@tuwaio/siwx-server 0.1.0 → 0.2.0

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.
@@ -0,0 +1,193 @@
1
+ import { SiwxVerificationPolicy, SiwxVerifyResult, ParsedSiwxMessage } from '@tuwaio/siwx-core';
2
+
3
+ /**
4
+ * @fileoverview Server-side types for the @tuwaio/siwx-server package.
5
+ */
6
+
7
+ /**
8
+ * Options for the `verifySiwxPayload` function.
9
+ */
10
+ interface ServerVerifyOptions {
11
+ /**
12
+ * A set of nonces that have already been used.
13
+ * If the payload's nonce is found in this set, verification will fail
14
+ * to prevent replay attacks.
15
+ */
16
+ usedNonces?: Set<string>;
17
+ /**
18
+ * If true, skips the `expirationTime` validation check.
19
+ * Not recommended for production use.
20
+ * @default false
21
+ */
22
+ skipExpiration?: boolean;
23
+ /**
24
+ * Optional verification policy to enforce on the message fields.
25
+ */
26
+ policy?: SiwxVerificationPolicy;
27
+ /**
28
+ * Optional viem `PublicClient` instance for EVM chain EIP-1271 (smart contract wallet) verification.
29
+ */
30
+ publicClient?: any;
31
+ }
32
+ /**
33
+ * The result of a server-side verification operation, extending the base result
34
+ * with the verification method used.
35
+ */
36
+ interface ServerVerifyResult extends SiwxVerifyResult {
37
+ /**
38
+ * The CAIP-2 namespace used for verification routing.
39
+ * `eip155` for EVM chains, `solana` for Solana.
40
+ */
41
+ namespace?: 'eip155' | 'solana';
42
+ }
43
+ /**
44
+ * Represents a serializable session object derived from a verified CAIP-122 message.
45
+ */
46
+ interface SiwxSession {
47
+ /** The verified CAIP-10 blockchain address. */
48
+ address: string;
49
+ /** The CAIP-2 chain ID the session is bound to. */
50
+ chainId: string;
51
+ /** The domain that issued the session. */
52
+ domain: string;
53
+ /** The nonce that was used. Must be invalidated server-side after use. */
54
+ nonce: string;
55
+ /** ISO 8601 timestamp when the session was issued. */
56
+ issuedAt: string;
57
+ /** ISO 8601 timestamp when the session expires, if set. */
58
+ expirationTime?: string;
59
+ }
60
+ /**
61
+ * Represents a stored session record in a durable session store.
62
+ */
63
+ interface SiwxSessionRecord {
64
+ /** Unique opaque session identifier (e.g. secure random UUID). */
65
+ id: string;
66
+ /** The verified SIWX session data. */
67
+ session: SiwxSession;
68
+ /** Optional subject ID (e.g., Payload User ID or internal database ID) bound to this session. */
69
+ subjectId?: string;
70
+ /** Timestamp in milliseconds when the session record was created. */
71
+ createdAt: number;
72
+ /** Timestamp in milliseconds when the session record expires. */
73
+ expiresAt: number;
74
+ }
75
+ /**
76
+ * Durable session store interface for production environments.
77
+ */
78
+ interface SiwxSessionStore {
79
+ /**
80
+ * Creates and stores a new session record.
81
+ * @param input.session - The verified session data.
82
+ * @param input.ttlSeconds - Time-to-live in seconds.
83
+ * @returns The created session record with unique ID.
84
+ */
85
+ create(input: {
86
+ session: SiwxSession;
87
+ ttlSeconds: number;
88
+ }): Promise<SiwxSessionRecord>;
89
+ /**
90
+ * Retrieves a session record by its opaque ID.
91
+ * @param id - The session ID.
92
+ * @returns The session record, or null if not found or expired.
93
+ */
94
+ get(id: string): Promise<SiwxSessionRecord | null>;
95
+ /**
96
+ * Atomically binds a user/subject identifier to the session.
97
+ * @param id - The session ID.
98
+ * @param subjectId - The user or subject ID.
99
+ * @returns True if binding succeeded, false if session not found.
100
+ */
101
+ bindSubject(id: string, subjectId: string): Promise<boolean>;
102
+ /**
103
+ * Revokes and removes a session record.
104
+ * @param id - The session ID.
105
+ */
106
+ revoke(id: string): Promise<void>;
107
+ }
108
+ /**
109
+ * Durable nonce store interface for single-use nonce issuance and atomic consumption.
110
+ */
111
+ interface SiwxNonceStore {
112
+ /**
113
+ * Issues and stores a new challenge nonce with TTL.
114
+ * @param input.nonce - The unique nonce string.
115
+ * @param input.ttlSeconds - Time-to-live in seconds (typically 300s).
116
+ */
117
+ issue(input: {
118
+ nonce: string;
119
+ ttlSeconds: number;
120
+ }): Promise<void>;
121
+ /**
122
+ * Atomically consumes a nonce, guaranteeing single-use.
123
+ * @param input.nonce - The nonce string to consume.
124
+ * @returns True if the nonce was valid and consumed, false if already consumed or expired.
125
+ */
126
+ consume(input: {
127
+ nonce: string;
128
+ }): Promise<boolean>;
129
+ }
130
+ /**
131
+ * Compact payload structure for stateless demo session tokens.
132
+ */
133
+ interface StatelessDemoTokenPayload {
134
+ version: 1;
135
+ address: string;
136
+ chainId: string;
137
+ domain: string;
138
+ nonce: string;
139
+ issuedAt: string;
140
+ expirationTime?: string;
141
+ sessionId: string;
142
+ mode: 'demo';
143
+ }
144
+ /**
145
+ * Limits for stateless demo profile.
146
+ */
147
+ interface StatelessDemoLimits {
148
+ /** Maximum transaction payload size in bytes. */
149
+ maxTransactionPayloadBytes?: number;
150
+ /** Advisory request cap per session. */
151
+ maxRequestsPerSession?: number;
152
+ }
153
+ /**
154
+ * Options for cookie session serialization.
155
+ */
156
+ interface CookieOptions {
157
+ /**
158
+ * The name of the cookie.
159
+ * @default "siwx-session-v2"
160
+ */
161
+ name?: string;
162
+ /**
163
+ * Max age in seconds. Defaults to 7 days for durable, 30 minutes for demo.
164
+ * @default 604800
165
+ */
166
+ maxAge?: number;
167
+ /**
168
+ * The cookie path.
169
+ * @default "/"
170
+ */
171
+ path?: string;
172
+ /**
173
+ * The cookie domain.
174
+ */
175
+ domain?: string;
176
+ /**
177
+ * Whether to set the Secure flag.
178
+ * @default true
179
+ */
180
+ secure?: boolean;
181
+ /**
182
+ * The SameSite policy.
183
+ * @default "Strict"
184
+ */
185
+ sameSite?: 'Strict' | 'Lax' | 'None';
186
+ }
187
+ /**
188
+ * Converts a ParsedSiwxMessage to a lean SiwxSession object.
189
+ * @internal
190
+ */
191
+ declare function toSession(parsed: ParsedSiwxMessage): SiwxSession;
192
+
193
+ export { type CookieOptions as C, type SiwxNonceStore as S, type SiwxSessionStore as a, type SiwxSession as b, type SiwxSessionRecord as c, type ServerVerifyOptions as d, type ServerVerifyResult as e, type StatelessDemoLimits as f, type StatelessDemoTokenPayload as g, toSession as t };
@@ -0,0 +1,193 @@
1
+ import { SiwxVerificationPolicy, SiwxVerifyResult, ParsedSiwxMessage } from '@tuwaio/siwx-core';
2
+
3
+ /**
4
+ * @fileoverview Server-side types for the @tuwaio/siwx-server package.
5
+ */
6
+
7
+ /**
8
+ * Options for the `verifySiwxPayload` function.
9
+ */
10
+ interface ServerVerifyOptions {
11
+ /**
12
+ * A set of nonces that have already been used.
13
+ * If the payload's nonce is found in this set, verification will fail
14
+ * to prevent replay attacks.
15
+ */
16
+ usedNonces?: Set<string>;
17
+ /**
18
+ * If true, skips the `expirationTime` validation check.
19
+ * Not recommended for production use.
20
+ * @default false
21
+ */
22
+ skipExpiration?: boolean;
23
+ /**
24
+ * Optional verification policy to enforce on the message fields.
25
+ */
26
+ policy?: SiwxVerificationPolicy;
27
+ /**
28
+ * Optional viem `PublicClient` instance for EVM chain EIP-1271 (smart contract wallet) verification.
29
+ */
30
+ publicClient?: any;
31
+ }
32
+ /**
33
+ * The result of a server-side verification operation, extending the base result
34
+ * with the verification method used.
35
+ */
36
+ interface ServerVerifyResult extends SiwxVerifyResult {
37
+ /**
38
+ * The CAIP-2 namespace used for verification routing.
39
+ * `eip155` for EVM chains, `solana` for Solana.
40
+ */
41
+ namespace?: 'eip155' | 'solana';
42
+ }
43
+ /**
44
+ * Represents a serializable session object derived from a verified CAIP-122 message.
45
+ */
46
+ interface SiwxSession {
47
+ /** The verified CAIP-10 blockchain address. */
48
+ address: string;
49
+ /** The CAIP-2 chain ID the session is bound to. */
50
+ chainId: string;
51
+ /** The domain that issued the session. */
52
+ domain: string;
53
+ /** The nonce that was used. Must be invalidated server-side after use. */
54
+ nonce: string;
55
+ /** ISO 8601 timestamp when the session was issued. */
56
+ issuedAt: string;
57
+ /** ISO 8601 timestamp when the session expires, if set. */
58
+ expirationTime?: string;
59
+ }
60
+ /**
61
+ * Represents a stored session record in a durable session store.
62
+ */
63
+ interface SiwxSessionRecord {
64
+ /** Unique opaque session identifier (e.g. secure random UUID). */
65
+ id: string;
66
+ /** The verified SIWX session data. */
67
+ session: SiwxSession;
68
+ /** Optional subject ID (e.g., Payload User ID or internal database ID) bound to this session. */
69
+ subjectId?: string;
70
+ /** Timestamp in milliseconds when the session record was created. */
71
+ createdAt: number;
72
+ /** Timestamp in milliseconds when the session record expires. */
73
+ expiresAt: number;
74
+ }
75
+ /**
76
+ * Durable session store interface for production environments.
77
+ */
78
+ interface SiwxSessionStore {
79
+ /**
80
+ * Creates and stores a new session record.
81
+ * @param input.session - The verified session data.
82
+ * @param input.ttlSeconds - Time-to-live in seconds.
83
+ * @returns The created session record with unique ID.
84
+ */
85
+ create(input: {
86
+ session: SiwxSession;
87
+ ttlSeconds: number;
88
+ }): Promise<SiwxSessionRecord>;
89
+ /**
90
+ * Retrieves a session record by its opaque ID.
91
+ * @param id - The session ID.
92
+ * @returns The session record, or null if not found or expired.
93
+ */
94
+ get(id: string): Promise<SiwxSessionRecord | null>;
95
+ /**
96
+ * Atomically binds a user/subject identifier to the session.
97
+ * @param id - The session ID.
98
+ * @param subjectId - The user or subject ID.
99
+ * @returns True if binding succeeded, false if session not found.
100
+ */
101
+ bindSubject(id: string, subjectId: string): Promise<boolean>;
102
+ /**
103
+ * Revokes and removes a session record.
104
+ * @param id - The session ID.
105
+ */
106
+ revoke(id: string): Promise<void>;
107
+ }
108
+ /**
109
+ * Durable nonce store interface for single-use nonce issuance and atomic consumption.
110
+ */
111
+ interface SiwxNonceStore {
112
+ /**
113
+ * Issues and stores a new challenge nonce with TTL.
114
+ * @param input.nonce - The unique nonce string.
115
+ * @param input.ttlSeconds - Time-to-live in seconds (typically 300s).
116
+ */
117
+ issue(input: {
118
+ nonce: string;
119
+ ttlSeconds: number;
120
+ }): Promise<void>;
121
+ /**
122
+ * Atomically consumes a nonce, guaranteeing single-use.
123
+ * @param input.nonce - The nonce string to consume.
124
+ * @returns True if the nonce was valid and consumed, false if already consumed or expired.
125
+ */
126
+ consume(input: {
127
+ nonce: string;
128
+ }): Promise<boolean>;
129
+ }
130
+ /**
131
+ * Compact payload structure for stateless demo session tokens.
132
+ */
133
+ interface StatelessDemoTokenPayload {
134
+ version: 1;
135
+ address: string;
136
+ chainId: string;
137
+ domain: string;
138
+ nonce: string;
139
+ issuedAt: string;
140
+ expirationTime?: string;
141
+ sessionId: string;
142
+ mode: 'demo';
143
+ }
144
+ /**
145
+ * Limits for stateless demo profile.
146
+ */
147
+ interface StatelessDemoLimits {
148
+ /** Maximum transaction payload size in bytes. */
149
+ maxTransactionPayloadBytes?: number;
150
+ /** Advisory request cap per session. */
151
+ maxRequestsPerSession?: number;
152
+ }
153
+ /**
154
+ * Options for cookie session serialization.
155
+ */
156
+ interface CookieOptions {
157
+ /**
158
+ * The name of the cookie.
159
+ * @default "siwx-session-v2"
160
+ */
161
+ name?: string;
162
+ /**
163
+ * Max age in seconds. Defaults to 7 days for durable, 30 minutes for demo.
164
+ * @default 604800
165
+ */
166
+ maxAge?: number;
167
+ /**
168
+ * The cookie path.
169
+ * @default "/"
170
+ */
171
+ path?: string;
172
+ /**
173
+ * The cookie domain.
174
+ */
175
+ domain?: string;
176
+ /**
177
+ * Whether to set the Secure flag.
178
+ * @default true
179
+ */
180
+ secure?: boolean;
181
+ /**
182
+ * The SameSite policy.
183
+ * @default "Strict"
184
+ */
185
+ sameSite?: 'Strict' | 'Lax' | 'None';
186
+ }
187
+ /**
188
+ * Converts a ParsedSiwxMessage to a lean SiwxSession object.
189
+ * @internal
190
+ */
191
+ declare function toSession(parsed: ParsedSiwxMessage): SiwxSession;
192
+
193
+ export { type CookieOptions as C, type SiwxNonceStore as S, type SiwxSessionStore as a, type SiwxSession as b, type SiwxSessionRecord as c, type ServerVerifyOptions as d, type ServerVerifyResult as e, type StatelessDemoLimits as f, type StatelessDemoTokenPayload as g, toSession as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/siwx-server",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -68,15 +68,15 @@
68
68
  }
