account.signTypedData()
Sign EIP-712 typed data.
Type: instance async
Signature
async signTypedData(
typedData: TypedDataDefinition<TypedData, string>,
options?: { address?: Address }
): Promise<Hex>Parameters
typedData
Type: TypedDataDefinition<TypedData, string>
The EIP-712 typed data to sign, including domain, types, primary type, and message.
options (optional)
Type: { address?: Address }
interface TypedDataDefinition {
domain: {
name?: string;
version?: string;
chainId?: number;
verifyingContract?: Address;
salt?: Hex;
};
types: Record<string, Array<{ name: string; type: string }>>;
primaryType: string;
message: Record<string, unknown>;
}Returns
Promise<Hex> - The signature as a hex string.
Behavior
- Encodes the typed data according to EIP-712
- Signs with the smart account (passkey or local account)
- Returns the signature wrapped for smart account validation
Example
Getting an Account Instance
Before calling instance methods, create an account using one of the factory methods:
import { Account } from '@jaw.id/core';
// Option 1: Restore existing session or login with passkey
const account = await Account.get({ chainId: 1, apiKey: 'your-api-key' });
// Option 2: Create a new account with passkey
const account = await Account.create({ chainId: 1, apiKey: 'your-api-key' }, { username: 'alice' });
// Option 3: Import from cloud backup
const account = await Account.import({ chainId: 1, apiKey: 'your-api-key' });
// Option 4: From a local account (server-side / embedded wallets)
const account = await Account.fromLocalAccount({ chainId: 1, apiKey: 'your-api-key' }, localAccount);Basic Usage
const signature = await account.signTypedData({
domain: {
name: 'MyApp',
version: '1',
chainId: 1,
verifyingContract: '0x...',
},
types: {
Message: [
{ name: 'content', type: 'string' },
{ name: 'timestamp', type: 'uint256' },
],
},
primaryType: 'Message',
message: {
content: 'Hello, World!',
timestamp: BigInt(Date.now()),
},
});Signing from a Different Account
Target account address to sign from. The signer must be a registered owner on that account.
const signature = await account.signTypedData(
{
domain: { name: 'MyApp', version: '1', chainId: 1, verifyingContract: '0x...' },
types: { Message: [{ name: 'content', type: 'string' }] },
primaryType: 'Message',
message: { content: 'Hello' },
},
{ address: '0xTargetAccount...' }
);Related
- account.signMessage() - Sign personal messages
- account.sendTransaction() - Send transactions
- EIP-712 Specification - Typed data standard