@checkdigit/hash 4.0.0 → 4.0.1-PR.28-41a4
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-mjs/hash.mjs +5 -2
- package/dist-mjs/uuid-v5.mjs +10 -3
- package/package.json +1 -63
- package/src/hash.ts +4 -1
- package/src/uuid-v5.ts +16 -4
package/dist-mjs/hash.mjs
CHANGED
|
@@ -3,10 +3,13 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import uuidV5 from "./uuid-v5.mjs";
|
|
4
4
|
var HASH_NAMESPACE = "f25d4515-fea7-44c7-8baf-f3ca50865e66";
|
|
5
5
|
function hash_default(value) {
|
|
6
|
-
return uuidV5(
|
|
6
|
+
return uuidV5(
|
|
7
|
+
createHash("sha512").update(value).digest("base64"),
|
|
8
|
+
HASH_NAMESPACE
|
|
9
|
+
);
|
|
7
10
|
}
|
|
8
11
|
export {
|
|
9
12
|
HASH_NAMESPACE,
|
|
10
13
|
hash_default as default
|
|
11
14
|
};
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2hhc2gudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBUUEsU0FBUyxrQkFBa0I7QUFFM0IsT0FBTyxZQUFZO0FBR1osSUFBTSxpQkFBaUI7QUFNZixTQUFSLGFBQWtCLE9BQXVCO0FBQzlDLFNBQU87QUFBQSxJQUNMLFdBQVcsUUFBUSxFQUFFLE9BQU8sS0FBSyxFQUFFLE9BQU8sUUFBUTtBQUFBLElBQ2xEO0FBQUEsRUFDRjtBQUNGOyIsCiAgIm5hbWVzIjogW10KfQo=
|
package/dist-mjs/uuid-v5.mjs
CHANGED
|
@@ -14,7 +14,8 @@ function parse(namespace) {
|
|
|
14
14
|
intArray[7] = value & 255;
|
|
15
15
|
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
16
16
|
intArray[9] = value & 255;
|
|
17
|
-
intArray[10] =
|
|
17
|
+
intArray[10] = // eslint-disable-next-line sonarjs/no-nested-assignment
|
|
18
|
+
(value = Number.parseInt(namespace.slice(24, 36), 16)) / 1099511627776 & 255;
|
|
18
19
|
intArray[11] = value / 4294967296 & 255;
|
|
19
20
|
intArray[12] = value >>> 24 & 255;
|
|
20
21
|
intArray[13] = value >>> 16 & 255;
|
|
@@ -27,9 +28,15 @@ function uuid_v5_default(value, namespace) {
|
|
|
27
28
|
buffer[6] = (buffer[6] ?? 0) & 15 | 80;
|
|
28
29
|
buffer[8] = (buffer[8] ?? 0) & 63 | 128;
|
|
29
30
|
const hex = buffer.toString("hex", 0, 16);
|
|
30
|
-
return [
|
|
31
|
+
return [
|
|
32
|
+
hex.slice(0, 8),
|
|
33
|
+
hex.slice(8, 12),
|
|
34
|
+
hex.slice(12, 16),
|
|
35
|
+
hex.slice(16, 20),
|
|
36
|
+
hex.slice(20, 32)
|
|
37
|
+
].join("-").toLowerCase();
|
|
31
38
|
}
|
|
32
39
|
export {
|
|
33
40
|
uuid_v5_default as default
|
|
34
41
|
};
|
|
35
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3V1aWQtdjUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBNkJBLFNBQVMsa0JBQWtCO0FBRzNCLFNBQVMsTUFBTSxXQUFtQjtBQUNoQyxNQUFJO0FBQ0osUUFBTSxXQUFXLElBQUksV0FBVyxFQUFFO0FBSWxDLFdBQVMsQ0FBQyxLQUFLLFFBQVEsT0FBTyxTQUFTLFVBQVUsTUFBTSxHQUFHLENBQUMsR0FBRyxFQUFFLE9BQU87QUFDdkUsV0FBUyxDQUFDLElBQUssVUFBVSxLQUFNO0FBQy9CLFdBQVMsQ0FBQyxJQUFLLFVB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EMsUUFBTSxNQUFNLE9BQU8sU0FBUyxPQUFPLEdBQUcsRUFBRTtBQUN4QyxTQUFPO0FBQUEsSUFDTCxJQUFJLE1BQU0sR0FBRyxDQUFDO0FBQUEsSUFDZCxJQUFJLE1BQU0sR0FBRyxFQUFFO0FBQUEsSUFDZixJQUFJLE1BQU0sSUFBSSxFQUFFO0FBQUEsSUFDaEIsSUFBSSxNQUFNLElBQUksRUFBRTtBQUFBLElBQ2hCLElBQUksTUFBTSxJQUFJLEVBQUU7QUFBQSxFQUNsQixFQUNHLEtBQUssR0FBRyxFQUNSLFlBQVk7QUFDakI7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
package/package.json
CHANGED
|
@@ -1,63 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/hash",
|
|
3
|
-
"version": "4.0.0",
|
|
4
|
-
"description": "Hash is a small function for Check Digit services to create a uuid derived from a hash generated from a given value.",
|
|
5
|
-
"homepage": "https://github.com/checkdigit/hash#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/checkdigit/hash/issues"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/checkdigit/hash.git"
|
|
12
|
-
},
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "Check Digit, LLC",
|
|
15
|
-
"sideEffects": false,
|
|
16
|
-
"type": "module",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"types": "./dist-types/index.d.ts",
|
|
20
|
-
"import": "./dist-mjs/index.mjs",
|
|
21
|
-
"default": "./dist-mjs/index.mjs"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"src",
|
|
26
|
-
"dist-types",
|
|
27
|
-
"dist-mjs",
|
|
28
|
-
"!src/**/*.test.ts",
|
|
29
|
-
"!src/**/*.spec.ts",
|
|
30
|
-
"!dist-types/**/*.test.d.ts",
|
|
31
|
-
"!dist-types/**/*.spec.d.ts",
|
|
32
|
-
"!dist-mjs/**/*.test.mjs",
|
|
33
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
34
|
-
"SECURITY.md"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
38
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
|
39
|
-
"ci:compile": "tsc --noEmit",
|
|
40
|
-
"ci:coverage": "rimraf coverage && mkdir coverage && node --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"",
|
|
41
|
-
"ci:lint": "npm run lint",
|
|
42
|
-
"ci:style": "npm run prettier",
|
|
43
|
-
"ci:test": "node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\"",
|
|
44
|
-
"coverage": "node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"",
|
|
45
|
-
"lint": "eslint --max-warnings 0 .",
|
|
46
|
-
"lint:fix": "eslint . --fix",
|
|
47
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
48
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
|
49
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
|
50
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
|
|
51
|
-
},
|
|
52
|
-
"prettier": "@checkdigit/prettier-config",
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@checkdigit/eslint-config": "^11.0.5",
|
|
55
|
-
"@checkdigit/prettier-config": "^6.1.0",
|
|
56
|
-
"@checkdigit/typescript-config": "^9.0.0",
|
|
57
|
-
"rimraf": "^6.0.1",
|
|
58
|
-
"uuid": "^11.0.5"
|
|
59
|
-
},
|
|
60
|
-
"engines": {
|
|
61
|
-
"node": ">=22.11"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
{"name":"@checkdigit/hash","version":"4.0.1-PR.28-41a4","description":"Hash is a small function for Check Digit services to create a uuid derived from a hash generated from a given value.","homepage":"https://github.com/checkdigit/hash#readme","bugs":{"url":"https://github.com/checkdigit/hash/issues"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/hash.git"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"rimraf coverage && mkdir coverage && node --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\"","coverage":"node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"","lint":"eslint --max-warnings 0 .","lint:fix":"eslint . --fix","prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","devDependencies":{"@checkdigit/eslint-config":"^11.0.5","@checkdigit/prettier-config":"^7.1.1","@checkdigit/typescript-config":"^9.0.0","rimraf":"^6.0.1","uuid":"^11.0.5"},"engines":{"node":">=22.11"}}
|
package/src/hash.ts
CHANGED
|
@@ -18,5 +18,8 @@ export const HASH_NAMESPACE = 'f25d4515-fea7-44c7-8baf-f3ca50865e66';
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export default function (value: string): string {
|
|
21
|
-
return uuidV5(
|
|
21
|
+
return uuidV5(
|
|
22
|
+
createHash('sha512').update(value).digest('base64'),
|
|
23
|
+
HASH_NAMESPACE,
|
|
24
|
+
);
|
|
22
25
|
}
|
package/src/uuid-v5.ts
CHANGED
|
@@ -58,8 +58,11 @@ function parse(namespace: string) {
|
|
|
58
58
|
|
|
59
59
|
// Parse ........-....-....-....-############
|
|
60
60
|
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
intArray[10] =
|
|
62
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
63
|
+
((value = Number.parseInt(namespace.slice(24, 36), 16)) /
|
|
64
|
+
0x1_00_00_00_00_00) &
|
|
65
|
+
0xff;
|
|
63
66
|
intArray[11] = (value / 0x1_00_00_00_00) & 0xff;
|
|
64
67
|
intArray[12] = (value >>> 24) & 0xff;
|
|
65
68
|
intArray[13] = (value >>> 16) & 0xff;
|
|
@@ -71,12 +74,21 @@ function parse(namespace: string) {
|
|
|
71
74
|
|
|
72
75
|
export default function (value: string, namespace: string): string {
|
|
73
76
|
// eslint-disable-next-line sonarjs/hashing
|
|
74
|
-
const buffer = createHash('sha1')
|
|
77
|
+
const buffer = createHash('sha1')
|
|
78
|
+
.update(parse(namespace))
|
|
79
|
+
.update(value)
|
|
80
|
+
.digest();
|
|
75
81
|
// note that undefined is treated as 0 by the & operator
|
|
76
82
|
buffer[6] = ((buffer[6] ?? 0) & 0x0f) | 0x50;
|
|
77
83
|
buffer[8] = ((buffer[8] ?? 0) & 0x3f) | 0x80;
|
|
78
84
|
const hex = buffer.toString('hex', 0, 16);
|
|
79
|
-
return [
|
|
85
|
+
return [
|
|
86
|
+
hex.slice(0, 8),
|
|
87
|
+
hex.slice(8, 12),
|
|
88
|
+
hex.slice(12, 16),
|
|
89
|
+
hex.slice(16, 20),
|
|
90
|
+
hex.slice(20, 32),
|
|
91
|
+
]
|
|
80
92
|
.join('-')
|
|
81
93
|
.toLowerCase();
|
|
82
94
|
}
|