@checkdigit/hash 1.0.0 → 2.0.0-PR.14-2bb3
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 +0 -1
- package/SECURITY.md +14 -0
- package/dist/hash.d.ts +6 -5
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +24 -0
- package/dist/hash.js.map +1 -0
- package/dist/hash.spec.d.ts +2 -0
- package/dist/hash.spec.d.ts.map +1 -0
- package/dist/hash.spec.js +36 -0
- package/dist/hash.spec.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -0
- package/dist/{uuidV5.d.ts → uuid-v5.d.ts} +2 -1
- package/dist/uuid-v5.d.ts.map +1 -0
- package/dist/uuid-v5.js +71 -0
- package/dist/uuid-v5.js.map +1 -0
- package/dist/uuid-v5.spec.d.ts +2 -0
- package/dist/uuid-v5.spec.d.ts.map +1 -0
- package/dist/uuid-v5.spec.js +48 -0
- package/dist/uuid-v5.spec.js.map +1 -0
- package/package.json +1 -57
- package/src/hash.ts +22 -0
- package/src/index.ts +10 -0
- package/src/uuid-v5.ts +77 -0
- package/.github/workflows/codeql-analysis.yml +0 -67
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
package/SECURITY.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
These versions of @checkdigit/hash are currently being supported with security updates.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | ------------------ |
|
|
9
|
+
| > 2.x | :white_check_mark: |
|
|
10
|
+
| < 2.0 | :x: |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
Please create an issue at https://github.com/checkdigit/hash/issues
|
package/dist/hash.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare const HASH_NAMESPACE = "f25d4515-fea7-44c7-8baf-f3ca50865e66";
|
|
2
|
-
/**
|
|
3
|
-
* @param value - a string to be hashed and converted into a derived uuid
|
|
4
|
-
*/
|
|
5
|
-
export default function (value: string): string;
|
|
1
|
+
export declare const HASH_NAMESPACE = "f25d4515-fea7-44c7-8baf-f3ca50865e66";
|
|
2
|
+
/**
|
|
3
|
+
* @param value - a string to be hashed and converted into a derived uuid
|
|
4
|
+
*/
|
|
5
|
+
export default function (value: string): string;
|
|
6
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,cAAc,yCAAyC,CAAC;AAErE;;GAEG;AAEH,MAAM,CAAC,OAAO,WAAW,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// hash.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HASH_NAMESPACE = void 0;
|
|
8
|
+
/*
|
|
9
|
+
* Copyright (c) 2021-2023 Check Digit, LLC
|
|
10
|
+
*
|
|
11
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
12
|
+
*/
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
const uuid_v5_1 = __importDefault(require("./uuid-v5"));
|
|
15
|
+
// eslint-disable-next-line @checkdigit/no-uuid
|
|
16
|
+
exports.HASH_NAMESPACE = 'f25d4515-fea7-44c7-8baf-f3ca50865e66';
|
|
17
|
+
/**
|
|
18
|
+
* @param value - a string to be hashed and converted into a derived uuid
|
|
19
|
+
*/
|
|
20
|
+
function default_1(value) {
|
|
21
|
+
return (0, uuid_v5_1.default)((0, node_crypto_1.createHash)('sha512').update(value).digest('base64'), exports.HASH_NAMESPACE);
|
|
22
|
+
}
|
|
23
|
+
exports.default = default_1;
|
|
24
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA,UAAU;;;;;;AAEV;;;;GAIG;AAEH,6CAAyC;AAEzC,wDAA+B;AAE/B,+CAA+C;AAClC,QAAA,cAAc,GAAG,sCAAsC,CAAC;AAErE;;GAEG;AAEH,mBAAyB,KAAa;IACpC,OAAO,IAAA,iBAAM,EAAC,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,sBAAc,CAAC,CAAC;AACrF,CAAC;AAFD,4BAEC","sourcesContent":["// hash.ts\n\n/*\n * Copyright (c) 2021-2023 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport { createHash } from 'node:crypto';\n\nimport uuidV5 from './uuid-v5';\n\n// eslint-disable-next-line @checkdigit/no-uuid\nexport const HASH_NAMESPACE = 'f25d4515-fea7-44c7-8baf-f3ca50865e66';\n\n/**\n * @param value - a string to be hashed and converted into a derived uuid\n */\n\nexport default function (value: string): string {\n return uuidV5(createHash('sha512').update(value).digest('base64'), HASH_NAMESPACE);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.spec.d.ts","sourceRoot":"","sources":["../src/hash.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// hash.spec.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2021-2023 Check Digit, LLC
|
|
9
|
+
*
|
|
10
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
11
|
+
*/
|
|
12
|
+
const node_assert_1 = require("node:assert");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const hash_1 = __importDefault(require("./hash"));
|
|
15
|
+
describe('hash', () => {
|
|
16
|
+
it('returns a uuid derived from hash of value', () => {
|
|
17
|
+
const result1 = (0, hash_1.default)('string to be hashed into a uuid');
|
|
18
|
+
const result2 = (0, hash_1.default)('string to be hashed into a uuid');
|
|
19
|
+
node_assert_1.strict.ok((0, uuid_1.validate)(result1) && (0, uuid_1.validate)(result2));
|
|
20
|
+
node_assert_1.strict.equal(result1, result2);
|
|
21
|
+
});
|
|
22
|
+
it('hash always returns the same value', () => {
|
|
23
|
+
node_assert_1.strict.equal((0, hash_1.default)('Hello World!'), '74caf525-c85a-5a3c-9d53-bef0507c21e4');
|
|
24
|
+
node_assert_1.strict.equal((0, hash_1.default)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55'), '14abff19-2c5f-5408-af3d-3c6526ebea73');
|
|
25
|
+
node_assert_1.strict.equal((0, hash_1.default)('Råma Ghantå'), '8a28bfef-8fa2-52de-b9c5-1d5a6d7ba5fe');
|
|
26
|
+
node_assert_1.strict.equal(
|
|
27
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
28
|
+
(0, hash_1.default)('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1'), '7cb123ec-2c42-5a8a-b358-adf113ee088d');
|
|
29
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
30
|
+
node_assert_1.strict.equal((0, hash_1.default)('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE='), 'e90938db-61fb-55b4-8ebe-4e1518e4fe97');
|
|
31
|
+
// eslint-disable-next-line @checkdigit/no-card-numbers
|
|
32
|
+
node_assert_1.strict.equal((0, hash_1.default)('5111111111111118'), '87e25c4b-c395-585e-9ecf-43d190f6e62f');
|
|
33
|
+
node_assert_1.strict.equal((0, hash_1.default)('https://checkdigit.com'), '2c391f52-ec24-5945-8c28-88f74d12b55d');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=hash.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.spec.js","sourceRoot":"","sources":["../src/hash.spec.ts"],"names":[],"mappings":";AAAA,eAAe;;;;;AAEf;;;;GAIG;AAEH,6CAA+C;AAC/C,+BAAgC;AAEhC,kDAA0B;AAE1B,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,OAAO,GAAG,IAAA,cAAI,EAAC,iCAAiC,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,IAAA,cAAI,EAAC,iCAAiC,CAAC,CAAC;QACxD,oBAAM,CAAC,EAAE,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,IAAI,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,CAAC;QAClD,oBAAM,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,cAAc,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAC3E,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,sCAAsC,CAAC,EAAE,sCAAsC,CAAC,CAAC;QACnG,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,aAAa,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAC1E,oBAAM,CAAC,KAAK;QACV,iDAAiD;QACjD,IAAA,cAAI,EAAC,kEAAkE,CAAC,EACxE,sCAAsC,CACvC,CAAC;QACF,iDAAiD;QACjD,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,8CAA8C,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAC3G,uDAAuD;QACvD,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,kBAAkB,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAC/E,oBAAM,CAAC,KAAK,CAAC,IAAA,cAAI,EAAC,wBAAwB,CAAC,EAAE,sCAAsC,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// hash.spec.ts\n\n/*\n * Copyright (c) 2021-2023 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport { strict as assert } from 'node:assert';\nimport { validate } from 'uuid';\n\nimport hash from './hash';\n\ndescribe('hash', () => {\n it('returns a uuid derived from hash of value', () => {\n const result1 = hash('string to be hashed into a uuid');\n const result2 = hash('string to be hashed into a uuid');\n assert.ok(validate(result1) && validate(result2));\n assert.equal(result1, result2);\n });\n\n it('hash always returns the same value', () => {\n assert.equal(hash('Hello World!'), '74caf525-c85a-5a3c-9d53-bef0507c21e4');\n assert.equal(hash('d1253ec1-14bc-4c56-8e09-4450ab4c8a55'), '14abff19-2c5f-5408-af3d-3c6526ebea73');\n assert.equal(hash('Råma Ghantå'), '8a28bfef-8fa2-52de-b9c5-1d5a6d7ba5fe');\n assert.equal(\n // eslint-disable-next-line no-secrets/no-secrets\n hash('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1'),\n '7cb123ec-2c42-5a8a-b358-adf113ee088d'\n );\n // eslint-disable-next-line no-secrets/no-secrets\n assert.equal(hash('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE='), 'e90938db-61fb-55b4-8ebe-4e1518e4fe97');\n // eslint-disable-next-line @checkdigit/no-card-numbers\n assert.equal(hash('5111111111111118'), '87e25c4b-c395-585e-9ecf-43d190f6e62f');\n assert.equal(hash('https://checkdigit.com'), '2c391f52-ec24-5945-8c28-88f74d12b55d');\n });\n});\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { default } from './hash';
|
|
2
|
-
export { default as hash, HASH_NAMESPACE } from './hash';
|
|
1
|
+
export { default } from './hash';
|
|
2
|
+
export { default as hash, HASH_NAMESPACE } from './hash';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
// index.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HASH_NAMESPACE = exports.hash = exports.default = void 0;
|
|
8
|
+
/*
|
|
9
|
+
* Copyright (c) 2021-2023 Check Digit, LLC
|
|
10
|
+
*
|
|
11
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
12
|
+
*/
|
|
13
|
+
var hash_1 = require("./hash");
|
|
14
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(hash_1).default; } });
|
|
15
|
+
var hash_2 = require("./hash");
|
|
16
|
+
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return __importDefault(hash_2).default; } });
|
|
17
|
+
Object.defineProperty(exports, "HASH_NAMESPACE", { enumerable: true, get: function () { return hash_2.HASH_NAMESPACE; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,WAAW;;;;;;AAEX;;;;GAIG;AAEH,+BAAiC;AAAxB,gHAAA,OAAO,OAAA;AAChB,+BAAyD;AAAhD,6GAAA,OAAO,OAAQ;AAAE,sGAAA,cAAc,OAAA","sourcesContent":["// index.ts\n\n/*\n * Copyright (c) 2021-2023 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nexport { default } from './hash';\nexport { default as hash, HASH_NAMESPACE } from './hash';\n"]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export default function (value: string, namespace: string): string;
|
|
1
|
+
export default function (value: string, namespace: string): string;
|
|
2
|
+
//# sourceMappingURL=uuid-v5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-v5.d.ts","sourceRoot":"","sources":["../src/uuid-v5.ts"],"names":[],"mappings":"AAkEA,MAAM,CAAC,OAAO,WAAW,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CASjE"}
|
package/dist/uuid-v5.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// uuid-v5.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2021 Check Digit, LLC
|
|
6
|
+
*
|
|
7
|
+
* This code is derived from https://github.com/uuidjs/uuid,
|
|
8
|
+
* licensed under the MIT license (see below for details).
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in
|
|
20
|
+
* all copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
28
|
+
* THE SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
const node_crypto_1 = require("node:crypto");
|
|
31
|
+
/* eslint-disable no-bitwise,no-magic-numbers */
|
|
32
|
+
function parse(namespace) {
|
|
33
|
+
let value;
|
|
34
|
+
const intArray = new Uint8Array(16);
|
|
35
|
+
// Parse ########-....-....-....-............
|
|
36
|
+
intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;
|
|
37
|
+
intArray[1] = (value >>> 16) & 0xff;
|
|
38
|
+
intArray[2] = (value >>> 8) & 0xff;
|
|
39
|
+
intArray[3] = value & 0xff;
|
|
40
|
+
// Parse ........-####-....-....-............
|
|
41
|
+
intArray[4] = (value = Number.parseInt(namespace.slice(9, 13), 16)) >>> 8;
|
|
42
|
+
intArray[5] = value & 0xff;
|
|
43
|
+
// Parse ........-....-####-....-............
|
|
44
|
+
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
45
|
+
intArray[7] = value & 0xff;
|
|
46
|
+
// Parse ........-....-....-####-............
|
|
47
|
+
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
48
|
+
intArray[9] = value & 0xff;
|
|
49
|
+
// Parse ........-....-....-....-############
|
|
50
|
+
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
51
|
+
intArray[10] = ((value = Number.parseInt(namespace.slice(24, 36), 16)) / 0x1_00_00_00_00_00) & 0xff;
|
|
52
|
+
intArray[11] = (value / 0x1_00_00_00_00) & 0xff;
|
|
53
|
+
intArray[12] = (value >>> 24) & 0xff;
|
|
54
|
+
intArray[13] = (value >>> 16) & 0xff;
|
|
55
|
+
intArray[14] = (value >>> 8) & 0xff;
|
|
56
|
+
intArray[15] = value & 0xff;
|
|
57
|
+
return intArray;
|
|
58
|
+
}
|
|
59
|
+
function default_1(value, namespace) {
|
|
60
|
+
const buffer = (0, node_crypto_1.createHash)('sha1').update(parse(namespace)).update(value).digest();
|
|
61
|
+
// note that undefined is treated as 0 by the & operator
|
|
62
|
+
buffer[6] = ((buffer[6] ?? 0) & 0x0f) | 0x50;
|
|
63
|
+
buffer[8] = ((buffer[8] ?? 0) & 0x3f) | 0x80;
|
|
64
|
+
const hex = buffer.toString('hex', 0, 16);
|
|
65
|
+
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)]
|
|
66
|
+
.join('-')
|
|
67
|
+
.toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
exports.default = default_1;
|
|
70
|
+
/* eslint-enable no-bitwise,no-magic-numbers */
|
|
71
|
+
//# sourceMappingURL=uuid-v5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SAChG,IAAI,CAAC,GAAG,CAAC;SACT,WAAW,EAAE,CAAC;AACnB,CAAC;AATD,4BASC;AACD,+CAA+C","sourcesContent":["// uuid-v5.ts\n\n/*\n * Copyright (c) 2021 Check Digit, LLC\n *\n * This code is derived from https://github.com/uuidjs/uuid,\n * licensed under the MIT license (see below for details).\n *\n * Copyright (c) 2010-2020 Robert Kieffer and other contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nimport { createHash } from 'node:crypto';\n\n/* eslint-disable no-bitwise,no-magic-numbers */\nfunction parse(namespace: string) {\n let value;\n const intArray = new Uint8Array(16);\n\n // Parse ########-....-....-....-............\n intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;\n intArray[1] = (value >>> 16) & 0xff;\n intArray[2] = (value >>> 8) & 0xff;\n intArray[3] = value & 0xff;\n\n // Parse ........-####-....-....-............\n intArray[4] = (value = Number.parseInt(namespace.slice(9, 13), 16)) >>> 8;\n intArray[5] = value & 0xff;\n\n // Parse ........-....-####-....-............\n intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;\n intArray[7] = value & 0xff;\n\n // Parse ........-....-....-####-............\n intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;\n intArray[9] = value & 0xff;\n\n // Parse ........-....-....-....-############\n // (Use \"/\" to avoid 32-bit truncation when bit-shifting high-order bytes)\n intArray[10] = ((value = Number.parseInt(namespace.slice(24, 36), 16)) / 0x1_00_00_00_00_00) & 0xff;\n intArray[11] = (value / 0x1_00_00_00_00) & 0xff;\n intArray[12] = (value >>> 24) & 0xff;\n intArray[13] = (value >>> 16) & 0xff;\n intArray[14] = (value >>> 8) & 0xff;\n intArray[15] = value & 0xff;\n\n return intArray;\n}\n\nexport default function (value: string, namespace: string): string {\n const buffer = createHash('sha1').update(parse(namespace)).update(value).digest();\n // note that undefined is treated as 0 by the & operator\n buffer[6] = ((buffer[6] ?? 0) & 0x0f) | 0x50;\n buffer[8] = ((buffer[8] ?? 0) & 0x3f) | 0x80;\n const hex = buffer.toString('hex', 0, 16);\n return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)]\n .join('-')\n .toLowerCase();\n}\n/* eslint-enable no-bitwise,no-magic-numbers */\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-v5.spec.d.ts","sourceRoot":"","sources":["../src/uuid-v5.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// uuid-v5.spec.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2021-2023 Check Digit, LLC
|
|
9
|
+
*
|
|
10
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
11
|
+
*/
|
|
12
|
+
const node_assert_1 = require("node:assert");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const hash_1 = require("./hash");
|
|
15
|
+
const uuid_v5_1 = __importDefault(require("./uuid-v5"));
|
|
16
|
+
describe('uuidV5', () => {
|
|
17
|
+
it('uuidV5 result matches v5(https://github.com/uuidjs/uuid) result', () => {
|
|
18
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('Hello World!', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('Hello World!', hash_1.HASH_NAMESPACE));
|
|
19
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', hash_1.HASH_NAMESPACE));
|
|
20
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', hash_1.HASH_NAMESPACE));
|
|
21
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', hash_1.HASH_NAMESPACE));
|
|
22
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('Råma Ghantå', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('Råma Ghantå', hash_1.HASH_NAMESPACE));
|
|
23
|
+
node_assert_1.strict.equal(
|
|
24
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
25
|
+
(0, uuid_v5_1.default)('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', hash_1.HASH_NAMESPACE),
|
|
26
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
27
|
+
(0, uuid_1.v5)('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', hash_1.HASH_NAMESPACE));
|
|
28
|
+
node_assert_1.strict.equal(
|
|
29
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
30
|
+
(0, uuid_v5_1.default)('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', hash_1.HASH_NAMESPACE),
|
|
31
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
32
|
+
(0, uuid_1.v5)('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', hash_1.HASH_NAMESPACE));
|
|
33
|
+
// eslint-disable-next-line @checkdigit/no-card-numbers
|
|
34
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('5111111111111118', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('5111111111111118', hash_1.HASH_NAMESPACE));
|
|
35
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('https://checkdigit.com', hash_1.HASH_NAMESPACE), (0, uuid_1.v5)('https://checkdigit.com', hash_1.HASH_NAMESPACE));
|
|
36
|
+
});
|
|
37
|
+
it('v5 - from https://github.com/uuidjs/uuid testing', () => {
|
|
38
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('hello.example.com', uuid_1.v5.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
39
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('http://example.com/hello', uuid_1.v5.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
40
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');
|
|
41
|
+
});
|
|
42
|
+
it('v5 namespace.toUpperCase - from https://github.com/uuidjs/uuid testing', () => {
|
|
43
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('hello.example.com', uuid_1.v5.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
44
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('http://example.com/hello', uuid_1.v5.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
45
|
+
node_assert_1.strict.equal((0, uuid_v5_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), '90123e1c-7512-523e-bb28-76fab9f2f73d');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=uuid-v5.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-v5.spec.js","sourceRoot":"","sources":["../src/uuid-v5.spec.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;;;AAElB;;;;GAIG;AAEH,6CAA+C;AAC/C,+BAA0B;AAE1B,iCAAwC;AACxC,wDAA+B;AAE/B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACzE,oBAAM,CAAC,KAAK,C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AAc,CAAC,EAAE,IAAA,SAAE,EAAC,wBAAwB,EAAE,qBAAc,CAAC,CAAC,CAAC;IAC/G,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,oBAAM,CAAC,KAAK,CAAC,IAAA,iBAAM,EAAC,mBAAmB,EAAE,SAAE,CAAC,GAAG,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAE1F,oBAAM,CAAC,KAAK,CAAC,IAAA,iBAAM,EAAC,0BAA0B,EAAE,SAAE,CAAC,GAAG,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAEjG,oBAAM,CAAC,KAAK,CAAC,IAAA,iBAAM,EAAC,OAAO,EAAE,sCAAsC,CAAC,EAAE,sCAAsC,CAAC,CAAC;IAChH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QAChF,oBAAM,CAAC,KAAK,CAAC,IAAA,iBAAM,EAAC,mBAAmB,EAAE,SAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAExG,oBAAM,CAAC,KAAK,CAAC,IAAA,iBAAM,EAAC,0BAA0B,EAAE,SAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,sCAAsC,CAAC,CAAC;QAE/G,oBAAM,CAAC,KAAK,CACV,IAAA,iBAAM,EAAC,OAAO,EAAE,sCAAsC,CAAC,WAAW,EAAE,CAAC,EACrE,sCAAsC,CACvC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// uuid-v5.spec.ts\n\n/*\n * Copyright (c) 2021-2023 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport { strict as assert } from 'node:assert';\nimport { v5 } from 'uuid';\n\nimport { HASH_NAMESPACE } from './hash';\nimport uuidV5 from './uuid-v5';\n\ndescribe('uuidV5', () => {\n it('uuidV5 result matches v5(https://github.com/uuidjs/uuid) result', () => {\n assert.equal(uuidV5('Hello World!', HASH_NAMESPACE), v5('Hello World!', HASH_NAMESPACE));\n assert.equal(\n uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', HASH_NAMESPACE),\n v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', HASH_NAMESPACE)\n );\n assert.equal(\n uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', HASH_NAMESPACE),\n v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', HASH_NAMESPACE)\n );\n assert.equal(\n uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', HASH_NAMESPACE),\n v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', HASH_NAMESPACE)\n );\n assert.equal(uuidV5('Råma Ghantå', HASH_NAMESPACE), v5('Råma Ghantå', HASH_NAMESPACE));\n assert.equal(\n // eslint-disable-next-line no-secrets/no-secrets\n uuidV5('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', HASH_NAMESPACE),\n // eslint-disable-next-line no-secrets/no-secrets\n v5('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', HASH_NAMESPACE)\n );\n assert.equal(\n // eslint-disable-next-line no-secrets/no-secrets\n uuidV5('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', HASH_NAMESPACE),\n // eslint-disable-next-line no-secrets/no-secrets\n v5('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', HASH_NAMESPACE)\n );\n // eslint-disable-next-line @checkdigit/no-card-numbers\n assert.equal(uuidV5('5111111111111118', HASH_NAMESPACE), v5('5111111111111118', HASH_NAMESPACE));\n assert.equal(uuidV5('https://checkdigit.com', HASH_NAMESPACE), v5('https://checkdigit.com', HASH_NAMESPACE));\n });\n\n it('v5 - from https://github.com/uuidjs/uuid testing', () => {\n assert.equal(uuidV5('hello.example.com', v5.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');\n\n assert.equal(uuidV5('http://example.com/hello', v5.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');\n\n assert.equal(uuidV5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');\n });\n\n it('v5 namespace.toUpperCase - from https://github.com/uuidjs/uuid testing', () => {\n assert.equal(uuidV5('hello.example.com', v5.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');\n\n assert.equal(uuidV5('http://example.com/hello', v5.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');\n\n assert.equal(\n uuidV5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()),\n '90123e1c-7512-523e-bb28-76fab9f2f73d'\n );\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/hash",
|
|
3
|
-
"version": "1.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
|
-
"typings": "./dist/index.d.ts",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"prettier": "@checkdigit/prettier-config",
|
|
8
|
-
"engines": {
|
|
9
|
-
"node": ">=12.18",
|
|
10
|
-
"npm": ">=6.14"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/checkdigit/hash.git"
|
|
15
|
-
},
|
|
16
|
-
"author": "Check Digit, LLC",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"bugs": {
|
|
19
|
-
"url": "https://github.com/checkdigit/hash/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/checkdigit/hash#readme",
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@checkdigit/eslint-config": "3.4.2",
|
|
24
|
-
"@checkdigit/prettier-config": "^1.0.2",
|
|
25
|
-
"@checkdigit/publish": "^1.0.18",
|
|
26
|
-
"@checkdigit/typescript-config": "^1.0.5",
|
|
27
|
-
"@types/jest": "^26.0.21",
|
|
28
|
-
"@types/uuid": "^8.3.0",
|
|
29
|
-
"eslint": "^7.22.0",
|
|
30
|
-
"jest": "^26.6.3",
|
|
31
|
-
"prettier": "^2.2.1",
|
|
32
|
-
"rimraf": "^3.0.2",
|
|
33
|
-
"ts-jest": "^26.5.4",
|
|
34
|
-
"typescript": "^4.2.3",
|
|
35
|
-
"uuid": "^8.3.2"
|
|
36
|
-
},
|
|
37
|
-
"jest": {
|
|
38
|
-
"collectCoverage": true,
|
|
39
|
-
"preset": "ts-jest",
|
|
40
|
-
"testPathIgnorePatterns": [
|
|
41
|
-
"<rootDir>/build/",
|
|
42
|
-
"<rootDir>/node_modules/"
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"prepublishOnly": "publish",
|
|
47
|
-
"postpublish": "rimraf dist .npmignore",
|
|
48
|
-
"preversion": "npm test",
|
|
49
|
-
"postversion": "git push && git push --tags",
|
|
50
|
-
"lint": "eslint -f unix 'src/**/*.ts'",
|
|
51
|
-
"lint:fix": "eslint -f unix 'src/**/*.ts' --fix",
|
|
52
|
-
"prettier": "prettier --list-different 'src/**/*.ts'",
|
|
53
|
-
"prettier:fix": "prettier --write 'src/**/*.ts'",
|
|
54
|
-
"test": "tsc --noEmit && jest && npm run prettier && npm run lint"
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {}
|
|
57
|
-
}
|
|
1
|
+
{"name":"@checkdigit/hash","version":"2.0.0-PR.14-2bb3","description":"Hash is a small function for Check Digit services to create a uuid derived from a hash generated from a given value.","typings":"./dist/index.d.ts","main":"./dist/index.js","files":["dist","SECURITY.md","/src/"],"prettier":"@checkdigit/prettier-config","engines":{"node":">=16"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/hash.git"},"author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/hash/issues"},"homepage":"https://github.com/checkdigit/hash#readme","devDependencies":{"@checkdigit/eslint-config":"^7.8.0","@checkdigit/jest-config":"^2.2.1","@checkdigit/prettier-config":"^3.4.0","@checkdigit/typescript-config":"^3.4.0","@types/uuid":"^9.0.1","rimraf":"^5.0.1","uuid":"^9.0.0"},"eslintConfig":{"extends":["@checkdigit/eslint-config"]},"jest":{"preset":"@checkdigit/jest-config"},"scripts":{"prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","lint:fix":"eslint -f unix --ext .ts,.mts src --fix","lint":"eslint -f unix --ext .ts,.mts src","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"jest --coverage=false","ci:coverage":"jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier"}}
|
package/src/hash.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// hash.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2021-2023 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
|
|
11
|
+
import uuidV5 from './uuid-v5';
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @checkdigit/no-uuid
|
|
14
|
+
export const HASH_NAMESPACE = 'f25d4515-fea7-44c7-8baf-f3ca50865e66';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param value - a string to be hashed and converted into a derived uuid
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export default function (value: string): string {
|
|
21
|
+
return uuidV5(createHash('sha512').update(value).digest('base64'), HASH_NAMESPACE);
|
|
22
|
+
}
|
package/src/index.ts
ADDED
package/src/uuid-v5.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// uuid-v5.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2021 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is derived from https://github.com/uuidjs/uuid,
|
|
7
|
+
* licensed under the MIT license (see below for details).
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
* in the Software without restriction, including without limitation the rights
|
|
14
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
* furnished to do so, subject to the following conditions:
|
|
17
|
+
*
|
|
18
|
+
* The above copyright notice and this permission notice shall be included in
|
|
19
|
+
* all copies or substantial portions of the Software.
|
|
20
|
+
*
|
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
27
|
+
* THE SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { createHash } from 'node:crypto';
|
|
31
|
+
|
|
32
|
+
/* eslint-disable no-bitwise,no-magic-numbers */
|
|
33
|
+
function parse(namespace: string) {
|
|
34
|
+
let value;
|
|
35
|
+
const intArray = new Uint8Array(16);
|
|
36
|
+
|
|
37
|
+
// Parse ########-....-....-....-............
|
|
38
|
+
intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;
|
|
39
|
+
intArray[1] = (value >>> 16) & 0xff;
|
|
40
|
+
intArray[2] = (value >>> 8) & 0xff;
|
|
41
|
+
intArray[3] = value & 0xff;
|
|
42
|
+
|
|
43
|
+
// Parse ........-####-....-....-............
|
|
44
|
+
intArray[4] = (value = Number.parseInt(namespace.slice(9, 13), 16)) >>> 8;
|
|
45
|
+
intArray[5] = value & 0xff;
|
|
46
|
+
|
|
47
|
+
// Parse ........-....-####-....-............
|
|
48
|
+
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
49
|
+
intArray[7] = value & 0xff;
|
|
50
|
+
|
|
51
|
+
// Parse ........-....-....-####-............
|
|
52
|
+
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
53
|
+
intArray[9] = value & 0xff;
|
|
54
|
+
|
|
55
|
+
// Parse ........-....-....-....-############
|
|
56
|
+
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
57
|
+
intArray[10] = ((value = Number.parseInt(namespace.slice(24, 36), 16)) / 0x1_00_00_00_00_00) & 0xff;
|
|
58
|
+
intArray[11] = (value / 0x1_00_00_00_00) & 0xff;
|
|
59
|
+
intArray[12] = (value >>> 24) & 0xff;
|
|
60
|
+
intArray[13] = (value >>> 16) & 0xff;
|
|
61
|
+
intArray[14] = (value >>> 8) & 0xff;
|
|
62
|
+
intArray[15] = value & 0xff;
|
|
63
|
+
|
|
64
|
+
return intArray;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default function (value: string, namespace: string): string {
|
|
68
|
+
const buffer = createHash('sha1').update(parse(namespace)).update(value).digest();
|
|
69
|
+
// note that undefined is treated as 0 by the & operator
|
|
70
|
+
buffer[6] = ((buffer[6] ?? 0) & 0x0f) | 0x50;
|
|
71
|
+
buffer[8] = ((buffer[8] ?? 0) & 0x3f) | 0x80;
|
|
72
|
+
const hex = buffer.toString('hex', 0, 16);
|
|
73
|
+
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)]
|
|
74
|
+
.join('-')
|
|
75
|
+
.toLowerCase();
|
|
76
|
+
}
|
|
77
|
+
/* eslint-enable no-bitwise,no-magic-numbers */
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
-
# to commit it to your repository.
|
|
3
|
-
#
|
|
4
|
-
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
-
# or to provide custom queries or build logic.
|
|
6
|
-
#
|
|
7
|
-
# ******** NOTE ********
|
|
8
|
-
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
-
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
-
# supported CodeQL languages.
|
|
11
|
-
#
|
|
12
|
-
name: "CodeQL"
|
|
13
|
-
|
|
14
|
-
on:
|
|
15
|
-
push:
|
|
16
|
-
branches: [ master ]
|
|
17
|
-
pull_request:
|
|
18
|
-
# The branches below must be a subset of the branches above
|
|
19
|
-
branches: [ master ]
|
|
20
|
-
schedule:
|
|
21
|
-
- cron: '21 12 * * 4'
|
|
22
|
-
|
|
23
|
-
jobs:
|
|
24
|
-
analyze:
|
|
25
|
-
name: Analyze
|
|
26
|
-
runs-on: ubuntu-latest
|
|
27
|
-
|
|
28
|
-
strategy:
|
|
29
|
-
fail-fast: false
|
|
30
|
-
matrix:
|
|
31
|
-
language: [ 'javascript' ]
|
|
32
|
-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
33
|
-
# Learn more:
|
|
34
|
-
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
|
35
|
-
|
|
36
|
-
steps:
|
|
37
|
-
- name: Checkout repository
|
|
38
|
-
uses: actions/checkout@v2
|
|
39
|
-
|
|
40
|
-
# Initializes the CodeQL tools for scanning.
|
|
41
|
-
- name: Initialize CodeQL
|
|
42
|
-
uses: github/codeql-action/init@v1
|
|
43
|
-
with:
|
|
44
|
-
languages: ${{ matrix.language }}
|
|
45
|
-
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
46
|
-
# By default, queries listed here will override any specified in a config file.
|
|
47
|
-
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
48
|
-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
49
|
-
|
|
50
|
-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
51
|
-
# If this step fails, then you should remove it and run the build manually (see below)
|
|
52
|
-
- name: Autobuild
|
|
53
|
-
uses: github/codeql-action/autobuild@v1
|
|
54
|
-
|
|
55
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
|
56
|
-
# 📚 https://git.io/JvXDl
|
|
57
|
-
|
|
58
|
-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
59
|
-
# and modify them (or add more) to build your code if your project
|
|
60
|
-
# uses a compiled language
|
|
61
|
-
|
|
62
|
-
#- run: |
|
|
63
|
-
# make bootstrap
|
|
64
|
-
# make release
|
|
65
|
-
|
|
66
|
-
- name: Perform CodeQL Analysis
|
|
67
|
-
uses: github/codeql-action/analyze@v1
|