All files / src util.ts

100% Statements 8/8
50% Branches 1/2
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x 1x 1x             2x     1x 1x 1x               1x      
import { addressNListToBIP32, BTCInputScriptType, BTCOutputScriptType } from "@shapeshiftoss/hdwallet-core";
import * as bitcoin from "@bithighlander/bitcoin-cash-js-lib";
import { getNetwork } from "./networks";
 
type BTCScriptType = BTCInputScriptType | BTCOutputScriptType;
 
function getKeyPair(
  seed: bitcoin.BIP32Interface,
  addressNList: number[],
  Enetwork = "bitcoin",
  scriptType?: BTCScriptType
): { privateKey: string; publicKey: string } {
  const path = addressNListToBIP32(addressNList);
  const keypair = bitcoin.ECPair.fromWIF(seed.derivePath(path).toWIF(), getNetwork(network, scriptType));
  return {
    // @ts-ignore
    privateKey: keypair.privateKey.toString("hex"),
    publicKey: keypair.publicKey.toString("hex"),
  };
}
 
// Prevent malicious JavaScript from replacing the method
export default Object.freeze({
  getKeyPair,
});