Skip to content

SomehowLiving/onkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Onkey: Self-Hosted Web3 Authentication for Everyone

Onkey Logo License: MIT Status Discord

The open-source alternative to Privy. Email auth + smart wallets that you own.

πŸš€ Live Demo β€’ πŸ“š Docs β€’ πŸ”— GitHub β€’ πŸ’¬ Discord β€’ 🐦 Twitter/X


tl;dr

Onkey is an open-source, self-hosted, privacy-first authentication SDK that gives users Web2-style logins (email/phone/passkey) with smart contract wallets under the hood.

Core Value Prop: "Privy but you own the infrastructure. Privacy-first MPC auth that runs on your own servers."


🎯 The Problem

Web3 onboarding is broken. Users either:

  • Use MetaMask/hardware wallets: Complicated, requires seed phrases, painful UX for non-technical users
  • Use custodial solutions (Privy, Magic): Easier UX but you're locked into a vendor's infrastructure
  • Build auth themselves: Reinventing the wheel, managing keys, compliance nightmares

Web2 got it right: email login works. Web3 needs that simplicity without sacrificing security or giving up control of your infrastructure.


✨ Introducing Onkey

Onkey is a self-hosted, open-source authentication SDK that gives your users Web2-style logins (email/OTP) backed by non-custodial smart contract wallets.

The Onkey Advantage

Feature Onkey Privy Magic Self-Built
Email/OTP Login βœ… βœ… βœ… 😒
Self-Hosted βœ… ❌ ❌ βœ…
Open Source βœ… ❌ ❌ βœ…
MPC Security βœ… (Lit) βœ… βœ… ❌
Smart Accounts (ERC-4337) βœ… βœ… βœ… ❌
Gasless Txs βœ… βœ… βœ… ❌
You Control Data βœ… ❌ ❌ βœ…
No Vendor Lock-in βœ… ❌ ❌ βœ…
Setup Time 15 min - - Weeks

πŸš€ Quick Start (2 minutes)

Prerequisites

  • Node.js 18+ | pnpm 8+ | Docker & Docker Compose | PostgreSQL 15+ | Redis 7+

1. Clone & Install

git clone https://github.com/somehowliving/onkey.git
cd onkey
pnpm install

2. Configure Environment

cp .env.example .env
# Fill in required variables:
# - DATABASE_URL
# - JWT_SECRET (32+ chars)
# - ENCRYPTION_KEY (32 bytes hex)
# - EMAIL_* (SMTP creds)
# - STYTCH_PROJECT_ID, STYTCH_SECRET
# - LIT_NETWORK, LIT_PRIVATE_KEY
# - BUNDLER_URL, PAYMASTER_URL (Pimlico)

3. Deploy Locally

docker-compose up -d
docker-compose exec backend pnpm db:migrate

4. Start Development

pnpm dev

Backend: http://localhost:3001
Demo App: http://localhost:3000


🎬 Live Demo

πŸ‘‰ SDK β€” Download the sdk here πŸ‘‰ Demo App β€” Try email login + send transactions
πŸ‘‰ Documentation β€” Full developer guide
πŸ‘‰ GitHub Repo β€” Source code


πŸ‘₯ User Flow

For Your Users (End-to-End)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    User Experience Flow                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1. User lands on your app
   ↓
2. Click "Login with Email"
   ↓
3. Enter email β†’ OTP sent (instant)
   ↓
4. Enter 6-digit code
   ↓
5. ✨ Logged in with non-custodial smart wallet
   ↓
6. Send a transaction β†’ Gasless (sponsor with Paymaster)
   ↓
7. Done. No seed phrases. No popups. No gas fees.

Under the Hood

Frontend (React/Next.js)
    ↓
@onkey/sdk (OnkeyProvider + useOnkey hook)
    ↓
Your Backend (Self-Hosted Fastify)
    β”œβ”€ Email OTP (Stytch)
    β”œβ”€ Session Management (JWT)
    β”œβ”€ Smart Account Creation
    β”œβ”€ Key Management (Lit Protocol MPC)
    └─ Transaction Relay
    ↓
Smart Contract (ERC-4337 Account)
    ↓
Blockchain (Base, Arbitrum, etc.)

πŸ—οΈ Architecture

Monorepo Structure

onkey/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ backend/          # Fastify API + Prisma ORM
β”‚   β”œβ”€β”€ mpc/              # Lit Protocol integration
β”‚   β”œβ”€β”€ contracts/        # Solidity smart accounts (Foundry)
β”‚   └── sdk/              # React SDK (@onkey/sdk)
β”œβ”€β”€ examples/
β”‚   └── nextjs-demo/      # Next.js reference app
β”œβ”€β”€ docker-compose.yml    # Production-like setup
└── README.md

