bip39

package
v0.0.0-...-3c905e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2023 License: BSD-3-Clause, MIT Imports: 9 Imported by: 0

README

go-bip39

A golang implementation of the BIP0039 spec for mnemonic seeds

Credits

English wordlist and test vectors are from the standard Python BIP0039 implementation from the Trezor guys: https://github.com/trezor/python-mnemonic

Example

package main

import (
  "github.com/tyler-smith/go-bip39"
  "github.com/tyler-smith/go-bip32"
  "fmt"
)

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)
}

Documentation

Overview

Package bip39 A golang implementation of the BIP0039 spec for mnemonic seeds

Index

Constants

This section is empty.

Variables

View Source
var (
	Last11BitsMask          = big.NewInt(2047)
	RightShift11BitsDivider = big.NewInt(2048)
	BigOne                  = big.NewInt(1)
	BigTwo                  = big.NewInt(2)
)

Some bitwise operands for working with big.Ints

View Source
var ChineseWordList = strings.Split(chineseWordList, "\n")

ChineseWordList 中文单词列表

View Source
var EnglishWordList = strings.Split(englishWordList, "\n")

EnglishWordList 英文单词列表

Functions

func IsMnemonicValid

func IsMnemonicValid(mnemonic string) bool

IsMnemonicValid 检测有效性

func MnemonicToByteArray

func MnemonicToByteArray(mnemonic string) ([]byte, error)

MnemonicToByteArray 转换

func NewEntropy

func NewEntropy(bitSize int) ([]byte, error)

NewEntropy 新建

func NewMnemonic

func NewMnemonic(entropy []byte, lang int32) (string, error)

NewMnemonic lang=0 english word lang=1 chinese word

func NewSeed

func NewSeed(mnemonic string, password string) []byte

NewSeed 新建Seed

func NewSeedWithErrorChecking

func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error)

NewSeedWithErrorChecking 带有错误检查的创建Seed

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL