unjwt 0.8.4 → 0.8.5
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 -9
- package/dist/_chunks/{_import-key.mjs → algorithms.mjs} +194 -399
- package/dist/_chunks/{_codec-jwe.d.mts → codec-jwe.d.mts} +40 -9
- package/dist/_chunks/{_codec-jws.mjs → codec-jws.mjs} +133 -80
- package/dist/_chunks/cookie.mjs +50 -0
- package/dist/_chunks/digest.mjs +10 -3
- package/dist/_chunks/error.d.mts +103 -0
- package/dist/_chunks/export.mjs +97 -0
- package/dist/_chunks/index.d.mts +5 -103
- package/dist/_chunks/index2.d.mts +206 -12
- package/dist/_chunks/index3.d.mts +12 -109
- package/dist/_chunks/{jwe.d.mts → index4.d.mts} +2 -1
- package/dist/_chunks/{jws.d.mts → index5.d.mts} +2 -1
- package/dist/_chunks/index6.d.mts +113 -0
- package/dist/_chunks/jwe.mjs +205 -72
- package/dist/{core → _chunks}/jwk.mjs +210 -495
- package/dist/_chunks/jws.mjs +280 -193
- package/dist/_chunks/jwt.d.mts +2 -1
- package/dist/_chunks/{_jwt-internal.mjs → jwt.mjs} +110 -54
- package/dist/_chunks/libs/unsecure.d.mts +35 -25
- package/dist/_chunks/libs/unsecure.mjs +101 -268
- package/dist/_chunks/{_internal.d.mts → limits.d.mts} +1 -1
- package/dist/_chunks/payload.mjs +23 -0
- package/dist/_chunks/wrap.mjs +209 -0
- package/dist/adapters/elysia/index.d.mts +4 -4
- package/dist/adapters/elysia/index.mjs +4 -3
- package/dist/adapters/h3/index.d.mts +13 -13
- package/dist/adapters/h3/index.mjs +8 -11
- package/dist/adapters/h3v1/index.d.mts +5 -5
- package/dist/adapters/h3v1/index.mjs +6 -9
- package/dist/core/internal.mjs +1 -1
- package/dist/core/{jwe.d.mts → jwe/index.d.mts} +5 -4
- package/dist/core/jwe/index.mjs +5 -0
- package/dist/core/{jwk.d.mts → jwk/index.d.mts} +5 -4
- package/dist/core/jwk/index.mjs +7 -0
- package/dist/core/{jws.d.mts → jws/index.d.mts} +5 -4
- package/dist/core/jws/index.mjs +5 -0
- package/dist/dpop/index.d.mts +73 -0
- package/dist/dpop/index.mjs +296 -0
- package/dist/error.d.mts +3 -0
- package/dist/error.mjs +20 -0
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +7 -4
- package/dist/session/index.d.mts +4 -4
- package/dist/session/index.mjs +6 -47
- package/dist/utils/index.d.mts +7 -0
- package/dist/{core/utils → utils}/index.mjs +4 -3
- package/package.json +21 -10
- package/dist/_chunks/jwk.d.mts +0 -205
- package/dist/core/jwe.mjs +0 -5
- package/dist/core/jws.mjs +0 -5
- package/dist/core/utils/index.d.mts +0 -6
- /package/dist/_chunks/{_cookie-attributes.d.mts → cookie-attributes.d.mts} +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { JWTError } from "../error.mjs";
|
|
2
|
+
import { assertPlainObject, isCryptoKey } from "./jwt.mjs";
|
|
3
|
+
import { MAX_PARTY_INFO_BYTES, aesKwUnwrap, aesKwWrap, asDecryptionError, assertDirectKeyRole, assertECDHKeyAllowed, assertJWEEncSupported, assertOctKeyLength, assertPBES2Params, bitLengthIV, bitLengthTag, buildECDHAgreementParams, decodeSegment, decryptRSAES, deriveECDHESKey, ecdhDerivedBits, ecdhesWrap, encryptRSAES, gcmkwDecrypt, gcmkwEncrypt, importKey, normalizeEpk, pbes2Unwrap, pbes2Wrap, resolvePasswordKey } from "./algorithms.mjs";
|
|
4
|
+
import { aesBitsOf, innerKeyWrapAlg } from "./digest.mjs";
|
|
5
|
+
function inferAesImportAlgorithm(enc, cekLengthBytes) {
|
|
6
|
+
const bitLength = cekLengthBytes << 3;
|
|
7
|
+
if (enc) {
|
|
8
|
+
if (enc.includes("GCM")) return {
|
|
9
|
+
name: "AES-GCM",
|
|
10
|
+
length: aesBitsOf(enc)
|
|
11
|
+
};
|
|
12
|
+
if (enc.includes("CBC-HS")) return;
|
|
13
|
+
}
|
|
14
|
+
if (bitLength === 128 || bitLength === 192 || bitLength === 256) return {
|
|
15
|
+
name: "AES-GCM",
|
|
16
|
+
length: bitLength
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function assertWrappableCEK(cek, alg) {
|
|
20
|
+
if (cek.length >= 16 && cek.length % 8 === 0) return;
|
|
21
|
+
throw new JWTError(`${alg} wraps a key of 16 or more bytes in whole 8-byte blocks (got ${cek.length}).`, "ERR_INVALID_OPTION");
|
|
22
|
+
}
|
|
23
|
+
async function unwrapping(operation) {
|
|
24
|
+
try {
|
|
25
|
+
return await operation;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw asDecryptionError(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function assertKeyBytesArg(value, name) {
|
|
31
|
+
if (value instanceof Uint8Array || isCryptoKey(value)) return;
|
|
32
|
+
throw new JWTError(`"${name}" must be a Uint8Array or a CryptoKey.`, "ERR_INVALID_OPTION");
|
|
33
|
+
}
|
|
34
|
+
function assertPartyInfoLength(name, bytes) {
|
|
35
|
+
if (bytes.length > 1024) throw new JWTError(`Invalid JWE: "${name}" must not exceed ${MAX_PARTY_INFO_BYTES} bytes (got ${bytes.length}).`, "ERR_JWE_INVALID");
|
|
36
|
+
}
|
|
37
|
+
function assertKeyWrapSegmentLength(name, bytes, expected, alg) {
|
|
38
|
+
if (bytes.length !== expected) throw new JWTError(`Invalid JWE: "${name}" must be ${expected} bytes for ${alg} (got ${bytes.length}).`, "ERR_JWE_INVALID");
|
|
39
|
+
}
|
|
40
|
+
function assertCryptoKeyFor(alg, key, role) {
|
|
41
|
+
if (isCryptoKey(key)) return;
|
|
42
|
+
throw new JWTError(`${alg} requires the ${role} key to be a CryptoKey`, "ERR_JWK_INVALID");
|
|
43
|
+
}
|
|
44
|
+
function segmentBytes(value, name) {
|
|
45
|
+
return typeof value === "string" ? decodeSegment(value, {
|
|
46
|
+
family: "JWE",
|
|
47
|
+
what: `"${name}"`
|
|
48
|
+
}) : value;
|
|
49
|
+
}
|
|
50
|
+
async function wrapKey(keyToWrap, wrappingKey, options) {
|
|
51
|
+
assertPlainObject(options, "options");
|
|
52
|
+
assertKeyBytesArg(keyToWrap, "keyToWrap");
|
|
53
|
+
const { alg } = options;
|
|
54
|
+
const cekBytes = keyToWrap instanceof Uint8Array ? keyToWrap : new Uint8Array(await crypto.subtle.exportKey("raw", keyToWrap));
|
|
55
|
+
if (alg.endsWith("KW")) assertWrappableCEK(cekBytes, alg);
|
|
56
|
+
if (alg.startsWith("PBES2")) assertPBES2Params({
|
|
57
|
+
p2s: options.p2s,
|
|
58
|
+
p2c: options.p2c
|
|
59
|
+
});
|
|
60
|
+
const importedWrappingKey = await importKey(resolvePasswordKey(alg, wrappingKey), {
|
|
61
|
+
alg,
|
|
62
|
+
expect: "public"
|
|
63
|
+
});
|
|
64
|
+
switch (alg) {
|
|
65
|
+
case "dir": return { encryptedKey: /* @__PURE__ */ new Uint8Array(0) };
|
|
66
|
+
case "A128KW":
|
|
67
|
+
case "A192KW":
|
|
68
|
+
case "A256KW": return { encryptedKey: await aesKwWrap(alg, importedWrappingKey, cekBytes) };
|
|
69
|
+
case "PBES2-HS256+A128KW":
|
|
70
|
+
case "PBES2-HS384+A192KW":
|
|
71
|
+
case "PBES2-HS512+A256KW": {
|
|
72
|
+
const { p2s, p2c } = options;
|
|
73
|
+
if (!p2s || typeof p2c !== "number") throw new JWTError("PBES2 requires 'p2s' (salt) and 'p2c' (count) options", "ERR_JWE_INVALID");
|
|
74
|
+
return pbes2Wrap(alg, importedWrappingKey, cekBytes, p2c, p2s);
|
|
75
|
+
}
|
|
76
|
+
case "A128GCMKW":
|
|
77
|
+
case "A192GCMKW":
|
|
78
|
+
case "A256GCMKW": {
|
|
79
|
+
const { encryptedKey, iv, tag } = await gcmkwEncrypt(alg, importedWrappingKey, cekBytes, options.iv);
|
|
80
|
+
return {
|
|
81
|
+
encryptedKey,
|
|
82
|
+
iv,
|
|
83
|
+
tag
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
case "RSA-OAEP":
|
|
87
|
+
case "RSA-OAEP-256":
|
|
88
|
+
case "RSA-OAEP-384":
|
|
89
|
+
case "RSA-OAEP-512":
|
|
90
|
+
assertCryptoKeyFor(alg, importedWrappingKey, "wrapping");
|
|
91
|
+
return { encryptedKey: await encryptRSAES(alg, importedWrappingKey, cekBytes) };
|
|
92
|
+
case "ECDH-ES":
|
|
93
|
+
case "ECDH-ES+A128KW":
|
|
94
|
+
case "ECDH-ES+A192KW":
|
|
95
|
+
case "ECDH-ES+A256KW": {
|
|
96
|
+
assertCryptoKeyFor(alg, importedWrappingKey, "wrapping");
|
|
97
|
+
const enc = options.ecdh?.enc;
|
|
98
|
+
if (enc !== void 0) assertJWEEncSupported(enc);
|
|
99
|
+
if (alg === "ECDH-ES" && !enc) throw new JWTError("ECDH-ES direct key agreement requires options.ecdh.enc", "ERR_JWK_INVALID");
|
|
100
|
+
const { encryptedKey, parameters } = await ecdhesWrap(alg, {
|
|
101
|
+
enc,
|
|
102
|
+
recipientKey: importedWrappingKey,
|
|
103
|
+
cek: cekBytes,
|
|
104
|
+
parameters: buildECDHAgreementParams(options.ecdh)
|
|
105
|
+
});
|
|
106
|
+
const wrapResult = {
|
|
107
|
+
encryptedKey: encryptedKey ?? /* @__PURE__ */ new Uint8Array(0),
|
|
108
|
+
epk: parameters.epk
|
|
109
|
+
};
|
|
110
|
+
if (parameters.apu) wrapResult.apu = parameters.apu;
|
|
111
|
+
if (parameters.apv) wrapResult.apv = parameters.apv;
|
|
112
|
+
return wrapResult;
|
|
113
|
+
}
|
|
114
|
+
default: throw new JWTError(`Unsupported key wrapping algorithm: ${alg}`, "ERR_JWK_UNSUPPORTED");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function unwrapKey(wrappedKey, unwrappingKey, options) {
|
|
118
|
+
assertPlainObject(options, "options");
|
|
119
|
+
if (!(wrappedKey instanceof Uint8Array)) throw new JWTError("\"wrappedKey\" must be a Uint8Array.", "ERR_INVALID_OPTION");
|
|
120
|
+
const { alg } = options;
|
|
121
|
+
const returnRaw = options.format === "raw";
|
|
122
|
+
const defaultExtractable = options.extractable !== false;
|
|
123
|
+
const importedUnwrappingKey = await importKey(resolvePasswordKey(alg, unwrappingKey), {
|
|
124
|
+
alg,
|
|
125
|
+
expect: "private"
|
|
126
|
+
});
|
|
127
|
+
let unwrappedCekBytes;
|
|
128
|
+
switch (alg) {
|
|
129
|
+
case "dir":
|
|
130
|
+
assertDirectKeyRole(unwrappingKey, options.enc);
|
|
131
|
+
if (importedUnwrappingKey instanceof Uint8Array) {
|
|
132
|
+
assertOctKeyLength(importedUnwrappingKey, options.enc);
|
|
133
|
+
unwrappedCekBytes = importedUnwrappingKey;
|
|
134
|
+
} else {
|
|
135
|
+
if (!returnRaw) return importedUnwrappingKey;
|
|
136
|
+
unwrappedCekBytes = new Uint8Array(await crypto.subtle.exportKey("raw", importedUnwrappingKey));
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
case "A128KW":
|
|
140
|
+
case "A192KW":
|
|
141
|
+
case "A256KW":
|
|
142
|
+
unwrappedCekBytes = await unwrapping(aesKwUnwrap(alg, importedUnwrappingKey, wrappedKey));
|
|
143
|
+
break;
|
|
144
|
+
case "PBES2-HS256+A128KW":
|
|
145
|
+
case "PBES2-HS384+A192KW":
|
|
146
|
+
case "PBES2-HS512+A256KW": {
|
|
147
|
+
const { p2s, p2c, minIterations, maxIterations } = options;
|
|
148
|
+
if (!p2s || typeof p2c !== "number") throw new JWTError("PBES2 requires 'p2s' (salt) and 'p2c' (count) options", "ERR_JWE_INVALID");
|
|
149
|
+
const p2sBytes = segmentBytes(p2s, "p2s");
|
|
150
|
+
unwrappedCekBytes = await unwrapping(pbes2Unwrap(alg, importedUnwrappingKey, wrappedKey, p2c, p2sBytes, minIterations, maxIterations));
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "A128GCMKW":
|
|
154
|
+
case "A192GCMKW":
|
|
155
|
+
case "A256GCMKW": {
|
|
156
|
+
if (!options.iv || !options.tag) throw new JWTError("AES-GCMKW requires 'iv' and 'tag' options for unwrapping", "ERR_JWE_INVALID");
|
|
157
|
+
const ivBytes = segmentBytes(options.iv, "iv");
|
|
158
|
+
const tagBytes = segmentBytes(options.tag, "tag");
|
|
159
|
+
assertKeyWrapSegmentLength("iv", ivBytes, bitLengthIV(alg) >> 3, alg);
|
|
160
|
+
assertKeyWrapSegmentLength("tag", tagBytes, bitLengthTag(alg) >> 3, alg);
|
|
161
|
+
unwrappedCekBytes = await unwrapping(gcmkwDecrypt(alg, importedUnwrappingKey, wrappedKey, ivBytes, tagBytes));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "RSA-OAEP":
|
|
165
|
+
case "RSA-OAEP-256":
|
|
166
|
+
case "RSA-OAEP-384":
|
|
167
|
+
case "RSA-OAEP-512": {
|
|
168
|
+
assertCryptoKeyFor(alg, importedUnwrappingKey, "unwrapping");
|
|
169
|
+
unwrappedCekBytes = await unwrapping(decryptRSAES(alg, importedUnwrappingKey, wrappedKey));
|
|
170
|
+
if (returnRaw) break;
|
|
171
|
+
const inferredAlgorithm = options.unwrappedKeyAlgorithm || inferAesImportAlgorithm(options.enc, unwrappedCekBytes.length);
|
|
172
|
+
if (!inferredAlgorithm) throw new JWTError("Cannot infer the RSA-OAEP unwrapped key algorithm, pass \"unwrappedKeyAlgorithm\".", "ERR_JWE_INVALID");
|
|
173
|
+
const keyUsages = options.keyUsage || ["encrypt", "decrypt"];
|
|
174
|
+
return await crypto.subtle.importKey("raw", unwrappedCekBytes, inferredAlgorithm, defaultExtractable, keyUsages);
|
|
175
|
+
}
|
|
176
|
+
case "ECDH-ES":
|
|
177
|
+
case "ECDH-ES+A128KW":
|
|
178
|
+
case "ECDH-ES+A192KW":
|
|
179
|
+
case "ECDH-ES+A256KW": {
|
|
180
|
+
if (!options.epk) throw new JWTError("ECDH-ES requires 'epk' option", "ERR_JWE_INVALID");
|
|
181
|
+
assertCryptoKeyFor(alg, importedUnwrappingKey, "unwrapping");
|
|
182
|
+
assertECDHKeyAllowed(importedUnwrappingKey);
|
|
183
|
+
const epkCandidate = await normalizeEpk(options.epk, {
|
|
184
|
+
alg,
|
|
185
|
+
recipientKey: importedUnwrappingKey
|
|
186
|
+
});
|
|
187
|
+
const apuBytes = segmentBytes(options.apu ?? /* @__PURE__ */ new Uint8Array(0), "apu");
|
|
188
|
+
const apvBytes = segmentBytes(options.apv ?? /* @__PURE__ */ new Uint8Array(0), "apv");
|
|
189
|
+
assertPartyInfoLength("apu", apuBytes);
|
|
190
|
+
assertPartyInfoLength("apv", apvBytes);
|
|
191
|
+
if (options.enc !== void 0) assertJWEEncSupported(options.enc);
|
|
192
|
+
const infoAlg = alg === "ECDH-ES" ? options.enc : alg;
|
|
193
|
+
if (!infoAlg) throw new JWTError("ECDH-ES requires 'enc' to derive the shared secret", "ERR_JWE_INVALID");
|
|
194
|
+
const keyLength = ecdhDerivedBits(alg, options.enc);
|
|
195
|
+
const sharedSecret = await unwrapping(deriveECDHESKey(epkCandidate, importedUnwrappingKey, infoAlg, keyLength, apuBytes, apvBytes));
|
|
196
|
+
if (alg === "ECDH-ES") unwrappedCekBytes = sharedSecret;
|
|
197
|
+
else {
|
|
198
|
+
const kwAlg = innerKeyWrapAlg(alg);
|
|
199
|
+
if (!(wrappedKey instanceof Uint8Array) || wrappedKey.length === 0) throw new JWTError("ECDH-ES key agreement with key wrapping requires an encrypted key", "ERR_JWE_INVALID");
|
|
200
|
+
unwrappedCekBytes = await unwrapping(aesKwUnwrap(kwAlg, sharedSecret, wrappedKey));
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
default: throw new JWTError(`Unsupported key unwrapping algorithm: ${alg}`, "ERR_JWK_UNSUPPORTED");
|
|
205
|
+
}
|
|
206
|
+
if (returnRaw) return unwrappedCekBytes;
|
|
207
|
+
return await crypto.subtle.importKey("raw", unwrappedCekBytes, options.unwrappedKeyAlgorithm || { name: "AES-GCM" }, defaultExtractable, options.keyUsage || ["encrypt", "decrypt"]);
|
|
208
|
+
}
|
|
209
|
+
export { unwrapKey, wrapKey };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/
|
|
2
|
-
import { CookieAttributes } from "../../_chunks/
|
|
1
|
+
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/codec-jwe.mjs";
|
|
2
|
+
import { CookieAttributes } from "../../_chunks/cookie-attributes.mjs";
|
|
3
3
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/index2.mjs";
|
|
5
|
+
import { thumbprint } from "../../_chunks/index3.mjs";
|
|
6
6
|
import { Elysia } from "elysia";
|
|
7
7
|
interface ChunkableCookie {
|
|
8
8
|
value: unknown;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { thumbprint } from "../../_chunks/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/algorithms.mjs";
|
|
2
|
+
import { toPublicJWK } from "../../_chunks/export.mjs";
|
|
3
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../../_chunks/jwk.mjs";
|
|
4
|
+
import { createJWECodec, createJWSCodec, defineSession, invalidConfigError } from "../../_chunks/codec-jws.mjs";
|
|
4
5
|
import { Elysia } from "elysia";
|
|
5
6
|
function sessionPlugin(options) {
|
|
6
7
|
const contextKey = options.contextKey ?? "session";
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/
|
|
1
|
+
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/codec-jwe.mjs";
|
|
2
2
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/index2.mjs";
|
|
4
|
+
import { thumbprint } from "../../_chunks/index3.mjs";
|
|
5
5
|
import { HTTPEvent, setCookie } from "h3";
|
|
6
6
|
type CookieSerializeOptions = NonNullable<Parameters<typeof setCookie>[3]>;
|
|
7
7
|
/**
|
|
8
8
|
* Session state for the current request, mirroring the claims of its JWE token.
|
|
9
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
9
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
10
10
|
*/
|
|
11
11
|
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
12
12
|
/**
|
|
13
13
|
* JWE session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token.
|
|
14
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
14
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
15
15
|
*/
|
|
16
16
|
interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
17
17
|
event: TEvent;
|
|
18
18
|
}, SessionConfigJWE<T, MaxAge, TEvent>> {}
|
|
19
19
|
/**
|
|
20
20
|
* Configuration for a JWE-backed (encrypted) session.
|
|
21
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
21
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
22
22
|
*/
|
|
23
23
|
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionConfig<MaxAge, CookieSerializeOptions> {
|
|
24
24
|
/** Cookie and session-header name. Default `"h3-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
@@ -27,7 +27,7 @@ interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge exten
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Defines a JWE (encrypted) session once; its `use`, `token`, `issue` and `open` serve every request.
|
|
30
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
30
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
31
31
|
*/
|
|
32
32
|
export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(config: SessionConfigJWE<T, MaxAge, TEvent>): SessionDefinition<T, MaxAge, TEvent>;
|
|
33
33
|
/**
|
|
@@ -41,7 +41,7 @@ export declare function useJWESession<T extends SessionRecord = SessionClaims, M
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function getJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionJWE<T, MaxAge>>;
|
|
43
43
|
/**
|
|
44
|
-
* Read the raw session token:
|
|
44
|
+
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
45
45
|
* @deprecated Use `defineJWESession(config).token(event)`.
|
|
46
46
|
*/
|
|
47
47
|
export declare function getJWESessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): string | undefined;
|
|
@@ -70,19 +70,19 @@ export declare function unsealJWESession<T extends SessionRecord = SessionClaims
|
|
|
70
70
|
export declare function clearJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<void>;
|
|
71
71
|
/**
|
|
72
72
|
* Session state for the current request, mirroring the claims of its JWS token.
|
|
73
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
73
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
74
74
|
*/
|
|
75
75
|
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
76
76
|
/**
|
|
77
77
|
* JWS session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token.
|
|
78
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
78
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
79
79
|
*/
|
|
80
80
|
interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
81
81
|
event: TEvent;
|
|
82
82
|
}, SessionConfigJWS<T, MaxAge, TEvent>> {}
|
|
83
83
|
/**
|
|
84
84
|
* Configuration for a JWS-backed (signed, not encrypted) session.
|
|
85
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
85
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
86
86
|
*/
|
|
87
87
|
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionConfig<MaxAge, CookieSerializeOptions> {
|
|
88
88
|
/** Cookie and session-header name. Default `"h3-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
@@ -91,7 +91,7 @@ interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge exten
|
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Defines a JWS (signed, not encrypted) session once, its data readable by clients; `use`, `token`, `issue` and `open` serve every request.
|
|
94
|
-
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is
|
|
94
|
+
* @deprecated `unjwt/adapters/h3` (and `h3v2`) is removed in 0.9.0. `unjwt/session` takes the h3 v2 event as it is and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
95
95
|
*/
|
|
96
96
|
export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(config: SessionConfigJWS<T, MaxAge, TEvent>): SessionDefinition<T, MaxAge, TEvent>;
|
|
97
97
|
/**
|
|
@@ -105,7 +105,7 @@ export declare function useJWSSession<T extends SessionRecord = SessionClaims, M
|
|
|
105
105
|
*/
|
|
106
106
|
export declare function getJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionJWS<T, MaxAge>>;
|
|
107
107
|
/**
|
|
108
|
-
* Read the raw session token:
|
|
108
|
+
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
109
109
|
* @deprecated Use `defineJWSSession(config).token(event)`.
|
|
110
110
|
*/
|
|
111
111
|
export declare function getJWSSessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): string | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { thumbprint } from "../../_chunks/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/algorithms.mjs";
|
|
2
|
+
import { toPublicJWK } from "../../_chunks/export.mjs";
|
|
3
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../../_chunks/jwk.mjs";
|
|
4
|
+
import { bindSession, createJWECodec, createJWSCodec, defineSession, dropSession, encodeSession, issueSession, loadSession, mirrorSetCookie, openSessionToken, sessionActions, setCookieValues } from "../../_chunks/codec-jws.mjs";
|
|
4
5
|
import { getCookie, getEventContext, setCookie } from "h3";
|
|
5
6
|
const PREFIX = "[unjwt/h3]";
|
|
6
7
|
const h3SessionDriver = {
|
|
@@ -15,20 +16,16 @@ function responseCookieJar(event) {
|
|
|
15
16
|
written: (name) => setCookieValues(event.res.headers.getSetCookie())[name],
|
|
16
17
|
write: (name, value, attrs) => {
|
|
17
18
|
setCookie(event, name, value, attrs);
|
|
18
|
-
|
|
19
|
+
mirrorSetCookie(name, {
|
|
20
|
+
from: event.res.headers,
|
|
21
|
+
to: event.res.errHeaders
|
|
22
|
+
});
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
function hasResponse(event) {
|
|
23
27
|
return "res" in event && Boolean(event.res);
|
|
24
28
|
}
|
|
25
|
-
function stageErrCookie(event, cookieName) {
|
|
26
|
-
const isThisCookie = (cookie) => setCookieName(cookie) === cookieName;
|
|
27
|
-
const errHeaders = event.res.errHeaders;
|
|
28
|
-
const staged = [...errHeaders.getSetCookie().filter((cookie) => !isThisCookie(cookie)), ...event.res.headers.getSetCookie().filter((cookie) => isThisCookie(cookie))];
|
|
29
|
-
errHeaders.delete("set-cookie");
|
|
30
|
-
for (const cookie of staged) errHeaders.append("set-cookie", cookie);
|
|
31
|
-
}
|
|
32
29
|
const codec$1 = createJWECodec({
|
|
33
30
|
prefix: PREFIX,
|
|
34
31
|
defaultName: "h3-jwe"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/
|
|
1
|
+
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/codec-jwe.mjs";
|
|
2
2
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/index2.mjs";
|
|
4
|
+
import { thumbprint } from "../../_chunks/index3.mjs";
|
|
5
5
|
import { H3Event, H3EventContext, setCookie } from "h3";
|
|
6
6
|
type CookieSerializeOptions = NonNullable<Parameters<typeof setCookie>[3]>;
|
|
7
7
|
/**
|
|
@@ -54,7 +54,7 @@ export declare function useJWESession<T extends SessionRecord = SessionClaims, M
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function getJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionJWE<T, MaxAge>>;
|
|
56
56
|
/**
|
|
57
|
-
* Read the raw session token:
|
|
57
|
+
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
58
58
|
* @deprecated Use `defineJWESession(config).token(event)`.
|
|
59
59
|
*/
|
|
60
60
|
export declare function getJWESessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): string | undefined;
|
|
@@ -118,7 +118,7 @@ export declare function useJWSSession<T extends SessionRecord = SessionClaims, M
|
|
|
118
118
|
*/
|
|
119
119
|
export declare function getJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionJWS<T, MaxAge>>;
|
|
120
120
|
/**
|
|
121
|
-
* Read the raw session token:
|
|
121
|
+
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
122
122
|
* @deprecated Use `defineJWSSession(config).token(event)`.
|
|
123
123
|
*/
|
|
124
124
|
export declare function getJWSSessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): string | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { thumbprint } from "../../_chunks/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/algorithms.mjs";
|
|
2
|
+
import { toPublicJWK } from "../../_chunks/export.mjs";
|
|
3
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../../_chunks/jwk.mjs";
|
|
4
|
+
import { bindSession, createJWECodec, createJWSCodec, defineSession, dropSession, encodeSession, issueSession, loadSession, openSessionToken, sessionActions, setCookieValues } from "../../_chunks/codec-jws.mjs";
|
|
5
|
+
import { requestCookies } from "../../_chunks/cookie.mjs";
|
|
5
6
|
import { getCookie, getRequestHeader, getResponseHeader, isEvent, setCookie } from "h3";
|
|
6
7
|
function responseSetCookies(event) {
|
|
7
8
|
const value = getResponseHeader(event, "set-cookie");
|
|
@@ -27,7 +28,7 @@ function eventJar(event) {
|
|
|
27
28
|
}
|
|
28
29
|
function compatJar(event) {
|
|
29
30
|
let cookies;
|
|
30
|
-
return { read: (name) => (cookies ||=
|
|
31
|
+
return { read: (name) => (cookies ||= requestCookies(compatHeaders(event)))[name] };
|
|
31
32
|
}
|
|
32
33
|
function requestHeader(event, name) {
|
|
33
34
|
const value = getRequestHeader(event, name);
|
|
@@ -36,10 +37,6 @@ function requestHeader(event, name) {
|
|
|
36
37
|
function compatHeaders(event) {
|
|
37
38
|
return "request" in event ? event.request.headers : event.headers;
|
|
38
39
|
}
|
|
39
|
-
function compatCookies(event) {
|
|
40
|
-
const header = compatHeaders(event).get("cookie");
|
|
41
|
-
return header ? parse(header) : Object.create(null);
|
|
42
|
-
}
|
|
43
40
|
const codec$1 = createJWECodec({
|
|
44
41
|
prefix: PREFIX,
|
|
45
42
|
defaultName: "h3-jwe"
|
package/dist/core/internal.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { applyTypDefault, assertCritShape, computeJwtTimeClaims, expiredClaimMessage, getPlaintextBytes, parsePayloadBytes, parsePayloadSegment, parsePayloadText, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "../_chunks/
|
|
1
|
+
export { applyTypDefault, assertCritShape, computeJwtTimeClaims, expiredClaimMessage, getPlaintextBytes, parsePayloadBytes, parsePayloadSegment, parsePayloadText, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "../_chunks/jwt.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { UnsecureError, UnsecureErrorCode } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { UnsecureError, UnsecureErrorCode } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, isJWTError, isUnsecureError } from "../../_chunks/error.mjs";
|
|
3
|
+
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, PayloadOf } from "../../_chunks/index.mjs";
|
|
4
|
+
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../../_chunks/index4.mjs";
|
|
5
|
+
import { DEFAULT_JOSE_LIMITS } from "../../_chunks/limits.mjs";
|
|
5
6
|
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyLookup, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UnsecureError } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, isJWTError, isUnsecureError } from "../../error.mjs";
|
|
3
|
+
import { DEFAULT_JOSE_LIMITS } from "../../_chunks/algorithms.mjs";
|
|
4
|
+
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../../_chunks/jwe.mjs";
|
|
5
|
+
export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { UnsecureError, UnsecureErrorCode } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "
|
|
1
|
+
import { UnsecureError, UnsecureErrorCode } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, isJWTError, isUnsecureError } from "../../_chunks/error.mjs";
|
|
3
|
+
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, ECDHEphemeralKeyInput, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, PEMType, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
4
|
+
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "../../_chunks/index2.mjs";
|
|
5
|
+
import { ThumbprintHash, thumbprint } from "../../_chunks/index3.mjs";
|
|
5
6
|
export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type ECDHEphemeralKeyInput, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_Algorithm, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type KnownJWTErrorCode, type PEMType, type ThumbprintHash, type ToPublicJWKReturn, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, isJWTError, isUnsecureError, thumbprint, toPublicJWK, unwrapKey, wrapKey };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UnsecureError } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, isJWTError, isUnsecureError } from "../../error.mjs";
|
|
3
|
+
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, getJWKsFromSet, importKey, thumbprint } from "../../_chunks/algorithms.mjs";
|
|
4
|
+
import { unwrapKey, wrapKey } from "../../_chunks/wrap.mjs";
|
|
5
|
+
import { exportJWK, exportKey, toPublicJWK } from "../../_chunks/export.mjs";
|
|
6
|
+
import { deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportPEM, generateJWK, generateKey, importPEM } from "../../_chunks/jwk.mjs";
|
|
7
|
+
export { JWTError, UnsecureError, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, isJWTError, isUnsecureError, thumbprint, toPublicJWK, unwrapKey, wrapKey };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { UnsecureError, UnsecureErrorCode } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { UnsecureError, UnsecureErrorCode } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, isJWTError, isUnsecureError } from "../../_chunks/error.mjs";
|
|
3
|
+
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, PayloadOf } from "../../_chunks/index.mjs";
|
|
4
|
+
import { DEFAULT_JOSE_LIMITS } from "../../_chunks/limits.mjs";
|
|
5
|
+
import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../../_chunks/index5.mjs";
|
|
5
6
|
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, generalToFlattenedJWS, isJWTError, isUnsecureError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UnsecureError } from "../../_chunks/libs/unsecure.mjs";
|
|
2
|
+
import { JWTError, isJWTError, isUnsecureError } from "../../error.mjs";
|
|
3
|
+
import { DEFAULT_JOSE_LIMITS } from "../../_chunks/algorithms.mjs";
|
|
4
|
+
import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../../_chunks/jws.mjs";
|
|
5
|
+
export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, generalToFlattenedJWS, isJWTError, isUnsecureError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { JWTError, JWTErrorCode, KnownJWTErrorCode, isJWTError } from "../_chunks/error.mjs";
|
|
2
|
+
import { JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK } from "../_chunks/index.mjs";
|
|
3
|
+
/** Closed set of supported asymmetric JWS algorithms. */
|
|
4
|
+
type DPoPAlgorithm = Exclude<JWSAlgorithm, `HS${string}`>;
|
|
5
|
+
/** The request method and absolute HTTP(S) URL; a Web Request satisfies this shape. */
|
|
6
|
+
interface DPoPTarget {
|
|
7
|
+
method: string;
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
/** Explicit signing pair; the private CryptoKey need not be extractable. */
|
|
11
|
+
type DPoPKeyPair = CryptoKeyPair | {
|
|
12
|
+
privateKey: JWSAsymmetricPrivateJWK;
|
|
13
|
+
publicKey: JWSAsymmetricPublicJWK;
|
|
14
|
+
};
|
|
15
|
+
interface DPoPPayload {
|
|
16
|
+
jti: string;
|
|
17
|
+
iat: number;
|
|
18
|
+
exp?: number;
|
|
19
|
+
nbf?: number;
|
|
20
|
+
htm: string;
|
|
21
|
+
htu: string;
|
|
22
|
+
nonce?: string;
|
|
23
|
+
ath?: string;
|
|
24
|
+
[claim: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
interface DPoPCreateOptions {
|
|
27
|
+
keyPair: DPoPKeyPair;
|
|
28
|
+
/** Inferred from JWK alg metadata or an unambiguous key shape. Required for CryptoKey pairs. */
|
|
29
|
+
algorithm?: DPoPAlgorithm;
|
|
30
|
+
/** Unique proof identifier. Defaults to a fresh UUID v4 for each proof. */
|
|
31
|
+
jti?: string;
|
|
32
|
+
/** Creation time in NumericDate seconds. Defaults to the current Unix second. */
|
|
33
|
+
iat?: number;
|
|
34
|
+
/** Expiration time in NumericDate seconds. Omitted by default. */
|
|
35
|
+
exp?: number;
|
|
36
|
+
/** Earliest acceptance time in NumericDate seconds. Omitted by default. */
|
|
37
|
+
nbf?: number;
|
|
38
|
+
nonce?: string;
|
|
39
|
+
/** Raw ASCII access token whose SHA-256 digest becomes `ath`. */
|
|
40
|
+
accessToken?: {
|
|
41
|
+
token: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface DPoPVerifyResult {
|
|
45
|
+
payload: DPoPPayload;
|
|
46
|
+
/** SHA-256 RFC 7638 thumbprint of the authenticated public key. */
|
|
47
|
+
thumbprint: string;
|
|
48
|
+
}
|
|
49
|
+
interface DPoPVerifyOptions {
|
|
50
|
+
algorithms: DPoPAlgorithm[];
|
|
51
|
+
/** Positive finite maximum proof age, in seconds. */
|
|
52
|
+
maxTokenAge: number;
|
|
53
|
+
currentDate?: Date;
|
|
54
|
+
/** Finite, non-negative clock tolerance, in seconds. Default: 0. */
|
|
55
|
+
clockTolerance?: number;
|
|
56
|
+
nonce?: string;
|
|
57
|
+
/** The raw access token and its authenticated `cnf.jkt` binding, supplied together. */
|
|
58
|
+
accessToken?: {
|
|
59
|
+
token: string;
|
|
60
|
+
thumbprint: string;
|
|
61
|
+
};
|
|
62
|
+
/** Atomically consume a validated proof; false rejects replay. No replay storage is provided. */
|
|
63
|
+
consumeProof?: (result: DPoPVerifyResult) => boolean | Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
/** Create a proof with matching private/public signing keys and optional identifier/time overrides. */
|
|
66
|
+
export declare function createDPoPProof(target: DPoPTarget, options: DPoPCreateOptions): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Authenticate and bind a proof; replay storage and access-token validation belong to the caller.
|
|
69
|
+
* A proof failure is `ERR_DPOP_INVALID` or `ERR_DPOP_CLAIM_INVALID` (a core error kept as `cause`);
|
|
70
|
+
* a missing or different expected nonce, checked last, is `ERR_DPOP_NONCE_INVALID`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function verifyDPoPProof(proof: string, target: DPoPTarget, options: DPoPVerifyOptions): Promise<DPoPVerifyResult>;
|
|
73
|
+
export { type DPoPAlgorithm, type DPoPCreateOptions, type DPoPKeyPair, type DPoPPayload, type DPoPTarget, type DPoPVerifyOptions, type DPoPVerifyResult, JWTError, type JWTErrorCode, type KnownJWTErrorCode, isJWTError };
|