Documentation
¶
Index ¶
- Constants
- func DeriveKeyFromPath(masterKey *bip32.Key, coin, account, chain, address uint32) (*bip32.Key, error)
- func GenerateKeysFromMnemonic(mnemonic string, coin, account, chain, address uint32) (*secp256k1.PrivateKey, *secp256k1.PublicKey, error)
- func GenerateMnemonic(bitSize int) (string, error)
- func GenerateTronAddress(publicKey *secp256k1.PublicKey) string
Constants ¶
const ( HardenedOffset uint32 = 0x80000000 Purpose uint32 = 44 )
Variables ¶
This section is empty.
Functions ¶
func DeriveKeyFromPath ¶
func DeriveKeyFromPath(masterKey *bip32.Key, coin, account, chain, address uint32) (*bip32.Key, error)
DeriveKeyFromPath derives a private key from a master key using BIP44 hierarchical deterministic derivation BIP44 defines a specific derivation path structure: m/purpose'/coin_type'/account'/change/address_index Where: - purpose: Always 44' (0x8000002C) for BIP44 compliance - coin_type: Registered coin type (e.g., 0' for Bitcoin, 60' for Ethereum) - account: Account index starting from 0' (allows multiple accounts per coin) - change: 0 for external chain (receiving addresses), 1 for internal chain (change addresses) - address_index: Address index starting from 0 (sequential address generation)
The apostrophe (') indicates hardened derivation (adds 0x80000000 to the index) Hardened derivation provides additional security by making it impossible to derive the parent private key from a child private key and parent public key
func GenerateKeysFromMnemonic ¶
func GenerateKeysFromMnemonic(mnemonic string, coin, account, chain, address uint32) (*secp256k1.PrivateKey, *secp256k1.PublicKey, error)
GenerateKeysFromMnemonic converts a BIP39 mnemonic phrase into secp256k1 private/public key pair with flexible BIP44 derivation path parameters
This is a more flexible version that allows specifying custom derivation paths rather than hardcoded values, enabling support for: - Multiple cryptocurrencies (Bitcoin, Ethereum, Tron, etc.) - Multiple accounts per coin - Both receiving and change addresses - Any address index in the sequence
Parameters: - mnemonic: BIP39 mnemonic phrase (12, 15, 18, 21, or 24 words) - coin: Coin type from SLIP-0044 registry (e.g., 0 for Bitcoin, 60 for Ethereum, 195 for Tron) - account: Account index (usually 0 for first account) - chain: 0 for external chain (receiving), 1 for internal chain (change) - address: Address index (0, 1, 2, ... for sequential addresses)
func GenerateMnemonic ¶
GenerateMnemonic creates a new BIP39 mnemonic phrase for wallet seed generation BIP39 defines a method for generating deterministic wallets using human-readable words The mnemonic acts as a master seed that can regenerate all wallet keys deterministically
Security considerations: - The entropy must be cryptographically secure and truly random - Mnemonic phrases should be stored securely and never transmitted over insecure channels - Loss of the mnemonic means permanent loss of wallet access - The mnemonic can regenerate the entire wallet hierarchy across different applications
func GenerateTronAddress ¶
GenerateTronAddress generates a TRON address from a secp256k1 public key TRON addresses are similar to Ethereum addresses but use a different prefix and encoding The process follows these steps: 1. Extract uncompressed public key coordinates 2. Hash using Keccak-256 (same as Ethereum) 3. Take last 20 bytes and add TRON prefix (0x41) 4. Add double SHA-256 checksum 5. Encode in Base58 format
TRON addresses always start with 'T' when encoded and are 34 characters long Example: TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy
Types ¶
This section is empty.