@fedify/fedify 2.4.6-dev.2628 → 2.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
- package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
- package/dist/callback-DPDs_dxC.d.mts +5280 -0
- package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
- package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
- package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.cjs +1 -1
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/mod.js +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
- package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
- package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
- package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
- 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/compound-fanout.test.mjs +4 -4
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +206 -14
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1188 -13
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +4 -4
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +5 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +293 -3
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
- package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
- package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
- package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
- package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
- package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
- package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
- package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
- package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
- package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
- package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
- package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
- package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
- package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +6 -6
- package/dist/nodeinfo/client.test.mjs +432 -4
- 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/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
- package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
- package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
- package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
- package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/portable-verifier-CPA86vIP.js +22 -0
- package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
- package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
- package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +162 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +572 -7
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- 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/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +100 -6
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
- package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
- package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
- package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- 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/dist/utils/portable-verifier.test.d.mts +2 -0
- package/dist/utils/portable-verifier.test.mjs +126 -0
- package/package.json +6 -6
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
import { t as __exportAll } from "./rolldown-runtime-BC-Eo5Mj.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
8
|
-
import { n as
|
|
4
|
+
import { t as getDefaultPortableObjectVerifier } from "./portable-verifier-CPA86vIP.js";
|
|
5
|
+
import { r as getDefaultActivityTransformers } from "./transformers-BlJ53iKs.js";
|
|
6
|
+
import { $ as instrumentDocumentLoader, A as hasSignatureLike, At as isPortableId, C as assertSafeJsonLd, Ct as getAuthenticationOrigin, D as describeSignatureShape, Dt as getRawCanonicalPortableId, Et as getPortableDid, F as verifyCompactJsonLd, Ft as name, G as validateCryptoKey, It as version, M as isClearlyMalformedContextReference, Mt as isPortableUri, N as isInvalidUrlTypeError, Nt as isSameObjectId, O as detachSignature, Ot as hasPortableActor, P as signJsonLd, Q as getRemoteHost, R as wrapContextLoaderForJsonLd, S as InvalidContextReferenceError, St as verificationObservation, T as compactJsonLd, Tt as getGatewayKeyBase, W as importJwk, X as getDurationMs, Z as getFederationMetrics, _ as verifyObject, _t as normalizeAttachmentArrays$1, at as recordCollectionTotalItems, b as verifyPortableObjectProofWithRoot, bt as observeAttempt, c as verifyRequestDetailed, ct as recordInboxActivity, d as InvalidPortableObjectIdError, dt as recordWebFingerHandle, et as isAbortError, f as classifyFep2277CoreType, ft as registerQueueDepthGauge, g as verifyMapLocalProof, h as signObject, i as selectRequestSignature, it as recordCollectionRequest, j as hasVerifiableSignature, jt as isPortableKeyId, k as getNormalizationContextLoader, kt as isCompatibleKeyId, lt as recordOutboxActivity, m as hasProofLike, n as listRequestSignatures, nt as recordCollectionDispatchDuration, o as validateMaxSignatures, pt as formatAcceptSignature, q as MAX_PORTABLE_KEY_TTL, r as parseRfc9421SignatureInput, rt as recordCollectionPageItems, s as verifyRequest, st as recordFanoutRecipients, t as doubleKnockScoped, tt as recordCircuitBreakerStateChange, ut as recordOutboxEnqueue, v as verifyPortableObjectProof, vt as normalizeOutgoingActivityJsonLd, wt as getCanonicalPortableId, xt as snapshotKey, y as verifyPortableObjectProofPolicy, yt as preloadedOnlyDocumentLoader, z as exportJwk } from "./http-BwgldAIk.js";
|
|
7
|
+
import { a as MAX_BODY_SIZE, i as BodyTooLargeError, n as getNodeInfo, o as readBoundedText, t as nodeInfoToJson } from "./types-BbCbtwZp.js";
|
|
8
|
+
import { n as doesActorOwnKey, r as getKeyOwner, t as verifyPortableObject } from "./portable-collection-M6d5I5JQ.js";
|
|
9
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-C-5yfTw-.js";
|
|
9
10
|
import { getLogger, withContext } from "@logtape/logtape";
|
|
10
11
|
import { Router, RouterError, assertPath } from "@fedify/uri-template";
|
|
11
|
-
import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, PUBLIC_COLLECTION, Tombstone, getTypeId, isActor, lookupObject, traverseCollection } from "@fedify/vocab";
|
|
12
|
+
import { Activity, Collection, CollectionPage, CryptographicKey, DataIntegrityProof, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, PUBLIC_COLLECTION, Tombstone, getTypeId, isActor, lookupObject, traverseCollection } from "@fedify/vocab";
|
|
12
13
|
import { SpanKind, SpanStatusCode, context, metrics, propagation, trace } from "@opentelemetry/api";
|
|
13
|
-
import { FetchError, UrlError, canonicalizePortableUri, decodeMultibase, formatIri, fromCompatibleEf61Id, getDocumentLoader, getFe34Origin, isGatewayUrl, parseDigestMultibase, parseHashlink, parseIri, preloadedContexts, resolveDocumentLoaderTimeout, toCompatibleEf61Id } from "@fedify/vocab-runtime";
|
|
14
|
+
import { FetchError, UrlError, canonicalizePortableUri, decodeMultibase, encodeMultibase, formatIri, fromCompatibleEf61Id, getDocumentLoader, getFe34Origin, isGatewayUrl, parseDigestMultibase, parseHashlink, parseIri, preloadedContexts, resolveDocumentLoaderTimeout, toCompatibleEf61Id } from "@fedify/vocab-runtime";
|
|
14
15
|
import { getPortableGatewayCandidates, isCompatibleEf61Iri } from "@fedify/vocab-runtime/internal/portable-dereference";
|
|
15
16
|
import { encodeHex } from "byte-encodings/hex";
|
|
16
17
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
17
18
|
import { uniq } from "es-toolkit";
|
|
19
|
+
import { asCryptoKey, openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
20
|
+
import serialize from "json-canon";
|
|
18
21
|
import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_HEADER, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
|
|
19
|
-
import {
|
|
22
|
+
import { normalizeDateTimeLiteral } from "@fedify/vocab-runtime/temporal";
|
|
20
23
|
import { lookupWebFinger } from "@fedify/webfinger";
|
|
21
24
|
import { DataPointType, MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
|
|
22
25
|
import { parse, stringifyAsync } from "devalue";
|
|
@@ -1558,6 +1561,17 @@ var InboxObservation = class {
|
|
|
1558
1561
|
}
|
|
1559
1562
|
};
|
|
1560
1563
|
//#endregion
|
|
1564
|
+
//#region src/compat/attachment-arrays.ts
|
|
1565
|
+
/**
|
|
1566
|
+
* Applies the shared attachment workaround to served documents without
|
|
1567
|
+
* rewriting any document that contains a semantic proof or LD signature.
|
|
1568
|
+
* RDF equivalence alone cannot preserve JCS signatures.
|
|
1569
|
+
* @internal
|
|
1570
|
+
*/
|
|
1571
|
+
function normalizeAttachmentArrays(document, contextLoader) {
|
|
1572
|
+
return normalizeAttachmentArrays$1(document, contextLoader, { preserveSecuredDocuments: true });
|
|
1573
|
+
}
|
|
1574
|
+
//#endregion
|
|
1561
1575
|
//#region src/sig/compound-proof.ts
|
|
1562
1576
|
const textEncoder = new TextEncoder();
|
|
1563
1577
|
/**
|
|
@@ -3619,7 +3633,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
3619
3633
|
* @param parameters The parameters for sending the activity.
|
|
3620
3634
|
* See also {@link SendActivityParameters}.
|
|
3621
3635
|
* @param deps The dependencies, for tests.
|
|
3622
|
-
* @throws {
|
|
3636
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
3637
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
3623
3638
|
*/
|
|
3624
3639
|
function sendActivity(options, deps = {}) {
|
|
3625
3640
|
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
@@ -3678,6 +3693,24 @@ async function sendActivityThroughGateways(parameters, inboxes) {
|
|
|
3678
3693
|
throw lastError;
|
|
3679
3694
|
}
|
|
3680
3695
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
3696
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
3697
|
+
function raceWithAbort(promise, signal) {
|
|
3698
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
3699
|
+
return new Promise((resolve, reject) => {
|
|
3700
|
+
const onAbort = () => {
|
|
3701
|
+
signal.removeEventListener("abort", onAbort);
|
|
3702
|
+
reject(signal.reason);
|
|
3703
|
+
};
|
|
3704
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3705
|
+
promise.then((value) => {
|
|
3706
|
+
signal.removeEventListener("abort", onAbort);
|
|
3707
|
+
resolve(value);
|
|
3708
|
+
}, (error) => {
|
|
3709
|
+
signal.removeEventListener("abort", onAbort);
|
|
3710
|
+
reject(error);
|
|
3711
|
+
});
|
|
3712
|
+
});
|
|
3713
|
+
}
|
|
3681
3714
|
function getActivityActorId(activity) {
|
|
3682
3715
|
if (!isRecord(activity)) return void 0;
|
|
3683
3716
|
return getIdValue(activity.actor);
|
|
@@ -3697,7 +3730,7 @@ function getIdValue(value) {
|
|
|
3697
3730
|
function isRecord(value) {
|
|
3698
3731
|
return typeof value === "object" && value != null;
|
|
3699
3732
|
}
|
|
3700
|
-
async function readLimitedResponseBody(response, maxBytes) {
|
|
3733
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
3701
3734
|
if (response.body == null) return "";
|
|
3702
3735
|
const reader = response.body.getReader();
|
|
3703
3736
|
const decoder = new TextDecoder();
|
|
@@ -3706,7 +3739,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
3706
3739
|
let truncated = false;
|
|
3707
3740
|
try {
|
|
3708
3741
|
while (true) {
|
|
3709
|
-
|
|
3742
|
+
signal.throwIfAborted();
|
|
3743
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
3710
3744
|
if (done) break;
|
|
3711
3745
|
if (totalBytes + value.length > maxBytes) {
|
|
3712
3746
|
const remaining = maxBytes - totalBytes;
|
|
@@ -3718,8 +3752,10 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
3718
3752
|
totalBytes += value.length;
|
|
3719
3753
|
}
|
|
3720
3754
|
} finally {
|
|
3721
|
-
if (truncated) reader.cancel().catch(() => {});
|
|
3722
|
-
|
|
3755
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
3756
|
+
try {
|
|
3757
|
+
reader.releaseLock();
|
|
3758
|
+
} catch (_) {}
|
|
3723
3759
|
}
|
|
3724
3760
|
let result = chunks.join("");
|
|
3725
3761
|
if (truncated) result += "… (truncated)";
|
|
@@ -3734,11 +3770,30 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3734
3770
|
const federationMetrics = getFederationMetrics(meterProvider);
|
|
3735
3771
|
const started = performance.now();
|
|
3736
3772
|
let deliverySuccess = false;
|
|
3737
|
-
const
|
|
3773
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
3774
|
+
const controller = new AbortController();
|
|
3775
|
+
const { signal } = controller;
|
|
3776
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
3777
|
+
function timeoutFailure(error) {
|
|
3778
|
+
if (!signal.aborted || error instanceof SendActivityError) return error;
|
|
3779
|
+
const failure = new FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
3780
|
+
failure.cause = signal.reason;
|
|
3781
|
+
return failure;
|
|
3782
|
+
}
|
|
3783
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? openDirectFetch : (url) => openPublicFetch(url, { signal }));
|
|
3738
3784
|
async function openHop(url) {
|
|
3739
3785
|
let session;
|
|
3740
3786
|
try {
|
|
3741
|
-
|
|
3787
|
+
signal.throwIfAborted();
|
|
3788
|
+
const opening = openUnvalidatedHop(url);
|
|
3789
|
+
opening.then((lateSession) => {
|
|
3790
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
3791
|
+
}, () => {});
|
|
3792
|
+
session = await raceWithAbort(opening, signal);
|
|
3793
|
+
if (signal.aborted) {
|
|
3794
|
+
closeAfterError(session, logger);
|
|
3795
|
+
signal.throwIfAborted();
|
|
3796
|
+
}
|
|
3742
3797
|
} catch (error) {
|
|
3743
3798
|
if (error instanceof UrlError && error.reason === "dns") {
|
|
3744
3799
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -3761,8 +3816,15 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3761
3816
|
try {
|
|
3762
3817
|
initialSession = await openHop(inbox.href);
|
|
3763
3818
|
} catch (error) {
|
|
3764
|
-
|
|
3765
|
-
|
|
3819
|
+
const failure = timeoutFailure(error);
|
|
3820
|
+
if (failure instanceof FetchError) federationMetrics.recordDelivery(inbox, getDurationMs(started), false, activityType);
|
|
3821
|
+
if (signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
3822
|
+
activityId,
|
|
3823
|
+
inbox: inbox.href,
|
|
3824
|
+
error: failure
|
|
3825
|
+
});
|
|
3826
|
+
clearTimeout(timer);
|
|
3827
|
+
throw failure;
|
|
3766
3828
|
}
|
|
3767
3829
|
let initialPending = true;
|
|
3768
3830
|
const openDeliveryHop = (url) => {
|
|
@@ -3779,7 +3841,8 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3779
3841
|
method: "POST",
|
|
3780
3842
|
headers,
|
|
3781
3843
|
body: JSON.stringify(activity),
|
|
3782
|
-
redirect: "manual"
|
|
3844
|
+
redirect: "manual",
|
|
3845
|
+
signal
|
|
3783
3846
|
});
|
|
3784
3847
|
let rsaKey = null;
|
|
3785
3848
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -3798,13 +3861,35 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3798
3861
|
}))
|
|
3799
3862
|
});
|
|
3800
3863
|
let outcome;
|
|
3864
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
3865
|
+
determineSpec(origin) {
|
|
3866
|
+
signal.throwIfAborted();
|
|
3867
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
3868
|
+
},
|
|
3869
|
+
rememberSpec(origin, spec) {
|
|
3870
|
+
if (signal.aborted) return;
|
|
3871
|
+
try {
|
|
3872
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3873
|
+
origin,
|
|
3874
|
+
error
|
|
3875
|
+
}));
|
|
3876
|
+
} catch (error) {
|
|
3877
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3878
|
+
origin,
|
|
3879
|
+
error
|
|
3880
|
+
});
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3801
3884
|
try {
|
|
3802
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox)) : await doubleKnockScoped(request, rsaKey, {
|
|
3885
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await doubleKnockScoped(request, rsaKey, {
|
|
3803
3886
|
tracerProvider,
|
|
3804
|
-
specDeterminer
|
|
3805
|
-
|
|
3887
|
+
specDeterminer: boundedSpecDeterminer,
|
|
3888
|
+
signal
|
|
3889
|
+
}, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
3806
3890
|
} catch (error) {
|
|
3807
|
-
const
|
|
3891
|
+
const boundedError = timeoutFailure(error);
|
|
3892
|
+
const failure = boundedError instanceof FetchError || boundedError instanceof UrlError ? boundedError : createFetchError(inbox.href, boundedError);
|
|
3808
3893
|
logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
3809
3894
|
activityId,
|
|
3810
3895
|
inbox: inbox.href,
|
|
@@ -3838,6 +3923,7 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3838
3923
|
federationMetrics.recordDelivery(inbox, getDurationMs(started), deliverySuccess, activityType);
|
|
3839
3924
|
}
|
|
3840
3925
|
} finally {
|
|
3926
|
+
clearTimeout(timer);
|
|
3841
3927
|
if (initialPending) await initialSession.close();
|
|
3842
3928
|
}
|
|
3843
3929
|
}
|
|
@@ -3869,17 +3955,18 @@ function cancelResponseBody(response, url) {
|
|
|
3869
3955
|
* session is open: the body of a successful response is cancelled, and at
|
|
3870
3956
|
* most 1 KiB of an error response body is read.
|
|
3871
3957
|
*/
|
|
3872
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
3958
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
3873
3959
|
if (response.ok) {
|
|
3874
3960
|
cancelResponseBody(response, response.url || inbox.href);
|
|
3875
3961
|
return { ok: true };
|
|
3876
3962
|
}
|
|
3877
3963
|
let error;
|
|
3878
3964
|
try {
|
|
3879
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
3965
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
3880
3966
|
} catch (_) {
|
|
3881
3967
|
error = "";
|
|
3882
3968
|
}
|
|
3969
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
3883
3970
|
return {
|
|
3884
3971
|
ok: false,
|
|
3885
3972
|
status: response.status,
|
|
@@ -3899,7 +3986,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
3899
3986
|
* @param consume The function to consume the final response.
|
|
3900
3987
|
* @returns The value returned by `consume`.
|
|
3901
3988
|
*/
|
|
3902
|
-
async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
3989
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
3903
3990
|
const logger = getLogger([
|
|
3904
3991
|
"fedify",
|
|
3905
3992
|
"federation",
|
|
@@ -3907,10 +3994,14 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
3907
3994
|
]);
|
|
3908
3995
|
let body = await request.clone().text();
|
|
3909
3996
|
for (let redirects = 0;; redirects++) {
|
|
3997
|
+
signal?.throwIfAborted();
|
|
3910
3998
|
const session = await openHop(request.url);
|
|
3911
3999
|
let response;
|
|
3912
4000
|
try {
|
|
3913
|
-
response = await session.fetch(request, {
|
|
4001
|
+
response = await session.fetch(request, {
|
|
4002
|
+
redirect: "manual",
|
|
4003
|
+
signal
|
|
4004
|
+
});
|
|
3914
4005
|
} catch (error) {
|
|
3915
4006
|
await closeAfterError(session, logger);
|
|
3916
4007
|
throw error;
|
|
@@ -3960,7 +4051,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
3960
4051
|
method,
|
|
3961
4052
|
headers,
|
|
3962
4053
|
body,
|
|
3963
|
-
redirect: "manual"
|
|
4054
|
+
redirect: "manual",
|
|
4055
|
+
signal: signal ?? request.signal
|
|
3964
4056
|
});
|
|
3965
4057
|
}
|
|
3966
4058
|
}
|
|
@@ -4432,9 +4524,6 @@ async function enqueueForwarding(parameters, outboxQueue, inboxes) {
|
|
|
4432
4524
|
function isPlainObject$1(value) {
|
|
4433
4525
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
4434
4526
|
}
|
|
4435
|
-
function normalizeDateTimeLiteral(value) {
|
|
4436
|
-
return value.substring(19).match(/[Z+-]/) ? value : value + "Z";
|
|
4437
|
-
}
|
|
4438
4527
|
function isMalformedDateTimeLiteral(value) {
|
|
4439
4528
|
if (typeof value !== "string") return false;
|
|
4440
4529
|
try {
|
|
@@ -4476,7 +4565,7 @@ function hasMalformedExpandedQuestionClosedLiteral(value) {
|
|
|
4476
4565
|
if (typeof literal === "boolean") return false;
|
|
4477
4566
|
if (typeof literal !== "string") return false;
|
|
4478
4567
|
if (value["@type"] !== XSD_DATE_TIME_IRI) return false;
|
|
4479
|
-
if (new Date(literal).toString() === "Invalid Date") return false;
|
|
4568
|
+
if (new Date(literal).toString() === "Invalid Date" && new Date(normalizeDateTimeLiteral(literal)).toString() === "Invalid Date") return false;
|
|
4480
4569
|
return isMalformedDateTimeLiteral(literal);
|
|
4481
4570
|
}
|
|
4482
4571
|
function hasMalformedExpandedDurationLiteral(value) {
|
|
@@ -4577,7 +4666,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
4577
4666
|
if (!await authorizePredicate(context, identifier)) return await onUnauthorized(request);
|
|
4578
4667
|
}
|
|
4579
4668
|
if (actor instanceof Tombstone) {
|
|
4580
|
-
const jsonLd = await actor
|
|
4669
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
4581
4670
|
return new Response(JSON.stringify(jsonLd), {
|
|
4582
4671
|
status: 410,
|
|
4583
4672
|
headers: {
|
|
@@ -4586,7 +4675,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
4586
4675
|
}
|
|
4587
4676
|
});
|
|
4588
4677
|
}
|
|
4589
|
-
const jsonLd = await actor
|
|
4678
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
4590
4679
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
4591
4680
|
"Content-Type": "application/activity+json",
|
|
4592
4681
|
Vary: "Accept"
|
|
@@ -4606,7 +4695,7 @@ async function handleObject(request, { values, context, objectDispatcher, author
|
|
|
4606
4695
|
if (authorizePredicate != null) {
|
|
4607
4696
|
if (!await authorizePredicate(context, values)) return await onUnauthorized(request);
|
|
4608
4697
|
}
|
|
4609
|
-
const jsonLd = await object
|
|
4698
|
+
const jsonLd = await serializeForResponse(object, context);
|
|
4610
4699
|
if (object instanceof Tombstone) return new Response(request.method === "HEAD" ? null : JSON.stringify(jsonLd), {
|
|
4611
4700
|
status: 410,
|
|
4612
4701
|
headers: {
|
|
@@ -4858,13 +4947,13 @@ function recordCollectionMetrics(meterProvider, base, result, options = {}) {
|
|
|
4858
4947
|
* @param parameters The parameters for handling the collection.
|
|
4859
4948
|
* @returns A promise that resolves to an HTTP response.
|
|
4860
4949
|
*/
|
|
4861
|
-
async function handleCollection(request, { name: name$
|
|
4862
|
-
const spanName = name$
|
|
4950
|
+
async function handleCollection(request, { name: name$2, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, portable, tracerProvider, meterProvider, onUnauthorized, onNotFound }) {
|
|
4951
|
+
const spanName = name$2.trim().replace(/\s+/g, "_");
|
|
4863
4952
|
tracerProvider = tracerProvider ?? trace.getTracerProvider();
|
|
4864
4953
|
const tracer = tracerProvider.getTracer(name, version);
|
|
4865
4954
|
const cursor = new URL(request.url).searchParams.get("cursor");
|
|
4866
4955
|
const metricBase = {
|
|
4867
|
-
kind: getCollectionMetricKind(name$
|
|
4956
|
+
kind: getCollectionMetricKind(name$2),
|
|
4868
4957
|
page: cursor != null,
|
|
4869
4958
|
dispatcher: "built_in"
|
|
4870
4959
|
};
|
|
@@ -4910,7 +4999,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
4910
4999
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
4911
5000
|
return await onNotFound(request);
|
|
4912
5001
|
}
|
|
4913
|
-
const items = filterCollectionItems(page.items, name$
|
|
5002
|
+
const items = filterCollectionItems(page.items, name$2, filterPredicate);
|
|
4914
5003
|
itemCount = items.length;
|
|
4915
5004
|
span.setAttribute("fedify.collection.items", itemCount);
|
|
4916
5005
|
return items;
|
|
@@ -4952,7 +5041,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
4952
5041
|
} else {
|
|
4953
5042
|
const uri = new URL(portable == null ? baseUri : pageBase);
|
|
4954
5043
|
uri.searchParams.set("cursor", cursor);
|
|
4955
|
-
const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$
|
|
5044
|
+
const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$2}`, {
|
|
4956
5045
|
kind: SpanKind.SERVER,
|
|
4957
5046
|
attributes: {
|
|
4958
5047
|
"activitypub.collection.id": uri.href,
|
|
@@ -4968,7 +5057,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
4968
5057
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
4969
5058
|
return await onNotFound(request);
|
|
4970
5059
|
}
|
|
4971
|
-
const items = filterCollectionItems(page.items, name$
|
|
5060
|
+
const items = filterCollectionItems(page.items, name$2, filterPredicate);
|
|
4972
5061
|
itemCount = items.length;
|
|
4973
5062
|
span.setAttribute("fedify.collection.items", itemCount);
|
|
4974
5063
|
return {
|
|
@@ -5012,7 +5101,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
5012
5101
|
if (portable == null && collectionCallbacks.authorizePredicate != null) {
|
|
5013
5102
|
if (!await collectionCallbacks.authorizePredicate(context, identifier)) return finish(await onUnauthorized(request), "unauthorized");
|
|
5014
5103
|
}
|
|
5015
|
-
const jsonLd = await collection
|
|
5104
|
+
const jsonLd = await serializeForResponse(collection, context, portable != null);
|
|
5016
5105
|
if (portable != null) return await verifyPortableCollection(jsonLd, context, portable) ? finish(respondWithPortableCollection(request, jsonLd), "served") : finish(portableObjectInternalServerError(request), "error");
|
|
5017
5106
|
return finish(new Response(JSON.stringify(jsonLd), { headers: {
|
|
5018
5107
|
"Content-Type": "application/activity+json",
|
|
@@ -5602,7 +5691,11 @@ async function handleInboxInternal(request, parameters, span) {
|
|
|
5602
5691
|
keyTtl: publicKeyTtl
|
|
5603
5692
|
});
|
|
5604
5693
|
const jsonWithoutSig = detachSignature(json);
|
|
5605
|
-
const hasLdSignature =
|
|
5694
|
+
const hasLdSignature = hasVerifiableSignature(json);
|
|
5695
|
+
if (!hasLdSignature) {
|
|
5696
|
+
const shape = describeSignatureShape(json);
|
|
5697
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
5698
|
+
}
|
|
5606
5699
|
const canAttemptAlternateAuthAfterLdSignatureFailure = skipSignatureVerification || hasHttpSignatureHeaders(request) || hasObjectIntegrityProof(jsonWithoutSig);
|
|
5607
5700
|
let deferredLdSignatureError = void 0;
|
|
5608
5701
|
const respondInvalidActivity = async (error) => {
|
|
@@ -6380,8 +6473,8 @@ var CustomCollectionHandler = class {
|
|
|
6380
6473
|
* @param CollectionPage The CollectionPage constructor.
|
|
6381
6474
|
* @param filterPredicate Optional filter predicate for items.
|
|
6382
6475
|
*/
|
|
6383
|
-
constructor(name$
|
|
6384
|
-
this.name = name$
|
|
6476
|
+
constructor(name$1, values, context, callbacks, tracerProvider = trace.getTracerProvider(), meterProvider, Collection, CollectionPage, filterPredicate, portable) {
|
|
6477
|
+
this.name = name$1;
|
|
6385
6478
|
this.values = values;
|
|
6386
6479
|
this.context = context;
|
|
6387
6480
|
this.callbacks = callbacks;
|
|
@@ -6405,7 +6498,7 @@ var CustomCollectionHandler = class {
|
|
|
6405
6498
|
* @returns A promise that resolves to the JSON-LD representation.
|
|
6406
6499
|
*/
|
|
6407
6500
|
async toJsonLd() {
|
|
6408
|
-
return (await this.collection
|
|
6501
|
+
return serializeForResponse(await this.collection, this.context, this.portable != null);
|
|
6409
6502
|
}
|
|
6410
6503
|
/**
|
|
6411
6504
|
* Fetches the collection with optional cursor for pagination.
|
|
@@ -6801,7 +6894,7 @@ var PortableCollectionRefusedError = class extends HandlerError {
|
|
|
6801
6894
|
* @since 0.3.0
|
|
6802
6895
|
*/
|
|
6803
6896
|
async function respondWithObject(object, options) {
|
|
6804
|
-
const jsonLd = await object
|
|
6897
|
+
const jsonLd = await serializeForResponse(object, options);
|
|
6805
6898
|
return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
|
|
6806
6899
|
}
|
|
6807
6900
|
/**
|
|
@@ -6898,6 +6991,13 @@ const MIN_COMPONENTS = [
|
|
|
6898
6991
|
function isPortableActorKey(key) {
|
|
6899
6992
|
return key?.id != null && isPortableKeyId(key.id) && key.ownerId != null && isPortableId(key.ownerId);
|
|
6900
6993
|
}
|
|
6994
|
+
/** Applies compatibility changes after ordinary vocabulary serialization. */
|
|
6995
|
+
async function serializeForResponse(object, options, compact = false) {
|
|
6996
|
+
return await normalizeAttachmentArrays(await object.toJsonLd(compact ? {
|
|
6997
|
+
format: "compact",
|
|
6998
|
+
contextLoader: options?.contextLoader
|
|
6999
|
+
} : options), options?.contextLoader);
|
|
7000
|
+
}
|
|
6901
7001
|
/**
|
|
6902
7002
|
* Checks whether an activity needs an Object Integrity Proof by its DID:
|
|
6903
7003
|
* either it is performed by an [FEP-ef61] portable actor, or its own ID is
|
|
@@ -7257,6 +7357,102 @@ function buildPortableCollectionView(collectionId, requestUrl) {
|
|
|
7257
7357
|
return view;
|
|
7258
7358
|
}
|
|
7259
7359
|
//#endregion
|
|
7360
|
+
//#region src/sig/proof-creation.ts
|
|
7361
|
+
/** Signs the exact serialized message supplied by an internal producer. */
|
|
7362
|
+
async function createProofForJsonLd(jsonLd, privateKey, keyId, created) {
|
|
7363
|
+
validateCryptoKey(privateKey, "private");
|
|
7364
|
+
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
7365
|
+
const encoder = new TextEncoder();
|
|
7366
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(jsonLd)));
|
|
7367
|
+
created ??= Temporal.Now.instant();
|
|
7368
|
+
const proofConfig = {
|
|
7369
|
+
"@context": jsonLd["@context"],
|
|
7370
|
+
type: "DataIntegrityProof",
|
|
7371
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7372
|
+
verificationMethod: keyId.href,
|
|
7373
|
+
proofPurpose: "assertionMethod",
|
|
7374
|
+
created: created.toString()
|
|
7375
|
+
};
|
|
7376
|
+
const proofDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(proofConfig)));
|
|
7377
|
+
const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
|
|
7378
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
7379
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
7380
|
+
const sig = await crypto.subtle.sign("Ed25519", asCryptoKey(privateKey), digest);
|
|
7381
|
+
return new DataIntegrityProof({
|
|
7382
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7383
|
+
verificationMethod: keyId,
|
|
7384
|
+
proofPurpose: "assertionMethod",
|
|
7385
|
+
created,
|
|
7386
|
+
proofValue: new Uint8Array(sig)
|
|
7387
|
+
});
|
|
7388
|
+
}
|
|
7389
|
+
//#endregion
|
|
7390
|
+
//#region src/compat/delivery-jsonld.ts
|
|
7391
|
+
/**
|
|
7392
|
+
* Returns changed wire JSON only; unchanged documents keep the existing
|
|
7393
|
+
* delivery signing path. This uses ordinary vocabulary serialization, without
|
|
7394
|
+
* retaining or repairing independently signed child representations.
|
|
7395
|
+
*/
|
|
7396
|
+
async function prepareActivityJsonLd(activity, contextLoader) {
|
|
7397
|
+
if (activity.proofIds.length > 0) return void 0;
|
|
7398
|
+
for await (const _ of activity.getProofs({ contextLoader })) return void 0;
|
|
7399
|
+
const source = await activity.clone({}, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) }).toJsonLd({
|
|
7400
|
+
format: "compact",
|
|
7401
|
+
contextLoader
|
|
7402
|
+
});
|
|
7403
|
+
const prepared = await normalizeOutgoingActivityJsonLd(source, contextLoader, { preserveSecuredDocuments: true });
|
|
7404
|
+
return prepared !== source && typeof prepared === "object" && prepared != null && !Array.isArray(prepared) ? prepared : void 0;
|
|
7405
|
+
}
|
|
7406
|
+
/** Signs a changed, proof-free delivery map without serializing it again. */
|
|
7407
|
+
async function signActivityJsonLd(activity, unsigned, keys, options) {
|
|
7408
|
+
const proofs = [];
|
|
7409
|
+
const serializedProofs = [];
|
|
7410
|
+
const tracer = (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version);
|
|
7411
|
+
for (const { privateKey, keyId } of keys) {
|
|
7412
|
+
const proof = await tracer.startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": getTypeId(activity).href } }, async (span) => {
|
|
7413
|
+
try {
|
|
7414
|
+
if (activity.id != null) span.setAttribute("activitypub.object.id", activity.id.href);
|
|
7415
|
+
const proof = await createProofForJsonLd(unsigned, privateKey, keyId);
|
|
7416
|
+
if (span.isRecording()) {
|
|
7417
|
+
span.setAttribute("object_integrity_proofs.cryptosuite", "eddsa-jcs-2022");
|
|
7418
|
+
span.setAttribute("object_integrity_proofs.key_id", keyId.href);
|
|
7419
|
+
span.setAttribute("object_integrity_proofs.signature", encodeHex(proof.proofValue));
|
|
7420
|
+
}
|
|
7421
|
+
return proof;
|
|
7422
|
+
} catch (error) {
|
|
7423
|
+
span.setStatus({
|
|
7424
|
+
code: SpanStatusCode.ERROR,
|
|
7425
|
+
message: String(error)
|
|
7426
|
+
});
|
|
7427
|
+
throw error;
|
|
7428
|
+
} finally {
|
|
7429
|
+
span.end();
|
|
7430
|
+
}
|
|
7431
|
+
});
|
|
7432
|
+
proofs.push(proof);
|
|
7433
|
+
serializedProofs.push({
|
|
7434
|
+
"@context": unsigned["@context"],
|
|
7435
|
+
type: "DataIntegrityProof",
|
|
7436
|
+
cryptosuite: proof.cryptosuite,
|
|
7437
|
+
verificationMethod: keyId.href,
|
|
7438
|
+
proofPurpose: "assertionMethod",
|
|
7439
|
+
created: proof.created.toString(),
|
|
7440
|
+
proofValue: new TextDecoder().decode(encodeMultibase("base58btc", proof.proofValue))
|
|
7441
|
+
});
|
|
7442
|
+
}
|
|
7443
|
+
if (proofs.length === 0) return {
|
|
7444
|
+
activity,
|
|
7445
|
+
jsonLd: unsigned
|
|
7446
|
+
};
|
|
7447
|
+
return {
|
|
7448
|
+
activity: activity.clone({ proofs }, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) }),
|
|
7449
|
+
jsonLd: {
|
|
7450
|
+
...unsigned,
|
|
7451
|
+
proof: serializedProofs.length === 1 ? serializedProofs[0] : serializedProofs
|
|
7452
|
+
}
|
|
7453
|
+
};
|
|
7454
|
+
}
|
|
7455
|
+
//#endregion
|
|
7260
7456
|
//#region src/federation/outgoing-proof.ts
|
|
7261
7457
|
function formatKeyIds(candidates) {
|
|
7262
7458
|
return candidates.map((c) => c.verificationMethod.href).join(", ");
|
|
@@ -7324,6 +7520,15 @@ async function signOutgoingActivity(activity, candidates, options) {
|
|
|
7324
7520
|
const { contextLoader, tracerProvider } = options;
|
|
7325
7521
|
assertPortableActorActivity(activity);
|
|
7326
7522
|
const sign = async (selected) => {
|
|
7523
|
+
const prepared = !hasProof ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
|
|
7524
|
+
if (prepared != null) return {
|
|
7525
|
+
...await signActivityJsonLd(activity, prepared, selected.map(({ verificationMethod, privateKey }) => ({
|
|
7526
|
+
keyId: verificationMethod,
|
|
7527
|
+
privateKey
|
|
7528
|
+
})), { tracerProvider: tracerProvider ?? trace.getTracerProvider() }),
|
|
7529
|
+
hasProof: true,
|
|
7530
|
+
proofCreated: true
|
|
7531
|
+
};
|
|
7327
7532
|
for (const { verificationMethod, privateKey } of selected) activity = await signObject(activity, privateKey, verificationMethod, {
|
|
7328
7533
|
contextLoader,
|
|
7329
7534
|
tracerProvider
|
|
@@ -8488,6 +8693,13 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
8488
8693
|
if (resolved != null) return resolved;
|
|
8489
8694
|
return this.taskQueueResolution === "strict" ? void 0 : this.outboxQueue;
|
|
8490
8695
|
}
|
|
8696
|
+
#listenQueue(queue, ctxData, signal) {
|
|
8697
|
+
try {
|
|
8698
|
+
return queue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal });
|
|
8699
|
+
} catch (error) {
|
|
8700
|
+
return Promise.reject(error);
|
|
8701
|
+
}
|
|
8702
|
+
}
|
|
8491
8703
|
async _startQueueInternal(ctxData, signal, queue) {
|
|
8492
8704
|
const taskQueue = this.taskQueue ?? (this.taskQueueResolution === "fallback" ? this.outboxQueue : void 0);
|
|
8493
8705
|
const customQueues = this.taskDefinitions.values().map((def) => ["task", def.queue]);
|
|
@@ -8509,10 +8721,31 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
8509
8721
|
if (this.startedQueues.has(target)) continue;
|
|
8510
8722
|
this.startedQueues.add(target);
|
|
8511
8723
|
logger.debug("Starting a {role} queue worker.", { role });
|
|
8512
|
-
promises.push(
|
|
8724
|
+
promises.push(this.#listenQueue(target, ctxData, signal));
|
|
8513
8725
|
}
|
|
8514
8726
|
await Promise.all(promises);
|
|
8515
8727
|
}
|
|
8728
|
+
/**
|
|
8729
|
+
* Starts the queue workers automatically, reporting a failure instead of
|
|
8730
|
+
* leaving the returned promise unobserved.
|
|
8731
|
+
*
|
|
8732
|
+
* Automatic startup is best-effort: call sites cannot await it, so a failing
|
|
8733
|
+
* listener (e.g., `WorkersMessageQueue`, whose `listen()` throws) must not
|
|
8734
|
+
* become an unhandled rejection. {@link startQueue} keeps rejecting for
|
|
8735
|
+
* callers that start workers deliberately.
|
|
8736
|
+
*/
|
|
8737
|
+
#queueStartupFailureReported = false;
|
|
8738
|
+
_startQueueAutomatically(ctxData) {
|
|
8739
|
+
this._startQueueInternal(ctxData).catch((error) => {
|
|
8740
|
+
if (this.#queueStartupFailureReported) return;
|
|
8741
|
+
this.#queueStartupFailureReported = true;
|
|
8742
|
+
getLogger([
|
|
8743
|
+
"fedify",
|
|
8744
|
+
"federation",
|
|
8745
|
+
"queue"
|
|
8746
|
+
]).warn("Failed to start queue workers automatically: {error}", { error });
|
|
8747
|
+
});
|
|
8748
|
+
}
|
|
8516
8749
|
processQueuedTask(contextData, message) {
|
|
8517
8750
|
const extractedContext = propagation.extract(context.active(), message.traceContext);
|
|
8518
8751
|
return withContext({ messageId: message.id }, async () => {
|
|
@@ -9391,7 +9624,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9391
9624
|
let parseInput = void 0;
|
|
9392
9625
|
let parseContextLoader = context.contextLoader;
|
|
9393
9626
|
try {
|
|
9394
|
-
const hasSignatureField =
|
|
9627
|
+
const hasSignatureField = hasVerifiableSignature(message.activity);
|
|
9395
9628
|
const shouldParseFromNormalizedSignedPayload = message.ldSignatureVerified === true || message.normalizedActivity != null || message.ldSignatureVerified == null && hasSignatureField;
|
|
9396
9629
|
const parseContext = hasSignatureField ? {
|
|
9397
9630
|
...context,
|
|
@@ -9708,11 +9941,11 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9708
9941
|
});
|
|
9709
9942
|
activity = signed.activity;
|
|
9710
9943
|
const { hasProof, proofCreated } = signed;
|
|
9711
|
-
let jsonLd = !proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
9944
|
+
let jsonLd = signed.jsonLd ?? (!proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
9712
9945
|
format: "compact",
|
|
9713
9946
|
contextLoader
|
|
9714
|
-
});
|
|
9715
|
-
if (proofCreated || !hasProof || options.normalizeExistingProofs) jsonLd = await normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, { preserveNestedSecuredDocuments: true });
|
|
9947
|
+
}));
|
|
9948
|
+
if (signed.jsonLd == null && (proofCreated || !hasProof || options.normalizeExistingProofs)) jsonLd = await normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, { preserveNestedSecuredDocuments: true });
|
|
9716
9949
|
assertSupportedCompoundProofShape(jsonLd, activityId);
|
|
9717
9950
|
if (rsaKey == null && !ldSignable) logger.debug("The activity {activityId} is performed by a portable actor, so it is sent without a Linked Data signature.", { activityId });
|
|
9718
9951
|
else if (rsaKey == null) logger.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
|
|
@@ -9751,19 +9984,27 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9751
9984
|
activity: jsonLd
|
|
9752
9985
|
});
|
|
9753
9986
|
const promises = [];
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9987
|
+
try {
|
|
9988
|
+
for (const inbox in inboxes) {
|
|
9989
|
+
const promise = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
9990
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
|
9991
|
+
keys,
|
|
9992
|
+
activity: jsonLd,
|
|
9993
|
+
activityId: activity.id?.href,
|
|
9994
|
+
activityType: getTypeId(activity).href,
|
|
9995
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
9996
|
+
headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
|
|
9997
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
9998
|
+
meterProvider: this.meterProvider,
|
|
9999
|
+
tracerProvider: this.tracerProvider
|
|
10000
|
+
});
|
|
10001
|
+
promise.catch(() => {});
|
|
10002
|
+
promises.push(promise);
|
|
10003
|
+
}
|
|
10004
|
+
await Promise.all(promises);
|
|
10005
|
+
} finally {
|
|
10006
|
+
await Promise.allSettled(promises);
|
|
10007
|
+
}
|
|
9767
10008
|
return;
|
|
9768
10009
|
}
|
|
9769
10010
|
logger.debug("Enqueuing activity {activityId} to send later.", {
|
|
@@ -9778,7 +10019,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9778
10019
|
privateKey: privateKeyJwk
|
|
9779
10020
|
});
|
|
9780
10021
|
}
|
|
9781
|
-
if (!this.manuallyStartQueue) this.
|
|
10022
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(ctx.data);
|
|
9782
10023
|
const carrier = {};
|
|
9783
10024
|
propagation.inject(context.active(), carrier);
|
|
9784
10025
|
const messages = [];
|
|
@@ -10458,7 +10699,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
10458
10699
|
return await observation.run(() => Promise.reject(error), span);
|
|
10459
10700
|
}
|
|
10460
10701
|
async #handleInbox(request, { recipient, context, contextData, onNotFound, portableInbox, observation }) {
|
|
10461
|
-
if (!this.manuallyStartQueue) this.
|
|
10702
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(contextData);
|
|
10462
10703
|
const inboxContextFactory = context.toInboxContext.bind(context);
|
|
10463
10704
|
inboxContextFactory[rawInboxContextFactorySymbol] = context.toInboxContext.bind(context);
|
|
10464
10705
|
return await handleInbox(request, {
|
|
@@ -10571,7 +10812,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
10571
10812
|
kv: this.kv,
|
|
10572
10813
|
kvPrefix: this.kvPrefixes.portableInboxForwarding,
|
|
10573
10814
|
outboxQueue: this.outboxQueue,
|
|
10574
|
-
startQueue: this.manuallyStartQueue ? void 0 : () => this.
|
|
10815
|
+
startQueue: this.manuallyStartQueue ? void 0 : () => this._startQueueAutomatically(contextData),
|
|
10575
10816
|
allowPrivateAddress: this.allowPrivateAddress,
|
|
10576
10817
|
getKeys: () => this.#getPortableGatewayKeyPairs(context, identifier, recipient),
|
|
10577
10818
|
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
@@ -11077,6 +11318,8 @@ var ContextImpl = class ContextImpl {
|
|
|
11077
11318
|
for (const keyPair of keyPairs) {
|
|
11078
11319
|
const newPair = {
|
|
11079
11320
|
...keyPair,
|
|
11321
|
+
privateKey: asCryptoKey(keyPair.privateKey),
|
|
11322
|
+
publicKey: asCryptoKey(keyPair.publicKey),
|
|
11080
11323
|
cryptographicKey: new CryptographicKey({
|
|
11081
11324
|
id: keyPair.keyId,
|
|
11082
11325
|
owner,
|
|
@@ -11174,10 +11417,16 @@ var ContextImpl = class ContextImpl {
|
|
|
11174
11417
|
} else identifierPromise = Promise.resolve(identity.identifier);
|
|
11175
11418
|
return identifierPromise.then((identifier) => {
|
|
11176
11419
|
if (identifier == null) return this.documentLoader;
|
|
11177
|
-
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(
|
|
11420
|
+
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory({
|
|
11421
|
+
keyId: pair.keyId,
|
|
11422
|
+
privateKey: asCryptoKey(pair.privateKey)
|
|
11423
|
+
}));
|
|
11178
11424
|
});
|
|
11179
11425
|
}
|
|
11180
|
-
return this.federation.authenticatedDocumentLoaderFactory(
|
|
11426
|
+
return this.federation.authenticatedDocumentLoaderFactory({
|
|
11427
|
+
keyId: identity.keyId,
|
|
11428
|
+
privateKey: asCryptoKey(identity.privateKey)
|
|
11429
|
+
});
|
|
11181
11430
|
}
|
|
11182
11431
|
lookupObject(identifier, options = {}) {
|
|
11183
11432
|
return lookupObject(identifier, {
|
|
@@ -11203,10 +11452,14 @@ var ContextImpl = class ContextImpl {
|
|
|
11203
11452
|
return options.parse === "none" ? getNodeInfo(url, {
|
|
11204
11453
|
parse: "none",
|
|
11205
11454
|
direct: options.direct,
|
|
11455
|
+
timeout: options.timeout,
|
|
11456
|
+
signal: options.signal,
|
|
11206
11457
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
11207
11458
|
}) : getNodeInfo(url, {
|
|
11208
11459
|
parse: options.parse,
|
|
11209
11460
|
direct: options.direct,
|
|
11461
|
+
timeout: options.timeout,
|
|
11462
|
+
signal: options.signal,
|
|
11210
11463
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
11211
11464
|
});
|
|
11212
11465
|
}
|
|
@@ -11225,7 +11478,17 @@ var ContextImpl = class ContextImpl {
|
|
|
11225
11478
|
async enqueueTaskMany(task, payloads, options = {}) {
|
|
11226
11479
|
await this.#enqueueTasks(task, payloads, options);
|
|
11227
11480
|
}
|
|
11228
|
-
sendActivity(sender, recipients, activity, options = {}) {
|
|
11481
|
+
async sendActivity(sender, recipients, activity, options = {}) {
|
|
11482
|
+
let activityJsonLd = void 0;
|
|
11483
|
+
let hasProof = activity.proofIds.length > 0;
|
|
11484
|
+
if (!hasProof) for await (const _ of activity.getProofs({ contextLoader: this.contextLoader })) {
|
|
11485
|
+
hasProof = true;
|
|
11486
|
+
break;
|
|
11487
|
+
}
|
|
11488
|
+
if (hasProof) {
|
|
11489
|
+
activityJsonLd = await activity.toJsonLd({ contextLoader: this.contextLoader });
|
|
11490
|
+
if (!hasTopLevelProof(activityJsonLd)) activityJsonLd = void 0;
|
|
11491
|
+
}
|
|
11229
11492
|
return this.tracerProvider.getTracer(name, version).startActiveSpan(this.federation.outboxQueue == null || options.immediate ? "activitypub.outbox" : "activitypub.fanout", {
|
|
11230
11493
|
kind: this.federation.outboxQueue == null || options.immediate ? SpanKind.CLIENT : SpanKind.PRODUCER,
|
|
11231
11494
|
attributes: {
|
|
@@ -11238,7 +11501,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11238
11501
|
}, async (span) => {
|
|
11239
11502
|
try {
|
|
11240
11503
|
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
|
11241
|
-
await this.sendActivityInternal(sender, recipients, activity, options, span);
|
|
11504
|
+
await this.sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd);
|
|
11242
11505
|
} catch (e) {
|
|
11243
11506
|
span.setStatus({
|
|
11244
11507
|
code: SpanStatusCode.ERROR,
|
|
@@ -11250,7 +11513,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11250
11513
|
}
|
|
11251
11514
|
});
|
|
11252
11515
|
}
|
|
11253
|
-
async sendActivityInternal(sender, recipients, activity, options, span) {
|
|
11516
|
+
async sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd) {
|
|
11254
11517
|
const logger = getLogger([
|
|
11255
11518
|
"fedify",
|
|
11256
11519
|
"federation",
|
|
@@ -11297,15 +11560,23 @@ var ContextImpl = class ContextImpl {
|
|
|
11297
11560
|
if (!(error instanceof RouterError)) throw error;
|
|
11298
11561
|
}
|
|
11299
11562
|
} else expandedRecipients = [recipients];
|
|
11300
|
-
const opts = {
|
|
11301
|
-
context: this,
|
|
11302
|
-
orderingKey: options.orderingKey,
|
|
11303
|
-
collectionSync,
|
|
11304
|
-
immediate: options.immediate,
|
|
11305
|
-
normalizeExistingProofs: options.normalizeExistingProofs
|
|
11306
|
-
};
|
|
11307
11563
|
span.setAttribute("activitypub.inboxes", expandedRecipients.length);
|
|
11308
11564
|
for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
|
|
11565
|
+
let contextMatches = false;
|
|
11566
|
+
if (activityJsonLd != null) {
|
|
11567
|
+
const capturedJsonLd = activityJsonLd;
|
|
11568
|
+
const transformedJsonLd = await activity.toJsonLd({
|
|
11569
|
+
format: "compact",
|
|
11570
|
+
contextLoader: this.contextLoader
|
|
11571
|
+
});
|
|
11572
|
+
const contentChanged = getContentFields(transformedJsonLd) !== getContentFields(capturedJsonLd);
|
|
11573
|
+
contextMatches = getContextFields(transformedJsonLd) === getContextFields(capturedJsonLd);
|
|
11574
|
+
const proofsChanged = getProofFields(transformedJsonLd) !== getProofFields(capturedJsonLd);
|
|
11575
|
+
if (contentChanged || !contextMatches && proofsChanged) {
|
|
11576
|
+
activity = activity.clone({ proofs: await getUncapturedProofs(activity, capturedJsonLd, this.contextLoader) }, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) });
|
|
11577
|
+
activityJsonLd = void 0;
|
|
11578
|
+
} else if (proofsChanged) activityJsonLd = void 0;
|
|
11579
|
+
}
|
|
11309
11580
|
span?.setAttribute("activitypub.activity.id", activity?.id?.href ?? "");
|
|
11310
11581
|
if (activity.actorId == null) {
|
|
11311
11582
|
logger.error("Activity {activityId} to send does not have an actor.", {
|
|
@@ -11314,7 +11585,11 @@ var ContextImpl = class ContextImpl {
|
|
|
11314
11585
|
});
|
|
11315
11586
|
throw new TypeError("The activity to send must have at least one actor property.");
|
|
11316
11587
|
}
|
|
11317
|
-
|
|
11588
|
+
if (actorKeyPairs != null && activityJsonLd != null && !contextMatches && actorKeyPairs.some((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null && !isPortableKeyId(kp.multikey.id))) {
|
|
11589
|
+
activity = activity.clone({ proofs: [] }, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) });
|
|
11590
|
+
activityJsonLd = void 0;
|
|
11591
|
+
}
|
|
11592
|
+
const signed = await signOutgoingActivity(activity, actorKeyPairs == null ? keys.map(({ keyId, privateKey }) => ({
|
|
11318
11593
|
verificationMethod: keyId,
|
|
11319
11594
|
privateKey
|
|
11320
11595
|
})) : actorKeyPairs.flatMap((kp) => kp.multikey.id == null ? [] : [{
|
|
@@ -11325,7 +11600,15 @@ var ContextImpl = class ContextImpl {
|
|
|
11325
11600
|
tracerProvider: this.tracerProvider,
|
|
11326
11601
|
appendToExistingProofs: actorKeyPairs != null
|
|
11327
11602
|
});
|
|
11328
|
-
activity =
|
|
11603
|
+
activity = signed.activity;
|
|
11604
|
+
const { proofCreated } = signed;
|
|
11605
|
+
const opts = {
|
|
11606
|
+
context: this,
|
|
11607
|
+
orderingKey: options.orderingKey,
|
|
11608
|
+
collectionSync,
|
|
11609
|
+
immediate: options.immediate,
|
|
11610
|
+
normalizeExistingProofs: options.normalizeExistingProofs
|
|
11611
|
+
};
|
|
11329
11612
|
const inboxes = extractInboxes({
|
|
11330
11613
|
recipients: expandedRecipients,
|
|
11331
11614
|
preferSharedInbox: options.preferSharedInbox,
|
|
@@ -11343,10 +11626,10 @@ var ContextImpl = class ContextImpl {
|
|
|
11343
11626
|
activityId: activity.id?.href,
|
|
11344
11627
|
activity
|
|
11345
11628
|
});
|
|
11346
|
-
|
|
11629
|
+
activityJsonLd = signed.jsonLd ?? (!proofCreated && activityJsonLd != null ? activityJsonLd : await activity.toJsonLd({
|
|
11347
11630
|
format: "compact",
|
|
11348
11631
|
contextLoader: this.contextLoader
|
|
11349
|
-
});
|
|
11632
|
+
}));
|
|
11350
11633
|
try {
|
|
11351
11634
|
await warnCompatibleIdsInJson(activityJsonLd, this instanceof RequestContextImpl && !this.isInActorDispatcher() ? this : void 0);
|
|
11352
11635
|
} catch (error) {
|
|
@@ -11388,7 +11671,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11388
11671
|
normalizeExistingProofs: proofCreated || options.normalizeExistingProofs,
|
|
11389
11672
|
traceContext: carrier
|
|
11390
11673
|
};
|
|
11391
|
-
if (!this.federation.manuallyStartQueue) this.federation.
|
|
11674
|
+
if (!this.federation.manuallyStartQueue) this.federation._startQueueAutomatically(this.data);
|
|
11392
11675
|
await this.federation.fanoutQueue.enqueue(message, { orderingKey: options.orderingKey });
|
|
11393
11676
|
getFederationMetrics(this.federation.meterProvider).recordQueueTaskEnqueued({
|
|
11394
11677
|
role: "fanout",
|
|
@@ -11786,7 +12069,7 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
11786
12069
|
if (forwarder.length < 1) throw new Error("The forwarder's key pairs are empty.");
|
|
11787
12070
|
keys = forwarder;
|
|
11788
12071
|
} else keys = [forwarder];
|
|
11789
|
-
if (!hasSignatureLike(ctx.activity)) {
|
|
12072
|
+
if (!hasVerifiableSignature(ctx.activity) && !hasSignatureLike(ctx.activity)) {
|
|
11790
12073
|
if (!hasProofLike(ctx.activity)) {
|
|
11791
12074
|
if (options?.skipIfUnsigned) return false;
|
|
11792
12075
|
logger.warn("The activity {activityId} is not signed; even if it is forwarded to other servers as is, it may not be accepted by them due to the lack of a signature/proof.", {
|
|
@@ -11824,25 +12107,33 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
11824
12107
|
if (options?.immediate) logger.debug("Forwarding activity immediately without queue since immediate option is set.");
|
|
11825
12108
|
else logger.debug("Forwarding activity immediately without queue since queue is not set.");
|
|
11826
12109
|
const promises = [];
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
12110
|
+
try {
|
|
12111
|
+
for (const inbox in inboxes) {
|
|
12112
|
+
const promise = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
12113
|
+
allowPrivateAddress: ctx.federation.allowPrivateAddress,
|
|
12114
|
+
keys,
|
|
12115
|
+
activity: ctx.activity,
|
|
12116
|
+
activityId: ctx.activityId,
|
|
12117
|
+
activityType: ctx.activityType,
|
|
12118
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
12119
|
+
meterProvider: ctx.meterProvider,
|
|
12120
|
+
tracerProvider: ctx.tracerProvider,
|
|
12121
|
+
specDeterminer: new KvSpecDeterminer(ctx.federation.kv, ctx.federation.kvPrefixes.httpMessageSignaturesSpec, ctx.federation.firstKnock, { specTtl: ctx.federation.httpMessageSignaturesSpecTtl })
|
|
12122
|
+
});
|
|
12123
|
+
promise.catch(() => {});
|
|
12124
|
+
promises.push(promise);
|
|
12125
|
+
}
|
|
12126
|
+
await Promise.all(promises);
|
|
12127
|
+
} finally {
|
|
12128
|
+
await Promise.allSettled(promises);
|
|
12129
|
+
}
|
|
11839
12130
|
return true;
|
|
11840
12131
|
}
|
|
11841
12132
|
logger.debug("Enqueuing activity {activityId} to forward later.", {
|
|
11842
12133
|
activityId: ctx.activityId,
|
|
11843
12134
|
activity: ctx.activity
|
|
11844
12135
|
});
|
|
11845
|
-
if (!ctx.federation.manuallyStartQueue) ctx.federation.
|
|
12136
|
+
if (!ctx.federation.manuallyStartQueue) ctx.federation._startQueueAutomatically(ctx.data);
|
|
11846
12137
|
const keyJwkPairs = [];
|
|
11847
12138
|
for (const { keyId, privateKey } of keys) {
|
|
11848
12139
|
const privateKeyJwk = await exportJwk(privateKey);
|
|
@@ -12022,6 +12313,69 @@ var KvSpecDeterminer = class {
|
|
|
12022
12313
|
function notFound(_request) {
|
|
12023
12314
|
return new Response("Not Found", { status: 404 });
|
|
12024
12315
|
}
|
|
12316
|
+
function hasTopLevelProof(value) {
|
|
12317
|
+
return typeof value === "object" && value != null && !Array.isArray(value) && globalThis.Object.prototype.hasOwnProperty.call(value, "proof");
|
|
12318
|
+
}
|
|
12319
|
+
function getContentFields(value) {
|
|
12320
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
12321
|
+
const record = { ...value };
|
|
12322
|
+
delete record["@context"];
|
|
12323
|
+
delete record.proof;
|
|
12324
|
+
delete record.signature;
|
|
12325
|
+
return JSON.stringify(sortJsonKeys(record));
|
|
12326
|
+
}
|
|
12327
|
+
function getContextFields(value) {
|
|
12328
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
12329
|
+
const context = value["@context"];
|
|
12330
|
+
return JSON.stringify(sortJsonKeys(context ?? null));
|
|
12331
|
+
}
|
|
12332
|
+
function getProofEntries(value) {
|
|
12333
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return [];
|
|
12334
|
+
const proof = value.proof;
|
|
12335
|
+
if (proof == null) return [];
|
|
12336
|
+
return Array.isArray(proof) ? proof : [proof];
|
|
12337
|
+
}
|
|
12338
|
+
function normalizeProofEntry(proof) {
|
|
12339
|
+
const stripped = stripContexts(proof);
|
|
12340
|
+
if (typeof stripped !== "object" || stripped == null || Array.isArray(stripped)) return stripped;
|
|
12341
|
+
const record = { ...stripped };
|
|
12342
|
+
if (typeof record.created === "string") try {
|
|
12343
|
+
record.created = Temporal.Instant.from(record.created).toString();
|
|
12344
|
+
} catch {}
|
|
12345
|
+
return record;
|
|
12346
|
+
}
|
|
12347
|
+
function getProofEntryFields(proof) {
|
|
12348
|
+
return JSON.stringify(sortJsonKeys(normalizeProofEntry(proof)));
|
|
12349
|
+
}
|
|
12350
|
+
function getProofFields(value) {
|
|
12351
|
+
return JSON.stringify(getProofEntries(value).map(getProofEntryFields).sort());
|
|
12352
|
+
}
|
|
12353
|
+
async function getUncapturedProofs(activity, capturedJsonLd, contextLoader) {
|
|
12354
|
+
const capturedProofs = new Set(getProofEntries(capturedJsonLd).map(getProofEntryFields));
|
|
12355
|
+
const retainedProofs = [];
|
|
12356
|
+
for await (const proof of activity.getProofs({ contextLoader })) {
|
|
12357
|
+
const proofJsonLd = await proof.toJsonLd({
|
|
12358
|
+
format: "compact",
|
|
12359
|
+
contextLoader
|
|
12360
|
+
});
|
|
12361
|
+
if (!capturedProofs.has(getProofEntryFields(proofJsonLd))) retainedProofs.push(proof);
|
|
12362
|
+
}
|
|
12363
|
+
return retainedProofs;
|
|
12364
|
+
}
|
|
12365
|
+
function stripContexts(value) {
|
|
12366
|
+
if (Array.isArray(value)) return value.map(stripContexts);
|
|
12367
|
+
if (typeof value !== "object" || value == null) return value;
|
|
12368
|
+
const record = { ...value };
|
|
12369
|
+
delete record["@context"];
|
|
12370
|
+
delete record.signature;
|
|
12371
|
+
for (const key of globalThis.Object.keys(record)) record[key] = stripContexts(record[key]);
|
|
12372
|
+
return record;
|
|
12373
|
+
}
|
|
12374
|
+
function sortJsonKeys(value) {
|
|
12375
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
12376
|
+
if (typeof value !== "object" || value == null) return value;
|
|
12377
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
12378
|
+
}
|
|
12025
12379
|
function notAcceptable(_request) {
|
|
12026
12380
|
return new Response("Not Acceptable", {
|
|
12027
12381
|
status: 406,
|