aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/envshare/pkg/encoding.test.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-18 03:02:17 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-18 03:02:17 +0800
commit4919f028c884a041da7ff098abb02389b4eac598 (patch)
treeb0f482568c4b8c8a680ce6e2e70a7b7ca87dc190 /envshare/pkg/encoding.test.ts
parentb135aac8531c1e1488147ad8c6f98eddbdbe0c99 (diff)
downloadHydroRoll-4919f028c884a041da7ff098abb02389b4eac598.tar.gz
HydroRoll-4919f028c884a041da7ff098abb02389b4eac598.zip
✨add envshare docs
Diffstat (limited to 'envshare/pkg/encoding.test.ts')
-rw-r--r--envshare/pkg/encoding.test.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/envshare/pkg/encoding.test.ts b/envshare/pkg/encoding.test.ts
new file mode 100644
index 0000000..be0a7f8
--- /dev/null
+++ b/envshare/pkg/encoding.test.ts
@@ -0,0 +1,23 @@
+import { describe, it, expect, beforeAll } from "@jest/globals";
+import { decodeCompositeKey, encodeCompositeKey } from "./encoding";
+import { generateKey } from "./encryption";
+import { generateId } from "./id";
+import crypto from "node:crypto";
+
+beforeAll(() => {
+ global.crypto = crypto.webcrypto;
+});
+describe("composite key encoding", () => {
+ it("encodes and decodes composite keys", async () => {
+ for (let i = 0; i < 10000; i++) {
+ const id = generateId();
+ const key = new Uint8Array(await crypto.subtle.exportKey("raw", await generateKey()));
+
+ const encoded = encodeCompositeKey(1, id, key);
+
+ const decoded = decodeCompositeKey(encoded);
+ expect(decoded.id).toEqual(id);
+ expect(decoded.encryptionKey).toEqual(key);
+ }
+ });
+});