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:

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

const message = "hello world";
const signature = await smartAccountClient.account.signMessage({ message });
const chainId = arbitrumSepolia.id

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

const isValidSignature = response.data.result

You can also verify the signature on the client side:

const message = "hello world";
const signature = await smartAccountClient.account.signMessage({ message });

const isValidSignature = await smartAccountClient.verifySignature({
  message,
  signature
});

Last updated