hpke 1.0.0 → 1.0.1

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 CHANGED
@@ -70,7 +70,7 @@ Please note that some suites may not be available depending on the runtime used.
70
70
  Algorithm implementations exposed by this module are built on top of [Web Cryptography][] (and its
71
71
  extensions, e.g. [Secure Curves][], [Modern Algorithms][]). Runtimes implementing Web Cryptography
72
72
  are not required to support all of its algorithms and so not all algorithms are available in all
73
- runtimes, see
73
+ runtimes.
74
74
 
75
75
  This module is designed to be extensible, you can bring outside-built implementations of any KEM,
76
76
  KDF, or AEAD algorithm into any JavaScript runtime by conforming to the respective interfaces
package/index.d.ts CHANGED
@@ -58,8 +58,12 @@
58
58
  */
59
59
  declare class SenderContext {
60
60
  #private;
61
- constructor(suite: Triple, mode: number, key: Uint8Array, base_nonce: Uint8Array, exporter_secret: Uint8Array);
62
- /** @returns The mode (0x00 = Base, 0x01 = PSK) for this context. */
61
+ constructor(suite: Triple, mode: typeof MODE_BASE | typeof MODE_PSK, key: Uint8Array, base_nonce: Uint8Array, exporter_secret: Uint8Array);
62
+ /**
63
+ * @returns The mode (0x00 = Base, 0x01 = PSK) for this context.
64
+ * @see {@link MODE_BASE}
65
+ * @see {@link MODE_PSK}
66
+ */
63
67
  get mode(): number;
64
68
  /**
65
69
  * @returns The sequence number for this context's next {@link Seal}, initially zero, increments
@@ -144,8 +148,12 @@ export type { SenderContext };
144
148
  */
145
149
  declare class RecipientContext {
146
150
  #private;
147
- constructor(suite: Triple, mode: number, key: Uint8Array, base_nonce: Uint8Array, exporter_secret: Uint8Array);
148
- /** @returns The mode (0x00 = Base, 0x01 = PSK) for this context. */
151
+ constructor(suite: Triple, mode: typeof MODE_BASE | typeof MODE_PSK, key: Uint8Array, base_nonce: Uint8Array, exporter_secret: Uint8Array);
152
+ /**
153
+ * @returns The mode (0x00 = Base, 0x01 = PSK) for this context.
154
+ * @see {@link MODE_BASE}
155
+ * @see {@link MODE_PSK}
156
+ */
149
157
  get mode(): number;
150
158
  /**
151
159
  * @returns The sequence number for this context's next {@link Open}, initially zero, increments
@@ -371,11 +379,16 @@ export declare class CipherSuite {
371
379
  */
372
380
  GenerateKeyPair(extractable?: boolean): Promise<KeyPair>;
373
381
  /**
374
- * Deterministically derives a key pair for this CipherSuite from input keying material. By
382
+ * Deterministically derives a key pair for this CipherSuite's KEM from input keying material. By
375
383
  * default, private keys are derived as non-extractable (their value cannot be exported).
376
384
  *
377
- * An `ikm` input MUST NOT be reused elsewhere, particularly not with `DeriveKeyPair()` of a
378
- * different KEM.
385
+ * > [!CAUTION]\
386
+ * > Input keying material must not be reused elsewhere, particularly not with `DeriveKeyPair()` of
387
+ * > a different KEM. Re-use across different KEMs could leak information about the private key.
388
+ *
389
+ * > [!CAUTION]\
390
+ * > Input keying material should be generated from a cryptographically secure random source or
391
+ * > derived from high-entropy secret material.
379
392
  *
380
393
  * @category Key Management
381
394
 
@@ -440,7 +453,7 @@ export declare class CipherSuite {
440
453
 
441
454
 
442
455
 
443
- * @param privateKey - Serialized private key
456
+ * @param privateKey - Serialized private key (must be exactly {@link CipherSuite.KEM Nsk} bytes)
444
457
  * @param extractable - Whether the deserialized private key should be extractable (e.g. by
445
458
  * {@link SerializePrivateKey}) (default: false)
446
459
  *
@@ -460,7 +473,7 @@ export declare class CipherSuite {
460
473
 
461
474
 
462
475
 
463
- * @param publicKey - Serialized public key
476
+ * @param publicKey - Serialized public key (must be exactly {@link CipherSuite.KEM Npk} bytes)
464
477
  *
465
478
  * @returns A Promise that resolves to the deserialized public key.
466
479
  */
@@ -828,9 +841,20 @@ interface Triple {
828
841
  readonly KDF: Readonly<KDF>;
829
842
  readonly AEAD: Readonly<AEAD>;
830
843
  }
831
- /** Mode identifier for Base mode */
844
+ /**
845
+ * Mode identifier for Base mode (0x00).
846
+ *
847
+ * Base mode provides encryption to a public key without sender authentication. The recipient cannot
848
+ * verify who encrypted the message, only that someone with access to their public key did.
849
+ */
832
850
  export declare const MODE_BASE = 0;
833
- /** Mode identifier for PSK mode */
851
+ /**
852
+ * Mode identifier for PSK mode (0x01).
853
+ *
854
+ * PSK (Pre-Shared Key) mode provides encryption with authentication using a pre-shared secret. Both
855
+ * sender and recipient must possess the same PSK and PSK ID. This provides implicit sender
856
+ * authentication.
857
+ */
834
858
  export declare const MODE_PSK = 1;
835
859
  /**
836
860
  * Factory function that returns a KEM implementation.
@@ -929,6 +953,9 @@ export interface KeyPair {
929
953
  * This interface is designed to be compatible with Web Cryptography's CryptoKey objects while
930
954
  * allowing for custom key implementations that may not have all CryptoKey properties. It includes
931
955
  * only the essential properties needed for HPKE operations and validations.
956
+ *
957
+ * Keys are created through {@link CipherSuite.GenerateKeyPair}, {@link CipherSuite.DeriveKeyPair},
958
+ * {@link CipherSuite.DeserializePrivateKey}, or {@link CipherSuite.DeserializePublicKey}.
932
959
  */
933
960
  export interface Key {
934
961
  /** The key algorithm properties */
@@ -955,7 +982,7 @@ export declare function concat(...buffers: Uint8Array[]): Uint8Array;
955
982
  * Encodes an ASCII string into a Uint8Array.
956
983
  *
957
984
  * This utility function converts ASCII strings to byte arrays. It's exported for use in custom KEM,
958
- * KDF, or AEAD implementations.
985
+ * KDF, or AEAD implementations to encode identifiers or HPKE suite_id values.
959
986
  *
960
987
  * @param string - ASCII string to encode
961
988
  *
@@ -1265,7 +1292,7 @@ export interface KEM {
1265
1292
  /**
1266
1293
  * Deserializes a public key from bytes.
1267
1294
  *
1268
- * @param key - The serialized public key already validated to be at least {@link Npk} bytes
1295
+ * @param key - The serialized public key already validated to be exactly {@link Npk} bytes
1269
1296
  *
1270
1297
  * @returns A promise resolving to a {@link !Key} or a Key interface-conforming object
1271
1298
  */
@@ -1281,7 +1308,7 @@ export interface KEM {
1281
1308
  /**
1282
1309
  * Deserializes a private key from bytes.
1283
1310
  *
1284
- * @param key - The serialized private key already validated to be at least {@link Nsk} bytes
1311
+ * @param key - The serialized private key already validated to be exactly {@link Nsk} bytes
1285
1312
  * @param extractable - Whether the private key should be extractable
1286
1313
  *
1287
1314
  * @returns A promise resolving to a {@link !Key} or a Key interface-conforming object
@@ -1413,7 +1440,7 @@ export interface AEAD {
1413
1440
  * into a byte string of specified length. It's exported for use in custom KEM, KDF, or AEAD
1414
1441
  * implementations.
1415
1442
  *
1416
- * @param n - Non-negative integer to convert
1443
+ * @param n - Non-negative safe integer to convert
1417
1444
  * @param w - Desired length of output in bytes
1418
1445
  *
1419
1446
  * @returns A Uint8Array of length w containing the big-endian representation of n
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAmDH;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAM,aAAa;;gBAUf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,UAAU,EACf,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,UAAU;IAS7B,oEAAoE;IACpE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBxE;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,MAAM,CAAC,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9E;;;OAGG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;CACF;AACD,YAAY,EAAE,aAAa,EAAE,CAAA;AAE7B;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAM,gBAAgB;;gBAUlB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,UAAU,EACf,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BAA0B,EAAE,UAoBxC,CAAA;AAeD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B,EAAE,UAoBxC,CAAA;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,4BAA4B,EAAE,UAyB1C,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B,EAAE,UAyBxC,CAAA;AAqGD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,EAAE,UAmB5B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,EAAE,UAmB5B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,EAAE,UAmB7B,CAAA;AAoDD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAY9B,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAY9B,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAanC,CAAA;AAiXD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,mBAAmB,EAAE,UAoCjC,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,EAAE,UAmC/B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,EAAE,UAoChC,CAAA"}
package/index.js CHANGED
@@ -111,13 +111,13 @@ class SenderContext {
111
111
  #key
112
112
  #base_nonce
113
113
  #exporter_secret
114
- #mode
114
+ #mode
115
115
  #seq = 0
116
116
  #mutex
117
117
 
118
118
  constructor(
119
119
  suite ,
120
- mode ,
120
+ mode ,
121
121
  key ,
122
122
  base_nonce ,
123
123
  exporter_secret ,
@@ -130,6 +130,10 @@ class SenderContext {
130
130
  }
131
131
 
132
132
 
133
+
134
+
135
+
136
+
133
137
  get mode() {
134
138
  return this.#mode
135
139
  }
@@ -253,13 +257,13 @@ class RecipientContext {
253
257
  #key
254
258
  #base_nonce
255
259
  #exporter_secret
256
- #mode
260
+ #mode
257
261
  #seq = 0
258
262
  #mutex
259
263
 
260
264
  constructor(
261
265
  suite ,
262
- mode ,
266
+ mode ,
263
267
  key ,
264
268
  base_nonce ,
265
269
  exporter_secret ,
@@ -272,6 +276,10 @@ class RecipientContext {
272
276
  }
273
277
 
274
278
 
279
+
280
+
281
+
282
+
275
283
  get mode() {
276
284
  return this.#mode
277
285
  }
@@ -615,6 +623,11 @@ export class CipherSuite {
615
623
 
616
624
 
617
625
 
626
+
627
+
628
+
629
+
630
+
618
631
 
619
632
 
620
633
 
@@ -1240,9 +1253,20 @@ export class NotSupportedError extends Error {
1240
1253
 
1241
1254
 
1242
1255
 
1256
+
1257
+
1258
+
1259
+
1260
+
1243
1261
  export const MODE_BASE = 0x00
1244
1262
 
1245
1263
 
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
1246
1270
  export const MODE_PSK = 0x01
1247
1271
 
1248
1272
 
@@ -1370,6 +1394,9 @@ export const MODE_PSK = 0x01
1370
1394
 
1371
1395
 
1372
1396
 
1397
+
1398
+
1399
+
1373
1400
 
1374
1401
 
1375
1402
 
@@ -1404,6 +1431,9 @@ export function encode(string ) {
1404
1431
  const bytes = new Uint8Array(string.length)
1405
1432
  for (let i = 0; i < string.length; i++) {
1406
1433
  const code = string.charCodeAt(i)
1434
+ if (code > 0x7f) {
1435
+ throw new TypeError('Input string must contain only ASCII characters')
1436
+ }
1407
1437
  bytes[i] = code
1408
1438
  }
1409
1439
  return bytes
@@ -2224,9 +2254,9 @@ export const AEAD_EXPORT_ONLY = function () {
2224
2254
 
2225
2255
 
2226
2256
 
2227
- async function subtle (promise , name ) {
2257
+ async function subtle (promise , name ) {
2228
2258
  try {
2229
- return await promise()
2259
+ return await promise(crypto.subtle)
2230
2260
  } catch (cause) {
2231
2261
  if (
2232
2262
  cause instanceof TypeError ||
@@ -2272,12 +2302,10 @@ function HKDF_SHARED() {
2272
2302
  const ikm = ab(_ikm)
2273
2303
  return new Uint8Array(
2274
2304
  await subtle(
2275
- async () =>
2276
- crypto.subtle.sign(
2305
+ async (c) =>
2306
+ c.sign(
2277
2307
  'HMAC',
2278
- await crypto.subtle.importKey('raw', salt, { name: 'HMAC', hash: this.hash }, false, [
2279
- 'sign',
2280
- ]),
2308
+ await c.importKey('raw', salt, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2281
2309
  ikm,
2282
2310
  ),
2283
2311
  this.name,
@@ -2294,8 +2322,7 @@ function HKDF_SHARED() {
2294
2322
  const N = Math.ceil(L / this.Nh)
2295
2323
  const prk = ab(_prk)
2296
2324
  const key = await subtle(
2297
- () =>
2298
- crypto.subtle.importKey('raw', prk, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2325
+ (c) => c.importKey('raw', prk, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2299
2326
  this.name,
2300
2327
  )
2301
2328
 
@@ -2308,9 +2335,7 @@ function HKDF_SHARED() {
2308
2335
  input.set(info, T_prev.byteLength)
2309
2336
  input[T_prev.byteLength + info.byteLength] = i + 1
2310
2337
 
2311
- const T_i = new Uint8Array(
2312
- await subtle(() => crypto.subtle.sign('HMAC', key, input), this.name),
2313
- )
2338
+ const T_i = new Uint8Array(await subtle((c) => c.sign('HMAC', key, input), this.name))
2314
2339
 
2315
2340
  T.set(T_i, i * this.Nh)
2316
2341
  T_prev = T_i
@@ -2400,20 +2425,8 @@ export const KDF_HKDF_SHA512 = function () {
2400
2425
 
2401
2426
 
2402
2427
  async function ShakeDerive(name , variant , ikm , L ) {
2403
- return new Uint8Array(
2404
- await subtle(
2405
- () =>
2406
- crypto.subtle.digest(
2407
- {
2408
- name: variant,
2409
-
2410
- length: L << 3,
2411
- },
2412
- ikm,
2413
- ),
2414
- name,
2415
- ),
2416
- )
2428
+ const alg = { name: variant, length: L << 3 }
2429
+ return new Uint8Array(await subtle((c) => c.digest(alg, ikm), name))
2417
2430
  }
2418
2431
 
2419
2432
  function SHAKE_SHARED() {
@@ -2496,9 +2509,9 @@ async function getPublicKeyByExport(
2496
2509
  )
2497
2510
  }
2498
2511
 
2499
- return await subtle(async () => {
2500
- const jwk = await crypto.subtle.exportKey('jwk', key)
2501
- return await crypto.subtle.importKey(
2512
+ return await subtle(async (c) => {
2513
+ const jwk = await c.exportKey('jwk', key)
2514
+ return c.importKey(
2502
2515
  'jwk',
2503
2516
  { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y } ,
2504
2517
  key.algorithm,
@@ -2511,7 +2524,7 @@ async function getPublicKeyByExport(
2511
2524
  async function getPublicKey(name , key , usages ) {
2512
2525
  return (
2513
2526
 
2514
- ((await subtle(() => crypto.subtle.getPublicKey?.(key, usages), name)) ) ||
2527
+ ((await subtle((c) => c.getPublicKey?.(key, usages), name)) ) ||
2515
2528
  (await getPublicKeyByExport(name, key, usages))
2516
2529
  )
2517
2530
  }
@@ -2651,26 +2664,23 @@ function DHKEM_SHARED()
2651
2664
  return {
2652
2665
  async GenerateKeyPair( extractable) {
2653
2666
  return (await subtle(
2654
- () => crypto.subtle.generateKey(this.algorithm, extractable, ['deriveBits']),
2667
+ (c) => c.generateKey(this.algorithm, extractable, ['deriveBits']),
2655
2668
  this.name,
2656
2669
  ))
2657
2670
  },
2658
2671
  async SerializePublicKey( key) {
2659
2672
  assertKeyAlgorithm(key, this.algorithm)
2660
2673
  assertCryptoKey(key)
2661
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey('raw', key), this.name))
2674
+ return new Uint8Array(await subtle((c) => c.exportKey('raw', key), this.name))
2662
2675
  },
2663
2676
  async DeserializePublicKey( _key) {
2664
2677
  const key = ab(_key)
2665
- return await subtle(
2666
- () => crypto.subtle.importKey('raw', key, this.algorithm, true, []),
2667
- this.name,
2668
- )
2678
+ return await subtle((c) => c.importKey('raw', key, this.algorithm, true, []), this.name)
2669
2679
  },
2670
2680
  async SerializePrivateKey( key) {
2671
2681
  assertKeyAlgorithm(key, this.algorithm)
2672
2682
  assertCryptoKey(key)
2673
- const { d } = await subtle(() => crypto.subtle.exportKey('jwk', key), this.name)
2683
+ const { d } = await subtle((c) => c.exportKey('jwk', key), this.name)
2674
2684
  return b64u(d )
2675
2685
  },
2676
2686
  async Encap( pkR) {
@@ -2685,8 +2695,7 @@ function DHKEM_SHARED()
2685
2695
 
2686
2696
  const dh = new Uint8Array(
2687
2697
  await subtle(
2688
- () =>
2689
- crypto.subtle.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2698
+ (c) => c.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2690
2699
  this.name,
2691
2700
  ),
2692
2701
  )
@@ -2728,8 +2737,7 @@ function DHKEM_SHARED()
2728
2737
 
2729
2738
  const dh = new Uint8Array(
2730
2739
  await subtle(
2731
- () =>
2732
- crypto.subtle.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2740
+ (c) => c.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2733
2741
  this.name,
2734
2742
  ),
2735
2743
  )
@@ -2793,7 +2801,7 @@ async function CurveKeyFromD(
2793
2801
  pkcs8.set(tmpl)
2794
2802
  pkcs8.set(key, tmpl.byteLength)
2795
2803
  return await subtle(
2796
- () => crypto.subtle.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2804
+ (c) => c.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2797
2805
  name,
2798
2806
  )
2799
2807
  }
@@ -2934,7 +2942,7 @@ async function DeserializePrivateKeyNist(
2934
2942
  const jwk = getPrivateJwkNist(this, d)
2935
2943
 
2936
2944
  const privateKey = await subtle(
2937
- () => crypto.subtle.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2945
+ (c) => c.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2938
2946
  this.name,
2939
2947
  )
2940
2948
 
@@ -2971,13 +2979,13 @@ async function GetKeyPairNist(
2971
2979
  const jwk = getPrivateJwkNist(curveConfig, OS2IP(sk))
2972
2980
 
2973
2981
  const privateKey = await subtle(
2974
- () => crypto.subtle.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2982
+ (c) => c.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2975
2983
  name,
2976
2984
  )
2977
2985
 
2978
2986
  delete jwk.d
2979
2987
  const publicKey = await subtle(
2980
- () => crypto.subtle.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2988
+ (c) => c.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2981
2989
  name,
2982
2990
  )
2983
2991
 
@@ -3300,7 +3308,7 @@ function MLKEM_SHARED() {
3300
3308
 
3301
3309
  const usages = ['encapsulateBits', 'decapsulateBits']
3302
3310
  return (await subtle(
3303
- () => crypto.subtle.generateKey(this.algorithm, extractable, usages),
3311
+ (c) => c.generateKey(this.algorithm, extractable, usages),
3304
3312
  this.name,
3305
3313
  ))
3306
3314
  },
@@ -3309,7 +3317,7 @@ function MLKEM_SHARED() {
3309
3317
  assertCryptoKey(key)
3310
3318
 
3311
3319
  const format = 'raw-public'
3312
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey(format, key), this.name))
3320
+ return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3313
3321
  },
3314
3322
  async DeserializePublicKey( _key) {
3315
3323
 
@@ -3317,17 +3325,14 @@ function MLKEM_SHARED() {
3317
3325
 
3318
3326
  const usages = ['encapsulateBits']
3319
3327
  const key = ab(_key)
3320
- return await subtle(
3321
- () => crypto.subtle.importKey(format, key, this.algorithm, true, usages),
3322
- this.name,
3323
- )
3328
+ return await subtle((c) => c.importKey(format, key, this.algorithm, true, usages), this.name)
3324
3329
  },
3325
3330
  async SerializePrivateKey( key) {
3326
3331
  assertKeyAlgorithm(key, this.algorithm)
3327
3332
  assertCryptoKey(key)
3328
3333
 
3329
3334
  const format = 'raw-seed'
3330
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey(format, key), this.name))
3335
+ return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3331
3336
  },
3332
3337
  async DeserializePrivateKey( _key, extractable) {
3333
3338
 
@@ -3336,7 +3341,7 @@ function MLKEM_SHARED() {
3336
3341
  const usages = ['decapsulateBits']
3337
3342
  const key = ab(_key)
3338
3343
  return await subtle(
3339
- () => crypto.subtle.importKey(format, key, this.algorithm, extractable, usages),
3344
+ (c) => c.importKey(format, key, this.algorithm, extractable, usages),
3340
3345
  this.name,
3341
3346
  )
3342
3347
  },
@@ -3344,9 +3349,8 @@ function MLKEM_SHARED() {
3344
3349
  assertKeyAlgorithm(pkR, this.algorithm)
3345
3350
 
3346
3351
  const { sharedKey, ciphertext } = (await subtle(
3347
- () =>
3348
3352
 
3349
- crypto.subtle.encapsulateBits(this.algorithm, pkR),
3353
+ (c) => c.encapsulateBits(this.algorithm, pkR),
3350
3354
  this.name,
3351
3355
  ))
3352
3356
 
@@ -3357,9 +3361,8 @@ function MLKEM_SHARED() {
3357
3361
  const enc = ab(_enc)
3358
3362
  return new Uint8Array(
3359
3363
  await subtle(
3360
- () =>
3361
3364
 
3362
- crypto.subtle.decapsulateBits(this.algorithm, skR, enc),
3365
+ (c) => c.decapsulateBits(this.algorithm, skR, enc),
3363
3366
  this.name,
3364
3367
  ),
3365
3368
  )
@@ -3504,12 +3507,10 @@ function AEAD_SHARED() {
3504
3507
  const pt = ab(_pt)
3505
3508
  return new Uint8Array(
3506
3509
  await subtle(
3507
- async () =>
3508
- crypto.subtle.encrypt(
3510
+ async (c) =>
3511
+ c.encrypt(
3509
3512
  { name: this.algorithm, iv: nonce, additionalData: aad },
3510
- await crypto.subtle.importKey(this.keyFormat, key, this.algorithm, false, [
3511
- 'encrypt',
3512
- ]),
3513
+ await c.importKey(this.keyFormat, key, this.algorithm, false, ['encrypt']),
3513
3514
  pt,
3514
3515
  ),
3515
3516
  this.name,
@@ -3523,12 +3524,10 @@ function AEAD_SHARED() {
3523
3524
  const ct = ab(_ct)
3524
3525
  return new Uint8Array(
3525
3526
  await subtle(
3526
- async () =>
3527
- crypto.subtle.decrypt(
3527
+ async (c) =>
3528
+ c.decrypt(
3528
3529
  { name: this.algorithm, iv: nonce, additionalData: aad },
3529
- await crypto.subtle.importKey(this.keyFormat, key, this.algorithm, false, [
3530
- 'decrypt',
3531
- ]),
3530
+ await c.importKey(this.keyFormat, key, this.algorithm, false, ['decrypt']),
3532
3531
  ct,
3533
3532
  ),
3534
3533
  this.name,
@@ -3759,7 +3758,7 @@ async function expandDecapsKeyG(PQTKEM , _seed ) {
3759
3758
 
3760
3759
  const algorithm = { name: 'cSHAKE256', length: Nout << 3 }
3761
3760
  const seed = ab(_seed)
3762
- const seed_full = await subtle(() => crypto.subtle.digest(algorithm, seed), PQTKEM.name)
3761
+ const seed_full = await subtle((c) => c.digest(algorithm, seed), PQTKEM.name)
3763
3762
 
3764
3763
  const [_seed_PQ, seed_T] = split(PQTKEM.pq.Nseed, PQTKEM.t.Nseed, new Uint8Array(seed_full))
3765
3764
  const seed_PQ = ab(_seed_PQ)
@@ -3769,7 +3768,7 @@ async function expandDecapsKeyG(PQTKEM , _seed ) {
3769
3768
 
3770
3769
  const usages = ['decapsulateBits', 'encapsulateBits']
3771
3770
  const dk_PQ = await subtle(
3772
- () => crypto.subtle.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3771
+ (c) => c.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3773
3772
  PQTKEM.name,
3774
3773
  )
3775
3774
  const ek_PQ = await getPublicKey(PQTKEM.name, dk_PQ, [usages[1]])
@@ -3788,11 +3787,9 @@ async function C2PRICombiner(
3788
3787
  _ek_T ,
3789
3788
  label ,
3790
3789
  ) {
3791
- const ek_T = new Uint8Array(
3792
- await subtle(() => crypto.subtle.exportKey('raw', _ek_T), PQTKEM.name),
3793
- )
3790
+ const ek_T = new Uint8Array(await subtle((c) => c.exportKey('raw', _ek_T), PQTKEM.name))
3794
3791
  const data = ab(concat(ss_PQ, ss_T, ct_T, ek_T, label))
3795
- return new Uint8Array(await subtle(() => crypto.subtle.digest('SHA3-256', data), PQTKEM.name))
3792
+ return new Uint8Array(await subtle((c) => c.digest('SHA3-256', data), PQTKEM.name))
3796
3793
  }
3797
3794
 
3798
3795
  async function prepareEncapsG(
@@ -3801,30 +3798,22 @@ async function prepareEncapsG(
3801
3798
  ek_T ,
3802
3799
  ) {
3803
3800
  const res = (await subtle(
3804
- () =>
3805
3801
 
3806
- crypto.subtle.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3802
+ (c) => c.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3807
3803
  PQTKEM.name,
3808
3804
  ))
3809
3805
  const ss_PQ = new Uint8Array(res.sharedKey)
3810
3806
  const ct_PQ = new Uint8Array(res.ciphertext)
3811
3807
 
3812
3808
  const { privateKey: sk_E, publicKey } = (await subtle(
3813
- () => crypto.subtle.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3809
+ (c) => c.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3814
3810
  PQTKEM.name,
3815
3811
  ))
3816
- const ct_T = new Uint8Array(
3817
- await subtle(() => crypto.subtle.exportKey('raw', publicKey), PQTKEM.name),
3818
- )
3812
+ const ct_T = new Uint8Array(await subtle((c) => c.exportKey('raw', publicKey), PQTKEM.name))
3819
3813
 
3820
3814
  const ss_T = new Uint8Array(
3821
3815
  await subtle(
3822
- () =>
3823
- crypto.subtle.deriveBits(
3824
- { name: PQTKEM.t.algorithm.name, public: ek_T },
3825
- sk_E,
3826
- PQTKEM.t.Nss << 3,
3827
- ),
3816
+ (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: ek_T }, sk_E, PQTKEM.t.Nss << 3),
3828
3817
  PQTKEM.name,
3829
3818
  ),
3830
3819
  )
@@ -3842,27 +3831,21 @@ async function prepareDecapsG(
3842
3831
  ) {
3843
3832
  const ss_PQ = new Uint8Array(
3844
3833
  await subtle(
3845
- () =>
3846
3834
 
3847
- crypto.subtle.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3835
+ (c) => c.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3848
3836
  PQTKEM.name,
3849
3837
  ),
3850
3838
  )
3851
3839
 
3852
3840
  const ct_T = ab(_ct_T)
3853
3841
  const pub = await subtle(
3854
- () => crypto.subtle.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3842
+ (c) => c.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3855
3843
  PQTKEM.name,
3856
3844
  )
3857
3845
 
3858
3846
  const ss_T = new Uint8Array(
3859
3847
  await subtle(
3860
- () =>
3861
- crypto.subtle.deriveBits(
3862
- { name: PQTKEM.t.algorithm.name, public: pub },
3863
- dk_T,
3864
- PQTKEM.t.Nss << 3,
3865
- ),
3848
+ (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: pub }, dk_T, PQTKEM.t.Nss << 3),
3866
3849
  PQTKEM.name,
3867
3850
  ),
3868
3851
  )
@@ -3937,10 +3920,10 @@ function PQTKEM_SHARED() {
3937
3920
 
3938
3921
  const format = 'raw-public'
3939
3922
  const ek_PQ = new Uint8Array(
3940
- await subtle(() => crypto.subtle.exportKey(format, key.getPq(priv)), this.name),
3923
+ await subtle((c) => c.exportKey(format, key.getPq(priv)), this.name),
3941
3924
  )
3942
3925
  const ek_T = new Uint8Array(
3943
- await subtle(() => crypto.subtle.exportKey('raw', key.getT(priv)), this.name),
3926
+ await subtle((c) => c.exportKey('raw', key.getT(priv)), this.name),
3944
3927
  )
3945
3928
 
3946
3929
  return concat(ek_PQ, ek_T)
@@ -3953,11 +3936,8 @@ function PQTKEM_SHARED() {
3953
3936
  const pubPq = ab(key.subarray(0, this.pq.Npk))
3954
3937
  const pubT = ab(key.subarray(this.pq.Npk))
3955
3938
  const [ek_PQ, ek_T] = await Promise.all([
3956
- subtle(
3957
- () => crypto.subtle.importKey(format, pubPq, this.pq.algorithm, true, usages),
3958
- this.name,
3959
- ),
3960
- subtle(() => crypto.subtle.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3939
+ subtle((c) => c.importKey(format, pubPq, this.pq.algorithm, true, usages), this.name),
3940
+ subtle((c) => c.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3961
3941
  ])
3962
3942
 
3963
3943
  return new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
package/index.ts CHANGED
@@ -111,13 +111,13 @@ class SenderContext {
111
111
  #key: Uint8Array
112
112
  #base_nonce: Uint8Array
113
113
  #exporter_secret: Uint8Array
114
- #mode: number
114
+ #mode: typeof MODE_BASE | typeof MODE_PSK
115
115
  #seq: number = 0
116
116
  #mutex?: Mutex
117
117
 
118
118
  constructor(
119
119
  suite: Triple,
120
- mode: number,
120
+ mode: typeof MODE_BASE | typeof MODE_PSK,
121
121
  key: Uint8Array,
122
122
  base_nonce: Uint8Array,
123
123
  exporter_secret: Uint8Array,
@@ -129,7 +129,11 @@ class SenderContext {
129
129
  this.#exporter_secret = exporter_secret
130
130
  }
131
131
 
132
- /** @returns The mode (0x00 = Base, 0x01 = PSK) for this context. */
132
+ /**
133
+ * @returns The mode (0x00 = Base, 0x01 = PSK) for this context.
134
+ * @see {@link MODE_BASE}
135
+ * @see {@link MODE_PSK}
136
+ */
133
137
  get mode(): number {
134
138
  return this.#mode
135
139
  }
@@ -253,13 +257,13 @@ class RecipientContext {
253
257
  #key: Uint8Array
254
258
  #base_nonce: Uint8Array
255
259
  #exporter_secret: Uint8Array
256
- #mode: number
260
+ #mode: typeof MODE_BASE | typeof MODE_PSK
257
261
  #seq: number = 0
258
262
  #mutex?: Mutex
259
263
 
260
264
  constructor(
261
265
  suite: Triple,
262
- mode: number,
266
+ mode: typeof MODE_BASE | typeof MODE_PSK,
263
267
  key: Uint8Array,
264
268
  base_nonce: Uint8Array,
265
269
  exporter_secret: Uint8Array,
@@ -271,7 +275,11 @@ class RecipientContext {
271
275
  this.#exporter_secret = exporter_secret
272
276
  }
273
277
 
274
- /** @returns The mode (0x00 = Base, 0x01 = PSK) for this context. */
278
+ /**
279
+ * @returns The mode (0x00 = Base, 0x01 = PSK) for this context.
280
+ * @see {@link MODE_BASE}
281
+ * @see {@link MODE_PSK}
282
+ */
275
283
  get mode(): number {
276
284
  return this.#mode
277
285
  }
@@ -600,11 +608,16 @@ export class CipherSuite {
600
608
  }
601
609
 
602
610
  /**
603
- * Deterministically derives a key pair for this CipherSuite from input keying material. By
611
+ * Deterministically derives a key pair for this CipherSuite's KEM from input keying material. By
604
612
  * default, private keys are derived as non-extractable (their value cannot be exported).
605
613
  *
606
- * An `ikm` input MUST NOT be reused elsewhere, particularly not with `DeriveKeyPair()` of a
607
- * different KEM.
614
+ * > [!CAUTION]\
615
+ * > Input keying material must not be reused elsewhere, particularly not with `DeriveKeyPair()` of
616
+ * > a different KEM. Re-use across different KEMs could leak information about the private key.
617
+ *
618
+ * > [!CAUTION]\
619
+ * > Input keying material should be generated from a cryptographically secure random source or
620
+ * > derived from high-entropy secret material.
608
621
  *
609
622
  * @category Key Management
610
623
  * @example
@@ -695,7 +708,7 @@ export class CipherSuite {
695
708
  * const privateKey: HPKE.Key = await suite.DeserializePrivateKey(serialized)
696
709
  * ```
697
710
  *
698
- * @param privateKey - Serialized private key
711
+ * @param privateKey - Serialized private key (must be exactly {@link CipherSuite.KEM Nsk} bytes)
699
712
  * @param extractable - Whether the deserialized private key should be extractable (e.g. by
700
713
  * {@link SerializePrivateKey}) (default: false)
701
714
  *
@@ -732,7 +745,7 @@ export class CipherSuite {
732
745
  * const publicKey: HPKE.Key = await suite.DeserializePublicKey(serialized)
733
746
  * ```
734
747
  *
735
- * @param publicKey - Serialized public key
748
+ * @param publicKey - Serialized public key (must be exactly {@link CipherSuite.KEM Npk} bytes)
736
749
  *
737
750
  * @returns A Promise that resolves to the deserialized public key.
738
751
  */
@@ -1239,10 +1252,21 @@ interface Triple {
1239
1252
  readonly AEAD: Readonly<AEAD>
1240
1253
  }
1241
1254
 
1242
- /** Mode identifier for Base mode */
1255
+ /**
1256
+ * Mode identifier for Base mode (0x00).
1257
+ *
1258
+ * Base mode provides encryption to a public key without sender authentication. The recipient cannot
1259
+ * verify who encrypted the message, only that someone with access to their public key did.
1260
+ */
1243
1261
  export const MODE_BASE = 0x00
1244
1262
 
1245
- /** Mode identifier for PSK mode */
1263
+ /**
1264
+ * Mode identifier for PSK mode (0x01).
1265
+ *
1266
+ * PSK (Pre-Shared Key) mode provides encryption with authentication using a pre-shared secret. Both
1267
+ * sender and recipient must possess the same PSK and PSK ID. This provides implicit sender
1268
+ * authentication.
1269
+ */
1246
1270
  export const MODE_PSK = 0x01
1247
1271
 
1248
1272
  /**
@@ -1346,6 +1370,9 @@ export interface KeyPair {
1346
1370
  * This interface is designed to be compatible with Web Cryptography's CryptoKey objects while
1347
1371
  * allowing for custom key implementations that may not have all CryptoKey properties. It includes
1348
1372
  * only the essential properties needed for HPKE operations and validations.
1373
+ *
1374
+ * Keys are created through {@link CipherSuite.GenerateKeyPair}, {@link CipherSuite.DeriveKeyPair},
1375
+ * {@link CipherSuite.DeserializePrivateKey}, or {@link CipherSuite.DeserializePublicKey}.
1349
1376
  */
1350
1377
  export interface Key {
1351
1378
  /** The key algorithm properties */
@@ -1393,7 +1420,7 @@ function slice(buffer: Uint8Array, start?: number, end?: number) {
1393
1420
  * Encodes an ASCII string into a Uint8Array.
1394
1421
  *
1395
1422
  * This utility function converts ASCII strings to byte arrays. It's exported for use in custom KEM,
1396
- * KDF, or AEAD implementations.
1423
+ * KDF, or AEAD implementations to encode identifiers or HPKE suite_id values.
1397
1424
  *
1398
1425
  * @param string - ASCII string to encode
1399
1426
  *
@@ -1404,6 +1431,9 @@ export function encode(string: string): Uint8Array {
1404
1431
  const bytes = new Uint8Array(string.length)
1405
1432
  for (let i = 0; i < string.length; i++) {
1406
1433
  const code = string.charCodeAt(i)
1434
+ if (code > 0x7f) {
1435
+ throw new TypeError('Input string must contain only ASCII characters')
1436
+ }
1407
1437
  bytes[i] = code
1408
1438
  }
1409
1439
  return bytes
@@ -1919,7 +1949,7 @@ export interface KEM {
1919
1949
  /**
1920
1950
  * Deserializes a public key from bytes.
1921
1951
  *
1922
- * @param key - The serialized public key already validated to be at least {@link Npk} bytes
1952
+ * @param key - The serialized public key already validated to be exactly {@link Npk} bytes
1923
1953
  *
1924
1954
  * @returns A promise resolving to a {@link !Key} or a Key interface-conforming object
1925
1955
  */
@@ -1937,7 +1967,7 @@ export interface KEM {
1937
1967
  /**
1938
1968
  * Deserializes a private key from bytes.
1939
1969
  *
1940
- * @param key - The serialized private key already validated to be at least {@link Nsk} bytes
1970
+ * @param key - The serialized private key already validated to be exactly {@link Nsk} bytes
1941
1971
  * @param extractable - Whether the private key should be extractable
1942
1972
  *
1943
1973
  * @returns A promise resolving to a {@link !Key} or a Key interface-conforming object
@@ -2121,7 +2151,7 @@ export interface AEAD {
2121
2151
  * into a byte string of specified length. It's exported for use in custom KEM, KDF, or AEAD
2122
2152
  * implementations.
2123
2153
  *
2124
- * @param n - Non-negative integer to convert
2154
+ * @param n - Non-negative safe integer to convert
2125
2155
  * @param w - Desired length of output in bytes
2126
2156
  *
2127
2157
  * @returns A Uint8Array of length w containing the big-endian representation of n
@@ -2221,12 +2251,12 @@ export const AEAD_EXPORT_ONLY: AEADFactory = function (): AEAD {
2221
2251
  }
2222
2252
 
2223
2253
  // ============================================================================
2224
- // Crypto.subtle wrapper to convert DOMException NotSupportedError
2254
+ // Wrapper for crypto.subtle to convert DOMException to NotSupportedError
2225
2255
  // ============================================================================
2226
2256
 
2227
- async function subtle<T>(promise: () => Promise<T>, name: string): Promise<T> {
2257
+ async function subtle<T>(promise: (subtle: SubtleCrypto) => Promise<T>, name: string): Promise<T> {
2228
2258
  try {
2229
- return await promise()
2259
+ return await promise(crypto.subtle)
2230
2260
  } catch (cause) {
2231
2261
  if (
2232
2262
  cause instanceof TypeError ||
@@ -2272,12 +2302,10 @@ function HKDF_SHARED(): KDF_BASE {
2272
2302
  const ikm = ab(_ikm)
2273
2303
  return new Uint8Array(
2274
2304
  await subtle(
2275
- async () =>
2276
- crypto.subtle.sign(
2305
+ async (c) =>
2306
+ c.sign(
2277
2307
  'HMAC',
2278
- await crypto.subtle.importKey('raw', salt, { name: 'HMAC', hash: this.hash }, false, [
2279
- 'sign',
2280
- ]),
2308
+ await c.importKey('raw', salt, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2281
2309
  ikm,
2282
2310
  ),
2283
2311
  this.name,
@@ -2294,8 +2322,7 @@ function HKDF_SHARED(): KDF_BASE {
2294
2322
  const N = Math.ceil(L / this.Nh)
2295
2323
  const prk = ab(_prk)
2296
2324
  const key = await subtle(
2297
- () =>
2298
- crypto.subtle.importKey('raw', prk, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2325
+ (c) => c.importKey('raw', prk, { name: 'HMAC', hash: this.hash }, false, ['sign']),
2299
2326
  this.name,
2300
2327
  )
2301
2328
 
@@ -2308,9 +2335,7 @@ function HKDF_SHARED(): KDF_BASE {
2308
2335
  input.set(info, T_prev.byteLength)
2309
2336
  input[T_prev.byteLength + info.byteLength] = i + 1
2310
2337
 
2311
- const T_i = new Uint8Array(
2312
- await subtle(() => crypto.subtle.sign('HMAC', key, input), this.name),
2313
- )
2338
+ const T_i = new Uint8Array(await subtle((c) => c.sign('HMAC', key, input), this.name))
2314
2339
 
2315
2340
  T.set(T_i, i * this.Nh)
2316
2341
  T_prev = T_i
@@ -2400,20 +2425,8 @@ interface SHAKE extends KDF {
2400
2425
  }
2401
2426
 
2402
2427
  async function ShakeDerive(name: string, variant: string, ikm: ArrayBuffer, L: number) {
2403
- return new Uint8Array(
2404
- await subtle(
2405
- () =>
2406
- crypto.subtle.digest(
2407
- {
2408
- name: variant,
2409
- // @ts-expect-error
2410
- length: L << 3,
2411
- },
2412
- ikm,
2413
- ),
2414
- name,
2415
- ),
2416
- )
2428
+ const alg = { name: variant, length: L << 3 }
2429
+ return new Uint8Array(await subtle((c) => c.digest(alg, ikm), name))
2417
2430
  }
2418
2431
 
2419
2432
  function SHAKE_SHARED(): KDF_BASE {
@@ -2496,9 +2509,9 @@ async function getPublicKeyByExport(
2496
2509
  )
2497
2510
  }
2498
2511
 
2499
- return await subtle(async () => {
2500
- const jwk = await crypto.subtle.exportKey('jwk', key)
2501
- return await crypto.subtle.importKey(
2512
+ return await subtle(async (c) => {
2513
+ const jwk = await c.exportKey('jwk', key)
2514
+ return c.importKey(
2502
2515
  'jwk',
2503
2516
  { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y } as JsonWebKey,
2504
2517
  key.algorithm,
@@ -2511,7 +2524,7 @@ async function getPublicKeyByExport(
2511
2524
  async function getPublicKey(name: string, key: CryptoKey, usages: KeyUsage[]): Promise<CryptoKey> {
2512
2525
  return (
2513
2526
  // @ts-expect-error
2514
- ((await subtle(() => crypto.subtle.getPublicKey?.(key, usages), name)) as CryptoKey) ||
2527
+ ((await subtle((c) => c.getPublicKey?.(key, usages), name)) as CryptoKey) ||
2515
2528
  (await getPublicKeyByExport(name, key, usages))
2516
2529
  )
2517
2530
  }
@@ -2651,26 +2664,23 @@ function DHKEM_SHARED(): Required<Omit<KEM_BASE, 'DeriveKeyPair' | 'DeserializeP
2651
2664
  return {
2652
2665
  async GenerateKeyPair(this: DHKEM, extractable) {
2653
2666
  return (await subtle(
2654
- () => crypto.subtle.generateKey(this.algorithm, extractable, ['deriveBits']),
2667
+ (c) => c.generateKey(this.algorithm, extractable, ['deriveBits']),
2655
2668
  this.name,
2656
2669
  )) as CryptoKeyPair
2657
2670
  },
2658
2671
  async SerializePublicKey(this: DHKEM, key) {
2659
2672
  assertKeyAlgorithm(key, this.algorithm)
2660
2673
  assertCryptoKey(key)
2661
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey('raw', key), this.name))
2674
+ return new Uint8Array(await subtle((c) => c.exportKey('raw', key), this.name))
2662
2675
  },
2663
2676
  async DeserializePublicKey(this: DHKEM, _key) {
2664
2677
  const key = ab(_key)
2665
- return await subtle(
2666
- () => crypto.subtle.importKey('raw', key, this.algorithm, true, []),
2667
- this.name,
2668
- )
2678
+ return await subtle((c) => c.importKey('raw', key, this.algorithm, true, []), this.name)
2669
2679
  },
2670
2680
  async SerializePrivateKey(this: DHKEM, key) {
2671
2681
  assertKeyAlgorithm(key, this.algorithm)
2672
2682
  assertCryptoKey(key)
2673
- const { d } = await subtle(() => crypto.subtle.exportKey('jwk', key), this.name)
2683
+ const { d } = await subtle((c) => c.exportKey('jwk', key), this.name)
2674
2684
  return b64u(d!)
2675
2685
  },
2676
2686
  async Encap(this: DHKEM, pkR) {
@@ -2685,8 +2695,7 @@ function DHKEM_SHARED(): Required<Omit<KEM_BASE, 'DeriveKeyPair' | 'DeserializeP
2685
2695
  // by WebCrypto's underlying implementations
2686
2696
  const dh = new Uint8Array(
2687
2697
  await subtle(
2688
- () =>
2689
- crypto.subtle.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2698
+ (c) => c.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2690
2699
  this.name,
2691
2700
  ),
2692
2701
  )
@@ -2728,8 +2737,7 @@ function DHKEM_SHARED(): Required<Omit<KEM_BASE, 'DeriveKeyPair' | 'DeserializeP
2728
2737
  // by WebCrypto's underlying implementations
2729
2738
  const dh = new Uint8Array(
2730
2739
  await subtle(
2731
- () =>
2732
- crypto.subtle.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2740
+ (c) => c.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2733
2741
  this.name,
2734
2742
  ),
2735
2743
  )
@@ -2793,7 +2801,7 @@ async function CurveKeyFromD(
2793
2801
  pkcs8.set(tmpl)
2794
2802
  pkcs8.set(key, tmpl.byteLength)
2795
2803
  return await subtle(
2796
- () => crypto.subtle.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2804
+ (c) => c.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2797
2805
  name,
2798
2806
  )
2799
2807
  }
@@ -2934,7 +2942,7 @@ async function DeserializePrivateKeyNist(
2934
2942
  const jwk = getPrivateJwkNist(this, d)
2935
2943
 
2936
2944
  const privateKey = await subtle(
2937
- () => crypto.subtle.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2945
+ (c) => c.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2938
2946
  this.name,
2939
2947
  )
2940
2948
 
@@ -2971,13 +2979,13 @@ async function GetKeyPairNist(
2971
2979
  const jwk = getPrivateJwkNist(curveConfig, OS2IP(sk))
2972
2980
 
2973
2981
  const privateKey = await subtle(
2974
- () => crypto.subtle.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2982
+ (c) => c.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2975
2983
  name,
2976
2984
  )
2977
2985
 
2978
2986
  delete jwk.d
2979
2987
  const publicKey = await subtle(
2980
- () => crypto.subtle.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2988
+ (c) => c.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2981
2989
  name,
2982
2990
  )
2983
2991
 
@@ -3300,7 +3308,7 @@ function MLKEM_SHARED(): KEM_BASE {
3300
3308
  // @ts-expect-error
3301
3309
  const usages: KeyUsage[] = ['encapsulateBits', 'decapsulateBits']
3302
3310
  return (await subtle(
3303
- () => crypto.subtle.generateKey(this.algorithm, extractable, usages),
3311
+ (c) => c.generateKey(this.algorithm, extractable, usages),
3304
3312
  this.name,
3305
3313
  )) as CryptoKeyPair
3306
3314
  },
@@ -3309,7 +3317,7 @@ function MLKEM_SHARED(): KEM_BASE {
3309
3317
  assertCryptoKey(key)
3310
3318
  // @ts-expect-error
3311
3319
  const format: Exclude<KeyFormat, 'jwk'> = 'raw-public'
3312
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey(format, key), this.name))
3320
+ return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3313
3321
  },
3314
3322
  async DeserializePublicKey(this: MLKEM, _key) {
3315
3323
  // @ts-expect-error
@@ -3317,17 +3325,14 @@ function MLKEM_SHARED(): KEM_BASE {
3317
3325
  // @ts-expect-error
3318
3326
  const usages: KeyUsage[] = ['encapsulateBits']
3319
3327
  const key = ab(_key)
3320
- return await subtle(
3321
- () => crypto.subtle.importKey(format, key, this.algorithm, true, usages),
3322
- this.name,
3323
- )
3328
+ return await subtle((c) => c.importKey(format, key, this.algorithm, true, usages), this.name)
3324
3329
  },
3325
3330
  async SerializePrivateKey(this: MLKEM, key) {
3326
3331
  assertKeyAlgorithm(key, this.algorithm)
3327
3332
  assertCryptoKey(key)
3328
3333
  // @ts-expect-error
3329
3334
  const format: Exclude<KeyFormat, 'jwk'> = 'raw-seed'
3330
- return new Uint8Array(await subtle(() => crypto.subtle.exportKey(format, key), this.name))
3335
+ return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3331
3336
  },
3332
3337
  async DeserializePrivateKey(this: MLKEM, _key, extractable) {
3333
3338
  // @ts-expect-error
@@ -3336,7 +3341,7 @@ function MLKEM_SHARED(): KEM_BASE {
3336
3341
  const usages: KeyUsage[] = ['decapsulateBits']
3337
3342
  const key = ab(_key)
3338
3343
  return await subtle(
3339
- () => crypto.subtle.importKey(format, key, this.algorithm, extractable, usages),
3344
+ (c) => c.importKey(format, key, this.algorithm, extractable, usages),
3340
3345
  this.name,
3341
3346
  )
3342
3347
  },
@@ -3344,9 +3349,8 @@ function MLKEM_SHARED(): KEM_BASE {
3344
3349
  assertKeyAlgorithm(pkR, this.algorithm)
3345
3350
 
3346
3351
  const { sharedKey, ciphertext } = (await subtle(
3347
- () =>
3348
- // @ts-expect-error
3349
- crypto.subtle.encapsulateBits(this.algorithm, pkR),
3352
+ // @ts-expect-error
3353
+ (c) => c.encapsulateBits(this.algorithm, pkR),
3350
3354
  this.name,
3351
3355
  )) as { sharedKey: ArrayBuffer; ciphertext: ArrayBuffer }
3352
3356
 
@@ -3357,9 +3361,8 @@ function MLKEM_SHARED(): KEM_BASE {
3357
3361
  const enc = ab(_enc)
3358
3362
  return new Uint8Array(
3359
3363
  await subtle(
3360
- () =>
3361
- // @ts-expect-error
3362
- crypto.subtle.decapsulateBits(this.algorithm, skR, enc),
3364
+ // @ts-expect-error
3365
+ (c) => c.decapsulateBits(this.algorithm, skR, enc),
3363
3366
  this.name,
3364
3367
  ),
3365
3368
  )
@@ -3504,12 +3507,10 @@ function AEAD_SHARED(): AEAD_BASE {
3504
3507
  const pt = ab(_pt)
3505
3508
  return new Uint8Array(
3506
3509
  await subtle(
3507
- async () =>
3508
- crypto.subtle.encrypt(
3510
+ async (c) =>
3511
+ c.encrypt(
3509
3512
  { name: this.algorithm, iv: nonce, additionalData: aad },
3510
- await crypto.subtle.importKey(this.keyFormat, key, this.algorithm, false, [
3511
- 'encrypt',
3512
- ]),
3513
+ await c.importKey(this.keyFormat, key, this.algorithm, false, ['encrypt']),
3513
3514
  pt,
3514
3515
  ),
3515
3516
  this.name,
@@ -3523,12 +3524,10 @@ function AEAD_SHARED(): AEAD_BASE {
3523
3524
  const ct = ab(_ct)
3524
3525
  return new Uint8Array(
3525
3526
  await subtle(
3526
- async () =>
3527
- crypto.subtle.decrypt(
3527
+ async (c) =>
3528
+ c.decrypt(
3528
3529
  { name: this.algorithm, iv: nonce, additionalData: aad },
3529
- await crypto.subtle.importKey(this.keyFormat, key, this.algorithm, false, [
3530
- 'decrypt',
3531
- ]),
3530
+ await c.importKey(this.keyFormat, key, this.algorithm, false, ['decrypt']),
3532
3531
  ct,
3533
3532
  ),
3534
3533
  this.name,
@@ -3759,7 +3758,7 @@ async function expandDecapsKeyG(PQTKEM: HybridKEM, _seed: Uint8Array) {
3759
3758
  // @ts-expect-error
3760
3759
  const algorithm: CShakeParams = { name: 'cSHAKE256', length: Nout << 3 }
3761
3760
  const seed = ab(_seed)
3762
- const seed_full = await subtle(() => crypto.subtle.digest(algorithm, seed), PQTKEM.name)
3761
+ const seed_full = await subtle((c) => c.digest(algorithm, seed), PQTKEM.name)
3763
3762
 
3764
3763
  const [_seed_PQ, seed_T] = split(PQTKEM.pq.Nseed, PQTKEM.t.Nseed, new Uint8Array(seed_full))
3765
3764
  const seed_PQ = ab(_seed_PQ)
@@ -3769,7 +3768,7 @@ async function expandDecapsKeyG(PQTKEM: HybridKEM, _seed: Uint8Array) {
3769
3768
  // @ts-expect-error
3770
3769
  const usages: [KeyUsage, KeyUsage] = ['decapsulateBits', 'encapsulateBits']
3771
3770
  const dk_PQ = await subtle(
3772
- () => crypto.subtle.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3771
+ (c) => c.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3773
3772
  PQTKEM.name,
3774
3773
  )
3775
3774
  const ek_PQ = await getPublicKey(PQTKEM.name, dk_PQ, [usages[1]])
@@ -3788,11 +3787,9 @@ async function C2PRICombiner(
3788
3787
  _ek_T: CryptoKey,
3789
3788
  label: Uint8Array,
3790
3789
  ): Promise<Uint8Array> {
3791
- const ek_T = new Uint8Array(
3792
- await subtle(() => crypto.subtle.exportKey('raw', _ek_T), PQTKEM.name),
3793
- )
3790
+ const ek_T = new Uint8Array(await subtle((c) => c.exportKey('raw', _ek_T), PQTKEM.name))
3794
3791
  const data = ab(concat(ss_PQ, ss_T, ct_T, ek_T, label))
3795
- return new Uint8Array(await subtle(() => crypto.subtle.digest('SHA3-256', data), PQTKEM.name))
3792
+ return new Uint8Array(await subtle((c) => c.digest('SHA3-256', data), PQTKEM.name))
3796
3793
  }
3797
3794
 
3798
3795
  async function prepareEncapsG(
@@ -3801,30 +3798,22 @@ async function prepareEncapsG(
3801
3798
  ek_T: CryptoKey,
3802
3799
  ): Promise<[Uint8Array, Uint8Array, Uint8Array, Uint8Array]> {
3803
3800
  const res = (await subtle(
3804
- () =>
3805
- // @ts-expect-error
3806
- crypto.subtle.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3801
+ // @ts-expect-error
3802
+ (c) => c.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3807
3803
  PQTKEM.name,
3808
3804
  )) as { sharedKey: ArrayBuffer; ciphertext: ArrayBuffer }
3809
3805
  const ss_PQ = new Uint8Array(res.sharedKey)
3810
3806
  const ct_PQ = new Uint8Array(res.ciphertext)
3811
3807
 
3812
3808
  const { privateKey: sk_E, publicKey } = (await subtle(
3813
- () => crypto.subtle.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3809
+ (c) => c.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3814
3810
  PQTKEM.name,
3815
3811
  )) as CryptoKeyPair
3816
- const ct_T = new Uint8Array(
3817
- await subtle(() => crypto.subtle.exportKey('raw', publicKey), PQTKEM.name),
3818
- )
3812
+ const ct_T = new Uint8Array(await subtle((c) => c.exportKey('raw', publicKey), PQTKEM.name))
3819
3813
 
3820
3814
  const ss_T = new Uint8Array(
3821
3815
  await subtle(
3822
- () =>
3823
- crypto.subtle.deriveBits(
3824
- { name: PQTKEM.t.algorithm.name, public: ek_T },
3825
- sk_E,
3826
- PQTKEM.t.Nss << 3,
3827
- ),
3816
+ (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: ek_T }, sk_E, PQTKEM.t.Nss << 3),
3828
3817
  PQTKEM.name,
3829
3818
  ),
3830
3819
  )
@@ -3842,27 +3831,21 @@ async function prepareDecapsG(
3842
3831
  ): Promise<[Uint8Array, Uint8Array]> {
3843
3832
  const ss_PQ = new Uint8Array(
3844
3833
  await subtle(
3845
- () =>
3846
- // @ts-expect-error
3847
- crypto.subtle.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3834
+ // @ts-expect-error
3835
+ (c) => c.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3848
3836
  PQTKEM.name,
3849
3837
  ),
3850
3838
  )
3851
3839
 
3852
3840
  const ct_T = ab(_ct_T)
3853
3841
  const pub = await subtle(
3854
- () => crypto.subtle.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3842
+ (c) => c.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3855
3843
  PQTKEM.name,
3856
3844
  )
3857
3845
 
3858
3846
  const ss_T = new Uint8Array(
3859
3847
  await subtle(
3860
- () =>
3861
- crypto.subtle.deriveBits(
3862
- { name: PQTKEM.t.algorithm.name, public: pub },
3863
- dk_T,
3864
- PQTKEM.t.Nss << 3,
3865
- ),
3848
+ (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: pub }, dk_T, PQTKEM.t.Nss << 3),
3866
3849
  PQTKEM.name,
3867
3850
  ),
3868
3851
  )
@@ -3937,10 +3920,10 @@ function PQTKEM_SHARED(): KEM_BASE {
3937
3920
  // @ts-expect-error
3938
3921
  const format: Exclude<KeyFormat, 'jwk'> = 'raw-public'
3939
3922
  const ek_PQ = new Uint8Array(
3940
- await subtle(() => crypto.subtle.exportKey(format, key.getPq(priv)), this.name),
3923
+ await subtle((c) => c.exportKey(format, key.getPq(priv)), this.name),
3941
3924
  )
3942
3925
  const ek_T = new Uint8Array(
3943
- await subtle(() => crypto.subtle.exportKey('raw', key.getT(priv)), this.name),
3926
+ await subtle((c) => c.exportKey('raw', key.getT(priv)), this.name),
3944
3927
  )
3945
3928
 
3946
3929
  return concat(ek_PQ, ek_T)
@@ -3953,11 +3936,8 @@ function PQTKEM_SHARED(): KEM_BASE {
3953
3936
  const pubPq = ab(key.subarray(0, this.pq.Npk))
3954
3937
  const pubT = ab(key.subarray(this.pq.Npk))
3955
3938
  const [ek_PQ, ek_T] = await Promise.all([
3956
- subtle(
3957
- () => crypto.subtle.importKey(format, pubPq, this.pq.algorithm, true, usages),
3958
- this.name,
3959
- ),
3960
- subtle(() => crypto.subtle.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3939
+ subtle((c) => c.importKey(format, pubPq, this.pq.algorithm, true, usages), this.name),
3940
+ subtle((c) => c.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3961
3941
  ])
3962
3942
 
3963
3943
  return new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hpke",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Hybrid Public Key Encryption (HPKE) for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "browser",