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:
Jaco
2021-11-21 20:21:20 +02:00
committed by GitHub
parent 1606dfd9ca
commit e8af9b5a1e
25 changed files with 112 additions and 165 deletions
+4 -2
View File
@@ -4,7 +4,9 @@
import hash from 'hash.js';
import { u8aToU8a } from '@polkadot/util';
import { hmacSha256, hmacSha512, isReady } from '@polkadot/wasm-crypto';
import { hmacSha256, hmacSha512 } from '@polkadot/wasm-crypto';
import { isWasmOnly } from '../helpers';
type HashFn = (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array;
@@ -17,7 +19,7 @@ export function hmacShaAsU8a (key: Uint8Array | string, data: Uint8Array, bitLen
const is256 = bitLength === 256;
const u8aKey = u8aToU8a(key);
return isReady() && !onlyJs
return isWasmOnly(onlyJs)
? is256
? hmacSha256(u8aKey, data)
: hmacSha512(u8aKey, data)