@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.57
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 +15 -11
- package/README.md +152 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-IWUGKLDX.js → chunk-WEGSITAH.js} +30 -14
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/__tests__/blob-upload.test.ts +93 -93
- package/src/__tests__/channel-e2ee.test.ts +62 -62
- package/src/__tests__/flota-jawnie.test.ts +2 -2
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +217 -182
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +199 -199
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +259 -199
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -288
- package/src/crypto/mdm-session.ts +842 -842
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +162 -162
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +212 -202
- package/src/providers/supabase-voice.ts +103 -91
- package/src/server.ts +195 -195
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/channel-payload.ts +2 -2
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- package/src/tools/mdm-as-agent.ts +138 -126
- package/src/tools/mdm.ts +6 -4
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc-messages.ts +1 -1
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/presence.ts +442 -442
- package/src/tools/voice-format.ts +43 -28
- package/src/types.ts +121 -121
- package/src/voice/floor.ts +132 -132
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LANA PLIKOW — ŻYWA, NIE DOPISANA Z PAMIĘCI (16.09).
|
|
3
|
-
*
|
|
4
|
-
* Zmierzone PRZED poprawką, na żywym MCP (mcp.mosadd.com), 1 KB text/plain:
|
|
5
|
-
* mDM_send_file → "blob upload to file-blobs/dm-…/….txt failed: Bucket not found"
|
|
6
|
-
* mDM_send_voice → "blob upload to voice-blobs/dm-…/….webm failed: Bucket not found"
|
|
7
|
-
* Buckety `file-blobs` i `voice-blobs` NIE ISTNIEJĄ w projekcie — lista bucketów
|
|
8
|
-
* (16.09) to: secure_vault, brand_assets, chat-files, gemstone-models, voice-messages,
|
|
9
|
-
* chat-attachments, odyssey-media, raydio-media, voice-samples, mayl-attachments,
|
|
10
|
-
* rag-uploads, ptt-recordings, avatars, downloads, orb-media, founder-archive, krol-wrzutki.
|
|
11
|
-
*
|
|
12
|
-
* Dwa zamki, każdy pilnuje jednej połowy kontraktu z polityką RLS:
|
|
13
|
-
* 1. bucket, który istnieje I przyjmie ten JWT (chat-files / voice-messages);
|
|
14
|
-
* 2. ścieżka z `auth.uid()` jako PIERWSZYM segmentem, bo obie polityki INSERT
|
|
15
|
-
* sprawdzają dokładnie `(storage.foldername(name))[1] = auth.uid()`.
|
|
16
|
-
* Ścieżka bez segmentu użytkownika to wysyłka, która ZAWSZE padnie — i padnie
|
|
17
|
-
* komunikatem, który nie mówi dlaczego.
|
|
18
|
-
*/
|
|
19
|
-
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
20
|
-
|
|
21
|
-
const SUB = "05261c7d-f34a-4fb2-a0e0-0f85149eb0ce";
|
|
22
|
-
const THREAD = "dm-dbe85c4e-ec79-4e9a-a55d-7274e0e3296e-4cd1894d-b878-4fe4-b221-084419f7d225";
|
|
23
|
-
|
|
24
|
-
function jwt(sub: string | null): string {
|
|
25
|
-
const b64 = (o: unknown) => Buffer.from(JSON.stringify(o)).toString("base64url");
|
|
26
|
-
return `${b64({ alg: "HS256", typ: "JWT" })}.${b64(sub ? { sub, role: "authenticated" } : { role: "authenticated" })}.sig`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Co dokładnie poszło do magazynu — jedno miejsce prawdy dla obu zamków. */
|
|
30
|
-
let lastCall: { bucket: string; path: string; mime: string } | null = null;
|
|
31
|
-
let userJwt: string | undefined = jwt(SUB);
|
|
32
|
-
|
|
33
|
-
vi.mock("../providers/supabase.js", () => ({
|
|
34
|
-
readSupabaseEnv: () => ({ url: "https://x.supabase.co", anonKey: "anon", userJwt }),
|
|
35
|
-
getSupabase: () => ({
|
|
36
|
-
storage: {
|
|
37
|
-
from: (bucket: string) => ({
|
|
38
|
-
upload: async (path: string, _bytes: Uint8Array, opts: { contentType: string }) => {
|
|
39
|
-
lastCall = { bucket, path, mime: opts.contentType };
|
|
40
|
-
return { error: null };
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
const { uploadBlob, decodeBase64Body } = await import("../providers/blob-upload.js");
|
|
48
|
-
|
|
49
|
-
beforeEach(() => { lastCall = null; userJwt = jwt(SUB); });
|
|
50
|
-
|
|
51
|
-
describe("blob-upload — bucket i ścieżka, które polityka RLS naprawdę przyjmie", () => {
|
|
52
|
-
it("plik idzie do chat-files, a ścieżka zaczyna się od auth.uid()", async () => {
|
|
53
|
-
const desc = await uploadBlob({
|
|
54
|
-
kind: "file",
|
|
55
|
-
bytes: new Uint8Array([1, 2, 3]),
|
|
56
|
-
mime: "text/plain",
|
|
57
|
-
prefix: THREAD,
|
|
58
|
-
filename: "lana-plikow-test.txt",
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(lastCall!.bucket).toBe("chat-files");
|
|
62
|
-
expect(desc.bucket).toBe("chat-files");
|
|
63
|
-
const [uid, thread, file] = lastCall!.path.split("/");
|
|
64
|
-
expect(uid).toBe(SUB); // ← to sprawdza polityka INSERT
|
|
65
|
-
expect(thread).toBe(THREAD);
|
|
66
|
-
expect(file).toMatch(/^[0-9a-f-]{36}\.txt$/);
|
|
67
|
-
expect(desc.path).toBe(lastCall!.path);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("głos idzie do voice-messages (nie do nieistniejącego voice-blobs)", async () => {
|
|
71
|
-
const desc = await uploadBlob({ kind: "voice", bytes: new Uint8Array([1]), mime: "audio/webm", prefix: THREAD });
|
|
72
|
-
expect(lastCall!.bucket).toBe("voice-messages");
|
|
73
|
-
expect(desc.bucket).toBe("voice-messages");
|
|
74
|
-
expect(lastCall!.path.split("/")[0]).toBe(SUB);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("ptt też ląduje w buckecie, który istnieje i ma politykę INSERT", async () => {
|
|
78
|
-
await uploadBlob({ kind: "ptt", bytes: new Uint8Array([1]), mime: "audio/ogg", prefix: "chat-abc" });
|
|
79
|
-
expect(lastCall!.bucket).toBe("voice-messages");
|
|
80
|
-
expect(lastCall!.path).toMatch(new RegExp(`^${SUB}/chat-abc/[0-9a-f-]{36}\\.ogg$`));
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("bez JWT użytkownika upload jest ODRZUCONY, zanim poleci bajt", async () => {
|
|
84
|
-
userJwt = undefined;
|
|
85
|
-
await expect(uploadBlob({ kind: "file", bytes: new Uint8Array([1]), mime: "text/plain" }))
|
|
86
|
-
.rejects.toThrow(/auth\.uid\(\)/);
|
|
87
|
-
expect(lastCall).toBeNull(); // nic nie poszło do magazynu
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("ścieżka z pamięci przechodzi przez ten sam dekoder base64 (kontrakt narzędzi)", () => {
|
|
91
|
-
expect(new TextDecoder().decode(decodeBase64Body("VEVTVCAxNg=="))).toBe("TEST 16");
|
|
92
|
-
});
|
|
93
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* LANA PLIKOW — ŻYWA, NIE DOPISANA Z PAMIĘCI (16.09).
|
|
3
|
+
*
|
|
4
|
+
* Zmierzone PRZED poprawką, na żywym MCP (mcp.mosadd.com), 1 KB text/plain:
|
|
5
|
+
* mDM_send_file → "blob upload to file-blobs/dm-…/….txt failed: Bucket not found"
|
|
6
|
+
* mDM_send_voice → "blob upload to voice-blobs/dm-…/….webm failed: Bucket not found"
|
|
7
|
+
* Buckety `file-blobs` i `voice-blobs` NIE ISTNIEJĄ w projekcie — lista bucketów
|
|
8
|
+
* (16.09) to: secure_vault, brand_assets, chat-files, gemstone-models, voice-messages,
|
|
9
|
+
* chat-attachments, odyssey-media, raydio-media, voice-samples, mayl-attachments,
|
|
10
|
+
* rag-uploads, ptt-recordings, avatars, downloads, orb-media, founder-archive, krol-wrzutki.
|
|
11
|
+
*
|
|
12
|
+
* Dwa zamki, każdy pilnuje jednej połowy kontraktu z polityką RLS:
|
|
13
|
+
* 1. bucket, który istnieje I przyjmie ten JWT (chat-files / voice-messages);
|
|
14
|
+
* 2. ścieżka z `auth.uid()` jako PIERWSZYM segmentem, bo obie polityki INSERT
|
|
15
|
+
* sprawdzają dokładnie `(storage.foldername(name))[1] = auth.uid()`.
|
|
16
|
+
* Ścieżka bez segmentu użytkownika to wysyłka, która ZAWSZE padnie — i padnie
|
|
17
|
+
* komunikatem, który nie mówi dlaczego.
|
|
18
|
+
*/
|
|
19
|
+
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
20
|
+
|
|
21
|
+
const SUB = "05261c7d-f34a-4fb2-a0e0-0f85149eb0ce";
|
|
22
|
+
const THREAD = "dm-dbe85c4e-ec79-4e9a-a55d-7274e0e3296e-4cd1894d-b878-4fe4-b221-084419f7d225";
|
|
23
|
+
|
|
24
|
+
function jwt(sub: string | null): string {
|
|
25
|
+
const b64 = (o: unknown) => Buffer.from(JSON.stringify(o)).toString("base64url");
|
|
26
|
+
return `${b64({ alg: "HS256", typ: "JWT" })}.${b64(sub ? { sub, role: "authenticated" } : { role: "authenticated" })}.sig`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Co dokładnie poszło do magazynu — jedno miejsce prawdy dla obu zamków. */
|
|
30
|
+
let lastCall: { bucket: string; path: string; mime: string } | null = null;
|
|
31
|
+
let userJwt: string | undefined = jwt(SUB);
|
|
32
|
+
|
|
33
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
34
|
+
readSupabaseEnv: () => ({ url: "https://x.supabase.co", anonKey: "anon", userJwt }),
|
|
35
|
+
getSupabase: () => ({
|
|
36
|
+
storage: {
|
|
37
|
+
from: (bucket: string) => ({
|
|
38
|
+
upload: async (path: string, _bytes: Uint8Array, opts: { contentType: string }) => {
|
|
39
|
+
lastCall = { bucket, path, mime: opts.contentType };
|
|
40
|
+
return { error: null };
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const { uploadBlob, decodeBase64Body } = await import("../providers/blob-upload.js");
|
|
48
|
+
|
|
49
|
+
beforeEach(() => { lastCall = null; userJwt = jwt(SUB); });
|
|
50
|
+
|
|
51
|
+
describe("blob-upload — bucket i ścieżka, które polityka RLS naprawdę przyjmie", () => {
|
|
52
|
+
it("plik idzie do chat-files, a ścieżka zaczyna się od auth.uid()", async () => {
|
|
53
|
+
const desc = await uploadBlob({
|
|
54
|
+
kind: "file",
|
|
55
|
+
bytes: new Uint8Array([1, 2, 3]),
|
|
56
|
+
mime: "text/plain",
|
|
57
|
+
prefix: THREAD,
|
|
58
|
+
filename: "lana-plikow-test.txt",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(lastCall!.bucket).toBe("chat-files");
|
|
62
|
+
expect(desc.bucket).toBe("chat-files");
|
|
63
|
+
const [uid, thread, file] = lastCall!.path.split("/");
|
|
64
|
+
expect(uid).toBe(SUB); // ← to sprawdza polityka INSERT
|
|
65
|
+
expect(thread).toBe(THREAD);
|
|
66
|
+
expect(file).toMatch(/^[0-9a-f-]{36}\.txt$/);
|
|
67
|
+
expect(desc.path).toBe(lastCall!.path);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("głos idzie do voice-messages (nie do nieistniejącego voice-blobs)", async () => {
|
|
71
|
+
const desc = await uploadBlob({ kind: "voice", bytes: new Uint8Array([1]), mime: "audio/webm", prefix: THREAD });
|
|
72
|
+
expect(lastCall!.bucket).toBe("voice-messages");
|
|
73
|
+
expect(desc.bucket).toBe("voice-messages");
|
|
74
|
+
expect(lastCall!.path.split("/")[0]).toBe(SUB);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("ptt też ląduje w buckecie, który istnieje i ma politykę INSERT", async () => {
|
|
78
|
+
await uploadBlob({ kind: "ptt", bytes: new Uint8Array([1]), mime: "audio/ogg", prefix: "chat-abc" });
|
|
79
|
+
expect(lastCall!.bucket).toBe("voice-messages");
|
|
80
|
+
expect(lastCall!.path).toMatch(new RegExp(`^${SUB}/chat-abc/[0-9a-f-]{36}\\.ogg$`));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("bez JWT użytkownika upload jest ODRZUCONY, zanim poleci bajt", async () => {
|
|
84
|
+
userJwt = undefined;
|
|
85
|
+
await expect(uploadBlob({ kind: "file", bytes: new Uint8Array([1]), mime: "text/plain" }))
|
|
86
|
+
.rejects.toThrow(/auth\.uid\(\)/);
|
|
87
|
+
expect(lastCall).toBeNull(); // nic nie poszło do magazynu
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("ścieżka z pamięci przechodzi przez ten sam dekoder base64 (kontrakt narzędzi)", () => {
|
|
91
|
+
expect(new TextDecoder().decode(decodeBase64Body("VEVTVCAxNg=="))).toBe("TEST 16");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { generateGroupKey } from "@mosadd/crypto";
|
|
3
|
-
import {
|
|
4
|
-
decryptWithGroupKey,
|
|
5
|
-
encryptWithGroupKey,
|
|
6
|
-
signCiphertext,
|
|
7
|
-
unwrapEnvelopeText,
|
|
8
|
-
} from "../crypto/channel-e2ee.js";
|
|
9
|
-
|
|
10
|
-
const envelope = (text: string) =>
|
|
11
|
-
JSON.stringify({ v: "mosadd.chat.v1", type: "text", text, reply_to: null, sent_at: new Date().toISOString() });
|
|
12
|
-
|
|
13
|
-
describe("channel-e2ee pure core", () => {
|
|
14
|
-
it("roundtrip: encrypt → decrypt returns the original text", async () => {
|
|
15
|
-
const key = generateGroupKey();
|
|
16
|
-
const plain = envelope("Fala 4 żyje");
|
|
17
|
-
const payload = await encryptWithGroupKey(key, plain);
|
|
18
|
-
expect(typeof payload).toBe("string");
|
|
19
|
-
const out = await decryptWithGroupKey(key, payload);
|
|
20
|
-
expect(out).toBe(plain);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("decrypt of a legacy (non-JSON) payload returns null", async () => {
|
|
24
|
-
const key = generateGroupKey();
|
|
25
|
-
const legacy = Buffer.from(envelope("stara wiadomość"), "utf8").toString("base64");
|
|
26
|
-
expect(await decryptWithGroupKey(key, legacy)).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("tampered ciphertext fails the HMAC check and returns null", async () => {
|
|
30
|
-
const key = generateGroupKey();
|
|
31
|
-
const payload = await encryptWithGroupKey(key, envelope("nie ruszaj"));
|
|
32
|
-
const parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8")) as {
|
|
33
|
-
iv: string;
|
|
34
|
-
ciphertext: string;
|
|
35
|
-
hmac: string;
|
|
36
|
-
};
|
|
37
|
-
// flip one character of the ciphertext
|
|
38
|
-
parsed.ciphertext = (parsed.ciphertext[0] === "A" ? "B" : "A") + parsed.ciphertext.slice(1);
|
|
39
|
-
const tampered = Buffer.from(JSON.stringify(parsed), "utf8").toString("base64");
|
|
40
|
-
expect(await decryptWithGroupKey(key, tampered)).toBeNull();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("wrong key does not decrypt", async () => {
|
|
44
|
-
const keyA = generateGroupKey();
|
|
45
|
-
const keyB = generateGroupKey();
|
|
46
|
-
const payload = await encryptWithGroupKey(keyA, envelope("sekret"));
|
|
47
|
-
expect(await decryptWithGroupKey(keyB, payload)).toBeNull();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("HMAC is over the base64 ciphertext string (app parity 2C)", async () => {
|
|
51
|
-
const key = generateGroupKey();
|
|
52
|
-
const payload = await encryptWithGroupKey(key, "abc");
|
|
53
|
-
const parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8")) as { ciphertext: string; hmac: string };
|
|
54
|
-
expect(parsed.hmac).toBe(signCiphertext(key, parsed.ciphertext));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("unwrapEnvelopeText unwraps toolkit envelopes and leaves raw text", () => {
|
|
58
|
-
expect(unwrapEnvelopeText(envelope("witaj"))).toBe("witaj");
|
|
59
|
-
expect(unwrapEnvelopeText("zwykły tekst")).toBe("zwykły tekst");
|
|
60
|
-
expect(unwrapEnvelopeText('{"audio":"AAAA"}')).toBe('{"audio":"AAAA"}');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { generateGroupKey } from "@mosadd/crypto";
|
|
3
|
+
import {
|
|
4
|
+
decryptWithGroupKey,
|
|
5
|
+
encryptWithGroupKey,
|
|
6
|
+
signCiphertext,
|
|
7
|
+
unwrapEnvelopeText,
|
|
8
|
+
} from "../crypto/channel-e2ee.js";
|
|
9
|
+
|
|
10
|
+
const envelope = (text: string) =>
|
|
11
|
+
JSON.stringify({ v: "mosadd.chat.v1", type: "text", text, reply_to: null, sent_at: new Date().toISOString() });
|
|
12
|
+
|
|
13
|
+
describe("channel-e2ee pure core", () => {
|
|
14
|
+
it("roundtrip: encrypt → decrypt returns the original text", async () => {
|
|
15
|
+
const key = generateGroupKey();
|
|
16
|
+
const plain = envelope("Fala 4 żyje");
|
|
17
|
+
const payload = await encryptWithGroupKey(key, plain);
|
|
18
|
+
expect(typeof payload).toBe("string");
|
|
19
|
+
const out = await decryptWithGroupKey(key, payload);
|
|
20
|
+
expect(out).toBe(plain);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("decrypt of a legacy (non-JSON) payload returns null", async () => {
|
|
24
|
+
const key = generateGroupKey();
|
|
25
|
+
const legacy = Buffer.from(envelope("stara wiadomość"), "utf8").toString("base64");
|
|
26
|
+
expect(await decryptWithGroupKey(key, legacy)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("tampered ciphertext fails the HMAC check and returns null", async () => {
|
|
30
|
+
const key = generateGroupKey();
|
|
31
|
+
const payload = await encryptWithGroupKey(key, envelope("nie ruszaj"));
|
|
32
|
+
const parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8")) as {
|
|
33
|
+
iv: string;
|
|
34
|
+
ciphertext: string;
|
|
35
|
+
hmac: string;
|
|
36
|
+
};
|
|
37
|
+
// flip one character of the ciphertext
|
|
38
|
+
parsed.ciphertext = (parsed.ciphertext[0] === "A" ? "B" : "A") + parsed.ciphertext.slice(1);
|
|
39
|
+
const tampered = Buffer.from(JSON.stringify(parsed), "utf8").toString("base64");
|
|
40
|
+
expect(await decryptWithGroupKey(key, tampered)).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("wrong key does not decrypt", async () => {
|
|
44
|
+
const keyA = generateGroupKey();
|
|
45
|
+
const keyB = generateGroupKey();
|
|
46
|
+
const payload = await encryptWithGroupKey(keyA, envelope("sekret"));
|
|
47
|
+
expect(await decryptWithGroupKey(keyB, payload)).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("HMAC is over the base64 ciphertext string (app parity 2C)", async () => {
|
|
51
|
+
const key = generateGroupKey();
|
|
52
|
+
const payload = await encryptWithGroupKey(key, "abc");
|
|
53
|
+
const parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8")) as { ciphertext: string; hmac: string };
|
|
54
|
+
expect(parsed.hmac).toBe(signCiphertext(key, parsed.ciphertext));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("unwrapEnvelopeText unwraps toolkit envelopes and leaves raw text", () => {
|
|
58
|
+
expect(unwrapEnvelopeText(envelope("witaj"))).toBe("witaj");
|
|
59
|
+
expect(unwrapEnvelopeText("zwykły tekst")).toBe("zwykły tekst");
|
|
60
|
+
expect(unwrapEnvelopeText('{"audio":"AAAA"}')).toBe('{"audio":"AAAA"}');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ZAMEK „ZERO SZYFROWANIA Z FLOTA" (29.09.2026,
|
|
3
|
-
*
|
|
2
|
+
* ZAMEK „ZERO SZYFROWANIA Z FLOTA" (29.09.2026, owner decision 28.09: no encryption on agent-line
|
|
3
|
+
* conversations, in any channel or identity).
|
|
4
4
|
*
|
|
5
5
|
* Dwie reguly bramy MCP, obie zmierzone jako zepsute 28–29.09 (Public\ZERO-SZYFROWANIA-29-09,
|
|
6
6
|
* D1 §3 i S1 §1b):
|
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
|
|
3
|
-
*
|
|
4
|
-
* Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
|
|
5
|
-
* under mDM without mosadd-os knowing anything about that transport:
|
|
6
|
-
* 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
|
|
7
|
-
* (usable off-grid over radio),
|
|
8
|
-
* 2. host injects a fake RadioProvider,
|
|
9
|
-
* 3. agent calls mDM_send,
|
|
10
|
-
* 4. the opaque payload bytes actually arrive at the injected provider,
|
|
11
|
-
* 5. they round-trip back out via mDM_list.
|
|
12
|
-
*
|
|
13
|
-
* This is the "is it sp, not just written" check the whole 2144 task hinges on.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, expect, it } from "vitest";
|
|
17
|
-
import type {
|
|
18
|
-
DmProvider,
|
|
19
|
-
DmSendArgs,
|
|
20
|
-
DmListArgs,
|
|
21
|
-
DmSendResult,
|
|
22
|
-
DmListResult,
|
|
23
|
-
} from "@mosadd/providers";
|
|
24
|
-
import { mdmTools } from "../tools/mdm.js";
|
|
25
|
-
import { makeCapabilitiesTool } from "../tools/capabilities.js";
|
|
26
|
-
import { allTools } from "../tools/index.js";
|
|
27
|
-
import { createMosaddServer } from "../server.js";
|
|
28
|
-
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
29
|
-
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
30
|
-
import type { MosaddToolContext, ProviderRegistry } from "../types.js";
|
|
31
|
-
|
|
32
|
-
/** Stand-in for a host-supplied radio transport: captures the bytes it's asked
|
|
33
|
-
* to send, and replays them on list — i.e. "the message reached the link". */
|
|
34
|
-
class FakeRadioDmProvider implements DmProvider {
|
|
35
|
-
public readonly sent: DmSendArgs[] = [];
|
|
36
|
-
private bundle: Uint8Array | null = null;
|
|
37
|
-
async selfId(): Promise<string> {
|
|
38
|
-
return "radio:self-callsign";
|
|
39
|
-
}
|
|
40
|
-
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
41
|
-
this.sent.push(args);
|
|
42
|
-
return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
|
|
43
|
-
}
|
|
44
|
-
async list(args: DmListArgs): Promise<DmListResult> {
|
|
45
|
-
return {
|
|
46
|
-
messages: this.sent
|
|
47
|
-
.filter((s) => s.threadId === args.threadId)
|
|
48
|
-
.map((s, i) => ({
|
|
49
|
-
id: `radio-${i + 1}`,
|
|
50
|
-
senderId: "radio:self-callsign",
|
|
51
|
-
payload: s.payload,
|
|
52
|
-
timestamp: new Date(0).toISOString(),
|
|
53
|
-
threadId: s.threadId,
|
|
54
|
-
})),
|
|
55
|
-
nextCursor: null,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
59
|
-
this.bundle = bundle;
|
|
60
|
-
}
|
|
61
|
-
async fetchPrekeyBundle(): Promise<Uint8Array | null> {
|
|
62
|
-
return this.bundle;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
|
|
67
|
-
return {
|
|
68
|
-
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
69
|
-
providers: {
|
|
70
|
-
dm: providers.dm,
|
|
71
|
-
keys: providers.keys ?? new InMemoryMdmKeyStore(),
|
|
72
|
-
voice: new InMemoryVoiceProvider("radio:self-callsign"),
|
|
73
|
-
},
|
|
74
|
-
log: () => {},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const getTool = (name: string) => {
|
|
79
|
-
const t = mdmTools.find((x) => x.name === name);
|
|
80
|
-
if (!t) throw new Error(`tool ${name} not found`);
|
|
81
|
-
return t;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
describe("golden path — host injects transport under mDM", () => {
|
|
85
|
-
it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
|
|
86
|
-
const capTool = makeCapabilitiesTool(allTools);
|
|
87
|
-
const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
|
|
88
|
-
by_requirement: Record<string, string[]>;
|
|
89
|
-
};
|
|
90
|
-
expect(manifest.by_requirement.any).toContain("mDM_send");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
|
|
94
|
-
// This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
|
|
95
|
-
// plaintext envelope and the bytes reach the injected provider verbatim.
|
|
96
|
-
// (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
|
|
97
|
-
const radio = new FakeRadioDmProvider();
|
|
98
|
-
const ctx = makeCtx({ dm: radio });
|
|
99
|
-
|
|
100
|
-
const send = getTool("mDM_send_unencrypted");
|
|
101
|
-
const result = (await send.handler(
|
|
102
|
-
{ to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
|
|
103
|
-
ctx,
|
|
104
|
-
)) as { message_id: string; thread_id: string };
|
|
105
|
-
|
|
106
|
-
// The bytes actually reached the transport.
|
|
107
|
-
expect(radio.sent).toHaveLength(1);
|
|
108
|
-
expect(radio.sent[0]!.to).toBe("bob-callsign");
|
|
109
|
-
expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
|
|
110
|
-
expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
|
|
111
|
-
expect(result.message_id).toBe("radio-1");
|
|
112
|
-
|
|
113
|
-
// The payload is opaque to the provider but carries our text under the hood.
|
|
114
|
-
// 2026-08-25: plaintext lane is RAW utf8 text (native app format), not a JSON
|
|
115
|
-
// envelope — packPlaintextPayload change, unpack tolerates both shapes.
|
|
116
|
-
const decoded = Buffer.from(radio.sent[0]!.payload).toString("utf8");
|
|
117
|
-
expect(decoded).toBe("rendezvous at grid 4471, 0600");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("step 5: mDM_list round-trips the message back through the same provider", async () => {
|
|
121
|
-
const radio = new FakeRadioDmProvider();
|
|
122
|
-
const ctx = makeCtx({ dm: radio });
|
|
123
|
-
|
|
124
|
-
await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
|
|
125
|
-
const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
|
|
126
|
-
messages: Array<{ text: string }>;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
expect(listed.messages).toHaveLength(1);
|
|
130
|
-
expect(listed.messages[0]!.text).toBe("ack");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("default server wires a DmProvider without a host override (no throw)", () => {
|
|
134
|
-
// Network default path: constructing the server must not require a host to
|
|
135
|
-
// inject anything (it falls back to the Supabase adapter).
|
|
136
|
-
expect(() => createMosaddServer()).not.toThrow();
|
|
137
|
-
expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
|
|
3
|
+
*
|
|
4
|
+
* Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
|
|
5
|
+
* under mDM without mosadd-os knowing anything about that transport:
|
|
6
|
+
* 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
|
|
7
|
+
* (usable off-grid over radio),
|
|
8
|
+
* 2. host injects a fake RadioProvider,
|
|
9
|
+
* 3. agent calls mDM_send,
|
|
10
|
+
* 4. the opaque payload bytes actually arrive at the injected provider,
|
|
11
|
+
* 5. they round-trip back out via mDM_list.
|
|
12
|
+
*
|
|
13
|
+
* This is the "is it sp, not just written" check the whole 2144 task hinges on.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
import type {
|
|
18
|
+
DmProvider,
|
|
19
|
+
DmSendArgs,
|
|
20
|
+
DmListArgs,
|
|
21
|
+
DmSendResult,
|
|
22
|
+
DmListResult,
|
|
23
|
+
} from "@mosadd/providers";
|
|
24
|
+
import { mdmTools } from "../tools/mdm.js";
|
|
25
|
+
import { makeCapabilitiesTool } from "../tools/capabilities.js";
|
|
26
|
+
import { allTools } from "../tools/index.js";
|
|
27
|
+
import { createMosaddServer } from "../server.js";
|
|
28
|
+
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
29
|
+
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
30
|
+
import type { MosaddToolContext, ProviderRegistry } from "../types.js";
|
|
31
|
+
|
|
32
|
+
/** Stand-in for a host-supplied radio transport: captures the bytes it's asked
|
|
33
|
+
* to send, and replays them on list — i.e. "the message reached the link". */
|
|
34
|
+
class FakeRadioDmProvider implements DmProvider {
|
|
35
|
+
public readonly sent: DmSendArgs[] = [];
|
|
36
|
+
private bundle: Uint8Array | null = null;
|
|
37
|
+
async selfId(): Promise<string> {
|
|
38
|
+
return "radio:self-callsign";
|
|
39
|
+
}
|
|
40
|
+
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
41
|
+
this.sent.push(args);
|
|
42
|
+
return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
|
|
43
|
+
}
|
|
44
|
+
async list(args: DmListArgs): Promise<DmListResult> {
|
|
45
|
+
return {
|
|
46
|
+
messages: this.sent
|
|
47
|
+
.filter((s) => s.threadId === args.threadId)
|
|
48
|
+
.map((s, i) => ({
|
|
49
|
+
id: `radio-${i + 1}`,
|
|
50
|
+
senderId: "radio:self-callsign",
|
|
51
|
+
payload: s.payload,
|
|
52
|
+
timestamp: new Date(0).toISOString(),
|
|
53
|
+
threadId: s.threadId,
|
|
54
|
+
})),
|
|
55
|
+
nextCursor: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
59
|
+
this.bundle = bundle;
|
|
60
|
+
}
|
|
61
|
+
async fetchPrekeyBundle(): Promise<Uint8Array | null> {
|
|
62
|
+
return this.bundle;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
|
|
67
|
+
return {
|
|
68
|
+
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
69
|
+
providers: {
|
|
70
|
+
dm: providers.dm,
|
|
71
|
+
keys: providers.keys ?? new InMemoryMdmKeyStore(),
|
|
72
|
+
voice: new InMemoryVoiceProvider("radio:self-callsign"),
|
|
73
|
+
},
|
|
74
|
+
log: () => {},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const getTool = (name: string) => {
|
|
79
|
+
const t = mdmTools.find((x) => x.name === name);
|
|
80
|
+
if (!t) throw new Error(`tool ${name} not found`);
|
|
81
|
+
return t;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
describe("golden path — host injects transport under mDM", () => {
|
|
85
|
+
it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
|
|
86
|
+
const capTool = makeCapabilitiesTool(allTools);
|
|
87
|
+
const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
|
|
88
|
+
by_requirement: Record<string, string[]>;
|
|
89
|
+
};
|
|
90
|
+
expect(manifest.by_requirement.any).toContain("mDM_send");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
|
|
94
|
+
// This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
|
|
95
|
+
// plaintext envelope and the bytes reach the injected provider verbatim.
|
|
96
|
+
// (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
|
|
97
|
+
const radio = new FakeRadioDmProvider();
|
|
98
|
+
const ctx = makeCtx({ dm: radio });
|
|
99
|
+
|
|
100
|
+
const send = getTool("mDM_send_unencrypted");
|
|
101
|
+
const result = (await send.handler(
|
|
102
|
+
{ to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
|
|
103
|
+
ctx,
|
|
104
|
+
)) as { message_id: string; thread_id: string };
|
|
105
|
+
|
|
106
|
+
// The bytes actually reached the transport.
|
|
107
|
+
expect(radio.sent).toHaveLength(1);
|
|
108
|
+
expect(radio.sent[0]!.to).toBe("bob-callsign");
|
|
109
|
+
expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
|
|
110
|
+
expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
|
|
111
|
+
expect(result.message_id).toBe("radio-1");
|
|
112
|
+
|
|
113
|
+
// The payload is opaque to the provider but carries our text under the hood.
|
|
114
|
+
// 2026-08-25: plaintext lane is RAW utf8 text (native app format), not a JSON
|
|
115
|
+
// envelope — packPlaintextPayload change, unpack tolerates both shapes.
|
|
116
|
+
const decoded = Buffer.from(radio.sent[0]!.payload).toString("utf8");
|
|
117
|
+
expect(decoded).toBe("rendezvous at grid 4471, 0600");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("step 5: mDM_list round-trips the message back through the same provider", async () => {
|
|
121
|
+
const radio = new FakeRadioDmProvider();
|
|
122
|
+
const ctx = makeCtx({ dm: radio });
|
|
123
|
+
|
|
124
|
+
await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
|
|
125
|
+
const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
|
|
126
|
+
messages: Array<{ text: string }>;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
expect(listed.messages).toHaveLength(1);
|
|
130
|
+
expect(listed.messages[0]!.text).toBe("ack");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("default server wires a DmProvider without a host override (no throw)", () => {
|
|
134
|
+
// Network default path: constructing the server must not require a host to
|
|
135
|
+
// inject anything (it falls back to the Supabase adapter).
|
|
136
|
+
expect(() => createMosaddServer()).not.toThrow();
|
|
137
|
+
expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
|
|
138
|
+
});
|
|
139
|
+
});
|