This commit is contained in:
Overtorment 2018-07-01 20:59:38 +01:00
parent 9aff7c24e6
commit b5e031d63f
3 changed files with 21 additions and 26 deletions

View File

@ -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);
});

View File

@ -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;

View File

@ -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';
}
/**