@fedify/fedify 2.4.6-dev.2628 → 2.4.6

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 (133) hide show
  1. package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
  2. package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
  3. package/dist/callback-DPDs_dxC.d.mts +5280 -0
  4. package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
  5. package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
  6. package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.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.cjs +1 -1
  10. package/dist/compat/mod.d.cts +1 -1
  11. package/dist/compat/mod.d.ts +1 -1
  12. package/dist/compat/mod.js +1 -1
  13. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  14. package/dist/compat/transformers.test.mjs +1 -1
  15. package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
  16. package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
  17. package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
  18. package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
  19. package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
  20. package/dist/federation/attachment-responses.test.d.mts +2 -0
  21. package/dist/federation/attachment-responses.test.mjs +182 -0
  22. package/dist/federation/builder.test.mjs +1 -1
  23. package/dist/federation/compound-fanout.test.mjs +4 -4
  24. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  25. package/dist/federation/delivery-attachments.test.mjs +288 -0
  26. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  27. package/dist/federation/handler.test.mjs +206 -14
  28. package/dist/federation/hashlink-media.test.mjs +2 -2
  29. package/dist/federation/idempotency.test.mjs +2 -2
  30. package/dist/federation/inbox-report.test.mjs +5 -5
  31. package/dist/federation/inbox.test.mjs +1 -1
  32. package/dist/federation/metrics.test.mjs +1 -1
  33. package/dist/federation/middleware.test.mjs +1188 -13
  34. package/dist/federation/mod.cjs +1 -1
  35. package/dist/federation/mod.d.cts +3 -3
  36. package/dist/federation/mod.d.ts +3 -3
  37. package/dist/federation/mod.js +1 -1
  38. package/dist/federation/outgoing-proof.test.mjs +4 -4
  39. package/dist/federation/portable-actor.test.mjs +3 -3
  40. package/dist/federation/portable-chain.test.mjs +3 -3
  41. package/dist/federation/portable-collection.test.mjs +4 -4
  42. package/dist/federation/portable-delivery.test.mjs +2 -2
  43. package/dist/federation/portable-gateway-keys.test.mjs +5 -5
  44. package/dist/federation/portable-inbox.test.mjs +4 -4
  45. package/dist/federation/portable-parse-uri.test.mjs +1 -1
  46. package/dist/federation/portable-route-activity.test.mjs +2 -2
  47. package/dist/federation/portable.test.mjs +3 -3
  48. package/dist/federation/send.test.mjs +293 -3
  49. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  50. package/dist/federation/tasks/tasks.test.mjs +2 -2
  51. package/dist/federation/temporal.test.mjs +25 -1
  52. package/dist/federation/webfinger.test.mjs +1 -1
  53. package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
  54. package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
  55. package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
  56. package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
  57. package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
  58. package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
  59. package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
  60. package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
  61. package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
  62. package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
  63. package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
  64. package/dist/ld-signature-D1tFSFK8.mjs +23 -0
  65. package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
  66. package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
  67. package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
  68. package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
  69. package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
  70. package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
  71. package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
  72. package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
  73. package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
  74. package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
  75. package/dist/mod.cjs +6 -6
  76. package/dist/mod.d.cts +8 -8
  77. package/dist/mod.d.ts +8 -8
  78. package/dist/mod.js +6 -6
  79. package/dist/nodeinfo/client.test.mjs +432 -4
  80. package/dist/nodeinfo/handler.test.mjs +1 -1
  81. package/dist/nodeinfo/mod.cjs +1 -1
  82. package/dist/nodeinfo/mod.d.cts +1 -1
  83. package/dist/nodeinfo/mod.d.ts +1 -1
  84. package/dist/nodeinfo/mod.js +1 -1
  85. package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
  86. package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
  87. package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
  88. package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
  89. package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
  90. package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
  91. package/dist/portable-verifier-CPA86vIP.js +22 -0
  92. package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
  93. package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
  94. package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
  95. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  96. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  97. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  98. package/dist/sig/compound-proof.test.mjs +3 -3
  99. package/dist/sig/http.test.mjs +2 -2
  100. package/dist/sig/key-types.test.d.mts +162 -0
  101. package/dist/sig/key-types.test.mjs +8 -0
  102. package/dist/sig/key.test.mjs +1 -1
  103. package/dist/sig/ld.test.mjs +572 -7
  104. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  105. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  106. package/dist/sig/mod.cjs +2 -2
  107. package/dist/sig/mod.d.cts +3 -3
  108. package/dist/sig/mod.d.ts +3 -3
  109. package/dist/sig/mod.js +2 -2
  110. package/dist/sig/owner.test.mjs +1 -1
  111. package/dist/sig/portable-collection.test.mjs +1 -1
  112. package/dist/sig/portable-interop.test.mjs +3 -3
  113. package/dist/sig/portable-key.test.mjs +5 -5
  114. package/dist/sig/proof.test.mjs +100 -6
  115. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  116. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  117. package/dist/sig/verification.test.mjs +3 -3
  118. package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
  119. package/dist/testing/kv.test.mjs +1 -1
  120. package/dist/testing/mod.d.mts +3 -5045
  121. package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
  122. package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
  123. package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
  124. package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
  125. package/dist/utils/docloader.test.mjs +2 -2
  126. package/dist/utils/kv-cache.test.mjs +1 -1
  127. package/dist/utils/mod.cjs +1 -1
  128. package/dist/utils/mod.d.cts +1 -1
  129. package/dist/utils/mod.d.ts +1 -1
  130. package/dist/utils/mod.js +1 -1
  131. package/dist/utils/portable-verifier.test.d.mts +2 -0
  132. package/dist/utils/portable-verifier.test.mjs +126 -0
  133. package/package.json +6 -6
