decryption for socket gun rpc
This commit is contained in:
parent
b8199660ca
commit
9069ae0921
1 changed files with 22 additions and 4 deletions
|
|
@ -12,7 +12,16 @@ const {
|
||||||
getUser,
|
getUser,
|
||||||
isAuthenticated
|
isAuthenticated
|
||||||
} = require('../services/gunDB/Mediator')
|
} = require('../services/gunDB/Mediator')
|
||||||
|
const { deepDecryptIfNeeded } = require('../services/gunDB/rpc')
|
||||||
|
/**
|
||||||
|
* @typedef {import('../services/gunDB/Mediator').SimpleSocket} SimpleSocket
|
||||||
|
* @typedef {import('../services/gunDB/contact-api/SimpleGUN').ValidDataValue} ValidDataValue
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {SimpleSocket} socket
|
||||||
|
* @param {string} subID
|
||||||
|
*/
|
||||||
const onPing = (socket, subID) => {
|
const onPing = (socket, subID) => {
|
||||||
logger.warn('Subscribing to pings socket...' + subID)
|
logger.warn('Subscribing to pings socket...' + subID)
|
||||||
|
|
||||||
|
|
@ -299,7 +308,7 @@ module.exports = (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { $shock } = socket.handshake.query
|
const { $shock, publicKeyForDecryption } = socket.handshake.query
|
||||||
|
|
||||||
const [root, path, method] = $shock.split('::')
|
const [root, path, method] = $shock.split('::')
|
||||||
|
|
||||||
|
|
@ -319,12 +328,21 @@ module.exports = (
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {unknown} data
|
* @param {ValidDataValue} data
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
*/
|
*/
|
||||||
const listener = (data, key) => {
|
const listener = async (data, key) => {
|
||||||
try {
|
try {
|
||||||
|
if (publicKeyForDecryption) {
|
||||||
|
const decData = await deepDecryptIfNeeded(
|
||||||
|
data,
|
||||||
|
publicKeyForDecryption
|
||||||
|
)
|
||||||
|
|
||||||
|
socket.emit('$shock', decData, key)
|
||||||
|
} else {
|
||||||
socket.emit('$shock', data, key)
|
socket.emit('$shock', data, key)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Error for gun rpc socket, query ${$shock} -> ${err.message}`
|
`Error for gun rpc socket, query ${$shock} -> ${err.message}`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue