@enbox/crypto 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +708 -0
  3. package/dist/browser.js +64 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/browser.mjs +64 -0
  6. package/dist/browser.mjs.map +7 -0
  7. package/dist/cjs/algorithms/aes-ctr.js +188 -0
  8. package/dist/cjs/algorithms/aes-ctr.js.map +1 -0
  9. package/dist/cjs/algorithms/aes-gcm.js +196 -0
  10. package/dist/cjs/algorithms/aes-gcm.js.map +1 -0
  11. package/dist/cjs/algorithms/crypto-algorithm.js +13 -0
  12. package/dist/cjs/algorithms/crypto-algorithm.js.map +1 -0
  13. package/dist/cjs/algorithms/ecdsa.js +352 -0
  14. package/dist/cjs/algorithms/ecdsa.js.map +1 -0
  15. package/dist/cjs/algorithms/eddsa.js +325 -0
  16. package/dist/cjs/algorithms/eddsa.js.map +1 -0
  17. package/dist/cjs/algorithms/sha-2.js +119 -0
  18. package/dist/cjs/algorithms/sha-2.js.map +1 -0
  19. package/dist/cjs/index.js +41 -0
  20. package/dist/cjs/index.js.map +1 -0
  21. package/dist/cjs/jose/jwe.js +3 -0
  22. package/dist/cjs/jose/jwe.js.map +1 -0
  23. package/dist/cjs/jose/jwk.js +278 -0
  24. package/dist/cjs/jose/jwk.js.map +1 -0
  25. package/dist/cjs/jose/jws.js +3 -0
  26. package/dist/cjs/jose/jws.js.map +1 -0
  27. package/dist/cjs/jose/jwt.js +3 -0
  28. package/dist/cjs/jose/jwt.js.map +1 -0
  29. package/dist/cjs/jose/utils.js +60 -0
  30. package/dist/cjs/jose/utils.js.map +1 -0
  31. package/dist/cjs/local-key-manager.js +521 -0
  32. package/dist/cjs/local-key-manager.js.map +1 -0
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/primitives/aes-ctr.js +398 -0
  35. package/dist/cjs/primitives/aes-ctr.js.map +1 -0
  36. package/dist/cjs/primitives/aes-gcm.js +425 -0
  37. package/dist/cjs/primitives/aes-gcm.js.map +1 -0
  38. package/dist/cjs/primitives/concat-kdf.js +215 -0
  39. package/dist/cjs/primitives/concat-kdf.js.map +1 -0
  40. package/dist/cjs/primitives/ed25519.js +651 -0
  41. package/dist/cjs/primitives/ed25519.js.map +1 -0
  42. package/dist/cjs/primitives/pbkdf2.js +120 -0
  43. package/dist/cjs/primitives/pbkdf2.js.map +1 -0
  44. package/dist/cjs/primitives/secp256k1.js +958 -0
  45. package/dist/cjs/primitives/secp256k1.js.map +1 -0
  46. package/dist/cjs/primitives/secp256r1.js +959 -0
  47. package/dist/cjs/primitives/secp256r1.js.map +1 -0
  48. package/dist/cjs/primitives/sha256.js +93 -0
  49. package/dist/cjs/primitives/sha256.js.map +1 -0
  50. package/dist/cjs/primitives/x25519.js +498 -0
  51. package/dist/cjs/primitives/x25519.js.map +1 -0
  52. package/dist/cjs/primitives/xchacha20-poly1305.js +340 -0
  53. package/dist/cjs/primitives/xchacha20-poly1305.js.map +1 -0
  54. package/dist/cjs/primitives/xchacha20.js +316 -0
  55. package/dist/cjs/primitives/xchacha20.js.map +1 -0
  56. package/dist/cjs/types/cipher.js +3 -0
  57. package/dist/cjs/types/cipher.js.map +1 -0
  58. package/dist/cjs/types/crypto-api.js +3 -0
  59. package/dist/cjs/types/crypto-api.js.map +1 -0
  60. package/dist/cjs/types/hasher.js +3 -0
  61. package/dist/cjs/types/hasher.js.map +1 -0
  62. package/dist/cjs/types/identifier.js +3 -0
  63. package/dist/cjs/types/identifier.js.map +1 -0
  64. package/dist/cjs/types/key-compressor.js +3 -0
  65. package/dist/cjs/types/key-compressor.js.map +1 -0
  66. package/dist/cjs/types/key-converter.js +3 -0
  67. package/dist/cjs/types/key-converter.js.map +1 -0
  68. package/dist/cjs/types/key-deriver.js +3 -0
  69. package/dist/cjs/types/key-deriver.js.map +1 -0
  70. package/dist/cjs/types/key-generator.js +3 -0
  71. package/dist/cjs/types/key-generator.js.map +1 -0
  72. package/dist/cjs/types/key-io.js +3 -0
  73. package/dist/cjs/types/key-io.js.map +1 -0
  74. package/dist/cjs/types/key-wrapper.js +3 -0
  75. package/dist/cjs/types/key-wrapper.js.map +1 -0
  76. package/dist/cjs/types/params-direct.js +3 -0
  77. package/dist/cjs/types/params-direct.js.map +1 -0
  78. package/dist/cjs/types/params-enclosed.js +3 -0
  79. package/dist/cjs/types/params-enclosed.js.map +1 -0
  80. package/dist/cjs/types/params-kms.js +3 -0
  81. package/dist/cjs/types/params-kms.js.map +1 -0
  82. package/dist/cjs/types/signer.js +3 -0
  83. package/dist/cjs/types/signer.js.map +1 -0
  84. package/dist/cjs/utils.js +173 -0
  85. package/dist/cjs/utils.js.map +1 -0
  86. package/dist/esm/algorithms/aes-ctr.js +124 -0
  87. package/dist/esm/algorithms/aes-ctr.js.map +1 -0
  88. package/dist/esm/algorithms/aes-gcm.js +132 -0
  89. package/dist/esm/algorithms/aes-gcm.js.map +1 -0
  90. package/dist/esm/algorithms/crypto-algorithm.js +6 -0
  91. package/dist/esm/algorithms/crypto-algorithm.js.map +1 -0
  92. package/dist/esm/algorithms/ecdsa.js +237 -0
  93. package/dist/esm/algorithms/ecdsa.js.map +1 -0
  94. package/dist/esm/algorithms/eddsa.js +213 -0
  95. package/dist/esm/algorithms/eddsa.js.map +1 -0
  96. package/dist/esm/algorithms/sha-2.js +57 -0
  97. package/dist/esm/algorithms/sha-2.js.map +1 -0
  98. package/dist/esm/index.js +25 -0
  99. package/dist/esm/index.js.map +1 -0
  100. package/dist/esm/jose/jwe.js +2 -0
  101. package/dist/esm/jose/jwe.js.map +1 -0
  102. package/dist/esm/jose/jwk.js +241 -0
  103. package/dist/esm/jose/jwk.js.map +1 -0
  104. package/dist/esm/jose/jws.js +2 -0
  105. package/dist/esm/jose/jws.js.map +1 -0
  106. package/dist/esm/jose/jwt.js +2 -0
  107. package/dist/esm/jose/jwt.js.map +1 -0
  108. package/dist/esm/jose/utils.js +34 -0
  109. package/dist/esm/jose/utils.js.map +1 -0
  110. package/dist/esm/local-key-manager.js +417 -0
  111. package/dist/esm/local-key-manager.js.map +1 -0
  112. package/dist/esm/primitives/aes-ctr.js +327 -0
  113. package/dist/esm/primitives/aes-ctr.js.map +1 -0
  114. package/dist/esm/primitives/aes-gcm.js +347 -0
  115. package/dist/esm/primitives/aes-gcm.js.map +1 -0
  116. package/dist/esm/primitives/concat-kdf.js +185 -0
  117. package/dist/esm/primitives/concat-kdf.js.map +1 -0
  118. package/dist/esm/primitives/ed25519.js +521 -0
  119. package/dist/esm/primitives/ed25519.js.map +1 -0
  120. package/dist/esm/primitives/pbkdf2.js +78 -0
  121. package/dist/esm/primitives/pbkdf2.js.map +1 -0
  122. package/dist/esm/primitives/secp256k1.js +805 -0
  123. package/dist/esm/primitives/secp256k1.js.map +1 -0
  124. package/dist/esm/primitives/secp256r1.js +806 -0
  125. package/dist/esm/primitives/secp256r1.js.map +1 -0
  126. package/dist/esm/primitives/sha256.js +55 -0
  127. package/dist/esm/primitives/sha256.js.map +1 -0
  128. package/dist/esm/primitives/x25519.js +392 -0
  129. package/dist/esm/primitives/x25519.js.map +1 -0
  130. package/dist/esm/primitives/xchacha20-poly1305.js +270 -0
  131. package/dist/esm/primitives/xchacha20-poly1305.js.map +1 -0
  132. package/dist/esm/primitives/xchacha20.js +246 -0
  133. package/dist/esm/primitives/xchacha20.js.map +1 -0
  134. package/dist/esm/types/cipher.js +2 -0
  135. package/dist/esm/types/cipher.js.map +1 -0
  136. package/dist/esm/types/crypto-api.js +2 -0
  137. package/dist/esm/types/crypto-api.js.map +1 -0
  138. package/dist/esm/types/hasher.js +2 -0
  139. package/dist/esm/types/hasher.js.map +1 -0
  140. package/dist/esm/types/identifier.js +2 -0
  141. package/dist/esm/types/identifier.js.map +1 -0
  142. package/dist/esm/types/key-compressor.js +2 -0
  143. package/dist/esm/types/key-compressor.js.map +1 -0
  144. package/dist/esm/types/key-converter.js +2 -0
  145. package/dist/esm/types/key-converter.js.map +1 -0
  146. package/dist/esm/types/key-deriver.js +2 -0
  147. package/dist/esm/types/key-deriver.js.map +1 -0
  148. package/dist/esm/types/key-generator.js +2 -0
  149. package/dist/esm/types/key-generator.js.map +1 -0
  150. package/dist/esm/types/key-io.js +2 -0
  151. package/dist/esm/types/key-io.js.map +1 -0
  152. package/dist/esm/types/key-wrapper.js +2 -0
  153. package/dist/esm/types/key-wrapper.js.map +1 -0
  154. package/dist/esm/types/params-direct.js +2 -0
  155. package/dist/esm/types/params-direct.js.map +1 -0
  156. package/dist/esm/types/params-enclosed.js +2 -0
  157. package/dist/esm/types/params-enclosed.js.map +1 -0
  158. package/dist/esm/types/params-kms.js +2 -0
  159. package/dist/esm/types/params-kms.js.map +1 -0
  160. package/dist/esm/types/signer.js +2 -0
  161. package/dist/esm/types/signer.js.map +1 -0
  162. package/dist/esm/utils.js +165 -0
  163. package/dist/esm/utils.js.map +1 -0
  164. package/dist/types/algorithms/aes-ctr.d.ts +121 -0
  165. package/dist/types/algorithms/aes-ctr.d.ts.map +1 -0
  166. package/dist/types/algorithms/aes-gcm.d.ts +152 -0
  167. package/dist/types/algorithms/aes-gcm.d.ts.map +1 -0
  168. package/dist/types/algorithms/crypto-algorithm.d.ts +6 -0
  169. package/dist/types/algorithms/crypto-algorithm.d.ts.map +1 -0
  170. package/dist/types/algorithms/ecdsa.d.ts +154 -0
  171. package/dist/types/algorithms/ecdsa.d.ts.map +1 -0
  172. package/dist/types/algorithms/eddsa.d.ts +151 -0
  173. package/dist/types/algorithms/eddsa.d.ts.map +1 -0
  174. package/dist/types/algorithms/sha-2.d.ts +51 -0
  175. package/dist/types/algorithms/sha-2.d.ts.map +1 -0
  176. package/dist/types/index.d.ts +39 -0
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/jose/jwe.d.ts +135 -0
  179. package/dist/types/jose/jwe.d.ts.map +1 -0
  180. package/dist/types/jose/jwk.d.ts +439 -0
  181. package/dist/types/jose/jwk.d.ts.map +1 -0
  182. package/dist/types/jose/jws.d.ts +67 -0
  183. package/dist/types/jose/jws.d.ts.map +1 -0
  184. package/dist/types/jose/jwt.d.ts +139 -0
  185. package/dist/types/jose/jwt.d.ts.map +1 -0
  186. package/dist/types/jose/utils.d.ts +14 -0
  187. package/dist/types/jose/utils.d.ts.map +1 -0
  188. package/dist/types/local-key-manager.d.ts +307 -0
  189. package/dist/types/local-key-manager.d.ts.map +1 -0
  190. package/dist/types/primitives/aes-ctr.d.ts +219 -0
  191. package/dist/types/primitives/aes-ctr.d.ts.map +1 -0
  192. package/dist/types/primitives/aes-gcm.d.ts +245 -0
  193. package/dist/types/primitives/aes-gcm.d.ts.map +1 -0
  194. package/dist/types/primitives/concat-kdf.d.ts +160 -0
  195. package/dist/types/primitives/concat-kdf.d.ts.map +1 -0
  196. package/dist/types/primitives/ed25519.d.ts +359 -0
  197. package/dist/types/primitives/ed25519.d.ts.map +1 -0
  198. package/dist/types/primitives/pbkdf2.d.ts +94 -0
  199. package/dist/types/primitives/pbkdf2.d.ts.map +1 -0
  200. package/dist/types/primitives/secp256k1.d.ts +598 -0
  201. package/dist/types/primitives/secp256k1.d.ts.map +1 -0
  202. package/dist/types/primitives/secp256r1.d.ts +599 -0
  203. package/dist/types/primitives/secp256r1.d.ts.map +1 -0
  204. package/dist/types/primitives/sha256.d.ts +42 -0
  205. package/dist/types/primitives/sha256.d.ts.map +1 -0
  206. package/dist/types/primitives/x25519.d.ts +283 -0
  207. package/dist/types/primitives/x25519.d.ts.map +1 -0
  208. package/dist/types/primitives/xchacha20-poly1305.d.ts +210 -0
  209. package/dist/types/primitives/xchacha20-poly1305.d.ts.map +1 -0
  210. package/dist/types/primitives/xchacha20.d.ts +186 -0
  211. package/dist/types/primitives/xchacha20.d.ts.map +1 -0
  212. package/dist/types/types/cipher.d.ts +49 -0
  213. package/dist/types/types/cipher.d.ts.map +1 -0
  214. package/dist/types/types/crypto-api.d.ts +40 -0
  215. package/dist/types/types/crypto-api.d.ts.map +1 -0
  216. package/dist/types/types/hasher.d.ts +33 -0
  217. package/dist/types/types/hasher.d.ts.map +1 -0
  218. package/dist/types/types/identifier.d.ts +16 -0
  219. package/dist/types/types/identifier.d.ts.map +1 -0
  220. package/dist/types/types/key-compressor.d.ts +28 -0
  221. package/dist/types/types/key-compressor.d.ts.map +1 -0
  222. package/dist/types/types/key-converter.d.ts +57 -0
  223. package/dist/types/types/key-converter.d.ts.map +1 -0
  224. package/dist/types/types/key-deriver.d.ts +39 -0
  225. package/dist/types/types/key-deriver.d.ts.map +1 -0
  226. package/dist/types/types/key-generator.d.ts +105 -0
  227. package/dist/types/types/key-generator.d.ts.map +1 -0
  228. package/dist/types/types/key-io.d.ts +37 -0
  229. package/dist/types/types/key-io.d.ts.map +1 -0
  230. package/dist/types/types/key-wrapper.d.ts +38 -0
  231. package/dist/types/types/key-wrapper.d.ts.map +1 -0
  232. package/dist/types/types/params-direct.d.ts +90 -0
  233. package/dist/types/types/params-direct.d.ts.map +1 -0
  234. package/dist/types/types/params-enclosed.d.ts +47 -0
  235. package/dist/types/types/params-enclosed.d.ts.map +1 -0
  236. package/dist/types/types/params-kms.d.ts +131 -0
  237. package/dist/types/types/params-kms.d.ts.map +1 -0
  238. package/dist/types/types/signer.d.ts +46 -0
  239. package/dist/types/types/signer.d.ts.map +1 -0
  240. package/dist/types/utils.d.ts +112 -0
  241. package/dist/types/utils.d.ts.map +1 -0
  242. package/dist/utils.js +7 -0
  243. package/dist/utils.js.map +7 -0
  244. package/package.json +103 -0
  245. package/src/algorithms/aes-ctr.ts +156 -0
  246. package/src/algorithms/aes-gcm.ts +187 -0
  247. package/src/algorithms/crypto-algorithm.ts +4 -0
  248. package/src/algorithms/ecdsa.ts +269 -0
  249. package/src/algorithms/eddsa.ts +243 -0
  250. package/src/algorithms/sha-2.ts +65 -0
  251. package/src/index.ts +42 -0
  252. package/src/jose/jwe.ts +196 -0
  253. package/src/jose/jwk.ts +632 -0
  254. package/src/jose/jws.ts +95 -0
  255. package/src/jose/jwt.ts +147 -0
  256. package/src/jose/utils.ts +34 -0
  257. package/src/local-key-manager.ts +540 -0
  258. package/src/primitives/aes-ctr.ts +352 -0
  259. package/src/primitives/aes-gcm.ts +378 -0
  260. package/src/primitives/concat-kdf.ts +240 -0
  261. package/src/primitives/ed25519.ts +548 -0
  262. package/src/primitives/pbkdf2.ts +122 -0
  263. package/src/primitives/secp256k1.ts +848 -0
  264. package/src/primitives/secp256r1.ts +850 -0
  265. package/src/primitives/sha256.ts +47 -0
  266. package/src/primitives/x25519.ts +403 -0
  267. package/src/primitives/xchacha20-poly1305.ts +274 -0
  268. package/src/primitives/xchacha20.ts +247 -0
  269. package/src/types/cipher.ts +53 -0
  270. package/src/types/crypto-api.ts +56 -0
  271. package/src/types/hasher.ts +32 -0
  272. package/src/types/identifier.ts +16 -0
  273. package/src/types/key-compressor.ts +25 -0
  274. package/src/types/key-converter.ts +53 -0
  275. package/src/types/key-deriver.ts +43 -0
  276. package/src/types/key-generator.ts +119 -0
  277. package/src/types/key-io.ts +42 -0
  278. package/src/types/key-wrapper.ts +42 -0
  279. package/src/types/params-direct.ts +106 -0
  280. package/src/types/params-enclosed.ts +50 -0
  281. package/src/types/params-kms.ts +156 -0
  282. package/src/types/signer.ts +50 -0
  283. package/src/utils.ts +181 -0
