signature=049bc13d9571d1c0224997c83ec25925,go - Geth ecrecover invalid signature recovery id - Stack...

在尝试使用go-ethereum库验证客户端传递的Ethereum签名时遇到问题。参数已在Etherscan上验证正确,但代码中出现'invalid signature recovery id'错误。尝试了对消息进行预处理和编码,但未成功。发现库期望的恢复ID大于4,而实际为27。
摘要由CSDN通过智能技术生成

I'm trying to verify signature passed in from client using the geth golang library. I'm getting the sample data (signature / address) from one of my cryptokitties accounts (I can see it in the request). If I paste the blow credentials into https://etherscan.io/verifySig, it gets verified, so I know the parameters are correct.

My code:

import (

"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/ethereum/go-ethereum/crypto"

)

sig := 0x80f5bac5b6300ed64835d5e2f167a368c892ccc2d0e252bc84befbcb093f5a2d36294b95d86683cec778c8c796049933c04c71576c56c1d6e9a9fa10342beca31c

data := "Cryptokitties"

decoded = hexutil.MustDecode(sig) // j8aUTtPid0ZnNa/s4Ef5gisYYh1bCeLSmFrtJtDjNRRqxShUr+1A3BVgoAPwiZ+lKN0POB1JOdVhVHI9tcHmABs=

hash := crypto.Keccak256([]byte(data)) // "ljQQTm25oqIbD+LMl70aRUcTzXCeeDGfkRj9YJYsgKY="

pubKey, err := crypto.Ecrecover(hash, sig) // error: "invalid signature recovery id"

I'm sure I'm missing something simple, but not really sure where to look.

**UPDATE

What I tried after looking around some answers:

changing the message like this:

fmt.Sprintf("\u0019Ethereum Signed Message:\n%d%s", len(data), data) //"\u0019Ethereum Signed Message:\n13Cryptokitties"

hex encoding the message before hashing it:

data=hexutil.Encode(data)

combining the above two, so first prepending the 'Ethereum Signed Message', then hexencoding it.

Any points would be appreciated, I'm sure this is a noob question.

**UPDATE

Looking through the source code, I discovered its expecting recovery id to be greater than 4:

sig[64] >= 4

In my case it turns out to be 27:

sig[64] --> 27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值