Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Phone secrets: ready only after the key imports; keep index.ts within its size limit

AdityaUmale72ae1671504b
diff --git a/server/index.ts b/server/index.ts
index f242138820..52bb134f4b 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -12785,9 +12785,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
expiresAt: opened.expiresAt,
url: base ? `${base}/pair#code=${code}` : null,
inviteUrl: invite,
- serverName, ...(phoneRelay ? { relay: phoneRelay.status() } : {}),
- // False until a desktop app hands this server its phone key; a self-hosted server never gets one.
- phoneSecrets: phoneSecrets.ready,
+ serverName, ...(phoneRelay ? { relay: phoneRelay.status() } : {}), phoneSecrets: phoneSecrets.ready,
hint: base
? null
: "this server has no public address to put in a link: set OMB_PUBLIC_URL, or open /pair on the address you use and type the code",
diff --git a/server/phone-secret.test.ts b/server/phone-secret.test.ts
index e5c4ca3632..aad45b5920 100644
--- a/server/phone-secret.test.ts
+++ b/server/phone-secret.test.ts
@@ -186,8 +186,14 @@ describe("PhoneSecretBridge", () => {
const desktop = new PhoneSecretBridge(() => true, 50);
await expect(desktop.provide(context)).rejects.toMatchObject({ message: expect.stringContaining("Reopen OpenMausBot") });
- desktop.receive((await keyMaterial()).message);
- expect(desktop.ready).toBe(true);
+ const material = await keyMaterial();
+ desktop.receive(material.message);
+ await vi.waitFor(() => expect(desktop.ready).toBe(true));
+
+ desktop.receive({ ...material.message, version: 2 });
+ expect(desktop.ready).toBe(false);
+ await expect(desktop.provide(context)).rejects.toMatchObject({ status: 503 });
+ expect(desktop.ready).toBe(false);
});
it("rejects a private scalar that does not match the advertised public point", async () => {
diff --git a/server/phone-secret.ts b/server/phone-secret.ts
index 2b3bbe2dbc..3db407af5b 100644
--- a/server/phone-secret.ts
+++ b/server/phone-secret.ts
@@ -314,6 +314,7 @@ function decodeSaveResult(raw: unknown): { requestId: string; ok: boolean; error
/** The HTTP route hands this ciphertext only; plaintext exists only after HPKE opens it on the desktop and never reaches HTTP, chat, SQLite, SSE or logs. */
export class PhoneSecretBridge {
private identity: Promise<PhoneSecretIdentity> | null = null;
+ private imported = false;
private readonly pending = new Map<string, PendingSave>();
private active = 0;
private readonly send: SendPrivateMessage;
@@ -337,7 +338,7 @@ export class PhoneSecretBridge {
/** Whether a phone can seal a secret for this computer: only after the desktop app has handed over its key. */
get ready(): boolean {
- return this.identity !== null;
+ return this.imported;
}
receive(raw: unknown): boolean {
@@ -345,8 +346,11 @@ export class PhoneSecretBridge {
if (!message || typeof message !== "object" || Array.isArray(message)) return false;
const record = message as Record<string, unknown>;
if (record.type === "openmausbot:phone-secret-key") {
- this.identity = importIdentity(record);
- void this.identity.catch(() => {});
+ const identity = importIdentity(record);
+ this.identity = identity;
+ this.imported = false;
+ // Ready only once this key imports; a failed or superseded import never counts.
+ identity.then(() => { if (this.identity === identity) this.imported = true; }, () => {});
return true;
}
const result = decodeSaveResult(record);