ehbp 0.0.6 → 0.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.
Files changed (63) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +158 -0
  3. package/dist/cjs/client.d.ts +13 -13
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +39 -50
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/derive.d.ts +63 -0
  8. package/dist/cjs/derive.d.ts.map +1 -0
  9. package/dist/cjs/derive.js +136 -0
  10. package/dist/cjs/derive.js.map +1 -0
  11. package/dist/cjs/identity.d.ts +37 -10
  12. package/dist/cjs/identity.d.ts.map +1 -1
  13. package/dist/cjs/identity.js +169 -150
  14. package/dist/cjs/identity.js.map +1 -1
  15. package/dist/cjs/index.d.ts +4 -1
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/index.js +15 -1
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/protocol.d.ts +1 -1
  20. package/dist/cjs/protocol.js +2 -2
  21. package/dist/cjs/protocol.js.map +1 -1
  22. package/dist/esm/client.d.ts +13 -13
  23. package/dist/esm/client.d.ts.map +1 -1
  24. package/dist/esm/client.js +39 -50
  25. package/dist/esm/client.js.map +1 -1
  26. package/dist/esm/derive.d.ts +63 -0
  27. package/dist/esm/derive.d.ts.map +1 -0
  28. package/dist/esm/derive.js +127 -0
  29. package/dist/esm/derive.js.map +1 -0
  30. package/dist/esm/identity.d.ts +37 -10
  31. package/dist/esm/identity.d.ts.map +1 -1
  32. package/dist/esm/identity.js +169 -150
  33. package/dist/esm/identity.js.map +1 -1
  34. package/dist/esm/index.d.ts +4 -1
  35. package/dist/esm/index.d.ts.map +1 -1
  36. package/dist/esm/index.js +2 -0
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/protocol.d.ts +1 -1
  39. package/dist/esm/protocol.js +2 -2
  40. package/dist/esm/protocol.js.map +1 -1
  41. package/dist/esm/test/client.test.js +15 -16
  42. package/dist/esm/test/client.test.js.map +1 -1
  43. package/dist/esm/test/derive.test.d.ts +2 -0
  44. package/dist/esm/test/derive.test.d.ts.map +1 -0
  45. package/dist/esm/test/derive.test.js +164 -0
  46. package/dist/esm/test/derive.test.js.map +1 -0
  47. package/dist/esm/test/security.test.d.ts +10 -0
  48. package/dist/esm/test/security.test.d.ts.map +1 -0
  49. package/dist/esm/test/security.test.js +153 -0
  50. package/dist/esm/test/security.test.js.map +1 -0
  51. package/dist/esm/test/streaming.integration.d.ts +9 -0
  52. package/dist/esm/test/streaming.integration.d.ts.map +1 -0
  53. package/dist/esm/test/streaming.integration.js +190 -0
  54. package/dist/esm/test/streaming.integration.js.map +1 -0
  55. package/package.json +6 -7
  56. package/dist/esm/example.d.ts +0 -6
  57. package/dist/esm/example.d.ts.map +0 -1
  58. package/dist/esm/example.js +0 -115
  59. package/dist/esm/example.js.map +0 -1
  60. package/dist/esm/streaming-test.d.ts +0 -3
  61. package/dist/esm/streaming-test.d.ts.map +0 -1
  62. package/dist/esm/streaming-test.js +0 -102
  63. package/dist/esm/streaming-test.js.map +0 -1
@@ -1,4 +1,12 @@
1
- import { CipherSuite } from '@hpke/core';
1
+ import { CipherSuite, type SenderContext, type Key } from 'hpke';
2
+ /**
3
+ * Request context for response decryption.
4
+ * Holds the HPKE sender context needed to derive response keys.
5
+ */
6
+ export interface RequestContext {
7
+ senderContext: SenderContext;
8
+ requestEnc: Uint8Array;
9
+ }
2
10
  /**
3
11
  * Identity class for managing HPKE key pairs and encryption/decryption
4
12
  */
