unjwt 0.5.3 → 0.5.5

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.mjs';
2
2
  export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.BvIkEGGz.mjs';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.BvA-8hLQ.mjs';
4
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.DLOO5Rmq.mjs';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.CGkRbYL2.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.8w7jp2aw.mjs';
5
5
  export { i as utils } from './shared/unjwt.CbvzYE-m.mjs';
6
- export { j as jwk } from './shared/unjwt.DZjogLQk.mjs';
6
+ export { j as jwk } from './shared/unjwt.DH1p_WL8.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.js';
2
2
  export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.c10n3uM8.js';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.C5blWtcA.js';
4
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.BJPVLhUb.js';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.RZpKLLLg.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.CoSilGqk.js';
5
5
  export { i as utils } from './shared/unjwt.D4DUiNeM.js';
6
- export { j as jwk } from './shared/unjwt.B4NFVxpx.js';
6
+ export { j as jwk } from './shared/unjwt.CrcUJklb.js';
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { i as utils } from './shared/unjwt.X5vzu_l_.mjs';
2
- export { j as jwe } from './shared/unjwt.BtEHeKmp.mjs';
3
- export { j as jwk } from './shared/unjwt.BPpolBff.mjs';
4
- export { j as jws } from './shared/unjwt.Dsh9nxbB.mjs';
5
- import './shared/unjwt.CauxOPN5.mjs';
1
+ export { i as utils } from './shared/unjwt.BHpknTpg.mjs';
2
+ export { j as jwe } from './shared/unjwt.B2olxeGL.mjs';
3
+ export { j as jwk } from './shared/unjwt.DRUXIabl.mjs';
4
+ export { j as jws } from './shared/unjwt.BY2vKT86.mjs';
5
+ import './shared/unjwt.Ca03jPX3.mjs';
package/dist/jwe.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.D9da8HQF.mjs';
2
2
  import './shared/unjwt.BvIkEGGz.mjs';
3
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.DLOO5Rmq.mjs';
3
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.8w7jp2aw.mjs';
package/dist/jwe.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.D9da8HQF.js';
2
2
  import './shared/unjwt.c10n3uM8.js';
3
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.BJPVLhUb.js';
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.CoSilGqk.js';
package/dist/jwe.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.BPpolBff.mjs';
2
- import './shared/unjwt.X5vzu_l_.mjs';
3
- export { d as decrypt, e as encrypt } from './shared/unjwt.BtEHeKmp.mjs';
4
- import './shared/unjwt.CauxOPN5.mjs';
1
+ import './shared/unjwt.DRUXIabl.mjs';
2
+ import './shared/unjwt.BHpknTpg.mjs';
3
+ export { d as decrypt, e as encrypt } from './shared/unjwt.B2olxeGL.mjs';
4
+ import './shared/unjwt.Ca03jPX3.mjs';
package/dist/jwk.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.mjs';
2
2
  import './shared/unjwt.BvIkEGGz.mjs';
3
- export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.DZjogLQk.mjs';
3
+ export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.DH1p_WL8.mjs';
package/dist/jwk.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.js';
2
2
  import './shared/unjwt.c10n3uM8.js';
3
- export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.B4NFVxpx.js';
3
+ export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.CrcUJklb.js';
package/dist/jwk.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import './shared/unjwt.X5vzu_l_.mjs';
2
- export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.BPpolBff.mjs';
1
+ import './shared/unjwt.BHpknTpg.mjs';
2
+ export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.DRUXIabl.mjs';
package/dist/jws.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.D9da8HQF.mjs';
2
2
  import './shared/unjwt.BvIkEGGz.mjs';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.BvA-8hLQ.mjs';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.CGkRbYL2.mjs';
package/dist/jws.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.D9da8HQF.js';
2
2
  import './shared/unjwt.c10n3uM8.js';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.C5blWtcA.js';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.RZpKLLLg.js';
