Class Wallet
A wallet is the primary interface for end-users to interact with the blockchain. It holds a secp256k1 key pair, derives a unique blockchain address from the public key, and provides methods to sign transactions and compute balances (FR-WALLET-01, FR-WALLET-04).
Key management
The wallet's private key is never exposed via public API. Instead, callers
invoke sign(Transaction) to produce a signed transaction. The private key
is accessible only to trusted code during import/export operations.
Address derivation
The blockchain address is derived once during construction via
AddressUtil.deriveAddress(java.security.PublicKey) and is immutable.
Thread safety
Wallet is immutable; all methods are thread-safe.
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanTwo wallets are equal if they derive the same address.Returns the blockchain address derived from this wallet's public key.getBalance(Blockchain blockchain) Computes the balance of this wallet by scanning the blockchain for all confirmed transactions involving this address.inthashCode()Hash code based on the wallet's address.sign(Transaction transaction) Signs a transaction with this wallet's private key.toString()Returns a human-readable summary of the wallet.
-
Method Details
-
getAddress
Returns the blockchain address derived from this wallet's public key.- Returns:
- non-null, Base58Check-encoded address
-
sign
Signs a transaction with this wallet's private key.The transaction is modified in-place (signature bytes are attached). The signer's address should match
getAddress(), but this is not enforced here — that validation occurs in the consensus layer.- Parameters:
transaction- the transaction to sign (non-null)- Returns:
- the same transaction, now with a signature attached
- Throws:
NullPointerException- if transaction is nullIllegalStateException- if signing fails (e.g., invalid key)
-
getBalance
Computes the balance of this wallet by scanning the blockchain for all confirmed transactions involving this address.The balance is the sum of all incoming transactions minus the sum of all outgoing transactions. Only transactions that have been included in a block are counted (FR-WALLET-04).
- Parameters:
blockchain- the blockchain to query (non-null)- Returns:
- the wallet's balance as a non-negative
BigDecimal - Throws:
NullPointerException- if blockchain is null
-
toString
Returns a human-readable summary of the wallet.The private key is never included in the output (NFR-SEC-01).
-
equals
Two wallets are equal if they derive the same address. -
hashCode
public int hashCode()Hash code based on the wallet's address.
-