EIPs Explained

ERC-6662 · Draft(草案) · ERC · 2023-03-09

ERC-6662: AA Account Metadata For Authentication

ERC-4337 的草案扩展:智能账户在链上公布其认证器所在位置和接受的请求格式,使 dApp 无需预先连接钱包即可请求签名。

它解决什么问题?

如今,dApp 只有在你"连接钱包"之后才知道你的账户:钱包把你的地址推送给网站,所有签名请求都通过这条实时连接返回。对于智能合约账户(ERC-4337),真正授权操作的可以是任何东西:手机应用、云端签名服务、硬件设备。dApp 没有标准方式去发现它。

ERC-6662 让账户把认证信息一次性公布在链上。只要知道你的账户地址,dApp 就能查到应该把签名请求发到哪里、用什么格式。

它如何运作

涉及三种角色:

  • Authenticator(认证器):持有为你的用户操作签名的密钥的任何东西(手机应用、在线服务等)。
  • Relay(中继):把 dApp 的请求转发给认证器的在线服务。在线认证器可以兼作自己的中继。
  • dApp:读取账户的元数据,并向中继发送 AuthenticationRequest。

智能账户在 ERC-4337 的 IAccount 之外还实现 IAccountMetadata:

  • getAuthenticationInfo() 返回 AuthenticatorInfo { string[] relayURI; string schema; } 的列表。
  • relayURI 列出中继端点;dApp 按顺序尝试,使用第一个可用的。
  • schema 是描述 AuthenticationRequest 的 JSON Schema(内联,或 URI;若存储在链上则使用 ERC-4804 的 web3://)。典型的请求包含入口点地址、链 ID 和未签名的 UserOperation。

多个 AuthenticatorInfo 条目可以实现多重签名:每个认证器独立签名,再由 ERC-4337 聚合器合并签名。

示例代码

接口以及 dApp 端的查询(ethers v6):

interface IAccountMetadata {
    struct AuthenticatorInfo {
        string[] relayURI; // where to send requests
        string schema;     // JSON schema or URI for AuthenticationRequest
    }
    function getAuthenticationInfo() external view returns (AuthenticatorInfo[] memory);
}
import { Contract } from "ethers";

const account = new Contract(smartAccountAddr, [
  "function getAuthenticationInfo() view returns ((string[] relayURI, string schema)[])",
], provider);

const [first] = await account.getAuthenticationInfo();
const request = {
  entrypoint: ENTRYPOINT_ADDRESS,
  chainId: "0x1",
  userOp: unsignedUserOp, // ERC-4337 UserOperation without signature
};
for (const uri of first.relayURI) {
  const res = await fetch(uri, { method: "POST", body: JSON.stringify(request) });
  if (res.ok) break; // first working relay wins
}

需要注意

  • 状态:Draft。 中继协议、传输方式以及 dApp 自身的认证都没有标准化;schema 由账户自行定义。
  • 中继可以看到请求内容。规范建议使用端到端加密,例如 JWE,并把内容密钥加密给签名者,这样中继既无法读取也无法抢跑。
  • 链上元数据是公开的:公布中继 URI 会暴露哪些服务在支撑你的账户。
  • 示例中的请求字段遵循规范里的示例 schema;实际的账户可能要求不同的字段。

#account-abstraction #authentication #erc4337 #smart-account #metadata

详细信息

作者
Shu Dong (@dongshu2013), Zihao Chen (@zihaoccc), Peter Chen (@pette1999)
状态
Draft(草案)
类型
Standards Track / ERC
创建日期
2023-03-09
依赖的提案

机器可读数据: Markdown · JSON