@fedify/fedify 2.4.0-pr.936.41 → 2.5.0-dev.2271

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 (244) hide show
  1. package/README.md +50 -39
  2. package/dist/{assert-CJ1KXcvv.mjs → assert-D1Eafmd_.mjs} +1 -1
  3. package/dist/{assert_equals-BV7oLMxm.mjs → assert_equals-Z6IcEbWU.mjs} +2 -28
  4. package/dist/assert_exists-cffSpJ7X.mjs +28 -0
  5. package/dist/assert_false-CPdRnc3E.mjs +23 -0
  6. package/dist/assert_greater_or_equal-BlafOF4-.mjs +31 -0
  7. package/dist/{assert_instance_of-Q9KTBnrf.mjs → assert_instance_of-mrXWWNY-.mjs} +1 -1
  8. package/dist/{assert_not_equals-EPJPoxuf.mjs → assert_not_equals-CpPK2t89.mjs} +2 -1
  9. package/dist/assert_rejects-CTptdYck.mjs +39 -0
  10. package/dist/{assert_strict_equals-Ec20AUwa.mjs → assert_strict_equals-CYvBmkpC.mjs} +2 -1
  11. package/dist/{assert_throws-NiFfqbnH.mjs → assert_throws-BYITOvPO.mjs} +2 -1
  12. package/dist/assertion_error-B-cx0fFA.mjs +31 -0
  13. package/dist/audience-CHQ-FlLD.mjs +95 -0
  14. package/dist/{builder-DonuxRl_.mjs → builder-Bda6LK7A.mjs} +169 -14
  15. package/dist/{circuit-breaker-CBGyz5F7.mjs → circuit-breaker-XJ53md4S.mjs} +224 -17
  16. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +14 -0
  17. package/dist/{client-CjF5IYQS.mjs → client-CEnNz8O7.mjs} +144 -8
  18. package/dist/{codec-BBga-FWI.mjs → codec-C6rTrpIp.mjs} +26 -3
  19. package/dist/{collection-BIhlldqK.mjs → collection-CnnP1UAv.mjs} +1 -1
  20. package/dist/compat/mod.cjs +1 -1
  21. package/dist/compat/mod.d.cts +1 -1
  22. package/dist/compat/mod.d.ts +1 -1
  23. package/dist/compat/mod.js +1 -1
  24. package/dist/compat/outgoing-jsonld.test.mjs +71 -3
  25. package/dist/compat/public-audience.test.mjs +14 -5
  26. package/dist/compat/secured-document.test.d.mts +2 -0
  27. package/dist/compat/secured-document.test.mjs +58 -0
  28. package/dist/compat/transformers.test.mjs +5 -5
  29. package/dist/compound-proof-B-9mXxFW.mjs +989 -0
  30. package/dist/{context-Zii1f5xS.d.ts → context-7NyiqIcg.d.ts} +1600 -25
  31. package/dist/{context-BJXxPElm.mjs → context-8Tu9kea0.mjs} +21 -63
  32. package/dist/{context-lxX6I7as.d.cts → context-tsYPJ2Ew.d.cts} +1600 -25
  33. package/dist/{deno-BHzKn9Ig.mjs → deno-oR5aJKpU.mjs} +1 -1
  34. package/dist/dist-DJQM4u7i.mjs +189 -0
  35. package/dist/docloader-DBoYbvYW.mjs +87 -0
  36. package/dist/{esm-yYQfPhIY.mjs → esm-BHXXx4Wx.mjs} +13 -6
  37. package/dist/federation/audience.test.d.mts +2 -0
  38. package/dist/federation/audience.test.mjs +130 -0
  39. package/dist/federation/builder.test.mjs +54 -5
  40. package/dist/federation/circuit-breaker.test.mjs +838 -7
  41. package/dist/federation/collection.test.mjs +3 -3
  42. package/dist/federation/compound-fanout.test.d.mts +2 -0
  43. package/dist/federation/compound-fanout.test.mjs +228 -0
  44. package/dist/federation/handler-compound-proof.test.d.mts +2 -0
  45. package/dist/federation/handler-compound-proof.test.mjs +384 -0
  46. package/dist/federation/handler.test.mjs +385 -15
  47. package/dist/federation/hashlink-media.test.d.mts +2 -0
  48. package/dist/federation/hashlink-media.test.mjs +422 -0
  49. package/dist/federation/idempotency.test.mjs +6 -6
  50. package/dist/federation/inbox-report.test.d.mts +2 -0
  51. package/dist/federation/inbox-report.test.mjs +475 -0
  52. package/dist/federation/inbox.test.mjs +3 -3
  53. package/dist/federation/keycache.test.mjs +215 -14
  54. package/dist/federation/kv.test.mjs +3 -3
  55. package/dist/federation/metrics.test.mjs +5 -5
  56. package/dist/federation/middleware.test.mjs +967 -35
  57. package/dist/federation/mod.cjs +18 -261
  58. package/dist/federation/mod.d.cts +5 -5
  59. package/dist/federation/mod.d.ts +5 -5
  60. package/dist/federation/mod.js +279 -1
  61. package/dist/federation/mq.test.mjs +123 -47
  62. package/dist/federation/negotiation.test.mjs +4 -4
  63. package/dist/federation/outgoing-proof.test.d.mts +2 -0
  64. package/dist/federation/outgoing-proof.test.mjs +931 -0
  65. package/dist/federation/portable-actor.test.d.mts +2 -0
  66. package/dist/federation/portable-actor.test.mjs +496 -0
  67. package/dist/federation/portable-chain.test.d.mts +2 -0
  68. package/dist/federation/portable-chain.test.mjs +370 -0
  69. package/dist/federation/portable-collection.test.d.mts +2 -0
  70. package/dist/federation/portable-collection.test.mjs +832 -0
  71. package/dist/federation/portable-delivery.test.d.mts +2 -0
  72. package/dist/federation/portable-delivery.test.mjs +746 -0
  73. package/dist/federation/portable-gateway-keys.test.d.mts +2 -0
  74. package/dist/federation/portable-gateway-keys.test.mjs +686 -0
  75. package/dist/federation/portable-inbox.test.d.mts +2 -0
  76. package/dist/federation/portable-inbox.test.mjs +1535 -0
  77. package/dist/federation/portable-parse-uri.test.d.mts +2 -0
  78. package/dist/federation/portable-parse-uri.test.mjs +348 -0
  79. package/dist/federation/portable-route-activity.test.d.mts +2 -0
  80. package/dist/federation/portable-route-activity.test.mjs +259 -0
  81. package/dist/federation/portable.test.d.mts +2 -0
  82. package/dist/federation/portable.test.mjs +1072 -0
  83. package/dist/federation/retry.test.mjs +4 -3
  84. package/dist/federation/router.test.mjs +9 -159
  85. package/dist/federation/send.test.mjs +245 -27
  86. package/dist/federation/tasks/codec.test.mjs +4 -4
  87. package/dist/federation/tasks/enqueue.test.mjs +42 -4
  88. package/dist/federation/tasks/tasks.test.mjs +7 -6
  89. package/dist/federation/temporal.test.mjs +4 -4
  90. package/dist/federation/webfinger.test.mjs +275 -12
  91. package/dist/{middleware-FrSMAYEx.cjs → federation-CkZiAcWY.cjs} +8640 -3722
  92. package/dist/http-B5JT115n.cjs +10630 -0
  93. package/dist/http-DydWCB7R.js +6527 -0
  94. package/dist/{http-CPVMUgsW.mjs → http-siciWkmx.mjs} +397 -168
  95. package/dist/key-BspPiXqn.mjs +951 -0
  96. package/dist/key-C1nv7_jD.d.ts +1125 -0
  97. package/dist/key-DYxuyd-s.d.cts +1125 -0
  98. package/dist/key-owner-evidence-APB6NpSk.mjs +108 -0
  99. package/dist/keycache-Da8A8mZa.mjs +200 -0
  100. package/dist/{kv-D6hNiMTK.d.ts → kv-B2mzK5tl.d.cts} +3 -2
  101. package/dist/{kv-gJ8LYbxX.d.cts → kv-B2mzK5tl.d.ts} +3 -2
  102. package/dist/kv-DBRWVx3Q.mjs +104 -0
  103. package/dist/{kv-cache-KyGqJqSp.mjs → kv-cache-BF1hnW65.mjs} +1 -1
  104. package/dist/{kv-cache-5bnX3-Jq.js → kv-cache-CTQr1tbn.js} +54 -16
  105. package/dist/{kv-cache-DQ29C4XL.cjs → kv-cache-DCac1nEU.cjs} +55 -19
  106. package/dist/{ld-Cj9F_5AP.mjs → ld-CzaP-hJl.mjs} +44 -12
  107. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +204 -0
  108. package/dist/map-local-create-note-B0SeXJms.mjs +214 -0
  109. package/dist/{metrics-DMk-nTxI.mjs → metrics-CYg9yxBL.mjs} +3 -2
  110. package/dist/metrics-DVKYY6K1.d.cts +36 -0
  111. package/dist/metrics-DoRtI0qU.d.ts +36 -0
  112. package/dist/{middleware-Y-kpsp6S.js → middleware-CsDDXKuL.js} +5493 -1103
  113. package/dist/{middleware-CvwTUgnP.mjs → middleware-D7_LO-Vs.mjs} +3157 -272
  114. package/dist/{middleware-CEctxBN6.mjs → middleware-DWjrfpcz.mjs} +1 -1
  115. package/dist/{mod-gOlPDuT8.d.cts → mod-BojP2Bw3.d.cts} +1 -1
  116. package/dist/mod-CavhAgLw.d.cts +320 -0
  117. package/dist/mod-CtpF2BU5.d.ts +320 -0
  118. package/dist/{mod-BtEaIEcD.d.cts → mod-DEZXwV6J.d.ts} +10 -4
  119. package/dist/{mod-UMmveiO0.d.ts → mod-Dw-nPxQh.d.cts} +10 -4
  120. package/dist/{mod-DLc2Ot6f.d.ts → mod-Xj5P4s4d.d.ts} +1 -1
  121. package/dist/mod.cjs +40 -39
  122. package/dist/mod.d.cts +10 -11
  123. package/dist/mod.d.ts +10 -11
  124. package/dist/mod.js +9 -9
  125. package/dist/{mq-llHKivST.mjs → mq-Dm1Wmtm-.mjs} +6 -0
  126. package/dist/nodeinfo/client.test.mjs +139 -4
  127. package/dist/nodeinfo/handler.test.mjs +5 -5
  128. package/dist/nodeinfo/mod.cjs +1 -1
  129. package/dist/nodeinfo/mod.d.cts +1 -1
  130. package/dist/nodeinfo/mod.d.ts +1 -1
  131. package/dist/nodeinfo/mod.js +1 -1
  132. package/dist/nodeinfo/types.test.mjs +4 -4
  133. package/dist/otel/exporter.test.mjs +3 -3
  134. package/dist/otel/mod.cjs +0 -1
  135. package/dist/otel/mod.d.cts +1 -1
  136. package/dist/otel/mod.d.ts +1 -1
  137. package/dist/{outgoing-jsonld-URuqsICz.mjs → outgoing-jsonld-4IJqPYos.mjs} +12 -10
  138. package/dist/{owner-DEvZuyOE.d.cts → owner-BF0L9cMt.d.cts} +11 -0
  139. package/dist/{owner-CnngXDNJ.d.ts → owner-BSzr5-I8.d.ts} +11 -0
  140. package/dist/owner-DYgfTFHy.mjs +267 -0
  141. package/dist/portable-collection-BpsVsRov.js +670 -0
  142. package/dist/portable-collection-C74P1vtC.mjs +418 -0
  143. package/dist/portable-collection-DZd2bm7M.cjs +686 -0
  144. package/dist/portable-key-BIMLrAP4.mjs +549 -0
  145. package/dist/portable-key-id-Ca30-hOa.mjs +248 -0
  146. package/dist/proof-Dxy6ByqI.mjs +1299 -0
  147. package/dist/{public-audience-Cr5MsnMq.mjs → public-audience--klBIOk1.mjs} +15 -10
  148. package/dist/router-u5O5KCQr.mjs +156 -0
  149. package/dist/runtime/mod.cjs +1 -1
  150. package/dist/runtime/mod.js +1 -1
  151. package/dist/secured-document-CxzZZ9nL.mjs +35 -0
  152. package/dist/send-C4dDpAxm.mjs +495 -0
  153. package/dist/sig/accept.test.mjs +1 -1
  154. package/dist/sig/compound-proof-discovery.test.d.mts +2 -0
  155. package/dist/sig/compound-proof-discovery.test.mjs +331 -0
  156. package/dist/sig/compound-proof-producer.test.d.mts +2 -0
  157. package/dist/sig/compound-proof-producer.test.mjs +107 -0
  158. package/dist/sig/compound-proof-verification.test.d.mts +2 -0
  159. package/dist/sig/compound-proof-verification.test.mjs +833 -0
  160. package/dist/sig/compound-proof.test.d.mts +2 -0
  161. package/dist/sig/compound-proof.test.mjs +411 -0
  162. package/dist/sig/http.test.mjs +702 -31
  163. package/dist/sig/key-owner-evidence.test.d.mts +2 -0
  164. package/dist/sig/key-owner-evidence.test.mjs +100 -0
  165. package/dist/sig/key.test.mjs +220 -8
  166. package/dist/sig/ld.test.mjs +65 -7
  167. package/dist/sig/mitra-receive-interop.test.d.mts +2 -0
  168. package/dist/sig/mitra-receive-interop.test.mjs +260 -0
  169. package/dist/sig/mitra-send-interop.test.d.mts +2 -0
  170. package/dist/sig/mitra-send-interop.test.mjs +461 -0
  171. package/dist/sig/mod.cjs +18 -16
  172. package/dist/sig/mod.d.cts +4 -4
  173. package/dist/sig/mod.d.ts +4 -4
  174. package/dist/sig/mod.js +3 -3
  175. package/dist/sig/owner.test.mjs +108 -9
  176. package/dist/sig/portable-collection.test.d.mts +2 -0
  177. package/dist/sig/portable-collection.test.mjs +697 -0
  178. package/dist/sig/portable-interop.test.d.mts +2 -0
  179. package/dist/sig/portable-interop.test.mjs +156 -0
  180. package/dist/sig/portable-key-id.test.d.mts +2 -0
  181. package/dist/sig/portable-key-id.test.mjs +67 -0
  182. package/dist/sig/portable-key.test.d.mts +2 -0
  183. package/dist/sig/portable-key.test.mjs +1439 -0
  184. package/dist/sig/proof.test.mjs +1753 -16
  185. package/dist/sig/tootik-request-interop.test.d.mts +2 -0
  186. package/dist/sig/tootik-request-interop.test.mjs +190 -0
  187. package/dist/sig/tootik-send-interop.test.d.mts +2 -0
  188. package/dist/sig/tootik-send-interop.test.mjs +331 -0
  189. package/dist/sig/verification.test.d.mts +2 -0
  190. package/dist/sig/verification.test.mjs +310 -0
  191. package/dist/std__assert-DvMDRPes.mjs +8 -0
  192. package/dist/{testing-CO7ftO8A.mjs → tasks-IG3pHfvZ.mjs} +2 -2
  193. package/dist/{temporal-fsXO5IvD.mjs → temporal-D0KJI4NF.mjs} +3 -3
  194. package/dist/testing/context.test.d.mts +2 -0
  195. package/dist/testing/context.test.mjs +19 -0
  196. package/dist/testing/kv.test.d.mts +2 -0
  197. package/dist/testing/kv.test.mjs +101 -0
  198. package/dist/testing/mod.d.mts +1617 -48
  199. package/dist/testing/mod.mjs +6 -3
  200. package/dist/testing-t8xDeJZ5.mjs +8 -0
  201. package/dist/{transformers-DGwl-hD1.cjs → transformers-BalCrSsr.cjs} +0 -1
  202. package/dist/{types-DC1pNgJA.js → types-_S2_MeLF.js} +144 -8
  203. package/dist/{types-CPym83zc.cjs → types-poIao40f.cjs} +160 -7
  204. package/dist/utils/docloader.test.mjs +530 -8
  205. package/dist/utils/kv-cache.test.mjs +2 -2
  206. package/dist/utils/mod.cjs +1 -1
  207. package/dist/utils/mod.d.cts +1 -1
  208. package/dist/utils/mod.d.ts +1 -1
  209. package/dist/utils/mod.js +1 -1
  210. package/dist/verification-C3954hQh.mjs +5 -0
  211. package/dist/verification-Dpfcw8ml.mjs +105 -0
  212. package/dist/vocab/cjs.test.mjs +1 -1
  213. package/package.json +8 -8
  214. package/dist/assert_rejects-EgstcQy5.mjs +0 -82
  215. package/dist/docloader-e1khNUKy.mjs +0 -49
  216. package/dist/http-CsmQ-BQ4.js +0 -2483
  217. package/dist/http-VyDTd4G3.d.cts +0 -553
  218. package/dist/http-hlIjmewS.cjs +0 -2694
  219. package/dist/http-lf8Hsd91.d.ts +0 -553
  220. package/dist/key-DfPsX8hv.mjs +0 -453
  221. package/dist/keycache-_DHqz5z_.mjs +0 -97
  222. package/dist/metrics-CoUJLQhZ.d.cts +0 -276
  223. package/dist/metrics-Dc4jR-IC.d.ts +0 -276
  224. package/dist/mod-B0hW12_O.d.cts +0 -307
  225. package/dist/mod-COIAjwRS.d.ts +0 -307
  226. package/dist/owner-Br9YYzn_.mjs +0 -120
  227. package/dist/proof-B4ngoaNQ.mjs +0 -316
  228. package/dist/proof-B6E0XUXJ.js +0 -1415
  229. package/dist/proof-NN4xCQGL.cjs +0 -1562
  230. package/dist/send-CxHKUNzv.mjs +0 -239
  231. package/dist/std__assert-B2NnY9bq.mjs +0 -79
  232. package/dist/temporal-polyfill-BCdTHexd.cjs +0 -3565
  233. /package/dist/{accept-8PiolDP7.mjs → accept-CPVqki78.mjs} +0 -0
  234. /package/dist/{activity-listener-BtTSxZWA.mjs → activity-listener-C-BSbKI7.mjs} +0 -0
  235. /package/dist/{client-CAM_bQXx.d.cts → client-D-XP_Ccb.d.cts} +0 -0
  236. /package/dist/{client-CSddvgWN.d.ts → client-D-XP_Ccb.d.ts} +0 -0
  237. /package/dist/{keys-Dbyd7bhl.mjs → keys-DIJNHW-Y.mjs} +0 -0
  238. /package/dist/{kv-CXBAok3k.mjs → kv-DCHkaJ9-.mjs} +0 -0
  239. /package/dist/{negotiation-RuwrPFqi.mjs → negotiation-CCocWT_N.mjs} +0 -0
  240. /package/dist/{retry-DgFqeS5k.mjs → retry-zX5xw5e0.mjs} +0 -0
  241. /package/dist/{chunk-D5IdezsZ.js → rolldown-runtime-BC-Eo5Mj.js} +0 -0
  242. /package/dist/{chunk-Czpeue4M.cjs → rolldown-runtime-Dmm3t92W.cjs} +0 -0
  243. /package/dist/{transformers-DXze6FUB.js → transformers-DAtXl_Kc.js} +0 -0
  244. /package/dist/{types-CrtdVuDP.mjs → types-DE_LV1JB.mjs} +0 -0
