How to use the bitcore-lib.util 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 bitpay / bwdb / lib / models / txids.js View on Github external
WalletTxids.prototype.insert = function(height, blockIndex, txid) {
  assert(bitcore.util.js.isNaturalNumber(height));
  assert(bitcore.util.js.isNaturalNumber(blockIndex));
  assert(Buffer.isBuffer(txid) && txid.length === 32);
  var position = new Buffer(new Array(8));
  position.writeUInt32BE(height);
  position.writeUInt32BE(blockIndex, 4);
  var lower = this._searchLowerBound(position);
  if (lower.found) {
    // Duplicate position exists
    return false;
  }
  var item = Buffer.concat([position, txid]);
  var pos = lower.index + 1;
  this._data.splice(pos, 0, item);
  return pos;
};
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / drivers / blockchain_dot_info.js View on Github external
var inherits = require('inherits')
var extend = require('shallow-extend')
var bitcore = require('bitcore-lib')

var webExplorer = require('./web_explorer')

var $ = bitcore.util.preconditions

var UnsupportedFeatureError = webExplorer.UnsupportedFeatureError
var NoUtxosError = webExplorer.NoUtxosError
var WebExplorer = webExplorer.WebExplorer

function BlockchainDotInfo (options, cb) {
  if (!options) options = {}

  this.__defineGetter__('baseUrl', function () {
    // TODO: Handle a tor parameter to change the url
    // TODO: Handle a secure parameter to change the http/s
    return 'https://blockchain.info/'
  })

  $.checkState((!options.isMutable),
    'Blockchain.info only supports immutable blockchains')
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / drivers / blockr_io.js View on Github external
var inherits = require('inherits')
var extend = require('shallow-extend')
var bitcore = require('bitcore-lib')

var webExplorer = require('./web_explorer')

var $ = bitcore.util.preconditions

var UnsupportedFeatureError = webExplorer.UnsupportedFeatureError
var MalformedResponseError = webExplorer.MalformedResponseError
var RelayUnacceptedError = webExplorer.RelayUnacceptedError
var NoUtxosError = webExplorer.NoUtxosError
var WebExplorer = webExplorer.WebExplorer

function BlockrIo (options, cb) {
  if (!options) options = {}

  this.__defineGetter__('baseUrl', function () {
    // TODO: Handle a proto parameter to change the http/s
    return (this.isMutable) ? 'https://tbtc.blockr.io/' : 'https://btc.blockr.io/'
  })

  var Super = this.constructor.super_
github bitpay / bitcore-p2p / test / inventory.js View on Github external
'use strict';

/*jshint immed: false */

var should = require('chai').should();

var bitcore = require('bitcore-lib');
var P2P = require('../');
var Inventory = P2P.Inventory;
var BufferUtils = bitcore.util.buffer;
var BufferWriter = bitcore.encoding.BufferWriter;
var BufferReader = bitcore.encoding.BufferReader;

describe('Inventory', function() {

  var hash = new Buffer('eb951630aba498b9a0d10f72b5ea9e39d5ff04b03dc2231e662f52057f948aa1', 'hex');
  var hashedStr = BufferUtils.reverse(new Buffer(hash, 'hex')).toString('hex');
  var inventoryBuffer = new Buffer(
    '01000000eb951630aba498b9a0d10f72b5ea9e39d5ff04b03dc2231e662f52057f948aa1',
    'hex'
  );

  describe('@constructor', function() {
    it('create inventory', function() {
      var inventory = new Inventory({type: Inventory.TYPE.TX, hash: hash});
      should.exist(inventory);
github bitpay / bitcore-node / lib / services / block / reorg.js View on Github external
'use strict';
var bitcore = require('bitcore-lib');
var BufferUtil = bitcore.util.buffer;
var async = require('async');

function Reorg(node, block) {
  this.node = node;
  this.block = block;
  this.db = block.db;
}

Reorg.prototype.handleReorg = function(newBlockHash, callback) {
  var self = this;

  self.handleConcurrentReorg(function(err) {
    if(err) {
      return callback(err);
    }
github bitpay / bitcore-channel / lib / provider.js View on Github external
'use strict';

var Payment = require('./transactions/payment');
var Refund = require('./transactions/refund');

var $ = require('bitcore-lib').util.preconditions;
var PrivateKey = require('bitcore-lib').PrivateKey;
var Script = require('bitcore-lib').Script;
var Address = require('bitcore-lib').Address;
var Networks = require('bitcore-lib').Networks;
var _ = require('bitcore-lib').deps._;

/**
 * @constructor
 */
function Provider(opts) {
  this.network = Networks.get(opts.network) || Networks.defaultNetwork;
  if (!opts.paymentAddress) {
    this.paymentKey = new PrivateKey();
    this.paymentAddress = this.paymentKey.toAddress(this.network);
  } else {
    this.paymentAddress = new Address(opts.paymentAddress);
github bitpay / bitcore-node / lib / services / address / streams / inputs-transform.js View on Github external
'use strict';

var Transform = require('stream').Transform;
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib');
var encodingUtil = require('../../../encoding');
var $ = bitcore.util.preconditions;

function InputsTransformStream(options) {
  $.checkArgument(options.address instanceof bitcore.Address);
  Transform.call(this, {
    objectMode: true
  });
  this._address = options.address;
  this._addressStr = this._address.toString();
  this._tipHeight = options.tipHeight;
}
inherits(InputsTransformStream, Transform);

InputsTransformStream.prototype._transform = function(chunk, encoding, callback) {
  var self = this;

  var key = encodingUtil.decodeInputKey(chunk.key);
github bitpay / bitcore-ecies / lib / aes.js View on Github external
'use strict';

var bitcore = require('bitcore-lib');
var $ = bitcore.util.preconditions;
var aes = require('aes');

var AES = function AES() {};

AES.encrypt = function(messagebuf, keybuf) {
  var key = AES.buf2words(keybuf);
  var message = AES.buf2words(messagebuf);
  var a = new aes(key);
  var enc = a.encrypt(message);
  var encbuf = AES.words2buf(enc);
  return encbuf;
};

AES.decrypt = function(encbuf, keybuf) {
  var enc = AES.buf2words(encbuf);
  var key = AES.buf2words(keybuf);
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / message_base.js View on Github external
var _ = require('lodash')
var bitcore = require('bitcore-lib')
var validator = require('node-validator')
var util = require('util')

var $ = bitcore.util.preconditions

var Varint = bitcore.encoding.Varint
var BufferReader = bitcore.encoding.BufferReader

var DEFAULT_FEE = 40000

function toVarString(buf) {
  return new Buffer.concat([new Varint(buf.length).buf, new Buffer(buf)])
}

function MessageBase (connection, options) {
  $.checkArgument(connection, 
    'First argument is required, please include a connection.')

  var messageAttribs = {}
  var messageIntegers = []
github bitpay / bitcore-message / lib / message.js View on Github external
'use strict';

var bitcore = require('bitcore-lib');
var _ = bitcore.deps._;
var PrivateKey = bitcore.PrivateKey;
var PublicKey = bitcore.PublicKey;
var Address = bitcore.Address;
var BufferWriter = bitcore.encoding.BufferWriter;
var ECDSA = bitcore.crypto.ECDSA;
var Signature = bitcore.crypto.Signature;
var sha256sha256 = bitcore.crypto.Hash.sha256sha256;
var JSUtil = bitcore.util.js;
var $ = bitcore.util.preconditions;

/**
 * constructs a new message to sign and verify.
 *
 * @param {String} message
 * @returns {Message}
 */
var Message = function Message(message) {
  if (!(this instanceof Message)) {
    return new Message(message);
  }
  $.checkArgument(_.isString(message), 'First argument should be a string');
  this.message = message;

  return this;
};