signTypedData
ClientSign 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:
- Domain info - Application name, version, chain, and contract
- Message fields - Formatted values with type-aware display
- 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
| Property | Type | Required | Description |
|---|---|---|---|
username | string | Yes | Username of the signer |
domain | EIP712Domain | Yes | EIP-712 domain parameters |
types | EIP712Types | Yes | Type definitions |
primaryType | string | Yes | Primary type to sign |
message | Record<string, unknown> | Yes | Message values |
description | string | No | Description shown in dialog |
theme | ThemeConfig | No | Theme override |
EIP712Domain
| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Application name |
version | string | Yes | Application version |
chainId | number | No | Chain ID |
verifyingContract | 0x${string} | No | Contract address |
salt | 0x${string} | No | Salt value |
SignTypedDataResult
| Property | Type | Description |
|---|---|---|
success | boolean | Whether signing succeeded |
signature | WebAuthnSignature | The WebAuthn signature |
signedHash | 0x${string} | The EIP-712 hash that was signed |
passkey | PasskeyCredentials | Passkey 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
- The SDK sends the typed data (domain, types, message) to the sign dialog
- The sign dialog displays the data in human-readable format for user review
- The sign dialog computes the EIP-712 hash locally using viem's
hashTypedData - The user signs the locally-computed hash with their passkey
- 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.