@sebastienrousseau/crypto-lib 0.0.8 → 0.0.24

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 (42) hide show
  1. package/dist/accel/wasm-bridge.d.ts.map +1 -1
  2. package/dist/accel/wasm-bridge.js +46 -46
  3. package/dist/bin/cryptolib.d.ts +2 -11
  4. package/dist/bin/cryptolib.d.ts.map +1 -1
  5. package/dist/bin/cryptolib.js +3 -10
  6. package/dist/high-level/index.d.ts +1 -1
  7. package/dist/high-level/index.d.ts.map +1 -1
  8. package/dist/high-level/index.js +3 -1
  9. package/dist/high-level/multi-recipient.d.ts +6 -0
  10. package/dist/high-level/multi-recipient.d.ts.map +1 -1
  11. package/dist/high-level/multi-recipient.js +34 -23
  12. package/dist/index.d.ts +1 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -8
  15. package/dist/keys/keygen.d.ts.map +1 -1
  16. package/dist/keys/keygen.js +19 -83
  17. package/dist/modern/hash.d.ts.map +1 -1
  18. package/dist/modern/hash.js +26 -14
  19. package/dist/modern/hpke.d.ts +1 -1
  20. package/dist/modern/hpke.d.ts.map +1 -1
  21. package/dist/modern/hpke.js +74 -11
  22. package/dist/modern/index.d.ts +1 -1
  23. package/dist/modern/index.d.ts.map +1 -1
  24. package/dist/modern/index.js +2 -0
  25. package/dist/modern/kdf.d.ts.map +1 -1
  26. package/dist/modern/kdf.js +25 -19
  27. package/dist/streaming/index.d.ts +6 -2
  28. package/dist/streaming/index.d.ts.map +1 -1
  29. package/dist/streaming/index.js +18 -1
  30. package/dist/streaming/stream-multi-pq-aead.d.ts +35 -0
  31. package/dist/streaming/stream-multi-pq-aead.d.ts.map +1 -0
  32. package/dist/streaming/stream-multi-pq-aead.js +315 -0
  33. package/dist/streaming/stream-pq-aead.d.ts +29 -0
  34. package/dist/streaming/stream-pq-aead.d.ts.map +1 -0
  35. package/dist/streaming/stream-pq-aead.js +175 -0
  36. package/dist/streaming/web-streams.d.ts +25 -0
  37. package/dist/streaming/web-streams.d.ts.map +1 -1
  38. package/dist/streaming/web-streams.js +106 -0
  39. package/dist/tokens/paseto.d.ts +1 -0
  40. package/dist/tokens/paseto.d.ts.map +1 -1
  41. package/dist/tokens/paseto.js +66 -69
  42. package/package.json +88 -13
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-bridge.d.ts","sourceRoot":"","sources":["../../src/accel/wasm-bridge.ts"],"names":[],"mappings":"AA8BA,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;AAGtD,MAAM,MAAM,iBAAiB,GAC3B,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAG3D,MAAM,WAAW,eAAe;IAE9B,SAAS,EAAE,iBAAiB,CAAC;IAE7B,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC3B;AAGD,MAAM,WAAW,cAAc;IAE7B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,iBAAiB,CAAC;IAE7B,OAAO,EAAE,WAAW,CAAC;CACtB;AAGD,MAAM,WAAW,sBAAsB;IAErC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAE/B,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAGD,MAAM,WAAW,qBAAqB;IAEpC,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,EAAE,WAAW,CAAC;CACtB;AAGD,MAAM,WAAW,qBAAqB;IAEpC,SAAS,EAAE,UAAU,CAAC;IAEtB,OAAO,EAAE,WAAW,CAAC;CACtB;AAoBD,wBAAgB,iBAAiB,IAAI,WAAW,CA0E/C;AASD,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAkDD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc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DD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAYjE;AAgBD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,qBAAqB,CAsBvB;AAWD,wBAAgB,eAAe,CAAC,OAAO,EAAE;IAEvC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,UAAU,EAAE,MAAM,CAAC;IAEnB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB,GAAG,qBAAqB,CAmBxB"}
@@ -11,6 +11,51 @@ const blake3_js_1 = require("@noble/hashes/blake3.js");
11
11
  const chacha_js_1 = require("@noble/ciphers/chacha.js");
