diff --git a/README.md b/README.md index c74488e..5d7acee 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ So we use [seck256k1](https://www.npmjs.com/package/secp256k1) library in Node f ## Usage +### ECDSA + ```js var crypto = require("crypto"); var eccrypto = require("eccrypto"); @@ -45,19 +47,27 @@ var eccrypto = require("eccrypto"); var privateKey = crypto.randomBytes(32); var publicKey = eccrypto.getPublic(privateKey); var str = "msg to sign"; -// Always hash you msg to sign! +// Always hash you message to sign! var msg = crypto.createHash("sha256").update(str).digest(); eccrypto.sign(privateKey, msg).then(function(sig) { console.log("signed:", sig); - // Public key is sufficient for verifying but private key also could be - // passed for convinience. eccrypto.verify(publicKey, msg, sig).then(function() { console.log("verified"); }); }); ``` +### ECDH + +```js +``` + +### ECIES + +```js +``` + ## License eccrypto - JavaScript Elliptic curve cryptography library diff --git a/index.js b/index.js index 88f97f7..176d91d 100644 --- a/index.js +++ b/index.js @@ -33,14 +33,13 @@ exports.sign = function(privateKey, msg) { /** * Verify an ECDSA signature. - * @param {Buffer} key - A private or public key + * @param {Buffer} publicKey - A 65-byte public key * @param {Buffer} msg - The message being verified * @param {Buffer} sig - The signature * @return {Promise.} A promise that resolves on correct * signature and rejects on bad key or signature. */ -exports.verify = function(key, msg, sig) { - var publicKey = key.length === 32 ? getPublic(key) : key; +exports.verify = function(publicKey, msg, sig) { return new promise(function(resolve, reject) { return secp256k1.verify(publicKey, msg, sig) === 1 ? resolve() : reject(); }); diff --git a/test.js b/test.js index 892f4bb..4419354 100644 --- a/test.js +++ b/test.js @@ -38,14 +38,6 @@ describe("ECDSA", function() { }); }); - it("should allow to verify using private key", function() { - return eccrypto.sign(privateKey, msg) - .then(function(sig) { - expect(Buffer.isBuffer(sig)).to.be.true; - return eccrypto.verify(privateKey, msg, sig); - }); - }); - it("shouldn't verify incorrect signature", function(done) { eccrypto.sign(privateKey, msg).then(function(sig) { expect(Buffer.isBuffer(sig)).to.be.true;