1 | import { u8aToBn } from '@polkadot/util';
|
2 | import { BN_LE_OPTS } from '../bn.js';
|
3 | import { DEFAULT_PARAMS } from './defaults.js';
|
4 | export function scryptFromU8a(data) {
|
5 | const salt = data.subarray(0, 32);
|
6 | const N = u8aToBn(data.subarray(32 + 0, 32 + 4), BN_LE_OPTS).toNumber();
|
7 | const p = u8aToBn(data.subarray(32 + 4, 32 + 8), BN_LE_OPTS).toNumber();
|
8 | const r = u8aToBn(data.subarray(32 + 8, 32 + 12), BN_LE_OPTS).toNumber();
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | if (N !== DEFAULT_PARAMS.N || p !== DEFAULT_PARAMS.p || r !== DEFAULT_PARAMS.r) {
|
15 | throw new Error('Invalid injected scrypt params found');
|
16 | }
|
17 | return { params: { N, p, r }, salt };
|
18 | }
|