@mosadd/mcp 3.0.0-alpha.32 → 3.0.0-alpha.33
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 +74 -0
- package/README.md +11 -11
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-KX34DDJB.js → chunk-IWLN5EO5.js} +614 -134
- package/dist/index.js +1 -1
- package/package.json +15 -15
- package/src/__tests__/golden-path.test.ts +137 -137
- package/src/__tests__/integration.test.ts +179 -179
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +141 -0
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +121 -1
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +502 -502
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -116
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +122 -122
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +148 -148
- package/src/tools/actions.ts +162 -162
- package/src/tools/attachments.ts +268 -268
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -108
- package/src/tools/index.ts +173 -104
- package/src/tools/knowledge-graph.ts +178 -0
- package/src/tools/knowledge.ts +319 -191
- package/src/tools/mail-agentbox.ts +147 -0
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +135 -135
- package/src/tools/mail.ts +381 -381
- package/src/tools/mdm.ts +476 -479
- package/src/tools/mirc-edge.ts +190 -190
- package/src/tools/mirc-members.ts +2 -2
- package/src/tools/mirc-messages.ts +155 -155
- package/src/tools/mirc.ts +2 -2
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +121 -121
- package/src/tools/murl.ts +4 -2
- package/src/tools/presence.ts +208 -0
- package/src/types.ts +94 -94
- package/src/voice/floor.ts +132 -132
- package/LICENSE +0 -201
- package/dist/bin/login.d.ts +0 -13
- package/dist/bin/mcp.d.ts +0 -1
- package/dist/index.d.ts +0 -266
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mDM E2EE golden path (LINEAR-2357) — the "done" bar.
|
|
3
|
-
*
|
|
4
|
-
* Two parties (alice, bob) sharing ONE backend that acts as both the message
|
|
5
|
-
* store AND the key directory (decision "1a": prekey bundles ride the same
|
|
6
|
-
* DmProvider as messages). Proves:
|
|
7
|
-
* 1. both publish prekey bundles via the provider,
|
|
8
|
-
* 2. alice mDM_send → X3DH handshake + ratchet → bob mDM_list decrypts it,
|
|
9
|
-
* 3. the bytes on the wire are CIPHERTEXT, not plaintext (no test-theater),
|
|
10
|
-
* 4. bob replies on the established session → alice mDM_list decrypts it.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { describe, expect, it } from "vitest";
|
|
14
|
-
import type {
|
|
15
|
-
DmProvider,
|
|
16
|
-
DmSendArgs,
|
|
17
|
-
DmListArgs,
|
|
18
|
-
DmSendResult,
|
|
19
|
-
DmListResult,
|
|
20
|
-
} from "@mosadd/providers";
|
|
21
|
-
import { mdmTools } from "../tools/mdm.js";
|
|
22
|
-
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
23
|
-
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
24
|
-
import { createMosaddServer } from "../server.js";
|
|
25
|
-
import type { MosaddToolContext } from "../types.js";
|
|
26
|
-
|
|
27
|
-
/** Shared store: message log + key directory, both keyed in one place. */
|
|
28
|
-
class SharedBackend {
|
|
29
|
-
readonly messages: Array<{ id: string; senderId: string; payload: Uint8Array; threadId: string }> = [];
|
|
30
|
-
readonly bundles = new Map<string, Uint8Array>();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** One participant's view onto the shared backend. */
|
|
34
|
-
class ClientProvider implements DmProvider {
|
|
35
|
-
constructor(
|
|
36
|
-
private readonly backend: SharedBackend,
|
|
37
|
-
private readonly myId: string,
|
|
38
|
-
) {}
|
|
39
|
-
async selfId(): Promise<string> {
|
|
40
|
-
return this.myId;
|
|
41
|
-
}
|
|
42
|
-
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
43
|
-
const id = `m${this.backend.messages.length + 1}`;
|
|
44
|
-
this.backend.messages.push({ id, senderId: this.myId, payload: args.payload, threadId: args.threadId });
|
|
45
|
-
return { id, deliveredAt: new Date(0).toISOString() };
|
|
46
|
-
}
|
|
47
|
-
async list(args: DmListArgs): Promise<DmListResult> {
|
|
48
|
-
return {
|
|
49
|
-
messages: this.backend.messages
|
|
50
|
-
.filter((m) => m.threadId === args.threadId)
|
|
51
|
-
.map((m) => ({
|
|
52
|
-
id: m.id,
|
|
53
|
-
senderId: m.senderId,
|
|
54
|
-
payload: m.payload,
|
|
55
|
-
timestamp: new Date(0).toISOString(),
|
|
56
|
-
threadId: m.threadId,
|
|
57
|
-
})),
|
|
58
|
-
nextCursor: null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
62
|
-
this.backend.bundles.set(this.myId, bundle);
|
|
63
|
-
}
|
|
64
|
-
async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
|
|
65
|
-
return this.backend.bundles.get(peerId) ?? null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const tool = (name: string) => {
|
|
70
|
-
const t = mdmTools.find((x) => x.name === name);
|
|
71
|
-
if (!t) throw new Error(`tool ${name} not found`);
|
|
72
|
-
return t.handler;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
function ctxFor(backend: SharedBackend, id: string): MosaddToolContext {
|
|
76
|
-
return {
|
|
77
|
-
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
78
|
-
providers: {
|
|
79
|
-
dm: new ClientProvider(backend, id),
|
|
80
|
-
keys: new InMemoryMdmKeyStore(),
|
|
81
|
-
voice: new InMemoryVoiceProvider(id),
|
|
82
|
-
},
|
|
83
|
-
log: () => {},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", () => {
|
|
88
|
-
it("delivers an encrypted message alice→bob and a reply bob→alice", async () => {
|
|
89
|
-
const backend = new SharedBackend();
|
|
90
|
-
const alice = ctxFor(backend, "alice");
|
|
91
|
-
const bob = ctxFor(backend, "bob");
|
|
92
|
-
|
|
93
|
-
// 1. Both publish their prekey bundles (so first contact is possible).
|
|
94
|
-
await tool("mDM_publish_keys")({}, alice);
|
|
95
|
-
const bobPub = (await tool("mDM_publish_keys")({}, bob)) as { one_time_prekeys: number };
|
|
96
|
-
expect(bobPub.one_time_prekeys).toBeGreaterThan(0);
|
|
97
|
-
|
|
98
|
-
// 2. Alice sends an encrypted DM to Bob (first contact → X3DH handshake).
|
|
99
|
-
const sent = (await tool("mDM_send")({ to: "bob", text: "first contact" }, alice)) as {
|
|
100
|
-
encrypted: boolean;
|
|
101
|
-
};
|
|
102
|
-
expect(sent.encrypted).toBe(true);
|
|
103
|
-
|
|
104
|
-
// 3. The wire bytes must be CIPHERTEXT — the plaintext must NOT appear.
|
|
105
|
-
const wire = backend.messages[0]!.payload;
|
|
106
|
-
const wireStr = Buffer.from(wire).toString("utf8");
|
|
107
|
-
expect(wireStr).not.toContain("first contact");
|
|
108
|
-
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS — LINEAR-3409)
|
|
109
|
-
|
|
110
|
-
// 4. Bob lists the thread and decrypts Alice's message.
|
|
111
|
-
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
112
|
-
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
113
|
-
};
|
|
114
|
-
const fromAlice = bobView.messages.find((m) => m.sender_identity_id === "alice");
|
|
115
|
-
expect(fromAlice?.text).toBe("first contact");
|
|
116
|
-
expect(fromAlice?.encrypted).toBe(true);
|
|
117
|
-
|
|
118
|
-
// 5. Bob replies on the now-established session (no new handshake).
|
|
119
|
-
await tool("mDM_send")({ to: "alice", text: "copy that" }, bob);
|
|
120
|
-
|
|
121
|
-
// 6. Alice decrypts Bob's reply AND reads back her OWN sent message
|
|
122
|
-
// (sent-items cache — the ratchet can't re-derive own plaintext on read).
|
|
123
|
-
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
124
|
-
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
125
|
-
};
|
|
126
|
-
const fromBob = aliceView.messages.find((m) => m.sender_identity_id === "bob");
|
|
127
|
-
expect(fromBob?.text).toBe("copy that");
|
|
128
|
-
const ownByAlice = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
129
|
-
expect(ownByAlice?.text).toBe("first contact"); // not "<encrypted · sent by you>"
|
|
130
|
-
expect(ownByAlice?.encrypted).toBe(true);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("falls back to a marker for own messages when no sent-items cache exists", async () => {
|
|
134
|
-
// A keystore WITHOUT the optional sent-items cache must not crash; the
|
|
135
|
-
// sender simply sees the marker for their own outgoing messages.
|
|
136
|
-
const backend = new SharedBackend();
|
|
137
|
-
const alice = ctxFor(backend, "alice");
|
|
138
|
-
const bob = ctxFor(backend, "bob");
|
|
139
|
-
// Strip the optional cache methods from alice's keystore.
|
|
140
|
-
(alice.providers.keys as { putSentMessage?: unknown }).putSentMessage = undefined;
|
|
141
|
-
(alice.providers.keys as { getSentMessage?: unknown }).getSentMessage = undefined;
|
|
142
|
-
|
|
143
|
-
await tool("mDM_publish_keys")({}, bob);
|
|
144
|
-
await tool("mDM_send")({ to: "bob", text: "no cache here" }, alice);
|
|
145
|
-
|
|
146
|
-
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
147
|
-
messages: Array<{ text: string; sender_identity_id: string }>;
|
|
148
|
-
};
|
|
149
|
-
const own = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
150
|
-
expect(own?.text).toBe("<encrypted · sent by you>");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("mDM_send fails with an actionable error when the peer has no published keys", async () => {
|
|
154
|
-
const backend = new SharedBackend();
|
|
155
|
-
const alice = ctxFor(backend, "alice");
|
|
156
|
-
// Bob never published — no bundle to fetch.
|
|
157
|
-
await expect(tool("mDM_send")({ to: "bob", text: "hi" }, alice)).rejects.toThrow(
|
|
158
|
-
/has not published a prekey bundle/i,
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("rejects a tampered (MITM) prekey bundle instead of starting a session", async () => {
|
|
163
|
-
const backend = new SharedBackend();
|
|
164
|
-
const alice = ctxFor(backend, "alice");
|
|
165
|
-
const bob = ctxFor(backend, "bob");
|
|
166
|
-
|
|
167
|
-
await tool("mDM_publish_keys")({}, bob);
|
|
168
|
-
|
|
169
|
-
// MITM swaps Bob's DH identity key (a SIGNED field) in the directory entry,
|
|
170
|
-
// keeping it valid base64 so it parses — only the signature should catch it.
|
|
171
|
-
const obj = JSON.parse(Buffer.from(backend.bundles.get("bob")!).toString("utf8"));
|
|
172
|
-
obj.ik = (obj.ik[0] === "A" ? "B" : "A") + obj.ik.slice(1);
|
|
173
|
-
backend.bundles.set("bob", new Uint8Array(Buffer.from(JSON.stringify(obj), "utf8")));
|
|
174
|
-
|
|
175
|
-
await expect(tool("mDM_send")({ to: "bob", text: "intercept me" }, alice)).rejects.toThrow(
|
|
176
|
-
/signature verification|man-in-the-middle/i,
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe("auto-publish prekeys on startup (LINEAR-3104 cold-start fix)", () => {
|
|
182
|
-
it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
|
|
183
|
-
const backend = new SharedBackend();
|
|
184
|
-
createMosaddServer({
|
|
185
|
-
mode: "local",
|
|
186
|
-
autoPublishKeys: true,
|
|
187
|
-
providers: {
|
|
188
|
-
dm: new ClientProvider(backend, "self-agent"),
|
|
189
|
-
keys: new InMemoryMdmKeyStore(),
|
|
190
|
-
voice: new InMemoryVoiceProvider("self-agent"),
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
// fire-and-forget; getOwnMaterial() does async key generation, so flush.
|
|
194
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
195
|
-
expect(backend.bundles.has("self-agent")).toBe(true);
|
|
196
|
-
expect(backend.bundles.get("self-agent")!.byteLength).toBeGreaterThan(0);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("does NOT publish when autoPublishKeys is unset (hosted/default)", async () => {
|
|
200
|
-
const backend = new SharedBackend();
|
|
201
|
-
createMosaddServer({
|
|
202
|
-
mode: "local",
|
|
203
|
-
providers: {
|
|
204
|
-
dm: new ClientProvider(backend, "quiet-agent"),
|
|
205
|
-
keys: new InMemoryMdmKeyStore(),
|
|
206
|
-
voice: new InMemoryVoiceProvider("quiet-agent"),
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
210
|
-
expect(backend.bundles.has("quiet-agent")).toBe(false);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* mDM E2EE golden path (LINEAR-2357) — the "done" bar.
|
|
3
|
+
*
|
|
4
|
+
* Two parties (alice, bob) sharing ONE backend that acts as both the message
|
|
5
|
+
* store AND the key directory (decision "1a": prekey bundles ride the same
|
|
6
|
+
* DmProvider as messages). Proves:
|
|
7
|
+
* 1. both publish prekey bundles via the provider,
|
|
8
|
+
* 2. alice mDM_send → X3DH handshake + ratchet → bob mDM_list decrypts it,
|
|
9
|
+
* 3. the bytes on the wire are CIPHERTEXT, not plaintext (no test-theater),
|
|
10
|
+
* 4. bob replies on the established session → alice mDM_list decrypts it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, it } from "vitest";
|
|
14
|
+
import type {
|
|
15
|
+
DmProvider,
|
|
16
|
+
DmSendArgs,
|
|
17
|
+
DmListArgs,
|
|
18
|
+
DmSendResult,
|
|
19
|
+
DmListResult,
|
|
20
|
+
} from "@mosadd/providers";
|
|
21
|
+
import { mdmTools } from "../tools/mdm.js";
|
|
22
|
+
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
23
|
+
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
24
|
+
import { createMosaddServer } from "../server.js";
|
|
25
|
+
import type { MosaddToolContext } from "../types.js";
|
|
26
|
+
|
|
27
|
+
/** Shared store: message log + key directory, both keyed in one place. */
|
|
28
|
+
class SharedBackend {
|
|
29
|
+
readonly messages: Array<{ id: string; senderId: string; payload: Uint8Array; threadId: string }> = [];
|
|
30
|
+
readonly bundles = new Map<string, Uint8Array>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One participant's view onto the shared backend. */
|
|
34
|
+
class ClientProvider implements DmProvider {
|
|
35
|
+
constructor(
|
|
36
|
+
private readonly backend: SharedBackend,
|
|
37
|
+
private readonly myId: string,
|
|
38
|
+
) {}
|
|
39
|
+
async selfId(): Promise<string> {
|
|
40
|
+
return this.myId;
|
|
41
|
+
}
|
|
42
|
+
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
43
|
+
const id = `m${this.backend.messages.length + 1}`;
|
|
44
|
+
this.backend.messages.push({ id, senderId: this.myId, payload: args.payload, threadId: args.threadId });
|
|
45
|
+
return { id, deliveredAt: new Date(0).toISOString() };
|
|
46
|
+
}
|
|
47
|
+
async list(args: DmListArgs): Promise<DmListResult> {
|
|
48
|
+
return {
|
|
49
|
+
messages: this.backend.messages
|
|
50
|
+
.filter((m) => m.threadId === args.threadId)
|
|
51
|
+
.map((m) => ({
|
|
52
|
+
id: m.id,
|
|
53
|
+
senderId: m.senderId,
|
|
54
|
+
payload: m.payload,
|
|
55
|
+
timestamp: new Date(0).toISOString(),
|
|
56
|
+
threadId: m.threadId,
|
|
57
|
+
})),
|
|
58
|
+
nextCursor: null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
62
|
+
this.backend.bundles.set(this.myId, bundle);
|
|
63
|
+
}
|
|
64
|
+
async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
|
|
65
|
+
return this.backend.bundles.get(peerId) ?? null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const tool = (name: string) => {
|
|
70
|
+
const t = mdmTools.find((x) => x.name === name);
|
|
71
|
+
if (!t) throw new Error(`tool ${name} not found`);
|
|
72
|
+
return t.handler;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function ctxFor(backend: SharedBackend, id: string): MosaddToolContext {
|
|
76
|
+
return {
|
|
77
|
+
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
78
|
+
providers: {
|
|
79
|
+
dm: new ClientProvider(backend, id),
|
|
80
|
+
keys: new InMemoryMdmKeyStore(),
|
|
81
|
+
voice: new InMemoryVoiceProvider(id),
|
|
82
|
+
},
|
|
83
|
+
log: () => {},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", () => {
|
|
88
|
+
it("delivers an encrypted message alice→bob and a reply bob→alice", async () => {
|
|
89
|
+
const backend = new SharedBackend();
|
|
90
|
+
const alice = ctxFor(backend, "alice");
|
|
91
|
+
const bob = ctxFor(backend, "bob");
|
|
92
|
+
|
|
93
|
+
// 1. Both publish their prekey bundles (so first contact is possible).
|
|
94
|
+
await tool("mDM_publish_keys")({}, alice);
|
|
95
|
+
const bobPub = (await tool("mDM_publish_keys")({}, bob)) as { one_time_prekeys: number };
|
|
96
|
+
expect(bobPub.one_time_prekeys).toBeGreaterThan(0);
|
|
97
|
+
|
|
98
|
+
// 2. Alice sends an encrypted DM to Bob (first contact → X3DH handshake).
|
|
99
|
+
const sent = (await tool("mDM_send")({ to: "bob", text: "first contact" }, alice)) as {
|
|
100
|
+
encrypted: boolean;
|
|
101
|
+
};
|
|
102
|
+
expect(sent.encrypted).toBe(true);
|
|
103
|
+
|
|
104
|
+
// 3. The wire bytes must be CIPHERTEXT — the plaintext must NOT appear.
|
|
105
|
+
const wire = backend.messages[0]!.payload;
|
|
106
|
+
const wireStr = Buffer.from(wire).toString("utf8");
|
|
107
|
+
expect(wireStr).not.toContain("first contact");
|
|
108
|
+
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS — LINEAR-3409)
|
|
109
|
+
|
|
110
|
+
// 4. Bob lists the thread and decrypts Alice's message.
|
|
111
|
+
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
112
|
+
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
113
|
+
};
|
|
114
|
+
const fromAlice = bobView.messages.find((m) => m.sender_identity_id === "alice");
|
|
115
|
+
expect(fromAlice?.text).toBe("first contact");
|
|
116
|
+
expect(fromAlice?.encrypted).toBe(true);
|
|
117
|
+
|
|
118
|
+
// 5. Bob replies on the now-established session (no new handshake).
|
|
119
|
+
await tool("mDM_send")({ to: "alice", text: "copy that" }, bob);
|
|
120
|
+
|
|
121
|
+
// 6. Alice decrypts Bob's reply AND reads back her OWN sent message
|
|
122
|
+
// (sent-items cache — the ratchet can't re-derive own plaintext on read).
|
|
123
|
+
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
124
|
+
messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }>;
|
|
125
|
+
};
|
|
126
|
+
const fromBob = aliceView.messages.find((m) => m.sender_identity_id === "bob");
|
|
127
|
+
expect(fromBob?.text).toBe("copy that");
|
|
128
|
+
const ownByAlice = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
129
|
+
expect(ownByAlice?.text).toBe("first contact"); // not "<encrypted · sent by you>"
|
|
130
|
+
expect(ownByAlice?.encrypted).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("falls back to a marker for own messages when no sent-items cache exists", async () => {
|
|
134
|
+
// A keystore WITHOUT the optional sent-items cache must not crash; the
|
|
135
|
+
// sender simply sees the marker for their own outgoing messages.
|
|
136
|
+
const backend = new SharedBackend();
|
|
137
|
+
const alice = ctxFor(backend, "alice");
|
|
138
|
+
const bob = ctxFor(backend, "bob");
|
|
139
|
+
// Strip the optional cache methods from alice's keystore.
|
|
140
|
+
(alice.providers.keys as { putSentMessage?: unknown }).putSentMessage = undefined;
|
|
141
|
+
(alice.providers.keys as { getSentMessage?: unknown }).getSentMessage = undefined;
|
|
142
|
+
|
|
143
|
+
await tool("mDM_publish_keys")({}, bob);
|
|
144
|
+
await tool("mDM_send")({ to: "bob", text: "no cache here" }, alice);
|
|
145
|
+
|
|
146
|
+
const aliceView = (await tool("mDM_list")({ contact_id: "bob" }, alice)) as {
|
|
147
|
+
messages: Array<{ text: string; sender_identity_id: string }>;
|
|
148
|
+
};
|
|
149
|
+
const own = aliceView.messages.find((m) => m.sender_identity_id === "alice");
|
|
150
|
+
expect(own?.text).toBe("<encrypted · sent by you>");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("mDM_send fails with an actionable error when the peer has no published keys", async () => {
|
|
154
|
+
const backend = new SharedBackend();
|
|
155
|
+
const alice = ctxFor(backend, "alice");
|
|
156
|
+
// Bob never published — no bundle to fetch.
|
|
157
|
+
await expect(tool("mDM_send")({ to: "bob", text: "hi" }, alice)).rejects.toThrow(
|
|
158
|
+
/has not published a prekey bundle/i,
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("rejects a tampered (MITM) prekey bundle instead of starting a session", async () => {
|
|
163
|
+
const backend = new SharedBackend();
|
|
164
|
+
const alice = ctxFor(backend, "alice");
|
|
165
|
+
const bob = ctxFor(backend, "bob");
|
|
166
|
+
|
|
167
|
+
await tool("mDM_publish_keys")({}, bob);
|
|
168
|
+
|
|
169
|
+
// MITM swaps Bob's DH identity key (a SIGNED field) in the directory entry,
|
|
170
|
+
// keeping it valid base64 so it parses — only the signature should catch it.
|
|
171
|
+
const obj = JSON.parse(Buffer.from(backend.bundles.get("bob")!).toString("utf8"));
|
|
172
|
+
obj.ik = (obj.ik[0] === "A" ? "B" : "A") + obj.ik.slice(1);
|
|
173
|
+
backend.bundles.set("bob", new Uint8Array(Buffer.from(JSON.stringify(obj), "utf8")));
|
|
174
|
+
|
|
175
|
+
await expect(tool("mDM_send")({ to: "bob", text: "intercept me" }, alice)).rejects.toThrow(
|
|
176
|
+
/signature verification|man-in-the-middle/i,
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("auto-publish prekeys on startup (LINEAR-3104 cold-start fix)", () => {
|
|
182
|
+
it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
|
|
183
|
+
const backend = new SharedBackend();
|
|
184
|
+
createMosaddServer({
|
|
185
|
+
mode: "local",
|
|
186
|
+
autoPublishKeys: true,
|
|
187
|
+
providers: {
|
|
188
|
+
dm: new ClientProvider(backend, "self-agent"),
|
|
189
|
+
keys: new InMemoryMdmKeyStore(),
|
|
190
|
+
voice: new InMemoryVoiceProvider("self-agent"),
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
// fire-and-forget; getOwnMaterial() does async key generation, so flush.
|
|
194
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
195
|
+
expect(backend.bundles.has("self-agent")).toBe(true);
|
|
196
|
+
expect(backend.bundles.get("self-agent")!.byteLength).toBeGreaterThan(0);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does NOT publish when autoPublishKeys is unset (hosted/default)", async () => {
|
|
200
|
+
const backend = new SharedBackend();
|
|
201
|
+
createMosaddServer({
|
|
202
|
+
mode: "local",
|
|
203
|
+
providers: {
|
|
204
|
+
dm: new ClientProvider(backend, "quiet-agent"),
|
|
205
|
+
keys: new InMemoryMdmKeyStore(),
|
|
206
|
+
voice: new InMemoryVoiceProvider("quiet-agent"),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
210
|
+
expect(backend.bundles.has("quiet-agent")).toBe(false);
|
|
211
|
+
});
|
|
212
|
+
});
|