A comprehensive example demonstrating how to create an Autobase where multiple peers can write encrypted data, but only the bootstrapper can read the aggregated view. This implements a "single-reader" pattern using public key encryption.
This example shows how to layer encryption on top of standard Autobase multi-writer patterns to create a system where:
- Multiple writers can connect and send encrypted messages
- Only the bootstrapper (reader) can decrypt and view the content
- Writers cannot read each other's messages or the aggregated view
- All communication is end-to-end encrypted using public key cryptography
- Creates the Autobase and generates an encryption keypair
- Accepts new writers via blind-pairing
- Receives the bootstrapper's public key for encryption
- Decrypts messages using their private key
- Can read the complete aggregated view
- Connect to the bootstrapper using an invite code
- Receive the bootstrapper's public key during pairing
- Encrypt messages using ephemeral keypairs + bootstrapper's public key
- Cannot decrypt or read the Autobase view
- Can only write encrypted data
Each message is encrypted using:
- Ephemeral keypair generated per message
- Bootstrapper's public key for encryption
- Sodium crypto_box for authenticated encryption
- Format:
[ephemeralPubKey][nonce][ciphertext]
- π Single Reader: Only bootstrapper has private key to decrypt messages
- βοΈ Multiple Writers: Alice, Bob, Charlie can all write encrypted data
- π End-to-End Encryption: Messages encrypted before entering Autobase
- π€ Secure Pairing: Blind-pairing for writer authentication
- β Write-Only for Writers: Writers cannot read encrypted content
- π P2P Networking: Hyperswarm for peer discovery and connections
bootstrapper.js
- Creates Autobase, manages encryption keys, reads decrypted viewwriter.js
- Connects via blind-pairing, encrypts and writes datademo.js
- Automated demonstration with multiple writersREADME.md
- This documentation
Start the bootstrapper in one terminal:
node bootstrapper.js
The bootstrapper will output an invite code. Copy this code and start writers in separate terminals:
# Terminal 2 - Start Alice
node writer.js <invite_code> Alice
# Terminal 3 - Start Bob
node writer.js <invite_code> Bob
# Terminal 4 - Start Charlie
node writer.js <invite_code> Charlie
Writers can then type messages that will be encrypted and sent to the Autobase. Only the bootstrapper can read the decrypted content.
Run the complete demonstration:
node demo.js
This will automatically:
- Start a bootstrapper
- Connect three writers (Alice, Bob, Charlie)
- Send several encrypted messages
- Show that only the bootstrapper can read the content
- Clean up all resources
- End-to-end encryption: Messages are encrypted before writing to Autobase
- Forward secrecy: Each message uses a unique ephemeral keypair
- Reader isolation: Only the bootstrapper can decrypt messages
- Authenticated encryption: Uses sodium crypto_box for integrity
- Standard patterns: Follows reference Autobase multi-writer patterns
- Proper writer addition: Uses
addWriter
messages andautobase.update()
- Blind-pairing: Secure peer discovery and writer authorization
- Clean apply function: Separates encryption from Autobase logic
- Hyperswarm: For peer discovery and connections
- Corestore replication: Standard Hypercore data sync
- Graceful cleanup: Proper resource management
Message: { text: "Hello", from: "Alice", timestamp: 1234567890 }
β JSON serialize
β Generate ephemeral keypair
β crypto_box_easy(message, nonce, bootstrapper_pubkey, ephemeral_seckey)
β Combine: [ephemeral_pubkey][nonce][ciphertext]
β Store as hex string in Autobase
Encrypted data from Autobase
β Parse: [ephemeral_pubkey][nonce][ciphertext]
β crypto_box_open_easy(ciphertext, nonce, ephemeral_pubkey, bootstrapper_seckey)
β JSON parse decrypted message
β Display in readable view
This pattern is useful for:
- Anonymous data collection: Multiple sources, single analyzer
- Confidential reporting: Whistleblowing or sensitive feedback systems
- Research data gathering: Privacy-preserving data aggregation
- Audit logs: Multiple writers, single auditor with decryption access
- IoT sensor networks: Many sensors, centralized encrypted data lake
autobase
- Multi-writer append-only logcorestore
- Hypercore storage managementhyperswarm
- Peer discovery and networkingblind-pairing
- Secure peer pairing without shared secretssodium-universal
- Authenticated encryptionz32
- Base32 encoding for invite codes
- Writers become writable after being added by the bootstrapper
- The bootstrapper must remain online to add new writers
- Encryption keys are generated per session (not persisted)
- All temp files are cleaned up automatically
- Compatible with standard Autobase tooling and patterns
This example demonstrates how to add a security layer to Autobase while maintaining compatibility with the core protocol and patterns.