Add browser version of crypto and test with karma
This commit is contained in:
parent
600dc6e4bb
commit
a402c40d4d
|
@ -1,6 +1,8 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
|
before_script:
|
||||||
|
- "sudo apt-get install -y chromium-browser"
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
on_success: never
|
on_success: never
|
||||||
|
|
73
karma.conf.js
Normal file
73
karma.conf.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
process.env.CHROME_BIN = "chromium-browser";
|
||||||
|
|
||||||
|
module.exports = function(config) {
|
||||||
|
config.set({
|
||||||
|
|
||||||
|
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||||
|
basePath: "",
|
||||||
|
|
||||||
|
|
||||||
|
// frameworks to use
|
||||||
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
|
frameworks: ["mocha", "browserify"],
|
||||||
|
|
||||||
|
|
||||||
|
// list of files / patterns to load in the browser
|
||||||
|
files: [
|
||||||
|
"test.js"
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
// preprocess matching files before serving them to the browser
|
||||||
|
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||||
|
preprocessors: {
|
||||||
|
"test.js": ["browserify"],
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// list of files to exclude
|
||||||
|
exclude: [
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
// test results reporter to use
|
||||||
|
// possible values: "dots", "progress"
|
||||||
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||||
|
reporters: ["mocha"],
|
||||||
|
|
||||||
|
|
||||||
|
// web server port
|
||||||
|
port: 9876,
|
||||||
|
|
||||||
|
|
||||||
|
// enable / disable colors in the output (reporters and logs)
|
||||||
|
colors: true,
|
||||||
|
|
||||||
|
|
||||||
|
// level of logging
|
||||||
|
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
|
||||||
|
|
||||||
|
// enable / disable watching file and executing tests whenever any file changes
|
||||||
|
autoWatch: true,
|
||||||
|
|
||||||
|
|
||||||
|
// start these browsers
|
||||||
|
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||||
|
browsers: ["chromium_no_sandbox"],
|
||||||
|
customLaunchers: {
|
||||||
|
chromium_no_sandbox: {
|
||||||
|
base: "Chrome",
|
||||||
|
flags: ["--no-sandbox"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Continuous Integration mode
|
||||||
|
// if true, Karma captures browsers, runs the tests and exits
|
||||||
|
singleRun: false,
|
||||||
|
});
|
||||||
|
};
|
|
@ -2,3 +2,11 @@
|
||||||
* Browser version of the crypto for Bitmessage JS implementation.
|
* Browser version of the crypto for Bitmessage JS implementation.
|
||||||
* @module bitmessage/lib/crypto.browser
|
* @module bitmessage/lib/crypto.browser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.sha512 = function(buf) {
|
||||||
|
return window.crypto.subtle.digest({name: "SHA-512"}, buf).then(function(arr) {
|
||||||
|
return new Buffer(new Uint8Array(arr));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
13
package.json
13
package.json
|
@ -2,12 +2,13 @@
|
||||||
"name": "bitmessage",
|
"name": "bitmessage",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"description": "JavaScript Bitmessage library",
|
"description": "JavaScript Bitmessage library",
|
||||||
"main": "./lib/index",
|
"main": "./lib/index.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
"./lib/crypto": "./lib/crypto.browser"
|
"./lib/crypto.js": "./lib/crypto.browser.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha && jshint ."
|
"test": "mocha && xvfb-run -a karma start --single-run && jshint .",
|
||||||
|
"karma": "xvfb-run -a karma start"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -28,6 +29,12 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "*",
|
"chai": "*",
|
||||||
"jshint": "*",
|
"jshint": "*",
|
||||||
|
"karma": "^0.12.28",
|
||||||
|
"karma-browserify": "^1.0.1",
|
||||||
|
"karma-chrome-launcher": "^0.1.7",
|
||||||
|
"karma-cli": "~0.0.4",
|
||||||
|
"karma-mocha": "^0.1.10",
|
||||||
|
"karma-mocha-reporter": "^0.3.1",
|
||||||
"mocha": "*"
|
"mocha": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
5
test.js
5
test.js
|
@ -3,10 +3,9 @@ var expect = require("chai").expect;
|
||||||
var bmcrypto = require("./lib/crypto");
|
var bmcrypto = require("./lib/crypto");
|
||||||
|
|
||||||
describe("Bitmessage crypto", function() {
|
describe("Bitmessage crypto", function() {
|
||||||
it("should calculate sha512 hash for both node and browserify", function(done) {
|
it("should calculate sha512 hash", function() {
|
||||||
bmcrypto.sha512(new Buffer("test")).then(function(res) {
|
return bmcrypto.sha512(new Buffer("test")).then(function(res) {
|
||||||
expect(res.toString("hex")).to.equal("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff");
|
expect(res.toString("hex")).to.equal("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff");
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user