eth_sign_verify.go
source link: https://gist.github.com/dcb9/385631846097e1f59e3cba3b1d42f3ed
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
works like a charm
This is godsend!
Saved me from more head-breaking. Thank you!
phuwn commented on Nov 4, 2021
Thank you. geth
should use this as an example
4 years later this is saving lives.
Hello internet. Make sure to read the latest version of func (s *PrivateAccountAPI) EcRecover
at https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go.
Notable changes are:
- The
64
is replaced withcrypto.RecoveryIDOffset
signHash
is replaced withaccounts.TextHash
Maybe @dcb9 should update this gist.
krasi-georgiev commented on Mar 22 •
simplified version
package main
import (
"fmt"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
fmt.Println(verifySig(
"0x0EaE3eF6CC7176553E6B45d94e9eFDE2Da7B82a5",
"0x34850b7e36e635783df0563c7202c3ac776df59db5015d2b6f0add33955bb5c43ce35efb5ce695a243bc4c5dc4298db40cd765f3ea5612d2d57da1e4933b2f201b",
[]byte("Example `personal_sign` message"),
))
}
func verifySig(from, sigHex string, msg []byte) bool {
sig := hexutil.MustDecode(sigHex)
msg = accounts.TextHash(msg)
sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
recovered, err := crypto.SigToPub(msg, sig)
if err != nil {
return false
}
recoveredAddr := crypto.PubkeyToAddress(*recovered)
return from == recoveredAddr.Hex()
}
@krasi-georgiev Perfect I copied yours as the latest version
@rht Thanks you so much
It works! Thanks!
Good! helped me a lot!
Helped a lot cheers !
Works fine but I need to replace
sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
if sig[crypto.RecoveryIDOffset] == 27 || sig[crypto.RecoveryIDOffset] == 28 {
sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
}
Amazing! Worked on the first go!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK