@fedify/fedify 2.4.6-dev.2628 → 2.4.6

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 (133) hide show
  1. package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
  2. package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
  3. package/dist/callback-DPDs_dxC.d.mts +5280 -0
  4. package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
  5. package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
  6. package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.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.cjs +1 -1
  10. package/dist/compat/mod.d.cts +1 -1
  11. package/dist/compat/mod.d.ts +1 -1
  12. package/dist/compat/mod.js +1 -1
  13. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  14. package/dist/compat/transformers.test.mjs +1 -1
  15. package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
  16. package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
  17. package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
  18. package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
  19. package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
  20. package/dist/federation/attachment-responses.test.d.mts +2 -0
  21. package/dist/federation/attachment-responses.test.mjs +182 -0
  22. package/dist/federation/builder.test.mjs +1 -1
  23. package/dist/federation/compound-fanout.test.mjs +4 -4
  24. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  25. package/dist/federation/delivery-attachments.test.mjs +288 -0
  26. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  27. package/dist/federation/handler.test.mjs +206 -14
  28. package/dist/federation/hashlink-media.test.mjs +2 -2
  29. package/dist/federation/idempotency.test.mjs +2 -2
  30. package/dist/federation/inbox-report.test.mjs +5 -5
  31. package/dist/federation/inbox.test.mjs +1 -1
  32. package/dist/federation/metrics.test.mjs +1 -1
  33. package/dist/federation/middleware.test.mjs +1188 -13
  34. package/dist/federation/mod.cjs +1 -1
  35. package/dist/federation/mod.d.cts +3 -3
  36. package/dist/federation/mod.d.ts +3 -3
  37. package/dist/federation/mod.js +1 -1
  38. package/dist/federation/outgoing-proof.test.mjs +4 -4
  39. package/dist/federation/portable-actor.test.mjs +3 -3
  40. package/dist/federation/portable-chain.test.mjs +3 -3
  41. package/dist/federation/portable-collection.test.mjs +4 -4
  42. package/dist/federation/portable-delivery.test.mjs +2 -2
  43. package/dist/federation/portable-gateway-keys.test.mjs +5 -5
  44. package/dist/federation/portable-inbox.test.mjs +4 -4
  45. package/dist/federation/portable-parse-uri.test.mjs +1 -1
  46. package/dist/federation/portable-route-activity.test.mjs +2 -2
  47. package/dist/federation/portable.test.mjs +3 -3
  48. package/dist/federation/send.test.mjs +293 -3
  49. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  50. package/dist/federation/tasks/tasks.test.mjs +2 -2
  51. package/dist/federation/temporal.test.mjs +25 -1
  52. package/dist/federation/webfinger.test.mjs +1 -1
  53. package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
  54. package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
  55. package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
  56. package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
  57. package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
  58. package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
  59. package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
  60. package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
  61. package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
  62. package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
  63. package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
  64. package/dist/ld-signature-D1tFSFK8.mjs +23 -0
  65. package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
  66. package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
  67. package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
  68. package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
  69. package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
  70. package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
  71. package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
  72. package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
  73. package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
  74. package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
  75. package/dist/mod.cjs +6 -6
  76. package/dist/mod.d.cts +8 -8
  77. package/dist/mod.d.ts +8 -8
  78. package/dist/mod.js +6 -6
  79. package/dist/nodeinfo/client.test.mjs +432 -4
  80. package/dist/nodeinfo/handler.test.mjs +1 -1
  81. package/dist/nodeinfo/mod.cjs +1 -1
  82. package/dist/nodeinfo/mod.d.cts +1 -1
  83. package/dist/nodeinfo/mod.d.ts +1 -1
  84. package/dist/nodeinfo/mod.js +1 -1
  85. package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
  86. package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
  87. package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
  88. package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
  89. package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
  90. package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
  91. package/dist/portable-verifier-CPA86vIP.js +22 -0
  92. package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
  93. package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
  94. package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
  95. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  96. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  97. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  98. package/dist/sig/compound-proof.test.mjs +3 -3
  99. package/dist/sig/http.test.mjs +2 -2
  100. package/dist/sig/key-types.test.d.mts +162 -0
  101. package/dist/sig/key-types.test.mjs +8 -0
  102. package/dist/sig/key.test.mjs +1 -1
  103. package/dist/sig/ld.test.mjs +572 -7
  104. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  105. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  106. package/dist/sig/mod.cjs +2 -2
  107. package/dist/sig/mod.d.cts +3 -3
  108. package/dist/sig/mod.d.ts +3 -3
  109. package/dist/sig/mod.js +2 -2
  110. package/dist/sig/owner.test.mjs +1 -1
  111. package/dist/sig/portable-collection.test.mjs +1 -1
  112. package/dist/sig/portable-interop.test.mjs +3 -3
  113. package/dist/sig/portable-key.test.mjs +5 -5
  114. package/dist/sig/proof.test.mjs +100 -6
  115. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  116. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  117. package/dist/sig/verification.test.mjs +3 -3
  118. package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
  119. package/dist/testing/kv.test.mjs +1 -1
  120. package/dist/testing/mod.d.mts +3 -5045
  121. package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
  122. package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
  123. package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
  124. package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
  125. package/dist/utils/docloader.test.mjs +2 -2
  126. package/dist/utils/kv-cache.test.mjs +1 -1
  127. package/dist/utils/mod.cjs +1 -1
  128. package/dist/utils/mod.d.cts +1 -1
  129. package/dist/utils/mod.d.ts +1 -1
  130. package/dist/utils/mod.js +1 -1
  131. package/dist/utils/portable-verifier.test.d.mts +2 -0
  132. package/dist/utils/portable-verifier.test.mjs +126 -0
  133. package/package.json +6 -6
