@checkdigit/hash 2.0.0-PR.14-7f35 → 2.0.0-PR.14-ab03
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/SECURITY.md +14 -0
- package/dist-cjs/hash.cjs +46 -0
- package/dist-cjs/hash.d.ts +5 -0
- package/dist-cjs/hash.spec.cjs +49 -0
- package/dist-cjs/hash.spec.d.ts +1 -0
- package/dist-cjs/index.cjs +44 -0
- package/dist-cjs/index.d.ts +2 -0
- package/dist-cjs/uuid-v5.cjs +54 -0
- package/dist-cjs/uuid-v5.d.ts +1 -0
- package/dist-cjs/uuid-v5.spec.cjs +74 -0
- package/dist-cjs/uuid-v5.spec.d.ts +1 -0
- package/dist-mjs/hash.d.ts +5 -0
- package/dist-mjs/hash.mjs +11 -0
- package/dist-mjs/hash.spec.d.ts +1 -0
- package/dist-mjs/hash.spec.mjs +25 -0
- package/dist-mjs/index.d.ts +2 -0
- package/dist-mjs/index.mjs +8 -0
- package/dist-mjs/uuid-v5.d.ts +1 -0
- package/dist-mjs/uuid-v5.mjs +33 -0
- package/dist-mjs/uuid-v5.spec.d.ts +1 -0
- package/dist-mjs/uuid-v5.spec.mjs +50 -0
- package/package.json +1 -1
- package/src/hash.spec.ts +37 -0
- package/src/uuid-v5.spec.ts +66 -0
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
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/hash.ts
|
|
31
|
+
var hash_exports = {};
|
|
32
|
+
__export(hash_exports, {
|
|
33
|
+
HASH_NAMESPACE: () => HASH_NAMESPACE,
|
|
34
|
+
default: () => hash_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(hash_exports);
|
|
37
|
+
var import_node_crypto = require("node:crypto");
|
|
38
|
+
var import_uuid_v5 = __toESM(require("./uuid-v5.cjs"));
|
|
39
|
+
var HASH_NAMESPACE = "f25d4515-fea7-44c7-8baf-f3ca50865e66";
|
|
40
|
+
function hash_default(value) {
|
|
41
|
+
return (0, import_uuid_v5.default)((0, import_node_crypto.createHash)("sha512").update(value).digest("base64"), HASH_NAMESPACE);
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
HASH_NAMESPACE
|
|
46
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/hash.spec.ts
|
|
26
|
+
var import_node_assert = require("node:assert");
|
|
27
|
+
var import_uuid = require("uuid");
|
|
28
|
+
var import_hash = __toESM(require("./hash.cjs"));
|
|
29
|
+
describe("hash", () => {
|
|
30
|
+
it("returns a uuid derived from hash of value", () => {
|
|
31
|
+
const result1 = (0, import_hash.default)("string to be hashed into a uuid");
|
|
32
|
+
const result2 = (0, import_hash.default)("string to be hashed into a uuid");
|
|
33
|
+
import_node_assert.strict.ok((0, import_uuid.validate)(result1) && (0, import_uuid.validate)(result2));
|
|
34
|
+
import_node_assert.strict.equal(result1, result2);
|
|
35
|
+
});
|
|
36
|
+
it("hash always returns the same value", () => {
|
|
37
|
+
import_node_assert.strict.equal((0, import_hash.default)("Hello World!"), "74caf525-c85a-5a3c-9d53-bef0507c21e4");
|
|
38
|
+
import_node_assert.strict.equal((0, import_hash.default)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55"), "14abff19-2c5f-5408-af3d-3c6526ebea73");
|
|
39
|
+
import_node_assert.strict.equal((0, import_hash.default)("R\xE5ma Ghant\xE5"), "8a28bfef-8fa2-52de-b9c5-1d5a6d7ba5fe");
|
|
40
|
+
import_node_assert.strict.equal(
|
|
41
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
42
|
+
(0, import_hash.default)("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1"),
|
|
43
|
+
"7cb123ec-2c42-5a8a-b358-adf113ee088d"
|
|
44
|
+
);
|
|
45
|
+
import_node_assert.strict.equal((0, import_hash.default)("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE="), "e90938db-61fb-55b4-8ebe-4e1518e4fe97");
|
|
46
|
+
import_node_assert.strict.equal((0, import_hash.default)("5111111111111118"), "87e25c4b-c395-585e-9ecf-43d190f6e62f");
|
|
47
|
+
import_node_assert.strict.equal((0, import_hash.default)("https://checkdigit.com"), "2c391f52-ec24-5945-8c28-88f74d12b55d");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
HASH_NAMESPACE: () => import_hash2.HASH_NAMESPACE,
|
|
34
|
+
default: () => import_hash.default,
|
|
35
|
+
hash: () => import_hash2.default
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_hash = __toESM(require("./hash.cjs"));
|
|
39
|
+
var import_hash2 = __toESM(require("./hash.cjs"));
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
HASH_NAMESPACE,
|
|
43
|
+
hash
|
|
44
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/uuid-v5.ts
|
|
21
|
+
var uuid_v5_exports = {};
|
|
22
|
+
__export(uuid_v5_exports, {
|
|
23
|
+
default: () => uuid_v5_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(uuid_v5_exports);
|
|
26
|
+
var import_node_crypto = require("node:crypto");
|
|
27
|
+
function parse(namespace) {
|
|
28
|
+
let value;
|
|
29
|
+
const intArray = new Uint8Array(16);
|
|
30
|
+
intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;
|
|
31
|
+
intArray[1] = value >>> 16 & 255;
|
|
32
|
+
intArray[2] = value >>> 8 & 255;
|
|
33
|
+
intArray[3] = value & 255;
|
|
34
|
+
intArray[4] = (value = Number.parseInt(namespace.slice(9, 13), 16)) >>> 8;
|
|
35
|
+
intArray[5] = value & 255;
|
|
36
|
+
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
37
|
+
intArray[7] = value & 255;
|
|
38
|
+
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
39
|
+
intArray[9] = value & 255;
|
|
40
|
+
intArray[10] = (value = Number.parseInt(namespace.slice(24, 36), 16)) / 1099511627776 & 255;
|
|
41
|
+
intArray[11] = value / 4294967296 & 255;
|
|
42
|
+
intArray[12] = value >>> 24 & 255;
|
|
43
|
+
intArray[13] = value >>> 16 & 255;
|
|
44
|
+
intArray[14] = value >>> 8 & 255;
|
|
45
|
+
intArray[15] = value & 255;
|
|
46
|
+
return intArray;
|
|
47
|
+
}
|
|
48
|
+
function uuid_v5_default(value, namespace) {
|
|
49
|
+
const buffer = (0, import_node_crypto.createHash)("sha1").update(parse(namespace)).update(value).digest();
|
|
50
|
+
buffer[6] = (buffer[6] ?? 0) & 15 | 80;
|
|
51
|
+
buffer[8] = (buffer[8] ?? 0) & 63 | 128;
|
|
52
|
+
const hex = buffer.toString("hex", 0, 16);
|
|
53
|
+
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)].join("-").toLowerCase();
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (value: string, namespace: string): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/uuid-v5.spec.ts
|
|
26
|
+
var import_node_assert = require("node:assert");
|
|
27
|
+
var import_uuid = require("uuid");
|
|
28
|
+
var import_hash = require("./hash.cjs");
|
|
29
|
+
var import_uuid_v5 = __toESM(require("./uuid-v5.cjs"));
|
|
30
|
+
describe("uuidV5", () => {
|
|
31
|
+
it("uuidV5 result matches v5(https://github.com/uuidjs/uuid) result", () => {
|
|
32
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("Hello World!", import_hash.HASH_NAMESPACE), (0, import_uuid.v5)("Hello World!", import_hash.HASH_NAMESPACE));
|
|
33
|
+
import_node_assert.strict.equal(
|
|
34
|
+
(0, import_uuid_v5.default)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55", import_hash.HASH_NAMESPACE),
|
|
35
|
+
(0, import_uuid.v5)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55", import_hash.HASH_NAMESPACE)
|
|
36
|
+
);
|
|
37
|
+
import_node_assert.strict.equal(
|
|
38
|
+
(0, import_uuid_v5.default)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz", import_hash.HASH_NAMESPACE),
|
|
39
|
+
(0, import_uuid.v5)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz", import_hash.HASH_NAMESPACE)
|
|
40
|
+
);
|
|
41
|
+
import_node_assert.strict.equal(
|
|
42
|
+
(0, import_uuid_v5.default)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC", import_hash.HASH_NAMESPACE),
|
|
43
|
+
(0, import_uuid.v5)("d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC", import_hash.HASH_NAMESPACE)
|
|
44
|
+
);
|
|
45
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("R\xE5ma Ghant\xE5", import_hash.HASH_NAMESPACE), (0, import_uuid.v5)("R\xE5ma Ghant\xE5", import_hash.HASH_NAMESPACE));
|
|
46
|
+
import_node_assert.strict.equal(
|
|
47
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
48
|
+
(0, import_uuid_v5.default)("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1", import_hash.HASH_NAMESPACE),
|
|
49
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
50
|
+
(0, import_uuid.v5)("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1", import_hash.HASH_NAMESPACE)
|
|
51
|
+
);
|
|
52
|
+
import_node_assert.strict.equal(
|
|
53
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
54
|
+
(0, import_uuid_v5.default)("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=", import_hash.HASH_NAMESPACE),
|
|
55
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
56
|
+
(0, import_uuid.v5)("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=", import_hash.HASH_NAMESPACE)
|
|
57
|
+
);
|
|
58
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("5111111111111118", import_hash.HASH_NAMESPACE), (0, import_uuid.v5)("5111111111111118", import_hash.HASH_NAMESPACE));
|
|
59
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("https://checkdigit.com", import_hash.HASH_NAMESPACE), (0, import_uuid.v5)("https://checkdigit.com", import_hash.HASH_NAMESPACE));
|
|
60
|
+
});
|
|
61
|
+
it("v5 - from https://github.com/uuidjs/uuid testing", () => {
|
|
62
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("hello.example.com", import_uuid.v5.DNS), "fdda765f-fc57-5604-a269-52a7df8164ec");
|
|
63
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("http://example.com/hello", import_uuid.v5.URL), "3bbcee75-cecc-5b56-8031-b6641c1ed1f1");
|
|
64
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("hello", "0f5abcd1-c194-47f3-905b-2df7263a084b"), "90123e1c-7512-523e-bb28-76fab9f2f73d");
|
|
65
|
+
});
|
|
66
|
+
it("v5 namespace.toUpperCase - from https://github.com/uuidjs/uuid testing", () => {
|
|
67
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("hello.example.com", import_uuid.v5.DNS.toUpperCase()), "fdda765f-fc57-5604-a269-52a7df8164ec");
|
|
68
|
+
import_node_assert.strict.equal((0, import_uuid_v5.default)("http://example.com/hello", import_uuid.v5.URL.toUpperCase()), "3bbcee75-cecc-5b56-8031-b6641c1ed1f1");
|
|
69
|
+
import_node_assert.strict.equal(
|
|
70
|
+
(0, import_uuid_v5.default)("hello", "0f5abcd1-c194-47f3-905b-2df7263a084b".toUpperCase()),
|
|
71
|
+
"90123e1c-7512-523e-bb28-76fab9f2f73d"
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/hash.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import uuidV5 from "./uuid-v5.mjs";
|
|
4
|
+
var HASH_NAMESPACE = "f25d4515-fea7-44c7-8baf-f3ca50865e66";
|
|
5
|
+
function hash_default(value) {
|
|
6
|
+
return uuidV5(createHash("sha512").update(value).digest("base64"), HASH_NAMESPACE);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
HASH_NAMESPACE,
|
|
10
|
+
hash_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/hash.spec.ts
|
|
2
|
+
import { strict as assert } from "node:assert";
|
|
3
|
+
import { validate } from "uuid";
|
|
4
|
+
import hash from "./hash.mjs";
|
|
5
|
+
describe("hash", () => {
|
|
6
|
+
it("returns a uuid derived from hash of value", () => {
|
|
7
|
+
const result1 = hash("string to be hashed into a uuid");
|
|
8
|
+
const result2 = hash("string to be hashed into a uuid");
|
|
9
|
+
assert.ok(validate(result1) && validate(result2));
|
|
10
|
+
assert.equal(result1, result2);
|
|
11
|
+
});
|
|
12
|
+
it("hash always returns the same value", () => {
|
|
13
|
+
assert.equal(hash("Hello World!"), "74caf525-c85a-5a3c-9d53-bef0507c21e4");
|
|
14
|
+
assert.equal(hash("d1253ec1-14bc-4c56-8e09-4450ab4c8a55"), "14abff19-2c5f-5408-af3d-3c6526ebea73");
|
|
15
|
+
assert.equal(hash("R\xE5ma Ghant\xE5"), "8a28bfef-8fa2-52de-b9c5-1d5a6d7ba5fe");
|
|
16
|
+
assert.equal(
|
|
17
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
18
|
+
hash("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1"),
|
|
19
|
+
"7cb123ec-2c42-5a8a-b358-adf113ee088d"
|
|
20
|
+
);
|
|
21
|
+
assert.equal(hash("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE="), "e90938db-61fb-55b4-8ebe-4e1518e4fe97");
|
|
22
|
+
assert.equal(hash("5111111111111118"), "87e25c4b-c395-585e-9ecf-43d190f6e62f");
|
|
23
|
+
assert.equal(hash("https://checkdigit.com"), "2c391f52-ec24-5945-8c28-88f74d12b55d");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (value: string, namespace: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/uuid-v5.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
function parse(namespace) {
|
|
4
|
+
let value;
|
|
5
|
+
const intArray = new Uint8Array(16);
|
|
6
|
+
intArray[0] = (value = Number.parseInt(namespace.slice(0, 8), 16)) >>> 24;
|
|
7
|
+
intArray[1] = value >>> 16 & 255;
|
|
8
|
+
intArray[2] = value >>> 8 & 255;
|
|
9
|
+
intArray[3] = value & 255;
|
|
10
|
+
intArray[4] = (value = Number.parseInt(namespace.slice(9, 13), 16)) >>> 8;
|
|
11
|
+
intArray[5] = value & 255;
|
|
12
|
+
intArray[6] = (value = Number.parseInt(namespace.slice(14, 18), 16)) >>> 8;
|
|
13
|
+
intArray[7] = value & 255;
|
|
14
|
+
intArray[8] = (value = Number.parseInt(namespace.slice(19, 23), 16)) >>> 8;
|
|
15
|
+
intArray[9] = value & 255;
|
|
16
|
+
intArray[10] = (value = Number.parseInt(namespace.slice(24, 36), 16)) / 1099511627776 & 255;
|
|
17
|
+
intArray[11] = value / 4294967296 & 255;
|
|
18
|
+
intArray[12] = value >>> 24 & 255;
|
|
19
|
+
intArray[13] = value >>> 16 & 255;
|
|
20
|
+
intArray[14] = value >>> 8 & 255;
|
|
21
|
+
intArray[15] = value & 255;
|
|
22
|
+
return intArray;
|
|
23
|
+
}
|
|
24
|
+
function uuid_v5_default(value, namespace) {
|
|
25
|
+
const buffer = createHash("sha1").update(parse(namespace)).update(value).digest();
|
|
26
|
+
buffer[6] = (buffer[6] ?? 0) & 15 | 80;
|
|
27
|
+
buffer[8] = (buffer[8] ?? 0) & 63 | 128;
|
|
28
|
+
const hex = buffer.toString("hex", 0, 16);
|
|
29
|
+
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)].join("-").toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
uuid_v5_default as default
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/uuid-v5.spec.ts
|
|
2
|
+
import { strict as assert } from "node:assert";
|
|
3
|
+
import { v5 } from "uuid";
|
|
4
|
+
import { HASH_NAMESPACE } from "./hash.mjs";
|
|
5
|
+
import uuidV5 from "./uuid-v5.mjs";
|
|
6
|
+
describe("uuidV5", () => {
|
|
7
|
+
it("uuidV5 result matches v5(https://github.com/uuidjs/uuid) result", () => {
|
|
8
|
+
assert.equal(uuidV5("Hello World!", HASH_NAMESPACE), v5("Hello World!", HASH_NAMESPACE));
|
|
9
|
+
assert.equal(
|
|
10
|
+
uuidV5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55", HASH_NAMESPACE),
|
|
11
|
+
v5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55", HASH_NAMESPACE)
|
|
12
|
+
);
|
|
13
|
+
assert.equal(
|
|
14
|
+
uuidV5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz", HASH_NAMESPACE),
|
|
15
|
+
v5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz", HASH_NAMESPACE)
|
|
16
|
+
);
|
|
17
|
+
assert.equal(
|
|
18
|
+
uuidV5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC", HASH_NAMESPACE),
|
|
19
|
+
v5("d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC", HASH_NAMESPACE)
|
|
20
|
+
);
|
|
21
|
+
assert.equal(uuidV5("R\xE5ma Ghant\xE5", HASH_NAMESPACE), v5("R\xE5ma Ghant\xE5", HASH_NAMESPACE));
|
|
22
|
+
assert.equal(
|
|
23
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
24
|
+
uuidV5("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1", HASH_NAMESPACE),
|
|
25
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
26
|
+
v5("/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1", HASH_NAMESPACE)
|
|
27
|
+
);
|
|
28
|
+
assert.equal(
|
|
29
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
30
|
+
uuidV5("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=", HASH_NAMESPACE),
|
|
31
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
32
|
+
v5("nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=", HASH_NAMESPACE)
|
|
33
|
+
);
|
|
34
|
+
assert.equal(uuidV5("5111111111111118", HASH_NAMESPACE), v5("5111111111111118", HASH_NAMESPACE));
|
|
35
|
+
assert.equal(uuidV5("https://checkdigit.com", HASH_NAMESPACE), v5("https://checkdigit.com", HASH_NAMESPACE));
|
|
36
|
+
});
|
|
37
|
+
it("v5 - from https://github.com/uuidjs/uuid testing", () => {
|
|
38
|
+
assert.equal(uuidV5("hello.example.com", v5.DNS), "fdda765f-fc57-5604-a269-52a7df8164ec");
|
|
39
|
+
assert.equal(uuidV5("http://example.com/hello", v5.URL), "3bbcee75-cecc-5b56-8031-b6641c1ed1f1");
|
|
40
|
+
assert.equal(uuidV5("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
|
+
assert.equal(uuidV5("hello.example.com", v5.DNS.toUpperCase()), "fdda765f-fc57-5604-a269-52a7df8164ec");
|
|
44
|
+
assert.equal(uuidV5("http://example.com/hello", v5.URL.toUpperCase()), "3bbcee75-cecc-5b56-8031-b6641c1ed1f1");
|
|
45
|
+
assert.equal(
|
|
46
|
+
uuidV5("hello", "0f5abcd1-c194-47f3-905b-2df7263a084b".toUpperCase()),
|
|
47
|
+
"90123e1c-7512-523e-bb28-76fab9f2f73d"
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
});
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/hash","version":"2.0.0-PR.14-
|
|
1
|
+
{"name":"@checkdigit/hash","version":"2.0.0-PR.14-ab03","description":"Hash is a small function for Check Digit services to create a uuid derived from a hash generated from a given value.","exports":{".":{"types":"./build-mjs/index.d.ts","require":"./dist-cjs/index.cjs","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["dist-cjs","dist-mjs","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":{"prepublishOnly":"npm run build:dist-cjs && npm run build:dist-esm && rimraf .github tsconfig.json","build:dist-cjs":"rimraf dist-cjs && npx builder --type=commonjs --outDir=dist-cjs","build:dist-esm":"rimraf dist-esm && npx builder --type=module --outDir=dist-mjs","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.spec.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// hash.spec.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 { strict as assert } from 'node:assert';
|
|
10
|
+
import { validate } from 'uuid';
|
|
11
|
+
|
|
12
|
+
import hash from './hash';
|
|
13
|
+
|
|
14
|
+
describe('hash', () => {
|
|
15
|
+
it('returns a uuid derived from hash of value', () => {
|
|
16
|
+
const result1 = hash('string to be hashed into a uuid');
|
|
17
|
+
const result2 = hash('string to be hashed into a uuid');
|
|
18
|
+
assert.ok(validate(result1) && validate(result2));
|
|
19
|
+
assert.equal(result1, result2);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('hash always returns the same value', () => {
|
|
23
|
+
assert.equal(hash('Hello World!'), '74caf525-c85a-5a3c-9d53-bef0507c21e4');
|
|
24
|
+
assert.equal(hash('d1253ec1-14bc-4c56-8e09-4450ab4c8a55'), '14abff19-2c5f-5408-af3d-3c6526ebea73');
|
|
25
|
+
assert.equal(hash('Råma Ghantå'), '8a28bfef-8fa2-52de-b9c5-1d5a6d7ba5fe');
|
|
26
|
+
assert.equal(
|
|
27
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
28
|
+
hash('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1'),
|
|
29
|
+
'7cb123ec-2c42-5a8a-b358-adf113ee088d'
|
|
30
|
+
);
|
|
31
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
32
|
+
assert.equal(hash('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE='), 'e90938db-61fb-55b4-8ebe-4e1518e4fe97');
|
|
33
|
+
// eslint-disable-next-line @checkdigit/no-card-numbers
|
|
34
|
+
assert.equal(hash('5111111111111118'), '87e25c4b-c395-585e-9ecf-43d190f6e62f');
|
|
35
|
+
assert.equal(hash('https://checkdigit.com'), '2c391f52-ec24-5945-8c28-88f74d12b55d');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// uuid-v5.spec.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 { strict as assert } from 'node:assert';
|
|
10
|
+
import { v5 } from 'uuid';
|
|
11
|
+
|
|
12
|
+
import { HASH_NAMESPACE } from './hash';
|
|
13
|
+
import uuidV5 from './uuid-v5';
|
|
14
|
+
|
|
15
|
+
describe('uuidV5', () => {
|
|
16
|
+
it('uuidV5 result matches v5(https://github.com/uuidjs/uuid) result', () => {
|
|
17
|
+
assert.equal(uuidV5('Hello World!', HASH_NAMESPACE), v5('Hello World!', HASH_NAMESPACE));
|
|
18
|
+
assert.equal(
|
|
19
|
+
uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', HASH_NAMESPACE),
|
|
20
|
+
v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55', HASH_NAMESPACE)
|
|
21
|
+
);
|
|
22
|
+
assert.equal(
|
|
23
|
+
uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', HASH_NAMESPACE),
|
|
24
|
+
v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55/abc/xyz', HASH_NAMESPACE)
|
|
25
|
+
);
|
|
26
|
+
assert.equal(
|
|
27
|
+
uuidV5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', HASH_NAMESPACE),
|
|
28
|
+
v5('d1253ec1-14bc-4c56-8e09-4450ab4c8a55-ABC', HASH_NAMESPACE)
|
|
29
|
+
);
|
|
30
|
+
assert.equal(uuidV5('Råma Ghantå', HASH_NAMESPACE), v5('Råma Ghantå', HASH_NAMESPACE));
|
|
31
|
+
assert.equal(
|
|
32
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
33
|
+
uuidV5('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', HASH_NAMESPACE),
|
|
34
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
35
|
+
v5('/hYSjdEGQI0DaVHCR0vZq0KeF5JLys3jSNvU9EzBMKKlSsC97xFd3wr+nrhzHhp1', HASH_NAMESPACE)
|
|
36
|
+
);
|
|
37
|
+
assert.equal(
|
|
38
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
39
|
+
uuidV5('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', HASH_NAMESPACE),
|
|
40
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
41
|
+
v5('nfv8yFRghIJV6ffFr2dJGi1978GPnUuc7JVi2/FPqHE=', HASH_NAMESPACE)
|
|
42
|
+
);
|
|
43
|
+
// eslint-disable-next-line @checkdigit/no-card-numbers
|
|
44
|
+
assert.equal(uuidV5('5111111111111118', HASH_NAMESPACE), v5('5111111111111118', HASH_NAMESPACE));
|
|
45
|
+
assert.equal(uuidV5('https://checkdigit.com', HASH_NAMESPACE), v5('https://checkdigit.com', HASH_NAMESPACE));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('v5 - from https://github.com/uuidjs/uuid testing', () => {
|
|
49
|
+
assert.equal(uuidV5('hello.example.com', v5.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
50
|
+
|
|
51
|
+
assert.equal(uuidV5('http://example.com/hello', v5.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
52
|
+
|
|
53
|
+
assert.equal(uuidV5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('v5 namespace.toUpperCase - from https://github.com/uuidjs/uuid testing', () => {
|
|
57
|
+
assert.equal(uuidV5('hello.example.com', v5.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
58
|
+
|
|
59
|
+
assert.equal(uuidV5('http://example.com/hello', v5.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
60
|
+
|
|
61
|
+
assert.equal(
|
|
62
|
+
uuidV5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()),
|
|
63
|
+
'90123e1c-7512-523e-bb28-76fab9f2f73d'
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
});
|