-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
60 lines (50 loc) · 1.31 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
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"github.com/roosmaa/nano-bip39-demo/internal/ed25519"
"github.com/tyler-smith/go-bip39"
)
var bip32Path = Bip32Path{
44 + 0x80000000,
165 + 0x80000000,
1 + 0x80000000,
}
func main() {
mnemonic := flag.String("mnemonic", "", "BIP39 mnemonic (required)")
password := flag.String("password", "", "BIP39 passphrase")
path := flag.String("path", "44'/165'/0'", "BIP32 path to derive the key from")
flag.Parse()
if *mnemonic == "" {
panic("mnemonic argument missing")
}
bip32Path, err := Bip32PathFromString(*path)
if err != nil {
panic(err)
}
seed, err := bip39.NewSeedWithErrorChecking(*mnemonic, *password)
if err != nil {
panic(err)
}
keyData, err := DerivePrivateKey(seed, bip32Path)
if err != nil {
panic(err)
}
publicKey, privateKey, err := ed25519.GenerateKey(bytes.NewReader(keyData.Key))
if err != nil {
panic(err)
}
nanoAddress, err := EncodeAddress(publicKey)
if err != nil {
panic(err)
}
// Display mnemonic and keys
fmt.Printf("Mnemonic: %#v\n", *mnemonic)
fmt.Printf("Password: %#v\n", *password)
fmt.Printf("Path: %s\n", bip32Path)
fmt.Printf("Private key: %s\n", hex.EncodeToString(privateKey[:32]))
fmt.Printf("Public key: %s\n", hex.EncodeToString(publicKey))
fmt.Printf("Nano address: %s\n", nanoAddress)
}