Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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);
});
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);
}
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',
it('errors', function() {
should.exist(bitcore.errors.ECIES);
});
'use strict';
var spec = {
name: 'PaymentProtocol',
message: 'Internal Error on bitcore-payment-protocol Module: {0}'
};
module.exports = require('bitcore-lib').errors.extend(spec);
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')
}
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;
};
'use strict';
var spec = {
name: 'P2P',
message: 'Internal Error on bitcore-p2p Module {0}'
};
module.exports = require('bitcore-lib').errors.extend(spec);
'use strict';
var spec = {
name: 'Channel',
message: 'Internal Error on bitcore-channels Module {0}',
};
module.exports = require('bitcore-lib').errors.extend(spec);
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;
};