khodpay-signing
EVM signing library for BSC and other EVM-compatible chains.
Provides EIP-1559 transaction signing, EIP-712 typed structured data signing, and
ERC-4337 v0.7 PackedUserOperation support — all built on BIP-44 HD wallet key derivation.
Features
- EIP-1559 Transactions: Type-2 transactions for EOA wallets
- EIP-712 Typed Data: Generic, protocol-agnostic structured data signing (any struct)
- ERC-4337 Account Abstraction:
PackedUserOperationv0.7 — build, hash, sign, verify - BIP-44 Integration: Sign 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 — EIP-1559 (EOA Wallet)
use Network;
use ;
use ;
let mut wallet = from_english_mnemonic.unwrap;
let account = wallet.get_account.unwrap;
let signer = new.unwrap;
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;
let signature = signer.sign_transaction.unwrap;
let signed_tx = new;
println!; // "0x02..."
println!;
Quick Start — EIP-712 Typed Data
Implement Eip712Type for any struct to get standards-compliant typed data signing:
use ;
use Address;
let gateway: Address = "0x1111111111111111111111111111111111111111".parse.unwrap;
let domain = new;
let intent = PaymentIntent ;
let sig = sign_typed_data.unwrap;
let valid = verify_typed_data.unwrap;
assert!;
Quick Start — ERC-4337 Smart Wallet (Gasless)
use ;
use Address;
let entry_point: Address = ENTRY_POINT_V07.parse.unwrap;
let user_op = builder
.sender
.nonce
.call_data // any contract call
.account_gas_limits // verificationGas, callGas
.pre_verification_gas
.gas_fees // maxPriorityFee, maxFee (wei)
.paymaster
.build
.unwrap;
let sig = sign_user_operation.unwrap;
let mut signed_op = user_op;
signed_op.signature = sig.to_bytes.to_vec; // submit to bundler
Types
ChainId
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;
let addr: Address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e".parse.unwrap;
println!; // 0x742d35Cc6634C0532925a3b844Bc454e4438f44e
Wei
256-bit unsigned integer for Ether/BNB amounts:
use Wei;
let one_ether = from_ether;
let one_gwei = from_gwei;
let total = one_ether + one_gwei;
Bip44Signer
use Bip44Signer;
let signer = new.unwrap;
// or for testing:
let signer = from_private_key.unwrap;
let address = signer.address;
let signature = signer.sign_transaction.unwrap;
let sig712 = sign_typed_data.unwrap;
let sig4337 = sign_user_operation.unwrap;
Gas Constants
use ;
assert_eq!; // Standard ETH/BNB transfer
assert_eq!; // Typical BEP-20/ERC-20 transfer
EIP-712 Encoding Helpers
Available inside Eip712Type::encode_data() implementations:
| Helper | Solidity type |
|---|---|
encode_address(&addr) |
address |
encode_uint64(n) |
uint64 |
encode_u256_bytes(&bytes) |
uint256 |
encode_bool(b) |
bool |
encode_bytes32(bytes) |
bytes32 |
encode_bytes_dynamic(&bytes) |
bytes / string |
Optional Features
| Feature | Enables |
|---|---|
serde |
Serialization for core types |
eip712 |
eip712 module (implies serde) |
erc4337 |
erc4337 module (implies eip712) |
[]
= { = "0.2", = ["erc4337"] }
Security
- Private keys are wrapped in
Zeroizing— cleared from memory on drop SignatureimplementsZeroizeto clearr,s,v- The underlying
k256::SigningKeyalso implementsZeroize - Zero unsafe code
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.