Merge pull request #324 from shocknet/bug/socket-args
Fixed socket emits not sending multiple arguments
This commit is contained in:
commit
d8102a3377
4 changed files with 14 additions and 9 deletions
|
|
@ -226,6 +226,7 @@ const Config = require('../config')
|
|||
/**
|
||||
* @typedef {import('../contact-api/SimpleGUN').GUNNode} GUNNode
|
||||
* @typedef {import('../contact-api/SimpleGUN').UserGUNNode} UserGUNNode
|
||||
* @typedef {import('../contact-api/SimpleGUN').ValidDataValue} ValidDataValue
|
||||
*/
|
||||
|
||||
// TO DO: move to common repo
|
||||
|
|
@ -254,7 +255,7 @@ const Config = require('../config')
|
|||
// TO DO: move to common repo
|
||||
/**
|
||||
* @typedef {object} SimpleSocket
|
||||
* @prop {(eventName: string, data?: Emission|EncryptedEmissionLegacy|EncryptedEmission) => void} emit
|
||||
* @prop {(eventName: string, data?: Emission|EncryptedEmissionLegacy|EncryptedEmission|ValidDataValue) => void} emit
|
||||
* @prop {(eventName: string, handler: (data: any) => void) => void} on
|
||||
* @prop {{ query: { 'x-shockwallet-device-id': string, encryptionId: string }}} handshake
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -296,9 +296,9 @@ module.exports = (
|
|||
publicKeyForDecryption
|
||||
)
|
||||
|
||||
emit('$shock', decData)
|
||||
emit('$shock', decData, key)
|
||||
} else {
|
||||
emit('$shock', data)
|
||||
emit('$shock', data, key)
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
|
|
|
|||
|
|
@ -83,10 +83,11 @@ const authorizeDevice = async ({ deviceId, publicKey }) => {
|
|||
/**
|
||||
* Encrypts the specified message using the specified deviceId's
|
||||
* public key
|
||||
* @param {{ deviceId: string, message: string }} arg0
|
||||
* @param {{ deviceId: string, message: string | number | boolean }} arg0
|
||||
* @returns {Promise<import('./crypto').EncryptedMessageResponse>}
|
||||
*/
|
||||
const encryptMessage = async ({ message = '', deviceId }) => {
|
||||
const parsedMessage = message.toString()
|
||||
const publicKey = devicePublicKeys.get(deviceId)
|
||||
|
||||
if (!publicKey) {
|
||||
|
|
@ -97,7 +98,7 @@ const encryptMessage = async ({ message = '', deviceId }) => {
|
|||
}
|
||||
|
||||
const processedPublicKey = processKey(publicKey)
|
||||
const messageBuffer = convertUTF8ToBuffer(message)
|
||||
const messageBuffer = convertUTF8ToBuffer(parsedMessage)
|
||||
const encryptedMessage = await ECCrypto.encrypt(
|
||||
processedPublicKey,
|
||||
messageBuffer
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ const nonEncryptedEvents = [
|
|||
* @typedef {import('../../services/gunDB/Mediator').Emission} Emission
|
||||
* @typedef {import('../../services/gunDB/Mediator').EncryptedEmission} EncryptedEmission
|
||||
* @typedef {import('../../services/gunDB/Mediator').EncryptedEmissionLegacy} EncryptedEmissionLegacy
|
||||
* @typedef {import('../../services/gunDB/contact-api/SimpleGUN').ValidDataValue} ValidDataValue
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +29,7 @@ const isNonEncrypted = eventName => nonEncryptedEvents.includes(eventName)
|
|||
|
||||
/**
|
||||
* @param {SimpleSocket} socket
|
||||
* @returns {(eventName: string, args?: Emission | EncryptedEmission | EncryptedEmissionLegacy) => Promise<void>}
|
||||
* @returns {(eventName: string, ...args: any[]) => Promise<void>}
|
||||
*/
|
||||
const encryptedEmit = socket => async (eventName, ...args) => {
|
||||
try {
|
||||
|
|
@ -55,19 +56,21 @@ const encryptedEmit = socket => async (eventName, ...args) => {
|
|||
}
|
||||
|
||||
const encryptedArgs = await Promise.all(
|
||||
args.map(data => {
|
||||
args.map(async data => {
|
||||
if (!data) {
|
||||
return data
|
||||
}
|
||||
|
||||
return ECC.encryptMessage({
|
||||
const encryptedMessage = await ECC.encryptMessage({
|
||||
message: typeof data === 'object' ? JSON.stringify(data) : data,
|
||||
deviceId
|
||||
})
|
||||
|
||||
return encryptedMessage
|
||||
})
|
||||
)
|
||||
|
||||
console.log('Encrypted args:', encryptedArgs)
|
||||
console.log('Encrypted args:', encryptedArgs, args)
|
||||
|
||||
return socket.emit(eventName, ...encryptedArgs)
|
||||
} catch (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue