Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
utils.sharedEncryptionKey = function (aPriv, bPub, cb) {
// TODO: unhardcode network
if (typeof aPriv !== 'string') aPriv = aPriv.toWIF(bitcoin.networks.testnet)
if (typeof bPub !== 'string') bPub = bPub.toHex()
var key = aPriv + bPub
var cached = ecdhCache.get(key)
if (!cb) {
if (!cached) {
cached = sharedEncryptionKey.apply(this, arguments)
ecdhCache.set(key, cached)
}
return cached
}
if (cached) return cb(null, cached)
sharedEncryptionKey.call(utils, aPriv, bPub, function (err, result) {
const unspents = []
opts.unspents.forEach(({ address, amounts }) => {
const tx = fund(address, amounts)
tx.outs.forEach(function (o, i) {
unspents.push({
txId: tx.getId(),
confirmations: 6,
address,
value: o.value,
vout: i
})
})
})
const fakechain = createFakeChain({
network: bitcoin.networks[network.name],
unspents,
blocktime
})
const wrapper = utils.extend(new EventEmitter(), network.wrapCommonBlockchain(fakechain))
fakechain.on('block', block => wrapper.emit('block', block))
return wrapper
}