12
12
  const utils_js_1 = require("@noble/ciphers/utils.js");
13
13
  let cachedBackend;
14
+ const SIMD_TEST_BYTES = new Uint8Array([
15
+ 0x00,
16
+ 0x61,
17
+ 0x73,
18
+ 0x6d,
19
+ 0x01,
20
+ 0x00,
21
+ 0x00,
22
+ 0x00,
23
+ 0x01,
24
+ 0x05,
25
+ 0x01,
26
+ 0x60,
27
+ 0x00,
28
+ 0x01,
29
+ 0x7b,
30
+ 0x03,
31
+ 0x02,
32
+ 0x01,
33
+ 0x00,
34
+ 0x0a,
35
+ 0x0a,
36
+ 0x01,
37
+ 0x08,
38
+ 0x00,
39
+ 0xfd,
40
+ 0x0c,
41
+ 0x00,
42
+ 0x00,
43
+ 0x00,
44
+ 0x00,
45
+ 0x00,
46
+ 0x00,
47
+ 0x00,
48
+ 0x00,
49
+ 0x00,
50
+ 0x00,
51
+ 0x00,
52
+ 0x00,
53
+ 0x00,
54
+ 0x00,
55
+ 0x00,
56
+ 0x00,
57
+ 0x0b,
58
+ ]);
14
59
  function detectWasmBackend() {
15
60
  if (cachedBackend !== undefined)
16
61
  return cachedBackend;
@@ -21,52 +66,7 @@ function detectWasmBackend() {
21
66
  return cachedBackend;
22
67
  }
23
68
  try {
24
- const simdTest = new Uint8Array([
25
- 0x00,
26
- 0x61,
27
- 0x73,
28
- 0x6d,
29
- 0x01,
30
- 0x00,
31
- 0x00,
32
- 0x00,
33
- 0x01,
34
- 0x05,
35
- 0x01,
36
- 0x60,
37
- 0x00,
38
- 0x01,
39
- 0x7b,
40
- 0x03,
41
- 0x02,
42
- 0x01,
43
- 0x00,
44
- 0x0a,
45
- 0x0a,
46
- 0x01,
47
- 0x08,
48
- 0x00,
49
- 0xfd,
50
- 0x0c,
51
- 0x00,
52
- 0x00,
53
- 0x00,
54
- 0x00,
55
- 0x00,
56
- 0x00,
57
- 0x00,
58
- 0x00,
59
- 0x00,
60
- 0x00,
61
- 0x00,
62
- 0x00,
63
- 0x00,
64
- 0x00,
65
- 0x00,
66
- 0x00,
67
- 0x0b,
68
- ]);
69
- const mod = new WA.Module(simdTest);
69
+ const mod = new WA.Module(SIMD_TEST_BYTES);
70
70
  if (mod) {
71
71
  cachedBackend = "wasm-simd";
72
72
  return cachedBackend;
@@ -11,15 +11,6 @@ export declare function session(data: dataSessionKey): Promise<import("openpgp")
11
11
  export declare function revoke(data: dataRevoke): Promise<ArmoredKeyResult>;
12
12
  export declare function sign(data: dataSign): Promise<string>;
13
13
  export declare function verify(data: dataVerify): Promise<import("openpgp").VerifyMessageResult<GenericWebStream<T>>>;
14
- declare const _default: {
15
- decrypt: typeof decrypt;
16
- encrypt: typeof encrypt;
17
- generate: typeof generate;
18
- reformat: typeof reformat;
19
- revoke: typeof revoke;
20
- session: typeof session;
21
- sign: typeof sign;
22
- verify: typeof verify;
23
- };
24
- export default _default;
14
+ export { loadKeystore } from "../key/keystore";
15
+ export type { Keystore } from "../key/keystore";
25
16
  //# sourceMappingURL=cryptolib.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cryptolib.d.ts","sourceRoot":"","sources":["../../src/bin/cryptolib.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,O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GxE;AAiBD,wBAAsB,IAAI,CAAC,IAAI,EAAE,QAAQ,mBAGxC;AAiBD,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,uEAG5C;AAOD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadKeystore = void 0;
36
37
  exports.decrypt = decrypt;
37
38
  exports.encrypt = encrypt;
38
39
  exports.generate = generate;
@@ -74,14 +75,6 @@ async function verify(data) {
74
75
  const verify = await key.verify.default(data);
75
76
  return verify;
76
77
  }
77
- exports.default = {
78
- decrypt,
79
- encrypt,
80
- generate,
81
- reformat,
82
- revoke,
83
- session,
84
- sign,
85
- verify,
86
- };
78
+ var keystore_1 = require("../key/keystore");
79
+ Object.defineProperty(exports, "loadKeystore", { enumerable: true, get: function () { return keystore_1.loadKeystore; } });
87
80
  //# sourceMappingURL=cryptolib.js.map
@@ -6,6 +6,6 @@ export { passwordEncrypt, passwordDecrypt } from "./password-encrypt";
6
6
  export type { PasswordEncryptOptions, PasswordEncryptResult, } from "./password-encrypt";
7
7
  export { aesKwWrap, aesKwUnwrap, aesKwpWrap, aesKwpUnwrap, x25519AesKwWrap, x25519AesKwUnwrap, } from "./key-wrap";
8
8
  export type { AesKwWrapResult, X25519AesKwWrapResult } from "./key-wrap";
9
- export { multiEncrypt, multiDecryptClassical, multiDecryptPQ, } from "./multi-recipient";
9
+ export { multiEncrypt, multiDecryptClassical, multiDecryptPQ, wrapDekHybrid, unwrapDekHybrid, } from "./multi-recipient";
10
10
  export type { ClassicalRecipient, PqRecipient, Recipient, WrappedKey, MultiRecipientEncryptResult, } from "./multi-recipient";
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/high-level/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEtE,YAAY,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,UAAU,EACV,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/high-level/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEtE,YAAY,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,UAAU,EACV,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC"}
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.multiDecryptPQ = exports.multiDecryptClassical = exports.multiEncrypt = exports.x25519AesKwUnwrap = exports.x25519AesKwWrap = exports.aesKwpUnwrap = exports.aesKwpWrap = exports.aesKwUnwrap = exports.aesKwWrap = exports.passwordDecrypt = exports.passwordEncrypt = exports.sealedbox = exports.secretbox = void 0;
36
+ exports.unwrapDekHybrid = exports.wrapDekHybrid = exports.multiDecryptPQ = exports.multiDecryptClassical = exports.multiEncrypt = exports.x25519AesKwUnwrap = exports.x25519AesKwWrap = exports.aesKwpUnwrap = exports.aesKwpWrap = exports.aesKwUnwrap = exports.aesKwWrap = exports.passwordDecrypt = exports.passwordEncrypt = exports.sealedbox = exports.secretbox = void 0;
37
37
  exports.secretbox = __importStar(require("./secretbox"));
38
38
  exports.sealedbox = __importStar(require("./sealedbox"));
39
39
  var password_encrypt_1 = require("./password-encrypt");
@@ -50,4 +50,6 @@ var multi_recipient_1 = require("./multi-recipient");
50
50
  Object.defineProperty(exports, "multiEncrypt", { enumerable: true, get: function () { return multi_recipient_1.multiEncrypt; } });
51
51
  Object.defineProperty(exports, "multiDecryptClassical", { enumerable: true, get: function () { return multi_recipient_1.multiDecryptClassical; } });
52
52
  Object.defineProperty(exports, "multiDecryptPQ", { enumerable: true, get: function () { return multi_recipient_1.multiDecryptPQ; } });
53
+ Object.defineProperty(exports, "wrapDekHybrid", { enumerable: true, get: function () { return multi_recipient_1.wrapDekHybrid; } });
54
+ Object.defineProperty(exports, "unwrapDekHybrid", { enumerable: true, get: function () { return multi_recipient_1.unwrapDekHybrid; } });
53
55
  //# sourceMappingURL=index.js.map
@@ -21,5 +21,11 @@ export interface MultiRecipientEncryptResult {
21
21
  }
22
22
  export declare function multiEncrypt(recipients: Recipient[], plaintext: string | Uint8Array): MultiRecipientEncryptResult;
23
23
  export declare function multiDecryptClassical(secretKey: string | Uint8Array, wrappedKey: WrappedKey, ciphertext: string): Uint8Array;
24
+ export declare function wrapDekHybrid(dek: Uint8Array, x25519PublicKey: string, mlKemPublicKey: string): {
25
+ wrappedKey: string;
26
+ ephemeralPublicKey: string;
27
+ mlKemCiphertext: string;
28
+ };
29
+ export declare function unwrapDekHybrid(x25519SecretKey: string | Uint8Array, mlKemSecretKey: string | Uint8Array, ephemeralPublicKey: string, mlKemCiphertext: string, wrappedKey: string): Uint8Array;
24
30
  export declare function multiDecryptPQ(x25519SecretKey: string | Uint8Array, mlKemSecretKey: string | Uint8Array, wrappedKey: WrappedKey, ciphertext: string): Uint8Array;
25
31
  //# sourceMappingURL=multi-recipient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multi-recipient.d.ts","sourceRoot":"","sources":["../../src/high-level/multi-recipient.ts"],"names":[],"mappings":"AAwCA,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE,QAAQ,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,WAAW;IAE1B,IAAI,EAAE,mBAAmB,CAAC;IAE1B,eAAe,EAAE,MAAM,CAAC;IAExB,cAAc,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,MAAM,SAAS,GAAG,kBAAkB,GAAG,WAAW,CAAC;AAGzD,MAAM,WAAW,UAAU;IAEzB,IAAI,EAAE,QAAQ,GAAG,mBAAmB,CAAC;IAErC,UAAU,EAAE,MAAM,CAAC;IAEnB,kBAAkB,EAAE,MAAM,CAAC;IAE3B,eAAe,CAAC,EAAE,MA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AQD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,EAAE,EACvB,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,2BAA2B,CAkC7B;AASD,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,GACjB,UAAU,CAOZ;AASD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,EACf,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,GACrB;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;CACzB,CAkCA;AAWD,wBAAgB,eAAe,CAC7B,eAAe,EAAE,MAAM,GAAG,UAAU,EACpC,cAAc,EAAE,MAAM,GAAG,UAAU,EACnC,kBAAkB,EAAE,MAAM,EAC1B,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,GACjB,UAAU,CAiCZ;AAUD,wBAAgB,cAAc,CAC5B,eAAe,EAAE,MAAM,GAAG,UAAU,EACpC,cAAc,EAAE,MAAM,GAAG,UAAU,EACnC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,GACjB,UAAU,CAcZ"}
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.multiEncrypt = multiEncrypt;
37
37
  exports.multiDecryptClassical = multiDecryptClassical;
38
+ exports.wrapDekHybrid = wrapDekHybrid;
39
+ exports.unwrapDekHybrid = unwrapDekHybrid;
38
40
  exports.multiDecryptPQ = multiDecryptPQ;
39
41
  const utils_js_1 = require("@noble/ciphers/utils.js");
40
42
  const secretbox = __importStar(require("./secretbox"));
@@ -66,23 +68,10 @@ function multiEncrypt(recipients, plaintext) {
66
68
  };
67
69
  }
68
70
  else {
69
- const x25519Pub = hexToBytes(r.x25519PublicKey);
70
- const mlKemPub = hexToBytes(r.mlKemPublicKey);
71
- const ephPriv = (0, utils_js_1.randomBytes)(32);
72
- const ephPub = ed25519_js_1.x25519.getPublicKey(ephPriv);
73
- const x25519Shared = ed25519_js_1.x25519.getSharedSecret(ephPriv, x25519Pub);
74
- const { cipherText: mlKemCt, sharedSecret: mlKemShared } = ml_kem_js_1.ml_kem768.encapsulate(mlKemPub);
75
- const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
76
- combined.set(x25519Shared);
77
- combined.set(mlKemShared, x25519Shared.length);
78
- const kek = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, ephPub, new TextEncoder().encode("multi-recipient-pq-v1"), 32);
79
- const cipher = (0, aes_js_1.aeskw)(kek);
80
- const wrapped = cipher.encrypt(dek);
71
+ const wrapped = wrapDekHybrid(dek, r.x25519PublicKey, r.mlKemPublicKey);
81
72
  return {
82
73
  type: "x25519-ml-kem-768",
83
- wrappedKey: Buffer.from(wrapped).toString("base64"),
84
- ephemeralPublicKey: Buffer.from(ephPub).toString("hex"),
85
- mlKemCiphertext: Buffer.from(mlKemCt).toString("hex"),
74
+ ...wrapped,
86
75
  };
87
76
  }
88
77
  });
