inray 0.0.13 → 0.0.14
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/LICENSE.md +1 -1
- package/README.md +1 -1
- package/dist/jose/src/index.d.ts +3 -2
- package/dist/jose/src/index.d.ts.map +1 -1
- package/dist/jose/src/index.js +3 -2
- package/dist/jose/src/index.js.map +1 -1
- package/dist/jose/src/jwe/compact/decrypt.d.ts +14 -10
- package/dist/jose/src/jwe/compact/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/compact/decrypt.js +7 -4
- package/dist/jose/src/jwe/compact/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/compact/encrypt.d.ts +18 -17
- package/dist/jose/src/jwe/compact/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/compact/encrypt.js +27 -29
- package/dist/jose/src/jwe/compact/encrypt.js.map +1 -1
- package/dist/jose/src/jwe/flattened/decrypt.d.ts +14 -12
- package/dist/jose/src/jwe/flattened/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/flattened/decrypt.js +6 -10
- package/dist/jose/src/jwe/flattened/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/flattened/encrypt.d.ts +22 -23
- package/dist/jose/src/jwe/flattened/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/flattened/encrypt.js +66 -43
- package/dist/jose/src/jwe/flattened/encrypt.js.map +1 -1
- package/dist/jose/src/jwe/general/decrypt.d.ts +19 -13
- package/dist/jose/src/jwe/general/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/general/decrypt.js +27 -34
- package/dist/jose/src/jwe/general/decrypt.js.map +1 -1
- package/dist/jose/src/jwe/general/encrypt.d.ts +25 -28
- package/dist/jose/src/jwe/general/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwe/general/encrypt.js +94 -67
- package/dist/jose/src/jwe/general/encrypt.js.map +1 -1
- package/dist/jose/src/jwk/embedded.d.ts +6 -4
- package/dist/jose/src/jwk/embedded.d.ts.map +1 -1
- package/dist/jose/src/jwk/embedded.js +9 -22
- package/dist/jose/src/jwk/embedded.js.map +1 -1
- package/dist/jose/src/jwk/thumbprint.d.ts +9 -7
- package/dist/jose/src/jwk/thumbprint.d.ts.map +1 -1
- package/dist/jose/src/jwk/thumbprint.js +26 -32
- package/dist/jose/src/jwk/thumbprint.js.map +1 -1
- package/dist/jose/src/jwks/local.d.ts +18 -10
- package/dist/jose/src/jwks/local.d.ts.map +1 -1
- package/dist/jose/src/jwks/local.js +92 -90
- package/dist/jose/src/jwks/local.js.map +1 -1
- package/dist/jose/src/jwks/remote.d.ts +43 -39
- package/dist/jose/src/jwks/remote.d.ts.map +1 -1
- package/dist/jose/src/jwks/remote.js +145 -121
- package/dist/jose/src/jwks/remote.js.map +1 -1
- package/dist/jose/src/jws/compact/sign.d.ts +7 -10
- package/dist/jose/src/jws/compact/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/compact/sign.js +16 -16
- package/dist/jose/src/jws/compact/sign.js.map +1 -1
- package/dist/jose/src/jws/compact/verify.d.ts +14 -12
- package/dist/jose/src/jws/compact/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/compact/verify.js +6 -2
- package/dist/jose/src/jws/compact/verify.js.map +1 -1
- package/dist/jose/src/jws/flattened/sign.d.ts +8 -11
- package/dist/jose/src/jws/flattened/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/flattened/sign.js +26 -21
- package/dist/jose/src/jws/flattened/sign.js.map +1 -1
- package/dist/jose/src/jws/flattened/verify.d.ts +14 -13
- package/dist/jose/src/jws/flattened/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/flattened/verify.js +19 -6
- package/dist/jose/src/jws/flattened/verify.js.map +1 -1
- package/dist/jose/src/jws/general/sign.d.ts +18 -19
- package/dist/jose/src/jws/general/sign.d.ts.map +1 -1
- package/dist/jose/src/jws/general/sign.js +24 -21
- package/dist/jose/src/jws/general/sign.js.map +1 -1
- package/dist/jose/src/jws/general/verify.d.ts +20 -17
- package/dist/jose/src/jws/general/verify.d.ts.map +1 -1
- package/dist/jose/src/jws/general/verify.js +28 -48
- package/dist/jose/src/jws/general/verify.js.map +1 -1
- package/dist/jose/src/jwt/decrypt.d.ts +15 -21
- package/dist/jose/src/jwt/decrypt.d.ts.map +1 -1
- package/dist/jose/src/jwt/decrypt.js +18 -15
- package/dist/jose/src/jwt/decrypt.js.map +1 -1
- package/dist/jose/src/jwt/encrypt.d.ts +33 -23
- package/dist/jose/src/jwt/encrypt.d.ts.map +1 -1
- package/dist/jose/src/jwt/encrypt.js +90 -44
- package/dist/jose/src/jwt/encrypt.js.map +1 -1
- package/dist/jose/src/jwt/sign.d.ts +19 -9
- package/dist/jose/src/jwt/sign.d.ts.map +1 -1
- package/dist/jose/src/jwt/sign.js +51 -15
- package/dist/jose/src/jwt/sign.js.map +1 -1
- package/dist/jose/src/jwt/unsecured.d.ts +19 -15
- package/dist/jose/src/jwt/unsecured.d.ts.map +1 -1
- package/dist/jose/src/jwt/unsecured.js +57 -27
- package/dist/jose/src/jwt/unsecured.js.map +1 -1
- package/dist/jose/src/jwt/verify.d.ts +14 -21
- package/dist/jose/src/jwt/verify.d.ts.map +1 -1
- package/dist/jose/src/jwt/verify.js +9 -7
- package/dist/jose/src/jwt/verify.js.map +1 -1
- package/dist/jose/src/key/export.d.ts +7 -7
- package/dist/jose/src/key/export.d.ts.map +1 -1
- package/dist/jose/src/key/export.js +42 -46
- package/dist/jose/src/key/export.js.map +1 -1
- package/dist/jose/src/key/generate_key_pair.d.ts +18 -14
- package/dist/jose/src/key/generate_key_pair.d.ts.map +1 -1
- package/dist/jose/src/key/generate_key_pair.js +18 -17
- package/dist/jose/src/key/generate_key_pair.js.map +1 -1
- package/dist/jose/src/key/generate_secret.d.ts +16 -11
- package/dist/jose/src/key/generate_secret.d.ts.map +1 -1
- package/dist/jose/src/key/generate_secret.js +11 -16
- package/dist/jose/src/key/generate_secret.js.map +1 -1
- package/dist/jose/src/key/import.d.ts +27 -21
- package/dist/jose/src/key/import.d.ts.map +1 -1
- package/dist/jose/src/key/import.js +27 -30
- package/dist/jose/src/key/import.js.map +1 -1
- package/dist/jose/src/lib/asn1.d.ts +1 -1
- package/dist/jose/src/lib/asn1.d.ts.map +1 -1
- package/dist/jose/src/lib/asn1.js +11 -20
- package/dist/jose/src/lib/asn1.js.map +1 -1
- package/dist/jose/src/lib/base64.d.ts +11 -0
- package/dist/jose/src/lib/base64.d.ts.map +1 -0
- package/dist/jose/src/lib/base64.js +36 -0
- package/dist/jose/src/lib/base64.js.map +1 -0
- package/dist/jose/src/lib/buffer_utils.d.ts +1 -4
- package/dist/jose/src/lib/buffer_utils.d.ts.map +1 -1
- package/dist/jose/src/lib/buffer_utils.js +6 -51
- package/dist/jose/src/lib/buffer_utils.js.map +1 -1
- package/dist/jose/src/lib/content_encryption.d.ts +1 -2
- package/dist/jose/src/lib/content_encryption.d.ts.map +1 -1
- package/dist/jose/src/lib/content_encryption.js +76 -63
- package/dist/jose/src/lib/content_encryption.js.map +1 -1
- package/dist/jose/src/lib/crypto_key.d.ts +23 -0
- package/dist/jose/src/lib/crypto_key.d.ts.map +1 -0
- package/dist/jose/src/lib/crypto_key.js +41 -0
- package/dist/jose/src/lib/crypto_key.js.map +1 -0
- package/dist/jose/src/lib/deflate.d.ts +1 -3
- package/dist/jose/src/lib/deflate.d.ts.map +1 -1
- package/dist/jose/src/lib/deflate.js +22 -24
- package/dist/jose/src/lib/deflate.js.map +1 -1
- package/dist/jose/src/lib/helpers.d.ts +20 -0
- package/dist/jose/src/lib/helpers.d.ts.map +1 -0
- package/dist/jose/src/lib/helpers.js +56 -0
- package/dist/jose/src/lib/helpers.js.map +1 -0
- package/dist/jose/src/lib/invalid_key_input.d.ts +11 -0
- package/dist/jose/src/lib/invalid_key_input.d.ts.map +1 -0
- package/dist/jose/src/lib/invalid_key_input.js +35 -0
- package/dist/jose/src/lib/invalid_key_input.js.map +1 -0
- package/dist/jose/src/lib/is_key_like.d.ts +14 -0
- package/dist/jose/src/lib/is_key_like.d.ts.map +1 -0
- package/dist/jose/src/lib/is_key_like.js +29 -0
- package/dist/jose/src/lib/is_key_like.js.map +1 -0
- package/dist/jose/src/lib/jwe_algorithms.d.ts +3 -24
- package/dist/jose/src/lib/jwe_algorithms.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_algorithms.js +6 -22
- package/dist/jose/src/lib/jwe_algorithms.js.map +1 -1
- package/dist/jose/src/lib/jwe_decrypt.d.ts +23 -19
- package/dist/jose/src/lib/jwe_decrypt.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_decrypt.js +106 -179
- package/dist/jose/src/lib/jwe_decrypt.js.map +1 -1
- package/dist/jose/src/lib/jwe_encrypt.d.ts +19 -20
- package/dist/jose/src/lib/jwe_encrypt.d.ts.map +1 -1
- package/dist/jose/src/lib/jwe_encrypt.js +50 -96
- package/dist/jose/src/lib/jwe_encrypt.js.map +1 -1
- package/dist/jose/src/lib/jwk_to_key.d.ts +12 -0
- package/dist/jose/src/lib/jwk_to_key.d.ts.map +1 -0
- package/dist/jose/src/lib/jwk_to_key.js +26 -0
- package/dist/jose/src/lib/jwk_to_key.js.map +1 -0
- package/dist/jose/src/lib/jws_algorithms.d.ts +1 -1
- package/dist/jose/src/lib/jws_algorithms.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_algorithms.js +3 -9
- package/dist/jose/src/lib/jws_algorithms.js.map +1 -1
- package/dist/jose/src/lib/jws_sign.d.ts +11 -13
- package/dist/jose/src/lib/jws_sign.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_sign.js +50 -49
- package/dist/jose/src/lib/jws_sign.js.map +1 -1
- package/dist/jose/src/lib/jws_verify.d.ts +10 -9
- package/dist/jose/src/lib/jws_verify.d.ts.map +1 -1
- package/dist/jose/src/lib/jws_verify.js +66 -105
- package/dist/jose/src/lib/jws_verify.js.map +1 -1
- package/dist/jose/src/lib/jwt_claims_set.d.ts +15 -12
- package/dist/jose/src/lib/jwt_claims_set.d.ts.map +1 -1
- package/dist/jose/src/lib/jwt_claims_set.js +83 -133
- package/dist/jose/src/lib/jwt_claims_set.js.map +1 -1
- package/dist/jose/src/lib/key.d.ts +16 -23
- package/dist/jose/src/lib/key.d.ts.map +1 -1
- package/dist/jose/src/lib/key.js +91 -191
- package/dist/jose/src/lib/key.js.map +1 -1
- package/dist/jose/src/lib/key_algorithm.d.ts +1 -1
- package/dist/jose/src/lib/key_algorithm.js +1 -1
- package/dist/jose/src/lib/key_descriptor.d.ts +6 -7
- package/dist/jose/src/lib/key_descriptor.d.ts.map +1 -1
- package/dist/jose/src/lib/key_descriptor.js +1 -1
- package/dist/jose/src/lib/key_descriptor.js.map +1 -1
- package/dist/jose/src/lib/key_management.d.ts +4 -5
- package/dist/jose/src/lib/key_management.d.ts.map +1 -1
- package/dist/jose/src/lib/key_management.js +131 -153
- package/dist/jose/src/lib/key_management.js.map +1 -1
- package/dist/jose/src/lib/options.d.ts +30 -0
- package/dist/jose/src/lib/options.d.ts.map +1 -0
- package/dist/jose/src/lib/options.js +64 -0
- package/dist/jose/src/lib/options.js.map +1 -0
- package/dist/jose/src/lib/signing.d.ts +13 -0
- package/dist/jose/src/lib/signing.d.ts.map +1 -0
- package/dist/jose/src/lib/signing.js +35 -0
- package/dist/jose/src/lib/signing.js.map +1 -0
- package/dist/jose/src/lib/type_checks.d.ts +24 -0
- package/dist/jose/src/lib/type_checks.d.ts.map +1 -0
- package/dist/jose/src/lib/type_checks.js +44 -0
- package/dist/jose/src/lib/type_checks.js.map +1 -0
- package/dist/jose/src/util/base64url.d.ts +8 -8
- package/dist/jose/src/util/base64url.d.ts.map +1 -1
- package/dist/jose/src/util/base64url.js +45 -17
- package/dist/jose/src/util/base64url.js.map +1 -1
- package/dist/jose/src/util/decode_jwt.d.ts +6 -11
- package/dist/jose/src/util/decode_jwt.d.ts.map +1 -1
- package/dist/jose/src/util/decode_jwt.js +35 -16
- package/dist/jose/src/util/decode_jwt.js.map +1 -1
- package/dist/jose/src/util/decode_protected_header.d.ts +4 -6
- package/dist/jose/src/util/decode_protected_header.d.ts.map +1 -1
- package/dist/jose/src/util/decode_protected_header.js +10 -14
- package/dist/jose/src/util/decode_protected_header.js.map +1 -1
- package/dist/jose/src/util/errors.d.ts +61 -59
- package/dist/jose/src/util/errors.d.ts.map +1 -1
- package/dist/jose/src/util/errors.js +37 -33
- package/dist/jose/src/util/errors.js.map +1 -1
- package/dist/media_types/_db.d.ts +1 -1
- package/package.json +1 -1
- package/dist/jose/src/lib/validate.d.ts +0 -53
- package/dist/jose/src/lib/validate.d.ts.map +0 -1
- package/dist/jose/src/lib/validate.js +0 -166
- package/dist/jose/src/lib/validate.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/***/
|
|
9
9
|
import type * as types from '../../types.d.ts';
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* The FlattenedEncrypt class is used to build and encrypt Flattened JWE objects.
|
|
12
12
|
*
|
|
13
13
|
* This class is exported (as a named export) from the main `'jose'` module entry point as well as
|
|
14
14
|
* from its subpath export `'jose/jwe/flattened/encrypt'`.
|
|
@@ -29,69 +29,68 @@ import type * as types from '../../types.d.ts';
|
|
|
29
29
|
export declare class FlattenedEncrypt {
|
|
30
30
|
#private;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* {@link FlattenedEncrypt} constructor
|
|
33
33
|
*
|
|
34
34
|
* @param plaintext Binary representation of the plaintext to encrypt.
|
|
35
35
|
*/
|
|
36
36
|
constructor(plaintext: Uint8Array);
|
|
37
37
|
/**
|
|
38
|
-
* Sets
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Sets the JWE Key Management parameters to be used when encrypting. Use this method instead of
|
|
39
|
+
* the header setters to configure algorithm inputs such as ECDH-ES "apu" (Agreement PartyUInfo)
|
|
40
|
+
* and "apv" (Agreement PartyVInfo), or PBES2 "p2c" (PBES2 Count). The parameters are added to the
|
|
41
|
+
* appropriate JOSE Header.
|
|
41
42
|
*
|
|
42
43
|
* @param parameters JWE Key Management parameters.
|
|
43
44
|
*/
|
|
44
45
|
setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): this;
|
|
45
46
|
/**
|
|
46
|
-
* Sets the JWE Protected Header
|
|
47
|
+
* Sets the JWE Protected Header on the FlattenedEncrypt object.
|
|
47
48
|
*
|
|
48
49
|
* @param protectedHeader JWE Protected Header.
|
|
49
50
|
*/
|
|
50
51
|
setProtectedHeader(protectedHeader: types.JWEHeaderParameters): this;
|
|
51
52
|
/**
|
|
52
|
-
* Sets the JWE Shared Unprotected Header
|
|
53
|
+
* Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.
|
|
53
54
|
*
|
|
54
55
|
* @param sharedUnprotectedHeader JWE Shared Unprotected Header.
|
|
55
56
|
*/
|
|
56
57
|
setSharedUnprotectedHeader(sharedUnprotectedHeader: types.JWEHeaderParameters): this;
|
|
57
58
|
/**
|
|
58
|
-
* Sets the JWE Per-Recipient Unprotected Header
|
|
59
|
+
* Sets the JWE Per-Recipient Unprotected Header on the FlattenedEncrypt object.
|
|
59
60
|
*
|
|
60
61
|
* @param unprotectedHeader JWE Per-Recipient Unprotected Header.
|
|
61
62
|
*/
|
|
62
63
|
setUnprotectedHeader(unprotectedHeader: types.JWEHeaderParameters): this;
|
|
63
64
|
/**
|
|
64
|
-
* Sets the
|
|
65
|
+
* Sets the Additional Authenticated Data on the FlattenedEncrypt object.
|
|
65
66
|
*
|
|
66
|
-
*
|
|
67
|
-
* Authenticated Data encryption parameter. See
|
|
68
|
-
* {@link https://www.ietf.org/archive/id/draft-ietf-jose-hpke-encrypt-22.html#section-7.1 draft-ietf-jose-hpke-encrypt-22, Section 7.1, step 15}.
|
|
69
|
-
*
|
|
70
|
-
* @param aad JWE Additional Authenticated Data (JWE AAD).
|
|
67
|
+
* @param aad Additional Authenticated Data.
|
|
71
68
|
*/
|
|
72
69
|
setAdditionalAuthenticatedData(aad: Uint8Array): this;
|
|
73
70
|
/**
|
|
74
|
-
* Sets a content encryption key
|
|
75
|
-
*
|
|
71
|
+
* Sets a content encryption key to use, by default a random suitable one is generated for the JWE
|
|
72
|
+
* "enc" (Encryption Algorithm) Header Parameter.
|
|
76
73
|
*
|
|
77
|
-
* @deprecated
|
|
74
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
75
|
+
* validation purposes.
|
|
78
76
|
*
|
|
79
77
|
* @param cek JWE Content Encryption Key.
|
|
80
78
|
*/
|
|
81
79
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
82
80
|
/**
|
|
83
|
-
* Sets the
|
|
84
|
-
*
|
|
81
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
|
|
82
|
+
* one is generated for the JWE "enc" (Encryption Algorithm) Header Parameter.
|
|
85
83
|
*
|
|
86
|
-
* @deprecated
|
|
84
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
85
|
+
* validation purposes.
|
|
87
86
|
*
|
|
88
87
|
* @param iv JWE Initialization Vector.
|
|
89
88
|
*/
|
|
90
89
|
setInitializationVector(iv: Uint8Array): this;
|
|
91
90
|
/**
|
|
92
|
-
* Encrypts the
|
|
91
|
+
* Encrypts and resolves the value of the Flattened JWE object.
|
|
93
92
|
*
|
|
94
|
-
* @param key Public
|
|
93
|
+
* @param key Public Key or Secret to encrypt the JWE with. See
|
|
95
94
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
96
95
|
* @param options JWE Encryption options.
|
|
97
96
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/flattened/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/flattened/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AASL,OAAO,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAK9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAgB;;IAiB3B;;;;OAIG;gBACS,SAAS,EAAE,UAAU;IAOjC;;;;;;;OAOG;IACH,0BAA0B,CAAC,UAAU,EAAE,KAAK,CAAC,gCAAgC,GAAG,IAAI;IAMpF;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,KAAK,CAAC,mBAAmB,GAAG,IAAI;IAMpE;;;;OAIG;IACH,0BAA0B,CAAC,uBAAuB,EAAE,KAAK,CAAC,mBAAmB,GAAG,IAAI;IAMpF;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,GAAG,IAAI;IAMxE;;;;OAIG;IACH,8BAA8B,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAKrD;;;;;;;;OAQG;IACH,uBAAuB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAM9C;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI;IAM7C;;;;;;OAMG;IACG,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC;CAyBhG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* Encrypting JSON Web Encryption (JWE) in Flattened JSON Serialization
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
|
-
*
|
|
14
|
-
* @see {@link https://www.rfc-editor.org/info/rfc7516/#section-7.2.2 RFC 7516, Section 7.2.2}
|
|
15
13
|
*/
|
|
16
|
-
import {
|
|
14
|
+
import { unprotected, assertNotSet } from '../../lib/helpers.js';
|
|
15
|
+
import { JWEInvalid } from '../../util/errors.js';
|
|
17
16
|
import { createJWE } from '../../lib/jwe_encrypt.js';
|
|
17
|
+
import { validateCritDuplicates } from '../../lib/options.js';
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* The FlattenedEncrypt class is used to build and encrypt Flattened JWE objects.
|
|
20
20
|
*
|
|
21
21
|
* This class is exported (as a named export) from the main `'jose'` module entry point as well as
|
|
22
22
|
* from its subpath export `'jose/jwe/flattened/encrypt'`.
|
|
@@ -35,106 +35,129 @@ import { createJWE } from '../../lib/jwe_encrypt.js';
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export class FlattenedEncrypt {
|
|
38
|
-
#
|
|
38
|
+
#plaintext;
|
|
39
|
+
#protectedHeader;
|
|
40
|
+
#sharedUnprotectedHeader;
|
|
41
|
+
#unprotectedHeader;
|
|
42
|
+
#aad;
|
|
43
|
+
#cek;
|
|
44
|
+
#iv;
|
|
45
|
+
#keyManagementParameters;
|
|
39
46
|
/**
|
|
40
|
-
*
|
|
47
|
+
* {@link FlattenedEncrypt} constructor
|
|
41
48
|
*
|
|
42
49
|
* @param plaintext Binary representation of the plaintext to encrypt.
|
|
43
50
|
*/
|
|
44
51
|
constructor(plaintext) {
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
53
|
+
throw new TypeError('plaintext must be an instance of Uint8Array');
|
|
54
|
+
}
|
|
55
|
+
this.#plaintext = plaintext;
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
49
|
-
* Sets
|
|
50
|
-
*
|
|
51
|
-
*
|
|
58
|
+
* Sets the JWE Key Management parameters to be used when encrypting. Use this method instead of
|
|
59
|
+
* the header setters to configure algorithm inputs such as ECDH-ES "apu" (Agreement PartyUInfo)
|
|
60
|
+
* and "apv" (Agreement PartyVInfo), or PBES2 "p2c" (PBES2 Count). The parameters are added to the
|
|
61
|
+
* appropriate JOSE Header.
|
|
52
62
|
*
|
|
53
63
|
* @param parameters JWE Key Management parameters.
|
|
54
64
|
*/
|
|
55
65
|
setKeyManagementParameters(parameters) {
|
|
56
|
-
assertNotSet(this.#
|
|
57
|
-
this.#
|
|
66
|
+
assertNotSet(this.#keyManagementParameters, 'setKeyManagementParameters');
|
|
67
|
+
this.#keyManagementParameters = parameters;
|
|
58
68
|
return this;
|
|
59
69
|
}
|
|
60
70
|
/**
|
|
61
|
-
* Sets the JWE Protected Header
|
|
71
|
+
* Sets the JWE Protected Header on the FlattenedEncrypt object.
|
|
62
72
|
*
|
|
63
73
|
* @param protectedHeader JWE Protected Header.
|
|
64
74
|
*/
|
|
65
75
|
setProtectedHeader(protectedHeader) {
|
|
66
|
-
assertNotSet(this.#
|
|
67
|
-
this.#
|
|
76
|
+
assertNotSet(this.#protectedHeader, 'setProtectedHeader');
|
|
77
|
+
this.#protectedHeader = protectedHeader;
|
|
68
78
|
return this;
|
|
69
79
|
}
|
|
70
80
|
/**
|
|
71
|
-
* Sets the JWE Shared Unprotected Header
|
|
81
|
+
* Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.
|
|
72
82
|
*
|
|
73
83
|
* @param sharedUnprotectedHeader JWE Shared Unprotected Header.
|
|
74
84
|
*/
|
|
75
85
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
76
|
-
assertNotSet(this.#
|
|
77
|
-
this.#
|
|
86
|
+
assertNotSet(this.#sharedUnprotectedHeader, 'setSharedUnprotectedHeader');
|
|
87
|
+
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
78
88
|
return this;
|
|
79
89
|
}
|
|
80
90
|
/**
|
|
81
|
-
* Sets the JWE Per-Recipient Unprotected Header
|
|
91
|
+
* Sets the JWE Per-Recipient Unprotected Header on the FlattenedEncrypt object.
|
|
82
92
|
*
|
|
83
93
|
* @param unprotectedHeader JWE Per-Recipient Unprotected Header.
|
|
84
94
|
*/
|
|
85
95
|
setUnprotectedHeader(unprotectedHeader) {
|
|
86
|
-
assertNotSet(this.#
|
|
87
|
-
this.#
|
|
96
|
+
assertNotSet(this.#unprotectedHeader, 'setUnprotectedHeader');
|
|
97
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
88
98
|
return this;
|
|
89
99
|
}
|
|
90
100
|
/**
|
|
91
|
-
* Sets the
|
|
92
|
-
*
|
|
93
|
-
* Its base64url encoding is combined with the Encoded Protected Header to form the Additional
|
|
94
|
-
* Authenticated Data encryption parameter. See
|
|
95
|
-
* {@link https://www.ietf.org/archive/id/draft-ietf-jose-hpke-encrypt-22.html#section-7.1 draft-ietf-jose-hpke-encrypt-22, Section 7.1, step 15}.
|
|
101
|
+
* Sets the Additional Authenticated Data on the FlattenedEncrypt object.
|
|
96
102
|
*
|
|
97
|
-
* @param aad
|
|
103
|
+
* @param aad Additional Authenticated Data.
|
|
98
104
|
*/
|
|
99
105
|
setAdditionalAuthenticatedData(aad) {
|
|
100
|
-
this.#
|
|
106
|
+
this.#aad = aad;
|
|
101
107
|
return this;
|
|
102
108
|
}
|
|
103
109
|
/**
|
|
104
|
-
* Sets a content encryption key
|
|
105
|
-
*
|
|
110
|
+
* Sets a content encryption key to use, by default a random suitable one is generated for the JWE
|
|
111
|
+
* "enc" (Encryption Algorithm) Header Parameter.
|
|
106
112
|
*
|
|
107
|
-
* @deprecated
|
|
113
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
114
|
+
* validation purposes.
|
|
108
115
|
*
|
|
109
116
|
* @param cek JWE Content Encryption Key.
|
|
110
117
|
*/
|
|
111
118
|
setContentEncryptionKey(cek) {
|
|
112
|
-
assertNotSet(this.#
|
|
113
|
-
this.#
|
|
119
|
+
assertNotSet(this.#cek, 'setContentEncryptionKey');
|
|
120
|
+
this.#cek = cek;
|
|
114
121
|
return this;
|
|
115
122
|
}
|
|
116
123
|
/**
|
|
117
|
-
* Sets the
|
|
118
|
-
*
|
|
124
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
|
|
125
|
+
* one is generated for the JWE "enc" (Encryption Algorithm) Header Parameter.
|
|
119
126
|
*
|
|
120
|
-
* @deprecated
|
|
127
|
+
* @deprecated You should not use this method. It is only really intended for test and vector
|
|
128
|
+
* validation purposes.
|
|
121
129
|
*
|
|
122
130
|
* @param iv JWE Initialization Vector.
|
|
123
131
|
*/
|
|
124
132
|
setInitializationVector(iv) {
|
|
125
|
-
assertNotSet(this.#
|
|
126
|
-
this.#
|
|
133
|
+
assertNotSet(this.#iv, 'setInitializationVector');
|
|
134
|
+
this.#iv = iv;
|
|
127
135
|
return this;
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
|
-
* Encrypts the
|
|
138
|
+
* Encrypts and resolves the value of the Flattened JWE object.
|
|
131
139
|
*
|
|
132
|
-
* @param key Public
|
|
140
|
+
* @param key Public Key or Secret to encrypt the JWE with. See
|
|
133
141
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
134
142
|
* @param options JWE Encryption options.
|
|
135
143
|
*/
|
|
136
144
|
async encrypt(key, options) {
|
|
137
|
-
|
|
145
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
146
|
+
throw new JWEInvalid('either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()');
|
|
147
|
+
}
|
|
148
|
+
validateCritDuplicates(JWEInvalid, this.#protectedHeader);
|
|
149
|
+
return createJWE([
|
|
150
|
+
this.#plaintext,
|
|
151
|
+
this.#protectedHeader,
|
|
152
|
+
this.#unprotectedHeader,
|
|
153
|
+
this.#sharedUnprotectedHeader,
|
|
154
|
+
this.#aad,
|
|
155
|
+
this.#cek,
|
|
156
|
+
this.#iv,
|
|
157
|
+
this.#keyManagementParameters,
|
|
158
|
+
options?.crit,
|
|
159
|
+
options ? unprotected in options : false,
|
|
160
|
+
], key);
|
|
138
161
|
}
|
|
139
162
|
}
|
|
140
163
|
//# sourceMappingURL=encrypt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/flattened/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL
|
|
1
|
+
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/flattened/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,UAAU,CAAY;IAEtB,gBAAgB,CAAwC;IAExD,wBAAwB,CAAwC;IAEhE,kBAAkB,CAAwC;IAE1D,IAAI,CAAyB;IAE7B,IAAI,CAAyB;IAE7B,GAAG,CAAyB;IAE5B,wBAAwB,CAAyC;IAEjE;;;;OAIG;IACH,YAAY,SAAqB;QAC/B,IAAI,CAAC,CAAC,SAAS,YAAY,UAAU,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,0BAA0B,CAAC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K,CAAC,OAAO,CAAC,GAAmB,EAAE,OAA8B;QAC/D,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACzF,MAAM,IAAI,UAAU,CAClB,8GAA8G,CAC/G,CAAA;QACH,CAAC;QAED,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAEzD,OAAO,SAAS,CACd;YACE,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,gBAAgB;YACrB,IAAI,CAAC,kBAAkB;YACvB,IAAI,CAAC,wBAAwB;YAC7B,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,GAAG;YACR,IAAI,CAAC,wBAAwB;YAC7B,OAAO,EAAE,IAAI;YACb,OAAO,CAAC,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK;SACzC,EACD,GAAG,CACJ,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Original library: jose (v6.2.
|
|
2
|
+
* Original library: jose (v6.2.9)
|
|
3
3
|
* - Copyright (c) 2018 Filip Skokan
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
/***/
|
|
9
9
|
import type * as types from '../../types.d.ts';
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Interface for General JWE Decryption dynamic key resolution. No token components have been
|
|
12
|
+
* verified at the time of this function call.
|
|
12
13
|
*
|
|
13
14
|
* @typeParam KeyType Type definition of the keys the function resolves. Narrowing it is what lets
|
|
14
15
|
* {@link types.ResolvedKey.key ResolvedKey.key} be inferred at the call site.
|
|
@@ -16,15 +17,17 @@ import type * as types from '../../types.d.ts';
|
|
|
16
17
|
export interface GeneralDecryptGetKey<KeyType extends types.CryptoKey | Uint8Array = types.CryptoKey | Uint8Array> extends types.GetKeyFunction<types.JWEHeaderParameters | undefined, types.FlattenedJWE, KeyType | types.KeyObject | types.JWK> {
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Decrypts a General JWE.
|
|
20
21
|
*
|
|
21
22
|
* This function is exported (as a named export) from the main `'jose'` module entry point as well
|
|
22
23
|
* as from its subpath export `'jose/jwe/general/decrypt'`.
|
|
23
24
|
*
|
|
24
25
|
* > [!NOTE]\
|
|
25
|
-
* >
|
|
26
|
-
* >
|
|
27
|
-
* > the
|
|
26
|
+
* > The function iterates over the `recipients` array in the General JWE and returns the decryption
|
|
27
|
+
* > result of the first recipient entry that can be successfully decrypted. The result only contains
|
|
28
|
+
* > the plaintext and headers of that successfully decrypted recipient entry. Other recipient entries
|
|
29
|
+
* > in the General JWE are not validated, and their headers are not included in the returned result.
|
|
30
|
+
* > Recipients of a General JWE should only rely on the returned (decrypted) data.
|
|
28
31
|
*
|
|
29
32
|
* @example
|
|
30
33
|
*
|
|
@@ -53,26 +56,29 @@ export interface GeneralDecryptGetKey<KeyType extends types.CryptoKey | Uint8Arr
|
|
|
53
56
|
* ```
|
|
54
57
|
*
|
|
55
58
|
* @param jwe General JWE.
|
|
56
|
-
* @param key Private
|
|
59
|
+
* @param key Private Key or Secret to decrypt the JWE with. See
|
|
57
60
|
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
58
61
|
* @param options JWE Decryption options.
|
|
59
62
|
*/
|
|
60
63
|
export declare function generalDecrypt(jwe: types.GeneralJWE, key: types.KeyInput, options?: types.DecryptOptions): Promise<types.GeneralDecryptResult>;
|
|
61
64
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
65
|
+
* Decrypts a General JWE, resolving the key dynamically. The result additionally carries the
|
|
66
|
+
* {@link types.ResolvedKey.key resolved key}.
|
|
64
67
|
*
|
|
65
68
|
* @param jwe General JWE.
|
|
66
|
-
* @param getKey
|
|
69
|
+
* @param getKey Function resolving Private Key or Secret to decrypt the JWE with. See
|
|
70
|
+
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
67
71
|
* @param options JWE Decryption options.
|
|
68
72
|
*/
|
|
69
73
|
export declare function generalDecrypt<KeyType extends types.CryptoKey | Uint8Array = types.CryptoKey | Uint8Array>(jwe: types.GeneralJWE, getKey: GeneralDecryptGetKey<KeyType>, options?: types.DecryptOptions): Promise<types.GeneralDecryptResult & types.ResolvedKey<KeyType>>;
|
|
70
74
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
75
|
+
* Accepts either form of the `key` argument. Use this overload when forwarding a value that may be
|
|
76
|
+
* either a key or a key resolution function; `key` is present on the result only when a resolution
|
|
77
|
+
* function was used.
|
|
73
78
|
*
|
|
74
79
|
* @param jwe General JWE.
|
|
75
|
-
* @param key Private
|
|
80
|
+
* @param key Private Key or Secret, or a function resolving one, to decrypt the JWE with. See
|
|
81
|
+
* {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
|
|
76
82
|
* @param options JWE Decryption options.
|
|
77
83
|
*/
|
|
78
84
|
export declare function generalDecrypt(jwe: types.GeneralJWE, key: types.KeyInput | GeneralDecryptGetKey, options?: types.DecryptOptions): Promise<types.GeneralDecryptResult & Partial<types.ResolvedKey>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/general/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;
|
|
1
|
+
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/general/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAkBL,OAAO,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAG9C;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB,CACnC,OAAO,SAAS,KAA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an
|
|
4
4
|
*
|
|
5
5
|
* Modified and integrated in "Inray":
|
|
@@ -10,63 +10,56 @@
|
|
|
10
10
|
* Decrypting JSON Web Encryption (JWE) in General JSON Serialization
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
|
-
*
|
|
14
|
-
* @see {@link https://www.rfc-editor.org/info/rfc7516/#section-7.2.1 RFC 7516, Section 7.2.1}
|
|
15
13
|
*/
|
|
16
|
-
import { prepareDecrypt, shareJWE,
|
|
14
|
+
import { prepareDecrypt, shareJWE, decryptRecipient, decryptResult, checkShared, checkRecipient, } from '../../lib/jwe_decrypt.js';
|
|
17
15
|
import { JWEDecryptionFailed, JWEInvalid } from '../../util/errors.js';
|
|
18
|
-
import { isObject } from '../../lib/
|
|
19
|
-
import { JWE, isJWECEKTransport } from '../../lib/jwe_algorithms.js';
|
|
16
|
+
import { isObject } from '../../lib/type_checks.js';
|
|
20
17
|
export async function generalDecrypt(jwe, key, options) {
|
|
21
18
|
if (!isObject(jwe)) {
|
|
22
19
|
throw new JWEInvalid('General JWE must be an object');
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
if (!Array.isArray(inputRecipients)) {
|
|
26
|
-
throw new JWEInvalid('JWE Recipients missing or incorrect type');
|
|
27
|
-
}
|
|
28
|
-
const recipients = Array.from(inputRecipients);
|
|
29
|
-
if (!recipients.every(isObject)) {
|
|
21
|
+
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
|
|
30
22
|
throw new JWEInvalid('JWE Recipients missing or incorrect type');
|
|
31
23
|
}
|
|
32
|
-
if (!recipients.length) {
|
|
24
|
+
if (!jwe.recipients.length) {
|
|
33
25
|
throw new JWEInvalid('JWE Recipients has no members');
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
let sharedJwe;
|
|
27
|
+
let shared;
|
|
37
28
|
let token;
|
|
38
29
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
checkShared(jwe);
|
|
31
|
+
shared = prepareDecrypt(options);
|
|
32
|
+
token = shareJWE(jwe);
|
|
41
33
|
}
|
|
42
34
|
catch {
|
|
43
35
|
// A fault in a shared member is a fault of the token, but reporting it as such would tell a
|
|
44
36
|
// caller which recipient - if any - their key was meant for. Stay indistinguishable.
|
|
45
37
|
throw new JWEDecryptionFailed();
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
for (const [, headerAlg] of recipientSnapshots) {
|
|
54
|
-
const alg = token[0]?.alg ?? headerAlg ?? sharedJwe.unprotected?.alg;
|
|
55
|
-
const algEntry = typeof alg === 'string' ? JWE[alg] : undefined;
|
|
56
|
-
if (algEntry && !isJWECEKTransport(algEntry)) {
|
|
39
|
+
if (jwe.recipients.length > 1) {
|
|
40
|
+
for (const { header } of jwe.recipients) {
|
|
41
|
+
// https://www.rfc-editor.org/rfc/rfc7516#section-5.2 step 7 - these modes have no
|
|
42
|
+
// per-recipient JWE Encrypted Key, so more than one recipient cannot be addressed.
|
|
43
|
+
const alg = token[0]?.alg ?? header?.alg ?? jwe.unprotected?.alg;
|
|
44
|
+
if (alg === 'dir' || alg === 'ECDH-ES') {
|
|
57
45
|
throw new JWEInvalid(`"${alg}" alg may only have a single recipient`);
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
// succeed. This API returns the first success, which is a library selection policy.
|
|
63
|
-
for (const [recipient] of recipientSnapshots) {
|
|
64
|
-
if (!recipient)
|
|
65
|
-
continue;
|
|
49
|
+
for (const recipient of jwe.recipients) {
|
|
66
50
|
try {
|
|
67
|
-
const flattened = {
|
|
51
|
+
const flattened = {
|
|
52
|
+
aad: jwe.aad,
|
|
53
|
+
ciphertext: jwe.ciphertext,
|
|
54
|
+
encrypted_key: recipient.encrypted_key,
|
|
55
|
+
header: recipient.header,
|
|
56
|
+
iv: jwe.iv,
|
|
57
|
+
protected: jwe.protected,
|
|
58
|
+
tag: jwe.tag,
|
|
59
|
+
unprotected: jwe.unprotected,
|
|
60
|
+
};
|
|
68
61
|
checkRecipient(flattened);
|
|
69
|
-
return await
|
|
62
|
+
return decryptResult(flattened, await decryptRecipient(flattened, token, shared, key));
|
|
70
63
|
}
|
|
71
64
|
catch {
|
|
72
65
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/general/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL
|
|
1
|
+
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../../../src/jose/src/jwe/general/decrypt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL;;;;GAIG;AAEH,OAAO,EACL,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAiGnD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAqB,EACrB,GAA0C,EAC1C,OAA8B;IAE9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAA;IACvD,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,UAAU,CAAC,0CAA0C,CAAC,CAAA;IAClE,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAA;IACvD,CAAC;I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