aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-05 18:35:23 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-01-05 18:35:23 +0800
commit08eea0f0e417c5f6ff864ae4633cc3e0a12aa405 (patch)
treef3a76e0c2511e18a874742cf801d35073b62c2f2 /accounts
parent0fac8cba479a7cd90c17307b8795a0f836877c2e (diff)
downloadgo-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.gz
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.bz2
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.lz
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.xz
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.zst
go-tangerine-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.zip
accounts, core, crypto, internal: use normalised V during signature handling (#3455)
To address increasing complexity in code that handles signatures, this PR discards all notion of "different" signature types at the library level. Both the crypto and accounts package is reduced to only be able to produce plain canonical secp256k1 signatures. This makes the crpyto APIs much cleaner, simpler and harder to abuse.
Diffstat (limited to 'accounts')
-rw-r--r--accounts/abi/bind/auth.go2
-rw-r--r--accounts/account_manager.go27
2 files changed, 8 insertions, 21 deletions
diff --git a/accounts/abi/bind/auth.go b/accounts/abi/bind/auth.go
index a20852fca..dbb235c14 100644
--- a/accounts/abi/bind/auth.go
+++ b/accounts/abi/bind/auth.go
@@ -52,7 +52,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
if address != keyAddr {
return nil, errors.New("not authorized to sign this account")
}
- signature, err := crypto.SignEthereum(signer.Hash(tx).Bytes(), key)
+ signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
if err != nil {
return nil, err
}
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index abe442388..12ff30bca 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -136,42 +136,29 @@ func (am *Manager) DeleteAccount(a Account, passphrase string) error {
return err
}
-// Sign calculates a ECDSA signature for the given hash.
-// Note, Ethereum signatures have a particular format as described in the
-// yellow paper. Use the SignEthereum function to calculate a signature
-// in Ethereum format.
+// Sign calculates a ECDSA signature for the given hash. The produced signature
+// is in the [R || S || V] format where V is 0 or 1.
func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) {
am.mu.RLock()
defer am.mu.RUnlock()
- unlockedKey, found := am.unlocked[addr]
- if !found {
- return nil, ErrLocked
- }
- return crypto.Sign(hash, unlockedKey.PrivateKey)
-}
-// SignEthereum calculates a ECDSA signature for the given hash.
-// The signature has the format as described in the Ethereum yellow paper.
-func (am *Manager) SignEthereum(addr common.Address, hash []byte) ([]byte, error) {
- am.mu.RLock()
- defer am.mu.RUnlock()
unlockedKey, found := am.unlocked[addr]
if !found {
return nil, ErrLocked
}
- return crypto.SignEthereum(hash, unlockedKey.PrivateKey)
+ return crypto.Sign(hash, unlockedKey.PrivateKey)
}
-// SignWithPassphrase signs hash if the private key matching the given
-// address can be decrypted with the given passphrase.
+// SignWithPassphrase signs hash if the private key matching the given address
+// can be decrypted with the given passphrase. The produced signature is in the
+// [R || S || V] format where V is 0 or 1.
func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error) {
_, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase)
if err != nil {
return nil, err
}
-
defer zeroKey(key.PrivateKey)
- return crypto.SignEthereum(hash, key.PrivateKey)
+ return crypto.Sign(hash, key.PrivateKey)
}
// Unlock unlocks the given account indefinitely.