@naturalcycles/nodejs-lib 13.27.0 → 13.28.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/dist/security/hash.util.js +4 -12
- package/package.json +2 -2
- package/src/security/hash.util.ts +4 -14
|
@@ -31,21 +31,13 @@ function sha256AsBuffer(s) {
|
|
|
31
31
|
return hashAsBuffer(s, 'sha256');
|
|
32
32
|
}
|
|
33
33
|
function hash(s, algorithm, outputEncoding = 'hex') {
|
|
34
|
-
// todo: cleanup after @types/node is updated
|
|
35
34
|
// https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#crypto-implement-cryptohash
|
|
36
|
-
// Node 20.12+
|
|
37
|
-
|
|
38
|
-
return node_crypto_1.default.hash(algorithm, s, outputEncoding);
|
|
39
|
-
}
|
|
40
|
-
return node_crypto_1.default.createHash(algorithm).update(s).digest(outputEncoding);
|
|
35
|
+
// Note: crypto.hash is Node 20.12+
|
|
36
|
+
return node_crypto_1.default.hash(algorithm, s, outputEncoding);
|
|
41
37
|
}
|
|
42
38
|
function hashAsBuffer(s, algorithm) {
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
if (node_crypto_1.default.hash) {
|
|
46
|
-
return node_crypto_1.default.hash(algorithm, s, 'buffer');
|
|
47
|
-
}
|
|
48
|
-
return node_crypto_1.default.createHash(algorithm).update(s).digest();
|
|
39
|
+
// Note: crypto.hash is Node 20.12+
|
|
40
|
+
return node_crypto_1.default.hash(algorithm, s, 'buffer');
|
|
49
41
|
}
|
|
50
42
|
function base64(s) {
|
|
51
43
|
return (typeof s === 'string' ? Buffer.from(s) : s).toString('base64');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.28.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"docs-serve": "vuepress dev docs",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"url": "https://github.com/NaturalCycles/nodejs-lib"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
|
-
"node": ">=
|
|
71
|
+
"node": ">=20.12.0"
|
|
72
72
|
},
|
|
73
73
|
"description": "Standard library for Node.js",
|
|
74
74
|
"author": "Natural Cycles Team",
|
|
@@ -22,24 +22,14 @@ export function hash(
|
|
|
22
22
|
algorithm: string,
|
|
23
23
|
outputEncoding: BinaryToTextEncoding = 'hex',
|
|
24
24
|
): string {
|
|
25
|
-
// todo: cleanup after @types/node is updated
|
|
26
25
|
// https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#crypto-implement-cryptohash
|
|
27
|
-
// Node 20.12+
|
|
28
|
-
|
|
29
|
-
return (crypto as any).hash(algorithm, s, outputEncoding)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return crypto.createHash(algorithm).update(s).digest(outputEncoding)
|
|
26
|
+
// Note: crypto.hash is Node 20.12+
|
|
27
|
+
return crypto.hash(algorithm, s, outputEncoding)
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
export function hashAsBuffer(s: string | Buffer, algorithm: string): Buffer {
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
if ((crypto as any).hash) {
|
|
39
|
-
return (crypto as any).hash(algorithm, s, 'buffer')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return crypto.createHash(algorithm).update(s).digest()
|
|
31
|
+
// Note: crypto.hash is Node 20.12+
|
|
32
|
+
return crypto.hash(algorithm, s, 'buffer')
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
export function base64(s: string | Buffer): Base64String {
|