diff --git a/src/background-cases.ts b/src/background-cases.ts index 5e2a90e..aae6e03 100644 --- a/src/background-cases.ts +++ b/src/background-cases.ts @@ -493,8 +493,8 @@ export async function cancelInvitationToGroupCase(request, event) { export async function leaveGroupCase(request, event) { try { - const { groupId, qortalAddress } = request.payload; - const response = await leaveGroup({ groupId, qortalAddress }); + const { groupId } = request.payload; + const response = await leaveGroup({ groupId }); event.source.postMessage( { @@ -611,7 +611,8 @@ 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( { @@ -638,7 +639,8 @@ 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( { @@ -1028,6 +1030,7 @@ export async function addGroupNotificationTimestampCase(request, event) { const response = await addTimestampGroupAnnouncement({ groupId, timestamp, + seenTimestamp: true }); event.source.postMessage( @@ -1546,7 +1549,7 @@ export async function publishGroupEncryptedResourceCase(request, event) { export async function decryptSingleForPublishesCase(request, event) { try { const { data, secretKeyObject, skipDecodeBase64} = request.payload; - const response = await decryptSingleForPublishes({ data, secretKeyObject, skipDecodeBase64 }); + const response = await decryptSingleForPublishes({ messages: data, secretKeyObject, skipDecodeBase64 }); event.source.postMessage( { diff --git a/src/utils/chromeStorage.ts b/src/utils/chromeStorage.ts index 4419710..3689887 100644 --- a/src/utils/chromeStorage.ts +++ b/src/utils/chromeStorage.ts @@ -95,33 +95,39 @@ export const storeData = async (key: string, payload: any): Promise => { }; -export const getData = async (key: string): Promise => { +export const getData = async (key: string): Promise => { await initializeKeyAndIV(); - const storedDataBase64 = await SecureStoragePlugin.get({ key }); - if (storedDataBase64.value) { - if (keysToEncrypt.includes(key) && inMemoryKey) { - // Decode the Base64-encoded encrypted data - const combinedData = atob(storedDataBase64.value) - .split("") - .map((c) => c.charCodeAt(0)); + try { + const storedDataBase64 = await SecureStoragePlugin.get({ key }); - const iv = new Uint8Array(combinedData.slice(0, 12)); // First 12 bytes are the IV - const encryptedData = new Uint8Array(combinedData.slice(12)).buffer; + if (storedDataBase64.value) { + if (keysToEncrypt.includes(key) && inMemoryKey) { + // Decode the Base64-encoded encrypted data + const combinedData = atob(storedDataBase64.value) + .split("") + .map((c) => c.charCodeAt(0)); - const decryptedBase64Data = await decryptData(encryptedData, inMemoryKey, iv); - return base64ToJson(decryptedBase64Data); + const iv = new Uint8Array(combinedData.slice(0, 12)); // First 12 bytes are the IV + const encryptedData = new Uint8Array(combinedData.slice(12)).buffer; + + const decryptedBase64Data = await decryptData(encryptedData, inMemoryKey, iv); + return base64ToJson(decryptedBase64Data); + } else { + // Decode non-encrypted data + return base64ToJson(storedDataBase64.value); + } } else { - // Decode non-encrypted data - return base64ToJson(storedDataBase64.value); + return null; } - } else { - throw new Error(`No data found for key: ${key}`); + } catch (error) { + return null } }; + // Remove keys from storage and log out export async function removeKeysAndLogout(keys: string[], event: MessageEvent, request: any) { try {