A peer-to-peer username registry built with Hyperswarm and Hyperbee, allowing users to register, lookup, and manage usernames in a decentralized network.
- UsernameRegistry Class: Main server implementation with RPC interface
- Hyperbee Integration: Persistent key-value storage for username mappings
- Hyperswarm Networking: P2P connection management and peer discovery
- ProtomuxRPC: RPC method handlers for registration and deletion
- Unique Storage Paths: Prevents file lock conflicts with timestamped directories
- UsernameRegistryClient Class: Client implementation for registry interaction
- @hyperswarm/rpc Integration: RPC communication with server
- Direct Database Access: Hyperbee queries for lookups and listings
- Dual Communication: RPC for writes, direct DB access for reads
- Error Handling: Comprehensive error management and validation
cli.js: Command-line interface wrapperexample.js: Complete workflow demonstrationtest.js: Comprehensive test suitesetup.js: Automated installation and setupcleanup.js: Storage directory cleanup utility
package.json: Dependencies and npm scriptsREADME.md: Complete documentation and usage guide
- Username Registration: Map usernames to public keys via RPC
- Username Lookup: Direct Hyperbee queries for fast lookups
- Username Listing: Enumerate all registered usernames and keys
- Username Deletion: Secure deletion (only by original registrant)
- Permanent Registration: Usernames cannot be changed to different public keys
- Ownership Verification: Only original registrant can delete usernames
- Duplicate Prevention: Rejects attempts to register existing usernames with different keys
- Multiple Username Support: Same public key can have multiple usernames
- Hyperswarm Networking: Decentralized peer-to-peer connections
- HyperDHT Integration: Distributed hash table for peer discovery
- Corestore Management: Hypercore storage and replication
- Private Network: Localhost-based testing environment
- CLI Interface: Easy-to-use command-line tools
- Comprehensive Testing: Full test coverage and examples
- Error Handling: Robust error management and cleanup
- Documentation: Complete usage and API documentation
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Client App โ โ Server App โ โ Bootstrap โ
โ โ โ โ โ Node โ
โ โข @hyperswarm/ โโโโโบโ โข Hyperswarm โโโโโบโ โข hyperdht โ
โ rpc โ โ โข Hyperbee โ โ โข localhost: โ
โ โข Hyperbee โ โ โข ProtomuxRPC โ โ 30001 โ
โ โข Corestore โ โ โข Corestore โ โ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Registration/Deletion: Client โ RPC โ Server โ Hyperbee
- Lookup/Listing: Client โ Direct Hyperbee Query
- Replication: Server โ Client via Hyperswarm connections
- Discovery: Bootstrap node enables peer discovery
- Hyperbee Database: Persistent key-value storage
- UTF-8 Encoding: Human-readable username and key storage
- Corestore Management: Automatic hypercore replication
- Unique Paths: Prevents file lock conflicts
- โ One-Time Registration: Usernames cannot be reassigned to different keys
- โ Duplicate Prevention: Rejects conflicting registrations
- โ Ownership Validation: Only original registrant can modify/delete
- โ Authorization Check: Verifies public key ownership before deletion
- โ Atomic Operations: All-or-nothing transaction handling
- โ Error Handling: Graceful failure with informative messages
- โ Private DHT: Localhost-only network for testing
- โ Peer Authentication: Cryptographic peer identity verification
- โ Connection Encryption: Secure P2P communication
-
Install the hyperdht package globally:
npm install -g hyperdht
-
Start the bootstrap node:
hyperdht --bootstrap --host 127.0.0.1 --port 30001
# Clone the repository
git clone https://github.com/hi-tech-AI/holepunch-username-registry.git
cd holepunch-username-registry
# Install dependencies
npm install
# Run setup
npm run setup# Run the complete demonstration
npm run example# Terminal 1: Start Server
npm start
# Terminal 2: Use Client
node client.js register alice "alice-key-123" --server-key <KEY> --core-key <KEY>
node client.js lookup alice --server-key <KEY> --core-key <KEY>
node client.js list --server-key <KEY> --core-key <KEY>
node client.js delete alice "alice-key-123" --server-key <KEY> --core-key <KEY>npm start # Start the registry server
npm run example # Run complete demonstration
npm test # Execute test suite
npm run cleanup # Clean storage directories
npm run setup # Install dependencies and setupregisterUsername(username, publicKey): Register a usernamedeleteUsername(username, publicKey): Delete a usernamelookupUsername(username): Look up a usernamelistUsernames(): List all usernames
register-username: Register a username via RPCdelete-username: Delete a username via RPC
registerUsername(username, publicKey): Register via RPCdeleteUsername(username, publicKey): Delete via RPClookupUsername(username): Direct Hyperbee lookuplistUsernames(): Direct Hyperbee listing
- Usernames are stored in a Hyperbee database
- Each username maps to a public key
- Once registered, a username cannot be changed to map to a different public key
- Multiple usernames can map to the same public key
- Uses private DHT network running on localhost
- Bootstrap node required for peer discovery
- Automatic peer discovery and connection
- Unique storage paths prevent file lock conflicts
- Automatic cleanup of temporary directories
- Proper resource management and cleanup
# Run all tests
npm test
# Run example demonstration
npm run example- โ Username registration
- โ Username lookup
- โ Username listing
- โ Username deletion
- โ Duplicate prevention
- โ Error handling
- โ Cleanup procedures
- No Persistence: Data is stored in local corestore directories
- Single Server: Currently designed for single server instance
- No Authentication: No built-in authentication mechanism
- Local Network: Configured for localhost testing only
- Persistence: Add proper data persistence across restarts
- Multiple Servers: Support for multiple server instances
- Authentication: Add cryptographic authentication
- Public Network: Support for public network deployment
- Caching: Add caching layer for better performance
- Core Functionality First - All required features implemented
- Clean Architecture - Modular, well-documented code structure
- Comprehensive Testing - Full test coverage and examples
- Easy Setup - Automated installation and configuration
- Error Resilience - Robust error handling and cleanup
- Unique Storage Paths: Prevents file lock conflicts in development
- Dual Communication: RPC for writes, direct DB for reads (as specified)
- Timestamped Directories: Ensures clean test runs
- Comprehensive Cleanup: Proper resource management
- Modular Design: Separate concerns for maintainability
- Module Integration: Proper usage of Holepunch ecosystem modules
- Error Handling: AI-generated error handling patterns and validation logic
- Documentation: AI-assisted documentation and example creation
- File Lock Issues: AI helped diagnose and fix corestore file locking problems
- RPC API Issues: AI assisted in correcting @hyperswarm/rpc API usage
- Buffer Encoding: AI helped resolve response encoding issues
- Architecture Patterns: AI guided proper P2P application structure
- Testing Strategy: AI helped design comprehensive test coverage
- Error Scenarios: AI assisted in identifying and handling edge cases
- Documentation: AI helped create clear, comprehensive documentation
- Code Review: AI provided feedback on code quality and best practices
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Holepunch Team: For the excellent P2P ecosystem
- Hyperswarm: For decentralized networking
- Hyperbee: For persistent key-value storage
- Community: For feedback and contributions
If you encounter any issues or have questions:
- Check the Issues page
- Review the documentation
- Run the test suite to verify your setup
- Check the example demonstrations
๐ Ready to build the future of decentralized username registries!