@fedify/fedify 2.4.0-dev.2157 → 2.4.0-dev.2164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/{builder-CLaS4-yA.mjs → builder-BqRmnx7p.mjs} +2 -2
  2. package/dist/compat/mod.d.cts +1 -1
  3. package/dist/compat/mod.d.ts +1 -1
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{compound-proof-D7K94KPz.mjs → compound-proof-CxDBdtNz.mjs} +2 -2
  6. package/dist/{context-exYu7gDU.d.ts → context-BykNUf04.d.ts} +120 -3
  7. package/dist/{context-BMggDR-l.d.cts → context-L0Fnib9j.d.cts} +120 -3
  8. package/dist/{deno-D1gcWWqB.mjs → deno-CizGaYeG.mjs} +1 -1
  9. package/dist/{docloader-BMqr3hji.mjs → docloader-BBFAItNB.mjs} +2 -2
  10. package/dist/federation/builder.test.mjs +1 -1
  11. package/dist/federation/compound-fanout.test.mjs +3 -3
  12. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  13. package/dist/federation/handler.test.mjs +5 -5
  14. package/dist/federation/hashlink-media.test.mjs +2 -2
  15. package/dist/federation/idempotency.test.mjs +2 -2
  16. package/dist/federation/keycache.test.mjs +67 -1
  17. package/dist/federation/metrics.test.mjs +1 -1
  18. package/dist/federation/middleware.test.mjs +7 -7
  19. package/dist/federation/mod.cjs +1 -1
  20. package/dist/federation/mod.d.cts +3 -3
  21. package/dist/federation/mod.d.ts +3 -3
  22. package/dist/federation/mod.js +1 -1
  23. package/dist/federation/outgoing-proof.test.mjs +5 -5
  24. package/dist/federation/portable-actor.test.mjs +3 -3
  25. package/dist/federation/portable-chain.test.mjs +3 -3
  26. package/dist/federation/portable-collection.test.mjs +4 -4
  27. package/dist/federation/portable-gateway-keys.test.mjs +180 -6
  28. package/dist/federation/portable-inbox.test.mjs +4 -4
  29. package/dist/federation/portable-parse-uri.test.d.mts +2 -0
  30. package/dist/federation/portable-parse-uri.test.mjs +348 -0
  31. package/dist/federation/portable.test.mjs +3 -3
  32. package/dist/federation/send.test.mjs +3 -3
  33. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  34. package/dist/federation/tasks/tasks.test.mjs +2 -2
  35. package/dist/federation/temporal.test.mjs +1 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{federation-2e8XrN7q.cjs → federation-DFCnp94y.cjs} +103 -29
  38. package/dist/{http-Dgtt45-K.js → http-Baovr6xq.js} +161 -7
  39. package/dist/{http-CjezPjFX.d.cts → http-Cok5-vIC.d.ts} +6 -1
  40. package/dist/{http-C-x_OLSp.d.ts → http-DC1cqAQ2.d.cts} +6 -1
  41. package/dist/{http-CGcLv8rh.mjs → http-DRH0n8TD.mjs} +7 -5
  42. package/dist/{http-BObQoB0j.cjs → http-R4g1McwE.cjs} +185 -11
  43. package/dist/{key-CPM4r6tP.mjs → key-D5awqp7u.mjs} +58 -7
  44. package/dist/key-owner-evidence-Bo3yaeL5.mjs +108 -0
  45. package/dist/{keycache-BInaECGj.mjs → keycache-PiOM9pM0.mjs} +46 -21
  46. package/dist/{kv-cache-bdPqTR1k.mjs → kv-cache-C7RWL7hz.mjs} +1 -1
  47. package/dist/{kv-cache-BweyIZTb.js → kv-cache-CZiBDLPi.js} +1 -1
  48. package/dist/{kv-cache-D2fnB8qu.cjs → kv-cache-Ct-KWRta.cjs} +1 -1
  49. package/dist/{ld-lU_ZqzsQ.mjs → ld-CyliEU48.mjs} +3 -3
  50. package/dist/{metrics-B41pRPfd.mjs → metrics-CFBEehTc.mjs} +1 -1
  51. package/dist/{middleware-xdukzV3x.mjs → middleware-B99JjvFn.mjs} +70 -20
  52. package/dist/{middleware-TrCVULgs.mjs → middleware-BmqEWsWP.mjs} +1 -1
  53. package/dist/{middleware-BYWyYjmX.js → middleware-CdpTFsa2.js} +103 -29
  54. package/dist/{mod-Bz9tFXI2.d.ts → mod--jv6vyrP.d.ts} +1 -1
  55. package/dist/{mod-DaiBrWDW.d.ts → mod-B5z_q9TH.d.ts} +1 -1
  56. package/dist/{mod-Mt4aO3DX.d.cts → mod-BA_F2x53.d.cts} +1 -1
  57. package/dist/{mod-Decmur1U.d.cts → mod-BLOXGs6m.d.cts} +1 -1
  58. package/dist/{mod-S--JxYjo.d.cts → mod-CPPqkyV_.d.cts} +1 -1
  59. package/dist/{mod-CnGtADvO.d.ts → mod-DK0y9fd-.d.ts} +1 -1
  60. package/dist/mod.cjs +4 -4
  61. package/dist/mod.d.cts +7 -7
  62. package/dist/mod.d.ts +7 -7
  63. package/dist/mod.js +4 -4
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/{owner-D63yPo_i.mjs → owner-DKdtsrEq.mjs} +18 -3
  66. package/dist/{portable-collection-_lZg-osX.mjs → portable-collection-Cb5cdPIU.mjs} +2 -2
  67. package/dist/{portable-collection-B8ojoQ50.cjs → portable-collection-UajqDrSL.cjs} +15 -1
  68. package/dist/{portable-collection-C3xEzYri.js → portable-collection-uv4CuQXm.js} +15 -1
  69. package/dist/{portable-key-D8uWZF7b.mjs → portable-key-Bv1RdQ0n.mjs} +2 -1
  70. package/dist/{proof-C2YwD8a_.mjs → proof-CRTPWbVh.mjs} +4 -4
  71. package/dist/{send-D9SGhxTB.mjs → send-2dULlZc8.mjs} +3 -3
  72. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  73. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  74. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  75. package/dist/sig/compound-proof.test.mjs +2 -2
  76. package/dist/sig/http.test.mjs +2 -2
  77. package/dist/sig/key-owner-evidence.test.d.mts +2 -0
  78. package/dist/sig/key-owner-evidence.test.mjs +100 -0
  79. package/dist/sig/key.test.mjs +1 -1
  80. package/dist/sig/ld.test.mjs +2 -2
  81. package/dist/sig/mod.cjs +2 -2
  82. package/dist/sig/mod.d.cts +2 -2
  83. package/dist/sig/mod.d.ts +2 -2
  84. package/dist/sig/mod.js +2 -2
  85. package/dist/sig/owner.test.mjs +1 -1
  86. package/dist/sig/portable-collection.test.mjs +1 -1
  87. package/dist/sig/portable-key.test.mjs +6 -6
  88. package/dist/sig/proof.test.mjs +3 -3
  89. package/dist/{temporal-q6FSekcN.mjs → temporal-Dhsk6aUT.mjs} +1 -1
  90. package/dist/testing/kv.test.mjs +1 -1
  91. package/dist/testing/mod.d.mts +118 -1
  92. package/dist/utils/docloader.test.mjs +2 -2
  93. package/dist/utils/kv-cache.test.mjs +1 -1
  94. package/dist/utils/mod.cjs +1 -1
  95. package/dist/utils/mod.d.cts +1 -1
  96. package/dist/utils/mod.d.ts +1 -1
  97. package/dist/utils/mod.js +1 -1
  98. package/package.json +6 -6
