---
eip: 7739
label: ERC-7739
title: Readable Typed Signatures for Smart Accounts
status: Draft
type: Standards Track
category: ERC
created: 2024-05-28
requires: 191, 712, 1271, 5267
official: https://eips.ethereum.org/EIPS/eip-7739
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7739.md
canonical: https://eips.huatuo.xyz/ko/eip-7739/
lang: ko
tldr: ERC-1271 스마트 계정을 위한 방어적 재해시 방식. 한 소유자의 서명이 그 소유자의 여러 계정 사이에서 재전송되는 것을 막으면서, 서명 대상 내용은 EIP-712 지갑에서 계속 읽을 수 있게 한다.
tags: [signatures, smart-accounts, eip-712, erc-1271, security, draft]
---

# ERC-7739: Readable Typed Signatures for Smart Accounts

> A defensive rehashing scheme which prevents signature replays across smart accounts and preserves the readability of the signed contents

**TL;DR:** ERC-1271 스마트 계정을 위한 방어적 재해시 방식. 한 소유자의 서명이 그 소유자의 여러 계정 사이에서 재전송되는 것을 막으면서, 서명 대상 내용은 EIP-712 지갑에서 계속 읽을 수 있게 한다.

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

스마트 계정은 [ERC-1271](/eip-1271/)의 `isValidSignature(hash, signature)`로 서명을 검증합니다. 단순한 구현은 계정 소유자가 `hash`에 서명했는지만 확인합니다. 하나의 EOA가 여러 스마트 계정을 소유하고 있고 애플리케이션의 `hash`에 계정 주소가 들어 있지 않다면(실제로 흔하며, 명세에서는 Permit2를 예로 듭니다), 계정 A를 위해 만든 서명은 계정 B에서도 똑같이 유효합니다. 이것이 재전송 공격입니다.

계정은 재해시로 스스로를 방어할 수 있습니다. 서명을 확인하기 전에 자신의 주소와 체인 ID를 해시에 섞는 것입니다. 하지만 단순하게 하면 지갑이 사용자에게 알아볼 수 없는 32바이트 해시에 서명하라고 요청하게 되어 피싱 위험이 있습니다. ERC-7739는 중첩된 [EIP-712](/eip-712/) 구조체로 구성한 재해시 방식을 정의해, 지갑이 사람이 읽을 수 있는 원래 메시지를 계속 보여 줄 수 있게 합니다.

## 어떻게 동작하나요?

`isValidSignature`는 시그니처를 그대로 유지하면서 두 가지 워크플로 중 하나를 실행합니다.

**TypedDataSign**(앱의 해시가 EIP-712인 경우). 사용자는 *앱의* 도메인 아래에서 래퍼 구조체에 서명합니다.

```
TypedDataSign(<Contents> contents, string name, string version,
              uint256 chainId, address verifyingContract, bytes32 salt)<ContentsType>
```

여기서 name/version/chainId/verifyingContract/salt 필드는 *계정의* [ERC-5267](/eip-5267/) `eip712Domain()`에서 가져옵니다. 원래 구조체가 중첩 필드이므로 지갑은 이를 평소처럼 표시하고, 계정 주소가 안에 들어 있으므로 서명은 해당 계정에서만 동작합니다.

온체인으로 전달되는 서명은 다음과 같이 패킹됩니다.

```
originalSignature ‖ APP_DOMAIN_SEPARATOR ‖ contentsHash ‖ contentsDescription ‖ uint16(len)
```

계정은 먼저 `hash == keccak256(0x1901 ‖ APP_DOMAIN_SEPARATOR ‖ contentsHash)`를 확인한 다음, 래퍼 해시를 다시 만들어 그것에 대해 서명을 검증합니다. 타입 이름 주입 수법을 막기 위해 `contentsName`은 정제해야 합니다(비어 있지 않을 것, 소문자나 `(`로 시작하지 않을 것, `, )`나 NUL을 포함하지 않을 것).

**PersonalSign**(앱의 해시가 [EIP-191](/eip-191/) 개인 메시지인 경우). 사용자는 *계정의* 도메인 아래에서 `PersonalSign(bytes prefixed)`에 서명하며, `prefixed`에는 원래 해시를 넣습니다. 서명에는 아무것도 덧붙이지 않습니다.

덧붙은 데이터로 `hash`를 재구성할 수 있으면 계정은 TypedDataSign을 사용해야 하고, 그렇지 않으면 PersonalSign을 사용합니다. 오프체인 호출이거나 `hash`가 이미 계정 주소를 포함해 커밋하고 있다면 재해시를 생략할 수 있습니다.

**감지:** `isValidSignature(0x7739…7739, "")`는 `0x77390001`을 반환해야 합니다.

## 샘플 코드

스마트 계정용 TypedDataSign 서명 만들기(ethers v6):

```ts
import { TypedDataEncoder, solidityPacked, toUtf8Bytes } from "ethers";

const appDomain = { name: "MailApp", version: "1", chainId: 1, verifyingContract: appAddr };
const mailTypes = { Mail: [{ name: "from", type: "address" }, { name: "to", type: "address" },
                           { name: "message", type: "string" }] };
const mail = { from: alice, to: bob, message: "hi" };

// Account's own domain, read from eip712Domain() (ERC-5267)
const [, name, version, chainId, verifyingContract, salt] = await account.eip712Domain();

const types = {
  TypedDataSign: [
    { name: "contents", type: "Mail" }, { name: "name", type: "string" },
    { name: "version", type: "string" }, { name: "chainId", type: "uint256" },
    { name: "verifyingContract", type: "address" }, { name: "salt", type: "bytes32" },
  ],
  ...mailTypes,
};
const sig = await owner.signTypedData(appDomain, types,
  { contents: mail, name, version, chainId, verifyingContract, salt });

const contentsType = "Mail(address from,address to,string message)";
const wrapped = solidityPacked(
  ["bytes", "bytes32", "bytes32", "bytes", "uint16"],
  [sig, TypedDataEncoder.hashDomain(appDomain),
   TypedDataEncoder.hashStruct("Mail", mailTypes, mail),
   toUtf8Bytes(contentsType), toUtf8Bytes(contentsType).length],
);
// The app then calls account.isValidSignature(TypedDataEncoder.hash(appDomain, mailTypes, mail), wrapped)
```

## 알아둘 점

- **상태: Draft.** 지원 여부를 나타내는 매직 값 같은 세부 사항은 바뀔 수 있습니다(이전 초안에서는 `0xd620c85a`를 반환하는 `supportsNestedTypedDataSign()`을 썼습니다).
- 이 방식을 쓰는 계정은, 그 자신의 서명자가 같은 방식을 쓸 수 없습니다. 중첩된 `TypedDataSign` 타입은 하나의 EIP-712 요청으로 표현할 수 없기 때문입니다.
- 명세의 레퍼런스 구현은 의도적으로 모든 기능을 갖추고 있습니다. 최소 버전이 안전하다고 가정하지 마세요. ERC-1271에서 그런 실수가 있었습니다.
- 애플리케이션 컨트랙트는 바뀌지 않으며 서명 요청만 래핑됩니다. 명세는 지갑이나 프런트엔드가 업데이트되지 않아도 클라이언트 측 JavaScript를 주입하는 방식으로 동작할 수 있다고 밝힙니다.


---

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