package/dist/jws.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.BPpolBff.mjs';
2
- import './shared/unjwt.X5vzu_l_.mjs';
3
- import './shared/unjwt.CauxOPN5.mjs';
4
- export { s as sign, v as verify } from './shared/unjwt.Dsh9nxbB.mjs';
1
+ import './shared/unjwt.DRUXIabl.mjs';
2
+ import './shared/unjwt.BHpknTpg.mjs';
3
+ import './shared/unjwt.Ca03jPX3.mjs';
4
+ export { s as sign, v as verify } from './shared/unjwt.BY2vKT86.mjs';
@@ -125,7 +125,7 @@ interface JWEDecryptOptions {
125
125
  /**
126
126
  * Result of a JWE decryption operation.
127
127
  */
128
- interface JWEDecryptResult<T = JWTClaims | string> {
128
+ interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
129
129
  /** The decrypted payload. */
130
130
  payload: T;
131
131
  /** The JWE Protected Header. */
@@ -167,13 +167,13 @@ declare function encrypt(payload: string | Uint8Array | Record<string, any>, key
167
167
  * @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
168
168
  * @throws If JWE is invalid, decryption fails, or options are not met.
169
169
  */
170
- declare function decrypt<T = JWTClaims | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
170
+ declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
171
171
  declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
172
172
  forceUint8Array: true;
173
173
  }): Promise<JWEDecryptResult<Uint8Array>>;
174
174
 
175
175
  type jwe_JWEDecryptOptions = JWEDecryptOptions;
176
- type jwe_JWEDecryptResult<T = JWTClaims | string> = JWEDecryptResult<T>;
176
+ type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
177
177
  type jwe_JWEEncryptOptions = JWEEncryptOptions;
178
178
  type jwe_JWEHeaderParameters = JWEHeaderParameters;
179
179
  type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
@@ -1,6 +1,6 @@
1
- import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.BPpolBff.mjs';
2
- import { f as concatUint8Arrays, t as textEncoder, g as assertCryptoKey, b as base64UrlEncode, h as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.X5vzu_l_.mjs';
3
- import { c as checkKeyLength } from './unjwt.CauxOPN5.mjs';
1
+ import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.DRUXIabl.mjs';
2
+ import { f as concatUint8Arrays, t as textEncoder, g as assertCryptoKey, b as base64UrlEncode, h as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.BHpknTpg.mjs';
3
+ import { c as checkKeyLength } from './unjwt.Ca03jPX3.mjs';
4
4
 
5
5
  function lengthAndInput(input) {
6
6
  return concatUint8Arrays(uint32be(input.length), input);
@@ -19,10 +19,10 @@ function base64Decode(str, toString) {
19
19
  if (!str) {
20
20
  return decodeToString ? "" : new Uint8Array(0);
21
21
  }
22
- if (Uint8Array.fromBase64) {
23
- return Uint8Array.fromBase64(str);
24
- }
25
- const data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
22
+ const data = Uint8Array.fromBase64 ? (
23
+ // @ts-expect-error
24
+ Uint8Array.fromBase64(str)
25
+ ) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
26
26
  return decodeToString ? textDecoder.decode(data) : data;
27
27
  }
28
28
  function base64UrlDecode(str, toString) {
@@ -30,12 +30,14 @@ function base64UrlDecode(str, toString) {
30
30
  if (!str) {
31
31
  return decodeToString ? "" : new Uint8Array(0);
32
32
  }
33
+ let data;
33
34
  if (Uint8Array.fromBase64) {
34
- return Uint8Array.fromBase64(str, { alphabet: "base64url" });
35
+ data = Uint8Array.fromBase64(str, { alphabet: "base64url" });
36
+ } else {
37
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
38
+ while (str.length % 4) str += "=";
39
+ data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
35
40
  }
36
- str = str.replace(/-/g, "+").replace(/_/g, "/");
37
- while (str.length % 4) str += "=";
38
- const data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
39
41
  return decodeToString ? textDecoder.decode(data) : data;
40
42
  }
41
43
  function randomBytes(length) {
@@ -1,6 +1,6 @@
1
- import { i as importKey, g as getJWKFromSet } from './unjwt.BPpolBff.mjs';
2
- import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, e as isJWKSet, m as maybeArray } from './unjwt.X5vzu_l_.mjs';
3
- import { s as sign$1, v as verify$1 } from './unjwt.CauxOPN5.mjs';
1
+ import { i as importKey, g as getJWKFromSet } from './unjwt.DRUXIabl.mjs';
2
+ import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, e as isJWKSet, m as maybeArray } from './unjwt.BHpknTpg.mjs';
3
+ import { s as sign$1, v as verify$1 } from './unjwt.Ca03jPX3.mjs';
4
4
 
5
5
  async function sign(payload, key, options = {}) {
6
6
  const { protectedHeader: additionalProtectedHeader } = options;
@@ -33,7 +33,7 @@ interface JWSSignOptions {
33
33
  protectedHeader?: JWSHeaderParameters;
34
34
  }
35
35
  /** Result of JWS verification */
36
- interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
36
+ interface JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
37
37
  /** The decoded and verified payload. */
38
38
  payload: T;
39
39
  /** The JWS Protected Header. */
@@ -117,14 +117,20 @@ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => Crypt
117
117
  * @param options Signing options, including the algorithm (`alg`) and protected header parameters.
118
118
  * @returns A Promise resolving to the JWS Compact Serialization string.
119
119
  */
120
- declare function sign(payload: JWTClaims, key: JWK | Uint8Array, options?: JWSSignOptions): Promise<string>;
121
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK | Uint8Array, options?: JWSSignOptions): Promise<string>;
120
+ declare function sign(payload: JWTClaims, key: JWK, options?: JWSSignOptions): Promise<string>;
121
+ declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
122
122
  declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
123
123
  alg: JWSAlgorithm;
124
124
  }): Promise<string>;
125
125
  declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
126
126
  alg: JWSAlgorithm;
127
127
  }): Promise<string>;
