UNPKG

613 BJavaScriptView Raw
1import { hasBigInt, u8aToHex, u8aToU8a } from '@polkadot/util';
2import { isReady } from '@polkadot/wasm-crypto';
3/** @internal */
4export function createAsHex(fn) {
5 return (...args) => u8aToHex(fn(...args));
6}
7/** @internal */
8export function createBitHasher(bitLength, fn) {
9 return (data, onlyJs) => fn(data, bitLength, onlyJs);
10}
11/** @internal */
12export function createDualHasher(wa, js) {
13 return (value, bitLength = 256, onlyJs) => {
14 const u8a = u8aToU8a(value);
15 return !hasBigInt || (!onlyJs && isReady())
16 ? wa[bitLength](u8a)
17 : js[bitLength](u8a);
18 };
19}