How to use the bitcore-lib.PrivateKey function in bitcore-lib

To help you get started, we’ve selected a few bitcore-lib 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 fanatid / coloredcoinjs-lib / test / integration / transfer.js View on Github external
it('EPOBC', async () => {
    // http://tbtc.blockr.io/tx/info/87b2e65e7fec95c2ba5d84f5e61779d64df8ca17f2e0f2dd86e56d65c882dce6

    let pk1 = new bitcore.PrivateKey(
      'cW4QRvHawwgJNxuSBrUsSpPEkLpLDAemaZ68ciibV64HYHwHATVm', 'testnet')
    let pk2 = new bitcore.PrivateKey(
      'cVZRCg3E45bjMiqt16uWDiYsEimtzvUJShAnXUurDxgo44rSu6a2', 'testnet')

    let cdef = await cclib.definitions.EPOBC.fromDesc(
      'epobc:7932c31eca2d7f6798f3edd03cbac195dca6443e49b44918233abfcfe9597f9d:0:318050', 1)
    let cvalue = new cclib.ColorValue(cdef, 100000)
    let inputScript = bitcore.Script.buildPublicKeyHashOut(pk1.toPublicKey()).toHex()
    let targetScript = bitcore.Script.buildPublicKeyHashOut(pk2.toPublicKey()).toHex()
    let ctarget = new cclib.ColorTarget(targetScript, cvalue)

    let optx = new cclib.tx.SimpleOperational({
      targets: [
        ctarget
      ],
      coins: {
        0: [{
          txId: '34ab8f0822dbedb3bff09353e909da8b24dece04610cc461b01f90469dcb706d',
github dfinity-side-projects / STIFTUNG-DFN-donations / app / javascripts / btc.js View on Github external
BitcoinWorker.prototype.start = function(config) {
    console.log("Worker started");
    var self = this

    // Client configuration:
    self.clientPrivateKey = bitcore.PrivateKey(config.privateKey)
    self.clientAddress = self.clientPrivateKey.toAddress();
    console.log("clientDfinity data is: " + config.clientDfinityData);
    self.clientDfinityData = bitcore.util.buffer.hexToBuffer(config.clientDfinityData);

    // Central configuration:
    self.centralAddress = bitcore.Address(config.centralAddress)

    // External block explorer configuration:
    self.pollIntervalMs = config.pollIntervalMs || 5000
    self.bitcoinProvider = config.bitcoinProvider;
    self.bitcoinProvider.__proto__.getTransactions = getTransactions;
    self.bitcoinProvider.__proto__.getStatus = getStatus;

    // self worker considers itself "connected" if the last HTTP request it made
    // was successful (starts disconnected):
    self.isConnected = false
github bitpay / bitcore / packages / bitcore-wallet-service / src / scripts / v8tool.ts View on Github external
const request = require('request');
const Bitcore = require('bitcore-lib');
import { Client } from '../lib//blockchainexplorers/v8/client';

const coin = 'BTC';
console.log('COIN:', coin);
const network = 'mainnet';
const authKey = process.argv[2];
const path = process.argv[3] || 'addresses';

if (!authKey)
  throw new Error('provide authKey');

// ====================
//
const authKeyObj =  Bitcore.PrivateKey(authKey);

let tmp  = authKeyObj.toObject();
tmp.compressed = false;
const pubKey = Bitcore.PrivateKey(tmp).toPublicKey() ;
const baseUrl = `https://api.bitcore.io/api/${coin}/${network}`;
let client = new Client({
  baseUrl,
  authKey: authKeyObj,
});

// utxos
// addresses

const url = `${baseUrl}/wallet/${pubKey}/${path}`;
console.log('[v8tool.37:url:]', url);
const signature = client.sign({ method: 'GET', url });
github bitpay / bitcore-channel / test / sender.unit.js View on Github external
describe('Sender (party who wants to open a payment channel)', function() {
  var senderPrivateKey = new bitcore.PrivateKey();
  var receiverPrivateKey = new bitcore.PrivateKey();
console.log(senderPrivateKey.toWIF());
console.log(receiverPrivateKey.toWIF());
console.log(senderPrivateKey.publicKey);
console.log(receiverPrivateKey.publicKey);
  var past2038 = new Date('2040-01-01Z');
  var sender = new Sender({
    expirationTime: past2038,
    amount: 10,
    receiverPublicKeys: [receiverPrivateKey.publicKey],
    senderPublicKeys: [senderPrivateKey.publicKey]
  });

  it('should convert expiration time stamp', function() {
    sender._convertExpirationTimeStamp().should.deep.equal(new Buffer('d0c4aa8300', 'hex'));
  });
github bitpay / bwdb / test / utils.unit.js View on Github external
}, function(err, res) {
        if (err) {
          return done(err);
        }
        var privKey = res.toString('hex');
        var addressFromCompressedPubKey = new bitcore.PublicKey(pubkey, {network: 'testnet'}).toAddress().toString();
        var addressFromRawPrivateKey = new bitcore.PrivateKey(privKey, 'testnet').toAddress().toString();
        var actual = '4a9f87c9384a60d1fe95f5cc6c94e54d76457798b687639fb83f2d0cf365ad7b';
        privKey.should.equal(actual);
        addressFromCompressedPubKey.should.equal(addressFromRawPrivateKey);
        done();
      });
    });
github bitpay / bitcore-channel / test / basic.js View on Github external
var provider = getProvider();
      var consumer = getValidatedConsumer().consumer;
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.currentAmount.should.equal(1000);
      provider.paymentTx.getFee().should.equal(10000);
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.currentAmount.should.equal(4000);
      provider.paymentTx.getFee().should.equal(10000);
    });
  });
});

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 / basic.js View on Github external
var consumer = getValidatedConsumer().consumer;
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.currentAmount.should.equal(1000);
      provider.paymentTx.getFee().should.equal(10000);
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.validPayment(consumer.incrementPaymentBy(1000));
      provider.currentAmount.should.equal(4000);
      provider.paymentTx.getFee().should.equal(10000);
    });
  });
});

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 / examples / 00.createConsumer.js View on Github external
var channel = require('../');
var bitcore = require('bitcore-lib');


