@fedify/fedify 2.0.0-pr.412.1559 → 2.0.0-pr.412.1794

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 (204) hide show
  1. package/README.md +3 -0
  2. package/dist/{actor-Cc6B76eG.js → actor-BXHc5r-q.js} +1 -1
  3. package/dist/actor-Ba9Z1eNJ.cjs +42079 -0
  4. package/dist/{actor-C22bXuuC.d.ts → actor-DqFajh9s.d.ts} +2 -2
  5. package/dist/{actor-CTAuCsWy.js → actor-DzhunPC_.js} +7058 -2722
  6. package/dist/actor-f2NtjyCg.d.cts +128 -0
  7. package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
  8. package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
  9. package/dist/{builder-BOEBObR8.js → builder-u7usRsT3.js} +13 -8
  10. package/dist/chunk-DqRYRqnO.cjs +34 -0
  11. package/dist/client-94iWEfQa.d.cts +222 -0
  12. package/dist/{client-DF8anIB5.d.ts → client-BsGzbnV-.d.ts} +3 -75
  13. package/dist/{client-De-z2UnN.js → client-pY7-3icS.js} +3 -22
  14. package/dist/compat/mod.cjs +10 -0
  15. package/dist/compat/mod.d.cts +12 -0
  16. package/dist/compat/mod.d.ts +11 -12
  17. package/dist/compat/mod.js +5 -5
  18. package/dist/compat/transformers.test.js +20 -20
  19. package/dist/compat-DmDDELst.cjs +4 -0
  20. package/dist/compat-nxUqe4Z-.js +4 -0
  21. package/dist/{context-9gCpIkiz.d.ts → context-DG0huGW-.d.ts} +184 -127
  22. package/dist/context-DJ8aSy2Q.d.cts +2312 -0
  23. package/dist/{authdocloader-CLgDGafZ.js → docloader-CrbAy9Oc.js} +17 -8
  24. package/dist/{esm-CHdxdkuH.js → esm-C-Qa1zEM.js} +11 -11
  25. package/dist/federation/builder.test.js +9 -12
  26. package/dist/federation/collection.test.js +7 -9
  27. package/dist/federation/handler.test.js +27 -148
  28. package/dist/federation/idempotency.test.js +201 -0
  29. package/dist/federation/inbox.test.js +4 -6
  30. package/dist/federation/keycache.test.js +3 -4
  31. package/dist/federation/kv.test.js +7 -8
  32. package/dist/federation/middleware.test.js +242 -64
  33. package/dist/federation/mod.cjs +27 -0
  34. package/dist/federation/mod.d.cts +12 -0
  35. package/dist/federation/mod.d.ts +12 -13
  36. package/dist/federation/mod.js +13 -15
  37. package/dist/federation/mq.test.js +8 -10
  38. package/dist/federation/negotiation.test.js +26 -0
  39. package/dist/federation/retry.test.js +4 -5
  40. package/dist/federation/router.test.js +6 -8
  41. package/dist/federation/send.test.js +13 -15
  42. package/dist/federation-CRpdnOMS.cjs +244 -0
  43. package/dist/{federation-CMX7WzeL.js → federation-jcR8-ZxP.js} +3 -3
  44. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  45. package/dist/{http-DqSNLFNY.d.ts → http-BbO0ejuk.d.ts} +2 -2
  46. package/dist/{http-l0TEupZK.js → http-CUVx-vzb.js} +260 -10
  47. package/dist/{http-CcdM1brU.js → http-D2kIm9la.js} +3 -3
  48. package/dist/http-Dofes42e.cjs +1106 -0
  49. package/dist/http-M8k5mKc0.d.cts +253 -0
  50. package/dist/{inbox-B6DZbGNf.js → inbox-HjG5peXY.js} +24 -7
  51. package/dist/{key-CzLv1phF.js → key-CxdLUFS6.js} +3 -2
  52. package/dist/{keycache-B8HdZJSt.js → keycache-bU7COwsh.js} +1 -1
  53. package/dist/{keys-zZwiKkfx.js → keys-DMHs8XNn.js} +2 -1
  54. package/dist/kv-Bxr0Q87_.d.cts +81 -0
  55. package/dist/kv-cache-CGXcDejL.js +122 -0
  56. package/dist/kv-cache-DN9pfMBe.js +94 -0
  57. package/dist/kv-cache-Dkvbn6rg.cjs +134 -0
  58. package/dist/{ld-CBcQdZ6N.js → ld-CIhvSCCr.js} +5 -4
  59. package/dist/lookup-CHkCVZTU.js +260 -0
  60. package/dist/lookup-CfFkONZD.cjs +272 -0
  61. package/dist/{type-SK-d7Tbw.js → lookup-DQRtjvb1.js} +7266 -7087
  62. package/dist/middleware-Bot7EEwV.js +26 -0
  63. package/dist/middleware-CFJgmUMW.cjs +15 -0
  64. package/dist/{middleware-BRgu1IH8.js → middleware-CJlj5Olw.js} +86 -181
  65. package/dist/middleware-CjHl2NHA.js +15 -0
  66. package/dist/middleware-D74TgW2E.cjs +4225 -0
  67. package/dist/{middleware-CxEkcFW0.js → middleware-DMk2Mdn9.js} +117 -127
  68. package/dist/mod-0noXw66R.d.cts +107 -0
  69. package/dist/mod-B-hUPT2N.d.cts +1 -0
  70. package/dist/{mod-Drmz72EK.d.ts → mod-B2iOw50L.d.ts} +3 -3
  71. package/dist/mod-B9M-8jm2.d.ts +109 -0
  72. package/dist/{mod-Cxt4Kpf6.d.ts → mod-BlVovdcy.d.ts} +20 -2
  73. package/dist/{mod-Bqxcp7eN.d.ts → mod-BoHnwOCs.d.ts} +2 -2
  74. package/dist/mod-BxRCHTz-.d.cts +307 -0
  75. package/dist/mod-C2tOeRkN.d.cts +1 -0
  76. package/dist/mod-C58MZ7Wx.d.cts +113 -0
  77. package/dist/mod-DJcZDvjA.d.cts +80 -0
  78. package/dist/mod-DgdBYYa0.d.cts +266 -0
  79. package/dist/{mod-DBzN0aCM.d.ts → mod-Ds0mpFZU.d.ts} +1 -1
  80. package/dist/mod.cjs +137 -0
  81. package/dist/mod.d.cts +16 -0
  82. package/dist/mod.d.ts +16 -17
  83. package/dist/mod.js +19 -21
  84. package/dist/mq-DcJPkXD5.d.cts +140 -0
  85. package/dist/negotiation-C4nFufNk.js +71 -0
  86. package/dist/nodeinfo/client.test.js +30 -111
  87. package/dist/nodeinfo/handler.test.js +25 -26
  88. package/dist/nodeinfo/mod.cjs +10 -0
  89. package/dist/nodeinfo/mod.d.cts +3 -0
  90. package/dist/nodeinfo/mod.d.ts +3 -5
  91. package/dist/nodeinfo/mod.js +6 -7
  92. package/dist/nodeinfo/types.test.js +8 -15
  93. package/dist/nodeinfo-BnthBobC.js +4 -0
  94. package/dist/nodeinfo-CdN0rEnZ.cjs +4 -0
  95. package/dist/owner-B4HbyP8s.d.cts +67 -0
  96. package/dist/{owner-VEIjmR8r.js → owner-Dvh7mBvr.js} +3 -2
  97. package/dist/{owner-CQPnQVtf.d.ts → owner-kQRGVXG1.d.ts} +3 -3
  98. package/dist/proof-D0uThUvD.cjs +674 -0
  99. package/dist/{proof-DoSQAGkE.js → proof-Dgy35fzc.js} +3 -3
  100. package/dist/{proof-tgUlT8hw.js → proof-fqzaMJ4g.js} +11 -10
  101. package/dist/{send-BzS7w-QF.js → send-Drp20VO9.js} +2 -2
  102. package/dist/sig/http.test.js +13 -14
  103. package/dist/sig/key.test.js +9 -11
  104. package/dist/sig/ld.test.js +8 -10
  105. package/dist/sig/mod.cjs +28 -0
  106. package/dist/sig/mod.d.cts +6 -0
  107. package/dist/sig/mod.d.ts +5 -7
  108. package/dist/sig/mod.js +8 -10
  109. package/dist/sig/owner.test.js +10 -12
  110. package/dist/sig/proof.test.js +13 -14
  111. package/dist/sig-C34-oHBl.js +4 -0
  112. package/dist/sig-YYj5tCnr.cjs +4 -0
  113. package/dist/testing/docloader.test.js +6 -8
  114. package/dist/testing/mod.d.ts +387 -224
  115. package/dist/testing/mod.js +2 -3
  116. package/dist/{testing-Z2omCvKy.js → testing-g4UC4liW.js} +1 -2
  117. package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
  118. package/dist/transformers-CoBS-oFG.cjs +116 -0
  119. package/dist/{types-DgPvoUWN.js → types-BtUjyi5y.js} +8 -169
  120. package/dist/{types-BIgY6c-l.js → types-C2XVl6gj.js} +1 -3
  121. package/dist/types-CWgzGaqk.cjs +315 -0
  122. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +14 -15
  123. package/dist/utils/kv-cache.test.js +209 -0
  124. package/dist/utils/mod.cjs +12 -0
  125. package/dist/utils/mod.d.cts +5 -0
  126. package/dist/utils/mod.d.ts +7 -0
  127. package/dist/utils/mod.js +11 -0
  128. package/dist/utils-D-Va7aXC.js +4 -0
  129. package/dist/utils-DyRU1gdZ.cjs +4 -0
  130. package/dist/vocab/actor.test.js +8 -10
  131. package/dist/vocab/lookup.test.js +257 -9
  132. package/dist/vocab/mod.cjs +86 -0
  133. package/dist/vocab/mod.d.cts +4 -0
  134. package/dist/vocab/mod.d.ts +3 -5
  135. package/dist/vocab/mod.js +6 -7
  136. package/dist/vocab/type.test.js +2 -3
  137. package/dist/vocab/vocab.test.js +438 -15
  138. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BCWe1Ih5.d.ts} +292 -21
  139. package/dist/{vocab-CvD6Vbml.js → vocab-BnR3nIU9.js} +26 -17
  140. package/dist/vocab-CeDBzu-f.d.cts +14903 -0
  141. package/dist/{lookup-Bn_HEC_d.js → vocab-DFaWWYDn.cjs} +108 -139
  142. package/dist/webfinger/handler.test.js +24 -25
  143. package/dist/webfinger/lookup.test.js +7 -9
  144. package/dist/webfinger/mod.cjs +8 -0
  145. package/dist/webfinger/mod.d.cts +2 -0
  146. package/dist/webfinger/mod.d.ts +1 -3
  147. package/dist/webfinger/mod.js +5 -6
  148. package/dist/webfinger-C72Y8lrh.js +4 -0
  149. package/dist/webfinger-vAtLmxOF.cjs +4 -0
  150. package/dist/x/cfworkers.cjs +100 -0
  151. package/dist/x/cfworkers.d.cts +59 -0
  152. package/dist/x/cfworkers.d.ts +2 -2
  153. package/dist/x/cfworkers.js +3 -3
  154. package/dist/x/cfworkers.test.js +6 -8
  155. package/dist/x/hono.cjs +61 -0
  156. package/dist/x/hono.d.cts +53 -0
  157. package/dist/x/hono.d.ts +10 -11
  158. package/dist/x/hono.js +3 -3
  159. package/dist/x/sveltekit.cjs +69 -0
  160. package/dist/x/sveltekit.d.cts +45 -0
  161. package/dist/x/sveltekit.d.ts +10 -11
  162. package/dist/x/sveltekit.js +3 -3
  163. package/package.json +79 -23
  164. package/dist/assert_throws-BOO88avQ.js +0 -39
  165. package/dist/authdocloader-BFVqUbyo.js +0 -52
  166. package/dist/compat-Bb5myD13.js +0 -4
  167. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  168. package/dist/docloader-DEhniCVa.js +0 -4615
  169. package/dist/key-CUZQgVlf.js +0 -10
  170. package/dist/key-Deb0_wWL.js +0 -10
  171. package/dist/key-DxA6xRtZ.js +0 -260
  172. package/dist/lookup-dtdr2ftf.js +0 -131
  173. package/dist/middleware-BE_geSiJ.js +0 -17
  174. package/dist/middleware-BnU6hzVp.js +0 -26
  175. package/dist/mod-TFoH2Ql8.d.ts +0 -104
  176. package/dist/nodeinfo/semver.test.js +0 -143
  177. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  178. package/dist/runtime/docloader.test.js +0 -522
  179. package/dist/runtime/key.test.js +0 -103
  180. package/dist/runtime/langstr.test.d.ts +0 -3
  181. package/dist/runtime/langstr.test.js +0 -39
  182. package/dist/runtime/mod.d.ts +0 -8
  183. package/dist/runtime/mod.js +0 -13
  184. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  185. package/dist/runtime/multibase/multibase.test.js +0 -358
  186. package/dist/runtime/url.test.d.ts +0 -3
  187. package/dist/runtime/url.test.js +0 -45
  188. package/dist/runtime-BSkOVUWM.js +0 -4
  189. package/dist/semver-dArNLkR9.js +0 -149
  190. package/dist/sig-BXJO--F9.js +0 -4
  191. package/dist/webfinger-C3GIyXIg.js +0 -4
  192. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  193. /package/dist/{collection-CSzG2j1P.js → collection-BzWsN9pB.js} +0 -0
  194. /package/dist/{denokv-Bv33Xxea.js → denokv-CCssOzMJ.js} +0 -0
  195. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
  196. /package/dist/{runtime/authdocloader.test.d.ts → federation/negotiation.test.d.ts} +0 -0
  197. /package/dist/{kv-C7sopW2E.d.ts → kv-BKNZ-Tb-.d.ts} +0 -0
  198. /package/dist/{mod-1pDWKvUL.d.ts → mod-CVgZgliM.d.ts} +0 -0
  199. /package/dist/{mod-g0xFzAP9.d.ts → mod-xIj-IT58.d.ts} +0 -0
  200. /package/dist/{mq-CRGm1e_F.d.ts → mq-CUKlBw08.d.ts} +0 -0
  201. /package/dist/{retry-D4GJ670a.js → retry-CfF8Gn4d.js} +0 -0
  202. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  203. /package/dist/{runtime → utils}/docloader.test.d.ts +0 -0
  204. /package/dist/{runtime/key.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
@@ -0,0 +1,26 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import "../lookup-DQRtjvb1.js";
7
+ import "../assert_equals-DSbWqCm3.js";
8
+ import { assert } from "../assert-MZs1qjMx.js";
9
+ import "../assert_instance_of-DHz7EHNU.js";
10
+ import { acceptsJsonLd } from "../negotiation-C4nFufNk.js";
11
+ import { test } from "../testing-g4UC4liW.js";
12
+ import "../std__assert-DWivtrGR.js";
13
+ import { assertFalse } from "../assert_rejects-Ce45JcFg.js";
14
+ import "../assert_throws-BNXdRGWP.js";
15
+ import "../assert_not_equals-C80BG-_5.js";
16
+
17
+ //#region src/federation/negotiation.test.ts
18
+ test("acceptsJsonLd()", () => {
19
+ assert(acceptsJsonLd(new Request("https://example.com/", { headers: { Accept: "application/activity+json" } })));
20
+ assert(acceptsJsonLd(new Request("https://example.com/", { headers: { Accept: "application/ld+json" } })));
21
+ assert(acceptsJsonLd(new Request("https://example.com/", { headers: { Accept: "application/json" } })));
22
+ assertFalse(acceptsJsonLd(new Request("https://example.com/", { headers: { Accept: "application/ld+json; q=0.5, text/html; q=0.8" } })));
23
+ assertFalse(acceptsJsonLd(new Request("https://example.com/", { headers: { Accept: "application/ld+json; q=0.4, application/xhtml+xml; q=0.9" } })));
24
+ });
25
+
26
+ //#endregion
@@ -3,12 +3,11 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "../type-SK-d7Tbw.js";
6
+ import "../lookup-DQRtjvb1.js";
7
7
  import { AssertionError, assertEquals } from "../assert_equals-DSbWqCm3.js";
8
- import "../lookup-Bn_HEC_d.js";
9
- import { createExponentialBackoffPolicy } from "../retry-D4GJ670a.js";
10
- import { test } from "../testing-Z2omCvKy.js";
11
- import { assertNotEquals } from "../assert_not_equals-f3m3epl3.js";
8
+ import { createExponentialBackoffPolicy } from "../retry-CfF8Gn4d.js";
9
+ import { test } from "../testing-g4UC4liW.js";
10
+ import { assertNotEquals } from "../assert_not_equals-C80BG-_5.js";
12
11
 
13
12
  //#region src/federation/retry.test.ts
14
13
  test("createExponentialBackoffPolicy()", () => {
@@ -3,17 +3,15 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "../type-SK-d7Tbw.js";
6
+ import { Router, RouterError } from "../lookup-DQRtjvb1.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
9
  import "../assert_instance_of-DHz7EHNU.js";
10
- import { Router, RouterError } from "../lookup-Bn_HEC_d.js";
11
- import { test } from "../testing-Z2omCvKy.js";
12
- import "../std__assert-X-_kMxKM.js";
13
- import { assertFalse } from "../assert_rejects-DiIiJbZn.js";
14
- import "../assert_is_error-BPGph1Jx.js";
15
- import "../assert_not_equals-f3m3epl3.js";
16
- import { assertThrows } from "../assert_throws-BOO88avQ.js";
10
+ import { test } from "../testing-g4UC4liW.js";
11
+ import "../std__assert-DWivtrGR.js";
12
+ import { assertFalse } from "../assert_rejects-Ce45JcFg.js";
13
+ import { assertThrows } from "../assert_throws-BNXdRGWP.js";
14
+ import "../assert_not_equals-C80BG-_5.js";
17
15
 
18
16
  //#region src/federation/router.test.ts
19
17
  function setUp(options = {}) {
@@ -3,24 +3,22 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, Application, Endpoints, Group, Person, Service } from "../type-SK-d7Tbw.js";
6
+ import { Activity, Application, Endpoints, Group, Person, Service } from "../lookup-DQRtjvb1.js";
7
7
  import { assertEquals } from "../assert_equals-DSbWqCm3.js";
8
8
  import { assert } from "../assert-MZs1qjMx.js";
9
9
  import "../assert_instance_of-DHz7EHNU.js";
10
- import "../lookup-Bn_HEC_d.js";
11
- import "../actor-Cc6B76eG.js";
12
- import "../key-CzLv1phF.js";
13
- import { verifyRequest } from "../http-CcdM1brU.js";
14
- import { doesActorOwnKey } from "../owner-VEIjmR8r.js";
15
- import { extractInboxes, sendActivity } from "../send-BzS7w-QF.js";
16
- import { mockDocumentLoader, test } from "../testing-Z2omCvKy.js";
17
- import "../std__assert-X-_kMxKM.js";
18
- import { assertFalse, assertRejects } from "../assert_rejects-DiIiJbZn.js";
19
- import "../assert_is_error-BPGph1Jx.js";
20
- import { assertNotEquals } from "../assert_not_equals-f3m3epl3.js";
21
- import "../assert_throws-BOO88avQ.js";
22
- import { ed25519Multikey, ed25519PrivateKey, rsaPrivateKey2, rsaPublicKey2 } from "../keys-zZwiKkfx.js";
23
- import { esm_default } from "../esm-CHdxdkuH.js";
10
+ import "../actor-BXHc5r-q.js";
11
+ import "../key-CxdLUFS6.js";
12
+ import { verifyRequest } from "../http-D2kIm9la.js";
13
+ import { doesActorOwnKey } from "../owner-Dvh7mBvr.js";
14
+ import { extractInboxes, sendActivity } from "../send-Drp20VO9.js";
15
+ import { mockDocumentLoader, test } from "../testing-g4UC4liW.js";
16
+ import "../std__assert-DWivtrGR.js";
17
+ import { assertFalse, assertRejects } from "../assert_rejects-Ce45JcFg.js";
18
+ import "../assert_throws-BNXdRGWP.js";
19
+ import { assertNotEquals } from "../assert_not_equals-C80BG-_5.js";
20
+ import { ed25519Multikey, ed25519PrivateKey, rsaPrivateKey2, rsaPublicKey2 } from "../keys-DMHs8XNn.js";
21
+ import { esm_default } from "../esm-C-Qa1zEM.js";
24
22
 
25
23
  //#region src/federation/send.test.ts
26
24
  test("extractInboxes()", () => {
@@ -0,0 +1,244 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
+ const es_toolkit = require_chunk.__toESM(require("es-toolkit"));
7
+
8
+ //#region src/federation/kv.ts
9
+ /**
10
+ * A key–value store that stores values in memory.
11
+ * Do not use this in production as it does not persist values.
12
+ *
13
+ * @since 0.5.0
14
+ */
15
+ var MemoryKvStore = class {
16
+ #values = {};
17
+ #encodeKey(key) {
18
+ return JSON.stringify(key);
19
+ }
20
+ /**
21
+ * {@inheritDoc KvStore.get}
22
+ */
23
+ get(key) {
24
+ const encodedKey = this.#encodeKey(key);
25
+ const entry = this.#values[encodedKey];
26
+ if (entry == null) return Promise.resolve(void 0);
27
+ const [value, expiration] = entry;
28
+ if (expiration != null && Temporal.Now.instant().until(expiration).sign < 0) {
29
+ delete this.#values[encodedKey];
30
+ return Promise.resolve(void 0);
31
+ }
32
+ return Promise.resolve(value);
33
+ }
34
+ /**
35
+ * {@inheritDoc KvStore.set}
36
+ */
37
+ set(key, value, options) {
38
+ const encodedKey = this.#encodeKey(key);
39
+ const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
40
+ this.#values[encodedKey] = [value, expiration];
41
+ return Promise.resolve();
42
+ }
43
+ /**
44
+ * {@inheritDoc KvStore.delete}
45
+ */
46
+ delete(key) {
47
+ const encodedKey = this.#encodeKey(key);
48
+ delete this.#values[encodedKey];
49
+ return Promise.resolve();
50
+ }
51
+ /**
52
+ * {@inheritDoc KvStore.cas}
53
+ */
54
+ cas(key, expectedValue, newValue, options) {
55
+ const encodedKey = this.#encodeKey(key);
56
+ const entry = this.#values[encodedKey];
57
+ let currentValue;
58
+ if (entry == null) currentValue = void 0;
59
+ else {
60
+ const [value, expiration$1] = entry;
61
+ if (expiration$1 != null && Temporal.Now.instant().until(expiration$1).sign < 0) {
62
+ delete this.#values[encodedKey];
63
+ currentValue = void 0;
64
+ } else currentValue = value;
65
+ }
66
+ if (!(0, es_toolkit.isEqual)(currentValue, expectedValue)) return Promise.resolve(false);
67
+ const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
68
+ this.#values[encodedKey] = [newValue, expiration];
69
+ return Promise.resolve(true);
70
+ }
71
+ };
72
+
73
+ //#endregion
74
+ //#region src/federation/mq.ts
75
+ /**
76
+ * A message queue that processes messages in the same process.
77
+ * Do not use this in production as it does neither persist messages nor
78
+ * distribute them across multiple processes.
79
+ *
80
+ * @since 0.5.0
81
+ */
82
+ var InProcessMessageQueue = class {
83
+ #messages;
84
+ #monitors;
85
+ #pollIntervalMs;
86
+ /**
87
+ * In-process message queue does not provide native retry mechanisms.
88
+ * @since 1.7.0
89
+ */
90
+ nativeRetrial = false;
91
+ /**
92
+ * Constructs a new {@link InProcessMessageQueue} with the given options.
93
+ * @param options Additional options for the in-process message queue.
94
+ */
95
+ constructor(options = {}) {
96
+ this.#messages = [];
97
+ this.#monitors = {};
98
+ this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
99
+ }
100
+ enqueue(message, options) {
101
+ const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
102
+ if (delay > 0) {
103
+ setTimeout(() => this.enqueue(message, {
104
+ ...options,
105
+ delay: void 0
106
+ }), delay);
107
+ return Promise.resolve();
108
+ }
109
+ this.#messages.push(message);
110
+ for (const monitorId in this.#monitors) this.#monitors[monitorId]();
111
+ return Promise.resolve();
112
+ }
113
+ enqueueMany(messages, options) {
114
+ if (messages.length === 0) return Promise.resolve();
115
+ const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
116
+ if (delay > 0) {
117
+ setTimeout(() => this.enqueueMany(messages, {
118
+ ...options,
119
+ delay: void 0
120
+ }), delay);
121
+ return Promise.resolve();
122
+ }
123
+ this.#messages.push(...messages);
124
+ for (const monitorId in this.#monitors) this.#monitors[monitorId]();
125
+ return Promise.resolve();
126
+ }
127
+ async listen(handler, options = {}) {
128
+ const signal = options.signal;
129
+ while (signal == null || !signal.aborted) {
130
+ while (this.#messages.length > 0) {
131
+ const message = this.#messages.shift();
132
+ await handler(message);
133
+ }
134
+ await this.#wait(this.#pollIntervalMs, signal);
135
+ }
136
+ }
137
+ #wait(ms, signal) {
138
+ let timer = null;
139
+ return Promise.any([new Promise((resolve) => {
140
+ signal?.addEventListener("abort", () => {
141
+ if (timer != null) clearTimeout(timer);
142
+ resolve();
143
+ }, { once: true });
144
+ const monitorId = crypto.randomUUID();
145
+ this.#monitors[monitorId] = () => {
146
+ delete this.#monitors[monitorId];
147
+ if (timer != null) clearTimeout(timer);
148
+ resolve();
149
+ };
150
+ }), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
151
+ }
152
+ };
153
+ /**
154
+ * A message queue that processes messages in parallel. It takes another
155
+ * {@link MessageQueue}, and processes messages in parallel up to a certain
156
+ * number of workers.
157
+ *
158
+ * Actually, it's rather a decorator than a queue itself.
159
+ *
160
+ * Note that the workers do not run in truly parallel, in the sense that they
161
+ * are not running in separate threads or processes. They are running in the
162
+ * same process, but are scheduled to run in parallel. Hence, this is useful
163
+ * for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
164
+ * workloads.
165
+ *
166
+ * @since 1.0.0
167
+ */
168
+ var ParallelMessageQueue = class ParallelMessageQueue {
169
+ queue;
170
+ workers;
171
+ /**
172
+ * Inherits the native retry capability from the wrapped queue.
173
+ * @since 1.7.0
174
+ */
175
+ nativeRetrial;
176
+ /**
177
+ * Constructs a new {@link ParallelMessageQueue} with the given queue and
178
+ * number of workers.
179
+ * @param queue The message queue to use under the hood. Note that
180
+ * {@link ParallelMessageQueue} cannot be nested.
181
+ * @param workers The number of workers to process messages in parallel.
182
+ * @throws {TypeError} If the given queue is an instance of
183
+ * {@link ParallelMessageQueue}.
184
+ */
185
+ constructor(queue, workers) {
186
+ if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
187
+ this.queue = queue;
188
+ this.workers = workers;
189
+ this.nativeRetrial = queue.nativeRetrial;
190
+ }
191
+ enqueue(message, options) {
192
+ return this.queue.enqueue(message, options);
193
+ }
194
+ async enqueueMany(messages, options) {
195
+ if (this.queue.enqueueMany == null) {
196
+ const results = await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)));
197
+ const errors = results.filter((r) => r.status === "rejected").map((r) => r.reason);
198
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
199
+ else if (errors.length === 1) throw errors[0];
200
+ return;
201
+ }
202
+ await this.queue.enqueueMany(messages, options);
203
+ }
204
+ listen(handler, options = {}) {
205
+ const workers = /* @__PURE__ */ new Map();
206
+ return this.queue.listen(async (message) => {
207
+ while (workers.size >= this.workers) {
208
+ const consumedId = await Promise.any(workers.values());
209
+ workers.delete(consumedId);
210
+ }
211
+ const workerId = crypto.randomUUID();
212
+ const promise = this.#work(workerId, handler, message);
213
+ workers.set(workerId, promise);
214
+ }, options);
215
+ }
216
+ async #work(workerId, handler, message) {
217
+ await this.#sleep(0);
218
+ await handler(message);
219
+ return workerId;
220
+ }
221
+ #sleep(ms) {
222
+ return new Promise((resolve) => setTimeout(resolve, ms));
223
+ }
224
+ };
225
+
226
+ //#endregion
227
+ Object.defineProperty(exports, 'InProcessMessageQueue', {
228
+ enumerable: true,
229
+ get: function () {
230
+ return InProcessMessageQueue;
231
+ }
232
+ });
233
+ Object.defineProperty(exports, 'MemoryKvStore', {
234
+ enumerable: true,
235
+ get: function () {
236
+ return MemoryKvStore;
237
+ }
238
+ });
239
+ Object.defineProperty(exports, 'ParallelMessageQueue', {
240
+ enumerable: true,
241
+ get: function () {
242
+ return ParallelMessageQueue;
243
+ }
244
+ });
@@ -1,7 +1,7 @@
1
1
 
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
5
  import { isEqual } from "es-toolkit";
6
6
 
7
7
  //#region src/federation/kv.ts
@@ -0,0 +1,6 @@
1
+ {
2
+ "@context": "https://www.w3.org/ns/activitystreams",
3
+ "id": "https://media.example.com/avatars/test-avatar.jpg",
4
+ "type": "Image",
5
+ "url": "/avatars/test-avatar.jpg"
6
+ }
@@ -1,8 +1,8 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { DocumentLoader } from "./docloader-CxWcuWqQ.js";
4
- import { CryptographicKey, Multikey } from "./vocab-SOE1ifCr.js";
3
+ import { CryptographicKey, Multikey } from "./vocab-BCWe1Ih5.js";
5
4
  import { TracerProvider } from "@opentelemetry/api";
5
+ import { DocumentLoader } from "@fedify/vocab-runtime";
6
6
 
7
7
  //#region src/sig/key.d.ts
8
8
 
@@ -1,17 +1,267 @@
1
1
 
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { deno_default } from "./docloader-DEhniCVa.js";
6
- import { CryptographicKey } from "./actor-CTAuCsWy.js";
7
- import { fetchKey, validateCryptoKey } from "./key-DxA6xRtZ.js";
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { deno_default } from "./lookup-CHkCVZTU.js";
6
+ import { CryptographicKey, Object as Object$1, isActor } from "./actor-DzhunPC_.js";
8
7
  import { getLogger } from "@logtape/logtape";
9
- import { SpanStatusCode, trace } from "@opentelemetry/api";
10
- import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
8
+ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
+ import { getDocumentLoader } from "@fedify/vocab-runtime";
11
10
  import { encodeHex } from "byte-encodings/hex";
12
11
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
12
+ import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
13
13
  import { Item, decodeDict, encodeItem } from "structured-field-values";
14
14
 
15
+ //#region src/sig/key.ts
16
+ /**
17
+ * Checks if the given key is valid and supported. No-op if the key is valid,
18
+ * otherwise throws an error.
19
+ * @param key The key to check.
20
+ * @param type Which type of key to check. If not specified, the key can be
21
+ * either public or private.
22
+ * @throws {TypeError} If the key is invalid or unsupported.
23
+ */
24
+ function validateCryptoKey(key, type) {
25
+ if (type != null && key.type !== type) throw new TypeError(`The key is not a ${type} key.`);
26
+ if (!key.extractable) throw new TypeError("The key is not extractable.");
27
+ if (key.algorithm.name !== "RSASSA-PKCS1-v1_5" && key.algorithm.name !== "Ed25519") throw new TypeError("Currently only RSASSA-PKCS1-v1_5 and Ed25519 keys are supported. More algorithms will be added in the future!");
28
+ if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
29
+ const algorithm = key.algorithm;
30
+ if (algorithm.hash.name !== "SHA-256") throw new TypeError("For compatibility with the existing Fediverse software (e.g., Mastodon), hash algorithm for RSASSA-PKCS1-v1_5 keys must be SHA-256.");
31
+ }
32
+ }
33
+ /**
34
+ * Generates a key pair which is appropriate for Fedify.
35
+ * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
36
+ * Ed25519 are supported.
37
+ * @returns The generated key pair.
38
+ * @throws {TypeError} If the algorithm is unsupported.
39
+ */
40
+ function generateCryptoKeyPair(algorithm) {
41
+ if (algorithm == null) getLogger([
42
+ "fedify",
43
+ "sig",
44
+ "key"
45
+ ]).warn("No algorithm specified. Using RSASSA-PKCS1-v1_5 by default, but it is recommended to specify the algorithm explicitly as the parameter will be required in the future.");
46
+ if (algorithm == null || algorithm === "RSASSA-PKCS1-v1_5") return crypto.subtle.generateKey({
47
+ name: "RSASSA-PKCS1-v1_5",
48
+ modulusLength: 4096,
49
+ publicExponent: new Uint8Array([
50
+ 1,
51
+ 0,
52
+ 1
53
+ ]),
54
+ hash: "SHA-256"
55
+ }, true, ["sign", "verify"]);
56
+ else if (algorithm === "Ed25519") return crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
57
+ throw new TypeError("Unsupported algorithm: " + algorithm);
58
+ }
59
+ /**
60
+ * Exports a key in JWK format.
61
+ * @param key The key to export. Either public or private key.
62
+ * @returns The exported key in JWK format. The key is suitable for
63
+ * serialization and storage.
64
+ * @throws {TypeError} If the key is invalid or unsupported.
65
+ */
66
+ async function exportJwk(key) {
67
+ validateCryptoKey(key);
68
+ const jwk = await crypto.subtle.exportKey("jwk", key);
69
+ if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
70
+ return jwk;
71
+ }
72
+ /**
73
+ * Imports a key from JWK format.
74
+ * @param jwk The key in JWK format.
75
+ * @param type Which type of key to import, either `"public"` or `"private"`.
76
+ * @returns The imported key.
77
+ * @throws {TypeError} If the key is invalid or unsupported.
78
+ */
79
+ async function importJwk(jwk, type) {
80
+ let key;
81
+ if (jwk.kty === "RSA" && jwk.alg === "RS256") key = await crypto.subtle.importKey("jwk", jwk, {
82
+ name: "RSASSA-PKCS1-v1_5",
83
+ hash: "SHA-256"
84
+ }, true, type === "public" ? ["verify"] : ["sign"]);
85
+ else if (jwk.kty === "OKP" && jwk.crv === "Ed25519") {
86
+ if (navigator?.userAgent === "Cloudflare-Workers") {
87
+ jwk = { ...jwk };
88
+ delete jwk.alg;
89
+ }
90
+ key = await crypto.subtle.importKey("jwk", jwk, "Ed25519", true, type === "public" ? ["verify"] : ["sign"]);
91
+ } else throw new TypeError("Unsupported JWK format.");
92
+ validateCryptoKey(key, type);
93
+ return key;
94
+ }
95
+ /**
96
+ * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
97
+ * If the given URL contains an {@link Actor} object, it tries to find
98
+ * the corresponding key in the `publicKey` or `assertionMethod` property.
99
+ * @template T The type of the key to fetch. Either {@link CryptographicKey}
100
+ * or {@link Multikey}.
101
+ * @param keyId The URL of the key.
102
+ * @param cls The class of the key to fetch. Either {@link CryptographicKey}
103
+ * or {@link Multikey}.
104
+ * @param options Options for fetching the key. See {@link FetchKeyOptions}.
105
+ * @returns The fetched key or `null` if the key is not found.
106
+ * @since 1.3.0
107
+ */
108
+ function fetchKey(keyId, cls, options = {}) {
109
+ const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
110
+ const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
111
+ keyId = typeof keyId === "string" ? new URL(keyId) : keyId;
112
+ return tracer.startActiveSpan("activitypub.fetch_key", {
113
+ kind: SpanKind.CLIENT,
114
+ attributes: {
115
+ "http.method": "GET",
116
+ "url.full": keyId.href,
117
+ "url.scheme": keyId.protocol.replace(/:$/, ""),
118
+ "url.domain": keyId.hostname,
119
+ "url.path": keyId.pathname,
120
+ "url.query": keyId.search.replace(/^\?/, ""),
121
+ "url.fragment": keyId.hash.replace(/^#/, "")
122
+ }
123
+ }, async (span) => {
124
+ try {
125
+ const result = await fetchKeyInternal(keyId, cls, options);
126
+ span.setAttribute("activitypub.actor.key.cached", result.cached);
127
+ return result;
128
+ } catch (e) {
129
+ span.setStatus({
130
+ code: SpanStatusCode.ERROR,
131
+ message: String(e)
132
+ });
133
+ throw e;
134
+ } finally {
135
+ span.end();
136
+ }
137
+ });
138
+ }
139
+ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, keyCache, tracerProvider } = {}) {
140
+ const logger = getLogger([
141
+ "fedify",
142
+ "sig",
143
+ "key"
144
+ ]);
145
+ const cacheKey = typeof keyId === "string" ? new URL(keyId) : keyId;
146
+ keyId = typeof keyId === "string" ? keyId : keyId.href;
147
+ if (keyCache != null) {
148
+ const cachedKey = await keyCache.get(cacheKey);
149
+ if (cachedKey instanceof cls && cachedKey.publicKey != null) {
150
+ logger.debug("Key {keyId} found in cache.", { keyId });
151
+ return {
152
+ key: cachedKey,
153
+ cached: true
154
+ };
155
+ } else if (cachedKey === null) {
156
+ logger.debug("Entry {keyId} found in cache, but it is unavailable.", { keyId });
157
+ return {
158
+ key: null,
159
+ cached: true
160
+ };
161
+ }
162
+ }
163
+ logger.debug("Fetching key {keyId} to verify signature...", { keyId });
164
+ let document;
165
+ try {
166
+ const remoteDocument = await (documentLoader ?? getDocumentLoader())(keyId);
167
+ document = remoteDocument.document;
168
+ } catch (_) {
169
+ logger.debug("Failed to fetch key {keyId}.", { keyId });
170
+ await keyCache?.set(cacheKey, null);
171
+ return {
172
+ key: null,
173
+ cached: false
174
+ };
175
+ }
176
+ let object;
177
+ try {
178
+ object = await Object$1.fromJsonLd(document, {
179
+ documentLoader,
180
+ contextLoader,
181
+ tracerProvider
182
+ });
183
+ } catch (e) {
184
+ if (!(e instanceof TypeError)) throw e;
185
+ try {
186
+ object = await cls.fromJsonLd(document, {
187
+ documentLoader,
188
+ contextLoader,
189
+ tracerProvider
190
+ });
191
+ } catch (e$1) {
192
+ if (e$1 instanceof TypeError) {
193
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
194
+ await keyCache?.set(cacheKey, null);
195
+ return {
196
+ key: null,
197
+ cached: false
198
+ };
199
+ }
200
+ throw e$1;
201
+ }
202
+ }
203
+ let key = null;
204
+ if (object instanceof cls) key = object;
205
+ else if (isActor(object)) {
206
+ const keys = cls === CryptographicKey ? object.getPublicKeys({
207
+ documentLoader,
208
+ contextLoader,
209
+ tracerProvider
210
+ }) : object.getAssertionMethods({
211
+ documentLoader,
212
+ contextLoader,
213
+ tracerProvider
214
+ });
215
+ let length = 0;
216
+ let lastKey = null;
217
+ for await (const k of keys) {
218
+ length++;
219
+ lastKey = k;
220
+ if (k.id?.href === keyId) {
221
+ key = k;
222
+ break;
223
+ }
224
+ }
225
+ const keyIdUrl = new URL(keyId);
226
+ if (key == null && keyIdUrl.hash === "" && length === 1) key = lastKey;
227
+ if (key == null) {
228
+ logger.debug("Failed to verify; object {keyId} returned an {actorType}, but has no key matching {keyId}.", {
229
+ keyId,
230
+ actorType: object.constructor.name
231
+ });
232
+ await keyCache?.set(cacheKey, null);
233
+ return {
234
+ key: null,
235
+ cached: false
236
+ };
237
+ }
238
+ } else {
239
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
240
+ await keyCache?.set(cacheKey, null);
241
+ return {
242
+ key: null,
243
+ cached: false
244
+ };
245
+ }
246
+ if (key.publicKey == null) {
247
+ logger.debug("Failed to verify; key {keyId} has no publicKeyPem field.", { keyId });
248
+ await keyCache?.set(cacheKey, null);
249
+ return {
250
+ key: null,
251
+ cached: false
252
+ };
253
+ }
254
+ if (keyCache != null) {
255
+ await keyCache.set(cacheKey, key);
256
+ logger.debug("Key {keyId} cached.", { keyId });
257
+ }
258
+ return {
259
+ key,
260
+ cached: false
261
+ };
262
+ }
263
+
264
+ //#endregion
15
265
  //#region src/sig/http.ts
16
266
  /**
17
267
  * Signs a request using the given private key.
@@ -658,7 +908,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
658
908
  const signatureBaseBytes = new TextEncoder().encode(signatureBase);
659
909
  span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
660
910
  try {
661
- const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes, signatureBaseBytes);
911
+ const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes);
662
912
  if (verified) {
663
913
  validKey = key;
664
914
  break;
@@ -805,4 +1055,4 @@ function timingSafeEqual(a, b) {
805
1055
  }
806
1056
 
807
1057
  //#endregion
808
- export { doubleKnock, signRequest, verifyRequest };
1058
+ export { doubleKnock, exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, validateCryptoKey, verifyRequest };