@fedify/fedify 2.4.0-dev.2122 → 2.4.0-dev.2127

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 (90) hide show
  1. package/dist/{builder-BCXywsZF.mjs → builder-B2bgGYbP.mjs} +2 -2
  2. package/dist/compat/mod.d.cts +1 -1
  3. package/dist/compat/mod.d.ts +1 -1
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{compound-proof-Fxd45Oy5.mjs → compound-proof-SVlHSzV7.mjs} +2 -2
  6. package/dist/{context-SMNOiiY6.d.cts → context-Bm6ldGvx.d.cts} +30 -4
  7. package/dist/{context-tOiJfBoD.d.ts → context-Ci5vuUr_.d.ts} +30 -4
  8. package/dist/{context-CoNRxGYp.mjs → context-DfSVPcJ8.mjs} +6 -3
  9. package/dist/{deno-BZrnW0Qz.mjs → deno-Be9xoxps.mjs} +1 -1
  10. package/dist/{docloader-3BHaS20Z.mjs → docloader-Dtuyb0ps.mjs} +7 -7
  11. package/dist/federation/builder.test.mjs +1 -1
  12. package/dist/federation/compound-fanout.test.mjs +3 -3
  13. package/dist/federation/handler-compound-proof.test.mjs +4 -4
  14. package/dist/federation/handler.test.mjs +6 -6
  15. package/dist/federation/hashlink-media.test.mjs +2 -2
  16. package/dist/federation/idempotency.test.mjs +2 -2
  17. package/dist/federation/metrics.test.mjs +1 -1
  18. package/dist/federation/middleware.test.mjs +8 -8
  19. package/dist/federation/mod.cjs +1 -1
  20. package/dist/federation/mod.d.cts +2 -2
  21. package/dist/federation/mod.d.ts +2 -2
  22. package/dist/federation/mod.js +1 -1
  23. package/dist/federation/outgoing-proof.test.mjs +5 -5
  24. package/dist/federation/portable-actor.test.mjs +3 -3
  25. package/dist/federation/portable-chain.test.d.mts +2 -0
  26. package/dist/federation/portable-chain.test.mjs +358 -0
  27. package/dist/federation/portable-gateway-keys.test.mjs +4 -4
  28. package/dist/federation/portable-inbox.test.mjs +4 -4
  29. package/dist/federation/portable.test.mjs +3 -3
  30. package/dist/federation/send.test.mjs +3 -3
  31. package/dist/federation/tasks/enqueue.test.mjs +2 -2
  32. package/dist/federation/tasks/tasks.test.mjs +3 -3
  33. package/dist/federation/temporal.test.mjs +1 -1
  34. package/dist/federation/webfinger.test.mjs +2 -2
  35. package/dist/{federation-Ml6NrgRV.cjs → federation-B6IHuS6n.cjs} +37 -13
  36. package/dist/{http-B9BQDNIy.mjs → http-BFeK9sBg.mjs} +4 -4
  37. package/dist/{http-BETASGl0.js → http-Rmbiu-5S.js} +1 -1
  38. package/dist/{http-4bmgw-mA.cjs → http-o8l4QeUY.cjs} +1 -1
  39. package/dist/{key-PyYvun0F.mjs → key-Cc1b6pW9.mjs} +2 -2
  40. package/dist/{kv-cache-D2Bz6t_c.cjs → kv-cache-BUkgZAcX.cjs} +6 -6
  41. package/dist/{kv-cache-C4mv2ZFQ.js → kv-cache-BweDce2I.js} +6 -6
  42. package/dist/{kv-cache-CPqUxRL3.mjs → kv-cache-tLKBfxHc.mjs} +1 -1
  43. package/dist/{ld-u4JOD4iO.mjs → ld-DQNTIrAe.mjs} +3 -3
  44. package/dist/{metrics-DCLoLvLz.mjs → metrics-DDE9S63Q.mjs} +1 -1
  45. package/dist/{middleware-CgOqRkK-.mjs → middleware-BdhvduR9.mjs} +54 -29
  46. package/dist/{middleware-B7bmtONC.mjs → middleware-CsQorLC_.mjs} +1 -1
  47. package/dist/{middleware-DWlAGlyP.js → middleware-K9aLnf57.js} +43 -19
  48. package/dist/{mod-DnElMslb.d.cts → mod-AVir5nVI.d.cts} +1 -1
  49. package/dist/{mod-DMdGFMEl.d.cts → mod-Byt5tvAS.d.cts} +13 -2
  50. package/dist/{mod-CTh7ijx5.d.ts → mod-Co53r-VP.d.ts} +13 -2
  51. package/dist/{mod-COWgSo2v.d.ts → mod-eVOUPbQE.d.ts} +1 -1
  52. package/dist/mod.cjs +8 -8
  53. package/dist/mod.d.cts +3 -3
  54. package/dist/mod.d.ts +3 -3
  55. package/dist/mod.js +5 -5
  56. package/dist/nodeinfo/handler.test.mjs +2 -2
  57. package/dist/{owner-CPFM-sqo.mjs → owner-CCfdL83M.mjs} +3 -3
  58. package/dist/{sig-Cb9VSeiF.cjs → portable-collection-DXogVs__.cjs} +220 -2
  59. package/dist/portable-collection-DdXsKBg4.js +623 -0
  60. package/dist/{sig-C1xOA4ml.js → portable-collection-WXaHkNqC.mjs} +5 -4
  61. package/dist/{portable-key-DyylakVV.mjs → portable-key-C-fPq_Yf.mjs} +1 -1
  62. package/dist/{proof-BCOg7Njv.mjs → proof-CW8k0R1G.mjs} +4 -4
  63. package/dist/{send-C8eOPat3.mjs → send--FORaIc4.mjs} +3 -3
  64. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  65. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  66. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  67. package/dist/sig/compound-proof.test.mjs +2 -2
  68. package/dist/sig/http.test.mjs +2 -2
  69. package/dist/sig/key.test.mjs +1 -1
  70. package/dist/sig/ld.test.mjs +2 -2
  71. package/dist/sig/mod.cjs +5 -6
  72. package/dist/sig/mod.d.cts +1 -1
  73. package/dist/sig/mod.d.ts +1 -1
  74. package/dist/sig/mod.js +2 -3
  75. package/dist/sig/owner.test.mjs +1 -1
  76. package/dist/sig/portable-collection.test.mjs +20 -431
  77. package/dist/sig/portable-key.test.mjs +5 -5
  78. package/dist/sig/proof.test.mjs +3 -3
  79. package/dist/{temporal-vjHOhBpy.mjs → temporal-CffY_XOJ.mjs} +1 -1
  80. package/dist/testing/kv.test.mjs +1 -1
  81. package/dist/testing/mod.d.mts +30 -4
  82. package/dist/testing/mod.mjs +2 -2
  83. package/dist/{testing-BWq1dCzx.mjs → testing-otQhu4aD.mjs} +1 -1
  84. package/dist/utils/docloader.test.mjs +81 -2
  85. package/dist/utils/kv-cache.test.mjs +1 -1
  86. package/dist/utils/mod.cjs +1 -1
  87. package/dist/utils/mod.js +1 -1
  88. package/package.json +7 -7
  89. package/dist/owner-DkA0Lz7v.cjs +0 -225
  90. package/dist/owner-wNinn7RK.js +0 -215
