@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,439 @@
1
+ /**
2
+ * Constant defining the prefix for JSON Web Keys (JWK) key URIs in this library.
3
+ *
4
+ * The prefix 'urn:jwk:' makes it explicit that a string represents a JWK, referenced by a
5
+ * {@link https://datatracker.ietf.org/doc/html/rfc3986 | URI} (Uniform Resource Identifier),
6
+ * which ensures consistent key referencing across all Web5 Key Management System (KMS)
7
+ * implementations.
8
+ *
9
+ * These key URIs take the form `urn:jwk:<JWK thumbprint>`, where the
10
+ * {@link https://datatracker.ietf.org/doc/html/rfc7638 | JWK thumbprint}, derived from the JWK, is
11
+ * unique to the key's material, unaffected by the order or optional properties in the JWK.
12
+ */
13
+ export declare const KEY_URI_PREFIX_JWK = "urn:jwk:";
14
+ /**
15
+ * JSON Web Key Operations
16
+ *
17
+ * The "key_ops" (key operations) parameter identifies the operation(s)
18
+ * for which the key is intended to be used. The "key_ops" parameter is
19
+ * intended for use cases in which public, private, or symmetric keys
20
+ * may be present.
21
+ *
22
+ * Its value is an array of key operation values. Values defined by
23
+ * {@link https://www.rfc-editor.org/rfc/rfc7517.html#section-4.3 | RFC 7517 Section 4.3} are:
24
+ *
25
+ * - "decrypt" : Decrypt content and validate decryption, if applicable
26
+ * - "deriveBits" : Derive bits not to be used as a key
27
+ * - "deriveKey" : Derive key
28
+ * - "encrypt" : Encrypt content
29
+ * - "sign" : Compute digital signature or MAC
30
+ * - "unwrapKey" : Decrypt key and validate decryption, if applicable
31
+ * - "verify" : Verify digital signature or MAC
32
+ * - "wrapKey" : Encrypt key
33
+ *
34
+ * Other values MAY be used. The key operation values are case-
35
+ * sensitive strings. Duplicate key operation values MUST NOT be
36
+ * present in the array. Use of the "key_ops" member is OPTIONAL,
37
+ * unless the application requires its presence.
38
+ *
39
+ * The "use" and "key_ops" JWK members SHOULD NOT be used together;
40
+ * however, if both are used, the information they convey MUST be
41
+ * consistent. Applications should specify which of these members they
42
+ * use, if either is to be used by the application.
43
+ */
44
+ export type JwkOperation = 'encrypt' | 'decrypt' | 'sign' | 'verify' | 'deriveKey' | 'deriveBits' | 'wrapKey' | 'unwrapKey';
45
+ /**
46
+ * JSON Web Key Use
47
+ *
48
+ * The "use" (public key use) parameter identifies the intended use of
49
+ * the public key. The "use" parameter is employed to indicate whether
50
+ * a public key is used for encrypting data or verifying the signature
51
+ * on data.
52
+ *
53
+ * Values defined by {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4.2 | RFC 7517 Section 4.2} are:
54
+ *
55
+ * - "sig" (signature)
56
+ * - "enc" (encryption)
57
+ *
58
+ * Other values MAY be used. The "use" value is a case-sensitive
59
+ * string. Use of the "use" member is OPTIONAL, unless the application
60
+ * requires its presence.
61
+ *
62
+ * The "use" and "key_ops" JWK members SHOULD NOT be used together;
63
+ * however, if both are used, the information they convey MUST be
64
+ * consistent. Applications should specify which of these members they
65
+ * use, if either is to be used by the application.
66
+ *
67
+ * When a key is used to wrap another key and a public key use
68
+ * designation for the first key is desired, the "enc" (encryption) key
69
+ * use value is used, since key wrapping is a kind of encryption. The
70
+ * "enc" value is also to be used for public keys used for key agreement
71
+ * operations.
72
+ */
73
+ export type JwkUse = 'sig' | 'enc' | string;
74
+ /**
75
+ * JSON Web Key Types
76
+ */
77
+ export type JwkType =
78
+ /**
79
+ * Elliptic Curve
80
+ * Used with Elliptic Curve Digital Signature Algorithm (ECDSA) and Elliptic
81
+ * Curve Diffie-Hellman (ECDH), including secp256k1, P-256, P-384, and P-521.
82
+ */
83
+ 'EC'
84
+ /**
85
+ * RSA
86
+ * Widely used for encryption and digital signatures. RSA keys are used in
87
+ * various algorithms like RS256, RS384, RS512, etc.
88
+ */
89
+ | 'RSA'
90
+ /**
91
+ * Octet sequence
92
+ * Used with symmetric signing (e.g., HMAC HS256, HS512, etc.) and
93
+ * symmetric encryption (e.g., A256CBC-HS512, A256GCM, etc.) algorithms.
94
+ */
95
+ | 'oct'
96
+ /**
97
+ * Octet string key pairs (OKP)
98
+ * A type of public key that is used with algorithms such as EdDSA (Ed25519 and
99
+ * Ed448 curves) and ECDH (X25519 and X448 curves).
100
+ */
101
+ | 'OKP';
102
+ /**
103
+ * JSON Web Key Elliptic Curve
104
+ */
105
+ export type JwkNamedCurves = 'P-256' | 'P-384' | 'P-521' | 'Ed25519' | 'Ed448' | 'X25519' | 'X448' | 'secp256k1';
106
+ /**
107
+ * JSON Web Key Parameters
108
+ */
109
+ /** Parameters used with any "kty" (key type) value. */
110
+ export type JwkParamsAnyKeyType = {
111
+ /** JWK Algorithm Parameter. The algorithm intended for use with the key. */
112
+ alg?: string;
113
+ /** JWK Extractable Parameter */
114
+ ext?: 'true' | 'false';
115
+ /** JWK Key Operations Parameter */
116
+ key_ops?: JwkOperation[];
117
+ /** JWK Key ID Parameter */
118
+ kid?: string;
119
+ /** JWK Key Type Parameter */
120
+ kty: JwkType;
121
+ /** JWK Public Key Use Parameter */
122
+ use?: JwkUse;
123
+ /** JWK X.509 Certificate Chain Parameter */
124
+ x5c?: string;
125
+ /** JWK X.509 Certificate SHA-1 Thumbprint Parameter */
126
+ x5t?: string;
127
+ /** JWK X.509 Certificate SHA-256 Thumbprint Parameter */
128
+ 'x5t#S256'?: string;
129
+ /** JWK X.509 URL Parameter */
130
+ x5u?: string;
131
+ };
132
+ /** Parameters used with "EC" (elliptic curve) public keys. */
133
+ export type JwkParamsEcPublic = Omit<JwkParamsAnyKeyType, 'alg' | 'kty'> & {
134
+ /**
135
+ * The algorithm intended for use with the key.
136
+ * ES256 : ECDSA using P-256 and SHA-256
137
+ * ES256K : ECDSA using secp256k1 curve and SHA-256
138
+ * ES384 : ECDSA using P-384 and SHA-384
139
+ * ES512 : ECDSA using P-521 and SHA-512
140
+ */
141
+ alg?: 'ES256' | 'ES256K' | 'ES384' | 'ES512';
142
+ /**
143
+ * Elliptic Curve key pair.
144
+ */
145
+ kty: 'EC';
146
+ /**
147
+ * The cryptographic curve used with the key.
148
+ * MUST be present for all EC public keys.
149
+ */
150
+ crv: 'secp256k1' | 'P-256' | 'P-384' | 'P-521';
151
+ /**
152
+ * The x-coordinate for the Elliptic Curve point.
153
+ * Represented as the base64url encoding of the octet string
154
+ * representation of the coordinate.
155
+ * MUST be present for all EC public keys
156
+ */
157
+ x: string;
158
+ /**
159
+ * The y-coordinate for the Elliptic Curve point.
160
+ * Represented as the base64url encoding of the octet string
161
+ * representation of the coordinate.
162
+ * MUST be present only for secp256k1 public keys.
163
+ */
164
+ y?: string;
165
+ };
166
+ /** Parameters used with "EC" (elliptic curve) private keys. */
167
+ export type JwkParamsEcPrivate = JwkParamsEcPublic & {
168
+ /**
169
+ * The d-coordinate for the Elliptic Curve point.
170
+ * Represented as the base64url encoding of the octet string
171
+ * representation of the coordinate.
172
+ * MUST be present for all EC private keys.
173
+ */
174
+ d: string;
175
+ };
176
+ /** Parameters used with "OKP" (octet key pair) public keys. */
177
+ export type JwkParamsOkpPublic = Omit<JwkParamsAnyKeyType, 'kty' | 'alg' | 'crv'> & Pick<JwkParamsEcPublic, 'x'> & {
178
+ /**
179
+ * The algorithm intended for use with the key.
180
+ * EdDSA: Edwards Curve Digital Signature Algorithm
181
+ */
182
+ alg?: 'EdDSA';
183
+ /**
184
+ * The cryptographic curve used with the key.
185
+ * MUST be present for all OKP public keys.
186
+ */
187
+ crv: 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
188
+ /**
189
+ * Key type
190
+ * OKP (Octet Key Pair) is defined for public key algorithms that use octet
191
+ * strings as private and public keys.
192
+ */
193
+ kty: 'OKP';
194
+ };
195
+ /** Parameters used with "OKP" (octet key pair) private keys. */
196
+ export type JwkParamsOkpPrivate = JwkParamsOkpPublic & {
197
+ /**
198
+ * The d-coordinate for the Edwards Curve point.
199
+ * Represented as the base64url encoding of the octet string
200
+ * representation of the coordinate.
201
+ * MUST be present for all EC private keys.
202
+ */
203
+ d: string;
204
+ };
205
+ /** Parameters used with "oct" (octet sequence) private keys. */
206
+ export type JwkParamsOctPrivate = Omit<JwkParamsAnyKeyType, 'alg' | 'kty'> & {
207
+ /**
208
+ * The algorithm intended for use with the key.
209
+ * Used with symmetric signing (e.g., HMAC HS256, etc.) and
210
+ * symmetric encryption (e.g., A256GCM, etc.) algorithms.
211
+ */
212
+ alg?: 'A128CBC' | 'A192CBC' | 'A256CBC' | 'A128CTR' | 'A192CTR' | 'A256CTR' | 'A128GCM' | 'A192GCM' | 'A256GCM' | 'HS256' | 'HS384' | 'HS512';
213
+ /**
214
+ * The "k" (key value) parameter contains the value of the symmetric
215
+ * (or other single-valued) key. It is represented as the base64url
216
+ * encoding of the octet sequence containing the key value.
217
+ */
218
+ k: string;
219
+ /**
220
+ * Key type
221
+ * oct (Octet Sequence) is defined for symmetric encryption and
222
+ * symmetric signature algorithms.
223
+ */
224
+ kty: 'oct';
225
+ };
226
+ /** Parameters Used with "RSA" public keys. */
227
+ export type JwkParamsRsaPublic = Omit<JwkParamsAnyKeyType, 'kty'> & {
228
+ /** Public exponent for RSA */
229
+ e: string;
230
+ /**
231
+ * Key type
232
+ * RSA is widely used for encryption and digital signatures.
233
+ */
234
+ kty: 'RSA';
235
+ /** Modulus for RSA */
236
+ n: string;
237
+ };
238
+ /** Parameters used with "RSA" private keys. */
239
+ export type JwkParamsRsaPrivate = JwkParamsRsaPublic & {
240
+ /** Private exponent for RSA */
241
+ d: string;
242
+ /** First prime factor for RSA */
243
+ p?: string;
244
+ /** Second prime factor for RSA */
245
+ q?: string;
246
+ /** First factor's CRT exponent for RSA */
247
+ dp?: string;
248
+ /** Second factor's CRT exponent for RSA */
249
+ dq?: string;
250
+ /** First CRT coefficient for RSA */
251
+ qi?: string;
252
+ /** Other primes information (optional in RFC 7518) */
253
+ oth?: {
254
+ /** Other primes' factor */
255
+ r: string;
256
+ /** Other primes' CRT exponent */
257
+ d: string;
258
+ /** Other primes' CRT coefficient */
259
+ t: string;
260
+ }[];
261
+ };
262
+ /** Parameters used with public keys in JWK format. */
263
+ export type PublicKeyJwk = JwkParamsEcPublic | JwkParamsOkpPublic | JwkParamsRsaPublic;
264
+ /** Parameters used with private keys in JWK format. */
265
+ export type PrivateKeyJwk = JwkParamsEcPrivate | JwkParamsOkpPrivate | JwkParamsOctPrivate | JwkParamsRsaPrivate;
266
+ /**
267
+ * JSON Web Key ({@link https://datatracker.ietf.org/doc/html/rfc7517 | JWK}).
268
+ * "RSA", "EC", "OKP", and "oct" key types are supported.
269
+ */
270
+ export interface Jwk {
271
+ /** JWK Algorithm Parameter. The algorithm intended for use with the key. */
272
+ alg?: string;
273
+ /** JWK Extractable Parameter */
274
+ ext?: 'true' | 'false';
275
+ /** JWK Key Operations Parameter */
276
+ key_ops?: JwkOperation[];
277
+ /** JWK Key ID Parameter */
278
+ kid?: string;
279
+ /** JWK Key Type Parameter */
280
+ kty: JwkType;
281
+ /** JWK Public Key Use Parameter */
282
+ use?: JwkUse;
283
+ /** JWK X.509 Certificate Chain Parameter */
284
+ x5c?: string;
285
+ /** JWK X.509 Certificate SHA-1 Thumbprint Parameter */
286
+ x5t?: string;
287
+ /** JWK X.509 Certificate SHA-256 Thumbprint Parameter */
288
+ 'x5t#S256'?: string;
289
+ /** JWK X.509 URL Parameter */
290
+ x5u?: string;
291
+ /** The cryptographic curve used with the key. */
292
+ crv?: string;
293
+ /** The x-coordinate for the Elliptic Curve point. */
294
+ x?: string;
295
+ /** The y-coordinate for the Elliptic Curve point. */
296
+ y?: string;
297
+ /** The "k" (key value) parameter contains the value of the symmetric (or other single-valued) key. */
298
+ k?: string;
299
+ /** Public exponent for RSA */
300
+ e?: string;
301
+ /** Modulus for RSA */
302
+ n?: string;
303
+ /** First prime factor for RSA */
304
+ p?: string;
305
+ /** Second prime factor for RSA */
306
+ q?: string;
307
+ /** First factor's CRT exponent for RSA */
308
+ dp?: string;
309
+ /** Second factor's CRT exponent for RSA */
310
+ dq?: string;
311
+ /** First CRT coefficient for RSA */
312
+ qi?: string;
313
+ /** Other primes information (optional in RFC 7518) */
314
+ oth?: {
315
+ /** Other primes' factor */
316
+ r: string;
317
+ /** Other primes' CRT exponent */
318
+ d: string;
319
+ /** Other primes' CRT coefficient */
320
+ t: string;
321
+ }[];
322
+ /** Private key component for EC, OKP, or RSA keys. */
323
+ d?: string;
324
+ [key: string]: unknown;
325
+ }
326
+ /**
327
+ * JSON Web Key Set ({@link https://datatracker.ietf.org/doc/html/rfc7517 | JWK Set})
328
+ *
329
+ * @remarks
330
+ * A JWK Set is a JSON object that represents a set of JWKs. The JSON object MUST have a "keys"
331
+ * member, with its value being an array of JWKs.
332
+ *
333
+ * Additional members can be present in the JWK Set but member names MUST be unique. If not
334
+ * understood by implementations encountering them, they MUST be ignored. Parameters for
335
+ * representing additional properties of JWK Sets should either be registered in the IANA
336
+ * "JSON Web Key Set Parameters" registry or be a value that contains a Collision-Resistant Name.
337
+ */
338
+ export interface JwkSet {
339
+ /** Array of JWKs */
340
+ keys: Jwk[];
341
+ }
342
+ /**
343
+ * Computes the thumbprint of a JSON Web Key (JWK) using the method
344
+ * specified in RFC 7638. This function accepts RSA, EC, OKP, and oct keys
345
+ * and returns the thumbprint as a base64url encoded SHA-256 hash of the
346
+ * JWK's required members, serialized and sorted lexicographically.
347
+ *
348
+ * Purpose:
349
+ * - Uniquely Identifying Keys: The thumbprint allows the unique
350
+ * identification of a specific JWK within a set of JWKs. It provides a
351
+ * deterministic way to generate a value that can be used as a key
352
+ * identifier (kid) or to match a specific key.
353
+ *
354
+ * - Simplifying Key Management: In systems where multiple keys are used,
355
+ * managing and identifying individual keys can become complex. The
356
+ * thumbprint method simplifies this by creating a standardized, unique
357
+ * identifier for each key.
358
+ *
359
+ * - Enabling Interoperability: By standardizing the method to compute a
360
+ * thumbprint, different systems can compute the same thumbprint value for
361
+ * a given JWK. This enables interoperability among systems that use JWKs.
362
+ *
363
+ * - Secure Comparison: The thumbprint provides a way to securely compare
364
+ * JWKs to determine if they are equivalent.
365
+ *
366
+ * @example
367
+ * ```ts
368
+ * const jwk: PublicKeyJwk = {
369
+ * 'kty': 'EC',
370
+ * 'crv': 'secp256k1',
371
+ * 'x': '61iPYuGefxotzBdQZtDvv6cWHZmXrTTscY-u7Y2pFZc',
372
+ * 'y': '88nPCVLfrAY9i-wg5ORcwVbHWC_tbeAd1JE2e0co0lU'
373
+ * };
374
+ *
375
+ * const thumbprint = jwkThumbprint(jwk);
376
+ * console.log(`JWK thumbprint: ${thumbprint}`);
377
+ * ```
378
+ *
379
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7638 | RFC7638} for
380
+ * the specification of JWK thumbprint computation.
381
+ *
382
+ * @param jwk - The JSON Web Key for which the thumbprint will be computed.
383
+ * This must be an RSA, EC, OKP, or oct key.
384
+ * @returns The thumbprint as a base64url encoded string.
385
+ * @throws Throws an `Error` if the provided key type is unsupported.
386
+ */
387
+ export declare function computeJwkThumbprint({ jwk }: {
388
+ jwk: Jwk;
389
+ }): Promise<string>;
390
+ /**
391
+ * Checks if the provided object is a valid elliptic curve private key in JWK format.
392
+ *
393
+ * @param obj - The object to check.
394
+ * @returns True if the object is a valid EC private JWK; otherwise, false.
395
+ */
396
+ export declare function isEcPrivateJwk(obj: unknown): obj is JwkParamsEcPrivate;
397
+ /**
398
+ * Checks if the provided object is a valid elliptic curve public key in JWK format.
399
+ *
400
+ * @param obj - The object to check.
401
+ * @returns True if the object is a valid EC public JWK; otherwise, false.
402
+ */
403
+ export declare function isEcPublicJwk(obj: unknown): obj is JwkParamsEcPublic;
404
+ /**
405
+ * Checks if the provided object is a valid octet sequence (symmetric key) in JWK format.
406
+ *
407
+ * @param obj - The object to check.
408
+ * @returns True if the object is a valid oct private JWK; otherwise, false.
409
+ */
410
+ export declare function isOctPrivateJwk(obj: unknown): obj is JwkParamsOctPrivate;
411
+ /**
412
+ * Checks if the provided object is a valid octet key pair private key in JWK format.
413
+ *
414
+ * @param obj - The object to check.
415
+ * @returns True if the object is a valid OKP private JWK; otherwise, false.
416
+ */
417
+ export declare function isOkpPrivateJwk(obj: unknown): obj is JwkParamsOkpPrivate;
418
+ /**
419
+ * Checks if the provided object is a valid octet key pair public key in JWK format.
420
+ *
421
+ * @param obj - The object to check.
422
+ * @returns True if the object is a valid OKP public JWK; otherwise, false.
423
+ */
424
+ export declare function isOkpPublicJwk(obj: unknown): obj is JwkParamsOkpPublic;
425
+ /**
426
+ * Checks if the provided object is a valid private key in JWK format of any supported type.
427
+ *
428
+ * @param obj - The object to check.
429
+ * @returns True if the object is a valid private JWK; otherwise, false.
430
+ */
431
+ export declare function isPrivateJwk(obj: unknown): obj is PrivateKeyJwk;
432
+ /**
433
+ * Checks if the provided object is a valid public key in JWK format of any supported type.
434
+ *
435
+ * @param obj - The object to check.
436
+ * @returns True if the object is a valid public JWK; otherwise, false.
437
+ */
438
+ export declare function isPublicJwk(obj: unknown): obj is PublicKeyJwk;
439
+ //# source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,MAAM,CAAC;QACV,oCAAoC;QACpC,CAAC,EAAE,MAAM,CAAC;KACX,EAAE,CAAC;IAIJ,sDAAsD;IACtD,CAAC,CAAC,EAAE,MAAM,CAAC;IAGX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,MAAM;IACrB,oBAAoB;IACpB,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,GAAG,EAAE,EAAE;IAClD,GAAG,EAAE,GAAG,CAAA;CACT,GAAG,OAAO,CAAC,MAAM,CAAC,CAiClB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAOtE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,iBAAiB,CAOpE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,mBAAmB,CAMxE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,mBAAmB,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAOtE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa,CAe/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAc7D"}
@@ -0,0 +1,67 @@
1
+ import type { Jwk } from './jwk.js';
2
+ /**
3
+ * JSON Object Signing and Encryption (JOSE) Header Parameters
4
+ *
5
+ * The Header Parameter names for use in both JWSs and JWEs are registered in the IANA "JSON Web
6
+ * Signature and Encryption Header Parameters" registry.
7
+ *
8
+ * As indicated by the common registry, JWSs and JWEs share a common Header Parameter space; when a
9
+ * parameter is used by both specifications, its usage must be compatible between the
10
+ * specifications.
11
+ *
12
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1 | RFC 7515, Section 4.1}
13
+ */
14
+ export interface JoseHeaderParams {
15
+ /** Content Type Header Parameter */
16
+ cty?: string;
17
+ /** JWK Set URL Header Parameter */
18
+ jku?: string;
19
+ /** JSON Web Key Header Parameter */
20
+ jwk?: Jwk;
21
+ /** Key ID Header Parameter */
22
+ kid?: string;
23
+ /** Type Header Parameter */
24
+ typ?: string;
25
+ /** X.509 Certificate Chain Header Parameter */
26
+ x5c?: string[];
27
+ /** X.509 Certificate SHA-1 Thumbprint Header Parameter */
28
+ x5t?: string;
29
+ /** X.509 URL Header Parameter */
30
+ x5u?: string;
31
+ }
32
+ /**
33
+ * JSON Web Signature (JWS) Header Parameters
34
+ *
35
+ * The Header Parameter names for use in JWSs are registered in the IANA "JSON Web Signature and
36
+ * Encryption Header Parameters" registry.
37
+ *
38
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1 | RFC 7515, Section 4.1}
39
+ */
40
+ export interface JwsHeaderParams extends JoseHeaderParams {
41
+ /**
42
+ * Algorithm Header Parameter
43
+ *
44
+ * Identifies the cryptographic algorithm used to secure the JWS. The JWS Signature value is not
45
+ * valid if the "alg" value does not represent a supported algorithm or if there is not a key for
46
+ * use with that algorithm associated with the party that digitally signed or MACed the content.
47
+ *
48
+ * "alg" values should either be registered in the IANA "JSON Web Signature and Encryption
49
+ * Algorithms" registry or be a value that contains a Collision-Resistant Name. The "alg" value is
50
+ * a case-sensitive ASCII string. This Header Parameter MUST be present and MUST be understood
51
+ * and processed by implementations.
52
+ *
53
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.1 | RFC 7515, Section 4.1.1}
54
+ */
55
+ alg: 'EdDSA' | 'ES256' | 'ES256K' | 'ES384' | 'ES512' | 'HS256' | 'HS384' | 'HS512' | string;
56
+ /**
57
+ * Critical Header Parameter
58
+ *
59
+ * Indicates that extensions to JOSE RFCs are being used that MUST be understood and processed.
60
+ */
61
+ crit?: string[];
62
+ /**
63
+ * Additional Public or Private Header Parameter names.
64
+ */
65
+ [key: string]: unknown;
66
+ }
67
+ //# sourceMappingURL=jws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jws.d.ts","sourceRoot":"","sources":["../../../src/jose/jws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,4BAA4B;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IAEf,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD;;;;;;;;;;;;;OAaG;IACH,GAAG,EAEC,OAAO,GAEP,OAAO,GAEP,QAAQ,GAER,OAAO,GAEP,OAAO,GAEP,OAAO,GAEP,OAAO,GAEP,OAAO,GAEP,MAAM,CAAC;IAEX;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IAEf;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB"}
@@ -0,0 +1,139 @@
1
+ import type { JweHeaderParams } from './jwe.js';
2
+ import type { JwsHeaderParams } from './jws.js';
3
+ /**
4
+ * JSON Web Token (JWT) Header
5
+ *
6
+ * For a JWT object, the members of the JSON object represented by the JOSE Header describe the
7
+ * cryptographic operations applied to the JWT and optionally, additional properties of the JWT.
8
+ * Depending upon whether the JWT is a JWS or JWE, the corresponding rules for the JOSE Header
9
+ * values apply.
10
+ *
11
+ * The {@link https://datatracker.ietf.org/doc/html/rfc7519#section-5 | RFC 7519} specification
12
+ * further specifies the use of the following Header Parameters in both the cases where the JWT is a
13
+ * JWS and where it is a JWE:
14
+ *
15
+ * - "typ" (type) Header Parameter: This Header Parameter is OPTIONAL. When used, this Header
16
+ * Parameter MUST be used to declare the MIME Media Type of this complete JWT. This parameter is
17
+ * ignored by JWT implementations; any processing of this parameter is performed by the JWT
18
+ * application. If present, it is RECOMMENDED that its value be "JWT" to indicate that this
19
+ * object is a JWT. While media type names are not case sensitive, it is RECOMMENDED that "JWT"
20
+ * always be spelled using uppercase characters for compatibility with legacy implementations.
21
+ *
22
+ * - "cty" (content type) Header Parameter: This Header Parameter is OPTIONAL. When used, this
23
+ * Header Parameter MUST be used to declare the MIME Media Type of the secured content (the
24
+ * payload). In the normal case in which nested signing or encryption operations are not employed,
25
+ * the use of this Header Parameter is NOT RECOMMENDED. In the case that nested signing or
26
+ * encryption is employed, this Header Parameter MUST be present; in this case, the value MUST be
27
+ * "JWT", to indicate that a Nested JWT is carried in this JWT. While media type names are not
28
+ * case sensitive, it is RECOMMENDED that "JWT" always be spelled using uppercase characters
29
+ * for compatibility with legacy implementations.
30
+ *
31
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-5 | RFC 7519, Section 5}
32
+ */
33
+ export type JwtHeaderParams = JwsHeaderParams | JweHeaderParams;
34
+ /**
35
+ * JSON Web Token Payload
36
+ *
37
+ * The JWT Claims Set represents a JSON object whose members are the claims conveyed by the JWT.
38
+ * The Claim Names within a JWT Claims Set MUST be unique; JWT parsers MUST either reject JWTs
39
+ * with duplicate Claim Names or use a JSON parser that returns only the lexically last duplicate
40
+ * member name.
41
+ *
42
+ * The set of claims that a JWT must contain to be considered valid is context dependent and is
43
+ * undefined by RFC 7519. Specific applications of JWTs will require implementations to understand
44
+ * and process some claims in particular ways.
45
+ *
46
+ * There are three classes of JWT Claim Names:
47
+ *
48
+ * - Registered Claim Names: Claim names registered in the IANA "JSON Web Token Claims" registry.
49
+ * None of the claims defined below are intended to be mandatory to use or implement in all cases,
50
+ * but rather they provide a starting point for a set of useful, interoperable claims
51
+ * Applications using JWTs should define which specific claims they use and when they are required
52
+ * or optional.
53
+ *
54
+ * - Public Claim Names: Claim Names can be defined at will by those using JWTs. However, in order
55
+ * prevent collisions, any new Claim Name should either be registered in the IANA "JSON Web Token
56
+ * Claims" registry or be a Public Name: a value that contains a Collision-Resistant Name. In each
57
+ * case, the definer of the name or value needs to take reasonable precautions to make sure they
58
+ * are in control of the part of the namespace they use to define the Claim Name.
59
+ *
60
+ * - Private Claim Names: A producer and consumer of a JWT MAY agree to use Claim Names that are
61
+ * Private Names: names that are not Registered Claim Names or Public Claim Names. Unlike Public
62
+ * Claim Names, Private Claim Names are subject to collision and should be used with caution.
63
+ *
64
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4 | RFC 7519, Section 4}
65
+ */
66
+ export interface JwtPayload {
67
+ /**
68
+ * Issuer
69
+ * Identifies the principal that issued the JWT. The "iss" value is a case-sensitive string
70
+ * containing a string or URI value. Use of this claim is OPTIONAL.
71
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1 | RFC 7519, Section 4.1.1}
72
+ */
73
+ iss?: string;
74
+ /**
75
+ * Subject
76
+ * Identifies the principal that is the subject of the JWT. The claims in a JWT are normally
77
+ * statements about the subject. The subject value MUST either be scoped to be locally unique in
78
+ * the context of the issuer or be globally unique. The "sub" value is a case-sensitive string
79
+ * containing a string or URI value. Use of this claim is OPTIONAL.
80
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 | RFC 7519, Section 4.1.2}
81
+ */
82
+ sub?: string;
83
+ /**
84
+ * Audience
85
+ * Identifies the recipients that the JWT is intended for. Each principal intended to process
86
+ * the JWT MUST identify itself with a value in the audience claim. If the principal processing
87
+ * the claim does not identify itself with a value in the "aud" claim when this claim is present,
88
+ * then the JWT MUST be rejected. In the general case, the "aud" value is an array of case-
89
+ * sensitive strings, each containing a string or URI value. In the special case when the JWT has
90
+ * one audience, the "aud" value MAY be a single case-sensitive string containing a string or URI
91
+ * value. Use of this claim is OPTIONAL.
92
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3 | RFC 7519, Section 4.1.3}
93
+ */
94
+ aud?: string | string[];
95
+ /**
96
+ * Expiration Time
97
+ * Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing.
98
+ * The processing of the "exp" claim requires that the current date/time MUST be before the
99
+ * expiration date/time listed in the "exp" claim. Implementers MAY provide for some small leeway,
100
+ * usually no more than a few minutes, to account for clock skew. Its value MUST be a number
101
+ * containing a numeric date value. Use of this claim is OPTIONAL.
102
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 | RFC 7519, Section 4.1.4}
103
+ */
104
+ exp?: number;
105
+ /**
106
+ * Not Before
107
+ * Identifies the time before which the JWT MUST NOT be accepted for processing. The processing
108
+ * of the "nbf" claim requires that the current date/time MUST be after or equal to the not-before
109
+ * date/time listed in the "nbf" claim. Implementers MAY provide for some small leeway, usually no
110
+ * more than a few minutes, to account for clock skew. Its value MUST be a number containing a
111
+ * numeric date value. Use of this claim is OPTIONAL.
112
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5 | RFC 7519, Section 4.1.5}
113
+ */
114
+ nbf?: number;
115
+ /**
116
+ * Issued At
117
+ * Identifies the time at which the JWT was issued. This claim can be used to determine the age
118
+ * of the JWT. Its value MUST be a number containing a numeric date value. Use of this claim is
119
+ * OPTIONAL.
120
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6 | RFC 7519, Section 4.1.6}
121
+ */
122
+ iat?: number;
123
+ /**
124
+ * JWT ID
125
+ * Provides a unique identifier for the JWT. The identifier value MUST be assigned in a manner
126
+ * that ensures that there is a negligible probability that the same value will be accidentally
127
+ * assigned to a different data object; if the application uses multiple issuers, collisions
128
+ * MUST be prevented among values produced by different issuers as well. The "jti" claim can be
129
+ * used to prevent the JWT from being replayed. The "jti" value is a case-sensitive string.
130
+ * Use of this claim is OPTIONAL.
131
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7 | RFC 7519, Section 4.1.7}
132
+ */
133
+ jti?: string;
134
+ /**
135
+ * Additional Public or Private Claim names.
136
+ */
137
+ [key: string]: unknown;
138
+ }
139
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/jose/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,eAAe,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;OAUG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}