Skip to content

Web3Auth/sign-in-with-web3

Repository files navigation

@web3auth/sign-in-with-web3

Authenticate users with their Web3 accounts instead of relying on custodial OAuth providers. Users sign a standard message with any Web3-compatible wallet, keeping full control of their identity and data.

Sign-In with Web3 uses a standard message format compliant with CAIP-74, parameterized by scope, session details, and security mechanisms (e.g., a nonce).

Supported Chains

  • EthereumEIP-4361 with EIP-1271/6492 smart contract signature support
  • SolanaSIP-99 with ed25519 signature verification

Installation

npm install @web3auth/sign-in-with-web3

Usage

Register strategies

Strategies are not auto-registered. Register the chains you need before using SIWWeb3:

import { SIWWeb3, ethereumStrategy, solanaStrategy } from "@web3auth/sign-in-with-web3";

SIWWeb3.registerStrategy(ethereumStrategy);
SIWWeb3.registerStrategy(solanaStrategy);

Basic

// Parse a signed message string (chain is detected automatically)
const msg = new SIWWeb3(messageString);

// Or construct from fields (chain is required)
const msg = new SIWWeb3({
  chain: "ethereum", // or "solana"
  payload: {
    domain: "example.com",
    address: "0x...",
    statement: "Sign in with Ethereum to the app.",
    uri: "https://example.com",
    version: "1",
    chainId: 1,
    nonce: "32891757",
    issuedAt: new Date().toISOString(),
  },
});

// Generate the EIP-4361 message to sign
const messageToSign = msg.prepareMessage();

// Verify a signature
const { success, error } = await msg.verify(msg.payload, signature);

Using chain-specific classes directly

import { SIWE, SIWS } from "@web3auth/sign-in-with-web3";

const ethMsg = new SIWE({ header, payload, signature });
const solMsg = new SIWS(messageString);

Registering a custom strategy

import { SIWWeb3 } from "@web3auth/sign-in-with-web3";

SIWWeb3.registerStrategy({
  chain: "mychain",
  parse: (msg) => new MyChainSIW(msg),
  create: (params) => new MyChainSIW(params),
});

Architecture

src/
  client.ts          — SIWWeb3 (main entry, strategy registry)
  strategies/
    base.ts          — SIWBase (abstract base class)
    ethereum.ts      — SIWE + EIP-1271/6492 verifier
    solana.ts        — SIWS + ed25519 verifier
  regex.ts           — Shared message parsing
  types.ts           — Shared types

Exports

Export Description
SIWWeb3 Main class with chain auto-detection and strategy registry
SIWBase Abstract base class for building custom chain strategies
SIWE Ethereum sign-in (EIP-4361)
SIWS Solana sign-in (SIP-99)
ethereumStrategy Ethereum strategy for registry
solanaStrategy Solana strategy for registry
eipVerifyMessage EIP-1271/6492 signature verification utility

Migration from @web3auth/sign-in-with-ethereum / @web3auth/sign-in-with-solana

These packages have been deprecated and consolidated into this package.

- import { SIWEthereum } from "@web3auth/sign-in-with-ethereum";
- import { SIWS } from "@web3auth/sign-in-with-solana";
+ import { SIWWeb3, ethereumStrategy, solanaStrategy, SIWE, SIWS } from "@web3auth/sign-in-with-web3";
+ SIWWeb3.registerStrategy(ethereumStrategy);
+ SIWWeb3.registerStrategy(solanaStrategy);

Key changes from previous versions:

  • SIWEthereum has been renamed to SIWE
  • network property has been renamed to chain
  • chain is now required when constructing from an object
  • Strategies must be registered manually (no longer auto-registered)

Docs

About

With Sign-in With Web3, users will be able to take control of their digital identities with their Web3 accounts rather than relying on custodial Oauth providers such as Google and Facebook. What this means is that users don't need to share their information and usage data. Leveraging the security and privacy aspects of Web3 accounts, users can c…

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors