@oari/jose 0.0.0

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 (88) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +150 -0
  3. package/dist/types/index.d.ts +55 -0
  4. package/dist/types/jwe/compact/decrypt.d.ts +43 -0
  5. package/dist/types/jwe/compact/encrypt.d.ts +76 -0
  6. package/dist/types/jwe/flattened/decrypt.d.ts +53 -0
  7. package/dist/types/jwe/flattened/encrypt.d.ts +95 -0
  8. package/dist/types/jwe/general/decrypt.d.ts +64 -0
  9. package/dist/types/jwe/general/encrypt.d.ts +89 -0
  10. package/dist/types/jwk/embedded.d.ts +31 -0
  11. package/dist/types/jwk/thumbprint.d.ts +60 -0
  12. package/dist/types/jwks/local.d.ts +90 -0
  13. package/dist/types/jwks/remote.d.ts +306 -0
  14. package/dist/types/jws/compact/sign.d.ts +47 -0
  15. package/dist/types/jws/compact/verify.d.ts +45 -0
  16. package/dist/types/jws/flattened/sign.d.ts +53 -0
  17. package/dist/types/jws/flattened/verify.d.ts +50 -0
  18. package/dist/types/jws/general/sign.d.ts +67 -0
  19. package/dist/types/jws/general/verify.d.ts +61 -0
  20. package/dist/types/jwt/decrypt.d.ts +51 -0
  21. package/dist/types/jwt/encrypt.d.ts +105 -0
  22. package/dist/types/jwt/sign.d.ts +140 -0
  23. package/dist/types/jwt/unsecured.d.ts +70 -0
  24. package/dist/types/jwt/verify.d.ts +124 -0
  25. package/dist/types/key/export.d.ts +59 -0
  26. package/dist/types/key/generate_key_pair.d.ts +64 -0
  27. package/dist/types/key/generate_secret.d.ts +42 -0
  28. package/dist/types/key/import.d.ts +146 -0
  29. package/dist/types/types.d.ts +869 -0
  30. package/dist/types/util/base64url.d.ts +9 -0
  31. package/dist/types/util/decode_jwt.d.ts +25 -0
  32. package/dist/types/util/decode_protected_header.d.ts +24 -0
  33. package/dist/types/util/errors.d.ts +488 -0
  34. package/dist/webapi/index.js +32 -0
  35. package/dist/webapi/jwe/compact/decrypt.js +27 -0
  36. package/dist/webapi/jwe/compact/encrypt.js +27 -0
  37. package/dist/webapi/jwe/flattened/decrypt.js +159 -0
  38. package/dist/webapi/jwe/flattened/encrypt.js +167 -0
  39. package/dist/webapi/jwe/general/decrypt.js +31 -0
  40. package/dist/webapi/jwe/general/encrypt.js +182 -0
  41. package/dist/webapi/jwk/embedded.js +17 -0
  42. package/dist/webapi/jwk/thumbprint.js +68 -0
  43. package/dist/webapi/jwks/local.js +119 -0
  44. package/dist/webapi/jwks/remote.js +179 -0
  45. package/dist/webapi/jws/compact/sign.js +18 -0
  46. package/dist/webapi/jws/compact/verify.js +21 -0
  47. package/dist/webapi/jws/flattened/sign.js +87 -0
  48. package/dist/webapi/jws/flattened/verify.js +110 -0
  49. package/dist/webapi/jws/general/sign.js +70 -0
  50. package/dist/webapi/jws/general/verify.js +24 -0
  51. package/dist/webapi/jwt/decrypt.js +23 -0
  52. package/dist/webapi/jwt/encrypt.js +101 -0
  53. package/dist/webapi/jwt/sign.js +52 -0
  54. package/dist/webapi/jwt/unsecured.js +63 -0
  55. package/dist/webapi/jwt/verify.js +15 -0
  56. package/dist/webapi/key/export.js +11 -0
  57. package/dist/webapi/key/generate_key_pair.js +97 -0
  58. package/dist/webapi/key/generate_secret.js +40 -0
  59. package/dist/webapi/key/import.js +57 -0
  60. package/dist/webapi/lib/aesgcmkw.js +15 -0
  61. package/dist/webapi/lib/aeskw.js +25 -0
  62. package/dist/webapi/lib/asn1.js +243 -0
  63. package/dist/webapi/lib/base64.js +22 -0
  64. package/dist/webapi/lib/buffer_utils.js +43 -0
  65. package/dist/webapi/lib/check_key_type.js +127 -0
  66. package/dist/webapi/lib/content_encryption.js +217 -0
  67. package/dist/webapi/lib/crypto_key.js +136 -0
  68. package/dist/webapi/lib/deflate.js +44 -0
  69. package/dist/webapi/lib/ecdhes.js +52 -0
  70. package/dist/webapi/lib/helpers.js +19 -0
  71. package/dist/webapi/lib/invalid_key_input.js +27 -0
  72. package/dist/webapi/lib/is_key_like.js +17 -0
  73. package/dist/webapi/lib/jwk_to_key.js +107 -0
  74. package/dist/webapi/lib/jwt_claims_set.js +238 -0
  75. package/dist/webapi/lib/key_management.js +186 -0
  76. package/dist/webapi/lib/key_to_jwk.js +31 -0
  77. package/dist/webapi/lib/normalize_key.js +166 -0
  78. package/dist/webapi/lib/pbes2kw.js +42 -0
  79. package/dist/webapi/lib/rsaes.js +24 -0
  80. package/dist/webapi/lib/signing.js +74 -0
  81. package/dist/webapi/lib/type_checks.js +41 -0
  82. package/dist/webapi/lib/validate_algorithms.js +10 -0
  83. package/dist/webapi/lib/validate_crit.js +33 -0
  84. package/dist/webapi/util/base64url.js +30 -0
  85. package/dist/webapi/util/decode_jwt.js +32 -0
  86. package/dist/webapi/util/decode_protected_header.js +34 -0
  87. package/dist/webapi/util/errors.js +99 -0
  88. package/package.json +195 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Signing JSON Web Signature (JWS) in General JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /** Used to build General JWS object's individual signatures. */
