2017-10-16 04:07:22 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (cli *CLI) generateKey() {
|
2017-10-19 19:44:58 -05:00
|
|
|
private, public := newKeyPair()
|
2017-10-16 04:07:22 -05:00
|
|
|
fmt.Println("Public Key:")
|
|
|
|
fmt.Println(hex.EncodeToString(public))
|
2017-10-19 19:44:58 -05:00
|
|
|
priKey := append(private.PublicKey.X.Bytes(), private.PublicKey.Y.Bytes()...)
|
|
|
|
priKey = append(priKey, private.D.Bytes()...)
|
|
|
|
fmt.Println("Private Key:")
|
|
|
|
fmt.Printf("%d%s\n", private.Curve, hex.EncodeToString(priKey))
|
2017-10-16 04:07:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *CLI) getAddress(pubKey string) {
|
|
|
|
public, _ := hex.DecodeString(pubKey)
|
|
|
|
|
|
|
|
pubKeyHash := HashPubKey(public)
|
|
|
|
|
|
|
|
versionedPayload := append([]byte{version}, pubKeyHash...)
|
2017-10-19 09:28:49 -05:00
|
|
|
fullPayload := append(versionedPayload, checksum(versionedPayload)...)
|
2017-10-16 04:07:22 -05:00
|
|
|
|
|
|
|
fmt.Println()
|
2017-10-18 02:28:36 -05:00
|
|
|
fmt.Printf("PubKey : %s\n", pubKey)
|
|
|
|
fmt.Printf("PubKeyHash : %x\n", pubKeyHash)
|
2017-10-19 09:28:49 -05:00
|
|
|
fmt.Printf("Address : %s\n", Base58Encode(fullPayload))
|
2017-10-16 04:07:22 -05:00
|
|
|
}
|
|
|
|
|
2017-10-18 02:29:19 -05:00
|
|
|
func (cli *CLI) getPubKeyHash(address string) {
|
|
|
|
pubKeyHash := Base58Decode([]byte(address))
|
|
|
|
fmt.Printf("%x\n", pubKeyHash[1:len(pubKeyHash)-4])
|
|
|
|
}
|
|
|
|
|
2017-10-16 04:07:22 -05:00
|
|
|
func (cli *CLI) validateAddr(address string) {
|
|
|
|
fmt.Printf("Address: %s\n", address)
|
|
|
|
if !ValidateAddress(address) {
|
|
|
|
fmt.Println("Not valid!")
|
|
|
|
} else {
|
|
|
|
fmt.Println("Valid!")
|
|
|
|
}
|
|
|
|
}
|