logo

EIP-712 Signing

Prepare and sign Namefi EIP-712 requests using the live helper endpoints

Typed-data requests on /v4

To prepare a signature, put authentication metadata alongside the normal business fields:

{
  "normalizedDomainName": "example.com",
  "enableParking": true,
  "$metadata": {
    "auth": {
      "method": "eip712",
      "mode": "typed-data",
      "account": "0x1111111111111111111111111111111111111111",
      "chainId": 1
    }
  }
}

Send this to the operation, such as PUT /v4/dns/park. Without a signature, the API returns HTTP 401 with safe signing requirements and a WWW-Authenticate header. It does not execute the action. Sign the returned typedData, then send a metadata-only request containing the returned auth plus your signature:

const { auth, typedData } = requirements.data;
const signature = await wallet.signTypedData(typedData);
const body = { $metadata: { auth: { ...auth, signature } } };

Do not repeat business fields beside $metadata on signed retries: those requests are rejected. auth.payloadType identifies the method struct and auth.payload contains its signed values. NamefiApiRequest is the envelope; its payload field has that method-specific struct type, not a JSON string. Its domain, envelope fields and allowed payload types are selected by the server.

Optional fields use suffixed zero-or-one arrays: overrideExistingRecords_opt: [] means omitted, [false] means explicitly false. Nullable fields use a separate __nullable wrapper, preserving null, omission and empty arrays as distinct values. The server decodes these fields only for authenticated execution, then applies the procedure's original validation, defaults and normalization. JSON number fields must remain safe integers; a decimal string is not automatically coerced to a number after signature verification.

mode: "payload" remains an alias of "typed-data". This method-struct format changes signed hashes from the earlier generic JSON-string /v4 format; deploy the matching SDK/backend together and prepare fresh signatures. /v-next keeps its existing signing format.

The proof includes the operation, account, chain, canonical API origin, payload, nonce, and UTC Unix seconds timestamp. The server verifies the supplied structured payload and rejects changed signed fields, expired proofs, or reused nonces. ERC-1271 verification checks the claimed contract on the server-configured account-verification chain. No challenge ID or stored challenge is involved.

$metadata is reserved transport input and never reaches business handlers. Use API-key, OAuth, or SIWE credentials for GET reads. The SDK requires authentication.chainId (or siwe.chainId) for signed writes and accepts an explicit authentication.account for contract wallets.

Legacy /v-next signing

The sections below describe the retained header/envelope format for existing clients. Do not use these legacy envelopes to construct /v4 metadata proofs. Its signing types come from the same procedure declarations as the API, without depending on OpenAPI document generation.

Live helper endpoints

EndpointPurpose
GET /v-next/eip712/domain?chain=1Returns the signing domain
GET /v-next/eip712/typesReturns the full EIP-712 type registry
GET /v-next/eip712/types-for-method?method=toggleDomainParkingReturns accepted primary types and the type map for one operation

EIP-712 domain

Fetch the current domain from the API:

const domain = await fetch(
  'https://api.namefi.io/v-next/eip712/domain?chain=1',
).then((r) => r.json());

console.log(domain);
// { name: 'Namefi', version: '1', chainId: 1 }

The endpoint includes chainId when chain is supplied. Use the exact returned domain when signing.

Per-method types

Fetch the accepted primary types and type map for one operation:

const methodTypes = await fetch(
  'https://api.namefi.io/v-next/eip712/types-for-method?method=toggleDomainParking',
).then((r) => r.json());

console.log(methodTypes);
/*
{
  found: true,
  acceptedPrimaryTypes: ['ToggleDomainParkingEnvelope'],
  types: {
    ToggleDomainParking: [
      { name: 'normalizedDomainName', type: 'string' },
      { name: 'enableParking', type: 'bool' },
      { name: 'overrideExistingRecords', type: 'bool' }
    ],
    ToggleDomainParkingEnvelope: [
      { name: 'payloadType', type: 'string' },
      { name: 'payload', type: 'ToggleDomainParking' },
      { name: 'timestamp', type: 'uint256' },
      { name: 'nonce', type: 'string' }
    ]
  }
}
*/

When found is false, the response includes availableMethods so you can discover valid EIP-712 operation IDs.

Envelope structure

Every EIP-712 request signs a standard envelope:

{
  payloadType: string;
  payload: Record<string, unknown>;
  timestamp: number;
  nonce: string;
}

The primaryType is always an envelope type such as ToggleDomainParkingEnvelope. The inner payloadType is derived by removing the Envelope suffix.

Manual signing flow

import { toHex } from 'viem';

const payload = {
  normalizedDomainName: 'example.com',
  enableParking: true,
  overrideExistingRecords: false,
};

const domain = await fetch(
  'https://api.namefi.io/v-next/eip712/domain?chain=1',
).then((r) => r.json());

const methodTypes = await fetch(
  'https://api.namefi.io/v-next/eip712/types-for-method?method=toggleDomainParking',
).then((r) => r.json());

if (!methodTypes.found) {
  throw new Error('Method is not registered for EIP-712');
}

const primaryType = methodTypes.acceptedPrimaryTypes[0];
const payloadType = primaryType.replace(/Envelope$/, '');

const envelope = {
  payloadType,
  payload,
  timestamp: Math.trunc(Date.now() / 1000),
  nonce: toHex(crypto.getRandomValues(new Uint8Array(32))),
};

const typedData = {
  domain,
  types: methodTypes.types,
  primaryType,
  message: envelope,
};

const signature = await externalSigner.signTypedData(typedData);

const preparedRequest = {
  method: 'PUT',
  url: '<use the resolved operation URL here>',
  headers: {
    'content-type': 'application/json',
    'x-namefi-signer': externalSigner.address,
    'x-namefi-signature': signature,
    'x-namefi-eip712-type': primaryType,
  },
  body: envelope,
};

await fetch(preparedRequest.url, {
  method: preparedRequest.method,
  headers: preparedRequest.headers,
  body: JSON.stringify(preparedRequest.body),
});

Request headers

HeaderValue
x-namefi-signerSigner address
x-namefi-signatureHex-encoded EIP-712 signature
x-namefi-eip712-typeSelected primary type

Preparing requests independently of a signer

Use the domain, per-operation type map and envelope above with an external wallet. Read Prepare Auth Requests for the operation-aware choice between anonymous, SIWE and EIP-712 requests.

The public namefi-skills repository currently provides API-key REST scripts and an MCP connection skill; its scripts are separate from this manual EIP-712 flow.

Notes

  • Prefer GET /eip712/types-for-method over copying static type definitions into your app.
  • timestamp uses Unix seconds, not milliseconds.
  • nonce should be unique per request.
  • Some operations accept more than one primary type. Choose the one that matches the payload shape you are sending.

Account-level wallet authentication uses the server's default NFT chain, matching its existing account-verification policy. Both unsigned discovery and signed proofs must supply that chain; other chains return 400 before account lookup. This does not change chain-specific action verification for an already authenticated user. Use the canonical API origin when configuring SDK signed requests (production: https://api.namefi.io). Proofs cannot be reused against another API origin.

Typed-data payloads use bounded canonical JSON: at most 16,384 UTF-16 code units, 2,048 nodes, and depth 16. Body metadata is supported on object-body operations without URL path parameters; GET/HEAD and other operations retain their existing API-key/OAuth/SIWE authentication.

On this page