aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-03-22 08:02:24 +0800
committerobscuren <geffobscura@gmail.com>2014-03-22 08:02:24 +0800
commit1f2547b8a7cfe100f64428d20f4bcf95eb9ecc5c (patch)
treed8be2c7b97a86f2b9949c4b4dc14ab2c2a34dc2e /utils
parent22b4e9b6173437b28045d69e8fd0b468e526e559 (diff)
downloaddexon-1f2547b8a7cfe100f64428d20f4bcf95eb9ecc5c.tar.gz
dexon-1f2547b8a7cfe100f64428d20f4bcf95eb9ecc5c.tar.zst
dexon-1f2547b8a7cfe100f64428d20f4bcf95eb9ecc5c.zip
Major re-organisation.
The Ethereum node and Gui are now separated.
Diffstat (limited to 'utils')
-rw-r--r--utils/keys.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/utils/keys.go b/utils/keys.go
new file mode 100644
index 000000000..910c8c477
--- /dev/null
+++ b/utils/keys.go
@@ -0,0 +1,50 @@
+package utils
+
+import (
+ "fmt"
+ "github.com/ethereum/eth-go/ethutil"
+ "github.com/obscuren/secp256k1-go"
+)
+
+func CreateKeyPair(force bool) {
+ data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
+ if len(data) == 0 || force {
+ pub, prv := secp256k1.GenerateKeyPair()
+ pair := &ethutil.Key{PrivateKey: prv, PublicKey: pub}
+ ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
+
+ fmt.Printf(`
+Generating new address and keypair.
+Please keep your keys somewhere save.
+
+++++++++++++++++ KeyRing +++++++++++++++++++
+addr: %x
+prvk: %x
+pubk: %x
+++++++++++++++++++++++++++++++++++++++++++++
+
+`, pair.Address(), prv, pub)
+
+ }
+}
+
+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)
+ pair := &ethutil.Key{PrivateKey: key, PublicKey: pub}
+ ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
+
+ fmt.Printf(`
+Importing private key
+
+++++++++++++++++ KeyRing +++++++++++++++++++
+addr: %x
+prvk: %x
+pubk: %x
+++++++++++++++++++++++++++++++++++++++++++++
+
+`, pair.Address(), key, pub)
+}