@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
@@ -1,427 +1,16 @@
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 { l as verifyPortableObjectProofWithRoot, s as verifyPortableObjectProof } from "../proof-BCOg7Njv.mjs";
6
4
  import { n as ed25519PrivateKey, r as ed25519PublicKey } from "../keys-DIJNHW-Y.mjs";
7
- import { getLogger } from "@logtape/logtape";
8
- import { Collection, CollectionPage, Note, Object as Object$1, OrderedCollection, Person, isActor, traverseCollection } from "@fedify/vocab";
9
- import { trace } from "@opentelemetry/api";
5
+ import { t as verifyPortableObject } from "../portable-collection-WXaHkNqC.mjs";
6
+ import { Collection, CollectionPage, Note, OrderedCollection, Person, traverseCollection } from "@fedify/vocab";
10
7
  import { test } from "@fedify/fixture";
11
- import { FetchError, canonicalizePortableUri, encodeMultibase, exportDidKey, formatIri, fromCompatibleEf61Id, getDocumentLoader, getFe34Origin, parseIri, preloadedContexts } from "@fedify/vocab-runtime";
12
- import { dereferencePortableIri, getPortableGatewayCandidates } from "@fedify/vocab-runtime/internal/portable-dereference";
8
+ import { FetchError, encodeMultibase, exportDidKey, preloadedContexts } from "@fedify/vocab-runtime";
13
9
  import serialize from "json-canon";
14
10
  import { deepStrictEqual, ok, strictEqual } from "node:assert/strict";