@@ -5,11 +5,15 @@ import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
6
6
  import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
7
7
  import "../std__assert-DvMDRPes.mjs";
8
- import { a as parseOutboundService, c as parseSoftware, i as parseNodeInfo, l as parseUsage, n as getNodeInfoInternal, o as parseProtocol, r as parseInboundService, s as parseServices, t as getNodeInfo } from "../client-5SIFzW3q.mjs";
8
+ import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
9
+ import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
10
+ import { a as parseOutboundService, c as parseSoftware, i as parseNodeInfo, l as parseUsage, n as getNodeInfoInternal, o as parseProtocol, r as parseInboundService, s as parseServices, t as getNodeInfo } from "../client-DU3owZBD.mjs";
9
11
  import { configure, reset } from "@logtape/logtape";
10
12
  import { UrlError } from "@fedify/vocab-runtime";
11
13
  import { test } from "@fedify/fixture";
12
- import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
14
+ import { detectRuntime, openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
15
+ import dns from "node:dns/promises";
16
+ import { createServer } from "node:http";
13
17
  //#region src/nodeinfo/client.test.ts
14
18
  function getNodeInfoDirect(url, options) {
15
19
  return getNodeInfoInternal(url, options, { openHop: openDirectFetch });
@@ -1049,6 +1053,64 @@ test("getNodeInfo() logs DNS failures as such", async (t) => {
1049
1053
  }
1050
1054
  });
1051
1055
  });
1056
+ test("getNodeInfo() bounds and cancels default Node.js DNS lookups", { ignore: detectRuntime() !== "node" }, async () => {
1057
+ const originalLookup = dns.lookup;
1058
+ const pending = [];
1059
+ const hostnames = [];
1060
+ const twoStarted = deferred();
1061
+ const records = [];
1062
+ dns.lookup = ((hostname) => {
1063
+ hostnames.push(hostname);
1064
+ const lookup = deferred();
1065
+ pending.push(lookup);
1066
+ if (hostnames.length === 2) twoStarted.resolve();
1067
+ return lookup.promise;
1068
+ });
1069
+ try {
1070
+ await configure({
1071
+ sinks: { buffer: (record) => records.push(record) },
1072
+ loggers: [{
1073
+ category: "fedify",
1074
+ sinks: ["buffer"],
1075
+ lowestLevel: "debug"
1076
+ }, {
1077
+ category: ["logtape", "meta"],
1078
+ sinks: []
1079
+ }],
1080
+ reset: true
1081
+ });
1082
+ const first = getNodeInfo("https://first.example/nodeinfo", {
1083
+ direct: true,
1084
+ timeout: 50
1085
+ });
1086
+ const second = getNodeInfo("https://second.example/nodeinfo", {
1087
+ direct: true,
1088
+ timeout: 50
1089
+ });
1090
+ await settleWithin(twoStarted.promise, 1e3);
1091
+ assertEquals(await settleWithin(getNodeInfo("https://third.example/nodeinfo", {
1092
+ direct: true,
1093
+ timeout: 20
1094
+ }), 1e3), void 0);
1095
+ assertEquals(await settleWithin(first, 1e3), void 0);
1096
+ assertEquals(await settleWithin(second, 1e3), void 0);
1097
+ assertEquals(hostnames, ["first.example", "second.example"]);
1098
+ for (const lookup of pending) lookup.resolve([{
1099
+ address: "93.184.215.14",
1100
+ family: 4
1101
+ }]);
1102
+ await new Promise((resolve) => setTimeout(resolve, 0));
1103
+ assertEquals(hostnames, ["first.example", "second.example"]);
1104
+ assertEquals(records.some((record) => String(record.rawMessage).includes("DNS lookup failed")), false);
1105
+ } finally {
1106
+ dns.lookup = originalLookup;
1107
+ for (const lookup of pending) lookup.resolve([{
1108
+ address: "93.184.215.14",
1109
+ family: 4
1110
+ }]);
1111
+ await reset();
1112
+ }
1113
+ });
1052
1114
  function recordHops(respond) {
1053
1115
  const events = [];
1054
1116
  const unsettled = [];
@@ -1116,6 +1178,347 @@ function recordHops(respond) {
1116
1178
  }
1117
1179
  };
