@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,237 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Secp256k1 } from '../primitives/secp256k1.js';
11
+ import { Secp256r1 } from '../primitives/secp256r1.js';
12
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
13
+ import { isEcPrivateJwk, isEcPublicJwk } from '../jose/jwk.js';
14
+ /**
15
+ * The `EcdsaAlgorithm` class provides a concrete implementation for cryptographic operations using
16
+ * the Elliptic Curve Digital Signature Algorithm (ECDSA). This class implements both
17
+ * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
18
+ * interfaces, providing private key generation, public key derivation, and creation/verification
19
+ * of signatures.
20
+ *
21
+ * This class is typically accessed through implementations that extend the
22
+ * {@link CryptoApi | `CryptoApi`} interface.
23
+ */
24
+ export class EcdsaAlgorithm extends CryptoAlgorithm {
25
+ /**
26
+ * Derives the public key in JWK format from a given private key.
27
+ *
28
+ * @remarks
29
+ * This method takes a private key in JWK format and derives its corresponding public key,
30
+ * also in JWK format. The process ensures that the derived public key correctly corresponds to
31
+ * the given private key.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const ecdsa = new EcdsaAlgorithm();
36
+ * const privateKey = { ... }; // A Jwk object representing a private key
37
+ * const publicKey = await ecdsa.computePublicKey({ key: privateKey });
38
+ * ```
39
+ *
40
+ * @param params - The parameters for the public key derivation.
41
+ * @param params.key - The private key in JWK format from which to derive the public key.
42
+ *
43
+ * @returns A Promise that resolves to the derived public key in JWK format.
44
+ */
45
+ computePublicKey(_a) {
46
+ return __awaiter(this, arguments, void 0, function* ({ key }) {
47
+ if (!isEcPrivateJwk(key))
48
+ throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
49
+ switch (key.crv) {
50
+ case 'secp256k1': {
51
+ const publicKey = yield Secp256k1.computePublicKey({ key });
52
+ publicKey.alg = 'ES256K';
53
+ return publicKey;
54
+ }
55
+ case 'P-256': {
56
+ const publicKey = yield Secp256r1.computePublicKey({ key });
57
+ publicKey.alg = 'ES256';
58
+ return publicKey;
59
+ }
60
+ default: {
61
+ throw new Error(`Unsupported curve: ${key.crv}`);
62
+ }
63
+ }
64
+ });
65
+ }
66
+ /**
67
+ * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const ecdsa = new EcdsaAlgorithm();
72
+ * const privateKey = await ecdsa.generateKey({ algorithm: 'ES256K' });
73
+ * ```
74
+ *
75
+ * @param params - The parameters for key generation.
76
+ * @param params.algorithm - The algorithm to use for key generation.
77
+ *
78
+ * @returns A Promise that resolves to the generated private key in JWK format.
79
+ */
80
+ generateKey(_a) {
81
+ return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
82
+ switch (algorithm) {
83
+ case 'ES256K':
84
+ case 'secp256k1': {
85
+ const privateKey = yield Secp256k1.generateKey();
86
+ privateKey.alg = 'ES256K';
87
+ return privateKey;
88
+ }
89
+ case 'ES256':
90
+ case 'secp256r1': {
91
+ const privateKey = yield Secp256r1.generateKey();
92
+ privateKey.alg = 'ES256';
93
+ return privateKey;
94
+ }
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * Retrieves the public key properties from a given private key in JWK format.
100
+ *
101
+ * @remarks
102
+ * This method extracts the public key portion from an ECDSA private key in JWK format. It does
103
+ * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
104
+ * public key.
105
+ *
106
+ * Note: This method offers a significant performance advantage, being about 200 times faster
107
+ * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
108
+ * does it derive the public key from the private key. It simply extracts existing public key
109
+ * properties from the private key object. This makes it suitable for scenarios where speed is
110
+ * critical and the private key's integrity is already assured.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const ecdsa = new EcdsaAlgorithm();
115
+ * const privateKey = { ... }; // A Jwk object representing a private key
116
+ * const publicKey = await ecdsa.getPublicKey({ key: privateKey });
117
+ * ```
118
+ *
119
+ * @param params - The parameters for retrieving the public key properties.
120
+ * @param params.key - The private key in JWK format.
121
+ *
122
+ * @returns A Promise that resolves to the public key in JWK format.
123
+ */
124
+ getPublicKey(_a) {
125
+ return __awaiter(this, arguments, void 0, function* ({ key }) {
126
+ if (!isEcPrivateJwk(key))
127
+ throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
128
+ switch (key.crv) {
129
+ case 'secp256k1': {
130
+ const publicKey = yield Secp256k1.getPublicKey({ key });
131
+ publicKey.alg = 'ES256K';
132
+ return publicKey;
133
+ }
134
+ case 'P-256': {
135
+ const publicKey = yield Secp256r1.getPublicKey({ key });
136
+ publicKey.alg = 'ES256';
137
+ return publicKey;
138
+ }
139
+ default: {
140
+ throw new Error(`Unsupported curve: ${key.crv}`);
141
+ }
142
+ }
143
+ });
144
+ }
145
+ /**
146
+ * Generates an ECDSA signature of given data using a private key.
147
+ *
148
+ * @remarks
149
+ * This method uses the signature algorithm determined by the given `algorithm` to sign the
150
+ * provided data.
151
+ *
152
+ * The signature can later be verified by parties with access to the corresponding
153
+ * public key, ensuring that the data has not been tampered with and was indeed signed by the
154
+ * holder of the private key.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const ecdsa = new EcdsaAlgorithm();
159
+ * const data = new TextEncoder().encode('Message');
160
+ * const privateKey = { ... }; // A Jwk object representing a private key
161
+ * const signature = await ecdsa.sign({
162
+ * key: privateKey,
163
+ * data
164
+ * });
165
+ * ```
166
+ *
167
+ * @param params - The parameters for the signing operation.
168
+ * @param params.key - The private key to use for signing, represented in JWK format.
169
+ * @param params.data - The data to sign.
170
+ *
171
+ * @returns A Promise resolving to the digital signature as a `Uint8Array`.
172
+ */
173
+ sign(_a) {
174
+ return __awaiter(this, arguments, void 0, function* ({ key, data }) {
175
+ if (!isEcPrivateJwk(key))
176
+ throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
177
+ switch (key.crv) {
178
+ case 'secp256k1': {
179
+ return yield Secp256k1.sign({ key, data });
180
+ }
181
+ case 'P-256': {
182
+ return yield Secp256r1.sign({ key, data });
183
+ }
184
+ default: {
185
+ throw new Error(`Unsupported curve: ${key.crv}`);
186
+ }
187
+ }
188
+ });
189
+ }
190
+ /**
191
+ * Verifies an ECDSA signature associated with the provided data using the provided key.
192
+ *
193
+ * @remarks
194
+ * This method uses the signature algorithm determined by the `crv` property of the provided key
195
+ * to check the validity of a digital signature against the original data. It confirms whether the
196
+ * signature was created by the holder of the corresponding private key and that the data has not
197
+ * been tampered with.
198
+ *s
199
+ * @example
200
+ * ```ts
201
+ * const ecdsa = new EcdsaAlgorithm();
202
+ * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
203
+ * const signature = new Uint8Array([...]); // Signature to verify
204
+ * const data = new TextEncoder().encode('Message');
205
+ * const isValid = await ecdsa.verify({
206
+ * key: publicKey,
207
+ * signature,
208
+ * data
209
+ * });
210
+ * ```
211
+ *
212
+ * @param params - The parameters for the verification operation.
213
+ * @param params.key - The key to use for verification.
214
+ * @param params.signature - The signature to verify.
215
+ * @param params.data - The data to verify.
216
+ *
217
+ * @returns A Promise resolving to a boolean indicating whether the signature is valid.
218
+ */
219
+ verify(_a) {
220
+ return __awaiter(this, arguments, void 0, function* ({ key, signature, data }) {
221
+ if (!isEcPublicJwk(key))
222
+ throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) public key.');
223
+ switch (key.crv) {
224
+ case 'secp256k1': {
225
+ return yield Secp256k1.verify({ key, signature, data });
226
+ }
227
+ case 'P-256': {
228
+ return yield Secp256r1.verify({ key, signature, data });
229
+ }
230
+ default: {
231
+ throw new Error(`Unsupported curve: ${key.crv}`);
232
+ }
233
+ }
234
+ });
235
+ }
236
+ }
237
+ //# sourceMappingURL=ecdsa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecdsa.js","sourceRoot":"","sources":["../../../src/algorithms/ecdsa.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MA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,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBAED,KAAK,OAAO,CAAC,CAAC,CAAC;oBACb,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACU,MAAM;6DAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAC5B;YAEZ,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAC;YAEjH,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;gBAEhB,KAAK,WAAW,CAAC,CAAC,CAAC;oBACjB,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBAED,KAAK,OAAO,CAAC,CAAC,CAAC;oBACb,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,213 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Ed25519 } from '../primitives/ed25519.js';
11
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
12
+ import { isOkpPrivateJwk, isOkpPublicJwk } from '../jose/jwk.js';
13
+ /**
14
+ * The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
15
+ * the Edwards-curve Digital Signature Algorithm (EdDSA). This class implements both
16
+ * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
17
+ * interfaces, providing private key generation, public key derivation, and creation/verification
18
+ * of signatures.
19
+ *
20
+ * This class is typically accessed through implementations that extend the
21
+ * {@link CryptoApi | `CryptoApi`} interface.
22
+ */
23
+ export class EdDsaAlgorithm extends CryptoAlgorithm {
24
+ /**
25
+ * Derives the public key in JWK format from a given private key.
26
+ *
27
+ * @remarks
28
+ * This method takes a private key in JWK format and derives its corresponding public key,
29
+ * also in JWK format. The process ensures that the derived public key correctly corresponds to
30
+ * the given private key.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const eddsa = new EdDsaAlgorithm();
35
+ * const privateKey = { ... }; // A Jwk object representing a private key
36
+ * const publicKey = await eddsa.computePublicKey({ key: privateKey });
37
+ * ```
38
+ *
39
+ * @param params - The parameters for the public key derivation.
40
+ * @param params.key - The private key in JWK format from which to derive the public key.
41
+ *
42
+ * @returns A Promise that resolves to the derived public key in JWK format.
43
+ */
44
+ computePublicKey(_a) {
45
+ return __awaiter(this, arguments, void 0, function* ({ key }) {
46
+ if (!isOkpPrivateJwk(key))
47
+ throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
48
+ switch (key.crv) {
49
+ case 'Ed25519': {
50
+ const publicKey = yield Ed25519.computePublicKey({ key });
51
+ publicKey.alg = 'EdDSA';
52
+ return publicKey;
53
+ }
54
+ default: {
55
+ throw new Error(`Unsupported curve: ${key.crv}`);
56
+ }
57
+ }
58
+ });
59
+ }
60
+ /**
61
+ * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const eddsa = new EdDsaAlgorithm();
66
+ * const privateKey = await eddsa.generateKey({ algorithm: 'Ed25519' });
67
+ * ```
68
+ *
69
+ * @param params - The parameters for key generation.
70
+ * @param params.algorithm - The algorithm to use for key generation.
71
+ *
72
+ * @returns A Promise that resolves to the generated private key in JWK format.
73
+ */
74
+ generateKey(_a) {
75
+ return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
76
+ switch (algorithm) {
77
+ case 'Ed25519': {
78
+ const privateKey = yield Ed25519.generateKey();
79
+ privateKey.alg = 'EdDSA';
80
+ return privateKey;
81
+ }
82
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Retrieves the public key properties from a given private key in JWK format.
87
+ *
88
+ * @remarks
89
+ * This method extracts the public key portion from an EdDSA private key in JWK format. It does
90
+ * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
91
+ * public key.
92
+ *
93
+ * Note: This method offers a significant performance advantage, being about 100 times faster
94
+ * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
95
+ * does it derive the public key from the private key. It simply extracts existing public key
96
+ * properties from the private key object. This makes it suitable for scenarios where speed is
97
+ * critical and the private key's integrity is already assured.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const eddsa = new EdDsaAlgorithm();
102
+ * const privateKey = { ... }; // A Jwk object representing a private key
103
+ * const publicKey = await eddsa.getPublicKey({ key: privateKey });
104
+ * ```
105
+ *
106
+ * @param params - The parameters for retrieving the public key properties.
107
+ * @param params.key - The private key in JWK format.
108
+ *
109
+ * @returns A Promise that resolves to the public key in JWK format.
110
+ */
111
+ getPublicKey(_a) {
112
+ return __awaiter(this, arguments, void 0, function* ({ key }) {
113
+ if (!isOkpPrivateJwk(key))
114
+ throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
115
+ switch (key.crv) {
116
+ case 'Ed25519': {
117
+ const publicKey = yield Ed25519.getPublicKey({ key });
118
+ publicKey.alg = 'EdDSA';
119
+ return publicKey;
120
+ }
121
+ default: {
122
+ throw new Error(`Unsupported curve: ${key.crv}`);
123
+ }
124
+ }
125
+ });
126
+ }
127
+ /**
128
+ * Generates an EdDSA signature of given data using a private key.
129
+ *
130
+ * @remarks
131
+ * This method uses the signature algorithm determined by the given `algorithm` to sign the
132
+ * provided data.
133
+ *
134
+ * The signature can later be verified by parties with access to the corresponding
135
+ * public key, ensuring that the data has not been tampered with and was indeed signed by the
136
+ * holder of the private key.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * const eddsa = new EdDsaAlgorithm();
141
+ * const data = new TextEncoder().encode('Message');
142
+ * const privateKey = { ... }; // A Jwk object representing a private key
143
+ * const signature = await eddsa.sign({
144
+ * key: privateKey,
145
+ * data
146
+ * });
147
+ * ```
148
+ *
149
+ * @param params - The parameters for the signing operation.
150
+ * @param params.key - The private key to use for signing, represented in JWK format.
151
+ * @param params.data - The data to sign.
152
+ *
153
+ * @returns A Promise resolving to the digital signature as a `Uint8Array`.
154
+ */
155
+ sign(_a) {
156
+ return __awaiter(this, arguments, void 0, function* ({ key, data }) {
157
+ if (!isOkpPrivateJwk(key))
158
+ throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
159
+ switch (key.crv) {
160
+ case 'Ed25519': {
161
+ return yield Ed25519.sign({ key, data });
162
+ }
163
+ default: {
164
+ throw new Error(`Unsupported curve: ${key.crv}`);
165
+ }
166
+ }
167
+ });
168
+ }
169
+ /**
170
+ * Verifies an EdDSA signature associated with the provided data using the provided key.
171
+ *
172
+ * @remarks
173
+ * This method uses the signature algorithm determined by the `crv` property of the provided key
174
+ * to check the validity of a digital signature against the original data. It confirms whether the
175
+ * signature was created by the holder of the corresponding private key and that the data has not
176
+ * been tampered with.
177
+ *s
178
+ * @example
179
+ * ```ts
180
+ * const eddsa = new EdDsaAlgorithm();
181
+ * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
182
+ * const signature = new Uint8Array([...]); // Signature to verify
183
+ * const data = new TextEncoder().encode('Message');
184
+ * const isValid = await eddsa.verify({
185
+ * key: publicKey,
186
+ * signature,
187
+ * data
188
+ * });
189
+ * ```
190
+ *
191
+ * @param params - The parameters for the verification operation.
192
+ * @param params.key - The key to use for verification.
193
+ * @param params.signature - The signature to verify.
194
+ * @param params.data - The data to verify.
195
+ *
196
+ * @returns A Promise resolving to a boolean indicating whether the signature is valid.
197
+ */
198
+ verify(_a) {
199
+ return __awaiter(this, arguments, void 0, function* ({ key, signature, data }) {
200
+ if (!isOkpPublicJwk(key))
201
+ throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');
202
+ switch (key.crv) {
203
+ case 'Ed25519': {
204
+ return yield Ed25519.verify({ key, signature, data });
205
+ }
206
+ default: {
207
+ throw new Error(`Unsupported curve: ${key.crv}`);
208
+ }
209
+ }
210
+ });
211
+ }
212
+ }
213
+ //# sourceMappingURL=eddsa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eddsa.js","sourceRoot":"","sources":["../../../src/algorithms/eddsa.ts"],"names":[],"mappings":";;;;;;;;;AAWA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAcjE;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAIjD;;;;;;;;;;;;;;;;;;;OAmBG;IACU,gBAAgB;6DAAC,EAAE,GAAG,EACX;YAEtB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,CAAC;YAErH,QAAQ,GAAG,CAAC,GAAG,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACU,IAAI;6DAAC,EAAE,GAAG,EAAE,IAAI,EACjB;YAEV,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,CAAC;YAErH,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;gBAEhB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3C,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACU,MAAM;6DAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAC5B;YAEZ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;YAEnH,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;gBAEhB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,57 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Sha256 } from '../primitives/sha256.js';
11
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
12
+ /**
13
+ * The `Sha2Algorithm` class is an implementation of the {@link Hasher | `Hasher`} interface for the
14
+ * SHA-2 family of cryptographic hash functions. The `digest` method takes the algorithm identifier
15
+ * of the hash function and arbitrary data as input and returns the hash digest of the data.
16
+ *
17
+ * This class is typically accessed through implementations that extend the
18
+ * {@link CryptoApi | `CryptoApi`} interface.
19
+ */
20
+ export class Sha2Algorithm extends CryptoAlgorithm {
21
+ /**
22
+ * Generates a hash digest of the provided data.
23
+ *
24
+ * @remarks
25
+ * A digest is the output of the hash function. It's a fixed-size string of bytes
26
+ * that uniquely represents the data input into the hash function. The digest is often used for
27
+ * data integrity checks, as any alteration in the input data results in a significantly
28
+ * different digest.
29
+ *
30
+ * It takes the algorithm identifier of the hash function and data to digest as input and returns
31
+ * the digest of the data.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const sha2 = new Sha2Algorithm();
36
+ * const data = new TextEncoder().encode('Messsage');
37
+ * const digest = await sha2.digest({ data });
38
+ * ```
39
+ *
40
+ * @param params - The parameters for the digest operation.
41
+ * @param params.algorithm - The name of hash function to use.
42
+ * @param params.data - The data to digest.
43
+ *
44
+ * @returns A Promise which will be fulfilled with the hash digest.
45
+ */
46
+ digest(_a) {
47
+ return __awaiter(this, arguments, void 0, function* ({ algorithm, data }) {
48
+ switch (algorithm) {
49
+ case 'SHA-256': {
50
+ const hash = yield Sha256.digest({ data });
51
+ return hash;
52
+ }
53
+ }
54
+ });
55
+ }
56
+ }
57
+ //# sourceMappingURL=sha-2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha-2.js","sourceRoot":"","sources":["../../../src/algorithms/sha-2.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAcxD;;;;;;;GAOG;AACH,MAAM,OAAO,aAAc,SAAQ,eAAe;IAGhD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,MAAM;6DAAC,EAAE,SAAS,EAAE,IAAI,EAAoB;YACvD,QAAQ,SAAS,EAAE,CAAC;gBAElB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC3C,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QAEH,CAAC;KAAA;CACF"}
@@ -0,0 +1,25 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jwe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwe.js","sourceRoot":"","sources":["../../../src/jose/jwe.ts"],"names":[],"mappings":""}