Scrypt via wasm-crypto (#647)
* Scrypt via wasm-crypto * Bump wasm-crypto
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
|
||||
import { Params } from './types';
|
||||
|
||||
import scrypt from 'scryptsy';
|
||||
import scryptsy from 'scryptsy';
|
||||
import { bufferToU8a, u8aToBuffer, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, scrypt } from '@polkadot/wasm-crypto';
|
||||
|
||||
import randomAsU8a from '../random/asU8a';
|
||||
import { DEFAULT_PARAMS } from './defaults';
|
||||
@@ -17,9 +18,11 @@ interface Result {
|
||||
}
|
||||
|
||||
export default function scryptEncode (passphrase?: Uint8Array | string, salt = randomAsU8a(), params = DEFAULT_PARAMS): Result {
|
||||
const password = bufferToU8a(
|
||||
scrypt(u8aToBuffer(u8aToU8a(passphrase)), u8aToBuffer(salt), params.N, params.r, params.p, 64)
|
||||
);
|
||||
const password = isReady()
|
||||
? scrypt(u8aToU8a(passphrase), salt, Math.log2(params.N), params.r, params.p)
|
||||
: bufferToU8a(
|
||||
scryptsy(u8aToBuffer(u8aToU8a(passphrase)), u8aToBuffer(salt), params.N, params.r, params.p, 64)
|
||||
);
|
||||
|
||||
return { params, password, salt };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user