-
Notifications
You must be signed in to change notification settings - Fork 0
/
wl.go
51 lines (43 loc) · 856 Bytes
/
wl.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
package bip39
import (
"fmt"
"hash/crc32"
"strconv"
"strings"
_ "embed"
)
func init() {
if cs := strconv.FormatUint(uint64(crc32.ChecksumIEEE([]byte(english))), 16); cs != "c1dbd296" {
panic(fmt.Sprintf("Invalid checksum: %s", cs))
}
}
// Source: https://github.com/raw/bitcoin/bips/master/bip-0039/english.txt
//go:embed testdata/english.txt
var english string
var English = NewWordList(
strings.Split(
strings.TrimSpace(english),
"\n",
),
)
func NewWordList(list []string) WordList {
lookup := make(map[string]int)
for i, l := range list {
lookup[l] = i
}
return WordList{
list: list,
lookup: lookup,
}
}
type WordList struct {
list []string
lookup map[string]int
}
func (l WordList) Get(w string) (int, bool) {
i, ok := l.lookup[w]
return i, ok
}
func (l WordList) List() []string {
return l.list
}