@@ -0,0 +1,288 @@
1
+ import "temporal-polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
+ import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
+ import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
+ import "../std__assert-DvMDRPes.mjs";
8
+ import { t as assert } from "../assert-D1Eafmd_.mjs";
9
+ import { c as detachSignature, v as verifySignature } from "../ld-BGnZDnia.mjs";
10
+ import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-Dsca6G_Y.mjs";
11
+ import { a as signObject } from "../proof-C4pwAF2k.mjs";
12
+ import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
13
+ import { l as prepareActivityJsonLd, n as FederationImpl, t as ContextImpl } from "../middleware-mRXKHq68.mjs";
14
+ import { Create, Image, Note, PUBLIC_COLLECTION, Person, PropertyValue, Update } from "@fedify/vocab";
15
+ import { decodeMultibase } from "@fedify/vocab-runtime";
16
+ import { mockDocumentLoader, test } from "@fedify/fixture";
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 {};
@@ -5,10 +5,10 @@ import { r as createRequestContext, t as createInboxContext } from "../context-8
5
5
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
7
  import "../std__assert-DvMDRPes.mjs";
8
- import { a as compactJsonLd, m as verifyCompactJsonLd, p as signJsonLd } from "../ld-DJZrjNuN.mjs";
9
- import { u as signRequest } from "../http-BSARoDPh.mjs";
8
+ import { a as compactJsonLd, g as verifyCompactJsonLd, h as signJsonLd } from "../ld-BGnZDnia.mjs";
9
+ import { u as signRequest } from "../http-B6sfb5xN.mjs";
10
10
  import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
11
- import { f as handleInbox, o as createFederation } from "../middleware-DblGj642.mjs";
11
+ import { o as createFederation, p as handleInbox } from "../middleware-mRXKHq68.mjs";
12
12
  import { t as ActivityListenerSet } from "../activity-listener-C-BSbKI7.mjs";
13
13
  import { t as map_local_create_note_default } from "../map-local-create-note-B0SeXJms.mjs";
14
14
  import { Create, CryptographicKey, Multikey, Person, Update } from "@fedify/vocab";
@@ -4,18 +4,21 @@ globalThis.addEventListener = () => {};
4
4
  import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-8Tu9kea0.mjs";
5
5
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
+ import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
7
8
  import { t as assertGreaterOrEqual } from "../assert_greater_or_equal-BlafOF4-.mjs";
