diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-18 19:09:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-18 19:09:26 +0800 |
commit | ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d (patch) | |
tree | 494805d26ad52acac51be93e5004faa03a2cbff3 /ethereum.go | |
parent | 8c8554f5584dcc0efb4526c1d5f4d50bf2ed3b01 (diff) | |
download | go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar.gz go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar.bz2 go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar.lz go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar.xz go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.tar.zst go-tangerine-ab7dc924042b4cdb36ec7f2b26ab14c40d34ec9d.zip |
Added import/exporting of private keys
Diffstat (limited to 'ethereum.go')
-rw-r--r-- | ethereum.go | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/ethereum.go b/ethereum.go index 372d434af..36700a6d4 100644 --- a/ethereum.go +++ b/ethereum.go @@ -38,8 +38,6 @@ func CreateKeyPair(force bool) { fmt.Printf(` Generating new address and keypair. Please keep your keys somewhere save. -Currently Ethereum(G) does not support -exporting keys. ++++++++++++++++ KeyRing +++++++++++++++++++ addr: %x @@ -54,6 +52,29 @@ pubk: %x } } +func ImportPrivateKey(prvKey string) { + key := ethutil.FromHex(prvKey) + msg := []byte("tmp") + // Couldn't think of a better way to get the pub key + sig, _ := secp256k1.Sign(msg, key) + pub, _ := secp256k1.RecoverPubkey(msg, sig) + addr := ethutil.Sha3Bin(pub[1:])[12:] + + fmt.Printf(` +Importing private key + +++++++++++++++++ KeyRing +++++++++++++++++++ +addr: %x +prvk: %x +pubk: %x +++++++++++++++++++++++++++++++++++++++++++++ + +`, addr, key, pub) + + keyRing := ethutil.NewValue([]interface{}{key, addr, pub[1:]}) + ethutil.Config.Db.Put([]byte("KeyRing"), keyRing.Encode()) +} + func main() { runtime.GOMAXPROCS(runtime.NumCPU()) Init() @@ -87,7 +108,31 @@ func main() { } os.Exit(0) } else { - CreateKeyPair(false) + if len(ImportKey) > 0 { + fmt.Println("This action overwrites your old private key. Are you sure? (y/n)") + var r string + fmt.Scanln(&r) + for ; ; fmt.Scanln(&r) { + if r == "n" || r == "y" { + break + } else { + fmt.Printf("Yes or no?", r) + } + } + + if r == "y" { + ImportPrivateKey(ImportKey) + } + } else { + CreateKeyPair(false) + } + } + + if ExportKey { + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + keyRing := ethutil.NewValueFromBytes(data) + fmt.Printf("%x\n", keyRing.Get(0).Bytes()) + os.Exit(0) } if ShowGenesis { |