|
1 | | -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 |
2 | | -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 |
3 | | -privacy aspects of Web3 accounts, users can controls what they share and in what capacity with the apps/dApps they're interating with. |
| 1 | +# @web3auth/sign-in-with-web3 |
4 | 2 |
|
5 | | -## Sign-in With Web3 - You Own Your Identity |
| 3 | +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. |
6 | 4 |
|
7 | | -One of the critical problems that web3 solves is privacy. Having control over the private key allows users to own their digital identities. Sign In |
8 | | -With Web3 leverages this very principle to allow any application (Web2 or Web3) to authenticate users with their Web3 address. Users simply need to |
9 | | -sign a message using any Web3 compatible wallet to do this. |
| 5 | +Sign-In with Web3 uses a standard message format compliant with [CAIP-74](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-74.md), parameterized by scope, session details, and security mechanisms (e.g., a nonce). |
10 | 6 |
|
11 | | -## What does Sign-in With Web3 Solve? |
| 7 | +## Supported Chains |
12 | 8 |
|
13 | | -Today most authentication mechanisms rely on accounts controlled by centralized identity providers such as Google, Facebook, and Apple. Identity |
14 | | -providers have complete control over the existence and use of users’ digital identities and data. |
| 9 | +- **Ethereum** — [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) with EIP-1271/6492 smart contract signature support |
| 10 | +- **Solana** — [SIP-99](https://github.com/AdrenaFoundation/SIPs/blob/main/SIPS/sip-99.md) with ed25519 signature verification |
15 | 11 |
|
16 | | -Sign-In with Web3 allows off-chain authentication of Web3 accounts by signing a standard message format parameterized by scope, session details, and |
17 | | -security mechanisms (e.g., a nonce) compliant with [CAIP-74](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-74.md) which is the current |
18 | | -chain agnostic standard. |
19 | 12 |
|
20 | | -## Supported Chains |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install @web3auth/sign-in-with-web3 |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Register strategies |
| 22 | + |
| 23 | +Strategies are not auto-registered. Register the chains you need before using `SIWWeb3`: |
| 24 | + |
| 25 | +```typescript |
| 26 | +import { SIWWeb3, ethereumStrategy, solanaStrategy } from "@web3auth/sign-in-with-web3"; |
| 27 | + |
| 28 | +SIWWeb3.registerStrategy(ethereumStrategy); |
| 29 | +SIWWeb3.registerStrategy(solanaStrategy); |
| 30 | +``` |
| 31 | + |
| 32 | +### Basic |
| 33 | + |
| 34 | +```typescript |
| 35 | +// Parse a signed message string (chain is detected automatically) |
| 36 | +const msg = new SIWWeb3(messageString); |
| 37 | + |
| 38 | +// Or construct from fields (chain is required) |
| 39 | +const msg = new SIWWeb3({ |
| 40 | + chain: "ethereum", // or "solana" |
| 41 | + payload: { |
| 42 | + domain: "example.com", |
| 43 | + address: "0x...", |
| 44 | + statement: "Sign in with Ethereum to the app.", |
| 45 | + uri: "https://example.com", |
| 46 | + version: "1", |
| 47 | + chainId: 1, |
| 48 | + nonce: "32891757", |
| 49 | + issuedAt: new Date().toISOString(), |
| 50 | + }, |
| 51 | +}); |
| 52 | + |
| 53 | +// Generate the EIP-4361 message to sign |
| 54 | +const messageToSign = msg.prepareMessage(); |
| 55 | + |
| 56 | +// Verify a signature |
| 57 | +const { success, error } = await msg.verify(msg.payload, signature); |
| 58 | +``` |
| 59 | + |
| 60 | +### Using chain-specific classes directly |
| 61 | + |
| 62 | +```typescript |
| 63 | +import { SIWE, SIWS } from "@web3auth/sign-in-with-web3"; |
| 64 | + |
| 65 | +const ethMsg = new SIWE({ header, payload, signature }); |
| 66 | +const solMsg = new SIWS(messageString); |
| 67 | +``` |
| 68 | + |
| 69 | +### Registering a custom strategy |
| 70 | + |
| 71 | +```typescript |
| 72 | +import { SIWWeb3 } from "@web3auth/sign-in-with-web3"; |
| 73 | + |
| 74 | +SIWWeb3.registerStrategy({ |
| 75 | + chain: "mychain", |
| 76 | + parse: (msg) => new MyChainSIW(msg), |
| 77 | + create: (params) => new MyChainSIW(params), |
| 78 | +}); |
| 79 | +``` |
| 80 | + |
| 81 | +## Architecture |
| 82 | + |
| 83 | +``` |
| 84 | +src/ |
| 85 | + client.ts — SIWWeb3 (main entry, strategy registry) |
| 86 | + strategies/ |
| 87 | + base.ts — SIWBase (abstract base class) |
| 88 | + ethereum.ts — SIWE + EIP-1271/6492 verifier |
| 89 | + solana.ts — SIWS + ed25519 verifier |
| 90 | + regex.ts — Shared message parsing |
| 91 | + types.ts — Shared types |
| 92 | +``` |
| 93 | + |
| 94 | +## Exports |
| 95 | + |
| 96 | +| Export | Description | |
| 97 | +|---|---| |
| 98 | +| `SIWWeb3` | Main class with chain auto-detection and strategy registry | |
| 99 | +| `SIWBase` | Abstract base class for building custom chain strategies | |
| 100 | +| `SIWE` | Ethereum sign-in (EIP-4361) | |
| 101 | +| `SIWS` | Solana sign-in (SIP-99) | |
| 102 | +| `ethereumStrategy` | Ethereum strategy for registry | |
| 103 | +| `solanaStrategy` | Solana strategy for registry | |
| 104 | +| `eipVerifyMessage` | EIP-1271/6492 signature verification utility | |
| 105 | + |
| 106 | +## Migration from `@web3auth/sign-in-with-ethereum` / `@web3auth/sign-in-with-solana` |
21 | 107 |
|
22 | | -Currently Sign-in with Web3 supports |
| 108 | +These packages have been deprecated and consolidated into this package. |
23 | 109 |
|
24 | | -1. Ethereum |
25 | | -2. Solana |
26 | | -3. Starknet |
| 110 | +```diff |
| 111 | +- import { SIWEthereum } from "@web3auth/sign-in-with-ethereum"; |
| 112 | +- import { SIWS } from "@web3auth/sign-in-with-solana"; |
| 113 | ++ import { SIWWeb3, ethereumStrategy, solanaStrategy, SIWE, SIWS } from "@web3auth/sign-in-with-web3"; |
| 114 | ++ SIWWeb3.registerStrategy(ethereumStrategy); |
| 115 | ++ SIWWeb3.registerStrategy(solanaStrategy); |
| 116 | +``` |
27 | 117 |
|
28 | | -\*\*Support for more chains coming soon. |
| 118 | +Key changes from previous versions: |
| 119 | +- `SIWEthereum` has been renamed to `SIWE` |
| 120 | +- `network` property has been renamed to `chain` |
| 121 | +- `chain` is now required when constructing from an object |
| 122 | +- Strategies must be registered manually (no longer auto-registered) |
29 | 123 |
|
30 | | -[Docs here](https://siww.web3auth.io) |
| 124 | +[Docs](https://siww.web3auth.io) |
0 commit comments