@fedify/fedify 2.3.16-dev.2841 → 2.3.16

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 (108) hide show
  1. package/dist/attachment-arrays-BlfpZlWF.mjs +16 -0
  2. package/dist/{builder-G4wSHQX-.mjs → builder-D4GE1Gmi.mjs} +3 -3
  3. package/dist/callback-kR_sx2zZ.d.mts +2661 -0
  4. package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-DpUNYKla.mjs → client-DFgYVbUA.mjs} +86 -11
  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-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
  15. package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
  16. package/dist/{deno-DmDVx5sE.mjs → deno-FtdqgHJA.mjs} +1 -1
  17. package/dist/{docloader-0fjyUmvI.mjs → docloader-B9iU4DP2.mjs} +2 -2
  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/circuit-breaker.test.mjs +2 -2
  22. package/dist/federation/collection.test.mjs +1 -1
  23. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  24. package/dist/federation/delivery-attachments.test.mjs +288 -0
  25. package/dist/federation/handler.test.mjs +208 -16
  26. package/dist/federation/idempotency.test.mjs +2 -2
  27. package/dist/federation/inbox.test.mjs +2 -2
  28. package/dist/federation/metrics.test.mjs +1 -1
  29. package/dist/federation/middleware.test.mjs +1191 -16
  30. package/dist/federation/mod.cjs +1 -1
  31. package/dist/federation/mod.d.cts +2 -2
  32. package/dist/federation/mod.d.ts +2 -2
  33. package/dist/federation/mod.js +1 -1
  34. package/dist/federation/negotiation.test.mjs +1 -1
  35. package/dist/federation/retry.test.mjs +1 -1
  36. package/dist/federation/send.test.mjs +293 -3
  37. package/dist/federation/temporal.test.mjs +25 -1
  38. package/dist/federation/webfinger.test.mjs +1 -1
  39. package/dist/{http-CKX94hfh.cjs → http-2RyDQ0tE.cjs} +6 -4
  40. package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
  41. package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
  42. package/dist/{http-DCK-QQfE.mjs → http-D8tiOrZf.mjs} +7 -5
  43. package/dist/{http-DwIMsxu9.js → http-mLeLYFj-.js} +6 -4
  44. package/dist/{inbox-Bx6PCMeE.mjs → inbox-Dy8awbi8.mjs} +2 -2
  45. package/dist/{key-SkLDUmPM.mjs → key-o1SmN5s0.mjs} +4 -3
  46. package/dist/{kv-cache-BaJOO6O3.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
  47. package/dist/{kv-cache-BnZ4KLMY.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
  48. package/dist/{kv-cache-xIexNacM.js → kv-cache-Dsq8C8D8.js} +1 -1
  49. package/dist/{ld-DUG6cq9q.mjs → ld-DCKrqj9y.mjs} +155 -22
  50. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  51. package/dist/{metrics-D3OnAgfj.mjs → metrics-CaoYRhNH.mjs} +1 -1
  52. package/dist/{middleware-CUwjLKp3.mjs → middleware-4p3opEMT.mjs} +1 -1
  53. package/dist/{middleware-C9RexCTx.cjs → middleware-CP-8P7kk.cjs} +492 -117
  54. package/dist/{middleware-DU2jy5eY.js → middleware-Cce0nLDw.js} +491 -117
  55. package/dist/{middleware-zEy-wJYI.mjs → middleware-D31fNcY4.mjs} +399 -109
  56. package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
  57. package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
  58. package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
  59. package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
  60. package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
  61. package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
  62. package/dist/mod.cjs +5 -5
  63. package/dist/mod.d.cts +8 -8
  64. package/dist/mod.d.ts +8 -8
  65. package/dist/mod.js +5 -5
  66. package/dist/nodeinfo/client.test.mjs +432 -4
  67. package/dist/nodeinfo/handler.test.mjs +1 -1
  68. package/dist/nodeinfo/mod.cjs +1 -1
  69. package/dist/nodeinfo/mod.d.cts +1 -1
  70. package/dist/nodeinfo/mod.d.ts +1 -1
  71. package/dist/nodeinfo/mod.js +1 -1
  72. package/dist/nodeinfo/types.test.mjs +1 -1
  73. package/dist/{outgoing-jsonld-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
  74. package/dist/{owner-Baf_LRb2.mjs → owner-Bdj0nHhf.mjs} +2 -2
  75. package/dist/{proof-CNGy7TJL.js → proof-B9XJiyz-.js} +1030 -858
  76. package/dist/{proof-BdAFbOFg.cjs → proof-CmcP8yqP.cjs} +1243 -1059
  77. package/dist/{proof-LTsbjXnQ.mjs → proof-DrbjYma9.mjs} +41 -16
  78. package/dist/{send-DOf5y1nB.mjs → send-VD_WG3dN.mjs} +100 -22
  79. package/dist/sig/http.test.mjs +2 -2
  80. package/dist/sig/key-types.test.d.mts +218 -0
  81. package/dist/sig/key-types.test.mjs +8 -0
  82. package/dist/sig/key.test.mjs +2 -2
  83. package/dist/sig/ld.test.mjs +573 -8
  84. package/dist/sig/mod.cjs +2 -2
  85. package/dist/sig/mod.d.cts +3 -3
  86. package/dist/sig/mod.d.ts +3 -3
  87. package/dist/sig/mod.js +2 -2
  88. package/dist/sig/owner.test.mjs +1 -1
  89. package/dist/sig/proof.test.mjs +96 -4
  90. package/dist/{temporal-fl4sM1Gs.mjs → temporal-CMvoB-vD.mjs} +3 -5
  91. package/dist/testing/mod.d.mts +2 -2476
  92. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  93. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  94. package/dist/utils/docloader.test.mjs +2 -2
  95. package/dist/utils/kv-cache.test.mjs +1 -1
  96. package/dist/utils/mod.cjs +1 -1
  97. package/dist/utils/mod.d.cts +1 -1
  98. package/dist/utils/mod.d.ts +1 -1
  99. package/dist/utils/mod.js +1 -1
  100. package/package.json +7 -7
  101. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
  102. /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
  103. /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
  104. /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
  105. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
  106. /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
  107. /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
  108. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -0,0 +1,288 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as esm_default } from "../esm-vrlUxr60.mjs";
5
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
+ import "../std__assert-BjJn2daJ.mjs";
7
+ import { t as assert } from "../assert-CEO06XCw.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-DCKrqj9y.mjs";
11
+ import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-BZEAVK_Q.mjs";
12
+ import { r as signObject } from "../proof-DrbjYma9.mjs";
13
+ import { n as FederationImpl, t as ContextImpl, x as prepareActivityJsonLd } from "../middleware-D31fNcY4.mjs";
14
+ import { Create, Image, Note, PUBLIC_COLLECTION, Person, PropertyValue, Update } from "@fedify/vocab";
15
+ import { mockDocumentLoader, test } from "@fedify/fixture";
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 {};
@@ -4,17 +4,20 @@ globalThis.addEventListener = () => {};
4
4
  import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-CxbCIptr.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
6
  import "../std__assert-BjJn2daJ.mjs";
7
+ import { r as assertFalse } from "../assert_throws-BbSMEFKo.mjs";
7
8
  import { n as assertGreaterOrEqual, t as assertRejects } from "../assert_rejects-D1HYAik3.mjs";
8
9
  import { n as assertInstanceOf, t as assert } from "../assert-CEO06XCw.mjs";
9
10
  import { r as parseAcceptSignature } from "../accept-Dd__NiUL.mjs";
10
- import { a as generateCryptoKeyPair } from "../key-SkLDUmPM.mjs";
11
- import { c as signRequest } from "../http-DCK-QQfE.mjs";
11
+ import { a as generateCryptoKeyPair } from "../key-o1SmN5s0.mjs";
12
+ import { c as signRequest } from "../http-D8tiOrZf.mjs";
12
13
  import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
13
14
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
14
- import { a as compactJsonLd, p as signJsonLd } from "../ld-DUG6cq9q.mjs";
15
- import { r as signObject } from "../proof-LTsbjXnQ.mjs";
16
- import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-zEy-wJYI.mjs";
17
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
15
+ import { a as compactJsonLd, h as signJsonLd } from "../ld-DCKrqj9y.mjs";
16
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-Dgz_b89j.mjs";
17
+ import { r as signObject } from "../proof-DrbjYma9.mjs";
18
+ import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-D31fNcY4.mjs";
19
+ import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
20
+ import { configure, reset } from "@logtape/logtape";
18
21
  import { Activity, Create, CryptographicKey, Multikey, Note, Person, Tombstone } from "@fedify/vocab";
19
22
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
20
23
  import { FetchError } from "@fedify/vocab-runtime";
@@ -601,8 +604,8 @@ test("handleCollection()", async () => {
601
604
  assertEquals(response.status, 200);
602
605
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
603
606
  const createCtx = [
604
- "https://w3id.org/identity/v1",
605
607
  "https://www.w3.org/ns/activitystreams",
608
+ "https://w3id.org/security/v1",
606
609
  "https://w3id.org/security/data-integrity/v1",
607
610
  "https://gotosocial.org/ns",
608
611
  {
@@ -649,7 +652,13 @@ test("handleCollection()", async () => {
649
652
  "@id": "fedibird:emojiReactions",
650
653
  "@type": "@id"
651
654
  }
652
- }
655
+ },
656
+ { orderedItems: {
657
+ "@id": "https://www.w3.org/ns/activitystreams#items",
658
+ "@type": "@id",
659
+ "@container": "@list",
660
+ "@context": null
661
+ } }
653
662
  ],
654
663
  id: "https://example.com/users/someone",
655
664
  type: "OrderedCollection",
@@ -734,7 +743,13 @@ test("handleCollection()", async () => {
734
743
  "@id": "fedibird:emojiReactions",
735
744
  "@type": "@id"
736
745
  }
737
- }
746
+ },
747
+ { orderedItems: {
748
+ "@id": "https://www.w3.org/ns/activitystreams#items",
749
+ "@type": "@id",
750
+ "@container": "@list",
751
+ "@context": null
752
+ } }
738
753
  ],
739
754
  id: "https://example.com/users/someone",
740
755
  type: "OrderedCollection",
@@ -854,7 +869,13 @@ test("handleCollection()", async () => {
854
869
  "@id": "fedibird:emojiReactions",
855
870
  "@type": "@id"
856
871
  }
857
- }
872
+ },
873
+ { orderedItems: {
874
+ "@id": "https://www.w3.org/ns/activitystreams#items",
875
+ "@type": "@id",
876
+ "@container": "@list",
877
+ "@context": null
878
+ } }
858
879
  ],
