Documentation
¶
Overview ¶
Package hdwallet is a Trust Wallet-compatible hierarchical-deterministic wallet for Go.
It generates a BIP-39 mnemonic (or imports one) and derives receive addresses for many networks using the same derivation paths and address formats Trust Wallet uses by default, so seeds are interchangeable between the two.
Secrets (the mnemonic and the derived seed) are never held as plain Go strings or long-lived byte slices. They are stored in encrypted, page-locked memguard enclaves and decrypted only for the duration of a single derivation. Always call (*HDWallet).Destroy when finished, and consider memguard.Purge on program exit.
Index ¶
- Constants
- Variables
- func ABIEncode(name string, args []ABIValue) ([]byte, error)
- func ABIEncodeParams(values []ABIValue) ([]byte, error)
- func ABIFunctionSelector(name string, types []string) []byte
- func AddressFromPublicKey(symbol Symbol, pub []byte) (string, error)
- func EIP712Hash(typedDataJSON []byte) ([]byte, error)
- func EncodeRLP(item RLPItem) []byte
- func EthereumPersonalMessageHash(message []byte) []byte
- func GenerateMnemonic() (string, error)
- func GenerateMnemonicWithWordCount(words int) (string, error)
- func IsValidAddress(symbol Symbol, addr string) bool
- func ParseAddress(symbol Symbol, addr string) ([]byte, error)
- func RecoverEthereumAddress(message, sig []byte) (string, error)
- func ValidateAddress(symbol Symbol, addr string) error
- func Verify(curve Curve, pub, data []byte, sig *Signature) bool
- func VerifyBitcoinMessage(address string, message []byte, sigBase64 string) bool
- func VerifyEthereumMessage(addressOrPubKey string, message, sig []byte) bool
- func VerifyEthereumTypedData(addressOrPubKey string, typedDataJSON, sig []byte) bool
- func VerifySolanaMessage(address string, message []byte, sigBase58 string) bool
- type ABIValue
- type Coin
- type Curve
- type HDWallet
- func FromMnemonic(mnemonic string) (*HDWallet, error)
- func FromMnemonicBuffer(buf *memguard.LockedBuffer) (*HDWallet, error)
- func FromMnemonicBufferWithPassphrase(buf, passphrase *memguard.LockedBuffer) (*HDWallet, error)
- func FromMnemonicBytes(mnemonic []byte) (*HDWallet, error)
- func FromMnemonicWithPassphrase(mnemonic, passphrase []byte) (*HDWallet, error)
- func FromPrivateKeyBuffer(buf *memguard.LockedBuffer, curve Curve) (*HDWallet, error)
- func FromPrivateKeyBytes(priv []byte, curve Curve) (*HDWallet, error)
- func FromWIF(wif []byte) (*HDWallet, error)
- func NewHDWallet() (*HDWallet, error)
- func NewHDWalletWithEntropy(bits int) (*HDWallet, error)
- func NewHDWalletWithWordCount(words int) (*HDWallet, error)
- func (w *HDWallet) AccountXPub(symbol Symbol, account uint32) (string, error)
- func (w *HDWallet) Address(symbol Symbol) (string, error)
- func (w *HDWallet) AddressAt(symbol Symbol, account, change, index uint32) (string, error)
- func (w *HDWallet) AddressIndex(symbol Symbol, index uint32) (string, error)
- func (w *HDWallet) AddressPath(symbol Symbol, path string) (string, error)
- func (w *HDWallet) AllAddresses() (map[Symbol]string, error)
- func (w *HDWallet) AllAddressesAt(index uint32) (map[Symbol]string, error)
- func (w *HDWallet) Destroy()
- func (w *HDWallet) Mnemonic() (*memguard.LockedBuffer, error)
- func (w *HDWallet) PrivateKey(symbol Symbol, index uint32) (*memguard.LockedBuffer, error)
- func (w *HDWallet) PrivateKeyPath(symbol Symbol, path string) (*memguard.LockedBuffer, error)
- func (w *HDWallet) PublicKey(symbol Symbol) ([]byte, error)
- func (w *HDWallet) PublicKeyAt(symbol Symbol, account, change, index uint32) ([]byte, error)
- func (w *HDWallet) PublicKeyIndex(symbol Symbol, index uint32) ([]byte, error)
- func (w *HDWallet) PublicKeyPath(symbol Symbol, path string) ([]byte, error)
- func (w *HDWallet) Sign(symbol Symbol, data []byte) (*Signature, error)
- func (w *HDWallet) SignAt(symbol Symbol, account, change, index uint32, data []byte) (*Signature, error)
- func (w *HDWallet) SignBitcoinMessage(symbol Symbol, index uint32, message []byte) (string, error)
- func (w *HDWallet) SignIndex(symbol Symbol, index uint32, data []byte) (*Signature, error)
- func (w *HDWallet) SignMessage(symbol Symbol, index uint32, message []byte) ([]byte, error)
- func (w *HDWallet) SignPath(symbol Symbol, path string, data []byte) (*Signature, error)
- func (w *HDWallet) SignSolanaMessage(symbol Symbol, index uint32, message []byte) (string, error)
- func (w *HDWallet) SignTransaction(symbol Symbol, index uint32, input proto.Message) (proto.Message, error)
- func (w *HDWallet) SignTypedData(symbol Symbol, index uint32, typedDataJSON []byte) ([]byte, error)
- func (w *HDWallet) WIF(symbol Symbol, index uint32) (*memguard.LockedBuffer, error)
- func (w *HDWallet) WithAccountXPrv(symbol Symbol, account uint32, fn func(xprv []byte) error) error
- func (w *HDWallet) WithMnemonic(fn func(mnemonic []byte) error) error
- func (w *HDWallet) WithPrivateKey(symbol Symbol, index uint32, fn func(priv []byte) error) error
- func (w *HDWallet) WithPrivateKeyPath(symbol Symbol, path string, fn func(priv []byte) error) error
- func (w *HDWallet) WithWIF(symbol Symbol, index uint32, fn func(wif []byte) error) error
- type RLPItem
- type Signature
- type Symbol
- type WatchWallet
Examples ¶
Constants ¶
const ( EthTxModeLegacy uint32 = 0 // EIP-155 legacy EthTxModeEIP2930 uint32 = 1 // type-1 access-list EthTxModeEIP1559 uint32 = 2 // type-2 fee market )
EVM transaction modes, selecting the serialization format produced by SignTransaction for an EVM chain. They are the values of ethereum.SigningInput.tx_mode; use them instead of bare integers.
Variables ¶
var ( // ErrABIType is returned for an unrecognized or unsupported ABI type string. ErrABIType = errors.New("hdwallet: unsupported ABI type") // ErrABIValue is returned when a Go value does not match its ABI type. ErrABIValue = errors.New("hdwallet: ABI value does not match type") // ErrABIDecode is returned when ABI-encoded input is malformed. ErrABIDecode = errors.New("hdwallet: malformed ABI encoding") )
ABI-related errors.
var ( // ErrRLPCanonical is returned when a decoded item is not in canonical form // (e.g. a leading zero in a length prefix, or a single byte < 0x80 wrapped in // a string header). Ethereum requires canonical RLP. ErrRLPCanonical = errors.New("hdwallet: non-canonical RLP encoding") // ErrRLPTruncated is returned when the input ends before a declared length. ErrRLPTruncated = errors.New("hdwallet: truncated RLP input") // ErrRLPTrailing is returned by DecodeRLP when bytes remain after one item. ErrRLPTrailing = errors.New("hdwallet: trailing bytes after RLP item") )
RLP-related errors.
var ( // ErrInvalidMnemonic is returned when a mnemonic fails BIP-39 validation. ErrInvalidMnemonic = errors.New("hdwallet: invalid mnemonic") // ErrUnsupportedCoin is returned for a symbol not in the registry. ErrUnsupportedCoin = errors.New("hdwallet: unsupported coin") // ErrDestroyed is returned by operations on a wallet whose secrets were wiped. ErrDestroyed = errors.New("hdwallet: wallet has been destroyed") // ErrInvalidDigest is returned when an ECDSA signing input is not 32 bytes. ErrInvalidDigest = errors.New("hdwallet: digest must be 32 bytes") // ErrInvalidPrivateKey is returned when an imported private key has the wrong // length or is otherwise invalid for its curve. ErrInvalidPrivateKey = errors.New("hdwallet: invalid private key") // ErrUnsupportedCurve is returned when a curve is not one of the supported // elliptic curves. ErrUnsupportedCurve = errors.New("hdwallet: unsupported curve") // ErrCurveMismatch is returned when an operation targets a coin whose curve // differs from the curve of a key-only wallet's imported private key. ErrCurveMismatch = errors.New("hdwallet: coin curve does not match imported key curve") // ErrKeyOnlyWallet is returned by mnemonic/seed-only operations (Mnemonic, // WithMnemonic, AllAddresses) on a wallet imported from a raw private key. ErrKeyOnlyWallet = errors.New("hdwallet: operation not available on a private-key-only wallet") // ErrKeyOnlyIndex is returned when a non-zero address/sign index is requested // on a key-only wallet, which has a single leaf key and no HD path. ErrKeyOnlyIndex = errors.New("hdwallet: private-key-only wallet supports only index 0") // ErrPathArity is returned by the structured account/change/index helpers // (AddressAt, SignAt, PublicKeyAt) when a coin's path template is not a // 5-element BIP-44/BIP-84 path; use the AddressPath/SignPath primitives instead. ErrPathArity = errors.New("hdwallet: coin path is not a 5-element BIP-44/84 path; use the *Path methods") // ErrExtKeyUnsupportedCurve is returned by the extended-key (xprv/xpub) and // watch-only APIs for a non-secp256k1 coin: BIP-32 extended keys and public // (non-hardened) child derivation apply only to secp256k1; the SLIP-0010 // ed25519/nist256p1 schemes support hardened derivation only. ErrExtKeyUnsupportedCurve = errors.New("hdwallet: extended keys / watch-only require a secp256k1 coin") // ErrInvalidWordCount is returned when a requested mnemonic length is not a // valid BIP-39 word count (12, 15, 18, 21, or 24) or entropy size in bits // (128, 160, 192, 224, or 256). ErrInvalidWordCount = errors.New("hdwallet: invalid mnemonic word count") )
Exported sentinel errors. Consumers can match them with errors.Is; errors that add context (e.g. the offending symbol) wrap these with %w.
var ( // ErrTxUnsupported is returned when SignTransaction is asked to sign for a // symbol whose family has no transaction builder. ErrTxUnsupported = errors.New("hdwallet: transaction signing not supported for coin") // ErrTxInput is returned when the SigningInput proto type does not match the // family selected by symbol, or a required field is missing/invalid. ErrTxInput = errors.New("hdwallet: invalid transaction signing input") // ErrTxRoadmap is returned by families that are planned but not yet // vector-verified; the corresponding builder is intentionally not shipped. ErrTxRoadmap = errors.New("hdwallet: transaction signing for this coin is not yet implemented") )
Transaction-signing errors.
var ( // ErrEIP712 is returned for malformed typed data or unsupported types. ErrEIP712 = errors.New("hdwallet: invalid EIP-712 typed data") )
EIP-712-related errors.
var ( // ErrEthSignature is returned when an Ethereum signature is malformed. ErrEthSignature = errors.New("hdwallet: invalid ethereum signature") )
Ethereum message errors.
var ErrInvalidAddress = errors.New("hdwallet: invalid address")
ErrInvalidAddress is the base sentinel for all address-validation failures. Specific reasons (bad checksum, wrong prefix, wrong length, …) wrap it with %w, so errors.Is(err, ErrInvalidAddress) matches any validation failure while the message still describes the precise cause.
var ErrInvalidWIF = errors.New("hdwallet: invalid WIF private key")
ErrInvalidWIF is returned for a malformed WIF string or a WIF export requested for a non-secp256k1 coin.
var ErrNotRecoverable = errors.New("hdwallet: coin curve does not support recoverable signatures")
ErrNotRecoverable is returned by SignBitcoinMessage when the coin's curve is not secp256k1 (only secp256k1 produces a recoverable signature).
Functions ¶
func ABIEncode ¶ added in v0.2.2
ABIEncode encodes a function call: selector(name,types...) || head/tail(args). The signature is formed from name and the argument types, so name must be the bare function name (e.g. "transfer"), not the full signature.
func ABIEncodeParams ¶ added in v0.2.2
ABIEncodeParams encodes a tuple of values (no selector) using the head/tail layout. This is the encoding used for the arguments of a call and for nested tuples/arrays.
func ABIFunctionSelector ¶ added in v0.2.2
ABIFunctionSelector returns the 4-byte selector for a function signature built from name and the given argument types (the canonical forms are used).
func AddressFromPublicKey ¶ added in v0.2.2
AddressFromPublicKey derives the address for symbol directly from an external public key, reusing the registry's encoder (read-only). pub must be the curve's expected public-key form: a 33-byte compressed key for secp256k1/nist256p1, or a 32-byte key for ed25519. An unknown symbol returns ErrUnsupportedCoin; a malformed key is reported by the underlying encoder.
func EIP712Hash ¶ added in v0.2.2
EIP712Hash parses MetaMask-shape typed-data JSON and returns the 32-byte keccak256 digest to sign (the 0x1901-prefixed hash).
func EthereumPersonalMessageHash ¶ added in v0.2.2
EthereumPersonalMessageHash returns the 32-byte keccak256 digest that EIP-191 personal_sign signs for the given message. len(message) is rendered as its decimal ASCII representation, per the standard.
func GenerateMnemonic ¶
GenerateMnemonic returns a fresh 12-word BIP-39 mnemonic as a string.
The returned string cannot be securely wiped; for sensitive use derive a wallet with NewHDWallet (which keeps the mnemonic in protected memory) and read it back via Mnemonic or WithMnemonic only when required.
func GenerateMnemonicWithWordCount ¶ added in v0.3.1
GenerateMnemonicWithWordCount returns a fresh BIP-39 mnemonic of the given length in words (12, 15, 18, 21, or 24) as a string. Like GenerateMnemonic, the returned string cannot be securely wiped; prefer NewHDWalletWithWordCount for sensitive use. An unsupported word count returns an error wrapping ErrInvalidWordCount.
func IsValidAddress ¶ added in v0.2.2
IsValidAddress reports whether addr is a syntactically and checksum-valid address for the given network. It is a convenience wrapper over ValidateAddress.
func ParseAddress ¶ added in v0.2.2
ParseAddress decodes addr for symbol, verifies its checksum, and returns the decoded payload — e.g. the 20-byte hash160 for Bitcoin/Cosmos/Tron, the 32-byte public key for Solana/Stellar/SS58, or the 20/32-byte account identifier for EVM/Sui/Aptos. An unknown symbol returns ErrUnsupportedCoin; an invalid address returns an error wrapping ErrInvalidAddress.
func RecoverEthereumAddress ¶ added in v0.2.2
RecoverEthereumAddress recovers the EIP-55 checksummed Ethereum address that produced sig over message under EIP-191 personal_sign. It is a convenience for callers that want the signer's address rather than a boolean match.
func ValidateAddress ¶ added in v0.2.2
ValidateAddress returns nil if addr is a valid address for symbol, or a descriptive error wrapping ErrInvalidAddress (bad checksum, wrong prefix, wrong length, …) or ErrUnsupportedCoin for an unknown symbol.
func Verify ¶ added in v0.2.0
Verify reports whether sig is a valid signature of data by the public key pub on the given curve. For ECDSA curves data is the 32-byte digest that was signed; for ed25519 it is the message.
func VerifyBitcoinMessage ¶ added in v0.3.1
VerifyBitcoinMessage reports whether sigBase64 is a valid Bitcoin signed-message signature of message by the key behind a legacy P2PKH (base58check, "1"-prefix) address. It recovers the public key from the compact signature and checks its legacy address equals address.
func VerifyEthereumMessage ¶ added in v0.2.2
VerifyEthereumMessage reports whether sig (65-byte r||s||v, v in {27,28} or {0,1}) is a valid EIP-191 personal_sign signature of message by the signer identified by addressOrPubKey. addressOrPubKey may be a 0x-hex Ethereum address (20 bytes), or a hex/raw secp256k1 public key (33-byte compressed or 65-byte uncompressed). It ecrecovers the signer and compares.
func VerifyEthereumTypedData ¶ added in v0.2.2
VerifyEthereumTypedData is the EIP-712 counterpart of VerifyEthereumMessage.
func VerifySolanaMessage ¶ added in v0.3.1
VerifySolanaMessage reports whether sigBase58 is a valid Solana off-chain message signature for message under the given base58 account address (which is itself the 32-byte ed25519 public key).
Types ¶
type ABIValue ¶ added in v0.2.2
ABIValue is one ABI argument: Type is the canonical type string (e.g. "uint256", "address", "bytes", "uint256[]", "(address,uint256)") and Value is the Go value:
address, bytesN, bytes, string -> []byte uint*/int* -> *big.Int bool -> bool arrays, tuples -> []ABIValue (elements/fields)
type Coin ¶
type Coin struct {
Name string
Symbol Symbol
Curve Curve
Path string
Encode func(pub []byte) (string, error)
}
Coin describes a supported network: its curve, BIP-32 derivation path, and the function that turns a derived public key into an address string. Adding a network is a single entry in the registry below.
type Curve ¶
type Curve int
Curve identifies the elliptic curve a coin derives keys on. Each curve has a distinct derivation scheme (BIP-32 for secp256k1, SLIP-0010 for the others).
const ( // Secp256k1 covers Bitcoin-style, Ethereum/EVM, Cosmos, XRP and Tron. Secp256k1 Curve = iota // Ed25519 covers Solana, Stellar, Polkadot, NEAR, Algorand, Sui, Aptos, Tezos. Ed25519 // Nist256p1 (NIST P-256) covers NEO. Nist256p1 // Ed25519Blake2bNano is the ed25519 EdDSA variant Nano uses: identical to // ed25519 except the internal 512-bit hash is BLAKE2b-512 instead of SHA-512 // (both for key expansion and the R/challenge hashes). SLIP-0010 ed25519 // derivation is used for the leaf private key. Matches Trust Wallet Core's // TWCurveED25519Blake2bNano. Ed25519Blake2bNano // Curve25519 is the public-key/signing scheme Waves uses: the leaf private // key is derived via SLIP-0010 ed25519, the public key is the X25519 // (Montgomery) point, and signing is ed25519 with the public-key sign bit // folded into S[63] (the "curve25519_sign" construction). Matches Trust // Wallet Core's TWCurveCurve25519. Curve25519 // Ed25519ExtendedCardano is BIP32-Ed25519 (CIP-1852) with 64-byte extended // private keys, as used by Cardano. The master secret comes from the Icarus // (PBKDF2-HMAC-SHA512 over the BIP-39 entropy) scheme. Matches Trust Wallet // Core's TWCurveED25519ExtendedCardano. Ed25519ExtendedCardano // Starkex is the STARK curve (StarkNet/StarkEx), EIP-2645 key derivation with // grinding, RFC-6979 deterministic ECDSA. Matches Trust Wallet Core's // TWCurveStarkex. Starkex // Sr25519 is schnorrkel/ristretto255, the native key scheme for // Polkadot/Kusama. NOTE: this is NOT part of Trust Wallet Core's curve set // (TWC uses plain ed25519 for Polkadot); it is provided here as an additional // curve for native substrate signing. Sr25519 )
type HDWallet ¶
type HDWallet struct {
// contains filtered or unexported fields
}
HDWallet is an HD wallet derived from a BIP-39 mnemonic. Its sensitive material is protected in memory; see the package documentation. All methods are safe for concurrent use.
func FromMnemonic ¶
FromMnemonic builds a wallet from an existing 12/24-word mnemonic string.
Prefer FromMnemonicBytes where possible: a Go string cannot be wiped from memory, so any mnemonic held as a string lingers until garbage-collected.
func FromMnemonicBuffer ¶
func FromMnemonicBuffer(buf *memguard.LockedBuffer) (*HDWallet, error)
FromMnemonicBuffer builds a wallet from a mnemonic held in a memguard LockedBuffer. This is the most secure entry point: the mnemonic stays in page-locked, encrypted-at-rest memory from your code all the way into the wallet's sealed enclave, with no intermediate plaintext copy on the Go heap.
The wallet takes ownership of buf and destroys it; do not use buf afterwards. Surrounding whitespace in the buffer is trimmed before use.
It uses the empty BIP-39 passphrase (Trust Wallet's default). For a passphrase-protected wallet, use FromMnemonicBufferWithPassphrase.
Example ¶
ExampleFromMnemonicBuffer shows the most secure way to import a mnemonic: the phrase lives in a page-locked, encrypted memguard buffer and is handed to the wallet without an intermediate plaintext copy. The wallet takes ownership of the buffer and destroys it.
package main
import (
"fmt"
"log"
"github.com/awnumar/memguard"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
// exampleMnemonic is the standard BIP-39 test vector mnemonic. Never hard-code a
// real mnemonic in source; this one holds no funds and is used only for docs.
const exampleMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
// In real code, read the mnemonic straight into protected memory (for
// example with memguard.NewBufferFromReaderUntil over stdin).
buf := memguard.NewBufferFromBytes([]byte(exampleMnemonic))
w, err := hdwallet.FromMnemonicBuffer(buf)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
addr, _ := w.Address(hdwallet.BTC)
fmt.Println(addr)
}
Output: bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu
func FromMnemonicBufferWithPassphrase ¶ added in v0.3.0
func FromMnemonicBufferWithPassphrase(buf, passphrase *memguard.LockedBuffer) (*HDWallet, error)
FromMnemonicBufferWithPassphrase is the most secure passphrase entry point: both the mnemonic and the BIP-39 passphrase are supplied in page-locked, encrypted-at-rest memguard buffers and used without an intermediate plaintext heap copy (aside from the unavoidable transient BIP-39 string conversion).
The wallet takes ownership of both buffers and destroys them; do not use either afterwards. passphrase may be nil for the empty passphrase. Surrounding whitespace in the mnemonic buffer is trimmed; the passphrase is used verbatim.
func FromMnemonicBytes ¶
FromMnemonicBytes builds a wallet from a mnemonic held in a byte slice. The slice is wiped before the function returns; callers must not reuse it.
It uses the empty BIP-39 passphrase (Trust Wallet's default). For a passphrase-protected ("hidden") wallet, use FromMnemonicWithPassphrase.
func FromMnemonicWithPassphrase ¶ added in v0.3.0
FromMnemonicWithPassphrase builds a wallet from a mnemonic and an optional BIP-39 passphrase (the "25th word"), both held in byte slices. A different passphrase derives a completely different set of addresses from the same mnemonic; the empty passphrase (nil or empty slice) matches FromMnemonicBytes and Trust Wallet's default.
Both slices are wiped before the function returns; callers must not reuse them. Like the mnemonic, the passphrase is briefly converted to a Go string internally for BIP-39 seed derivation (see the package secret-handling notes).
func FromPrivateKeyBuffer ¶ added in v0.2.2
func FromPrivateKeyBuffer(buf *memguard.LockedBuffer, curve Curve) (*HDWallet, error)
FromPrivateKeyBuffer builds a key-only wallet from a raw private key held in a memguard LockedBuffer. This is the most secure key-import entry point: the key stays in page-locked, encrypted-at-rest memory from your code all the way into the wallet's sealed enclave, with no intermediate plaintext copy on the Go heap (mirrors FromMnemonicBuffer).
The wallet takes ownership of buf and destroys it; do not use buf afterwards. See FromPrivateKeyBytes for the semantics of a key-only wallet.
func FromPrivateKeyBytes ¶ added in v0.2.2
FromPrivateKeyBytes builds a key-only wallet from a raw private key held in a byte slice. The slice is wiped before this function returns; callers must not reuse it (mirrors FromMnemonicBytes).
curve identifies the elliptic curve the key belongs to (Secp256k1, Ed25519, or Nist256p1). The resulting wallet can derive addresses, public keys, sign, and export the key for any registered coin whose curve matches; mismatched-curve coins return ErrCurveMismatch. A key-only wallet has no HD path — the imported key is the leaf — so only index 0 is valid and there is no mnemonic to read (Mnemonic/WithMnemonic/AllAddresses return ErrKeyOnlyWallet).
The key must be exactly 32 bytes and non-zero, or ErrInvalidPrivateKey is returned.
func FromWIF ¶ added in v0.3.0
FromWIF builds a key-only secp256k1 wallet from a Bitcoin WIF private key held in a byte slice. The slice is wiped before returning; callers must not reuse it. Both compressed and uncompressed mainnet (0x80) WIF are accepted, and the imported key may then be used with any secp256k1 coin.
Like the mnemonic path, the WIF is briefly converted to a Go string internally for base58 decoding (it cannot be wiped and is GC-bounded).
func NewHDWallet ¶
NewHDWallet creates a wallet with a fresh 12-word (128-bit) mnemonic. It is a convenience wrapper over NewHDWalletWithWordCount(12).
Example ¶
ExampleNewHDWallet creates a wallet with a fresh, random mnemonic and derives an address. Output is omitted because the mnemonic (and therefore the address) is random on every run.
package main
import (
"fmt"
"log"
"strings"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
func main() {
w, err := hdwallet.NewHDWallet()
if err != nil {
log.Fatal(err)
}
defer w.Destroy() // wipe the wallet's secrets when finished
addr, err := w.Address(hdwallet.ETH)
if err != nil {
log.Fatal(err)
}
fmt.Println(strings.HasPrefix(addr, "0x"))
}
Output: true
func NewHDWalletWithEntropy ¶ added in v0.3.1
NewHDWalletWithEntropy creates a wallet with a fresh mnemonic generated from bits of BIP-39 entropy. bits must be one of 128, 160, 192, 224, or 256 (yielding 12, 15, 18, 21, or 24 words); any other value returns an error wrapping ErrInvalidWordCount.
func NewHDWalletWithWordCount ¶ added in v0.3.1
NewHDWalletWithWordCount creates a wallet with a fresh mnemonic of the given length in words. words must be one of 12, 15, 18, 21, or 24; any other value returns an error wrapping ErrInvalidWordCount.
func (*HDWallet) AccountXPub ¶ added in v0.3.0
AccountXPub returns the BIP-32 extended PUBLIC key (xpub) for symbol's account at the given index — i.e. the neutered key at m/purpose'/coin'/account'. It is public and safe to share; feed it to WatchOnlyFromXPub to derive addresses without the seed. symbol must be a secp256k1 coin.
func (*HDWallet) Address ¶
Address returns the first receive address (index 0) for a coin symbol, e.g. "BTC", "ETH", "SOL", "ATOM". Use SupportedCoins to list every symbol.
It is exactly equivalent to AddressIndex(symbol, 0).
Example ¶
ExampleHDWallet_Address derives the first receive address for several chains from a fixed mnemonic, producing deterministic, Trust Wallet-compatible addresses.
package main
import (
"fmt"
"log"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
// exampleMnemonic is the standard BIP-39 test vector mnemonic. Never hard-code a
// real mnemonic in source; this one holds no funds and is used only for docs.
const exampleMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
w, err := hdwallet.FromMnemonic(exampleMnemonic)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
btc, _ := w.Address(hdwallet.BTC)
eth, _ := w.Address(hdwallet.ETH)
fmt.Println(btc)
fmt.Println(eth)
}
Output: bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu 0x9858EfFD232B4033E47d90003D41EC34EcaEda94
func (*HDWallet) AddressAt ¶ added in v0.3.0
AddressAt returns the address for symbol at the given BIP-44 account, change branch, and address index, building the path "m/purpose'/coin'/account'/change/ index" from the coin's template. It requires a standard 5-element path; coins whose template has a different shape (e.g. SOL's "m/44'/501'/0'") return ErrPathArity — use AddressPath for those.
func (*HDWallet) AddressIndex ¶
AddressIndex returns the address for a coin symbol derived with the final element of the coin's BIP-32 path replaced by index, preserving that element's hardened flag (a trailing "'").
For BIP-44/BIP-84 chains whose path ends in "/0/0" (change/address_index), this varies the non-hardened receive address index — e.g. for BTC (m/84'/0'/0'/0/0), index 1 derives m/84'/0'/0'/0/1. For account-based chains whose path ends in a hardened element such as "/0'" (e.g. SOL, m/44'/501'/0'), this varies that final hardened element — index 1 derives m/44'/501'/1'.
index must be below 2^31 (0x80000000); a larger value returns an error, as does an unknown symbol (wrapping ErrUnsupportedCoin) or a destroyed wallet.
Example ¶
ExampleHDWallet_AddressIndex derives multiple receive addresses for the same chain by varying the final path index.
package main
import (
"fmt"
"log"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
// exampleMnemonic is the standard BIP-39 test vector mnemonic. Never hard-code a
// real mnemonic in source; this one holds no funds and is used only for docs.
const exampleMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
w, err := hdwallet.FromMnemonic(exampleMnemonic)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
first, _ := w.AddressIndex(hdwallet.BTC, 0)
second, _ := w.AddressIndex(hdwallet.BTC, 1)
fmt.Println(first)
fmt.Println(second)
}
Output: bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu bc1qnjg0jd8228aq7egyzacy8cys3knf9xvrerkf9g
func (*HDWallet) AddressPath ¶ added in v0.3.0
AddressPath returns the address for symbol derived at the given absolute BIP-32 path (e.g. "m/44'/60'/1'/0/5"). The path's curve scheme is the coin's; only the child indices are taken from path. An invalid path or unknown symbol returns an error; a key-only wallet returns ErrKeyOnlyWallet.
func (*HDWallet) AllAddresses ¶
AllAddresses derives the first address (index 0) for every supported coin. It is exactly equivalent to AllAddressesAt(0).
func (*HDWallet) AllAddressesAt ¶ added in v0.3.1
AllAddressesAt derives the address at the given index for every supported coin, varying the final element of each coin's BIP-32 path (preserving its hardened flag) exactly as AddressIndex does. The seed enclave is opened exactly once and every coin is derived inside that single decryption window.
index must be below 2^31 (0x80000000); a larger value returns an error. It is only available on seed-based wallets; a key-only wallet (imported from a single private key) has no seed to enumerate over and returns ErrKeyOnlyWallet.
func (*HDWallet) Destroy ¶
func (w *HDWallet) Destroy()
Destroy wipes the wallet's secret material from memory. The wallet is unusable afterwards. It is safe to call multiple times.
func (*HDWallet) Mnemonic ¶
func (w *HDWallet) Mnemonic() (*memguard.LockedBuffer, error)
Mnemonic returns the wallet's mnemonic in a page-locked buffer. This is a lower-level accessor: the caller MUST call Destroy on the returned buffer when finished with it, or the decrypted phrase lingers in memory. Prefer WithMnemonic, which wipes the decrypted copy automatically when its callback returns.
func (*HDWallet) PrivateKey ¶ added in v0.2.2
PrivateKey returns the raw leaf private key for symbol at the given address index in a page-locked, encrypted-at-rest memguard buffer. This is a lower-level accessor: the caller MUST call Destroy on the returned buffer when finished, or the decrypted key lingers in memory. Prefer WithPrivateKey, which wipes the key automatically when its callback returns (mirrors Mnemonic).
The returned buffer holds a copy taken inside the wallet's protected derivation window; the wallet's own working copy is wiped before this returns. See WithPrivateKey for the seed/key-only semantics and the key encoding.
func (*HDWallet) PrivateKeyPath ¶ added in v0.3.0
PrivateKeyPath returns the raw leaf private key for symbol derived at the given absolute BIP-32 path in a page-locked memguard buffer; the caller MUST Destroy it (mirrors PrivateKey). Prefer WithPrivateKeyPath, which wipes automatically.
func (*HDWallet) PublicKey ¶ added in v0.2.0
PublicKey returns the public key for symbol at address index 0. See PublicKeyIndex.
func (*HDWallet) PublicKeyAt ¶ added in v0.3.0
PublicKeyAt is the account/change/index counterpart of PublicKeyPath.
func (*HDWallet) PublicKeyIndex ¶ added in v0.2.0
PublicKeyIndex returns the public key derived for symbol at the given address index: the 33-byte compressed key for secp256k1/nist256p1, or the 32-byte key for ed25519. Signing callers need this to build or verify transactions.
func (*HDWallet) PublicKeyPath ¶ added in v0.3.0
PublicKeyPath returns the public key for symbol derived at the given absolute BIP-32 path: the 33-byte compressed key for secp256k1/nist256p1, or the 32-byte key for ed25519-family curves.
func (*HDWallet) Sign ¶ added in v0.2.0
Sign signs data with the key for symbol at address index 0. See SignIndex.
Example ¶
ExampleHDWallet_Sign signs a digest and verifies it with the derived public key. For ECDSA chains (BTC/ETH/…) pass the 32-byte digest your chain hashes; for ed25519 chains pass the message itself.
package main
import (
"crypto/sha256"
"fmt"
"log"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
// exampleMnemonic is the standard BIP-39 test vector mnemonic. Never hard-code a
// real mnemonic in source; this one holds no funds and is used only for docs.
const exampleMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
w, err := hdwallet.FromMnemonic(exampleMnemonic)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
digest := sha256.Sum256([]byte("transaction bytes to sign"))
sig, err := w.Sign(hdwallet.BTC, digest[:])
if err != nil {
log.Fatal(err)
}
pub, _ := w.PublicKey(hdwallet.BTC)
fmt.Println(hdwallet.Verify(hdwallet.Secp256k1, pub, digest[:], sig))
}
Output: true
func (*HDWallet) SignAt ¶ added in v0.3.0
func (w *HDWallet) SignAt(symbol Symbol, account, change, index uint32, data []byte) (*Signature, error)
SignAt is the account/change/index counterpart of SignPath.
func (*HDWallet) SignBitcoinMessage ¶ added in v0.3.1
SignBitcoinMessage signs message under the Bitcoin signed-message standard with the key derived for symbol at the given address index, returning the base64 compact signature. symbol must be a secp256k1 coin (e.g. BTC, LTC); the derived private key is wiped immediately after signing and never leaves the package.
The signature commits only to the message and key, so it is independent of the address format; this library derives compressed keys, so the header byte marks the key compressed (verifiers recover the compressed key / its legacy address).
func (*HDWallet) SignIndex ¶ added in v0.2.0
SignIndex signs data with the private key derived for symbol at the given address index and returns the signature.
For ECDSA chains (secp256k1, nist256p1 — e.g. BTC, ETH, ATOM, NEO) data must be the 32-byte digest the chain signs; pre-hash the message with the chain's hash function (keccak256 for Ethereum/Tron, double-SHA256 for Bitcoin, SHA-256 for Cosmos, …). For ed25519 chains (e.g. SOL, XLM, DOT) data is the message itself; the EdDSA scheme hashes internally.
The derived private key is wiped immediately after signing and never leaves the package.
func (*HDWallet) SignMessage ¶ added in v0.2.2
SignMessage signs message with EIP-191 personal_sign using the key for symbol at the given address index, returning a 65-byte r||s||v signature (v = 27/28). symbol must be a secp256k1/EVM coin (e.g. ETH); other curves return an error.
func (*HDWallet) SignPath ¶ added in v0.3.0
SignPath signs data with the key for symbol derived at the given absolute BIP-32 path. The ECDSA-vs-ed25519 input rule is identical to SignIndex (ECDSA curves want the 32-byte digest; ed25519 wants the message).
func (*HDWallet) SignSolanaMessage ¶ added in v0.3.1
SignSolanaMessage signs message with the ed25519 key derived for symbol at the given address index and returns the base58-encoded 64-byte signature.
symbol must be a Solana / ed25519 coin (e.g. SOL). The derived private key is wiped immediately after signing and never leaves the package.
func (*HDWallet) SignTransaction ¶ added in v0.2.2
func (w *HDWallet) SignTransaction(symbol Symbol, index uint32, input proto.Message) (proto.Message, error)
SignTransaction signs a transaction for symbol using the key derived at the given address index and returns a per-chain protobuf SigningOutput.
input must be the SigningInput proto for symbol's family (e.g. *ethereum.SigningInput for ETH/EVM, *tron.SigningInput for TRX, …). The returned proto.Message is the matching SigningOutput, holding the signed serialized raw-transaction bytes plus a hex/base58/base64 convenience form. No network calls are made.
The derived private key is wiped immediately after signing and never leaves the package. An unknown symbol returns ErrTxUnsupported; a wrong input type returns ErrTxInput.
func (*HDWallet) SignTypedData ¶ added in v0.2.2
SignTypedData signs the EIP-712 digest of MetaMask-shape typed-data JSON using the key for symbol at the given address index, returning a 65-byte r||s||v signature (v = 27/28).
func (*HDWallet) WIF ¶ added in v0.3.0
WIF returns the leaf key for symbol at the given address index as a Bitcoin mainnet compressed WIF in a page-locked memguard buffer; the caller MUST Destroy it. Prefer WithWIF, which wipes automatically.
func (*HDWallet) WithAccountXPrv ¶ added in v0.3.0
WithAccountXPrv runs fn with the BIP-32 extended PRIVATE key (xprv) string for symbol's account, then wipes the byte slice (mirrors WithPrivateKey/WithWIF). The xprv is a full secret — anyone holding it can derive every key under the account. The slice passed to fn must not escape fn. symbol must be secp256k1.
func (*HDWallet) WithMnemonic ¶
WithMnemonic runs fn with the plaintext mnemonic bytes and wipes the decrypted copy as soon as fn returns. The slice passed to fn must not escape fn.
Example ¶
ExampleHDWallet_WithMnemonic shows the safe pattern for reading the mnemonic back: the decrypted copy is wiped automatically when the callback returns, and the slice must not escape it.
package main
import (
"fmt"
"log"
"strings"
hdwallet "github.com/ranjbar-dev/hd-wallet"
)
// exampleMnemonic is the standard BIP-39 test vector mnemonic. Never hard-code a
// real mnemonic in source; this one holds no funds and is used only for docs.
const exampleMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
w, err := hdwallet.FromMnemonic(exampleMnemonic)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
err = w.WithMnemonic(func(mnemonic []byte) error {
fmt.Println(len(strings.Fields(string(mnemonic))), "words")
return nil
})
if err != nil {
log.Fatal(err)
}
}
Output: 12 words
func (*HDWallet) WithPrivateKey ¶ added in v0.2.2
WithPrivateKey runs fn with the raw leaf private key for symbol at the given address index and wipes the key as soon as fn returns. This is the safe export primitive — the key never escapes into a value the caller must remember to clear (mirrors WithMnemonic). The slice passed to fn must not escape fn.
It works for both wallet modes: seed wallets derive the key for symbol/index; key-only wallets return their imported key (curve must match symbol's curve, and index must be 0). The key is the 32-byte scalar/seed for the coin's curve.
For ECDSA chains this is the signing scalar; for ed25519 it is the 32-byte seed (not the 64-byte expanded key).
func (*HDWallet) WithPrivateKeyPath ¶ added in v0.3.0
WithPrivateKeyPath runs fn with the raw leaf private key for symbol derived at the given absolute BIP-32 path and wipes the key as soon as fn returns (mirrors WithPrivateKey). The slice passed to fn must not escape fn.
type RLPItem ¶ added in v0.2.2
RLPItem is a node in an RLP tree: exactly one of Str (a byte string, a leaf) or List (an ordered list of items) is meaningful. IsList selects which. The zero value is the empty string item (encodes to 0x80).
func DecodeRLP ¶ added in v0.2.2
DecodeRLP decodes a single, complete RLP item. It is strict: the entire input must be exactly one canonical item with no trailing bytes.
type Signature ¶ added in v0.2.0
type Signature struct {
Curve Curve
R, S []byte // ECDSA signature scalars (nil for ed25519)
RecoveryID byte // secp256k1 public-key recovery id (0 or 1)
// contains filtered or unexported fields
}
Signature is the result of signing with a derived key.
For ECDSA curves (secp256k1, nist256p1), R and S are the signature scalars and the value is available as a 64-byte R||S string, an ASN.1 DER encoding, and — for secp256k1 — a 65-byte recoverable form. For ed25519, R and S are nil and the 64-byte signature is available via Bytes.
func (*Signature) Bytes ¶ added in v0.2.0
Bytes returns the 64-byte signature: R||S for ECDSA curves, or the raw 64-byte signature for ed25519. Cosmos and Solana use this form.
func (*Signature) DER ¶ added in v0.2.0
DER returns the ASN.1 DER encoding (SEQUENCE of two INTEGERs) used by Bitcoin-family chains. It is valid for ECDSA curves; for ed25519 it returns nil.
func (*Signature) Recoverable ¶ added in v0.2.0
Recoverable returns the 65-byte [R||S||V] signature, where V is the recovery id (0 or 1), used by Ethereum/EVM chains and Tron. Callers add the chain's V offset (e.g. 27, or 35+2*chainID for EIP-155) as needed. It is only valid for secp256k1; for other curves it returns nil.
type Symbol ¶
type Symbol string
Symbol is a typed network identifier used to look up a registry entry. Use the exported constants below (hdwallet.BTC, hdwallet.ETH, …) when calling methods such as (*HDWallet).Address and AddressIndex; the typed enum gives compile-time checking and editor autocomplete instead of bare strings.
const ( // secp256k1 — Bitcoin-style UTXO chains. BTC Symbol = "BTC" LTC Symbol = "LTC" DOGE Symbol = "DOGE" BCH Symbol = "BCH" DASH Symbol = "DASH" ZEC Symbol = "ZEC" // secp256k1 — additional UTXO chains. GRS Symbol = "GRS" // Groestlcoin (segwit) DGB Symbol = "DGB" // DigiByte (segwit) BTG Symbol = "BTG" // Bitcoin Gold (segwit) SYS Symbol = "SYS" // Syscoin (segwit) VIA Symbol = "VIA" // Viacoin (segwit) QTUM Symbol = "QTUM" // Qtum (base58check P2PKH) RVN Symbol = "RVN" // Ravencoin (base58check P2PKH) KMD Symbol = "KMD" // Komodo (base58check P2PKH) FIRO Symbol = "FIRO" // Firo (base58check P2PKH) MONA Symbol = "MONA" // MonaCoin (base58check P2PKH) XVG Symbol = "XVG" // Verge (base58check P2PKH) PIVX Symbol = "PIVX" // PIVX (base58check P2PKH) NEBL Symbol = "NEBL" // Neblio (base58check P2PKH) STRAX Symbol = "STRAX" // Stratis (segwit) ZEN Symbol = "ZEN" // Horizen (base58check 2-byte) BCD Symbol = "BCD" // Bitcoin Diamond (base58check P2PKH) XEC Symbol = "XEC" // eCash (CashAddr) FLUX Symbol = "FLUX" // Flux/Zelcash (base58check 2-byte) // secp256k1 — account-based / keccak. ETH Symbol = "ETH" TRX Symbol = "TRX" XRP Symbol = "XRP" // secp256k1 — EOS-family public-key strings. EOS Symbol = "EOS" WAX Symbol = "WAX" FIO Symbol = "FIO" // secp256k1 — Filecoin (f1 base32 address). FIL Symbol = "FIL" // secp256k1 — EVM chains (same key & address format as Ethereum). BNB Symbol = "BNB" MATIC Symbol = "MATIC" AVAX Symbol = "AVAX" ARB Symbol = "ARB" OP Symbol = "OP" FTM Symbol = "FTM" BASE Symbol = "BASE" CRO Symbol = "CRO" GNO Symbol = "GNO" CELO Symbol = "CELO" // secp256k1 — additional EVM chains (Ethereum address format, EIP-55). ETC Symbol = "ETC" RONIN Symbol = "RONIN" ZKSYNC Symbol = "ZKSYNC" LINEA Symbol = "LINEA" SCROLL Symbol = "SCROLL" MANTLE Symbol = "MANTLE" BLAST Symbol = "BLAST" KAIA Symbol = "KAIA" AURORA Symbol = "AURORA" GLMR Symbol = "GLMR" MOVR Symbol = "MOVR" BOBA Symbol = "BOBA" METIS Symbol = "METIS" OPBNB Symbol = "OPBNB" POLZKEVM Symbol = "POLZKEVM" MANTA Symbol = "MANTA" RBTC Symbol = "RBTC" HECO Symbol = "HECO" OKT Symbol = "OKT" KCS Symbol = "KCS" WAN Symbol = "WAN" POA Symbol = "POA" CLO Symbol = "CLO" GO Symbol = "GO" TT Symbol = "TT" VET Symbol = "VET" IOTX Symbol = "IOTX" THETA Symbol = "THETA" NEON Symbol = "NEON" MERLIN Symbol = "MERLIN" LIGHT Symbol = "LIGHT" SONIC Symbol = "SONIC" ZENEON Symbol = "ZENEON" ZETAEVM Symbol = "ZETAEVM" // secp256k1 — Cosmos SDK chains. ATOM Symbol = "ATOM" OSMO Symbol = "OSMO" JUNO Symbol = "JUNO" TIA Symbol = "TIA" // secp256k1 — additional Cosmos SDK chains (hash160 bech32, per-chain HRP). LUNA Symbol = "LUNA" KAVA Symbol = "KAVA" SCRT Symbol = "SCRT" BAND Symbol = "BAND" RUNE Symbol = "RUNE" STARS Symbol = "STARS" AXL Symbol = "AXL" STRD Symbol = "STRD" BLD Symbol = "BLD" CRE Symbol = "CRE" KUJI Symbol = "KUJI" CMDX Symbol = "CMDX" NTRN Symbol = "NTRN" SOMM Symbol = "SOMM" FET Symbol = "FET" MARS Symbol = "MARS" UMEE Symbol = "UMEE" COREUM Symbol = "COREUM" QSR Symbol = "QSR" XPRT Symbol = "XPRT" AKT Symbol = "AKT" NOBLE Symbol = "NOBLE" SEI Symbol = "SEI" DYDX Symbol = "DYDX" BLZ Symbol = "BLZ" CRYPTOORG Symbol = "CRYPTOORG" // secp256k1 — Cosmos chains with EVM-style keys (keccak address, bech32). EVMOS Symbol = "EVMOS" INJ Symbol = "INJ" CANTO Symbol = "CANTO" ZETA Symbol = "ZETA" ONE Symbol = "ONE" // ed25519 (SLIP-0010). SOL Symbol = "SOL" XLM Symbol = "XLM" DOT Symbol = "DOT" KSM Symbol = "KSM" NEAR Symbol = "NEAR" ALGO Symbol = "ALGO" SUI Symbol = "SUI" APTOS Symbol = "APTOS" XTZ Symbol = "XTZ" // ed25519 (SLIP-0010) — additional chains. EGLD Symbol = "EGLD" // MultiversX (bech32 of pubkey) IOST Symbol = "IOST" // IOST (base58 of pubkey) HBAR Symbol = "HBAR" // Hedera (0.0.<DER-encoded pubkey hex>) ROSE Symbol = "ROSE" // Oasis (bech32 of context-hashed pubkey) KIN Symbol = "KIN" // Kin (Stellar strkey) AE Symbol = "AE" // Aeternity (ak_ base58check) // nist256p1 (SLIP-0010). NEO Symbol = "NEO" ONT Symbol = "ONT" // Ontology (same NEO-style address) // new-curve chains (SLIP-0010 ed25519 leaf key, chain-specific signing). XNO Symbol = "XNO" // Nano (ed25519-blake2b) WAVES Symbol = "WAVES" // Waves (curve25519) )
Supported network symbols. These mirror the registry below and match Trust Wallet's tickers.
func SupportedCoins ¶
func SupportedCoins() []Symbol
SupportedCoins lists the registered coin symbols in sorted order.
type WatchWallet ¶ added in v0.3.0
type WatchWallet struct {
// contains filtered or unexported fields
}
WatchWallet derives receive/change addresses for a single account from its extended PUBLIC key (xpub) — no seed, no private keys, no signing. It is the watch-only counterpart of HDWallet for secp256k1 coins.
func WatchOnlyFromXPub ¶ added in v0.3.0
func WatchOnlyFromXPub(xpub string, symbol Symbol) (*WatchWallet, error)
WatchOnlyFromXPub builds a watch-only wallet for symbol from an account-level extended key string. Both xpub and xprv strings are accepted; an xprv is immediately neutered so the WatchWallet never holds private material. symbol must be a secp256k1 coin whose address format matches the xpub's chain.
func (*WatchWallet) Address ¶ added in v0.3.0
func (ww *WatchWallet) Address(change, index uint32) (string, error)
Address returns the address at the account's change/index branch (e.g. change=0, index=5 -> .../0/5). Both must be non-hardened (< 2^31); public derivation cannot produce hardened children.
Source Files
¶
- address_validate.go
- cardano.go
- codec.go
- crypto.go
- curve25519.go
- curve_helpers.go
- derive.go
- ed25519_blake2b.go
- encoders_ed25519.go
- encoders_nist256p1.go
- encoders_secp256k1.go
- eth_abi.go
- eth_eip191.go
- eth_eip712.go
- eth_message.go
- eth_rlp.go
- extkey.go
- hdwallet.go
- message_bitcoin.go
- message_solana.go
- path.go
- privatekey.go
- registry.go
- secret.go
- sign.go
- slip10.go
- sr25519.go
- starkex.go
- tx.go
- tx_cosmos.go
- tx_ethereum.go
- tx_families.go
- tx_ripple.go
- tx_roadmap.go
- tx_solana.go
- tx_tron.go
- wif.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hdwallet
command
Command hdwallet is a small demo CLI for the hd-wallet library: it generates a fresh BIP-39 mnemonic (or imports one) and prints the receive address for every supported network.
|
Command hdwallet is a small demo CLI for the hd-wallet library: it generates a fresh BIP-39 mnemonic (or imports one) and prints the receive address for every supported network. |
|
txproto
|
|