Sign In With Polkadot (SIWP) plugin for Better-Auth. Add wallet-based authentication to any Polkadot application with a single plugin.
Built on the SIWS standard by Talisman. Works with LunoKit, Dedot, @polkadot/extension-dapp, or any Polkadot wallet framework.
npm i @zig-zag/better-siwpimport { betterAuth } from "better-auth";
import { siwp } from "@zig-zag/better-siwp";
export const auth = betterAuth({
plugins: [
siwp({ domain: "example.com" }),
],
});import { createAuthClient } from "better-auth/client";
import { siwpClient } from "@zig-zag/better-siwp/client";
export const authClient = createAuthClient({
plugins: [siwpClient()],
});LunoKit provides wallet connection and message signing out of the box:
import { useAccount, useSignMessage } from "@luno-kit/react";
import { useConnectModal } from "@luno-kit/ui";
import { SiwsMessage } from "@talismn/siws";
function SignInButton() {
const { account } = useAccount();
const { signMessageAsync } = useSignMessage();
const { open: openConnectModal } = useConnectModal();
const handleSignIn = async () => {
// Get nonce from server
const { data } = await authClient.siwp.nonce({ walletAddress: account.address });
// Build and sign the SIWS message
const message = new SiwsMessage({ domain: location.host, address: account.address, nonce: data.nonce, ... }).prepareMessage();
const { signature } = await signMessageAsync({ message });
// Verify — session cookie set automatically
await authClient.siwp.verify({ message, signature, walletAddress: account.address });
};
if (!account) return <button onClick={openConnectModal}>Connect Wallet</button>;
return <button onClick={handleSignIn}>Sign In</button>;
}See the full API reference for all configuration options, usage with @polkadot/extension-dapp, and detailed documentation.
| Example | Stack | Description |
|---|---|---|
examples/nextjs-lunokit |
Next.js + LunoKit + Dedot | Wallet connection via LunoKit, signing via useSignMessage |
examples/nextjs-app |
Next.js + @polkadot/extension-dapp | Direct wallet extension API usage |
Both include a polished dark-themed UI with Polkadot identicons, session persistence, and sign-out.
pnpm install
pnpm build:package # Build the plugin
pnpm dev:lunokit # Run the LunoKit example
pnpm dev # Run the extension-dapp example
pnpm test # Run tests (25 tests, 96% coverage)@zig-zag/chains— Chain registry for Polkadot SDK chains@zig-zag/better-siwp— This package
MIT - Yogesh Kumar