2014-04-08 15:39:22 +02:00
|
|
|
var assert = require('assert')
|
2014-05-13 09:55:53 +02:00
|
|
|
var crypto = require('../src/crypto')
|
2014-05-13 08:35:07 +02:00
|
|
|
|
2014-05-18 11:47:39 +02:00
|
|
|
var fixtures = require('./fixtures/crypto.json')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
|
|
|
describe('Crypto', function() {
|
|
|
|
describe('HASH160', function() {
|
2014-05-16 04:36:09 +02:00
|
|
|
it('matches the test vectors', function() {
|
2014-05-13 08:35:07 +02:00
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
2014-05-16 04:36:09 +02:00
|
|
|
var data = new Buffer(hex, 'hex')
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.hash160(data).toString('hex')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.hash160[i])
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('HASH256', function() {
|
2014-05-16 04:36:09 +02:00
|
|
|
it('matches the test vectors', function() {
|
2014-05-13 08:35:07 +02:00
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
2014-05-16 04:36:09 +02:00
|
|
|
var data = new Buffer(hex, 'hex')
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.hash256(data).toString('hex')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.hash256[i])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('RIPEMD160', function() {
|
|
|
|
it('matches the test vectors', function() {
|
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
|
|
|
var data = new Buffer(hex, 'hex')
|
|
|
|
var actual = crypto.ripemd160(data).toString('hex')
|
|
|
|
|
|
|
|
assert.equal(actual, fixtures.after.ripemd160[i])
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('SHA1', function() {
|
2014-05-16 04:36:09 +02:00
|
|
|
it('matches the test vectors', function() {
|
2014-05-13 08:35:07 +02:00
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
2014-05-16 04:36:09 +02:00
|
|
|
var data = new Buffer(hex, 'hex')
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.sha1(data).toString('hex')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.sha1[i])
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('SHA256', function() {
|
2014-05-16 04:36:09 +02:00
|
|
|
it('matches the test vectors', function() {
|
2014-05-13 08:35:07 +02:00
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
2014-05-16 04:36:09 +02:00
|
|
|
var data = new Buffer(hex, 'hex')
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.sha256(data).toString('hex')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.sha256[i])
|
2014-05-16 04:36:09 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('HmacSHA256', function() {
|
|
|
|
it('matches the test vectors', function() {
|
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
|
|
|
var data = new Buffer(hex, 'hex')
|
|
|
|
var secret = new Buffer(fixtures.before.secret)
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.HmacSHA256(data, secret).toString('hex')
|
2014-05-16 04:36:09 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.hmacsha256[i])
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-05-10 01:55:55 +02:00
|
|
|
|
2014-05-16 04:36:09 +02:00
|
|
|
describe('HmacSHA512', function() {
|
|
|
|
it('matches the test vectors', function() {
|
2014-05-13 08:35:07 +02:00
|
|
|
fixtures.before.hex.forEach(function(hex, i) {
|
2014-05-10 01:55:55 +02:00
|
|
|
var data = new Buffer(hex, 'hex')
|
2014-05-16 04:36:09 +02:00
|
|
|
var secret = new Buffer(fixtures.before.secret)
|
2014-06-26 11:26:21 +02:00
|
|
|
var actual = crypto.HmacSHA512(data, secret).toString('hex')
|
2014-05-10 01:55:55 +02:00
|
|
|
|
2014-06-26 11:26:21 +02:00
|
|
|
assert.equal(actual, fixtures.after.hmacsha512[i])
|
2014-05-10 01:55:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|