@fedify/fedify 2.2.19 → 2.2.21

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 (109) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
  15. package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
  16. package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/docloader-Bogpjg4d.mjs +125 -0
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1567 -30
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +723 -68
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
  38. package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
  39. package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
  40. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  41. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  42. package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
  45. package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
  46. package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
  49. package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
  52. package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
  53. package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
  58. package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +764 -18
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/otel/exporter.test.mjs +292 -30
  71. package/dist/otel/mod.cjs +36 -30
  72. package/dist/otel/mod.d.cts +13 -0
  73. package/dist/otel/mod.d.ts +13 -0
  74. package/dist/otel/mod.js +36 -30
  75. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  76. package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
  77. package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
  78. package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  79. package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
  80. package/dist/send-CAdpwbFX.mjs +416 -0
  81. package/dist/sig/http.test.mjs +528 -2
  82. package/dist/sig/key-types.test.d.mts +218 -0
  83. package/dist/sig/key-types.test.mjs +8 -0
  84. package/dist/sig/key.test.mjs +2 -2
  85. package/dist/sig/ld.test.mjs +573 -8
  86. package/dist/sig/mod.cjs +2 -2
  87. package/dist/sig/mod.d.cts +3 -3
  88. package/dist/sig/mod.d.ts +3 -3
  89. package/dist/sig/mod.js +2 -2
  90. package/dist/sig/owner.test.mjs +1 -1
  91. package/dist/sig/proof.test.mjs +96 -4
  92. package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
  93. package/dist/testing/mod.d.mts +1 -2396
  94. package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
  95. package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
  96. package/dist/utils/docloader.test.mjs +318 -34
  97. package/dist/utils/mod.cjs +1 -1
  98. package/dist/utils/mod.d.cts +1 -1
  99. package/dist/utils/mod.d.ts +1 -1
  100. package/dist/utils/mod.js +1 -1
  101. package/package.json +6 -6
  102. package/dist/docloader-D1ghurDJ.mjs +0 -83
  103. package/dist/send-D35Va72B.mjs +0 -260
  104. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  105. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  106. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  107. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  108. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  109. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
6
- import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-amccRMrV.mjs";
6
+ import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-DHf_DYXp.mjs";
7
7
  import { mockDocumentLoader, test } from "@fedify/fixture";