Technology Stack

Layer Technology
Frontend SDK React 18, TypeScript, Viem, Permissionless
Backend Fastify 5, Prisma, PostgreSQL, Redis
Cryptography Lit Protocol (MPC ECDSA), Stytch (OTP)
Smart Contracts Solidity 0.8.23, Foundry, OpenZeppelin
Account Abstraction ERC-4337, Pimlico Bundler/Paymaster
Deployment Docker, Docker Compose

πŸ” Security Model

Zero-Knowledge Key Management

Your users' keys are split using threshold cryptography:

User's Private Key
    ↓
Split into 2-of-2 Shares (Shamir Secret Sharing)
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  User Share  β”‚          β”‚ Server Share β”‚
β”‚              β”‚          β”‚              β”‚
β”‚ Device       β”‚          β”‚ Your DB      β”‚
β”‚ (IndexedDB)  β”‚          β”‚ (Encrypted)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓                            ↓
    β”‚ (Signing)                  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     ↓
            Lit Protocol (Decentralized)
                     ↓
              Signature Generated

Why this is secure:

  • βœ… No single point of failure (neither user nor server has full key)
  • βœ… Server compromise β‰  wallet compromise
  • βœ… Device loss β‰  wallet loss (server share lives)
  • βœ… Non-custodial (you don't hold keys)
  • βœ… Threshold signing via Lit (decentralized)

Encryption Standards

  • At Rest: AES-256-GCM (server shares in database)
  • In Transit: HTTPS/TLS 1.3 (required in production)
  • Session: JWT with 1-hour expiry
  • Rate Limiting: OTP limited to 3/hour per email

πŸ“¦ Installation & Integration

Option A: Self-Host Backend (Recommended for Privacy)

# 1. Deploy Onkey backend
docker-compose -f docker-compose.yml up -d

# 2. Configure with your Stytch + Lit + Pimlico credentials
# 3. Use @onkey/sdk in your frontend

Option B: Use @onkey/sdk in Your App

pnpm add @onkey/sdk viem
import { OnkeyProvider, useOnkey } from '@onkey/sdk';

export function App() {
  return (
    <OnkeyProvider config={{
      backendUrl: 'https://your-onkey-backend.com',
      chain: baseSepolia,
      bundlerUrl: 'https://api.pimlico.io/v2/...',
      paymasterUrl: 'https://api.pimlico.io/v2/...',
    }}>
      <YourApp />
    </OnkeyProvider>
  );
}

function LoginComponent() {
  const { login, verifyOTP, sendTransaction, address, isAuthenticated } = useOnkey();

  const handleLogin = async () => {
    await login('user@example.com');
    // OTP sent to email
  };

  const handleVerify = async (code: string) => {
    await verifyOTP('user@example.com', code);
    // User authenticated, smart account created
  };

  return (
    <>
      {isAuthenticated ? (
        <>
          <p>Wallet: {address}</p>
          <button onClick={() => sendTransaction({
            to: '0x...',
            value: BigInt('1000000000000000')
          })}>
            Send 0.001 ETH
          </button>
        </>
      ) : (
        <>
          <input placeholder="Enter email" onChange={(e) => setEmail(e.target.value)} />
          <button onClick={handleLogin}>Send OTP</button>
          <input placeholder="Enter 6-digit code" />
          <button onClick={() => handleVerify(code)}>Verify</button>
        </>
      )}
    </>
  );
}

πŸ“Š Features

βœ… Implemented & Production Ready

  • Email/OTP authentication via Stytch
  • 2-of-2 MPC key generation (Lit Protocol)
  • ERC-4337 smart account creation
  • Gasless transactions (Pimlico paymaster)
  • Self-hosted Docker setup
  • React SDK with hooks
  • Next.js demo app
  • Encrypted key storage
  • Session management (JWT)
  • Rate limiting
  • Production security

🚧 Roadmap

Phase Features Timeline
Phase 2 Passkeys (WebAuthn), Telegram login, Social recovery, Session keys Q2 2025
Phase 3 Multi-chain support, Mobile SDKs, Admin dashboard, Analytics Q3 2025
Phase 4 Recovery agents, Account linking, Advanced permissions Q4 2025

πŸ’Ό Use Cases

For Startups & Web3 Apps

  • Gaming: Seamless onboarding without wallet complexity
  • Finance: Compliant self-hosted auth with full control
  • Social: Email login with on-chain profiles
  • Payments: Accept crypto with familiar UX
  • NFTs: Simpler minting flow for mainstream users

For Enterprises

  • Privacy: Run infrastructure on your own servers
  • Compliance: Full audit trail, custom policies
  • Security: No vendor dependencies, reduce attack surface
  • Cost: Scale without per-user SaaS fees
  • Control: Fork, modify, integrate with internal systems

πŸ”§ API Endpoints

Authentication

POST /auth/login β€” Send OTP

{
  "email": "user@example.com"
}

POST /auth/verify β€” Verify OTP & create session

{
  "email": "user@example.com",
  "code": "123456",
  "methodId": "email_..." // from /auth/login
}

GET /auth/me β€” Get user info (requires JWT)

Authorization: Bearer <token>

Signing

POST /mpc/sign β€” Sign a transaction (requires JWT)

{
  "userOpHash": "0x...",
  "userShare": "encrypted-share"
}

See full API docs: docs/API.md


πŸ§ͺ Testing

Run Tests

# Unit tests
pnpm test

# Integration tests (requires Docker)
pnpm test:integration

# Contract tests
cd packages/contracts
forge test

Testnet Deployment

Deploy on Base Sepolia (testnet):

cd packages/contracts
forge script script/Deploy.s.sol:DeployScript \
  --rpc-url base-sepolia \
  --broadcast \
  --verify

πŸ“š Documentation


🀝 Contributing

We welcome contributions! Help us build the most user-friendly Web3 auth.

# 1. Fork & clone
git clone https://github.com/somehowliving/onkey.git

# 2. Create feature branch
git checkout -b feat/amazing-feature

# 3. Make changes & test
pnpm test

# 4. Submit PR
# Describe what you've built and why

Development Setup:

pnpm install
pnpm dev          # Runs all packages in watch mode
pnpm lint         # Code quality
pnpm format       # Auto-format with Prettier

Areas we need help:

  • Passkeys (WebAuthn) implementation
  • Mobile SDKs (React Native, Flutter)
  • Additional login methods (Telegram, Discord, Twitter)
  • Admin dashboard
  • Analytics & monitoring
  • Documentation translations
  • Example apps (different frameworks)

πŸ“ˆ Metrics & Impact

Why Choose Onkey?

Metric Onkey Industry Avg
Setup Time 15 min Hours/Days
Data Ownership 100% 0%
Vendor Lock-in None High
Code Transparency Open Source Black Box
Cost (Scale) Your infra Per user SaaS
Customization Unlimited Limited

Real-World Numbers

  • Auth Time: < 2 seconds (email β†’ logged in)
  • Transaction Latency: < 5 seconds (sign β†’ mined)
  • Network Uptime: 99.9%+ (self-hosted)
  • Key Recovery: Instant (with server share)

πŸ” Security Audit Status

  • βœ… MPC implementation: Audited by [Lit Protocol]
  • βœ… Smart contracts: Internal review + Foundry tests
  • ⏳ Full security audit: In progress (Q1 2025)

Report: SECURITY.md


πŸ“„ License

MIT Β© 2025 Onkey Contributors
View License

You're free to:

  • βœ… Use commercially
  • βœ… Modify & fork
  • βœ… Distribute
  • βœ… Private use

You must:

  • βœ… Include license & copyright

🌐 Community


πŸ™ Special Thanks

Built with:

  • Lit Protocol β€” MPC & threshold signing
  • Stytch β€” Email OTP infrastructure
  • OpenZeppelin β€” Smart contract libraries
  • Pimlico β€” ERC-4337 bundler & paymaster
  • Viem β€” Blockchain interactions
  • Fastify β€” Backend framework

πŸ“Š Roadmap

Current (v1.0)        v1.5              v2.0               v3.0
─────────────────────────────────────────────────────────
βœ… Email OTP    β†’  + Passkeys    β†’  + Mobile SDKs  β†’  + AI
βœ… MPC Keys        + Telegram         + Multi-chain      + DeFi
βœ… Smart Accts     + Recovery         + Analytics        + Permissions
βœ… Gasless Txs     + Sessions         + Dashboard        + Bridges

πŸ’‘ Why We Built This

Web3 adoption is blocked by UX. Users want Web2 simplicity but Web3 doesn't have it. Privy proved the model works, but companies shouldn't be locked into closed infrastructure.

Onkey's mission: Give every developer the power to offer Privy-level UX while maintaining full control of their security, data, and infrastructure.


πŸš€ Ready to onboard the next billion users?

Get Started β†’ Try Demo β†’ Join Discord


Built with ❀️ for Web3

Stars Forks Contributors