-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsansseed.go
executable file
·64 lines (52 loc) · 1.7 KB
/
sansseed.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
55
56
57
58
59
60
61
62
63
64
package sansseed
import (
"errors"
"github.com/zackslash/sansseed/entropy"
"github.com/zackslash/sansseed/lengths"
"github.com/zackslash/sansseed/wordlists"
)
// NewWordEntropy returns new mnemonic integer slice of given length
func NewWordEntropy(l lengths.SeedBitLength) ([]int, error) {
e, err := entropy.GetRandomEntropyBytesWithCheckSum(l)
if err != nil {
return []int{}, err
}
ints, err := entropy.BinaryStringToIntSlice(e)
if err != nil {
return []int{}, err
}
return ints, nil
}
// MnemonicPhraseForLanguage uses given entropy and language to generate a mnemonic phrase
func MnemonicPhraseForLanguage(i []int, l wordlists.BIP39Wordlist) ([]string, error) {
w := l.GetList()
r := []string{}
for _, en := range i {
if en < 0 || en >= len(w) {
return []string{}, errors.New("entropy exceeds bounds of word list")
}
wrd := w[en]
r = append(r, wrd)
}
return r, nil
}
// New12WordEntropy returns new twelve length seed as an integer slice
func New12WordEntropy() ([]int, error) {
return NewWordEntropy(lengths.TwelveWordSeed)
}
// New15WordEntropy returns new fiveteen length seed as an integer slice
func New15WordEntropy() ([]int, error) {
return NewWordEntropy(lengths.FiveteenWordSeed)
}
// New18WordEntropy returns new eighteen length seed as an integer slice
func New18WordEntropy() ([]int, error) {
return NewWordEntropy(lengths.EighteenWordSeed)
}
// New21WordEntropy returns new twentyone length seed as an integer slice
func New21WordEntropy() ([]int, error) {
return NewWordEntropy(lengths.TwentyoneWordSeed)
}
// New24WordEntropy returns new twentyfour length seed as an integer slice
func New24WordEntropy() ([]int, error) {
return NewWordEntropy(lengths.TwentyfourWordSeed)
}