unjwt 0.5.38 → 0.5.39
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 +142 -666
- package/dist/_chunks/chunk.mjs +13 -0
- package/dist/_chunks/h3v1.mjs +598 -0
- package/dist/_chunks/index.d.mts +250 -0
- package/dist/_chunks/index2.d.mts +108 -0
- package/dist/_chunks/jwe.d.mts +43 -0
- package/dist/_chunks/jwe.mjs +132 -0
- package/dist/_chunks/jwk.d.mts +575 -0
- package/dist/_chunks/jwk.mjs +1592 -0
- package/dist/_chunks/jws.d.mts +46 -0
- package/dist/_chunks/jws.mjs +2069 -0
- package/dist/_chunks/utils.mjs +374 -0
- package/dist/adapters/h3.d.mts +3 -267
- package/dist/adapters/h3.mjs +3 -704
- package/dist/adapters/h3v1.d.mts +3 -8
- package/dist/adapters/h3v1.mjs +3 -7
- package/dist/adapters/h3v2.d.mts +145 -146
- package/dist/adapters/h3v2.mjs +505 -594
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +5 -4
- package/dist/jwe.d.mts +3 -4
- package/dist/jwe.mjs +4 -3
- package/dist/jwk.d.mts +3 -2
- package/dist/jwk.mjs +3 -2
- package/dist/jws.d.mts +3 -3
- package/dist/jws.mjs +4 -3
- package/dist/utils.d.mts +3 -3
- package/dist/utils.mjs +2 -1
- package/package.json +33 -31
- package/dist/shared/unjwt.4JQCoID_.d.mts +0 -161
- package/dist/shared/unjwt.B-v62plj.mjs +0 -249
- package/dist/shared/unjwt.BCi3FEWr.d.mts +0 -328
- package/dist/shared/unjwt.BYDTEWa-.d.mts +0 -269
- package/dist/shared/unjwt.Be8NxwFK.mjs +0 -438
- package/dist/shared/unjwt.BqdNUKDr.d.mts +0 -64
- package/dist/shared/unjwt.CMNtw8ek.d.mts +0 -155
- package/dist/shared/unjwt.Cy2MlkUe.d.mts +0 -174
- package/dist/shared/unjwt.D0_ccT7g.d.mts +0 -166
- package/dist/shared/unjwt.DdLN9vwI.mjs +0 -163
- package/dist/shared/unjwt.Dpl__ZAR.mjs +0 -2121
- package/dist/shared/unjwt.JdKqVANs.d.mts +0 -5
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { E as ExpiresIn, X as JWTClaims, Z as JWTClaimValidationOptions, v as JWK, w as JWKSet, q as JWK_oct, u as JWK_Private, t as JWK_Public } from './unjwt.BCi3FEWr.mjs';
|
|
2
|
-
import { S as StrictOmit } from './unjwt.JdKqVANs.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Apply default typ/cty semantics shared by JWS & JWE.
|
|
6
|
-
* - If typ is undefined and payload is a non-Uint8Array object, set typ="JWT".
|
|
7
|
-
* - If typ is "JWT" and payload is a non-Uint8Array object, ensure cty defaults to "application/json".
|
|
8
|
-
*/
|
|
9
|
-
declare function applyTypCtyDefaults<T extends {
|
|
10
|
-
typ?: string;
|
|
11
|
-
cty?: string;
|
|
12
|
-
}>(header: T, payload: unknown): T;
|
|
13
|
-
/** Returns true when headers indicate JSON content. */
|
|
14
|
-
declare function isJWTContent(header: {
|
|
15
|
-
typ?: string;
|
|
16
|
-
cty?: string;
|
|
17
|
-
} | undefined): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Given a decoded string and JOSE headers, return an object if JSON, otherwise the string.
|
|
20
|
-
*/
|
|
21
|
-
declare function decodeMaybeJWTString<T = unknown>(decodedString: string, header: {
|
|
22
|
-
typ?: string;
|
|
23
|
-
cty?: string;
|
|
24
|
-
} | undefined): T | string;
|
|
25
|
-
/**
|
|
26
|
-
* Decode a payload that is represented as raw bytes into T | string, honoring forceUint8Array and headers.
|
|
27
|
-
*/
|
|
28
|
-
declare function decodePayloadFromBytes<T = unknown>(bytes: Uint8Array<ArrayBuffer>, header: {
|
|
29
|
-
typ?: string;
|
|
30
|
-
cty?: string;
|
|
31
|
-
} | undefined, forceUint8Array?: boolean): T | Uint8Array<ArrayBuffer> | string;
|
|
32
|
-
/**
|
|
33
|
-
* Decode a payload that is a Base64URL segment into T | string | Uint8Array based on flags and headers.
|
|
34
|
-
*/
|
|
35
|
-
declare function decodePayloadFromB64UrlSegment<T = unknown>(payloadEncoded: string, header: {
|
|
36
|
-
typ?: string;
|
|
37
|
-
cty?: string;
|
|
38
|
-
} | undefined, forceUint8Array?: boolean): T | Uint8Array<ArrayBuffer> | string;
|
|
39
|
-
/** Convert plaintext input to bytes, shared by JWS & JWE when preparing payload. */
|
|
40
|
-
declare function getPlaintextBytes(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>): Uint8Array<ArrayBuffer>;
|
|
41
|
-
declare function computeExpiresInSeconds(expiresIn: ExpiresIn): number;
|
|
42
|
-
declare const computeMaxTokenAgeSeconds: typeof computeExpiresInSeconds;
|
|
43
|
-
/** Optionally compute iat/exp when signing JWTs. */
|
|
44
|
-
declare function computeJwtTimeClaims(payload: unknown, headerTyp: string | undefined, expiresIn?: ExpiresIn, currentDate?: Date): JWTClaims | undefined;
|
|
45
|
-
/** Validate JWT claims under JWS verification rules (or custom JWE implementations). */
|
|
46
|
-
declare function validateJwtClaims(jwtClaims: JWTClaims, options?: JWTClaimValidationOptions): void;
|
|
47
|
-
/** Validate critical headers in JWS semantics. */
|
|
48
|
-
declare function validateCriticalHeadersJWS(protectedHeader: {
|
|
49
|
-
crit?: string[];
|
|
50
|
-
} & Record<string, any>, requiredHeaders?: string[]): void;
|
|
51
|
-
/** Validate critical headers in JWE semantics. */
|
|
52
|
-
declare function validateCriticalHeadersJWE(protectedHeader: {
|
|
53
|
-
crit?: string[];
|
|
54
|
-
} & Record<string, any>, understoodFromOptions?: string[]): void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Forked from unsecure@0.0.4
|
|
58
|
-
* Licensed under the MIT License.
|
|
59
|
-
*
|
|
60
|
-
* Source: https://github.com/sandros94/unsecure/blob/913ed5580c551153a19154b4916c67a8efb2be85/src/sanitize.ts
|
|
61
|
-
*/
|
|
62
|
-
/**
|
|
63
|
-
* Remove prototype-pollution vectors from a plain record in-place.
|
|
64
|
-
* This strips __proto__, prototype, and constructor own properties.
|
|
65
|
-
* Returns the same reference for convenience.
|
|
66
|
-
*/
|
|
67
|
-
declare function sanitizeObject<T extends Record<string, unknown> | undefined>(obj: T): T;
|
|
68
|
-
|
|
69
|
-
declare const textEncoder: TextEncoder;
|
|
70
|
-
declare const textDecoder: TextDecoder;
|
|
71
|
-
declare function base64Encode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
72
|
-
declare function base64UrlEncode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
73
|
-
declare function base64Decode(str: string | undefined): string;
|
|
74
|
-
declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array<ArrayBuffer> : string;
|
|
75
|
-
declare function base64UrlDecode(str: string | undefined): string;
|
|
76
|
-
declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array<ArrayBuffer> : string;
|
|
77
|
-
declare function randomBytes(length: Readonly<number>): Uint8Array<ArrayBuffer>;
|
|
78
|
-
/**
|
|
79
|
-
* Concatenates multiple Uint8Arrays
|
|
80
|
-
* @param arrays Arrays to concatenate
|
|
81
|
-
* @returns Concatenated array
|
|
82
|
-
*/
|
|
83
|
-
declare function concatUint8Arrays(...arrays: Readonly<Uint8Array<ArrayBuffer>[]>): Uint8Array<ArrayBuffer>;
|
|
84
|
-
declare function maybeArray<T>(item: T | T[]): T[];
|
|
85
|
-
declare function isJWK(key: any): key is JWK;
|
|
86
|
-
declare function isJWKSet(key: any): key is JWKSet;
|
|
87
|
-
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
88
|
-
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
89
|
-
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
90
|
-
/** Returns true if the JWK is a symmetric (oct) key. */
|
|
91
|
-
declare function isSymmetricJWK(key: unknown): key is Extract<JWK, JWK_oct>;
|
|
92
|
-
/** Returns true if the JWK is an asymmetric (RSA, EC, OKP) key. */
|
|
93
|
-
declare function isAsymmetricJWK(key: unknown): key is Exclude<JWK, JWK_oct>;
|
|
94
|
-
/**
|
|
95
|
-
* Type guard that checks if the provided JWK contains private key material.
|
|
96
|
-
* It relies purely on the presence of private components (e.g. "d"), not on the alg value.
|
|
97
|
-
*/
|
|
98
|
-
declare function isPrivateJWK(key: unknown): key is JWK_Private;
|
|
99
|
-
/**
|
|
100
|
-
* Type guard that checks if the provided JWK is a public (asymmetric) key.
|
|
101
|
-
* This checks for the presence of public components and absence of private material.
|
|
102
|
-
*/
|
|
103
|
-
declare function isPublicJWK(key: unknown): key is JWK_Public;
|
|
104
|
-
|
|
105
|
-
declare const index_StrictOmit: typeof StrictOmit;
|
|
106
|
-
declare const index_applyTypCtyDefaults: typeof applyTypCtyDefaults;
|
|
107
|
-
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
108
|
-
declare const index_base64Decode: typeof base64Decode;
|
|
109
|
-
declare const index_base64Encode: typeof base64Encode;
|
|
110
|
-
declare const index_base64UrlDecode: typeof base64UrlDecode;
|
|
111
|
-
declare const index_base64UrlEncode: typeof base64UrlEncode;
|
|
112
|
-
declare const index_computeExpiresInSeconds: typeof computeExpiresInSeconds;
|
|
113
|
-
declare const index_computeJwtTimeClaims: typeof computeJwtTimeClaims;
|
|
114
|
-
declare const index_computeMaxTokenAgeSeconds: typeof computeMaxTokenAgeSeconds;
|
|
115
|
-
declare const index_concatUint8Arrays: typeof concatUint8Arrays;
|
|
116
|
-
declare const index_decodeMaybeJWTString: typeof decodeMaybeJWTString;
|
|
117
|
-
declare const index_decodePayloadFromB64UrlSegment: typeof decodePayloadFromB64UrlSegment;
|
|
118
|
-
declare const index_decodePayloadFromBytes: typeof decodePayloadFromBytes;
|
|
119
|
-
declare const index_getPlaintextBytes: typeof getPlaintextBytes;
|
|
120
|
-
declare const index_isAsymmetricJWK: typeof isAsymmetricJWK;
|
|
121
|
-
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
122
|
-
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
123
|
-
declare const index_isJWK: typeof isJWK;
|
|
124
|
-
declare const index_isJWKSet: typeof isJWKSet;
|
|
125
|
-
declare const index_isJWTContent: typeof isJWTContent;
|
|
126
|
-
declare const index_isPrivateJWK: typeof isPrivateJWK;
|
|
127
|
-
declare const index_isPublicJWK: typeof isPublicJWK;
|
|
128
|
-
declare const index_isSymmetricJWK: typeof isSymmetricJWK;
|
|
129
|
-
declare const index_maybeArray: typeof maybeArray;
|
|
130
|
-
declare const index_randomBytes: typeof randomBytes;
|
|
131
|
-
declare const index_sanitizeObject: typeof sanitizeObject;
|
|
132
|
-
declare const index_textDecoder: typeof textDecoder;
|
|
133
|
-
declare const index_textEncoder: typeof textEncoder;
|
|
134
|
-
declare const index_validateCriticalHeadersJWE: typeof validateCriticalHeadersJWE;
|
|
135
|
-
declare const index_validateCriticalHeadersJWS: typeof validateCriticalHeadersJWS;
|
|
136
|
-
declare const index_validateJwtClaims: typeof validateJwtClaims;
|
|
137
|
-
declare namespace index {
|
|
138
|
-
export {
|
|
139
|
-
index_StrictOmit as StrictOmit,
|
|
140
|
-
index_applyTypCtyDefaults as applyTypCtyDefaults,
|
|
141
|
-
index_assertCryptoKey as assertCryptoKey,
|
|
142
|
-
index_base64Decode as base64Decode,
|
|
143
|
-
index_base64Encode as base64Encode,
|
|
144
|
-
index_base64UrlDecode as base64UrlDecode,
|
|
145
|
-
index_base64UrlEncode as base64UrlEncode,
|
|
146
|
-
index_computeExpiresInSeconds as computeExpiresInSeconds,
|
|
147
|
-
index_computeJwtTimeClaims as computeJwtTimeClaims,
|
|
148
|
-
index_computeMaxTokenAgeSeconds as computeMaxTokenAgeSeconds,
|
|
149
|
-
index_concatUint8Arrays as concatUint8Arrays,
|
|
150
|
-
index_decodeMaybeJWTString as decodeMaybeJWTString,
|
|
151
|
-
index_decodePayloadFromB64UrlSegment as decodePayloadFromB64UrlSegment,
|
|
152
|
-
index_decodePayloadFromBytes as decodePayloadFromBytes,
|
|
153
|
-
index_getPlaintextBytes as getPlaintextBytes,
|
|
154
|
-
index_isAsymmetricJWK as isAsymmetricJWK,
|
|
155
|
-
index_isCryptoKey as isCryptoKey,
|
|
156
|
-
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
157
|
-
index_isJWK as isJWK,
|
|
158
|
-
index_isJWKSet as isJWKSet,
|
|
159
|
-
index_isJWTContent as isJWTContent,
|
|
160
|
-
index_isPrivateJWK as isPrivateJWK,
|
|
161
|
-
index_isPublicJWK as isPublicJWK,
|
|
162
|
-
index_isSymmetricJWK as isSymmetricJWK,
|
|
163
|
-
index_maybeArray as maybeArray,
|
|
164
|
-
index_randomBytes as randomBytes,
|
|
165
|
-
index_sanitizeObject as sanitizeObject,
|
|
166
|
-
index_textDecoder as textDecoder,
|
|
167
|
-
index_textEncoder as textEncoder,
|
|
168
|
-
index_validateCriticalHeadersJWE as validateCriticalHeadersJWE,
|
|
169
|
-
index_validateCriticalHeadersJWS as validateCriticalHeadersJWS,
|
|
170
|
-
index_validateJwtClaims as validateJwtClaims,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export { computeMaxTokenAgeSeconds as A, computeJwtTimeClaims as B, validateJwtClaims as C, validateCriticalHeadersJWS as D, validateCriticalHeadersJWE as E, sanitizeObject as F, 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, isSymmetricJWK as n, isAsymmetricJWK as o, isPrivateJWK as p, isPublicJWK as q, randomBytes as r, applyTypCtyDefaults as s, textEncoder as t, isJWTContent as u, decodeMaybeJWTString as v, decodePayloadFromBytes as w, decodePayloadFromB64UrlSegment as x, getPlaintextBytes as y, computeExpiresInSeconds as z };
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { X as JWTClaims, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, w as JWKSet, C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './unjwt.BCi3FEWr.mjs';
|
|
2
|
-
import { c as JWSSignOptions, J as JWSAlgorithm, f as JWSKeyLookupFunction, e as JWSVerifyOptions, d as JWSVerifyResult, a as JWSHeaderParameters, b as JWSProtectedHeader } from './unjwt.BqdNUKDr.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a JWS (JSON Web Signature) in Compact Serialization format.
|
|
6
|
-
*
|
|
7
|
-
* @param payload The payload to sign. Can be a string, Uint8Array, or an object (which will be JSON stringified).
|
|
8
|
-
* @param key The signing key (CryptoKey, JWK, or raw symmetric key as Uint8Array).
|
|
9
|
-
* @param options Signing options, including the algorithm (`alg`) and protected header parameters.
|
|
10
|
-
* @returns A Promise resolving to the JWS Compact Serialization string.
|
|
11
|
-
*/
|
|
12
|
-
declare function sign(payload: JWTClaims, key: JWK_Symmetric | JWK_Private, options?: JWSSignOptions): Promise<string>;
|
|
13
|
-
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: JWK_Symmetric | JWK_Private, options?: JWSSignOptions): Promise<string>;
|
|
14
|
-
declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
|
|
15
|
-
alg: JWSAlgorithm;
|
|
16
|
-
}): Promise<string>;
|
|
17
|
-
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
|
|
18
|
-
alg: JWSAlgorithm;
|
|
19
|
-
}): Promise<string>;
|
|
20
|
-
declare function sign(payload: JWTClaims, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
21
|
-
alg: JWSAlgorithm;
|
|
22
|
-
}): Promise<string>;
|
|
23
|
-
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
24
|
-
alg: JWSAlgorithm;
|
|
25
|
-
}): Promise<string>;
|
|
26
|
-
declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey | JWK_Symmetric | JWK_Private | Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
27
|
-
alg: JWSAlgorithm;
|
|
28
|
-
}): Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* Verifies a JWS (JSON Web Signature) in Compact Serialization format.
|
|
31
|
-
*
|
|
32
|
-
* @param jws The JWS Compact Serialization string.
|
|
33
|
-
* @param key The verification key (CryptoKey, JWK, JWKSet, raw symmetric key as Uint8Array, or a function resolving the key or set).
|
|
34
|
-
* @param options Verification options, such as allowed algorithms.
|
|
35
|
-
* @returns A Promise resolving to an object containing the verified payload and protected header.
|
|
36
|
-
* @throws If the JWS is invalid, signature verification fails, or options are not met.
|
|
37
|
-
*/
|
|
38
|
-
declare function verify<T extends JWTClaims | Uint8Array<ArrayBuffer> | string>(jws: string, key: CryptoKey | JWK_Symmetric | JWK_Public | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
39
|
-
declare function verify(jws: string, key: CryptoKey | JWK_Symmetric | JWK_Public | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options: JWSVerifyOptions & {
|
|
40
|
-
forceUint8Array: true;
|
|
41
|
-
}): Promise<JWSVerifyResult<Uint8Array<ArrayBuffer>>>;
|
|
42
|
-
|
|
43
|
-
declare const jws_CompositeKey: typeof CompositeKey;
|
|
44
|
-
declare const jws_ContentEncryptionAlgorithm: typeof ContentEncryptionAlgorithm;
|
|
45
|
-
declare const jws_DeriveKeyOptions: typeof DeriveKeyOptions;
|
|
46
|
-
declare const jws_DeriveKeyReturn: typeof DeriveKeyReturn;
|
|
47
|
-
declare const jws_GenerateJWKOptions: typeof GenerateJWKOptions;
|
|
48
|
-
declare const jws_GenerateJWKReturn: typeof GenerateJWKReturn;
|
|
49
|
-
declare const jws_GenerateKeyAlgorithm: typeof GenerateKeyAlgorithm;
|
|
50
|
-
declare const jws_GenerateKeyOptions: typeof GenerateKeyOptions;
|
|
51
|
-
declare const jws_GenerateKeyReturn: typeof GenerateKeyReturn;
|
|
52
|
-
declare const jws_JWK: typeof JWK;
|
|
53
|
-
declare const jws_JWKAlgorithm: typeof JWKAlgorithm;
|
|
54
|
-
declare const jws_JWKPEMAlgorithm: typeof JWKPEMAlgorithm;
|
|
55
|
-
declare const jws_JWKParameters: typeof JWKParameters;
|
|
56
|
-
declare const jws_JWKSet: typeof JWKSet;
|
|
57
|
-
declare const jws_JWK_AES_CBC_HMAC: typeof JWK_AES_CBC_HMAC;
|
|
58
|
-
declare const jws_JWK_AES_GCM: typeof JWK_AES_GCM;
|
|
59
|
-
declare const jws_JWK_AES_GCM_KW: typeof JWK_AES_GCM_KW;
|
|
60
|
-
declare const jws_JWK_AES_KW: typeof JWK_AES_KW;
|
|
61
|
-
declare const jws_JWK_Asymmetric: typeof JWK_Asymmetric;
|
|
62
|
-
declare const jws_JWK_Asymmetric_Algorithm: typeof JWK_Asymmetric_Algorithm;
|
|
63
|
-
declare const jws_JWK_EC: typeof JWK_EC;
|
|
64
|
-
declare const jws_JWK_ECDH_ES: typeof JWK_ECDH_ES;
|
|
65
|
-
declare const jws_JWK_ECDSA: typeof JWK_ECDSA;
|
|
66
|
-
declare const jws_JWK_EC_Private: typeof JWK_EC_Private;
|
|
67
|
-
declare const jws_JWK_EC_Public: typeof JWK_EC_Public;
|
|
68
|
-
declare const jws_JWK_HMAC: typeof JWK_HMAC;
|
|
69
|
-
declare const jws_JWK_OKP: typeof JWK_OKP;
|
|
70
|
-
declare const jws_JWK_OKP_Private: typeof JWK_OKP_Private;
|
|
71
|
-
declare const jws_JWK_OKP_Public: typeof JWK_OKP_Public;
|
|
72
|
-
declare const jws_JWK_OKP_SIGN: typeof JWK_OKP_SIGN;
|
|
73
|
-
declare const jws_JWK_PBES2: typeof JWK_PBES2;
|
|
74
|
-
declare const jws_JWK_Private: typeof JWK_Private;
|
|
75
|
-
declare const jws_JWK_Public: typeof JWK_Public;
|
|
76
|
-
declare const jws_JWK_RSA: typeof JWK_RSA;
|
|
77
|
-
declare const jws_JWK_RSA_ENC: typeof JWK_RSA_ENC;
|
|
78
|
-
declare const jws_JWK_RSA_PSS: typeof JWK_RSA_PSS;
|
|
79
|
-
declare const jws_JWK_RSA_Private: typeof JWK_RSA_Private;
|
|
80
|
-
declare const jws_JWK_RSA_Public: typeof JWK_RSA_Public;
|
|
81
|
-
declare const jws_JWK_RSA_SIGN: typeof JWK_RSA_SIGN;
|
|
82
|
-
declare const jws_JWK_Symmetric: typeof JWK_Symmetric;
|
|
83
|
-
declare const jws_JWK_Symmetric_Algorithm: typeof JWK_Symmetric_Algorithm;
|
|
84
|
-
declare const jws_JWK_oct: typeof JWK_oct;
|
|
85
|
-
declare const jws_JWSAlgorithm: typeof JWSAlgorithm;
|
|
86
|
-
declare const jws_JWSHeaderParameters: typeof JWSHeaderParameters;
|
|
87
|
-
declare const jws_JWSKeyLookupFunction: typeof JWSKeyLookupFunction;
|
|
88
|
-
declare const jws_JWSProtectedHeader: typeof JWSProtectedHeader;
|
|
89
|
-
declare const jws_JWSSignOptions: typeof JWSSignOptions;
|
|
90
|
-
declare const jws_JWSVerifyOptions: typeof JWSVerifyOptions;
|
|
91
|
-
declare const jws_JWSVerifyResult: typeof JWSVerifyResult;
|
|
92
|
-
declare const jws_JWT: typeof JWT;
|
|
93
|
-
declare const jws_JWTClaimValidationOptions: typeof JWTClaimValidationOptions;
|
|
94
|
-
declare const jws_JWTClaims: typeof JWTClaims;
|
|
95
|
-
declare const jws_JoseHeaderParameters: typeof JoseHeaderParameters;
|
|
96
|
-
declare const jws_KeyManagementAlgorithm: typeof KeyManagementAlgorithm;
|
|
97
|
-
declare const jws_UnwrapKeyOptions: typeof UnwrapKeyOptions;
|
|
98
|
-
declare const jws_WrapKeyOptions: typeof WrapKeyOptions;
|
|
99
|
-
declare const jws_WrapKeyResult: typeof WrapKeyResult;
|
|
100
|
-
declare const jws_sign: typeof sign;
|
|
101
|
-
declare const jws_verify: typeof verify;
|
|
102
|
-
declare namespace jws {
|
|
103
|
-
export {
|
|
104
|
-
jws_CompositeKey as CompositeKey,
|
|
105
|
-
jws_ContentEncryptionAlgorithm as ContentEncryptionAlgorithm,
|
|
106
|
-
jws_DeriveKeyOptions as DeriveKeyOptions,
|
|
107
|
-
jws_DeriveKeyReturn as DeriveKeyReturn,
|
|
108
|
-
jws_GenerateJWKOptions as GenerateJWKOptions,
|
|
109
|
-
jws_GenerateJWKReturn as GenerateJWKReturn,
|
|
110
|
-
jws_GenerateKeyAlgorithm as GenerateKeyAlgorithm,
|
|
111
|
-
jws_GenerateKeyOptions as GenerateKeyOptions,
|
|
112
|
-
jws_GenerateKeyReturn as GenerateKeyReturn,
|
|
113
|
-
jws_JWK as JWK,
|
|
114
|
-
jws_JWKAlgorithm as JWKAlgorithm,
|
|
115
|
-
jws_JWKPEMAlgorithm as JWKPEMAlgorithm,
|
|
116
|
-
jws_JWKParameters as JWKParameters,
|
|
117
|
-
jws_JWKSet as JWKSet,
|
|
118
|
-
jws_JWK_AES_CBC_HMAC as JWK_AES_CBC_HMAC,
|
|
119
|
-
jws_JWK_AES_GCM as JWK_AES_GCM,
|
|
120
|
-
jws_JWK_AES_GCM_KW as JWK_AES_GCM_KW,
|
|
121
|
-
jws_JWK_AES_KW as JWK_AES_KW,
|
|
122
|
-
jws_JWK_Asymmetric as JWK_Asymmetric,
|
|
123
|
-
jws_JWK_Asymmetric_Algorithm as JWK_Asymmetric_Algorithm,
|
|
124
|
-
jws_JWK_EC as JWK_EC,
|
|
125
|
-
jws_JWK_ECDH_ES as JWK_ECDH_ES,
|
|
126
|
-
jws_JWK_ECDSA as JWK_ECDSA,
|
|
127
|
-
jws_JWK_EC_Private as JWK_EC_Private,
|
|
128
|
-
jws_JWK_EC_Public as JWK_EC_Public,
|
|
129
|
-
jws_JWK_HMAC as JWK_HMAC,
|
|
130
|
-
jws_JWK_OKP as JWK_OKP,
|
|
131
|
-
jws_JWK_OKP_Private as JWK_OKP_Private,
|
|
132
|
-
jws_JWK_OKP_Public as JWK_OKP_Public,
|
|
133
|
-
jws_JWK_OKP_SIGN as JWK_OKP_SIGN,
|
|
134
|
-
jws_JWK_PBES2 as JWK_PBES2,
|
|
135
|
-
jws_JWK_Private as JWK_Private,
|
|
136
|
-
jws_JWK_Public as JWK_Public,
|
|
137
|
-
jws_JWK_RSA as JWK_RSA,
|
|
138
|
-
jws_JWK_RSA_ENC as JWK_RSA_ENC,
|
|
139
|
-
jws_JWK_RSA_PSS as JWK_RSA_PSS,
|
|
140
|
-
jws_JWK_RSA_Private as JWK_RSA_Private,
|
|
141
|
-
jws_JWK_RSA_Public as JWK_RSA_Public,
|
|
142
|
-
jws_JWK_RSA_SIGN as JWK_RSA_SIGN,
|
|
143
|
-
jws_JWK_Symmetric as JWK_Symmetric,
|
|
144
|
-
jws_JWK_Symmetric_Algorithm as JWK_Symmetric_Algorithm,
|
|
145
|
-
jws_JWK_oct as JWK_oct,
|
|
146
|
-
jws_JWSAlgorithm as JWSAlgorithm,
|
|
147
|
-
jws_JWSHeaderParameters as JWSHeaderParameters,
|
|
148
|
-
jws_JWSKeyLookupFunction as JWSKeyLookupFunction,
|
|
149
|
-
jws_JWSProtectedHeader as JWSProtectedHeader,
|
|
150
|
-
jws_JWSSignOptions as JWSSignOptions,
|
|
151
|
-
jws_JWSVerifyOptions as JWSVerifyOptions,
|
|
152
|
-
jws_JWSVerifyResult as JWSVerifyResult,
|
|
153
|
-
jws_JWT as JWT,
|
|
154
|
-
jws_JWTClaimValidationOptions as JWTClaimValidationOptions,
|
|
155
|
-
jws_JWTClaims as JWTClaims,
|
|
156
|
-
jws_JoseHeaderParameters as JoseHeaderParameters,
|
|
157
|
-
jws_KeyManagementAlgorithm as KeyManagementAlgorithm,
|
|
158
|
-
jws_UnwrapKeyOptions as UnwrapKeyOptions,
|
|
159
|
-
jws_WrapKeyOptions as WrapKeyOptions,
|
|
160
|
-
jws_WrapKeyResult as WrapKeyResult,
|
|
161
|
-
jws_sign as sign,
|
|
162
|
-
jws_verify as verify,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export { jws as j, sign as s, verify as v };
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { i as importKey, s as sign$1, b as getJWKFromSet, v as verify$1 } from './unjwt.Dpl__ZAR.mjs';
|
|
2
|
-
import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, l as textDecoder, e as base64UrlDecode, m as isJWKSet, n as decodePayloadFromB64UrlSegment, o as validateCriticalHeadersJWS, h as validateJwtClaims } from './unjwt.Be8NxwFK.mjs';
|
|
3
|
-
|
|
4
|
-
async function sign(payload, key, options = {}) {
|
|
5
|
-
const { protectedHeader: additionalProtectedHeader } = options;
|
|
6
|
-
const safeAdditionalHeader = sanitizeObject(
|
|
7
|
-
additionalProtectedHeader
|
|
8
|
-
);
|
|
9
|
-
let { alg } = options;
|
|
10
|
-
if (!alg) {
|
|
11
|
-
if (isJWK(key) && key.alg) {
|
|
12
|
-
alg = key.alg;
|
|
13
|
-
} else {
|
|
14
|
-
throw new TypeError('JWS "alg" (Algorithm) must be provided in options');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
validateKeyLength(key, alg);
|
|
18
|
-
const signingKey = await importKey(key, alg);
|
|
19
|
-
const protectedHeader = {
|
|
20
|
-
...safeAdditionalHeader,
|
|
21
|
-
...isJWK(key) && key.kid ? { kid: key.kid } : {},
|
|
22
|
-
// Include kid if available
|
|
23
|
-
alg,
|
|
24
|
-
typ: safeAdditionalHeader?.typ
|
|
25
|
-
};
|
|
26
|
-
applyTypCtyDefaults(protectedHeader, payload);
|
|
27
|
-
if (protectedHeader.b64 === true) {
|
|
28
|
-
delete protectedHeader.b64;
|
|
29
|
-
}
|
|
30
|
-
const computedPayload = computeJwtTimeClaims(
|
|
31
|
-
payload,
|
|
32
|
-
protectedHeader.typ,
|
|
33
|
-
options.expiresIn,
|
|
34
|
-
options.currentDate
|
|
35
|
-
);
|
|
36
|
-
const protectedHeaderString = JSON.stringify(protectedHeader);
|
|
37
|
-
const protectedHeaderEncoded = base64UrlEncode(protectedHeaderString);
|
|
38
|
-
let payloadBytes;
|
|
39
|
-
if (payload instanceof Uint8Array) {
|
|
40
|
-
payloadBytes = payload;
|
|
41
|
-
} else if (typeof payload === "string") {
|
|
42
|
-
payloadBytes = textEncoder.encode(payload);
|
|
43
|
-
} else if (typeof payload === "object" && payload !== null) {
|
|
44
|
-
payloadBytes = textEncoder.encode(
|
|
45
|
-
JSON.stringify(computedPayload || payload)
|
|
46
|
-
);
|
|
47
|
-
} else {
|
|
48
|
-
throw new TypeError(
|
|
49
|
-
"Payload must be a string, Uint8Array, or a JSON-serializable object."
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
const useB64 = protectedHeader.b64 !== false;
|
|
53
|
-
const payloadEncoded = useB64 ? base64UrlEncode(payloadBytes) : textDecoder.decode(payloadBytes);
|
|
54
|
-
const signingInputString = `${protectedHeaderEncoded}.${payloadEncoded}`;
|
|
55
|
-
const signingInputBytes = textEncoder.encode(signingInputString);
|
|
56
|
-
const signatureBytes = await sign$1(alg, signingKey, signingInputBytes);
|
|
57
|
-
const signatureEncoded = base64UrlEncode(signatureBytes);
|
|
58
|
-
return `${signingInputString}.${signatureEncoded}`;
|
|
59
|
-
}
|
|
60
|
-
async function verify(jws, key, options = {}) {
|
|
61
|
-
const parts = jws.split(".");
|
|
62
|
-
if (parts.length !== 3) {
|
|
63
|
-
throw new Error("Invalid JWS: Must contain three parts separated by dots.");
|
|
64
|
-
}
|
|
65
|
-
const [protectedHeaderEncoded, payloadEncoded, signatureEncoded] = parts;
|
|
66
|
-
let protectedHeader;
|
|
67
|
-
try {
|
|
68
|
-
const protectedHeaderString = base64UrlDecode(protectedHeaderEncoded);
|
|
69
|
-
protectedHeader = sanitizeObject(
|
|
70
|
-
JSON.parse(protectedHeaderString)
|
|
71
|
-
);
|
|
72
|
-
} catch (error_) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Invalid JWS: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
if (!protectedHeader || typeof protectedHeader !== "object" || !protectedHeader.alg) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
'Invalid JWS: Protected header must be an object with an "alg" property.'
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const alg = protectedHeader.alg;
|
|
83
|
-
if (options.algorithms && !options.algorithms.includes(alg)) {
|
|
84
|
-
throw new Error(`Algorithm not allowed: ${alg}`);
|
|
85
|
-
}
|
|
86
|
-
if (options.typ && protectedHeader.typ !== options.typ) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
`Invalid JWS: "typ" (Type) Header Parameter mismatch. Expected "${options.typ}", got "${protectedHeader.typ}".`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
let signatureBytes;
|
|
92
|
-
try {
|
|
93
|
-
signatureBytes = base64UrlDecode(signatureEncoded, false);
|
|
94
|
-
} catch (error_) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
`Invalid JWS: Signature is not valid Base64URL (${error_ instanceof Error ? error_.message : error_})`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const keyInput = typeof key === "function" ? await key(protectedHeader, jws) : key;
|
|
100
|
-
const resolvedKey = isJWKSet(keyInput) ? getJWKFromSet(keyInput, protectedHeader) : keyInput;
|
|
101
|
-
const verificationKey = await importKey(resolvedKey, alg);
|
|
102
|
-
const signingInputString = `${protectedHeaderEncoded}.${payloadEncoded}`;
|
|
103
|
-
const signingInputBytes = textEncoder.encode(signingInputString);
|
|
104
|
-
const isValid = await verify$1(
|
|
105
|
-
alg,
|
|
106
|
-
verificationKey,
|
|
107
|
-
signatureBytes,
|
|
108
|
-
signingInputBytes
|
|
109
|
-
);
|
|
110
|
-
if (!isValid) {
|
|
111
|
-
throw new Error("JWS signature verification failed.");
|
|
112
|
-
}
|
|
113
|
-
const useB64 = protectedHeader.b64 !== false;
|
|
114
|
-
let payload;
|
|
115
|
-
try {
|
|
116
|
-
payload = useB64 ? decodePayloadFromB64UrlSegment(
|
|
117
|
-
payloadEncoded,
|
|
118
|
-
protectedHeader,
|
|
119
|
-
options.forceUint8Array
|
|
120
|
-
) : options.forceUint8Array ? textEncoder.encode(payloadEncoded) : payloadEncoded;
|
|
121
|
-
} catch (error_) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
`Invalid JWS: Payload decoding failed (${error_ instanceof Error ? error_.message : error_})`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
validateCriticalHeadersJWS(protectedHeader, [
|
|
127
|
-
...options.critical || [],
|
|
128
|
-
...options.requiredHeaders || []
|
|
129
|
-
]);
|
|
130
|
-
if (payload && typeof payload === "object" && options.validateJWT !== false && (options.validateJWT === true || protectedHeader.typ?.toLowerCase().includes("jwt")) && !options.forceUint8Array && !(payload instanceof Uint8Array)) {
|
|
131
|
-
validateJwtClaims(payload, options);
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
payload,
|
|
135
|
-
protectedHeader
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function validateKeyLength(key, alg) {
|
|
139
|
-
if (!alg || isJWK(key)) return;
|
|
140
|
-
if (alg.startsWith("HS") && key instanceof Uint8Array) {
|
|
141
|
-
const algLength = Number.parseInt(alg.slice(2)) / 8;
|
|
142
|
-
if (key.length < algLength) {
|
|
143
|
-
throw new TypeError(
|
|
144
|
-
`${alg} requires key length to be ${algLength} bytes or larger`
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
} else if ((alg.startsWith("RS") || alg.startsWith("PS")) && key instanceof CryptoKey) {
|
|
148
|
-
const { modulusLength } = key.algorithm;
|
|
149
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
150
|
-
throw new TypeError(
|
|
151
|
-
`${alg} requires key modulusLength to be 2048 bits or larger`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const jws = {
|
|
158
|
-
__proto__: null,
|
|
159
|
-
sign: sign,
|
|
160
|
-
verify: verify
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export { jws as j, sign as s, verify as v };
|