unjwt 0.5.7 → 0.5.9
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.mjs +1 -1
- package/dist/jws.mjs +1 -1
- package/dist/shared/{unjwt.DqUOpdA-.mjs → unjwt.wHjOCapq.mjs} +7 -3
- package/package.json +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/jwe.d.ts +0 -3
- package/dist/jwk.d.ts +0 -3
- package/dist/jws.d.ts +0 -3
- package/dist/shared/unjwt.CoSilGqk.d.ts +0 -189
- package/dist/shared/unjwt.CrcUJklb.d.ts +0 -221
- package/dist/shared/unjwt.D4DUiNeM.d.ts +0 -58
- package/dist/shared/unjwt.D9da8HQF.d.ts +0 -210
- package/dist/shared/unjwt.c10n3uM8.d.ts +0 -52
- package/dist/shared/unjwt.w-IAnI15.d.ts +0 -172
- package/dist/utils.d.ts +0 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { i as utils } from './shared/unjwt.BHpknTpg.mjs';
|
|
2
2
|
export { j as jwe } from './shared/unjwt.B2olxeGL.mjs';
|
|
3
3
|
export { j as jwk } from './shared/unjwt.DRUXIabl.mjs';
|
|
4
|
-
export { j as jws } from './shared/unjwt.
|
|
4
|
+
export { j as jws } from './shared/unjwt.wHjOCapq.mjs';
|
|
5
5
|
import './shared/unjwt.Ca03jPX3.mjs';
|
package/dist/jws.mjs
CHANGED
|
@@ -16,6 +16,8 @@ async function sign(payload, key, options = {}) {
|
|
|
16
16
|
const signingKey = await importKey(key, alg);
|
|
17
17
|
const protectedHeader = {
|
|
18
18
|
...additionalProtectedHeader,
|
|
19
|
+
...isJWK(key) && key.kid ? { kid: additionalProtectedHeader?.kid || key.kid } : {},
|
|
20
|
+
// Include kid if available
|
|
19
21
|
alg,
|
|
20
22
|
typ: additionalProtectedHeader?.typ ?? (typeof payload === "object" && !(payload instanceof Uint8Array) ? "JWT" : void 0)
|
|
21
23
|
// Default typ to JWT for objects
|
|
@@ -30,9 +32,11 @@ async function sign(payload, key, options = {}) {
|
|
|
30
32
|
let computedPayload = void 0;
|
|
31
33
|
if (options.expiresIn !== void 0 && protectedHeader.typ === "JWT" && typeof payload === "object" && !(payload instanceof Uint8Array) && !payload.exp) {
|
|
32
34
|
computedPayload = { ...payload };
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const currentTime = Math.round(
|
|
36
|
+
(options.currentDate ?? /* @__PURE__ */ new Date()).getTime() / 1e3
|
|
37
|
+
);
|
|
38
|
+
computedPayload.iat ||= currentTime;
|
|
39
|
+
computedPayload.exp = currentTime + options.expiresIn;
|
|
36
40
|
}
|
|
37
41
|
const protectedHeaderString = JSON.stringify(protectedHeader);
|
|
38
42
|
const protectedHeaderEncoded = base64UrlEncode(protectedHeaderString);
|
package/package.json
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
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.w-IAnI15.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
|
-
export { i as utils } from './shared/unjwt.D4DUiNeM.js';
|
|
6
|
-
export { j as jwk } from './shared/unjwt.CrcUJklb.js';
|
package/dist/jwe.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import './shared/unjwt.D9da8HQF.js';
|
|
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.CoSilGqk.js';
|
package/dist/jwk.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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
|
-
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.CrcUJklb.js';
|
package/dist/jws.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import './shared/unjwt.D9da8HQF.js';
|
|
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.w-IAnI15.js';
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.D9da8HQF.js';
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
|
|
3
|
-
|
|
4
|
-
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
5
|
-
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
6
|
-
/**
|
|
7
|
-
* `alg` (Algorithm): Header Parameter - Key Management Algorithm
|
|
8
|
-
*/
|
|
9
|
-
alg?: string;
|
|
10
|
-
/**
|
|
11
|
-
* `enc` (Encryption Algorithm): Header Parameter - Content Encryption Algorithm
|
|
12
|
-
*/
|
|
13
|
-
enc?: string;
|
|
14
|
-
/**
|
|
15
|
-
* `p2c` (PBES2 Count): Header Parameter
|
|
16
|
-
*/
|
|
17
|
-
p2c?: number;
|
|
18
|
-
/**
|
|
19
|
-
* `p2s` (PBES2 Salt): Header Parameter. Base64URL encoded.
|
|
20
|
-
*/
|
|
21
|
-
p2s?: string;
|
|
22
|
-
/**
|
|
23
|
-
* "iv" (Initialization Vector) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
|
|
24
|
-
*/
|
|
25
|
-
iv?: string;
|
|
26
|
-
/**
|
|
27
|
-
* "tag" (Authentication Tag) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
|
|
28
|
-
*/
|
|
29
|
-
tag?: string;
|
|
30
|
-
/**
|
|
31
|
-
* "epk" (Ephemeral Public Key) Header Parameter for ECDH-ES.
|
|
32
|
-
*/
|
|
33
|
-
epk?: JWK_EC_Public;
|
|
34
|
-
/**
|
|
35
|
-
* "apu" (Agreement PartyUInfo) Header Parameter for ECDH-ES. Base64URL encoded.
|
|
36
|
-
*/
|
|
37
|
-
apu?: string;
|
|
38
|
-
/**
|
|
39
|
-
* "apv" (Agreement PartyVInfo) Header Parameter for ECDH-ES. Base64URL encoded.
|
|
40
|
-
*/
|
|
41
|
-
apv?: string;
|
|
42
|
-
/** Any other JWE Header member. */
|
|
43
|
-
[propName: string]: unknown;
|
|
44
|
-
}
|
|
45
|
-
/** Recognized JWE Key Management-related Header Parameters. */
|
|
46
|
-
interface JWEKeyManagementHeaderParameters {
|
|
47
|
-
apu?: Uint8Array;
|
|
48
|
-
apv?: Uint8Array;
|
|
49
|
-
/**
|
|
50
|
-
* For Internal use only
|
|
51
|
-
*/
|
|
52
|
-
p2c?: number;
|
|
53
|
-
/**
|
|
54
|
-
* For Internal use only
|
|
55
|
-
*/
|
|
56
|
-
p2s?: Uint8Array;
|
|
57
|
-
/**
|
|
58
|
-
* For Internal use only
|
|
59
|
-
*/
|
|
60
|
-
iv?: Uint8Array;
|
|
61
|
-
/**
|
|
62
|
-
* For Internal use only
|
|
63
|
-
*/
|
|
64
|
-
epk?: CryptoKey;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* JWE (JSON Web Encryption) encryption options
|
|
68
|
-
*/
|
|
69
|
-
interface JWEEncryptOptions {
|
|
70
|
-
/** JWE "alg" (Algorithm) Header Parameter. Key Management Algorithm. */
|
|
71
|
-
alg?: KeyManagementAlgorithm;
|
|
72
|
-
/** JWE "enc" (Encryption Algorithm) Header Parameter. Content Encryption Algorithm. */
|
|
73
|
-
enc?: ContentEncryptionAlgorithm;
|
|
74
|
-
/** Additional JWE Protected Header parameters. */
|
|
75
|
-
protectedHeader?: Omit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "apu" | "apv">;
|
|
76
|
-
/** Initialization Vector for AES-GCMKW key wrapping. Generated if not provided. */
|
|
77
|
-
keyManagementIV?: Uint8Array;
|
|
78
|
-
/** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
|
|
79
|
-
p2s?: Uint8Array;
|
|
80
|
-
/** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
|
|
81
|
-
p2c?: number;
|
|
82
|
-
/** ECDH-ES Agreement PartyUInfo. */
|
|
83
|
-
ecdhPartyUInfo?: Uint8Array;
|
|
84
|
-
/** ECDH-ES Agreement PartyVInfo. */
|
|
85
|
-
ecdhPartyVInfo?: Uint8Array;
|
|
86
|
-
/**
|
|
87
|
-
* Content Encryption Key (CEK) to use.
|
|
88
|
-
* If provided, it will be used directly. Otherwise, a CEK will be generated.
|
|
89
|
-
*/
|
|
90
|
-
cek?: Uint8Array;
|
|
91
|
-
/**
|
|
92
|
-
* Initialization Vector for content encryption.
|
|
93
|
-
* If provided, it will be used. Otherwise, one will be generated.
|
|
94
|
-
*/
|
|
95
|
-
contentEncryptionIV?: Uint8Array;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Key lookup function for JWE decryption.
|
|
99
|
-
* @param header The JWE Protected Header.
|
|
100
|
-
* @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
|
|
101
|
-
*/
|
|
102
|
-
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
|
|
103
|
-
/**
|
|
104
|
-
* JWE (JSON Web Encryption) decryption options
|
|
105
|
-
*/
|
|
106
|
-
interface JWEDecryptOptions {
|
|
107
|
-
/** A list of allowed JWE "alg" (Algorithm) Header Parameter values for key management. */
|
|
108
|
-
algorithms?: KeyManagementAlgorithm[];
|
|
109
|
-
/** A list of allowed JWE "enc" (Encryption Algorithm) Header Parameter values for content encryption. */
|
|
110
|
-
encryptionAlgorithms?: ContentEncryptionAlgorithm[];
|
|
111
|
-
/**
|
|
112
|
-
* Critical Header Parameters to be understood and processed.
|
|
113
|
-
* If the JWE contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
|
|
114
|
-
*/
|
|
115
|
-
critical?: string[];
|
|
116
|
-
/** Algorithm to import the unwrapped CEK as (e.g., { name: 'AES-GCM' }). Defaults based on 'enc'. */
|
|
117
|
-
unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
|
|
118
|
-
/** Key usages for the unwrapped CEK. Defaults based on 'enc' (typically ['encrypt', 'decrypt']). */
|
|
119
|
-
keyUsage?: KeyUsage[];
|
|
120
|
-
/** Mark the unwrapped CEK as extractable. Defaults to true. */
|
|
121
|
-
extractable?: boolean;
|
|
122
|
-
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred based on JWE headers. */
|
|
123
|
-
forceUint8Array?: boolean;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Result of a JWE decryption operation.
|
|
127
|
-
*/
|
|
128
|
-
interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
|
|
129
|
-
/** The decrypted payload. */
|
|
130
|
-
payload: T;
|
|
131
|
-
/** The JWE Protected Header. */
|
|
132
|
-
protectedHeader: JWEHeaderParameters;
|
|
133
|
-
/** The Content Encryption Key (CEK) used for decryption, as Uint8Array. */
|
|
134
|
-
cek: Uint8Array;
|
|
135
|
-
/** The Additional Authenticated Data (AAD) used, as Uint8Array. */
|
|
136
|
-
aad: Uint8Array;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Encrypts a payload to produce a JWE Compact Serialization string.
|
|
141
|
-
*
|
|
142
|
-
* @param payload The payload to encrypt. Can be a string, Uint8Array, or a JSON-serializable object.
|
|
143
|
-
* @param key The key encryption key (KEK). Can be a CryptoKey, JWK, or for PBES2, a password string/Uint8Array.
|
|
144
|
-
* @param options JWE encryption options, including `alg` (key management algorithm) and `enc` (content encryption algorithm).
|
|
145
|
-
* @returns A Promise resolving to the JWE Compact Serialization string.
|
|
146
|
-
*/
|
|
147
|
-
declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
|
|
148
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
|
|
149
|
-
declare function encrypt(payload: JWTClaims, key: CryptoKey, options: JWEEncryptOptions & {
|
|
150
|
-
alg: KeyManagementAlgorithm;
|
|
151
|
-
enc: ContentEncryptionAlgorithm;
|
|
152
|
-
}): Promise<string>;
|
|
153
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
|
|
154
|
-
alg: KeyManagementAlgorithm;
|
|
155
|
-
enc: ContentEncryptionAlgorithm;
|
|
156
|
-
}): Promise<string>;
|
|
157
|
-
declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array, options: JWEEncryptOptions & {
|
|
158
|
-
alg: KeyManagementAlgorithm;
|
|
159
|
-
enc: ContentEncryptionAlgorithm;
|
|
160
|
-
}): Promise<string>;
|
|
161
|
-
/**
|
|
162
|
-
* Decrypts a JWE Compact Serialization string.
|
|
163
|
-
*
|
|
164
|
-
* @param jwe The JWE Compact Serialization string.
|
|
165
|
-
* @param key The key decryption key (KEK) or a function to look up the key.
|
|
166
|
-
* @param options JWE decryption options.
|
|
167
|
-
* @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
|
|
168
|
-
* @throws If JWE is invalid, decryption fails, or options are not met.
|
|
169
|
-
*/
|
|
170
|
-
declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
|
|
171
|
-
declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
|
|
172
|
-
forceUint8Array: true;
|
|
173
|
-
}): Promise<JWEDecryptResult<Uint8Array>>;
|
|
174
|
-
|
|
175
|
-
type jwe_JWEDecryptOptions = JWEDecryptOptions;
|
|
176
|
-
type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
|
|
177
|
-
type jwe_JWEEncryptOptions = JWEEncryptOptions;
|
|
178
|
-
type jwe_JWEHeaderParameters = JWEHeaderParameters;
|
|
179
|
-
type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
|
|
180
|
-
type jwe_JWEKeyManagementHeaderParameters = JWEKeyManagementHeaderParameters;
|
|
181
|
-
declare const jwe_decrypt: typeof decrypt;
|
|
182
|
-
declare const jwe_encrypt: typeof encrypt;
|
|
183
|
-
declare namespace jwe {
|
|
184
|
-
export { jwe_decrypt as decrypt, jwe_encrypt as encrypt };
|
|
185
|
-
export type { jwe_JWEDecryptOptions as JWEDecryptOptions, jwe_JWEDecryptResult as JWEDecryptResult, jwe_JWEEncryptOptions as JWEEncryptOptions, jwe_JWEHeaderParameters as JWEHeaderParameters, jwe_JWEKeyLookupFunction as JWEKeyLookupFunction, jwe_JWEKeyManagementHeaderParameters as JWEKeyManagementHeaderParameters };
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export { encrypt as f, decrypt as g, jwe as j };
|
|
189
|
-
export type { JWEHeaderParameters as J, JWEKeyManagementHeaderParameters as a, JWEEncryptOptions as b, JWEKeyLookupFunction as c, JWEDecryptOptions as d, JWEDecryptResult as e };
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x 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, F as JWKPEMAlgorithm, n as JWKSet, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, 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, 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 } from './unjwt.D9da8HQF.js';
|
|
2
|
-
import { J as JoseHeaderParameters } from './unjwt.c10n3uM8.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This is a fork of Jose library's utility functions.
|
|
6
|
-
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/asn1.ts
|
|
7
|
-
* @license MIT https://github.com/panva/jose/blob/69b7960c67e05be55fa2ec31c74b987696c20c60/LICENSE.md
|
|
8
|
-
*/
|
|
9
|
-
/** Key Import Function options. */
|
|
10
|
-
interface KeyImportOptions {
|
|
11
|
-
/**
|
|
12
|
-
* The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
|
|
13
|
-
* private keys, true otherwise.
|
|
14
|
-
*/
|
|
15
|
-
extractable?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Generates a cryptographic key for the specified algorithm.
|
|
20
|
-
*
|
|
21
|
-
* @param alg The JWA algorithm identifier (e.g., "HS256", "RS256", "A128GCM").
|
|
22
|
-
* @param options Configuration options for key generation.
|
|
23
|
-
* @returns A Promise resolving to the generated key (CryptoKey, CryptoKeyPair, or Uint8Array) or its JWK representation.
|
|
24
|
-
*/
|
|
25
|
-
declare function generateKey<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions>(alg: TAlg, options?: TOptions): Promise<GenerateKeyReturn<TAlg, TOptions>>;
|
|
26
|
-
/**
|
|
27
|
-
* Derives a key from a password using PBKDF2 as specified by PBES2 algorithms.
|
|
28
|
-
*
|
|
29
|
-
* @param password The password to derive the key from (string or Uint8Array).
|
|
30
|
-
* @param alg The PBES2 algorithm identifier (e.g., "PBES2-HS256+A128KW").
|
|
31
|
-
* @param options Configuration options including salt and iterations.
|
|
32
|
-
* @returns A Promise resolving to the derived key (CryptoKey) or its JWK_oct representation.
|
|
33
|
-
*/
|
|
34
|
-
declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends DeriveKeyOptions>(password: string | Uint8Array, alg: TAlg, options: TOptions): Promise<DeriveKeyReturn<TOptions>>;
|
|
35
|
-
/**
|
|
36
|
-
* Imports a key from various formats (CryptoKey, JWK, Uint8Array).
|
|
37
|
-
*
|
|
38
|
-
* - If `key` is a CryptoKey, it's returned directly.
|
|
39
|
-
* - If `key` is a Uint8Array, it's returned directly.
|
|
40
|
-
* - If `key` is a JWK_oct (symmetric key with 'k'), the raw key bytes are returned as Uint8Array.
|
|
41
|
-
* - If `key` is any other JWK type (asymmetric), the `alg` parameter is required, and a CryptoKey is returned.
|
|
42
|
-
*
|
|
43
|
-
* @param key The key to import.
|
|
44
|
-
* @param alg The algorithm hint, required when importing asymmetric JWKs.
|
|
45
|
-
* @returns A Promise resolving to the imported key as CryptoKey or Uint8Array.
|
|
46
|
-
*/
|
|
47
|
-
declare function importKey(key: string): Promise<Uint8Array>;
|
|
48
|
-
declare function importKey(key: Uint8Array): Promise<Uint8Array>;
|
|
49
|
-
declare function importKey(key: CryptoKey): Promise<CryptoKey>;
|
|
50
|
-
declare function importKey(key: JWK_oct): Promise<Uint8Array>;
|
|
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
|
-
* Retrieves a JWK (JSON Web Key) from a JWKSet based on a key ID (kid) or
|
|
106
|
-
* properties from a JOSE Header.
|
|
107
|
-
*
|
|
108
|
-
* @param jwkSet The JWKSet to search within.
|
|
109
|
-
* @param kidOrProtectedHeader Either a string representing the 'kid' (Key ID)
|
|
110
|
-
* or an object representing the JOSE Protected Header. If an object is
|
|
111
|
-
* provided, it must contain a 'kid' property. It can optionally contain
|
|
112
|
-
* 'alg' (Algorithm) and 'kty' (Key Type) to further refine the search.
|
|
113
|
-
* @returns The matching JWK from the set.
|
|
114
|
-
* @throws TypeError if `jwkSet` is invalid or `kidOrProtectedHeader` is not a
|
|
115
|
-
* string or a valid header object.
|
|
116
|
-
* @throws Error if no key is found matching the provided criteria, or if the
|
|
117
|
-
* header object is missing the 'kid' property.
|
|
118
|
-
*/
|
|
119
|
-
declare function getJWKFromSet(jwkSet: JWKSet, kidOrProtectedHeader: string | (JoseHeaderParameters & {
|
|
120
|
-
alg?: string;
|
|
121
|
-
kty?: string;
|
|
122
|
-
})): JWK;
|
|
123
|
-
|
|
124
|
-
declare const jwk_CompositeKey: typeof CompositeKey;
|
|
125
|
-
declare const jwk_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
126
|
-
declare const jwk_DeriveKeyOptions: typeof DeriveKeyOptions;
|
|
127
|
-
declare const jwk_DeriveKeyReturn: typeof DeriveKeyReturn;
|
|
128
|
-
declare const jwk_GenerateKeyAlgorithm: typeof GenerateKeyAlgorithm;
|
|
129
|
-
declare const jwk_GenerateKeyOptions: typeof GenerateKeyOptions;
|
|
130
|
-
declare const jwk_GenerateKeyReturn: typeof GenerateKeyReturn;
|
|
131
|
-
declare const jwk_JWK: typeof JWK;
|
|
132
|
-
declare const jwk_JWKAlgorithm: typeof JWKAlgorithm;
|
|
133
|
-
declare const jwk_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
134
|
-
declare const jwk_JWKParameters: typeof JWKParameters;
|
|
135
|
-
declare const jwk_JWKSet: typeof JWKSet;
|
|
136
|
-
declare const jwk_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
137
|
-
declare const jwk_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
138
|
-
declare const jwk_JWK_AES_GCM_KW: typeof JWK_AES_GCM_KW;
|
|
139
|
-
declare const jwk_JWK_AES_KW: typeof JWK_AES_KW;
|
|
140
|
-
declare const jwk_JWK_Asymmetric_Algorithm: typeof JWK_Asymmetric_Algorithm;
|
|
141
|
-
declare const jwk_JWK_EC: typeof JWK_EC;
|
|
142
|
-
declare const jwk_JWK_ECDH_ES: typeof JWK_ECDH_ES;
|
|
143
|
-
declare const jwk_JWK_ECDSA: typeof JWK_ECDSA;
|
|
144
|
-
declare const jwk_JWK_EC_Private: typeof JWK_EC_Private;
|
|
145
|
-
declare const jwk_JWK_EC_Public: typeof JWK_EC_Public;
|
|
146
|
-
declare const jwk_JWK_ED: typeof JWK_ED;
|
|
147
|
-
declare const jwk_JWK_HMAC: typeof JWK_HMAC;
|
|
148
|
-
declare const jwk_JWK_PBES2: typeof JWK_PBES2;
|
|
149
|
-
declare const jwk_JWK_RSA: typeof JWK_RSA;
|
|
150
|
-
declare const jwk_JWK_RSA_ENC: typeof JWK_RSA_ENC;
|
|
151
|
-
declare const jwk_JWK_RSA_PSS: typeof JWK_RSA_PSS;
|
|
152
|
-
declare const jwk_JWK_RSA_Private: typeof JWK_RSA_Private;
|
|
153
|
-
declare const jwk_JWK_RSA_Public: typeof JWK_RSA_Public;
|
|
154
|
-
declare const jwk_JWK_RSA_SIGN: typeof JWK_RSA_SIGN;
|
|
155
|
-
declare const jwk_JWK_Symmetric_Algorithm: typeof JWK_Symmetric_Algorithm;
|
|
156
|
-
declare const jwk_JWK_oct: typeof JWK_oct;
|
|
157
|
-
declare const jwk_KeyManagementAlgorithm: typeof KeyManagementAlgorithm;
|
|
158
|
-
declare const jwk_UnwrapKeyOptions: typeof UnwrapKeyOptions;
|
|
159
|
-
declare const jwk_WrapKeyOptions: typeof WrapKeyOptions;
|
|
160
|
-
declare const jwk_WrapKeyResult: typeof WrapKeyResult;
|
|
161
|
-
declare const jwk_deriveKeyFromPassword: typeof deriveKeyFromPassword;
|
|
162
|
-
declare const jwk_exportJWKToPEM: typeof exportJWKToPEM;
|
|
163
|
-
declare const jwk_exportKey: typeof exportKey;
|
|
164
|
-
declare const jwk_generateKey: typeof generateKey;
|
|
165
|
-
declare const jwk_getJWKFromSet: typeof getJWKFromSet;
|
|
166
|
-
declare const jwk_importJWKFromPEM: typeof importJWKFromPEM;
|
|
167
|
-
declare const jwk_importKey: typeof importKey;
|
|
168
|
-
declare const jwk_unwrapKey: typeof unwrapKey;
|
|
169
|
-
declare const jwk_wrapKey: typeof wrapKey;
|
|
170
|
-
declare namespace jwk {
|
|
171
|
-
export {
|
|
172
|
-
jwk_CompositeKey as CompositeKey,
|
|
173
|
-
jwk_ContentEncryptionAlgorithm as ContentEncryptionAlgorithm,
|
|
174
|
-
jwk_DeriveKeyOptions as DeriveKeyOptions,
|
|
175
|
-
jwk_DeriveKeyReturn as DeriveKeyReturn,
|
|
176
|
-
jwk_GenerateKeyAlgorithm as GenerateKeyAlgorithm,
|
|
177
|
-
jwk_GenerateKeyOptions as GenerateKeyOptions,
|
|
178
|
-
jwk_GenerateKeyReturn as GenerateKeyReturn,
|
|
179
|
-
jwk_JWK as JWK,
|
|
180
|
-
jwk_JWKAlgorithm as JWKAlgorithm,
|
|
181
|
-
jwk_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
182
|
-
jwk_JWKParameters as JWKParameters,
|
|
183
|
-
jwk_JWKSet as JWKSet,
|
|
184
|
-
jwk_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
185
|
-
jwk_JWK_AES_GCM as JWK_AES_GCM,
|
|
186
|
-
jwk_JWK_AES_GCM_KW as JWK_AES_GCM_KW,
|
|
187
|
-
jwk_JWK_AES_KW as JWK_AES_KW,
|
|
188
|
-
jwk_JWK_Asymmetric_Algorithm as JWK_Asymmetric_Algorithm,
|
|
189
|
-
jwk_JWK_EC as JWK_EC,
|
|
190
|
-
jwk_JWK_ECDH_ES as JWK_ECDH_ES,
|
|
191
|
-
jwk_JWK_ECDSA as JWK_ECDSA,
|
|
192
|
-
jwk_JWK_EC_Private as JWK_EC_Private,
|
|
193
|
-
jwk_JWK_EC_Public as JWK_EC_Public,
|
|
194
|
-
jwk_JWK_ED as JWK_ED,
|
|
195
|
-
jwk_JWK_HMAC as JWK_HMAC,
|
|
196
|
-
jwk_JWK_PBES2 as JWK_PBES2,
|
|
197
|
-
jwk_JWK_RSA as JWK_RSA,
|
|
198
|
-
jwk_JWK_RSA_ENC as JWK_RSA_ENC,
|
|
199
|
-
jwk_JWK_RSA_PSS as JWK_RSA_PSS,
|
|
200
|
-
jwk_JWK_RSA_Private as JWK_RSA_Private,
|
|
201
|
-
jwk_JWK_RSA_Public as JWK_RSA_Public,
|
|
202
|
-
jwk_JWK_RSA_SIGN as JWK_RSA_SIGN,
|
|
203
|
-
jwk_JWK_Symmetric_Algorithm as JWK_Symmetric_Algorithm,
|
|
204
|
-
jwk_JWK_oct as JWK_oct,
|
|
205
|
-
jwk_KeyManagementAlgorithm as KeyManagementAlgorithm,
|
|
206
|
-
jwk_UnwrapKeyOptions as UnwrapKeyOptions,
|
|
207
|
-
jwk_WrapKeyOptions as WrapKeyOptions,
|
|
208
|
-
jwk_WrapKeyResult as WrapKeyResult,
|
|
209
|
-
jwk_deriveKeyFromPassword as deriveKeyFromPassword,
|
|
210
|
-
jwk_exportJWKToPEM as exportJWKToPEM,
|
|
211
|
-
jwk_exportKey as exportKey,
|
|
212
|
-
jwk_generateKey as generateKey,
|
|
213
|
-
jwk_getJWKFromSet as getJWKFromSet,
|
|
214
|
-
jwk_importJWKFromPEM as importJWKFromPEM,
|
|
215
|
-
jwk_importKey as importKey,
|
|
216
|
-
jwk_unwrapKey as unwrapKey,
|
|
217
|
-
jwk_wrapKey as wrapKey,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export { importJWKFromPEM as a, exportJWKToPEM as b, getJWKFromSet as c, deriveKeyFromPassword as d, exportKey as e, generateKey as g, importKey as i, jwk as j, unwrapKey as u, wrapKey as w };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
|
|
2
|
-
|
|
3
|
-
declare const textEncoder: TextEncoder;
|
|
4
|
-
declare const textDecoder: TextDecoder;
|
|
5
|
-
declare function base64Encode(data: Uint8Array | string): string;
|
|
6
|
-
declare function base64UrlEncode(data: Uint8Array | string): string;
|
|
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;
|
|
10
|
-
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
11
|
-
declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
12
|
-
/**
|
|
13
|
-
* Concatenates multiple Uint8Arrays
|
|
14
|
-
* @param arrays Arrays to concatenate
|
|
15
|
-
* @returns Concatenated array
|
|
16
|
-
*/
|
|
17
|
-
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
18
|
-
declare function maybeArray<T>(item: T | T[]): T[];
|
|
19
|
-
declare function isJWK(key: any): key is JWK;
|
|
20
|
-
declare function isJWKSet(key: any): key is JWKSet;
|
|
21
|
-
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
22
|
-
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
23
|
-
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
24
|
-
|
|
25
|
-
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
26
|
-
declare const index_base64Decode: typeof base64Decode;
|
|
27
|
-
declare const index_base64Encode: typeof base64Encode;
|
|
28
|
-
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
29
|
-
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
30
|
-
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
31
|
-
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
32
|
-
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
33
|
-
declare const index_isJWK: typeof isJWK;
|
|
34
|
-
declare const index_isJWKSet: typeof isJWKSet;
|
|
35
|
-
declare const index_maybeArray: typeof maybeArray;
|
|
36
|
-
declare const index_randomBytes: typeof randomBytes;
|
|
37
|
-
declare const index_textDecoder: typeof textDecoder;
|
|
38
|
-
declare const index_textEncoder: typeof textEncoder;
|
|
39
|
-
declare namespace index {
|
|
40
|
-
export {
|
|
41
|
-
index_assertCryptoKey as assertCryptoKey,
|
|
42
|
-
index_base64Decode as base64Decode,
|
|
43
|
-
index_base64Encode as base64Encode,
|
|
44
|
-
index_base64UrlDecode as base64UrlDecode,
|
|
45
|
-
index_base64UrlEncode as base64UrlEncode,
|
|
46
|
-
index_concatUint8Arrays as concatUint8Arrays,
|
|
47
|
-
index_isCryptoKey as isCryptoKey,
|
|
48
|
-
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
49
|
-
index_isJWK as isJWK,
|
|
50
|
-
index_isJWKSet as isJWKSet,
|
|
51
|
-
index_maybeArray as maybeArray,
|
|
52
|
-
index_randomBytes as randomBytes,
|
|
53
|
-
index_textDecoder as textDecoder,
|
|
54
|
-
index_textEncoder as textEncoder,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -1,210 +0,0 @@
|
|
|
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", "EC" and "oct" key types are supported.
|
|
182
|
-
*/
|
|
183
|
-
type JWK = JWK_oct | JWK_RSA | JWK_EC;
|
|
184
|
-
/**
|
|
185
|
-
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
186
|
-
*/
|
|
187
|
-
interface JWKSet {
|
|
188
|
-
/** JWK Set "keys" Parameter */
|
|
189
|
-
keys: JWK[];
|
|
190
|
-
[parameter: string]: unknown;
|
|
191
|
-
}
|
|
192
|
-
/** JWK Key Algorithms */
|
|
193
|
-
type JWK_HMAC = "HS256" | "HS384" | "HS512";
|
|
194
|
-
type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
|
|
195
|
-
type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
|
|
196
|
-
type JWK_ECDSA = "ES256" | "ES384" | "ES512";
|
|
197
|
-
type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
|
|
198
|
-
type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
|
|
199
|
-
type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
|
|
200
|
-
type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
|
|
201
|
-
type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
|
|
202
|
-
type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
203
|
-
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
204
|
-
type JWK_ED = "Ed25519" | "EdDSA";
|
|
205
|
-
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
206
|
-
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
207
|
-
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
208
|
-
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_ED;
|
|
209
|
-
|
|
210
|
-
export type { JWK_Symmetric_Algorithm as A, JWK_Asymmetric_Algorithm as B, CompositeKey as C, DeriveKeyOptions as D, JWKAlgorithm as E, JWKPEMAlgorithm as F, 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, JWKSet as n, JWK_HMAC as o, JWK_RSA_SIGN as p, JWK_RSA_PSS as q, JWK_ECDSA as r, JWK_RSA_ENC as s, JWK_AES_KW as t, JWK_AES_GCM_KW as u, JWK_AES_CBC_HMAC as v, JWK_AES_GCM as w, JWK_PBES2 as x, JWK_ECDH_ES as y, JWK_ED as z };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { i as JWK_RSA_Public } from './unjwt.D9da8HQF.js';
|
|
2
|
-
|
|
3
|
-
/** Header Parameters common to JWE and JWS */
|
|
4
|
-
interface JoseHeaderParameters {
|
|
5
|
-
/** "kid" (Key ID) Header Parameter */
|
|
6
|
-
kid?: string;
|
|
7
|
-
/** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
|
|
8
|
-
x5t?: string;
|
|
9
|
-
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
10
|
-
x5c?: string[];
|
|
11
|
-
/** "x5u" (X.509 URL) Header Parameter */
|
|
12
|
-
x5u?: string;
|
|
13
|
-
/** "jku" (JWK Set URL) Header Parameter */
|
|
14
|
-
jku?: string;
|
|
15
|
-
/** "jwk" (JSON Web Key) Header Parameter */
|
|
16
|
-
jwk?: JWK_RSA_Public;
|
|
17
|
-
/** "typ" (Type) Header Parameter */
|
|
18
|
-
typ?: string;
|
|
19
|
-
/** "cty" (Content Type) Header Parameter */
|
|
20
|
-
cty?: string;
|
|
21
|
-
/** "crit" (Critical) Header Parameter */
|
|
22
|
-
crit?: string[];
|
|
23
|
-
/** Any other JWS/JWE Header member. */
|
|
24
|
-
[propName: string]: unknown;
|
|
25
|
-
}
|
|
26
|
-
interface JWTClaims {
|
|
27
|
-
/** "iss" (Issuer) Claim */
|
|
28
|
-
iss?: string;
|
|
29
|
-
/** "sub" (Subject) Claim */
|
|
30
|
-
sub?: string;
|
|
31
|
-
/** "aud" (Audience) Claim */
|
|
32
|
-
aud?: string | string[];
|
|
33
|
-
/** "exp" (Expiration Time) Claim */
|
|
34
|
-
exp?: number;
|
|
35
|
-
/** "nbf" (Not Before) Claim */
|
|
36
|
-
nbf?: number;
|
|
37
|
-
/** "iat" (Issued At) Claim */
|
|
38
|
-
iat?: number;
|
|
39
|
-
/** "jti" (JWT ID) Claim */
|
|
40
|
-
jti?: string;
|
|
41
|
-
/** Any other JWT member. */
|
|
42
|
-
[propName: string]: unknown;
|
|
43
|
-
}
|
|
44
|
-
interface JWT<T = JWTClaims> {
|
|
45
|
-
header: JoseHeaderParameters & {
|
|
46
|
-
/** "alg" (Algorithm) Header Parameter */
|
|
47
|
-
alg: string;
|
|
48
|
-
};
|
|
49
|
-
claims: T;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type { JoseHeaderParameters as J, JWTClaims as a, JWT as b };
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
|
|
3
|
-
|
|
4
|
-
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
|
-
/** JWS Signing Algorithm Identifier. */
|
|
6
|
-
type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWS_SIGN_EXTRA;
|
|
7
|
-
/** Recognized JWS Header Parameters, any other Header Members may also be present. */
|
|
8
|
-
interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
9
|
-
/** JWS "alg" (Algorithm) Header Parameter */
|
|
10
|
-
alg?: JWSAlgorithm;
|
|
11
|
-
/**
|
|
12
|
-
* This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
|
|
13
|
-
* Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
|
|
14
|
-
* If `false`, the payload is used directly without Base64URL encoding.
|
|
15
|
-
* Defaults to `true`.
|
|
16
|
-
*/
|
|
17
|
-
b64?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/** JWS Protected Header */
|
|
20
|
-
interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
21
|
-
alg: JWSAlgorithm;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* JWS (JSON Web Signature) options for signing
|
|
25
|
-
*/
|
|
26
|
-
interface JWSSignOptions {
|
|
27
|
-
/** The JWS Algorithm to use. Must be provided. */
|
|
28
|
-
alg?: JWSAlgorithm;
|
|
29
|
-
/**
|
|
30
|
-
* Additional protected header parameters. `alg` is automatically included.
|
|
31
|
-
* `typ` defaults to "JWT" if not provided.
|
|
32
|
-
*/
|
|
33
|
-
protectedHeader?: JWSHeaderParameters;
|
|
34
|
-
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
35
|
-
currentDate?: Date;
|
|
36
|
-
/**
|
|
37
|
-
* Time at which the JWS should expire, if no `exp` was already provided.
|
|
38
|
-
*/
|
|
39
|
-
expiresIn?: number;
|
|
40
|
-
}
|
|
41
|
-
/** Result of JWS verification */
|
|
42
|
-
interface JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
|
|
43
|
-
/** The decoded and verified payload. */
|
|
44
|
-
payload: T;
|
|
45
|
-
/** The JWS Protected Header. */
|
|
46
|
-
protectedHeader: JWSProtectedHeader;
|
|
47
|
-
}
|
|
48
|
-
/** Options for JWS verification */
|
|
49
|
-
interface JWSVerifyOptions {
|
|
50
|
-
/** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
|
|
51
|
-
algorithms?: JWSAlgorithm[];
|
|
52
|
-
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
|
|
53
|
-
forceUint8Array?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Expected JWT "aud" (Audience) Claim value(s).
|
|
56
|
-
*
|
|
57
|
-
* This option makes the JWT "aud" (Audience) Claim presence required.
|
|
58
|
-
*/
|
|
59
|
-
audience?: string | string[];
|
|
60
|
-
/**
|
|
61
|
-
* Clock skew tolerance (in seconds) for validating JWT claims.
|
|
62
|
-
*
|
|
63
|
-
* Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
|
|
64
|
-
* validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
|
|
65
|
-
*/
|
|
66
|
-
clockTolerance?: number;
|
|
67
|
-
/**
|
|
68
|
-
* Expected JWT "iss" (Issuer) Claim value(s).
|
|
69
|
-
*
|
|
70
|
-
* This option makes the JWT "iss" (Issuer) Claim presence required.
|
|
71
|
-
*/
|
|
72
|
-
issuer?: string | string[];
|
|
73
|
-
/**
|
|
74
|
-
* Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
|
|
75
|
-
*
|
|
76
|
-
* This option makes the JWT "iat" (Issued At) Claim presence required.
|
|
77
|
-
*/
|
|
78
|
-
maxTokenAge?: number;
|
|
79
|
-
/**
|
|
80
|
-
* Expected JWT "sub" (Subject) Claim value.
|
|
81
|
-
*
|
|
82
|
-
* This option makes the JWT "sub" (Subject) Claim presence required.
|
|
83
|
-
*/
|
|
84
|
-
subject?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Expected JWT "typ" (Type) Header Parameter value.
|
|
87
|
-
*
|
|
88
|
-
* This option makes the JWT "typ" (Type) Header Parameter presence required.
|
|
89
|
-
*/
|
|
90
|
-
typ?: string;
|
|
91
|
-
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
92
|
-
currentDate?: Date;
|
|
93
|
-
/** List of critical header parameters that must be understood and processed. */
|
|
94
|
-
requiredHeaders?: string[];
|
|
95
|
-
/**
|
|
96
|
-
* Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
|
|
97
|
-
* the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
|
|
98
|
-
* {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
|
|
99
|
-
* the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
|
|
100
|
-
* the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
|
|
101
|
-
* present.
|
|
102
|
-
*/
|
|
103
|
-
requiredClaims?: string[];
|
|
104
|
-
/**
|
|
105
|
-
* List of critical header parameters that must be understood and processed.
|
|
106
|
-
* @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
|
|
107
|
-
*/
|
|
108
|
-
critical?: string[];
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Key lookup function for JWS verification.
|
|
112
|
-
* @param header The JWS Protected Header.
|
|
113
|
-
* @param token The JWS token.
|
|
114
|
-
* @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
|
|
115
|
-
*/
|
|
116
|
-
type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array | Promise<CryptoKey | JWK | JWKSet | Uint8Array>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Creates a JWS (JSON Web Signature) in Compact Serialization format.
|
|
120
|
-
*
|
|
121
|
-
* @param payload The payload to sign. Can be a string, Uint8Array, or an object (which will be JSON stringified).
|
|
122
|
-
* @param key The signing key (CryptoKey, JWK, or raw symmetric key as Uint8Array).
|
|
123
|
-
* @param options Signing options, including the algorithm (`alg`) and protected header parameters.
|
|
124
|
-
* @returns A Promise resolving to the JWS Compact Serialization string.
|
|
125
|
-
*/
|
|
126
|
-
declare function sign(payload: JWTClaims, key: JWK, options?: JWSSignOptions): Promise<string>;
|
|
127
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
|
|
128
|
-
declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
|
|
129
|
-
alg: JWSAlgorithm;
|
|
130
|
-
}): Promise<string>;
|
|
131
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
|
|
132
|
-
alg: JWSAlgorithm;
|
|
133
|
-
}): Promise<string>;
|
|
134
|
-
declare function sign(payload: JWTClaims, key: Uint8Array, options: JWSSignOptions & {
|
|
135
|
-
alg: JWSAlgorithm;
|
|
136
|
-
}): Promise<string>;
|
|
137
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: Uint8Array, options: JWSSignOptions & {
|
|
138
|
-
alg: JWSAlgorithm;
|
|
139
|
-
}): Promise<string>;
|
|
140
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
|
|
141
|
-
alg: JWSAlgorithm;
|
|
142
|
-
}): Promise<string>;
|
|
143
|
-
/**
|
|
144
|
-
* Verifies a JWS (JSON Web Signature) in Compact Serialization format.
|
|
145
|
-
*
|
|
146
|
-
* @param jws The JWS Compact Serialization string.
|
|
147
|
-
* @param key The verification key (CryptoKey, JWK, JWKSet, raw symmetric key as Uint8Array, or a function resolving the key or set).
|
|
148
|
-
* @param options Verification options, such as allowed algorithms.
|
|
149
|
-
* @returns A Promise resolving to an object containing the verified payload and protected header.
|
|
150
|
-
* @throws If the JWS is invalid, signature verification fails, or options are not met.
|
|
151
|
-
*/
|
|
152
|
-
declare function verify<T extends JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
153
|
-
declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
|
|
154
|
-
forceUint8Array: true;
|
|
155
|
-
}): Promise<JWSVerifyResult<Uint8Array>>;
|
|
156
|
-
|
|
157
|
-
type jws_JWSAlgorithm = JWSAlgorithm;
|
|
158
|
-
type jws_JWSHeaderParameters = JWSHeaderParameters;
|
|
159
|
-
type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
|
|
160
|
-
type jws_JWSProtectedHeader = JWSProtectedHeader;
|
|
161
|
-
type jws_JWSSignOptions = JWSSignOptions;
|
|
162
|
-
type jws_JWSVerifyOptions = JWSVerifyOptions;
|
|
163
|
-
type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
|
|
164
|
-
declare const jws_sign: typeof sign;
|
|
165
|
-
declare const jws_verify: typeof verify;
|
|
166
|
-
declare namespace jws {
|
|
167
|
-
export { jws_sign as sign, jws_verify as verify };
|
|
168
|
-
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSKeyLookupFunction as JWSKeyLookupFunction, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export { jws as j, sign as s, verify as v };
|
|
172
|
-
export type { JWSAlgorithm as J, JWSHeaderParameters as a, JWSProtectedHeader as b, JWSSignOptions as c, JWSVerifyResult as d, JWSVerifyOptions as e, JWSKeyLookupFunction as f };
|
package/dist/utils.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import './shared/unjwt.D9da8HQF.js';
|
|
2
|
-
export { j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.D4DUiNeM.js';
|