jose 4.8.0 → 4.9.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.
- package/README.md +9 -10
- package/dist/browser/index.js +1 -1
- package/dist/browser/jwe/flattened/decrypt.js +1 -1
- package/dist/browser/jwk/thumbprint.js +7 -1
- package/dist/browser/jws/flattened/verify.js +1 -1
- package/dist/browser/lib/crypto_key.js +1 -6
- package/dist/browser/runtime/asn1.js +3 -5
- package/dist/browser/runtime/env.js +0 -8
- package/dist/browser/runtime/generate.js +3 -7
- package/dist/browser/runtime/jwk_to_key.js +2 -6
- package/dist/browser/runtime/subtle_dsa.js +2 -2
- package/dist/node/cjs/index.js +2 -1
- package/dist/node/cjs/jwe/flattened/decrypt.js +1 -1
- package/dist/node/cjs/jwk/thumbprint.js +9 -2
- package/dist/node/cjs/jws/flattened/verify.js +1 -1
- package/dist/node/cjs/lib/crypto_key.js +0 -5
- package/dist/node/cjs/runtime/env.js +1 -5
- package/dist/node/cjs/runtime/key_to_jwk.js +4 -0
- package/dist/node/esm/index.js +1 -1
- package/dist/node/esm/jwe/flattened/decrypt.js +1 -1
- package/dist/node/esm/jwk/thumbprint.js +7 -1
- package/dist/node/esm/jws/flattened/verify.js +1 -1
- package/dist/node/esm/lib/crypto_key.js +1 -6
- package/dist/node/esm/runtime/env.js +0 -3
- package/dist/node/esm/runtime/key_to_jwk.js +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jwe/compact/decrypt.d.ts +9 -7
- package/dist/types/jwe/compact/encrypt.d.ts +14 -20
- package/dist/types/jwe/flattened/decrypt.d.ts +12 -13
- package/dist/types/jwe/flattened/encrypt.d.ts +17 -26
- package/dist/types/jwe/general/decrypt.d.ts +13 -14
- package/dist/types/jwe/general/encrypt.d.ts +6 -15
- package/dist/types/jwk/embedded.d.ts +8 -7
- package/dist/types/jwk/thumbprint.d.ts +30 -7
- package/dist/types/jwks/local.d.ts +12 -15
- package/dist/types/jwks/remote.d.ts +22 -36
- package/dist/types/jws/compact/sign.d.ts +3 -6
- package/dist/types/jws/compact/verify.d.ts +11 -8
- package/dist/types/jws/flattened/sign.d.ts +3 -6
- package/dist/types/jws/flattened/verify.d.ts +12 -9
- package/dist/types/jws/general/sign.d.ts +7 -18
- package/dist/types/jws/general/verify.d.ts +14 -11
- package/dist/types/jwt/decrypt.d.ts +13 -12
- package/dist/types/jwt/encrypt.d.ts +15 -18
- package/dist/types/jwt/produce.d.ts +9 -14
- package/dist/types/jwt/sign.d.ts +2 -2
- package/dist/types/jwt/unsecured.d.ts +4 -4
- package/dist/types/jwt/verify.d.ts +15 -13
- package/dist/types/key/export.d.ts +13 -8
- package/dist/types/key/generate_key_pair.d.ts +14 -19
- package/dist/types/key/generate_secret.d.ts +3 -2
- package/dist/types/key/import.d.ts +50 -39
- package/dist/types/types.d.ts +196 -371
- package/dist/types/util/decode_jwt.d.ts +7 -6
- package/dist/types/util/decode_protected_header.d.ts +3 -2
- package/dist/types/util/errors.d.ts +20 -61
- package/package.json +2 -1
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import type { KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction, CompactJWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Combination of JWE Decryption options and JWT Claims Set verification options.
|
|
4
|
-
*/
|
|
2
|
+
/** Combination of JWE Decryption options and JWT Claims Set verification options. */
|
|
5
3
|
export interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {
|
|
6
4
|
}
|
|
7
5
|
/**
|
|
8
|
-
* Interface for JWT Decryption dynamic key resolution.
|
|
9
|
-
*
|
|
6
|
+
* Interface for JWT Decryption dynamic key resolution. No token components have been verified at
|
|
7
|
+
* the time of this function call.
|
|
10
8
|
*/
|
|
11
9
|
export interface JWTDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParameters, FlattenedJWE> {
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
|
-
* Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT
|
|
15
|
-
*
|
|
16
|
-
* @param jwt JSON Web Token value (encoded as JWE).
|
|
17
|
-
* @param key Private Key or Secret to decrypt and verify the JWT with.
|
|
18
|
-
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
12
|
+
* Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT
|
|
13
|
+
* Claims Set.
|
|
19
14
|
*
|
|
20
15
|
* @example Usage
|
|
16
|
+
*
|
|
21
17
|
* ```js
|
|
22
|
-
* const jwt =
|
|
18
|
+
* const jwt =
|
|
19
|
+
* 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..KVcNLqK-3-8ZkYIC.xSwF4VxO0kUMUD2W-cifsNUxnr-swyBq-nADBptyt6y9n79-iNc5b0AALJpRwc0wwDkJw8hNOMjApNUTMsK9b-asToZ3DXFMvwfJ6n1aWefvd7RsoZ2LInWFfVAuttJDzoGB.uuexQoWHwrLMEYRElT8pBQ'
|
|
23
20
|
*
|
|
24
21
|
* const { payload, protectedHeader } = await jose.jwtDecrypt(jwt, secretKey, {
|
|
25
22
|
* issuer: 'urn:example:issuer',
|
|
26
|
-
* audience: 'urn:example:audience'
|
|
23
|
+
* audience: 'urn:example:audience',
|
|
27
24
|
* })
|
|
28
25
|
*
|
|
29
26
|
* console.log(protectedHeader)
|
|
30
27
|
* console.log(payload)
|
|
31
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param jwt JSON Web Token value (encoded as JWE).
|
|
31
|
+
* @param key Private Key or Secret to decrypt and verify the JWT with.
|
|
32
|
+
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
32
33
|
*/
|
|
33
34
|
export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
|
|
34
35
|
/**
|
|
@@ -4,6 +4,7 @@ import { ProduceJWT } from './produce';
|
|
|
4
4
|
* The EncryptJWT class is a utility for creating Compact JWE formatted JWT strings.
|
|
5
5
|
*
|
|
6
6
|
* @example Usage
|
|
7
|
+
*
|
|
7
8
|
* ```js
|
|
8
9
|
* const jwt = await new jose.EncryptJWT({ 'urn:example:claim': true })
|
|
9
10
|
* .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
|
|
@@ -27,39 +28,35 @@ export declare class EncryptJWT extends ProduceJWT {
|
|
|
27
28
|
/**
|
|
28
29
|
* Sets the JWE Protected Header on the EncryptJWT object.
|
|
29
30
|
*
|
|
30
|
-
* @param protectedHeader JWE Protected Header.
|
|
31
|
-
*
|
|
32
|
-
* Encryption Algorithm) properties.
|
|
31
|
+
* @param protectedHeader JWE Protected Header. Must contain an "alg" (JWE Algorithm) and "enc"
|
|
32
|
+
* (JWE Encryption Algorithm) properties.
|
|
33
33
|
*/
|
|
34
34
|
setProtectedHeader(protectedHeader: CompactJWEHeaderParameters): this;
|
|
35
35
|
/**
|
|
36
|
-
* Sets the JWE Key Management parameters to be used when encrypting.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Sets the JWE Key Management parameters to be used when encrypting. Use of this is method is
|
|
37
|
+
* really only needed for ECDH based algorithms when utilizing the Agreement PartyUInfo or
|
|
38
|
+
* Agreement PartyVInfo parameters. Other parameters will always be randomly generated when needed
|
|
39
|
+
* and missing.
|
|
40
40
|
*
|
|
41
41
|
* @param parameters JWE Key Management parameters.
|
|
42
42
|
*/
|
|
43
43
|
setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
|
|
44
44
|
/**
|
|
45
|
-
* Sets a content encryption key to use, by default a random suitable one
|
|
46
|
-
*
|
|
45
|
+
* Sets a content encryption key to use, by default a random suitable one is generated for the JWE
|
|
46
|
+
* enc" (Encryption Algorithm) Header Parameter.
|
|
47
47
|
*
|
|
48
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
49
|
+
* validation purposes.
|
|
48
50
|
* @param cek JWE Content Encryption Key.
|
|
49
|
-
*
|
|
50
|
-
* @deprecated You should not use this method. It is only really intended
|
|
51
|
-
* for test and vector validation purposes.
|
|
52
51
|
*/
|
|
53
52
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
54
53
|
/**
|
|
55
|
-
* Sets the JWE Initialization Vector to use for content encryption, by default
|
|
56
|
-
*
|
|
57
|
-
* Header Parameter.
|
|
54
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
|
|
55
|
+
* one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
|
|
58
56
|
*
|
|
57
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
58
|
+
* validation purposes.
|
|
59
59
|
* @param iv JWE Initialization Vector.
|
|
60
|
-
*
|
|
61
|
-
* @deprecated You should not use this method. It is only really intended
|
|
62
|
-
* for test and vector validation purposes.
|
|
63
60
|
*/
|
|
64
61
|
setInitializationVector(iv: Uint8Array): this;
|
|
65
62
|
/**
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { JWTPayload } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Generic class for JWT producing.
|
|
4
|
-
*/
|
|
2
|
+
/** Generic class for JWT producing. */
|
|
5
3
|
export declare class ProduceJWT {
|
|
6
4
|
protected _payload: JWTPayload;
|
|
7
|
-
/**
|
|
8
|
-
* @param payload The JWT Claims Set object.
|
|
9
|
-
*/
|
|
5
|
+
/** @param payload The JWT Claims Set object. */
|
|
10
6
|
constructor(payload: JWTPayload);
|
|
11
7
|
/**
|
|
12
8
|
* Set "iss" (Issuer) Claim.
|
|
@@ -35,24 +31,23 @@ export declare class ProduceJWT {
|
|
|
35
31
|
/**
|
|
36
32
|
* Set "nbf" (Not Before) Claim.
|
|
37
33
|
*
|
|
38
|
-
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
34
|
+
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed
|
|
35
|
+
* that is used as a value, when string is passed it is resolved to a time span and added to the
|
|
36
|
+
* current timestamp.
|
|
41
37
|
*/
|
|
42
38
|
setNotBefore(input: number | string): this;
|
|
43
39
|
/**
|
|
44
40
|
* Set "exp" (Expiration Time) Claim.
|
|
45
41
|
*
|
|
46
|
-
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
42
|
+
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is
|
|
43
|
+
* passed that is used as a value, when string is passed it is resolved to a time span and added
|
|
44
|
+
* to the current timestamp.
|
|
49
45
|
*/
|
|
50
46
|
setExpirationTime(input: number | string): this;
|
|
51
47
|
/**
|
|
52
48
|
* Set "iat" (Issued At) Claim.
|
|
53
49
|
*
|
|
54
|
-
* @param input "iat" (Issued At) Claim value to set on the JWT Claims Set.
|
|
55
|
-
* Default is current timestamp.
|
|
50
|
+
* @param input "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp.
|
|
56
51
|
*/
|
|
57
52
|
setIssuedAt(input?: number): this;
|
|
58
53
|
}
|
package/dist/types/jwt/sign.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ProduceJWT } from './produce';
|
|
|
4
4
|
* The SignJWT class is a utility for creating Compact JWS formatted JWT strings.
|
|
5
5
|
*
|
|
6
6
|
* @example Usage
|
|
7
|
+
*
|
|
7
8
|
* ```js
|
|
8
9
|
* const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
|
|
9
10
|
* .setProtectedHeader({ alg: 'ES256' })
|
|
@@ -21,8 +22,7 @@ export declare class SignJWT extends ProduceJWT {
|
|
|
21
22
|
/**
|
|
22
23
|
* Sets the JWS Protected Header on the SignJWT object.
|
|
23
24
|
*
|
|
24
|
-
* @param protectedHeader JWS Protected Header.
|
|
25
|
-
* Must contain an "alg" (JWS Algorithm) property.
|
|
25
|
+
* @param protectedHeader JWS Protected Header. Must contain an "alg" (JWS Algorithm) property.
|
|
26
26
|
*/
|
|
27
27
|
setProtectedHeader(protectedHeader: JWTHeaderParameters): this;
|
|
28
28
|
/**
|
|
@@ -8,6 +8,7 @@ export interface UnsecuredResult {
|
|
|
8
8
|
* The UnsecuredJWT class is a utility for dealing with `{ "alg": "none" }` Unsecured JWTs.
|
|
9
9
|
*
|
|
10
10
|
* @example Encoding
|
|
11
|
+
*
|
|
11
12
|
* ```js
|
|
12
13
|
* const unsecuredJwt = new jose.UnsecuredJWT({ 'urn:example:claim': true })
|
|
13
14
|
* .setIssuedAt()
|
|
@@ -20,19 +21,18 @@ export interface UnsecuredResult {
|
|
|
20
21
|
* ```
|
|
21
22
|
*
|
|
22
23
|
* @example Decoding
|
|
24
|
+
*
|
|
23
25
|
* ```js
|
|
24
26
|
* const payload = jose.UnsecuredJWT.decode(jwt, {
|
|
25
27
|
* issuer: 'urn:example:issuer',
|
|
26
|
-
* audience: 'urn:example:audience'
|
|
28
|
+
* audience: 'urn:example:audience',
|
|
27
29
|
* })
|
|
28
30
|
*
|
|
29
31
|
* console.log(payload)
|
|
30
32
|
* ```
|
|
31
33
|
*/
|
|
32
34
|
export declare class UnsecuredJWT extends ProduceJWT {
|
|
33
|
-
/**
|
|
34
|
-
* Encodes the Unsecured JWT.
|
|
35
|
-
*/
|
|
35
|
+
/** Encodes the Unsecured JWT. */
|
|
36
36
|
encode(): string;
|
|
37
37
|
/**
|
|
38
38
|
* Decodes an unsecured JWT.
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import type { KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Combination of JWS Verification options and JWT Claims Set verification options.
|
|
4
|
-
*/
|
|
2
|
+
/** Combination of JWS Verification options and JWT Claims Set verification options. */
|
|
5
3
|
export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
|
|
6
4
|
}
|
|
7
5
|
/**
|
|
8
|
-
* Interface for JWT Verification dynamic key resolution.
|
|
9
|
-
*
|
|
6
|
+
* Interface for JWT Verification dynamic key resolution. No token components have been verified at
|
|
7
|
+
* the time of this function call.
|
|
10
8
|
*
|
|
11
|
-
* See
|
|
9
|
+
* See
|
|
10
|
+
* [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
|
|
12
11
|
* to verify using a remote JSON Web Key Set.
|
|
13
12
|
*/
|
|
14
13
|
export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, FlattenedJWSInput> {
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
* Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
|
|
18
|
-
*
|
|
19
|
-
* @param jwt JSON Web Token value (encoded as JWS).
|
|
20
|
-
* @param key Key to verify the JWT with.
|
|
21
|
-
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
16
|
+
* Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
|
|
17
|
+
* JWT Claims Set.
|
|
22
18
|
*
|
|
23
19
|
* @example Usage
|
|
20
|
+
*
|
|
24
21
|
* ```js
|
|
25
|
-
* const jwt =
|
|
22
|
+
* const jwt =
|
|
23
|
+
* 'eyJhbGciOiJFUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjA0MzE1MDc0LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.hx1nOfAT5LlXuzu8O-bhjXBGpklWDt2EsHw7-MDn49NrnwvVsstNhEnkW2ddauB7eSikFtUNeumLpFI9CWDBsg'
|
|
26
24
|
*
|
|
27
25
|
* const { payload, protectedHeader } = await jose.jwtVerify(jwt, publicKey, {
|
|
28
26
|
* issuer: 'urn:example:issuer',
|
|
29
|
-
* audience: 'urn:example:audience'
|
|
27
|
+
* audience: 'urn:example:audience',
|
|
30
28
|
* })
|
|
31
29
|
*
|
|
32
30
|
* console.log(protectedHeader)
|
|
33
31
|
* console.log(payload)
|
|
34
32
|
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param jwt JSON Web Token value (encoded as JWS).
|
|
35
|
+
* @param key Key to verify the JWT with.
|
|
36
|
+
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
35
37
|
*/
|
|
36
38
|
export declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
|
|
37
39
|
/**
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import type { JWK, KeyLike } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Exports a runtime-specific public key representation (KeyObject or CryptoKey) to
|
|
4
|
-
*
|
|
5
|
-
* @param key Key representation to transform to an PEM-encoded SPKI string format.
|
|
3
|
+
* Exports a runtime-specific public key representation (KeyObject or CryptoKey) to a PEM-encoded
|
|
4
|
+
* SPKI string format.
|
|
6
5
|
*
|
|
7
6
|
* @example Usage
|
|
7
|
+
*
|
|
8
8
|
* ```js
|
|
9
9
|
* const spkiPem = await jose.exportSPKI(publicKey)
|
|
10
10
|
*
|
|
11
11
|
* console.log(spkiPem)
|
|
12
12
|
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param key Key representation to transform to a PEM-encoded SPKI string format.
|
|
13
15
|
*/
|
|
14
16
|
export declare function exportSPKI(key: KeyLike): Promise<string>;
|
|
15
17
|
/**
|
|
16
|
-
* Exports a runtime-specific private key representation (KeyObject or CryptoKey) to
|
|
17
|
-
*
|
|
18
|
-
* @param key Key representation to transform to an PEM-encoded PKCS8 string format.
|
|
18
|
+
* Exports a runtime-specific private key representation (KeyObject or CryptoKey) to a PEM-encoded
|
|
19
|
+
* PKCS8 string format.
|
|
19
20
|
*
|
|
20
21
|
* @example Usage
|
|
22
|
+
*
|
|
21
23
|
* ```js
|
|
22
24
|
* const pkcs8Pem = await jose.exportPKCS8(privateKey)
|
|
23
25
|
*
|
|
24
26
|
* console.log(pkcs8Pem)
|
|
25
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param key Key representation to transform to a PEM-encoded PKCS8 string format.
|
|
26
30
|
*/
|
|
27
31
|
export declare function exportPKCS8(key: KeyLike): Promise<string>;
|
|
28
32
|
/**
|
|
29
33
|
* Exports a runtime-specific key representation (KeyLike) to a JWK.
|
|
30
34
|
*
|
|
31
|
-
* @param key Key representation to export as JWK.
|
|
32
|
-
*
|
|
33
35
|
* @example Usage
|
|
36
|
+
*
|
|
34
37
|
* ```js
|
|
35
38
|
* const privateJwk = await jose.exportJWK(privateKey)
|
|
36
39
|
* const publicJwk = await jose.exportJWK(publicKey)
|
|
@@ -38,5 +41,7 @@ export declare function exportPKCS8(key: KeyLike): Promise<string>;
|
|
|
38
41
|
* console.log(privateJwk)
|
|
39
42
|
* console.log(publicJwk)
|
|
40
43
|
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param key Key representation to export as JWK.
|
|
41
46
|
*/
|
|
42
47
|
export declare function exportJWK(key: KeyLike | Uint8Array): Promise<JWK>;
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import type { KeyLike } from '../types';
|
|
2
2
|
export interface GenerateKeyPairResult {
|
|
3
|
-
/**
|
|
4
|
-
* The generated Private Key.
|
|
5
|
-
*/
|
|
3
|
+
/** The generated Private Key. */
|
|
6
4
|
privateKey: KeyLike;
|
|
7
|
-
/**
|
|
8
|
-
* Public Key corresponding to the generated Private Key.
|
|
9
|
-
*/
|
|
5
|
+
/** Public Key corresponding to the generated Private Key. */
|
|
10
6
|
publicKey: KeyLike;
|
|
11
7
|
}
|
|
12
8
|
export interface GenerateKeyPairOptions {
|
|
13
9
|
/**
|
|
14
|
-
* The EC "crv" (Curve) or OKP "crv" (Subtype of Key Pair) value to generate.
|
|
15
|
-
*
|
|
16
|
-
* the given JWA algorithm identifier.
|
|
10
|
+
* The EC "crv" (Curve) or OKP "crv" (Subtype of Key Pair) value to generate. The curve must be
|
|
11
|
+
* both supported on the runtime as well as applicable for the given JWA algorithm identifier.
|
|
17
12
|
*/
|
|
18
13
|
crv?: string;
|
|
19
14
|
/**
|
|
20
|
-
* A hint for RSA algorithms to generate an RSA key of a given `modulusLength`
|
|
21
|
-
*
|
|
15
|
+
* A hint for RSA algorithms to generate an RSA key of a given `modulusLength` (Key size in bits).
|
|
16
|
+
* JOSE requires 2048 bits or larger. Default is 2048.
|
|
22
17
|
*/
|
|
23
18
|
modulusLength?: number;
|
|
24
19
|
/**
|
|
@@ -29,21 +24,21 @@ export interface GenerateKeyPairOptions {
|
|
|
29
24
|
extractable?: boolean;
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
|
-
* Generates a private and a public key for a given JWA algorithm identifier.
|
|
33
|
-
*
|
|
34
|
-
* `generateSecret` function.
|
|
27
|
+
* Generates a private and a public key for a given JWA algorithm identifier. This can only generate
|
|
28
|
+
* asymmetric key pairs. For symmetric secrets use the `generateSecret` function.
|
|
35
29
|
*
|
|
36
|
-
* Note: Under Web Cryptography API runtime the `privateKey` is generated with
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
-
* @param alg JWA Algorithm Identifier to be used with the generated key pair.
|
|
40
|
-
* @param options Additional options passed down to the key pair generation.
|
|
30
|
+
* Note: Under Web Cryptography API runtime the `privateKey` is generated with `extractable` set to
|
|
31
|
+
* `false` by default.
|
|
41
32
|
*
|
|
42
33
|
* @example Usage
|
|
34
|
+
*
|
|
43
35
|
* ```js
|
|
44
36
|
* const { publicKey, privateKey } = await jose.generateKeyPair('PS256')
|
|
45
37
|
* console.log(publicKey)
|
|
46
38
|
* console.log(privateKey)
|
|
47
39
|
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param alg JWA Algorithm Identifier to be used with the generated key pair.
|
|
42
|
+
* @param options Additional options passed down to the key pair generation.
|
|
48
43
|
*/
|
|
49
44
|
export declare function generateKeyPair(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult>;
|
|
@@ -10,10 +10,11 @@ export interface GenerateSecretOptions {
|
|
|
10
10
|
/**
|
|
11
11
|
* Generates a symmetric secret key for a given JWA algorithm identifier.
|
|
12
12
|
*
|
|
13
|
-
* Note: Under Web Cryptography API runtime the secret key is generated with
|
|
14
|
-
* `
|
|
13
|
+
* Note: Under Web Cryptography API runtime the secret key is generated with `extractable` set to
|
|
14
|
+
* `false` by default.
|
|
15
15
|
*
|
|
16
16
|
* @example Usage
|
|
17
|
+
*
|
|
17
18
|
* ```js
|
|
18
19
|
* const secret = await jose.generateSecret('HS256')
|
|
19
20
|
* console.log(secret)
|
|
@@ -8,14 +8,12 @@ export interface PEMImportOptions {
|
|
|
8
8
|
extractable?: boolean;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Imports
|
|
12
|
-
* See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
|
|
13
|
-
* requirements and mapping.
|
|
14
|
-
*
|
|
15
|
-
* @param pem PEM-encoded SPKI string
|
|
16
|
-
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
11
|
+
* Imports a PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or
|
|
12
|
+
* CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
|
|
13
|
+
* about key to algorithm requirements and mapping.
|
|
17
14
|
*
|
|
18
15
|
* @example Usage
|
|
16
|
+
*
|
|
19
17
|
* ```js
|
|
20
18
|
* const algorithm = 'ES256'
|
|
21
19
|
* const spki = `-----BEGIN PUBLIC KEY-----
|
|
@@ -24,17 +22,19 @@ export interface PEMImportOptions {
|
|
|
24
22
|
* -----END PUBLIC KEY-----`
|
|
25
23
|
* const ecPublicKey = await jose.importSPKI(spki, algorithm)
|
|
26
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param pem PEM-encoded SPKI string
|
|
27
|
+
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
27
28
|
*/
|
|
28
29
|
export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
29
30
|
/**
|
|
30
|
-
* Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
|
|
31
|
-
* See [Algorithm Key
|
|
31
|
+
* Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
|
|
32
|
+
* (KeyObject or CryptoKey). See [Algorithm Key
|
|
33
|
+
* Requirements](https://github.com/panva/jose/issues/210) to learn about key to algorithm
|
|
32
34
|
* requirements and mapping.
|
|
33
35
|
*
|
|
34
|
-
* @param pem X.509 certificate string
|
|
35
|
-
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
36
|
-
*
|
|
37
36
|
* @example Usage
|
|
37
|
+
*
|
|
38
38
|
* ```js
|
|
39
39
|
* const algorithm = 'ES256'
|
|
40
40
|
* const x509 = `-----BEGIN CERTIFICATE-----
|
|
@@ -49,17 +49,18 @@ export declare function importSPKI(spki: string, alg: string, options?: PEMImpor
|
|
|
49
49
|
* -----END CERTIFICATE-----`
|
|
50
50
|
* const ecPublicKey = await jose.importX509(x509, algorithm)
|
|
51
51
|
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param pem X.509 certificate string
|
|
54
|
+
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
52
55
|
*/
|
|
53
56
|
export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
54
57
|
/**
|
|
55
|
-
* Imports
|
|
56
|
-
* See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
|
|
57
|
-
* requirements and mapping. Encrypted keys are not supported.
|
|
58
|
-
*
|
|
59
|
-
* @param pem PEM-encoded PKCS8 string
|
|
60
|
-
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
58
|
+
* Imports a PEM-encoded PKCS8 string as a runtime-specific private key representation (KeyObject or
|
|
59
|
+
* CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
|
|
60
|
+
* about key to algorithm requirements and mapping. Encrypted keys are not supported.
|
|
61
61
|
*
|
|
62
62
|
* @example Usage
|
|
63
|
+
*
|
|
63
64
|
* ```js
|
|
64
65
|
* const algorithm = 'ES256'
|
|
65
66
|
* const pkcs8 = `-----BEGIN PRIVATE KEY-----
|
|
@@ -69,36 +70,46 @@ export declare function importX509(x509: string, alg: string, options?: PEMImpor
|
|
|
69
70
|
* -----END PRIVATE KEY-----`
|
|
70
71
|
* const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
|
|
71
72
|
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param pem PEM-encoded PKCS8 string
|
|
75
|
+
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
72
76
|
*/
|
|
73
77
|
export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
74
78
|
/**
|
|
75
|
-
* Imports a JWK to a runtime-specific key representation (KeyLike). Either
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
79
|
+
* Imports a JWK to a runtime-specific key representation (KeyLike). Either JWK "alg" (Algorithm)
|
|
80
|
+
* Parameter must be present or the optional "alg" argument. When running on a runtime using [Web
|
|
81
|
+
* Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) the jwk parameters "use", "key_ops", and
|
|
82
|
+
* "ext" are also used in the resulting `CryptoKey`. See [Algorithm Key
|
|
83
|
+
* Requirements](https://github.com/panva/jose/issues/210) to learn about key to algorithm
|
|
80
84
|
* requirements and mapping.
|
|
81
85
|
*
|
|
82
|
-
* @param jwk JSON Web Key.
|
|
83
|
-
* @param alg JSON Web Algorithm identifier to be used with the imported key.
|
|
84
|
-
* Default is the "alg" property on the JWK.
|
|
85
|
-
* @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or
|
|
86
|
-
* CryptoKey. Default is true unless JWK "ext" (Extractable) is true.
|
|
87
|
-
*
|
|
88
86
|
* @example Usage
|
|
87
|
+
*
|
|
89
88
|
* ```js
|
|
90
|
-
* const ecPublicKey = await jose.importJWK(
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
89
|
+
* const ecPublicKey = await jose.importJWK(
|
|
90
|
+
* {
|
|
91
|
+
* crv: 'P-256',
|
|
92
|
+
* kty: 'EC',
|
|
93
|
+
* x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
|
|
94
|
+
* y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo',
|
|
95
|
+
* },
|
|
96
|
+
* 'ES256',
|
|
97
|
+
* )
|
|
96
98
|
*
|
|
97
|
-
* const rsaPublicKey = await jose.importJWK(
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
99
|
+
* const rsaPublicKey = await jose.importJWK(
|
|
100
|
+
* {
|
|
101
|
+
* kty: 'RSA',
|
|
102
|
+
* e: 'AQAB',
|
|
103
|
+
* n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ',
|
|
104
|
+
* },
|
|
105
|
+
* 'PS256',
|
|
106
|
+
* )
|
|
102
107
|
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param jwk JSON Web Key.
|
|
110
|
+
* @param alg JSON Web Algorithm identifier to be used with the imported key. Default is the "alg"
|
|
111
|
+
* property on the JWK.
|
|
112
|
+
* @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default
|
|
113
|
+
* is true unless JWK "ext" (Extractable) is true.
|
|
103
114
|
*/
|
|
104
115
|
export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike | Uint8Array>;
|