šŸ”1auth SDK Docs
Back to all components

signTypedData

Client

Sign EIP-712 typed data with human-readable preview and verification.

import { signTypedData } from '@1auth/sdk'

Live Demo

EIP-712 Typed Data Signing

EIP-712 typed data signing with human-readable preview

Overview

Sign EIP-712 structured data with a human-readable preview. The dialog displays:

  1. Domain info - Application name, version, chain, and contract
  2. Message fields - Formatted values with type-aware display
  3. Signature - WebAuthn signature with the EIP-712 hash

Basic Usage

import { PasskeyProviderClient } from '@1auth/sdk';

const client = new PasskeyProviderClient({
  providerUrl: 'https://auth.example.com',
  clientId: 'my-app',
});

const result = await client.signTypedData({
  username: 'alice',
  domain: {
    name: 'My dApp',
    version: '1',
    chainId: 8453,
    verifyingContract: '0x...',
  },
  types: {
    Vote: [
      { name: 'proposalId', type: 'uint256' },
      { name: 'support', type: 'bool' },
      { name: 'voter', type: 'address' },
    ],
  },
  primaryType: 'Vote',
  message: {
    proposalId: '42',
    support: true,
    voter: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  },
  description: 'Cast your vote',
});

if (result.success) {
  console.log('Signature:', result.signature);
  console.log('EIP-712 Hash:', result.signedHash);
}

ERC-2612 Permit Example

Sign a token approval without an on-chain transaction:

const result = await client.signTypedData({
  username: 'alice',
  domain: {
    name: 'Dai Stablecoin',
    version: '1',
    chainId: 1,
    verifyingContract: '0x6B175474E89094C44Da98b954EecdeCB5BE3830F',
  },
  types: {
    Permit: [
      { name: 'owner', type: 'address' },
      { name: 'spender', type: 'address' },
      { name: 'value', type: 'uint256' },
      { name: 'nonce', type: 'uint256' },
      { name: 'deadline', type: 'uint256' },
    ],
  },
  primaryType: 'Permit',
  message: {
    owner: '0xabc...',
    spender: '0xdef...',
    value: '1000000000000000000',
    nonce: '0',
    deadline: '1735689600',
  },
  description: 'Allow spending of DAI',
});

SignTypedDataOptions

PropertyTypeRequiredDescription
usernamestringYesUsername of the signer
domainEIP712DomainYesEIP-712 domain parameters
typesEIP712TypesYesType definitions
primaryTypestringYesPrimary type to sign
messageRecord<string, unknown>YesMessage values
descriptionstringNoDescription shown in dialog
themeThemeConfigNoTheme override

EIP712Domain

PropertyTypeRequiredDescription
namestringYesApplication name
versionstringYesApplication version
chainIdnumberNoChain ID
verifyingContract0x${string}NoContract address
salt0x${string}NoSalt value

SignTypedDataResult

PropertyTypeDescription
successbooleanWhether signing succeeded
signatureWebAuthnSignatureThe WebAuthn signature
signedHash0x${string}The EIP-712 hash that was signed
passkeyPasskeyCredentialsPasskey used for signing
error{ code, message }Error details if failed

Use Cases

  • ERC-2612 Permits - Gasless token approvals
  • Governance - Off-chain voting with typed signatures
  • Order signing - DEX limit orders (EIP-712 format)
  • Meta-transactions - Relay-compatible signatures

How It Works

  1. The SDK sends the typed data (domain, types, message) to the sign dialog
  2. The sign dialog displays the data in human-readable format for user review
  3. The sign dialog computes the EIP-712 hash locally using viem's hashTypedData
  4. The user signs the locally-computed hash with their passkey
  5. The signature and hash are returned to your app

Security Model

The EIP-712 hash is computed inside the sign dialog, not by the calling application. This ensures users sign exactly what they see displayed:

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Your App (SDK Client)              │
│                                     │
│  1. Calls client.signTypedData()    │
│  2. SDK sends typed data to dialog  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
               │ postMessage (typed data only)
               ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Sign Dialog (Trusted)              │
│                                     │
│  3. Displays data for user review   │
│  4. Computes EIP-712 hash locally   │  ◄── Hash computed HERE
│  5. Signs hash with passkey         │
│  6. Returns signature + hash        │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

This prevents a malicious app from displaying one thing while getting the user to sign something different. The sign dialog is the trusted component that ensures what you see is what you sign.