Key Types
Ubu-Block uses asymmetric cryptography with two types of keys:Private Keys (SigningKey)
- Used to create digital signatures
- Must be kept secret and secure
- Stored in the
private_dbdatabase - Never transmitted over the network
- Required to create new blocks
Public Keys (VerifyingKey)
- Used to verify digital signatures
- Can be shared publicly
- Stored in the
chain_dbdatabase - Distributed to all nodes
- Used to validate blocks
Key Generation
Keys are generated using cryptographically secure random numbers:The public key is derived from the private key using elliptic curve mathematics. This is a one-way operation - you cannot derive the private key from the public key.
Key Storage
Ubu-Block uses two separate SQLite databases for key storage:Private Key Database (private_db)
Stores private keys that belong to this node:
crates/database/src/lib.rs:115-130 for the full implementation.
Private key storage includes:
pubkey_hash- SHA3-256 hash of the corresponding public keyprivkey- Hex-encoded private key bytestime_added- Unix timestamp when the key was added
Public Key Database (chain_db)
Stores all public keys in the network:
crates/database/src/lib.rs:93-113 for the full implementation.
Public key storage includes:
pubkey_hash- SHA3-256 hash of the public keycreator- Human-readable identifier for the key ownerpubkey- Hex-encoded public key bytesstate- Key state (“A” for active, revoked keys have different states)time_added- Unix timestamp when addedblock_height- Block number when the key was addedtime_revoked- Optional timestamp if the key was revoked
Key Retrieval
Getting Your Private Key
When creating a new block, the node retrieves its private key:crates/database/src/lib.rs:147-154 for the full implementation.
This returns a tuple containing:
SigningKey- Used to sign new blocksVerifyingKey- Used for signature verificationPubKey- Metadata about the key
Getting a Public Key by Hash
When verifying a block, the node looks up the creator’s public key:crates/database/src/lib.rs:156-183 for the full implementation.
Public Key Structure
ThePubKey struct contains:
Key Hashing
Public keys are hashed to create shorter identifiers:- Stored in block headers as
signature_pub_key_hash - Used to look up the full public key during verification
- Provides a consistent-length identifier
Hashing public keys provides several benefits:
- Shorter identifiers (64 characters vs. variable length)
- Consistent format across the system
- Additional layer of abstraction
Key Lifecycle
1. Generation
When initializing a node:2. Active Use
When creating blocks:3. Verification
When validating blocks:4. Revocation
Keys can be revoked (though the revocation mechanism is not yet fully implemented):Multi-Key Support
A node can manage multiple key pairs:crates/database/src/lib.rs:132-138 for the full implementation.
This allows:
- Key rotation for security
- Different keys for different purposes
- Multiple authorized signers
Security Best Practices
Private Key Protection
Backup Strategy
- Regular Backups: Back up
private.dbto secure, encrypted storage - Multiple Locations: Store backups in geographically distributed locations
- Access Control: Limit who can access backup files
- Test Restoration: Periodically verify you can restore from backups
Key Rotation
While not required, periodic key rotation improves security:
- Generate a new key pair
- Add the new public key to the blockchain
- Start using the new key for future blocks
- Keep the old key for historical verification
Database Schema
Private Keys Table
Public Keys Table
Integration with Block Creation
When creating a new block, the system:- Retrieves the private key from
private_db - Hashes the corresponding public key
- Includes the hash in the block header
- Signs the block hash with the private key
- Signs the previous block hash
- Stores both signatures in the new block
crates/types/src/lib.rs:74-111 for the block creation implementation.
Troubleshooting
Key Not Found
If you get “key not found” errors:Invalid Signature
If signature verification fails:- Verify the public key hash matches
- Check the key hasn’t been corrupted
- Ensure you’re using the correct key for verification
- Validate the key was active when the block was created
Database Corruption
If key databases are corrupted:- Restore from backup immediately
- Validate blockchain integrity after restoration
- Re-sync with other nodes if necessary