@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,151 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ import type { Signer } from '../types/signer.js';
3
+ import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
4
+ import type { SignParams, VerifyParams, GenerateKeyParams, GetPublicKeyParams, ComputePublicKeyParams } from '../types/params-direct.js';
5
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
6
+ /**
7
+ * The `EdDsaGenerateKeyParams` interface defines the algorithm-specific parameters that should be
8
+ * passed into the `generateKey()` method when using the EdDSA algorithm.
9
+ */
10
+ export interface EdDsaGenerateKeyParams extends GenerateKeyParams {
11
+ /**
12
+ * A string defining the type of key to generate. The value must be one of the following:
13
+ * - `"Ed25519"`: EdDSA using the Ed25519 curve.
14
+ */
15
+ algorithm: 'Ed25519';
16
+ }
17
+ /**
18
+ * The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
19
+ * the Edwards-curve Digital Signature Algorithm (EdDSA). This class implements both
20
+ * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
21
+ * interfaces, providing private key generation, public key derivation, and creation/verification
22
+ * of signatures.
23
+ *
24
+ * This class is typically accessed through implementations that extend the
25
+ * {@link CryptoApi | `CryptoApi`} interface.
26
+ */
27
+ export declare class EdDsaAlgorithm extends CryptoAlgorithm implements AsymmetricKeyGenerator<EdDsaGenerateKeyParams, Jwk, GetPublicKeyParams>, Signer<SignParams, VerifyParams> {
28
+ /**
29
+ * Derives the public key in JWK format from a given private key.
30
+ *
31
+ * @remarks
32
+ * This method takes a private key in JWK format and derives its corresponding public key,
33
+ * also in JWK format. The process ensures that the derived public key correctly corresponds to
34
+ * the given private key.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const eddsa = new EdDsaAlgorithm();
39
+ * const privateKey = { ... }; // A Jwk object representing a private key
40
+ * const publicKey = await eddsa.computePublicKey({ key: privateKey });
41
+ * ```
42
+ *
43
+ * @param params - The parameters for the public key derivation.
44
+ * @param params.key - The private key in JWK format from which to derive the public key.
45
+ *
46
+ * @returns A Promise that resolves to the derived public key in JWK format.
47
+ */
48
+ computePublicKey({ key }: ComputePublicKeyParams): Promise<Jwk>;
49
+ /**
50
+ * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const eddsa = new EdDsaAlgorithm();
55
+ * const privateKey = await eddsa.generateKey({ algorithm: 'Ed25519' });
56
+ * ```
57
+ *
58
+ * @param params - The parameters for key generation.
59
+ * @param params.algorithm - The algorithm to use for key generation.
60
+ *
61
+ * @returns A Promise that resolves to the generated private key in JWK format.
62
+ */
63
+ generateKey({ algorithm }: EdDsaGenerateKeyParams): Promise<Jwk>;
64
+ /**
65
+ * Retrieves the public key properties from a given private key in JWK format.
66
+ *
67
+ * @remarks
68
+ * This method extracts the public key portion from an EdDSA private key in JWK format. It does
69
+ * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
70
+ * public key.
71
+ *
72
+ * Note: This method offers a significant performance advantage, being about 100 times faster
73
+ * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
74
+ * does it derive the public key from the private key. It simply extracts existing public key
75
+ * properties from the private key object. This makes it suitable for scenarios where speed is
76
+ * critical and the private key's integrity is already assured.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const eddsa = new EdDsaAlgorithm();
81
+ * const privateKey = { ... }; // A Jwk object representing a private key
82
+ * const publicKey = await eddsa.getPublicKey({ key: privateKey });
83
+ * ```
84
+ *
85
+ * @param params - The parameters for retrieving the public key properties.
86
+ * @param params.key - The private key in JWK format.
87
+ *
88
+ * @returns A Promise that resolves to the public key in JWK format.
89
+ */
90
+ getPublicKey({ key }: GetPublicKeyParams): Promise<Jwk>;
91
+ /**
92
+ * Generates an EdDSA signature of given data using a private key.
93
+ *
94
+ * @remarks
95
+ * This method uses the signature algorithm determined by the given `algorithm` to sign the
96
+ * provided data.
97
+ *
98
+ * The signature can later be verified by parties with access to the corresponding
99
+ * public key, ensuring that the data has not been tampered with and was indeed signed by the
100
+ * holder of the private key.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const eddsa = new EdDsaAlgorithm();
105
+ * const data = new TextEncoder().encode('Message');
106
+ * const privateKey = { ... }; // A Jwk object representing a private key
107
+ * const signature = await eddsa.sign({
108
+ * key: privateKey,
109
+ * data
110
+ * });
111
+ * ```
112
+ *
113
+ * @param params - The parameters for the signing operation.
114
+ * @param params.key - The private key to use for signing, represented in JWK format.
115
+ * @param params.data - The data to sign.
116
+ *
117
+ * @returns A Promise resolving to the digital signature as a `Uint8Array`.
118
+ */
119
+ sign({ key, data }: SignParams): Promise<Uint8Array>;
120
+ /**
121
+ * Verifies an EdDSA signature associated with the provided data using the provided key.
122
+ *
123
+ * @remarks
124
+ * This method uses the signature algorithm determined by the `crv` property of the provided key
125
+ * to check the validity of a digital signature against the original data. It confirms whether the
126
+ * signature was created by the holder of the corresponding private key and that the data has not
127
+ * been tampered with.
128
+ *s
129
+ * @example
130
+ * ```ts
131
+ * const eddsa = new EdDsaAlgorithm();
132
+ * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
133
+ * const signature = new Uint8Array([...]); // Signature to verify
134
+ * const data = new TextEncoder().encode('Message');
135
+ * const isValid = await eddsa.verify({
136
+ * key: publicKey,
137
+ * signature,
138
+ * data
139
+ * });
140
+ * ```
141
+ *
142
+ * @param params - The parameters for the verification operation.
143
+ * @param params.key - The key to use for verification.
144
+ * @param params.signature - The signature to verify.
145
+ * @param params.data - The data to verify.
146
+ *
147
+ * @returns A Promise resolving to a boolean indicating whether the signature is valid.
148
+ */
149
+ verify({ key, signature, data }: VerifyParams): Promise<boolean>;
150
+ }
151
+ //# sourceMappingURL=eddsa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/algorithms/eddsa.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,eAClC,YAAW,sBAAsB,CAAC,sBAAsB,EAAE,GAAG,EAAE,kBAAkB,CAAC,EACvE,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC;IAE3C;;;;;;;;;;;;;;;;;;;OAmBG;IACU,gBAAgB,CAAC,EAAE,GAAG,EAAE,EACnC,sBAAsB,GACrB,OAAO,CAAC,GAAG,CAAC;IAiBf;;;;;;;;;;;;;OAaG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,EAC7B,sBAAsB,GACrB,OAAO,CAAC,GAAG,CAAC;IAWf;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,YAAY,CAAC,EAAE,GAAG,EAAE,EAC/B,kBAAkB,GACjB,OAAO,CAAC,GAAG,CAAC;IAiBf;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACU,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAC7B,UAAU,GACT,OAAO,CAAC,UAAU,CAAC;IAetB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACU,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAC1C,YAAY,GACX,OAAO,CAAC,OAAO,CAAC;CAcpB"}
@@ -0,0 +1,51 @@
1
+ import type { Hasher } from '../types/hasher.js';
2
+ import type { DigestParams } from '../types/params-direct.js';
3
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
4
+ /**
5
+ * The `Sha2DigestParams` interface defines the algorithm-specific parameters that should be
6
+ * passed into the `digest()` method when using the SHA-2 algorithm.
7
+ */
8
+ export interface Sha2DigestParams extends DigestParams {
9
+ /**
10
+ * A string defining the name of hash function to use. The value must be one of the following:
11
+ * - `"SHA-256"`: Generates a 256-bit digest.
12
+ */
13
+ algorithm: 'SHA-256';
14
+ }
15
+ /**
16
+ * The `Sha2Algorithm` class is an implementation of the {@link Hasher | `Hasher`} interface for the
17
+ * SHA-2 family of cryptographic hash functions. The `digest` method takes the algorithm identifier
18
+ * of the hash function and arbitrary data as input and returns the hash digest of the data.
19
+ *
20
+ * This class is typically accessed through implementations that extend the
21
+ * {@link CryptoApi | `CryptoApi`} interface.
22
+ */
23
+ export declare class Sha2Algorithm extends CryptoAlgorithm implements Hasher<Sha2DigestParams> {
24
+ /**
25
+ * Generates a hash digest of the provided data.
26
+ *
27
+ * @remarks
28
+ * A digest is the output of the hash function. It's a fixed-size string of bytes
29
+ * that uniquely represents the data input into the hash function. The digest is often used for
30
+ * data integrity checks, as any alteration in the input data results in a significantly
31
+ * different digest.
32
+ *
33
+ * It takes the algorithm identifier of the hash function and data to digest as input and returns
34
+ * the digest of the data.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const sha2 = new Sha2Algorithm();
39
+ * const data = new TextEncoder().encode('Messsage');
40
+ * const digest = await sha2.digest({ data });
41
+ * ```
42
+ *
43
+ * @param params - The parameters for the digest operation.
44
+ * @param params.algorithm - The name of hash function to use.
45
+ * @param params.data - The data to digest.
46
+ *
47
+ * @returns A Promise which will be fulfilled with the hash digest.
48
+ */
49
+ digest({ algorithm, data }: Sha2DigestParams): Promise<Uint8Array>;
50
+ }
51
+ //# sourceMappingURL=sha-2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha-2.d.ts","sourceRoot":"","sources":["../../../src/algorithms/sha-2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,eACjC,YAAW,MAAM,CAAC,gBAAgB,CAAC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;CAUhF"}
@@ -0,0 +1,39 @@
1
+ export * from './local-key-manager.js';
2
+ export * from './utils.js';
3
+ export * from './algorithms/aes-ctr.js';
4
+ export * from './algorithms/aes-gcm.js';
5
+ export * from './algorithms/crypto-algorithm.js';
6
+ export * from './algorithms/ecdsa.js';
7
+ export * from './algorithms/eddsa.js';
8
+ export * from './algorithms/sha-2.js';
9
+ export * from './jose/jwe.js';
10
+ export * from './jose/jwk.js';
11
+ export * from './jose/jws.js';
12
+ export * from './jose/jwt.js';
13
+ export * from './jose/utils.js';
14
+ export * from './primitives/aes-ctr.js';
15
+ export * from './primitives/aes-gcm.js';
16
+ export * from './primitives/concat-kdf.js';
17
+ export * from './primitives/ed25519.js';
18
+ export * from './primitives/secp256r1.js';
19
+ export * from './primitives/pbkdf2.js';
20
+ export * from './primitives/secp256k1.js';
21
+ export * from './primitives/sha256.js';
22
+ export * from './primitives/x25519.js';
23
+ export * from './primitives/xchacha20.js';
24
+ export * from './primitives/xchacha20-poly1305.js';
25
+ export type * from './types/cipher.js';
26
+ export type * from './types/crypto-api.js';
27
+ export type * from './types/hasher.js';
28
+ export type * from './types/identifier.js';
29
+ export type * from './types/key-compressor.js';
30
+ export type * from './types/key-converter.js';
31
+ export type * from './types/key-deriver.js';
32
+ export type * from './types/key-generator.js';
33
+ export type * from './types/key-io.js';
34
+ export type * from './types/key-wrapper.js';
35
+ export type * from './types/params-direct.js';
36
+ export type * from './types/params-enclosed.js';
37
+ export type * from './types/params-kms.js';
38
+ export type * from './types/signer.js';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAE3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AAEnD,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,2BAA2B,CAAC;AAC/C,mBAAmB,0BAA0B,CAAC;AAC9C,mBAAmB,wBAAwB,CAAC;AAC5C,mBAAmB,0BAA0B,CAAC;AAC9C,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,wBAAwB,CAAC;AAC5C,mBAAmB,0BAA0B,CAAC;AAC9C,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,mBAAmB,CAAC"}
@@ -0,0 +1,135 @@
1
+ import type { JoseHeaderParams } from './jws.js';
2
+ /**
3
+ * JSON Web Encryption (JWE) Header Parameters
4
+ *
5
+ * The Header Parameter names for use in JWEs are registered in the IANA "JSON Web Signature and
6
+ * Encryption Header Parameters" registry.
7
+ *
8
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1 | RFC 7516, Section 4.1}
9
+ */
10
+ export interface JweHeaderParams extends JoseHeaderParams {
11
+ /**
12
+ * Algorithm Header Parameter
13
+ *
14
+ * Identifies the cryptographic algorithm used to encrypt or determine the value of the Content
15
+ * Encryption Key (CEK). The encrypted content is not usable if the "alg" value does not represent
16
+ * a supported algorithm, or if the recipient does not have a key that can be used with that
17
+ * algorithm.
18
+ *
19
+ * "alg" values should either be registered in the IANA "JSON Web Signature and Encryption
20
+ * Algorithms" registry or be a value that contains a Collision-Resistant Name. The "alg" value is
21
+ * a case-sensitive ASCII string. This Header Parameter MUST be present and MUST be understood
22
+ * and processed by implementations.
23
+ *
24
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1.1 | RFC 7516, Section 4.1.1}
25
+ */
26
+ alg: 'A128KW' | 'A192KW' | 'A256KW' | 'dir' | 'ECDH-ES' | 'ECDH-ES+A128KW' | 'ECDH-ES+A192KW' | 'ECDH-ES+A256KW' | 'A128GCMKW' | 'A192GCMKW' | 'A256GCMKW' | 'PBES2-HS256+A128KW' | 'PBES2-HS384+A192KW' | 'PBES2-HS512+A256KW' | 'PBES2-HS512+XC20PKW' | string;
27
+ /**
28
+ * Agreement PartyUInfo Header Parameter
29
+ *
30
+ * The "apu" (agreement PartyUInfo) value is a base64url-encoded octet sequence containing
31
+ * information about the producer of the JWE. This information is used by the recipient to
32
+ * determine the key agreement algorithm and key encryption algorithm to use to decrypt the JWE.
33
+ *
34
+ * Note: This parameter is intended only for use when the recipient is a key agreement algorithm
35
+ * that uses public key cryptography.
36
+ */
37
+ apu?: Uint8Array;
38
+ /**
39
+ * Agreement PartyVInfo Header Parameter
40
+ *
41
+ * The "apv" (agreement PartyVInfo) value is a base64url-encoded octet sequence containing
42
+ * information about the recipient of the JWE. This information is used by the recipient to
43
+ * determine the key agreement algorithm and key encryption algorithm to use to decrypt the JWE.
44
+ *
45
+ * Note: This parameter is intended only for use when the recipient is a key agreement algorithm
46
+ * that uses public key cryptography.
47
+ */
48
+ apv?: Uint8Array;
49
+ /**
50
+ * Critical Header Parameter
51
+ *
52
+ * Indicates that extensions to JOSE RFCs are being used that MUST be understood and processed.
53
+ */
54
+ crit?: string[];
55
+ /**
56
+ * Encryption Algorithm Header Parameter
57
+ *
58
+ * Identifies the content encryption algorithm used to encrypt and integrity-protect (also
59
+ * known as "authenticated encryption") the plaintext and to integrity-protect the Additional
60
+ * Authenticated Data (AAD), if any. This algorithm MUST be an AEAD algorithm with a specified
61
+ * key length.
62
+ *
63
+ * The encrypted content is not usable if the "enc" value does not represent a supported
64
+ * algorithm. "enc" values should either be registered in the IANA "JSON Web Signature and
65
+ * Encryption Algorithms" registry or be a value that contains a Collision-Resistant Name. The
66
+ * "enc" value is a case-sensitive ASCII string containing a StringOrURI value. This Header
67
+ * Parameter MUST be present and MUST be understood and processed by implementations.
68
+ *
69
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1.2 | RFC 7516, Section 4.1.2}
70
+ */
71
+ enc: 'A128CBC-HS256' | 'A192CBC-HS384' | 'A256CBC-HS512' | 'A128GCM' | 'A192GCM' | 'A256GCM' | 'XC20P' | string;
72
+ /**
73
+ * Ephemeral Public Key Header Parameter
74
+ *
75
+ * The "epk" (ephemeral public key) value created by the originator for the use in key agreement
76
+ * algorithms. It is the ephemeral public key that corresponds to the key used to encrypt the
77
+ * JWE. This value is represented as a JSON Web Key (JWK).
78
+ *
79
+ * Note: This parameter is intended only for use when the recipient is a key agreement algorithm
80
+ * that uses public key cryptography.
81
+ */
82
+ epk?: Uint8Array;
83
+ /**
84
+ * Initialization Vector Header Parameter
85
+ *
86
+ * The "iv" (initialization vector) value is a base64url-encoded octet sequence used by the
87
+ * specified "enc" algorithm. The length of this Initialization Vector value MUST be exactly
88
+ * equal to the value that would be produced by the "enc" algorithm.
89
+ *
90
+ * Note: With symmetric encryption algorithms such as AES GCM, this Header Parameter MUST
91
+ * be present and MUST be understood and processed by implementations.
92
+ */
93
+ iv?: Uint8Array;
94
+ /**
95
+ * PBES2 Count Header Parameter
96
+ *
97
+ * The "p2c" (PBES2 count) value is an integer indicating the number of iterations of the PBKDF2
98
+ * algorithm performed during key derivation.
99
+ *
100
+ * Note: The iteration count adds computational expense, ideally compounded by the possible range
101
+ * of keys introduced by the salt. A minimum iteration count of 1000 is RECOMMENDED.
102
+ */
103
+ p2c?: number;
104
+ /**
105
+ * PBES2 Salt Input Header Parameter
106
+ *
107
+ * The "p2s" (PBES2 salt) value is a base64url-encoded octet sequence used as the salt value
108
+ * input to the PBKDF2 algorithm during key derivation.
109
+ *
110
+ * The salt value used is (UTF8(Alg) || 0x00 || Salt Input), where Alg is the "alg" (algorithm)
111
+ * Header Parameter value.
112
+ *
113
+ * Note: The salt value is used to ensure that each key derived from the master key is
114
+ * independent of every other key. A suitable source of salt value is a sequence of
115
+ * cryptographically random bytes containing 8 or more octets.
116
+ */
117
+ p2s?: string;
118
+ /**
119
+ * Authentication Tag Header Parameter
120
+ *
121
+ * The "tag" value is a base64url-encoded octet sequence containing the value of the
122
+ * Authentication Tag output by the specified "enc" algorithm. The length of this
123
+ * Authentication Tag value MUST be exactly equal to the value that would be produced by the
124
+ * "enc" algorithm.
125
+ *
126
+ * Note: With authenticated encryption algorithms such as AES GCM, this Header Parameter MUST
127
+ * be present and MUST be understood and processed by implementations.
128
+ */
129
+ tag?: Uint8Array;
130
+ /**
131
+ * Additional Public or Private Header Parameter names.
132
+ */
133
+ [key: string]: unknown;
134
+ }
135
+ //# sourceMappingURL=jwe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwe.d.ts","sourceRoot":"","sources":["../../../src/jose/jwe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD;;;;;;;;;;;;;;OAcG;IACH,GAAG,EAEC,QAAQ,GAER,QAAQ,GAER,QAAQ,GAER,KAAK,GAEL,SAAS,GAET,gBAAgB,GAEhB,gBAAgB,GAEhB,gBAAgB,GAEhB,WAAW,GAEX,WAAW,GAEX,WAAW,GAEX,oBAAoB,GAEpB,oBAAoB,GAEpB,oBAAoB,GAEpB,qBAAqB,GAErB,MAAM,CAAC;IAEX;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IAEf;;;;;;;;;;;;;;;OAeG;IACH,GAAG,EAGC,eAAe,GAGf,eAAe,GAGf,eAAe,GAEf,SAAS,GAET,SAAS,GAET,SAAS,GAET,OAAO,GAEP,MAAM,CAAC;IAEX;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB;;;;;;;;;OASG;IACH,EAAE,CAAC,EAAE,UAAU,CAAC;IAEhB;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;OAUG;IACH,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB"}