aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-01-25 09:07:20 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-01-26 11:30:17 +0800
commit512ffa2bf4308b44aa6f43f25238b375b58d7dbc (patch)
tree40cc0f2aa3eda21eb7039b128d27bdab94d883be /crypto/crypto.go
parentd792e95c214c8352e6b23b798101e90844eaa7a3 (diff)
downloaddexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar.gz
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar.bz2
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar.lz
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar.xz
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.tar.zst
dexon-512ffa2bf4308b44aa6f43f25238b375b58d7dbc.zip
Add accounts package and refactor key stores
* Add initial UserAccount and AccountManager structs * Add NewAccount, Sign and Accounts functions * Refactor key stores to use key address as main identifier while keeping the UUID. * Use key address as file/dir names instead of UUID
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 4b2cc7bb4..f8d6139a8 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -134,7 +134,7 @@ func ImportPreSaleKey(keyStore KeyStore2, keyJSON []byte, password string) (*Key
return nil, err
}
id := uuid.NewRandom()
- key.Id = &id
+ key.Id = id
err = keyStore.StoreKey(key, password)
return key, err
}
@@ -167,9 +167,10 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
ecKey := ToECDSA(ethPriv)
key = &Key{
Id: nil,
+ Address: pubkeyToAddress(ecKey.PublicKey),
PrivateKey: ecKey,
}
- derivedAddr := ethutil.Bytes2Hex(key.Address())
+ derivedAddr := ethutil.Bytes2Hex(key.Address)
expectedAddr := preSaleKeyStruct.EthAddr
if derivedAddr != expectedAddr {
err = errors.New("decrypted addr not equal to expected addr")
@@ -223,3 +224,8 @@ func PKCS7Unpad(in []byte) []byte {
}
return in[:len(in)-int(padding)]
}
+
+func pubkeyToAddress(p ecdsa.PublicKey) []byte {
+ pubBytes := FromECDSAPub(&p)
+ return Sha3(pubBytes[1:])[12:]
+}