@@ -96,27 +85,49 @@ function multiDecryptClassical(secretKey, wrappedKey, ciphertext) {
96
85
  const dek = (0, key_wrap_1.x25519AesKwUnwrap)(secretKey, wrappedKey.ephemeralPublicKey, wrappedKey.wrappedKey);
97
86
  return secretbox.open(dek, ciphertext);
98
87
  }
99
- function multiDecryptPQ(x25519SecretKey, mlKemSecretKey, wrappedKey, ciphertext) {
88
+ function wrapDekHybrid(dek, x25519PublicKey, mlKemPublicKey) {
89
+ const x25519Pub = hexToBytes(x25519PublicKey);
90
+ const mlKemPub = hexToBytes(mlKemPublicKey);
91
+ const ephPriv = (0, utils_js_1.randomBytes)(32);
92
+ const ephPub = ed25519_js_1.x25519.getPublicKey(ephPriv);
93
+ const x25519Shared = ed25519_js_1.x25519.getSharedSecret(ephPriv, x25519Pub);
94
+ const { cipherText: mlKemCt, sharedSecret: mlKemShared } = ml_kem_js_1.ml_kem768.encapsulate(mlKemPub);
95
+ const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
96
+ combined.set(x25519Shared);
97
+ combined.set(mlKemShared, x25519Shared.length);
98
+ const kek = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, ephPub, new TextEncoder().encode("multi-recipient-pq-v1"), 32);
99
+ const cipher = (0, aes_js_1.aeskw)(kek);
100
+ const wrapped = cipher.encrypt(dek);
101
+ return {
102
+ wrappedKey: Buffer.from(wrapped).toString("base64"),
103
+ ephemeralPublicKey: Buffer.from(ephPub).toString("hex"),
104
+ mlKemCiphertext: Buffer.from(mlKemCt).toString("hex"),
105
+ };
106
+ }
107
+ function unwrapDekHybrid(x25519SecretKey, mlKemSecretKey, ephemeralPublicKey, mlKemCiphertext, wrappedKey) {
100
108
  const x25519Sec = typeof x25519SecretKey === "string"
101
109
  ? hexToBytes(x25519SecretKey)
102
110
  : x25519SecretKey;
103
111
  const mlKemSec = typeof mlKemSecretKey === "string"
104
112
  ? hexToBytes(mlKemSecretKey)
105
113
  : mlKemSecretKey;
106
- if (!wrappedKey.mlKemCiphertext) {
107
- throw new Error("Missing ML-KEM ciphertext in wrapped key");
108
- }
109
- const ephPub = hexToBytes(wrappedKey.ephemeralPublicKey);
110
- const mlKemCt = hexToBytes(wrappedKey.mlKemCiphertext);
114
+ const ephPub = hexToBytes(ephemeralPublicKey);
115
+ const mlKemCt = hexToBytes(mlKemCiphertext);
111
116
  const x25519Shared = ed25519_js_1.x25519.getSharedSecret(x25519Sec, ephPub);
112
117
  const mlKemShared = ml_kem_js_1.ml_kem768.decapsulate(mlKemCt, mlKemSec);
113
118
  const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
114
119
  combined.set(x25519Shared);
115
120
  combined.set(mlKemShared, x25519Shared.length);
116
121
  const kek = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, ephPub, new TextEncoder().encode("multi-recipient-pq-v1"), 32);
