move convert methods from util to convert

This commit is contained in:
Wei Lu 2014-03-11 09:52:48 +08:00
parent 227fa97500
commit 3d6b66e811
15 changed files with 161 additions and 172 deletions

View file

@ -1,14 +1,14 @@
/* global describe, it */
var assert = require('assert');
var base58 = require('../').base58;
var conv = require('../').convert;
var convert = require('../').convert;
describe('base58', function() {
describe('decode', function() {
it('validates known examples', function() {
var enc = '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ';
var hex = '800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d';
assert.deepEqual(base58.decode(enc), conv.hexToBytes(hex));
assert.deepEqual(base58.decode(enc), convert.hexToBytes(hex));
})
})
@ -16,7 +16,7 @@ describe('base58', function() {
it('handles known examples', function() {
var enc = '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ';
var hex = '800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d';
assert.equal(base58.encode(conv.hexToBytes(hex)), enc);
assert.equal(base58.encode(convert.hexToBytes(hex)), enc);
})
})

View file

@ -44,4 +44,31 @@ describe('convert', function() {
assert.equal(b64('foobar'), 'Zm9vYmFy')
})
})
describe('byte array and word array conversions', function(){
var bytes, wordArray;
beforeEach(function(){
bytes = [
98, 233, 7, 177, 92, 191, 39, 213, 66, 83,
153, 235, 246, 240, 251, 80, 235, 184, 143, 24
]
wordArray = {
words: [1659439025, 1556031445, 1112775147, -151979184, -340226280],
sigBytes: 20
}
})
describe('bytesToWords', function() {
it('works', function() {
assert.deepEqual(convert.bytesToWordArray(bytes), wordArray)
})
})
describe('bytesToWords', function() {
it('works', function() {
assert.deepEqual(convert.wordArrayToBytes(wordArray), bytes)
})
})
})
})

View file

@ -10,10 +10,10 @@ var rng = new SecureRandom();
var ecparams = sec('secp256k1');
var ECPointFp = bitcoinjs.ECPointFp;
var util = require('../src/util');
var convert = require('../src/convert');
function sha256FromBytesToBytes(message){
return util.wordArrayToBytes(SHA256(util.bytesToWordArray(message)))
return convert.wordArrayToBytes(SHA256(convert.bytesToWordArray(message)))
}
it('Keys & Key Management', function () {

View file

@ -1,33 +0,0 @@
var util = require('../src/util.js')
var assert = require('assert')
describe('util', function() {
describe('byte array and word array conversions', function(){
var bytes, wordArray;
beforeEach(function(){
bytes = [
98, 233, 7, 177, 92, 191, 39, 213, 66, 83,
153, 235, 246, 240, 251, 80, 235, 184, 143, 24
]
wordArray = {
words: [1659439025, 1556031445, 1112775147, -151979184, -340226280],
sigBytes: 20
}
})
describe('bytesToWords', function() {
it('works', function() {
assert.deepEqual(util.bytesToWordArray(bytes), wordArray)
})
})
describe('bytesToWords', function() {
it('works', function() {
assert.deepEqual(util.wordArrayToBytes(wordArray), bytes)
})
})
})
})