mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-25 01:17:58 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import type { ScryptParams } from './types.js';
|
||||
export declare const ALLOWED_PARAMS: ScryptParams[];
|
||||
export declare const DEFAULT_PARAMS: ScryptParams;
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DEFAULT_PARAMS = exports.ALLOWED_PARAMS = void 0;
|
||||
exports.ALLOWED_PARAMS = [
|
||||
{ N: 1 << 13, p: 10, r: 8 },
|
||||
{ N: 1 << 14, p: 5, r: 8 },
|
||||
{ N: 1 << 15, p: 3, r: 8 },
|
||||
{ N: 1 << 15, p: 1, r: 8 },
|
||||
{ N: 1 << 16, p: 2, r: 8 },
|
||||
{ N: 1 << 17, p: 1, r: 8 }
|
||||
];
|
||||
exports.DEFAULT_PARAMS = {
|
||||
N: 1 << 17,
|
||||
p: 1,
|
||||
r: 8
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { ScryptParams } from './types.js';
|
||||
interface Result {
|
||||
params: ScryptParams;
|
||||
password: Uint8Array;
|
||||
salt: Uint8Array;
|
||||
}
|
||||
export declare function scryptEncode(passphrase?: string | Uint8Array, salt?: Uint8Array, params?: ScryptParams, onlyJs?: boolean): Result;
|
||||
export {};
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.scryptEncode = scryptEncode;
|
||||
const scrypt_1 = require("@noble/hashes/scrypt");
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
|
||||
const asU8a_js_1 = require("../random/asU8a.js");
|
||||
const defaults_js_1 = require("./defaults.js");
|
||||
function scryptEncode(passphrase, salt = (0, asU8a_js_1.randomAsU8a)(), params = defaults_js_1.DEFAULT_PARAMS, onlyJs) {
|
||||
const u8a = (0, util_1.u8aToU8a)(passphrase);
|
||||
return {
|
||||
params,
|
||||
password: !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
|
||||
? (0, wasm_crypto_1.scrypt)(u8a, salt, Math.log2(params.N), params.r, params.p)
|
||||
: (0, scrypt_1.scrypt)(u8a, salt, (0, util_1.objectSpread)({ dkLen: 64 }, params)),
|
||||
salt
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { ScryptParams } from './types.js';
|
||||
interface Result {
|
||||
params: ScryptParams;
|
||||
salt: Uint8Array;
|
||||
}
|
||||
export declare function scryptFromU8a(data: Uint8Array): Result;
|
||||
export {};
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.scryptFromU8a = scryptFromU8a;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const bn_js_1 = require("../bn.js");
|
||||
const defaults_js_1 = require("./defaults.js");
|
||||
function scryptFromU8a(data) {
|
||||
if (!(data instanceof Uint8Array)) {
|
||||
throw new Error('Expected input to be a Uint8Array');
|
||||
}
|
||||
// Ensure the input is exactly 44 bytes: 32 for salt + 3 * 4 for N, p, r
|
||||
if (data.length < 32 + 12) {
|
||||
throw new Error(`Invalid input length: expected 44 bytes, found ${data.length}`);
|
||||
}
|
||||
const salt = data.subarray(0, 32);
|
||||
const N = (0, util_1.u8aToBn)(data.subarray(32, 36), bn_js_1.BN_LE_OPTS).toNumber();
|
||||
const p = (0, util_1.u8aToBn)(data.subarray(36, 40), bn_js_1.BN_LE_OPTS).toNumber();
|
||||
const r = (0, util_1.u8aToBn)(data.subarray(40, 44), bn_js_1.BN_LE_OPTS).toNumber();
|
||||
if (N > (1 << 20) || p > 4 || r > 16) {
|
||||
throw new Error('Scrypt parameters exceed safe limits');
|
||||
}
|
||||
const isAllowed = defaults_js_1.ALLOWED_PARAMS.some((preset) => preset.N === N && preset.p === p && preset.r === r);
|
||||
if (!isAllowed) {
|
||||
throw new Error('Invalid injected scrypt params found');
|
||||
}
|
||||
return { params: { N, p, r }, salt };
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { scryptEncode } from './encode.js';
|
||||
export { scryptFromU8a } from './fromU8a.js';
|
||||
export { scryptToU8a } from './toU8a.js';
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.scryptToU8a = exports.scryptFromU8a = exports.scryptEncode = void 0;
|
||||
var encode_js_1 = require("./encode.js");
|
||||
Object.defineProperty(exports, "scryptEncode", { enumerable: true, get: function () { return encode_js_1.scryptEncode; } });
|
||||
var fromU8a_js_1 = require("./fromU8a.js");
|
||||
Object.defineProperty(exports, "scryptFromU8a", { enumerable: true, get: function () { return fromU8a_js_1.scryptFromU8a; } });
|
||||
var toU8a_js_1 = require("./toU8a.js");
|
||||
Object.defineProperty(exports, "scryptToU8a", { enumerable: true, get: function () { return toU8a_js_1.scryptToU8a; } });
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { ScryptParams } from './types.js';
|
||||
export declare function scryptToU8a(salt: Uint8Array, { N, p, r }: ScryptParams): Uint8Array;
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.scryptToU8a = scryptToU8a;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const bn_js_1 = require("../bn.js");
|
||||
function scryptToU8a(salt, { N, p, r }) {
|
||||
return (0, util_1.u8aConcat)(salt, (0, util_1.bnToU8a)(N, bn_js_1.BN_LE_32_OPTS), (0, util_1.bnToU8a)(p, bn_js_1.BN_LE_32_OPTS), (0, util_1.bnToU8a)(r, bn_js_1.BN_LE_32_OPTS));
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/** The params that control scrypt generation */
|
||||
export interface ScryptParams {
|
||||
N: number;
|
||||
p: number;
|
||||
r: number;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Reference in New Issue
Block a user