@sebastienrousseau/crypto-lib 0.0.34 → 0.0.36

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 (174) hide show
  1. package/README.md +17 -2
  2. package/dist/accel/index.d.ts +5 -4
  3. package/dist/accel/index.d.ts.map +1 -1
  4. package/dist/accel/index.js +5 -5
  5. package/dist/accel/kdf-backend.d.ts +13 -0
  6. package/dist/accel/kdf-backend.d.ts.map +1 -0
  7. package/dist/accel/kdf-backend.js +81 -0
  8. package/dist/accel/native-pqc-bridge.d.ts.map +1 -1
  9. package/dist/accel/native-pqc-bridge.js +12 -52
  10. package/dist/accel/pq-backend.d.ts +3652 -0
  11. package/dist/accel/pq-backend.d.ts.map +1 -0
  12. package/dist/accel/pq-backend.js +215 -0
  13. package/dist/accel/runtime.d.ts +3 -0
  14. package/dist/accel/runtime.d.ts.map +1 -0
  15. package/dist/accel/runtime.js +9 -0
  16. package/dist/accel/wasm-bridge.d.ts.map +1 -1
  17. package/dist/accel/wasm-bridge.js +14 -13
  18. package/dist/accel/webcrypto-bridge.d.ts.map +1 -1
  19. package/dist/accel/webcrypto-bridge.js +14 -13
  20. package/dist/accel/webcrypto-modern.d.ts.map +1 -1
  21. package/dist/accel/webcrypto-modern.js +15 -14
  22. package/dist/accel/worker-pool.d.ts +18 -0
  23. package/dist/accel/worker-pool.d.ts.map +1 -1
  24. package/dist/accel/worker-pool.js +113 -37
  25. package/dist/bin/cryptolib.d.ts +7 -4
  26. package/dist/bin/cryptolib.d.ts.map +1 -1
  27. package/dist/bin/cryptolib.js +6 -6
  28. package/dist/crypto.d.ts.map +1 -1
  29. package/dist/crypto.js +2 -1
  30. package/dist/encoding.d.ts +10 -0
  31. package/dist/encoding.d.ts.map +1 -0
  32. package/dist/encoding.js +84 -0
  33. package/dist/errors.d.ts +11 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +20 -1
  36. package/dist/high-level/key-wrap.d.ts.map +1 -1
  37. package/dist/high-level/key-wrap.js +12 -17
  38. package/dist/high-level/multi-recipient.d.ts.map +1 -1
  39. package/dist/high-level/multi-recipient.js +15 -28
  40. package/dist/high-level/password-encrypt.d.ts.map +1 -1
  41. package/dist/high-level/password-encrypt.js +11 -11
  42. package/dist/high-level/sealedbox.d.ts.map +1 -1
  43. package/dist/high-level/sealedbox.js +16 -28
  44. package/dist/high-level/secretbox.d.ts.map +1 -1
  45. package/dist/high-level/secretbox.js +11 -10
  46. package/dist/index.d.ts +1 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +3 -1
  49. package/dist/key/keystore.d.ts.map +1 -1
  50. package/dist/key/keystore.js +2 -1
  51. package/dist/keys/keygen.d.ts.map +1 -1
  52. package/dist/keys/keygen.js +13 -14
  53. package/dist/keys/keyring.d.ts.map +1 -1
  54. package/dist/keys/keyring.js +4 -2
  55. package/dist/keys/serialize.d.ts.map +1 -1
  56. package/dist/keys/serialize.js +18 -16
  57. package/dist/lib/decrypt.d.ts.map +1 -1
  58. package/dist/lib/decrypt.js +2 -1
  59. package/dist/lib/generate.d.ts +2 -1
  60. package/dist/lib/generate.d.ts.map +1 -1
  61. package/dist/lib/generate.js +7 -6
  62. package/dist/lib/key-output.d.ts +4 -1
  63. package/dist/lib/key-output.d.ts.map +1 -1
  64. package/dist/lib/key-output.js +2 -2
  65. package/dist/lib/reformat.d.ts +2 -1
  66. package/dist/lib/reformat.d.ts.map +1 -1
  67. package/dist/lib/reformat.js +2 -2
  68. package/dist/lib/revoke.d.ts +2 -1
  69. package/dist/lib/revoke.d.ts.map +1 -1
  70. package/dist/lib/revoke.js +2 -2
  71. package/dist/lib/verify.d.ts +6 -2
  72. package/dist/lib/verify.d.ts.map +1 -1
  73. package/dist/lib/verify.js +28 -9
  74. package/dist/modern/aead.d.ts.map +1 -1
  75. package/dist/modern/aead.js +11 -10
  76. package/dist/modern/aes.d.ts.map +1 -1
  77. package/dist/modern/aes.js +10 -9
  78. package/dist/modern/cost-limits.d.ts.map +1 -1
  79. package/dist/modern/cost-limits.js +3 -2
  80. package/dist/modern/curves.d.ts +10 -5
  81. package/dist/modern/curves.d.ts.map +1 -1
  82. package/dist/modern/curves.js +43 -36
  83. package/dist/modern/ecdh.d.ts +2 -1
  84. package/dist/modern/ecdh.d.ts.map +1 -1
  85. package/dist/modern/ecdh.js +10 -9
  86. package/dist/modern/fn-dsa.d.ts.map +1 -1
  87. package/dist/modern/fn-dsa.js +9 -8
  88. package/dist/modern/hash.d.ts.map +1 -1
  89. package/dist/modern/hash.js +5 -3
  90. package/dist/modern/hpke-xwing.d.ts +10 -0
  91. package/dist/modern/hpke-xwing.d.ts.map +1 -0
  92. package/dist/modern/hpke-xwing.js +26 -0
  93. package/dist/modern/hpke.d.ts +1 -1
  94. package/dist/modern/hpke.d.ts.map +1 -1
  95. package/dist/modern/hpke.js +60 -28
  96. package/dist/modern/hybrid-combiner.d.ts +20 -0
  97. package/dist/modern/hybrid-combiner.d.ts.map +1 -0
  98. package/dist/modern/hybrid-combiner.js +79 -0
  99. package/dist/modern/index.d.ts +10 -10
  100. package/dist/modern/index.d.ts.map +1 -1
  101. package/dist/modern/index.js +17 -7
  102. package/dist/modern/kdf.d.ts.map +1 -1
  103. package/dist/modern/kdf.js +12 -12
  104. package/dist/modern/mac.d.ts +1 -0
  105. package/dist/modern/mac.d.ts.map +1 -1
  106. package/dist/modern/mac.js +24 -15
  107. package/dist/modern/password.d.ts.map +1 -1
  108. package/dist/modern/password.js +19 -18
  109. package/dist/modern/pq-hash-sign.d.ts.map +1 -1
  110. package/dist/modern/pq-hash-sign.js +23 -22
  111. package/dist/modern/pq-kem.d.ts +8 -0
  112. package/dist/modern/pq-kem.d.ts.map +1 -1
  113. package/dist/modern/pq-kem.js +71 -79
  114. package/dist/modern/pq-sign.d.ts +9 -2
  115. package/dist/modern/pq-sign.d.ts.map +1 -1
  116. package/dist/modern/pq-sign.js +60 -23
  117. package/dist/modern/pq.d.ts +0 -17
  118. package/dist/modern/pq.d.ts.map +1 -1
  119. package/dist/modern/pq.js +15 -43
  120. package/dist/modern/signing.d.ts +2 -1
  121. package/dist/modern/signing.d.ts.map +1 -1
  122. package/dist/modern/signing.js +14 -13
  123. package/dist/protocols/iso20022.d.ts.map +1 -1
  124. package/dist/protocols/iso20022.js +12 -6
  125. package/dist/protocols/opaque/ksf.js +2 -2
  126. package/dist/protocols/opaque/suite.d.ts +1 -8
  127. package/dist/protocols/opaque/suite.d.ts.map +1 -1
  128. package/dist/protocols/opaque/suite.js +5 -10
  129. package/dist/protocols/pqxdh.d.ts +9 -2
  130. package/dist/protocols/pqxdh.d.ts.map +1 -1
  131. package/dist/protocols/pqxdh.js +99 -94
  132. package/dist/protocols/ratchet.d.ts.map +1 -1
  133. package/dist/protocols/ratchet.js +14 -15
  134. package/dist/protocols/threshold.d.ts.map +1 -1
  135. package/dist/protocols/threshold.js +16 -15
  136. package/dist/registry.d.ts.map +1 -1
  137. package/dist/registry.js +26 -0
  138. package/dist/streaming/chunks.d.ts +40 -0
  139. package/dist/streaming/chunks.d.ts.map +1 -0
  140. package/dist/streaming/chunks.js +173 -0
  141. package/dist/streaming/stream-aead.d.ts +9 -0
  142. package/dist/streaming/stream-aead.d.ts.map +1 -1
  143. package/dist/streaming/stream-aead.js +33 -82
  144. package/dist/streaming/stream-hash.d.ts.map +1 -1
  145. package/dist/streaming/stream-hash.js +6 -4
  146. package/dist/streaming/stream-multi-pq-aead.d.ts +12 -0
  147. package/dist/streaming/stream-multi-pq-aead.d.ts.map +1 -1
  148. package/dist/streaming/stream-multi-pq-aead.js +90 -147
  149. package/dist/streaming/stream-pq-aead.d.ts +7 -3
  150. package/dist/streaming/stream-pq-aead.d.ts.map +1 -1
  151. package/dist/streaming/stream-pq-aead.js +34 -114
  152. package/dist/streaming/web-streams.d.ts +5 -2
  153. package/dist/streaming/web-streams.d.ts.map +1 -1
  154. package/dist/streaming/web-streams.js +90 -151
  155. package/dist/testing/index.d.ts +5 -0
  156. package/dist/testing/index.d.ts.map +1 -0
  157. package/dist/testing/index.js +13 -0
  158. package/dist/tokens/index.d.ts.map +1 -1
  159. package/dist/tokens/key-rotation.d.ts.map +1 -1
  160. package/dist/tokens/key-rotation.js +4 -2
  161. package/dist/tokens/paseto.d.ts +2 -0
  162. package/dist/tokens/paseto.d.ts.map +1 -1
  163. package/dist/tokens/paseto.js +56 -29
  164. package/dist/types/types.d.ts +1 -0
  165. package/dist/types/types.d.ts.map +1 -1
  166. package/dist/utils.d.ts.map +1 -1
  167. package/dist/utils.js +3 -2
  168. package/package.json +12 -2
  169. package/dist/config/config.d.ts +0 -8
  170. package/dist/config/config.d.ts.map +0 -1
  171. package/dist/config/config.js +0 -13
  172. package/dist/key/key.d.ts +0 -10
  173. package/dist/key/key.d.ts.map +0 -1
  174. package/dist/key/key.js +0 -25
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.passwordEncrypt = passwordEncrypt;
4
4
  exports.passwordDecrypt = passwordDecrypt;