@@ -14,7 +14,7 @@ import serialize from "json-canon";
14
14
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
15
15
  //#region deno.json
16
16
  var name = "@fedify/fedify";
17
- var version = "2.4.0-dev.2157+b76e5888";
17
+ var version = "2.4.0-dev.2164+db2b8571";
18
18
  //#endregion
19
19
  //#region src/sig/portable-key-id.ts
20
20
  const COMPATIBLE_KEY_ID_PATH_PATTERN = /^\/\.well-known\/apgateway\/did(?::|%3A)/i;
@@ -1181,6 +1181,108 @@ function getDurationMs(start) {
1181
1181
  return Math.max(0, performance.now() - start);
1182
1182
  }
1183
1183
  //#endregion
1184
+ //#region src/sig/key-owner-evidence.ts
1185
+ /**
1186
+ * How long a key of an [FEP-ef61] portable actor is trusted after its actor's
1187
+ * signed document vouched for it, however long the proof of the document is
1188
+ * valid. The actor can drop the key or the gateway from its document at any
1189
+ * time, so the key is looked up again at least this often.
1190
+ *
1191
+ * [FEP-ef61]: https://w3id.org/fep/ef61
1192
+ * @internal
1193
+ */
1194
+ const MAX_PORTABLE_KEY_TTL = Temporal.Duration.from({ hours: 1 });
1195
+ const candidates = /* @__PURE__ */ new WeakMap();
1196
+ const verified = /* @__PURE__ */ new WeakMap();
1197
+ /**
1198
+ * Attaches to a key that was just resolved the evidence of the portable actor
1199
+ * that owns it. The evidence is not used until the key verifies
1200
+ * a signature; see {@link promoteKeyOwnerEvidence}.
1201
+ *
1202
+ * Nothing is attached unless the document, the key's owner, and the actor
1203
+ * the key ID belongs to agree on the actor's canonical portable ID.
1204
+ * @param key The key, whose owner the document vouched for.
1205
+ * @param document The expanded root node of the actor's verified document.
1206
+ * @param expires When the evidence must not be used anymore.
1207
+ * @returns Whether the evidence was attached.
1208
+ * @internal
1209
+ */
1210
+ function attachKeyOwnerEvidence(key, document, expires) {
1211
+ if (!(key instanceof CryptographicKey) || key.id == null || key.ownerId == null || key.publicKey == null || document == null || typeof document !== "object" || Array.isArray(document)) return false;
1212
+ const rawId = document["@id"];
1213
+ if (typeof rawId !== "string") return false;
1214
+ const keyBase = new URL(key.id.href);
1215
+ keyBase.hash = "";
1216
+ const ownerId = getCanonicalPortableId(key.ownerId);
1217
+ if (ownerId == null || getRawCanonicalPortableId(rawId) !== ownerId || getCanonicalPortableId(keyBase) !== ownerId) return false;
1218
+ candidates.set(key, {
1219
+ keyId: key.id.href,
1220
+ keyOwner: key.ownerId.href,
1221
+ publicKey: key.publicKey,
1222
+ ownerId,
1223
+ document: structuredClone(document),
1224
+ expires
1225
+ });
1226
+ return true;
1227
+ }
1228
+ /**
1229
+ * Makes the evidence attached to a key usable, as the key has just verified
1230
+ * an HTTP Signature. Nothing happens if the key has no evidence.
1231
+ * @param key The key that verified a signature.
1232
+ * @internal
1233
+ */
1234
+ function promoteKeyOwnerEvidence(key) {
1235
+ const evidence = candidates.get(key);
1236
+ if (evidence == null) return;
1237
+ candidates.delete(key);
1238
+ verified.set(key, evidence);
1239
+ }
1240
+ /**
1241
+ * Gets the evidence of the portable actor that owns a key HTTP Signature
1242
+ * verification returned.
1243
+ * @param key The key.
1244
+ * @param now The current time.
1245
+ * @returns The evidence, or `undefined` if the key was not returned by HTTP
1246
+ * Signature verification, if it has no evidence, if the evidence
1247
+ * expired, or if the key has been changed since.
1248
+ * @internal
1249
+ */
1250
+ function getVerifiedKeyOwnerEvidence(key, now = Temporal.Now.instant()) {
1251
+ const evidence = verified.get(key);
1252
+ if (evidence == null) return void 0;
1253
+ if (Temporal.Instant.compare(now, evidence.expires) >= 0) {
1254
+ verified.delete(key);
1255
+ return;
1256
+ }
1257
+ if (key.id?.href !== evidence.keyId || key.ownerId?.href !== evidence.keyOwner || key.publicKey !== evidence.publicKey) return;
1258
+ return evidence;
1259
+ }
1260
+ /**
1261
+ * Parses the actor from the evidence, i.e., from the expansion of its
1262
+ * document whose proof was verified. Every call returns a new object.
1263
+ * @param evidence The evidence.
1264
+ * @param options Options for parsing the document.
1265
+ * @returns The actor, or `null` if the document is not the actor that
1266
+ * the evidence is about, or the evidence expired meanwhile.
1267
+ * @internal
1268
+ */
1269
+ async function parseKeyOwnerEvidence(evidence, options = {}) {
1270
+ const refuse = (url) => Promise.reject(/* @__PURE__ */ new Error(`Refusing to fetch ${url}.`));
1271
+ let actor;
1272
+ try {
1273
+ actor = await Object$1.fromJsonLd(structuredClone(evidence.document), {
1274
+ documentLoader: refuse,
1275
+ contextLoader: options.contextLoader,
1276
+ tracerProvider: options.tracerProvider
1277
+ });
1278
+ } catch (error) {
1279
+ if (!(error instanceof TypeError)) throw error;
1280
+ return null;
1281
+ }
1282
+ if (!isPortableActorDocument(actor) || getCanonicalPortableId(actor.id) !== evidence.ownerId || Temporal.Instant.compare(Temporal.Now.instant(), evidence.expires) >= 0) return null;
1283
+ return actor;
1284
+ }
1285
+ //#endregion
1184
1286
  //#region src/sig/key.ts
