Browse Source

Merge pull request #163 from dcousens/wordass

Enforces convert.wordsToBytes to only allow for byte input
hk-custom-address
Wei Lu 11 years ago
parent
commit
39516d5532
  1. 2
      src/convert.js
  2. 12
      test/hdwallet.js

2
src/convert.js

@ -1,3 +1,4 @@
var assert = require('assert')
var Crypto = require('crypto-js') var Crypto = require('crypto-js')
var WordArray = Crypto.lib.WordArray var WordArray = Crypto.lib.WordArray
@ -77,6 +78,7 @@ function varIntToNum(bytes) {
} }
function bytesToWords(bytes) { function bytesToWords(bytes) {
assert(Array.isArray(bytes) || Buffer.isBuffer(bytes), 'Input must be a byte array')
var words = [] var words = []
for (var i = 0, b = 0; i < bytes.length; i++, b += 8) { for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
words[b >>> 5] |= bytes[i] << (24 - b % 32) words[b >>> 5] |= bytes[i] << (24 - b % 32)

12
test/hdwallet.js

@ -233,17 +233,17 @@ describe('HDWallet', function() {
describe('network types', function() { describe('network types', function() {
it('ensures that a bitcoin Wallet generates bitcoin addresses', function() { it('ensures that a bitcoin Wallet generates bitcoin addresses', function() {
var wallet = new HDWallet('foobar', 'bitcoin') var wallet = new HDWallet(new Buffer('foobar'), 'bitcoin')
assert.equal(wallet.getAddress().toString(), '1JNymexJHEr5u1BndiChMStFkCgPm4EQ6o') assert.equal(wallet.getAddress().toString(), '17SnB9hyGwJPoKpLb9eVPHjsujyEuBpMAA')
}) })
it('ensures that a testnet Wallet generates testnet addresses', function() { it('ensures that a testnet Wallet generates testnet addresses', function() {
var wallet = new HDWallet('foobar', 'testnet') var wallet = new HDWallet(new Buffer('foobar'), 'testnet')
assert.equal(wallet.getAddress().toString(), 'mxtw4i3H6GHLg7fQMHB5BN6acCH6kQ7aoY') assert.equal(wallet.getAddress().toString(), 'mmxjUCnx5xjeaSHxJicsDCxCmjZwq8KTbv')
}) })
it('throws an excption when unknown network type is passed in', function() { it('throws an exception when unknown network type is passed in', function() {
assert.throws(function() { new HDWallet("foobar", "doge") }) assert.throws(function() { new HDWallet(new Buffer('foobar'), 'doge') })
}) })
}) })
}) })

Loading…
Cancel
Save