mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/scwallet: address review concerns, remove copy-pasta
This commit is contained in:
parent
afe95fd7ae
commit
e820c7caf5
1 changed files with 7 additions and 9 deletions
|
|
@ -1049,27 +1049,25 @@ func (s *Session) sign(path accounts.DerivationPath, hash []byte) ([]byte, error
|
|||
// determinePublicKey uses a signature and the X component of a public key to
|
||||
// recover the entire public key.
|
||||
func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) {
|
||||
for v := 0; v < 2; v++ {
|
||||
sig[64] = byte(v)
|
||||
if pubkey, err := crypto.Ecrecover(DerivationSignatureHash[:], sig); err == nil {
|
||||
if bytes.Equal(pubkey, pubkeyX) {
|
||||
return pubkey, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, ErrPubkeyMismatch
|
||||
return makeRecoverableSignature(DerivationSignatureHash[:], sig, pubkeyX)
|
||||
}
|
||||
|
||||
// makeRecoverableSignature uses a signature and an expected public key to
|
||||
// recover the v value and produce a recoverable signature.
|
||||
func makeRecoverableSignature(hash, sig, expectedPubkey []byte) ([]byte, error) {
|
||||
var libraryError error
|
||||
for v := 0; v < 2; v++ {
|
||||
sig[64] = byte(v)
|
||||
if pubkey, err := crypto.Ecrecover(hash, sig); err == nil {
|
||||
if bytes.Equal(pubkey, expectedPubkey) {
|
||||
return sig, nil
|
||||
}
|
||||
} else {
|
||||
libraryError = err
|
||||
}
|
||||
}
|
||||
if libraryError != nil {
|
||||
return nil, libraryError
|
||||
}
|
||||
return nil, ErrPubkeyMismatch
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue