Skip to main content

Overview

Cavos supports signing typed data (SNIP-12) using your session key. This is useful for authentication, proof of ownership, or off-chain signatures (like order signing).

Signing Typed Data

To sign a message, prepare it in the SNIP-12 format and call signMessage().
import { useCavos } from '@cavos/react';

function SignDemo() {
  const { signMessage } = useCavos();

  const handleSign = async () => {
    const typedData = {
      types: {
        StarkNetDomain: [
          { name: 'name', type: 'shortstring' },
          { name: 'version', type: 'shortstring' },
        ],
        Message: [
          { name: 'content', type: 'felt' },
        ],
      },
      primaryType: 'Message',
      domain: {
        name: 'MyAwesomeDApp',
        version: '1',
      },
      message: {
        content: '0x48656c6c6f20576f726c64', // "Hello World" in hex
      },
    };

    try {
      const signature = await signMessage(typedData);
      console.log('Signature:', signature.r, signature.s);
    } catch (error) {
      console.error('Signing failed:', error);
    }
  };

  return <button onClick={handleSign}>Sign Message</button>;
}

Verifying Signatures

Since Cavos uses a session key for signing, verification must happen against the registered session key on-chain.
  1. On-Chain: Use the account contract’s is_valid_signature method (SRC-6).
  2. Off-Chain: Fetch the current session key for the user from the contract via get_session(session_key) and then verify the ECDSA signature against it.

Signature Format

The signMessage method returns a standard STARK curve signature:
interface Signature {
  r: string; // Hex string
  s: string; // Hex string
}

Use Cases

Authentication

Instead of a password, users can sign a unique challenge (nonce) to prove they control the wallet associated with their OAuth identity.

Order Signing

DEXs and NFT marketplaces use off-chain signatures to allow users to list assets or place orders without paying gas, only executing on-chain when a match is found.