libp2p-crypto-secp256k1

Support for secp256k1 keys in libp2p-crypto

Included in libp2p-crypto, use it instead. https://github.com/libp2p/js-libp2p-crypto
Last updated 5 years ago by jacobheun .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install libp2p-crypto-secp256k1 
SYNC missed versions from official npm registry.

js-libp2p-crypto-secp256k1

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

Install

npm install --save libp2p-crypto-secp256k1

Usage

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.

Example

const crypto = require('libp2p-crypto')
const msg = Buffer.from('Hello World')

const key = await crypto.generateKeyPair('secp256k1', 256)
// assuming no error, key will be an instance of Secp256k1PrivateKey
// the public key is available as key.public
const sig = await key.sign(msg)

const valid = await key.public.verify(msg, sig)
assert(valid, 'Something went horribly wrong')

API

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

generateKeyPair([bits])

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

Returns Promise<Secp256k1PrivateKey>

unmarshalSecp256k1PublicKey(bytes)

  • bytes: Buffer

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

unmarshalSecp256k1PrivateKey(bytes)

  • bytes: Buffer

Returns Promise<Secp256k1PrivateKey>

Converts a serialized secp256k1 private key into an instance of Secp256k1PrivateKey.

Secp256k1PublicKey

.verify(data, sig)

  • data: Buffer
  • sig: Buffer

Returns Promise<Boolean>

Calculates the SHA-256 hash of data, and verifies the DER-encoded signature in sig.

Secp256k1PrivateKey

.public

Accessor for the Secp256k1PublicKey associated with this private key.

.sign(data)

  • data: Buffer

Returns Promise<Buffer>

Calculates the SHA-256 hash of data and signs it, resolves with the DER-encoded signature.

Contribute

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

This repository falls under the IPFS Code of Conduct.

License

MIT

Current Tags

  • 0.4.3                                ...           latest (5 years ago)

14 Versions

  • 0.4.3 [deprecated]           ...           5 years ago
  • 0.4.2 [deprecated]           ...           5 years ago
  • 0.4.1 [deprecated]           ...           5 years ago
  • 0.4.0 [deprecated]           ...           5 years ago
  • 0.3.1 [deprecated]           ...           5 years ago
  • 0.3.0 [deprecated]           ...           6 years ago
  • 0.2.3 [deprecated]           ...           6 years ago
  • 0.2.2 [deprecated]           ...           7 years ago
  • 0.2.1 [deprecated]           ...           7 years ago
  • 0.2.0 [deprecated]           ...           7 years ago
  • 0.1.4 [deprecated]           ...           8 years ago
  • 0.1.3 [deprecated]           ...           8 years ago
  • 0.1.2 [deprecated]           ...           8 years ago
  • 0.1.0 [deprecated]           ...           8 years ago
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE