jose 4.0.0 → 4.0.4
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/lib/cek.js +18 -16
- package/dist/browser/lib/check_iv_length.js +2 -2
- package/dist/browser/lib/crypto_key.js +160 -0
- package/dist/browser/lib/decrypt_key_management.js +2 -2
- package/dist/browser/lib/encrypt_key_management.js +2 -2
- package/dist/browser/lib/iv.js +24 -19
- package/dist/browser/runtime/aeskw.js +5 -3
- package/dist/browser/runtime/check_cek_length.js +4 -34
- package/dist/browser/runtime/decrypt.js +18 -6
- package/dist/browser/runtime/ecdhes.js +3 -0
- package/dist/browser/runtime/encrypt.js +18 -6
- package/dist/browser/runtime/get_sign_verify_key.js +2 -0
- package/dist/browser/runtime/pbes2kw.js +5 -3
- package/dist/browser/runtime/rsaes.js +3 -0
- package/dist/node/cjs/lib/cek.js +20 -17
- package/dist/node/cjs/lib/check_iv_length.js +1 -1
- package/dist/node/cjs/lib/crypto_key.js +165 -0
- 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/lib/iv.js +26 -20
- package/dist/node/cjs/runtime/aeskw.js +3 -1
- package/dist/node/cjs/runtime/asn1.js +1 -1
- package/dist/node/cjs/runtime/decrypt.js +3 -1
- package/dist/node/cjs/runtime/ecdhes.js +6 -3
- package/dist/node/cjs/runtime/encrypt.js +3 -1
- package/dist/node/cjs/runtime/fetch_jwks.js +13 -9
- package/dist/node/cjs/runtime/get_named_curve.js +1 -1
- package/dist/node/cjs/runtime/get_sign_verify_key.js +5 -3
- package/dist/node/cjs/runtime/global.js +11 -0
- package/dist/node/cjs/runtime/key_to_jwk.js +1 -1
- package/dist/node/cjs/runtime/pbes2kw.js +3 -1
- package/dist/node/cjs/runtime/rsaes.js +3 -1
- package/dist/node/cjs/runtime/webcrypto.js +1 -149
- package/dist/node/esm/lib/cek.js +18 -16
- package/dist/node/esm/lib/check_iv_length.js +2 -2
- package/dist/node/esm/lib/crypto_key.js +160 -0
- package/dist/node/esm/lib/decrypt_key_management.js +2 -2
- package/dist/node/esm/lib/encrypt_key_management.js +2 -2
- package/dist/node/esm/lib/iv.js +24 -19
- package/dist/node/esm/runtime/aeskw.js +5 -3
- package/dist/node/esm/runtime/asn1.js +3 -3
- package/dist/node/esm/runtime/decrypt.js +5 -3
- package/dist/node/esm/runtime/ecdhes.js +8 -5
- package/dist/node/esm/runtime/encrypt.js +5 -3
- package/dist/node/esm/runtime/fetch_jwks.js +13 -9
- package/dist/node/esm/runtime/get_named_curve.js +3 -3
- package/dist/node/esm/runtime/get_sign_verify_key.js +6 -4
- package/dist/node/esm/runtime/global.js +6 -0
- package/dist/node/esm/runtime/key_to_jwk.js +3 -3
- package/dist/node/esm/runtime/pbes2kw.js +5 -3
- package/dist/node/esm/runtime/rsaes.js +5 -3
- package/dist/node/esm/runtime/webcrypto.js +0 -147
- package/dist/types/index.d.ts +17 -0
- package/package.json +1 -1
|
@@ -6,150 +6,3 @@ export const isCryptoKey = util.types.isCryptoKey
|
|
|
6
6
|
? (obj) => util.types.isCryptoKey(obj)
|
|
7
7
|
:
|
|
8
8
|
(obj) => false;
|
|
9
|
-
function getHashLength(hash) {
|
|
10
|
-
return parseInt(hash === null || hash === void 0 ? void 0 : hash.name.substr(4), 10);
|
|
11
|
-
}
|
|
12
|
-
function getNamedCurve(alg) {
|
|
13
|
-
switch (alg) {
|
|
14
|
-
case 'ES256':
|
|
15
|
-
return 'P-256';
|
|
16
|
-
case 'ES384':
|
|
17
|
-
return 'P-384';
|
|
18
|
-
case 'ES512':
|
|
19
|
-
return 'P-521';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export function getKeyObject(key, alg, usage) {
|
|
23
|
-
switch (alg) {
|
|
24
|
-
case undefined:
|
|
25
|
-
break;
|
|
26
|
-
case 'HS256':
|
|
27
|
-
case 'HS384':
|
|
28
|
-
case 'HS512': {
|
|
29
|
-
if (key.algorithm.name !== 'HMAC') {
|
|
30
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be HMAC.`);
|
|
31
|
-
}
|
|
32
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
33
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
34
|
-
if (actual !== expected) {
|
|
35
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case 'RS256':
|
|
40
|
-
case 'RS384':
|
|
41
|
-
case 'RS512': {
|
|
42
|
-
if (key.algorithm.name !== 'RSASSA-PKCS1-v1_5') {
|
|
43
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSASSA-PKCS1-v1_5.`);
|
|
44
|
-
}
|
|
45
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
46
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
47
|
-
if (actual !== expected) {
|
|
48
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case 'PS256':
|
|
53
|
-
case 'PS384':
|
|
54
|
-
case 'PS512': {
|
|
55
|
-
if (key.algorithm.name !== 'RSA-PSS') {
|
|
56
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-PSS.`);
|
|
57
|
-
}
|
|
58
|
-
const expected = parseInt(alg.substr(2), 10);
|
|
59
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
60
|
-
if (actual !== expected) {
|
|
61
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'EdDSA': {
|
|
66
|
-
if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448') {
|
|
67
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be NODE-ED25519 or NODE-ED448.`);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case 'ES256':
|
|
72
|
-
case 'ES384':
|
|
73
|
-
case 'ES512': {
|
|
74
|
-
if (key.algorithm.name !== 'ECDSA') {
|
|
75
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDSA.`);
|
|
76
|
-
}
|
|
77
|
-
const expected = getNamedCurve(alg);
|
|
78
|
-
const actual = key.algorithm.namedCurve;
|
|
79
|
-
if (actual !== expected) {
|
|
80
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.namedCurve must be ${expected}.`);
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case 'A128GCM':
|
|
85
|
-
case 'A192GCM':
|
|
86
|
-
case 'A256GCM': {
|
|
87
|
-
if (key.algorithm.name !== 'AES-GCM') {
|
|
88
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-GCM.`);
|
|
89
|
-
}
|
|
90
|
-
const expected = parseInt(alg.substr(1, 3), 10);
|
|
91
|
-
const actual = key.algorithm.length;
|
|
92
|
-
if (actual !== expected) {
|
|
93
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case 'A128KW':
|
|
98
|
-
case 'A192KW':
|
|
99
|
-
case 'A256KW': {
|
|
100
|
-
if (key.algorithm.name !== 'AES-KW') {
|
|
101
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-KW.`);
|
|
102
|
-
}
|
|
103
|
-
const expected = parseInt(alg.substr(1, 3), 10);
|
|
104
|
-
const actual = key.algorithm.length;
|
|
105
|
-
if (actual !== expected) {
|
|
106
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case 'ECDH-ES':
|
|
111
|
-
if (key.algorithm.name !== 'ECDH') {
|
|
112
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDH.`);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
case 'PBES2-HS256+A128KW':
|
|
116
|
-
case 'PBES2-HS384+A192KW':
|
|
117
|
-
case 'PBES2-HS512+A256KW':
|
|
118
|
-
if (key.algorithm.name !== 'PBKDF2') {
|
|
119
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be PBKDF2.`);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case 'RSA-OAEP':
|
|
123
|
-
case 'RSA-OAEP-256':
|
|
124
|
-
case 'RSA-OAEP-384':
|
|
125
|
-
case 'RSA-OAEP-512': {
|
|
126
|
-
if (key.algorithm.name !== 'RSA-OAEP') {
|
|
127
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-OAEP.`);
|
|
128
|
-
}
|
|
129
|
-
const expected = parseInt(alg.substr(9), 10) || 1;
|
|
130
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
131
|
-
if (actual !== expected) {
|
|
132
|
-
throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
default:
|
|
137
|
-
throw new TypeError('CryptoKey does not support this operation');
|
|
138
|
-
}
|
|
139
|
-
if (usage && !key.usages.find(Set.prototype.has.bind(usage))) {
|
|
140
|
-
const usages = [...usage];
|
|
141
|
-
let msg = 'CryptoKey does not support this operation, its usages must include ';
|
|
142
|
-
if (usages.length > 2) {
|
|
143
|
-
const last = usages.pop();
|
|
144
|
-
msg += `one of ${usages.join(', ')}, or ${last}.`;
|
|
145
|
-
}
|
|
146
|
-
else if (usages.length === 2) {
|
|
147
|
-
msg += `one of ${usages[0]} or ${usages[1]}.`;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
msg += ` ${usages[0]}.`;
|
|
151
|
-
}
|
|
152
|
-
throw new TypeError(msg);
|
|
153
|
-
}
|
|
154
|
-
return crypto.KeyObject.from(key);
|
|
155
|
-
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
export { compactDecrypt } from './jwe/compact/decrypt';
|
|
2
|
+
export type { CompactDecryptGetKey } from './jwe/compact/decrypt';
|
|
2
3
|
export { flattenedDecrypt } from './jwe/flattened/decrypt';
|
|
4
|
+
export type { FlattenedDecryptGetKey } from './jwe/flattened/decrypt';
|
|
3
5
|
export { generalDecrypt } from './jwe/general/decrypt';
|
|
6
|
+
export type { GeneralDecryptGetKey } from './jwe/general/decrypt';
|
|
4
7
|
export { compactVerify } from './jws/compact/verify';
|
|
8
|
+
export type { CompactVerifyGetKey } from './jws/compact/verify';
|
|
5
9
|
export { flattenedVerify } from './jws/flattened/verify';
|
|
10
|
+
export type { FlattenedVerifyGetKey } from './jws/flattened/verify';
|
|
6
11
|
export { generalVerify } from './jws/general/verify';
|
|
12
|
+
export type { GeneralVerifyGetKey } from './jws/general/verify';
|
|
7
13
|
export { jwtVerify } from './jwt/verify';
|
|
14
|
+
export type { JWTVerifyOptions, JWTVerifyGetKey } from './jwt/verify';
|
|
8
15
|
export { jwtDecrypt } from './jwt/decrypt';
|
|
16
|
+
export type { JWTDecryptOptions, JWTDecryptGetKey } from './jwt/decrypt';
|
|
17
|
+
export type { ProduceJWT } from './jwt/produce';
|
|
9
18
|
export { CompactEncrypt } from './jwe/compact/encrypt';
|
|
10
19
|
export { FlattenedEncrypt } from './jwe/flattened/encrypt';
|
|
11
20
|
export { CompactSign } from './jws/compact/sign';
|
|
12
21
|
export { FlattenedSign } from './jws/flattened/sign';
|
|
13
22
|
export { GeneralSign } from './jws/general/sign';
|
|
23
|
+
export type { Signature } from './jws/general/sign';
|
|
14
24
|
export { SignJWT } from './jwt/sign';
|
|
15
25
|
export { EncryptJWT } from './jwt/encrypt';
|
|
16
26
|
export { calculateJwkThumbprint } from './jwk/thumbprint';
|
|
17
27
|
export { EmbeddedJWK } from './jwk/embedded';
|
|
18
28
|
export { createRemoteJWKSet } from './jwks/remote';
|
|
29
|
+
export type { RemoteJWKSetOptions } from './jwks/remote';
|
|
19
30
|
export { UnsecuredJWT } from './jwt/unsecured';
|
|
31
|
+
export type { UnsecuredResult } from './jwt/unsecured';
|
|
20
32
|
export { exportPKCS8, exportSPKI, exportJWK } from './key/export';
|
|
21
33
|
export { importSPKI, importPKCS8, importX509, importJWK } from './key/import';
|
|
34
|
+
export type { PEMImportOptions } from './key/import';
|
|
22
35
|
export { decodeProtectedHeader } from './util/decode_protected_header';
|
|
36
|
+
export type { ProtectedHeaderParameters } from './util/decode_protected_header';
|
|
23
37
|
export * as errors from './util/errors';
|
|
24
38
|
export { generateKeyPair } from './key/generate_key_pair';
|
|
39
|
+
export type { GenerateKeyPairResult, GenerateKeyPairOptions } from './key/generate_key_pair';
|
|
25
40
|
export { generateSecret } from './key/generate_secret';
|
|
41
|
+
export type { GenerateSecretOptions } from './key/generate_secret';
|
|
26
42
|
export * as base64url from './util/base64url';
|
|
43
|
+
export type { KeyLike, JWK, FlattenedJWSInput, GeneralJWSInput, FlattenedJWS, GeneralJWS, JoseHeaderParameters, JWSHeaderParameters, JWEKeyManagementHeaderParameters, FlattenedJWE, GeneralJWE, JWEHeaderParameters, CritOption, DecryptOptions, EncryptOptions, JWTClaimVerificationOptions, VerifyOptions, SignOptions, JWTPayload, DeflateFunction, InflateFunction, FlattenedDecryptResult, GeneralDecryptResult, CompactDecryptResult, FlattenedVerifyResult, GeneralVerifyResult, CompactVerifyResult, JWTVerifyResult, JWTDecryptResult, ResolvedKey, } from './types';
|