Sign/Verify a message

You can sign and verify messages in just 1 line of code.

With Cometh Connect, we deploy a smart account for our users.

When you use a smart account, you need to follow the EIP1271 standard for signature verification. You have to call the isValidSignature function available on the smart contract (here is a more detailed explanation). We created a library that facilitates smart account signature verification using viem.

With Connect, we deploy the smart account at the first transaction of the user, allowing to reduce gas cost for our clients (it's a feature called lazy deployment). You might want to verify the signature of a wallet that is not yet deployed.

To facilitate that, we created an endpoint that allows you to verify an account signature, whether the account is deployed or not:

In practice, this is what it looks like:

import {
  ComethWallet,
  ConnectAdaptor,
  ComethProvider,
  SupportedNetworks
} from '@cometh/connect-sdk'

const api = axios.create({ baseURL: "https://api.connect.cometh.io"});
api.defaults.headers.common["apikey"] = API_KEY;

const walletAdaptor = new ConnectAdaptor({
  chainId: YOUR_CHAIN_ID,
  apiKey: API_KEY
})

const wallet = new ComethWallet({
  authAdapter: walletAdaptor,
  apiKey: API_KEY,
  rpcUrl: RPC_URL
})

await wallet.connect(OPTIONAL_WALLET_ADDRESS)

const message = "hello world";
const signature = await wallet.signMessage(message);

const body = { message, signature };
const response = await api.post(`/wallets/${walletAddress}/is-valid-signature`, body);

const verificationResult = response.data.result

Last updated