1118
1180
  }
1181
+ function deferred() {
1182
+ let resolve;
1183
+ return {
1184
+ promise: new Promise((done) => resolve = done),
1185
+ resolve
1186
+ };
1187
+ }
1188
+ function waitForAbort(signal) {
1189
+ return new Promise((_, reject) => {
1190
+ if (signal?.aborted) {
1191
+ reject(signal.reason);
1192
+ return;
1193
+ }
1194
+ signal?.addEventListener("abort", () => reject(signal.reason), { once: true });
1195
+ });
1196
+ }
1197
+ test("getNodeInfo() times out while waiting for response headers", async () => {
1198
+ const closed = deferred();
1199
+ let fetches = 0;
1200
+ let closes = 0;
1201
+ let signal;
1202
+ const records = [];
1203
+ await configure({
1204
+ sinks: { buffer: (record) => records.push(record) },
1205
+ loggers: [{
1206
+ category: "fedify",
1207
+ sinks: ["buffer"],
1208
+ lowestLevel: "debug"
1209
+ }, {
1210
+ category: ["logtape", "meta"],
1211
+ sinks: []
1212
+ }],
1213
+ reset: true
1214
+ });
1215
+ try {
1216
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1217
+ direct: true,
1218
+ timeout: 30
1219
+ }, { openHop: async (url, hopSignal) => {
1220
+ signal = hopSignal;
1221
+ return {
1222
+ url: new URL(url),
1223
+ fetch(_input, init) {
1224
+ fetches++;
1225
+ assertEquals(init?.signal, hopSignal);
1226
+ return waitForAbort(init?.signal);
1227
+ },
1228
+ async close() {
1229
+ closes++;
1230
+ closed.resolve();
1231
+ }
1232
+ };
1233
+ } }), 1e3), void 0);
1234
+ await settleWithin(closed.promise, 1e3);
1235
+ assertEquals(fetches, 1);
1236
+ assertEquals(closes, 1);
1237
+ assertEquals(signal?.aborted, true);
1238
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1239
+ await new Promise((resolve) => setTimeout(resolve, 0));
1240
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1241
+ } finally {
1242
+ await reset();
1243
+ }
1244
+ });
1245
+ test("getNodeInfo() times out while a small response body stalls", async () => {
1246
+ const closed = deferred();
1247
+ let bodyCancelled = false;
1248
+ let signal;
1249
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1250
+ direct: true,
1251
+ timeout: 30
1252
+ }, { async openHop(url, hopSignal) {
1253
+ signal = hopSignal;
1254
+ return {
1255
+ url: new URL(url),
1256
+ async fetch(_input, init) {
1257
+ assertEquals(init?.signal, hopSignal);
1258
+ return new Response(new ReadableStream({
1259
+ start(controller) {
1260
+ controller.enqueue(new TextEncoder().encode("{\"software\":"));
1261
+ },
1262
+ cancel() {
1263
+ bodyCancelled = true;
1264
+ }
1265
+ }));
1266
+ },
1267
+ async close() {
1268
+ closed.resolve();
1269
+ }
1270
+ };
1271
+ } }), 1e3), void 0);
1272
+ await settleWithin(closed.promise, 1e3);
1273
+ assertEquals(signal?.aborted, true);
1274
+ assertEquals(bodyCancelled, true);
1275
+ });
1276
+ test({
1277
+ name: "getNodeInfo() aborts stalled HTTP responses",
1278
+ ignore: "navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers" || "Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted",
1279
+ async fn(t) {
1280
+ for (const stage of ["headers", "body"]) await t.step(stage, async () => {
1281
+ const disconnected = deferred();
1282
+ const server = createServer((request, response) => {
1283
+ response.on("close", () => disconnected.resolve());
1284
+ request.socket.on("close", () => disconnected.resolve());
1285
+ if (stage === "body") {
1286
+ response.writeHead(200, { "Content-Type": "application/json" });
1287
+ response.write("{\"software\":");
1288
+ }
1289
+ });
1290
+ try {
1291
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
1292
+ const address = server.address();
1293
+ if (address == null || typeof address === "string") throw new Error("Expected a TCP server address.");
1294
+ assertEquals(await settleWithin(getNodeInfoInternal(`http://127.0.0.1:${address.port}/nodeinfo`, {
1295
+ direct: true,
1296
+ timeout: 200
1297
+ }, { openHop: openDirectFetch }), 2e3).catch((error) => {
1298
+ throw new Error(`${stage} lookup did not finish`, { cause: error });
1299
+ }), void 0);
1300
+ await settleWithin(disconnected.promise, 2e3).catch((error) => {
1301
+ throw new Error(`${stage} connection did not close`, { cause: error });
1302
+ });
1303
+ } finally {
1304
+ server.closeAllConnections();
1305
+ await new Promise((resolve) => server.close(() => resolve()));
1306
+ }
1307
+ });
1308
+ }
1309
+ });
1310
+ test("getNodeInfo() shares one timeout across discovery and document", async () => {
1311
+ const documentRequested = deferred();
1312
+ const documentClosed = deferred();
1313
+ let discoverySignal;
1314
+ let documentSignal;
1315
+ const descriptor = JSON.stringify({ links: [{
1316
+ rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
1317
+ href: "https://example.com/nodeinfo/2.1"
1318
+ }] });
1319
+ const result = getNodeInfoInternal("https://example.com/", { timeout: 200 }, { async openHop(url) {
1320
+ const isDocument = url.endsWith("/nodeinfo/2.1");
1321
+ return {
1322
+ url: new URL(url),
1323
+ async fetch(_input, init) {
1324
+ if (isDocument) {
1325
+ documentSignal = init?.signal ?? void 0;
1326
+ documentRequested.resolve();
1327
+ return await waitForAbort(init?.signal);
1328
+ }
1329
+ discoverySignal = init?.signal ?? void 0;
1330
+ return new Response(descriptor);
1331
+ },
1332
+ async close() {
1333
+ if (isDocument) documentClosed.resolve();
1334
+ }
1335
+ };
1336
+ } });
1337
+ await settleWithin(documentRequested.promise, 1e3);
1338
+ assertStrictEquals(documentSignal, discoverySignal);
1339
+ assertEquals(await settleWithin(result, 1e3), void 0);
1340
+ await settleWithin(documentClosed.promise, 1e3);
1341
+ assertEquals(discoverySignal?.aborted, true);
1342
+ });
1343
+ test("getNodeInfo() honors caller cancellation without a timeout", async () => {
1344
+ const caller = new AbortController();
1345
+ const closed = deferred();
1346
+ let requestSignal;
1347
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1348
+ direct: true,
1349
+ timeout: null,
1350
+ signal: caller.signal
1351
+ }, { async openHop(url, signal) {
1352
+ requestSignal = signal;
1353
+ return {
1354
+ url: new URL(url),
1355
+ fetch(_input, init) {
1356
+ assertStrictEquals(init?.signal, signal);
1357
+ caller.abort(/* @__PURE__ */ new Error("Caller stopped waiting"));
1358
+ return waitForAbort(init?.signal);
1359
+ },
1360
+ async close() {
1361
+ closed.resolve();
1362
+ }
1363
+ };
1364
+ } }), 1e3), void 0);
1365
+ await settleWithin(closed.promise, 1e3);
1366
+ assertEquals(requestSignal?.aborted, true);
1367
+ });
1368
+ test("getNodeInfo() stops before fetching when caller already aborted", async () => {
1369
+ const caller = new AbortController();
1370
+ caller.abort();
1371
+ let opened = false;
1372
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1373
+ direct: true,
1374
+ signal: caller.signal
1375
+ }, { async openHop() {
1376
+ opened = true;
1377
+ throw new Error("Unexpected fetch");
1378
+ } }), void 0);
1379
+ assertEquals(opened, false);
1380
+ });
1381
+ test("getNodeInfo() closes a session opened just after its timeout", async () => {
1382
+ const closed = deferred();
1383
+ let fetches = 0;
1384
+ let closes = 0;
1385
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1386
+ direct: true,
1387
+ timeout: 25
1388
+ }, { async openHop(url) {
1389
+ await new Promise((resolve) => setTimeout(resolve, 55));
1390
+ return {
1391
+ url: new URL(url),
1392
+ async fetch() {
1393
+ fetches++;
1394
+ return Response.json({ software: {
1395
+ name: "x",
1396
+ version: "1"
1397
+ } });
1398
+ },
1399
+ async close() {
1400
+ closes++;
1401
+ closed.resolve();
1402
+ }
1403
+ };
1404
+ } }), 1e3), void 0);
1405
+ await settleWithin(closed.promise, 1e3);
1406
+ assertEquals(fetches, 0);
1407
+ assertEquals(closes, 1);
1408
+ });
1409
+ test("getNodeInfo() does not log a late DNS failure as another error", async () => {
1410
+ const records = [];
1411
+ const finished = deferred();
1412
+ await configure({
1413
+ sinks: { buffer: (record) => records.push(record) },
1414
+ loggers: [{
1415
+ category: "fedify",
1416
+ sinks: ["buffer"],
1417
+ lowestLevel: "debug"
1418
+ }, {
1419
+ category: ["logtape", "meta"],
1420
+ sinks: []
1421
+ }],
1422
+ reset: true
1423
+ });
1424
+ try {
1425
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1426
+ direct: true,
1427
+ timeout: 25
1428
+ }, { async openHop() {
1429
+ try {
1430
+ await new Promise((resolve) => setTimeout(resolve, 55));
1431
+ throw new UrlError("DNS lookup failed", { reason: "dns" });
1432
+ } finally {
1433
+ finished.resolve();
1434
+ }
1435
+ } }), 1e3), void 0);
1436
+ await settleWithin(finished.promise, 1e3);
1437
+ await new Promise((resolve) => setTimeout(resolve, 0));
1438
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1439
+ } finally {
1440
+ await reset();
1441
+ }
1442
+ });
1443
+ test("getNodeInfo() cancels a response returned after timeout", async () => {
1444
+ const closed = deferred();
1445
+ let bodyCancelled = false;
1446
+ let closes = 0;
1447
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1448
+ direct: true,
1449
+ timeout: 25
1450
+ }, { async openHop(url) {
1451
+ return {
1452
+ url: new URL(url),
1453
+ async fetch() {
1454
+ await new Promise((resolve) => setTimeout(resolve, 55));
1455
+ return new Response(new ReadableStream({ cancel() {
1456
+ bodyCancelled = true;
1457
+ } }));
1458
+ },
1459
+ async close() {
1460
+ closes++;
1461
+ closed.resolve();
1462
+ }
1463
+ };
1464
+ } }), 1e3), void 0);
1465
+ await settleWithin(closed.promise, 1e3);
1466
+ assertEquals(closes, 1);
1467
+ assertEquals(bodyCancelled, true);
1468
+ });
1469
+ test("getNodeInfo() validates its timeout", async () => {
1470
+ for (const timeout of [
1471
+ 0,
1472
+ -1,
1473
+ NaN,
1474
+ Infinity,
1475
+ 2147483648
1476
+ ]) await assertRejects(() => getNodeInfoInternal("https://example.com/", { timeout }), RangeError);
1477
+ });
1478
+ test("getNodeInfo() can disable its timeout", async () => {
1479
+ const value = { software: {
1480
+ name: "x",
1481
+ version: "1"
1482
+ } };
1483
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1484
+ direct: true,
1485
+ parse: "none",
1486
+ timeout: null
1487
+ }, { async openHop(url, signal) {
1488
+ assertEquals(signal, void 0);
1489
+ return {
1490
+ url: new URL(url),
1491
+ async fetch(_input, init) {
1492
+ assertEquals(init?.signal, void 0);
1493
+ return Response.json(value);
1494
+ },
1495
+ async close() {}
1496
+ };
1497
+ } }), value);
1498
+ });
1499
+ test("getNodeInfo() clears its timer after a successful fetch", async () => {
1500
+ let signal;
1501
+ const value = { software: {
1502
+ name: "x",
1503
+ version: "1"
1504
+ } };
1505
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1506
+ direct: true,
1507
+ parse: "none",
1508
+ timeout: 100
1509
+ }, { async openHop(url, hopSignal) {
1510
+ signal = hopSignal;
1511
+ return {
1512
+ url: new URL(url),
1513
+ async fetch() {
1514
+ return Response.json(value);
1515
+ },
1516
+ async close() {}
1517
+ };
1518
+ } }), value);
1519
+ await new Promise((resolve) => setTimeout(resolve, 120));
1520
+ assertEquals(signal?.aborted, false);
1521
+ });
1119
1522
  test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1120
