@tuwaio/siwx-server 0.1.0 → 0.2.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/dist/next.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk47HTX7ZQ_js=require('./chunk-47HTX7ZQ.js');function T(i={}){let p=i.cookieOptions?.name||"siwx-session",r=async e=>{try{let s="",c=new URL(e.url).pathname.split("/").filter(Boolean);if(s=c[c.length-1]||"",e.method==="GET"&&s==="session"){let t=e.headers.get("cookie")||"",o=Object.fromEntries(t.split("; ").filter(Boolean).map(S=>{let l=S.split("=");return [l[0].trim(),l.slice(1).join("=")]}))[p];if(!o)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let a=chunk47HTX7ZQ_js.e(o);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})}if(e.method==="POST"&&s==="verify"){let t=await e.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let n=await chunk47HTX7ZQ_js.c(t,i.verifyOptions);if(!n.success)return new Response(JSON.stringify({error:n.error}),{status:401,headers:{"Content-Type":"application/json"}});if(!n.data)return new Response(JSON.stringify({error:"Verification succeeded but returned no data"}),{status:500,headers:{"Content-Type":"application/json"}});let{cookieHeader:o,session:a}=chunk47HTX7ZQ_js.d(chunk47HTX7ZQ_js.a(n.data),i.cookieOptions);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":o}})}return e.method==="DELETE"&&s==="session"||e.method==="POST"&&s==="logout"?new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":`${p}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Strict`}}):new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(s){return console.error("[SIWX-SERVER] API Handler error:",s),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}exports.createSiwxApiHandler=T;
1
+ 'use strict';var chunkU25GZS7S_js=require('./chunk-U25GZS7S.js'),siwxCore=require('@tuwaio/siwx-core');function k(e){if(!e?.sessionStore||!e?.nonceStore)throw new Error("[SIWX-SERVER] createSiwxApiHandler requires both `sessionStore` and `nonceStore`. For zero-infrastructure demos without storage, use `createStatelessDemoSiwxHandler`.");let i=e.cookieOptions?.name||"siwx-session-v2",a=e.ttlSeconds??(e.cookieOptions?.maxAge||3600*24*7),r=async n=>{try{let p=new URL(n.url).pathname.split("/").filter(Boolean),o=p[p.length-1]||"";if(n.method==="GET"&&o==="session"){let t=chunkU25GZS7S_js.h(n.headers.get("cookie"),i);if(!t)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let s=await e.sessionStore.get(t);return new Response(JSON.stringify(s?.session??null),{status:200,headers:{"Content-Type":"application/json"}})}if((n.method==="GET"||n.method==="POST")&&o==="nonce"){let t=siwxCore.generateNonce();return await e.nonceStore.issue({nonce:t,ttlSeconds:300}),new Response(JSON.stringify({nonce:t}),{status:200,headers:{"Content-Type":"application/json"}})}if(n.method==="POST"&&o==="verify"){let t=await n.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let s=await chunkU25GZS7S_js.c(t,{...e.verifyOptions,policy:e.policy});if(!s.success||!s.data)return new Response(JSON.stringify({error:s.error||"Verification failed"}),{status:401,headers:{"Content-Type":"application/json"}});if(!await e.nonceStore.consume({nonce:s.data.nonce}))return new Response(JSON.stringify({error:"Nonce replay detected or nonce expired"}),{status:401,headers:{"Content-Type":"application/json"}});let S=chunkU25GZS7S_js.a(s.data),d=await e.sessionStore.create({session:S,ttlSeconds:a}),T=chunkU25GZS7S_js.f(d.id,{...e.cookieOptions,name:i,maxAge:a});return new Response(JSON.stringify(S),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":T}})}if(n.method==="DELETE"&&o==="session"||n.method==="POST"&&o==="logout"){let t=chunkU25GZS7S_js.h(n.headers.get("cookie"),i);return t&&await e.sessionStore.revoke(t),new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":chunkU25GZS7S_js.g({...e.cookieOptions,name:i})}})}return new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(c){return console.error("[SIWX-SERVER] Durable Handler error:",c),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}function E(e){if(!e?.signingSecret||e.signingSecret.length<32)throw new Error("[SIWX-SERVER] createStatelessDemoSiwxHandler requires a `signingSecret` of at least 32 characters.");let i=e.cookieOptions?.name||"siwx-session-v2",a=e.ttlSeconds??(e.cookieOptions?.maxAge||1800),r=async n=>{try{let p=new URL(n.url).pathname.split("/").filter(Boolean),o=p[p.length-1]||"";if(n.method==="GET"&&o==="session"){let t=chunkU25GZS7S_js.h(n.headers.get("cookie"),i);if(!t)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let s=await chunkU25GZS7S_js.e(t,e.signingSecret,e.policy);return new Response(JSON.stringify(s),{status:200,headers:{"Content-Type":"application/json"}})}if((n.method==="GET"||n.method==="POST")&&o==="nonce"){let t=siwxCore.generateNonce();return new Response(JSON.stringify({nonce:t}),{status:200,headers:{"Content-Type":"application/json"}})}if(n.method==="POST"&&o==="verify"){let t=await n.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let s=await chunkU25GZS7S_js.c(t,{...e.verifyOptions,policy:e.policy});if(!s.success||!s.data)return new Response(JSON.stringify({error:s.error||"Verification failed"}),{status:401,headers:{"Content-Type":"application/json"}});let u=chunkU25GZS7S_js.a(s.data),S=await chunkU25GZS7S_js.d(u,e.signingSecret,a),d=chunkU25GZS7S_js.f(S,{...e.cookieOptions,name:i,maxAge:a});return new Response(JSON.stringify(u),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":d}})}return n.method==="DELETE"&&o==="session"||n.method==="POST"&&o==="logout"?new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":chunkU25GZS7S_js.g({...e.cookieOptions,name:i})}}):new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(c){return console.error("[SIWX-SERVER] Stateless Demo Handler error:",c),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}Object.defineProperty(exports,"getSiwxServerSession",{enumerable:true,get:function(){return chunkU25GZS7S_js.k}});exports.createSiwxApiHandler=k;exports.createStatelessDemoSiwxHandler=E;
package/dist/next.mjs CHANGED
@@ -1 +1 @@
1
- import {e,c,d,a}from'./chunk-JVIBIICZ.mjs';function T(i={}){let p=i.cookieOptions?.name||"siwx-session",r=async e$1=>{try{let s="",c$1=new URL(e$1.url).pathname.split("/").filter(Boolean);if(s=c$1[c$1.length-1]||"",e$1.method==="GET"&&s==="session"){let t=e$1.headers.get("cookie")||"",o=Object.fromEntries(t.split("; ").filter(Boolean).map(S=>{let l=S.split("=");return [l[0].trim(),l.slice(1).join("=")]}))[p];if(!o)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let a=e(o);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})}if(e$1.method==="POST"&&s==="verify"){let t=await e$1.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let n=await c(t,i.verifyOptions);if(!n.success)return new Response(JSON.stringify({error:n.error}),{status:401,headers:{"Content-Type":"application/json"}});if(!n.data)return new Response(JSON.stringify({error:"Verification succeeded but returned no data"}),{status:500,headers:{"Content-Type":"application/json"}});let{cookieHeader:o,session:a$1}=d(a(n.data),i.cookieOptions);return new Response(JSON.stringify(a$1),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":o}})}return e$1.method==="DELETE"&&s==="session"||e$1.method==="POST"&&s==="logout"?new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":`${p}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Strict`}}):new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(s){return console.error("[SIWX-SERVER] API Handler error:",s),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}export{T as createSiwxApiHandler};
1
+ import {h,c,a,f,g,e,d}from'./chunk-WXHFSBDK.mjs';export{k as getSiwxServerSession}from'./chunk-WXHFSBDK.mjs';import {generateNonce}from'@tuwaio/siwx-core';function k(e){if(!e?.sessionStore||!e?.nonceStore)throw new Error("[SIWX-SERVER] createSiwxApiHandler requires both `sessionStore` and `nonceStore`. For zero-infrastructure demos without storage, use `createStatelessDemoSiwxHandler`.");let i=e.cookieOptions?.name||"siwx-session-v2",a$1=e.ttlSeconds??(e.cookieOptions?.maxAge||3600*24*7),r=async n=>{try{let p=new URL(n.url).pathname.split("/").filter(Boolean),o=p[p.length-1]||"";if(n.method==="GET"&&o==="session"){let t=h(n.headers.get("cookie"),i);if(!t)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let s=await e.sessionStore.get(t);return new Response(JSON.stringify(s?.session??null),{status:200,headers:{"Content-Type":"application/json"}})}if((n.method==="GET"||n.method==="POST")&&o==="nonce"){let t=generateNonce();return await e.nonceStore.issue({nonce:t,ttlSeconds:300}),new Response(JSON.stringify({nonce:t}),{status:200,headers:{"Content-Type":"application/json"}})}if(n.method==="POST"&&o==="verify"){let t=await n.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let s=await c(t,{...e.verifyOptions,policy:e.policy});if(!s.success||!s.data)return new Response(JSON.stringify({error:s.error||"Verification failed"}),{status:401,headers:{"Content-Type":"application/json"}});if(!await e.nonceStore.consume({nonce:s.data.nonce}))return new Response(JSON.stringify({error:"Nonce replay detected or nonce expired"}),{status:401,headers:{"Content-Type":"application/json"}});let S=a(s.data),d=await e.sessionStore.create({session:S,ttlSeconds:a$1}),T=f(d.id,{...e.cookieOptions,name:i,maxAge:a$1});return new Response(JSON.stringify(S),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":T}})}if(n.method==="DELETE"&&o==="session"||n.method==="POST"&&o==="logout"){let t=h(n.headers.get("cookie"),i);return t&&await e.sessionStore.revoke(t),new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":g({...e.cookieOptions,name:i})}})}return new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(c){return console.error("[SIWX-SERVER] Durable Handler error:",c),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}function E(e$1){if(!e$1?.signingSecret||e$1.signingSecret.length<32)throw new Error("[SIWX-SERVER] createStatelessDemoSiwxHandler requires a `signingSecret` of at least 32 characters.");let i=e$1.cookieOptions?.name||"siwx-session-v2",a$1=e$1.ttlSeconds??(e$1.cookieOptions?.maxAge||1800),r=async n=>{try{let p=new URL(n.url).pathname.split("/").filter(Boolean),o=p[p.length-1]||"";if(n.method==="GET"&&o==="session"){let t=h(n.headers.get("cookie"),i);if(!t)return new Response(JSON.stringify(null),{status:200,headers:{"Content-Type":"application/json"}});let s=await e(t,e$1.signingSecret,e$1.policy);return new Response(JSON.stringify(s),{status:200,headers:{"Content-Type":"application/json"}})}if((n.method==="GET"||n.method==="POST")&&o==="nonce"){let t=generateNonce();return new Response(JSON.stringify({nonce:t}),{status:200,headers:{"Content-Type":"application/json"}})}if(n.method==="POST"&&o==="verify"){let t=await n.json();if(!t.message||!t.signature)return new Response(JSON.stringify({error:"Missing message or signature"}),{status:400,headers:{"Content-Type":"application/json"}});let s=await c(t,{...e$1.verifyOptions,policy:e$1.policy});if(!s.success||!s.data)return new Response(JSON.stringify({error:s.error||"Verification failed"}),{status:401,headers:{"Content-Type":"application/json"}});let u=a(s.data),S=await d(u,e$1.signingSecret,a$1),d$1=f(S,{...e$1.cookieOptions,name:i,maxAge:a$1});return new Response(JSON.stringify(u),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":d$1}})}return n.method==="DELETE"&&o==="session"||n.method==="POST"&&o==="logout"?new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json","Set-Cookie":g({...e$1.cookieOptions,name:i})}}):new Response(JSON.stringify({error:"Not Found"}),{status:404,headers:{"Content-Type":"application/json"}})}catch(c){return console.error("[SIWX-SERVER] Stateless Demo Handler error:",c),new Response(JSON.stringify({error:"Internal Server Error"}),{status:500,headers:{"Content-Type":"application/json"}})}};return {GET:r,POST:r,DELETE:r}}export{k as createSiwxApiHandler,E as createStatelessDemoSiwxHandler};
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.1",
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 };