From 2de78d9caefa77ce8cd4b66670f4f412bb7d6c86 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Sat, 10 Apr 2021 23:52:22 +0800 Subject: [PATCH] fix(): fix Ecrecover function bug --- utils.go | 4 +++- utils_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index cd5ceb2..f38a344 100644 --- a/utils.go +++ b/utils.go @@ -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 diff --git a/utils_test.go b/utils_test.go index 62dc846..2d43487 100644 --- a/utils_test.go +++ b/utils_test.go @@ -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()) }