gleeth/crypto/wallet
Types
Represents an Ethereum wallet with private key and derived address
pub type Wallet {
Wallet(
private_key: secp256k1.PrivateKey,
public_key: secp256k1.PublicKey,
address: secp256k1.EthereumAddress,
)
}
Constructors
-
Wallet( private_key: secp256k1.PrivateKey, public_key: secp256k1.PublicKey, address: secp256k1.EthereumAddress, )
Error types for wallet operations
pub type WalletError {
InvalidPrivateKey(String)
InvalidHex(String)
KeyGenerationFailed(String)
SigningFailed(String)
}
Constructors
-
InvalidPrivateKey(String) -
InvalidHex(String) -
KeyGenerationFailed(String) -
SigningFailed(String)
Values
pub fn equals(wallet1: Wallet, wallet2: Wallet) -> Bool
Check if two wallets are the same (have same private key)
pub fn error_to_string(error: WalletError) -> String
Convert WalletError to string for display
pub fn from_private_key_bytes(
bytes: BitArray,
) -> Result(Wallet, WalletError)
Create a wallet from raw private key bytes
pub fn from_private_key_hex(
hex_string: String,
) -> Result(Wallet, WalletError)
Create a wallet from a private key hex string Supports both with and without 0x prefix
pub fn generate() -> Result(Wallet, WalletError)
Generate a new random wallet using cryptographically secure randomness
pub fn get_address(wallet: Wallet) -> String
Get the wallet’s Ethereum address as a string
pub fn get_private_key_bytes(wallet: Wallet) -> BitArray
Get the wallet’s private key as raw bytes
pub fn get_private_key_hex(wallet: Wallet) -> String
Get the wallet’s private key as a hex string
pub fn get_public_key_bytes(wallet: Wallet) -> BitArray
Get the wallet’s public key as raw bytes
pub fn get_public_key_hex(wallet: Wallet) -> String
Get the wallet’s public key as a hex string
pub fn is_recoverable_error(error: WalletError) -> Bool
Check if an error is recoverable
pub fn recover_personal_message(
message: String,
signature_hex: String,
) -> Result(String, WalletError)
Recover the signer address from an EIP-191 personal message signature. Applies the standard prefix before recovery, matching what MetaMask and other wallets produce with personal_sign.
pub fn sign_hash(
wallet: Wallet,
message_hash: BitArray,
) -> Result(secp256k1.Signature, WalletError)
Sign a message hash with the wallet’s private key
pub fn sign_message(
wallet: Wallet,
message: BitArray,
) -> Result(secp256k1.Signature, WalletError)
Sign raw message bytes (will be hashed with keccak256)
pub fn sign_personal_message(
wallet: Wallet,
message: String,
) -> Result(secp256k1.Signature, WalletError)
Sign an Ethereum personal message
pub fn to_string(wallet: Wallet) -> String
Convert a wallet to a summary string for display
pub fn to_summary(wallet: Wallet) -> String
Convert a wallet to a compact summary for logging
pub fn verify_personal_message(
message: String,
signature_hex: String,
expected_address: String,
) -> Result(Bool, WalletError)
Verify that a specific address signed a personal message.