@getmyenv/crypto 0.5.0 → 0.6.0
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/dist/fingerprint.d.ts +6 -0
- package/dist/fingerprint.js +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Change detection for a push: HMAC-SHA256 over the sorted name/value pairs,
|
|
3
|
+
* keyed from the context key. Not a protection for the values. The key only
|
|
4
|
+
* stops the server, which stores the result, from guessing short values.
|
|
5
|
+
*/
|
|
6
|
+
export declare function pushFingerprint(contextKey: Uint8Array, values: Record<string, string>): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
2
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
3
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4
|
+
import { bytesToBase64Url, utf8Encode } from "./bytes.js";
|
|
5
|
+
import { wipe } from "./wrap.js";
|
|
6
|
+
const HKDF_INFO_PUSH = "getmyenv push fingerprint";
|
|
7
|
+
/**
|
|
8
|
+
* Change detection for a push: HMAC-SHA256 over the sorted name/value pairs,
|
|
9
|
+
* keyed from the context key. Not a protection for the values. The key only
|
|
10
|
+
* stops the server, which stores the result, from guessing short values.
|
|
11
|
+
*/
|
|
12
|
+
export function pushFingerprint(contextKey, values) {
|
|
13
|
+
const key = hkdf(sha256, contextKey, new Uint8Array(0), utf8Encode(HKDF_INFO_PUSH), 32);
|
|
14
|
+
const lines = Object.keys(values)
|
|
15
|
+
.sort()
|
|
16
|
+
.map((name) => `${name}\0${values[name]}`)
|
|
17
|
+
.join("\n");
|
|
18
|
+
const mac = hmac(sha256, key, utf8Encode(lines));
|
|
19
|
+
wipe(key);
|
|
20
|
+
return bytesToBase64Url(mac);
|
|
21
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED