diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 86c4aab..3cda10a 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -13,6 +13,7 @@ dependencies { implementation project(':capacitor-browser') implementation project(':capacitor-filesystem') implementation project(':capacitor-local-notifications') + implementation project(':capacitor-preferences') implementation project(':capacitor-splash-screen') implementation project(':capawesome-capacitor-file-picker') implementation project(':evva-capacitor-secure-storage-plugin') diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 305ad0d..a098a15 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -14,6 +14,9 @@ project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacit include ':capacitor-local-notifications' project(':capacitor-local-notifications').projectDir = new File('../node_modules/@capacitor/local-notifications/android') +include ':capacitor-preferences' +project(':capacitor-preferences').projectDir = new File('../node_modules/@capacitor/preferences/android') + include ':capacitor-splash-screen' project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android') diff --git a/package-lock.json b/package-lock.json index f71eea8..852f67d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@capacitor/core": "^6.1.2", "@capacitor/filesystem": "^6.0.1", "@capacitor/local-notifications": "^6.1.0", + "@capacitor/preferences": "^6.0.3", "@capacitor/splash-screen": "^6.0.2", "@capawesome/capacitor-file-picker": "^6.1.0", "@chatscope/chat-ui-kit-react": "^2.0.3", @@ -1776,6 +1777,14 @@ "@capacitor/core": "^6.0.0" } }, + "node_modules/@capacitor/preferences": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@capacitor/preferences/-/preferences-6.0.3.tgz", + "integrity": "sha512-3I1BbhhCBTMBziVvr0fU7RCRXqGvhUW/apHLRJSaJAWonASya5rp6AWsHv1lW1tkF0avUOMwp6e7iNA4UUGu8g==", + "peerDependencies": { + "@capacitor/core": "^6.0.0" + } + }, "node_modules/@capacitor/splash-screen": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@capacitor/splash-screen/-/splash-screen-6.0.2.tgz", diff --git a/package.json b/package.json index 1b32d33..06c429c 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@capacitor/core": "^6.1.2", "@capacitor/filesystem": "^6.0.1", "@capacitor/local-notifications": "^6.1.0", + "@capacitor/preferences": "^6.0.3", "@capacitor/splash-screen": "^6.0.2", "@capawesome/capacitor-file-picker": "^6.1.0", "@chatscope/chat-ui-kit-react": "^2.0.3", @@ -72,6 +73,7 @@ "react-frame-component": "^5.2.7", "react-infinite-scroller": "^1.2.6", "react-intersection-observer": "^9.13.0", + "react-json-view-lite": "^2.0.1", "react-loader-spinner": "^6.1.6", "react-qr-code": "^2.0.15", "react-quick-pinch-zoom": "^5.1.0", @@ -87,8 +89,7 @@ "tiptap-extension-resize-image": "^1.1.8", "ts-key-enum": "^2.0.12", "vite-plugin-top-level-await": "^1.4.4", - "vite-plugin-wasm": "^3.3.0", - "react-json-view-lite": "^2.0.1" + "vite-plugin-wasm": "^3.3.0" }, "devDependencies": { "@testing-library/dom": "^10.3.0", diff --git a/src/components/Group/Group.tsx b/src/components/Group/Group.tsx index d33e301..cdc58df 100644 --- a/src/components/Group/Group.tsx +++ b/src/components/Group/Group.tsx @@ -533,6 +533,7 @@ export const Group = ({ }, [selectedGroup]); + useEffect(() => { selectedDirectRef.current = selectedDirect; }, [selectedDirect]); @@ -633,6 +634,13 @@ export const Group = ({ } catch (error) {} }; + useEffect(()=> { + if(myAddress){ + getGroupAnnouncements() + getTimestampEnterChat() + } + }, [myAddress]) + const getGroupOwner = async (groupId) => { try { const url = `${getBaseApiReact()}/groups/${groupId}`; diff --git a/src/utils/chromeStorage.ts b/src/utils/chromeStorage.ts index 3689887..9b188ff 100644 --- a/src/utils/chromeStorage.ts +++ b/src/utils/chromeStorage.ts @@ -1,13 +1,14 @@ import { SecureStoragePlugin } from '@evva/capacitor-secure-storage-plugin'; +import { Preferences } from '@capacitor/preferences'; let inMemoryKey: CryptoKey | null = null; -let inMemoryIV: Uint8Array | null = null; const keysToEncrypt = ['keyPair']; +const keysToUseEvva = ['wallets']; async function initializeKeyAndIV() { if (!inMemoryKey) { - inMemoryKey = await generateKey(); // Generates the key in memory + inMemoryKey = await generateKey(); // Generates the key in memory } } @@ -15,7 +16,7 @@ async function generateKey(): Promise { return await crypto.subtle.generateKey( { name: "AES-GCM", - length: 256 + length: 256, }, true, ["encrypt", "decrypt"] @@ -32,7 +33,7 @@ async function encryptData(data: string, key: CryptoKey): Promise<{ iv: Uint8Arr const encryptedData = await crypto.subtle.encrypt( { name: "AES-GCM", - iv: iv + iv: iv, }, key, encodedData @@ -45,7 +46,7 @@ async function decryptData(encryptedData: ArrayBuffer, key: CryptoKey, iv: Uint8 const decryptedData = await crypto.subtle.decrypt( { name: "AES-GCM", - iv: iv + iv: iv, }, key, encryptedData @@ -56,7 +57,7 @@ async function decryptData(encryptedData: ArrayBuffer, key: CryptoKey, iv: Uint8 } // Encode a JSON payload as Base64 -function jsonToBase64(payload) { +function jsonToBase64(payload: any): string { const utf8Array = new TextEncoder().encode(JSON.stringify(payload)); let binary = ''; utf8Array.forEach((byte) => (binary += String.fromCharCode(byte))); @@ -64,7 +65,7 @@ function jsonToBase64(payload) { } // Decode a Base64 string back to JSON -function base64ToJson(base64) { +function base64ToJson(base64: string): any { const binary = atob(base64); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { @@ -86,24 +87,25 @@ export const storeData = async (key: string, payload: any): Promise => { const combinedData = new Uint8Array([...iv, ...new Uint8Array(encryptedData)]); const encryptedBase64Data = btoa(String.fromCharCode(...combinedData)); await SecureStoragePlugin.set({ key, value: encryptedBase64Data }); - } else { - // Store Base64-encoded data in plain text if not in keysToEncrypt + } else if (keysToUseEvva?.includes(key)){ await SecureStoragePlugin.set({ key, value: base64Data }); + } else { + // Store Base64-encoded data in Capacitor Preferences for non-encrypted keys + await Preferences.set({ key, value: base64Data }); } return "Data saved successfully"; }; - export const getData = async (key: string): Promise => { await initializeKeyAndIV(); try { - const storedDataBase64 = await SecureStoragePlugin.get({ key }); + if (keysToEncrypt.includes(key) && inMemoryKey) { + // Fetch encrypted data for sensitive keys + const storedDataBase64 = await SecureStoragePlugin.get({ key }); - if (storedDataBase64.value) { - if (keysToEncrypt.includes(key) && inMemoryKey) { - // Decode the Base64-encoded encrypted data + if (storedDataBase64.value) { const combinedData = atob(storedDataBase64.value) .split("") .map((c) => c.charCodeAt(0)); @@ -113,28 +115,39 @@ export const getData = async (key: string): Promise => { const decryptedBase64Data = await decryptData(encryptedData, inMemoryKey, iv); return base64ToJson(decryptedBase64Data); - } else { - // Decode non-encrypted data - return base64ToJson(storedDataBase64.value); } + } else if (keysToUseEvva?.includes(key)){ + const storedDataBase64 = await SecureStoragePlugin.get({ key }); + if(storedDataBase64?.value){ + return base64ToJson(storedDataBase64.value); + + } else return null } else { - return null; + // Fetch plain data for non-encrypted keys + const { value } = await Preferences.get({ key }); + if (value) { + return base64ToJson(value); + } } + + return null; } catch (error) { - return null + console.error("Error fetching data:", error); + return null; } }; - - - -// Remove keys from storage and log out export async function removeKeysAndLogout(keys: string[], event: MessageEvent, request: any) { try { for (const key of keys) { try { - await SecureStoragePlugin.remove({ key }); - await SecureStoragePlugin.remove({ key: `${key}_iv` }); // Remove associated IV + if (keysToEncrypt.includes(key)) { + // Remove from Secure Storage for sensitive keys + await SecureStoragePlugin.remove({ key }); + } else { + // Remove from Capacitor Preferences for non-sensitive keys + await Preferences.remove({ key }); + } } catch (error) { console.warn(`Key not found: ${key}`); }