859
880
  id: "https://example.com/users/someone?cursor=0",
860
881
  type: "OrderedCollectionPage",
@@ -914,7 +935,13 @@ test("handleCollection()", async () => {
914
935
  "@id": "fedibird:emojiReactions",
915
936
  "@type": "@id"
916
937
  }
917
- }
938
+ },
939
+ { orderedItems: {
940
+ "@id": "https://www.w3.org/ns/activitystreams#items",
941
+ "@type": "@id",
942
+ "@container": "@list",
943
+ "@context": null
944
+ } }
918
945
  ],
919
946
  id: "https://example.com/users/someone?cursor=2",
920
947
  type: "OrderedCollectionPage",
@@ -2737,6 +2764,166 @@ test("handleOutbox()", async () => {
2737
2764
  assertEquals(response.status, 500);
2738
2765
  assertEquals(onErrorCalled, true);
2739
2766
  });
2767
+ test("handleInbox() verifies Linked Data signatures without created", async (t) => {
2768
+ const inserted = structuredClone(ldSignatureWithoutCreated);
2769
+ const withTimestamp = {
2770
+ ...inserted,
2771
+ signature: {
2772
+ ...inserted.signature,
2773
+ created: "2024-09-12T16:50:46Z"
2774
+ }
2775
+ };
2776
+ const tampered = structuredClone(ldSignatureWithoutCreated);
2777
+ tampered.object.content = "tampered";
2778
+ const invalid = structuredClone(ldSignatureWithoutCreated);
2779
+ invalid.signature.signatureValue = "AAAA";
2780
+ const { signature: _, ...unsigned } = ldSignatureWithoutCreated;
2781
+ for (const [name, body, expected] of [
2782
+ [
2783
+ "valid LD-only",
2784
+ ldSignatureWithoutCreated,
2785
+ 202
2786
+ ],
2787
+ [
2788
+ "inserted created",
2789
+ withTimestamp,
2790
+ 401
2791
+ ],
2792
+ [
2793
+ "tampered content",
2794
+ tampered,
2795
+ 401
2796
+ ],
2797
+ [
2798
+ "invalid signature",
2799
+ invalid,
2800
+ 401
2801
+ ],
2802
+ [
2803
+ "unsigned",
2804
+ unsigned,
2805
+ 401
2806
+ ],
2807
+ [
2808
+ "malformed created",
2809
+ {
2810
+ ...ldSignatureWithoutCreated,
2811
+ signature: {
2812
+ ...ldSignatureWithoutCreated.signature,
2813
+ created: 123
2814
+ }
2815
+ },
2816
+ 401
2817
+ ],
2818
+ [
2819
+ "malformed creator",
2820
+ {
2821
+ ...ldSignatureWithoutCreated,
2822
+ signature: {
2823
+ ...ldSignatureWithoutCreated.signature,
2824
+ creator: {}
2825
+ }
2826
+ },
2827
+ 401
2828
+ ],
2829
+ [
2830
+ "malformed null",
2831
+ {
2832
+ ...ldSignatureWithoutCreated,
2833
+ signature: null
2834
+ },
2835
+ 401
2836
+ ],
2837
+ [
2838
+ "malformed array",
2839
+ {
2840
+ ...ldSignatureWithoutCreated,
2841
+ signature: []
2842
+ },
2843
+ 401
2844
+ ],
2845
+ [
2846
+ "malformed primitive",
2847
+ {
2848
+ ...ldSignatureWithoutCreated,
2849
+ signature: "secret"
2850
+ },
2851
+ 401
2852
+ ]
2853
+ ]) await t.step(name, async () => {
2854
+ const kv = new MemoryKvStore();
2855
+ const federation = createFederation({ kv });
2856
+ const request = new Request("https://example.com/inbox", {
2857
+ method: "POST",
2858
+ body: JSON.stringify(body)
2859
+ });
2860
+ const context = createRequestContext({
2861
+ federation,
2862
+ request,
2863
+ url: new URL(request.url),
2864
+ data: void 0,
2865
+ documentLoader: mockDocumentLoader,
2866
+ contextLoader: mockDocumentLoader
2867
+ });
2868
+ let deliveries = 0;
2869
+ const inboxListeners = new ActivityListenerSet();
2870
+ inboxListeners.add(Create, () => {
2871
+ deliveries++;
2872
+ });
2873
+ const records = [];
2874
+ await configure({
2875
+ sinks: { buffer: (record) => records.push(record) },
2876
+ loggers: [{
2877
+ category: ["fedify"],
2878
+ sinks: ["buffer"],
2879
+ lowestLevel: "debug"
2880
+ }, {
2881
+ category: ["logtape", "meta"],
2882
+ sinks: []
2883
+ }],
2884
+ reset: true
2885
+ });
2886
+ try {
2887
+ assertEquals((await handleInbox(request, {
2888
+ recipient: null,
2889
+ context,
2890
+ inboxContextFactory() {
2891
+ return createInboxContext({
2892
+ ...context,
2893
+ clone: void 0
2894
+ });
2895
+ },
2896
+ kv,
2897
+ kvPrefixes: {
2898
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2899
+ publicKey: ["_fedify", "publicKey"],
2900
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
2901
+ },
2902
+ actorDispatcher: () => null,
2903
+ inboxListeners,
2904
+ onNotFound: () => new Response("Not found", { status: 404 }),
2905
+ signatureTimeWindow: { minutes: 5 },
2906
+ skipSignatureVerification: false
2907
+ })).status, expected);
2908
+ assertEquals(deliveries, expected === 202 ? 1 : 0);
2909
+ const malformedRecords = records.filter((r) => r.rawMessage === "Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.");
2910
+ assertEquals(malformedRecords.length, name.startsWith("malformed") ? 1 : 0);
2911
+ for (const record of malformedRecords) {
2912
+ assertEquals(record.category, [
2913
+ "fedify",
2914
+ "federation",
2915
+ "inbox"
2916
+ ]);
2917
+ assertEquals(record.level, "debug");
2918
+ assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.creator));
2919
+ assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.signatureValue));
2920
+ assertFalse(JSON.stringify(record).includes("secret"));
2921
+ }
2922
+ } finally {
2923
+ await reset();
2924
+ }
2925
+ });
2926
+ });
2740
2927
  test("handleInbox() preserves the raw signed payload for inboxContextFactory", async () => {
2741
2928
  const federation = createFederation({ kv: new MemoryKvStore() });
2742
2929
  const remoteContextUrl = "https://remote.example/contexts/ext";
@@ -3462,8 +3649,8 @@ test("handleCustomCollection()", async () => {
3462
3649
  assertEquals(response.status, 200);
3463
3650
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3464
3651
  const createCtx = [
3465
- "https://w3id.org/identity/v1",
3466
3652
  "https://www.w3.org/ns/activitystreams",
3653
+ "https://w3id.org/security/v1",
3467
3654
  "https://w3id.org/security/data-integrity/v1",
3468
3655
  "https://gotosocial.org/ns",
3469
3656
  {
@@ -3511,8 +3698,13 @@ test("handleCustomCollection()", async () => {
3511
3698
  }
3512
3699
  }
3513
3700
  ];
3701
+ const ITEM_CONTEXT = [...CONTEXT, { items: {
3702
+ "@id": "https://www.w3.org/ns/activitystreams#items",
3703
+ "@type": "@id",
3704
+ "@context": null
3705
+ } }];
3514
3706
  assertEquals(await response.json(), {
3515
- "@context": CONTEXT,
3707
+ "@context": ITEM_CONTEXT,
3516
3708
  id: "https://example.com/",
3517
3709
  type: "Collection",
3518
3710
  items: [
@@ -3567,7 +3759,7 @@ test("handleCustomCollection()", async () => {
3567
3759
  assertEquals(response.status, 200);
3568
3760
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3569
3761
  assertEquals(await response.json(), {
3570
- "@context": CONTEXT,
3762
+ "@context": ITEM_CONTEXT,
3571
3763
  id: "https://example.com/",
3572
3764
  type: "Collection",
3573
3765
  items: [
@@ -3625,7 +3817,7 @@ test("handleCustomCollection()", async () => {
3625
3817
  assertEquals(response.status, 200);
3626
3818
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3627
3819
  assertEquals(await response.json(), {
3628
- "@context": CONTEXT,
3820
+ "@context": ITEM_CONTEXT,
3629
3821
  id: "https://example.com/?cursor=0",
3630
3822
  type: "CollectionPage",
3631
3823
  partOf: "https://example.com/",
@@ -3654,7 +3846,7 @@ test("handleCustomCollection()", async () => {
3654
3846
  assertEquals(response.status, 200);
3655
3847
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3656
3848
  assertEquals(await response.json(), {
3657
- "@context": CONTEXT,
3849
+ "@context": ITEM_CONTEXT,
3658
3850
  id: "https://example.com/?cursor=2",
3659
3851
  type: "CollectionPage",
3660
3852
  partOf: "https://example.com/",
@@ -5,8 +5,8 @@ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BjJn2daJ.mjs";
6
6
  import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
8
- import { r as signObject } from "../proof-LTsbjXnQ.mjs";
9
- import { o as createFederation } from "../middleware-zEy-wJYI.mjs";
8
+ import { r as signObject } from "../proof-DrbjYma9.mjs";
9
+ import { o as createFederation } from "../middleware-D31fNcY4.mjs";
10
10
  import { Create, Follow, Person } from "@fedify/vocab";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  //#region src/federation/idempotency.test.ts
@@ -3,8 +3,8 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { r as assertFalse, t as assertThrows } from "../assert_throws-BbSMEFKo.mjs";
6
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
7
- import { t as actorsHaveSameOrigin } from "../inbox-Bx6PCMeE.mjs";
6
+ import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
7
+ import { t as actorsHaveSameOrigin } from "../inbox-Dy8awbi8.mjs";
8
8
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/federation/inbox.test.ts
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BjJn2daJ.mjs";
6
6
  import { t as assertRejects } from "../assert_rejects-D1HYAik3.mjs";
7
- import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-D3OnAgfj.mjs";
7
+ import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-CaoYRhNH.mjs";
8
8
  import { createTestMeterProvider, test } from "@fedify/fixture";
9
9
  import { FetchError } from "@fedify/vocab-runtime";
10
10
  import { DataPointType, MeterProvider, MetricReader } from "@opentelemetry/sdk-metrics";