unjwt 0.5.0 → 0.5.1
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.DKq5VF7t.mjs → unjwt.1gbuWbc6.mjs} +325 -4
- package/dist/shared/{unjwt.BKG_8Y9G.d.ts → unjwt.B0XDPf8a.d.ts} +2 -2
- package/dist/shared/{unjwt.mc4AEAT7.d.ts → unjwt.B4fFiy1c.d.mts} +10 -4
- package/dist/shared/{unjwt.DYFIh1YE.d.mts → unjwt.BG_R52ey.d.mts} +2 -2
- package/dist/shared/{unjwt.DoVzOnty.d.ts → unjwt.BISJ5yt1.d.ts} +1 -1
- package/dist/shared/{unjwt.Bzcov22m.mjs → unjwt.BxqF-n1S.mjs} +5 -5
- package/dist/shared/{unjwt.sux3_Z19.mjs → unjwt.C9Xhi7hE.mjs} +1 -1
- package/dist/shared/{unjwt.ppm5Y0k7.d.ts → unjwt.CVKbKOFy.d.ts} +2 -2
- package/dist/shared/{unjwt.D90BbcE1.d.mts → unjwt.Cd9nTEWg.d.mts} +1 -1
- package/dist/shared/{unjwt.B4e_rwol.mjs → unjwt.Ce72NmIz.mjs} +3 -3
- 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.DHdDAH0L.mjs} +28 -2
- package/dist/shared/{unjwt.Dz5Oe9BG.d.mts → unjwt.DQIYSlHj.d.mts} +2 -2
- package/dist/shared/{unjwt.CJ_ohCFC.d.mts → unjwt.DqmNvXMd.d.ts} +10 -4
- package/dist/shared/{unjwt.B9uGngq-.d.mts → unjwt.WvWb2zNM.d.ts} +46 -2
- 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.BG_R52ey.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.B4fFiy1c.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.CVKbKOFy.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.DqmNvXMd.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.DHdDAH0L.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.Ce72NmIz.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.1gbuWbc6.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.BxqF-n1S.mjs';
|
|
5
|
+
import './shared/unjwt.C9Xhi7hE.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.1gbuWbc6.mjs';
|
|
2
|
+
import './shared/unjwt.DHdDAH0L.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.Ce72NmIz.mjs';
|
|
4
|
+
import './shared/unjwt.C9Xhi7hE.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.DHdDAH0L.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.1gbuWbc6.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.BG_R52ey.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.CVKbKOFy.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.1gbuWbc6.mjs';
|
|
2
|
+
import './shared/unjwt.DHdDAH0L.mjs';
|
|
3
|
+
import './shared/unjwt.C9Xhi7hE.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.BxqF-n1S.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as isCryptoKey, e as concatUint8Arrays, b as base64UrlEncode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode } from './unjwt.
|
|
1
|
+
import { g as isCryptoKey, e as concatUint8Arrays, b as base64UrlEncode, h as base64Decode, j as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode } from './unjwt.DHdDAH0L.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -113,7 +113,7 @@ function isAlgorithm(algorithm, name) {
|
|
|
113
113
|
function getHashLength(hash) {
|
|
114
114
|
return Number.parseInt(hash.name.slice(4), 10);
|
|
115
115
|
}
|
|
116
|
-
function getNamedCurve(alg) {
|
|
116
|
+
function getNamedCurve$1(alg) {
|
|
117
117
|
switch (alg) {
|
|
118
118
|
case "ES256": {
|
|
119
119
|
return "P-256";
|
|
@@ -182,7 +182,7 @@ function checkSigCryptoKey(key, alg, usage) {
|
|
|
182
182
|
case "ES512": {
|
|
183
183
|
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
184
184
|
throw unusable("ECDSA");
|
|
185
|
-
const expected = getNamedCurve(alg);
|
|
185
|
+
const expected = getNamedCurve$1(alg);
|
|
186
186
|
const actual = key.algorithm.namedCurve;
|
|
187
187
|
if (actual !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
188
188
|
break;
|
|
@@ -511,6 +511,251 @@ async function decryptIV(alg, key, encryptedKey, iv, tag) {
|
|
|
511
511
|
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
/**
|
|
515
|
+
* This is a fork of Jose library's utility functions.
|
|
516
|
+
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/asn1.ts
|
|
517
|
+
* @license MIT https://github.com/panva/jose/blob/69b7960c67e05be55fa2ec31c74b987696c20c60/LICENSE.md
|
|
518
|
+
*/
|
|
519
|
+
const formatPEM = (b64, descriptor) => {
|
|
520
|
+
const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
|
|
521
|
+
return `-----BEGIN ${descriptor}-----
|
|
522
|
+
${newlined}
|
|
523
|
+
-----END ${descriptor}-----`;
|
|
524
|
+
};
|
|
525
|
+
const genericExport = async (keyType, keyFormat, key) => {
|
|
526
|
+
if (!isCryptoKey(key)) {
|
|
527
|
+
throw new TypeError(`Key must be ${key} of type CryptoKey`);
|
|
528
|
+
}
|
|
529
|
+
if (!key.extractable) {
|
|
530
|
+
throw new TypeError("CryptoKey is not extractable");
|
|
531
|
+
}
|
|
532
|
+
if (key.type !== keyType) {
|
|
533
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
534
|
+
}
|
|
535
|
+
return formatPEM(
|
|
536
|
+
base64Encode(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))),
|
|
537
|
+
`${keyType.toUpperCase()} KEY`
|
|
538
|
+
);
|
|
539
|
+
};
|
|
540
|
+
const toSPKI = (key) => {
|
|
541
|
+
return genericExport("public", "spki", key);
|
|
542
|
+
};
|
|
543
|
+
const toPKCS8 = (key) => {
|
|
544
|
+
return genericExport("private", "pkcs8", key);
|
|
545
|
+
};
|
|
546
|
+
const findOid = (keyData, oid, from = 0) => {
|
|
547
|
+
if (from === 0) {
|
|
548
|
+
oid.unshift(oid.length);
|
|
549
|
+
oid.unshift(6);
|
|
550
|
+
}
|
|
551
|
+
const i = keyData.indexOf(oid[0], from);
|
|
552
|
+
if (i === -1) return false;
|
|
553
|
+
const sub = keyData.subarray(i, i + oid.length);
|
|
554
|
+
if (sub.length !== oid.length) return false;
|
|
555
|
+
return sub.every((value, index) => value === oid[index]) || findOid(keyData, oid, i + 1);
|
|
556
|
+
};
|
|
557
|
+
const getNamedCurve = (keyData) => {
|
|
558
|
+
switch (true) {
|
|
559
|
+
case findOid(keyData, [42, 134, 72, 206, 61, 3, 1, 7]): {
|
|
560
|
+
return "P-256";
|
|
561
|
+
}
|
|
562
|
+
case findOid(keyData, [43, 129, 4, 0, 34]): {
|
|
563
|
+
return "P-384";
|
|
564
|
+
}
|
|
565
|
+
case findOid(keyData, [43, 129, 4, 0, 35]): {
|
|
566
|
+
return "P-521";
|
|
567
|
+
}
|
|
568
|
+
default: {
|
|
569
|
+
return void 0;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
|
574
|
+
let algorithm;
|
|
575
|
+
let keyUsages;
|
|
576
|
+
const cleanedPem = pem.replace(replace, "");
|
|
577
|
+
const keyData = base64Decode(cleanedPem, false);
|
|
578
|
+
const isPublic = keyFormat === "spki";
|
|
579
|
+
switch (alg) {
|
|
580
|
+
case "PS256":
|
|
581
|
+
case "PS384":
|
|
582
|
+
case "PS512": {
|
|
583
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
584
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
case "RS256":
|
|
588
|
+
case "RS384":
|
|
589
|
+
case "RS512": {
|
|
590
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
591
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
case "RSA-OAEP":
|
|
595
|
+
case "RSA-OAEP-256":
|
|
596
|
+
case "RSA-OAEP-384":
|
|
597
|
+
case "RSA-OAEP-512": {
|
|
598
|
+
algorithm = {
|
|
599
|
+
name: "RSA-OAEP",
|
|
600
|
+
hash: `SHA-${Number.parseInt(alg.slice(-3), 10) || 1}`
|
|
601
|
+
};
|
|
602
|
+
keyUsages = isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
case "ES256": {
|
|
606
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
607
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
case "ES384": {
|
|
611
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
612
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
case "ES512": {
|
|
616
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
617
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
case "ECDH-ES":
|
|
621
|
+
case "ECDH-ES+A128KW":
|
|
622
|
+
case "ECDH-ES+A192KW":
|
|
623
|
+
case "ECDH-ES+A256KW": {
|
|
624
|
+
const namedCurve = getNamedCurve(keyData);
|
|
625
|
+
algorithm = namedCurve?.startsWith("P-") ? { name: "ECDH", namedCurve } : { name: "X25519" };
|
|
626
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
case "Ed25519":
|
|
630
|
+
case "EdDSA": {
|
|
631
|
+
algorithm = { name: "Ed25519" };
|
|
632
|
+
keyUsages = isPublic ? ["verify"] : ["sign"];
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
default: {
|
|
636
|
+
throw new Error('Invalid or unsupported "alg" (Algorithm) value');
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return crypto.subtle.importKey(
|
|
640
|
+
keyFormat,
|
|
641
|
+
keyData,
|
|
642
|
+
algorithm,
|
|
643
|
+
options?.extractable ?? (isPublic ? true : false),
|
|
644
|
+
keyUsages
|
|
645
|
+
);
|
|
646
|
+
};
|
|
647
|
+
const fromPKCS8 = (pem, alg, options) => {
|
|
648
|
+
return genericImport(
|
|
649
|
+
/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g,
|
|
650
|
+
"pkcs8",
|
|
651
|
+
pem,
|
|
652
|
+
alg,
|
|
653
|
+
options
|
|
654
|
+
);
|
|
655
|
+
};
|
|
656
|
+
const fromSPKI = (pem, alg, options) => {
|
|
657
|
+
return genericImport(
|
|
658
|
+
/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g,
|
|
659
|
+
"spki",
|
|
660
|
+
pem,
|
|
661
|
+
alg,
|
|
662
|
+
options
|
|
663
|
+
);
|
|
664
|
+
};
|
|
665
|
+
function getElement(seq) {
|
|
666
|
+
const result = [];
|
|
667
|
+
let next = 0;
|
|
668
|
+
while (next < seq.length) {
|
|
669
|
+
const nextPart = parseElement(seq.subarray(next));
|
|
670
|
+
result.push(nextPart);
|
|
671
|
+
next += nextPart.byteLength;
|
|
672
|
+
}
|
|
673
|
+
return result;
|
|
674
|
+
}
|
|
675
|
+
function parseElement(bytes) {
|
|
676
|
+
let position = 0;
|
|
677
|
+
let tag = bytes[0] & 31;
|
|
678
|
+
position++;
|
|
679
|
+
if (tag === 31) {
|
|
680
|
+
tag = 0;
|
|
681
|
+
while (bytes[position] >= 128) {
|
|
682
|
+
tag = tag * 128 + bytes[position] - 128;
|
|
683
|
+
position++;
|
|
684
|
+
}
|
|
685
|
+
tag = tag * 128 + bytes[position] - 128;
|
|
686
|
+
position++;
|
|
687
|
+
}
|
|
688
|
+
let length = 0;
|
|
689
|
+
if (bytes[position] < 128) {
|
|
690
|
+
length = bytes[position];
|
|
691
|
+
position++;
|
|
692
|
+
} else if (length === 128) {
|
|
693
|
+
length = 0;
|
|
694
|
+
while (bytes[position + length] !== 0 || bytes[position + length + 1] !== 0) {
|
|
695
|
+
if (length > bytes.byteLength) {
|
|
696
|
+
throw new TypeError("invalid indefinite form length");
|
|
697
|
+
}
|
|
698
|
+
length++;
|
|
699
|
+
}
|
|
700
|
+
const byteLength2 = position + length + 2;
|
|
701
|
+
return {
|
|
702
|
+
byteLength: byteLength2,
|
|
703
|
+
contents: bytes.subarray(position, position + length),
|
|
704
|
+
raw: bytes.subarray(0, byteLength2)
|
|
705
|
+
};
|
|
706
|
+
} else {
|
|
707
|
+
const numberOfDigits = bytes[position] & 127;
|
|
708
|
+
position++;
|
|
709
|
+
length = 0;
|
|
710
|
+
for (let i = 0; i < numberOfDigits; i++) {
|
|
711
|
+
length = length * 256 + bytes[position];
|
|
712
|
+
position++;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
const byteLength = position + length;
|
|
716
|
+
return {
|
|
717
|
+
byteLength,
|
|
718
|
+
contents: bytes.subarray(position, byteLength),
|
|
719
|
+
raw: bytes.subarray(0, byteLength)
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
function spkiFromX509(buf) {
|
|
723
|
+
const tbsCertificate = getElement(
|
|
724
|
+
getElement(parseElement(buf).contents)[0].contents
|
|
725
|
+
);
|
|
726
|
+
return base64Encode(
|
|
727
|
+
tbsCertificate[tbsCertificate[0].raw[0] === 160 ? 6 : 5].raw
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
let createPublicKey;
|
|
731
|
+
function getSPKI(x509) {
|
|
732
|
+
try {
|
|
733
|
+
createPublicKey ??= globalThis.process?.getBuiltinModule?.("node:crypto")?.createPublicKey;
|
|
734
|
+
} catch {
|
|
735
|
+
createPublicKey = 0;
|
|
736
|
+
}
|
|
737
|
+
if (createPublicKey) {
|
|
738
|
+
try {
|
|
739
|
+
return new createPublicKey(x509).export({ format: "pem", type: "spki" });
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, "");
|
|
744
|
+
const raw = base64Decode(pem, false);
|
|
745
|
+
return formatPEM(spkiFromX509(raw), "PUBLIC KEY");
|
|
746
|
+
}
|
|
747
|
+
const fromX509 = (pem, alg, options) => {
|
|
748
|
+
let spki;
|
|
749
|
+
try {
|
|
750
|
+
spki = getSPKI(pem);
|
|
751
|
+
} catch (error_) {
|
|
752
|
+
throw new TypeError("Failed to parse the X.509 certificate", {
|
|
753
|
+
cause: error_
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
return fromSPKI(spki, alg, options);
|
|
757
|
+
};
|
|
758
|
+
|
|
514
759
|
/**
|
|
515
760
|
* This is a fork of Jose library's utility functions.
|
|
516
761
|
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/jwt_to_key.ts
|
|
@@ -1064,6 +1309,80 @@ async function unwrapKey(alg, wrappedKey, unwrappingKey, options = {}) {
|
|
|
1064
1309
|
);
|
|
1065
1310
|
return finalKey;
|
|
1066
1311
|
}
|
|
1312
|
+
async function importJWKFromPEM(pem, pemType, alg, importOptions, jwkExtras) {
|
|
1313
|
+
let cryptoKey;
|
|
1314
|
+
const defaultExtractable = importOptions?.extractable !== false;
|
|
1315
|
+
switch (pemType) {
|
|
1316
|
+
case "pkcs8": {
|
|
1317
|
+
cryptoKey = await fromPKCS8(pem, alg, {
|
|
1318
|
+
...importOptions,
|
|
1319
|
+
extractable: defaultExtractable
|
|
1320
|
+
});
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
case "spki": {
|
|
1324
|
+
cryptoKey = await fromSPKI(pem, alg, {
|
|
1325
|
+
...importOptions,
|
|
1326
|
+
extractable: defaultExtractable
|
|
1327
|
+
});
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
case "x509": {
|
|
1331
|
+
cryptoKey = await fromX509(pem, alg, {
|
|
1332
|
+
...importOptions,
|
|
1333
|
+
extractable: defaultExtractable
|
|
1334
|
+
});
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
default: {
|
|
1338
|
+
throw new TypeError(`Unsupported PEM type: ${pemType}`);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const finalJWKExtras = { alg, ...jwkExtras };
|
|
1342
|
+
return exportKey(cryptoKey, finalJWKExtras);
|
|
1343
|
+
}
|
|
1344
|
+
async function exportJWKToPEM(jwk, pemFormat, algForCryptoKeyImport) {
|
|
1345
|
+
if (jwk.kty === "oct") {
|
|
1346
|
+
throw new TypeError(
|
|
1347
|
+
"Octet (symmetric) JWKs (kty: 'oct') cannot be exported to PKCS8 or SPKI PEM formats."
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
const effectiveAlg = jwk.alg || algForCryptoKeyImport;
|
|
1351
|
+
if (!effectiveAlg && (jwk.kty === "RSA" || jwk.kty === "EC" || jwk.kty === "OKP")) {
|
|
1352
|
+
throw new TypeError(
|
|
1353
|
+
"Algorithm (alg) must be provided in the JWK or as a parameter for converting this JWK type to a CryptoKey."
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
const jwkForImport = { ...jwk, ext: true };
|
|
1357
|
+
const cryptoKeyCandidate = await importKey(jwkForImport, effectiveAlg);
|
|
1358
|
+
if (!isCryptoKey(cryptoKeyCandidate)) {
|
|
1359
|
+
throw new Error(
|
|
1360
|
+
"Failed to convert JWK to a CryptoKey instance suitable for PEM export."
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
const cryptoKey = cryptoKeyCandidate;
|
|
1364
|
+
switch (pemFormat) {
|
|
1365
|
+
case "pkcs8": {
|
|
1366
|
+
if (cryptoKey.type !== "private") {
|
|
1367
|
+
throw new TypeError(
|
|
1368
|
+
`Only 'private' type CryptoKeys can be exported to PKCS8 PEM format. Key type is '${cryptoKey.type}'.`
|
|
1369
|
+
);
|
|
1370
|
+
}
|
|
1371
|
+
return toPKCS8(cryptoKey);
|
|
1372
|
+
}
|
|
1373
|
+
case "spki": {
|
|
1374
|
+
if (cryptoKey.type !== "public") {
|
|
1375
|
+
throw new TypeError(
|
|
1376
|
+
`Only 'public' type CryptoKeys can be exported to SPKI PEM format. Key type is '${cryptoKey.type}'.`
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
return toSPKI(cryptoKey);
|
|
1380
|
+
}
|
|
1381
|
+
default: {
|
|
1382
|
+
throw new TypeError(`Unsupported PEM format: ${pemFormat}`);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1067
1386
|
function getGenerateKeyParams(alg, options) {
|
|
1068
1387
|
let algorithm;
|
|
1069
1388
|
let keyUsages;
|
|
@@ -1176,11 +1495,13 @@ function getGenerateKeyParams(alg, options) {
|
|
|
1176
1495
|
const jwk = {
|
|
1177
1496
|
__proto__: null,
|
|
1178
1497
|
deriveKeyFromPassword: deriveKeyFromPassword,
|
|
1498
|
+
exportJWKToPEM: exportJWKToPEM,
|
|
1179
1499
|
exportKey: exportKey,
|
|
1180
1500
|
generateKey: generateKey,
|
|
1501
|
+
importJWKFromPEM: importJWKFromPEM,
|
|
1181
1502
|
importKey: importKey,
|
|
1182
1503
|
unwrapKey: unwrapKey,
|
|
1183
1504
|
wrapKey: wrapKey
|
|
1184
1505
|
};
|
|
1185
1506
|
|
|
1186
|
-
export { checkEncCryptoKey as a, bitLengthCEK as b, checkSigCryptoKey as c, jwkTokey as d, encryptIV as e, generateIV as f, generateCEK as g, encrypt as h, importKey as i, jwk as j, keyToJWK as k, unwrapKey as l, decrypt as m, generateKey as n, deriveKeyFromPassword as o, exportKey as p, wrapKey as q, uint32be as u, wrap as w };
|
|
1507
|
+
export { checkEncCryptoKey as a, bitLengthCEK as b, checkSigCryptoKey as c, jwkTokey as d, encryptIV as e, generateIV as f, generateCEK as g, encrypt as h, importKey as i, jwk as j, keyToJWK as k, unwrapKey as l, decrypt as m, generateKey as n, deriveKeyFromPassword as o, exportKey as p, wrapKey as q, importJWKFromPEM as r, exportJWKToPEM as s, uint32be as u, wrap 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.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.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
|
/**
|
|
@@ -19,6 +21,8 @@ declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
|
19
21
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
20
22
|
|
|
21
23
|
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
24
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
25
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
22
26
|
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
23
27
|
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
24
28
|
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
@@ -31,6 +35,8 @@ declare const index_textEncoder: typeof textEncoder;
|
|
|
31
35
|
declare namespace index {
|
|
32
36
|
export {
|
|
33
37
|
index_assertCryptoKey as assertCryptoKey,
|
|
38
|
+
index_base64Decode as base64Decode,
|
|
39
|
+
index_base64Encode as base64Encode,
|
|
34
40
|
index_base64UrlDecode as base64UrlDecode,
|
|
35
41
|
index_base64UrlEncode as base64UrlEncode,
|
|
36
42
|
index_concatUint8Arrays as concatUint8Arrays,
|
|
@@ -43,4 +49,4 @@ declare namespace index {
|
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
export { textDecoder as a,
|
|
52
|
+
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, randomBytes as r, textEncoder as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as JWK_HMAC, o as JWK_RSA_SIGN, p as JWK_RSA_PSS, q as JWK_ECDSA, m as JWK } from './unjwt.
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.
|
|
1
|
+
import { n as JWK_HMAC, o as JWK_RSA_SIGN, p as JWK_RSA_PSS, q as JWK_ECDSA, m as JWK } from './unjwt.CxhGjEAX.mjs';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.Cd9nTEWg.mjs';
|
|
3
3
|
|
|
4
4
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
5
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -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.1gbuWbc6.mjs';
|
|
2
|
+
import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode } from './unjwt.DHdDAH0L.mjs';
|
|
3
|
+
import { s as sign$1, v as verify$1 } from './unjwt.C9Xhi7hE.mjs';
|
|
4
4
|
|
|
5
5
|
async function sign(payload, key, options = {}) {
|
|
6
6
|
const { protectedHeader: additionalProtectedHeader } = options;
|
|
@@ -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_})`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as JWK_HMAC, o as JWK_RSA_SIGN, p as JWK_RSA_PSS, q as JWK_ECDSA, m as JWK } from './unjwt.
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.
|
|
1
|
+
import { n as JWK_HMAC, o as JWK_RSA_SIGN, p as JWK_RSA_PSS, q as JWK_ECDSA, m as JWK } from './unjwt.CxhGjEAX.js';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BISJ5yt1.js';
|
|
3
3
|
|
|
4
4
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
5
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -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.1gbuWbc6.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.DHdDAH0L.mjs';
|
|
3
|
+
import { c as checkKeyLength } from './unjwt.C9Xhi7hE.mjs';
|
|
4
4
|
|
|
5
5
|
function lengthAndInput(input) {
|
|
6
6
|
return concatUint8Arrays(uint32be(input.length), input);
|
|
@@ -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 };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, w 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, C as CompositeKey, d as ContentEncryptionAlgorithm,
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, w 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, E as JWKPEMAlgorithm, C as CompositeKey, d as ContentEncryptionAlgorithm, B as JWKAlgorithm, 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, 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 } from './unjwt.CxhGjEAX.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a fork of Jose library's utility functions.
|
|
5
|
+
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/asn1.ts
|
|
6
|
+
* @license MIT https://github.com/panva/jose/blob/69b7960c67e05be55fa2ec31c74b987696c20c60/LICENSE.md
|
|
7
|
+
*/
|
|
8
|
+
/** Key Import Function options. */
|
|
9
|
+
interface KeyImportOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
|
|
12
|
+
* private keys, true otherwise.
|
|
13
|
+
*/
|
|
14
|
+
extractable?: boolean;
|
|
15
|
+
}
|
|
2
16
|
|
|
3
17
|
/**
|
|
4
18
|
* Generates a cryptographic key for the specified algorithm.
|
|
@@ -65,6 +79,28 @@ declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uin
|
|
|
65
79
|
declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyManagementAlgorithm, wrappedKey: Uint8Array, unwrappingKey: CryptoKey | JWK | string | Uint8Array, options?: UnwrapKeyOptions & {
|
|
66
80
|
returnAs?: T;
|
|
67
81
|
}): Promise<T extends false ? Uint8Array : CryptoKey>;
|
|
82
|
+
/**
|
|
83
|
+
* Imports a key from a PEM-encoded string and converts it to a JWK.
|
|
84
|
+
*
|
|
85
|
+
* @param pem The PEM-encoded string.
|
|
86
|
+
* @param pemType The type of PEM encoding ('pkcs8' for private keys, 'spki' for public keys, 'x509' for certificates).
|
|
87
|
+
* @param alg The JWA algorithm identifier. This is crucial for `crypto.subtle.importKey`
|
|
88
|
+
* to understand the key's intended algorithm and for setting the 'alg' field in the resulting JWK.
|
|
89
|
+
* @param importOptions Options for the PEM import process (e.g., extractable for the CryptoKey).
|
|
90
|
+
* @param jwkExtras Additional properties to merge into the resulting JWK.
|
|
91
|
+
* @returns A Promise resolving to the imported key as a JWK.
|
|
92
|
+
*/
|
|
93
|
+
declare function importJWKFromPEM(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, importOptions?: KeyImportOptions, jwkExtras?: Partial<JWK>): Promise<JWK>;
|
|
94
|
+
/**
|
|
95
|
+
* Exports a JWK to a PEM-encoded string.
|
|
96
|
+
*
|
|
97
|
+
* @param jwk The JWK to export.
|
|
98
|
+
* @param pemFormat The desired PEM format ('pkcs8' for private keys, 'spki' for public keys).
|
|
99
|
+
* @param algForCryptoKeyImport If the JWK does not have an 'alg' property, this algorithm hint is
|
|
100
|
+
* required to correctly convert it to a CryptoKey first.
|
|
101
|
+
* @returns A Promise resolving to the PEM-encoded key string.
|
|
102
|
+
*/
|
|
103
|
+
declare function exportJWKToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
|
|
68
104
|
|
|
69
105
|
declare const jwk_CompositeKey: typeof CompositeKey;
|
|
70
106
|
declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
@@ -75,6 +111,7 @@ declare const jwk_GenerateKeyOptions: typeof GenerateKeyOptions;
|
|
|
75
111
|
declare const jwk_GenerateKeyReturn: typeof GenerateKeyReturn;
|
|
76
112
|
declare const jwk_JWK: typeof JWK;
|
|
77
113
|
declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
|
|
114
|
+
declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
78
115
|
declare const jwk_JWKParameters: typeof JWKParameters;
|
|
79
116
|
declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
80
117
|
declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
@@ -86,6 +123,7 @@ declare const jwk_JWK_ECDH_ES: typeof JWK_ECDH_ES;
|
|
|
86
123
|
declare const jwk_JWK_ECDSA: typeof JWK_ECDSA;
|
|
87
124
|
declare const jwk_JWK_EC_Private: typeof JWK_EC_Private;
|
|
88
125
|
declare const jwk_JWK_EC_Public: typeof JWK_EC_Public;
|
|
126
|
+
declare const jwk_JWK_ED: typeof JWK_ED;
|
|
89
127
|
declare const jwk_JWK_HMAC: typeof JWK_HMAC;
|
|
90
128
|
declare const jwk_JWK_PBES2: typeof JWK_PBES2;
|
|
91
129
|
declare const jwk_JWK_RSA: typeof JWK_RSA;
|
|
@@ -101,8 +139,10 @@ declare const jwk_UnwrapKeyOptions: typeof UnwrapKeyOptions;
|
|
|
101
139
|
declare const jwk_WrapKeyOptions: typeof WrapKeyOptions;
|
|
102
140
|
declare const jwk_WrapKeyResult: typeof WrapKeyResult;
|
|
103
141
|
declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
|
|
142
|
+
declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
|
|
104
143
|
declare const jwk_exportKey: typeof exportKey;
|
|
105
144
|
declare const jwk_generateKey: typeof generateKey;
|
|
145
|
+
declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
|
|
106
146
|
declare const jwk_importKey: typeof importKey;
|
|
107
147
|
declare const jwk_unwrapKey: typeof unwrapKey;
|
|
108
148
|
declare const jwk_wrapKey: typeof wrapKey;
|
|
@@ -117,6 +157,7 @@ declare namespace jwk {
|
|
|
117
157
|
jwk_GenerateKeyReturn as GenerateKeyReturn,
|
|
118
158
|
jwk_JWK as JWK,
|
|
119
159
|
jwk_JWKAlgorithm as JWKAlgorithm,
|
|
160
|
+
jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
120
161
|
jwk_JWKParameters as JWKParameters,
|
|
121
162
|
jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
122
163
|
jwk_JWK_AES_GCM as JWK_AES_GCM,
|
|
@@ -128,6 +169,7 @@ declare namespace jwk {
|
|
|
128
169
|
jwk_JWK_ECDSA as JWK_ECDSA,
|
|
129
170
|
jwk_JWK_EC_Private as JWK_EC_Private,
|
|
130
171
|
jwk_JWK_EC_Public as JWK_EC_Public,
|
|
172
|
+
jwk_JWK_ED as JWK_ED,
|
|
131
173
|
jwk_JWK_HMAC as JWK_HMAC,
|
|
132
174
|
jwk_JWK_PBES2 as JWK_PBES2,
|
|
133
175
|
jwk_JWK_RSA as JWK_RSA,
|
|
@@ -143,12 +185,14 @@ declare namespace jwk {
|
|
|
143
185
|
jwk_WrapKeyOptions as WrapKeyOptions,
|
|
144
186
|
jwk_WrapKeyResult as WrapKeyResult,
|
|
145
187
|
jwk_deriveKeyFromPassword as deriveKeyFromPassword,
|
|
188
|
+
jwk_exportJWKToPEM as exportJWKToPEM,
|
|
146
189
|
jwk_exportKey as exportKey,
|
|
147
190
|
jwk_generateKey as generateKey,
|
|
191
|
+
jwk_importJWKFromPEM as importJWKFromPEM,
|
|
148
192
|
jwk_importKey as importKey,
|
|
149
193
|
jwk_unwrapKey as unwrapKey,
|
|
150
194
|
jwk_wrapKey as wrapKey,
|
|
151
195
|
};
|
|
152
196
|
}
|
|
153
197
|
|
|
154
|
-
export { deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
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 };
|
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
2
2
|
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
3
|
+
function base64Encode(data) {
|
|
4
|
+
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
5
|
+
if (Uint8Array.prototype.toBase64) {
|
|
6
|
+
return encodedData.toBase64();
|
|
7
|
+
}
|
|
8
|
+
return btoa(String.fromCodePoint(...encodedData));
|
|
9
|
+
}
|
|
3
10
|
function base64UrlEncode(data) {
|
|
4
11
|
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
5
|
-
|
|
12
|
+
if (Uint8Array.prototype.toBase64) {
|
|
13
|
+
return encodedData.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
14
|
+
}
|
|
15
|
+
return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
16
|
+
}
|
|
17
|
+
function base64Decode(str, toString) {
|
|
18
|
+
const decodeToString = toString !== false;
|
|
19
|
+
if (!str) {
|
|
20
|
+
return decodeToString ? "" : new Uint8Array(0);
|
|
21
|
+
}
|
|
22
|
+
if (Uint8Array.fromBase64) {
|
|
23
|
+
return Uint8Array.fromBase64(str);
|
|
24
|
+
}
|
|
25
|
+
const data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
26
|
+
return decodeToString ? textDecoder.decode(data) : data;
|
|
6
27
|
}
|
|
7
28
|
function base64UrlDecode(str, toString) {
|
|
8
29
|
const decodeToString = toString !== false;
|
|
9
30
|
if (!str) {
|
|
10
31
|
return decodeToString ? "" : new Uint8Array(0);
|
|
11
32
|
}
|
|
33
|
+
if (Uint8Array.fromBase64) {
|
|
34
|
+
return Uint8Array.fromBase64(str, { alphabet: "base64url" });
|
|
35
|
+
}
|
|
12
36
|
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
13
37
|
while (str.length % 4) str += "=";
|
|
14
38
|
const data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
@@ -43,6 +67,8 @@ const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(k
|
|
|
43
67
|
const index = {
|
|
44
68
|
__proto__: null,
|
|
45
69
|
assertCryptoKey: assertCryptoKey,
|
|
70
|
+
base64Decode: base64Decode,
|
|
71
|
+
base64Encode: base64Encode,
|
|
46
72
|
base64UrlDecode: base64UrlDecode,
|
|
47
73
|
base64UrlEncode: base64UrlEncode,
|
|
48
74
|
concatUint8Arrays: concatUint8Arrays,
|
|
@@ -54,4 +80,4 @@ const index = {
|
|
|
54
80
|
textEncoder: textEncoder
|
|
55
81
|
};
|
|
56
82
|
|
|
57
|
-
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g,
|
|
83
|
+
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g, base64Decode as h, index as i, base64Encode as j, isCryptoKeyPair as k, randomBytes as r, textEncoder as t };
|
|
@@ -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.mjs';
|
|
2
|
+
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.Cd9nTEWg.mjs';
|
|
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
|
/**
|
|
@@ -19,6 +21,8 @@ declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
|
19
21
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
20
22
|
|
|
21
23
|
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
24
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
25
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
22
26
|
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
23
27
|
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
24
28
|
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
@@ -31,6 +35,8 @@ declare const index_textEncoder: typeof textEncoder;
|
|
|
31
35
|
declare namespace index {
|
|
32
36
|
export {
|
|
33
37
|
index_assertCryptoKey as assertCryptoKey,
|
|
38
|
+
index_base64Decode as base64Decode,
|
|
39
|
+
index_base64Encode as base64Encode,
|
|
34
40
|
index_base64UrlDecode as base64UrlDecode,
|
|
35
41
|
index_base64UrlEncode as base64UrlEncode,
|
|
36
42
|
index_concatUint8Arrays as concatUint8Arrays,
|
|
@@ -43,4 +49,4 @@ declare namespace index {
|
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
export { textDecoder as a,
|
|
52
|
+
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, randomBytes as r, textEncoder as t };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, w 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, C as CompositeKey, d as ContentEncryptionAlgorithm,
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, w 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, E as JWKPEMAlgorithm, C as CompositeKey, d as ContentEncryptionAlgorithm, B as JWKAlgorithm, 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, 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 } from './unjwt.CxhGjEAX.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a fork of Jose library's utility functions.
|
|
5
|
+
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/asn1.ts
|
|
6
|
+
* @license MIT https://github.com/panva/jose/blob/69b7960c67e05be55fa2ec31c74b987696c20c60/LICENSE.md
|
|
7
|
+
*/
|
|
8
|
+
/** Key Import Function options. */
|
|
9
|
+
interface KeyImportOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
|
|
12
|
+
* private keys, true otherwise.
|
|
13
|
+
*/
|
|
14
|
+
extractable?: boolean;
|
|
15
|
+
}
|
|
2
16
|
|
|
3
17
|
/**
|
|
4
18
|
* Generates a cryptographic key for the specified algorithm.
|
|
@@ -65,6 +79,28 @@ declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uin
|
|
|
65
79
|
declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyManagementAlgorithm, wrappedKey: Uint8Array, unwrappingKey: CryptoKey | JWK | string | Uint8Array, options?: UnwrapKeyOptions & {
|
|
66
80
|
returnAs?: T;
|
|
67
81
|
}): Promise<T extends false ? Uint8Array : CryptoKey>;
|
|
82
|
+
/**
|
|
83
|
+
* Imports a key from a PEM-encoded string and converts it to a JWK.
|
|
84
|
+
*
|
|
85
|
+
* @param pem The PEM-encoded string.
|
|
86
|
+
* @param pemType The type of PEM encoding ('pkcs8' for private keys, 'spki' for public keys, 'x509' for certificates).
|
|
87
|
+
* @param alg The JWA algorithm identifier. This is crucial for `crypto.subtle.importKey`
|
|
88
|
+
* to understand the key's intended algorithm and for setting the 'alg' field in the resulting JWK.
|
|
89
|
+
* @param importOptions Options for the PEM import process (e.g., extractable for the CryptoKey).
|
|
90
|
+
* @param jwkExtras Additional properties to merge into the resulting JWK.
|
|
91
|
+
* @returns A Promise resolving to the imported key as a JWK.
|
|
92
|
+
*/
|
|
93
|
+
declare function importJWKFromPEM(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, importOptions?: KeyImportOptions, jwkExtras?: Partial<JWK>): Promise<JWK>;
|
|
94
|
+
/**
|
|
95
|
+
* Exports a JWK to a PEM-encoded string.
|
|
96
|
+
*
|
|
97
|
+
* @param jwk The JWK to export.
|
|
98
|
+
* @param pemFormat The desired PEM format ('pkcs8' for private keys, 'spki' for public keys).
|
|
99
|
+
* @param algForCryptoKeyImport If the JWK does not have an 'alg' property, this algorithm hint is
|
|
100
|
+
* required to correctly convert it to a CryptoKey first.
|
|
101
|
+
* @returns A Promise resolving to the PEM-encoded key string.
|
|
102
|
+
*/
|
|
103
|
+
declare function exportJWKToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
|
|
68
104
|
|
|
69
105
|
declare const jwk_CompositeKey: typeof CompositeKey;
|
|
70
106
|
declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
@@ -75,6 +111,7 @@ declare const jwk_GenerateKeyOptions: typeof GenerateKeyOptions;
|
|
|
75
111
|
declare const jwk_GenerateKeyReturn: typeof GenerateKeyReturn;
|
|
76
112
|
declare const jwk_JWK: typeof JWK;
|
|
77
113
|
declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
|
|
114
|
+
declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
78
115
|
declare const jwk_JWKParameters: typeof JWKParameters;
|
|
79
116
|
declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
80
117
|
declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
@@ -86,6 +123,7 @@ declare const jwk_JWK_ECDH_ES: typeof JWK_ECDH_ES;
|
|
|
86
123
|
declare const jwk_JWK_ECDSA: typeof JWK_ECDSA;
|
|
87
124
|
declare const jwk_JWK_EC_Private: typeof JWK_EC_Private;
|
|
88
125
|
declare const jwk_JWK_EC_Public: typeof JWK_EC_Public;
|
|
126
|
+
declare const jwk_JWK_ED: typeof JWK_ED;
|
|
89
127
|
declare const jwk_JWK_HMAC: typeof JWK_HMAC;
|
|
90
128
|
declare const jwk_JWK_PBES2: typeof JWK_PBES2;
|
|
91
129
|
declare const jwk_JWK_RSA: typeof JWK_RSA;
|
|
@@ -101,8 +139,10 @@ declare const jwk_UnwrapKeyOptions: typeof UnwrapKeyOptions;
|
|
|
101
139
|
declare const jwk_WrapKeyOptions: typeof WrapKeyOptions;
|
|
102
140
|
declare const jwk_WrapKeyResult: typeof WrapKeyResult;
|
|
103
141
|
declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
|
|
142
|
+
declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
|
|
104
143
|
declare const jwk_exportKey: typeof exportKey;
|
|
105
144
|
declare const jwk_generateKey: typeof generateKey;
|
|
145
|
+
declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
|
|
106
146
|
declare const jwk_importKey: typeof importKey;
|
|
107
147
|
declare const jwk_unwrapKey: typeof unwrapKey;
|
|
108
148
|
declare const jwk_wrapKey: typeof wrapKey;
|
|
@@ -117,6 +157,7 @@ declare namespace jwk {
|
|
|
117
157
|
jwk_GenerateKeyReturn as GenerateKeyReturn,
|
|
118
158
|
jwk_JWK as JWK,
|
|
119
159
|
jwk_JWKAlgorithm as JWKAlgorithm,
|
|
160
|
+
jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
120
161
|
jwk_JWKParameters as JWKParameters,
|
|
121
162
|
jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
122
163
|
jwk_JWK_AES_GCM as JWK_AES_GCM,
|
|
@@ -128,6 +169,7 @@ declare namespace jwk {
|
|
|
128
169
|
jwk_JWK_ECDSA as JWK_ECDSA,
|
|
129
170
|
jwk_JWK_EC_Private as JWK_EC_Private,
|
|
130
171
|
jwk_JWK_EC_Public as JWK_EC_Public,
|
|
172
|
+
jwk_JWK_ED as JWK_ED,
|
|
131
173
|
jwk_JWK_HMAC as JWK_HMAC,
|
|
132
174
|
jwk_JWK_PBES2 as JWK_PBES2,
|
|
133
175
|
jwk_JWK_RSA as JWK_RSA,
|
|
@@ -143,12 +185,14 @@ declare namespace jwk {
|
|
|
143
185
|
jwk_WrapKeyOptions as WrapKeyOptions,
|
|
144
186
|
jwk_WrapKeyResult as WrapKeyResult,
|
|
145
187
|
jwk_deriveKeyFromPassword as deriveKeyFromPassword,
|
|
188
|
+
jwk_exportJWKToPEM as exportJWKToPEM,
|
|
146
189
|
jwk_exportKey as exportKey,
|
|
147
190
|
jwk_generateKey as generateKey,
|
|
191
|
+
jwk_importJWKFromPEM as importJWKFromPEM,
|
|
148
192
|
jwk_importKey as importKey,
|
|
149
193
|
jwk_unwrapKey as unwrapKey,
|
|
150
194
|
jwk_wrapKey as wrapKey,
|
|
151
195
|
};
|
|
152
196
|
}
|
|
153
197
|
|
|
154
|
-
export { deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
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 };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.CxhGjEAX.mjs';
|
|
2
|
+
export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.B4fFiy1c.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.CxhGjEAX.js';
|
|
2
|
+
export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.DqmNvXMd.js';
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { f as assertCryptoKey, d as base64UrlDecode, b as base64UrlEncode, e as concatUint8Arrays, g as isCryptoKey,
|
|
1
|
+
export { f as assertCryptoKey, h as base64Decode, j as base64Encode, d as base64UrlDecode, b as base64UrlEncode, e as concatUint8Arrays, g as isCryptoKey, k as isCryptoKeyPair, a as isJWK, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.DHdDAH0L.mjs';
|