How to use the bitcore-lib-cash.HDPublicKey function in bitcore-lib-cash

To help you get started, we’ve selected a few bitcore-lib-cash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simpleledger / slpjs / examples / 11-get-txns-from-xpub-grpc.ts View on Github external
import * as bitcore from "bitcore-lib-cash";
import { GrpcClient, Transaction } from "grpc-bchrpc-node";
import { Utils } from "../lib/utils";

const gprc = new GrpcClient();

// user variables
const tokenId = "";
const address = "";

const xpub = "xpub661MyMwAqRbcEmunind5AZXnevFW66TB3vq5MHM5Asq8UNaEdTsgk4njwUXW4RGywGK68au91R1rvjQ6SmJQEUwUinjYZPnJA7o72bG5HFr";
// @ts-ignore
const hdPublickey = new bitcore.HDPublicKey(xpub);
const accountDerivation = "m/0/";  //  this is the account part of the non-hardened HD path so, "//<address>/"
let lastFoundActiveAddressIndex = 0;
const addressGapScanDepth = 10;  // this is the gap that will be maintained past the "lastActiveAddressIndex"
let transactionHistory: Transaction[] = [];

// main scanning loop
(async () =&gt; {
    for (let i = 0; i &lt; 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);</address>