8
8
  import { Create, Document, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
9
9
  //#region src/compat/outgoing-jsonld.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { t as assertNotEquals } from "../assert_not_equals-BkxW5QJI.mjs";
6
- import { t as normalizePublicAudience } from "../public-audience-DpJqzPuh.mjs";
6
+ import { t as normalizePublicAudience } from "../public-audience-4g3_Ze4y.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { Create, Follow, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
9
9
  import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
7
- import { n as FederationImpl, v as actorDehydrator, y as autoIdAssigner } from "../middleware-CpXoRHs3.mjs";
7
+ import { n as FederationImpl, v as actorDehydrator, y as autoIdAssigner } from "../middleware-dlGvSrXl.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { Follow, Person } from "@fedify/vocab";
10
10
  //#region src/compat/transformers.test.ts
@@ -1,10 +1,10 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-CAM_bQXx.cjs";
3
- import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-DqZhyEso.cjs";
2
+ import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-B3ruDgWg.cjs";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-C8qLHs_Z.cjs";
4
4
  import { n as GetKeyOwnerOptions } from "./owner-B3hNQCG8.cjs";
5
5
  import { n as KvStore, t as KvKey } from "./kv-CZKl1IUS.cjs";
6
6
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
7
- import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
7
+ import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
8
8
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
9
9
  import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
10
10
 
@@ -46,13 +46,18 @@ declare function buildCollectionSynchronizationHeader(collectionId: string | URL
46
46
  //#region src/federation/send.d.ts
47
47
  /**
48
48
  * A key pair for an actor who sends an activity.
49
+ *
50
+ * The private key type is parameterized so that Fedify can accept keys from
51
+ * `node:crypto` at its input boundaries while `SenderKeyPair` still exposes the
52
+ * ambient `CryptoKey` type by default.
53
+ * @template TKey The type of the private key.
49
54
  * @since 0.10.0
50
55
  */
51
- interface SenderKeyPair {
56
+ interface SenderKeyPair<TKey extends CryptoKeyLike = CryptoKey> {
52
57
  /**
53
58
  * The actor's private key to sign the request.
54
59
  */
55
- readonly privateKey: CryptoKey;
60
+ readonly privateKey: TKey;
56
61
  /**
57
62
  * The public key ID that corresponds to the private key.
58
63
  */
@@ -116,13 +121,19 @@ type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, ide
116
121
  /**
117
122
  * A callback that dispatches key pairs for an actor.
118
123
  *
124
+ * The returned key pairs may come from any supported runtime, including keys
125
+ * obtained from `node:crypto`'s Web Crypto API, so the key pair type is
126
+ * parameterized. It defaults to the ambient `CryptoKeyPair` type for
127
+ * compatibility with code that calls a dispatcher directly.
128
+ *
119
129
  * @template TContextData The context data to pass to the {@link Context}.
130
+ * @template TKeyPair The type of the key pairs the dispatcher returns.
120
131
  * @param context The context.
121
132
  * @param identifier The actor's internal identifier or username.
122
133
  * @returns The key pairs.
123
134
  * @since 0.10.0
124
135
  */
125
- type ActorKeyPairsDispatcher<TContextData> = (context: Context<TContextData>, identifier: string) => CryptoKeyPair[] | Promise<CryptoKeyPair[]>;
136
+ type ActorKeyPairsDispatcher<TContextData, TKeyPair extends CryptoKeyPairLike = CryptoKeyPair> = (context: Context<TContextData>, identifier: string) => TKeyPair[] | Promise<TKeyPair[]>;
126
137
  /**
127
138
  * A callback that maps a WebFinger username to the corresponding actor's
128
139
  * internal identifier, or `null` if the username is not found.
@@ -271,11 +282,11 @@ type OutboxListenerErrorHandler<TContextData> = (context: OutboxContext<TContext
271
282
  * not authorized.
272
283
  * @since 0.11.0
273
284
  */
274
- type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
285
+ type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
275
286
  identifier: string;
276
287
  } | {
277
288
  username: string;
278
- } | null | Promise<SenderKeyPair | {
289
+ } | null | Promise<SenderKeyPair<TKeyPair> | {
279
290
  identifier: string;
280
291
  } | {
281
292
  username: string;
@@ -1481,6 +1492,12 @@ interface FederationOptions<TContextData> {
1481
1492
  *
1482
1493
  * By default, the queue starts automatically.
1483
1494
  *
1495
+ * Automatic startup is best-effort: if a queue cannot start listening,
1496
+ * a warning is logged once per federation instance and the failed worker is
1497
+ * not retried, while an explicit {@link Federation.startQueue} call rejects.
1498
+ * Runtimes that consume the queue elsewhere, such as Cloudflare Workers with
1499
+ * {@link Federation.processQueuedTask}, should set this to `true`.
1500
+ *
1484
1501
  * @since 0.12.0
1485
1502
  */
1486
1503
  manuallyStartQueue?: boolean;
@@ -1654,7 +1671,7 @@ interface ActorCallbackSetters<TContextData> {
1654
1671
  * @returns The setters object so that settings can be chained.
1655
1672
  * @since 0.10.0
1656
1673
  */
1657
- setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
1674
+ setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
1658
1675
  /**
1659
1676
  * Sets the callback function that maps a WebFinger username to
1660
1677
  * the corresponding actor's identifier. If it's omitted, the identifier
@@ -1853,7 +1870,7 @@ interface InboxListenerSetters<TContextData> {
1853
1870
  * @returns The setters object so that settings can be chained.
1854
1871
  * @since 0.11.0
1855
1872
  */
1856
- setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
1873
+ setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
1857
1874
  /**
1858
1875
  * Configures the strategy for handling activity idempotency in inbox processing.
1859
1876
  *
@@ -2186,7 +2203,7 @@ interface Context<TContextData> {
2186
2203
  */
2187
2204
  getDocumentLoader(identity: {
2188
2205
  keyId: URL;
2189
- privateKey: CryptoKey;
2206
+ privateKey: CryptoKeyLike;
2190
2207
  }): DocumentLoader;
2191
2208
  /**
2192
2209
  * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
@@ -2299,7 +2316,7 @@ interface Context<TContextData> {
2299
2316
  * @param activity The activity to send.
2300
2317
  * @param options Options for sending the activity.
2301
2318
  */
2302
- sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
2319
+ sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2303
2320
  identifier: string;
2304
2321
  } | {
2305
2322
  username: string;
@@ -2447,6 +2464,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2447
2464
  * Gets the public key of the sender, if any exists and it is verified.
2448
2465
  * Otherwise, `null` is returned.
2449
2466
  *
2467
+ * Successful results are reused for this request regardless of the options.
2468
+ * Pending checks and `null` results are reused for the same effective
2469
+ * document and context loaders, including failed lookups. Rejected checks
2470
+ * can be retried. Shared work uses the first caller's tracer provider.
2471
+ *
2450
2472
  * This can be used for implementing [authorized fetch] (also known as
2451
2473
  * secure mode) in ActivityPub.
2452
2474
  *
@@ -2460,6 +2482,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2460
2482
  * Gets the public key of the sender, if any exists and it is verified.
2461
2483
  * Otherwise, `null` is returned.
2462
2484
  *
2485
+ * Successful results are reused for this request regardless of the options.
2486
+ * Pending checks and `null` results are reused for the same effective
2487
+ * document and context loaders, including failed lookups. Rejected checks
2488
+ * can be retried. Shared work uses the first caller's tracer provider.
2489
+ *
2463
2490
  * This can be used for implementing [authorized fetch] (also known as
2464
2491
  * secure mode) in ActivityPub.
2465
2492
  *
@@ -2479,6 +2506,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2479
2506
  * Gets the owner of the signed key, if any exists and it is verified.
2480
2507
  * Otherwise, `null` is returned.
2481
2508
  *
2509
+ * Verified keys and owners are reused for this request regardless of the
2510
+ * options. Pending checks are shared for the same effective document and
2511
+ * context loaders. A `null` result from an owner lookup after key
2512
+ * verification is retained for those loaders. A `null` result caused by
2513
+ * an unverified key is not retained, allowing an owner lookup after another
2514
+ * loader verifies the key. Rejected checks can be retried. Shared work
2515
+ * uses the first caller's tracer provider.
2516
+ *
2482
2517
  * This can be used for implementing [authorized fetch] (also known as
2483
2518
  * secure mode) in ActivityPub.
2484
2519
  *
@@ -2493,6 +2528,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2493
2528
  * Gets the owner of the signed key, if any exists and it is verified.
2494
2529
  * Otherwise, `null` is returned.
2495
2530
  *
2531
+ * Verified keys and owners are reused for this request regardless of the
2532
+ * options. Pending checks are shared for the same effective document and
2533
+ * context loaders. A `null` result from an owner lookup after key
2534
+ * verification is retained for those loaders. A `null` result caused by
2535
+ * an unverified key is not retained, allowing an owner lookup after another
2536
+ * loader verifies the key. Rejected checks can be retried. Shared work
2537
+ * uses the first caller's tracer provider.
2538
+ *
2496
2539
  * This can be used for implementing [authorized fetch] (also known as
2497
2540
  * secure mode) in ActivityPub.
2498
2541
  *
@@ -2546,7 +2589,7 @@ interface InboxContext<TContextData> extends Context<TContextData> {
2546
2589
  * @param options Options for forwarding the activity.
2547
2590
  * @since 1.0.0
2548
2591
  */
2549
- forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2592
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2550
2593
  identifier: string;
2551
2594
  } | {
2552
2595
  username: string;
@@ -2604,7 +2647,7 @@ interface OutboxContext<TContextData> extends Context<TContextData> {
2604
2647
  * @param options Options for forwarding the activity.
2605
2648
  * @since 2.2.0
2606
2649
  */
2607
- forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2650
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2608
2651
  identifier: string;
2609
2652
  } | {
2610
2653
  username: string;
@@ -1,11 +1,11 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-CSddvgWN.js";
3
- import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-Dl00HXr4.js";
2
+ import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-9DPcy_Yx.js";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-D8WmcRAF.js";
4
4
  import { n as GetKeyOwnerOptions } from "./owner-CiBPcC6F.js";
5
5
  import { n as KvStore, t as KvKey } from "./kv-CxaI4eGo.js";
6
6
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
8
- import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
8
+ import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
9
9
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
10
10
 
11
11
  //#region src/compat/types.d.ts
@@ -46,13 +46,18 @@ declare function buildCollectionSynchronizationHeader(collectionId: string | URL
46
46
  //#region src/federation/send.d.ts
47
47
  /**
48
48
  * A key pair for an actor who sends an activity.
49
+ *
50
+ * The private key type is parameterized so that Fedify can accept keys from
51
+ * `node:crypto` at its input boundaries while `SenderKeyPair` still exposes the
52
+ * ambient `CryptoKey` type by default.
53
+ * @template TKey The type of the private key.
49
54
  * @since 0.10.0
50
55
  */
51
- interface SenderKeyPair {
56
+ interface SenderKeyPair<TKey extends CryptoKeyLike = CryptoKey> {
52
57
  /**
53
58
  * The actor's private key to sign the request.
54
59
  */
55
- readonly privateKey: CryptoKey;
60
+ readonly privateKey: TKey;
56
61
  /**
57
62
  * The public key ID that corresponds to the private key.
58
63
  */
@@ -116,13 +121,19 @@ type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, ide
116
121
  /**
117
122
  * A callback that dispatches key pairs for an actor.
118
123
  *
124
+ * The returned key pairs may come from any supported runtime, including keys
125
+ * obtained from `node:crypto`'s Web Crypto API, so the key pair type is
126
+ * parameterized. It defaults to the ambient `CryptoKeyPair` type for
127
+ * compatibility with code that calls a dispatcher directly.
128
+ *
119
129
  * @template TContextData The context data to pass to the {@link Context}.
130
+ * @template TKeyPair The type of the key pairs the dispatcher returns.
120
131
  * @param context The context.
121
132
  * @param identifier The actor's internal identifier or username.
122
133
  * @returns The key pairs.
123
134
  * @since 0.10.0
124
135
  */
125
- type ActorKeyPairsDispatcher<TContextData> = (context: Context<TContextData>, identifier: string) => CryptoKeyPair[] | Promise<CryptoKeyPair[]>;
136
+ type ActorKeyPairsDispatcher<TContextData, TKeyPair extends CryptoKeyPairLike = CryptoKeyPair> = (context: Context<TContextData>, identifier: string) => TKeyPair[] | Promise<TKeyPair[]>;
126
137
  /**
127
138
  * A callback that maps a WebFinger username to the corresponding actor's
128
139
  * internal identifier, or `null` if the username is not found.
@@ -271,11 +282,11 @@ type OutboxListenerErrorHandler<TContextData> = (context: OutboxContext<TContext
271
282
  * not authorized.
272
283
  * @since 0.11.0
273
284
  */
274
- type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
285
+ type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
275
286
  identifier: string;
276
287
  } | {
277
288
  username: string;
278
- } | null | Promise<SenderKeyPair | {
289
+ } | null | Promise<SenderKeyPair<TKeyPair> | {
279
290
  identifier: string;
280
291
  } | {
281
292
  username: string;
@@ -1481,6 +1492,12 @@ interface FederationOptions<TContextData> {
1481
1492
  *
1482
1493
  * By default, the queue starts automatically.
1483
1494
  *
1495
+ * Automatic startup is best-effort: if a queue cannot start listening,
1496
+ * a warning is logged once per federation instance and the failed worker is
1497
+ * not retried, while an explicit {@link Federation.startQueue} call rejects.
1498
+ * Runtimes that consume the queue elsewhere, such as Cloudflare Workers with
1499
+ * {@link Federation.processQueuedTask}, should set this to `true`.
1500
+ *
1484
1501
  * @since 0.12.0
1485
1502
  */
1486
1503
  manuallyStartQueue?: boolean;
@@ -1654,7 +1671,7 @@ interface ActorCallbackSetters<TContextData> {
1654
1671
  * @returns The setters object so that settings can be chained.
1655
1672
  * @since 0.10.0
1656
1673
  */
1657
- setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
1674
+ setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
1658
1675
  /**
1659
1676
  * Sets the callback function that maps a WebFinger username to
1660
1677
  * the corresponding actor's identifier. If it's omitted, the identifier
@@ -1853,7 +1870,7 @@ interface InboxListenerSetters<TContextData> {
1853
1870
  * @returns The setters object so that settings can be chained.
1854
1871
  * @since 0.11.0
1855
1872
  */
1856
- setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
1873
+ setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
1857
1874
  /**
1858
1875
  * Configures the strategy for handling activity idempotency in inbox processing.
1859
1876
  *
@@ -2186,7 +2203,7 @@ interface Context<TContextData> {
2186
2203
  */
2187
2204
  getDocumentLoader(identity: {
2188
2205
  keyId: URL;
2189
- privateKey: CryptoKey;
2206
+ privateKey: CryptoKeyLike;
2190
2207
  }): DocumentLoader;
2191
2208
  /**
2192
2209
  * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
@@ -2299,7 +2316,7 @@ interface Context<TContextData> {
2299
2316
  * @param activity The activity to send.
2300
2317
  * @param options Options for sending the activity.
2301
2318
  */
2302
- sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
2319
+ sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2303
2320
  identifier: string;
2304
2321
  } | {
2305
2322
  username: string;
@@ -2447,6 +2464,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2447
2464
  * Gets the public key of the sender, if any exists and it is verified.
2448
2465
  * Otherwise, `null` is returned.
2449
2466
  *
2467
+ * Successful results are reused for this request regardless of the options.
2468
+ * Pending checks and `null` results are reused for the same effective
2469
+ * document and context loaders, including failed lookups. Rejected checks
2470
+ * can be retried. Shared work uses the first caller's tracer provider.
2471
+ *
2450
2472
  * This can be used for implementing [authorized fetch] (also known as
2451
2473
  * secure mode) in ActivityPub.
2452
2474
  *
@@ -2460,6 +2482,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2460
2482
  * Gets the public key of the sender, if any exists and it is verified.
2461
2483
  * Otherwise, `null` is returned.
2462
2484
  *
2485
+ * Successful results are reused for this request regardless of the options.
2486
+ * Pending checks and `null` results are reused for the same effective
2487
+ * document and context loaders, including failed lookups. Rejected checks
2488
+ * can be retried. Shared work uses the first caller's tracer provider.
2489
+ *
2463
2490
  * This can be used for implementing [authorized fetch] (also known as
2464
2491
  * secure mode) in ActivityPub.
2465
2492
  *
@@ -2479,6 +2506,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2479
2506
  * Gets the owner of the signed key, if any exists and it is verified.
2480
2507
  * Otherwise, `null` is returned.
2481
2508
  *
2509
+ * Verified keys and owners are reused for this request regardless of the
2510
+ * options. Pending checks are shared for the same effective document and
2511
+ * context loaders. A `null` result from an owner lookup after key
2512
+ * verification is retained for those loaders. A `null` result caused by
2513
+ * an unverified key is not retained, allowing an owner lookup after another
2514
+ * loader verifies the key. Rejected checks can be retried. Shared work
2515
+ * uses the first caller's tracer provider.
2516
+ *
2482
2517
  * This can be used for implementing [authorized fetch] (also known as
2483
2518
  * secure mode) in ActivityPub.
2484
2519
  *
@@ -2493,6 +2528,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
2493
2528
  * Gets the owner of the signed key, if any exists and it is verified.
2494
2529
  * Otherwise, `null` is returned.
2495
2530
  *
2531
+ * Verified keys and owners are reused for this request regardless of the
2532
+ * options. Pending checks are shared for the same effective document and
2533
+ * context loaders. A `null` result from an owner lookup after key
2534
+ * verification is retained for those loaders. A `null` result caused by
2535
+ * an unverified key is not retained, allowing an owner lookup after another
2536
+ * loader verifies the key. Rejected checks can be retried. Shared work
2537
+ * uses the first caller's tracer provider.
2538
+ *
2496
2539
  * This can be used for implementing [authorized fetch] (also known as
2497
2540
  * secure mode) in ActivityPub.
2498
2541
  *
@@ -2546,7 +2589,7 @@ interface InboxContext<TContextData> extends Context<TContextData> {
2546
2589
  * @param options Options for forwarding the activity.
2547
2590
  * @since 1.0.0
2548
2591
  */
2549
- forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2592
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2550
2593
  identifier: string;
2551
2594
  } | {
2552
2595
  username: string;
@@ -2604,7 +2647,7 @@ interface OutboxContext<TContextData> extends Context<TContextData> {
2604
2647
  * @param options Options for forwarding the activity.
2605
2648
  * @since 2.2.0
2606
2649
  */
2607
- forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2650
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2608
2651
  identifier: string;
2609
2652
  } | {
2610
2653
  username: string;
@@ -3,6 +3,6 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  //#region deno.json
5
5
  var name = "@fedify/fedify";
6
- var version = "2.2.19";
6
+ var version = "2.2.21";
7
7
  //#endregion
8
8
  export { version as n, name as t };
@@ -0,0 +1,125 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { s as validateCryptoKey } from "./key-Bhc8cQC7.mjs";
5
+ import { r as doubleKnockScoped } from "./http-B3wCvgu8.mjs";
6
+ import { curry } from "es-toolkit";
7
+ import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest } from "@fedify/vocab-runtime";
8
+ import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
9
+ import { getLogger } from "@logtape/logtape";
10
+ //#region src/utils/docloader.ts
11
+ const logger = getLogger([
12
+ "fedify",
13
+ "utils",
14
+ "docloader"
15
+ ]);
16
+ const DEFAULT_MAX_REDIRECTION = 20;
17
+ /**
18
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
19
+ * Note that an authenticated document loader intentionally does not cache
20
+ * the fetched documents.
21
+ * At most 20 HTTP redirects and alternate document links are followed in total
22
+ * per call. Revisiting a URL within that chain throws a {@link FetchError}.
23
+ * @param identity The identity to get the document loader for.
24
+ * The actor's key pair.
25
+ * @param options The options for the document loader.
26
+ * @returns The authenticated document loader.
27
+ * @throws {TypeError} If the key is invalid or unsupported.
28
+ * @since 0.4.0
29
+ */
30
+ function getAuthenticatedDocumentLoader(identity, options = {}) {
31
+ return createAuthenticatedDocumentLoader(identity, options);
32
+ }
33
+ /**
34
+ * The placeholder that the alternate document callback of
35
+ * `getRemoteDocument()` returns, so that the alternate document is loaded
36
+ * after the current hop is closed.
37
+ */
38
+ const ALTERNATE_PLACEHOLDER = Object.freeze({
39
+ contextUrl: null,
40
+ document: null,
41
+ documentUrl: "about:blank"
42
+ });
43
+ /**
44
+ * The implementation of {@link getAuthenticatedDocumentLoader}. This is not
45
+ * exported from any entry point.
46
+ * @param identity The identity to get the document loader for.
47
+ * @param options The options for the document loader.
48
+ * @param deps The dependencies, for tests.
49
+ * @returns The authenticated document loader.
50
+ * @throws {TypeError} If the key is invalid or unsupported.
51
+ */
52
+ function createAuthenticatedDocumentLoader(identity, { allowPrivateAddress, maxRedirection, userAgent, specDeterminer, tracerProvider } = {}, deps = {}) {
53
+ validateCryptoKey(identity.privateKey);
54
+ async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
55
+ options?.signal?.throwIfAborted();
56
+ let currentUrl = new URL(url).href;
57
+ validateUrl(currentUrl);
58
+ visited.add(currentUrl);
59
+ const originalRequest = createActivityPubRequest(currentUrl, { userAgent });
60
+ function follow(nextUrl) {
61
+ options?.signal?.throwIfAborted();
62
+ if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
63
+ if (visited.has(nextUrl)) throw new FetchError(currentUrl, `Redirect loop detected: ${nextUrl}`);
64
+ redirected++;
65
+ }
66
+ const result = await doubleKnockScoped(originalRequest, identity, {
67
+ maxRedirection,
68
+ specDeterminer,
69
+ log: curry(logRequest)(logger),
70
+ tracerProvider,
71
+ signal: options?.signal,
72
+ validateRedirect: (nextUrl) => {
73
+ follow(nextUrl);
74
+ validateUrl(nextUrl);
75
+ visited.add(nextUrl);
76
+ currentUrl = nextUrl;
77
+ }
78
+ }, (hopUrl) => openHop(hopUrl, options?.signal), async (response) => {
79
+ let alternateUrl;
80
+ const document = await getRemoteDocument(currentUrl, response, (url) => {
81
+ alternateUrl = url;
82
+ return Promise.resolve(ALTERNATE_PLACEHOLDER);
83
+ });
84
+ if (alternateUrl == null) return { document };
85
+ if (!response.bodyUsed && response.body?.locked !== true) response.body?.cancel().catch((error) => {
86
+ logger.debug("Failed to cancel the response body from {url}: {error}", {
87
+ url: currentUrl,
88
+ error
89
+ });
90
+ });
91
+ return { alternateUrl };
92
+ });
93
+ if ("document" in result) return result.document;
94
+ follow(result.alternateUrl);
95
+ return load(result.alternateUrl, options, redirected, visited);
96
+ }
97
+ function openUnvalidatedHop(url, signal) {
98
+ if (deps.openHop != null) return deps.openHop(url);
99
+ return allowPrivateAddress ? openDirectFetch(url) : openPublicFetch(url, { signal });
100
+ }
101
+ async function openHop(url, signal) {
102
+ try {
103
+ return await openUnvalidatedHop(url, signal);
104
+ } catch (error) {
105
+ if (error instanceof UrlError) if (error.reason === "dns") logger.debug("DNS lookup failed for {url}", {
106
+ url,
107
+ error
108
+ });
109
+ else logger.error("Disallowed private URL: {url}", {
110
+ url,
111
+ error
112
+ });
113
+ throw error;
114
+ }
115
+ }
116
+ function validateUrl(url) {
117
+ const parsedUrl = new URL(url);
118
+ const protocol = parsedUrl.protocol;
119
+ if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
120
+ if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new UrlError("URLs with credentials are not allowed");
121
+ }
122
+ return (url, options) => load(url, options);
123
+ }
124
+ //#endregion
125
+ export { getAuthenticatedDocumentLoader as n, createAuthenticatedDocumentLoader as t };
@@ -0,0 +1,2 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";