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

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 (98) hide show
  1. package/dist/{builder-BCXywsZF.mjs → builder-C0bxZDL0.mjs} +3 -3
  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-D9Kljk_7.mjs} +3 -3
  6. package/dist/{context-tOiJfBoD.d.ts → context-Cz1w5Krc.d.ts} +31 -5
  7. package/dist/{context-CoNRxGYp.mjs → context-DfSVPcJ8.mjs} +6 -3
  8. package/dist/{context-SMNOiiY6.d.cts → context-Dvec_D_h.d.cts} +31 -5
  9. package/dist/{deno-BZrnW0Qz.mjs → deno-_o3lkDlG.mjs} +1 -1
  10. package/dist/{docloader-3BHaS20Z.mjs → docloader-BbS0rO-Y.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 +6 -6
  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 +77 -6
  28. package/dist/federation/portable-inbox.test.mjs +9 -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-DRY8KrkB.cjs} +46 -22
  36. package/dist/{http-4bmgw-mA.cjs → http-B1J6E-bT.cjs} +384 -33
  37. package/dist/{http-B9BQDNIy.mjs → http-BpOiZE09.mjs} +18 -12
  38. package/dist/{http-D76Py0M4.d.cts → http-C-x_OLSp.d.ts} +57 -14
  39. package/dist/{http-BETASGl0.js → http-C2M6wcs8.js} +374 -35
  40. package/dist/{http-BrQgkJay.d.ts → http-CjezPjFX.d.cts} +57 -14
  41. package/dist/{key-PyYvun0F.mjs → key-DolJjJab.mjs} +103 -16
  42. package/dist/{kv-cache-CPqUxRL3.mjs → kv-cache-Bq2cah0c.mjs} +1 -1
  43. package/dist/{kv-cache-C4mv2ZFQ.js → kv-cache-D7TiyMxv.js} +6 -6
  44. package/dist/{kv-cache-D2Bz6t_c.cjs → kv-cache-D9nRbG2Q.cjs} +6 -6
  45. package/dist/{ld-u4JOD4iO.mjs → ld-Dwc176V4.mjs} +3 -3
  46. package/dist/{metrics-DCLoLvLz.mjs → metrics-CDaHfBXY.mjs} +1 -1
  47. package/dist/{middleware-B7bmtONC.mjs → middleware-CmB1FD8A.mjs} +1 -1
  48. package/dist/{middleware-DWlAGlyP.js → middleware-CylX-pvI.js} +52 -28
  49. package/dist/{middleware-CgOqRkK-.mjs → middleware-DN3MdTDg.mjs} +64 -39
  50. package/dist/{mod-CTh7ijx5.d.ts → mod-Bz9tFXI2.d.ts} +14 -3
  51. package/dist/{mod-Cwdt_CWU.d.ts → mod-CZetqT5h.d.ts} +1 -1
  52. package/dist/{mod-Cr79cQlc.d.cts → mod-D4g9ffEn.d.cts} +1 -1
  53. package/dist/{mod-DnElMslb.d.cts → mod-DGOIxEfb.d.cts} +1 -1
  54. package/dist/{mod-DMdGFMEl.d.cts → mod-S--JxYjo.d.cts} +14 -3
  55. package/dist/{mod-COWgSo2v.d.ts → mod-owwElvpw.d.ts} +1 -1
  56. package/dist/mod.cjs +8 -8
  57. package/dist/mod.d.cts +5 -5
  58. package/dist/mod.d.ts +5 -5
  59. package/dist/mod.js +5 -5
  60. package/dist/nodeinfo/handler.test.mjs +2 -2
  61. package/dist/{owner-CPFM-sqo.mjs → owner-BNHhwjNu.mjs} +37 -4
  62. package/dist/{sig-C1xOA4ml.js → portable-collection-CRpTUHCY.mjs} +5 -4
  63. package/dist/portable-collection-CgglAI9B.js +656 -0
  64. package/dist/{sig-Cb9VSeiF.cjs → portable-collection-PTGD0q70.cjs} +253 -2
  65. package/dist/portable-key-DqX2emHQ.mjs +395 -0
  66. package/dist/{portable-key-id-T7lecIbt.mjs → portable-key-id-Bg259c4Z.mjs} +69 -2
  67. package/dist/{proof-BCOg7Njv.mjs → proof-B4_0E-KU.mjs} +5 -5
  68. package/dist/{send-C8eOPat3.mjs → send-Dpu5qbP5.mjs} +3 -3
  69. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  70. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  71. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  72. package/dist/sig/compound-proof.test.mjs +2 -2
  73. package/dist/sig/http.test.mjs +2 -2
  74. package/dist/sig/key.test.mjs +1 -1
  75. package/dist/sig/ld.test.mjs +2 -2
  76. package/dist/sig/mod.cjs +5 -6
  77. package/dist/sig/mod.d.cts +2 -2
  78. package/dist/sig/mod.d.ts +2 -2
  79. package/dist/sig/mod.js +2 -3
  80. package/dist/sig/owner.test.mjs +1 -1
  81. package/dist/sig/portable-collection.test.mjs +20 -431
  82. package/dist/sig/portable-key.test.mjs +479 -5
  83. package/dist/sig/proof.test.mjs +3 -3
  84. package/dist/{temporal-vjHOhBpy.mjs → temporal-78JVR3GK.mjs} +1 -1
  85. package/dist/testing/kv.test.mjs +1 -1
  86. package/dist/testing/mod.d.mts +30 -4
  87. package/dist/testing/mod.mjs +2 -2
  88. package/dist/{testing-BWq1dCzx.mjs → testing-otQhu4aD.mjs} +1 -1
  89. package/dist/utils/docloader.test.mjs +81 -2
  90. package/dist/utils/kv-cache.test.mjs +1 -1
  91. package/dist/utils/mod.cjs +1 -1
  92. package/dist/utils/mod.d.cts +1 -1
  93. package/dist/utils/mod.d.ts +1 -1
  94. package/dist/utils/mod.js +1 -1
  95. package/package.json +7 -7
  96. package/dist/owner-DkA0Lz7v.cjs +0 -225
  97. package/dist/owner-wNinn7RK.js +0 -215
  98. package/dist/portable-key-DyylakVV.mjs +0 -214
@@ -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-CRpTUHCY.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