@fedify/fedify 2.1.31 → 2.1.32

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 (97) hide show
  1. package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
  2. package/dist/{builder-isMRh_I6.mjs → builder--sc-rozj.mjs} +3 -3
  3. package/dist/callback-BARPujV7.d.mts +2388 -0
  4. package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-BZr7TGyu.mjs → client-cpPaW7Ww.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +254 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/transformers.test.mjs +1 -1
  12. package/dist/{context-C0uGVzgk.d.ts → context-DE2YrQwM.d.ts} +30 -13
  13. package/dist/{context-CLaLxi49.d.cts → context-y6ZUQCMf.d.cts} +30 -13
  14. package/dist/{deno-CiaJqTcu.mjs → deno-L23b3Hba.mjs} +1 -1
  15. package/dist/{docloader-DOrwedT7.mjs → docloader-DUXr9k_O.mjs} +2 -2
  16. package/dist/federation/attachment-responses.test.d.mts +2 -0
  17. package/dist/federation/attachment-responses.test.mjs +182 -0
  18. package/dist/federation/builder.test.mjs +1 -1
  19. package/dist/federation/collection.test.mjs +1 -1
  20. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  21. package/dist/federation/delivery-attachments.test.mjs +280 -0
  22. package/dist/federation/handler.test.mjs +208 -16
  23. package/dist/federation/idempotency.test.mjs +2 -2
  24. package/dist/federation/inbox.test.mjs +1 -1
  25. package/dist/federation/middleware.test.mjs +1185 -8
  26. package/dist/federation/mod.cjs +1 -1
  27. package/dist/federation/mod.d.cts +2 -2
  28. package/dist/federation/mod.d.ts +2 -2
  29. package/dist/federation/mod.js +1 -1
  30. package/dist/federation/negotiation.test.mjs +1 -1
  31. package/dist/federation/retry.test.mjs +1 -1
  32. package/dist/federation/send.test.mjs +283 -3
  33. package/dist/federation/temporal.test.mjs +25 -1
  34. package/dist/federation/webfinger.test.mjs +1 -1
  35. package/dist/{http-Crml3gei.js → http-BtbMAgTA.js} +6 -4
  36. package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
  37. package/dist/{http-CRiVlZd5.cjs → http-D5woFKA_.cjs} +6 -4
  38. package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
  39. package/dist/{http-A9mP2uM7.mjs → http-HX6wVyJh.mjs} +6 -4
  40. package/dist/{inbox-KESLudq4.mjs → inbox-CL7A0HXT.mjs} +1 -1
  41. package/dist/{key-Dg6-DV_O.mjs → key-Dai3f5yI.mjs} +3 -2
  42. package/dist/{kv-cache-Cqmm-yQa.cjs → kv-cache-B0V_e231.cjs} +1 -1
  43. package/dist/{kv-cache-DQcyZL5T.js → kv-cache-BsDg-cT8.js} +1 -1
  44. package/dist/{ld-COjDN6Nb.mjs → ld-DN6x1iZ8.mjs} +153 -21
  45. package/dist/ld-signature-DoZcbsZR.mjs +23 -0
  46. package/dist/{middleware-BtDQUCcz.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
  47. package/dist/{middleware-BbgR7xOI.cjs → middleware-CrfRuKCf.cjs} +561 -101
  48. package/dist/{middleware-COFlKeYn.mjs → middleware-DiquMgtt.mjs} +378 -89
  49. package/dist/{middleware-DIW5S_5L.js → middleware-DunNtbo9.js} +560 -101
  50. package/dist/{middleware-CuQvczZd.mjs → middleware-SnQS8eIb.mjs} +1 -1
  51. package/dist/{mod-LOEOKbYd.d.cts → mod-CehHJOV4.d.cts} +30 -13
  52. package/dist/{mod-CFRocFeQ.d.ts → mod-DLJpnqdw.d.ts} +1 -1
  53. package/dist/{mod-C7w-QVUv.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
  54. package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
  55. package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
  56. package/dist/{mod-CGUH8Ujp.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
  57. package/dist/mod.cjs +5 -5
  58. package/dist/mod.d.cts +8 -8
  59. package/dist/mod.d.ts +8 -8
  60. package/dist/mod.js +5 -5
  61. package/dist/nodeinfo/client.test.mjs +432 -5
  62. package/dist/nodeinfo/handler.test.mjs +1 -1
  63. package/dist/nodeinfo/mod.cjs +1 -1
  64. package/dist/nodeinfo/mod.d.cts +1 -1
  65. package/dist/nodeinfo/mod.d.ts +1 -1
  66. package/dist/nodeinfo/mod.js +1 -1
  67. package/dist/nodeinfo/types.test.mjs +1 -1
  68. package/dist/{owner-CFHq61cq.mjs → owner-DwyDorZI.mjs} +2 -2
  69. package/dist/{proof-0JkSC_pT.cjs → proof-Be-4K4jn.cjs} +193 -46
  70. package/dist/{proof-KSHlbPCG.mjs → proof-DYjmyrHh.mjs} +38 -13
  71. package/dist/{proof-DzksJFK7.js → proof-Du4-5SHY.js} +187 -46
  72. package/dist/{send-DaDe2YCb.mjs → send-BGSfQkIK.mjs} +92 -21
  73. package/dist/sig/http.test.mjs +2 -2
  74. package/dist/sig/key-types.test.d.mts +218 -0
  75. package/dist/sig/key-types.test.mjs +8 -0
  76. package/dist/sig/key.test.mjs +2 -2
  77. package/dist/sig/ld.test.mjs +573 -8
  78. package/dist/sig/mod.cjs +2 -2
  79. package/dist/sig/mod.d.cts +3 -3
  80. package/dist/sig/mod.d.ts +3 -3
  81. package/dist/sig/mod.js +2 -2
  82. package/dist/sig/owner.test.mjs +1 -1
  83. package/dist/sig/proof.test.mjs +95 -3
  84. package/dist/{temporal-DNGH8o2E.mjs → temporal-CNCchWly.mjs} +3 -5
  85. package/dist/testing/mod.d.mts +2 -2203
  86. package/dist/{types-DOvyymM4.cjs → types-B5wRhemi.cjs} +85 -10
  87. package/dist/{types-B1_pRFE_.js → types-CXy2lRVU.js} +86 -11
  88. package/dist/utils/docloader.test.mjs +2 -2
  89. package/dist/utils/mod.cjs +1 -1
  90. package/dist/utils/mod.d.cts +1 -1
  91. package/dist/utils/mod.d.ts +1 -1
  92. package/dist/utils/mod.js +1 -1
  93. package/package.json +6 -6
  94. /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
  95. /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  96. /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
  97. /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -2,33 +2,133 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as RouterError } from "./router-CrMLXoOr.mjs";
5
- import { n as version, t as name } from "./deno-CiaJqTcu.mjs";
5
+ import { n as version, t as name } from "./deno-L23b3Hba.mjs";
6
6
  import { t as formatAcceptSignature } from "./accept-BavzedPB.mjs";
7
- import { o as importJwk, s as validateCryptoKey, t as exportJwk } from "./key-Dg6-DV_O.mjs";
8
- import { d as verifyRequestDetailed, s as parseRfc9421SignatureInput, u as verifyRequest } from "./http-A9mP2uM7.mjs";
9
- import { n as getAuthenticatedDocumentLoader } from "./docloader-DOrwedT7.mjs";
7
+ import { o as importJwk, s as validateCryptoKey, t as exportJwk } from "./key-Dai3f5yI.mjs";
8
+ import { d as verifyRequestDetailed, s as parseRfc9421SignatureInput, u as verifyRequest } from "./http-HX6wVyJh.mjs";
9
+ import { n as getAuthenticatedDocumentLoader } from "./docloader-DUXr9k_O.mjs";
10
10
  import { n as kvCache } from "./kv-cache-DqEKe5E0.mjs";
11
11
  import { t as KvKeyCache } from "./keycache-DahCaG_m.mjs";
12
- import { a as compactJsonLd, c as getNormalizationContextLoader, d as isInvalidUrlTypeError, f as signJsonLd, g as wrapContextLoaderForJsonLd, l as hasSignature, p as verifyCompactJsonLd, r as assertSafeJsonLd, s as detachSignature, t as InvalidContextReferenceError, u as isClearlyMalformedContextReference } from "./ld-COjDN6Nb.mjs";
13
- import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-CFHq61cq.mjs";
14
- import { n as signObject, r as verifyObject } from "./proof-KSHlbPCG.mjs";
15
- import { d as MAX_BODY_SIZE, f as readBoundedText, t as getNodeInfo, u as BodyTooLargeError } from "./client-BZr7TGyu.mjs";
16
- import { t as nodeInfoToJson } from "./types-DCP0WLdt.mjs";
17
- import { n as actorsHaveSameOrigin, r as routeActivity } from "./inbox-KESLudq4.mjs";
18
- import { t as FederationBuilderImpl } from "./builder-isMRh_I6.mjs";
19
- import { t as buildCollectionSynchronizationHeader } from "./collection-BD6-SZ6O.mjs";
20
- import { t as acceptsJsonLd } from "./negotiation-BehA2uul.mjs";
21
- import { t as hasMalformedKnownTemporalLiteral } from "./temporal-DNGH8o2E.mjs";
22
- import { t as createExponentialBackoffPolicy } from "./retry-B_E3V_Dx.mjs";
23
- import { i as sendActivity, n as extractInboxes, t as SendActivityError } from "./send-DaDe2YCb.mjs";
24
- import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
12
+ import { a as compactJsonLd, c as detachSignature, d as hasVerifiableSignature, f as isClearlyMalformedContextReference, h as verifyCompactJsonLd, l as getNormalizationContextLoader, m as signJsonLd, p as isInvalidUrlTypeError, r as assertSafeJsonLd, s as describeSignatureShape, t as InvalidContextReferenceError, v as wrapContextLoaderForJsonLd } from "./ld-DN6x1iZ8.mjs";
13
+ import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-DwyDorZI.mjs";
14
+ import { n as signObject, r as verifyObject } from "./proof-DYjmyrHh.mjs";
15
+ import { d as MAX_BODY_SIZE, f as readBoundedText, t as getNodeInfo, u as BodyTooLargeError } from "./client-cpPaW7Ww.mjs";
16
+ import { t as normalizeAttachmentArrays } from "./attachment-arrays-DZ4JHJD8.mjs";
17
+ import { t as nodeInfoToJson } from "./types-s4mCTGkT.mjs";
18
+ import { n as actorsHaveSameOrigin, r as routeActivity } from "./inbox-CL7A0HXT.mjs";
19
+ import { t as FederationBuilderImpl } from "./builder--sc-rozj.mjs";
20
+ import { t as buildCollectionSynchronizationHeader } from "./collection-DnoYNwBC.mjs";
21
+ import { t as acceptsJsonLd } from "./negotiation-xb0QR3u_.mjs";
22
+ import { t as hasMalformedKnownTemporalLiteral } from "./temporal-CNCchWly.mjs";
23
+ import { t as createExponentialBackoffPolicy } from "./retry-CI1flGDD.mjs";
24
+ import { i as sendActivity, n as extractInboxes, t as SendActivityError } from "./send-BGSfQkIK.mjs";
25
+ import { Activity, Collection, CollectionPage, CryptographicKey, DataIntegrityProof, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
25
26
  import { lookupWebFinger } from "@fedify/webfinger";
26
27
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
27
28
  import { uniq } from "es-toolkit";
28
- import { FetchError, getDocumentLoader } from "@fedify/vocab-runtime";
29
+ import { FetchError, encodeMultibase, getDocumentLoader } from "@fedify/vocab-runtime";
30
+ import { asCryptoKey } from "@fedify/vocab-runtime/internal";
29
31
  import { getLogger, withContext } from "@logtape/logtape";
30
32
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_HEADER, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
33
+ import { encodeHex } from "byte-encodings/hex";
34
+ import serialize from "json-canon";
31
35
  import { domainToASCII } from "node:url";
36
+ //#region src/sig/proof-creation.ts
37
+ /** Signs the exact serialized message supplied by an internal producer. */
38
+ async function createProofForJsonLd(jsonLd, privateKey, keyId, created) {
39
+ validateCryptoKey(privateKey, "private");
40
+ if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
41
+ const encoder = new TextEncoder();
42
+ const msgDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(jsonLd)));
43
+ created ??= Temporal.Now.instant();
44
+ const proofConfig = {
45
+ "@context": jsonLd["@context"],
46
+ type: "DataIntegrityProof",
47
+ cryptosuite: "eddsa-jcs-2022",
48
+ verificationMethod: keyId.href,
49
+ proofPurpose: "assertionMethod",
50
+ created: created.toString()
51
+ };
52
+ const proofDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(proofConfig)));
53
+ const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
54
+ digest.set(new Uint8Array(proofDigest), 0);
55
+ digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
56
+ const sig = await crypto.subtle.sign("Ed25519", asCryptoKey(privateKey), digest);
57
+ return new DataIntegrityProof({
58
+ cryptosuite: "eddsa-jcs-2022",
59
+ verificationMethod: keyId,
60
+ proofPurpose: "assertionMethod",
61
+ created,
62
+ proofValue: new Uint8Array(sig)
63
+ });
64
+ }
65
+ //#endregion
66
+ //#region src/compat/delivery-jsonld.ts
67
+ /**
68
+ * Returns changed attachment JSON only; unchanged documents keep the existing
69
+ * delivery signing path. This uses ordinary vocabulary serialization, without
70
+ * retaining or repairing independently signed child representations.
71
+ */
72
+ async function prepareActivityJsonLd(activity, contextLoader) {
73
+ if (activity.proofIds.length > 0) return void 0;
74
+ for await (const _ of activity.getProofs({ contextLoader })) return void 0;
75
+ const source = await activity.clone().toJsonLd({
76
+ format: "compact",
77
+ contextLoader
78
+ });
79
+ const prepared = await normalizeAttachmentArrays(source, contextLoader);
80
+ return prepared !== source && typeof prepared === "object" && prepared != null && !Array.isArray(prepared) ? prepared : void 0;
81
+ }
82
+ /** Signs a changed, proof-free delivery map without serializing it again. */
83
+ async function signActivityJsonLd(activity, unsigned, keys, options) {
84
+ const proofs = [];
85
+ const serializedProofs = [];
86
+ const tracer = (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version);
87
+ for (const { privateKey, keyId } of keys) {
88
+ const proof = await tracer.startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": getTypeId(activity).href } }, async (span) => {
89
+ try {
90
+ if (activity.id != null) span.setAttribute("activitypub.object.id", activity.id.href);
91
+ const proof = await createProofForJsonLd(unsigned, privateKey, keyId);
92
+ if (span.isRecording()) {
93
+ span.setAttribute("object_integrity_proofs.cryptosuite", "eddsa-jcs-2022");
94
+ span.setAttribute("object_integrity_proofs.key_id", keyId.href);
95
+ span.setAttribute("object_integrity_proofs.signature", encodeHex(proof.proofValue));
96
+ }
97
+ return proof;
98
+ } catch (error) {
99
+ span.setStatus({
100
+ code: SpanStatusCode.ERROR,
101
+ message: String(error)
102
+ });
103
+ throw error;
104
+ } finally {
105
+ span.end();
106
+ }
107
+ });
108
+ proofs.push(proof);
109
+ serializedProofs.push({
110
+ "@context": unsigned["@context"],
111
+ type: "DataIntegrityProof",
112
+ cryptosuite: proof.cryptosuite,
113
+ verificationMethod: keyId.href,
114
+ proofPurpose: "assertionMethod",
115
+ created: proof.created.toString(),
116
+ proofValue: new TextDecoder().decode(encodeMultibase("base58btc", proof.proofValue))
117
+ });
118
+ }
119
+ if (proofs.length === 0) return {
120
+ activity,
121
+ jsonLd: unsigned
122
+ };
123
+ return {
124
+ activity: activity.clone({ proofs }),
125
+ jsonLd: {
126
+ ...unsigned,
127
+ proof: serializedProofs.length === 1 ? serializedProofs[0] : serializedProofs
128
+ }
129
+ };
130
+ }
131
+ //#endregion
32
132
  //#region src/compat/transformers.ts
