forked from FactomProject/keymaker
/
keymaker.go
56 lines (45 loc) · 1.27 KB
/
keymaker.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
package main
import (
"bufio"
"fmt"
"github.com/FactomProject/factoid"
"github.com/FactomProject/factoid/wallet"
"os"
"strings"
)
func main() {
r := bufio.NewScanner(os.Stdin)
fmt.Print("Enter 12 words from Koinify here: ")
r.Scan()
line := r.Text()
args := strings.Fields(string(line))
if len(args) == 12 {
mnemonic := ""
for _, v := range args {
v = strings.ToLower(v)
mnemonic = mnemonic + v + " "
}
mnemonic = strings.TrimSpace(mnemonic)
private, err := wallet.MnemonicStringToPrivateKey(mnemonic)
if err != nil {
fmt.Print("\n\nThere was a problem with the 12 words you entered. Please check spelling against this list:\n")
fmt.Print("https://github.com/FactomProject/go-bip39/blob/master/wordlist.go\n\n\n\n")
panic(err)
}
pub, priv, err := wallet.GenerateKeyFromPrivateKey(private)
if err != nil {
panic(err)
}
we := new(wallet.WalletEntry)
we.AddKey(pub, priv)
we.SetName([]byte("test"))
we.SetRCD(factoid.NewRCD_1(pub))
we.SetType("fct")
address, _ := we.GetAddress()
adr := factoid.ConvertFctAddressToUserStr(address)
fmt.Printf("\nFactoid Address: %v\n", adr)
fmt.Printf("\nCheck your balance at http://explorer.factom.org/\n")
} else {
fmt.Printf("\n\nError: 12 and only 12 words are expected.\n")
}
}