1 | import { blake2b as blake2bJs } from '@noble/hashes/blake2b';
|
2 | import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
3 | import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
4 | import { createAsHex } from '../helpers.js';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export function blake2AsU8a(data, bitLength = 256, key, onlyJs) {
|
20 | const byteLength = Math.ceil(bitLength / 8);
|
21 | const u8a = u8aToU8a(data);
|
22 | return !hasBigInt || (!onlyJs && isReady())
|
23 | ? blake2b(u8a, u8aToU8a(key), byteLength)
|
24 | : key
|
25 | ? blake2bJs(u8a, { dkLen: byteLength, key })
|
26 | : blake2bJs(u8a, { dkLen: byteLength });
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export const blake2AsHex = createAsHex(blake2AsU8a);
|