@fedify/fedify 2.3.16-dev.2845 → 2.3.16

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 (108) hide show
  1. package/dist/attachment-arrays-BlfpZlWF.mjs +16 -0
  2. package/dist/{builder-B9apzaoK.mjs → builder-D4GE1Gmi.mjs} +3 -3
  3. package/dist/callback-kR_sx2zZ.d.mts +2661 -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-DpUNYKla.mjs → client-DFgYVbUA.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
  15. package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
  16. package/dist/{deno-CgHxPWA-.mjs → deno-FtdqgHJA.mjs} +1 -1
  17. package/dist/{docloader-CYscMv4m.mjs → docloader-B9iU4DP2.mjs} +2 -2
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/circuit-breaker.test.mjs +2 -2
  22. package/dist/federation/collection.test.mjs +1 -1
  23. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  24. package/dist/federation/delivery-attachments.test.mjs +288 -0
  25. package/dist/federation/handler.test.mjs +208 -16
  26. package/dist/federation/idempotency.test.mjs +2 -2
  27. package/dist/federation/inbox.test.mjs +2 -2
  28. package/dist/federation/metrics.test.mjs +1 -1
  29. package/dist/federation/middleware.test.mjs +1191 -16
  30. package/dist/federation/mod.cjs +1 -1
  31. package/dist/federation/mod.d.cts +2 -2
  32. package/dist/federation/mod.d.ts +2 -2
  33. package/dist/federation/mod.js +1 -1
  34. package/dist/federation/negotiation.test.mjs +1 -1
  35. package/dist/federation/retry.test.mjs +1 -1
  36. package/dist/federation/send.test.mjs +293 -3
  37. package/dist/federation/temporal.test.mjs +25 -1
  38. package/dist/federation/webfinger.test.mjs +1 -1
  39. package/dist/{http-CfxAK-RL.cjs → http-2RyDQ0tE.cjs} +6 -4
  40. package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
  41. package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
  42. package/dist/{http-dzXtCtOp.mjs → http-D8tiOrZf.mjs} +7 -5
  43. package/dist/{http-BzIb8Gk0.js → http-mLeLYFj-.js} +6 -4
  44. package/dist/{inbox-BMytDl21.mjs → inbox-Dy8awbi8.mjs} +2 -2
  45. package/dist/{key-fdTPEBhG.mjs → key-o1SmN5s0.mjs} +4 -3
  46. package/dist/{kv-cache-ShxnSuNt.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
  47. package/dist/{kv-cache-dQUFD_pa.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
  48. package/dist/{kv-cache-CwqJUNNd.js → kv-cache-Dsq8C8D8.js} +1 -1
  49. package/dist/{ld-B8mU49Dg.mjs → ld-DCKrqj9y.mjs} +155 -22
  50. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  51. package/dist/{metrics-C0ZYkgVy.mjs → metrics-CaoYRhNH.mjs} +1 -1
  52. package/dist/{middleware-DK_kGeMl.mjs → middleware-4p3opEMT.mjs} +1 -1
  53. package/dist/{middleware-9mBkHYci.cjs → middleware-CP-8P7kk.cjs} +492 -117
  54. package/dist/{middleware-D0GPqg_7.js → middleware-Cce0nLDw.js} +491 -117
  55. package/dist/{middleware-Hr9ci9uD.mjs → middleware-D31fNcY4.mjs} +399 -109
  56. package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
  57. package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
  58. package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
  59. package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
  60. package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
  61. package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
  62. package/dist/mod.cjs +5 -5
  63. package/dist/mod.d.cts +8 -8
  64. package/dist/mod.d.ts +8 -8
  65. package/dist/mod.js +5 -5
  66. package/dist/nodeinfo/client.test.mjs +432 -4
  67. package/dist/nodeinfo/handler.test.mjs +1 -1
  68. package/dist/nodeinfo/mod.cjs +1 -1
  69. package/dist/nodeinfo/mod.d.cts +1 -1
  70. package/dist/nodeinfo/mod.d.ts +1 -1
  71. package/dist/nodeinfo/mod.js +1 -1
  72. package/dist/nodeinfo/types.test.mjs +1 -1
  73. package/dist/{outgoing-jsonld-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
  74. package/dist/{owner-BqnaV4zl.mjs → owner-Bdj0nHhf.mjs} +2 -2
  75. package/dist/{proof-BSRF2hIP.js → proof-B9XJiyz-.js} +1030 -858
  76. package/dist/{proof-D9VX-J1n.cjs → proof-CmcP8yqP.cjs} +1243 -1059
  77. package/dist/{proof-BvpOtXRD.mjs → proof-DrbjYma9.mjs} +41 -16
  78. package/dist/{send-BPel6SCW.mjs → send-VD_WG3dN.mjs} +100 -22
  79. package/dist/sig/http.test.mjs +2 -2
  80. package/dist/sig/key-types.test.d.mts +218 -0
  81. package/dist/sig/key-types.test.mjs +8 -0
  82. package/dist/sig/key.test.mjs +2 -2
  83. package/dist/sig/ld.test.mjs +573 -8
  84. package/dist/sig/mod.cjs +2 -2
  85. package/dist/sig/mod.d.cts +3 -3
  86. package/dist/sig/mod.d.ts +3 -3
  87. package/dist/sig/mod.js +2 -2
  88. package/dist/sig/owner.test.mjs +1 -1
  89. package/dist/sig/proof.test.mjs +96 -4
  90. package/dist/{temporal-CaD1O1QX.mjs → temporal-CMvoB-vD.mjs} +3 -5
  91. package/dist/testing/mod.d.mts +2 -2476
  92. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  93. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  94. package/dist/utils/docloader.test.mjs +2 -2
  95. package/dist/utils/kv-cache.test.mjs +1 -1
  96. package/dist/utils/mod.cjs +1 -1
  97. package/dist/utils/mod.d.cts +1 -1
  98. package/dist/utils/mod.d.ts +1 -1
  99. package/dist/utils/mod.js +1 -1
  100. package/package.json +6 -6
  101. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
  102. /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
  103. /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
  104. /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
  105. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
  106. /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
  107. /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
  108. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -9,17 +9,19 @@ import { t as assertRejects } from "../assert_rejects-D1HYAik3.mjs";
9
9
  import { n as assertInstanceOf, t as assert } from "../assert-CEO06XCw.mjs";
10
10
  import { t as assertNotEquals } from "../assert_not_equals-DkVK8oqV.mjs";
11
11
  import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
12
- import { g as recordInboxActivity } from "../metrics-C0ZYkgVy.mjs";
13
- import { c as signRequest, u as verifyRequest } from "../http-dzXtCtOp.mjs";
12
+ import { g as recordInboxActivity } from "../metrics-CaoYRhNH.mjs";
13
+ import { c as signRequest, u as verifyRequest } from "../http-D8tiOrZf.mjs";
14
14
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
15
- import { n as getAuthenticatedDocumentLoader } from "../docloader-CYscMv4m.mjs";
15
+ import { n as getAuthenticatedDocumentLoader } from "../docloader-B9iU4DP2.mjs";
16
16
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
17
- import { a as compactJsonLd, h as verifyJsonLd, p as signJsonLd, s as detachSignature } from "../ld-B8mU49Dg.mjs";
18
- import { t as doesActorOwnKey } from "../owner-BqnaV4zl.mjs";
19
- import { i as verifyObject, r as signObject } from "../proof-BvpOtXRD.mjs";
20
- import { g as handleBenchmarkTrigger, i as KvSpecDeterminer, n as FederationImpl, o as createFederation, r as InboxContextImpl, t as ContextImpl } from "../middleware-Hr9ci9uD.mjs";
21
- import { t as CircuitBreaker } from "../circuit-breaker-D1fxthDI.mjs";
22
- import { t as markCircuitBreakerLegacySweepDone } from "../circuit-breaker-test-utils-CAdwjgMi.mjs";
17
+ import { _ as verifyJsonLd, a as compactJsonLd, c as detachSignature, h as signJsonLd, i as attachSignature } from "../ld-DCKrqj9y.mjs";
18
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-Dgz_b89j.mjs";
19
+ import { t as doesActorOwnKey } from "../owner-Bdj0nHhf.mjs";
20
+ import { i as verifyObject, r as signObject } from "../proof-DrbjYma9.mjs";
21
+ import { g as handleBenchmarkTrigger, i as KvSpecDeterminer, n as FederationImpl, o as createFederation, r as InboxContextImpl, t as ContextImpl } from "../middleware-D31fNcY4.mjs";
22
+ import { t as SendActivityError } from "../send-VD_WG3dN.mjs";
23
+ import { t as CircuitBreaker } from "../circuit-breaker-B1fLHmg2.mjs";
24
+ import { t as markCircuitBreakerLegacySweepDone } from "../circuit-breaker-test-utils-BGHm_MsT.mjs";
23
25
  import { configure, reset } from "@logtape/logtape";
24
26
  import { RouterError } from "@fedify/uri-template";
25
27
  import * as vocab from "@fedify/vocab";
@@ -28,8 +30,8 @@ import { SpanStatusCode, metrics } from "@opentelemetry/api";
28
30
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
29
31
  import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
30
32
  import serialize from "json-canon";
31
- import { DataPointType, MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
32
33
  import dns from "node:dns/promises";
34
+ import { DataPointType, MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
33
35
  //#region ../fixture/src/fixtures/example.com/create.json
34
36
  var id$2 = "https://example.com/create";
35
37
  var create_default = {
@@ -627,6 +629,104 @@ test("benchmarkMode trigger endpoint", async (t) => {
627
629
  assertEquals(messages[0].inbox, "https://sink.example/inbox");
628
630
  });
629
631
  });
632
+ test("FederationImpl.startQueue()", async (t) => {
633
+ function createCountingQueue() {
634
+ const messages = [];
635
+ let listenCount = 0;
636
+ return {
637
+ messages,
638
+ get listenCount() {
639
+ return listenCount;
640
+ },
641
+ enqueue(message) {
642
+ messages.push(message);
643
+ return Promise.resolve();
644
+ },
645
+ listen() {
646
+ listenCount++;
647
+ return Promise.resolve();
648
+ }
649
+ };
650
+ }
651
+ await t.step("starts a fanout-only queue with an explicit selector", async () => {
652
+ const queue = createCountingQueue();
653
+ const federation = new FederationImpl({
654
+ kv: new MemoryKvStore(),
655
+ queue: { fanout: queue },
656
+ manuallyStartQueue: true
657
+ });
658
+ await federation.startQueue(void 0, { queue: "fanout" });
659
+ assertEquals(queue.listenCount, 1);
660
+ await federation.startQueue(void 0, { queue: "fanout" });
661
+ assertEquals(queue.listenCount, 1);
662
+ });
663
+ await t.step("starts a fanout-only queue without a selector", async () => {
664
+ const queue = createCountingQueue();
665
+ await new FederationImpl({
666
+ kv: new MemoryKvStore(),
667
+ queue: { fanout: queue },
668
+ manuallyStartQueue: true
669
+ }).startQueue(void 0);
670
+ assertEquals(queue.listenCount, 1);
671
+ });
672
+ await t.step("starts a fanout-only queue after a fanout enqueue", async () => {
673
+ const queue = createCountingQueue();
674
+ const ctx = new ContextImpl({
675
+ data: void 0,
676
+ federation: new FederationImpl({
677
+ kv: new MemoryKvStore(),
678
+ contextLoaderFactory: () => mockDocumentLoader,
679
+ queue: { fanout: queue }
680
+ }),
681
+ url: new URL("https://example.com/"),
682
+ documentLoader: mockDocumentLoader,
683
+ contextLoader: mockDocumentLoader
684
+ });
685
+ const activity = new vocab.Create({
686
+ id: new URL("https://example.com/activity/1"),
687
+ actor: new URL("https://example.com/person")
688
+ });
689
+ await ctx.sendActivity([{
690
+ privateKey: rsaPrivateKey2,
691
+ keyId: rsaPublicKey2.id
692
+ }], {
693
+ id: new URL("https://example.com/recipient"),
694
+ inboxId: new URL("https://example.com/inbox")
695
+ }, activity, { fanout: "force" });
696
+ assertEquals(queue.listenCount, 1);
697
+ assertEquals(queue.messages.length, 1);
698
+ assertEquals(queue.messages[0].type, "fanout");
699
+ });
700
+ await t.step("does not start a fanout-only queue automatically when manually started", async () => {
701
+ const queue = createCountingQueue();
702
+ const ctx = new ContextImpl({
703
+ data: void 0,
704
+ federation: new FederationImpl({
705
+ kv: new MemoryKvStore(),
706
+ contextLoaderFactory: () => mockDocumentLoader,
707
+ queue: { fanout: queue },
708
+ manuallyStartQueue: true
709
+ }),
710
+ url: new URL("https://example.com/"),
711
+ documentLoader: mockDocumentLoader,
712
+ contextLoader: mockDocumentLoader
713
+ });
714
+ const activity = new vocab.Create({
715
+ id: new URL("https://example.com/activity/1"),
716
+ actor: new URL("https://example.com/person")
717
+ });
718
+ await ctx.sendActivity([{
719
+ privateKey: rsaPrivateKey2,
720
+ keyId: rsaPublicKey2.id
721
+ }], {
722
+ id: new URL("https://example.com/recipient"),
723
+ inboxId: new URL("https://example.com/inbox")
724
+ }, activity, { fanout: "force" });
725
+ assertEquals(queue.listenCount, 0);
726
+ assertEquals(queue.messages.length, 1);
727
+ assertEquals(queue.messages[0].type, "fanout");
728
+ });
729
+ });
630
730
  test({
631
731
  name: "Federation.createContext()",
632
732
  permissions: {
@@ -1067,6 +1167,22 @@ test({
1067
1167
  localComments: 456
1068
1168
  }
1069
1169
  });
1170
+ await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", { timeout: 0 }), RangeError);
1171
+ const caller = new AbortController();
1172
+ caller.abort();
1173
+ assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
1174
+ signal: caller.signal,
1175
+ timeout: null
1176
+ }), void 0);
1177
+ assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
1178
+ parse: "none",
1179
+ signal: caller.signal,
1180
+ timeout: null
1181
+ }), void 0);
1182
+ await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", {
1183
+ parse: "none",
1184
+ timeout: 0
1185
+ }), RangeError);
1070
1186
  });
