unjwt 0.4.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.
Files changed (49) hide show
  1. package/README.md +445 -190
  2. package/dist/index.d.mts +6 -5
  3. package/dist/index.d.ts +6 -5
  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 -3
  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.1gbuWbc6.mjs +1507 -0
  15. package/dist/shared/unjwt.B0XDPf8a.d.ts +189 -0
  16. package/dist/shared/unjwt.B4fFiy1c.d.mts +52 -0
  17. package/dist/shared/unjwt.BG_R52ey.d.mts +100 -0
  18. package/dist/shared/unjwt.BISJ5yt1.d.ts +52 -0
  19. package/dist/shared/unjwt.BxqF-n1S.mjs +167 -0
  20. package/dist/shared/unjwt.C9Xhi7hE.mjs +101 -0
  21. package/dist/shared/unjwt.CVKbKOFy.d.ts +100 -0
  22. package/dist/shared/unjwt.Cd9nTEWg.d.mts +52 -0
  23. package/dist/shared/unjwt.Ce72NmIz.mjs +453 -0
  24. package/dist/shared/unjwt.CxhGjEAX.d.mts +202 -0
  25. package/dist/shared/unjwt.CxhGjEAX.d.ts +202 -0
  26. package/dist/shared/unjwt.D1J1DelP.d.mts +198 -0
  27. package/dist/shared/unjwt.DHdDAH0L.mjs +83 -0
  28. package/dist/shared/unjwt.DQIYSlHj.d.mts +189 -0
  29. package/dist/shared/unjwt.DqmNvXMd.d.ts +52 -0
  30. package/dist/shared/unjwt.WvWb2zNM.d.ts +198 -0
  31. package/dist/utils.d.mts +2 -0
  32. package/dist/utils.d.ts +2 -0
  33. package/dist/utils.mjs +1 -0
  34. package/package.json +8 -4
  35. package/dist/shared/unjwt.4uzJv0cA.d.mts +0 -110
  36. package/dist/shared/unjwt.A7HKFx3n.d.mts +0 -52
  37. package/dist/shared/unjwt.BdjvpIUY.d.mts +0 -79
  38. package/dist/shared/unjwt.BmjmfFWo.d.ts +0 -79
  39. package/dist/shared/unjwt.C9ELsKeK.mjs +0 -120
  40. package/dist/shared/unjwt.CVUxLNoy.d.ts +0 -52
  41. package/dist/shared/unjwt.ChP7VhqI.d.ts +0 -110
  42. package/dist/shared/unjwt.DD0p18Gd.mjs +0 -81
  43. package/dist/shared/unjwt.DGsIvgyn.d.ts +0 -106
  44. package/dist/shared/unjwt.DPTwlVpK.mjs +0 -28
  45. package/dist/shared/unjwt.Dr-mxtq9.d.mts +0 -106
  46. package/dist/shared/unjwt.KOd0vXyx.mjs +0 -90
  47. package/dist/shared/unjwt._GivNhs2.mjs +0 -213
  48. package/dist/shared/unjwt.zb2wBNCJ.d.mts +0 -82
  49. package/dist/shared/unjwt.zb2wBNCJ.d.ts +0 -82
