@qevm/sha2 5.7.0
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/LICENSE.md +21 -0
- package/README.md +38 -0
- package/lib/_version.d.ts +2 -0
- package/lib/_version.d.ts.map +1 -0
- package/lib/_version.js +5 -0
- package/lib/_version.js.map +1 -0
- package/lib/browser-sha2.d.ts +7 -0
- package/lib/browser-sha2.d.ts.map +1 -0
- package/lib/browser-sha2.js +35 -0
- package/lib/browser-sha2.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/sha2.d.ts +7 -0
- package/lib/sha2.d.ts.map +1 -0
- package/lib/sha2.js +36 -0
- package/lib/sha2.js.map +1 -0
- package/lib/types.d.ts +5 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +10 -0
- package/lib/types.js.map +1 -0
- package/package.json +42 -0
- package/src.ts/_version.ts +1 -0
- package/src.ts/browser-sha2.ts +36 -0
- package/src.ts/index.ts +14 -0
- package/src.ts/sha2.ts +38 -0
- package/src.ts/types.ts +2 -0
- package/thirdparty.d.ts +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Richard Moore
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
SHA2 Hash Functions
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
This sub-module is part of the [ethers project](https://github.com/ethers-io/ethers.js).
|
|
5
|
+
|
|
6
|
+
It is responsible for common cryptographic hashes and HMAC.
|
|
7
|
+
|
|
8
|
+
For more information, see the [documentation](https://docs.ethers.io/v5/api/utils/hashing/).
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Importing
|
|
12
|
+
---------
|
|
13
|
+
|
|
14
|
+
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/ethers),
|
|
15
|
+
but for those with more specific needs, individual components can be imported.
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const {
|
|
19
|
+
|
|
20
|
+
ripemd160,
|
|
21
|
+
|
|
22
|
+
sha256,
|
|
23
|
+
sha512,
|
|
24
|
+
|
|
25
|
+
computeHmac,
|
|
26
|
+
|
|
27
|
+
// Enums
|
|
28
|
+
|
|
29
|
+
SupportedAlgorithm
|
|
30
|
+
|
|
31
|
+
} = require("@ethersproject/sha2");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
License
|
|
36
|
+
-------
|
|
37
|
+
|
|
38
|
+
MIT License
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_version.d.ts","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,eAAe,CAAC"}
|
package/lib/_version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BytesLike } from "@qevm/bytes";
|
|
2
|
+
import { SupportedAlgorithm } from "./types";
|
|
3
|
+
export declare function ripemd160(data: BytesLike): string;
|
|
4
|
+
export declare function sha256(data: BytesLike): string;
|
|
5
|
+
export declare function sha512(data: BytesLike): string;
|
|
6
|
+
export declare function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string;
|
|
7
|
+
//# sourceMappingURL=browser-sha2.d.ts.map
|
|
@@ -0,0 +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,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CASlG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ripemd160 = ripemd160;
|
|
7
|
+
exports.sha256 = sha256;
|
|
8
|
+
exports.sha512 = sha512;
|
|
9
|
+
exports.computeHmac = computeHmac;
|
|
10
|
+
const hash_js_1 = __importDefault(require("hash.js"));
|
|
11
|
+
//const _ripemd160 = _hash.ripemd160;
|
|
12
|
+
const bytes_1 = require("@qevm/bytes");
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const logger_1 = require("@ethersproject/logger");
|
|
15
|
+
const _version_1 = require("./_version");
|
|
16
|
+
const logger = new logger_1.Logger(_version_1.version);
|
|
17
|
+
function ripemd160(data) {
|
|
18
|
+
return "0x" + (hash_js_1.default.ripemd160().update((0, bytes_1.arrayify)(data)).digest("hex"));
|
|
19
|
+
}
|
|
20
|
+
function sha256(data) {
|
|
21
|
+
return "0x" + (hash_js_1.default.sha256().update((0, bytes_1.arrayify)(data)).digest("hex"));
|
|
22
|
+
}
|
|
23
|
+
function sha512(data) {
|
|
24
|
+
return "0x" + (hash_js_1.default.sha512().update((0, bytes_1.arrayify)(data)).digest("hex"));
|
|
25
|
+
}
|
|
26
|
+
function computeHmac(algorithm, key, data) {
|
|
27
|
+
if (!types_1.SupportedAlgorithm[algorithm]) {
|
|
28
|
+
logger.throwError("unsupported algorithm " + algorithm, logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
29
|
+
operation: "hmac",
|
|
30
|
+
algorithm: algorithm
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return "0x" + hash_js_1.default.hmac(hash_js_1.default[algorithm], (0, bytes_1.arrayify)(key)).update((0, bytes_1.arrayify)(data)).digest("hex");
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=browser-sha2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-sha2.js","sourceRoot":"","sources":["../src.ts/browser-sha2.ts"],"names":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MAAM,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxG,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +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,EACH,WAAW,EAEX,SAAS,EAET,MAAM,EACN,MAAM,EAEN,kBAAkB,EACrB,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupportedAlgorithm = exports.sha512 = exports.sha256 = exports.ripemd160 = exports.computeHmac = void 0;
|
|
4
|
+
const sha2_1 = require("./sha2");
|
|
5
|
+
Object.defineProperty(exports, "computeHmac", { enumerable: true, get: function () { return sha2_1.computeHmac; } });
|
|
6
|
+
Object.defineProperty(exports, "ripemd160", { enumerable: true, get: function () { return sha2_1.ripemd160; } });
|
|
7
|
+
Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return sha2_1.sha256; } });
|
|
8
|
+
Object.defineProperty(exports, "sha512", { enumerable: true, get: function () { return sha2_1.sha512; } });
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
Object.defineProperty(exports, "SupportedAlgorithm", { enumerable: true, get: function () { return types_1.SupportedAlgorithm; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgE;AAK5D,4FALK,kBAAW,OAKL;AAEX,0FAPkB,gBAAS,OAOlB;AAET,uFAT6B,aAAM,OAS7B;AACN,uFAVqC,aAAM,OAUrC;AARV,mCAA6C;AAUzC,mGAVK,0BAAkB,OAUL"}
|
package/lib/sha2.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BytesLike } from "@qevm/bytes";
|
|
2
|
+
import { SupportedAlgorithm } from "./types";
|
|
3
|
+
export declare function ripemd160(data: BytesLike): string;
|
|
4
|
+
export declare function sha256(data: BytesLike): string;
|
|
5
|
+
export declare function sha512(data: BytesLike): string;
|
|
6
|
+
export declare function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string;
|
|
7
|
+
//# sourceMappingURL=sha2.d.ts.map
|
|
@@ -0,0 +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,CAE9C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAE9C;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAUlG"}
|
package/lib/sha2.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ripemd160 = ripemd160;
|
|
7
|
+
exports.sha256 = sha256;
|
|
8
|
+
exports.sha512 = sha512;
|
|
9
|
+
exports.computeHmac = computeHmac;
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
const hash_js_1 = __importDefault(require("hash.js"));
|
|
12
|
+
const bytes_1 = require("@qevm/bytes");
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const logger_1 = require("@ethersproject/logger");
|
|
15
|
+
const _version_1 = require("./_version");
|
|
16
|
+
const logger = new logger_1.Logger(_version_1.version);
|
|
17
|
+
function ripemd160(data) {
|
|
18
|
+
return "0x" + (hash_js_1.default.ripemd160().update((0, bytes_1.arrayify)(data)).digest("hex"));
|
|
19
|
+
}
|
|
20
|
+
function sha256(data) {
|
|
21
|
+
return "0x" + (0, crypto_1.createHash)("sha256").update(Buffer.from((0, bytes_1.arrayify)(data))).digest("hex");
|
|
22
|
+
}
|
|
23
|
+
function sha512(data) {
|
|
24
|
+
return "0x" + (0, crypto_1.createHash)("sha512").update(Buffer.from((0, bytes_1.arrayify)(data))).digest("hex");
|
|
25
|
+
}
|
|
26
|
+
function computeHmac(algorithm, key, data) {
|
|
27
|
+
/* istanbul ignore if */
|
|
28
|
+
if (!types_1.SupportedAlgorithm[algorithm]) {
|
|
29
|
+
logger.throwError("unsupported algorithm - " + algorithm, logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
30
|
+
operation: "computeHmac",
|
|
31
|
+
algorithm: algorithm
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return "0x" + (0, crypto_1.createHmac)(algorithm, Buffer.from((0, bytes_1.arrayify)(key))).update(Buffer.from((0, bytes_1.arrayify)(data))).digest("hex");
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=sha2.js.map
|
package/lib/sha2.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha2.js","sourceRoot":"","sources":["../src.ts/sha2.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AAcb,8BAEC;AAED,wBAEC;AAED,w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AAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtH,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAAG,MAAM,WAAW;IAAE,MAAM,WAAW;CAAE"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupportedAlgorithm = void 0;
|
|
4
|
+
var SupportedAlgorithm;
|
|
5
|
+
(function (SupportedAlgorithm) {
|
|
6
|
+
SupportedAlgorithm["sha256"] = "sha256";
|
|
7
|
+
SupportedAlgorithm["sha512"] = "sha512";
|
|
8
|
+
})(SupportedAlgorithm || (exports.SupportedAlgorithm = SupportedAlgorithm = {}));
|
|
9
|
+
;
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src.ts/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,kBAA2D;AAAvE,WAAY,kBAAkB;IAAG,uCAAiB,CAAA;IAAE,uCAAiB,CAAA;AAAC,CAAC,EAA3D,kBAAkB,kCAAlB,kBAAkB,QAAyC;AAAA,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_ethers.alias": {
|
|
3
|
+
"sha2.js": "browser-sha2.js"
|
|
4
|
+
},
|
|
5
|
+
"author": "Eugene Kuleshov",
|
|
6
|
+
"browser": {
|
|
7
|
+
"./lib/sha2": "./lib/browser-sha2.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@ethersproject/logger": "^5.7.0",
|
|
11
|
+
"@qevm/bytes": "5.7.1",
|
|
12
|
+
"hash.js": "1.1.7",
|
|
13
|
+
"crypto-js": "^4.2.0"
|
|
14
|
+
},
|
|
15
|
+
"description": "The SHA2 family hash functions and HMAC functions for qethers.",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"Ethereum",
|
|
18
|
+
"qethers"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "./lib/index.js",
|
|
22
|
+
"module": "./lib.esm/index.js",
|
|
23
|
+
"name": "@qevm/sha2",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"directory": "packages/sha2",
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/ethers-io/ethers.js.git"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"tarballHash": "0xf4e98e42d47de50b1a899374350f5257d0ea9a604d59546ab0acbed6d89eceb6",
|
|
37
|
+
"types": "./lib/index.d.ts",
|
|
38
|
+
"version": "5.7.0",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.15.30"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = "sha2/5.7.0";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import hash from "hash.js";
|
|
4
|
+
//const _ripemd160 = _hash.ripemd160;
|
|
5
|
+
|
|
6
|
+
import { arrayify, BytesLike } from "@qevm/bytes";
|
|
7
|
+
|
|
8
|
+
import { SupportedAlgorithm } from "./types";
|
|
9
|
+
|
|
10
|
+
import { Logger } from "@ethersproject/logger";
|
|
11
|
+
import { version } from "./_version";
|
|
12
|
+
const logger = new Logger(version);
|
|
13
|
+
|
|
14
|
+
export function ripemd160(data: BytesLike): string {
|
|
15
|
+
return "0x" + (hash.ripemd160().update(arrayify(data)).digest("hex"));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sha256(data: BytesLike): string {
|
|
19
|
+
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function sha512(data: BytesLike): string {
|
|
23
|
+
return "0x" + (hash.sha512().update(arrayify(data)).digest("hex"));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string {
|
|
27
|
+
if (!SupportedAlgorithm[algorithm]) {
|
|
28
|
+
logger.throwError("unsupported algorithm " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
|
|
29
|
+
operation: "hmac",
|
|
30
|
+
algorithm: algorithm
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return "0x" + hash.hmac((<any>hash)[algorithm], arrayify(key)).update(arrayify(data)).digest("hex");
|
|
35
|
+
}
|
|
36
|
+
|
package/src.ts/index.ts
ADDED
package/src.ts/sha2.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createHash, createHmac } from "crypto";
|
|
4
|
+
|
|
5
|
+
import hash from "hash.js";
|
|
6
|
+
|
|
7
|
+
import { arrayify, BytesLike } from "@qevm/bytes";
|
|
8
|
+
|
|
9
|
+
import { SupportedAlgorithm } from "./types";
|
|
10
|
+
|
|
11
|
+
import { Logger } from "@ethersproject/logger";
|
|
12
|
+
import { version } from "./_version";
|
|
13
|
+
const logger = new Logger(version);
|
|
14
|
+
|
|
15
|
+
export function ripemd160(data: BytesLike): string {
|
|
16
|
+
return "0x" + (hash.ripemd160().update(arrayify(data)).digest("hex"));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function sha256(data: BytesLike): string {
|
|
20
|
+
return "0x" + createHash("sha256").update(Buffer.from(arrayify(data))).digest("hex")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function sha512(data: BytesLike): string {
|
|
24
|
+
return "0x" + createHash("sha512").update(Buffer.from(arrayify(data))).digest("hex")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string {
|
|
28
|
+
/* istanbul ignore if */
|
|
29
|
+
if (!SupportedAlgorithm[algorithm]) {
|
|
30
|
+
logger.throwError("unsupported algorithm - " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
|
|
31
|
+
operation: "computeHmac",
|
|
32
|
+
algorithm: algorithm
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return "0x" + createHmac(algorithm, Buffer.from(arrayify(key))).update(Buffer.from(arrayify(data))).digest("hex");
|
|
37
|
+
}
|
|
38
|
+
|
package/src.ts/types.ts
ADDED
package/thirdparty.d.ts
ADDED
|
File without changes
|