EIPs Explained

ERC-7754 · Draft · ERC · 2024-07-29

ERC-7754: Tamperproof Extension Wallets API (TWIST)

Proposes a wallet_signedRequest RPC so a dapp can sign its wallet requests with a key published under its domain, letting browser-extension wallets detect requests tampered with by injected scripts.

What problem does it solve?

A dapp talks to an extension wallet through JavaScript running in the page (the EIP-1193 provider). Anything else that runs in that page, such as an XSS payload or a malicious browser extension, can intercept those requests and quietly change them: swap the calldata to drain funds, alter EIP-712 parameters, or obtain a replayable signature. The wallet has no way to know the request is not what the dapp sent.

TWIST (Tamperproof Web Immutable Secure Transaction) gives dapps a way to sign their requests so the wallet can verify integrity, comparable to how HTTPS protects the channel between browser and server.

How it works

  1. Publish keys. The dapp adds a DNS TXT record such as TWIST=/.well-known/twist.json, pointing to a JSON manifest on its own domain listing public keys: { id, alg, publicKey }. Keys are hex-encoded X.509 SPKI (DER). Wallets must support at least ES256 and EdDSA.
  2. Sign requests. The dapp's backend signs the request payload { method, params } with the matching private key.
  3. Send signed. The dapp calls wallet_signedRequest with [requestPayload, signature, keyId].
  4. Verify. The wallet fetches the manifest over HTTPS from the tab's own domain, never following redirects and checking Content-Type: application/json. It looks up the key by keyId, verifies the signature, and if valid processes requestPayload normally.

If a domain has TWIST configured but a plain request arrives, or the signature fails, the wallet shows an actionable warning; the user can cancel or proceed. Domains without TWIST behave as before. Wallets should not cache dapp keys for more than two hours, since there is no revocation mechanism.

Sample code

Dapp side, using the EIP-1193 provider:

type RequestPayload<P> = { method: string; params: P };

const requestPayload: RequestPayload<unknown[]> = {
  method: "eth_sendTransaction",
  params: [{ from: account, to: target, data: calldata }],
};

// Signed by your backend with the private key whose public half is in twist.json
const { signature, keyId } = await fetch("/api/twist-sign", {
  method: "POST",
  body: JSON.stringify(requestPayload),
}).then((r) => r.json());

const txHash = await window.ethereum.request({
  method: "wallet_signedRequest",
  params: [requestPayload, signature, keyId],
});

Manifest at https://my-dapp.example/.well-known/twist.json:

{
  "publicKeys": [
    { "id": "1", "alg": "ES256", "publicKey": "0x3059..." }
  ]
}

Things to know

  • Status is Draft; the method name and verification steps may change, and wallet support should not be assumed.
  • TWIST protects integrity, not replay. The spec relies on transaction nonces and EIP-712 domain separation for that, and leaves read-only methods unprotected.
  • Signing must happen somewhere the attacker cannot reach, typically a backend. A signing key exposed to page JavaScript defeats the purpose.
  • The scheme trusts the dapp's domain and TLS certificate; if the domain itself is compromised, so is the manifest.

#wallet #security #rpc #extension #dapp

Details

Authors
Erik Marks (@remarks), Guillaume Grosbois (@uni-guillaume)
Status
Draft
Type
Standards Track / ERC
Created
2024-07-29
Requires

Machine-readable: Markdown · JSON