Skip to content

Commit 7efe5df

Browse files
MrChicolivnev
authored andcommitted
ethsign: utilize SigToPub instead of manual labor
1 parent f23996c commit 7efe5df

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/ethsign/ethsign.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,11 @@ func recover(data []byte, sig hexutil.Bytes, noPrefix bool) (common.Address, err
157157
hash = signHash(data)
158158
}
159159

160-
rpk, err := crypto.Ecrecover(hash, sig)
160+
rpk, err := crypto.SigToPub(hash, sig)
161161
if err != nil {
162162
return common.Address{}, err
163163
}
164-
pubKey, err := crypto.UnmarshalPubkey(rpk)
165-
if err != nil {
166-
return common.Address{}, fmt.Errorf("invalid public key")
167-
}
168-
recoveredAddr := crypto.PubkeyToAddress(*pubKey)
169-
return recoveredAddr, nil
164+
return crypto.PubkeyToAddress(*rpk), nil
170165
}
171166

172167
func main() {
@@ -611,7 +606,7 @@ func main() {
611606
return cli.NewExitError("ethsign: failed to read private key", 1)
612607
}
613608

614-
acct, err := ks.ImportECDSA(privatekey, string(passphraseBytes))
609+
acct, err := ks.ImportECDSA(privatekey, string(passphraseBytes))
615610
if err != nil {
616611
fmt.Fprintf(os.Stderr, "keystore error: %v\n", err)
617612
return cli.NewExitError("ethsign: failed to import key", 1)

0 commit comments

Comments
 (0)