@arcjet/stable-hash 1.0.0-beta.10 → 1.0.0-beta.11
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/README.md +6 -0
- package/edge-light.js +4 -0
- package/hasher.d.ts +63 -1
- package/hasher.js +56 -0
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -63,6 +63,12 @@ console.log(id);
|
|
|
63
63
|
|
|
64
64
|
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
|
|
65
65
|
|
|
66
|
+
Derivative work based on [`feross/buffer`][github-buffer] licensed under
|
|
67
|
+
[MIT][github-buffer-license] © Feross Aboukhadijeh and contributors.
|
|
68
|
+
Our work picks its internal hex encoding logic adjusted for our use.
|
|
69
|
+
|
|
66
70
|
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
|
|
67
71
|
[arcjet]: https://arcjet.com
|
|
68
72
|
[arcjet-get-started]: https://docs.arcjet.com/get-started
|
|
73
|
+
[github-buffer-license]: https://github.com/feross/buffer/blob/5857e295f4d37e3ad02c3abcbf7e8e5ef51f3be6/LICENSE
|
|
74
|
+
[github-buffer]: https://github.com/feross/buffer/tree/5857e295f4d37e3ad02c3abcbf7e8e5ef51f3be6
|
package/edge-light.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { makeHasher } from './hasher.js';
|
|
2
2
|
export { bool, string, stringSliceOrdered, uint32 } from './hasher.js';
|
|
3
3
|
|
|
4
|
+
// @ts-ignore: this value exists in Edge Light, as it implements the DOM type for it.
|
|
5
|
+
// See <https://vercel.com/docs/functions/runtimes/edge#crypto-apis>.
|
|
6
|
+
// This can be verified by adding `/// <reference lib="dom" />` above.
|
|
7
|
+
// But we don’t want to load the entire DOM types or edge-light-specific types.
|
|
4
8
|
const hash = makeHasher(crypto.subtle);
|
|
5
9
|
|
|
6
10
|
export { hash, makeHasher };
|
package/hasher.d.ts
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writer.
|
|
3
|
+
*/
|
|
1
4
|
export interface StringWriter {
|
|
5
|
+
/**
|
|
6
|
+
* Write data.
|
|
7
|
+
*
|
|
8
|
+
* @param data
|
|
9
|
+
* Value.
|
|
10
|
+
*/
|
|
2
11
|
writeString(data: string): void;
|
|
3
12
|
}
|
|
4
13
|
interface SubtleCryptoLike {
|
|
5
|
-
digest(algorithm:
|
|
14
|
+
digest(algorithm: {
|
|
15
|
+
name: string;
|
|
16
|
+
} | string, data: ArrayBufferView<ArrayBufferLike> | ArrayBufferLike): Promise<ArrayBuffer>;
|
|
6
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Hash a field.
|
|
20
|
+
*/
|
|
7
21
|
export type FieldHasher = (data: StringWriter) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Create a hasher for a boolean.
|
|
24
|
+
*
|
|
25
|
+
* @param key
|
|
26
|
+
* Key.
|
|
27
|
+
* @param value
|
|
28
|
+
* Value.
|
|
29
|
+
* @returns
|
|
30
|
+
* Hasher.
|
|
31
|
+
*/
|
|
8
32
|
export declare function bool(key: string, value: boolean): FieldHasher;
|
|
33
|
+
/**
|
|
34
|
+
* Create a hasher for an unsigned 32-bit integer.
|
|
35
|
+
*
|
|
36
|
+
* @param key
|
|
37
|
+
* Key.
|
|
38
|
+
* @param value
|
|
39
|
+
* Value.
|
|
40
|
+
* @returns
|
|
41
|
+
* Hasher.
|
|
42
|
+
*/
|
|
9
43
|
export declare function uint32(key: string, value: number): FieldHasher;
|
|
44
|
+
/**
|
|
45
|
+
* Create a hasher for a string.
|
|
46
|
+
*
|
|
47
|
+
* @param key
|
|
48
|
+
* Key.
|
|
49
|
+
* @param value
|
|
50
|
+
* Value.
|
|
51
|
+
* @returns
|
|
52
|
+
* Hasher.
|
|
53
|
+
*/
|
|
10
54
|
export declare function string(key: string, value: string): FieldHasher;
|
|
55
|
+
/**
|
|
56
|
+
* Create a hasher for an array of strings.
|
|
57
|
+
*
|
|
58
|
+
* @param key
|
|
59
|
+
* Key.
|
|
60
|
+
* @param values
|
|
61
|
+
* Values.
|
|
62
|
+
* @returns
|
|
63
|
+
* Hasher.
|
|
64
|
+
*/
|
|
11
65
|
export declare function stringSliceOrdered(key: string, values: string[]): FieldHasher;
|
|
66
|
+
/**
|
|
67
|
+
* Create a hasher.
|
|
68
|
+
*
|
|
69
|
+
* @param subtle
|
|
70
|
+
* Subtle crypto.
|
|
71
|
+
* @returns
|
|
72
|
+
* Hasher.
|
|
73
|
+
*/
|
|
12
74
|
export declare function makeHasher(subtle: SubtleCryptoLike): (...hashers: FieldHasher[]) => Promise<string>;
|
|
13
75
|
export {};
|
package/hasher.js
CHANGED
|
@@ -20,6 +20,16 @@ class Sha256 {
|
|
|
20
20
|
const maxUint32 = 4294967295;
|
|
21
21
|
const fieldSeparator = ":";
|
|
22
22
|
const itemSeparator = ",";
|
|
23
|
+
/**
|
|
24
|
+
* Create a hasher for a boolean.
|
|
25
|
+
*
|
|
26
|
+
* @param key
|
|
27
|
+
* Key.
|
|
28
|
+
* @param value
|
|
29
|
+
* Value.
|
|
30
|
+
* @returns
|
|
31
|
+
* Hasher.
|
|
32
|
+
*/
|
|
23
33
|
function bool(key, value) {
|
|
24
34
|
return (data) => {
|
|
25
35
|
data.writeString(key);
|
|
@@ -32,6 +42,16 @@ function bool(key, value) {
|
|
|
32
42
|
}
|
|
33
43
|
};
|
|
34
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a hasher for an unsigned 32-bit integer.
|
|
47
|
+
*
|
|
48
|
+
* @param key
|
|
49
|
+
* Key.
|
|
50
|
+
* @param value
|
|
51
|
+
* Value.
|
|
52
|
+
* @returns
|
|
53
|
+
* Hasher.
|
|
54
|
+
*/
|
|
35
55
|
function uint32(key, value) {
|
|
36
56
|
return (data) => {
|
|
37
57
|
data.writeString(key);
|
|
@@ -44,6 +64,16 @@ function uint32(key, value) {
|
|
|
44
64
|
}
|
|
45
65
|
};
|
|
46
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a hasher for a string.
|
|
69
|
+
*
|
|
70
|
+
* @param key
|
|
71
|
+
* Key.
|
|
72
|
+
* @param value
|
|
73
|
+
* Value.
|
|
74
|
+
* @returns
|
|
75
|
+
* Hasher.
|
|
76
|
+
*/
|
|
47
77
|
function string(key, value) {
|
|
48
78
|
return (data) => {
|
|
49
79
|
data.writeString(key);
|
|
@@ -53,6 +83,16 @@ function string(key, value) {
|
|
|
53
83
|
data.writeString(`"`);
|
|
54
84
|
};
|
|
55
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a hasher for an array of strings.
|
|
88
|
+
*
|
|
89
|
+
* @param key
|
|
90
|
+
* Key.
|
|
91
|
+
* @param values
|
|
92
|
+
* Values.
|
|
93
|
+
* @returns
|
|
94
|
+
* Hasher.
|
|
95
|
+
*/
|
|
56
96
|
function stringSliceOrdered(key, values) {
|
|
57
97
|
return (data) => {
|
|
58
98
|
data.writeString(key);
|
|
@@ -67,7 +107,23 @@ function stringSliceOrdered(key, values) {
|
|
|
67
107
|
data.writeString("]");
|
|
68
108
|
};
|
|
69
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a hasher.
|
|
112
|
+
*
|
|
113
|
+
* @param subtle
|
|
114
|
+
* Subtle crypto.
|
|
115
|
+
* @returns
|
|
116
|
+
* Hasher.
|
|
117
|
+
*/
|
|
70
118
|
function makeHasher(subtle) {
|
|
119
|
+
/**
|
|
120
|
+
* Hash fields.
|
|
121
|
+
*
|
|
122
|
+
* @param hashers
|
|
123
|
+
* Hashers.
|
|
124
|
+
* @returns
|
|
125
|
+
* Promise to a hash.
|
|
126
|
+
*/
|
|
71
127
|
return async function hash(...hashers) {
|
|
72
128
|
const h = new Sha256(subtle);
|
|
73
129
|
for (const hasher of hashers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/stable-hash",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "Arcjet stable hashing utility",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcjet",
|
|
@@ -52,12 +52,11 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
56
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"
|
|
60
|
-
"eslint": "9.32.0",
|
|
55
|
+
"@arcjet/eslint-config": "1.0.0-beta.11",
|
|
56
|
+
"@arcjet/rollup-config": "1.0.0-beta.11",
|
|
57
|
+
"@rollup/wasm-node": "4.50.0",
|
|
58
|
+
"@types/node": "24.3.0",
|
|
59
|
+
"eslint": "9.34.0",
|
|
61
60
|
"typescript": "5.9.2"
|
|
62
61
|
},
|
|
63
62
|
"publishConfig": {
|