How to use the bitcore-lib.errors 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 / bitcore-mnemonic / test / mnemonic.unit.js View on Github external
'use strict';

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

var Mnemonic = require('..');
var errors = require('bitcore-lib').errors;
var bip39_vectors = require('./data/fixtures.json');

describe('Mnemonic', function() {
  this.timeout(30000);

  it('should initialize the class', function() {
    should.exist(Mnemonic);
  });

  describe('# Mnemonic', function() {

    describe('Constructor', function() {
      it('does not require new keyword', function() {
        var mnemonic = Mnemonic(); // jshint ignore:line
        mnemonic.should.be.instanceof(Mnemonic);
      });
github bitpay / bitcore / packages / bitcore-mnemonic / lib / mnemonic.js View on Github external
wordlist = data;
    data = null;
  }


  // handle data overloading
  var ent, phrase, seed;
  if (Buffer.isBuffer(data)) {
    seed = data;
    ent = seed.length * 8;
  } else if (_.isString(data)) {
    phrase = unorm.nfkd(data);
  } else if (_.isNumber(data)) {
    ent = data;
  } else if (data) {
    throw new bitcore.errors.InvalidArgument('data', 'Must be a Buffer, a string or an integer');
  }
  ent = ent || 128;


  // check and detect wordlist
  wordlist = wordlist || Mnemonic._getDictionary(phrase);
  if (phrase && !wordlist) {
    throw new errors.UnknownWordlist(phrase);
  }
  wordlist = wordlist || Mnemonic.Words.ENGLISH;

  if (seed) {
    phrase = Mnemonic._entropy2mnemonic(seed, wordlist);
  }
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / drivers / utxo_planner.js View on Github external
var extend = require('shallow-extend')
var blockchain = require('../blockchain')
var tx_encoder = require('../tx_encoder')

var Address = bitcore.Address
var Script = bitcore.Script
var Transaction = bitcore.Transaction
var MultiSigInput = bitcore.Transaction.Input.MultiSig
var PublicKey = bitcore.PublicKey
var Output = bitcore.Transaction.Output
var BufferReader = bitcore.encoding.BufferReader
var BufferWriter = bitcore.encoding.BufferWriter
var TxEncoder = tx_encoder.TxEncoder
var TxoCache = 'TODO: This should be a param' // TODO: cache.models.Txo

var InvalidStateError = bitcore.errors.InvalidState

var TXO_DUST = 5430
var MSG_PREFIX = 'DZ'

function MessagesError (message) {
  this.name = this.constructor.name
  this.message = 'Messages error: ' + message
  Error.captureStackTrace(this, this.constructor)
}

function InsufficientBalanceError () {
  MessagesError.call(this, 'insufficient balance to make a transaction')
}

var messageSchema = gate.createSchema({
  id: '/Message',
github bitpay / bitcore-ecies / test / ecies.js View on Github external
it('errors', function() {
    should.exist(bitcore.errors.ECIES);
  });
github bitpay / bitcore / packages / bitcore-payment-protocol / lib / errors.js View on Github external
'use strict';

var spec = {
  name: 'PaymentProtocol',
  message: 'Internal Error on bitcore-payment-protocol Module: {0}'
};

module.exports = require('bitcore-lib').errors.extend(spec);
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / messages.js View on Github external
var BufferReader = bitcore.encoding.BufferReader
var BufferWriter = bitcore.encoding.BufferWriter
var Address = bitcore.Address
var Script = bitcore.Script
var Transaction = bitcore.Transaction
var MultiSigInput = bitcore.Transaction.Input.MultiSig
var PublicKey = bitcore.PublicKey
var Output = bitcore.Transaction.Output
var TxDecoder = tx_decoder.TxDecoder
var TxEncoder = tx_encoder.TxEncoder
var TxCache = cache.models.Tx
var TipCache = cache.models.Tip
var TxoCache = cache.models.Txo

var InvalidStateError = bitcore.errors.InvalidState
var BadEncodingError = tx_decoder.BadEncodingError

var MSGS_PREFIX = 'DZ'
var CHATMSG_PREFIX = 'COMMUN'
var CIPHER_ALGORITHM = 'AES-256-CBC'
var TXO_DUST = 5430

function MessagesError (message) {
  this.name = this.constructor.name
  this.message = 'Messages error: ' + message
  Error.captureStackTrace(this, this.constructor)
}

function InsufficientBalanceError () {
  MessagesError.call(this, 'insufficient balance to make a transaction')
}
github bitpay / bitcore-wallet-service / lib / server.js View on Github external
try {
    var bitcoreTx = txp.getBitcoreTx();
    bitcoreError = bitcoreTx.getSerializationError(serializationOpts);
    if (!bitcoreError) {
      txp.fee = bitcoreTx.getFee();
    }
  } catch (ex) {
    log.error('Error building Bitcore transaction', ex);
    return ex;
  }

  if (bitcoreError instanceof Bitcore.errors.Transaction.FeeError)
    return Errors.INSUFFICIENT_FUNDS_FOR_FEE;

  if (bitcoreError instanceof Bitcore.errors.Transaction.DustOutputs)
    return Errors.DUST_AMOUNT;
  return bitcoreError;
};
github bitpay / bitcore-p2p / lib / errors.js View on Github external
'use strict';

var spec = {
  name: 'P2P',
  message: 'Internal Error on bitcore-p2p Module {0}'
};

module.exports = require('bitcore-lib').errors.extend(spec);
github bitpay / bitcore-channel / lib / errors.js View on Github external
'use strict';

var spec = {
  name: 'Channel',
  message: 'Internal Error on bitcore-channels Module {0}',
};

module.exports = require('bitcore-lib').errors.extend(spec);
github bitpay / bitcore-wallet-service / lib / server.js View on Github external
if (txp.getEstimatedSize() / 1000 > Defaults.MAX_TX_SIZE_IN_KB)
    return Errors.TX_MAX_SIZE_EXCEEDED;

  try {
    var bitcoreTx = txp.getBitcoreTx();
    bitcoreError = bitcoreTx.getSerializationError(serializationOpts);
    if (!bitcoreError) {
      txp.fee = bitcoreTx.getFee();
    }
  } catch (ex) {
    log.error('Error building Bitcore transaction', ex);
    return ex;
  }

  if (bitcoreError instanceof Bitcore.errors.Transaction.FeeError)
    return Errors.INSUFFICIENT_FUNDS_FOR_FEE;

  if (bitcoreError instanceof Bitcore.errors.Transaction.DustOutputs)
    return Errors.DUST_AMOUNT;
  return bitcoreError;
};