jose 5.8.0 → 5.9.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 (46) hide show
  1. package/README.md +21 -17
  2. package/dist/browser/jwks/remote.js +1 -1
  3. package/dist/browser/jws/flattened/sign.js +2 -2
  4. package/dist/browser/jws/flattened/verify.js +10 -2
  5. package/dist/browser/lib/check_key_type.js +40 -9
  6. package/dist/browser/lib/invalid_key_input.js +1 -0
  7. package/dist/browser/lib/is_jwk.js +13 -0
  8. package/dist/browser/runtime/get_sign_verify_key.js +1 -1
  9. package/dist/browser/runtime/normalize_key.js +21 -4
  10. package/dist/node/cjs/jwks/remote.js +1 -1
  11. package/dist/node/cjs/jws/flattened/sign.js +1 -1
  12. package/dist/node/cjs/jws/flattened/verify.js +9 -1
  13. package/dist/node/cjs/lib/check_key_type.js +41 -9
  14. package/dist/node/cjs/lib/invalid_key_input.js +1 -0
  15. package/dist/node/cjs/lib/is_jwk.js +20 -0
  16. package/dist/node/cjs/runtime/base64url.js +1 -1
  17. package/dist/node/cjs/runtime/check_key_length.js +11 -1
  18. package/dist/node/cjs/runtime/get_named_curve.js +4 -0
  19. package/dist/node/cjs/runtime/get_sign_verify_key.js +8 -1
  20. package/dist/node/cjs/runtime/node_key.js +51 -14
  21. package/dist/node/cjs/runtime/sign.js +3 -3
  22. package/dist/node/cjs/runtime/verify.js +3 -3
  23. package/dist/node/esm/jwks/remote.js +1 -1
  24. package/dist/node/esm/jws/flattened/sign.js +2 -2
  25. package/dist/node/esm/jws/flattened/verify.js +10 -2
  26. package/dist/node/esm/lib/check_key_type.js +40 -9
  27. package/dist/node/esm/lib/invalid_key_input.js +1 -0
  28. package/dist/node/esm/lib/is_jwk.js +13 -0
  29. package/dist/node/esm/runtime/base64url.js +1 -1
  30. package/dist/node/esm/runtime/check_key_length.js +11 -1
  31. package/dist/node/esm/runtime/get_named_curve.js +4 -0
  32. package/dist/node/esm/runtime/get_sign_verify_key.js +8 -1
  33. package/dist/node/esm/runtime/node_key.js +52 -15
  34. package/dist/node/esm/runtime/sign.js +3 -3
  35. package/dist/node/esm/runtime/verify.js +3 -3
  36. package/dist/types/index.d.ts +1 -1
  37. package/dist/types/jws/compact/sign.d.ts +2 -2
  38. package/dist/types/jws/compact/verify.d.ts +3 -3
  39. package/dist/types/jws/flattened/sign.d.ts +2 -2
  40. package/dist/types/jws/flattened/verify.d.ts +3 -3
  41. package/dist/types/jws/general/sign.d.ts +2 -2
  42. package/dist/types/jws/general/verify.d.ts +3 -3
  43. package/dist/types/jwt/sign.d.ts +2 -2
  44. package/dist/types/jwt/verify.d.ts +3 -3
  45. package/dist/types/types.d.ts +151 -29
  46. package/package.json +1 -1
@@ -29,59 +29,175 @@
29
29
  */
30
30
  export type KeyLike = { type: string }
31
31
 
