@fedify/fedify 2.5.0-dev.2664 → 2.5.0-dev.2710

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 (266) hide show
  1. package/dist/compat/mod.d.cts +1 -1
  2. package/dist/compat/mod.d.ts +1 -1
  3. package/dist/{context-xrqq4Hrq.d.ts → context-CuLvR1Os.d.ts} +2 -2
  4. package/dist/{context-C1NqcIct.d.cts → context-apq0IBg2.d.cts} +2 -2
  5. package/dist/federation/mod.cjs +1 -1
  6. package/dist/federation/mod.d.cts +3 -3
  7. package/dist/federation/mod.d.ts +3 -3
  8. package/dist/federation/mod.js +1 -1
  9. package/dist/{federation-FbwcnRHg.cjs → federation-JvzYDx0P.cjs} +5 -5
  10. package/dist/{http-DbvOPsFZ.cjs → http-BG5cDmTS.cjs} +1 -1
  11. package/dist/{http-CWn0K5jD.js → http-MUf125Jc.js} +1 -1
  12. package/dist/{key-dwwAg5bA.d.ts → key-BZw-YiK5.d.ts} +2 -2
  13. package/dist/{key-DlHT4R6k.d.cts → key-D5fbQkKM.d.cts} +2 -2
  14. package/dist/{kv-cache-B-fOrhb-.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  15. package/dist/{kv-cache-BC837EqC.js → kv-cache-CbWc1BZA.js} +1 -1
  16. package/dist/{ld-CWVpo_NM.d.cts → ld-DEi9ERHf.d.cts} +1 -1
  17. package/dist/{ld-o4LnhCYY.d.ts → ld-DlC78ioJ.d.ts} +1 -1
  18. package/dist/{middleware-n2UrG62B.js → middleware-DzzdJ7Wz.js} +5 -5
  19. package/dist/{mod-D22ZsiKi.d.ts → mod-BJRtsw7l.d.ts} +1 -1
  20. package/dist/{mod-C1nT74IG.d.cts → mod-BamwZjJx.d.cts} +1 -1
  21. package/dist/{mod-DO0epJGH.d.ts → mod-BkTi19dI.d.ts} +1 -1
  22. package/dist/{mod-CQC9xlLZ.d.ts → mod-CMtF0VVy.d.ts} +1 -1
  23. package/dist/{mod-YvA4Rk8J.d.cts → mod-D2Z9MiCm.d.cts} +1 -1
  24. package/dist/{mod-TwiQgEf3.d.cts → mod-DB2NOzQF.d.cts} +1 -1
  25. package/dist/mod.cjs +4 -4
  26. package/dist/mod.d.cts +6 -6
  27. package/dist/mod.d.ts +6 -6
  28. package/dist/mod.js +4 -4
  29. package/dist/{portable-collection-DQhIkX5a.js → portable-collection-CAer9RWN.js} +1 -1
  30. package/dist/{portable-collection-DseoiPPj.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  31. package/dist/sig/mod.cjs +2 -2
  32. package/dist/sig/mod.d.cts +3 -3
  33. package/dist/sig/mod.d.ts +3 -3
  34. package/dist/sig/mod.js +2 -2
  35. package/dist/utils/mod.cjs +1 -1
  36. package/dist/utils/mod.d.cts +1 -1
  37. package/dist/utils/mod.d.ts +1 -1
  38. package/dist/utils/mod.js +1 -1
  39. package/package.json +22 -9
  40. package/skills/fedify/SKILL.md +10 -0
  41. package/dist/accept-CPVqki78.mjs +0 -145
  42. package/dist/activity-listener-CELFAodc.mjs +0 -44
  43. package/dist/assert-D1Eafmd_.mjs +0 -23
  44. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  45. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  46. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  47. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  48. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  49. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  50. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  51. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  52. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  53. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  54. package/dist/audience-CHQ-FlLD.mjs +0 -95
  55. package/dist/builder-CGJ-NXcZ.mjs +0 -911
  56. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  57. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  58. package/dist/client-5SIFzW3q.mjs +0 -441
  59. package/dist/codec-C6rTrpIp.mjs +0 -147
  60. package/dist/collection-CnnP1UAv.mjs +0 -44
  61. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  62. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  63. package/dist/compat/public-audience.test.d.mts +0 -2
  64. package/dist/compat/public-audience.test.mjs +0 -187
  65. package/dist/compat/secured-document.test.d.mts +0 -2
  66. package/dist/compat/secured-document.test.mjs +0 -58
  67. package/dist/compat/transformers.test.d.mts +0 -2
  68. package/dist/compat/transformers.test.mjs +0 -62
  69. package/dist/compound-proof-CnzwOddk.mjs +0 -1019
  70. package/dist/context-LgGFFSz7.mjs +0 -146
  71. package/dist/deno-eoFpPk7W.mjs +0 -8
  72. package/dist/dist-_geWsuaI.mjs +0 -189
  73. package/dist/docloader-DwkipyL1.mjs +0 -136
  74. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  75. package/dist/exporter-DVG68ozH.mjs +0 -263
  76. package/dist/federation/audience.test.d.mts +0 -2
  77. package/dist/federation/audience.test.mjs +0 -130
  78. package/dist/federation/builder.test.d.mts +0 -2
  79. package/dist/federation/builder.test.mjs +0 -396
  80. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  81. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  82. package/dist/federation/collection.test.d.mts +0 -2
  83. package/dist/federation/collection.test.mjs +0 -21
  84. package/dist/federation/compound-fanout.test.d.mts +0 -2
  85. package/dist/federation/compound-fanout.test.mjs +0 -231
  86. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  87. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  88. package/dist/federation/handler.test.d.mts +0 -2
  89. package/dist/federation/handler.test.mjs +0 -5445
  90. package/dist/federation/hashlink-media.test.d.mts +0 -2
  91. package/dist/federation/hashlink-media.test.mjs +0 -422
  92. package/dist/federation/idempotency.test.d.mts +0 -2
  93. package/dist/federation/idempotency.test.mjs +0 -207
  94. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  95. package/dist/federation/inbox-actorless.test.mjs +0 -522
  96. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  97. package/dist/federation/inbox-authentication.test.mjs +0 -220
  98. package/dist/federation/inbox-report.test.d.mts +0 -2
  99. package/dist/federation/inbox-report.test.mjs +0 -719
  100. package/dist/federation/inbox-view.test.d.mts +0 -2
  101. package/dist/federation/inbox-view.test.mjs +0 -369
  102. package/dist/federation/inbox.test.d.mts +0 -2
  103. package/dist/federation/inbox.test.mjs +0 -139
  104. package/dist/federation/keycache.test.d.mts +0 -2
  105. package/dist/federation/keycache.test.mjs +0 -337
  106. package/dist/federation/kv.test.d.mts +0 -2
  107. package/dist/federation/kv.test.mjs +0 -88
  108. package/dist/federation/metrics.test.d.mts +0 -2
  109. package/dist/federation/metrics.test.mjs +0 -634
  110. package/dist/federation/middleware.test.d.mts +0 -2
  111. package/dist/federation/middleware.test.mjs +0 -9314
  112. package/dist/federation/mq.test.d.mts +0 -2
  113. package/dist/federation/mq.test.mjs +0 -591
  114. package/dist/federation/negotiation.test.d.mts +0 -2
  115. package/dist/federation/negotiation.test.mjs +0 -18
  116. package/dist/federation/outbound-body.test.d.mts +0 -2
  117. package/dist/federation/outbound-body.test.mjs +0 -149
  118. package/dist/federation/outbound-capture.test.d.mts +0 -2
  119. package/dist/federation/outbound-capture.test.mjs +0 -394
  120. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  121. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  122. package/dist/federation/outbound-document.test.d.mts +0 -2
  123. package/dist/federation/outbound-document.test.mjs +0 -171
  124. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  125. package/dist/federation/outbound-provenance.test.mjs +0 -543
  126. package/dist/federation/outbound-report.test.d.mts +0 -2
  127. package/dist/federation/outbound-report.test.mjs +0 -5475
  128. package/dist/federation/outbound-workers.test.d.mts +0 -2
  129. package/dist/federation/outbound-workers.test.mjs +0 -64
  130. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  131. package/dist/federation/outbound-workflow.test.mjs +0 -154
  132. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  133. package/dist/federation/outgoing-proof.test.mjs +0 -933
  134. package/dist/federation/portable-actor.test.d.mts +0 -2
  135. package/dist/federation/portable-actor.test.mjs +0 -496
  136. package/dist/federation/portable-chain.test.d.mts +0 -2
  137. package/dist/federation/portable-chain.test.mjs +0 -370
  138. package/dist/federation/portable-collection.test.d.mts +0 -2
  139. package/dist/federation/portable-collection.test.mjs +0 -832
  140. package/dist/federation/portable-delivery.test.d.mts +0 -2
  141. package/dist/federation/portable-delivery.test.mjs +0 -845
  142. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  143. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  144. package/dist/federation/portable-inbox.test.d.mts +0 -2
  145. package/dist/federation/portable-inbox.test.mjs +0 -1960
  146. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  147. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  148. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  149. package/dist/federation/portable-route-activity.test.mjs +0 -259
  150. package/dist/federation/portable.test.d.mts +0 -2
  151. package/dist/federation/portable.test.mjs +0 -1072
  152. package/dist/federation/retry.test.d.mts +0 -2
  153. package/dist/federation/retry.test.mjs +0 -42
  154. package/dist/federation/router.test.d.mts +0 -2
  155. package/dist/federation/router.test.mjs +0 -123
  156. package/dist/federation/send.test.d.mts +0 -2
  157. package/dist/federation/send.test.mjs +0 -1421
  158. package/dist/federation/tasks/codec.test.d.mts +0 -2
  159. package/dist/federation/tasks/codec.test.mjs +0 -302
  160. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  161. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  162. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  163. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  164. package/dist/federation/temporal.test.d.mts +0 -2
  165. package/dist/federation/temporal.test.mjs +0 -71
  166. package/dist/federation/webfinger.test.d.mts +0 -2
  167. package/dist/federation/webfinger.test.mjs +0 -944
  168. package/dist/http-l1zKGCll.mjs +0 -1449
  169. package/dist/inbox-CWX3EBTO.mjs +0 -399
  170. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  171. package/dist/inbox-view-DkPCF71K.mjs +0 -385
  172. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  173. package/dist/keycache-N2opu4-3.mjs +0 -221
  174. package/dist/keys-DIJNHW-Y.mjs +0 -120
  175. package/dist/kv-DBRWVx3Q.mjs +0 -104
  176. package/dist/kv-DCHkaJ9-.mjs +0 -92
  177. package/dist/kv-cache-8eJh4Xum.mjs +0 -121
  178. package/dist/ld-Cdt8qD-r.mjs +0 -1752
  179. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  180. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  181. package/dist/metrics-BnfvSPj9.mjs +0 -818
  182. package/dist/middleware-CwnXJze2.mjs +0 -5
  183. package/dist/middleware-D_W_LdJN.mjs +0 -9971
  184. package/dist/mq-eF96QxUT.mjs +0 -288
  185. package/dist/negotiation-BAKO9nih.mjs +0 -96
  186. package/dist/nodeinfo/client.test.d.mts +0 -2
  187. package/dist/nodeinfo/client.test.mjs +0 -1364
  188. package/dist/nodeinfo/handler.test.d.mts +0 -2
  189. package/dist/nodeinfo/handler.test.mjs +0 -94
  190. package/dist/nodeinfo/types.test.d.mts +0 -2
  191. package/dist/nodeinfo/types.test.mjs +0 -192
  192. package/dist/otel/exporter.test.d.mts +0 -2
  193. package/dist/otel/exporter.test.mjs +0 -887
  194. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  195. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  196. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  197. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  198. package/dist/owner-DukEQnv3.mjs +0 -267
  199. package/dist/portable-collection-OHaqa11n.mjs +0 -418
  200. package/dist/portable-key-BkOLJxVz.mjs +0 -549
  201. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  202. package/dist/proof-Y7omSVvc.mjs +0 -1420
  203. package/dist/public-audience--klBIOk1.mjs +0 -197
  204. package/dist/retry-zX5xw5e0.mjs +0 -34
  205. package/dist/router-u5O5KCQr.mjs +0 -156
  206. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  207. package/dist/send-ccQynabr.mjs +0 -710
  208. package/dist/sig/accept.test.d.mts +0 -2
  209. package/dist/sig/accept.test.mjs +0 -416
  210. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  211. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  212. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  213. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  214. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  215. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  216. package/dist/sig/compound-proof.test.d.mts +0 -2
  217. package/dist/sig/compound-proof.test.mjs +0 -411
  218. package/dist/sig/http.test.d.mts +0 -2
  219. package/dist/sig/http.test.mjs +0 -3328
  220. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  221. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  222. package/dist/sig/key.test.d.mts +0 -2
  223. package/dist/sig/key.test.mjs +0 -1250
  224. package/dist/sig/ld.test.d.mts +0 -2
  225. package/dist/sig/ld.test.mjs +0 -1044
  226. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  227. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  228. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  229. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  230. package/dist/sig/owner.test.d.mts +0 -2
  231. package/dist/sig/owner.test.mjs +0 -202
  232. package/dist/sig/portable-collection.test.d.mts +0 -2
  233. package/dist/sig/portable-collection.test.mjs +0 -697
  234. package/dist/sig/portable-interop.test.d.mts +0 -2
  235. package/dist/sig/portable-interop.test.mjs +0 -156
  236. package/dist/sig/portable-key-id.test.d.mts +0 -2
  237. package/dist/sig/portable-key-id.test.mjs +0 -67
  238. package/dist/sig/portable-key.test.d.mts +0 -2
  239. package/dist/sig/portable-key.test.mjs +0 -1438
  240. package/dist/sig/proof.test.d.mts +0 -2
  241. package/dist/sig/proof.test.mjs +0 -2638
  242. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  243. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  244. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  245. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  246. package/dist/sig/verification.test.d.mts +0 -2
  247. package/dist/sig/verification.test.mjs +0 -310
  248. package/dist/std__assert-DvMDRPes.mjs +0 -8
  249. package/dist/tasks-BCUmQbbz.mjs +0 -77
  250. package/dist/temporal-f_K4lAVR.mjs +0 -95
  251. package/dist/testing/context.test.d.mts +0 -2
  252. package/dist/testing/context.test.mjs +0 -19
  253. package/dist/testing/kv.test.d.mts +0 -2
  254. package/dist/testing/kv.test.mjs +0 -101
  255. package/dist/testing/mod.d.mts +0 -6099
  256. package/dist/testing/mod.mjs +0 -9
  257. package/dist/testing-vrnD5Uaa.mjs +0 -8
  258. package/dist/types-DE_LV1JB.mjs +0 -46
  259. package/dist/utils/docloader.test.d.mts +0 -2
  260. package/dist/utils/docloader.test.mjs +0 -1076
  261. package/dist/utils/kv-cache.test.d.mts +0 -2
  262. package/dist/utils/kv-cache.test.mjs +0 -261
  263. package/dist/verification-C3954hQh.mjs +0 -5
  264. package/dist/verification-Dpfcw8ml.mjs +0 -105
  265. package/dist/vocab/cjs.test.d.mts +0 -2
  266. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,399 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as getAuthenticationOrigin } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { o as serializeAuthentication, r as getEffectivePrincipals } from "./inbox-authentication-CgonVRkg.mjs";
6
- import { n as version, t as name } from "./deno-eoFpPk7W.mjs";
7
- import { g as recordInboxActivity, n as getDurationMs, r as getFederationMetrics } from "./metrics-BnfvSPj9.mjs";
8
- import { getLogger } from "@logtape/logtape";
9
- import { getTypeId } from "@fedify/vocab";
10
- import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
11
- //#region src/federation/outbound-provenance.ts
12
- const outboundProvenance = Symbol("outboundProvenance");
13
- const emptyProvenance = Object.freeze({});
14
- function getOutboundProvenance(context) {
15
- return context[outboundProvenance] ?? emptyProvenance;
16
- }
17
- function snapshotLocalContext(context) {
18
- return Object.freeze({
19
- origin: context.origin,
20
- host: context.host,
21
- hostname: context.hostname,
22
- canonicalOrigin: context.canonicalOrigin
23
- });
24
- }
25
- function createInboxRequestSource(request, requestId, canonicalOrigin) {
26
- const url = new URL(request.url);
27
- return Object.freeze({
28
- inboxRequestId: crypto.randomUUID(),
29
- requestId,
30
- context: snapshotLocalContext({
31
- origin: url.origin,
32
- host: url.host,
33
- hostname: url.hostname,
34
- canonicalOrigin: canonicalOrigin ?? url.origin
35
- })
36
- });
37
- }
38
- /** The same exact-string budget applies to public input and queued metadata. */
39
- function validateDispatchId(value) {
40
- if (value === void 0) return;
41
- if (typeof value !== "string") throw new TypeError("dispatchId must be a string.");
42
- if (value.length > 1024 || new TextEncoder().encode(value).byteLength > 1024) throw new RangeError("dispatchId must not exceed 1,024 UTF-8 bytes.");
43
- }
44
- /** A new public invocation keeps its HTTP source, with its own dispatch ID. */
45
- function invocationProvenance(context, dispatchId) {
46
- validateDispatchId(dispatchId);
47
- const { dispatchId: _previous, ...source } = getOutboundProvenance(context);
48
- return Object.freeze({
49
- ...source,
50
- ...dispatchId === void 0 ? {} : { dispatchId }
51
- });
52
- }
53
- /** Restore only explicit source facts; never infer them from queue/trace IDs. */
54
- function restoreProvenance(value) {
55
- if (value === void 0) return emptyProvenance;
56
- const record = (v) => v != null && typeof v === "object" && !Array.isArray(v);
57
- const invalid = () => /* @__PURE__ */ new TypeError("Invalid provenance in queue metadata.");
58
- if (!record(value)) throw invalid();
59
- validateDispatchId(value.dispatchId);
60
- if (value.originatingRequestId !== void 0 && typeof value.originatingRequestId !== "string") throw invalid();
61
- let inboxRequest;
62
- if (value.inboxRequest !== void 0) {
63
- const source = value.inboxRequest;
64
- if (!record(source) || typeof source.inboxRequestId !== "string" || source.inboxRequestId.length < 1 || typeof source.requestId !== "string" || !record(source.context)) throw invalid();
65
- const facts = source.context;
66
- if (typeof facts.origin !== "string" || typeof facts.host !== "string" || typeof facts.hostname !== "string" || typeof facts.canonicalOrigin !== "string") throw invalid();
67
- inboxRequest = Object.freeze({
68
- inboxRequestId: source.inboxRequestId,
69
- requestId: source.requestId,
70
- context: Object.freeze({
71
- origin: facts.origin,
72
- host: facts.host,
73
- hostname: facts.hostname,
74
- canonicalOrigin: facts.canonicalOrigin
75
- })
76
- });
77
- }
78
- return Object.freeze({
79
- ...value.dispatchId === void 0 ? {} : { dispatchId: value.dispatchId },
80
- ...inboxRequest == null ? {} : { inboxRequest },
81
- ...value.originatingRequestId === void 0 ? {} : { originatingRequestId: value.originatingRequestId }
82
- });
83
- }
84
- /** Omit absent provenance on legacy and independent producers. */
85
- function serializeProvenance(value) {
86
- const provenance = restoreProvenance(value);
87
- return provenance.dispatchId === void 0 && provenance.inboxRequest == null && provenance.originatingRequestId == null ? {} : { provenance };
88
- }
89
- function sourceLogContext(source) {
90
- return {
91
- dispatchId: source.dispatchId,
92
- sourceInboxRequestId: source.inboxRequest?.inboxRequestId,
93
- sourceRequestId: source.inboxRequest?.requestId ?? source.originatingRequestId
94
- };
95
- }
96
- //#endregion
97
- //#region src/federation/inbox.ts
98
- /**
99
- * Checks whether an activity's ID and all of its actor IDs have the same
100
- * [FEP-fe34] origin. Activities without an ID have no origin to authenticate.
101
- *
102
- * Origins are compared by `getAuthenticationOrigin()`, so a portable activity
103
- * and its portable actors, including compatible identifiers on any gateway,
104
- * are compared by their DIDs. An ID that has no supported origin, such as an
105
- * opaque URN, never matches.
106
- *
107
- * The caller is responsible for rejecting a missing primary actor ID before
108
- * relying on this check.
109
- *
110
- * [FEP-fe34]: https://w3id.org/fep/fe34
111
- * @internal
112
- */
113
- function actorsHaveSameOrigin(activity) {
114
- if (activity.id == null) return true;
115
- const origin = getAuthenticationOrigin(activity.id);
116
- return origin != null && activity.actorIds.every((actor) => getAuthenticationOrigin(actor) === origin);
117
- }
118
- /**
119
- * The headroom that the size check of a queued inbox message leaves for the
120
- * fields that grow when Fedify retries the message, e.g., its attempt count.
121
- */
122
- const QUEUED_MESSAGE_HEADROOM = 64;
123
- /**
124
- * Computes the idempotency key of an incoming activity.
125
- * @returns The key, or `null` if the activity is not deduplicated.
126
- * @internal
127
- */
128
- async function getInboxIdempotencyKey(strategy, inboxContext, activity, origin, recipient, prefix) {
129
- if (activity.id == null) return null;
130
- strategy ??= "per-inbox";
131
- let keyString;
132
- if (typeof strategy === "function") keyString = await strategy(inboxContext(), activity);
133
- else switch (strategy) {
134
- case "global":
135
- keyString = activity.id.href;
136
- break;
137
- case "per-origin":
138
- keyString = `${origin}\n${activity.id.href}`;
139
- break;
140
- case "per-inbox":
141
- keyString = `${origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
142
- break;
143
- default: keyString = `${origin}\n${activity.id.href}`;
144
- }
145
- return keyString == null ? null : [...prefix, keyString];
146
- }
147
- /**
148
- * Checks whether an incoming activity has already been processed, by its
149
- * idempotency key, or by the key that queue workers of older versions of
150
- * Fedify recorded.
151
- * @internal
152
- */
153
- async function isInboxActivityProcessed(kv, cacheKey, activity, origin, prefix) {
154
- if (cacheKey == null) return false;
155
- if (await kv.get(cacheKey) === true) return true;
156
- if (activity.id == null) return false;
157
- return await kv.get([
158
- ...prefix,
159
- origin,
160
- activity.id.href
161
- ]) === true;
162
- }
163
- /**
164
- * The bytes added to the UTF-8 JSON length of a message for each of its JSON
165
- * values, to bound the size of serialization formats other than JSON, such
166
- * as the structured serialization of Deno KV, which spends more bytes than
167
- * JSON on type tags and lengths of small values, e.g., empty arrays, and up
168
- * to nine bytes on a fractional number that JSON writes in three.
169
- */
170
- const PER_VALUE_SERIALIZATION_OVERHEAD = 8;
171
- /**
172
- * Estimates, conservatively, how large a queued message is once a queue
173
- * backend serializes it: the UTF-8 length of its JSON serialization, plus
174
- * a fixed overhead for each JSON value in it, plus the bytes that encoding
175
- * strings beyond Latin-1 as UTF-16 adds.
176
- * @internal
177
- */
178
- function estimateQueuedMessageSize(message) {
179
- const encoder = new TextEncoder();
180
- let values = 0;
181
- let stringExpansion = 0;
182
- const countString = (value) => {
183
- values++;
184
- if (!/[\u0100-\uffff]/.test(value)) return;
185
- const expansion = value.length * 2 - encoder.encode(value).byteLength;
186
- if (expansion > 0) stringExpansion += expansion;
187
- };
188
- const count = (value) => {
189
- if (typeof value === "string") {
190
- countString(value);
191
- return;
192
- }
193
- values++;
194
- if (Array.isArray(value)) for (const item of value) count(item);
195
- else if (value != null && typeof value === "object") for (const [key, item] of Object.entries(value)) {
196
- if (item === void 0) continue;
197
- countString(key);
198
- count(item);
199
- }
200
- };
201
- count(message);
202
- return encoder.encode(JSON.stringify(message)).byteLength + stringExpansion + values * PER_VALUE_SERIALIZATION_OVERHEAD;
203
- }
204
- /**
205
- * Checks whether an activity that declares no actor is authenticated: at
206
- * least one principal must be authenticated for it, and its ID, if any, must
207
- * have the same [FEP-fe34] origin as one of those principals.
208
- *
209
- * [FEP-fe34]: https://w3id.org/fep/fe34
210
- * @returns `"ok"` if it is authenticated, or why it is not.
211
- * @internal
212
- */
213
- function checkActorlessActivity(activity, authentication) {
214
- const principals = getEffectivePrincipals(authentication);
215
- if (principals.length < 1) return {
216
- status: "noAuthenticatedPrincipal",
217
- principals
218
- };
219
- if (activity.id == null) return {
220
- status: "ok",
221
- principals
222
- };
223
- const origin = getAuthenticationOrigin(activity.id);
224
- if (origin == null || !principals.some((principal) => getAuthenticationOrigin(principal.id) === origin)) return {
225
- status: "activityOriginMismatch",
226
- principals
227
- };
228
- return {
229
- status: "ok",
230
- principals
231
- };
232
- }
233
- /**
234
- * Same as {@link checkActorlessActivity}, but returns a boolean.
235
- * @internal
236
- */
237
- function isActorlessActivityAuthenticated(activity, authentication) {
238
- return checkActorlessActivity(activity, authentication).status === "ok";
239
- }
240
- async function routeActivity({ context: ctx, json, originalJson, normalizedActivity, ldSignatureVerified, authentication, verifiedView, replayable, actorless, activity, recipient, inboxListeners, inboxContextFactory, listenerInboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, meterProvider, tracerProvider, idempotencyStrategy }) {
241
- const logger = getLogger([
242
- "fedify",
243
- "federation",
244
- "inbox"
245
- ]);
246
- if (activity.actorId == null && !actorless) {
247
- logger.error("Missing actor.", { activity: json });
248
- span.setStatus({
249
- code: SpanStatusCode.ERROR,
250
- message: "Missing actor."
251
- });
252
- recordInboxActivity(meterProvider, "rejected", getTypeId(activity).href);
253
- return "missingActor";
254
- }
255
- const contextMetadata = { authentication };
256
- const cacheKey = await getInboxIdempotencyKey(idempotencyStrategy, () => inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href, contextMetadata), activity, ctx.origin, recipient, kvPrefixes.activityIdempotence);
257
- if (await isInboxActivityProcessed(kv, cacheKey, activity, ctx.origin, kvPrefixes.activityIdempotence)) {
258
- logger.debug("Activity {activityId} has already been processed.", {
259
- activityId: activity.id?.href,
260
- activity: json,
261
- recipient
262
- });
263
- span.setStatus({
264
- code: SpanStatusCode.UNSET,
265
- message: `Activity ${activity.id?.href} has already been processed.`
266
- });
267
- recordInboxActivity(meterProvider, "rejected", getTypeId(activity).href);
268
- return "alreadyProcessed";
269
- }
270
- if (activity.actorId != null) span.setAttribute("activitypub.actor.id", activity.actorId.href);
271
- let message;
272
- if (queue != null) {
273
- const carrier = {};
274
- propagation.inject(context.active(), carrier);
275
- message = {
276
- type: "inbox",
277
- ...serializeProvenance(getOutboundProvenance(ctx)),
278
- id: crypto.randomUUID(),
279
- baseUrl: ctx.origin,
280
- activity: originalJson ?? json,
281
- ...normalizedActivity == null ? {} : { normalizedActivity },
282
- ...ldSignatureVerified == null ? {} : { ldSignatureVerified },
283
- ...verifiedView == null ? {} : { verifiedView },
284
- ...authentication == null ? {} : { authentication: serializeAuthentication(authentication) },
285
- identifier: recipient,
286
- attempt: 0,
287
- started: (/* @__PURE__ */ new Date()).toISOString(),
288
- traceContext: carrier
289
- };
290
- const maxMessageSize = queue.maxMessageSize;
291
- if (replayable === false) {
292
- logger.warn("The incoming activity {activityId} uses a JSON-LD context that cannot be kept for the queue; processing it immediately instead.", {
293
- activityId: activity.id?.href,
294
- recipient
295
- });
296
- message = void 0;
297
- } else if (maxMessageSize != null && estimateQueuedMessageSize(message) > maxMessageSize - QUEUED_MESSAGE_HEADROOM) {
298
- logger.warn("The incoming activity {activityId} is too large to enqueue; processing it immediately instead.", {
299
- activityId: activity.id?.href,
300
- recipient,
301
- maxMessageSize
302
- });
303
- message = void 0;
304
- }
305
- }
306
- if (queue != null && message != null) {
307
- try {
308
- await queue.enqueue(message);
309
- } catch (error) {
310
- logger.error("Failed to enqueue the incoming activity {activityId}:\n{error}", {
311
- error,
312
- activityId: activity.id?.href,
313
- activity: json,
314
- recipient
315
- });
316
- span.setStatus({
317
- code: SpanStatusCode.ERROR,
318
- message: `Failed to enqueue the incoming activity ${activity.id?.href}.`
319
- });
320
- throw error;
321
- }
322
- getFederationMetrics(meterProvider).recordQueueTaskEnqueued({
323
- role: "inbox",
324
- queue,
325
- activityType: getTypeId(activity).href
326
- }, 0);
327
- recordInboxActivity(meterProvider, "queued", getTypeId(activity).href);
328
- logger.info("Activity {activityId} is enqueued.", {
329
- activityId: activity.id?.href,
330
- activity: json,
331
- recipient
332
- });
333
- return "enqueued";
334
- }
335
- tracerProvider = tracerProvider ?? trace.getTracerProvider();
336
- return await tracerProvider.getTracer(name, version).startActiveSpan("activitypub.dispatch_inbox_listener", { kind: SpanKind.INTERNAL }, async (span) => {
337
- const dispatched = inboxListeners?.dispatchWithClass(activity);
338
- if (dispatched == null) {
339
- logger.error("Unsupported activity type:\n{activity}", {
340
- activity: json,
341
- recipient
342
- });
343
- span.setStatus({
344
- code: SpanStatusCode.UNSET,
345
- message: `Unsupported activity type: ${getTypeId(activity).href}`
346
- });
347
- recordInboxActivity(meterProvider, "rejected", getTypeId(activity).href);
348
- span.end();
349
- return "unsupportedActivity";
350
- }
351
- const { class: cls, listener } = dispatched;
352
- span.updateName(`activitypub.dispatch_inbox_listener ${cls.name}`);
353
- try {
354
- const activityType = getTypeId(activity).href;
355
- const started = performance.now();
356
- try {
357
- const contextFactory = listenerInboxContextFactory ?? inboxContextFactory;
358
- await listener(contextFactory(recipient, contextFactory === inboxContextFactory ? json : originalJson ?? json, activity.id?.href, activityType, contextMetadata), activity);
359
- } finally {
360
- getFederationMetrics(meterProvider).recordInboxProcessingDuration(activityType, getDurationMs(started));
361
- }
362
- } catch (error) {
363
- try {
364
- await inboxErrorHandler?.(ctx, error);
365
- } catch (error) {
366
- logger.error("An unexpected error occurred in inbox error handler:\n{error}", {
367
- error,
368
- activityId: activity.id?.href,
369
- activity: json,
370
- recipient
371
- });
372
- }
373
- logger.error("Failed to process the incoming activity {activityId}:\n{error}", {
374
- error,
375
- activityId: activity.id?.href,
376
- activity: json,
377
- recipient
378
- });
379
- span.setStatus({
380
- code: SpanStatusCode.ERROR,
381
- message: String(error)
382
- });
383
- recordInboxActivity(meterProvider, "rejected", getTypeId(activity).href);
384
- span.end();
385
- return "error";
386
- }
387
- recordInboxActivity(meterProvider, "processed", getTypeId(activity).href);
388
- if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal.Duration.from({ days: 1 }) });
389
- logger.info("Activity {activityId} has been processed.", {
390
- activityId: activity.id?.href,
391
- activity: json,
392
- recipient
393
- });
394
- span.end();
395
- return "success";
396
- });
397
- }
398
- //#endregion
399
- export { isActorlessActivityAuthenticated as a, createInboxRequestSource as c, invocationProvenance as d, outboundProvenance as f, sourceLogContext as g, snapshotLocalContext as h, getInboxIdempotencyKey as i, emptyProvenance as l, serializeProvenance as m, checkActorlessActivity as n, isInboxActivityProcessed as o, restoreProvenance as p, estimateQueuedMessageSize as r, routeActivity as s, actorsHaveSameOrigin as t, getOutboundProvenance as u };
@@ -1,198 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { i as getPortableDid, l as isPortableId, n as getCanonicalPortableId } from "./portable-key-id-Ca30-hOa.mjs";
5
- //#region src/federation/inbox-authentication.ts
6
- /**
7
- * The evidence of an activity that has not been authenticated by Fedify.
8
- */
9
- const EMPTY_EVIDENCE = Object.freeze({
10
- verified: false,
11
- requestSigners: Object.freeze([]),
12
- documentSigners: Object.freeze([]),
13
- originAuthenticated: Object.freeze([]),
14
- expandedActivity: Object.freeze([]),
15
- baseUrl: null
16
- });
17
- /**
18
- * Gets the evidence of an activity that has not been authenticated.
19
- * @internal
20
- */
21
- function getEmptyAuthenticationEvidence() {
22
- return EMPTY_EVIDENCE;
23
- }
24
- /**
25
- * Gets the principals that an authorization decision should rely on.
26
- * @param evidence The evidence.
27
- * @param scope See {@link IsActorAuthenticatedOptions.scope}.
28
- * @returns The principals.
29
- * @internal
30
- */
31
- function getEffectivePrincipals(evidence, scope = "effective") {
32
- if (scope === "document" || evidence.documentSigners.length > 0) return evidence.documentSigners;
33
- if (evidence.requestSigners.length > 0) return evidence.requestSigners;
34
- return evidence.originAuthenticated;
35
- }
36
- /**
37
- * Normalizes an actor ID for comparison: portable IDs and compatible
38
- * identifiers to their canonical portable ID, other IDs to their `href`.
39
- * @returns The normalized ID, or `null` for a malformed portable ID.
40
- */
41
- function normalizeActorId(id) {
42
- return isPortableId(id) ? getCanonicalPortableId(id) : id.href;
43
- }
44
- /**
45
- * Checks whether the given principal authenticates the given actor.
46
- * @param principal The principal.
47
- * @param actorId The actor ID.
48
- * @returns `true` if the principal authenticates the actor.
49
- * @internal
50
- */
51
- function principalAuthenticates(principal, actorId) {
52
- if (principal.kind === "portable-authority") {
53
- if (!isPortableId(actorId)) return false;
54
- const did = getPortableDid(actorId);
55
- return did != null && did === getPortableDid(principal.id);
56
- }
57
- const expected = normalizeActorId(actorId);
58
- return expected != null && normalizeActorId(principal.id) === expected;
59
- }
60
- /**
61
- * Checks whether the given evidence authenticates the given actor.
62
- *
63
- * Actor IDs are compared exactly, except that [FEP-ef61] portable IDs and
64
- * compatible identifiers are compared by their canonical portable IDs, and
65
- * a portable authority (a DID) authenticates the portable actors of that DID.
66
- *
67
- * @example
68
- * ``` typescript
69
- * federation
70
- * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
71
- * .on(Follow, async (ctx, follow) => {
72
- * if (follow.actorId == null) return;
73
- * // The actor is always authenticated for activities that declare one,
74
- * // but the same check works for any actor an activity names:
75
- * isActorAuthenticated(ctx.authentication, follow.actorId);
76
- * });
77
- * ```
78
- *
79
- * [FEP-ef61]: https://w3id.org/fep/ef61
80
- * @param evidence The authentication evidence, usually
81
- * {@link InboxContext.authentication}.
82
- * @param actorId The actor ID to check.
83
- * @param options Options.
84
- * @returns `true` if the actor is authenticated.
85
- * @since 2.5.0
86
- */
87
- function isActorAuthenticated(evidence, actorId, options = {}) {
88
- return getEffectivePrincipals(evidence, options.scope).some((principal) => principalAuthenticates(principal, actorId));
89
- }
90
- const SERIALIZED_KINDS = {
91
- actor: "actor",
92
- "portable-authority": "portableAuthority"
93
- };
94
- const PUBLIC_KINDS = {
95
- actor: "actor",
96
- portableAuthority: "portable-authority"
97
- };
98
- const SERIALIZED_MECHANISMS = {
99
- "http-signatures": "httpSignatures",
100
- "linked-data-signatures": "linkedDataSignatures",
101
- "object-integrity-proofs": "objectIntegrityProofs",
102
- origin: "origin"
103
- };
104
- const PUBLIC_MECHANISMS = {
105
- httpSignatures: "http-signatures",
106
- linkedDataSignatures: "linked-data-signatures",
107
- objectIntegrityProofs: "object-integrity-proofs",
108
- origin: "origin"
109
- };
110
- /**
111
- * Converts an internal proof signer to the public authentication principal.
112
- * @param signer The authenticated signer.
113
- * @returns The public principal.
114
- * @internal
115
- */
116
- function toProofPrincipal(signer) {
117
- return {
118
- kind: PUBLIC_KINDS[signer.kind],
119
- id: signer.id,
120
- mechanism: "object-integrity-proofs",
121
- keyId: signer.keyId
122
- };
123
- }
124
- function serializePrincipal(principal) {
125
- return {
126
- kind: SERIALIZED_KINDS[principal.kind],
127
- id: principal.id.href,
128
- mechanism: SERIALIZED_MECHANISMS[principal.mechanism],
129
- keyId: principal.keyId?.href ?? null
130
- };
131
- }
132
- /**
133
- * Serializes the principals of the given evidence for a queued message.
134
- * @internal
135
- */
136
- function serializeAuthentication(evidence) {
137
- return {
138
- verified: evidence.verified,
139
- requestSigners: evidence.requestSigners.map(serializePrincipal),
140
- documentSigners: evidence.documentSigners.map(serializePrincipal),
141
- originAuthenticated: evidence.originAuthenticated.map(serializePrincipal)
142
- };
143
- }
144
- function deserializePrincipals(value) {
145
- if (!Array.isArray(value)) return null;
146
- const principals = [];
147
- for (const item of value) {
148
- if (item == null || typeof item !== "object" || !(typeof item.kind === "string" && Object.hasOwn(PUBLIC_KINDS, item.kind)) || !(typeof item.mechanism === "string" && Object.hasOwn(PUBLIC_MECHANISMS, item.mechanism)) || typeof item.id !== "string" || !URL.canParse(item.id) || item.keyId != null && (typeof item.keyId !== "string" || !URL.canParse(item.keyId))) return null;
149
- principals.push(Object.freeze({
150
- kind: PUBLIC_KINDS[item.kind],
151
- id: new URL(item.id),
152
- mechanism: PUBLIC_MECHANISMS[item.mechanism],
153
- keyId: item.keyId == null ? null : new URL(item.keyId)
154
- }));
155
- }
156
- return principals;
157
- }
158
- /**
159
- * Restores the evidence of a queued message.
160
- * @param value The serialized principals.
161
- * @param expandedActivity The expanded activity, restored from the queued
162
- * verified view.
163
- * @param baseUrl The base URL, restored from the queued verified view.
164
- * @returns The evidence, or `null` if the serialized value is malformed.
165
- * @internal
166
- */
167
- function deserializeAuthentication(value, expandedActivity, baseUrl) {
168
- if (value == null || typeof value !== "object" || typeof value.verified !== "boolean") return null;
169
- const record = value;
170
- const requestSigners = deserializePrincipals(record.requestSigners);
171
- const documentSigners = deserializePrincipals(record.documentSigners);
172
- const originAuthenticated = deserializePrincipals(record.originAuthenticated);
173
- if (requestSigners == null || documentSigners == null || originAuthenticated == null) return null;
174
- return createAuthenticationEvidence({
175
- verified: record.verified,
176
- requestSigners,
177
- documentSigners,
178
- originAuthenticated,
179
- expandedActivity,
180
- baseUrl
181
- });
182
- }
183
- /**
184
- * Creates frozen evidence.
185
- * @internal
186
- */
187
- function createAuthenticationEvidence(evidence) {
188
- return Object.freeze({
189
- verified: evidence.verified,
190
- requestSigners: Object.freeze([...evidence.requestSigners]),
191
- documentSigners: Object.freeze([...evidence.documentSigners]),
192
- originAuthenticated: Object.freeze([...evidence.originAuthenticated]),
193
- expandedActivity: evidence.expandedActivity,
194
- baseUrl: evidence.baseUrl
195
- });
196
- }
197
- //#endregion
198
- export { isActorAuthenticated as a, getEmptyAuthenticationEvidence as i, deserializeAuthentication as n, serializeAuthentication as o, getEffectivePrincipals as r, toProofPrincipal as s, createAuthenticationEvidence as t };