zeyra 1.0.1 → 2.0.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.
Files changed (55) hide show
  1. package/README.md +160 -69
  2. package/dist/CipherAgent/class.d.ts +13 -0
  3. package/dist/CipherAgent/class.d.ts.map +1 -0
  4. package/dist/CipherAgent/class.js +19 -0
  5. package/dist/CipherAgent/class.js.map +1 -0
  6. package/dist/CipherCluster/class.d.ts +12 -0
  7. package/dist/CipherCluster/class.d.ts.map +1 -0
  8. package/dist/CipherCluster/class.js +27 -0
  9. package/dist/CipherCluster/class.js.map +1 -0
  10. package/dist/SigningAgent/class.d.ts +6 -0
  11. package/dist/SigningAgent/class.d.ts.map +1 -0
  12. package/dist/SigningAgent/class.js +12 -0
  13. package/dist/SigningAgent/class.js.map +1 -0
  14. package/dist/SigningCluster/class.d.ts +5 -0
  15. package/dist/SigningCluster/class.d.ts.map +1 -0
  16. package/dist/SigningCluster/class.js +20 -0
  17. package/dist/SigningCluster/class.js.map +1 -0
  18. package/dist/UnwrappingAgent/class.d.ts +6 -0
  19. package/dist/UnwrappingAgent/class.d.ts.map +1 -0
  20. package/dist/UnwrappingAgent/class.js +12 -0
  21. package/dist/UnwrappingAgent/class.js.map +1 -0
  22. package/dist/UnwrappingCluster/class.d.ts +5 -0
  23. package/dist/UnwrappingCluster/class.d.ts.map +1 -0
  24. package/dist/UnwrappingCluster/class.js +18 -0
  25. package/dist/UnwrappingCluster/class.js.map +1 -0
  26. package/dist/VerificationAgent/class.d.ts +6 -0
  27. package/dist/VerificationAgent/class.d.ts.map +1 -0
  28. package/dist/VerificationAgent/class.js +12 -0
  29. package/dist/VerificationAgent/class.js.map +1 -0
  30. package/dist/VerificationCluster/class.d.ts +5 -0
  31. package/dist/VerificationCluster/class.d.ts.map +1 -0
  32. package/dist/VerificationCluster/class.js +20 -0
  33. package/dist/VerificationCluster/class.js.map +1 -0
  34. package/dist/WrappingAgent/class.d.ts +6 -0
  35. package/dist/WrappingAgent/class.d.ts.map +1 -0
  36. package/dist/WrappingAgent/class.js +14 -0
  37. package/dist/WrappingAgent/class.js.map +1 -0
  38. package/dist/WrappingCluster/class.d.ts +5 -0
  39. package/dist/WrappingCluster/class.d.ts.map +1 -0
  40. package/dist/WrappingCluster/class.js +18 -0
  41. package/dist/WrappingCluster/class.js.map +1 -0
  42. package/dist/generateKeyset/index.d.ts +8 -0
  43. package/dist/generateKeyset/index.d.ts.map +1 -0
  44. package/dist/generateKeyset/index.js +23 -0
  45. package/dist/generateKeyset/index.js.map +1 -0
  46. package/dist/index.d.ts +13 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +13 -0
  49. package/dist/index.js.map +1 -0
  50. package/package.json +24 -9
  51. package/src/CipherAgent/class.js +0 -43
  52. package/src/SigningAgent/class.js +0 -23
  53. package/src/VerificationAgent/class.js +0 -29
  54. package/src/generateKeyset/index.js +0 -36
  55. package/src/index.js +0 -5
