diff --git a/HDWallet.test.js b/HDWallet.test.js index 731c473f4..b122049c5 100644 --- a/HDWallet.test.js +++ b/HDWallet.test.js @@ -7,7 +7,7 @@ import { } from './class'; let assert = require('assert'); -it.only('can convert witness to address', () => { +it('can convert witness to address', () => { let address = SegwitP2SHWallet.witnessToAddress( '035c618df829af694cb99e664ce1b34f80ad2c3b49bcd0d9c0b1836c66b2d25fd8', ); @@ -62,27 +62,27 @@ it('HD breadwallet works', async function() { hdBread.setSecret( 'high relief amount witness try remember adult destroy puppy fox giant peace', ); - console.log( - 'bread 0/0 = ', + + assert.equal(hdBread.validateMnemonic(), true); + assert.equal( hdBread._getExternalAddressByIndex(0), - 'bread 1/0 = ', - hdBread._getInternalAddressByIndex(0), - 'valid = ', - hdBread.validateMnemonic(), + '1ARGkNMdsBE36fJhddSwf8PqBXG3s4d2KU', + ); + assert.equal( + hdBread._getInternalAddressByIndex(0), + '1JLvA5D7RpWgChb4A5sFcLNrfxYbyZdw3V', + ); + + assert.equal( + hdBread.getXpub(), + 'xpub68nLLEi3KERQY7jyznC9PQSpSjmekrEmN8324YRCXayMXaavbdEJsK4gEcX2bNf9vGzT4xRks9utZ7ot1CTHLtdyCn9udvv1NWvtY7HXroh', ); - console.log(hdBread.getXpub()); await hdBread.fetchBalance(); - console.log(hdBread.balance); + assert.equal(hdBread.balance, 0); await hdBread.fetchTransactions(); - console.log('tx count = ', hdBread.transactions.length); + assert.equal(hdBread.transactions.length, 175); - console.log( - hdBread.next_free_address_index, - hdBread.next_free_change_address_index, - ); - - // let bitcoin = require('bitcoinjs-lib'); - // let node = bitcoin.HDNode.fromBase58( hdBread.getXpub() ); - // console.log( "normal address", node.derive(0).derive(0).getAddress()); + assert.equal(hdBread.next_free_address_index, 10); + assert.equal(hdBread.next_free_change_address_index, 118); }); diff --git a/class/hd-segwit-p2sh-wallet.js b/class/hd-segwit-p2sh-wallet.js index 96e61329a..3e3b60940 100644 --- a/class/hd-segwit-p2sh-wallet.js +++ b/class/hd-segwit-p2sh-wallet.js @@ -115,12 +115,10 @@ export class HDSegwitP2SHWallet extends LegacyWallet { let scriptSig = bitcoin.script.witnessPubKeyHash.output.encode(keyhash); let addressBytes = bitcoin.crypto.hash160(scriptSig); let outputScript = bitcoin.script.scriptHash.output.encode(addressBytes); - let address = bitcoin.address.fromOutputScript( + return bitcoin.address.fromOutputScript( outputScript, bitcoin.networks.bitcoin, ); - - return address; } async fetchBalance() { @@ -128,7 +126,6 @@ export class HDSegwitP2SHWallet extends LegacyWallet { let response = await api.get('/balance?active=' + this.getXpub()); - // console.log(response); if (response && response.body) { for (let xpub of Object.keys(response.body)) { this.balance = response.body[xpub].final_balance / 100000000; @@ -144,7 +141,6 @@ export class HDSegwitP2SHWallet extends LegacyWallet { let offset = 0; while (1) { - console.log('fetching ', offset); let response = await api.get( '/multiaddr?active=' + this.getXpub() + '&n=100&offset=' + offset, ); @@ -155,7 +151,6 @@ export class HDSegwitP2SHWallet extends LegacyWallet { } // processing TXs and adding to internal memory - console.log('response.body.txs = ', response.body.txs.length); if (response.body.txs) { for (let tx of response.body.txs) { let value = 0; diff --git a/class/legacy-wallet.js b/class/legacy-wallet.js index 259d0d4f5..4e415e9f7 100644 --- a/class/legacy-wallet.js +++ b/class/legacy-wallet.js @@ -24,7 +24,7 @@ export class LegacyWallet extends AbstractWallet { let totalhex = ''; for (let i = 0; i < c; i++) { let randomNumber = isaac.random(); - randomNumber = Math.floor(randomNumber * 255); + randomNumber = Math.floor(randomNumber * 256); let n = new BigNumber(randomNumber); let hex = n.toString(16); if (hex.length === 1) { @@ -41,7 +41,7 @@ export class LegacyWallet extends AbstractWallet { } getTypeReadable() { - return 'P2 PKH'; + return 'P2PKH'; } /**