unjwt 0.8.1 → 0.8.3
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 +4 -4
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/_codec-jwe.d.mts +101 -22
- package/dist/_chunks/_codec-jws.mjs +306 -232
- package/dist/_chunks/_cookie-attributes.d.mts +12 -0
- package/dist/_chunks/_jwt-internal.mjs +9 -6
- package/dist/_chunks/digest.d.mts +8 -0
- package/dist/_chunks/{algorithms.mjs → digest.mjs} +78 -8
- package/dist/_chunks/index.d.mts +313 -268
- package/dist/_chunks/index2.d.mts +2 -1
- package/dist/_chunks/index3.d.mts +1 -0
- package/dist/_chunks/jwe.d.mts +4 -4
- package/dist/_chunks/jwe.mjs +21 -3
- package/dist/_chunks/jwk.mjs +219 -173
- package/dist/_chunks/jws.d.mts +10 -10
- package/dist/_chunks/jws.mjs +18 -6
- package/dist/_chunks/jwt.d.mts +2 -1
- package/dist/_chunks/libs/cookie-es.mjs +255 -0
- package/dist/adapters/elysia/index.d.mts +32 -15
- package/dist/adapters/elysia/index.mjs +46 -67
- package/dist/adapters/h3/index.d.mts +135 -0
- package/dist/adapters/h3/index.mjs +119 -0
- package/dist/adapters/h3v1/index.d.mts +100 -27
- package/dist/adapters/h3v1/index.mjs +59 -76
- package/dist/core/jwe.d.mts +2 -2
- package/dist/core/jwk.d.mts +22 -14
- package/dist/core/jwk.mjs +2 -2
- package/dist/core/jws.d.mts +2 -2
- package/dist/core/utils/index.d.mts +2 -1
- package/dist/core/utils/index.mjs +2 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -3
- package/dist/session/index.d.mts +44 -0
- package/dist/session/index.mjs +113 -0
- package/package.json +37 -18
- package/dist/adapters/h3v2/index.d.mts +0 -65
- package/dist/adapters/h3v2/index.mjs +0 -139
package/package.json
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unjwt",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.3",
|
|
4
|
+
"description": "A collection of JWT utilities based on the Web Crypto API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"auth",
|
|
7
|
+
"browser",
|
|
8
|
+
"decrypt",
|
|
9
|
+
"edge",
|
|
10
|
+
"encrypt",
|
|
11
|
+
"jose",
|
|
12
|
+
"jwe",
|
|
13
|
+
"jwk",
|
|
14
|
+
"jws",
|
|
15
|
+
"jwt",
|
|
16
|
+
"security",
|
|
17
|
+
"serverless",
|
|
18
|
+
"session",
|
|
19
|
+
"sign",
|
|
20
|
+
"verify",
|
|
21
|
+
"webcrypto"
|
|
22
|
+
],
|
|
5
23
|
"homepage": "https://unjwt.s94.dev",
|
|
6
24
|
"license": "MIT",
|
|
7
25
|
"author": {
|
|
@@ -12,6 +30,9 @@
|
|
|
12
30
|
"type": "git",
|
|
13
31
|
"url": "git+https://github.com/sandros94/unjwt.git"
|
|
14
32
|
},
|
|
33
|
+
"funding": {
|
|
34
|
+
"url": "https://github.com/sponsors/sandros94"
|
|
35
|
+
},
|
|
15
36
|
"files": [
|
|
16
37
|
"dist"
|
|
17
38
|
],
|
|
@@ -41,21 +62,25 @@
|
|
|
41
62
|
"types": "./dist/core/utils/index.d.mts",
|
|
42
63
|
"default": "./dist/core/utils/index.mjs"
|
|
43
64
|
},
|
|
65
|
+
"./session": {
|
|
66
|
+
"types": "./dist/session/index.d.mts",
|
|
67
|
+
"default": "./dist/session/index.mjs"
|
|
68
|
+
},
|
|
44
69
|
"./internal": {
|
|
45
70
|
"types": "./dist/core/internal.d.mts",
|
|
46
71
|
"default": "./dist/core/internal.mjs"
|
|
47
72
|
},
|
|
48
73
|
"./adapters/h3": {
|
|
49
|
-
"types": "./dist/adapters/
|
|
50
|
-
"default": "./dist/adapters/
|
|
74
|
+
"types": "./dist/adapters/h3/index.d.mts",
|
|
75
|
+
"default": "./dist/adapters/h3/index.mjs"
|
|
51
76
|
},
|
|
52
77
|
"./adapters/h3v1": {
|
|
53
78
|
"types": "./dist/adapters/h3v1/index.d.mts",
|
|
54
79
|
"default": "./dist/adapters/h3v1/index.mjs"
|
|
55
80
|
},
|
|
56
81
|
"./adapters/h3v2": {
|
|
57
|
-
"types": "./dist/adapters/
|
|
58
|
-
"default": "./dist/adapters/
|
|
82
|
+
"types": "./dist/adapters/h3/index.d.mts",
|
|
83
|
+
"default": "./dist/adapters/h3/index.mjs"
|
|
59
84
|
},
|
|
60
85
|
"./adapters/elysia": {
|
|
61
86
|
"types": "./dist/adapters/elysia/index.d.mts",
|
|
@@ -67,11 +92,10 @@
|
|
|
67
92
|
"@types/supertest": "^7.2.1",
|
|
68
93
|
"@vitest/coverage-v8": "^5.0.4",
|
|
69
94
|
"automd": "^0.4.3",
|
|
70
|
-
"cookie-
|
|
71
|
-
"cookie-esv3": "npm:cookie-es@^3.1.1",
|
|
95
|
+
"cookie-es": "^3.1.1",
|
|
72
96
|
"elysia": "^1.4.30",
|
|
97
|
+
"h3": "^2.0.5",
|
|
73
98
|
"h3v1": "npm:h3@^1.15.11",
|
|
74
|
-
"h3v2": "npm:h3@^2.0.2",
|
|
75
99
|
"jose": "^6.2.12",
|
|
76
100
|
"obuild": "^0.4.45",
|
|
77
101
|
"oxfmt": "^0.73.0",
|
|
@@ -85,14 +109,10 @@
|
|
|
85
109
|
"vitest": "^5.0.4"
|
|
86
110
|
},
|
|
87
111
|
"peerDependencies": {
|
|
88
|
-
"cookie-es": "^1.2.3 || ^3.1.1",
|
|
89
112
|
"elysia": "^1.4.29",
|
|
90
113
|
"h3": "^1.15.4 || ^2.0.1"
|
|
91
114
|
},
|
|
92
115
|
"peerDependenciesMeta": {
|
|
93
|
-
"cookie-es": {
|
|
94
|
-
"optional": true
|
|
95
|
-
},
|
|
96
116
|
"elysia": {
|
|
97
117
|
"optional": true
|
|
98
118
|
},
|
|
@@ -100,9 +120,6 @@
|
|
|
100
120
|
"optional": true
|
|
101
121
|
}
|
|
102
122
|
},
|
|
103
|
-
"resolutions": {
|
|
104
|
-
"unjwt": "link:."
|
|
105
|
-
},
|
|
106
123
|
"simple-git-hooks": {
|
|
107
124
|
"pre-commit": "pnpm build --stub && pnpm lint && pnpm typecheck"
|
|
108
125
|
},
|
|
@@ -120,8 +137,10 @@
|
|
|
120
137
|
},
|
|
121
138
|
"scripts": {
|
|
122
139
|
"build": "obuild",
|
|
123
|
-
"dev": "
|
|
124
|
-
"dev:
|
|
140
|
+
"dev": "pnpm --dir playgrounds/h3 dev",
|
|
141
|
+
"dev:nuxt": "pnpm --dir playgrounds/nuxt-4 dev",
|
|
142
|
+
"dev:nitro": "pnpm --dir playgrounds/nitro dev",
|
|
143
|
+
"dev:prepare": "obuild --stub && pnpm --dir playgrounds/nuxt-4 prepare && pnpm simple-git-hooks",
|
|
125
144
|
"lint": "oxlint --deny-warnings . && oxfmt --check .",
|
|
126
145
|
"fmt": "automd && oxlint --fix . && oxfmt .",
|
|
127
146
|
"test": "vitest run --slowTestThreshold=1000",
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, 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, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, MaxTokenAge, NotBeforeIn, PayloadOf, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
2
|
-
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, SessionClaims, SessionData, SessionDecryptOptions, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/_codec-jwe.mjs";
|
|
3
|
-
import { thumbprint } from "../../_chunks/index2.mjs";
|
|
4
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../../core/jwk.mjs";
|
|
5
|
-
import { HTTPEvent } from "h3";
|
|
6
|
-
import { CookieSerializeOptions } from "cookie-es";
|
|
7
|
-
/** Session state for the current request, mirroring the claims of its JWE token. */
|
|
8
|
-
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
9
|
-
/** JWE session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
10
|
-
interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
11
|
-
event: TEvent;
|
|
12
|
-
}, SessionConfigJWE<T, MaxAge, TEvent>> {}
|
|
13
|
-
/** Configuration for a JWE-backed (encrypted) session. */
|
|
14
|
-
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionConfig<MaxAge, CookieSerializeOptions> {
|
|
15
|
-
/** Cookie and session-header name. Default `"h3-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
16
|
-
name?: string;
|
|
17
|
-
hooks?: SessionHooksJWE<T, MaxAge, TEvent>;
|
|
18
|
-
}
|
|
19
|
-
/** Create a JWE (encrypted) session manager for the request. */
|
|
20
|
-
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>>;
|
|
21
|
-
/** Get (and lazily initialize) the session for the current request. */
|
|
22
|
-
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>>;
|
|
23
|
-
/** Read the raw session token: cookie first, then the session header (default `x-<name>-session`, optional `Bearer`). */
|
|
24
|
-
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;
|
|
25
|
-
/** Update the session data (if provided) and reissue the JWE; `options.maxAge` overrides this token's lifetime. */
|
|
26
|
-
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> & {
|
|
27
|
-
id: string;
|
|
28
|
-
token: string;
|
|
29
|
-
}>;
|
|
30
|
-
/** Seal the session as a compact JWE without writing a cookie; fresh `jti` if no ID, no token source needed. */
|
|
31
|
-
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>;
|
|
32
|
-
/** Decrypt a compact JWE into a session, checking `typ`, pinned `alg`/`enc`, `jti`/`iat` and `exp` (required with `maxAge`). */
|
|
33
|
-
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>>>;
|
|
34
|
-
/** Drop the session cookie and leave an empty session for the rest of the request. */
|
|
35
|
-
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>;
|
|
36
|
-
/** Session state for the current request, mirroring the claims of its JWS token. */
|
|
37
|
-
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
38
|
-
/** JWS session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
39
|
-
interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
40
|
-
event: TEvent;
|
|
41
|
-
}, SessionConfigJWS<T, MaxAge, TEvent>> {}
|
|
42
|
-
/** Configuration for a JWS-backed (signed, not encrypted) session. */
|
|
43
|
-
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionConfig<MaxAge, CookieSerializeOptions> {
|
|
44
|
-
/** Cookie and session-header name. Default `"h3-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
45
|
-
name?: string;
|
|
46
|
-
hooks?: SessionHooksJWS<T, MaxAge, TEvent>;
|
|
47
|
-
}
|
|
48
|
-
/** Create a JWS (signed, not encrypted) session manager for the request; clients can read its data. */
|
|
49
|
-
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>>;
|
|
50
|
-
/** Get (and lazily initialize) the session for the current request. */
|
|
51
|
-
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>>;
|
|
52
|
-
/** Read the raw session token: cookie first, then the session header (default `x-<name>-session`, optional `Bearer`). */
|
|
53
|
-
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;
|
|
54
|
-
/** Update the session data (if provided) and reissue the JWS; `options.maxAge` overrides this token's lifetime. */
|
|
55
|
-
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> & {
|
|
56
|
-
id: string;
|
|
57
|
-
token: string;
|
|
58
|
-
}>;
|
|
59
|
-
/** Sign the session as a compact JWS without writing a cookie; fresh `jti` if no ID, no token source needed. */
|
|
60
|
-
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>;
|
|
61
|
-
/** Verify a compact JWS into a session, checking `typ`, pinned `alg`, `jti`/`iat` and `exp` (required with `maxAge`). */
|
|
62
|
-
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>>>;
|
|
63
|
-
/** Drop the session cookie and leave an empty session for the rest of the request. */
|
|
64
|
-
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>;
|
|
65
|
-
export { type CompositeKey, type ContentEncryptionAlgorithm, 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 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 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_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 JWSHeaderParameters, 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 JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type MaxTokenAge, type NotBeforeIn, type PayloadOf, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionDecryptOptions, type SessionEncryptOptions, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionSignOptions, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint } from "../../_chunks/jwk.mjs";
|
|
2
|
-
import { bindSession, createJWECodec, createJWSCodec, dropSession, encodeSession, isChunkName, issueSession, loadSession, openSessionToken, readChunkedBy, readChunkedFromSetCookie, recordSlotStore, removeChunked, resolveSessionToken, responseCookieStore, sessionActions, sessionManager, sessionToken, setCookieName, writeChunked } from "../../_chunks/_codec-jws.mjs";
|
|
3
|
-
import { getCookie, getEventContext, setCookie } from "h3";
|
|
4
|
-
function eventCookieStore(event) {
|
|
5
|
-
return responseCookieStore({
|
|
6
|
-
request: (name) => getCookie(event, name),
|
|
7
|
-
response: () => event.res.headers.getSetCookie(),
|
|
8
|
-
write: (name, value, attrs) => setCookie(event, name, value, attrs)
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
const PREFIX = "[unjwt/h3]";
|
|
12
|
-
const h3SessionPort = {
|
|
13
|
-
prefix: PREFIX,
|
|
14
|
-
carrier: (event) => ({ event }),
|
|
15
|
-
store: (event, slot) => recordSlotStore(() => {
|
|
16
|
-
const context = getEventContext(event);
|
|
17
|
-
return context.sessions ||= Object.create(null);
|
|
18
|
-
}, slot),
|
|
19
|
-
readToken: readSessionToken,
|
|
20
|
-
scope: (event) => getEventContext(event),
|
|
21
|
-
writable: hasWritableResponse,
|
|
22
|
-
setCookie: (event, sessionName, token, { attrs, chunkMaxLength }) => {
|
|
23
|
-
const target = cookieEvent(event);
|
|
24
|
-
writeChunked(eventCookieStore(target), sessionName, token, {
|
|
25
|
-
attrs,
|
|
26
|
-
chunkMaxLength,
|
|
27
|
-
prefix: PREFIX
|
|
28
|
-
});
|
|
29
|
-
stageSessionErrCookies(target, sessionName);
|
|
30
|
-
},
|
|
31
|
-
deleteCookie: (event, sessionName, { attrs }) => {
|
|
32
|
-
const target = cookieEvent(event);
|
|
33
|
-
removeChunked(eventCookieStore(target), sessionName, { attrs });
|
|
34
|
-
stageSessionErrCookies(target, sessionName);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
function hasResponse(event) {
|
|
38
|
-
return "res" in event && Boolean(event.res);
|
|
39
|
-
}
|
|
40
|
-
function hasWritableResponse(event) {
|
|
41
|
-
if (!hasResponse(event)) return false;
|
|
42
|
-
const res = event.runtime?.node?.res;
|
|
43
|
-
return !res || !res.headersSent && !res.writableEnded;
|
|
44
|
-
}
|
|
45
|
-
function readSessionToken(event, sessionName, source) {
|
|
46
|
-
return resolveSessionToken(source, sessionName, {
|
|
47
|
-
written: (name) => hasResponse(event) ? readChunkedFromSetCookie(event.res.headers.getSetCookie(), name) : void 0,
|
|
48
|
-
cookie: (name) => readChunkedBy((key) => getCookie(event, key), name),
|
|
49
|
-
header: (name) => event.req.headers.get(name)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function stageSessionErrCookies(event, sessionName) {
|
|
53
|
-
const isSessionCookie = (cookie) => {
|
|
54
|
-
const name = setCookieName(cookie);
|
|
55
|
-
return name !== void 0 && (name === sessionName || isChunkName(name, sessionName));
|
|
56
|
-
};
|
|
57
|
-
const errHeaders = event.res.errHeaders;
|
|
58
|
-
const staged = [...errHeaders.getSetCookie().filter((cookie) => !isSessionCookie(cookie)), ...event.res.headers.getSetCookie().filter((cookie) => isSessionCookie(cookie))];
|
|
59
|
-
errHeaders.delete("set-cookie");
|
|
60
|
-
for (const cookie of staged) errHeaders.append("set-cookie", cookie);
|
|
61
|
-
}
|
|
62
|
-
function cookieEvent(event) {
|
|
63
|
-
return event;
|
|
64
|
-
}
|
|
65
|
-
const codec$1 = createJWECodec({
|
|
66
|
-
prefix: PREFIX,
|
|
67
|
-
defaultName: "h3-jwe"
|
|
68
|
-
});
|
|
69
|
-
async function useJWESession(event, config) {
|
|
70
|
-
const binding = bind$1(event, config);
|
|
71
|
-
await loadSession(binding);
|
|
72
|
-
return sessionManager(binding);
|
|
73
|
-
}
|
|
74
|
-
async function getJWESession(event, config) {
|
|
75
|
-
return loadSession(bind$1(event, config));
|
|
76
|
-
}
|
|
77
|
-
function getJWESessionToken(event, config) {
|
|
78
|
-
return sessionToken(bind$1(event, config));
|
|
79
|
-
}
|
|
80
|
-
async function updateJWESession(event, config, update, options) {
|
|
81
|
-
return issueSession(bind$1(event, config), update, options);
|
|
82
|
-
}
|
|
83
|
-
async function sealJWESession(event, config) {
|
|
84
|
-
return encodeSession(bind$1(event, config));
|
|
85
|
-
}
|
|
86
|
-
async function unsealJWESession(event, config, sealed) {
|
|
87
|
-
return openSessionToken(codec$1, config, {
|
|
88
|
-
token: sealed,
|
|
89
|
-
carrier: { event }
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
async function clearJWESession(event, config) {
|
|
93
|
-
return dropSession(bind$1(event, config));
|
|
94
|
-
}
|
|
95
|
-
function bind$1(event, config) {
|
|
96
|
-
return bindSession(event, config, {
|
|
97
|
-
port: h3SessionPort,
|
|
98
|
-
codec: codec$1,
|
|
99
|
-
actions: sessionActions()
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const codec = createJWSCodec({
|
|
103
|
-
prefix: PREFIX,
|
|
104
|
-
defaultName: "h3-jws"
|
|
105
|
-
});
|
|
106
|
-
async function useJWSSession(event, config) {
|
|
107
|
-
const binding = bind(event, config);
|
|
108
|
-
await loadSession(binding);
|
|
109
|
-
return sessionManager(binding);
|
|
110
|
-
}
|
|
111
|
-
async function getJWSSession(event, config) {
|
|
112
|
-
return loadSession(bind(event, config));
|
|
113
|
-
}
|
|
114
|
-
function getJWSSessionToken(event, config) {
|
|
115
|
-
return sessionToken(bind(event, config));
|
|
116
|
-
}
|
|
117
|
-
async function updateJWSSession(event, config, update, options) {
|
|
118
|
-
return issueSession(bind(event, config), update, options);
|
|
119
|
-
}
|
|
120
|
-
async function signJWSSession(event, config) {
|
|
121
|
-
return encodeSession(bind(event, config));
|
|
122
|
-
}
|
|
123
|
-
async function verifyJWSSession(event, config, token) {
|
|
124
|
-
return openSessionToken(codec, config, {
|
|
125
|
-
token,
|
|
126
|
-
carrier: { event }
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
async function clearJWSSession(event, config) {
|
|
130
|
-
return dropSession(bind(event, config));
|
|
131
|
-
}
|
|
132
|
-
function bind(event, config) {
|
|
133
|
-
return bindSession(event, config, {
|
|
134
|
-
port: h3SessionPort,
|
|
135
|
-
codec,
|
|
136
|
-
actions: sessionActions()
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
export { clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importPEM, sealJWESession, signJWSSession, thumbprint, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|