simple-hpke 0.1.5 → 0.2.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/dist/index.cjs CHANGED
@@ -24,8 +24,8 @@ __export(index_exports, {
24
24
  create: () => create2,
25
25
  decrypt: () => decrypt,
26
26
  encrypt: () => encrypt,
27
- open: () => open,
28
- seal: () => seal
27
+ encryptKey: () => encryptKey,
28
+ open: () => open
29
29
  });
30
30
  module.exports = __toCommonJS(index_exports);
31
31
 
@@ -1366,17 +1366,7 @@ async function aeadOpen(key, nonce, ciphertext) {
1366
1366
  __name(aeadOpen, "aeadOpen");
1367
1367
  async function encryptBytes(recipient, message, aesKey, opts) {
1368
1368
  const plaintext = typeof message === "string" ? new TextEncoder().encode(message) : message;
1369
- let enc;
1370
- let key;
1371
- if (!aesKey) {
1372
- const keys = await create2(recipient, opts);
1373
- enc = keys.enc;
1374
- key = keys.key;
1375
- } else {
1376
- const keys = await seal(recipient, aesKey, opts);
1377
- enc = keys.enc;
1378
- key = keys.key;
1379
- }
1369
+ const { enc, key } = await encryptKey(recipient, aesKey, opts);
1380
1370
  const iv = globalThis.crypto.getRandomValues(new Uint8Array(NN));
1381
1371
  const ct = new Uint8Array(await subtle.encrypt(
1382
1372
  { name: "AES-GCM", iv },
@@ -1585,15 +1575,10 @@ __name(concat2, "concat");
1585
1575
  // src/index.ts
1586
1576
  var subtle2 = globalThis.crypto.subtle;
1587
1577
  async function create2(recipient, opts) {
1588
- const { wrapped, key } = await encryptKey(recipient, null, opts);
1589
- return { enc: wrapped, key };
1578
+ const { enc, key } = await encryptKey(recipient, null, opts);
1579
+ return { enc, key };
1590
1580
  }
1591
1581
  __name(create2, "create");
1592
- async function seal(recipient, aesKey, opts) {
1593
- const { wrapped, key } = await encryptKey(recipient, aesKey, opts);
1594
- return { enc: wrapped, key };
1595
- }
1596
- __name(seal, "seal");
1597
1582
  var open = Object.assign(openBytes, {
1598
1583
  raw: openRawBytes
1599
1584
  });
@@ -1774,7 +1759,7 @@ async function encryptKey(recipient, aesKey, opts) {
1774
1759
  const ciphertext = await aeadSeal(key, baseNonce, keyBytes);
1775
1760
  const wrapped = concat2(enc, ciphertext);
1776
1761
  const aesGcmKey = await importAesKey(keyBytes);
1777
- return { wrapped, key: aesGcmKey };
1762
+ return { enc: wrapped, key: aesGcmKey };
1778
1763
  }
1779
1764
  __name(encryptKey, "encryptKey");
1780
1765
  //# sourceMappingURL=index.cjs.map