---
eip: 7908
label: ERC-7908
title: HD wallet In Treasury Management
status: Final
type: Standards Track
category: ERC
created: 2025-03-07
official: https://eips.ethereum.org/EIPS/eip-7908
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7908.md
canonical: https://eips.huatuo.xyz/zh/eip-7908/
lang: zh
tldr: 一种面向机构资金库、类似 BIP-44 的 HD 派生路径，为每个子公司和部门分配独立的强化（hardened）密钥分支，通过对名称做哈希来派生。
tags: [wallet, hd-wallet, bip-44, treasury, key-management]
---

# ERC-7908: HD wallet In Treasury Management

> Hierarchical deterministic (HD) wallets for treasury systems, isolating entities via cryptographic key paths.

**TL;DR:** 一种面向机构资金库、类似 BIP-44 的 HD 派生路径，为每个子公司和部门分配独立的强化（hardened）密钥分支，通过对名称做哈希来派生。

## 它解决什么问题？

持有加密资产的公司通常需要许多账户：每个子公司、每个部门，有时还有每个角色。为每个账户生成互不相关的密钥，既难备份又难审计；而让各团队共用一个密钥，则完全丧失隔离。

ERC-7908 标准化了组织如何布局一个分层确定性（HD）钱包，使得：

- 集团管理员可以从一个主密钥派生所有账户，
- 可以把独立的分支交给某个子公司或部门，而不暴露其他分支，
- 可以向审计方提供扩展**公钥**，让他们看到某个部门的全部地址，却无法动用资金。

## 它如何运作

必需的路径是：

```text
m / 44' / 60' / entity_id' / department_id' / account_index
```

- `44'` 和 `60'` 是常见的 BIP-44 purpose 和以太坊 coin type。
- `entity_id'` 和 `department_id'` 是通过对名称做哈希计算出的**强化（hardened）**索引，因此泄露的部门密钥无法用来触及同级或上级。
- `account_index` 是**非强化（non-hardened）**的，因此部门的 xpub 可以派生其所有地址。
- BIP-44 的 `change` 层级被去掉了，因为以太坊是基于账户的。

索引派生使用 SHA-256，并保持最高位为 1（范围 2^31 到 2^32 − 1）：

- `entity_index = first4bytes(sha256("ENTITY:" + entity)) | 0x80000000`
- `dept_index = first4bytes(sha256("DEPT:" + entity_hash + ":" + department)) | 0x80000000`

把实体哈希串入部门哈希，意味着两个子公司中的"Finance"会得到两个不同的索引。

规范还描述了可选的额外 `role_id'` 层级，以及面向没有子公司的组织的简化路径 `m/44'/60'/department_id'/0/account_index`。

## 示例代码

按参考实现（对实体哈希做十六进制编码）用 Python 计算索引：

```python
import hashlib

def treasury_path(entity: str, department: str, account: int = 0) -> str:
    entity_hash = hashlib.sha256(f"ENTITY:{entity}".encode()).digest()
    e_idx = int.from_bytes(entity_hash[:4], "big") | 0x80000000

    dept_hash = hashlib.sha256(f"DEPT:{entity_hash.hex()}:{department}".encode()).digest()
    d_idx = int.from_bytes(dept_hash[:4], "big") | 0x80000000

    # e_idx / d_idx already include the hardened bit
    return f"m/44'/60'/{e_idx - 0x80000000}'/{d_idx - 0x80000000}'/{account}"

print(treasury_path("GroupA", "Finance", 0))
```

把得到的路径交给任何 BIP-32 库（secp256k1），即可得到密钥和地址。

## 需要注意

- 状态为 **Final**。
- 规范文本把部门输入写作 `DEPT:{entity_hash}`，而参考代码使用的是 `entity_hash.hex()`。请选定一种编码并写入文档，否则各工具之间的索引将无法一致。
- 这么大的强化索引在 BIP-32 中是合法的，但有些钱包界面不允许输入自定义路径；扩展的角色路径（省略了 `44'`）被明确说明与标准钱包不兼容。
- 一切都依赖于同一个主密钥。规范要求对其加以额外保护，例如拆分助记词或主密钥。
- 交出部门的 **xprv** 就等于交出该分支的完全花费权；如需仅限审计的访问，请共享 **xpub**。


---

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