unjwt 0.5.0 → 0.5.2
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 +89 -4
- 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 +2 -2
- package/dist/jwk.d.ts +2 -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.BKG_8Y9G.d.ts → unjwt.B0XDPf8a.d.ts} +2 -2
- package/dist/shared/{unjwt.CJ_ohCFC.d.mts → unjwt.B5N3dPN9.d.ts} +13 -4
- package/dist/shared/{unjwt.DoVzOnty.d.ts → unjwt.BISJ5yt1.d.ts} +1 -1
- package/dist/shared/{unjwt.mc4AEAT7.d.ts → unjwt.BJEchXrM.d.mts} +13 -4
- package/dist/shared/{unjwt.B4e_rwol.mjs → unjwt.ByclPbtq.mjs} +3 -3
- package/dist/shared/{unjwt.Bzcov22m.mjs → unjwt.COPr8ebc.mjs} +98 -20
- package/dist/shared/{unjwt.D90BbcE1.d.mts → unjwt.Cd9nTEWg.d.mts} +1 -1
- package/dist/shared/{unjwt.C0bBN0AC.d.mts → unjwt.CxhGjEAX.d.mts} +3 -1
- package/dist/shared/{unjwt.C0bBN0AC.d.ts → unjwt.CxhGjEAX.d.ts} +3 -1
- package/dist/shared/{unjwt.BOEZHxi_.d.ts → unjwt.D1J1DelP.d.mts} +46 -2
- package/dist/shared/{unjwt.CjHZv3F3.mjs → unjwt.DOI5UE8K.mjs} +32 -2
- package/dist/shared/{unjwt.Dz5Oe9BG.d.mts → unjwt.DQIYSlHj.d.mts} +2 -2
- package/dist/shared/{unjwt.ppm5Y0k7.d.ts → unjwt.TbszLNOP.d.ts} +57 -4
- package/dist/shared/{unjwt.B9uGngq-.d.mts → unjwt.WvWb2zNM.d.ts} +46 -2
- package/dist/shared/{unjwt.DKq5VF7t.mjs → unjwt.ZsOShfhX.mjs} +325 -4
- package/dist/shared/{unjwt.DYFIh1YE.d.mts → unjwt.kiNPBQh0.d.mts} +57 -4
- package/dist/shared/{unjwt.sux3_Z19.mjs → unjwt.z_U3fRJ-.mjs} +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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# unjwt
|
|
2
2
|
|
|
3
|
-
<!-- automd:badges color=
|
|
3
|
+
<!-- automd:badges bundlephobia style="flat" color="FFDC3B" -->
|
|
4
4
|
|
|
5
|
-
[](https://npmjs.com/package/unjwt)
|
|
6
|
+
[](https://npm.chart.dev/unjwt)
|
|
7
|
+
[](https://bundlephobia.com/package/unjwt)
|
|
7
8
|
|
|
8
9
|
<!-- /automd -->
|
|
9
10
|
|
|
@@ -13,6 +14,14 @@ A collection of low-level JWT ([RFC 7519](https://datatracker.ietf.org/doc/html/
|
|
|
13
14
|
- **JWE (JSON Web Encryption, [RFC 7516](https://datatracker.ietf.org/doc/html/rfc7516))**: encrypt and decrypt data using various key management algorithms (AES Key Wrap, AES-GCM Key Wrap, RSA-OAEP, PBES2, ECDH-ES) and content encryption algorithms (AES-GCM, AES-CBC HMAC-SHA2).
|
|
14
15
|
- **JWK (JSON Web Key, [RFC 7517](https://datatracker.ietf.org/doc/html/rfc7517))**: generate, import, export, wrap, and unwrap keys in JWK format or as `CryptoKey` objects.
|
|
15
16
|
|
|
17
|
+
> [!WARNING]
|
|
18
|
+
> Please do note that some algorithms are not fully working out-of-the-box yet, such as:
|
|
19
|
+
>
|
|
20
|
+
> - ECDH-ES algorithms with AES Key Wrap (e.g., ECDH-ES+A128KW)
|
|
21
|
+
> - RSA algorithms in combination with some bigger CBC encodings (for example RSA-OAEP-256 with A256CBC-HS512)
|
|
22
|
+
>
|
|
23
|
+
> For these algorithms, you should be able to provide your own keys. Although I do plan to study and simplify this.
|
|
24
|
+
|
|
16
25
|
## Usage
|
|
17
26
|
|
|
18
27
|
Install the package:
|
|
@@ -48,8 +57,8 @@ import { base64UrlEncode, base64UrlDecode, randomBytes } from "unjwt/utils";
|
|
|
48
57
|
**CDN** (Deno, Bun and Browsers)
|
|
49
58
|
|
|
50
59
|
```js
|
|
51
|
-
// JWS functions
|
|
52
60
|
import { jws, jwe, jwk } from "https://esm.sh/unjwt";
|
|
61
|
+
// JWS functions
|
|
53
62
|
import { sign, verify } from "https://esm.sh/unjwt/jws";
|
|
54
63
|
// JWE functions
|
|
55
64
|
import { encrypt, decrypt } from "https://esm.sh/unjwt/jwe";
|
|
@@ -488,6 +497,82 @@ async function unwrapMyKey(encryptedKey: Uint8Array, kdk: CryptoKey) {
|
|
|
488
497
|
}
|
|
489
498
|
```
|
|
490
499
|
|
|
500
|
+
#### `importJWKFromPEM(pem, pemType, alg, importOptions?, jwkExtras?)`
|
|
501
|
+
|
|
502
|
+
Imports a key from a PEM-encoded string and converts it to a JWK.
|
|
503
|
+
|
|
504
|
+
- `pem`: The PEM-encoded string (including `-----BEGIN ...-----` and `-----END ...-----` markers).
|
|
505
|
+
- `pemType`: The type of PEM encoding:
|
|
506
|
+
- `"pkcs8"`: For private keys in PKCS#8 format.
|
|
507
|
+
- `"spki"`: For public keys in SPKI format.
|
|
508
|
+
- `"x509"`: For X.509 certificates (extracts the public key).
|
|
509
|
+
- `alg`: The JWA algorithm identifier (e.g., `"RS256"`, `"ES256"`). This is crucial for `crypto.subtle.importKey` to understand the key's intended algorithm and for setting the `'alg'` field in the resulting JWK.
|
|
510
|
+
- `importOptions` (optional): Options for the underlying `crypto.subtle.importKey` call:
|
|
511
|
+
- `extractable`: Boolean, whether the imported `CryptoKey` should be extractable. Defaults to `true`.
|
|
512
|
+
- `keyUsage`: Array of `KeyUsage` strings for the imported `CryptoKey`.
|
|
513
|
+
- `jwkExtras` (optional): An object containing additional properties to merge into the resulting JWK (e.g., `"kid"`, `"use"`).
|
|
514
|
+
|
|
515
|
+
Returns a `Promise<JWK>` resolving to the imported key as a JWK.
|
|
516
|
+
|
|
517
|
+
**Example:**
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
import { importJWKFromPEM } from "unjwt/jwk";
|
|
521
|
+
|
|
522
|
+
const rsaPublicJwk = await importJWKFromPEM(
|
|
523
|
+
provess.env.RSA_PEM_SPKI, // PEM string
|
|
524
|
+
"spki",
|
|
525
|
+
"RS256",
|
|
526
|
+
{ extractable: false },
|
|
527
|
+
{ kid: "my-rsa-key" }, // Additional properties to add to the JWK
|
|
528
|
+
);
|
|
529
|
+
console.log(rsaPublicJwk);
|
|
530
|
+
// {
|
|
531
|
+
// kty: 'RSA',
|
|
532
|
+
// alg: 'RS256',
|
|
533
|
+
// kid: 'my-rsa-key',
|
|
534
|
+
// n: '...',
|
|
535
|
+
// e: 'AQAB',
|
|
536
|
+
// ext: false,
|
|
537
|
+
// key_ops: [ 'verify' ]
|
|
538
|
+
// }
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
#### exportJWKToPEM(jwk, pemFormat, algForCryptoKeyImport?)
|
|
542
|
+
|
|
543
|
+
Exports a JWK to a PEM-encoded string.
|
|
544
|
+
|
|
545
|
+
- jwk: The JWK to export.
|
|
546
|
+
- pemFormat: The desired PEM format:
|
|
547
|
+
- "pkcs8": For private keys in PKCS#8 format.
|
|
548
|
+
- "spki": For public keys in SPKI format.
|
|
549
|
+
- algForCryptoKeyImport (optional): If the JWK does not have an 'alg' property, this algorithm hint is required to correctly convert it to a CryptoKey first. This is only needed if the JWK lacks an alg property.
|
|
550
|
+
|
|
551
|
+
Returns a `Promise<string>` resolving to the PEM-encoded key string.
|
|
552
|
+
|
|
553
|
+
Example:
|
|
554
|
+
|
|
555
|
+
```ts
|
|
556
|
+
import { exportJWKToPEM } from "unjwt/jwk";
|
|
557
|
+
import { rsaJWK } from "./keys"; // Assuming you have JWKs in keys.ts
|
|
558
|
+
|
|
559
|
+
const rsaPrivatePem = await exportJWKToPEM(rsaJWK.private, "pkcs8");
|
|
560
|
+
console.log(rsaPrivatePem);
|
|
561
|
+
// -----BEGIN PRIVATE KEY-----
|
|
562
|
+
// MII...
|
|
563
|
+
// -----END PRIVATE KEY-----
|
|
564
|
+
|
|
565
|
+
const rsaPublicSpki = await exportJWKToPEM(
|
|
566
|
+
rsaJWK.public,
|
|
567
|
+
"spki",
|
|
568
|
+
"RS256", // this is required if `rsaJWK.public.alg` is undefined
|
|
569
|
+
);
|
|
570
|
+
console.log(rsaPublicSpki);
|
|
571
|
+
// -----BEGIN PUBLIC KEY-----
|
|
572
|
+
// MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQE...
|
|
573
|
+
// -----END PUBLIC KEY-----
|
|
574
|
+
```
|
|
575
|
+
|
|
491
576
|
### Utility Functions
|
|
492
577
|
|
|
493
578
|
`unjwt/utils` exports several helpful functions:
|
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, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.mjs';
|
|
2
|
+
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.Cd9nTEWg.mjs';
|
|
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.kiNPBQh0.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.DQIYSlHj.mjs';
|
|
5
|
+
export { i as utils } from './shared/unjwt.BJEchXrM.mjs';
|
|
6
|
+
export { j as jwk } from './shared/unjwt.D1J1DelP.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, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.js';
|
|
2
|
+
export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.BISJ5yt1.js';
|
|
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.TbszLNOP.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.B0XDPf8a.js';
|
|
5
|
+
export { i as utils } from './shared/unjwt.B5N3dPN9.js';
|
|
6
|
+
export { j as jwk } from './shared/unjwt.WvWb2zNM.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.DOI5UE8K.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.ByclPbtq.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.ZsOShfhX.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.COPr8ebc.mjs';
|
|
5
|
+
import './shared/unjwt.z_U3fRJ-.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.CxhGjEAX.mjs';
|
|
2
|
+
import './shared/unjwt.Cd9nTEWg.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.DQIYSlHj.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.CxhGjEAX.js';
|
|
2
|
+
import './shared/unjwt.BISJ5yt1.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.B0XDPf8a.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.ZsOShfhX.mjs';
|
|
2
|
+
import './shared/unjwt.DOI5UE8K.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.ByclPbtq.mjs';
|
|
4
|
+
import './shared/unjwt.z_U3fRJ-.mjs';
|
package/dist/jwk.d.mts
CHANGED
|
@@ -1,2 +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,
|
|
2
|
-
export { d as deriveKeyFromPassword, e as exportKey, g as generateKey, i as importKey, u as unwrapKey, w as wrapKey } 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, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.mjs';
|
|
2
|
+
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.D1J1DelP.mjs';
|
package/dist/jwk.d.ts
CHANGED
|
@@ -1,2 +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,
|
|
2
|
-
export { d as deriveKeyFromPassword, e as exportKey, g as generateKey, i as importKey, u as unwrapKey, w as wrapKey } 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, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.js';
|
|
2
|
+
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.WvWb2zNM.js';
|
package/dist/jwk.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export { o as deriveKeyFromPassword, p as exportKey, n as generateKey, i as importKey, l as unwrapKey, q as wrapKey } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.DOI5UE8K.mjs';
|
|
2
|
+
export { o as deriveKeyFromPassword, s as exportJWKToPEM, p as exportKey, n as generateKey, r as importJWKFromPEM, i as importKey, l as unwrapKey, q as wrapKey } from './shared/unjwt.ZsOShfhX.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.CxhGjEAX.mjs';
|
|
2
|
+
import './shared/unjwt.Cd9nTEWg.mjs';
|
|
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.kiNPBQh0.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.CxhGjEAX.js';
|
|
2
|
+
import './shared/unjwt.BISJ5yt1.js';
|
|
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.TbszLNOP.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.ZsOShfhX.mjs';
|
|
2
|
+
import './shared/unjwt.DOI5UE8K.mjs';
|
|
3
|
+
import './shared/unjwt.z_U3fRJ-.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.COPr8ebc.mjs';
|
|
@@ -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.CxhGjEAX.js';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BISJ5yt1.js';
|
|
3
3
|
|
|
4
4
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
5
5
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { m as JWK } from './unjwt.
|
|
1
|
+
import { m as JWK } from './unjwt.CxhGjEAX.js';
|
|
2
2
|
|
|
3
3
|
declare const textEncoder: TextEncoder;
|
|
4
4
|
declare const textDecoder: TextDecoder;
|
|
5
|
+
declare function base64Encode(data: Uint8Array | string): string;
|
|
5
6
|
declare function base64UrlEncode(data: Uint8Array | string): string;
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
7
|
+
declare function base64Decode(str: string | undefined): string;
|
|
8
|
+
declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
9
|
+
declare function base64UrlDecode(str: string | undefined): string;
|
|
8
10
|
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
9
11
|
declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
10
12
|
/**
|
|
@@ -13,34 +15,41 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
|
13
15
|
* @returns Concatenated array
|
|
14
16
|
*/
|
|
15
17
|
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
18
|
+
declare function maybeArray<T>(item: T | T[]): T[];
|
|
16
19
|
declare function isJWK(key: any): key is JWK;
|
|
17
20
|
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
18
21
|
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
19
22
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
20
23
|
|
|
21
24
|
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
25
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
26
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
22
27
|
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
23
28
|
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
24
29
|
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
25
30
|
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
26
31
|
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
27
32
|
declare const index_isJWK: typeof isJWK;
|
|
33
|
+
declare const index_maybeArray: typeof maybeArray;
|
|
28
34
|
declare const index_randomBytes: typeof randomBytes;
|
|
29
35
|
declare const index_textDecoder: typeof textDecoder;
|
|
30
36
|
declare const index_textEncoder: typeof textEncoder;
|
|
31
37
|
declare namespace index {
|
|
32
38
|
export {
|
|
33
39
|
index_assertCryptoKey as assertCryptoKey,
|
|
40
|
+
index_base64Decode as base64Decode,
|
|
41
|
+
index_base64Encode as base64Encode,
|
|
34
42
|
index_base64UrlDecode as base64UrlDecode,
|
|
35
43
|
index_base64UrlEncode as base64UrlEncode,
|
|
36
44
|
index_concatUint8Arrays as concatUint8Arrays,
|
|
37
45
|
index_isCryptoKey as isCryptoKey,
|
|
38
46
|
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
39
47
|
index_isJWK as isJWK,
|
|
48
|
+
index_maybeArray as maybeArray,
|
|
40
49
|
index_randomBytes as randomBytes,
|
|
41
50
|
index_textDecoder as textDecoder,
|
|
42
51
|
index_textEncoder as textEncoder,
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
export { textDecoder as a,
|
|
55
|
+
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { m as JWK } from './unjwt.
|
|
1
|
+
import { m as JWK } from './unjwt.CxhGjEAX.mjs';
|
|
2
2
|
|
|
3
3
|
declare const textEncoder: TextEncoder;
|
|
4
4
|
declare const textDecoder: TextDecoder;
|
|
5
|
+
declare function base64Encode(data: Uint8Array | string): string;
|
|
5
6
|
declare function base64UrlEncode(data: Uint8Array | string): string;
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
7
|
+
declare function base64Decode(str: string | undefined): string;
|
|
8
|
+
declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
9
|
+
declare function base64UrlDecode(str: string | undefined): string;
|
|
8
10
|
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
9
11
|
declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
10
12
|
/**
|
|
@@ -13,34 +15,41 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
|
13
15
|
* @returns Concatenated array
|
|
14
16
|
*/
|
|
15
17
|
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
18
|
+
declare function maybeArray<T>(item: T | T[]): T[];
|
|
16
19
|
declare function isJWK(key: any): key is JWK;
|
|
17
20
|
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
18
21
|
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
19
22
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
20
23
|
|
|
21
24
|
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
25
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
26
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
22
27
|
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
23
28
|
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
24
29
|
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
25
30
|
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
26
31
|
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
27
32
|
declare const index_isJWK: typeof isJWK;
|
|
33
|
+
declare const index_maybeArray: typeof maybeArray;
|
|
28
34
|
declare const index_randomBytes: typeof randomBytes;
|
|
29
35
|
declare const index_textDecoder: typeof textDecoder;
|
|
30
36
|
declare const index_textEncoder: typeof textEncoder;
|
|
31
37
|
declare namespace index {
|
|
32
38
|
export {
|
|
33
39
|
index_assertCryptoKey as assertCryptoKey,
|
|
40
|
+
index_base64Decode as base64Decode,
|
|
41
|
+
index_base64Encode as base64Encode,
|
|
34
42
|
index_base64UrlDecode as base64UrlDecode,
|
|
35
43
|
index_base64UrlEncode as base64UrlEncode,
|
|
36
44
|
index_concatUint8Arrays as concatUint8Arrays,
|
|
37
45
|
index_isCryptoKey as isCryptoKey,
|
|
38
46
|
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
39
47
|
index_isJWK as isJWK,
|
|
48
|
+
index_maybeArray as maybeArray,
|
|
40
49
|
index_randomBytes as randomBytes,
|
|
41
50
|
index_textDecoder as textDecoder,
|
|
42
51
|
index_textEncoder as textEncoder,
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
export { textDecoder as a,
|
|
55
|
+
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as checkEncCryptoKey, u as uint32be, g as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, b as bitLengthCEK, d as jwkTokey, i as importKey, f as generateIV, h as encrypt$1, l as unwrapKey, m as decrypt$1 } from './unjwt.
|
|
2
|
-
import { e as concatUint8Arrays, t as textEncoder, f as assertCryptoKey, b as base64UrlEncode, g as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.
|
|
3
|
-
import { c as checkKeyLength } from './unjwt.
|
|
1
|
+
import { a as checkEncCryptoKey, u as uint32be, g as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, b as bitLengthCEK, d as jwkTokey, i as importKey, f as generateIV, h as encrypt$1, l as unwrapKey, m as decrypt$1 } from './unjwt.ZsOShfhX.mjs';
|
|
2
|
+
import { e as concatUint8Arrays, t as textEncoder, f as assertCryptoKey, b as base64UrlEncode, g as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.DOI5UE8K.mjs';
|
|
3
|
+
import { c as checkKeyLength } from './unjwt.z_U3fRJ-.mjs';
|
|
4
4
|
|
|
5
5
|
function lengthAndInput(input) {
|
|
6
6
|
return concatUint8Arrays(uint32be(input.length), input);
|
|
@@ -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 } from './unjwt.ZsOShfhX.mjs';
|
|
2
|
+
import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, m as maybeArray } from './unjwt.DOI5UE8K.mjs';
|
|
3
|
+
import { s as sign$1, v as verify$1 } from './unjwt.z_U3fRJ-.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.");
|
|
@@ -56,8 +56,8 @@ async function verify(jws, key, options) {
|
|
|
56
56
|
const [protectedHeaderEncoded, payloadEncoded, signatureEncoded] = parts;
|
|
57
57
|
let protectedHeader;
|
|
58
58
|
try {
|
|
59
|
-
const
|
|
60
|
-
protectedHeader = JSON.parse(
|
|
59
|
+
const protectedHeaderString = base64UrlDecode(protectedHeaderEncoded);
|
|
60
|
+
protectedHeader = JSON.parse(protectedHeaderString);
|
|
61
61
|
} catch (error_) {
|
|
62
62
|
throw new Error(
|
|
63
63
|
`Invalid JWS: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
@@ -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);
|
|
@@ -97,13 +102,13 @@ async function verify(jws, key, options) {
|
|
|
97
102
|
let payload;
|
|
98
103
|
try {
|
|
99
104
|
if (useB64) {
|
|
100
|
-
if (options
|
|
105
|
+
if (options.forceUint8Array) {
|
|
101
106
|
payload = base64UrlDecode(payloadEncoded, false);
|
|
102
107
|
} else {
|
|
103
108
|
const cty = protectedHeader.cty?.toLowerCase();
|
|
104
109
|
const isJsonOutput = protectedHeader.typ === "JWT" || cty === "json" || cty === "application/json" || cty && cty.endsWith("+json");
|
|
110
|
+
const decodedString = base64UrlDecode(payloadEncoded);
|
|
105
111
|
if (isJsonOutput) {
|
|
106
|
-
const decodedString = base64UrlDecode(payloadEncoded, true);
|
|
107
112
|
if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) {
|
|
108
113
|
try {
|
|
109
114
|
payload = JSON.parse(decodedString);
|
|
@@ -114,21 +119,23 @@ async function verify(jws, key, options) {
|
|
|
114
119
|
payload = decodedString;
|
|
115
120
|
}
|
|
116
121
|
} else {
|
|
117
|
-
payload =
|
|
122
|
+
payload = decodedString;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
} else {
|
|
121
|
-
payload = textEncoder.encode(payloadEncoded);
|
|
126
|
+
payload = options.forceUint8Array ? textEncoder.encode(payloadEncoded) : payloadEncoded;
|
|
122
127
|
}
|
|
123
128
|
} catch (error_) {
|
|
124
129
|
throw new Error(
|
|
125
130
|
`Invalid JWS: Payload decoding failed (${error_ instanceof Error ? error_.message : error_})`
|
|
126
131
|
);
|
|
127
132
|
}
|
|
128
|
-
if (
|
|
133
|
+
if (protectedHeader.crit) {
|
|
134
|
+
const missingHeaderParams = /* @__PURE__ */ new Set();
|
|
129
135
|
const recognizedParams = /* @__PURE__ */ new Set([
|
|
130
|
-
...Object.keys(protectedHeader),
|
|
131
136
|
...options.critical || [],
|
|
137
|
+
// TODO: remove deprecated option
|
|
138
|
+
...options.requiredHeaders || [],
|
|
132
139
|
"alg",
|
|
133
140
|
"typ",
|
|
134
141
|
"cty",
|
|
@@ -140,17 +147,88 @@ async function verify(jws, key, options) {
|
|
|
140
147
|
"x5u",
|
|
141
148
|
"b64"
|
|
142
149
|
]);
|
|
143
|
-
for (const
|
|
144
|
-
if (
|
|
150
|
+
for (const param of protectedHeader.crit) {
|
|
151
|
+
if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
missingHeaderParams.add(param);
|
|
155
|
+
}
|
|
156
|
+
if (missingHeaderParams.size > 0) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (payload && typeof payload === "object" && !options.forceUint8Array) {
|
|
163
|
+
const jwtClaims = payload;
|
|
164
|
+
const clockTolerance = (options.clockTolerance ?? 0) * 1e3;
|
|
165
|
+
const currentDate = options.currentDate ?? /* @__PURE__ */ new Date();
|
|
166
|
+
const currentTime = currentDate.getTime();
|
|
167
|
+
const allRequiredClaims = new Set(options.requiredClaims || []);
|
|
168
|
+
const missingClaims = /* @__PURE__ */ new Set();
|
|
169
|
+
if (options.issuer) allRequiredClaims.add("iss");
|
|
170
|
+
if (options.audience) allRequiredClaims.add("aud");
|
|
171
|
+
if (options.subject) allRequiredClaims.add("sub");
|
|
172
|
+
if (options.maxTokenAge) allRequiredClaims.add("iat");
|
|
173
|
+
for (const claimName of allRequiredClaims) {
|
|
174
|
+
if (!(claimName in jwtClaims)) {
|
|
175
|
+
missingClaims.add(claimName);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (missingClaims.size > 0) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Missing required JWT Claims: ${[...missingClaims].join(", ")}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (options.issuer) {
|
|
184
|
+
const expectedIssuers = maybeArray(options.issuer);
|
|
185
|
+
if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) {
|
|
145
186
|
throw new Error(
|
|
146
|
-
`
|
|
187
|
+
`Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (options.subject && jwtClaims.sub !== options.subject) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (options.audience) {
|
|
197
|
+
const expectedAudiences = maybeArray(options.audience);
|
|
198
|
+
const claimAudience = maybeArray(jwtClaims.aud || []);
|
|
199
|
+
if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf * 1e3 > currentTime + clockTolerance) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${new Date(jwtClaims.nbf * 1e3).toISOString()})`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
if (typeof jwtClaims.exp === "number" && jwtClaims.exp * 1e3 <= currentTime - clockTolerance) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${new Date(jwtClaims.exp * 1e3).toISOString()})`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (options.maxTokenAge) {
|
|
216
|
+
if (typeof jwtClaims.iat !== "number") {
|
|
217
|
+
throw new TypeError(
|
|
218
|
+
'JWT "iat" (Issued At) Claim must be a number when maxTokenAge is set.'
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
if (jwtClaims.iat * 1e3 > currentTime + clockTolerance) {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (jwtClaims.iat * 1e3 < currentTime - options.maxTokenAge * 1e3 - clockTolerance) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
|
|
147
229
|
);
|
|
148
230
|
}
|
|
149
231
|
}
|
|
150
|
-
} else if (!options?.critical && protectedHeader.crit) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
`Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`
|
|
153
|
-
);
|
|
154
232
|
}
|
|
155
233
|
return {
|
|
156
234
|
payload,
|
|
@@ -193,8 +193,10 @@ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
|
|
|
193
193
|
type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
|
|
194
194
|
type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
195
195
|
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
196
|
+
type JWK_ED = "Ed25519" | "EdDSA";
|
|
196
197
|
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
197
198
|
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
198
199
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
200
|
+
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
199
201
|
|
|
200
|
-
export type {
|
|
202
|
+
export type { JWK_Asymmetric_Algorithm as A, JWKAlgorithm as B, CompositeKey as C, DeriveKeyOptions as D, JWKPEMAlgorithm as E, 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, JWK_HMAC as n, JWK_RSA_SIGN as o, JWK_RSA_PSS as p, JWK_ECDSA as q, JWK_RSA_ENC as r, JWK_AES_KW as s, JWK_AES_GCM_KW as t, JWK_AES_CBC_HMAC as u, JWK_AES_GCM as v, JWK_PBES2 as w, JWK_ECDH_ES as x, JWK_ED as y, JWK_Symmetric_Algorithm as z };
|
|
@@ -193,8 +193,10 @@ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
|
|
|
193
193
|
type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
|
|
194
194
|
type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
195
195
|
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
196
|
+
type JWK_ED = "Ed25519" | "EdDSA";
|
|
196
197
|
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
197
198
|
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
198
199
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
200
|
+
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
199
201
|
|
|
200
|
-
export type {
|
|
202
|
+
export type { JWK_Asymmetric_Algorithm as A, JWKAlgorithm as B, CompositeKey as C, DeriveKeyOptions as D, JWKPEMAlgorithm as E, 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, JWK_HMAC as n, JWK_RSA_SIGN as o, JWK_RSA_PSS as p, JWK_ECDSA as q, JWK_RSA_ENC as r, JWK_AES_KW as s, JWK_AES_GCM_KW as t, JWK_AES_CBC_HMAC as u, JWK_AES_GCM as v, JWK_PBES2 as w, JWK_ECDH_ES as x, JWK_ED as y, JWK_Symmetric_Algorithm as z };
|