@bitgo/ecpair

中文文档
2.1.0-rc.0发布于 2022/09/24MITTypeScriptCommonJS近 30 天下载 47.2万

带有 BitGo 特定变化的 ecpair 叉

中文使用文档

喜闻乐见

Github CI NPM code style: prettier

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

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

示例

类型脚本

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]);

自由主义 麻省理工学院

书面和测试 比特币js-lib 自2014年以来提供捐款.

版本与发布记录

@bitgo/ecpair 共发布 1 个版本,首次发布于 2022/09/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0-rc.0latest2022/09/244 年前

关于 @bitgo/ecpair 的常见问题

@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 和提交记录判断。