Scrypt via wasm-crypto (#647)

* Scrypt via wasm-crypto

* Bump wasm-crypto
This commit is contained in:
Jaco Greeff
2020-08-05 16:07:38 +02:00
committed by GitHub
parent 0cf65e1671
commit ce6f9d8bc8
4 changed files with 142 additions and 139 deletions
+7 -4
View File
@@ -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 };
}