diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index a906c2a3..bcf10e8c 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -33,6 +33,8 @@ const $$__SHOCKWALLET__MSG__ = '$$__SHOCKWALLET__MSG__' const $$__SHOCKWALLET__NUMBER__ = '$$__SHOCKWALLET__NUMBER__' const $$__SHOCKWALLET__BOOLEAN__ = '$$__SHOCKWALLET__BOOLEAN__' +/// + mySEA.encrypt = (msg, secret) => { if (typeof secret !== 'string') { throw new TypeError( @@ -280,6 +282,9 @@ const isAuthenticated = () => typeof user.is === 'object' && user.is !== null const isAuthenticating = () => _isAuthenticating const isRegistering = () => _isRegistering +/** + * @returns {Smith.GunSmithNode} + */ const getGun = () => { throw new Error('NO GUNS') } diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index b1b8243a..f63e665a 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -306,8 +306,10 @@ const setCurrentStreamInfo = (encryptedCurrentStreamInfo, user) => /** * @typedef {object} SpontaneousPaymentOptions - * @prop {Common.Schema.OrderTargetType} type + * @prop {Common.Schema.OrderTargetType=} type * @prop {string=} ackInfo + * @prop {number=} maxParts + * @prop {number=} timeoutSeconds */ /** * @typedef {object} OrderRes @@ -330,7 +332,7 @@ const sendSpontaneousPayment = async ( amount, memo, feeLimit, - opts = { type: 'spontaneousPayment' } + { ackInfo, maxParts, timeoutSeconds, type = 'spontaneousPayment' } ) => { try { const SEA = require('../Mediator').mySEA @@ -338,12 +340,12 @@ const sendSpontaneousPayment = async ( const myPub = getUser()._.sea.pub if ( to === myPub && - opts.type === 'torrentSeed' && - opts.ackInfo && - !isNaN(parseInt(opts.ackInfo, 10)) + type === 'torrentSeed' && + ackInfo && + !isNaN(parseInt(ackInfo, 10)) ) { //user requested a seed to themselves - const numberOfTokens = Number(opts.ackInfo) || 1 + const numberOfTokens = Number(ackInfo) || 1 const seedInfo = selfContentToken() if (!seedInfo) { throw new Error('torrentSeed service not available') @@ -375,8 +377,8 @@ const sendSpontaneousPayment = async ( from: getUser()._.sea.pub, memo: memo || 'no memo', timestamp: Date.now(), - targetType: opts.type, - ackInfo: opts.ackInfo + targetType: type, + ackInfo } logger.info(JSON.stringify(order)) @@ -496,18 +498,20 @@ const sendSpontaneousPayment = async ( const payment = await sendPaymentV2Invoice({ feeLimit, - payment_request: orderResponse.response + payment_request: orderResponse.response, + max_parts: maxParts, + timeoutSeconds }) const myLndPub = LNDHealthManager.lndPub if ( - (opts.type !== 'contentReveal' && - opts.type !== 'torrentSeed' && - opts.type !== 'service' && - opts.type !== 'product') || + (type !== 'contentReveal' && + type !== 'torrentSeed' && + type !== 'service' && + type !== 'product') || !orderResponse.ackNode ) { SchemaManager.AddOrder({ - type: opts.type, + type, amount: parseInt(payment.value_sat, 10), coordinateHash: payment.payment_hash, coordinateIndex: parseInt(payment.payment_index, 10), @@ -580,7 +584,7 @@ const sendSpontaneousPayment = async ( throw new Error(`expected orderAck response, got: ${orderAck.type}`) } SchemaManager.AddOrder({ - type: opts.type, + type, amount: parseInt(payment.value_sat, 10), coordinateHash: payment.payment_hash, coordinateIndex: parseInt(payment.payment_index, 10), @@ -606,12 +610,24 @@ const sendSpontaneousPayment = async ( * @param {number} amount * @param {string} memo * @param {number} feeLimit + * @param {number=} maxParts + * @param {number=} timeoutSeconds * @throws {Error} If no response in less than 20 seconds from the recipient, or * lightning cannot find a route for the payment. * @returns {Promise} The payment's preimage. */ -const sendPayment = async (to, amount, memo, feeLimit) => { - const res = await sendSpontaneousPayment(to, amount, memo, feeLimit) +const sendPayment = async ( + to, + amount, + memo, + feeLimit, + maxParts, + timeoutSeconds +) => { + const res = await sendSpontaneousPayment(to, amount, memo, feeLimit, { + maxParts, + timeoutSeconds + }) if (!res.payment) { throw new Error('invalid payment params') //only if it's a torrentSeed request to self } diff --git a/src/routes.js b/src/routes.js index 48d33775..76037045 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1189,7 +1189,7 @@ module.exports = async ( lightning.listPayments( { // TODO - include_incomplete: !!req.include_incomplete + include_incomplete: !!req.body.include_incomplete }, (err, { payments = [] } = {}) => { if (err) { @@ -2630,7 +2630,7 @@ module.exports = async ( } }) - app.get('/api/accessInfo', async (req, res) => { + app.get('/api/accessInfo', (req, res) => { if (req.ip !== '127.0.0.1') { res.json({ field: 'origin', diff --git a/src/server.js b/src/server.js index 1425b31e..38ad63bc 100644 --- a/src/server.js +++ b/src/server.js @@ -280,7 +280,7 @@ const server = program => { saveUninitialized: true }) ) - app.use(bodyParser.urlencoded({ extended: 'true' })) + app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.json({ limit: '500kb' })) app.use(bodyParser.json({ type: 'application/vnd.api+json' })) app.use(methodOverride()) @@ -323,7 +323,7 @@ const server = program => { const serverInstance = await createServer() - const io = require('socket.io')(serverInstance, { + require('socket.io')(serverInstance, { parser: binaryParser, transports: ['websocket', 'polling'], cors: { diff --git a/utils/GunSmith/GunSmith.js b/utils/GunSmith/GunSmith.js index b755c2ab..a13a7b3d 100644 --- a/utils/GunSmith/GunSmith.js +++ b/utils/GunSmith/GunSmith.js @@ -288,7 +288,13 @@ const forge = () => { } await new Promise(res => { currentGun.on('message', msg => { - if (msg.type === 'init') { + if (typeof msg !== 'object') { + throw new Error(`msg.type !== object`) + } + + const message = /** @type {{type: string}} */ (msg) + + if (message.type === 'init') { // @ts-ignore res() }