unjwt 0.5.1 → 0.5.3
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 +23 -5
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +3 -3
- package/dist/jwe.d.ts +3 -3
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +3 -2
- package/dist/jwk.d.ts +3 -2
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +3 -3
- package/dist/jws.d.ts +3 -3
- package/dist/jws.mjs +4 -4
- package/dist/shared/{unjwt.D1J1DelP.d.mts → unjwt.B4NFVxpx.d.ts} +26 -2
- package/dist/shared/{unjwt.B0XDPf8a.d.ts → unjwt.BJPVLhUb.d.ts} +3 -3
- package/dist/shared/{unjwt.1gbuWbc6.mjs → unjwt.BPpolBff.mjs} +41 -2
- package/dist/shared/{unjwt.Ce72NmIz.mjs → unjwt.BtEHeKmp.mjs} +4 -4
- package/dist/shared/{unjwt.BG_R52ey.d.mts → unjwt.BvA-8hLQ.d.mts} +70 -10
- package/dist/shared/{unjwt.Cd9nTEWg.d.mts → unjwt.BvIkEGGz.d.mts} +1 -1
- package/dist/shared/{unjwt.CVKbKOFy.d.ts → unjwt.C5blWtcA.d.ts} +70 -10
- package/dist/shared/{unjwt.C9Xhi7hE.mjs → unjwt.CauxOPN5.mjs} +1 -1
- package/dist/shared/{unjwt.B4fFiy1c.d.mts → unjwt.CbvzYE-m.d.mts} +8 -2
- package/dist/shared/{unjwt.DqmNvXMd.d.ts → unjwt.D4DUiNeM.d.ts} +8 -2
- package/dist/shared/{unjwt.CxhGjEAX.d.mts → unjwt.D9da8HQF.d.mts} +10 -2
- package/dist/shared/{unjwt.CxhGjEAX.d.ts → unjwt.D9da8HQF.d.ts} +10 -2
- package/dist/shared/{unjwt.DQIYSlHj.d.mts → unjwt.DLOO5Rmq.d.mts} +3 -3
- package/dist/shared/{unjwt.WvWb2zNM.d.ts → unjwt.DZjogLQk.d.mts} +26 -2
- package/dist/shared/{unjwt.BxqF-n1S.mjs → unjwt.Dsh9nxbB.mjs} +98 -19
- package/dist/shared/{unjwt.DHdDAH0L.mjs → unjwt.X5vzu_l_.mjs} +9 -1
- package/dist/shared/{unjwt.BISJ5yt1.d.ts → unjwt.c10n3uM8.d.ts} +1 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,14 +44,25 @@ import { encrypt, decrypt } from "unjwt/jwe";
|
|
|
44
44
|
// JWK functions
|
|
45
45
|
import {
|
|
46
46
|
generateKey,
|
|
47
|
-
deriveKeyFromPassword,
|
|
48
47
|
importKey,
|
|
49
48
|
exportKey,
|
|
50
49
|
wrapKey,
|
|
51
50
|
unwrapKey,
|
|
51
|
+
getJWKFromSet,
|
|
52
|
+
importJWKFromPEM,
|
|
53
|
+
exportJWKToPEM,
|
|
54
|
+
deriveKeyFromPassword,
|
|
52
55
|
} from "unjwt/jwk";
|
|
53
56
|
// Utility functions
|
|
54
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
isJWK,
|
|
59
|
+
isJWKSet,
|
|
60
|
+
isCryptoKey,
|
|
61
|
+
isCryptoKeyPair,
|
|
62
|
+
base64UrlEncode,
|
|
63
|
+
base64UrlDecode,
|
|
64
|
+
randomBytes,
|
|
65
|
+
} from "unjwt/utils";
|
|
55
66
|
```
|
|
56
67
|
|
|
57
68
|
**CDN** (Deno, Bun and Browsers)
|
|
@@ -65,14 +76,21 @@ import { encrypt, decrypt } from "https://esm.sh/unjwt/jwe";
|
|
|
65
76
|
// JWK functions
|
|
66
77
|
import {
|
|
67
78
|
generateKey,
|
|
68
|
-
deriveKeyFromPassword,
|
|
69
79
|
importKey,
|
|
70
80
|
exportKey,
|
|
71
81
|
wrapKey,
|
|
72
82
|
unwrapKey,
|
|
83
|
+
getJWKFromSet,
|
|
84
|
+
importJWKFromPEM,
|
|
85
|
+
exportJWKToPEM,
|
|
86
|
+
deriveKeyFromPassword,
|
|
73
87
|
} from "https://esm.sh/unjwt/jwk";
|
|
74
88
|
// Utility functions
|
|
75
89
|
import {
|
|
90
|
+
isJWK,
|
|
91
|
+
isJWKSet,
|
|
92
|
+
isCryptoKey,
|
|
93
|
+
isCryptoKeyPair,
|
|
76
94
|
base64UrlEncode,
|
|
77
95
|
base64UrlDecode,
|
|
78
96
|
randomBytes,
|
|
@@ -129,8 +147,8 @@ console.log(token);
|
|
|
129
147
|
Verifies a JWS token.
|
|
130
148
|
|
|
131
149
|
- `jws`: The JWS token string.
|
|
132
|
-
- `key`: The verification key (`CryptoKey`, `JWK`, `Uint8Array`, or a `KeyLookupFunction`).
|
|
133
|
-
A `KeyLookupFunction` has the signature `(header: JWSProtectedHeader) => Promise<CryptoKey | JWK | Uint8Array> | CryptoKey | JWK | Uint8Array`.
|
|
150
|
+
- `key`: The verification key (`CryptoKey`, `JWK`, `JWKSet`, `Uint8Array`, or a `KeyLookupFunction`).
|
|
151
|
+
A `KeyLookupFunction` has the signature `(header: JWSProtectedHeader, jws: string) => Promise<CryptoKey | JWK | JWKSet | Uint8Array> | CryptoKey | JWK | JWKSet | Uint8Array`.
|
|
134
152
|
- `options` (optional):
|
|
135
153
|
- `algorithms`: An array of allowed JWS `alg` values. If not provided, the `alg` from the JWS header is used.
|
|
136
154
|
- `critical`: An array of JWS header parameter names that the application understands and processes.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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,
|
|
2
|
-
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.
|
|
3
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.
|
|
4
|
-
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.
|
|
5
|
-
export { i as utils } from './shared/unjwt.
|
|
6
|
-
export { j as jwk } from './shared/unjwt.
|
|
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.D9da8HQF.mjs';
|
|
2
|
+
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.BvIkEGGz.mjs';
|
|
3
|
+
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.BvA-8hLQ.mjs';
|
|
4
|
+
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.DLOO5Rmq.mjs';
|
|
5
|
+
export { i as utils } from './shared/unjwt.CbvzYE-m.mjs';
|
|
6
|
+
export { j as jwk } from './shared/unjwt.DZjogLQk.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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,
|
|
2
|
-
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.
|
|
3
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.
|
|
4
|
-
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.
|
|
5
|
-
export { i as utils } from './shared/unjwt.
|
|
6
|
-
export { j as jwk } from './shared/unjwt.
|
|
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.D9da8HQF.js';
|
|
2
|
+
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.c10n3uM8.js';
|
|
3
|
+
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.C5blWtcA.js';
|
|
4
|
+
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.BJPVLhUb.js';
|
|
5
|
+
export { i as utils } from './shared/unjwt.D4DUiNeM.js';
|
|
6
|
+
export { j as jwk } from './shared/unjwt.B4NFVxpx.js';
|
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.X5vzu_l_.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.BtEHeKmp.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.BPpolBff.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.Dsh9nxbB.mjs';
|
|
5
|
+
import './shared/unjwt.CauxOPN5.mjs';
|
package/dist/jwe.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
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.
|
|
1
|
+
import './shared/unjwt.D9da8HQF.mjs';
|
|
2
|
+
import './shared/unjwt.BvIkEGGz.mjs';
|
|
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.DLOO5Rmq.mjs';
|
package/dist/jwe.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
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.
|
|
1
|
+
import './shared/unjwt.D9da8HQF.js';
|
|
2
|
+
import './shared/unjwt.c10n3uM8.js';
|
|
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.BJPVLhUb.js';
|
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.BPpolBff.mjs';
|
|
2
|
+
import './shared/unjwt.X5vzu_l_.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.BtEHeKmp.mjs';
|
|
4
|
+
import './shared/unjwt.CauxOPN5.mjs';
|
package/dist/jwk.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
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,
|
|
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.D9da8HQF.mjs';
|
|
2
|
+
import './shared/unjwt.BvIkEGGz.mjs';
|
|
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.DZjogLQk.mjs';
|
package/dist/jwk.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
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,
|
|
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.D9da8HQF.js';
|
|
2
|
+
import './shared/unjwt.c10n3uM8.js';
|
|
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.B4NFVxpx.js';
|
package/dist/jwk.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.X5vzu_l_.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.BPpolBff.mjs';
|
package/dist/jws.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.D9da8HQF.mjs';
|
|
2
|
+
import './shared/unjwt.BvIkEGGz.mjs';
|
|
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.BvA-8hLQ.mjs';
|
package/dist/jws.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.D9da8HQF.js';
|
|
2
|
+
import './shared/unjwt.c10n3uM8.js';
|
|
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.C5blWtcA.js';
|
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.BPpolBff.mjs';
|
|
2
|
+
import './shared/unjwt.X5vzu_l_.mjs';
|
|
3
|
+
import './shared/unjwt.CauxOPN5.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.Dsh9nxbB.mjs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn,
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, 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, 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 } from './unjwt.D9da8HQF.js';
|
|
2
|
+
import { J as JoseHeaderParameters } from './unjwt.c10n3uM8.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* This is a fork of Jose library's utility functions.
|
|
@@ -101,6 +102,25 @@ declare function importJWKFromPEM(pem: string, pemType: "pkcs8" | "spki" | "x509
|
|
|
101
102
|
* @returns A Promise resolving to the PEM-encoded key string.
|
|
102
103
|
*/
|
|
103
104
|
declare function exportJWKToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a JWK (JSON Web Key) from a JWKSet based on a key ID (kid) or
|
|
107
|
+
* properties from a JOSE Header.
|
|
108
|
+
*
|
|
109
|
+
* @param jwkSet The JWKSet to search within.
|
|
110
|
+
* @param kidOrProtectedHeader Either a string representing the 'kid' (Key ID)
|
|
111
|
+
* or an object representing the JOSE Protected Header. If an object is
|
|
112
|
+
* provided, it must contain a 'kid' property. It can optionally contain
|
|
113
|
+
* 'alg' (Algorithm) and 'kty' (Key Type) to further refine the search.
|
|
114
|
+
* @returns The matching JWK from the set.
|
|
115
|
+
* @throws TypeError if `jwkSet` is invalid or `kidOrProtectedHeader` is not a
|
|
116
|
+
* string or a valid header object.
|
|
117
|
+
* @throws Error if no key is found matching the provided criteria, or if the
|
|
118
|
+
* header object is missing the 'kid' property.
|
|
119
|
+
*/
|
|
120
|
+
declare function getJWKFromSet(jwkSet: JWKSet, kidOrProtectedHeader: string | (JoseHeaderParameters & {
|
|
121
|
+
alg?: string;
|
|
122
|
+
kty?: string;
|
|
123
|
+
})): JWK;
|
|
104
124
|
|
|
105
125
|
declare const jwk_CompositeKey: typeof CompositeKey;
|
|
106
126
|
declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
@@ -113,6 +133,7 @@ declare const jwk_JWK: typeof JWK;
|
|
|
113
133
|
declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
|
|
114
134
|
declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
115
135
|
declare const jwk_JWKParameters: typeof JWKParameters;
|
|
136
|
+
declare const jwk_JWKSet: typeof JWKSet;
|
|
116
137
|
declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
117
138
|
declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
118
139
|
declare const jwk_JWK_AES_GCM_KW: typeof JWK_AES_GCM_KW;
|
|
@@ -142,6 +163,7 @@ declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
|
|
|
142
163
|
declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
|
|
143
164
|
declare const jwk_exportKey: typeof exportKey;
|
|
144
165
|
declare const jwk_generateKey: typeof generateKey;
|
|
166
|
+
declare const jwk_getJWKFromSet: typeof getJWKFromSet;
|
|
145
167
|
declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
|
|
146
168
|
declare const jwk_importKey: typeof importKey;
|
|
147
169
|
declare const jwk_unwrapKey: typeof unwrapKey;
|
|
@@ -159,6 +181,7 @@ declare namespace jwk {
|
|
|
159
181
|
jwk_JWKAlgorithm as JWKAlgorithm,
|
|
160
182
|
jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
161
183
|
jwk_JWKParameters as JWKParameters,
|
|
184
|
+
jwk_JWKSet as JWKSet,
|
|
162
185
|
jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
163
186
|
jwk_JWK_AES_GCM as JWK_AES_GCM,
|
|
164
187
|
jwk_JWK_AES_GCM_KW as JWK_AES_GCM_KW,
|
|
@@ -188,6 +211,7 @@ declare namespace jwk {
|
|
|
188
211
|
jwk_exportJWKToPEM as exportJWKToPEM,
|
|
189
212
|
jwk_exportKey as exportKey,
|
|
190
213
|
jwk_generateKey as generateKey,
|
|
214
|
+
jwk_getJWKFromSet as getJWKFromSet,
|
|
191
215
|
jwk_importJWKFromPEM as importJWKFromPEM,
|
|
192
216
|
jwk_importKey as importKey,
|
|
193
217
|
jwk_unwrapKey as unwrapKey,
|
|
@@ -195,4 +219,4 @@ declare namespace jwk {
|
|
|
195
219
|
};
|
|
196
220
|
}
|
|
197
221
|
|
|
198
|
-
export { importJWKFromPEM as a, exportJWKToPEM as b, deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
222
|
+
export { importJWKFromPEM as a, exportJWKToPEM as b, getJWKFromSet as c, deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
@@ -1,5 +1,5 @@
|
|
|
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.
|
|
1
|
+
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.D9da8HQF.js';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
|
|
3
3
|
|
|
4
4
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
5
5
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -99,7 +99,7 @@ interface JWEEncryptOptions {
|
|
|
99
99
|
* @param header The JWE Protected Header.
|
|
100
100
|
* @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
|
|
101
101
|
*/
|
|
102
|
-
type JWEKeyLookupFunction = (header: JWEHeaderParameters) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
|
|
102
|
+
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
|
|
103
103
|
/**
|
|
104
104
|
* JWE (JSON Web Encryption) decryption options
|
|
105
105
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as isCryptoKey, f as concatUint8Arrays, b as base64UrlEncode, j as base64Decode, k as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode, e as isJWKSet } from './unjwt.X5vzu_l_.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -1383,6 +1383,44 @@ async function exportJWKToPEM(jwk, pemFormat, algForCryptoKeyImport) {
|
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
1385
|
}
|
|
1386
|
+
function getJWKFromSet(jwkSet, kidOrProtectedHeader) {
|
|
1387
|
+
if (!jwkSet || !isJWKSet(jwkSet)) {
|
|
1388
|
+
throw new TypeError("Invalid JWK Set provided");
|
|
1389
|
+
}
|
|
1390
|
+
if (typeof kidOrProtectedHeader === "string") {
|
|
1391
|
+
const kid = kidOrProtectedHeader;
|
|
1392
|
+
const selectedKey = jwkSet.keys.find((k) => k.kid === kid);
|
|
1393
|
+
if (!selectedKey) {
|
|
1394
|
+
throw new Error(`No key found in JWK Set with kid "${kid}".`);
|
|
1395
|
+
}
|
|
1396
|
+
return selectedKey;
|
|
1397
|
+
} else if (typeof kidOrProtectedHeader === "object") {
|
|
1398
|
+
const { kid, alg, kty } = kidOrProtectedHeader;
|
|
1399
|
+
if (!kid) {
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
"JWS Protected Header is missing 'kid' (Key ID) and a JWK Set was provided. Cannot select key from JWK Set automatically."
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
const selectedKey = jwkSet.keys.find((k) => {
|
|
1405
|
+
return k.kid === kid && (!alg || k.alg === alg) && (!kty || k.kty === kty);
|
|
1406
|
+
});
|
|
1407
|
+
if (!selectedKey) {
|
|
1408
|
+
let errorMessage = `No key found in JWK Set with kid "${kid}"`;
|
|
1409
|
+
if (alg) {
|
|
1410
|
+
errorMessage += ` and alg "${alg}"`;
|
|
1411
|
+
}
|
|
1412
|
+
if (kty) {
|
|
1413
|
+
errorMessage += ` and kty "${kty}"`;
|
|
1414
|
+
}
|
|
1415
|
+
errorMessage += ".";
|
|
1416
|
+
throw new Error(errorMessage);
|
|
1417
|
+
}
|
|
1418
|
+
return selectedKey;
|
|
1419
|
+
}
|
|
1420
|
+
throw new TypeError(
|
|
1421
|
+
"`kidOrProtectedHeader` must be a string (kid) or an object (JOSE Protected Header)."
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1386
1424
|
function getGenerateKeyParams(alg, options) {
|
|
1387
1425
|
let algorithm;
|
|
1388
1426
|
let keyUsages;
|
|
@@ -1498,10 +1536,11 @@ const jwk = {
|
|
|
1498
1536
|
exportJWKToPEM: exportJWKToPEM,
|
|
1499
1537
|
exportKey: exportKey,
|
|
1500
1538
|
generateKey: generateKey,
|
|
1539
|
+
getJWKFromSet: getJWKFromSet,
|
|
1501
1540
|
importJWKFromPEM: importJWKFromPEM,
|
|
1502
1541
|
importKey: importKey,
|
|
1503
1542
|
unwrapKey: unwrapKey,
|
|
1504
1543
|
wrapKey: wrapKey
|
|
1505
1544
|
};
|
|
1506
1545
|
|
|
1507
|
-
export { checkEncCryptoKey as a,
|
|
1546
|
+
export { checkEncCryptoKey as a, generateCEK as b, checkSigCryptoKey as c, bitLengthCEK as d, encryptIV as e, jwkTokey as f, getJWKFromSet as g, generateIV as h, importKey as i, jwk as j, keyToJWK as k, encrypt as l, unwrapKey as m, decrypt as n, generateKey as o, deriveKeyFromPassword as p, exportKey as q, wrapKey as r, importJWKFromPEM as s, exportJWKToPEM as t, uint32be as u, wrap as w };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as checkEncCryptoKey, u as uint32be,
|
|
2
|
-
import {
|
|
3
|
-
import { c as checkKeyLength } from './unjwt.
|
|
1
|
+
import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.BPpolBff.mjs';
|
|
2
|
+
import { f as concatUint8Arrays, t as textEncoder, g as assertCryptoKey, b as base64UrlEncode, h as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.X5vzu_l_.mjs';
|
|
3
|
+
import { c as checkKeyLength } from './unjwt.CauxOPN5.mjs';
|
|
4
4
|
|
|
5
5
|
function lengthAndInput(input) {
|
|
6
6
|
return concatUint8Arrays(uint32be(input.length), input);
|
|
@@ -327,7 +327,7 @@ async function decrypt(jwe, key, options) {
|
|
|
327
327
|
if (options?.encryptionAlgorithms && !options.encryptionAlgorithms.includes(enc)) {
|
|
328
328
|
throw new Error(`Content encryption algorithm not allowed: ${enc}`);
|
|
329
329
|
}
|
|
330
|
-
const resolvedKeyMaterial = typeof key === "function" ? await key(protectedHeader) : key;
|
|
330
|
+
const resolvedKeyMaterial = typeof key === "function" ? await key(protectedHeader, jwe) : key;
|
|
331
331
|
const unwrappingKey = await importKey(resolvedKeyMaterial, alg);
|
|
332
332
|
const encryptedKeyBytes = base64UrlDecode(encryptedKeyEncoded, false);
|
|
333
333
|
const contentIVBytes = base64UrlDecode(ivEncoded, false);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.
|
|
1
|
+
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, m as JWK, n as JWKSet } from './unjwt.D9da8HQF.mjs';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BvIkEGGz.mjs';
|
|
3
3
|
|
|
4
4
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
5
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -43,11 +43,71 @@ interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
|
|
|
43
43
|
interface JWSVerifyOptions {
|
|
44
44
|
/** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
|
|
45
45
|
algorithms?: JWSAlgorithm[];
|
|
46
|
-
/** List of critical header parameters that must be understood and processed. */
|
|
47
|
-
critical?: string[];
|
|
48
46
|
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
|
|
49
47
|
forceUint8Array?: boolean;
|
|
48
|
+
/** List of critical header parameters that must be understood and processed. */
|
|
49
|
+
requiredHeaders?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Expected JWT "aud" (Audience) Claim value(s).
|
|
52
|
+
*
|
|
53
|
+
* This option makes the JWT "aud" (Audience) Claim presence required.
|
|
54
|
+
*/
|
|
55
|
+
audience?: string | string[];
|
|
56
|
+
/**
|
|
57
|
+
* Clock skew tolerance (in seconds) for validating JWT claims.
|
|
58
|
+
*
|
|
59
|
+
* Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
|
|
60
|
+
* validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
|
|
61
|
+
*/
|
|
62
|
+
clockTolerance?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Expected JWT "iss" (Issuer) Claim value(s).
|
|
65
|
+
*
|
|
66
|
+
* This option makes the JWT "iss" (Issuer) Claim presence required.
|
|
67
|
+
*/
|
|
68
|
+
issuer?: string | string[];
|
|
69
|
+
/**
|
|
70
|
+
* Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
|
|
71
|
+
*
|
|
72
|
+
* This option makes the JWT "iat" (Issued At) Claim presence required.
|
|
73
|
+
*/
|
|
74
|
+
maxTokenAge?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Expected JWT "sub" (Subject) Claim value.
|
|
77
|
+
*
|
|
78
|
+
* This option makes the JWT "sub" (Subject) Claim presence required.
|
|
79
|
+
*/
|
|
80
|
+
subject?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Expected JWT "typ" (Type) Header Parameter value.
|
|
83
|
+
*
|
|
84
|
+
* This option makes the JWT "typ" (Type) Header Parameter presence required.
|
|
85
|
+
*/
|
|
86
|
+
typ?: string;
|
|
87
|
+
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
88
|
+
currentDate?: Date;
|
|
89
|
+
/**
|
|
90
|
+
* Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
|
|
91
|
+
* the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
|
|
92
|
+
* {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
|
|
93
|
+
* the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
|
|
94
|
+
* the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
|
|
95
|
+
* present.
|
|
96
|
+
*/
|
|
97
|
+
requiredClaims?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* List of critical header parameters that must be understood and processed.
|
|
100
|
+
* @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
|
|
101
|
+
*/
|
|
102
|
+
critical?: string[];
|
|
50
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Key lookup function for JWS verification.
|
|
106
|
+
* @param header The JWS Protected Header.
|
|
107
|
+
* @param token The JWS token.
|
|
108
|
+
* @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
|
|
109
|
+
*/
|
|
110
|
+
type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array | Promise<CryptoKey | JWK | JWKSet | Uint8Array>;
|
|
51
111
|
|
|
52
112
|
/**
|
|
53
113
|
* Creates a JWS (JSON Web Signature) in Compact Serialization format.
|
|
@@ -68,23 +128,23 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
|
|
|
68
128
|
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
|
|
69
129
|
alg: JWSAlgorithm;
|
|
70
130
|
}): Promise<string>;
|
|
71
|
-
type KeyLookupFunction = (header: JWSProtectedHeader) => CryptoKey | JWK | Uint8Array | Promise<CryptoKey | JWK | Uint8Array>;
|
|
72
131
|
/**
|
|
73
132
|
* Verifies a JWS (JSON Web Signature) in Compact Serialization format.
|
|
74
133
|
*
|
|
75
134
|
* @param jws The JWS Compact Serialization string.
|
|
76
|
-
* @param key The verification key (CryptoKey, JWK, raw symmetric key as Uint8Array, or a function resolving the key).
|
|
135
|
+
* @param key The verification key (CryptoKey, JWK, JWKSet, raw symmetric key as Uint8Array, or a function resolving the key or set).
|
|
77
136
|
* @param options Verification options, such as allowed algorithms.
|
|
78
137
|
* @returns A Promise resolving to an object containing the verified payload and protected header.
|
|
79
138
|
* @throws If the JWS is invalid, signature verification fails, or options are not met.
|
|
80
139
|
*/
|
|
81
|
-
declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | Uint8Array |
|
|
82
|
-
declare function verify(jws: string, key: CryptoKey | JWK | Uint8Array |
|
|
140
|
+
declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
141
|
+
declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
|
|
83
142
|
forceUint8Array: true;
|
|
84
143
|
}): Promise<JWSVerifyResult<Uint8Array>>;
|
|
85
144
|
|
|
86
145
|
type jws_JWSAlgorithm = JWSAlgorithm;
|
|
87
146
|
type jws_JWSHeaderParameters = JWSHeaderParameters;
|
|
147
|
+
type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
|
|
88
148
|
type jws_JWSProtectedHeader = JWSProtectedHeader;
|
|
89
149
|
type jws_JWSSignOptions = JWSSignOptions;
|
|
90
150
|
type jws_JWSVerifyOptions = JWSVerifyOptions;
|
|
@@ -93,8 +153,8 @@ declare const jws_sign: typeof sign;
|
|
|
93
153
|
declare const jws_verify: typeof verify;
|
|
94
154
|
declare namespace jws {
|
|
95
155
|
export { jws_sign as sign, jws_verify as verify };
|
|
96
|
-
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
156
|
+
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSKeyLookupFunction as JWSKeyLookupFunction, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
97
157
|
}
|
|
98
158
|
|
|
99
159
|
export { jws as j, sign as s, verify as v };
|
|
100
|
-
export type { JWSAlgorithm as J, JWSHeaderParameters as a, JWSProtectedHeader as b, JWSSignOptions as c, JWSVerifyResult as d, JWSVerifyOptions as e };
|
|
160
|
+
export type { JWSAlgorithm as J, JWSHeaderParameters as a, JWSProtectedHeader as b, JWSSignOptions as c, JWSVerifyResult as d, JWSVerifyOptions as e, JWSKeyLookupFunction as f };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.
|
|
1
|
+
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
|
|
3
3
|
|
|
4
4
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
5
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -43,11 +43,71 @@ interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
|
|
|
43
43
|
interface JWSVerifyOptions {
|
|
44
44
|
/** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
|
|
45
45
|
algorithms?: JWSAlgorithm[];
|
|
46
|
-
/** List of critical header parameters that must be understood and processed. */
|
|
47
|
-
critical?: string[];
|
|
48
46
|
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
|
|
49
47
|
forceUint8Array?: boolean;
|
|
48
|
+
/** List of critical header parameters that must be understood and processed. */
|
|
49
|
+
requiredHeaders?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Expected JWT "aud" (Audience) Claim value(s).
|
|
52
|
+
*
|
|
53
|
+
* This option makes the JWT "aud" (Audience) Claim presence required.
|
|
54
|
+
*/
|
|
55
|
+
audience?: string | string[];
|
|
56
|
+
/**
|
|
57
|
+
* Clock skew tolerance (in seconds) for validating JWT claims.
|
|
58
|
+
*
|
|
59
|
+
* Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
|
|
60
|
+
* validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
|
|
61
|
+
*/
|
|
62
|
+
clockTolerance?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Expected JWT "iss" (Issuer) Claim value(s).
|
|
65
|
+
*
|
|
66
|
+
* This option makes the JWT "iss" (Issuer) Claim presence required.
|
|
67
|
+
*/
|
|
68
|
+
issuer?: string | string[];
|
|
69
|
+
/**
|
|
70
|
+
* Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
|
|
71
|
+
*
|
|
72
|
+
* This option makes the JWT "iat" (Issued At) Claim presence required.
|
|
73
|
+
*/
|
|
74
|
+
maxTokenAge?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Expected JWT "sub" (Subject) Claim value.
|
|
77
|
+
*
|
|
78
|
+
* This option makes the JWT "sub" (Subject) Claim presence required.
|
|
79
|
+
*/
|
|
80
|
+
subject?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Expected JWT "typ" (Type) Header Parameter value.
|
|
83
|
+
*
|
|
84
|
+
* This option makes the JWT "typ" (Type) Header Parameter presence required.
|
|
85
|
+
*/
|
|
86
|
+
typ?: string;
|
|
87
|
+
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
88
|
+
currentDate?: Date;
|
|
89
|
+
/**
|
|
90
|
+
* Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
|
|
91
|
+
* the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
|
|
92
|
+
* {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
|
|
93
|
+
* the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
|
|
94
|
+
* the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
|
|
95
|
+
* present.
|
|
96
|
+
*/
|
|
97
|
+
requiredClaims?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* List of critical header parameters that must be understood and processed.
|
|
100
|
+
* @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
|
|
101
|
+
*/
|
|
102
|
+
critical?: string[];
|
|
50
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Key lookup function for JWS verification.
|
|
106
|
+
* @param header The JWS Protected Header.
|
|
107
|
+
* @param token The JWS token.
|
|
108
|
+
* @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
|
|
109
|
+
*/
|
|
110
|
+
type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array | Promise<CryptoKey | JWK | JWKSet | Uint8Array>;
|
|
51
111
|
|
|
52
112
|
/**
|
|
53
113
|
* Creates a JWS (JSON Web Signature) in Compact Serialization format.
|
|
@@ -68,23 +128,23 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
|
|
|
68
128
|
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
|
|
69
129
|
alg: JWSAlgorithm;
|
|
70
130
|
}): Promise<string>;
|
|
71
|
-
type KeyLookupFunction = (header: JWSProtectedHeader) => CryptoKey | JWK | Uint8Array | Promise<CryptoKey | JWK | Uint8Array>;
|
|
72
131
|
/**
|
|
73
132
|
* Verifies a JWS (JSON Web Signature) in Compact Serialization format.
|
|
74
133
|
*
|
|
75
134
|
* @param jws The JWS Compact Serialization string.
|
|
76
|
-
* @param key The verification key (CryptoKey, JWK, raw symmetric key as Uint8Array, or a function resolving the key).
|
|
135
|
+
* @param key The verification key (CryptoKey, JWK, JWKSet, raw symmetric key as Uint8Array, or a function resolving the key or set).
|
|
77
136
|
* @param options Verification options, such as allowed algorithms.
|
|
78
137
|
* @returns A Promise resolving to an object containing the verified payload and protected header.
|
|
79
138
|
* @throws If the JWS is invalid, signature verification fails, or options are not met.
|
|
80
139
|
*/
|
|
81
|
-
declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | Uint8Array |
|
|
82
|
-
declare function verify(jws: string, key: CryptoKey | JWK | Uint8Array |
|
|
140
|
+
declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
141
|
+
declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
|
|
83
142
|
forceUint8Array: true;
|
|
84
143
|
}): Promise<JWSVerifyResult<Uint8Array>>;
|
|
85
144
|
|
|
86
145
|
type jws_JWSAlgorithm = JWSAlgorithm;
|
|
87
146
|
type jws_JWSHeaderParameters = JWSHeaderParameters;
|
|
147
|
+
type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
|
|
88
148
|
type jws_JWSProtectedHeader = JWSProtectedHeader;
|
|
89
149
|
type jws_JWSSignOptions = JWSSignOptions;
|
|
90
150
|
type jws_JWSVerifyOptions = JWSVerifyOptions;
|
|
@@ -93,8 +153,8 @@ declare const jws_sign: typeof sign;
|
|
|
93
153
|
declare const jws_verify: typeof verify;
|
|
94
154
|
declare namespace jws {
|
|
95
155
|
export { jws_sign as sign, jws_verify as verify };
|
|
96
|
-
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
156
|
+
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSKeyLookupFunction as JWSKeyLookupFunction, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
97
157
|
}
|
|
98
158
|
|
|
99
159
|
export { jws as j, sign as s, verify as v };
|
|
100
|
-
export type { JWSAlgorithm as J, JWSHeaderParameters as a, JWSProtectedHeader as b, JWSSignOptions as c, JWSVerifyResult as d, JWSVerifyOptions as e };
|
|
160
|
+
export type { JWSAlgorithm as J, JWSHeaderParameters as a, JWSProtectedHeader as b, JWSSignOptions as c, JWSVerifyResult as d, JWSVerifyOptions as e, JWSKeyLookupFunction as f };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as JWK } from './unjwt.
|
|
1
|
+
import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.mjs';
|
|
2
2
|
|
|
3
3
|
declare const textEncoder: TextEncoder;
|
|
4
4
|
declare const textDecoder: TextDecoder;
|
|
@@ -15,7 +15,9 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
|
15
15
|
* @returns Concatenated array
|
|
16
16
|
*/
|
|
17
17
|
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
18
|
+
declare function maybeArray<T>(item: T | T[]): T[];
|
|
18
19
|
declare function isJWK(key: any): key is JWK;
|
|
20
|
+
declare function isJWKSet(key: any): key is JWKSet;
|
|
19
21
|
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
20
22
|
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
21
23
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
@@ -29,6 +31,8 @@ declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
|
29
31
|
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
30
32
|
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
31
33
|
declare const index_isJWK: typeof isJWK;
|
|
34
|
+
declare const index_isJWKSet: typeof isJWKSet;
|
|
35
|
+
declare const index_maybeArray: typeof maybeArray;
|
|
32
36
|
declare const index_randomBytes: typeof randomBytes;
|
|
33
37
|
declare const index_textDecoder: typeof textDecoder;
|
|
34
38
|
declare const index_textEncoder: typeof textEncoder;
|
|
@@ -43,10 +47,12 @@ declare namespace index {
|
|
|
43
47
|
index_isCryptoKey as isCryptoKey,
|
|
44
48
|
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
45
49
|
index_isJWK as isJWK,
|
|
50
|
+
index_isJWKSet as isJWKSet,
|
|
51
|
+
index_maybeArray as maybeArray,
|
|
46
52
|
index_randomBytes as randomBytes,
|
|
47
53
|
index_textDecoder as textDecoder,
|
|
48
54
|
index_textEncoder as textEncoder,
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g,
|
|
58
|
+
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as JWK } from './unjwt.
|
|
1
|
+
import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
|
|
2
2
|
|
|
3
3
|
declare const textEncoder: TextEncoder;
|
|
4
4
|
declare const textDecoder: TextDecoder;
|
|
@@ -15,7 +15,9 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
|
15
15
|
* @returns Concatenated array
|
|
16
16
|
*/
|
|
17
17
|
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
18
|
+
declare function maybeArray<T>(item: T | T[]): T[];
|
|
18
19
|
declare function isJWK(key: any): key is JWK;
|
|
20
|
+
declare function isJWKSet(key: any): key is JWKSet;
|
|
19
21
|
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
20
22
|
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
21
23
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
@@ -29,6 +31,8 @@ declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
|
29
31
|
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
30
32
|
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
31
33
|
declare const index_isJWK: typeof isJWK;
|
|
34
|
+
declare const index_isJWKSet: typeof isJWKSet;
|
|
35
|
+
declare const index_maybeArray: typeof maybeArray;
|
|
32
36
|
declare const index_randomBytes: typeof randomBytes;
|
|
33
37
|
declare const index_textDecoder: typeof textDecoder;
|
|
34
38
|
declare const index_textEncoder: typeof textEncoder;
|
|
@@ -43,10 +47,12 @@ declare namespace index {
|
|
|
43
47
|
index_isCryptoKey as isCryptoKey,
|
|
44
48
|
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
45
49
|
index_isJWK as isJWK,
|
|
50
|
+
index_isJWKSet as isJWKSet,
|
|
51
|
+
index_maybeArray as maybeArray,
|
|
46
52
|
index_randomBytes as randomBytes,
|
|
47
53
|
index_textDecoder as textDecoder,
|
|
48
54
|
index_textEncoder as textEncoder,
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g,
|
|
58
|
+
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -178,9 +178,17 @@ interface JWK_oct extends JWKParameters {
|
|
|
178
178
|
k: string;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA" and "oct" key types are supported.
|
|
181
|
+
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC" and "oct" key types are supported.
|
|
182
182
|
*/
|
|
183
183
|
type JWK = JWK_oct | JWK_RSA | JWK_EC;
|
|
184
|
+
/**
|
|
185
|
+
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
186
|
+
*/
|
|
187
|
+
interface JWKSet {
|
|
188
|
+
/** JWK Set "keys" Parameter */
|
|
189
|
+
keys: JWK[];
|
|
190
|
+
[parameter: string]: unknown;
|
|
191
|
+
}
|
|
184
192
|
/** JWK Key Algorithms */
|
|
185
193
|
type JWK_HMAC = "HS256" | "HS384" | "HS512";
|
|
186
194
|
type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
|
|
@@ -199,4 +207,4 @@ type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA
|
|
|
199
207
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
200
208
|
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
201
209
|
|
|
202
|
-
export type {
|
|
210
|
+
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, JWKParameters as J, KeyManagementAlgorithm as K, 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 };
|
|
@@ -178,9 +178,17 @@ interface JWK_oct extends JWKParameters {
|
|
|
178
178
|
k: string;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA" and "oct" key types are supported.
|
|
181
|
+
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC" and "oct" key types are supported.
|
|
182
182
|
*/
|
|
183
183
|
type JWK = JWK_oct | JWK_RSA | JWK_EC;
|
|
184
|
+
/**
|
|
185
|
+
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
186
|
+
*/
|
|
187
|
+
interface JWKSet {
|
|
188
|
+
/** JWK Set "keys" Parameter */
|
|
189
|
+
keys: JWK[];
|
|
190
|
+
[parameter: string]: unknown;
|
|
191
|
+
}
|
|
184
192
|
/** JWK Key Algorithms */
|
|
185
193
|
type JWK_HMAC = "HS256" | "HS384" | "HS512";
|
|
186
194
|
type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
|
|
@@ -199,4 +207,4 @@ type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA
|
|
|
199
207
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
200
208
|
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
201
209
|
|
|
202
|
-
export type {
|
|
210
|
+
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, JWKParameters as J, KeyManagementAlgorithm as K, 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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
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.
|
|
1
|
+
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.D9da8HQF.mjs';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BvIkEGGz.mjs';
|
|
3
3
|
|
|
4
4
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
5
5
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -99,7 +99,7 @@ interface JWEEncryptOptions {
|
|
|
99
99
|
* @param header The JWE Protected Header.
|
|
100
100
|
* @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
|
|
101
101
|
*/
|
|
102
|
-
type JWEKeyLookupFunction = (header: JWEHeaderParameters) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
|
|
102
|
+
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
|
|
103
103
|
/**
|
|
104
104
|
* JWE (JSON Web Encryption) decryption options
|
|
105
105
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn,
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, 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, 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 } from './unjwt.D9da8HQF.mjs';
|
|
2
|
+
import { J as JoseHeaderParameters } from './unjwt.BvIkEGGz.mjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* This is a fork of Jose library's utility functions.
|
|
@@ -101,6 +102,25 @@ declare function importJWKFromPEM(pem: string, pemType: "pkcs8" | "spki" | "x509
|
|
|
101
102
|
* @returns A Promise resolving to the PEM-encoded key string.
|
|
102
103
|
*/
|
|
103
104
|
declare function exportJWKToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a JWK (JSON Web Key) from a JWKSet based on a key ID (kid) or
|
|
107
|
+
* properties from a JOSE Header.
|
|
108
|
+
*
|
|
109
|
+
* @param jwkSet The JWKSet to search within.
|
|
110
|
+
* @param kidOrProtectedHeader Either a string representing the 'kid' (Key ID)
|
|
111
|
+
* or an object representing the JOSE Protected Header. If an object is
|
|
112
|
+
* provided, it must contain a 'kid' property. It can optionally contain
|
|
113
|
+
* 'alg' (Algorithm) and 'kty' (Key Type) to further refine the search.
|
|
114
|
+
* @returns The matching JWK from the set.
|
|
115
|
+
* @throws TypeError if `jwkSet` is invalid or `kidOrProtectedHeader` is not a
|
|
116
|
+
* string or a valid header object.
|
|
117
|
+
* @throws Error if no key is found matching the provided criteria, or if the
|
|
118
|
+
* header object is missing the 'kid' property.
|
|
119
|
+
*/
|
|
120
|
+
declare function getJWKFromSet(jwkSet: JWKSet, kidOrProtectedHeader: string | (JoseHeaderParameters & {
|
|
121
|
+
alg?: string;
|
|
122
|
+
kty?: string;
|
|
123
|
+
})): JWK;
|
|
104
124
|
|
|
105
125
|
declare const jwk_CompositeKey: typeof CompositeKey;
|
|
106
126
|
declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
@@ -113,6 +133,7 @@ declare const jwk_JWK: typeof JWK;
|
|
|
113
133
|
declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
|
|
114
134
|
declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
115
135
|
declare const jwk_JWKParameters: typeof JWKParameters;
|
|
136
|
+
declare const jwk_JWKSet: typeof JWKSet;
|
|
116
137
|
declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
117
138
|
declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
118
139
|
declare const jwk_JWK_AES_GCM_KW: typeof JWK_AES_GCM_KW;
|
|
@@ -142,6 +163,7 @@ declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
|
|
|
142
163
|
declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
|
|
143
164
|
declare const jwk_exportKey: typeof exportKey;
|
|
144
165
|
declare const jwk_generateKey: typeof generateKey;
|
|
166
|
+
declare const jwk_getJWKFromSet: typeof getJWKFromSet;
|
|
145
167
|
declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
|
|
146
168
|
declare const jwk_importKey: typeof importKey;
|
|
147
169
|
declare const jwk_unwrapKey: typeof unwrapKey;
|
|
@@ -159,6 +181,7 @@ declare namespace jwk {
|
|
|
159
181
|
jwk_JWKAlgorithm as JWKAlgorithm,
|
|
160
182
|
jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
161
183
|
jwk_JWKParameters as JWKParameters,
|
|
184
|
+
jwk_JWKSet as JWKSet,
|
|
162
185
|
jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
163
186
|
jwk_JWK_AES_GCM as JWK_AES_GCM,
|
|
164
187
|
jwk_JWK_AES_GCM_KW as JWK_AES_GCM_KW,
|
|
@@ -188,6 +211,7 @@ declare namespace jwk {
|
|
|
188
211
|
jwk_exportJWKToPEM as exportJWKToPEM,
|
|
189
212
|
jwk_exportKey as exportKey,
|
|
190
213
|
jwk_generateKey as generateKey,
|
|
214
|
+
jwk_getJWKFromSet as getJWKFromSet,
|
|
191
215
|
jwk_importJWKFromPEM as importJWKFromPEM,
|
|
192
216
|
jwk_importKey as importKey,
|
|
193
217
|
jwk_unwrapKey as unwrapKey,
|
|
@@ -195,4 +219,4 @@ declare namespace jwk {
|
|
|
195
219
|
};
|
|
196
220
|
}
|
|
197
221
|
|
|
198
|
-
export { importJWKFromPEM as a, exportJWKToPEM as b, deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
222
|
+
export { importJWKFromPEM as a, exportJWKToPEM as b, getJWKFromSet as c, deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as importKey } from './unjwt.
|
|
2
|
-
import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode } from './unjwt.
|
|
3
|
-
import { s as sign$1, v as verify$1 } from './unjwt.
|
|
1
|
+
import { i as importKey, g as getJWKFromSet } from './unjwt.BPpolBff.mjs';
|
|
2
|
+
import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, e as isJWKSet, m as maybeArray } from './unjwt.X5vzu_l_.mjs';
|
|
3
|
+
import { s as sign$1, v as verify$1 } from './unjwt.CauxOPN5.mjs';
|
|
4
4
|
|
|
5
5
|
async function sign(payload, key, options = {}) {
|
|
6
6
|
const { protectedHeader: additionalProtectedHeader } = options;
|
|
@@ -48,7 +48,7 @@ async function sign(payload, key, options = {}) {
|
|
|
48
48
|
const signatureEncoded = base64UrlEncode(signatureBytes);
|
|
49
49
|
return `${signingInputString}.${signatureEncoded}`;
|
|
50
50
|
}
|
|
51
|
-
async function verify(jws, key, options) {
|
|
51
|
+
async function verify(jws, key, options = {}) {
|
|
52
52
|
const parts = jws.split(".");
|
|
53
53
|
if (parts.length !== 3) {
|
|
54
54
|
throw new Error("Invalid JWS: Must contain three parts separated by dots.");
|
|
@@ -69,9 +69,14 @@ async function verify(jws, key, options) {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
const alg = protectedHeader.alg;
|
|
72
|
-
if (options
|
|
72
|
+
if (options.algorithms && !options.algorithms.includes(alg)) {
|
|
73
73
|
throw new Error(`Algorithm not allowed: ${alg}`);
|
|
74
74
|
}
|
|
75
|
+
if (options.typ && protectedHeader.typ !== options.typ) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Invalid JWS: "typ" (Type) Header Parameter mismatch. Expected "${options.typ}", got "${protectedHeader.typ}".`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
75
80
|
let signatureBytes;
|
|
76
81
|
try {
|
|
77
82
|
signatureBytes = base64UrlDecode(signatureEncoded, false);
|
|
@@ -80,7 +85,8 @@ async function verify(jws, key, options) {
|
|
|
80
85
|
`Invalid JWS: Signature is not valid Base64URL (${error_ instanceof Error ? error_.message : error_})`
|
|
81
86
|
);
|
|
82
87
|
}
|
|
83
|
-
const
|
|
88
|
+
const keyInput = typeof key === "function" ? await key(protectedHeader, jws) : key;
|
|
89
|
+
const resolvedKey = isJWKSet(keyInput) ? getJWKFromSet(keyInput, protectedHeader) : keyInput;
|
|
84
90
|
const verificationKey = await importKey(resolvedKey, alg);
|
|
85
91
|
const signingInputString = `${protectedHeaderEncoded}.${payloadEncoded}`;
|
|
86
92
|
const signingInputBytes = textEncoder.encode(signingInputString);
|
|
@@ -97,13 +103,13 @@ async function verify(jws, key, options) {
|
|
|
97
103
|
let payload;
|
|
98
104
|
try {
|
|
99
105
|
if (useB64) {
|
|
100
|
-
if (options
|
|
106
|
+
if (options.forceUint8Array) {
|
|
101
107
|
payload = base64UrlDecode(payloadEncoded, false);
|
|
102
108
|
} else {
|
|
103
109
|
const cty = protectedHeader.cty?.toLowerCase();
|
|
104
110
|
const isJsonOutput = protectedHeader.typ === "JWT" || cty === "json" || cty === "application/json" || cty && cty.endsWith("+json");
|
|
111
|
+
const decodedString = base64UrlDecode(payloadEncoded);
|
|
105
112
|
if (isJsonOutput) {
|
|
106
|
-
const decodedString = base64UrlDecode(payloadEncoded, true);
|
|
107
113
|
if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) {
|
|
108
114
|
try {
|
|
109
115
|
payload = JSON.parse(decodedString);
|
|
@@ -114,21 +120,23 @@ async function verify(jws, key, options) {
|
|
|
114
120
|
payload = decodedString;
|
|
115
121
|
}
|
|
116
122
|
} else {
|
|
117
|
-
payload =
|
|
123
|
+
payload = decodedString;
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
} else {
|
|
121
|
-
payload = textEncoder.encode(payloadEncoded);
|
|
127
|
+
payload = options.forceUint8Array ? textEncoder.encode(payloadEncoded) : payloadEncoded;
|
|
122
128
|
}
|
|
123
129
|
} catch (error_) {
|
|
124
130
|
throw new Error(
|
|
125
131
|
`Invalid JWS: Payload decoding failed (${error_ instanceof Error ? error_.message : error_})`
|
|
126
132
|
);
|
|
127
133
|
}
|
|
128
|
-
if (
|
|
134
|
+
if (protectedHeader.crit) {
|
|
135
|
+
const missingHeaderParams = /* @__PURE__ */ new Set();
|
|
129
136
|
const recognizedParams = /* @__PURE__ */ new Set([
|
|
130
|
-
...Object.keys(protectedHeader),
|
|
131
137
|
...options.critical || [],
|
|
138
|
+
// TODO: remove deprecated option
|
|
139
|
+
...options.requiredHeaders || [],
|
|
132
140
|
"alg",
|
|
133
141
|
"typ",
|
|
134
142
|
"cty",
|
|
@@ -140,17 +148,88 @@ async function verify(jws, key, options) {
|
|
|
140
148
|
"x5u",
|
|
141
149
|
"b64"
|
|
142
150
|
]);
|
|
143
|
-
for (const
|
|
144
|
-
if (
|
|
151
|
+
for (const param of protectedHeader.crit) {
|
|
152
|
+
if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
missingHeaderParams.add(param);
|
|
156
|
+
}
|
|
157
|
+
if (missingHeaderParams.size > 0) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (payload && typeof payload === "object" && !options.forceUint8Array) {
|
|
164
|
+
const jwtClaims = payload;
|
|
165
|
+
const clockTolerance = (options.clockTolerance ?? 0) * 1e3;
|
|
166
|
+
const currentDate = options.currentDate ?? /* @__PURE__ */ new Date();
|
|
167
|
+
const currentTime = currentDate.getTime();
|
|
168
|
+
const allRequiredClaims = new Set(options.requiredClaims || []);
|
|
169
|
+
const missingClaims = /* @__PURE__ */ new Set();
|
|
170
|
+
if (options.issuer) allRequiredClaims.add("iss");
|
|
171
|
+
if (options.audience) allRequiredClaims.add("aud");
|
|
172
|
+
if (options.subject) allRequiredClaims.add("sub");
|
|
173
|
+
if (options.maxTokenAge) allRequiredClaims.add("iat");
|
|
174
|
+
for (const claimName of allRequiredClaims) {
|
|
175
|
+
if (!(claimName in jwtClaims)) {
|
|
176
|
+
missingClaims.add(claimName);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (missingClaims.size > 0) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Missing required JWT Claims: ${[...missingClaims].join(", ")}`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (options.issuer) {
|
|
185
|
+
const expectedIssuers = maybeArray(options.issuer);
|
|
186
|
+
if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) {
|
|
145
187
|
throw new Error(
|
|
146
|
-
`
|
|
188
|
+
`Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (options.subject && jwtClaims.sub !== options.subject) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (options.audience) {
|
|
198
|
+
const expectedAudiences = maybeArray(options.audience);
|
|
199
|
+
const claimAudience = maybeArray(jwtClaims.aud || []);
|
|
200
|
+
if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf * 1e3 > currentTime + clockTolerance) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${new Date(jwtClaims.nbf * 1e3).toISOString()})`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (typeof jwtClaims.exp === "number" && jwtClaims.exp * 1e3 <= currentTime - clockTolerance) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${new Date(jwtClaims.exp * 1e3).toISOString()})`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
if (options.maxTokenAge) {
|
|
217
|
+
if (typeof jwtClaims.iat !== "number") {
|
|
218
|
+
throw new TypeError(
|
|
219
|
+
'JWT "iat" (Issued At) Claim must be a number when maxTokenAge is set.'
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (jwtClaims.iat * 1e3 > currentTime + clockTolerance) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
if (jwtClaims.iat * 1e3 < currentTime - options.maxTokenAge * 1e3 - clockTolerance) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
|
|
147
230
|
);
|
|
148
231
|
}
|
|
149
232
|
}
|
|
150
|
-
} else if (!options?.critical && protectedHeader.crit) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
`Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`
|
|
153
|
-
);
|
|
154
233
|
}
|
|
155
234
|
return {
|
|
156
235
|
payload,
|
|
@@ -51,9 +51,15 @@ function concatUint8Arrays(...arrays) {
|
|
|
51
51
|
}
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
|
+
function maybeArray(item) {
|
|
55
|
+
return Array.isArray(item) ? item : [item];
|
|
56
|
+
}
|
|
54
57
|
function isJWK(key) {
|
|
55
58
|
return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
|
|
56
59
|
}
|
|
60
|
+
function isJWKSet(key) {
|
|
61
|
+
return key && typeof key === "object" && "keys" in key && Array.isArray(key.keys);
|
|
62
|
+
}
|
|
57
63
|
function assertCryptoKey(key) {
|
|
58
64
|
if (!isCryptoKey(key)) {
|
|
59
65
|
throw new Error("CryptoKey instance expected");
|
|
@@ -75,9 +81,11 @@ const index = {
|
|
|
75
81
|
isCryptoKey: isCryptoKey,
|
|
76
82
|
isCryptoKeyPair: isCryptoKeyPair,
|
|
77
83
|
isJWK: isJWK,
|
|
84
|
+
isJWKSet: isJWKSet,
|
|
85
|
+
maybeArray: maybeArray,
|
|
78
86
|
randomBytes: randomBytes,
|
|
79
87
|
textDecoder: textDecoder,
|
|
80
88
|
textEncoder: textEncoder
|
|
81
89
|
};
|
|
82
90
|
|
|
83
|
-
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d,
|
|
91
|
+
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, isJWKSet as e, concatUint8Arrays as f, assertCryptoKey as g, isCryptoKey as h, index as i, base64Decode as j, base64Encode as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.D9da8HQF.mjs';
|
|
2
|
+
export { j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.CbvzYE-m.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.D9da8HQF.js';
|
|
2
|
+
export { j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.D4DUiNeM.js';
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { g as assertCryptoKey, j as base64Decode, k as base64Encode, d as base64UrlDecode, b as base64UrlEncode, f as concatUint8Arrays, h as isCryptoKey, l as isCryptoKeyPair, a as isJWK, e as isJWKSet, m as maybeArray, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.X5vzu_l_.mjs';
|