128
+ declare function sign(payload: JWTClaims, key: Uint8Array, options: JWSSignOptions & {
129
+ alg: JWSAlgorithm;
130
+ }): Promise<string>;
131
+ declare function sign(payload: string | Uint8Array | Record<string, any>, key: Uint8Array, options: JWSSignOptions & {
132
+ alg: JWSAlgorithm;
133
+ }): Promise<string>;
128
134
  declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
129
135
  alg: JWSAlgorithm;
130
136
  }): Promise<string>;
@@ -137,7 +143,7 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
137
143
  * @returns A Promise resolving to an object containing the verified payload and protected header.
138
144
  * @throws If the JWS is invalid, signature verification fails, or options are not met.
139
145
  */
140
- declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
146
+ declare function verify<T extends JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
141
147
  declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
142
148
  forceUint8Array: true;
143
149
  }): Promise<JWSVerifyResult<Uint8Array>>;
@@ -148,7 +154,7 @@ type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
148
154
  type jws_JWSProtectedHeader = JWSProtectedHeader;
149
155
  type jws_JWSSignOptions = JWSSignOptions;
150
156
  type jws_JWSVerifyOptions = JWSVerifyOptions;
151
- type jws_JWSVerifyResult<T = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
157
+ type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
152
158
  declare const jws_sign: typeof sign;
153
159
  declare const jws_verify: typeof verify;
154
160
  declare namespace jws {
@@ -1,4 +1,4 @@
1
- import { c as checkSigCryptoKey } from './unjwt.BPpolBff.mjs';
1
+ import { c as checkSigCryptoKey } from './unjwt.DRUXIabl.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -125,7 +125,7 @@ interface JWEDecryptOptions {
125
125
  /**
126
126
  * Result of a JWE decryption operation.
127
127
  */
128
- interface JWEDecryptResult<T = JWTClaims | string> {
128
+ interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
129
129
  /** The decrypted payload. */
130
130
  payload: T;
131
131
  /** The JWE Protected Header. */
@@ -167,13 +167,13 @@ declare function encrypt(payload: string | Uint8Array | Record<string, any>, key
167
167
  * @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
168
168
  * @throws If JWE is invalid, decryption fails, or options are not met.
169
169
  */
170
- declare function decrypt<T = JWTClaims | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
170
+ declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
171
171
  declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
172
172
  forceUint8Array: true;
173
173
  }): Promise<JWEDecryptResult<Uint8Array>>;
174
174
 
175
175
  type jwe_JWEDecryptOptions = JWEDecryptOptions;
176
- type jwe_JWEDecryptResult<T = JWTClaims | string> = JWEDecryptResult<T>;
176
+ type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
177
177
  type jwe_JWEEncryptOptions = JWEEncryptOptions;
178
178
  type jwe_JWEHeaderParameters = JWEHeaderParameters;
179
179
  type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
@@ -48,7 +48,6 @@ declare function importKey(key: string): Promise<Uint8Array>;
48
48
  declare function importKey(key: Uint8Array): Promise<Uint8Array>;
49
49
  declare function importKey(key: CryptoKey): Promise<CryptoKey>;
50
50
  declare function importKey(key: JWK_oct): Promise<Uint8Array>;
51
- declare function importKey(key: Exclude<JWK, JWK_oct>, alg: string): Promise<CryptoKey>;
52
51
  declare function importKey(key: CryptoKey | JWK | Uint8Array | string, alg?: string): Promise<CryptoKey | Uint8Array>;
53
52
  /**
54
53
  * Exports a CryptoKey to a JWK (JSON Web Key) format.
@@ -48,7 +48,6 @@ declare function importKey(key: string): Promise<Uint8Array>;
48
48
  declare function importKey(key: Uint8Array): Promise<Uint8Array>;
49
49
  declare function importKey(key: CryptoKey): Promise<CryptoKey>;
50
50
  declare function importKey(key: JWK_oct): Promise<Uint8Array>;
51
- declare function importKey(key: Exclude<JWK, JWK_oct>, alg: string): Promise<CryptoKey>;
52
51
  declare function importKey(key: CryptoKey | JWK | Uint8Array | string, alg?: string): Promise<CryptoKey | Uint8Array>;
53
52
  /**
54
53
  * Exports a CryptoKey to a JWK (JSON Web Key) format.
@@ -1,4 +1,4 @@
1
- import { h as isCryptoKey, f as concatUint8Arrays, b as base64UrlEncode, j as base64Decode, k as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode, e as isJWKSet } from './unjwt.X5vzu_l_.mjs';
1
+ import { h as isCryptoKey, f as concatUint8Arrays, b as base64UrlEncode, j as base64Decode, k as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode, e as isJWKSet } from './unjwt.BHpknTpg.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -1095,12 +1095,12 @@ async function importKey(key, alg) {
1095
1095
  if ("k" in key && typeof key.k === "string") {
1096
1096
  return base64UrlDecode(key.k, false);
1097
1097
  } else {
1098
- if (!alg) {
1098
+ if (!key.alg && !alg) {
1099
1099
  throw new TypeError(
1100
1100
  "Algorithm must be provided when importing non-oct JWK"
1101
1101
  );
1102
1102
  }
1103
- return jwkTokey({ ...key, alg });
1103
+ return jwkTokey({ ...key, alg: key.alg || alg });
1104
1104
  }
1105
1105
  }
1106
1106
  throw new Error("Invalid key type provided to importKey");
@@ -33,7 +33,7 @@ interface JWSSignOptions {
33
33
  protectedHeader?: JWSHeaderParameters;
34
34
  }
35
35
  /** Result of JWS verification */
36
- interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
36
+ interface JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
37
37
  /** The decoded and verified payload. */
38
38
  payload: T;
39
39
  /** The JWS Protected Header. */
@@ -117,14 +117,20 @@ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => Crypt
117
117
  * @param options Signing options, including the algorithm (`alg`) and protected header parameters.
118
118
  * @returns A Promise resolving to the JWS Compact Serialization string.
119
119
  */
120
- declare function sign(payload: JWTClaims, key: JWK | Uint8Array, options?: JWSSignOptions): Promise<string>;
121
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK | Uint8Array, options?: JWSSignOptions): Promise<string>;
120
+ declare function sign(payload: JWTClaims, key: JWK, options?: JWSSignOptions): Promise<string>;
121
+ declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
122
122
  declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
