unjwt 0.2.1 → 0.4.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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023-PRESENT Johann Schopplich
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sandro Circi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,70 +1,370 @@
1
1
  # unjwt
2
2
 
3
- > Easy creation and verification of JSON Web Tokens (JWT).
3
+ <!-- automd:badges color=yellow -->
4
4
 
5
- You may just use [Jose](https://github.com/panva/jose) or one of the other libraries out there. But I wanted to take my shot at creating a JWT library that is easy to use and has zero dependencies.
5
+ [![npm version](https://img.shields.io/npm/v/unjwt?color=yellow)](https://npmjs.com/package/unjwt)
6
+ [![npm downloads](https://img.shields.io/npm/dm/unjwt?color=yellow)](https://npm.chart.dev/unjwt)
6
7
 
7
- ## Features
8
+ <!-- /automd -->
8
9
 
9
- - 📦 Works in Node.js, browser and workers
10
- - 💨 Zero dependencies
10
+ Low-level JWT utilities using the Web Crypto API. Currently supports:
11
11
 
12
- ## Installation
12
+ - JWE (JSON Web Encryption) with password-based key derivation (PBES2).
13
+ - JWS (JSON Web Signature) with symmetric keys (HMAC).
14
+ - JWK (JSON Web Key) generation, import, and export for symmetric keys (`oct`).
13
15
 
14
- Run the following command to add `unjwt` to your project.
16
+ ## Usage
17
+
18
+ Install the package:
19
+
20
+ ```sh
21
+ # ✨ Auto-detect (supports npm, yarn, pnpm, deno and bun)
22
+ npx nypm install unjwt
23
+ ```
15
24
 
16
- ```bash
17
- # pnpm
18
- pnpm add unjwt
25
+ Import:
19
26
 
20
- # npm
21
- npm install unjwt
27
+ **ESM** (Node.js, Bun, Deno)
22
28
 
23
- # yarn
24
- yarn add unjwt
29
+ ```js
30
+ import { jws, jwe, jwk } from "unjwt";
31
+ import { seal, unseal } from "unjwt/jwe";
32
+ import { sign, verify } from "unjwt/jws";
33
+ import { generateKey, exportKey, importKey } from "unjwt/jwk";
25
34
  ```
26
35
 
27
- ## Usage
36
+ **CDN** (Deno, Bun and Browsers)
37
+
38
+ ```js
39
+ import { jws, jwe, jwk } from "https://esm.sh/unjwt";
40
+ import { seal, unseal } from "https://esm.sh/unjwt/jwe";
41
+ import { sign, verify } from "https://esm.sh/unjwt/jws";
42
+ import { generateKey, exportKey, importKey } from "https://esm.sh/unjwt/jwk";
43
+ ```
44
+
45
+ ### JWE (JSON Web Encryption)
46
+
47
+ This library provides functions to encrypt (seal) and decrypt (unseal) data according to the JWE specification using password-based encryption.
48
+
49
+ #### `seal(data, password, options?)`
50
+
51
+ Encrypts the provided data using a password.
52
+
53
+ - `data`: The data to encrypt (string or `Uint8Array`).
54
+ - `password`: The password to use for encryption (string or `Uint8Array`).
55
+ - `options` (optional):
56
+ - `iterations`: Number of PBKDF2 iterations (default: `2048`).
57
+ - `saltSize`: Size of the random salt in bytes (default: `16`).
58
+ - `protectedHeader`: An object containing JWE header parameters to include.
59
+ - `alg`: Key Wrapping Algorithm (default: `PBES2-HS256+A128KW`). Supported: `PBES2-HS256+A128KW`, `PBES2-HS384+A192KW`, `PBES2-HS512+A256KW`.
60
+ - `enc`: Content Encryption Algorithm (default: `A256GCM`). Supported: `A128GCM`, `A192GCM`, `A256GCM`, `A128CBC-HS256`, `A192CBC-HS384`, `A256CBC-HS512`.
61
+ - Other standard JWE or custom header parameters can be added here.
62
+
63
+ Returns a Promise resolving to the JWE token string in Compact Serialization format.
64
+
65
+ **Example:**
66
+
67
+ ```ts
68
+ import { seal } from "unjwt/jwe";
69
+
70
+ const plaintext = "My secret data";
71
+ const password = "strongpassword";
72
+
73
+ const token = await seal(plaintext, password, {
74
+ protectedHeader: {
75
+ alg: "PBES2-HS512+A256KW",
76
+ enc: "A256GCM",
77
+ },
78
+ });
79
+
80
+ console.log(token);
81
+ // eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIiwicDJzIjoi...
82
+ ```
83
+
84
+ #### `unseal(token, password, options?)`
85
+
86
+ Decrypts a JWE token using a password.
87
+
88
+ - `token`: The JWE token string (Compact Serialization).
89
+ - `password`: The password used for encryption (string or `Uint8Array`).
90
+ - `options` (optional):
91
+ - `textOutput`: If `false`, returns the decrypted data as a `Uint8Array` instead of a string (default: `true`).
92
+
93
+ Returns a Promise resolving to the decrypted data (string or `Uint8Array`).
94
+
95
+ **Example:**
28
96
 
29
97
  ```ts
30
- import { decodeJWT, signJWT, verifyJWT } from 'unjwt'
98
+ import { unseal } from "unjwt/jwe";
99
+
100
+ const token =
101
+ "eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIiwicDJzIjoi..."; // From seal example
102
+ const password = "strongpassword";
103
+
104
+ // Decrypt as string (default)
105
+ const decryptedString = await unseal(token, password);
106
+ console.log(decryptedString); // "My secret data"
107
+
108
+ // Decrypt as Uint8Array
109
+ const decryptedBytes = await unseal(token, password, { textOutput: false });
110
+ console.log(decryptedBytes); // Uint8Array [ 77, 121, 32, ... ]
111
+ ```
31
112
 
32
- interface JWTUserClaims {
33
- email: string
34
- }
113
+ ### JWS (JSON Web Signature)
35
114
 
36
- const secret = 'secret'
37
- const issuer = 'https://domain.com'
115
+ This library provides functions to sign (sign) and verify (verify) data according to the JWS specification using HMAC with symmetric keys.
38
116
 
39
- // Sign a JWT
40
- const accessToken = await signJWT<JWTUserClaims>({
41
- payload: {
42
- email: 'user@domain.com'
117
+ #### `sign(data, secret, options?)`
118
+
119
+ Signs the provided payload using a symmetric secret.
120
+
121
+ - `payload`: The data to sign (string or `Uint8Array`).
122
+ - `secret`: The symmetric secret key to use for signing. Can be:
123
+ - A `string`.
124
+ - A `Uint8Array` containing the raw key bytes.
125
+ - A symmetric JSON Web Key (`JWK`) object (with `kty: "oct"`).
126
+ - `options` (optional):
127
+ - `protectedHeader`: An object containing JWS header parameters to include.
128
+ - alg: Signing Algorithm (default: `HS256`). Supported: `HS256`, `HS384`, `HS512`.
129
+ - Other standard JWS or custom header parameters can be added here.
130
+
131
+ Returns a Promise resolving to the JWS token string in Compact Serialization format.
132
+
133
+ **Example (using string secret):**
134
+
135
+ ```ts
136
+ import { sign } from "unjwt/jws";
137
+
138
+ const payload = JSON.stringify({ message: "My important data" });
139
+ const secret = "supersecretkey";
140
+
141
+ const token = await sign(payload, secret, {
142
+ protectedHeader: {
143
+ alg: "HS512",
43
144
  },
44
- secret,
45
- issuer,
46
- audience: issuer,
47
- })
48
-
49
- // Verify a JWT
50
- try {
51
- const verifiedAccessToken = await verifyJWT({
52
- token: accessToken,
53
- secret,
54
- issuer,
55
- audience: issuer
56
- })
57
- }
58
- catch (error) {
59
- // Handle error
60
- console.error(error)
61
- }
62
-
63
- // Decode a JWT – does not verify the signature
64
- const decodedAccessToken = await decodeJWT<JWTUserClaims>(accessToken)
65
- console.log(decodedAccessToken.email)
145
+ });
146
+
147
+ console.log(token);
148
+ // eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...
66
149
  ```
67
150
 
151
+ **Example (using JWK secret):**
152
+
153
+ ```ts
154
+ import { sign } from "unjwt/jws";
155
+ import { generateKey } from "unjwt/jwk";
156
+
157
+ const payload = JSON.stringify({ message: "Data signed with JWK" });
158
+ // Generate a JWK suitable for HS256
159
+ const secretJwk = await generateKey("oct", 256, { alg: "HS256" });
160
+
161
+ const token = await sign(payload, secretJwk); // alg defaults to HS256
162
+
163
+ console.log(token);
164
+ // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
165
+ ```
166
+
167
+ #### `verify(token, secret, options?)`
168
+
169
+ Verifies a JWS token using a symmetric secret.
170
+
171
+ - `token`: The JWS token string (Compact Serialization).
172
+ - `secret`: The symmetric secret key used for signing. Can be:
173
+ - A `string`.
174
+ - A `Uint8Array` containing the raw key bytes.
175
+ - A symmetric JSON Web Key (`JWK`) object (with `kty: "oct"`).
176
+ - `options` (optional):
177
+ - `textOutput`: If `false`, returns the verified payload as a `Uint8Array` instead of a string (default: `true`).
178
+
179
+ Returns a Promise resolving to the verified payload (string or `Uint8Array`). Throws an error if the signature is invalid or the token is malformed.
180
+
181
+ **Example (using string secret):**
182
+
183
+ ```ts
184
+ import { verify } from "unjwt/jws";
185
+
186
+ const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9..."; // From sign example
187
+ const secret = "supersecretkey";
188
+
189
+ // Verify as string (default)
190
+ const verifiedString = await verify(token, secret);
191
+ console.log(verifiedString); // {"message":"My important data"}
192
+
193
+ // Verify as Uint8Array
194
+ const verifiedBytes = await verify(token, secret, { textOutput: false });
195
+ console.log(verifiedBytes); // Uint8Array [ 123, 34, ... ]
196
+ ```
197
+
198
+ **Example (using JWK secret):**
199
+
200
+ ```ts
201
+ import { verify } from "unjwt/jws";
202
+ import { generateKey } from "unjwt/jwk";
203
+
204
+ const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."; // From sign example
205
+ const secretJwk = { kty: "oct", k: "...", alg: "HS256" }; // Load or use the generated JWK
206
+
207
+ const verifiedPayload = await verify(token, secretJwk);
208
+ console.log(verifiedPayload); // {"message":"Data signed with JWK"}
209
+ ```
210
+
211
+ ### JWK (JSON Web Key)
212
+
213
+ This library provides functions to generate (`generateKey`), export (`exportKey`), and import (`importKey`) symmetric keys (`kty: "oct"`) using the Web Crypto API.
214
+
215
+ #### `generateKey(type, length, jwk?)`
216
+
217
+ Generates a new key as a JWK object.
218
+
219
+ - `type`: The key type. Currently only supports `"oct"` (symmetric).
220
+ - `length`(for `"oct"`): Key length in bits (e.g., `128`, `192`, `256`, `512`). Choose a length appropriate for the intended algorithm (e.g., >= 256 for HS256, >= 384 for HS384, >= 512 for HS512).
221
+ - `jwk` (optional, for `"oct"`): Any valid JWK param such as a JWA algorithm identifier (e.g., `HS256`, `A128KW`) to include in the generated JWK.
222
+
223
+ Returns a Promise resolving to the generated key as a JWK object (`{ kty: "oct", k: "...", ... }`).
224
+
225
+ **Example:**
226
+
227
+ ```ts
228
+ import { generateKey } from "unjwt/jwk";
229
+
230
+ // Generate a 512-bit key suitable for HS512
231
+ const jwk = await generateKey("oct", 512, { alg: "HS512" });
232
+
233
+ console.log(jwk);
234
+ // {
235
+ // kty: 'oct',
236
+ // k: '...', // base64url encoded key material
237
+ // ext: true,
238
+ // alg: 'HS512'
239
+ // }
240
+ ```
241
+
242
+ #### `exportKey(key)`
243
+
244
+ Exports a symmetric `CryptoKey` to JWK format.
245
+
246
+ - `key`: The `CryptoKey` to export. It must be `extractable` and currently only of type `"secret"`.
247
+
248
+ Returns a Promise resolving to the exported key as a JWK object. The JWK will include `kty`, `k`, `key_ops`, `ext`, and potentially `alg` based on the `CryptoKey`'s algorithm.
249
+
250
+ **Example:**
251
+
252
+ ```ts
253
+ import { importKey, exportKey } from "unjwt/jwk";
254
+
255
+ // First, import or generate a CryptoKey
256
+ const rawKeyBytes = new TextEncoder().encode(
257
+ "a-very-secure-secret-key-for-hmac",
258
+ );
259
+ const cryptoKey = await importKey(
260
+ rawKeyBytes,
261
+ { name: "HMAC", hash: "SHA-256" },
262
+ true, // Must be extractable to export
263
+ ["sign", "verify"],
264
+ );
265
+
266
+ // Now export the CryptoKey to JWK
267
+ const jwk = await exportKey(cryptoKey);
268
+
269
+ console.log(jwk);
270
+ // {
271
+ // kty: 'oct',
272
+ // k: 'YS12ZXJ5LXNlY3VyZS1zZWNyZXQta2V5LWZvci1obWFj',
273
+ // alg: 'HS256',
274
+ // key_ops: [ 'sign', 'verify' ],
275
+ // ext: true
276
+ // }
277
+ ```
278
+
279
+ #### `importKey(key, algorithm, extractable, keyUsages)`
280
+
281
+ Imports a symmetric key from various formats into a `CryptoKey` object.
282
+
283
+ - `key`: The key material to import. Can be:
284
+ - A symmetric JSON Web Key (`JWK`) object (with `kty: "oct"` and a `k` property).
285
+ - A `string` representing the raw secret.
286
+ - A `Uint8Array` containing the raw key bytes.
287
+ - `algorithm`: The Web Crypto `AlgorithmIdentifier` object specifying the algorithm the key will be used for (e.g., `{ name: "HMAC", hash: "SHA-256" }`, `{ name: "AES-GCM", length: 256 }`).
288
+ - `extractable`: A boolean indicating whether the generated `CryptoKey` can be exported later (using `exportKey` or `crypto.subtle.exportKey`).
289
+ - `keyUsages`: An array of strings indicating the allowed operations for the key (e.g., `["sign", "verify"]`, `["encrypt", "decrypt"]`, `["wrapKey", "unwrapKey"]`).
290
+
291
+ Returns a Promise resolving to the imported `CryptoKey` object.
292
+
293
+ **Example (importing a JWK):**
294
+
295
+ ```ts
296
+ import { importKey } from "unjwt/jwk";
297
+
298
+ const jwk = {
299
+ kty: "oct",
300
+ k: "AyMee--70a4a4xED9qS4sN0KxBas6KTMx7_Q9Gf6nvM", // Example base64url key
301
+ alg: "HS256", // Optional hint, but algorithm param below is definitive
302
+ };
303
+
304
+ const cryptoKey = await importKey(
305
+ jwk,
306
+ { name: "HMAC", hash: "SHA-256" }, // Algorithm for the CryptoKey
307
+ false, // Make this key non-extractable
308
+ ["verify"], // Allow only verification usage
309
+ );
310
+
311
+ console.log(cryptoKey);
312
+ // CryptoKey { type: 'secret', extractable: false, algorithm: { ... }, usages: [ 'verify' ] }
313
+ ```
314
+
315
+ **Example (importing a raw string):**
316
+
317
+ ```ts
318
+ import { importKey } from "unjwt/jwk";
319
+
320
+ const rawSecret = "my-raw-password-string";
321
+
322
+ const cryptoKey = await importKey(
323
+ rawSecret,
324
+ { name: "HMAC", hash: "SHA-384" },
325
+ true,
326
+ ["sign"],
327
+ );
328
+
329
+ console.log(cryptoKey);
330
+ // CryptoKey { type: 'secret', extractable: true, algorithm: { ... }, usages: [ 'sign' ] }
331
+ ```
332
+
333
+ ## Development
334
+
335
+ <details>
336
+
337
+ <summary>local development</summary>
338
+
339
+ - Clone this repository
340
+ - Install latest LTS version of [Node.js](https://nodejs.org/en/)
341
+ - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
342
+ - Install dependencies using `pnpm install`
343
+ - Run interactive tests using `pnpm dev`
344
+
345
+ </details>
346
+
347
+ ## Credits
348
+
349
+ Originally developed by [Johann Schopplich](https://github.com/johannschopplich/unjwt).
350
+
68
351
  ## License
69
352
 
70
- [MIT](./LICENSE) License © 2023-PRESENT [Johann Schopplich](https://github.com/johannschopplich)
353
+ <!-- automd:contributors license=MIT -->
354
+
355
+ Published under the [MIT](https://github.com/sandros94/unjwt/blob/main/LICENSE) license.
356
+ Made by [community](https://github.com/sandros94/unjwt/graphs/contributors) 💛
357
+ <br><br>
358
+ <a href="https://github.com/sandros94/unjwt/graphs/contributors">
359
+ <img src="https://contrib.rocks/image?repo=sandros94/unjwt" />
360
+ </a>
361
+
362
+ <!-- /automd -->
363
+
364
+ <!-- automd:with-automd -->
365
+
366
+ ---
367
+
368
+ _🤖 auto updated with [automd](https://automd.unjs.io)_
369
+
370
+ <!-- /automd -->
package/dist/index.d.mts CHANGED
@@ -1,79 +1,5 @@
1
- /** Recognized JWT Claims Set members */
2
- interface JWTRegisteredClaims {
3
- /**
4
- * JWT Issuer
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
7
- */
8
- iss?: string;
9
- /**
10
- * JWT Subject
11
- *
12
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
13
- */
14
- sub?: string;
15
- /**
16
- * JWT Audience
17
- *
18
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
19
- */
20
- aud?: string | string[];
21
- /**
22
- * JWT ID
23
- *
24
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
25
- */
26
- jti?: string;
27
- /**
28
- * JWT Not Before
29
- *
30
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
31
- */
32
- nbf?: number;
33
- /**
34
- * JWT Expiration Time
35
- *
36
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
37
- */
38
- exp?: number;
39
- /**
40
- * JWT Issued At
41
- *
42
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
43
- */
44
- iat?: number;
45
- }
46
-
47
- declare function decodeJWT<T extends Record<string, any> = Record<string, any>>(token: string): (JWTRegisteredClaims & T) | undefined;
48
- declare function _decodeJWT<T extends Record<string, any> = Record<string, any>>(token: string): JWTRegisteredClaims & T;
49
-
50
- declare function signJWT<T extends Record<string, any> = Record<string, any>>(options: {
51
- payload?: T;
52
- secret: string;
53
- issuer: string;
54
- audience: string;
55
- /**
56
- * Expiration time in days
57
- * @default 30
58
- */
59
- expires?: number;
60
- /** @default 'HMAC' */
61
- signatureMethod?: string;
62
- /** @default 'SHA-256' */
63
- hashMethod?: string;
64
- }): Promise<string>;
65
-
66
- declare function verifyJWT(options: {
67
- token: string;
68
- secret: string;
69
- issuer: string;
70
- audience: string;
71
- /** @default 60 */
72
- leeway?: number;
73
- /** @default 'HMAC' */
74
- signatureMethod?: string;
75
- /** @default 'SHA-256' */
76
- hashMethod?: string;
77
- }): Promise<void>;
78
-
79
- export { JWTRegisteredClaims, _decodeJWT, decodeJWT, signJWT, verifyJWT };
1
+ export { j as jwe } from './shared/unjwt.Dr-mxtq9.mjs';
2
+ export { j as jwk } from './shared/unjwt.A7HKFx3n.mjs';
3
+ export { j as jws } from './shared/unjwt.BdjvpIUY.mjs';
4
+ import './shared/unjwt.4uzJv0cA.mjs';
5
+ import './shared/unjwt.zb2wBNCJ.mjs';
package/dist/index.d.ts CHANGED
@@ -1,79 +1,5 @@
1
- /** Recognized JWT Claims Set members */
2
- interface JWTRegisteredClaims {
3
- /**
4
- * JWT Issuer
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
7
- */
8
- iss?: string;
9
- /**
10
- * JWT Subject
11
- *
12
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
13
- */
14
- sub?: string;
15
- /**
16
- * JWT Audience
17
- *
18
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
19
- */
20
- aud?: string | string[];
21
- /**
22
- * JWT ID
23
- *
24
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
25
- */
26
- jti?: string;
27
- /**
28
- * JWT Not Before
29
- *
30
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
31
- */
32
- nbf?: number;
33
- /**
34
- * JWT Expiration Time
35
- *
36
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
37
- */
38
- exp?: number;
39
- /**
40
- * JWT Issued At
41
- *
42
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
43
- */
44
- iat?: number;
45
- }
46
-
47
- declare function decodeJWT<T extends Record<string, any> = Record<string, any>>(token: string): (JWTRegisteredClaims & T) | undefined;
48
- declare function _decodeJWT<T extends Record<string, any> = Record<string, any>>(token: string): JWTRegisteredClaims & T;
49
-
50
- declare function signJWT<T extends Record<string, any> = Record<string, any>>(options: {
51
- payload?: T;
52
- secret: string;
53
- issuer: string;
54
- audience: string;
55
- /**
56
- * Expiration time in days
57
- * @default 30
58
- */
59
- expires?: number;
60
- /** @default 'HMAC' */
61
- signatureMethod?: string;
62
- /** @default 'SHA-256' */
63
- hashMethod?: string;
64
- }): Promise<string>;
65
-
66
- declare function verifyJWT(options: {
67
- token: string;
68
- secret: string;
69
- issuer: string;
70
- audience: string;
71
- /** @default 60 */
72
- leeway?: number;
73
- /** @default 'HMAC' */
74
- signatureMethod?: string;
75
- /** @default 'SHA-256' */
76
- hashMethod?: string;
77
- }): Promise<void>;
78
-
79
- export { JWTRegisteredClaims, _decodeJWT, decodeJWT, signJWT, verifyJWT };
1
+ export { j as jwe } from './shared/unjwt.DGsIvgyn.js';
2
+ export { j as jwk } from './shared/unjwt.CVUxLNoy.js';
3
+ export { j as jws } from './shared/unjwt.BmjmfFWo.js';
4
+ import './shared/unjwt.ChP7VhqI.js';
5
+ import './shared/unjwt.zb2wBNCJ.js';