---
eip: 5267
label: ERC-5267
title: Retrieval of EIP-712 domain
status: Final
type: Standards Track
category: ERC
created: 2022-07-14
requires: 155, 712, 2612
official: https://eips.ethereum.org/EIPS/eip-5267
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5267.md
canonical: https://eips.huatuo.xyz/ko/eip-5267/
lang: ko
tldr: 표준 `eip712Domain()` 조회 함수를 추가해 지갑과 앱이 컨트랙트가 사용하는 EIP-712 도메인을 정확히 읽을 수 있게 한다. 맞춤 코드 없이도 어떤 컨트랙트에 대해서든 올바른 타입 데이터 서명(permit 등)을 만들 수 있다.
tags: [signatures, eip-712, permit, wallets]
---

# ERC-5267: Retrieval of EIP-712 domain

> A way to describe and retrieve an EIP-712 domain to securely integrate EIP-712 signatures.

**TL;DR:** 표준 `eip712Domain()` 조회 함수를 추가해 지갑과 앱이 컨트랙트가 사용하는 EIP-712 도메인을 정확히 읽을 수 있게 한다. 맞춤 코드 없이도 어떤 컨트랙트에 대해서든 올바른 타입 데이터 서명(permit 등)을 만들 수 있다.

## 어떤 문제를 해결하나요?

[EIP-712](/eip-712/) 타입 데이터 서명에는 *도메인*(name, version, chain ID, verifying contract, salt)이 포함되어, 서명이 한 체인의 한 컨트랙트에서만 유효하게 됩니다. 하지만 EIP-712는 컨트랙트가 어떤 도메인 필드를 쓰고 그 값이 무엇인지 어떻게 알릴지는 정하지 않았습니다.

[ERC-2612](/eip-2612/) `permit`이 있는 컨트랙트는 `DOMAIN_SEPARATOR()`를 노출하지만, 이는 해시일 뿐입니다. 앱은 이를 `eth_signTypedData_v4`가 필요로 하는 도메인 객체로 되돌릴 수 없고, 지갑도 사용자에게 무엇에 서명하는지 보여줄 수 없습니다. 그래서 모든 연동이 토큰마다 도메인을 하드코딩했습니다. ERC-5267은 표준 getter 하나로 이를 해결합니다.

## 어떻게 동작하나요?

준수하는 컨트랙트는 다음을 정확히 구현합니다.

```solidity
function eip712Domain() external view returns (
    bytes1 fields,
    string name,
    string version,
    uint256 chainId,
    address verifyingContract,
    bytes32 salt,
    uint256[] extensions
);
```

- `fields`는 어떤 도메인 필드가 있는지 나타내는 비트맵입니다. 비트 0 = `name`, 1 = `version`, 2 = `chainId`, 3 = `verifyingContract`, 4 = `salt`. 예를 들어 `0x0f`는 name, version, chainId, verifyingContract를 뜻합니다.
- 모든 값은 항상 반환되지만(ABI가 디코딩되도록), `fields`에 표시된 것만 의미가 있습니다.
- `extensions`는 도메인 필드를 추가하는 EIP 번호를 나열합니다. 이해하지 못하는 항목이 있으면 클라이언트는 진행을 거부해야 합니다.
- 도메인은 시간이 지나며 바뀔 수 있습니다(예: 포크 후의 `chainId`, [EIP-155](/eip-155/) 참고). 컨트랙트는 이를 알리기 위해 `EIP712DomainChanged()`를 발생시킬 수 있습니다.

## 샘플 코드

ethers v6로 도메인을 만들고 permit에 서명하기:

```ts
import { Contract, Wallet, JsonRpcProvider, TypedDataDomain } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
const token = new Contract(process.env.TOKEN!, [
  "function eip712Domain() view returns (bytes1,string,string,uint256,address,bytes32,uint256[])",
  "function nonces(address) view returns (uint256)",
], provider);

async function getDomain(c: Contract): Promise<TypedDataDomain> {
  const [fields, name, version, chainId, verifyingContract, salt, ext] = await c.eip712Domain();
  if (ext.length) throw new Error("unsupported EIP-712 domain extensions");
  const f = Number(fields);
  const d: TypedDataDomain = {};
  if (f & 1) d.name = name;
  if (f & 2) d.version = version;
  if (f & 4) d.chainId = chainId;
  if (f & 8) d.verifyingContract = verifyingContract;
  if (f & 16) d.salt = salt;
  return d;
}

const domain = await getDomain(token);
const types = { Permit: [
  { name: "owner", type: "address" }, { name: "spender", type: "address" },
  { name: "value", type: "uint256" }, { name: "nonce", type: "uint256" },
  { name: "deadline", type: "uint256" },
]};
const sig = await wallet.signTypedData(domain, types, {
  owner: wallet.address, spender: process.env.SPENDER!, value: 1000n,
  nonce: await token.nonces(wallet.address), deadline: 2n ** 32n,
});
```

Solidity에서는 OpenZeppelin의 `EIP712` 베이스 컨트랙트가 `eip712Domain()`을 대신 구현해 줍니다.

## 알아둘 점

- 상태는 **Final**입니다.
- 사용자에게 서명을 요청하기 전에, 지갑과 앱은 반환된 `chainId`와 `verifyingContract`가 현재 체인 및 컨트랙트와 일치하는지 확인해야 합니다. 명세는 둘이 다른 것을 허용하므로 악용될 수 있습니다.
- 오래된 불변 컨트랙트에는 이 함수를 추가할 수 없습니다. 명세는 하드코딩된 도메인으로 폴백하거나, 흔한 도메인을 추측해 컨트랙트의 `DOMAIN_SEPARATOR()`와 해시가 일치하는 것을 확인하라고 제안합니다.
- `fields`는 `bytes1`입니다. 위 코드처럼 비트 마스크를 적용하기 전에 숫자로 변환하세요.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5267
