-
Notifications
You must be signed in to change notification settings - Fork 3
/
mnemonic.go
54 lines (46 loc) · 1.15 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
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)
case JAPANESE:
bip39.SetWordList(wordlists.Japanese)
case ITALIAN:
bip39.SetWordList(wordlists.Italian)
case KOREAN:
bip39.SetWordList(wordlists.Korean)
case SPANISH:
bip39.SetWordList(wordlists.Spanish)
case FRENCH:
bip39.SetWordList(wordlists.French)
default:
bip39.SetWordList(wordlists.English)
}
}
// NewMnemonic creates a random mnemonic
// Return the English Mnemonic default
func NewMnemonic(length int) (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)
}