https://github.com/angeal185/js-ecdsa
ecdsa for the browser using the webcrypto api
https://github.com/angeal185/js-ecdsa
browser ecdsa elliptic-curve elliptic-curve-cryptography sign signing verification verify webcrypto webcrypto-api
Last synced: 8 months ago
JSON representation
ecdsa for the browser using the webcrypto api
- Host: GitHub
- URL: https://github.com/angeal185/js-ecdsa
- Owner: angeal185
- License: mit
- Created: 2019-05-15T05:23:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-16T04:24:16.000Z (over 6 years ago)
- Last Synced: 2024-10-09T21:08:23.802Z (12 months ago)
- Topics: browser, ecdsa, elliptic-curve, elliptic-curve-cryptography, sign, signing, verification, verify, webcrypto, webcrypto-api
- Language: JavaScript
- Homepage: https://angeal185.github.io/jquery-ecdsa
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-ecdsa
ecdsa for the browser using the webcrypto apiDemo: https://angeal185.github.io/jquery-ecdsa
### Installation
npm
```sh
$ npm install js-ecdsa --save
```bower
```sh
$ bower install js-ecdsa
```git
```sh
$ git clone git@github.com:angeal185/js-ecdsa.git
```#### browser
```html
```
#### API
```javascript
/**
* 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')
})
})
})```