# secp256k1

> This module provides native bindings to ecdsa secp256k1 functions

Latest version **5.0.2** (published 2026-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install secp256k1
pnpm add secp256k1
yarn add secp256k1
bun add secp256k1
```

## Health

**Score 58/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.2 |
| Published | 2026-08-07 |
| First published | 2014-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/secp256k1) |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 3 |
| Unpacked size | 1.8 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 360 |
| Author | Martin Becze |
| Maintainers | null_radix, fanatid, jprichardson |
| Keywords | ec, ecdh, ecdsa, secp256k1 |

## Links

- npm: https://www.npmjs.com/package/secp256k1
- Repository: https://github.com/cryptocoinjs/secp256k1-node
- Homepage: https://github.com/cryptocoinjs/secp256k1-node#readme
- Issues: https://github.com/cryptocoinjs/secp256k1-node/issues
- npm.io page: https://npm.io/package/secp256k1

## Dependencies (3)

- [elliptic](https://npm.io/package/elliptic.md) ^6.5.7
- [node-addon-api](https://npm.io/package/node-addon-api.md) ^5.0.0
- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^4.2.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 5.0.2 (latest) — 2026-08-07
- 4.0.5 — 2026-08-07
- 3.8.1 — 2024-10-20
- 4.0.4 — 2024-10-18
- 5.0.1 — 2024-10-18
- 5.0.0 — 2022-12-31
- 4.0.3 — 2022-01-08
- 4.0.2 — 2020-07-20
- 4.0.1 — 2020-04-27
- 4.0.0 — 2020-01-09
- 3.8.0 — 2019-12-19
- 3.7.1 — 2019-05-31
- 3.7.0 — 2019-05-08
- 3.6.2 — 2019-01-28
- 3.6.1 — 2018-12-29
- … 49 more at https://npm.io/package/secp256k1/versions

## README

# secp256k1-node

This module provides native bindings to [bitcoin-core/secp256k1](https://github.com/bitcoin-core/secp256k1). In browser [elliptic](https://github.com/indutny/elliptic) will be used as fallback.

Works on node version 14.0.0 or greater, because use [N-API](https://nodejs.org/api/n-api.html).

## Installation

##### from npm

`npm install secp256k1`

##### from git

```
git clone git@github.com:cryptocoinjs/secp256k1-node.git
cd secp256k1-node
git submodule update --init
npm install
```

##### Windows

The easiest way to build the package on windows is to install [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools).

Or install the following software:

  * Git: https://git-scm.com/download/win
  * nvm: https://github.com/coreybutler/nvm-windows
  * Python 2.7: https://www.python.org/downloads/release/python-2712/
  * Visual C++ Build Tools: http://landinghub.visualstudio.com/visual-cpp-build-tools (Custom Install, and select both Windows 8.1 and Windows 10 SDKs)

And run commands:

```
npm config set msvs_version 2015 --global
npm install npm@next -g
```

Based on:

  * https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245
  * https://github.com/nodejs/node-gyp/issues/972

## Usage

* [API Reference (v4.x)](API.md) (current version)
* [API Reference (v3.x)](https://github.com/cryptocoinjs/secp256k1-node/blob/v3.x/API.md)
* [API Reference (v2.x)](https://github.com/cryptocoinjs/secp256k1-node/blob/v2.x/API.md)

##### Private Key generation, Public Key creation, signature creation, signature verification

```js
const { randomBytes } = require('crypto')
const secp256k1 = require('secp256k1')
// or require('secp256k1/elliptic')
//   if you want to use pure js implementation in node

// generate message to sign
// message should have 32-byte length, if you have some other length you can hash message
// for example `msg = sha256(rawMessage)`
const msg = randomBytes(32)

// generate privKey
let privKey
do {
  privKey = randomBytes(32)
} while (!secp256k1.privateKeyVerify(privKey))

// get the public key in a compressed format
const pubKey = secp256k1.publicKeyCreate(privKey)

// sign the message
const sigObj = secp256k1.ecdsaSign(msg, privKey)

// verify the signature
console.log(secp256k1.ecdsaVerify(sigObj.signature, msg, pubKey))
// => true
```

\* **.verify return false for high signatures**

##### Get X point of ECDH

```js
const { randomBytes } = require('crypto')
// const secp256k1 = require('./elliptic')
const secp256k1 = require('./')

// generate privKey
function getPrivateKey () {
  while (true) {
    const privKey = randomBytes(32)
    if (secp256k1.privateKeyVerify(privKey)) return privKey
  }
}

// generate private and public keys
const privKey = getPrivateKey()
const pubKey = secp256k1.publicKeyCreate(privKey)

// compressed public key from X and Y
function hashfn (x, y) {
  const pubKey = new Uint8Array(33)
  pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03
  pubKey.set(x, 1)
  return pubKey
}

// get X point of ecdh
const ecdhPointX = secp256k1.ecdh(pubKey, privKey, { hashfn }, Buffer.alloc(33))
console.log(ecdhPointX.toString('hex'))
```

## LICENSE

This library is free and open-source software released under the MIT license.

---
_Source: https://npm.io/package/secp256k1 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
