@agora-sdk/secure-chat-core 0.4.0 → 0.6.0
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/dist/cjs/backup/passphrase-strength.d.ts +22 -0
- package/dist/cjs/backup/passphrase-strength.js +75 -0
- package/dist/cjs/backup/passphrase-strength.js.map +1 -0
- package/dist/cjs/context/secure-chat-context.d.ts +12 -1
- package/dist/cjs/context/secure-chat-context.js +3 -1
- package/dist/cjs/context/secure-chat-context.js.map +1 -1
- package/dist/cjs/hooks/useSecureBackup.d.ts +67 -0
- package/dist/cjs/hooks/useSecureBackup.js +207 -0
- package/dist/cjs/hooks/useSecureBackup.js.map +1 -0
- package/dist/cjs/hooks/useSecureDevice.d.ts +21 -1
- package/dist/cjs/hooks/useSecureDevice.js +46 -5
- package/dist/cjs/hooks/useSecureDevice.js.map +1 -1
- package/dist/cjs/hooks/useSecureMessages.d.ts +16 -3
- package/dist/cjs/hooks/useSecureMessages.js +38 -15
- package/dist/cjs/hooks/useSecureMessages.js.map +1 -1
- package/dist/cjs/hooks/useSecureSafetyNumber.d.ts +30 -0
- package/dist/cjs/hooks/useSecureSafetyNumber.js +82 -0
- package/dist/cjs/hooks/useSecureSafetyNumber.js.map +1 -0
- package/dist/cjs/index.d.ts +12 -1
- package/dist/cjs/index.js +16 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/util/padding.d.ts +39 -0
- package/dist/cjs/util/padding.js +80 -0
- package/dist/cjs/util/padding.js.map +1 -0
- package/dist/cjs/util/safety-number.d.ts +27 -0
- package/dist/cjs/util/safety-number.js +84 -0
- package/dist/cjs/util/safety-number.js.map +1 -0
- package/dist/esm/backup/passphrase-strength.d.ts +22 -0
- package/dist/esm/backup/passphrase-strength.js +72 -0
- package/dist/esm/backup/passphrase-strength.js.map +1 -0
- package/dist/esm/context/secure-chat-context.d.ts +12 -1
- package/dist/esm/context/secure-chat-context.js +3 -1
- package/dist/esm/context/secure-chat-context.js.map +1 -1
- package/dist/esm/hooks/useSecureBackup.d.ts +67 -0
- package/dist/esm/hooks/useSecureBackup.js +204 -0
- package/dist/esm/hooks/useSecureBackup.js.map +1 -0
- package/dist/esm/hooks/useSecureDevice.d.ts +21 -1
- package/dist/esm/hooks/useSecureDevice.js +46 -5
- package/dist/esm/hooks/useSecureDevice.js.map +1 -1
- package/dist/esm/hooks/useSecureMessages.d.ts +16 -3
- package/dist/esm/hooks/useSecureMessages.js +38 -15
- package/dist/esm/hooks/useSecureMessages.js.map +1 -1
- package/dist/esm/hooks/useSecureSafetyNumber.d.ts +30 -0
- package/dist/esm/hooks/useSecureSafetyNumber.js +79 -0
- package/dist/esm/hooks/useSecureSafetyNumber.js.map +1 -0
- package/dist/esm/index.d.ts +12 -1
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/padding.d.ts +39 -0
- package/dist/esm/util/padding.js +75 -0
- package/dist/esm/util/padding.js.map +1 -0
- package/dist/esm/util/safety-number.d.ts +27 -0
- package/dist/esm/util/safety-number.js +81 -0
- package/dist/esm/util/safety-number.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The outcome of {@link estimatePassphraseStrength}: a coarse 0–4 score plus display copy. */
|
|
2
|
+
export interface PassphraseStrength {
|
|
3
|
+
/** 0 (weakest) … 4 (strongest) — for a 5-segment meter. */
|
|
4
|
+
score: 0 | 1 | 2 | 3 | 4;
|
|
5
|
+
/** A short human label for the score (e.g. "Weak", "Strong"). */
|
|
6
|
+
label: string;
|
|
7
|
+
/** A specific reason the passphrase is weak, when applicable (e.g. a common password). */
|
|
8
|
+
warning?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Estimate the strength of a backup passphrase for a strength meter.
|
|
12
|
+
*
|
|
13
|
+
* @param passphrase - The candidate passphrase (never logged or sent anywhere).
|
|
14
|
+
* @returns A {@link PassphraseStrength} with a 0–4 score, a label, and an optional warning.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const { score, label, warning } = estimatePassphraseStrength(input);
|
|
19
|
+
* // render a 5-segment meter from `score`, show `warning` if present.
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function estimatePassphraseStrength(passphrase: string): PassphraseStrength;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Passphrase-strength estimator for backup UX.
|
|
3
|
+
//
|
|
4
|
+
// Why this exists (CLAUDE.md #1 + spec §16.5): the blind server stores the passphrase-encrypted
|
|
5
|
+
// backup blob, so a weak passphrase is offline-brute-forceable on a DB exfil. The real argon2id KDF
|
|
6
|
+
// raises the cost per guess, but it can't rescue a guessable passphrase — so we nudge the user toward
|
|
7
|
+
// a strong one at entry time. This is a deliberately small, dependency-free heuristic (length +
|
|
8
|
+
// character-class diversity + a common-password penalty), NOT a substitute for zxcvbn-grade entropy
|
|
9
|
+
// estimation. It runs purely client-side and never logs or transmits the passphrase.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.estimatePassphraseStrength = estimatePassphraseStrength;
|
|
12
|
+
const LABELS = ["Very weak", "Weak", "Fair", "Strong", "Very strong"];
|
|
13
|
+
// A tiny set of the most-guessed passwords/substrings. Not exhaustive — a guardrail against the
|
|
14
|
+
// obvious, not a real dictionary check.
|
|
15
|
+
const COMMON = [
|
|
16
|
+
"password", "passw0rd", "12345", "123456", "qwerty", "letmein", "admin", "welcome",
|
|
17
|
+
"iloveyou", "abc123", "hunter2", "monkey", "dragon", "trustno1", "secret",
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Estimate the strength of a backup passphrase for a strength meter.
|
|
21
|
+
*
|
|
22
|
+
* @param passphrase - The candidate passphrase (never logged or sent anywhere).
|
|
23
|
+
* @returns A {@link PassphraseStrength} with a 0–4 score, a label, and an optional warning.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { score, label, warning } = estimatePassphraseStrength(input);
|
|
28
|
+
* // render a 5-segment meter from `score`, show `warning` if present.
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function estimatePassphraseStrength(passphrase) {
|
|
32
|
+
const pw = passphrase ?? "";
|
|
33
|
+
if (pw.length === 0)
|
|
34
|
+
return { score: 0, label: LABELS[0] };
|
|
35
|
+
const lower = pw.toLowerCase();
|
|
36
|
+
const hitsCommon = COMMON.some((c) => lower.includes(c));
|
|
37
|
+
// Character-class diversity.
|
|
38
|
+
let classes = 0;
|
|
39
|
+
if (/[a-z]/.test(pw))
|
|
40
|
+
classes++;
|
|
41
|
+
if (/[A-Z]/.test(pw))
|
|
42
|
+
classes++;
|
|
43
|
+
if (/[0-9]/.test(pw))
|
|
44
|
+
classes++;
|
|
45
|
+
if (/[^a-zA-Z0-9]/.test(pw))
|
|
46
|
+
classes++;
|
|
47
|
+
// Length is the dominant factor (passphrases >> complex-but-short passwords).
|
|
48
|
+
let score = 0;
|
|
49
|
+
if (pw.length >= 8)
|
|
50
|
+
score++;
|
|
51
|
+
if (pw.length >= 12)
|
|
52
|
+
score++;
|
|
53
|
+
if (pw.length >= 16)
|
|
54
|
+
score++;
|
|
55
|
+
// Diversity adds at most one step, and only once there's some length.
|
|
56
|
+
if (classes >= 3 && pw.length >= 8)
|
|
57
|
+
score++;
|
|
58
|
+
// A short, single-class passphrase never rates above "weak".
|
|
59
|
+
if (pw.length < 8 || classes <= 1)
|
|
60
|
+
score = Math.min(score, 1);
|
|
61
|
+
// A recognizably common password is capped hard regardless of shape.
|
|
62
|
+
if (hitsCommon)
|
|
63
|
+
score = Math.min(score, 1);
|
|
64
|
+
const clamped = Math.max(0, Math.min(4, score));
|
|
65
|
+
return {
|
|
66
|
+
score: clamped,
|
|
67
|
+
label: LABELS[clamped],
|
|
68
|
+
warning: hitsCommon
|
|
69
|
+
? "This looks like a common password — choose something less guessable."
|
|
70
|
+
: clamped <= 1
|
|
71
|
+
? "Use a longer passphrase (4+ random words) with mixed character types."
|
|
72
|
+
: undefined,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=passphrase-strength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passphrase-strength.js","sourceRoot":"","sources":["../../../src/backup/passphrase-strength.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,EAAE;AACF,gGAAgG;AAChG,oGAAoG;AACpG,sGAAsG;AACtG,gGAAgG;AAChG,oGAAoG;AACpG,qFAAqF;;AAiCrF,gEAsCC;AA3DD,MAAM,MAAM,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAU,CAAC;AAE/E,gGAAgG;AAChG,wCAAwC;AACxC,MAAM,MAAM,GAAG;IACb,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS;IAClF,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ;CAC1E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,SAAgB,0BAA0B,CAAC,UAAkB;IAC3D,MAAM,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3D,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzD,6BAA6B;IAC7B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB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AAC,SAAS;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { SecureChatRestClient } from "../transport/rest.js";
|
|
|
4
4
|
import { SecureChatSocketClient } from "../transport/socket.js";
|
|
5
5
|
import { SecureChatStore } from "../persistence/store.js";
|
|
6
6
|
import { SecureChatRepository } from "../persistence/repository.js";
|
|
7
|
+
import { PaddingPolicy } from "../util/padding.js";
|
|
7
8
|
/**
|
|
8
9
|
* The value exposed by {@link useSecureChat}: shared transport clients, the injected crypto, the
|
|
9
10
|
* persistence repository, the group-handle resolver, and the active project id.
|
|
@@ -31,6 +32,11 @@ export interface SecureChatContextValue {
|
|
|
31
32
|
* @returns An unsubscribe function.
|
|
32
33
|
*/
|
|
33
34
|
subscribeGroupChange: (listener: () => void) => () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Outbound message size-bucket padding policy. `useSecureMessages` pads plaintext to this before
|
|
37
|
+
* encryption so ciphertext size leaks less; defaults to `"ladder"`.
|
|
38
|
+
*/
|
|
39
|
+
padding: PaddingPolicy;
|
|
34
40
|
/** The Agora project id these clients are scoped to. */
|
|
35
41
|
projectId: string;
|
|
36
42
|
}
|
|
@@ -50,6 +56,11 @@ export interface SecureChatProviderProps {
|
|
|
50
56
|
baseUrl?: string;
|
|
51
57
|
/** Override the socket origin. Defaults to @agora-sdk/core `getSocketUrl()`. */
|
|
52
58
|
socketUrl?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Outbound message size-bucket padding policy (metadata hardening). `"ladder"` (default) pads each
|
|
61
|
+
* message up to a fixed size bucket so ciphertext length leaks less; `"none"` frames without padding.
|
|
62
|
+
*/
|
|
63
|
+
padding?: PaddingPolicy;
|
|
53
64
|
children: React.ReactNode;
|
|
54
65
|
}
|
|
55
66
|
/**
|
|
@@ -66,7 +77,7 @@ export interface SecureChatProviderProps {
|
|
|
66
77
|
* </SecureChatProvider>
|
|
67
78
|
* ```
|
|
68
79
|
*/
|
|
69
|
-
export declare function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessToken, baseUrl, socketUrl, children, }: SecureChatProviderProps): React.JSX.Element;
|
|
80
|
+
export declare function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessToken, baseUrl, socketUrl, padding, children, }: SecureChatProviderProps): React.JSX.Element;
|
|
70
81
|
/**
|
|
71
82
|
* Access the nearest {@link SecureChatContextValue}.
|
|
72
83
|
*
|
|
@@ -31,7 +31,7 @@ const SecureChatContext = (0, react_1.createContext)(null);
|
|
|
31
31
|
* </SecureChatProvider>
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessToken, baseUrl, socketUrl, children, }) {
|
|
34
|
+
function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessToken, baseUrl, socketUrl, padding = "ladder", children, }) {
|
|
35
35
|
const tokenRef = (0, react_1.useRef)(accessToken);
|
|
36
36
|
tokenRef.current = accessToken;
|
|
37
37
|
const resolveToken = (0, react_1.useMemo)(() => getAccessToken ?? (() => tokenRef.current), [getAccessToken]);
|
|
@@ -95,6 +95,7 @@ function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessTo
|
|
|
95
95
|
rememberGroup,
|
|
96
96
|
getGroupVersion,
|
|
97
97
|
subscribeGroupChange,
|
|
98
|
+
padding,
|
|
98
99
|
projectId,
|
|
99
100
|
}), [
|
|
100
101
|
rest,
|
|
@@ -105,6 +106,7 @@ function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessTo
|
|
|
105
106
|
rememberGroup,
|
|
106
107
|
getGroupVersion,
|
|
107
108
|
subscribeGroupChange,
|
|
109
|
+
padding,
|
|
108
110
|
projectId,
|
|
109
111
|
]);
|
|
110
112
|
return (0, jsx_runtime_1.jsx)(SecureChatContext.Provider, { value: value, children: children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-chat-context.js","sourceRoot":"","sources":["../../../src/context/secure-chat-context.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"secure-chat-context.js","sourceRoot":"","sources":["../../../src/context/secure-chat-context.tsx"],"names":[],"mappings":";;AA+FA,gDA2HC;AAQD,sCAMC;;AAxOD,yFAAyF;AACzF,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,+FAA+F;AAC/F,mGAAmG;AACnG,gEAAgE;AAEhE,iCAAkG;AAClG,0CAA8D;AAG9D,kDAA4D;AAC5D,sDAAgE;AAEhE,oEAA6D;AAC7D,gEAAoE;AAuCpE,MAAM,iBAAiB,GAAG,IAAA,qBAAa,EAAgC,IAAI,CAAC,CAAC;AA0B7E;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,SAAS,EACT,KAAK,EACL,WAAW,EACX,cAAc,EACd,OAAO,EACP,SAAS,EACT,OAAO,GAAG,QAAQ,EAClB,QAAQ,GACgB;IACxB,MAAM,QAAQ,GAAG,IAAA,cAAM,EAAqB,WAAW,CAAC,CAAC;IACzD,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC;IAE/B,MAAM,YAAY,GAAG,IAAA,eAAO,EAC1B,GAAG,EAAE,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAChD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,MAAM,IAAI,GAAG,IAAA,eAAO,EAClB,GAAG,EAAE,CACH,IAAI,8BAAoB,CAAC;QACvB,SAAS;QACT,cAAc,EAAE,YAAY;QAC5B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,IAAI,IAAA,oBAAa,GAAE;KAC7C,CAAC,EACJ,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,CACnC,CAAC;IAEF,MAAM,MAAM,GAAG,IAAA,eAAO,EACpB,GAAG,EAAE,CACH,IAAI,kCAAsB,CAAC;QACzB,SAAS;QACT,cAAc,EAAE,YAAY;QAC5B,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,I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B,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,MAAM;QACN,MAAM;QACN,IAAI;QACJ,YAAY;QACZ,aAAa;QACb,eAAe;QACf,oBAAoB;QACpB,OAAO;QACP,SAAS;KACV,CAAC,EACF;QACE,IAAI;QACJ,MAAM;QACN,MAAM;QACN,IAAI;QACJ,YAAY;QACZ,aAAa;QACb,eAAe;QACf,oBAAoB;QACpB,OAAO;QACP,SAAS;KACV,CACF,CAAC;IAEF,OAAO,uBAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA8B,CAAC;AAC3F,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa;IAC3B,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,iBAAiB,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type PassphraseStrength } from "../backup/passphrase-strength.js";
|
|
2
|
+
/** State + actions returned by {@link useSecureBackup}. */
|
|
3
|
+
export interface UseSecureBackupValues {
|
|
4
|
+
/**
|
|
5
|
+
* Seal all local key material under `passphrase` and upload it to the blind server.
|
|
6
|
+
* @throws {Error} If export or upload fails.
|
|
7
|
+
*/
|
|
8
|
+
backup: (passphrase: string) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Restore local key material on a fresh client from the server's backup, rehydrating the device and
|
|
11
|
+
* every conversation's group state.
|
|
12
|
+
* @throws {Error} If no backup exists, the passphrase is wrong, or the backup is corrupt.
|
|
13
|
+
*/
|
|
14
|
+
restore: (passphrase: string) => Promise<void>;
|
|
15
|
+
/** True while {@link UseSecureBackupValues.backup} is in flight. */
|
|
16
|
+
backingUp: boolean;
|
|
17
|
+
/** True while {@link UseSecureBackupValues.restore} is in flight. */
|
|
18
|
+
restoring: boolean;
|
|
19
|
+
/** The last error thrown by backup or restore, or `null`. */
|
|
20
|
+
error: unknown;
|
|
21
|
+
/** Server `updatedAt` of the most recent successful upload this session, or `null`. */
|
|
22
|
+
lastBackupAt: string | null;
|
|
23
|
+
/** True once a group has advanced since the last backup (membership/epoch change) — prompt a re-backup. */
|
|
24
|
+
needsBackup: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* True when there is NO local key material but a backup exists on the server — i.e. this client was
|
|
27
|
+
* evicted (Safari ITP / "clear browsing data") or is a fresh browser, and recovery is possible. The
|
|
28
|
+
* app should route to a passphrase prompt → {@link UseSecureBackupValues.restore} instead of
|
|
29
|
+
* registering a new device. Indistinguishable cases (evicted vs cleared vs new browser) all resolve
|
|
30
|
+
* the same way. Cleared after a successful restore.
|
|
31
|
+
*/
|
|
32
|
+
needsRestore: boolean;
|
|
33
|
+
/** True while the mount-time eviction check (or {@link UseSecureBackupValues.recheckRestore}) is in flight. */
|
|
34
|
+
checkingRestore: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Re-run the eviction check on demand (e.g. after catching a storage error mid-session, or after
|
|
37
|
+
* sign-in). Skips the server entirely when local key material is present.
|
|
38
|
+
* @returns The new {@link UseSecureBackupValues.needsRestore} value.
|
|
39
|
+
*/
|
|
40
|
+
recheckRestore: () => Promise<boolean>;
|
|
41
|
+
/** Coarse client-side passphrase-strength estimate for a meter (see {@link estimatePassphraseStrength}). */
|
|
42
|
+
estimateStrength: (passphrase: string) => PassphraseStrength;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Manage passphrase backup + restore of the client's secure-chat key material.
|
|
46
|
+
*
|
|
47
|
+
* Backups are explicit (call {@link UseSecureBackupValues.backup}); `needsBackup` flips true when a
|
|
48
|
+
* group advances so the app can prompt. On mount it also detects an evicted/fresh client
|
|
49
|
+
* (`needsRestore`) so the app restores rather than registering a fresh, history-less identity.
|
|
50
|
+
*
|
|
51
|
+
* @returns Backup/restore actions, the evicted-client `needsRestore` signal, in-flight + error state, a
|
|
52
|
+
* stale-backup signal, and a passphrase-strength helper.
|
|
53
|
+
* @throws {Error} When used outside a `<SecureChatProvider>`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const { needsRestore, restore, backup } = useSecureBackup();
|
|
58
|
+
* const { device, register } = useSecureDevice();
|
|
59
|
+
* // Route an evicted / fresh client to restore; a true first-run to register.
|
|
60
|
+
* if (needsRestore) await restore(passphrase); // prompt for the passphrase first
|
|
61
|
+
* else if (!device) await register();
|
|
62
|
+
* await backup(passphrase); // later, after a device/chat exists
|
|
63
|
+
* ```
|
|
64
|
+
* Restore should complete before the app relies on `useSecureDevice` (which read `device: null` on its
|
|
65
|
+
* own mount) — gate the chat subtree on a post-restore flag or remount it after restore.
|
|
66
|
+
*/
|
|
67
|
+
export declare function useSecureBackup(): UseSecureBackupValues;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// useSecureBackup — passphrase backup + restore of all local key material.
|
|
3
|
+
//
|
|
4
|
+
// Backup: crypto.exportBackup(passphrase) seals the device identity + every group's state under a
|
|
5
|
+
// real argon2id KDF + AEAD; we base64 the blob/nonce at the wire boundary and PUT it to the blind
|
|
6
|
+
// server, which stores the ciphertext verbatim (it never sees the passphrase or plaintext).
|
|
7
|
+
//
|
|
8
|
+
// Restore (fresh browser): GET the blob → crypto.importBackup re-derives the identity + groups in
|
|
9
|
+
// memory → re-assert the device server-side (idempotent) to recover its row → persist the device →
|
|
10
|
+
// rebind each conversation's group state by conversationId from the server's conversation list (the
|
|
11
|
+
// server is the source of truth for membership; the backup itself is conversationId-agnostic). The
|
|
12
|
+
// handshake cursor is intentionally left unset so useSecureHandshakes re-pulls from since=0 and
|
|
13
|
+
// dedupes — no cursor needs to live in the backup.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useSecureBackup = useSecureBackup;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const base64_js_1 = require("../util/base64.js");
|
|
18
|
+
const secure_chat_context_js_1 = require("../context/secure-chat-context.js");
|
|
19
|
+
const passphrase_strength_js_1 = require("../backup/passphrase-strength.js");
|
|
20
|
+
/**
|
|
21
|
+
* Manage passphrase backup + restore of the client's secure-chat key material.
|
|
22
|
+
*
|
|
23
|
+
* Backups are explicit (call {@link UseSecureBackupValues.backup}); `needsBackup` flips true when a
|
|
24
|
+
* group advances so the app can prompt. On mount it also detects an evicted/fresh client
|
|
25
|
+
* (`needsRestore`) so the app restores rather than registering a fresh, history-less identity.
|
|
26
|
+
*
|
|
27
|
+
* @returns Backup/restore actions, the evicted-client `needsRestore` signal, in-flight + error state, a
|
|
28
|
+
* stale-backup signal, and a passphrase-strength helper.
|
|
29
|
+
* @throws {Error} When used outside a `<SecureChatProvider>`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const { needsRestore, restore, backup } = useSecureBackup();
|
|
34
|
+
* const { device, register } = useSecureDevice();
|
|
35
|
+
* // Route an evicted / fresh client to restore; a true first-run to register.
|
|
36
|
+
* if (needsRestore) await restore(passphrase); // prompt for the passphrase first
|
|
37
|
+
* else if (!device) await register();
|
|
38
|
+
* await backup(passphrase); // later, after a device/chat exists
|
|
39
|
+
* ```
|
|
40
|
+
* Restore should complete before the app relies on `useSecureDevice` (which read `device: null` on its
|
|
41
|
+
* own mount) — gate the chat subtree on a post-restore flag or remount it after restore.
|
|
42
|
+
*/
|
|
43
|
+
function useSecureBackup() {
|
|
44
|
+
const { crypto, rest, repo, rememberGroup, subscribeGroupChange } = (0, secure_chat_context_js_1.useSecureChat)();
|
|
45
|
+
const [backingUp, setBackingUp] = (0, react_1.useState)(false);
|
|
46
|
+
const [restoring, setRestoring] = (0, react_1.useState)(false);
|
|
47
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
48
|
+
const [lastBackupAt, setLastBackupAt] = (0, react_1.useState)(null);
|
|
49
|
+
const [needsBackup, setNeedsBackup] = (0, react_1.useState)(false);
|
|
50
|
+
const [needsRestore, setNeedsRestore] = (0, react_1.useState)(false);
|
|
51
|
+
const [checkingRestore, setCheckingRestore] = (0, react_1.useState)(false);
|
|
52
|
+
// A group advancing (a join or a processed Commit) means the on-server backup is now stale.
|
|
53
|
+
// Guard the very first synchronous fire so mount doesn't immediately flag a backup as needed.
|
|
54
|
+
const armed = (0, react_1.useRef)(false);
|
|
55
|
+
(0, react_1.useEffect)(() => {
|
|
56
|
+
armed.current = true;
|
|
57
|
+
return subscribeGroupChange(() => {
|
|
58
|
+
if (armed.current)
|
|
59
|
+
setNeedsBackup(true);
|
|
60
|
+
});
|
|
61
|
+
}, [subscribeGroupChange]);
|
|
62
|
+
// Eviction / fresh-client detection: local key material gone but a server backup exists ⇒ restore is
|
|
63
|
+
// possible (and preferable to registering a new, history-less identity). Evicted, "cleared browsing
|
|
64
|
+
// data", and a brand-new browser are indistinguishable here and resolve the same way. We only hit the
|
|
65
|
+
// server when there's no local device, so the common (healthy) path stays a single IndexedDB read.
|
|
66
|
+
const recheckRestore = (0, react_1.useCallback)(async () => {
|
|
67
|
+
setCheckingRestore(true);
|
|
68
|
+
try {
|
|
69
|
+
const persisted = await repo.loadDevice();
|
|
70
|
+
if (persisted) {
|
|
71
|
+
setNeedsRestore(false);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const model = await rest.getKeyBackup();
|
|
75
|
+
const possible = model !== null;
|
|
76
|
+
setNeedsRestore(possible);
|
|
77
|
+
return possible;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
// Fail soft: a network blip must not strand the user as "needs restore". Surface the error only.
|
|
81
|
+
setError(err);
|
|
82
|
+
setNeedsRestore(false);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
setCheckingRestore(false);
|
|
87
|
+
}
|
|
88
|
+
}, [repo, rest]);
|
|
89
|
+
(0, react_1.useEffect)(() => {
|
|
90
|
+
let alive = true;
|
|
91
|
+
repo
|
|
92
|
+
.loadDevice()
|
|
93
|
+
.then(async (persisted) => {
|
|
94
|
+
if (!alive || persisted)
|
|
95
|
+
return; // have local state → not evicted; skip the server call
|
|
96
|
+
const model = await rest.getKeyBackup();
|
|
97
|
+
if (alive)
|
|
98
|
+
setNeedsRestore(model !== null);
|
|
99
|
+
})
|
|
100
|
+
.catch((err) => {
|
|
101
|
+
if (alive)
|
|
102
|
+
setError(err); // fail soft
|
|
103
|
+
});
|
|
104
|
+
return () => {
|
|
105
|
+
alive = false;
|
|
106
|
+
};
|
|
107
|
+
}, [repo, rest]);
|
|
108
|
+
const backup = (0, react_1.useCallback)(async (passphrase) => {
|
|
109
|
+
setBackingUp(true);
|
|
110
|
+
setError(null);
|
|
111
|
+
try {
|
|
112
|
+
const b = await crypto.exportBackup(passphrase);
|
|
113
|
+
const { updatedAt } = await rest.uploadKeyBackup({
|
|
114
|
+
// base64 at the wire boundary; KDF params (incl. the hex salt) are non-secret metadata.
|
|
115
|
+
blob: (0, base64_js_1.toBase64)(b.blob),
|
|
116
|
+
nonce: (0, base64_js_1.toBase64)(b.nonce),
|
|
117
|
+
kdf: b.kdf,
|
|
118
|
+
kdfParams: b.kdfParams,
|
|
119
|
+
cipher: b.cipher,
|
|
120
|
+
version: b.version,
|
|
121
|
+
});
|
|
122
|
+
setLastBackupAt(updatedAt);
|
|
123
|
+
setNeedsBackup(false);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
setError(err);
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
setBackingUp(false);
|
|
131
|
+
}
|
|
132
|
+
}, [crypto, rest]);
|
|
133
|
+
const restore = (0, react_1.useCallback)(async (passphrase) => {
|
|
134
|
+
setRestoring(true);
|
|
135
|
+
setError(null);
|
|
136
|
+
try {
|
|
137
|
+
const model = await rest.getKeyBackup();
|
|
138
|
+
if (!model)
|
|
139
|
+
throw new Error("No key backup found on the server to restore.");
|
|
140
|
+
// Decrypt + repopulate crypto memory (identity + groups). Returns the restored identity.
|
|
141
|
+
const id = await crypto.importBackup(passphrase, {
|
|
142
|
+
blob: (0, base64_js_1.fromBase64)(model.blob),
|
|
143
|
+
nonce: (0, base64_js_1.fromBase64)(model.nonce),
|
|
144
|
+
kdf: model.kdf,
|
|
145
|
+
kdfParams: model.kdfParams,
|
|
146
|
+
cipher: model.cipher,
|
|
147
|
+
version: model.version,
|
|
148
|
+
});
|
|
149
|
+
// Re-assert the (already-registered) device to recover its server row — idempotent on
|
|
150
|
+
// (userId, deviceId). The row's id is the senderDeviceId messages need.
|
|
151
|
+
const device = await rest.registerDevice({
|
|
152
|
+
deviceId: id.deviceId,
|
|
153
|
+
signaturePublicKey: (0, base64_js_1.toBase64)(id.signaturePublicKey),
|
|
154
|
+
credential: (0, base64_js_1.toBase64)(id.credential),
|
|
155
|
+
ciphersuite: id.ciphersuite,
|
|
156
|
+
});
|
|
157
|
+
await repo.saveDevice({
|
|
158
|
+
deviceId: id.deviceId,
|
|
159
|
+
deviceState: await crypto.exportDeviceState(),
|
|
160
|
+
device,
|
|
161
|
+
});
|
|
162
|
+
// Rebind conversationId → restored group state from the server's conversation list.
|
|
163
|
+
let cursor;
|
|
164
|
+
for (;;) {
|
|
165
|
+
const page = await rest.listConversations(cursor ? { cursor } : undefined);
|
|
166
|
+
for (const c of page.conversations) {
|
|
167
|
+
try {
|
|
168
|
+
await rememberGroup(c.id, {
|
|
169
|
+
mlsGroupId: (0, base64_js_1.fromBase64)(c.mlsGroupId),
|
|
170
|
+
epoch: BigInt(c.currentEpoch),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// The group isn't in this backup (created after it, or we're not a member) — skip it.
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!page.hasMore || page.conversations.length === 0)
|
|
178
|
+
break;
|
|
179
|
+
const last = page.conversations[page.conversations.length - 1];
|
|
180
|
+
cursor = last.lastMessageAt ?? last.createdAt;
|
|
181
|
+
}
|
|
182
|
+
setNeedsBackup(false);
|
|
183
|
+
setNeedsRestore(false); // we now hold local key material again
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
setError(err);
|
|
187
|
+
throw err;
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
setRestoring(false);
|
|
191
|
+
}
|
|
192
|
+
}, [crypto, rest, repo, rememberGroup]);
|
|
193
|
+
return {
|
|
194
|
+
backup,
|
|
195
|
+
restore,
|
|
196
|
+
backingUp,
|
|
197
|
+
restoring,
|
|
198
|
+
error,
|
|
199
|
+
lastBackupAt,
|
|
200
|
+
needsBackup,
|
|
201
|
+
needsRestore,
|
|
202
|
+
checkingRestore,
|
|
203
|
+
recheckRestore,
|
|
204
|
+
estimateStrength: passphrase_strength_js_1.estimatePassphraseStrength,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=useSecureBackup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSecureBackup.js","sourceRoot":"","sources":["../../../src/hooks/useSecureBackup.tsx"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,EAAE;AACF,kGAAkG;AAClG,kGAAkG;AAClG,4FAA4F;AAC5F,EAAE;AACF,kGAAkG;AAClG,mGAAmG;AACnG,oGAAoG;AACpG,mGAAmG;AACnG,gGAAgG;AAChG,mDAAmD;;AA4EnD,0CAuKC;AAjPD,iCAAiE;AACjE,iDAAyD;AACzD,8EAAkE;AAClE,6EAG0C;AA6C1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,eAAe;IAC7B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,GAAG,IAAA,sCAAa,GAAE,CAAC;IAEpF,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAA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D,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;oBAAE,MAAM;gBAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;gBAChE,MAAM,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,SAAS,CAAC;YAChD,CAAC;YAED,cAAc,CAAC,KAAK,CAAC,CAAC;YACtB,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,uCAAuC;QACjE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EACD,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,CACpC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO;QACP,SAAS;QACT,SAAS;QACT,KAAK;QACL,YAAY;QACZ,WAAW;QACX,YAAY;QACZ,eAAe;QACf,cAAc;QACd,gBAAgB,EAAE,mDAA0B;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -8,7 +8,20 @@ export interface UseSecureDeviceOptions {
|
|
|
8
8
|
ciphersuite?: number;
|
|
9
9
|
/** How many KeyPackages to publish on registration and replenish toward. Default 20. */
|
|
10
10
|
keyPackageTarget?: number;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Low-water mark: when the server's available count drops **below** this, a top-up refills to
|
|
13
|
+
* {@link UseSecureDeviceOptions.keyPackageTarget}. KeyPackages are single-use, so this guards
|
|
14
|
+
* against exhaustion (peers unable to add this device). Default `ceil(keyPackageTarget / 2)` (10 for
|
|
15
|
+
* the default target of 20). Only governs the proactive/manual path — the server's
|
|
16
|
+
* `secure:key-packages-low` signal always tops up, since the server already judged the stock low.
|
|
17
|
+
*/
|
|
18
|
+
keyPackageLowWater?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Auto-replenish without app involvement. Default true. When true the hook subscribes to
|
|
21
|
+
* `secure:key-packages-low` and runs a one-shot proactive count check once the device is ready. When
|
|
22
|
+
* false, both automatic paths are disabled but {@link UseSecureDeviceValues.checkAndReplenish}
|
|
23
|
+
* still works on demand.
|
|
24
|
+
*/
|
|
12
25
|
autoReplenish?: boolean;
|
|
13
26
|
}
|
|
14
27
|
/** The state and actions returned by {@link useSecureDevice}. */
|
|
@@ -29,6 +42,13 @@ export interface UseSecureDeviceValues {
|
|
|
29
42
|
publishKeyPackages: (count?: number) => Promise<number>;
|
|
30
43
|
/** Re-query the server for the available KeyPackage count and update `keyPackagesAvailable`. */
|
|
31
44
|
refreshKeyPackageCount: () => Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Refresh the server count and, if it's below the low-water mark, top up to `keyPackageTarget`
|
|
47
|
+
* (publishing only the deficit). Safe to call before {@link UseSecureDeviceValues.register} — it
|
|
48
|
+
* no-ops to 0 when there's no device and never throws for that case — so an app can wire it to a
|
|
49
|
+
* window-focus / app-foreground handler.
|
|
50
|
+
*/
|
|
51
|
+
checkAndReplenish: () => Promise<number>;
|
|
32
52
|
}
|
|
33
53
|
/**
|
|
34
54
|
* Register this client as an MLS device, persist its identity, and keep KeyPackages stocked.
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
//
|
|
5
5
|
// On mount it re-hydrates a persisted device (stable deviceId + private state via
|
|
6
6
|
// crypto.importDeviceState) so a reload does NOT mint a new identity. register() generates, registers
|
|
7
|
-
// on the server, and persists.
|
|
7
|
+
// on the server, and persists.
|
|
8
|
+
//
|
|
9
|
+
// KeyPackages are single-use (the server consumes one per group-add), so running dry means peers can't
|
|
10
|
+
// add this device. The hook keeps the stock topped up to `keyPackageTarget` from three triggers: the
|
|
11
|
+
// server's `secure:key-packages-low` realtime signal, a one-shot proactive count check once the device
|
|
12
|
+
// is ready (self-heals a client that missed the signal while offline), and an app-callable
|
|
13
|
+
// `checkAndReplenish()` (e.g. on window focus). Each top-up publishes only the DEFICIT to the target
|
|
14
|
+
// (using the actual available count), not a blind full batch.
|
|
8
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
16
|
exports.useSecureDevice = useSecureDevice;
|
|
10
17
|
const react_1 = require("react");
|
|
@@ -40,6 +47,7 @@ function newDeviceId() {
|
|
|
40
47
|
function useSecureDevice(options = {}) {
|
|
41
48
|
const { crypto, rest, socket, repo } = (0, secure_chat_context_js_1.useSecureChat)();
|
|
42
49
|
const { ciphersuite, keyPackageTarget = 20, autoReplenish = true } = options;
|
|
50
|
+
const keyPackageLowWater = options.keyPackageLowWater ?? Math.ceil(keyPackageTarget / 2);
|
|
43
51
|
const [device, setDevice] = (0, react_1.useState)(null);
|
|
44
52
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
45
53
|
const [registering, setRegistering] = (0, react_1.useState)(false);
|
|
@@ -47,6 +55,8 @@ function useSecureDevice(options = {}) {
|
|
|
47
55
|
const [keyPackagesAvailable, setKeyPackagesAvailable] = (0, react_1.useState)(null);
|
|
48
56
|
const deviceIdRef = (0, react_1.useRef)(options.deviceId ?? newDeviceId());
|
|
49
57
|
const registerStartedRef = (0, react_1.useRef)(false);
|
|
58
|
+
// Guards the one-shot proactive count check so it runs once per device-ready, not on every render.
|
|
59
|
+
const proactiveCheckedRef = (0, react_1.useRef)(false);
|
|
50
60
|
// On mount: re-hydrate a persisted device (stable id + private state). No persisted device ⇒
|
|
51
61
|
// first-run; the app calls register().
|
|
52
62
|
(0, react_1.useEffect)(() => {
|
|
@@ -99,6 +109,25 @@ function useSecureDevice(options = {}) {
|
|
|
99
109
|
setKeyPackagesAvailable(available);
|
|
100
110
|
return available;
|
|
101
111
|
}, [rest, device]);
|
|
112
|
+
// Publish only the shortfall (target − available) to refill to the target; nothing if already
|
|
113
|
+
// at/above it. Optimistically bumps the local count so the UI reflects the refill without a re-query.
|
|
114
|
+
// Callers guarantee `device` exists (publishKeyPackages throws otherwise).
|
|
115
|
+
const replenishToTarget = (0, react_1.useCallback)(async (available) => {
|
|
116
|
+
const deficit = keyPackageTarget - available;
|
|
117
|
+
if (deficit <= 0)
|
|
118
|
+
return 0;
|
|
119
|
+
const published = await publishKeyPackages(deficit);
|
|
120
|
+
setKeyPackagesAvailable(available + published);
|
|
121
|
+
return published;
|
|
122
|
+
}, [keyPackageTarget, publishKeyPackages]);
|
|
123
|
+
const checkAndReplenish = (0, react_1.useCallback)(async () => {
|
|
124
|
+
if (!device)
|
|
125
|
+
return 0; // not registered yet — no-op (app may call this eagerly on focus)
|
|
126
|
+
const available = await refreshKeyPackageCount();
|
|
127
|
+
if (available >= keyPackageLowWater)
|
|
128
|
+
return 0;
|
|
129
|
+
return replenishToTarget(available);
|
|
130
|
+
}, [device, refreshKeyPackageCount, keyPackageLowWater, replenishToTarget]);
|
|
102
131
|
const register = (0, react_1.useCallback)(async () => {
|
|
103
132
|
registerStartedRef.current = true;
|
|
104
133
|
setRegistering(true);
|
|
@@ -128,17 +157,28 @@ function useSecureDevice(options = {}) {
|
|
|
128
157
|
setRegistering(false);
|
|
129
158
|
}
|
|
130
159
|
}, [crypto, rest, repo, ciphersuite]);
|
|
131
|
-
// Auto-replenish on the server's low-water signal for this device.
|
|
160
|
+
// Auto-replenish on the server's low-water signal for this device. We top up to the target using the
|
|
161
|
+
// count the signal reports (not a blind full batch), and trust the server's "low" verdict — the
|
|
162
|
+
// client `keyPackageLowWater` only gates the proactive path below.
|
|
132
163
|
(0, react_1.useEffect)(() => {
|
|
133
164
|
if (!autoReplenish || !device)
|
|
134
165
|
return;
|
|
135
166
|
const off = socket.on("secure:key-packages-low", (signal) => {
|
|
136
167
|
if (signal.deviceId !== device.id)
|
|
137
|
-
return;
|
|
138
|
-
|
|
168
|
+
return; // device.id is the server ROW id, not the deviceId
|
|
169
|
+
setKeyPackagesAvailable(signal.available);
|
|
170
|
+
replenishToTarget(signal.available).catch(setError);
|
|
139
171
|
});
|
|
140
172
|
return off;
|
|
141
|
-
}, [autoReplenish, device, socket,
|
|
173
|
+
}, [autoReplenish, device, socket, replenishToTarget]);
|
|
174
|
+
// One-shot proactive top-up once the device is ready (covers both register and rehydrate-on-mount),
|
|
175
|
+
// so a client that missed the realtime signal while offline self-heals on next load.
|
|
176
|
+
(0, react_1.useEffect)(() => {
|
|
177
|
+
if (!autoReplenish || !device || proactiveCheckedRef.current)
|
|
178
|
+
return;
|
|
179
|
+
proactiveCheckedRef.current = true;
|
|
180
|
+
checkAndReplenish().catch(setError);
|
|
181
|
+
}, [autoReplenish, device, checkAndReplenish]);
|
|
142
182
|
return {
|
|
143
183
|
device,
|
|
144
184
|
loading,
|
|
@@ -148,6 +188,7 @@ function useSecureDevice(options = {}) {
|
|
|
148
188
|
register,
|
|
149
189
|
publishKeyPackages,
|
|
150
190
|
refreshKeyPackageCount,
|
|
191
|
+
checkAndReplenish,
|
|
151
192
|
};
|
|
152
193
|
}
|
|
153
194
|
//# sourceMappingURL=useSecureDevice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSecureDevice.js","sourceRoot":"","sources":["../../../src/hooks/useSecureDevice.tsx"],"names":[],"mappings":";AAAA,qGAAqG;AACrG,yBAAyB;AACzB,EAAE;AACF,kFAAkF;AAClF,sGAAsG;AACtG,
|
|
1
|
+
{"version":3,"file":"useSecureDevice.js","sourceRoot":"","sources":["../../../src/hooks/useSecureDevice.tsx"],"names":[],"mappings":";AAAA,qGAAqG;AACrG,yBAAyB;AACzB,EAAE;AACF,kFAAkF;AAClF,sGAAsG;AACtG,+BAA+B;AAC/B,EAAE;AACF,uGAAuG;AACvG,qGAAqG;AACrG,uGAAuG;AACvG,2FAA2F;AAC3F,qGAAqG;AACrG,8DAA8D;;AAuF9D,0CAwJC;AA7OD,iCAAiE;AAEjE,iDAA6C;AAC7C,8EAAkE;AAElE;;;;;GAKG;AACH,SAAS,WAA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