var refundKey = new bitcore.PrivateKey(bitcore.Networks.testnet);
var fundingKey = new bitcore.PrivateKey(bitcore.Networks.testnet);
var commitmentKey = new bitcore.PrivateKey(bitcore.Networks.testnet);

console.log('funding key: ' + refundKey.toString());
console.log('refund key: ' + fundingKey.toString());
console.log('commitment key: ' + commitmentKey.toString());
github bitpay / bitcore-mnemonic / packages / bitcore-wallet-client / lib / api.js View on Github external
if (network != self.credentials.network) {
    return cb(new Error('Existing keys were created for a different network'));
  }

  var walletPrivKey = opts.walletPrivKey || new Bitcore.PrivateKey();

  var c = self.credentials;
  c.addWalletPrivateKey(walletPrivKey.toString());
  var encWalletName = Utils.encryptMessage(walletName, c.sharedEncryptingKey);

  var args = {
    name: encWalletName,
    m: m,
    n: n,
    pubKey: (new Bitcore.PrivateKey(walletPrivKey)).toPublicKey().toString(),
    path: c.getBaseAddressDerivationPath(),
    coin: coin,
    chain: coin,
    network: network,
    singleAddress: !!opts.singleAddress,
    id: opts.id,
  };

  network = network || 'main';
  coin = coin.toUpperCase();
  var url = `api/${coin}/${network}/wallet/`;
  self._doPostRequest(url, args, function(err, res) {
    if (err) return cb(err);

    var walletId = res._id;
    c.addWalletInfo(walletId, walletName, m, n, copayerName);
github poetapp / poet-js / src / Common.ts View on Github external
export function sign(privateKey: string, value: Uint8Array): Uint8Array {
  const signature = bitcore.crypto.ECDSA.sign(
    value,
    new bitcore.PrivateKey(privateKey)
  )
  return signature.toBuffer()
}