Skip to content

Commit

Permalink
Print QR codes for the public Wallet address and the private key
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed Sep 3, 2017
1 parent 834c8c5 commit 4c81730
Showing 1 changed file with 52 additions and 12 deletions.
64 changes: 52 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ package main

import (
"bufio"
"bytes"
"fmt"
"os"
"strings"

"github.com/moncho/warpwallet/bitcoin"
"github.com/moncho/warpwallet/qr"
"github.com/moncho/warpwallet/terminal"
"github.com/moncho/warpwallet/warp"
)

func main() {

stat, _ := os.Stdin.Stat()
piped := false
if (stat.Mode() & os.ModeCharDevice) == 0 {
piped = true
piped := seedsFromPipe()
pass, salt := promptSeeds(piped)

if pass == "" || salt == "" {
fmt.Println("A pass and some salt are required")
os.Exit(-1)
}
pass, salt := askForSeeds(piped)

key, err := warp.NewSeed(pass, salt)

//log.Printf("Generating wallet seed from %s, %s", pass, salt)

if err != nil {
fmt.Printf("Could not generate wallet seed from %s, %s: %s", pass, salt, err.Error())
os.Exit(-1)
Expand All @@ -32,21 +34,50 @@ func main() {
if wif == "" || pubAddress == "" {
os.Exit(-1)
}
fmt.Printf("Public bitcoin address: %v\n", pubAddress)
fmt.Printf("Private key (don't share): %v\n", wif)

var wifQR bytes.Buffer
if err := qr.Encode(wif, &wifQR); err != nil {
fmt.Printf("Could not generate QR code for WIF: %s", err.Error())
os.Exit(-1)
}
var pubAddressQR bytes.Buffer

if err := qr.Encode(pubAddress, &pubAddressQR); err != nil {
fmt.Printf("Could not generate QR code for pubAddress: %s", err.Error())
os.Exit(-1)
}
print(wif, wifQR.String(), pubAddress, pubAddressQR.String())
}

func print(wif, wifQR, pubAddress, pubAddressQR string) {

fmt.Printf("\n%s %s\t\t %s %s\n\n",
terminal.White("Public bitcoin address:"),
terminal.Yellow(pubAddress),
terminal.White("Private key (don't share):"),
terminal.Red(wif))

pub := strings.Split(pubAddressQR, "\n")
wif2 := strings.Split(wifQR, "\n")

for i, line := range pub {
fmt.Printf("%s\t\t%s\n", string(line), string(wif2[i]))

}
}

func askForSeeds(piped bool) (string, string) {
func promptSeeds(piped bool) (string, string) {

reader := bufio.NewReader(os.Stdin)
if !piped {
fmt.Print("Passphrase: ")
fmt.Print(
terminal.White("Passphrase: "))
}
pass, _ := reader.ReadString('\n')
pass = strings.Trim(pass, "\n")
if !piped {
fmt.Print("Your email [as a salt]: ")
fmt.Print(
terminal.White("Your email [as a salt]: "))
}
salt, _ := reader.ReadString('\n')
salt = strings.Trim(salt, "\n")
Expand All @@ -72,3 +103,12 @@ func generate(key []byte) (string, string) {

return wif, address
}

func seedsFromPipe() bool {
stat, _ := os.Stdin.Stat()
piped := false
if (stat.Mode() & os.ModeCharDevice) == 0 {
piped = true
}
return piped
}

0 comments on commit 4c81730

Please sign in to comment.