8
9
  import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
9
10
  import "../std__assert-DvMDRPes.mjs";
10
11
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
11
12
  import { t as assert } from "../assert-D1Eafmd_.mjs";
12
13
  import { r as parseAcceptSignature } from "../accept-CPVqki78.mjs";
13
- import { C as generateCryptoKeyPair, a as compactJsonLd, p as signJsonLd } from "../ld-DJZrjNuN.mjs";
14
- import { a as signObject } from "../proof-DW0FK6Cp.mjs";
15
- import { u as signRequest } from "../http-BSARoDPh.mjs";
14
+ import { T as generateCryptoKeyPair, a as compactJsonLd, h as signJsonLd } from "../ld-BGnZDnia.mjs";
15
+ import { a as signObject } from "../proof-C4pwAF2k.mjs";
16
+ import { u as signRequest } from "../http-B6sfb5xN.mjs";
16
17
  import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
17
- import { d as handleCustomCollection, f as handleInbox, g as respondWithObjectIfAcceptable, h as respondWithObject, l as handleActor, m as handleOutbox, o as createFederation, p as handleObject, u as handleCollection } from "../middleware-DblGj642.mjs";
18
+ import { _ as respondWithObjectIfAcceptable, d as handleCollection, f as handleCustomCollection, g as respondWithObject, h as handleOutbox, m as handleObject, o as createFederation, p as handleInbox, u as handleActor } from "../middleware-mRXKHq68.mjs";
18
19
  import { t as ActivityListenerSet } from "../activity-listener-C-BSbKI7.mjs";
20
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-D1tFSFK8.mjs";
21
+ import { configure, reset } from "@logtape/logtape";
19
22
  import { Activity, Create, CryptographicKey, Multikey, Note, Person, Tombstone } from "@fedify/vocab";
20
23
  import { FetchError, parseIri } from "@fedify/vocab-runtime";
21
24
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
@@ -727,8 +730,8 @@ test("handleCollection()", async () => {
727
730
  assertEquals(response.status, 200);
728
731
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
729
732
  const createCtx = [
730
- "https://w3id.org/identity/v1",
731
733
  "https://www.w3.org/ns/activitystreams",
734
+ "https://w3id.org/security/v1",
732
735
  "https://w3id.org/security/data-integrity/v1",
733
736
  "https://gotosocial.org/ns",
734
737
  {
@@ -775,7 +778,13 @@ test("handleCollection()", async () => {
775
778
  "@id": "fedibird:emojiReactions",
776
779
  "@type": "@id"
777
780
  }
778
- }
781
+ },
782
+ { orderedItems: {
783
+ "@id": "https://www.w3.org/ns/activitystreams#items",
784
+ "@type": "@id",
785
+ "@container": "@list",
786
+ "@context": null
787
+ } }
779
788
  ],
780
789
  id: "https://example.com/users/someone",
781
790
  type: "OrderedCollection",
@@ -860,7 +869,13 @@ test("handleCollection()", async () => {
860
869
  "@id": "fedibird:emojiReactions",
861
870
  "@type": "@id"
862
871
  }
863
- }
872
+ },
873
+ { orderedItems: {
874
+ "@id": "https://www.w3.org/ns/activitystreams#items",
875
+ "@type": "@id",
876
+ "@container": "@list",
877
+ "@context": null
878
+ } }
864
879
  ],
865
880
  id: "https://example.com/users/someone",
866
881
  type: "OrderedCollection",
@@ -980,7 +995,13 @@ test("handleCollection()", async () => {
980
995
  "@id": "fedibird:emojiReactions",
981
996
  "@type": "@id"
982
997
  }
983
- }
998
+ },
999
+ { orderedItems: {
1000
+ "@id": "https://www.w3.org/ns/activitystreams#items",
1001
+ "@type": "@id",
1002
+ "@container": "@list",
1003
+ "@context": null
1004
+ } }
984
1005
  ],
985
1006
  id: "https://example.com/users/someone?cursor=0",
986
1007
  type: "OrderedCollectionPage",
