unjwt 0.5.9 → 0.5.11
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 +3 -3
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +2 -3
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +2 -3
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +2 -3
- package/dist/jws.mjs +4 -4
- package/dist/shared/{unjwt.8w7jp2aw.d.mts → unjwt.BvhKNVNR.d.mts} +28 -30
- package/dist/shared/{unjwt.D9da8HQF.d.mts → unjwt.CN1C8TlR.d.mts} +90 -15
- package/dist/shared/{unjwt.Ca03jPX3.mjs → unjwt.C_D0RMCp.mjs} +1 -1
- package/dist/shared/unjwt.Ce8yMcp_.mjs +298 -0
- package/dist/shared/{unjwt.DH1p_WL8.d.mts → unjwt.Cz90HQhy.d.mts} +11 -12
- package/dist/shared/{unjwt.B2olxeGL.mjs → unjwt.DVMpKj8x.mjs} +22 -86
- package/dist/shared/unjwt.D_JFPtpW.mjs +161 -0
- package/dist/shared/{unjwt.DRUXIabl.mjs → unjwt.DuBBF25X.mjs} +19 -8
- package/dist/shared/{unjwt.D_Mabhgz.d.mts → unjwt.QRureeXk.d.mts} +14 -70
- package/dist/shared/unjwt.df8yQ5_5.d.mts +128 -0
- package/dist/utils.d.mts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +12 -11
- package/dist/shared/unjwt.BHpknTpg.mjs +0 -93
- package/dist/shared/unjwt.BvIkEGGz.d.mts +0 -52
- package/dist/shared/unjwt.CbvzYE-m.d.mts +0 -58
- package/dist/shared/unjwt.wHjOCapq.mjs +0 -279
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ Creates a JWS token.
|
|
|
111
111
|
- `key`: The signing key (`CryptoKey`, `JWK`, or `Uint8Array` for symmetric keys).
|
|
112
112
|
- `options`:
|
|
113
113
|
- `alg`: (Required) The JWS algorithm (e.g., `"HS256"`, `"RS256"`, `"ES256"`, `"PS256"`).
|
|
114
|
-
- `protectedHeader`: An object for additional JWS Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `b64`). If `payload` is an object and `typ` is not set, it defaults to `"
|
|
114
|
+
- `protectedHeader`: An object for additional JWS Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `b64`). If `payload` is an object and `typ` is not set, it defaults to `"at+jwt"`. The `b64` parameter ([RFC7797 section-3](https://datatracker.ietf.org/doc/html/rfc7797#section-3)) controls payload encoding (defaults to `true`, meaning Base64URL encoded).
|
|
115
115
|
- `expiresIn`: Sets an expiration time in seconds (e.g., `3600` for 1 hour). If `iat` is missing it will be set to the current time. If `exp` is missing it will be set to `iat + expiresIn`. This is only applied if `payload` is a JWT.
|
|
116
116
|
- `currentDate`: The current date for computing `expiresIn` option. Defaults to `new Date()`.
|
|
117
117
|
|
|
@@ -170,7 +170,7 @@ const secret = "supersecretkey";
|
|
|
170
170
|
|
|
171
171
|
const { payload, protectedHeader } = await verify(token, secret);
|
|
172
172
|
console.log(payload); // { message: "My important data" }
|
|
173
|
-
console.log(protectedHeader); // { alg: "HS256", typ: "
|
|
173
|
+
console.log(protectedHeader); // { alg: "HS256", typ: "at+jwt" }
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
**Example (RS256 with key lookup):**
|
|
@@ -210,7 +210,7 @@ Encrypts data to produce a JWE token.
|
|
|
210
210
|
- `options`:
|
|
211
211
|
- `alg`: (Required) The JWE Key Management algorithm (e.g., `"A128KW"`, `"RSA-OAEP-256"`, `"PBES2-HS256+A128KW"`, `"ECDH-ES+A128KW"`), defaults depends on the key provided.
|
|
212
212
|
- `enc`: (Required) The JWE Content Encryption algorithm (e.g., `"A128GCM"`, `"A256CBC-HS512"`), defaults depends on the key provided.
|
|
213
|
-
- `protectedHeader`: An object for JWE Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `apu`, `apv`, `p2s`, `p2c`). If `payload` is an object and `typ` is not set, it defaults to `"
|
|
213
|
+
- `protectedHeader`: An object for JWE Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `apu`, `apv`, `p2s`, `p2c`). If `payload` is an object and `typ` is not set, it defaults to `"at+jwt"`.
|
|
214
214
|
- `cek`: (Optional) Provide your own Content Encryption Key (`CryptoKey` or `Uint8Array`).
|
|
215
215
|
- `contentEncryptionIV`: (Optional) Provide your own Initialization Vector for content encryption (`Uint8Array`).
|
|
216
216
|
- Other algorithm-specific options like `p2s`, `p2c` (for PBES2), `keyManagementIV`, `ecdhPartyUInfo`, `ecdhPartyVInfo`.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { j as jwk } from './shared/unjwt.DH1p_WL8.mjs';
|
|
1
|
+
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, L as JWT, M as JWTClaimValidationOptions, I as JWTClaims, H as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.QRureeXk.mjs';
|
|
3
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.BvhKNVNR.mjs';
|
|
4
|
+
export { i as utils } from './shared/unjwt.df8yQ5_5.mjs';
|
|
5
|
+
export { j as jwk } from './shared/unjwt.Cz90HQhy.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { i as utils } from './shared/unjwt.
|
|
2
|
-
export { j as jwe } from './shared/unjwt.
|
|
3
|
-
export { j as jwk } from './shared/unjwt.
|
|
4
|
-
export { j as jws } from './shared/unjwt.
|
|
5
|
-
import './shared/unjwt.
|
|
1
|
+
export { i as utils } from './shared/unjwt.Ce8yMcp_.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.DVMpKj8x.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.DuBBF25X.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.D_JFPtpW.mjs';
|
|
5
|
+
import './shared/unjwt.C_D0RMCp.mjs';
|
package/dist/jwe.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
|
|
3
|
-
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.8w7jp2aw.mjs';
|
|
1
|
+
import './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.BvhKNVNR.mjs';
|
package/dist/jwe.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
export { d as decrypt, e as encrypt } from './shared/unjwt.
|
|
4
|
-
import './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.DuBBF25X.mjs';
|
|
2
|
+
import './shared/unjwt.Ce8yMcp_.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.DVMpKj8x.mjs';
|
|
4
|
+
import './shared/unjwt.C_D0RMCp.mjs';
|
package/dist/jwk.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.
|
|
2
|
-
|
|
3
|
-
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.DH1p_WL8.mjs';
|
|
1
|
+
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.Cz90HQhy.mjs';
|
package/dist/jwk.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.Ce8yMcp_.mjs';
|
|
2
|
+
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.DuBBF25X.mjs';
|
package/dist/jws.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
|
|
3
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.D_Mabhgz.mjs';
|
|
1
|
+
import './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.QRureeXk.mjs';
|
package/dist/jws.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
import './shared/unjwt.
|
|
4
|
-
export { s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.DuBBF25X.mjs';
|
|
2
|
+
import './shared/unjwt.Ce8yMcp_.mjs';
|
|
3
|
+
import './shared/unjwt.C_D0RMCp.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.D_JFPtpW.mjs';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BvIkEGGz.mjs';
|
|
1
|
+
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, H as JoseHeaderParameters, f as JWK_EC_Public, m as JWK, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
|
|
3
2
|
|
|
4
3
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
5
4
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -44,8 +43,8 @@ interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
|
44
43
|
}
|
|
45
44
|
/** Recognized JWE Key Management-related Header Parameters. */
|
|
46
45
|
interface JWEKeyManagementHeaderParameters {
|
|
47
|
-
apu?: Uint8Array
|
|
48
|
-
apv?: Uint8Array
|
|
46
|
+
apu?: Uint8Array<ArrayBuffer>;
|
|
47
|
+
apv?: Uint8Array<ArrayBuffer>;
|
|
49
48
|
/**
|
|
50
49
|
* For Internal use only
|
|
51
50
|
*/
|
|
@@ -53,11 +52,11 @@ interface JWEKeyManagementHeaderParameters {
|
|
|
53
52
|
/**
|
|
54
53
|
* For Internal use only
|
|
55
54
|
*/
|
|
56
|
-
p2s?: Uint8Array
|
|
55
|
+
p2s?: Uint8Array<ArrayBuffer>;
|
|
57
56
|
/**
|
|
58
57
|
* For Internal use only
|
|
59
58
|
*/
|
|
60
|
-
iv?: Uint8Array
|
|
59
|
+
iv?: Uint8Array<ArrayBuffer>;
|
|
61
60
|
/**
|
|
62
61
|
* For Internal use only
|
|
63
62
|
*/
|
|
@@ -71,48 +70,47 @@ interface JWEEncryptOptions {
|
|
|
71
70
|
alg?: KeyManagementAlgorithm;
|
|
72
71
|
/** JWE "enc" (Encryption Algorithm) Header Parameter. Content Encryption Algorithm. */
|
|
73
72
|
enc?: ContentEncryptionAlgorithm;
|
|
73
|
+
/** Date to use when computing NumericDate claims, defaults to `new Date()`. */
|
|
74
|
+
currentDate?: Date;
|
|
75
|
+
/** Time at which the JWT should expire, if no `exp` was already provided (only when typ is "at+jwt"). */
|
|
76
|
+
expiresIn?: number;
|
|
74
77
|
/** Additional JWE Protected Header parameters. */
|
|
75
78
|
protectedHeader?: Omit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "apu" | "apv">;
|
|
76
79
|
/** Initialization Vector for AES-GCMKW key wrapping. Generated if not provided. */
|
|
77
|
-
keyManagementIV?: Uint8Array
|
|
80
|
+
keyManagementIV?: Uint8Array<ArrayBuffer>;
|
|
78
81
|
/** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
|
|
79
|
-
p2s?: Uint8Array
|
|
82
|
+
p2s?: Uint8Array<ArrayBuffer>;
|
|
80
83
|
/** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
|
|
81
84
|
p2c?: number;
|
|
82
85
|
/** ECDH-ES Agreement PartyUInfo. */
|
|
83
|
-
ecdhPartyUInfo?: Uint8Array
|
|
86
|
+
ecdhPartyUInfo?: Uint8Array<ArrayBuffer>;
|
|
84
87
|
/** ECDH-ES Agreement PartyVInfo. */
|
|
85
|
-
ecdhPartyVInfo?: Uint8Array
|
|
88
|
+
ecdhPartyVInfo?: Uint8Array<ArrayBuffer>;
|
|
86
89
|
/**
|
|
87
90
|
* Content Encryption Key (CEK) to use.
|
|
88
91
|
* If provided, it will be used directly. Otherwise, a CEK will be generated.
|
|
89
92
|
*/
|
|
90
|
-
cek?: Uint8Array
|
|
93
|
+
cek?: Uint8Array<ArrayBuffer>;
|
|
91
94
|
/**
|
|
92
95
|
* Initialization Vector for content encryption.
|
|
93
96
|
* If provided, it will be used. Otherwise, one will be generated.
|
|
94
97
|
*/
|
|
95
|
-
contentEncryptionIV?: Uint8Array
|
|
98
|
+
contentEncryptionIV?: Uint8Array<ArrayBuffer>;
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
101
|
* Key lookup function for JWE decryption.
|
|
99
102
|
* @param header The JWE Protected Header.
|
|
100
103
|
* @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
|
|
101
104
|
*/
|
|
102
|
-
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array
|
|
105
|
+
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | string | Uint8Array<ArrayBuffer>>;
|
|
103
106
|
/**
|
|
104
107
|
* JWE (JSON Web Encryption) decryption options
|
|
105
108
|
*/
|
|
106
|
-
interface JWEDecryptOptions {
|
|
109
|
+
interface JWEDecryptOptions extends JWTClaimValidationOptions {
|
|
107
110
|
/** A list of allowed JWE "alg" (Algorithm) Header Parameter values for key management. */
|
|
108
111
|
algorithms?: KeyManagementAlgorithm[];
|
|
109
112
|
/** A list of allowed JWE "enc" (Encryption Algorithm) Header Parameter values for content encryption. */
|
|
110
113
|
encryptionAlgorithms?: ContentEncryptionAlgorithm[];
|
|
111
|
-
/**
|
|
112
|
-
* Critical Header Parameters to be understood and processed.
|
|
113
|
-
* If the JWE contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
|
|
114
|
-
*/
|
|
115
|
-
critical?: string[];
|
|
116
114
|
/** Algorithm to import the unwrapped CEK as (e.g., { name: 'AES-GCM' }). Defaults based on 'enc'. */
|
|
117
115
|
unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
|
|
118
116
|
/** Key usages for the unwrapped CEK. Defaults based on 'enc' (typically ['encrypt', 'decrypt']). */
|
|
@@ -125,15 +123,15 @@ interface JWEDecryptOptions {
|
|
|
125
123
|
/**
|
|
126
124
|
* Result of a JWE decryption operation.
|
|
127
125
|
*/
|
|
128
|
-
interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
|
|
126
|
+
interface JWEDecryptResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
|
|
129
127
|
/** The decrypted payload. */
|
|
130
128
|
payload: T;
|
|
131
129
|
/** The JWE Protected Header. */
|
|
132
130
|
protectedHeader: JWEHeaderParameters;
|
|
133
131
|
/** The Content Encryption Key (CEK) used for decryption, as Uint8Array. */
|
|
134
|
-
cek: Uint8Array
|
|
132
|
+
cek: Uint8Array<ArrayBuffer>;
|
|
135
133
|
/** The Additional Authenticated Data (AAD) used, as Uint8Array. */
|
|
136
|
-
aad: Uint8Array
|
|
134
|
+
aad: Uint8Array<ArrayBuffer>;
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
/**
|
|
@@ -144,17 +142,17 @@ interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims
|
|
|
144
142
|
* @param options JWE encryption options, including `alg` (key management algorithm) and `enc` (content encryption algorithm).
|
|
145
143
|
* @returns A Promise resolving to the JWE Compact Serialization string.
|
|
146
144
|
*/
|
|
147
|
-
declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array
|
|
148
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: JWK | string | Uint8Array
|
|
145
|
+
declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
|
|
146
|
+
declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: JWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
|
|
149
147
|
declare function encrypt(payload: JWTClaims, key: CryptoKey, options: JWEEncryptOptions & {
|
|
150
148
|
alg: KeyManagementAlgorithm;
|
|
151
149
|
enc: ContentEncryptionAlgorithm;
|
|
152
150
|
}): Promise<string>;
|
|
153
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
|
|
151
|
+
declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
|
|
154
152
|
alg: KeyManagementAlgorithm;
|
|
155
153
|
enc: ContentEncryptionAlgorithm;
|
|
156
154
|
}): Promise<string>;
|
|
157
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array
|
|
155
|
+
declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
|
|
158
156
|
alg: KeyManagementAlgorithm;
|
|
159
157
|
enc: ContentEncryptionAlgorithm;
|
|
160
158
|
}): Promise<string>;
|
|
@@ -167,13 +165,13 @@ declare function encrypt(payload: string | Uint8Array | Record<string, any>, key
|
|
|
167
165
|
* @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
|
|
168
166
|
* @throws If JWE is invalid, decryption fails, or options are not met.
|
|
169
167
|
*/
|
|
170
|
-
declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
|
|
171
|
-
declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
|
|
168
|
+
declare function decrypt<T extends JWTClaims | Uint8Array<ArrayBuffer> | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
|
|
169
|
+
declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookupFunction, options: JWEDecryptOptions & {
|
|
172
170
|
forceUint8Array: true;
|
|
173
|
-
}): Promise<JWEDecryptResult<Uint8Array
|
|
171
|
+
}): Promise<JWEDecryptResult<Uint8Array<ArrayBuffer>>>;
|
|
174
172
|
|
|
175
173
|
type jwe_JWEDecryptOptions = JWEDecryptOptions;
|
|
176
|
-
type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
|
|
174
|
+
type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> = JWEDecryptResult<T>;
|
|
177
175
|
type jwe_JWEEncryptOptions = JWEEncryptOptions;
|
|
178
176
|
type jwe_JWEHeaderParameters = JWEHeaderParameters;
|
|
179
177
|
type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
|
|
@@ -15,7 +15,7 @@ interface GenerateKeyOptions {
|
|
|
15
15
|
/** RSA modulus length. Defaults to 2048. */
|
|
16
16
|
modulusLength?: number;
|
|
17
17
|
/** RSA public exponent. Defaults to 65537 (0x010001). */
|
|
18
|
-
publicExponent?: Uint8Array
|
|
18
|
+
publicExponent?: Uint8Array<ArrayBuffer>;
|
|
19
19
|
/** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
|
|
20
20
|
toJWK?: boolean | undefined;
|
|
21
21
|
}
|
|
@@ -23,12 +23,12 @@ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_
|
|
|
23
23
|
privateKey: JWK;
|
|
24
24
|
publicKey: JWK;
|
|
25
25
|
} : JWK;
|
|
26
|
-
type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
|
|
26
|
+
type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
|
|
27
27
|
type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
|
|
28
28
|
/** Options for the deriveKeyFromPassword function. */
|
|
29
29
|
interface DeriveKeyOptions {
|
|
30
30
|
/** Salt value (p2s). Must be at least 8 bytes. */
|
|
31
|
-
salt: Uint8Array
|
|
31
|
+
salt: Uint8Array<ArrayBuffer>;
|
|
32
32
|
/** Iteration count (p2c). Must be a positive integer. */
|
|
33
33
|
iterations: number;
|
|
34
34
|
/** Key usages for the derived key. Defaults to ["wrapKey", "unwrapKey"]. */
|
|
@@ -44,22 +44,22 @@ type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
|
|
|
44
44
|
/** Options for the wrapKey function. */
|
|
45
45
|
interface WrapKeyOptions {
|
|
46
46
|
/** Initialization Vector for AES-GCMKW. Generated if not provided. */
|
|
47
|
-
iv?: Uint8Array
|
|
47
|
+
iv?: Uint8Array<ArrayBuffer>;
|
|
48
48
|
/** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
|
|
49
|
-
p2s?: Uint8Array
|
|
49
|
+
p2s?: Uint8Array<ArrayBuffer>;
|
|
50
50
|
/** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
|
|
51
51
|
p2c?: number;
|
|
52
52
|
/** ECDH-ES Ephemeral Public Key. Generated if not provided for ECDH-ES. */
|
|
53
53
|
epk?: JWK_EC_Public;
|
|
54
54
|
/** ECDH-ES Agreement PartyUInfo. */
|
|
55
|
-
apu?: Uint8Array
|
|
55
|
+
apu?: Uint8Array<ArrayBuffer>;
|
|
56
56
|
/** ECDH-ES Agreement PartyVInfo. */
|
|
57
|
-
apv?: Uint8Array
|
|
57
|
+
apv?: Uint8Array<ArrayBuffer>;
|
|
58
58
|
}
|
|
59
59
|
/** Result of the wrapKey function. */
|
|
60
60
|
interface WrapKeyResult {
|
|
61
61
|
/** The wrapped key (Ciphertext). */
|
|
62
|
-
encryptedKey: Uint8Array
|
|
62
|
+
encryptedKey: Uint8Array<ArrayBuffer>;
|
|
63
63
|
/** Initialization Vector used (only for AES-GCMKW). Base64URL encoded. */
|
|
64
64
|
iv?: string;
|
|
65
65
|
/** Authentication Tag generated (only for AES-GCMKW). Base64URL encoded. */
|
|
@@ -78,19 +78,19 @@ interface WrapKeyResult {
|
|
|
78
78
|
/** Options for the unwrapKey function. */
|
|
79
79
|
interface UnwrapKeyOptions {
|
|
80
80
|
/** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
81
|
-
iv?: Uint8Array | string;
|
|
81
|
+
iv?: Uint8Array<ArrayBuffer> | string;
|
|
82
82
|
/** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
83
|
-
tag?: Uint8Array | string;
|
|
83
|
+
tag?: Uint8Array<ArrayBuffer> | string;
|
|
84
84
|
/** PBES2 Salt value (required for PBES2). Base64URL encoded or Uint8Array. */
|
|
85
|
-
p2s?: Uint8Array | string;
|
|
85
|
+
p2s?: Uint8Array<ArrayBuffer> | string;
|
|
86
86
|
/** PBES2 Iteration count (required for PBES2). */
|
|
87
87
|
p2c?: number;
|
|
88
88
|
/** ECDH-ES Ephemeral Public Key (required for ECDH-ES). */
|
|
89
89
|
epk?: JWK_EC_Public;
|
|
90
90
|
/** ECDH-ES Agreement PartyUInfo. Base64URL encoded or Uint8Array. */
|
|
91
|
-
apu?: Uint8Array | string;
|
|
91
|
+
apu?: Uint8Array<ArrayBuffer> | string;
|
|
92
92
|
/** ECDH-ES Agreement PartyVInfo. Base64URL encoded or Uint8Array. */
|
|
93
|
-
apv?: Uint8Array | string;
|
|
93
|
+
apv?: Uint8Array<ArrayBuffer> | string;
|
|
94
94
|
/** Expected unwrapped key algorithm (e.g., 'AES-GCM', 'AES-CBC'). Used by crypto.subtle.unwrapKey. */
|
|
95
95
|
unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
|
|
96
96
|
/** Expected key usages for the unwrapped key. */
|
|
@@ -203,8 +203,83 @@ type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256
|
|
|
203
203
|
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
204
204
|
type JWK_ED = "Ed25519" | "EdDSA";
|
|
205
205
|
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
206
|
-
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
206
|
+
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_ED;
|
|
207
207
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
208
208
|
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
/** Header Parameters common to JWE and JWS */
|
|
211
|
+
interface JoseHeaderParameters {
|
|
212
|
+
/** "kid" (Key ID) Header Parameter */
|
|
213
|
+
kid?: string;
|
|
214
|
+
/** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
|
|
215
|
+
x5t?: string;
|
|
216
|
+
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
217
|
+
x5c?: string[];
|
|
218
|
+
/** "x5u" (X.509 URL) Header Parameter */
|
|
219
|
+
x5u?: string;
|
|
220
|
+
/** "jku" (JWK Set URL) Header Parameter */
|
|
221
|
+
jku?: string;
|
|
222
|
+
/** "jwk" (JSON Web Key) Header Parameter */
|
|
223
|
+
jwk?: JWK_RSA_Public;
|
|
224
|
+
/** "typ" (Type) Header Parameter */
|
|
225
|
+
typ?: string;
|
|
226
|
+
/** "cty" (Content Type) Header Parameter */
|
|
227
|
+
cty?: string;
|
|
228
|
+
/** "crit" (Critical) Header Parameter */
|
|
229
|
+
crit?: string[];
|
|
230
|
+
/** Any other JWS/JWE Header member. */
|
|
231
|
+
[propName: string]: unknown;
|
|
232
|
+
}
|
|
233
|
+
interface JWTClaims {
|
|
234
|
+
/** "iss" (Issuer) Claim */
|
|
235
|
+
iss?: string;
|
|
236
|
+
/** "sub" (Subject) Claim */
|
|
237
|
+
sub?: string;
|
|
238
|
+
/** "aud" (Audience) Claim */
|
|
239
|
+
aud?: string | string[];
|
|
240
|
+
/** "exp" (Expiration Time) Claim */
|
|
241
|
+
exp?: number;
|
|
242
|
+
/** "nbf" (Not Before) Claim */
|
|
243
|
+
nbf?: number;
|
|
244
|
+
/** "iat" (Issued At) Claim */
|
|
245
|
+
iat?: number;
|
|
246
|
+
/** "jti" (JWT ID) Claim */
|
|
247
|
+
jti?: string;
|
|
248
|
+
/** Any other JWT member. */
|
|
249
|
+
[propName: string]: unknown;
|
|
250
|
+
}
|
|
251
|
+
interface JWT<T = JWTClaims> {
|
|
252
|
+
header: JoseHeaderParameters & {
|
|
253
|
+
/** "alg" (Algorithm) Header Parameter */
|
|
254
|
+
alg: string;
|
|
255
|
+
};
|
|
256
|
+
claims: T;
|
|
257
|
+
}
|
|
258
|
+
interface JWTClaimValidationOptions {
|
|
259
|
+
/** Expected JWT "aud" (Audience) Claim value(s). Implies presence requirement. */
|
|
260
|
+
audience?: string | string[];
|
|
261
|
+
/** Expected JWT "iss" (Issuer) Claim value(s). Implies presence requirement. */
|
|
262
|
+
issuer?: string | string[];
|
|
263
|
+
/** Expected JWT "sub" (Subject) Claim value. Implies presence requirement. */
|
|
264
|
+
subject?: string;
|
|
265
|
+
/** Maximum token age in seconds, from the JWT "iat" (Issued At) Claim value. Implies presence requirement. */
|
|
266
|
+
maxTokenAge?: number;
|
|
267
|
+
/** Clock skew tolerance (in seconds) for validating time-based claims (nbf/exp/iat). */
|
|
268
|
+
clockTolerance?: number;
|
|
269
|
+
/** Expected JWT "typ" (Type) Header Parameter value. Implies presence requirement. */
|
|
270
|
+
typ?: string;
|
|
271
|
+
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
272
|
+
currentDate?: Date;
|
|
273
|
+
/** Additional required claim names. */
|
|
274
|
+
requiredClaims?: string[];
|
|
275
|
+
/** List of critical header parameters that must be understood and processed. */
|
|
276
|
+
requiredHeaders?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Critical Header Parameters to be understood and processed.
|
|
279
|
+
* If the JWT contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
|
|
280
|
+
* @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
|
|
281
|
+
*/
|
|
282
|
+
critical?: string[];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export type { JWK_Symmetric_Algorithm as A, JWK_Asymmetric_Algorithm as B, CompositeKey as C, DeriveKeyOptions as D, JWKAlgorithm as E, JWKPEMAlgorithm as F, GenerateKeyAlgorithm as G, JoseHeaderParameters as H, JWTClaims as I, JWKParameters as J, KeyManagementAlgorithm as K, JWT as L, JWTClaimValidationOptions as M, UnwrapKeyOptions as U, WrapKeyOptions as W, GenerateKeyOptions as a, GenerateKeyReturn as b, DeriveKeyReturn as c, ContentEncryptionAlgorithm as d, WrapKeyResult as e, JWK_EC_Public as f, JWK_EC_Private as g, JWK_EC as h, JWK_RSA_Public as i, JWK_RSA_Private as j, JWK_RSA as k, JWK_oct as l, JWK as m, JWKSet as n, JWK_HMAC as o, JWK_RSA_SIGN as p, JWK_RSA_PSS as q, JWK_ECDSA as r, JWK_RSA_ENC as s, JWK_AES_KW as t, JWK_AES_GCM_KW as u, JWK_AES_CBC_HMAC as v, JWK_AES_GCM as w, JWK_PBES2 as x, JWK_ECDH_ES as y, JWK_ED as z };
|