117
- const wrapped = Buffer.from(wrappedKey.wrappedKey, "base64");
122
+ const wrapped = Buffer.from(wrappedKey, "base64");
118
123
  const cipher = (0, aes_js_1.aeskw)(kek);
119
- const dek = cipher.decrypt(wrapped);
124
+ return cipher.decrypt(wrapped);
125
+ }
126
+ function multiDecryptPQ(x25519SecretKey, mlKemSecretKey, wrappedKey, ciphertext) {
127
+ if (!wrappedKey.mlKemCiphertext) {
128
+ throw new Error("Missing ML-KEM ciphertext in wrapped key");
129
+ }
130
+ const dek = unwrapDekHybrid(x25519SecretKey, mlKemSecretKey, wrappedKey.ephemeralPublicKey, wrappedKey.mlKemCiphertext, wrappedKey.wrappedKey);
120
131
  return secretbox.open(dek, ciphertext);
121
132
  }
122
133
  //# sourceMappingURL=multi-recipient.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import CryptoLib from "./bin/cryptolib";
2
- export default CryptoLib;
1
+ export * as pgp from "./bin/cryptolib";
3
2
  export * from "./modern";
4
3
  export * from "./high-level";
5
4
  export * from "./keys";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAGxC,eAAe,SAAS,CAAC;AAGzB,cAAc,UAAU,CAAC;AAGzB,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAG5B,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAGnC,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAGvC,cAAc,UAAU,CAAC;AAGzB,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAG5B,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAGnC,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -15,9 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