@@ -1040,7 +1061,13 @@ test("handleCollection()", async () => {
1040
1061
  "@id": "fedibird:emojiReactions",
1041
1062
  "@type": "@id"
1042
1063
  }
1043
- }
1064
+ },
1065
+ { orderedItems: {
1066
+ "@id": "https://www.w3.org/ns/activitystreams#items",
1067
+ "@type": "@id",
1068
+ "@container": "@list",
1069
+ "@context": null
1070
+ } }
1044
1071
  ],
1045
1072
  id: "https://example.com/users/someone?cursor=2",
1046
1073
  type: "OrderedCollectionPage",
@@ -2991,6 +3018,166 @@ test("handleOutbox() matches portable actors by their canonical IDs", async () =
2991
3018
  [actorId, "ap://did:key:z6MkAlice/users/other"]
2992
3019
  ]) assertEquals(await post(actor), [400, 0], String(actor));
2993
3020
  });
3021
+ test("handleInbox() verifies Linked Data signatures without created", async (t) => {
3022
+ const inserted = structuredClone(ldSignatureWithoutCreated);
3023
+ const withTimestamp = {
3024
+ ...inserted,
3025
+ signature: {
3026
+ ...inserted.signature,
3027
+ created: "2024-09-12T16:50:46Z"
3028
+ }
3029
+ };
3030
+ const tampered = structuredClone(ldSignatureWithoutCreated);
3031
+ tampered.object.content = "tampered";
3032
+ const invalid = structuredClone(ldSignatureWithoutCreated);
3033
+ invalid.signature.signatureValue = "AAAA";
3034
+ const { signature: _, ...unsigned } = ldSignatureWithoutCreated;
3035
+ for (const [name, body, expected] of [
3036
+ [
3037
+ "valid LD-only",
3038
+ ldSignatureWithoutCreated,
3039
+ 202
3040
+ ],
3041
+ [
3042
+ "inserted created",
3043
+ withTimestamp,
3044
+ 401
3045
+ ],
3046
+ [
3047
+ "tampered content",
3048
+ tampered,
3049
+ 401
3050
+ ],
3051
+ [
3052
+ "invalid signature",
3053
+ invalid,
3054
+ 401
3055
+ ],
3056
+ [
3057
+ "unsigned",
3058
+ unsigned,
3059
+ 401
3060
+ ],
3061
+ [
3062
+ "malformed created",
3063
+ {
3064
+ ...ldSignatureWithoutCreated,
3065
+ signature: {
3066
+ ...ldSignatureWithoutCreated.signature,
3067
+ created: 123
3068
+ }
3069
+ },
3070
+ 401
3071
+ ],
3072
+ [
3073
+ "malformed creator",
3074
+ {
3075
+ ...ldSignatureWithoutCreated,
3076
+ signature: {
3077
+ ...ldSignatureWithoutCreated.signature,
3078
+ creator: {}
3079
+ }
3080
+ },
3081
+ 401
3082
+ ],
3083
+ [
3084
+ "malformed null",
3085
+ {
3086
+ ...ldSignatureWithoutCreated,
3087
+ signature: null
3088
+ },
3089
+ 401
3090
+ ],
3091
+ [
3092
+ "malformed array",
3093
+ {
3094
+ ...ldSignatureWithoutCreated,
3095
+ signature: []
3096
+ },
3097
+ 401
3098
+ ],
3099
+ [
3100
+ "malformed primitive",
3101
+ {
3102
+ ...ldSignatureWithoutCreated,
3103
+ signature: "secret"
3104
+ },
3105
+ 401
3106
+ ]
3107
+ ]) await t.step(name, async () => {
3108
+ const kv = new MemoryKvStore();
3109
+ const federation = createFederation({ kv });
3110
+ const request = new Request("https://example.com/inbox", {
3111
+ method: "POST",
3112
+ body: JSON.stringify(body)
3113
+ });
3114
+ const context = createRequestContext({
3115
+ federation,
3116
+ request,
3117
+ url: new URL(request.url),
3118
+ data: void 0,
3119
+ documentLoader: mockDocumentLoader,
3120
+ contextLoader: mockDocumentLoader
3121
+ });
3122
+ let deliveries = 0;
3123
+ const inboxListeners = new ActivityListenerSet();
3124
+ inboxListeners.add(Create, () => {
3125
+ deliveries++;
3126
+ });
3127
+ const records = [];
3128
+ await configure({
3129
+ sinks: { buffer: (record) => records.push(record) },
3130
+ loggers: [{
3131
+ category: ["fedify"],
3132
+ sinks: ["buffer"],
3133
+ lowestLevel: "debug"
3134
+ }, {
3135
+ category: ["logtape", "meta"],
3136
+ sinks: []
3137
+ }],
3138
+ reset: true
3139
+ });
3140
+ try {
3141
+ assertEquals((await handleInbox(request, {
3142
+ recipient: null,
3143
+ context,
3144
+ inboxContextFactory() {
3145
+ return createInboxContext({
3146
+ ...context,
3147
+ clone: void 0
3148
+ });
3149
+ },
3150
+ kv,
3151
+ kvPrefixes: {
3152
+ activityIdempotence: ["_fedify", "activityIdempotence"],
3153
+ publicKey: ["_fedify", "publicKey"],
3154
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
3155
+ },
3156
+ actorDispatcher: () => null,
3157
+ inboxListeners,
3158
+ onNotFound: () => new Response("Not found", { status: 404 }),
3159
+ signatureTimeWindow: { minutes: 5 },
3160
+ skipSignatureVerification: false
3161
+ })).status, expected);
3162
+ assertEquals(deliveries, expected === 202 ? 1 : 0);
3163
+ const malformedRecords = records.filter((r) => r.rawMessage === "Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.");
3164
+ assertEquals(malformedRecords.length, name.startsWith("malformed") ? 1 : 0);
3165
+ for (const record of malformedRecords) {
3166
+ assertEquals(record.category, [
3167
+ "fedify",
3168
+ "federation",
3169
+ "inbox"
3170
+ ]);
3171
+ assertEquals(record.level, "debug");
3172
+ assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.creator));
3173
+ assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.signatureValue));
3174
+ assertFalse(JSON.stringify(record).includes("secret"));
3175
+ }
3176
+ } finally {
3177
+ await reset();
3178
+ }
3179
+ });
3180
+ });
2994
3181
  test("handleInbox() preserves the raw signed payload for inboxContextFactory", async () => {
2995
3182
  const federation = createFederation({ kv: new MemoryKvStore() });
2996
3183
  const remoteContextUrl = "https://remote.example/contexts/ext";
@@ -3716,8 +3903,8 @@ test("handleCustomCollection()", async () => {
3716
3903
  assertEquals(response.status, 200);
3717
3904
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3718
3905
  const createCtx = [
3719
- "https://w3id.org/identity/v1",
3720
3906
  "https://www.w3.org/ns/activitystreams",
3907
+ "https://w3id.org/security/v1",
3721
3908
  "https://w3id.org/security/data-integrity/v1",
3722
3909
  "https://gotosocial.org/ns",
3723
3910
  {
@@ -3765,8 +3952,13 @@ test("handleCustomCollection()", async () => {
3765
3952
  }
3766
3953
  }
3767
3954
  ];
3955
+ const ITEM_CONTEXT = [...CONTEXT, { items: {
3956
+ "@id": "https://www.w3.org/ns/activitystreams#items",
3957
+ "@type": "@id",
3958
+ "@context": null
3959
+ } }];
3768
3960
  assertEquals(await response.json(), {
3769
- "@context": CONTEXT,
3961
+ "@context": ITEM_CONTEXT,
3770
3962
  id: "https://example.com/",
3771
3963
  type: "Collection",
3772
3964
  items: [
@@ -3821,7 +4013,7 @@ test("handleCustomCollection()", async () => {
3821
4013
  assertEquals(response.status, 200);
3822
4014
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3823
4015
  assertEquals(await response.json(), {
3824
- "@context": CONTEXT,
4016
+ "@context": ITEM_CONTEXT,
3825
4017
  id: "https://example.com/",
3826
4018
  type: "Collection",
3827
4019
  items: [
@@ -3879,7 +4071,7 @@ test("handleCustomCollection()", async () => {
3879
4071
  assertEquals(response.status, 200);
3880
4072
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3881
4073
  assertEquals(await response.json(), {
3882
- "@context": CONTEXT,
4074
+ "@context": ITEM_CONTEXT,
3883
4075
  id: "https://example.com/?cursor=0",
3884
4076
  type: "CollectionPage",
3885
4077
  partOf: "https://example.com/",
@@ -3908,7 +4100,7 @@ test("handleCustomCollection()", async () => {
3908
4100
  assertEquals(response.status, 200);
3909
4101
  assertEquals(response.headers.get("Content-Type"), "application/activity+json");
3910
4102
  assertEquals(await response.json(), {
3911
- "@context": CONTEXT,
4103
+ "@context": ITEM_CONTEXT,
3912
4104
  id: "https://example.com/?cursor=2",
3913
4105
  type: "CollectionPage",
3914
4106
  partOf: "https://example.com/",
@@ -10,8 +10,8 @@ import "../std__assert-DvMDRPes.mjs";
10
10
  import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
11
11
  import { t as assert } from "../assert-D1Eafmd_.mjs";
12
12
  import { r as ed25519PublicKey } from "../keys-DIJNHW-Y.mjs";
13
- import { o as createFederation, x as parseHashlinkGatewayRequest } from "../middleware-DblGj642.mjs";
14
- import { r as createFederationBuilder } from "../builder-kj5boG2l.mjs";
13
+ import { S as parseHashlinkGatewayRequest, o as createFederation } from "../middleware-mRXKHq68.mjs";
14
+ import { r as createFederationBuilder } from "../builder-CadJYxhX.mjs";
15
15
  import { n as RouterError } from "../router-u5O5KCQr.mjs";
16
16
  import { Note } from "@fedify/vocab";
17
17
  import { computeDigestMultibase, encodeMultibase, exportDidKey } from "@fedify/vocab-runtime";
@@ -4,9 +4,9 @@ globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
6
6
  import "../std__assert-DvMDRPes.mjs";
7
- import { a as signObject } from "../proof-DW0FK6Cp.mjs";
7
+ import { a as signObject } from "../proof-C4pwAF2k.mjs";
8
8
  import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
9
- import { o as createFederation } from "../middleware-DblGj642.mjs";
9
+ import { o as createFederation } from "../middleware-mRXKHq68.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
@@ -2,12 +2,12 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
5
- import { p as signJsonLd } from "../ld-DJZrjNuN.mjs";
6
- import { a as signObject } from "../proof-DW0FK6Cp.mjs";
7
- import { u as signRequest } from "../http-BSARoDPh.mjs";
5
+ import { h as signJsonLd } from "../ld-BGnZDnia.mjs";
6
+ import { a as signObject } from "../proof-C4pwAF2k.mjs";
7
+ import { u as signRequest } from "../http-B6sfb5xN.mjs";
8
8
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
9
- import { o as createFederation } from "../middleware-DblGj642.mjs";
10
- import { r as createFederationBuilder } from "../builder-kj5boG2l.mjs";
9
+ import { o as createFederation } from "../middleware-mRXKHq68.mjs";
10
+ import { r as createFederationBuilder } from "../builder-CadJYxhX.mjs";
11
11
  import { Create, Person } from "@fedify/vocab";
12
12
  import { exportDidKey, parseIri } from "@fedify/vocab-runtime";
13
13
  import { mockDocumentLoader, test } from "@fedify/fixture";
@@ -5,7 +5,7 @@ import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
5
5
  import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
7
7
  import { t as ActivityListenerSet } from "../activity-listener-C-BSbKI7.mjs";
8
- import { t as actorsHaveSameOrigin } from "../inbox-BdZenpZQ.mjs";
8
+ import { t as actorsHaveSameOrigin } from "../inbox-B7NVkb8j.mjs";
9
9
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
10
10
  import { parseIri } from "@fedify/vocab-runtime";
11
11
  import { test } from "@fedify/fixture";