1

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?

0

1 Answer 1

0

I just realized how stupid my question is.

Signing the message is just a cryptographic thing. The code above just checks that the incoming signature hex is valid using the nonce and message.

What I am doing doesn't involve anything regarding Ethereum or BSC, the same code will work on both without an issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.