SafeX is an enterprise-grade, 100% non-custodial Web3 crypto wallet built from fundamental cryptographic primitives. It provides client-side zero-trust security, multi-chain HD address derivation (EVM + Bitcoin Native SegWit), offline EIP-1559 transaction construction, and direct decentralized blockchain node interactionโwith zero central database storing your keys or balances.
Important
True self-custody means zero server trust. In authentic Web3 architecture, storing private keys, seed phrases, or user wallet balances in a centralized database (such as PostgreSQL or MongoDB) is a major anti-pattern and a critical security vulnerability.
- No Database for Wallets: SafeX never records private keys, mnemonics, or balances to a server database.
- Pure Client-Side Cryptography: 100% of entropy generation, key derivation, and transaction signing occurs exclusively in the user's browser sandbox.
- Direct Node Communication: Signed raw bytecode is broadcast directly to decentralized Ethereum and Bitcoin JSON-RPC nodes.
Tip
For comprehensive architectural teardowns, mathematical proofs, and high-resolution diagrams, explore the /notes directory.
| Phase / Topic | Technical Focus & Engineering Scope | Handbook Link |
|---|---|---|
| Phase 1 | CSPRNG Entropy, BIP-39 Mnemonics, PBKDF2, Argon2id KDF, AES-256-GCM Vault, RAM Zeroization | ๐ Phase 1 Handbook |
| Phase 2 | EIP-1559 Transaction Anatomy, Gas Base Fee Burn, Priority Tips, ECDSA Secp256k1 Offline Signing | ๐ Phase 2 Handbook |
| Phase 3 | Nonce Management, Mempool Race Conditions, Replacement & Cancellation, Block Confirmations | ๐ Phase 3 Handbook |
| Phase 4 | Smart Contracts, 4-Byte EVM Calldata Selectors, ERC-20 Standard, Fixed-Point Arithmetic | ๐ Phase 4 Handbook |
| Phase 5 | On-Chain Swapping (DEX / AMM), Uniswap V2 Router & Factory, Multi-Hop Routing, Slippage Bounds | ๐ Phase 5 Handbook |
| Math & Curves | Secp256k1 Elliptic Curve Algebra, Discrete Logarithm Problem, Point Multiplication ( |
๐ Elliptic Curve Math |
| Fundamentals | Consensus Algorithms, Cryptographic Hashes, Peer-to-Peer Networks, Block Structures | ๐ Blockchain Core |
High-resolution technical diagrams located in /notes/infographics:
- Seed Phrase to Multi-Chain Address Pipeline
- Complete EIP-1559 Transaction Lifecycle
- Offline ECDSA Signing & Public Key Recovery Tuple $(r, s, v)$
- Sender Address Extraction from Raw Byte Stream
- Resilient Multi-Tier JSON-RPC Architecture
- EIP-1559 Transaction Anatomy Breakdown
All cryptographic operations occur on-device. The only external traffic is raw blockchain JSON-RPC calls.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLIENT BROWSER SANDBOX โ
โ โ
โ [ Entropy (CSPRNG) ] โโโบ [ BIP-39 Mnemonic ] โโโบ [ PBKDF2 ] โโโบ [ 512-bit Root Seed ]โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโ โ
โ โผ (BIP-44: m/44'/60'/0'/0/0) โผ (BIP-84: m/84'/0'/0'/0/0) โ โ
โ [ EVM Private Key ] [ BTC Private Key ] โ โ
โ โ โ โ โ
โ [ Secp256k1 Point Mult ] [ Secp256k1 Point Mult ] โ โ
โ โ โ โ โ
โ [ Keccak-256 + EIP-55 ] [ HASH160 + Bech32 Encoding ] โ โ
โ โผ โผ โ โ
โ Ethereum (0x5de9...Ac) Bitcoin Native SegWit (bc1q...3x) โ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Client-Side Vault Security (Zero Server Knowledge): โ โ
โ โ โข Master Password โโโบ Argon2id KDF (64MB RAM, 3 iterations) โโโบ 256-bit Key โ โ
โ โ โข Plaintext Mnemonic โโโบ AES-256-GCM Authenticated Encryption โโโบ IndexedDB โ โ
โ โ โข Tab Session Cache: Ephemeral sessionStorage with 10-min rolling timer โ โ
โ โ โข Memory Protection: buffer.fill(0) active RAM zeroization on lock/timeout โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Offline Transaction Signing (secp256k1): โ โ
โ โ [ Unsigned EIP-1559 Tx ] โโโบ [ Sign with PrivKey in RAM ] โโโบ [ Signed Hex ] โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Direct JSON-RPC (eth_sendRawTransaction)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DECENTRALIZED BLOCKCHAIN NODES โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Ethereum Mainnet / Sepolia โ โ Bitcoin SegWit Network โ โ
โ โ โข Viem JSON-RPC Multi-Pool โ โ โข Blockstream / Mempool.space โ โ
โ โ โข Gas Oracle & Nonce Sync โ โ โข UTXO Tracking & Fee Estimator โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-
Argon2id Memory-Hard KDF: Replaces legacy PBKDF2/SHA-256 password hashing with Argon2id (
$m=65,536\text{ KB}$ ,$t=3$ ,$p=1$ ) using@noble/hashes. By demanding 64 MB of dedicated RAM per hash attempt, brute-forcing master passwords on GPUs or ASICs is computationally infeasible. -
Authenticated Symmetric Encryption (AES-256-GCM): Plaintext recovery phrases are encrypted with a 12-byte random CSPRNG initialization vector (
iv) and sealed with a 16-byte Galois Field authentication tag (authTag). Any bit corruption or tampering immediately invalidates decryption. -
Ephemeral Session Persistence: Uses an in-memory /
sessionStoragehybrid cache. Survives page reloads (F5) in the active tab, but automatically self-destructs the moment the browser tab is closed. -
Active RAM Zeroization: Decrypted private keys exist only in volatile JavaScript memory while unlocked. When locked or after a 10-minute inactivity timeout, buffers are actively scrubbed using
.fill(0).
- BIP-39 Mnemonic Standards: Cryptographically secure entropy collection supporting 128-bit (12 words) and 256-bit (24 words) recovery phrases with SHA-256 checksum bits.
-
BIP-32 / BIP-44 Hierarchical Deterministic (HD) Paths:
-
Ethereum / EVM: Path
m/44'/60'/0'/0/0$\rightarrow$ Uncompressed public key$\rightarrow$ Keccak-256hashing of$(X, Y)$ coordinates$\rightarrow$ Drop first 12 bytes$\rightarrow$ EIP-55 mixed-case checksum. -
Bitcoin Native SegWit (BIP-84): Path
m/84'/0'/0'/0/0$\rightarrow$ Compressed public key (33 bytes)$\rightarrow$ HASH160(SHA-256 + RIPEMD-160)$\rightarrow$ Witness program version 0 with 5-bit Bech32 encoding (bc1q...).
-
Ethereum / EVM: Path
-
Type-2 Envelope Serialization: Constructs and encodes native EIP-1559 transactions:
$$\text{Payload} = \text{0x02} \mathbin{\Vert} \text{RLP}\left([ \text{chainId}, \text{nonce}, \text{maxPriorityFeePerGas}, \text{maxFeePerGas}, \text{gasLimit}, \text{to}, \text{value}, \text{data}, \text{accessList} ]\right)$$ -
Base Fee Burn & Priority Tip:
$$\text{Total Fee} = \text{Gas Units} \times (\text{Base Fee} + \text{Priority Fee})$$ -
Client-Side ECDSA Offline Signing: Uses curve
secp256k1to compute the signature tuple$(r, s, v)$ completely in the browser before broadcasting the signed hex bytecode to the blockchain mempool. -
Sender Address Extraction: Demonstrates mathematically how EVM miners recover the originating
fromaddress from$(r, s, v)$ without transmitting the sender's public key across the wire.
- EVM Calldata Construction: Manual calculation of 4-byte function selectors (
0xa9059cbbfortransfer(address,uint256)) and 32-byte left-padded hex encoding. - Fixed-Point Arithmetic (BigInt): Eliminates JavaScript IEEE-754 floating-point inaccuracies when handling token transfers with different decimal precisions (e.g. 6 decimals for USDC/USDT vs. 18 decimals for ETH/DAI).
- Multi-Chain Verified Registry: Seamlessly handles testnet assets (Sepolia USDC, LINK, WETH) and Ethereum Mainnet assets (native ETH, USDC, USDT, WBTC, DAI).
- Custom Token Dynamic Import: Paste any verified ERC-20 contract address to query
name(),symbol(),decimals(), andbalanceOf(address)directly from the blockchain state.
-
Constant-Product Market Maker (
$x \cdot y = k$ ): Executes on-chain token swaps with exact fee-adjusted output formulas:$$\Delta y = \frac{y \cdot 997 \cdot \Delta x}{1000 \cdot x + 997 \cdot \Delta x}$$ -
Canonical Multi-Hop Routing: Automatically constructs multi-hop routes across Wrapped Ether (
[tokenIn, WETH, tokenOut]) when direct liquidity pairs do not exist on the Uniswap V2 Factory. -
Two-Step Non-Custodial Authorization:
-
Allowance Check: Queries on-chain ERC-20
allowance(owner, router). If insufficient, prompts an atomic one-clickapprove()transaction. -
Router Execution: Encodes 4-byte calldata for
swapExactETHForTokens,swapExactTokensForETH, orswapExactTokensForTokens.
-
Allowance Check: Queries on-chain ERC-20
-
Slippage Bounds & Liquidity Protection:
$$\text{minAmountOut} = \text{expectedAmountOut} \times (1 - \text{slippageTolerance})$$ Enforces strictly on-chain slippage boundaries with zero fabricated math, alerting users to high price impact in low-depth pools. -
Network Support: Configured for Ethereum Mainnet (
Chain ID 1via official Uniswap Router0x7a25...488Dwith ETH, WETH, USDC, USDT, WBTC, DAI) and Sepolia Testnet (Chain ID 11155111).
- Zero-Downtime Fallback Transports: Configures multi-node resilient fallback pools:
- Sepolia Testnet: PublicNode, dRPC, and Ethereum Foundation (
rpc.sepolia.org). - Ethereum Mainnet: LlamaRPC, Ankr, Cloudflare, with plug-and-play support for dedicated Alchemy or Infura nodes.
- Sepolia Testnet: PublicNode, dRPC, and Ethereum Foundation (
- Automatic Node Failover: Network rate limits (HTTP 429) or node timeouts trigger instantaneous switching to healthy secondary RPC endpoints.
SafeX---Crypto-Wallet/
โโโ apps/
โ โโโ web/ # Next.js 14 Client-Side Wallet Application
โ โ โโโ app/ # Next.js App Router (Dashboard, Send, Receive, Swap, History, Status)
โ โ โโโ components/ # Shared UI (ChainSelector, BackToDashboard, VaultGate, QR)
โ โ โโโ core/ # Core cryptography (BIP-39, HD Keys, Vault, EIP-1559, oRPC client, utils)
โ โ โโโ features/ # Feature-driven modules (swap, send, receive, tokens, history, dashboard)
โ โโโ server/ # Lightweight Blockchain Helper & Broadcast Node
โ โโโ src/
โ โโโ core/ # Blockchain RPC fallback clients, gas estimation, base oRPC server
โ โโโ features/ # Modular backend feature routers (swap, tokens, prices, history, health, wallet)
โโโ notes/ # Deep Technical Handbooks (Phases 1โ5), Math Proofs, Infographics
โโโ Plan/ # Project Roadmap & Implementation Tracker
| Component | Technology | Role in Architecture |
|---|---|---|
| Frontend UI | Next.js 14 + React 18 + Tailwind CSS |
Client application, responsive dark-mode dashboard |
| RAM State | Zustand + sessionStorage |
Ephemeral in-memory vault state, 10-minute auto-lock |
| Local Vault Storage | IndexedDB (safex_db) |
Encrypted ciphertext storage (salt, iv, authTag, ciphertext) |
| Blockchain Engine | Viem 2.x + @scure/bip32 + @scure/base |
RLP encoding, multi-provider JSON-RPC, Bech32 & EIP-55 formatting |
| Cryptography | @noble/hashes (Argon2id, Keccak-256, SHA-256) |
Zero-trust client-side key derivation and authenticated encryption |
git clone https://github.com/Sandipxg/SafeX---Crypto-Wallet.git
cd SafeX---Crypto-Wallet
npm install-
Frontend Web (
apps/web/.env.local):cp apps/web/.env.example apps/web/.env.local
Pre-configured defaults:
NEXT_PUBLIC_API_URL=http://localhost:4000 NEXT_PUBLIC_SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com NEXT_PUBLIC_MAINNET_RPC_URL=https://eth.llamarpc.com
-
Backend Server (
apps/server/.env):cp apps/server/.env.example apps/server/.env
Launch the web wallet application:
npm run devOpen your browser to:
- ๐ SafeX Web Application: http://localhost:3000
- ๐ฉบ System Status & RPC Health: http://localhost:3000/status
Run the full monorepo test suite or individual workspace tests:
# Execute all unit tests across the entire monorepo (15 test suites)
npm test
# Frontend unit tests (BIP-39, HD keys, AES-GCM vault, token encoder, format & explorer)
npm --prefix apps/web test
# Backend unit tests (swap services, wallet services, tokens, prices, history, health)
npm --prefix apps/server testNote: SafeX is a progressive learning platform. While Phases 1โ5 implement a pure zero-trust self-custodial wallet, upcoming phases demonstrate centralized exchange mechanics:
- Phase 6: Exchange Custody & Deposit Sweeper: Hot/cold wallet segregation, auto-forwarding user deposits.
- Phase 7: Double-Entry Ledger (PostgreSQL): Immutable debits/credits accounting ledger preventing balance drift.
- Phase 8: High-Throughput Matching Engine: In-memory limit order book (LOB) matching FIFO bids/asks.
- Phase 9: Proof of Reserves (PoR): Cryptographic Merkle tree reserve audits allowing users to verify solvency.
Distributed under the MIT License. See LICENSE for full details.