33
133
  const logger$1 = getLogger([
34
134
  "fedify",
@@ -207,7 +307,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
207
307
  if (authorizePredicate != null) {
208
308
  if (!await authorizePredicate(context, identifier)) return await onUnauthorized(request);
209
309
  }
210
- const jsonLd = await actor.toJsonLd(context);
310
+ const jsonLd = await serializeForResponse(actor, context);
211
311
  return new Response(JSON.stringify(jsonLd), { headers: {
212
312
  "Content-Type": "application/activity+json",
213
313
  Vary: "Accept"
@@ -227,7 +327,7 @@ async function handleObject(request, { values, context, objectDispatcher, author
227
327
  if (authorizePredicate != null) {
228
328
  if (!await authorizePredicate(context, values)) return await onUnauthorized(request);
229
329
  }
230
- const jsonLd = await object.toJsonLd(context);
330
+ const jsonLd = await serializeForResponse(object, context);
231
331
  return new Response(JSON.stringify(jsonLd), { headers: {
232
332
  "Content-Type": "application/activity+json",
233
333
  Vary: "Accept"
@@ -358,7 +458,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
358
458
  if (collectionCallbacks.authorizePredicate != null) {
359
459
  if (!await collectionCallbacks.authorizePredicate(context, identifier)) return await onUnauthorized(request);
360
460
  }
361
- const jsonLd = await collection.toJsonLd(context);
461
+ const jsonLd = await serializeForResponse(collection, context);
362
462
  return new Response(JSON.stringify(jsonLd), { headers: {
363
463
  "Content-Type": "application/activity+json",
364
464
  Vary: "Accept"
@@ -510,7 +610,11 @@ async function handleInboxInternal(request, parameters, span) {
510
610
  }
511
611
  const keyCache = new KvKeyCache(kv, kvPrefixes.publicKey, ctx);
512
612
  const jsonWithoutSig = detachSignature(json);
513
- const hasLdSignature = hasSignature(json);
613
+ const hasLdSignature = hasVerifiableSignature(json);
614
+ if (!hasLdSignature) {
615
+ const shape = describeSignatureShape(json);
616
+ if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
617
+ }
514
618
  const canAttemptAlternateAuthAfterLdSignatureFailure = skipSignatureVerification || hasHttpSignatureHeaders(request) || hasObjectIntegrityProof(jsonWithoutSig);
515
619
  let deferredLdSignatureError = void 0;
516
620
  const respondInvalidActivity = async (error) => {
@@ -989,7 +1093,7 @@ var CustomCollectionHandler = class {
989
1093
  * @returns A promise that resolves to the JSON-LD representation.
990
1094
  */
991
1095
  async toJsonLd() {
992
- return (await this.collection).toJsonLd(this.context);
1096
+ return serializeForResponse(await this.collection, this.context);
993
1097
  }
994
1098
  /**
995
1099
  * Fetches the collection with optional cursor for pagination.
@@ -1292,7 +1396,7 @@ var UnauthorizedError = class extends HandlerError {
1292
1396
  * @since 0.3.0
1293
1397
  */
1294
1398
  async function respondWithObject(object, options) {
1295
- const jsonLd = await object.toJsonLd(options);
1399
+ const jsonLd = await serializeForResponse(object, options);
1296
1400
  return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
1297
1401
  }
1298
1402
  /**
@@ -1380,6 +1484,10 @@ const MIN_COMPONENTS = [
1380
1484
  "@target-uri",
1381
1485
  "@authority"
1382
1486
  ];
1487
+ /** Applies compatibility changes only after ordinary vocabulary serialization. */
1488
+ async function serializeForResponse(object, options) {
1489
+ return await normalizeAttachmentArrays(await object.toJsonLd(options), options?.contextLoader);
1490
+ }
1383
1491
  //#endregion
1384
1492
  //#region src/federation/webfinger.ts
1385
1493
  const logger = getLogger([
@@ -1682,8 +1790,25 @@ var FederationImpl = class extends FederationBuilderImpl {
1682
1790
  _getTracer() {
1683
1791
  return this.tracerProvider.getTracer(name, version);
1684
1792
  }
1793
+ /**
1794
+ * Starts listening on a queue, converting a synchronous throw into
1795
+ * a rejected promise.
1796
+ *
1797
+ * `MessageQueue.listen()` is documented to never reject, but some
1798
+ * implementations (e.g., `WorkersMessageQueue`) throw synchronously. Without
1799
+ * this normalization, one such throw aborts {@link _startQueueInternal} while
1800
+ * it is still collecting listener promises, so listeners started earlier are
1801
+ * never awaited and later queues are never started.
1802
+ */
1803
+ #listenQueue(queue, ctxData, signal) {
1804
+ try {
1805
+ return queue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal });
1806
+ } catch (error) {
1807
+ return Promise.reject(error);
1808
+ }
1809
+ }
1685
1810
  async _startQueueInternal(ctxData, signal, queue) {
1686
- if (this.inboxQueue == null && this.outboxQueue == null) return;
1811
+ if (this.inboxQueue == null && this.outboxQueue == null && this.fanoutQueue == null) return;
1687
1812
  const logger = getLogger([
1688
1813
  "fedify",
1689
1814
  "federation",
@@ -1693,20 +1818,38 @@ var FederationImpl = class extends FederationBuilderImpl {
1693
1818
  if (this.inboxQueue != null && (queue == null || queue === "inbox") && !this.inboxQueueStarted) {
1694
1819
  logger.debug("Starting an inbox task worker.");
1695
1820
  this.inboxQueueStarted = true;
1696
- promises.push(this.inboxQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
1821
+ promises.push(this.#listenQueue(this.inboxQueue, ctxData, signal));
1697
1822
  }
1698
1823
  if (this.outboxQueue != null && this.outboxQueue !== this.inboxQueue && (queue == null || queue === "outbox") && !this.outboxQueueStarted) {
1699
1824
  logger.debug("Starting an outbox task worker.");
1700
1825
  this.outboxQueueStarted = true;
1701
- promises.push(this.outboxQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
1826
+ promises.push(this.#listenQueue(this.outboxQueue, ctxData, signal));
1702
1827
  }
1703
1828
  if (this.fanoutQueue != null && this.fanoutQueue !== this.inboxQueue && this.fanoutQueue !== this.outboxQueue && (queue == null || queue === "fanout") && !this.fanoutQueueStarted) {
1704
1829
  logger.debug("Starting a fanout task worker.");
1705
1830
  this.fanoutQueueStarted = true;
1706
- promises.push(this.fanoutQueue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal }));
1831
+ promises.push(this.#listenQueue(this.fanoutQueue, ctxData, signal));
1707
1832
  }
1708
1833
  await Promise.all(promises);
1709
1834
  }
1835
+ /**
1836
+ * Starts the queue workers automatically, reporting a failure instead of
1837
+ * leaving the returned promise unobserved.
1838
+ *
1839
+ * Automatic startup is best-effort: call sites cannot await it, so a failing
1840
+ * listener (e.g., `WorkersMessageQueue`, whose `listen()` throws) must not
1841
+ * become an unhandled rejection. {@link startQueue} keeps rejecting for
1842
+ * callers that start workers deliberately.
1843
+ */
1844
+ _startQueueAutomatically(ctxData) {
1845
+ this._startQueueInternal(ctxData).catch((error) => {
1846
+ getLogger([
1847
+ "fedify",
1848
+ "federation",
1849
+ "queue"
1850
+ ]).warn("Failed to start queue workers automatically: {error}", { error });
1851
+ });
1852
+ }
1710
1853
  processQueuedTask(contextData, message) {
1711
1854
  const tracer = this._getTracer();
1712
1855
  const extractedContext = propagation.extract(context.active(), message.traceContext);
@@ -1815,7 +1958,8 @@ var FederationImpl = class extends FederationBuilderImpl {
1815
1958
  await this.sendActivity(keys, message.inboxes, activity, {
1816
1959
  collectionSync: message.collectionSync,
1817
1960
  orderingKey: message.orderingKey,
1818
- context
1961
+ context,
1962
+ activityJsonLd: hasTopLevelProof(message.activity) ? message.activity : void 0
1819
1963
  });
1820
1964
  }
1821
1965
  async #listenOutboxMessage(_, message, span) {
@@ -2018,7 +2162,7 @@ var FederationImpl = class extends FederationBuilderImpl {
2018
2162
  let parseInput = void 0;
2019
2163
  let parseContextLoader = context.contextLoader;
2020
2164
  try {
2021
- const hasSignatureField = hasSignature(message.activity);
2165
+ const hasSignatureField = hasVerifiableSignature(message.activity);
2022
2166
  const shouldParseFromNormalizedSignedPayload = message.ldSignatureVerified === true || message.normalizedActivity != null || message.ldSignatureVerified == null && hasSignatureField;
2023
2167
  const parseContext = hasSignatureField ? {
2024
2168
  ...context,
@@ -2213,19 +2357,29 @@ var FederationImpl = class extends FederationBuilderImpl {
2213
2357
  proofCreated = true;
2214
2358
  break;
2215
2359
  }
2216
- if (!proofCreated) {
2217
- for (const { keyId, privateKey } of keys) if (privateKey.algorithm.name === "Ed25519") {
2218
- activity = await signObject(activity, privateKey, keyId, {
2219
- contextLoader,
2220
- tracerProvider: this.tracerProvider
2221
- });
2222
- proofCreated = true;
2360
+ const prepared = !proofCreated && options.activityJsonLd == null ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
2361
+ let jsonLd;
2362
+ if (prepared != null) {
2363
+ const signingKeys = keys.filter(({ privateKey }) => privateKey.algorithm.name === "Ed25519");
2364
+ const signed = await signActivityJsonLd(activity, prepared, signingKeys, { tracerProvider: this.tracerProvider });
2365
+ activity = signed.activity;
2366
+ jsonLd = signed.jsonLd;
2367
+ proofCreated = signingKeys.length > 0;
2368
+ } else {
2369
+ if (!proofCreated) {
2370
+ for (const { keyId, privateKey } of keys) if (privateKey.algorithm.name === "Ed25519") {
2371
+ activity = await signObject(activity, privateKey, keyId, {
2372
+ contextLoader,
2373
+ tracerProvider: this.tracerProvider
2374
+ });
2375
+ proofCreated = true;
2376
+ }
2223
2377
  }
2378
+ jsonLd = options.activityJsonLd != null ? detachSignature(options.activityJsonLd) : await activity.toJsonLd({
2379
+ format: "compact",
2380
+ contextLoader
2381
+ });
2224
2382
  }
2225
- let jsonLd = await activity.toJsonLd({
2226
- format: "compact",
2227
- contextLoader
2228
- });
2229
2383
  if (rsaKey == null) logger.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
2230
2384
  activityId,
2231
2385
  keys: keys.map((pair) => ({
@@ -2262,19 +2416,27 @@ var FederationImpl = class extends FederationBuilderImpl {
2262
2416
  activity: jsonLd
2263
2417
  });
2264
2418
  const promises = [];
2265
- for (const inbox in inboxes) promises.push(sendActivity({
2266
- allowPrivateAddress: this.allowPrivateAddress,
2267
- keys,
2268
- activity: jsonLd,
2269
- activityId: activity.id?.href,
2270
- activityType: getTypeId(activity).href,
2271
- inbox: new URL(inbox),
2272
- sharedInbox: inboxes[inbox].sharedInbox,
2273
- headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
2274
- specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock),
2275
- tracerProvider: this.tracerProvider
2276
- }));
2277
- await Promise.all(promises);
2419
+ try {
2420
+ for (const inbox in inboxes) {
2421
+ const promise = sendActivity({
2422
+ allowPrivateAddress: this.allowPrivateAddress,
2423
+ keys,
2424
+ activity: jsonLd,
2425
+ activityId: activity.id?.href,
2426
+ activityType: getTypeId(activity).href,
2427
+ inbox: new URL(inbox),
2428
+ sharedInbox: inboxes[inbox].sharedInbox,
2429
+ headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
2430
+ specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock),
2431
+ tracerProvider: this.tracerProvider
2432
+ });
2433
+ promise.catch(() => {});
2434
+ promises.push(promise);
2435
+ }
2436
+ await Promise.all(promises);
2437
+ } finally {
2438
+ await Promise.allSettled(promises);
2439
+ }
2278
2440
  return;
2279
2441
  }
2280
2442
  logger.debug("Enqueuing activity {activityId} to send later.", {
@@ -2289,7 +2451,7 @@ var FederationImpl = class extends FederationBuilderImpl {
2289
2451
  privateKey: privateKeyJwk
2290
2452
  });
2291
2453
  }
2292
- if (!this.manuallyStartQueue) this._startQueueInternal(ctx.data);
2454
+ if (!this.manuallyStartQueue) this._startQueueAutomatically(ctx.data);
2293
2455
  const carrier = {};
2294
2456
  propagation.inject(context.active(), carrier);
2295
2457
  const messages = [];
@@ -2501,7 +2663,7 @@ var FederationImpl = class extends FederationBuilderImpl {
2501
2663
  const identity = await this.sharedInboxKeyDispatcher(context);
2502
2664
  if (identity != null) context = this.#createContext(request, contextData, { documentLoader: "identifier" in identity || "username" in identity ? await context.getDocumentLoader(identity) : context.getDocumentLoader(identity) });
2503
2665
  }
2504
- if (!this.manuallyStartQueue) this._startQueueInternal(contextData);
2666
+ if (!this.manuallyStartQueue) this._startQueueAutomatically(contextData);
2505
2667
  const inboxContextFactory = context.toInboxContext.bind(context);
2506
2668
  inboxContextFactory[rawInboxContextFactorySymbol] = context.toInboxContext.bind(context);
2507
2669
  return await handleInbox(request, {
@@ -2824,6 +2986,8 @@ var ContextImpl = class ContextImpl {
2824
2986
  for (const keyPair of keyPairs) {
2825
2987
  const newPair = {
2826
2988
  ...keyPair,
2989
+ privateKey: asCryptoKey(keyPair.privateKey),
2990
+ publicKey: asCryptoKey(keyPair.publicKey),
2827
2991
  cryptographicKey: new CryptographicKey({
2828
2992
  id: keyPair.keyId,
2829
2993
  owner,
@@ -2900,10 +3064,16 @@ var ContextImpl = class ContextImpl {
2900
3064
  } else identifierPromise = Promise.resolve(identity.identifier);
2901
3065
  return identifierPromise.then((identifier) => {
2902
3066
  if (identifier == null) return this.documentLoader;
2903
- return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(pair));
3067
+ return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory({
3068
+ keyId: pair.keyId,
3069
+ privateKey: asCryptoKey(pair.privateKey)
3070
+ }));
2904
3071
  });
2905
3072
  }
2906
- return this.federation.authenticatedDocumentLoaderFactory(identity);
3073
+ return this.federation.authenticatedDocumentLoaderFactory({
3074
+ keyId: identity.keyId,
3075
+ privateKey: asCryptoKey(identity.privateKey)
3076
+ });
2907
3077
  }
2908
3078
  lookupObject(identifier, options = {}) {
2909
3079
  return lookupObject(identifier, {
@@ -2926,10 +3096,14 @@ var ContextImpl = class ContextImpl {
2926
3096
  return options.parse === "none" ? getNodeInfo(url, {
2927
3097
  parse: "none",
2928
3098
  direct: options.direct,
3099
+ timeout: options.timeout,
3100
+ signal: options.signal,
2929
3101
  userAgent: options?.userAgent ?? this.federation.userAgent
2930
3102
  }) : getNodeInfo(url, {
2931
3103
  parse: options.parse,
2932
3104
  direct: options.direct,
3105
+ timeout: options.timeout,
3106
+ signal: options.signal,
2933
3107
  userAgent: options?.userAgent ?? this.federation.userAgent
2934
3108
  });
2935
3109
  }
@@ -2941,7 +3115,17 @@ var ContextImpl = class ContextImpl {
2941
3115
  allowPrivateAddress: this.federation.allowPrivateAddress
2942
3116
  });
2943
3117
  }
2944
- sendActivity(sender, recipients, activity, options = {}) {
3118
+ async sendActivity(sender, recipients, activity, options = {}) {
3119
+ let activityJsonLd = void 0;
3120
+ let hasProof = activity.proofIds.length > 0;
3121
+ if (!hasProof) for await (const _ of activity.getProofs({ contextLoader: this.contextLoader })) {
3122
+ hasProof = true;
3123
+ break;
3124
+ }
3125
+ if (hasProof) {
3126
+ activityJsonLd = await activity.toJsonLd({ contextLoader: this.contextLoader });
3127
+ if (!hasTopLevelProof(activityJsonLd)) activityJsonLd = void 0;
3128
+ }
2945
3129
  return this.tracerProvider.getTracer(name, version).startActiveSpan(this.federation.outboxQueue == null || options.immediate ? "activitypub.outbox" : "activitypub.fanout", {
2946
3130
  kind: this.federation.outboxQueue == null || options.immediate ? SpanKind.CLIENT : SpanKind.PRODUCER,
2947
3131
  attributes: {
@@ -2954,7 +3138,7 @@ var ContextImpl = class ContextImpl {
2954
3138
  }, async (span) => {
2955
3139
  try {
2956
3140
  if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
2957
- await this.sendActivityInternal(sender, recipients, activity, options, span);
3141
+ await this.sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd);
2958
3142
  } catch (e) {
2959
3143
  span.setStatus({
2960
3144
  code: SpanStatusCode.ERROR,
@@ -2966,7 +3150,7 @@ var ContextImpl = class ContextImpl {
2966
3150
  }
2967
3151
  });
2968
3152
  }
2969
- async sendActivityInternal(sender, recipients, activity, options, span) {
3153
+ async sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd) {
2970
3154
  const logger = getLogger([
2971
3155
  "fedify",
2972
3156
  "federation",
@@ -3013,14 +3197,23 @@ var ContextImpl = class ContextImpl {
3013
3197
  if (!(error instanceof RouterError)) throw error;
3014
3198
  }
3015
3199
  } else expandedRecipients = [recipients];
3016
- const opts = {
3017
- context: this,
3018
- orderingKey: options.orderingKey,
3019
- collectionSync,
3020
- immediate: options.immediate
3021
- };
3022
3200
  span.setAttribute("activitypub.inboxes", expandedRecipients.length);
3023
3201
  for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
3202
+ let contextMatches = false;
3203
+ if (activityJsonLd != null) {
3204
+ const capturedJsonLd = activityJsonLd;
3205
+ const transformedJsonLd = await activity.toJsonLd({
3206
+ format: "compact",
3207
+ contextLoader: this.contextLoader
3208
+ });
3209
+ const contentChanged = getContentFields(transformedJsonLd) !== getContentFields(capturedJsonLd);
3210
+ contextMatches = getContextFields(transformedJsonLd) === getContextFields(capturedJsonLd);
3211
+ const proofsChanged = getProofFields(transformedJsonLd) !== getProofFields(capturedJsonLd);
3212
+ if (contentChanged || !contextMatches && proofsChanged) {
3213
+ activity = activity.clone({ proofs: await getUncapturedProofs(activity, capturedJsonLd, this.contextLoader) });
3214
+ activityJsonLd = void 0;
3215
+ } else if (proofsChanged) activityJsonLd = void 0;
3216
+ }
3024
3217
  span?.setAttribute("activitypub.activity.id", activity?.id?.href ?? "");
3025
3218
  if (activity.actorId == null) {
3026
3219
  logger.error("Activity {activityId} to send does not have an actor.", {
@@ -3031,14 +3224,39 @@ var ContextImpl = class ContextImpl {
3031
3224
  }
3032
3225
  if (actorKeyPairs != null) {
3033
3226
  const contextLoader = this.contextLoader;
3034
- for (const kp of actorKeyPairs) {
3035
- if (kp.privateKey.algorithm.name !== "Ed25519" || kp.multikey.id == null) continue;
3036
- activity = await signObject(activity, kp.privateKey, kp.multikey.id, {
3037
- contextLoader,
3038
- tracerProvider: this.tracerProvider
3039
- });
3227
+ const willSign = actorKeyPairs.some((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null);
3228
+ if (willSign) {
3229
+ if (activityJsonLd != null && !contextMatches) activity = activity.clone({ proofs: [] });
3230
+ }
3231
+ const prepared = willSign ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
3232
+ if (prepared != null) {
3233
+ const signingKeys = actorKeyPairs.flatMap((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null ? [{
3234
+ privateKey: kp.privateKey,
3235
+ keyId: kp.multikey.id
3236
+ }] : []);
3237
+ const signed = await signActivityJsonLd(activity, prepared, signingKeys, { tracerProvider: this.tracerProvider });
3238
+ activity = signed.activity;
3239
+ activityJsonLd = signed.jsonLd;
3240
+ } else {
3241
+ let proofAdded = false;
3242
+ for (const kp of actorKeyPairs) {
3243
+ if (kp.privateKey.algorithm.name !== "Ed25519" || kp.multikey.id == null) continue;
3244
+ activity = await signObject(activity, kp.privateKey, kp.multikey.id, {
3245
+ contextLoader,
3246
+ tracerProvider: this.tracerProvider
3247
+ });
3248
+ proofAdded = true;
3249
+ }
3250
+ if (proofAdded) activityJsonLd = void 0;
3040
3251
  }
3041
3252
  }
3253
+ const opts = {
3254
+ context: this,
3255
+ orderingKey: options.orderingKey,
3256
+ collectionSync,
3257
+ immediate: options.immediate,
3258
+ activityJsonLd
3259
+ };
3042
3260
  const inboxes = extractInboxes({
3043
3261
  recipients: expandedRecipients,
3044
3262
  preferSharedInbox: options.preferSharedInbox,
@@ -3068,7 +3286,7 @@ var ContextImpl = class ContextImpl {
3068
3286
  actorIds: [...actorIds],
3069
3287
  sharedInbox
3070
3288
  }])),
3071
- activity: await activity.toJsonLd({
3289
+ activity: activityJsonLd != null ? detachSignature(activityJsonLd) : await activity.toJsonLd({
3072
3290
  format: "compact",
3073
3291
  contextLoader: this.contextLoader
3074
3292
  }),
@@ -3078,7 +3296,7 @@ var ContextImpl = class ContextImpl {
3078
3296
  orderingKey: options.orderingKey,
3079
3297
  traceContext: carrier
3080
3298
  };
3081
- if (!this.federation.manuallyStartQueue) this.federation._startQueueInternal(this.data);
3299
+ if (!this.federation.manuallyStartQueue) this.federation._startQueueAutomatically(this.data);
3082
3300
  await this.federation.fanoutQueue.enqueue(message, { orderingKey: options.orderingKey });
3083
3301
  }
3084
3302
  async *getFollowers(identifier) {
@@ -3432,7 +3650,7 @@ var InboxContextImpl = class InboxContextImpl extends ContextImpl {
3432
3650
  if (forwarder.length < 1) throw new Error("The forwarder's key pairs are empty.");
3433
3651
  keys = forwarder;
3434
3652
  } else keys = [forwarder];
3435
- if (!hasSignature(this.activity)) {
3653
+ if (!hasVerifiableSignature(this.activity)) {
3436
3654
  let hasProof;
3437
3655
  try {
3438
3656
  hasProof = await (await Activity.fromJsonLd(this.activity, this)).getProof() != null;
@@ -3464,18 +3682,26 @@ var InboxContextImpl = class InboxContextImpl extends ContextImpl {
3464
3682
  if (options?.immediate) logger.debug("Forwarding activity immediately without queue since immediate option is set.");
3465
3683
  else logger.debug("Forwarding activity immediately without queue since queue is not set.");
3466
3684
  const promises = [];
3467
- for (const inbox in inboxes) promises.push(sendActivity({
3468
- allowPrivateAddress: this.federation.allowPrivateAddress,
3469
- keys,
3470
- activity: this.activity,
3471
- activityId: this.activityId,
3472
- activityType: this.activityType,
3473
- inbox: new URL(inbox),
3474
- sharedInbox: inboxes[inbox].sharedInbox,
3475
- tracerProvider: this.tracerProvider,
3476
- specDeterminer: new KvSpecDeterminer(this.federation.kv, this.federation.kvPrefixes.httpMessageSignaturesSpec, this.federation.firstKnock)
3477
- }));
3478
- await Promise.all(promises);
3685
+ try {
3686
+ for (const inbox in inboxes) {
3687
+ const promise = sendActivity({
3688
+ allowPrivateAddress: this.federation.allowPrivateAddress,
3689
+ keys,
3690
+ activity: this.activity,
3691
+ activityId: this.activityId,
3692
+ activityType: this.activityType,
3693
+ inbox: new URL(inbox),
3694
+ sharedInbox: inboxes[inbox].sharedInbox,
3695
+ tracerProvider: this.tracerProvider,
3696
+ specDeterminer: new KvSpecDeterminer(this.federation.kv, this.federation.kvPrefixes.httpMessageSignaturesSpec, this.federation.firstKnock)
3697
+ });
3698
+ promise.catch(() => {});
3699
+ promises.push(promise);
3700
+ }
3701
+ await Promise.all(promises);
3702
+ } finally {
3703
+ await Promise.allSettled(promises);
3704
+ }
3479
3705
  return;
3480
3706
  }
3481
3707
  logger.debug("Enqueuing activity {activityId} to forward later.", {
@@ -3570,6 +3796,69 @@ var KvSpecDeterminer = class {
3570
3796
  function notFound(_request) {
3571
3797
  return new Response("Not Found", { status: 404 });
3572
3798
  }
3799
+ function hasTopLevelProof(value) {
3800
+ return typeof value === "object" && value != null && !Array.isArray(value) && globalThis.Object.prototype.hasOwnProperty.call(value, "proof");
3801
+ }
3802
+ function getContentFields(value) {
3803
+ if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
3804
+ const record = { ...value };
3805
+ delete record["@context"];
3806
+ delete record.proof;
3807
+ delete record.signature;
3808
+ return JSON.stringify(sortJsonKeys(record));
3809
+ }
3810
+ function getContextFields(value) {
3811
+ if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
3812
+ const context = value["@context"];
3813
+ return JSON.stringify(sortJsonKeys(context ?? null));
3814
+ }
3815
+ function getProofEntries(value) {
3816
+ if (typeof value !== "object" || value == null || Array.isArray(value)) return [];
3817
+ const proof = value.proof;
3818
+ if (proof == null) return [];
3819
+ return Array.isArray(proof) ? proof : [proof];
3820
+ }
3821
+ function normalizeProofEntry(proof) {
3822
+ const stripped = stripContexts(proof);
3823
+ if (typeof stripped !== "object" || stripped == null || Array.isArray(stripped)) return stripped;
3824
+ const record = { ...stripped };
3825
+ if (typeof record.created === "string") try {
3826
+ record.created = Temporal.Instant.from(record.created).toString();
3827
+ } catch {}
3828
+ return record;
3829
+ }
3830
+ function getProofEntryFields(proof) {
3831
+ return JSON.stringify(sortJsonKeys(normalizeProofEntry(proof)));
3832
+ }
3833
+ function getProofFields(value) {
3834
+ return JSON.stringify(getProofEntries(value).map(getProofEntryFields).sort());
3835
+ }
3836
+ async function getUncapturedProofs(activity, capturedJsonLd, contextLoader) {
3837
+ const capturedProofs = new Set(getProofEntries(capturedJsonLd).map(getProofEntryFields));
3838
+ const retainedProofs = [];
3839
+ for await (const proof of activity.getProofs({ contextLoader })) {
3840
+ const proofJsonLd = await proof.toJsonLd({
3841
+ format: "compact",
3842
+ contextLoader
3843
+ });
3844
+ if (!capturedProofs.has(getProofEntryFields(proofJsonLd))) retainedProofs.push(proof);
3845
+ }
3846
+ return retainedProofs;
3847
+ }
3848
+ function stripContexts(value) {
3849
+ if (Array.isArray(value)) return value.map(stripContexts);
3850
+ if (typeof value !== "object" || value == null) return value;
3851
+ const record = { ...value };
3852
+ delete record["@context"];
3853
+ delete record.signature;
3854
+ for (const key of globalThis.Object.keys(record)) record[key] = stripContexts(record[key]);
3855
+ return record;
3856
+ }
3857
+ function sortJsonKeys(value) {
3858
+ if (Array.isArray(value)) return value.map(sortJsonKeys);
3859
+ if (typeof value !== "object" || value == null) return value;
3860
+ return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
3861
+ }
3573
3862
  function notAcceptable(_request) {
3574
3863
  return new Response("Not Acceptable", {
3575
3864
  status: 406,
@@ -3601,4 +3890,4 @@ function getRequestId(request) {
3601
3890
  return `req_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
3602
3891
  }
3603
3892
  //#endregion
3604
- export { autoIdAssigner as _, createFederation as a, handleCollection as c, handleObject as d, respondWithObject as f, actorDehydrator as g, handleNodeInfoJrd as h, KvSpecDeterminer as i, handleCustomCollection as l, handleNodeInfo as m, FederationImpl as n, handleWebFinger as o, respondWithObjectIfAcceptable as p, InboxContextImpl as r, handleActor as s, ContextImpl as t, handleInbox as u };
3893
+ export { autoIdAssigner as _, createFederation as a, handleCollection as c, handleObject as d, respondWithObject as f, actorDehydrator as g, handleNodeInfoJrd as h, KvSpecDeterminer as i, handleCustomCollection as l, handleNodeInfo as m, FederationImpl as n, handleWebFinger as o, respondWithObjectIfAcceptable as p, InboxContextImpl as r, handleActor as s, ContextImpl as t, handleInbox as u, prepareActivityJsonLd as v };