@@ -0,0 +1,358 @@
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 { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
8
+ import "../std__assert-DvMDRPes.mjs";
9
+ import { t as assert } from "../assert-D1Eafmd_.mjs";
10
+ import { n as exportJwk } from "../key-Cc1b6pW9.mjs";
11
+ import { o as verifyObject, s as verifyPortableObjectProof } from "../proof-CW8k0R1G.mjs";
12
+ import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
13
+ import { n as FederationImpl } from "../middleware-BdhvduR9.mjs";
14
+ import { Create, DataIntegrityProof, Note, OrderedCollection, Person, traverseCollection } from "@fedify/vocab";
15
+ import { mockDocumentLoader, test } from "@fedify/fixture";
16
+ import { FetchError, encodeMultibase, exportDidKey } from "@fedify/vocab-runtime";
17
+ import serialize from "json-canon";
18
+ //#region src/federation/portable-chain.test.ts
19
+ const did = await exportDidKey(ed25519PublicKey.publicKey);
20
+ const keyId = `${did}#${did.slice(8)}`;
21
+ const GATEWAY = "https://gw.example";
22
+ const context = [
23
+ "https://www.w3.org/ns/activitystreams",
24
+ "https://w3id.org/security/data-integrity/v1",
25
+ "https://w3id.org/fep/ef61"
26
+ ];
27
+ function compatible(path, gateway = GATEWAY) {
28
+ return `${gateway}/.well-known/apgateway/${did}${path}`;
29
+ }
30
+ async function sign(document, proofOptions = {}) {
31
+ const proofConfig = {
32
+ "@context": document["@context"],
33
+ ...proofOptions,
34
+ type: "DataIntegrityProof",
35
+ cryptosuite: "eddsa-jcs-2022",
36
+ verificationMethod: keyId,
37
+ proofPurpose: "assertionMethod",
38
+ created: "2023-02-24T23:36:38Z"
39
+ };
40
+ const encoder = new TextEncoder();
41
+ const digest = /* @__PURE__ */ new Uint8Array(64);
42
+ digest.set(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(serialize(proofConfig)))), 0);
43
+ digest.set(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(serialize(document)))), 32);
44
+ const signature = await crypto.subtle.sign("Ed25519", ed25519PrivateKey, digest);
45
+ return {
46
+ ...document,
47
+ proof: {
48
+ ...proofConfig,
49
+ proofValue: new TextDecoder().decode(encodeMultibase("base58btc", new Uint8Array(signature)))
50
+ }
51
+ };
52
+ }
53
+ function note(path, content = "A portable note") {
54
+ return {
55
+ "@context": context,
56
+ id: compatible(path),
57
+ type: "Note",
58
+ attributedTo: compatible("/actor"),
59
+ content
60
+ };
61
+ }
62
+ function activity(object, id = compatible("/activities/1")) {
63
+ return {
64
+ "@context": context,
65
+ id,
66
+ type: "Create",
67
+ actor: compatible("/actor"),
68
+ object
69
+ };
70
+ }
71
+ function actor() {
72
+ return {
73
+ "@context": context,
74
+ id: compatible("/actor"),
75
+ type: "Person",
76
+ inbox: compatible("/actor/inbox"),
77
+ outbox: compatible("/actor/outbox"),
78
+ gateways: [GATEWAY]
79
+ };
80
+ }
81
+ function createLoader(responses) {
82
+ const fetched = [];
83
+ const loader = (url) => {
84
+ url = url.replace(/^ap\+ef61:/, "ap:");
85
+ fetched.push(url);
86
+ const document = responses[url];
87
+ if (document == null) {
88
+ if (!URL.canParse(url)) return Promise.reject(/* @__PURE__ */ new Error(`Not found: ${url}`));
89
+ if (!url.includes("/.well-known/apgateway/")) return mockDocumentLoader(url);
90
+ return Promise.reject(new FetchError(url, "HTTP 404", new Response(null, { status: 404 })));
91
+ }
92
+ return Promise.resolve({
93
+ contextUrl: null,
94
+ documentUrl: url,
95
+ document: structuredClone(document)
96
+ });
97
+ };
98
+ return Object.assign(loader, { fetched });
99
+ }
100
+ function createFederation(documentLoader, queue) {
101
+ return new FederationImpl({
102
+ kv: new MemoryKvStore(),
103
+ queue,
104
+ manuallyStartQueue: true,
105
+ contextLoaderFactory: () => mockDocumentLoader,
106
+ documentLoaderFactory: () => documentLoader
107
+ });
108
+ }
109
+ test("Context.verifyPortableObject", async (t) => {
110
+ const signed = await sign(note("/notes/1"));
111
+ const ctx = createFederation(createLoader({})).createContext(new URL("https://example.com/"));
112
+ await t.step("is an own property that survives spreading", () => {
113
+ assert(Object.hasOwn(ctx, "verifyPortableObject"));
114
+ assert({ ...ctx }.verifyPortableObject === ctx.verifyPortableObject);
115
+ assert(ctx.clone(void 0).verifyPortableObject != null);
116
+ });
117
+ await t.step("verifies portable objects with the context's loaders", async () => {
118
+ assertEquals((await ctx.verifyPortableObject(signed, {})).verified, true);
119
+ assertEquals((await ctx.verifyPortableObject(note("/notes/1"), {})).verified, false);
120
+ assertEquals((await ctx.verifyPortableObject({
121
+ ...signed,
122
+ content: "Forged"
123
+ }, {})).verified, false);
124
+ });
125
+ });
126
+ test("accessors given a Context verify references of compatible-ID objects", async (t) => {
127
+ const signed = await sign(note("/notes/1"));
128
+ const create = () => Create.fromJsonLd(activity(compatible("/notes/1")), { contextLoader: mockDocumentLoader });
129
+ await t.step("a signed object at the reference", async () => {
130
+ const loader = createLoader({ [compatible("/notes/1")]: signed });
131
+ const ctx = createFederation(loader).createContext(new URL("https://example.com/"));
132
+ const object = await (await create()).getObject(ctx);
133
+ assertInstanceOf(object, Note);
134
+ assertEquals(object.content, "A portable note");
135
+ assertEquals(loader.fetched, [compatible("/notes/1")]);
136
+ });
137
+ await t.step("an unsigned object at the reference", async () => {
138
+ const ctx = createFederation(createLoader({ [compatible("/notes/1")]: note("/notes/1") })).createContext(new URL("https://example.com/"));
139
+ assertEquals(await (await create()).getObject(ctx), null);
140
+ });
141
+ await t.step("a forged object at the reference", async () => {
142
+ const ctx = createFederation(createLoader({ [compatible("/notes/1")]: {
143
+ ...signed,
144
+ content: "Forged"
145
+ } })).createContext(new URL("https://example.com/"));
146
+ assertEquals(await (await create()).getObject(ctx), null);
147
+ });
148
+ await t.step("an ordinary object's compatible reference", async () => {
149
+ const loader = createLoader({ [compatible("/notes/1")]: note("/notes/1") });
150
+ const ctx = createFederation(loader).createContext(new URL("https://example.com/"));
151
+ const create = await Create.fromJsonLd(activity(compatible("/notes/1"), "https://example.com/activities/1"), { contextLoader: mockDocumentLoader });
152
+ assertEquals(await create.getObject(ctx), null);
153
+ assertInstanceOf(await create.getObject({
154
+ documentLoader: loader,
155
+ contextLoader: mockDocumentLoader
156
+ }), Note);
157
+ });
158
+ });
159
+ function createRecordingQueue() {
160
+ const queued = [];
161
+ return {
162
+ queued,
163
+ queue: {
164
+ enqueue(message) {
165
+ queued.push(message);
166
+ return Promise.resolve();
167
+ },
168
+ listen() {
169
+ return Promise.resolve();
170
+ }
171
+ }
172
+ };
173
+ }
174
+ test("inbox listeners dereference references of compatible-ID activities without options", async (t) => {
175
+ const signedNote = await sign(note("/notes/1"));
176
+ const signedCreate = await sign(activity(compatible("/notes/1")));
177
+ for (const queued of [false, true]) for (const [label, served] of [["signed", signedNote], ["unsigned", note("/notes/1")]]) await t.step(`${label} object${queued ? " through a queue" : ""}`, async () => {
178
+ const loader = createLoader({ [compatible("/notes/1")]: served });
179
+ const { queue, queued: messages } = createRecordingQueue();
180
+ const federation = createFederation(loader, queued ? queue : void 0);
181
+ const results = [];
182
+ federation.setActorDispatcher("/users/{identifier}", () => null);
183
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, async (_ctx, create) => {
184
+ const object = await create.getObject();
185
+ assert(object == null || object instanceof Note);
186
+ results.push(object);
187
+ });
188
+ assertEquals((await federation.fetch(new Request("https://example.com/inbox", {
189
+ method: "POST",
190
+ headers: { "Content-Type": "application/activity+json" },
191
+ body: JSON.stringify(signedCreate)
192
+ }), { contextData: void 0 })).status, 202);
193
+ if (queued) {
194
+ assertEquals(messages.length, 1);
195
+ assertEquals(messages[0].type, "inbox");
196
+ await federation.processQueuedTask(void 0, messages[0]);
197
+ }
198
+ assertEquals(results.length, 1);
199
+ if (label === "signed") {
200
+ assertInstanceOf(results[0], Note);
201
+ assertEquals(results[0].content, "A portable note");
202
+ } else assertEquals(results[0], null);
203
+ assertEquals(loader.fetched, [compatible("/notes/1")]);
204
+ });
205
+ });
206
+ test("verifyObject() does not leave its proof verifier to returned objects", async () => {
207
+ const proofUrl = `ap://${did}/proofs/1`;
208
+ const { proof, ...document } = await sign(activity(compatible("/notes/1")), { id: proofUrl });
209
+ const referenced = {
210
+ ...document,
211
+ "https://w3id.org/security#proof": [{ "@graph": [proof] }, { "@graph": [{ "@id": proofUrl }] }]
212
+ };
213
+ const loader = createLoader({ [proofUrl]: proof });
214
+ const verifier = () => Promise.resolve({ verified: false });
215
+ for (const verifyPortableObject of [void 0, verifier]) {
216
+ const create = await verifyObject(Create, referenced, {
217
+ contextLoader: mockDocumentLoader,
218
+ documentLoader: loader,
219
+ verifyPortableObject
220
+ });
221
+ assertInstanceOf(create, Create);
222
+ assert(loader.fetched.includes(proofUrl));
223
+ const proofs = await Array.fromAsync(create.getProofs());
224
+ assertEquals(proofs.length, 2);
225
+ for (const p of proofs) {
226
+ assertInstanceOf(p, DataIntegrityProof);
227
+ assert(p._verifyPortableObject === verifyPortableObject);
228
+ }
229
+ assert(create._verifyPortableObject === verifyPortableObject);
230
+ }
231
+ });
232
+ test("Context.lookupObject() applies the gateway policy to unsecured collections", async (t) => {
233
+ const outbox = {
234
+ "@context": context,
235
+ id: compatible("/actor/outbox"),
236
+ type: "OrderedCollection",
237
+ attributedTo: compatible("/actor"),
238
+ orderedItems: [compatible("/notes/1")]
239
+ };
240
+ const signedActor = await sign(actor());
241
+ await t.step("from a listed gateway", async () => {
242
+ const ctx = createFederation(createLoader({
243
+ [compatible("/actor")]: signedActor,
244
+ [compatible("/actor/outbox")]: outbox,
245
+ [compatible("/notes/1")]: note("/notes/1")
246
+ })).createContext(new URL("https://example.com/"));
247
+ const collection = await ctx.lookupObject(compatible("/actor/outbox"));
248
+ assertInstanceOf(collection, OrderedCollection);
249
+ assertEquals(await Array.fromAsync(collection.getItems()), []);
250
+ assertEquals(await Array.fromAsync(traverseCollection(collection, ctx)), []);
251
+ assertEquals(await ctx.lookupObject(compatible("/actor/outbox"), { verifyPortableObject: verifyPortableObjectProof }), null);
252
+ });
253
+ await t.step("from an unlisted gateway", async () => {
254
+ const evil = "https://evil.example";
255
+ assertEquals(await createFederation(createLoader({
256
+ [compatible("/actor", evil)]: signedActor,
257
+ [compatible("/actor/outbox", evil)]: {
258
+ ...outbox,
259
+ id: compatible("/actor/outbox", evil)
260
+ }
261
+ })).createContext(new URL("https://example.com/")).lookupObject(compatible("/actor/outbox", evil)), null);
262
+ });
263
+ await t.step("with signed items", async () => {
264
+ const collection = await createFederation(createLoader({
265
+ [compatible("/actor")]: signedActor,
266
+ [compatible("/actor/outbox")]: outbox,
267
+ [compatible("/notes/1")]: await sign(note("/notes/1"))
268
+ })).createContext(new URL("https://example.com/")).lookupObject(compatible("/actor/outbox"));
269
+ assertInstanceOf(collection, OrderedCollection);
270
+ const items = await Array.fromAsync(collection.getItems());
271
+ assertEquals(items.length, 1);
272
+ assertInstanceOf(items[0], Note);
273
+ });
274
+ });
275
+ test("traverseCollection() with a Context verifies pages and items of portable collections", async () => {
276
+ const loader = createLoader({
277
+ [compatible("/actor")]: await sign(actor()),
278
+ [compatible("/actor/outbox")]: {
279
+ "@context": context,
280
+ id: compatible("/actor/outbox"),
281
+ type: "OrderedCollection",
282
+ first: compatible("/actor/outbox/1")
283
+ },
284
+ [compatible("/actor/outbox/1")]: {
285
+ "@context": context,
286
+ id: compatible("/actor/outbox/1"),
287
+ type: "OrderedCollectionPage",
288
+ partOf: compatible("/actor/outbox"),
289
+ orderedItems: [compatible("/notes/1"), compatible("/notes/2")]
290
+ },
291
+ [compatible("/notes/1")]: await sign(note("/notes/1")),
292
+ [compatible("/notes/2")]: note("/notes/2", "Unsigned")
293
+ });
294
+ const ctx = createFederation(loader).createContext(new URL("https://example.com/"));
295
+ const outbox = await (await Person.fromJsonLd(actor(), { contextLoader: mockDocumentLoader })).getOutbox(ctx);
296
+ assertInstanceOf(outbox, OrderedCollection);
297
+ const items = await Array.fromAsync(traverseCollection(outbox, ctx));
298
+ assertEquals(items.length, 1);
299
+ assertInstanceOf(items[0], Note);
300
+ assertEquals(items[0].content, "A portable note");
301
+ let error;
302
+ try {
303
+ await items[0].getAttribution({ documentLoader: loader });
304
+ } catch (e) {
305
+ error = e;
306
+ }
307
+ assertInstanceOf(error, TypeError);
308
+ assertInstanceOf(await items[0].getAttribution(ctx), Person);
309
+ });
310
+ test("onOutboxError receives activities that verify portable objects by default", async () => {
311
+ const loader = createLoader({ [compatible("/notes/1")]: await sign(note("/notes/1")) });
312
+ const received = [];
313
+ const federation = new FederationImpl({
314
+ kv: new MemoryKvStore(),
315
+ queue: createRecordingQueue().queue,
316
+ manuallyStartQueue: true,
317
+ contextLoaderFactory: () => mockDocumentLoader,
318
+ documentLoaderFactory: () => loader,
319
+ authenticatedDocumentLoaderFactory: () => loader,
320
+ onOutboxError: async (_error, activity) => {
321
+ try {
322
+ received.push(await activity?.getObject());
323
+ } catch (error) {
324
+ received.push(error);
325
+ }
326
+ }
327
+ });
328
+ const message = {
329
+ type: "outbox",
330
+ id: crypto.randomUUID(),
331
+ baseUrl: "https://example.com",
332
+ keys: [{
333
+ keyId: rsaPublicKey2.id.href,
334
+ privateKey: await exportJwk(rsaPrivateKey2)
335
+ }],
336
+ activity: await sign(activity(compatible("/notes/1"))),
337
+ activityId: compatible("/activities/1"),
338
+ activityType: "https://www.w3.org/ns/activitystreams#Create",
339
+ inbox: "https://remote.example/inbox",
340
+ sharedInbox: false,
341
+ started: (/* @__PURE__ */ new Date()).toISOString(),
342
+ attempt: 0,
343
+ headers: {},
344
+ traceContext: {}
345
+ };
346
+ esm_default.spyGlobal();
347
+ esm_default.post("https://remote.example/inbox", 500);
348
+ try {
349
+ await federation.processQueuedTask(void 0, message);
350
+ } finally {
351
+ esm_default.hardReset();
352
+ }
353
+ assertEquals(received.length, 1);
354
+ assertInstanceOf(received[0], Note);
355
+ assertEquals(loader.fetched, [compatible("/notes/1")]);
356
+ });
357
+ //#endregion
358
+ export {};
@@ -2,15 +2,15 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
- import { r as createRequestContext, t as createInboxContext } from "../context-CoNRxGYp.mjs";
5
+ import { r as createRequestContext, t as createInboxContext } from "../context-DfSVPcJ8.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
7
7
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
8
8
  import "../std__assert-DvMDRPes.mjs";
