Update tests: add hashes.
This commit is contained in:
parent
7946c2ff2e
commit
b12015528a
17
test.js
17
test.js
|
@ -2,7 +2,6 @@ var expect = require("chai").expect;
|
||||||
var createHash = require("crypto").createHash;
|
var createHash = require("crypto").createHash;
|
||||||
var bufferEqual = require("buffer-equal");
|
var bufferEqual = require("buffer-equal");
|
||||||
var eccrypto = require("./");
|
var eccrypto = require("./");
|
||||||
var assert = require('assert'); // deleteme
|
|
||||||
|
|
||||||
var msg = createHash("sha256").update("test").digest();
|
var msg = createHash("sha256").update("test").digest();
|
||||||
var otherMsg = createHash("sha256").update("test2").digest();
|
var otherMsg = createHash("sha256").update("test2").digest();
|
||||||
|
@ -23,13 +22,27 @@ privateKeyB.fill(3);
|
||||||
var publicKeyB = eccrypto.getPublic(privateKeyB);
|
var publicKeyB = eccrypto.getPublic(privateKeyB);
|
||||||
var publicKeyBCompressed = eccrypto.getPublicCompressed(privateKeyB);
|
var publicKeyBCompressed = eccrypto.getPublicCompressed(privateKeyB);
|
||||||
|
|
||||||
|
describe("Hashes", function() {
|
||||||
|
it("should comply to the Spec", function() {
|
||||||
|
const sample_sha512 = "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043",
|
||||||
|
sample_double_sha512 = "0592a10584ffabf96539f3d780d776828c67da1ab5b169e9e8aed838aaecc9ed36d49ff1423c55f019e050c66c6324f53588be88894fef4dcffdb74b98e2b200",
|
||||||
|
sample_bm160 = "79a324faeebcbf9849f310545ed531556882487e";
|
||||||
|
var sha512 = createHash("sha512").update("hello").digest(),
|
||||||
|
double_sha512 = createHash("sha512").update(sha512).digest(),
|
||||||
|
bm160 = createHash("ripemd160").update(sha512).digest();
|
||||||
|
expect(sha512.toString("hex")).to.equal(sample_sha512);
|
||||||
|
expect(double_sha512.toString("hex")).to.equal(sample_double_sha512);
|
||||||
|
expect(bm160.toString("hex")).to.equal(sample_bm160);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Key conversion", function() {
|
describe("Key conversion", function() {
|
||||||
it("should allow to convert private key to public", function() {
|
it("should allow to convert private key to public", function() {
|
||||||
expect(Buffer.isBuffer(publicKey)).to.be.true;
|
expect(Buffer.isBuffer(publicKey)).to.be.true;
|
||||||
expect(publicKey.toString("hex")).to.equal("041b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f70beaf8f588b541507fed6a642c5ab42dfdf8120a7f639de5122d47a69a8e8d1");
|
expect(publicKey.toString("hex")).to.equal("041b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f70beaf8f588b541507fed6a642c5ab42dfdf8120a7f639de5122d47a69a8e8d1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouwld allow to convert private key to compressed public", function() {
|
it("should allow to convert private key to compressed public", function() {
|
||||||
expect(Buffer.isBuffer(publicKeyCompressed)).to.be.true;
|
expect(Buffer.isBuffer(publicKeyCompressed)).to.be.true;
|
||||||
expect(publicKeyCompressed.toString("hex")).to.equal("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
|
expect(publicKeyCompressed.toString("hex")).to.equal("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user