Start with isomorphic sha512 wrapper
This commit is contained in:
parent
800b53d9f1
commit
19129b0903
4
lib/crypto.browser.js
Normal file
4
lib/crypto.browser.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* Browser version of the crypto for Bitmessage JS implementation.
|
||||||
|
* @module bitmessage/lib/crypto.browser
|
||||||
|
*/
|
16
lib/crypto.js
Normal file
16
lib/crypto.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Node.js version of the crypto for Bitmessage JS implementation.
|
||||||
|
* Wrap all crypto functions with promises because WebCryptoAPI uses it
|
||||||
|
* throughout.
|
||||||
|
* @module bitmessage/lib/crypto
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var crypto = require("crypto");
|
||||||
|
|
||||||
|
exports.sha512 = function(buf) {
|
||||||
|
var hash = crypto.createHash("sha512");
|
||||||
|
hash.update(buf);
|
||||||
|
return Promise.resolve(hash.digest());
|
||||||
|
};
|
|
@ -2,7 +2,10 @@
|
||||||
"name": "bitmessage",
|
"name": "bitmessage",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"description": "JavaScript Bitmessage library",
|
"description": "JavaScript Bitmessage library",
|
||||||
"main": "index.js",
|
"main": "./lib/index",
|
||||||
|
"browser": {
|
||||||
|
"./lib/crypto": "./lib/crypto.browser"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha && jshint ."
|
"test": "mocha && jshint ."
|
||||||
},
|
},
|
||||||
|
@ -24,6 +27,7 @@
|
||||||
"homepage": "https://github.com/nekogrid/bitmessage",
|
"homepage": "https://github.com/nekogrid/bitmessage",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "*",
|
"chai": "*",
|
||||||
|
"es6-promise": "^2.0.1",
|
||||||
"jshint": "*",
|
"jshint": "*",
|
||||||
"mocha": "*"
|
"mocha": "*"
|
||||||
}
|
}
|
||||||
|
|
13
test.js
13
test.js
|
@ -0,0 +1,13 @@
|
||||||
|
var expect = require("chai").expect;
|
||||||
|
|
||||||
|
require("es6-promise").polyfill();
|
||||||
|
var crypto = require("./lib/crypto");
|
||||||
|
|
||||||
|
describe("crypto", function() {
|
||||||
|
it("should calculate sha512 hash for both node and browserify", function(done) {
|
||||||
|
crypto.sha512(new Buffer("test")).then(function(res) {
|
||||||
|
expect(res.toString("hex")).to.equal("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user