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.
Files changed (34) hide show
  1. package/README.md +89 -4
  2. package/dist/index.d.mts +6 -6
  3. package/dist/index.d.ts +6 -6
  4. package/dist/index.mjs +5 -5
  5. package/dist/jwe.d.mts +3 -3
  6. package/dist/jwe.d.ts +3 -3
  7. package/dist/jwe.mjs +4 -4
  8. package/dist/jwk.d.mts +2 -2
  9. package/dist/jwk.d.ts +2 -2
  10. package/dist/jwk.mjs +2 -2
  11. package/dist/jws.d.mts +3 -3
  12. package/dist/jws.d.ts +3 -3
  13. package/dist/jws.mjs +4 -4
  14. package/dist/shared/{unjwt.BKG_8Y9G.d.ts → unjwt.B0XDPf8a.d.ts} +2 -2
  15. package/dist/shared/{unjwt.CJ_ohCFC.d.mts → unjwt.B5N3dPN9.d.ts} +13 -4
  16. package/dist/shared/{unjwt.DoVzOnty.d.ts → unjwt.BISJ5yt1.d.ts} +1 -1
  17. package/dist/shared/{unjwt.mc4AEAT7.d.ts → unjwt.BJEchXrM.d.mts} +13 -4
  18. package/dist/shared/{unjwt.B4e_rwol.mjs → unjwt.ByclPbtq.mjs} +3 -3
  19. package/dist/shared/{unjwt.Bzcov22m.mjs → unjwt.COPr8ebc.mjs} +98 -20
  20. package/dist/shared/{unjwt.D90BbcE1.d.mts → unjwt.Cd9nTEWg.d.mts} +1 -1
  21. package/dist/shared/{unjwt.C0bBN0AC.d.mts → unjwt.CxhGjEAX.d.mts} +3 -1
  22. package/dist/shared/{unjwt.C0bBN0AC.d.ts → unjwt.CxhGjEAX.d.ts} +3 -1
  23. package/dist/shared/{unjwt.BOEZHxi_.d.ts → unjwt.D1J1DelP.d.mts} +46 -2
  24. package/dist/shared/{unjwt.CjHZv3F3.mjs → unjwt.DOI5UE8K.mjs} +32 -2
  25. package/dist/shared/{unjwt.Dz5Oe9BG.d.mts → unjwt.DQIYSlHj.d.mts} +2 -2
  26. package/dist/shared/{unjwt.ppm5Y0k7.d.ts → unjwt.TbszLNOP.d.ts} +57 -4
  27. package/dist/shared/{unjwt.B9uGngq-.d.mts → unjwt.WvWb2zNM.d.ts} +46 -2
  28. package/dist/shared/{unjwt.DKq5VF7t.mjs → unjwt.ZsOShfhX.mjs} +325 -4
  29. package/dist/shared/{unjwt.DYFIh1YE.d.mts → unjwt.kiNPBQh0.d.mts} +57 -4
  30. package/dist/shared/{unjwt.sux3_Z19.mjs → unjwt.z_U3fRJ-.mjs} +1 -1
  31. package/dist/utils.d.mts +2 -2
  32. package/dist/utils.d.ts +2 -2
  33. package/dist/utils.mjs +1 -1
  34. package/package.json +1 -1
@@ -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, A 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, z 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, 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, y as JWK_Symmetric_Algorithm } from './unjwt.C0bBN0AC.js';
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
- return btoa(String.fromCodePoint(...encodedData)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
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));
@@ -27,6 +51,9 @@ function concatUint8Arrays(...arrays) {
27
51
  }
28
52
  return result;
29
53
  }
54
+ function maybeArray(item) {
55
+ return Array.isArray(item) ? item : [item];
56
+ }
30
57
  function isJWK(key) {
31
58
  return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
32
59
  }
@@ -43,15 +70,18 @@ const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(k
43
70
  const index = {
44
71
  __proto__: null,
45
72
  assertCryptoKey: assertCryptoKey,
73
+ base64Decode: base64Decode,
74
+ base64Encode: base64Encode,
46
75
  base64UrlDecode: base64UrlDecode,
47
76
  base64UrlEncode: base64UrlEncode,
48
77
  concatUint8Arrays: concatUint8Arrays,
49
78
  isCryptoKey: isCryptoKey,
50
79
  isCryptoKeyPair: isCryptoKeyPair,
51
80
  isJWK: isJWK,
81
+ maybeArray: maybeArray,
52
82
  randomBytes: randomBytes,
53
83
  textDecoder: textDecoder,
54
84
  textEncoder: textEncoder
55
85
  };
56
86
 
57
- export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g, isCryptoKeyPair as h, index as i, randomBytes as r, textEncoder as t };
87
+ 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, maybeArray as m, 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.C0bBN0AC.mjs';
2
- import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.D90BbcE1.mjs';
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,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.C0bBN0AC.js';
2
- import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.DoVzOnty.js';
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. */
@@ -43,10 +43,63 @@ interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
43
43
  interface JWSVerifyOptions {
44
44
  /** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
45
45
  algorithms?: JWSAlgorithm[];
46
- /** List of critical header parameters that must be understood and processed. */
47
- critical?: string[];
48
46
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
49
47
  forceUint8Array?: boolean;
48
+ /** List of critical header parameters that must be understood and processed. */
49
+ requiredHeaders?: string[];
50
+ /**
51
+ * Expected JWT "aud" (Audience) Claim value(s).
52
+ *
53
+ * This option makes the JWT "aud" (Audience) Claim presence required.
54
+ */
55
+ audience?: string | string[];
56
+ /**
57
+ * Clock skew tolerance (in seconds) for validating JWT claims.
58
+ *
59
+ * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
60
+ * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
61
+ */
62
+ clockTolerance?: number;
63
+ /**
64
+ * Expected JWT "iss" (Issuer) Claim value(s).
65
+ *
66
+ * This option makes the JWT "iss" (Issuer) Claim presence required.
67
+ */
68
+ issuer?: string | string[];
69
+ /**
70
+ * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
71
+ *
72
+ * This option makes the JWT "iat" (Issued At) Claim presence required.
73
+ */
74
+ maxTokenAge?: number;
75
+ /**
76
+ * Expected JWT "sub" (Subject) Claim value.
77
+ *
78
+ * This option makes the JWT "sub" (Subject) Claim presence required.
79
+ */
80
+ subject?: string;
81
+ /**
82
+ * Expected JWT "typ" (Type) Header Parameter value.
83
+ *
84
+ * This option makes the JWT "typ" (Type) Header Parameter presence required.
85
+ */
86
+ typ?: string;
87
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
88
+ currentDate?: Date;
89
+ /**
90
+ * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
91
+ * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
92
+ * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
93
+ * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
94
+ * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
95
+ * present.
96
+ */
97
+ requiredClaims?: string[];
98
+ /**
99
+ * List of critical header parameters that must be understood and processed.
100
+ * @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
101
+ */
102
+ critical?: string[];
50
103
  }
51
104
 
52
105
  /**
@@ -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, A 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, z 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, 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, y as JWK_Symmetric_Algorithm } from './unjwt.C0bBN0AC.mjs';
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 };