UNPKG

669 BJavaScriptView Raw
1import { scrypt as scryptJs } from '@noble/hashes/scrypt';
2import { hasBigInt, objectSpread, u8aToU8a } from '@polkadot/util';
3import { isReady, scrypt } from '@polkadot/wasm-crypto';
4import { randomAsU8a } from '../random/asU8a.js';
5import { DEFAULT_PARAMS } from './defaults.js';
6export 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}