How to use the bitcore.PrivateKey function in bitcore

To help you get started, we’ve selected a few bitcore 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 quartzjer / pennybank / bc-p2cm.js View on Github external
getUTXO(address, function(utxo){
  console.log(utxo.toJSON());
  
  // test sending a small bit to a p2cm
  var privateKey1 = new bitcore.PrivateKey('612b3ca3f368cf2658c2e1777d2fa28e6bcde8ea19312cbf69e09e7333e13994',bitcore.Networks.testnet);
  var privateKey2 = new bitcore.PrivateKey('d65788b9947b41625ffff946bc145187c6b85d1686e60becdf34567f17478730',bitcore.Networks.testnet);
  var publicKey1 = privateKey1.publicKey;
  var publicKey2 = privateKey2.publicKey;

  var P2CMScript = new bitcore.Script.buildMultisigOut([publicKey1, publicKey2], 1);

  // now do the secrets/hashing part
  var A_secret = new Buffer("a236d85656fb05bf157d5328f191c7e6","hex");
  var B_secret = new Buffer("65b3e07dbb2861cad500906e1af5c2c6","hex");
  
  // prepend (in reverse order)
  P2CMScript
  .prepend('OP_EQUALVERIFY')
  .prepend(hash160(B_secret))
  .prepend('OP_HASH160')
  .prepend('OP_EQUALVERIFY')
  .prepend(hash160(A_secret))
github quartzjer / pennybank / bc-p2cm.js View on Github external
var crypto = require('crypto');
var bitcore = require('bitcore');
var Sighash = require('./node_modules/bitcore/lib/transaction/sighash')
var explorers = require('bitcore-explorers');
var insight = new explorers.Insight(bitcore.Networks.testnet);


// testnet
var privateKey = bitcore.PrivateKey({
  "bn":"8c026a359a13f707a3497ef58da45b628958ff98b5f33322cf29ede12fcfd56f",
  "compressed":true,
  "network":"testnet"
});
var address = privateKey.toAddress();
console.log("address",address);

getUTXO(address, function(utxo){
  console.log(utxo.toJSON());
  
  // test sending a small bit to a p2cm
  var privateKey1 = new bitcore.PrivateKey('612b3ca3f368cf2658c2e1777d2fa28e6bcde8ea19312cbf69e09e7333e13994',bitcore.Networks.testnet);
  var privateKey2 = new bitcore.PrivateKey('d65788b9947b41625ffff946bc145187c6b85d1686e60becdf34567f17478730',bitcore.Networks.testnet);
  var publicKey1 = privateKey1.publicKey;
  var publicKey2 = privateKey2.publicKey;
github bitpay / bitcore-channel / test / signatures.js View on Github external
it('has no false positive on payment validation', function() {
    var provider = getProvider();
    var consumer = getValidatedConsumer().consumer;

    var payment = consumer.incrementPaymentBy(1000);
    payment.transaction.nLockTime = 1;

    (function() {
      provider.validPayment(payment);
    }).should.throw();
  });

});

var providerKey = new bitcore.PrivateKey('58e78db594be551a8f4c7070fd8695363992bd1eb37d01cd4a4da608f3dc5c2d', bitcore.Networks.testnet);
var fundingKey = new bitcore.PrivateKey('79b0630419ad72397d211db4988c98ffcb5955b14f6ec5c5651eec5c98d7e557', bitcore.Networks.testnet);
var commitmentKey = new bitcore.PrivateKey('17bc93ac93f4a26599d3af49e59206e8276259febba503434eacb871f9bbad75', bitcore.Networks.testnet);
var providerAddress = providerKey.toAddress(Networks.testnet);

var getConsumer = function() {

  var Consumer = require('../').Consumer;
  var refundAddress = 'mzCXqcsLBerwyoRZzBFQELHaJ1ZtBSxxe6';

  var consumer = new Consumer({
    network: 'testnet',
    fundingKey: fundingKey,
    commitmentKey: commitmentKey,
    providerPublicKey: providerKey.publicKey,
    providerAddress: providerKey.toAddress(),
    refundAddress: refundAddress
  });
github bitpay / bitcore-channel / test / signatures.js View on Github external
var provider = getProvider();
    var consumer = getValidatedConsumer().consumer;

    var payment = consumer.incrementPaymentBy(1000);
    payment.transaction.nLockTime = 1;

    (function() {
      provider.validPayment(payment);
    }).should.throw();
  });

});

