aboutsummaryrefslogtreecommitdiffstats
path: root/utils/keys.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-14 19:55:08 +0800
committerobscuren <geffobscura@gmail.com>2014-05-14 19:55:08 +0800
commitf18ec51cb3959cc662bfc7b84314cd1d3b1541b5 (patch)
tree1c3d99407624dc791db0cb6c135bd2bd1dfc56cf /utils/keys.go
parente8147cf7c6f508910698e6743ad347c78010ffe3 (diff)
downloadgo-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.gz
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.bz2
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.lz
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.xz
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.zst
go-tangerine-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.zip
Switched to new keyring methods
Diffstat (limited to 'utils/keys.go')
-rw-r--r--utils/keys.go57
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)
}
+*/