# @ethereumjs/wallet 中文文档

规范地址：https://npmcn.com/package/%40ethereumjs/wallet/

版本：10\.0\.0
npm 元数据更新时间：2025-04-29T09:55:05.973Z
中文译文更新时间：2026-11-13T23:40:40.075Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ethereumjs/wallet
原文对照：https://npmcn.com/package/%40ethereumjs/wallet/?lang=original
项目主页：https://github.com/ethereumjs/ethereumjs-monorepo/packages/wallet
源码仓库：https://github.com/ethereumjs/ethereumjs-monorepo

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：249 kB，43 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：5 个
- 首次发布：2023-07-17T14:44:15.954Z
- 最新版本发布：2025-04-29T09:55:05.736Z
- 近 30 天下载量：18820（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 0 个）

## 中文简介

处理Ethereum 密钥的公用事业

## 安装

```sh
npm install @ethereumjs/wallet
```

也可以使用：`pnpm add @ethereumjs/wallet`、`yarn add @ethereumjs/wallet`、`bun add @ethereumjs/wallet`

## README

# @ethereumjs/wallet (英语) `v10`

[![NPM Package](https://img.shields.io/npm/v/ethereumjs-wallet.svg)](https://www.npmjs.org/package/@ethereumjs/wallet) [![Actions Status](https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethereumjs-monorepo/actions) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-wallet.svg)](https://coveralls.io/r/ethereumjs/ethereumjs-wallet) [![Discord](https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue)](https://discord.gg/TNwARpR)

轻量级钱包执行 。 目前它支持各种格式之间的密钥创建和转换.

由以下一揽子方案加以补充:

-   [@ethereumjs/tx (英语)](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx) 以签署交易
-   [乙型六氯环己烷](https://github.com/ethereumjs/ethereumjs-icap) 操作 ICAP 地址
-   [存储.js](https://github.com/marcuswestin/store.js) 要使用浏览器存储

动机是:

-   轻量级
-   在浏览器中工作
-   使用一个单一的、维护的加密库(这应符合 [`@ethereumjs/util`](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util) 财务报告和审定财务报表 `@ethereumjs/tx`(中文(简体) )
-   支持不同钱包格式之间的导入/导出
-   支持 BIP32 HD 键

不支持的特性 :

-   签名交易
-   管理存储(无论是节点.js还是浏览器)

## 目录

-   [安装](https://npmcn.com/package/%40ethereumjs/wallet/#readme-installation)
-   [钱包 API](https://npmcn.com/package/%40ethereumjs/wallet/#readme-wallet-api)
-   [第三方 API](https://npmcn.com/package/%40ethereumjs/wallet/#readme-thirdparty-api)
-   [HD 钱包 API](https://npmcn.com/package/%40ethereumjs/wallet/#readme-hd-wallet-api)
-   [专题](https://npmcn.com/package/%40ethereumjs/wallet/#readme-special-topics)
-   [爱丽丝](https://npmcn.com/package/%40ethereumjs/wallet/#readme-ethereumjs)
-   [许可证](https://npmcn.com/package/%40ethereumjs/wallet/#readme-license)

## 钱包 API

关于钱包的API,请前往 [./docs/class/wallet.md](https://npmcn.com/package/%40ethereumjs/wallet/docs/classes/wallet.md)。 。 。 .

您可以导入 `Wallet` 像这样的课

节点.js/ES6:

```js
// ./examples/wallet.cjs

const { Wallet } = require('@ethereumjs/wallet')

const wallet = Wallet.generate()
console.log(wallet.getAddressString()) // should output an Ethereum address
```

无害环境管理/类型脚本:

```ts
// ./examples/wallet.ts

import { Wallet } from '@ethereumjs/wallet'

const wallet = Wallet.generate()
console.log(wallet.getAddressString()) // should output an Ethereum address
```

## 第三方 API

可以通过 `thirdparty` 子模块 :

节点.js/ES5:

```js
// ./examples/thirdparty.cjs

const { thirdparty } = require('@ethereumjs/wallet')

const wallet = thirdparty.fromQuorumWallet('mySecretQuorumWalletPassphrase', 'myPublicQuorumUserId')
console.log(wallet.getAddressString()) // An Ethereum address
```

无害环境管理/类型脚本:

```ts
// ./examples/thirdparty.ts

import { thirdparty } from '@ethereumjs/wallet'

const wallet = thirdparty.fromQuorumWallet('mySecretQuorumWalletPassphrase', 'myPublicQuorumUserId')
console.log(wallet.getAddressString()) // An Ethereum address
```

请去 [./文件/README.md](https://npmcn.com/package/%40ethereumjs/wallet/docs/README.md) 需要更多信息.

## HD 钱包 API

要使用 BIP32 HD 钱包,首先包括 `hdkey` 子模块 :

节点.js/ES5:

```js
// ./examples/hdKey.cjs

const { hdkey } = require('@ethereumjs/wallet')

const wallet = hdkey.EthereumHDKey.fromMnemonic(
  'clown galaxy face oxygen birth round modify fame correct stumble kind excess',
)
console.log(wallet.getWallet().getAddressString()) // Should print an Ethereum address
```

无害环境管理/类型脚本:

```ts
// ./examples/hdKey.ts

import { hdkey } from '@ethereumjs/wallet'

const wallet = hdkey.EthereumHDKey.fromMnemonic(
  'clown galaxy face oxygen birth round modify fame correct stumble kind excess',
)
console.log(wallet.getWallet().getAddressString()) // Should print an Ethereum address
```

请去 [./docs/class/etherumhdkey.md](https://npmcn.com/package/%40ethereumjs/wallet/docs/classes/ethereumhdkey.md) 需要更多信息.

## 专题

### 关于 `toV3`

这个 `options` 是一个可选对象散列,其中所有序列化参数都可以被细调:

-   uuid - UUID (英语). 一是随机生成.
-   盐 -- -- 随机盐 `kdf`。大小必须符合 KDF(关键衍生函数)的要求。 随机数通过 `crypto.getRandomBytes` 如果一无所获.
-   iv - 初始化矢量 `cipher`。大小必须符合密码的要求。 随机数通过 `crypto.getRandomBytes` 如果一无所获.
-   缩略语 关键衍生函数,见下文.
-   dklen - 衍生出密钥长度. 当然 `cipher` 设置,此设置必须与这些设置的块大小相匹配 .
-   密码 - 要使用的密码. 名称必须与所支持的名称相匹配 `OpenSSL`,比如说. `aes-128-ctr` 或者说 `aes-128-cbc`。 。 。 .

取决于 `kdf` 选项.

对于 `pbkdf2`数字 :

-   `c` - 重复次数。 默认为262144.
-   `prf` - 唯一支持(和默认)值是 `hmac-sha256`所以没有意义改变它.

对于 `scrypt`数字 :

-   `n` - 重复计数 默认为262144.
-   `r` - 基本散列的块大小 默认为 8.
-   `p` - 平行因素。 默认为 1 .

Go Ethereum 的执行有利于以下设置,我们默认为:

-   `kdf`数字 : `scrypt`
-   `dklen`数字 : `32`
-   `n`数字 : `262144`
-   `r`数字 : `8`
-   `p`数字 : `1`
-   `cipher`数字 : `aes-128-ctr`

## 爱丽丝

看我们的组织 [文档](https://ethereumjs.readthedocs.io/) 介绍 `EthereumJS` 以及关于现行标准和最佳做法的资料.

如果你想参加工作或改进图书馆,请看看我们 [捐款准则](https://ethereumjs.readthedocs.io/en/latest/contributing.html)。 。 。 .

## 许可证

MIT 许可证

版权(C)2016 Alex Beregszaszi

## 常见问题

### @ethereumjs/wallet 是什么？

处理Ethereum 密钥的公用事业

### 如何安装 @ethereumjs/wallet？

在项目目录运行 npm install @ethereumjs/wallet，或使用 pnpm add / yarn add / bun add。

### @ethereumjs/wallet 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @ethereumjs/wallet 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @ethereumjs/wallet 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @ethereumjs/wallet 可以商用吗？

@ethereumjs/wallet 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ethereumjs/wallet 的下载量有多少？

根据 npm 官方下载统计，@ethereumjs/wallet 在 2026/10/14 – 2026/11/12 这 30 天内被下载 18,820 次，日均约 627 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ethereumjs/wallet 还在维护吗？

最新版本 10\.0\.0 发布于 2025/04/29（1\.5 年前）；至今共发布 9 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/07/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

