@fedify/fedify 2.2.19 → 2.2.21

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.
Files changed (109) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
  15. package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
  16. package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/docloader-Bogpjg4d.mjs +125 -0
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1567 -30
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +723 -68
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
  38. package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
  39. package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
  40. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  41. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  42. package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
  45. package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
  46. package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
  49. package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
  52. package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
  53. package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
  58. package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +764 -18
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/otel/exporter.test.mjs +292 -30
  71. package/dist/otel/mod.cjs +36 -30
  72. package/dist/otel/mod.d.cts +13 -0
  73. package/dist/otel/mod.d.ts +13 -0
  74. package/dist/otel/mod.js +36 -30
  75. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  76. package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
  77. package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
  78. package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  79. package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
  80. package/dist/send-CAdpwbFX.mjs +416 -0
  81. package/dist/sig/http.test.mjs +528 -2
  82. package/dist/sig/key-types.test.d.mts +218 -0
  83. package/dist/sig/key-types.test.mjs +8 -0
  84. package/dist/sig/key.test.mjs +2 -2
  85. package/dist/sig/ld.test.mjs +573 -8
  86. package/dist/sig/mod.cjs +2 -2
  87. package/dist/sig/mod.d.cts +3 -3
  88. package/dist/sig/mod.d.ts +3 -3
  89. package/dist/sig/mod.js +2 -2
  90. package/dist/sig/owner.test.mjs +1 -1
  91. package/dist/sig/proof.test.mjs +96 -4
  92. package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
  93. package/dist/testing/mod.d.mts +1 -2396
  94. package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
  95. package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
  96. package/dist/utils/docloader.test.mjs +318 -34
  97. package/dist/utils/mod.cjs +1 -1
  98. package/dist/utils/mod.d.cts +1 -1
  99. package/dist/utils/mod.d.ts +1 -1
  100. package/dist/utils/mod.js +1 -1
  101. package/package.json +6 -6
  102. package/dist/docloader-D1ghurDJ.mjs +0 -83
  103. package/dist/send-D35Va72B.mjs +0 -260
  104. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  105. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  106. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  107. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  108. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  109. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -0,0 +1,182 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-DNZ4Liil.mjs";
