@fedify/fedify 2.4.6-dev.2837 → 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-DYeeuJIZ.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.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-CxRUa-wY.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-CRpGtqm6.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-CZtA3Qjh.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-DkIcc4TV.cjs → federation-CM4nzbhO.cjs} +500 -144
- package/dist/{http-G2ORncQt.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-DnJvGLuL.js → http-BwgldAIk.js} +2798 -2629
- package/dist/{http-DWIArxRV.cjs → http-Tj9eQ_rd.cjs} +2634 -2453
- package/dist/{inbox-WfHbmNbc.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-CSJwIUzA.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-C9jAD4VW.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-C7b-sBZL.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-CKWvh95H.mjs → ld-BGnZDnia.mjs} +155 -22
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-Og1y_3kX.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-BLnbBpsz.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-ClfuKN0B.js → middleware-DX8wADUa.js} +451 -97
- package/dist/{middleware-CcNRQv7R.mjs → middleware-mRXKHq68.mjs} +355 -86
- 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 +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 +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-DxVC0b0R.mjs → owner-DEiBiiqR.mjs} +3 -3
- package/dist/{portable-collection-8BzIIWJb.cjs → portable-collection--h11WDIi.cjs} +1 -1
- package/dist/{portable-collection-pWL8BrQk.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-Bz3Zn527.js → portable-collection-M6d5I5JQ.js} +1 -1
- package/dist/{portable-key-BGmzMBYm.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/{proof-Cgvg3rEH.mjs → proof-C4pwAF2k.mjs} +29 -9
- package/dist/{send-DheMZ6fh.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-B7odHbLs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- 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.mjs +3 -3
- package/package.json +6 -6
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
2
|
const require_rolldown_runtime = require("./rolldown-runtime-Dmm3t92W.cjs");
|
|
3
|
+
const require_portable_verifier = require("./portable-verifier-DiLU8c9T.cjs");
|
|
3
4
|
const require_transformers = require("./transformers-aIK89ibB.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
5
|
-
const require_types = require("./types-
|
|
6
|
-
const require_portable_collection = require("./portable-collection
|
|
7
|
-
const require_kv_cache = require("./kv-cache-
|
|
5
|
+
const require_http = require("./http-Tj9eQ_rd.cjs");
|
|
6
|
+
const require_types = require("./types-C8gac_AD.cjs");
|
|
7
|
+
const require_portable_collection = require("./portable-collection--h11WDIi.cjs");
|
|
8
|
+
const require_kv_cache = require("./kv-cache-Vbq0yM7W.cjs");
|
|
8
9
|
let _logtape_logtape = require("@logtape/logtape");
|
|
9
10
|
let _fedify_uri_template = require("@fedify/uri-template");
|
|
10
11
|
let _fedify_vocab = require("@fedify/vocab");
|
|
@@ -15,8 +16,11 @@ let byte_encodings_hex = require("byte-encodings/hex");
|
|
|
15
16
|
let _fedify_vocab_runtime_jsonld = require("@fedify/vocab-runtime/jsonld");
|
|
16
17
|
_fedify_vocab_runtime_jsonld = require_rolldown_runtime.__toESM(_fedify_vocab_runtime_jsonld, 1);
|
|
17
18
|
let es_toolkit = require("es-toolkit");
|
|
18
|
-
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
19
19
|
let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
|
|
20
|
+
let json_canon = require("json-canon");
|
|
21
|
+
json_canon = require_rolldown_runtime.__toESM(json_canon, 1);
|
|
22
|
+
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
23
|
+
let _fedify_vocab_runtime_temporal = require("@fedify/vocab-runtime/temporal");
|
|
20
24
|
let _fedify_webfinger = require("@fedify/webfinger");
|
|
21
25
|
let _opentelemetry_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
22
26
|
let devalue = require("devalue");
|
|
@@ -876,13 +880,13 @@ function warnCompatibleActorId(actorId, gateway) {
|
|
|
876
880
|
}
|
|
877
881
|
//#endregion
|
|
878
882
|
//#region src/federation/circuit-breaker.ts
|
|
879
|
-
const Temporal$
|
|
883
|
+
const Temporal$12 = require_http.Temporal;
|
|
880
884
|
const LEGACY_SWEEP_MARKER = ["__fedify_meta", "circuit_breaker_state_ttl_sweep_v2"];
|
|
881
885
|
const LEGACY_SWEEP_DELETING_MARKER = { __fedifyDeletingCircuitBreakerLegacyState: true };
|
|
882
886
|
const CIRCUIT_BREAKER_STATE_VERSION = 1;
|
|
883
|
-
const LEGACY_SWEEP_LOCK_TTL = Temporal$
|
|
884
|
-
const LEGACY_SWEEP_RENEW_INTERVAL = Temporal$
|
|
885
|
-
const LEGACY_SWEEP_RETRY_WINDOW = Temporal$
|
|
887
|
+
const LEGACY_SWEEP_LOCK_TTL = Temporal$12.Duration.from({ minutes: 5 });
|
|
888
|
+
const LEGACY_SWEEP_RENEW_INTERVAL = Temporal$12.Duration.from({ minutes: 1 });
|
|
889
|
+
const LEGACY_SWEEP_RETRY_WINDOW = Temporal$12.Duration.from({ hours: 168 });
|
|
886
890
|
const LEGACY_SWEEP_WAIT_INTERVAL = 10;
|
|
887
891
|
const LEGACY_SWEEP_CAS_ATTEMPTS = 3;
|
|
888
892
|
/**
|
|
@@ -901,7 +905,7 @@ var CircuitBreaker = class {
|
|
|
901
905
|
this.#kv = options.kv;
|
|
902
906
|
this.#prefix = options.prefix;
|
|
903
907
|
this.#options = normalizeCircuitBreakerOptions(options.options ?? {});
|
|
904
|
-
this.#now = options.now ?? (() => Temporal$
|
|
908
|
+
this.#now = options.now ?? (() => Temporal$12.Now.instant());
|
|
905
909
|
this.#stateChangeObserver = options.stateChangeObserver;
|
|
906
910
|
}
|
|
907
911
|
get options() {
|
|
@@ -915,7 +919,7 @@ var CircuitBreaker = class {
|
|
|
915
919
|
this.#sweepLegacyStates();
|
|
916
920
|
const heldSince = parseHeldSince(message.circuitHeldSince);
|
|
917
921
|
const now = this.#now();
|
|
918
|
-
if (heldSince != null && Temporal$
|
|
922
|
+
if (heldSince != null && Temporal$12.Instant.compare(heldSince.add(this.#options.heldActivityTtl), now) <= 0) return {
|
|
919
923
|
type: "drop",
|
|
920
924
|
heldSince
|
|
921
925
|
};
|
|
@@ -927,12 +931,12 @@ var CircuitBreaker = class {
|
|
|
927
931
|
probe: false
|
|
928
932
|
};
|
|
929
933
|
if (oldState.state === "half-open") {
|
|
930
|
-
const halfOpened = oldState.halfOpened == null ? void 0 : Temporal$
|
|
934
|
+
const halfOpened = oldState.halfOpened == null ? void 0 : Temporal$12.Instant.from(oldState.halfOpened);
|
|
931
935
|
if (halfOpened != null) {
|
|
932
936
|
const staleAt = halfOpened.add(this.#options.recoveryDelay);
|
|
933
|
-
if (Temporal$
|
|
937
|
+
if (Temporal$12.Instant.compare(now, staleAt) < 0) {
|
|
934
938
|
const releaseAt = now.add(this.#options.releaseInterval);
|
|
935
|
-
const retryAt = Temporal$
|
|
939
|
+
const retryAt = Temporal$12.Instant.compare(releaseAt, staleAt) < 0 ? releaseAt : staleAt;
|
|
936
940
|
const cappedRetryAt = this.#capHeldRetryAt(now, heldSince, retryAt);
|
|
937
941
|
return {
|
|
938
942
|
type: "hold",
|
|
@@ -954,8 +958,8 @@ var CircuitBreaker = class {
|
|
|
954
958
|
lastConflictingState = "half-open";
|
|
955
959
|
continue;
|
|
956
960
|
}
|
|
957
|
-
const probeAt = (oldState.opened == null ? now : Temporal$
|
|
958
|
-
if (Temporal$
|
|
961
|
+
const probeAt = (oldState.opened == null ? now : Temporal$12.Instant.from(oldState.opened)).add(this.#options.recoveryDelay);
|
|
962
|
+
if (Temporal$12.Instant.compare(now, probeAt) < 0) {
|
|
959
963
|
const retryAt = this.#capHeldRetryAt(now, heldSince, probeAt);
|
|
960
964
|
return {
|
|
961
965
|
type: "hold",
|
|
@@ -1020,7 +1024,7 @@ var CircuitBreaker = class {
|
|
|
1020
1024
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
1021
1025
|
const { state: oldState, raw: oldValue } = await this.#get(remoteHost);
|
|
1022
1026
|
if (oldState?.state === "open") return void 0;
|
|
1023
|
-
const oldFailures = oldState?.failures.map(Temporal$
|
|
1027
|
+
const oldFailures = oldState?.failures.map(Temporal$12.Instant.from) ?? [];
|
|
1024
1028
|
const failures = this.#options.pruneFailures([...oldFailures, now], now);
|
|
1025
1029
|
let newState;
|
|
1026
1030
|
let transition;
|
|
@@ -1104,7 +1108,7 @@ var CircuitBreaker = class {
|
|
|
1104
1108
|
for await (const { key, value } of this.#kv.list(this.#prefix)) {
|
|
1105
1109
|
if (key.length !== this.#prefix.length + 1) continue;
|
|
1106
1110
|
await this.#migrateLegacyState(key, value);
|
|
1107
|
-
if (Temporal$
|
|
1111
|
+
if (Temporal$12.Instant.compare(this.#now(), leaseRenewedAt.add(LEGACY_SWEEP_RENEW_INTERVAL)) >= 0) {
|
|
1108
1112
|
const renewed = await this.#renewLegacySweep(markerKey, marker);
|
|
1109
1113
|
if (renewed == null) return;
|
|
1110
1114
|
marker = renewed;
|
|
@@ -1128,7 +1132,7 @@ var CircuitBreaker = class {
|
|
|
1128
1132
|
}
|
|
1129
1133
|
#finishLegacySweepMarker(marker) {
|
|
1130
1134
|
const retryUntil = getLegacySweepRetryUntil(marker);
|
|
1131
|
-
if (retryUntil != null && Temporal$
|
|
1135
|
+
if (retryUntil != null && Temporal$12.Instant.compare(this.#now(), Temporal$12.Instant.from(retryUntil)) < 0) return {
|
|
1132
1136
|
state: "done",
|
|
1133
1137
|
retryUntil
|
|
1134
1138
|
};
|
|
@@ -1171,7 +1175,7 @@ var CircuitBreaker = class {
|
|
|
1171
1175
|
#isLegacySweepDone() {
|
|
1172
1176
|
if (this.#legacySweepDone === "final") return true;
|
|
1173
1177
|
if (this.#legacySweepDone == null) return false;
|
|
1174
|
-
if (Temporal$
|
|
1178
|
+
if (Temporal$12.Instant.compare(this.#now(), this.#legacySweepDone) < 0) return true;
|
|
1175
1179
|
this.#legacySweepDone = void 0;
|
|
1176
1180
|
return false;
|
|
1177
1181
|
}
|
|
@@ -1181,7 +1185,7 @@ var CircuitBreaker = class {
|
|
|
1181
1185
|
}
|
|
1182
1186
|
#capHeldRetryAt(now, heldSince, retryAt) {
|
|
1183
1187
|
const expiresAt = (heldSince ?? now).add(this.#options.heldActivityTtl);
|
|
1184
|
-
return Temporal$
|
|
1188
|
+
return Temporal$12.Instant.compare(expiresAt, retryAt) < 0 ? expiresAt : retryAt;
|
|
1185
1189
|
}
|
|
1186
1190
|
async #get(remoteHost) {
|
|
1187
1191
|
const value = await this.#kv.get(this.#key(remoteHost));
|
|
@@ -1256,7 +1260,7 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1256
1260
|
assertPositiveDuration(releaseInterval, "releaseInterval");
|
|
1257
1261
|
if (configuredStateTtl != null) {
|
|
1258
1262
|
assertPositiveDuration(configuredStateTtl, "stateTtl");
|
|
1259
|
-
if (Temporal$
|
|
1263
|
+
if (Temporal$12.Duration.compare(configuredStateTtl, recoveryDelay) < 0) throw new RangeError("stateTtl must be at least recoveryDelay.");
|
|
1260
1264
|
}
|
|
1261
1265
|
let failure;
|
|
1262
1266
|
let pruneFailures;
|
|
@@ -1268,13 +1272,13 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1268
1272
|
assertPositiveDuration(failureWindow, "failureWindow");
|
|
1269
1273
|
pruneFailures = (timestamps, now) => {
|
|
1270
1274
|
const earliest = now.subtract(failureWindow);
|
|
1271
|
-
return timestamps.filter((timestamp) => Temporal$
|
|
1275
|
+
return timestamps.filter((timestamp) => Temporal$12.Instant.compare(timestamp, earliest) >= 0).slice(-failureThreshold);
|
|
1272
1276
|
};
|
|
1273
1277
|
failure = (timestamps) => {
|
|
1274
1278
|
if (timestamps.length < failureThreshold) return false;
|
|
1275
1279
|
const first = timestamps[timestamps.length - failureThreshold];
|
|
1276
1280
|
const last = timestamps[timestamps.length - 1];
|
|
1277
|
-
return Temporal$
|
|
1281
|
+
return Temporal$12.Duration.compare(first.until(last), failureWindow) <= 0;
|
|
1278
1282
|
};
|
|
1279
1283
|
stateTtl = configuredStateTtl ?? maxDuration(recoveryDelay.add(failureWindow), recoveryDelay.add(heldActivityTtl));
|
|
1280
1284
|
} else {
|
|
@@ -1294,7 +1298,7 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1294
1298
|
};
|
|
1295
1299
|
}
|
|
1296
1300
|
function maxDuration(duration, ...durations) {
|
|
1297
|
-
return durations.reduce((max, candidate) => Temporal$
|
|
1301
|
+
return durations.reduce((max, candidate) => Temporal$12.Duration.compare(candidate, max) > 0 ? candidate : max, duration);
|
|
1298
1302
|
}
|
|
1299
1303
|
function isLegacySweepDone(value, now) {
|
|
1300
1304
|
return getLegacySweepDoneUntil(value, now) != null;
|
|
@@ -1303,8 +1307,8 @@ function getLegacySweepDoneUntil(value, now) {
|
|
|
1303
1307
|
if (typeof value !== "object" || value == null || !("state" in value)) return;
|
|
1304
1308
|
if (value.state === "final") return "final";
|
|
1305
1309
|
if (value.state === "done" && "retryUntil" in value && typeof value.retryUntil === "string") try {
|
|
1306
|
-
const retryUntil = Temporal$
|
|
1307
|
-
return Temporal$
|
|
1310
|
+
const retryUntil = Temporal$12.Instant.from(value.retryUntil);
|
|
1311
|
+
return Temporal$12.Instant.compare(now, retryUntil) < 0 ? retryUntil : void 0;
|
|
1308
1312
|
} catch {
|
|
1309
1313
|
return;
|
|
1310
1314
|
}
|
|
@@ -1312,7 +1316,7 @@ function getLegacySweepDoneUntil(value, now) {
|
|
|
1312
1316
|
function isLegacySweepRetryDue(value, now) {
|
|
1313
1317
|
if (typeof value !== "object" || value == null || !("state" in value) || value.state !== "done" || !("retryUntil" in value) || typeof value.retryUntil !== "string") return false;
|
|
1314
1318
|
try {
|
|
1315
|
-
return Temporal$
|
|
1319
|
+
return Temporal$12.Instant.compare(now, Temporal$12.Instant.from(value.retryUntil)) >= 0;
|
|
1316
1320
|
} catch {
|
|
1317
1321
|
return false;
|
|
1318
1322
|
}
|
|
@@ -1323,7 +1327,7 @@ function isLegacySweepActive(value, now) {
|
|
|
1323
1327
|
function isLegacySweepInProgress(value, now) {
|
|
1324
1328
|
if (typeof value !== "object" || value == null || !("state" in value) || value.state !== "sweeping" || !("started" in value) || typeof value.started !== "string") return false;
|
|
1325
1329
|
try {
|
|
1326
|
-
return Temporal$
|
|
1330
|
+
return Temporal$12.Instant.compare(now, Temporal$12.Instant.from(value.started).add(LEGACY_SWEEP_LOCK_TTL)) < 0;
|
|
1327
1331
|
} catch {
|
|
1328
1332
|
return false;
|
|
1329
1333
|
}
|
|
@@ -1331,7 +1335,7 @@ function isLegacySweepInProgress(value, now) {
|
|
|
1331
1335
|
function getLegacySweepRetryUntil(value) {
|
|
1332
1336
|
if (typeof value !== "object" || value == null || !("retryUntil" in value) || typeof value.retryUntil !== "string") return;
|
|
1333
1337
|
try {
|
|
1334
|
-
Temporal$
|
|
1338
|
+
Temporal$12.Instant.from(value.retryUntil);
|
|
1335
1339
|
return value.retryUntil;
|
|
1336
1340
|
} catch {
|
|
1337
1341
|
return;
|
|
@@ -1355,19 +1359,19 @@ function delay(milliseconds) {
|
|
|
1355
1359
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
1356
1360
|
}
|
|
1357
1361
|
function toInstantDuration(duration) {
|
|
1358
|
-
const parsed = Temporal$
|
|
1359
|
-
return Temporal$
|
|
1362
|
+
const parsed = Temporal$12.Duration.from(duration);
|
|
1363
|
+
return Temporal$12.Duration.from({ milliseconds: Math.trunc(parsed.total({
|
|
1360
1364
|
unit: "millisecond",
|
|
1361
|
-
relativeTo: Temporal$
|
|
1365
|
+
relativeTo: Temporal$12.PlainDateTime.from("2026-01-01T00:00:00")
|
|
1362
1366
|
})) });
|
|
1363
1367
|
}
|
|
1364
1368
|
function assertPositiveDuration(duration, name) {
|
|
1365
|
-
if (Temporal$
|
|
1369
|
+
if (Temporal$12.Duration.compare(duration, { seconds: 0 }) <= 0) throw new RangeError(`${name} must be a positive duration.`);
|
|
1366
1370
|
}
|
|
1367
1371
|
function parseHeldSince(value) {
|
|
1368
1372
|
if (value == null) return void 0;
|
|
1369
1373
|
try {
|
|
1370
|
-
return Temporal$
|
|
1374
|
+
return Temporal$12.Instant.from(value);
|
|
1371
1375
|
} catch (error) {
|
|
1372
1376
|
(0, _logtape_logtape.getLogger)([
|
|
1373
1377
|
"fedify",
|
|
@@ -1394,7 +1398,7 @@ function parseStoredCircuitBreakerKvState(value) {
|
|
|
1394
1398
|
const isInstantString = (v) => {
|
|
1395
1399
|
if (typeof v !== "string") return false;
|
|
1396
1400
|
try {
|
|
1397
|
-
Temporal$
|
|
1401
|
+
Temporal$12.Instant.from(v);
|
|
1398
1402
|
return true;
|
|
1399
1403
|
} catch {
|
|
1400
1404
|
return false;
|
|
@@ -1559,6 +1563,17 @@ var InboxObservation = class {
|
|
|
1559
1563
|
}
|
|
1560
1564
|
};
|
|
1561
1565
|
//#endregion
|
|
1566
|
+
//#region src/compat/attachment-arrays.ts
|
|
1567
|
+
/**
|
|
1568
|
+
* Applies the shared attachment workaround to served documents without
|
|
1569
|
+
* rewriting any document that contains a semantic proof or LD signature.
|
|
1570
|
+
* RDF equivalence alone cannot preserve JCS signatures.
|
|
1571
|
+
* @internal
|
|
1572
|
+
*/
|
|
1573
|
+
function normalizeAttachmentArrays(document, contextLoader) {
|
|
1574
|
+
return require_http.normalizeAttachmentArrays(document, contextLoader, { preserveSecuredDocuments: true });
|
|
1575
|
+
}
|
|
1576
|
+
//#endregion
|
|
1562
1577
|
//#region src/sig/compound-proof.ts
|
|
1563
1578
|
const textEncoder = new TextEncoder();
|
|
1564
1579
|
/**
|
|
@@ -2779,7 +2794,7 @@ async function isInAudience(object, actor, options = {}) {
|
|
|
2779
2794
|
}
|
|
2780
2795
|
//#endregion
|
|
2781
2796
|
//#region src/federation/inbox.ts
|
|
2782
|
-
const Temporal$
|
|
2797
|
+
const Temporal$11 = require_http.Temporal;
|
|
2783
2798
|
/**
|
|
2784
2799
|
* Checks whether an activity's ID and all of its actor IDs have the same
|
|
2785
2800
|
* [FEP-fe34] origin. Activities without an ID have no origin to authenticate.
|
|
@@ -2946,7 +2961,7 @@ async function routeActivity({ context: ctx, json, originalJson, normalizedActiv
|
|
|
2946
2961
|
return "error";
|
|
2947
2962
|
}
|
|
2948
2963
|
require_http.recordInboxActivity(meterProvider, "processed", (0, _fedify_vocab.getTypeId)(activity).href);
|
|
2949
|
-
if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal$
|
|
2964
|
+
if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal$11.Duration.from({ days: 1 }) });
|
|
2950
2965
|
logger.info("Activity {activityId} has been processed.", {
|
|
2951
2966
|
activityId: activity.id?.href,
|
|
2952
2967
|
activity: json,
|
|
@@ -2958,7 +2973,7 @@ async function routeActivity({ context: ctx, json, originalJson, normalizedActiv
|
|
|
2958
2973
|
}
|
|
2959
2974
|
//#endregion
|
|
2960
2975
|
//#region src/federation/keycache.ts
|
|
2961
|
-
const Temporal$
|
|
2976
|
+
const Temporal$10 = require_http.Temporal;
|
|
2962
2977
|
const KEY_CACHE_GENERATION = "3";
|
|
2963
2978
|
const COMPATIBLE_KEY_SEGMENT = "__compatible";
|
|
2964
2979
|
const MAX_OWNER_BYTES = 32 * 1024;
|
|
@@ -2979,8 +2994,8 @@ var KvKeyCache = class {
|
|
|
2979
2994
|
this.kv = kv;
|
|
2980
2995
|
this.prefix = prefix;
|
|
2981
2996
|
this.options = options;
|
|
2982
|
-
this.unavailableKeyTtl = options.unavailableKeyTtl ?? Temporal$
|
|
2983
|
-
this.keyTtl = options.keyTtl ?? Temporal$
|
|
2997
|
+
this.unavailableKeyTtl = options.unavailableKeyTtl ?? Temporal$10.Duration.from({ minutes: 10 });
|
|
2998
|
+
this.keyTtl = options.keyTtl ?? Temporal$10.Duration.from({ days: 30 });
|
|
2984
2999
|
this.nullKeys = /* @__PURE__ */ new Map();
|
|
2985
3000
|
}
|
|
2986
3001
|
#getFetchErrorKey(keyId) {
|
|
@@ -3000,13 +3015,13 @@ var KvKeyCache = class {
|
|
|
3000
3015
|
async get(keyId) {
|
|
3001
3016
|
const negativeExpiration = this.nullKeys.get(keyId.href);
|
|
3002
3017
|
if (negativeExpiration != null) {
|
|
3003
|
-
if (Temporal$
|
|
3018
|
+
if (Temporal$10.Now.instant().until(negativeExpiration).sign >= 0) return null;
|
|
3004
3019
|
this.nullKeys.delete(keyId.href);
|
|
3005
3020
|
}
|
|
3006
3021
|
const serialized = await this.kv.get(this.#entryKey(keyId));
|
|
3007
3022
|
if (serialized === void 0) return void 0;
|
|
3008
3023
|
if (serialized === null) {
|
|
3009
|
-
this.nullKeys.set(keyId.href, Temporal$
|
|
3024
|
+
this.nullKeys.set(keyId.href, Temporal$10.Now.instant().add(this.unavailableKeyTtl));
|
|
3010
3025
|
return null;
|
|
3011
3026
|
}
|
|
3012
3027
|
try {
|
|
@@ -3022,7 +3037,7 @@ var KvKeyCache = class {
|
|
|
3022
3037
|
}
|
|
3023
3038
|
async set(keyId, key) {
|
|
3024
3039
|
if (key == null) {
|
|
3025
|
-
this.nullKeys.set(keyId.href, Temporal$
|
|
3040
|
+
this.nullKeys.set(keyId.href, Temporal$10.Now.instant().add(this.unavailableKeyTtl));
|
|
3026
3041
|
await this.kv.set(this.#entryKey(keyId), null, { ttl: this.unavailableKeyTtl });
|
|
3027
3042
|
return;
|
|
3028
3043
|
}
|
|
@@ -3041,7 +3056,7 @@ var KvKeyCache = class {
|
|
|
3041
3056
|
* @internal
|
|
3042
3057
|
*/
|
|
3043
3058
|
compatibleKeyScope(scope) {
|
|
3044
|
-
const now = this.options.now ?? (() => Temporal$
|
|
3059
|
+
const now = this.options.now ?? (() => Temporal$10.Now.instant());
|
|
3045
3060
|
const entryKey = (keyId) => [
|
|
3046
3061
|
...this.prefix,
|
|
3047
3062
|
COMPATIBLE_KEY_SEGMENT,
|
|
@@ -3061,7 +3076,7 @@ var KvKeyCache = class {
|
|
|
3061
3076
|
if (entry.key === null) return null;
|
|
3062
3077
|
let expires;
|
|
3063
3078
|
try {
|
|
3064
|
-
expires = Temporal$
|
|
3079
|
+
expires = Temporal$10.Instant.fromEpochMilliseconds(entry.expires);
|
|
3065
3080
|
} catch (error) {
|
|
3066
3081
|
if (!(error instanceof RangeError)) throw error;
|
|
3067
3082
|
await this.kv.delete(entryKey(keyId));
|
|
@@ -3106,8 +3121,8 @@ var KvKeyCache = class {
|
|
|
3106
3121
|
key: serialized,
|
|
3107
3122
|
expires,
|
|
3108
3123
|
...owner == null ? {} : { owner }
|
|
3109
|
-
}, { ttl: Temporal$
|
|
3110
|
-
return key == null ? void 0 : Temporal$
|
|
3124
|
+
}, { ttl: Temporal$10.Duration.from({ milliseconds: ttl }) });
|
|
3125
|
+
return key == null ? void 0 : Temporal$10.Instant.fromEpochMilliseconds(expires);
|
|
3111
3126
|
},
|
|
3112
3127
|
delete: async (keyId) => {
|
|
3113
3128
|
await this.kv.delete(entryKey(keyId));
|
|
@@ -3622,7 +3637,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
3622
3637
|
* @param parameters The parameters for sending the activity.
|
|
3623
3638
|
* See also {@link SendActivityParameters}.
|
|
3624
3639
|
* @param deps The dependencies, for tests.
|
|
3625
|
-
* @throws {
|
|
3640
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
3641
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
3626
3642
|
*/
|
|
3627
3643
|
function sendActivity(options, deps = {}) {
|
|
3628
3644
|
const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
|
|
@@ -3681,6 +3697,24 @@ async function sendActivityThroughGateways(parameters, inboxes) {
|
|
|
3681
3697
|
throw lastError;
|
|
3682
3698
|
}
|
|
3683
3699
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
3700
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
3701
|
+
function raceWithAbort(promise, signal) {
|
|
3702
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
3703
|
+
return new Promise((resolve, reject) => {
|
|
3704
|
+
const onAbort = () => {
|
|
3705
|
+
signal.removeEventListener("abort", onAbort);
|
|
3706
|
+
reject(signal.reason);
|
|
3707
|
+
};
|
|
3708
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3709
|
+
promise.then((value) => {
|
|
3710
|
+
signal.removeEventListener("abort", onAbort);
|
|
3711
|
+
resolve(value);
|
|
3712
|
+
}, (error) => {
|
|
3713
|
+
signal.removeEventListener("abort", onAbort);
|
|
3714
|
+
reject(error);
|
|
3715
|
+
});
|
|
3716
|
+
});
|
|
3717
|
+
}
|
|
3684
3718
|
function getActivityActorId(activity) {
|
|
3685
3719
|
if (!isRecord(activity)) return void 0;
|
|
3686
3720
|
return getIdValue(activity.actor);
|
|
@@ -3700,7 +3734,7 @@ function getIdValue(value) {
|
|
|
3700
3734
|
function isRecord(value) {
|
|
3701
3735
|
return typeof value === "object" && value != null;
|
|
3702
3736
|
}
|
|
3703
|
-
async function readLimitedResponseBody(response, maxBytes) {
|
|
3737
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
3704
3738
|
if (response.body == null) return "";
|
|
3705
3739
|
const reader = response.body.getReader();
|
|
3706
3740
|
const decoder = new TextDecoder();
|
|
@@ -3709,7 +3743,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
3709
3743
|
let truncated = false;
|
|
3710
3744
|
try {
|
|
3711
3745
|
while (true) {
|
|
3712
|
-
|
|
3746
|
+
signal.throwIfAborted();
|
|
3747
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
3713
3748
|
if (done) break;
|
|
3714
3749
|
if (totalBytes + value.length > maxBytes) {
|
|
3715
3750
|
const remaining = maxBytes - totalBytes;
|
|
@@ -3721,8 +3756,10 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
3721
3756
|
totalBytes += value.length;
|
|
3722
3757
|
}
|
|
3723
3758
|
} finally {
|
|
3724
|
-
if (truncated) reader.cancel().catch(() => {});
|
|
3725
|
-
|
|
3759
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
3760
|
+
try {
|
|
3761
|
+
reader.releaseLock();
|
|
3762
|
+
} catch (_) {}
|
|
3726
3763
|
}
|
|
3727
3764
|
let result = chunks.join("");
|
|
3728
3765
|
if (truncated) result += "… (truncated)";
|
|
@@ -3737,11 +3774,30 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3737
3774
|
const federationMetrics = require_http.getFederationMetrics(meterProvider);
|
|
3738
3775
|
const started = performance.now();
|
|
3739
3776
|
let deliverySuccess = false;
|
|
3740
|
-
const
|
|
3777
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
3778
|
+
const controller = new AbortController();
|
|
3779
|
+
const { signal } = controller;
|
|
3780
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
3781
|
+
function timeoutFailure(error) {
|
|
3782
|
+
if (!signal.aborted || error instanceof SendActivityError) return error;
|
|
3783
|
+
const failure = new _fedify_vocab_runtime.FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
3784
|
+
failure.cause = signal.reason;
|
|
3785
|
+
return failure;
|
|
3786
|
+
}
|
|
3787
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? _fedify_vocab_runtime_internal.openDirectFetch : (url) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(url, { signal }));
|
|
3741
3788
|
async function openHop(url) {
|
|
3742
3789
|
let session;
|
|
3743
3790
|
try {
|
|
3744
|
-
|
|
3791
|
+
signal.throwIfAborted();
|
|
3792
|
+
const opening = openUnvalidatedHop(url);
|
|
3793
|
+
opening.then((lateSession) => {
|
|
3794
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
3795
|
+
}, () => {});
|
|
3796
|
+
session = await raceWithAbort(opening, signal);
|
|
3797
|
+
if (signal.aborted) {
|
|
3798
|
+
closeAfterError(session, logger);
|
|
3799
|
+
signal.throwIfAborted();
|
|
3800
|
+
}
|
|
3745
3801
|
} catch (error) {
|
|
3746
3802
|
if (error instanceof _fedify_vocab_runtime.UrlError && error.reason === "dns") {
|
|
3747
3803
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -3764,8 +3820,15 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3764
3820
|
try {
|
|
3765
3821
|
initialSession = await openHop(inbox.href);
|
|
3766
3822
|
} catch (error) {
|
|
3767
|
-
|
|
3768
|
-
|
|
3823
|
+
const failure = timeoutFailure(error);
|
|
3824
|
+
if (failure instanceof _fedify_vocab_runtime.FetchError) federationMetrics.recordDelivery(inbox, require_http.getDurationMs(started), false, activityType);
|
|
3825
|
+
if (signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
3826
|
+
activityId,
|
|
3827
|
+
inbox: inbox.href,
|
|
3828
|
+
error: failure
|
|
3829
|
+
});
|
|
3830
|
+
clearTimeout(timer);
|
|
3831
|
+
throw failure;
|
|
3769
3832
|
}
|
|
3770
3833
|
let initialPending = true;
|
|
3771
3834
|
const openDeliveryHop = (url) => {
|
|
@@ -3782,7 +3845,8 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3782
3845
|
method: "POST",
|
|
3783
3846
|
headers,
|
|
3784
3847
|
body: JSON.stringify(activity),
|
|
3785
|
-
redirect: "manual"
|
|
3848
|
+
redirect: "manual",
|
|
3849
|
+
signal
|
|
3786
3850
|
});
|
|
3787
3851
|
let rsaKey = null;
|
|
3788
3852
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -3801,13 +3865,35 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3801
3865
|
}))
|
|
3802
3866
|
});
|
|
3803
3867
|
let outcome;
|
|
3868
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
3869
|
+
determineSpec(origin) {
|
|
3870
|
+
signal.throwIfAborted();
|
|
3871
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
3872
|
+
},
|
|
3873
|
+
rememberSpec(origin, spec) {
|
|
3874
|
+
if (signal.aborted) return;
|
|
3875
|
+
try {
|
|
3876
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3877
|
+
origin,
|
|
3878
|
+
error
|
|
3879
|
+
}));
|
|
3880
|
+
} catch (error) {
|
|
3881
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3882
|
+
origin,
|
|
3883
|
+
error
|
|
3884
|
+
});
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3804
3888
|
try {
|
|
3805
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox)) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
3889
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
3806
3890
|
tracerProvider,
|
|
3807
|
-
specDeterminer
|
|
3808
|
-
|
|
3891
|
+
specDeterminer: boundedSpecDeterminer,
|
|
3892
|
+
signal
|
|
3893
|
+
}, openDeliveryHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
3809
3894
|
} catch (error) {
|
|
3810
|
-
const
|
|
3895
|
+
const boundedError = timeoutFailure(error);
|
|
3896
|
+
const failure = boundedError instanceof _fedify_vocab_runtime.FetchError || boundedError instanceof _fedify_vocab_runtime.UrlError ? boundedError : createFetchError(inbox.href, boundedError);
|
|
3811
3897
|
logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
3812
3898
|
activityId,
|
|
3813
3899
|
inbox: inbox.href,
|
|
@@ -3841,6 +3927,7 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
3841
3927
|
federationMetrics.recordDelivery(inbox, require_http.getDurationMs(started), deliverySuccess, activityType);
|
|
3842
3928
|
}
|
|
3843
3929
|
} finally {
|
|
3930
|
+
clearTimeout(timer);
|
|
3844
3931
|
if (initialPending) await initialSession.close();
|
|
3845
3932
|
}
|
|
3846
3933
|
}
|
|
@@ -3872,17 +3959,18 @@ function cancelResponseBody(response, url) {
|
|
|
3872
3959
|
* session is open: the body of a successful response is cancelled, and at
|
|
3873
3960
|
* most 1 KiB of an error response body is read.
|
|
3874
3961
|
*/
|
|
3875
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
3962
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
3876
3963
|
if (response.ok) {
|
|
3877
3964
|
cancelResponseBody(response, response.url || inbox.href);
|
|
3878
3965
|
return { ok: true };
|
|
3879
3966
|
}
|
|
3880
3967
|
let error;
|
|
3881
3968
|
try {
|
|
3882
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
3969
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
3883
3970
|
} catch (_) {
|
|
3884
3971
|
error = "";
|
|
3885
3972
|
}
|
|
3973
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
3886
3974
|
return {
|
|
3887
3975
|
ok: false,
|
|
3888
3976
|
status: response.status,
|
|
@@ -3902,7 +3990,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
3902
3990
|
* @param consume The function to consume the final response.
|
|
3903
3991
|
* @returns The value returned by `consume`.
|
|
3904
3992
|
*/
|
|
3905
|
-
async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
3993
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
3906
3994
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
3907
3995
|
"fedify",
|
|
3908
3996
|
"federation",
|
|
@@ -3910,10 +3998,14 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
3910
3998
|
]);
|
|
3911
3999
|
let body = await request.clone().text();
|
|
3912
4000
|
for (let redirects = 0;; redirects++) {
|
|
4001
|
+
signal?.throwIfAborted();
|
|
3913
4002
|
const session = await openHop(request.url);
|
|
3914
4003
|
let response;
|
|
3915
4004
|
try {
|
|
3916
|
-
response = await session.fetch(request, {
|
|
4005
|
+
response = await session.fetch(request, {
|
|
4006
|
+
redirect: "manual",
|
|
4007
|
+
signal
|
|
4008
|
+
});
|
|
3917
4009
|
} catch (error) {
|
|
3918
4010
|
await closeAfterError(session, logger);
|
|
3919
4011
|
throw error;
|
|
@@ -3963,7 +4055,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
3963
4055
|
method,
|
|
3964
4056
|
headers,
|
|
3965
4057
|
body,
|
|
3966
|
-
redirect: "manual"
|
|
4058
|
+
redirect: "manual",
|
|
4059
|
+
signal: signal ?? request.signal
|
|
3967
4060
|
});
|
|
3968
4061
|
}
|
|
3969
4062
|
}
|
|
@@ -4023,7 +4116,7 @@ var SendActivityError = class extends Error {
|
|
|
4023
4116
|
};
|
|
4024
4117
|
//#endregion
|
|
4025
4118
|
//#region src/federation/portable-inbox.ts
|
|
4026
|
-
const Temporal$
|
|
4119
|
+
const Temporal$9 = require_http.Temporal;
|
|
4027
4120
|
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
4028
4121
|
/**
|
|
4029
4122
|
* Fills in the defaults of {@link PortableInboxForwardingOptions} and
|
|
@@ -4039,9 +4132,9 @@ const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
|
4039
4132
|
function resolvePortableInboxForwardingOptions(options = {}) {
|
|
4040
4133
|
const maxTargets = options.maxTargets ?? 10;
|
|
4041
4134
|
if (!Number.isInteger(maxTargets) || maxTargets < 0) throw new RangeError("portableInboxForwarding.maxTargets must be a non-negative integer.");
|
|
4042
|
-
const ttl = Temporal$
|
|
4135
|
+
const ttl = Temporal$9.Duration.from(options.ttl ?? { days: 30 });
|
|
4043
4136
|
if (ttl.total("millisecond") <= 0) throw new RangeError("portableInboxForwarding.ttl must be positive.");
|
|
4044
|
-
const deadline = Temporal$
|
|
4137
|
+
const deadline = Temporal$9.Duration.from(options.deadline ?? { seconds: 10 });
|
|
4045
4138
|
const deadlineMs = deadline.total("millisecond");
|
|
4046
4139
|
if (deadlineMs < 0 || deadlineMs > MAX_TIMEOUT_MS) throw new RangeError(`portableInboxForwarding.deadline must be between 0 and ${MAX_TIMEOUT_MS} milliseconds.`);
|
|
4047
4140
|
return {
|
|
@@ -4433,17 +4526,14 @@ async function enqueueForwarding(parameters, outboxQueue, inboxes) {
|
|
|
4433
4526
|
}
|
|
4434
4527
|
//#endregion
|
|
4435
4528
|
//#region src/federation/temporal.ts
|
|
4436
|
-
const Temporal$
|
|
4529
|
+
const Temporal$8 = require_http.Temporal;
|
|
4437
4530
|
function isPlainObject$1(value) {
|
|
4438
4531
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
4439
4532
|
}
|
|
4440
|
-
function normalizeDateTimeLiteral(value) {
|
|
4441
|
-
return value.substring(19).match(/[Z+-]/) ? value : value + "Z";
|
|
4442
|
-
}
|
|
4443
4533
|
function isMalformedDateTimeLiteral(value) {
|
|
4444
4534
|
if (typeof value !== "string") return false;
|
|
4445
4535
|
try {
|
|
4446
|
-
Temporal$
|
|
4536
|
+
Temporal$8.Instant.from((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(value));
|
|
4447
4537
|
return false;
|
|
4448
4538
|
} catch {
|
|
4449
4539
|
return true;
|
|
@@ -4452,7 +4542,7 @@ function isMalformedDateTimeLiteral(value) {
|
|
|
4452
4542
|
function isMalformedDurationLiteral(value) {
|
|
4453
4543
|
if (typeof value !== "string") return false;
|
|
4454
4544
|
try {
|
|
4455
|
-
Temporal$
|
|
4545
|
+
Temporal$8.Duration.from(value);
|
|
4456
4546
|
return false;
|
|
4457
4547
|
} catch {
|
|
4458
4548
|
return true;
|
|
@@ -4481,7 +4571,7 @@ function hasMalformedExpandedQuestionClosedLiteral(value) {
|
|
|
4481
4571
|
if (typeof literal === "boolean") return false;
|
|
4482
4572
|
if (typeof literal !== "string") return false;
|
|
4483
4573
|
if (value["@type"] !== XSD_DATE_TIME_IRI) return false;
|
|
4484
|
-
if (new Date(literal).toString() === "Invalid Date") return false;
|
|
4574
|
+
if (new Date(literal).toString() === "Invalid Date" && new Date((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(literal)).toString() === "Invalid Date") return false;
|
|
4485
4575
|
return isMalformedDateTimeLiteral(literal);
|
|
4486
4576
|
}
|
|
4487
4577
|
function hasMalformedExpandedDurationLiteral(value) {
|
|
@@ -4523,7 +4613,7 @@ async function hasMalformedKnownTemporalLiteral(value, contextLoader) {
|
|
|
4523
4613
|
}
|
|
4524
4614
|
//#endregion
|
|
4525
4615
|
//#region src/federation/handler.ts
|
|
4526
|
-
const Temporal$
|
|
4616
|
+
const Temporal$7 = require_http.Temporal;
|
|
4527
4617
|
const rawInboxContextFactorySymbol = Symbol("fedify.rawInboxContextFactory");
|
|
4528
4618
|
const INBOX_COMPOUND_PROOF_LIMITS = {
|
|
4529
4619
|
maxDepth: 64,
|
|
@@ -4583,7 +4673,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
4583
4673
|
if (!await authorizePredicate(context, identifier)) return await onUnauthorized(request);
|
|
4584
4674
|
}
|
|
4585
4675
|
if (actor instanceof _fedify_vocab.Tombstone) {
|
|
4586
|
-
const jsonLd = await actor
|
|
4676
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
4587
4677
|
return new Response(JSON.stringify(jsonLd), {
|
|
4588
4678
|
status: 410,
|
|
4589
4679
|
headers: {
|
|
@@ -4592,7 +4682,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
4592
4682
|
}
|
|
4593
4683
|
});
|
|
4594
4684
|
}
|
|
4595
|
-
const jsonLd = await actor
|
|
4685
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
4596
4686
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
4597
4687
|
"Content-Type": "application/activity+json",
|
|
4598
4688
|
Vary: "Accept"
|
|
@@ -4612,7 +4702,7 @@ async function handleObject(request, { values, context, objectDispatcher, author
|
|
|
4612
4702
|
if (authorizePredicate != null) {
|
|
4613
4703
|
if (!await authorizePredicate(context, values)) return await onUnauthorized(request);
|
|
4614
4704
|
}
|
|
4615
|
-
const jsonLd = await object
|
|
4705
|
+
const jsonLd = await serializeForResponse(object, context);
|
|
4616
4706
|
if (object instanceof _fedify_vocab.Tombstone) return new Response(request.method === "HEAD" ? null : JSON.stringify(jsonLd), {
|
|
4617
4707
|
status: 410,
|
|
4618
4708
|
headers: {
|
|
@@ -5018,7 +5108,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
5018
5108
|
if (portable == null && collectionCallbacks.authorizePredicate != null) {
|
|
5019
5109
|
if (!await collectionCallbacks.authorizePredicate(context, identifier)) return finish(await onUnauthorized(request), "unauthorized");
|
|
5020
5110
|
}
|
|
5021
|
-
const jsonLd = await collection
|
|
5111
|
+
const jsonLd = await serializeForResponse(collection, context, portable != null);
|
|
5022
5112
|
if (portable != null) return await verifyPortableCollection(jsonLd, context, portable) ? finish(respondWithPortableCollection(request, jsonLd), "served") : finish(portableObjectInternalServerError(request), "error");
|
|
5023
5113
|
return finish(new Response(JSON.stringify(jsonLd), { headers: {
|
|
5024
5114
|
"Content-Type": "application/activity+json",
|
|
@@ -5608,7 +5698,11 @@ async function handleInboxInternal(request, parameters, span) {
|
|
|
5608
5698
|
keyTtl: publicKeyTtl
|
|
5609
5699
|
});
|
|
5610
5700
|
const jsonWithoutSig = require_http.detachSignature(json);
|
|
5611
|
-
const hasLdSignature = require_http.
|
|
5701
|
+
const hasLdSignature = require_http.hasVerifiableSignature(json);
|
|
5702
|
+
if (!hasLdSignature) {
|
|
5703
|
+
const shape = require_http.describeSignatureShape(json);
|
|
5704
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
5705
|
+
}
|
|
5612
5706
|
const canAttemptAlternateAuthAfterLdSignatureFailure = skipSignatureVerification || hasHttpSignatureHeaders(request) || hasObjectIntegrityProof(jsonWithoutSig);
|
|
5613
5707
|
let deferredLdSignatureError = void 0;
|
|
5614
5708
|
const respondInvalidActivity = async (error) => {
|
|
@@ -6411,7 +6505,7 @@ var CustomCollectionHandler = class {
|
|
|
6411
6505
|
* @returns A promise that resolves to the JSON-LD representation.
|
|
6412
6506
|
*/
|
|
6413
6507
|
async toJsonLd() {
|
|
6414
|
-
return (await this.collection
|
|
6508
|
+
return serializeForResponse(await this.collection, this.context, this.portable != null);
|
|
6415
6509
|
}
|
|
6416
6510
|
/**
|
|
6417
6511
|
* Fetches the collection with optional cursor for pagination.
|
|
@@ -6807,7 +6901,7 @@ var PortableCollectionRefusedError = class extends HandlerError {
|
|
|
6807
6901
|
* @since 0.3.0
|
|
6808
6902
|
*/
|
|
6809
6903
|
async function respondWithObject(object, options) {
|
|
6810
|
-
const jsonLd = await object
|
|
6904
|
+
const jsonLd = await serializeForResponse(object, options);
|
|
6811
6905
|
return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
|
|
6812
6906
|
}
|
|
6813
6907
|
/**
|
|
@@ -6881,7 +6975,7 @@ async function buildAcceptSignatureHeader(policy, kv, noncePrefix) {
|
|
|
6881
6975
|
}
|
|
6882
6976
|
async function setKey(kv, key, policy) {
|
|
6883
6977
|
const seconds = policy.nonceTtlSeconds ?? 300;
|
|
6884
|
-
const ttl = Temporal$
|
|
6978
|
+
const ttl = Temporal$7.Duration.from({ seconds });
|
|
6885
6979
|
await kv.set(key, true, { ttl });
|
|
6886
6980
|
}
|
|
6887
6981
|
const DEF_COMPONENTS = [
|
|
@@ -6904,6 +6998,13 @@ const MIN_COMPONENTS = [
|
|
|
6904
6998
|
function isPortableActorKey(key) {
|
|
6905
6999
|
return key?.id != null && require_http.isPortableKeyId(key.id) && key.ownerId != null && require_http.isPortableId(key.ownerId);
|
|
6906
7000
|
}
|
|
7001
|
+
/** Applies compatibility changes after ordinary vocabulary serialization. */
|
|
7002
|
+
async function serializeForResponse(object, options, compact = false) {
|
|
7003
|
+
return await normalizeAttachmentArrays(await object.toJsonLd(compact ? {
|
|
7004
|
+
format: "compact",
|
|
7005
|
+
contextLoader: options?.contextLoader
|
|
7006
|
+
} : options), options?.contextLoader);
|
|
7007
|
+
}
|
|
6907
7008
|
/**
|
|
6908
7009
|
* Checks whether an activity needs an Object Integrity Proof by its DID:
|
|
6909
7010
|
* either it is performed by an [FEP-ef61] portable actor, or its own ID is
|
|
@@ -6940,7 +7041,7 @@ async function verifyPortableActivityId(activityId, jsonLd, options) {
|
|
|
6940
7041
|
}
|
|
6941
7042
|
//#endregion
|
|
6942
7043
|
//#region src/federation/kv.ts
|
|
6943
|
-
const Temporal$
|
|
7044
|
+
const Temporal$6 = require_http.Temporal;
|
|
6944
7045
|
/**
|
|
6945
7046
|
* A key–value store that stores values in memory.
|
|
6946
7047
|
* Do not use this in production as it does not persist values.
|
|
@@ -6960,7 +7061,7 @@ var MemoryKvStore = class {
|
|
|
6960
7061
|
const entry = this.#values[encodedKey];
|
|
6961
7062
|
if (entry == null) return Promise.resolve(void 0);
|
|
6962
7063
|
const [value, expiration] = entry;
|
|
6963
|
-
if (expiration != null && Temporal$
|
|
7064
|
+
if (expiration != null && Temporal$6.Now.instant().until(expiration).sign < 0) {
|
|
6964
7065
|
delete this.#values[encodedKey];
|
|
6965
7066
|
return Promise.resolve(void 0);
|
|
6966
7067
|
}
|
|
@@ -6971,7 +7072,7 @@ var MemoryKvStore = class {
|
|
|
6971
7072
|
*/
|
|
6972
7073
|
set(key, value, options) {
|
|
6973
7074
|
const encodedKey = this.#encodeKey(key);
|
|
6974
|
-
const expiration = options?.ttl == null ? null : Temporal$
|
|
7075
|
+
const expiration = options?.ttl == null ? null : Temporal$6.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
|
|
6975
7076
|
this.#values[encodedKey] = [value, expiration];
|
|
6976
7077
|
return Promise.resolve();
|
|
6977
7078
|
}
|
|
@@ -6993,13 +7094,13 @@ var MemoryKvStore = class {
|
|
|
6993
7094
|
if (entry == null) currentValue = void 0;
|
|
6994
7095
|
else {
|
|
6995
7096
|
const [value, expiration] = entry;
|
|
6996
|
-
if (expiration != null && Temporal$
|
|
7097
|
+
if (expiration != null && Temporal$6.Now.instant().until(expiration).sign < 0) {
|
|
6997
7098
|
delete this.#values[encodedKey];
|
|
6998
7099
|
currentValue = void 0;
|
|
6999
7100
|
} else currentValue = value;
|
|
7000
7101
|
}
|
|
7001
7102
|
if (!(0, es_toolkit.isEqual)(currentValue, expectedValue)) return Promise.resolve(false);
|
|
7002
|
-
const expiration = options?.ttl == null ? null : Temporal$
|
|
7103
|
+
const expiration = options?.ttl == null ? null : Temporal$6.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
|
|
7003
7104
|
this.#values[encodedKey] = [newValue, expiration];
|
|
7004
7105
|
return Promise.resolve(true);
|
|
7005
7106
|
}
|
|
@@ -7007,7 +7108,7 @@ var MemoryKvStore = class {
|
|
|
7007
7108
|
* {@inheritDoc KvStore.list}
|
|
7008
7109
|
*/
|
|
7009
7110
|
async *list(prefix) {
|
|
7010
|
-
const now = Temporal$
|
|
7111
|
+
const now = Temporal$6.Now.instant();
|
|
7011
7112
|
for (const [encodedKey, entry] of Object.entries(this.#values)) {
|
|
7012
7113
|
const key = JSON.parse(encodedKey);
|
|
7013
7114
|
if (prefix != null) {
|
|
@@ -7351,6 +7452,103 @@ function buildPortableCollectionView(collectionId, requestUrl) {
|
|
|
7351
7452
|
return view;
|
|
7352
7453
|
}
|
|
7353
7454
|
//#endregion
|
|
7455
|
+
//#region src/sig/proof-creation.ts
|
|
7456
|
+
const Temporal$5 = require_http.Temporal;
|
|
7457
|
+
/** Signs the exact serialized message supplied by an internal producer. */
|
|
7458
|
+
async function createProofForJsonLd(jsonLd, privateKey, keyId, created) {
|
|
7459
|
+
require_http.validateCryptoKey(privateKey, "private");
|
|
7460
|
+
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
7461
|
+
const encoder = new TextEncoder();
|
|
7462
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(jsonLd)));
|
|
7463
|
+
created ??= Temporal$5.Now.instant();
|
|
7464
|
+
const proofConfig = {
|
|
7465
|
+
"@context": jsonLd["@context"],
|
|
7466
|
+
type: "DataIntegrityProof",
|
|
7467
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7468
|
+
verificationMethod: keyId.href,
|
|
7469
|
+
proofPurpose: "assertionMethod",
|
|
7470
|
+
created: created.toString()
|
|
7471
|
+
};
|
|
7472
|
+
const proofDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(proofConfig)));
|
|
7473
|
+
const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
|
|
7474
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
7475
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
7476
|
+
const sig = await crypto.subtle.sign("Ed25519", (0, _fedify_vocab_runtime_internal.asCryptoKey)(privateKey), digest);
|
|
7477
|
+
return new _fedify_vocab.DataIntegrityProof({
|
|
7478
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7479
|
+
verificationMethod: keyId,
|
|
7480
|
+
proofPurpose: "assertionMethod",
|
|
7481
|
+
created,
|
|
7482
|
+
proofValue: new Uint8Array(sig)
|
|
7483
|
+
});
|
|
7484
|
+
}
|
|
7485
|
+
//#endregion
|
|
7486
|
+
//#region src/compat/delivery-jsonld.ts
|
|
7487
|
+
/**
|
|
7488
|
+
* Returns changed wire JSON only; unchanged documents keep the existing
|
|
7489
|
+
* delivery signing path. This uses ordinary vocabulary serialization, without
|
|
7490
|
+
* retaining or repairing independently signed child representations.
|
|
7491
|
+
*/
|
|
7492
|
+
async function prepareActivityJsonLd(activity, contextLoader) {
|
|
7493
|
+
if (activity.proofIds.length > 0) return void 0;
|
|
7494
|
+
for await (const _ of activity.getProofs({ contextLoader })) return void 0;
|
|
7495
|
+
const source = await activity.clone({}, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) }).toJsonLd({
|
|
7496
|
+
format: "compact",
|
|
7497
|
+
contextLoader
|
|
7498
|
+
});
|
|
7499
|
+
const prepared = await require_http.normalizeOutgoingActivityJsonLd(source, contextLoader, { preserveSecuredDocuments: true });
|
|
7500
|
+
return prepared !== source && typeof prepared === "object" && prepared != null && !Array.isArray(prepared) ? prepared : void 0;
|
|
7501
|
+
}
|
|
7502
|
+
/** Signs a changed, proof-free delivery map without serializing it again. */
|
|
7503
|
+
async function signActivityJsonLd(activity, unsigned, keys, options) {
|
|
7504
|
+
const proofs = [];
|
|
7505
|
+
const serializedProofs = [];
|
|
7506
|
+
const tracer = (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version);
|
|
7507
|
+
for (const { privateKey, keyId } of keys) {
|
|
7508
|
+
const proof = await tracer.startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": (0, _fedify_vocab.getTypeId)(activity).href } }, async (span) => {
|
|
7509
|
+
try {
|
|
7510
|
+
if (activity.id != null) span.setAttribute("activitypub.object.id", activity.id.href);
|
|
7511
|
+
const proof = await createProofForJsonLd(unsigned, privateKey, keyId);
|
|
7512
|
+
if (span.isRecording()) {
|
|
7513
|
+
span.setAttribute("object_integrity_proofs.cryptosuite", "eddsa-jcs-2022");
|
|
7514
|
+
span.setAttribute("object_integrity_proofs.key_id", keyId.href);
|
|
7515
|
+
span.setAttribute("object_integrity_proofs.signature", (0, byte_encodings_hex.encodeHex)(proof.proofValue));
|
|
7516
|
+
}
|
|
7517
|
+
return proof;
|
|
7518
|
+
} catch (error) {
|
|
7519
|
+
span.setStatus({
|
|
7520
|
+
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
7521
|
+
message: String(error)
|
|
7522
|
+
});
|
|
7523
|
+
throw error;
|
|
7524
|
+
} finally {
|
|
7525
|
+
span.end();
|
|
7526
|
+
}
|
|
7527
|
+
});
|
|
7528
|
+
proofs.push(proof);
|
|
7529
|
+
serializedProofs.push({
|
|
7530
|
+
"@context": unsigned["@context"],
|
|
7531
|
+
type: "DataIntegrityProof",
|
|
7532
|
+
cryptosuite: proof.cryptosuite,
|
|
7533
|
+
verificationMethod: keyId.href,
|
|
7534
|
+
proofPurpose: "assertionMethod",
|
|
7535
|
+
created: proof.created.toString(),
|
|
7536
|
+
proofValue: new TextDecoder().decode((0, _fedify_vocab_runtime.encodeMultibase)("base58btc", proof.proofValue))
|
|
7537
|
+
});
|
|
7538
|
+
}
|
|
7539
|
+
if (proofs.length === 0) return {
|
|
7540
|
+
activity,
|
|
7541
|
+
jsonLd: unsigned
|
|
7542
|
+
};
|
|
7543
|
+
return {
|
|
7544
|
+
activity: activity.clone({ proofs }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) }),
|
|
7545
|
+
jsonLd: {
|
|
7546
|
+
...unsigned,
|
|
7547
|
+
proof: serializedProofs.length === 1 ? serializedProofs[0] : serializedProofs
|
|
7548
|
+
}
|
|
7549
|
+
};
|
|
7550
|
+
}
|
|
7551
|
+
//#endregion
|
|
7354
7552
|
//#region src/federation/outgoing-proof.ts
|
|
7355
7553
|
function formatKeyIds(candidates) {
|
|
7356
7554
|
return candidates.map((c) => c.verificationMethod.href).join(", ");
|
|
@@ -7418,6 +7616,15 @@ async function signOutgoingActivity(activity, candidates, options) {
|
|
|
7418
7616
|
const { contextLoader, tracerProvider } = options;
|
|
7419
7617
|
assertPortableActorActivity(activity);
|
|
7420
7618
|
const sign = async (selected) => {
|
|
7619
|
+
const prepared = !hasProof ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
|
|
7620
|
+
if (prepared != null) return {
|
|
7621
|
+
...await signActivityJsonLd(activity, prepared, selected.map(({ verificationMethod, privateKey }) => ({
|
|
7622
|
+
keyId: verificationMethod,
|
|
7623
|
+
privateKey
|
|
7624
|
+
})), { tracerProvider: tracerProvider ?? _opentelemetry_api.trace.getTracerProvider() }),
|
|
7625
|
+
hasProof: true,
|
|
7626
|
+
proofCreated: true
|
|
7627
|
+
};
|
|
7421
7628
|
for (const { verificationMethod, privateKey } of selected) activity = await require_http.signObject(activity, privateKey, verificationMethod, {
|
|
7422
7629
|
contextLoader,
|
|
7423
7630
|
tracerProvider
|
|
@@ -8585,6 +8792,13 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
8585
8792
|
if (resolved != null) return resolved;
|
|
8586
8793
|
return this.taskQueueResolution === "strict" ? void 0 : this.outboxQueue;
|
|
8587
8794
|
}
|
|
8795
|
+
#listenQueue(queue, ctxData, signal) {
|
|
8796
|
+
try {
|
|
8797
|
+
return queue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal });
|
|
8798
|
+
} catch (error) {
|
|
8799
|
+
return Promise.reject(error);
|
|
8800
|
+
}
|
|
8801
|
+
}
|
|
8588
8802
|
async _startQueueInternal(ctxData, signal, queue) {
|
|
8589
8803
|
const taskQueue = this.taskQueue ?? (this.taskQueueResolution === "fallback" ? this.outboxQueue : void 0);
|
|
8590
8804
|
const customQueues = this.taskDefinitions.values().map((def) => ["task", def.queue]);
|
|
@@ -8606,10 +8820,31 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
8606
8820
|
if (this.startedQueues.has(target)) continue;
|
|
8607
8821
|
this.startedQueues.add(target);
|
|
8608
8822
|
logger.debug("Starting a {role} queue worker.", { role });
|
|
8609
|
-
promises.push(
|
|
8823
|
+
promises.push(this.#listenQueue(target, ctxData, signal));
|
|
8610
8824
|
}
|
|
8611
8825
|
await Promise.all(promises);
|
|
8612
8826
|
}
|
|
8827
|
+
/**
|
|
8828
|
+
* Starts the queue workers automatically, reporting a failure instead of
|
|
8829
|
+
* leaving the returned promise unobserved.
|
|
8830
|
+
*
|
|
8831
|
+
* Automatic startup is best-effort: call sites cannot await it, so a failing
|
|
8832
|
+
* listener (e.g., `WorkersMessageQueue`, whose `listen()` throws) must not
|
|
8833
|
+
* become an unhandled rejection. {@link startQueue} keeps rejecting for
|
|
8834
|
+
* callers that start workers deliberately.
|
|
8835
|
+
*/
|
|
8836
|
+
#queueStartupFailureReported = false;
|
|
8837
|
+
_startQueueAutomatically(ctxData) {
|
|
8838
|
+
this._startQueueInternal(ctxData).catch((error) => {
|
|
8839
|
+
if (this.#queueStartupFailureReported) return;
|
|
8840
|
+
this.#queueStartupFailureReported = true;
|
|
8841
|
+
(0, _logtape_logtape.getLogger)([
|
|
8842
|
+
"fedify",
|
|
8843
|
+
"federation",
|
|
8844
|
+
"queue"
|
|
8845
|
+
]).warn("Failed to start queue workers automatically: {error}", { error });
|
|
8846
|
+
});
|
|
8847
|
+
}
|
|
8613
8848
|
processQueuedTask(contextData, message) {
|
|
8614
8849
|
const extractedContext = _opentelemetry_api.propagation.extract(_opentelemetry_api.context.active(), message.traceContext);
|
|
8615
8850
|
return (0, _logtape_logtape.withContext)({ messageId: message.id }, async () => {
|
|
@@ -9488,7 +9723,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9488
9723
|
let parseInput = void 0;
|
|
9489
9724
|
let parseContextLoader = context.contextLoader;
|
|
9490
9725
|
try {
|
|
9491
|
-
const hasSignatureField = require_http.
|
|
9726
|
+
const hasSignatureField = require_http.hasVerifiableSignature(message.activity);
|
|
9492
9727
|
const shouldParseFromNormalizedSignedPayload = message.ldSignatureVerified === true || message.normalizedActivity != null || message.ldSignatureVerified == null && hasSignatureField;
|
|
9493
9728
|
const parseContext = hasSignatureField ? {
|
|
9494
9729
|
...context,
|
|
@@ -9805,11 +10040,11 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9805
10040
|
});
|
|
9806
10041
|
activity = signed.activity;
|
|
9807
10042
|
const { hasProof, proofCreated } = signed;
|
|
9808
|
-
let jsonLd = !proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
10043
|
+
let jsonLd = signed.jsonLd ?? (!proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
9809
10044
|
format: "compact",
|
|
9810
10045
|
contextLoader
|
|
9811
|
-
});
|
|
9812
|
-
if (proofCreated || !hasProof || options.normalizeExistingProofs) jsonLd = await require_http.normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, { preserveNestedSecuredDocuments: true });
|
|
10046
|
+
}));
|
|
10047
|
+
if (signed.jsonLd == null && (proofCreated || !hasProof || options.normalizeExistingProofs)) jsonLd = await require_http.normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, { preserveNestedSecuredDocuments: true });
|
|
9813
10048
|
assertSupportedCompoundProofShape(jsonLd, activityId);
|
|
9814
10049
|
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 });
|
|
9815
10050
|
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.", {
|
|
@@ -9848,19 +10083,27 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9848
10083
|
activity: jsonLd
|
|
9849
10084
|
});
|
|
9850
10085
|
const promises = [];
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
10086
|
+
try {
|
|
10087
|
+
for (const inbox in inboxes) {
|
|
10088
|
+
const promise = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
10089
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
|
10090
|
+
keys,
|
|
10091
|
+
activity: jsonLd,
|
|
10092
|
+
activityId: activity.id?.href,
|
|
10093
|
+
activityType: (0, _fedify_vocab.getTypeId)(activity).href,
|
|
10094
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
10095
|
+
headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
|
|
10096
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
10097
|
+
meterProvider: this.meterProvider,
|
|
10098
|
+
tracerProvider: this.tracerProvider
|
|
10099
|
+
});
|
|
10100
|
+
promise.catch(() => {});
|
|
10101
|
+
promises.push(promise);
|
|
10102
|
+
}
|
|
10103
|
+
await Promise.all(promises);
|
|
10104
|
+
} finally {
|
|
10105
|
+
await Promise.allSettled(promises);
|
|
10106
|
+
}
|
|
9864
10107
|
return;
|
|
9865
10108
|
}
|
|
9866
10109
|
logger.debug("Enqueuing activity {activityId} to send later.", {
|
|
@@ -9875,7 +10118,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
9875
10118
|
privateKey: privateKeyJwk
|
|
9876
10119
|
});
|
|
9877
10120
|
}
|
|
9878
|
-
if (!this.manuallyStartQueue) this.
|
|
10121
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(ctx.data);
|
|
9879
10122
|
const carrier = {};
|
|
9880
10123
|
_opentelemetry_api.propagation.inject(_opentelemetry_api.context.active(), carrier);
|
|
9881
10124
|
const messages = [];
|
|
@@ -10555,7 +10798,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
10555
10798
|
return await observation.run(() => Promise.reject(error), span);
|
|
10556
10799
|
}
|
|
10557
10800
|
async #handleInbox(request, { recipient, context, contextData, onNotFound, portableInbox, observation }) {
|
|
10558
|
-
if (!this.manuallyStartQueue) this.
|
|
10801
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(contextData);
|
|
10559
10802
|
const inboxContextFactory = context.toInboxContext.bind(context);
|
|
10560
10803
|
inboxContextFactory[rawInboxContextFactorySymbol] = context.toInboxContext.bind(context);
|
|
10561
10804
|
return await handleInbox(request, {
|
|
@@ -10668,7 +10911,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
10668
10911
|
kv: this.kv,
|
|
10669
10912
|
kvPrefix: this.kvPrefixes.portableInboxForwarding,
|
|
10670
10913
|
outboxQueue: this.outboxQueue,
|
|
10671
|
-
startQueue: this.manuallyStartQueue ? void 0 : () => this.
|
|
10914
|
+
startQueue: this.manuallyStartQueue ? void 0 : () => this._startQueueAutomatically(contextData),
|
|
10672
10915
|
allowPrivateAddress: this.allowPrivateAddress,
|
|
10673
10916
|
getKeys: () => this.#getPortableGatewayKeyPairs(context, identifier, recipient),
|
|
10674
10917
|
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
@@ -11174,6 +11417,8 @@ var ContextImpl = class ContextImpl {
|
|
|
11174
11417
|
for (const keyPair of keyPairs) {
|
|
11175
11418
|
const newPair = {
|
|
11176
11419
|
...keyPair,
|
|
11420
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.privateKey),
|
|
11421
|
+
publicKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.publicKey),
|
|
11177
11422
|
cryptographicKey: new _fedify_vocab.CryptographicKey({
|
|
11178
11423
|
id: keyPair.keyId,
|
|
11179
11424
|
owner,
|
|
@@ -11271,10 +11516,16 @@ var ContextImpl = class ContextImpl {
|
|
|
11271
11516
|
} else identifierPromise = Promise.resolve(identity.identifier);
|
|
11272
11517
|
return identifierPromise.then((identifier) => {
|
|
11273
11518
|
if (identifier == null) return this.documentLoader;
|
|
11274
|
-
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(
|
|
11519
|
+
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory({
|
|
11520
|
+
keyId: pair.keyId,
|
|
11521
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(pair.privateKey)
|
|
11522
|
+
}));
|
|
11275
11523
|
});
|
|
11276
11524
|
}
|
|
11277
|
-
return this.federation.authenticatedDocumentLoaderFactory(
|
|
11525
|
+
return this.federation.authenticatedDocumentLoaderFactory({
|
|
11526
|
+
keyId: identity.keyId,
|
|
11527
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(identity.privateKey)
|
|
11528
|
+
});
|
|
11278
11529
|
}
|
|
11279
11530
|
lookupObject(identifier, options = {}) {
|
|
11280
11531
|
return (0, _fedify_vocab.lookupObject)(identifier, {
|
|
@@ -11300,10 +11551,14 @@ var ContextImpl = class ContextImpl {
|
|
|
11300
11551
|
return options.parse === "none" ? require_types.getNodeInfo(url, {
|
|
11301
11552
|
parse: "none",
|
|
11302
11553
|
direct: options.direct,
|
|
11554
|
+
timeout: options.timeout,
|
|
11555
|
+
signal: options.signal,
|
|
11303
11556
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
11304
11557
|
}) : require_types.getNodeInfo(url, {
|
|
11305
11558
|
parse: options.parse,
|
|
11306
11559
|
direct: options.direct,
|
|
11560
|
+
timeout: options.timeout,
|
|
11561
|
+
signal: options.signal,
|
|
11307
11562
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
11308
11563
|
});
|
|
11309
11564
|
}
|
|
@@ -11322,7 +11577,17 @@ var ContextImpl = class ContextImpl {
|
|
|
11322
11577
|
async enqueueTaskMany(task, payloads, options = {}) {
|
|
11323
11578
|
await this.#enqueueTasks(task, payloads, options);
|
|
11324
11579
|
}
|
|
11325
|
-
sendActivity(sender, recipients, activity, options = {}) {
|
|
11580
|
+
async sendActivity(sender, recipients, activity, options = {}) {
|
|
11581
|
+
let activityJsonLd = void 0;
|
|
11582
|
+
let hasProof = activity.proofIds.length > 0;
|
|
11583
|
+
if (!hasProof) for await (const _ of activity.getProofs({ contextLoader: this.contextLoader })) {
|
|
11584
|
+
hasProof = true;
|
|
11585
|
+
break;
|
|
11586
|
+
}
|
|
11587
|
+
if (hasProof) {
|
|
11588
|
+
activityJsonLd = await activity.toJsonLd({ contextLoader: this.contextLoader });
|
|
11589
|
+
if (!hasTopLevelProof(activityJsonLd)) activityJsonLd = void 0;
|
|
11590
|
+
}
|
|
11326
11591
|
return this.tracerProvider.getTracer(require_http.name, require_http.version).startActiveSpan(this.federation.outboxQueue == null || options.immediate ? "activitypub.outbox" : "activitypub.fanout", {
|
|
11327
11592
|
kind: this.federation.outboxQueue == null || options.immediate ? _opentelemetry_api.SpanKind.CLIENT : _opentelemetry_api.SpanKind.PRODUCER,
|
|
11328
11593
|
attributes: {
|
|
@@ -11335,7 +11600,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11335
11600
|
}, async (span) => {
|
|
11336
11601
|
try {
|
|
11337
11602
|
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
|
11338
|
-
await this.sendActivityInternal(sender, recipients, activity, options, span);
|
|
11603
|
+
await this.sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd);
|
|
11339
11604
|
} catch (e) {
|
|
11340
11605
|
span.setStatus({
|
|
11341
11606
|
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
@@ -11347,7 +11612,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11347
11612
|
}
|
|
11348
11613
|
});
|
|
11349
11614
|
}
|
|
11350
|
-
async sendActivityInternal(sender, recipients, activity, options, span) {
|
|
11615
|
+
async sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd) {
|
|
11351
11616
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
11352
11617
|
"fedify",
|
|
11353
11618
|
"federation",
|
|
@@ -11394,15 +11659,23 @@ var ContextImpl = class ContextImpl {
|
|
|
11394
11659
|
if (!(error instanceof _fedify_uri_template.RouterError)) throw error;
|
|
11395
11660
|
}
|
|
11396
11661
|
} else expandedRecipients = [recipients];
|
|
11397
|
-
const opts = {
|
|
11398
|
-
context: this,
|
|
11399
|
-
orderingKey: options.orderingKey,
|
|
11400
|
-
collectionSync,
|
|
11401
|
-
immediate: options.immediate,
|
|
11402
|
-
normalizeExistingProofs: options.normalizeExistingProofs
|
|
11403
|
-
};
|
|
11404
11662
|
span.setAttribute("activitypub.inboxes", expandedRecipients.length);
|
|
11405
11663
|
for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
|
|
11664
|
+
let contextMatches = false;
|
|
11665
|
+
if (activityJsonLd != null) {
|
|
11666
|
+
const capturedJsonLd = activityJsonLd;
|
|
11667
|
+
const transformedJsonLd = await activity.toJsonLd({
|
|
11668
|
+
format: "compact",
|
|
11669
|
+
contextLoader: this.contextLoader
|
|
11670
|
+
});
|
|
11671
|
+
const contentChanged = getContentFields(transformedJsonLd) !== getContentFields(capturedJsonLd);
|
|
11672
|
+
contextMatches = getContextFields(transformedJsonLd) === getContextFields(capturedJsonLd);
|
|
11673
|
+
const proofsChanged = getProofFields(transformedJsonLd) !== getProofFields(capturedJsonLd);
|
|
11674
|
+
if (contentChanged || !contextMatches && proofsChanged) {
|
|
11675
|
+
activity = activity.clone({ proofs: await getUncapturedProofs(activity, capturedJsonLd, this.contextLoader) }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
11676
|
+
activityJsonLd = void 0;
|
|
11677
|
+
} else if (proofsChanged) activityJsonLd = void 0;
|
|
11678
|
+
}
|
|
11406
11679
|
span?.setAttribute("activitypub.activity.id", activity?.id?.href ?? "");
|
|
11407
11680
|
if (activity.actorId == null) {
|
|
11408
11681
|
logger.error("Activity {activityId} to send does not have an actor.", {
|
|
@@ -11411,7 +11684,11 @@ var ContextImpl = class ContextImpl {
|
|
|
11411
11684
|
});
|
|
11412
11685
|
throw new TypeError("The activity to send must have at least one actor property.");
|
|
11413
11686
|
}
|
|
11414
|
-
|
|
11687
|
+
if (actorKeyPairs != null && activityJsonLd != null && !contextMatches && actorKeyPairs.some((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null && !require_http.isPortableKeyId(kp.multikey.id))) {
|
|
11688
|
+
activity = activity.clone({ proofs: [] }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
11689
|
+
activityJsonLd = void 0;
|
|
11690
|
+
}
|
|
11691
|
+
const signed = await signOutgoingActivity(activity, actorKeyPairs == null ? keys.map(({ keyId, privateKey }) => ({
|
|
11415
11692
|
verificationMethod: keyId,
|
|
11416
11693
|
privateKey
|
|
11417
11694
|
})) : actorKeyPairs.flatMap((kp) => kp.multikey.id == null ? [] : [{
|
|
@@ -11422,7 +11699,15 @@ var ContextImpl = class ContextImpl {
|
|
|
11422
11699
|
tracerProvider: this.tracerProvider,
|
|
11423
11700
|
appendToExistingProofs: actorKeyPairs != null
|
|
11424
11701
|
});
|
|
11425
|
-
activity =
|
|
11702
|
+
activity = signed.activity;
|
|
11703
|
+
const { proofCreated } = signed;
|
|
11704
|
+
const opts = {
|
|
11705
|
+
context: this,
|
|
11706
|
+
orderingKey: options.orderingKey,
|
|
11707
|
+
collectionSync,
|
|
11708
|
+
immediate: options.immediate,
|
|
11709
|
+
normalizeExistingProofs: options.normalizeExistingProofs
|
|
11710
|
+
};
|
|
11426
11711
|
const inboxes = extractInboxes({
|
|
11427
11712
|
recipients: expandedRecipients,
|
|
11428
11713
|
preferSharedInbox: options.preferSharedInbox,
|
|
@@ -11440,10 +11725,10 @@ var ContextImpl = class ContextImpl {
|
|
|
11440
11725
|
activityId: activity.id?.href,
|
|
11441
11726
|
activity
|
|
11442
11727
|
});
|
|
11443
|
-
|
|
11728
|
+
activityJsonLd = signed.jsonLd ?? (!proofCreated && activityJsonLd != null ? activityJsonLd : await activity.toJsonLd({
|
|
11444
11729
|
format: "compact",
|
|
11445
11730
|
contextLoader: this.contextLoader
|
|
11446
|
-
});
|
|
11731
|
+
}));
|
|
11447
11732
|
try {
|
|
11448
11733
|
await warnCompatibleIdsInJson(activityJsonLd, this instanceof RequestContextImpl && !this.isInActorDispatcher() ? this : void 0);
|
|
11449
11734
|
} catch (error) {
|
|
@@ -11485,7 +11770,7 @@ var ContextImpl = class ContextImpl {
|
|
|
11485
11770
|
normalizeExistingProofs: proofCreated || options.normalizeExistingProofs,
|
|
11486
11771
|
traceContext: carrier
|
|
11487
11772
|
};
|
|
11488
|
-
if (!this.federation.manuallyStartQueue) this.federation.
|
|
11773
|
+
if (!this.federation.manuallyStartQueue) this.federation._startQueueAutomatically(this.data);
|
|
11489
11774
|
await this.federation.fanoutQueue.enqueue(message, { orderingKey: options.orderingKey });
|
|
11490
11775
|
require_http.getFederationMetrics(this.federation.meterProvider).recordQueueTaskEnqueued({
|
|
11491
11776
|
role: "fanout",
|
|
@@ -11883,7 +12168,7 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
11883
12168
|
if (forwarder.length < 1) throw new Error("The forwarder's key pairs are empty.");
|
|
11884
12169
|
keys = forwarder;
|
|
11885
12170
|
} else keys = [forwarder];
|
|
11886
|
-
if (!require_http.hasSignatureLike(ctx.activity)) {
|
|
12171
|
+
if (!require_http.hasVerifiableSignature(ctx.activity) && !require_http.hasSignatureLike(ctx.activity)) {
|
|
11887
12172
|
if (!require_http.hasProofLike(ctx.activity)) {
|
|
11888
12173
|
if (options?.skipIfUnsigned) return false;
|
|
11889
12174
|
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.", {
|
|
@@ -11921,25 +12206,33 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
11921
12206
|
if (options?.immediate) logger.debug("Forwarding activity immediately without queue since immediate option is set.");
|
|
11922
12207
|
else logger.debug("Forwarding activity immediately without queue since queue is not set.");
|
|
11923
12208
|
const promises = [];
|
|
11924
|
-
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
11929
|
-
|
|
11930
|
-
|
|
11931
|
-
|
|
11932
|
-
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
12209
|
+
try {
|
|
12210
|
+
for (const inbox in inboxes) {
|
|
12211
|
+
const promise = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
12212
|
+
allowPrivateAddress: ctx.federation.allowPrivateAddress,
|
|
12213
|
+
keys,
|
|
12214
|
+
activity: ctx.activity,
|
|
12215
|
+
activityId: ctx.activityId,
|
|
12216
|
+
activityType: ctx.activityType,
|
|
12217
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
12218
|
+
meterProvider: ctx.meterProvider,
|
|
12219
|
+
tracerProvider: ctx.tracerProvider,
|
|
12220
|
+
specDeterminer: new KvSpecDeterminer(ctx.federation.kv, ctx.federation.kvPrefixes.httpMessageSignaturesSpec, ctx.federation.firstKnock, { specTtl: ctx.federation.httpMessageSignaturesSpecTtl })
|
|
12221
|
+
});
|
|
12222
|
+
promise.catch(() => {});
|
|
12223
|
+
promises.push(promise);
|
|
12224
|
+
}
|
|
12225
|
+
await Promise.all(promises);
|
|
12226
|
+
} finally {
|
|
12227
|
+
await Promise.allSettled(promises);
|
|
12228
|
+
}
|
|
11936
12229
|
return true;
|
|
11937
12230
|
}
|
|
11938
12231
|
logger.debug("Enqueuing activity {activityId} to forward later.", {
|
|
11939
12232
|
activityId: ctx.activityId,
|
|
11940
12233
|
activity: ctx.activity
|
|
11941
12234
|
});
|
|
11942
|
-
if (!ctx.federation.manuallyStartQueue) ctx.federation.
|
|
12235
|
+
if (!ctx.federation.manuallyStartQueue) ctx.federation._startQueueAutomatically(ctx.data);
|
|
11943
12236
|
const keyJwkPairs = [];
|
|
11944
12237
|
for (const { keyId, privateKey } of keys) {
|
|
11945
12238
|
const privateKeyJwk = await require_http.exportJwk(privateKey);
|
|
@@ -12119,6 +12412,69 @@ var KvSpecDeterminer = class {
|
|
|
12119
12412
|
function notFound(_request) {
|
|
12120
12413
|
return new Response("Not Found", { status: 404 });
|
|
12121
12414
|
}
|
|
12415
|
+
function hasTopLevelProof(value) {
|
|
12416
|
+
return typeof value === "object" && value != null && !Array.isArray(value) && globalThis.Object.prototype.hasOwnProperty.call(value, "proof");
|
|
12417
|
+
}
|
|
12418
|
+
function getContentFields(value) {
|
|
12419
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
12420
|
+
const record = { ...value };
|
|
12421
|
+
delete record["@context"];
|
|
12422
|
+
delete record.proof;
|
|
12423
|
+
delete record.signature;
|
|
12424
|
+
return JSON.stringify(sortJsonKeys(record));
|
|
12425
|
+
}
|
|
12426
|
+
function getContextFields(value) {
|
|
12427
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
12428
|
+
const context = value["@context"];
|
|
12429
|
+
return JSON.stringify(sortJsonKeys(context ?? null));
|
|
12430
|
+
}
|
|
12431
|
+
function getProofEntries(value) {
|
|
12432
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return [];
|
|
12433
|
+
const proof = value.proof;
|
|
12434
|
+
if (proof == null) return [];
|
|
12435
|
+
return Array.isArray(proof) ? proof : [proof];
|
|
12436
|
+
}
|
|
12437
|
+
function normalizeProofEntry(proof) {
|
|
12438
|
+
const stripped = stripContexts(proof);
|
|
12439
|
+
if (typeof stripped !== "object" || stripped == null || Array.isArray(stripped)) return stripped;
|
|
12440
|
+
const record = { ...stripped };
|
|
12441
|
+
if (typeof record.created === "string") try {
|
|
12442
|
+
record.created = Temporal$2.Instant.from(record.created).toString();
|
|
12443
|
+
} catch {}
|
|
12444
|
+
return record;
|
|
12445
|
+
}
|
|
12446
|
+
function getProofEntryFields(proof) {
|
|
12447
|
+
return JSON.stringify(sortJsonKeys(normalizeProofEntry(proof)));
|
|
12448
|
+
}
|
|
12449
|
+
function getProofFields(value) {
|
|
12450
|
+
return JSON.stringify(getProofEntries(value).map(getProofEntryFields).sort());
|
|
12451
|
+
}
|
|
12452
|
+
async function getUncapturedProofs(activity, capturedJsonLd, contextLoader) {
|
|
12453
|
+
const capturedProofs = new Set(getProofEntries(capturedJsonLd).map(getProofEntryFields));
|
|
12454
|
+
const retainedProofs = [];
|
|
12455
|
+
for await (const proof of activity.getProofs({ contextLoader })) {
|
|
12456
|
+
const proofJsonLd = await proof.toJsonLd({
|
|
12457
|
+
format: "compact",
|
|
12458
|
+
contextLoader
|
|
12459
|
+
});
|
|
12460
|
+
if (!capturedProofs.has(getProofEntryFields(proofJsonLd))) retainedProofs.push(proof);
|
|
12461
|
+
}
|
|
12462
|
+
return retainedProofs;
|
|
12463
|
+
}
|
|
12464
|
+
function stripContexts(value) {
|
|
12465
|
+
if (Array.isArray(value)) return value.map(stripContexts);
|
|
12466
|
+
if (typeof value !== "object" || value == null) return value;
|
|
12467
|
+
const record = { ...value };
|
|
12468
|
+
delete record["@context"];
|
|
12469
|
+
delete record.signature;
|
|
12470
|
+
for (const key of globalThis.Object.keys(record)) record[key] = stripContexts(record[key]);
|
|
12471
|
+
return record;
|
|
12472
|
+
}
|
|
12473
|
+
function sortJsonKeys(value) {
|
|
12474
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
12475
|
+
if (typeof value !== "object" || value == null) return value;
|
|
12476
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
12477
|
+
}
|
|
12122
12478
|
function notAcceptable(_request) {
|
|
12123
12479
|
return new Response("Not Acceptable", {
|
|
12124
12480
|
status: 406,
|