From e2bb817c6f9c9409ab2131f17eb1b678b4503287 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Thu, 8 May 2025 22:14:34 +0300 Subject: [PATCH] fix qrs, added publish apps with multi-name, fixed publish qdn data for multi names --- src/background-cases.ts | 1738 ++++++++++++----------- src/backgroundFunctions/encryption.ts | 12 +- src/components/Apps/AppPublish.tsx | 25 +- src/components/Apps/AppsDesktop.tsx | 9 +- src/components/Apps/AppsHomeDesktop.tsx | 3 +- src/components/Apps/AppsPrivate.tsx | 63 +- src/components/Group/Group.tsx | 3 +- src/qortalRequests/get.ts | 41 +- 8 files changed, 1029 insertions(+), 865 deletions(-) diff --git a/src/background-cases.ts b/src/background-cases.ts index d4ab82a..eff3a0f 100644 --- a/src/background-cases.ts +++ b/src/background-cases.ts @@ -56,22 +56,28 @@ import { setGroupData, updateThreadActivity, walletVersion, -} from "./background"; -import { decryptGroupEncryption, encryptAndPublishSymmetricKeyGroupChat, encryptAndPublishSymmetricKeyGroupChatForAdmins, publishGroupEncryptedResource, publishOnQDN } from "./backgroundFunctions/encryption"; -import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from "./constants/codes"; -import Base58 from "./deps/Base58"; -import { encryptSingle } from "./qdn/encryption/group-encryption"; -import { _createPoll, _voteOnPoll } from "./qortalRequests/get"; -import { createTransaction } from "./transactions/transactions"; -import { getData, storeData } from "./utils/chromeStorage"; +} from './background'; +import { + decryptGroupEncryption, + encryptAndPublishSymmetricKeyGroupChat, + encryptAndPublishSymmetricKeyGroupChatForAdmins, + publishGroupEncryptedResource, + publishOnQDN, +} from './backgroundFunctions/encryption'; +import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from './constants/codes'; +import Base58 from './deps/Base58'; +import { encryptSingle } from './qdn/encryption/group-encryption'; +import { _createPoll, _voteOnPoll } from './qortalRequests/get'; +import { createTransaction } from './transactions/transactions'; +import { getData, storeData } from './utils/chromeStorage'; export function versionCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "version", - payload: { version: "1.0" }, - type: "backgroundMessageResponse", + action: 'version', + payload: { version: '1.0' }, + type: 'backgroundMessageResponse', }, event.origin ); @@ -82,14 +88,14 @@ export async function getWalletInfoCase(request, event) { const response = await getKeyPair(); try { - const walletInfo = await getData('walletInfo').catch((error)=> null) - if(walletInfo){ + const walletInfo = await getData('walletInfo').catch((error) => null); + if (walletInfo) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", + action: 'getWalletInfo', payload: { walletInfo, hasKeyPair: true }, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -97,36 +103,34 @@ export async function getWalletInfoCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", - error: "No wallet info found", - type: "backgroundMessageResponse", + action: 'getWalletInfo', + error: 'No wallet info found', + type: 'backgroundMessageResponse', }, event.origin ); } - } catch (error) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", - error: "No wallet info found", - type: "backgroundMessageResponse", + action: 'getWalletInfo', + error: 'No wallet info found', + type: 'backgroundMessageResponse', }, event.origin ); } - } catch (error) { try { - const walletInfo = await getData('walletInfo').catch((error)=> null) - if(walletInfo){ + const walletInfo = await getData('walletInfo').catch((error) => null); + if (walletInfo) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", + action: 'getWalletInfo', payload: { walletInfo, hasKeyPair: false }, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -134,9 +138,9 @@ export async function getWalletInfoCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", - error: "Wallet not authenticated", - type: "backgroundMessageResponse", + action: 'getWalletInfo', + error: 'Wallet not authenticated', + type: 'backgroundMessageResponse', }, event.origin ); @@ -145,14 +149,13 @@ export async function getWalletInfoCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getWalletInfo", - error: "Wallet not authenticated", - type: "backgroundMessageResponse", + action: 'getWalletInfo', + error: 'Wallet not authenticated', + type: 'backgroundMessageResponse', }, event.origin ); } - } } @@ -163,9 +166,9 @@ export async function validApiCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "validApi", + action: 'validApi', payload: usableApi, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -173,9 +176,9 @@ export async function validApiCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "validApi", + action: 'validApi', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -189,9 +192,9 @@ export async function nameCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "name", + action: 'name', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -199,9 +202,9 @@ export async function nameCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "name", + action: 'name', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -215,9 +218,9 @@ export async function userInfoCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "userInfo", + action: 'userInfo', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -225,9 +228,9 @@ export async function userInfoCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "userInfo", - error: "User not authenticated", - type: "backgroundMessageResponse", + action: 'userInfo', + error: 'User not authenticated', + type: 'backgroundMessageResponse', }, event.origin ); @@ -235,15 +238,19 @@ export async function userInfoCase(request, event) { } export async function decryptWalletCase(request, event) { - try { + try { const { password, wallet } = request.payload; - const response = await decryptWallet({password, wallet, walletVersion: wallet?.version || walletVersion}); + const response = await decryptWallet({ + password, + wallet, + walletVersion: wallet?.version || walletVersion, + }); event.source.postMessage( { requestId: request.requestId, - action: "decryptWallet", + action: 'decryptWallet', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -251,9 +258,9 @@ export async function decryptWalletCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "decryptWallet", + action: 'decryptWallet', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -267,9 +274,9 @@ export async function balanceCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "balance", + action: 'balance', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -277,9 +284,9 @@ export async function balanceCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "balance", + action: 'balance', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -292,9 +299,9 @@ export async function ltcBalanceCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "ltcBalance", + action: 'ltcBalance', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -302,9 +309,9 @@ export async function ltcBalanceCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "ltcBalance", + action: 'ltcBalance', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -319,9 +326,9 @@ export async function sendCoinCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "sendCoin", + action: 'sendCoin', error: res?.data?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -330,9 +337,9 @@ export async function sendCoinCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "sendCoin", + action: 'sendCoin', payload: true, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -340,9 +347,9 @@ export async function sendCoinCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "sendCoin", + action: 'sendCoin', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -361,9 +368,9 @@ export async function inviteToGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "inviteToGroup", + action: 'inviteToGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -371,9 +378,9 @@ export async function inviteToGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "inviteToGroup", + action: 'inviteToGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -388,9 +395,9 @@ export async function saveTempPublishCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "saveTempPublish", + action: 'saveTempPublish', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -398,9 +405,9 @@ export async function saveTempPublishCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "saveTempPublish", + action: 'saveTempPublish', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -414,9 +421,9 @@ export async function getTempPublishCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTempPublish", + action: 'getTempPublish', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -424,9 +431,9 @@ export async function getTempPublishCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTempPublish", + action: 'getTempPublish', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -455,9 +462,9 @@ export async function createGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "createGroup", + action: 'createGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -465,9 +472,9 @@ export async function createGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "createGroup", + action: 'createGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -482,9 +489,9 @@ export async function cancelInvitationToGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "cancelInvitationToGroup", + action: 'cancelInvitationToGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -492,9 +499,9 @@ export async function cancelInvitationToGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "cancelInvitationToGroup", + action: 'cancelInvitationToGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -509,9 +516,9 @@ export async function leaveGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "leaveGroup", + action: 'leaveGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -519,9 +526,9 @@ export async function leaveGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "leaveGroup", + action: 'leaveGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -536,9 +543,9 @@ export async function joinGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "joinGroup", + action: 'joinGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -546,9 +553,9 @@ export async function joinGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "joinGroup", + action: 'joinGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -567,9 +574,9 @@ export async function kickFromGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "kickFromGroup", + action: 'kickFromGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -577,9 +584,9 @@ export async function kickFromGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "kickFromGroup", + action: 'kickFromGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -599,9 +606,9 @@ export async function banFromGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "banFromGroup", + action: 'banFromGroup', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -609,9 +616,9 @@ export async function banFromGroupCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "banFromGroup", + action: 'banFromGroup', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -621,14 +628,14 @@ export async function banFromGroupCase(request, event) { export async function addDataPublishesCase(request, event) { try { const { data, groupId, type } = request.payload; - const response = await addDataPublishes( data, groupId, type ); + const response = await addDataPublishes(data, groupId, type); event.source.postMessage( { requestId: request.requestId, - action: "addDataPublishes", + action: 'addDataPublishes', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -636,9 +643,9 @@ export async function addDataPublishesCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addDataPublishes", + action: 'addDataPublishes', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -648,14 +655,14 @@ export async function addDataPublishesCase(request, event) { export async function getDataPublishesCase(request, event) { try { const { groupId, type } = request.payload; - const response = await getDataPublishes(groupId, type ); + const response = await getDataPublishes(groupId, type); event.source.postMessage( { requestId: request.requestId, - action: "getDataPublishes", + action: 'getDataPublishes', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -663,9 +670,9 @@ export async function getDataPublishesCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getDataPublishes", + action: 'getDataPublishes', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -679,9 +686,9 @@ export async function addUserSettingsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addUserSettings", + action: 'addUserSettings', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -689,9 +696,9 @@ export async function addUserSettingsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addUserSettings", + action: 'addUserSettings', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -706,9 +713,9 @@ export async function getUserSettingsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getUserSettings", + action: 'getUserSettings', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -716,9 +723,9 @@ export async function getUserSettingsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getUserSettings", + action: 'getUserSettings', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -733,9 +740,9 @@ export async function cancelBanCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "cancelBan", + action: 'cancelBan', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -743,9 +750,9 @@ export async function cancelBanCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "cancelBan", + action: 'cancelBan', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -760,9 +767,9 @@ export async function registerNameCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -770,9 +777,9 @@ export async function registerNameCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -788,15 +795,15 @@ export async function createPollCase(request, event) { options: pollOptions, }, true, - true // skip permission + true // skip permission ); event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', payload: resCreatePoll, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -804,9 +811,9 @@ export async function createPollCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -816,13 +823,12 @@ export async function voteOnPollCase(request, event) { try { const res = await _voteOnPoll(request.payload, true, true); - event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', payload: res, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -830,9 +836,9 @@ export async function voteOnPollCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "registerName", + action: 'registerName', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -847,9 +853,9 @@ export async function makeAdminCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "makeAdmin", + action: 'makeAdmin', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -857,9 +863,9 @@ export async function makeAdminCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "makeAdmin", + action: 'makeAdmin', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -874,9 +880,9 @@ export async function removeAdminCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "removeAdmin", + action: 'removeAdmin', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -884,9 +890,9 @@ export async function removeAdminCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "removeAdmin", + action: 'removeAdmin', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -895,14 +901,14 @@ export async function removeAdminCase(request, event) { export async function notificationCase(request, event) { try { - const notificationId = "chat_notification_" + Date.now(); // Create a unique ID + const notificationId = 'chat_notification_' + Date.now(); // Create a unique ID // chrome.notifications.create(notificationId, { // type: "basic", // iconUrl: "qort.png", // Add an appropriate icon for chat notifications // title: "New Group Message!", // message: "You have received a new message from one of your groups", - // priority: 2, // Use the maximum priority to ensure it's + // priority: 2, // Use the maximum priority to ensure it's // }); // Set a timeout to clear the notification after 'timeout' milliseconds // setTimeout(() => { @@ -922,9 +928,9 @@ export async function notificationCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "notification", - error: "Error displaying notifaction", - type: "backgroundMessageResponse", + action: 'notification', + error: 'Error displaying notifaction', + type: 'backgroundMessageResponse', }, event.origin ); @@ -939,9 +945,9 @@ export async function addTimestampEnterChatCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addTimestampEnterChat", + action: 'addTimestampEnterChat', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -949,9 +955,9 @@ export async function addTimestampEnterChatCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addTimestampEnterChat", + action: 'addTimestampEnterChat', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -961,13 +967,13 @@ export async function addTimestampEnterChatCase(request, event) { export async function setApiKeyCase(request, event) { try { const payload = request.payload; - storeData('apiKey', payload) + storeData('apiKey', payload); event.source.postMessage( { requestId: request.requestId, - action: "setApiKey", + action: 'setApiKey', payload: true, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -975,9 +981,9 @@ export async function setApiKeyCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "setApiKey", + action: 'setApiKey', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -986,14 +992,14 @@ export async function setApiKeyCase(request, event) { export async function setCustomNodesCase(request, event) { try { const nodes = request.payload; - storeData('customNodes', nodes) + storeData('customNodes', nodes); event.source.postMessage( { requestId: request.requestId, - action: "setCustomNodes", + action: 'setCustomNodes', payload: true, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1001,9 +1007,9 @@ export async function setCustomNodesCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "setCustomNodes", + action: 'setCustomNodes', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1017,9 +1023,9 @@ export async function getApiKeyCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getApiKey", + action: 'getApiKey', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1027,9 +1033,9 @@ export async function getApiKeyCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getApiKey", + action: 'getApiKey', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1043,9 +1049,9 @@ export async function getCustomNodesFromStorageCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getCustomNodesFromStorage", + action: 'getCustomNodesFromStorage', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1053,9 +1059,9 @@ export async function getCustomNodesFromStorageCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getCustomNodesFromStorage", + action: 'getCustomNodesFromStorage', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1073,9 +1079,9 @@ export async function notifyAdminRegenerateSecretKeyCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "notifyAdminRegenerateSecretKey", + action: 'notifyAdminRegenerateSecretKey', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1083,9 +1089,9 @@ export async function notifyAdminRegenerateSecretKeyCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "notifyAdminRegenerateSecretKey", + action: 'notifyAdminRegenerateSecretKey', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1098,15 +1104,15 @@ export async function addGroupNotificationTimestampCase(request, event) { const response = await addTimestampGroupAnnouncement({ groupId, timestamp, - seenTimestamp: true + seenTimestamp: true, }); event.source.postMessage( { requestId: request.requestId, - action: "addGroupNotificationTimestamp", + action: 'addGroupNotificationTimestamp', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1114,9 +1120,9 @@ export async function addGroupNotificationTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addGroupNotificationTimestamp", + action: 'addGroupNotificationTimestamp', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1129,9 +1135,9 @@ export async function addEnteredQmailTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addEnteredQmailTimestamp", + action: 'addEnteredQmailTimestamp', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1139,9 +1145,9 @@ export async function addEnteredQmailTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addEnteredQmailTimestamp", + action: 'addEnteredQmailTimestamp', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1154,9 +1160,9 @@ export async function getEnteredQmailTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getEnteredQmailTimestamp", - payload: {timestamp: response}, - type: "backgroundMessageResponse", + action: 'getEnteredQmailTimestamp', + payload: { timestamp: response }, + type: 'backgroundMessageResponse', }, event.origin ); @@ -1164,9 +1170,9 @@ export async function getEnteredQmailTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getEnteredQmailTimestamp", + action: 'getEnteredQmailTimestamp', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1180,9 +1186,9 @@ export async function clearAllNotificationsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "clearAllNotifications", + action: 'clearAllNotifications', payload: true, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1190,9 +1196,9 @@ export async function clearAllNotificationsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "clearAllNotifications", + action: 'clearAllNotifications', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1213,9 +1219,9 @@ export async function setGroupDataCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "setGroupData", + action: 'setGroupData', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1223,9 +1229,9 @@ export async function setGroupDataCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "setGroupData", + action: 'setGroupData', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1240,9 +1246,9 @@ export async function getGroupDataSingleCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getGroupDataSingle", + action: 'getGroupDataSingle', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1250,9 +1256,9 @@ export async function getGroupDataSingleCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getGroupDataSingle", + action: 'getGroupDataSingle', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1266,9 +1272,9 @@ export async function getTimestampEnterChatCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTimestampEnterChat", + action: 'getTimestampEnterChat', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1276,9 +1282,9 @@ export async function getTimestampEnterChatCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTimestampEnterChat", + action: 'getTimestampEnterChat', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1288,66 +1294,66 @@ export async function getTimestampEnterChatCase(request, event) { export async function listActionsCase(request, event) { try { const { type, listName = '', items = [] } = request.payload; - let responseData + let responseData; - if(type === 'get'){ + if (type === 'get') { const url = await createEndpoint(`/lists/${listName}`); - const response = await fetch(url); - if (!response.ok) throw new Error("Failed to fetch"); - - responseData = await response.json(); - } else if(type === 'remove'){ - const url = await createEndpoint(`/lists/${listName}`); - const body = { - items: items , - }; - const bodyToString = JSON.stringify(body); - const response = await fetch(url, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - }, - body: bodyToString, - }); + const response = await fetch(url); + if (!response.ok) throw new Error('Failed to fetch'); - if (!response.ok) throw new Error("Failed to remove from list"); - let res; - try { - res = await response.clone().json(); - } catch (e) { - res = await response.text(); - } - responseData = res; - } else if(type === 'add'){ - const url = await createEndpoint(`/lists/${listName}`); - const body = { - items: items , - }; - const bodyToString = JSON.stringify(body); - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: bodyToString, - }); - - if (!response.ok) throw new Error("Failed to add to list"); - let res; - try { - res = await response.clone().json(); - } catch (e) { - res = await response.text(); - } - responseData = res; - } + responseData = await response.json(); + } else if (type === 'remove') { + const url = await createEndpoint(`/lists/${listName}`); + const body = { + items: items, + }; + const bodyToString = JSON.stringify(body); + const response = await fetch(url, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + body: bodyToString, + }); + + if (!response.ok) throw new Error('Failed to remove from list'); + let res; + try { + res = await response.clone().json(); + } catch (e) { + res = await response.text(); + } + responseData = res; + } else if (type === 'add') { + const url = await createEndpoint(`/lists/${listName}`); + const body = { + items: items, + }; + const bodyToString = JSON.stringify(body); + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: bodyToString, + }); + + if (!response.ok) throw new Error('Failed to add to list'); + let res; + try { + res = await response.clone().json(); + } catch (e) { + res = await response.text(); + } + responseData = res; + } event.source.postMessage( { requestId: request.requestId, - action: "listActions", + action: 'listActions', payload: responseData, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1355,9 +1361,9 @@ export async function listActionsCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "listActions", + action: 'listActions', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1371,9 +1377,9 @@ export async function getTimestampMentionCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTimestampMention", + action: 'getTimestampMention', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1381,9 +1387,9 @@ export async function getTimestampMentionCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getTimestampMention", + action: 'getTimestampMention', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1398,9 +1404,9 @@ export async function addTimestampMentionCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addTimestampMention", + action: 'addTimestampMention', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1408,9 +1414,9 @@ export async function addTimestampMentionCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "addTimestampMention", + action: 'addTimestampMention', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1424,9 +1430,9 @@ export async function getGroupNotificationTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getGroupNotificationTimestamp", + action: 'getGroupNotificationTimestamp', payload: response, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1434,9 +1440,9 @@ export async function getGroupNotificationTimestampCase(request, event) { event.source.postMessage( { requestId: request.requestId, - action: "getGroupNotificationTimestamp", + action: 'getGroupNotificationTimestamp', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1459,24 +1465,24 @@ export async function encryptAndPublishSymmetricKeyGroupChatCase( event.source.postMessage( { requestId: request.requestId, - action: "encryptAndPublishSymmetricKeyGroupChat", + action: 'encryptAndPublishSymmetricKeyGroupChat', payload: data, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); if (!previousData) { - try { - sendChatGroup({ - groupId, - typeMessage: undefined, - chatReference: undefined, - messageText: PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY, - }); - } catch (error) { - // error in sending chat message + try { + sendChatGroup({ + groupId, + typeMessage: undefined, + chatReference: undefined, + messageText: PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY, + }); + } catch (error) { + // error in sending chat message + } } - } try { sendChatNotification(data, groupId, previousData, numberOfMembers); } catch (error) { @@ -1486,9 +1492,9 @@ export async function encryptAndPublishSymmetricKeyGroupChatCase( event.source.postMessage( { requestId: request.requestId, - action: "encryptAndPublishSymmetricKeyGroupChat", + action: 'encryptAndPublishSymmetricKeyGroupChat', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1505,15 +1511,15 @@ export async function encryptAndPublishSymmetricKeyGroupChatForAdminsCase( await encryptAndPublishSymmetricKeyGroupChatForAdmins({ groupId, previousData, - admins + admins, }); event.source.postMessage( { requestId: request.requestId, - action: "encryptAndPublishSymmetricKeyGroupChatForAdmins", + action: 'encryptAndPublishSymmetricKeyGroupChatForAdmins', payload: data, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1521,9 +1527,9 @@ export async function encryptAndPublishSymmetricKeyGroupChatForAdminsCase( event.source.postMessage( { requestId: request.requestId, - action: "encryptAndPublishSymmetricKeyGroupChat", + action: 'encryptAndPublishSymmetricKeyGroupChat', error: error?.message, - type: "backgroundMessageResponse", + type: 'backgroundMessageResponse', }, event.origin ); @@ -1531,588 +1537,634 @@ export async function encryptAndPublishSymmetricKeyGroupChatForAdminsCase( } export async function publishGroupEncryptedResourceCase(request, event) { - try { - const {encryptedData, identifier} = request.payload; - const response = await publishGroupEncryptedResource({encryptedData, identifier}); - - event.source.postMessage( - { - requestId: request.requestId, - action: "publishGroupEncryptedResource", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "publishGroupEncryptedResource", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } - } + try { + const { encryptedData, identifier } = request.payload; + const response = await publishGroupEncryptedResource({ + encryptedData, + identifier, + }); - export async function publishOnQDNCase(request, event) { - try { - const {data, identifier, service, title, - description, - category, - tag1, - tag2, - tag3, - tag4, - tag5, uploadType} = request.payload; - const response = await publishOnQDN({data, identifier, service, title, - description, - category, - tag1, - tag2, - tag3, - tag4, - tag5, uploadType}); - - event.source.postMessage( - { - requestId: request.requestId, - action: "publishOnQDN", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "publishOnQDN", - error: error?.message || 'Unable to publish', - type: "backgroundMessageResponse", - }, - event.origin - ); - } + event.source.postMessage( + { + requestId: request.requestId, + action: 'publishGroupEncryptedResource', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'publishGroupEncryptedResource', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function handleActiveGroupDataFromSocketCase(request, event) { - try { - const {groups, directs} = request.payload; - const response = await handleActiveGroupDataFromSocket({groups, directs}); - - event.source.postMessage( - { - requestId: request.requestId, - action: "handleActiveGroupDataFromSocket", - payload: true, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "handleActiveGroupDataFromSocket", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function publishOnQDNCase(request, event) { + try { + const { + data, + name = '', + identifier, + service, + title, + description, + category, + tag1, + tag2, + tag3, + tag4, + tag5, + uploadType, + } = request.payload; + const response = await publishOnQDN({ + data, + name, + identifier, + service, + title, + description, + category, + tag1, + tag2, + tag3, + tag4, + tag5, + uploadType, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'publishOnQDN', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'publishOnQDN', + error: error?.message || 'Unable to publish', + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function getThreadActivityCase(request, event) { - try { - const response = await checkThreads(true) - - event.source.postMessage( - { - requestId: request.requestId, - action: "getThreadActivity", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "getThreadActivity", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function handleActiveGroupDataFromSocketCase(request, event) { + try { + const { groups, directs } = request.payload; + const response = await handleActiveGroupDataFromSocket({ groups, directs }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'handleActiveGroupDataFromSocket', + payload: true, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'handleActiveGroupDataFromSocket', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function updateThreadActivityCase(request, event) { - try { - const { threadId, qortalName, groupId, thread} = request.payload; - const response = await updateThreadActivity({ threadId, qortalName, groupId, thread }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "updateThreadActivity", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "updateThreadActivity", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function getThreadActivityCase(request, event) { + try { + const response = await checkThreads(true); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'getThreadActivity', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'getThreadActivity', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function decryptGroupEncryptionCase(request, event) { - try { - const { data} = request.payload; - const response = await decryptGroupEncryption({ data }); - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptGroupEncryption", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptGroupEncryption", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function updateThreadActivityCase(request, event) { + try { + const { threadId, qortalName, groupId, thread } = request.payload; + const response = await updateThreadActivity({ + threadId, + qortalName, + groupId, + thread, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'updateThreadActivity', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'updateThreadActivity', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function encryptSingleCase(request, event) { - try { - const { data, secretKeyObject, typeNumber} = request.payload; - const response = await encryptSingle({ data64: data, secretKeyObject, typeNumber }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "encryptSingle", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "encryptSingle", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function decryptGroupEncryptionCase(request, event) { + try { + const { data } = request.payload; + const response = await decryptGroupEncryption({ data }); + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptGroupEncryption', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptGroupEncryption', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function decryptSingleCase(request, event) { - try { - const { data, secretKeyObject, skipDecodeBase64} = request.payload; - const response = await decryptSingleFunc({ messages: data, secretKeyObject, skipDecodeBase64 }); - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptSingle", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptSingle", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function encryptSingleCase(request, event) { + try { + const { data, secretKeyObject, typeNumber } = request.payload; + const response = await encryptSingle({ + data64: data, + secretKeyObject, + typeNumber, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'encryptSingle', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'encryptSingle', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function pauseAllQueuesCase(request, event) { - try { - await pauseAllQueues(); - - event.source.postMessage( - { - requestId: request.requestId, - action: "pauseAllQueues", - payload: true, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "pauseAllQueues", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function decryptSingleCase(request, event) { + try { + const { data, secretKeyObject, skipDecodeBase64 } = request.payload; + const response = await decryptSingleFunc({ + messages: data, + secretKeyObject, + skipDecodeBase64, + }); + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptSingle', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptSingle', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function resumeAllQueuesCase(request, event) { - try { - await resumeAllQueues(); - - event.source.postMessage( - { - requestId: request.requestId, - action: "resumeAllQueues", - payload: true, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "resumeAllQueues", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function pauseAllQueuesCase(request, event) { + try { + await pauseAllQueues(); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'pauseAllQueues', + payload: true, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'pauseAllQueues', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } - export async function checkLocalCase(request, event) { - try { - const response = await checkLocalFunc() - event.source.postMessage( - { - requestId: request.requestId, - action: "pauseAllQueues", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "checkLocal", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +} + +export async function resumeAllQueuesCase(request, event) { + try { + await resumeAllQueues(); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'resumeAllQueues', + payload: true, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'resumeAllQueues', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } - - export async function decryptSingleForPublishesCase(request, event) { - try { - const { data, secretKeyObject, skipDecodeBase64} = request.payload; - const response = await decryptSingleForPublishes({ messages: data, secretKeyObject, skipDecodeBase64 }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptSingleForPublishes", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptSingle", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +} +export async function checkLocalCase(request, event) { + try { + const response = await checkLocalFunc(); + event.source.postMessage( + { + requestId: request.requestId, + action: 'pauseAllQueues', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'checkLocal', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function decryptDirectCase(request, event) { - try { - const { data, involvingAddress} = request.payload; - const response = await decryptDirectFunc({ messages: data, involvingAddress }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptDirect", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "decryptDirect", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function decryptSingleForPublishesCase(request, event) { + try { + const { data, secretKeyObject, skipDecodeBase64 } = request.payload; + const response = await decryptSingleForPublishes({ + messages: data, + secretKeyObject, + skipDecodeBase64, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptSingleForPublishes', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptSingle', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } - export async function sendChatGroupCase(request, event) { - try { - const { groupId, - typeMessage = undefined, - chatReference = undefined, - messageText} = request.payload; - const response = await sendChatGroup({ groupId, typeMessage, chatReference, messageText }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatGroup", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatGroup", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +} + +export async function decryptDirectCase(request, event) { + try { + const { data, involvingAddress } = request.payload; + const response = await decryptDirectFunc({ + messages: data, + involvingAddress, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptDirect', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'decryptDirect', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } - export async function sendChatDirectCase(request, event) { - try { - const { directTo, - typeMessage = undefined, - chatReference = undefined, - messageText, - publicKeyOfRecipient, - address, - otherData} = request.payload; - const response = await sendChatDirect({ directTo, - chatReference, - messageText, - typeMessage, - publicKeyOfRecipient, - address, - otherData }); - - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatDirect", - payload: response, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatDirect", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +} +export async function sendChatGroupCase(request, event) { + try { + const { + groupId, + typeMessage = undefined, + chatReference = undefined, + messageText, + } = request.payload; + const response = await sendChatGroup({ + groupId, + typeMessage, + chatReference, + messageText, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatGroup', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatGroup', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} +export async function sendChatDirectCase(request, event) { + try { + const { + directTo, + typeMessage = undefined, + chatReference = undefined, + messageText, + publicKeyOfRecipient, + address, + otherData, + } = request.payload; + const response = await sendChatDirect({ + directTo, + chatReference, + messageText, + typeMessage, + publicKeyOfRecipient, + address, + otherData, + }); - export async function setupGroupWebsocketCase(request, event) { - try { - - checkNewMessages(); - checkThreads(); - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatDirect", - payload: true, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "sendChatDirect", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatDirect', + payload: response, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatDirect', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function createRewardShareCase(request, event) { - try { - const {recipientPublicKey} = request.payload; - const resKeyPair = await getKeyPair(); - const parsedData = resKeyPair; - const uint8PrivateKey = Base58.decode(parsedData.privateKey); - const uint8PublicKey = Base58.decode(parsedData.publicKey); - const keyPair = { - privateKey: uint8PrivateKey, - publicKey: uint8PublicKey, - }; - let lastRef = await getLastRef(); - - const tx = await createTransaction(38, keyPair, { - recipientPublicKey, - percentageShare: 0, - lastReference: lastRef, - }); - - const signedBytes = Base58.encode(tx.signedBytes); - - const res = await processTransactionVersion2(signedBytes); - if (!res?.signature) - throw new Error("Transaction was not able to be processed"); - event.source.postMessage( - { - requestId: request.requestId, - action: "createRewardShare", - payload: res, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "createRewardShare", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } +export async function setupGroupWebsocketCase(request, event) { + try { + checkNewMessages(); + checkThreads(); + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatDirect', + payload: true, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'sendChatDirect', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function removeRewardShareCase(request, event) { - try { - const {rewardShareKeyPairPublicKey, recipient, percentageShare} = request.payload; - const resKeyPair = await getKeyPair(); - const parsedData = resKeyPair; - const uint8PrivateKey = Base58.decode(parsedData.privateKey); - const uint8PublicKey = Base58.decode(parsedData.publicKey); - const keyPair = { - privateKey: uint8PrivateKey, - publicKey: uint8PublicKey, - }; - let lastRef = await getLastRef(); - - const tx = await createTransaction(381, keyPair, { - rewardShareKeyPairPublicKey, - recipient, - percentageShare, - lastReference: lastRef, - }); +export async function createRewardShareCase(request, event) { + try { + const { recipientPublicKey } = request.payload; + const resKeyPair = await getKeyPair(); + const parsedData = resKeyPair; + const uint8PrivateKey = Base58.decode(parsedData.privateKey); + const uint8PublicKey = Base58.decode(parsedData.publicKey); + const keyPair = { + privateKey: uint8PrivateKey, + publicKey: uint8PublicKey, + }; + let lastRef = await getLastRef(); - const signedBytes = Base58.encode(tx.signedBytes); - - const res = await processTransactionVersion2(signedBytes); - if (!res?.signature) - throw new Error("Transaction was not able to be processed"); - event.source.postMessage( - { - requestId: request.requestId, - action: "removeRewardShare", - payload: res, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "removeRewardShare", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } + const tx = await createTransaction(38, keyPair, { + recipientPublicKey, + percentageShare: 0, + lastReference: lastRef, + }); + + const signedBytes = Base58.encode(tx.signedBytes); + + const res = await processTransactionVersion2(signedBytes); + if (!res?.signature) + throw new Error('Transaction was not able to be processed'); + event.source.postMessage( + { + requestId: request.requestId, + action: 'createRewardShare', + payload: res, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'createRewardShare', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - export async function getRewardSharePrivateKeyCase(request, event) { - try { - const {recipientPublicKey} = request.payload; - const resKeyPair = await getKeyPair(); - const parsedData = resKeyPair; - const uint8PrivateKey = Base58.decode(parsedData.privateKey); - const uint8PublicKey = Base58.decode(parsedData.publicKey); - const keyPair = { - privateKey: uint8PrivateKey, - publicKey: uint8PublicKey, - }; - let lastRef = await getLastRef(); - - const tx = await createTransaction(38, keyPair, { - recipientPublicKey, - percentageShare: 0, - lastReference: lastRef, - }); +export async function removeRewardShareCase(request, event) { + try { + const { rewardShareKeyPairPublicKey, recipient, percentageShare } = + request.payload; + const resKeyPair = await getKeyPair(); + const parsedData = resKeyPair; + const uint8PrivateKey = Base58.decode(parsedData.privateKey); + const uint8PublicKey = Base58.decode(parsedData.publicKey); + const keyPair = { + privateKey: uint8PrivateKey, + publicKey: uint8PublicKey, + }; + let lastRef = await getLastRef(); - event.source.postMessage( - { - requestId: request.requestId, - action: "getRewardSharePrivateKey", - payload: tx?._base58RewardShareSeed, - type: "backgroundMessageResponse", - }, - event.origin - ); - } catch (error) { - event.source.postMessage( - { - requestId: request.requestId, - action: "getRewardSharePrivateKey", - error: error?.message, - type: "backgroundMessageResponse", - }, - event.origin - ); - } + const tx = await createTransaction(381, keyPair, { + rewardShareKeyPairPublicKey, + recipient, + percentageShare, + lastReference: lastRef, + }); + + const signedBytes = Base58.encode(tx.signedBytes); + + const res = await processTransactionVersion2(signedBytes); + if (!res?.signature) + throw new Error('Transaction was not able to be processed'); + event.source.postMessage( + { + requestId: request.requestId, + action: 'removeRewardShare', + payload: res, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'removeRewardShare', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); } +} - \ No newline at end of file +export async function getRewardSharePrivateKeyCase(request, event) { + try { + const { recipientPublicKey } = request.payload; + const resKeyPair = await getKeyPair(); + const parsedData = resKeyPair; + const uint8PrivateKey = Base58.decode(parsedData.privateKey); + const uint8PublicKey = Base58.decode(parsedData.publicKey); + const keyPair = { + privateKey: uint8PrivateKey, + publicKey: uint8PublicKey, + }; + let lastRef = await getLastRef(); + + const tx = await createTransaction(38, keyPair, { + recipientPublicKey, + percentageShare: 0, + lastReference: lastRef, + }); + + event.source.postMessage( + { + requestId: request.requestId, + action: 'getRewardSharePrivateKey', + payload: tx?._base58RewardShareSeed, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } catch (error) { + event.source.postMessage( + { + requestId: request.requestId, + action: 'getRewardSharePrivateKey', + error: error?.message, + type: 'backgroundMessageResponse', + }, + event.origin + ); + } +} diff --git a/src/backgroundFunctions/encryption.ts b/src/backgroundFunctions/encryption.ts index 6cc0150..205fd34 100644 --- a/src/backgroundFunctions/encryption.ts +++ b/src/backgroundFunctions/encryption.ts @@ -66,6 +66,15 @@ export async function getNameInfo() { } } +export async function getAllUserNames() { + const wallet = await getSaveWallet(); + const address = wallet.address0; + const validApi = await getBaseApi(); + const response = await fetch(validApi + '/names/address/' + address); + const nameData = await response.json(); + return nameData.map((item) => item.name); +} + async function getKeyPair() { const res = await getData('keyPair').catch(() => null); if (res) { @@ -288,9 +297,10 @@ export const publishOnQDN = async ({ tag4, tag5, uploadType = 'file', + name, }) => { if (data && service) { - const registeredName = await getNameInfo(); + const registeredName = name || (await getNameInfo()); if (!registeredName) throw new Error('You need a name to publish'); const res = await publishData({ diff --git a/src/components/Apps/AppPublish.tsx b/src/components/Apps/AppPublish.tsx index 486fd8a..5ceed1e 100644 --- a/src/components/Apps/AppPublish.tsx +++ b/src/components/Apps/AppPublish.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useCallback, useContext, useEffect, useState } from 'react'; import { AppCircle, AppCircleContainer, @@ -72,7 +72,8 @@ const CustomMenuItem = styled(MenuItem)({ // }, }); -export const AppPublish = ({ names, categories }) => { +export const AppPublish = ({ categories, myAddress, myName }) => { + const [names, setNames] = useState([]); const [name, setName] = useState(''); const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); @@ -152,6 +153,25 @@ export const AppPublish = ({ names, categories }) => { getQapp(name, appType); }, [name, appType]); + const getNames = useCallback(async () => { + if (!myAddress) return; + try { + setIsLoading('Loading names'); + const res = await fetch( + `${getBaseApiReact()}/names/address/${myAddress}` + ); + const data = await res.json(); + setNames(data?.map((item) => item.name)); + } catch (error) { + console.error(error); + } finally { + setIsLoading(''); + } + }, [myAddress]); + useEffect(() => { + getNames(); + }, [getNames]); + const publishApp = async () => { try { const data = { @@ -196,6 +216,7 @@ export const AppPublish = ({ names, categories }) => { data: fileBase64, service: appType, title, + name, description, category, tag1, diff --git a/src/components/Apps/AppsDesktop.tsx b/src/components/Apps/AppsDesktop.tsx index 80f57b9..73cdb20 100644 --- a/src/components/Apps/AppsDesktop.tsx +++ b/src/components/Apps/AppsDesktop.tsx @@ -38,6 +38,7 @@ export const AppsDesktop = ({ hasUnreadGroups, setDesktopViewMode, desktopViewMode, + myAddress, }) => { const [availableQapps, setAvailableQapps] = useState([]); const [selectedAppInfo, setSelectedAppInfo] = useState(null); @@ -458,6 +459,7 @@ export const AppsDesktop = ({ setMode={setMode} myApp={myApp} myWebsite={myWebsite} + myAddress={myAddress} /> )} @@ -485,7 +487,11 @@ export const AppsDesktop = ({ myName={myName} /> {mode === 'publish' && !selectedTab && ( - + )} {tabs.map((tab) => { if (!iframeRefs.current[tab.tabId]) { @@ -521,6 +527,7 @@ export const AppsDesktop = ({ setMode={setMode} myApp={myApp} myWebsite={myWebsite} + myAddress={myAddress} /> diff --git a/src/components/Apps/AppsHomeDesktop.tsx b/src/components/Apps/AppsHomeDesktop.tsx index 8a96015..e01a715 100644 --- a/src/components/Apps/AppsHomeDesktop.tsx +++ b/src/components/Apps/AppsHomeDesktop.tsx @@ -23,6 +23,7 @@ export const AppsHomeDesktop = ({ myWebsite, availableQapps, myName, + myAddress, }) => { const [qortalUrl, setQortalUrl] = useState(''); const theme = useTheme(); @@ -147,7 +148,7 @@ export const AppsHomeDesktop = ({ - + { +export const AppsPrivate = ({ myName, myAddress }) => { + const [names, setNames] = useState([]); + const [name, setName] = useState(0); + const { openApp } = useHandlePrivateApps(); const [file, setFile] = useState(null); const [logo, setLogo] = useState(null); @@ -140,7 +149,7 @@ export const AppsPrivate = ({ myName }) => { try { if (selectedGroup === 0) return; if (!logo) throw new Error('Please select an image for a logo'); - if (!myName) throw new Error('You need a Qortal name to publish'); + if (!name) throw new Error('Please select a Qortal name'); if (!newPrivateAppValues?.name) throw new Error('Your app needs a name'); const base64Logo = await fileToBase64(logo); const base64App = await fileToBase64(file); @@ -177,6 +186,7 @@ export const AppsPrivate = ({ myName }) => { data: decryptedData, identifier: newPrivateAppValues?.identifier, service: newPrivateAppValues?.service, + name, }) .then((response) => { if (!response?.error) { @@ -194,7 +204,7 @@ export const AppsPrivate = ({ myName }) => { { identifier: newPrivateAppValues?.identifier, service: newPrivateAppValues?.service, - name: myName, + name, groupId: selectedGroup, }, true @@ -220,6 +230,22 @@ export const AppsPrivate = ({ myName }) => { }; } + const getNames = useCallback(async () => { + if (!myAddress) return; + try { + const res = await fetch( + `${getBaseApiReact()}/names/address/${myAddress}` + ); + const data = await res.json(); + setNames(data?.map((item) => item.name)); + } catch (error) { + console.error(error); + } + }, [myAddress]); + useEffect(() => { + getNames(); + }, [getNames]); + return ( <> { {file ? 'Change' : 'Choose'} File + + + + + + 0 && appFeeRecipient) { hasAppFee = true; } - const registeredName = await getNameInfo(); + + const registeredName = data?.name || (await getNameInfo()); const name = registeredName; if (!name) { throw new Error('User has no Qortal name'); @@ -1144,6 +1146,7 @@ export const publishQDNResource = async ( text1: 'Do you give this application permission to publish to QDN?', text2: `service: ${service}`, text3: `identifier: ${identifier || null}`, + text4: `name: ${registeredName}`, fee: fee.fee, ...handleDynamicValues, }, @@ -1272,10 +1275,19 @@ export const publishMultipleQDNResources = async ( // } const fee = await getFee('ARBITRARY'); const registeredName = await getNameInfo(); + const name = registeredName; if (!name) { throw new Error('You need a Qortal name to publish.'); } + const userNames = await getAllUserNames(); + data.resources?.forEach((item) => { + if (item?.name && !userNames?.includes(item.name)) + throw new Error( + `The name ${item.name}, does not belong to the publisher.` + ); + }); + const appFee = data?.appFee ? +data.appFee : undefined; const appFeeRecipient = data?.appFeeRecipient; let hasAppFee = false; @@ -1343,7 +1355,7 @@ export const publishMultipleQDNResources = async (
Service: ${ resource.service }
-
Name: ${name}
+
Name: ${resource?.name || name}
Identifier: ${ resource.identifier }
@@ -1384,6 +1396,7 @@ export const publishMultipleQDNResources = async ( reason: errorMsg, identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); continue; } @@ -1393,6 +1406,7 @@ export const publishMultipleQDNResources = async ( reason: errorMsg, identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); continue; } @@ -1423,6 +1437,7 @@ export const publishMultipleQDNResources = async ( reason: errorMsg, identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); continue; } @@ -1451,6 +1466,7 @@ export const publishMultipleQDNResources = async ( reason: errorMsg, identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); continue; } @@ -1461,7 +1477,7 @@ export const publishMultipleQDNResources = async ( publishData, [ { - registeredName: encodeURIComponent(name), + registeredName: encodeURIComponent(resource?.name || name), file: data64, service: service, identifier: encodeURIComponent(identifier), @@ -1493,6 +1509,7 @@ export const publishMultipleQDNResources = async ( reason: errorMsg, identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); } } catch (error) { @@ -1500,6 +1517,7 @@ export const publishMultipleQDNResources = async ( reason: error?.message || 'Unknown error', identifier: resource.identifier, service: resource.service, + name: resource?.name || name, }); } } @@ -4305,9 +4323,10 @@ export const updateNameRequest = async (data, isFromExtension) => { const fee = await getFee('UPDATE_NAME'); const resPermission = await getUserPermission( { - text1: `Do you give this application permission to register this name?`, - highlightedText: data.newName, - text2: data?.description, + text1: `Do you give this application permission to update this name?`, + text2: `previous name: ${oldName}`, + text3: `new name: ${newName}`, + text4: data?.description, fee: fee.fee, }, isFromExtension @@ -4741,7 +4760,7 @@ export const createGroupRequest = async (data, isFromExtension) => { ]; const missingFields: string[] = []; requiredFields.forEach((field) => { - if (data[field] !== undefined && data[field] !== null) { + if (data[field] === undefined || data[field] === null) { missingFields.push(field); } }); @@ -4793,7 +4812,7 @@ export const updateGroupRequest = async (data, isFromExtension) => { ]; const missingFields: string[] = []; requiredFields.forEach((field) => { - if (data[field] !== undefined && data[field] !== null) { + if (data[field] === undefined || data[field] === null) { missingFields.push(field); } }); @@ -4928,7 +4947,7 @@ export const sellNameRequest = async (data, isFromExtension) => { const requiredFields = ['salePrice', 'nameForSale']; const missingFields: string[] = []; requiredFields.forEach((field) => { - if (data[field] !== undefined && data[field] !== null) { + if (data[field] === undefined || data[field] === null) { missingFields.push(field); } }); @@ -4972,7 +4991,7 @@ export const cancelSellNameRequest = async (data, isFromExtension) => { const requiredFields = ['nameForSale']; const missingFields: string[] = []; requiredFields.forEach((field) => { - if (data[field] !== undefined && data[field] !== null) { + if (data[field] === undefined || data[field] === null) { missingFields.push(field); } }); @@ -5012,7 +5031,7 @@ export const buyNameRequest = async (data, isFromExtension) => { const requiredFields = ['nameForSale']; const missingFields: string[] = []; requiredFields.forEach((field) => { - if (data[field] !== undefined && data[field] !== null) { + if (data[field] === undefined || data[field] === null) { missingFields.push(field); } });