Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function check(addresses) {
if (!addresses) return;
for(var i = 0; i < addresses.length; i++) {
try {
new bitcore.Address(addresses[i]);
} catch(e) {
throw addresses[i];
}
}
}
WalletService.prototype._getUtxos = function(addresses, cb) {
var self = this;
if (addresses.length == 0) return cb(null, []);
var networkName = Bitcore.Address(addresses[0]).toObject().network;
var bc = self._getBlockchainExplorer(networkName);
bc.getUtxos(addresses, function(err, utxos) {
if (err) return cb(err);
var utxos = _.map(utxos, function(utxo) {
var u = _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis', 'confirmations']);
u.confirmations = u.confirmations || 0;
u.locked = false;
u.satoshis = _.isNumber(u.satoshis) ? +u.satoshis : Utils.strip(u.amount * 1e8);
delete u.amount;
return u;
});
return cb(null, utxos);
});
address(index:number, change:boolean):string{
var chain:number = change ? 1 : 0;
return new bitcore.Address(this.hdPublicKey.derive(chain).derive(index).publicKey).toString();
}
TxProposal._create.simple = function(txp, opts) {
txp.toAddress = opts.toAddress;
txp.amount = opts.amount;
txp.outputOrder = _.shuffle(_.range(2));
try {
txp.network = Bitcore.Address(txp.toAddress).toObject().network;
} catch (ex) {}
};
function WalletAddressMap(address, walletIds, network) {
if (!(this instanceof WalletAddressMap)) {
return new WalletAddressMap(address, walletIds, network);
}
assert(Array.isArray(walletIds), '"walletIds" is expected to be an array');
assert(address, '"address" is required for a wallet address');
assert(network, '"network" is expected');
this.address = new bitcore.Address(address, network);
this.walletIds = walletIds;
}
function WalletAddress(walletId, address) {
if (!(this instanceof WalletAddress)) {
return new WalletAddress(walletId, address);
}
assert(walletId, '"walletId" is required for a wallet address');
assert(address, '"address" is required for a wallet address');
this._initWalletId(walletId);
this.address = new bitcore.Address(address);
}
addressStr = req.body.address;
} else {
addressStr = req.params.address;
}
if(!addressStr) {
return utils.sendError({
message: 'Address param is expected',
statusCode: 400
}, res);
}
assert(req.network, '"network" is expected to be set on the request');
try {
address = new bitcore.Address(addressStr, req.network);
} catch(e) {
return utils.sendError({
message: 'Invalid address: ' + e.message,
statusCode: 400
}, res);
}
req.address = address;
next();
};
function getNormalizedTxs(addresses, from, to, cb) {
var txs, fromCache, totalItems;
var useCache = addresses.length >= Defaults.HISTORY_CACHE_ADDRESS_THRESOLD;
var network = Bitcore.Address(addresses[0].address).toObject().network;
async.series([
function(next) {
if (!useCache) return next();
self.storage.getTxHistoryCache(self.walletId, from, to, function(err, res) {
if (err) return next(err);
if (!res || !res[0]) return next();
txs = res;
fromCache = true;
return next()
});
},
PublicWallet.prototype.getAddress = function (index) {
return new bitcore.Address(this.hdPublicKey.derive(0).derive(index).publicKey);
};
PublicWallet.prototype.getBalance = function (index) {
/**
* @type bitcore.PrivateKey
* @desc This is the key used for the 2-of-2 locking of funds
*/
this.commitmentKey = new PrivateKey(opts.commitmentKey);
/**
* @type {bitcore.PublicKey}
*/
this.providerPublicKey = new PublicKey(opts.providerPublicKey);
/**
* @type {bitcore.Address|string}
* @desc The address where the server will be paid.
*/
this.providerAddress = opts.providerAddress ? new Address(opts.providerAddress) : this.providerPublicKey.toAddress();
/**
* @type bitcore.PrivateKey
* @desc A private key for funding the channel. An alternative implementation could
* provide a list of unspent outputs and the keys needed to sign the outputs
*/
$.checkArgument(opts.fundingKey instanceof PrivateKey, 'fundingKey is expected to be a PrivateKey');
this.fundingKey = opts.fundingKey;
/**
* @type bitcore.Address
* @desc The address where the user will pay to fund the channel
*/
this.fundingAddress = this.fundingKey.toAddress();
$.checkArgument(opts.refundAddress, 'refundAddress is expected');