How to use the bitcore-lib-cash.PrivateKey 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 ninjadotorg / handshake-app / src / services / Wallets / BitcoinCash.js View on Github external
createAddressPrivatekey() {
    super.createAddressPrivatekey();
    this.setDefaultNetwork();
    // get Cashaddr
    var address = new bitcore.PrivateKey(this.privateKey).toAddress();
    this.address = address.toString().split(':')[1];
  }
  async getBalance(isFormatNumber) {
github simpleledger / slpjs / lib / transactionhelpers.ts View on Github external
// NOTE: Only works for compressed-WIF format

        let ecpair = this.slp.BITBOX.ECPair.fromWIF(wif);

        // we set the previous output for the input
        // again, this is for bitcore-lib input sig generation

        txn.inputs[input_index].output = new Bitcore.Transaction.Output({
            satoshis: input_satoshis, 
            script: redeemScript
        });

        // produce a signature that is specific to this input
        // NOTE: currently only uses ecdsa

        let privateKey = new Bitcore.PrivateKey(wif);
        var sig = Bitcore.Transaction.Sighash.sign(txn, privateKey, sigHashType, input_index, redeemScript, Bitcore.crypto.BN.fromNumber(input_satoshis));
        
        // add have to add the sighash type manually.. :(
        // NOTE: signature is in DER format and is specific to ecdsa & sigHash 0x41

        let sigBuf = Buffer.concat([ sig.toDER(), Buffer.alloc(1, sigHashType) ]);  

        // we can return a object conforming to InputSigData interface

        return {
            index: input_index,
            pubKeyBuf: ecpair.getPublicKeyBuffer(),
            signatureBuf: sigBuf
        }
    }
github simpleledger / slpjs / lib / transactionhelpers.ts View on Github external
// we set the previous output for the input
        // again, this is for bitcore-lib input sig generation

        txn.inputs[input_index].output = new Bitcore.Transaction.Output({
            satoshis: input_satoshis, 
            script: Bitcore.Script.fromAddress(Utils.toCashAddress(ecpair.getAddress())) 
        });

        // Update input to be non-abstract type so we can get the p2pkh sign method

        txn.inputs[input_index] = new Bitcore.Transaction.Input.PublicKeyHash(txn.inputs[input_index]);

        // produce a signature that is specific to this input
        // NOTE: currently only uses ecdsa

        let privateKey = new Bitcore.PrivateKey(wif);
        let sig = txn.inputs[input_index].getSignatures(txn, privateKey, input_index, sigHashType);

        // add have to add the sighash type manually.. :(
        // NOTE: signature is in DER format and is specific to ecdsa & sigHash 0x41

        let sigBuf = Buffer.concat([ sig[0].signature.toDER(), Buffer.alloc(1, sigHashType) ]);  

        // we can return a object conforming to InputSigData interface

        return {
            index: input_index, 
            pubKeyBuf: ecpair.getPublicKeyBuffer(),
            signatureBuf: sigBuf
        }
    }
