zeyra 1.1.0 → 2.1.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/README.md +183 -97
- package/dist/CipherAgent/class.d.ts +13 -0
- package/dist/CipherAgent/class.d.ts.map +1 -0
- package/dist/CipherAgent/class.js +19 -0
- package/dist/CipherAgent/class.js.map +1 -0
- package/dist/CipherCluster/class.d.ts +12 -0
- package/dist/CipherCluster/class.d.ts.map +1 -0
- package/dist/CipherCluster/class.js +27 -0
- package/dist/CipherCluster/class.js.map +1 -0
- package/dist/HmacAgent/class.d.ts +7 -0
- package/dist/HmacAgent/class.d.ts.map +1 -0
- package/dist/HmacAgent/class.js +15 -0
- package/dist/HmacAgent/class.js.map +1 -0
- package/dist/SigningAgent/class.d.ts +6 -0
- package/dist/SigningAgent/class.d.ts.map +1 -0
- package/dist/SigningAgent/class.js +12 -0
- package/dist/SigningAgent/class.js.map +1 -0
- package/dist/SigningCluster/class.d.ts +5 -0
- package/dist/SigningCluster/class.d.ts.map +1 -0
- package/dist/SigningCluster/class.js +20 -0
- package/dist/SigningCluster/class.js.map +1 -0
- package/dist/UnwrappingAgent/class.d.ts +6 -0
- package/dist/UnwrappingAgent/class.d.ts.map +1 -0
- package/dist/UnwrappingAgent/class.js +12 -0
- package/dist/UnwrappingAgent/class.js.map +1 -0
- package/dist/UnwrappingCluster/class.d.ts +5 -0
- package/dist/UnwrappingCluster/class.d.ts.map +1 -0
- package/dist/UnwrappingCluster/class.js +18 -0
- package/dist/UnwrappingCluster/class.js.map +1 -0
- package/dist/VerificationAgent/class.d.ts +6 -0
- package/dist/VerificationAgent/class.d.ts.map +1 -0
- package/dist/VerificationAgent/class.js +12 -0
- package/dist/VerificationAgent/class.js.map +1 -0
- package/dist/VerificationCluster/class.d.ts +5 -0
- package/dist/VerificationCluster/class.d.ts.map +1 -0
- package/dist/VerificationCluster/class.js +20 -0
- package/dist/VerificationCluster/class.js.map +1 -0
- package/dist/WrappingAgent/class.d.ts +6 -0
- package/dist/WrappingAgent/class.d.ts.map +1 -0
- package/dist/WrappingAgent/class.js +14 -0
- package/dist/WrappingAgent/class.js.map +1 -0
- package/dist/WrappingCluster/class.d.ts +5 -0
- package/dist/WrappingCluster/class.d.ts.map +1 -0
- package/dist/WrappingCluster/class.js +18 -0
- package/dist/WrappingCluster/class.js.map +1 -0
- package/dist/deriveRootKeys/deriveCipherKey.d.ts +2 -0
- package/dist/deriveRootKeys/deriveCipherKey.d.ts.map +1 -0
- package/dist/deriveRootKeys/deriveCipherKey.js +5 -0
- package/dist/deriveRootKeys/deriveCipherKey.js.map +1 -0
- package/dist/deriveRootKeys/deriveHmacKey.d.ts +2 -0
- package/dist/deriveRootKeys/deriveHmacKey.d.ts.map +1 -0
- package/dist/deriveRootKeys/deriveHmacKey.js +5 -0
- package/dist/deriveRootKeys/deriveHmacKey.js.map +1 -0
- package/dist/deriveRootKeys/index.d.ts +6 -0
- package/dist/deriveRootKeys/index.d.ts.map +1 -0
- package/dist/deriveRootKeys/index.js +21 -0
- package/dist/deriveRootKeys/index.js.map +1 -0
- package/dist/generateKeyset/generateCipherKey/index.d.ts +2 -0
- package/dist/generateKeyset/generateCipherKey/index.d.ts.map +1 -0
- package/dist/generateKeyset/generateCipherKey/index.js +5 -0
- package/dist/generateKeyset/generateCipherKey/index.js.map +1 -0
- package/dist/generateKeyset/generateHmacKey/index.d.ts +2 -0
- package/dist/generateKeyset/generateHmacKey/index.d.ts.map +1 -0
- package/dist/generateKeyset/generateHmacKey/index.js +5 -0
- package/dist/generateKeyset/generateHmacKey/index.js.map +1 -0
- package/dist/generateKeyset/generateSignPair/index.d.ts +5 -0
- package/dist/generateKeyset/generateSignPair/index.d.ts.map +1 -0
- package/dist/generateKeyset/generateSignPair/index.js +7 -0
- package/dist/generateKeyset/generateSignPair/index.js.map +1 -0
- package/dist/generateKeyset/generateWrapPair/index.d.ts +5 -0
- package/dist/generateKeyset/generateWrapPair/index.d.ts.map +1 -0
- package/dist/generateKeyset/generateWrapPair/index.js +12 -0
- package/dist/generateKeyset/generateWrapPair/index.js.map +1 -0
- package/dist/generateKeyset/index.d.ts +9 -0
- package/dist/generateKeyset/index.d.ts.map +1 -0
- package/dist/generateKeyset/index.js +19 -0
- package/dist/generateKeyset/index.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -53
- package/src/CipherAgent/class.js +0 -43
- package/src/CipherCluster/class.js +0 -57
- package/src/SigningAgent/class.js +0 -23
- package/src/SigningCluster/class.js +0 -34
- package/src/VerificationAgent/class.js +0 -29
- package/src/VerificationCluster/class.js +0 -35
- package/src/generateKeyset/index.js +0 -36
- package/src/index.js +0 -16
package/README.md
CHANGED
|
@@ -1,113 +1,199 @@
|
|
|
1
|
-
# Zeyra
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
- ECDSA P-256
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
# Zeyra
|
|
2
|
+
|
|
3
|
+
Client-side WebCrypto helpers for AES-GCM encryption, ECDSA signatures, RSA-OAEP key wrapping, HMAC, and key generation, 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, RSA-OAEP, and HMAC SHA-256 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
|
+
- HMAC SHA-256 sign/verify via `HmacAgent` + key generation via `generateHmacKey()`
|
|
16
|
+
- RSA-OAEP 4096 wrap/unwrap for AES-GCM JWKs
|
|
17
|
+
- WebAuthn PRF root key derivation via `deriveRootKeys()`
|
|
18
|
+
- `generateKeyset()` yields `cipherJwk`, `signingJwk`, `verificationJwk`, `wrappingJwk`, `unwrappingJwk`, `hmacJwk`
|
|
19
|
+
- Individual key generators are available when you only need one key type.
|
|
20
|
+
- Cluster classes cache agents with `WeakRef`; they are a lightweight optimization, not a full end-to-end solution
|
|
21
|
+
- Byte-oriented clusters return raw `Uint8Array` / `ArrayBuffer` (no base64); use `bytecodec` for JSON, compression, and encoding
|
|
22
|
+
- TypeScript source; published package ships compiled JS + `.d.ts`
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- Node.js 18+ for server/edge usage
|
|
27
|
+
- ESM environment (`"type": "module"`)
|
|
28
|
+
- `bytecodec` for JSON/bytes/compression helpers
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm install zeyra
|
|
34
|
+
# or
|
|
35
|
+
pnpm add zeyra
|
|
36
|
+
# or
|
|
37
|
+
yarn add zeyra
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quickstart (agents)
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { Bytes } from "bytecodec";
|
|
44
|
+
import {
|
|
45
|
+
generateKeyset,
|
|
46
|
+
CipherAgent,
|
|
47
|
+
SigningAgent,
|
|
48
|
+
VerificationAgent,
|
|
49
|
+
} from "zeyra";
|
|
50
|
+
|
|
51
|
+
const { cipherJwk, signingJwk, verificationJwk } = await generateKeyset();
|
|
52
|
+
|
|
53
|
+
const cipher = new CipherAgent(cipherJwk);
|
|
54
|
+
const signer = new SigningAgent(signingJwk);
|
|
55
|
+
const verifier = new VerificationAgent(verificationJwk);
|
|
56
|
+
|
|
57
|
+
const payload = await cipher.encrypt(Bytes.fromString("hello world"));
|
|
58
|
+
const ciphertextBytes = new Uint8Array(payload.ciphertext);
|
|
59
|
+
const signature = await signer.sign(ciphertextBytes);
|
|
60
|
+
|
|
61
|
+
const authorized = await verifier.verify(ciphertextBytes, signature);
|
|
62
|
+
const plaintext = Bytes.toString(await cipher.decrypt(payload));
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Managed cluster flow
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import {
|
|
69
|
+
generateKeyset,
|
|
70
|
+
CipherCluster,
|
|
71
|
+
SigningCluster,
|
|
72
|
+
VerificationCluster,
|
|
73
|
+
} from "zeyra";
|
|
74
|
+
|
|
75
|
+
const { cipherJwk, signingJwk, verificationJwk } = await generateKeyset();
|
|
76
|
+
|
|
77
|
+
const resource = { id: "file-123", body: "hello world" };
|
|
78
|
+
const artifact = await CipherCluster.encrypt(cipherJwk, resource);
|
|
79
|
+
// artifact: { iv: Uint8Array, ciphertext: ArrayBuffer }
|
|
80
|
+
|
|
81
|
+
const signature = await SigningCluster.sign(signingJwk, resource.id);
|
|
82
|
+
const authorized = await VerificationCluster.verify(
|
|
83
|
+
verificationJwk,
|
|
84
|
+
resource.id,
|
|
85
|
+
signature
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const decrypted = await CipherCluster.decrypt(cipherJwk, artifact);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Key wrapping flow
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { generateKeyset, WrappingCluster, UnwrappingCluster } from "zeyra";
|
|
95
|
+
|
|
96
|
+
const { cipherJwk, wrappingJwk, unwrappingJwk } = await generateKeyset();
|
|
97
|
+
|
|
98
|
+
const wrapped = await WrappingCluster.wrap(wrappingJwk, cipherJwk);
|
|
99
|
+
const unwrappedCipherJwk = await UnwrappingCluster.unwrap(
|
|
100
|
+
unwrappingJwk,
|
|
101
|
+
wrapped
|
|
102
|
+
);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## HMAC flow
|
|
27
106
|
|
|
28
107
|
```js
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
generateKeyset,
|
|
32
|
-
CipherAgent,
|
|
33
|
-
SigningAgent,
|
|
34
|
-
VerificationAgent,
|
|
35
|
-
} from "zeyra";
|
|
36
|
-
|
|
37
|
-
// One-time key material for a resource
|
|
38
|
-
const { symmetricJwk, privateJwk, publicJwk } = await generateKeyset();
|
|
108
|
+
import { generateHmacKey, HmacAgent } from "zeyra";
|
|
39
109
|
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const signer = new SigningAgent(privateJwk);
|
|
43
|
-
const payload = await cipher.encrypt(Bytes.fromString("hello world"));
|
|
44
|
-
const signature = await signer.sign(payload.ciphertext);
|
|
110
|
+
const hmacJwk = await generateHmacKey();
|
|
111
|
+
const hmac = new HmacAgent(hmacJwk);
|
|
45
112
|
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const authorized = await
|
|
49
|
-
const plaintext = Bytes.toString(await cipher.decrypt(payload));
|
|
113
|
+
const challenge = new TextEncoder().encode("hello world");
|
|
114
|
+
const signature = await hmac.sign(challenge);
|
|
115
|
+
const authorized = await hmac.verify(challenge, signature);
|
|
50
116
|
```
|
|
51
117
|
|
|
52
|
-
##
|
|
118
|
+
## PRF root key derivation
|
|
53
119
|
|
|
54
|
-
|
|
55
|
-
import {
|
|
56
|
-
generateKeyset,
|
|
57
|
-
CipherCluster,
|
|
58
|
-
SigningCluster,
|
|
59
|
-
VerificationCluster,
|
|
60
|
-
} from "zeyra";
|
|
61
|
-
|
|
62
|
-
const { symmetricJwk, privateJwk, publicJwk } = await generateKeyset();
|
|
120
|
+
Pass WebAuthn PRF results (from `assertion.getClientExtensionResults()?.prf?.results`) to derive HMAC + AES root keys.
|
|
63
121
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const signature = await SigningCluster.sign(privateJwk, resource.id);
|
|
122
|
+
```js
|
|
123
|
+
import { deriveRootKeys } from "zeyra";
|
|
67
124
|
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
resource.id,
|
|
72
|
-
signature
|
|
73
|
-
);
|
|
125
|
+
const prfResults = assertion.getClientExtensionResults()?.prf?.results;
|
|
126
|
+
const rootKeys = await deriveRootKeys(prfResults);
|
|
127
|
+
if (!rootKeys) throw new Error("Missing PRF results");
|
|
74
128
|
|
|
75
|
-
const
|
|
129
|
+
const { hmacJwk, cipherJwk } = rootKeys;
|
|
76
130
|
```
|
|
77
131
|
|
|
78
132
|
## API
|
|
79
133
|
|
|
80
|
-
- `generateKeyset()` -> `{
|
|
81
|
-
- `
|
|
134
|
+
- `generateKeyset()` -> `{ cipherJwk, verificationJwk, signingJwk, wrappingJwk, unwrappingJwk, hmacJwk }`
|
|
135
|
+
- `generateHmacKey()` -> `JsonWebKey` (HMAC SHA-256)
|
|
136
|
+
- `generateCipherKey()` -> `JsonWebKey` (AES-GCM 256)
|
|
137
|
+
- `generateSignPair()` -> `{ signingJwk, verificationJwk }` (ECDSA P-256)
|
|
138
|
+
- `generateWrapPair()` -> `{ wrappingJwk, unwrappingJwk }` (RSA-OAEP 4096)
|
|
139
|
+
- `deriveRootKeys(prfResults)` -> `{ hmacJwk, cipherJwk } | false`
|
|
140
|
+
- `new CipherAgent(cipherJwk)`
|
|
82
141
|
- `.encrypt(Uint8Array)` -> `{ iv: Uint8Array, ciphertext: ArrayBuffer }`
|
|
83
142
|
- `.decrypt({ iv, ciphertext })` -> `Uint8Array`
|
|
84
|
-
- `new
|
|
85
|
-
- `.sign(
|
|
86
|
-
-
|
|
87
|
-
|
|
88
|
-
- `
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
- `
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
143
|
+
- `new HmacAgent(hmacJwk)`
|
|
144
|
+
- `.sign(BufferSource)` -> `ArrayBuffer` (HMAC SHA-256)
|
|
145
|
+
- `.verify(BufferSource, BufferSource)` -> `boolean`
|
|
146
|
+
- `new SigningAgent(signingJwk)`
|
|
147
|
+
- `.sign(Uint8Array)` -> `ArrayBuffer` (ECDSA P-256 / SHA-256)
|
|
148
|
+
- `new VerificationAgent(verificationJwk)`
|
|
149
|
+
- `.verify(Uint8Array, ArrayBuffer)` -> `boolean`
|
|
150
|
+
- `new WrappingAgent(wrappingJwk)`
|
|
151
|
+
- `.wrap(cipherJwk)` -> `ArrayBuffer` (RSA-OAEP / SHA-256)
|
|
152
|
+
- `new UnwrappingAgent(unwrappingJwk)`
|
|
153
|
+
- `.unwrap(ArrayBuffer)` -> `JsonWebKey`
|
|
154
|
+
- `CipherCluster.encrypt(cipherJwk, resource)` -> `{ iv, ciphertext }`
|
|
155
|
+
- `CipherCluster.decrypt(cipherJwk, artifact)` -> `resource`
|
|
156
|
+
- `SigningCluster.sign(signingJwk, value)` -> `ArrayBuffer`
|
|
157
|
+
- `VerificationCluster.verify(verificationJwk, value, signature)` -> `boolean`
|
|
158
|
+
- `WrappingCluster.wrap(wrappingJwk, cipherJwk)` -> `ArrayBuffer`
|
|
159
|
+
- `UnwrappingCluster.unwrap(unwrappingJwk, wrapped)` -> `JsonWebKey`
|
|
160
|
+
|
|
161
|
+
## Serialization helpers
|
|
162
|
+
|
|
163
|
+
Zeyra keeps clusters byte-oriented. Use `bytecodec` when you need to serialize or store artifacts.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
import { Bytes } from "bytecodec";
|
|
167
|
+
|
|
168
|
+
const artifact = await CipherCluster.encrypt(cipherJwk, resource);
|
|
169
|
+
const ciphertextB64 = Bytes.toBase64UrlString(
|
|
170
|
+
new Uint8Array(artifact.ciphertext)
|
|
171
|
+
);
|
|
172
|
+
const ivB64 = Bytes.toBase64UrlString(artifact.iv);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Testing and benchmarks
|
|
176
|
+
|
|
177
|
+
- Build: `npm run build` (outputs `dist/`)
|
|
178
|
+
- Run tests: `npm test` (builds `dist/`, then runs `node --test`)
|
|
179
|
+
- Run benchmarks: `npm run bench`
|
|
180
|
+
- Pass iterations: `npm run bench -- --iterations=500`
|
|
181
|
+
|
|
182
|
+
## Benchmarks (local)
|
|
183
|
+
|
|
184
|
+
Results will vary by hardware, runtime, and payload size. Run `npm run bench` to reproduce.
|
|
185
|
+
|
|
186
|
+
- Node v22.14.0 (Windows), iterations=200
|
|
187
|
+
- encrypt only: 31.68ms (6313.6 ops/sec)
|
|
188
|
+
- hmac sign/verify: 40.48ms (4940.1 ops/sec)
|
|
189
|
+
- full pipeline: 122.61ms (1631.2 ops/sec)
|
|
190
|
+
|
|
191
|
+
## Notes
|
|
192
|
+
|
|
193
|
+
- Zeyra is intended for client-side encryption workflows; server/edge usage is supported where WebCrypto is available.
|
|
194
|
+
- Cluster helpers cache keys with `WeakRef` and keep `CryptoKey` material private inside agents.
|
|
195
|
+
- `CipherCluster` compresses JSON payloads before encryption; `SigningCluster`/`VerificationCluster` sign JSON values.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
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 @@
|
|
|
1
|
+
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/HmacAgent/class.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAqB;gBAE3B,OAAO,EAAE,UAAU;IAUzB,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAKnD,MAAM,CACV,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,OAAO,CAAC;CAIpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class HmacAgent {
|
|
2
|
+
keyPromise;
|
|
3
|
+
constructor(hmacJwk) {
|
|
4
|
+
this.keyPromise = crypto.subtle.importKey("jwk", hmacJwk, { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
5
|
+
}
|
|
6
|
+
async sign(challenge) {
|
|
7
|
+
const key = await this.keyPromise;
|
|
8
|
+
return crypto.subtle.sign("HMAC", key, challenge);
|
|
9
|
+
}
|
|
10
|
+
async verify(challenge, signature) {
|
|
11
|
+
const key = await this.keyPromise;
|
|
12
|
+
return crypto.subtle.verify("HMAC", key, signature, challenge);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/HmacAgent/class.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IACZ,UAAU,CAAqB;IAEvC,YAAY,OAAmB;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,OAAO,EACP,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAuB;QAChC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,MAAM,CACV,SAAuB,EACvB,SAAuB;QAEvB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACjE,CAAC;CACF"}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|