Expand feature matrix, improve consistency
This commit is contained in:
parent
1d03820f3f
commit
4d5a699c6e
30
README.md
30
README.md
|
@ -33,14 +33,32 @@ With the help of browserify `bitmessage` provides different implementations for
|
||||||
- [ ] ECIES
|
- [ ] ECIES
|
||||||
- [ ] AES-256-CBC
|
- [ ] AES-256-CBC
|
||||||
- [ ] HMAC-SHA-256
|
- [ ] HMAC-SHA-256
|
||||||
- [ ] Core structures
|
- [ ] Common structures
|
||||||
|
- [ ] message
|
||||||
- [x] var_int
|
- [x] var_int
|
||||||
- [x] var_str
|
- [x] var_str
|
||||||
- [x] var_int_list
|
- [x] var_int_list
|
||||||
- [ ] inv_vect
|
|
||||||
- [ ] net_addr
|
- [ ] net_addr
|
||||||
|
- [ ] inv_vect
|
||||||
|
- [ ] encrypted
|
||||||
|
- [ ] unencrypted
|
||||||
|
- [ ] encoding
|
||||||
- [ ] bitfield
|
- [ ] bitfield
|
||||||
- [ ] High-level objects
|
- [ ] Message types
|
||||||
|
- [ ] version
|
||||||
|
- [ ] verack
|
||||||
|
- [ ] addr
|
||||||
|
- [ ] inv
|
||||||
|
- [ ] getdata
|
||||||
|
- [ ] object
|
||||||
|
- [ ] Object types
|
||||||
|
- [ ] getpubkey
|
||||||
|
- [ ] pubkey
|
||||||
|
- [ ] msg
|
||||||
|
- [ ] broadcast
|
||||||
|
- [x] WIF
|
||||||
|
- [ ] POW
|
||||||
|
- [ ] High-level classes
|
||||||
- [ ] Address
|
- [ ] Address
|
||||||
- [x] encode
|
- [x] encode
|
||||||
- [x] decode
|
- [x] decode
|
||||||
|
@ -48,10 +66,8 @@ With the help of browserify `bitmessage` provides different implementations for
|
||||||
- [x] fromRandom
|
- [x] fromRandom
|
||||||
- [ ] fromPassphrase
|
- [ ] fromPassphrase
|
||||||
- [ ] Message
|
- [ ] Message
|
||||||
- [ ] encode
|
- [ ] encrypt
|
||||||
- [ ] decode
|
- [ ] decrypt
|
||||||
- [x] WIF
|
|
||||||
- [ ] POW
|
|
||||||
- [ ] Parse PyBitmessage configs
|
- [ ] Parse PyBitmessage configs
|
||||||
- [ ] decode keys.dat
|
- [ ] decode keys.dat
|
||||||
- [ ] decode knownnodes.dat
|
- [ ] decode knownnodes.dat
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** Common structures. */
|
||||||
|
exports.struct = require("./struct");
|
||||||
|
/** Working with WIF. */
|
||||||
|
exports.WIF = require("./wif");
|
||||||
/** Working with addresses. */
|
/** Working with addresses. */
|
||||||
exports.Address = require("./address");
|
exports.Address = require("./address");
|
||||||
/** Working with WIF. */
|
|
||||||
exports.wif = require("./wif");
|
|
||||||
/** Core structures. */
|
|
||||||
exports.struct = require("./struct");
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Implements core structures.
|
* Implements common structures.
|
||||||
* @see {@link https://bitmessage.org/wiki/Protocol_specification#Common_structures}
|
* @see {@link https://bitmessage.org/wiki/Protocol_specification#Common_structures}
|
||||||
* @module bitmessage/struct
|
* @module bitmessage/struct
|
||||||
*/
|
*/
|
||||||
|
@ -154,7 +154,7 @@ exports.var_int_list = {
|
||||||
rest = decoded.rest;
|
rest = decoded.rest;
|
||||||
sumLength += decoded.length;
|
sumLength += decoded.length;
|
||||||
}
|
}
|
||||||
return {list: list, length: sumLength, rest: rest}
|
return {list: list, length: sumLength, rest: rest};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
102
test.js
102
test.js
|
@ -3,15 +3,58 @@ var allTests = typeof window === "undefined" ?
|
||||||
!!process.env.ALL_TESTS :
|
!!process.env.ALL_TESTS :
|
||||||
window.ALL_TESTS;
|
window.ALL_TESTS;
|
||||||
|
|
||||||
|
var bmcrypto = require("./lib/crypto");
|
||||||
var bitmessage = require("./lib");
|
var bitmessage = require("./lib");
|
||||||
var Address = bitmessage.Address;
|
|
||||||
var wif = bitmessage.wif;
|
|
||||||
var var_int = bitmessage.struct.var_int;
|
var var_int = bitmessage.struct.var_int;
|
||||||
var var_str = bitmessage.struct.var_str;
|
var var_str = bitmessage.struct.var_str;
|
||||||
var var_int_list = bitmessage.struct.var_int_list;
|
var var_int_list = bitmessage.struct.var_int_list;
|
||||||
var bmcrypto = require("./lib/crypto");
|
var WIF = bitmessage.WIF;
|
||||||
|
var Address = bitmessage.Address;
|
||||||
|
|
||||||
describe("Core structures", function() {
|
describe("Crypto", function() {
|
||||||
|
it("should implement SHA-512 hash", function() {
|
||||||
|
return bmcrypto.sha512(Buffer("test")).then(function(res) {
|
||||||
|
expect(res.toString("hex")).to.equal("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should implement SHA-256 hash", function() {
|
||||||
|
return bmcrypto.sha256(Buffer("test")).then(function(res) {
|
||||||
|
expect(res.toString("hex")).to.equal("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should implement RIPEMD-160 hash", function() {
|
||||||
|
return bmcrypto.ripemd160(Buffer("test")).then(function(res) {
|
||||||
|
expect(res.toString("hex")).to.equal("5e52fee47e6b070565f74372468cdc699de89107");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should implement cryptographically secure PRNG", function() {
|
||||||
|
var size = 100;
|
||||||
|
var rnd = bmcrypto.randomBytes(size);
|
||||||
|
expect(Buffer.isBuffer(rnd)).to.be.true;
|
||||||
|
expect(rnd.length).to.equal(size);
|
||||||
|
// Very simple statistical test.
|
||||||
|
var bytes = {};
|
||||||
|
var sum = 0;
|
||||||
|
var value;
|
||||||
|
for (var i = 0; i < size; i++) {
|
||||||
|
value = rnd[i];
|
||||||
|
sum += value;
|
||||||
|
if (!bytes[value]) {
|
||||||
|
bytes[value] = 0;
|
||||||
|
}
|
||||||
|
bytes[value]++;
|
||||||
|
expect(bytes[value]).to.be.below(7);
|
||||||
|
}
|
||||||
|
// Ideal sum = (255 / 2) * size = 12750
|
||||||
|
expect(sum).to.be.above(10000);
|
||||||
|
expect(sum).to.be.below(15000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Common structures", function() {
|
||||||
describe("var_int", function() {
|
describe("var_int", function() {
|
||||||
it("should decode", function() {
|
it("should decode", function() {
|
||||||
var res;
|
var res;
|
||||||
|
@ -122,12 +165,12 @@ describe("WIF", function() {
|
||||||
var encPrivateKey = Buffer("9f9969c93c2d186787a7653f70e49be34c03c4a853e6ad0c867db0946bc433c6", "hex");
|
var encPrivateKey = Buffer("9f9969c93c2d186787a7653f70e49be34c03c4a853e6ad0c867db0946bc433c6", "hex");
|
||||||
|
|
||||||
it("should decode", function() {
|
it("should decode", function() {
|
||||||
return wif.decode(wifSign)
|
return WIF.decode(wifSign)
|
||||||
.then(function(key1) {
|
.then(function(key1) {
|
||||||
expect(Buffer.isBuffer(key1)).to.be.true;
|
expect(Buffer.isBuffer(key1)).to.be.true;
|
||||||
expect(key1.length).to.equal(32);
|
expect(key1.length).to.equal(32);
|
||||||
expect(key1.toString("hex")).to.equal(signPrivateKey.toString("hex"));
|
expect(key1.toString("hex")).to.equal(signPrivateKey.toString("hex"));
|
||||||
return wif.decode(wifEnc).then(function(key2) {
|
return WIF.decode(wifEnc).then(function(key2) {
|
||||||
expect(Buffer.isBuffer(key2)).to.be.true;
|
expect(Buffer.isBuffer(key2)).to.be.true;
|
||||||
expect(key2.length).to.equal(32);
|
expect(key2.length).to.equal(32);
|
||||||
expect(key2.toString("hex")).to.equal(encPrivateKey.toString("hex"));
|
expect(key2.toString("hex")).to.equal(encPrivateKey.toString("hex"));
|
||||||
|
@ -139,58 +182,15 @@ describe("WIF", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should encode", function() {
|
it("should encode", function() {
|
||||||
return wif.encode(signPrivateKey).then(function(wif1) {
|
return WIF.encode(signPrivateKey).then(function(wif1) {
|
||||||
expect(wif1).to.equal(wifSign);
|
expect(wif1).to.equal(wifSign);
|
||||||
return wif.encode(encPrivateKey);
|
return WIF.encode(encPrivateKey);
|
||||||
}).then(function(wif2) {
|
}).then(function(wif2) {
|
||||||
expect(wif2).to.equal(wifEnc);
|
expect(wif2).to.equal(wifEnc);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Crypto", function() {
|
|
||||||
it("should implement SHA-512 hash", function() {
|
|
||||||
return bmcrypto.sha512(Buffer("test")).then(function(res) {
|
|
||||||
expect(res.toString("hex")).to.equal("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should implement SHA-256 hash", function() {
|
|
||||||
return bmcrypto.sha256(Buffer("test")).then(function(res) {
|
|
||||||
expect(res.toString("hex")).to.equal("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should implement RIPEMD-160 hash", function() {
|
|
||||||
return bmcrypto.ripemd160(Buffer("test")).then(function(res) {
|
|
||||||
expect(res.toString("hex")).to.equal("5e52fee47e6b070565f74372468cdc699de89107");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should implement cryptographically secure PRNG", function() {
|
|
||||||
var size = 100;
|
|
||||||
var rnd = bmcrypto.randomBytes(size);
|
|
||||||
expect(Buffer.isBuffer(rnd)).to.be.true;
|
|
||||||
expect(rnd.length).to.equal(size);
|
|
||||||
// Very simple statistical test.
|
|
||||||
var bytes = {};
|
|
||||||
var sum = 0;
|
|
||||||
var value;
|
|
||||||
for (var i = 0; i < size; i++) {
|
|
||||||
value = rnd[i];
|
|
||||||
sum += value;
|
|
||||||
if (!bytes[value]) {
|
|
||||||
bytes[value] = 0;
|
|
||||||
}
|
|
||||||
bytes[value]++;
|
|
||||||
expect(bytes[value]).to.be.below(7);
|
|
||||||
}
|
|
||||||
// Ideal sum = (255 / 2) * size = 12750
|
|
||||||
expect(sum).to.be.above(10000);
|
|
||||||
expect(sum).to.be.below(15000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Address", function() {
|
describe("Address", function() {
|
||||||
it("should decode Bitmessage address", function() {
|
it("should decode Bitmessage address", function() {
|
||||||
return Address.decode("BM-2cTux3PGRqHTEH6wyUP2sWeT4LrsGgy63z")
|
return Address.decode("BM-2cTux3PGRqHTEH6wyUP2sWeT4LrsGgy63z")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user