GithubHelp home page GithubHelp logo

alanshaw / js-libp2p-crypto-secp256k1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from libp2p/js-libp2p-crypto-secp256k1

0.0 1.0 1.0 27 KB

js-libp2p-crypto-compatible implementation of cryptographic signature generation/verification using the secp256k1 elliptic curve

Home Page: https://libp2p.io

License: MIT License

Groovy 1.33% JavaScript 98.67%

js-libp2p-crypto-secp256k1's Introduction

js-libp2p-crypto-secp256k1

standard-readme compliant 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')

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')
    })
  })
})

API

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

unmarshalSecp256k1PublicKey(bytes)

  • 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

Secp256k1PublicKey

.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

Secp256k1PrivateKey

.public

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

Contribute

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

This repository falls under the IPFS Code of Conduct.

License

MIT

js-libp2p-crypto-secp256k1's People

Contributors

daviddias avatar dignifiedquire avatar victorb avatar yusefnapora avatar

Watchers

 avatar

Forkers

dirkmc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.