EIPs Explained

ERC-5131 · Stagnant · ERC · 2022-06-03

ERC-5131: SAFE Authentication For ENS

Uses ENS text records to link a cold "main" wallet to one or more hot signing wallets, so you can prove ownership of the main wallet's assets without ever signing with it.

What problem does it solve?

Many dApps ask you to sign a message with the wallet that holds an NFT or token: to edit a profile, enter gated content, claim an airdrop or prove ownership at an event. If that wallet is a hardware wallet or multisig, this is inconvenient. Worse, it means exposing your most valuable wallet to every site you visit, where one malicious signature can drain it.

These actions are really "read-only" proofs. ERC-5131 lets a separate, low-value wallet authenticate on behalf of the main wallet, using ENS records you already control rather than a new registry contract.

How it works

Terms:

  • mainAddress: the vault wallet whose assets you want to prove; its reverse ENS name is mainENS.
  • authAddress: the hot wallet that will sign; its reverse ENS name is authENS.
  • authKey: any alphanumeric label you choose.

Setup (both addresses need ENS resolver and reverse records, per EIP-137 and EIP-181):

  1. On mainENS, set text record eip5131:<authKey> = authAddress.
  2. On authENS, set text record eip5131:vault = <authKey>:<mainAddress>.

Text records come from EIP-634. The link is two-sided, so neither wallet can claim the other alone.

Verification, when authAddress signs or sends a transaction:

  1. Look up authENS and read its eip5131:vault record.
  2. Split it into authKey and mainAddress.
  3. Reverse-resolve mainAddress and confirm it matches mainENS (this stops someone pointing a different ENS name at your vault).
  4. Read eip5131:<authKey> on mainENS and confirm it equals authAddress.

If all checks pass, the app treats the signer as controlling mainAddress. One main wallet can authorise many auth wallets; each auth wallet links to at most one main wallet. Revocation is simply deleting or changing the eip5131:<authKey> record on mainENS.

Sample code

Client-side check with ethers v6:

import { JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);

export async function getLinkedVault(signer: string) {
  const authENS = await provider.lookupAddress(signer);
  if (!authENS) return null;

  const vaultInfo = await (await provider.getResolver(authENS))?.getText("eip5131:vault");
  if (!vaultInfo) return null;

  const parts = vaultInfo.split(":");
  if (parts.length !== 2) throw new Error("malformed eip5131:vault record");
  const [authKey, mainAddress] = parts;

  const mainENS = await provider.lookupAddress(mainAddress);
  if (!mainENS) throw new Error("vault has no reverse ENS record");

  const expected = await (await provider.getResolver(mainENS))?.getText(`eip5131:${authKey}`);
  if (expected?.toLowerCase() !== signer.toLowerCase()) {
    throw new Error("authentication link mismatch");
  }
  return { ens: mainENS, address: mainAddress };
}

The spec also includes a Solidity library that performs the same checks on-chain against the ENS registry and resolvers.

Things to know

  • Status: Stagnant.
  • There is no on-chain interface to implement: verification can be done in a contract, a backend or the browser. A backend result can be combined with ERC-1271-style signature validation.
  • Setting ENS records costs gas, including on the hot wallet, which needs a little ETH for its reverse record.
  • It authorises proofs of ownership, not spending. The hot wallet cannot move the vault's assets, which is the point.
  • Apps must perform the reverse-record check in step 3; skipping it makes spoofing possible. For generic wallet login, see Sign-In with Ethereum, ERC-4361.

#ens #authentication #wallet #security #delegation

Details

Authors
Wilkins Chung (@wwhchung) <[email protected]>, Jalil Wahdatehagh (@jwahdatehagh), Cry (@crydoteth), Sillytuna (@sillytuna), Cyberpnk (@CyberpnkWin)
Status
Stagnant
Type
Standards Track / ERC
Created
2022-06-03
Requires

Machine-readable: Markdown · JSON