1523
  const wellKnown = "https://example.com/.well-known/nodeinfo";
1121
1524
  const wellKnown2 = "https://example.com/.well-known/nodeinfo2";
@@ -1186,9 +1589,9 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1186
1589
  recorder.assertInvariants();
1187
1590
  });
1188
1591
  await t.step("too many redirections", async () => {
1189
- const recorder = recordHops(() => ({
1592
+ const recorder = recordHops((url) => ({
1190
1593
  status: 302,
1191
- headers: { Location: "/.well-known/nodeinfo" },
1594
+ headers: { Location: `?hop=${Number(url.searchParams.get("hop") ?? 0) + 1}` },
1192
1595
  body: "redirecting"
1193
1596
  }));
1194
1597
  assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
@@ -1196,6 +1599,31 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1196
1599
  assertEquals(recorder.events.filter((e) => e.startsWith("cancel ")).length, 5);
1197
1600
  recorder.assertInvariants();
1198
1601
  });
1602
+ await t.step("self-redirect cycle", async () => {
1603
+ const recorder = recordHops(() => ({
1604
+ status: 302,
1605
+ headers: { Location: "/.well-known/nodeinfo#another-fragment" },
1606
+ body: "redirecting"
1607
+ }));
1608
+ assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1609
+ assertEquals(recorder.events, [
1610
+ `open ${wellKnown}`,
1611
+ `fetch ${wellKnown} #1`,
1612
+ "cancel #1",
1613
+ `close ${wellKnown}`
1614
+ ]);
1615
+ recorder.assertInvariants();
1616
+ });
1617
+ await t.step("two-URL redirect cycle", async () => {
1618
+ const recorder = recordHops((url) => ({
1619
+ status: 302,
1620
+ headers: { Location: url.href === wellKnown ? "/.well-known/nodeinfo2" : "/.well-known/nodeinfo" },
1621
+ body: "redirecting"
1622
+ }));
1623
+ assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1624
+ assertEquals(recorder.events.filter((e) => e.startsWith("open ")), [`open ${wellKnown}`, `open ${wellKnown2}`]);
1625
+ recorder.assertInvariants();
1626
+ });
1199
1627
  await t.step("failed redirect body cancellation", async () => {
1200
1628
  const recorder = recordHops((url) => {
1201
1629
  switch (url.href) {
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-8Tu9kea0.mjs";
5
5
  import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
7
  import "../std__assert-DvMDRPes.mjs";
8
- import { D as handleNodeInfoJrd, E as handleNodeInfo, o as createFederation } from "../middleware-DblGj642.mjs";
8
+ import { D as handleNodeInfo, O as handleNodeInfoJrd, o as createFederation } from "../middleware-mRXKHq68.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/nodeinfo/handler.test.ts
11
11
  test("handleNodeInfo()", async () => {
@@ -1,6 +1,6 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_types = require("../types-hKCCjii0.cjs");
3
+ const require_types = require("../types-C8gac_AD.cjs");
4
4
  exports.getNodeInfo = require_types.getNodeInfo;
5
5
  exports.nodeInfoToJson = require_types.nodeInfoToJson;
6
6
  exports.parseNodeInfo = require_types.parseNodeInfo;
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-3InDZbba.cjs";
2
+ import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-DLHsPY7X.cjs";
3
3
  export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-3InDZbba.js";
2
+ import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-DLHsPY7X.js";
3
3
  export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -1,4 +1,4 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-DUjZb4i6.js";
3
+ import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-BbCbtwZp.js";
4
4
  export { getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -169,35 +169,66 @@ function getLogSafeJsonLdMetadata(jsonLd) {
169
169
  * failures leave the original document unchanged.
170
170
  */
171
171
  async function normalizeAttachmentArrays(jsonLd, contextLoader, options = {}) {
172
+ const preserveSecured = options.preserveSecuredDocuments ?? false;
172
173
  const normalized = wrapScalarAttachments(jsonLd, options.preserveNestedSecuredDocuments ?? false);
173
174
  if (normalized === jsonLd) return jsonLd;
174
175
  if (exceedsTraversalDepth(jsonLd)) {
175
176
  logger.debug("Skipping attachment array normalization because the JSON-LD document exceeds the safe traversal depth; leaving it unchanged.");
176
177
  return jsonLd;
177
178
  }
178
- if (hasKnownSafeContext(jsonLd)) return normalized;
179
- const loader = contextLoader ?? preloadedOnlyDocumentLoader;
179
+ const sourceLoader = contextLoader ?? preloadedOnlyDocumentLoader;
180
+ const pending = /* @__PURE__ */ new Map();
181
+ const loader = (url, options) => {
182
+ let result = pending.get(url);
183
+ if (result == null) {
184
+ result = sourceLoader(url, options);
185
+ pending.set(url, result);
186
+ }
187
+ return result;
188
+ };
180
189
  try {
181
- const [before, after] = await Promise.all([jsonld.canonize(jsonLd, {
190
+ if (preserveSecured) {
191
+ if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: loader }))) return jsonLd;
192
+ }
193
+ if (!preserveSecured && hasKnownSafeContext(jsonLd)) return normalized;
194
+ const [before, after] = await Promise.allSettled([jsonld.canonize(jsonLd, {
182
195
  format: "application/n-quads",
183
196
  documentLoader: loader
184
197
  }), jsonld.canonize(normalized, {
185
198
  format: "application/n-quads",
186
199
  documentLoader: loader
187
200
  })]);
188
- if (before === after) return normalized;
201
+ if (before.status === "rejected") throw before.reason;
202
+ if (after.status === "rejected") throw after.reason;
203
+ if (before.value === after.value) return normalized;
189
204
  logger.warn("Wrapping scalar attachment values in arrays would change the canonical form of the JSON-LD document; leaving it unchanged. This usually means the active JSON-LD context redefines the `attachment` term. Document: {id}; type: {type}; context: {context}.", getLogSafeJsonLdMetadata(jsonLd));
190
205
  } catch (error) {
191
206
  logger.debug("Failed to verify attachment array normalization equivalence via JSON-LD canonicalization; leaving the JSON-LD document unchanged.\n{error}", { error });
192
207
  }
193
208
  return jsonLd;
194
209
  }
210
+ function hasSecurityPredicate(value) {
211
+ if (Array.isArray(value)) return value.some(hasSecurityPredicate);
212
+ if (typeof value !== "object" || value == null) return false;
213
+ const record = value;
214
+ if (Object.hasOwn(record, "@value")) return false;
215
+ for (const [key, child] of Object.entries(record)) {
216
+ if (key === "https://w3id.org/security#proof" || key === "https://w3id.org/security#signature") return true;
217
+ if (hasSecurityPredicate(child)) return true;
218
+ }
219
+ return false;
220
+ }
195
221
  /**
196
222
  * Applies Fedify's internal JSON-LD wire-format interoperability workarounds
197
223
  * to locally generated outgoing activities before they are signed, enqueued,
198
224
  * or sent.
199
225
  */
200
226
  async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, options = {}) {
227
+ if (options.preserveSecuredDocuments) try {
228
+ if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: contextLoader ?? preloadedOnlyDocumentLoader }))) return jsonLd;
229
+ } catch {
230
+ return jsonLd;
231
+ }
201
232
  jsonLd = await normalizePublicAudience(jsonLd, contextLoader, options);
202
233
  return await normalizeAttachmentArrays(jsonLd, contextLoader, options);
203
234
  }
@@ -2,10 +2,10 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { d as isPortableUri, l as isPortableId, n as getCanonicalPortableId, p as isSamePublicKey$1, s as isCompatibleKeyId } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { n as version, t as name } from "./deno-ksnVeCA7.mjs";
5
+ import { n as version, t as name } from "./deno-BKSRi6w3.mjs";
6
6
  import { i as parseKeyOwnerEvidence, r as getVerifiedKeyOwnerEvidence } from "./key-owner-evidence-APB6NpSk.mjs";
7
- import { E as verifyKeyOwnership, b as fetchActorDocument, y as exportJwk } from "./ld-DJZrjNuN.mjs";
8
- import { n as resolvePortableActorKey, t as fetchPortableGatewayKey } from "./portable-key-DXGepvtD.mjs";
7
+ import { O as verifyKeyOwnership, S as fetchActorDocument, k as getDefaultPortableObjectVerifier, x as exportJwk } from "./ld-BGnZDnia.mjs";
8
+ import { n as resolvePortableActorKey, t as fetchPortableGatewayKey } from "./portable-key-CyVJpWWJ.mjs";
9
9
  import { getLogger } from "@logtape/logtape";
10
10
  import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
11
11
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
@@ -198,7 +198,7 @@ async function getKeyOwner(keyId, options) {
198
198
  }
199
199
  if (object instanceof CryptographicKey) {
200
200
  if (object.id != null && object.id.href !== keyId.href) return null;
201
- return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
201
+ return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }, { verifyPortableObject: getDefaultPortableObjectVerifier(object) }) : object, fetchOptions);
202
202
  }
203
203
  if (!isActor(object)) return null;
204
204
  if (object.id == null || isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
@@ -1,5 +1,6 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
- const require_http = require("./http-CeVcKQMZ.cjs");
2
+ const require_portable_verifier = require("./portable-verifier-DiLU8c9T.cjs");
3
+ const require_http = require("./http-Tj9eQ_rd.cjs");
3
4
  let _logtape_logtape = require("@logtape/logtape");
4
5
  let _fedify_vocab = require("@fedify/vocab");
5
6
  let _opentelemetry_api = require("@opentelemetry/api");
@@ -193,7 +194,7 @@ async function getKeyOwner(keyId, options) {
193
194
  }
194
195
  if (object instanceof _fedify_vocab.CryptographicKey) {
195
196
  if (object.id != null && object.id.href !== keyId.href) return null;
196
- return await require_http.verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
197
+ return await require_http.verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(object) }) : object, fetchOptions);
197
198
  }
198
199
  if (!(0, _fedify_vocab.isActor)(object)) return null;
199
200
  if (object.id == null || require_http.isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
@@ -1,8 +1,8 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-ksnVeCA7.mjs";
5
- import { c as verifyPortableObjectProof, u as verifyPortableObjectProofWithRoot } from "./proof-DW0FK6Cp.mjs";
4
+ import { n as version, t as name } from "./deno-BKSRi6w3.mjs";
5
+ import { c as verifyPortableObjectProof, u as verifyPortableObjectProofWithRoot } from "./proof-C4pwAF2k.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { CollectionPage, Object as Object$1, isActor } from "@fedify/vocab";
8
8
  import { trace } from "@opentelemetry/api";
@@ -1,6 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { At as isPortableUri, B as fetchActorDocument, Dt as isCompatibleKeyId, J as getVerifiedKeyOwnerEvidence, K as verifyKeyOwnership, Mt as isSamePublicKey$1, Nt as name, Ot as isPortableId, Pt as version, St as getCanonicalPortableId, Y as parseKeyOwnerEvidence, b as verifyPortableObjectProofWithRoot, l as fetchPortableGatewayKey, u as resolvePortableActorKey, v as verifyPortableObjectProof, z as exportJwk } from "./http-rH230xCD.js";
3
+ import { t as getDefaultPortableObjectVerifier } from "./portable-verifier-CPA86vIP.js";
4
+ import { At as isPortableId, B as fetchActorDocument, Ft as name, It as version, J as getVerifiedKeyOwnerEvidence, K as verifyKeyOwnership, Mt as isPortableUri, Pt as isSamePublicKey$1, Y as parseKeyOwnerEvidence, b as verifyPortableObjectProofWithRoot, kt as isCompatibleKeyId, l as fetchPortableGatewayKey, u as resolvePortableActorKey, v as verifyPortableObjectProof, wt as getCanonicalPortableId, z as exportJwk } from "./http-BwgldAIk.js";
4
5
  import { getLogger } from "@logtape/logtape";
5
6
  import { CollectionPage, CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
6
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
@@ -194,7 +195,7 @@ async function getKeyOwner(keyId, options) {
194
195
  }
195
196
  if (object instanceof CryptographicKey) {
196
197
  if (object.id != null && object.id.href !== keyId.href) return null;
197
- return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
198
+ return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }, { verifyPortableObject: getDefaultPortableObjectVerifier(object) }) : object, fetchOptions);
198
199
  }
199
200
  if (!isActor(object)) return null;
200
201
  if (object.id == null || isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
@@ -2,7 +2,7 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { a as getRawCanonicalPortableId, c as isPortableActorDocument, d as isPortableUri, n as getCanonicalPortableId, p as isSamePublicKey } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { u as verifyPortableObjectProofWithRoot } from "./proof-DW0FK6Cp.mjs";
5
+ import { u as verifyPortableObjectProofWithRoot } from "./proof-C4pwAF2k.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { CryptographicKey, Multikey, Object as Object$1 } from "@fedify/vocab";
8
8
  import { FetchError, formatIri, getDocumentLoader, isGatewayUrl, parseIri, toCompatibleEf61Id } from "@fedify/vocab-runtime";