9
9
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
10
- import { p as signJsonLd } from "../ld-u4JOD4iO.mjs";
11
- import { l as signRequest } from "../http-B9BQDNIy.mjs";
10
+ import { p as signJsonLd } from "../ld-DQNTIrAe.mjs";
11
+ import { l as signRequest } from "../http-BFeK9sBg.mjs";
12
12
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
13
- import { f as handleInbox, n as FederationImpl, o as createFederation } from "../middleware-CgOqRkK-.mjs";
13
+ import { f as handleInbox, n as FederationImpl, o as createFederation } from "../middleware-BdhvduR9.mjs";
14
14
  import { t as ActivityListenerSet } from "../activity-listener-C-BSbKI7.mjs";
15
15
  import { t as KvKeyCache } from "../keycache-BInaECGj.mjs";
16
16
  import { Create, CryptographicKey, Person } from "@fedify/vocab";
@@ -8,11 +8,11 @@ import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
8
8
  import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
9
9
  import "../std__assert-DvMDRPes.mjs";
10
10
  import { t as assert } from "../assert-D1Eafmd_.mjs";
11
- import { p as signJsonLd } from "../ld-u4JOD4iO.mjs";
12
- import { i as signObject } from "../proof-BCOg7Njv.mjs";
13
- import { f as verifyRequestDetailed, l as signRequest } from "../http-B9BQDNIy.mjs";
11
+ import { p as signJsonLd } from "../ld-DQNTIrAe.mjs";
12
+ import { i as signObject } from "../proof-CW8k0R1G.mjs";
13
+ import { f as verifyRequestDetailed, l as signRequest } from "../http-BFeK9sBg.mjs";
14
14
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
15
- import { _ as coversDelivery, o as createFederation, v as forwardPortableInboxActivity, y as resolvePortableInboxForwardingOptions } from "../middleware-CgOqRkK-.mjs";
15
+ import { _ as coversDelivery, o as createFederation, v as forwardPortableInboxActivity, y as resolvePortableInboxForwardingOptions } from "../middleware-BdhvduR9.mjs";
16
16
  import { Create, CryptographicKey, Follow, Note, Person, Tombstone } from "@fedify/vocab";
