Add a helper for de-dupe of *AsHex (#1224)
* Add a helper for de-dupe of *AsHex * Update packages/util-crypto/src/random/asU8a.ts * lint * isWasmOnly helper * bit hasher
This commit is contained in:
@@ -7,8 +7,9 @@ import type { Params } from './types';
|
||||
import scryptsy from 'scryptsy';
|
||||
|
||||
import { bufferToU8a, u8aToBuffer, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, scrypt } from '@polkadot/wasm-crypto';
|
||||
import { scrypt } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { DEFAULT_PARAMS } from './defaults';
|
||||
|
||||
@@ -21,7 +22,7 @@ interface Result {
|
||||
export function scryptEncode (passphrase?: HexString | Uint8Array | string, salt = randomAsU8a(), params = DEFAULT_PARAMS, onlyJs?: boolean): Result {
|
||||
const u8a = u8aToU8a(passphrase);
|
||||
|
||||
const password = isReady() && !onlyJs
|
||||
const password = isWasmOnly(onlyJs)
|
||||
? scrypt(u8a, salt, Math.log2(params.N), params.r, params.p)
|
||||
: bufferToU8a(
|
||||
scryptsy(u8aToBuffer(u8a), u8aToBuffer(salt), params.N, params.r, params.p, 64)
|
||||
|
||||
Reference in New Issue
Block a user