@fedify/fedify 2.5.0-dev.2664 → 2.5.0-dev.2710

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 (266) hide show
  1. package/dist/compat/mod.d.cts +1 -1
  2. package/dist/compat/mod.d.ts +1 -1
  3. package/dist/{context-xrqq4Hrq.d.ts → context-CuLvR1Os.d.ts} +2 -2
  4. package/dist/{context-C1NqcIct.d.cts → context-apq0IBg2.d.cts} +2 -2
  5. package/dist/federation/mod.cjs +1 -1
  6. package/dist/federation/mod.d.cts +3 -3
  7. package/dist/federation/mod.d.ts +3 -3
  8. package/dist/federation/mod.js +1 -1
  9. package/dist/{federation-FbwcnRHg.cjs → federation-JvzYDx0P.cjs} +5 -5
  10. package/dist/{http-DbvOPsFZ.cjs → http-BG5cDmTS.cjs} +1 -1
  11. package/dist/{http-CWn0K5jD.js → http-MUf125Jc.js} +1 -1
  12. package/dist/{key-dwwAg5bA.d.ts → key-BZw-YiK5.d.ts} +2 -2
  13. package/dist/{key-DlHT4R6k.d.cts → key-D5fbQkKM.d.cts} +2 -2
  14. package/dist/{kv-cache-B-fOrhb-.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  15. package/dist/{kv-cache-BC837EqC.js → kv-cache-CbWc1BZA.js} +1 -1
  16. package/dist/{ld-CWVpo_NM.d.cts → ld-DEi9ERHf.d.cts} +1 -1
  17. package/dist/{ld-o4LnhCYY.d.ts → ld-DlC78ioJ.d.ts} +1 -1
  18. package/dist/{middleware-n2UrG62B.js → middleware-DzzdJ7Wz.js} +5 -5
  19. package/dist/{mod-D22ZsiKi.d.ts → mod-BJRtsw7l.d.ts} +1 -1
  20. package/dist/{mod-C1nT74IG.d.cts → mod-BamwZjJx.d.cts} +1 -1
  21. package/dist/{mod-DO0epJGH.d.ts → mod-BkTi19dI.d.ts} +1 -1
  22. package/dist/{mod-CQC9xlLZ.d.ts → mod-CMtF0VVy.d.ts} +1 -1
  23. package/dist/{mod-YvA4Rk8J.d.cts → mod-D2Z9MiCm.d.cts} +1 -1
  24. package/dist/{mod-TwiQgEf3.d.cts → mod-DB2NOzQF.d.cts} +1 -1
  25. package/dist/mod.cjs +4 -4
  26. package/dist/mod.d.cts +6 -6
  27. package/dist/mod.d.ts +6 -6
  28. package/dist/mod.js +4 -4
  29. package/dist/{portable-collection-DQhIkX5a.js → portable-collection-CAer9RWN.js} +1 -1
  30. package/dist/{portable-collection-DseoiPPj.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  31. package/dist/sig/mod.cjs +2 -2
  32. package/dist/sig/mod.d.cts +3 -3
  33. package/dist/sig/mod.d.ts +3 -3
  34. package/dist/sig/mod.js +2 -2
  35. package/dist/utils/mod.cjs +1 -1
  36. package/dist/utils/mod.d.cts +1 -1
  37. package/dist/utils/mod.d.ts +1 -1
  38. package/dist/utils/mod.js +1 -1
  39. package/package.json +22 -9
  40. package/skills/fedify/SKILL.md +10 -0
  41. package/dist/accept-CPVqki78.mjs +0 -145
  42. package/dist/activity-listener-CELFAodc.mjs +0 -44
  43. package/dist/assert-D1Eafmd_.mjs +0 -23
  44. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  45. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  46. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  47. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  48. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  49. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  50. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  51. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  52. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  53. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  54. package/dist/audience-CHQ-FlLD.mjs +0 -95
  55. package/dist/builder-CGJ-NXcZ.mjs +0 -911
  56. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  57. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  58. package/dist/client-5SIFzW3q.mjs +0 -441
  59. package/dist/codec-C6rTrpIp.mjs +0 -147
  60. package/dist/collection-CnnP1UAv.mjs +0 -44
  61. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  62. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  63. package/dist/compat/public-audience.test.d.mts +0 -2
  64. package/dist/compat/public-audience.test.mjs +0 -187
  65. package/dist/compat/secured-document.test.d.mts +0 -2
  66. package/dist/compat/secured-document.test.mjs +0 -58
  67. package/dist/compat/transformers.test.d.mts +0 -2
  68. package/dist/compat/transformers.test.mjs +0 -62
  69. package/dist/compound-proof-CnzwOddk.mjs +0 -1019
  70. package/dist/context-LgGFFSz7.mjs +0 -146
  71. package/dist/deno-eoFpPk7W.mjs +0 -8
  72. package/dist/dist-_geWsuaI.mjs +0 -189
  73. package/dist/docloader-DwkipyL1.mjs +0 -136
  74. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  75. package/dist/exporter-DVG68ozH.mjs +0 -263
  76. package/dist/federation/audience.test.d.mts +0 -2
  77. package/dist/federation/audience.test.mjs +0 -130
  78. package/dist/federation/builder.test.d.mts +0 -2
  79. package/dist/federation/builder.test.mjs +0 -396
  80. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  81. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  82. package/dist/federation/collection.test.d.mts +0 -2
  83. package/dist/federation/collection.test.mjs +0 -21
  84. package/dist/federation/compound-fanout.test.d.mts +0 -2
  85. package/dist/federation/compound-fanout.test.mjs +0 -231
  86. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  87. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  88. package/dist/federation/handler.test.d.mts +0 -2
  89. package/dist/federation/handler.test.mjs +0 -5445
  90. package/dist/federation/hashlink-media.test.d.mts +0 -2
  91. package/dist/federation/hashlink-media.test.mjs +0 -422
  92. package/dist/federation/idempotency.test.d.mts +0 -2
  93. package/dist/federation/idempotency.test.mjs +0 -207
  94. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  95. package/dist/federation/inbox-actorless.test.mjs +0 -522
  96. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  97. package/dist/federation/inbox-authentication.test.mjs +0 -220
  98. package/dist/federation/inbox-report.test.d.mts +0 -2
  99. package/dist/federation/inbox-report.test.mjs +0 -719
  100. package/dist/federation/inbox-view.test.d.mts +0 -2
  101. package/dist/federation/inbox-view.test.mjs +0 -369
  102. package/dist/federation/inbox.test.d.mts +0 -2
  103. package/dist/federation/inbox.test.mjs +0 -139
  104. package/dist/federation/keycache.test.d.mts +0 -2
  105. package/dist/federation/keycache.test.mjs +0 -337
  106. package/dist/federation/kv.test.d.mts +0 -2
  107. package/dist/federation/kv.test.mjs +0 -88
  108. package/dist/federation/metrics.test.d.mts +0 -2
  109. package/dist/federation/metrics.test.mjs +0 -634
  110. package/dist/federation/middleware.test.d.mts +0 -2
  111. package/dist/federation/middleware.test.mjs +0 -9314
  112. package/dist/federation/mq.test.d.mts +0 -2
  113. package/dist/federation/mq.test.mjs +0 -591
  114. package/dist/federation/negotiation.test.d.mts +0 -2
  115. package/dist/federation/negotiation.test.mjs +0 -18
  116. package/dist/federation/outbound-body.test.d.mts +0 -2
  117. package/dist/federation/outbound-body.test.mjs +0 -149
  118. package/dist/federation/outbound-capture.test.d.mts +0 -2
  119. package/dist/federation/outbound-capture.test.mjs +0 -394
  120. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  121. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  122. package/dist/federation/outbound-document.test.d.mts +0 -2
  123. package/dist/federation/outbound-document.test.mjs +0 -171
  124. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  125. package/dist/federation/outbound-provenance.test.mjs +0 -543
  126. package/dist/federation/outbound-report.test.d.mts +0 -2
  127. package/dist/federation/outbound-report.test.mjs +0 -5475
  128. package/dist/federation/outbound-workers.test.d.mts +0 -2
  129. package/dist/federation/outbound-workers.test.mjs +0 -64
  130. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  131. package/dist/federation/outbound-workflow.test.mjs +0 -154
  132. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  133. package/dist/federation/outgoing-proof.test.mjs +0 -933
  134. package/dist/federation/portable-actor.test.d.mts +0 -2
  135. package/dist/federation/portable-actor.test.mjs +0 -496
  136. package/dist/federation/portable-chain.test.d.mts +0 -2
  137. package/dist/federation/portable-chain.test.mjs +0 -370
  138. package/dist/federation/portable-collection.test.d.mts +0 -2
  139. package/dist/federation/portable-collection.test.mjs +0 -832
  140. package/dist/federation/portable-delivery.test.d.mts +0 -2
  141. package/dist/federation/portable-delivery.test.mjs +0 -845
  142. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  143. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  144. package/dist/federation/portable-inbox.test.d.mts +0 -2
  145. package/dist/federation/portable-inbox.test.mjs +0 -1960
  146. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  147. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  148. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  149. package/dist/federation/portable-route-activity.test.mjs +0 -259
  150. package/dist/federation/portable.test.d.mts +0 -2
  151. package/dist/federation/portable.test.mjs +0 -1072
  152. package/dist/federation/retry.test.d.mts +0 -2
  153. package/dist/federation/retry.test.mjs +0 -42
  154. package/dist/federation/router.test.d.mts +0 -2
  155. package/dist/federation/router.test.mjs +0 -123
  156. package/dist/federation/send.test.d.mts +0 -2
  157. package/dist/federation/send.test.mjs +0 -1421
  158. package/dist/federation/tasks/codec.test.d.mts +0 -2
  159. package/dist/federation/tasks/codec.test.mjs +0 -302
  160. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  161. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  162. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  163. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  164. package/dist/federation/temporal.test.d.mts +0 -2
  165. package/dist/federation/temporal.test.mjs +0 -71
  166. package/dist/federation/webfinger.test.d.mts +0 -2
  167. package/dist/federation/webfinger.test.mjs +0 -944
  168. package/dist/http-l1zKGCll.mjs +0 -1449
  169. package/dist/inbox-CWX3EBTO.mjs +0 -399
  170. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  171. package/dist/inbox-view-DkPCF71K.mjs +0 -385
  172. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  173. package/dist/keycache-N2opu4-3.mjs +0 -221
  174. package/dist/keys-DIJNHW-Y.mjs +0 -120
  175. package/dist/kv-DBRWVx3Q.mjs +0 -104
  176. package/dist/kv-DCHkaJ9-.mjs +0 -92
  177. package/dist/kv-cache-8eJh4Xum.mjs +0 -121
  178. package/dist/ld-Cdt8qD-r.mjs +0 -1752
  179. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  180. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  181. package/dist/metrics-BnfvSPj9.mjs +0 -818
  182. package/dist/middleware-CwnXJze2.mjs +0 -5
  183. package/dist/middleware-D_W_LdJN.mjs +0 -9971
  184. package/dist/mq-eF96QxUT.mjs +0 -288
  185. package/dist/negotiation-BAKO9nih.mjs +0 -96
  186. package/dist/nodeinfo/client.test.d.mts +0 -2
  187. package/dist/nodeinfo/client.test.mjs +0 -1364
  188. package/dist/nodeinfo/handler.test.d.mts +0 -2
  189. package/dist/nodeinfo/handler.test.mjs +0 -94
  190. package/dist/nodeinfo/types.test.d.mts +0 -2
  191. package/dist/nodeinfo/types.test.mjs +0 -192
  192. package/dist/otel/exporter.test.d.mts +0 -2
  193. package/dist/otel/exporter.test.mjs +0 -887
  194. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  195. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  196. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  197. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  198. package/dist/owner-DukEQnv3.mjs +0 -267
  199. package/dist/portable-collection-OHaqa11n.mjs +0 -418
  200. package/dist/portable-key-BkOLJxVz.mjs +0 -549
  201. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  202. package/dist/proof-Y7omSVvc.mjs +0 -1420
  203. package/dist/public-audience--klBIOk1.mjs +0 -197
  204. package/dist/retry-zX5xw5e0.mjs +0 -34
  205. package/dist/router-u5O5KCQr.mjs +0 -156
  206. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  207. package/dist/send-ccQynabr.mjs +0 -710
  208. package/dist/sig/accept.test.d.mts +0 -2
  209. package/dist/sig/accept.test.mjs +0 -416
  210. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  211. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  212. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  213. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  214. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  215. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  216. package/dist/sig/compound-proof.test.d.mts +0 -2
  217. package/dist/sig/compound-proof.test.mjs +0 -411
  218. package/dist/sig/http.test.d.mts +0 -2
  219. package/dist/sig/http.test.mjs +0 -3328
  220. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  221. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  222. package/dist/sig/key.test.d.mts +0 -2
  223. package/dist/sig/key.test.mjs +0 -1250
  224. package/dist/sig/ld.test.d.mts +0 -2
  225. package/dist/sig/ld.test.mjs +0 -1044
  226. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  227. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  228. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  229. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  230. package/dist/sig/owner.test.d.mts +0 -2
  231. package/dist/sig/owner.test.mjs +0 -202
  232. package/dist/sig/portable-collection.test.d.mts +0 -2
  233. package/dist/sig/portable-collection.test.mjs +0 -697
  234. package/dist/sig/portable-interop.test.d.mts +0 -2
  235. package/dist/sig/portable-interop.test.mjs +0 -156
  236. package/dist/sig/portable-key-id.test.d.mts +0 -2
  237. package/dist/sig/portable-key-id.test.mjs +0 -67
  238. package/dist/sig/portable-key.test.d.mts +0 -2
  239. package/dist/sig/portable-key.test.mjs +0 -1438
  240. package/dist/sig/proof.test.d.mts +0 -2
  241. package/dist/sig/proof.test.mjs +0 -2638
  242. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  243. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  244. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  245. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  246. package/dist/sig/verification.test.d.mts +0 -2
  247. package/dist/sig/verification.test.mjs +0 -310
  248. package/dist/std__assert-DvMDRPes.mjs +0 -8
  249. package/dist/tasks-BCUmQbbz.mjs +0 -77
  250. package/dist/temporal-f_K4lAVR.mjs +0 -95
  251. package/dist/testing/context.test.d.mts +0 -2
  252. package/dist/testing/context.test.mjs +0 -19
  253. package/dist/testing/kv.test.d.mts +0 -2
  254. package/dist/testing/kv.test.mjs +0 -101
  255. package/dist/testing/mod.d.mts +0 -6099
  256. package/dist/testing/mod.mjs +0 -9
  257. package/dist/testing-vrnD5Uaa.mjs +0 -8
  258. package/dist/types-DE_LV1JB.mjs +0 -46
  259. package/dist/utils/docloader.test.d.mts +0 -2
  260. package/dist/utils/docloader.test.mjs +0 -1076
  261. package/dist/utils/kv-cache.test.d.mts +0 -2
  262. package/dist/utils/kv-cache.test.mjs +0 -261
  263. package/dist/verification-C3954hQh.mjs +0 -5
  264. package/dist/verification-Dpfcw8ml.mjs +0 -105
  265. package/dist/vocab/cjs.test.d.mts +0 -2
  266. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,385 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { c as getNormalizationContextLoader, p as markEffectiveContextLoader, s as detachSignature, y as wrapContextLoaderForJsonLd } from "./ld-Cdt8qD-r.mjs";
5
- import { preloadedContexts } from "@fedify/vocab-runtime";
6
- import { encodeHex } from "byte-encodings/hex";
7
- import jsonld from "@fedify/vocab-runtime/jsonld";
8
- import serialize from "json-canon";
9
- //#region src/federation/inbox-view.ts
10
- /**
11
- * The interpretation of an incoming activity that Fedify authenticated, kept
12
- * so that listeners, authorization helpers, and queue workers observe the
13
- * same JSON-LD meaning that signature verification observed.
14
- *
15
- * Every JSON-LD processing step of one delivery goes through a request-scoped
16
- * *context snapshot*, which memoizes the remote context responses so that
17
- * a nondeterministic or mutable remote context cannot give verification and
18
- * dispatch different meanings. The snapshot is serialized into queued
19
- * messages, so that workers and retries replay the very same responses
20
- * without loading contexts again.
21
- * @module
22
- */
23
- /**
24
- * Thrown when replaying an interpretation needs a context response that its
25
- * snapshot does not have, or has with a different content.
26
- * @internal
27
- */
28
- var ContextSnapshotMissError = class extends Error {
29
- url;
30
- constructor(url, reason) {
31
- super(`Context ${url} cannot be replayed: ${reason}.`);
32
- this.name = "ContextSnapshotMissError";
33
- this.url = url;
34
- }
35
- };
36
- function normalizeUrl(url) {
37
- return URL.canParse(url) ? new URL(url).href : url;
38
- }
39
- /**
40
- * Creates the context snapshot of a delivery.
41
- * @param base The caller's context loader.
42
- * @returns The snapshot.
43
- * @internal
44
- */
45
- function createContextSnapshot(base) {
46
- const underlying = {
47
- standard: wrapContextLoaderForJsonLd(base),
48
- normalization: getNormalizationContextLoader(base)
49
- };
50
- const cache = /* @__PURE__ */ new Map();
51
- const recorded = /* @__PURE__ */ new Map();
52
- const loaders = /* @__PURE__ */ new Map();
53
- let released = false;
54
- return {
55
- loader(policy) {
56
- let loader = loaders.get(policy);
57
- if (loader != null) return loader;
58
- const effective = underlying[policy];
59
- loader = markEffectiveContextLoader(async (url, options) => {
60
- if (released) return await effective(url, options);
61
- const normalizedUrl = normalizeUrl(url);
62
- const key = `${policy}\n${normalizedUrl}`;
63
- let promise = cache.get(key);
64
- if (promise == null) {
65
- promise = Promise.resolve(effective(url, options)).then((response) => {
66
- const cloned = normalizeResponse(structuredClone(response));
67
- recorded.set(key, {
68
- policy,
69
- url: normalizedUrl,
70
- response: structuredClone(cloned)
71
- });
72
- return cloned;
73
- });
74
- promise.catch(() => {});
75
- cache.set(key, promise);
76
- }
77
- return structuredClone(await promise);
78
- }, policy);
79
- loaders.set(policy, loader);
80
- return loader;
81
- },
82
- entries() {
83
- return [...recorded.values()];
84
- },
85
- release() {
86
- released = true;
87
- }
88
- };
89
- }
90
- function getBundledResponse(url) {
91
- if (!(url in preloadedContexts)) return null;
92
- return {
93
- contextUrl: null,
94
- document: preloadedContexts[url],
95
- documentUrl: url
96
- };
97
- }
98
- async function sha256(value) {
99
- return encodeHex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(serialize(value))));
100
- }
101
- function normalizeResponse(response) {
102
- return {
103
- contextUrl: response.contextUrl ?? null,
104
- document: response.document,
105
- documentUrl: response.documentUrl
106
- };
107
- }
108
- /**
109
- * Serializes the entries of a context snapshot for a queued message.
110
- * @param entries The entries.
111
- * @returns The serialized entries, which are plain JSON values.
112
- * @internal
113
- */
114
- async function serializeContextSnapshot(entries) {
115
- const result = [];
116
- for (const entry of entries) {
117
- const response = normalizeResponse(entry.response);
118
- const hash = await sha256(response);
119
- const bundled = getBundledResponse(entry.url);
120
- if (bundled != null && await sha256(bundled) === hash) result.push({
121
- policy: entry.policy,
122
- url: entry.url,
123
- sha256: hash,
124
- bundled: true
125
- });
126
- else result.push({
127
- policy: entry.policy,
128
- url: entry.url,
129
- sha256: hash,
130
- response: structuredClone(response)
131
- });
132
- }
133
- return result;
134
- }
135
- function isRemoteDocument(value) {
136
- if (value == null || typeof value !== "object") return false;
137
- const record = value;
138
- return typeof record.documentUrl === "string" && "document" in record && (record.contextUrl == null || typeof record.contextUrl === "string");
139
- }
140
- /**
141
- * Restores the entries of a serialized context snapshot, verifying the
142
- * hashes of stored responses. Bundled entries are reconstructed from the
143
- * contexts this version of Fedify bundles.
144
- * @param entries The serialized entries.
145
- * @returns The entries.
146
- * @throws {ContextSnapshotMissError} If an entry is malformed, or its
147
- * content does not match its hash.
148
- * @internal
149
- */
150
- async function deserializeContextSnapshot(entries) {
151
- if (!Array.isArray(entries)) throw new ContextSnapshotMissError("(snapshot)", "malformed snapshot");
152
- const result = [];
153
- for (const entry of entries) {
154
- if (entry == null || typeof entry !== "object" || entry.policy !== "standard" && entry.policy !== "normalization" || typeof entry.url !== "string" || typeof entry.sha256 !== "string") throw new ContextSnapshotMissError("(snapshot)", "malformed entry");
155
- let response;
156
- if (entry.bundled === true) {
157
- response = getBundledResponse(entry.url);
158
- if (response == null) throw new ContextSnapshotMissError(entry.url, "not bundled");
159
- } else if (isRemoteDocument(entry.response)) response = normalizeResponse(entry.response);
160
- else throw new ContextSnapshotMissError(entry.url, "malformed entry");
161
- if (entry.bundled !== true && await sha256(response) !== entry.sha256) throw new ContextSnapshotMissError(entry.url, "content mismatch");
162
- result.push({
163
- policy: entry.policy,
164
- url: entry.url,
165
- response: structuredClone(response)
166
- });
167
- }
168
- return result;
169
- }
170
- /**
171
- * Creates a context loader of a policy that serves only the responses of
172
- * a snapshot. It is marked as the effective loader of the policy.
173
- * @param entries The snapshot's entries.
174
- * @param policy The policy.
175
- * @returns The loader, which throws {@link ContextSnapshotMissError} for
176
- * anything else.
177
- * @internal
178
- */
179
- function createSnapshotOnlyLoader(entries, policy) {
180
- const responses = /* @__PURE__ */ new Map();
181
- for (const entry of entries) if (entry.policy === policy) responses.set(entry.url, entry.response);
182
- return markEffectiveContextLoader(async (url) => {
183
- const response = responses.get(normalizeUrl(url));
184
- if (response == null) throw new ContextSnapshotMissError(url, "not in the snapshot");
185
- return structuredClone(response);
186
- }, policy);
187
- }
188
- /**
189
- * Creates a {@link ReleasableLoader}.
190
- * @param strict The loader to use until release.
191
- * @param fallback The loader to use after release.
192
- * @param policy The policy both loaders apply.
193
- * @returns The releasable loader.
194
- * @internal
195
- */
196
- function createReleasableLoader(strict, fallback, policy) {
197
- let released = false;
198
- return {
199
- loader: markEffectiveContextLoader((url, options) => released ? fallback(url, options) : strict(url, options), policy),
200
- release() {
201
- released = true;
202
- }
203
- };
204
- }
205
- /**
206
- * Expands a JSON-LD document with the given context loader.
207
- * @param document The document.
208
- * @param contextLoader The context loader.
209
- * @returns The expanded document.
210
- * @internal
211
- */
212
- async function expandDocument(document, contextLoader) {
213
- return await jsonld.expand(document, { documentLoader: contextLoader });
214
- }
215
- /**
216
- * Computes the digest of an expanded document.
217
- * @param expanded The expanded document.
218
- * @returns The hex-encoded SHA-256 of its canonical JSON.
219
- * @internal
220
- */
221
- function digestExpandedDocument(expanded) {
222
- return sha256(expanded);
223
- }
224
- /**
225
- * Deeply freezes a JSON value.
226
- * @param value The value.
227
- * @returns The same value, frozen.
228
- * @internal
229
- */
230
- function deepFreeze(value) {
231
- if (value != null && typeof value === "object" && !Object.isFrozen(value)) {
232
- Object.freeze(value);
233
- for (const child of Object.values(value)) deepFreeze(child);
234
- }
235
- return value;
236
- }
237
- const ACTOR_IRI = "https://www.w3.org/ns/activitystreams#actor";
238
- /**
239
- * Gets the single root node of an expanded document.
240
- * @param expanded The expanded document.
241
- * @returns The root node, or `null` if there is not exactly one.
242
- * @internal
243
- */
244
- function getRootNode(expanded) {
245
- if (expanded.length !== 1) return null;
246
- const node = expanded[0];
247
- if (node == null || typeof node !== "object" || Array.isArray(node)) return null;
248
- return node;
249
- }
250
- /**
251
- * Gets the values of a property of an expanded node, unwrapping a single
252
- * `@list` container the way generated vocabulary decoders do.
253
- * @param node The expanded node.
254
- * @param iri The property IRI.
255
- * @returns The values, or an empty array if the property is absent.
256
- * @internal
257
- */
258
- function getPropertyValues(node, iri) {
259
- const values = node[iri];
260
- if (values == null) return [];
261
- if (!Array.isArray(values)) return [values];
262
- if (values.length === 1 && values[0] != null && typeof values[0] === "object" && "@list" in values[0]) {
263
- const list = values[0]["@list"];
264
- return Array.isArray(list) ? list : [list];
265
- }
266
- return values;
267
- }
268
- /**
269
- * Tells whether the root node of an expanded activity declares any `actor`
270
- * value at all, including blank nodes, anonymous or untyped nodes, and
271
- * literals, which ID accessors and typed parsing may drop.
272
- * @param expanded The expanded activity.
273
- * @returns `"absent"` if the root node declares no actor; `"present"`
274
- * otherwise, including when there is no single root node.
275
- * @internal
276
- */
277
- function getActorPresence(expanded) {
278
- const root = getRootNode(expanded);
279
- if (root == null) return "present";
280
- return getPropertyValues(root, ACTOR_IRI).length < 1 ? "absent" : "present";
281
- }
282
- /**
283
- * Builds the serialized view of an authenticated activity. The document is
284
- * expanded through the snapshot, so that the snapshot holds every context
285
- * response the interpretation needs.
286
- * @param snapshot The delivery's context snapshot.
287
- * @param source Which document the activity was parsed from.
288
- * @returns The serialized view and the expanded activity.
289
- * @internal
290
- */
291
- async function buildVerifiedActivityView(snapshot, source) {
292
- const loader = snapshot.loader(source.policy);
293
- const used = /* @__PURE__ */ new Set();
294
- const expanded = await expandDocument(source.document, markEffectiveContextLoader((url, options) => {
295
- used.add(normalizeUrl(url));
296
- return loader(url, options);
297
- }, source.policy));
298
- const entries = snapshot.entries().filter((entry) => entry.policy === source.policy && used.has(entry.url));
299
- const contexts = await serializeContextSnapshot(entries);
300
- const references = /* @__PURE__ */ new Set();
301
- collectContextReferences(source.document, source.baseUrl?.href, references);
302
- for (const entry of entries) {
303
- const { contextUrl, document } = entry.response;
304
- collectContextReferences(document, entry.url, references);
305
- if (contextUrl != null) collectContextReferences({ "@context": contextUrl }, entry.url, references);
306
- }
307
- return {
308
- replayable: [...references].every((url) => used.has(url)),
309
- view: {
310
- version: 1,
311
- policy: source.policy,
312
- source: source.source,
313
- baseUrl: source.baseUrl?.href ?? null,
314
- contexts,
315
- expandedDigest: await digestExpandedDocument(expanded)
316
- },
317
- expanded
318
- };
319
- }
320
- /**
321
- * Collects the remote context references of a JSON-LD document or context
322
- * document: every IRI given as a value of `@context` at any depth, including
323
- * scoped contexts of term definitions, and of `@import`.
324
- * @param value The document.
325
- * @param base The URL to resolve relative references against.
326
- * @param references The set to add the normalized references to.
327
- */
328
- function collectContextReferences(value, base, references) {
329
- const add = (reference) => {
330
- let url = reference;
331
- if (base != null && URL.canParse(reference, base)) url = new URL(reference, base).href;
332
- references.add(normalizeUrl(url));
333
- };
334
- const collectContext = (context) => {
335
- if (typeof context === "string") add(context);
336
- else if (Array.isArray(context)) for (const item of context) collectContext(item);
337
- else if (context != null && typeof context === "object") {
338
- const imported = context["@import"];
339
- if (typeof imported === "string") add(imported);
340
- walk(context);
341
- }
342
- };
343
- const walk = (node) => {
344
- if (Array.isArray(node)) for (const item of node) walk(item);
345
- else if (node != null && typeof node === "object") for (const [key, item] of Object.entries(node)) if (key === "@context") collectContext(item);
346
- else walk(item);
347
- };
348
- walk(value);
349
- }
350
- /**
351
- * Validates the shape of a serialized view taken from a queued message.
352
- * @param value The value of the message's `verifiedView` field.
353
- * @returns The view, or `null` if it is malformed or of an unsupported
354
- * version.
355
- * @internal
356
- */
357
- function parseSerializedVerifiedActivityView(value) {
358
- if (value == null || typeof value !== "object") return null;
359
- const view = value;
360
- if (view.version !== 1 || view.policy !== "standard" && view.policy !== "normalization" || view.source !== "activity" && view.source !== "normalizedActivity" || view.baseUrl !== null && (typeof view.baseUrl !== "string" || !URL.canParse(view.baseUrl)) || !Array.isArray(view.contexts) || typeof view.expandedDigest !== "string") return null;
361
- return view;
362
- }
363
- /**
364
- * Restores a view from a queued message without loading any context.
365
- * @param view The serialized view.
366
- * @param message The fields of the message the view refers to.
367
- * @returns The restored view.
368
- * @throws {ContextSnapshotMissError} If the view cannot be replayed exactly.
369
- * @internal
370
- */
371
- async function restoreVerifiedActivityView(view, message) {
372
- const loader = createSnapshotOnlyLoader(await deserializeContextSnapshot(view.contexts), view.policy);
373
- if (view.source === "normalizedActivity" && message.normalizedActivity == null) throw new ContextSnapshotMissError("(normalizedActivity)", "the normalized activity is missing");
374
- const document = detachSignature(view.source === "activity" ? message.activity : message.normalizedActivity);
375
- const expanded = await expandDocument(document, loader);
376
- if (await digestExpandedDocument(expanded) !== view.expandedDigest) throw new ContextSnapshotMissError("(activity)", "the interpretation does not match the authenticated one");
377
- return {
378
- document,
379
- loader,
380
- expanded,
381
- baseUrl: view.baseUrl == null ? null : new URL(view.baseUrl)
382
- };
383
- }
384
- //#endregion
385
- export { createSnapshotOnlyLoader as a, expandDocument as c, parseSerializedVerifiedActivityView as d, restoreVerifiedActivityView as f, createReleasableLoader as i, getActorPresence as l, buildVerifiedActivityView as n, deepFreeze as o, serializeContextSnapshot as p, createContextSnapshot as r, deserializeContextSnapshot as s, ContextSnapshotMissError as t, getPropertyValues as u };
@@ -1,108 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { a as getRawCanonicalPortableId, c as isPortableActorDocument, n as getCanonicalPortableId } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { CryptographicKey, Object as Object$1 } from "@fedify/vocab";
6
- //#region src/sig/key-owner-evidence.ts
7
- /**
8
- * How long a key of an [FEP-ef61] portable actor is trusted after its actor's
9
- * signed document vouched for it, however long the proof of the document is
10
- * valid. The actor can drop the key or the gateway from its document at any
11
- * time, so the key is looked up again at least this often.
12
- *
13
- * [FEP-ef61]: https://w3id.org/fep/ef61
14
- * @internal
15
- */
16
- const MAX_PORTABLE_KEY_TTL = Temporal.Duration.from({ hours: 1 });
17
- const candidates = /* @__PURE__ */ new WeakMap();
18
- const verified = /* @__PURE__ */ new WeakMap();
19
- /**
20
- * Attaches to a key that was just resolved the evidence of the portable actor
21
- * that owns it. The evidence is not used until the key verifies
22
- * a signature; see {@link promoteKeyOwnerEvidence}.
23
- *
24
- * Nothing is attached unless the document, the key's owner, and the actor
25
- * the key ID belongs to agree on the actor's canonical portable ID.
26
- * @param key The key, whose owner the document vouched for.
27
- * @param document The expanded root node of the actor's verified document.
28
- * @param expires When the evidence must not be used anymore.
29
- * @returns Whether the evidence was attached.
30
- * @internal
31
- */
32
- function attachKeyOwnerEvidence(key, document, expires) {
33
- if (!(key instanceof CryptographicKey) || key.id == null || key.ownerId == null || key.publicKey == null || document == null || typeof document !== "object" || Array.isArray(document)) return false;
34
- const rawId = document["@id"];
35
- if (typeof rawId !== "string") return false;
36
- const keyBase = new URL(key.id.href);
37
- keyBase.hash = "";
38
- const ownerId = getCanonicalPortableId(key.ownerId);
39
- if (ownerId == null || getRawCanonicalPortableId(rawId) !== ownerId || getCanonicalPortableId(keyBase) !== ownerId) return false;
40
- candidates.set(key, {
41
- keyId: key.id.href,
42
- keyOwner: key.ownerId.href,
43
- publicKey: key.publicKey,
44
- ownerId,
45
- document: structuredClone(document),
46
- expires
47
- });
48
- return true;
49
- }
50
- /**
51
- * Makes the evidence attached to a key usable, as the key has just verified
52
- * an HTTP Signature. Nothing happens if the key has no evidence.
53
- * @param key The key that verified a signature.
54
- * @internal
55
- */
56
- function promoteKeyOwnerEvidence(key) {
57
- const evidence = candidates.get(key);
58
- if (evidence == null) return;
59
- candidates.delete(key);
60
- verified.set(key, evidence);
61
- }
62
- /**
63
- * Gets the evidence of the portable actor that owns a key HTTP Signature
64
- * verification returned.
65
- * @param key The key.
66
- * @param now The current time.
67
- * @returns The evidence, or `undefined` if the key was not returned by HTTP
68
- * Signature verification, if it has no evidence, if the evidence
69
- * expired, or if the key has been changed since.
70
- * @internal
71
- */
72
- function getVerifiedKeyOwnerEvidence(key, now = Temporal.Now.instant()) {
73
- const evidence = verified.get(key);
74
- if (evidence == null) return void 0;
75
- if (Temporal.Instant.compare(now, evidence.expires) >= 0) {
76
- verified.delete(key);
77
- return;
78
- }
79
- if (key.id?.href !== evidence.keyId || key.ownerId?.href !== evidence.keyOwner || key.publicKey !== evidence.publicKey) return;
80
- return evidence;
81
- }
82
- /**
83
- * Parses the actor from the evidence, i.e., from the expansion of its
84
- * document whose proof was verified. Every call returns a new object.
85
- * @param evidence The evidence.
86
- * @param options Options for parsing the document.
87
- * @returns The actor, or `null` if the document is not the actor that
88
- * the evidence is about, or the evidence expired meanwhile.
89
- * @internal
90
- */
91
- async function parseKeyOwnerEvidence(evidence, options = {}) {
92
- const refuse = (url) => Promise.reject(/* @__PURE__ */ new Error(`Refusing to fetch ${url}.`));
93
- let actor;
94
- try {
95
- actor = await Object$1.fromJsonLd(structuredClone(evidence.document), {
96
- documentLoader: refuse,
97
- contextLoader: options.contextLoader,
98
- tracerProvider: options.tracerProvider
99
- });
100
- } catch (error) {
101
- if (!(error instanceof TypeError)) throw error;
102
- return null;
103
- }
104
- if (!isPortableActorDocument(actor) || getCanonicalPortableId(actor.id) !== evidence.ownerId || Temporal.Instant.compare(Temporal.Now.instant(), evidence.expires) >= 0) return null;
105
- return actor;
106
- }
107
- //#endregion
108
- export { promoteKeyOwnerEvidence as a, parseKeyOwnerEvidence as i, attachKeyOwnerEvidence as n, getVerifiedKeyOwnerEvidence as r, MAX_PORTABLE_KEY_TTL as t };