17
17
  import { mockDocumentLoader, test } from "@fedify/fixture";
18
18
  import { exportDidKey, formatIri, parseIri } from "@fedify/vocab-runtime";
@@ -8,10 +8,10 @@ import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
8
8
  import "../std__assert-DvMDRPes.mjs";
9
9
  import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
10
10
  import { t as assert } from "../assert-D1Eafmd_.mjs";
11
- import { i as signObject, s as verifyPortableObjectProof } from "../proof-BCOg7Njv.mjs";
12
- import { l as signRequest } from "../http-B9BQDNIy.mjs";
11
+ import { i as signObject, s as verifyPortableObjectProof } from "../proof-CW8k0R1G.mjs";
12
+ import { l as signRequest } from "../http-BFeK9sBg.mjs";
13
13
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
14
- import { b as PORTABLE_OBJECT_CONTENT_TYPE, o as createFederation } from "../middleware-CgOqRkK-.mjs";
14
+ import { b as PORTABLE_OBJECT_CONTENT_TYPE, o as createFederation } from "../middleware-BdhvduR9.mjs";
15
15
  import { configure, reset } from "@logtape/logtape";
16
16
  import { Collection, Create, Note, Object as Object$1, Person, Tombstone, lookupObject } from "@fedify/vocab";
17
17
  import { mockDocumentLoader, test } from "@fedify/fixture";
