diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-04 22:52:23 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-05 01:28:39 +0800 |
commit | 0f51ee6c88f0697cec368d6e2c88b35cc173e37a (patch) | |
tree | 0aae35efd25eed2f9c1486e648db33359ae2ff07 | |
parent | dcdb4554d7f7ea3e96fec57805f0ea1042d0abc7 (diff) | |
download | dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar.gz dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar.bz2 dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar.lz dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar.xz dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.tar.zst dexon-0f51ee6c88f0697cec368d6e2c88b35cc173e37a.zip |
crypto: return common.Address rather than raw bytes
-rw-r--r-- | core/types/transaction_test.go | 6 | ||||
-rw-r--r-- | crypto/crypto.go | 8 | ||||
-rw-r--r-- | crypto/key.go | 2 |
3 files changed, 8 insertions, 8 deletions
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index dada424e9..492059c28 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -64,7 +64,7 @@ func decodeTx(data []byte) (*Transaction, error) { return &tx, rlp.Decode(bytes.NewReader(data), &tx) } -func defaultTestKey() (*ecdsa.PrivateKey, []byte) { +func defaultTestKey() (*ecdsa.PrivateKey, common.Address) { key := crypto.ToECDSA(common.Hex2Bytes("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8")) addr := crypto.PubkeyToAddress(key.PublicKey) return key, addr @@ -85,7 +85,7 @@ func TestRecipientEmpty(t *testing.T) { t.FailNow() } - if !bytes.Equal(addr, from.Bytes()) { + if addr != from { t.Error("derived address doesn't match") } } @@ -105,7 +105,7 @@ func TestRecipientNormal(t *testing.T) { t.FailNow() } - if !bytes.Equal(addr, from.Bytes()) { + if addr != from { t.Error("derived address doesn't match") } } diff --git a/crypto/crypto.go b/crypto/crypto.go index 9aef44863..8f5597b09 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -201,7 +201,7 @@ func ImportBlockTestKey(privKeyBytes []byte) error { ecKey := ToECDSA(privKeyBytes) key := &Key{ Id: uuid.NewRandom(), - Address: common.BytesToAddress(PubkeyToAddress(ecKey.PublicKey)), + Address: PubkeyToAddress(ecKey.PublicKey), PrivateKey: ecKey, } err := ks.StoreKey(key, "") @@ -247,7 +247,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error ecKey := ToECDSA(ethPriv) key = &Key{ Id: nil, - Address: common.BytesToAddress(PubkeyToAddress(ecKey.PublicKey)), + Address: PubkeyToAddress(ecKey.PublicKey), PrivateKey: ecKey, } derivedAddr := hex.EncodeToString(key.Address.Bytes()) // needed because .Hex() gives leading "0x" @@ -305,7 +305,7 @@ func PKCS7Unpad(in []byte) []byte { return in[:len(in)-int(padding)] } -func PubkeyToAddress(p ecdsa.PublicKey) []byte { +func PubkeyToAddress(p ecdsa.PublicKey) common.Address { pubBytes := FromECDSAPub(&p) - return Sha3(pubBytes[1:])[12:] + return common.BytesToAddress(Sha3(pubBytes[1:])[12:]) } diff --git a/crypto/key.go b/crypto/key.go index 0c5ce4254..0b76c43ff 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -124,7 +124,7 @@ func NewKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key { id := uuid.NewRandom() key := &Key{ Id: id, - Address: common.BytesToAddress(PubkeyToAddress(privateKeyECDSA.PublicKey)), + Address: PubkeyToAddress(privateKeyECDSA.PublicKey), PrivateKey: privateKeyECDSA, } return key |