var providerKey = new bitcore.PrivateKey('58e78db594be551a8f4c7070fd8695363992bd1eb37d01cd4a4da608f3dc5c2d', bitcore.Networks.testnet);
var fundingKey = new bitcore.PrivateKey('79b0630419ad72397d211db4988c98ffcb5955b14f6ec5c5651eec5c98d7e557', bitcore.Networks.testnet);
var commitmentKey = new bitcore.PrivateKey('17bc93ac93f4a26599d3af49e59206e8276259febba503434eacb871f9bbad75', bitcore.Networks.testnet);
var providerAddress = providerKey.toAddress(Networks.testnet);

var getConsumer = function() {

  var Consumer = require('../').Consumer;
  var refundAddress = 'mzCXqcsLBerwyoRZzBFQELHaJ1ZtBSxxe6';

  var consumer = new Consumer({
    network: 'testnet',
    fundingKey: fundingKey,
    commitmentKey: commitmentKey,
    providerPublicKey: providerKey.publicKey,
    providerAddress: providerKey.toAddress(),
    refundAddress: refundAddress
  });
github Kejixu / SmartProperty / server.js View on Github external
genTx.genSmtPropTx(buyBio, sellBio, function(data) {
              var propertyInfo = {};
              propertyInfo.privateKey = data;
              var pubk = new bitcore.PrivateKey(data);
              propertyInfo.publicAddress = pubk.toAddress();
              io.sockets.emit("transactionComplete", propertyInfo);
            })
github bitpay / bitcore / lib / client / api.js View on Github external
}, function(err, wcd) {
    if (err) return cb(err);

    var walletPrivKey = new Bitcore.PrivateKey();
    var args = {
      name: walletName,
      m: wcd.m,
      n: wcd.n,
      pubKey: walletPrivKey.toPublicKey().toString(),
      network: wcd.network,
    };
    var url = '/v1/wallets/';
    self._doPostRequest(url, args, {}, function(err, body) {
      if (err) return cb(err);

      var walletId = body.walletId;

      var secret = WalletUtils.toSecret(walletId, walletPrivKey, wcd.network);
      var i = 0;
      async.each(wcd.publicKeyRing, function(xpub, next) {
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
public createSig(reedemTx, inputIndex, contract, recipientAddress, privateKey) {
        const wif = privateKey;
        const WIF = new PrivateKey(wif);
        const sighashType = 1;
        const sig = Transaction.Sighash.sign(reedemTx, WIF, sighashType, inputIndex, contract);
        const pubKey = WIF.toPublicKey();
        return {sig, pubKey};
    }
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / dist / common / createSig.js View on Github external
return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            wif = privateKey;
            WIF = new PrivateKey(wif);
            sighashType = 1;
            sig = Transaction.Sighash.sign(reedemTx, WIF, sighashType, inputIndex, contract);
            pubKey = WIF.toPublicKey();
            return _context.abrupt('return', { sig: sig, pubKey: pubKey });

          case 6:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, undefined);
  }));
github bitpay / bitcore / lib / client / api.js View on Github external
}, function(err, wcd) {
    if (err && err != 'NOTFOUND')
      return cb(err);

    if (wcd && wcd.n)
      return cb(self.storage.getName() + ' already contains a wallet');

    if (wcd && wcd.network && wcd.network != network)
      return cb('Storage ' + self.storage.getName() + ' is set to network:' + wcd.network);

    var walletPrivKey = new Bitcore.PrivateKey();
    var args = {
      name: walletName,
      m: m,
      n: n,
      pubKey: walletPrivKey.toPublicKey().toString(),
      network: network,
    };
    var url = '/v1/wallets/';
    self._doPostRequest(url, args, {}, function(err, body) {
      if (err) return cb(err);

      var walletId = body.walletId;

      var secret = WalletUtils.toSecret(walletId, walletPrivKey, network);

      wcd = wcd || _initWcd(network);