---
eip: 8143
label: ERC-8143
title: Smart Credential Resolution Interface
status: Draft
type: Standards Track
category: ERC
created: 2025-12-15
requires: 165, 3668
official: https://eips.ethereum.org/EIPS/eip-8143
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8143.md
canonical: https://eips.huatuo.xyz/zh/eip-8143/
lang: zh
tldr: 一个只有一个函数 `getCredential(key)` 的合约接口，让钱包、应用和 AI 智能体可以用统一的方式查询由发行方控制的凭证，例如 KYC、真人证明或信誉，可以在链上进行，也可以通过 CCIP-Read 进行。
tags: [identity, credentials, kyc, agents, ccip-read]
---

# ERC-8143: Smart Credential Resolution Interface

> Resolve credentials.

**TL;DR:** 一个只有一个函数 `getCredential(key)` 的合约接口，让钱包、应用和 AI 智能体可以用统一的方式查询由发行方控制的凭证，例如 KYC、真人证明或信誉，可以在链上进行，也可以通过 CCIP-Read 进行。

## 它解决什么问题？

关于用户的某些事实，不应由该用户自己控制："此人通过了 KYC"、"此账户属于唯一的真人"、"这个 AI 智能体的信誉分是 95"。这类记录由第三方**发行方**写入，而不是由用户写入。

发行方已经可以从合约发布数据，包括通过 [ERC-3668](/eip-3668/)（CCIP-Read）发布的链下数据。但每个发行方的暴露方式各不相同，客户端只能逐个手动集成。ERC-8143 标准化了一个最小接口，使任何客户端（包括自主智能体）都能解析凭证，甚至通过监听标准事件来发现新的凭证。在规范中，"用户"既指人类，也指 AI 智能体。

## 它如何运作

Smart Credential 合约实现：

- `getCredential(string key) returns (bytes)`，用于获取凭证。
- `event CredentialSet(string key)`，每当凭证被设置或更新时触发，使客户端无需事先知道就能发现新的 key。
- [ERC-165](/eip-165/) 的 `supportsInterface`，对接口 ID `0xd091187f` 返回 true。

该标准有意**不**规定 key 的格式，也不规定返回字节的编码。每个发行方自行定义并公开文档。key 可以遵循 [ERC-8119](/eip-8119/) 的参数化风格（`kyc:0xabc…`、`pop/0xabc…`），但这是可选的。如果客户端不知道某个 key 的格式，应把这些字节当作原始 UTF-8。

对于链下数据，`getCredential` 可以用 ERC-3668 的 `OffchainLookup` 进行 revert。合规的客户端必须遵循 CCIP-Read 流程：先从网关获取，再调用合约的回调，由回调在返回之前验证响应（签名、Merkle 证明、ZK 证明等）。

## 示例代码

接口和一个简单的链上发行方：

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

interface IERC8143 {
    event CredentialSet(string key);
    function getCredential(string calldata key) external view returns (bytes memory result);
}

contract SimpleIssuer is IERC8143 {
    address public immutable issuer = msg.sender;
    mapping(string => bytes) private creds;

    function setCredential(string calldata key, bytes calldata value) external {
        require(msg.sender == issuer, "not issuer");
        creds[key] = value;
        emit CredentialSet(key);
    }

    function getCredential(string calldata key) external view returns (bytes memory) {
        return creds[key];
    }

    function supportsInterface(bytes4 id) external pure returns (bool) {
        return id == 0xd091187f || id == 0x01ffc9a7; // ERC-8143, ERC-165
    }
}
```

在客户端用 ethers v6 解析（`enableCcipRead` 会跟进 ERC-3668 的 revert）：

```ts
import { Contract, AbiCoder } from "ethers";

const c = new Contract(issuerAddr, ["function getCredential(string) view returns (bytes)"], provider);
const raw = await c.getCredential(`pop:${user}`, { enableCcipRead: true });
const [isHuman] = AbiCoder.defaultAbiCoder().decode(["bool"], raw); // format defined by issuer
```

## 需要注意

- **状态：Draft。** 接口可能变化。
- 凭证的可信度不会超过其发行方。在依赖任何结果之前，客户端应先决定信任哪些发行方合约。
- 你无法猜出凭证的编码；请针对每个 key 查阅发行方的文档。
- 把 KYC 记录等个人数据放到链上是永久且公开的。保护隐私的设计（通过 CCIP-Read 进行链下存储，或规范明确希望支持的零知识证明）值得考虑。


---

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