I am trying to implement a metamask user authentication flow on BSC.
I managed to get it working on ethereum. The flow is like this.
I've found the code for ethereum on some gist however I am unable to do so for BSC and I am having a hard time understanding the documentation for BSC https://github.com/bnb-chain/bsc (same as go-ethereum). At least for the documentation I am used to this is so so unfriendly.
In order to verify the transaction I do this:
import("github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto")
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()
}
I guess if I import the same things from https://github.com/bnb-chain/bsc and do the same thing it will work? Am I mistaken?