@checkdigit/hash 1.0.0 → 2.0.0-PR.14-7f35

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 CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  The MIT License
3
3
 
4
- Copyright (c) 2021 Check Digit, LLC
4
+ Copyright (c) 2021-2023 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
@@ -9,7 +9,6 @@ Hash is a small function for Check Digit services to create a UUID derived from
9
9
  ```
10
10
  $ npm install @checkdigit/hash
11
11
  ```
12
-
13
12
 
14
13
  ### Use
15
14
 
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-7f35","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":["index.js","/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
@@ -0,0 +1,10 @@
1
+ // index.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
+ export { default } from './hash';
10
+ export { default as hash, HASH_NAMESPACE } from './hash';
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
package/dist/hash.d.ts DELETED
@@ -1,5 +0,0 @@
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;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default } from './hash';
2
- export { default as hash, HASH_NAMESPACE } from './hash';
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("crypto");function t(t,s){const r=e.createHash("sha1").update(function(e){let t;const s=new Uint8Array(16);return s[0]=(t=parseInt(e.slice(0,8),16))>>>24,s[1]=t>>>16&255,s[2]=t>>>8&255,s[3]=255&t,s[4]=(t=parseInt(e.slice(9,13),16))>>>8,s[5]=255&t,s[6]=(t=parseInt(e.slice(14,18),16))>>>8,s[7]=255&t,s[8]=(t=parseInt(e.slice(19,23),16))>>>8,s[9]=255&t,s[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,s[11]=t/4294967296&255,s[12]=t>>>24&255,s[13]=t>>>16&255,s[14]=t>>>8&255,s[15]=255&t,s}(s)).update(t).digest();r[6]=15&r[6]|80,r[8]=63&r[8]|128;const a=r.toString("hex",0,16);return[a.substring(0,8),a.substring(8,12),a.substring(12,16),a.substring(16,20),a.substring(20,32)].join("-").toLowerCase()}function s(s){return t(e.createHash("sha512").update(s).digest("base64"),"f25d4515-fea7-44c7-8baf-f3ca50865e66")}exports.HASH_NAMESPACE="f25d4515-fea7-44c7-8baf-f3ca50865e66",exports.default=s,exports.hash=s;
package/dist/uuidV5.d.ts DELETED
@@ -1 +0,0 @@
1
- export default function (value: string, namespace: string): string;