8
+ export interface Signature {
9
+ /**
10
+ * Sets the JWS Protected Header on the Signature object.
11
+ *
12
+ * @param protectedHeader JWS Protected Header.
13
+ */
14
+ setProtectedHeader(protectedHeader: types.JWSHeaderParameters): Signature;
15
+ /**
16
+ * Sets the JWS Unprotected Header on the Signature object.
17
+ *
18
+ * @param unprotectedHeader JWS Unprotected Header.
19
+ */
20
+ setUnprotectedHeader(unprotectedHeader: types.JWSHeaderParameters): Signature;
21
+ /** A shorthand for calling addSignature() on the enclosing {@link GeneralSign} instance */
22
+ addSignature(...args: Parameters<GeneralSign['addSignature']>): Signature;
23
+ /** A shorthand for calling encrypt() on the enclosing {@link GeneralSign} instance */
24
+ sign(...args: Parameters<GeneralSign['sign']>): Promise<types.GeneralJWS>;
25
+ /** Returns the enclosing {@link GeneralSign} instance */
26
+ done(): GeneralSign;
27
+ }
28
+ /**
29
+ * The GeneralSign class is used to build and sign General JWS objects.
30
+ *
31
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
32
+ * from its subpath export `'jose/jws/general/sign'`.
33
+ *
34
+ * @example
35
+ *
36
+ * ```js
37
+ * const jws = await new jose.GeneralSign(
38
+ * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
39
+ * )
40
+ * .addSignature(ecPrivateKey)
41
+ * .setProtectedHeader({ alg: 'ES256' })
42
+ * .addSignature(rsaPrivateKey)
43
+ * .setProtectedHeader({ alg: 'PS256' })
44
+ * .sign()
45
+ *
46
+ * console.log(jws)
47
+ * ```
48
+ */
49
+ export declare class GeneralSign {
50
+ #private;
51
+ /**
52
+ * {@link GeneralSign} constructor
53
+ *
54
+ * @param payload Binary representation of the payload to sign.
55
+ */
56
+ constructor(payload: Uint8Array);
57
+ /**
58
+ * Adds an additional signature for the General JWS object.
59
+ *
60
+ * @param key Private Key or Secret to sign the individual JWS signature with. See
61
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
62
+ * @param options JWS Sign options.
63
+ */
64
+ addSignature(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.SignOptions): Signature;
65
+ /** Signs and resolves the value of the General JWS object. */
66
+ sign(): Promise<types.GeneralJWS>;
67
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Verifying JSON Web Signature (JWS) in General JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * Interface for General JWS Verification dynamic key resolution. No token components have been
9
+ * verified at the time of this function call.
10
+ *
11
+ * @see {@link jwks/remote.createRemoteJWKSet createRemoteJWKSet} to verify using a remote JSON Web Key Set.
12
+ */
13
+ export interface GeneralVerifyGetKey extends types.GenericGetKeyFunction<types.JWSHeaderParameters, types.FlattenedJWSInput, types.CryptoKey | types.KeyObject | types.JWK | Uint8Array> {
14
+ }
15
+ /**
16
+ * Verifies the signature and format of and afterwards decodes the General JWS.
17
+ *
18
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
19
+ * as from its subpath export `'jose/jws/general/verify'`.
20
+ *
21
+ * > [!NOTE]\
22
+ * > The function iterates over the `signatures` array in the General JWS and returns the verification
23
+ * > result of the first signature entry that can be successfully verified. The result only contains
24
+ * > the payload, protected header, and unprotected header of that successfully verified signature
25
+ * > entry. Other signature entries in the General JWS are not validated, and their headers are not
26
+ * > included in the returned result. Recipients of a General JWS should only rely on the returned
27
+ * > (verified) data.
28
+ *
29
+ * @example
30
+ *
31
+ * ```js
32
+ * const jws = {
33
+ * payload: 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4',
34
+ * signatures: [
35
+ * {
36
+ * signature:
37
+ * 'FVVOXwj6kD3DqdfD9yYqfT2W9jv-Nop4kOehp_DeDGNB5dQNSPRvntBY6xH3uxlCxE8na9d_kyhYOcanpDJ0EA',
38
+ * protected: 'eyJhbGciOiJFUzI1NiJ9',
39
+ * },
40
+ * ],
41
+ * }
42
+ *
43
+ * const { payload, protectedHeader } = await jose.generalVerify(jws, publicKey)
44
+ *
45
+ * console.log(protectedHeader)
46
+ * console.log(new TextDecoder().decode(payload))
47
+ * ```
48
+ *
49
+ * @param jws General JWS.
50
+ * @param key Key to verify the JWS with. See
51
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
52
+ * @param options JWS Verify options.
53
+ */
54
+ export declare function generalVerify(jws: types.GeneralJWSInput, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.VerifyOptions): Promise<types.GeneralVerifyResult>;
55
+ /**
56
+ * @param jws General JWS.
57
+ * @param getKey Function resolving a key to verify the JWS with. See
58
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
59
+ * @param options JWS Verify options.
60
+ */
61
+ export declare function generalVerify(jws: types.GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: types.VerifyOptions): Promise<types.GeneralVerifyResult & types.ResolvedKey>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * JSON Web Token (JWT) Decryption (JWT is in JWE format)
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Combination of JWE Decryption options and JWT Claims Set verification options. */
8
+ export interface JWTDecryptOptions extends types.DecryptOptions, types.JWTClaimVerificationOptions {
9
+ }
10
+ /**
11
+ * Interface for JWT Decryption dynamic key resolution. No token components have been verified at
12
+ * the time of this function call.
13
+ */
14
+ export interface JWTDecryptGetKey extends types.GetKeyFunction<types.CompactJWEHeaderParameters, types.FlattenedJWE> {
15
+ }
16
+ /**
17
+ * Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT
18
+ * Claims Set.
19
+ *
20
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
21
+ * as from its subpath export `'jose/jwt/decrypt'`.
22
+ *
23
+ * @example
24
+ *
25
+ * ```js
26
+ * const secret = jose.base64url.decode('zH4NRP1HMALxxCFnRZABFA7GOJtzU_gIj02alfL1lvI')
27
+ * const jwt =
28
+ * 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..MB66qstZBPxAXKdsjet_lA.WHbtJTl4taHp7otOHLq3hBvv0yNPsPEKHYInmCPdDDeyV1kU-f-tGEiU4FxlSqkqAT2hVs8_wMNiQFAzPU1PUgIqWCPsBrPP3TtxYsrtwagpn4SvCsUsx0Mhw9ZhliAO8CLmCBQkqr_T9AcYsz5uZw.7nX9m7BGUu_u1p1qFHzyIg'
29
+ *
30
+ * const { payload, protectedHeader } = await jose.jwtDecrypt(jwt, secret, {
31
+ * issuer: 'urn:example:issuer',
32
+ * audience: 'urn:example:audience',
33
+ * })
34
+ *
35
+ * console.log(protectedHeader)
36
+ * console.log(payload)
37
+ * ```
38
+ *
39
+ * @param jwt JSON Web Token value (encoded as JWE).
40
+ * @param key Private Key or Secret to decrypt and verify the JWT with. See
41
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
42
+ * @param options JWT Decryption and JWT Claims Set validation options.
43
+ */
44
+ export declare function jwtDecrypt<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: JWTDecryptOptions): Promise<types.JWTDecryptResult<PayloadType>>;
45
+ /**
46
+ * @param jwt JSON Web Token value (encoded as JWE).
47
+ * @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with. See
48
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
49
+ * @param options JWT Decryption and JWT Claims Set validation options.
50
+ */
51
+ export declare function jwtDecrypt<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<types.JWTDecryptResult<PayloadType> & types.ResolvedKey>;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * JSON Web Token (JWT) Encryption (JWT is in JWE format)
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /**
8
+ * The EncryptJWT class is used to build and encrypt Compact JWE formatted JSON Web Tokens.
9
+ *
10
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
11
+ * from its subpath export `'jose/jwt/encrypt'`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const secret = jose.base64url.decode('zH4NRP1HMALxxCFnRZABFA7GOJtzU_gIj02alfL1lvI')
17
+ * const jwt = await new jose.EncryptJWT({ 'urn:example:claim': true })
18
+ * .setProtectedHeader({ alg: 'dir', enc: 'A128CBC-HS256' })
19
+ * .setIssuedAt()
20
+ * .setIssuer('urn:example:issuer')
21
+ * .setAudience('urn:example:audience')
22
+ * .setExpirationTime('2h')
23
+ * .encrypt(secret)
24
+ *
25
+ * console.log(jwt)
26
+ * ```
27
+ */
28
+ export declare class EncryptJWT implements types.ProduceJWT {
29
+ #private;
30
+ /**
31
+ * {@link EncryptJWT} constructor
32
+ *
33
+ * @param payload The JWT Claims Set object. Defaults to an empty object.
34
+ */
35
+ constructor(payload?: types.JWTPayload);
36
+ setIssuer(issuer: string): this;
37
+ setSubject(subject: string): this;
38
+ setAudience(audience: string | string[]): this;
39
+ setJti(jwtId: string): this;
40
+ setNotBefore(input: number | string | Date): this;
41
+ setExpirationTime(input: number | string | Date): this;
42
+ setIssuedAt(input?: number | string | Date): this;
43
+ /**
44
+ * Sets the JWE Protected Header on the EncryptJWT object.
45
+ *
46
+ * @param protectedHeader JWE Protected Header. Must contain an "alg" (JWE Algorithm) and "enc"
47
+ * (JWE Encryption Algorithm) properties.
48
+ */
49
+ setProtectedHeader(protectedHeader: types.CompactJWEHeaderParameters): this;
50
+ /**
51
+ * Sets the JWE Key Management parameters to be used when encrypting.
52
+ *
53
+ * (ECDH-ES) Use of this method is needed for ECDH based algorithms to set the "apu" (Agreement
54
+ * PartyUInfo) or "apv" (Agreement PartyVInfo) parameters.
55
+ *
56
+ * @param parameters JWE Key Management parameters.
57
+ */
58
+ setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): this;
59
+ /**
60
+ * Sets a content encryption key to use, by default a random suitable one is generated for the JWE
61
+ * enc" (Encryption Algorithm) Header Parameter.
62
+ *
63
+ * @deprecated You should not use this method. It is only really intended for test and vector
64
+ * validation purposes.
65
+ *
66
+ * @param cek JWE Content Encryption Key.
67
+ */
68
+ setContentEncryptionKey(cek: Uint8Array): this;
69
+ /**
70
+ * Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
71
+ * one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
72
+ *
73
+ * @deprecated You should not use this method. It is only really intended for test and vector
74
+ * validation purposes.
75
+ *
76
+ * @param iv JWE Initialization Vector.
77
+ */
78
+ setInitializationVector(iv: Uint8Array): this;
79
+ /**
80
+ * Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter.
81
+ *
82
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
83
+ */
84
+ replicateIssuerAsHeader(): this;
85
+ /**
86
+ * Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter.
87
+ *
88
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
89
+ */
90
+ replicateSubjectAsHeader(): this;
91
+ /**
92
+ * Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter.
93
+ *
94
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
95
+ */
96
+ replicateAudienceAsHeader(): this;
97
+ /**
98
+ * Encrypts and returns the JWT.
99
+ *
100
+ * @param key Public Key or Secret to encrypt the JWT with. See
101
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
102
+ * @param options JWE Encryption options.
103
+ */
104
+ encrypt(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.EncryptOptions): Promise<string>;
105
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * JSON Web Token (JWT) Signing (JWT is in JWS format)
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /**
8
+ * The SignJWT class is used to build and sign Compact JWS formatted JSON Web Tokens.
9
+ *
10
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
11
+ * from its subpath export `'jose/jwt/sign'`.
12
+ *
13
+ * @example
14
+ *
15
+ * Usage with a symmetric secret
16
+ *
17
+ * ```js
18
+ * const secret = new TextEncoder().encode(
19
+ * 'cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2',
20
+ * )
21
+ * const alg = 'HS256'
22
+ *
23
+ * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
24
+ * .setProtectedHeader({ alg })
25
+ * .setIssuedAt()
26
+ * .setIssuer('urn:example:issuer')
27
+ * .setAudience('urn:example:audience')
28
+ * .setExpirationTime('2h')
29
+ * .sign(secret)
30
+ *
31
+ * console.log(jwt)
32
+ * ```
33
+ *
34
+ * @example
35
+ *
36
+ * Usage with a private PKCS#8 encoded RSA key
37
+ *
38
+ * ```js
39
+ * const alg = 'RS256'
40
+ * const pkcs8 = `-----BEGIN PRIVATE KEY-----
41
+ * MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCFg4UrY5xtulv
42
+ * /NXKmL1J4qI1SopAfTNMo3X7p+kJO7plqUYjzaztcre1qfh0m33Sm1Q8oPbO/GpP
43
+ * MU1/HgcceytgJ/b4UwufVVMl9BrMDYG8moDBylbVupFQS3Ly1L9i/iFG9Z9A9xzY
44
+ * Zzf799A45bnvNXL6s2glzvjiRvfQ2NDF0anTcnZLcYtC7ugq1IMM+ihAcPfw8Qw2
45
+ * chN/SmP4qAM+PKaQwagmU7doqmmyN9u38AfoYZ1GCFhEs5TBBT6H6h9YdHeVtiIq
46
+ * 1c+fl03biSIfLrV7dUBD39gBmXBcL/30Ya3D82mCEUC4zg/UkOfQOmkmV3Lc8YUL
47
+ * QZ8EJkBLAgMBAAECggEAVuVE/KEP6323WjpbBdAIv7HGahGrgGANvbxZsIhm34ls
48
+ * VOPK0XDegZkhAybMZHjRhp+gwVxX5ChC+J3cUpOBH5FNxElgW6HizD2Jcq6t6LoL
49
+ * YgPSrfEHm71iHg8JsgrqfUnGYFzMJmv88C6WdCtpgG/qJV1K00/Ly1G1QKoBffEs
50
+ * +v4fAMJrCbUdCz1qWto+PU+HLMEo+krfEpGgcmtZeRlDADh8cETMQlgQfQX2VWq/
51
+ * aAP4a1SXmo+j0cvRU4W5Fj0RVwNesIpetX2ZFz4p/JmB5sWFEj/fC7h5z2lq+6Bm
52
+ * e2T3BHtXkIxoBW0/pYVnASC8P2puO5FnVxDmWuHDYQKBgQDTuuBd3+0tSFVEX+DU
53
+ * 5qpFmHm5nyGItZRJTS+71yg5pBxq1KqNCUjAtbxR0q//fwauakh+BwRVCPOrqsUG
54
+ * jBSb3NYE70Srp6elqxgkE54PwQx4Mr6exJPnseM9U4K+hULllf5yjM9edreJE1nV
55
+ * NVgFjeyafQhrHKwgr7PERJ/ikwKBgQDqqsT1M+EJLmI1HtCspOG6cu7q3gf/wKRh
56
+ * E8tu84i3YyBnI8uJkKy92RNVI5fvpBARe3tjSdM25rr2rcrcmF/5g6Q9ImxZPGCt
57
+ * 86eOgO9ErNtbc4TEgybsP319UE4O41aKeNiBTAZKoYCxv/dMqG0j4avmWzd+foHq
58
+ * gSNUvR2maQKBgQCYeqOsV2B6VPY7KIVFLd0AA9/dwvEmgAYLiA/RShDI+hwQ/5jX
59
+ * uxDu37KAhqeC65sHLrmIMUt4Zdr+DRyZK3aIDNEAesPMjw/X6lCXYp1ZISD2yyym
60
+ * MFGH8X8CIkstI9Faf9vf6PJKSFrC1/HA7wq17VCwrUzLvrljTMW8meM/CwKBgCpo
61
+ * 2leGHLFQFKeM/iF1WuYbR1pi7gcmhY6VyTowARFDdOOu8GXYI5/bz0afvCGvAMho
62
+ * DJCREv7lC/zww6zCTPYG+HOj+PjXlJFba3ixjIxYwPvyEJiDK1Ge18sB7Fl8dHNq
63
+ * C5ayaqCqN1voWYUdGzxU2IA1E/5kVo5O8FesJeOhAoGBAImJbZFf+D5kA32Xxhac
64
+ * 59lLWBCsocvvbd1cvDMNlRywAAyhsCb1SuX4nEAK9mrSBdfmoF2Nm3eilfsOds0f
65
+ * K5mX069IKG82CMqh3Mzptd7e7lyb9lsoGO0BAtjho3cWtha/UZ70vfaMzGuZ6JmQ
66
+ * ak6k+8+UFd93M4z0Qo74OhXB
67
+ * -----END PRIVATE KEY-----`
68
+ * const privateKey = await jose.importPKCS8(pkcs8, alg)
69
+ *
70
+ * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
71
+ * .setProtectedHeader({ alg })
72
+ * .setIssuedAt()
73
+ * .setIssuer('urn:example:issuer')
74
+ * .setAudience('urn:example:audience')
75
+ * .setExpirationTime('2h')
76
+ * .sign(privateKey)
77
+ *
78
+ * console.log(jwt)
79
+ * ```
80
+ *
81
+ * @example
82
+ *
83
+ * Usage with a private JWK encoded RSA key
84
+ *
85
+ * ```js
86
+ * const alg = 'RS256'
87
+ * const jwk = {
88
+ * kty: 'RSA',
89
+ * n: 'whYOFK2Ocbbpb_zVypi9SeKiNUqKQH0zTKN1-6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4HHHsrYCf2-FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS_Yv4hRvWfQPcc2Gc3-_fQOOW57zVy-rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj-KgDPjymkMGoJlO3aKppsjfbt_AH6GGdRghYRLOUwQU-h-ofWHR3lbYiKtXPn5dN24kiHy61e3VAQ9_YAZlwXC_99GGtw_NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZASw',
90
+ * e: 'AQAB',
91
+ * d: 'VuVE_KEP6323WjpbBdAIv7HGahGrgGANvbxZsIhm34lsVOPK0XDegZkhAybMZHjRhp-gwVxX5ChC-J3cUpOBH5FNxElgW6HizD2Jcq6t6LoLYgPSrfEHm71iHg8JsgrqfUnGYFzMJmv88C6WdCtpgG_qJV1K00_Ly1G1QKoBffEs-v4fAMJrCbUdCz1qWto-PU-HLMEo-krfEpGgcmtZeRlDADh8cETMQlgQfQX2VWq_aAP4a1SXmo-j0cvRU4W5Fj0RVwNesIpetX2ZFz4p_JmB5sWFEj_fC7h5z2lq-6Bme2T3BHtXkIxoBW0_pYVnASC8P2puO5FnVxDmWuHDYQ',
92
+ * p: '07rgXd_tLUhVRF_g1OaqRZh5uZ8hiLWUSU0vu9coOaQcatSqjQlIwLW8UdKv_38GrmpIfgcEVQjzq6rFBowUm9zWBO9Eq6enpasYJBOeD8EMeDK-nsST57HjPVOCvoVC5ZX-cozPXna3iRNZ1TVYBY3smn0IaxysIK-zxESf4pM',
93
+ * q: '6qrE9TPhCS5iNR7QrKThunLu6t4H_8CkYRPLbvOIt2MgZyPLiZCsvdkTVSOX76QQEXt7Y0nTNua69q3K3Jhf-YOkPSJsWTxgrfOnjoDvRKzbW3OExIMm7D99fVBODuNWinjYgUwGSqGAsb_3TKhtI-Gr5ls3fn6B6oEjVL0dpmk',
94
+ * dp: 'mHqjrFdgelT2OyiFRS3dAAPf3cLxJoAGC4gP0UoQyPocEP-Y17sQ7t-ygIanguubBy65iDFLeGXa_g0cmSt2iAzRAHrDzI8P1-pQl2KdWSEg9ssspjBRh_F_AiJLLSPRWn_b3-jySkhawtfxwO8Kte1QsK1My765Y0zFvJnjPws',
95
+ * dq: 'KmjaV4YcsVAUp4z-IXVa5htHWmLuByaFjpXJOjABEUN0467wZdgjn9vPRp-8Ia8AyGgMkJES_uUL_PDDrMJM9gb4c6P4-NeUkVtreLGMjFjA-_IQmIMrUZ7XywHsWXx0c2oLlrJqoKo3W-hZhR0bPFTYgDUT_mRWjk7wV6wl46E',
96
+ * qi: 'iYltkV_4PmQDfZfGFpzn2UtYEKyhy-9t3Vy8Mw2VHLAADKGwJvVK5ficQAr2atIF1-agXY2bd6KV-w52zR8rmZfTr0gobzYIyqHczOm13t7uXJv2WygY7QEC2OGjdxa2Fr9RnvS99ozMa5nomZBqTqT7z5QV33czjPRCjvg6FcE',
97
+ * }
98
+ * const privateKey = await jose.importJWK(jwk, alg)
99
+ *
100
+ * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
101
+ * .setProtectedHeader({ alg })
102
+ * .setIssuedAt()
103
+ * .setIssuer('urn:example:issuer')
104
+ * .setAudience('urn:example:audience')
105
+ * .setExpirationTime('2h')
106
+ * .sign(privateKey)
107
+ *
108
+ * console.log(jwt)
109
+ * ```
110
+ */
111
+ export declare class SignJWT implements types.ProduceJWT {
112
+ #private;
113
+ /**
114
+ * {@link SignJWT} constructor
115
+ *
116
+ * @param payload The JWT Claims Set object. Defaults to an empty object.
117
+ */
118
+ constructor(payload?: types.JWTPayload);
119
+ setIssuer(issuer: string): this;
120
+ setSubject(subject: string): this;
121
+ setAudience(audience: string | string[]): this;
122
+ setJti(jwtId: string): this;
123
+ setNotBefore(input: number | string | Date): this;
124
+ setExpirationTime(input: number | string | Date): this;
125
+ setIssuedAt(input?: number | string | Date): this;
126
+ /**
127
+ * Sets the JWS Protected Header on the SignJWT object.
128
+ *
129
+ * @param protectedHeader JWS Protected Header. Must contain an "alg" (JWS Algorithm) property.
130
+ */
131
+ setProtectedHeader(protectedHeader: types.JWTHeaderParameters): this;
132
+ /**
133
+ * Signs and returns the JWT.
134
+ *
135
+ * @param key Private Key or Secret to sign the JWT with. See
136
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
137
+ * @param options JWT Sign options.
138
+ */
139
+ sign(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.SignOptions): Promise<string>;
140
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Unsecured (unsigned & unencrypted) JSON Web Tokens (JWT)
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Result of decoding an Unsecured JWT. */
8
+ export interface UnsecuredResult<PayloadType = types.JWTPayload> {
9
+ payload: PayloadType & types.JWTPayload;
10
+ header: types.JWSHeaderParameters;
11
+ }
12
+ /**
13
+ * The UnsecuredJWT class is a utility for dealing with `{ "alg": "none" }` Unsecured JWTs.
14
+ *
15
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
16
+ * from its subpath export `'jose/jwt/unsecured'`.
17
+ *
18
+ * @example
19
+ *
20
+ * Encoding
21
+ *
22
+ * ```js
23
+ * const unsecuredJwt = new jose.UnsecuredJWT({ 'urn:example:claim': true })
24
+ * .setIssuedAt()
25
+ * .setIssuer('urn:example:issuer')
26
+ * .setAudience('urn:example:audience')
27
+ * .setExpirationTime('2h')
28
+ * .encode()
29
+ *
30
+ * console.log(unsecuredJwt)
31
+ * ```
32
+ *
33
+ * @example
34
+ *
35
+ * Decoding
36
+ *
37
+ * ```js
38
+ * const payload = jose.UnsecuredJWT.decode(unsecuredJwt, {
39
+ * issuer: 'urn:example:issuer',
40
+ * audience: 'urn:example:audience',
41
+ * })
42
+ *
43
+ * console.log(payload)
44
+ * ```
45
+ */
46
+ export declare class UnsecuredJWT implements types.ProduceJWT {
47
+ #private;
48
+ /**
49
+ * {@link UnsecuredJWT} constructor
50
+ *
51
+ * @param payload The JWT Claims Set object. Defaults to an empty object.
52
+ */
53
+ constructor(payload?: types.JWTPayload);
54
+ /** Encodes the Unsecured JWT. */
55
+ encode(): string;
56
+ setIssuer(issuer: string): this;
57
+ setSubject(subject: string): this;
58
+ setAudience(audience: string | string[]): this;
59
+ setJti(jwtId: string): this;
60
+ setNotBefore(input: number | string | Date): this;
61
+ setExpirationTime(input: number | string | Date): this;
62
+ setIssuedAt(input?: number | string | Date): this;
63
+ /**
64
+ * Decodes an unsecured JWT.
65
+ *
66
+ * @param jwt Unsecured JWT to decode the payload of.
67
+ * @param options JWT Claims Set validation options.
68
+ */
69
+ static decode<PayloadType = types.JWTPayload>(jwt: string, options?: types.JWTClaimVerificationOptions): UnsecuredResult<PayloadType>;
70
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * JSON Web Token (JWT) Verification (JWT is in JWS format)
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Combination of JWS Verification options and JWT Claims Set verification options. */
8
+ export interface JWTVerifyOptions extends types.VerifyOptions, types.JWTClaimVerificationOptions {
9
+ }
10
+ /**
11
+ * Interface for JWT Verification dynamic key resolution. No token components have been verified at
12
+ * the time of this function call.
13
+ *
14
+ * @see {@link jwks/remote.createRemoteJWKSet createRemoteJWKSet} to verify using a remote JSON Web Key Set.
15
+ */
16
+ export interface JWTVerifyGetKey extends types.GenericGetKeyFunction<types.JWTHeaderParameters, types.FlattenedJWSInput, types.CryptoKey | types.KeyObject | types.JWK | Uint8Array> {
17
+ }
18
+ /**
19
+ * Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
20
+ * JWT Claims Set.
21
+ *
22
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
23
+ * as from its subpath export `'jose/jwt/verify'`.
24
+ *
25
+ * @example
26
+ *
27
+ * Usage with a symmetric secret
28
+ *
29
+ * ```js
30
+ * const secret = new TextEncoder().encode(
31
+ * 'cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2',
32
+ * )
33
+ * const jwt =
34
+ * 'eyJhbGciOiJIUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2MjMxLCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.C4iSlLfAUMBq--wnC6VqD9gEOhwpRZpoRarE0m7KEnI'
35
+ *
36
+ * const { payload, protectedHeader } = await jose.jwtVerify(jwt, secret, {
37
+ * issuer: 'urn:example:issuer',
38
+ * audience: 'urn:example:audience',
39
+ * })
40
+ *
41
+ * console.log(protectedHeader)
42
+ * console.log(payload)
43
+ * ```
44
+ *
45
+ * @example
46
+ *
47
+ * Usage with a public SPKI encoded RSA key
48
+ *
49
+ * ```js
50
+ * const alg = 'RS256'
51
+ * const spki = `-----BEGIN PUBLIC KEY-----
52
+ * MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwhYOFK2Ocbbpb/zVypi9
53
+ * SeKiNUqKQH0zTKN1+6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4H
54
+ * HHsrYCf2+FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS/Yv4hRvWfQPcc2Gc3+/fQ
55
+ * OOW57zVy+rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj
56
+ * +KgDPjymkMGoJlO3aKppsjfbt/AH6GGdRghYRLOUwQU+h+ofWHR3lbYiKtXPn5dN
57
+ * 24kiHy61e3VAQ9/YAZlwXC/99GGtw/NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZA
58
+ * SwIDAQAB
59
+ * -----END PUBLIC KEY-----`
60
+ * const publicKey = await jose.importSPKI(spki, alg)
61
+ * const jwt =
62
+ * 'eyJhbGciOiJSUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2NDg4LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.gXrPZ3yM_60dMXGE69dusbpzYASNA-XIOwsb5D5xYnSxyj6_D6OR_uR_1vqhUm4AxZxcrH1_-XJAve9HCw8az_QzHcN-nETt-v6stCsYrn6Bv1YOc-mSJRZ8ll57KVqLbCIbjKwerNX5r2_Qg2TwmJzQdRs-AQDhy-s_DlJd8ql6wR4n-kDZpar-pwIvz4fFIN0Fj57SXpAbLrV6Eo4Byzl0xFD8qEYEpBwjrMMfxCZXTlAVhAq6KCoGlDTwWuExps342-0UErEtyIqDnDGcrfNWiUsoo8j-29IpKd-w9-C388u-ChCxoHz--H8WmMSZzx3zTXsZ5lXLZ9IKfanDKg'
63
+ *
64
+ * const { payload, protectedHeader } = await jose.jwtVerify(jwt, publicKey, {
65
+ * issuer: 'urn:example:issuer',
66
+ * audience: 'urn:example:audience',
67
+ * })
68
+ *
69
+ * console.log(protectedHeader)
70
+ * console.log(payload)
71
+ * ```
72
+ *
73
+ * @example
74
+ *
75
+ * Usage with a public JWK encoded RSA key
76
+ *
77
+ * ```js
78
+ * const alg = 'RS256'
79
+ * const jwk = {
80
+ * kty: 'RSA',
81
+ * n: 'whYOFK2Ocbbpb_zVypi9SeKiNUqKQH0zTKN1-6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4HHHsrYCf2-FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS_Yv4hRvWfQPcc2Gc3-_fQOOW57zVy-rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj-KgDPjymkMGoJlO3aKppsjfbt_AH6GGdRghYRLOUwQU-h-ofWHR3lbYiKtXPn5dN24kiHy61e3VAQ9_YAZlwXC_99GGtw_NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZASw',
82
+ * e: 'AQAB',
83
+ * }
84
+ * const publicKey = await jose.importJWK(jwk, alg)
85
+ * const jwt =
86
+ * 'eyJhbGciOiJSUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2NDg4LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.gXrPZ3yM_60dMXGE69dusbpzYASNA-XIOwsb5D5xYnSxyj6_D6OR_uR_1vqhUm4AxZxcrH1_-XJAve9HCw8az_QzHcN-nETt-v6stCsYrn6Bv1YOc-mSJRZ8ll57KVqLbCIbjKwerNX5r2_Qg2TwmJzQdRs-AQDhy-s_DlJd8ql6wR4n-kDZpar-pwIvz4fFIN0Fj57SXpAbLrV6Eo4Byzl0xFD8qEYEpBwjrMMfxCZXTlAVhAq6KCoGlDTwWuExps342-0UErEtyIqDnDGcrfNWiUsoo8j-29IpKd-w9-C388u-ChCxoHz--H8WmMSZzx3zTXsZ5lXLZ9IKfanDKg'
87
+ *
88
+ * const { payload, protectedHeader } = await jose.jwtVerify(jwt, publicKey, {
89
+ * issuer: 'urn:example:issuer',
90
+ * audience: 'urn:example:audience',
91
+ * })
92
+ *
93
+ * console.log(protectedHeader)
94
+ * console.log(payload)
95
+ * ```
96
+ *
97
+ * @param jwt JSON Web Token value (encoded as JWS).
98
+ * @param key Key to verify the JWT with. See
99
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
100
+ * @param options JWT Decryption and JWT Claims Set validation options.
101
+ */
102
+ export declare function jwtVerify<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: JWTVerifyOptions): Promise<types.JWTVerifyResult<PayloadType>>;
103
+ /**
104
+ * @example
105
+ *
106
+ * Usage with a public JSON Web Key Set hosted on a remote URL
107
+ *
108
+ * ```js
109
+ * const JWKS = jose.createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
110
+ *
111
+ * const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
112
+ * issuer: 'urn:example:issuer',
113
+ * audience: 'urn:example:audience',
114
+ * })
115
+ * console.log(protectedHeader)
116
+ * console.log(payload)
117
+ * ```
118
+ *
119
+ * @param jwt JSON Web Token value (encoded as JWS).
120
+ * @param getKey Function resolving a key to verify the JWT with. See
121
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
122
+ * @param options JWT Decryption and JWT Claims Set validation options.
123
+ */
124
+ export declare function jwtVerify<PayloadType = types.JWTPayload>(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<types.JWTVerifyResult<PayloadType> & types.ResolvedKey>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Cryptographic key export functions
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /**
8
+ * Exports a public {@link !CryptoKey} or {@link !KeyObject} to a PEM-encoded SPKI string format.
9
+ *
10
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
11
+ * as from its subpath export `'jose/key/export'`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const spkiPem = await jose.exportSPKI(publicKey)
17
+ *
18
+ * console.log(spkiPem)
19
+ * ```
20
+ *
21
+ * @param key Key to export to a PEM-encoded SPKI string format.
22
+ */
23
+ export declare function exportSPKI(key: types.CryptoKey | types.KeyObject): Promise<string>;
24
+ /**
25
+ * Exports a private {@link !CryptoKey} or {@link !KeyObject} to a PEM-encoded PKCS8 string format.
26
+ *
27
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
28
+ * as from its subpath export `'jose/key/export'`.
29
+ *
30
+ * @example
31
+ *
32
+ * ```js
33
+ * const pkcs8Pem = await jose.exportPKCS8(privateKey)
34
+ *
35
+ * console.log(pkcs8Pem)
36
+ * ```
37
+ *
38
+ * @param key Key to export to a PEM-encoded PKCS8 string format.
39
+ */
40
+ export declare function exportPKCS8(key: types.CryptoKey | types.KeyObject): Promise<string>;
41
+ /**
42
+ * Exports a {@link !CryptoKey}, {@link !KeyObject}, or {@link !Uint8Array} to a JWK.
43
+ *
44
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
45
+ * as from its subpath export `'jose/key/export'`.
46
+ *
47
+ * @example
48
+ *
49
+ * ```js
50
+ * const privateJwk = await jose.exportJWK(privateKey)
51
+ * const publicJwk = await jose.exportJWK(publicKey)
52
+ *
53
+ * console.log(privateJwk)
54
+ * console.log(publicJwk)
55
+ * ```
56
+ *
57
+ * @param key Key to export as JWK.
58
+ */
59
+ export declare function exportJWK(key: types.CryptoKey | types.KeyObject | Uint8Array): Promise<types.JWK>;