bitcoinjs-lib/test/crypto.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-04-08 15:39:22 +02:00
var assert = require('assert')
var crypto = require('../src/crypto')
2014-05-13 08:35:07 +02:00
var fixtures = require('./fixtures/crypto')
2014-04-08 15:39:22 +02:00
describe('Crypto', function() {
describe('HASH160', function() {
it('matches the test vector', function() {
2014-05-13 08:35:07 +02:00
fixtures.before.hex.forEach(function(hex, i) {
2014-04-08 15:39:22 +02:00
var actual = crypto.hash160(new Buffer(hex, 'hex')).toString('hex')
2014-05-13 08:35:07 +02:00
var expected = fixtures.after.hash160[i]
2014-04-08 15:39:22 +02:00
2014-04-08 15:50:27 +02:00
assert.equal(actual, expected)
2014-04-08 15:39:22 +02:00
})
})
})
describe('HASH256', function() {
it('matches the test vector', function() {
2014-05-13 08:35:07 +02:00
fixtures.before.hex.forEach(function(hex, i) {
2014-04-08 15:39:22 +02:00
var actual = crypto.hash256(new Buffer(hex, 'hex')).toString('hex')
2014-05-13 08:35:07 +02:00
var expected = fixtures.after.hash256[i]
2014-04-08 15:39:22 +02:00
2014-04-08 15:50:27 +02:00
assert.equal(actual, expected)
2014-04-08 15:39:22 +02:00
})
})
})
describe('SHA1', function() {
it('matches the test vector', function() {
2014-05-13 08:35:07 +02:00
fixtures.before.hex.forEach(function(hex, i) {
2014-04-08 15:39:22 +02:00
var actual = crypto.sha1(new Buffer(hex, 'hex')).toString('hex')
2014-05-13 08:35:07 +02:00
var expected = fixtures.after.sha1[i]
2014-04-08 15:39:22 +02:00
2014-04-08 15:50:27 +02:00
assert.equal(actual, expected)
2014-04-08 15:39:22 +02:00
})
})
})
describe('SHA256', function() {
it('matches the test vector', function() {
2014-05-13 08:35:07 +02:00
fixtures.before.hex.forEach(function(hex, i) {
2014-04-08 15:39:22 +02:00
var actual = crypto.sha256(new Buffer(hex, 'hex')).toString('hex')
2014-05-13 08:35:07 +02:00
var expected = fixtures.after.sha256[i]
2014-04-08 15:39:22 +02:00
2014-04-08 15:50:27 +02:00
assert.equal(actual, expected)
2014-04-08 15:39:22 +02:00
})
})
})
describe('HMAC SHA512', function() {
it('matches the test vector', function() {
2014-05-13 08:35:07 +02:00
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
2014-05-13 08:35:07 +02:00
var secret = new Buffer(fixtures.after.hmacsha512.secret)
var actual = crypto.HmacSHA512(data, secret)
2014-05-13 08:35:07 +02:00
var expected = fixtures.after.hmacsha512.hash[i]
assert.equal(actual.toString('hex'), expected)
})
})
})
2014-04-08 15:39:22 +02:00
})