1185
1287
  /**
1186
1288
  * Checks if the given key is valid and supported. No-op if the key is valid,
@@ -1403,6 +1505,7 @@ function bypassKeyCacheReads(keyCache) {
1403
1505
  const scoped = cache.compatibleKeyScope(scope);
1404
1506
  return {
1405
1507
  get: () => Promise.resolve(void 0),
1508
+ getEntry: () => Promise.resolve(void 0),
1406
1509
  set: async (keyId, key, options) => await scoped.set(keyId, key, options),
1407
1510
  delete: async (keyId) => await scoped.delete(keyId)
1408
1511
  };
@@ -1570,6 +1673,49 @@ function checkCachedKeyHit(cachedKey, keyId, cls, logger) {
1570
1673
  }
1571
1674
  return null;
1572
1675
  }
1676
+ /**
1677
+ * Looks up a key at a compatible identifier, or at an `ap:` or `ap+ef61:`
1678
+ * URI, in the cache namespace of a purpose, like {@link getCachedFetchKey}.
1679
+ * A key that the verified document of its portable actor was cached with
1680
+ * gets the actor's evidence attached from the same entry; see
1681
+ * {@link attachKeyOwnerEvidence}.
1682
+ */
1683
+ async function getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger) {
1684
+ if (scopedCache?.getEntry == null) return await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
1685
+ const entry = await scopedCache.getEntry(cacheKey);
1686
+ if (entry === void 0) return null;
1687
+ if (entry === null) {
1688
+ logger.debug("Entry {keyId} found in cache, but it is unavailable.", { keyId });
1689
+ return {
1690
+ key: null,
1691
+ cached: true
1692
+ };
1693
+ }
1694
+ const hit = checkCachedKeyHit(entry.key, keyId, cls, logger);
1695
+ if (hit?.key instanceof CryptographicKey && entry.owner != null) attachKeyOwnerEvidence(hit.key, entry.owner, entry.expires);
1696
+ return hit;
1697
+ }
1698
+ /**
1699
+ * Attaches the evidence of the portable actor whose document has just
1700
+ * vouched for a key to the key. The evidence expires with the cache entry
1701
+ * of the key, so that it is never trusted longer than the key is cached.
1702
+ * Without a cache, it expires with the proof of the document, but no later
1703
+ * than {@link MAX_PORTABLE_KEY_TTL}, as a cache entry would.
1704
+ * @param resolution The resolution of the key.
1705
+ * @param scopedCache The cache namespace the key was stored in, if any.
1706
+ * @param cached When the cache entry expires, if the cache stored one.
1707
+ */
1708
+ function attachResolvedKeyOwnerEvidence(resolution, scopedCache, cached) {
1709
+ let expires;
1710
+ if (scopedCache != null) {
1711
+ if (cached == null) return;
1712
+ expires = cached;
1713
+ } else {
1714
+ expires = Temporal.Now.instant().add(MAX_PORTABLE_KEY_TTL);
1715
+ if (resolution.expires != null && Temporal.Instant.compare(resolution.expires, expires) < 0) expires = resolution.expires;
1716
+ }
1717
+ attachKeyOwnerEvidence(resolution.key, resolution.document, expires);
1718
+ }
1573
1719
  async function clearFetchErrorMetadata(keyId, keyCache) {
1574
1720
  await keyCache?.setFetchError?.(keyId, null);
1575
1721
  }
@@ -1694,7 +1840,10 @@ async function resolveFetchedKey(document, cacheKey, documentUrl, keyId, cls, {
1694
1840
  cached: false
1695
1841
  };
1696
1842
  }