@@ -0,0 +1,686 @@
1
+ const { URLPattern } = require("urlpattern-polyfill");
2
+ const require_http = require("./http-B5JT115n.cjs");
3
+ let _logtape_logtape = require("@logtape/logtape");
4
+ let _fedify_vocab = require("@fedify/vocab");
5
+ let _opentelemetry_api = require("@opentelemetry/api");
6
+ let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
7
+ let _fedify_vocab_runtime_internal_portable_dereference = require("@fedify/vocab-runtime/internal/portable-dereference");
8
+ //#region src/sig/owner.ts
9
+ const logger$1 = (0, _logtape_logtape.getLogger)([
10
+ "fedify",
11
+ "sig",
12
+ "owner"
13
+ ]);
14
+ /**
15
+ * Checks if the actor of the given activity owns the specified key.
16
+ *
17
+ * Ownership is never taken from what the activity or the key say about
18
+ * themselves, as both are written by whoever sent the activity. It is
19
+ * established from a document that the owner itself serves: either the key's
20
+ * claimed owner links back to the key, or the actor the activity claims lists
21
+ * the key as its own.
22
+ *
23
+ * @param activity The activity to check.
24
+ * @param key The public key to check.
25
+ * @param options Options for checking the key ownership.
26
+ * @returns Whether the actor is the owner of the key.
27
+ */
28
+ async function doesActorOwnKey(activity, key, options) {
29
+ return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version).startActiveSpan("activitypub.verify_key_ownership", {
30
+ kind: _opentelemetry_api.SpanKind.INTERNAL,
31
+ attributes: {
32
+ "activitypub.actor.id": activity.actorId?.href ?? "",
33
+ "activitypub.key.id": key.id?.href ?? ""
34
+ }
35
+ }, async (span) => {
36
+ try {
37
+ const actorId = activity.actorId;
38
+ if (actorId == null) {
39
+ span.setAttribute("activitypub.key_ownership.verified", false);
40
+ span.setAttribute("activitypub.key_ownership.method", "none");
41
+ return false;
42
+ }
43
+ const evidence = require_http.getVerifiedKeyOwnerEvidence(key);
44
+ if (evidence != null) {
45
+ const verified = require_http.getCanonicalPortableId(actorId) === evidence.ownerId;
46
+ span.setAttribute("activitypub.key_ownership.verified", verified);
47
+ span.setAttribute("activitypub.key_ownership.method", key.id != null && require_http.isPortableUri(key.id) ? "portable_actor_key" : "portable_gateway_key");
48
+ return verified;
49
+ }
50
+ if (key.id != null && require_http.isPortableUri(key.id)) {
51
+ const owner = await getPortableActorKeyOwner(key, options);
52
+ const ownerId = owner?.id == null ? null : require_http.getCanonicalPortableId(owner.id);
53
+ const verified = ownerId != null && ownerId === require_http.getCanonicalPortableId(actorId);
54
+ span.setAttribute("activitypub.key_ownership.verified", verified);
55
+ span.setAttribute("activitypub.key_ownership.method", "portable_actor_key");
56
+ return verified;
57
+ }
58
+ if (key.id != null && require_http.isCompatibleKeyId(key.id)) {
59
+ const owner = await getPortableGatewayKeyOwner(key, options);
60
+ if (owner !== void 0) {
61
+ const ownerId = owner?.id == null ? null : require_http.getCanonicalPortableId(owner.id);
62
+ const verified = ownerId != null && ownerId === require_http.getCanonicalPortableId(actorId);
63
+ span.setAttribute("activitypub.key_ownership.verified", verified);
64
+ span.setAttribute("activitypub.key_ownership.method", "portable_gateway_key");
65
+ return verified;
66
+ }
67
+ }
68
+ if (key.ownerId != null) {
69
+ const owner = await require_http.verifyKeyOwnership(key, options);
70
+ if (owner?.id != null && owner.id.href === actorId.href) {
71
+ span.setAttribute("activitypub.key_ownership.verified", true);
72
+ span.setAttribute("activitypub.key_ownership.method", "key_owner");
73
+ return true;
74
+ }
75
+ }
76
+ const actor = await require_http.fetchActorDocument(actorId, options);
77
+ if (actor != null && await doesActorListKey(actor, key, options)) {
78
+ span.setAttribute("activitypub.key_ownership.verified", true);
79
+ span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
80
+ return true;
81
+ }
82
+ logger$1.debug("The actor {actorId} does not own key {keyId}: neither the owner the key claims nor the actor's own document links the two to each other.", {
83
+ actorId: actorId.href,
84
+ keyId: key.id?.href
85
+ });
86
+ span.setAttribute("activitypub.key_ownership.verified", false);
87
+ span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
88
+ return false;
89
+ } catch (error) {
90
+ span.recordException(error);
91
+ span.setStatus({
92
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
93
+ message: String(error)
94
+ });
95
+ throw error;
96
+ } finally {
97
+ span.end();
98
+ }
99
+ });
100
+ }
101
+ /**
102
+ * Determines whether the given actor's own document lists the given key among
103
+ * its public keys.
104
+ *
105
+ * Keys are matched by id, which is what an actor document links to. A key
106
+ * document may leave its id implicit, though, and then there is no id for the
107
+ * actor to link to; the key material itself is the only thing the two can
108
+ * have in common, so that is what gets compared.
109
+ */
110
+ async function doesActorListKey(actor, key, options) {
111
+ if (key.id != null) {
112
+ for (const publicKeyId of actor.publicKeyIds) if (publicKeyId.href === key.id.href) return true;
113
+ return false;
114
+ }
115
+ if (key.publicKey == null) return false;
116
+ const publicKeys = actor.getPublicKeys({
117
+ ...options,
118
+ suppressError: true
119
+ });
120
+ for await (const publicKey of publicKeys) {
121
+ if (publicKey.publicKey == null) continue;
122
+ if (await isSamePublicKey(publicKey.publicKey, key.publicKey)) return true;
123
+ }
124
+ return false;
125
+ }
126
+ /**
127
+ * Compares two public keys by their key material, ignoring the metadata that
128
+ * surrounds it.
129
+ */
130
+ async function isSamePublicKey(a, b) {
131
+ const [x, y] = await Promise.all([require_http.exportJwk(a), require_http.exportJwk(b)]);
132
+ return x.kty === y.kty && x.crv === y.crv && x.n === y.n && x.e === y.e && x.x === y.x && x.y === y.y;
133
+ }
134
+ /**
135
+ * Gets the actor that owns the specified key. Returns `null` if the key has no
136
+ * known owner.
137
+ *
138
+ * The owner is only returned when the key and the owner link to each other:
139
+ * a document that merely claims to own a key is not enough, as the claim and
140
+ * the key can come from the same host.
141
+ *
142
+ * @param keyId The ID of the key to check, or the key itself.
143
+ * @param options Options for getting the key owner.
144
+ * @returns The actor that owns the key, or `null` if the key has no known
145
+ * owner.
146
+ * @since 0.7.0
147
+ */
148
+ async function getKeyOwner(keyId, options) {
149
+ const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
150
+ const documentLoader = options.documentLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)();
151
+ const fetchOptions = {
152
+ documentLoader,
153
+ contextLoader: options.contextLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)(),
154
+ tracerProvider
155
+ };
156
+ if (keyId instanceof _fedify_vocab.CryptographicKey) {
157
+ const evidence = require_http.getVerifiedKeyOwnerEvidence(keyId);
158
+ if (evidence != null) {
159
+ const owner = await require_http.parseKeyOwnerEvidence(evidence, fetchOptions);
160
+ if (owner != null) return owner;
161
+ }
162
+ }
163
+ const id = keyId instanceof _fedify_vocab.CryptographicKey ? keyId.id : keyId;
164
+ if (id != null && require_http.isPortableUri(id)) return await getPortableActorKeyOwner(keyId, fetchOptions);
165
+ if (id != null && require_http.isCompatibleKeyId(id)) {
166
+ const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
167
+ if (owner !== void 0) return owner;
168
+ }
169
+ if (keyId instanceof _fedify_vocab.CryptographicKey) return await require_http.verifyKeyOwnership(keyId, fetchOptions);
170
+ let keyDoc;
171
+ let documentUrl = keyId;
172
+ try {
173
+ const remoteDocument = await documentLoader(keyId.href);
174
+ keyDoc = remoteDocument.document;
175
+ documentUrl = new URL(remoteDocument.documentUrl ?? "", keyId);
176
+ } catch (_) {
177
+ return null;
178
+ }
179
+ let object;
180
+ try {
181
+ object = await _fedify_vocab.Object.fromJsonLd(keyDoc, {
182
+ ...fetchOptions,
183
+ baseUrl: documentUrl
184
+ });
185
+ } catch (e) {
186
+ if (!(e instanceof TypeError)) throw e;
187
+ try {
188
+ object = await _fedify_vocab.CryptographicKey.fromJsonLd(keyDoc, fetchOptions);
189
+ } catch (e) {
190
+ if (e instanceof TypeError) return null;
191
+ throw e;
192
+ }
193
+ }
194
+ if (object instanceof _fedify_vocab.CryptographicKey) {
195
+ if (object.id != null && object.id.href !== keyId.href) return null;
196
+ return await require_http.verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
197
+ }
198
+ if (!(0, _fedify_vocab.isActor)(object)) return null;
199
+ if (object.id == null || require_http.isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
200
+ logger$1.debug("The document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin; refusing to treat it as the owner of key {keyId}.", {
201
+ documentUrl: documentUrl.href,
202
+ actorId: object.id?.href,
203
+ keyId: keyId.href
204
+ });
205
+ return null;
206
+ }
207
+ for (const kid of object.publicKeyIds) if (kid.href === keyId.href) return object;
208
+ return null;
209
+ }
210
+ /**
211
+ * Resolves the owner of a key at a compatible identifier, if the key turns
212
+ * out to be a gateway key of an [FEP-ef61] portable actor.
213
+ *
214
+ * [FEP-ef61]: https://w3id.org/fep/ef61
215
+ * @param key The key, or its ID, which must be a compatible identifier.
216
+ * @param options Options for fetching the key.
217
+ * @returns `undefined` if the key is not a gateway key, i.e., the document at
218
+ * the key ID is not a portable actor, so the usual checks apply.
219
+ * Otherwise, the portable actor if its signed document vouches for
220
+ * the key, and the given key, if any, has the same key material, or
221
+ * `null` if not.
222
+ */
223
+ async function getPortableGatewayKeyOwner(key, options) {
224
+ const keyId = key instanceof _fedify_vocab.CryptographicKey ? key.id : key;
225
+ if (keyId == null) return void 0;
226
+ const resolution = await require_http.fetchPortableGatewayKey(keyId, options);
227
+ if (resolution.type === "legacy") return void 0;
228
+ if (resolution.type === "rejected") return null;
229
+ if (key instanceof _fedify_vocab.CryptographicKey) {
230
+ if (key.publicKey == null || !await require_http.isSamePublicKey(key.publicKey, resolution.key.publicKey)) {
231
+ logger$1.debug("The key {keyId} does not have the same key material as the gateway key its portable actor vouches for.", { keyId: keyId.href });
232
+ return null;
233
+ }
234
+ }
235
+ return resolution.actor;
236
+ }
237
+ /**
238
+ * Resolves the owner of a key of an [FEP-ef61] portable actor at an `ap:` or
239
+ * `ap+ef61:` key ID.
240
+ *
241
+ * [FEP-ef61]: https://w3id.org/fep/ef61
242
+ * @param key The key, or its ID, which must be an `ap:` or `ap+ef61:` URI.
243
+ * @param options Options for fetching the key.
244
+ * @returns The portable actor if its signed document vouches for the key,
245
+ * and the given key, if any, has the same key material, or `null`
246
+ * if not.
247
+ */
248
+ async function getPortableActorKeyOwner(key, options) {
249
+ const keyId = key instanceof _fedify_vocab.CryptographicKey ? key.id : key;
250
+ if (keyId == null) return null;
251
+ const resolution = await require_http.resolvePortableActorKey(keyId, options);
252
+ if (resolution.type !== "verified") return null;
253
+ if (key instanceof _fedify_vocab.CryptographicKey) {
254
+ if (key.publicKey == null || !await require_http.isSamePublicKey(key.publicKey, resolution.key.publicKey)) {
255
+ logger$1.debug("The key {keyId} does not have the same key material as the key its portable actor vouches for.", { keyId: keyId.href });
256
+ return null;
257
+ }
258
+ }
259
+ return resolution.actor;
260
+ }
261
+ //#endregion
262
+ //#region src/sig/portable-collection.ts
263
+ const logger = (0, _logtape_logtape.getLogger)([
264
+ "fedify",
265
+ "sig",
266
+ "proof"
267
+ ]);
268
+ const AS_NAMESPACE = "https://www.w3.org/ns/activitystreams#";
269
+ const AS_ATTRIBUTED_TO = `${AS_NAMESPACE}attributedTo`;
270
+ const AS_PART_OF = `${AS_NAMESPACE}partOf`;
271
+ /**
272
+ * The properties through which a collection refers to its pages, and a page
273
+ * to other pages of the same collection.
274
+ */
275
+ const PAGING_PROPERTIES = new Set([
276
+ "first",
277
+ "last",
278
+ "current",
279
+ "next",
280
+ "prev"
281
+ ].map((p) => AS_NAMESPACE + p));
282
+ /**
283
+ * The properties through which an actor refers to its own collections.
284
+ */
285
+ const ACTOR_COLLECTION_PROPERTIES = /* @__PURE__ */ new Set([
286
+ "http://www.w3.org/ns/ldp#inbox",
287
+ `${AS_NAMESPACE}outbox`,
288
+ `${AS_NAMESPACE}followers`,
289
+ `${AS_NAMESPACE}following`,
290
+ `${AS_NAMESPACE}liked`
291
+ ]);
292
+ const contextStates = /* @__PURE__ */ new WeakMap();
293
+ function createContext(state) {
294
+ const token = Object.freeze(Object.create(null));
295
+ contextStates.set(token, state);
296
+ return token;
297
+ }
298
+ function getContextState(context) {
299
+ if (context == null || typeof context !== "object") return void 0;
300
+ return contextStates.get(context);
301
+ }
302
+ function canonicalize(id) {
303
+ try {
304
+ const portable = (0, _fedify_vocab_runtime.fromCompatibleEf61Id)(id);
305
+ if (portable != null) return (0, _fedify_vocab_runtime.canonicalizePortableUri)((0, _fedify_vocab_runtime.formatIri)(portable));
306
+ return (0, _fedify_vocab_runtime.canonicalizePortableUri)(typeof id === "string" ? id : (0, _fedify_vocab_runtime.formatIri)(id));
307
+ } catch (error) {
308
+ if (error instanceof TypeError) return null;
309
+ throw error;
310
+ }
311
+ }
312
+ function toUrl(canonicalId) {
313
+ return (0, _fedify_vocab_runtime.parseIri)(canonicalId);
314
+ }
315
+ function canonicalizeAll(ids) {
316
+ const result = [];
317
+ for (const id of ids) {
318
+ const canonical = canonicalize(id);
319
+ if (canonical == null) return null;
320
+ result.push(canonical);
321
+ }
322
+ return result;
323
+ }
324
+ function getExpandedIds(node, property) {
325
+ const values = node[property];
326
+ if (values == null) return [];
327
+ if (!Array.isArray(values)) return null;
328
+ const ids = [];
329
+ for (const value of values) {
330
+ if (value == null || typeof value !== "object" || Array.isArray(value) || typeof value["@id"] !== "string") return null;
331
+ ids.push(value["@id"]);
332
+ }
333
+ return ids;
334
+ }
335
+ function parseAll(ids) {
336
+ const result = [];
337
+ for (const id of ids) try {
338
+ result.push((0, _fedify_vocab_runtime.parseIri)(id));
339
+ } catch (error) {
340
+ if (error instanceof TypeError) return null;
341
+ throw error;
342
+ }
343
+ return result;
344
+ }
345
+ function describeRoot(root) {
346
+ const rawId = root["@id"];
347
+ if (typeof rawId !== "string") return null;
348
+ const id = canonicalize(rawId);
349
+ if (id == null) return null;
350
+ const partOf = getExpandedIds(root, AS_PART_OF);
351
+ const attributedTo = getExpandedIds(root, AS_ATTRIBUTED_TO);
352
+ return {
353
+ id,
354
+ url: toUrl(id),
355
+ origin: (0, _fedify_vocab_runtime.getFe34Origin)(id),
356
+ partOf: partOf == null ? null : canonicalizeAll(partOf),
357
+ attributedTo: attributedTo == null ? null : canonicalizeAll(attributedTo),
358
+ attributedToUrls: attributedTo == null ? null : parseAll(attributedTo)
359
+ };
360
+ }
361
+ function describeObject(object) {
362
+ if (!(object instanceof _fedify_vocab.Object) || object.id == null) return null;
363
+ const id = canonicalize(object.id);
364
+ if (id == null) return null;
365
+ const partOfId = object instanceof _fedify_vocab.CollectionPage ? object.partOfId : null;
366
+ return {
367
+ id,
368
+ url: toUrl(id),
369
+ origin: (0, _fedify_vocab_runtime.getFe34Origin)(id),
370
+ partOf: canonicalizeAll(partOfId == null ? [] : [partOfId]),
371
+ attributedTo: canonicalizeAll(object.attributionIds),
372
+ attributedToUrls: object.attributionIds
373
+ };
374
+ }
375
+ function fail(reason) {
376
+ return {
377
+ verified: false,
378
+ reason
379
+ };
380
+ }
381
+ /**
382
+ * Walks the referrer chain of a collection or page to find the root
383
+ * collection and its owner candidate, checking every page on the way.
384
+ */
385
+ function resolveChain(node, referrer) {
386
+ const pages = [];
387
+ let top = node;
388
+ let link = referrer;
389
+ let state;
390
+ while (link != null && PAGING_PROPERTIES.has(link.property)) {
391
+ pages.push(top);
392
+ state = getContextState(link.collectionContext);
393
+ if (state != null) break;
394
+ const parent = describeObject(link.object);
395
+ if (parent == null || link.truncated) return fail({ type: "unknownCollectionOwner" });
396
+ top = parent;
397
+ link = link.referrer;
398
+ }
399
+ let rootId;
400
+ let rootOrigin;
401
+ let candidate;
402
+ if (state != null) {
403
+ rootId = state.rootId;
404
+ rootOrigin = state.rootOrigin;
405
+ const ownerCandidate = state.owner == null ? state.ownerCandidate : { id: canonicalize(state.owner.id) };
406
+ if (ownerCandidate == null) return fail({ type: "unknownCollectionOwner" });
407
+ candidate = ownerCandidate;
408
+ } else {
409
+ rootId = top.id;
410
+ rootOrigin = top.origin;
411
+ const attributedTo = top.attributedTo;
412
+ if (attributedTo == null) return fail({ type: "unknownCollectionOwner" });
413
+ if (link != null && ACTOR_COLLECTION_PROPERTIES.has(link.property)) {
414
+ const id = link.id == null ? null : canonicalize(link.id);
415
+ if (id == null) return fail({ type: "unknownCollectionOwner" });
416
+ candidate = {
417
+ id,
418
+ object: link.object,
419
+ acceptance: link.acceptance
420
+ };
421
+ } else if (attributedTo.length === 1) candidate = {
422
+ id: attributedTo[0],
423
+ url: top.attributedToUrls?.[0]
424
+ };
425
+ else if (attributedTo.length > 1) return fail({
426
+ type: "conflictingCollectionOwners",
427
+ candidates: attributedTo.map(toUrl)
428
+ });
429
+ else return fail({ type: "unknownCollectionOwner" });
430
+ const conflict = attributedTo.find((id) => id !== candidate.id);
431
+ if (conflict != null) return fail({
432
+ type: "conflictingCollectionOwners",
433
+ candidates: [toUrl(candidate.id), toUrl(conflict)]
434
+ });
435
+ }
436
+ if ((0, _fedify_vocab_runtime.getFe34Origin)(candidate.id) !== rootOrigin) return fail({ type: "unknownCollectionOwner" });
437
+ for (const page of pages) {
438
+ if (page.origin !== rootOrigin) return fail({
439
+ type: "collectionPageMismatch",
440
+ pageId: page.url,
441
+ collectionId: toUrl(rootId),
442
+ partOf: null
443
+ });
444
+ if (page.partOf == null) return fail({ type: "unknownCollectionOwner" });
445
+ const partOf = page.partOf.find((id) => id !== rootId);
446
+ if (partOf != null) return fail({
447
+ type: "collectionPageMismatch",
448
+ pageId: page.url,
449
+ collectionId: toUrl(rootId),
450
+ partOf: toUrl(partOf)
451
+ });
452
+ if (page.attributedTo == null) return fail({ type: "unknownCollectionOwner" });
453
+ const conflict = page.attributedTo.find((id) => id !== candidate.id);
454
+ if (conflict != null) return fail({
455
+ type: "conflictingCollectionOwners",
456
+ candidates: [toUrl(candidate.id), toUrl(conflict)]
457
+ });
458
+ }
459
+ return {
460
+ rootId,
461
+ rootOrigin,
462
+ owner: state?.owner ?? null,
463
+ candidate
464
+ };
465
+ }
466
+ function getActorCollectionIds(actor) {
467
+ const ids = [];
468
+ for (const id of [
469
+ actor.inboxId,
470
+ actor.outboxId,
471
+ actor.followersId,
472
+ actor.followingId,
473
+ actor.likedId
474
+ ]) {
475
+ if (id == null) continue;
476
+ const canonical = canonicalize(id);
477
+ if (canonical != null) ids.push(canonical);
478
+ }
479
+ return ids;
480
+ }
481
+ async function fetchOwner(candidate, options) {
482
+ const documentLoader = options.documentLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)();
483
+ const contextLoader = options.contextLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)();
484
+ const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
485
+ const tracer = tracerProvider.getTracer(require_http.name, require_http.version);
486
+ let inferredGateways;
487
+ try {
488
+ const portable = (0, _fedify_vocab_runtime.fromCompatibleEf61Id)(candidate);
489
+ if (portable != null) {
490
+ inferredGateways = [new URL(candidate.origin)];
491
+ candidate = portable;
492
+ }
493
+ } catch (error) {
494
+ if (!(error instanceof TypeError)) throw error;
495
+ logger.debug("The owner {owner} of a portable collection is a malformed compatible identifier.", { owner: candidate.href });
496
+ return null;
497
+ }
498
+ const gateways = options.gateways ?? (inferredGateways != null || (0, _fedify_vocab_runtime_internal_portable_dereference.getPortableGatewayCandidates)(candidate).length > 0 ? void 0 : options.gatewayHints);
499
+ if (options.gateways != null) inferredGateways = void 0;
500
+ const span = tracer.startSpan("activitypub.lookup_object");
501
+ try {
502
+ const object = await (0, _fedify_vocab_runtime_internal_portable_dereference.dereferencePortableIri)(candidate, {
503
+ documentLoader,
504
+ contextLoader,
505
+ tracerProvider,
506
+ gateways,
507
+ ...inferredGateways == null ? {} : { inferredGateways },
508
+ verifyPortableObject: (document, verifierOptions) => require_http.verifyPortableObjectProof(document, {
509
+ ...options,
510
+ ...verifierOptions
511
+ }),
512
+ suppressError: true,
513
+ span,
514
+ parse: (document, parseOptions) => _fedify_vocab.Object.fromJsonLd(document, {
515
+ documentLoader,
516
+ contextLoader: parseOptions.contextLoader,
517
+ tracerProvider,
518
+ baseUrl: parseOptions.baseUrl
519
+ })
520
+ });
521
+ return (0, _fedify_vocab.isActor)(object) ? object : null;
522
+ } catch (error) {
523
+ logger.debug("Failed to fetch the owner {owner} of a portable collection: {error}", {
524
+ owner: (0, _fedify_vocab_runtime.formatIri)(candidate),
525
+ error
526
+ });
527
+ return null;
528
+ } finally {
529
+ span.end();
530
+ }
531
+ }
532
+ async function resolveOwner(chain, options) {
533
+ if (chain.owner != null) return chain.owner;
534
+ const { candidate } = chain;
535
+ const candidateUrl = toUrl(candidate.id);
536
+ let actor = null;
537
+ if (candidate.acceptance === "verified" && (0, _fedify_vocab.isActor)(candidate.object) && candidate.object.id != null && canonicalize(candidate.object.id) === candidate.id) actor = candidate.object;
538
+ else actor = await fetchOwner(candidate.url ?? (candidate.object instanceof _fedify_vocab.Object && candidate.object.id != null ? candidate.object.id : candidateUrl), options);
539
+ if (actor == null || actor.id == null) return fail({
540
+ type: "collectionOwnerUnavailable",
541
+ owner: candidateUrl
542
+ });
543
+ const gateways = actor.gateways;
544
+ if (gateways.length < 1) return fail({
545
+ type: "collectionOwnerUnavailable",
546
+ owner: candidateUrl
547
+ });
548
+ if (!getActorCollectionIds(actor).includes(chain.rootId)) return fail({
549
+ type: "collectionNotListedByOwner",
550
+ owner: candidateUrl,
551
+ collectionId: toUrl(chain.rootId)
552
+ });
553
+ return {
554
+ id: candidateUrl,
555
+ gateways
556
+ };
557
+ }
558
+ function getSourceGateway(node, documentUrl) {
559
+ if (documentUrl == null || documentUrl.protocol !== "http:" && documentUrl.protocol !== "https:") return null;
560
+ let portableId;
561
+ try {
562
+ portableId = (0, _fedify_vocab_runtime.fromCompatibleEf61Id)(documentUrl);
563
+ } catch (error) {
564
+ if (error instanceof TypeError) return null;
565
+ throw error;
566
+ }
567
+ if (portableId == null || canonicalize(portableId) !== node.id) return null;
568
+ return new URL(documentUrl.origin);
569
+ }
570
+ /**
571
+ * Applies the [FEP-ef61] trust policy to a portable object fetched through
572
+ * a gateway.
573
+ *
574
+ * Portable actors, activities, objects, and collections with proofs are
575
+ * verified by {@link verifyPortableObjectProof}. A portable collection or
576
+ * collection page without a proof is accepted only if all of the following
577
+ * hold:
578
+ *
579
+ * - It was retrieved from a gateway: its final URL (`documentUrl`) is
580
+ * a compatible identifier for the same portable collection.
581
+ * - Its owner is determined unambiguously: the actor whose `inbox`,
582
+ * `outbox`, `followers`, `following`, or `liked` property referred to
583
+ * the collection, or the single actor in its `attributedTo`. A page
584
+ * inherits the owner of the collection it was reached from through
585
+ * `first`, `last`, `current`, `next`, or `prev`, and must not name
586
+ * another collection in `partOf`.
587
+ * - The owner's actor document is verified by its proof and lists the
588
+ * collection as its `inbox`, `outbox`, `followers`, `following`, or
589
+ * `liked`.
590
+ * - The gateway that served the collection is in the owner's `gateways`.
591
+ *
592
+ * Where the document came from and which object referred to it are passed
593
+ * by property accessors when this function is used as their
594
+ * `verifyPortableObject` option. Objects embedded in an unsecured
595
+ * collection accepted this way are not trusted: accessors dereference and
596
+ * verify them one by one.
597
+ *
598
+ * Note that acceptance through the gateway policy does not verify anything
599
+ * cryptographically; it only means that the owner trusts the gateway.
600
+ *
601
+ * [FEP-ef61]: https://w3id.org/fep/ef61
602
+ *
603
+ * @param jsonLd The JSON-LD document to verify.
604
+ * @param options Additional options. See also
605
+ * {@link VerifyPortableObjectOptions}.
606
+ * @returns The detailed result.
607
+ * @throws {TypeError} If the input is not a single JSON-LD object or has a
608
+ * malformed portable ID.
609
+ * @since 2.4.0
610
+ */
611
+ async function verifyPortableObject(jsonLd, options = {}) {
612
+ const { result, root, objectType } = await require_http.verifyPortableObjectProofWithRoot(jsonLd, options);
613
+ if (result.verified) {
614
+ const node = objectType === "collection" && root != null ? describeRoot(root) : null;
615
+ const chain = node == null ? null : resolveChain(node, options.referrer);
616
+ if (chain == null || !("rootId" in chain)) return {
617
+ verified: true,
618
+ method: "proof",
619
+ keys: result.keys
620
+ };
621
+ return {
622
+ verified: true,
623
+ method: "proof",
624
+ keys: result.keys,
625
+ collectionContext: createContext({
626
+ rootId: chain.rootId,
627
+ rootOrigin: chain.rootOrigin,
628
+ owner: chain.owner,
629
+ ownerCandidate: chain.candidate
630
+ })
631
+ };
632
+ }
633
+ if (result.reason.type !== "unsecuredCollection") return {
634
+ verified: false,
635
+ reason: result.reason
636
+ };
637
+ const node = root == null ? null : describeRoot(root);
638
+ if (node == null) return fail({ type: "unknownCollectionOwner" });
639
+ const gateway = getSourceGateway(node, options.documentUrl);
640
+ if (gateway == null) return fail({
641
+ type: "unknownCollectionSource",
642
+ documentUrl: options.documentUrl ?? null
643
+ });
644
+ const chain = resolveChain(node, options.referrer);
645
+ if (!("rootId" in chain)) return chain;
646
+ const owner = await resolveOwner(chain, options);
647
+ if (!("gateways" in owner)) return owner;
648
+ if (!owner.gateways.some((g) => g.origin === gateway.origin)) return fail({
649
+ type: "untrustedGateway",
650
+ owner: owner.id,
651
+ gateway,
652
+ gateways: owner.gateways
653
+ });
654
+ return {
655
+ verified: true,
656
+ method: "gateway",
657
+ unsecured: true,
658
+ owner: owner.id,
659
+ gateway,
660
+ collectionContext: createContext({
661
+ rootId: chain.rootId,
662
+ rootOrigin: chain.rootOrigin,
663
+ owner,
664
+ ownerCandidate: null
665
+ })
666
+ };
667
+ }
668
+ //#endregion
669
+ Object.defineProperty(exports, "doesActorOwnKey", {
670
+ enumerable: true,
671
+ get: function() {
672
+ return doesActorOwnKey;
673
+ }
674
+ });
675
+ Object.defineProperty(exports, "getKeyOwner", {
676
+ enumerable: true,
677
+ get: function() {
678
+ return getKeyOwner;
679
+ }
680
+ });
681
+ Object.defineProperty(exports, "verifyPortableObject", {
682
+ enumerable: true,
683
+ get: function() {
684
+ return verifyPortableObject;
685
+ }
686
+ });