@fedify/fedify 2.5.0-dev.2446 → 2.5.0-dev.2492

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 (141) hide show
  1. package/README.md +3 -0
  2. package/dist/{activity-listener-C-BSbKI7.mjs → activity-listener-CELFAodc.mjs} +8 -4
  3. package/dist/{builder-Da8b9O6v.mjs → builder-DphK9v7f.mjs} +5 -5
  4. package/dist/{client-D-XP_Ccb.d.ts → client-3InDZbba.d.cts} +0 -1
  5. package/dist/{client-D-XP_Ccb.d.cts → client-3InDZbba.d.ts} +0 -1
  6. package/dist/{client-CEnNz8O7.mjs → client-5SIFzW3q.mjs} +113 -64
  7. package/dist/compat/mod.d.cts +1 -1
  8. package/dist/compat/mod.d.ts +1 -1
  9. package/dist/compat/transformers.test.mjs +1 -1
  10. package/dist/{compound-proof-D1djO5fa.mjs → compound-proof-cYtvlTgF.mjs} +2 -2
  11. package/dist/{context-8Tu9kea0.mjs → context-COHd1Rsh.mjs} +2 -0
  12. package/dist/{context-BdB54V-A.d.ts → context-DQJE9YfH.d.ts} +332 -6
  13. package/dist/{context-CQ9H8vNW.d.cts → context-DSuL3YWx.d.cts} +332 -6
  14. package/dist/{deno-eNpfj4oR.mjs → deno-iOAA7iRN.mjs} +1 -1
  15. package/dist/docloader-DCZkiTeF.mjs +136 -0
  16. package/dist/{exporter-DThFfe7P.mjs → exporter-DVG68ozH.mjs} +36 -30
  17. package/dist/federation/builder.test.mjs +1 -1
  18. package/dist/federation/compound-fanout.test.mjs +6 -3
  19. package/dist/federation/handler-compound-proof.test.mjs +5 -5
  20. package/dist/federation/handler.test.mjs +22 -7
  21. package/dist/federation/hashlink-media.test.mjs +2 -2
  22. package/dist/federation/idempotency.test.mjs +2 -2
  23. package/dist/federation/inbox-actorless.test.d.mts +2 -0
  24. package/dist/federation/inbox-actorless.test.mjs +487 -0
  25. package/dist/federation/inbox-authentication.test.d.mts +2 -0
  26. package/dist/federation/inbox-authentication.test.mjs +116 -0
  27. package/dist/federation/inbox-report.test.mjs +5 -5
  28. package/dist/federation/inbox-view.test.d.mts +2 -0
  29. package/dist/federation/inbox-view.test.mjs +369 -0
  30. package/dist/federation/inbox.test.mjs +22 -12
  31. package/dist/federation/metrics.test.mjs +1 -1
  32. package/dist/federation/middleware.test.mjs +470 -35
  33. package/dist/federation/mod.cjs +2 -1
  34. package/dist/federation/mod.d.cts +4 -4
  35. package/dist/federation/mod.d.ts +4 -4
  36. package/dist/federation/mod.js +8 -2
  37. package/dist/federation/mq.test.mjs +36 -1
  38. package/dist/federation/outgoing-proof.test.mjs +9 -6
  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 +13 -7
  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 +502 -93
  49. package/dist/federation/tasks/enqueue.test.mjs +3 -3
  50. package/dist/federation/tasks/tasks.test.mjs +4 -4
  51. package/dist/federation/temporal.test.mjs +1 -1
  52. package/dist/federation/webfinger.test.mjs +2 -2
  53. package/dist/{federation-BVH7drJA.cjs → federation-D0AZw_aw.cjs} +1415 -236
  54. package/dist/{http-BUJ5SFh6.mjs → http-BoJCMnjY.mjs} +204 -106
  55. package/dist/{http-DlNxxW_5.js → http-ChXUU_3c.js} +319 -123
  56. package/dist/{http-BfW3wyQ4.cjs → http-kv1LZw-r.cjs} +339 -125
  57. package/dist/inbox-BjihTKLo.mjs +312 -0
  58. package/dist/inbox-authentication-DflPYlLL.mjs +171 -0
  59. package/dist/inbox-view-D-skypg-.mjs +385 -0
  60. package/dist/{key-nYGY4QB9.d.cts → key-DbLNT-vA.d.ts} +1 -2
  61. package/dist/{key-DhsBxxZN.d.ts → key-DlHT4R6k.d.cts} +1 -2
  62. package/dist/{kv-cache-D_m3A241.mjs → kv-cache-Cmsyke4d.mjs} +1 -1
  63. package/dist/{kv-cache-7015lbrx.js → kv-cache-DQcte7ES.js} +73 -28
  64. package/dist/{kv-cache-kkBB0vbI.cjs → kv-cache-Ddh5sMxH.cjs} +72 -27
  65. package/dist/ld-CWVpo_NM.d.cts +250 -0
  66. package/dist/{ld-CD2CsPxq.mjs → ld-CdvcOEXQ.mjs} +52 -9
  67. package/dist/ld-Inagww4R.d.ts +250 -0
  68. package/dist/{metrics-D3LHk6Z4.mjs → metrics-CpxvUrBz.mjs} +1 -1
  69. package/dist/{middleware-N9eM16XE.js → middleware-BHb5toqA.js} +1413 -247
  70. package/dist/{middleware-CCDXvXOG.mjs → middleware-BKs2DLUF.mjs} +1 -1
  71. package/dist/{middleware-CzoWvrdZ.mjs → middleware-CoBLrTKX.mjs} +533 -132
  72. package/dist/{mod-B0dGgQsg.d.cts → mod-6TQ4UQZb.d.cts} +1 -1
  73. package/dist/mod-B4kBw1-8.d.ts +154 -0
  74. package/dist/{mod-DkhfZC1u.d.ts → mod-B7j30IQf.d.ts} +2 -9
  75. package/dist/mod-C1nT74IG.d.cts +154 -0
  76. package/dist/{mod-D0bxB8jS.d.ts → mod-CIeBgsOC.d.ts} +1 -1
  77. package/dist/{mod-B5-wdzmJ.d.cts → mod-YvA4Rk8J.d.cts} +2 -9
  78. package/dist/mod.cjs +6 -5
  79. package/dist/mod.d.cts +9 -9
  80. package/dist/mod.d.ts +9 -9
  81. package/dist/mod.js +6 -6
  82. package/dist/{mq-Dm1Wmtm-.mjs → mq-eF96QxUT.mjs} +6 -0
  83. package/dist/nodeinfo/client.test.mjs +337 -19
  84. package/dist/nodeinfo/handler.test.mjs +2 -2
  85. package/dist/nodeinfo/mod.cjs +1 -1
  86. package/dist/nodeinfo/mod.d.cts +1 -1
  87. package/dist/nodeinfo/mod.d.ts +1 -1
  88. package/dist/nodeinfo/mod.js +1 -1
  89. package/dist/otel/exporter.test.mjs +257 -1
  90. package/dist/otel/mod.cjs +36 -30
  91. package/dist/otel/mod.d.cts +13 -0
  92. package/dist/otel/mod.d.ts +13 -0
  93. package/dist/otel/mod.js +36 -30
  94. package/dist/{owner-C5-FVX6t.mjs → owner-DTnVpUKA.mjs} +3 -3
  95. package/dist/{portable-collection-Cony3_LC.mjs → portable-collection-CJeYTL61.mjs} +2 -2
  96. package/dist/{portable-collection-C-Z1SKDy.cjs → portable-collection-DciwBIia.cjs} +1 -1
  97. package/dist/{portable-collection-CC2zNAje.js → portable-collection-TmtpzD4E.js} +1 -1
  98. package/dist/{portable-key-DNc_flH-.mjs → portable-key-DcYok4ki.mjs} +1 -1
  99. package/dist/{proof-Cryb1c70.mjs → proof-GH7Poos_.mjs} +98 -10
  100. package/dist/{send-AF25pWaJ.mjs → send-BgGJh6pv.mjs} +174 -76
  101. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  102. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  103. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  104. package/dist/sig/compound-proof.test.mjs +2 -2
  105. package/dist/sig/http.test.mjs +553 -2
  106. package/dist/sig/key.test.mjs +1 -1
  107. package/dist/sig/ld.test.mjs +1 -1
  108. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  109. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  110. package/dist/sig/mod.cjs +2 -2
  111. package/dist/sig/mod.d.cts +3 -3
  112. package/dist/sig/mod.d.ts +3 -3
  113. package/dist/sig/mod.js +2 -2
  114. package/dist/sig/owner.test.mjs +1 -1
  115. package/dist/sig/portable-collection.test.mjs +1 -1
  116. package/dist/sig/portable-interop.test.mjs +3 -3
  117. package/dist/sig/portable-key.test.mjs +5 -5
  118. package/dist/sig/proof.test.mjs +45 -5
  119. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  120. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  121. package/dist/sig/verification.test.mjs +3 -3
  122. package/dist/{temporal-BsAeuUJj.mjs → temporal-gJINzcL4.mjs} +1 -1
  123. package/dist/testing/kv.test.mjs +1 -1
  124. package/dist/testing/mod.d.mts +288 -2
  125. package/dist/testing/mod.mjs +2 -2
  126. package/dist/{testing-t8xDeJZ5.mjs → testing-Dbr21vZk.mjs} +1 -1
  127. package/dist/{types-_S2_MeLF.js → types-DUjZb4i6.js} +112 -63
  128. package/dist/{types-poIao40f.cjs → types-hKCCjii0.cjs} +111 -62
  129. package/dist/utils/docloader.test.mjs +344 -36
  130. package/dist/utils/kv-cache.test.mjs +1 -1
  131. package/dist/utils/mod.cjs +1 -1
  132. package/dist/utils/mod.d.cts +1 -1
  133. package/dist/utils/mod.d.ts +1 -1
  134. package/dist/utils/mod.js +1 -1
  135. package/package.json +7 -7
  136. package/dist/docloader-B-0nqOB1.mjs +0 -91
  137. package/dist/inbox-CHvMaIFX.mjs +0 -188
  138. package/dist/mod-BRpER-B0.d.ts +0 -320
  139. package/dist/mod-xAfaLS4T.d.cts +0 -320
  140. package/dist/owner-BF0L9cMt.d.cts +0 -78
  141. package/dist/owner-BSzr5-I8.d.ts +0 -78
