diff options
author | Maran <maran.hidskes@gmail.com> | 2014-03-24 17:26:19 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-03-24 17:26:19 +0800 |
commit | 6724d27c0c897f116cac3163230f043e80304f91 (patch) | |
tree | 4e3f9c0225881c2b6a12deb5f223ee9b139d517d /utils/keys.go | |
parent | 3002570085c6823da4b8e12015eafa4bd87177fb (diff) | |
parent | 642630db15a793cf0a0f7fbd827daee364df5423 (diff) | |
download | dexon-6724d27c0c897f116cac3163230f043e80304f91.tar.gz dexon-6724d27c0c897f116cac3163230f043e80304f91.tar.zst dexon-6724d27c0c897f116cac3163230f043e80304f91.zip |
Merge master into miner branch
Diffstat (limited to 'utils/keys.go')
-rw-r--r-- | utils/keys.go | 50 |
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 := ðutil.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 := ðutil.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) +} |