jose 4.15.4 → 5.0.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 +2 -1
- package/dist/browser/index.js +2 -4
- package/dist/browser/jwe/flattened/decrypt.js +13 -22
- package/dist/browser/jwe/flattened/encrypt.js +3 -18
- package/dist/browser/jwe/general/decrypt.js +1 -1
- package/dist/browser/jwe/general/encrypt.js +8 -13
- package/dist/browser/jwk/embedded.js +2 -2
- package/dist/browser/jwk/thumbprint.js +2 -2
- package/dist/browser/jwks/local.js +2 -2
- package/dist/browser/jwks/remote.js +4 -4
- package/dist/browser/jws/flattened/sign.js +1 -1
- package/dist/browser/jws/flattened/verify.js +6 -7
- package/dist/browser/jws/general/verify.js +1 -1
- package/dist/browser/jwt/produce.js +19 -4
- package/dist/browser/jwt/sign.js +1 -2
- package/dist/browser/jwt/unsecured.js +1 -1
- package/dist/browser/jwt/verify.js +1 -2
- package/dist/browser/key/import.js +1 -6
- package/dist/browser/lib/decrypt_key_management.js +6 -6
- package/dist/browser/lib/jwt_claims_set.js +1 -1
- package/dist/browser/runtime/asn1.js +1 -2
- package/dist/browser/runtime/base64url.js +1 -1
- package/dist/browser/runtime/decrypt.js +3 -3
- package/dist/browser/runtime/fetch_jwks.js +1 -1
- package/dist/browser/runtime/generate.js +5 -8
- package/dist/browser/runtime/jwk_to_key.js +2 -45
- package/dist/browser/runtime/verify.js +1 -1
- package/dist/browser/util/decode_jwt.js +2 -2
- package/dist/browser/util/decode_protected_header.js +1 -1
- package/dist/browser/util/errors.js +1 -2
- package/dist/node/cjs/jwe/compact/encrypt.js +1 -0
- package/dist/node/cjs/jwe/flattened/decrypt.js +7 -16
- package/dist/node/cjs/jwe/flattened/encrypt.js +12 -19
- package/dist/node/cjs/jwe/general/encrypt.js +16 -13
- package/dist/node/cjs/jwk/embedded.js +2 -2
- package/dist/node/cjs/jwk/thumbprint.js +2 -2
- package/dist/node/cjs/jwks/local.js +3 -2
- package/dist/node/cjs/jwks/remote.js +13 -6
- package/dist/node/cjs/jws/compact/sign.js +1 -0
- package/dist/node/cjs/jws/flattened/sign.js +4 -1
- package/dist/node/cjs/jws/flattened/verify.js +3 -4
- package/dist/node/cjs/jws/general/sign.js +7 -1
- package/dist/node/cjs/jwt/encrypt.js +7 -0
- package/dist/node/cjs/jwt/produce.js +20 -4
- package/dist/node/cjs/jwt/sign.js +2 -2
- package/dist/node/cjs/jwt/verify.js +1 -2
- package/dist/node/cjs/key/import.js +2 -7
- package/dist/node/cjs/lib/aesgcmkw.js +1 -1
- package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
- package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
- package/dist/node/cjs/runtime/aeskw.js +6 -6
- package/dist/node/cjs/runtime/asn1.js +8 -8
- package/dist/node/cjs/runtime/base64url.js +6 -11
- package/dist/node/cjs/runtime/cbc_tag.js +2 -2
- package/dist/node/cjs/runtime/check_key_length.js +8 -0
- package/dist/node/cjs/runtime/ciphers.js +2 -2
- package/dist/node/cjs/runtime/decrypt.js +4 -4
- package/dist/node/cjs/runtime/digest.js +2 -2
- package/dist/node/cjs/runtime/ecdhes.js +7 -7
- package/dist/node/cjs/runtime/encrypt.js +4 -4
- package/dist/node/cjs/runtime/fetch_jwks.js +4 -4
- package/dist/node/cjs/runtime/generate.js +7 -11
- package/dist/node/cjs/runtime/get_named_curve.js +7 -45
- package/dist/node/cjs/runtime/get_sign_verify_key.js +4 -4
- package/dist/node/cjs/runtime/is_key_like.js +1 -1
- package/dist/node/cjs/runtime/is_key_object.js +2 -5
- package/dist/node/cjs/runtime/jwk_to_key.js +2 -113
- package/dist/node/cjs/runtime/key_to_jwk.js +6 -130
- package/dist/node/cjs/runtime/node_key.js +9 -18
- package/dist/node/cjs/runtime/pbes2kw.js +4 -4
- package/dist/node/cjs/runtime/random.js +2 -2
- package/dist/node/cjs/runtime/rsaes.js +8 -8
- package/dist/node/cjs/runtime/sign.js +3 -9
- package/dist/node/cjs/runtime/timing_safe_equal.js +2 -2
- package/dist/node/cjs/runtime/verify.js +3 -10
- package/dist/node/cjs/runtime/webcrypto.js +4 -6
- package/dist/node/cjs/util/errors.js +26 -59
- package/dist/node/esm/jwe/compact/encrypt.js +1 -0
- package/dist/node/esm/jwe/flattened/decrypt.js +7 -16
- package/dist/node/esm/jwe/flattened/encrypt.js +12 -19
- package/dist/node/esm/jwe/general/encrypt.js +17 -14
- package/dist/node/esm/jwk/embedded.js +2 -2
- package/dist/node/esm/jwk/thumbprint.js +2 -2
- package/dist/node/esm/jwks/local.js +3 -2
- package/dist/node/esm/jwks/remote.js +13 -6
- package/dist/node/esm/jws/compact/sign.js +1 -0
- package/dist/node/esm/jws/flattened/sign.js +4 -1
- package/dist/node/esm/jws/flattened/verify.js +3 -4
- package/dist/node/esm/jws/general/sign.js +7 -1
- package/dist/node/esm/jwt/encrypt.js +7 -0
- package/dist/node/esm/jwt/produce.js +20 -4
- package/dist/node/esm/jwt/sign.js +2 -2
- package/dist/node/esm/jwt/verify.js +1 -2
- package/dist/node/esm/key/import.js +2 -7
- package/dist/node/esm/lib/aesgcmkw.js +1 -1
- package/dist/node/esm/lib/decrypt_key_management.js +1 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -1
- package/dist/node/esm/runtime/aeskw.js +2 -2
- package/dist/node/esm/runtime/asn1.js +2 -2
- package/dist/node/esm/runtime/base64url.js +4 -10
- package/dist/node/esm/runtime/cbc_tag.js +1 -1
- package/dist/node/esm/runtime/check_key_length.js +6 -0
- package/dist/node/esm/runtime/ciphers.js +2 -2
- package/dist/node/esm/runtime/decrypt.js +1 -1
- package/dist/node/esm/runtime/digest.js +1 -1
- package/dist/node/esm/runtime/ecdhes.js +2 -2
- package/dist/node/esm/runtime/encrypt.js +1 -1
- package/dist/node/esm/runtime/fetch_jwks.js +3 -3
- package/dist/node/esm/runtime/generate.js +5 -9
- package/dist/node/esm/runtime/get_named_curve.js +5 -42
- package/dist/node/esm/runtime/get_sign_verify_key.js +1 -1
- package/dist/node/esm/runtime/is_key_like.js +1 -1
- package/dist/node/esm/runtime/is_key_object.js +2 -5
- package/dist/node/esm/runtime/jwk_to_key.js +2 -113
- package/dist/node/esm/runtime/key_to_jwk.js +5 -129
- package/dist/node/esm/runtime/node_key.js +7 -16
- package/dist/node/esm/runtime/pbes2kw.js +2 -2
- package/dist/node/esm/runtime/random.js +1 -1
- package/dist/node/esm/runtime/rsaes.js +3 -3
- package/dist/node/esm/runtime/sign.js +3 -9
- package/dist/node/esm/runtime/timing_safe_equal.js +1 -1
- package/dist/node/esm/runtime/verify.js +3 -10
- package/dist/node/esm/runtime/webcrypto.js +3 -6
- package/dist/node/esm/util/errors.js +26 -59
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jwe/compact/decrypt.d.ts +1 -1
- package/dist/types/jwe/flattened/decrypt.d.ts +1 -1
- package/dist/types/jwe/general/decrypt.d.ts +1 -1
- package/dist/types/jwe/general/encrypt.d.ts +3 -7
- package/dist/types/jwk/embedded.d.ts +1 -1
- package/dist/types/jwks/local.d.ts +3 -3
- package/dist/types/jwks/remote.d.ts +1 -1
- package/dist/types/jws/compact/verify.d.ts +1 -1
- package/dist/types/jws/flattened/verify.d.ts +1 -1
- package/dist/types/jws/general/verify.d.ts +1 -1
- package/dist/types/jwt/decrypt.d.ts +3 -3
- package/dist/types/jwt/produce.d.ts +12 -12
- package/dist/types/jwt/unsecured.d.ts +3 -3
- package/dist/types/jwt/verify.d.ts +3 -3
- package/dist/types/key/generate_key_pair.d.ts +7 -5
- package/dist/types/key/generate_secret.d.ts +1 -1
- package/dist/types/key/import.d.ts +4 -6
- package/dist/types/types.d.ts +13 -50
- package/package.json +1 -1
- package/dist/browser/runtime/zlib.js +0 -7
- package/dist/node/cjs/runtime/asn1_sequence_decoder.js +0 -47
- package/dist/node/cjs/runtime/asn1_sequence_encoder.js +0 -91
- package/dist/node/cjs/runtime/check_modulus_length.js +0 -52
- package/dist/node/cjs/runtime/flags.js +0 -8
- package/dist/node/cjs/runtime/zlib.js +0 -11
- package/dist/node/esm/runtime/asn1_sequence_decoder.js +0 -44
- package/dist/node/esm/runtime/asn1_sequence_encoder.js +0 -88
- package/dist/node/esm/runtime/check_modulus_length.js +0 -48
- package/dist/node/esm/runtime/flags.js +0 -5
- package/dist/node/esm/runtime/zlib.js +0 -6
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { KeyObject
|
|
1
|
+
import { KeyObject } from 'node:crypto';
|
|
2
2
|
import { encode as base64url } from './base64url.js';
|
|
3
|
-
import Asn1SequenceDecoder from './asn1_sequence_decoder.js';
|
|
4
3
|
import { JOSENotSupported } from '../util/errors.js';
|
|
5
|
-
import getNamedCurve from './get_named_curve.js';
|
|
6
4
|
import { isCryptoKey } from './webcrypto.js';
|
|
7
5
|
import isKeyObject from './is_key_object.js';
|
|
8
6
|
import invalidKeyInput from '../lib/invalid_key_input.js';
|
|
9
7
|
import { types } from './is_key_like.js';
|
|
10
|
-
import { jwkExport } from './flags.js';
|
|
11
8
|
const keyToJWK = (key) => {
|
|
12
9
|
let keyObject;
|
|
13
10
|
if (isCryptoKey(key)) {
|
|
@@ -28,131 +25,10 @@ const keyToJWK = (key) => {
|
|
|
28
25
|
else {
|
|
29
26
|
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
30
27
|
}
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
throw new JOSENotSupported('Unsupported key asymmetricKeyType');
|
|
35
|
-
}
|
|
36
|
-
return keyObject.export({ format: 'jwk' });
|
|
37
|
-
}
|
|
38
|
-
switch (keyObject.type) {
|
|
39
|
-
case 'secret':
|
|
40
|
-
return {
|
|
41
|
-
kty: 'oct',
|
|
42
|
-
k: base64url(keyObject.export()),
|
|
43
|
-
};
|
|
44
|
-
case 'private':
|
|
45
|
-
case 'public': {
|
|
46
|
-
switch (keyObject.asymmetricKeyType) {
|
|
47
|
-
case 'rsa': {
|
|
48
|
-
const der = keyObject.export({ format: 'der', type: 'pkcs1' });
|
|
49
|
-
const dec = new Asn1SequenceDecoder(der);
|
|
50
|
-
if (keyObject.type === 'private') {
|
|
51
|
-
dec.unsignedInteger();
|
|
52
|
-
}
|
|
53
|
-
const n = base64url(dec.unsignedInteger());
|
|
54
|
-
const e = base64url(dec.unsignedInteger());
|
|
55
|
-
let jwk;
|
|
56
|
-
if (keyObject.type === 'private') {
|
|
57
|
-
jwk = {
|
|
58
|
-
d: base64url(dec.unsignedInteger()),
|
|
59
|
-
p: base64url(dec.unsignedInteger()),
|
|
60
|
-
q: base64url(dec.unsignedInteger()),
|
|
61
|
-
dp: base64url(dec.unsignedInteger()),
|
|
62
|
-
dq: base64url(dec.unsignedInteger()),
|
|
63
|
-
qi: base64url(dec.unsignedInteger()),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
dec.end();
|
|
67
|
-
return { kty: 'RSA', n, e, ...jwk };
|
|
68
|
-
}
|
|
69
|
-
case 'ec': {
|
|
70
|
-
const crv = getNamedCurve(keyObject);
|
|
71
|
-
let len;
|
|
72
|
-
let offset;
|
|
73
|
-
let correction;
|
|
74
|
-
switch (crv) {
|
|
75
|
-
case 'secp256k1':
|
|
76
|
-
len = 64;
|
|
77
|
-
offset = 31 + 2;
|
|
78
|
-
correction = -1;
|
|
79
|
-
break;
|
|
80
|
-
case 'P-256':
|
|
81
|
-
len = 64;
|
|
82
|
-
offset = 34 + 2;
|
|
83
|
-
correction = -1;
|
|
84
|
-
break;
|
|
85
|
-
case 'P-384':
|
|
86
|
-
len = 96;
|
|
87
|
-
offset = 33 + 2;
|
|
88
|
-
correction = -3;
|
|
89
|
-
break;
|
|
90
|
-
case 'P-521':
|
|
91
|
-
len = 132;
|
|
92
|
-
offset = 33 + 2;
|
|
93
|
-
correction = -3;
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
throw new JOSENotSupported('Unsupported curve');
|
|
97
|
-
}
|
|
98
|
-
if (keyObject.type === 'public') {
|
|
99
|
-
const der = keyObject.export({ type: 'spki', format: 'der' });
|
|
100
|
-
return {
|
|
101
|
-
kty: 'EC',
|
|
102
|
-
crv,
|
|
103
|
-
x: base64url(der.subarray(-len, -len / 2)),
|
|
104
|
-
y: base64url(der.subarray(-len / 2)),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
108
|
-
if (der.length < 100) {
|
|
109
|
-
offset += correction;
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
...keyToJWK(createPublicKey(keyObject)),
|
|
113
|
-
d: base64url(der.subarray(offset, offset + len / 2)),
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
case 'ed25519':
|
|
117
|
-
case 'x25519': {
|
|
118
|
-
const crv = getNamedCurve(keyObject);
|
|
119
|
-
if (keyObject.type === 'public') {
|
|
120
|
-
const der = keyObject.export({ type: 'spki', format: 'der' });
|
|
121
|
-
return {
|
|
122
|
-
kty: 'OKP',
|
|
123
|
-
crv,
|
|
124
|
-
x: base64url(der.subarray(-32)),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
128
|
-
return {
|
|
129
|
-
...keyToJWK(createPublicKey(keyObject)),
|
|
130
|
-
d: base64url(der.subarray(-32)),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
case 'ed448':
|
|
134
|
-
case 'x448': {
|
|
135
|
-
const crv = getNamedCurve(keyObject);
|
|
136
|
-
if (keyObject.type === 'public') {
|
|
137
|
-
const der = keyObject.export({ type: 'spki', format: 'der' });
|
|
138
|
-
return {
|
|
139
|
-
kty: 'OKP',
|
|
140
|
-
crv,
|
|
141
|
-
x: base64url(der.subarray(crv === 'Ed448' ? -57 : -56)),
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
const der = keyObject.export({ type: 'pkcs8', format: 'der' });
|
|
145
|
-
return {
|
|
146
|
-
...keyToJWK(createPublicKey(keyObject)),
|
|
147
|
-
d: base64url(der.subarray(crv === 'Ed448' ? -57 : -56)),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
default:
|
|
151
|
-
throw new JOSENotSupported('Unsupported key asymmetricKeyType');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
default:
|
|
155
|
-
throw new JOSENotSupported('Unsupported key type');
|
|
28
|
+
if (keyObject.type !== 'secret' &&
|
|
29
|
+
!['rsa', 'ec', 'ed25519', 'x25519', 'ed448', 'x448'].includes(keyObject.asymmetricKeyType)) {
|
|
30
|
+
throw new JOSENotSupported('Unsupported key asymmetricKeyType');
|
|
156
31
|
}
|
|
32
|
+
return keyObject.export({ format: 'jwk' });
|
|
157
33
|
};
|
|
158
34
|
export default keyToJWK;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { constants } from 'crypto';
|
|
1
|
+
import { constants } from 'node:crypto';
|
|
2
2
|
import getNamedCurve from './get_named_curve.js';
|
|
3
3
|
import { JOSENotSupported } from '../util/errors.js';
|
|
4
|
-
import
|
|
5
|
-
import { rsaPssParams } from './flags.js';
|
|
4
|
+
import checkKeyLength from './check_key_length.js';
|
|
6
5
|
const PSS = {
|
|
7
6
|
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
8
7
|
saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
|
|
@@ -26,11 +25,11 @@ export default function keyForCrypto(alg, key) {
|
|
|
26
25
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
27
26
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
checkKeyLength(key, alg);
|
|
30
29
|
return key;
|
|
31
|
-
case
|
|
32
|
-
case
|
|
33
|
-
case
|
|
30
|
+
case 'PS256':
|
|
31
|
+
case 'PS384':
|
|
32
|
+
case 'PS512':
|
|
34
33
|
if (key.asymmetricKeyType === 'rsa-pss') {
|
|
35
34
|
const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = key.asymmetricKeyDetails;
|
|
36
35
|
const length = parseInt(alg.slice(-3), 10);
|
|
@@ -45,15 +44,7 @@ export default function keyForCrypto(alg, key) {
|
|
|
45
44
|
else if (key.asymmetricKeyType !== 'rsa') {
|
|
46
45
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss');
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
return { key, ...PSS };
|
|
50
|
-
case !rsaPssParams && 'PS256':
|
|
51
|
-
case !rsaPssParams && 'PS384':
|
|
52
|
-
case !rsaPssParams && 'PS512':
|
|
53
|
-
if (key.asymmetricKeyType !== 'rsa') {
|
|
54
|
-
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
55
|
-
}
|
|
56
|
-
checkModulusLength(key, alg);
|
|
47
|
+
checkKeyLength(key, alg);
|
|
57
48
|
return { key, ...PSS };
|
|
58
49
|
case 'ES256':
|
|
59
50
|
case 'ES256K':
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { promisify } from 'util';
|
|
2
|
-
import { KeyObject, pbkdf2 as pbkdf2cb } from 'crypto';
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
|
+
import { KeyObject, pbkdf2 as pbkdf2cb } from 'node:crypto';
|
|
3
3
|
import random from './random.js';
|
|
4
4
|
import { p2s as concatSalt } from '../lib/buffer_utils.js';
|
|
5
5
|
import { encode as base64url } from './base64url.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { randomFillSync as default } from 'crypto';
|
|
1
|
+
export { randomFillSync as default } from 'node:crypto';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KeyObject, publicEncrypt, constants, privateDecrypt } from 'crypto';
|
|
2
|
-
import
|
|
1
|
+
import { KeyObject, publicEncrypt, constants, privateDecrypt } from 'node:crypto';
|
|
2
|
+
import checkKeyLength from './check_key_length.js';
|
|
3
3
|
import { isCryptoKey } from './webcrypto.js';
|
|
4
4
|
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
|
5
5
|
import isKeyObject from './is_key_object.js';
|
|
@@ -9,7 +9,7 @@ const checkKey = (key, alg) => {
|
|
|
9
9
|
if (key.asymmetricKeyType !== 'rsa') {
|
|
10
10
|
throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
checkKeyLength(key, alg);
|
|
13
13
|
};
|
|
14
14
|
const resolvePadding = (alg) => {
|
|
15
15
|
switch (alg) {
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import { promisify } from 'util';
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
3
|
import nodeDigest from './dsa_digest.js';
|
|
4
4
|
import hmacDigest from './hmac_digest.js';
|
|
5
5
|
import nodeKey from './node_key.js';
|
|
6
6
|
import getSignKey from './get_sign_verify_key.js';
|
|
7
|
-
|
|
8
|
-
if (crypto.sign.length > 3) {
|
|
9
|
-
oneShotSign = promisify(crypto.sign);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
oneShotSign = crypto.sign;
|
|
13
|
-
}
|
|
7
|
+
const oneShotSign = promisify(crypto.sign);
|
|
14
8
|
const sign = async (alg, key, data) => {
|
|
15
9
|
const keyObject = getSignKey(alg, key, 'sign');
|
|
16
10
|
if (alg.startsWith('HS')) {
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import { promisify } from 'util';
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
3
|
import nodeDigest from './dsa_digest.js';
|
|
4
4
|
import nodeKey from './node_key.js';
|
|
5
5
|
import sign from './sign.js';
|
|
6
6
|
import getVerifyKey from './get_sign_verify_key.js';
|
|
7
|
-
|
|
8
|
-
let oneShotVerify;
|
|
9
|
-
if (crypto.verify.length > 4 && oneShotCallback) {
|
|
10
|
-
oneShotVerify = promisify(crypto.verify);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
oneShotVerify = crypto.verify;
|
|
14
|
-
}
|
|
7
|
+
const oneShotVerify = promisify(crypto.verify);
|
|
15
8
|
const verify = async (alg, key, signature, data) => {
|
|
16
9
|
const keyObject = getVerifyKey(alg, key, 'verify');
|
|
17
10
|
if (alg.startsWith('HS')) {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import * as util from 'util';
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
import * as util from 'node:util';
|
|
3
3
|
const webcrypto = crypto.webcrypto;
|
|
4
4
|
export default webcrypto;
|
|
5
|
-
export const isCryptoKey = util.types.isCryptoKey
|
|
6
|
-
? (key) => util.types.isCryptoKey(key)
|
|
7
|
-
:
|
|
8
|
-
(key) => false;
|
|
5
|
+
export const isCryptoKey = (key) => util.types.isCryptoKey(key);
|
|
@@ -2,21 +2,22 @@ export class JOSEError extends Error {
|
|
|
2
2
|
static get code() {
|
|
3
3
|
return 'ERR_JOSE_GENERIC';
|
|
4
4
|
}
|
|
5
|
+
code = 'ERR_JOSE_GENERIC';
|
|
5
6
|
constructor(message) {
|
|
6
|
-
var _a;
|
|
7
7
|
super(message);
|
|
8
|
-
this.code = 'ERR_JOSE_GENERIC';
|
|
9
8
|
this.name = this.constructor.name;
|
|
10
|
-
|
|
9
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
export class JWTClaimValidationFailed extends JOSEError {
|
|
14
13
|
static get code() {
|
|
15
14
|
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
16
15
|
}
|
|
16
|
+
code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
17
|
+
claim;
|
|
18
|
+
reason;
|
|
17
19
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
18
20
|
super(message);
|
|
19
|
-
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
|
20
21
|
this.claim = claim;
|
|
21
22
|
this.reason = reason;
|
|
22
23
|
}
|
|
@@ -25,124 +26,90 @@ export class JWTExpired extends JOSEError {
|
|
|
25
26
|
static get code() {
|
|
26
27
|
return 'ERR_JWT_EXPIRED';
|
|
27
28
|
}
|
|
29
|
+
code = 'ERR_JWT_EXPIRED';
|
|
30
|
+
claim;
|
|
31
|
+
reason;
|
|
28
32
|
constructor(message, claim = 'unspecified', reason = 'unspecified') {
|
|
29
33
|
super(message);
|
|
30
|
-
this.code = 'ERR_JWT_EXPIRED';
|
|
31
34
|
this.claim = claim;
|
|
32
35
|
this.reason = reason;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
export class JOSEAlgNotAllowed extends JOSEError {
|
|
36
|
-
constructor() {
|
|
37
|
-
super(...arguments);
|
|
38
|
-
this.code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
39
|
-
}
|
|
40
39
|
static get code() {
|
|
41
40
|
return 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
42
41
|
}
|
|
42
|
+
code = 'ERR_JOSE_ALG_NOT_ALLOWED';
|
|
43
43
|
}
|
|
44
44
|
export class JOSENotSupported extends JOSEError {
|
|
45
|
-
constructor() {
|
|
46
|
-
super(...arguments);
|
|
47
|
-
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
48
|
-
}
|
|
49
45
|
static get code() {
|
|
50
46
|
return 'ERR_JOSE_NOT_SUPPORTED';
|
|
51
47
|
}
|
|
48
|
+
code = 'ERR_JOSE_NOT_SUPPORTED';
|
|
52
49
|
}
|
|
53
50
|
export class JWEDecryptionFailed extends JOSEError {
|
|
54
|
-
constructor() {
|
|
55
|
-
super(...arguments);
|
|
56
|
-
this.code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
57
|
-
this.message = 'decryption operation failed';
|
|
58
|
-
}
|
|
59
51
|
static get code() {
|
|
60
52
|
return 'ERR_JWE_DECRYPTION_FAILED';
|
|
61
53
|
}
|
|
54
|
+
code = 'ERR_JWE_DECRYPTION_FAILED';
|
|
55
|
+
message = 'decryption operation failed';
|
|
62
56
|
}
|
|
63
57
|
export class JWEInvalid extends JOSEError {
|
|
64
|
-
constructor() {
|
|
65
|
-
super(...arguments);
|
|
66
|
-
this.code = 'ERR_JWE_INVALID';
|
|
67
|
-
}
|
|
68
58
|
static get code() {
|
|
69
59
|
return 'ERR_JWE_INVALID';
|
|
70
60
|
}
|
|
61
|
+
code = 'ERR_JWE_INVALID';
|
|
71
62
|
}
|
|
72
63
|
export class JWSInvalid extends JOSEError {
|
|
73
|
-
constructor() {
|
|
74
|
-
super(...arguments);
|
|
75
|
-
this.code = 'ERR_JWS_INVALID';
|
|
76
|
-
}
|
|
77
64
|
static get code() {
|
|
78
65
|
return 'ERR_JWS_INVALID';
|
|
79
66
|
}
|
|
67
|
+
code = 'ERR_JWS_INVALID';
|
|
80
68
|
}
|
|
81
69
|
export class JWTInvalid extends JOSEError {
|
|
82
|
-
constructor() {
|
|
83
|
-
super(...arguments);
|
|
84
|
-
this.code = 'ERR_JWT_INVALID';
|
|
85
|
-
}
|
|
86
70
|
static get code() {
|
|
87
71
|
return 'ERR_JWT_INVALID';
|
|
88
72
|
}
|
|
73
|
+
code = 'ERR_JWT_INVALID';
|
|
89
74
|
}
|
|
90
75
|
export class JWKInvalid extends JOSEError {
|
|
91
|
-
constructor() {
|
|
92
|
-
super(...arguments);
|
|
93
|
-
this.code = 'ERR_JWK_INVALID';
|
|
94
|
-
}
|
|
95
76
|
static get code() {
|
|
96
77
|
return 'ERR_JWK_INVALID';
|
|
97
78
|
}
|
|
79
|
+
code = 'ERR_JWK_INVALID';
|
|
98
80
|
}
|
|
99
81
|
export class JWKSInvalid extends JOSEError {
|
|
100
|
-
constructor() {
|
|
101
|
-
super(...arguments);
|
|
102
|
-
this.code = 'ERR_JWKS_INVALID';
|
|
103
|
-
}
|
|
104
82
|
static get code() {
|
|
105
83
|
return 'ERR_JWKS_INVALID';
|
|
106
84
|
}
|
|
85
|
+
code = 'ERR_JWKS_INVALID';
|
|
107
86
|
}
|
|
108
87
|
export class JWKSNoMatchingKey extends JOSEError {
|
|
109
|
-
constructor() {
|
|
110
|
-
super(...arguments);
|
|
111
|
-
this.code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
112
|
-
this.message = 'no applicable key found in the JSON Web Key Set';
|
|
113
|
-
}
|
|
114
88
|
static get code() {
|
|
115
89
|
return 'ERR_JWKS_NO_MATCHING_KEY';
|
|
116
90
|
}
|
|
91
|
+
code = 'ERR_JWKS_NO_MATCHING_KEY';
|
|
92
|
+
message = 'no applicable key found in the JSON Web Key Set';
|
|
117
93
|
}
|
|
118
94
|
export class JWKSMultipleMatchingKeys extends JOSEError {
|
|
119
|
-
|
|
120
|
-
super(...arguments);
|
|
121
|
-
this.code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
122
|
-
this.message = 'multiple matching keys found in the JSON Web Key Set';
|
|
123
|
-
}
|
|
95
|
+
[Symbol.asyncIterator];
|
|
124
96
|
static get code() {
|
|
125
97
|
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
126
98
|
}
|
|
99
|
+
code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
|
|
100
|
+
message = 'multiple matching keys found in the JSON Web Key Set';
|
|
127
101
|
}
|
|
128
|
-
Symbol.asyncIterator;
|
|
129
102
|
export class JWKSTimeout extends JOSEError {
|
|
130
|
-
constructor() {
|
|
131
|
-
super(...arguments);
|
|
132
|
-
this.code = 'ERR_JWKS_TIMEOUT';
|
|
133
|
-
this.message = 'request timed out';
|
|
134
|
-
}
|
|
135
103
|
static get code() {
|
|
136
104
|
return 'ERR_JWKS_TIMEOUT';
|
|
137
105
|
}
|
|
106
|
+
code = 'ERR_JWKS_TIMEOUT';
|
|
107
|
+
message = 'request timed out';
|
|
138
108
|
}
|
|
139
109
|
export class JWSSignatureVerificationFailed extends JOSEError {
|
|
140
|
-
constructor() {
|
|
141
|
-
super(...arguments);
|
|
142
|
-
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
143
|
-
this.message = 'signature verification failed';
|
|
144
|
-
}
|
|
145
110
|
static get code() {
|
|
146
111
|
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
147
112
|
}
|
|
113
|
+
code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
|
114
|
+
message = 'signature verification failed';
|
|
148
115
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -44,5 +44,5 @@ export type { GenerateKeyPairResult, GenerateKeyPairOptions } from './key/genera
|
|
|
44
44
|
export { generateSecret } from './key/generate_secret';
|
|
45
45
|
export type { GenerateSecretOptions } from './key/generate_secret';
|
|
46
46
|
export * as base64url from './util/base64url';
|
|
47
|
-
export type { KeyLike, JWK, FlattenedJWSInput, GeneralJWSInput, FlattenedJWS, GeneralJWS, JoseHeaderParameters, JWSHeaderParameters, JWEKeyManagementHeaderParameters, FlattenedJWE, GeneralJWE, JWEHeaderParameters, CritOption,
|
|
47
|
+
export type { KeyLike, JWK, FlattenedJWSInput, GeneralJWSInput, FlattenedJWS, GeneralJWS, JoseHeaderParameters, JWSHeaderParameters, JWEKeyManagementHeaderParameters, FlattenedJWE, GeneralJWE, JWEHeaderParameters, CritOption, DecryptOptions, EncryptOptions, JWTClaimVerificationOptions, VerifyOptions, SignOptions, JWTPayload, FlattenedDecryptResult, GeneralDecryptResult, CompactDecryptResult, FlattenedVerifyResult, GeneralVerifyResult, CompactVerifyResult, JWTVerifyResult, JWTDecryptResult, ResolvedKey, CompactJWEHeaderParameters, CompactJWSHeaderParameters, JWTHeaderParameters, JSONWebKeySet, CryptoRuntime, GetKeyFunction, } from './types';
|
|
48
48
|
export { default as cryptoRuntime } from './util/runtime';
|
|
@@ -20,4 +20,4 @@ export declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike |
|
|
|
20
20
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
21
21
|
* @param options JWE Decryption options.
|
|
22
22
|
*/
|
|
23
|
-
export declare function compactDecrypt<
|
|
23
|
+
export declare function compactDecrypt<KeyLikeType extends KeyLike = KeyLike>(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -20,4 +20,4 @@ export declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike | Uint8
|
|
|
20
20
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
21
21
|
* @param options JWE Decryption options.
|
|
22
22
|
*/
|
|
23
|
-
export declare function flattenedDecrypt<
|
|
23
|
+
export declare function flattenedDecrypt<KeyLikeType extends KeyLike = KeyLike>(jwe: FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -20,4 +20,4 @@ export declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | Uint8Arra
|
|
|
20
20
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
21
21
|
* @param options JWE Decryption options.
|
|
22
22
|
*/
|
|
23
|
-
export declare function generalDecrypt<
|
|
23
|
+
export declare function generalDecrypt<KeyLikeType extends KeyLike = KeyLike>(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KeyLike, GeneralJWE, JWEHeaderParameters, CritOption
|
|
1
|
+
import type { KeyLike, GeneralJWE, JWEHeaderParameters, CritOption } from '../../types';
|
|
2
2
|
export interface Recipient {
|
|
3
3
|
/**
|
|
4
4
|
* Sets the JWE Per-Recipient Unprotected Header on the Recipient object.
|
|
@@ -51,10 +51,6 @@ export declare class GeneralEncrypt {
|
|
|
51
51
|
* @param aad Additional Authenticated Data.
|
|
52
52
|
*/
|
|
53
53
|
setAdditionalAuthenticatedData(aad: Uint8Array): this;
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* @param options JWE Encryption options.
|
|
58
|
-
*/
|
|
59
|
-
encrypt(options?: DeflateOption): Promise<GeneralJWE>;
|
|
54
|
+
/** Encrypts and resolves the value of the General JWE object. */
|
|
55
|
+
encrypt(): Promise<GeneralJWE>;
|
|
60
56
|
}
|
|
@@ -6,4 +6,4 @@ import type { KeyLike, FlattenedJWSInput, JWSHeaderParameters } from '../types';
|
|
|
6
6
|
* function's `algorithms` option to define accepted JWS "alg" (Algorithm) Header Parameter values.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
export declare function EmbeddedJWK<
|
|
9
|
+
export declare function EmbeddedJWK<KeyLikeType extends KeyLike = KeyLike>(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<KeyLikeType>;
|
|
@@ -2,11 +2,11 @@ import type { KeyLike, JWSHeaderParameters, JSONWebKeySet, FlattenedJWSInput } f
|
|
|
2
2
|
/** @private */
|
|
3
3
|
export declare function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet;
|
|
4
4
|
/** @private */
|
|
5
|
-
export declare class LocalJWKSet<
|
|
5
|
+
export declare class LocalJWKSet<KeyLikeType extends KeyLike = KeyLike> {
|
|
6
6
|
protected _jwks?: JSONWebKeySet;
|
|
7
7
|
private _cached;
|
|
8
8
|
constructor(jwks: unknown);
|
|
9
|
-
getKey(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<
|
|
9
|
+
getKey(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<KeyLikeType>;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Returns a function that resolves to a key object from a locally stored, or otherwise available,
|
|
@@ -23,4 +23,4 @@ export declare class LocalJWKSet<T extends KeyLike = KeyLike> {
|
|
|
23
23
|
*
|
|
24
24
|
* @param jwks JSON Web Key Set formatted object.
|
|
25
25
|
*/
|
|
26
|
-
export declare function createLocalJWKSet<
|
|
26
|
+
export declare function createLocalJWKSet<KeyLikeType extends KeyLike = KeyLike>(jwks: JSONWebKeySet): (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<KeyLikeType>;
|
|
@@ -46,4 +46,4 @@ export interface RemoteJWKSetOptions {
|
|
|
46
46
|
* @param url URL to fetch the JSON Web Key Set from.
|
|
47
47
|
* @param options Options for the remote JSON Web Key Set.
|
|
48
48
|
*/
|
|
49
|
-
export declare function createRemoteJWKSet<
|
|
49
|
+
export declare function createRemoteJWKSet<KeyLikeType extends KeyLike = KeyLike>(url: URL, options?: RemoteJWKSetOptions): (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<KeyLikeType>;
|
|
@@ -22,4 +22,4 @@ export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | U
|
|
|
22
22
|
* {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
|
|
23
23
|
* @param options JWS Verify options.
|
|
24
24
|
*/
|
|
25
|
-
export declare function compactVerify<
|
|
25
|
+
export declare function compactVerify<KeyLikeType extends KeyLike = KeyLike>(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -22,4 +22,4 @@ export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | U
|
|
|
22
22
|
* {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
|
|
23
23
|
* @param options JWS Verify options.
|
|
24
24
|
*/
|
|
25
|
-
export declare function flattenedVerify<
|
|
25
|
+
export declare function flattenedVerify<KeyLikeType extends KeyLike = KeyLike>(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -22,4 +22,4 @@ export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8
|
|
|
22
22
|
* {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
|
|
23
23
|
* @param options JWS Verify options.
|
|
24
24
|
*/
|
|
25
|
-
export declare function generalVerify<
|
|
25
|
+
export declare function generalVerify<KeyLikeType extends KeyLike = KeyLike>(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey<KeyLikeType>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction, CompactJWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
|
|
1
|
+
import type { JWTPayload, KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction, CompactJWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
|
|
2
2
|
/** Combination of JWE Decryption options and JWT Claims Set verification options. */
|
|
3
3
|
export interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {
|
|
4
4
|
}
|
|
@@ -17,11 +17,11 @@ export interface JWTDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParamet
|
|
|
17
17
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
18
18
|
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
19
19
|
*/
|
|
20
|
-
export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult
|
|
20
|
+
export declare function jwtDecrypt<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult<PayloadType>>;
|
|
21
21
|
/**
|
|
22
22
|
* @param jwt JSON Web Token value (encoded as JWE).
|
|
23
23
|
* @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with. See
|
|
24
24
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
25
25
|
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
26
26
|
*/
|
|
27
|
-
export declare function jwtDecrypt<
|
|
27
|
+
export declare function jwtDecrypt<PayloadType = JWTPayload, KeyLikeType extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult<PayloadType> & ResolvedKey<KeyLikeType>>;
|