我是靠谱客的博主 健壮麦片,最近开发中收集的这篇文章主要介绍signature=049bc13d9571d1c0224997c83ec25925,go - Geth ecrecover invalid signature recovery id - Stack...,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

最后

以上就是健壮麦片为你收集整理的signature=049bc13d9571d1c0224997c83ec25925,go - Geth ecrecover invalid signature recovery id - Stack...的全部内容,希望文章能够帮你解决signature=049bc13d9571d1c0224997c83ec25925,go - Geth ecrecover invalid signature recovery id - Stack...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部