1697
- await scopedCache?.set(cacheKey, resolution.key, { expires: resolution.expires });
1843
+ attachResolvedKeyOwnerEvidence(resolution, scopedCache, await scopedCache?.set(cacheKey, resolution.key, {
1844
+ expires: resolution.expires,
1845
+ owner: resolution.document
1846
+ }));
1698
1847
  return {
1699
1848
  key: resolution.key,
1700
1849
  cached: false
@@ -1915,7 +2064,7 @@ async function fetchCompatibleKey(cacheKey, cls, options, onCachedUnavailable, o
1915
2064
  const keyId = cacheKey.href;
1916
2065
  const sharedCache = options.keyCache;
1917
2066
  const scopedCache = sharedCache?.compatibleKeyScope?.(getCompatibleKeyScope(cls, options));
1918
- const cached = await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
2067
+ const cached = await getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger);
1919
2068
  if (cached != null) return {
1920
2069
  result: cached,
1921
2070
  outcome: { result: "hit" }
@@ -1979,7 +2128,7 @@ async function fetchPortableActorKey(cacheKey, cls, options, onCachedUnavailable
1979
2128
  }
1980
2129
  const sharedCache = options.keyCache;
1981
2130
  const scopedCache = sharedCache?.compatibleKeyScope?.("httpSignature");
1982
- const cached = await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
2131
+ const cached = await getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger);
1983
2132
  if (cached != null) return {
1984
2133
  result: cached,
1985
2134
  outcome: { result: "hit" }
@@ -1994,7 +2143,10 @@ async function fetchPortableActorKey(cacheKey, cls, options, onCachedUnavailable
1994
2143
  logger.debug("Resolving key {keyId} to verify signature...", { keyId });
1995
2144
  const resolution = await resolvers.actorKey(cacheKey);
1996
2145
  if (resolution.type === "verified") {
1997
- await scopedCache?.set(cacheKey, resolution.key, { expires: resolution.expires });
2146
+ attachResolvedKeyOwnerEvidence(resolution, scopedCache, await scopedCache?.set(cacheKey, resolution.key, {
2147
+ expires: resolution.expires,
2148
+ owner: resolution.document
2149
+ }));
1998
2150
  return {
1999
2151
  result: {
2000
2152
  key: resolution.key,
@@ -4334,6 +4486,7 @@ async function verifyPortableKeyDocument(document, actor, keyId, isGatewayKey, o
4334
4486
  type: "verified",
4335
4487
  actor,
4336
4488
  key,
4489
+ document: root,
4337
4490
  ...expires == null ? {} : { expires }
4338
4491
  };
4339
4492
  }
@@ -5010,7 +5163,8 @@ async function verifyRequestDetailed(request, options = {}) {
5010
5163
  if (spec === "rfc9421") result = await verifyRequestRfc9421(request, span, metricsContext, options);
5011
5164
  else result = await verifyRequestDraft(request, span, metricsContext, options);
5012
5165
  recordVerificationResult(span, result);
5013
- if (!result.verified) span.setStatus({ code: SpanStatusCode.ERROR });
5166
+ if (result.verified) promoteKeyOwnerEvidence(result.key);
5167
+ else span.setStatus({ code: SpanStatusCode.ERROR });
5014
5168
  return result;
5015
5169
  } catch (error) {
5016
5170
  threw = true;
@@ -5721,4 +5875,4 @@ function timingSafeEqual(a, b) {
5721
5875
  return result === 0;
5722
5876
  }
5723
5877
  //#endregion
5724
- export { recordCollectionPageItems as $, hasSignatureLike as A, fetchKey as B, assertSafeJsonLd as C, isSamePublicKey as Ct, detachSignature as D, createSignature as E, verifyJsonLd as F, verifyKeyOwnership as G, generateCryptoKeyPair as H, verifySignature as I, getRemoteHost as J, getDurationMs as K, wrapContextLoaderForJsonLd as L, isInvalidUrlTypeError as M, signJsonLd as N, getNormalizationContextLoader as O, verifyCompactJsonLd as P, recordCollectionDispatchDuration as Q, exportJwk as R, InvalidContextReferenceError as S, isPortableUri as St, compactJsonLd as T, version as Tt, importJwk as U, fetchKeyDetailed as V, validateCryptoKey as W, isAbortError$1 as X, instrumentDocumentLoader as Y, recordCircuitBreakerStateChange as Z, verifyPortableObjectProof as _, getRawCanonicalPortableId as _t, signRequest as a, recordOutboxActivity as at, verifyProof as b, isPortableId as bt, fetchPortableGatewayKey as c, registerQueueDepthGauge as ct, classifyFep2277CoreType as d, fulfillAcceptSignature as dt, recordCollectionRequest as et, createProof as f, parseAcceptSignature as ft, verifyObject as g, getPortableDid as gt, verifyMapLocalProof as h, getGatewayKeyBase as ht, selectRequestSignature as i, recordInboxActivity as it, isClearlyMalformedContextReference as j, hasSignature as k, resolvePortableActorKey as l, preloadedOnlyDocumentLoader as lt, signObject as m, getCanonicalPortableId as mt, listRequestSignatures as n, recordDocumentCache as nt, verifyRequest as o, recordOutboxEnqueue as ot, hasProofLike as p, validateAcceptSignature as pt, getFederationMetrics as q, parseRfc9421SignatureInput as r, recordFanoutRecipients as rt, verifyRequestDetailed as s, recordWebFingerHandle as st, doubleKnock as t, recordCollectionTotalItems as tt, InvalidPortableObjectIdError as u, formatAcceptSignature as ut, verifyPortableObjectProofPolicy as v, hasPortableActor as vt, attachSignature as w, name as wt, normalizeOutgoingActivityJsonLd as x, isPortableKeyId as xt, verifyPortableObjectProofWithRoot as y, isCompatibleKeyId as yt, fetchActorDocument as z };
5878
+ export { isAbortError$1 as $, hasSignatureLike as A, fetchKey as B, assertSafeJsonLd as C, isPortableId as Ct, detachSignature as D, name as Dt, createSignature as E, isSamePublicKey as Et, verifyJsonLd as F, verifyKeyOwnership as G, generateCryptoKeyPair as H, verifySignature as I, parseKeyOwnerEvidence as J, MAX_PORTABLE_KEY_TTL as K, wrapContextLoaderForJsonLd as L, isInvalidUrlTypeError as M, signJsonLd as N, getNormalizationContextLoader as O, version as Ot, verifyCompactJsonLd as P, instrumentDocumentLoader as Q, exportJwk as R, InvalidContextReferenceError as S, isCompatibleKeyId as St, compactJsonLd as T, isPortableUri as Tt, importJwk as U, fetchKeyDetailed as V, validateCryptoKey as W, getFederationMetrics as X, getDurationMs as Y, getRemoteHost as Z, verifyPortableObjectProof as _, getCanonicalPortableId as _t, signRequest as a, recordDocumentCache as at, verifyProof as b, getRawCanonicalPortableId as bt, fetchPortableGatewayKey as c, recordOutboxActivity as ct, classifyFep2277CoreType as d, registerQueueDepthGauge as dt, recordCircuitBreakerStateChange as et, createProof as f, preloadedOnlyDocumentLoader as ft, verifyObject as g, validateAcceptSignature as gt, verifyMapLocalProof as h, parseAcceptSignature as ht, selectRequestSignature as i, recordCollectionTotalItems as it, isClearlyMalformedContextReference as j, hasSignature as k, resolvePortableActorKey as l, recordOutboxEnqueue as lt, signObject as m, fulfillAcceptSignature as mt, listRequestSignatures as n, recordCollectionPageItems as nt, verifyRequest as o, recordFanoutRecipients as ot, hasProofLike as p, formatAcceptSignature as pt, getVerifiedKeyOwnerEvidence as q, parseRfc9421SignatureInput as r, recordCollectionRequest as rt, verifyRequestDetailed as s, recordInboxActivity as st, doubleKnock as t, recordCollectionDispatchDuration as tt, InvalidPortableObjectIdError as u, recordWebFingerHandle as ut, verifyPortableObjectProofPolicy as v, getGatewayKeyBase as vt, attachSignature as w, isPortableKeyId as wt, normalizeOutgoingActivityJsonLd as x, hasPortableActor as xt, verifyPortableObjectProofWithRoot as y, getPortableDid as yt, fetchActorDocument as z };
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { Actor, CryptographicKey, Multikey } from "@fedify/vocab";
3
- import { DocumentLoader } from "@fedify/vocab-runtime";
4
3
  import { MeterProvider, TracerProvider } from "@opentelemetry/api";
4
+ import { DocumentLoader } from "@fedify/vocab-runtime";
5
5
 
6
6
  //#region src/sig/portable-key.d.ts
7
7
  /**
@@ -24,6 +24,11 @@ type PortableGatewayKeyResolution = {
24
24
  publicKey: CryptoKey;
25
25
  };
26
26
  /**
27
+ * The expanded root node of the actor's document whose proof was
28
+ * verified, from which {@link actor} was parsed.
29
+ */
30
+ readonly document: Record<string, unknown>;
31
+ /**
27
32
  * When the proof of the actor's document expires, if it does. The
28
33
  * document does not vouch for the key after that.
29
34
  */
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { Actor, CryptographicKey, Multikey } from "@fedify/vocab";
3
- import { MeterProvider, TracerProvider } from "@opentelemetry/api";
4
3
  import { DocumentLoader } from "@fedify/vocab-runtime";
4
+ import { MeterProvider, TracerProvider } from "@opentelemetry/api";
5
5
 
6
6
  //#region src/sig/portable-key.d.ts
7
7
  /**
@@ -24,6 +24,11 @@ type PortableGatewayKeyResolution = {
24
24
  publicKey: CryptoKey;
25
25
  };
26
26
  /**
27
+ * The expanded root node of the actor's document whose proof was
28
+ * verified, from which {@link actor} was parsed.
29
+ */
30
+ readonly document: Record<string, unknown>;
31
+ /**
27
32
  * When the proof of the actor's document expires, if it does. The
28
33
  * document does not vouch for the key after that.
29
34
  */
@@ -1,12 +1,13 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-D1gcWWqB.mjs";
5
- import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-B41pRPfd.mjs";
4
+ import { n as version, t as name } from "./deno-CizGaYeG.mjs";
5
+ import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-CFBEehTc.mjs";
6
6
  import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-CPVqki78.mjs";
7
7
  import { f as parseKeyIdString } from "./portable-key-id-Bg259c4Z.mjs";
8
- import { a as fetchKeyDetailed, c as validateCryptoKey, t as bypassKeyCacheReads } from "./key-CPM4r6tP.mjs";
9
- import { n as resolvePortableActorKey, r as verifyPortableGatewayKeyDocument } from "./portable-key-D8uWZF7b.mjs";
8
+ import { a as promoteKeyOwnerEvidence } from "./key-owner-evidence-Bo3yaeL5.mjs";
9
+ import { a as fetchKeyDetailed, c as validateCryptoKey, t as bypassKeyCacheReads } from "./key-D5awqp7u.mjs";
10
+ import { n as resolvePortableActorKey, r as verifyPortableGatewayKeyDocument } from "./portable-key-Bv1RdQ0n.mjs";
10
11
  import { getLogger } from "@logtape/logtape";
11
12
  import { CryptographicKey } from "@fedify/vocab";
12
13
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -474,7 +475,8 @@ async function verifyRequestDetailed(request, options = {}) {
474
475
  if (spec === "rfc9421") result = await verifyRequestRfc9421(request, span, metricsContext, options);
475
476
  else result = await verifyRequestDraft(request, span, metricsContext, options);
476
477
  recordVerificationResult(span, result);
477
- if (!result.verified) span.setStatus({ code: SpanStatusCode.ERROR });
478
+ if (result.verified) promoteKeyOwnerEvidence(result.key);
479
+ else span.setStatus({ code: SpanStatusCode.ERROR });
478
480
  return result;
479
481
  } catch (error) {
480
482
  threw = true;
@@ -16,7 +16,7 @@ json_canon = require_rolldown_runtime.__toESM(json_canon, 1);
16
16
  let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
17
17
  //#region deno.json
18
18
  var name = "@fedify/fedify";
19
- var version = "2.4.0-dev.2157+b76e5888";
19
+ var version = "2.4.0-dev.2164+db2b8571";
20
20
  //#endregion
21
21
  //#region src/sig/portable-key-id.ts
22
22
  const COMPATIBLE_KEY_ID_PATH_PATTERN = /^\/\.well-known\/apgateway\/did(?::|%3A)/i;
@@ -3760,7 +3760,7 @@ const Now = /*@__PURE__*/ Object.defineProperties({}, {
3760
3760
  }
3761
3761
  })
3762
3762
  });
3763
- const Temporal$3 = /*@__PURE__*/ Object.defineProperties({}, {
3763
+ const Temporal$5 = /*@__PURE__*/ Object.defineProperties({}, {
3764
3764
  ...createStringTagDescriptors("Temporal"),
3765
3765
  ...createPropDescriptors({
3766
3766
  PlainYearMonth,
@@ -3776,7 +3776,7 @@ const Temporal$3 = /*@__PURE__*/ Object.defineProperties({}, {
3776
3776
  });
3777
3777
  //#endregion
3778
3778
  //#region ../../node_modules/.pnpm/temporal-polyfill@1.0.1/node_modules/temporal-polyfill/index.js
3779
- const Temporal$2 = NativeTemporal || Temporal$3;
3779
+ const Temporal$4 = NativeTemporal || Temporal$5;
3780
3780
  NativeTemporal && Date.prototype.toTemporalInstant;
3781
3781
  //#endregion
3782
3782
  //#region src/sig/accept.ts
@@ -4747,7 +4747,111 @@ function getDurationMs(start) {
4747
4747
  return Math.max(0, performance.now() - start);
4748
4748
  }
4749
4749
  //#endregion
4750
+ //#region src/sig/key-owner-evidence.ts
4751
+ const Temporal$3 = Temporal$4;
4752
+ /**
4753
+ * How long a key of an [FEP-ef61] portable actor is trusted after its actor's
4754
+ * signed document vouched for it, however long the proof of the document is
4755
+ * valid. The actor can drop the key or the gateway from its document at any
4756
+ * time, so the key is looked up again at least this often.
4757
+ *
4758
+ * [FEP-ef61]: https://w3id.org/fep/ef61
4759
+ * @internal
4760
+ */
4761
+ const MAX_PORTABLE_KEY_TTL = Temporal$3.Duration.from({ hours: 1 });
4762
+ const candidates = /* @__PURE__ */ new WeakMap();
4763
+ const verified = /* @__PURE__ */ new WeakMap();
4764
+ /**
4765
+ * Attaches to a key that was just resolved the evidence of the portable actor
4766
+ * that owns it. The evidence is not used until the key verifies
4767
+ * a signature; see {@link promoteKeyOwnerEvidence}.
4768
+ *
4769
+ * Nothing is attached unless the document, the key's owner, and the actor
4770
+ * the key ID belongs to agree on the actor's canonical portable ID.
4771
+ * @param key The key, whose owner the document vouched for.
4772
+ * @param document The expanded root node of the actor's verified document.
4773
+ * @param expires When the evidence must not be used anymore.
4774
+ * @returns Whether the evidence was attached.
4775
+ * @internal
4776
+ */
4777
+ function attachKeyOwnerEvidence(key, document, expires) {
4778
+ if (!(key instanceof _fedify_vocab.CryptographicKey) || key.id == null || key.ownerId == null || key.publicKey == null || document == null || typeof document !== "object" || Array.isArray(document)) return false;
4779
+ const rawId = document["@id"];
4780
+ if (typeof rawId !== "string") return false;
4781
+ const keyBase = new URL(key.id.href);
4782
+ keyBase.hash = "";
4783
+ const ownerId = getCanonicalPortableId(key.ownerId);
4784
+ if (ownerId == null || getRawCanonicalPortableId(rawId) !== ownerId || getCanonicalPortableId(keyBase) !== ownerId) return false;
4785
+ candidates.set(key, {
4786
+ keyId: key.id.href,
4787
+ keyOwner: key.ownerId.href,
4788
+ publicKey: key.publicKey,
4789
+ ownerId,
4790
+ document: structuredClone(document),
4791
+ expires
4792
+ });
4793
+ return true;
4794
+ }
4795
+ /**
4796
+ * Makes the evidence attached to a key usable, as the key has just verified
4797
+ * an HTTP Signature. Nothing happens if the key has no evidence.
4798
+ * @param key The key that verified a signature.
4799
+ * @internal
4800
+ */
4801
+ function promoteKeyOwnerEvidence(key) {
4802
+ const evidence = candidates.get(key);
4803
+ if (evidence == null) return;
4804
+ candidates.delete(key);
4805
+ verified.set(key, evidence);
4806
+ }
4807
+ /**
4808
+ * Gets the evidence of the portable actor that owns a key HTTP Signature
4809
+ * verification returned.
4810
+ * @param key The key.
4811
+ * @param now The current time.
4812
+ * @returns The evidence, or `undefined` if the key was not returned by HTTP
4813
+ * Signature verification, if it has no evidence, if the evidence
4814
+ * expired, or if the key has been changed since.
4815
+ * @internal
4816
+ */
4817
+ function getVerifiedKeyOwnerEvidence(key, now = Temporal$3.Now.instant()) {
4818
+ const evidence = verified.get(key);
4819
+ if (evidence == null) return void 0;
4820
+ if (Temporal$3.Instant.compare(now, evidence.expires) >= 0) {
4821
+ verified.delete(key);
4822
+ return;
4823
+ }
4824
+ if (key.id?.href !== evidence.keyId || key.ownerId?.href !== evidence.keyOwner || key.publicKey !== evidence.publicKey) return;
4825
+ return evidence;
4826
+ }
4827
+ /**
4828
+ * Parses the actor from the evidence, i.e., from the expansion of its
4829
+ * document whose proof was verified. Every call returns a new object.
4830
+ * @param evidence The evidence.
4831
+ * @param options Options for parsing the document.
4832
+ * @returns The actor, or `null` if the document is not the actor that
4833
+ * the evidence is about, or the evidence expired meanwhile.
4834
+ * @internal
4835
+ */
4836
+ async function parseKeyOwnerEvidence(evidence, options = {}) {
4837
+ const refuse = (url) => Promise.reject(/* @__PURE__ */ new Error(`Refusing to fetch ${url}.`));
4838
+ let actor;
4839
+ try {
4840
+ actor = await _fedify_vocab.Object.fromJsonLd(structuredClone(evidence.document), {
4841
+ documentLoader: refuse,
4842
+ contextLoader: options.contextLoader,
4843
+ tracerProvider: options.tracerProvider
4844
+ });
4845
+ } catch (error) {
4846
+ if (!(error instanceof TypeError)) throw error;
4847
+ return null;
4848
+ }
4849
+ if (!isPortableActorDocument(actor) || getCanonicalPortableId(actor.id) !== evidence.ownerId || Temporal$3.Instant.compare(Temporal$3.Now.instant(), evidence.expires) >= 0) return null;
4850
+ return actor;
4851
+ }
4852
+ //#endregion
4750
4853
  //#region src/sig/key.ts
4854
+ const Temporal$2 = Temporal$4;
4751
4855
  /**
4752
4856
  * Checks if the given key is valid and supported. No-op if the key is valid,
4753
4857
  * otherwise throws an error.
@@ -4969,6 +5073,7 @@ function bypassKeyCacheReads(keyCache) {
4969
5073
  const scoped = cache.compatibleKeyScope(scope);
4970
5074
  return {
4971
5075
  get: () => Promise.resolve(void 0),
5076
+ getEntry: () => Promise.resolve(void 0),
4972
5077
  set: async (keyId, key, options) => await scoped.set(keyId, key, options),
4973
5078
  delete: async (keyId) => await scoped.delete(keyId)
4974
5079
  };
@@ -5136,6 +5241,49 @@ function checkCachedKeyHit(cachedKey, keyId, cls, logger) {
5136
5241
  }
5137
5242
  return null;
5138
5243
  }
5244
+ /**
5245
+ * Looks up a key at a compatible identifier, or at an `ap:` or `ap+ef61:`
5246
+ * URI, in the cache namespace of a purpose, like {@link getCachedFetchKey}.
5247
+ * A key that the verified document of its portable actor was cached with
5248
+ * gets the actor's evidence attached from the same entry; see
5249
+ * {@link attachKeyOwnerEvidence}.
5250
+ */
5251
+ async function getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger) {
5252
+ if (scopedCache?.getEntry == null) return await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
5253
+ const entry = await scopedCache.getEntry(cacheKey);
5254
+ if (entry === void 0) return null;
5255
+ if (entry === null) {
5256
+ logger.debug("Entry {keyId} found in cache, but it is unavailable.", { keyId });
5257
+ return {
5258
+ key: null,
5259
+ cached: true
5260
+ };
5261
+ }
5262
+ const hit = checkCachedKeyHit(entry.key, keyId, cls, logger);
5263
+ if (hit?.key instanceof _fedify_vocab.CryptographicKey && entry.owner != null) attachKeyOwnerEvidence(hit.key, entry.owner, entry.expires);
5264
+ return hit;
5265
+ }
5266
+ /**
5267
+ * Attaches the evidence of the portable actor whose document has just
5268
+ * vouched for a key to the key. The evidence expires with the cache entry
5269
+ * of the key, so that it is never trusted longer than the key is cached.
5270
+ * Without a cache, it expires with the proof of the document, but no later
5271
+ * than {@link MAX_PORTABLE_KEY_TTL}, as a cache entry would.
5272
+ * @param resolution The resolution of the key.
5273
+ * @param scopedCache The cache namespace the key was stored in, if any.
5274
+ * @param cached When the cache entry expires, if the cache stored one.
5275
+ */
5276
+ function attachResolvedKeyOwnerEvidence(resolution, scopedCache, cached) {
5277
+ let expires;
5278
+ if (scopedCache != null) {
5279
+ if (cached == null) return;
5280
+ expires = cached;
5281
+ } else {
5282
+ expires = Temporal$2.Now.instant().add(MAX_PORTABLE_KEY_TTL);
5283
+ if (resolution.expires != null && Temporal$2.Instant.compare(resolution.expires, expires) < 0) expires = resolution.expires;
5284
+ }
5285
+ attachKeyOwnerEvidence(resolution.key, resolution.document, expires);
5286
+ }
5139
5287
  async function clearFetchErrorMetadata(keyId, keyCache) {
5140
5288
  await keyCache?.setFetchError?.(keyId, null);
5141
5289
  }
@@ -5260,7 +5408,10 @@ async function resolveFetchedKey(document, cacheKey, documentUrl, keyId, cls, {
5260
5408
  cached: false
5261
5409
  };
5262
5410
  }
5263
- await scopedCache?.set(cacheKey, resolution.key, { expires: resolution.expires });
5411
+ attachResolvedKeyOwnerEvidence(resolution, scopedCache, await scopedCache?.set(cacheKey, resolution.key, {
5412
+ expires: resolution.expires,
5413
+ owner: resolution.document
5414
+ }));
5264
5415
  return {
5265
5416
  key: resolution.key,
5266
5417
  cached: false
@@ -5481,7 +5632,7 @@ async function fetchCompatibleKey(cacheKey, cls, options, onCachedUnavailable, o
5481
5632
  const keyId = cacheKey.href;
5482
5633
  const sharedCache = options.keyCache;
5483
5634
  const scopedCache = sharedCache?.compatibleKeyScope?.(getCompatibleKeyScope(cls, options));
5484
- const cached = await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
5635
+ const cached = await getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger);
5485
5636
  if (cached != null) return {
5486
5637
  result: cached,
5487
5638
  outcome: { result: "hit" }
@@ -5545,7 +5696,7 @@ async function fetchPortableActorKey(cacheKey, cls, options, onCachedUnavailable
5545
5696
  }
5546
5697
  const sharedCache = options.keyCache;
5547
5698
  const scopedCache = sharedCache?.compatibleKeyScope?.("httpSignature");
5548
- const cached = await getCachedFetchKey(cacheKey, keyId, cls, scopedCache, logger);
5699
+ const cached = await getCachedCompatibleKey(cacheKey, keyId, cls, scopedCache, logger);
5549
5700
  if (cached != null) return {
5550
5701
  result: cached,
5551
5702
  outcome: { result: "hit" }
@@ -5560,7 +5711,10 @@ async function fetchPortableActorKey(cacheKey, cls, options, onCachedUnavailable
5560
5711
  logger.debug("Resolving key {keyId} to verify signature...", { keyId });
5561
5712
  const resolution = await resolvers.actorKey(cacheKey);
5562
5713
  if (resolution.type === "verified") {
5563
- await scopedCache?.set(cacheKey, resolution.key, { expires: resolution.expires });
5714
+ attachResolvedKeyOwnerEvidence(resolution, scopedCache, await scopedCache?.set(cacheKey, resolution.key, {
5715
+ expires: resolution.expires,
5716
+ owner: resolution.document
5717
+ }));
5564
5718
  return {
5565
5719
  result: {
5566
5720
  key: resolution.key,
@@ -6615,7 +6769,7 @@ async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, options =
6615
6769
  }
6616
6770
  //#endregion
6617
6771
  //#region src/sig/proof.ts
6618
- const Temporal$1 = Temporal$2;
6772
+ const Temporal$1 = Temporal$4;
6619
6773
  /**
6620
6774
  * Known Object Integrity Proof `cryptosuite` values, used to keep
6621
6775
  * `object_integrity_proofs.cryptosuite` on a bounded set of spec-defined
@@ -7901,6 +8055,7 @@ async function verifyPortableKeyDocument(document, actor, keyId, isGatewayKey, o
7901
8055
  type: "verified",
7902
8056
  actor,
7903
8057
  key,
8058
+ document: root,
7904
8059
  ...expires == null ? {} : { expires }
7905
8060
  };
7906
8061
  }
@@ -8119,7 +8274,7 @@ function isReference(node) {
8119
8274
  }
8120
8275
  //#endregion
8121
8276
  //#region src/sig/http.ts
8122
- const Temporal = Temporal$2;
8277
+ const Temporal = Temporal$4;
8123
8278
  const DEFAULT_MAX_REDIRECTION = 20;
8124
8279
  const DOUBLE_KNOCK_TRANSPORT_RETRY_DELAY_MS = 100;
8125
8280
  /**
@@ -8578,7 +8733,8 @@ async function verifyRequestDetailed(request, options = {}) {
8578
8733
  if (spec === "rfc9421") result = await verifyRequestRfc9421(request, span, metricsContext, options);
8579
8734
  else result = await verifyRequestDraft(request, span, metricsContext, options);
8580
8735
  recordVerificationResult(span, result);
8581
- if (!result.verified) span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
8736
+ if (result.verified) promoteKeyOwnerEvidence(result.key);
8737
+ else span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
8582
8738
  return result;
8583
8739
  } catch (error) {
8584
8740
  threw = true;
@@ -9301,10 +9457,16 @@ Object.defineProperty(exports, "InvalidPortableObjectIdError", {
9301
9457
  return InvalidPortableObjectIdError;
9302
9458
  }
9303
9459
  });
9460
+ Object.defineProperty(exports, "MAX_PORTABLE_KEY_TTL", {
9461
+ enumerable: true,
9462
+ get: function() {
9463
+ return MAX_PORTABLE_KEY_TTL;
9464
+ }
9465
+ });
9304
9466
  Object.defineProperty(exports, "Temporal", {
9305
9467
  enumerable: true,
9306
9468
  get: function() {
9307
- return Temporal$2;
9469
+ return Temporal$4;
9308
9470
  }
9309
9471
  });
9310
9472
  Object.defineProperty(exports, "assertSafeJsonLd", {
@@ -9451,6 +9613,12 @@ Object.defineProperty(exports, "getRemoteHost", {
9451
9613
  return getRemoteHost;
9452
9614
  }
9453
9615
  });
9616
+ Object.defineProperty(exports, "getVerifiedKeyOwnerEvidence", {
9617
+ enumerable: true,
9618
+ get: function() {
9619
+ return getVerifiedKeyOwnerEvidence;
9620
+ }
9621
+ });
9454
9622
  Object.defineProperty(exports, "hasPortableActor", {
9455
9623
  enumerable: true,
9456
9624
  get: function() {
@@ -9559,6 +9727,12 @@ Object.defineProperty(exports, "parseAcceptSignature", {
9559
9727
  return parseAcceptSignature;
9560
9728
  }
9561
9729
  });
9730
+ Object.defineProperty(exports, "parseKeyOwnerEvidence", {
9731
+ enumerable: true,
9732
+ get: function() {
9733
+ return parseKeyOwnerEvidence;
9734
+ }
9735
+ });
9562
9736
  Object.defineProperty(exports, "parseRfc9421SignatureInput", {
9563
9737
  enumerable: true,
9564
9738
  get: function() {