Skip to content

Commit 043ab32

Browse files
committed
Preparing for open source
0 parents  commit 043ab32

38 files changed

Lines changed: 20386 additions & 0 deletions

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
.env
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Base Verify Airdrop Demo
2+
3+
A Next.js mini app demonstrating Base Verify integration for X (Twitter) verification and airdrop claiming. Users connect their wallet, verify their X account through Base Verify, and claim an airdrop.
4+
5+
## Features
6+
7+
- **🔐 Wallet Integration**: Connect via Coinbase Wallet or other Web3 wallets using OnchainKit
8+
- **✅ X (Twitter) Verification**: Verify X accounts using Base Verify API
9+
10+
## Architecture
11+
12+
### Authentication Flow
13+
14+
1. **Wallet Connection**: User connects wallet via OnchainKit
15+
2. **Signature Generation**: App generates SIWE message with verification traits
16+
3. **Base Verify Redirect**: User redirects to Base Verify mini app with PKCE challenge
17+
4. **X Verification**: User verifies X account on Base Verify
18+
5. **Callback**: Base Verify redirects back with authorization code
19+
6. **Token Exchange**: App exchanges code for verification token
20+
7. **Database Storage**: Store wallet address + verification token (prevents reuse)
21+
8. **Airdrop Claimed**: Success confirmation
22+
23+
### Database Schema
24+
25+
```prisma
26+
model VerifiedUser {
27+
id String @id @default(cuid())
28+
address String @unique // Wallet address
29+
baseVerifyToken String? @unique // Verification token from Base Verify
30+
createdAt DateTime @default(now())
31+
updatedAt DateTime @updatedAt
32+
33+
@@map("verified_users")
34+
}
35+
```
36+
37+
**Key Constraints:**
38+
- `address` is unique (one claim per wallet)
39+
- `baseVerifyToken` is unique (prevents verification token reuse)
40+
41+
### API Routes
42+
43+
- **POST `/api/verify-token`**: Verifies signature with Base Verify API and stores user
44+
- **GET `/api/users`**: Fetches all verified users
45+
- **POST `/api/delete-airdrop`**: Allows users to delete their claim (requires signature)
46+
47+
## Setup
48+
49+
### Prerequisites
50+
51+
- Node.js 20+ and npm
52+
- PostgreSQL database
53+
- Coinbase Developer Platform account
54+
- Base Verify API access (secret key)
55+
56+
### 1. Install Dependencies
57+
58+
```bash
59+
npm install
60+
```
61+
62+
### 2. Environment Variables
63+
64+
Create a `.env.local` file in the root directory (see .env.example)
65+
66+
### 3. Database Setup
67+
68+
```bash
69+
# Generate Prisma client
70+
npm run db:generate
71+
72+
# Push schema to database (for development)
73+
npm run db:push
74+
75+
# Or run migrations (for production)
76+
npx prisma migrate deploy
77+
```
78+
79+
### 4. Run Development Server
80+
81+
```bash
82+
npm run dev
83+
```
84+
85+
The app will start on [http://localhost:3003](http://localhost:3003)
86+
87+
### 5. Open Prisma Studio (Optional)
88+
89+
To view/edit database records:
90+
91+
```bash
92+
npm run db:studio
93+
```
94+
95+
### SIWE Signature with Base Verify
96+
97+
The app uses Sign-In with Ethereum (SIWE) messages with custom resources to communicate verification requirements:
98+
99+
```typescript
100+
// Example SIWE message structure
101+
{
102+
domain: "your-app.vercel.app",
103+
address: "0x123...",
104+
statement: "Sign in with X verification",
105+
uri: "cbwallet://miniapp?url=https://your-app.vercel.app",
106+
chainId: 8453, // Base mainnet
107+
resources: [
108+
"urn:verify:action:base_verify_token",
109+
"urn:verify:provider:x",
110+
"urn:verify:provider:x:verified:true"
111+
]
112+
}
113+
```
114+
115+
### Signature Caching
116+
117+
To improve UX, signatures are cached in localStorage for 5 minutes:
118+
- Prevents repeated signature requests during verification flow
119+
- Automatically cleared on address change or error
120+
- Validates address and action match before reuse
121+
122+
### PKCE Flow
123+
124+
The app implements PKCE (Proof Key for Code Exchange) for secure OAuth-like flow:
125+
1. Generate code verifier and challenge
126+
2. Store verifier in sessionStorage
127+
3. Redirect to Base Verify with challenge
128+
4. Exchange authorization code + verifier for token
129+
130+
### Delete Functionality
131+
132+
Users can delete their own airdrop claim:
133+
- Signs message: `"Delete airdrop for {address}"`
134+
- Backend verifies signature using Viem (supports EOA & EIP-1271)
135+
- Removes user from database
136+

components/ErudaProvider.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
export function ErudaProvider() {
4+
return (
5+
<>
6+
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
7+
<script src="https://cdn.jsdelivr.net/npm/eruda" />
8+
<script>eruda.init();</script>
9+
</>
10+
)
11+
}

0 commit comments

Comments
 (0)