@pagopa/io-react-native-jwt 0.5.0 → 0.6.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 (39) hide show
  1. package/LICENSE +201 -20
  2. package/README.md +14 -0
  3. package/lib/commonjs/index.js +60 -72
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/jwk/index.js +26 -1
  6. package/lib/commonjs/jwk/index.js.map +1 -1
  7. package/lib/commonjs/jwt/index.js +49 -3
  8. package/lib/commonjs/jwt/index.js.map +1 -1
  9. package/lib/commonjs/types.js +63 -0
  10. package/lib/commonjs/types.js.map +1 -1
  11. package/lib/commonjs/utils/errors.js +23 -1
  12. package/lib/commonjs/utils/errors.js.map +1 -1
  13. package/lib/module/index.js +6 -6
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/jwk/index.js +25 -0
  16. package/lib/module/jwk/index.js.map +1 -1
  17. package/lib/module/jwt/index.js +47 -3
  18. package/lib/module/jwt/index.js.map +1 -1
  19. package/lib/module/types.js +56 -0
  20. package/lib/module/types.js.map +1 -1
  21. package/lib/module/utils/errors.js +20 -0
  22. package/lib/module/utils/errors.js.map +1 -1
  23. package/lib/typescript/index.d.ts +7 -6
  24. package/lib/typescript/index.d.ts.map +1 -1
  25. package/lib/typescript/jwk/index.d.ts +9 -1
  26. package/lib/typescript/jwk/index.d.ts.map +1 -1
  27. package/lib/typescript/jwt/index.d.ts +31 -3
  28. package/lib/typescript/jwt/index.d.ts.map +1 -1
  29. package/lib/typescript/types.d.ts +328 -31
  30. package/lib/typescript/types.d.ts.map +1 -1
  31. package/lib/typescript/utils/errors.d.ts +14 -0
  32. package/lib/typescript/utils/errors.d.ts.map +1 -1
  33. package/package.json +3 -2
  34. package/src/index.ts +16 -0
  35. package/src/jwk/index.ts +28 -1
  36. package/src/jwt/index.ts +58 -5
  37. package/src/types.ts +43 -32
  38. package/src/utils/errors.ts +22 -0
  39. package/src/index.tsx +0 -10
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { z } from 'zod';
2
+
1
3
  export interface JWTDecodeResult {
2
4
  /** JWT Claims Set. */
3
5
  payload: JWTPayload;
@@ -166,46 +168,55 @@ export interface JWTClaimVerificationOptions {
166
168
  requiredClaims?: string[];
167
169
  }
168
170
 
169
- export interface JWK {
170
- /** JWK "alg" (Algorithm) Parameter. */
171
- 'alg'?: string;
172
- 'crv'?: string;
173
- 'd'?: string;
174
- 'dp'?: string;
175
- 'dq'?: string;
176
- 'e'?: string;
171
+ export type JWK = z.infer<typeof JWK>;
172
+ export const JWK = z.object({
173
+ 'alg': z.string().optional(),
174
+ 'crv': z.string().optional(),
175
+ 'd': z.string().optional(),
176
+ 'dp': z.string().optional(),
177
+ 'dq': z.string().optional(),
178
+ 'e': z.string().optional(),
177
179
  /** JWK "ext" (Extractable) Parameter. */
178
- 'ext'?: boolean;
179
- 'k'?: string;
180
+ 'ext': z.boolean().optional(),
181
+ 'k': z.string().optional(),
180
182
  /** JWK "key_ops" (Key Operations) Parameter. */
181
- 'key_ops'?: string[];
183
+ 'key_ops': z.array(z.string()).optional(),
182
184
  /** JWK "kid" (Key ID) Parameter. */
183
- 'kid'?: string;
185
+ 'kid': z.string().optional(),
184
186
  /** JWK "kty" (Key Type) Parameter.
185
187
  * This attribute is required to discriminate the
186
188
  * type of EC/RSA algorithm */
187
- 'kty': string;
188
- 'n'?: string;
189
- 'oth'?: Array<{
190
- d?: string;
191
- r?: string;
192
- t?: string;
193
- }>;
194
- 'p'?: string;
195
- 'q'?: string;
196
- 'qi'?: string;
189
+ 'kty': z.string(),
190
+ 'n': z.string().optional(),
191
+ 'oth': z
192
+ .array(
193
+ z.object({
194
+ d: z.string().optional(),
195
+ r: z.string().optional(),
196
+ t: z.string().optional(),
197
+ })
198
+ )
199
+ .optional(),
200
+ 'p': z.string().optional(),
201
+ 'q': z.string().optional(),
202
+ 'qi': z.string().optional(),
197
203
  /** JWK "use" (Public Key Use) Parameter. */
198
- 'use'?: string;
199
- 'x'?: string;
200
- 'y'?: string;
204
+ 'use': z.string().optional(),
205
+ 'x': z.string().optional(),
206
+ 'y': z.string().optional(),
201
207
  /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
202
- 'x5c'?: string[];
208
+ 'x5c': z.array(z.string()).optional(),
203
209
  /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
204
- 'x5t'?: string;
210
+ 'x5t': z.string().optional(),
205
211
  /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
206
- 'x5t#S256'?: string;
212
+ 'x5t#S256': z.string().optional(),
207
213
  /** JWK "x5u" (X.509 URL) Parameter. */
208
- 'x5u'?: string;
209
-
210
- [propName: string]: unknown;
211
- }
214
+ 'x5u': z.string().optional(),
215
+ });
216
+
217
+ export type WithJWKS = z.infer<typeof WithJWKS>;
218
+ export const WithJWKS = z.object({
219
+ jwks: z.object({
220
+ keys: z.array(JWK),
221
+ }),
222
+ });
@@ -231,3 +231,25 @@ export class JWEInvalid extends JOSEError {
231
231
 
232
232
  code = 'ERR_JWE_INVALID';
233
233
  }
234
+
235
+ /**
236
+ * An error subclass thrown when a JWKSet is invalid.
237
+ */
238
+ export class JWKSetInvalid extends JOSEError {
239
+ static get code(): 'ERR_JWKS_INVALID' {
240
+ return 'ERR_JWKS_INVALID';
241
+ }
242
+
243
+ code = 'ERR_JWKS_INVALID';
244
+ }
245
+
246
+ /**
247
+ * An error subclass thrown when a JWK is not found.
248
+ */
249
+ export class JWKNotFound extends JOSEError {
250
+ static get code(): 'ERR_JWK_NOT_FOUND' {
251
+ return 'ERR_JWK_NOT_FOUND';
252
+ }
253
+
254
+ code = 'ERR_JWK_NOT_FOUND';
255
+ }
package/src/index.tsx DELETED
@@ -1,10 +0,0 @@
1
- export * from './jwe/index';
2
- export * from './jwt/index';
3
- export * from './jwk/index';
4
- export * from './jwt/produce';
5
- export * from './jwt/sign';
6
- export * from './jwt/unsecured';
7
-
8
- export { derToJose } from './utils/asn1';
9
- export { encodeBase64, decodeBase64 } from './utils/base64';
10
- export { sha256ToBase64 } from './hash';