@fedify/fedify 2.5.0-dev.2855 → 2.5.0-dev.2878
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/README.md +5 -1
- 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/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/{context-ZtE85CT_.d.cts → context-BhEcRbHo.d.cts} +32 -15
- package/dist/{context-CgIOZfHW.d.ts → context-C96-nSuT.d.ts} +32 -15
- 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-CNVLkzEA.cjs → federation-DjSQwE2V.cjs} +525 -196
- package/dist/{http-Dyr_FKL0.cjs → http-C0XQdcpM.cjs} +2643 -2456
- package/dist/{http-CLL0a37S.js → http-_KUsfrPP.js} +2639 -2464
- package/dist/{key-BZw-YiK5.d.ts → key-2YNB5dUS.d.cts} +5 -5
- package/dist/{key-D5fbQkKM.d.cts → key-BV9DK4qb.d.ts} +5 -5
- package/dist/{kv-cache-CfDFmySj.js → kv-cache-ChSbLqrg.js} +1 -1
- package/dist/{kv-cache-BSXFjN7O.cjs → kv-cache-EIPmfuOF.cjs} +1 -1
- package/dist/{ld-DlC78ioJ.d.ts → ld-BKOmKbuX.d.cts} +28 -6
- package/dist/{ld-DEi9ERHf.d.cts → ld-BewN9CW6.d.ts} +28 -6
- package/dist/{middleware-Bxhz1UUh.js → middleware-CfVUNzkx.js} +457 -129
- package/dist/{mod-rDDnkuR8.d.cts → mod-B9UuZYxK.d.cts} +3 -3
- package/dist/{mod-BD6xjFNY.d.ts → mod-BMHC9eZs.d.ts} +1 -1
- package/dist/{mod-Bl1EEZMj.d.cts → mod-CUXI3ede.d.cts} +1 -1
- package/dist/{mod-SgCN1wPF.d.ts → mod-DHjHSPnw.d.ts} +3 -3
- package/dist/{mod-BamwZjJx.d.cts → mod-iIOirIJV.d.ts} +3 -3
- package/dist/{mod-BJRtsw7l.d.ts → mod-oIp2uo8F.d.cts} +3 -3
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +9 -9
- package/dist/mod.d.ts +9 -9
- package/dist/mod.js +6 -6
- 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/{portable-collection-NzJ-twKe.js → portable-collection-CRRnuUb9.js} +3 -2
- package/dist/{portable-collection-CIJWeEsY.cjs → portable-collection-R3qHmk1r.cjs} +3 -2
- package/dist/portable-verifier-CPA86vIP.js +22 -0
- package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +4 -4
- package/dist/sig/mod.d.ts +4 -4
- package/dist/sig/mod.js +2 -2
- 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/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
2
|
const require_rolldown_runtime = require("./rolldown-runtime-Dmm3t92W.cjs");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
3
|
+
const require_portable_verifier = require("./portable-verifier-DiLU8c9T.cjs");
|
|
4
|
+
const require_transformers = require("./transformers-aIK89ibB.cjs");
|
|
5
|
+
const require_http = require("./http-C0XQdcpM.cjs");
|
|
6
|
+
const require_types = require("./types-C8gac_AD.cjs");
|
|
7
|
+
const require_portable_collection = require("./portable-collection-R3qHmk1r.cjs");
|
|
8
|
+
const require_kv_cache = require("./kv-cache-EIPmfuOF.cjs");
|
|
8
9
|
let _logtape_logtape = require("@logtape/logtape");
|
|
9
10
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
10
11
|
let _fedify_uri_template = require("@fedify/uri-template");
|
|
@@ -15,10 +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");
|
|
19
|
+
let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
|
|
18
20
|
let json_canon = require("json-canon");
|
|
19
21
|
json_canon = require_rolldown_runtime.__toESM(json_canon, 1);
|
|
20
22
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
21
|
-
let
|
|
23
|
+
let _fedify_vocab_runtime_temporal = require("@fedify/vocab-runtime/temporal");
|
|
22
24
|
let _fedify_webfinger = require("@fedify/webfinger");
|
|
23
25
|
let _opentelemetry_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
24
26
|
let devalue = require("devalue");
|
|
@@ -1396,13 +1398,13 @@ function warnCompatibleActorId(actorId, gateway) {
|
|
|
1396
1398
|
}
|
|
1397
1399
|
//#endregion
|
|
1398
1400
|
//#region src/federation/circuit-breaker.ts
|
|
1399
|
-
const Temporal$
|
|
1401
|
+
const Temporal$13 = require_http.Temporal;
|
|
1400
1402
|
const LEGACY_SWEEP_MARKER = ["__fedify_meta", "circuit_breaker_state_ttl_sweep_v2"];
|
|
1401
1403
|
const LEGACY_SWEEP_DELETING_MARKER = { __fedifyDeletingCircuitBreakerLegacyState: true };
|
|
1402
1404
|
const CIRCUIT_BREAKER_STATE_VERSION = 1;
|
|
1403
|
-
const LEGACY_SWEEP_LOCK_TTL = Temporal$
|
|
1404
|
-
const LEGACY_SWEEP_RENEW_INTERVAL = Temporal$
|
|
1405
|
-
const LEGACY_SWEEP_RETRY_WINDOW = Temporal$
|
|
1405
|
+
const LEGACY_SWEEP_LOCK_TTL = Temporal$13.Duration.from({ minutes: 5 });
|
|
1406
|
+
const LEGACY_SWEEP_RENEW_INTERVAL = Temporal$13.Duration.from({ minutes: 1 });
|
|
1407
|
+
const LEGACY_SWEEP_RETRY_WINDOW = Temporal$13.Duration.from({ hours: 168 });
|
|
1406
1408
|
const LEGACY_SWEEP_WAIT_INTERVAL = 10;
|
|
1407
1409
|
const LEGACY_SWEEP_CAS_ATTEMPTS = 3;
|
|
1408
1410
|
/**
|
|
@@ -1421,7 +1423,7 @@ var CircuitBreaker = class {
|
|
|
1421
1423
|
this.#kv = options.kv;
|
|
1422
1424
|
this.#prefix = options.prefix;
|
|
1423
1425
|
this.#options = normalizeCircuitBreakerOptions(options.options ?? {});
|
|
1424
|
-
this.#now = options.now ?? (() => Temporal$
|
|
1426
|
+
this.#now = options.now ?? (() => Temporal$13.Now.instant());
|
|
1425
1427
|
this.#stateChangeObserver = options.stateChangeObserver;
|
|
1426
1428
|
}
|
|
1427
1429
|
get options() {
|
|
@@ -1435,7 +1437,7 @@ var CircuitBreaker = class {
|
|
|
1435
1437
|
this.#sweepLegacyStates();
|
|
1436
1438
|
const heldSince = parseHeldSince(message.circuitHeldSince);
|
|
1437
1439
|
const now = this.#now();
|
|
1438
|
-
if (heldSince != null && Temporal$
|
|
1440
|
+
if (heldSince != null && Temporal$13.Instant.compare(heldSince.add(this.#options.heldActivityTtl), now) <= 0) return {
|
|
1439
1441
|
type: "drop",
|
|
1440
1442
|
heldSince
|
|
1441
1443
|
};
|
|
@@ -1447,12 +1449,12 @@ var CircuitBreaker = class {
|
|
|
1447
1449
|
probe: false
|
|
1448
1450
|
};
|
|
1449
1451
|
if (oldState.state === "half-open") {
|
|
1450
|
-
const halfOpened = oldState.halfOpened == null ? void 0 : Temporal$
|
|
1452
|
+
const halfOpened = oldState.halfOpened == null ? void 0 : Temporal$13.Instant.from(oldState.halfOpened);
|
|
1451
1453
|
if (halfOpened != null) {
|
|
1452
1454
|
const staleAt = halfOpened.add(this.#options.recoveryDelay);
|
|
1453
|
-
if (Temporal$
|
|
1455
|
+
if (Temporal$13.Instant.compare(now, staleAt) < 0) {
|
|
1454
1456
|
const releaseAt = now.add(this.#options.releaseInterval);
|
|
1455
|
-
const retryAt = Temporal$
|
|
1457
|
+
const retryAt = Temporal$13.Instant.compare(releaseAt, staleAt) < 0 ? releaseAt : staleAt;
|
|
1456
1458
|
const cappedRetryAt = this.#capHeldRetryAt(now, heldSince, retryAt);
|
|
1457
1459
|
return {
|
|
1458
1460
|
type: "hold",
|
|
@@ -1474,8 +1476,8 @@ var CircuitBreaker = class {
|
|
|
1474
1476
|
lastConflictingState = "half-open";
|
|
1475
1477
|
continue;
|
|
1476
1478
|
}
|
|
1477
|
-
const probeAt = (oldState.opened == null ? now : Temporal$
|
|
1478
|
-
if (Temporal$
|
|
1479
|
+
const probeAt = (oldState.opened == null ? now : Temporal$13.Instant.from(oldState.opened)).add(this.#options.recoveryDelay);
|
|
1480
|
+
if (Temporal$13.Instant.compare(now, probeAt) < 0) {
|
|
1479
1481
|
const retryAt = this.#capHeldRetryAt(now, heldSince, probeAt);
|
|
1480
1482
|
return {
|
|
1481
1483
|
type: "hold",
|
|
@@ -1540,7 +1542,7 @@ var CircuitBreaker = class {
|
|
|
1540
1542
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
1541
1543
|
const { state: oldState, raw: oldValue } = await this.#get(remoteHost);
|
|
1542
1544
|
if (oldState?.state === "open") return void 0;
|
|
1543
|
-
const oldFailures = oldState?.failures.map(Temporal$
|
|
1545
|
+
const oldFailures = oldState?.failures.map(Temporal$13.Instant.from) ?? [];
|
|
1544
1546
|
const failures = this.#options.pruneFailures([...oldFailures, now], now);
|
|
1545
1547
|
let newState;
|
|
1546
1548
|
let transition;
|
|
@@ -1624,7 +1626,7 @@ var CircuitBreaker = class {
|
|
|
1624
1626
|
for await (const { key, value } of this.#kv.list(this.#prefix)) {
|
|
1625
1627
|
if (key.length !== this.#prefix.length + 1) continue;
|
|
1626
1628
|
await this.#migrateLegacyState(key, value);
|
|
1627
|
-
if (Temporal$
|
|
1629
|
+
if (Temporal$13.Instant.compare(this.#now(), leaseRenewedAt.add(LEGACY_SWEEP_RENEW_INTERVAL)) >= 0) {
|
|
1628
1630
|
const renewed = await this.#renewLegacySweep(markerKey, marker);
|
|
1629
1631
|
if (renewed == null) return;
|
|
1630
1632
|
marker = renewed;
|
|
@@ -1648,7 +1650,7 @@ var CircuitBreaker = class {
|
|
|
1648
1650
|
}
|
|
1649
1651
|
#finishLegacySweepMarker(marker) {
|
|
1650
1652
|
const retryUntil = getLegacySweepRetryUntil(marker);
|
|
1651
|
-
if (retryUntil != null && Temporal$
|
|
1653
|
+
if (retryUntil != null && Temporal$13.Instant.compare(this.#now(), Temporal$13.Instant.from(retryUntil)) < 0) return {
|
|
1652
1654
|
state: "done",
|
|
1653
1655
|
retryUntil
|
|
1654
1656
|
};
|
|
@@ -1691,7 +1693,7 @@ var CircuitBreaker = class {
|
|
|
1691
1693
|
#isLegacySweepDone() {
|
|
1692
1694
|
if (this.#legacySweepDone === "final") return true;
|
|
1693
1695
|
if (this.#legacySweepDone == null) return false;
|
|
1694
|
-
if (Temporal$
|
|
1696
|
+
if (Temporal$13.Instant.compare(this.#now(), this.#legacySweepDone) < 0) return true;
|
|
1695
1697
|
this.#legacySweepDone = void 0;
|
|
1696
1698
|
return false;
|
|
1697
1699
|
}
|
|
@@ -1701,7 +1703,7 @@ var CircuitBreaker = class {
|
|
|
1701
1703
|
}
|
|
1702
1704
|
#capHeldRetryAt(now, heldSince, retryAt) {
|
|
1703
1705
|
const expiresAt = (heldSince ?? now).add(this.#options.heldActivityTtl);
|
|
1704
|
-
return Temporal$
|
|
1706
|
+
return Temporal$13.Instant.compare(expiresAt, retryAt) < 0 ? expiresAt : retryAt;
|
|
1705
1707
|
}
|
|
1706
1708
|
async #get(remoteHost) {
|
|
1707
1709
|
const value = await this.#kv.get(this.#key(remoteHost));
|
|
@@ -1776,7 +1778,7 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1776
1778
|
assertPositiveDuration(releaseInterval, "releaseInterval");
|
|
1777
1779
|
if (configuredStateTtl != null) {
|
|
1778
1780
|
assertPositiveDuration(configuredStateTtl, "stateTtl");
|
|
1779
|
-
if (Temporal$
|
|
1781
|
+
if (Temporal$13.Duration.compare(configuredStateTtl, recoveryDelay) < 0) throw new RangeError("stateTtl must be at least recoveryDelay.");
|
|
1780
1782
|
}
|
|
1781
1783
|
let failure;
|
|
1782
1784
|
let pruneFailures;
|
|
@@ -1788,13 +1790,13 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1788
1790
|
assertPositiveDuration(failureWindow, "failureWindow");
|
|
1789
1791
|
pruneFailures = (timestamps, now) => {
|
|
1790
1792
|
const earliest = now.subtract(failureWindow);
|
|
1791
|
-
return timestamps.filter((timestamp) => Temporal$
|
|
1793
|
+
return timestamps.filter((timestamp) => Temporal$13.Instant.compare(timestamp, earliest) >= 0).slice(-failureThreshold);
|
|
1792
1794
|
};
|
|
1793
1795
|
failure = (timestamps) => {
|
|
1794
1796
|
if (timestamps.length < failureThreshold) return false;
|
|
1795
1797
|
const first = timestamps[timestamps.length - failureThreshold];
|
|
1796
1798
|
const last = timestamps[timestamps.length - 1];
|
|
1797
|
-
return Temporal$
|
|
1799
|
+
return Temporal$13.Duration.compare(first.until(last), failureWindow) <= 0;
|
|
1798
1800
|
};
|
|
1799
1801
|
stateTtl = configuredStateTtl ?? maxDuration(recoveryDelay.add(failureWindow), recoveryDelay.add(heldActivityTtl));
|
|
1800
1802
|
} else {
|
|
@@ -1814,7 +1816,7 @@ function normalizeCircuitBreakerOptions(options) {
|
|
|
1814
1816
|
};
|
|
1815
1817
|
}
|
|
1816
1818
|
function maxDuration(duration, ...durations) {
|
|
1817
|
-
return durations.reduce((max, candidate) => Temporal$
|
|
1819
|
+
return durations.reduce((max, candidate) => Temporal$13.Duration.compare(candidate, max) > 0 ? candidate : max, duration);
|
|
1818
1820
|
}
|
|
1819
1821
|
function isLegacySweepDone(value, now) {
|
|
1820
1822
|
return getLegacySweepDoneUntil(value, now) != null;
|
|
@@ -1823,8 +1825,8 @@ function getLegacySweepDoneUntil(value, now) {
|
|
|
1823
1825
|
if (typeof value !== "object" || value == null || !("state" in value)) return;
|
|
1824
1826
|
if (value.state === "final") return "final";
|
|
1825
1827
|
if (value.state === "done" && "retryUntil" in value && typeof value.retryUntil === "string") try {
|
|
1826
|
-
const retryUntil = Temporal$
|
|
1827
|
-
return Temporal$
|
|
1828
|
+
const retryUntil = Temporal$13.Instant.from(value.retryUntil);
|
|
1829
|
+
return Temporal$13.Instant.compare(now, retryUntil) < 0 ? retryUntil : void 0;
|
|
1828
1830
|
} catch {
|
|
1829
1831
|
return;
|
|
1830
1832
|
}
|
|
@@ -1832,7 +1834,7 @@ function getLegacySweepDoneUntil(value, now) {
|
|
|
1832
1834
|
function isLegacySweepRetryDue(value, now) {
|
|
1833
1835
|
if (typeof value !== "object" || value == null || !("state" in value) || value.state !== "done" || !("retryUntil" in value) || typeof value.retryUntil !== "string") return false;
|
|
1834
1836
|
try {
|
|
1835
|
-
return Temporal$
|
|
1837
|
+
return Temporal$13.Instant.compare(now, Temporal$13.Instant.from(value.retryUntil)) >= 0;
|
|
1836
1838
|
} catch {
|
|
1837
1839
|
return false;
|
|
1838
1840
|
}
|
|
@@ -1843,7 +1845,7 @@ function isLegacySweepActive(value, now) {
|
|
|
1843
1845
|
function isLegacySweepInProgress(value, now) {
|
|
1844
1846
|
if (typeof value !== "object" || value == null || !("state" in value) || value.state !== "sweeping" || !("started" in value) || typeof value.started !== "string") return false;
|
|
1845
1847
|
try {
|
|
1846
|
-
return Temporal$
|
|
1848
|
+
return Temporal$13.Instant.compare(now, Temporal$13.Instant.from(value.started).add(LEGACY_SWEEP_LOCK_TTL)) < 0;
|
|
1847
1849
|
} catch {
|
|
1848
1850
|
return false;
|
|
1849
1851
|
}
|
|
@@ -1851,7 +1853,7 @@ function isLegacySweepInProgress(value, now) {
|
|
|
1851
1853
|
function getLegacySweepRetryUntil(value) {
|
|
1852
1854
|
if (typeof value !== "object" || value == null || !("retryUntil" in value) || typeof value.retryUntil !== "string") return;
|
|
1853
1855
|
try {
|
|
1854
|
-
Temporal$
|
|
1856
|
+
Temporal$13.Instant.from(value.retryUntil);
|
|
1855
1857
|
return value.retryUntil;
|
|
1856
1858
|
} catch {
|
|
1857
1859
|
return;
|
|
@@ -1875,19 +1877,19 @@ function delay(milliseconds) {
|
|
|
1875
1877
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
1876
1878
|
}
|
|
1877
1879
|
function toInstantDuration(duration) {
|
|
1878
|
-
const parsed = Temporal$
|
|
1879
|
-
return Temporal$
|
|
1880
|
+
const parsed = Temporal$13.Duration.from(duration);
|
|
1881
|
+
return Temporal$13.Duration.from({ milliseconds: Math.trunc(parsed.total({
|
|
1880
1882
|
unit: "millisecond",
|
|
1881
|
-
relativeTo: Temporal$
|
|
1883
|
+
relativeTo: Temporal$13.PlainDateTime.from("2026-01-01T00:00:00")
|
|
1882
1884
|
})) });
|
|
1883
1885
|
}
|
|
1884
1886
|
function assertPositiveDuration(duration, name) {
|
|
1885
|
-
if (Temporal$
|
|
1887
|
+
if (Temporal$13.Duration.compare(duration, { seconds: 0 }) <= 0) throw new RangeError(`${name} must be a positive duration.`);
|
|
1886
1888
|
}
|
|
1887
1889
|
function parseHeldSince(value) {
|
|
1888
1890
|
if (value == null) return void 0;
|
|
1889
1891
|
try {
|
|
1890
|
-
return Temporal$
|
|
1892
|
+
return Temporal$13.Instant.from(value);
|
|
1891
1893
|
} catch (error) {
|
|
1892
1894
|
(0, _logtape_logtape.getLogger)([
|
|
1893
1895
|
"fedify",
|
|
@@ -1914,7 +1916,7 @@ function parseStoredCircuitBreakerKvState(value) {
|
|
|
1914
1916
|
const isInstantString = (v) => {
|
|
1915
1917
|
if (typeof v !== "string") return false;
|
|
1916
1918
|
try {
|
|
1917
|
-
Temporal$
|
|
1919
|
+
Temporal$13.Instant.from(v);
|
|
1918
1920
|
return true;
|
|
1919
1921
|
} catch {
|
|
1920
1922
|
return false;
|
|
@@ -2092,6 +2094,17 @@ var InboxObservation = class {
|
|
|
2092
2094
|
}
|
|
2093
2095
|
};
|
|
2094
2096
|
//#endregion
|
|
2097
|
+
//#region src/compat/attachment-arrays.ts
|
|
2098
|
+
/**
|
|
2099
|
+
* Applies the shared attachment workaround to served documents without
|
|
2100
|
+
* rewriting any document that contains a semantic proof or LD signature.
|
|
2101
|
+
* RDF equivalence alone cannot preserve JCS signatures.
|
|
2102
|
+
* @internal
|
|
2103
|
+
*/
|
|
2104
|
+
function normalizeAttachmentArrays(document, contextLoader) {
|
|
2105
|
+
return require_http.normalizeAttachmentArrays(document, contextLoader, { preserveSecuredDocuments: true });
|
|
2106
|
+
}
|
|
2107
|
+
//#endregion
|
|
2095
2108
|
//#region src/sig/compound-proof.ts
|
|
2096
2109
|
const textEncoder = new TextEncoder();
|
|
2097
2110
|
/**
|
|
@@ -3621,7 +3634,7 @@ function createAuthenticationEvidence(evidence) {
|
|
|
3621
3634
|
}
|
|
3622
3635
|
//#endregion
|
|
3623
3636
|
//#region src/federation/inbox.ts
|
|
3624
|
-
const Temporal$
|
|
3637
|
+
const Temporal$12 = require_http.Temporal;
|
|
3625
3638
|
/**
|
|
3626
3639
|
* Checks whether an activity's ID and all of its actor IDs have the same
|
|
3627
3640
|
* [FEP-fe34] origin. Activities without an ID have no origin to authenticate.
|
|
@@ -3912,7 +3925,7 @@ async function routeActivity({ context: ctx, json, originalJson, normalizedActiv
|
|
|
3912
3925
|
return "error";
|
|
3913
3926
|
}
|
|
3914
3927
|
require_http.recordInboxActivity(meterProvider, "processed", (0, _fedify_vocab.getTypeId)(activity).href);
|
|
3915
|
-
if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal$
|
|
3928
|
+
if (cacheKey != null) await kv.set(cacheKey, true, { ttl: Temporal$12.Duration.from({ days: 1 }) });
|
|
3916
3929
|
logger.info("Activity {activityId} has been processed.", {
|
|
3917
3930
|
activityId: activity.id?.href,
|
|
3918
3931
|
activity: json,
|
|
@@ -4300,7 +4313,7 @@ async function restoreVerifiedActivityView(view, message) {
|
|
|
4300
4313
|
}
|
|
4301
4314
|
//#endregion
|
|
4302
4315
|
//#region src/federation/keycache.ts
|
|
4303
|
-
const Temporal$
|
|
4316
|
+
const Temporal$11 = require_http.Temporal;
|
|
4304
4317
|
const KEY_CACHE_GENERATION = "3";
|
|
4305
4318
|
const COMPATIBLE_KEY_SEGMENT = "__compatible";
|
|
4306
4319
|
const MAX_OWNER_BYTES = 32 * 1024;
|
|
@@ -4321,8 +4334,8 @@ var KvKeyCache = class {
|
|
|
4321
4334
|
this.kv = kv;
|
|
4322
4335
|
this.prefix = prefix;
|
|
4323
4336
|
this.options = options;
|
|
4324
|
-
this.unavailableKeyTtl = options.unavailableKeyTtl ?? Temporal$
|
|
4325
|
-
this.keyTtl = options.keyTtl ?? Temporal$
|
|
4337
|
+
this.unavailableKeyTtl = options.unavailableKeyTtl ?? Temporal$11.Duration.from({ minutes: 10 });
|
|
4338
|
+
this.keyTtl = options.keyTtl ?? Temporal$11.Duration.from({ days: 30 });
|
|
4326
4339
|
this.nullKeys = /* @__PURE__ */ new Map();
|
|
4327
4340
|
}
|
|
4328
4341
|
#getFetchErrorKey(keyId) {
|
|
@@ -4342,13 +4355,13 @@ var KvKeyCache = class {
|
|
|
4342
4355
|
async get(keyId) {
|
|
4343
4356
|
const negativeExpiration = this.nullKeys.get(keyId.href);
|
|
4344
4357
|
if (negativeExpiration != null) {
|
|
4345
|
-
if (Temporal$
|
|
4358
|
+
if (Temporal$11.Now.instant().until(negativeExpiration).sign >= 0) return null;
|
|
4346
4359
|
this.nullKeys.delete(keyId.href);
|
|
4347
4360
|
}
|
|
4348
4361
|
const serialized = await this.kv.get(this.#entryKey(keyId));
|
|
4349
4362
|
if (serialized === void 0) return void 0;
|
|
4350
4363
|
if (serialized === null) {
|
|
4351
|
-
this.nullKeys.set(keyId.href, Temporal$
|
|
4364
|
+
this.nullKeys.set(keyId.href, Temporal$11.Now.instant().add(this.unavailableKeyTtl));
|
|
4352
4365
|
return null;
|
|
4353
4366
|
}
|
|
4354
4367
|
try {
|
|
@@ -4364,7 +4377,7 @@ var KvKeyCache = class {
|
|
|
4364
4377
|
}
|
|
4365
4378
|
async set(keyId, key) {
|
|
4366
4379
|
if (key == null) {
|
|
4367
|
-
this.nullKeys.set(keyId.href, Temporal$
|
|
4380
|
+
this.nullKeys.set(keyId.href, Temporal$11.Now.instant().add(this.unavailableKeyTtl));
|
|
4368
4381
|
await this.kv.set(this.#entryKey(keyId), null, { ttl: this.unavailableKeyTtl });
|
|
4369
4382
|
return;
|
|
4370
4383
|
}
|
|
@@ -4383,7 +4396,7 @@ var KvKeyCache = class {
|
|
|
4383
4396
|
* @internal
|
|
4384
4397
|
*/
|
|
4385
4398
|
compatibleKeyScope(scope) {
|
|
4386
|
-
const now = this.options.now ?? (() => Temporal$
|
|
4399
|
+
const now = this.options.now ?? (() => Temporal$11.Now.instant());
|
|
4387
4400
|
const entryKey = (keyId) => [
|
|
4388
4401
|
...this.prefix,
|
|
4389
4402
|
COMPATIBLE_KEY_SEGMENT,
|
|
@@ -4403,7 +4416,7 @@ var KvKeyCache = class {
|
|
|
4403
4416
|
if (entry.key === null) return null;
|
|
4404
4417
|
let expires;
|
|
4405
4418
|
try {
|
|
4406
|
-
expires = Temporal$
|
|
4419
|
+
expires = Temporal$11.Instant.fromEpochMilliseconds(entry.expires);
|
|
4407
4420
|
} catch (error) {
|
|
4408
4421
|
if (!(error instanceof RangeError)) throw error;
|
|
4409
4422
|
await this.kv.delete(entryKey(keyId));
|
|
@@ -4448,8 +4461,8 @@ var KvKeyCache = class {
|
|
|
4448
4461
|
key: serialized,
|
|
4449
4462
|
expires,
|
|
4450
4463
|
...owner == null ? {} : { owner }
|
|
4451
|
-
}, { ttl: Temporal$
|
|
4452
|
-
return key == null ? void 0 : Temporal$
|
|
4464
|
+
}, { ttl: Temporal$11.Duration.from({ milliseconds: ttl }) });
|
|
4465
|
+
return key == null ? void 0 : Temporal$11.Instant.fromEpochMilliseconds(expires);
|
|
4453
4466
|
},
|
|
4454
4467
|
delete: async (keyId) => {
|
|
4455
4468
|
await this.kv.delete(entryKey(keyId));
|
|
@@ -4964,7 +4977,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
4964
4977
|
* @param parameters The parameters for sending the activity.
|
|
4965
4978
|
* See also {@link SendActivityParameters}.
|
|
4966
4979
|
* @param deps The dependencies, for tests.
|
|
4967
|
-
* @throws {
|
|
4980
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
4981
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
4968
4982
|
*/
|
|
4969
4983
|
function sendActivity(options, deps = {}) {
|
|
4970
4984
|
options.attemptStarted?.(options.inbox.href);
|
|
@@ -5034,6 +5048,24 @@ async function sendActivityThroughGateways(parameters, inboxes) {
|
|
|
5034
5048
|
}
|
|
5035
5049
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
5036
5050
|
const ERROR_RESPONSE_BODY_TIMEOUT_MS = 1e3;
|
|
5051
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
5052
|
+
function raceWithAbort(promise, signal) {
|
|
5053
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
5054
|
+
return new Promise((resolve, reject) => {
|
|
5055
|
+
const onAbort = () => {
|
|
5056
|
+
signal.removeEventListener("abort", onAbort);
|
|
5057
|
+
reject(signal.reason);
|
|
5058
|
+
};
|
|
5059
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5060
|
+
promise.then((value) => {
|
|
5061
|
+
signal.removeEventListener("abort", onAbort);
|
|
5062
|
+
resolve(value);
|
|
5063
|
+
}, (error) => {
|
|
5064
|
+
signal.removeEventListener("abort", onAbort);
|
|
5065
|
+
reject(error);
|
|
5066
|
+
});
|
|
5067
|
+
});
|
|
5068
|
+
}
|
|
5037
5069
|
function getActivityActorId(activity) {
|
|
5038
5070
|
if (!isRecord(activity)) return void 0;
|
|
5039
5071
|
return getIdValue(activity.actor);
|
|
@@ -5053,7 +5085,7 @@ function getIdValue(value) {
|
|
|
5053
5085
|
function isRecord(value) {
|
|
5054
5086
|
return typeof value === "object" && value != null;
|
|
5055
5087
|
}
|
|
5056
|
-
async function readLimitedResponseBody(response, maxBytes) {
|
|
5088
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
5057
5089
|
const captured = takeCapturedDiagnostic(response);
|
|
5058
5090
|
if (captured !== void 0) return captured;
|
|
5059
5091
|
if (response.body == null) return "";
|
|
@@ -5065,7 +5097,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
5065
5097
|
let timedOut = false;
|
|
5066
5098
|
try {
|
|
5067
5099
|
while (true) {
|
|
5068
|
-
|
|
5100
|
+
signal.throwIfAborted();
|
|
5101
|
+
const result = await raceWithAbort(pump.read(), signal);
|
|
5069
5102
|
if (result == null) {
|
|
5070
5103
|
timedOut = true;
|
|
5071
5104
|
break;
|
|
@@ -5099,11 +5132,30 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5099
5132
|
const federationMetrics = require_http.getFederationMetrics(meterProvider);
|
|
5100
5133
|
const started = performance.now();
|
|
5101
5134
|
let deliverySuccess = false;
|
|
5102
|
-
const
|
|
5135
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
5136
|
+
const controller = new AbortController();
|
|
5137
|
+
const { signal } = controller;
|
|
5138
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
5139
|
+
function timeoutFailure(error) {
|
|
5140
|
+
if (!signal.aborted || error instanceof SendActivityError) return error;
|
|
5141
|
+
const failure = new _fedify_vocab_runtime.FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
5142
|
+
failure.cause = signal.reason;
|
|
5143
|
+
return failure;
|
|
5144
|
+
}
|
|
5145
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? _fedify_vocab_runtime_internal.openDirectFetch : (url) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(url, { signal }));
|
|
5103
5146
|
async function openHop(url) {
|
|
5104
5147
|
let session;
|
|
5105
5148
|
try {
|
|
5106
|
-
|
|
5149
|
+
signal.throwIfAborted();
|
|
5150
|
+
const opening = openUnvalidatedHop(url);
|
|
5151
|
+
opening.then((lateSession) => {
|
|
5152
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
5153
|
+
}, () => {});
|
|
5154
|
+
session = await raceWithAbort(opening, signal);
|
|
5155
|
+
if (signal.aborted) {
|
|
5156
|
+
closeAfterError(session, logger);
|
|
5157
|
+
signal.throwIfAborted();
|
|
5158
|
+
}
|
|
5107
5159
|
} catch (error) {
|
|
5108
5160
|
if (error instanceof _fedify_vocab_runtime.UrlError && error.reason === "dns") {
|
|
5109
5161
|
attempt?.failure({
|
|
@@ -5165,8 +5217,15 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5165
5217
|
try {
|
|
5166
5218
|
initialSession = await openHop(inbox.href);
|
|
5167
5219
|
} catch (error) {
|
|
5168
|
-
|
|
5169
|
-
|
|
5220
|
+
const failure = timeoutFailure(error);
|
|
5221
|
+
if (failure instanceof _fedify_vocab_runtime.FetchError) federationMetrics.recordDelivery(inbox, require_http.getDurationMs(started), false, activityType);
|
|
5222
|
+
if (signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
5223
|
+
activityId,
|
|
5224
|
+
inbox: inbox.href,
|
|
5225
|
+
error: failure
|
|
5226
|
+
});
|
|
5227
|
+
clearTimeout(timer);
|
|
5228
|
+
throw failure;
|
|
5170
5229
|
}
|
|
5171
5230
|
let initialPending = true;
|
|
5172
5231
|
const openDeliveryHop = (url) => {
|
|
@@ -5206,7 +5265,8 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5206
5265
|
method: "POST",
|
|
5207
5266
|
headers,
|
|
5208
5267
|
body,
|
|
5209
|
-
redirect: "manual"
|
|
5268
|
+
redirect: "manual",
|
|
5269
|
+
signal
|
|
5210
5270
|
});
|
|
5211
5271
|
} catch (error) {
|
|
5212
5272
|
attempt?.failure({
|
|
@@ -5233,13 +5293,24 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5233
5293
|
}))
|
|
5234
5294
|
});
|
|
5235
5295
|
const consume = (response) => {
|
|
5236
|
-
return consumeSendActivityResponse(response, inbox);
|
|
5296
|
+
return consumeSendActivityResponse(response, inbox, signal);
|
|
5237
5297
|
};
|
|
5238
5298
|
let outcome;
|
|
5299
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
5300
|
+
determineSpec(origin) {
|
|
5301
|
+
signal.throwIfAborted();
|
|
5302
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
5303
|
+
},
|
|
5304
|
+
rememberSpec(origin, spec) {
|
|
5305
|
+
signal.throwIfAborted();
|
|
5306
|
+
return raceWithAbort(Promise.resolve(specDeterminer.rememberSpec(origin, spec)), signal);
|
|
5307
|
+
}
|
|
5308
|
+
};
|
|
5239
5309
|
try {
|
|
5240
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, consume, attempt) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
5310
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openDeliveryHop, consume, attempt, signal) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
5241
5311
|
tracerProvider,
|
|
5242
|
-
specDeterminer
|
|
5312
|
+
specDeterminer: boundedSpecDeterminer,
|
|
5313
|
+
signal
|
|
5243
5314
|
}, openDeliveryHop, consume, attempt == null ? void 0 : {
|
|
5244
5315
|
fetch: (request, submit) => attempt.fetch(request, submit),
|
|
5245
5316
|
response: (response, disposition) => attempt.response(response, disposition),
|
|
@@ -5251,7 +5322,8 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5251
5322
|
});
|
|
5252
5323
|
} catch (error) {
|
|
5253
5324
|
attempt?.unknown(error);
|
|
5254
|
-
const
|
|
5325
|
+
const boundedError = timeoutFailure(error);
|
|
5326
|
+
const failure = boundedError instanceof _fedify_vocab_runtime.FetchError || boundedError instanceof _fedify_vocab_runtime.UrlError ? boundedError : createFetchError(inbox.href, boundedError);
|
|
5255
5327
|
logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
5256
5328
|
activityId,
|
|
5257
5329
|
inbox: inbox.href,
|
|
@@ -5291,6 +5363,7 @@ async function sendActivityInternal({ activity, activityId, activityType, keys,
|
|
|
5291
5363
|
federationMetrics.recordDelivery(inbox, require_http.getDurationMs(started), deliverySuccess, activityType);
|
|
5292
5364
|
}
|
|
5293
5365
|
} finally {
|
|
5366
|
+
clearTimeout(timer);
|
|
5294
5367
|
if (initialPending) await initialSession.close();
|
|
5295
5368
|
}
|
|
5296
5369
|
}
|
|
@@ -5322,17 +5395,18 @@ function cancelResponseBody(response, url) {
|
|
|
5322
5395
|
* session is open: the body of a successful response is cancelled, and at
|
|
5323
5396
|
* most 1 KiB of an error response body is read within its diagnostic budget.
|
|
5324
5397
|
*/
|
|
5325
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
5398
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
5326
5399
|
if (response.ok) {
|
|
5327
5400
|
cancelResponseBody(response, response.url || inbox.href);
|
|
5328
5401
|
return { ok: true };
|
|
5329
5402
|
}
|
|
5330
5403
|
let error;
|
|
5331
5404
|
try {
|
|
5332
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
5405
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
5333
5406
|
} catch (_) {
|
|
5334
5407
|
error = "";
|
|
5335
5408
|
}
|
|
5409
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
5336
5410
|
return {
|
|
5337
5411
|
ok: false,
|
|
5338
5412
|
status: response.status,
|
|
@@ -5353,7 +5427,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
5353
5427
|
* @param attempt The in-process attempt observation, if registered.
|
|
5354
5428
|
* @returns The value returned by `consume`.
|
|
5355
5429
|
*/
|
|
5356
|
-
async function fetchWithValidatedRedirects(request, openHop, consume, attempt) {
|
|
5430
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, attempt, signal) {
|
|
5357
5431
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
5358
5432
|
"fedify",
|
|
5359
5433
|
"federation",
|
|
@@ -5361,10 +5435,17 @@ async function fetchWithValidatedRedirects(request, openHop, consume, attempt) {
|
|
|
5361
5435
|
]);
|
|
5362
5436
|
let body = await request.clone().text();
|
|
5363
5437
|
for (let redirects = 0;; redirects++) {
|
|
5438
|
+
signal?.throwIfAborted();
|
|
5364
5439
|
const session = await openHop(request.url);
|
|
5365
5440
|
let response;
|
|
5366
5441
|
try {
|
|
5367
|
-
response = await (attempt == null ? session.fetch(request, {
|
|
5442
|
+
response = await (attempt == null ? session.fetch(request, {
|
|
5443
|
+
redirect: "manual",
|
|
5444
|
+
signal
|
|
5445
|
+
}) : attempt.fetch(request, () => session.fetch(request, {
|
|
5446
|
+
redirect: "manual",
|
|
5447
|
+
signal
|
|
5448
|
+
})));
|
|
5368
5449
|
} catch (error) {
|
|
5369
5450
|
await closeAfterError(session, logger);
|
|
5370
5451
|
throw error;
|
|
@@ -5418,7 +5499,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume, attempt) {
|
|
|
5418
5499
|
method,
|
|
5419
5500
|
headers,
|
|
5420
5501
|
body,
|
|
5421
|
-
redirect: "manual"
|
|
5502
|
+
redirect: "manual",
|
|
5503
|
+
signal: signal ?? request.signal
|
|
5422
5504
|
});
|
|
5423
5505
|
}
|
|
5424
5506
|
}
|
|
@@ -5480,7 +5562,7 @@ var SendActivityError = class extends Error {
|
|
|
5480
5562
|
};
|
|
5481
5563
|
//#endregion
|
|
5482
5564
|
//#region src/federation/portable-inbox.ts
|
|
5483
|
-
const Temporal$
|
|
5565
|
+
const Temporal$10 = require_http.Temporal;
|
|
5484
5566
|
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
5485
5567
|
/**
|
|
5486
5568
|
* Fills in the defaults of {@link PortableInboxForwardingOptions} and
|
|
@@ -5496,9 +5578,9 @@ const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
|
5496
5578
|
function resolvePortableInboxForwardingOptions(options = {}) {
|
|
5497
5579
|
const maxTargets = options.maxTargets ?? 10;
|
|
5498
5580
|
if (!Number.isInteger(maxTargets) || maxTargets < 0) throw new RangeError("portableInboxForwarding.maxTargets must be a non-negative integer.");
|
|
5499
|
-
const ttl = Temporal$
|
|
5581
|
+
const ttl = Temporal$10.Duration.from(options.ttl ?? { days: 30 });
|
|
5500
5582
|
if (ttl.total("millisecond") <= 0) throw new RangeError("portableInboxForwarding.ttl must be positive.");
|
|
5501
|
-
const deadline = Temporal$
|
|
5583
|
+
const deadline = Temporal$10.Duration.from(options.deadline ?? { seconds: 10 });
|
|
5502
5584
|
const deadlineMs = deadline.total("millisecond");
|
|
5503
5585
|
if (deadlineMs < 0 || deadlineMs > MAX_TIMEOUT_MS) throw new RangeError(`portableInboxForwarding.deadline must be between 0 and ${MAX_TIMEOUT_MS} milliseconds.`);
|
|
5504
5586
|
return {
|
|
@@ -5954,17 +6036,14 @@ async function enqueueForwarding(parameters, outboxQueue, inboxes, observation)
|
|
|
5954
6036
|
}
|
|
5955
6037
|
//#endregion
|
|
5956
6038
|
//#region src/federation/temporal.ts
|
|
5957
|
-
const Temporal$
|
|
6039
|
+
const Temporal$9 = require_http.Temporal;
|
|
5958
6040
|
function isPlainObject$1(value) {
|
|
5959
6041
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
5960
6042
|
}
|
|
5961
|
-
function normalizeDateTimeLiteral(value) {
|
|
5962
|
-
return value.substring(19).match(/[Z+-]/) ? value : value + "Z";
|
|
5963
|
-
}
|
|
5964
6043
|
function isMalformedDateTimeLiteral(value) {
|
|
5965
6044
|
if (typeof value !== "string") return false;
|
|
5966
6045
|
try {
|
|
5967
|
-
Temporal$
|
|
6046
|
+
Temporal$9.Instant.from((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(value));
|
|
5968
6047
|
return false;
|
|
5969
6048
|
} catch {
|
|
5970
6049
|
return true;
|
|
@@ -5973,7 +6052,7 @@ function isMalformedDateTimeLiteral(value) {
|
|
|
5973
6052
|
function isMalformedDurationLiteral(value) {
|
|
5974
6053
|
if (typeof value !== "string") return false;
|
|
5975
6054
|
try {
|
|
5976
|
-
Temporal$
|
|
6055
|
+
Temporal$9.Duration.from(value);
|
|
5977
6056
|
return false;
|
|
5978
6057
|
} catch {
|
|
5979
6058
|
return true;
|
|
@@ -6002,7 +6081,7 @@ function hasMalformedExpandedQuestionClosedLiteral(value) {
|
|
|
6002
6081
|
if (typeof literal === "boolean") return false;
|
|
6003
6082
|
if (typeof literal !== "string") return false;
|
|
6004
6083
|
if (value["@type"] !== XSD_DATE_TIME_IRI) return false;
|
|
6005
|
-
if (new Date(literal).toString() === "Invalid Date") return false;
|
|
6084
|
+
if (new Date(literal).toString() === "Invalid Date" && new Date((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(literal)).toString() === "Invalid Date") return false;
|
|
6006
6085
|
return isMalformedDateTimeLiteral(literal);
|
|
6007
6086
|
}
|
|
6008
6087
|
function hasMalformedExpandedDurationLiteral(value) {
|
|
@@ -6044,7 +6123,7 @@ async function hasMalformedKnownTemporalLiteral(value, contextLoader) {
|
|
|
6044
6123
|
}
|
|
6045
6124
|
//#endregion
|
|
6046
6125
|
//#region src/federation/handler.ts
|
|
6047
|
-
const Temporal$
|
|
6126
|
+
const Temporal$8 = require_http.Temporal;
|
|
6048
6127
|
const rawInboxContextFactorySymbol = Symbol("fedify.rawInboxContextFactory");
|
|
6049
6128
|
const INBOX_COMPOUND_PROOF_LIMITS = {
|
|
6050
6129
|
maxDepth: 64,
|
|
@@ -6104,7 +6183,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
6104
6183
|
if (!await authorizePredicate(context, identifier)) return await onUnauthorized(request);
|
|
6105
6184
|
}
|
|
6106
6185
|
if (actor instanceof _fedify_vocab.Tombstone) {
|
|
6107
|
-
const jsonLd = await actor
|
|
6186
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
6108
6187
|
return new Response(JSON.stringify(jsonLd), {
|
|
6109
6188
|
status: 410,
|
|
6110
6189
|
headers: {
|
|
@@ -6113,7 +6192,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
6113
6192
|
}
|
|
6114
6193
|
});
|
|
6115
6194
|
}
|
|
6116
|
-
const jsonLd = await actor
|
|
6195
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
6117
6196
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
6118
6197
|
"Content-Type": "application/activity+json",
|
|
6119
6198
|
Vary: "Accept"
|
|
@@ -6133,7 +6212,7 @@ async function handleObject(request, { values, context, objectDispatcher, author
|
|
|
6133
6212
|
if (authorizePredicate != null) {
|
|
6134
6213
|
if (!await authorizePredicate(context, values)) return await onUnauthorized(request);
|
|
6135
6214
|
}
|
|
6136
|
-
const jsonLd = await object
|
|
6215
|
+
const jsonLd = await serializeForResponse(object, context);
|
|
6137
6216
|
if (object instanceof _fedify_vocab.Tombstone) return new Response(request.method === "HEAD" ? null : JSON.stringify(jsonLd), {
|
|
6138
6217
|
status: 410,
|
|
6139
6218
|
headers: {
|
|
@@ -6385,13 +6464,13 @@ function recordCollectionMetrics(meterProvider, base, result, options = {}) {
|
|
|
6385
6464
|
* @param parameters The parameters for handling the collection.
|
|
6386
6465
|
* @returns A promise that resolves to an HTTP response.
|
|
6387
6466
|
*/
|
|
6388
|
-
async function handleCollection(request, { name: name$
|
|
6389
|
-
const spanName = name$
|
|
6467
|
+
async function handleCollection(request, { name: name$2, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, portable, tracerProvider, meterProvider, onUnauthorized, onNotFound }) {
|
|
6468
|
+
const spanName = name$2.trim().replace(/\s+/g, "_");
|
|
6390
6469
|
tracerProvider = tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
|
|
6391
6470
|
const tracer = tracerProvider.getTracer(require_http.name, require_http.version);
|
|
6392
6471
|
const cursor = new URL(request.url).searchParams.get("cursor");
|
|
6393
6472
|
const metricBase = {
|
|
6394
|
-
kind: getCollectionMetricKind(name$
|
|
6473
|
+
kind: getCollectionMetricKind(name$2),
|
|
6395
6474
|
page: cursor != null,
|
|
6396
6475
|
dispatcher: "built_in"
|
|
6397
6476
|
};
|
|
@@ -6437,7 +6516,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
6437
6516
|
span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
6438
6517
|
return await onNotFound(request);
|
|
6439
6518
|
}
|
|
6440
|
-
const items = filterCollectionItems(page.items, name$
|
|
6519
|
+
const items = filterCollectionItems(page.items, name$2, filterPredicate);
|
|
6441
6520
|
itemCount = items.length;
|
|
6442
6521
|
span.setAttribute("fedify.collection.items", itemCount);
|
|
6443
6522
|
return items;
|
|
@@ -6479,7 +6558,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
6479
6558
|
} else {
|
|
6480
6559
|
const uri = new URL(portable == null ? baseUri : pageBase);
|
|
6481
6560
|
uri.searchParams.set("cursor", cursor);
|
|
6482
|
-
const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$
|
|
6561
|
+
const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$2}`, {
|
|
6483
6562
|
kind: _opentelemetry_api.SpanKind.SERVER,
|
|
6484
6563
|
attributes: {
|
|
6485
6564
|
"activitypub.collection.id": uri.href,
|
|
@@ -6495,7 +6574,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
6495
6574
|
span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
6496
6575
|
return await onNotFound(request);
|
|
6497
6576
|
}
|
|
6498
|
-
const items = filterCollectionItems(page.items, name$
|
|
6577
|
+
const items = filterCollectionItems(page.items, name$2, filterPredicate);
|
|
6499
6578
|
itemCount = items.length;
|
|
6500
6579
|
span.setAttribute("fedify.collection.items", itemCount);
|
|
6501
6580
|
return {
|
|
@@ -6539,7 +6618,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
6539
6618
|
if (portable == null && collectionCallbacks.authorizePredicate != null) {
|
|
6540
6619
|
if (!await collectionCallbacks.authorizePredicate(context, identifier)) return finish(await onUnauthorized(request), "unauthorized");
|
|
6541
6620
|
}
|
|
6542
|
-
const jsonLd = await collection
|
|
6621
|
+
const jsonLd = await serializeForResponse(collection, context, portable != null);
|
|
6543
6622
|
if (portable != null) return await verifyPortableCollection(jsonLd, context, portable) ? finish(respondWithPortableCollection(request, jsonLd), "served") : finish(portableObjectInternalServerError(request), "error");
|
|
6544
6623
|
return finish(new Response(JSON.stringify(jsonLd), { headers: {
|
|
6545
6624
|
"Content-Type": "application/activity+json",
|
|
@@ -7138,7 +7217,11 @@ async function handleInboxInternal(request, parameters, span, snapshot) {
|
|
|
7138
7217
|
const standardLoader = snapshot.loader("standard");
|
|
7139
7218
|
const normalizationLoader = snapshot.loader("normalization");
|
|
7140
7219
|
const jsonWithoutSig = require_http.detachSignature(json);
|
|
7141
|
-
const hasLdSignature = require_http.
|
|
7220
|
+
const hasLdSignature = require_http.hasVerifiableSignature(json);
|
|
7221
|
+
if (!hasLdSignature) {
|
|
7222
|
+
const shape = require_http.describeSignatureShape(json);
|
|
7223
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
7224
|
+
}
|
|
7142
7225
|
const canAttemptAlternateAuthAfterLdSignatureFailure = skipSignatureVerification || hasHttpSignatureHeaders(request) || hasObjectIntegrityProof(jsonWithoutSig);
|
|
7143
7226
|
let deferredLdSignatureError = void 0;
|
|
7144
7227
|
const respondInvalidActivity = async (error) => {
|
|
@@ -8075,8 +8158,8 @@ var CustomCollectionHandler = class {
|
|
|
8075
8158
|
* @param CollectionPage The CollectionPage constructor.
|
|
8076
8159
|
* @param filterPredicate Optional filter predicate for items.
|
|
8077
8160
|
*/
|
|
8078
|
-
constructor(name$
|
|
8079
|
-
this.name = name$
|
|
8161
|
+
constructor(name$1, values, context, callbacks, tracerProvider = _opentelemetry_api.trace.getTracerProvider(), meterProvider, Collection, CollectionPage, filterPredicate, portable) {
|
|
8162
|
+
this.name = name$1;
|
|
8080
8163
|
this.values = values;
|
|
8081
8164
|
this.context = context;
|
|
8082
8165
|
this.callbacks = callbacks;
|
|
@@ -8100,7 +8183,7 @@ var CustomCollectionHandler = class {
|
|
|
8100
8183
|
* @returns A promise that resolves to the JSON-LD representation.
|
|
8101
8184
|
*/
|
|
8102
8185
|
async toJsonLd() {
|
|
8103
|
-
return (await this.collection
|
|
8186
|
+
return serializeForResponse(await this.collection, this.context, this.portable != null);
|
|
8104
8187
|
}
|
|
8105
8188
|
/**
|
|
8106
8189
|
* Fetches the collection with optional cursor for pagination.
|
|
@@ -8496,7 +8579,7 @@ var PortableCollectionRefusedError = class extends HandlerError {
|
|
|
8496
8579
|
* @since 0.3.0
|
|
8497
8580
|
*/
|
|
8498
8581
|
async function respondWithObject(object, options) {
|
|
8499
|
-
const jsonLd = await object
|
|
8582
|
+
const jsonLd = await serializeForResponse(object, options);
|
|
8500
8583
|
return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
|
|
8501
8584
|
}
|
|
8502
8585
|
/**
|
|
@@ -8570,7 +8653,7 @@ async function buildAcceptSignatureHeader(policy, kv, noncePrefix) {
|
|
|
8570
8653
|
}
|
|
8571
8654
|
async function setKey(kv, key, policy) {
|
|
8572
8655
|
const seconds = policy.nonceTtlSeconds ?? 300;
|
|
8573
|
-
const ttl = Temporal$
|
|
8656
|
+
const ttl = Temporal$8.Duration.from({ seconds });
|
|
8574
8657
|
await kv.set(key, true, { ttl });
|
|
8575
8658
|
}
|
|
8576
8659
|
const DEF_COMPONENTS = [
|
|
@@ -8624,6 +8707,13 @@ function getHttpKeyPrincipal(key) {
|
|
|
8624
8707
|
function isPortableActorKey(key) {
|
|
8625
8708
|
return key?.id != null && require_http.isPortableKeyId(key.id) && key.ownerId != null && require_http.isPortableId(key.ownerId);
|
|
8626
8709
|
}
|
|
8710
|
+
/** Applies compatibility changes after ordinary vocabulary serialization. */
|
|
8711
|
+
async function serializeForResponse(object, options, compact = false) {
|
|
8712
|
+
return await normalizeAttachmentArrays(await object.toJsonLd(compact ? {
|
|
8713
|
+
format: "compact",
|
|
8714
|
+
contextLoader: options?.contextLoader
|
|
8715
|
+
} : options), options?.contextLoader);
|
|
8716
|
+
}
|
|
8627
8717
|
/**
|
|
8628
8718
|
* Checks whether an activity needs an Object Integrity Proof by its DID:
|
|
8629
8719
|
* either it is performed by an [FEP-ef61] portable actor, or its own ID is
|
|
@@ -8660,7 +8750,7 @@ async function verifyPortableActivityId(activityId, jsonLd, options) {
|
|
|
8660
8750
|
}
|
|
8661
8751
|
//#endregion
|
|
8662
8752
|
//#region src/federation/kv.ts
|
|
8663
|
-
const Temporal$
|
|
8753
|
+
const Temporal$7 = require_http.Temporal;
|
|
8664
8754
|
/**
|
|
8665
8755
|
* Checks that all five atomic methods are functions. This checks capabilities
|
|
8666
8756
|
* only, not their correctness, supported scope, or persistence.
|
|
@@ -8708,7 +8798,7 @@ var MemoryKvStore = class {
|
|
|
8708
8798
|
}
|
|
8709
8799
|
#read(key, now) {
|
|
8710
8800
|
const entry = this.#values[key];
|
|
8711
|
-
if (entry == null || entry[1] != null && Temporal$
|
|
8801
|
+
if (entry == null || entry[1] != null && Temporal$7.Instant.compare(entry[1], now) <= 0) return void 0;
|
|
8712
8802
|
return entry[0];
|
|
8713
8803
|
}
|
|
8714
8804
|
#prepare(entries, now) {
|
|
@@ -8732,7 +8822,7 @@ var MemoryKvStore = class {
|
|
|
8732
8822
|
ttl: entry.options?.ttl
|
|
8733
8823
|
}));
|
|
8734
8824
|
const keys = this.#encodeKeys(captured.map((entry) => entry.key));
|
|
8735
|
-
const now = Temporal$
|
|
8825
|
+
const now = Temporal$7.Now.instant();
|
|
8736
8826
|
const prepared = captured.map((entry, index) => {
|
|
8737
8827
|
if (entry.newValue === void 0 && entry.ttl != null) throw new TypeError("A CAS deletion must not specify a TTL.");
|
|
8738
8828
|
const expiration = entry.ttl == null ? null : now.add(entry.ttl.round({ largestUnit: "hour" }));
|
|
@@ -8751,7 +8841,7 @@ var MemoryKvStore = class {
|
|
|
8751
8841
|
/** {@inheritDoc KvStore.get} */
|
|
8752
8842
|
async get(key) {
|
|
8753
8843
|
const encoded = this.#encodeKey(key);
|
|
8754
|
-
const now = Temporal$
|
|
8844
|
+
const now = Temporal$7.Now.instant();
|
|
8755
8845
|
const value = this.#read(encoded, now);
|
|
8756
8846
|
if (value === void 0) delete this.#values[encoded];
|
|
8757
8847
|
return value;
|
|
@@ -8762,7 +8852,7 @@ var MemoryKvStore = class {
|
|
|
8762
8852
|
key,
|
|
8763
8853
|
value,
|
|
8764
8854
|
options
|
|
8765
|
-
}], Temporal$
|
|
8855
|
+
}], Temporal$7.Now.instant()));
|
|
8766
8856
|
}
|
|
8767
8857
|
/** {@inheritDoc KvStore.delete} */
|
|
8768
8858
|
async delete(key) {
|
|
@@ -8780,12 +8870,12 @@ var MemoryKvStore = class {
|
|
|
8780
8870
|
/** {@inheritDoc AtomicKvStore.getMany} */
|
|
8781
8871
|
async getMany(keys) {
|
|
8782
8872
|
const encoded = this.#encodeKeyList(keys);
|
|
8783
|
-
const now = Temporal$
|
|
8873
|
+
const now = Temporal$7.Now.instant();
|
|
8784
8874
|
return encoded.map((key) => this.#read(key, now));
|
|
8785
8875
|
}
|
|
8786
8876
|
/** {@inheritDoc AtomicKvStore.setMany} */
|
|
8787
8877
|
async setMany(entries) {
|
|
8788
|
-
this.#apply(this.#prepare(entries, Temporal$
|
|
8878
|
+
this.#apply(this.#prepare(entries, Temporal$7.Now.instant()));
|
|
8789
8879
|
}
|
|
8790
8880
|
/** {@inheritDoc AtomicKvStore.deleteMany} */
|
|
8791
8881
|
async deleteMany(keys) {
|
|
@@ -8798,7 +8888,7 @@ var MemoryKvStore = class {
|
|
|
8798
8888
|
}
|
|
8799
8889
|
/** {@inheritDoc KvStore.list} */
|
|
8800
8890
|
async *list(prefix) {
|
|
8801
|
-
const now = Temporal$
|
|
8891
|
+
const now = Temporal$7.Now.instant();
|
|
8802
8892
|
for (const [encodedKey, entry] of Object.entries(this.#values)) {
|
|
8803
8893
|
const key = JSON.parse(encodedKey);
|
|
8804
8894
|
if (prefix != null) {
|
|
@@ -8806,7 +8896,7 @@ var MemoryKvStore = class {
|
|
|
8806
8896
|
if (!prefix.every((p, i) => key[i] === p)) continue;
|
|
8807
8897
|
}
|
|
8808
8898
|
const [value, expiration] = entry;
|
|
8809
|
-
if (expiration != null && Temporal$
|
|
8899
|
+
if (expiration != null && Temporal$7.Instant.compare(expiration, now) <= 0) {
|
|
8810
8900
|
if (this.#values[encodedKey] === entry) delete this.#values[encodedKey];
|
|
8811
8901
|
continue;
|
|
8812
8902
|
}
|
|
@@ -8819,7 +8909,7 @@ var MemoryKvStore = class {
|
|
|
8819
8909
|
};
|
|
8820
8910
|
//#endregion
|
|
8821
8911
|
//#region src/federation/outbound-observation.ts
|
|
8822
|
-
const Temporal$
|
|
8912
|
+
const Temporal$6 = require_http.Temporal;
|
|
8823
8913
|
function snapshotDeliveryIdentity(identity) {
|
|
8824
8914
|
if (identity == null || typeof identity.deliveryId !== "string" || identity.deliveryId.length < 1 || typeof identity.destinationInbox !== "string" || identity.destinationInbox.length < 1 || identity.broadcast == null || !(identity.broadcast.type === "unknown" || identity.broadcast.type === "known" && typeof identity.broadcast.id === "string" && identity.broadcast.id.length > 0) || !(identity.portableInbox == null || typeof identity.portableInbox === "string")) throw new TypeError("Invalid outbound delivery identity in queue metadata.");
|
|
8825
8915
|
return Object.freeze({
|
|
@@ -8961,7 +9051,7 @@ var OutboundAttemptObservation = class {
|
|
|
8961
9051
|
attemptId: this.#attemptId,
|
|
8962
9052
|
inboxUrl: this.inboxUrl,
|
|
8963
9053
|
exchangeIndex,
|
|
8964
|
-
observedAt: Temporal$
|
|
9054
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
8965
9055
|
request: snapshot,
|
|
8966
9056
|
response: responseSnapshot,
|
|
8967
9057
|
body,
|
|
@@ -8979,7 +9069,7 @@ var OutboundAttemptObservation = class {
|
|
|
8979
9069
|
attemptId: this.#attemptId,
|
|
8980
9070
|
inboxUrl: this.inboxUrl,
|
|
8981
9071
|
exchangeIndex,
|
|
8982
|
-
observedAt: Temporal$
|
|
9072
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
8983
9073
|
request,
|
|
8984
9074
|
outcome: Object.freeze(outcome),
|
|
8985
9075
|
...bodyCapture == null ? {} : { bodyCapture }
|
|
@@ -9050,7 +9140,7 @@ var OutboundAttemptObservation = class {
|
|
|
9050
9140
|
inboxUrl: this.inboxUrl,
|
|
9051
9141
|
httpExchangeCount: this.#exchangeCount,
|
|
9052
9142
|
senderPayload: this.#senderPayload,
|
|
9053
|
-
observedAt: Temporal$
|
|
9143
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
9054
9144
|
...this.#trace == null ? {} : { trace: this.#trace },
|
|
9055
9145
|
outcome: Object.freeze(outcome)
|
|
9056
9146
|
});
|
|
@@ -9238,7 +9328,7 @@ var OutboundWorkerObservation = class {
|
|
|
9238
9328
|
await this.#notify({ type: "completed" });
|
|
9239
9329
|
}
|
|
9240
9330
|
async #notify(result) {
|
|
9241
|
-
const observedAt = Temporal$
|
|
9331
|
+
const observedAt = Temporal$6.Now.instant().epochMilliseconds;
|
|
9242
9332
|
try {
|
|
9243
9333
|
const context = this.getContext();
|
|
9244
9334
|
await notifyObserver(context, this.callback, Object.freeze({
|
|
@@ -9346,7 +9436,7 @@ var OutboundDeliveryObservation = class {
|
|
|
9346
9436
|
planned() {
|
|
9347
9437
|
return notifyObserver(this.context, this.observer, Object.freeze({
|
|
9348
9438
|
...this.trace == null ? {} : { trace: this.trace },
|
|
9349
|
-
observedAt: Temporal$
|
|
9439
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
9350
9440
|
provenance: this.provenance,
|
|
9351
9441
|
local: snapshotLocalContext(this.context),
|
|
9352
9442
|
...this.#reference,
|
|
@@ -9359,7 +9449,7 @@ var OutboundDeliveryObservation = class {
|
|
|
9359
9449
|
this.#finished = true;
|
|
9360
9450
|
return notifyObserver(this.context, this.observer, Object.freeze({
|
|
9361
9451
|
...this.trace == null ? {} : { trace: this.trace },
|
|
9362
|
-
observedAt: Temporal$
|
|
9452
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
9363
9453
|
provenance: this.provenance,
|
|
9364
9454
|
local: snapshotLocalContext(this.context),
|
|
9365
9455
|
...this.#reference,
|
|
@@ -9372,7 +9462,7 @@ var OutboundDeliveryObservation = class {
|
|
|
9372
9462
|
this.#finished = true;
|
|
9373
9463
|
return notifyObserver(this.context, this.observer, Object.freeze({
|
|
9374
9464
|
...this.trace == null ? {} : { trace: this.trace },
|
|
9375
|
-
observedAt: Temporal$
|
|
9465
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
9376
9466
|
provenance: this.provenance,
|
|
9377
9467
|
local: snapshotLocalContext(this.context),
|
|
9378
9468
|
...this.#reference,
|
|
@@ -9570,7 +9660,7 @@ var OutboundBroadcastObservation = class OutboundBroadcastObservation {
|
|
|
9570
9660
|
return notifyObserver(this.context, this.#onBroadcast, Object.freeze({
|
|
9571
9661
|
...event,
|
|
9572
9662
|
...this.#trace == null ? {} : { trace: this.#trace },
|
|
9573
|
-
observedAt: Temporal$
|
|
9663
|
+
observedAt: Temporal$6.Now.instant().epochMilliseconds,
|
|
9574
9664
|
provenance: this.provenance,
|
|
9575
9665
|
local: snapshotLocalContext(this.context)
|
|
9576
9666
|
}), "broadcast");
|
|
@@ -9923,6 +10013,103 @@ function buildPortableCollectionView(collectionId, requestUrl) {
|
|
|
9923
10013
|
return view;
|
|
9924
10014
|
}
|
|
9925
10015
|
//#endregion
|
|
10016
|
+
//#region src/sig/proof-creation.ts
|
|
10017
|
+
const Temporal$5 = require_http.Temporal;
|
|
10018
|
+
/** Signs the exact serialized message supplied by an internal producer. */
|
|
10019
|
+
async function createProofForJsonLd(jsonLd, privateKey, keyId, created) {
|
|
10020
|
+
require_http.validateCryptoKey(privateKey, "private");
|
|
10021
|
+
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
10022
|
+
const encoder = new TextEncoder();
|
|
10023
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(jsonLd)));
|
|
10024
|
+
created ??= Temporal$5.Now.instant();
|
|
10025
|
+
const proofConfig = {
|
|
10026
|
+
"@context": jsonLd["@context"],
|
|
10027
|
+
type: "DataIntegrityProof",
|
|
10028
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
10029
|
+
verificationMethod: keyId.href,
|
|
10030
|
+
proofPurpose: "assertionMethod",
|
|
10031
|
+
created: created.toString()
|
|
10032
|
+
};
|
|
10033
|
+
const proofDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(proofConfig)));
|
|
10034
|
+
const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
|
|
10035
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
10036
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
10037
|
+
const sig = await crypto.subtle.sign("Ed25519", (0, _fedify_vocab_runtime_internal.asCryptoKey)(privateKey), digest);
|
|
10038
|
+
return new _fedify_vocab.DataIntegrityProof({
|
|
10039
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
10040
|
+
verificationMethod: keyId,
|
|
10041
|
+
proofPurpose: "assertionMethod",
|
|
10042
|
+
created,
|
|
10043
|
+
proofValue: new Uint8Array(sig)
|
|
10044
|
+
});
|
|
10045
|
+
}
|
|
10046
|
+
//#endregion
|
|
10047
|
+
//#region src/compat/delivery-jsonld.ts
|
|
10048
|
+
/**
|
|
10049
|
+
* Returns changed wire JSON only; unchanged documents keep the existing
|
|
10050
|
+
* delivery signing path. This uses ordinary vocabulary serialization, without
|
|
10051
|
+
* retaining or repairing independently signed child representations.
|
|
10052
|
+
*/
|
|
10053
|
+
async function prepareActivityJsonLd(activity, contextLoader) {
|
|
10054
|
+
if (activity.proofIds.length > 0) return void 0;
|
|
10055
|
+
for await (const _ of activity.getProofs({ contextLoader })) return void 0;
|
|
10056
|
+
const source = await activity.clone({}, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) }).toJsonLd({
|
|
10057
|
+
format: "compact",
|
|
10058
|
+
contextLoader
|
|
10059
|
+
});
|
|
10060
|
+
const prepared = await require_http.normalizeOutgoingActivityJsonLd(source, contextLoader, { preserveSecuredDocuments: true });
|
|
10061
|
+
return prepared !== source && typeof prepared === "object" && prepared != null && !Array.isArray(prepared) ? prepared : void 0;
|
|
10062
|
+
}
|
|
10063
|
+
/** Signs a changed, proof-free delivery map without serializing it again. */
|
|
10064
|
+
async function signActivityJsonLd(activity, unsigned, keys, options) {
|
|
10065
|
+
const proofs = [];
|
|
10066
|
+
const serializedProofs = [];
|
|
10067
|
+
const tracer = (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version);
|
|
10068
|
+
for (const { privateKey, keyId } of keys) {
|
|
10069
|
+
const proof = await tracer.startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": (0, _fedify_vocab.getTypeId)(activity).href } }, async (span) => {
|
|
10070
|
+
try {
|
|
10071
|
+
if (activity.id != null) span.setAttribute("activitypub.object.id", activity.id.href);
|
|
10072
|
+
const proof = await createProofForJsonLd(unsigned, privateKey, keyId);
|
|
10073
|
+
if (span.isRecording()) {
|
|
10074
|
+
span.setAttribute("object_integrity_proofs.cryptosuite", "eddsa-jcs-2022");
|
|
10075
|
+
span.setAttribute("object_integrity_proofs.key_id", keyId.href);
|
|
10076
|
+
span.setAttribute("object_integrity_proofs.signature", (0, byte_encodings_hex.encodeHex)(proof.proofValue));
|
|
10077
|
+
}
|
|
10078
|
+
return proof;
|
|
10079
|
+
} catch (error) {
|
|
10080
|
+
span.setStatus({
|
|
10081
|
+
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
10082
|
+
message: String(error)
|
|
10083
|
+
});
|
|
10084
|
+
throw error;
|
|
10085
|
+
} finally {
|
|
10086
|
+
span.end();
|
|
10087
|
+
}
|
|
10088
|
+
});
|
|
10089
|
+
proofs.push(proof);
|
|
10090
|
+
serializedProofs.push({
|
|
10091
|
+
"@context": unsigned["@context"],
|
|
10092
|
+
type: "DataIntegrityProof",
|
|
10093
|
+
cryptosuite: proof.cryptosuite,
|
|
10094
|
+
verificationMethod: keyId.href,
|
|
10095
|
+
proofPurpose: "assertionMethod",
|
|
10096
|
+
created: proof.created.toString(),
|
|
10097
|
+
proofValue: new TextDecoder().decode((0, _fedify_vocab_runtime.encodeMultibase)("base58btc", proof.proofValue))
|
|
10098
|
+
});
|
|
10099
|
+
}
|
|
10100
|
+
if (proofs.length === 0) return {
|
|
10101
|
+
activity,
|
|
10102
|
+
jsonLd: unsigned
|
|
10103
|
+
};
|
|
10104
|
+
return {
|
|
10105
|
+
activity: activity.clone({ proofs }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) }),
|
|
10106
|
+
jsonLd: {
|
|
10107
|
+
...unsigned,
|
|
10108
|
+
proof: serializedProofs.length === 1 ? serializedProofs[0] : serializedProofs
|
|
10109
|
+
}
|
|
10110
|
+
};
|
|
10111
|
+
}
|
|
10112
|
+
//#endregion
|
|
9926
10113
|
//#region src/federation/outgoing-proof.ts
|
|
9927
10114
|
function formatKeyIds(candidates) {
|
|
9928
10115
|
return candidates.map((c) => c.verificationMethod.href).join(", ");
|
|
@@ -9990,6 +10177,15 @@ async function signOutgoingActivity(activity, candidates, options) {
|
|
|
9990
10177
|
const { contextLoader, tracerProvider } = options;
|
|
9991
10178
|
assertPortableActorActivity(activity);
|
|
9992
10179
|
const sign = async (selected) => {
|
|
10180
|
+
const prepared = !hasProof ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
|
|
10181
|
+
if (prepared != null) return {
|
|
10182
|
+
...await signActivityJsonLd(activity, prepared, selected.map(({ verificationMethod, privateKey }) => ({
|
|
10183
|
+
keyId: verificationMethod,
|
|
10184
|
+
privateKey
|
|
10185
|
+
})), { tracerProvider: tracerProvider ?? _opentelemetry_api.trace.getTracerProvider() }),
|
|
10186
|
+
hasProof: true,
|
|
10187
|
+
proofCreated: true
|
|
10188
|
+
};
|
|
9993
10189
|
for (const { verificationMethod, privateKey } of selected) activity = await require_http.signObject(activity, privateKey, verificationMethod, {
|
|
9994
10190
|
contextLoader,
|
|
9995
10191
|
tracerProvider
|
|
@@ -11160,6 +11356,13 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
11160
11356
|
if (resolved != null) return resolved;
|
|
11161
11357
|
return this.taskQueueResolution === "strict" ? void 0 : this.outboxQueue;
|
|
11162
11358
|
}
|
|
11359
|
+
#listenQueue(queue, ctxData, signal) {
|
|
11360
|
+
try {
|
|
11361
|
+
return queue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal });
|
|
11362
|
+
} catch (error) {
|
|
11363
|
+
return Promise.reject(error);
|
|
11364
|
+
}
|
|
11365
|
+
}
|
|
11163
11366
|
async _startQueueInternal(ctxData, signal, queue) {
|
|
11164
11367
|
const taskQueue = this.taskQueue ?? (this.taskQueueResolution === "fallback" ? this.outboxQueue : void 0);
|
|
11165
11368
|
const customQueues = this.taskDefinitions.values().map((def) => ["task", def.queue]);
|
|
@@ -11181,10 +11384,22 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
11181
11384
|
if (this.startedQueues.has(target)) continue;
|
|
11182
11385
|
this.startedQueues.add(target);
|
|
11183
11386
|
logger.debug("Starting a {role} queue worker.", { role });
|
|
11184
|
-
promises.push(
|
|
11387
|
+
promises.push(this.#listenQueue(target, ctxData, signal));
|
|
11185
11388
|
}
|
|
11186
11389
|
await Promise.all(promises);
|
|
11187
11390
|
}
|
|
11391
|
+
#queueStartupFailureReported = false;
|
|
11392
|
+
_startQueueAutomatically(ctxData) {
|
|
11393
|
+
this._startQueueInternal(ctxData).catch((error) => {
|
|
11394
|
+
if (this.#queueStartupFailureReported) return;
|
|
11395
|
+
this.#queueStartupFailureReported = true;
|
|
11396
|
+
(0, _logtape_logtape.getLogger)([
|
|
11397
|
+
"fedify",
|
|
11398
|
+
"federation",
|
|
11399
|
+
"queue"
|
|
11400
|
+
]).warn("Failed to start queue workers automatically: {error}", { error });
|
|
11401
|
+
});
|
|
11402
|
+
}
|
|
11188
11403
|
async processQueuedTask(contextData, message) {
|
|
11189
11404
|
const extractedContext = _opentelemetry_api.propagation.extract(_opentelemetry_api.context.active(), message.traceContext);
|
|
11190
11405
|
let provenance = emptyProvenance;
|
|
@@ -11348,10 +11563,10 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
11348
11563
|
"fedify",
|
|
11349
11564
|
"federation",
|
|
11350
11565
|
"fanout"
|
|
11351
|
-
]).debug("Fanning out activity {activityId} to {inboxes} inbox(es)...", {
|
|
11566
|
+
]).debug("Fanning out activity {activityId} to {inboxes} inbox(es)...", () => ({
|
|
11352
11567
|
activityId: message.activityId,
|
|
11353
11568
|
inboxes: globalThis.Object.keys(message.inboxes).length
|
|
11354
|
-
});
|
|
11569
|
+
}));
|
|
11355
11570
|
const importKeys = () => Promise.all(message.keys.map(async ({ keyId, privateKey }) => ({
|
|
11356
11571
|
keyId: new URL(keyId),
|
|
11357
11572
|
privateKey: await require_http.importJwk(privateKey, "private")
|
|
@@ -12268,7 +12483,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12268
12483
|
}
|
|
12269
12484
|
try {
|
|
12270
12485
|
if (activity == null) {
|
|
12271
|
-
const hasSignatureField = require_http.
|
|
12486
|
+
const hasSignatureField = require_http.hasSignatureLike(message.activity);
|
|
12272
12487
|
const shouldParseFromNormalizedSignedPayload = message.ldSignatureVerified === true || message.normalizedActivity != null || message.ldSignatureVerified == null && hasSignatureField;
|
|
12273
12488
|
const parseContext = hasSignatureField ? {
|
|
12274
12489
|
...context,
|
|
@@ -12602,10 +12817,10 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12602
12817
|
const { hasProof, proofCreated } = signed;
|
|
12603
12818
|
observation?.setPhase("serialization");
|
|
12604
12819
|
const serializeActivity = async () => {
|
|
12605
|
-
let result = !proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
12820
|
+
let result = signed.jsonLd ?? (!proofCreated && options.activityJsonLd != null ? options.activityJsonLd : await activity.toJsonLd({
|
|
12606
12821
|
format: "compact",
|
|
12607
12822
|
contextLoader
|
|
12608
|
-
});
|
|
12823
|
+
}));
|
|
12609
12824
|
if (proofCreated || !hasProof || options.normalizeExistingProofs) result = await require_http.normalizeOutgoingActivityJsonLd(result, contextLoader, { preserveNestedSecuredDocuments: true });
|
|
12610
12825
|
return result;
|
|
12611
12826
|
};
|
|
@@ -12615,13 +12830,13 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12615
12830
|
if (worker == null) validateProofShape();
|
|
12616
12831
|
else await worker.prepare("validation", validateProofShape);
|
|
12617
12832
|
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 });
|
|
12618
|
-
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.", {
|
|
12833
|
+
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.", () => ({
|
|
12619
12834
|
activityId,
|
|
12620
12835
|
keys: keys.map((pair) => ({
|
|
12621
12836
|
keyId: pair.keyId.href,
|
|
12622
12837
|
privateKey: pair.privateKey
|
|
12623
12838
|
}))
|
|
12624
|
-
});
|
|
12839
|
+
}));
|
|
12625
12840
|
else {
|
|
12626
12841
|
const signLinkedData = async () => {
|
|
12627
12842
|
try {
|
|
@@ -12641,13 +12856,13 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12641
12856
|
};
|
|
12642
12857
|
jsonLd = worker == null ? await signLinkedData() : await worker.prepare("signing", signLinkedData);
|
|
12643
12858
|
}
|
|
12644
|
-
if (!hasProof) logger.warn("No supported key found to create a proof for the activity {activityId}. The activity will be sent without a proof. In order to create a proof, at least one Ed25519 key must be provided.", {
|
|
12859
|
+
if (!hasProof) logger.warn("No supported key found to create a proof for the activity {activityId}. The activity will be sent without a proof. In order to create a proof, at least one Ed25519 key must be provided.", () => ({
|
|
12645
12860
|
activityId,
|
|
12646
12861
|
keys: keys.map((pair) => ({
|
|
12647
12862
|
keyId: pair.keyId.href,
|
|
12648
12863
|
privateKey: pair.privateKey
|
|
12649
12864
|
}))
|
|
12650
|
-
});
|
|
12865
|
+
}));
|
|
12651
12866
|
observation?.setPhase("request-preparation");
|
|
12652
12867
|
if (immediate || this.outboxQueue == null) {
|
|
12653
12868
|
if (immediate) logger.debug("Sending activity immediately without queue since immediate option is set.", {
|
|
@@ -12659,41 +12874,45 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12659
12874
|
activity: jsonLd
|
|
12660
12875
|
});
|
|
12661
12876
|
const promises = [];
|
|
12662
|
-
|
|
12663
|
-
const
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12877
|
+
try {
|
|
12878
|
+
for (const inbox in inboxes) {
|
|
12879
|
+
const delivery = observation?.delivery(inbox);
|
|
12880
|
+
let sending;
|
|
12881
|
+
try {
|
|
12882
|
+
const createHeaders = collectionSync == null ? void 0 : async () => new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) });
|
|
12883
|
+
const sendActivityId = activity.id?.href;
|
|
12884
|
+
const activityType = (0, _fedify_vocab.getTypeId)(activity).href;
|
|
12885
|
+
observation?.setActivity({
|
|
12886
|
+
...sendActivityId == null ? {} : { id: sendActivityId },
|
|
12887
|
+
type: activityType
|
|
12888
|
+
});
|
|
12889
|
+
sending = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
12890
|
+
attemptStarted: worker == null ? void 0 : (target) => worker.directAttemptStarted(target, observation?.continuation(inbox)?.outbound),
|
|
12891
|
+
observation: delivery,
|
|
12892
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
|
12893
|
+
keys,
|
|
12894
|
+
activity: jsonLd,
|
|
12895
|
+
activityId: sendActivityId,
|
|
12896
|
+
activityType,
|
|
12897
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
12898
|
+
headers: createHeaders == null ? void 0 : await (worker == null ? createHeaders() : worker.prepare("request-preparation", createHeaders)),
|
|
12899
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
12900
|
+
meterProvider: this.meterProvider,
|
|
12901
|
+
tracerProvider: this.tracerProvider
|
|
12902
|
+
});
|
|
12903
|
+
} catch (error) {
|
|
12904
|
+
if (delivery != null) await delivery.failed(error);
|
|
12905
|
+
throw error;
|
|
12906
|
+
}
|
|
12907
|
+
sending.catch(() => {});
|
|
12908
|
+
promises.push(sending);
|
|
12909
|
+
if (delivery != null) await delivery.handoff({ type: "direct" });
|
|
12690
12910
|
}
|
|
12691
|
-
if (observation != null)
|
|
12692
|
-
|
|
12693
|
-
|
|
12911
|
+
if (observation != null) await observation.prepared("delivery");
|
|
12912
|
+
await Promise.all(promises);
|
|
12913
|
+
} finally {
|
|
12914
|
+
await Promise.allSettled(promises);
|
|
12694
12915
|
}
|
|
12695
|
-
if (observation != null) await observation.prepared("delivery");
|
|
12696
|
-
await Promise.all(promises);
|
|
12697
12916
|
return;
|
|
12698
12917
|
}
|
|
12699
12918
|
logger.debug("Enqueuing activity {activityId} to send later.", {
|
|
@@ -12710,7 +12929,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
12710
12929
|
privateKey: privateKeyJwk
|
|
12711
12930
|
});
|
|
12712
12931
|
}
|
|
12713
|
-
if (!this.manuallyStartQueue) this.
|
|
12932
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(ctx.data);
|
|
12714
12933
|
observation?.setPhase("request-preparation");
|
|
12715
12934
|
const carrier = {};
|
|
12716
12935
|
const injectTraceContext = () => _opentelemetry_api.propagation.inject(_opentelemetry_api.context.active(), carrier);
|
|
@@ -13454,7 +13673,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
13454
13673
|
return await observation.run(() => Promise.reject(error), span);
|
|
13455
13674
|
}
|
|
13456
13675
|
async #handleInbox(request, { recipient, context, contextData, onNotFound, portableInbox, observation }) {
|
|
13457
|
-
if (!this.manuallyStartQueue) this.
|
|
13676
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(contextData);
|
|
13458
13677
|
const inboxContextFactory = context.toInboxContext.bind(context);
|
|
13459
13678
|
inboxContextFactory[rawInboxContextFactorySymbol] = context.toInboxContext.bind(context);
|
|
13460
13679
|
return await handleInbox(request, {
|
|
@@ -13580,7 +13799,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
13580
13799
|
kv: this.kv,
|
|
13581
13800
|
kvPrefix: this.kvPrefixes.portableInboxForwarding,
|
|
13582
13801
|
outboxQueue: this.outboxQueue,
|
|
13583
|
-
startQueue: this.manuallyStartQueue ? void 0 : () => this.
|
|
13802
|
+
startQueue: this.manuallyStartQueue ? void 0 : () => this._startQueueAutomatically(contextData),
|
|
13584
13803
|
allowPrivateAddress: this.allowPrivateAddress,
|
|
13585
13804
|
getKeys: () => this.#getPortableGatewayKeyPairs(context, identifier, recipient),
|
|
13586
13805
|
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock, { specTtl: this.httpMessageSignaturesSpecTtl }),
|
|
@@ -14090,6 +14309,8 @@ var ContextImpl = class ContextImpl {
|
|
|
14090
14309
|
for (const keyPair of keyPairs) {
|
|
14091
14310
|
const newPair = {
|
|
14092
14311
|
...keyPair,
|
|
14312
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.privateKey),
|
|
14313
|
+
publicKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.publicKey),
|
|
14093
14314
|
cryptographicKey: new _fedify_vocab.CryptographicKey({
|
|
14094
14315
|
id: keyPair.keyId,
|
|
14095
14316
|
owner,
|
|
@@ -14188,10 +14409,16 @@ var ContextImpl = class ContextImpl {
|
|
|
14188
14409
|
return identifierPromise.then(async (identifier) => {
|
|
14189
14410
|
if (identifier == null) return this.documentLoader;
|
|
14190
14411
|
const pair = await this.getRsaKeyPairFromIdentifier(identifier);
|
|
14191
|
-
return pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(
|
|
14412
|
+
return pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory({
|
|
14413
|
+
keyId: pair.keyId,
|
|
14414
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(pair.privateKey)
|
|
14415
|
+
});
|
|
14192
14416
|
});
|
|
14193
14417
|
}
|
|
14194
|
-
return this.federation.authenticatedDocumentLoaderFactory(
|
|
14418
|
+
return this.federation.authenticatedDocumentLoaderFactory({
|
|
14419
|
+
keyId: identity.keyId,
|
|
14420
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(identity.privateKey)
|
|
14421
|
+
});
|
|
14195
14422
|
}
|
|
14196
14423
|
lookupObject(identifier, options = {}) {
|
|
14197
14424
|
return (0, _fedify_vocab.lookupObject)(identifier, {
|
|
@@ -14217,10 +14444,14 @@ var ContextImpl = class ContextImpl {
|
|
|
14217
14444
|
return options.parse === "none" ? require_types.getNodeInfo(url, {
|
|
14218
14445
|
parse: "none",
|
|
14219
14446
|
direct: options.direct,
|
|
14447
|
+
timeout: options.timeout,
|
|
14448
|
+
signal: options.signal,
|
|
14220
14449
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
14221
14450
|
}) : require_types.getNodeInfo(url, {
|
|
14222
14451
|
parse: options.parse,
|
|
14223
14452
|
direct: options.direct,
|
|
14453
|
+
timeout: options.timeout,
|
|
14454
|
+
signal: options.signal,
|
|
14224
14455
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
14225
14456
|
});
|
|
14226
14457
|
}
|
|
@@ -14241,7 +14472,18 @@ var ContextImpl = class ContextImpl {
|
|
|
14241
14472
|
await this.#enqueueTasks(task, payloads, options);
|
|
14242
14473
|
}
|
|
14243
14474
|
sendActivity(sender, recipients, activity, options = {}) {
|
|
14244
|
-
return observeOutboundBroadcast(this, this.federation.outboundObservers, (observation, provenance) => {
|
|
14475
|
+
return observeOutboundBroadcast(this, this.federation.outboundObservers, async (observation, provenance) => {
|
|
14476
|
+
observation?.setPhase("signing");
|
|
14477
|
+
let activityJsonLd = void 0;
|
|
14478
|
+
let hasProof = activity.proofIds.length > 0;
|
|
14479
|
+
if (!hasProof) for await (const _ of activity.getProofs({ contextLoader: this.contextLoader })) {
|
|
14480
|
+
hasProof = true;
|
|
14481
|
+
break;
|
|
14482
|
+
}
|
|
14483
|
+
if (hasProof) {
|
|
14484
|
+
activityJsonLd = await activity.toJsonLd({ contextLoader: this.contextLoader });
|
|
14485
|
+
if (!hasTopLevelProof(activityJsonLd)) activityJsonLd = void 0;
|
|
14486
|
+
}
|
|
14245
14487
|
const tracer = this.tracerProvider.getTracer(require_http.name, require_http.version);
|
|
14246
14488
|
const parentSpanContext = _opentelemetry_api.trace.getSpanContext(_opentelemetry_api.context.active());
|
|
14247
14489
|
const activityType = (0, _fedify_vocab.getTypeId)(activity).href;
|
|
@@ -14264,7 +14506,7 @@ var ContextImpl = class ContextImpl {
|
|
|
14264
14506
|
type: activityType,
|
|
14265
14507
|
...activityId == null ? {} : { id: activityId }
|
|
14266
14508
|
});
|
|
14267
|
-
await this.sendActivityInternal(sender, recipients, activity, options, span, observation, provenance);
|
|
14509
|
+
await this.sendActivityInternal(sender, recipients, activity, options, span, observation, provenance, activityJsonLd);
|
|
14268
14510
|
} catch (e) {
|
|
14269
14511
|
span.setStatus({
|
|
14270
14512
|
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
@@ -14277,7 +14519,7 @@ var ContextImpl = class ContextImpl {
|
|
|
14277
14519
|
});
|
|
14278
14520
|
}, "send", options.dispatchId);
|
|
14279
14521
|
}
|
|
14280
|
-
async sendActivityInternal(sender, recipients, activity, options, span, observation, provenance = getOutboundProvenance(this)) {
|
|
14522
|
+
async sendActivityInternal(sender, recipients, activity, options, span, observation, provenance = getOutboundProvenance(this), activityJsonLd) {
|
|
14281
14523
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
14282
14524
|
"fedify",
|
|
14283
14525
|
"federation",
|
|
@@ -14342,6 +14584,21 @@ var ContextImpl = class ContextImpl {
|
|
|
14342
14584
|
observation?.setPhase("transformation");
|
|
14343
14585
|
if (this.federation.activityTransformers.length > 0) observation?.setActivity({});
|
|
14344
14586
|
for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
|
|
14587
|
+
let contextMatches = false;
|
|
14588
|
+
if (activityJsonLd != null) {
|
|
14589
|
+
const capturedJsonLd = activityJsonLd;
|
|
14590
|
+
const transformedJsonLd = await activity.toJsonLd({
|
|
14591
|
+
format: "compact",
|
|
14592
|
+
contextLoader: this.contextLoader
|
|
14593
|
+
});
|
|
14594
|
+
const contentChanged = getContentFields(transformedJsonLd) !== getContentFields(capturedJsonLd);
|
|
14595
|
+
contextMatches = getContextFields(transformedJsonLd) === getContextFields(capturedJsonLd);
|
|
14596
|
+
const proofsChanged = getProofFields(transformedJsonLd) !== getProofFields(capturedJsonLd);
|
|
14597
|
+
if (contentChanged || !contextMatches && proofsChanged) {
|
|
14598
|
+
activity = activity.clone({ proofs: await getUncapturedProofs(activity, capturedJsonLd, this.contextLoader) }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
14599
|
+
activityJsonLd = void 0;
|
|
14600
|
+
} else if (proofsChanged) activityJsonLd = void 0;
|
|
14601
|
+
}
|
|
14345
14602
|
let transformedActivityId;
|
|
14346
14603
|
try {
|
|
14347
14604
|
transformedActivityId = activity?.id?.href;
|
|
@@ -14367,7 +14624,11 @@ var ContextImpl = class ContextImpl {
|
|
|
14367
14624
|
throw new TypeError("The activity to send must have at least one actor property.");
|
|
14368
14625
|
}
|
|
14369
14626
|
observation?.setPhase("signing");
|
|
14370
|
-
|
|
14627
|
+
if (actorKeyPairs != null && activityJsonLd != null && !contextMatches && actorKeyPairs.some((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null && !require_http.isPortableKeyId(kp.multikey.id))) {
|
|
14628
|
+
activity = activity.clone({ proofs: [] }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
14629
|
+
activityJsonLd = void 0;
|
|
14630
|
+
}
|
|
14631
|
+
const signed = await signOutgoingActivity(activity, actorKeyPairs == null ? keys.map(({ keyId, privateKey }) => ({
|
|
14371
14632
|
verificationMethod: keyId,
|
|
14372
14633
|
privateKey
|
|
14373
14634
|
})) : actorKeyPairs.flatMap((kp) => kp.multikey.id == null ? [] : [{
|
|
@@ -14378,7 +14639,8 @@ var ContextImpl = class ContextImpl {
|
|
|
14378
14639
|
tracerProvider: this.tracerProvider,
|
|
14379
14640
|
appendToExistingProofs: actorKeyPairs != null
|
|
14380
14641
|
});
|
|
14381
|
-
activity =
|
|
14642
|
+
activity = signed.activity;
|
|
14643
|
+
const { proofCreated } = signed;
|
|
14382
14644
|
observation?.setPhase("destination-planning");
|
|
14383
14645
|
const inboxes = extractInboxes({
|
|
14384
14646
|
recipients: expandedRecipients,
|
|
@@ -14394,16 +14656,16 @@ var ContextImpl = class ContextImpl {
|
|
|
14394
14656
|
if (observation != null) await observation.skipped();
|
|
14395
14657
|
return false;
|
|
14396
14658
|
}
|
|
14397
|
-
logger.debug("Sending activity {activityId} to inboxes:\n{inboxes}", {
|
|
14659
|
+
logger.debug("Sending activity {activityId} to inboxes:\n{inboxes}", () => ({
|
|
14398
14660
|
inboxes: globalThis.Object.keys(inboxes),
|
|
14399
14661
|
activityId: activity.id?.href,
|
|
14400
14662
|
activity
|
|
14401
|
-
});
|
|
14663
|
+
}));
|
|
14402
14664
|
observation?.setPhase("serialization");
|
|
14403
|
-
|
|
14665
|
+
activityJsonLd = signed.jsonLd ?? (!proofCreated && activityJsonLd != null ? activityJsonLd : await activity.toJsonLd({
|
|
14404
14666
|
format: "compact",
|
|
14405
14667
|
contextLoader: this.contextLoader
|
|
14406
|
-
});
|
|
14668
|
+
}));
|
|
14407
14669
|
try {
|
|
14408
14670
|
await warnCompatibleIdsInJson(activityJsonLd, this instanceof RequestContextImpl && !this.isInActorDispatcher() ? this : void 0);
|
|
14409
14671
|
} catch (error) {
|
|
@@ -14456,7 +14718,7 @@ var ContextImpl = class ContextImpl {
|
|
|
14456
14718
|
normalizeExistingProofs: proofCreated || options.normalizeExistingProofs,
|
|
14457
14719
|
traceContext: carrier
|
|
14458
14720
|
};
|
|
14459
|
-
if (!this.federation.manuallyStartQueue) this.federation.
|
|
14721
|
+
if (!this.federation.manuallyStartQueue) this.federation._startQueueAutomatically(this.data);
|
|
14460
14722
|
if (observation != null) await observation.prepared("fanout");
|
|
14461
14723
|
await (observation == null ? this.federation.fanoutQueue.enqueue(message, { orderingKey: options.orderingKey }) : observation.enqueue(globalThis.Object.keys(inboxes).map((inbox) => ({
|
|
14462
14724
|
inbox,
|
|
@@ -14990,42 +15252,46 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
14990
15252
|
if (observation != null) await observation.skipped();
|
|
14991
15253
|
return false;
|
|
14992
15254
|
}
|
|
14993
|
-
logger.debug("Forwarding activity {activityId} to inboxes:\n{inboxes}", {
|
|
15255
|
+
logger.debug("Forwarding activity {activityId} to inboxes:\n{inboxes}", () => ({
|
|
14994
15256
|
inboxes: globalThis.Object.keys(inboxes),
|
|
14995
15257
|
activityId: ctx.activityId,
|
|
14996
15258
|
activity: ctx.activity
|
|
14997
|
-
});
|
|
15259
|
+
}));
|
|
14998
15260
|
if (options?.immediate || ctx.federation.outboxQueue == null) {
|
|
14999
15261
|
if (options?.immediate) logger.debug("Forwarding activity immediately without queue since immediate option is set.");
|
|
15000
15262
|
else logger.debug("Forwarding activity immediately without queue since queue is not set.");
|
|
15001
15263
|
observation?.setPhase("request-preparation");
|
|
15002
15264
|
const promises = [];
|
|
15003
|
-
|
|
15004
|
-
const
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15265
|
+
try {
|
|
15266
|
+
for (const inbox in inboxes) {
|
|
15267
|
+
const delivery = observation?.delivery(inbox);
|
|
15268
|
+
let sending;
|
|
15269
|
+
try {
|
|
15270
|
+
sending = sendActivityToInbox(inbox, inboxes[inbox].gatewayInboxes, {
|
|
15271
|
+
observation: delivery,
|
|
15272
|
+
allowPrivateAddress: ctx.federation.allowPrivateAddress,
|
|
15273
|
+
keys,
|
|
15274
|
+
activity: ctx.activity,
|
|
15275
|
+
activityId: ctx.activityId,
|
|
15276
|
+
activityType: ctx.activityType,
|
|
15277
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
15278
|
+
meterProvider: ctx.meterProvider,
|
|
15279
|
+
tracerProvider: ctx.tracerProvider,
|
|
15280
|
+
specDeterminer: new KvSpecDeterminer(ctx.federation.kv, ctx.federation.kvPrefixes.httpMessageSignaturesSpec, ctx.federation.firstKnock, { specTtl: ctx.federation.httpMessageSignaturesSpecTtl })
|
|
15281
|
+
});
|
|
15282
|
+
} catch (error) {
|
|
15283
|
+
if (delivery != null) await delivery.failed(error);
|
|
15284
|
+
throw error;
|
|
15285
|
+
}
|
|
15286
|
+
sending.catch(() => {});
|
|
15287
|
+
promises.push(sending);
|
|
15288
|
+
if (delivery != null) await delivery.handoff({ type: "direct" });
|
|
15022
15289
|
}
|
|
15023
|
-
if (observation != null)
|
|
15024
|
-
|
|
15025
|
-
|
|
15290
|
+
if (observation != null) await observation.prepared("delivery");
|
|
15291
|
+
await Promise.all(promises);
|
|
15292
|
+
} finally {
|
|
15293
|
+
await Promise.allSettled(promises);
|
|
15026
15294
|
}
|
|
15027
|
-
if (observation != null) await observation.prepared("delivery");
|
|
15028
|
-
await Promise.all(promises);
|
|
15029
15295
|
return true;
|
|
15030
15296
|
}
|
|
15031
15297
|
logger.debug("Enqueuing activity {activityId} to forward later.", {
|
|
@@ -15033,7 +15299,7 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
15033
15299
|
activity: ctx.activity
|
|
15034
15300
|
});
|
|
15035
15301
|
observation?.setPhase("request-preparation");
|
|
15036
|
-
if (!ctx.federation.manuallyStartQueue) ctx.federation.
|
|
15302
|
+
if (!ctx.federation.manuallyStartQueue) ctx.federation._startQueueAutomatically(ctx.data);
|
|
15037
15303
|
observation?.setPhase("key-resolution");
|
|
15038
15304
|
const keyJwkPairs = [];
|
|
15039
15305
|
for (const { keyId, privateKey } of keys) {
|
|
@@ -15243,6 +15509,69 @@ var KvSpecDeterminer = class {
|
|
|
15243
15509
|
function notFound(_request) {
|
|
15244
15510
|
return new Response("Not Found", { status: 404 });
|
|
15245
15511
|
}
|
|
15512
|
+
function hasTopLevelProof(value) {
|
|
15513
|
+
return typeof value === "object" && value != null && !Array.isArray(value) && globalThis.Object.prototype.hasOwnProperty.call(value, "proof");
|
|
15514
|
+
}
|
|
15515
|
+
function getContentFields(value) {
|
|
15516
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
15517
|
+
const record = { ...value };
|
|
15518
|
+
delete record["@context"];
|
|
15519
|
+
delete record.proof;
|
|
15520
|
+
delete record.signature;
|
|
15521
|
+
return JSON.stringify(sortJsonKeys(record));
|
|
15522
|
+
}
|
|
15523
|
+
function getContextFields(value) {
|
|
15524
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
15525
|
+
const context = value["@context"];
|
|
15526
|
+
return JSON.stringify(sortJsonKeys(context ?? null));
|
|
15527
|
+
}
|
|
15528
|
+
function getProofEntries(value) {
|
|
15529
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return [];
|
|
15530
|
+
const proof = value.proof;
|
|
15531
|
+
if (proof == null) return [];
|
|
15532
|
+
return Array.isArray(proof) ? proof : [proof];
|
|
15533
|
+
}
|
|
15534
|
+
function normalizeProofEntry(proof) {
|
|
15535
|
+
const stripped = stripContexts(proof);
|
|
15536
|
+
if (typeof stripped !== "object" || stripped == null || Array.isArray(stripped)) return stripped;
|
|
15537
|
+
const record = { ...stripped };
|
|
15538
|
+
if (typeof record.created === "string") try {
|
|
15539
|
+
record.created = Temporal$2.Instant.from(record.created).toString();
|
|
15540
|
+
} catch {}
|
|
15541
|
+
return record;
|
|
15542
|
+
}
|
|
15543
|
+
function getProofEntryFields(proof) {
|
|
15544
|
+
return JSON.stringify(sortJsonKeys(normalizeProofEntry(proof)));
|
|
15545
|
+
}
|
|
15546
|
+
function getProofFields(value) {
|
|
15547
|
+
return JSON.stringify(getProofEntries(value).map(getProofEntryFields).sort());
|
|
15548
|
+
}
|
|
15549
|
+
async function getUncapturedProofs(activity, capturedJsonLd, contextLoader) {
|
|
15550
|
+
const capturedProofs = new Set(getProofEntries(capturedJsonLd).map(getProofEntryFields));
|
|
15551
|
+
const retainedProofs = [];
|
|
15552
|
+
for await (const proof of activity.getProofs({ contextLoader })) {
|
|
15553
|
+
const proofJsonLd = await proof.toJsonLd({
|
|
15554
|
+
format: "compact",
|
|
15555
|
+
contextLoader
|
|
15556
|
+
});
|
|
15557
|
+
if (!capturedProofs.has(getProofEntryFields(proofJsonLd))) retainedProofs.push(proof);
|
|
15558
|
+
}
|
|
15559
|
+
return retainedProofs;
|
|
15560
|
+
}
|
|
15561
|
+
function stripContexts(value) {
|
|
15562
|
+
if (Array.isArray(value)) return value.map(stripContexts);
|
|
15563
|
+
if (typeof value !== "object" || value == null) return value;
|
|
15564
|
+
const record = { ...value };
|
|
15565
|
+
delete record["@context"];
|
|
15566
|
+
delete record.signature;
|
|
15567
|
+
for (const key of globalThis.Object.keys(record)) record[key] = stripContexts(record[key]);
|
|
15568
|
+
return record;
|
|
15569
|
+
}
|
|
15570
|
+
function sortJsonKeys(value) {
|
|
15571
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
15572
|
+
if (typeof value !== "object" || value == null) return value;
|
|
15573
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
15574
|
+
}
|
|
15246
15575
|
function notAcceptable(_request) {
|
|
15247
15576
|
return new Response("Not Acceptable", {
|
|
15248
15577
|
status: 406,
|