@checkdigit/hash 3.0.1-PR.24-c15c → 4.0.0-PR.26-d40a
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.txt +1 -1
- package/README.md +5 -5
- package/SECURITY.md +2 -2
- package/dist-mjs/uuid-v5.mjs +3 -2
- package/dist-types/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/hash.ts +2 -2
- package/src/index.ts +3 -3
- package/src/uuid-v5.ts +8 -2
package/LICENSE.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
The MIT License
|
|
3
3
|
|
|
4
|
-
Copyright (c) 2021-
|
|
4
|
+
Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# Hash
|
|
2
2
|
|
|
3
|
-
Copyright
|
|
3
|
+
Copyright © 2021-2025 [Check Digit, LLC](https://checkdigit.com)
|
|
4
4
|
|
|
5
5
|
Hash is a small function for Check Digit services to create a UUID derived from a hash generated from a given value.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```shell
|
|
10
10
|
$ npm install @checkdigit/hash
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Use
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```ts
|
|
16
16
|
import { hash } from '@checkdigit/hash';
|
|
17
17
|
|
|
18
18
|
const derivedUUID = hash('some value');
|
package/SECURITY.md
CHANGED
|
@@ -6,8 +6,8 @@ These versions of @checkdigit/hash are currently being supported with security u
|
|
|
6
6
|
|
|
7
7
|
| Version | Supported |
|
|
8
8
|
| ------- | ------------------ |
|
|
9
|
-
| >
|
|
10
|
-
| <
|
|
9
|
+
| > 4.x | :white_check_mark: |
|
|
10
|
+
| < 4.0 | :x: |
|
|
11
11
|
|
|
12
12
|
## Reporting a Vulnerability
|
|
13
13
|
|
package/dist-mjs/uuid-v5.mjs
CHANGED
|
@@ -7,7 +7,8 @@ function parse(namespace) {
|
|
|
7
7
|
intArray[1] = value >>> 16 & 255;
|
|
8
8
|
intArray[2] = value >>> 8 & 255;
|
|
9
9
|
intArray[3] = value & 255;
|
|
10
|
-
|
|
10
|
+
value = Number.parseInt(namespace.slice(9, 13), 16);
|
|
11
|
+
intArray[4] = value >>> 8;
|
|
11
12
|
intArray[5] = value & 255;
|
|
12
13
|
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
13
14
|
intArray[7] = value & 255;
|
|
@@ -31,4 +32,4 @@ function uuid_v5_default(value, namespace) {
|
|
|
31
32
|
export {
|
|
32
33
|
uuid_v5_default as default
|
|
33
34
|
};
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3V1aWQtdjUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBNkJBLFNBQVMsa0JBQWtCO0FBRzNCLFNBQVMsTUFBTSxXQUFtQjtBQUNoQyxNQUFJO0FBQ0osUUFBTSxXQUFXLElBQUksV0FBVyxFQUFFO0FBSWxDLFdBQVMsQ0FBQyxLQUFLLFFBQVEsT0FBTyxTQUFTLFVBQVUsTUFBTSxHQUFHLENBQUMsR0FBRyxFQUFFLE9BQU87QUFDdkUsV0FBUyxDQUFDLElBQUssVUFBVSxLQUFNO0FBQy9CLFdBQVMsQ0FBQyxJQUFLLFVBQVUsSUFBSztBQUM5QixXQUFTLENBQUMsSUFBSSxRQUFRO0FBR3RCLFVBQVEsT0FBTyxTQUFTLFVBQVUsTUFBTSxHQUFHLEVBQUUsR0FBRyxFQUFFO0FBQ2xELFdBQVMsQ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csSUFBSSxNQUFNLElBQUksRUFBRSxHQUFHLElBQUksTUFBTSxJQUFJLEVBQUUsR0FBRyxJQUFJLE1BQU0sSUFBSSxFQUFFLENBQUMsRUFDL0YsS0FBSyxHQUFHLEVBQ1IsWUFBWTtBQUNqQjsiLAogICJuYW1lcyI6IFtdCn0K
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './hash';
|
|
2
|
-
export { default as hash, HASH_NAMESPACE } from './hash';
|
|
1
|
+
export { default } from './hash.ts';
|
|
2
|
+
export { default as hash, HASH_NAMESPACE } from './hash.ts';
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/hash","version":"
|
|
1
|
+
{"name":"@checkdigit/hash","version":"4.0.0-PR.26-d40a","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":"^6.1.0","@checkdigit/typescript-config":"^9.0.0","rimraf":"^6.0.1","uuid":"^11.0.5"},"engines":{"node":">=22.11"}}
|
package/src/hash.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// hash.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2021-
|
|
4
|
+
* Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
10
|
|
|
11
|
-
import uuidV5 from './uuid-v5';
|
|
11
|
+
import uuidV5 from './uuid-v5.ts';
|
|
12
12
|
|
|
13
13
|
// eslint-disable-next-line @checkdigit/no-uuid
|
|
14
14
|
export const HASH_NAMESPACE = 'f25d4515-fea7-44c7-8baf-f3ca50865e66';
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2021-
|
|
4
|
+
* Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export { default } from './hash';
|
|
10
|
-
export { default as hash, HASH_NAMESPACE } from './hash';
|
|
9
|
+
export { default } from './hash.ts';
|
|
10
|
+
export { default as hash, HASH_NAMESPACE } from './hash.ts';
|
package/src/uuid-v5.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// uuid-v5.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2021-
|
|
4
|
+
* Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is derived from https://github.com/uuidjs/uuid,
|
|
7
7
|
* licensed under the MIT license (see below for details).
|
|
@@ -35,25 +35,30 @@ function parse(namespace: string) {
|
|
|
35
35
|
const intArray = new Uint8Array(16);
|
|
36
36
|
|
|
37
37
|
// Parse ########-....-....-....-............
|
|
38
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
38
39
|
intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;
|
|
39
40
|
intArray[1] = (value >>> 16) & 0xff;
|
|
40
41
|
intArray[2] = (value >>> 8) & 0xff;
|
|
41
42
|
intArray[3] = value & 0xff;
|
|
42
43
|
|
|
43
44
|
// Parse ........-####-....-....-............
|
|
44
|
-
|
|
45
|
+
value = Number.parseInt(namespace.slice(9, 13), 16);
|
|
46
|
+
intArray[4] = value >>> 8;
|
|
45
47
|
intArray[5] = value & 0xff;
|
|
46
48
|
|
|
47
49
|
// Parse ........-....-####-....-............
|
|
50
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
48
51
|
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
49
52
|
intArray[7] = value & 0xff;
|
|
50
53
|
|
|
51
54
|
// Parse ........-....-....-####-............
|
|
55
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
52
56
|
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
53
57
|
intArray[9] = value & 0xff;
|
|
54
58
|
|
|
55
59
|
// Parse ........-....-....-....-############
|
|
56
60
|
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
61
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
57
62
|
intArray[10] = ((value = Number.parseInt(namespace.slice(24, 36), 16)) / 0x1_00_00_00_00_00) & 0xff;
|
|
58
63
|
intArray[11] = (value / 0x1_00_00_00_00) & 0xff;
|
|
59
64
|
intArray[12] = (value >>> 24) & 0xff;
|
|
@@ -65,6 +70,7 @@ function parse(namespace: string) {
|
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
export default function (value: string, namespace: string): string {
|
|
73
|
+
// eslint-disable-next-line sonarjs/hashing
|
|
68
74
|
const buffer = createHash('sha1').update(parse(namespace)).update(value).digest();
|
|
69
75
|
// note that undefined is treated as 0 by the & operator
|
|
70
76
|
buffer[6] = ((buffer[6] ?? 0) & 0x0f) | 0x50;
|