@sebastienrousseau/crypto-lib 0.0.3 → 0.0.8

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 (253) hide show
  1. package/README.md +304 -314
  2. package/dist/accel/index.d.ts +11 -0
  3. package/dist/accel/index.d.ts.map +1 -0
  4. package/dist/accel/index.js +31 -0
  5. package/dist/accel/native-pqc-bridge.d.ts +18 -0
  6. package/dist/accel/native-pqc-bridge.d.ts.map +1 -0
  7. package/dist/accel/native-pqc-bridge.js +100 -0
  8. package/dist/accel/wasm-bridge.d.ts +35 -0
  9. package/dist/accel/wasm-bridge.d.ts.map +1 -0
  10. package/dist/accel/wasm-bridge.js +161 -0
  11. package/dist/accel/webcrypto-bridge.d.ts +32 -0
  12. package/dist/accel/webcrypto-bridge.d.ts.map +1 -0
  13. package/dist/accel/webcrypto-bridge.js +179 -0
  14. package/dist/accel/webcrypto-modern.d.ts +40 -0
  15. package/dist/accel/webcrypto-modern.d.ts.map +1 -0
  16. package/dist/accel/webcrypto-modern.js +213 -0
  17. package/dist/accel/worker-pool.d.ts +23 -0
  18. package/dist/accel/worker-pool.d.ts.map +1 -0
  19. package/dist/accel/worker-pool.js +119 -0
  20. package/dist/bin/cryptolib.d.ts +9 -7
  21. package/dist/bin/cryptolib.d.ts.map +1 -1
  22. package/dist/bin/cryptolib.js +25 -16
  23. package/dist/config/config.d.ts.map +1 -1
  24. package/dist/crypto.d.ts +43 -0
  25. package/dist/crypto.d.ts.map +1 -0
  26. package/dist/crypto.js +107 -0
  27. package/dist/enums.d.ts +29 -29
  28. package/dist/enums.d.ts.map +1 -1
  29. package/dist/enums.js +54 -54
  30. package/dist/errors.d.ts +14 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +22 -0
  33. package/dist/high-level/index.d.ts +11 -0
  34. package/dist/high-level/index.d.ts.map +1 -0
  35. package/dist/high-level/index.js +53 -0
  36. package/dist/high-level/key-wrap.d.ts +16 -0
  37. package/dist/high-level/key-wrap.d.ts.map +1 -0
  38. package/dist/high-level/key-wrap.js +93 -0
  39. package/dist/high-level/multi-recipient.d.ts +25 -0
  40. package/dist/high-level/multi-recipient.d.ts.map +1 -0
  41. package/dist/high-level/multi-recipient.js +122 -0
  42. package/dist/high-level/password-encrypt.d.ts +14 -0
  43. package/dist/high-level/password-encrypt.d.ts.map +1 -0
  44. package/dist/high-level/password-encrypt.js +93 -0
  45. package/dist/high-level/sealedbox.d.ts +13 -0
  46. package/dist/high-level/sealedbox.d.ts.map +1 -0
  47. package/dist/high-level/sealedbox.js +119 -0
  48. package/dist/high-level/secretbox.d.ts +7 -0
  49. package/dist/high-level/secretbox.d.ts.map +1 -0
  50. package/dist/high-level/secretbox.js +54 -0
  51. package/dist/index.d.ts +14 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +59 -0
  54. package/dist/key/key.d.ts +6 -13
  55. package/dist/key/key.d.ts.map +1 -1
  56. package/dist/key/key.js +20 -14
  57. package/dist/key/keystore.d.ts +11 -0
  58. package/dist/key/keystore.d.ts.map +1 -0
  59. package/dist/key/keystore.js +87 -0
  60. package/dist/keys/index.d.ts +7 -0
  61. package/dist/keys/index.d.ts.map +1 -0
  62. package/dist/keys/index.js +22 -0
  63. package/dist/keys/keygen.d.ts +16 -0
  64. package/dist/keys/keygen.d.ts.map +1 -0
  65. package/dist/keys/keygen.js +128 -0
  66. package/dist/keys/keyring.d.ts +35 -0
  67. package/dist/keys/keyring.d.ts.map +1 -0
  68. package/dist/keys/keyring.js +136 -0
  69. package/dist/keys/serialize.d.ts +30 -0
  70. package/dist/keys/serialize.d.ts.map +1 -0
  71. package/dist/keys/serialize.js +120 -0
  72. package/dist/lib/decrypt.d.ts +4 -1
  73. package/dist/lib/decrypt.d.ts.map +1 -1
  74. package/dist/lib/decrypt.js +43 -51
  75. package/dist/lib/encrypt.d.ts +1 -1
  76. package/dist/lib/encrypt.d.ts.map +1 -1
  77. package/dist/lib/encrypt.js +29 -45
  78. package/dist/lib/generate.d.ts.map +1 -1
  79. package/dist/lib/generate.js +56 -63
  80. package/dist/lib/index.d.ts.map +1 -1
  81. package/dist/lib/index.js +17 -7
  82. package/dist/lib/key-output.d.ts +7 -0
  83. package/dist/lib/key-output.d.ts.map +1 -0
  84. package/dist/lib/key-output.js +50 -0
  85. package/dist/lib/reformat.d.ts +6 -1
  86. package/dist/lib/reformat.d.ts.map +1 -1
  87. package/dist/lib/reformat.js +37 -61
  88. package/dist/lib/revoke.d.ts +2 -2
  89. package/dist/lib/revoke.d.ts.map +1 -1
  90. package/dist/lib/revoke.js +33 -50
  91. package/dist/lib/session.d.ts.map +1 -1
  92. package/dist/lib/session.js +21 -36
  93. package/dist/lib/sign.d.ts.map +1 -1
  94. package/dist/lib/sign.js +36 -43
  95. package/dist/lib/verify.d.ts +1 -3
  96. package/dist/lib/verify.d.ts.map +1 -1
  97. package/dist/lib/verify.js +25 -30
  98. package/dist/modern/aead.d.ts +17 -0
  99. package/dist/modern/aead.d.ts.map +1 -0
  100. package/dist/modern/aead.js +51 -0
  101. package/dist/modern/aes.d.ts +35 -0
  102. package/dist/modern/aes.d.ts.map +1 -0
  103. package/dist/modern/aes.js +82 -0
  104. package/dist/modern/cost-limits.d.ts +11 -0
  105. package/dist/modern/cost-limits.d.ts.map +1 -0
  106. package/dist/modern/cost-limits.js +35 -0
  107. package/dist/modern/curves.d.ts +86 -0
  108. package/dist/modern/curves.d.ts.map +1 -0
  109. package/dist/modern/curves.js +171 -0
  110. package/dist/modern/ecdh.d.ts +11 -0
  111. package/dist/modern/ecdh.d.ts.map +1 -0
  112. package/dist/modern/ecdh.js +28 -0
  113. package/dist/modern/fn-dsa.d.ts +19 -0
  114. package/dist/modern/fn-dsa.d.ts.map +1 -0
  115. package/dist/modern/fn-dsa.js +57 -0
  116. package/dist/modern/hash.d.ts +13 -0
  117. package/dist/modern/hash.d.ts.map +1 -0
  118. package/dist/modern/hash.js +45 -0
  119. package/dist/modern/hpke.d.ts +47 -0
  120. package/dist/modern/hpke.d.ts.map +1 -0
  121. package/dist/modern/hpke.js +207 -0
  122. package/dist/modern/index.d.ts +40 -0
  123. package/dist/modern/index.d.ts.map +1 -0
  124. package/dist/modern/index.js +194 -0
  125. package/dist/modern/kdf.d.ts +23 -0
  126. package/dist/modern/kdf.d.ts.map +1 -0
  127. package/dist/modern/kdf.js +67 -0
  128. package/dist/modern/mac.d.ts +51 -0
  129. package/dist/modern/mac.d.ts.map +1 -0
  130. package/dist/modern/mac.js +119 -0
  131. package/dist/modern/password.d.ts +40 -0
  132. package/dist/modern/password.d.ts.map +1 -0
  133. package/dist/modern/password.js +123 -0
  134. package/dist/modern/pq-hash-sign.d.ts +18 -0
  135. package/dist/modern/pq-hash-sign.d.ts.map +1 -0
  136. package/dist/modern/pq-hash-sign.js +73 -0
  137. package/dist/modern/pq-kem.d.ts +88 -0
  138. package/dist/modern/pq-kem.d.ts.map +1 -0
  139. package/dist/modern/pq-kem.js +270 -0
  140. package/dist/modern/pq-sign.d.ts +30 -0
  141. package/dist/modern/pq-sign.d.ts.map +1 -0
  142. package/dist/modern/pq-sign.js +94 -0
  143. package/dist/modern/pq.d.ts +38 -0
  144. package/dist/modern/pq.d.ts.map +1 -0
  145. package/dist/modern/pq.js +80 -0
  146. package/dist/modern/signing.d.ts +16 -0
  147. package/dist/modern/signing.d.ts.map +1 -0
  148. package/dist/modern/signing.js +34 -0
  149. package/dist/protocols/index.d.ts +7 -0
  150. package/dist/protocols/index.d.ts.map +1 -0
  151. package/dist/protocols/index.js +46 -0
  152. package/dist/protocols/iso20022.d.ts +51 -0
  153. package/dist/protocols/iso20022.d.ts.map +1 -0
  154. package/dist/protocols/iso20022.js +145 -0
  155. package/dist/protocols/opaque/ake.d.ts +51 -0
  156. package/dist/protocols/opaque/ake.d.ts.map +1 -0
  157. package/dist/protocols/opaque/ake.js +102 -0
  158. package/dist/protocols/opaque/client.d.ts +45 -0
  159. package/dist/protocols/opaque/client.d.ts.map +1 -0
  160. package/dist/protocols/opaque/client.js +63 -0
  161. package/dist/protocols/opaque/config.d.ts +14 -0
  162. package/dist/protocols/opaque/config.d.ts.map +1 -0
  163. package/dist/protocols/opaque/config.js +18 -0
  164. package/dist/protocols/opaque/credentials.d.ts +29 -0
  165. package/dist/protocols/opaque/credentials.d.ts.map +1 -0
  166. package/dist/protocols/opaque/credentials.js +61 -0
  167. package/dist/protocols/opaque/envelope.d.ts +36 -0
  168. package/dist/protocols/opaque/envelope.d.ts.map +1 -0
  169. package/dist/protocols/opaque/envelope.js +77 -0
  170. package/dist/protocols/opaque/ksf.d.ts +15 -0
  171. package/dist/protocols/opaque/ksf.d.ts.map +1 -0
  172. package/dist/protocols/opaque/ksf.js +27 -0
  173. package/dist/protocols/opaque/messages.d.ts +61 -0
  174. package/dist/protocols/opaque/messages.d.ts.map +1 -0
  175. package/dist/protocols/opaque/messages.js +94 -0
  176. package/dist/protocols/opaque/server.d.ts +33 -0
  177. package/dist/protocols/opaque/server.d.ts.map +1 -0
  178. package/dist/protocols/opaque/server.js +74 -0
  179. package/dist/protocols/opaque/suite.d.ts +58 -0
  180. package/dist/protocols/opaque/suite.d.ts.map +1 -0
  181. package/dist/protocols/opaque/suite.js +115 -0
  182. package/dist/protocols/pake.d.ts +14 -0
  183. package/dist/protocols/pake.d.ts.map +1 -0
  184. package/dist/protocols/pake.js +33 -0
  185. package/dist/protocols/pqxdh.d.ts +53 -0
  186. package/dist/protocols/pqxdh.d.ts.map +1 -0
  187. package/dist/protocols/pqxdh.js +143 -0
  188. package/dist/protocols/ratchet.d.ts +52 -0
  189. package/dist/protocols/ratchet.d.ts.map +1 -0
  190. package/dist/protocols/ratchet.js +187 -0
  191. package/dist/protocols/threshold.d.ts +23 -0
  192. package/dist/protocols/threshold.d.ts.map +1 -0
  193. package/dist/protocols/threshold.js +191 -0
  194. package/dist/registry.d.ts +20 -0
  195. package/dist/registry.d.ts.map +1 -0
  196. package/dist/registry.js +399 -0
  197. package/dist/streaming/index.d.ts +7 -0
  198. package/dist/streaming/index.d.ts.map +1 -0
  199. package/dist/streaming/index.js +15 -0
  200. package/dist/streaming/stream-aead.d.ts +17 -0
  201. package/dist/streaming/stream-aead.d.ts.map +1 -0
  202. package/dist/streaming/stream-aead.js +125 -0
  203. package/dist/streaming/stream-hash.d.ts +9 -0
  204. package/dist/streaming/stream-hash.d.ts.map +1 -0
  205. package/dist/streaming/stream-hash.js +52 -0
  206. package/dist/streaming/web-streams.d.ts +17 -0
  207. package/dist/streaming/web-streams.d.ts.map +1 -0
  208. package/dist/streaming/web-streams.js +114 -0
  209. package/dist/tokens/index.d.ts +5 -0
  210. package/dist/tokens/index.d.ts.map +1 -0
  211. package/dist/tokens/index.js +15 -0
  212. package/dist/tokens/key-rotation.d.ts +20 -0
  213. package/dist/tokens/key-rotation.d.ts.map +1 -0
  214. package/dist/tokens/key-rotation.js +76 -0
  215. package/dist/tokens/paseto.d.ts +46 -0
  216. package/dist/tokens/paseto.d.ts.map +1 -0
  217. package/dist/tokens/paseto.js +200 -0
  218. package/dist/types/types.d.ts +24 -16
  219. package/dist/types/types.d.ts.map +1 -1
  220. package/dist/utils.d.ts +13 -0
  221. package/dist/utils.d.ts.map +1 -0
  222. package/dist/utils.js +56 -0
  223. package/package.json +77 -142
  224. package/dist/COPYRIGHT +0 -15
  225. package/dist/Report.txt +0 -160
  226. package/dist/bin/cryptolib.js.map +0 -1
  227. package/dist/config/config.js.map +0 -1
  228. package/dist/data/decrypted.txt +0 -1
  229. package/dist/data/detached.sig +0 -1
  230. package/dist/data/encrypted.txt +0 -1
  231. package/dist/data/signed.sig +0 -1
  232. package/dist/enums.js.map +0 -1
  233. package/dist/index.js.map +0 -1
  234. package/dist/key/key.js.map +0 -1
  235. package/dist/key/rsa-reformat.cert +0 -1
  236. package/dist/key/rsa-reformat.key +0 -1
  237. package/dist/key/rsa-reformat.pub +0 -1
  238. package/dist/key/rsa-revoke.key +0 -1
  239. package/dist/key/rsa-revoke.pub +0 -1
  240. package/dist/key/rsa.cert +0 -1
  241. package/dist/key/rsa.key +0 -1
  242. package/dist/key/rsa.pub +0 -1
  243. package/dist/lib/decrypt.js.map +0 -1
  244. package/dist/lib/encrypt.js.map +0 -1
  245. package/dist/lib/generate.js.map +0 -1
  246. package/dist/lib/index.js.map +0 -1
  247. package/dist/lib/reformat.js.map +0 -1
  248. package/dist/lib/revoke.js.map +0 -1
  249. package/dist/lib/session.js.map +0 -1
  250. package/dist/lib/sign.js.map +0 -1
  251. package/dist/lib/verify.js.map +0 -1
  252. package/dist/package.json +0 -143
  253. package/dist/types/types.js.map +0 -1
