@tuwaio/siwx-server 0.2.2 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -1,49 +1,51 @@
1
1
  import * as _tuwaio_siwx_core from '@tuwaio/siwx-core';
2
2
  import { SiwxVerificationPolicy, SiwxVerifyResult, ParsedSiwxMessage, SiwxVerifyPayload } from '@tuwaio/siwx-core';
3
3
  export { ParsedSiwxMessage, SiwxMessageFields, SiwxSessionLike, SiwxVerificationPolicy, ValidateMessageOptions, generateNonce, generateNonce as generateServerNonce, isSessionMatchingTarget, validateMessage, validatePolicy } from '@tuwaio/siwx-core';
4
+ import { PublicClient } from 'viem';
4
5
 
5
6
  /**
6
- * @fileoverview Server-side types for the @tuwaio/siwx-server package.
7
+ * @file Server-side types for the @tuwaio/siwx-server package.
7
8
  */
8
9
 
9
10
  /**
10
- * Options for the `verifySiwxPayload` function.
11
+ * Options of {@link verifySiwxPayload}.
11
12
  */
12
13
  interface ServerVerifyOptions {
13
14
  /**
14
- * A set of nonces that have already been used.
15
- * If the payload's nonce is found in this set, verification will fail
16
- * to prevent replay attacks.
15
+ * Nonces that must be rejected. Verification fails when the message nonce is in the set. The set is only read:
16
+ * record used nonces yourself, or use a {@link SiwxNonceStore} (as `createSiwxApiHandler` does) for
17
+ * multi-instance deployments.
17
18
  */
18
19
  usedNonces?: Set<string>;
19
20
  /**
20
- * If true, skips the `expirationTime` validation check.
21
- * Not recommended for production use.
21
+ * Skips the check that the message `expirationTime` has not passed. Not recommended in production.
22
22
  * @default false
23
23
  */
24
24
  skipExpiration?: boolean;
25
25
  /**
26
- * Optional verification policy to enforce on the message fields.
26
+ * Verification policy enforced on the message fields (domain, URI, chains, timing). See
27
+ * {@link SiwxVerificationPolicy}.
27
28
  */
28
29
  policy?: SiwxVerificationPolicy;
29
30
  /**
30
- * Optional viem `PublicClient` instance for EVM chain EIP-1271 (smart contract wallet) verification.
31
+ * viem `PublicClient` for the chain of the message. Enables the EIP-1271 (smart contract wallet) fallback for
32
+ * `eip155` messages; ignored for Solana.
31
33
  */
32
- publicClient?: any;
34
+ publicClient?: PublicClient;
33
35
  }
34
36
  /**
35
- * The result of a server-side verification operation, extending the base result
36
- * with the verification method used.
37
+ * Result of {@link verifySiwxPayload}.
37
38
  */
38
39
  interface ServerVerifyResult extends SiwxVerifyResult {
39
40
  /**
40
- * The CAIP-2 namespace used for verification routing.
41
- * `eip155` for EVM chains, `solana` for Solana.
41
+ * The CAIP-2 namespace whose verifier checked the signature: `eip155` or `solana`. Absent when verification
42
+ * failed before the signature check.
42
43
  */
43
44
  namespace?: 'eip155' | 'solana';
44
45
  }
45
46
  /**
46
- * Represents a serializable session object derived from a verified CAIP-122 message.
47
+ * Serializable session derived from a verified CAIP-122 message (see {@link toSession}). Returned as JSON by the
48
+ * `verify` and `session` endpoints of `@tuwaio/siwx-server/next`.
47
49
  */
