@bitcoinerlab/secp256k1

中文文档
2.0.0发布于 2026/08/18MITTypeScriptCommonJS近 30 天下载 148.2万

A library for performing elliptic curve operations on the secp256k1 curve. It is designed to integrate into the BitcoinJS & BitcoinerLAB ecosystems and uses the audited noble-curves library. It is compatible with environments that do not support WASM, suc

原始使用文档
文档目录11 节
  1. Features
  2. Installation
  3. Usage
  4. API
  5. Examples
  6. Usage with React Native
  7. Authors and Contributors
  8. Building from source
  9. Testing
  10. Licensing
  11. Acknowledgments

Secp256k1

@bitcoinerlab/secp256k1 is a Javascript library for performing elliptic curve operations on the secp256k1 curve. It is designed to integrate into the BitcoinJS and BitcoinerLAB ecosystems and uses the audited noble-curves library, created by Paul Miller.

This library is compatible with environments that do not support WebAssembly, such as React Native.

Features

  • Compatible with BitcoinJS ecpair and bip32 Factory functions.
  • Based on audited code @noble/curves.
  • Can be used in environments that do not support WASM, such as React Native.
  • Uses the same tests as tiny-secp256k1.

Installation

To install the package, use npm:

npm install @bitcoinerlab/secp256k1

Version 2 requires Node.js 20.19 or newer. The package keeps its CommonJS entry point while using the ESM-only @noble/curves version 2 dependency.

Usage

API

This implementation follows the tiny-secp256k1 API. Please refer to tiny-secp256k1 for documentation on the methods.

  • xOnlyPointAddTweakCheck: This method is not yet implemented. It is not used in ecpair or bip32.

  • signSchnorr: Starting from version 1.2.0, this function deviates from the exact behavior mapping with bitcoinjs/tiny-secp256k1 and no longer initializes the auxiliary random data parameter (e) to a zero-filled array by default. Instead, it requires the caller to explicitly provide randomness if desired. If omitted, the underlying implementation uses cryptographically secure randomness (through crypto.getRandomValues). For more details on this change, see the discussion here and the conclusions here.

Examples

You can test the examples in this section using the online playground demo available at https://bitcoinerlab.com/modules/secp256k1.

import ecc from '@bitcoinerlab/secp256k1';
import { BIP32Factory } from 'bip32';
import { ECPairFactory } from 'ecpair';
const BIP32 = BIP32Factory(ecc);
const ECPair = ECPairFactory(ecc);

const keyPair1 = ECPair.fromWIF(
  'KynD8ZKdViVo5W82oyxvE18BbG6nZPVQ8Td8hYbwU94RmyUALUik'
);
const node = BIP32.fromBase58(
  'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
);

Usage with React Native

@noble/curves uses Javascript BigInt, which is fully supported in React Native on iOS. However, to use it on Android, you must make sure you use the Hermes Javascript Engine, available from RN-0.70 release.

Noble uses crypto.getRandomValues for operations such as Schnorr auxiliary randomness and scalar blinding. React Native environments that do not provide it must install a compatible polyfill such as react-native-get-random-values.

Authors and Contributors

The project was initially developed and is currently maintained by Jose-Luis Landabaso. Contributions and help from other developers are welcome.

Here are some resources to help you get started with contributing:

Building from source

To download the source code and build the project, follow these steps:

  1. Clone the repository:
git clone https://github.com/bitcoinerlab/secp256k1.git
  1. Install the dependencies:
npm install
  1. Build the project:
npm run build

This will build the project and generate the necessary files in the dist directory.

Testing

Before committing any code, make sure it passes all tests by running:

npm run test

Licensing

This project is licensed under the MIT License.

Acknowledgments

Thanks to Paul Miller for creating and maintaining the noble-curves library, upon which this library is based.

Thanks to the BitcoinJS team for creating and maintaining the BitcoinJS ecosystem, including the ecpair and bip32 libraries, which this library is designed to integrate with.

Thanks to the tiny-secp256k1 team for creating and maintaining the tiny-secp256k1 library, which this library uses for testing.

版本与发布记录

@bitcoinerlab/secp256k1 共发布 10 个版本,首次发布于 2023/01/09;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.0latest2026/08/182 个月前
1.2.02024/12/131.9 年前
1.1.12024/02/102 年前
1.1.02024/02/092 年前
1.0.52023/07/103 年前
1.0.42023/06/283 年前

关于 @bitcoinerlab/secp256k1 的常见问题

@bitcoinerlab/secp256k1 是什么?

A library for performing elliptic curve operations on the secp256k1 curve. It is designed to integrate into the BitcoinJS & BitcoinerLAB ecosystems and uses the audited noble-curves library. It is compatible with environments that do not support WASM, suc

如何安装 @bitcoinerlab/secp256k1?

在项目目录运行 npm install @bitcoinerlab/secp256k1,或使用 pnpm add / yarn add / bun add。

@bitcoinerlab/secp256k1 支持 TypeScript 吗?

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

@bitcoinerlab/secp256k1 支持 ESM 还是 CommonJS?

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

@bitcoinerlab/secp256k1 需要什么版本的 Node.js?

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

@bitcoinerlab/secp256k1 可以商用吗?

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

@bitcoinerlab/secp256k1 的下载量有多少?

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

@bitcoinerlab/secp256k1 还在维护吗?

最新版本 2.0.0 发布于 2026/08/18(2 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/01/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。