32
+ /** Generic JSON Web Key Parameters. */
33
+ export interface JWKParameters {
34
+ /** JWK "kty" (Key Type) Parameter. */
35
+ kty: string
36
+ /** JWK "alg" (Algorithm) Parameter. */
37
+ alg?: string
38
+ /** JWK "key_ops" (Key Operations) Parameter. */
39
+ key_ops?: string[]
40
+ /** JWK "ext" (Extractable) Parameter. */
41
+ ext?: boolean
42
+ /** JWK "use" (Public Key Use) Parameter. */
43
+ use?: string
44
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
45
+ x5c?: string[]
46
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
47
+ x5t?: string
48
+ /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
49
+ 'x5t#S256'?: string
50
+ /** JWK "x5u" (X.509 URL) Parameter. */
51
+ x5u?: string
52
+ /** JWK "kid" (Key ID) Parameter. */
53
+ kid?: string
54
+
55
+ [propName: string]: unknown
56
+ }
57
+
58
+ /** Convenience interface for Public OKP JSON Web Keys */
59
+ export interface JWK_OKP_Public extends JWKParameters {
60
+ /** The Subtype of Key Pair */
61
+ crv: string
62
+ /** The public key */
63
+ x: string
64
+
65
+ [propName: string]: unknown
66
+ }
67
+
68
+ /** Convenience interface for Private OKP JSON Web Keys */
69
+ export interface JWK_OKP_Private extends JWK_OKP_Public, JWKParameters {
70
+ /** The Private Key */
71
+ d: string
72
+
73
+ [propName: string]: unknown
74
+ }
75
+
76
+ /** Convenience interface for Public EC JSON Web Keys */
77
+ export interface JWK_EC_Public extends JWKParameters {
78
+ /** Curve */
79
+ crv: string
80
+ /** X Coordinate */
81
+ x: string
82
+ /** Y Coordinate */
83
+ y: string
84
+
85
+ [propName: string]: unknown
86
+ }
87
+
88
+ /** Convenience interface for Private EC JSON Web Keys */
89
+ export interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
90
+ /** ECC Private Key */
91
+ d: string
92
+
93
+ [propName: string]: unknown
94
+ }
95
+
96
+ /** Convenience interface for Public RSA JSON Web Keys */
97
+ export interface JWK_RSA_Public extends JWKParameters {
98
+ /** Exponent */
99
+ e: string
100
+ /** Modulus */
101
+ n: string
102
+
103
+ [propName: string]: unknown
104
+ }
105
+
106
+ /** Convenience interface for Private RSA JSON Web Keys */
107
+ export interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
108
+ /** Private Exponent */
109
+ d: string
110
+ /** First Factor CRT Exponent */
111
+ dp: string
112
+ /** Second Factor CRT Exponent */
113
+ dq: string
114
+ /** Other Primes Info. This parameter is not supported. */
115
+ oth?: Array<{
116
+ d?: string
117
+ r?: string
118
+ t?: string
119
+ }>
120
+ /** First Prime Factor */
121
+ p: string
122
+ /** Second Prime Factor */
123
+ q: string
124
+ /** First CRT Coefficient */
125
+ qi: string
126
+
127
+ [propName: string]: unknown
128
+ }
129
+
130
+ /** Convenience interface for oct JSON Web Keys */
131
+ export interface JWK_oct extends JWKParameters {
132
+ /** Key Value */
133
+ k: string
134
+
135
+ [propName: string]: unknown
136
+ }
137
+
32
138
  /**
33
139
  * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", and "oct"
34
140
  * key types are supported.
141
+ *
142
+ * @see {@link JWK_OKP_Public}
143
+ * @see {@link JWK_OKP_Private}
144
+ * @see {@link JWK_EC_Public}
145
+ * @see {@link JWK_EC_Private}
146
+ * @see {@link JWK_RSA_Public}
147
+ * @see {@link JWK_RSA_Private}
148
+ * @see {@link JWK_oct}
35
149
  */
