1 | import { hasBigInt, u8aToHex, u8aToU8a } from '@polkadot/util';
|
2 | import { isReady } from '@polkadot/wasm-crypto';
|
3 |
|
4 | export function createAsHex(fn) {
|
5 | return (...args) => u8aToHex(fn(...args));
|
6 | }
|
7 |
|
8 | export function createBitHasher(bitLength, fn) {
|
9 | return (data, onlyJs) => fn(data, bitLength, onlyJs);
|
10 | }
|
11 |
|
12 | export 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 | }
|