-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
62 lines (49 loc) · 1.34 KB
/
main.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
package main
import (
_ "embed"
"fmt"
"strconv"
"strings"
"syscall/js"
"github.com/nomnemonic/nomnemonic"
)
const (
// nomnemonic library version
_versionLibrary = nomnemonic.Version
// nomnemonic algorithm version
_versionAlgorithm = nomnemonic.VersionAlgorithm
)
//go:embed data/english.txt
var _words []byte
var _mnemonicer nomnemonic.Mnemonicer
func init() {
var err error
_mnemonicer, err = nomnemonic.New(strings.Split(string(_words), "\n"))
if err != nil {
panic("couldn't load words")
}
}
func main() {
fmt.Printf("nomnemonic v%s: deterministic mnemonic generator\n", _versionLibrary)
js.Global().Set("generate", js.FuncOf(generate))
js.Global().Set("libraryVersion", js.FuncOf(libraryVersion))
js.Global().Set("algorithmVersion", js.FuncOf(algorithmVersion))
select {}
}
func generate(this js.Value, inputs []js.Value) interface{} {
identifier := inputs[0].String()
password := inputs[1].String()
passcode := inputs[2].String()
size, _ := strconv.Atoi(inputs[3].String())
words, err := _mnemonicer.Generate(identifier, password, passcode, size)
if err != nil {
return "Error: " + err.Error()
}
return strings.Join(words, " ")
}
func libraryVersion(this js.Value, inputs []js.Value) interface{} {
return _versionLibrary
}
func algorithmVersion(this js.Value, inputs []js.Value) interface{} {
return _versionAlgorithm
}