Skip to content

Commit a45c612

Browse files
committed
Add WhipHash: Secure password generator using Pyth Entropy
1 parent b48bc74 commit a45c612

Some content is hidden

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

44 files changed

+16604
-0
lines changed

entropy/whiphash/README.md

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
# WhipHash - Secure Password Generator
2+
3+
**Built with Pure High Pyth Entropy**
4+
5+
A decentralized password generator that creates cryptographically secure passwords using high-entropy randomness from the Pyth Network, combined with advanced client-side encryption and secure storage in NilDB.
6+
7+
## 🔗 Contract Explorer & Transaction Details
8+
9+
**📊 Transaction Explorer**: [View on BaseScan](https://sepolia.basescan.org/address/0xE861DC68Eb976da0661035bBf132d6F3a3288B71)
10+
11+
**💰 Pyth Network Fee**: **0.00000015 ETH** (constant throughout the project)
12+
- **Cost Efficiency**: Ultra-low fees for high-entropy randomness
13+
14+
## 📋 Deployed Contracts
15+
16+
### Base Sepolia Testnet
17+
18+
| Contract | Address | Purpose |
19+
|----------|---------|---------|
20+
| **RandomnessGen** | `0xE861DC68Eb976da0661035bBf132d6F3a3288B71` | Generates random number pairs using Pyth Network entropy |
21+
| **Entropy** | `0x41c9e39574F40Ad34c79f1C99B66A45eFB830d4c` | Pyth Network entropy provider contract |
22+
23+
### Contract Details
24+
- **Network**: Base Sepolia Testnet (Chain ID: 84532)
25+
- **Deployment Hash**: `0x39a943edca709c3337e2b01e6b58cf9db16af0b6403acb48448f7094b9354bb1`
26+
- **Block**: 32774035
27+
- **Gas Used**: 1,857,888 gas
28+
- **Cost**: 0.000001858038488928 ETH
29+
- **Status**: ✅ Verified on Sourcify
30+
31+
## 🏗️ Architecture Overview
32+
33+
### Client-Side Password Generation
34+
- **Pure Client-Side**: All password generation happens in the browser using Web Crypto API
35+
- **No Server Dependency**: Passwords are never transmitted to servers in plaintext
36+
- **Device Secrets**: Generated locally using `crypto.getRandomValues()`
37+
38+
### Server-Side Storage
39+
- **Encrypted Storage**: Passwords are encrypted before being sent to NilDB
40+
- **NilDB Integration**: Decentralized database for secure password storage
41+
- **Metadata Preservation**: Transaction hashes and sequence numbers stored for verification
42+
43+
## 🔒 Encryption & Security Implementation
44+
45+
### Multi-Layer Cryptographic Process
46+
47+
#### 1. **Device Secret Generation (C)**
48+
```javascript
49+
// Generate 32-byte device secret locally
50+
const deviceSecret = crypto.getRandomValues(new Uint8Array(32))
51+
```
52+
- **Purpose**: Local entropy source that never leaves the device
53+
- **Storage**: Kept in memory only, never transmitted
54+
55+
#### 2. **On-Chain Randomness (R1, R2)**
56+
```solidity
57+
// Pyth Network provides two random numbers
58+
uint256 n1; // First random number (R1)
59+
uint256 n2; // Second random number (R2)
60+
```
61+
- **Source**: Pyth Network's high-entropy randomness
62+
- **Verification**: Blockchain transaction provides cryptographic proof
63+
- **Advantage**: Unpredictable, verifiable, and tamper-proof
64+
65+
#### 3. **HKDF Key Derivation**
66+
```javascript
67+
// Mix R1 + C → local_raw using HKDF-SHA256
68+
const localRaw = await hkdf(ikm, 32, appSalt1, 'local_raw_v1')
69+
```
70+
- **Algorithm**: HKDF-SHA256 (RFC 5869)
71+
- **Purpose**: Combines on-chain and device entropy
72+
- **Security**: Normalizes inputs and provides uniform seed
73+
74+
#### 4. **Memory-Hard Key Derivation**
75+
```javascript
76+
// Harden local_raw → LocalKey using Argon2id/scrypt
77+
const localKey = await argon2id(localRaw, salt1, params, 32)
78+
```
79+
- **Algorithm**: Argon2id/scrypt (memory-hard)
80+
- **Parameters**: 64MB memory, 3 iterations, 4 parallelism
81+
- **Purpose**: Defends against offline brute force attacks
82+
83+
#### 5. **Final Password Derivation**
84+
```javascript
85+
// Derive final password using LocalKey + R2
86+
const passwordBytes = await argon2id(seedRaw, passwordSalt, params, 32)
87+
```
88+
- **Process**: HKDF + Argon2id for final hardening
89+
- **Output**: 32-byte password material
90+
- **Character Set**: Letters, numbers, symbols (94 characters)
91+
92+
### Security Advantages
93+
94+
#### **Pyth Network Entropy Benefits:**
95+
1. **True Randomness**: Pyth provides cryptographically secure random numbers
96+
2. **Verifiable**: Blockchain transactions provide proof of randomness
97+
3. **Tamper-Proof**: Immutable blockchain prevents manipulation
98+
4. **High Entropy**: Superior to pseudo-random number generators
99+
5. **Decentralized**: No single point of failure or control
100+
101+
#### **Multi-Layer Protection:**
102+
- **Device Secret**: Local entropy prevents server-side attacks
103+
- **On-Chain Proof**: Blockchain provides verifiable randomness
104+
- **Memory Hardening**: Argon2id prevents GPU/ASIC attacks
105+
- **HKDF Mixing**: Combines multiple entropy sources securely
106+
107+
## 🚀 How to Run the Project
108+
109+
### Prerequisites
110+
- Node.js 18+
111+
- npm or yarn
112+
- MetaMask wallet (for blockchain interaction)
113+
- Git
114+
115+
### 1. Clone the Repository
116+
```bash
117+
git clone <repository-url>
118+
cd whiphash
119+
```
120+
121+
### 2. Install Dependencies
122+
```bash
123+
npm install
124+
```
125+
126+
### 3. Environment Setup
127+
```bash
128+
cp .env.example .env.local
129+
```
130+
131+
#### Required Environment Variables
132+
```env
133+
# NilDB Configuration
134+
NILLION_API_KEY=your-nillion-api-key
135+
NILLION_COLLECTION_ID=your-collection-id
136+
137+
# Alternative NilDB Configuration (if using different setup)
138+
NILCHAIN_URL=http://rpc.testnet.nilchain-rpc-proxy.nilogy.xyz
139+
NILAUTH_URL=https://nilauth.sandbox.app-cluster.sandbox.nilogy.xyz
140+
NILDB_NODES=https://nildb-stg-n1.nillion.network,https://nildb-stg-n2.nillion.network,https://nildb-stg-n3.nillion.network
141+
BUILDER_PRIVATE_KEY=your-builder-private-key
142+
```
143+
144+
### 4. Start the Development Server
145+
```bash
146+
npm run dev
147+
```
148+
149+
The app will be available at `http://localhost:3000`
150+
151+
### 5. Browser Extension (Optional)
152+
153+
#### Install the Extension
154+
1. Open Chrome and go to `chrome://extensions/`
155+
2. Enable "Developer mode"
156+
3. Click "Load unpacked"
157+
4. Select the `demo-extension` folder
158+
5. Pin the extension for easy access
159+
160+
#### Extension Features
161+
- **🖼️ Embedded Mode**: View app within extension popup
162+
- **⛶ Fullscreen Mode**: Open app in new tab
163+
- **🔗 Wallet Mode**: Optimized for wallet interactions
164+
165+
### 6. Usage Instructions
166+
167+
#### Generate a Password
168+
1. **Connect Wallet**: Click "Connect Wallet" and approve MetaMask
169+
2. **Request Randomness**: Click "Generate Secure Password"
170+
3. **Wait for Pyth**: System fetches randomness from Pyth Network
171+
4. **Password Generated**: Secure password appears with copy option
172+
5. **Store Password**: Enter socials and save to NilDB
173+
174+
#### View Saved Passwords
175+
1. Navigate to `/view` or click "View Saved Passwords →"
176+
2. See all stored passwords with metadata
177+
3. Click to show/hide passwords
178+
4. Copy passwords to clipboard
179+
180+
## 🛠️ Development
181+
182+
### Project Structure
183+
```
184+
whiphash/
185+
├── app/ # App router pages
186+
│ ├── page.tsx # Landing page
187+
│ ├── test/page.tsx # Password generation
188+
│ ├── view/page.tsx # Password viewing
189+
│ └── api/nildb/ # NilDB API routes
190+
├── components/ # React components
191+
├── lib/ # Utility functions
192+
└── demo-extension/ # Browser extension
193+
```
194+
195+
### Key Technologies
196+
- **Frontend**: Next.js 16, React 19, TypeScript, Tailwind CSS
197+
- **Blockchain**: Viem, Ethers.js, Base Sepolia
198+
- **Randomness**: Pyth Network, Entropy Protocol
199+
- **Storage**: NilDB (Nillion Network)
200+
- **Crypto**: Web Crypto API, HKDF, Argon2id/scrypt
201+
- **UI**: Three.js, GSAP, Custom animations
202+
203+
### API Endpoints
204+
- `POST /api/nildb/store-password` - Store encrypted password
205+
- `GET /api/nildb/read-collection` - Retrieve stored passwords
206+
- `GET /api/nildb/test-config` - Test NilDB configuration
207+
208+
## 🔐 Security Considerations
209+
210+
### What's Encrypted
211+
- ✅ Passwords (client-side generation)
212+
- ✅ Device secrets (never transmitted)
213+
- ✅ Storage in NilDB (encrypted at rest)
214+
- ✅ All sensitive data (socials, metadata)
215+
216+
### What's Public
217+
- ✅ Transaction hashes (for verification)
218+
- ✅ Sequence numbers (for randomness proof)
219+
- ✅ Blockchain randomness (verifiable on-chain)
220+
221+
### Best Practices
222+
- **Never share device secrets**
223+
- **Verify transaction hashes**
224+
- **Use strong master passwords**
225+
- **Regular security audits**
226+
227+
## 📊 Performance
228+
229+
### Password Generation Time
230+
- **Device Secret**: ~1ms (local generation)
231+
- **Blockchain Call**: ~2-5s (Pyth Network)
232+
- **HKDF Processing**: ~10ms
233+
- **Argon2id**: ~100-500ms (memory-hard)
234+
- **Total**: ~3-6 seconds per password
235+
236+
### Storage Efficiency
237+
- **Password**: 16-32 characters
238+
- **Metadata**: ~1KB per entry
239+
- **NilDB**: Decentralized, redundant storage
240+
241+
## 🤝 Contributing
242+
243+
1. Fork the repository
244+
2. Create a feature branch
245+
3. Make your changes
246+
4. Test thoroughly
247+
5. Submit a pull request
248+
249+
## 📄 License
250+
251+
This project is licensed under the MIT License - see the LICENSE file for details.
252+
253+
## 🙏 Acknowledgments
254+
255+
- **Pyth Network** for providing high-entropy randomness
256+
- **Nillion Network** for decentralized storage
257+
- **Base Network** for fast, low-cost transactions
258+
- **MetaMask** for wallet integration
259+
- **Next.js** for the React framework
260+
261+
## 🔗 Links
262+
263+
- **Live Demo**: [ETHGlobal Showcase](https://ethglobal.com/showcase/whiphash-9u5xj)
264+
- **GitHub Repository**: [dumprahul/whiphash](https://github.com/dumprahul/whiphash)
265+
- **Contract Explorer**: [BaseScan](https://sepolia.basescan.org/address/0xE861DC68Eb976da0661035bBf132d6F3a3288B71)
266+
267+
---
268+
269+
**Built with ❤️ and pure high Pyth entropy**

entropy/whiphash/abi/DeployRandomnessGen.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)