unjwt 0.5.9 → 0.5.11
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/README.md +3 -3
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +2 -3
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +2 -3
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +2 -3
- package/dist/jws.mjs +4 -4
- package/dist/shared/{unjwt.8w7jp2aw.d.mts → unjwt.BvhKNVNR.d.mts} +28 -30
- package/dist/shared/{unjwt.D9da8HQF.d.mts → unjwt.CN1C8TlR.d.mts} +90 -15
- package/dist/shared/{unjwt.Ca03jPX3.mjs → unjwt.C_D0RMCp.mjs} +1 -1
- package/dist/shared/unjwt.Ce8yMcp_.mjs +298 -0
- package/dist/shared/{unjwt.DH1p_WL8.d.mts → unjwt.Cz90HQhy.d.mts} +11 -12
- package/dist/shared/{unjwt.B2olxeGL.mjs → unjwt.DVMpKj8x.mjs} +22 -86
- package/dist/shared/unjwt.D_JFPtpW.mjs +161 -0
- package/dist/shared/{unjwt.DRUXIabl.mjs → unjwt.DuBBF25X.mjs} +19 -8
- package/dist/shared/{unjwt.D_Mabhgz.d.mts → unjwt.QRureeXk.d.mts} +14 -70
- package/dist/shared/unjwt.df8yQ5_5.d.mts +128 -0
- package/dist/utils.d.mts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +12 -11
- package/dist/shared/unjwt.BHpknTpg.mjs +0 -93
- package/dist/shared/unjwt.BvIkEGGz.d.mts +0 -52
- package/dist/shared/unjwt.CbvzYE-m.d.mts +0 -58
- package/dist/shared/unjwt.wHjOCapq.mjs +0 -279
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode, s as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, f as base64UrlDecode, g as isJWKSet } from './unjwt.Ce8yMcp_.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -330,7 +330,7 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
330
330
|
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
331
331
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
332
332
|
throw new TypeError(
|
|
333
|
-
`Key must be ${cek} one of type: CryptoKey
|
|
333
|
+
`Key must be ${cek} one of type: CryptoKey or Uint8Array`
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
if (iv) {
|
|
@@ -461,7 +461,7 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
461
461
|
async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
462
462
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
463
463
|
throw new TypeError(
|
|
464
|
-
`Key must be ${cek} one of type: CryptoKey
|
|
464
|
+
`Key must be ${cek} one of type: CryptoKey or Uint8Array`
|
|
465
465
|
);
|
|
466
466
|
}
|
|
467
467
|
if (!iv) {
|
|
@@ -497,18 +497,24 @@ async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
497
497
|
* @source https://github.com/panva/jose/tree/69b7960c67e05be55fa2ec31c74b987696c20c60/src/lib/aesgcmkw.ts
|
|
498
498
|
* @license MIT https://github.com/panva/jose/blob/69b7960c67e05be55fa2ec31c74b987696c20c60/LICENSE.md
|
|
499
499
|
*/
|
|
500
|
-
async function encryptIV(alg, key,
|
|
500
|
+
async function encryptIV(alg, key, plaintext, iv) {
|
|
501
501
|
const jweAlgorithm = alg.slice(0, 7);
|
|
502
|
-
const wrapped = await encrypt(
|
|
502
|
+
const wrapped = await encrypt(
|
|
503
|
+
jweAlgorithm,
|
|
504
|
+
plaintext,
|
|
505
|
+
key,
|
|
506
|
+
iv,
|
|
507
|
+
new Uint8Array(0)
|
|
508
|
+
);
|
|
503
509
|
return {
|
|
504
510
|
encryptedKey: wrapped.ciphertext,
|
|
505
511
|
iv: base64UrlEncode(wrapped.iv),
|
|
506
512
|
tag: base64UrlEncode(wrapped.tag)
|
|
507
513
|
};
|
|
508
514
|
}
|
|
509
|
-
async function decryptIV(alg, key,
|
|
515
|
+
async function decryptIV(alg, key, ciphertext, iv, tag) {
|
|
510
516
|
const jweAlgorithm = alg.slice(0, 7);
|
|
511
|
-
return decrypt(jweAlgorithm, key,
|
|
517
|
+
return decrypt(jweAlgorithm, key, ciphertext, iv, tag, new Uint8Array(0));
|
|
512
518
|
}
|
|
513
519
|
|
|
514
520
|
/**
|
|
@@ -1479,7 +1485,12 @@ function getGenerateKeyParams(alg, options) {
|
|
|
1479
1485
|
keyUsages = defaultKeyUsage ?? ["sign", "verify"];
|
|
1480
1486
|
break;
|
|
1481
1487
|
}
|
|
1482
|
-
|
|
1488
|
+
case "Ed25519":
|
|
1489
|
+
case "EdDSA": {
|
|
1490
|
+
algorithm = { name: "Ed25519" };
|
|
1491
|
+
keyUsages = defaultKeyUsage ?? ["sign", "verify"];
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1483
1494
|
// RSA Encryption
|
|
1484
1495
|
case "RSA-OAEP":
|
|
1485
1496
|
case "RSA-OAEP-256":
|
|
@@ -1,5 +1,4 @@
|
|
|
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.
|
|
2
|
-
import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BvIkEGGz.mjs';
|
|
1
|
+
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, H as JoseHeaderParameters, m as JWK, n as JWKSet, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
|
|
3
2
|
|
|
4
3
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
5
4
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -28,7 +27,7 @@ interface JWSSignOptions {
|
|
|
28
27
|
alg?: JWSAlgorithm;
|
|
29
28
|
/**
|
|
30
29
|
* Additional protected header parameters. `alg` is automatically included.
|
|
31
|
-
* `typ` defaults to "
|
|
30
|
+
* `typ` defaults to "at+jwt" if not provided.
|
|
32
31
|
*/
|
|
33
32
|
protectedHeader?: JWSHeaderParameters;
|
|
34
33
|
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
@@ -39,73 +38,18 @@ interface JWSSignOptions {
|
|
|
39
38
|
expiresIn?: number;
|
|
40
39
|
}
|
|
41
40
|
/** Result of JWS verification */
|
|
42
|
-
interface JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
|
|
41
|
+
interface JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
|
|
43
42
|
/** The decoded and verified payload. */
|
|
44
43
|
payload: T;
|
|
45
44
|
/** The JWS Protected Header. */
|
|
46
45
|
protectedHeader: JWSProtectedHeader;
|
|
47
46
|
}
|
|
48
47
|
/** Options for JWS verification */
|
|
49
|
-
interface JWSVerifyOptions {
|
|
48
|
+
interface JWSVerifyOptions extends JWTClaimValidationOptions {
|
|
50
49
|
/** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
|
|
51
50
|
algorithms?: JWSAlgorithm[];
|
|
52
51
|
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
|
|
53
52
|
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
53
|
}
|
|
110
54
|
/**
|
|
111
55
|
* Key lookup function for JWS verification.
|
|
@@ -113,7 +57,7 @@ interface JWSVerifyOptions {
|
|
|
113
57
|
* @param token The JWS token.
|
|
114
58
|
* @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
|
|
115
59
|
*/
|
|
116
|
-
type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array | Promise<CryptoKey | JWK | JWKSet | Uint8Array
|
|
60
|
+
type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer>>;
|
|
117
61
|
|
|
118
62
|
/**
|
|
119
63
|
* Creates a JWS (JSON Web Signature) in Compact Serialization format.
|
|
@@ -124,20 +68,20 @@ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => Crypt
|
|
|
124
68
|
* @returns A Promise resolving to the JWS Compact Serialization string.
|
|
125
69
|
*/
|
|
126
70
|
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>;
|
|
71
|
+
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
|
|
128
72
|
declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
|
|
129
73
|
alg: JWSAlgorithm;
|
|
130
74
|
}): Promise<string>;
|
|
131
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
|
|
75
|
+
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
|
|
132
76
|
alg: JWSAlgorithm;
|
|
133
77
|
}): Promise<string>;
|
|
134
|
-
declare function sign(payload: JWTClaims, key: Uint8Array
|
|
78
|
+
declare function sign(payload: JWTClaims, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
135
79
|
alg: JWSAlgorithm;
|
|
136
80
|
}): Promise<string>;
|
|
137
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: Uint8Array
|
|
81
|
+
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
138
82
|
alg: JWSAlgorithm;
|
|
139
83
|
}): Promise<string>;
|
|
140
|
-
declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array
|
|
84
|
+
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey | JWK | Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
141
85
|
alg: JWSAlgorithm;
|
|
142
86
|
}): Promise<string>;
|
|
143
87
|
/**
|
|
@@ -149,10 +93,10 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
|
|
|
149
93
|
* @returns A Promise resolving to an object containing the verified payload and protected header.
|
|
150
94
|
* @throws If the JWS is invalid, signature verification fails, or options are not met.
|
|
151
95
|
*/
|
|
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 & {
|
|
96
|
+
declare function verify<T extends JWTClaims | Uint8Array<ArrayBuffer> | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
97
|
+
declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options: JWSVerifyOptions & {
|
|
154
98
|
forceUint8Array: true;
|
|
155
|
-
}): Promise<JWSVerifyResult<Uint8Array
|
|
99
|
+
}): Promise<JWSVerifyResult<Uint8Array<ArrayBuffer>>>;
|
|
156
100
|
|
|
157
101
|
type jws_JWSAlgorithm = JWSAlgorithm;
|
|
158
102
|
type jws_JWSHeaderParameters = JWSHeaderParameters;
|
|
@@ -160,7 +104,7 @@ type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
|
|
|
160
104
|
type jws_JWSProtectedHeader = JWSProtectedHeader;
|
|
161
105
|
type jws_JWSSignOptions = JWSSignOptions;
|
|
162
106
|
type jws_JWSVerifyOptions = JWSVerifyOptions;
|
|
163
|
-
type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
|
|
107
|
+
type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> = JWSVerifyResult<T>;
|
|
164
108
|
declare const jws_sign: typeof sign;
|
|
165
109
|
declare const jws_verify: typeof verify;
|
|
166
110
|
declare namespace jws {
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { I as JWTClaims, M as JWTClaimValidationOptions, m as JWK, n as JWKSet } from './unjwt.CN1C8TlR.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Apply default typ/cty semantics shared by JWS & JWE.
|
|
5
|
+
* - If typ is undefined and payload is a non-Uint8Array object, set typ="at+jwt".
|
|
6
|
+
* - If typ is "at+jwt" and payload is a non-Uint8Array object, ensure cty defaults to "application/json".
|
|
7
|
+
*/
|
|
8
|
+
declare function applyTypCtyDefaults<T extends {
|
|
9
|
+
typ?: string;
|
|
10
|
+
cty?: string;
|
|
11
|
+
}>(header: T, payload: unknown): T;
|
|
12
|
+
/** Returns true when headers indicate JSON content. */
|
|
13
|
+
declare function isJsonContent(header: {
|
|
14
|
+
typ?: string;
|
|
15
|
+
cty?: string;
|
|
16
|
+
} | undefined): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Given a decoded string and JOSE headers, return an object if JSON, otherwise the string.
|
|
19
|
+
*/
|
|
20
|
+
declare function decodeMaybeJsonString<T = unknown>(decodedString: string, header: {
|
|
21
|
+
typ?: string;
|
|
22
|
+
cty?: string;
|
|
23
|
+
} | undefined): T | string;
|
|
24
|
+
/**
|
|
25
|
+
* Decode a payload that is represented as raw bytes into T | string, honoring forceUint8Array and headers.
|
|
26
|
+
*/
|
|
27
|
+
declare function decodePayloadFromBytes<T = unknown>(bytes: Uint8Array<ArrayBuffer>, header: {
|
|
28
|
+
typ?: string;
|
|
29
|
+
cty?: string;
|
|
30
|
+
} | undefined, forceUint8Array?: boolean): T | Uint8Array<ArrayBuffer> | string;
|
|
31
|
+
/**
|
|
32
|
+
* Decode a payload that is a Base64URL segment into T | string | Uint8Array based on flags and headers.
|
|
33
|
+
*/
|
|
34
|
+
declare function decodePayloadFromB64UrlSegment<T = unknown>(payloadEncoded: string, header: {
|
|
35
|
+
typ?: string;
|
|
36
|
+
cty?: string;
|
|
37
|
+
} | undefined, forceUint8Array?: boolean): T | Uint8Array<ArrayBuffer> | string;
|
|
38
|
+
/** Convert plaintext input to bytes, shared by JWS & JWE when preparing payload. */
|
|
39
|
+
declare function getPlaintextBytes(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>): Uint8Array<ArrayBuffer>;
|
|
40
|
+
/** Optionally compute iat/exp when signing JWTs. */
|
|
41
|
+
declare function computeJwtTimeClaims(payload: unknown, headerTyp: string | undefined, expiresIn?: number, currentDate?: Date): JWTClaims | undefined;
|
|
42
|
+
/** Validate JWT claims under JWS verification rules (or custom JWE implementations). */
|
|
43
|
+
declare function validateJwtClaims(jwtClaims: JWTClaims, options?: JWTClaimValidationOptions): void;
|
|
44
|
+
/** Validate critical headers in JWS semantics. */
|
|
45
|
+
declare function validateCriticalHeadersJWS(protectedHeader: {
|
|
46
|
+
crit?: string[];
|
|
47
|
+
} & Record<string, any>, requiredHeaders?: string[]): void;
|
|
48
|
+
/** Validate critical headers in JWE semantics. */
|
|
49
|
+
declare function validateCriticalHeadersJWE(protectedHeader: {
|
|
50
|
+
crit?: string[];
|
|
51
|
+
} & Record<string, any>, understoodFromOptions?: string[]): void;
|
|
52
|
+
|
|
53
|
+
declare const textEncoder: TextEncoder;
|
|
54
|
+
declare const textDecoder: TextDecoder;
|
|
55
|
+
declare function base64Encode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
56
|
+
declare function base64UrlEncode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
57
|
+
declare function base64Decode(str: string | undefined): string;
|
|
58
|
+
declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array<ArrayBuffer> : string;
|
|
59
|
+
declare function base64UrlDecode(str: string | undefined): string;
|
|
60
|
+
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array<ArrayBuffer> : string;
|
|
61
|
+
declare function randomBytes(length: Readonly<number>): Uint8Array<ArrayBuffer>;
|
|
62
|
+
/**
|
|
63
|
+
* Concatenates multiple Uint8Arrays
|
|
64
|
+
* @param arrays Arrays to concatenate
|
|
65
|
+
* @returns Concatenated array
|
|
66
|
+
*/
|
|
67
|
+
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array<ArrayBuffer>[]>): Uint8Array<ArrayBuffer>;
|
|
68
|
+
declare function maybeArray<T>(item: T | T[]): T[];
|
|
69
|
+
declare function isJWK(key: any): key is JWK;
|
|
70
|
+
declare function isJWKSet(key: any): key is JWKSet;
|
|
71
|
+
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
72
|
+
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
73
|
+
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
74
|
+
|
|
75
|
+
declare const index_applyTypCtyDefaults: typeof applyTypCtyDefaults;
|
|
76
|
+
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
77
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
78
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
79
|
+
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
80
|
+
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
81
|
+
declare const index_computeJwtTimeClaims: typeof computeJwtTimeClaims;
|
|
82
|
+
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
83
|
+
declare const index_decodeMaybeJsonString: typeof decodeMaybeJsonString;
|
|
84
|
+
declare const index_decodePayloadFromB64UrlSegment: typeof decodePayloadFromB64UrlSegment;
|
|
85
|
+
declare const index_decodePayloadFromBytes: typeof decodePayloadFromBytes;
|
|
86
|
+
declare const index_getPlaintextBytes: typeof getPlaintextBytes;
|
|
87
|
+
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
88
|
+
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
89
|
+
declare const index_isJWK: typeof isJWK;
|
|
90
|
+
declare const index_isJWKSet: typeof isJWKSet;
|
|
91
|
+
declare const index_isJsonContent: typeof isJsonContent;
|
|
92
|
+
declare const index_maybeArray: typeof maybeArray;
|
|
93
|
+
declare const index_randomBytes: typeof randomBytes;
|
|
94
|
+
declare const index_textDecoder: typeof textDecoder;
|
|
95
|
+
declare const index_textEncoder: typeof textEncoder;
|
|
96
|
+
declare const index_validateCriticalHeadersJWE: typeof validateCriticalHeadersJWE;
|
|
97
|
+
declare const index_validateCriticalHeadersJWS: typeof validateCriticalHeadersJWS;
|
|
98
|
+
declare const index_validateJwtClaims: typeof validateJwtClaims;
|
|
99
|
+
declare namespace index {
|
|
100
|
+
export {
|
|
101
|
+
index_applyTypCtyDefaults as applyTypCtyDefaults,
|
|
102
|
+
index_assertCryptoKey as assertCryptoKey,
|
|
103
|
+
index_base64Decode as base64Decode,
|
|
104
|
+
index_base64Encode as base64Encode,
|
|
105
|
+
index_base64UrlDecode as base64UrlDecode,
|
|
106
|
+
index_base64UrlEncode as base64UrlEncode,
|
|
107
|
+
index_computeJwtTimeClaims as computeJwtTimeClaims,
|
|
108
|
+
index_concatUint8Arrays as concatUint8Arrays,
|
|
109
|
+
index_decodeMaybeJsonString as decodeMaybeJsonString,
|
|
110
|
+
index_decodePayloadFromB64UrlSegment as decodePayloadFromB64UrlSegment,
|
|
111
|
+
index_decodePayloadFromBytes as decodePayloadFromBytes,
|
|
112
|
+
index_getPlaintextBytes as getPlaintextBytes,
|
|
113
|
+
index_isCryptoKey as isCryptoKey,
|
|
114
|
+
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
115
|
+
index_isJWK as isJWK,
|
|
116
|
+
index_isJWKSet as isJWKSet,
|
|
117
|
+
index_isJsonContent as isJsonContent,
|
|
118
|
+
index_maybeArray as maybeArray,
|
|
119
|
+
index_randomBytes as randomBytes,
|
|
120
|
+
index_textDecoder as textDecoder,
|
|
121
|
+
index_textEncoder as textEncoder,
|
|
122
|
+
index_validateCriticalHeadersJWE as validateCriticalHeadersJWE,
|
|
123
|
+
index_validateCriticalHeadersJWS as validateCriticalHeadersJWS,
|
|
124
|
+
index_validateJwtClaims as validateJwtClaims,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
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, applyTypCtyDefaults as n, isJsonContent as o, decodeMaybeJsonString as p, decodePayloadFromBytes as q, randomBytes as r, decodePayloadFromB64UrlSegment as s, textEncoder as t, getPlaintextBytes as u, computeJwtTimeClaims as v, validateJwtClaims as w, validateCriticalHeadersJWS as x, validateCriticalHeadersJWE as y };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
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.
|
|
1
|
+
import './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { n as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, v as computeJwtTimeClaims, f as concatUint8Arrays, p as decodeMaybeJsonString, s as decodePayloadFromB64UrlSegment, q as decodePayloadFromBytes, u as getPlaintextBytes, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, o as isJsonContent, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder, y as validateCriticalHeadersJWE, x as validateCriticalHeadersJWS, w as validateJwtClaims } from './shared/unjwt.df8yQ5_5.mjs';
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, s as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, y as decodeMaybeJsonString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, m as isCryptoKey, w as isCryptoKeyPair, a as isJWK, g as isJWKSet, x as isJsonContent, u as maybeArray, r as randomBytes, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.Ce8yMcp_.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unjwt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "Low-level JWT utilities",
|
|
5
5
|
"repository": "sandros94/unjwt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,16 +50,17 @@
|
|
|
50
50
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^22.13.
|
|
54
|
-
"@vitest/coverage-v8": "^3.
|
|
53
|
+
"@types/node": "^22.13.14",
|
|
54
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
55
55
|
"automd": "^0.4.0",
|
|
56
|
-
"changelogen": "^0.6.
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"eslint-config-unjs": "^0.
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
56
|
+
"changelogen": "^0.6.2",
|
|
57
|
+
"eslint": "^9.34.0",
|
|
58
|
+
"eslint-config-unjs": "^0.5.0",
|
|
59
|
+
"jose": "^6.0.13",
|
|
60
|
+
"prettier": "^3.6.2",
|
|
61
|
+
"typescript": "^5.9.2",
|
|
62
|
+
"unbuild": "^3.6.1",
|
|
63
|
+
"vitest": "^3.2.4"
|
|
63
64
|
},
|
|
64
|
-
"packageManager": "pnpm@10.
|
|
65
|
+
"packageManager": "pnpm@10.15.0"
|
|
65
66
|
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
2
|
-
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
3
|
-
function base64Encode(data) {
|
|
4
|
-
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
5
|
-
if (Uint8Array.prototype.toBase64) {
|
|
6
|
-
return encodedData.toBase64();
|
|
7
|
-
}
|
|
8
|
-
return btoa(String.fromCodePoint(...encodedData));
|
|
9
|
-
}
|
|
10
|
-
function base64UrlEncode(data) {
|
|
11
|
-
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
12
|
-
if (Uint8Array.prototype.toBase64) {
|
|
13
|
-
return encodedData.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
14
|
-
}
|
|
15
|
-
return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
16
|
-
}
|
|
17
|
-
function base64Decode(str, toString) {
|
|
18
|
-
const decodeToString = toString !== false;
|
|
19
|
-
if (!str) {
|
|
20
|
-
return decodeToString ? "" : new Uint8Array(0);
|
|
21
|
-
}
|
|
22
|
-
const data = Uint8Array.fromBase64 ? (
|
|
23
|
-
// @ts-expect-error
|
|
24
|
-
Uint8Array.fromBase64(str)
|
|
25
|
-
) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
26
|
-
return decodeToString ? textDecoder.decode(data) : data;
|
|
27
|
-
}
|
|
28
|
-
function base64UrlDecode(str, toString) {
|
|
29
|
-
const decodeToString = toString !== false;
|
|
30
|
-
if (!str) {
|
|
31
|
-
return decodeToString ? "" : new Uint8Array(0);
|
|
32
|
-
}
|
|
33
|
-
let data;
|
|
34
|
-
if (Uint8Array.fromBase64) {
|
|
35
|
-
data = Uint8Array.fromBase64(str, { alphabet: "base64url" });
|
|
36
|
-
} else {
|
|
37
|
-
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
38
|
-
while (str.length % 4) str += "=";
|
|
39
|
-
data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
40
|
-
}
|
|
41
|
-
return decodeToString ? textDecoder.decode(data) : data;
|
|
42
|
-
}
|
|
43
|
-
function randomBytes(length) {
|
|
44
|
-
return crypto.getRandomValues(new Uint8Array(length));
|
|
45
|
-
}
|
|
46
|
-
function concatUint8Arrays(...arrays) {
|
|
47
|
-
const totalLength = arrays.reduce((length, arr) => length + arr.length, 0);
|
|
48
|
-
const result = new Uint8Array(totalLength);
|
|
49
|
-
let offset = 0;
|
|
50
|
-
for (const arr of arrays) {
|
|
51
|
-
result.set(arr, offset);
|
|
52
|
-
offset += arr.length;
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
function maybeArray(item) {
|
|
57
|
-
return Array.isArray(item) ? item : [item];
|
|
58
|
-
}
|
|
59
|
-
function isJWK(key) {
|
|
60
|
-
return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
|
|
61
|
-
}
|
|
62
|
-
function isJWKSet(key) {
|
|
63
|
-
return key && typeof key === "object" && "keys" in key && Array.isArray(key.keys);
|
|
64
|
-
}
|
|
65
|
-
function assertCryptoKey(key) {
|
|
66
|
-
if (!isCryptoKey(key)) {
|
|
67
|
-
throw new Error("CryptoKey instance expected");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function isCryptoKey(key) {
|
|
71
|
-
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
72
|
-
}
|
|
73
|
-
const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
|
|
74
|
-
|
|
75
|
-
const index = {
|
|
76
|
-
__proto__: null,
|
|
77
|
-
assertCryptoKey: assertCryptoKey,
|
|
78
|
-
base64Decode: base64Decode,
|
|
79
|
-
base64Encode: base64Encode,
|
|
80
|
-
base64UrlDecode: base64UrlDecode,
|
|
81
|
-
base64UrlEncode: base64UrlEncode,
|
|
82
|
-
concatUint8Arrays: concatUint8Arrays,
|
|
83
|
-
isCryptoKey: isCryptoKey,
|
|
84
|
-
isCryptoKeyPair: isCryptoKeyPair,
|
|
85
|
-
isJWK: isJWK,
|
|
86
|
-
isJWKSet: isJWKSet,
|
|
87
|
-
maybeArray: maybeArray,
|
|
88
|
-
randomBytes: randomBytes,
|
|
89
|
-
textDecoder: textDecoder,
|
|
90
|
-
textEncoder: textEncoder
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, isJWKSet as e, concatUint8Arrays as f, assertCryptoKey as g, isCryptoKey as h, index as i, base64Decode as j, base64Encode as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { i as JWK_RSA_Public } from './unjwt.D9da8HQF.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 };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.mjs';
|
|
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 };
|