PrivateKey, PublicKey, and Signature classes.
Key Hierarchy
Hive uses ECDSA (secp256k1) keys, the same cryptographic system as Bitcoin. Each account has multiple key types with different permission levels:1
Owner Key
Highest authority. Used to change all other keys and recover accounts. Keep this offline and secure.
2
Active Key
Financial authority. Required for transfers, powering up/down, and account updates.
3
Posting Key
Content authority. Used for voting, posting, following, and other social actions. Safe for apps.
4
Memo Key
Encryption authority. Used to encrypt/decrypt transfer memos. Not used for signing transactions.
PrivateKey Class
ThePrivateKey class handles all private key operations: creation, signing, and key derivation.
Creating Private Keys
From WIF String
Wallet Import Format (WIF) is the standard way to store and transmit private keys:src/helpers/PrivateKey.ts:57
Generate Random Key
Create a cryptographically secure random key:src/helpers/PrivateKey.ts:179
Random key generation may take up to 250ms due to secure entropy collection. This is normal and ensures cryptographic security.
From Seed
Derive a key from a seed string or bytes:src/helpers/PrivateKey.ts:83
From Login Credentials
Generate keys from username and password using Hive’s standard derivation:src/helpers/PrivateKey.ts:105
SHA256(username + role + password)
Signing Messages
Sign a 32-byte hash to create a recoverable signature:src/helpers/PrivateKey.ts:117
Deriving Public Keys
Every private key has a corresponding public key:src/helpers/PrivateKey.ts:133
Exporting Private Keys
As WIF String
src/helpers/PrivateKey.ts:143
Safe Logging
For debugging without exposing the full key:src/helpers/PrivateKey.ts:154
Shared Secrets for Encryption
Compute ECDH shared secrets for memo encryption:src/helpers/PrivateKey.ts:166
- Alice:
alicePrivate.getSharedSecret(bobPublic) - Bob:
bobPrivate.getSharedSecret(alicePublic)
The shared secret is
SHA512(ECDH(privateKey, publicKey)). The parity byte is stripped before hashing.PublicKey Class
Public keys are derived from private keys and used for signature verification and encryption.Creating Public Keys
From String
src/helpers/PublicKey.ts:30
From Private Key
Verifying Signatures
Check if a signature is valid for a given message:src/helpers/PublicKey.ts:54
Signature object or a hex string:
Exporting Public Keys
src/helpers/PublicKey.ts:68
Signature Class
Signatures prove that a message was signed by a specific private key.Creating Signatures
From Signing
From Hex String
src/helpers/Signature.ts:28
- 1 byte: Recovery ID (allows public key recovery)
- 64 bytes: ECDSA signature (r, s values)
Signature Format
As Hex String
src/helpers/Signature.ts:65
As Buffer
src/helpers/Signature.ts:50
Recovering Public Keys
Signatures are “recoverable” - you can extract the public key that created them:src/helpers/Signature.ts:75
Key Formats
Private Key (WIF)
Wallet Import Format includes network ID and checksum:base58(0x80 + 32-byte-key + 4-byte-checksum)
Public Key
Includes address prefix and checksum:prefix + base58(33-byte-compressed-key + 4-byte-checksum)
Signature
130-character hex string:Security Best Practices
Key Storage
Key Storage
- Never hardcode private keys in source code
- Use environment variables or secure key management systems
- Encrypt keys at rest with strong passwords
- Use hardware wallets for owner/active keys when possible
Key Usage
Key Usage
- Use posting keys for apps when possible (can’t access funds)
- Never send private keys over unencrypted connections
- Validate key formats before using them
- Clear key data from memory after use in sensitive contexts
Development
Development
- Use testnet accounts for development
- Never commit real keys to version control
- Use
.envfiles with.gitignorefor local development - Audit dependencies that handle keys
Complete Example
Here’s a complete workflow showing key generation, signing, and verification:Next Steps
Transactions
Use keys to sign transactions
Operations
Learn which operations need which keys
Memo Encryption
Encrypt transfer memos
PrivateKey API
Full API reference