15
- //#region src/sig/portable-collection.ts
16
- const logger = getLogger([
17
- "fedify",
18
- "sig",
19
- "proof"
20
- ]);
21
- const AS_NAMESPACE = "https://www.w3.org/ns/activitystreams#";
22
- const AS_ATTRIBUTED_TO = `${AS_NAMESPACE}attributedTo`;
23
- const AS_PART_OF = `${AS_NAMESPACE}partOf`;
24
- /**
25
- * The properties through which a collection refers to its pages, and a page
26
- * to other pages of the same collection.
27
- */
28
- const PAGING_PROPERTIES = new Set([
29
- "first",
30
- "last",
31
- "current",
32
- "next",
33
- "prev"
34
- ].map((p) => AS_NAMESPACE + p));
35
- /**
36
- * The properties through which an actor refers to its own collections.
37
- */
38
- const ACTOR_COLLECTION_PROPERTIES = /* @__PURE__ */ new Set([
39
- "http://www.w3.org/ns/ldp#inbox",
40
- `${AS_NAMESPACE}outbox`,
41
- `${AS_NAMESPACE}followers`,
42
- `${AS_NAMESPACE}following`,
43
- `${AS_NAMESPACE}liked`
44
- ]);
45
- const contextStates = /* @__PURE__ */ new WeakMap();
46
- function createContext(state) {
47
- const token = Object.freeze(Object.create(null));
48
- contextStates.set(token, state);
49
- return token;
50
- }
51
- function getContextState(context) {
52
- if (context == null || typeof context !== "object") return void 0;
53
- return contextStates.get(context);
54
- }
55
- function canonicalize(id) {
56
- try {
57
- const portable = fromCompatibleEf61Id(id);
58
- if (portable != null) return canonicalizePortableUri(formatIri(portable));
59
- return canonicalizePortableUri(typeof id === "string" ? id : formatIri(id));
60
- } catch (error) {
61
- if (error instanceof TypeError) return null;
62
- throw error;
63
- }
64
- }
65
- function toUrl(canonicalId) {
66
- return parseIri(canonicalId);
67
- }
68
- function canonicalizeAll(ids) {
69
- const result = [];
70
- for (const id of ids) {
71
- const canonical = canonicalize(id);
72
- if (canonical == null) return null;
73
- result.push(canonical);
74
- }
75
- return result;
76
- }
77
- function getExpandedIds(node, property) {
78
- const values = node[property];
79
- if (values == null) return [];
80
- if (!Array.isArray(values)) return null;
81
- const ids = [];
82
- for (const value of values) {
83
- if (value == null || typeof value !== "object" || Array.isArray(value) || typeof value["@id"] !== "string") return null;
84
- ids.push(value["@id"]);
85
- }
86
- return ids;
87
- }
88
- function parseAll(ids) {
89
- const result = [];
90
- for (const id of ids) try {
91
- result.push(parseIri(id));
92
- } catch (error) {
93
- if (error instanceof TypeError) return null;
94
- throw error;
95
- }
96
- return result;
97
- }
98
- function describeRoot(root) {
99
- const rawId = root["@id"];
100
- if (typeof rawId !== "string") return null;
101
- const id = canonicalize(rawId);
102
- if (id == null) return null;
103
- const partOf = getExpandedIds(root, AS_PART_OF);
104
- const attributedTo = getExpandedIds(root, AS_ATTRIBUTED_TO);
105
- return {
106
- id,
107
- url: toUrl(id),
108
- origin: getFe34Origin(id),
109
- partOf: partOf == null ? null : canonicalizeAll(partOf),
110
- attributedTo: attributedTo == null ? null : canonicalizeAll(attributedTo),
111
- attributedToUrls: attributedTo == null ? null : parseAll(attributedTo)
112
- };
113
- }
114
- function describeObject(object) {
115
- if (!(object instanceof Object$1) || object.id == null) return null;
116
- const id = canonicalize(object.id);
117
- if (id == null) return null;
118
- const partOfId = object instanceof CollectionPage ? object.partOfId : null;
119
- return {
120
- id,
121
- url: toUrl(id),
122
- origin: getFe34Origin(id),
123
- partOf: canonicalizeAll(partOfId == null ? [] : [partOfId]),
124
- attributedTo: canonicalizeAll(object.attributionIds),
125
- attributedToUrls: object.attributionIds
126
- };
127
- }
128
- function fail(reason) {
129
- return {
130
- verified: false,
131
- reason
132
- };
133
- }
134
- /**
135
- * Walks the referrer chain of a collection or page to find the root
136
- * collection and its owner candidate, checking every page on the way.
137
- */
138
- function resolveChain(node, referrer) {
139
- const pages = [];
140
- let top = node;
141
- let link = referrer;
142
- let state;
143
- while (link != null && PAGING_PROPERTIES.has(link.property)) {
144
- pages.push(top);
145
- state = getContextState(link.collectionContext);
146
- if (state != null) break;
147
- const parent = describeObject(link.object);
148
- if (parent == null || link.truncated) return fail({ type: "unknownCollectionOwner" });
149
- top = parent;
150
- link = link.referrer;
151
- }
152
- let rootId;
153
- let rootOrigin;
154
- let candidate;
155
- if (state != null) {
156
- rootId = state.rootId;
157
- rootOrigin = state.rootOrigin;
158
- const ownerCandidate = state.owner == null ? state.ownerCandidate : { id: canonicalize(state.owner.id) };
159
- if (ownerCandidate == null) return fail({ type: "unknownCollectionOwner" });
160
- candidate = ownerCandidate;
161
- } else {
162
- rootId = top.id;
163
- rootOrigin = top.origin;
164
- const attributedTo = top.attributedTo;
165
- if (attributedTo == null) return fail({ type: "unknownCollectionOwner" });
166
- if (link != null && ACTOR_COLLECTION_PROPERTIES.has(link.property)) {
167
- const id = link.id == null ? null : canonicalize(link.id);
168
- if (id == null) return fail({ type: "unknownCollectionOwner" });
169
- candidate = {
170
- id,
171
- object: link.object,
172
- acceptance: link.acceptance
173
- };
174
- } else if (attributedTo.length === 1) candidate = {
175
- id: attributedTo[0],
176
- url: top.attributedToUrls?.[0]
177
- };
178
- else if (attributedTo.length > 1) return fail({
179
- type: "conflictingCollectionOwners",
180
- candidates: attributedTo.map(toUrl)
181
- });
182
- else return fail({ type: "unknownCollectionOwner" });
183
- const conflict = attributedTo.find((id) => id !== candidate.id);
184
- if (conflict != null) return fail({
185
- type: "conflictingCollectionOwners",
186
- candidates: [toUrl(candidate.id), toUrl(conflict)]
187
- });
188
- }
189
- if (getFe34Origin(candidate.id) !== rootOrigin) return fail({ type: "unknownCollectionOwner" });
190
- for (const page of pages) {
191
- if (page.origin !== rootOrigin) return fail({
192
- type: "collectionPageMismatch",
193
- pageId: page.url,
194
- collectionId: toUrl(rootId),
195
- partOf: null
196
- });
197
- if (page.partOf == null) return fail({ type: "unknownCollectionOwner" });
198
- const partOf = page.partOf.find((id) => id !== rootId);
199
- if (partOf != null) return fail({
200
- type: "collectionPageMismatch",
201
- pageId: page.url,
202
- collectionId: toUrl(rootId),
203
- partOf: toUrl(partOf)
204
- });
205
- if (page.attributedTo == null) return fail({ type: "unknownCollectionOwner" });
206
- const conflict = page.attributedTo.find((id) => id !== candidate.id);
207
- if (conflict != null) return fail({
208
- type: "conflictingCollectionOwners",
209
- candidates: [toUrl(candidate.id), toUrl(conflict)]
210
- });
211
- }
212
- return {
213
- rootId,
214
- rootOrigin,
215
- owner: state?.owner ?? null,
216
- candidate
217
- };
218
- }
219
- function getActorCollectionIds(actor) {
220
- const ids = [];
221
- for (const id of [
222
- actor.inboxId,
223
- actor.outboxId,
224
- actor.followersId,
225
- actor.followingId,
226
- actor.likedId
227
- ]) {
228
- if (id == null) continue;
229
- const canonical = canonicalize(id);
230
- if (canonical != null) ids.push(canonical);
231
- }
232
- return ids;
233
- }
234
- async function fetchOwner(candidate, options) {
235
- const documentLoader = options.documentLoader ?? getDocumentLoader();
236
- const contextLoader = options.contextLoader ?? getDocumentLoader();
237
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
238
- const tracer = tracerProvider.getTracer(name, version);
239
- let inferredGateways;
240
- try {
241
- const portable = fromCompatibleEf61Id(candidate);
242
- if (portable != null) {
243
- inferredGateways = [new URL(candidate.origin)];
244
- candidate = portable;
245
- }
246
- } catch (error) {
247
- if (!(error instanceof TypeError)) throw error;
248
- logger.debug("The owner {owner} of a portable collection is a malformed compatible identifier.", { owner: candidate.href });
249
- return null;
250
- }
251
- const gateways = options.gateways ?? (inferredGateways != null || getPortableGatewayCandidates(candidate).length > 0 ? void 0 : options.gatewayHints);
252
- if (options.gateways != null) inferredGateways = void 0;
253
- const span = tracer.startSpan("activitypub.lookup_object");
254
- try {
255
- const object = await dereferencePortableIri(candidate, {
256
- documentLoader,
257
- contextLoader,
258
- tracerProvider,
259
- gateways,
260
- ...inferredGateways == null ? {} : { inferredGateways },
261
- verifyPortableObject: (document, verifierOptions) => verifyPortableObjectProof(document, {
262
- ...options,
263
- ...verifierOptions
264
- }),
265
- suppressError: true,
266
- span,
267
- parse: (document, parseOptions) => Object$1.fromJsonLd(document, {
268
- documentLoader,
269
- contextLoader: parseOptions.contextLoader,
270
- tracerProvider,
271
- baseUrl: parseOptions.baseUrl
272
- })
273
- });
274
- return isActor(object) ? object : null;
275
- } catch (error) {
276
- logger.debug("Failed to fetch the owner {owner} of a portable collection: {error}", {
277
- owner: formatIri(candidate),
278
- error
279
- });
280
- return null;
281
- } finally {
282
- span.end();
283
- }
284
- }
285
- async function resolveOwner(chain, options) {
286
- if (chain.owner != null) return chain.owner;
287
- const { candidate } = chain;
288
- const candidateUrl = toUrl(candidate.id);
289
- let actor = null;
290
- if (candidate.acceptance === "verified" && isActor(candidate.object) && candidate.object.id != null && canonicalize(candidate.object.id) === candidate.id) actor = candidate.object;
291
- else actor = await fetchOwner(candidate.url ?? (candidate.object instanceof Object$1 && candidate.object.id != null ? candidate.object.id : candidateUrl), options);
292
- if (actor == null || actor.id == null) return fail({
293
- type: "collectionOwnerUnavailable",
294
- owner: candidateUrl
295
- });
296
- const gateways = actor.gateways;
297
- if (gateways.length < 1) return fail({
298
- type: "collectionOwnerUnavailable",
299
- owner: candidateUrl
300
- });
301
- if (!getActorCollectionIds(actor).includes(chain.rootId)) return fail({
302
- type: "collectionNotListedByOwner",
303
- owner: candidateUrl,
304
- collectionId: toUrl(chain.rootId)
305
- });
306
- return {
307
- id: candidateUrl,
308
- gateways
309
- };
310
- }
311
- function getSourceGateway(node, documentUrl) {
312
- if (documentUrl == null || documentUrl.protocol !== "http:" && documentUrl.protocol !== "https:") return null;
313
- let portableId;
314
- try {
315
- portableId = fromCompatibleEf61Id(documentUrl);
316
- } catch (error) {
317
- if (error instanceof TypeError) return null;
318
- throw error;
319
- }
320
- if (portableId == null || canonicalize(portableId) !== node.id) return null;
321
- return new URL(documentUrl.origin);
322
- }
323
- /**
324
- * Applies the [FEP-ef61] trust policy to a portable object fetched through
325
- * a gateway.
326
- *
327
- * Portable actors, activities, objects, and collections with proofs are
328
- * verified by {@link verifyPortableObjectProof}. A portable collection or
329
- * collection page without a proof is accepted only if all of the following
330
- * hold:
331
- *
332
- * - It was retrieved from a gateway: its final URL (`documentUrl`) is
333
- * a compatible identifier for the same portable collection.
334
- * - Its owner is determined unambiguously: the actor whose `inbox`,
335
- * `outbox`, `followers`, `following`, or `liked` property referred to
336
- * the collection, or the single actor in its `attributedTo`. A page
337
- * inherits the owner of the collection it was reached from through
338
- * `first`, `last`, `current`, `next`, or `prev`, and must not name
339
- * another collection in `partOf`.
340
- * - The owner's actor document is verified by its proof and lists the
341
- * collection as its `inbox`, `outbox`, `followers`, `following`, or
342
- * `liked`.
343
- * - The gateway that served the collection is in the owner's `gateways`.
344
- *
345
- * Where the document came from and which object referred to it are passed
346
- * by property accessors when this function is used as their
347
- * `verifyPortableObject` option. Objects embedded in an unsecured
348
- * collection accepted this way are not trusted: accessors dereference and
349
- * verify them one by one.
350
- *
351
- * Note that acceptance through the gateway policy does not verify anything
352
- * cryptographically; it only means that the owner trusts the gateway.
353
- *
354
- * [FEP-ef61]: https://w3id.org/fep/ef61
355
- *
356
- * @param jsonLd The JSON-LD document to verify.
357
- * @param options Additional options. See also
358
- * {@link VerifyPortableObjectOptions}.
359
- * @returns The detailed result.
360
- * @throws {TypeError} If the input is not a single JSON-LD object or has a
361
- * malformed portable ID.
362
- * @since 2.4.0
363
- */
364
- async function verifyPortableObject(jsonLd, options = {}) {
365
- const { result, root, objectType } = await verifyPortableObjectProofWithRoot(jsonLd, options);
366
- if (result.verified) {
367
- const node = objectType === "collection" && root != null ? describeRoot(root) : null;
368
- const chain = node == null ? null : resolveChain(node, options.referrer);
369
- if (chain == null || !("rootId" in chain)) return {
370
- verified: true,
371
- method: "proof",
372
- keys: result.keys
373
- };
374
- return {
375
- verified: true,
376
- method: "proof",
377
- keys: result.keys,
378
- collectionContext: createContext({
379
- rootId: chain.rootId,
380
- rootOrigin: chain.rootOrigin,
381
- owner: chain.owner,
382
- ownerCandidate: chain.candidate
383
- })
384
- };
385
- }
386
- if (result.reason.type !== "unsecuredCollection") return {
387
- verified: false,
388
- reason: result.reason
389
- };
390
- const node = root == null ? null : describeRoot(root);
391
- if (node == null) return fail({ type: "unknownCollectionOwner" });
392
- const gateway = getSourceGateway(node, options.documentUrl);
393
- if (gateway == null) return fail({
394
- type: "unknownCollectionSource",
395
- documentUrl: options.documentUrl ?? null
396
- });
397
- const chain = resolveChain(node, options.referrer);
398
- if (!("rootId" in chain)) return chain;
399
- const owner = await resolveOwner(chain, options);
400
- if (!("gateways" in owner)) return owner;
401
- if (!owner.gateways.some((g) => g.origin === gateway.origin)) return fail({
402
- type: "untrustedGateway",
403
- owner: owner.id,
404
- gateway,
405
- gateways: owner.gateways
406
- });
407
- return {
408
- verified: true,
409
- method: "gateway",
410
- unsecured: true,
411
- owner: owner.id,
412
- gateway,
413
- collectionContext: createContext({
414
- rootId: chain.rootId,
415
- rootOrigin: chain.rootOrigin,
416
- owner,
417
- ownerCandidate: null
418
- })
419
- };
420
- }
421
- //#endregion
422
11
  //#region src/sig/portable-collection.test.ts
