Skip to content

UniZKTech/wasm-WGSL-wallet

Repository files navigation

UniCash Browser Wallet

WebGPU-Accelerated Post-Quantum Blockchain Wallet


Overview

The UniCash wallet is a Progressive Web App (PWA) that enables users to:

  • Generate post-quantum cryptographic keys (Dilithium)
  • Create and sign transactions
  • Generate zero-knowledge proofs using WebGPU
  • Fallback to CPU proving (WASM) for unsupported devices

Architecture

wallet/
├── src/
│   ├── App.tsx              # Main React application
│   ├── main.tsx             # Entry point
│   ├── index.css            # Styles
│   ├── webgpu/
│   │   ├── prover.ts        # WebGPU proof generation
│   │   └── shaders/
│   │       ├── ntt.wgsl     # Number Theoretic Transform
│   │       └── fri.wgsl     # FRI folding
│   └── wasm/
│       └── crypto.ts        # WASM crypto bridge
├── public/
│   └── wasm/                # Compiled WASM modules
├── package.json
├── vite.config.ts
└── tsconfig.json

Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Rust and wasm-pack (for building WASM)
  • Modern browser with WebGPU support

Installation

cd unicash-mvp/wallet

# Install dependencies
npm install

# Build WASM module
npm run wasm:build

# Start development server
npm run dev

Open http://localhost:3000 in your browser.


Building WASM Module

The wallet uses Rust compiled to WebAssembly for cryptographic operations:

# Install wasm-pack (one time)
cargo install wasm-pack

# Build WASM module
cd unicash-mvp
wasm-pack build --target web --out-dir wallet/public/wasm wasm-crypto

# Or use npm script
cd wallet
npm run wasm:build

WebGPU Support

Supported Browsers (2026)

Browser Version WebGPU Support
Chrome 113+ ✅ Full support
Edge 113+ ✅ Full support
Safari 17+ ✅ Full support
Firefox 120+ ⚠️ Experimental

Checking WebGPU Support

The wallet automatically detects WebGPU support:

if (!navigator.gpu) {
  console.log('WebGPU not supported, falling back to CPU');
}

Fallback Strategy

  1. WebGPU (preferred): <1s proof generation
  2. WASM CPU: 3-5s proof generation
  3. Delegated proving: Send to prover network (future)

WGSL Shaders

NTT Shader (ntt.wgsl)

Performs Number Theoretic Transform on M31 field:

  • Cooley-Tukey FFT algorithm
  • Optimized for GPU parallelism
  • Handles up to 2^20 elements

FRI Shader (fri.wgsl)

Implements FRI folding for Circle STARKs:

  • Polynomial degree reduction
  • Query evaluation
  • Commitment generation

Performance Targets

Device Method Proof Time Status
Desktop GPU WebGPU <1s ✅ Target
Mobile GPU WebGPU <3s ✅ Target
Desktop CPU WASM 3-5s ✅ Acceptable
Mobile CPU WASM 5-10s ⚠️ Slow

Development

Running Tests

# Unit tests
npm test

# WASM tests
cd ../wasm-crypto
cargo test --target wasm32-unknown-unknown

Building for Production

# Build optimized bundle
npm run build

# Preview production build
npm run preview

Debugging

Enable verbose logging:

// In browser console
localStorage.setItem('debug', 'unicash:*');

Security Considerations

Key Storage

  • Keys stored in browser's IndexedDB
  • Encrypted with user password
  • Never sent to server

Proof Generation

  • All computation happens locally
  • No data leaves the device
  • Proofs are zero-knowledge (reveal nothing)

Network Communication

  • All RPC calls use HTTPS
  • WebSocket connections use WSS
  • P2P connections use libp2p encryption

Browser Compatibility

Required Features

  • WebAssembly (all modern browsers)
  • WebGPU (Chrome 113+, Safari 17+)
  • IndexedDB (for key storage)
  • Web Workers (for background tasks)

Progressive Enhancement

The wallet works on all devices but performs best with:

  • WebGPU support (10x faster proving)
  • 4GB+ RAM
  • Modern GPU (2020+)

Troubleshooting

"WebGPU not supported"

Solution: Use a supported browser or enable experimental features:

  • Chrome: chrome://flags/#enable-unsafe-webgpu
  • Firefox: about:configdom.webgpu.enabled

"WASM module failed to load"

Solution: Rebuild WASM module:

npm run wasm:build

"Proof generation too slow"

Solution:

  1. Check if WebGPU is enabled
  2. Close other GPU-intensive applications
  3. Use delegated proving (future feature)

Roadmap

Phase 1 (Current)

  • ✅ Basic UI
  • ✅ WebGPU detection
  • ✅ WASM crypto bridge
  • ⏳ WGSL shader implementation

Phase 2 (Next)

  • Transaction creation
  • Balance display
  • Transaction history
  • QR code support

Phase 3 (Future)

  • Staking interface
  • Multi-signature support
  • Hardware wallet integration
  • Mobile app (React Native)

Contributing

See CONTRIBUTING.md for development guidelines.


License

Apache 2.0 - See LICENSE for details.


Built with ❤️ for a post-quantum future

Unicash-WGSL-wallet

About

Generate ZK-start proof using WebGPU

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published