@@ -0,0 +1,186 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ /**
3
+ * The `XChaCha20` class provides a comprehensive suite of utilities for cryptographic operations
4
+ * using the XChaCha20 symmetric encryption algorithm. This class includes methods for key
5
+ * generation, encryption, decryption, and conversions between raw byte arrays and JSON Web Key
6
+ * (JWK) formats. XChaCha20 is an extended nonce variant of ChaCha20, a stream cipher designed for
7
+ * high-speed encryption with substantial security margins.
8
+ *
9
+ * The XChaCha20 algorithm is particularly well-suited for encrypting large volumes of data or
10
+ * data streams, especially where random access is required. The class adheres to standard
11
+ * cryptographic practices, ensuring robustness and security in its implementations.
12
+ *
13
+ * Key Features:
14
+ * - Key Generation: Generate XChaCha20 symmetric keys in JWK format.
15
+ * - Key Conversion: Transform keys between raw byte arrays and JWK formats.
16
+ * - Encryption: Encrypt data using XChaCha20 with the provided symmetric key.
17
+ * - Decryption: Decrypt data encrypted with XChaCha20 using the corresponding symmetric key.
18
+ *
19
+ * The methods in this class are asynchronous, returning Promises to accommodate various
20
+ * JavaScript environments.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // Key Generation
25
+ * const privateKey = await XChaCha20.generateKey();
26
+ *
27
+ * // Encryption
28
+ * const data = new TextEncoder().encode('Messsage');
29
+ * const nonce = utils.randomBytes(24); // 24-byte nonce for XChaCha20
30
+ * const encryptedData = await XChaCha20.encrypt({
31
+ * data,
32
+ * nonce,
33
+ * key: privateKey
34
+ * });
35
+ *
36
+ * // Decryption
37
+ * const decryptedData = await XChaCha20.decrypt({
38
+ * data: encryptedData,
39
+ * nonce,
40
+ * key: privateKey
41
+ * });
42
+ *
43
+ * // Key Conversion
44
+ * const privateKeyBytes = await XChaCha20.privateKeyToBytes({ privateKey });
45
+ * ```
46
+ */
47
+ export declare class XChaCha20 {
48
+ /**
49
+ * Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
50
+ *
51
+ * @remarks
52
+ * This method takes a symmetric key represented as a byte array (Uint8Array) and
53
+ * converts it into a JWK object for use with the XChaCha20 symmetric encryption algorithm. The
54
+ * conversion process involves encoding the key into base64url format and setting the appropriate
55
+ * JWK parameters.
56
+ *
57
+ * The resulting JWK object includes the following properties:
58
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
59
+ * - `k`: The symmetric key, base64url-encoded.
60
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
65
+ * const privateKey = await XChaCha20.bytesToPrivateKey({ privateKeyBytes });
66
+ * ```
67
+ *
68
+ * @param params - The parameters for the symmetric key conversion.
69
+ * @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
70
+ *
71
+ * @returns A Promise that resolves to the symmetric key in JWK format.
72
+ */
73
+ static bytesToPrivateKey({ privateKeyBytes }: {
74
+ privateKeyBytes: Uint8Array;
75
+ }): Promise<Jwk>;
76
+ /**
77
+ * Decrypts the provided data using XChaCha20.
78
+ *
79
+ * @remarks
80
+ * This method performs XChaCha20 decryption on the given encrypted data using the specified key
81
+ * and nonce. The nonce should be the same as used in the encryption process and must be 24 bytes
82
+ * long. The method returns the decrypted data as a Uint8Array.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const encryptedData = new Uint8Array([...]); // Encrypted data
87
+ * const nonce = new Uint8Array(24); // 24-byte nonce used during encryption
88
+ * const key = { ... }; // A Jwk object representing the XChaCha20 key
89
+ * const decryptedData = await XChaCha20.decrypt({
90
+ * data: encryptedData,
91
+ * nonce,
92
+ * key
93
+ * });
94
+ * ```
95
+ *
96
+ * @param params - The parameters for the decryption operation.
97
+ * @param params.data - The encrypted data to decrypt, represented as a Uint8Array.
98
+ * @param params.key - The key to use for decryption, represented in JWK format.
99
+ * @param params.nonce - The nonce used during the encryption process.
100
+ *
101
+ * @returns A Promise that resolves to the decrypted data as a Uint8Array.
102
+ */
103
+ static decrypt({ data, key, nonce }: {
104
+ data: Uint8Array;
105
+ key: Jwk;
106
+ nonce: Uint8Array;
107
+ }): Promise<Uint8Array>;
108
+ /**
109
+ * Encrypts the provided data using XChaCha20.
110
+ *
111
+ * @remarks
112
+ * This method performs XChaCha20 encryption on the given data using the specified key and nonce.
113
+ * The nonce must be 24 bytes long, ensuring a high level of security through a vast nonce space,
114
+ * reducing the risks associated with nonce reuse. The method returns the encrypted data as a
115
+ * Uint8Array.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const data = new TextEncoder().encode('Messsage');
120
+ * const nonce = utils.randomBytes(24); // 24-byte nonce for XChaCha20
121
+ * const key = { ... }; // A Jwk object representing an XChaCha20 key
122
+ * const encryptedData = await XChaCha20.encrypt({
123
+ * data,
124
+ * nonce,
125
+ * key
126
+ * });
127
+ * ```
128
+ *
129
+ * @param params - The parameters for the encryption operation.
130
+ * @param params.data - The data to encrypt, represented as a Uint8Array.
131
+ * @param params.key - The key to use for encryption, represented in JWK format.
132
+ * @param params.nonce - A 24-byte nonce for the encryption process.
133
+ *
134
+ * @returns A Promise that resolves to the encrypted data as a Uint8Array.
135
+ */
136
+ static encrypt({ data, key, nonce }: {
137
+ data: Uint8Array;
138
+ key: Jwk;
139
+ nonce: Uint8Array;
140
+ }): Promise<Uint8Array>;
141
+ /**
142
+ * Generates a symmetric key for XChaCha20 in JSON Web Key (JWK) format.
143
+ *
144
+ * @remarks
145
+ * This method creates a new symmetric key suitable for use with the XChaCha20 encryption
146
+ * algorithm. The key is generated using cryptographically secure random number generation
147
+ * to ensure its uniqueness and security. The XChaCha20 algorithm requires a 256-bit key
148
+ * (32 bytes), and this method adheres to that specification.
149
+ *
150
+ * Key components included in the JWK:
151
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence.
152
+ * - `k`: The symmetric key component, base64url-encoded.
153
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const privateKey = await XChaCha20.generateKey();
158
+ * ```
159
+ *
160
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
161
+ */
162
+ static generateKey(): Promise<Jwk>;
163
+ /**
164
+ * Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
165
+ *
166
+ * @remarks
167
+ * This method takes a symmetric key in JWK format and extracts its raw byte representation.
168
+ * It decodes the 'k' parameter of the JWK value, which represents the symmetric key in base64url
169
+ * encoding, into a byte array.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const privateKey = { ... }; // A symmetric key in JWK format
174
+ * const privateKeyBytes = await XChaCha20.privateKeyToBytes({ privateKey });
175
+ * ```
176
+ *
177
+ * @param params - The parameters for the symmetric key conversion.
178
+ * @param params.privateKey - The symmetric key in JWK format.
179
+ *
180
+ * @returns A Promise that resolves to the symmetric key as a Uint8Array.
181
+ */
182
+ static privateKeyToBytes({ privateKey }: {
183
+ privateKey: Jwk;
184
+ }): Promise<Uint8Array>;
185
+ }
186
+ //# sourceMappingURL=xchacha20.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xchacha20.d.ts","sourceRoot":"","sources":["../../../src/primitives/xchacha20.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBAAa,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACiB,iBAAiB,CAAC,EAAE,eAAe,EAAE,EAAE;QACzD,eAAe,EAAE,UAAU,CAAC;KAC7B,GAAG,OAAO,CAAC,GAAG,CAAC;IAahB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;WACiB,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAChD,IAAI,EAAE,UAAU,CAAC;QACjB,GAAG,EAAE,GAAG,CAAC;QACT,KAAK,EAAE,UAAU,CAAC;KACnB,GAAG,OAAO,CAAC,UAAU,CAAC;IASvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;WACiB,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAChD,IAAI,EAAE,UAAU,CAAC;QACjB,GAAG,EAAE,GAAG,CAAC;QACT,KAAK,EAAE,UAAU,CAAC;KACnB,GAAG,OAAO,CAAC,UAAU,CAAC;IASvB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAkB/C;;;;;;;;;;;;;;;;;;OAkBG;WACiB,iBAAiB,CAAC,EAAE,UAAU,EAAE,EAAE;QACpD,UAAU,EAAE,GAAG,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,CAAC;CAWxB"}
@@ -0,0 +1,49 @@
1
+ import type { EnclosedEncryptParams, EnclosedDecryptParams } from './params-enclosed.js';
2
+ /**
3
+ * The `Cipher` interface provides methods for encrypting and decrypting data.
4
+ *
5
+ * It defines two core functions: `encrypt()` for converting plaintext to ciphertext using specific
6
+ * algorithm parameters, and `decrypt()` for the reverse process, turning ciphertext back into
7
+ * plaintext. These methods operate asynchronously and return promises that resolve to the processed
8
+ * data, whether encrypted or decrypted.
9
+ *
10
+ * The interface is designed to be flexible, accommodating various encryption algorithms and their
11
+ * unique parameters. It defaults to using {@link EnclosedEncryptParams | `EnclosedEncryptParams`}
12
+ * and {@link EnclosedDecryptParams | `EnclosedDecryptParams`}, which are intended to be used with
13
+ * a closure that captures the key and algorithm-specific parameters so that arbitrary data can be
14
+ * encrypted and decrypted without exposing the key or parameters to the caller. However, the
15
+ * interface can be extended to support other parameter types, such as {@link EncryptParams |
16
+ * `EncryptParams`} and {@link DecryptParams | `DecryptParams`}, which are intended to be used when
17
+ * the key and algorithm-specific parameters are known to the caller.
18
+ */
19
+ export interface Cipher<EncryptInput = EnclosedEncryptParams, DecryptInput = EnclosedDecryptParams> {
20
+ /**
21
+ * Encrypts the provided data.
22
+ *
23
+ * @remarks
24
+ * The `encrypt()` method of the {@link Cipher |`Cipher`} interface encrypts data.
25
+ *
26
+ * It typically takes the data to encrypt (also known as "plaintext") and algorithm-specific
27
+ * parameters as input and returns the encrypted data (also known as "ciphertext").
28
+ *
29
+ * @param params - The parameters for the encryption operation.
30
+ *
31
+ * @returns A Promise which will be fulfilled with the encrypted data.
32
+ */
33
+ encrypt(params: EncryptInput): Promise<Uint8Array>;
34
+ /**
35
+ * Decrypts the provided data.
36
+ *
37
+ * @remarks
38
+ * The `decrypt()` method of the {@link Cipher |`Cipher`} interface decrypts encrypted data.
39
+ *
40
+ * It typically takes the data to decrypt (also known as "ciphertext") and algorithm-specific
41
+ * parameters as input and returns the decrypted data (also known as "plaintext").
42
+ *
43
+ * @param params - The parameters for the decryption operation.
44
+ *
45
+ * @returns A Promise which will be fulfilled with the decrypted data.
46
+ */
47
+ decrypt(params: DecryptInput): Promise<Uint8Array>;
48
+ }
49
+ //# sourceMappingURL=cipher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cipher.d.ts","sourceRoot":"","sources":["../../../src/types/cipher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEzF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,MAAM,CACrB,YAAY,GAAG,qBAAqB,EACpC,YAAY,GAAG,qBAAqB;IAEpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEnD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD"}
@@ -0,0 +1,40 @@
1
+ import type { Hasher } from './hasher.js';
2
+ import type { Signer } from './signer.js';
3
+ import type { KeyIdentifier } from './identifier.js';
4
+ import type { AsymmetricKeyGenerator } from './key-generator.js';
5
+ import type { KmsSignParams, KmsDigestParams, KmsVerifyParams, KmsGetKeyUriParams, KmsGenerateKeyParams, KmsGetPublicKeyParams } from './params-kms.js';
6
+ /**
7
+ * The `CryptoApi` interface integrates key generation, hashing, and signing functionalities,
8
+ * designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
9
+ * generating asymmetric keys, `Hasher` for hash digest computations, and `Signer` for signing and
10
+ * verifying operations.
11
+ *
12
+ * Concrete implementations of this interface are intended to be used with a KMS, which is
13
+ * responsible for generating and storing cryptographic keys. The KMS is also responsible for
14
+ * performing cryptographic operations using the keys it manages. The KMS is typically a cloud
15
+ * service, but it can also be a hardware device or software application.
16
+ *
17
+ * Guidelines for implementing this interface:
18
+ * - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
19
+ * - Must IANA registered JSON Object Signing and Encryption
20
+ * {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
21
+ * names for algorithm, curves, etc. whenever possible.
22
+ * - All I/O that interacts with private or secret keys must be done via reference using a
23
+ * {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
24
+ * identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
25
+ * - Must support key generation, hashing, signing, and verifying operations.
26
+ * - May be extended to support other cryptographic operations.
27
+ * - Implementations of the `CryptoApi` interface can be passed as an argument to the public API
28
+ * methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
29
+ * data signing/verification, etc.).
30
+ */
31
+ export interface CryptoApi<GenerateKeyInput = KmsGenerateKeyParams, GenerateKeyOutput = KeyIdentifier, GetPublicKeyInput = KmsGetPublicKeyParams, DigestInput = KmsDigestParams, SignInput = KmsSignParams, VerifyInput = KmsVerifyParams> extends AsymmetricKeyGenerator<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput>, Hasher<DigestInput>, Signer<SignInput, VerifyInput> {
32
+ /**
33
+ *
34
+ * @param params - The parameters for getting the key URI.
35
+ * @param params.key - The key to get the URI for.
36
+ * @returns The key URI.
37
+ */
38
+ getKeyUri(params: KmsGetKeyUriParams): Promise<KeyIdentifier>;
39
+ }
40
+ //# sourceMappingURL=crypto-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-api.d.ts","sourceRoot":"","sources":["../../../src/types/crypto-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,SAAS,CACxB,gBAAgB,GAAG,oBAAoB,EACvC,iBAAiB,GAAG,aAAa,EACjC,iBAAiB,GAAG,qBAAqB,EACzC,WAAW,GAAG,eAAe,EAC7B,SAAS,GAAG,aAAa,EACzB,WAAW,GAAG,eAAe,CAC7B,SAAQ,sBAAsB,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,EAC9E,MAAM,CAAC,WAAW,CAAC,EACnB,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC;IACtC;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `Hasher` interface provides a method for generating digests of data using hash functions.
3
+ * It defines the core function `digest()` for processing variable-size input data to produce a
4
+ * fixed-size output (the "digest") which uniquely represents the input data.
5
+ *
6
+ * This method operates asynchronously and returns a digest, often used for data integrity checks.
7
+ * The interface can be implemented with various hash algorithms and their unique parameters.
8
+ *
9
+ * The interface is designed to accommodate byte array input data but can be extended to support
10
+ * other input types as needed.
11
+ */
12
+ export interface Hasher<DigestInput> {
13
+ /**
14
+ * Generates a hash digest of the provided data.
15
+ *
16
+ * @remarks
17
+ * The `digest()` method of the {@link Hasher | `Hasher`} interface generates a hash digest of the
18
+ * input data.
19
+ *
20
+ * A digest is the output of the hash function. It's a fixed-size string of bytes
21
+ * that uniquely represents the data input into the hash function. The digest is often used for
22
+ * data integrity checks, as any alteration in the input data results in a significantly
23
+ * different digest.
24
+ *
25
+ * It typically takes the data to digest as input and returns the digest of the data.
26
+ *
27
+ * @param params - The parameters for the digest operation.
28
+ *
29
+ * @returns A Promise which will be fulfilled with the hash digest.
30
+ */
31
+ digest(params: DigestInput): Promise<Uint8Array>;
32
+ }
33
+ //# sourceMappingURL=hasher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../../src/types/hasher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM,CAAC,WAAW;IACjC;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAClD"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Represents an identifier for a cryptographic algorithm.
3
+ *
4
+ * This is typically a string that specifies the name of the algorithm, such as 'ES256K', 'A256GCM',
5
+ * 'SHA-256', etc. It's used to refer to the specific algorithm in cryptographic operations.
6
+ */
7
+ export type AlgorithmIdentifier = string;
8
+ /**
9
+ * Denotes an identifier for a cryptographic key.
10
+ *
11
+ * It's a string used to uniquely identify a key within a given context, such as in key management
12
+ * systems (KMS) or cryptographic protocols. This identifier can be a simple string, a UUID, a URI,
13
+ * or any format chosen to suit the application's needs.
14
+ */
15
+ export type KeyIdentifier = string;
16
+ //# sourceMappingURL=identifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifier.d.ts","sourceRoot":"","sources":["../../../src/types/identifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `KeyCompressor` interface for converting public keys between compressed and uncompressed form.
3
+ */
4
+ export interface KeyCompressor {
5
+ /**
6
+ * Converts a public key to its compressed form.
7
+ *
8
+ * @param params - The parameters for the public key compression.
9
+ * @param params.publicKeyBytes - The public key as a Uint8Array.
10
+ *
11
+ * @returns A Promise that resolves to the compressed public key as a Uint8Array.
12
+ */
13
+ compressPublicKey(params: {
14
+ publicKeyBytes: Uint8Array;
15
+ }): Promise<Uint8Array>;
16
+ /**
17
+ * Converts a public key to its uncompressed form.
18
+ *
19
+ * @param params - The parameters for the public key decompression.
20
+ * @param params.publicKeyBytes - The public key as a Uint8Array.
21
+ *
22
+ * @returns A Promise that resolves to the uncompressed public key as a Uint8Array.
23
+ */
24
+ decompressPublicKey(params: {
25
+ publicKeyBytes: Uint8Array;
26
+ }): Promise<Uint8Array>;
27
+ }
28
+ //# sourceMappingURL=key-compressor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-compressor.d.ts","sourceRoot":"","sources":["../../../src/types/key-compressor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAE5B;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAE/E;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAClF"}
@@ -0,0 +1,57 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ /**
3
+ * `KeyConverter` interface for converting private keys between byte array and JWK formats.
4
+ */
5
+ export interface KeyConverter {
6
+ /**
7
+ * Converts a private key from a byte array to JWK format.
8
+ *
9
+ * @param params - The parameters for the private key conversion.
10
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
11
+ *
12
+ * @returns A Promise that resolves to the private key in JWK format.
13
+ */
14
+ bytesToPrivateKey(params: {
15
+ privateKeyBytes: Uint8Array;
16
+ }): Promise<Jwk>;
17
+ /**
18
+ * Converts a private key from JWK format to a byte array.
19
+ *
20
+ * @param params - The parameters for the private key conversion.
21
+ * @param params.privateKey - The private key in JWK format.
22
+ *
23
+ * @returns A Promise that resolves to the private key as a Uint8Array.
24
+ */
25
+ privateKeyToBytes(params: {
26
+ privateKey: Jwk;
27
+ }): Promise<Uint8Array>;
28
+ }
29
+ /**
30
+ * `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support
31
+ * for public key conversions.
32
+ */
33
+ export interface AsymmetricKeyConverter extends KeyConverter {
34
+ /**
35
+ * Converts a public key from a byte array to JWK format.
36
+ *
37
+ * @param params - The parameters for the public key conversion.
38
+ * @param params.publicKeyBytes - The raw public key as a Uint8Array.
39
+ *
40
+ * @returns A Promise that resolves to the public key in JWK format.
41
+ */
42
+ bytesToPublicKey(params: {
43
+ publicKeyBytes: Uint8Array;
44
+ }): Promise<Jwk>;
45
+ /**
46
+ * Converts a public key from JWK format to a byte array.
47
+ *
48
+ * @param params - The parameters for the public key conversion.
49
+ * @param params.publicKey - The public key in JWK format.
50
+ *
51
+ * @returns A Promise that resolves to the public key as a Uint8Array.
52
+ */
53
+ publicKeyToBytes(params: {
54
+ publicKey: Jwk;
55
+ }): Promise<Uint8Array>;
56
+ }
57
+ //# sourceMappingURL=key-converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-converter.d.ts","sourceRoot":"","sources":["../../../src/types/key-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEzE;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrE;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvE;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACnE"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The `KeyDeriver` interface provides methods for key derivation. It includes the methods
3
+ * `deriveBits()` to derive cryptographic bits and `deriveKey()` to derive JWK keys from input data
4
+ * using specific algorithms. This interface is designed to support various key derivation
5
+ * algorithms, accommodating different input and output types.
6
+ *
7
+ * Both methods return a Promise that resolves to the derived cryptographic material.
8
+ */
9
+ export interface KeyDeriver<DeriveBitsInput, DeriveKeyInput, DeriveKeyOutput> {
10
+ /**
11
+ * Generates a specified number of cryptographic bits from given input parameters.
12
+ *
13
+ * @remarks
14
+ * The `deriveBits()` method of the {@link KeyDeriver | `KeyDeriver`} interface is used to create
15
+ * cryptographic material such as initialization vectors or keys from various sources. The method
16
+ * takes in parameters specific to the chosen key derivation algorithm and outputs a promise that
17
+ * resolves to a `Uint8Array` containing the derived bits.
18
+ *
19
+ * @param params - The parameters for the bit derivation process, specific to the chosen algorithm.
20
+ *
21
+ * @returns A Promise resolving to the derived bits as a `Uint8Array`.
22
+ */
23
+ deriveBits(params: DeriveBitsInput): Promise<Uint8Array>;
24
+ /**
25
+ * Derives a cryptographic key in JWK format based on the provided input parameters.
26
+ *
27
+ * @remarks
28
+ * The `deriveKey()` method of the {@link KeyDeriver | `KeyDeriver`} interface is utilized to
29
+ * generate cryptographic keys for operations like encryption, decryption, or signing. The method
30
+ * takes in parameters tailored to the key derivation algorithm being used and returns a promise
31
+ * that resolves to the derived key.
32
+ *
33
+ * @param params - The parameters for the key derivation process, customized for the specific algorithm.
34
+ *
35
+ * @returns A Promise resolving to the derived key in the specified output format.
36
+ */
37
+ deriveKey(params: DeriveKeyInput): Promise<DeriveKeyOutput>;
38
+ }
39
+ //# sourceMappingURL=key-deriver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-deriver.d.ts","sourceRoot":"","sources":["../../../src/types/key-deriver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU,CACzB,eAAe,EACf,cAAc,EACd,eAAe;IAEf;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,105 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ /**
3
+ * The `KeyGenerator` interface provides a method for cryptographic key generation. It includes
4
+ * the `generateKey()` method to produce keys for cryptographic operations, supporting various
5
+ * algorithms and configurations. This interface is adaptable to different key generation
6
+ * requirements and can produce keys in formats such as JWK.
7
+ *
8
+ * The method returns a Promise that resolves to the generated key in the specified format.
9
+ */
10
+ export interface KeyGenerator<GenerateKeyInput, GenerateKeyOutput> {
11
+ /**
12
+ * Generates a cryptographic key based on the provided parameters.
13
+ *
14
+ * @remarks
15
+ * The `generateKey()` method of the {@link KeyGenerator | `KeyGenerator`} interface generates
16
+ * private keys suitable for various cryptographic operations. This method can adapt to different
17
+ * key generation algorithms and input parameters.
18
+ *
19
+ * @param params - Optional parameters for the key generation process, specific to the chosen
20
+ * algorithm.
21
+ *
22
+ * @returns A Promise resolving to the generated private key in the specified output format.
23
+ */
24
+ generateKey(params?: GenerateKeyInput): Promise<GenerateKeyOutput>;
25
+ }
26
+ /**
27
+ * The `AsymmetricKeyGenerator` interface extends {@link KeyGenerator | `KeyGenerator`}, adding
28
+ * methods specific to asymmetric public keys. It supports generating asymmetric private keys and
29
+ * obtaining the public key from a private key.
30
+ *
31
+ * This interface is designed for asymmetric cryptographic operations where both public and private
32
+ * keys are used.
33
+ */
34
+ export interface AsymmetricKeyGenerator<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput> extends KeyGenerator<GenerateKeyInput, GenerateKeyOutput> {
35
+ /**
36
+ * Optional method that mathetmatically derives the public key in JWK format from a given private
37
+ * key.
38
+ *
39
+ * @param params - The parameters for public key computation.
40
+ *
41
+ * @returns A Promise resolving to the public key in JWK format.
42
+ */
43
+ computePublicKey?(params: GetPublicKeyInput): Promise<Jwk>;
44
+ /**
45
+ * Extracts the public key portion from the given public key in JWK format.
46
+ *
47
+ * @remarks
48
+ * Unlike `computePublicKey()`, the `getPublicKey()` method does not mathematically validate the
49
+ * private key, nor does it derive the public key from the private key. It simply extracts
50
+ * existing public key properties from the private key JWK object. This makes it suitable for
51
+ * scenarios where speed is critical and the private key's integrity is already assured.
52
+ *
53
+ * @param params - The parameters for public key retrieval.
54
+ *
55
+ * @returns A Promise resolving to the public key in JWK format.
56
+ */
57
+ getPublicKey(params: GetPublicKeyInput): Promise<Jwk>;
58
+ }
59
+ /**
60
+ * Infers the supported algorithm type from the `generateKey` method of a key generator.
61
+ *
62
+ * @remarks
63
+ * The `InferKeyGeneratorAlgorithm` utility type extracts the algorithm type from the input
64
+ * parameters of the `generateKey` method implemented in a key generator. This type is useful when
65
+ * working with various cryptographic key generators, as it enables TypeScript to infer the
66
+ * supported algorithms based on the key generator's implementation. This inference ensures type
67
+ * safety and improves developer experience by providing relevant suggestions and checks for the
68
+ * supported algorithms during development.
69
+ *
70
+ * This utility type can be particularly advantageous in contexts where the specific key generator
71
+ * may vary, but the code needs to adapt dynamically based on the supported algorithms of the
72
+ * provided key generator instance.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * export interface MyKmsGenerateKeyParams extends KmsGenerateKeyParams {
77
+ * algorithm: 'Ed25519' | 'secp256k1';
78
+ * }
79
+ *
80
+ * class MyKms implements KeyGenerator<MyKmsGenerateKeyParams, Jwk> {
81
+ * generateKey(params: MyKmsGenerateKeyParams): Promise<Jwk> {
82
+ * // Implementation for generating a key...
83
+ * }
84
+ * }
85
+ *
86
+ * type SupportedAlgorithms = InferKeyGeneratorAlgorithm<MyKms>;
87
+ * // `SupportedAlgorithms` will be inferred as 'Ed25519' | 'secp256k1'
88
+ * ```
89
+ *
90
+ * @template T - The type of the key generator from which to infer the algorithm type.
91
+ */
92
+ export type InferKeyGeneratorAlgorithm<T> = T extends {
93
+ /**
94
+ * The `generateKey` method signature from which the algorithm type is inferred.
95
+ * This is an internal implementation detail and not part of the public API.
96
+ */
97
+ generateKey(params: infer P): any;
98
+ } ? P extends {
99
+ /**
100
+ * The `algorithm` property within the parameters of `generateKey`.
101
+ * This internal element is used to infer the algorithm type.
102
+ */
103
+ algorithm: infer A;
104
+ } ? A : never : never;
105
+ //# sourceMappingURL=key-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/types/key-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY,CAC3B,gBAAgB,EAChB,iBAAiB;IAEjB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CACrC,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,CACjB,SAAQ,YAAY,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IACzD;;;;;;;OAOG;IACH,gBAAgB,CAAC,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE3D;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI,CAAC,SAAS;IAClD;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC;CACnC,GACC,CAAC,SAAS;IACR;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC,CAAA;CACnB,GACC,CAAC,GACD,KAAK,GACP,KAAK,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ /**
3
+ * The `KeyImporterExporter` interface provides methods for importing and exporting cryptographic
4
+ * keys. It includes `importKey()` for importing external keys, and `exportKey()` for exporting a
5
+ * cryptographic key to an external JWK object.
6
+ *
7
+ * This interface is designed to handle various key formats and is adaptable for different
8
+ * cryptographic environments and requirements.
9
+ */
10
+ export interface KeyImporterExporter<ImportKeyInput, ImportKeyOutput, ExportKeyInput> {
11
+ /**
12
+ * Exports a cryptographic key to an external JWK object.
13
+ *
14
+ * @remarks
15
+ * The `exportKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface
16
+ * returns a cryptographic key in JWK format, facilitating interoperability and backup.
17
+ *
18
+ * @param params - The parameters for the key export operation.
19
+ *
20
+ * @returns A Promise resolving to the exported key in JWK format.
21
+ */
22
+ exportKey(params: ExportKeyInput): Promise<Jwk>;
23
+ /**
24
+ * Imports an external key in JWK format.
25
+ *
26
+ * @remarks
27
+ * The `importKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface
28
+ * takes as input an external key in JWK format and typically returns a key identifier reference
29
+ * for the imported key.
30
+ *
31
+ * @param params - The parameters for the key import operation.
32
+ *
33
+ * @returns A Promise resolving to the key identifier of the imported key.
34
+ */
35
+ importKey(params: ImportKeyInput): Promise<ImportKeyOutput>;
36
+ }
37
+ //# sourceMappingURL=key-io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-io.d.ts","sourceRoot":"","sources":["../../../src/types/key-io.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB,CAClC,cAAc,EACd,eAAe,EACf,cAAc;IAEd;;;;;;;;;;OAUG;IACH,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEhD;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7D"}