A golang implementation of the BIP39 spec for mnemonic seeds.
This is a modernized fork of the original go-bip39 library by tyler-smith, which has been removed from GitHub.
- Fixed typos in error messages
- Updated dependencies
go get github.com/X-Vlad/go-bip39Add this to your go.mod:
replace github.com/tyler-smith/go-bip39 => github.com/X-Vlad/go-bip39 v1.0.0
package main
import (
"fmt"
"github.com/X-Vlad/go-bip39"
"github.com/X-Vlad/go-bip32"
)
func main() {
// Generate a mnemonic for memorization or user-friendly seeds
entropy, _ := bip39.NewEntropy(256)
mnemonic, _ := bip39.NewMnemonic(entropy)
// Generate a Bip32 HD wallet for the mnemonic and a user supplied password
seed := bip39.NewSeed(mnemonic, "Secret Passphrase")
masterKey, _ := bip32.NewMasterKey(seed)
publicKey := masterKey.PublicKey()
// Display mnemonic and keys
fmt.Println("Mnemonic: ", mnemonic)
fmt.Println("Master private key: ", masterKey)
fmt.Println("Master public key: ", publicKey)
}NewEntropy(bitSize int) ([]byte, error)- Generate random entropy (bitSize must be 128-256, multiple of 32)NewMnemonic(entropy []byte) (string, error)- Generate mnemonic words from entropyNewSeed(mnemonic string, password string) []byte- Generate seed from mnemonic and passwordNewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error)- Same as NewSeed but validates mnemonic firstIsMnemonicValid(mnemonic string) bool- Check if mnemonic is validEntropyFromMnemonic(mnemonic string) ([]byte, error)- Extract entropy from mnemonicMnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error)- Convert mnemonic to byte array
SetWordList(list []string)- Set custom word listGetWordList() []string- Get current word listGetWordIndex(word string) (int, bool)- Get word index in current word list
The library includes word lists for multiple languages in the wordlists package:
- English (default)
- Japanese
- Korean
- Spanish
- Chinese (Simplified & Traditional)
- French
- Italian
- Czech
go test -v ./...MIT License - see LICENSE for details.
Based on the original go-bip39 by tyler-smith.
Wordlists are from the BIP39 spec.
Test vectors are from the Trezor python-mnemonic implementation.
Contributions are welcome! Please feel free to submit a Pull Request.
If this project was helpful, you can support development:
| Network | Address |
|---|---|
| BTC | bc1q3l4jcnplvcmvqh26pfh3qdkrw4flqevemsfed8 |
| ETH, BSC, ... (EVM) | 0x49999CD2B8F7Bc9309e5929a79799eA55a17e6Ce |
| Tron | TDxyjiittx9zzkHd25wmM12mvutTKBhZKS |
| Solana | ahiiQWz9eRLpFRpEFSPf7See7J46YBFhMgsADNmGRgt |
| TON | UQCfsCHBWq3_kD0D_mkfetuwIgACoSJ8YsYTZPKKkMprDlLD |