@@ -10,10 +10,10 @@ import { t as assertNotEquals } from "../assert_not_equals-CpPK2t89.mjs";
10
10
  import "../std__assert-DvMDRPes.mjs";
11
11
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
12
12
  import { t as assert } from "../assert-D1Eafmd_.mjs";
13
- import { d as verifyRequest } from "../http-B9BQDNIy.mjs";
13
+ import { d as verifyRequest } from "../http-BFeK9sBg.mjs";
14
14
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
15
- import { t as doesActorOwnKey } from "../owner-CPFM-sqo.mjs";
16
- import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "../send-C8eOPat3.mjs";
15
+ import { t as doesActorOwnKey } from "../owner-CCfdL83M.mjs";
16
+ import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "../send--FORaIc4.mjs";
17
17
  import { Activity, Application, Endpoints, Group, Person, Service } from "@fedify/vocab";
18
18
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
19
19
  import { FetchError, UrlError } from "@fedify/vocab-runtime";
@@ -3,8 +3,8 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../../kv-DCHkaJ9-.mjs";
5
5
  import { a as numberSchema, i as makeSchema, n as baseOptions, o as stringSchema, t as MockQueue } from "../../tasks-dbCShlCb.mjs";
6
- import "../../testing-BWq1dCzx.mjs";
7
- import { o as createFederation } from "../../middleware-CgOqRkK-.mjs";
6
+ import "../../testing-otQhu4aD.mjs";
7
+ import { o as createFederation } from "../../middleware-BdhvduR9.mjs";
8
8
  import { n as ParallelMessageQueue } from "../../mq-Dm1Wmtm-.mjs";
