Caravan Documentation
    Preparing search index...

    Function deriveChildPublicKey

    • Return the public key at the given BIP32 path below the given extended public key.

      Parameters

      • extendedPublicKey: string

        base58 encoded extended public key (xpub...)

      • bip32Path: string

        BIP32 derivation path string (with or without initial m/)

      • network: BitcoinNetwork

        bitcoin network

      Returns string

      (compressed) child public key in hex

      import {deriveChildPublicKey, MAINNET} from "@caravan/bitcoin";
      const xpub = "xpub6CCHViYn5VzKSmKD9cK9LBDPz9wBLV7owXJcNDioETNvhqhVtj3ABnVUERN9aV1RGTX9YpyPHnC4Ekzjnr7TZthsJRBiXA4QCeXNHEwxLab";
      console.log(deriveChildPublicKey(xpub, "m/0/0", MAINNET));
      // "021a0b6eb37bd9d2767a364601e41635a11c1dbbbb601efab8406281e210336ace"
      console.log(deriveChildPublicKey(xpub, "0/0", MAINNET)); // w/o leading `m/`
      // "021a0b6eb37bd9d2767a364601e41635a11c1dbbbb601efab8406281e210336ace"