@ethora/chat-component-rn 26.6.13 → 26.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/commonjs/components/AuthForms/Login.js +2 -3
- package/lib/commonjs/components/AuthForms/Login.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js +9 -8
- package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
- package/lib/commonjs/components/Modals/NewChatModal/ModalContent.js +2 -1
- package/lib/commonjs/components/Modals/NewChatModal/ModalContent.js.map +1 -1
- package/lib/commonjs/components/Modals/NewChatModal/UpdNewChatModal.js +8 -0
- package/lib/commonjs/components/Modals/NewChatModal/UpdNewChatModal.js.map +1 -1
- package/lib/commonjs/components/Modals/UserProfileModal/EditUserModal.js +7 -21
- package/lib/commonjs/components/Modals/UserProfileModal/EditUserModal.js.map +1 -1
- package/lib/commonjs/context/xmppProvider.js +2 -3
- package/lib/commonjs/context/xmppProvider.js.map +1 -1
- package/lib/commonjs/helpers/ensureScopedChatCache.js +2 -2
- package/lib/commonjs/helpers/ensureScopedChatCache.js.map +1 -1
- package/lib/commonjs/helpers/persistCrypto.js +122 -0
- package/lib/commonjs/helpers/persistCrypto.js.map +1 -0
- package/lib/commonjs/helpers/pickImageAsset.js +68 -0
- package/lib/commonjs/helpers/pickImageAsset.js.map +1 -0
- package/lib/commonjs/helpers/resolveInitBeforeLoadUser.js +5 -6
- package/lib/commonjs/helpers/resolveInitBeforeLoadUser.js.map +1 -1
- package/lib/commonjs/helpers/secureKeyValue.js +83 -0
- package/lib/commonjs/helpers/secureKeyValue.js.map +1 -0
- package/lib/commonjs/helpers/secureStoreRuntime.js +59 -0
- package/lib/commonjs/helpers/secureStoreRuntime.js.map +1 -0
- package/lib/commonjs/helpers/secureUserStorage.js +75 -0
- package/lib/commonjs/helpers/secureUserStorage.js.map +1 -0
- package/lib/commonjs/hooks/useLogout.js +15 -7
- package/lib/commonjs/hooks/useLogout.js.map +1 -1
- package/lib/commonjs/networking/authRefresh.js +4 -5
- package/lib/commonjs/networking/authRefresh.js.map +1 -1
- package/lib/commonjs/roomStore/chatSettingsSlice.js +3 -4
- package/lib/commonjs/roomStore/chatSettingsSlice.js.map +1 -1
- package/lib/commonjs/roomStore/persistence.js +29 -15
- package/lib/commonjs/roomStore/persistence.js.map +1 -1
- package/lib/commonjs/roomStore/roomsSlice.js +2 -0
- package/lib/commonjs/roomStore/roomsSlice.js.map +1 -1
- package/lib/module/components/AuthForms/Login.js +2 -3
- package/lib/module/components/AuthForms/Login.js.map +1 -1
- package/lib/module/components/MainComponents/ProfileImagePlaceholder.js +9 -8
- package/lib/module/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
- package/lib/module/components/Modals/NewChatModal/ModalContent.js +2 -1
- package/lib/module/components/Modals/NewChatModal/ModalContent.js.map +1 -1
- package/lib/module/components/Modals/NewChatModal/UpdNewChatModal.js +8 -0
- package/lib/module/components/Modals/NewChatModal/UpdNewChatModal.js.map +1 -1
- package/lib/module/components/Modals/UserProfileModal/EditUserModal.js +9 -23
- package/lib/module/components/Modals/UserProfileModal/EditUserModal.js.map +1 -1
- package/lib/module/context/xmppProvider.js +2 -3
- package/lib/module/context/xmppProvider.js.map +1 -1
- package/lib/module/helpers/ensureScopedChatCache.js +2 -2
- package/lib/module/helpers/ensureScopedChatCache.js.map +1 -1
- package/lib/module/helpers/persistCrypto.js +115 -0
- package/lib/module/helpers/persistCrypto.js.map +1 -0
- package/lib/module/helpers/pickImageAsset.js +63 -0
- package/lib/module/helpers/pickImageAsset.js.map +1 -0
- package/lib/module/helpers/resolveInitBeforeLoadUser.js +5 -6
- package/lib/module/helpers/resolveInitBeforeLoadUser.js.map +1 -1
- package/lib/module/helpers/secureKeyValue.js +75 -0
- package/lib/module/helpers/secureKeyValue.js.map +1 -0
- package/lib/module/helpers/secureStoreRuntime.js +52 -0
- package/lib/module/helpers/secureStoreRuntime.js.map +1 -0
- package/lib/module/helpers/secureUserStorage.js +72 -0
- package/lib/module/helpers/secureUserStorage.js.map +1 -0
- package/lib/module/hooks/useLogout.js +15 -7
- package/lib/module/hooks/useLogout.js.map +1 -1
- package/lib/module/networking/authRefresh.js +4 -5
- package/lib/module/networking/authRefresh.js.map +1 -1
- package/lib/module/roomStore/chatSettingsSlice.js +3 -4
- package/lib/module/roomStore/chatSettingsSlice.js.map +1 -1
- package/lib/module/roomStore/persistence.js +30 -15
- package/lib/module/roomStore/persistence.js.map +1 -1
- package/lib/module/roomStore/roomsSlice.js +2 -0
- package/lib/module/roomStore/roomsSlice.js.map +1 -1
- package/lib/typescript/components/AuthForms/Login.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ProfileImagePlaceholder.d.ts.map +1 -1
- package/lib/typescript/components/Modals/NewChatModal/ModalContent.d.ts +4 -2
- package/lib/typescript/components/Modals/NewChatModal/ModalContent.d.ts.map +1 -1
- package/lib/typescript/components/Modals/NewChatModal/UpdNewChatModal.d.ts.map +1 -1
- package/lib/typescript/components/Modals/UserProfileModal/EditUserModal.d.ts.map +1 -1
- package/lib/typescript/context/xmppProvider.d.ts.map +1 -1
- package/lib/typescript/helpers/persistCrypto.d.ts +13 -0
- package/lib/typescript/helpers/persistCrypto.d.ts.map +1 -0
- package/lib/typescript/helpers/pickImageAsset.d.ts +27 -0
- package/lib/typescript/helpers/pickImageAsset.d.ts.map +1 -0
- package/lib/typescript/helpers/resolveInitBeforeLoadUser.d.ts.map +1 -1
- package/lib/typescript/helpers/secureKeyValue.d.ts +13 -0
- package/lib/typescript/helpers/secureKeyValue.d.ts.map +1 -0
- package/lib/typescript/helpers/secureStoreRuntime.d.ts +29 -0
- package/lib/typescript/helpers/secureStoreRuntime.d.ts.map +1 -0
- package/lib/typescript/helpers/secureUserStorage.d.ts +23 -0
- package/lib/typescript/helpers/secureUserStorage.d.ts.map +1 -0
- package/lib/typescript/hooks/useLogout.d.ts.map +1 -1
- package/lib/typescript/networking/authRefresh.d.ts.map +1 -1
- package/lib/typescript/roomStore/chatSettingsSlice.d.ts.map +1 -1
- package/lib/typescript/roomStore/persistence.d.ts.map +1 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts.map +1 -1
- package/package.json +8 -1
- package/src/components/AuthForms/Login.tsx +2 -3
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +16 -9
- package/src/components/Modals/NewChatModal/ModalContent.tsx +6 -3
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +12 -1
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +9 -25
- package/src/context/xmppProvider.tsx +2 -3
- package/src/helpers/ensureScopedChatCache.ts +2 -2
- package/src/helpers/persistCrypto.ts +127 -0
- package/src/helpers/pickImageAsset.ts +68 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +5 -10
- package/src/helpers/secureKeyValue.ts +80 -0
- package/src/helpers/secureStoreRuntime.ts +62 -0
- package/src/helpers/secureUserStorage.ts +80 -0
- package/src/hooks/useLogout.tsx +15 -9
- package/src/networking/authRefresh.ts +4 -9
- package/src/roomStore/chatSettingsSlice.ts +3 -6
- package/src/roomStore/persistence.ts +39 -19
- package/src/roomStore/roomsSlice.ts +2 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { loadSecureStore } from './secureStoreRuntime';
|
|
5
|
+
import { pushLog } from '../utils/devLogger';
|
|
6
|
+
|
|
7
|
+
// Fallback keys are prefixed and namespaced away from every other
|
|
8
|
+
// AsyncStorage key this SDK writes, so a host that never installs
|
|
9
|
+
// expo-secure-store can still be told apart from one that used to lack
|
|
10
|
+
// it and has since added it (see `secureSet`'s stale-fallback cleanup).
|
|
11
|
+
const FALLBACK_PREFIX = '@ethora/secure-fallback:';
|
|
12
|
+
let warnedFallback = false;
|
|
13
|
+
const warnFallbackOnce = () => {
|
|
14
|
+
if (warnedFallback) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
warnedFallback = true;
|
|
18
|
+
pushLog('warn', 'expo-secure-store is not installed — auth tokens, the XMPP ' + 'password, and the message-history cipher key are falling back ' + 'to plain AsyncStorage instead of the platform Keychain/Keystore. ' + 'Add the optional peer dependency `expo-secure-store` to your app ' + 'to store them securely.');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Small-value secure KV store: platform Keychain/Keystore via
|
|
23
|
+
* expo-secure-store when the host has it installed, plain (but still
|
|
24
|
+
* namespaced) AsyncStorage otherwise. NOT for bulk data — see
|
|
25
|
+
* `persistCrypto.ts`'s size note on why message history goes through
|
|
26
|
+
* AES instead of straight into this store.
|
|
27
|
+
*/
|
|
28
|
+
export async function secureGet(key) {
|
|
29
|
+
const store = loadSecureStore();
|
|
30
|
+
if (store) {
|
|
31
|
+
try {
|
|
32
|
+
return await store.getItemAsync(key);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
pushLog('warn', `secureStore: getItemAsync(${key}) failed`, e);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
warnFallbackOnce();
|
|
39
|
+
return AsyncStorage.getItem(FALLBACK_PREFIX + key);
|
|
40
|
+
}
|
|
41
|
+
export async function secureSet(key, value) {
|
|
42
|
+
const store = loadSecureStore();
|
|
43
|
+
if (store) {
|
|
44
|
+
try {
|
|
45
|
+
await store.setItemAsync(key, value);
|
|
46
|
+
// Clean up a stale plaintext fallback copy from before this host
|
|
47
|
+
// added expo-secure-store — otherwise it sits on disk forever.
|
|
48
|
+
AsyncStorage.removeItem(FALLBACK_PREFIX + key).catch(() => undefined);
|
|
49
|
+
return;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
pushLog('warn', `secureStore: setItemAsync(${key}) failed`, e);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
warnFallbackOnce();
|
|
56
|
+
await AsyncStorage.setItem(FALLBACK_PREFIX + key, value);
|
|
57
|
+
}
|
|
58
|
+
export async function secureRemove(key) {
|
|
59
|
+
const store = loadSecureStore();
|
|
60
|
+
if (store) {
|
|
61
|
+
try {
|
|
62
|
+
await store.deleteItemAsync(key);
|
|
63
|
+
} catch {
|
|
64
|
+
// Key may simply not exist — deleteItemAsync throwing here isn't
|
|
65
|
+
// actionable either way.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
await AsyncStorage.removeItem(FALLBACK_PREFIX + key).catch(() => undefined);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Test seam only. */
|
|
72
|
+
export const __resetSecureKeyValueWarningForTests = () => {
|
|
73
|
+
warnedFallback = false;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=secureKeyValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AsyncStorage","loadSecureStore","pushLog","FALLBACK_PREFIX","warnedFallback","warnFallbackOnce","secureGet","key","store","getItemAsync","e","getItem","secureSet","value","setItemAsync","removeItem","catch","undefined","setItem","secureRemove","deleteItemAsync","__resetSecureKeyValueWarningForTests"],"sourceRoot":"../../../src","sources":["helpers/secureKeyValue.ts"],"mappings":";;AAAA,OAAOA,YAAY,MAAM,2CAA2C;AACpE,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,0BAA0B;AAElD,IAAIC,cAAc,GAAG,KAAK;AAC1B,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EAC7B,IAAID,cAAc,EAAE;IAAC;EAAO;EAC5BA,cAAc,GAAG,IAAI;EACrBF,OAAO,CACL,MAAM,EACN,6DAA6D,GAC3D,gEAAgE,GAChE,mEAAmE,GACnE,mEAAmE,GACnE,yBACJ,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeI,SAASA,CAAC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,MAAMC,SAAS,CAAC;AAC7E;;AAEA;AACA,OAAO,MAAMI,oCAAoC,GAAGA,CAAA,KAAY;EAC9DjB,cAAc,GAAG,KAAK;AACxB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Optional-dependency bridge for `expo-secure-store` — the Keychain
|
|
5
|
+
* (iOS) / Keystore-backed EncryptedSharedPreferences (Android) API.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `components/VideoCalls/livekitRuntime.ts`: a plain top-level
|
|
8
|
+
* `import ... from 'expo-secure-store'` is not allowed anywhere in the
|
|
9
|
+
* SDK, since Metro resolves imports at bundle time and a host that
|
|
10
|
+
* hasn't added this optional peer dependency would fail to build over
|
|
11
|
+
* a feature it never opted into. Everything goes through
|
|
12
|
+
* `loadSecureStore()`, which requires the module lazily and returns
|
|
13
|
+
* null when it isn't installed — callers fall back to plain
|
|
14
|
+
* AsyncStorage rather than crash (see `secureKeyValue.ts`).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
let cached;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the SecureStore runtime, or null when the optional native
|
|
21
|
+
* package isn't installed in the host app. Result is memoised
|
|
22
|
+
* (including the failure) so a missing dependency doesn't re-throw on
|
|
23
|
+
* every read/write.
|
|
24
|
+
*/
|
|
25
|
+
export const loadSecureStore = () => {
|
|
26
|
+
if (cached !== undefined) {
|
|
27
|
+
return cached;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
31
|
+
const mod = require('expo-secure-store');
|
|
32
|
+
if (typeof mod?.getItemAsync !== 'function' || typeof mod?.setItemAsync !== 'function' || typeof mod?.deleteItemAsync !== 'function') {
|
|
33
|
+
cached = null;
|
|
34
|
+
} else {
|
|
35
|
+
cached = {
|
|
36
|
+
getItemAsync: mod.getItemAsync,
|
|
37
|
+
setItemAsync: mod.setItemAsync,
|
|
38
|
+
deleteItemAsync: mod.deleteItemAsync
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
cached = null;
|
|
43
|
+
}
|
|
44
|
+
return cached;
|
|
45
|
+
};
|
|
46
|
+
export const isSecureStoreAvailable = () => loadSecureStore() !== null;
|
|
47
|
+
|
|
48
|
+
/** Test seam only. */
|
|
49
|
+
export const __resetSecureStoreRuntimeForTests = () => {
|
|
50
|
+
cached = undefined;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=secureStoreRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["cached","loadSecureStore","undefined","mod","require","getItemAsync","setItemAsync","deleteItemAsync","isSecureStoreAvailable","__resetSecureStoreRuntimeForTests"],"sourceRoot":"../../../src","sources":["helpers/secureStoreRuntime.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,IAAIA,MAA6C;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAGA,CAAA,KAAiC;EAC9D,IAAID,MAAM,KAAKE,SAAS,EAAE;IACxB,OAAOF,MAAM;EACf;EAEA,IAAI;IACF;IACA,MAAMG,GAAG,GAAGC,OAAO,CAAC,mBAAmB,CAAC;IACxC,IACE,OAAOD,GAAG,EAAEE,YAAY,KAAK,UAAU,IACvC,OAAOF,GAAG,EAAEG,YAAY,KAAK,UAAU,IACvC,OAAOH,GAAG,EAAEI,eAAe,KAAK,UAAU,EAC1C;MACAP,MAAM,GAAG,IAAI;IACf,CAAC,MAAM;MACLA,MAAM,GAAG;QACPK,YAAY,EAAEF,GAAG,CAACE,YAAY;QAC9BC,YAAY,EAAEH,GAAG,CAACG,YAAY;QAC9BC,eAAe,EAAEJ,GAAG,CAACI;MACvB,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACNP,MAAM,GAAG,IAAI;EACf;EAEA,OAAOA,MAAM;AACf,CAAC;AAED,OAAO,MAAMQ,sBAAsB,GAAGA,CAAA,KAAeP,eAAe,CAAC,CAAC,KAAK,IAAI;;AAE/E;AACA,OAAO,MAAMQ,iCAAiC,GAAGA,CAAA,KAAY;EAC3DT,MAAM,GAAGE,SAAS;AACpB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { asyncLocalStorage } from '../hooks/useLocalStorage';
|
|
4
|
+
import { localStorageConstants } from './constants/LOCAL_STORAGE';
|
|
5
|
+
import { secureGet, secureSet, secureRemove } from './secureKeyValue';
|
|
6
|
+
|
|
7
|
+
// Keychain (iOS) / Keystore-backed EncryptedSharedPreferences (Android)
|
|
8
|
+
// keys for the four live bearer credentials on `User`. Deliberately one
|
|
9
|
+
// key per field rather than one JSON blob: expo-secure-store historically
|
|
10
|
+
// caps a single value's size on Android, and four short JWTs each stay
|
|
11
|
+
// comfortably under that ceiling where one combined blob might not.
|
|
12
|
+
const SECRET_KEYS = {
|
|
13
|
+
token: 'ethora_auth_token',
|
|
14
|
+
refreshToken: 'ethora_auth_refresh_token',
|
|
15
|
+
xmppPassword: 'ethora_auth_xmpp_password',
|
|
16
|
+
fileToken: 'ethora_auth_file_token'
|
|
17
|
+
};
|
|
18
|
+
const SECRET_FIELDS = Object.keys(SECRET_KEYS);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Persisted-user storage, split across two backends behind the exact
|
|
22
|
+
* same `{ get, set, remove }` shape `asyncLocalStorage<User>(...)`
|
|
23
|
+
* already exposed — every existing call site swaps in by changing only
|
|
24
|
+
* the constructor call, `get()`/`set()`/`remove()` keep returning/taking
|
|
25
|
+
* a complete `User`.
|
|
26
|
+
*
|
|
27
|
+
* The four live credentials (REST access + refresh token, XMPP
|
|
28
|
+
* password, secure-media fileToken) never touch plain AsyncStorage:
|
|
29
|
+
* they go through `secureGet`/`secureSet`/`secureRemove` (platform
|
|
30
|
+
* Keychain/Keystore, falling back to namespaced AsyncStorage only when
|
|
31
|
+
* the host hasn't installed the optional `expo-secure-store` peer dep).
|
|
32
|
+
* Everything else on `User` — name, avatar, ids, xmppUsername, wallet
|
|
33
|
+
* address, none of it a bearer credential — keeps living under the
|
|
34
|
+
* existing `ETHORA_USER` AsyncStorage key, unchanged.
|
|
35
|
+
*/
|
|
36
|
+
export function secureUserStorage() {
|
|
37
|
+
const get = async () => {
|
|
38
|
+
const profile = await asyncLocalStorage(localStorageConstants.ETHORA_USER).get();
|
|
39
|
+
if (!profile) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const secretValues = await Promise.all(SECRET_FIELDS.map(field => secureGet(SECRET_KEYS[field])));
|
|
43
|
+
const merged = {
|
|
44
|
+
...profile
|
|
45
|
+
};
|
|
46
|
+
SECRET_FIELDS.forEach((field, i) => {
|
|
47
|
+
merged[field] = secretValues[i] || '';
|
|
48
|
+
});
|
|
49
|
+
return merged;
|
|
50
|
+
};
|
|
51
|
+
const set = async user => {
|
|
52
|
+
const profile = {
|
|
53
|
+
...user
|
|
54
|
+
};
|
|
55
|
+
for (const field of SECRET_FIELDS) {
|
|
56
|
+
profile[field] = '';
|
|
57
|
+
}
|
|
58
|
+
await Promise.all([asyncLocalStorage(localStorageConstants.ETHORA_USER).set(profile), ...SECRET_FIELDS.map(field => {
|
|
59
|
+
const value = user?.[field];
|
|
60
|
+
return value ? secureSet(SECRET_KEYS[field], value) : secureRemove(SECRET_KEYS[field]);
|
|
61
|
+
})]);
|
|
62
|
+
};
|
|
63
|
+
const remove = async () => {
|
|
64
|
+
await Promise.all([asyncLocalStorage(localStorageConstants.ETHORA_USER).remove(), ...SECRET_FIELDS.map(field => secureRemove(SECRET_KEYS[field]))]);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
get,
|
|
68
|
+
set,
|
|
69
|
+
remove
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=secureUserStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["asyncLocalStorage","localStorageConstants","secureGet","secureSet","secureRemove","SECRET_KEYS","token","refreshToken","xmppPassword","fileToken","SECRET_FIELDS","Object","keys","secureUserStorage","get","profile","ETHORA_USER","secretValues","Promise","all","map","field","merged","forEach","i","set","user","value","remove"],"sourceRoot":"../../../src","sources":["helpers/secureUserStorage.ts"],"mappings":";;AACA,SAASA,iBAAiB,QAAQ,0BAA0B;AAC5D,SAASC,qBAAqB,QAAQ,2BAA2B;AACjE,SAASC,SAAS,EAAEC,SAAS,EAAEC,YAAY,QAAQ,kBAAkB;;AAErE;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG;EAClBC,KAAK,EAAE,mBAAmB;EAC1BC,YAAY,EAAE,2BAA2B;EACzCC,YAAY,EAAE,2BAA2B;EACzCC,SAAS,EAAE;AACb,CAAU;AAGV,MAAMC,aAAa,GAAGC,MAAM,CAACC,IAAI,CAACP,WAAW,CAAkB;;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,iBAAiBA,CAAA,EAAG;EAClC,MAAMC,GAAG,GAAG,MAAAA,CAAA,KAAkC;IAC5C,MAAMC,OAAO,GAAG,MAAMf,iBAAiB,CACrCC,qBAAqB,CAACe,WACxB,CAAC,CAACF,GAAG,CAAC,CAAC;IACP,IAAI,CAACC,OAAO,EAAE;MAAC,OAAO,IAAI;IAAC;IAE3B,MAAME,YAAY,GAAG,MAAMC,OAAO,CAACC,GAAG,CACpCT,aAAa,CAACU,GAAG,CAAEC,KAAK,IAAKnB,SAAS,CAACG,WAAW,CAACgB,KAAK,CAAC,CAAC,CAC5D,CAAC;IAED,MAAMC,MAAY,GAAG;MAAE,GAAGP;IAAQ,CAAC;IACnCL,aAAa,CAACa,OAAO,CAAC,CAACF,KAAK,EAAEG,CAAC,KAAK;MACjCF,MAAM,CAASD,KAAK,CAAC,GAAGJ,YAAY,CAACO,CAAC,CAAC,IAAI,EAAE;IAChD,CAAC,CAAC;IACF,OAAOF,MAAM;EACf,CAAC;EAED,MAAMG,GAAG,GAAG,MAAOC,IAAU,IAAoB;IAC/C,MAAMX,OAAY,GAAG;MAAE,GAAGW;IAAK,CAAC;IAChC,KAAK,MAAML,KAAK,IAAIX,aAAa,EAAE;MACjCK,OAAO,CAACM,KAAK,CAAC,GAAG,EAAE;IACrB;IAEA,MAAMH,OAAO,CAACC,GAAG,CAAC,CAChBnB,iBAAiB,CAAOC,qBAAqB,CAACe,WAAW,CAAC,CAACS,GAAG,CAACV,OAAO,CAAC,EACvE,GAAGL,aAAa,CAACU,GAAG,CAAEC,KAAK,IAAK;MAC9B,MAAMM,KAAK,GAAGD,IAAI,GAAGL,KAAK,CAAuB;MACjD,OAAOM,KAAK,GACRxB,SAAS,CAACE,WAAW,CAACgB,KAAK,CAAC,EAAEM,KAAK,CAAC,GACpCvB,YAAY,CAACC,WAAW,CAACgB,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CACH,CAAC;EACJ,CAAC;EAED,MAAMO,MAAM,GAAG,MAAAA,CAAA,KAA2B;IACxC,MAAMV,OAAO,CAACC,GAAG,CAAC,CAChBnB,iBAAiB,CAACC,qBAAqB,CAACe,WAAW,CAAC,CAACY,MAAM,CAAC,CAAC,EAC7D,GAAGlB,aAAa,CAACU,GAAG,CAAEC,KAAK,IAAKjB,YAAY,CAACC,WAAW,CAACgB,KAAK,CAAC,CAAC,CAAC,CAClE,CAAC;EACJ,CAAC;EAED,OAAO;IAAEP,GAAG;IAAEW,GAAG;IAAEG;EAAO,CAAC;AAC7B","ignoreList":[]}
|
|
@@ -11,7 +11,7 @@ import { clearHeap } from '../roomStore/roomHeapSlice';
|
|
|
11
11
|
import { pushSubscriptionService } from '../services/pushSubscriptionService';
|
|
12
12
|
import { clearRoomsRestCache } from '../networking/api-requests/rooms.api';
|
|
13
13
|
import { clearPersistedState } from '../roomStore/persistence';
|
|
14
|
-
import {
|
|
14
|
+
import { secureUserStorage } from '../helpers/secureUserStorage';
|
|
15
15
|
|
|
16
16
|
// AsyncStorage keys the library writes but that aren't cleared by any
|
|
17
17
|
// slice reducer. Listed here so a single logout call wipes the full
|
|
@@ -117,15 +117,23 @@ const logoutService = {
|
|
|
117
117
|
|
|
118
118
|
// 6. Stray keys the slices don't touch.
|
|
119
119
|
try {
|
|
120
|
-
await AsyncStorage.multiRemove(
|
|
121
|
-
// Belt-and-suspenders: the chat slice's `logout` reducer
|
|
122
|
-
// schedules an async remove of ETHORA_USER fire-and-forget;
|
|
123
|
-
// re-issue it here so the disk is provably clean before this
|
|
124
|
-
// Promise resolves.
|
|
125
|
-
localStorageConstants.ETHORA_USER]);
|
|
120
|
+
await AsyncStorage.multiRemove(LIBRARY_STRAY_KEYS);
|
|
126
121
|
} catch (e) {
|
|
127
122
|
console.warn('logoutService: stray-key clear failed', e);
|
|
128
123
|
}
|
|
124
|
+
|
|
125
|
+
// 7. Belt-and-suspenders: the chat slice's `logout` reducer already
|
|
126
|
+
// fires an async ETHORA_USER removal, but re-issue it here (via
|
|
127
|
+
// the same secureUserStorage split the reducer uses) so BOTH the
|
|
128
|
+
// plain-AsyncStorage profile half AND the Keychain/Keystore
|
|
129
|
+
// secrets are provably gone before this Promise resolves — a bare
|
|
130
|
+
// `AsyncStorage.removeItem(ETHORA_USER)` here would only clear the
|
|
131
|
+
// profile half and leave the tokens behind.
|
|
132
|
+
try {
|
|
133
|
+
await secureUserStorage().remove();
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.warn('logoutService: secure user storage clear failed', e);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
};
|
|
131
139
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","DeviceEventEmitter","AsyncStorage","store","logout","setLogoutState","useCallback","clearHeap","pushSubscriptionService","clearRoomsRestCache","clearPersistedState","
|
|
1
|
+
{"version":3,"names":["useDispatch","DeviceEventEmitter","AsyncStorage","store","logout","setLogoutState","useCallback","clearHeap","pushSubscriptionService","clearRoomsRestCache","clearPersistedState","secureUserStorage","LIBRARY_STRAY_KEYS","logoutService","performLogout","state","getState","client","chatSettingStore","rooms","visibleRoomJID","flushLastViewedToPrivateStoreStanza","Promise","race","onlyIfNoUnread","res","setTimeout","e","console","warn","emit","reset","dispatch","multiRemove","remove","useLogout","err"],"sourceRoot":"../../../src","sources":["hooks/useLogout.tsx"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,aAAa;AACzC,SAASC,kBAAkB,QAAQ,cAAc;AACjD,OAAOC,YAAY,MAAM,2CAA2C;AACpE,SAASC,KAAK,QAAQ,cAAc;AACpC,SAASC,MAAM,QAAQ,gCAAgC;AACvD,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,WAAW,QAAQ,OAAO;AACnC,SAASC,SAAS,QAAQ,4BAA4B;AACtD,SAASC,uBAAuB,QAAQ,qCAAqC;AAC7E,SAASC,mBAAmB,QAAQ,sCAAsC;AAC1E,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,iBAAiB,QAAQ,8BAA8B;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,CACzB,iCAAiC,CAAE;AAAA,CACpC;AAED,MAAMC,aAAa,GAAG;EACpB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,aAAa,EAAE,MAAAA,CAAA,KAA2B;IACxC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI;MACF,MAAMC,KAAK,GAAGZ,KAAK,CAACa,QAAQ,CAAC,CAAC;MAC9B,MAAMC,MAAM,GAAIF,KAAK,CAACG,gBAAgB,EAAUD,MAAM;MACtD,MAAME,KAAK,GAAGJ,KAAK,CAACI,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,mBAAmB,CAAC,CAAC;IAC7B,CAAC,CAAC,MAAM;MACN;IAAA;;IAGF;IACA,IAAI;MACF,MAAMR,YAAY,CAAC+B,WAAW,CAACrB,kBAAkB,CAAC;IACpD,CAAC,CAAC,OAAOe,CAAC,EAAE;MACVC,OAAO,CAACC,IAAI,CAAC,uCAAuC,EAAEF,CAAC,CAAC;IAC1D;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI;MACF,MAAMhB,iBAAiB,CAAC,CAAC,CAACuB,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,OAAOP,CAAC,EAAE;MACVC,OAAO,CAACC,IAAI,CAAC,iDAAiD,EAAEF,CAAC,CAAC;IACpE;EACF;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMQ,SAAS,GAAGA,CAAA,KAA6B;EACpD;EACA;EACA;EACAnC,WAAW,CAAC,CAAC;EAEb,OAAOM,WAAW,CAAC,YAAY;IAC7B,IAAI;MACF,MAAMO,aAAa,CAACC,aAAa,CAAC,CAAC;IACrC,CAAC,CAAC,OAAOsB,GAAG,EAAE;MACZR,OAAO,CAACC,IAAI,CAAC,iCAAiC,EAAEO,GAAG,CAAC;IACtD;EACF,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAED,SAASvB,aAAa","ignoreList":[]}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
import http from './apiClient';
|
|
4
4
|
import { store } from '../roomStore';
|
|
5
5
|
import { refreshTokens } from '../roomStore/chatSettingsSlice';
|
|
6
|
-
import {
|
|
7
|
-
import { localStorageConstants } from '../helpers/constants/LOCAL_STORAGE';
|
|
6
|
+
import { secureUserStorage } from '../helpers/secureUserStorage';
|
|
8
7
|
import { pushLog } from '../utils/devLogger';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -110,7 +109,7 @@ const readCurrentRefreshToken = async () => {
|
|
|
110
109
|
if (fromStore) {
|
|
111
110
|
return fromStore;
|
|
112
111
|
}
|
|
113
|
-
const stored = await
|
|
112
|
+
const stored = await secureUserStorage().get();
|
|
114
113
|
return stored?.refreshToken || '';
|
|
115
114
|
};
|
|
116
115
|
|
|
@@ -132,7 +131,7 @@ const persistTokens = async result => {
|
|
|
132
131
|
// Write the post-dispatch snapshot rather than a read-modify-write
|
|
133
132
|
// merge, so this can't race the reducer's own write back to a
|
|
134
133
|
// stale copy of the surrounding user fields.
|
|
135
|
-
await
|
|
134
|
+
await secureUserStorage().set(store.getState().chatSettingStore.user);
|
|
136
135
|
} catch (error) {
|
|
137
136
|
pushLog('warn', 'authRefresh: failed to persist rotated tokens', error);
|
|
138
137
|
}
|
|
@@ -144,7 +143,7 @@ const persistTokens = async result => {
|
|
|
144
143
|
* web build and this one stay structurally identical.
|
|
145
144
|
*/
|
|
146
145
|
const adoptStoredTokens = async () => {
|
|
147
|
-
const stored = await
|
|
146
|
+
const stored = await secureUserStorage().get();
|
|
148
147
|
if (!stored?.refreshToken || !stored?.token) {
|
|
149
148
|
return null;
|
|
150
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["http","store","refreshTokens","
|
|
1
|
+
{"version":3,"names":["http","store","refreshTokens","secureUserStorage","pushLog","RefreshFatalError","Error","constructor","code","message","name","Object","setPrototypeOf","prototype","isRefreshFatalError","error","REFRESH_ENDPOINT","IN_PROGRESS_MAX_ATTEMPTS","IN_PROGRESS_BASE_DELAY_MS","IN_PROGRESS_JITTER_MS","KNOWN_CODES","sleep","ms","Promise","resolve","setTimeout","inProgressDelay","attempt","Math","floor","random","parseRefreshErrorCode","response","data","candidates","errors","headers","candidate","match","find","includes","getStoreUser","getState","chatSettingStore","user","readCurrentRefreshToken","fromStore","refreshToken","stored","get","persistTokens","result","dispatch","token","xmppPassword","fileToken","set","adoptStoredTokens","runConsumerRefresh","refreshFunction","refreshed","accessToken","requestRotation","post","Authorization","wsToken","performRefresh","overrideToken","consumerRefresh","config","adopted","inflight","refreshAuthTokens","options","finally","refreshAuthTokensQuietly","__resetAuthRefreshStateForTests"],"sourceRoot":"../../../src","sources":["networking/authRefresh.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,aAAa;AAC9B,SAASC,KAAK,QAAQ,cAAc;AACpC,SAASC,aAAa,QAAQ,gCAAgC;AAC9D,SAASC,iBAAiB,QAAQ,8BAA8B;AAChE,SAASC,OAAO,QAAQ,oBAAoB;;AAG5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,SAASC,KAAK,CAAC;EAG3CC,WAAWA,CAACC,IAAsB,EAAEC,OAAgB,EAAE;IACpD,KAAK,CAACA,OAAO,IAAI,mBAAmBD,IAAI,EAAE,CAAC;IAC3C,IAAI,CAACE,IAAI,GAAG,mBAAmB;IAC/B,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB;IACA;IACAG,MAAM,CAACC,cAAc,CAAC,IAAI,EAAEP,iBAAiB,CAACQ,SAAS,CAAC;EAC1D;AACF;AAEA,OAAO,MAAMC,mBAAmB,GAC9BC,KAAc,IAEdA,KAAK,YAAYV,iBAAiB,IACjCU,KAAK,EAAwBL,IAAI,KAAK,mBAAmB;AAE5D,MAAMM,gBAAgB,GAAG,yBAAyB;;AAElD;AACA,MAAMC,wBAAwB,GAAG,CAAC;AAClC,MAAMC,yBAAyB,GAAG,GAAG;AACrC;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,GAAG,GAAG;AAEjC,MAAMC,WAA+B,GAAG,CACtC,qBAAqB,EACrB,+BAA+B,EAC/B,8BAA8B,EAC9B,yBAAyB,CAC1B;AAED,MAAMC,KAAK,GAAIC,EAAU,IACvB,IAAIC,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K,EAAE;IACdX,OAAO,CACLU,mBAAmB,CAACC,KAAK,CAAC,GAAG,OAAO,GAAG,MAAM,EAC7C,wCAAwC,EACxCA,KACF,CAAC;IACD,OAAO,IAAI;EACb;AACF;;AAEA;AACA,OAAO,SAAS6D,+BAA+BA,CAAA,EAAS;EACtDL,QAAQ,GAAG,IAAI;AACjB","ignoreList":[]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { createSlice } from '@reduxjs/toolkit';
|
|
4
|
-
import {
|
|
5
|
-
import { asyncLocalStorage } from '../hooks/useLocalStorage';
|
|
4
|
+
import { secureUserStorage } from '../helpers/secureUserStorage';
|
|
6
5
|
export const unpackAndTransform = input => {
|
|
7
6
|
return {
|
|
8
7
|
description: '',
|
|
@@ -88,7 +87,7 @@ const initialState = {
|
|
|
88
87
|
const reducers = {
|
|
89
88
|
setUser: (state, action) => {
|
|
90
89
|
state.user = unpackAndTransform(action.payload);
|
|
91
|
-
|
|
90
|
+
secureUserStorage().set(unpackAndTransform(action.payload));
|
|
92
91
|
},
|
|
93
92
|
updateUser(state, action) {
|
|
94
93
|
const {
|
|
@@ -151,7 +150,7 @@ const reducers = {
|
|
|
151
150
|
state.client = undefined;
|
|
152
151
|
state.langSource = undefined;
|
|
153
152
|
state.translateMode = undefined;
|
|
154
|
-
|
|
153
|
+
secureUserStorage().remove();
|
|
155
154
|
},
|
|
156
155
|
setLangSource: (state, action) => {
|
|
157
156
|
state.langSource = action.payload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSlice","
|
|
1
|
+
{"version":3,"names":["createSlice","secureUserStorage","unpackAndTransform","input","description","token","profileImage","_id","walletAddress","defaultWallet","xmppPassword","fileToken","refreshToken","firstName","lastName","email","username","appId","homeScreen","registrationChannelType","updatedAt","authMethod","resetPasswordExpires","resetPasswordToken","xmppUsername","roles","tags","__v","isProfileOpen","isAssetsOpen","isAgreeWithTerms","initialState","user","deleteModal","isDeleteModal","roomJid","messageId","config","colors","primary","secondary","reducers","setUser","state","action","payload","set","updateUser","updates","setConfig","setActiveModal","activeModal","setActiveFile","activeFile","setDeleteModal","setStoreClient","client","setSelectedUser","selectedUser","refreshTokens","logout","undefined","langSource","translateMode","remove","setLangSource","setTranslateMode","chatSlice","name","actions","reducer"],"sourceRoot":"../../../src","sources":["roomStore/chatSettingsSlice.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAmC,kBAAkB;AAazE,SAASC,iBAAiB,QAAQ,8BAA8B;AAoBhE,OAAO,MAAMC,kBAAkB,GAAIC,KAAY,IAAW;EACxD,OAAO;IACLC,WAAW,EAAE,EAAE;IACfC,KAAK,EAAEF,KAAK,EAAEE,KAAK,IAAI,EAAE;IACzBC,YAAY,EAAEH,KAAK,EAAEG,YAAY,IAAI,EAAE;IACvCC,GAAG,EAAEJ,KAAK,EAAEI,GAAG,IAAI,EAAE;IACrBC,aAAa,EAAEL,KAAK,EAAEM,aAAa,EAAED,aAAa,IAAI,EAAE;IACxDE,YAAY,EAAEP,KAAK,EAAEO,YAAY,IAAI,EAAE;IACvCC,SAAS,EAAER,KAAK,EAAEQ,SAAS,IAAI,EAAE;IACjCC,YAAY,EAAET,KAAK,EAAES,YAAY,IAAI,EAAE;IACvCC,SAAS,EAAEV,KAAK,EAAEU,SAAS,IAAI,EAAE;IACjCC,QAAQ,EAAEX,KAAK,EAAEW,QAAQ,IAAI,EAAE;IAC/BL,aAAa,EAAE;MACbD,aAAa,EAAEL,KAAK,EAAEM,aAAa,EAAED,aAAa,IAAI;IACxD,CAAC;IACDO,KAAK,EAAEZ,KAAK,EAAEY,KAAK,IAAI,EAAE;IACzBC,QAAQ,EAAEb,KAAK,EAAEa,QAAQ,IAAI,EAAE;IAC/BC,KAAK,EAAEd,KAAK,EAAEc,KAAK,IAAI,EAAE;IACzBC,UAAU,EAAEf,KAAK,EAAEe,UAAU,IAAI,EAAE;IACnCC,uBAAuB,EAAEhB,KAAK,EAAEgB,u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B,CAAC,CAAC,CAAC+D,MAAM,CAAC,CAAC;EAC9B,CAAC;EACDC,aAAa,EAAEA,CACbtB,KAA+B,EAC/BC,MAAgD,KAC7C;IACHD,KAAK,CAACmB,UAAU,GAAGlB,MAAM,CAACC,OAAO;EACnC,CAAC;EACDqB,gBAAgB,EAAEA,CAChBvB,KAA+B,EAC/BC,MAAgD,KAC7C;IACHD,KAAK,CAACoB,aAAa,GAAGnB,MAAM,CAACC,OAAO;EACtC;AACF,CAAC;AAED,OAAO,MAAMsB,SAAoD,GAAGnE,WAAW,CAAC;EAC9EoE,IAAI,EAAE,MAAM;EACZrC,YAAY;EACZU;AACF,CAAC,CAAC;AAEF,OAAO,MAAM;EACXC,OAAO;EACPO,SAAS;EACTU,aAAa;EACbC,MAAM;EACNV,cAAc;EACdI,cAAc;EACdG,eAAe;EACfV,UAAU;EACVK,aAAa;EACbG,cAAc;EACdU,aAAa;EACbC;AACF,CAAC,GAAGC,SAAS,CAACE,OAAO;AAErB,eAAeF,SAAS,CAACG,OAAO","ignoreList":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { encryptForPersist, decryptFromPersist } from '../helpers/persistCrypto';
|
|
5
|
+
|
|
4
6
|
// -------------------------------------------------------------------
|
|
5
7
|
// Lightweight RN persistence layer. Mirrors what redux-persist gives
|
|
6
8
|
// the web component:
|
|
@@ -10,7 +12,11 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
10
12
|
// - cap each room's messages to the most recent MESSAGE_LIMIT (100)
|
|
11
13
|
// - debounced writes (200ms) on relevant action types
|
|
12
14
|
//
|
|
13
|
-
//
|
|
15
|
+
// AES-256-CBC at rest (see `helpers/persistCrypto.ts`): the JSON blob
|
|
16
|
+
// under each key below is encrypted before it reaches AsyncStorage, with
|
|
17
|
+
// the symmetric key held in the platform Keychain/Keystore. `user` here
|
|
18
|
+
// is already secret-free (see `sanitizeUser`) — the encryption is for
|
|
19
|
+
// the message bodies in `rooms`, which aren't.
|
|
14
20
|
// -------------------------------------------------------------------
|
|
15
21
|
|
|
16
22
|
const KEY_CHAT = '@ethora/persist:chatSettingStore';
|
|
@@ -151,18 +157,21 @@ export const persistenceMiddleware = storeAPI => next => action => {
|
|
|
151
157
|
clearTimeout(writeTimer);
|
|
152
158
|
}
|
|
153
159
|
writeTimer = setTimeout(() => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
(async () => {
|
|
161
|
+
try {
|
|
162
|
+
const state = storeAPI.getState();
|
|
163
|
+
const chatPayload = {
|
|
164
|
+
user: sanitizeUser(state.chatSettingStore?.user)
|
|
165
|
+
};
|
|
166
|
+
const roomsPayload = {
|
|
167
|
+
rooms: sanitizeRooms(state.rooms?.rooms || {})
|
|
168
|
+
};
|
|
169
|
+
const [chatCipher, roomsCipher] = await Promise.all([encryptForPersist(JSON.stringify(chatPayload)), encryptForPersist(JSON.stringify(roomsPayload))]);
|
|
170
|
+
await AsyncStorage.multiSet([[KEY_CHAT, chatCipher], [KEY_ROOMS, roomsCipher]]);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
console.warn('persist write failed', e);
|
|
173
|
+
}
|
|
174
|
+
})();
|
|
166
175
|
}, 200);
|
|
167
176
|
return result;
|
|
168
177
|
};
|
|
@@ -175,8 +184,14 @@ export const persistenceMiddleware = storeAPI => next => action => {
|
|
|
175
184
|
export async function readPersistedState() {
|
|
176
185
|
try {
|
|
177
186
|
const [chatRaw, roomsRaw] = await AsyncStorage.multiGet([KEY_CHAT, KEY_ROOMS]);
|
|
178
|
-
const
|
|
179
|
-
|
|
187
|
+
const [chatPlain, roomsPlain] = await Promise.all([chatRaw[1] ? decryptFromPersist(chatRaw[1]) : Promise.resolve(null), roomsRaw[1] ? decryptFromPersist(roomsRaw[1]) : Promise.resolve(null)]);
|
|
188
|
+
// `decryptFromPersist` returns null both for "nothing stored" and
|
|
189
|
+
// for "stored value isn't a valid envelope for the current key" —
|
|
190
|
+
// notably a plaintext blob left over from a pre-encryption install.
|
|
191
|
+
// Either way there is nothing safe to parse, so the caller treats it
|
|
192
|
+
// as a cold start and re-hydrates from the server.
|
|
193
|
+
const chat = chatPlain ? JSON.parse(chatPlain) : null;
|
|
194
|
+
const rooms = roomsPlain ? JSON.parse(roomsPlain) : null;
|
|
180
195
|
return {
|
|
181
196
|
chat,
|
|
182
197
|
rooms
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AsyncStorage","KEY_CHAT","KEY_ROOMS","MESSAGE_LIMIT","sanitizeUser","user","token","_token","refreshToken","_refreshToken","xmppPassword","_xmppPassword","rest","PERSISTED_MESSAGE_FIELDS","PERSISTED_MESSAGE_USER_FIELDS","REFETCHED_ROOM_FIELDS","pickDefined","source","keys","out","key","value","undefined","compactMessageForPersist","message","compact","sanitizeMessages","messages","Array","isArray","capped","length","slice","map","sanitizeRooms","rooms","jid","room","Object","entries","includes","compactRoom","usersCnt","members","field","composing","composingList","isLoading","historyPreloadState","writeTimer","persistenceMiddleware","storeAPI","next","action","result","type","startsWith","clearTimeout","setTimeout","state","getState","chatPayload","chatSettingStore","roomsPayload","
|
|
1
|
+
{"version":3,"names":["AsyncStorage","encryptForPersist","decryptFromPersist","KEY_CHAT","KEY_ROOMS","MESSAGE_LIMIT","sanitizeUser","user","token","_token","refreshToken","_refreshToken","xmppPassword","_xmppPassword","rest","PERSISTED_MESSAGE_FIELDS","PERSISTED_MESSAGE_USER_FIELDS","REFETCHED_ROOM_FIELDS","pickDefined","source","keys","out","key","value","undefined","compactMessageForPersist","message","compact","sanitizeMessages","messages","Array","isArray","capped","length","slice","map","sanitizeRooms","rooms","jid","room","Object","entries","includes","compactRoom","usersCnt","members","field","composing","composingList","isLoading","historyPreloadState","writeTimer","persistenceMiddleware","storeAPI","next","action","result","type","startsWith","clearTimeout","setTimeout","state","getState","chatPayload","chatSettingStore","roomsPayload","chatCipher","roomsCipher","Promise","all","JSON","stringify","multiSet","e","console","warn","readPersistedState","chatRaw","roomsRaw","multiGet","chatPlain","roomsPlain","resolve","chat","parse","clearPersistedState","multiRemove","PERSIST_KEYS"],"sourceRoot":"../../../src","sources":["roomStore/persistence.ts"],"mappings":";;AAAA,OAAOA,YAAY,MAAM,2CAA2C;AAGpE,SAASC,iBAAiB,EAAEC,kBAAkB,QAAQ,0BAA0B;;AAEhF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,QAAQ,GAAG,kCAAkC;AACnD,MAAMC,SAAS,GAAG,uBAAuB;;AAEzC;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG,GAAG;AAWhC,MAAMC,YAAY,GAAIC,IAAW,IAAkB;EACjD,IAAI,CAACA,IAAI,EAAE;IAAC,OAAO,IAAI;EAAC;EACxB;EACA;EACA,MAAM;IACJC,KAAK,EAAEC,MAAM;IACbC,YAAY,EAAEC,aAAa;IAC3BC,YAAY,EAAEC,aAAa;IAC3B,GAAGC;EACL,CAAC,GAAGP,IAAW;EACf,OAAO;IACL,GAAGO,IAAI;IACPN,KAAK,EAAE,EAAE;IACTE,YAAY,EAAE,EAAE;IAChBE,YAAY,EAAE;EAChB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMG,wBAA4C,GAAG,CACnD,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,MAAM,EACN,YAAY,EACZ,SAAS,CACV;;AAED;AAC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AAE;IACVC,OAAO,CAACC,IAAI,CAAC,sBAAsB,EAAEF,CAAC,CAAC;EACzC;AACF;AAEA,OAAO,MAAMc,YAAY,GAAG;EAAEpF,QAAQ;EAAEC;AAAU,CAAC","ignoreList":[]}
|
|
@@ -264,6 +264,8 @@ const reducers = {
|
|
|
264
264
|
const existingMessages = Array.isArray(existing?.messages) ? existing.messages : [];
|
|
265
265
|
state.rooms[roomData.jid] = {
|
|
266
266
|
...roomData,
|
|
267
|
+
icon: roomData.icon !== undefined ? roomData.icon : existing?.icon,
|
|
268
|
+
roomBg: roomData.roomBg !== undefined ? roomData.roomBg : existing?.roomBg,
|
|
267
269
|
messages: existingMessages.length > 0 ? existingMessages : incomingMessages,
|
|
268
270
|
lastViewedTimestamp: lastViewed,
|
|
269
271
|
unreadMessages: roomData.unreadMessages ?? existing?.unreadMessages ?? 0,
|