@qevm/sha2 5.7.0 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/lib/_version.d.ts +1 -1
- package/lib/_version.js +1 -1
- package/lib/browser-sha2.d.ts.map +1 -1
- package/lib/browser-sha2.js +10 -6
- package/lib/browser-sha2.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/sha2.d.ts.map +1 -1
- package/lib/sha2.js +15 -6
- package/lib/sha2.js.map +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +0 -1
- package/lib/types.js.map +1 -1
- package/package.json +39 -40
- package/src.ts/_version.ts +1 -1
- package/src.ts/browser-sha2.ts +24 -11
- package/src.ts/index.ts +1 -10
- package/src.ts/sha2.ts +33 -11
- package/src.ts/types.ts +4 -2
package/README.md
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
SHA2 Hash Functions
|
|
2
2
|
===================
|
|
3
3
|
|
|
4
|
-
This sub-module is part of the [ethers project](https://github.com/ethers-io/ethers.js).
|
|
4
|
+
This sub-module is part of the qethers, a fork of [ethers project](https://github.com/ethers-io/ethers.js).
|
|
5
5
|
|
|
6
6
|
It is responsible for common cryptographic hashes and HMAC.
|
|
7
7
|
|
|
8
|
-
For more information, see the [documentation](https://docs.ethers.io/v5/api/utils/hashing/).
|
|
9
|
-
|
|
10
8
|
|
|
11
9
|
Importing
|
|
12
10
|
---------
|
|
13
11
|
|
|
14
|
-
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/
|
|
12
|
+
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/@qevm/qethers),
|
|
15
13
|
but for those with more specific needs, individual components can be imported.
|
|
16
14
|
|
|
17
15
|
```javascript
|
|
@@ -28,7 +26,7 @@ const {
|
|
|
28
26
|
|
|
29
27
|
SupportedAlgorithm
|
|
30
28
|
|
|
31
|
-
} = require("@
|
|
29
|
+
} = require("@qevm/sha2");
|
|
32
30
|
```
|
|
33
31
|
|
|
34
32
|
|
package/lib/_version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "sha2/5.7.
|
|
1
|
+
export declare const version = "sha2/5.7.1";
|
|
2
2
|
//# sourceMappingURL=_version.d.ts.map
|
package/lib/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-sha2.d.ts","sourceRoot":"","sources":["../src.ts/browser-sha2.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"browser-sha2.d.ts","sourceRoot":"","sources":["../src.ts/browser-sha2.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,wBAAgB,WAAW,CACvB,SAAS,EAAE,kBAAkB,EAC7B,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,SAAS,GAChB,MAAM,CAmBR"}
|
package/lib/browser-sha2.js
CHANGED
|
@@ -11,25 +11,29 @@ const hash_js_1 = __importDefault(require("hash.js"));
|
|
|
11
11
|
//const _ripemd160 = _hash.ripemd160;
|
|
12
12
|
const bytes_1 = require("@qevm/bytes");
|
|
13
13
|
const types_1 = require("./types");
|
|
14
|
-
const logger_1 = require("@
|
|
14
|
+
const logger_1 = require("@qevm/logger");
|
|
15
15
|
const _version_1 = require("./_version");
|
|
16
16
|
const logger = new logger_1.Logger(_version_1.version);
|
|
17
17
|
function ripemd160(data) {
|
|
18
|
-
return "0x" +
|
|
18
|
+
return "0x" + hash_js_1.default.ripemd160().update((0, bytes_1.arrayify)(data)).digest("hex");
|
|
19
19
|
}
|
|
20
20
|
function sha256(data) {
|
|
21
|
-
return "0x" +
|
|
21
|
+
return "0x" + hash_js_1.default.sha256().update((0, bytes_1.arrayify)(data)).digest("hex");
|
|
22
22
|
}
|
|
23
23
|
function sha512(data) {
|
|
24
|
-
return "0x" +
|
|
24
|
+
return "0x" + hash_js_1.default.sha512().update((0, bytes_1.arrayify)(data)).digest("hex");
|
|
25
25
|
}
|
|
26
26
|
function computeHmac(algorithm, key, data) {
|
|
27
27
|
if (!types_1.SupportedAlgorithm[algorithm]) {
|
|
28
28
|
logger.throwError("unsupported algorithm " + algorithm, logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
29
29
|
operation: "hmac",
|
|
30
|
-
algorithm: algorithm
|
|
30
|
+
algorithm: algorithm,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
return "0x" +
|
|
33
|
+
return ("0x" +
|
|
34
|
+
hash_js_1.default
|
|
35
|
+
.hmac(hash_js_1.default[algorithm], (0, bytes_1.arrayify)(key))
|
|
36
|
+
.update((0, bytes_1.arrayify)(data))
|
|
37
|
+
.digest("hex"));
|
|
34
38
|
}
|
|
35
39
|
//# sourceMappingURL=browser-sha2.js.map
|
package/lib/browser-sha2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-sha2.js","sourceRoot":"","sources":["../src.ts/browser-sha2.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;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,CAAO,iBAAK,CAAC,SAAS,CAAC,EAAE,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAC;aAC3C,MAAM,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;aACtB,MAAM,CAAC,KAAK,CAAC,CACrB,CAAC;AACN,CAAC"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgE;AAIvD,4FAJA,kBAAW,OAIA;AAAE,0FAJA,gBAAS,OAIA;AAAE,uFAJA,aAAM,OAIA;AAAE,uFAJA,aAAM,OAIA;AAF/C,mCAA6C;AAEI,mGAFxC,0BAAkB,OAEwC"}
|
package/lib/sha2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha2.d.ts","sourceRoot":"","sources":["../src.ts/sha2.ts"],"names":[],"mappings":"AAMA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"sha2.d.ts","sourceRoot":"","sources":["../src.ts/sha2.ts"],"names":[],"mappings":"AAMA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAO9C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAO9C;AAED,wBAAgB,WAAW,CACvB,SAAS,EAAE,kBAAkB,EAC7B,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,SAAS,GAChB,MAAM,CAmBR"}
|
package/lib/sha2.js
CHANGED
|
@@ -11,26 +11,35 @@ const crypto_1 = require("crypto");
|
|
|
11
11
|
const hash_js_1 = __importDefault(require("hash.js"));
|
|
12
12
|
const bytes_1 = require("@qevm/bytes");
|
|
13
13
|
const types_1 = require("./types");
|
|
14
|
-
const logger_1 = require("@
|
|
14
|
+
const logger_1 = require("@qevm/logger");
|
|
15
15
|
const _version_1 = require("./_version");
|
|
16
16
|
const logger = new logger_1.Logger(_version_1.version);
|
|
17
17
|
function ripemd160(data) {
|
|
18
|
-
return "0x" +
|
|
18
|
+
return "0x" + hash_js_1.default.ripemd160().update((0, bytes_1.arrayify)(data)).digest("hex");
|
|
19
19
|
}
|
|
20
20
|
function sha256(data) {
|
|
21
|
-
return "0x" +
|
|
21
|
+
return ("0x" +
|
|
22
|
+
(0, crypto_1.createHash)("sha256")
|
|
23
|
+
.update(Buffer.from((0, bytes_1.arrayify)(data)))
|
|
24
|
+
.digest("hex"));
|
|
22
25
|
}
|
|
23
26
|
function sha512(data) {
|
|
24
|
-
return "0x" +
|
|
27
|
+
return ("0x" +
|
|
28
|
+
(0, crypto_1.createHash)("sha512")
|
|
29
|
+
.update(Buffer.from((0, bytes_1.arrayify)(data)))
|
|
30
|
+
.digest("hex"));
|
|
25
31
|
}
|
|
26
32
|
function computeHmac(algorithm, key, data) {
|
|
27
33
|
/* istanbul ignore if */
|
|
28
34
|
if (!types_1.SupportedAlgorithm[algorithm]) {
|
|
29
35
|
logger.throwError("unsupported algorithm - " + algorithm, logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
30
36
|
operation: "computeHmac",
|
|
31
|
-
algorithm: algorithm
|
|
37
|
+
algorithm: algorithm,
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
|
-
return "0x" +
|
|
40
|
+
return ("0x" +
|
|
41
|
+
(0, crypto_1.createHmac)(algorithm, Buffer.from((0, bytes_1.arrayify)(key)))
|
|
42
|
+
.update(Buffer.from((0, bytes_1.arrayify)(data)))
|
|
43
|
+
.digest("hex"));
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=sha2.js.map
|
package/lib/sha2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha2.js","sourceRoot":"","sources":["../src.ts/sha2.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AAcb,8BAEC;AAED,
|
|
1
|
+
{"version":3,"file":"sha2.js","sourceRoot":"","sources":["../src.ts/sha2.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AAcb,8BAEC;AAED,wBAOC;AAED,wBAOC;AAED,kCAuBC;AAzDD,mCAAgD;AAEhD,sDAA2B;AAE3B,uCAAkD;AAElD,mCAA6C;AAE7C,yCAAsC;AACtC,yCAAqC;AACrC,MAAM,MAAM,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ACrB,CAAC;AACN,CAAC"}
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC1B,MAAM,WAAW;IACjB,MAAM,WAAW;CACpB"}
|
package/lib/types.js
CHANGED
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC1B,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;AACrB,CAAC,EAHW,kBAAkB,kCAAlB,kBAAkB,QAG7B"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"qethers"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
2
|
+
"_ethers.alias": {
|
|
3
|
+
"sha2.js": "browser-sha2.js"
|
|
4
|
+
},
|
|
5
|
+
"contributors": [
|
|
6
|
+
"Eugene Kuleshov <kulevgen32@gmail.com>",
|
|
7
|
+
"Richard Moore <me@ricmoo.com>"
|
|
8
|
+
],
|
|
9
|
+
"browser": {
|
|
10
|
+
"./lib/sha2": "./lib/browser-sha2.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@qevm/logger": "^5.7.1",
|
|
14
|
+
"@qevm/bytes": "^5.7.2",
|
|
15
|
+
"hash.js": "1.1.7",
|
|
16
|
+
"crypto-js": "^4.2.0"
|
|
17
|
+
},
|
|
18
|
+
"description": "The SHA2 family hash functions and HMAC functions for qethers.",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"QEVM",
|
|
21
|
+
"QuantumEVM",
|
|
22
|
+
"qethers"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"main": "./lib/index.js",
|
|
26
|
+
"module": "./lib.esm/index.js",
|
|
27
|
+
"name": "@qevm/sha2",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"tarballHash": "0xf4e98e42d47de50b1a899374350f5257d0ea9a604d59546ab0acbed6d89eceb6",
|
|
36
|
+
"types": "./lib/index.d.ts",
|
|
37
|
+
"version": "5.7.1",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.15.30"
|
|
40
|
+
}
|
|
42
41
|
}
|
package/src.ts/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "sha2/5.7.
|
|
1
|
+
export const version = "sha2/5.7.1";
|
package/src.ts/browser-sha2.ts
CHANGED
|
@@ -7,30 +7,43 @@ import { arrayify, BytesLike } from "@qevm/bytes";
|
|
|
7
7
|
|
|
8
8
|
import { SupportedAlgorithm } from "./types";
|
|
9
9
|
|
|
10
|
-
import { Logger } from "@
|
|
10
|
+
import { Logger } from "@qevm/logger";
|
|
11
11
|
import { version } from "./_version";
|
|
12
12
|
const logger = new Logger(version);
|
|
13
13
|
|
|
14
14
|
export function ripemd160(data: BytesLike): string {
|
|
15
|
-
return "0x" +
|
|
15
|
+
return "0x" + hash.ripemd160().update(arrayify(data)).digest("hex");
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function sha256(data: BytesLike): string {
|
|
19
|
-
return "0x" +
|
|
19
|
+
return "0x" + hash.sha256().update(arrayify(data)).digest("hex");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function sha512(data: BytesLike): string {
|
|
23
|
-
return "0x" +
|
|
23
|
+
return "0x" + hash.sha512().update(arrayify(data)).digest("hex");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function computeHmac(
|
|
26
|
+
export function computeHmac(
|
|
27
|
+
algorithm: SupportedAlgorithm,
|
|
28
|
+
key: BytesLike,
|
|
29
|
+
data: BytesLike,
|
|
30
|
+
): string {
|
|
27
31
|
if (!SupportedAlgorithm[algorithm]) {
|
|
28
|
-
logger.throwError(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
logger.throwError(
|
|
33
|
+
"unsupported algorithm " + algorithm,
|
|
34
|
+
Logger.errors.UNSUPPORTED_OPERATION,
|
|
35
|
+
{
|
|
36
|
+
operation: "hmac",
|
|
37
|
+
algorithm: algorithm,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
return
|
|
42
|
+
return (
|
|
43
|
+
"0x" +
|
|
44
|
+
hash
|
|
45
|
+
.hmac((<any>hash)[algorithm], arrayify(key))
|
|
46
|
+
.update(arrayify(data))
|
|
47
|
+
.digest("hex")
|
|
48
|
+
);
|
|
35
49
|
}
|
|
36
|
-
|
package/src.ts/index.ts
CHANGED
|
@@ -2,13 +2,4 @@ import { computeHmac, ripemd160, sha256, sha512 } from "./sha2";
|
|
|
2
2
|
|
|
3
3
|
import { SupportedAlgorithm } from "./types";
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
computeHmac,
|
|
7
|
-
|
|
8
|
-
ripemd160,
|
|
9
|
-
|
|
10
|
-
sha256,
|
|
11
|
-
sha512,
|
|
12
|
-
|
|
13
|
-
SupportedAlgorithm
|
|
14
|
-
}
|
|
5
|
+
export { computeHmac, ripemd160, sha256, sha512, SupportedAlgorithm };
|
package/src.ts/sha2.ts
CHANGED
|
@@ -8,31 +8,53 @@ import { arrayify, BytesLike } from "@qevm/bytes";
|
|
|
8
8
|
|
|
9
9
|
import { SupportedAlgorithm } from "./types";
|
|
10
10
|
|
|
11
|
-
import { Logger } from "@
|
|
11
|
+
import { Logger } from "@qevm/logger";
|
|
12
12
|
import { version } from "./_version";
|
|
13
13
|
const logger = new Logger(version);
|
|
14
14
|
|
|
15
15
|
export function ripemd160(data: BytesLike): string {
|
|
16
|
-
return "0x" +
|
|
16
|
+
return "0x" + hash.ripemd160().update(arrayify(data)).digest("hex");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function sha256(data: BytesLike): string {
|
|
20
|
-
return
|
|
20
|
+
return (
|
|
21
|
+
"0x" +
|
|
22
|
+
createHash("sha256")
|
|
23
|
+
.update(Buffer.from(arrayify(data)))
|
|
24
|
+
.digest("hex")
|
|
25
|
+
);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
export function sha512(data: BytesLike): string {
|
|
24
|
-
return
|
|
29
|
+
return (
|
|
30
|
+
"0x" +
|
|
31
|
+
createHash("sha512")
|
|
32
|
+
.update(Buffer.from(arrayify(data)))
|
|
33
|
+
.digest("hex")
|
|
34
|
+
);
|
|
25
35
|
}
|
|
26
36
|
|
|
27
|
-
export function computeHmac(
|
|
37
|
+
export function computeHmac(
|
|
38
|
+
algorithm: SupportedAlgorithm,
|
|
39
|
+
key: BytesLike,
|
|
40
|
+
data: BytesLike,
|
|
41
|
+
): string {
|
|
28
42
|
/* istanbul ignore if */
|
|
29
43
|
if (!SupportedAlgorithm[algorithm]) {
|
|
30
|
-
logger.throwError(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
logger.throwError(
|
|
45
|
+
"unsupported algorithm - " + algorithm,
|
|
46
|
+
Logger.errors.UNSUPPORTED_OPERATION,
|
|
47
|
+
{
|
|
48
|
+
operation: "computeHmac",
|
|
49
|
+
algorithm: algorithm,
|
|
50
|
+
},
|
|
51
|
+
);
|
|
34
52
|
}
|
|
35
53
|
|
|
36
|
-
return
|
|
54
|
+
return (
|
|
55
|
+
"0x" +
|
|
56
|
+
createHmac(algorithm, Buffer.from(arrayify(key)))
|
|
57
|
+
.update(Buffer.from(arrayify(data)))
|
|
58
|
+
.digest("hex")
|
|
59
|
+
);
|
|
37
60
|
}
|
|
38
|
-
|
package/src.ts/types.ts
CHANGED