khodpay-signing
EVM transaction signing for BSC and other EVM-compatible chains.
Features
- EIP-1559 Transactions: Full support for Type 2 transactions with priority fees
- BIP-44 Integration: Sign transactions using keys derived from HD wallets
- BSC Support: Built-in chain IDs for BSC Mainnet (56) and Testnet (97)
- Security: Automatic zeroization of sensitive key material
- Type Safety: Strong types for
Address,Wei,ChainId, andSignature
Quick Start
use Network;
use ;
use ;
// 1. Create wallet from mnemonic
let mut wallet = from_english_mnemonic.unwrap;
// 2. Get Ethereum account (CoinType 60 for EVM chains)
let account = wallet.get_account.unwrap;
// 3. Create signer
let signer = new.unwrap;
println!;
// 4. Build transaction
let recipient: Address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e".parse.unwrap;
let tx = builder
.chain_id
.nonce
.max_priority_fee_per_gas
.max_fee_per_gas
.gas_limit
.to
.value
.build
.unwrap;
// 5. Sign transaction
let signature = signer.sign_transaction.unwrap;
let signed_tx = new;
// 6. Get raw transaction for broadcast
let raw_tx = signed_tx.to_raw_transaction;
println!;
println!;
Types
ChainId
Network identifier for replay protection:
use ChainId;
let mainnet = BscMainnet; // 56
let testnet = BscTestnet; // 97
let custom = Custom; // Ethereum mainnet
Address
20-byte EVM address with EIP-55 checksum:
use Address;
// Parse from hex
let addr: Address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e".parse.unwrap;
// Display with checksum
println!; // 0x742d35Cc6634C0532925a3b844Bc454e4438f44e
Wei
256-bit unsigned integer for Ether/BNB amounts:
use Wei;
let one_ether = from_ether;
let one_gwei = from_gwei;
let one_wei = from_wei;
// Arithmetic
let total = one_ether + one_gwei;
Eip1559Transaction
EIP-1559 (Type 2) transaction with builder pattern:
use ;
let tx = builder
.chain_id
.nonce
.max_priority_fee_per_gas // Tip
.max_fee_per_gas // Max total fee
.gas_limit // 21,000 for transfers
.to
.value
.data // Optional calldata
.build
.unwrap;
Bip44Signer
Signs transactions using BIP-44 derived keys:
use Bip44Signer;
// From BIP-44 account
let signer = new.unwrap;
// Or from raw private key (for testing)
let signer = from_private_key.unwrap;
let address = signer.address;
let signature = signer.sign_transaction.unwrap;
SignedTransaction
Signed transaction ready for broadcast:
use SignedTransaction;
let signed = new;
// For eth_sendRawTransaction
let raw = signed.to_raw_transaction; // "0x02f86c..."
// Transaction hash
let hash = signed.tx_hash_hex; // "0x..."
Gas Constants
use ;
// Standard ETH/BNB transfer
assert_eq!;
// Typical BEP-20/ERC-20 token transfer
assert_eq!;
Security
- Private keys are wrapped in
Zeroizingto ensure they're cleared from memory SignatureimplementsZeroizeto clearr,s,vwhen dropped- The underlying
k256::SigningKeyalso implementsZeroize
Optional Features
serde
Enable serialization support:
[]
= { = "0.1", = ["serde"] }
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.