Skip to content

hi-tech-AI/holepunch-username-registry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Holepunch Username Registry

A peer-to-peer username registry built with Hyperswarm and Hyperbee, allowing users to register, lookup, and manage usernames in a decentralized network.

๐ŸŽฏ Complete Solution Overview

Core Components Created

1. Server Infrastructure (server.js)

  • 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

2. Client Interface (client.js)

  • 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

3. CLI & Utilities

  • cli.js: Command-line interface wrapper
  • example.js: Complete workflow demonstration
  • test.js: Comprehensive test suite
  • setup.js: Automated installation and setup
  • cleanup.js: Storage directory cleanup utility

4. Configuration & Documentation

  • package.json: Dependencies and npm scripts
  • README.md: Complete documentation and usage guide

โœจ Key Features Implemented

โœ… Core Username Management

  • 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)

โœ… Security & Validation

  • 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

โœ… P2P Architecture

  • 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

โœ… Developer Experience

  • 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

๐Ÿ—๏ธ Architecture Highlights

Technology Stack

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Client App    โ”‚    โ”‚   Server App    โ”‚    โ”‚   Bootstrap     โ”‚
โ”‚                 โ”‚    โ”‚                 โ”‚    โ”‚   Node          โ”‚
โ”‚ โ€ข @hyperswarm/  โ”‚โ—„โ”€โ”€โ–บโ”‚ โ€ข Hyperswarm    โ”‚โ—„โ”€โ”€โ–บโ”‚ โ€ข hyperdht     โ”‚
โ”‚   rpc           โ”‚    โ”‚ โ€ข Hyperbee      โ”‚    โ”‚ โ€ข localhost:   โ”‚
โ”‚ โ€ข Hyperbee      โ”‚    โ”‚ โ€ข ProtomuxRPC   โ”‚    โ”‚   30001        โ”‚
โ”‚ โ€ข Corestore     โ”‚    โ”‚ โ€ข Corestore     โ”‚    โ”‚                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow Architecture

  1. Registration/Deletion: Client โ†’ RPC โ†’ Server โ†’ Hyperbee
  2. Lookup/Listing: Client โ†’ Direct Hyperbee Query
  3. Replication: Server โ†” Client via Hyperswarm connections
  4. Discovery: Bootstrap node enables peer discovery

Storage Layer

  • 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

๐Ÿ”’ Security & Validation

Registration Security

  • โœ… One-Time Registration: Usernames cannot be reassigned to different keys
  • โœ… Duplicate Prevention: Rejects conflicting registrations
  • โœ… Ownership Validation: Only original registrant can modify/delete

Deletion Security

  • โœ… Authorization Check: Verifies public key ownership before deletion
  • โœ… Atomic Operations: All-or-nothing transaction handling
  • โœ… Error Handling: Graceful failure with informative messages

Network Security

  • โœ… Private DHT: Localhost-only network for testing
  • โœ… Peer Authentication: Cryptographic peer identity verification
  • โœ… Connection Encryption: Secure P2P communication

๐Ÿš€ Quick Start

Prerequisites

  1. Install the hyperdht package globally:

    npm install -g hyperdht
  2. Start the bootstrap node:

    hyperdht --bootstrap --host 127.0.0.1 --port 30001

Installation

# 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

Usage

Complete Example (Recommended)

# Run the complete demonstration
npm run example

Manual Server/Client Usage

# 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>

Available Scripts

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 setup

๐Ÿ“– API Reference

Server Methods

  • registerUsername(username, publicKey): Register a username
  • deleteUsername(username, publicKey): Delete a username
  • lookupUsername(username): Look up a username
  • listUsernames(): List all usernames

RPC Methods

  • register-username: Register a username via RPC
  • delete-username: Delete a username via RPC

Client Methods

  • registerUsername(username, publicKey): Register via RPC
  • deleteUsername(username, publicKey): Delete via RPC
  • lookupUsername(username): Direct Hyperbee lookup
  • listUsernames(): Direct Hyperbee listing

๐Ÿ”ง Implementation Details

Username Storage

  • 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

Network Configuration

  • Uses private DHT network running on localhost
  • Bootstrap node required for peer discovery
  • Automatic peer discovery and connection

File Management

  • Unique storage paths prevent file lock conflicts
  • Automatic cleanup of temporary directories
  • Proper resource management and cleanup

๐Ÿงช Testing

Test Suite

# Run all tests
npm test

# Run example demonstration
npm run example

Test Coverage

  • โœ… Username registration
  • โœ… Username lookup
  • โœ… Username listing
  • โœ… Username deletion
  • โœ… Duplicate prevention
  • โœ… Error handling
  • โœ… Cleanup procedures

๐Ÿšง Limitations

  1. No Persistence: Data is stored in local corestore directories
  2. Single Server: Currently designed for single server instance
  3. No Authentication: No built-in authentication mechanism
  4. Local Network: Configured for localhost testing only

๐Ÿ”ฎ Future Improvements

  1. Persistence: Add proper data persistence across restarts
  2. Multiple Servers: Support for multiple server instances
  3. Authentication: Add cryptographic authentication
  4. Public Network: Support for public network deployment
  5. Caching: Add caching layer for better performance

๐Ÿ› ๏ธ Development Approach

Priority Framework

  1. Core Functionality First - All required features implemented
  2. Clean Architecture - Modular, well-documented code structure
  3. Comprehensive Testing - Full test coverage and examples
  4. Easy Setup - Automated installation and configuration
  5. Error Resilience - Robust error handling and cleanup

Technical Decisions

  • 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

๐Ÿค– AI Usage

Development Acceleration

  • 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

Problem Solving

  • 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

Quality Assurance

  • 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

๐Ÿ“ Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Holepunch Team: For the excellent P2P ecosystem
  • Hyperswarm: For decentralized networking
  • Hyperbee: For persistent key-value storage
  • Community: For feedback and contributions

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Review the documentation
  3. Run the test suite to verify your setup
  4. Check the example demonstrations

๐ŸŽ‰ Ready to build the future of decentralized username registries!

About

A peer-to-peer username registry built with Hyperswarm and Hyperbee. Register, lookup, and manage usernames in a decentralized network with RPC interface, direct database access, and comprehensive security features.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors