tips overlay security

This commit is contained in:
hatim boufnichel 2021-07-09 19:49:36 +02:00
parent 7d75c3c389
commit c49a727739
6 changed files with 52 additions and 14 deletions

View file

@ -286,7 +286,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
TipForwarder.notifySocketIfAny( TipForwarder.notifySocketIfAny(
postID, postID,
order.from, order.from,
'TIPPED YOU', paidInvoice.memo || 'TIPPED YOU',
amt + ' sats' amt + ' sats'
) )
const ackData = { tippedPost: postID } const ackData = { tippedPost: postID }

View file

@ -1,8 +1,21 @@
//@ts-nocheck TODO- fix types //@ts-nocheck TODO- fix types
const { gunUUID } = require("../utils")
class TipsCB { class TipsCB {
listeners = {} listeners = {}
addSocket(postID,socket){ postsEnabled = {}
enablePostNotifications(postID){
const accessId = gunUUID()
this.postsEnabled[accessId] = postID
return accessId
}
addSocket(accessId,socket){
if(!this.postsEnabled[accessId]){
return "invalid access id"
}
const postID = this.postsEnabled[accessId]
console.log("subbing new socket for post: "+postID) console.log("subbing new socket for post: "+postID)
if(!this.listeners[postID]){ if(!this.listeners[postID]){

View file

@ -51,8 +51,8 @@
</head> </head>
<body> <body>
<div class="main"> <div class="main">
<div class="content hide"> <div class="content">
<p id="content-name">fdsigfudfsbigbfduigbdfb</p> <p id="content-name">some random name i dont know</p>
<p id="content-message">JUST TIPPED YOU!</p> <p id="content-message">JUST TIPPED YOU!</p>
<p id="content-amount">100sats</p> <p id="content-amount">100sats</p>
</div> </div>
@ -61,9 +61,9 @@
console.log(location.origin) console.log(location.origin)
const queryString = window.location.search; const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString); const urlParams = new URLSearchParams(queryString);
const postID = urlParams.get("postID") const accessId = urlParams.get("accessId")
var socket = io(`${location.origin}/streams`); var socket = io(`${location.origin}/streams`);
socket.emit("postID",postID) socket.emit("accessId",accessId)
let latestTimeout = null let latestTimeout = null
socket.on("update",(update)=>{ socket.on("update",(update)=>{
const name = document.querySelector("#content-name") const name = document.querySelector("#content-name")

View file

@ -37,6 +37,7 @@ const GunWriteRPC = require('../services/gunDB/rpc')
const Key = require('../services/gunDB/contact-api/key') const Key = require('../services/gunDB/contact-api/key')
const { startedStream, endStream } = require('../services/streams') const { startedStream, endStream } = require('../services/streams')
const channelRequest = require('../utils/lightningServices/channelRequests') const channelRequest = require('../utils/lightningServices/channelRequests')
const TipsForwarder = require('../services/tipsCallback')
const DEFAULT_MAX_NUM_ROUTES_TO_QUERY = 10 const DEFAULT_MAX_NUM_ROUTES_TO_QUERY = 10
const SESSION_ID = uuid() const SESSION_ID = uuid()
@ -2291,11 +2292,20 @@ module.exports = async (
app.post(`/api/gun/wall/`, async (req, res) => { app.post(`/api/gun/wall/`, async (req, res) => {
try { try {
const { tags, title, contentItems } = req.body const { tags, title, contentItems, enableTipsOverlay } = req.body
const SEA = require('../services/gunDB/Mediator').mySEA const SEA = require('../services/gunDB/Mediator').mySEA
return res const postRes = await GunActions.createPostNew(
.status(200) tags,
.json(await GunActions.createPostNew(tags, title, contentItems, SEA)) title,
contentItems,
SEA
)
if (enableTipsOverlay) {
const [postID] = postRes
const accessId = TipsForwarder.enablePostNotifications(postID)
return res.status(200).json([...postRes, accessId])
}
return res.status(200).json(postRes)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
return res.status(500).json({ return res.status(500).json({
@ -3348,6 +3358,18 @@ module.exports = async (
ap.get('/api/subscribeStream', (req, res) => { ap.get('/api/subscribeStream', (req, res) => {
res.sendFile(path.join(__dirname, '/index.html')) res.sendFile(path.join(__dirname, '/index.html'))
}) })
ap.post('/api/enableNotificationsOverlay', (req, res) => {
const { postID } = req.body
if (!postID) {
return res.status(400).json({
errorMessage: 'no post id provided'
})
}
const accessId = TipsForwarder.enablePostNotifications(postID)
res.json({
accessId
})
})
//this is for wasLive/isLive status //this is for wasLive/isLive status
ap.post('/api/listenStream', (req, res) => { ap.post('/api/listenStream', (req, res) => {
try { try {

View file

@ -186,10 +186,13 @@ module.exports = (
io.of('streams').on('connect', socket => { io.of('streams').on('connect', socket => {
console.log('a user connected') console.log('a user connected')
socket.on('postID', postID => { socket.on('accessId', accessId => {
TipsForwarder.addSocket(postID, socket) const err = TipsForwarder.addSocket(accessId, socket)
if (err) {
console.log('err invalid socket for tips notifications ' + err)
socket.disconnect(true)
}
}) })
}) })
return io return io
} }

View file

@ -10,7 +10,7 @@ const { asyncFilter } = require('./helpers')
*/ */
const gunUUID = () => { const gunUUID = () => {
// @ts-expect-error Not typed // @ts-expect-error Not typed
const uuid = Gun.Text.random() const uuid = Gun.text.random()
return uuid return uuid
} }