423
12
  const AS = "https://www.w3.org/ns/activitystreams#";
424
- const context$1 = [
13
+ const context = [
425
14
  "https://www.w3.org/ns/activitystreams",
426
15
  "https://w3id.org/security/data-integrity/v1",
427
16
  "https://w3id.org/fep/ef61"
@@ -464,7 +53,7 @@ async function sign(document, privateKey = ed25519PrivateKey, verificationMethod
464
53
  }
465
54
  function actor(overrides = {}) {
466
55
  return {
467
- "@context": context$1,
56
+ "@context": context,
468
57
  id: actorId,
469
58
  type: "Person",
470
59
  inbox: `ap://${did}/actor/inbox`,
@@ -476,7 +65,7 @@ function actor(overrides = {}) {
476
65
  }
477
66
  function outbox(overrides = {}) {
478
67
  return {
479
- "@context": context$1,
68
+ "@context": context,
480
69
  id: outboxId,
481
70
  type: "OrderedCollection",
482
71
  totalItems: 0,
@@ -648,7 +237,7 @@ test("verifyPortableObject() requires an unambiguous owner", async () => {
648
237
  };
649
238
  assertFailure(await verify(outbox(), base), "unknownCollectionOwner");
650
239
  const note = await Note.fromJsonLd({
651
- "@context": context$1,
240
+ "@context": context,
652
241
  id: `ap://${did}/notes/1`,
653
242
  type: "Note"
654
243
  }, { contextLoader });
@@ -772,7 +361,7 @@ test("verifyPortableObject() checks pages against their collection", async () =>
772
361
  const collectionContext = collectionResult.collectionContext;
773
362
  const pageId = `ap://${did}/actor/outbox?page=1`;
774
363
  const page = (overrides = {}) => ({
775
- "@context": context$1,
364
+ "@context": context,
776
365
  id: pageId,
777
366
  type: "OrderedCollectionPage",
778
367
  partOf: outboxId,
@@ -831,14 +420,14 @@ test("verifyPortableObject() checks intermediate pages", async () => {
831
420
  const documentLoader = createLoader({ [gatewayUrl(gw1, actorId)]: signedActor });
832
421
  const collection = await OrderedCollection.fromJsonLd(outbox(), { contextLoader });
833
422
  const intermediate = async (partOf) => await CollectionPage.fromJsonLd({
834
- "@context": context$1,
423
+ "@context": context,
835
424
  id: `ap://${did}/actor/outbox?page=1`,
836
425
  type: "OrderedCollectionPage",
837
426
  partOf
838
427
  }, { contextLoader });
839
428
  const pageId = `ap://${did}/actor/outbox?page=2`;
840
429
  const page = {
841
- "@context": context$1,
430
+ "@context": context,
842
431
  id: pageId,
843
432
  type: "OrderedCollectionPage",
844
433
  partOf: outboxId,
@@ -868,7 +457,7 @@ test("verifyPortableObject() checks intermediate pages", async () => {
868
457
  test("verifyPortableObject() works with property accessors", async () => {
869
458
  const itemId = `ap://${did}/notes/1`;
870
459
  const note = await sign({
871
- "@context": context$1,
460
+ "@context": context,
872
461
  id: itemId,
873
462
  type: "Note",
874
463
  attributedTo: actorId,
@@ -892,11 +481,11 @@ test("verifyPortableObject() works with property accessors", async () => {
892
481
  [gatewayUrl(gw1, actorId)]: signedActor,
893
482
  [gatewayUrl(gw1, outboxId)]: outbox({ first: page1 }),
894
483
  [gatewayUrl(gw1, page1Id)]: {
895
- "@context": context$1,
484
+ "@context": context,
896
485
  ...page1
897
486
  },
898
487
  [gatewayUrl(gw1, page2Id)]: {
899
- "@context": context$1,
488
+ "@context": context,
900
489
  id: page2Id,
901
490
  type: "OrderedCollectionPage",
902
491
  partOf: outboxId,
@@ -909,7 +498,7 @@ test("verifyPortableObject() works with property accessors", async () => {
909
498
  verifyPortableObject
910
499
  };
911
500
  const create = await Collection.fromJsonLd({
912
- "@context": context$1,
501
+ "@context": context,
913
502
  type: "Collection",
914
503
  items: [actorId]
915
504
  }, { contextLoader });
@@ -932,7 +521,7 @@ test("verifyPortableObject() works with property accessors", async () => {
932
521
  test("verifyPortableObject() lets pages inherit owners across signed and embedded collections", async () => {
933
522
  const page1Id = `ap://${did}/actor/outbox?page=1`;
934
523
  const page1 = {
935
- "@context": context$1,
524
+ "@context": context,
936
525
  id: page1Id,
937
526
  type: "OrderedCollectionPage",
938
527
  partOf: outboxId,
@@ -940,7 +529,7 @@ test("verifyPortableObject() lets pages inherit owners across signed and embedde
940
529
  };
941
530
  const fetchPerson = async (options) => {
942
531
  const wrapper = await Collection.fromJsonLd({
943
- "@context": context$1,
532
+ "@context": context,
944
533
  type: "Collection",
945
534
  items: [actorId]
946
535
  }, { contextLoader });
@@ -1006,7 +595,7 @@ test("verifyPortableObject() reuses a verified actor for pages of signed collect
1006
595
  const collection = await OrderedCollection.fromJsonLd(outbox(), { contextLoader });
1007
596
  const pageId = `ap://${did}/actor/outbox?page=1`;
1008
597
  const result = await verify({
1009
- "@context": context$1,
598
+ "@context": context,
1010
599
  id: pageId,
1011
600
  type: "OrderedCollectionPage",
1012
601
  partOf: outboxId,
@@ -1034,21 +623,21 @@ test("verifyPortableObject() fetches the owner through attributedTo hints", asyn
1034
623
  test("verifyPortableObject() applies to compatible identifiers in accessors", async (t) => {
1035
624
  const noteId = `ap://${did}/notes/1`;
1036
625
  const signedNote = await sign({
1037
- "@context": context$1,
626
+ "@context": context,
1038
627
  id: noteId,
1039
628
  type: "Note",
1040
629
  attributedTo: actorId,
1041
630
  content: "Hello"
1042
631
  });
1043
632
  const forgedNote = {
1044
- "@context": context$1,
633
+ "@context": context,
1045
634
  id: noteId,
1046
635
  type: "Note",
1047
636
  attributedTo: actorId,
1048
637
  content: "Forged"
1049
638
  };
1050
639
  const collection = (items) => Collection.fromJsonLd({
1051
- "@context": context$1,
640
+ "@context": context,
1052
641
  id: "https://example.com/collection",
1053
642
  type: "Collection",
1054
643
  items
@@ -2,12 +2,12 @@ import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
5
- import { i as fetchKey } from "../key-PyYvun0F.mjs";
6
- import { h as verifyJsonLd, p as signJsonLd } from "../ld-u4JOD4iO.mjs";
7
- import { n as createProof, u as verifyProof } from "../proof-BCOg7Njv.mjs";
8
- import { d as verifyRequest, f as verifyRequestDetailed, l as signRequest } from "../http-B9BQDNIy.mjs";
5
+ import { i as fetchKey } from "../key-Cc1b6pW9.mjs";
6
+ import { h as verifyJsonLd, p as signJsonLd } from "../ld-DQNTIrAe.mjs";
7
+ import { n as createProof, u as verifyProof } from "../proof-CW8k0R1G.mjs";
8
+ import { d as verifyRequest, f as verifyRequestDetailed, l as signRequest } from "../http-BFeK9sBg.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
10
- import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-CPFM-sqo.mjs";
10
+ import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-CCfdL83M.mjs";
11
11
  import { t as KvKeyCache } from "../keycache-BInaECGj.mjs";
12
12
  import { Create, CryptographicKey, Multikey, Note, Person } from "@fedify/vocab";
13
13
  import { test } from "@fedify/fixture";
@@ -10,10 +10,10 @@ import "../std__assert-DvMDRPes.mjs";
10
10
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
11
11
  import { t as assert } from "../assert-D1Eafmd_.mjs";
12
12
  import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-4IJqPYos.mjs";
13
- import { i as signObject, n as createProof, o as verifyObject, r as hasProofLike, s as verifyPortableObjectProof, u as verifyProof } from "../proof-BCOg7Njv.mjs";
14
- import { d as verifyRequest } from "../http-B9BQDNIy.mjs";
13
+ import { i as signObject, n as createProof, o as verifyObject, r as hasProofLike, s as verifyPortableObjectProof, u as verifyProof } from "../proof-CW8k0R1G.mjs";
14
+ import { d as verifyRequest } from "../http-BFeK9sBg.mjs";
15
15
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
16
- import { t as getAuthenticatedDocumentLoader } from "../docloader-3BHaS20Z.mjs";
16
+ import { t as getAuthenticatedDocumentLoader } from "../docloader-Dtuyb0ps.mjs";
17
17
  import { Create, DataIntegrityProof, Document, Multikey, Note, PUBLIC_COLLECTION, Place, Translation } from "@fedify/vocab";
18
18
  import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
19
19
  import { decodeMultibase, encodeMultibase, exportDidKey, exportMultibaseKey, formatIri, importMultibaseKey, parseIri } from "@fedify/vocab-runtime";
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { c as getNormalizationContextLoader } from "./ld-u4JOD4iO.mjs";
4
+ import { c as getNormalizationContextLoader } from "./ld-DQNTIrAe.mjs";
5
5
  import jsonld from "@fedify/vocab-runtime/jsonld";
6
6
  //#region src/federation/temporal.ts
7
7
  function isPlainObject(value) {
@@ -6,7 +6,7 @@ import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
6
  import { t as ManualClockKvStore } from "../kv-DBRWVx3Q.mjs";
7
7
  import { n as baseOptions, o as stringSchema, t as MockQueue } from "../tasks-dbCShlCb.mjs";
8
8
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
9
- import { o as createFederation } from "../middleware-CgOqRkK-.mjs";
9
+ import { o as createFederation } from "../middleware-BdhvduR9.mjs";
10
10
  //#region src/testing/kv.test.ts
11
11
  test("ManualClockKvStore keeps an entry at its exact expiration instant", async () => {
12
12
  const kv = new ManualClockKvStore();
@@ -5,7 +5,7 @@ import { Router } from "@fedify/uri-template";
5
5
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Note, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
6
6
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
7
7
  import { MeterProvider, TracerProvider } from "@opentelemetry/api";
8
- import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
8
+ import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions, PortableObjectVerifier } from "@fedify/vocab-runtime";
9
9
  import { MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
10
10
  import { StandardSchemaV1 } from "@standard-schema/spec";
11
11
 
@@ -2881,6 +2881,27 @@ interface Context<TContextData> {
2881
2881
  * The context loader for loading remote JSON-LD contexts.
2882
2882
  */
2883
2883
  readonly contextLoader: DocumentLoader;
2884
+ /**
2885
+ * The [FEP-ef61] portable object policy that this context applies to
2886
+ * portable objects it dereferences. It is `verifyPortableObject()` with
2887
+ * this context's document loader, context loader, and tracer provider as
2888
+ * defaults, which the options passed to it override.
2889
+ *
2890
+ * Since its name is the same as the `verifyPortableObject` option of
2891
+ * property accessors, `lookupObject()`, and `traverseCollection()`, passing
2892
+ * a context as their options applies the policy, e.g.,
2893
+ * `await create.getObject(ctx)`. Objects parsed with a context as options,
2894
+ * such as activities that inboxes receive, also use it by default for
2895
+ * their property accessors. It never verifies an object by itself being
2896
+ * there: it only applies to objects that are dereferenced.
2897
+ *
2898
+ * It is optional only so that custom implementations of this interface
2899
+ * keep working; contexts that Fedify creates always have it.
2900
+ *
2901
+ * [FEP-ef61]: https://w3id.org/fep/ef61
2902
+ * @since 2.4.0
2903
+ */
2904
+ readonly verifyPortableObject?: PortableObjectVerifier;
2884
2905
  /**
2885
2906
  * The federation object that this context belongs to.
2886
2907
  * @since 1.6.0
@@ -3158,10 +3179,13 @@ interface Context<TContextData> {
3158
3179
  *
3159
3180
  * It's almost the same as the {@link lookupObject} function, but it uses
3160
3181
  * the context's document loader and context loader by default. It also
3161
- * uses `verifyPortableObjectProof()` as the `verifyPortableObject`
3182
+ * uses {@link Context.verifyPortableObject} as the `verifyPortableObject`
3162
3183
  * option by default (since 2.4.0), so [FEP-ef61] portable objects,
3163
3184
  * including portable actors found through WebFinger, are looked up through
3164
- * their gateways and returned only if they have valid proofs.
3185
+ * their gateways and returned only if they have valid proofs, or, for
3186
+ * collections without proofs, if they are served by gateways that their
3187
+ * owners list. The returned object uses the same policy by default for
3188
+ * its property accessors.
3165
3189
  *
3166
3190
  * [FEP-ef61]: https://w3id.org/fep/ef61
3167
3191
  *
@@ -3187,7 +3211,9 @@ interface Context<TContextData> {
3187
3211
  * ```
3188
3212
  *
3189
3213
  * It's almost the same as the {@link traverseCollection} function, but it
3190
- * uses the context's document loader and context loader by default.
3214
+ * uses the context's document loader and context loader by default. It
3215
+ * also uses {@link Context.verifyPortableObject} as the
3216
+ * `verifyPortableObject` option by default (since 2.4.0).
3191
3217
  * @param collection The collection to traverse.
3192
3218
  * @param options Options for traversing the collection.
3193
3219
  * @returns An async iterable of each item in the collection.