bip39

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const IdeographicSpace = "\u3000"

IdeographicSpace is used to join Japanese mnemonic phrases.

Variables

View Source
var ChineseSimplifiedWordList = []string{}/* 2048 elements not displayed */
View Source
var ChineseTraditionalWordList = []string{}/* 2048 elements not displayed */
View Source
var CzechWordList = []string{}/* 2048 elements not displayed */
View Source
var EnglishWordList = []string{}/* 2048 elements not displayed */
View Source
var ErrBadEntropy = errors.New("entropy must be 128-256 bits, divisible by 32")
View Source
var ErrOutOfEntropy, _ = wrapped.New("not enough entropy available in the OS entropy pool")
View Source
var ErrWrongChecksum = errors.New("wrong mnemonic phrase: checksum doesn't match")
View Source
var ErrWrongLength = errors.New("wrong mnemonic length: must be 12, 15, 18, 21 or 24 words")
View Source
var ErrWrongWord = errors.New("wrong word in mnemonic phrase: not on the wordlist")
View Source
var FrenchWordList = []string{}/* 2048 elements not displayed */
View Source
var ItalianWordList = []string{}/* 2048 elements not displayed */
View Source
var JapaneseWordList = []string{}/* 2048 elements not displayed */
View Source
var KoreanWordList = []string{}/* 2048 elements not displayed */
View Source
var LangSpace = map[string]string{
	"english":             " ",
	"chinese_simplified":  " ",
	"chinese_traditional": " ",
	"czech":               " ",
	"french":              " ",
	"italian":             " ",
	"japanese":            IdeographicSpace,
	"korean":              " ",
	"portuguese":          " ",
	"spanish":             " ",
}

LangSpace is the joining whitespace for each language.

View Source
var PortugueseWordList = []string{}/* 2048 elements not displayed */
View Source
var SpanishWordList = []string{}/* 2048 elements not displayed */
View Source
var WordLists = map[string][]string{
	"english":             EnglishWordList,
	"chinese_simplified":  ChineseSimplifiedWordList,
	"chinese_traditional": ChineseTraditionalWordList,
	"czech":               CzechWordList,
	"french":              FrenchWordList,
	"italian":             ItalianWordList,
	"japanese":            JapaneseWordList,
	"korean":              KoreanWordList,
	"portuguese":          PortugueseWordList,
	"spanish":             SpanishWordList,
}

Word Lists for each language. Language names are from BIP39 test vectors.

Functions

func GenerateRandomMnemonic added in v0.0.3

func GenerateRandomMnemonic(entropy int, wordlist []string) (mnemonic []string, err error)

GenerateRandomMnemonic generates a 12-24 word mnemonic phrase with 128-256 bits of entropy.

Implements BIP-39 as described in https://en.bitcoin.it/wiki/BIP_0039

The number of entropy bits must be between 128 and 256 inclusive, and divisible by 32 as per BIP-39.

Returns the generated mnemonic phrase.

Can return the following errors: ErrBadEntropy (entropy length is incorrect; expects 128,160,192,224,256) ErrOutOfEntropy (the OS entropy source is exhausted)

func MnemonicFromEntropy

func MnemonicFromEntropy(entropy []byte, wordlist []string) (mnemonic []string, err error)

MnemonicFromEntropy converts 128-256 bits of entropy to a 12-24 word mnemonic phrase.

Implements BIP-39 as described in https://en.bitcoin.it/wiki/BIP_0039

The number of entropy bits must be between 128 and 256 inclusive, and divisible by 32 as per BIP-39.

Returns the encoded mnemonic phrase.

Can return the following errors: ErrBadEntropy (entropy length is incorrect; expects 16,20,24,28,32 bytes)

func SeedFromMnemonic

func SeedFromMnemonic(mnemonic []string, passphrase string, wordlist []string) (seed []byte, err error)

SeedFromMnemonicPhrase derives a cryptographically random seed from a mnemonic phrase.

Implements BIP-39 as described in https://en.bitcoin.it/wiki/BIP_0039

This function verifies the 12-24 words are on the wordlist, and verifies the checksum bits included in the mnemonic phrase.

The passphrase is an optional string used to protect the seed derived from the mnemonic phrase (via PBKDF2)

Can return the following errors: ErrWrongLength (wrong number of words; expects 12,15,18,21,24) ErrWrongWord (one or more words are not on the word-list) ErrWrongChecksum (one or more of the words is incorrect, leading to a checksum mismatch)

Types

This section is empty.

Jump to

Keyboard shortcuts

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