package/dist/enums.d.ts CHANGED
@@ -17,55 +17,55 @@ declare const _default: {
17
17
  keySize6144: number;
18
18
  keySize7680: number;
19
19
  keySize8192: number;
20
- keySize1536: number;
20
+ keySize15360: number;
21
21
  };
22
22
  curve: {
23
23
  p256: string;
24
- 'P-256': string;
24
+ "P-256": string;
25
25
  secp256r1: string;
26
26
  prime256v1: string;
27
- '1.2.840.10045.3.1.7': string;
27
+ "1.2.840.10045.3.1.7": string;
28
28
  p384: string;
29
- 'P-384': string;
29
+ "P-384": string;
30
30
  secp384r1: string;
31
- '1.3.132.0.34': string;
32
- '2b81040022': string;
33
- '2B81040022': string;
31
+ "1.3.132.0.34": string;
32
+ "2b81040022": string;
33
+ "2B81040022": string;
34
34
  p521: string;
35
- 'P-521': string;
35
+ "P-521": string;
36
36
  secp521r1: string;
37
- '1.3.132.0.35': string;
38
- '2b81040023': string;
39
- '2B81040023': string;
37
+ "1.3.132.0.35": string;
38
+ "2b81040023": string;
39
+ "2B81040023": string;
40
40
  secp256k1: string;
41
- '1.3.132.0.10': string;
42
- '2b8104000a': string;
43
- '2B8104000A': string;
41
+ "1.3.132.0.10": string;
42
+ "2b8104000a": string;
43
+ "2B8104000A": string;
44
44
  ED25519: string;
45
45
  ed25519: string;
46
46
  Ed25519: string;
47
- '1.3.6.1.4.1.11591.15.1': string;
48
- '2b06010401da470f01': string;
49
- '2B06010401DA470F01': string;
47
+ "1.3.6.1.4.1.11591.15.1": string;
48
+ "2b06010401da470f01": string;
49
+ "2B06010401DA470F01": string;
50
50
  X25519: string;
51
51
  cv25519: string;
52
52
  curve25519: string;
53
53
  Curve25519: string;
54
- '1.3.6.1.4.1.3029.1.5.1': string;
55
- '2b060104019755010501': string;
56
- '2B060104019755010501': string;
54
+ "1.3.6.1.4.1.3029.1.5.1": string;
55
+ "2b060104019755010501": string;
56
+ "2B060104019755010501": string;
57
57
  brainpoolP256r1: string;
58
- '1.3.36.3.3.2.8.1.1.7': string;
59
- '2b2403030208010107': string;
60
- '2B2403030208010107': string;
58
+ "1.3.36.3.3.2.8.1.1.7": string;
59
+ "2b2403030208010107": string;
60
+ "2B2403030208010107": string;
61
61
  brainpoolP384r1: string;
62
- '1.3.36.3.3.2.8.1.1.11': string;
63
- '2b240303020801010b': string;
64
- '2B240303020801010B': string;
62
+ "1.3.36.3.3.2.8.1.1.11": string;
63
+ "2b240303020801010b": string;
64
+ "2B240303020801010B": string;
65
65
  brainpoolP512r1: string;
66
- '1.3.36.3.3.2.8.1.1.13': string;
67
- '2b240303020801010d': string;
68
- '2B240303020801010D': string;
66
+ "1.3.36.3.3.2.8.1.1.13": string;
67
+ "2b240303020801010d": string;
68
+ "2B240303020801010D": string;
69
69
  };
70
70
  type: {
71
71
  ecc: string;
@@ -1 +1 @@
1
- {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA2LC"}
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBA2OE"}
package/dist/enums.js CHANGED
@@ -8,7 +8,7 @@ exports.default = {
8
8
  sha256: 8,
9
9
  sha384: 9,
10
10
  sha512: 10,
11
- sha224: 11
11
+ sha224: 11,
12
12
  },
13
13
  size: {
14
14
  keySize512: 512,
@@ -19,64 +19,64 @@ exports.default = {
19
19
  keySize6144: 6144,
20
20
  keySize7680: 7680,
21
21
  keySize8192: 8192,
22
- keySize1536: 15360,
22
+ keySize15360: 15360,
23
23
  },
24
24
  curve: {
25
- 'p256': 'p256',
26
- 'P-256': 'p256',
27
- 'secp256r1': 'p256',
28
- 'prime256v1': 'p256',
29
- '1.2.840.10045.3.1.7': 'p256',
30
- 'p384': 'p384',
31
- 'P-384': 'p384',
32
- 'secp384r1': 'p384',
33
- '1.3.132.0.34': 'p384',
34
- '2b81040022': 'p384',
35
- '2B81040022': 'p384',
36
- 'p521': 'p521',
37
- 'P-521': 'p521',
38
- 'secp521r1': 'p521',
39
- '1.3.132.0.35': 'p521',
40
- '2b81040023': 'p521',
41
- '2B81040023': 'p521',
42
- 'secp256k1': 'secp256k1',
43
- '1.3.132.0.10': 'secp256k1',
44
- '2b8104000a': 'secp256k1',
45
- '2B8104000A': 'secp256k1',
46
- 'ED25519': 'ed25519',
47
- 'ed25519': 'ed25519',
48
- 'Ed25519': 'ed25519',
49
- '1.3.6.1.4.1.11591.15.1': 'ed25519',
50
- '2b06010401da470f01': 'ed25519',
51
- '2B06010401DA470F01': 'ed25519',
52
- 'X25519': 'curve25519',
53
- 'cv25519': 'curve25519',
54
- 'curve25519': 'curve25519',
55
- 'Curve25519': 'curve25519',
56
- '1.3.6.1.4.1.3029.1.5.1': 'curve25519',
57
- '2b060104019755010501': 'curve25519',
58
- '2B060104019755010501': 'curve25519',
59
- 'brainpoolP256r1': 'brainpoolP256r1',
60
- '1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1',
61
- '2b2403030208010107': 'brainpoolP256r1',
62
- '2B2403030208010107': 'brainpoolP256r1',
63
- 'brainpoolP384r1': 'brainpoolP384r1',
64
- '1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1',
65
- '2b240303020801010b': 'brainpoolP384r1',
66
- '2B240303020801010B': 'brainpoolP384r1',
67
- 'brainpoolP512r1': 'brainpoolP512r1',
68
- '1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1',
69
- '2b240303020801010d': 'brainpoolP512r1',
70
- '2B240303020801010D': 'brainpoolP512r1'
25
+ p256: "p256",
26
+ "P-256": "p256",
27
+ secp256r1: "p256",
28
+ prime256v1: "p256",
29
+ "1.2.840.10045.3.1.7": "p256",
30
+ p384: "p384",
31
+ "P-384": "p384",
32
+ secp384r1: "p384",
33
+ "1.3.132.0.34": "p384",
34
+ "2b81040022": "p384",
35
+ "2B81040022": "p384",
36
+ p521: "p521",
37
+ "P-521": "p521",
38
+ secp521r1: "p521",
39
+ "1.3.132.0.35": "p521",
40
+ "2b81040023": "p521",
41
+ "2B81040023": "p521",
42
+ secp256k1: "secp256k1",
43
+ "1.3.132.0.10": "secp256k1",
44
+ "2b8104000a": "secp256k1",
45
+ "2B8104000A": "secp256k1",
46
+ ED25519: "ed25519",
47
+ ed25519: "ed25519",
48
+ Ed25519: "ed25519",
49
+ "1.3.6.1.4.1.11591.15.1": "ed25519",
50
+ "2b06010401da470f01": "ed25519",
51
+ "2B06010401DA470F01": "ed25519",
52
+ X25519: "curve25519",
53
+ cv25519: "curve25519",
54
+ curve25519: "curve25519",
55
+ Curve25519: "curve25519",
56
+ "1.3.6.1.4.1.3029.1.5.1": "curve25519",
57
+ "2b060104019755010501": "curve25519",
58
+ "2B060104019755010501": "curve25519",
59
+ brainpoolP256r1: "brainpoolP256r1",
60
+ "1.3.36.3.3.2.8.1.1.7": "brainpoolP256r1",
61
+ "2b2403030208010107": "brainpoolP256r1",
62
+ "2B2403030208010107": "brainpoolP256r1",
63
+ brainpoolP384r1: "brainpoolP384r1",
64
+ "1.3.36.3.3.2.8.1.1.11": "brainpoolP384r1",
65
+ "2b240303020801010b": "brainpoolP384r1",
66
+ "2B240303020801010B": "brainpoolP384r1",
67
+ brainpoolP512r1: "brainpoolP512r1",
68
+ "1.3.36.3.3.2.8.1.1.13": "brainpoolP512r1",
69
+ "2b240303020801010d": "brainpoolP512r1",
70
+ "2B240303020801010D": "brainpoolP512r1",
71
71
  },
72
72
  type: {
73
- ecc: 'ecc',
74
- rsa: 'rsa',
73
+ ecc: "ecc",
74
+ rsa: "rsa",
75
75
  },
76
76
  format: {
77
- armored: 'armored',
78
- binary: 'binary',
79
- object: 'object',
80
- }
77
+ armored: "armored",
78
+ binary: "binary",
79
+ object: "object",
80
+ },
81
81
  };
82
82
  //# sourceMappingURL=enums.js.map
@@ -0,0 +1,14 @@
1
+ export declare class CryptoError extends Error {
2
+ readonly code: string;
3
+ constructor(message: string, code: string);
4
+ }
5
+ export declare const CryptoErrorCode: {
6
+ readonly INVALID_KEY: "INVALID_KEY";
7
+ readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
8
+ readonly INVALID_HEX: "INVALID_HEX";
9
+ readonly INVALID_CIPHERTEXT: "INVALID_CIPHERTEXT";
10
+ readonly AUTH_FAILED: "AUTH_FAILED";
11
+ readonly BUFFER_DESTROYED: "BUFFER_DESTROYED";
12
+ readonly INVALID_INPUT: "INVALID_INPUT";
13
+ };
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAwBA,qBAAa,WAAY,SAAQ,KAAK;IAEpC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAajB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAK1C;AAGD,eAAO,MAAM,eAAe;;;;;;;;CAelB,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoErrorCode = exports.CryptoError = void 0;
4
+ class CryptoError extends Error {
5
+ code;
6
+ constructor(message, code) {
7
+ super(message);
8
+ this.name = "CryptoError";
9
+ this.code = code;
10
+ }
11
+ }
12
+ exports.CryptoError = CryptoError;
13
+ exports.CryptoErrorCode = {
14
+ INVALID_KEY: "INVALID_KEY",
15
+ UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM",
16
+ INVALID_HEX: "INVALID_HEX",
17
+ INVALID_CIPHERTEXT: "INVALID_CIPHERTEXT",
18
+ AUTH_FAILED: "AUTH_FAILED",
19
+ BUFFER_DESTROYED: "BUFFER_DESTROYED",
20
+ INVALID_INPUT: "INVALID_INPUT",
21
+ };
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,11 @@
1
+ export * as secretbox from "./secretbox";
2
+ export type { SecretboxResult } from "./secretbox";
3
+ export * as sealedbox from "./sealedbox";
4
+ export type { SealedBoxResult, PqSealedBoxResult } from "./sealedbox";
5
+ export { passwordEncrypt, passwordDecrypt } from "./password-encrypt";
6
+ export type { PasswordEncryptOptions, PasswordEncryptResult, } from "./password-encrypt";
7
+ export { aesKwWrap, aesKwUnwrap, aesKwpWrap, aesKwpUnwrap, x25519AesKwWrap, x25519AesKwUnwrap, } from "./key-wrap";
8
+ export type { AesKwWrapResult, X25519AesKwWrapResult } from "./key-wrap";
9
+ export { multiEncrypt, multiDecryptClassical, multiDecryptPQ, } from "./multi-recipient";
10
+ export type { ClassicalRecipient, PqRecipient, Recipient, WrappedKey, MultiRecipientEncryptResult, } from "./multi-recipient";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
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;
37
+ exports.secretbox = __importStar(require("./secretbox"));
38
+ exports.sealedbox = __importStar(require("./sealedbox"));
39
+ var password_encrypt_1 = require("./password-encrypt");
40
+ Object.defineProperty(exports, "passwordEncrypt", { enumerable: true, get: function () { return password_encrypt_1.passwordEncrypt; } });
41
+ Object.defineProperty(exports, "passwordDecrypt", { enumerable: true, get: function () { return password_encrypt_1.passwordDecrypt; } });
42
+ var key_wrap_1 = require("./key-wrap");
43
+ Object.defineProperty(exports, "aesKwWrap", { enumerable: true, get: function () { return key_wrap_1.aesKwWrap; } });
44
+ Object.defineProperty(exports, "aesKwUnwrap", { enumerable: true, get: function () { return key_wrap_1.aesKwUnwrap; } });
45
+ Object.defineProperty(exports, "aesKwpWrap", { enumerable: true, get: function () { return key_wrap_1.aesKwpWrap; } });
46
+ Object.defineProperty(exports, "aesKwpUnwrap", { enumerable: true, get: function () { return key_wrap_1.aesKwpUnwrap; } });
47
+ Object.defineProperty(exports, "x25519AesKwWrap", { enumerable: true, get: function () { return key_wrap_1.x25519AesKwWrap; } });
48
+ Object.defineProperty(exports, "x25519AesKwUnwrap", { enumerable: true, get: function () { return key_wrap_1.x25519AesKwUnwrap; } });
49
+ var multi_recipient_1 = require("./multi-recipient");
50
+ Object.defineProperty(exports, "multiEncrypt", { enumerable: true, get: function () { return multi_recipient_1.multiEncrypt; } });
51
+ Object.defineProperty(exports, "multiDecryptClassical", { enumerable: true, get: function () { return multi_recipient_1.multiDecryptClassical; } });
52
+ Object.defineProperty(exports, "multiDecryptPQ", { enumerable: true, get: function () { return multi_recipient_1.multiDecryptPQ; } });
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ export interface AesKwWrapResult {
2
+ wrapped: string;
3
+ algorithm: "aes-kw" | "aes-kwp";
4
+ }
5
+ export interface X25519AesKwWrapResult {
6
+ wrapped: string;
7
+ ephemeralPublicKey: string;
8
+ algorithm: "x25519-aes-kw";
9
+ }
10
+ export declare function aesKwWrap(kek: string | Uint8Array, keyToWrap: string | Uint8Array): AesKwWrapResult;
11
+ export declare function aesKwUnwrap(kek: string | Uint8Array, wrappedKey: string | Uint8Array): Uint8Array;
12
+ export declare function aesKwpWrap(kek: string | Uint8Array, data: string | Uint8Array): AesKwWrapResult;
13
+ export declare function aesKwpUnwrap(kek: string | Uint8Array, wrappedData: string | Uint8Array): Uint8Array;
14
+ export declare function x25519AesKwWrap(recipientPublicKey: string | Uint8Array, keyToWrap: string | Uint8Array): X25519AesKwWrapResult;
15
+ export declare function x25519AesKwUnwrap(recipientSecretKey: string | Uint8Array, ephemeralPublicKey: string | Uint8Array, wrappedKey: string | Uint8Array): Uint8Array;
16
+ //# sourceMappingURL=key-wrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-wrap.d.ts","sourceRoot":"","sources":["../../src/high-level/key-wrap.ts"],"names":[],"mappings":"AAuCA,MAAM,WAAW,eAAe;IAE9B,OAAO,EAAE,MAAM,CAAC;IAEhB,SAAS,EAAE,QAAQ,GAAG,SAAS,CAAC;CACjC;AAGD,MAAM,WAAW,qBAAqB;IAEpC,OAAO,EAAE,MAAM,CAAC;IAEhB,kBAAkB,EAAE,MAAM,CAAC;IAE3B,SAAS,EAAE,eAAe,CAAC;CAC5B;AAUD,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,eAAe,CASjB;AAQD,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,UAAU,EAAE,MAAM,GAAG,UAAU,GAC9B,UAAU,CAQZ;AAUD,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,IAAI,EAAE,MAAM,GAAG,UAAU,GACxB,eAAe,CASjB;AAQD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,UAAU,EACxB,WAAW,EAAE,MAAM,GAAG,UAAU,GAC/B,UAAU,CAQZ;AAcD,wBAAgB,eAAe,CAC7B,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,qBAAqB,CA0BvB;AASD,wBAAgB,iBAAiB,CAC/B,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,kBAAkB,EAAE,MAAM,GAAG,UAAU,EACvC,UAAU,EAAE,MAAM,GAAG,UAAU,GAC9B,UAAU,CA0BZ"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.aesKwWrap = aesKwWrap;
4
+ exports.aesKwUnwrap = aesKwUnwrap;
5
+ exports.aesKwpWrap = aesKwpWrap;
6
+ exports.aesKwpUnwrap = aesKwpUnwrap;
7
+ exports.x25519AesKwWrap = x25519AesKwWrap;
8
+ exports.x25519AesKwUnwrap = x25519AesKwUnwrap;
9
+ const aes_js_1 = require("@noble/ciphers/aes.js");
10
+ const ed25519_js_1 = require("@noble/curves/ed25519.js");
11
+ const hkdf_js_1 = require("@noble/hashes/hkdf.js");
12
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
13
+ const utils_js_1 = require("@noble/ciphers/utils.js");
14
+ const HEX_RE = /^[0-9a-fA-F]*$/;
15
+ function hexToBytes(hex) {
16
+ if (!HEX_RE.test(hex))
17
+ throw new Error("Invalid hex string");
18
+ return Buffer.from(hex, "hex");
19
+ }
20
+ function toKey(key) {
21
+ if (key instanceof Uint8Array)
22
+ return key;
23
+ return hexToBytes(key);
24
+ }
25
+ function aesKwWrap(kek, keyToWrap) {
26
+ const kekBytes = toKey(kek);
27
+ const keyBytes = toKey(keyToWrap);
28
+ const cipher = (0, aes_js_1.aeskw)(kekBytes);
29
+ const wrapped = cipher.encrypt(keyBytes);
30
+ return {
31
+ wrapped: Buffer.from(wrapped).toString("base64"),
32
+ algorithm: "aes-kw",
33
+ };
34
+ }
35
+ function aesKwUnwrap(kek, wrappedKey) {
36
+ const kekBytes = toKey(kek);
37
+ const wrapped = wrappedKey instanceof Uint8Array
38
+ ? wrappedKey
39
+ : Buffer.from(wrappedKey, "base64");
40
+ const cipher = (0, aes_js_1.aeskw)(kekBytes);
41
+ return cipher.decrypt(wrapped);
42
+ }
43
+ function aesKwpWrap(kek, data) {
44
+ const kekBytes = toKey(kek);
45
+ const dataBytes = toKey(data);
46
+ const cipher = (0, aes_js_1.aeskwp)(kekBytes);
47
+ const wrapped = cipher.encrypt(dataBytes);
48
+ return {
49
+ wrapped: Buffer.from(wrapped).toString("base64"),
50
+ algorithm: "aes-kwp",
51
+ };
52
+ }
53
+ function aesKwpUnwrap(kek, wrappedData) {
54
+ const kekBytes = toKey(kek);
55
+ const wrapped = wrappedData instanceof Uint8Array
56
+ ? wrappedData
57
+ : Buffer.from(wrappedData, "base64");
58
+ const cipher = (0, aes_js_1.aeskwp)(kekBytes);
59
+ return cipher.decrypt(wrapped);
60
+ }
61
+ function x25519AesKwWrap(recipientPublicKey, keyToWrap) {
62
+ const recipPub = typeof recipientPublicKey === "string"
63
+ ? hexToBytes(recipientPublicKey)
64
+ : recipientPublicKey;
65
+ const keyBytes = toKey(keyToWrap);
66
+ const ephPriv = (0, utils_js_1.randomBytes)(32);
67
+ const ephPub = ed25519_js_1.x25519.getPublicKey(ephPriv);
68
+ const raw = ed25519_js_1.x25519.getSharedSecret(ephPriv, recipPub);
69
+ const kek = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, raw, ephPub, new TextEncoder().encode("x25519-aes-kw-v1"), 32);
70
+ const cipher = (0, aes_js_1.aeskw)(kek);
71
+ const wrapped = cipher.encrypt(keyBytes);
72
+ return {
73
+ wrapped: Buffer.from(wrapped).toString("base64"),
74
+ ephemeralPublicKey: Buffer.from(ephPub).toString("hex"),
75
+ algorithm: "x25519-aes-kw",
76
+ };
77
+ }
78
+ function x25519AesKwUnwrap(recipientSecretKey, ephemeralPublicKey, wrappedKey) {
79
+ const secKey = typeof recipientSecretKey === "string"
80
+ ? hexToBytes(recipientSecretKey)
81
+ : recipientSecretKey;
82
+ const ephPub = typeof ephemeralPublicKey === "string"
83
+ ? hexToBytes(ephemeralPublicKey)
84
+ : ephemeralPublicKey;
85
+ const wrapped = wrappedKey instanceof Uint8Array
86
+ ? wrappedKey
87
+ : Buffer.from(wrappedKey, "base64");
88
+ const raw = ed25519_js_1.x25519.getSharedSecret(secKey, ephPub);
89
+ const kek = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, raw, ephPub, new TextEncoder().encode("x25519-aes-kw-v1"), 32);
90
+ const cipher = (0, aes_js_1.aeskw)(kek);
91
+ return cipher.decrypt(wrapped);
92
+ }
93
+ //# sourceMappingURL=key-wrap.js.map
@@ -0,0 +1,25 @@
1
+ export interface ClassicalRecipient {
2
+ type: "x25519";
3
+ publicKey: string;
4
+ }
5
+ export interface PqRecipient {
6
+ type: "x25519-ml-kem-768";
7
+ x25519PublicKey: string;
8
+ mlKemPublicKey: string;
9
+ }
10
+ export type Recipient = ClassicalRecipient | PqRecipient;
11
+ export interface WrappedKey {
12
+ type: "x25519" | "x25519-ml-kem-768";
13
+ wrappedKey: string;
14
+ ephemeralPublicKey: string;
15
+ mlKemCiphertext?: string;
16
+ }
17
+ export interface MultiRecipientEncryptResult {
18
+ ciphertext: string;
19
+ recipients: WrappedKey[];
20
+ algorithm: "multi-recipient-secretbox";
21
+ }
22
+ export declare function multiEncrypt(recipients: Recipient[], plaintext: string | Uint8Array): MultiRecipientEncryptResult;
23
+ export declare function multiDecryptClassical(secretKey: string | Uint8Array, wrappedKey: WrappedKey, ciphertext: string): Uint8Array;
24
+ export declare function multiDecryptPQ(x25519SecretKey: string | Uint8Array, mlKemSecretKey: string | Uint8Array, wrappedKey: WrappedKey, ciphertext: string): Uint8Array;
25
+ //# sourceMappingURL=multi-recipient.d.ts.map
@@ -0,0 +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,MAAM,CAAC;CAC1B;AAGD,MAAM,WAAW,2BAA2B;IAE1C,UAAU,EAAE,MAAM,CAAC;IAEnB,UAAU,EAAE,UAAU,EAAE,CAAC;IAEzB,SAAS,EAAE,2BAA2B,CAAC;CACxC;AAQD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,EAAE,EACvB,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,2BAA2B,CAgE7B;AASD,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,GACjB,UAAU,CAOZ;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,CAuCZ"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.multiEncrypt = multiEncrypt;
37
+ exports.multiDecryptClassical = multiDecryptClassical;
38
+ exports.multiDecryptPQ = multiDecryptPQ;
39
+ const utils_js_1 = require("@noble/ciphers/utils.js");
40
+ const secretbox = __importStar(require("./secretbox"));
41
+ const key_wrap_1 = require("./key-wrap");
42
+ const ed25519_js_1 = require("@noble/curves/ed25519.js");
43
+ const ml_kem_js_1 = require("@noble/post-quantum/ml-kem.js");
44
+ const aes_js_1 = require("@noble/ciphers/aes.js");
45
+ const hkdf_js_1 = require("@noble/hashes/hkdf.js");
46
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
47
+ const HEX_RE = /^[0-9a-fA-F]*$/;
48
+ function hexToBytes(hex) {
49
+ if (!HEX_RE.test(hex))
50
+ throw new Error("Invalid hex string");
51
+ return Buffer.from(hex, "hex");
52
+ }
53
+ function multiEncrypt(recipients, plaintext) {
54
+ if (recipients.length === 0) {
55
+ throw new Error("At least one recipient is required");
56
+ }
57
+ const dek = (0, utils_js_1.randomBytes)(32);
58
+ const sealed = secretbox.seal(dek, plaintext);
59
+ const wrappedKeys = recipients.map((r) => {
60
+ if (r.type === "x25519") {
61
+ const result = (0, key_wrap_1.x25519AesKwWrap)(r.publicKey, dek);
62
+ return {
63
+ type: "x25519",
64
+ wrappedKey: result.wrapped,
65
+ ephemeralPublicKey: result.ephemeralPublicKey,
66
+ };
67
+ }
68
+ 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);
81
+ return {
82
+ 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"),
86
+ };
87
+ }
88
+ });
89
+ return {
90
+ ciphertext: sealed.sealed,
91
+ recipients: wrappedKeys,
92
+ algorithm: "multi-recipient-secretbox",
93
+ };
94
+ }
95
+ function multiDecryptClassical(secretKey, wrappedKey, ciphertext) {
96
+ const dek = (0, key_wrap_1.x25519AesKwUnwrap)(secretKey, wrappedKey.ephemeralPublicKey, wrappedKey.wrappedKey);
97
+ return secretbox.open(dek, ciphertext);
98
+ }
99
+ function multiDecryptPQ(x25519SecretKey, mlKemSecretKey, wrappedKey, ciphertext) {
100
+ const x25519Sec = typeof x25519SecretKey === "string"
101
+ ? hexToBytes(x25519SecretKey)
102
+ : x25519SecretKey;
103
+ const mlKemSec = typeof mlKemSecretKey === "string"
104
+ ? hexToBytes(mlKemSecretKey)
105
+ : 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);
111
+ const x25519Shared = ed25519_js_1.x25519.getSharedSecret(x25519Sec, ephPub);
112
+ const mlKemShared = ml_kem_js_1.ml_kem768.decapsulate(mlKemCt, mlKemSec);
113
+ const combined = new Uint8Array(x25519Shared.length + mlKemShared.length);
114
+ combined.set(x25519Shared);
115
+ combined.set(mlKemShared, x25519Shared.length);
116
+ 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");
118
+ const cipher = (0, aes_js_1.aeskw)(kek);
119
+ const dek = cipher.decrypt(wrapped);
120
+ return secretbox.open(dek, ciphertext);
121
+ }
122
+ //# sourceMappingURL=multi-recipient.js.map
@@ -0,0 +1,14 @@
1
+ export interface PasswordEncryptOptions {
2
+ password: string | Uint8Array;
3
+ plaintext: string | Uint8Array;
4
+ timeCost?: number;
5
+ memoryCost?: number;
6
+ parallelism?: number;
7
+ }
8
+ export interface PasswordEncryptResult {
9
+ encrypted: string;
10
+ algorithm: "argon2id-xchacha20-poly1305";
11
+ }
12
+ export declare function passwordEncrypt(options: PasswordEncryptOptions): PasswordEncryptResult;
13
+ export declare function passwordDecrypt(password: string | Uint8Array, encrypted: string | Uint8Array): Uint8Array;
14
+ //# sourceMappingURL=password-encrypt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-encrypt.d.ts","sourceRoot":"","sources":["../../src/high-level/password-encrypt.ts"],"names":[],"mappings":"AAoDA,MAAM,WAAW,sBAAsB;IAErC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAE/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,WAAW,qBAAqB;IAEpC,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,6BAA6B,CAAC;CAC1C;AAsDD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,qBAAqB,CAwBvB;AAQD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,GAAG,UAAU,EAC7B,SAAS,EAAE,MAAM,GAAG,UAAU,GAC7B,UAAU,CA+BZ"}