forked from cerc-io/plugeth
Exit after importing a key
This commit is contained in:
parent
8d1d72abee
commit
5e7f8cca4f
23
ethereum.go
23
ethereum.go
@ -36,7 +36,8 @@ func CreateKeyPair(force bool) {
|
|||||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
||||||
if len(data) == 0 || force {
|
if len(data) == 0 || force {
|
||||||
pub, prv := secp256k1.GenerateKeyPair()
|
pub, prv := secp256k1.GenerateKeyPair()
|
||||||
addr := ethutil.Sha3Bin(pub[1:])[12:]
|
pair := ðutil.Key{PrivateKey: prv, PublicKey: pub}
|
||||||
|
ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
|
||||||
|
|
||||||
fmt.Printf(`
|
fmt.Printf(`
|
||||||
Generating new address and keypair.
|
Generating new address and keypair.
|
||||||
@ -48,10 +49,8 @@ prvk: %x
|
|||||||
pubk: %x
|
pubk: %x
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
`, addr, prv, pub)
|
`, pair.Address(), prv, pub)
|
||||||
|
|
||||||
keyRing := ethutil.NewValue([]interface{}{prv, addr, pub[1:]})
|
|
||||||
ethutil.Config.Db.Put([]byte("KeyRing"), keyRing.Encode())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +60,8 @@ func ImportPrivateKey(prvKey string) {
|
|||||||
// Couldn't think of a better way to get the pub key
|
// Couldn't think of a better way to get the pub key
|
||||||
sig, _ := secp256k1.Sign(msg, key)
|
sig, _ := secp256k1.Sign(msg, key)
|
||||||
pub, _ := secp256k1.RecoverPubkey(msg, sig)
|
pub, _ := secp256k1.RecoverPubkey(msg, sig)
|
||||||
addr := ethutil.Sha3Bin(pub[1:])[12:]
|
pair := ðutil.Key{PrivateKey: key, PublicKey: pub}
|
||||||
|
ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
|
||||||
|
|
||||||
fmt.Printf(`
|
fmt.Printf(`
|
||||||
Importing private key
|
Importing private key
|
||||||
@ -72,10 +72,7 @@ prvk: %x
|
|||||||
pubk: %x
|
pubk: %x
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
`, addr, key, pub)
|
`, pair.Address(), key, pub)
|
||||||
|
|
||||||
keyRing := ethutil.NewValue([]interface{}{key, addr, pub[1:]})
|
|
||||||
ethutil.Config.Db.Put([]byte("KeyRing"), keyRing.Encode())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -95,11 +92,11 @@ func main() {
|
|||||||
|
|
||||||
// Instantiated a eth stack
|
// Instantiated a eth stack
|
||||||
ethereum, err := eth.New(eth.CapDefault, UseUPnP)
|
ethereum, err := eth.New(eth.CapDefault, UseUPnP)
|
||||||
ethereum.Port = OutboundPort
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("eth start err:", err)
|
log.Println("eth start err:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ethereum.Port = OutboundPort
|
||||||
|
|
||||||
if GenAddr {
|
if GenAddr {
|
||||||
fmt.Println("This action overwrites your old private key. Are you sure? (y/n)")
|
fmt.Println("This action overwrites your old private key. Are you sure? (y/n)")
|
||||||
@ -133,6 +130,7 @@ func main() {
|
|||||||
|
|
||||||
if r == "y" {
|
if r == "y" {
|
||||||
ImportPrivateKey(ImportKey)
|
ImportPrivateKey(ImportKey)
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CreateKeyPair(false)
|
CreateKeyPair(false)
|
||||||
@ -140,9 +138,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ExportKey {
|
if ExportKey {
|
||||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
key := ethutil.Config.Db.GetKeys()[0]
|
||||||
keyRing := ethutil.NewValueFromBytes(data)
|
fmt.Printf("%x\n", key.PrivateKey)
|
||||||
fmt.Printf("%x\n", keyRing.Get(0).Bytes())
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user