aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/key.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-01-30 01:28:55 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-01-30 01:28:55 +0800
commit1cfea1113ac90b5214560ea6db923106f638c4b8 (patch)
tree5a539d60640da4ee4b1ddd62f703f715523c411a /crypto/key.go
parent726852e3d3ba5c2167bbdb3bdd3ecbaff6b4f242 (diff)
parent6488a392a347d0d47212fdc78386e3e0e5841d7d (diff)
downloadgo-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar.gz
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar.bz2
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar.lz
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar.xz
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.tar.zst
go-tangerine-1cfea1113ac90b5214560ea6db923106f638c4b8.zip
Merge branch 'qt5.4' of github.com:ethereum/go-ethereum into qt5.4
Diffstat (limited to 'crypto/key.go')
-rw-r--r--crypto/key.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/crypto/key.go b/crypto/key.go
index ca29b691f..b9ad34f47 100644
--- a/crypto/key.go
+++ b/crypto/key.go
@@ -33,7 +33,9 @@ import (
)
type Key struct {
- Id *uuid.UUID // Version 4 "random" for unique id not derived from key data
+ Id uuid.UUID // Version 4 "random" for unique id not derived from key data
+ // to simplify lookups we also store the address
+ Address []byte
// we only store privkey as pubkey/address can be derived from it
// privkey in this struct is always in plaintext
PrivateKey *ecdsa.PrivateKey
@@ -41,6 +43,7 @@ type Key struct {
type plainKeyJSON struct {
Id []byte
+ Address []byte
PrivateKey []byte
}
@@ -51,18 +54,15 @@ type cipherJSON struct {
}
type encryptedKeyJSON struct {
- Id []byte
- Crypto cipherJSON
-}
-
-func (k *Key) Address() []byte {
- pubBytes := FromECDSAPub(&k.PrivateKey.PublicKey)
- return Sha3(pubBytes[1:])[12:]
+ Id []byte
+ Address []byte
+ Crypto cipherJSON
}
func (k *Key) MarshalJSON() (j []byte, err error) {
jStruct := plainKeyJSON{
- *k.Id,
+ k.Id,
+ k.Address,
FromECDSA(k.PrivateKey),
}
j, err = json.Marshal(jStruct)
@@ -78,8 +78,8 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
u := new(uuid.UUID)
*u = keyJSON.Id
- k.Id = u
-
+ k.Id = *u
+ k.Address = keyJSON.Address
k.PrivateKey = ToECDSA(keyJSON.PrivateKey)
return err
@@ -101,7 +101,8 @@ func NewKey(rand io.Reader) *Key {
id := uuid.NewRandom()
key := &Key{
- Id: &id,
+ Id: id,
+ Address: PubkeyToAddress(privateKeyECDSA.PublicKey),
PrivateKey: privateKeyECDSA,
}
return key