6
+ import { t as assert } from "../assert-BhQd8QHP.mjs";
7
+ import { n as ed25519PrivateKey, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
8
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
9
+ import { a as verifyProof, r as signObject } from "../proof-C63Hqt9N.mjs";
10
+ import { h as respondWithObjectIfAcceptable, m as respondWithObject, o as createFederation } from "../middleware-dlGvSrXl.mjs";
11
+ import { mockDocumentLoader, test } from "@fedify/fixture";
12
+ import { Note, Object as Object$1, OrderedCollection, PropertyValue, Service, Update } from "@fedify/vocab";
13
+ //#region src/federation/attachment-responses.test.ts
14
+ const ACCEPTS = ["application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""];
15
+ function profile(count) {
16
+ return new Service({
17
+ id: new URL("https://example.com/actors/app"),
18
+ preferredUsername: "app",
19
+ attachments: Array.from({ length: count }, (_, i) => new PropertyValue({
20
+ name: `Field ${i}`,
21
+ value: `https://example.com/${i}`
22
+ }))
23
+ });
24
+ }
25
+ function attachmentValues(value) {
26
+ if (Array.isArray(value)) return value.flatMap(attachmentValues);
27
+ if (typeof value !== "object" || value == null) return [];
28
+ return Object.entries(value).flatMap(([key, item]) => key === "@context" ? [] : key === "attachment" ? [item] : attachmentValues(item));
29
+ }
30
+ test("attachment responses: actor, object, collections and pages negotiate both media types", async () => {
31
+ for (const count of [1, 2]) {
32
+ const actor = profile(count);
33
+ const update = new Update({
34
+ id: new URL("https://example.com/updates/1"),
35
+ actor: actor.id,
36
+ object: actor
37
+ });
38
+ const federation = createFederation({ kv: new MemoryKvStore() });
39
+ federation.setActorDispatcher("/actors/{identifier}", () => actor);
40
+ federation.setObjectDispatcher(Note, "/notes/{id}", () => new Note({ attachments: Array.from({ length: count }, () => new Note({ content: "attachment" })) }));
41
+ federation.setFollowersDispatcher("/actors/{identifier}/followers", () => ({ items: [actor] }));
42
+ federation.setCollectionDispatcher("objects", Object$1, "/collections/{id}", () => ({ items: [update] }));
43
+ federation.setOrderedCollectionDispatcher("ordered", Object$1, "/ordered/{id}", () => ({ items: [update] }));
44
+ for (const accept of ACCEPTS) for (const path of [
45
+ "/actors/app",
46
+ "/notes/1",
47
+ "/actors/app/followers",
48
+ "/actors/app/followers?cursor=a",
49
+ "/collections/1",
50
+ "/collections/1?cursor=a",
51
+ "/ordered/1",
52
+ "/ordered/1?cursor=a"
53
+ ]) {
54
+ const response = await federation.fetch(new Request(`https://example.com${path}`, { headers: { Accept: accept } }), { contextData: void 0 });
55
+ assertEquals(response.status, 200, path);
56
+ assertEquals(response.headers.get("Content-Type"), "application/activity+json");
57
+ assertEquals(response.headers.get("Vary"), "Accept");
58
+ const values = attachmentValues(await response.json());
59
+ assert(values.length > 0, path);
60
+ for (const value of values) {
61
+ assert(Array.isArray(value), path);
62
+ assertEquals(value.length, count, path);
63
+ }
64
+ }
65
+ }
66
+ });
67
+ test("attachment responses: helpers normalize without changing the vocabulary cache", async () => {
68
+ const json = await profile(1).toJsonLd();
69
+ const actor = await Service.fromJsonLd(json, { contextLoader: mockDocumentLoader });
70
+ const before = structuredClone(await actor.toJsonLd());
71
+ for (const options of [void 0, { contextLoader: mockDocumentLoader }]) {
72
+ const response = await respondWithObject(actor, options);
73
+ assert(Array.isArray((await response.json()).attachment));
74
+ for (const accept of ACCEPTS) {
75
+ const acceptable = await respondWithObjectIfAcceptable(actor, new Request("https://example.com/", { headers: { Accept: accept } }), options);
76
+ assert(acceptable != null);
77
+ assert(Array.isArray((await acceptable.json()).attachment));
78
+ assertEquals(acceptable.headers.get("Vary"), "Accept");
79
+ }
80
+ }
81
+ assertEquals(await actor.toJsonLd(), before);
82
+ assertEquals(await respondWithObjectIfAcceptable(actor, new Request("https://example.com/", { headers: { Accept: "text/html" } })), null);
83
+ });
84
+ test("attachment responses: cached actor with deep JSON data remains servable", async () => {
85
+ let data = "leaf";
86
+ for (let i = 0; i < 70; i++) data = { child: data };
87
+ const original = {
88
+ "@context": ["https://www.w3.org/ns/activitystreams", { data: {
89
+ "@id": "https://example.com/data",
90
+ "@type": "@json"
91
+ } }],
92
+ type: "Service",
93
+ id: "https://example.com/actors/app",
94
+ preferredUsername: "app",
95
+ attachment: {
96
+ type: "Note",
97
+ content: "cached attachment"
98
+ },
99
+ data
100
+ };
101
+ const actor = await Service.fromJsonLd(original, { contextLoader: mockDocumentLoader });
102
+ const before = structuredClone(await actor.toJsonLd());
103
+ const federation = createFederation({ kv: new MemoryKvStore() });
104
+ federation.setActorDispatcher("/actors/{identifier}", () => actor);
105
+ for (const accept of ACCEPTS) {
106
+ const response = await federation.fetch(new Request("https://example.com/actors/app", { headers: { Accept: accept } }), { contextData: void 0 });
107
+ assertEquals(response.status, 200);
108
+ assertEquals(await response.json(), before);
109
+ }
110
+ assertEquals(await actor.toJsonLd(), before);
111
+ });
112
+ test("attachment responses: uncached collections serve unsigned cached children with deep or large JSON data", async () => {
113
+ let deep = "leaf";
114
+ for (let i = 0; i < 70; i++) deep = { child: deep };
115
+ for (const data of [deep, Array.from({ length: 100001 }, () => "leaf")]) {
116
+ const original = {
117
+ "@context": ["https://www.w3.org/ns/activitystreams", { data: {
118
+ "@id": "https://example.com/data",
119
+ "@type": "@json"
120
+ } }],
121
+ type: "Note",
122
+ id: "https://example.com/notes/cached",
123
+ content: "unsigned cached child",
124
+ data
125
+ };
126
+ const note = await Note.fromJsonLd(original, { contextLoader: mockDocumentLoader });
127
+ const before = structuredClone(await note.toJsonLd());
128
+ const collection = new OrderedCollection({ items: [note] });
129
+ const options = { contextLoader: mockDocumentLoader };
130
+ const serialized = structuredClone(await collection.toJsonLd(options));
131
+ for (const response of [await respondWithObject(collection, options), ...await Promise.all(ACCEPTS.map((accept) => respondWithObjectIfAcceptable(collection, new Request("https://example.com/", { headers: { Accept: accept } }), options)))]) {
132
+ assert(response != null);
133
+ assertEquals(response.status, 200);
134
+ assertEquals(await response.json(), serialized);
135
+ }
136
+ assertEquals(await note.toJsonLd(), before);
137
+ }
138
+ });
139
+ test("attachment responses: large cached collection remains servable", async () => {
140
+ const original = {
141
+ "@context": "https://www.w3.org/ns/activitystreams",
142
+ type: "OrderedCollection",
143
+ id: "https://example.com/collection",
144
+ orderedItems: Array.from({ length: 100001 }, (_, i) => `https://example.com/items/${i}`)
145
+ };
146
+ const collection = await OrderedCollection.fromJsonLd(original, { contextLoader: mockDocumentLoader });
147
+ const before = structuredClone(await collection.toJsonLd());
148
+ const response = await respondWithObject(collection, { contextLoader: mockDocumentLoader });
149
+ assertEquals(response.status, 200);
150
+ assertEquals(await response.json(), before);
151
+ assertEquals(await collection.toJsonLd(), before);
152
+ });
153
+ test("attachment responses: cached signed roots pass through without invalidating their JCS proof", async () => {
154
+ const signed = await signObject(new Note({
155
+ id: new URL("https://example.com/notes/signed"),
156
+ attachments: [new Note({ content: "signed attachment" })]
157
+ }), ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader });
158
+ const json = await signed.toJsonLd({
159
+ format: "compact",
160
+ contextLoader: mockDocumentLoader
161
+ });
162
+ const cached = await Note.fromJsonLd(json, { contextLoader: mockDocumentLoader });
163
+ const proofs = [];
164
+ for await (const proof of signed.getProofs()) proofs.push(proof);
165
+ assertEquals(proofs.length, 1);
166
+ const verification = {
167
+ contextLoader: mockDocumentLoader,
168
+ documentLoader: mockDocumentLoader
169
+ };
170
+ assert(await verifyProof(json, proofs[0], verification) != null);
171
+ const options = { contextLoader: mockDocumentLoader };
172
+ for (const response of [await respondWithObject(cached, options), ...await Promise.all(ACCEPTS.map((accept) => respondWithObjectIfAcceptable(cached, new Request("https://example.com/", { headers: { Accept: accept } }), options)))]) {
173
+ assert(response != null);
174
+ assertEquals(response.status, 200);
175
+ const body = await response.json();
176
+ assertEquals(body, json);
177
+ assert(await verifyProof(body, proofs[0], verification) != null);
178
+ }
179
+ assertEquals(await cached.toJsonLd(), json);
180
+ });
181
+ //#endregion
182
+ export {};
@@ -7,7 +7,7 @@ import { r as assertExists } from "../std__assert-DNZ4Liil.mjs";
7
7
  import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
8
8
  import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
9
9
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
10
- import { n as createFederationBuilder } from "../builder-UmydCxtK.mjs";
10
+ import { n as createFederationBuilder } from "../builder-4ImvtjG4.mjs";
11
11
  import { test } from "@fedify/fixture";
12
12
  import { Activity, Note, Person } from "@fedify/vocab";
13
13
  //#region src/federation/builder.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-DNZ4Liil.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-D-HqUuA2.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-CA3V5zyK.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
9
9
  //#region src/federation/collection.test.ts
@@ -0,0 +1,2 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
@@ -0,0 +1,288 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
+ import "../std__assert-DNZ4Liil.mjs";
7
+ import { t as assert } from "../assert-BhQd8QHP.mjs";
8
+ import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-BAK-tUlf.mjs";
9
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
10
+ import { c as detachSignature, v as verifySignature } from "../ld-DTeykI0e.mjs";
11
+ import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-DHf_DYXp.mjs";
12
+ import { r as signObject } from "../proof-C63Hqt9N.mjs";
13
+ import { b as prepareActivityJsonLd, n as FederationImpl, t as ContextImpl } from "../middleware-dlGvSrXl.mjs";
14
+ import { mockDocumentLoader, test } from "@fedify/fixture";
15
+ import { Create, Image, Note, PUBLIC_COLLECTION, Person, PropertyValue, Update } from "@fedify/vocab";
16
+ import { decodeMultibase } from "@fedify/vocab-runtime";
17
+ import serialize from "json-canon";
18
+ //#region src/federation/delivery-attachments.test.ts
19
+ async function assertRawProof(document, proof, publicKey) {
20
+ const unsigned = { ...document };
21
+ delete unsigned.proof;
22
+ delete unsigned.signature;
23
+ const encoder = new TextEncoder();
24
+ const config = {
25
+ "@context": document["@context"],
26
+ type: "DataIntegrityProof",
27
+ cryptosuite: proof.cryptosuite,
28
+ verificationMethod: proof.verificationMethod,
29
+ proofPurpose: proof.proofPurpose,
30
+ created: proof.created
31
+ };
32
+ const configDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(config)));
33
+ const messageDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(unsigned)));
34
+ const bytes = new Uint8Array(configDigest.byteLength + messageDigest.byteLength);
35
+ bytes.set(new Uint8Array(configDigest));
36
+ bytes.set(new Uint8Array(messageDigest), configDigest.byteLength);
37
+ assert(await crypto.subtle.verify("Ed25519", publicKey, decodeMultibase(proof.proofValue).slice(), bytes), "The proof must cover the exact received JSON representation.");
38
+ }
39
+ test("attachment delivery keeps fetched profiles, proofs, and queued bytes consistent", async (t) => {
40
+ const secondEdKey = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
41
+ const inbox = "https://example.com/attachment-inbox";
42
+ const received = [];
43
+ let responseStatus = 202;
44
+ esm_default.spyGlobal();
45
+ esm_default.post(inbox, async ({ request }) => {
46
+ received.push(await request.json());
47
+ return new Response(null, { status: responseStatus });
48
+ });
49
+ try {
50
+ for (const scenario of [
51
+ "rsa",
52
+ "immediate",
53
+ "outbox",
54
+ "fanout",
55
+ "raw-fanout",
56
+ "raw-immediate",
57
+ "raw-outbox",
58
+ "rsa-fanout",
59
+ "retry"
60
+ ]) await t.step(scenario, async () => {
61
+ const messages = [];
62
+ const federation = new FederationImpl({
63
+ kv: new MemoryKvStore(),
64
+ queue: {
65
+ enqueue(message) {
66
+ messages.push(message);
67
+ return Promise.resolve();
68
+ },
69
+ async listen() {}
70
+ },
71
+ manuallyStartQueue: true,
72
+ allowPrivateAddress: true
73
+ });
74
+ federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => new Person({
75
+ id: ctx.getActorUri(identifier),
76
+ preferredUsername: identifier,
77
+ attachments: [new PropertyValue({
78
+ name: "Website",
79
+ value: "https://example.com/"
80
+ })]
81
+ })).setKeyPairsDispatcher(() => [{
82
+ privateKey: rsaPrivateKey2,
83
+ publicKey: rsaPublicKey2.publicKey
84
+ }, ...scenario.startsWith("rsa") ? [] : [{
85
+ privateKey: ed25519PrivateKey,
86
+ publicKey: ed25519PublicKey.publicKey
87
+ }, {
88
+ privateKey: secondEdKey.privateKey,
89
+ publicKey: secondEdKey.publicKey
90
+ }]]);
91
+ const ctx = new ContextImpl({
92
+ data: void 0,
93
+ federation,
94
+ url: new URL("https://example.com/"),
95
+ documentLoader: mockDocumentLoader,
96
+ contextLoader: mockDocumentLoader
97
+ });
98
+ const actor = new Person({
99
+ id: ctx.getActorUri("alice"),
100
+ preferredUsername: "alice",
101
+ attachments: [new PropertyValue({
102
+ name: "Website",
103
+ value: "https://example.com/"
104
+ })]
105
+ });
106
+ const fetched = await (await federation.fetch(new Request(ctx.getActorUri("alice"), { headers: { Accept: "application/activity+json" } }), { contextData: void 0 })).json();
107
+ assert(Array.isArray(fetched.attachment));
108
+ const keyPairs = await ctx.getActorKeyPairs("alice");
109
+ const start = received.length;
110
+ await ctx.sendActivity(scenario.startsWith("raw-") ? keyPairs.map((kp) => ({
111
+ privateKey: kp.privateKey,
112
+ keyId: kp.keyId
113
+ })) : { identifier: "alice" }, {
114
+ id: new URL("https://example.com/recipient"),
115
+ inboxId: new URL(inbox)
116
+ }, new Update({
117
+ id: new URL(`https://example.com/updates/${scenario}`),
118
+ actor: actor.id,
119
+ object: actor,
120
+ tos: [PUBLIC_COLLECTION]
121
+ }), scenario === "immediate" || scenario === "raw-immediate" || scenario === "rsa" ? { immediate: true } : scenario === "fanout" || scenario === "raw-fanout" || scenario === "rsa-fanout" ? { fanout: "force" } : {});
122
+ if (scenario === "retry") {
123
+ const first = messages.shift();
124
+ assert(first?.type === "outbox");
125
+ const original = structuredClone(first.activity);
126
+ responseStatus = 503;
127
+ await federation.processQueuedTask(void 0, first);
128
+ responseStatus = 202;
129
+ const retried = messages[0];
130
+ assert(retried?.type === "outbox");
131
+ assertEquals(retried.attempt, 1);
132
+ assertEquals(retried.activity, original);
133
+ }
134
+ for (let count = 0; messages.length > 0; count++) {
135
+ assert(count < 10, "The delivery queue must drain.");
136
+ await federation.processQueuedTask(void 0, messages.shift());
137
+ }
138
+ assert(received.length > start);
139
+ const delivered = received.at(-1);
140
+ assertEquals(delivered.object.attachment, fetched.attachment);
141
+ assert(await verifySignature(delivered, {
142
+ contextLoader: mockDocumentLoader,
143
+ keyCache: {
144
+ get(id) {
145
+ return Promise.resolve(keyPairs.find((kp) => kp.cryptographicKey.id?.href === id.href)?.cryptographicKey ?? null);
146
+ },
147
+ async set() {}
148
+ }
149
+ }));
150
+ const wire = detachSignature(delivered);
151
+ assertEquals(wire.to, PUBLIC_COLLECTION.href);
152
+ const proofs = wire.proof == null ? [] : Array.isArray(wire.proof) ? wire.proof : [wire.proof];
153
+ assertEquals(proofs.length, scenario.startsWith("rsa") ? 0 : 2);
154
+ for (const proof of proofs) {
155
+ const key = keyPairs.find((kp) => kp.multikey.id?.href === proof.verificationMethod || kp.keyId.href === proof.verificationMethod);
156
+ assert(key != null);
157
+ await assertRawProof(wire, proof, key.publicKey);
158
+ }
159
+ if (scenario === "retry") assertEquals(received.at(-2), received.at(-1));
160
+ });
161
+ } finally {
162
+ esm_default.unmockGlobal();
163
+ esm_default.removeRoutes();
164
+ esm_default.clearHistory();
165
+ }
166
+ });
167
+ test("public attachment proofs cover the normalized 2.2 wire representation", async () => {
168
+ const signed = await signObject(new Create({
169
+ actor: new URL("https://example.com/actor"),
170
+ object: new Note({ attachments: [new Image({ url: new URL("https://example.com/image.png") })] })
171
+ }), ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
172
+ const raw = await signed.toJsonLd({
173
+ format: "compact",
174
+ contextLoader: mockDocumentLoader
175
+ });
176
+ assert(!Array.isArray(raw.object.attachment));
177
+ const normalized = await normalizeOutgoingActivityJsonLd(raw, mockDocumentLoader);
178
+ await assertRawProof(normalized, normalized.proof, ed25519PublicKey.publicKey);
179
+ const resignedJson = await (await signObject(signed, ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader })).toJsonLd({
180
+ format: "compact",
181
+ contextLoader: mockDocumentLoader
182
+ });
183
+ assert(!Array.isArray(resignedJson.object.attachment));
184
+ assert(Array.isArray(resignedJson.proof));
185
+ assertEquals(resignedJson.proof.length, 2);
186
+ const resignedWire = await normalizeOutgoingActivityJsonLd(resignedJson, mockDocumentLoader);
187
+ for (const proof of resignedJson.proof) await assertRawProof(resignedWire, proof, ed25519PublicKey.publicKey);
188
+ });
189
+ test("delivery preparation only selects changed proof-free attachment JSON", async () => {
190
+ assertEquals(await prepareActivityJsonLd(new Create({
191
+ actor: new URL("https://example.com/actor"),
192
+ object: new Note({ content: "No attachments" })
193
+ }), mockDocumentLoader), void 0);
194
+ const child = new Note({ attachments: [new Image({ url: new URL("https://example.com/image.png") })] });
195
+ const activity = new Create({
196
+ actor: new URL("https://example.com/actor"),
197
+ object: child
198
+ });
199
+ const before = structuredClone(await activity.toJsonLd());
200
+ const childBefore = structuredClone(await child.toJsonLd());
201
+ const prepared = await prepareActivityJsonLd(activity, mockDocumentLoader);
202
+ assert(prepared != null);
203
+ assert(Array.isArray(prepared.object.attachment));
204
+ assertEquals(await activity.toJsonLd(), before);
205
+ assertEquals(await child.toJsonLd(), childBefore);
206
+ const signedChild = await signObject(child, ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
207
+ assertEquals(await prepareActivityJsonLd(new Create({
208
+ actor: activity.actorId,
209
+ object: signedChild
210
+ }), mockDocumentLoader), void 0);
211
+ });
212
+ test("existing root proofs retain 2.2 signing with normalization opted in", async (t) => {
213
+ const inbox = "https://example.com/existing-proof-inbox";
214
+ let delivered;
215
+ esm_default.spyGlobal();
216
+ esm_default.post(inbox, async ({ request }) => {
217
+ delivered = await request.json();
218
+ return new Response(null, { status: 202 });
219
+ });
220
+ try {
221
+ for (const sender of ["actor", "raw"]) await t.step(sender, async () => {
222
+ const federation = new FederationImpl({
223
+ kv: new MemoryKvStore(),
224
+ allowPrivateAddress: true
225
+ });
226
+ federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => new Person({ id: ctx.getActorUri(identifier) })).setKeyPairsDispatcher(() => [{
227
+ privateKey: rsaPrivateKey2,
228
+ publicKey: rsaPublicKey2.publicKey
229
+ }, {
230
+ privateKey: ed25519PrivateKey,
231
+ publicKey: ed25519PublicKey.publicKey
232
+ }]);
233
+ const ctx = new ContextImpl({
234
+ data: void 0,
235
+ federation,
236
+ url: new URL("https://example.com/"),
237
+ documentLoader: mockDocumentLoader,
238
+ contextLoader: mockDocumentLoader
239
+ });
240
+ const activity = await signObject(new Update({
241
+ id: new URL(`https://example.com/existing-proof/${sender}`),
242
+ actor: ctx.getActorUri("alice"),
243
+ object: new Person({
244
+ id: ctx.getActorUri("alice"),
245
+ attachments: [new PropertyValue({
246
+ name: "Site",
247
+ value: "example"
248
+ })]
249
+ })
250
+ }), ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
251
+ const before = structuredClone(await activity.toJsonLd());
252
+ assertEquals(await prepareActivityJsonLd(activity, mockDocumentLoader), void 0);
253
+ await ctx.sendActivity(sender === "actor" ? { identifier: "alice" } : [{
254
+ privateKey: rsaPrivateKey2,
255
+ keyId: rsaPublicKey2.id
256
+ }, {
257
+ privateKey: ed25519PrivateKey,
258
+ keyId: ed25519PublicKey.id
259
+ }], {
260
+ id: new URL("https://example.com/recipient"),
261
+ inboxId: new URL(inbox)
262
+ }, activity, {
263
+ immediate: true,
264
+ normalizeExistingProofs: true
265
+ });
266
+ assert(delivered != null);
267
+ assert(Array.isArray(delivered.object.attachment));
268
+ assert(await verifySignature(delivered, {
269
+ contextLoader: mockDocumentLoader,
270
+ keyCache: {
271
+ get: () => Promise.resolve(rsaPublicKey2),
272
+ async set() {}
273
+ }
274
+ }));
275
+ const wire = detachSignature(delivered);
276
+ const proofs = Array.isArray(wire.proof) ? wire.proof : [wire.proof];
277
+ assertEquals(proofs.length, sender === "actor" ? 2 : 1);
278
+ for (const proof of proofs) await assertRawProof(wire, proof, ed25519PublicKey.publicKey);
279
+ assertEquals(await activity.toJsonLd(), before);
280
+ });
281
+ } finally {
282
+ esm_default.unmockGlobal();
283
+ esm_default.removeRoutes();
284
+ esm_default.clearHistory();
285
+ }
286
+ });
287
+ //#endregion
288
+ export {};