From 6aec8a33189e4b161166936afedcb8f71c7c6d7a Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Wed, 14 Jan 2015 03:09:37 +0300 Subject: [PATCH] Docs, cosmetics --- README.md | 11 ++++++++--- browser.js | 11 +++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d77658..f2506fe 100644 --- a/README.md +++ b/README.md @@ -39,16 +39,21 @@ So we use [seck256k1](https://www.npmjs.com/package/secp256k1) library in Node f var crypto = require("crypto"); var eccrypto = require("eccrypto"); +// A new random 32-byte private key. var privateKey = crypto.randomBytes(32); +// Corresponding uncompressed (65-byte) public key. var publicKey = eccrypto.getPublic(privateKey); -var str = "msg to sign"; + +var str = "message 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); + console.log("Signature in DER format:", sig); eccrypto.verify(publicKey, msg, sig).then(function() { - console.log("verified"); + console.log("Signature is OK"); + }).catch(function() { + console.log("Signature is BAD"); }); }); ``` diff --git a/browser.js b/browser.js index e3a0f40..b84221d 100644 --- a/browser.js +++ b/browser.js @@ -2,12 +2,6 @@ * Browser eccrypto implementation. */ -// NOTE(Kagami): We don't use promise shim in Browser implementation -// because it's supported natively in new browsers (see -// ) and we can use only new browsers -// because of the WebCryptoAPI (see -// ). - "use strict"; var EC = require("elliptic").ec; @@ -76,6 +70,11 @@ var getPublic = exports.getPublic = function(privateKey) { return new Buffer(ec.keyPair(privateKey).getPublic("arr")); }; +// NOTE(Kagami): We don't use promise shim in Browser implementation +// because it's supported natively in new browsers (see +// ) and we can use only new browsers +// because of the WebCryptoAPI (see +// ). exports.sign = function(privateKey, msg) { return new Promise(function(resolve) { assert(privateKey.length === 32, "Bad private key");