From 449bba1913535abe6fdd1d12afd0303a80867891 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 15:21:51 -0500 Subject: [PATCH 1/9] Doesn't need to be async --- src/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 48d33775..42df908d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -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', From 6d9bff23c0427d8e61381fdbf29b51726b36b927 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 15:34:20 -0500 Subject: [PATCH 2/9] Actually fetch the incomplete papramter from the request body --- src/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 42df908d..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) { From cecf6a9d2e394a6d11c9c723b4909c2558cf436f Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 15:35:32 -0500 Subject: [PATCH 3/9] Return typing even though it's not currently used --- services/gunDB/Mediator/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index a906c2a3..dba5a510 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -280,6 +280,9 @@ const isAuthenticated = () => typeof user.is === 'object' && user.is !== null const isAuthenticating = () => _isAuthenticating const isRegistering = () => _isRegistering +/** + * @returns {import('../contact-api/SimpleGUN').GUNNode} + */ const getGun = () => { throw new Error('NO GUNS') } From fffe1313fd654156804b11ee41b7065f808129c9 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 15:41:40 -0500 Subject: [PATCH 4/9] Correct typings and parameters for spontaneous payments --- services/gunDB/contact-api/actions.js | 50 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 17 deletions(-) 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 } From 191e6c068d953b14607cabe4c9650b6f77738600 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 15:52:11 -0500 Subject: [PATCH 5/9] Use Gunsmith typing instead of old SimpleGun typing --- services/gunDB/Mediator/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index dba5a510..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( @@ -281,7 +283,7 @@ const isAuthenticating = () => _isAuthenticating const isRegistering = () => _isRegistering /** - * @returns {import('../contact-api/SimpleGUN').GUNNode} + * @returns {Smith.GunSmithNode} */ const getGun = () => { throw new Error('NO GUNS') From f6c4999c63df234cb759c849573cbc46cea7adb9 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 16:24:02 -0500 Subject: [PATCH 6/9] Unbind unused declaration --- src/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 1425b31e..24b48e8a 100644 --- a/src/server.js +++ b/src/server.js @@ -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: { From 2e65d20c39dd707b9d80af5440eb0be3d3326a8a Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 16:26:21 -0500 Subject: [PATCH 7/9] This paremeter is boolean not string --- src/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 24b48e8a..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()) From f233394d0d87eafdfeb6f0f82f9040690e8154bc Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 29 Jan 2022 16:37:03 -0500 Subject: [PATCH 8/9] Please typescript by double checking type --- utils/GunSmith/GunSmith.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() } From de1facc8a68e8d85e8632355f64d415437cbc1d4 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 31 Jan 2022 08:54:40 -0500 Subject: [PATCH 9/9] Upgrade commander --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 609a9adb..36cc88f4 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "body-parser": "^1.16.0", "colors": "^1.4.0", "command-exists": "^1.2.6", - "commander": "^2.9.0", + "commander": "^9.0.0", "compression": "^1.7.4", "cors": "^2.8.5", "debug": "^3.1.0", diff --git a/yarn.lock b/yarn.lock index 13e45cff..4170c11e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1376,16 +1376,16 @@ command-exists@^1.2.6: resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69" integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w== -commander@^2.9.0: - version "2.20.3" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" - integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== - commander@^6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== +commander@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-9.0.0.tgz#86d58f24ee98126568936bd1d3574e0308a99a40" + integrity sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw== + compare-versions@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"