Documentation
¶
Overview ¶
Package mnemonic provides BIP39 mnemonic phrase generation and validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidMnemonic = errors.New("invalid mnemonic given")
ErrInvalidMnemonic is returned when a mnemonic phrase is not valid BIP39.
Functions ¶
func DeriveKey ¶ added in v0.27.0
DeriveKey derives a key pair from a BIP39 mnemonic and passphrase at the given TRON HD path index (44'/195'/0'/0/{index}).
Unlike FromSeedAndPassphrase it validates the mnemonic (an invalid one returns an error matching ErrInvalidMnemonic) and the index, which must be in [0, 2^31), and it returns an error instead of nil keys. For a valid mnemonic and index both functions derive the same key.
func FromSeedAndPassphrase ¶ added in v0.26.0
func FromSeedAndPassphrase(mnemonic, passphrase string, index int) (*btcec.PrivateKey, *btcec.PublicKey)
FromSeedAndPassphrase derives a key pair from a BIP39 mnemonic and passphrase at the given TRON HD path index (44'/195'/0'/0/{index}).
It does NOT check the mnemonic's checksum or word list: any string is turned into a seed, so wallets created from an unchecked mnemonic stay recoverable. It returns nil, nil when index is outside [0, 2^31) or derivation fails. New code should call Validate first, or use DeriveKey, which validates and returns the reason for a failure.
func Generate ¶
Generate returns a new random BIP39 mnemonic phrase. An optional entropy size in bits can be provided (128, 160, 192, 224, 256). Default: 256 (24 words).
func Validate ¶ added in v0.27.0
Validate checks that m is a valid BIP39 mnemonic: 12, 15, 18, 21 or 24 words from the English word list, with a matching checksum, separated by single spaces with no leading or trailing whitespace. It returns an error matching ErrInvalidMnemonic (via errors.Is) when it is not.
The spacing rule matters because the seed is derived from the string as given: the same words with other spacing would derive a different wallet than other BIP39 wallets do.
Types ¶
This section is empty.