@tuwaio/satellite-siwe-next-auth 0.3.0 → 0.3.2

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 CHANGED
@@ -33,7 +33,7 @@ Built on top of **Wagmi/Viem** for signature generation and verification.
33
33
 
34
34
  - Node.js 20-24
35
35
  - TypeScript 5.9+
36
- - Wagmi v2+
36
+ - Wagmi v3+
37
37
  - Viem v2+
38
38
  - Iron Session v8+
39
39
 
@@ -1,2 +1,2 @@
1
- 'use strict';var ironSession=require('iron-session'),server=require('next/server'),siwe=require('siwe');function E(n){let e=n.session||{},d=process.env.SIWE_SESSION_SECRET,a=e.password||d;if(!a||a.length<32)throw new Error("SIWE Error: Iron Session requires a 'password' option (min 32 chars) or SIWE_SESSION_SECRET environment variable to be set.");let S={...{secure:process.env.NODE_ENV==="production",maxAge:300*60,httpOnly:true,sameSite:"lax",path:"/"},...e.cookieOptions};return {password:a,cookieName:e.cookieName||"satellite_siwe",cookieOptions:S}}function O(n){if(!n)return console.warn("SIWE WARN: SIWE_SESSION_URL is not defined. Defaulting domain check to 'localhost'."),"localhost";try{return new URL(n.startsWith("http")?n:`https://${n}`).host}catch(e){return console.error(`SIWE ERROR: Invalid URL provided in SIWE_SESSION_URL: ${n}. Error: ${typeof e=="string"?e:e.message}`),"localhost"}}function x(n={}){let e=n.options||{},d=E(n);async function a(o){let s=new Response;return {session:await ironSession.getIronSession(o,s,d),response:s}}async function f(o){try{let{message:s,signature:p}=await o.json();if(!s||!p)return server.NextResponse.json({message:"Missing message or signature"},{status:400});e.afterNonce&&await e.afterNonce();let t=new siwe.SiweMessage(s),i=O(process.env.SIWE_SESSION_URL);if(!(await t.verify({signature:p,domain:i})).success)return server.NextResponse.json({message:"SIWE verification failed"},{status:401});e.afterVerify&&await e.afterVerify();let{session:c,response:l}=await a(o);c.address=t.address,c.chainId=t.chainId,c.isLoggedIn=!0,await c.save(),e.afterSession&&await e.afterSession();let m=server.NextResponse.json({isLoggedIn:!0,address:c.address,chainId:c.chainId},{status:200});return l.headers.forEach((w,h)=>{h.toLowerCase()==="set-cookie"&&m.headers.append("Set-Cookie",w);}),m}catch(s){return console.error("SIWE CRITICAL LOGIN ERROR:",s),server.NextResponse.json({message:"Internal Server Error during login"},{status:500})}}async function S(o){let{session:s,response:p}=await a(o);if(o.method==="POST"||o.method==="DELETE"){s.destroy(),e.afterLogout&&await e.afterLogout();let t=server.NextResponse.json({isLoggedIn:false},{status:200});return p.headers.forEach((i,g)=>{g.toLowerCase()==="set-cookie"&&t.headers.append("Set-Cookie",i);}),t}return s.isLoggedIn&&s.address&&s.chainId?server.NextResponse.json({isLoggedIn:true,address:s.address,chainId:s.chainId}):server.NextResponse.json({isLoggedIn:false},{status:401})}let u=async(o,s)=>{let t=(await s.params||{})?.siwe||[],i=t[t.length-1];return i==="login"&&o.method==="POST"?f(o):i==="session"&&o.method==="GET"||i==="logout"&&(o.method==="POST"||o.method==="DELETE")?S(o):Promise.resolve(new Response("Not Found",{status:404}))};return {GET:u,POST:u,DELETE:u}}
2
- exports.createSiweApiHandler=x;exports.getSessionOptions=E;
1
+ 'use strict';var ironSession=require('iron-session'),server=require('next/server'),viem=require('viem'),siwe=require('viem/siwe');function l(t){let e=t.session||{},c=process.env.SIWE_SESSION_SECRET,a=e.password||c;if(!a||a.length<32)throw new Error("SIWE Error: Iron Session requires a 'password' option (min 32 chars) or SIWE_SESSION_SECRET environment variable to be set.");let S={...{secure:process.env.NODE_ENV==="production",maxAge:300*60,httpOnly:true,sameSite:"lax",path:"/"},...e.cookieOptions};return {password:a,cookieName:e.cookieName||"satellite_siwe",cookieOptions:S}}function C(t){if(!t)return console.warn("SIWE WARN: SIWE_SESSION_URL is not defined. Defaulting domain check to 'localhost'."),"localhost";try{return new URL(t.startsWith("http")?t:`https://${t}`).host}catch(e){return console.error(`SIWE ERROR: Invalid URL provided in SIWE_SESSION_URL: ${t}. Error: ${typeof e=="string"?e:e.message}`),"localhost"}}function _(t={}){let e=t.options||{},c=l(t);async function a(o){let s=new Response;return {session:await ironSession.getIronSession(o,s,c),response:s}}async function f(o){try{let{message:s,signature:d}=await o.json();if(!s||!d)return server.NextResponse.json({message:"Missing message or signature"},{status:400});e.afterNonce&&await e.afterNonce();let n=siwe.parseSiweMessage(s);if(!n||!n.address||!n.chainId)return server.NextResponse.json({message:"Invalid SIWE message format"},{status:400});let r=C(process.env.SIWE_SESSION_URL);if(!siwe.validateSiweMessage({message:n,domain:r}))return server.NextResponse.json({message:"SIWE message validation failed"},{status:401});if(!await viem.verifyMessage({address:n.address,message:s,signature:d}))return server.NextResponse.json({message:"SIWE signature verification failed"},{status:401});e.afterVerify&&await e.afterVerify();let{session:p,response:E}=await a(o);p.address=n.address,p.chainId=n.chainId,p.isLoggedIn=!0,await p.save(),e.afterSession&&await e.afterSession();let m=server.NextResponse.json({isLoggedIn:!0,address:p.address,chainId:p.chainId},{status:200});return E.headers.forEach((w,I)=>{I.toLowerCase()==="set-cookie"&&m.headers.append("Set-Cookie",w);}),m}catch(s){return console.error("SIWE CRITICAL LOGIN ERROR:",s),server.NextResponse.json({message:"Internal Server Error during login"},{status:500})}}async function S(o){let{session:s,response:d}=await a(o);if(o.method==="POST"||o.method==="DELETE"){s.destroy(),e.afterLogout&&await e.afterLogout();let n=server.NextResponse.json({isLoggedIn:false},{status:200});return d.headers.forEach((r,g)=>{g.toLowerCase()==="set-cookie"&&n.headers.append("Set-Cookie",r);}),n}return s.isLoggedIn&&s.address&&s.chainId?server.NextResponse.json({isLoggedIn:true,address:s.address,chainId:s.chainId}):server.NextResponse.json({isLoggedIn:false},{status:401})}let u=async(o,s)=>{let n=(await s.params||{})?.siwe||[],r=n[n.length-1];return r==="login"&&o.method==="POST"?f(o):r==="session"&&o.method==="GET"||r==="logout"&&(o.method==="POST"||o.method==="DELETE")?S(o):Promise.resolve(new Response("Not Found",{status:404}))};return {GET:u,POST:u,DELETE:u}}
2
+ exports.createSiweApiHandler=_;exports.getSessionOptions=l;
@@ -1,2 +1,2 @@
1
- import {getIronSession}from'iron-session';import {NextResponse}from'next/server';import {SiweMessage}from'siwe';function E(n){let e=n.session||{},d=process.env.SIWE_SESSION_SECRET,a=e.password||d;if(!a||a.length<32)throw new Error("SIWE Error: Iron Session requires a 'password' option (min 32 chars) or SIWE_SESSION_SECRET environment variable to be set.");let S={...{secure:process.env.NODE_ENV==="production",maxAge:300*60,httpOnly:true,sameSite:"lax",path:"/"},...e.cookieOptions};return {password:a,cookieName:e.cookieName||"satellite_siwe",cookieOptions:S}}function O(n){if(!n)return console.warn("SIWE WARN: SIWE_SESSION_URL is not defined. Defaulting domain check to 'localhost'."),"localhost";try{return new URL(n.startsWith("http")?n:`https://${n}`).host}catch(e){return console.error(`SIWE ERROR: Invalid URL provided in SIWE_SESSION_URL: ${n}. Error: ${typeof e=="string"?e:e.message}`),"localhost"}}function x(n={}){let e=n.options||{},d=E(n);async function a(o){let s=new Response;return {session:await getIronSession(o,s,d),response:s}}async function f(o){try{let{message:s,signature:p}=await o.json();if(!s||!p)return NextResponse.json({message:"Missing message or signature"},{status:400});e.afterNonce&&await e.afterNonce();let t=new SiweMessage(s),i=O(process.env.SIWE_SESSION_URL);if(!(await t.verify({signature:p,domain:i})).success)return NextResponse.json({message:"SIWE verification failed"},{status:401});e.afterVerify&&await e.afterVerify();let{session:c,response:l}=await a(o);c.address=t.address,c.chainId=t.chainId,c.isLoggedIn=!0,await c.save(),e.afterSession&&await e.afterSession();let m=NextResponse.json({isLoggedIn:!0,address:c.address,chainId:c.chainId},{status:200});return l.headers.forEach((w,h)=>{h.toLowerCase()==="set-cookie"&&m.headers.append("Set-Cookie",w);}),m}catch(s){return console.error("SIWE CRITICAL LOGIN ERROR:",s),NextResponse.json({message:"Internal Server Error during login"},{status:500})}}async function S(o){let{session:s,response:p}=await a(o);if(o.method==="POST"||o.method==="DELETE"){s.destroy(),e.afterLogout&&await e.afterLogout();let t=NextResponse.json({isLoggedIn:false},{status:200});return p.headers.forEach((i,g)=>{g.toLowerCase()==="set-cookie"&&t.headers.append("Set-Cookie",i);}),t}return s.isLoggedIn&&s.address&&s.chainId?NextResponse.json({isLoggedIn:true,address:s.address,chainId:s.chainId}):NextResponse.json({isLoggedIn:false},{status:401})}let u=async(o,s)=>{let t=(await s.params||{})?.siwe||[],i=t[t.length-1];return i==="login"&&o.method==="POST"?f(o):i==="session"&&o.method==="GET"||i==="logout"&&(o.method==="POST"||o.method==="DELETE")?S(o):Promise.resolve(new Response("Not Found",{status:404}))};return {GET:u,POST:u,DELETE:u}}
2
- export{x as createSiweApiHandler,E as getSessionOptions};
1
+ import {getIronSession}from'iron-session';import {NextResponse}from'next/server';import {verifyMessage}from'viem';import {parseSiweMessage,validateSiweMessage}from'viem/siwe';function l(t){let e=t.session||{},c=process.env.SIWE_SESSION_SECRET,a=e.password||c;if(!a||a.length<32)throw new Error("SIWE Error: Iron Session requires a 'password' option (min 32 chars) or SIWE_SESSION_SECRET environment variable to be set.");let S={...{secure:process.env.NODE_ENV==="production",maxAge:300*60,httpOnly:true,sameSite:"lax",path:"/"},...e.cookieOptions};return {password:a,cookieName:e.cookieName||"satellite_siwe",cookieOptions:S}}function C(t){if(!t)return console.warn("SIWE WARN: SIWE_SESSION_URL is not defined. Defaulting domain check to 'localhost'."),"localhost";try{return new URL(t.startsWith("http")?t:`https://${t}`).host}catch(e){return console.error(`SIWE ERROR: Invalid URL provided in SIWE_SESSION_URL: ${t}. Error: ${typeof e=="string"?e:e.message}`),"localhost"}}function _(t={}){let e=t.options||{},c=l(t);async function a(o){let s=new Response;return {session:await getIronSession(o,s,c),response:s}}async function f(o){try{let{message:s,signature:d}=await o.json();if(!s||!d)return NextResponse.json({message:"Missing message or signature"},{status:400});e.afterNonce&&await e.afterNonce();let n=parseSiweMessage(s);if(!n||!n.address||!n.chainId)return NextResponse.json({message:"Invalid SIWE message format"},{status:400});let r=C(process.env.SIWE_SESSION_URL);if(!validateSiweMessage({message:n,domain:r}))return NextResponse.json({message:"SIWE message validation failed"},{status:401});if(!await verifyMessage({address:n.address,message:s,signature:d}))return NextResponse.json({message:"SIWE signature verification failed"},{status:401});e.afterVerify&&await e.afterVerify();let{session:p,response:E}=await a(o);p.address=n.address,p.chainId=n.chainId,p.isLoggedIn=!0,await p.save(),e.afterSession&&await e.afterSession();let m=NextResponse.json({isLoggedIn:!0,address:p.address,chainId:p.chainId},{status:200});return E.headers.forEach((w,I)=>{I.toLowerCase()==="set-cookie"&&m.headers.append("Set-Cookie",w);}),m}catch(s){return console.error("SIWE CRITICAL LOGIN ERROR:",s),NextResponse.json({message:"Internal Server Error during login"},{status:500})}}async function S(o){let{session:s,response:d}=await a(o);if(o.method==="POST"||o.method==="DELETE"){s.destroy(),e.afterLogout&&await e.afterLogout();let n=NextResponse.json({isLoggedIn:false},{status:200});return d.headers.forEach((r,g)=>{g.toLowerCase()==="set-cookie"&&n.headers.append("Set-Cookie",r);}),n}return s.isLoggedIn&&s.address&&s.chainId?NextResponse.json({isLoggedIn:true,address:s.address,chainId:s.chainId}):NextResponse.json({isLoggedIn:false},{status:401})}let u=async(o,s)=>{let n=(await s.params||{})?.siwe||[],r=n[n.length-1];return r==="login"&&o.method==="POST"?f(o):r==="session"&&o.method==="GET"||r==="logout"&&(o.method==="POST"||o.method==="DELETE")?S(o):Promise.resolve(new Response("Not Found",{status:404}))};return {GET:u,POST:u,DELETE:u}}
2
+ export{_ as createSiweApiHandler,l as getSessionOptions};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-siwe-next-auth",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -52,7 +52,6 @@
52
52
  ],
53
53
  "peerDependencies": {
54
54
  "@wagmi/core": "3.x.x",
55
- "siwe": "3.x.x",
56
55
  "next": ">=16.1",
57
56
  "iron-session": "8.x.x",
58
57
  "react": ">=19.2.3",
@@ -60,16 +59,15 @@
60
59
  "wagmi": "3.x.x"
61
60
  },
62
61
  "devDependencies": {
63
- "@wagmi/core": "^3.3.2",
64
- "@types/react": "^19.2.10",
65
- "siwe": "^3.0.0",
62
+ "@wagmi/core": "^3.4.0",
63
+ "@types/react": "^19.2.14",
66
64
  "next": "16.1.6",
67
65
  "iron-session": "^8.0.4",
68
66
  "react": "^19.2.4",
69
67
  "tsup": "^8.5.1",
70
68
  "typescript": "^5.9.3",
71
- "viem": "^2.45.1",
72
- "wagmi": "^3.4.2"
69
+ "viem": "^2.46.3",
70
+ "wagmi": "^3.5.0"
73
71
  },
74
72
  "scripts": {
75
73
  "start": "tsup src/index.ts --watch",