Docs, cosmetics
This commit is contained in:
parent
bcc78bd8e4
commit
6aec8a3318
11
README.md
11
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");
|
||||
});
|
||||
});
|
||||
```
|
||||
|
|
11
browser.js
11
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
|
||||
// <http://caniuse.com/#feat=promises>) and we can use only new browsers
|
||||
// because of the WebCryptoAPI (see
|
||||
// <http://caniuse.com/#feat=cryptography>).
|
||||
|
||||
"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
|
||||
// <http://caniuse.com/#feat=promises>) and we can use only new browsers
|
||||
// because of the WebCryptoAPI (see
|
||||
// <http://caniuse.com/#feat=cryptography>).
|
||||
exports.sign = function(privateKey, msg) {
|
||||
return new Promise(function(resolve) {
|
||||
assert(privateKey.length === 32, "Bad private key");
|
||||
|
|
Loading…
Reference in New Issue
Block a user