@@ -0,0 +1,202 @@
1
+ /** Structure returned for composite AES-CBC + HMAC keys. */
2
+ type CompositeKey = {
3
+ /** The AES-CBC encryption/decryption key. */
4
+ encryptionKey: CryptoKey;
5
+ /** The HMAC key for integrity/authentication. */
6
+ macKey: CryptoKey;
7
+ };
8
+ type GenerateKeyAlgorithm = Exclude<JWKAlgorithm, "none" | "dir" | JWK_PBES2 | JWK_ECDH_ES>;
9
+ /** Options for the generateKey function. */
10
+ interface GenerateKeyOptions {
11
+ /** Key usages for the generated key(s). Note: For composite keys (CBC), default usages are applied separately. */
12
+ keyUsage?: KeyUsage[];
13
+ /** Mark the key(s) as extractable. Defaults to true. */
14
+ extractable?: boolean;
15
+ /** RSA modulus length. Defaults to 2048. */
16
+ modulusLength?: number;
17
+ /** RSA public exponent. Defaults to 65537 (0x010001). */
18
+ publicExponent?: Uint8Array;
19
+ /** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
20
+ toJWK?: boolean | undefined;
21
+ }
22
+ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? {
23
+ privateKey: JWK;
24
+ publicKey: JWK;
25
+ } : JWK;
26
+ type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
27
+ type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
28
+ /** Options for the deriveKeyFromPassword function. */
29
+ interface DeriveKeyOptions {
30
+ /** Salt value (p2s). Must be at least 8 bytes. */
31
+ salt: Uint8Array;
32
+ /** Iteration count (p2c). Must be a positive integer. */
33
+ iterations: number;
34
+ /** Key usages for the derived key. Defaults to ["wrapKey", "unwrapKey"]. */
35
+ keyUsage?: KeyUsage[];
36
+ /** Mark the derived key as extractable. Defaults to false. */
37
+ extractable?: boolean;
38
+ /** Export the derived key as JWK. If true, the key will be returned in JWK_oct format. */
39
+ toJWK?: boolean | undefined;
40
+ }
41
+ type DeriveKeyReturn<TOptions extends DeriveKeyOptions> = TOptions["toJWK"] extends true ? JWK_oct : CryptoKey;
42
+ type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES;
43
+ type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
44
+ /** Options for the wrapKey function. */
45
+ interface WrapKeyOptions {
46
+ /** Initialization Vector for AES-GCMKW. Generated if not provided. */
47
+ iv?: Uint8Array;
48
+ /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
49
+ p2s?: Uint8Array;
50
+ /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
51
+ p2c?: number;
52
+ /** ECDH-ES Ephemeral Public Key. Generated if not provided for ECDH-ES. */
53
+ epk?: JWK_EC_Public;
54
+ /** ECDH-ES Agreement PartyUInfo. */
55
+ apu?: Uint8Array;
56
+ /** ECDH-ES Agreement PartyVInfo. */
57
+ apv?: Uint8Array;
58
+ }
59
+ /** Result of the wrapKey function. */
60
+ interface WrapKeyResult {
61
+ /** The wrapped key (Ciphertext). */
62
+ encryptedKey: Uint8Array;
63
+ /** Initialization Vector used (only for AES-GCMKW). Base64URL encoded. */
64
+ iv?: string;
65
+ /** Authentication Tag generated (only for AES-GCMKW). Base64URL encoded. */
66
+ tag?: string;
67
+ /** PBES2 Salt value used (only for PBES2). Base64URL encoded. */
68
+ p2s?: string;
69
+ /** PBES2 Iteration count used (only for PBES2). */
70
+ p2c?: number;
71
+ /** ECDH-ES Ephemeral Public Key used (only for ECDH-ES). */
72
+ epk?: JWK_EC_Public;
73
+ /** ECDH-ES Agreement PartyUInfo used (only for ECDH-ES). Base64URL encoded. */
74
+ apu?: string;
75
+ /** ECDH-ES Agreement PartyVInfo used (only for ECDH-ES). Base64URL encoded. */
76
+ apv?: string;
77
+ }
78
+ /** Options for the unwrapKey function. */
79
+ interface UnwrapKeyOptions {
80
+ /** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
81
+ iv?: Uint8Array | string;
82
+ /** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
83
+ tag?: Uint8Array | string;
84
+ /** PBES2 Salt value (required for PBES2). Base64URL encoded or Uint8Array. */
85
+ p2s?: Uint8Array | string;
86
+ /** PBES2 Iteration count (required for PBES2). */
87
+ p2c?: number;
88
+ /** ECDH-ES Ephemeral Public Key (required for ECDH-ES). */
89
+ epk?: JWK_EC_Public;
90
+ /** ECDH-ES Agreement PartyUInfo. Base64URL encoded or Uint8Array. */
91
+ apu?: Uint8Array | string;
92
+ /** ECDH-ES Agreement PartyVInfo. Base64URL encoded or Uint8Array. */
93
+ apv?: Uint8Array | string;
94
+ /** Expected unwrapped key algorithm (e.g., 'AES-GCM', 'AES-CBC'). Used by crypto.subtle.unwrapKey. */
95
+ unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
96
+ /** Expected key usages for the unwrapped key. */
97
+ keyUsage?: KeyUsage[];
98
+ /** Mark the unwrapped key as extractable. Defaults to true. */
99
+ extractable?: boolean;
100
+ returnAs?: boolean | undefined;
101
+ }
102
+ /**
103
+ * Forked from https://github.com/panva/jose/tree/v6.0.10
104
+ * Copyright (c) 2018 Filip Skokan.
105
+ * LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md
106
+ */
107
+ /** Generic JSON Web Key Parameters. */
108
+ interface JWKParameters {
109
+ /** JWK "kty" (Key Type) Parameter */
110
+ kty: string;
111
+ /**
112
+ * JWK "alg" (Algorithm) Parameter
113
+ *
114
+ * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
115
+ */
116
+ alg?: string;
117
+ /** JWK "key_ops" (Key Operations) Parameter */
118
+ key_ops?: KeyUsage[];
119
+ /** JWK "ext" (Extractable) Parameter */
120
+ ext?: boolean;
121
+ /** JWK "use" (Public Key Use) Parameter */
122
+ use?: string;
123
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter */
124
+ x5c?: string[];
125
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
126
+ x5t?: string;
127
+ /** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
128
+ "x5t#S256"?: string;
129
+ /** JWK "x5u" (X.509 URL) Parameter */
130
+ x5u?: string;
131
+ /** JWK "kid" (Key ID) Parameter */
132
+ kid?: string;
133
+ }
134
+ /** Public EC JSON Web Keys */
135
+ interface JWK_EC_Public extends JWKParameters {
136
+ /** EC JWK "crv" (Curve) Parameter */
137
+ crv: string;
138
+ /** EC JWK "x" (X Coordinate) Parameter */
139
+ x: string;
140
+ /** EC JWK "y" (Y Coordinate) Parameter */
141
+ y: string;
142
+ }
143
+ /** Private EC JSON Web Keys */
144
+ interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
145
+ /** EC JWK "d" (ECC Private Key) Parameter */
146
+ d: string;
147
+ }
148
+ /** EC JSON Web Keys */
149
+ type JWK_EC = JWK_EC_Public | JWK_EC_Private;
150
+ /** Public RSA JSON Web Keys */
151
+ interface JWK_RSA_Public extends JWKParameters {
152
+ /** RSA JWK "e" (Exponent) Parameter */
153
+ e: string;
154
+ /** RSA JWK "n" (Modulus) Parameter */
155
+ n: string;
156
+ oth?: RsaOtherPrimesInfo[];
157
+ }
158
+ /** Private RSA JSON Web Keys */
159
+ interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
160
+ /** RSA JWK "d" (Private Exponent) Parameter */
161
+ d: string;
162
+ /** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
163
+ dp: string;
164
+ /** RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
165
+ dq: string;
166
+ /** RSA JWK "p" (First Prime Factor) Parameter */
167
+ p: string;
168
+ /** RSA JWK "q" (Second Prime Factor) Parameter */
169
+ q: string;
170
+ /** RSA JWK "qi" (First CRT Coefficient) Parameter */
171
+ qi: string;
172
+ }
173
+ /** RSA JSON Web Keys */
174
+ type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
175
+ /** oct JSON Web Keys */
176
+ interface JWK_oct extends JWKParameters {
177
+ /** Oct JWK "k" (Key Value) Parameter */
178
+ k: string;
179
+ }
180
+ /**
181
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA" and "oct" key types are supported.
182
+ */
183
+ type JWK = JWK_oct | JWK_RSA | JWK_EC;
184
+ /** JWK Key Algorithms */
185
+ type JWK_HMAC = "HS256" | "HS384" | "HS512";
186
+ type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
187
+ type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
188
+ type JWK_ECDSA = "ES256" | "ES384" | "ES512";
189
+ type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
190
+ type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
191
+ type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
192
+ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
193
+ type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
194
+ type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
195
+ type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
196
+ type JWK_ED = "Ed25519" | "EdDSA";
197
+ type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
198
+ type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
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;
201
+
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 };
@@ -0,0 +1,202 @@
1
+ /** Structure returned for composite AES-CBC + HMAC keys. */
2
+ type CompositeKey = {
3
+ /** The AES-CBC encryption/decryption key. */
4
+ encryptionKey: CryptoKey;
5
+ /** The HMAC key for integrity/authentication. */
6
+ macKey: CryptoKey;
7
+ };
8
+ type GenerateKeyAlgorithm = Exclude<JWKAlgorithm, "none" | "dir" | JWK_PBES2 | JWK_ECDH_ES>;
9
+ /** Options for the generateKey function. */
10
+ interface GenerateKeyOptions {
11
+ /** Key usages for the generated key(s). Note: For composite keys (CBC), default usages are applied separately. */
12
+ keyUsage?: KeyUsage[];
13
+ /** Mark the key(s) as extractable. Defaults to true. */
14
+ extractable?: boolean;
15
+ /** RSA modulus length. Defaults to 2048. */
16
+ modulusLength?: number;
17
+ /** RSA public exponent. Defaults to 65537 (0x010001). */
18
+ publicExponent?: Uint8Array;
19
+ /** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
20
+ toJWK?: boolean | undefined;
21
+ }
22
+ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? {
23
+ privateKey: JWK;
24
+ publicKey: JWK;
25
+ } : JWK;
26
+ type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
27
+ type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
28
+ /** Options for the deriveKeyFromPassword function. */
29
+ interface DeriveKeyOptions {
30
+ /** Salt value (p2s). Must be at least 8 bytes. */
31
+ salt: Uint8Array;
32
+ /** Iteration count (p2c). Must be a positive integer. */
33
+ iterations: number;
34
+ /** Key usages for the derived key. Defaults to ["wrapKey", "unwrapKey"]. */
35
+ keyUsage?: KeyUsage[];
36
+ /** Mark the derived key as extractable. Defaults to false. */
37
+ extractable?: boolean;
38
+ /** Export the derived key as JWK. If true, the key will be returned in JWK_oct format. */
39
+ toJWK?: boolean | undefined;
40
+ }
41
+ type DeriveKeyReturn<TOptions extends DeriveKeyOptions> = TOptions["toJWK"] extends true ? JWK_oct : CryptoKey;
42
+ type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES;
43
+ type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
44
+ /** Options for the wrapKey function. */
45
+ interface WrapKeyOptions {
46
+ /** Initialization Vector for AES-GCMKW. Generated if not provided. */
47
+ iv?: Uint8Array;
48
+ /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
49
+ p2s?: Uint8Array;
50
+ /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
51
+ p2c?: number;
52
+ /** ECDH-ES Ephemeral Public Key. Generated if not provided for ECDH-ES. */
53
+ epk?: JWK_EC_Public;
54
+ /** ECDH-ES Agreement PartyUInfo. */
55
+ apu?: Uint8Array;
56
+ /** ECDH-ES Agreement PartyVInfo. */
57
+ apv?: Uint8Array;
58
+ }
59
+ /** Result of the wrapKey function. */
60
+ interface WrapKeyResult {
61
+ /** The wrapped key (Ciphertext). */
62
+ encryptedKey: Uint8Array;
63
+ /** Initialization Vector used (only for AES-GCMKW). Base64URL encoded. */
64
+ iv?: string;
65
+ /** Authentication Tag generated (only for AES-GCMKW). Base64URL encoded. */
66
+ tag?: string;
67
+ /** PBES2 Salt value used (only for PBES2). Base64URL encoded. */
68
+ p2s?: string;
69
+ /** PBES2 Iteration count used (only for PBES2). */
70
+ p2c?: number;
71
+ /** ECDH-ES Ephemeral Public Key used (only for ECDH-ES). */
72
+ epk?: JWK_EC_Public;
73
+ /** ECDH-ES Agreement PartyUInfo used (only for ECDH-ES). Base64URL encoded. */
74
+ apu?: string;
75
+ /** ECDH-ES Agreement PartyVInfo used (only for ECDH-ES). Base64URL encoded. */
76
+ apv?: string;
77
+ }
78
+ /** Options for the unwrapKey function. */
79
+ interface UnwrapKeyOptions {
80
+ /** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
81
+ iv?: Uint8Array | string;
82
+ /** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
83
+ tag?: Uint8Array | string;
84
+ /** PBES2 Salt value (required for PBES2). Base64URL encoded or Uint8Array. */
85
+ p2s?: Uint8Array | string;
86
+ /** PBES2 Iteration count (required for PBES2). */
87
+ p2c?: number;
88
+ /** ECDH-ES Ephemeral Public Key (required for ECDH-ES). */
89
+ epk?: JWK_EC_Public;
90
+ /** ECDH-ES Agreement PartyUInfo. Base64URL encoded or Uint8Array. */
91
+ apu?: Uint8Array | string;
92
+ /** ECDH-ES Agreement PartyVInfo. Base64URL encoded or Uint8Array. */
93
+ apv?: Uint8Array | string;
94
+ /** Expected unwrapped key algorithm (e.g., 'AES-GCM', 'AES-CBC'). Used by crypto.subtle.unwrapKey. */
95
+ unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
96
+ /** Expected key usages for the unwrapped key. */
97
+ keyUsage?: KeyUsage[];
98
+ /** Mark the unwrapped key as extractable. Defaults to true. */
99
+ extractable?: boolean;
100
+ returnAs?: boolean | undefined;
101
+ }
102
+ /**
103
+ * Forked from https://github.com/panva/jose/tree/v6.0.10
104
+ * Copyright (c) 2018 Filip Skokan.
105
+ * LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md
106
+ */
107
+ /** Generic JSON Web Key Parameters. */
108
+ interface JWKParameters {
109
+ /** JWK "kty" (Key Type) Parameter */
110
+ kty: string;
111
+ /**
112
+ * JWK "alg" (Algorithm) Parameter
113
+ *
114
+ * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
115
+ */
116
+ alg?: string;
117
+ /** JWK "key_ops" (Key Operations) Parameter */
118
+ key_ops?: KeyUsage[];
119
+ /** JWK "ext" (Extractable) Parameter */
120
+ ext?: boolean;
121
+ /** JWK "use" (Public Key Use) Parameter */
122
+ use?: string;
123
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter */
124
+ x5c?: string[];
125
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
126
+ x5t?: string;
127
+ /** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
128
+ "x5t#S256"?: string;
129
+ /** JWK "x5u" (X.509 URL) Parameter */
130
+ x5u?: string;
131
+ /** JWK "kid" (Key ID) Parameter */
132
+ kid?: string;
133
+ }
134
+ /** Public EC JSON Web Keys */
135
+ interface JWK_EC_Public extends JWKParameters {
136
+ /** EC JWK "crv" (Curve) Parameter */
137
+ crv: string;
138
+ /** EC JWK "x" (X Coordinate) Parameter */
139
+ x: string;
140
+ /** EC JWK "y" (Y Coordinate) Parameter */
141
+ y: string;
142
+ }
143
+ /** Private EC JSON Web Keys */
144
+ interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
145
+ /** EC JWK "d" (ECC Private Key) Parameter */
146
+ d: string;
147
+ }
148
+ /** EC JSON Web Keys */
149
+ type JWK_EC = JWK_EC_Public | JWK_EC_Private;
150
+ /** Public RSA JSON Web Keys */
151
+ interface JWK_RSA_Public extends JWKParameters {
152
+ /** RSA JWK "e" (Exponent) Parameter */
153
+ e: string;
154
+ /** RSA JWK "n" (Modulus) Parameter */
155
+ n: string;
156
+ oth?: RsaOtherPrimesInfo[];
157
+ }
158
+ /** Private RSA JSON Web Keys */
159
+ interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
160
+ /** RSA JWK "d" (Private Exponent) Parameter */
161
+ d: string;
162
+ /** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
163
+ dp: string;
164
+ /** RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
165
+ dq: string;
166
+ /** RSA JWK "p" (First Prime Factor) Parameter */
167
+ p: string;
168
+ /** RSA JWK "q" (Second Prime Factor) Parameter */
169
+ q: string;
170
+ /** RSA JWK "qi" (First CRT Coefficient) Parameter */
171
+ qi: string;
172
+ }
173
+ /** RSA JSON Web Keys */
174
+ type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
175
+ /** oct JSON Web Keys */
176
+ interface JWK_oct extends JWKParameters {
177
+ /** Oct JWK "k" (Key Value) Parameter */
178
+ k: string;
179
+ }
180
+ /**
181
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA" and "oct" key types are supported.
182
+ */
183
+ type JWK = JWK_oct | JWK_RSA | JWK_EC;
184
+ /** JWK Key Algorithms */
185
+ type JWK_HMAC = "HS256" | "HS384" | "HS512";
186
+ type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
187
+ type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
188
+ type JWK_ECDSA = "ES256" | "ES384" | "ES512";
189
+ type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
190
+ type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
191
+ type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
192
+ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
193
+ type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
194
+ type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
195
+ type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
196
+ type JWK_ED = "Ed25519" | "EdDSA";
197
+ type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
198
+ type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
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;
201
+
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 };
@@ -0,0 +1,198 @@
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
+ }
16
+
17
+ /**
18
+ * Generates a cryptographic key for the specified algorithm.
19
+ *
20
+ * @param alg The JWA algorithm identifier (e.g., "HS256", "RS256", "A128GCM").
21
+ * @param options Configuration options for key generation.
22
+ * @returns A Promise resolving to the generated key (CryptoKey, CryptoKeyPair, or Uint8Array) or its JWK representation.
23
+ */
24
+ declare function generateKey<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions>(alg: TAlg, options?: TOptions): Promise<GenerateKeyReturn<TAlg, TOptions>>;
25
+ /**
26
+ * Derives a key from a password using PBKDF2 as specified by PBES2 algorithms.
27
+ *
28
+ * @param password The password to derive the key from (string or Uint8Array).
29
+ * @param alg The PBES2 algorithm identifier (e.g., "PBES2-HS256+A128KW").
30
+ * @param options Configuration options including salt and iterations.
31
+ * @returns A Promise resolving to the derived key (CryptoKey) or its JWK_oct representation.
32
+ */
33
+ declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends DeriveKeyOptions>(password: string | Uint8Array, alg: TAlg, options: TOptions): Promise<DeriveKeyReturn<TOptions>>;
34
+ /**
35
+ * Imports a key from various formats (CryptoKey, JWK, Uint8Array).
36
+ *
37
+ * - If `key` is a CryptoKey, it's returned directly.
38
+ * - If `key` is a Uint8Array, it's returned directly.
39
+ * - If `key` is a JWK_oct (symmetric key with 'k'), the raw key bytes are returned as Uint8Array.
40
+ * - If `key` is any other JWK type (asymmetric), the `alg` parameter is required, and a CryptoKey is returned.
41
+ *
42
+ * @param key The key to import.
43
+ * @param alg The algorithm hint, required when importing asymmetric JWKs.
44
+ * @returns A Promise resolving to the imported key as CryptoKey or Uint8Array.
45
+ */
46
+ declare function importKey(key: string): Promise<Uint8Array>;
47
+ declare function importKey(key: Uint8Array): Promise<Uint8Array>;
48
+ declare function importKey(key: CryptoKey): Promise<CryptoKey>;
49
+ declare function importKey(key: JWK_oct): Promise<Uint8Array>;
50
+ declare function importKey(key: Exclude<JWK, JWK_oct>, alg: string): Promise<CryptoKey>;
51
+ declare function importKey(key: CryptoKey | JWK | Uint8Array | string, alg?: string): Promise<CryptoKey | Uint8Array>;
52
+ /**
53
+ * Exports a CryptoKey to a JWK (JSON Web Key) format.
54
+ *
55
+ * @param key The CryptoKey to export.
56
+ * @param jwk Optional partial JWK to merge with the exported key, allowing overrides.
57
+ * @returns A Promise resolving to the exported JWK.
58
+ */
59
+ declare function exportKey(key: CryptoKey, jwk?: Partial<JWK>): Promise<JWK>;
60
+ /**
61
+ * Wraps a Content Encryption Key (CEK) using the specified algorithm and wrapping key.
62
+ *
63
+ * @param alg The JWA key management algorithm (e.g., "A128KW", "RSA-OAEP", "PBES2-HS256+A128KW").
64
+ * @param keyToWrap The key to be wrapped (CEK), typically a symmetric key as Uint8Array or CryptoKey.
65
+ * @param wrappingKey The key used to wrap the CEK (CryptoKey, JWK, or password string/Uint8Array for PBES2).
66
+ * @param options Additional options required by certain algorithms (e.g., p2s, p2c for PBES2).
67
+ * @returns A Promise resolving to an object containing the wrapped key and any necessary parameters (iv, tag, epk, etc.).
68
+ */
69
+ declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uint8Array, wrappingKey: CryptoKey | JWK | string | Uint8Array, options?: WrapKeyOptions): Promise<WrapKeyResult>;
70
+ /**
71
+ * Unwraps a Content Encryption Key (CEK) using the specified algorithm and unwrapping key.
72
+ *
73
+ * @param alg The JWA key management algorithm (e.g., "A128KW", "RSA-OAEP", "PBES2-HS256+A128KW").
74
+ * @param wrappedKey The wrapped key (ciphertext) as Uint8Array.
75
+ * @param unwrappingKey The key used to unwrap the CEK (CryptoKey, JWK, or password string/Uint8Array for PBES2).
76
+ * @param options Additional options required by certain algorithms (e.g., iv, tag, p2s, p2c, epk).
77
+ * @returns A Promise resolving to the unwrapped key (CEK) as a CryptoKey or Uint8Array.
78
+ */
79
+ declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyManagementAlgorithm, wrappedKey: Uint8Array, unwrappingKey: CryptoKey | JWK | string | Uint8Array, options?: UnwrapKeyOptions & {
80
+ returnAs?: T;
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>;
104
+
105
+ declare const jwk_CompositeKey: typeof CompositeKey;
106
+ declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
107
+ declare const jwk_DeriveKeyOptions: typeof DeriveKeyOptions;
108
+ declare const jwk_DeriveKeyReturn: typeof DeriveKeyReturn;
109
+ declare const jwk_GenerateKeyAlgorithm: typeof GenerateKeyAlgorithm;
110
+ declare const jwk_GenerateKeyOptions: typeof GenerateKeyOptions;
111
+ declare const jwk_GenerateKeyReturn: typeof GenerateKeyReturn;
112
+ declare const jwk_JWK: typeof JWK;
113
+ declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
114
+ declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
115
+ declare const jwk_JWKParameters: typeof JWKParameters;
116
+ declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
117
+ declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
118
+ declare const jwk_JWK_AES_GCM_KW: typeof JWK_AES_GCM_KW;
119
+ declare const jwk_JWK_AES_KW: typeof JWK_AES_KW;
120
+ declare const jwk_JWK_Asymmetric_Algorithm: typeof JWK_Asymmetric_Algorithm;
121
+ declare const jwk_JWK_EC: typeof JWK_EC;
122
+ declare const jwk_JWK_ECDH_ES: typeof JWK_ECDH_ES;
123
+ declare const jwk_JWK_ECDSA: typeof JWK_ECDSA;
124
+ declare const jwk_JWK_EC_Private: typeof JWK_EC_Private;
125
+ declare const jwk_JWK_EC_Public: typeof JWK_EC_Public;
126
+ declare const jwk_JWK_ED: typeof JWK_ED;
127
+ declare const jwk_JWK_HMAC: typeof JWK_HMAC;
128
+ declare const jwk_JWK_PBES2: typeof JWK_PBES2;
129
+ declare const jwk_JWK_RSA: typeof JWK_RSA;
130
+ declare const jwk_JWK_RSA_ENC: typeof JWK_RSA_ENC;
131
+ declare const jwk_JWK_RSA_PSS: typeof JWK_RSA_PSS;
132
+ declare const jwk_JWK_RSA_Private: typeof JWK_RSA_Private;
133
+ declare const jwk_JWK_RSA_Public: typeof JWK_RSA_Public;
134
+ declare const jwk_JWK_RSA_SIGN: typeof JWK_RSA_SIGN;
135
+ declare const jwk_JWK_Symmetric_Algorithm: typeof JWK_Symmetric_Algorithm;
136
+ declare const jwk_JWK_oct: typeof JWK_oct;
137
+ declare const jwk_KeyManagementAlgorithm: typeof KeyManagementAlgorithm;
138
+ declare const jwk_UnwrapKeyOptions: typeof UnwrapKeyOptions;
139
+ declare const jwk_WrapKeyOptions: typeof WrapKeyOptions;
140
+ declare const jwk_WrapKeyResult: typeof WrapKeyResult;
141
+ declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
142
+ declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
143
+ declare const jwk_exportKey: typeof exportKey;
144
+ declare const jwk_generateKey: typeof generateKey;
145
+ declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
146
+ declare const jwk_importKey: typeof importKey;
147
+ declare const jwk_unwrapKey: typeof unwrapKey;
148
+ declare const jwk_wrapKey: typeof wrapKey;
149
+ declare namespace jwk {
150
+ export {
151
+ jwk_CompositeKey as CompositeKey,
152
+ jwk_ContentEncryptionAlgorithm as ContentEncryptionAlgorithm,
153
+ jwk_DeriveKeyOptions as DeriveKeyOptions,
154
+ jwk_DeriveKeyReturn as DeriveKeyReturn,
155
+ jwk_GenerateKeyAlgorithm as GenerateKeyAlgorithm,
156
+ jwk_GenerateKeyOptions as GenerateKeyOptions,
157
+ jwk_GenerateKeyReturn as GenerateKeyReturn,
158
+ jwk_JWK as JWK,
159
+ jwk_JWKAlgorithm as JWKAlgorithm,
160
+ jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
161
+ jwk_JWKParameters as JWKParameters,
162
+ jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
163
+ jwk_JWK_AES_GCM as JWK_AES_GCM,
164
+ jwk_JWK_AES_GCM_KW as JWK_AES_GCM_KW,
165
+ jwk_JWK_AES_KW as JWK_AES_KW,
166
+ jwk_JWK_Asymmetric_Algorithm as JWK_Asymmetric_Algorithm,
167
+ jwk_JWK_EC as JWK_EC,
168
+ jwk_JWK_ECDH_ES as JWK_ECDH_ES,
169
+ jwk_JWK_ECDSA as JWK_ECDSA,
170
+ jwk_JWK_EC_Private as JWK_EC_Private,
171
+ jwk_JWK_EC_Public as JWK_EC_Public,
172
+ jwk_JWK_ED as JWK_ED,
173
+ jwk_JWK_HMAC as JWK_HMAC,
174
+ jwk_JWK_PBES2 as JWK_PBES2,
175
+ jwk_JWK_RSA as JWK_RSA,
176
+ jwk_JWK_RSA_ENC as JWK_RSA_ENC,
177
+ jwk_JWK_RSA_PSS as JWK_RSA_PSS,
178
+ jwk_JWK_RSA_Private as JWK_RSA_Private,
179
+ jwk_JWK_RSA_Public as JWK_RSA_Public,
180
+ jwk_JWK_RSA_SIGN as JWK_RSA_SIGN,
181
+ jwk_JWK_Symmetric_Algorithm as JWK_Symmetric_Algorithm,
182
+ jwk_JWK_oct as JWK_oct,
183
+ jwk_KeyManagementAlgorithm as KeyManagementAlgorithm,
184
+ jwk_UnwrapKeyOptions as UnwrapKeyOptions,
185
+ jwk_WrapKeyOptions as WrapKeyOptions,
186
+ jwk_WrapKeyResult as WrapKeyResult,
187
+ jwk_deriveKeyFromPassword as deriveKeyFromPassword,
188
+ jwk_exportJWKToPEM as exportJWKToPEM,
189
+ jwk_exportKey as exportKey,
190
+ jwk_generateKey as generateKey,
191
+ jwk_importJWKFromPEM as importJWKFromPEM,
192
+ jwk_importKey as importKey,
193
+ jwk_unwrapKey as unwrapKey,
194
+ jwk_wrapKey as wrapKey,
195
+ };
196
+ }
197
+
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 };