Technical Documentation
Demo ID: desktop-wallet-management Version: 1.0.0 Last Updated: December 9, 2025
Architecture Overview
This demo showcases a comprehensive wallet architecture using @bsv/sdk with BRC-42 key derivation, basket-based UTXO management, and P2PKH transactions. The architecture is portable from desktop to server-side implementations.
Technology Stack
SDK: @bsv/sdk (Official BSV Blockchain SDK)
Key Derivation: BRC-42 standard implementation
Script Type: P2PKH (Pay-to-Public-Key-Hash)
Language: TypeScript
Core Components
WalletClient: Main interface for wallet operations, identity management, and transaction creation
Key Derivation: BRC-42 hierarchical deterministic keys for protocol-specific key generation
Basket Manager: UTXO organization with fund categorization (savings, spending, payments, etc.)
Transaction Builder: P2PKH transaction creation with locking scripts and basket assignment
Balance Tracker: Multi-basket balance aggregation and real-time updates
Integration & APIs
External Dependencies
WalletClient API
Connection & Identity
Key Derivation (BRC-42)
Transaction Creation
Balance Querying
Implementation Guide
Prerequisites
Node.js v18 or higher
TypeScript 4.x or higher
Basic understanding of Bitcoin UTXO model
Knowledge of public/private key cryptography
BSV wallet with sufficient balance for testing
Getting Started
Clone the demo repository to get started quickly:
Alternatively, you can set up a project from scratch:
Configuration
Create tsconfig.json:
Basic Implementation
1. Wallet Connection
2. Key Derivation
3. Address Generation
4. Transaction Creation
5. Balance Calculation
Testing & Validation
Test Coverage
Unit Tests: Key derivation determinism, address generation correctness
Integration Tests: Wallet connection, transaction creation, balance queries
Manual Testing: End-to-end wallet operations with real BSV testnet
Validation Criteria
Testing Example
Performance & Scalability
Performance Metrics
Key Derivation: < 10ms per key
Transaction Creation: ~200ms (network dependent)
Balance Query: ~100ms per basket
Scalability Best Practices
Desktop to Server: Replace WalletClient with server-side key management and database layer for UTXO tracking
High-Volume: Use batch operations, key caching, and parallel queries
UTXO Management: Regularly consolidate small outputs to prevent fragmentation
Basket Organization: Use meaningful basket names and implement basket-specific spending policies
Maintenance & Support
Monitoring
Key Metrics
Transaction Success Rate: Track failed transactions
Balance Accuracy: Verify calculated vs actual balances
Key Derivation Errors: Monitor BRC-42 compliance
Network Connectivity: Check wallet service availability
Logging Implementation
Troubleshooting
"Wallet not connected"
WalletClient initialization failed
Verify BSV wallet software is running and accessible
"Invalid protocol ID"
Special characters in protocolID
Use only alphanumeric characters and spaces
"Insufficient funds"
Basket lacks required balance
Check balance or select different basket
"Transaction rejected"
Malformed locking script or insufficient fees
Validate P2PKH script format and ensure adequate fees
"Basket not found"
Basket name mismatch or never used
Check basket name spelling; create basket with transaction
"Key derivation failed"
Invalid BRC-42 parameters
Verify protocolID, keyID format compliance
Common Errors and Fixes
Error: Invalid Public Key
Error: Balance Mismatch
Production Considerations
Security Best Practices
Never expose private keys in logs or error messages
Store identity keys in secure hardware when possible
Always verify amounts before transaction creation
Restrict basket access based on user permissions
Audit all fund movements with immutable logs
Server-Side Adaptation
For production deployments, implement:
Database layer for key storage and UTXO tracking
Caching strategy for frequently accessed keys (LRU cache recommended)
Webhook notifications for transaction events
Connection pooling for concurrent operations
Advanced Concepts
Multi-Protocol Key Management
Use a protocol registry to organize keys by application context (payments, messaging, documents, tokens). The demo repository includes examples of protocol-specific key derivation.
UTXO Consolidation
Periodically consolidate small UTXOs (below a threshold like 1000 satoshis) when you have 10+ small outputs. This reduces transaction complexity and improves wallet performance.
Resources
Demo Repository: https://github.com/bsv-blockchain-demos/desktop-wallet-data
Business Documentation: Business Desktop Wallet Management Documentation
BSV SDK Documentation: Official BSV SDK
BRC-42 Specification: Key Derivation Standard
BSV Academy: Bitcoin Fundamentals
Support Contact: BSV Blockchain Association
For business context and use cases, see: Business Desktop Wallet Management Documentation
Last updated
