Support for secp256k1 keys in libp2p-crypto
Last updated a year ago by arve.knudsen .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @arve.knudsen/libp2p-crypto-secp256k1 
SYNC missed versions from official npm registry.


Discourse posts Dependency Status js-standard-style

Support for secp256k1 keys in js-libp2p-crypto

This repo contains a js-libp2p-crypto-compatible implementation of cryptographic signature generation and verification using the secp256k1 elliptic curve popularized by Bitcoin and other crypto currencies.

Lead Captain

Friedel Ziegelmayer

Table of Contents


npm install --save libp2p-crypto-secp256k1


This module is designed to work with js-libp2p-crypto.
Installing libp2p-crypto-secp256k1 will automatically add support for the 'secp256k1' key type, which can be used as an argument to the libp2p-crypto API functions generateKeyPair, unmarshalPublicKey, and marshalPrivateKey. The keys returned from those functions will be instances of the Secp256k1PublicKey or Secp256k1PrivateKey classes provided by this module.


const crypto = require('libp2p-crypto')

const msg = Buffer.from('Hello World')

crypto.generateKeyPair('secp256k1', 256, (err, key) => {
  // assuming no error, key will be an instance of Secp256k1PrivateKey
  // the public key is available as key.public
  key.sign(msg, (err, sig) => {
    key.public.verify(msg, sig, (err, valid) => {
      assert(valid, 'Something went horribly wrong')


The functions below are the public API of this module. For usage within libp2p-crypto, see the libp2p-crypto API documentation.

generateKeyPair([bits, ] callback)

  • bits: Number - Optional, included for compatibility with js-libp2p-crypto. Ignored if present; private keys will always be 256 bits.
  • callback: Function


  • bytes: Buffer

Converts a serialized secp256k1 public key into an instance of Secp256k1PublicKey and returns it

unmarshalSecp256k1PrivateKey(bytes, callback)

  • bytes: Buffer
  • callback: Function

Converts a serialized secp256k1 private key into an instance of Secp256k1PrivateKey, passing it to callback on success


.verify(data, sig, callback)

  • data: Buffer
  • sig: Buffer
  • callback: Function

Calculates the SHA-256 hash of data, and verifies the DER-encoded signature in sig, passing the result to callback



Accessor for the Secp256k1PublicKey associated with this private key.

.sign(data, callback)

  • data: Buffer

Calculates the SHA-256 hash of data and signs it, passing the DER-encoded signature to callback


Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.



Current Tags

  • 0.3.0                                ...           latest (a year ago)

1 Versions

  • 0.3.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (6)
Dev Dependencies (5)

Copyright 2014 - 2017 © taobao.org |