jose 3.19.0 → 3.20.3
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/dist/browser/jwe/flattened/decrypt.js +5 -9
- package/dist/browser/jwe/flattened/encrypt.js +2 -5
- package/dist/browser/jwk/embedded.js +2 -2
- package/dist/browser/jwks/remote.js +7 -10
- package/dist/browser/jws/flattened/sign.js +1 -2
- package/dist/browser/jws/flattened/verify.js +2 -4
- package/dist/browser/jwt/encrypt.js +1 -1
- package/dist/browser/{lib/jwt_producer.js → jwt/produce.js} +4 -4
- package/dist/browser/jwt/sign.js +1 -1
- package/dist/browser/jwt/unsecured.js +1 -1
- package/dist/browser/lib/cek.js +3 -2
- package/dist/browser/lib/check_key_type.js +33 -16
- package/dist/browser/lib/decrypt_key_management.js +35 -35
- package/dist/browser/lib/encrypt_key_management.js +3 -5
- package/dist/browser/lib/iv.js +3 -2
- package/dist/browser/runtime/aesgcmkw.js +1 -3
- package/dist/browser/runtime/fetch_jwks.js +16 -3
- package/dist/browser/runtime/is_key_like.js +5 -0
- package/dist/browser/runtime/random.js +1 -2
- package/dist/browser/util/errors.js +73 -34
- package/dist/node/cjs/jwe/flattened/decrypt.js +5 -9
- package/dist/node/cjs/jwe/flattened/encrypt.js +2 -5
- package/dist/node/cjs/jwk/embedded.js +2 -2
- package/dist/node/cjs/jwks/remote.js +7 -10
- package/dist/node/cjs/jws/flattened/sign.js +1 -2
- package/dist/node/cjs/jws/flattened/verify.js +2 -4
- package/dist/node/cjs/jwt/encrypt.js +2 -2
- package/dist/node/cjs/{lib/jwt_producer.js → jwt/produce.js} +5 -4
- package/dist/node/cjs/jwt/sign.js +2 -2
- package/dist/node/cjs/jwt/unsecured.js +2 -2
- package/dist/node/cjs/lib/cek.js +4 -3
- package/dist/node/cjs/lib/check_key_type.js +33 -16
- package/dist/node/cjs/lib/decrypt_key_management.js +35 -35
- package/dist/node/cjs/lib/encrypt_key_management.js +7 -9
- package/dist/node/cjs/lib/iv.js +4 -3
- package/dist/node/cjs/runtime/aesgcmkw.js +1 -3
- package/dist/node/cjs/runtime/fetch_jwks.js +5 -1
- package/dist/node/cjs/runtime/is_key_like.js +11 -0
- package/dist/node/cjs/runtime/random.js +3 -2
- package/dist/node/cjs/util/errors.js +77 -37
- package/dist/node/esm/jwe/flattened/decrypt.js +5 -9
- package/dist/node/esm/jwe/flattened/encrypt.js +2 -5
- package/dist/node/esm/jwk/embedded.js +2 -2
- package/dist/node/esm/jwks/remote.js +7 -10
- package/dist/node/esm/jws/flattened/sign.js +1 -2
- package/dist/node/esm/jws/flattened/verify.js +2 -4
- package/dist/node/esm/jwt/encrypt.js +1 -1
- package/dist/node/esm/{lib/jwt_producer.js → jwt/produce.js} +4 -4
- package/dist/node/esm/jwt/sign.js +1 -1
- package/dist/node/esm/jwt/unsecured.js +1 -1
- package/dist/node/esm/lib/cek.js +3 -2
- package/dist/node/esm/lib/check_key_type.js +33 -16
- package/dist/node/esm/lib/decrypt_key_management.js +35 -35
- package/dist/node/esm/lib/encrypt_key_management.js +3 -5
- package/dist/node/esm/lib/iv.js +3 -2
- package/dist/node/esm/runtime/aesgcmkw.js +1 -3
- package/dist/node/esm/runtime/fetch_jwks.js +6 -2
- package/dist/node/esm/runtime/is_key_like.js +8 -0
- package/dist/node/esm/runtime/random.js +1 -2
- package/dist/node/esm/util/errors.js +73 -34
- package/dist/types/jwe/compact/decrypt.d.ts +1 -1
- package/dist/types/jwe/compact/encrypt.d.ts +1 -1
- package/dist/types/jwe/flattened/decrypt.d.ts +1 -1
- package/dist/types/jwe/flattened/encrypt.d.ts +1 -1
- package/dist/types/jwe/general/decrypt.d.ts +1 -1
- package/dist/types/jwk/embedded.d.ts +2 -3
- package/dist/types/jwk/from_key_like.d.ts +1 -1
- package/dist/types/jwk/parse.d.ts +1 -1
- package/dist/types/jws/compact/sign.d.ts +1 -1
- package/dist/types/jws/compact/verify.d.ts +1 -1
- package/dist/types/jws/flattened/sign.d.ts +1 -1
- package/dist/types/jws/flattened/verify.d.ts +1 -1
- package/dist/types/jws/general/sign.d.ts +1 -1
- package/dist/types/jws/general/verify.d.ts +1 -1
- package/dist/types/jwt/decrypt.d.ts +1 -1
- package/dist/types/jwt/encrypt.d.ts +2 -2
- package/dist/types/{lib/jwt_producer.d.ts → jwt/produce.d.ts} +1 -1
- package/dist/types/jwt/sign.d.ts +2 -2
- package/dist/types/jwt/unsecured.d.ts +1 -1
- package/dist/types/jwt/verify.d.ts +1 -1
- package/dist/types/key/export.d.ts +3 -3
- package/dist/types/key/import.d.ts +4 -4
- package/dist/types/types.d.ts +99 -6
- package/dist/types/util/errors.d.ts +24 -16
- package/dist/types/util/generate_key_pair.d.ts +2 -2
- package/dist/types/util/generate_secret.d.ts +1 -1
- package/package.json +3 -4
|
@@ -8,81 +8,81 @@ import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
|
|
|
8
8
|
import { bitLengths as cekLengths } from '../lib/cek.js';
|
|
9
9
|
import { importJWK } from '../key/import.js';
|
|
10
10
|
import checkKeyType from './check_key_type.js';
|
|
11
|
-
|
|
12
|
-
if (!encryptedKey) {
|
|
13
|
-
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function assertHeaderParameter(joseHeader, parameter, name) {
|
|
17
|
-
if (joseHeader[parameter] === undefined) {
|
|
18
|
-
throw new JWEInvalid(`JOSE Header ${name} (${parameter}) missing`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
11
|
+
import isObject from './is_object.js';
|
|
21
12
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
|
|
22
13
|
checkKeyType(alg, key, 'decrypt');
|
|
23
14
|
switch (alg) {
|
|
24
15
|
case 'dir': {
|
|
25
|
-
if (encryptedKey !== undefined)
|
|
16
|
+
if (encryptedKey !== undefined)
|
|
26
17
|
throw new JWEInvalid('Encountered unexpected JWE Encrypted Key');
|
|
27
|
-
}
|
|
28
18
|
return key;
|
|
29
19
|
}
|
|
30
20
|
case 'ECDH-ES':
|
|
31
|
-
if (encryptedKey !== undefined)
|
|
21
|
+
if (encryptedKey !== undefined)
|
|
32
22
|
throw new JWEInvalid('Encountered unexpected JWE Encrypted Key');
|
|
33
|
-
}
|
|
34
23
|
case 'ECDH-ES+A128KW':
|
|
35
24
|
case 'ECDH-ES+A192KW':
|
|
36
25
|
case 'ECDH-ES+A256KW': {
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
if (!isObject(joseHeader.epk))
|
|
27
|
+
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
28
|
+
if (!ECDH.ecdhAllowed(key))
|
|
39
29
|
throw new JOSENotSupported('ECDH-ES with the provided key is not allowed or not supported by your javascript runtime');
|
|
40
|
-
}
|
|
41
30
|
const epk = await importJWK(joseHeader.epk, alg);
|
|
42
31
|
let partyUInfo;
|
|
43
32
|
let partyVInfo;
|
|
44
|
-
if (joseHeader.apu !== undefined)
|
|
33
|
+
if (joseHeader.apu !== undefined) {
|
|
34
|
+
if (typeof joseHeader.apu !== 'string')
|
|
35
|
+
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
45
36
|
partyUInfo = base64url(joseHeader.apu);
|
|
46
|
-
|
|
37
|
+
}
|
|
38
|
+
if (joseHeader.apv !== undefined) {
|
|
39
|
+
if (typeof joseHeader.apv !== 'string')
|
|
40
|
+
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
47
41
|
partyVInfo = base64url(joseHeader.apv);
|
|
42
|
+
}
|
|
48
43
|
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLengths.get(joseHeader.enc), partyUInfo, partyVInfo);
|
|
49
|
-
if (alg === 'ECDH-ES')
|
|
44
|
+
if (alg === 'ECDH-ES')
|
|
50
45
|
return sharedSecret;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return aesKw(kwAlg, sharedSecret, encryptedKey);
|
|
46
|
+
if (encryptedKey === undefined)
|
|
47
|
+
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
48
|
+
return aesKw(alg.substr(-6), sharedSecret, encryptedKey);
|
|
55
49
|
}
|
|
56
50
|
case 'RSA1_5':
|
|
57
51
|
case 'RSA-OAEP':
|
|
58
52
|
case 'RSA-OAEP-256':
|
|
59
53
|
case 'RSA-OAEP-384':
|
|
60
54
|
case 'RSA-OAEP-512': {
|
|
61
|
-
|
|
55
|
+
if (encryptedKey === undefined)
|
|
56
|
+
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
62
57
|
return rsaEs(alg, key, encryptedKey);
|
|
63
58
|
}
|
|
64
59
|
case 'PBES2-HS256+A128KW':
|
|
65
60
|
case 'PBES2-HS384+A192KW':
|
|
66
61
|
case 'PBES2-HS512+A256KW': {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
if (encryptedKey === undefined)
|
|
63
|
+
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
64
|
+
if (typeof joseHeader.p2c !== 'number')
|
|
65
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
66
|
+
if (typeof joseHeader.p2s !== 'string')
|
|
67
|
+
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
68
|
+
return pbes2Kw(alg, key, encryptedKey, joseHeader.p2c, base64url(joseHeader.p2s));
|
|
73
69
|
}
|
|
74
70
|
case 'A128KW':
|
|
75
71
|
case 'A192KW':
|
|
76
72
|
case 'A256KW': {
|
|
77
|
-
|
|
73
|
+
if (encryptedKey === undefined)
|
|
74
|
+
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
78
75
|
return aesKw(alg, key, encryptedKey);
|
|
79
76
|
}
|
|
80
77
|
case 'A128GCMKW':
|
|
81
78
|
case 'A192GCMKW':
|
|
82
79
|
case 'A256GCMKW': {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
if (encryptedKey === undefined)
|
|
81
|
+
throw new JWEInvalid('JWE Encrypted Key missing');
|
|
82
|
+
if (typeof joseHeader.iv !== 'string')
|
|
83
|
+
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
84
|
+
if (typeof joseHeader.tag !== 'string')
|
|
85
|
+
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
86
86
|
const iv = base64url(joseHeader.iv);
|
|
87
87
|
const tag = base64url(joseHeader.tag);
|
|
88
88
|
return aesGcmKw(alg, key, encryptedKey, iv, tag);
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import random from '../runtime/random.js';
|
|
2
1
|
import { wrap as aesKw } from '../runtime/aeskw.js';
|
|
3
2
|
import * as ECDH from '../runtime/ecdhes.js';
|
|
4
3
|
import { encrypt as pbes2Kw } from '../runtime/pbes2kw.js';
|
|
5
4
|
import { encrypt as rsaEs } from '../runtime/rsaes.js';
|
|
6
5
|
import { wrap as aesGcmKw } from '../runtime/aesgcmkw.js';
|
|
7
6
|
import { encode as base64url } from '../runtime/base64url.js';
|
|
8
|
-
import
|
|
7
|
+
import generateCek, { bitLengths as cekLengths } from '../lib/cek.js';
|
|
9
8
|
import { JOSENotSupported } from '../util/errors.js';
|
|
10
|
-
import {
|
|
9
|
+
import { exportJWK } from '../key/export.js';
|
|
11
10
|
import checkKeyType from './check_key_type.js';
|
|
12
|
-
const generateCek = cekFactory(random);
|
|
13
11
|
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
14
12
|
let encryptedKey;
|
|
15
13
|
let parameters;
|
|
@@ -30,7 +28,7 @@ async function encryptKeyManagement(alg, enc, key, providedCek, providedParamete
|
|
|
30
28
|
const { apu, apv } = providedParameters;
|
|
31
29
|
let { epk: ephemeralKey } = providedParameters;
|
|
32
30
|
ephemeralKey || (ephemeralKey = await ECDH.generateEpk(key));
|
|
33
|
-
const { x, y, crv, kty } = await
|
|
31
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
34
32
|
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLengths.get(enc), apu, apv);
|
|
35
33
|
parameters = { epk: { x, y, crv, kty } };
|
|
36
34
|
if (apu)
|
package/dist/node/esm/lib/iv.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JOSENotSupported } from '../util/errors.js';
|
|
2
|
+
import random from '../runtime/random.js';
|
|
2
3
|
const bitLengths = new Map([
|
|
3
4
|
['A128CBC-HS256', 128],
|
|
4
5
|
['A128GCM', 96],
|
|
@@ -10,12 +11,12 @@ const bitLengths = new Map([
|
|
|
10
11
|
['A256GCM', 96],
|
|
11
12
|
['A256GCMKW', 96],
|
|
12
13
|
]);
|
|
13
|
-
const
|
|
14
|
+
const generateIv = (alg) => {
|
|
14
15
|
const bitLength = bitLengths.get(alg);
|
|
15
16
|
if (!bitLength) {
|
|
16
17
|
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
17
18
|
}
|
|
18
19
|
return random(new Uint8Array(bitLength >> 3));
|
|
19
20
|
};
|
|
20
|
-
export default
|
|
21
|
+
export default generateIv;
|
|
21
22
|
export { bitLengths };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import encrypt from './encrypt.js';
|
|
2
2
|
import decrypt from './decrypt.js';
|
|
3
|
-
import
|
|
4
|
-
import random from './random.js';
|
|
3
|
+
import generateIv from '../lib/iv.js';
|
|
5
4
|
import { encode as base64url } from './base64url.js';
|
|
6
|
-
const generateIv = ivFactory(random);
|
|
7
5
|
export const wrap = async (alg, key, cek, iv) => {
|
|
8
6
|
const jweAlgorithm = alg.substr(0, 7);
|
|
9
7
|
iv || (iv = generateIv(jweAlgorithm));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { get as http } from 'http';
|
|
2
2
|
import { get as https } from 'https';
|
|
3
3
|
import { once } from 'events';
|
|
4
|
-
import { JOSEError } from '../util/errors.js';
|
|
4
|
+
import { JOSEError, JWKSTimeout } from '../util/errors.js';
|
|
5
5
|
import { concat, decoder } from '../lib/buffer_utils.js';
|
|
6
6
|
const protocols = {
|
|
7
7
|
'https:': https,
|
|
@@ -16,7 +16,11 @@ const fetchJwks = async (url, timeout, options) => {
|
|
|
16
16
|
agent,
|
|
17
17
|
timeout,
|
|
18
18
|
});
|
|
19
|
-
const [response] = await once(req, 'response');
|
|
19
|
+
const [response] = (await Promise.race([once(req, 'response'), once(req, 'timeout')]));
|
|
20
|
+
if (!response) {
|
|
21
|
+
req.destroy();
|
|
22
|
+
throw new JWKSTimeout();
|
|
23
|
+
}
|
|
20
24
|
if (response.statusCode !== 200) {
|
|
21
25
|
throw new JOSEError('Expected 200 OK from the JSON Web Key Set HTTP response');
|
|
22
26
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isCryptoKey } from './webcrypto.js';
|
|
2
|
+
import isKeyObject from './is_key_object.js';
|
|
3
|
+
export default (key) => isKeyObject(key) || isCryptoKey(key);
|
|
4
|
+
const types = ['KeyObject'];
|
|
5
|
+
if (parseInt(process.versions.node) >= 16) {
|
|
6
|
+
types.push('CryptoKey');
|
|
7
|
+
}
|
|
8
|
+
export { types };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default randomFillSync;
|
|
1
|
+
export { randomFillSync as default } from 'crypto';
|
|
@@ -1,108 +1,147 @@
|
|
|
1
1
|
export class JOSEError extends Error {
|
|
2
2
|
constructor(message) {
|
|
3
|
+
var _a;
|
|
3
4
|
super(message);
|
|
4
|
-
this.code =
|
|
5
|
+
this.code = 'ERR_JOSE_GENERIC';
|
|
5
6
|
this.name = this.constructor.name;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
8
|
+
}
|
|
9
|
+
static get code() {
|
|
10
|
+
return 'ERR_JOSE_GENERIC';
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
JOSEError.code = 'ERR_JOSE_GENERIC';
|
|
12
13
|
export class JWTClaimValidationFailed extends JOSEError {
|
|
13
14
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
14
15
|
super(message);
|
|
15
|
-
this.code =
|
|
16
|
+
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
16
17
|
this.claim = claim;
|
|
17
18
|
this.reason = reason;
|
|
18
19
|
}
|
|
20
|
+
static get code() {
|
|
21
|
+
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class JWTExpired extends JOSEError {
|
|
25
|
+
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = 'ERR_JWT_EXPIRED';
|
|
28
|
+
this.claim = claim;
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
}
|
|
31
|
+
static get code() {
|
|
32
|
+
return 'ERR_JWT_EXPIRED';
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
|
-
JWTClaimValidationFailed.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
21
35
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
22
36
|
constructor() {
|
|
23
37
|
super(...arguments);
|
|
24
|
-
this.code =
|
|
38
|
+
this.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
39
|
+
}
|
|
40
|
+
static get code() {
|
|
41
|
+
return 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
25
42
|
}
|
|
26
43
|
}
|
|
27
|
-
JOSEAlgNotAllowed.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
28
44
|
export class JOSENotSupported extends JOSEError {
|
|
29
45
|
constructor() {
|
|
30
46
|
super(...arguments);
|
|
31
|
-
this.code =
|
|
47
|
+
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
48
|
+
}
|
|
49
|
+
static get code() {
|
|
50
|
+
return 'ERR_JOSE_NOT_SUPPORTED';
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
|
-
JOSENotSupported.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
35
53
|
export class JWEDecryptionFailed extends JOSEError {
|
|
36
54
|
constructor() {
|
|
37
55
|
super(...arguments);
|
|
38
|
-
this.code =
|
|
56
|
+
this.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
39
57
|
this.message = 'decryption operation failed';
|
|
40
58
|
}
|
|
59
|
+
static get code() {
|
|
60
|
+
return 'ERR_JWE_DECRYPTION_FAILED';
|
|
61
|
+
}
|
|
41
62
|
}
|
|
42
|
-
JWEDecryptionFailed.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
43
63
|
export class JWEInvalid extends JOSEError {
|
|
44
64
|
constructor() {
|
|
45
65
|
super(...arguments);
|
|
46
|
-
this.code =
|
|
66
|
+
this.code = 'ERR_JWE_INVALID';
|
|
67
|
+
}
|
|
68
|
+
static get code() {
|
|
69
|
+
return 'ERR_JWE_INVALID';
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
|
-
JWEInvalid.code = 'ERR_JWE_INVALID';
|
|
50
72
|
export class JWSInvalid extends JOSEError {
|
|
51
73
|
constructor() {
|
|
52
74
|
super(...arguments);
|
|
53
|
-
this.code =
|
|
75
|
+
this.code = 'ERR_JWS_INVALID';
|
|
76
|
+
}
|
|
77
|
+
static get code() {
|
|
78
|
+
return 'ERR_JWS_INVALID';
|
|
54
79
|
}
|
|
55
80
|
}
|
|
56
|
-
JWSInvalid.code = 'ERR_JWS_INVALID';
|
|
57
81
|
export class JWTInvalid extends JOSEError {
|
|
58
82
|
constructor() {
|
|
59
83
|
super(...arguments);
|
|
60
|
-
this.code =
|
|
84
|
+
this.code = 'ERR_JWT_INVALID';
|
|
85
|
+
}
|
|
86
|
+
static get code() {
|
|
87
|
+
return 'ERR_JWT_INVALID';
|
|
61
88
|
}
|
|
62
89
|
}
|
|
63
|
-
JWTInvalid.code = 'ERR_JWT_INVALID';
|
|
64
90
|
export class JWKInvalid extends JOSEError {
|
|
65
91
|
constructor() {
|
|
66
92
|
super(...arguments);
|
|
67
|
-
this.code =
|
|
93
|
+
this.code = 'ERR_JWK_INVALID';
|
|
94
|
+
}
|
|
95
|
+
static get code() {
|
|
96
|
+
return 'ERR_JWK_INVALID';
|
|
68
97
|
}
|
|
69
98
|
}
|
|
70
|
-
JWKInvalid.code = 'ERR_JWK_INVALID';
|
|
71
99
|
export class JWKSInvalid extends JOSEError {
|
|
72
100
|
constructor() {
|
|
73
101
|
super(...arguments);
|
|
74
|
-
this.code =
|
|
102
|
+
this.code = 'ERR_JWKS_INVALID';
|
|
103
|
+
}
|
|
104
|
+
static get code() {
|
|
105
|
+
return 'ERR_JWKS_INVALID';
|
|
75
106
|
}
|
|
76
107
|
}
|
|
77
|
-
JWKSInvalid.code = 'ERR_JWKS_INVALID';
|
|
78
108
|
export class JWKSNoMatchingKey extends JOSEError {
|
|
79
109
|
constructor() {
|
|
80
110
|
super(...arguments);
|
|
81
|
-
this.code =
|
|
111
|
+
this.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
82
112
|
this.message = 'no applicable key found in the JSON Web Key Set';
|
|
83
113
|
}
|
|
114
|
+
static get code() {
|
|
115
|
+
return 'ERR_JWKS_NO_MATCHING_KEY';
|
|
116
|
+
}
|
|
84
117
|
}
|
|
85
|
-
JWKSNoMatchingKey.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
86
118
|
export class JWKSMultipleMatchingKeys extends JOSEError {
|
|
87
119
|
constructor() {
|
|
88
120
|
super(...arguments);
|
|
89
|
-
this.code =
|
|
121
|
+
this.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
90
122
|
this.message = 'multiple matching keys found in the JSON Web Key Set';
|
|
91
123
|
}
|
|
124
|
+
static get code() {
|
|
125
|
+
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
126
|
+
}
|
|
92
127
|
}
|
|
93
|
-
|
|
94
|
-
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
128
|
+
export class JWKSTimeout extends JOSEError {
|
|
95
129
|
constructor() {
|
|
96
130
|
super(...arguments);
|
|
97
|
-
this.code =
|
|
98
|
-
this.message = '
|
|
131
|
+
this.code = 'ERR_JWKS_TIMEOUT';
|
|
132
|
+
this.message = 'request timed out';
|
|
133
|
+
}
|
|
134
|
+
static get code() {
|
|
135
|
+
return 'ERR_JWKS_TIMEOUT';
|
|
99
136
|
}
|
|
100
137
|
}
|
|
101
|
-
JWSSignatureVerificationFailed
|
|
102
|
-
export class JWTExpired extends JWTClaimValidationFailed {
|
|
138
|
+
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
103
139
|
constructor() {
|
|
104
140
|
super(...arguments);
|
|
105
|
-
this.code =
|
|
141
|
+
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
142
|
+
this.message = 'signature verification failed';
|
|
143
|
+
}
|
|
144
|
+
static get code() {
|
|
145
|
+
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
106
146
|
}
|
|
107
147
|
}
|
|
108
|
-
JWTExpired.code = 'ERR_JWT_EXPIRED';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, CompactDecryptResult, ResolvedKey } from '../../types';
|
|
2
2
|
export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
|
|
3
3
|
}
|
|
4
|
-
declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike, options?: DecryptOptions): Promise<CompactDecryptResult>;
|
|
4
|
+
declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike | Uint8Array, options?: DecryptOptions): Promise<CompactDecryptResult>;
|
|
5
5
|
declare function compactDecrypt(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey>;
|
|
6
6
|
export { compactDecrypt };
|
|
7
7
|
export default compactDecrypt;
|
|
@@ -6,7 +6,7 @@ declare class CompactEncrypt {
|
|
|
6
6
|
setInitializationVector(iv: Uint8Array): this;
|
|
7
7
|
setProtectedHeader(protectedHeader: JWEHeaderParameters): this;
|
|
8
8
|
setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
|
|
9
|
-
encrypt(key: KeyLike, options?: EncryptOptions): Promise<string>;
|
|
9
|
+
encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>;
|
|
10
10
|
}
|
|
11
11
|
export { CompactEncrypt };
|
|
12
12
|
export default CompactEncrypt;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FlattenedDecryptResult, KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, GetKeyFunction, ResolvedKey } from '../../types';
|
|
2
2
|
export interface FlattenedDecryptGetKey extends GetKeyFunction<JWEHeaderParameters | undefined, FlattenedJWE> {
|
|
3
3
|
}
|
|
4
|
-
declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike, options?: DecryptOptions): Promise<FlattenedDecryptResult>;
|
|
4
|
+
declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike | Uint8Array, options?: DecryptOptions): Promise<FlattenedDecryptResult>;
|
|
5
5
|
declare function flattenedDecrypt(jwe: FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult & ResolvedKey>;
|
|
6
6
|
export { flattenedDecrypt };
|
|
7
7
|
export default flattenedDecrypt;
|
|
@@ -16,7 +16,7 @@ declare class FlattenedEncrypt {
|
|
|
16
16
|
setAdditionalAuthenticatedData(aad: Uint8Array): this;
|
|
17
17
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
18
18
|
setInitializationVector(iv: Uint8Array): this;
|
|
19
|
-
encrypt(key: KeyLike, options?: EncryptOptions): Promise<FlattenedJWE>;
|
|
19
|
+
encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<FlattenedJWE>;
|
|
20
20
|
}
|
|
21
21
|
export { FlattenedEncrypt };
|
|
22
22
|
export default FlattenedEncrypt;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult, ResolvedKey } from '../../types';
|
|
2
2
|
export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
|
|
3
3
|
}
|
|
4
|
-
declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike, options?: DecryptOptions): Promise<GeneralDecryptResult>;
|
|
4
|
+
declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | Uint8Array, options?: DecryptOptions): Promise<GeneralDecryptResult>;
|
|
5
5
|
declare function generalDecrypt(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey>;
|
|
6
6
|
export { generalDecrypt };
|
|
7
7
|
export default generalDecrypt;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<CryptoKey | KeyObject>;
|
|
1
|
+
import type { FlattenedJWSInput, JWSHeaderParameters } from '../types';
|
|
2
|
+
declare function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<import("../types.d").KeyLike>;
|
|
4
3
|
export { EmbeddedJWK };
|
|
5
4
|
export default EmbeddedJWK;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JWK, KeyLike } from '../types';
|
|
2
|
-
declare function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike>;
|
|
2
|
+
declare function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike | Uint8Array>;
|
|
3
3
|
export { parseJwk };
|
|
4
4
|
export default parseJwk;
|
|
5
5
|
export type { KeyLike, JWK };
|
|
@@ -3,7 +3,7 @@ declare class CompactSign {
|
|
|
3
3
|
private _flattened;
|
|
4
4
|
constructor(payload: Uint8Array);
|
|
5
5
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
|
|
6
|
-
sign(key: KeyLike, options?: SignOptions): Promise<string>;
|
|
6
|
+
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
7
|
}
|
|
8
8
|
export { CompactSign };
|
|
9
9
|
export default CompactSign;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
|
|
2
2
|
export interface CompactVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
|
|
3
3
|
}
|
|
4
|
-
declare function compactVerify(jws: string | Uint8Array, key: KeyLike, options?: VerifyOptions): Promise<CompactVerifyResult>;
|
|
4
|
+
declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
|
|
5
5
|
declare function compactVerify(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey>;
|
|
6
6
|
export { compactVerify };
|
|
7
7
|
export default compactVerify;
|
|
@@ -6,7 +6,7 @@ declare class FlattenedSign {
|
|
|
6
6
|
constructor(payload: Uint8Array);
|
|
7
7
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
|
|
8
8
|
setUnprotectedHeader(unprotectedHeader: JWSHeaderParameters): this;
|
|
9
|
-
sign(key: KeyLike, options?: SignOptions): Promise<FlattenedJWS>;
|
|
9
|
+
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<FlattenedJWS>;
|
|
10
10
|
}
|
|
11
11
|
export { FlattenedSign };
|
|
12
12
|
export default FlattenedSign;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction, ResolvedKey } from '../../types';
|
|
2
2
|
export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
|
|
3
3
|
}
|
|
4
|
-
declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
|
|
4
|
+
declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
|
|
5
5
|
declare function flattenedVerify(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey>;
|
|
6
6
|
export { flattenedVerify };
|
|
7
7
|
export default flattenedVerify;
|
|
@@ -7,7 +7,7 @@ declare class GeneralSign {
|
|
|
7
7
|
private _payload;
|
|
8
8
|
private _signatures;
|
|
9
9
|
constructor(payload: Uint8Array);
|
|
10
|
-
addSignature(key: KeyLike, options?: SignOptions): Signature;
|
|
10
|
+
addSignature(key: KeyLike | Uint8Array, options?: SignOptions): Signature;
|
|
11
11
|
sign(): Promise<GeneralJWS>;
|
|
12
12
|
}
|
|
13
13
|
export { GeneralSign };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
|
|
2
2
|
export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
|
|
3
3
|
}
|
|
4
|
-
declare function generalVerify(jws: GeneralJWSInput, key: KeyLike, options?: VerifyOptions): Promise<GeneralVerifyResult>;
|
|
4
|
+
declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<GeneralVerifyResult>;
|
|
5
5
|
declare function generalVerify(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey>;
|
|
6
6
|
export { generalVerify };
|
|
7
7
|
export default generalVerify;
|
|
@@ -3,7 +3,7 @@ interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions
|
|
|
3
3
|
}
|
|
4
4
|
export interface JWTDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
|
|
5
5
|
}
|
|
6
|
-
declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
|
|
6
|
+
declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
|
|
7
7
|
declare function jwtDecrypt(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey>;
|
|
8
8
|
export { jwtDecrypt };
|
|
9
9
|
export default jwtDecrypt;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EncryptOptions, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWTPayload, KeyLike } from '../types';
|
|
2
|
-
import ProduceJWT from '
|
|
2
|
+
import { ProduceJWT } from './produce';
|
|
3
3
|
declare class EncryptJWT extends ProduceJWT {
|
|
4
4
|
private _cek;
|
|
5
5
|
private _iv;
|
|
@@ -15,7 +15,7 @@ declare class EncryptJWT extends ProduceJWT {
|
|
|
15
15
|
replicateIssuerAsHeader(): this;
|
|
16
16
|
replicateSubjectAsHeader(): this;
|
|
17
17
|
replicateAudienceAsHeader(): this;
|
|
18
|
-
encrypt(key: KeyLike, options?: EncryptOptions): Promise<string>;
|
|
18
|
+
encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>;
|
|
19
19
|
}
|
|
20
20
|
export { EncryptJWT };
|
|
21
21
|
export default EncryptJWT;
|
package/dist/types/jwt/sign.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { JWSHeaderParameters, JWTPayload, KeyLike, SignOptions } from '../types';
|
|
2
|
-
import ProduceJWT from '
|
|
2
|
+
import { ProduceJWT } from './produce';
|
|
3
3
|
declare class SignJWT extends ProduceJWT {
|
|
4
4
|
private _protectedHeader;
|
|
5
5
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
|
|
6
|
-
sign(key: KeyLike, options?: SignOptions): Promise<string>;
|
|
6
|
+
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
7
|
}
|
|
8
8
|
export { SignJWT };
|
|
9
9
|
export default SignJWT;
|
|
@@ -3,7 +3,7 @@ interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
|
|
|
3
3
|
}
|
|
4
4
|
export interface JWTVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
|
|
5
5
|
}
|
|
6
|
-
declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
|
|
6
|
+
declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
|
|
7
7
|
declare function jwtVerify(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey>;
|
|
8
8
|
export { jwtVerify };
|
|
9
9
|
export default jwtVerify;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JWK, KeyLike } from '../types';
|
|
2
|
-
export declare function exportSPKI(key:
|
|
3
|
-
export declare function exportPKCS8(key:
|
|
4
|
-
export declare function exportJWK(key: KeyLike): Promise<JWK>;
|
|
2
|
+
export declare function exportSPKI(key: KeyLike): Promise<string>;
|
|
3
|
+
export declare function exportPKCS8(key: KeyLike): Promise<string>;
|
|
4
|
+
export declare function exportJWK(key: KeyLike | Uint8Array): Promise<JWK>;
|
|
5
5
|
export type { KeyLike, JWK };
|
|
@@ -2,8 +2,8 @@ import type { JWK, KeyLike } from '../types';
|
|
|
2
2
|
export interface PEMImportOptions {
|
|
3
3
|
extractable?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<
|
|
6
|
-
export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<
|
|
7
|
-
export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<
|
|
8
|
-
export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike>;
|
|
5
|
+
export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
6
|
+
export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
7
|
+
export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
|
|
8
|
+
export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike | Uint8Array>;
|
|
9
9
|
export type { KeyLike, JWK };
|