# @bitgo/ecpair 中文文档

规范地址：https://npmcn.com/package/%40bitgo/ecpair/

版本：2\.1\.0-rc\.0
npm 元数据更新时间：2026-03-09T04:23:37.254Z
中文译文更新时间：2026-11-08T04:21:38.578Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bitgo/ecpair
原文对照：https://npmcn.com/package/%40bitgo/ecpair/?lang=original
项目主页：https://github.com/BitGo/ecpair#readme
源码仓库：https://github.com/BitGo/ecpair

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

- 包体积（解压后）：24.5 kB，13 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=8\.0\.0
- 运行依赖：3 个
- 首次发布：2022-09-23T16:51:33.784Z
- 最新版本发布：2022-09-23T16:51:34.059Z
- 近 30 天下载量：472472（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

带有 BitGo 特定变化的 ecpair 叉

## 安装

```sh
npm install @bitgo/ecpair
```

也可以使用：`pnpm add @bitgo/ecpair`、`yarn add @bitgo/ecpair`、`bun add @bitgo/ecpair`

## README

# 喜闻乐见

[![Github CI](https://github.com/bitcoinjs/ecpair/actions/workflows/main_ci.yml/badge.svg)](https://github.com/bitcoinjs/ecpair/actions/workflows/main_ci.yml) [![NPM](https://img.shields.io/npm/v/ecpair.svg)](https://www.npmjs.org/package/ecpair) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

一个用于管理SECP256k1 keypairs的库,用TypeScript写出,并被转接的JavaScript承诺去git.

这个BitGo分叉改善了与分叉硬币的相容性,以及替代的SECP256K1执行.

## 示例

类型脚本

```typescript
import { Signer, SignerAsync, ECPairInterface, ECPairFactory, ECPairAPI, TinySecp256k1Interface } from 'ecpair';
import * as crypto from 'crypto';

// You need to provide the ECC library. The ECC library must implement 
// all the methods of the `TinySecp256k1Interface` interface.
const tinysecp: TinySecp256k1Interface = require('tiny-secp256k1');
const ECPair: ECPairAPI = ECPairFactory(tinysecp);

// You don't need to explicitly write ECPairInterface, but just to show
// that the keyPair implements the interface this example includes it.

// From WIF
const keyPair1: ECPairInterface = ECPair.fromWIF('KynD8ZKdViVo5W82oyxvE18BbG6nZPVQ8Td8hYbwU94RmyUALUik');
// Random private key
const keyPair2 = ECPair.fromPrivateKey(crypto.randomBytes(32));
// OR (uses randombytes library, compatible with browser)
const keyPair3 = ECPair.makeRandom();
// OR use your own custom random buffer generator BE CAREFUL!!!!
const customRandomBufferFunc = (size: number): Buffer => crypto.randomBytes(size);
const keyPair4 = ECPair.makeRandom({ rng: customRandomBufferFunc });
// From pubkey (33 or 65 byte DER format public key)
const keyPair5 = ECPair.fromPublicKey(keyPair1.publicKey);

// Pass a custom network
const network = {}; // Your custom network object here
ECPair.makeRandom({ network });
ECPair.fromPrivateKey(crypto.randomBytes(32), { network });
ECPair.fromPublicKey(keyPair1.publicKey, { network });
// fromWIF will check the WIF version against the network you pass in
// pass in multiple networks if you are not sure
ECPair.fromWIF('wif key...', network);
const network2 = {}; // Your custom network object here
const network3 = {}; // Your custom network object here
ECPair.fromWIF('wif key...', [network, network2, network3]);
```

## 自由主义 [麻省理工学院](https://npmcn.com/package/%40bitgo/ecpair/LICENSE)

书面和测试 [比特币js-lib](https://github.com/bitcoinjs/bitcoinjs-lib) 自2014年以来提供捐款.

## 常见问题

### @bitgo/ecpair 是什么？

带有 BitGo 特定变化的 ecpair 叉

### 如何安装 @bitgo/ecpair？

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

### @bitgo/ecpair 支持 TypeScript 吗？

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

### @bitgo/ecpair 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @bitgo/ecpair 需要什么版本的 Node\.js？

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

### @bitgo/ecpair 可以商用吗？

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

### @bitgo/ecpair 的下载量有多少？

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

### @bitgo/ecpair 还在维护吗？

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