9
9
  import { configure, reset } from "@logtape/logtape";
10
10
  import { delay } from "es-toolkit";
@@ -3,9 +3,9 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../../kv-DCHkaJ9-.mjs";
5
5
  import { a as numberSchema, i as makeSchema, n as baseOptions, o as stringSchema, t as MockQueue } from "../../tasks-dbCShlCb.mjs";
6
- import "../../testing-BWq1dCzx.mjs";
7
- import { o as createFederation } from "../../middleware-CgOqRkK-.mjs";
8
- import { r as createFederationBuilder } from "../../builder-BCXywsZF.mjs";
6
+ import "../../testing-otQhu4aD.mjs";
7
+ import { o as createFederation } from "../../middleware-BdhvduR9.mjs";
8
+ import { r as createFederationBuilder } from "../../builder-B2bgGYbP.mjs";
9
9
  import { t as TaskCodec } from "../../codec-C6rTrpIp.mjs";
10
10
  import { t as InProcessMessageQueue } from "../../mq-Dm1Wmtm-.mjs";
11
11
  import { W3CTraceContextPropagator } from "@opentelemetry/core";
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
5
5
  import "../std__assert-DvMDRPes.mjs";
6
6
  import { t as assert } from "../assert-D1Eafmd_.mjs";
7
- import { t as hasMalformedKnownTemporalLiteral } from "../temporal-vjHOhBpy.mjs";
7
+ import { t as hasMalformedKnownTemporalLiteral } from "../temporal-CffY_XOJ.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/federation/temporal.test.ts
10
10
  test("hasMalformedKnownTemporalLiteral() detects expanded proof timestamps", async () => {
@@ -1,12 +1,12 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { r as createRequestContext } from "../context-CoNRxGYp.mjs";
4
+ import { r as createRequestContext } from "../context-DfSVPcJ8.mjs";
5
5
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
7
  import { t as assertNotEquals } from "../assert_not_equals-CpPK2t89.mjs";
8
8
  import "../std__assert-DvMDRPes.mjs";
9
- import { o as createFederation, s as handleWebFinger } from "../middleware-CgOqRkK-.mjs";
9
+ import { o as createFederation, s as handleWebFinger } from "../middleware-BdhvduR9.mjs";
10
10
  import { Image, Link, Person, Tombstone } from "@fedify/vocab";
11
11
  import { createTestMeterProvider, test } from "@fedify/fixture";
12
12
  import { parseIri } from "@fedify/vocab-runtime";
@@ -1,10 +1,10 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  const require_rolldown_runtime = require("./rolldown-runtime-Dmm3t92W.cjs");
3
3
  const require_transformers = require("./transformers-BalCrSsr.cjs");
4
- const require_http = require("./http-4bmgw-mA.cjs");
4
+ const require_http = require("./http-o8l4QeUY.cjs");
5
5
  const require_types = require("./types-Be2zbyeG.cjs");
6
- const require_owner = require("./owner-DkA0Lz7v.cjs");
7
- const require_kv_cache = require("./kv-cache-D2Bz6t_c.cjs");
6
+ const require_portable_collection = require("./portable-collection-DXogVs__.cjs");
7
+ const require_kv_cache = require("./kv-cache-BUkgZAcX.cjs");
8
8
  let _logtape_logtape = require("@logtape/logtape");
9
9
  let _fedify_uri_template = require("@fedify/uri-template");
10
10
  let _fedify_vocab = require("@fedify/vocab");
@@ -4512,7 +4512,8 @@ async function handleInboxInternal(request, parameters, span) {
4512
4512
  documentLoader: ctx.documentLoader,
4513
4513
  keyCache,
4514
4514
  meterProvider,
4515
- tracerProvider
4515
+ tracerProvider,
4516
+ verifyPortableObject: ctx.verifyPortableObject
4516
4517
  });
4517
4518
  } catch (error) {
4518
4519
  if (error instanceof RangeError && await hasMalformedKnownTemporalLiteral(jsonWithoutSig, ctx.contextLoader)) return await respondInvalidActivity(error);
@@ -4714,7 +4715,7 @@ async function handleInboxInternal(request, parameters, span) {
4714
4715
  });