@@ -6,7 +14,7 @@ export declare class Identity {
6
14
  private suite;
7
15
  private publicKey;
8
16
  private privateKey;
9
- constructor(suite: CipherSuite, publicKey: CryptoKey, privateKey: CryptoKey);
17
+ constructor(suite: CipherSuite, publicKey: Key, privateKey: Key);
10
18
  /**
11
19
  * Generate a new identity with X25519 key pair
12
20
  */
@@ -20,17 +28,17 @@ export declare class Identity {
20
28
  */
21
29
  toJSON(): Promise<string>;
22
30
  /**
23
- * Get public key as CryptoKey
31
+ * Get public key
24
32
  */
25
- getPublicKey(): CryptoKey;
33
+ getPublicKey(): Key;
26
34
  /**
27
35
  * Get public key as hex string
28
36
  */
29
37
  getPublicKeyHex(): Promise<string>;
30
38
  /**
31
- * Get private key as CryptoKey
39
+ * Get private key
32
40
  */
33
- getPrivateKey(): CryptoKey;
41
+ getPrivateKey(): Key;
34
42
  /**
35
43
  * Marshal public key configuration for server key distribution
36
44
  * Implements RFC 9458 format
@@ -41,12 +49,31 @@ export declare class Identity {
41
49
  */
42
50
  static unmarshalPublicConfig(data: Uint8Array): Promise<Identity>;
43
51
  /**
44
- * Encrypt request body and set appropriate headers
52
+ * Encrypt request body and return context for response decryption.
53
+ *
54
+ * This method is called on the SERVER's identity (public key only).
55
+ * It:
56
+ * 1. Creates an HPKE sender context to this identity's public key
57
+ * 2. Encrypts the request body
58
+ * 3. Returns a RequestContext that must be used to decrypt the response
59
+ */
60
+ encryptRequestWithContext(request: Request): Promise<{
61
+ request: Request;
62
+ context: RequestContext | null;
63
+ }>;
64
+ /**
65
+ * Decrypt response using keys derived from request context.
66
+ *
67
+ * This method:
68
+ * 1. Reads the response nonce from Ehbp-Response-Nonce header
69
+ * 2. Exports a secret from the HPKE sender context
70
+ * 3. Derives response keys using HKDF
71
+ * 4. Decrypts the response body
45
72
  */
46
- encryptRequest(request: Request, serverPublicKey: CryptoKey): Promise<Request>;
73
+ decryptResponseWithContext(response: Response, context: RequestContext): Promise<Response>;
47
74
  /**
48
- * Decrypt response body
75
+ * Creates a ReadableStream that decrypts response chunks.
49
76
  */
50
- decryptResponse(response: Response, serverEncapKey: Uint8Array): Promise<Response>;
77
+ private createDecryptStream;
51
78
  }
52
79
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgD,MA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,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAM;gBAEZ,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG;IAM/D;;OAEG;WACU,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAO1C;;OAEG;WACU,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAWtD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAU/B;;OAEG;IACH,YAAY,IAAI,GAAG;IAInB;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAKxC;;OAEG;IACH,aAAa,IAAI,GAAG;IAIpB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IA0C1C;;OAEG;WACU,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqDvE;;;;;;;;OAQG;IACG,yBAAyB,CAC7B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;KAAE,CAAC;IAwDhE;;;;;;;;OAQG;IACG,0BAA0B,CAC9B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,QAAQ,CAAC;IAmCpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAyD5B"}
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Identity = void 0;
4
- const core_1 = require("@hpke/core");
4
+ const hpke_1 = require("hpke");
5
5
  const protocol_js_1 = require("./protocol.js");
6
+ const derive_js_1 = require("./derive.js");
7
+ /**
8
+ * Creates a new CipherSuite for X25519/HKDF-SHA256/AES-256-GCM
9
+ */
10
+ function createSuite() {
11
+ return new hpke_1.CipherSuite(hpke_1.KEM_DHKEM_X25519_HKDF_SHA256, hpke_1.KDF_HKDF_SHA256, hpke_1.AEAD_AES_256_GCM);
12
+ }
6
13
  /**
7
14
  * Identity class for managing HPKE key pairs and encryption/decryption
8
15
  */
@@ -19,48 +26,34 @@ class Identity {
19
26
  * Generate a new identity with X25519 key pair
20
27
  */
21
28
  static async generate() {
22
- const suite = new core_1.CipherSuite({
23
- kem: new core_1.DhkemX25519HkdfSha256(),
24
- kdf: new core_1.HkdfSha256(),
25
- aead: new core_1.Aes256Gcm()
26
- });
27
- const { publicKey, privateKey } = await suite.kem.generateKeyPair();
28
- // Make sure the public key is extractable for serialization
29
- const extractablePublicKey = await crypto.subtle.importKey('raw', await crypto.subtle.exportKey('raw', publicKey), { name: 'X25519' }, true, // extractable
30
- []);
31
- return new Identity(suite, extractablePublicKey, privateKey);
29
+ const suite = createSuite();
30
+ const { publicKey, privateKey } = await suite.GenerateKeyPair(true); // extractable
31
+ return new Identity(suite, publicKey, privateKey);
32
32
  }
33
33
  /**
34
34
  * Create identity from JSON string
35
35
  */
36
36
  static async fromJSON(json) {
37
37
  const data = JSON.parse(json);
38
- const suite = new core_1.CipherSuite({
39
- kem: new core_1.DhkemX25519HkdfSha256(),
40
- kdf: new core_1.HkdfSha256(),
41
- aead: new core_1.Aes256Gcm()
42
- });
43
- // Import public key
44
- const publicKey = await crypto.subtle.importKey('raw', new Uint8Array(data.publicKey), { name: 'X25519' }, true, // extractable
45
- []);
46
- // Deserialize private key using HPKE library
47
- const privateKey = await suite.kem.deserializePrivateKey(new Uint8Array(data.privateKey).buffer);
38
+ const suite = createSuite();
39
+ // Deserialize keys using the suite
40
+ const publicKey = await suite.DeserializePublicKey(new Uint8Array(data.publicKey));
41
+ const privateKey = await suite.DeserializePrivateKey(new Uint8Array(data.privateKey), true);
48
42
  return new Identity(suite, publicKey, privateKey);
49
43
  }
50
44
  /**
51
45
  * Convert identity to JSON string
52
46
  */
53
47
  async toJSON() {
54
- const publicKeyBytes = new Uint8Array(await crypto.subtle.exportKey('raw', this.publicKey));
55
- // For X25519, we need to use the HPKE library's serialization for private keys
56
- const privateKeyBytes = await this.suite.kem.serializePrivateKey(this.privateKey);
48
+ const publicKeyBytes = await this.suite.SerializePublicKey(this.publicKey);
49
+ const privateKeyBytes = await this.suite.SerializePrivateKey(this.privateKey);
57
50
  return JSON.stringify({
58
51
  publicKey: Array.from(publicKeyBytes),
59
- privateKey: Array.from(new Uint8Array(privateKeyBytes))
52
+ privateKey: Array.from(privateKeyBytes),
60
53
  });
61
54
  }
62
55
  /**
63
- * Get public key as CryptoKey
56
+ * Get public key
64
57
  */
65
58
  getPublicKey() {
66
59
  return this.publicKey;
@@ -69,13 +62,11 @@ class Identity {
69
62
  * Get public key as hex string
70
63
  */
71
64
  async getPublicKeyHex() {
72
- const exported = await crypto.subtle.exportKey('raw', this.publicKey);
73
- return Array.from(new Uint8Array(exported))
74
- .map(b => b.toString(16).padStart(2, '0'))
75
- .join('');
65
+ const exported = await this.suite.SerializePublicKey(this.publicKey);
66
+ return (0, derive_js_1.bytesToHex)(exported);
76
67
  }
77
68
  /**
78
- * Get private key as CryptoKey
69
+ * Get private key
79
70
  */
80
71
  getPrivateKey() {
81
72
  return this.privateKey;
@@ -89,7 +80,7 @@ class Identity {
89
80
  const kdfId = protocol_js_1.HPKE_CONFIG.KDF;
90
81
  const aeadId = protocol_js_1.HPKE_CONFIG.AEAD;
91
82
  // Export public key as raw bytes
92
- const publicKeyBytes = new Uint8Array(await crypto.subtle.exportKey('raw', this.publicKey));
83
+ const publicKeyBytes = await this.suite.SerializePublicKey(this.publicKey);
93
84
  // Key ID (1 byte) + KEM ID (2 bytes) + Public Key + Cipher Suites
94
85
  const keyId = 0;
95
86
  const publicKeySize = publicKeyBytes.length;
@@ -99,20 +90,20 @@ class Identity {
99
90
  // Key ID
100
91
  buffer[offset++] = keyId;
101
92
  // KEM ID
102
- buffer[offset++] = (kemId >> 8) & 0xFF;
103
- buffer[offset++] = kemId & 0xFF;
93
+ buffer[offset++] = (kemId >> 8) & 0xff;
94
+ buffer[offset++] = kemId & 0xff;
104
95
  // Public Key
105
96
  buffer.set(publicKeyBytes, offset);
106
97
  offset += publicKeySize;
107
98
  // Cipher Suites Length (2 bytes)
108
- buffer[offset++] = (cipherSuitesSize >> 8) & 0xFF;
109
- buffer[offset++] = cipherSuitesSize & 0xFF;
99
+ buffer[offset++] = (cipherSuitesSize >> 8) & 0xff;
100
+ buffer[offset++] = cipherSuitesSize & 0xff;
110
101
  // KDF ID
111
- buffer[offset++] = (kdfId >> 8) & 0xFF;
112
- buffer[offset++] = kdfId & 0xFF;
102
+ buffer[offset++] = (kdfId >> 8) & 0xff;
103
+ buffer[offset++] = kdfId & 0xff;
113
104
  // AEAD ID
114
- buffer[offset++] = (aeadId >> 8) & 0xFF;
115
- buffer[offset++] = aeadId & 0xFF;
105
+ buffer[offset++] = (aeadId >> 8) & 0xff;
106
+ buffer[offset++] = aeadId & 0xff;
116
107
  return buffer;
117
108
  }
118
109
  /**
@@ -130,144 +121,172 @@ class Identity {
130
121
  offset += publicKeySize;
131
122
  // Read Cipher Suites Length
132
123
  const cipherSuitesLength = (data[offset++] << 8) | data[offset++];
133
- // Read KDF ID
134
- const kdfId = (data[offset++] << 8) | data[offset++];
135
- // Read AEAD ID
136
- const aeadId = (data[offset++] << 8) | data[offset++];
137
- // Create suite (assuming X25519 for now)
138
- const suite = new core_1.CipherSuite({
139
- kem: new core_1.DhkemX25519HkdfSha256(),
140
- kdf: new core_1.HkdfSha256(),
141
- aead: new core_1.Aes256Gcm()
142
- });
143
- // Import public key using HPKE library
144
- const publicKey = await suite.kem.deserializePublicKey(publicKeyBytes.buffer);
124
+ // Parse all cipher suites (each suite is 4 bytes: 2 for KDF, 2 for AEAD)
125
+ const suites = [];
126
+ const cipherSuitesEnd = offset + cipherSuitesLength;
127
+ while (offset < cipherSuitesEnd) {
128
+ const kdfId = (data[offset++] << 8) | data[offset++];
129
+ const aeadId = (data[offset++] << 8) | data[offset++];
130
+ suites.push({ kdfId, aeadId });
131
+ }
132
+ if (suites.length === 0) {
133
+ throw new Error('No cipher suites found in config');
134
+ }
135
+ // Use the first cipher suite
136
+ const firstSuite = suites[0];
137
+ // Validate that we support this cipher suite
138
+ if (firstSuite.kdfId !== protocol_js_1.HPKE_CONFIG.KDF || firstSuite.aeadId !== protocol_js_1.HPKE_CONFIG.AEAD) {
139
+ throw new Error(`Unsupported cipher suite: KDF=0x${firstSuite.kdfId.toString(16)}, AEAD=0x${firstSuite.aeadId.toString(16)}`);
140
+ }
141
+ // Create cipher suite
142
+ const suite = createSuite();
143
+ // Import public key
144
+ const publicKey = await suite.DeserializePublicKey(publicKeyBytes);
145
145
  // For server config, we only have the public key, no private key
146
146
  // We'll create a dummy private key that won't be used
147
- const dummyPrivateKey = await suite.kem.deserializePrivateKey(new Uint8Array(32).buffer);
147
+ const dummyPrivateKey = await suite.DeserializePrivateKey(new Uint8Array(32), false);
148
148
  return new Identity(suite, publicKey, dummyPrivateKey);
149
149
  }
150
150
  /**
151
- * Encrypt request body and set appropriate headers
151
+ * Encrypt request body and return context for response decryption.
152
+ *
153
+ * This method is called on the SERVER's identity (public key only).
154
+ * It:
155
+ * 1. Creates an HPKE sender context to this identity's public key
156
+ * 2. Encrypts the request body
157
+ * 3. Returns a RequestContext that must be used to decrypt the response
152
158
  */
153
- async encryptRequest(request, serverPublicKey) {
159
+ async encryptRequestWithContext(request) {
154
160
  const body = await request.arrayBuffer();
161
+ // Bodyless requests pass through unmodified - no HPKE context needed.
162
+ // See SPEC.md Section 5.1: "When the request has no payload body, an encrypted
163
+ // response is not possible (since there is no HPKE context to derive response
164
+ // keys from). Such requests pass through unmodified."
155
165
  if (body.byteLength === 0) {
156
- // No body to encrypt, just set client public key header
157
- const headers = new Headers(request.headers);
158
- headers.set(protocol_js_1.PROTOCOL.CLIENT_PUBLIC_KEY_HEADER, await this.getPublicKeyHex());
159
- return new Request(request.url, {
160
- method: request.method,
161
- headers,
162
- body: null
163
- });
166
+ return {
167
+ request: new Request(request.url, {
168
+ method: request.method,
169
+ headers: request.headers,
170
+ body: null,
171
+ }),
172
+ context: null,
173
+ };
164
174
  }
165
- // Create sender for encryption
166
- const sender = await this.suite.createSenderContext({
167
- recipientPublicKey: serverPublicKey
175
+ // Create sender context for encryption with info parameter for domain separation
176
+ const infoBytes = new TextEncoder().encode(derive_js_1.HPKE_REQUEST_INFO);
177
+ const { encapsulatedSecret, ctx } = await this.suite.SetupSender(this.publicKey, {
178
+ info: infoBytes,
168
179
  });
180
+ // Store context for response decryption
181
+ const context = {
182
+ senderContext: ctx,
183
+ requestEnc: encapsulatedSecret,
184
+ };
185
+ // Set headers - only encapsulated key for requests with body
186
+ const headers = new Headers(request.headers);
187
+ headers.set(protocol_js_1.PROTOCOL.ENCAPSULATED_KEY_HEADER, (0, derive_js_1.bytesToHex)(context.requestEnc));
169
188
  // Encrypt the body
170
- const encrypted = await sender.seal(body);
171
- // Get encapsulated key
172
- const encapKey = sender.enc;
189
+ const encrypted = await ctx.Seal(new Uint8Array(body));
173
190
  // Create chunked format: 4-byte length header + encrypted data
174
191
  const chunkLength = new Uint8Array(4);
175
- const view = new DataView(chunkLength.buffer);
176
- view.setUint32(0, encrypted.byteLength, false); // Big-endian
192
+ new DataView(chunkLength.buffer).setUint32(0, encrypted.byteLength, false);
177
193
  const chunkedData = new Uint8Array(4 + encrypted.byteLength);
178
194
  chunkedData.set(chunkLength, 0);
179
- chunkedData.set(new Uint8Array(encrypted), 4);
180
- // Create new request with encrypted body and headers
181
- const headers = new Headers(request.headers);
182
- headers.set(protocol_js_1.PROTOCOL.CLIENT_PUBLIC_KEY_HEADER, await this.getPublicKeyHex());
183
- headers.set(protocol_js_1.PROTOCOL.ENCAPSULATED_KEY_HEADER, Array.from(new Uint8Array(encapKey))
184
- .map(b => b.toString(16).padStart(2, '0'))
185
- .join(''));
186
- return new Request(request.url, {
187
- method: request.method,
188
- headers,
189
- body: chunkedData,
190
- duplex: 'half'
191
- });
195
+ chunkedData.set(encrypted, 4);
196
+ return {
197
+ request: new Request(request.url, {
198
+ method: request.method,
199
+ headers,
200
+ body: chunkedData,
201
+ duplex: 'half',
202
+ }),
203
+ context,
204
+ };
192
205
  }
193
206
  /**
194
- * Decrypt response body
207
+ * Decrypt response using keys derived from request context.
208
+ *
209
+ * This method:
210
+ * 1. Reads the response nonce from Ehbp-Response-Nonce header
211
+ * 2. Exports a secret from the HPKE sender context
212
+ * 3. Derives response keys using HKDF
213
+ * 4. Decrypts the response body
195
214
  */
196
- async decryptResponse(response, serverEncapKey) {
215
+ async decryptResponseWithContext(response, context) {
197
216
  if (!response.body) {
198
217
  return response;
199
218
  }
200
- // Create receiver for decryption
201
- const receiver = await this.suite.createRecipientContext({
202
- recipientKey: this.privateKey,
203
- enc: serverEncapKey.buffer
219
+ // Get response nonce from header
220
+ const responseNonceHex = response.headers.get(protocol_js_1.PROTOCOL.RESPONSE_NONCE_HEADER);
221
+ if (!responseNonceHex) {
222
+ throw new Error(`Missing ${protocol_js_1.PROTOCOL.RESPONSE_NONCE_HEADER} header`);
223
+ }
224
+ const responseNonce = (0, derive_js_1.hexToBytes)(responseNonceHex);
225
+ if (responseNonce.length !== derive_js_1.RESPONSE_NONCE_LENGTH) {
226
+ throw new Error(`Invalid response nonce length: expected ${derive_js_1.RESPONSE_NONCE_LENGTH}, got ${responseNonce.length}`);
227
+ }
228
+ // Export secret from request context
229
+ const exportLabelBytes = new TextEncoder().encode(derive_js_1.EXPORT_LABEL);
230
+ const exportedSecret = await context.senderContext.Export(exportLabelBytes, derive_js_1.EXPORT_LENGTH);
231
+ // Derive response keys
232
+ const km = await (0, derive_js_1.deriveResponseKeys)(exportedSecret, context.requestEnc, responseNonce);
233
+ // Create decrypting stream
234
+ const decryptedStream = this.createDecryptStream(response.body, km);
235
+ return new Response(decryptedStream, {
236
+ status: response.status,
237
+ statusText: response.statusText,
238
+ headers: response.headers,
204
239
  });
205
- // Create a readable stream that decrypts chunks as they arrive
206
- const decryptedStream = new ReadableStream({
207
- start(controller) {
208
- const reader = response.body.getReader();
209
- let buffer = new Uint8Array(0);
210
- let offset = 0;
211
- async function pump() {
212
- try {
213
- while (true) {
214
- const { done, value } = await reader.read();
215
- if (done)
216
- break;
217
- // Append new data to buffer
218
- const newBuffer = new Uint8Array(buffer.length + value.length);
219
- newBuffer.set(buffer);
220
- newBuffer.set(value, buffer.length);
221
- buffer = newBuffer;
222
- // Process complete chunks
223
- while (offset + 4 <= buffer.length) {
224
- // Read chunk length (4 bytes big-endian)
225
- const chunkLength = (buffer[offset] << 24) |
226
- (buffer[offset + 1] << 16) |
227
- (buffer[offset + 2] << 8) |
228
- buffer[offset + 3];
229
- offset += 4;
230
- if (chunkLength === 0) {
231
- continue; // Empty chunk
232
- }
233
- // Check if we have the complete chunk
234
- if (offset + chunkLength > buffer.length) {
235
- // Not enough data yet, rewind offset and wait for more
236
- offset -= 4;
237
- break;
238
- }
239
- // Extract and decrypt the chunk
240
- const encryptedChunk = buffer.slice(offset, offset + chunkLength);
241
- offset += chunkLength;
242
- try {
243
- const decryptedChunk = await receiver.open(encryptedChunk.buffer);
244
- controller.enqueue(new Uint8Array(decryptedChunk));
245
- }
246
- catch (error) {
247
- controller.error(new Error(`Failed to decrypt chunk: ${error}`));
248
- return;
249
- }
240
+ }
241
+ /**
242
+ * Creates a ReadableStream that decrypts response chunks.
243
+ */
244
+ createDecryptStream(body, km) {
245
+ let buffer = new Uint8Array(0);
246
+ let seq = 0;
247
+ const reader = body.getReader();
248
+ return new ReadableStream({
249
+ async pull(controller) {
250
+ while (true) {
251
+ // Try to read a complete chunk from buffer
252
+ if (buffer.length >= 4) {
253
+ const chunkLength = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
254
+ if (chunkLength === 0) {
255
+ // Skip empty chunk
256
+ buffer = buffer.slice(4);
257
+ continue;
258
+ }
259
+ if (buffer.length >= 4 + chunkLength) {
260
+ const ciphertext = buffer.slice(4, 4 + chunkLength);
261
+ buffer = buffer.slice(4 + chunkLength);
262
+ try {
263
+ const plaintext = await (0, derive_js_1.decryptChunk)(km, seq++, ciphertext);
264
+ controller.enqueue(plaintext);
265
+ return;
250
266
  }
251
- // Remove processed data from buffer
252
- if (offset > 0) {
253
- buffer = buffer.slice(offset);
254
- offset = 0;
267
+ catch (error) {
268
+ controller.error(new Error(`Decryption failed at chunk ${seq - 1}: ${error}`));
269
+ return;
255
270
  }
256
271
  }
257
- controller.close();
258
272
  }
259
- catch (error) {
260
- controller.error(error);
273
+ // Need more data
274
+ const { done, value } = await reader.read();
275
+ if (done) {
276
+ controller.close();
277
+ return;
261
278
  }
279
+ // Append to buffer
280
+ const newBuffer = new Uint8Array(buffer.length + value.length);
281
+ newBuffer.set(buffer);
282
+ newBuffer.set(value, buffer.length);
283
+ buffer = newBuffer;
262
284
  }
263
- pump();
264
- }
265
- });
266
- // Create new response with decrypted stream
267
- return new Response(decryptedStream, {
268
- status: response.status,
269
- statusText: response.statusText,
270
- headers: response.headers
285
+ },
286
+ cancel(reason) {
287
+ // Release the underlying reader when the stream is cancelled
288
+ return reader.cancel(reason);
289
+ },
271
290
  });
272
291
  }
273
292
  }
@@ -1 +1 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":";;;AAAA,qCAAuF;AACvF,+CAAsD;AAEtD;;GAEG;AACH,MAAa,QAAQ;IACX,KAAK,CAAc;IACnB,SAAS,CAAY;IACrB,UAAU,CAAY;IAE9B,YAAY,KAAkB,EAAE,SAAoB,EAAE,UAAqB;QACzE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ;QACnB,MAAM,KAAK,GAAG,IAAI,kBAAW,CAAC;YAC5B,GAAG,EAAE,IAAI,4BAAqB,EAAE;YAChC,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C,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;gCAC/E,OAAO;4BACT,CAAC;wBACH,CAAC;oBACH,CAAC;oBAED,iBAAiB;oBACjB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC5C,IAAI,IAAI,EAAE,CAAC;wBACT,UAAU,CAAC,KAAK,EAAE,CAAC;wBACnB,OAAO;oBACT,CAAC;oBAED,mBAAmB;oBACnB,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;oBAC/D,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACtB,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;oBACpC,MAAM,GAAG,SAAS,CAAC;gBACrB,CAAC;YACH,CAAC;YACD,MAAM,CAAC,MAAM;gBACX,6DAA6D;gBAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AA1VD,4BA0VC"}
@@ -6,7 +6,10 @@
6
6
  * bodies while preserving HTTP headers for routing.
7
7
  */
8
8
  export { Identity } from './identity.js';
9
+ export type { RequestContext } from './identity.js';
9
10
  export { Transport, createTransport } from './client.js';
10
11
  export { PROTOCOL, HPKE_CONFIG } from './protocol.js';
11
- export type { CipherSuite } from '@hpke/core';
12
+ export { deriveResponseKeys, computeNonce, encryptChunk, decryptChunk, hexToBytes, bytesToHex, HPKE_REQUEST_INFO, EXPORT_LABEL, EXPORT_LENGTH, RESPONSE_NONCE_LENGTH, AES256_KEY_LENGTH, AES_GCM_NONCE_LENGTH, } from './derive.js';
13
+ export type { ResponseKeyMaterial } from './derive.js';
14
+ export type { CipherSuite, SenderContext, RecipientContext, Key } from 'hpke';
12
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGtD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * bodies while preserving HTTP headers for routing.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.HPKE_CONFIG = exports.PROTOCOL = exports.createTransport = exports.Transport = exports.Identity = void 0;
10
+ exports.AES_GCM_NONCE_LENGTH = exports.AES256_KEY_LENGTH = exports.RESPONSE_NONCE_LENGTH = exports.EXPORT_LENGTH = exports.EXPORT_LABEL = exports.HPKE_REQUEST_INFO = exports.bytesToHex = exports.hexToBytes = exports.decryptChunk = exports.encryptChunk = exports.computeNonce = exports.deriveResponseKeys = exports.HPKE_CONFIG = exports.PROTOCOL = exports.createTransport = exports.Transport = exports.Identity = void 0;
11
11
  var identity_js_1 = require("./identity.js");
12
12
  Object.defineProperty(exports, "Identity", { enumerable: true, get: function () { return identity_js_1.Identity; } });
13
13
  var client_js_1 = require("./client.js");
@@ -16,4 +16,18 @@ Object.defineProperty(exports, "createTransport", { enumerable: true, get: funct
16
16
  var protocol_js_1 = require("./protocol.js");
17
17
  Object.defineProperty(exports, "PROTOCOL", { enumerable: true, get: function () { return protocol_js_1.PROTOCOL; } });
18
18
  Object.defineProperty(exports, "HPKE_CONFIG", { enumerable: true, get: function () { return protocol_js_1.HPKE_CONFIG; } });
19
+ // Export key derivation utilities for advanced usage
20
+ var derive_js_1 = require("./derive.js");
21
+ Object.defineProperty(exports, "deriveResponseKeys", { enumerable: true, get: function () { return derive_js_1.deriveResponseKeys; } });
22
+ Object.defineProperty(exports, "computeNonce", { enumerable: true, get: function () { return derive_js_1.computeNonce; } });
23
+ Object.defineProperty(exports, "encryptChunk", { enumerable: true, get: function () { return derive_js_1.encryptChunk; } });
24
+ Object.defineProperty(exports, "decryptChunk", { enumerable: true, get: function () { return derive_js_1.decryptChunk; } });
25
+ Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return derive_js_1.hexToBytes; } });
26
+ Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return derive_js_1.bytesToHex; } });
27
+ Object.defineProperty(exports, "HPKE_REQUEST_INFO", { enumerable: true, get: function () { return derive_js_1.HPKE_REQUEST_INFO; } });
28
+ Object.defineProperty(exports, "EXPORT_LABEL", { enumerable: true, get: function () { return derive_js_1.EXPORT_LABEL; } });
29
+ Object.defineProperty(exports, "EXPORT_LENGTH", { enumerable: true, get: function () { return derive_js_1.EXPORT_LENGTH; } });
30
+ Object.defineProperty(exports, "RESPONSE_NONCE_LENGTH", { enumerable: true, get: function () { return derive_js_1.RESPONSE_NONCE_LENGTH; } });
31
+ Object.defineProperty(exports, "AES256_KEY_LENGTH", { enumerable: true, get: function () { return derive_js_1.AES256_KEY_LENGTH; } });
32
+ Object.defineProperty(exports, "AES_GCM_NONCE_LENGTH", { enumerable: true, get: function () { return derive_js_1.AES_GCM_NONCE_LENGTH; } });
19
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,yCAAyD;AAAhD,sGAAA,SAAS,OAAA;AAAE,4GAAA,eAAe,OAAA;AACnC,6CAAsD;AAA7C,uGAAA,QAAQ,OAAA;AAAE,0GAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AAEjB,yCAAyD;AAAhD,sGAAA,SAAS,OAAA;AAAE,4GAAA,eAAe,OAAA;AACnC,6CAAsD;AAA7C,uGAAA,QAAQ,OAAA;AAAE,0GAAA,WAAW,OAAA;AAE9B,qDAAqD;AACrD,yCAaqB;AAZnB,+GAAA,kBAAkB,OAAA;AAClB,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,uGAAA,UAAU,OAAA;AACV,uGAAA,UAAU,OAAA;AACV,8GAAA,iBAAiB,OAAA;AACjB,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AACb,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,iHAAA,oBAAoB,OAAA"}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export declare const PROTOCOL: {
5
5
  readonly ENCAPSULATED_KEY_HEADER: "Ehbp-Encapsulated-Key";
6
- readonly CLIENT_PUBLIC_KEY_HEADER: "Ehbp-Client-Public-Key";
6
+ readonly RESPONSE_NONCE_HEADER: "Ehbp-Response-Nonce";
7
7
  readonly KEYS_MEDIA_TYPE: "application/ohttp-keys";
8
8
  readonly KEYS_PATH: "/.well-known/hpke-keys";
9
9
  readonly FALLBACK_HEADER: "Ehbp-Fallback";