jose 6.2.10 → 6.2.12
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/types/index.d.ts +1 -2
- package/dist/types/jwe/compact/decrypt.d.ts +12 -25
- package/dist/types/jwe/compact/encrypt.d.ts +18 -32
- package/dist/types/jwe/flattened/decrypt.d.ts +12 -25
- package/dist/types/jwe/flattened/encrypt.d.ts +24 -50
- package/dist/types/jwe/general/decrypt.d.ts +15 -30
- package/dist/types/jwe/general/encrypt.d.ts +29 -52
- package/dist/types/jwk/embedded.d.ts +5 -8
- package/dist/types/jwk/thumbprint.d.ts +7 -9
- package/dist/types/jwks/local.d.ts +10 -13
- package/dist/types/jwks/remote.d.ts +29 -41
- package/dist/types/jws/compact/sign.d.ts +8 -13
- package/dist/types/jws/compact/verify.d.ts +14 -26
- package/dist/types/jws/flattened/sign.d.ts +10 -19
- package/dist/types/jws/flattened/verify.d.ts +14 -26
- package/dist/types/jws/general/sign.d.ts +19 -33
- package/dist/types/jws/general/verify.d.ts +17 -32
- package/dist/types/jwt/decrypt.d.ts +20 -27
- package/dist/types/jwt/encrypt.d.ts +30 -35
- package/dist/types/jwt/sign.d.ts +8 -13
- package/dist/types/jwt/unsecured.d.ts +10 -19
- package/dist/types/jwt/verify.d.ts +19 -22
- package/dist/types/key/export.d.ts +10 -10
- package/dist/types/key/generate_key_pair.d.ts +15 -22
- package/dist/types/key/generate_secret.d.ts +12 -19
- package/dist/types/key/import.d.ts +25 -31
- package/dist/types/types.d.ts +184 -319
- package/dist/types/util/base64url.d.ts +7 -7
- package/dist/types/util/decode_jwt.d.ts +5 -7
- package/dist/types/util/decode_protected_header.d.ts +6 -5
- package/dist/types/util/errors.d.ts +50 -88
- package/dist/webapi/index.js +70 -32
- package/dist/webapi/jwe/compact/decrypt.js +6 -8
- package/dist/webapi/jwe/compact/encrypt.js +25 -48
- package/dist/webapi/jwe/flattened/decrypt.js +14 -14
- package/dist/webapi/jwe/flattened/encrypt.js +34 -64
- package/dist/webapi/jwe/general/decrypt.js +38 -49
- package/dist/webapi/jwe/general/encrypt.js +100 -172
- package/dist/webapi/jwk/embedded.js +29 -32
- package/dist/webapi/jwk/thumbprint.js +51 -70
- package/dist/webapi/jwks/local.js +53 -64
- package/dist/webapi/jwks/remote.js +88 -136
- package/dist/webapi/jws/compact/sign.js +19 -21
- package/dist/webapi/jws/compact/verify.js +7 -8
- package/dist/webapi/jws/flattened/sign.js +22 -31
- package/dist/webapi/jws/flattened/verify.js +11 -24
- package/dist/webapi/jws/general/sign.js +55 -73
- package/dist/webapi/jws/general/verify.js +43 -69
- package/dist/webapi/jwt/decrypt.js +12 -20
- package/dist/webapi/jwt/encrypt.js +43 -70
- package/dist/webapi/jwt/sign.js +17 -16
- package/dist/webapi/jwt/unsecured.js +31 -40
- package/dist/webapi/jwt/verify.js +12 -14
- package/dist/webapi/key/export.js +32 -41
- package/dist/webapi/key/generate_key_pair.js +32 -49
- package/dist/webapi/key/generate_secret.js +35 -40
- package/dist/webapi/key/import.js +48 -56
- package/dist/webapi/lib/asn1.js +128 -169
- package/dist/webapi/lib/buffer_utils.js +72 -41
- package/dist/webapi/lib/content_encryption.js +75 -119
- package/dist/webapi/lib/deflate.js +35 -47
- package/dist/webapi/lib/jwe_algorithms.js +102 -93
- package/dist/webapi/lib/jwe_decrypt.js +178 -234
- package/dist/webapi/lib/jwe_encrypt.js +71 -138
- package/dist/webapi/lib/jws_algorithms.js +62 -61
- package/dist/webapi/lib/jws_sign.js +43 -82
- package/dist/webapi/lib/jws_verify.js +78 -131
- package/dist/webapi/lib/jwt_claims_set.js +123 -209
- package/dist/webapi/lib/key.js +147 -139
- package/dist/webapi/lib/key_algorithm.js +13 -8
- package/dist/webapi/lib/key_descriptor.js +8 -6
- package/dist/webapi/lib/key_management.js +169 -235
- package/dist/webapi/lib/validate.js +122 -0
- package/dist/webapi/util/base64url.js +14 -37
- package/dist/webapi/util/decode_jwt.js +32 -31
- package/dist/webapi/util/decode_protected_header.js +18 -23
- package/dist/webapi/util/errors.js +94 -84
- package/package.json +17 -81
- package/dist/webapi/lib/base64.js +0 -22
- package/dist/webapi/lib/crypto_key.js +0 -28
- package/dist/webapi/lib/helpers.js +0 -42
- package/dist/webapi/lib/invalid_key_input.js +0 -26
- package/dist/webapi/lib/is_key_like.js +0 -17
- package/dist/webapi/lib/jwk_metadata.js +0 -20
- package/dist/webapi/lib/jwk_to_key.js +0 -17
- package/dist/webapi/lib/key_options.js +0 -6
- package/dist/webapi/lib/options.js +0 -74
- package/dist/webapi/lib/signing.js +0 -26
- package/dist/webapi/lib/type_checks.js +0 -33
|
@@ -1,243 +1,187 @@
|
|
|
1
|
-
import { decrypt, generateCek } from
|
|
2
|
-
import { decodeBase64url, encodeBase64url, parseJoseHeader } from
|
|
3
|
-
import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
aad,
|
|
33
|
-
ciphertext,
|
|
34
|
-
iv,
|
|
35
|
-
protected: encodedProtected,
|
|
36
|
-
tag,
|
|
37
|
-
unprotected: unprotected === undefined ? undefined : { ...unprotected },
|
|
38
|
-
};
|
|
1
|
+
import { decrypt, generateCek } from "./content_encryption.js";
|
|
2
|
+
import { decodeBase64url, encodeBase64url, parseJoseHeader, isDisjoint, isObject, validateCrit, validateAlgorithms, JWE_RECOGNIZED } from "./validate.js";
|
|
3
|
+
import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from "../util/errors.js";
|
|
4
|
+
import { decryptKeyManagement } from "./key_management.js";
|
|
5
|
+
import { decoder } from "./buffer_utils.js";
|
|
6
|
+
import { prepareKey } from "./key.js";
|
|
7
|
+
import { JWE, isJWECEKTransport, jweAlgorithm, jweEncryption } from "./jwe_algorithms.js";
|
|
8
|
+
import { decompress, validateZip } from "./deflate.js";
|
|
9
|
+
function snapshotSharedJWE(jwe) {
|
|
10
|
+
const { aad, ciphertext, iv, protected: encodedProtected, tag, unprotected } = jwe;
|
|
11
|
+
if (iv !== void 0 && (typeof iv != "string" || !iv))
|
|
12
|
+
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
13
|
+
if (typeof ciphertext != "string")
|
|
14
|
+
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
15
|
+
if (tag !== void 0 && (typeof tag != "string" || !tag))
|
|
16
|
+
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
17
|
+
if (encodedProtected !== void 0 && typeof encodedProtected != "string")
|
|
18
|
+
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
19
|
+
if (aad !== void 0 && (typeof aad != "string" || !aad))
|
|
20
|
+
throw new JWEInvalid("JWE AAD incorrect type");
|
|
21
|
+
if (unprotected !== void 0 && !isObject(unprotected))
|
|
22
|
+
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
23
|
+
return {
|
|
24
|
+
aad,
|
|
25
|
+
ciphertext,
|
|
26
|
+
iv,
|
|
27
|
+
protected: encodedProtected,
|
|
28
|
+
tag,
|
|
29
|
+
unprotected: unprotected === void 0 ? void 0 : { ...unprotected }
|
|
30
|
+
};
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
return [undefined, headerAlg, error];
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
const { encrypted_key: encryptedKey } = recipient;
|
|
64
|
-
return [{ encrypted_key: encryptedKey, header }, headerAlg];
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
return [undefined, headerAlg, error];
|
|
68
|
-
}
|
|
32
|
+
function snapshotRecipientJWE(recipient) {
|
|
33
|
+
let header, headerAlg;
|
|
34
|
+
try {
|
|
35
|
+
const { header: inputHeader } = recipient;
|
|
36
|
+
if (isObject(inputHeader)) {
|
|
37
|
+
headerAlg = inputHeader.alg;
|
|
38
|
+
const parameters = Object.keys(inputHeader);
|
|
39
|
+
parameters.includes("alg") || (headerAlg = void 0), header = Object.fromEntries(parameters.map((parameter) => [
|
|
40
|
+
parameter,
|
|
41
|
+
parameter === "alg" ? headerAlg : inputHeader[parameter]
|
|
42
|
+
]));
|
|
43
|
+
} else
|
|
44
|
+
header = inputHeader;
|
|
45
|
+
const { encrypted_key: encryptedKey } = recipient;
|
|
46
|
+
return [{ encrypted_key: encryptedKey, header }, headerAlg];
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return [void 0, headerAlg, error];
|
|
49
|
+
}
|
|
69
50
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (jwe.protected === undefined && header === undefined && jwe.unprotected === undefined) {
|
|
81
|
-
throw new JWEInvalid('JOSE Header missing');
|
|
82
|
-
}
|
|
51
|
+
function checkRecipient(jwe) {
|
|
52
|
+
const { encrypted_key: encryptedKey, header } = jwe;
|
|
53
|
+
if (encryptedKey !== void 0 && typeof encryptedKey != "string")
|
|
54
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
55
|
+
if (header !== void 0 && !isObject(header))
|
|
56
|
+
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
57
|
+
if (jwe.protected === void 0 && header === void 0 && jwe.unprotected === void 0)
|
|
58
|
+
throw new JWEInvalid("JOSE Header missing");
|
|
83
59
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
iv !== undefined ? decodeBase64url(iv, 'iv', JWEInvalid) : undefined,
|
|
95
|
-
tag !== undefined ? decodeBase64url(tag, 'tag', JWEInvalid) : undefined,
|
|
96
|
-
aad !== undefined
|
|
97
|
-
? concat(protectedHeader, encode('.'), encodeBase64url(aad, 'aad', JWEInvalid))
|
|
98
|
-
: protectedHeader,
|
|
99
|
-
];
|
|
60
|
+
function shareJWE(jwe) {
|
|
61
|
+
const { protected: encodedProtected, ciphertext, iv, tag, aad } = jwe;
|
|
62
|
+
let parsedProt;
|
|
63
|
+
return encodedProtected !== void 0 && (parsedProt = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid")), [
|
|
64
|
+
parsedProt,
|
|
65
|
+
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
66
|
+
iv !== void 0 ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
67
|
+
tag !== void 0 ? decodeBase64url(tag, "tag", JWEInvalid) : void 0,
|
|
68
|
+
encodeBase64url((encodedProtected ?? "") + (aad !== void 0 ? `.${aad}` : ""), "aad", JWEInvalid)
|
|
69
|
+
];
|
|
100
70
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
result.additionalAuthenticatedData = decodeBase64url(aad, 'aad', JWEInvalid);
|
|
110
|
-
}
|
|
111
|
-
if (unprotected !== undefined) {
|
|
112
|
-
result.sharedUnprotectedHeader = unprotected;
|
|
113
|
-
}
|
|
114
|
-
if (header !== undefined) {
|
|
115
|
-
result.unprotectedHeader = header;
|
|
116
|
-
}
|
|
117
|
-
if (resolvedKey) {
|
|
118
|
-
return { ...result, key };
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
export function prepareDecrypt(options) {
|
|
123
|
-
return [
|
|
124
|
-
options && validateAlgorithms('keyManagementAlgorithms', options.keyManagementAlgorithms),
|
|
125
|
-
options &&
|
|
126
|
-
validateAlgorithms('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms),
|
|
127
|
-
options?.crit,
|
|
128
|
-
options?.maxPBES2Count,
|
|
129
|
-
options?.maxDecompressedLength,
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
export async function decryptRecipient(jwe, token, shared, key) {
|
|
133
|
-
const [parsedProt] = token;
|
|
134
|
-
const { header, unprotected } = jwe;
|
|
135
|
-
let joseHeader;
|
|
136
|
-
if (header !== undefined || unprotected !== undefined) {
|
|
137
|
-
if (!isDisjoint(parsedProt, header, unprotected)) {
|
|
138
|
-
throw new JWEInvalid('JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint');
|
|
139
|
-
}
|
|
140
|
-
joseHeader = { ...parsedProt, ...header, ...unprotected };
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
joseHeader = parsedProt ?? {};
|
|
144
|
-
}
|
|
145
|
-
return decryptRecipientCore(jwe, token, shared, key, joseHeader);
|
|
71
|
+
function prepareDecrypt(options) {
|
|
72
|
+
return [
|
|
73
|
+
options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms),
|
|
74
|
+
options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms),
|
|
75
|
+
options?.crit,
|
|
76
|
+
options?.maxPBES2Count,
|
|
77
|
+
options?.maxDecompressedLength
|
|
78
|
+
];
|
|
146
79
|
}
|
|
147
|
-
async function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
80
|
+
async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
81
|
+
const [parsedProt, ciphertext, iv, tag, additionalData] = token, { header, unprotected, aad } = jwe;
|
|
82
|
+
let joseHeader;
|
|
83
|
+
if (header !== void 0 || unprotected !== void 0) {
|
|
84
|
+
if (!isDisjoint(parsedProt, header, unprotected))
|
|
85
|
+
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
86
|
+
joseHeader = { ...parsedProt, ...header, ...unprotected };
|
|
87
|
+
} else
|
|
88
|
+
joseHeader = parsedProt ?? {};
|
|
89
|
+
const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared, { encrypted_key: encodedKey } = jwe;
|
|
90
|
+
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, parsedProt, joseHeader), validateZip(joseHeader, parsedProt);
|
|
91
|
+
const { alg, enc } = joseHeader;
|
|
92
|
+
if (typeof alg != "string" || !alg)
|
|
93
|
+
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
94
|
+
const selected = JWE[alg];
|
|
95
|
+
if (encodedKey === "" && (!selected || !isJWECEKTransport(selected)))
|
|
96
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
97
|
+
const integrated = selected?.mode === "integrated-encryption";
|
|
98
|
+
if (!integrated && (typeof enc != "string" || !enc))
|
|
99
|
+
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
100
|
+
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2"))
|
|
101
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
102
|
+
let encEntry;
|
|
103
|
+
if (integrated) {
|
|
104
|
+
if (enc !== void 0)
|
|
105
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');
|
|
106
|
+
if (iv?.byteLength)
|
|
107
|
+
throw new JWEInvalid("JWE Initialization Vector must be empty for integrated encryption");
|
|
108
|
+
if (tag?.byteLength)
|
|
109
|
+
throw new JWEInvalid("JWE Authentication Tag must be empty for integrated encryption");
|
|
110
|
+
} else {
|
|
111
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc))
|
|
112
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
113
|
+
encEntry = jweEncryption(enc);
|
|
114
|
+
}
|
|
115
|
+
let encryptedKey;
|
|
116
|
+
if (encodedKey !== void 0)
|
|
117
|
+
try {
|
|
118
|
+
encryptedKey = decodeBase64url(encodedKey, "encrypted_key", JWEInvalid);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (!selected || !isJWECEKTransport(selected))
|
|
121
|
+
throw error;
|
|
122
|
+
encryptedKey = new Uint8Array();
|
|
123
|
+
}
|
|
124
|
+
let resolvedKey = !1;
|
|
125
|
+
typeof key == "function" && (key = await key(parsedProt, jwe), resolvedKey = !0);
|
|
126
|
+
const algEntry = selected ?? jweAlgorithm(alg);
|
|
127
|
+
isJWECEKTransport(algEntry) && encryptedKey === void 0 && (encryptedKey = new Uint8Array());
|
|
128
|
+
const k = await prepareKey(algEntry.mode === "direct-encryption" ? encEntry : algEntry, key, "decrypt");
|
|
129
|
+
let plaintext;
|
|
130
|
+
if (algEntry.mode === "integrated-encryption")
|
|
131
|
+
plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext, additionalData, parsedProt, joseHeader);
|
|
132
|
+
else {
|
|
133
|
+
const encryption = encEntry;
|
|
179
134
|
let cek;
|
|
180
135
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
return [plaintext, parsedProt, k, resolvedKey];
|
|
136
|
+
cek = await decryptKeyManagement(algEntry, encryption, k, encryptedKey, joseHeader, maxPBES2Count), isJWECEKTransport(algEntry) && cek instanceof Uint8Array && cek.byteLength << 3 !== encryption.cekBits && (cek = generateCek(encryption));
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported)
|
|
139
|
+
throw err;
|
|
140
|
+
cek = generateCek(encryption);
|
|
141
|
+
}
|
|
142
|
+
plaintext = await decrypt(encryption, cek, ciphertext, iv, tag, additionalData);
|
|
143
|
+
}
|
|
144
|
+
if (joseHeader.zip === "DEF") {
|
|
145
|
+
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
146
|
+
if (decompressionLimit === 0)
|
|
147
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
148
|
+
if (decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
|
|
149
|
+
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
150
|
+
plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
|
|
151
|
+
throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
plaintext,
|
|
156
|
+
...parsedProt && { protectedHeader: parsedProt },
|
|
157
|
+
...aad !== void 0 && {
|
|
158
|
+
additionalAuthenticatedData: decodeBase64url(aad, "aad", JWEInvalid)
|
|
159
|
+
},
|
|
160
|
+
...unprotected && { sharedUnprotectedHeader: unprotected },
|
|
161
|
+
...header && { unprotectedHeader: header },
|
|
162
|
+
...resolvedKey && { key: k }
|
|
163
|
+
};
|
|
211
164
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
const flattened = {
|
|
227
|
-
ciphertext,
|
|
228
|
-
iv: iv || undefined,
|
|
229
|
-
protected: protectedHeader,
|
|
230
|
-
tag: tag || undefined,
|
|
231
|
-
encrypted_key: encryptedKey || undefined,
|
|
232
|
-
};
|
|
233
|
-
const parsedProt = parseJoseHeader(protectedHeader, JWEInvalid, 'JWE Protected Header is invalid');
|
|
234
|
-
const protectedBytes = encode(protectedHeader);
|
|
235
|
-
const token = [
|
|
236
|
-
parsedProt,
|
|
237
|
-
decodeBase64url(ciphertext, 'ciphertext', JWEInvalid),
|
|
238
|
-
iv ? decodeBase64url(iv, 'iv', JWEInvalid) : undefined,
|
|
239
|
-
tag ? decodeBase64url(tag, 'tag', JWEInvalid) : undefined,
|
|
240
|
-
protectedBytes,
|
|
241
|
-
];
|
|
242
|
-
return decryptRecipientCore(flattened, token, shared, key, parsedProt);
|
|
165
|
+
async function decryptCompact(jwe, shared, key) {
|
|
166
|
+
if (jwe instanceof Uint8Array && (jwe = decoder.decode(jwe)), typeof jwe != "string")
|
|
167
|
+
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
168
|
+
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag, length } = jwe.split(".");
|
|
169
|
+
if (length !== 5)
|
|
170
|
+
throw new JWEInvalid("Invalid Compact JWE");
|
|
171
|
+
return decryptJWE({
|
|
172
|
+
ciphertext,
|
|
173
|
+
iv: iv || void 0,
|
|
174
|
+
protected: protectedHeader,
|
|
175
|
+
tag: tag || void 0,
|
|
176
|
+
encrypted_key: encryptedKey || void 0
|
|
177
|
+
}, shared, key);
|
|
243
178
|
}
|
|
179
|
+
export {
|
|
180
|
+
checkRecipient,
|
|
181
|
+
decryptCompact,
|
|
182
|
+
decryptJWE,
|
|
183
|
+
prepareDecrypt,
|
|
184
|
+
shareJWE,
|
|
185
|
+
snapshotRecipientJWE,
|
|
186
|
+
snapshotSharedJWE
|
|
187
|
+
};
|