unjwt 0.8.5 → 0.9.1
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 +34 -21
- package/dist/_chunks/algorithms.mjs +44 -20
- package/dist/_chunks/digest.d.mts +4 -4
- package/dist/_chunks/digest.mjs +23 -15
- package/dist/_chunks/error.d.mts +29 -42
- package/dist/_chunks/export.mjs +1 -4
- package/dist/_chunks/index.d.mts +270 -234
- package/dist/_chunks/index2.d.mts +82 -189
- package/dist/_chunks/index4.d.mts +223 -60
- package/dist/_chunks/index5.d.mts +68 -31
- package/dist/_chunks/index6.d.mts +45 -64
- package/dist/_chunks/jwe.mjs +53 -48
- package/dist/_chunks/jwk.mjs +9 -3
- package/dist/_chunks/jws.mjs +55 -50
- package/dist/_chunks/jwt.d.mts +13 -49
- package/dist/_chunks/jwt.mjs +4 -158
- package/dist/_chunks/jwt2.mjs +162 -0
- package/dist/_chunks/libs/unsecure.d.mts +0 -6
- package/dist/_chunks/limits.d.mts +3 -2
- package/dist/_chunks/payload.mjs +13 -7
- package/dist/_chunks/wrap.mjs +3 -1
- package/dist/core/internal.d.mts +50 -2
- package/dist/core/internal.mjs +3 -1
- package/dist/core/jwe/index.d.mts +1 -1
- package/dist/core/jwk/index.d.mts +2 -2
- package/dist/core/jwk/index.mjs +2 -2
- package/dist/dpop/index.d.mts +77 -18
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/session/index.d.mts +568 -22
- package/dist/session/index.mjs +1386 -34
- package/dist/utils/index.d.mts +4 -4
- package/dist/utils/index.mjs +2 -10
- package/package.json +4 -32
- package/dist/_chunks/codec-jwe.d.mts +0 -280
- package/dist/_chunks/codec-jws.mjs +0 -1005
- package/dist/_chunks/cookie-attributes.d.mts +0 -12
- package/dist/_chunks/cookie.mjs +0 -50
- package/dist/adapters/elysia/index.d.mts +0 -123
- package/dist/adapters/elysia/index.mjs +0 -120
- package/dist/adapters/h3/index.d.mts +0 -135
- package/dist/adapters/h3/index.mjs +0 -117
- package/dist/adapters/h3v1/index.d.mts +0 -148
- package/dist/adapters/h3v1/index.mjs +0 -128
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** The `Set-Cookie` attributes of a session cookie (RFC 6265, RFC 6265bis, CHIPS). */
|
|
2
|
-
export interface CookieAttributes {
|
|
3
|
-
domain?: string;
|
|
4
|
-
expires?: Date;
|
|
5
|
-
httpOnly?: boolean;
|
|
6
|
-
maxAge?: number;
|
|
7
|
-
path?: string;
|
|
8
|
-
priority?: "low" | "medium" | "high";
|
|
9
|
-
sameSite?: boolean | "lax" | "strict" | "none";
|
|
10
|
-
secure?: boolean;
|
|
11
|
-
partitioned?: boolean;
|
|
12
|
-
}
|
package/dist/_chunks/cookie.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { mirrorSetCookie, setCookieName, setCookieValues } from "./codec-jws.mjs";
|
|
2
|
-
import { parse, parseSetCookie, serialize } from "./libs/cookie-es.mjs";
|
|
3
|
-
function webCookieJar(request, response) {
|
|
4
|
-
let cookies;
|
|
5
|
-
const jar = { read: (name) => (cookies ||= requestCookies(request))[name] };
|
|
6
|
-
if (response) {
|
|
7
|
-
const { headers, errHeaders } = response;
|
|
8
|
-
jar.written = (name) => setCookieValues(headers.getSetCookie())[name];
|
|
9
|
-
jar.write = (name, value, attrs) => {
|
|
10
|
-
setCookie(headers, {
|
|
11
|
-
name,
|
|
12
|
-
value,
|
|
13
|
-
...attrs
|
|
14
|
-
});
|
|
15
|
-
if (errHeaders) mirrorSetCookie(name, {
|
|
16
|
-
from: headers,
|
|
17
|
-
to: errHeaders
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return jar;
|
|
22
|
-
}
|
|
23
|
-
function requestCookies(request) {
|
|
24
|
-
const header = request.get("cookie");
|
|
25
|
-
return header ? parse(header) : Object.create(null);
|
|
26
|
-
}
|
|
27
|
-
function setCookie(headers, cookie) {
|
|
28
|
-
const line = serialize({
|
|
29
|
-
path: "/",
|
|
30
|
-
...cookie
|
|
31
|
-
});
|
|
32
|
-
const key = cookieKey(cookie);
|
|
33
|
-
const kept = headers.getSetCookie().filter((existing) => {
|
|
34
|
-
const parsed = parseSetCookie(existing);
|
|
35
|
-
return parsed ? cookieKey(parsed) !== key : setCookieName(existing) !== cookie.name;
|
|
36
|
-
});
|
|
37
|
-
headers.delete("set-cookie");
|
|
38
|
-
for (const existing of kept) headers.append("set-cookie", existing);
|
|
39
|
-
headers.append("set-cookie", line);
|
|
40
|
-
}
|
|
41
|
-
function cookieKey(cookie) {
|
|
42
|
-
const domain = (cookie.domain || "").replace(/^\./, "").toLowerCase();
|
|
43
|
-
return [
|
|
44
|
-
cookie.name,
|
|
45
|
-
domain,
|
|
46
|
-
cookie.path || "/",
|
|
47
|
-
cookie.partitioned ? "1" : "0"
|
|
48
|
-
].join(";");
|
|
49
|
-
}
|
|
50
|
-
export { requestCookies, webCookieJar };
|
|
@@ -1,123 +0,0 @@
|
|
|
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
|
-
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 { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/index2.mjs";
|
|
5
|
-
import { thumbprint } from "../../_chunks/index3.mjs";
|
|
6
|
-
import { Elysia } from "elysia";
|
|
7
|
-
interface ChunkableCookie {
|
|
8
|
-
value: unknown;
|
|
9
|
-
set(config: CookieAttributes & {
|
|
10
|
-
value: string;
|
|
11
|
-
}): unknown;
|
|
12
|
-
}
|
|
13
|
-
type ChunkableCookieJar = Record<string, ChunkableCookie>;
|
|
14
|
-
type WriteChunkedCookieOptions = CookieAttributes & {
|
|
15
|
-
chunkMaxLength?: number;
|
|
16
|
-
};
|
|
17
|
-
interface SessionContext {
|
|
18
|
-
cookie: ChunkableCookieJar;
|
|
19
|
-
request: {
|
|
20
|
-
headers: {
|
|
21
|
-
get(name: string): string | null;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Explicit return type for the `jwsSession` / `jweSession` plugin factories.
|
|
27
|
-
*
|
|
28
|
-
* Modelling Elysia's generics by hand is required by `isolatedDeclarations`
|
|
29
|
-
* (the factories return an inferred `new Elysia().resolve().macro()` type that
|
|
30
|
-
* cannot otherwise be emitted). `Resolved` is the scoped `Ephemeral.resolve`
|
|
31
|
-
* augmentation — typically `{ [P in ContextKey]: SessionManager }` — so consumers
|
|
32
|
-
* read a typed `ctx[contextKey]`. `GuardName` is the guard macro key (derived
|
|
33
|
-
* from the context key, e.g. `requireSession`), so multiple session plugins on
|
|
34
|
-
* one app each expose a distinct guard rather than colliding. `macroFn` is left
|
|
35
|
-
* `{}`: consumers only need `Metadata.macro` for the `{ [GuardName]: true }`
|
|
36
|
-
* route option.
|
|
37
|
-
*/
|
|
38
|
-
type SessionPlugin<Resolved extends Record<string, unknown>, GuardName extends string = "requireSession"> = Elysia<"", {
|
|
39
|
-
decorator: {};
|
|
40
|
-
store: {};
|
|
41
|
-
derive: {};
|
|
42
|
-
resolve: {};
|
|
43
|
-
}, {
|
|
44
|
-
typebox: {};
|
|
45
|
-
error: {};
|
|
46
|
-
}, {
|
|
47
|
-
schema: {};
|
|
48
|
-
standaloneSchema: {};
|
|
49
|
-
macro: { [M in GuardName]?: boolean; };
|
|
50
|
-
macroFn: {};
|
|
51
|
-
parser: {};
|
|
52
|
-
response: {};
|
|
53
|
-
}, {}, {
|
|
54
|
-
derive: {};
|
|
55
|
-
resolve: Resolved;
|
|
56
|
-
schema: {};
|
|
57
|
-
standaloneSchema: {};
|
|
58
|
-
response: {};
|
|
59
|
-
}, {
|
|
60
|
-
derive: {};
|
|
61
|
-
resolve: {};
|
|
62
|
-
schema: {};
|
|
63
|
-
standaloneSchema: {};
|
|
64
|
-
response: {};
|
|
65
|
-
}>;
|
|
66
|
-
/** A session definition on Elysia, plus the plugin that resolves its manager under `contextKey` (`K`). */
|
|
67
|
-
interface SessionPluginDefinition<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, K extends string = "session"> extends SessionDefinition<T, MaxAge, SessionContext> {
|
|
68
|
-
/** Resolves the session onto the context under `contextKey`, with the guard macro answering 401 while no session is established. */
|
|
69
|
-
plugin: () => SessionPlugin<{ [P in K]: SessionManager<T, MaxAge>; }, `require${Capitalize<K>}`>;
|
|
70
|
-
}
|
|
71
|
-
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
72
|
-
interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
73
|
-
context: TContext;
|
|
74
|
-
}, SessionConfigJWS<T, MaxAge, TContext>> {}
|
|
75
|
-
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext> extends JWSSessionConfig<MaxAge, CookieAttributes> {
|
|
76
|
-
/** Context property the session is exposed under. Default `"session"`. */
|
|
77
|
-
contextKey?: string;
|
|
78
|
-
hooks?: SessionHooksJWS<T, MaxAge, TContext>;
|
|
79
|
-
}
|
|
80
|
-
/** Defines a JWS (signed, not encrypted) session once: `use`, `token`, `issue` and `open` serve every request, `plugin()` mounts it on an app. */
|
|
81
|
-
export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, K extends string = "session">(config: SessionConfigJWS<T, MaxAge> & (K extends "session" ? {
|
|
82
|
-
contextKey?: K;
|
|
83
|
-
} : {
|
|
84
|
-
contextKey: K;
|
|
85
|
-
})): SessionPluginDefinition<T, MaxAge, K>;
|
|
86
|
-
/**
|
|
87
|
-
* Create a JWS (signed, not encrypted) session manager for the request.
|
|
88
|
-
* @deprecated Use `defineJWSSession(config).use(context)`.
|
|
89
|
-
*/
|
|
90
|
-
export declare function createJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext>(context: TContext, config: SessionConfigJWS<T, MaxAge, TContext>): Promise<SessionManager<T, MaxAge>>;
|
|
91
|
-
/** The Elysia plugin of a JWS (signed, not encrypted) session: `defineJWSSession(config).plugin()`. */
|
|
92
|
-
export declare function jwsSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, K extends string = "session">(config: SessionConfigJWS<T, MaxAge> & (K extends "session" ? {
|
|
93
|
-
contextKey?: K;
|
|
94
|
-
} : {
|
|
95
|
-
contextKey: K;
|
|
96
|
-
})): SessionPlugin<{ [P in K]: SessionManager<T, MaxAge>; }, `require${Capitalize<K>}`>;
|
|
97
|
-
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
98
|
-
interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
99
|
-
context: TContext;
|
|
100
|
-
}, SessionConfigJWE<T, MaxAge, TContext>> {}
|
|
101
|
-
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext> extends JWESessionConfig<MaxAge, CookieAttributes> {
|
|
102
|
-
/** Context property the session is exposed under. Default `"session"`. */
|
|
103
|
-
contextKey?: string;
|
|
104
|
-
hooks?: SessionHooksJWE<T, MaxAge, TContext>;
|
|
105
|
-
}
|
|
106
|
-
/** Defines a JWE (encrypted) session once: `use`, `token`, `issue` and `open` serve every request, `plugin()` mounts it on an app. */
|
|
107
|
-
export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, K extends string = "session">(config: SessionConfigJWE<T, MaxAge> & (K extends "session" ? {
|
|
108
|
-
contextKey?: K;
|
|
109
|
-
} : {
|
|
110
|
-
contextKey: K;
|
|
111
|
-
})): SessionPluginDefinition<T, MaxAge, K>;
|
|
112
|
-
/**
|
|
113
|
-
* Create a JWE (encrypted) session manager for the request.
|
|
114
|
-
* @deprecated Use `defineJWESession(config).use(context)`.
|
|
115
|
-
*/
|
|
116
|
-
export declare function createJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext>(context: TContext, config: SessionConfigJWE<T, MaxAge, TContext>): Promise<SessionManager<T, MaxAge>>;
|
|
117
|
-
/** The Elysia plugin of a JWE (encrypted) session: `defineJWESession(config).plugin()`. */
|
|
118
|
-
export declare function jweSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, K extends string = "session">(config: SessionConfigJWE<T, MaxAge> & (K extends "session" ? {
|
|
119
|
-
contextKey?: K;
|
|
120
|
-
} : {
|
|
121
|
-
contextKey: K;
|
|
122
|
-
})): SessionPlugin<{ [P in K]: SessionManager<T, MaxAge>; }, `require${Capitalize<K>}`>;
|
|
123
|
-
export { type ChunkableCookie, type ChunkableCookieJar, type CompositeKey, type ContentEncryptionAlgorithm, type CookieAttributes, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, 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, 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, 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, type JWT, type JWTClaimValidationOptions, type JWTClaims, type JWTConfirmation, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type MaxTokenAge, type NotBeforeIn, type OpenedSessionState, type PEMType, type PayloadOf, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionContext, type SessionData, type SessionDecryptOptions, type SessionDefinition, type SessionEncryptOptions, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionPlugin, type SessionPluginDefinition, type SessionSignOptions, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type ToPublicJWKReturn, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, type WriteChunkedCookieOptions, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK };
|
|
@@ -1,120 +0,0 @@
|
|
|
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";
|
|
5
|
-
import { Elysia } from "elysia";
|
|
6
|
-
function sessionPlugin(options) {
|
|
7
|
-
const contextKey = options.contextKey ?? "session";
|
|
8
|
-
const seed = `${options.sessionName}:${contextKey}`;
|
|
9
|
-
return new Elysia({
|
|
10
|
-
name: options.name,
|
|
11
|
-
seed
|
|
12
|
-
}).resolve({ as: "scoped" }, async ({ cookie, request }) => {
|
|
13
|
-
const session = await options.create({
|
|
14
|
-
cookie,
|
|
15
|
-
request
|
|
16
|
-
});
|
|
17
|
-
return { [contextKey]: session };
|
|
18
|
-
}).macro({ [guardName(contextKey)]: { resolve(ctx) {
|
|
19
|
-
if (!hasSessionId(ctx[contextKey])) return ctx.status(401, "Unauthorized");
|
|
20
|
-
return {};
|
|
21
|
-
} } });
|
|
22
|
-
}
|
|
23
|
-
function guardName(contextKey) {
|
|
24
|
-
return `require${contextKey.charAt(0).toUpperCase()}${contextKey.slice(1)}`;
|
|
25
|
-
}
|
|
26
|
-
function hasSessionId(session) {
|
|
27
|
-
return typeof session === "object" && session !== null && "id" in session && Boolean(session.id);
|
|
28
|
-
}
|
|
29
|
-
const PREFIX$1 = "[unjwt/elysia]";
|
|
30
|
-
function reactiveCookieJar(jar) {
|
|
31
|
-
return {
|
|
32
|
-
read: (name) => {
|
|
33
|
-
const value = jar[name]?.value;
|
|
34
|
-
return typeof value === "string" ? value : void 0;
|
|
35
|
-
},
|
|
36
|
-
write: (name, value, attrs) => reactiveCookie(jar, name).set({
|
|
37
|
-
...attrs,
|
|
38
|
-
value
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function reactiveCookie(jar, name) {
|
|
43
|
-
const cookie = jar[name];
|
|
44
|
-
if (!cookie || typeof cookie.set !== "function") throw invalidConfigError(`${PREFIX$1} Session cookie jar has no reactive cookie at "${name}", pass Elysia's \`cookie\`.`);
|
|
45
|
-
return cookie;
|
|
46
|
-
}
|
|
47
|
-
const PREFIX = "[unjwt/elysia]";
|
|
48
|
-
const SESSIONS = /* @__PURE__ */ new WeakMap();
|
|
49
|
-
const elysiaSessionDriver = {
|
|
50
|
-
prefix: PREFIX,
|
|
51
|
-
state: (context) => requestSessions(context.request),
|
|
52
|
-
header: (context, name) => context.request.headers.get(name),
|
|
53
|
-
cookies: (context) => reactiveCookieJar(context.cookie)
|
|
54
|
-
};
|
|
55
|
-
function requestSessions(request) {
|
|
56
|
-
const existing = SESSIONS.get(request);
|
|
57
|
-
if (existing) return existing;
|
|
58
|
-
const created = Object.create(null);
|
|
59
|
-
SESSIONS.set(request, created);
|
|
60
|
-
return created;
|
|
61
|
-
}
|
|
62
|
-
const codec$1 = createJWSCodec({
|
|
63
|
-
prefix: PREFIX,
|
|
64
|
-
defaultName: "elysia-jws"
|
|
65
|
-
});
|
|
66
|
-
function defineJWSSession(config) {
|
|
67
|
-
const definition = define$1(config);
|
|
68
|
-
return {
|
|
69
|
-
...definition,
|
|
70
|
-
plugin: () => sessionPlugin({
|
|
71
|
-
name: "unjwt/elysia-jws",
|
|
72
|
-
sessionName: config.name || codec$1.defaultName,
|
|
73
|
-
contextKey: config.contextKey,
|
|
74
|
-
create: definition.use
|
|
75
|
-
})
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async function createJWSSession(context, config) {
|
|
79
|
-
return define$1(config).use(context);
|
|
80
|
-
}
|
|
81
|
-
function jwsSession(config) {
|
|
82
|
-
return defineJWSSession(config).plugin();
|
|
83
|
-
}
|
|
84
|
-
function define$1(config) {
|
|
85
|
-
return defineSession(config, {
|
|
86
|
-
driver: elysiaSessionDriver,
|
|
87
|
-
hookArgs: (context) => ({ context }),
|
|
88
|
-
codec: codec$1
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
const codec = createJWECodec({
|
|
92
|
-
prefix: PREFIX,
|
|
93
|
-
defaultName: "elysia-jwe"
|
|
94
|
-
});
|
|
95
|
-
function defineJWESession(config) {
|
|
96
|
-
const definition = define(config);
|
|
97
|
-
return {
|
|
98
|
-
...definition,
|
|
99
|
-
plugin: () => sessionPlugin({
|
|
100
|
-
name: "unjwt/elysia-jwe",
|
|
101
|
-
sessionName: config.name || codec.defaultName,
|
|
102
|
-
contextKey: config.contextKey,
|
|
103
|
-
create: definition.use
|
|
104
|
-
})
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
async function createJWESession(context, config) {
|
|
108
|
-
return define(config).use(context);
|
|
109
|
-
}
|
|
110
|
-
function jweSession(config) {
|
|
111
|
-
return defineJWESession(config).plugin();
|
|
112
|
-
}
|
|
113
|
-
function define(config) {
|
|
114
|
-
return defineSession(config, {
|
|
115
|
-
driver: elysiaSessionDriver,
|
|
116
|
-
hookArgs: (context) => ({ context }),
|
|
117
|
-
codec
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
export { createJWESession, createJWSSession, defineJWESession, defineJWSSession, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, jweSession, jwsSession, thumbprint, toPublicJWK };
|
|
@@ -1,135 +0,0 @@
|
|
|
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 { 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 { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/index2.mjs";
|
|
4
|
-
import { thumbprint } from "../../_chunks/index3.mjs";
|
|
5
|
-
import { HTTPEvent, setCookie } from "h3";
|
|
6
|
-
type CookieSerializeOptions = NonNullable<Parameters<typeof setCookie>[3]>;
|
|
7
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
10
|
-
*/
|
|
11
|
-
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
12
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
15
|
-
*/
|
|
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
|
-
event: TEvent;
|
|
18
|
-
}, SessionConfigJWE<T, MaxAge, TEvent>> {}
|
|
19
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
22
|
-
*/
|
|
23
|
-
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionConfig<MaxAge, CookieSerializeOptions> {
|
|
24
|
-
/** Cookie and session-header name. Default `"h3-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
25
|
-
name?: string;
|
|
26
|
-
hooks?: SessionHooksJWE<T, MaxAge, TEvent>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
31
|
-
*/
|
|
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
|
-
/**
|
|
34
|
-
* Create a JWE (encrypted) session manager for the request.
|
|
35
|
-
* @deprecated Use `defineJWESession(config).use(event)`.
|
|
36
|
-
*/
|
|
37
|
-
export declare function useJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
|
|
38
|
-
/**
|
|
39
|
-
* Get (and lazily initialize) the session for the current request.
|
|
40
|
-
* @deprecated Use `defineJWESession(config).use(event)`; the manager exposes the same state.
|
|
41
|
-
*/
|
|
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
|
-
/**
|
|
44
|
-
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
45
|
-
* @deprecated Use `defineJWESession(config).token(event)`.
|
|
46
|
-
*/
|
|
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;
|
|
48
|
-
/**
|
|
49
|
-
* Update the session data (if provided) and reissue the JWE; `options.maxAge` overrides this token's lifetime.
|
|
50
|
-
* @deprecated Use `(await defineJWESession(config).use(event)).update(update, options)`.
|
|
51
|
-
*/
|
|
52
|
-
export declare function updateJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>, update?: SessionUpdate<T>, options?: SessionIssueOptions): Promise<SessionJWE<T, MaxAge> & {
|
|
53
|
-
id: string;
|
|
54
|
-
token: string;
|
|
55
|
-
}>;
|
|
56
|
-
/**
|
|
57
|
-
* Seal the session as a compact JWE without writing a cookie; fresh `jti` if no ID, no token source needed.
|
|
58
|
-
* @deprecated Use `defineJWESession(config).issue(data)` to mint a token, or `(await defineJWESession(config).use(event)).token` for the current one.
|
|
59
|
-
*/
|
|
60
|
-
export declare function sealJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<string>;
|
|
61
|
-
/**
|
|
62
|
-
* Decrypt a compact JWE into a session, checking `typ`, pinned `alg`/`enc`, `jti`/`iat` and `exp` (required with `maxAge`).
|
|
63
|
-
* @deprecated Use `defineJWESession(config).open(sealed)`.
|
|
64
|
-
*/
|
|
65
|
-
export declare function unsealJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
|
|
66
|
-
/**
|
|
67
|
-
* Drop the session cookie and leave an empty session for the rest of the request.
|
|
68
|
-
* @deprecated Use `(await defineJWESession(config).use(event)).clear()`.
|
|
69
|
-
*/
|
|
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
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
74
|
-
*/
|
|
75
|
-
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
76
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
79
|
-
*/
|
|
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
|
-
event: TEvent;
|
|
82
|
-
}, SessionConfigJWS<T, MaxAge, TEvent>> {}
|
|
83
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
86
|
-
*/
|
|
87
|
-
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionConfig<MaxAge, CookieSerializeOptions> {
|
|
88
|
-
/** Cookie and session-header name. Default `"h3-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
89
|
-
name?: string;
|
|
90
|
-
hooks?: SessionHooksJWS<T, MaxAge, TEvent>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
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 and mirrors cookie writes into `res.errHeaders` as this adapter does.
|
|
95
|
-
*/
|
|
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
|
-
/**
|
|
98
|
-
* Create a JWS (signed, not encrypted) session manager for the request.
|
|
99
|
-
* @deprecated Use `defineJWSSession(config).use(event)`.
|
|
100
|
-
*/
|
|
101
|
-
export declare function useJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
|
|
102
|
-
/**
|
|
103
|
-
* Get (and lazily initialize) the session for the current request.
|
|
104
|
-
* @deprecated Use `defineJWSSession(config).use(event)`; the manager exposes the same state.
|
|
105
|
-
*/
|
|
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
|
-
/**
|
|
108
|
-
* Read the raw session token: the session header when the request carries it (default `x-<name>-session`, optional `Bearer`), else the cookie.
|
|
109
|
-
* @deprecated Use `defineJWSSession(config).token(event)`.
|
|
110
|
-
*/
|
|
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;
|
|
112
|
-
/**
|
|
113
|
-
* Update the session data (if provided) and reissue the JWS; `options.maxAge` overrides this token's lifetime.
|
|
114
|
-
* @deprecated Use `(await defineJWSSession(config).use(event)).update(update, options)`.
|
|
115
|
-
*/
|
|
116
|
-
export declare function updateJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>, update?: SessionUpdate<T>, options?: SessionIssueOptions): Promise<SessionJWS<T, MaxAge> & {
|
|
117
|
-
id: string;
|
|
118
|
-
token: string;
|
|
119
|
-
}>;
|
|
120
|
-
/**
|
|
121
|
-
* Sign the session as a compact JWS without writing a cookie; fresh `jti` if no ID, no token source needed.
|
|
122
|
-
* @deprecated Use `defineJWSSession(config).issue(data)` to mint a token, or `(await defineJWSSession(config).use(event)).token` for the current one.
|
|
123
|
-
*/
|
|
124
|
-
export declare function signJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<string>;
|
|
125
|
-
/**
|
|
126
|
-
* Verify a compact JWS into a session, checking `typ`, pinned `alg`, `jti`/`iat` and `exp` (required with `maxAge`).
|
|
127
|
-
* @deprecated Use `defineJWSSession(config).open(token)`.
|
|
128
|
-
*/
|
|
129
|
-
export declare function verifyJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
|
|
130
|
-
/**
|
|
131
|
-
* Drop the session cookie and leave an empty session for the rest of the request.
|
|
132
|
-
* @deprecated Use `(await defineJWSSession(config).use(event)).clear()`.
|
|
133
|
-
*/
|
|
134
|
-
export declare function clearJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<void>;
|
|
135
|
-
export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, 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, 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, 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, type JWT, type JWTClaimValidationOptions, type JWTClaims, type JWTConfirmation, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type MaxTokenAge, type NotBeforeIn, type OpenedSessionState, type PEMType, type PayloadOf, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionDecryptOptions, type SessionDefinition, type SessionEncryptOptions, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionSignOptions, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type ToPublicJWKReturn, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK };
|
|
@@ -1,117 +0,0 @@
|
|
|
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";
|
|
5
|
-
import { getCookie, getEventContext, setCookie } from "h3";
|
|
6
|
-
const PREFIX = "[unjwt/h3]";
|
|
7
|
-
const h3SessionDriver = {
|
|
8
|
-
prefix: PREFIX,
|
|
9
|
-
state: (event) => getEventContext(event).sessions ||= Object.create(null),
|
|
10
|
-
header: (event, name) => event.req.headers.get(name),
|
|
11
|
-
cookies: (event) => hasResponse(event) ? responseCookieJar(event) : { read: (name) => getCookie(event, name) }
|
|
12
|
-
};
|
|
13
|
-
function responseCookieJar(event) {
|
|
14
|
-
return {
|
|
15
|
-
read: (name) => getCookie(event, name),
|
|
16
|
-
written: (name) => setCookieValues(event.res.headers.getSetCookie())[name],
|
|
17
|
-
write: (name, value, attrs) => {
|
|
18
|
-
setCookie(event, name, value, attrs);
|
|
19
|
-
mirrorSetCookie(name, {
|
|
20
|
-
from: event.res.headers,
|
|
21
|
-
to: event.res.errHeaders
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function hasResponse(event) {
|
|
27
|
-
return "res" in event && Boolean(event.res);
|
|
28
|
-
}
|
|
29
|
-
const codec$1 = createJWECodec({
|
|
30
|
-
prefix: PREFIX,
|
|
31
|
-
defaultName: "h3-jwe"
|
|
32
|
-
});
|
|
33
|
-
const hookArgs$1 = (event) => ({ event });
|
|
34
|
-
function defineJWESession(config) {
|
|
35
|
-
return defineSession(config, {
|
|
36
|
-
driver: h3SessionDriver,
|
|
37
|
-
hookArgs: hookArgs$1,
|
|
38
|
-
codec: codec$1
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
async function useJWESession(event, config) {
|
|
42
|
-
return defineJWESession(config).use(event);
|
|
43
|
-
}
|
|
44
|
-
async function getJWESession(event, config) {
|
|
45
|
-
return loadSession(bind$1(event, config));
|
|
46
|
-
}
|
|
47
|
-
function getJWESessionToken(event, config) {
|
|
48
|
-
return defineJWESession(config).token(event);
|
|
49
|
-
}
|
|
50
|
-
async function updateJWESession(event, config, update, options) {
|
|
51
|
-
return issueSession(bind$1(event, config), update, options);
|
|
52
|
-
}
|
|
53
|
-
async function sealJWESession(event, config) {
|
|
54
|
-
return encodeSession(bind$1(event, config));
|
|
55
|
-
}
|
|
56
|
-
async function unsealJWESession(event, config, sealed) {
|
|
57
|
-
return openSessionToken(codec$1, config, {
|
|
58
|
-
token: sealed,
|
|
59
|
-
args: { event }
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async function clearJWESession(event, config) {
|
|
63
|
-
return dropSession(bind$1(event, config));
|
|
64
|
-
}
|
|
65
|
-
function bind$1(event, config) {
|
|
66
|
-
return bindSession(event, config, {
|
|
67
|
-
driver: h3SessionDriver,
|
|
68
|
-
hookArgs: hookArgs$1,
|
|
69
|
-
codec: codec$1,
|
|
70
|
-
actions: sessionActions()
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
const codec = createJWSCodec({
|
|
74
|
-
prefix: PREFIX,
|
|
75
|
-
defaultName: "h3-jws"
|
|
76
|
-
});
|
|
77
|
-
const hookArgs = (event) => ({ event });
|
|
78
|
-
function defineJWSSession(config) {
|
|
79
|
-
return defineSession(config, {
|
|
80
|
-
driver: h3SessionDriver,
|
|
81
|
-
hookArgs,
|
|
82
|
-
codec
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
async function useJWSSession(event, config) {
|
|
86
|
-
return defineJWSSession(config).use(event);
|
|
87
|
-
}
|
|
88
|
-
async function getJWSSession(event, config) {
|
|
89
|
-
return loadSession(bind(event, config));
|
|
90
|
-
}
|
|
91
|
-
function getJWSSessionToken(event, config) {
|
|
92
|
-
return defineJWSSession(config).token(event);
|
|
93
|
-
}
|
|
94
|
-
async function updateJWSSession(event, config, update, options) {
|
|
95
|
-
return issueSession(bind(event, config), update, options);
|
|
96
|
-
}
|
|
97
|
-
async function signJWSSession(event, config) {
|
|
98
|
-
return encodeSession(bind(event, config));
|
|
99
|
-
}
|
|
100
|
-
async function verifyJWSSession(event, config, token) {
|
|
101
|
-
return openSessionToken(codec, config, {
|
|
102
|
-
token,
|
|
103
|
-
args: { event }
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
async function clearJWSSession(event, config) {
|
|
107
|
-
return dropSession(bind(event, config));
|
|
108
|
-
}
|
|
109
|
-
function bind(event, config) {
|
|
110
|
-
return bindSession(event, config, {
|
|
111
|
-
driver: h3SessionDriver,
|
|
112
|
-
hookArgs,
|
|
113
|
-
codec,
|
|
114
|
-
actions: sessionActions()
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export { clearJWESession, clearJWSSession, defineJWESession, defineJWSSession, deriveJWKFromPassword, exportPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importPEM, sealJWESession, signJWSSession, thumbprint, toPublicJWK, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|