48
50
  interface SiwxSession {
49
51
  /** The verified CAIP-10 blockchain address. */
@@ -52,7 +54,7 @@ interface SiwxSession {
52
54
  chainId: string;
53
55
  /** The domain that issued the session. */
54
56
  domain: string;
55
- /** The nonce that was used. Must be invalidated server-side after use. */
57
+ /** The nonce of the signed message. It must be single-use: consume it in a {@link SiwxNonceStore}. */
56
58
  nonce: string;
57
59
  /** ISO 8601 timestamp when the session was issued. */
58
60
  issuedAt: string;
@@ -60,14 +62,14 @@ interface SiwxSession {
60
62
  expirationTime?: string;
61
63
  }
62
64
  /**
63
- * Represents a stored session record in a durable session store.
65
+ * A session stored in a {@link SiwxSessionStore}.
64
66
  */
65
67
  interface SiwxSessionRecord {
66
- /** Unique opaque session identifier (e.g. secure random UUID). */
68
+ /** Opaque, unguessable session ID. It is the value of the session cookie. */
67
69
  id: string;
68
70
  /** The verified SIWX session data. */
69
71
  session: SiwxSession;
70
- /** Optional subject ID (e.g., Payload User ID or internal database ID) bound to this session. */
72
+ /** Optional ID of your own user record (for example a database user ID), set with `bindSubject`. */
71
73
  subjectId?: string;
72
74
  /** Timestamp in milliseconds when the session record was created. */
73
75
  createdAt: number;
@@ -75,90 +77,109 @@ interface SiwxSessionRecord {
75
77
  expiresAt: number;
76
78
  }
77
79
  /**
78
- * Durable session store interface for production environments.
80
+ * Storage contract for durable sessions (Redis, SQL, KV…), used by `createSiwxApiHandler` and
81
+ * {@link getSiwxServerSession}. Implementations must be shared by every server instance.
82
+ * {@link MemorySiwxSessionStore} is an in-memory implementation for development and tests.
79
83
  */
80
84
  interface SiwxSessionStore {
81
85
  /**
82
86
  * Creates and stores a new session record.
87
+ * @param input - The session to store.
83
88
  * @param input.session - The verified session data.
84
89
  * @param input.ttlSeconds - Time-to-live in seconds.
85
- * @returns The created session record with unique ID.
90
+ * @returns The created record. Its `id` must be unguessable, because it becomes the session cookie value.
86
91
  */
87
92
  create(input: {
88
93
  session: SiwxSession;
89
94
  ttlSeconds: number;
90
95
  }): Promise<SiwxSessionRecord>;
91
96
  /**
92
- * Retrieves a session record by its opaque ID.
97
+ * Retrieves a session record by its ID. Session expiry is enforced here: SIWX does not compare `expiresAt` itself.
93
98
  * @param id - The session ID.
94
- * @returns The session record, or null if not found or expired.
99
+ * @returns The session record, or `null` if it does not exist or has expired.
95
100
  */
96
101
  get(id: string): Promise<SiwxSessionRecord | null>;
97
102
  /**
98
- * Atomically binds a user/subject identifier to the session.
103
+ * Binds one of your user IDs to the session. Not called by SIWX; use it after sign-in to link the wallet session to
104
+ * your own user record.
99
105
  * @param id - The session ID.
100
106
  * @param subjectId - The user or subject ID.
101
- * @returns True if binding succeeded, false if session not found.
107
+ * @returns `true` if the session exists and was updated, `false` otherwise.
102
108
  */
103
109
  bindSubject(id: string, subjectId: string): Promise<boolean>;
104
110
  /**
105
- * Revokes and removes a session record.
111
+ * Revokes a session. Must succeed when the session does not exist.
106
112
  * @param id - The session ID.
113
+ * @returns A promise that resolves once the session is removed.
107
114
  */
108
115
  revoke(id: string): Promise<void>;
109
116
  }
110
117
  /**
111
- * Durable nonce store interface for single-use nonce issuance and atomic consumption.
118
+ * Storage contract for single-use challenge nonces, used by `createSiwxApiHandler`. Implementations must be shared
119
+ * by every server instance and `consume` must be atomic (for example Redis `GETDEL`).
120
+ * {@link MemorySiwxNonceStore} is an in-memory implementation for development and tests.
112
121
  */
113
122
  interface SiwxNonceStore {
114
123
  /**
115
- * Issues and stores a new challenge nonce with TTL.
116
- * @param input.nonce - The unique nonce string.
117
- * @param input.ttlSeconds - Time-to-live in seconds (typically 300s).
124
+ * Stores a newly issued nonce.
125
+ * @param input - The nonce to store.
126
+ * @param input.nonce - The nonce string.
127
+ * @param input.ttlSeconds - Time-to-live in seconds. `createSiwxApiHandler` uses 300.
128
+ * @returns A promise that resolves once the nonce is stored.
118
129
  */
119
130
  issue(input: {
120
131
  nonce: string;
121
132
  ttlSeconds: number;
122
133
  }): Promise<void>;
123
134
  /**
124
- * Atomically consumes a nonce, guaranteeing single-use.
135
+ * Atomically removes a nonce, so that each nonce is accepted once.
136
+ * @param input - The nonce to consume.
125
137
  * @param input.nonce - The nonce string to consume.
126
- * @returns True if the nonce was valid and consumed, false if already consumed or expired.
138
+ * @returns `true` if the nonce was issued, not expired and not consumed before; otherwise `false`.
127
139
  */
128
140
  consume(input: {
129
141
  nonce: string;
130
142
  }): Promise<boolean>;
131
143
  }
132
144
  /**
133
- * Compact payload structure for stateless demo session tokens.
145
+ * JSON payload of a stateless demo session token (see {@link signStatelessDemoSession}). The token is signed, not
146
+ * encrypted: anyone holding it can read these fields.
134
147
  */
135
148
  interface StatelessDemoTokenPayload {
149
+ /** Token format version. */
136
150
  version: 1;
151
+ /** CAIP-10 account ID of the session. */
137
152
  address: string;
153
+ /** CAIP-2 chain ID of the session. */
138
154
  chainId: string;
155
+ /** Domain of the signed message. */
139
156
  domain: string;
157
+ /** Nonce of the signed message. */
140
158
  nonce: string;
159
+ /** `issuedAt` of the signed message. */
141
160
  issuedAt: string;
161
+ /** Expiry of the token: the message `expirationTime`, or the issuing time plus the token TTL. */
142
162
  expirationTime?: string;
163
+ /** Random ID of the token. */
143
164
  sessionId: string;
165
+ /** Token mode. */
144
166
  mode: 'demo';
145
167
  }
146
168
  /**
147
- * Enforceable request boundary limits for the stateless demo profile.
148
- *
149
- * Note: Shared rate limits and request quotas across multiple replicas require
150
- * a durable store or are authoritative at the Quasar App RPS / Quota layer.
169
+ * Request limits of `createStatelessDemoSiwxHandler`. Only the body size is limited; rate limiting is not part of
170
+ * SIWX.
151
171
  */
152
172
  interface StatelessDemoLimits {
153
173
  /**
154
- * Maximum allowed incoming payload body size in bytes for SIWX verification endpoints.
155
- * Requests exceeding this limit will be rejected with HTTP 413 (Payload Too Large).
174
+ * Maximum body size of `POST /verify`. Larger requests are rejected with HTTP 413. The durable handler always
175
+ * uses 65536.
156
176
  * @default 65536 (64 KB)
157
177
  */
158
178
  maxTransactionPayloadBytes?: number;
159
179
  }
160
180
  /**
161
- * Options for cookie session serialization.
181
+ * Attributes of the session cookie, used by {@link createSessionCookie}, {@link createClearCookie} and the
182
+ * `@tuwaio/siwx-server/next` handlers. The cookie is always `HttpOnly`.
162
183
  */
163
184
  interface CookieOptions {
164
185
  /**
@@ -167,7 +188,8 @@ interface CookieOptions {
167
188
  */
168
189
  name?: string;
169
190
  /**
170
- * Max age in seconds. Defaults to 7 days for durable, 30 minutes for demo.
191
+ * `Max-Age` in seconds. {@link createSessionCookie} defaults to 604800 (7 days). The handlers use their
192
+ * `ttlSeconds` instead, and fall back to this value when `ttlSeconds` is not set.
171
193
  * @default 604800
172
194
  */
173
195
  maxAge?: number;
@@ -192,15 +214,17 @@ interface CookieOptions {
192
214
  sameSite?: 'Strict' | 'Lax' | 'None';
193
215
  }
194
216
  /**
195
- * Options for the `getSiwxServerSession` helper function.
217
+ * Options of {@link getSiwxServerSession}.
196
218
  */
197
219
  interface GetSiwxServerSessionOptions {
198
220
  /**
199
- * Cookie source:
200
- * - A raw Cookie string (e.g. `req.headers.get('cookie')` or `"siwx-session-v2=xyz"`)
201
- * - A Next.js ReadonlyRequestCookies object (from `await cookies()`)
202
- * - A Web API `Request` or `Headers` object
203
- * - Any object with a `get(name)` method
221
+ * Where to read the session cookie from:
222
+ * - a `Cookie` header string (`"siwx-session-v2=…; other=…"`) or the bare cookie value;
223
+ * - a Web API `Request`;
224
+ * - the Next.js cookie store (`await cookies()`) or any object with `get(name)` returning `{ value }` or a string;
225
+ * - a Web API `Headers` object.
226
+ *
227
+ * `null` and `undefined` resolve to no session.
204
228
  */
205
229
  cookieSource: string | Request | Headers | {
206
230
  get(name: string): {
@@ -213,72 +237,136 @@ interface GetSiwxServerSessionOptions {
213
237
  */
214
238
  cookieName?: string;
215
239
  /**
216
- * Durable session store (for production durable sessions).
240
+ * Store of the durable profile. The cookie value is looked up with `sessionStore.get`. Takes precedence over
241
+ * `signingSecret`.
217
242
  */
218
243
  sessionStore?: SiwxSessionStore;
219
244
  /**
220
- * Server HMAC secret key (for stateless demo sessions).
245
+ * HMAC secret of the stateless demo profile. The cookie value is verified with
246
+ * {@link verifyStatelessDemoSession}.
221
247
  */
222
248
  signingSecret?: string;
223
249
  /**
224
- * Optional verification policy to validate the session.
250
+ * Policy checked against the stored session. Only a subset applies: `expectedDomain`, `allowedChainIds` (exact
251
+ * match) and, for durable sessions, `requireExpirationTime`; for demo tokens, expiry with `clockSkewSeconds`.
225
252
  */
226
253
  policy?: SiwxVerificationPolicy;
227
254
  }
228
255
  /**
229
- * Converts a ParsedSiwxMessage to a lean SiwxSession object.
230
- * @internal
256
+ * Converts a verified CAIP-122 message into a {@link SiwxSession}: keeps `address`, `chainId`, `domain`, `nonce`,
257
+ * `issuedAt` and `expirationTime`. Pure function.
258
+ *
259
+ * @param parsed - The verified message, for example `result.data` of {@link verifySiwxPayload}.
260
+ * @returns The session object to store or sign.
231
261
  */
232
262
  declare function toSession(parsed: ParsedSiwxMessage): SiwxSession;
233
263
 
234
264
  /**
235
- * Parses and validates a raw CAIP-122 payload (message + signature) on the server side.
236
- * Dynamically routes verification to the correct chain adapter based on the CAIP-2 namespace.
265
+ * Verifies a signed CAIP-122 message on the server, for any supported chain.
266
+ *
267
+ * Steps: parse the message, run {@link validateMessage} with `options.policy` (format, expiration with
268
+ * `clockSkewSeconds`, `notBefore` and the policy rules), reject nonces listed in `options.usedNonces`, then route by the `chainId` namespace to `verifyEvmSignature`
269
+ * (`@tuwaio/siwx-evm`, with the EIP-1271 fallback when `options.publicClient` is set) or `verifyEd25519`
270
+ * (`@tuwaio/siwx-solana`).
237
271
  *
238
- * @param payload - The `{ message, signature }` payload sent by the client.
239
- * @param options - Server-side verification options (policy, nonce replay protection, etc.).
240
- * @returns A `ServerVerifyResult` with `success: true` and the parsed session data, or an error.
272
+ * Side effects: dynamically imports the chain package of the namespace, so `@tuwaio/siwx-evm` and/or
273
+ * `@tuwaio/siwx-solana` must be installed for the chains you accept; the EIP-1271 fallback makes one RPC call.
274
+ * It does not consume nonces or create sessions: pair it with a {@link SiwxNonceStore} and a
275
+ * {@link SiwxSessionStore}, or use the handlers of `@tuwaio/siwx-server/next`.
276
+ *
277
+ * @param payload - The `{ message, signature }` sent by the client.
278
+ * @param options - Policy, replay protection and chain options.
279
+ * @returns `{ success: true, data, namespace }` with the parsed message, or `{ success: false, error }`. Never
280
+ * throws: every failure is returned as `error`.
241
281
  */
242
282
  declare function verifySiwxPayload(payload: SiwxVerifyPayload, options?: ServerVerifyOptions): Promise<ServerVerifyResult>;
243
283
  /**
244
- * Signs a stateless demo session into an authenticated compact token.
245
- * Uses Web Crypto HMAC-SHA256.
284
+ * Creates a stateless demo session token: the session as base64url JSON ({@link StatelessDemoTokenPayload}) plus
285
+ * an HMAC-SHA256 signature (Web Crypto). The token is signed, not encrypted, and cannot be revoked before it
286
+ * expires.
246
287
  *
247
288
  * @param session - The verified session to sign.
248
- * @param secret - Server-only signing secret (minimum 32 bytes).
249
- * @param ttlSeconds - Maximum session validity in seconds (default 1800 = 30m).
250
- * @returns Authenticated compact token in `${payload}.${signature}` format.
289
+ * @param secret - Server-only signing secret of at least 32 characters.
290
+ * @param ttlSeconds - Token lifetime in seconds, used only when the session has no `expirationTime`; otherwise the
291
+ * token expires with the message.
292
+ * @returns The token, formatted as `{payload}.{signature}`.
293
+ * @throws {Error} If `secret` is shorter than 32 characters.
251
294
  */
252
295
  declare function signStatelessDemoSession(session: SiwxSession, secret: string, ttlSeconds?: number): Promise<string>;
253
296
  /**
254
- * Verifies an authenticated stateless demo session token.
255
- * Performs constant-time cryptographic verification and validates expiration and policy.
297
+ * Verifies a token created by {@link signStatelessDemoSession}: checks the HMAC signature with Web Crypto, the
298
+ * token version and mode, and its expiry (with `policy.clockSkewSeconds`, 60 seconds by default).
299
+ *
300
+ * Only `expectedDomain` and `allowedChainIds` (exact match) of the policy are applied; other policy fields are
301
+ * ignored because they were checked when the token was issued.
256
302
  *
257
- * @param token - Compact token from cookie (`${payload}.${signature}`).
258
- * @param secret - Server-only signing secret.
259
- * @param policy - Optional verification policy to enforce.
260
- * @returns The verified SiwxSession, or null if invalid, expired, or tampered.
303
+ * @param token - The token from the session cookie.
304
+ * @param secret - The secret the token was signed with.
305
+ * @param policy - Optional policy to check against the token.
306
+ * @returns The session, or `null` if the token is missing, malformed, tampered, expired or rejected by the policy.
307
+ * Never throws.
261
308
  */
262
309
  declare function verifyStatelessDemoSession(token: string | null | undefined, secret: string, policy?: _tuwaio_siwx_core.SiwxVerificationPolicy): Promise<SiwxSession | null>;
263
310
  /**
264
- * Creates an HttpOnly Set-Cookie header value for a session.
311
+ * Issues a challenge nonce for the stateless demo profile: a random value and an expiry time, signed with
312
+ * HMAC-SHA256 (Web Crypto), encoded as 106 lowercase hex characters so that it is a valid CAIP-122 nonce.
313
+ * {@link verifyStatelessDemoNonce} can then check, without any storage, that the server issued the nonce and that it
314
+ * has not expired.
315
+ *
316
+ * @param secret - Server-only signing secret of at least 32 characters.
317
+ * @param ttlSeconds - How long the nonce can be used, in seconds.
318
+ * @returns The signed nonce.
319
+ * @throws {Error} If `secret` is shorter than 32 characters.
320
+ */
321
+ declare function issueStatelessDemoNonce(secret: string, ttlSeconds?: number): Promise<string>;
322
+ /**
323
+ * Checks a nonce issued by {@link issueStatelessDemoNonce}: its format, its HMAC signature (constant-time, Web
324
+ * Crypto) and its expiry. It does not track usage, so the same nonce passes until it expires; callers that need
325
+ * single use must remember consumed nonces (`createStatelessDemoSiwxHandler` does so per server instance).
326
+ *
327
+ * @param nonce - The nonce of the signed message.
328
+ * @param secret - The secret the nonce was issued with.
329
+ * @returns `true` if the nonce was issued with `secret` and has not expired; otherwise `false`. Never throws.
330
+ */
331
+ declare function verifyStatelessDemoNonce(nonce: string, secret: string): Promise<boolean>;
332
+ /**
333
+ * Formats a `Set-Cookie` header value for the session cookie: `HttpOnly`, `Secure` and `SameSite=Strict` by
334
+ * default.
335
+ *
336
+ * @param value - The cookie value (session ID or demo token). Written as-is, without encoding.
337
+ * @param opts - Cookie attributes. Defaults: name `siwx-session-v2`, `Max-Age` 604800, path `/`.
338
+ * @returns The header value, e.g. `siwx-session-v2=…; Max-Age=604800; Path=/; HttpOnly; SameSite=Strict; Secure`.
265
339
  */
266
340
  declare function createSessionCookie(value: string, opts?: CookieOptions): string;
267
341
  /**
268
- * Creates a clear/destroy Set-Cookie header value.
342
+ * Formats a `Set-Cookie` header value that deletes the session cookie (`Max-Age=0` and an expiry date in the
343
+ * past). Use the same `name`, `path` and `domain` as when the cookie was set.
344
+ *
345
+ * @param opts - Cookie attributes. `maxAge` is ignored.
346
+ * @returns The header value.
269
347
  */
270
348
  declare function createClearCookie(opts?: CookieOptions): string;
271
349
  /**
272
- * Extracts a cookie value by name from a raw Cookie header string.
350
+ * Reads one cookie from a `Cookie` request header. Pairs must be separated by `"; "`; values are returned as-is,
351
+ * without URL-decoding.
352
+ *
353
+ * @param cookieHeader - The `Cookie` header value.
354
+ * @param name - The cookie name.
355
+ * @returns The cookie value, or `null` when the header is empty or has no such cookie.
273
356
  */
274
357
  declare function parseCookie(cookieHeader: string | null | undefined, name: string): string | null;
275
358
  /**
276
- * In-memory implementation of SiwxSessionStore.
277
- * STRICTLY for local development, prototyping, and unit testing.
278
- * Fails closed in production environments.
359
+ * In-memory {@link SiwxSessionStore} for local development and tests. Sessions live in a `Map` of the current
360
+ * process: they are lost on restart and not shared between instances or serverless invocations. Session IDs are
361
+ * 32-character hex strings from {@link generateNonce}.
279
362
  */
280
363
  declare class MemorySiwxSessionStore implements SiwxSessionStore {
281
364
  private records;
365
+ /**
366
+ * @param options - Store options.
367
+ * @param options.allowInProduction - Allows the store when `NODE_ENV` is `production`.
368
+ * @throws {Error} When `process.env.NODE_ENV` is `production` and `allowInProduction` is not `true`.
369
+ */
282
370
  constructor(options?: {
283
371
  allowInProduction?: boolean;
284
372
  });
@@ -291,12 +379,17 @@ declare class MemorySiwxSessionStore implements SiwxSessionStore {
291
379
  revoke(id: string): Promise<void>;
292
380
  }
293
381
  /**
294
- * In-memory implementation of SiwxNonceStore.
295
- * STRICTLY for local development, prototyping, and unit testing.
296
- * Fails closed in production environments.
382
+ * In-memory {@link SiwxNonceStore} for local development and tests. Nonces live in a `Map` of the current process:
383
+ * they are lost on restart and not shared between instances or serverless invocations, so a nonce issued by one
384
+ * instance is rejected by another.
297
385
  */
298
386
  declare class MemorySiwxNonceStore implements SiwxNonceStore {
299
387
  private nonces;
388
+ /**
389
+ * @param options - Store options.
390
+ * @param options.allowInProduction - Allows the store when `NODE_ENV` is `production`.
391
+ * @throws {Error} When `process.env.NODE_ENV` is `production` and `allowInProduction` is not `true`.
392
+ */
300
393
  constructor(options?: {
301
394
  allowInProduction?: boolean;
302
395
  });
@@ -309,11 +402,17 @@ declare class MemorySiwxNonceStore implements SiwxNonceStore {
309
402
  }): Promise<boolean>;
310
403
  }
311
404
  /**
312
- * Resolves and verifies an active SIWX session strictly on the server side.
313
- * Supports both durable session stores and stateless HMAC-signed demo cookies.
405
+ * Reads the SIWX session of the current request from its session cookie. Use it in Server Actions, Route Handlers
406
+ * or any server code instead of trusting session data sent by the client.
407
+ *
408
+ * With `sessionStore`, the cookie value is a session ID looked up with `sessionStore.get` (which enforces
409
+ * expiry). Otherwise, with `signingSecret`, it is a demo token verified with {@link verifyStatelessDemoSession}.
410
+ * See {@link GetSiwxServerSessionOptions} for the accepted cookie sources and the policy checks.
314
411
  *
315
- * @param options - Configuration including cookieSource, sessionStore or signingSecret, and optional policy.
316
- * @returns The verified `SiwxSession` object, or `null` if invalid, expired, or absent.
412
+ * @param options - Cookie source, store or secret, and optional policy.
413
+ * @returns The session, or `null` when there is no cookie, no store or secret, or the session is unknown, expired or
414
+ * rejected by the policy.
415
+ * @throws Errors thrown by `sessionStore.get` are not caught.
317
416
  *
318
417
  * @example
319
418
  * ```ts
@@ -330,4 +429,4 @@ declare class MemorySiwxNonceStore implements SiwxNonceStore {
330
429
  */
331
430
  declare function getSiwxServerSession(options: GetSiwxServerSessionOptions): Promise<SiwxSession | null>;
332
431
 
333
- export { type CookieOptions, type GetSiwxServerSessionOptions, MemorySiwxNonceStore, MemorySiwxSessionStore, type ServerVerifyOptions, type ServerVerifyResult, type SiwxNonceStore, type SiwxSession, type SiwxSessionRecord, type SiwxSessionStore, type StatelessDemoLimits, type StatelessDemoTokenPayload, createClearCookie, createSessionCookie, getSiwxServerSession, parseCookie, signStatelessDemoSession, toSession, verifySiwxPayload, verifyStatelessDemoSession };
432
+ export { type CookieOptions, type GetSiwxServerSessionOptions, MemorySiwxNonceStore, MemorySiwxSessionStore, type ServerVerifyOptions, type ServerVerifyResult, type SiwxNonceStore, type SiwxSession, type SiwxSessionRecord, type SiwxSessionStore, type StatelessDemoLimits, type StatelessDemoTokenPayload, createClearCookie, createSessionCookie, getSiwxServerSession, issueStatelessDemoNonce, parseCookie, signStatelessDemoSession, toSession, verifySiwxPayload, verifyStatelessDemoNonce, verifyStatelessDemoSession };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkWPKBWXVR_js=require('./chunk-WPKBWXVR.js'),siwxCore=require('@tuwaio/siwx-core');Object.defineProperty(exports,"MemorySiwxNonceStore",{enumerable:true,get:function(){return chunkWPKBWXVR_js.j}});Object.defineProperty(exports,"MemorySiwxSessionStore",{enumerable:true,get:function(){return chunkWPKBWXVR_js.i}});Object.defineProperty(exports,"createClearCookie",{enumerable:true,get:function(){return chunkWPKBWXVR_js.g}});Object.defineProperty(exports,"createSessionCookie",{enumerable:true,get:function(){return chunkWPKBWXVR_js.f}});Object.defineProperty(exports,"generateServerNonce",{enumerable:true,get:function(){return chunkWPKBWXVR_js.b}});Object.defineProperty(exports,"getSiwxServerSession",{enumerable:true,get:function(){return chunkWPKBWXVR_js.k}});Object.defineProperty(exports,"parseCookie",{enumerable:true,get:function(){return chunkWPKBWXVR_js.h}});Object.defineProperty(exports,"signStatelessDemoSession",{enumerable:true,get:function(){return chunkWPKBWXVR_js.d}});Object.defineProperty(exports,"toSession",{enumerable:true,get:function(){return chunkWPKBWXVR_js.a}});Object.defineProperty(exports,"verifySiwxPayload",{enumerable:true,get:function(){return chunkWPKBWXVR_js.c}});Object.defineProperty(exports,"verifyStatelessDemoSession",{enumerable:true,get:function(){return chunkWPKBWXVR_js.e}});Object.defineProperty(exports,"generateNonce",{enumerable:true,get:function(){return siwxCore.generateNonce}});Object.defineProperty(exports,"isSessionMatchingTarget",{enumerable:true,get:function(){return siwxCore.isSessionMatchingTarget}});Object.defineProperty(exports,"validateMessage",{enumerable:true,get:function(){return siwxCore.validateMessage}});Object.defineProperty(exports,"validatePolicy",{enumerable:true,get:function(){return siwxCore.validatePolicy}});
1
+ 'use strict';var chunkSS5KJYWU_js=require('./chunk-SS5KJYWU.js'),siwxCore=require('@tuwaio/siwx-core');Object.defineProperty(exports,"MemorySiwxNonceStore",{enumerable:true,get:function(){return chunkSS5KJYWU_js.l}});Object.defineProperty(exports,"MemorySiwxSessionStore",{enumerable:true,get:function(){return chunkSS5KJYWU_js.k}});Object.defineProperty(exports,"createClearCookie",{enumerable:true,get:function(){return chunkSS5KJYWU_js.i}});Object.defineProperty(exports,"createSessionCookie",{enumerable:true,get:function(){return chunkSS5KJYWU_js.h}});Object.defineProperty(exports,"generateServerNonce",{enumerable:true,get:function(){return chunkSS5KJYWU_js.b}});Object.defineProperty(exports,"getSiwxServerSession",{enumerable:true,get:function(){return chunkSS5KJYWU_js.m}});Object.defineProperty(exports,"issueStatelessDemoNonce",{enumerable:true,get:function(){return chunkSS5KJYWU_js.f}});Object.defineProperty(exports,"parseCookie",{enumerable:true,get:function(){return chunkSS5KJYWU_js.j}});Object.defineProperty(exports,"signStatelessDemoSession",{enumerable:true,get:function(){return chunkSS5KJYWU_js.d}});Object.defineProperty(exports,"toSession",{enumerable:true,get:function(){return chunkSS5KJYWU_js.a}});Object.defineProperty(exports,"verifySiwxPayload",{enumerable:true,get:function(){return chunkSS5KJYWU_js.c}});Object.defineProperty(exports,"verifyStatelessDemoNonce",{enumerable:true,get:function(){return chunkSS5KJYWU_js.g}});Object.defineProperty(exports,"verifyStatelessDemoSession",{enumerable:true,get:function(){return chunkSS5KJYWU_js.e}});Object.defineProperty(exports,"generateNonce",{enumerable:true,get:function(){return siwxCore.generateNonce}});Object.defineProperty(exports,"isSessionMatchingTarget",{enumerable:true,get:function(){return siwxCore.isSessionMatchingTarget}});Object.defineProperty(exports,"validateMessage",{enumerable:true,get:function(){return siwxCore.validateMessage}});Object.defineProperty(exports,"validatePolicy",{enumerable:true,get:function(){return siwxCore.validatePolicy}});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{j as MemorySiwxNonceStore,i as MemorySiwxSessionStore,g as createClearCookie,f as createSessionCookie,b as generateServerNonce,k as getSiwxServerSession,h as parseCookie,d as signStatelessDemoSession,a as toSession,c as verifySiwxPayload,e as verifyStatelessDemoSession}from'./chunk-PBR725EL.mjs';export{generateNonce,isSessionMatchingTarget,validateMessage,validatePolicy}from'@tuwaio/siwx-core';
1
+ export{l as MemorySiwxNonceStore,k as MemorySiwxSessionStore,i as createClearCookie,h as createSessionCookie,b as generateServerNonce,m as getSiwxServerSession,f as issueStatelessDemoNonce,j as parseCookie,d as signStatelessDemoSession,a as toSession,c as verifySiwxPayload,g as verifyStatelessDemoNonce,e as verifyStatelessDemoSession}from'./chunk-AEFOZH2W.mjs';export{generateNonce,isSessionMatchingTarget,validateMessage,validatePolicy}from'@tuwaio/siwx-core';