github bitpay / bitcore / test / v8.js View on Github external
describe('V8', () => {
  var wallet={};

  wallet.beAuthPrivateKey2= new B.PrivateKey();

  describe('#listTransactions', () => {
    it('should handle partial json results', (done) => {
      class PartialJson extends Client {
        listTransactions(opts) {
          class MyReadable extends Readable {
            constructor(options) {
              super(options);
              var txStr = JSON.stringify(txs);
              this.push(txStr.substr(0,10));
              this.push(txStr.substr(10));
              this.push(null);
              }
          };

          return new MyReadable;
github monicanagent / cypherpoker.js / src / server / libs / adapters / CryptoAPIs.js View on Github external
throw (new Error("Parameter \"from\" must be a wallet object or derivation path."));
         }
      } else {
         fromWallet = from;
      }
      if ((network == "main") || (network == "livenet")) {
         network = "mainnet";
      }
      if ((network == "test") || (network == "test3")) {
         network = "testnet";
      }
      var fromAddress = this.getAddress(fromWallet, network);
      switch (APIType) {
         case "bitcoincash":
            var UTXOList = await this.getUTXOList(fromAddress, network);
            var signingKey = new bitcoreCash.PrivateKey(fromWallet.toWIF());
            var txHex = await this.buildRawTransaction(UTXOList, fromAddress, toAddress, signingKey, network, amount, fee);
            var API = this.server.config.CP.API.bitcoincash;
            var url = API.urls.cryptoapis.sendtx;
            if (network == null) {
               network = API.default.network;
            }
            var token = this.server.config.CP.API.tokens.cryptoapis;
            if ((network == "main") || (network == "livenet")) {
               network = "mainnet";
            }
            if ((network == "test") || (network == "test3")) {
               network = "testnet";
            }
            url = url.split("%network%").join(network);
            var sendTxObject = new Object();
            sendTxObject.hex = txHex;
github monicanagent / cypherpoker.js / src / server / libs / adapters / BitcoinComAPI.js View on Github external
throw (new Error("Parameter \"from\" must be a wallet object or derivation path."));
         }
      } else {
         fromWallet = from;
      }
      if ((network == "main") || (network == "livenet")) {
         network = "mainnet";
      }
      if ((network == "test") || (network == "test3")) {
         network = "testnet";
      }
      var fromAddress = this.getAddress(fromWallet, network);
      switch (APIType) {
         case "bitcoincash":
            var UTXOList = await this.getUTXOList(fromAddress, network);
            var signingKey = new bitcoreCash.PrivateKey(fromWallet.toWIF());
            var txHex = await this.buildRawTransaction(UTXOList, fromAddress, toAddress, signingKey, network, amount, fee);
            var API = this.server.config.CP.API.bitcoincash;
            var url = API.urls.bitcoincom.sendtx;
            if (network == null) {
               network = API.default.network;
            }
            if ((network == "main") | (network == "mainnet") || (network == "livenet")) {
               network = "rest";
            }
            if ((network == "test") || (network == "test3") || (network == "testnet")) {
               network = "trest";
            }
            url = url.split("%network%").join(network);
            var sendTxObject = new Object();
            sendTxObject.hexes = [txHex];
            var promise = new Promise((resolve, reject) => {
github monicanagent / cypherpoker.js / src / server / libs / adapters / BitcoinCashNative.js View on Github external
var fromWallet = wallet.derivePath(from);
         } else {
            throw (new Error("Parameter \"from\" must be a wallet object or derivation path."));
         }
      } else {
         fromWallet = from;
      }
      if (network == "main") {
         var fromAddress = this.getAddress(fromWallet);
      } else {
         fromAddress = this.getAddress(fromWallet, "test");
      }
      switch (APIType) {
         case "bitcoincash":
            var UTXOList = await this.getUTXOList(fromAddress, network);
            var signingKey = new bitcoreCash.PrivateKey(fromWallet.toWIF());
            var txHex = await this.buildRawTransaction(UTXOList, fromAddress, toAddress, signingKey, network, amount, fee);
            try {
               var txHash = await this.nativeRPC(network).sendRawTransaction(txHex, true); //alow high transaction fees (if included)
            } catch (err) {
               console.error(err);
            }
            //create expected response object
            var txObject = new Object();
            txObject.tx = new Object();
            txObject.tx.hash = txHash;
            if (network == "regtest") {
               //"mine" a block immediately to push the transaction onto the chain
               var mineAddress = this.getDerivedWallet(this.server.config.CP.API.bitcoincash.default.test.cashOutAddrPath, "regtest", true);
               var result = await this.generateRegBlocks(mineAddress, 10); //mine a block
            }
            return (txObject);
github blockparty-sh / craft.cash / src / main.js View on Github external
app.get_private_key = () => new bch.PrivateKey(app.get_wif());
app.get_address     = () => app.get_private_key().toAddress();
github BCNetio / BlockStackWallet / app / Providers / Wallets.js View on Github external
export const generateBCHWallet = (keychain = v4()) => {
  const pk = new bch.PrivateKey(mkBCHpk(keychain));
  return {
    privateKey: pk.toWIF(),
    address: pk.toAddress().toString(),
    wid: v4(),
    alias: generateRandomPair(curNames.BCH),
    type: curNames.BCH,
    created: new Date(),
    readOnly: false,
    balance: 0
  };
};
github BCNetio / BlockStackWallet / app / Providers / Wallets.js View on Github external
export const bchTransaction = (pKey, utxo, listOfReceivers) => {
  const pk = new bch.PrivateKey(pKey);
  const tx = bch
    .Transaction()
    .from(utxo.map(_ => ({ ..._, address: pk.toAddress().toString() })));
  listOfReceivers.forEach(receiver =>
    tx.to(receiver.key, toSatoshi(receiver.amount))
  );
  tx.sign(pk);
  return tx.toString();
};