Skip to content

Commit 4371db7

Browse files
Merge pull request #73 from Web3Auth/feat/combine-siwe-and-siws
feat: combine siwe and siws
2 parents 1e9f0bb + 78825ec commit 4371db7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+18575
-60304
lines changed

.cursor/worktrees.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"setup-worktree": ["npm install"]
3+
}

.github/CODEOWNERS

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Lines starting with '#' are comments.
2+
#
3+
# GUIDELINES:
4+
# Each line is a file pattern followed by one or more owners.
5+
# Owners bear a responsibility to the organization and the users of this
6+
# application. Repository administrators have the ability to merge pull
7+
# requests that have not yet received the requisite reviews as outlined
8+
# in this file. Do not force merge any PR without confidence that it
9+
# follows all policies or without full understanding of the impact of
10+
# those changes on build, release and publishing outcomes.
11+
#
12+
# The CODEOWNERS file constitutes an agreement amongst organisation
13+
# admins and maintainers to restrict approval capabilities to a subset
14+
# of contributors. Modifications to this file result in a modification of
15+
# that agreement and can only be approved by those with the knowledge
16+
# and responsibility to publish libraries under the MetaMask name.
17+
18+
# Fallback for all other files
19+
* @torusresearch/Admins
20+
21+
# Product code
22+
src/ @torusresearch/Web3Auth-Product
23+
test/ @torusresearch/Web3Auth-Product
24+
25+
# Most restrictive — last match wins
26+
.github/CODEOWNERS @torusresearch/Admins

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
test:
77
strategy:
88
matrix:
9-
node: ["22.x"]
9+
node: ["24.x"]
1010
os: [ubuntu-latest]
1111

1212
runs-on: ${{ matrix.os }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ secrets.json
2828
toruslabs-ethereum-embed*
2929

3030
.parcel-cache
31-
react-app/dist
31+
react-app/dist
32+
.eslintcache

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
>=18.x
1+
>=24.x

README.md

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,124 @@
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
42

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.
64

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).
106

11-
## What does Sign-in With Web3 Solve?
7+
## Supported Chains
128

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
1511

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.
1912

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`
21107

22-
Currently Sign-in with Web3 supports
108+
These packages have been deprecated and consolidated into this package.
23109

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+
```
27117

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)
29123

30-
[Docs here](https://siww.web3auth.io)
124+
[Docs](https://siww.web3auth.io)

0 commit comments

Comments
 (0)