18
  var __importStar = (this && this.__importStar) || (function () {
22
19
  var ownKeys = function(o) {
23
20
  ownKeys = Object.getOwnPropertyNames || function (o) {
@@ -35,13 +32,12 @@ var __importStar = (this && this.__importStar) || (function () {
35
32
  return result;
36
33
  };
37
34
  })();
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
40
37
  };
41
38
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.wipeMemory = exports.SecureBuffer = exports.timingSafeEqual = exports.CryptoErrorCode = exports.CryptoError = exports.isDeprecated = exports.recommended = exports.listAlgorithms = exports.getAlgorithm = exports.crypto = exports.tokens = exports.protocols = void 0;
43
- const cryptolib_1 = __importDefault(require("./bin/cryptolib"));
44
- exports.default = cryptolib_1.default;
39
+ exports.wipeMemory = exports.SecureBuffer = exports.timingSafeEqual = exports.CryptoErrorCode = exports.CryptoError = exports.isDeprecated = exports.recommended = exports.listAlgorithms = exports.getAlgorithm = exports.crypto = exports.tokens = exports.protocols = exports.pgp = void 0;
40
+ exports.pgp = __importStar(require("./bin/cryptolib"));
45
41
  __exportStar(require("./modern"), exports);
46
42
  __exportStar(require("./high-level"), exports);
47
43
  __exportStar(require("./keys"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/keys/keygen.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,cAAc,mJAajB,CAAC;AAGX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,MAAM,WAAW,WAAW;IAE1B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzB,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;IAEhC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAGD,MAAM,WAAW,gBAAgB;IAE/B,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,YAAY,CAAC;IAExB,GAAG,EAAE,MAAM,CAAC;IAEZ,QAAQ,EAAE,WAAW,CAAC;CACvB;AAuBD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,YAAY,EACvB,QAAQ,GAAE,WAAgB,GACzB,gBAAgB,CAkGlB"}
1
+ {"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/keys/keygen.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,cAAc,mJAajB,CAAC;AAGX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,MAAM,WAAW,WAAW;IAE1B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzB,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;IAEhC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAGD,MAAM,WAAW,gBAAgB;IAE/B,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,YAAY,CAAC;IAExB,GAAG,EAAE,MAAM,CAAC;IAEZ,QAAQ,EAAE,WAAW,CAAC;CACvB;AAsDD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,YAAY,EACvB,QAAQ,GAAE,WAAgB,GACzB,gBAAgB,CAiBlB"}
@@ -31,91 +31,27 @@ function generateKid(publicKey) {
31
31
  const digest = (0, sha2_js_1.sha256)(publicKey);
32
32
  return (0, serialize_1.bytesToBase64url)(digest.subarray(0, 16));
33
33
  }
34
+ const fromSecret = (privateKey, derive) => ({ publicKey: derive(privateKey), privateKey });
35
+ const fromPq = (kp) => ({ publicKey: kp.publicKey, privateKey: kp.secretKey });
36
+ const KEYGEN = {
37
+ ed25519: () => fromSecret(ed25519_js_1.ed25519.utils.randomSecretKey(), ed25519_js_1.ed25519.getPublicKey),
38
+ x25519: () => fromSecret((0, utils_js_1.randomBytes)(32), ed25519_js_1.x25519.getPublicKey),
39
+ ed448: () => fromSecret(ed448_js_1.ed448.utils.randomSecretKey(), ed448_js_1.ed448.getPublicKey),
40
+ x448: () => fromSecret((0, utils_js_1.randomBytes)(56), ed448_js_1.x448.getPublicKey),
41
+ p256: () => fromSecret(nist_js_1.p256.utils.randomSecretKey(), nist_js_1.p256.getPublicKey),
42
+ p384: () => fromSecret(nist_js_1.p384.utils.randomSecretKey(), nist_js_1.p384.getPublicKey),
43
+ "ml-kem-512": () => fromPq(ml_kem_js_1.ml_kem512.keygen()),
44
+ "ml-kem-768": () => fromPq(ml_kem_js_1.ml_kem768.keygen()),
45
+ "ml-kem-1024": () => fromPq(ml_kem_js_1.ml_kem1024.keygen()),
46
+ "ml-dsa-44": () => fromPq(ml_dsa_js_1.ml_dsa44.keygen()),
47
+ "ml-dsa-65": () => fromPq(ml_dsa_js_1.ml_dsa65.keygen()),
48
+ "ml-dsa-87": () => fromPq(ml_dsa_js_1.ml_dsa87.keygen()),
49
+ };
34
50
  function generateKeyPair(algorithm, metadata = {}) {
35
- let publicKey;
36
- let privateKey;
37
- switch (algorithm) {
38
- case "ed25519": {
39
- const priv = ed25519_js_1.ed25519.utils.randomSecretKey();
40
- const pub = ed25519_js_1.ed25519.getPublicKey(priv);
41
- privateKey = priv;
42
- publicKey = pub;
43
- break;
44
- }
45
- case "x25519": {
46
- const priv = (0, utils_js_1.randomBytes)(32);
47
- const pub = ed25519_js_1.x25519.getPublicKey(priv);
48
- privateKey = priv;
49
- publicKey = pub;
50
- break;
51
- }
52
- case "ed448": {
53
- const priv = ed448_js_1.ed448.utils.randomSecretKey();
54
- const pub = ed448_js_1.ed448.getPublicKey(priv);
55
- privateKey = priv;
56
- publicKey = pub;
57
- break;
58
- }
59
- case "x448": {
60
- const priv = (0, utils_js_1.randomBytes)(56);
61
- const pub = ed448_js_1.x448.getPublicKey(priv);
62
- privateKey = priv;
63
- publicKey = pub;
64
- break;
65
- }
66
- case "p256": {
67
- const priv = nist_js_1.p256.utils.randomSecretKey();
68
- const pub = nist_js_1.p256.getPublicKey(priv);
69
- privateKey = priv;
70
- publicKey = pub;
71
- break;
72
- }
73
- case "p384": {
74
- const priv = nist_js_1.p384.utils.randomSecretKey();
75
- const pub = nist_js_1.p384.getPublicKey(priv);
76
- privateKey = priv;
77
- publicKey = pub;
78
- break;
79
- }
80
- case "ml-kem-512": {
81
- const kp = ml_kem_js_1.ml_kem512.keygen();
82
- publicKey = kp.publicKey;
83
- privateKey = kp.secretKey;
84
- break;
85
- }
86
- case "ml-kem-768": {
87
- const kp = ml_kem_js_1.ml_kem768.keygen();
88
- publicKey = kp.publicKey;
89
- privateKey = kp.secretKey;
90
- break;
91
- }
92
- case "ml-kem-1024": {
93
- const kp = ml_kem_js_1.ml_kem1024.keygen();
94
- publicKey = kp.publicKey;
95
- privateKey = kp.secretKey;
96
- break;
97
- }
98
- case "ml-dsa-44": {
99
- const kp = ml_dsa_js_1.ml_dsa44.keygen();
100
- publicKey = kp.publicKey;
101
- privateKey = kp.secretKey;
102
- break;
103
- }
104
- case "ml-dsa-65": {
105
- const kp = ml_dsa_js_1.ml_dsa65.keygen();
106
- publicKey = kp.publicKey;
107
- privateKey = kp.secretKey;
108
- break;
109
- }
110
- case "ml-dsa-87": {
111
- const kp = ml_dsa_js_1.ml_dsa87.keygen();
112
- publicKey = kp.publicKey;
113
- privateKey = kp.secretKey;
114
- break;
115
- }
116
- default:
117
- throw new Error(`Unsupported algorithm: ${algorithm}. Supported: ${exports.KEY_ALGORITHMS.join(", ")}`);
51
+ if (!Object.hasOwn(KEYGEN, algorithm)) {
52
+ throw new Error(`Unsupported algorithm: ${algorithm}. Supported: ${exports.KEY_ALGORITHMS.join(", ")}`);
118
53
  }
54
+ const { publicKey, privateKey } = KEYGEN[algorithm]();
119
55
  const kid = metadata.kid ?? generateKid(publicKey);
120
56
  return {
121
57
  publicKey: toHex(publicKey),
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/modern/hash.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,eAAe,sFAQlB,CAAC;AAGX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7D,MAAM,WAAW,WAAW;IAE1B,SAAS,EAAE,aAAa,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B;AAGD,MAAM,WAAW,UAAU;IAEzB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,aAAa,CAAC;IAEzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAuBD,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,CAiBrD"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/modern/hash.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,eAAe,sFAQlB,CAAC;AAGX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7D,MAAM,WAAW,WAAW;IAE1B,SAAS,EAAE,aAAa,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B;AAGD,MAAM,WAAW,UAAU;IAEzB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,aAAa,CAAC;IAEzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,CAqCrD"}
@@ -20,22 +20,34 @@ function toBytes(input) {
20
20
  return input;
21
21
  return Buffer.from(input, "utf8");
22
22
  }
23
- const hashFunctions = {
24
- sha256: (d) => (0, sha2_js_1.sha256)(d),
25
- sha384: (d) => (0, sha2_js_1.sha384)(d),
26
- sha512: (d) => (0, sha2_js_1.sha512)(d),
27
- "sha3-256": (d) => (0, sha3_js_1.sha3_256)(d),
28
- "sha3-512": (d) => (0, sha3_js_1.sha3_512)(d),
29
- blake2b: (d) => (0, blake2_js_1.blake2b)(d),
30
- blake3: (d) => (0, blake3_js_1.blake3)(d),
31
- };
32
23
  function hash(options) {
33
- const fn = hashFunctions[options.algorithm];
34
- if (!fn) {
35
- throw new Error(`Unsupported algorithm: ${options.algorithm}. Supported: ${exports.HASH_ALGORITHMS.join(", ")}`);
36
- }
37
24
  const data = toBytes(options.data);
38
- const digest = fn(data);
25
+ let digest;
26
+ switch (options.algorithm) {
27
+ case "sha256":
28
+ digest = (0, sha2_js_1.sha256)(data);
29
+ break;
30
+ case "sha384":
31
+ digest = (0, sha2_js_1.sha384)(data);
32
+ break;
33
+ case "sha512":
34
+ digest = (0, sha2_js_1.sha512)(data);
35
+ break;
36
+ case "sha3-256":
37
+ digest = (0, sha3_js_1.sha3_256)(data);
38
+ break;
39
+ case "sha3-512":
40
+ digest = (0, sha3_js_1.sha3_512)(data);
41
+ break;
42
+ case "blake2b":
43
+ digest = (0, blake2_js_1.blake2b)(data);
44
+ break;
45
+ case "blake3":
46
+ digest = (0, blake3_js_1.blake3)(data);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported algorithm: ${options.algorithm}. Supported: ${exports.HASH_ALGORITHMS.join(", ")}`);
50
+ }
39
51
  return {
40
52
  digest: Buffer.from(digest).toString("hex"),
41
53
  algorithm: options.algorithm,
@@ -1,4 +1,4 @@
1
- export type HpkeKem = "x25519" | "p256";
1
+ export type HpkeKem = "x25519" | "p256" | "x25519-ml-kem-768";
2
2
  export type HpkeAead = "chacha20-poly1305" | "aes-128-gcm";
3
3
  export type HpkeMode = "base" | "psk";
4
4
  export interface HpkeKeyPair {
@@ -1 +1 @@
1
- {"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../src/modern/hpke.ts"],"names":[],"mappings":"AA4DA,MAAM,MAA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