5
- const argon2_js_1 = require("@noble/hashes/argon2.js");
5
+ const kdf_backend_1 = require("../accel/kdf-backend");
6
6
  const chacha_js_1 = require("@noble/ciphers/chacha.js");
7
7
  const utils_js_1 = require("@noble/ciphers/utils.js");
8
8
  const cost_limits_1 = require("../modern/cost-limits");
9
+ const errors_1 = require("../errors");
10
+ const encoding_1 = require("../encoding");
9
11
  const VERSION_V1 = 0x01;
10
12
  const VERSION_V2 = 0x02;
11
13
  const SALT_LEN = 16;
@@ -17,7 +19,7 @@ const DEFAULT_TIME = 3;
17
19
  const DEFAULT_MEMORY = 65536;
18
20
  const DEFAULT_PARALLELISM = 4;
19
21
  function toBytes(input) {
20
- return input instanceof Uint8Array ? input : Buffer.from(input, "utf8");
22
+ return input instanceof Uint8Array ? input : (0, encoding_1.utf8)(input);
21
23
  }
22
24
  function writeU32LE(buf, value, offset) {
23
25
  buf[offset] = value & 0xff;
@@ -51,7 +53,7 @@ function passwordEncrypt(options) {
51
53
  const p = options.parallelism ?? DEFAULT_PARALLELISM;
52
54
  (0, cost_limits_1.checkArgon2Costs)(t, m, p);
53
55
  const salt = (0, utils_js_1.randomBytes)(SALT_LEN);
54
- const key = (0, argon2_js_1.argon2id)(pwd, salt, { t, m, p, dkLen: KEY_LEN });
56
+ const key = (0, kdf_backend_1.argon2id)(pwd, salt, { t, m, p, dkLen: KEY_LEN });
55
57
  const nonce = (0, utils_js_1.randomBytes)(NONCE_LEN);
56
58
  const header = buildHeader(t, m, p, salt, nonce);
57
59
  const ct = (0, chacha_js_1.xchacha20poly1305)(key, nonce, header).encrypt(pt);
@@ -59,21 +61,19 @@ function passwordEncrypt(options) {
59
61
  out.set(header, 0);
60
62
  out.set(ct, HEADER_LEN);
61
63
  return {
62
- encrypted: Buffer.from(out).toString("base64"),
64
+ encrypted: (0, encoding_1.toBase64)(out),
63
65
  algorithm: "argon2id-xchacha20-poly1305",
64
66
  };
65
67
  }
66
68
  function passwordDecrypt(password, encrypted) {
67
69
  const pwd = toBytes(password);
68
- const raw = encrypted instanceof Uint8Array
69
- ? encrypted
70
- : Buffer.from(encrypted, "base64");
70
+ const raw = encrypted instanceof Uint8Array ? encrypted : (0, encoding_1.fromBase64)(encrypted);
71
71
  if (raw.length < HEADER_LEN + TAG_LEN) {
72
- throw new Error("Encrypted payload too short");
72
+ throw new errors_1.CryptoError("Encrypted payload too short", errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
73
73
  }
74
74
  const version = raw[0];
75
75
  if (version !== VERSION_V1 && version !== VERSION_V2) {
76
- throw new Error(`Unsupported format version: ${version}`);
76
+ throw new errors_1.CryptoError(`Unsupported format version: ${version}`, errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
77
77
  }
78
78
  const t = readU32LE(raw, 1);
79
79
  const m = readU32LE(raw, 5);
@@ -84,9 +84,9 @@ function passwordDecrypt(password, encrypted) {
84
84
  const ct = raw.subarray(HEADER_LEN);
85
85
  (0, cost_limits_1.checkArgon2Costs)(t, m, p);
86
86
  if (dkLen !== KEY_LEN) {
87
- throw new Error(`Unsupported key length in header: ${dkLen}`);
87
+ throw new errors_1.CryptoError(`Unsupported key length in header: ${dkLen}`, errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
88
88
  }
89
- const key = (0, argon2_js_1.argon2id)(pwd, salt, { t, m, p, dkLen });
89
+ const key = (0, kdf_backend_1.argon2id)(pwd, salt, { t, m, p, dkLen });
90
90
  const aad = version === VERSION_V2 ? raw.subarray(0, HEADER_LEN) : undefined;
91
91
  return (0, chacha_js_1.xchacha20poly1305)(key, nonce, aad).decrypt(ct);
92
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sealedbox.d.ts","sourceRoot":"","sources":["../../src/high-level/sealedbox.ts"],"names":[],"mappings":"AA8CA,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,2BAA2B,CAAC;CACxC;AAGD,MAAM,WAAW,iBAAiB;IAEhC,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,sCAAsC,CAAC;CACnD;AAQD,wBAAgB,IAAI,CAClB,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,eAAe,CAsCjB;AAQD,wBAAgB,IAAI,CAClB,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,UAAU,CA+BZ;AAmBD,wBAAgB,MAAM,CACpB,qBAAqB,EAAE,MAAM,GAAG,UAAU,EAC1C,oBAAoB,EAAE,MAAM,GAAG,UAAU,EACzC,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,iBAAiB,CAoDnB;AAYD,wBAAgB,MAAM,CACpB,qBAAqB,EAAE,MAAM,GAAG,UAAU,EAC1C,oBAAoB,EAAE,MAAM,GAAG,UAAU,EACzC,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,UAAU,CAiDZ"}
1
+ {"version":3,"file":"sealedbox.d.ts","sourceRoot":"","sources":["../../src/high-level/sealedbox.ts"],"names":[],"mappings":"AA0DA,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,2BAA2B,CAAC;CACxC;AAGD,MAAM,WAAW,iBAAiB;IAEhC,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,sCAAsC,CAAC;CACnD;AAQD,wBAAgB,IAAI,CAClB,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,eAAe,CAsCjB;AAQD,wBAAgB,IAAI,CAClB,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,UAAU,CA+BZ;AAqBD,wBAAgB,MAAM,CACpB,qBAAqB,EAAE,MAAM,GAAG,UAAU,EAC1C,oBAAoB,EAAE,MAAM,GAAG,UAAU,EACzC,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,iBAAiB,CAqCnB;AAYD,wBAAgB,MAAM,CACpB,qBAAqB,EAAE,MAAM,GAAG,UAAU,EAC1C,oBAAoB,EAAE,MAAM,GAAG,UAAU,EACzC,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,UAAU,CAiDZ"}
@@ -5,22 +5,23 @@ exports.open = open;
5
5
  exports.sealPQ = sealPQ;
6
6
  exports.openPQ = openPQ;
7
7
  const ed25519_js_1 = require("@noble/curves/ed25519.js");
8
- const ml_kem_js_1 = require("@noble/post-quantum/ml-kem.js");
8
+ const hybrid_combiner_1 = require("../modern/hybrid-combiner");
9
9
  const hkdf_js_1 = require("@noble/hashes/hkdf.js");
10
10
  const sha2_js_1 = require("@noble/hashes/sha2.js");
11
11
  const chacha_js_1 = require("@noble/ciphers/chacha.js");
12
12
  const utils_js_1 = require("@noble/ciphers/utils.js");
13
+ const errors_1 = require("../errors");
14
+ const encoding_1 = require("../encoding");
13
15
  const EPHEMERAL_LEN = 32;
14
16
  const NONCE_LEN = 24;
15
17
  const TAG_LEN = 16;
16
- const HEX_RE = /^[0-9a-fA-F]*$/;
17
18
  function hexToBytes(hex) {
18
- if (!HEX_RE.test(hex))
19
- throw new Error("Invalid hex string");
20
- return Buffer.from(hex, "hex");
19
+ if (!(0, encoding_1.isHex)(hex))
20
+ throw new errors_1.CryptoError("Invalid hex string", errors_1.CryptoErrorCode.INVALID_HEX);
21
+ return (0, encoding_1.decodeHex)(hex);
21
22
  }
22
23
  function toData(input) {
23
- return input instanceof Uint8Array ? input : Buffer.from(input, "utf8");
24
+ return input instanceof Uint8Array ? input : (0, encoding_1.utf8)(input);
24
25
  }
25
26
  function seal(recipientPublicKey, plaintext) {
26
27
  const recipPub = typeof recipientPublicKey === "string"
@@ -39,7 +40,7 @@ function seal(recipientPublicKey, plaintext) {
39
40
  out.set(nonce, EPHEMERAL_LEN);
40
41
  out.set(ct, EPHEMERAL_LEN + NONCE_LEN);
41
42
  return {
42
- sealed: Buffer.from(out).toString("base64"),
43
+ sealed: (0, encoding_1.toBase64)(out),
43
44
  algorithm: "x25519-xchacha20-poly1305",
44
45
  };
45
46
  }
@@ -47,10 +48,10 @@ function open(recipientSecretKey, sealed) {
47
48
  const secKey = typeof recipientSecretKey === "string"
48
49
  ? hexToBytes(recipientSecretKey)
49
50
  : recipientSecretKey;
50
- const raw = sealed instanceof Uint8Array ? sealed : Buffer.from(sealed, "base64");
51
+ const raw = sealed instanceof Uint8Array ? sealed : (0, encoding_1.fromBase64)(sealed);
51
52
  const minLen = EPHEMERAL_LEN + NONCE_LEN + TAG_LEN;
52
53
  if (raw.length < minLen) {
53
- throw new Error(`Sealed box too short: expected >= ${minLen} bytes, got ${raw.length}`);
54
+ throw new errors_1.CryptoError(`Sealed box too short: expected >= ${minLen} bytes, got ${raw.length}`, errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
54
55
  }
55
56
  const ephPub = raw.subarray(0, EPHEMERAL_LEN);
56
57
  const nonce = raw.subarray(EPHEMERAL_LEN, EPHEMERAL_LEN + NONCE_LEN);
@@ -67,14 +68,7 @@ function sealPQ(recipientX25519Public, recipientMlKemPublic, plaintext) {
67
68
  const mlKemPub = typeof recipientMlKemPublic === "string"
68
69
  ? hexToBytes(recipientMlKemPublic)
69
70
  : recipientMlKemPublic;
70
- const ephPriv = (0, utils_js_1.randomBytes)(32);
71
- const ephPub = ed25519_js_1.x25519.getPublicKey(ephPriv);
72
- const x25519Shared = ed25519_js_1.x25519.getSharedSecret(ephPriv, x25519Pub);
73
- const { cipherText: mlKemCt, sharedSecret: mlKemShared } = ml_kem_js_1.ml_kem768.encapsulate(mlKemPub);
74
- const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
75
- combined.set(x25519Shared);
76
- combined.set(mlKemShared, x25519Shared.length);
77
- const encKey = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, ephPub, new TextEncoder().encode("pq-sealedbox-v1"), 32);
71
+ const { ephPub, mlKemCt, key: encKey, } = (0, hybrid_combiner_1.hybridSend)(x25519Pub, mlKemPub, "sealed-box");
78
72
  const nonce = (0, utils_js_1.randomBytes)(NONCE_LEN);
79
73
  const pt = toData(plaintext);
80
74
  const cipher = (0, chacha_js_1.xchacha20poly1305)(encKey, nonce);
@@ -86,7 +80,7 @@ function sealPQ(recipientX25519Public, recipientMlKemPublic, plaintext) {
86
80
  out.set(nonce, EPHEMERAL_LEN + mlKemCtLen);
87
81
  out.set(ct, EPHEMERAL_LEN + mlKemCtLen + NONCE_LEN);
88
82
  return {
89
- sealed: Buffer.from(out).toString("base64"),
83
+ sealed: (0, encoding_1.toBase64)(out),
90
84
  algorithm: "x25519-ml-kem-768-xchacha20-poly1305",
91
85
  };
92
86
  }
@@ -98,22 +92,16 @@ function openPQ(recipientX25519Secret, recipientMlKemSecret, sealed) {
98
92
  const mlKemSec = typeof recipientMlKemSecret === "string"
99
93
  ? hexToBytes(recipientMlKemSecret)
100
94
  : recipientMlKemSecret;
101
- const raw = sealed instanceof Uint8Array ? sealed : Buffer.from(sealed, "base64");
95
+ const raw = sealed instanceof Uint8Array ? sealed : (0, encoding_1.fromBase64)(sealed);
102
96
  const minLen = EPHEMERAL_LEN + ML_KEM_768_CT_LEN + NONCE_LEN + TAG_LEN;
103
97
  if (raw.length < minLen) {
104
- throw new Error(`PQ sealed box too short: expected >= ${minLen} bytes, got ${raw.length}`);
98
+ throw new errors_1.CryptoError(`PQ sealed box too short: expected >= ${minLen} bytes, got ${raw.length}`, errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
105
99
  }
106
100
  const ephPub = raw.subarray(0, EPHEMERAL_LEN);
107
101
  const mlKemCt = raw.subarray(EPHEMERAL_LEN, EPHEMERAL_LEN + ML_KEM_768_CT_LEN);
108
102
  const nonce = raw.subarray(EPHEMERAL_LEN + ML_KEM_768_CT_LEN, EPHEMERAL_LEN + ML_KEM_768_CT_LEN + NONCE_LEN);
109
103
  const ct = raw.subarray(EPHEMERAL_LEN + ML_KEM_768_CT_LEN + NONCE_LEN);
110
- const x25519Shared = ed25519_js_1.x25519.getSharedSecret(x25519Sec, ephPub);
111
- const mlKemShared = ml_kem_js_1.ml_kem768.decapsulate(mlKemCt, mlKemSec);
112
- const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
113
- combined.set(x25519Shared);
114
- combined.set(mlKemShared, x25519Shared.length);
115
- const encKey = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, ephPub, new TextEncoder().encode("pq-sealedbox-v1"), 32);
116
- const cipher = (0, chacha_js_1.xchacha20poly1305)(encKey, nonce);
117
- return cipher.decrypt(ct);
104
+ const keys = (0, hybrid_combiner_1.hybridReceiveKeys)(x25519Sec, mlKemSec, ephPub, mlKemCt, "sealed-box", (x25519Shared, mlKemShared) => (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, (0, encoding_1.concat)([x25519Shared, mlKemShared]), ephPub, new TextEncoder().encode("pq-sealedbox-v1"), 32));
105
+ return (0, hybrid_combiner_1.openWithFirstKey)(keys, (key) => (0, chacha_js_1.xchacha20poly1305)(key, nonce).decrypt(ct));
118
106
  }
119
107
  //# sourceMappingURL=sealedbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"secretbox.d.ts","sourceRoot":"","sources":["../../src/high-level/secretbox.ts"],"names":[],"mappings":"AAoDA,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAQD,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,GAAG,CAAC,EAAE,UAAU,GACf,eAAe,CAajB;AAOD,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,MAAM,EAAE,MAAM,GAAG,UAAU,EAC3B,GAAG,CAAC,EAAE,UAAU,GACf,UAAU,CAWZ"}
1
+ {"version":3,"file":"secretbox.d.ts","sourceRoot":"","sources":["../../src/high-level/secretbox.ts"],"names":[],"mappings":"AAyDA,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAQD,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,GAAG,CAAC,EAAE,UAAU,GACf,eAAe,CAajB;AAOD,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,MAAM,EAAE,MAAM,GAAG,UAAU,EAC3B,GAAG,CAAC,EAAE,UAAU,GACf,UAAU,CAaZ"}
@@ -4,27 +4,28 @@ exports.seal = seal;
4
4
  exports.open = open;
5
5
  const chacha_js_1 = require("@noble/ciphers/chacha.js");
6
6
  const utils_js_1 = require("@noble/ciphers/utils.js");
7
+ const errors_1 = require("../errors");
8
+ const encoding_1 = require("../encoding");
7
9
  const NONCE_LEN = 24;
8
10
  const KEY_LEN = 32;
9
11
  const TAG_LEN = 16;
10
- const HEX_RE = /^[0-9a-fA-F]*$/;
11
12
  function toKey(key) {
12
13
  if (key instanceof Uint8Array) {
13
14
  if (key.length !== KEY_LEN) {
14
- throw new Error(`Key must be ${KEY_LEN} bytes, got ${key.length}`);
15
+ throw new errors_1.CryptoError(`Key must be ${KEY_LEN} bytes, got ${key.length}`, errors_1.CryptoErrorCode.INVALID_KEY);
15
16
  }
16
17
  return key;
17
18
  }
18
- if (!HEX_RE.test(key))
19
- throw new Error("Invalid hex key");
20
- const buf = Buffer.from(key, "hex");
19
+ if (!(0, encoding_1.isHex)(key))
20
+ throw new errors_1.CryptoError("Invalid hex key", errors_1.CryptoErrorCode.INVALID_HEX);
21
+ const buf = (0, encoding_1.decodeHex)(key);
21
22
  if (buf.length !== KEY_LEN) {
22
- throw new Error(`Key must be ${KEY_LEN} bytes (${KEY_LEN * 8} bits), got ${buf.length}`);
23
+ throw new errors_1.CryptoError(`Key must be ${KEY_LEN} bytes (${KEY_LEN * 8} bits), got ${buf.length}`, errors_1.CryptoErrorCode.INVALID_KEY);
23
24
  }
24
25
  return buf;
25
26
  }
26
27
  function toData(input) {
27
- return input instanceof Uint8Array ? input : Buffer.from(input, "utf8");
28
+ return input instanceof Uint8Array ? input : (0, encoding_1.utf8)(input);
28
29
  }
29
30
  function seal(key, plaintext, aad) {
30
31
  const k = toKey(key);
@@ -36,15 +37,15 @@ function seal(key, plaintext, aad) {
36
37
  out.set(nonce);
37
38
  out.set(ct, NONCE_LEN);
38
39
  return {
39
- sealed: Buffer.from(out).toString("base64"),
40
+ sealed: (0, encoding_1.toBase64)(out),
40
41
  algorithm: "xchacha20-poly1305",
41
42
  };
42
43
  }
43
44
  function open(key, sealed, aad) {
44
45
  const k = toKey(key);
45
- const raw = sealed instanceof Uint8Array ? sealed : Buffer.from(sealed, "base64");
46
+ const raw = sealed instanceof Uint8Array ? sealed : (0, encoding_1.fromBase64)(sealed);
46
47
  if (raw.length < NONCE_LEN + TAG_LEN) {
47
- throw new Error("Sealed box too short — missing nonce or auth tag");
48
+ throw new errors_1.CryptoError("Sealed box too short — missing nonce or auth tag", errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
48
49
  }
49
50
  const nonce = raw.subarray(0, NONCE_LEN);
50
51
  const ct = raw.subarray(NONCE_LEN);
package/dist/index.d.ts CHANGED
@@ -11,6 +11,6 @@ export { crypto } from "./crypto";
11
11
  export type { SignAlgorithm, VerifyPasswordOptions, HmacVerifyOptions, } from "./crypto";
12
12
  export { getAlgorithm, listAlgorithms, recommended, isDeprecated, } from "./registry";
13
13
  export type { AlgorithmInfo, AlgorithmCategory, AlgorithmStatus, SecurityLevel, } from "./registry";
14
- export { CryptoError, CryptoErrorCode } from "./errors";
14
+ export { CryptoError, CryptoErrorCode, OpaqueErrorCode, isCallerErrorCode, } from "./errors";
15
15
  export { timingSafeEqual, SecureBuffer, wipeMemory } from "./utils";
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
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,EACL,WAAW,EACX,eAAe,EACf,eAAe,EACf,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
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;
39
+ exports.wipeMemory = exports.SecureBuffer = exports.timingSafeEqual = exports.isCallerErrorCode = exports.OpaqueErrorCode = exports.CryptoErrorCode = exports.CryptoError = exports.isDeprecated = exports.recommended = exports.listAlgorithms = exports.getAlgorithm = exports.crypto = exports.tokens = exports.protocols = exports.pgp = void 0;
40
40
  exports.pgp = __importStar(require("./bin/cryptolib"));
41
41
  __exportStar(require("./modern"), exports);
42
42
  __exportStar(require("./high-level"), exports);
@@ -56,6 +56,8 @@ Object.defineProperty(exports, "isDeprecated", { enumerable: true, get: function
56
56
  var errors_1 = require("./errors");
57
57
  Object.defineProperty(exports, "CryptoError", { enumerable: true, get: function () { return errors_1.CryptoError; } });
58
58
  Object.defineProperty(exports, "CryptoErrorCode", { enumerable: true, get: function () { return errors_1.CryptoErrorCode; } });
59
+ Object.defineProperty(exports, "OpaqueErrorCode", { enumerable: true, get: function () { return errors_1.OpaqueErrorCode; } });
60
+ Object.defineProperty(exports, "isCallerErrorCode", { enumerable: true, get: function () { return errors_1.isCallerErrorCode; } });
59
61
  var utils_1 = require("./utils");
60
62
  Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: function () { return utils_1.timingSafeEqual; } });
61
63
  Object.defineProperty(exports, "SecureBuffer", { enumerable: true, get: function () { return utils_1.SecureBuffer; } });
@@ -1 +1 @@
1
- {"version":3,"file":"keystore.d.ts","sourceRoot":"","sources":["../../src/key/keystore.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,MAAM,WAAW,QAAQ;IAEvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAOD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU/C;AAyBD,wBAAgB,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgB5D;AAKD,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAaD,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAG7B"}
1
+ {"version":3,"file":"keystore.d.ts","sourceRoot":"","sources":["../../src/key/keystore.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,MAAM,WAAW,QAAQ;IAEvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAOD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU/C;AA0BD,wBAAgB,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgB5D;AAKD,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAaD,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAG7B"}
@@ -40,6 +40,7 @@ exports.unlockPrivateKey = unlockPrivateKey;
40
40
  const promises_1 = require("fs/promises");
41
41
  const path = __importStar(require("path"));
42
42
  const openpgp = __importStar(require("openpgp"));
43
+ const errors_1 = require("../errors");
43
44
  const ARMOR_BEGIN = Buffer.from("-----", "ascii");
44
45
  function decodeArmor(raw) {
45
46
  if (raw.length >= ARMOR_BEGIN.length &&
@@ -55,7 +56,7 @@ function resolveKeyDir(dir) {
55
56
  if (process.env["CRYPTO_KEY_DIR"])
56
57
  return process.env["CRYPTO_KEY_DIR"];
57
58
  if (process.env["NODE_ENV"] === "production") {
58
- throw new Error("CRYPTO_KEY_DIR is not set; refusing to use the bundled test keys in production");
59
+ throw new errors_1.CryptoError("CRYPTO_KEY_DIR is not set; refusing to use the bundled test keys in production", errors_1.CryptoErrorCode.CONFIGURATION);
59
60
  }
60
61
  return path.resolve(__dirname, "..", "key");
61
62
  }
@@ -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;AAsDD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,YAAY,EACvB,QAAQ,GAAE,WAAgB,GACzB,gBAAgB,CAiBlB"}
1
+ {"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/keys/keygen.ts"],"names":[],"mappings":"AA0BA,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;AAiDD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,YAAY,EACvB,QAAQ,GAAE,WAAgB,GACzB,gBAAgB,CAkBlB"}
@@ -5,11 +5,13 @@ exports.generateKeyPair = generateKeyPair;
5
5
  const ed25519_js_1 = require("@noble/curves/ed25519.js");
6
6
  const ed448_js_1 = require("@noble/curves/ed448.js");
7
7
  const nist_js_1 = require("@noble/curves/nist.js");
8
- const ml_kem_js_1 = require("@noble/post-quantum/ml-kem.js");
9
- const ml_dsa_js_1 = require("@noble/post-quantum/ml-dsa.js");
8
+ const pq_backend_1 = require("../accel/pq-backend");
9
+ const pq_backend_2 = require("../accel/pq-backend");
10
10
  const utils_js_1 = require("@noble/ciphers/utils.js");
11
11
  const sha2_js_1 = require("@noble/hashes/sha2.js");
12
12
  const serialize_1 = require("./serialize");
13
+ const errors_1 = require("../errors");
14
+ const encoding_1 = require("../encoding");
13
15
  exports.KEY_ALGORITHMS = [
14
16
  "ed25519",
15
17
  "x25519",
@@ -24,9 +26,6 @@ exports.KEY_ALGORITHMS = [
24
26
  "ml-dsa-65",
25
27
  "ml-dsa-87",
26
28
  ];
27
- function toHex(bytes) {
28
- return Buffer.from(bytes).toString("hex");
29
- }
30
29
  function generateKid(publicKey) {
31
30
  const digest = (0, sha2_js_1.sha256)(publicKey);
32
31
  return (0, serialize_1.bytesToBase64url)(digest.subarray(0, 16));
@@ -40,22 +39,22 @@ const KEYGEN = {
40
39
  x448: () => fromSecret((0, utils_js_1.randomBytes)(56), ed448_js_1.x448.getPublicKey),
41
40
  p256: () => fromSecret(nist_js_1.p256.utils.randomSecretKey(), nist_js_1.p256.getPublicKey),
42
41
  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()),
42
+ "ml-kem-512": () => fromPq(pq_backend_1.ml_kem512.keygen()),
43
+ "ml-kem-768": () => fromPq(pq_backend_1.ml_kem768.keygen()),
44
+ "ml-kem-1024": () => fromPq(pq_backend_1.ml_kem1024.keygen()),
45
+ "ml-dsa-44": () => fromPq(pq_backend_2.ml_dsa44.keygen()),
46
+ "ml-dsa-65": () => fromPq(pq_backend_2.ml_dsa65.keygen()),
47
+ "ml-dsa-87": () => fromPq(pq_backend_2.ml_dsa87.keygen()),
49
48
  };
50
49
  function generateKeyPair(algorithm, metadata = {}) {
51
50
  if (!Object.hasOwn(KEYGEN, algorithm)) {
52
- throw new Error(`Unsupported algorithm: ${algorithm}. Supported: ${exports.KEY_ALGORITHMS.join(", ")}`);
51
+ throw new errors_1.CryptoError(`Unsupported algorithm: ${algorithm}. Supported: ${exports.KEY_ALGORITHMS.join(", ")}`, errors_1.CryptoErrorCode.UNSUPPORTED_ALGORITHM);
53
52
  }
54
53
  const { publicKey, privateKey } = KEYGEN[algorithm]();
55
54
  const kid = metadata.kid ?? generateKid(publicKey);
56
55
  return {
57
- publicKey: toHex(publicKey),
58
- privateKey: toHex(privateKey),
56
+ publicKey: (0, encoding_1.toHex)(publicKey),
57
+ privateKey: (0, encoding_1.toHex)(privateKey),
59
58
  algorithm,
60
59
  kid,
61
60
  metadata: { ...metadata, kid },
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,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;QACpB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,GAAG,QAAQ,EAAE;IAsBd,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;IAoB7B,MAAM,IAAI,IAAI;IA2Bd,SAAS,IAAI,MAAM;IAOnB,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAczC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;IAY7C,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;CAK3E"}
@@ -37,6 +37,8 @@ exports.Keyring = void 0;
37
37
  const keygen_1 = require("./keygen");
38
38
  const serialize_1 = require("./serialize");
39
39
  const secretbox = __importStar(require("../high-level/secretbox"));
40
+ const errors_1 = require("../errors");
41
+ const encoding_1 = require("../encoding");
40
42
  class Keyring {
41
43
  keys = new Map();
42
44
  get size() {
@@ -82,7 +84,7 @@ class Keyring {
82
84
  rotate(kid) {
83
85
  const old = this.keys.get(kid);
84
86
  if (!old)
85
- throw new Error(`Key not found: ${kid}`);
87
+ throw new errors_1.CryptoError(`Key not found: ${kid}`, errors_1.CryptoErrorCode.INVALID_KEY);
86
88
  old.archived = true;
87
89
  return this.add(old.algorithm, {
88
90
  use: old.use,
@@ -128,7 +130,7 @@ class Keyring {
128
130
  }
129
131
  static fromEncrypted(key, encrypted) {
130
132
  const decrypted = secretbox.open(key, encrypted);
131
- const json = Buffer.from(decrypted).toString("utf8");
133
+ const json = (0, encoding_1.fromUtf8)(decrypted);
132
134
  return Keyring.deserialize(json);
133
135
  }
134
136
  }
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/keys/serialize.ts"],"names":[],"mappings":"AAiBA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAIlD;AAGD,w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GAAG,OAAO,CAAC;CACxB;AAKD,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,GAAG,CAYL;AAKD,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,GAAG,CAY7E;AAKD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG;IAElC,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAcA;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAa9C"}
@@ -13,32 +13,34 @@ exports.x25519ToJwk = x25519ToJwk;
13
13
  exports.jwkToHex = jwkToHex;
14
14
  exports.jwkThumbprint = jwkThumbprint;
15
15
  const sha2_js_1 = require("@noble/hashes/sha2.js");
16
+ const errors_1 = require("../errors");
17
+ const encoding_1 = require("../encoding");
16
18
  function hexToBytes(hex) {
17
19
  if (!/^[0-9a-fA-F]*$/.test(hex))
18
- throw new Error("Invalid hex string");
20
+ throw new errors_1.CryptoError("Invalid hex string", errors_1.CryptoErrorCode.INVALID_HEX);
19
21
  if (hex.length % 2 !== 0)
20
- throw new Error("Hex string must have even length");
21
- return Buffer.from(hex, "hex");
22
+ throw new errors_1.CryptoError("Hex string must have even length", errors_1.CryptoErrorCode.INVALID_HEX);
23
+ return (0, encoding_1.decodeHex)(hex);
22
24
  }
23
25
  function bytesToHex(bytes) {
24
- return Buffer.from(bytes).toString("hex");
26
+ return (0, encoding_1.toHex)(bytes);
25
27
  }
26
28
  function bytesToBase64(bytes) {
27
- return Buffer.from(bytes).toString("base64");
29
+ return (0, encoding_1.toBase64)(bytes);
28
30
  }
29
31
  function base64ToBytes(b64) {
30
- return Buffer.from(b64, "base64");
32
+ return (0, encoding_1.fromBase64)(b64);
31
33
  }
32
34
  function bytesToBase64url(bytes) {
33
- return Buffer.from(bytes).toString("base64url");
35
+ return (0, encoding_1.toBase64url)(bytes);
34
36
  }
35
37
  function base64urlToBytes(b64url) {
36
38
  const b64 = b64url.replace(/-/g, "+").replace(/_/g, "/");
37
39
  const pad = (4 - (b64.length % 4)) % 4;
38
- return Buffer.from(b64 + "=".repeat(pad), "base64");
40
+ return (0, encoding_1.fromBase64)(b64 + "=".repeat(pad));
39
41
  }
40
42
  function encodePem(label, der) {
41
- const b64 = Buffer.from(der).toString("base64");
43
+ const b64 = (0, encoding_1.toBase64)(der);
42
44
  const lines = [];
43
45
  for (let i = 0; i < b64.length; i += 64) {
44
46
  lines.push(b64.slice(i, i + 64));
@@ -50,19 +52,19 @@ function decodePem(pem) {
50
52
  const endMarker = "-----END ";
51
53
  const beginIdx = pem.indexOf(beginMarker);
52
54
  if (beginIdx === -1)
53
- throw new Error("Invalid PEM format");
55
+ throw new errors_1.CryptoError("Invalid PEM format", errors_1.CryptoErrorCode.INVALID_INPUT);
54
56
  const headerEnd = pem.indexOf("-----", beginIdx + beginMarker.length);
55
57
  if (headerEnd === -1)
56
- throw new Error("Invalid PEM format");
58
+ throw new errors_1.CryptoError("Invalid PEM format", errors_1.CryptoErrorCode.INVALID_INPUT);
57
59
  const label = pem.slice(beginIdx + beginMarker.length, headerEnd).trim();
58
60
  if (!label)
59
- throw new Error("Invalid PEM format");
61
+ throw new errors_1.CryptoError("Invalid PEM format", errors_1.CryptoErrorCode.INVALID_INPUT);
60
62
  const closeTag = `${endMarker}${label}-----`;
61
63
  const endIdx = pem.indexOf(closeTag, headerEnd + 5);
62
64
  if (endIdx === -1)
63
- throw new Error("Invalid PEM format");
65
+ throw new errors_1.CryptoError("Invalid PEM format", errors_1.CryptoErrorCode.INVALID_INPUT);
64
66
  const b64 = pem.slice(headerEnd + 5, endIdx).replace(/\s/g, "");
65
- return { label, data: Buffer.from(b64, "base64") };
67
+ return { label, data: (0, encoding_1.fromBase64)(b64) };
66
68
  }
67
69
  function ed25519ToJwk(publicKeyHex, privateKeyHex) {
68
70
  const pub = hexToBytes(publicKeyHex);
@@ -92,7 +94,7 @@ function x25519ToJwk(publicKeyHex, privateKeyHex) {
92
94
  }
93
95
  function jwkToHex(jwk) {
94
96
  if (!jwk.x)
95
- throw new Error("JWK missing 'x' (public key) field");
97
+ throw new errors_1.CryptoError("JWK missing 'x' (public key) field", errors_1.CryptoErrorCode.INVALID_KEY);
96
98
  const pub = base64urlToBytes(jwk.x);
97
99
  const result = {
98
100
  publicKey: bytesToHex(pub),
@@ -114,7 +116,7 @@ function jwkThumbprint(jwk) {
114
116
  members = { kty: jwk.kty };
115
117
  }
116
118
  const json = JSON.stringify(members, Object.keys(members).sort());
117
- const digest = (0, sha2_js_1.sha256)(Buffer.from(json, "utf8"));
119
+ const digest = (0, sha2_js_1.sha256)((0, encoding_1.utf8)(json));
118
120
  return bytesToBase64url(digest);
119
121
  }
120
122
  //# sourceMappingURL=serialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../src/lib/decrypt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AA0BxC,eAAO,MAAM,OAAO,GAClB,MAAM,KAAK,CAAC,WAAW,KACtB,OAAO,CAAC;IAET,IAAI,EAAE,MAAM,CAAC;IAEb,cAAc,EAAE,OAAO,CAAC;CACzB,CA8CA,CAAC;AAGF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../src/lib/decrypt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AA2BxC,eAAO,MAAM,OAAO,GAClB,MAAM,KAAK,CAAC,WAAW,KACtB,OAAO,CAAC;IAET,IAAI,EAAE,MAAM,CAAC;IAEb,cAAc,EAAE,OAAO,CAAC;CACzB,CAiDA,CAAC;AAGF,eAAe,OAAO,CAAC"}
@@ -36,10 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.decrypt = void 0;
37
37
  const openpgp = __importStar(require("openpgp"));
38
38
  const keystore_1 = require("../key/keystore");
39
+ const errors_1 = require("../errors");
39
40
  const decrypt = async (data) => {
40
41
  const { message: encryptedMessage, passphrase, publicKey: publicKeyBase64, privateKey: privateKeyBase64, } = data;
41
42
  if (!privateKeyBase64) {
42
- throw new Error("Private key is required for decryption");
43
+ throw new errors_1.CryptoError("Private key is required for decryption", errors_1.CryptoErrorCode.INVALID_KEY);
43
44
  }
44
45
  const message = await openpgp.readMessage({
45
46
  armoredMessage: Buffer.from(encryptedMessage, "base64").toString("latin1"),
@@ -1,4 +1,5 @@
1
+ import { type KeyOutputOptions } from "./key-output";
1
2
  import * as types from "../types/types";
2
- export declare function generate(data: types.dataGenerate): Promise<object>;
3
+ export declare function generate(data: types.dataGenerate, output?: KeyOutputOptions): Promise<object>;
3
4
  export default generate;
4
5
  //# sourceMappingURL=generate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/lib/generate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AA2DxC,wBAAsB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAkCxE;AAGD,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/lib/generate.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAmExC,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,KAAK,CAAC,YAAY,EACxB,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAwCjB;AAGD,eAAe,QAAQ,CAAC"}
@@ -37,24 +37,25 @@ exports.generate = generate;
37
37
  const path = __importStar(require("path"));
38
38
  const openpgp = __importStar(require("openpgp"));
39
39
  const key_output_1 = require("./key-output");
40
+ const errors_1 = require("../errors");
40
41
  function validateGenerateInput(data) {
41
42
  const rsaBits = Number(data.rsaBits);
42
43
  if (!Number.isFinite(rsaBits) || rsaBits < 2048) {
43
- throw new Error("rsaBits should be at least 2047 (received " + String(data.rsaBits) + ")");
44
+ throw new errors_1.CryptoError("rsaBits should be at least 2047 (received " + String(data.rsaBits) + ")", errors_1.CryptoErrorCode.INVALID_INPUT);
44
45
  }
45
46
  const keyExpirationTime = Number(data.keyExpirationTime);
46
47
  if (!Number.isFinite(keyExpirationTime) || keyExpirationTime < 0) {
47
- throw new Error("keyExpirationTime must be a non-negative number of seconds");
48
+ throw new errors_1.CryptoError("keyExpirationTime must be a non-negative number of seconds", errors_1.CryptoErrorCode.INVALID_INPUT);
48
49
  }
49
50
  if (data.type) {
50
51
  const safeType = path.basename(data.type);
51
52
  if (safeType !== data.type || safeType.includes("..")) {
52
- throw new Error("Invalid key type: must not contain path separators");
53
+ throw new errors_1.CryptoError("Invalid key type: must not contain path separators", errors_1.CryptoErrorCode.INVALID_INPUT);
53
54
  }
54
55
  }
55
56
  return { rsaBits, keyExpirationTime };
56
57
  }
57
- async function generate(data) {
58
+ async function generate(data, output = {}) {
58
59
  const { rsaBits, keyExpirationTime } = validateGenerateInput(data);
59
60
  const options = {
60
61
  date: new Date(),
@@ -68,7 +69,7 @@ async function generate(data) {
68
69
  };
69
70
  const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey(options);
70
71
  if (!data.type) {
71
- throw new Error("No key type specified");
72
+ throw new errors_1.CryptoError("No key type specified", errors_1.CryptoErrorCode.INVALID_INPUT);
72
73
  }
73
74
  const publicKeyString = typeof publicKey === "string" ? publicKey : publicKey.armor();
74
75
  const privateKeyString = typeof privateKey === "string" ? privateKey : privateKey.armor();
@@ -77,7 +78,7 @@ async function generate(data) {
77
78
  { name: `${base}.pub`, content: publicKeyString, secret: false },
78
79
  { name: `${base}.key`, content: privateKeyString, secret: true },
79
80
  { name: `${base}.cert`, content: revocationCertificate, secret: false },
80
- ]);
81
+ ], output);
81
82
  return { publicKey, privateKey, revocationCertificate };
82
83
  }
83
84
  exports.default = generate;
@@ -1,7 +1,10 @@
1
+ export interface KeyOutputOptions {
2
+ persist?: boolean;
3
+ }
1
4
  export interface KeyOutputFile {
2
5
  name: string;
3
6
  content: string;
4
7
  secret: boolean;
5
8
  }
6
- export declare function writeKeyOutputs(files: KeyOutputFile[]): Promise<void>;
9
+ export declare function writeKeyOutputs(files: KeyOutputFile[], options?: KeyOutputOptions): Promise<void>;
7
10
  //# sourceMappingURL=key-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"key-output.d.ts","sourceRoot":"","sources":["../../src/lib/key-output.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,aAAa;IAE5B,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,OAAO,CAAC;CACjB;AAUD,wBAAsB,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3E"}
1
+ {"version":3,"file":"key-output.d.ts","sourceRoot":"","sources":["../../src/lib/key-output.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAM/B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAGD,MAAM,WAAW,aAAa;IAE5B,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,OAAO,CAAC;CACjB;AAUD,wBAAsB,eAAe,CACnC,KAAK,EAAE,aAAa,EAAE,EACtB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAYf"}
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.writeKeyOutputs = writeKeyOutputs;
37
37
  const promises_1 = require("fs/promises");
38
38
  const path = __importStar(require("path"));
39
- async function writeKeyOutputs(files) {
39
+ async function writeKeyOutputs(files, options = {}) {
40
40
  const dir = process.env["CRYPTO_KEY_OUT_DIR"];
41
- if (!dir)
41
+ if (!dir || options.persist === false)
42
42
  return;
43
43
  await Promise.all(files.map(async (f) => {
44
44
  const target = path.join(dir, path.basename(f.name));