36
- export interface JWK {
37
- /** JWK "alg" (Algorithm) Parameter. */
38
- alg?: string
150
+ export interface JWK extends JWKParameters {
151
+ /**
152
+ * - (EC) Curve
153
+ * - (OKP) The Subtype of Key Pair
154
+ */
39
155
  crv?: string
156
+ /**
157
+ * - (Private RSA) Private Exponent
158
+ * - (Private EC) ECC Private Key
159
+ * - (Private OKP) The Private Key
160
+ */
40
161
  d?: string
162
+ /** (Private RSA) First Factor CRT Exponent */
41
163
  dp?: string
164
+ /** (Private RSA) Second Factor CRT Exponent */
42
165
  dq?: string
166
+ /** (RSA) Exponent */
43
167
  e?: string
44
- /** JWK "ext" (Extractable) Parameter. */
45
- ext?: boolean
168
+ /** (oct) Key Value */
46
169
  k?: string
47
- /** JWK "key_ops" (Key Operations) Parameter. */
48
- key_ops?: string[]
49
- /** JWK "kid" (Key ID) Parameter. */
50
- kid?: string
51
- /** JWK "kty" (Key Type) Parameter. */
52
- kty?: string
170
+ /** (RSA) Modulus */
53
171
  n?: string
172
+ /** (Private RSA) Other Primes Info. This parameter is not supported. */
54
173
  oth?: Array<{
55
174
  d?: string
56
175
  r?: string
57
176
  t?: string
58
177
  }>
178
+ /** (Private RSA) First Prime Factor */
59
179
  p?: string
180
+ /** (Private RSA) Second Prime Factor */
60
181
  q?: string
182
+ /** (Private RSA) First CRT Coefficient */
61
183
  qi?: string
62
- /** JWK "use" (Public Key Use) Parameter. */
63
- use?: string
184
+ /**
185
+ * - (EC) X Coordinate
186
+ * - (OKP) The public key
187
+ */
64
188
  x?: string
189
+ /** (EC) Y Coordinate */
65
190
  y?: string
66
- /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
67
- x5c?: string[]
68
- /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
69
- x5t?: string
70
- /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
71
- 'x5t#S256'?: string
72
- /** JWK "x5u" (X.509 URL) Parameter. */
73
- x5u?: string
74
191
 
75
192
  [propName: string]: unknown
76
193
  }
77
194
 
78
195
  /**
79
- * Generic Interface for consuming operations dynamic key resolution.
196
+ * @private
80
197
  *
81
- * @param IProtectedHeader Type definition of the JWE or JWS Protected Header.
82
- * @param IToken Type definition of the consumed JWE or JWS token.
198
+ * @internal
83
199
  */
84
- export interface GetKeyFunction<IProtectedHeader, IToken> {
200
+ export interface GenericGetKeyFunction<IProtectedHeader, IToken, ReturnKeyTypes> {
85
201
  /**
86
202
  * Dynamic key resolution function. No token components have been verified at the time of this
87
203
  * function call.
@@ -91,12 +207,18 @@ export interface GetKeyFunction<IProtectedHeader, IToken> {
91
207
  * @param protectedHeader JWE or JWS Protected Header.
92
208
  * @param token The consumed JWE or JWS token.
93
209
  */
94
- (
95
- protectedHeader: IProtectedHeader,
96
- token: IToken,
97
- ): Promise<KeyLike | Uint8Array> | KeyLike | Uint8Array
210
+ (protectedHeader: IProtectedHeader, token: IToken): Promise<ReturnKeyTypes> | ReturnKeyTypes
98
211
  }
99
212
 
213
+ /**
214
+ * Generic Interface for consuming operations dynamic key resolution.
215
+ *
216
+ * @param IProtectedHeader Type definition of the JWE or JWS Protected Header.
217
+ * @param IToken Type definition of the consumed JWE or JWS token.
218
+ */
219
+ export interface GetKeyFunction<IProtectedHeader, IToken>
220
+ extends GenericGetKeyFunction<IProtectedHeader, IToken, KeyLike | Uint8Array> {}
221
+
100
222
  /**
101
223
  * Flattened JWS definition for verify function inputs, allows payload as Uint8Array for detached
102
224
  * signature validation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "5.8.0",
3
+ "version": "5.9.1",
4
4
  "description": "JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "browser",