Code Monkey home page Code Monkey logo

js-ecdsa's Introduction

js-ecdsa

ecdsa for the browser using the webcrypto api

Demo: https://angeal185.github.io/jquery-ecdsa

Installation

npm

$ npm install js-ecdsa --save

bower

$ bower install js-ecdsa

git

$ git clone [email protected]:angeal185/js-ecdsa.git

browser

<script src="./dist/js-ecdsa.min.js"></script>

API

/**
 *  generate ecdsa keypair
 *  @param {string} curve ~ '256'/'384'/'521'
 *  @param {function} cb ~ callback function(err,res)
 **/

ecdsa.gen(curve, cb)


/**
 *  create signature
 *  @param {string} key ~ valid jwk
 *  @param {string} data ~ data to be signed
 *  @param {string} hash ~ '128'/'256'/'512'
 *  @param {string} digest ~ 'hex'/'base64'/'Uint8'
 *  @param {function} cb ~ callback function(err,res)
 **/

ecdsa.sign(key, data, hash, digest, cb)


/**
 *  verify signature
 *  @param {string} key ~ valid jwk
 *  @param {string} sig ~ valid signature
 *  @param {string} data ~ data to verify
 *  @param {string} hash ~ '128'/'256'/'512'
 *  @param {string} digest ~ 'hex'/'base64'/'Uint8'
 *  @param {function} cb ~ callback function(err,res)
 **/

ecdsa.verify(key, sig, data, hash, digest, cb)



//demo

const config = {
  curve: '521', // P-521
  hash: '512', // SHA-512
  digest: 'hex', // hexadecimal
  data: 'test'
}

//generate p-521 ecdsa keypair
ecdsa.gen(config.curve, function(err, gen){
  if(err){return console.log(err)}
  console.log(gen)

  //sign some data
  ecdsa.sign(gen.private, config.data, config.hash, config.digest, function(err, sig){
    if(err){return console.log(err)}
    console.log(sig)

    //verify signature
    ecdsa.verify(gen.public, sig, config.data, config.hash, config.digest, function(err, res){
      if(err){return console.log(err)}
      if(res){
        return console.log('ecdsa test pass')
      }
      return console.log('ecdsa test fail')
    })
  })
})

js-ecdsa's People

Contributors

angeal185 avatar

Watchers

 avatar  avatar

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.