---
eip: 6384
label: ERC-6384
title: Human-readable offline signatures
status: Stagnant
type: Standards Track
category: ERC
created: 2023-01-08
requires: 712
official: https://eips.ethereum.org/EIPS/eip-6384
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6384.md
canonical: https://eips.huatuo.xyz/zh/eip-6384/
lang: zh
tldr: 提议在验证合约上提供一个 evalEIP712Buffer view 函数，让钱包能在用户签名之前向其展示对 EIP-712 消息的通俗描述。
tags: [signatures, eip712, wallet, phishing, ux]
---

# ERC-6384: Human-readable offline signatures

> A method for retrieving a human-readable description of EIP-712 typed and structured data.

**TL;DR:** 提议在验证合约上提供一个 evalEIP712Buffer view 函数，让钱包能在用户签名之前向其展示对 EIP-712 消息的通俗描述。

## 它解决什么问题？

[EIP-712](/eip-712/) 格式的链下签名无处不在：代币 permit（[ERC-2612](/eip-2612/)）、NFT 市场挂单、订单簿。它们对用户来说不需要 gas，但签名之后可以被别人在链上使用。钓鱼网站正是利用这一点：它们让受害者签署一条消息，例如以几乎为零的价格挂出其 NFT。钱包通常显示原始的类型化字段，大多数用户无法理解，于是只能盲签。

ERC-6384 提议让最终会使用该签名的合约，用人类可读的方式解释这条消息。

## 它如何运作

EIP-712 消息已经在其 domain 中指定了 `verifyingContract`。ERC-6384 要求这类合约实现一个 `view` 函数：

```solidity
function evalEIP712Buffer(
    bytes32 domainHash,          // the EIP-712 domain separator
    string memory primaryType,   // the EIP-712 primaryType
    bytes memory typedDataBuffer // ABI-encoded message part
) external view returns (string[] memory);
```

流程：

1. dApp 请求钱包对一条 EIP-712 消息签名。
2. 钱包带着消息数据对 `verifyingContract` 调用 `evalEIP712Buffer`（免费的 `eth_call`）。
3. 合约返回一个或多个普通字符串，例如"以 0.0001 ETH 出售 NFT #1234"。钱包将其展示给用户，还可以选择性地加以丰富（例如把地址解析为名称）。

信任论证：消息来自可能是恶意的网站，但验证合约由合法的协议控制。攻击者无法换成另一个合约，因为那样的话签名在链上将不被接受。

值得了解的规则：

- 返回的是数组，因此多部分消息（多笔转账）可以逐行展示。
- 这些字符串必须被视为**不可信输入**，并以纯文本而不是 HTML 渲染。
- 如果 domain 没有 `verifyingContract`，钱包不得使用该方法，应当回退到其常规显示方式。

## 示例代码

一个描述自己 `TransferWithSig` 消息的合约（简化版）：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract MyToken {
    function evalEIP712Buffer(bytes32, string memory primaryType, bytes memory buf)
        external view returns (string[] memory out)
    {
        require(keccak256(bytes(primaryType)) == keccak256("TransferWithSig"), "unknown type");
        (address from, address to, uint256 amount, , ) =
            abi.decode(buf, (address, address, uint256, uint256, uint256));
        out = new string[](1);
        out[0] = string.concat(
            "Transfer ", Strings.toString(amount), " tokens from ",
            Strings.toHexString(from), " to ", Strings.toHexString(to)
        );
    }
}
```

钱包一侧（ethers v6）：

```ts
const c = new Contract(domain.verifyingContract, [
  "function evalEIP712Buffer(bytes32,string,bytes) view returns (string[])",
], provider);
const lines: string[] = await c.evalEIP712Buffer(domainHash, primaryType, encodedMessage);
lines.forEach((l) => ui.appendText(l)); // render as plain text
```

## 需要注意

- **状态：Stagnant。** 已知实现它的合约或钱包很少；不要依赖它一定可用。
- 只有在验证合约诚实时它才有帮助。恶意合约可能返回具有误导性的文字，但规范认为，这样的合约即使没有这个函数也已经能造成危害。
- 描述的准确程度取决于合约自身的解码代码，并且每支持一种消息类型都会增加合约体积。
- [ERC-5267](/eip-5267/) 是一个相关的 Final 标准，让钱包可以获取合约的 EIP-712 domain。


---

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