1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.hmacSha512AsU8a = exports.hmacSha256AsU8a = exports.hmacShaAsU8a = void 0;
|
4 | const hmac_1 = require("@noble/hashes/hmac");
|
5 | const sha256_1 = require("@noble/hashes/sha256");
|
6 | const sha512_1 = require("@noble/hashes/sha512");
|
7 | const util_1 = require("@polkadot/util");
|
8 | const wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
9 | const JS_HASH = {
|
10 | 256: sha256_1.sha256,
|
11 | 512: sha512_1.sha512
|
12 | };
|
13 | const WA_MHAC = {
|
14 | 256: wasm_crypto_1.hmacSha256,
|
15 | 512: wasm_crypto_1.hmacSha512
|
16 | };
|
17 | function createSha(bitLength) {
|
18 | return (key, data, onlyJs) => hmacShaAsU8a(key, data, bitLength, onlyJs);
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function hmacShaAsU8a(key, data, bitLength = 256, onlyJs) {
|
25 | const u8aKey = (0, util_1.u8aToU8a)(key);
|
26 | return !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
|
27 | ? WA_MHAC[bitLength](u8aKey, data)
|
28 | : (0, hmac_1.hmac)(JS_HASH[bitLength], u8aKey, data);
|
29 | }
|
30 | exports.hmacShaAsU8a = hmacShaAsU8a;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | exports.hmacSha256AsU8a = createSha(256);
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | exports.hmacSha512AsU8a = createSha(512);
|