Sign message

Signing a message

Messages can be signed by the user by utilising the following method.

// address: string user address to sign message
// message: string user message for them to sign against
await negotiator.web3WalletProvider.signMessage(
    address, 
    message
)

Tip 💡

When working with web3 wallets such as AlphaWallet or MetaMask, developers can utilise signatures as a means to identify the true owner of a wallet address. This process is crucial for building secure web3 applications that require user authentication and authorisation on the blockchain.

The method shown in this example demonstrates how to request a signature from the user via Token Negotiator. The response (e.g. "0x4c8be3f2039b....) from this method can be used to verify the token holder by uncovering the signers public address using a method such as this (most securely and commonly utilised server-side).

// return the signers public address 
getSignatureAddress(signature: string, message:string): string {
    const verifySigner = ethers.utils.recoverAddress(ethers.utils.hashMessage(message), signature)
    return verifySigner
}

Last updated