ERC-2520: 用于 ENS 的多重 contenthash 记录
Authors | Filip Štamcar (@filips123) |
---|---|
Created | 2020-02-18 |
Discussion Link | https://github.com/ethereum/EIPs/issues/2393 |
Requires | EIP-1577 |
简单总结
ENS 支持在单个 ENS 名称上使用多个 contenthash
记录。
动机
许多应用程序正在将 ENS 名称解析为托管在分布式系统上的内容。为此,他们使用来自 ENS 域的 contenthash
记录来了解如何解析名称以及应使用哪个分布式系统。
但是,该域只能存储一个 contenthash
记录,这意味着站点所有者需要决定使用哪个托管系统。由于有许多与 ENS 兼容的托管系统可用(IPFS,Swarm,最近的 Onion 和 ZeroNet),并且将来可能会有更多,因此缺少对多个记录的支持可能会成为问题。相反,域应该能够存储多个 contenthash
记录,以允许应用程序解析为多个托管系统。
规范
设置和获取函数 必须 具有与 EIP 1577 中指定的相同的公共接口。此外,它们必须还具有此 EIP 引入的新的公共接口:
-
为了设置
contenthash
记录,setContenthash
必须提供额外的proto
参数,并使用它来保存contenthash
。 当未提供proto
时,必须将记录保存为默认记录。function setContenthash(bytes32 node, bytes calldata proto, bytes calldata hash) external authorised(node);
-
为了获取
contenthash
记录,contenthash
必须提供额外的proto
参数,并使用它来获取请求类型的contenthash
。 当未提供proto
时,必须返回默认记录。function contenthash(bytes32 node, bytes calldata proto) external view returns (bytes memory);
-
支持多个
contenthash
记录的解析器,必须为具有接口 ID0x6de03e07
的supportsInterface
返回true
。
使用 ENS contenthash
记录的应用程序应按以下方式处理它们:
-
如果应用程序仅支持一个托管系统(例如直接从 IPFS/Swarm 网关处理 ENS),则它应请求具有特定类型的
contenthash
。 然后,合约必须返回它,并且应用程序应正确处理它。 -
如果应用程序支持多个托管系统(例如 MetaMask),则它应请求没有特定类型的
contenthash
(例如在 EIP 1577 中)。 然后,合约必须返回默认的contenthash
记录。
基本原理
选择提议的实现是因为它易于实现并且支持所有重要的请求功能。 但是,它不支持同一类型的多个记录和优先级顺序,因为它们没有带来太多优势并且更难以正确实现。
向后兼容性
该 EIP 与 EIP 1577 向后兼容,唯一的区别是附加的重载方法。 旧的应用程序仍然可以正常运行,因为它们将收到默认的 contenthash
记录。
实施
contract ContentHashResolver {
bytes4 constant private MULTI_CONTENT_HASH_INTERFACE_ID = 0x6de03e07;
mapping(bytes32=>mapping(bytes=>bytes)) hashes;
function setContenthash(bytes32 node, bytes calldata proto, bytes calldata hash) external {
hashes[node][proto] = hash;
emit ContenthashChanged(node, hash);
}
function contenthash(bytes32 node, bytes calldata proto) external view returns (bytes memory) {
return hashes[node][proto];
}
function supportsInterface(bytes4 interfaceID) public pure returns(bool) {
return interfaceID == MULTI_CONTENT_HASH_INTERFACE_ID;
}
}
安全注意事项
待定
版权
通过 CC0 放弃版权及相关权利。
Citation
Please cite this document as:
Filip Štamcar (@filips123), "ERC-2520: 用于 ENS 的多重 contenthash 记录 [DRAFT]," Ethereum Improvement Proposals, no. 2520, February 2020. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2520.