1 | import { scrypt as scryptJs } from '@noble/hashes/scrypt';
|
2 | import { hasBigInt, objectSpread, u8aToU8a } from '@polkadot/util';
|
3 | import { isReady, scrypt } from '@polkadot/wasm-crypto';
|
4 | import { randomAsU8a } from '../random/asU8a.js';
|
5 | import { DEFAULT_PARAMS } from './defaults.js';
|
6 | export function scryptEncode(passphrase, salt = randomAsU8a(), params = DEFAULT_PARAMS, onlyJs) {
|
7 | const u8a = u8aToU8a(passphrase);
|
8 | return {
|
9 | params,
|
10 | password: !hasBigInt || (!onlyJs && isReady())
|
11 | ? scrypt(u8a, salt, Math.log2(params.N), params.r, params.p)
|
12 | : scryptJs(u8a, salt, objectSpread({ dkLen: 64 }, params)),
|
13 | salt
|
14 | };
|
15 | }
|