Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
for (let i = 0; i < lastFoundActiveAddressIndex + addressGapScanDepth; i++) {
// get address
const orderPublickey = hdPublickey.deriveChild(accountDerivation + i.toFixed());
// @ts-ignore
const pubkey = new bitcore.PublicKey(orderPublickey.publicKey);
// @ts-ignore
const address = bitcore.Address.fromPublicKey(pubkey, bitcore.Networks.mainnet).toString();
console.log(address);
//const cashAddr = Utils.toCashAddress(address);
//console.log(cashAddr);
const res = await gprc.getAddressTransactions({address});
if (res.getConfirmedTransactionsList().length > 0) {
lastFoundActiveAddressIndex = i;
transactionHistory.push(...res.getConfirmedTransactionsList());
console.log("Has transactions!");
}
console.log(transactionHistory.length);
}
})();
pubKey = wallet.neutered().toBase58();//public key in "xpub"
pubKeyHex = wallet.neutered().publicKey.toString("hex"); //public key in hex
privKey = wallet.toBase58(); //private key in "xprv"
privKeyHex = wallet.privateKey.toString("hex"); //private key in hex
wif = wallet.toWIF();
childBIP32_0 = wallet.derivePath("m/0/0");
childBIP32_1 = wallet.derivePath("m/0/1");
if (!testnet) {
console.log("Wallet root address: "+getAddress(wallet, bitcoreCash.Networks.livenet, true));
console.log("Wallet \"xpub\": "+pubKey);
console.log("Wallet \"xprv\": "+privKey);
console.log("Wallet Import Format (WIF): "+wif);
console.log("Wallet public key (hex): "+pubKeyHex);
console.log("Wallet private key (hex): "+privKeyHex);
console.log("Inital derived address (m/0/0): "+getAddress(childBIP32_0, bitcoreCash.Networks.livenet, true));
console.log("Inital derived address (m/0/1): "+getAddress(childBIP32_1, bitcoreCash.Networks.livenet, true));
} else {
console.log("Testnet wallet root address: "+getAddress(wallet, bitcoreCash.Networks.testnet, true));
console.log("Testnet wallet \"tpub\": "+pubKey);
console.log("Testnet wallet \"tprv\": "+privKey);
console.log("Testnet Wallet Import Format (WIF): "+wif);
console.log("Testnet wallet public key (hex): "+pubKeyHex);
console.log("Testnet wallet private key (hex): "+privKeyHex);
console.log("Inital derived address (m/0/0): "+getAddress(childBIP32_0, bitcoreCash.Networks.testnet, true));
console.log("Inital derived address (m/0/1): "+getAddress(childBIP32_1, bitcoreCash.Networks.testnet, true));
}
console.log ("");
// Some other examples:
//var wallet = newHDWallet(); //create a mainnet top-level HD node (store these details!)
//var wallet = makeHDWallet("xprv9s21ZrQH143K29WDJvBtkuugkRRWAKe3S6soYUVRPnaCK9KXwc8BEJxrncy5mpHyLCFsx39Q6MPnTGT97UxadieivoWFwj1CiqUPdhHDWnY");
function Messages(options) {
this.builder = Messages.builder(options);
// map message constructors by name
for(var key in this.builder.commandsMap) {
var name = this.builder.commandsMap[key];
this[name] = this.builder.commands[key];
}
if (!options) {
options = {};
}
this.network = options.network || bitcore.Networks.defaultNetwork;
}
} else {
console.log ("Testnet Bitcoin Cash");
console.log ("--------------------");
testnet = true;
wallet = newHDWallet(bitcoin.networks.testnet); //create a testnet top-level HD node
}
pubKey = wallet.neutered().toBase58();//public key in "xpub"
pubKeyHex = wallet.neutered().publicKey.toString("hex"); //public key in hex
privKey = wallet.toBase58(); //private key in "xprv"
privKeyHex = wallet.privateKey.toString("hex"); //private key in hex
wif = wallet.toWIF();
childBIP32_0 = wallet.derivePath("m/0/0");
childBIP32_1 = wallet.derivePath("m/0/1");
if (!testnet) {
console.log("Wallet root address: "+getAddress(wallet, bitcoreCash.Networks.livenet, true));
console.log("Wallet \"xpub\": "+pubKey);
console.log("Wallet \"xprv\": "+privKey);
console.log("Wallet Import Format (WIF): "+wif);
console.log("Wallet public key (hex): "+pubKeyHex);
console.log("Wallet private key (hex): "+privKeyHex);
console.log("Inital derived address (m/0/0): "+getAddress(childBIP32_0, bitcoreCash.Networks.livenet, true));
console.log("Inital derived address (m/0/1): "+getAddress(childBIP32_1, bitcoreCash.Networks.livenet, true));
} else {
console.log("Testnet wallet root address: "+getAddress(wallet, bitcoreCash.Networks.testnet, true));
console.log("Testnet wallet \"tpub\": "+pubKey);
console.log("Testnet wallet \"tprv\": "+privKey);
console.log("Testnet Wallet Import Format (WIF): "+wif);
console.log("Testnet wallet public key (hex): "+pubKeyHex);
console.log("Testnet wallet private key (hex): "+privKeyHex);
console.log("Inital derived address (m/0/0): "+getAddress(childBIP32_0, bitcoreCash.Networks.testnet, true));
console.log("Inital derived address (m/0/1): "+getAddress(childBIP32_1, bitcoreCash.Networks.testnet, true));
setDefaultNetwork() {
bitcore.Networks.defaultNetwork = bitcore.Networks.testnet;
}
}
return await (async function(gene, options) {
let net = options.network === 'testnet' ? bitcore.Networks.testnet : bitcore.Networks.livenet;
let t = gene.toObject()
let inputs: Xput[] = [];
let outputs: Xput[] = [];
if (gene.inputs) {
gene.inputs.forEach(function(input, input_index) {
if (input.script) {
let xput: Xput = { i: input_index }
input.script.chunks.forEach(function(c, chunk_index) {
if (c.buf) {
const key_prefix = (c.buf.length >= 512) ? 'l' : '';
xput[key_prefix + "b" + chunk_index] = c.buf.toString('base64')
if (options && options.h && options.h > 0) {
xput[key_prefix + "h" + chunk_index] = c.buf.toString('hex')
}
} else {
if (typeof c.opcodenum !== 'undefined') {
setDefaultNetwork() {
bitcore.Networks.defaultNetwork = bitcore.Networks.livenet;
}
'use strict';
var Buffers = require('./buffers');
var EventEmitter = require('events').EventEmitter;
var Net = require('net');
var Socks5Client = require('socks5-client');
var bitcore = require('bitcore-lib-cash');
var Networks = bitcore.Networks;
var Messages = require('./messages');
var $ = bitcore.util.preconditions;
var util = require('util');
/**
* The Peer constructor will create an instance of Peer to send and receive messages
* using the standard Bitcoin protocol. A Peer instance represents one connection
* on the Bitcoin network. To create a new peer connection provide the host and port
* options and then invoke the connect method. Additionally, a newly connected socket
* can be provided instead of host and port.
*
* @example
* ```javascript
*
* var peer = new Peer({host: '127.0.0.1'}).setProxy('127.0.0.1', 9050);
* peer.on('tx', function(tx) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
switch (network) {
case "main":
var address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "mainnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "testnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "regtest":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.regtest);
break;
default:
throw (new Error("Unrecognized network \""+network+"\"."));
break;
}
return (address.toString());
} else {
if ((network == "main") || (network == "mainnet") || (network == "livenet")) {
return (this.server.bitcoincash.payments.p2pkh({pubkey:walletObj.publicKey}).address);
} else {