---
eip: 2386
label: ERC-2386
title: Ethereum 2 Hierarchical Deterministic Walletstore
status: Stagnant
type: Standards Track
category: ERC
created: 2019-11-21
requires: 2334, 2335
official: https://eips.ethereum.org/EIPS/eip-2386
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2386.md
canonical: https://eips.huatuo.xyz/zh/eip-2386/
lang: zh
tldr: "一种 JSON \"walletstore\" 格式，为以太坊共识层（BLS）密钥保存加密的 HD 种子和下一个密钥索引，使验证者钱包可以在不同工具之间迁移。"
tags: [wallet, keystore, validator, bls, json]
---

# ERC-2386: Ethereum 2 Hierarchical Deterministic Walletstore

> A JSON format for the storage and retrieval of Ethereum 2 hierarchical deterministic (HD) wallet definitions.

**TL;DR:** 一种 JSON "walletstore" 格式，为以太坊共识层（BLS）密钥保存加密的 HD 种子和下一个密钥索引，使验证者钱包可以在不同工具之间迁移。

## 它解决什么问题？

[EIP-2335](/eip-2335/) 标准化了 *keystore*：共识层验证者使用的、保存单个 BLS 私钥的加密 JSON 文件。但分层确定性（HD）钱包并不存储单个密钥，它存储的是一个**种子**，并沿着某条路径从中派生密钥。为了在不重复使用旧密钥的前提下创建下一个密钥，钱包还需要记住自己走到了哪个索引。

没有标准时，各个工具以各自的方式保存种子和计数器，因此无法把钱包从一个客户端或命令行工具迁移到另一个。ERC-2386 为此定义了一种通用的 JSON 文件，称为 *walletstore*。

## 它如何运作

walletstore 是一个包含以下字段的 JSON 对象：

| 字段 | 含义 |
| --- | --- |
| `uuid` | 标识钱包的随机 version-4 UUID |
| `name` | 便于人阅读的名称；不得以 `_` 开头 |
| `version` | 始终为整数 `1` |
| `type` | 字符串 `"hierarchical deterministic"` |
| `crypto` | 加密后的种子，严格采用 EIP-2335 的 `kdf` / `checksum` / `cipher` 结构 |
| `nextaccount` | 非负整数：下一个密钥使用的索引 |

新密钥按 [EIP-2334](/eip-2334/) 在路径 `m/12381/60/<nextaccount>/0` 派生，密钥派生本身由 [EIP-2333](/eip-2333/) 定义。创建密钥后，钱包会递增 `nextaccount`，确保不会两次生成同一个密钥。

解密方式与 keystore 完全相同：对密码运行 KDF，校验 checksum，然后解密 `cipher.message` 得到种子。

## 示例代码

walletstore 的结构（显示的是占位值；真实文件包含 KDF 和加密算法输出的十六进制数据）：

```json
{
  "crypto": {
    "kdf": {
      "function": "pbkdf2",
      "params": { "c": 262144, "dklen": 32, "prf": "hmac-sha256", "salt": "<hex>" },
      "message": ""
    },
    "checksum": { "function": "sha256", "params": {}, "message": "<hex>" },
    "cipher": {
      "function": "aes-128-ctr",
      "params": { "iv": "<hex>" },
      "message": "<encrypted seed, hex>"
    }
  },
  "name": "Validator wallet",
  "nextaccount": 0,
  "type": "hierarchical deterministic",
  "uuid": "b74559b8-ed56-4841-b25c-dba1b7c9d9d5",
  "version": 1
}
```

推导下一个密钥的路径：

```ts
function nextKeyPath(ws: { nextaccount: number }): string {
  return `m/12381/60/${ws.nextaccount}/0`;
}
```

## 需要注意

- 状态为 **Stagnant**。该格式有作者提供的 Go 实现，但作为跨客户端标准并未被广泛采用。
- 安全性：种子可以重新生成路径上的每一个密钥，因此 walletstore 的安全程度取决于其密码和 KDF 设置。泄露 walletstore 比泄露单个 keystore 更严重。
- 规范建议将 walletstore 保存在离线机器上，在那里生成单独的 EIP-2335 keystore，只把这些 keystore 转移到在线的验证者。
- 规范中的 JSON schema 有语法疏漏（`required` 列表缺少逗号）；请遵循上面的字段说明，不要原样照抄。


---

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