---
eip: 1056
label: ERC-1056
title: Ethereum Lightweight Identity
status: Stagnant
type: Standards Track
category: ERC
created: 2018-05-03
official: https://eips.ethereum.org/EIPS/eip-1056
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1056.md
canonical: https://eips.huatuo.xyz/zh/eip-1056/
lang: zh
tldr: 一个共享的注册表合约，把每个以太坊地址变成免费且兼容 DID 的身份，支持所有者轮换、有时限的委托密钥，以及以事件形式存储的属性。
tags: [identity, did, registry, delegation]
---

# ERC-1056: Ethereum Lightweight Identity

> A registry for key and attribute management of lightweight blockchain identities.

**TL;DR:** 一个共享的注册表合约，把每个以太坊地址变成免费且兼容 DID 的身份，支持所有者轮换、有时限的委托密钥，以及以事件形式存储的属性。

## 它解决什么问题？

此前的身份提案（如 [ERC-725](/eip-725/)）为每个用户提供各自的身份合约。部署合约需要 gas，因此创建身份成本很高，也无法离线完成。提出这个 ERC 的 uPort 团队希望身份满足：

- 创建不花钱，并且可以离线使用，例如在难民场景中，
- 轮换密钥时保持标识符不变，
- 既能在链上使用，也能在链下使用。

ERC-1056 通过**默认把任何以太坊地址都当作身份**来满足这些要求。一个共享的注册表合约只存储变更。

## 它如何运作

只需部署一次 `EthereumDIDRegistry` 合约，所有人共用。对于每个身份（一个地址），它跟踪：

- **所有者。** 默认情况下，身份拥有它自己。`changeOwner(identity, newOwner)` 让你在不改变标识符的前提下轮换到新密钥或多签。
- **委托者（delegate）。** `addDelegate(identity, delegateType, delegate, validity)` 为某种用途（例如签署 JWT）授权另一个密钥，有效期为 `validity` 秒。`validDelegate(...)` 用于检查，`revokeDelegate` 用于移除。
- **属性。** `setAttribute(identity, name, value, validity)` 发布服务端点或加密密钥之类的数据。`revokeAttribute` 将其移除。

每个写入函数都有一个 `…Signed` 变体，接受所有者的原始 `(v, r, s)` 签名，因此第三方可以代付 gas。

为了节省 gas，委托者和属性主要以**事件**（`DIDOwnerChanged`、`DIDDelegateChanged`、`DIDAttributeChanged`）的形式记录。每个事件都包含 `previousChange`，即该身份上一次更新所在的区块，合约把最新的一个存在 `changed[identity]` 中。解析器沿着这些相互链接的区块向前回溯，以较低成本重建完整历史，然后组装出 W3C **DID 文档**。

## 示例代码

添加一个有效期 30 天的签名委托者（ethers v6）。`REGISTRY` 是你所在网络上已部署的注册表地址：

```ts
import { Contract, Wallet, JsonRpcProvider, encodeBytes32String } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const owner = new Wallet(process.env.PRIVATE_KEY!, provider);

const registry = new Contract(REGISTRY, [
  "function addDelegate(address identity, bytes32 delegateType, address delegate, uint validity)",
  "function validDelegate(address identity, bytes32 delegateType, address delegate) view returns (bool)",
  "function changed(address) view returns (uint)",
], owner);

const delegate = Wallet.createRandom().address;
const type = encodeBytes32String("veriKey");

await (await registry.addDelegate(owner.address, type, delegate, 30 * 24 * 3600)).wait();
console.log(await registry.validDelegate(owner.address, type, delegate)); // true
```

## 需要注意

- 该 ERC 处于 **Stagnant** 状态，从未达到 Final。它的参考实现成为 `did:ethr` DID 方法（`ethr-did-registry`、`ethr-did-resolver`）的基础。
- 规范把具体的委托类型和属性名称留作"待定"（to be determined）。实际的解析器遵循 `did:ethr` 方法规范中定义的约定。
- 通过事件发布的数据是公开且永久的。切勿把个人数据放进属性。
- 委托者会自动过期，但提前撤销仍然需要发送一笔交易。
- 相关的身份工作包括 [ERC-725](/eip-725/)（Draft）和 [ERC-1812](/eip-1812/)（Stagnant）。


---

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