@@ -1,16 +1,45 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-D-XP_Ccb.js";
3
- import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-DhsBxxZN.js";
4
- import { n as GetKeyOwnerOptions } from "./owner-BSzr5-I8.js";
2
+ import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-3InDZbba.js";
3
+ import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-DbLNT-vA.js";
4
+ import { m as GetKeyOwnerOptions, n as EffectiveContextLoaderPolicy } from "./ld-Inagww4R.js";
5
5
  import { n as KvStore, t as KvKey } from "./kv-B2mzK5tl.js";
6
6
  import { Router } from "@fedify/uri-template";
7
7
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
8
8
  import { MeterProvider, Span, Tracer, TracerProvider } from "@opentelemetry/api";
9
- import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions, PortableObjectVerifier } from "@fedify/vocab-runtime";
9
+ import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions, PortableObjectVerifier, RemoteDocument } from "@fedify/vocab-runtime";
10
10
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
11
11
  import { MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
12
12
  import { StandardSchemaV1 } from "@standard-schema/spec";
13
13
 
14
+ //#region src/federation/activity-listener.d.ts
15
+ /**
16
+ * Options for an inbox listener.
17
+ * @since 2.5.0
18
+ */
19
+ interface InboxListenerOptions {
20
+ /**
21
+ * Whether activities that declare no `actor` at all may reach the listener.
22
+ *
23
+ * Some protocols identify the requester without an `actor`; for example,
24
+ * Mastodon sends [FEP-7aa9] `FeatureRequest` activities without one. When
25
+ * this is `true`, such an activity is dispatched to the listener if Fedify
26
+ * authenticated at least one principal for it, i.e., the signer of its
27
+ * Object Integrity Proofs or Linked Data Signature, or otherwise the signer
28
+ * of the HTTP request, and its `id`, if any, has the same origin as that
29
+ * principal. The listener is then responsible for authorizing the request
30
+ * with {@link InboxContext.authentication}, e.g., with
31
+ * `featureInteraction.verifyRequest()` from
32
+ * `@fedify/interaction-controls`.
33
+ *
34
+ * An activity that declares an `actor` is never affected by this option;
35
+ * its actor must be authenticated as usual.
36
+ *
37
+ * [FEP-7aa9]: https://w3id.org/fep/7aa9
38
+ * @default `false`
39
+ */
40
+ readonly allowActorless?: boolean;
41
+ }
42
+ //#endregion
14
43
  //#region src/federation/inbox-report.d.ts
15
44
  /**
16
45
  * A JSON value retained from the incoming request.
@@ -53,6 +82,13 @@ type InboxAuthentication = {
53
82
  readonly type: "activityOriginMismatch";
54
83
  readonly activityId: URL;
55
84
  readonly actorIds: readonly URL[];
85
+ } | {
86
+ /**
87
+ * The activity declares no actor, and no principal was authenticated
88
+ * for it, although its listener allows activities without an actor.
89
+ * @since 2.5.0
90
+ */
91
+ readonly type: "noAuthenticatedPrincipal";
56
92
  };
