Crate khodpay_signing

Crate khodpay_signing 

Source
Expand description

§Khodpay Signing

EVM transaction signing library for BSC (BNB Smart Chain) and other EVM-compatible chains.

This crate provides EIP-1559 (Type 2) transaction signing, integrating with khodpay-bip44 for HD wallet key derivation.

§Features

  • EIP-1559 Transactions: Modern fee market transactions
  • BSC Support: Native support for BNB Smart Chain (mainnet/testnet)
  • BIP-44 Integration: Seamless key derivation from HD wallets
  • BEP-20 Helpers: Token transfer encoding utilities

§Quick Start

use khodpay_signing::{Eip1559Transaction, ChainId, Wei, Bip44Signer};
use khodpay_bip44::{Wallet, Purpose, CoinType, Language};
use khodpay_bip32::Network;

// Create wallet and get account
let mnemonic = "your twelve word mnemonic phrase here";
let mut wallet = Wallet::from_mnemonic(mnemonic, "", Language::English, Network::BitcoinMainnet)?;
let account = wallet.get_account(Purpose::BIP44, CoinType::Ethereum, 0)?;

// Create signer
let signer = Bip44Signer::new(account, 0)?;

// Build transaction
let tx = Eip1559Transaction::builder()
    .chain_id(ChainId::BscMainnet)
    .nonce(0)
    .to("0x...".parse()?)
    .value(Wei::from_ether(1))
    .gas_limit(21000)
    .max_fee_per_gas(Wei::from_gwei(5))
    .max_priority_fee_per_gas(Wei::from_gwei(1))
    .build()?;

// Sign and get raw transaction
let signed = signer.sign_transaction(&tx)?;
let raw_tx = signed.to_raw_transaction();

Structs§

AccessListItem
An access list item specifying an address and its storage keys.
Address
A 20-byte EVM address.
Bip44Signer
A transaction signer using BIP-44 derived keys.
Eip1559Transaction
EIP-1559 (Type 2) transaction.
Eip1559TransactionBuilder
Builder for constructing EIP-1559 transactions.
Signature
An ECDSA signature with recovery ID.
SignedTransaction
A signed EIP-1559 transaction ready for broadcast.
Wei
A value in wei (smallest EVM currency unit).

Enums§

ChainId
EVM chain identifier for transaction replay protection.
Error
Errors that can occur during transaction signing operations.

Constants§

ETHER
The number of wei in one ether/BNB (10^18).
GWEI
The number of wei in one gwei (10^9).
TOKEN_TRANSFER_GAS
Typical gas limit for a BEP-20/ERC-20 token transfer.
TRANSFER_GAS
Gas limit for a standard ETH/BNB transfer.

Functions§

recover_signer
Recovers the signer’s address from a signature and message hash.

Type Aliases§

AccessList
A list of access list items.
Result
Result type alias for signing operations.