1071
1187
  await t.step("RequestContext", async () => {
1072
1188
  const federation = createFederation({
@@ -2011,10 +2127,9 @@ test("Federation.fetch() records HTTP server request metrics", async (t) => {
2011
2127
  });
2012
2128
  await t.step("preserves QUERY as a known HTTP method", async () => {
2013
2129
  const { federation, recorder } = createTestContext();
2014
- assert((await federation.fetch(new Request("https://example.com/users/alice", {
2015
- method: "QUERY",
2016
- headers: { "Accept": "application/activity+json" }
2017
- }), { contextData: void 0 })).status >= 100);
2130
+ const request = new Request("https://example.com/users/alice", { headers: { "Accept": "application/activity+json" } });
2131
+ Object.defineProperty(request, "method", { value: "QUERY" });
2132
+ assert((await federation.fetch(request, { contextData: void 0 })).status >= 100);
2018
2133
  const counts = recorder.getMeasurements("fedify.http.server.request.count");
2019
2134
  assertEquals(counts.length, 1);
2020
2135
  assertEquals(counts[0].attributes["http.request.method"], "QUERY");
@@ -3085,6 +3200,356 @@ test("FederationImpl.sendActivity()", async (t) => {
3085
3200
  });
3086
3201
  esm_default.hardReset();
3087
3202
  });
3203
+ const QUEUE_STARTUP_WARNING = "Failed to start queue workers automatically: {error}";
3204
+ /**
3205
+ * Captures unhandled promise rejections for the duration of a test step.
3206
+ *
3207
+ * Deno dispatches `unhandledrejection` on `globalThis`, while Node.js and Bun
3208
+ * dispatch `unhandledRejection` on `process`. Bun's test runner currently
3209
+ * fires neither, so there the native runner's own unhandled-rejection failure
3210
+ * remains the signal; the assertion is harmless otherwise.
3211
+ */
3212
+ function captureUnhandledRejections() {
3213
+ const reasons = [];
3214
+ const isDeno = "Deno" in globalThis;
3215
+ const onRejectionEvent = (event) => {
3216
+ event.preventDefault();
3217
+ reasons.push(event.reason);
3218
+ };
3219
+ const onProcessRejection = (reason) => {
3220
+ reasons.push(reason);
3221
+ };
3222
+ const globalTarget = globalThis;
3223
+ const proc = globalThis.process;
3224
+ if (isDeno) globalTarget.addEventListener?.("unhandledrejection", onRejectionEvent);
3225
+ else proc?.on?.("unhandledRejection", onProcessRejection);
3226
+ async function settle() {
3227
+ await new Promise((resolve) => setTimeout(resolve, 0));
3228
+ await new Promise((resolve) => setTimeout(resolve, 0));
3229
+ }
3230
+ return {
3231
+ reasons,
3232
+ settle,
3233
+ stop() {
3234
+ if (isDeno) globalTarget.removeEventListener?.("unhandledrejection", onRejectionEvent);
3235
+ else proc?.off?.("unhandledRejection", onProcessRejection);
3236
+ }
3237
+ };
3238
+ }
3239
+ async function configureQueueStartupWarningCapture(records) {
3240
+ await configure({
3241
+ sinks: { buffer(record) {
3242
+ records.push(record);
3243
+ } },
3244
+ loggers: [{
3245
+ category: "fedify",
3246
+ sinks: ["buffer"],
3247
+ lowestLevel: "warning"
3248
+ }, {
3249
+ category: ["logtape", "meta"],
3250
+ sinks: []
3251
+ }],
3252
+ reset: true
3253
+ });
3254
+ }
3255
+ function queueStartupWarnings(records, error) {
3256
+ return records.filter((record) => record.level === "warning" && record.category.length === 3 && record.category[0] === "fedify" && record.category[1] === "federation" && record.category[2] === "queue" && record.rawMessage === QUEUE_STARTUP_WARNING && record.properties.error === error);
3257
+ }
3258
+ test("Federation.fetch() reports automatic queue startup failures", async (t) => {
3259
+ const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
3260
+ const queue = {
3261
+ enqueue() {
3262
+ return Promise.resolve();
3263
+ },
3264
+ listen() {
3265
+ throw listenError;
3266
+ }
3267
+ };
3268
+ const capture = captureUnhandledRejections();
3269
+ const records = [];
3270
+ await configureQueueStartupWarningCapture(records);
3271
+ try {
3272
+ const federation = createFederation({
3273
+ kv: new MemoryKvStore(),
3274
+ queue,
3275
+ skipSignatureVerification: true,
3276
+ documentLoaderFactory: () => mockDocumentLoader,
3277
+ contextLoaderFactory: () => mockDocumentLoader
3278
+ });
3279
+ federation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
3280
+ federation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
3281
+ const post = (id) => federation.fetch(new Request("https://example.com/inbox", {
3282
+ method: "POST",
3283
+ headers: { "Content-Type": "application/activity+json" },
3284
+ body: JSON.stringify({
3285
+ "@context": "https://www.w3.org/ns/activitystreams",
3286
+ id,
3287
+ type: "Create",
3288
+ actor: "https://example.com/actor"
3289
+ })
3290
+ }), { contextData: void 0 });
3291
+ await t.step("synchronous failure", async () => {
3292
+ assertEquals((await post("https://example.com/activities/queued-1")).status, 202);
3293
+ await capture.settle();
3294
+ assertEquals(queueStartupWarnings(records, listenError).length, 1);
3295
+ assertEquals(capture.reasons, []);
3296
+ assertEquals((await post("https://example.com/activities/queued-2")).status, 202);
3297
+ await capture.settle();
3298
+ assertEquals(queueStartupWarnings(records, listenError).length, 1, "the warning must be logged only once per federation instance");
3299
+ assertEquals(capture.reasons, []);
3300
+ });
3301
+ await t.step("asynchronous failure", async () => {
3302
+ const asyncError = /* @__PURE__ */ new TypeError("simulated async listen() failure");
3303
+ let rejectListen;
3304
+ const asyncFederation = createFederation({
3305
+ kv: new MemoryKvStore(),
3306
+ queue: {
3307
+ enqueue() {
3308
+ return Promise.resolve();
3309
+ },
3310
+ listen() {
3311
+ return new Promise((_resolve, reject) => {
3312
+ rejectListen = reject;
3313
+ });
3314
+ }
3315
+ },
3316
+ skipSignatureVerification: true,
3317
+ documentLoaderFactory: () => mockDocumentLoader,
3318
+ contextLoaderFactory: () => mockDocumentLoader
3319
+ });
3320
+ asyncFederation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
3321
+ asyncFederation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
3322
+ assertEquals((await asyncFederation.fetch(new Request("https://example.com/inbox", {
3323
+ method: "POST",
3324
+ headers: { "Content-Type": "application/activity+json" },
3325
+ body: JSON.stringify({
3326
+ "@context": "https://www.w3.org/ns/activitystreams",
3327
+ id: "https://example.com/activities/queued-async",
3328
+ type: "Create",
3329
+ actor: "https://example.com/actor"
3330
+ })
3331
+ }), { contextData: void 0 })).status, 202);
3332
+ await capture.settle();
3333
+ assertEquals(queueStartupWarnings(records, asyncError).length, 0);
3334
+ assert(rejectListen != null);
3335
+ rejectListen(asyncError);
3336
+ await capture.settle();
3337
+ assertEquals(queueStartupWarnings(records, asyncError).length, 1, "a listener that rejects after startup must still be reported");
3338
+ assertEquals(capture.reasons, []);
3339
+ });
3340
+ } finally {
3341
+ await capture.settle();
3342
+ capture.stop();
3343
+ await reset();
3344
+ }
3345
+ });
3346
+ test("Federation.startQueue() rejects when a queue cannot listen", async () => {
3347
+ const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
3348
+ const federation = createFederation({
3349
+ kv: new MemoryKvStore(),
3350
+ queue: {
3351
+ enqueue() {
3352
+ return Promise.resolve();
3353
+ },
3354
+ listen() {
3355
+ throw listenError;
3356
+ }
3357
+ },
3358
+ manuallyStartQueue: true
3359
+ });
3360
+ assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), listenError);
3361
+ });
3362
+ test("Federation.startQueue() keeps other queue workers running", async () => {
3363
+ const outboxError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
3364
+ const lateInboxError = /* @__PURE__ */ new TypeError("simulated late inbox failure");
3365
+ let rejectInbox;
3366
+ let fanoutStarted = false;
3367
+ const inbox = {
3368
+ enqueue() {
3369
+ return Promise.resolve();
3370
+ },
3371
+ listen() {
3372
+ return new Promise((_resolve, reject) => {
3373
+ rejectInbox = reject;
3374
+ });
3375
+ }
3376
+ };
3377
+ const outbox = {
3378
+ enqueue() {
3379
+ return Promise.resolve();
3380
+ },
3381
+ listen() {
3382
+ throw outboxError;
3383
+ }
3384
+ };
3385
+ const fanout = {
3386
+ enqueue() {
3387
+ return Promise.resolve();
3388
+ },
3389
+ listen() {
3390
+ fanoutStarted = true;
3391
+ return new Promise(() => {});
3392
+ }
3393
+ };
3394
+ const capture = captureUnhandledRejections();
3395
+ try {
3396
+ const federation = createFederation({
3397
+ kv: new MemoryKvStore(),
3398
+ queue: {
3399
+ inbox,
3400
+ outbox,
3401
+ fanout
3402
+ },
3403
+ manuallyStartQueue: true
3404
+ });
3405
+ assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), outboxError);
3406
+ assert(fanoutStarted, "a synchronous throw from one queue must not prevent later queues from starting");
3407
+ assert(rejectInbox != null);
3408
+ rejectInbox(lateInboxError);
3409
+ await capture.settle();
3410
+ assertEquals(capture.reasons, [], "an earlier listener rejection must remain handled after startup fails");
3411
+ } finally {
3412
+ await capture.settle();
3413
+ capture.stop();
3414
+ }
3415
+ });
3416
+ test("ContextImpl.sendActivity() reports automatic queue startup failures", async (t) => {
3417
+ const sender = [{
3418
+ privateKey: ed25519PrivateKey,
3419
+ keyId: ed25519Multikey.id
3420
+ }];
3421
+ const recipient = {
3422
+ id: new URL("https://example.com/recipient"),
3423
+ inboxId: new URL("https://example.com/inbox")
3424
+ };
3425
+ const createActivity = () => new Create({
3426
+ id: new URL("https://example.com/activities/queue-startup-send"),
3427
+ actor: new URL("https://example.com/actor")
3428
+ });
3429
+ await t.step("outbox", async () => {
3430
+ const listenError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
3431
+ const messages = [];
3432
+ const queue = {
3433
+ enqueue(message) {
3434
+ messages.push(message);
3435
+ return Promise.resolve();
3436
+ },
3437
+ listen() {
3438
+ throw listenError;
3439
+ }
3440
+ };
3441
+ const capture = captureUnhandledRejections();
3442
+ const records = [];
3443
+ await configureQueueStartupWarningCapture(records);
3444
+ try {
3445
+ await new ContextImpl({
3446
+ data: void 0,
3447
+ federation: new FederationImpl({
3448
+ kv: new MemoryKvStore(),
3449
+ queue: { outbox: queue },
3450
+ documentLoaderFactory: () => mockDocumentLoader,
3451
+ contextLoaderFactory: () => mockDocumentLoader
3452
+ }),
3453
+ url: new URL("https://example.com/"),
3454
+ documentLoader: mockDocumentLoader,
3455
+ contextLoader: mockDocumentLoader
3456
+ }).sendActivity(sender, recipient, createActivity());
3457
+ assertEquals(messages.map((message) => message.type), ["outbox"]);
3458
+ await capture.settle();
3459
+ assertEquals(queueStartupWarnings(records, listenError).length, 1);
3460
+ assertEquals(capture.reasons, []);
3461
+ } finally {
3462
+ await capture.settle();
3463
+ capture.stop();
3464
+ await reset();
3465
+ }
3466
+ });
3467
+ await t.step("fanout", async () => {
3468
+ const listenError = /* @__PURE__ */ new TypeError("simulated fanout listen() failure");
3469
+ const messages = [];
3470
+ const outbox = {
3471
+ enqueue() {
3472
+ return Promise.resolve();
3473
+ },
3474
+ listen() {
3475
+ return Promise.resolve();
3476
+ }
3477
+ };
3478
+ const fanout = {
3479
+ enqueue(message) {
3480
+ messages.push(message);
3481
+ return Promise.resolve();
3482
+ },
3483
+ listen() {
3484
+ throw listenError;
3485
+ }
3486
+ };
3487
+ const capture = captureUnhandledRejections();
3488
+ const records = [];
3489
+ await configureQueueStartupWarningCapture(records);
3490
+ try {
3491
+ await new ContextImpl({
3492
+ data: void 0,
3493
+ federation: new FederationImpl({
3494
+ kv: new MemoryKvStore(),
3495
+ queue: {
3496
+ outbox,
3497
+ fanout
3498
+ },
3499
+ documentLoaderFactory: () => mockDocumentLoader,
3500
+ contextLoaderFactory: () => mockDocumentLoader
3501
+ }),
3502
+ url: new URL("https://example.com/"),
3503
+ documentLoader: mockDocumentLoader,
3504
+ contextLoader: mockDocumentLoader
3505
+ }).sendActivity(sender, recipient, createActivity(), { fanout: "force" });
3506
+ assertEquals(messages.map((message) => message.type), ["fanout"]);
3507
+ await capture.settle();
3508
+ assertEquals(queueStartupWarnings(records, listenError).length, 1);
3509
+ assertEquals(capture.reasons, []);
3510
+ } finally {
3511
+ await capture.settle();
3512
+ capture.stop();
3513
+ await reset();
3514
+ }
3515
+ });
3516
+ });
3517
+ test("queued Linked Data signatures without created use normalization contexts", async (t) => {
3518
+ for (const legacy of [false, true]) await t.step(legacy ? "legacy compacted payload" : "verified normalized cache", async () => {
3519
+ const normalized = await compactJsonLd(ldSignatureWithoutCreated, mockDocumentLoader);
3520
+ const raw = legacy ? normalized : structuredClone(ldSignatureWithoutCreated);
3521
+ const federation = new FederationImpl({
3522
+ kv: new MemoryKvStore(),
3523
+ contextLoaderFactory: () => async (url) => {
3524
+ if (url === "https://www.w3.org/ns/activitystreams" || url === "https://w3id.org/identity/v1") return await mockDocumentLoader(url);
3525
+ throw new Error(`Unexpected context: ${url}`);
3526
+ }
3527
+ });
3528
+ let deliveries = 0;
3529
+ let receivedRaw;
3530
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (ctx, activity) => {
3531
+ deliveries++;
3532
+ receivedRaw = ctx.activity;
3533
+ assertEquals(activity.id?.href, ldSignatureWithoutCreated.id);
3534
+ });
3535
+ await federation.processQueuedTask(void 0, {
3536
+ type: "inbox",
3537
+ id: crypto.randomUUID(),
3538
+ baseUrl: "https://example.com",
3539
+ activity: raw,
3540
+ ...legacy ? {} : {
3541
+ normalizedActivity: normalized,
3542
+ ldSignatureVerified: true
3543
+ },
3544
+ started: (/* @__PURE__ */ new Date()).toISOString(),
3545
+ attempt: 0,
3546
+ identifier: null,
3547
+ traceContext: {}
3548
+ });
3549
+ assertEquals(deliveries, 1);
3550
+ assertEquals(receivedRaw, raw);
3551
+ });
3552
+ });
3088
3553
  test("FederationImpl.processQueuedTask()", async (t) => {
3089
3554
  await t.step("with MessageQueue having nativeRetrial", async () => {
3090
3555
  const kv = new MemoryKvStore();
@@ -6704,15 +7169,19 @@ test("ContextImpl.sendActivity()", async (t) => {
6704
7169
  queue
6705
7170
  });
6706
7171
  federation2.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
6707
- if (identifier !== "john") return null;
7172
+ if (identifier !== "john" && identifier !== "rsa-only") return null;
6708
7173
  const keys = await ctx.getActorKeyPairs(identifier);
6709
7174
  return new vocab.Person({
6710
7175
  id: ctx.getActorUri(identifier),
6711
- preferredUsername: "john",
7176
+ preferredUsername: identifier,
6712
7177
  publicKey: keys[0].cryptographicKey,
6713
7178
  assertionMethods: keys.map((k) => k.multikey)
6714
7179
  });
6715
7180
  }).setKeyPairsDispatcher((_ctx, identifier) => {
7181
+ if (identifier === "rsa-only") return [{
7182
+ privateKey: rsaPrivateKey2,
7183
+ publicKey: rsaPublicKey2.publicKey
7184
+ }];
6716
7185
  if (identifier !== "john") return [];
6717
7186
  return [{
6718
7187
  privateKey: rsaPrivateKey2,
@@ -6761,6 +7230,375 @@ test("ContextImpl.sendActivity()", async (t) => {
6761
7230
  proofCount++;
6762
7231
  }
6763
7232
  assertEquals(proofCount, 1);
7233
+ const oldContext = [
7234
+ "https://w3id.org/identity/v1",
7235
+ "https://www.w3.org/ns/activitystreams",
7236
+ "https://w3id.org/security/data-integrity/v1"
7237
+ ];
7238
+ const oldJson = await (await signObject(new vocab.Create({
7239
+ id: new URL("https://example.com/activity/1"),
7240
+ actor: new URL("https://example.com/john")
7241
+ }), ed25519PrivateKey, ed25519Multikey.id, {
7242
+ contextLoader: documentLoader,
7243
+ context: oldContext
7244
+ })).toJsonLd({
7245
+ format: "compact",
7246
+ contextLoader: documentLoader,
7247
+ context: oldContext
7248
+ });
7249
+ queue.clear();
7250
+ await federation2.processQueuedTask(void 0, {
7251
+ ...fanoutMsg,
7252
+ id: crypto.randomUUID(),
7253
+ activity: oldJson
7254
+ });
7255
+ const replayed = queue.messages.at(-1);
7256
+ assert(replayed != null && replayed.type === "outbox");
7257
+ assertEquals(detachSignature(replayed.activity), oldJson);
7258
+ const proofless = { ...oldJson };
7259
+ delete proofless.proof;
7260
+ queue.clear();
7261
+ await federation2.processQueuedTask(void 0, {
7262
+ ...fanoutMsg,
7263
+ id: crypto.randomUUID(),
7264
+ activity: proofless
7265
+ });
7266
+ const signedReplay = queue.messages.at(-1);
7267
+ assert(signedReplay != null && signedReplay.type === "outbox");
7268
+ assert(typeof signedReplay.activity === "object" && signedReplay.activity != null && "proof" in signedReplay.activity);
7269
+ const edKey = (await ctx2.getActorKeyPairs("john")).find((key) => key.privateKey.algorithm.name === "Ed25519");
7270
+ assert(edKey != null && edKey.multikey.id != null);
7271
+ const restoredJson = await (await signObject(new vocab.Create({
7272
+ id: new URL("https://example.com/activity/old"),
7273
+ actor: ctx2.getActorUri("john")
7274
+ }), edKey.privateKey, edKey.multikey.id, {
7275
+ contextLoader: documentLoader,
7276
+ context: oldContext
7277
+ })).toJsonLd({
7278
+ format: "compact",
7279
+ contextLoader: documentLoader,
7280
+ context: oldContext
7281
+ });
7282
+ const restored = await vocab.Create.fromJsonLd(restoredJson, {
7283
+ contextLoader: documentLoader,
7284
+ documentLoader
7285
+ });
7286
+ queue.clear();
7287
+ await ctx2.sendActivity([{
7288
+ privateKey: rsaPrivateKey2,
7289
+ keyId: rsaPublicKey2.id
7290
+ }], {
7291
+ id: new URL("https://example.com/recipient"),
7292
+ inboxId: new URL("https://example.com/inbox")
7293
+ }, restored);
7294
+ const resent = queue.messages.at(-1);
7295
+ assert(resent != null && resent.type === "outbox");
7296
+ assertEquals(detachSignature(resent.activity), restoredJson);
7297
+ queue.clear();
7298
+ await ctx2.sendActivity([{
7299
+ privateKey: rsaPrivateKey2,
7300
+ keyId: rsaPublicKey2.id
7301
+ }], {
7302
+ id: new URL("https://example.com/recipient"),
7303
+ inboxId: new URL("https://example.com/inbox")
7304
+ }, restored, { fanout: "force" });
7305
+ const queuedFanout = queue.messages.at(-1);
7306
+ assert(queuedFanout != null && queuedFanout.type === "fanout");
7307
+ assertEquals(queuedFanout.activity, restoredJson);
7308
+ const restoredWithSignature = await vocab.Create.fromJsonLd(attachSignature(restoredJson, {
7309
+ "@context": "https://w3id.org/identity/v1",
7310
+ type: "RsaSignature2017",
7311
+ creator: "https://example.com/person2#key4",
7312
+ created: "2026-01-01T00:00:00Z",
7313
+ signatureValue: "abc"
7314
+ }), {
7315
+ contextLoader: documentLoader,
7316
+ documentLoader
7317
+ });
7318
+ queue.clear();
7319
+ await ctx2.sendActivity([{
7320
+ privateKey: rsaPrivateKey2,
7321
+ keyId: rsaPublicKey2.id
7322
+ }], {
7323
+ id: new URL("https://example.com/recipient"),
7324
+ inboxId: new URL("https://example.com/inbox")
7325
+ }, restoredWithSignature);
7326
+ const resigned = queue.messages.at(-1);
7327
+ assert(resigned != null && resigned.type === "outbox");
7328
+ assertEquals(detachSignature(resigned.activity), restoredJson);
7329
+ const rsaOnlyJson = await (await signObject(new vocab.Create({
7330
+ id: new URL("https://example.com/activity/rsa-only"),
7331
+ actor: new URL("https://example.com/rsa-only")
7332
+ }), ed25519PrivateKey, ed25519Multikey.id, {
7333
+ contextLoader: documentLoader,
7334
+ context: oldContext
7335
+ })).toJsonLd({
7336
+ format: "compact",
7337
+ contextLoader: documentLoader,
7338
+ context: oldContext
7339
+ });
7340
+ const rsaOnlyRestored = await vocab.Create.fromJsonLd(rsaOnlyJson, {
7341
+ contextLoader: documentLoader,
7342
+ documentLoader
7343
+ });
7344
+ queue.clear();
7345
+ await ctx2.sendActivity({ identifier: "rsa-only" }, {
7346
+ id: new URL("https://example.com/recipient"),
7347
+ inboxId: new URL("https://example.com/inbox")
7348
+ }, rsaOnlyRestored, { fanout: "force" });
7349
+ const rsaOnlyMessage = queue.messages.at(-1);
7350
+ assert(rsaOnlyMessage != null && rsaOnlyMessage.type === "fanout");
7351
+ assertEquals(rsaOnlyMessage.activity, rsaOnlyJson);
7352
+ queue.clear();
7353
+ await ctx2.sendActivity({ username: "john" }, {
7354
+ id: new URL("https://example.com/recipient"),
7355
+ inboxId: new URL("https://example.com/inbox")
7356
+ }, restored, { fanout: "force" });
7357
+ const namedFanout = queue.messages.at(-1);
7358
+ assert(namedFanout != null && namedFanout.type === "fanout");
7359
+ const namedJson = detachSignature(namedFanout.activity);
7360
+ assertEquals((Array.isArray(namedJson.proof) ? namedJson.proof : [namedJson.proof]).length, 1);
7361
+ assert(namedJson["@context"].includes("https://w3id.org/security/v1"));
7362
+ const noIdJson = await (await signObject(new vocab.Create({ actor: ctx2.getActorUri("john") }), edKey.privateKey, edKey.multikey.id, {
7363
+ contextLoader: documentLoader,
7364
+ context: oldContext
7365
+ })).toJsonLd({
7366
+ format: "compact",
7367
+ contextLoader: documentLoader,
7368
+ context: oldContext
7369
+ });
7370
+ const noIdRestored = await vocab.Create.fromJsonLd(noIdJson, {
7371
+ contextLoader: documentLoader,
7372
+ documentLoader
7373
+ });
7374
+ queue.clear();
7375
+ await ctx2.sendActivity([{
7376
+ privateKey: rsaPrivateKey2,
7377
+ keyId: rsaPublicKey2.id
7378
+ }], {
7379
+ id: new URL("https://example.com/recipient"),
7380
+ inboxId: new URL("https://example.com/inbox")
7381
+ }, noIdRestored);
7382
+ const noIdQueued = queue.messages.at(-1);
7383
+ assert(noIdQueued != null && noIdQueued.type === "outbox");
7384
+ assert(typeof detachSignature(noIdQueued.activity).id === "string");
7385
+ const currentJson = await (await signObject(new vocab.Create({
7386
+ id: new URL("https://example.com/activity/current"),
7387
+ actor: ctx2.getActorUri("john")
7388
+ }), edKey.privateKey, edKey.multikey.id, { contextLoader: documentLoader })).toJsonLd({
7389
+ format: "compact",
7390
+ contextLoader: documentLoader
7391
+ });
7392
+ const currentRestored = await vocab.Create.fromJsonLd(currentJson, {
7393
+ contextLoader: documentLoader,
7394
+ documentLoader
7395
+ });
7396
+ queue.clear();
7397
+ await ctx2.sendActivity({ username: "john" }, {
7398
+ id: new URL("https://example.com/recipient"),
7399
+ inboxId: new URL("https://example.com/inbox")
7400
+ }, currentRestored, { fanout: "force" });
7401
+ const currentFanout = queue.messages.at(-1);
7402
+ assert(currentFanout != null && currentFanout.type === "fanout");
7403
+ const currentQueued = detachSignature(currentFanout.activity);
7404
+ assertEquals((Array.isArray(currentQueued.proof) ? currentQueued.proof : [currentQueued.proof]).length, 2);
7405
+ });
7406
+ queue.clear();
7407
+ await t.step("activity transformers preserve proofs", async () => {
7408
+ const originalProof = new vocab.DataIntegrityProof({
7409
+ cryptosuite: "eddsa-jcs-2022",
7410
+ verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
7411
+ proofPurpose: "assertionMethod",
7412
+ proofValue: new Uint8Array([
7413
+ 1,
7414
+ 2,
7415
+ 3,
7416
+ 4
7417
+ ]),
7418
+ created: Temporal.Instant.from("2026-01-01T00:00:00Z")
7419
+ });
7420
+ const addedProof = new vocab.DataIntegrityProof({
7421
+ cryptosuite: "eddsa-jcs-2022",
7422
+ verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
7423
+ proofPurpose: "assertionMethod",
7424
+ proofValue: new Uint8Array([
7425
+ 5,
7426
+ 6,
7427
+ 7,
7428
+ 8
7429
+ ]),
7430
+ created: Temporal.Instant.from("2026-01-02T00:00:00Z")
7431
+ });
7432
+ const replacementProof = new vocab.DataIntegrityProof({
7433
+ cryptosuite: "eddsa-jcs-2022",
7434
+ verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
7435
+ proofPurpose: "assertionMethod",
7436
+ proofValue: new Uint8Array([
7437
+ 9,
7438
+ 10,
7439
+ 11,
7440
+ 12
7441
+ ]),
7442
+ created: Temporal.Instant.from("2026-01-03T00:00:00Z")
7443
+ });
7444
+ const restoredProof = new vocab.DataIntegrityProof({
7445
+ cryptosuite: "eddsa-jcs-2022",
7446
+ verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
7447
+ proofPurpose: "assertionMethod",
7448
+ proofValue: new Uint8Array([
7449
+ 13,
7450
+ 14,
7451
+ 15,
7452
+ 16
7453
+ ]),
7454
+ created: Temporal.Instant.from("2026-01-04T00:00:00Z")
7455
+ });
7456
+ const restoredProofHolder = {};
7457
+ const federation3 = new FederationImpl({
7458
+ kv,
7459
+ allowPrivateAddress: true,
7460
+ queue,
7461
+ activityTransformers: [(activity) => {
7462
+ if (activity.id?.href === "https://example.com/activity/transformed-proof") return activity.clone({ proofs: [originalProof, addedProof] });
7463
+ if (activity.id?.href === "https://example.com/activity/replaced-proof") return new vocab.Create({
7464
+ id: activity.id,
7465
+ actor: new URL("https://example.com/rsa-only"),
7466
+ object: new URL("https://example.com/note/replaced"),
7467
+ proofs: [replacementProof]
7468
+ });
7469
+ if (activity.id?.href === "https://example.com/activity/restored-proof") return activity.clone({ proofs: [restoredProofHolder.old, restoredProof] });
7470
+ return activity;
7471
+ }]
7472
+ });
7473
+ federation3.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
7474
+ if (identifier !== "rsa-only") return null;
7475
+ const keys = await ctx.getActorKeyPairs(identifier);
7476
+ return new vocab.Person({
7477
+ id: ctx.getActorUri(identifier),
7478
+ preferredUsername: identifier,
7479
+ publicKey: keys[0].cryptographicKey,
7480
+ assertionMethods: keys.map((k) => k.multikey)
7481
+ });
7482
+ }).setKeyPairsDispatcher((_ctx, identifier) => identifier === "rsa-only" ? [{
7483
+ privateKey: rsaPrivateKey2,
7484
+ publicKey: rsaPublicKey2.publicKey
7485
+ }] : []);
7486
+ const ctx3 = new ContextImpl({
7487
+ data: void 0,
7488
+ federation: federation3,
7489
+ url: new URL("https://example.com/"),
7490
+ documentLoader,
7491
+ contextLoader: documentLoader
7492
+ });
7493
+ const activity = new vocab.Create({
7494
+ id: new URL("https://example.com/activity/transformed-proof"),
7495
+ actor: ctx3.getActorUri("rsa-only"),
7496
+ proofs: [originalProof]
7497
+ });
7498
+ await ctx3.sendActivity({ identifier: "rsa-only" }, {
7499
+ id: new URL("https://example.com/recipient"),
7500
+ inboxId: new URL("https://example.com/inbox")
7501
+ }, activity, { fanout: "force" });
7502
+ const fanout = queue.messages.at(-1);
7503
+ assert(fanout != null && fanout.type === "fanout");
7504
+ const fanoutJson = detachSignature(fanout.activity);
7505
+ assertEquals((Array.isArray(fanoutJson.proof) ? fanoutJson.proof : [fanoutJson.proof]).length, 2);
7506
+ const replacedActivity = new vocab.Create({
7507
+ id: new URL("https://example.com/activity/replaced-proof"),
7508
+ actor: ctx3.getActorUri("rsa-only"),
7509
+ proofs: [originalProof]
7510
+ });
7511
+ queue.clear();
7512
+ await ctx3.sendActivity({ identifier: "rsa-only" }, {
7513
+ id: new URL("https://example.com/recipient"),
7514
+ inboxId: new URL("https://example.com/inbox")
7515
+ }, replacedActivity, { fanout: "force" });
7516
+ const replacedFanout = queue.messages.at(-1);
7517
+ assert(replacedFanout != null && replacedFanout.type === "fanout");
7518
+ const replacedJson = detachSignature(replacedFanout.activity);
7519
+ assertEquals(replacedJson.object, "https://example.com/note/replaced");
7520
+ const replacedProofs = Array.isArray(replacedJson.proof) ? replacedJson.proof : [replacedJson.proof];
7521
+ assertEquals(replacedProofs.length, 1);
7522
+ const [keptProof] = replacedProofs;
7523
+ assertEquals(keptProof.created, "2026-01-03T00:00:00Z");
7524
+ const oldContext = [
7525
+ "https://w3id.org/identity/v1",
7526
+ "https://www.w3.org/ns/activitystreams",
7527
+ "https://w3id.org/security/data-integrity/v1"
7528
+ ];
7529
+ const restoredJson = await (await signObject(new vocab.Create({
7530
+ id: new URL("https://example.com/activity/restored-proof"),
7531
+ actor: ctx3.getActorUri("rsa-only")
7532
+ }), ed25519PrivateKey, ed25519Multikey.id, {
7533
+ contextLoader: documentLoader,
7534
+ context: oldContext
7535
+ })).toJsonLd({
7536
+ format: "compact",
7537
+ contextLoader: documentLoader,
7538
+ context: oldContext
7539
+ });
7540
+ const restored = await vocab.Create.fromJsonLd(restoredJson, {
7541
+ contextLoader: documentLoader,
7542
+ documentLoader
7543
+ });
7544
+ for await (const proof of restored.getProofs({ contextLoader: documentLoader })) {
7545
+ restoredProofHolder.old = proof;
7546
+ break;
7547
+ }
7548
+ queue.clear();
7549
+ await ctx3.sendActivity({ identifier: "rsa-only" }, {
7550
+ id: new URL("https://example.com/recipient"),
7551
+ inboxId: new URL("https://example.com/inbox")
7552
+ }, restored, { fanout: "force" });
7553
+ const restoredFanout = queue.messages.at(-1);
7554
+ assert(restoredFanout != null && restoredFanout.type === "fanout");
7555
+ const restoredFanoutJson = detachSignature(restoredFanout.activity);
7556
+ const restoredProofs = Array.isArray(restoredFanoutJson.proof) ? restoredFanoutJson.proof : [restoredFanoutJson.proof];
7557
+ assertEquals(restoredProofs.length, 1);
7558
+ const [transformedProof] = restoredProofs;
7559
+ assertEquals(transformedProof.created, "2026-01-04T00:00:00Z");
7560
+ assert(Array.isArray(restoredFanoutJson["@context"]) && restoredFanoutJson["@context"].includes("https://w3id.org/security/v1"));
7561
+ const staleTimestampJson = await (await signObject(new vocab.Create({
7562
+ id: new URL("https://example.com/activity/stale-timestamp"),
7563
+ actor: ctx3.getActorUri("rsa-only")
7564
+ }), ed25519PrivateKey, ed25519Multikey.id, {
7565
+ contextLoader: documentLoader,
7566
+ context: oldContext
7567
+ })).toJsonLd({
7568
+ format: "compact",
7569
+ contextLoader: documentLoader,
7570
+ context: oldContext
7571
+ });
7572
+ const staleTimestampProof = Array.isArray(staleTimestampJson.proof) ? staleTimestampJson.proof[0] : staleTimestampJson.proof;
7573
+ staleTimestampProof.created = "2026-01-01T00:00:00+00:00";
7574
+ const staleTimestamp = await vocab.Create.fromJsonLd(staleTimestampJson, {
7575
+ contextLoader: documentLoader,
7576
+ documentLoader
7577
+ });
7578
+ queue.clear();
7579
+ await ctx3.sendActivity({ identifier: "rsa-only" }, {
7580
+ id: new URL("https://example.com/recipient"),
7581
+ inboxId: new URL("https://example.com/inbox")
7582
+ }, staleTimestamp, { fanout: "force" });
7583
+ const staleTimestampFanout = queue.messages.at(-1);
7584
+ assert(staleTimestampFanout != null && staleTimestampFanout.type === "fanout");
7585
+ assertEquals(detachSignature(staleTimestampFanout.activity), staleTimestampJson);
7586
+ const proofless = new vocab.Create({
7587
+ id: new URL("https://example.com/activity/proofless"),
7588
+ actor: ctx3.getActorUri("rsa-only")
7589
+ });
7590
+ let unformattedSerializations = 0;
7591
+ const originalToJsonLd = proofless.toJsonLd.bind(proofless);
7592
+ Object.defineProperty(proofless, "toJsonLd", { value: async (options) => {
7593
+ if (options?.format == null) unformattedSerializations++;
7594
+ return await originalToJsonLd(options);
7595
+ } });
7596
+ queue.clear();
7597
+ await ctx3.sendActivity({ identifier: "rsa-only" }, {
7598
+ id: new URL("https://example.com/recipient"),
7599
+ inboxId: new URL("https://example.com/inbox")
7600
+ }, proofless, { fanout: "skip" });
7601
+ assertEquals(unformattedSerializations, 0);
6764
7602
  });
6765
7603
  queue.clear();
6766
7604
  await t.step("fanout: \"force\" preserves pre-signed proof normalization", async () => {
@@ -7754,6 +8592,63 @@ test("InboxContextImpl.forwardActivity()", async (t) => {
7754
8592
  });
7755
8593
  esm_default.hardReset();
7756
8594
  });
8595
+ test("InboxContextImpl.forwardActivity() without created", async (t) => {
8596
+ for (const immediate of [true, false]) await t.step(immediate ? "immediate delivery" : "queued delivery", async () => {
8597
+ const delivered = [];
8598
+ const queued = [];
8599
+ esm_default.spyGlobal();
8600
+ esm_default.post("https://example.com/inbox", async (call) => {
8601
+ delivered.push(await call.request.json());
8602
+ return new Response(null, { status: 202 });
8603
+ });
8604
+ try {
8605
+ const federation = new FederationImpl({
8606
+ kv: new MemoryKvStore(),
8607
+ allowPrivateAddress: true,
8608
+ manuallyStartQueue: true,
8609
+ queue: { outbox: {
8610
+ enqueue(message) {
8611
+ queued.push(message);
8612
+ return Promise.resolve();
8613
+ },
8614
+ async listen() {}
8615
+ } }
8616
+ });
8617
+ const activity = structuredClone(ldSignatureWithoutCreated);
8618
+ assert(await verifyJsonLd(activity, {
8619
+ documentLoader: mockDocumentLoader,
8620
+ contextLoader: mockDocumentLoader
8621
+ }));
8622
+ await new InboxContextImpl(null, activity, activity.id, "https://www.w3.org/ns/activitystreams#Create", {
8623
+ data: void 0,
8624
+ federation,
8625
+ url: new URL("https://example.com/"),
8626
+ documentLoader: mockDocumentLoader,
8627
+ contextLoader: mockDocumentLoader
8628
+ }).forwardActivity([{
8629
+ privateKey: rsaPrivateKey2,
8630
+ keyId: rsaPublicKey2.id
8631
+ }], {
8632
+ id: new URL("https://example.com/recipient"),
8633
+ inboxId: new URL("https://example.com/inbox")
8634
+ }, {
8635
+ skipIfUnsigned: true,
8636
+ immediate
8637
+ });
8638
+ if (immediate) {
8639
+ assertEquals(delivered, [activity]);
8640
+ assertEquals(queued, []);
8641
+ } else {
8642
+ assertEquals(delivered, []);
8643
+ assertEquals(queued.length, 1);
8644
+ assertEquals(queued[0].type, "outbox");
8645
+ assertEquals(queued[0].activity, activity);
8646
+ }
8647
+ } finally {
8648
+ esm_default.hardReset();
8649
+ }
8650
+ });
8651
+ });
7757
8652
  test("KvSpecDeterminer", async (t) => {
7758
8653
  await t.step("should use default spec when not found in KV", async () => {
7759
8654
  assertEquals(await new KvSpecDeterminer(new MemoryKvStore(), ["test", "spec"]).determineSpec("example.com"), "rfc9421");
@@ -7866,6 +8761,286 @@ test("ContextImpl.sendActivity() honors the private-address policy", async (t) =
7866
8761
  }
7867
8762
  });
7868
8763
  });
8764
+ function deferredSignal() {
8765
+ let resolve;
8766
+ return {
8767
+ promise: new Promise((r) => resolve = r),
8768
+ resolve
8769
+ };
8770
+ }
8771
+ test("ContextImpl.sendActivity() waits for sibling deliveries on failure", async () => {
8772
+ const failingInbox = "http://127.0.0.1:3001/inbox/fail";
8773
+ const slowInbox = "http://127.0.0.1:3002/inbox/slow";
8774
+ const failingEntered = deferredSignal();
8775
+ const slowEntered = deferredSignal();
8776
+ const slowCompleted = deferredSignal();
8777
+ let releaseSlow;
8778
+ const slowGate = new Promise((resolve) => releaseSlow = resolve);
8779
+ let slowStarted = false;
8780
+ let slowSettled = false;
8781
+ esm_default.spyGlobal();
8782
+ esm_default.post(failingInbox, () => {
8783
+ failingEntered.resolve();
8784
+ return new Response(null, { status: 500 });
8785
+ });
8786
+ esm_default.post(slowInbox, async () => {
8787
+ slowStarted = true;
8788
+ slowEntered.resolve();
8789
+ await slowGate;
8790
+ slowSettled = true;
8791
+ slowCompleted.resolve();
8792
+ return new Response(null, { status: 202 });
8793
+ });
8794
+ let observed;
8795
+ let released = false;
8796
+ try {
8797
+ const ctx = createFederation({
8798
+ kv: new MemoryKvStore(),
8799
+ allowPrivateAddress: true
8800
+ }).createContext(new URL("https://example.com/"));
8801
+ const activity = new Create({
8802
+ id: new URL("https://example.com/activity/fanout"),
8803
+ actor: new URL("https://example.com/person")
8804
+ });
8805
+ let outerSettled = false;
8806
+ let outerError;
8807
+ observed = ctx.sendActivity([{
8808
+ privateKey: ed25519PrivateKey,
8809
+ keyId: ed25519Multikey.id
8810
+ }], [new Person({
8811
+ id: new URL("https://example.com/recipients/failing"),
8812
+ inbox: new URL(failingInbox)
8813
+ }), new Person({
8814
+ id: new URL("https://example.com/recipients/slow"),
8815
+ inbox: new URL(slowInbox)
8816
+ })], activity, { immediate: true }).then(() => {
8817
+ outerSettled = true;
8818
+ }, (error) => {
8819
+ outerSettled = true;
8820
+ outerError = error;
8821
+ });
8822
+ await Promise.all([failingEntered.promise, slowEntered.promise]);
8823
+ await new Promise((resolve) => setTimeout(resolve, 0));
8824
+ assertFalse(outerSettled, "sendActivity() must wait for sibling deliveries before rejecting");
8825
+ releaseSlow();
8826
+ released = true;
8827
+ await observed;
8828
+ assert(slowSettled, "the delayed delivery should have settled");
8829
+ assertInstanceOf(outerError, SendActivityError);
8830
+ } finally {
8831
+ if (!released) releaseSlow();
8832
+ if (slowStarted) await slowCompleted.promise;
8833
+ await observed;
8834
+ esm_default.hardReset();
8835
+ }
8836
+ });
8837
+ test("InboxContextImpl.forwardActivity() waits for sibling deliveries on failure", async () => {
8838
+ const failingInbox = "http://127.0.0.1:3003/inbox/fail";
8839
+ const slowInbox = "http://127.0.0.1:3004/inbox/slow";
8840
+ const failingEntered = deferredSignal();
8841
+ const slowEntered = deferredSignal();
8842
+ const slowCompleted = deferredSignal();
8843
+ let releaseSlow;
8844
+ const slowGate = new Promise((resolve) => releaseSlow = resolve);
8845
+ let slowStarted = false;
8846
+ let slowSettled = false;
8847
+ esm_default.spyGlobal();
8848
+ esm_default.post(failingInbox, () => {
8849
+ failingEntered.resolve();
8850
+ return new Response(null, { status: 500 });
8851
+ });
8852
+ esm_default.post(slowInbox, async () => {
8853
+ slowStarted = true;
8854
+ slowEntered.resolve();
8855
+ await slowGate;
8856
+ slowSettled = true;
8857
+ slowCompleted.resolve();
8858
+ return new Response(null, { status: 202 });
8859
+ });
8860
+ let observed;
8861
+ let released = false;
8862
+ try {
8863
+ const federation = new FederationImpl({
8864
+ kv: new MemoryKvStore(),
8865
+ allowPrivateAddress: true
8866
+ });
8867
+ const activity = await signObject(new vocab.Create({
8868
+ id: new URL("https://example.com/activity/forward"),
8869
+ actor: new URL("https://example.com/person2")
8870
+ }), ed25519PrivateKey, ed25519Multikey.id, {
8871
+ contextLoader: mockDocumentLoader,
8872
+ documentLoader: mockDocumentLoader
8873
+ });
8874
+ const ctx = new InboxContextImpl(null, await activity.toJsonLd({ contextLoader: mockDocumentLoader }), activity.id?.href, getTypeId(activity).href, {
8875
+ data: void 0,
8876
+ federation,
8877
+ url: new URL("https://example.com/"),
8878
+ documentLoader: mockDocumentLoader,
8879
+ contextLoader: mockDocumentLoader
8880
+ });
8881
+ let outerSettled = false;
8882
+ let outerError;
8883
+ observed = ctx.forwardActivity([{
8884
+ privateKey: ed25519PrivateKey,
8885
+ keyId: ed25519Multikey.id
8886
+ }], [{
8887
+ id: new URL("https://example.com/recipients/failing"),
8888
+ inboxId: new URL(failingInbox)
8889
+ }, {
8890
+ id: new URL("https://example.com/recipients/slow"),
8891
+ inboxId: new URL(slowInbox)
8892
+ }], {
8893
+ immediate: true,
8894
+ skipIfUnsigned: true
8895
+ }).then(() => {
8896
+ outerSettled = true;
8897
+ }, (error) => {
8898
+ outerSettled = true;
8899
+ outerError = error;
8900
+ });
8901
+ await Promise.all([failingEntered.promise, slowEntered.promise]);
8902
+ await new Promise((resolve) => setTimeout(resolve, 0));
8903
+ assertFalse(outerSettled, "forwardActivity() must wait for sibling deliveries before rejecting");
8904
+ releaseSlow();
8905
+ released = true;
8906
+ await observed;
8907
+ assert(slowSettled, "the delayed delivery should have settled");
8908
+ assertInstanceOf(outerError, SendActivityError);
8909
+ } finally {
8910
+ if (!released) releaseSlow();
8911
+ if (slowStarted) await slowCompleted.promise;
8912
+ await observed;
8913
+ esm_default.hardReset();
8914
+ }
8915
+ });
8916
+ test("FederationImpl.sendActivity() drains deliveries when fan-out setup fails", async () => {
8917
+ const slowInbox = "http://127.0.0.1:3005/inbox/slow";
8918
+ const slowEntered = deferredSignal();
8919
+ const slowCompleted = deferredSignal();
8920
+ let releaseSlow;
8921
+ const slowGate = new Promise((resolve) => releaseSlow = resolve);
8922
+ let slowStarted = false;
8923
+ let slowSettled = false;
8924
+ esm_default.spyGlobal();
8925
+ esm_default.post(slowInbox, async () => {
8926
+ slowStarted = true;
8927
+ slowEntered.resolve();
8928
+ await slowGate;
8929
+ slowSettled = true;
8930
+ slowCompleted.resolve();
8931
+ return new Response(null, { status: 202 });
8932
+ });
8933
+ let observed;
8934
+ let released = false;
8935
+ try {
8936
+ const federation = new FederationImpl({
8937
+ kv: new MemoryKvStore(),
8938
+ allowPrivateAddress: true
8939
+ });
8940
+ const context = federation.createContext(new URL("https://example.com/"));
8941
+ const activity = new Create({
8942
+ id: new URL("https://example.com/activity/setup-failure"),
8943
+ actor: new URL("https://example.com/person")
8944
+ });
8945
+ let outerSettled = false;
8946
+ let outerError;
8947
+ observed = federation.sendActivity([{
8948
+ privateKey: ed25519PrivateKey,
8949
+ keyId: ed25519Multikey.id
8950
+ }], {
8951
+ [slowInbox]: {
8952
+ actorIds: ["https://example.com/recipients/slow"],
8953
+ sharedInbox: false
8954
+ },
8955
+ "not a url": {
8956
+ actorIds: ["https://example.com/recipients/invalid"],
8957
+ sharedInbox: false
8958
+ }
8959
+ }, activity, {
8960
+ context,
8961
+ immediate: true
8962
+ }).then(() => {
8963
+ outerSettled = true;
8964
+ }, (error) => {
8965
+ outerSettled = true;
8966
+ outerError = error;
8967
+ });
8968
+ await slowEntered.promise;
8969
+ await new Promise((resolve) => setTimeout(resolve, 0));
8970
+ assertFalse(outerSettled, "sendActivity() must drain started deliveries when fan-out setup fails");
8971
+ releaseSlow();
8972
+ released = true;
8973
+ await observed;
8974
+ assert(slowSettled, "the started delivery should have settled");
8975
+ assertInstanceOf(outerError, TypeError);
8976
+ } finally {
8977
+ if (!released) releaseSlow();
8978
+ if (slowStarted) await slowCompleted.promise;
8979
+ await observed;
8980
+ esm_default.hardReset();
8981
+ }
8982
+ });
8983
+ test("FederationImpl.sendActivity() handles rejections while building headers", async () => {
8984
+ const federation = new FederationImpl({ kv: new MemoryKvStore() });
8985
+ const context = federation.createContext(new URL("https://example.com/"));
8986
+ const activity = await signObject(new Create({
8987
+ id: new URL("https://example.com/activity/header-failure"),
8988
+ actor: new URL("https://example.com/person")
8989
+ }), ed25519PrivateKey, ed25519Multikey.id, {
8990
+ contextLoader: mockDocumentLoader,
8991
+ documentLoader: mockDocumentLoader
8992
+ });
8993
+ const subtle = crypto.subtle;
8994
+ const originalDigest = subtle.digest;
8995
+ let digestCalls = 0;
8996
+ let releaseSecondDigest;
8997
+ const secondDigestGate = new Promise((resolve) => {
8998
+ releaseSecondDigest = resolve;
8999
+ });
9000
+ let secondDigestStarted;
9001
+ const secondDigestEntered = new Promise((resolve) => {
9002
+ secondDigestStarted = resolve;
9003
+ });
9004
+ subtle.digest = async (algorithm, data) => {
9005
+ digestCalls++;
9006
+ if (digestCalls === 2) {
9007
+ secondDigestStarted();
9008
+ await secondDigestGate;
9009
+ }
9010
+ return await originalDigest.call(subtle, algorithm, data);
9011
+ };
9012
+ const capture = captureUnhandledRejections();
9013
+ let released = false;
9014
+ try {
9015
+ const observed = federation.sendActivity([{
9016
+ privateKey: ed25519PrivateKey,
9017
+ keyId: ed25519Multikey.id
9018
+ }], {
9019
+ "ftp://example.com/fail": {
9020
+ actorIds: ["https://example.com/recipients/failing"],
9021
+ sharedInbox: false
9022
+ },
9023
+ "http://127.0.0.1:3006/inbox": {
9024
+ actorIds: ["https://example.com/recipients/slow"],
9025
+ sharedInbox: false
9026
+ }
9027
+ }, activity, {
9028
+ context,
9029
+ immediate: true,
9030
+ collectionSync: "https://example.com/followers"
9031
+ }).catch((error) => error);
9032
+ await secondDigestEntered;
9033
+ await capture.settle();
9034
+ assertEquals(capture.reasons, [], "an early rejection must not surface as an unhandled rejection");
9035
+ releaseSecondDigest();
9036
+ released = true;
9037
+ await observed;
9038
+ } finally {
9039
+ if (!released) releaseSecondDigest();
9040
+ subtle.digest = originalDigest;
9041
+ capture.stop();
9042
+ }
9043
+ });
7869
9044
  test("Federation.fetch() bounds inbox bodies before dispatch", async () => {
7870
9045
  let dispatched = false;
7871
9046
  const json = JSON.stringify({