forked from foxnut/go-hdwallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mnemonic.go
41 lines (33 loc) · 834 Bytes
/
mnemonic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package hdwallet
import (
"github.com/tyler-smith/go-bip39"
"github.com/tyler-smith/go-bip39/wordlists"
)
func setLanguage(language string) {
switch language {
case ChineseSimplified:
bip39.SetWordList(wordlists.ChineseSimplified)
case ChineseTraditional:
bip39.SetWordList(wordlists.ChineseTraditional)
}
}
// NewMnemonic creates a random mnemonic
func NewMnemonic(length int, language string) (string, error) {
setLanguage(language)
if length < 12 {
length = 12
}
if length > 24 {
length = 24
}
entropy, err := bip39.NewEntropy(length / 3 * 32)
if err != nil {
return "", err
}
return bip39.NewMnemonic(entropy)
}
// NewSeed creates a hashed seed
func NewSeed(mnemonic, password, language string) ([]byte, error) {
setLanguage(language)
return bip39.NewSeedWithErrorChecking(mnemonic, password)
}