Reorganize crypto modules

This commit is contained in:
Kagami Hiiragi 2014-12-26 19:47:25 +03:00
parent 49dc55c714
commit 68f1217911
4 changed files with 35 additions and 25 deletions

View File

@ -1,11 +1,9 @@
/**
* Browser version of the crypto for Bitmessage JS implementation.
* Browser Bitmessage crypto implementation.
*
* Documentation: <http://www.w3.org/TR/WebCryptoAPI/>
* Browsers support: <http://caniuse.com/#feat=cryptography>
* Blink implementation details: <https://sites.google.com/a/chromium.org/dev/blink/webcrypto>
*
* @module bitmessage/crypto.browser
*/
"use strict";

27
lib/crypto-platform.js Normal file
View File

@ -0,0 +1,27 @@
/**
* Node.js Bitmessage crypto implementation.
* @module bitmessage/crypto-platform
*/
"use strict";
require("es6-promise").polyfill();
var crypto = require("crypto");
exports.sha512 = function(buf) {
var hash = crypto.createHash("sha512");
hash.update(buf);
return Promise.resolve(hash.digest());
};
exports.sha256 = function(buf) {
var hash = crypto.createHash("sha256");
hash.update(buf);
return Promise.resolve(hash.digest());
};
exports.ripemd160 = function(buf) {
var hash = crypto.createHash("ripemd160");
hash.update(buf);
return Promise.resolve(hash.digest());
};

View File

@ -1,27 +1,12 @@
/**
* Node.js version of the crypto for Bitmessage JS implementation.
* Isomorphic Bitmessage crypto module. Reexport platform-specific
* functions and also export some common routines.
* @module bitmessage/crypto
*/
"use strict";
require("es6-promise").polyfill();
var crypto = require("crypto");
exports.sha512 = function(buf) {
var hash = crypto.createHash("sha512");
hash.update(buf);
return Promise.resolve(hash.digest());
};
exports.sha256 = function(buf) {
var hash = crypto.createHash("sha256");
hash.update(buf);
return Promise.resolve(hash.digest());
};
exports.ripemd160 = function(buf) {
var hash = crypto.createHash("ripemd160");
hash.update(buf);
return Promise.resolve(hash.digest());
};
var cryptoPlatform = require("./crypto-platform");
Object.keys(cryptoPlatform).forEach(function(key) {
exports[key] = cryptoPlatform[key];
});

View File

@ -5,7 +5,7 @@
"main": "./lib/index.js",
"browser": {
"int64-native": "node-int64",
"./lib/crypto.js": "./lib/crypto.browser.js"
"./lib/crypto-platform.js": "./lib/crypto-platform.browser.js"
},
"scripts": {
"test": "mocha && xvfb-run -a karma start && jshint .",