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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user