4715
4716
  }
4716
4717
  }
4717
- if (httpSigKey != null && !await require_owner.doesActorOwnKey(activity, httpSigKey, ctx)) {
4718
+ if (httpSigKey != null && !await require_portable_collection.doesActorOwnKey(activity, httpSigKey, ctx)) {
4718
4719
  if (deferredLdSignatureError != null) throw deferredLdSignatureError;
4719
4720
  require_http.getFederationMetrics(parameters.meterProvider).recordSignatureVerificationFailure("actorKeyMismatch", httpSigKey.id == null ? void 0 : require_http.getRemoteHost(httpSigKey.id));
4720
4721
  logger.error("The signer ({keyId}) and the actor ({actorId}) do not match.", {
@@ -7211,11 +7212,16 @@ var FederationImpl = class extends FederationBuilderImpl {
7211
7212
  });
7212
7213
  return parsedActorIds;
7213
7214
  };
7214
- const parseActivity = () => _fedify_vocab.Activity.fromJsonLd(message.activity, {
7215
- contextLoader: this.contextLoaderFactory(loaderOptions),
7216
- documentLoader: rsaKeyPair == null ? this.documentLoaderFactory(loaderOptions) : this.authenticatedDocumentLoaderFactory(rsaKeyPair, loaderOptions),
7217
- tracerProvider: this.tracerProvider
7218
- });
7215
+ const parseActivity = () => {
7216
+ const contextLoader = this.contextLoaderFactory(loaderOptions);
7217
+ const documentLoader = rsaKeyPair == null ? this.documentLoaderFactory(loaderOptions) : this.authenticatedDocumentLoaderFactory(rsaKeyPair, loaderOptions);
7218
+ return _fedify_vocab.Activity.fromJsonLd(message.activity, {
7219
+ contextLoader,
7220
+ documentLoader,
7221
+ tracerProvider: this.tracerProvider,
7222
+ verifyPortableObject: createPortableObjectVerifier(documentLoader, contextLoader, this)
7223
+ });
7224
+ };
7219
7225
  const enqueueHeldOutboxMessage = async (delay, heldSince) => {
7220
7226
  const { outboxQueue } = this;
7221
7227
  if (outboxQueue == null) return;
@@ -8691,12 +8697,28 @@ function getCollectionMetricRoute(routeName) {
8691
8697
  }
8692
8698
  }
8693
8699
  const FANOUT_THRESHOLD = 5;
8700
+ /**
8701
+ * Creates the FEP-ef61 portable object verifier that a context applies to
8702
+ * portable objects it dereferences: `verifyPortableObject()` with the given
8703
+ * loaders and the federation's tracer provider as defaults. Other options,
8704
+ * such as the document URL, gateways, and referrer, are passed through as
8705
+ * they are.
8706
+ */
8707
+ function createPortableObjectVerifier(documentLoader, contextLoader, federation) {
8708
+ return (document, options = {}) => require_portable_collection.verifyPortableObject(document, {
8709
+ ...options,
8710
+ documentLoader: options.documentLoader ?? documentLoader,
8711
+ contextLoader: options.contextLoader ?? contextLoader,
8712
+ tracerProvider: options.tracerProvider ?? federation.tracerProvider
8713
+ });
8714
+ }
8694
8715
  var ContextImpl = class ContextImpl {
8695
8716
  url;
8696
8717
  federation;
8697
8718
  data;
8698
8719
  documentLoader;
8699
8720
  contextLoader;
8721
+ verifyPortableObject;
8700
8722
  invokedFromActorKeyPairsDispatcher;
8701
8723
  #codec;
8702
8724
  constructor({ url, federation, data, documentLoader, contextLoader, invokedFromActorKeyPairsDispatcher }) {
@@ -8705,6 +8727,7 @@ var ContextImpl = class ContextImpl {
8705
8727
  this.data = data;
8706
8728
  this.documentLoader = documentLoader;
8707
8729
  this.contextLoader = contextLoader;
8730
+ this.verifyPortableObject = createPortableObjectVerifier(documentLoader, contextLoader, federation);
8708
8731
  this.invokedFromActorKeyPairsDispatcher = invokedFromActorKeyPairsDispatcher;
8709
8732
  }
8710
8733
  /**
@@ -9056,7 +9079,7 @@ var ContextImpl = class ContextImpl {
9056
9079
  userAgent: options.userAgent ?? this.federation.userAgent,
9057
9080
  tracerProvider: options.tracerProvider ?? this.tracerProvider,
9058
9081
  meterProvider: options.meterProvider ?? this.meterProvider,
9059
- verifyPortableObject: options.verifyPortableObject ?? require_http.verifyPortableObjectProof,
9082
+ verifyPortableObject: options.verifyPortableObject ?? this.verifyPortableObject,
9060
9083
  allowPrivateAddress: this.federation.allowPrivateAddress
9061
9084
  });
9062
9085
  }
@@ -9064,7 +9087,8 @@ var ContextImpl = class ContextImpl {
9064
9087
  return (0, _fedify_vocab.traverseCollection)(collection, {
9065
9088
  ...options,
9066
9089
  documentLoader: options.documentLoader ?? this.documentLoader,
9067
- contextLoader: options.contextLoader ?? this.contextLoader
9090
+ contextLoader: options.contextLoader ?? this.contextLoader,
9091
+ verifyPortableObject: options.verifyPortableObject ?? this.verifyPortableObject
9068
9092
  });
9069
9093
  }
9070
9094
  lookupNodeInfo(url, options = {}) {
@@ -9490,7 +9514,7 @@ var RequestContextImpl = class RequestContextImpl extends ContextImpl {
9490
9514
  const key = await this.getSignedKey(options);
9491
9515
  if (key == null) return this.#signedKeyOwner = null;
9492
9516
  try {
9493
- return this.#signedKeyOwner = await require_owner.getKeyOwner(key, {
9517
+ return this.#signedKeyOwner = await require_portable_collection.getKeyOwner(key, {
9494
9518
  contextLoader: options.contextLoader ?? this.contextLoader,
9495
9519
  documentLoader: options.documentLoader ?? this.documentLoader,
9496
9520
  tracerProvider: options.tracerProvider ?? this.tracerProvider
@@ -1,11 +1,11 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-BZrnW0Qz.mjs";
5
- import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-DCLoLvLz.mjs";
4
+ import { n as version, t as name } from "./deno-Be9xoxps.mjs";
5
+ import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-DDE9S63Q.mjs";
6
6
  import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-CPVqki78.mjs";
7
- import { a as fetchKeyDetailed, c as validateCryptoKey, t as bypassKeyCacheReads } from "./key-PyYvun0F.mjs";
8
- import { n as verifyPortableGatewayKeyDocument } from "./portable-key-DyylakVV.mjs";
7
+ import { a as fetchKeyDetailed, c as validateCryptoKey, t as bypassKeyCacheReads } from "./key-Cc1b6pW9.mjs";
8
+ import { n as verifyPortableGatewayKeyDocument } from "./portable-key-C-fPq_Yf.mjs";
9
9
  import { getLogger } from "@logtape/logtape";
10
10
  import { CryptographicKey } from "@fedify/vocab";
11
11
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -14,7 +14,7 @@ import serialize from "json-canon";
14
14
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
15
15
  //#region deno.json
16
16
  var name = "@fedify/fedify";
17
- var version = "2.4.0-dev.2122+bdc0ce8d";
17
+ var version = "2.4.0-dev.2127+c41ce2eb";
18
18
  //#endregion
19
19
  //#region src/sig/portable-key-id.ts
20
20
  const COMPATIBLE_KEY_ID_PATH_PATTERN = /^\/\.well-known\/apgateway\/did(?::|%3A)/i;
@@ -16,7 +16,7 @@ json_canon = require_rolldown_runtime.__toESM(json_canon, 1);
16
16
  let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
17
17
  //#region deno.json
18
18
  var name = "@fedify/fedify";
19
- var version = "2.4.0-dev.2122+bdc0ce8d";
19
+ var version = "2.4.0-dev.2127+c41ce2eb";
20
20
  //#endregion
21
21
  //#region src/sig/portable-key-id.ts
22
22
  const COMPATIBLE_KEY_ID_PATH_PATTERN = /^\/\.well-known\/apgateway\/did(?::|%3A)/i;
@@ -1,8 +1,8 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-BZrnW0Qz.mjs";
5
- import { _ as recordKeyLookup, n as getDurationMs, t as classifyFetchError } from "./metrics-DCLoLvLz.mjs";
4
+ import { n as version, t as name } from "./deno-Be9xoxps.mjs";
5
+ import { _ as recordKeyLookup, n as getDurationMs, t as classifyFetchError } from "./metrics-DDE9S63Q.mjs";
6
6
  import { a as isCompatibleKeyId, o as isPortableActorDocument, s as isPortableId } from "./portable-key-id-T7lecIbt.mjs";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { CryptographicKey, Multikey, Object as Object$1, isActor } from "@fedify/vocab";