@fedify/fedify 2.1.30 → 2.1.32
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.
- package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
- package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
- package/dist/callback-BARPujV7.d.mts +2388 -0
- package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +254 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
- package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
- package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
- package/dist/docloader-DUXr9k_O.mjs +124 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +280 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1559 -26
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
- package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
- package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
- package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
- package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
- package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
- package/dist/ld-signature-DoZcbsZR.mjs +23 -0
- package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
- package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
- package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
- package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
- package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
- package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
- package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
- package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
- package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
- package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
- package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -19
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
- package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
- package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
- package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
- package/dist/send-BGSfQkIK.mjs +416 -0
- package/dist/sig/http.test.mjs +506 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +95 -3
- package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2177
- package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
- package/dist/utils/docloader.test.mjs +316 -32
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
- package/dist/docloader-OLWc7P2D.mjs +0 -82
- package/dist/send-BHIt_8ia.mjs +0 -260
- /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
- /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
|
@@ -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-HvthQAHr.mjs";
|
|
7
|
-
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-
|
|
7
|
+
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-DiquMgtt.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,11 +1,11 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-
|
|
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, 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:
|
|
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) =>
|
|
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.
|
|
@@ -252,11 +263,11 @@ type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: E
|
|
|
252
263
|
* not authorized.
|
|
253
264
|
* @since 0.11.0
|
|
254
265
|
*/
|
|
255
|
-
type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
|
|
266
|
+
type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
|
|
256
267
|
identifier: string;
|
|
257
268
|
} | {
|
|
258
269
|
username: string;
|
|
259
|
-
} | null | Promise<SenderKeyPair | {
|
|
270
|
+
} | null | Promise<SenderKeyPair<TKeyPair> | {
|
|
260
271
|
identifier: string;
|
|
261
272
|
} | {
|
|
262
273
|
username: string;
|
|
@@ -1425,6 +1436,12 @@ interface FederationOptions<TContextData> {
|
|
|
1425
1436
|
*
|
|
1426
1437
|
* By default, the queue starts automatically.
|
|
1427
1438
|
*
|
|
1439
|
+
* Automatic startup is best-effort: if a queue cannot start listening,
|
|
1440
|
+
* a warning is logged once per federation instance and the failed worker is
|
|
1441
|
+
* not retried, while an explicit {@link Federation.startQueue} call rejects.
|
|
1442
|
+
* Runtimes that consume the queue elsewhere, such as Cloudflare Workers with
|
|
1443
|
+
* {@link Federation.processQueuedTask}, should set this to `true`.
|
|
1444
|
+
*
|
|
1428
1445
|
* @since 0.12.0
|
|
1429
1446
|
*/
|
|
1430
1447
|
manuallyStartQueue?: boolean;
|
|
@@ -1598,7 +1615,7 @@ interface ActorCallbackSetters<TContextData> {
|
|
|
1598
1615
|
* @returns The setters object so that settings can be chained.
|
|
1599
1616
|
* @since 0.10.0
|
|
1600
1617
|
*/
|
|
1601
|
-
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
|
|
1618
|
+
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
|
|
1602
1619
|
/**
|
|
1603
1620
|
* Sets the callback function that maps a WebFinger username to
|
|
1604
1621
|
* the corresponding actor's identifier. If it's omitted, the identifier
|
|
@@ -1765,7 +1782,7 @@ interface InboxListenerSetters<TContextData> {
|
|
|
1765
1782
|
* @returns The setters object so that settings can be chained.
|
|
1766
1783
|
* @since 0.11.0
|
|
1767
1784
|
*/
|
|
1768
|
-
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
|
|
1785
|
+
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
|
|
1769
1786
|
/**
|
|
1770
1787
|
* Configures the strategy for handling activity idempotency in inbox processing.
|
|
1771
1788
|
*
|
|
@@ -2098,7 +2115,7 @@ interface Context<TContextData> {
|
|
|
2098
2115
|
*/
|
|
2099
2116
|
getDocumentLoader(identity: {
|
|
2100
2117
|
keyId: URL;
|
|
2101
|
-
privateKey:
|
|
2118
|
+
privateKey: CryptoKeyLike;
|
|
2102
2119
|
}): DocumentLoader;
|
|
2103
2120
|
/**
|
|
2104
2121
|
* Looks up an ActivityStreams object by its URI (including `acct:` URIs)
|
|
@@ -2211,7 +2228,7 @@ interface Context<TContextData> {
|
|
|
2211
2228
|
* @param activity The activity to send.
|
|
2212
2229
|
* @param options Options for sending the activity.
|
|
2213
2230
|
*/
|
|
2214
|
-
sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
|
|
2231
|
+
sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
|
|
2215
2232
|
identifier: string;
|
|
2216
2233
|
} | {
|
|
2217
2234
|
username: string;
|
|
@@ -2306,6 +2323,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2306
2323
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
2307
2324
|
* Otherwise, `null` is returned.
|
|
2308
2325
|
*
|
|
2326
|
+
* Successful results are reused for this request regardless of the options.
|
|
2327
|
+
* Pending checks and `null` results are reused for the same effective
|
|
2328
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
2329
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
2330
|
+
*
|
|
2309
2331
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2310
2332
|
* secure mode) in ActivityPub.
|
|
2311
2333
|
*
|
|
@@ -2319,6 +2341,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2319
2341
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
2320
2342
|
* Otherwise, `null` is returned.
|
|
2321
2343
|
*
|
|
2344
|
+
* Successful results are reused for this request regardless of the options.
|
|
2345
|
+
* Pending checks and `null` results are reused for the same effective
|
|
2346
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
2347
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
2348
|
+
*
|
|
2322
2349
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2323
2350
|
* secure mode) in ActivityPub.
|
|
2324
2351
|
*
|
|
@@ -2338,6 +2365,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2338
2365
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
2339
2366
|
* Otherwise, `null` is returned.
|
|
2340
2367
|
*
|
|
2368
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
2369
|
+
* options. Pending checks are shared for the same effective document and
|
|
2370
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
2371
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
2372
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
2373
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
2374
|
+
* uses the first caller's tracer provider.
|
|
2375
|
+
*
|
|
2341
2376
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2342
2377
|
* secure mode) in ActivityPub.
|
|
2343
2378
|
*
|
|
@@ -2352,6 +2387,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2352
2387
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
2353
2388
|
* Otherwise, `null` is returned.
|
|
2354
2389
|
*
|
|
2390
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
2391
|
+
* options. Pending checks are shared for the same effective document and
|
|
2392
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
2393
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
2394
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
2395
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
2396
|
+
* uses the first caller's tracer provider.
|
|
2397
|
+
*
|
|
2355
2398
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2356
2399
|
* secure mode) in ActivityPub.
|
|
2357
2400
|
*
|
|
@@ -2405,7 +2448,7 @@ interface InboxContext<TContextData> extends Context<TContextData> {
|
|
|
2405
2448
|
* @param options Options for forwarding the activity.
|
|
2406
2449
|
* @since 1.0.0
|
|
2407
2450
|
*/
|
|
2408
|
-
forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
|
|
2451
|
+
forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
|
|
2409
2452
|
identifier: string;
|
|
2410
2453
|
} | {
|
|
2411
2454
|
username: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-
|
|
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, 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:
|
|
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) =>
|
|
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.
|
|
@@ -252,11 +263,11 @@ type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: E
|
|
|
252
263
|
* not authorized.
|
|
253
264
|
* @since 0.11.0
|
|
254
265
|
*/
|
|
255
|
-
type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
|
|
266
|
+
type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
|
|
256
267
|
identifier: string;
|
|
257
268
|
} | {
|
|
258
269
|
username: string;
|
|
259
|
-
} | null | Promise<SenderKeyPair | {
|
|
270
|
+
} | null | Promise<SenderKeyPair<TKeyPair> | {
|
|
260
271
|
identifier: string;
|
|
261
272
|
} | {
|
|
262
273
|
username: string;
|
|
@@ -1425,6 +1436,12 @@ interface FederationOptions<TContextData> {
|
|
|
1425
1436
|
*
|
|
1426
1437
|
* By default, the queue starts automatically.
|
|
1427
1438
|
*
|
|
1439
|
+
* Automatic startup is best-effort: if a queue cannot start listening,
|
|
1440
|
+
* a warning is logged once per federation instance and the failed worker is
|
|
1441
|
+
* not retried, while an explicit {@link Federation.startQueue} call rejects.
|
|
1442
|
+
* Runtimes that consume the queue elsewhere, such as Cloudflare Workers with
|
|
1443
|
+
* {@link Federation.processQueuedTask}, should set this to `true`.
|
|
1444
|
+
*
|
|
1428
1445
|
* @since 0.12.0
|
|
1429
1446
|
*/
|
|
1430
1447
|
manuallyStartQueue?: boolean;
|
|
@@ -1598,7 +1615,7 @@ interface ActorCallbackSetters<TContextData> {
|
|
|
1598
1615
|
* @returns The setters object so that settings can be chained.
|
|
1599
1616
|
* @since 0.10.0
|
|
1600
1617
|
*/
|
|
1601
|
-
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
|
|
1618
|
+
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
|
|
1602
1619
|
/**
|
|
1603
1620
|
* Sets the callback function that maps a WebFinger username to
|
|
1604
1621
|
* the corresponding actor's identifier. If it's omitted, the identifier
|
|
@@ -1765,7 +1782,7 @@ interface InboxListenerSetters<TContextData> {
|
|
|
1765
1782
|
* @returns The setters object so that settings can be chained.
|
|
1766
1783
|
* @since 0.11.0
|
|
1767
1784
|
*/
|
|
1768
|
-
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
|
|
1785
|
+
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
|
|
1769
1786
|
/**
|
|
1770
1787
|
* Configures the strategy for handling activity idempotency in inbox processing.
|
|
1771
1788
|
*
|
|
@@ -2098,7 +2115,7 @@ interface Context<TContextData> {
|
|
|
2098
2115
|
*/
|
|
2099
2116
|
getDocumentLoader(identity: {
|
|
2100
2117
|
keyId: URL;
|
|
2101
|
-
privateKey:
|
|
2118
|
+
privateKey: CryptoKeyLike;
|
|
2102
2119
|
}): DocumentLoader;
|
|
2103
2120
|
/**
|
|
2104
2121
|
* Looks up an ActivityStreams object by its URI (including `acct:` URIs)
|
|
@@ -2211,7 +2228,7 @@ interface Context<TContextData> {
|
|
|
2211
2228
|
* @param activity The activity to send.
|
|
2212
2229
|
* @param options Options for sending the activity.
|
|
2213
2230
|
*/
|
|
2214
|
-
sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
|
|
2231
|
+
sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
|
|
2215
2232
|
identifier: string;
|
|
2216
2233
|
} | {
|
|
2217
2234
|
username: string;
|
|
@@ -2306,6 +2323,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2306
2323
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
2307
2324
|
* Otherwise, `null` is returned.
|
|
2308
2325
|
*
|
|
2326
|
+
* Successful results are reused for this request regardless of the options.
|
|
2327
|
+
* Pending checks and `null` results are reused for the same effective
|
|
2328
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
2329
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
2330
|
+
*
|
|
2309
2331
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2310
2332
|
* secure mode) in ActivityPub.
|
|
2311
2333
|
*
|
|
@@ -2319,6 +2341,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2319
2341
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
2320
2342
|
* Otherwise, `null` is returned.
|
|
2321
2343
|
*
|
|
2344
|
+
* Successful results are reused for this request regardless of the options.
|
|
2345
|
+
* Pending checks and `null` results are reused for the same effective
|
|
2346
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
2347
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
2348
|
+
*
|
|
2322
2349
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2323
2350
|
* secure mode) in ActivityPub.
|
|
2324
2351
|
*
|
|
@@ -2338,6 +2365,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2338
2365
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
2339
2366
|
* Otherwise, `null` is returned.
|
|
2340
2367
|
*
|
|
2368
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
2369
|
+
* options. Pending checks are shared for the same effective document and
|
|
2370
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
2371
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
2372
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
2373
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
2374
|
+
* uses the first caller's tracer provider.
|
|
2375
|
+
*
|
|
2341
2376
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2342
2377
|
* secure mode) in ActivityPub.
|
|
2343
2378
|
*
|
|
@@ -2352,6 +2387,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
2352
2387
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
2353
2388
|
* Otherwise, `null` is returned.
|
|
2354
2389
|
*
|
|
2390
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
2391
|
+
* options. Pending checks are shared for the same effective document and
|
|
2392
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
2393
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
2394
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
2395
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
2396
|
+
* uses the first caller's tracer provider.
|
|
2397
|
+
*
|
|
2355
2398
|
* This can be used for implementing [authorized fetch] (also known as
|
|
2356
2399
|
* secure mode) in ActivityPub.
|
|
2357
2400
|
*
|
|
@@ -2405,7 +2448,7 @@ interface InboxContext<TContextData> extends Context<TContextData> {
|
|
|
2405
2448
|
* @param options Options for forwarding the activity.
|
|
2406
2449
|
* @since 1.0.0
|
|
2407
2450
|
*/
|
|
2408
|
-
forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
|
|
2451
|
+
forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
|
|
2409
2452
|
identifier: string;
|
|
2410
2453
|
} | {
|
|
2411
2454
|
username: string;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { s as validateCryptoKey } from "./key-Dai3f5yI.mjs";
|
|
5
|
+
import { r as doubleKnockScoped } from "./http-HX6wVyJh.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, 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
|
+
specDeterminer,
|
|
68
|
+
log: curry(logRequest)(logger),
|
|
69
|
+
tracerProvider,
|
|
70
|
+
signal: options?.signal,
|
|
71
|
+
validateRedirect: (nextUrl) => {
|
|
72
|
+
follow(nextUrl);
|
|
73
|
+
validateUrl(nextUrl);
|
|
74
|
+
visited.add(nextUrl);
|
|
75
|
+
currentUrl = nextUrl;
|
|
76
|
+
}
|
|
77
|
+
}, (hopUrl) => openHop(hopUrl, options?.signal), async (response) => {
|
|
78
|
+
let alternateUrl;
|
|
79
|
+
const document = await getRemoteDocument(currentUrl, response, (url) => {
|
|
80
|
+
alternateUrl = url;
|
|
81
|
+
return Promise.resolve(ALTERNATE_PLACEHOLDER);
|
|
82
|
+
});
|
|
83
|
+
if (alternateUrl == null) return { document };
|
|
84
|
+
if (!response.bodyUsed && response.body?.locked !== true) response.body?.cancel().catch((error) => {
|
|
85
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
86
|
+
url: currentUrl,
|
|
87
|
+
error
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return { alternateUrl };
|
|
91
|
+
});
|
|
92
|
+
if ("document" in result) return result.document;
|
|
93
|
+
follow(result.alternateUrl);
|
|
94
|
+
return load(result.alternateUrl, options, redirected, visited);
|
|
95
|
+
}
|
|
96
|
+
function openUnvalidatedHop(url, signal) {
|
|
97
|
+
if (deps.openHop != null) return deps.openHop(url);
|
|
98
|
+
return allowPrivateAddress ? openDirectFetch(url) : openPublicFetch(url, { signal });
|
|
99
|
+
}
|
|
100
|
+
async function openHop(url, signal) {
|
|
101
|
+
try {
|
|
102
|
+
return await openUnvalidatedHop(url, signal);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error instanceof UrlError) if (error.reason === "dns") logger.debug("DNS lookup failed for {url}", {
|
|
105
|
+
url,
|
|
106
|
+
error
|
|
107
|
+
});
|
|
108
|
+
else logger.error("Disallowed private URL: {url}", {
|
|
109
|
+
url,
|
|
110
|
+
error
|
|
111
|
+
});
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function validateUrl(url) {
|
|
116
|
+
const parsedUrl = new URL(url);
|
|
117
|
+
const protocol = parsedUrl.protocol;
|
|
118
|
+
if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
|
|
119
|
+
if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new UrlError("URLs with credentials are not allowed");
|
|
120
|
+
}
|
|
121
|
+
return (url, options) => load(url, options);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { getAuthenticatedDocumentLoader as n, createAuthenticatedDocumentLoader as t };
|