Documentation ¶
Index ¶
- Variables
- func IsMnemonicValid(mnemonic string) bool
- func NewSeed(mnemonic string, opts ...NewSeedOption) []byte
- func NormalizeMnemonic(mnemonic string) string
- func SplitMnemonic(mnemonic string) (words []string, delimiter string)
- func WithEntropyBits(entropyBits int) func(*GenerateMnemonicOptions)
- func WithLanguage(language Language) func(*NewMnemonicOptions)
- func WithLanguages(languages []Language) func(*DetectLanguageOptions)
- func WithPassphrase(passphrase string) func(*NewSeedOptions)
- type DetectLanguageOption
- type DetectLanguageOptions
- type GenerateMnemonicOption
- type GenerateMnemonicOptions
- type Language
- type Mnemonic
- type NewMnemonicOption
- type NewMnemonicOptions
- type NewSeedOption
- type NewSeedOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidEntropy = errors.New("invalid entropy") ErrInvalidMnemonic = errors.New("invalid mnemonic") ErrInvalidNumberWords = errors.New("invalid number of words") ErrInvalidNumberEntropy = errors.New("invalid number of entropy") ErrChecksumIncorrect = errors.New("checksum incorrect") )
Functions ¶
func IsMnemonicValid ¶
IsMnemonicValid attempts to verify that the provided mnemonic is valid. Validity is determined by both the number of words being appropriate, and that all the words in the mnemonic are present in the word list.
func NewSeed ¶
func NewSeed(mnemonic string, opts ...NewSeedOption) []byte
NewSeed creates a hashed seed output given a provided string and password. No checking is performed to validate that the string provided is a valid mnemonic. default passphrase is empty string. if you want to set passphrase, use WithPassphrase() option.
func NormalizeMnemonic ¶
NormalizeMnemonic normalizes the mnemonic.
Example:
mnemonic := "おさえる けむり けしごむ うせつ もちろん とさか いはつ ざっか たりる こさめ いわい にいがた こてい ちんもく がぞう " mnemonic = NormalizeMnemonic(mnemonic) fmt.Println(mnemonic) // おさえる けむり けしごむ うせつ もちろん とさか いはつ ざっか たりる こさめ いわい にいがた こてい ちんもく がぞう
Example:
mnemonic := "carbon elder drip best unlock pool athlete fortune mixture exist bachelor quick faculty obey cliff" mnemonic = NormalizeMnemonic(mnemonic) fmt.Println(mnemonic) // carbon elder drip best unlock pool athlete fortune mixture exist bachelor quick faculty obey cliff
func SplitMnemonic ¶
SplitMnemonic splits a mnemonic into words and delimiter. If the delimiter is a Japanese space, then the language must be Japanese.
Example:
words, delimiter := SplitMnemonic("おさえる けむり けしごむ うせつ もちろん とさか いはつ ざっか たりる こさめ いわい にいがた こてい ちんもく がぞう") fmt.Println(words) // ["おさえる", "けむり", "けしごむ", "うせつ", "もちろん", "とさか", "いはつ", "ざっか", "たりる", "こさめ", "いわい", "にいがた", "こてい", "ちんもく", "がぞう"] fmt.Println(delimiter) // " "
Example:
words, delimiter := SplitMnemonic("carbon elder drip best unlock pool athlete fortune mixture exist bachelor quick faculty obey cliff") fmt.Println(words) // ["carbon", "elder", "drip", "best", "unlock", "pool", "athlete", "fortune", "mixture", "exist", "bachelor", "quick", "faculty", "obey", "cliff"] fmt.Println(delimiter) // " "
func WithEntropyBits ¶
func WithEntropyBits(entropyBits int) func(*GenerateMnemonicOptions)
WithEntropyBits sets the bits of the entropy.
func WithLanguage ¶
func WithLanguage(language Language) func(*NewMnemonicOptions)
WithLanguage sets the language of the mnemonic.
func WithLanguages ¶
func WithLanguages(languages []Language) func(*DetectLanguageOptions)
WithLanguages sets the languages to detect. If not set, all languages are possible.
func WithPassphrase ¶
func WithPassphrase(passphrase string) func(*NewSeedOptions)
WithPassphrase sets the passphrase used to generate the seed.
Types ¶
type DetectLanguageOption ¶
type DetectLanguageOption func(*DetectLanguageOptions)
DetectLanguageOption a function that modifies DetectLanguageOptions
type DetectLanguageOptions ¶
type DetectLanguageOptions struct {
// contains filtered or unexported fields
}
DetectLanguageOptions options for DetectLanguage function
type GenerateMnemonicOption ¶
type GenerateMnemonicOption func(*GenerateMnemonicOptions)
GenerateMnemonicOption a function that modifies GenerateMnemonicOptions
type GenerateMnemonicOptions ¶
type GenerateMnemonicOptions struct {
// contains filtered or unexported fields
}
GenerateMnemonicOptions options for GenerateMnemonic function
type Language ¶
type Language byte
func DetectLanguage ¶
func DetectLanguage(mnemonic string, opts ...DetectLanguageOption) (languages []Language, ok bool)
DetectLanguage detect and return the languages of the mnemonic. Default all languages are possible. In some cases, multiple languages might be matched simultaneously, such as Simplified Chinese and Traditional Chinese. If you only want to perform detection within a specified list of languages. use WithLanguages() option.
type Mnemonic ¶
type Mnemonic struct {
// contains filtered or unexported fields
}
Mnemonic
func NewMnemonic ¶
func NewMnemonic(opts ...NewMnemonicOption) (*Mnemonic, error)
NewMnemonic creates a new Mnemonic instance.
The default language is English. If you want to set the language, use WithLanguage() option.
func (*Mnemonic) EntropyFromMnemonic ¶
EntropyFromMnemonic converts a mnemonic to entropy.
func (*Mnemonic) EntropyToMnemonic ¶
EntropyToMnemonic converts entropy to a mnemonic.
The entropy must be in [16, 20, 24, 28, 32] bytes. Corresponding to [128, 160, 192, 224, 256] bits.
func (*Mnemonic) GenerateMnemonic ¶
func (m *Mnemonic) GenerateMnemonic(opts ...GenerateMnemonicOption) (string, error)
GenerateMnemonic generates a new mnemonic.
The default entropy bits is 128. If you want to set the entropy bits, use WithEntropyBits() option. The entropy bits must be in [128, 160, 192, 224, 256]. Corresponding to [16, 20, 24, 28, 32] bytes.
type NewMnemonicOption ¶
type NewMnemonicOption func(*NewMnemonicOptions)
NewMnemonicOption a function that modifies NewMnemonicOptions
type NewMnemonicOptions ¶
type NewMnemonicOptions struct {
// contains filtered or unexported fields
}
NewMnemonicOptions options for NewMnemonic function
type NewSeedOption ¶
type NewSeedOption func(*NewSeedOptions)
NewSeedOption a function that modifies NewSeedOptions
type NewSeedOptions ¶
type NewSeedOptions struct {
// contains filtered or unexported fields
}
NewSeedOptions options for NewSeed function