---
eip: 7962
label: ERC-7962
title: Key Hash Based Tokens
status: Review
type: Standards Track
category: ERC
created: 2025-05-16
requires: 20, 712, 721, 5267
official: https://eips.ethereum.org/EIPS/eip-7962
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7962.md
canonical: https://eips.huatuo.xyz/zh/eip-7962/
lang: zh
tldr: 以公钥的 keccak256 而非地址来标识所有者的代币接口（KeyHash20 和 KeyHash721），持仓不与可见地址绑定，任何人都可以中继已签名的转账并支付 gas。
tags: [token, privacy, nft, eip-712, gas-sponsorship]
---

# ERC-7962: Key Hash Based Tokens

> Extends privacy to ERC-721 and ERC-20 tokens.

**TL;DR:** 以公钥的 keccak256 而非地址来标识所有者的代币接口（KeyHash20 和 KeyHash721），持仓不与可见地址绑定，任何人都可以中继已签名的转账并支付 gas。

## 它解决什么问题？

在 [ERC-20](/eip-20/) 和 [ERC-721](/eip-721/) 中，所有者是一个地址。地址是公开的、会被重复使用，并且很容易在不同应用和链之间与身份关联起来。持有代币的地址还必须发送交易并支付 gas。

ERC-7962 用 **keyHash** 取代所有者地址：`keccak256(key)`，其中 `key` 是 65 字节的未压缩 secp256k1 公钥。链上不存储任何地址。所有者通过出示公钥以及对应私钥的 [EIP-712](/eip-712/) 签名来证明控制权，而**任何**账户都可以提交这笔转账，因此中继者或赞助方可以支付 gas。这一思路沿袭了隐身地址（[ERC-5564](/eip-5564/)）的隐私方向。

## 它如何运作

**KeyHash721（NFT）。** `ownerOf(tokenId)` 返回一个 `bytes32` 类型的 keyHash。`transfer(tokenId, toKeyHash, key, signature, deadline)` 会检查 `keccak256(key)` 是否等于当前所有者的哈希、签名是否来自由 `key` 推导出的地址，以及截止时间是否未过。

**KeyHash20（同质化）。** `balanceOf(bytes32 keyHash)`。转账方式类似比特币的 UTXO：`transfer(fromKeyHash, toKeyHash, amount, key, signature, deadline, leftKeyHash)` 会清空 `fromKeyHash`，把 `amount` 发给接收方，把剩余部分（"找零"）发到 `leftKeyHash`。找零哈希必须与 `from` 和 `to` 都不同，因此任何余额始终位于公钥尚未被公开的密钥之下。

通用规则：

- 签名使用 EIP-712，带有每个 keyHash 各自的 `nonces(bytes32)` 和 `deadline`；合约必须通过 [ERC-5267](/eip-5267/) 的 `eip712Domain()` 公开域信息。
- 签名必须不可延展（`s` 取低值，`v` 为 27 或 28）。
- 没有 `approve`：密钥只打算使用一次。
- 每次余额或所有权变化都必须触发 `KeyHashTransfer721` / `KeyHashTransfer20`，这样钱包可以通过按自己控制的 keyHash 过滤日志来重建持仓。`mint` / `destroy` 是可选的，取决于具体实现。

## 示例代码

为中继者签署 KeyHash20 转账（ethers v6）：

```ts
import { Wallet, keccak256 } from "ethers";
// assumes: token (Contract), relayer (Signer), toKeyHash, leftKeyHash, amount, deadline

const owner = new Wallet(process.env.OWNER_KEY!);  // controls fromKeyHash
const key = owner.signingKey.publicKey;            // uncompressed 0x04||X||Y (65 bytes)
const fromKeyHash = keccak256(key);

const domain = await token.eip712Domain().then(([, name, version, chainId, verifyingContract]) =>
  ({ name, version, chainId, verifyingContract }));
const types = { Transfer: [
  { name: "fromKeyHash", type: "bytes32" }, { name: "toKeyHash", type: "bytes32" },
  { name: "amount", type: "uint256" },      { name: "nonce", type: "uint256" },
  { name: "deadline", type: "uint256" },    { name: "leftKeyHash", type: "bytes32" },
]};
const msg = { fromKeyHash, toKeyHash, amount, nonce: await token.nonces(fromKeyHash),
              deadline, leftKeyHash /* fresh key you control */ };
const signature = await owner.signTypedData(domain, types, msg);

// Any relayer can now submit and pay gas:
await token.connect(relayer).transfer(fromKeyHash, toKeyHash, amount, key, signature, deadline, leftKeyHash);
```

## 需要注意

- 状态：**Review**。函数签名和事件仍可能变化。
- 与 ERC-20/721 的工具不兼容：余额和所有者是 `bytes32` 而不是地址，因此现有的钱包、DEX 和市场需要适配器。
- 隐私有限。规范指出，from/to/找零哈希和金额都在 calldata 中可见，因此合约内的交易图完全可追踪，而且一旦公钥被公开，就可以推导出它的地址。它只是避免把持仓与更广泛的地址图关联起来；若要实现金额或交易图的隐私，需要零知识证明等额外工具。
- 丢失某个 keyHash 背后的私钥就意味着丢失代币；请为每个找零输出生成并备份一个新密钥。


---

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