mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 19:38:02 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user