@mosadd/mcp 3.0.0 → 3.0.2
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 +420 -410
- package/LICENSE +21 -0
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-VMMJJYXF.js → chunk-I3FSPQ4G.js} +78 -30
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/blob-upload.test.ts +1 -1
- package/src/__tests__/{flota-jawnie.test.ts → fleet-plaintext.test.ts} +59 -60
- package/src/__tests__/integration.test.ts +1 -1
- package/src/__tests__/mdm-e2ee.test.ts +3 -3
- package/src/__tests__/mdm-mcp-readable.test.ts +95 -95
- package/src/__tests__/mirc-files.test.ts +80 -0
- package/src/__tests__/mirc-invite.test.ts +1 -1
- package/src/__tests__/mirc-voice.test.ts +82 -0
- package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
- package/src/__tests__/presence.test.ts +2 -2
- package/src/__tests__/server.test.ts +3 -3
- package/src/__tests__/tool-count-consistency.test.ts +4 -4
- package/src/crypto/channel-e2ee.ts +1 -1
- package/src/crypto/mdm-session.ts +14 -14
- package/src/providers/supabase-dm.ts +6 -1
- package/src/providers/supabase.ts +8 -8
- package/src/server.ts +4 -4
- package/src/tools/channel-payload.ts +3 -3
- package/src/tools/index.ts +13 -13
- package/src/tools/knowledge.ts +384 -351
- package/src/tools/mail-aliases.ts +1 -1
- package/src/tools/mail-provenance.ts +1 -1
- package/src/tools/mdm-as-agent.ts +3 -4
- package/src/tools/mdm.ts +19 -14
- package/src/tools/mirc-edge.ts +4 -4
- package/src/tools/mirc-members.ts +1 -1
- package/src/tools/mirc-messages.ts +41 -12
- package/src/tools/mirc.ts +1 -1
- package/src/tools/mroom-messages.ts +1 -1
- package/src/tools/presence.ts +10 -10
- package/src/tools/ptt-ingest.ts +1 -1
- package/src/tools/threat.ts +1 -1
- package/src/tools/voice-format.ts +53 -7
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LOCK "NO ENCRYPTION WITH THE FLEET" (29.09.2026, owner decision 28.09: no encryption on agent-line
|
|
3
3
|
* conversations, in any channel or identity).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* D1 §3 i S1 §1b):
|
|
5
|
+
* Two rules of the MCP gateway, both measured as broken on 28–29.09:
|
|
7
6
|
*
|
|
8
|
-
* c1 —
|
|
9
|
-
*
|
|
10
|
-
* (`mirc-messages.ts` / `mroom-messages.ts` `unpackPayload`)
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
7
|
+
* c1 — CHANNEL DECODER. Open channels have no group key. The app stores channel text
|
|
8
|
+
* as bare UTF-8 in base64 (apps/web ircApi.ts `encodePayload`). The old decoder
|
|
9
|
+
* (`mirc-messages.ts` / `mroom-messages.ts` `unpackPayload`) knew only the JSON envelope, so
|
|
10
|
+
* EVERY post of the owner read as "<ciphertext>" for the agent lines.
|
|
11
|
+
* Now: plain text = text. "<ciphertext>" stays only for a real group-key envelope
|
|
12
|
+
* {iv,ciphertext,hmac} the line holds no key for (and for bytes that are not UTF-8).
|
|
14
13
|
*
|
|
15
|
-
* b1 — mDM_send
|
|
16
|
-
* (to === selfId),
|
|
17
|
-
*
|
|
14
|
+
* b1 — mDM_send TO THE FLEET IN THE CLEAR. When either side is an agent line OR it is a note to self
|
|
15
|
+
* (to === selfId), the send takes the plain path: encrypted:false, reason:"fleet_plaintext".
|
|
16
|
+
* Person↔person stays E2EE, unchanged (X3DH + Double Ratchet envelope).
|
|
18
17
|
*
|
|
19
|
-
*
|
|
18
|
+
* Every lock was checked red before the fix (alpha.54 code) and under sabotage after the fix.
|
|
20
19
|
*/
|
|
21
20
|
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
22
21
|
import type { DmProvider, DmListArgs, DmListResult, DmSendResult } from "@mosadd/providers";
|
|
@@ -66,82 +65,82 @@ const listCtx = { log: noopLog } as unknown as MosaddToolContext;
|
|
|
66
65
|
const appEncode = (text: string) => Buffer.from(new TextEncoder().encode(text)).toString("base64");
|
|
67
66
|
const b64json = (obj: unknown) => Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
|
|
68
67
|
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const LINE = "
|
|
68
|
+
const CHANNEL = "00000000-0000-4000-8000-000000000001";
|
|
69
|
+
const OWNER = "owner-identity";
|
|
70
|
+
const LINE = "agent-line-identity";
|
|
72
71
|
const PEER = "peer-human-identity";
|
|
73
|
-
// Synthetic (the repo is public — no real message
|
|
74
|
-
// diacritics, an em dash, an @mention, a newline and an emoji, like
|
|
75
|
-
const
|
|
72
|
+
// Synthetic (the repo is public — no real message goes into a fixture): Polish
|
|
73
|
+
// diacritics, an em dash, an @mention, a newline and an emoji, like a real owner post.
|
|
74
|
+
const OWNER_TEXT = "Zażółć gęślą jaźń — spotkanie o 9:00 🦞\n@all proszę o potwierdzenie";
|
|
76
75
|
|
|
77
76
|
type ListOut = { messages: Array<{ id: string; text: string }> };
|
|
78
77
|
|
|
79
78
|
async function readChannel(rows: Array<[string, string]>): Promise<string[]> {
|
|
80
79
|
storedRows = rows.map(([id, payload], i) => ({
|
|
81
80
|
id,
|
|
82
|
-
sender_identity_id:
|
|
81
|
+
sender_identity_id: OWNER,
|
|
83
82
|
encrypted_payload: payload,
|
|
84
83
|
created_at: new Date(i * 1000).toISOString(),
|
|
85
84
|
}));
|
|
86
85
|
const out = (await handler(mircMessagesTools, "mIRC_list_messages")(
|
|
87
|
-
{ channel_id:
|
|
86
|
+
{ channel_id: CHANNEL, space_id: "space-1", limit: 50 },
|
|
88
87
|
listCtx,
|
|
89
88
|
)) as ListOut;
|
|
90
89
|
return out.messages.map((m) => m.text);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
describe("c1 —
|
|
92
|
+
describe("c1 — channel decoder: the owner's text reads as text, <ciphertext> only for a sealed envelope", () => {
|
|
94
93
|
beforeEach(() => {
|
|
95
94
|
storedRows = [];
|
|
96
95
|
groupKeyOpens = () => null;
|
|
97
96
|
});
|
|
98
97
|
|
|
99
|
-
it("
|
|
98
|
+
it("an owner post from the app (bare UTF-8 in base64) on an open channel → readable text, not <ciphertext>", async () => {
|
|
100
99
|
const texts = await readChannel([
|
|
101
|
-
["
|
|
102
|
-
["
|
|
100
|
+
["msg-1", appEncode(OWNER_TEXT)],
|
|
101
|
+
["msg-2", appEncode("@all please confirm")],
|
|
103
102
|
]);
|
|
104
|
-
expect(texts).toEqual([
|
|
103
|
+
expect(texts).toEqual([OWNER_TEXT, "@all please confirm"]);
|
|
105
104
|
expect(texts).not.toContain("<ciphertext>");
|
|
106
105
|
});
|
|
107
106
|
|
|
108
|
-
it("
|
|
107
|
+
it("a mosadd.chat.v1 envelope from the tool (agent lines) → its text, as before", async () => {
|
|
109
108
|
const texts = await readChannel([
|
|
110
|
-
["line-1", b64json({ v: "mosadd.chat.v1", type: "text", text: "
|
|
109
|
+
["line-1", b64json({ v: "mosadd.chat.v1", type: "text", text: "line report", reply_to: null })],
|
|
111
110
|
]);
|
|
112
|
-
expect(texts).toEqual(["
|
|
111
|
+
expect(texts).toEqual(["line report"]);
|
|
113
112
|
});
|
|
114
113
|
|
|
115
|
-
it("
|
|
114
|
+
it("a group-key envelope {iv,ciphertext,hmac} WITHOUT the key → <ciphertext> stays", async () => {
|
|
116
115
|
const texts = await readChannel([["sealed", b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" })]]);
|
|
117
116
|
expect(texts).toEqual(["<ciphertext>"]);
|
|
118
117
|
});
|
|
119
118
|
|
|
120
|
-
it("
|
|
119
|
+
it("a group-key envelope, the line HAS the key → decrypted text (path unchanged)", async () => {
|
|
121
120
|
const sealed = b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" });
|
|
122
|
-
groupKeyOpens = (_c, p) => (p === sealed ? JSON.stringify({ v: "mosadd.chat.v1", type: "text", text: "
|
|
123
|
-
expect(await readChannel([["sealed", sealed]])).toEqual(["
|
|
121
|
+
groupKeyOpens = (_c, p) => (p === sealed ? JSON.stringify({ v: "mosadd.chat.v1", type: "text", text: "from the key" }) : null);
|
|
122
|
+
expect(await readChannel([["sealed", sealed]])).toEqual(["from the key"]);
|
|
124
123
|
});
|
|
125
124
|
|
|
126
|
-
it("
|
|
125
|
+
it("an mDM ratchet envelope (v: mosadd.e2ee.*) pasted into a channel → <ciphertext>", async () => {
|
|
127
126
|
const texts = await readChannel([["e2ee", b64json({ v: "mosadd.e2ee.v2", dh: "x", n: 0, ct: "y" })]]);
|
|
128
127
|
expect(texts).toEqual(["<ciphertext>"]);
|
|
129
128
|
});
|
|
130
129
|
|
|
131
|
-
it("
|
|
130
|
+
it("non-UTF-8 bytes → <ciphertext> (these are not words)", async () => {
|
|
132
131
|
const texts = await readChannel([["bin", Buffer.from([0xff, 0xfe, 0x00, 0x81, 0xc3]).toString("base64")]]);
|
|
133
132
|
expect(texts).toEqual(["<ciphertext>"]);
|
|
134
133
|
});
|
|
135
134
|
|
|
136
|
-
it("
|
|
135
|
+
it("voice {audio, mime, dur} → voice note marker (formatVoiceIfAny unchanged)", async () => {
|
|
137
136
|
const texts = await readChannel([["voice", b64json({ audio: "A".repeat(2000), mime: "audio/webm", dur: 4200 })]]);
|
|
138
137
|
expect(texts).toEqual(["[voice note — 4s]"]);
|
|
139
138
|
});
|
|
140
139
|
|
|
141
|
-
it("mROOM:
|
|
142
|
-
storedRows = [{ id: "r1", sender_identity_id:
|
|
140
|
+
it("mROOM: the same rule — text from the app reads as text", async () => {
|
|
141
|
+
storedRows = [{ id: "r1", sender_identity_id: OWNER, encrypted_payload: appEncode(OWNER_TEXT), created_at: new Date(0).toISOString() }];
|
|
143
142
|
const out = (await handler(mroomMessagesTools, "mROOM_list_messages")({ room_id: "room-1" }, listCtx)) as ListOut;
|
|
144
|
-
expect(out.messages.map((m) => m.text)).toEqual([
|
|
143
|
+
expect(out.messages.map((m) => m.text)).toEqual([OWNER_TEXT]);
|
|
145
144
|
});
|
|
146
145
|
});
|
|
147
146
|
|
|
@@ -189,56 +188,56 @@ const send = (b: Backend, from: string, to: string, text: string) =>
|
|
|
189
188
|
handler(mdmTools, "mDM_send")({ to, text }, gatewayRequest(b, from)) as Promise<SendOut>;
|
|
190
189
|
const plain = (row: Row) => new TextDecoder().decode(row.payload);
|
|
191
190
|
|
|
192
|
-
describe("b1 — mDM_send:
|
|
193
|
-
it("
|
|
191
|
+
describe("b1 — mDM_send: with fleet lines and with the owner always in the clear, person↔person E2EE", () => {
|
|
192
|
+
it("agent line → owner: encrypted:false, reason fleet_plaintext, the owner reads bare text", async () => {
|
|
194
193
|
const b = new Backend();
|
|
195
194
|
b.kinds.set(LINE, "agent");
|
|
196
|
-
await person(b,
|
|
197
|
-
const s = await send(b, LINE,
|
|
195
|
+
await person(b, OWNER, 7);
|
|
196
|
+
const s = await send(b, LINE, OWNER, "report");
|
|
198
197
|
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
199
198
|
expect(b.rows.at(-1)!.messageType).toBe("txt");
|
|
200
|
-
expect(plain(b.rows.at(-1)!)).toBe("
|
|
199
|
+
expect(plain(b.rows.at(-1)!)).toBe("report");
|
|
201
200
|
});
|
|
202
201
|
|
|
203
|
-
it("
|
|
202
|
+
it("owner (a person's key) → agent line: in the clear, even though the line has an old bundle", async () => {
|
|
204
203
|
const b = new Backend();
|
|
205
204
|
b.kinds.set(LINE, "agent");
|
|
206
|
-
await person(b,
|
|
205
|
+
await person(b, OWNER, 7);
|
|
207
206
|
b.bundles.set(LINE, serializePublicBundle(await new SeededMdmKeyStore(new Uint8Array(32).fill(9)).getOwnMaterial()));
|
|
208
|
-
const s = await send(b,
|
|
207
|
+
const s = await send(b, OWNER, LINE, "instruction");
|
|
209
208
|
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
210
|
-
expect(plain(b.rows.at(-1)!)).toBe("
|
|
209
|
+
expect(plain(b.rows.at(-1)!)).toBe("instruction");
|
|
211
210
|
});
|
|
212
211
|
|
|
213
|
-
it("
|
|
212
|
+
it("the owner writes to SELF (to === selfId) through MCP: in the clear — zero envelopes in the own thread", async () => {
|
|
214
213
|
const b = new Backend();
|
|
215
|
-
await person(b,
|
|
216
|
-
const s = await send(b,
|
|
214
|
+
await person(b, OWNER, 7);
|
|
215
|
+
const s = await send(b, OWNER, OWNER, "note to self");
|
|
217
216
|
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
218
217
|
const row = b.rows.at(-1)!;
|
|
219
|
-
expect(row.threadId).toBe(`dm:${
|
|
218
|
+
expect(row.threadId).toBe(`dm:${OWNER}:${OWNER}`);
|
|
220
219
|
expect(isE2eeEnvelope(row.payload)).toBe(false);
|
|
221
|
-
expect(plain(row)).toBe("
|
|
220
|
+
expect(plain(row)).toBe("note to self");
|
|
222
221
|
});
|
|
223
222
|
|
|
224
|
-
it("
|
|
223
|
+
it("person → person: E2EE stays — ratchet envelope, text not visible, the recipient opens it", async () => {
|
|
225
224
|
const b = new Backend();
|
|
226
|
-
await person(b,
|
|
225
|
+
await person(b, OWNER, 7);
|
|
227
226
|
const peerKeys = await person(b, PEER, 5);
|
|
228
|
-
const s = await send(b,
|
|
227
|
+
const s = await send(b, OWNER, PEER, "secret");
|
|
229
228
|
expect(s).toMatchObject({ encrypted: true, mode: "e2ee" });
|
|
230
229
|
expect(s.reason).not.toBe("fleet_plaintext");
|
|
231
230
|
const row = b.rows.at(-1)!;
|
|
232
231
|
expect(isE2eeEnvelope(row.payload)).toBe(true);
|
|
233
|
-
expect(plain(row)).not.toContain("
|
|
234
|
-
expect(new TextDecoder().decode(await decryptFromPeer(peerKeys,
|
|
232
|
+
expect(plain(row)).not.toContain("secret");
|
|
233
|
+
expect(new TextDecoder().decode(await decryptFromPeer(peerKeys, OWNER, row.payload))).toBe("secret");
|
|
235
234
|
});
|
|
236
235
|
|
|
237
|
-
it("
|
|
236
|
+
it("tool descriptions: mDM_send_unencrypted is not 'DEPRECATED / prefer mDM_send', both say: fleet always in the clear", () => {
|
|
238
237
|
const d = (n: string) => mdmTools.find((t) => t.name === n)!.description;
|
|
239
238
|
expect(d("mDM_send_unencrypted")).not.toMatch(/DEPRECATED|Prefer mDM_send|Will be removed/i);
|
|
240
239
|
for (const n of ["mDM_send", "mDM_send_unencrypted"]) {
|
|
241
|
-
expect(d(n)).toMatch(/fleet lines and with the
|
|
240
|
+
expect(d(n)).toMatch(/Conversations with fleet lines and with the [A-Za-z ]+: ALWAYS in the clear/);
|
|
242
241
|
}
|
|
243
242
|
});
|
|
244
243
|
});
|
|
@@ -176,7 +176,7 @@ describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
|
176
176
|
expect(names).toContain("mDM_send");
|
|
177
177
|
expect(names).toContain("mIRC_create");
|
|
178
178
|
expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
|
|
179
|
-
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered
|
|
179
|
+
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered
|
|
180
180
|
expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
|
|
181
181
|
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
182
182
|
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mDM E2EE golden path
|
|
2
|
+
* mDM E2EE golden path — the "done" bar.
|
|
3
3
|
*
|
|
4
4
|
* Two parties (alice, bob) sharing ONE backend that acts as both the message
|
|
5
5
|
* store AND the key directory (decision "1a": prekey bundles ride the same
|
|
@@ -105,7 +105,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
|
|
|
105
105
|
const wire = backend.messages[0]!.payload;
|
|
106
106
|
const wireStr = Buffer.from(wire).toString("utf8");
|
|
107
107
|
expect(wireStr).not.toContain("first contact");
|
|
108
|
-
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS
|
|
108
|
+
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS)
|
|
109
109
|
|
|
110
110
|
// 4. Bob lists the thread and decrypts Alice's message.
|
|
111
111
|
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
@@ -178,7 +178,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
|
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
describe("auto-publish prekeys on startup (
|
|
181
|
+
describe("auto-publish prekeys on startup (cold-start fix)", () => {
|
|
182
182
|
it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
|
|
183
183
|
const backend = new SharedBackend();
|
|
184
184
|
createMosaddServer({
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* LOCK (27.09.2026, follow-up fix after independent verification of the mDM gateway path):
|
|
3
|
+
* a message sent by mDM_send from MCP must be READABLE for the sender and for the recipient — on EVERY
|
|
4
|
+
* key of the same identity, not only on the one that sent it — and the app must tell the TRUTH
|
|
5
|
+
* when it cannot show something.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* 1. mDM_send
|
|
9
|
-
* 2.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 3. alpha.53
|
|
15
|
-
* (mdmE2ee.ts readOwnMdmMessage)
|
|
16
|
-
* (
|
|
7
|
+
* What was measured on 27.09:
|
|
8
|
+
* 1. mDM_send through the gateway created a NEW identity on every call (in-memory keystore per HTTP request).
|
|
9
|
+
* 2. The first fix (alpha.53) gave a stable identity per API KEY and let an agent line
|
|
10
|
+
* replace its bundle in the directory. An identity has MANY active keys (one agent identity: 8, all
|
|
11
|
+
* used within 3 days; 7 of 17 agents have several), so the bundle jumped between identities:
|
|
12
|
+
* the s1. copy opened only under the key that wrote it, and the r1. copies stopped
|
|
13
|
+
* opening for the recipient after the next send with another key.
|
|
14
|
+
* 3. alpha.53 also wrote `txt` + s1. under the API-key seed on a PERSON's key — the app
|
|
15
|
+
* (mdmE2ee.ts readOwnMdmMessage) does not open such a copy and gave a FALSE reason
|
|
16
|
+
* ("sent from another device" / "unlock your identity") instead of "sent by MCP".
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* Fix at the source = the owner's rule (20.09: no E2EE on internal conversations): when one
|
|
19
|
+
* side of the conversation is an agent line, the DM goes IN THE CLEAR — the app does the same (peerIsAgent).
|
|
20
|
+
* Plain text is readable by every key of the line and by the recipient's app on every device; no bundle is
|
|
21
|
+
* needed, so there is nothing to replace. Person↔person stays E2EE, and MCP on a person's
|
|
22
|
+
* key does NOT touch the bundle from their app, writes no s1. copy and marks the envelope `text`.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Real cryptography (X3DH + Double Ratchet + AES-GCM + HKDF from @mosadd/crypto), no fake
|
|
25
|
+
* ciphers. Every gateway "request" = a FRESH server with the given API key — like the gateway handler.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import { execFileSync } from "node:child_process";
|
|
@@ -179,9 +179,9 @@ async function appReadOwn(
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
const KEY_A = "mosadd_sk_live_0123456789abcdef0123456789abcdef";
|
|
182
|
-
const KEY_B = "mosadd_sk_live_fedcba9876543210fedcba9876543210"; //
|
|
183
|
-
const LINE = "
|
|
184
|
-
const
|
|
182
|
+
const KEY_B = "mosadd_sk_live_fedcba9876543210fedcba9876543210"; // a second key, active in parallel, same line
|
|
183
|
+
const LINE = "agent-line-identity";
|
|
184
|
+
const OWNER = "owner-identity";
|
|
185
185
|
const PEER = "peer-human-identity";
|
|
186
186
|
|
|
187
187
|
type SendOut = {
|
|
@@ -194,11 +194,11 @@ type SendOut = {
|
|
|
194
194
|
};
|
|
195
195
|
type ListOut = { messages: Array<{ text: string; sender_identity_id: string; encrypted: boolean }> };
|
|
196
196
|
|
|
197
|
-
describe("mDM_send
|
|
198
|
-
it("KAT:
|
|
197
|
+
describe("mDM_send from MCP — readable on every key, true reasons in the app (lock 27.09)", () => {
|
|
198
|
+
it("KAT: the identity derived from the seed is bit for bit the one the app derives", async () => {
|
|
199
199
|
const seed = new Uint8Array(32).map((_, i) => i + 1);
|
|
200
200
|
const m = await deriveOwnMaterialFromSeed(seed);
|
|
201
|
-
//
|
|
201
|
+
// computed with @noble/curves+hashes 2.0.1 from the mosADD tree (the same ones the web client uses)
|
|
202
202
|
expect(toBase64(m.identity.publicKey)).toBe("kGJhDa1OHhlUYRQ0ZgztQfIucOPLxkdOK2iBJpNEWEU=");
|
|
203
203
|
expect(toBase64(m.signingIdentity.publicKey)).toBe("4XxF9XwcOS25C+G8oS/NGXor6ahKsOklnpq3JUQHfVY=");
|
|
204
204
|
expect(toBase64(m.signedPrekey.pair.publicKey)).toBe("0/QU9p52caXSkyjLx/PH4C/9A/UzOZaPRecMtVBQj0Y=");
|
|
@@ -209,7 +209,7 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
|
|
|
209
209
|
);
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
it("
|
|
212
|
+
it("two gateway requests with the same key = ONE identity (not a new one per call)", async () => {
|
|
213
213
|
const b = new Backend();
|
|
214
214
|
const a = await gatewayRequest(b, LINE, KEY_A).providers.keys.getOwnMaterial();
|
|
215
215
|
const c = await gatewayRequest(b, LINE, KEY_A).providers.keys.getOwnMaterial();
|
|
@@ -217,19 +217,19 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
|
|
|
217
217
|
expect(toBase64(a.signedPrekey.pair.publicKey)).toBe(toBase64(c.signedPrekey.pair.publicKey));
|
|
218
218
|
});
|
|
219
219
|
|
|
220
|
-
it("
|
|
220
|
+
it("agent line, TWO keys alternating: plain txt, every key reads everything, the owner reads in the app, directory untouched", async () => {
|
|
221
221
|
const b = new Backend();
|
|
222
222
|
b.kinds.set(LINE, "agent");
|
|
223
|
-
await appOf(b,
|
|
223
|
+
await appOf(b, OWNER, 7);
|
|
224
224
|
|
|
225
|
-
const s1 = (await tool("mDM_send")({ to:
|
|
226
|
-
const s2 = (await tool("mDM_send")({ to:
|
|
227
|
-
const s3 = (await tool("mDM_send")({ to:
|
|
225
|
+
const s1 = (await tool("mDM_send")({ to: OWNER, text: "report from key A" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
|
|
226
|
+
const s2 = (await tool("mDM_send")({ to: OWNER, text: "report from key B" }, gatewayRequest(b, LINE, KEY_B))) as SendOut;
|
|
227
|
+
const s3 = (await tool("mDM_send")({ to: OWNER, text: "key A again" }, gatewayRequest(b, LINE, KEY_A))) as SendOut;
|
|
228
228
|
for (const s of [s1, s2, s3]) {
|
|
229
229
|
expect(s).toMatchObject({ encrypted: false, mode: "plaintext_agent_lane", sender_copy: true, recipient_copy: true, identity: "untouched" });
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
//
|
|
232
|
+
// Key directory: ZERO writes — the line has no bundle, so there is nothing to switch.
|
|
233
233
|
expect(b.publishes).toBe(0);
|
|
234
234
|
expect(b.bundles.has(LINE)).toBe(false);
|
|
235
235
|
|
|
@@ -238,104 +238,104 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
|
|
|
238
238
|
expect(row.selfPayload).toBeNull();
|
|
239
239
|
expect(row.recipientSelfPayload).toBeNull();
|
|
240
240
|
}
|
|
241
|
-
//
|
|
242
|
-
expect(b.rows.map(appPlaintext)).toEqual(["
|
|
241
|
+
// The owner in the app, on ANY device: plain text, no keys and no ratchet.
|
|
242
|
+
expect(b.rows.map(appPlaintext)).toEqual(["report from key A", "report from key B", "key A again"]);
|
|
243
243
|
|
|
244
|
-
//
|
|
244
|
+
// Sender: EVERY key of the line, fresh request (empty sent memory), reads ALL three.
|
|
245
245
|
for (const k of [KEY_A, KEY_B]) {
|
|
246
|
-
const read = (await tool("mDM_list")({ contact_id:
|
|
247
|
-
expect(read.messages.map((m) => m.text)).toEqual(["
|
|
246
|
+
const read = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, k))) as ListOut;
|
|
247
|
+
expect(read.messages.map((m) => m.text)).toEqual(["report from key A", "report from key B", "key A again"]);
|
|
248
248
|
}
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
-
it("
|
|
251
|
+
it("the line's own thread (dm:me:me): written with key A, read with key B", async () => {
|
|
252
252
|
const b = new Backend();
|
|
253
253
|
b.kinds.set(LINE, "agent");
|
|
254
|
-
await tool("mDM_send")({ to: LINE, text: "
|
|
254
|
+
await tool("mDM_send")({ to: LINE, text: "note to self" }, gatewayRequest(b, LINE, KEY_A));
|
|
255
255
|
const row = b.rows.at(-1)!;
|
|
256
256
|
expect(row.threadId).toBe(`dm:${LINE}:${LINE}`);
|
|
257
257
|
expect(row.messageType).toBe("txt");
|
|
258
258
|
const read = (await tool("mDM_list")({ contact_id: LINE }, gatewayRequest(b, LINE, KEY_B))) as ListOut;
|
|
259
|
-
expect(read.messages.map((m) => m.text)).toEqual(["
|
|
259
|
+
expect(read.messages.map((m) => m.text)).toEqual(["note to self"]);
|
|
260
260
|
expect(b.publishes).toBe(0);
|
|
261
261
|
});
|
|
262
262
|
|
|
263
|
-
it("
|
|
263
|
+
it("a person writes through MCP TO an agent line: in the clear (like peerIsAgent in the app)", async () => {
|
|
264
264
|
const b = new Backend();
|
|
265
265
|
b.kinds.set(LINE, "agent");
|
|
266
|
-
await appOf(b,
|
|
267
|
-
const s = (await tool("mDM_send")({ to: LINE, text: "
|
|
266
|
+
await appOf(b, OWNER, 7);
|
|
267
|
+
const s = (await tool("mDM_send")({ to: LINE, text: "instruction" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
|
|
268
268
|
expect(s.mode).toBe("plaintext_agent_lane");
|
|
269
|
-
expect(appPlaintext(b.rows.at(-1)!)).toBe("
|
|
270
|
-
const lineRead = (await tool("mDM_list")({ contact_id:
|
|
271
|
-
expect(lineRead.messages.map((m) => m.text)).toEqual(["
|
|
269
|
+
expect(appPlaintext(b.rows.at(-1)!)).toBe("instruction");
|
|
270
|
+
const lineRead = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, KEY_B))) as ListOut;
|
|
271
|
+
expect(lineRead.messages.map((m) => m.text)).toEqual(["instruction"]);
|
|
272
272
|
});
|
|
273
273
|
|
|
274
|
-
it("
|
|
274
|
+
it("a PERSON's key to a person: E2EE, app bundle untouched, no s1., type `text` — the app gives the TRUE reason", async () => {
|
|
275
275
|
const b = new Backend();
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
const
|
|
276
|
+
const ownerSeed = new Uint8Array(32).fill(7);
|
|
277
|
+
const ownerApp = await appOf(b, OWNER, 7);
|
|
278
|
+
const ownerBundle = toBase64(b.bundles.get(OWNER)!);
|
|
279
279
|
const peerApp = await appOf(b, PEER, 5);
|
|
280
280
|
|
|
281
|
-
const s = (await tool("mDM_send")({ to: PEER, text: "
|
|
281
|
+
const s = (await tool("mDM_send")({ to: PEER, text: "secret" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
|
|
282
282
|
expect(s).toMatchObject({ encrypted: true, mode: "e2ee", identity: "foreign", sender_copy: false, recipient_copy: false });
|
|
283
283
|
const row = b.rows.at(-1)!;
|
|
284
284
|
expect(row.messageType).toBe("text");
|
|
285
285
|
expect(row.selfPayload).toBeNull();
|
|
286
|
-
expect(appPlaintext(row)).not.toContain("
|
|
286
|
+
expect(appPlaintext(row)).not.toContain("secret");
|
|
287
287
|
expect(b.publishes).toBe(0);
|
|
288
|
-
expect(toBase64(b.bundles.get(
|
|
288
|
+
expect(toBase64(b.bundles.get(OWNER)!)).toBe(ownerBundle);
|
|
289
289
|
|
|
290
|
-
//
|
|
291
|
-
expect(new TextDecoder().decode(await decryptFromPeer(peerApp,
|
|
292
|
-
//
|
|
293
|
-
expect(await appReadOwn(
|
|
290
|
+
// The recipient reads through the ratchet (the envelope carries an X3DH header to THEIR app bundle).
|
|
291
|
+
expect(new TextDecoder().decode(await decryptFromPeer(peerApp, OWNER, row.payload))).toBe("secret");
|
|
292
|
+
// The owner in the app: no content (MCP does not know the app seed) and the reason is TRUE.
|
|
293
|
+
expect(await appReadOwn(ownerSeed, ownerApp, OWNER, row)).toEqual({ text: null, reason: "agent" });
|
|
294
294
|
});
|
|
295
295
|
|
|
296
|
-
// 29.09 (
|
|
297
|
-
//
|
|
298
|
-
it("
|
|
296
|
+
// 29.09 (owner decision 28.09: no encryption on agent-line conversations): a note to self from MCP goes IN THE CLEAR —
|
|
297
|
+
// until 28.09 it was an E2EE envelope the app opened with seed keys; now there is nothing to open.
|
|
298
|
+
it("a person's key, note to self: plain txt — the app reads bare text on every device", async () => {
|
|
299
299
|
const b = new Backend();
|
|
300
|
-
await appOf(b,
|
|
301
|
-
const s = (await tool("mDM_send")({ to:
|
|
300
|
+
await appOf(b, OWNER, 7);
|
|
301
|
+
const s = (await tool("mDM_send")({ to: OWNER, text: "note to self from MCP" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
|
|
302
302
|
expect(s).toMatchObject({ encrypted: false, mode: "plaintext_agent_lane", identity: "untouched" });
|
|
303
303
|
const row = b.rows.at(-1)!;
|
|
304
304
|
expect(row.messageType).toBe("txt");
|
|
305
305
|
expect(row.selfPayload).toBeNull();
|
|
306
|
-
expect(appPlaintext(row)).toBe("
|
|
306
|
+
expect(appPlaintext(row)).toBe("note to self from MCP");
|
|
307
307
|
expect(b.publishes).toBe(0);
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
-
it("
|
|
310
|
+
it("a person WITHOUT a bundle: MCP does not publish on its own (neither mDM_send nor autoPublishKeys); an explicit mDM_publish_keys may", async () => {
|
|
311
311
|
const b = new Backend();
|
|
312
|
-
b.kinds.set(
|
|
312
|
+
b.kinds.set(OWNER, "human");
|
|
313
313
|
await appOf(b, PEER, 5);
|
|
314
|
-
const s = (await tool("mDM_send")({ to: PEER, text: "x" }, gatewayRequest(b,
|
|
314
|
+
const s = (await tool("mDM_send")({ to: PEER, text: "x" }, gatewayRequest(b, OWNER, KEY_A))) as SendOut;
|
|
315
315
|
expect(s.identity).toBe("absent");
|
|
316
|
-
expect(b.bundles.has(
|
|
316
|
+
expect(b.bundles.has(OWNER)).toBe(false);
|
|
317
317
|
|
|
318
|
-
createMosaddServer({ apiKey: KEY_A, autoPublishKeys: true, providers: { dm: new Lane(b,
|
|
318
|
+
createMosaddServer({ apiKey: KEY_A, autoPublishKeys: true, providers: { dm: new Lane(b, OWNER), voice: new InMemoryVoiceProvider(OWNER) } });
|
|
319
319
|
await new Promise((r) => setTimeout(r, 50));
|
|
320
|
-
expect(b.bundles.has(
|
|
320
|
+
expect(b.bundles.has(OWNER)).toBe(false);
|
|
321
321
|
expect(b.publishes).toBe(0);
|
|
322
322
|
|
|
323
|
-
const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b,
|
|
323
|
+
const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, OWNER, KEY_A))) as { published: boolean; identity: string };
|
|
324
324
|
expect(p).toMatchObject({ published: true, identity: "published" });
|
|
325
325
|
});
|
|
326
326
|
|
|
327
|
-
it("
|
|
327
|
+
it("an explicit mDM_publish_keys on a person's key does NOT overwrite the app bundle", async () => {
|
|
328
328
|
const b = new Backend();
|
|
329
|
-
await appOf(b,
|
|
330
|
-
const before = toBase64(b.bundles.get(
|
|
331
|
-
const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b,
|
|
329
|
+
await appOf(b, OWNER, 7);
|
|
330
|
+
const before = toBase64(b.bundles.get(OWNER)!);
|
|
331
|
+
const p = (await tool("mDM_publish_keys")({}, gatewayRequest(b, OWNER, KEY_A))) as { published: boolean; identity: string; note?: string };
|
|
332
332
|
expect(p).toMatchObject({ published: false, identity: "foreign" });
|
|
333
333
|
expect(p.note).toBeTruthy();
|
|
334
|
-
expect(toBase64(b.bundles.get(
|
|
334
|
+
expect(toBase64(b.bundles.get(OWNER)!)).toBe(before);
|
|
335
335
|
expect(b.publishes).toBe(0);
|
|
336
336
|
});
|
|
337
337
|
|
|
338
|
-
it("autoPublishKeys
|
|
338
|
+
it("autoPublishKeys on an agent line: zero directory writes (none of its keys switches the bundle)", async () => {
|
|
339
339
|
const b = new Backend();
|
|
340
340
|
b.kinds.set(LINE, "agent");
|
|
341
341
|
for (const k of [KEY_A, KEY_B]) {
|
|
@@ -346,31 +346,31 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
|
|
|
346
346
|
expect(b.bundles.has(LINE)).toBe(false);
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
-
it("
|
|
349
|
+
it("an old E2EE envelope from the owner with an r1. copy (line bundle from before the fix) is still readable in the gateway", async () => {
|
|
350
350
|
const b = new Backend();
|
|
351
351
|
b.kinds.set(LINE, "agent");
|
|
352
|
-
const
|
|
353
|
-
//
|
|
352
|
+
const owner = await appOf(b, OWNER, 7);
|
|
353
|
+
// the line bundle published by alpha.53 from the seed of key A
|
|
354
354
|
b.bundles.set(LINE, serializePublicBundle(await new SeededMdmKeyStore(await deriveMdmSeedFromSecret(KEY_A)).getOwnMaterial()));
|
|
355
|
-
const
|
|
356
|
-
const lineBundle = (await fetchVerifiedBundle(
|
|
357
|
-
const inner = new TextEncoder().encode("
|
|
358
|
-
await encryptForPeer(
|
|
359
|
-
const env = await encryptForPeer(
|
|
360
|
-
await
|
|
355
|
+
const ownerLane = new Lane(b, OWNER);
|
|
356
|
+
const lineBundle = (await fetchVerifiedBundle(ownerLane, LINE))!;
|
|
357
|
+
const inner = new TextEncoder().encode("instruction from the owner");
|
|
358
|
+
await encryptForPeer(owner, ownerLane, LINE, new TextEncoder().encode("first"));
|
|
359
|
+
const env = await encryptForPeer(owner, ownerLane, LINE, inner);
|
|
360
|
+
await ownerLane.send({
|
|
361
361
|
to: LINE,
|
|
362
|
-
threadId: `dm:${[
|
|
362
|
+
threadId: `dm:${[OWNER, LINE].sort().join(":")}`,
|
|
363
363
|
payload: env,
|
|
364
364
|
messageType: "txt",
|
|
365
|
-
recipientSelfPayload: await sealForPeerRecoverable(
|
|
365
|
+
recipientSelfPayload: await sealForPeerRecoverable(owner, lineBundle, inner),
|
|
366
366
|
});
|
|
367
|
-
const read = (await tool("mDM_list")({ contact_id:
|
|
368
|
-
expect(read.messages.find((m) => m.sender_identity_id ===
|
|
367
|
+
const read = (await tool("mDM_list")({ contact_id: OWNER }, gatewayRequest(b, LINE, KEY_A))) as ListOut;
|
|
368
|
+
expect(read.messages.find((m) => m.sender_identity_id === OWNER)?.text).toBe("instruction from the owner");
|
|
369
369
|
});
|
|
370
370
|
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
// (
|
|
371
|
+
// Drift guard against the app: the two rules this fix stands on, read from the app source
|
|
372
|
+
// on origin/main of the mosADD repo (MOSADD_WEB_REPO, else the default path below). Without that repo
|
|
373
|
+
// next to this one (e.g. CI without the sibling tree) the test is skipped, not blindly green.
|
|
374
374
|
const webRepo = process.env.MOSADD_WEB_REPO ?? "C:/Projects/mosADD";
|
|
375
375
|
const appSource = (path: string): string | null => {
|
|
376
376
|
try {
|
|
@@ -381,7 +381,7 @@ describe("mDM_send z MCP — czytelne na kazdym kluczu, prawdziwe powody w aplik
|
|
|
381
381
|
};
|
|
382
382
|
const mdmE2ee = appSource("apps/web/src/lib/mdmE2ee.ts");
|
|
383
383
|
const ircApi = appSource("apps/web/src/lib/ircApi.ts");
|
|
384
|
-
it.skipIf(!mdmE2ee || !ircApi)("
|
|
384
|
+
it.skipIf(!mdmE2ee || !ircApi)("app contract: `text` = reason agent, s1. = my own copy, agent = in the clear", () => {
|
|
385
385
|
expect(mdmE2ee).toContain('reason: msg.message_type === "text" ? "agent" : "device"');
|
|
386
386
|
expect(mdmE2ee).toContain("const kopiaDlaMnie = doSiebie || (!!msg.self_payload && msg.self_payload.startsWith(SELF_TAG));");
|
|
387
387
|
expect(mdmE2ee).toContain('const SELF_TAG = "s1.";');
|