Skip to content

Commit

Permalink
Merge pull request #2 from zyjblockchain/fix-ecercover-bug
Browse files Browse the repository at this point in the history
fix(): fix Ecrecover function bug
  • Loading branch information
outprog authored Apr 10, 2021
2 parents b65cb1e + 2de78d9 commit 5ff2f64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func EIP712Hash(typedData core.TypedData) (hash []byte, err error) {
return
}

func Ecrecover(hash, sig []byte) (addr common.Address, err error) {
func Ecrecover(hash, sigData []byte) (addr common.Address, err error) {
sig := make([]byte, len(sigData))
copy(sig, sigData)
if len(sig) != 65 {
err = fmt.Errorf("invalid length of signture: %d", len(sig))
return
Expand Down
4 changes: 4 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ func TestEcrecover(t *testing.T) {
addr, err := Ecrecover(hash, sig)
assert.NoError(t, err)
assert.Equal(t, "0xab6c371B6c466BcF14d4003601951e5873dF2AcA", addr.String())
// run again
addr, err = Ecrecover(hash, sig)
assert.NoError(t, err)
assert.Equal(t, "0xab6c371B6c466BcF14d4003601951e5873dF2AcA", addr.String())
}

0 comments on commit 5ff2f64

Please sign in to comment.