69
69
  ],
70
70
  "peerDependencies": {
71
- "@tuwaio/siwx-core": "0.1.0"
71
+ "@tuwaio/siwx-core": "0.2.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "tsup": "^8.5.1",
75
75
  "typescript": "^6.0.3",
76
76
  "viem": "^2.55.11",
77
- "@tuwaio/siwx-core": "0.1.0",
78
- "@tuwaio/siwx-solana": "0.1.0",
79
- "@tuwaio/siwx-evm": "0.1.0"
77
+ "@tuwaio/siwx-core": "0.2.0",
78
+ "@tuwaio/siwx-evm": "0.2.0",
79
+ "@tuwaio/siwx-solana": "0.2.0"
80
80
  },
81
81
  "scripts": {
82
82
  "start": "tsup src/index.ts --watch",
@@ -1,2 +0,0 @@
1
- 'use strict';var siwxCore=require('@tuwaio/siwx-core');function x(e){return {address:e.address,chainId:e.chainId,domain:e.domain,nonce:e.nonce,issuedAt:e.issuedAt,expirationTime:e.expirationTime}}async function h(e,r={}){try{let i=siwxCore.parseMessage(e.message),t=siwxCore.validateMessage(i,{skipExpiration:r.skipExpiration});if(!t.valid)return {success:!1,error:`Validation failed: ${t.errors.join(", ")}`};if(!r.skipExpiration&&i.expirationTime&&new Date(i.expirationTime)<new Date)throw new siwxCore.SiwxExpiredSessionError(i.expirationTime);if(r.usedNonces?.has(i.nonce))throw new siwxCore.SiwxNonceReplayError(i.nonce);let s=i.chainId.split(":")[0];if(!s||!["eip155","solana"].includes(s))throw new siwxCore.SiwxUnsupportedNamespaceError(s??"unknown");if(s==="eip155"){let{verifyEvmSignature:n}=await import('@tuwaio/siwx-evm');return {...await n(e.message,e.signature,{skipExpiration:r.skipExpiration,publicClient:r.publicClient}),namespace:s}}if(s==="solana"){let{verifyEd25519:n}=await import('@tuwaio/siwx-solana');return {...await n(e,{skipExpiration:r.skipExpiration}),namespace:s}}return {success:!1,error:"Unsupported namespace."}}catch(i){return i instanceof siwxCore.SiwxExpiredSessionError||i instanceof siwxCore.SiwxNonceReplayError||i instanceof siwxCore.SiwxUnsupportedNamespaceError?{success:false,error:i.message}:{success:false,error:`Server verification failed: ${String(i)}`}}}function m(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function g(e){let r=e.replace(/-/g,"+").replace(/_/g,"/");return atob(r)}function E(e,r={}){let{name:i="siwx-session",maxAge:t=3600*24*7,path:s="/",domain:n,secure:o=true,sameSite:l="Strict"}=r,c=m(JSON.stringify(e)),a=[`${i}=${c}`,`Max-Age=${t}`,`Path=${s}`,"HttpOnly",`SameSite=${l}`];return o&&a.push("Secure"),n&&a.push(`Domain=${n}`),{cookieHeader:a.join("; "),session:e,cookieValue:c}}function V(e){try{let r=g(e);return JSON.parse(r)}catch{return null}}
2
- Object.defineProperty(exports,"b",{enumerable:true,get:function(){return siwxCore.generateNonce}});exports.a=x;exports.c=h;exports.d=E;exports.e=V;
@@ -1,2 +0,0 @@
1
- import {parseMessage,validateMessage,SiwxExpiredSessionError,SiwxNonceReplayError,SiwxUnsupportedNamespaceError}from'@tuwaio/siwx-core';export{generateNonce as b}from'@tuwaio/siwx-core';function x(e){return {address:e.address,chainId:e.chainId,domain:e.domain,nonce:e.nonce,issuedAt:e.issuedAt,expirationTime:e.expirationTime}}async function h(e,r={}){try{let i=parseMessage(e.message),t=validateMessage(i,{skipExpiration:r.skipExpiration});if(!t.valid)return {success:!1,error:`Validation failed: ${t.errors.join(", ")}`};if(!r.skipExpiration&&i.expirationTime&&new Date(i.expirationTime)<new Date)throw new SiwxExpiredSessionError(i.expirationTime);if(r.usedNonces?.has(i.nonce))throw new SiwxNonceReplayError(i.nonce);let s=i.chainId.split(":")[0];if(!s||!["eip155","solana"].includes(s))throw new SiwxUnsupportedNamespaceError(s??"unknown");if(s==="eip155"){let{verifyEvmSignature:n}=await import('@tuwaio/siwx-evm');return {...await n(e.message,e.signature,{skipExpiration:r.skipExpiration,publicClient:r.publicClient}),namespace:s}}if(s==="solana"){let{verifyEd25519:n}=await import('@tuwaio/siwx-solana');return {...await n(e,{skipExpiration:r.skipExpiration}),namespace:s}}return {success:!1,error:"Unsupported namespace."}}catch(i){return i instanceof SiwxExpiredSessionError||i instanceof SiwxNonceReplayError||i instanceof SiwxUnsupportedNamespaceError?{success:false,error:i.message}:{success:false,error:`Server verification failed: ${String(i)}`}}}function m(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function g(e){let r=e.replace(/-/g,"+").replace(/_/g,"/");return atob(r)}function E(e,r={}){let{name:i="siwx-session",maxAge:t=3600*24*7,path:s="/",domain:n,secure:o=true,sameSite:l="Strict"}=r,c=m(JSON.stringify(e)),a=[`${i}=${c}`,`Max-Age=${t}`,`Path=${s}`,"HttpOnly",`SameSite=${l}`];return o&&a.push("Secure"),n&&a.push(`Domain=${n}`),{cookieHeader:a.join("; "),session:e,cookieValue:c}}function V(e){try{let r=g(e);return JSON.parse(r)}catch{return null}}
2
- export{x as a,h as c,E as d,V as e};
@@ -1,108 +0,0 @@
1
- import { SiwxVerifyResult, ParsedSiwxMessage } from '@tuwaio/siwx-core';
2
-
3
- /**
4
- * @fileoverview Server-side types for the @tuwaio/siwx-server package.
5
- */
6
-
7
- /**
8
- * Options for the `verifySiwxPayload` function.
9
- */
10
- interface ServerVerifyOptions {
11
- /**
12
- * A set of nonces that have already been used.
13
- * If the payload's nonce is found in this set, verification will fail
14
- * to prevent replay attacks. You should populate this from your session store or cache.
15
- */
16
- usedNonces?: Set<string>;
17
- /**
18
- * If true, skips the `expirationTime` validation check.
19
- * Not recommended for production use.
20
- * @default false
21
- */
22
- skipExpiration?: boolean;
23
- /**
24
- * Optional viem `PublicClient` instance for EVM chain EIP-1271 (smart contract wallet) verification.
25
- */
26
- publicClient?: any;
27
- }
28
- /**
29
- * The result of a server-side verification operation, extending the base result
30
- * with the verification method used.
31
- */
32
- interface ServerVerifyResult extends SiwxVerifyResult {
33
- /**
34
- * The CAIP-2 namespace used for verification routing.
35
- * `eip155` for EVM chains, `solana` for Solana.
36
- */
37
- namespace?: 'eip155' | 'solana';
38
- }
39
- /**
40
- * Represents a serializable session object derived from a verified CAIP-122 message.
41
- * This can be stored in a cookie or JWT payload.
42
- */
43
- interface SiwxSession {
44
- /** The verified CAIP-10 blockchain address. */
45
- address: string;
46
- /** The CAIP-2 chain ID the session is bound to. */
47
- chainId: string;
48
- /** The domain that issued the session. */
49
- domain: string;
50
- /** The nonce that was used. Must be invalidated server-side after use. */
51
- nonce: string;
52
- /** ISO 8601 timestamp when the session was issued. */
53
- issuedAt: string;
54
- /** ISO 8601 timestamp when the session expires, if set. */
55
- expirationTime?: string;
56
- }
57
- /**
58
- * Options for cookie session serialization.
59
- */
60
- interface CookieOptions {
61
- /**
62
- * The name of the cookie.
63
- * @default "siwx-session"
64
- */
65
- name?: string;
66
- /**
67
- * Max age in seconds. Defaults to 7 days.
68
- * @default 604800
69
- */
70
- maxAge?: number;
71
- /**
72
- * The cookie path.
73
- * @default "/"
74
- */
75
- path?: string;
76
- /**
77
- * The cookie domain.
78
- */
79
- domain?: string;
80
- /**
81
- * Whether to set the Secure flag.
82
- * @default true
83
- */
84
- secure?: boolean;
85
- /**
86
- * The SameSite policy.
87
- * @default "Strict"
88
- */
89
- sameSite?: 'Strict' | 'Lax' | 'None';
90
- }
91
- /**
92
- * The serialized cookie string and session data together.
93
- */
94
- interface SerializedCookieSession {
95
- /** The full `Set-Cookie` header value. */
96
- cookieHeader: string;
97
- /** The session data embedded in the cookie. */
98
- session: SiwxSession;
99
- /** The base64url-encoded session payload (the cookie value). */
100
- cookieValue: string;
101
- }
102
- /**
103
- * Converts a ParsedSiwxMessage to a lean SiwxSession object.
104
- * @internal
105
- */
106
- declare function toSession(parsed: ParsedSiwxMessage): SiwxSession;
107
-
108
- export { type CookieOptions as C, type SiwxSession as S, type SerializedCookieSession as a, type ServerVerifyOptions as b, type ServerVerifyResult as c, toSession as t };
@@ -1,108 +0,0 @@
1
- import { SiwxVerifyResult, ParsedSiwxMessage } from '@tuwaio/siwx-core';
2
-
3
- /**
4
- * @fileoverview Server-side types for the @tuwaio/siwx-server package.
5
- */
6
-
7
- /**
8
- * Options for the `verifySiwxPayload` function.
9
- */
10
- interface ServerVerifyOptions {
11
- /**
12
- * A set of nonces that have already been used.
13
- * If the payload's nonce is found in this set, verification will fail
14
- * to prevent replay attacks. You should populate this from your session store or cache.
15
- */
16
- usedNonces?: Set<string>;
17
- /**
18
- * If true, skips the `expirationTime` validation check.
19
- * Not recommended for production use.
20
- * @default false
21
- */
22
- skipExpiration?: boolean;
23
- /**
24
- * Optional viem `PublicClient` instance for EVM chain EIP-1271 (smart contract wallet) verification.
25
- */
26
- publicClient?: any;
27
- }
28
- /**
29
- * The result of a server-side verification operation, extending the base result
30
- * with the verification method used.
31
- */
32
- interface ServerVerifyResult extends SiwxVerifyResult {
33
- /**
34
- * The CAIP-2 namespace used for verification routing.
35
- * `eip155` for EVM chains, `solana` for Solana.
36
- */
37
- namespace?: 'eip155' | 'solana';
38
- }
39
- /**
40
- * Represents a serializable session object derived from a verified CAIP-122 message.
41
- * This can be stored in a cookie or JWT payload.
42
- */
43
- interface SiwxSession {
44
- /** The verified CAIP-10 blockchain address. */
45
- address: string;
46
- /** The CAIP-2 chain ID the session is bound to. */
47
- chainId: string;
48
- /** The domain that issued the session. */
49
- domain: string;
50
- /** The nonce that was used. Must be invalidated server-side after use. */
51
- nonce: string;
52
- /** ISO 8601 timestamp when the session was issued. */
53
- issuedAt: string;
54
- /** ISO 8601 timestamp when the session expires, if set. */
55
- expirationTime?: string;
56
- }
57
- /**
58
- * Options for cookie session serialization.
59
- */
60
- interface CookieOptions {
61
- /**
62
- * The name of the cookie.
63
- * @default "siwx-session"
64
- */
65
- name?: string;
66
- /**
67
- * Max age in seconds. Defaults to 7 days.
68
- * @default 604800
69
- */
70
- maxAge?: number;
71
- /**
72
- * The cookie path.
73
- * @default "/"
74
- */
75
- path?: string;
76
- /**
77
- * The cookie domain.
78
- */
79
- domain?: string;
80
- /**
81
- * Whether to set the Secure flag.
82
- * @default true
83
- */
84
- secure?: boolean;
85
- /**
86
- * The SameSite policy.
87
- * @default "Strict"
88
- */
89
- sameSite?: 'Strict' | 'Lax' | 'None';
90
- }
91
- /**
92
- * The serialized cookie string and session data together.
93
- */
94
- interface SerializedCookieSession {
95
- /** The full `Set-Cookie` header value. */
96
- cookieHeader: string;
97
- /** The session data embedded in the cookie. */
98
- session: SiwxSession;
99
- /** The base64url-encoded session payload (the cookie value). */
100
- cookieValue: string;
101
- }
102
- /**
103
- * Converts a ParsedSiwxMessage to a lean SiwxSession object.
104
- * @internal
105
- */
106
- declare function toSession(parsed: ParsedSiwxMessage): SiwxSession;
107
-
108
- export { type CookieOptions as C, type SiwxSession as S, type SerializedCookieSession as a, type ServerVerifyOptions as b, type ServerVerifyResult as c, toSession as t };