Skip to main content

Authenticate Users with Message Signature

Ask for the wallet address

To get the user's Sequence wallet address:

const wallet = sequence.getWallet()
const address = await wallet.getAddress()

Authenticate wallet

In many cases, you'll want your users to connect and then verify they do control this wallet address. Applications typically do this by asking the user to sign a message with their wallet, and then verify the signature from the user to ensure its integrity.

As this is such a common workflow, Sequence can automatically authenticate the account address at the same time while the user is prompt to connect their wallet to your dapp. This allows the user experience to be simpler and more seamless.

import { sequence } from '0xsequence'

const wallet = sequence.getWallet()

const connectDetails = await wallet.connect({
app: 'Your Dapp name',
authorize: true // <---<<< this will automatically sign+verify a EIP712 message when user clicks "Connect"

It will look like this to your users:
Sequence on-demand sign in, connect

In the above example, we pass authorize: true to the connect() function, which will automatically have the user sign a EIP712 signed message to prove their identity. This allows you to then easily authenticate the connected wallet address with absolutely certainty.

You can find the signed message proof returned in connectDetails.proof, which is an EIP712 signed object using a simple a convention from ethauth. NOTE: EIP712 allows you to use an actual object for signing instead of just a plain-text string.

Authenticate wallet server-side

The above example demonstrates how to connect and verify the user's identity in your dapp on the client-side, but if you'd like to authenticate the Sequence authorization proof on your server, then you can do so with the following snippet:

const ethAuth = new ETHAuth()
await ethAuth.configJsonRpcProvider('<your infura key here>')

try {
const decodedProof = await ethAuth.decodeProof(connectDetails.proof.proofString)
console.log('welcome user address', decodedProof.address)

} catch (err) {
console.log('proof is invalid -- do not trust the provided account address')

See the Go Sequence SDK on using Sequence in your Go applications.

If your server is written in a language other then Javascript/Typescript or Go, all you have to do is validate the signature with EIP1271, the standard method for validating signed messages for a smart wallet.

As always, if you have any questions or require help, reach out to us on Discord.