diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:21 +0800 |
commit | 942f552c620471602326c1ded54095c1cf41ed76 (patch) | |
tree | cbc1f21a967bb522afad6c891afb4c4628f16ab4 /utils/keys.go | |
parent | 809b4ae0f68da7a6904208662dc316cd669184fe (diff) | |
parent | a73ae8727d38391c6975a9fa149043e6c69a2f30 (diff) | |
download | go-tangerine-poc5-rc6.tar go-tangerine-poc5-rc6.tar.gz go-tangerine-poc5-rc6.tar.bz2 go-tangerine-poc5-rc6.tar.lz go-tangerine-poc5-rc6.tar.xz go-tangerine-poc5-rc6.tar.zst go-tangerine-poc5-rc6.zip |
Merge branch 'release/poc5-rc6'poc5-rc6
Diffstat (limited to 'utils/keys.go')
-rw-r--r-- | utils/keys.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/utils/keys.go b/utils/keys.go index 2f39c10b2..1c0f6a9d6 100644 --- a/utils/keys.go +++ b/utils/keys.go @@ -7,6 +7,60 @@ import ( ) func CreateKeyPair(force bool) { + if force { + ethutil.GetKeyRing().Reset() + fmt.Println("resetting") + } + + if ethutil.GetKeyRing().Get(0) == nil { + _, prv := secp256k1.GenerateKeyPair() + + keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv) + if err != nil { + panic(err) + } + + mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey)) + + fmt.Printf(` +Generating new address and keypair. +Please keep your keys somewhere save. + +++++++++++++++++ KeyRing +++++++++++++++++++ +addr: %x +prvk: %x +pubk: %x +++++++++++++++++++++++++++++++++++++++++++++ +save these words so you can restore your account later: %s +`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne) + } +} + +func ImportPrivateKey(sec string) { + ethutil.GetKeyRing().Reset() + + keyPair, err := ethutil.GetKeyRing().NewKeyPair(ethutil.FromHex(sec)) + if err != nil { + panic(err) + } + + mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey)) + + fmt.Printf(` +Generating new address and keypair. +Please keep your keys somewhere save. + +++++++++++++++++ KeyRing +++++++++++++++++++ +addr: %x +prvk: %x +pubk: %x +++++++++++++++++++++++++++++++++++++++++++++ +save these words so you can restore your account later: %s +`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne) +} + +/* +func CreateKeyPair(force bool) { data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) if len(data) == 0 || force { pub, prv := secp256k1.GenerateKeyPair() @@ -28,7 +82,9 @@ save these words so you can restore your account later: %s } } +*/ +/* func ImportPrivateKey(prvKey string) { key := ethutil.FromHex(prvKey) msg := []byte("tmp") @@ -49,3 +105,4 @@ pubk: %x `, pair.Address(), key, pub) } +*/ |