package/README.md CHANGED
@@ -1,69 +1,160 @@
1
- # Zeyra
2
-
3
- WebCrypto helpers for zero-knowledge–friendly flows: generate AES-GCM + ECDSA keysets as JWKs and wrap them with tiny agent classes for encrypt, decrypt, sign, and verify.
4
-
5
- ## Features
6
- - AES-GCM 256 encryption/decryption via `CipherAgent`
7
- - ECDSA P-256 signing/verification via `SigningAgent` and `VerificationAgent`
8
- - `generateKeyset()` produces an exportable JWK bundle you can store or transport
9
- - Pure WebCrypto, no native add-ons; ships as ESM
10
- - Plays nicely with `bytecodec` for UTF-8 and base64url conversions
11
-
12
- ## Requirements
13
- - Node.js 18+ (global `crypto.subtle`)
14
- - ESM environment (`"type": "module"` in `package.json`)
15
-
16
- ## Installation
17
- ```bash
18
- npm install zeyra
19
- ```
20
-
21
- ## Quickstart
22
- ```js
23
- import { Bytes } from "bytecodec";
24
- import {
25
- generateKeyset,
26
- CipherAgent,
27
- SigningAgent,
28
- VerificationAgent,
29
- } from "zeyra";
30
-
31
- // One-time key material for a resource
32
- const { symmetricJwk, privateJwk, publicJwk } = await generateKeyset();
33
-
34
- // Writers: encrypt + sign
35
- const cipher = new CipherAgent(symmetricJwk);
36
- const signer = new SigningAgent(privateJwk);
37
- const payload = await cipher.encrypt(Bytes.fromString("hello world"));
38
- const signature = await signer.sign(payload.ciphertext);
39
-
40
- // Readers / servers: verify ownership + decrypt
41
- const verifier = new VerificationAgent(publicJwk);
42
- const authorized = await verifier.verify(payload.ciphertext, signature);
43
- const plaintext = Bytes.toString(await cipher.decrypt(payload));
44
- ```
45
-
46
- ## API
47
- - `generateKeyset()` -> `{ symmetricJwk, publicJwk, privateJwk }` (all exportable JWKs)
48
- - `new CipherAgent(symmetricJwk)`
49
- - `.encrypt(Uint8Array)` -> `{ iv: Uint8Array, ciphertext: ArrayBuffer }`
50
- - `.decrypt({ iv, ciphertext })` -> `Uint8Array`
51
- - `new SigningAgent(privateJwk)`
52
- - `.sign(Uint8Array | ArrayBuffer)` -> `ArrayBuffer` (ECDSA P-256 / SHA-256)
53
- - `new VerificationAgent(publicJwk)`
54
- - `.verify(Uint8Array | ArrayBuffer, ArrayBuffer)` -> `boolean`
55
-
56
- See the implementations in `src/index.js` and friends for details.
57
-
58
- ## Testing and benchmarks
59
- - Run tests: `npm test` (uses Node’s built-in `node:test` runner against `test.js`)
60
- - Run microbenchmarks (skipped by default): `npm run bench`
61
- - Pass iterations: `npm run bench -- --iterations=500`
62
- - Reports ops/sec for encryption and the full encrypt/sign/verify/decrypt pipeline.
63
-
64
- ## Notes
65
- - Keys are intentionally exportable to move them between client/storage; encrypt them at rest according to your threat model.
66
- - AES-GCM already authenticates ciphertext/IV; ECDSA signatures add an explicit ownership check for multi-party flows.
67
-
68
- ## License
69
- MIT
1
+ # Zeyra
2
+
3
+ Client-side WebCrypto helpers for AES-GCM encryption, ECDSA signatures, and RSA-OAEP key wrapping, with byte-oriented cluster helpers.
4
+
5
+ ## Compatibility
6
+
7
+ - WebCrypto (`crypto.subtle`) is stable in evergreen browsers; unprefixed support shipped in Chrome 37 (2014), Firefox 34 (2014), Edge 12 (2015), and Safari 11 (2017).
8
+ - Zeyra relies on AES-GCM, ECDSA P-256, and RSA-OAEP plus wrap/unwrap; legacy EdgeHTML/IE have partial WebCrypto (notably missing ECDSA), so target Chromium Edge (79+, 2020) and modern browsers.
9
+ - ESM only; requires global `crypto.subtle`.
10
+
11
+ ## Features
12
+
13
+ - AES-GCM 256 encryption/decryption via `CipherAgent` and `CipherCluster`
14
+ - ECDSA P-256 sign/verify via `SigningAgent`, `VerificationAgent`, and clusters
15
+ - RSA-OAEP 4096 wrap/unwrap for AES-GCM JWKs
16
+ - `generateKeyset()` yields `cipherJwk`, `signingJwk`, `verificationJwk`, `wrappingJwk`, `unwrappingJwk`
17
+ - Cluster classes cache agents with `WeakRef`; they are a lightweight optimization, not a full end-to-end solution
18
+ - Byte-oriented clusters return raw `Uint8Array` / `ArrayBuffer` (no base64); use `bytecodec` for JSON, compression, and encoding
19
+ - TypeScript source; published package ships compiled JS + `.d.ts`
20
+
21
+ ## Requirements
22
+
23
+ - Node.js 18+ for server/edge usage
24
+ - ESM environment (`"type": "module"`)
25
+ - `bytecodec` for JSON/bytes/compression helpers
26
+
27
+ ## Installation
28
+
29
+ ```sh
30
+ npm install zeyra
31
+ # or
32
+ pnpm add zeyra
33
+ # or
34
+ yarn add zeyra
35
+ ```
36
+
37
+ ## Quickstart (agents)
38
+
39
+ ```js
40
+ import { Bytes } from "bytecodec";
41
+ import {
42
+ generateKeyset,
43
+ CipherAgent,
44
+ SigningAgent,
45
+ VerificationAgent,
46
+ } from "zeyra";
47
+
48
+ const { cipherJwk, signingJwk, verificationJwk } = await generateKeyset();
49
+
50
+ const cipher = new CipherAgent(cipherJwk);
51
+ const signer = new SigningAgent(signingJwk);
52
+ const verifier = new VerificationAgent(verificationJwk);
53
+
54
+ const payload = await cipher.encrypt(Bytes.fromString("hello world"));
55
+ const ciphertextBytes = new Uint8Array(payload.ciphertext);
56
+ const signature = await signer.sign(ciphertextBytes);
57
+
58
+ const authorized = await verifier.verify(ciphertextBytes, signature);
59
+ const plaintext = Bytes.toString(await cipher.decrypt(payload));
60
+ ```
61
+
62
+ ## Managed cluster flow
63
+
64
+ ```js
65
+ import {
66
+ generateKeyset,
67
+ CipherCluster,
68
+ SigningCluster,
69
+ VerificationCluster,
70
+ } from "zeyra";
71
+
72
+ const { cipherJwk, signingJwk, verificationJwk } = await generateKeyset();
73
+
74
+ const resource = { id: "file-123", body: "hello world" };
75
+ const artifact = await CipherCluster.encrypt(cipherJwk, resource);
76
+ // artifact: { iv: Uint8Array, ciphertext: ArrayBuffer }
77
+
78
+ const signature = await SigningCluster.sign(signingJwk, resource.id);
79
+ const authorized = await VerificationCluster.verify(
80
+ verificationJwk,
81
+ resource.id,
82
+ signature
83
+ );
84
+
85
+ const decrypted = await CipherCluster.decrypt(cipherJwk, artifact);
86
+ ```
87
+
88
+ ## Key wrapping flow
89
+
90
+ ```js
91
+ import { generateKeyset, WrappingCluster, UnwrappingCluster } from "zeyra";
92
+
93
+ const { cipherJwk, wrappingJwk, unwrappingJwk } = await generateKeyset();
94
+
95
+ const wrapped = await WrappingCluster.wrap(wrappingJwk, cipherJwk);
96
+ const unwrappedCipherJwk = await UnwrappingCluster.unwrap(
97
+ unwrappingJwk,
98
+ wrapped
99
+ );
100
+ ```
101
+
102
+ ## API
103
+
104
+ - `generateKeyset()` -> `{ cipherJwk, verificationJwk, signingJwk, wrappingJwk, unwrappingJwk }`
105
+ - `new CipherAgent(cipherJwk)`
106
+ - `.encrypt(Uint8Array)` -> `{ iv: Uint8Array, ciphertext: ArrayBuffer }`
107
+ - `.decrypt({ iv, ciphertext })` -> `Uint8Array`
108
+ - `new SigningAgent(signingJwk)`
109
+ - `.sign(Uint8Array)` -> `ArrayBuffer` (ECDSA P-256 / SHA-256)
110
+ - `new VerificationAgent(verificationJwk)`
111
+ - `.verify(Uint8Array, ArrayBuffer)` -> `boolean`
112
+ - `new WrappingAgent(wrappingJwk)`
113
+ - `.wrap(cipherJwk)` -> `ArrayBuffer` (RSA-OAEP / SHA-256)
114
+ - `new UnwrappingAgent(unwrappingJwk)`
115
+ - `.unwrap(ArrayBuffer)` -> `JsonWebKey`
116
+ - `CipherCluster.encrypt(cipherJwk, resource)` -> `{ iv, ciphertext }`
117
+ - `CipherCluster.decrypt(cipherJwk, artifact)` -> `resource`
118
+ - `SigningCluster.sign(signingJwk, value)` -> `ArrayBuffer`
119
+ - `VerificationCluster.verify(verificationJwk, value, signature)` -> `boolean`
120
+ - `WrappingCluster.wrap(wrappingJwk, cipherJwk)` -> `ArrayBuffer`
121
+ - `UnwrappingCluster.unwrap(unwrappingJwk, wrapped)` -> `JsonWebKey`
122
+
123
+ ## Serialization helpers
124
+
125
+ Zeyra keeps clusters byte-oriented. Use `bytecodec` when you need to serialize or store artifacts.
126
+
127
+ ```js
128
+ import { Bytes } from "bytecodec";
129
+
130
+ const artifact = await CipherCluster.encrypt(cipherJwk, resource);
131
+ const ciphertextB64 = Bytes.toBase64UrlString(
132
+ new Uint8Array(artifact.ciphertext)
133
+ );
134
+ const ivB64 = Bytes.toBase64UrlString(artifact.iv);
135
+ ```
136
+
137
+ ## Testing and benchmarks
138
+
139
+ - Build: `npm run build` (outputs `dist/`)
140
+ - Run tests: `npm test` (builds `dist/`, then runs `node --test`)
141
+ - Run benchmarks: `npm run bench`
142
+ - Pass iterations: `npm run bench -- --iterations=500`
143
+
144
+ ## Benchmarks (local)
145
+
146
+ Results will vary by hardware, runtime, and payload size. Run `npm run bench` to reproduce.
147
+
148
+ - Node v22.14.0 (Windows), iterations=200
149
+ - encrypt only: 44.68ms (4476.3 ops/sec)
150
+ - full pipeline: 115.15ms (1736.9 ops/sec)
151
+
152
+ ## Notes
153
+
154
+ - Zeyra is intended for client-side encryption workflows; server/edge usage is supported where WebCrypto is available.
155
+ - Cluster helpers cache keys with `WeakRef` and keep `CryptoKey` material private inside agents.
156
+ - `CipherCluster` compresses JSON payloads before encryption; `SigningCluster`/`VerificationCluster` sign JSON values.
157
+
158
+ ## License
159
+
160
+ MIT
@@ -0,0 +1,13 @@
1
+ export declare class CipherAgent {
2
+ private keyPromise;
3
+ constructor(cipherJwk: JsonWebKey);
4
+ encrypt(plaintext: Uint8Array): Promise<{
5
+ iv: Uint8Array;
6
+ ciphertext: ArrayBuffer;
7
+ }>;
8
+ decrypt({ iv, ciphertext, }: {
9
+ iv: Uint8Array<ArrayBufferLike>;
10
+ ciphertext: ArrayBuffer;
11
+ }): Promise<Uint8Array>;
12
+ }
13
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/CipherAgent/class.ts"],"names":[],"mappings":"AACA,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAqB;gBAC3B,SAAS,EAAE,UAAU;IAU3B,OAAO,CACX,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,WAAW,CAAA;KAAE,CAAC;IAWjD,OAAO,CAAC,EACZ,EAAE,EACF,UAAU,GACX,EAAE;QACD,EAAE,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;QAChC,UAAU,EAAE,WAAW,CAAC;KACzB,GAAG,OAAO,CAAC,UAAU,CAAC;CASxB"}
@@ -0,0 +1,19 @@
1
+ import { Bytes } from "bytecodec";
2
+ export class CipherAgent {
3
+ keyPromise;
4
+ constructor(cipherJwk) {
5
+ this.keyPromise = crypto.subtle.importKey("jwk", cipherJwk, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
6
+ }
7
+ async encrypt(plaintext) {
8
+ const key = await this.keyPromise;
9
+ const iv = crypto.getRandomValues(new Uint8Array(12));
10
+ const ciphertext = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, Bytes.toBufferSource(plaintext));
11
+ return { iv, ciphertext };
12
+ }
13
+ async decrypt({ iv, ciphertext, }) {
14
+ const key = await this.keyPromise;
15
+ const plaintext = await crypto.subtle.decrypt({ name: "AES-GCM", iv: Bytes.toBufferSource(iv) }, key, ciphertext);
16
+ return new Uint8Array(plaintext);
17
+ }
18
+ }
19
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/CipherAgent/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,MAAM,OAAO,WAAW;IACd,UAAU,CAAqB;IACvC,YAAY,SAAqB;QAC/B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,KAAK,EACL,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CACX,SAAqB;QAErB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,MAAM,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAC5C,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,EACvB,GAAG,EACH,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAChC,CAAC;QACF,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EACZ,EAAE,EACF,UAAU,GAIX;QACC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAC3C,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EACjD,GAAG,EACH,UAAU,CACX,CAAC;QACF,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ export declare class CipherCluster {
2
+ #private;
3
+ static encrypt(cipherJwk: JsonWebKey, resource: any): Promise<{
4
+ iv: Uint8Array;
5
+ ciphertext: ArrayBuffer;
6
+ }>;
7
+ static decrypt(cipherJwk: JsonWebKey, artifact: {
8
+ iv: Uint8Array;
9
+ ciphertext: ArrayBuffer;
10
+ }): Promise<any>;
11
+ }
12
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/CipherCluster/class.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;;WAaX,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,GAAG,GACZ,OAAO,CAAC;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,WAAW,CAAA;KAAE,CAAC;WAQ1C,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,WAAW,CAAA;KAAE,GACpD,OAAO,CAAC,GAAG,CAAC;CAMhB"}
@@ -0,0 +1,27 @@
1
+ import { Bytes } from "bytecodec";
2
+ import { CipherAgent } from "../CipherAgent/class.js";
3
+ export class CipherCluster {
4
+ static #agents = new WeakMap();
5
+ static #loadAgent(cipherJwk) {
6
+ const weakRef = CipherCluster.#agents.get(cipherJwk);
7
+ let agent = weakRef?.deref();
8
+ if (!agent) {
9
+ agent = new CipherAgent(cipherJwk);
10
+ CipherCluster.#agents.set(cipherJwk, new WeakRef(agent));
11
+ }
12
+ return agent;
13
+ }
14
+ static async encrypt(cipherJwk, resource) {
15
+ const agent = CipherCluster.#loadAgent(cipherJwk);
16
+ const bytes = Bytes.fromJSON(resource);
17
+ const compressed = await Bytes.toCompressed(bytes);
18
+ return await agent.encrypt(compressed);
19
+ }
20
+ static async decrypt(cipherJwk, artifact) {
21
+ const agent = CipherCluster.#loadAgent(cipherJwk);
22
+ const bytes = await agent.decrypt(artifact);
23
+ const decompressed = await Bytes.fromCompressed(bytes);
24
+ return Bytes.toJSON(decompressed);
25
+ }
26
+ }
27
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/CipherCluster/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,OAAO,GAAG,IAAI,OAAO,EAAoC,CAAC;IAEjE,MAAM,CAAC,UAAU,CAAC,SAAqB;QACrC,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;YACnC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAClB,SAAqB,EACrB,QAAa;QAEb,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEvC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACnD,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAClB,SAAqB,EACrB,QAAqD;QAErD,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5C,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class SigningAgent {
2
+ private keyPromise;
3
+ constructor(signingJwk: JsonWebKey);
4
+ sign(bytes: Uint8Array): Promise<ArrayBuffer>;
5
+ }
6
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/SigningAgent/class.ts"],"names":[],"mappings":"AACA,qBAAa,YAAY;IACvB,OAAO,CAAC,UAAU,CAAqB;gBAE3B,UAAU,EAAE,UAAU;IAU5B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAQpD"}
@@ -0,0 +1,12 @@
1
+ import { Bytes } from "bytecodec";
2
+ export class SigningAgent {
3
+ keyPromise;
4
+ constructor(signingJwk) {
5
+ this.keyPromise = crypto.subtle.importKey("jwk", signingJwk, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
6
+ }
7
+ async sign(bytes) {
8
+ const key = await this.keyPromise;
9
+ return crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key, Bytes.toBufferSource(bytes));
10
+ }
11
+ }
12
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/SigningAgent/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,MAAM,OAAO,YAAY;IACf,UAAU,CAAqB;IAEvC,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,UAAU,EACV,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EACtC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAiB;QAC1B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CACvB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAClC,GAAG,EACH,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAC5B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class SigningCluster {
2
+ #private;
3
+ static sign(signingJwk: JsonWebKey, value: any): Promise<ArrayBuffer>;
4
+ }
5
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/SigningCluster/class.ts"],"names":[],"mappings":"AAGA,qBAAa,cAAc;;WAaZ,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;CAK5E"}
@@ -0,0 +1,20 @@
1
+ import { Bytes } from "bytecodec";
2
+ import { SigningAgent } from "../SigningAgent/class.js";
3
+ export class SigningCluster {
4
+ static #agents = new WeakMap();
5
+ static #loadAgent(signingJwk) {
6
+ const weakRef = SigningCluster.#agents.get(signingJwk);
7
+ let agent = weakRef?.deref();
8
+ if (!agent) {
9
+ agent = new SigningAgent(signingJwk);
10
+ SigningCluster.#agents.set(signingJwk, new WeakRef(agent));
11
+ }
12
+ return agent;
13
+ }
14
+ static async sign(signingJwk, value) {
15
+ const agent = SigningCluster.#loadAgent(signingJwk);
16
+ const bytes = Bytes.fromJSON(value);
17
+ return await agent.sign(bytes);
18
+ }
19
+ }
20
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/SigningCluster/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,OAAO,GAAG,IAAI,OAAO,EAAqC,CAAC;IAElE,MAAM,CAAC,UAAU,CAAC,UAAsB;QACtC,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;YACrC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAsB,EAAE,KAAU;QAClD,MAAM,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACpC,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class UnwrappingAgent {
2
+ private keyPromise;
3
+ constructor(unwrappingJwk: JsonWebKey);
4
+ unwrap(wrapped: ArrayBuffer): Promise<JsonWebKey>;
5
+ }
6
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/UnwrappingAgent/class.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAqB;gBAC3B,aAAa,EAAE,UAAU;IAU/B,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAexD"}
@@ -0,0 +1,12 @@
1
+ export class UnwrappingAgent {
2
+ keyPromise;
3
+ constructor(unwrappingJwk) {
4
+ this.keyPromise = crypto.subtle.importKey("jwk", unwrappingJwk, { name: "RSA-OAEP", hash: "SHA-256" }, false, ["unwrapKey"]);
5
+ }
6
+ async unwrap(wrapped) {
7
+ const unwrappingKey = await this.keyPromise;
8
+ const aesKey = await crypto.subtle.unwrapKey("jwk", wrapped, unwrappingKey, { name: "RSA-OAEP" }, { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
9
+ return crypto.subtle.exportKey("jwk", aesKey);
10
+ }
11
+ }
12
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/UnwrappingAgent/class.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAe;IAClB,UAAU,CAAqB;IACvC,YAAY,aAAyB;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,aAAa,EACb,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,EACrC,KAAK,EACL,CAAC,WAAW,CAAC,CACd,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAoB;QAC/B,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAE5C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC1C,KAAK,EACL,OAAO,EACP,aAAa,EACb,EAAE,IAAI,EAAE,UAAU,EAAE,EACpB,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,IAAI,EACJ,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,CAAC;QAEF,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class UnwrappingCluster {
2
+ #private;
3
+ static unwrap(unwrappingJwk: JsonWebKey, wrapped: ArrayBuffer): Promise<JsonWebKey>;
4
+ }
5
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/UnwrappingCluster/class.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAiB;;WAaf,MAAM,CACjB,aAAa,EAAE,UAAU,EACzB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC;CAIvB"}
@@ -0,0 +1,18 @@
1
+ import { UnwrappingAgent } from "../UnwrappingAgent/class.js";
2
+ export class UnwrappingCluster {
3
+ static #agents = new WeakMap();
4
+ static #loadAgent(unwrappingJwk) {
5
+ const weakRef = UnwrappingCluster.#agents.get(unwrappingJwk);
6
+ let agent = weakRef?.deref();
7
+ if (!agent) {
8
+ agent = new UnwrappingAgent(unwrappingJwk);
9
+ UnwrappingCluster.#agents.set(unwrappingJwk, new WeakRef(agent));
10
+ }
11
+ return agent;
12
+ }
13
+ static async unwrap(unwrappingJwk, wrapped) {
14
+ const agent = UnwrappingCluster.#loadAgent(unwrappingJwk);
15
+ return await agent.unwrap(wrapped);
16
+ }
17
+ }
18
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/UnwrappingCluster/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,OAAO,GAAG,IAAI,OAAO,EAAwC,CAAC;IAErE,MAAM,CAAC,UAAU,CAAC,aAAyB;QACzC,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,eAAe,CAAC,aAAa,CAAC,CAAC;YAC3C,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,aAAyB,EACzB,OAAoB;QAEpB,MAAM,KAAK,GAAG,iBAAiB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QAC1D,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class VerificationAgent {
2
+ private keyPromise;
3
+ constructor(verificationJwk: JsonWebKey);
4
+ verify(bytes: Uint8Array, signature: ArrayBuffer): Promise<boolean>;
5
+ }
6
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/VerificationAgent/class.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAqB;gBAE3B,eAAe,EAAE,UAAU;IAUjC,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAS1E"}
@@ -0,0 +1,12 @@
1
+ import { Bytes } from "bytecodec";
2
+ export class VerificationAgent {
3
+ keyPromise;
4
+ constructor(verificationJwk) {
5
+ this.keyPromise = crypto.subtle.importKey("jwk", verificationJwk, { name: "ECDSA", namedCurve: "P-256" }, false, ["verify"]);
6
+ }
7
+ async verify(bytes, signature) {
8
+ const key = await this.keyPromise;
9
+ return crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, key, signature, Bytes.toBufferSource(bytes));
10
+ }
11
+ }
12
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/VerificationAgent/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,MAAM,OAAO,iBAAiB;IACpB,UAAU,CAAqB;IAEvC,YAAY,eAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,eAAe,EACf,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EACtC,KAAK,EACL,CAAC,QAAQ,CAAC,CACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAiB,EAAE,SAAsB;QACpD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CACzB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAClC,GAAG,EACH,SAAS,EACT,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAC5B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class VerificationCluster {
2
+ #private;
3
+ static verify(verificationJwk: JsonWebKey, value: any, signature: ArrayBuffer): Promise<boolean>;
4
+ }
5
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/VerificationCluster/class.ts"],"names":[],"mappings":"AAGA,qBAAa,mBAAmB;;WAajB,MAAM,CACjB,eAAe,EAAE,UAAU,EAC3B,KAAK,EAAE,GAAG,EACV,SAAS,EAAE,WAAW,GACrB,OAAO,CAAC,OAAO,CAAC;CAKpB"}
@@ -0,0 +1,20 @@
1
+ import { Bytes } from "bytecodec";
2
+ import { VerificationAgent } from "../VerificationAgent/class.js";
3
+ export class VerificationCluster {
4
+ static #agents = new WeakMap();
5
+ static #loadAgent(verificationJwk) {
6
+ const weakRef = VerificationCluster.#agents.get(verificationJwk);
7
+ let agent = weakRef?.deref();
8
+ if (!agent) {
9
+ agent = new VerificationAgent(verificationJwk);
10
+ VerificationCluster.#agents.set(verificationJwk, new WeakRef(agent));
11
+ }
12
+ return agent;
13
+ }
14
+ static async verify(verificationJwk, value, signature) {
15
+ const agent = VerificationCluster.#loadAgent(verificationJwk);
16
+ const valueBytes = Bytes.fromJSON(value);
17
+ return await agent.verify(valueBytes, signature);
18
+ }
19
+ }
20
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/VerificationCluster/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,OAAO,mBAAmB;IAC9B,MAAM,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0C,CAAC;IAEvE,MAAM,CAAC,UAAU,CAAC,eAA2B;QAC3C,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACjE,IAAI,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;YAC/C,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,eAA2B,EAC3B,KAAU,EACV,SAAsB;QAEtB,MAAM,KAAK,GAAG,mBAAmB,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QAC9D,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class WrappingAgent {
2
+ private keyPromise;
3
+ constructor(wrappingJwk: JsonWebKey);
4
+ wrap(cipherJwk: JsonWebKey): Promise<ArrayBuffer>;
5
+ }
6
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/WrappingAgent/class.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAqB;gBAC3B,WAAW,EAAE,UAAU;IAU7B,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAexD"}
@@ -0,0 +1,14 @@
1
+ export class WrappingAgent {
2
+ keyPromise;
3
+ constructor(wrappingJwk) {
4
+ this.keyPromise = crypto.subtle.importKey("jwk", wrappingJwk, { name: "RSA-OAEP", hash: "SHA-256" }, false, ["wrapKey"]);
5
+ }
6
+ async wrap(cipherJwk) {
7
+ const wrappingKey = await this.keyPromise;
8
+ const aesKey = await crypto.subtle.importKey("jwk", cipherJwk, { name: "AES-GCM" }, true, ["encrypt", "decrypt"]);
9
+ return crypto.subtle.wrapKey("jwk", aesKey, wrappingKey, {
10
+ name: "RSA-OAEP",
11
+ });
12
+ }
13
+ }
14
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/WrappingAgent/class.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IAChB,UAAU,CAAqB;IACvC,YAAY,WAAuB;QACjC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,WAAW,EACX,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,EACrC,KAAK,EACL,CAAC,SAAS,CAAC,CACZ,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAqB;QAC9B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAE1C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC1C,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,IAAI,EACJ,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,CAAC;QAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE;YACvD,IAAI,EAAE,UAAU;SACjB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class WrappingCluster {
2
+ #private;
3
+ static wrap(wrappingJwk: JsonWebKey, cipherJwk: JsonWebKey): Promise<ArrayBuffer>;
4
+ }
5
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/WrappingCluster/class.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAe;;WAab,IAAI,CACf,WAAW,EAAE,UAAU,EACvB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,WAAW,CAAC;CAIxB"}
@@ -0,0 +1,18 @@
1
+ import { WrappingAgent } from "../WrappingAgent/class.js";
2
+ export class WrappingCluster {
3
+ static #agents = new WeakMap();
4
+ static #loadAgent(wrappingJwk) {
5
+ const weakRef = WrappingCluster.#agents.get(wrappingJwk);
6
+ let agent = weakRef?.deref();
7
+ if (!agent) {
8
+ agent = new WrappingAgent(wrappingJwk);
9
+ WrappingCluster.#agents.set(wrappingJwk, new WeakRef(agent));
10
+ }
11
+ return agent;
12
+ }
13
+ static async wrap(wrappingJwk, cipherJwk) {
14
+ const agent = WrappingCluster.#loadAgent(wrappingJwk);
15
+ return await agent.wrap(cipherJwk);
16
+ }
17
+ }
18
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/WrappingCluster/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,OAAO,GAAG,IAAI,OAAO,EAAsC,CAAC;IAEnE,MAAM,CAAC,UAAU,CAAC,WAAuB;QACvC,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzD,IAAI,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;YACvC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,WAAuB,EACvB,SAAqB;QAErB,MAAM,KAAK,GAAG,eAAe,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACtD,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function generateKeyset(): Promise<{
2
+ cipherJwk: JsonWebKey;
3
+ verificationJwk: JsonWebKey;
4
+ signingJwk: JsonWebKey;
5
+ wrappingJwk: JsonWebKey;
6
+ unwrappingJwk: JsonWebKey;
7
+ }>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generateKeyset/index.ts"],"names":[],"mappings":"AAAA,wBAAsB,cAAc,IAAI,OAAO,CAAC;IAC9C,SAAS,EAAE,UAAU,CAAC;IACtB,eAAe,EAAE,UAAU,CAAC;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,UAAU,CAAC;IACxB,aAAa,EAAE,UAAU,CAAC;CAC3B,CAAC,CA0CD"}
@@ -0,0 +1,23 @@
1
+ export async function generateKeyset() {
2
+ const aesKey = await crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
3
+ const cipherJwk = await crypto.subtle.exportKey("jwk", aesKey);
4
+ const signPair = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
5
+ const verificationJwk = await crypto.subtle.exportKey("jwk", signPair.publicKey);
6
+ const signingJwk = await crypto.subtle.exportKey("jwk", signPair.privateKey);
7
+ const wrapPair = await crypto.subtle.generateKey({
8
+ name: "RSA-OAEP",
9
+ modulusLength: 4096,
10
+ publicExponent: new Uint8Array([1, 0, 1]),
11
+ hash: "SHA-256",
12
+ }, true, ["wrapKey", "unwrapKey"]);
13
+ const wrappingJwk = await crypto.subtle.exportKey("jwk", wrapPair.publicKey);
14
+ const unwrappingJwk = await crypto.subtle.exportKey("jwk", wrapPair.privateKey);
15
+ return {
16
+ cipherJwk,
17
+ verificationJwk,
18
+ signingJwk,
19
+ wrappingJwk,
20
+ unwrappingJwk,
21
+ };
22
+ }
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generateKeyset/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,cAAc;IAOlC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,CAC5C,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,IAAI,EACJ,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAE/D,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,CAC9C,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EACtC,IAAI,EACJ,CAAC,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;IACF,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CACnD,KAAK,EACL,QAAQ,CAAC,SAAS,CACnB,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE7E,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,CAC9C;QACE,IAAI,EAAE,UAAU;QAChB,aAAa,EAAE,IAAI;QACnB,cAAc,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,IAAI,EAAE,SAAS;KAChB,EACD,IAAI,EACJ,CAAC,SAAS,EAAE,WAAW,CAAC,CACzB,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7E,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CACjD,KAAK,EACL,QAAQ,CAAC,UAAU,CACpB,CAAC;IAEF,OAAO;QACL,SAAS;QACT,eAAe;QACf,UAAU;QACV,WAAW;QACX,aAAa;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { generateKeyset } from "./generateKeyset/index.js";
2
+ import { CipherAgent } from "./CipherAgent/class.js";
3
+ import { SigningAgent } from "./SigningAgent/class.js";
4
+ import { VerificationAgent } from "./VerificationAgent/class.js";
5
+ import { CipherCluster } from "./CipherCluster/class.js";
6
+ import { SigningCluster } from "./SigningCluster/class.js";
7
+ import { VerificationCluster } from "./VerificationCluster/class.js";
8
+ import { WrappingAgent } from "./WrappingAgent/class.js";
9
+ import { WrappingCluster } from "./WrappingCluster/class.js";
10
+ import { UnwrappingAgent } from "./UnwrappingAgent/class.js";
11
+ import { UnwrappingCluster } from "./UnwrappingCluster/class.js";
12
+ export { generateKeyset, CipherAgent, SigningAgent, VerificationAgent, WrappingAgent, UnwrappingAgent, CipherCluster, SigningCluster, VerificationCluster, WrappingCluster, UnwrappingCluster, };
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { generateKeyset } from "./generateKeyset/index.js";
2
+ import { CipherAgent } from "./CipherAgent/class.js";
3
+ import { SigningAgent } from "./SigningAgent/class.js";
4
+ import { VerificationAgent } from "./VerificationAgent/class.js";
5
+ import { CipherCluster } from "./CipherCluster/class.js";
6
+ import { SigningCluster } from "./SigningCluster/class.js";
7
+ import { VerificationCluster } from "./VerificationCluster/class.js";
8
+ import { WrappingAgent } from "./WrappingAgent/class.js";
9
+ import { WrappingCluster } from "./WrappingCluster/class.js";
10
+ import { UnwrappingAgent } from "./UnwrappingAgent/class.js";
11
+ import { UnwrappingCluster } from "./UnwrappingCluster/class.js";
12
+ export { generateKeyset, CipherAgent, SigningAgent, VerificationAgent, WrappingAgent, UnwrappingAgent, CipherCluster, SigningCluster, VerificationCluster, WrappingCluster, UnwrappingCluster, };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,CAAC"}
package/package.json CHANGED
@@ -1,21 +1,32 @@
1
1
  {
2
2
  "name": "zeyra",
3
- "version": "1.0.1",
4
- "description": "WebCrypto helper for generating JWK keysets plus AES-GCM encryption and ECDSA signing agents.",
3
+ "version": "2.0.0",
4
+ "description": "Client-side WebCrypto helpers for AES-GCM encryption, ECDSA signatures, and RSA-OAEP key wrapping.",
5
5
  "keywords": [
6
6
  "webcrypto",
7
7
  "aes-gcm",
8
8
  "ecdsa",
9
+ "rsa-oaep",
9
10
  "jwk",
10
11
  "encryption",
11
- "signature"
12
+ "signature",
13
+ "key-wrapping",
14
+ "wrapping",
15
+ "unwrapping",
16
+ "cluster",
17
+ "keyset",
18
+ "compression",
19
+ "bytecodec",
20
+ "typescript"
12
21
  ],
13
22
  "license": "MIT",
14
23
  "type": "module",
15
- "main": "src/index.js",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
16
26
  "scripts": {
17
- "test": "node --test test.js && node test.js --bench",
18
- "bench": "node test.js --bench",
27
+ "build": "tsc -p tsconfig.json",
28
+ "test": "npm run build && node --test test.js && node test.js --bench",
29
+ "bench": "npm run build && node test.js --bench",
19
30
  "prepublishOnly": "npm test"
20
31
  },
21
32
  "repository": {
@@ -27,19 +38,23 @@
27
38
  },
28
39
  "homepage": "https://github.com/jortsupetterson/zeyra#readme",
29
40
  "dependencies": {
30
- "bytecodec": "^1.2.1"
41
+ "bytecodec": "^2.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^5.5.4"
31
45
  },
32
46
  "engines": {
33
47
  "node": ">=18"
34
48
  },
35
49
  "exports": {
36
50
  ".": {
37
- "import": "./src/index.js"
51
+ "types": "./dist/index.d.ts",
52
+ "import": "./dist/index.js"
38
53
  },
39
54
  "./package.json": "./package.json"
40
55
  },
41
56
  "files": [
42
- "src",
57
+ "dist",
43
58
  "LICENSE",
44
59
  "README.md"
45
60
  ],
@@ -1,43 +0,0 @@
1
- export class CipherAgent {
2
- /**
3
- * @param {JsonWebKey} symmetricJwk // AES-GCM (kty:"oct", alg:"A256GCM")
4
- */
5
- constructor(symmetricJwk) {
6
- this.keyPromise = crypto.subtle.importKey(
7
- "jwk",
8
- symmetricJwk,
9
- { name: "AES-GCM" },
10
- false,
11
- ["encrypt", "decrypt"]
12
- );
13
- }
14
-
15
- /**
16
- * @param {Uint8Array} plaintext
17
- * @returns {Promise<{ iv: Uint8Array, ciphertext: ArrayBuffer }>}
18
- */
19
- async encrypt(plaintext) {
20
- const key = await this.keyPromise;
21
- const iv = crypto.getRandomValues(new Uint8Array(12));
22
- const ciphertext = await crypto.subtle.encrypt(
23
- { name: "AES-GCM", iv },
24
- key,
25
- plaintext
26
- );
27
- return { iv, ciphertext };
28
- }
29
-
30
- /**
31
- * @param {{ iv: Uint8Array, ciphertext: ArrayBuffer }} payload
32
- * @returns {Promise<Uint8Array>}
33
- */
34
- async decrypt({ iv, ciphertext }) {
35
- const key = await this.keyPromise;
36
- const plaintext = await crypto.subtle.decrypt(
37
- { name: "AES-GCM", iv },
38
- key,
39
- ciphertext
40
- );
41
- return new Uint8Array(plaintext);
42
- }
43
- }
@@ -1,23 +0,0 @@
1
- export class SigningAgent {
2
- /**
3
- * @param {JsonWebKey} privateJwk // ECDSA P-256 private key
4
- */
5
- constructor(privateJwk) {
6
- this.keyPromise = crypto.subtle.importKey(
7
- "jwk",
8
- privateJwk,
9
- { name: "ECDSA", namedCurve: "P-256" },
10
- false,
11
- ["sign"]
12
- );
13
- }
14
-
15
- /**
16
- * @param {Uint8Array} bytes
17
- * @returns {Promise<ArrayBuffer>}
18
- */
19
- async sign(bytes) {
20
- const key = await this.keyPromise;
21
- return crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key, bytes);
22
- }
23
- }
@@ -1,29 +0,0 @@
1
- export class VerificationAgent {
2
- /**
3
- * @param {JsonWebKey} publicJwk // ECDSA P-256 public key
4
- */
5
- constructor(publicJwk) {
6
- this.keyPromise = crypto.subtle.importKey(
7
- "jwk",
8
- publicJwk,
9
- { name: "ECDSA", namedCurve: "P-256" },
10
- false,
11
- ["verify"]
12
- );
13
- }
14
-
15
- /**
16
- * @param {Uint8Array} bytes
17
- * @param {ArrayBuffer} signature
18
- * @returns {Promise<boolean>}
19
- */
20
- async verify(bytes, signature) {
21
- const key = await this.keyPromise;
22
- return crypto.subtle.verify(
23
- { name: "ECDSA", hash: "SHA-256" },
24
- key,
25
- signature,
26
- bytes
27
- );
28
- }
29
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Generates a cryptographic keyset for a single resource.
3
- *
4
- * Returned keys:
5
- * - symmetricJwk: AES-GCM 256-bit key (JWK, kty:"oct") for encrypt/decrypt
6
- * - publicJwk: ECDSA P-256 public key (JWK) for verify
7
- * - privateJwk: ECDSA P-256 private key (JWK) for sign
8
- *
9
- * All keys are extractable and intended to be stored encrypted
10
- * or transported as data. Type definitions are expected to live
11
- * in a separate TypeScript types file.
12
- *
13
- * @returns {Promise<{
14
- * symmetricJwk: JsonWebKey,
15
- * publicJwk: JsonWebKey,
16
- * privateJwk: JsonWebKey
17
- * }>}
18
- */
19
- export async function generateKeyset() {
20
- const aesKey = await crypto.subtle.generateKey(
21
- { name: "AES-GCM", length: 256 },
22
- true,
23
- ["encrypt", "decrypt"]
24
- );
25
- const symmetricJwk = await crypto.subtle.exportKey("jwk", aesKey);
26
-
27
- const keyPair = await crypto.subtle.generateKey(
28
- { name: "ECDSA", namedCurve: "P-256" },
29
- true,
30
- ["sign", "verify"]
31
- );
32
- const publicJwk = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
33
- const privateJwk = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
34
-
35
- return { symmetricJwk, publicJwk, privateJwk };
36
- }
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- import { generateKeyset } from "./generateKeyset/index.js";
2
- import { CipherAgent } from "./CipherAgent/class.js";
3
- import { SigningAgent } from "./SigningAgent/class.js";
4
- import { VerificationAgent } from "./VerificationAgent/class.js";
5
- export { generateKeyset, CipherAgent, SigningAgent, VerificationAgent };