57
93
  } | {
58
94
  readonly status: "skipped";
@@ -951,6 +987,18 @@ interface MessageQueue {
951
987
  */
952
988
  readonly atomicEnqueueMany?: boolean;
953
989
  /**
990
+ * The largest message, in bytes, that the backend can hold. Fedify compares
991
+ * it with a conservative estimate of a message's serialized size: the
992
+ * length of its JSON serialization encoded in UTF-8, plus 8 bytes for each
993
+ * JSON value in it, plus what encoding strings beyond Latin-1 as UTF-16
994
+ * adds, which also bounds binary serialization formats. When an
995
+ * incoming activity would make a larger inbox message, Fedify processes the
996
+ * activity right away instead of enqueueing it, as if there were no inbox
997
+ * queue. When omitted, messages are enqueued regardless of their size.
998
+ * @since 2.5.0
999
+ */
1000
+ readonly maxMessageSize?: number;
1001
+ /**
954
1002
  * Enqueues a message in the queue.
955
1003
  * @param message The message to enqueue.
956
1004
  * @param options Additional options for enqueuing the message.
@@ -1076,6 +1124,11 @@ declare class ParallelMessageQueue implements MessageQueue {
1076
1124
  * @since 2.4.0
1077
1125
  */
1078
1126
  readonly atomicEnqueueMany?: boolean;
1127
+ /**
1128
+ * Inherits the message size limit from the wrapped queue.
1129
+ * @since 2.5.0
1130
+ */
1131
+ readonly maxMessageSize?: number;
1079
1132
  readonly getDepth?: () => Promise<MessageQueueDepth>;
1080
1133
  /**
1081
1134
  * Constructs a new {@link ParallelMessageQueue} with the given queue and
@@ -1092,6 +1145,211 @@ declare class ParallelMessageQueue implements MessageQueue {
1092
1145
  listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
1093
1146
  }
1094
1147
  //#endregion
1148
+ //#region src/federation/inbox-authentication.d.ts
1149
+ /**
1150
+ * A party that Fedify authenticated for an incoming activity, independently
1151
+ * of the activity's declared `actor`.
1152
+ * @since 2.5.0
1153
+ */
1154
+ interface InboxPrincipal {
1155
+ /**
1156
+ * What {@link InboxPrincipal.id} is:
1157
+ *
1158
+ * - `"actor"`: an actor whose ownership of the verifying key Fedify
1159
+ * confirmed with the actor's own document.
1160
+ * - `"portableAuthority"`: a DID whose verification method made a valid
1161
+ * Object Integrity Proof. It authenticates the [FEP-ef61] portable
1162
+ * actors of that DID, and nothing else.
1163
+ *
1164
+ * [FEP-ef61]: https://w3id.org/fep/ef61
1165
+ */
1166
+ readonly kind: "actor" | "portableAuthority";
1167
+ /** The actor ID, or the DID if {@link kind} is `"portableAuthority"`. */
1168
+ readonly id: URL;
1169
+ /**
1170
+ * How the principal was authenticated:
1171
+ *
1172
+ * - `"httpSignatures"`: it signed the HTTP request.
1173
+ * - `"linkedDataSignatures"`: it made the Linked Data Signature of the
1174
+ * activity.
1175
+ * - `"objectIntegrityProofs"`: it made an Object Integrity Proof of the
1176
+ * activity.
1177
+ * - `"origin"`: the activity was fetched again from the actor's own web
1178
+ * origin, which happens only for `Context.routeActivity()`.
1179
+ */
1180
+ readonly mechanism: "httpSignatures" | "linkedDataSignatures" | "objectIntegrityProofs" | "origin";
1181
+ /** The key or verification method that authenticated the principal. */
1182
+ readonly keyId: URL | null;
1183
+ }
1184
+ /**
1185
+ * Who Fedify authenticated for an incoming activity, and the interpretation of
1186
+ * the activity it authenticated. Inbox listeners receive it as
1187
+ * {@link InboxContext.authentication}.
1188
+ *
1189
+ * Authenticated principals are independent of the activity's declared
1190
+ * `actor`: an activity forwarded by a relay is signed by the relay in its
1191
+ * HTTP request, but its document may be signed by its author, and some
1192
+ * activities, such as [FEP-7aa9] `FeatureRequest`s sent by Mastodon, declare
1193
+ * no `actor` at all. A valid signature alone does not authorize anything;
1194
+ * use {@link isActorAuthenticated} to check whether a specific actor was
1195
+ * authenticated.
1196
+ *
1197
+ * [FEP-7aa9]: https://w3id.org/fep/7aa9
1198
+ * @since 2.5.0
1199
+ */
1200
+ interface InboxAuthenticationEvidence {
1201
+ /**
1202
+ * Whether signatures were verified at all. It is `false` only when
1203
+ * signature verification is skipped, or when there is no evidence, e.g.,
1204
+ * for an activity queued by an older version of Fedify. In that case all
1205
+ * the principal lists are empty.
1206
+ */
1207
+ readonly verified: boolean;
1208
+ /**
1209
+ * The principals that signed the HTTP request, i.e., the server that
1210
+ * delivered the activity, which may have forwarded it. It is empty when
1211
+ * the activity document was authenticated by its own signatures, so that
1212
+ * HTTP Signatures did not need to be verified.
1213
+ */
1214
+ readonly requestSigners: readonly InboxPrincipal[];
1215
+ /**
1216
+ * The principals that made the verified Linked Data Signature or Object
1217
+ * Integrity Proofs of the activity document. All of them are listed when
1218
+ * there are several proofs.
1219
+ */
1220
+ readonly documentSigners: readonly InboxPrincipal[];
1221
+ /**
1222
+ * The actors authenticated because `Context.routeActivity()` fetched the
1223
+ * activity again from their own web origin. It is always empty for
1224
+ * activities delivered to an inbox.
1225
+ */
1226
+ readonly originAuthenticated: readonly InboxPrincipal[];
1227
+ /**
1228
+ * The activity as Fedify interpreted it while authenticating it, in
1229
+ * expanded JSON-LD. Typed vocabulary objects omit some values, such as
1230
+ * blank node references and values they cannot decode, so authorization
1231
+ * that has to count every value of a property, e.g., that a property has
1232
+ * exactly one value, should inspect this instead. It is deeply frozen.
1233
+ * It is empty when there is no evidence.
1234
+ */
1235
+ readonly expandedActivity: readonly Record<string, unknown>[];
1236
+ /**
1237
+ * The base URL the activity was decoded with, e.g., the URL an activity
1238
+ * fetched by `Context.routeActivity()` was finally retrieved from, or
1239
+ * `null` if none was given. Relative IRIs left in
1240
+ * {@link expandedActivity} resolve against it, or against the activity's
1241
+ * own `@id` if it is `null`, as the decoder resolves them.
1242
+ */
1243
+ readonly baseUrl: URL | null;
1244
+ }
1245
+ /**
1246
+ * Options for {@link isActorAuthenticated}.
1247
+ * @since 2.5.0
1248
+ */
1249
+ interface IsActorAuthenticatedOptions {
1250
+ /**
1251
+ * Which principals to consider:
1252
+ *
1253
+ * - `"effective"` (default): the document signers if there are any,
1254
+ * otherwise the request signers if there are any, otherwise the actors
1255
+ * authenticated by their origin.
1256
+ * - `"document"`: the document signers only.
1257
+ */
1258
+ readonly scope?: "effective" | "document";
1259
+ }
1260
+ /**
1261
+ * Checks whether the given evidence authenticates the given actor.
1262
+ *
1263
+ * Actor IDs are compared exactly, except that [FEP-ef61] portable IDs and
1264
+ * compatible identifiers are compared by their canonical portable IDs, and
1265
+ * a portable authority (a DID) authenticates the portable actors of that DID.
1266
+ *
1267
+ * @example
1268
+ * ``` typescript
1269
+ * federation
1270
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1271
+ * .on(Follow, async (ctx, follow) => {
1272
+ * if (follow.actorId == null) return;
1273
+ * // The actor is always authenticated for activities that declare one,
1274
+ * // but the same check works for any actor an activity names:
1275
+ * isActorAuthenticated(ctx.authentication, follow.actorId);
1276
+ * });
1277
+ * ```
1278
+ *
1279
+ * [FEP-ef61]: https://w3id.org/fep/ef61
1280
+ * @param evidence The authentication evidence, usually
1281
+ * {@link InboxContext.authentication}.
1282
+ * @param actorId The actor ID to check.
1283
+ * @param options Options.
1284
+ * @returns `true` if the actor is authenticated.
1285
+ * @since 2.5.0
1286
+ */
1287
+ declare function isActorAuthenticated(evidence: InboxAuthenticationEvidence, actorId: URL, options?: IsActorAuthenticatedOptions): boolean;
1288
+ /**
1289
+ * A {@link InboxPrincipal} as stored in a queued message.
1290
+ * @internal
1291
+ */
1292
+ interface SerializedInboxPrincipal {
1293
+ readonly kind: InboxPrincipal["kind"];
1294
+ readonly id: string;
1295
+ readonly mechanism: InboxPrincipal["mechanism"];
1296
+ readonly keyId: string | null;
1297
+ }
1298
+ /**
1299
+ * The principals of an {@link InboxAuthenticationEvidence} as stored in
1300
+ * a queued message. The expanded activity and the base URL are restored
1301
+ * from the queued verified view instead.
1302
+ * @internal
1303
+ */
1304
+ interface SerializedInboxAuthentication {
1305
+ readonly verified: boolean;
1306
+ readonly requestSigners: readonly SerializedInboxPrincipal[];
1307
+ readonly documentSigners: readonly SerializedInboxPrincipal[];
1308
+ readonly originAuthenticated: readonly SerializedInboxPrincipal[];
1309
+ }
1310
+ //#endregion
1311
+ //#region src/federation/inbox-view.d.ts
1312
+ /**
1313
+ * A {@link ContextSnapshotEntry} as stored in a queued message. A response
1314
+ * that equals the one Fedify bundles for the URL is stored as a reference to
1315
+ * the bundled context, along with its hash for diagnostics.
1316
+ * @internal
1317
+ */
1318
+ type SerializedContextSnapshotEntry = {
1319
+ readonly policy: EffectiveContextLoaderPolicy;
1320
+ readonly url: string; /** The SHA-256 of the canonical JSON of the whole response. */
1321
+ readonly sha256: string;
1322
+ } & ({
1323
+ readonly bundled: true;
1324
+ } | {
1325
+ readonly response: RemoteDocument;
1326
+ });
1327
+ /**
1328
+ * The interpretation of an incoming activity that Fedify authenticated, as
1329
+ * stored in a queued message. The document itself is not copied; it is
1330
+ * a field of the message.
1331
+ * @internal
1332
+ */
1333
+ interface SerializedVerifiedActivityView {
1334
+ /** The format version. */
1335
+ readonly version: 1;
1336
+ /** The context loader policy the activity was parsed with. */
1337
+ readonly policy: EffectiveContextLoaderPolicy;
1338
+ /**
1339
+ * Which document the activity was parsed from, with its Linked Data
1340
+ * Signature detached: the `activity` of the message, i.e., the payload as
1341
+ * received, or its `normalizedActivity`, i.e., the payload compacted for
1342
+ * Linked Data Signatures.
1343
+ */
1344
+ readonly source: "activity" | "normalizedActivity";
1345
+ /** The `baseUrl` option the activity was parsed with. */
1346
+ readonly baseUrl: string | null;
1347
+ /** The context responses the interpretation used. */
1348
+ readonly contexts: readonly SerializedContextSnapshotEntry[];
1349
+ /** The digest of the expanded activity. */
1350
+ readonly expandedDigest: string;
1351
+ }
1352
+ //#endregion
1095
1353
  //#region src/federation/handler.d.ts
1096
1354
  /**
1097
1355
  * Options for the {@link respondWithObject} and
@@ -1506,6 +1764,21 @@ interface InboxMessage {
1506
1764
  * @internal
1507
1765
  */
1508
1766
  readonly ldSignatureVerified?: boolean;
1767
+ /**
1768
+ * The interpretation of the activity that Fedify authenticated, i.e., which
1769
+ * document it was parsed from and every JSON-LD context response the parse
1770
+ * used, so that the worker and its retries dispatch the very same
1771
+ * interpretation without loading contexts again. Absent in messages queued
1772
+ * by older Fedify versions.
1773
+ * @internal
1774
+ */
1775
+ readonly verifiedView?: SerializedVerifiedActivityView;
1776
+ /**
1777
+ * Who Fedify authenticated for the activity. Absent in messages queued by
1778
+ * older Fedify versions.
1779
+ * @internal
1780
+ */
1781
+ readonly authentication?: SerializedInboxAuthentication;
1509
1782
  readonly started: string;
1510
1783
  readonly attempt: number;
1511
1784
  readonly identifier: string | null;
@@ -2886,11 +3159,27 @@ interface InboxListenerSetters<TContextData> {
2886
3159
  /**
2887
3160
  * Registers a listener for a specific incoming activity type.
2888
3161
  *
3162
+ * @example
3163
+ * ``` typescript
3164
+ * federation
3165
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
3166
+ * // Mastodon sends FeatureRequest activities without an actor:
3167
+ * .on(FeatureRequest, async (ctx, request) => {
3168
+ * const verification = await featureInteraction.verifyRequest(ctx, {
3169
+ * request,
3170
+ * authentication: ctx.authentication,
3171
+ * });
3172
+ * // ...
3173
+ * }, { allowActorless: true });
3174
+ * ```
3175
+ *
2889
3176
  * @param type A subclass of {@link Activity} to listen to.
2890
3177
  * @param listener A callback to handle an incoming activity.
3178
+ * @param options Options for the listener. See
3179
+ * {@link InboxListenerOptions}. (Since 2.5.0.)
2891
3180
  * @returns The setters object so that settings can be chained.
2892
3181
  */
2893
- on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>): InboxListenerSetters<TContextData>;
3182
+ on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>, options?: InboxListenerOptions): InboxListenerSetters<TContextData>;
2894
3183
  /**
2895
3184
  * Registers an error handler for inbox listeners. Any exceptions thrown
2896
3185
  * from the listeners are caught and passed to this handler.
@@ -4298,6 +4587,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
4298
4587
  * Gets the public key of the sender, if any exists and it is verified.
4299
4588
  * Otherwise, `null` is returned.
4300
4589
  *
4590
+ * Successful results are reused for this request regardless of the options.
4591
+ * Pending checks and `null` results are reused for the same effective
4592
+ * document and context loaders, including failed lookups. Rejected checks
4593
+ * can be retried. Shared work uses the first caller's tracer provider.
4594
+ *
4301
4595
  * This can be used for implementing [authorized fetch] (also known as
4302
4596
  * secure mode) in ActivityPub.
4303
4597
  *
@@ -4311,6 +4605,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
4311
4605
  * Gets the public key of the sender, if any exists and it is verified.
4312
4606
  * Otherwise, `null` is returned.
4313
4607
  *
4608
+ * Successful results are reused for this request regardless of the options.
4609
+ * Pending checks and `null` results are reused for the same effective
4610
+ * document and context loaders, including failed lookups. Rejected checks
4611
+ * can be retried. Shared work uses the first caller's tracer provider.
4612
+ *
4314
4613
  * This can be used for implementing [authorized fetch] (also known as
4315
4614
  * secure mode) in ActivityPub.
4316
4615
  *
@@ -4330,6 +4629,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
4330
4629
  * Gets the owner of the signed key, if any exists and it is verified.
4331
4630
  * Otherwise, `null` is returned.
4332
4631
  *
4632
+ * Verified keys and owners are reused for this request regardless of the
4633
+ * options. Pending checks are shared for the same effective document and
4634
+ * context loaders. A `null` result from an owner lookup after key
4635
+ * verification is retained for those loaders. A `null` result caused by
4636
+ * an unverified key is not retained, allowing an owner lookup after another
4637
+ * loader verifies the key. Rejected checks can be retried. Shared work
4638
+ * uses the first caller's tracer provider.
4639
+ *
4333
4640
  * This can be used for implementing [authorized fetch] (also known as
4334
4641
  * secure mode) in ActivityPub.
4335
4642
  *
@@ -4344,6 +4651,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
4344
4651
  * Gets the owner of the signed key, if any exists and it is verified.
4345
4652
  * Otherwise, `null` is returned.
4346
4653
  *
4654
+ * Verified keys and owners are reused for this request regardless of the
4655
+ * options. Pending checks are shared for the same effective document and
4656
+ * context loaders. A `null` result from an owner lookup after key
4657
+ * verification is retained for those loaders. A `null` result caused by
4658
+ * an unverified key is not retained, allowing an owner lookup after another
4659
+ * loader verifies the key. Rejected checks can be retried. Shared work
4660
+ * uses the first caller's tracer provider.
4661
+ *
4347
4662
  * This can be used for implementing [authorized fetch] (also known as
4348
4663
  * secure mode) in ActivityPub.
4349
4664
  *
@@ -4419,6 +4734,17 @@ interface InboxContext<TContextData> extends Context<TContextData> {
4419
4734
  */
4420
4735
  readonly recipient: string | null;
4421
4736
  /**
4737
+ * Who Fedify authenticated for the incoming activity, independently of its
4738
+ * declared `actor`, and the interpretation of the activity that was
4739
+ * authenticated. It is preserved through the inbox queue and its retries.
4740
+ *
4741
+ * Use it with {@link isActorAuthenticated} to authorize requests that do
4742
+ * not declare an `actor`, which reach a listener only if it is registered
4743
+ * with the `allowActorless` option.
4744
+ * @since 2.5.0
4745
+ */
4746
+ readonly authentication: InboxAuthenticationEvidence;
4747
+ /**
4422
4748
  * Creates a new context with the same properties as this one,
4423
4749
  * but with the given data.
4424
4750
  * @param data The new data to associate with the context.
@@ -4838,4 +5164,4 @@ interface ActorKeyPair extends CryptoKeyPair {
4838
5164
  readonly multikey: Multikey;
4839
5165
  }
4840
5166
  //#endregion
4841
- export { respondWithObject as $, digest as $t, InboxChallengePolicy as A, CustomCollectionDispatcher as At, createFederation as B, OutboxListener as Bt, FederationBenchmarkOptions as C, ActorKeyPairsDispatcher as Ct, FederationStartQueueOptions as D, CollectionDispatcher as Dt, FederationOptions as E, CollectionCursor as Et, PortableInboxForwardingOptions as F, MediaUploaderCallback as Ft, TaskEnqueueOptions as G, SharedInboxKeyDispatcher as Gt, createFederationBuilder as H, OutboxPermanentFailureHandler as Ht, Rfc6570Expression as I, NodeInfoDispatcher as It, CreateExponentialBackoffPolicyOptions as J, WebFingerLinksDispatcher as Jt, TaskHandler as K, UnverifiedActivityHandler as Kt, FederationKvPrefixes as L, ObjectAuthorizePredicate as Lt, MediaUploaderSetters as M, HashlinkMediaRequest as Mt, ObjectCallbackSetters as N, InboxErrorHandler as Nt, IdempotencyKeyCallback as O, CustomCollectionCounter as Ot, OutboxListenerSetters as P, InboxListener as Pt, RespondWithObjectOptions as Q, buildCollectionSynchronizationHeader as Qt, FederationOrigin as R, ObjectDispatcher as Rt, Federation as S, ActorHandleMapper as St, FederationFetchOptions as T, CollectionCounter as Tt, TaskDefinition as U, PortableActorIdMapper as Ut, Message as V, OutboxListenerErrorHandler as Vt, TaskDefinitionOptions as W, PortableCollectionOwnerMapper as Wt, RetryPolicy as X, SenderKeyPair as Xt, RetryContext as Y, SendActivityError as Yt, createExponentialBackoffPolicy as Z, PageItems as Zt, ActorCallbackSetters as _, NormalizedCircuitBreakerOptions as _t, GetObjectOptions as a, InboxRequestReport as an, MessageQueueEnqueueOptions as at, CustomCollectionCallbackSetters as b, ActorAliasMapper as bt, IsSignedByAudienceOptions as c, CircuitBreaker as ct, ParseUriResult as d, CircuitBreakerCreateOptions as dt, ActivityTransformer as en, respondWithObjectIfAcceptable as et, PortableRequest as f, CircuitBreakerFailurePolicy as ft, SendActivityOptionsForCollection as g, CircuitBreakerStateChange as gt, SendActivityOptions as h, CircuitBreakerState as ht, GetActorOptions as i, InboxRequestOutcome as in, MessageQueueDepth as it, InboxListenerSetters as j, HashlinkMediaDispatcher as jt, IdempotencyStrategy as k, CustomCollectionCursor as kt, OutboxContext as l, CircuitBreakerActivityDrop as lt, RouteActivityOptions as m, CircuitBreakerOptions as mt, Context as n, InboxJsonValue as nn, InProcessMessageQueueOptions as nt, GetSignedKeyOptions as o, MessageQueueListenOptions as ot, RequestContext as p, CircuitBreakerKvState as pt, TaskRegistry as q, UnverifiedActivityReason as qt, ForwardActivityOptions as r, InboxRequestFinishedHandler as rn, MessageQueue as rt, InboxContext as s, ParallelMessageQueue as st, ActorKeyPair as t, InboxAuthentication as tn, InProcessMessageQueue as tt, ParseUriOptions as u, CircuitBreakerBeforeSendDecision as ut, CollectionCallbackSetters as v, normalizeCircuitBreakerOptions as vt, FederationBuilder as w, AuthorizePredicate as wt, Federatable as x, ActorDispatcher as xt, ConstructorWithTypeId as y, parseCircuitBreakerKvState as yt, FederationQueueOptions as z, OutboxErrorHandler as zt };
5167
+ export { respondWithObject as $, SendActivityError as $t, InboxChallengePolicy as A, CollectionCursor as At, createFederation as B, NodeInfoDispatcher as Bt, FederationBenchmarkOptions as C, parseCircuitBreakerKvState as Ct, FederationStartQueueOptions as D, ActorKeyPairsDispatcher as Dt, FederationOptions as E, ActorHandleMapper as Et, PortableInboxForwardingOptions as F, HashlinkMediaDispatcher as Ft, TaskEnqueueOptions as G, OutboxListenerErrorHandler as Gt, createFederationBuilder as H, ObjectDispatcher as Ht, Rfc6570Expression as I, HashlinkMediaRequest as It, CreateExponentialBackoffPolicyOptions as J, PortableCollectionOwnerMapper as Jt, TaskHandler as K, OutboxPermanentFailureHandler as Kt, FederationKvPrefixes as L, InboxErrorHandler as Lt, MediaUploaderSetters as M, CustomCollectionCounter as Mt, ObjectCallbackSetters as N, CustomCollectionCursor as Nt, IdempotencyKeyCallback as O, AuthorizePredicate as Ot, OutboxListenerSetters as P, CustomCollectionDispatcher as Pt, RespondWithObjectOptions as Q, WebFingerLinksDispatcher as Qt, FederationOrigin as R, InboxListener as Rt, Federation as S, normalizeCircuitBreakerOptions as St, FederationFetchOptions as T, ActorDispatcher as Tt, TaskDefinition as U, OutboxErrorHandler as Ut, Message as V, ObjectAuthorizePredicate as Vt, TaskDefinitionOptions as W, OutboxListener as Wt, RetryPolicy as X, UnverifiedActivityHandler as Xt, RetryContext as Y, SharedInboxKeyDispatcher as Yt, createExponentialBackoffPolicy as Z, UnverifiedActivityReason as Zt, ActorCallbackSetters as _, CircuitBreakerKvState as _t, GetObjectOptions as a, InboxAuthentication as an, InProcessMessageQueue as at, CustomCollectionCallbackSetters as b, CircuitBreakerStateChange as bt, IsSignedByAudienceOptions as c, InboxRequestOutcome as cn, MessageQueueDepth as ct, ParseUriResult as d, ParallelMessageQueue as dt, SenderKeyPair as en, respondWithObjectIfAcceptable as et, PortableRequest as f, CircuitBreaker as ft, SendActivityOptionsForCollection as g, CircuitBreakerFailurePolicy as gt, SendActivityOptions as h, CircuitBreakerCreateOptions as ht, GetActorOptions as i, ActivityTransformer as in, isActorAuthenticated as it, InboxListenerSetters as j, CollectionDispatcher as jt, IdempotencyStrategy as k, CollectionCounter as kt, OutboxContext as l, InboxRequestReport as ln, MessageQueueEnqueueOptions as lt, RouteActivityOptions as m, CircuitBreakerBeforeSendDecision as mt, Context as n, buildCollectionSynchronizationHeader as nn, InboxPrincipal as nt, GetSignedKeyOptions as o, InboxJsonValue as on, InProcessMessageQueueOptions as ot, RequestContext as p, CircuitBreakerActivityDrop as pt, TaskRegistry as q, PortableActorIdMapper as qt, ForwardActivityOptions as r, digest as rn, IsActorAuthenticatedOptions as rt, InboxContext as s, InboxRequestFinishedHandler as sn, MessageQueue as st, ActorKeyPair as t, PageItems as tn, InboxAuthenticationEvidence as tt, ParseUriOptions as u, InboxListenerOptions as un, MessageQueueListenOptions as ut, CollectionCallbackSetters as v, CircuitBreakerOptions as vt, FederationBuilder as w, ActorAliasMapper as wt, Federatable as x, NormalizedCircuitBreakerOptions as xt, ConstructorWithTypeId as y, CircuitBreakerState as yt, FederationQueueOptions as z, MediaUploaderCallback as zt };