unjwt 0.3.0 → 0.5.0
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/LICENSE +21 -21
- package/README.md +518 -48
- package/dist/index.d.mts +6 -79
- package/dist/index.d.ts +6 -79
- package/dist/index.mjs +5 -141
- package/dist/jwe.d.mts +3 -0
- package/dist/jwe.d.ts +3 -0
- package/dist/jwe.mjs +4 -0
- package/dist/jwk.d.mts +2 -0
- package/dist/jwk.d.ts +2 -0
- package/dist/jwk.mjs +2 -0
- package/dist/jws.d.mts +3 -0
- package/dist/jws.d.ts +3 -0
- package/dist/jws.mjs +4 -0
- package/dist/shared/unjwt.B4e_rwol.mjs +453 -0
- package/dist/shared/unjwt.B9uGngq-.d.mts +154 -0
- package/dist/shared/unjwt.BKG_8Y9G.d.ts +189 -0
- package/dist/shared/unjwt.BOEZHxi_.d.ts +154 -0
- package/dist/shared/unjwt.Bzcov22m.mjs +167 -0
- package/dist/shared/unjwt.C0bBN0AC.d.mts +200 -0
- package/dist/shared/unjwt.C0bBN0AC.d.ts +200 -0
- package/dist/shared/unjwt.CJ_ohCFC.d.mts +46 -0
- package/dist/shared/unjwt.CjHZv3F3.mjs +57 -0
- package/dist/shared/unjwt.D90BbcE1.d.mts +52 -0
- package/dist/shared/unjwt.DKq5VF7t.mjs +1186 -0
- package/dist/shared/unjwt.DYFIh1YE.d.mts +100 -0
- package/dist/shared/unjwt.DoVzOnty.d.ts +52 -0
- package/dist/shared/unjwt.Dz5Oe9BG.d.mts +189 -0
- package/dist/shared/unjwt.mc4AEAT7.d.ts +46 -0
- package/dist/shared/unjwt.ppm5Y0k7.d.ts +100 -0
- package/dist/shared/unjwt.sux3_Z19.mjs +101 -0
- package/dist/utils.d.mts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.mjs +1 -0
- package/package.json +44 -84
- package/dist/crypto/node.cjs +0 -19
- package/dist/crypto/node.d.cts +0 -5
- package/dist/crypto/node.d.mts +0 -5
- package/dist/crypto/node.d.ts +0 -5
- package/dist/crypto/node.mjs +0 -11
- package/dist/crypto/web.cjs +0 -14
- package/dist/crypto/web.d.cts +0 -5
- package/dist/crypto/web.d.mts +0 -5
- package/dist/crypto/web.d.ts +0 -5
- package/dist/crypto/web.mjs +0 -10
- package/dist/index.cjs +0 -146
- package/dist/index.d.cts +0 -79
|
@@ -0,0 +1,200 @@
|
|
|
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_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
197
|
+
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
198
|
+
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
199
|
+
|
|
200
|
+
export type { JWKAlgorithm as A, CompositeKey as C, DeriveKeyOptions as D, 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_Symmetric_Algorithm as y, JWK_Asymmetric_Algorithm as z };
|
|
@@ -0,0 +1,200 @@
|
|
|
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_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
197
|
+
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC;
|
|
198
|
+
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
199
|
+
|
|
200
|
+
export type { JWKAlgorithm as A, CompositeKey as C, DeriveKeyOptions as D, 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_Symmetric_Algorithm as y, JWK_Asymmetric_Algorithm as z };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { m as JWK } from './unjwt.C0bBN0AC.mjs';
|
|
2
|
+
|
|
3
|
+
declare const textEncoder: TextEncoder;
|
|
4
|
+
declare const textDecoder: TextDecoder;
|
|
5
|
+
declare function base64UrlEncode(data: Uint8Array | string): string;
|
|
6
|
+
declare function base64UrlDecode(): string;
|
|
7
|
+
declare function base64UrlDecode(str?: string | undefined): string;
|
|
8
|
+
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
|
|
9
|
+
declare function randomBytes(length: Readonly<number>): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Concatenates multiple Uint8Arrays
|
|
12
|
+
* @param arrays Arrays to concatenate
|
|
13
|
+
* @returns Concatenated array
|
|
14
|
+
*/
|
|
15
|
+
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
|
|
16
|
+
declare function isJWK(key: any): key is JWK;
|
|
17
|
+
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
18
|
+
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
19
|
+
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
20
|
+
|
|
21
|
+
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
22
|
+
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
23
|
+
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
24
|
+
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
25
|
+
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
26
|
+
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
27
|
+
declare const index_isJWK: typeof isJWK;
|
|
28
|
+
declare const index_randomBytes: typeof randomBytes;
|
|
29
|
+
declare const index_textDecoder: typeof textDecoder;
|
|
30
|
+
declare const index_textEncoder: typeof textEncoder;
|
|
31
|
+
declare namespace index {
|
|
32
|
+
export {
|
|
33
|
+
index_assertCryptoKey as assertCryptoKey,
|
|
34
|
+
index_base64UrlDecode as base64UrlDecode,
|
|
35
|
+
index_base64UrlEncode as base64UrlEncode,
|
|
36
|
+
index_concatUint8Arrays as concatUint8Arrays,
|
|
37
|
+
index_isCryptoKey as isCryptoKey,
|
|
38
|
+
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
39
|
+
index_isJWK as isJWK,
|
|
40
|
+
index_randomBytes as randomBytes,
|
|
41
|
+
index_textDecoder as textDecoder,
|
|
42
|
+
index_textEncoder as textEncoder,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { textDecoder as a, base64UrlEncode as b, base64UrlDecode as c, concatUint8Arrays as d, isJWK as e, assertCryptoKey as f, isCryptoKey as g, isCryptoKeyPair as h, index as i, randomBytes as r, textEncoder as t };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
2
|
+
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
3
|
+
function base64UrlEncode(data) {
|
|
4
|
+
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
5
|
+
return btoa(String.fromCodePoint(...encodedData)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
6
|
+
}
|
|
7
|
+
function base64UrlDecode(str, toString) {
|
|
8
|
+
const decodeToString = toString !== false;
|
|
9
|
+
if (!str) {
|
|
10
|
+
return decodeToString ? "" : new Uint8Array(0);
|
|
11
|
+
}
|
|
12
|
+
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
13
|
+
while (str.length % 4) str += "=";
|
|
14
|
+
const data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
15
|
+
return decodeToString ? textDecoder.decode(data) : data;
|
|
16
|
+
}
|
|
17
|
+
function randomBytes(length) {
|
|
18
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
19
|
+
}
|
|
20
|
+
function concatUint8Arrays(...arrays) {
|
|
21
|
+
const totalLength = arrays.reduce((length, arr) => length + arr.length, 0);
|
|
22
|
+
const result = new Uint8Array(totalLength);
|
|
23
|
+
let offset = 0;
|
|
24
|
+
for (const arr of arrays) {
|
|
25
|
+
result.set(arr, offset);
|
|
26
|
+
offset += arr.length;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
function isJWK(key) {
|
|
31
|
+
return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
|
|
32
|
+
}
|
|
33
|
+
function assertCryptoKey(key) {
|
|
34
|
+
if (!isCryptoKey(key)) {
|
|
35
|
+
throw new Error("CryptoKey instance expected");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isCryptoKey(key) {
|
|
39
|
+
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
40
|
+
}
|
|
41
|
+
const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
|
|
42
|
+
|
|
43
|
+
const index = {
|
|
44
|
+
__proto__: null,
|
|
45
|
+
assertCryptoKey: assertCryptoKey,
|
|
46
|
+
base64UrlDecode: base64UrlDecode,
|
|
47
|
+
base64UrlEncode: base64UrlEncode,
|
|
48
|
+
concatUint8Arrays: concatUint8Arrays,
|
|
49
|
+
isCryptoKey: isCryptoKey,
|
|
50
|
+
isCryptoKeyPair: isCryptoKeyPair,
|
|
51
|
+
isJWK: isJWK,
|
|
52
|
+
randomBytes: randomBytes,
|
|
53
|
+
textDecoder: textDecoder,
|
|
54
|
+
textEncoder: textEncoder
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g, isCryptoKeyPair as h, index as i, randomBytes as r, textEncoder as t };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { i as JWK_RSA_Public } from './unjwt.C0bBN0AC.mjs';
|
|
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 };
|