jose 5.2.0 → 5.2.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.
- package/README.md +6 -6
- package/dist/browser/jwe/flattened/decrypt.js +1 -1
- package/dist/browser/jwe/general/encrypt.js +2 -2
- package/dist/browser/jwks/local.js +3 -7
- package/dist/browser/jwks/remote.js +2 -4
- package/dist/browser/lib/buffer_utils.js +2 -2
- package/dist/browser/lib/invalid_key_input.js +1 -1
- package/dist/browser/lib/validate_crit.js +1 -1
- package/dist/browser/runtime/asn1.js +4 -4
- package/dist/browser/runtime/generate.js +2 -1
- package/dist/node/cjs/jwe/flattened/decrypt.js +1 -1
- package/dist/node/cjs/jwe/general/encrypt.js +2 -2
- package/dist/node/cjs/jwks/local.js +3 -7
- package/dist/node/cjs/jwks/remote.js +2 -4
- package/dist/node/cjs/lib/buffer_utils.js +2 -2
- package/dist/node/cjs/lib/invalid_key_input.js +1 -1
- package/dist/node/cjs/lib/validate_crit.js +1 -1
- package/dist/node/cjs/runtime/generate.js +2 -1
- package/dist/node/cjs/runtime/get_named_curve.js +1 -1
- package/dist/node/esm/jwe/flattened/decrypt.js +1 -1
- package/dist/node/esm/jwe/general/encrypt.js +2 -2
- package/dist/node/esm/jwks/local.js +3 -7
- package/dist/node/esm/jwks/remote.js +2 -4
- package/dist/node/esm/lib/buffer_utils.js +2 -2
- package/dist/node/esm/lib/invalid_key_input.js +1 -1
- package/dist/node/esm/lib/validate_crit.js +1 -1
- package/dist/node/esm/runtime/generate.js +2 -1
- package/dist/node/esm/runtime/get_named_curve.js +1 -1
- package/dist/types/key/import.d.ts +3 -3
- package/dist/types/util/errors.d.ts +22 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,10 +28,10 @@ const jose = require('jose')
|
|
|
28
28
|
|
|
29
29
|
The `jose` module supports JSON Web Tokens (JWT) and provides functionality for signing and verifying tokens, as well as their JWT Claims Set validation.
|
|
30
30
|
|
|
31
|
+
- [JWT Claims Set Validation & Signature Verification](docs/functions/jwt_verify.jwtVerify.md) using the `jwtVerify` function
|
|
32
|
+
- [Using a remote JSON Web Key Set (JWKS)](docs/functions/jwks_remote.createRemoteJWKSet.md)
|
|
33
|
+
- [Using a local JSON Web Key Set (JWKS)](docs/functions/jwks_local.createLocalJWKSet.md)
|
|
31
34
|
- [Signing](docs/classes/jwt_sign.SignJWT.md) using the `SignJWT` class
|
|
32
|
-
- [Verification & JWT Claims Set Validation](docs/functions/jwt_verify.jwtVerify.md) using the `jwtVerify` function
|
|
33
|
-
- [Using a remote JWKS](docs/functions/jwks_remote.createRemoteJWKSet.md)
|
|
34
|
-
- [Using a local JWKS](docs/functions/jwks_local.createLocalJWKSet.md)
|
|
35
35
|
- Utility functions
|
|
36
36
|
- [Decoding Token's Protected Header](docs/functions/util_decode_protected_header.decodeProtectedHeader.md)
|
|
37
37
|
- [Decoding JWT Claims Set](docs/functions/util_decode_jwt.decodeJwt.md) prior to its validation
|
|
@@ -40,8 +40,8 @@ The `jose` module supports JSON Web Tokens (JWT) and provides functionality for
|
|
|
40
40
|
|
|
41
41
|
The `jose` module supports encrypted JSON Web Tokens and provides functionality for encrypting and decrypting tokens, as well as their JWT Claims Set validation.
|
|
42
42
|
|
|
43
|
-
- [Encryption](docs/classes/jwt_encrypt.EncryptJWT.md) using the `EncryptJWT` class
|
|
44
43
|
- [Decryption & JWT Claims Set Validation](docs/functions/jwt_decrypt.jwtDecrypt.md) using the `jwtDecrypt` function
|
|
44
|
+
- [Encryption](docs/classes/jwt_encrypt.EncryptJWT.md) using the `EncryptJWT` class
|
|
45
45
|
- Utility functions
|
|
46
46
|
- [Decoding Token's Protected Header](docs/functions/util_decode_protected_header.decodeProtectedHeader.md)
|
|
47
47
|
|
|
@@ -68,8 +68,8 @@ The `jose` module supports signing and verification of JWS messages with arbitra
|
|
|
68
68
|
|
|
69
69
|
- Signing - [Compact](docs/classes/jws_compact_sign.CompactSign.md), [Flattened JSON](docs/classes/jws_flattened_sign.FlattenedSign.md), [General JSON](docs/classes/jws_general_sign.GeneralSign.md)
|
|
70
70
|
- Verification - [Compact](docs/functions/jws_compact_verify.compactVerify.md), [Flattened JSON](docs/functions/jws_flattened_verify.flattenedVerify.md), [General JSON](docs/functions/jws_general_verify.generalVerify.md)
|
|
71
|
-
- [
|
|
72
|
-
- [
|
|
71
|
+
- [Using a remote JSON Web Key Set (JWKS)](docs/functions/jwks_remote.createRemoteJWKSet.md)
|
|
72
|
+
- [Using a local JSON Web Key Set (JWKS)](docs/functions/jwks_local.createLocalJWKSet.md)
|
|
73
73
|
- Utility functions
|
|
74
74
|
- [Decoding Token's Protected Header](docs/functions/util_decode_protected_header.decodeProtectedHeader.md)
|
|
75
75
|
|
|
@@ -131,7 +131,7 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
131
131
|
catch {
|
|
132
132
|
throw new JWEInvalid('Failed to base64url decode the ciphertext');
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag, additionalData);
|
|
135
135
|
const result = { plaintext };
|
|
136
136
|
if (jwe.protected !== undefined) {
|
|
137
137
|
result.protectedHeader = parsedProt;
|
|
@@ -68,7 +68,7 @@ export class GeneralEncrypt {
|
|
|
68
68
|
.setSharedUnprotectedHeader(this._unprotectedHeader)
|
|
69
69
|
.setUnprotectedHeader(recipient.unprotectedHeader)
|
|
70
70
|
.encrypt(recipient.key, { ...recipient.options });
|
|
71
|
-
|
|
71
|
+
const jwe = {
|
|
72
72
|
ciphertext: flattened.ciphertext,
|
|
73
73
|
iv: flattened.iv,
|
|
74
74
|
recipients: [{}],
|
|
@@ -119,7 +119,7 @@ export class GeneralEncrypt {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
const cek = generateCek(enc);
|
|
122
|
-
|
|
122
|
+
const jwe = {
|
|
123
123
|
ciphertext: '',
|
|
124
124
|
iv: '',
|
|
125
125
|
recipients: [],
|
|
@@ -79,7 +79,7 @@ export class LocalJWKSet {
|
|
|
79
79
|
if (length === 0) {
|
|
80
80
|
throw new JWKSNoMatchingKey();
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
if (length !== 1) {
|
|
83
83
|
const error = new JWKSMultipleMatchingKeys();
|
|
84
84
|
const { _cached } = this;
|
|
85
85
|
error[Symbol.asyncIterator] = async function* () {
|
|
@@ -87,9 +87,7 @@ export class LocalJWKSet {
|
|
|
87
87
|
try {
|
|
88
88
|
yield await importWithAlgCache(_cached, jwk, alg);
|
|
89
89
|
}
|
|
90
|
-
catch {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
90
|
+
catch { }
|
|
93
91
|
}
|
|
94
92
|
};
|
|
95
93
|
throw error;
|
|
@@ -110,7 +108,5 @@ async function importWithAlgCache(cache, jwk, alg) {
|
|
|
110
108
|
}
|
|
111
109
|
export function createLocalJWKSet(jwks) {
|
|
112
110
|
const set = new LocalJWKSet(jwks);
|
|
113
|
-
return async
|
|
114
|
-
return set.getKey(protectedHeader, token);
|
|
115
|
-
};
|
|
111
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
116
112
|
}
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.2.
|
|
12
|
+
const VERSION = 'v5.2.1';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -81,7 +81,5 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
81
81
|
}
|
|
82
82
|
export function createRemoteJWKSet(url, options) {
|
|
83
83
|
const set = new RemoteJWKSet(url, options);
|
|
84
|
-
return async
|
|
85
|
-
return set.getKey(protectedHeader, token);
|
|
86
|
-
};
|
|
84
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
87
85
|
}
|
|
@@ -6,10 +6,10 @@ export function concat(...buffers) {
|
|
|
6
6
|
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
7
7
|
const buf = new Uint8Array(size);
|
|
8
8
|
let i = 0;
|
|
9
|
-
|
|
9
|
+
for (const buffer of buffers) {
|
|
10
10
|
buf.set(buffer, i);
|
|
11
11
|
i += buffer.length;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
return buf;
|
|
14
14
|
}
|
|
15
15
|
export function p2s(alg, p2sInput) {
|
|
@@ -16,7 +16,7 @@ function message(msg, actual, ...types) {
|
|
|
16
16
|
msg += ` Received function ${actual.name}`;
|
|
17
17
|
}
|
|
18
18
|
else if (typeof actual === 'object' && actual != null) {
|
|
19
|
-
if (actual.constructor
|
|
19
|
+
if (actual.constructor?.name) {
|
|
20
20
|
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -25,7 +25,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
25
25
|
if (joseHeader[parameter] === undefined) {
|
|
26
26
|
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
29
29
|
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -27,7 +27,7 @@ const findOid = (keyData, oid, from = 0) => {
|
|
|
27
27
|
oid.unshift(oid.length);
|
|
28
28
|
oid.unshift(0x06);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const i = keyData.indexOf(oid[0], from);
|
|
31
31
|
if (i === -1)
|
|
32
32
|
return false;
|
|
33
33
|
const sub = keyData.subarray(i, i + oid.length);
|
|
@@ -122,10 +122,10 @@ export const fromSPKI = (pem, alg, options) => {
|
|
|
122
122
|
return genericImport(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, 'spki', pem, alg, options);
|
|
123
123
|
};
|
|
124
124
|
function getElement(seq) {
|
|
125
|
-
|
|
125
|
+
const result = [];
|
|
126
126
|
let next = 0;
|
|
127
127
|
while (next < seq.length) {
|
|
128
|
-
|
|
128
|
+
const nextPart = parseElement(seq.subarray(next));
|
|
129
129
|
result.push(nextPart);
|
|
130
130
|
next += nextPart.byteLength;
|
|
131
131
|
}
|
|
@@ -165,7 +165,7 @@ function parseElement(bytes) {
|
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
else {
|
|
168
|
-
|
|
168
|
+
const numberOfDigits = bytes[position] & 0x7f;
|
|
169
169
|
position++;
|
|
170
170
|
length = 0;
|
|
171
171
|
for (let i = 0; i < numberOfDigits; i++) {
|
|
@@ -97,7 +97,7 @@ export async function generateKeyPair(alg, options) {
|
|
|
97
97
|
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
|
98
98
|
keyUsages = ['sign', 'verify'];
|
|
99
99
|
break;
|
|
100
|
-
case 'EdDSA':
|
|
100
|
+
case 'EdDSA': {
|
|
101
101
|
keyUsages = ['sign', 'verify'];
|
|
102
102
|
const crv = options?.crv ?? 'Ed25519';
|
|
103
103
|
switch (crv) {
|
|
@@ -109,6 +109,7 @@ export async function generateKeyPair(alg, options) {
|
|
|
109
109
|
throw new JOSENotSupported('Invalid or unsupported crv option provided');
|
|
110
110
|
}
|
|
111
111
|
break;
|
|
112
|
+
}
|
|
112
113
|
case 'ECDH-ES':
|
|
113
114
|
case 'ECDH-ES+A128KW':
|
|
114
115
|
case 'ECDH-ES+A192KW':
|
|
@@ -134,7 +134,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
134
134
|
catch {
|
|
135
135
|
throw new errors_js_1.JWEInvalid('Failed to base64url decode the ciphertext');
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
const plaintext = await (0, decrypt_js_1.default)(enc, cek, ciphertext, iv, tag, additionalData);
|
|
138
138
|
const result = { plaintext };
|
|
139
139
|
if (jwe.protected !== undefined) {
|
|
140
140
|
result.protectedHeader = parsedProt;
|
|
@@ -79,7 +79,7 @@ class GeneralEncrypt {
|
|
|
79
79
|
.setSharedUnprotectedHeader(this._unprotectedHeader)
|
|
80
80
|
.setUnprotectedHeader(recipient.unprotectedHeader)
|
|
81
81
|
.encrypt(recipient.key, { ...recipient.options });
|
|
82
|
-
|
|
82
|
+
const jwe = {
|
|
83
83
|
ciphertext: flattened.ciphertext,
|
|
84
84
|
iv: flattened.iv,
|
|
85
85
|
recipients: [{}],
|
|
@@ -130,7 +130,7 @@ class GeneralEncrypt {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
const cek = (0, cek_js_1.default)(enc);
|
|
133
|
-
|
|
133
|
+
const jwe = {
|
|
134
134
|
ciphertext: '',
|
|
135
135
|
iv: '',
|
|
136
136
|
recipients: [],
|
|
@@ -84,7 +84,7 @@ class LocalJWKSet {
|
|
|
84
84
|
if (length === 0) {
|
|
85
85
|
throw new errors_js_1.JWKSNoMatchingKey();
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
if (length !== 1) {
|
|
88
88
|
const error = new errors_js_1.JWKSMultipleMatchingKeys();
|
|
89
89
|
const { _cached } = this;
|
|
90
90
|
error[Symbol.asyncIterator] = async function* () {
|
|
@@ -92,9 +92,7 @@ class LocalJWKSet {
|
|
|
92
92
|
try {
|
|
93
93
|
yield await importWithAlgCache(_cached, jwk, alg);
|
|
94
94
|
}
|
|
95
|
-
catch {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
95
|
+
catch { }
|
|
98
96
|
}
|
|
99
97
|
};
|
|
100
98
|
throw error;
|
|
@@ -116,8 +114,6 @@ async function importWithAlgCache(cache, jwk, alg) {
|
|
|
116
114
|
}
|
|
117
115
|
function createLocalJWKSet(jwks) {
|
|
118
116
|
const set = new LocalJWKSet(jwks);
|
|
119
|
-
return async
|
|
120
|
-
return set.getKey(protectedHeader, token);
|
|
121
|
-
};
|
|
117
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
122
118
|
}
|
|
123
119
|
exports.createLocalJWKSet = createLocalJWKSet;
|
|
@@ -12,7 +12,7 @@ function isCloudflareWorkers() {
|
|
|
12
12
|
let USER_AGENT;
|
|
13
13
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
14
14
|
const NAME = 'jose';
|
|
15
|
-
const VERSION = 'v5.2.
|
|
15
|
+
const VERSION = 'v5.2.1';
|
|
16
16
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
17
17
|
}
|
|
18
18
|
class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
@@ -91,8 +91,6 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
|
91
91
|
}
|
|
92
92
|
function createRemoteJWKSet(url, options) {
|
|
93
93
|
const set = new RemoteJWKSet(url, options);
|
|
94
|
-
return async
|
|
95
|
-
return set.getKey(protectedHeader, token);
|
|
96
|
-
};
|
|
94
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
97
95
|
}
|
|
98
96
|
exports.createRemoteJWKSet = createRemoteJWKSet;
|
|
@@ -9,10 +9,10 @@ function concat(...buffers) {
|
|
|
9
9
|
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
10
10
|
const buf = new Uint8Array(size);
|
|
11
11
|
let i = 0;
|
|
12
|
-
|
|
12
|
+
for (const buffer of buffers) {
|
|
13
13
|
buf.set(buffer, i);
|
|
14
14
|
i += buffer.length;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
return buf;
|
|
17
17
|
}
|
|
18
18
|
exports.concat = concat;
|
|
@@ -19,7 +19,7 @@ function message(msg, actual, ...types) {
|
|
|
19
19
|
msg += ` Received function ${actual.name}`;
|
|
20
20
|
}
|
|
21
21
|
else if (typeof actual === 'object' && actual != null) {
|
|
22
|
-
if (actual.constructor
|
|
22
|
+
if (actual.constructor?.name) {
|
|
23
23
|
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
27
27
|
if (joseHeader[parameter] === undefined) {
|
|
28
28
|
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
31
31
|
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -79,7 +79,7 @@ async function generateKeyPair(alg, options) {
|
|
|
79
79
|
case 'ECDH-ES':
|
|
80
80
|
case 'ECDH-ES+A128KW':
|
|
81
81
|
case 'ECDH-ES+A192KW':
|
|
82
|
-
case 'ECDH-ES+A256KW':
|
|
82
|
+
case 'ECDH-ES+A256KW': {
|
|
83
83
|
const crv = options?.crv ?? 'P-256';
|
|
84
84
|
switch (crv) {
|
|
85
85
|
case undefined:
|
|
@@ -94,6 +94,7 @@ async function generateKeyPair(alg, options) {
|
|
|
94
94
|
default:
|
|
95
95
|
throw new errors_js_1.JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448');
|
|
96
96
|
}
|
|
97
|
+
}
|
|
97
98
|
default:
|
|
98
99
|
throw new errors_js_1.JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
99
100
|
}
|
|
@@ -44,7 +44,7 @@ const getNamedCurve = (kee, raw) => {
|
|
|
44
44
|
case 'x448':
|
|
45
45
|
return `X${key.asymmetricKeyType.slice(1)}`;
|
|
46
46
|
case 'ec': {
|
|
47
|
-
|
|
47
|
+
const namedCurve = key.asymmetricKeyDetails.namedCurve;
|
|
48
48
|
if (raw) {
|
|
49
49
|
return namedCurve;
|
|
50
50
|
}
|
|
@@ -131,7 +131,7 @@ export async function flattenedDecrypt(jwe, key, options) {
|
|
|
131
131
|
catch {
|
|
132
132
|
throw new JWEInvalid('Failed to base64url decode the ciphertext');
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag, additionalData);
|
|
135
135
|
const result = { plaintext };
|
|
136
136
|
if (jwe.protected !== undefined) {
|
|
137
137
|
result.protectedHeader = parsedProt;
|
|
@@ -76,7 +76,7 @@ export class GeneralEncrypt {
|
|
|
76
76
|
.setSharedUnprotectedHeader(this._unprotectedHeader)
|
|
77
77
|
.setUnprotectedHeader(recipient.unprotectedHeader)
|
|
78
78
|
.encrypt(recipient.key, { ...recipient.options });
|
|
79
|
-
|
|
79
|
+
const jwe = {
|
|
80
80
|
ciphertext: flattened.ciphertext,
|
|
81
81
|
iv: flattened.iv,
|
|
82
82
|
recipients: [{}],
|
|
@@ -127,7 +127,7 @@ export class GeneralEncrypt {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
const cek = generateCek(enc);
|
|
130
|
-
|
|
130
|
+
const jwe = {
|
|
131
131
|
ciphertext: '',
|
|
132
132
|
iv: '',
|
|
133
133
|
recipients: [],
|
|
@@ -80,7 +80,7 @@ export class LocalJWKSet {
|
|
|
80
80
|
if (length === 0) {
|
|
81
81
|
throw new JWKSNoMatchingKey();
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
if (length !== 1) {
|
|
84
84
|
const error = new JWKSMultipleMatchingKeys();
|
|
85
85
|
const { _cached } = this;
|
|
86
86
|
error[Symbol.asyncIterator] = async function* () {
|
|
@@ -88,9 +88,7 @@ export class LocalJWKSet {
|
|
|
88
88
|
try {
|
|
89
89
|
yield await importWithAlgCache(_cached, jwk, alg);
|
|
90
90
|
}
|
|
91
|
-
catch {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
91
|
+
catch { }
|
|
94
92
|
}
|
|
95
93
|
};
|
|
96
94
|
throw error;
|
|
@@ -111,7 +109,5 @@ async function importWithAlgCache(cache, jwk, alg) {
|
|
|
111
109
|
}
|
|
112
110
|
export function createLocalJWKSet(jwks) {
|
|
113
111
|
const set = new LocalJWKSet(jwks);
|
|
114
|
-
return async
|
|
115
|
-
return set.getKey(protectedHeader, token);
|
|
116
|
-
};
|
|
112
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
117
113
|
}
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v5.2.
|
|
12
|
+
const VERSION = 'v5.2.1';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
class RemoteJWKSet extends LocalJWKSet {
|
|
@@ -88,7 +88,5 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
88
88
|
}
|
|
89
89
|
export function createRemoteJWKSet(url, options) {
|
|
90
90
|
const set = new RemoteJWKSet(url, options);
|
|
91
|
-
return async
|
|
92
|
-
return set.getKey(protectedHeader, token);
|
|
93
|
-
};
|
|
91
|
+
return async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
94
92
|
}
|
|
@@ -6,10 +6,10 @@ export function concat(...buffers) {
|
|
|
6
6
|
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
7
7
|
const buf = new Uint8Array(size);
|
|
8
8
|
let i = 0;
|
|
9
|
-
|
|
9
|
+
for (const buffer of buffers) {
|
|
10
10
|
buf.set(buffer, i);
|
|
11
11
|
i += buffer.length;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
return buf;
|
|
14
14
|
}
|
|
15
15
|
export function p2s(alg, p2sInput) {
|
|
@@ -16,7 +16,7 @@ function message(msg, actual, ...types) {
|
|
|
16
16
|
msg += ` Received function ${actual.name}`;
|
|
17
17
|
}
|
|
18
18
|
else if (typeof actual === 'object' && actual != null) {
|
|
19
|
-
if (actual.constructor
|
|
19
|
+
if (actual.constructor?.name) {
|
|
20
20
|
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -25,7 +25,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
25
25
|
if (joseHeader[parameter] === undefined) {
|
|
26
26
|
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
29
29
|
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -75,7 +75,7 @@ export async function generateKeyPair(alg, options) {
|
|
|
75
75
|
case 'ECDH-ES':
|
|
76
76
|
case 'ECDH-ES+A128KW':
|
|
77
77
|
case 'ECDH-ES+A192KW':
|
|
78
|
-
case 'ECDH-ES+A256KW':
|
|
78
|
+
case 'ECDH-ES+A256KW': {
|
|
79
79
|
const crv = options?.crv ?? 'P-256';
|
|
80
80
|
switch (crv) {
|
|
81
81
|
case undefined:
|
|
@@ -90,6 +90,7 @@ export async function generateKeyPair(alg, options) {
|
|
|
90
90
|
default:
|
|
91
91
|
throw new JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448');
|
|
92
92
|
}
|
|
93
|
+
}
|
|
93
94
|
default:
|
|
94
95
|
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
95
96
|
}
|
|
@@ -41,7 +41,7 @@ const getNamedCurve = (kee, raw) => {
|
|
|
41
41
|
case 'x448':
|
|
42
42
|
return `X${key.asymmetricKeyType.slice(1)}`;
|
|
43
43
|
case 'ec': {
|
|
44
|
-
|
|
44
|
+
const namedCurve = key.asymmetricKeyDetails.namedCurve;
|
|
45
45
|
if (raw) {
|
|
46
46
|
return namedCurve;
|
|
47
47
|
}
|
|
@@ -11,7 +11,7 @@ export interface PEMImportOptions {
|
|
|
11
11
|
* Imports a PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or
|
|
12
12
|
* CryptoKey).
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param spki PEM-encoded SPKI string
|
|
15
15
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
16
16
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
17
17
|
* {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
|
|
@@ -21,7 +21,7 @@ export declare function importSPKI<KeyLikeType extends KeyLike = KeyLike>(spki:
|
|
|
21
21
|
* Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
|
|
22
22
|
* (KeyObject or CryptoKey).
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
24
|
+
* @param x509 X.509 certificate string
|
|
25
25
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
26
26
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
27
27
|
* {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
|
|
@@ -31,7 +31,7 @@ export declare function importX509<KeyLikeType extends KeyLike = KeyLike>(x509:
|
|
|
31
31
|
* Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject
|
|
32
32
|
* or CryptoKey).
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
34
|
+
* @param pkcs8 PEM-encoded PKCS#8 string
|
|
35
35
|
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
|
|
36
36
|
* with the imported key, its presence is only enforced in Web Crypto API runtimes. See
|
|
37
37
|
* {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
|
|
@@ -4,10 +4,15 @@ import type { KeyLike } from '../types';
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
export declare class JOSEError extends Error {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* A unique error code for the particular error subclass.
|
|
9
|
+
*
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
8
12
|
static get code(): string;
|
|
9
|
-
/** A unique error code for
|
|
13
|
+
/** A unique error code for this particular error subclass. */
|
|
10
14
|
code: string;
|
|
15
|
+
/** @ignore */
|
|
11
16
|
constructor(message?: string);
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
@@ -15,12 +20,14 @@ export declare class JOSEError extends Error {
|
|
|
15
20
|
*
|
|
16
21
|
*/
|
|
17
22
|
export declare class JWTClaimValidationFailed extends JOSEError {
|
|
23
|
+
/** @ignore */
|
|
18
24
|
static get code(): 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
19
25
|
code: string;
|
|
20
26
|
/** The Claim for which the validation failed. */
|
|
21
27
|
claim: string;
|
|
22
28
|
/** Reason code for the validation failure. */
|
|
23
29
|
reason: string;
|
|
30
|
+
/** @ignore */
|
|
24
31
|
constructor(message: string, claim?: string, reason?: string);
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
@@ -28,12 +35,14 @@ export declare class JWTClaimValidationFailed extends JOSEError {
|
|
|
28
35
|
*
|
|
29
36
|
*/
|
|
30
37
|
export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
|
|
38
|
+
/** @ignore */
|
|
31
39
|
static get code(): 'ERR_JWT_EXPIRED';
|
|
32
40
|
code: string;
|
|
33
41
|
/** The Claim for which the validation failed. */
|
|
34
42
|
claim: string;
|
|
35
43
|
/** Reason code for the validation failure. */
|
|
36
44
|
reason: string;
|
|
45
|
+
/** @ignore */
|
|
37
46
|
constructor(message: string, claim?: string, reason?: string);
|
|
38
47
|
}
|
|
39
48
|
/**
|
|
@@ -41,6 +50,7 @@ export declare class JWTExpired extends JOSEError implements JWTClaimValidationF
|
|
|
41
50
|
*
|
|
42
51
|
*/
|
|
43
52
|
export declare class JOSEAlgNotAllowed extends JOSEError {
|
|
53
|
+
/** @ignore */
|
|
44
54
|
static get code(): 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
45
55
|
code: string;
|
|
46
56
|
}
|
|
@@ -50,6 +60,7 @@ export declare class JOSEAlgNotAllowed extends JOSEError {
|
|
|
50
60
|
*
|
|
51
61
|
*/
|
|
52
62
|
export declare class JOSENotSupported extends JOSEError {
|
|
63
|
+
/** @ignore */
|
|
53
64
|
static get code(): 'ERR_JOSE_NOT_SUPPORTED';
|
|
54
65
|
code: string;
|
|
55
66
|
}
|
|
@@ -58,6 +69,7 @@ export declare class JOSENotSupported extends JOSEError {
|
|
|
58
69
|
*
|
|
59
70
|
*/
|
|
60
71
|
export declare class JWEDecryptionFailed extends JOSEError {
|
|
72
|
+
/** @ignore */
|
|
61
73
|
static get code(): 'ERR_JWE_DECRYPTION_FAILED';
|
|
62
74
|
code: string;
|
|
63
75
|
message: string;
|
|
@@ -67,6 +79,7 @@ export declare class JWEDecryptionFailed extends JOSEError {
|
|
|
67
79
|
*
|
|
68
80
|
*/
|
|
69
81
|
export declare class JWEInvalid extends JOSEError {
|
|
82
|
+
/** @ignore */
|
|
70
83
|
static get code(): 'ERR_JWE_INVALID';
|
|
71
84
|
code: string;
|
|
72
85
|
}
|
|
@@ -75,6 +88,7 @@ export declare class JWEInvalid extends JOSEError {
|
|
|
75
88
|
*
|
|
76
89
|
*/
|
|
77
90
|
export declare class JWSInvalid extends JOSEError {
|
|
91
|
+
/** @ignore */
|
|
78
92
|
static get code(): 'ERR_JWS_INVALID';
|
|
79
93
|
code: string;
|
|
80
94
|
}
|
|
@@ -83,6 +97,7 @@ export declare class JWSInvalid extends JOSEError {
|
|
|
83
97
|
*
|
|
84
98
|
*/
|
|
85
99
|
export declare class JWTInvalid extends JOSEError {
|
|
100
|
+
/** @ignore */
|
|
86
101
|
static get code(): 'ERR_JWT_INVALID';
|
|
87
102
|
code: string;
|
|
88
103
|
}
|
|
@@ -91,6 +106,7 @@ export declare class JWTInvalid extends JOSEError {
|
|
|
91
106
|
*
|
|
92
107
|
*/
|
|
93
108
|
export declare class JWKInvalid extends JOSEError {
|
|
109
|
+
/** @ignore */
|
|
94
110
|
static get code(): 'ERR_JWK_INVALID';
|
|
95
111
|
code: string;
|
|
96
112
|
}
|
|
@@ -99,6 +115,7 @@ export declare class JWKInvalid extends JOSEError {
|
|
|
99
115
|
*
|
|
100
116
|
*/
|
|
101
117
|
export declare class JWKSInvalid extends JOSEError {
|
|
118
|
+
/** @ignore */
|
|
102
119
|
static get code(): 'ERR_JWKS_INVALID';
|
|
103
120
|
code: string;
|
|
104
121
|
}
|
|
@@ -107,6 +124,7 @@ export declare class JWKSInvalid extends JOSEError {
|
|
|
107
124
|
*
|
|
108
125
|
*/
|
|
109
126
|
export declare class JWKSNoMatchingKey extends JOSEError {
|
|
127
|
+
/** @ignore */
|
|
110
128
|
static get code(): 'ERR_JWKS_NO_MATCHING_KEY';
|
|
111
129
|
code: string;
|
|
112
130
|
message: string;
|
|
@@ -127,6 +145,7 @@ export declare class JWKSMultipleMatchingKeys extends JOSEError {
|
|
|
127
145
|
*
|
|
128
146
|
*/
|
|
129
147
|
export declare class JWKSTimeout extends JOSEError {
|
|
148
|
+
/** @ignore */
|
|
130
149
|
static get code(): 'ERR_JWKS_TIMEOUT';
|
|
131
150
|
code: string;
|
|
132
151
|
message: string;
|
|
@@ -136,6 +155,7 @@ export declare class JWKSTimeout extends JOSEError {
|
|
|
136
155
|
*
|
|
137
156
|
*/
|
|
138
157
|
export declare class JWSSignatureVerificationFailed extends JOSEError {
|
|
158
|
+
/** @ignore */
|
|
139
159
|
static get code(): 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
140
160
|
code: string;
|
|
141
161
|
message: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jose",
|
|
3
|
-
"version": "5.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.2.1",
|
|
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",
|
|
7
7
|
"bun",
|