123
123
  alg: JWSAlgorithm;
124
124
  }): Promise<string>;
125
125
  declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
126
126
  alg: JWSAlgorithm;
127
127
  }): Promise<string>;
128
+ declare function sign(payload: JWTClaims, key: Uint8Array, options: JWSSignOptions & {
129
+ alg: JWSAlgorithm;
130
+ }): Promise<string>;
131
+ declare function sign(payload: string | Uint8Array | Record<string, any>, key: Uint8Array, options: JWSSignOptions & {
132
+ alg: JWSAlgorithm;
133
+ }): Promise<string>;
128
134
  declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
129
135
  alg: JWSAlgorithm;
130
136
  }): Promise<string>;
@@ -137,7 +143,7 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
137
143
  * @returns A Promise resolving to an object containing the verified payload and protected header.
138
144
  * @throws If the JWS is invalid, signature verification fails, or options are not met.
139
145
  */
140
- declare function verify<T = JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
146
+ declare function verify<T extends JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
141
147
  declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
142
148
  forceUint8Array: true;
143
149
  }): Promise<JWSVerifyResult<Uint8Array>>;
@@ -148,7 +154,7 @@ type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
148
154
  type jws_JWSProtectedHeader = JWSProtectedHeader;
149
155
  type jws_JWSSignOptions = JWSSignOptions;
150
156
  type jws_JWSVerifyOptions = JWSVerifyOptions;
151
- type jws_JWSVerifyResult<T = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
157
+ type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
152
158
  declare const jws_sign: typeof sign;
153
159
  declare const jws_verify: typeof verify;
154
160
  declare namespace jws {
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- export { g as assertCryptoKey, j as base64Decode, k as base64Encode, d as base64UrlDecode, b as base64UrlEncode, f as concatUint8Arrays, h as isCryptoKey, l as isCryptoKeyPair, a as isJWK, e as isJWKSet, m as maybeArray, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.X5vzu_l_.mjs';
1
+ export { g as assertCryptoKey, j as base64Decode, k as base64Encode, d as base64UrlDecode, b as base64UrlEncode, f as concatUint8Arrays, h as isCryptoKey, l as isCryptoKeyPair, a as isJWK, e as isJWKSet, m as maybeArray, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.BHpknTpg.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",
@@ -45,7 +45,8 @@
45
45
  "lint:fix": "automd && eslint . --fix && prettier -w .",
46
46
  "prepack": "pnpm build",
47
47
  "release": "pnpm test && pnpm prepack && changelogen --release --push --publish",
48
- "test": "pnpm lint && pnpm test:types && vitest run --coverage --slowTestThreshold=500",
48
+ "test": "pnpm lint && pnpm test:types && vitest run --slowTestThreshold=500",
49
+ "test:coverage": "pnpm lint && pnpm test:types && vitest run --coverage --slowTestThreshold=500",
49
50
  "test:types": "tsc --noEmit --skipLibCheck"
50
51
  },
51
52
  "devDependencies": {