@fedify/fedify 2.0.7 → 2.0.9

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 (203) hide show
  1. package/dist/{assert-MZs1qjMx.js → assert-ddO5KLpe.mjs} +5 -9
  2. package/dist/{assert_equals-DSbWqCm3.js → assert_equals-Ew3jOFa3.mjs} +55 -69
  3. package/dist/{assert_instance_of-DHz7EHNU.js → assert_instance_of-C4Ri6VuN.mjs} +5 -9
  4. package/dist/{assert_not_equals-C80BG-_5.js → assert_not_equals--wG9hV7u.mjs} +6 -13
  5. package/dist/{assert_rejects-Ce45JcFg.js → assert_rejects-B-qJtC9Z.mjs} +6 -11
  6. package/dist/{assert_throws-BNXdRGWP.js → assert_throws-4NwKEy2q.mjs} +5 -10
  7. package/dist/{builder-DA7Qgx_F.js → builder-DDoQaGOu.mjs} +32 -41
  8. package/dist/{chunk-CGaQZ11T.cjs → chunk-DDcVe30Y.cjs} +23 -24
  9. package/dist/{chunk-DJNbSFdH.js → chunk-nlSIicah.js} +8 -8
  10. package/dist/{client-CoCIaTNO.js → client-A1UrnX6I.mjs} +9 -13
  11. package/dist/{client-BxMZiQaD.d.ts → client-AtlibPOU.d.ts} +1 -1
  12. package/dist/{client-C97KOq3x.d.cts → client-z-8dc-e1.d.cts} +1 -1
  13. package/dist/{collection-CcnIw1qY.js → collection-ChgDTHLz.mjs} +7 -12
  14. package/dist/compat/mod.cjs +5 -8
  15. package/dist/compat/mod.d.cts +78 -6
  16. package/dist/compat/mod.d.ts +78 -6
  17. package/dist/compat/mod.js +4 -8
  18. package/dist/compat/transformers.test.mjs +62 -0
  19. package/dist/{context-D3QkEtZd.d.cts → context-CNIt-Qn7.d.cts} +9 -18
  20. package/dist/{context-DZJhUmzF.d.ts → context-Dyg7P1qW.d.ts} +9 -18
  21. package/dist/{context-pa9aIrwp.js → context-Juj6bdHC.mjs} +7 -11
  22. package/dist/deno-CuVDEdyj.mjs +8 -0
  23. package/dist/{docloader-CJeSPcS_.js → docloader-BPq9yzC_.mjs} +8 -14
  24. package/dist/{esm-nLm00z9V.js → esm-DVILvP5e.mjs} +50 -89
  25. package/dist/federation/builder.test.d.mts +2 -0
  26. package/dist/federation/{builder.test.js → builder.test.mjs} +19 -38
  27. package/dist/federation/collection.test.d.mts +2 -0
  28. package/dist/federation/collection.test.mjs +21 -0
  29. package/dist/federation/handler.test.d.mts +2 -0
  30. package/dist/federation/{handler.test.js → handler.test.mjs} +26 -56
  31. package/dist/federation/idempotency.test.d.mts +2 -0
  32. package/dist/federation/{idempotency.test.js → idempotency.test.mjs} +31 -62
  33. package/dist/federation/inbox.test.d.mts +2 -0
  34. package/dist/federation/{inbox.test.js → inbox.test.mjs} +8 -12
  35. package/dist/federation/keycache.test.d.mts +2 -0
  36. package/dist/federation/{keycache.test.js → keycache.test.mjs} +13 -13
  37. package/dist/federation/kv.test.d.mts +2 -0
  38. package/dist/federation/{kv.test.js → kv.test.mjs} +11 -22
  39. package/dist/federation/middleware.test.d.mts +2 -0
  40. package/dist/federation/{middleware.test.js → middleware.test.mjs} +146 -225
  41. package/dist/federation/mod.cjs +327 -16
  42. package/dist/federation/mod.d.cts +3 -6
  43. package/dist/federation/mod.d.ts +3 -6
  44. package/dist/federation/mod.js +322 -13
  45. package/dist/federation/mq.test.d.mts +2 -0
  46. package/dist/federation/{mq.test.js → mq.test.mjs} +21 -35
  47. package/dist/federation/negotiation.test.d.mts +2 -0
  48. package/dist/federation/{negotiation.test.js → negotiation.test.mjs} +9 -16
  49. package/dist/federation/retry.test.d.mts +2 -0
  50. package/dist/federation/{retry.test.js → retry.test.mjs} +8 -11
  51. package/dist/federation/router.test.d.mts +2 -0
  52. package/dist/federation/{router.test.js → router.test.mjs} +11 -16
  53. package/dist/federation/send.test.d.mts +2 -0
  54. package/dist/federation/{send.test.js → send.test.mjs} +22 -29
  55. package/dist/federation/webfinger.test.d.mts +2 -0
  56. package/dist/federation/{webfinger.test.js → webfinger.test.mjs} +22 -55
  57. package/dist/{http-DkHdFfrc.d.ts → http-B2wiNmSo.d.ts} +1 -6
  58. package/dist/{http-B3vAjAtl.js → http-Bz7avX57.js} +39 -159
  59. package/dist/{http-Cz3MlXAZ.d.cts → http-C_tEAiZj.d.cts} +1 -6
  60. package/dist/{http-CjaLjnRN.js → http-DI213UHg.mjs} +31 -35
  61. package/dist/{http-CQ7TiYUI.cjs → http-DKBDoudA.cjs} +119 -233
  62. package/dist/{inbox-B33isX44.js → inbox-Bdn-CSRd.mjs} +18 -26
  63. package/dist/{key-Cga1p73u.js → key-DzJf84o7.mjs} +12 -19
  64. package/dist/{keycache-DRxpZ5r9.js → keycache-DaQ3ndaJ.mjs} +15 -10
  65. package/dist/{keys-ZbcByPg9.js → keys-CtZLJq76.mjs} +5 -9
  66. package/dist/{kv-QzKcOQgP.js → kv-BrZHNugx.mjs} +6 -10
  67. package/dist/{kv-BL4nlICN.d.cts → kv-CbLNp3zQ.d.cts} +1 -1
  68. package/dist/{kv-DXEUEP6z.d.ts → kv-GFYnFoOl.d.ts} +1 -1
  69. package/dist/{kv-cache-CFdy0BpZ.js → kv-cache-DBd7BezJ.js} +6 -13
  70. package/dist/{kv-cache--qyREO7e.cjs → kv-cache-Dj1Q7TiW.cjs} +27 -34
  71. package/dist/{kv-cache-El7We5sy.js → kv-cache-OWmRLHir.mjs} +4 -8
  72. package/dist/{ld-BWSOukKj.js → ld-DczS1fLK.mjs} +17 -31
  73. package/dist/middleware-B5CiOImA.mjs +5 -0
  74. package/dist/{middleware-CP7JdsGq.js → middleware-BKNu57ZI.js} +331 -365
  75. package/dist/middleware-C36TOX-2.cjs +4 -0
  76. package/dist/{middleware-Scz2k9eL.cjs → middleware-CyjmpK70.cjs} +523 -565
  77. package/dist/{middleware-BI1VCuPT.js → middleware-DoHz9oIo.mjs} +260 -292
  78. package/dist/{mod-DPkRU3EK.d.cts → mod-1xhgsHef.d.cts} +2 -2
  79. package/dist/{mod-DUWcVv49.d.ts → mod-BGtYJZKu.d.ts} +2 -2
  80. package/dist/{mod-DXsQakeS.d.cts → mod-Bld7oeqf.d.cts} +3 -3
  81. package/dist/{mod-DnSsduJF.d.ts → mod-BnAKGh2w.d.ts} +2 -2
  82. package/dist/{mod-CwZXZJ9d.d.ts → mod-DTOUyCce.d.ts} +3 -3
  83. package/dist/{mod-Di3W5OdP.d.cts → mod-DWoQffTD.d.cts} +2 -2
  84. package/dist/mod.cjs +29 -68
  85. package/dist/mod.d.cts +11 -14
  86. package/dist/mod.d.ts +11 -15
  87. package/dist/mod.js +17 -65
  88. package/dist/{negotiation-5NPJL6zp.js → negotiation-BehA2uul.mjs} +7 -11
  89. package/dist/nodeinfo/client.test.d.mts +2 -0
  90. package/dist/nodeinfo/{client.test.js → client.test.mjs} +22 -40
  91. package/dist/nodeinfo/handler.test.d.mts +2 -0
  92. package/dist/nodeinfo/{handler.test.js → handler.test.mjs} +13 -42
  93. package/dist/nodeinfo/mod.cjs +5 -8
  94. package/dist/nodeinfo/mod.d.cts +2 -3
  95. package/dist/nodeinfo/mod.d.ts +2 -3
  96. package/dist/nodeinfo/mod.js +4 -8
  97. package/dist/nodeinfo/types.test.d.mts +2 -0
  98. package/dist/nodeinfo/{types.test.js → types.test.mjs} +9 -16
  99. package/dist/otel/exporter.test.d.mts +2 -0
  100. package/dist/otel/{exporter.test.js → exporter.test.mjs} +117 -169
  101. package/dist/otel/mod.cjs +15 -20
  102. package/dist/otel/mod.d.cts +2 -2
  103. package/dist/otel/mod.d.ts +2 -2
  104. package/dist/otel/mod.js +8 -14
  105. package/dist/{owner-gd0Q9FuU.d.ts → owner-74ARJ5TL.d.ts} +1 -1
  106. package/dist/{owner-1AbPBOOZ.d.cts → owner-CptqhsOy.d.cts} +1 -1
  107. package/dist/{owner-HASxJJP1.js → owner-DXMGUEOr.mjs} +11 -16
  108. package/dist/{proof-BwfRl5J4.js → proof-C-7NljBU.js} +33 -59
  109. package/dist/{proof-BXt2Oi8t.js → proof-CEOujj0L.mjs} +21 -33
  110. package/dist/{proof-BYZ4hcgN.cjs → proof-DMu-6A_w.cjs} +133 -157
  111. package/dist/{retry-D4GJ670a.js → retry-Ddbq3AcK.mjs} +4 -7
  112. package/dist/{router-D9eI0s4b.js → router-CrMLXoOr.mjs} +4 -8
  113. package/dist/runtime/mod.cjs +11 -13
  114. package/dist/runtime/mod.d.cts +6 -2
  115. package/dist/runtime/mod.d.ts +0 -1
  116. package/dist/runtime/mod.js +4 -7
  117. package/dist/{send-BF3omx5-.js → send-DIfrLTB_.mjs} +8 -13
  118. package/dist/sig/http.test.d.mts +2 -0
  119. package/dist/sig/{http.test.js → http.test.mjs} +160 -199
  120. package/dist/sig/key.test.d.mts +2 -0
  121. package/dist/sig/{key.test.js → key.test.mjs} +11 -18
  122. package/dist/sig/ld.test.d.mts +2 -0
  123. package/dist/sig/{ld.test.js → ld.test.mjs} +22 -35
  124. package/dist/sig/mod.cjs +6 -9
  125. package/dist/sig/mod.d.cts +3 -3
  126. package/dist/sig/mod.d.ts +3 -3
  127. package/dist/sig/mod.js +5 -9
  128. package/dist/sig/owner.test.d.mts +2 -0
  129. package/dist/sig/{owner.test.js → owner.test.mjs} +19 -34
  130. package/dist/sig/proof.test.d.mts +2 -0
  131. package/dist/sig/{proof.test.js → proof.test.mjs} +16 -27
  132. package/dist/{std__assert-DWivtrGR.js → std__assert-Duiq_YC9.mjs} +12 -24
  133. package/dist/testing/{mod.d.ts → mod.d.mts} +26 -78
  134. package/dist/testing/mod.mjs +6 -0
  135. package/dist/{transformers-3g8GZwkZ.cjs → transformers-NeAONrAq.cjs} +20 -25
  136. package/dist/{transformers-C3FLHUd6.js → transformers-ve6e2xcg.js} +3 -7
  137. package/dist/{types-CPz01LGH.js → types-C37hquWI.mjs} +4 -7
  138. package/dist/{types-Cd_hszr_.cjs → types-KC4QAoxe.cjs} +29 -34
  139. package/dist/{types-C93Ob9cU.js → types-hvL8ElAs.js} +8 -13
  140. package/dist/utils/docloader.test.d.mts +2 -0
  141. package/dist/utils/{docloader.test.js → docloader.test.mjs} +14 -24
  142. package/dist/utils/kv-cache.test.d.mts +2 -0
  143. package/dist/utils/{kv-cache.test.js → kv-cache.test.mjs} +25 -40
  144. package/dist/utils/mod.cjs +5 -9
  145. package/dist/utils/mod.d.cts +1 -3
  146. package/dist/utils/mod.d.ts +1 -3
  147. package/dist/utils/mod.js +4 -9
  148. package/dist/vocab/cjs.test.d.mts +2 -0
  149. package/dist/vocab/cjs.test.mjs +14 -0
  150. package/dist/vocab/mod.cjs +10 -12
  151. package/dist/vocab/mod.js +3 -5
  152. package/package.json +7 -7
  153. package/dist/compat/transformers.test.d.ts +0 -3
  154. package/dist/compat/transformers.test.js +0 -87
  155. package/dist/compat-Bb4NuTUO.js +0 -4
  156. package/dist/compat-DmDDELst.cjs +0 -4
  157. package/dist/deno-CbQK8e-e.js +0 -121
  158. package/dist/federation/builder.test.d.ts +0 -3
  159. package/dist/federation/collection.test.d.ts +0 -3
  160. package/dist/federation/collection.test.js +0 -32
  161. package/dist/federation/handler.test.d.ts +0 -3
  162. package/dist/federation/idempotency.test.d.ts +0 -3
  163. package/dist/federation/inbox.test.d.ts +0 -3
  164. package/dist/federation/keycache.test.d.ts +0 -3
  165. package/dist/federation/kv.test.d.ts +0 -3
  166. package/dist/federation/middleware.test.d.ts +0 -3
  167. package/dist/federation/mq.test.d.ts +0 -3
  168. package/dist/federation/negotiation.test.d.ts +0 -3
  169. package/dist/federation/retry.test.d.ts +0 -3
  170. package/dist/federation/router.test.d.ts +0 -3
  171. package/dist/federation/send.test.d.ts +0 -3
  172. package/dist/federation/webfinger.test.d.ts +0 -3
  173. package/dist/federation-Bp3HI26G.cjs +0 -350
  174. package/dist/federation-DaMfqRm4.js +0 -332
  175. package/dist/middleware-CcXQzfn8.cjs +0 -12
  176. package/dist/middleware-CoeaBowW.js +0 -12
  177. package/dist/middleware-vH2jFwC6.js +0 -26
  178. package/dist/mod-Bh8mqlYw.d.cts +0 -9
  179. package/dist/mod-D6HodEq7.d.ts +0 -7
  180. package/dist/mod-DVwHUI_x.d.cts +0 -80
  181. package/dist/mod-DosD6NsG.d.ts +0 -82
  182. package/dist/mod-gq_Xfdz8.d.cts +0 -1
  183. package/dist/nodeinfo/client.test.d.ts +0 -3
  184. package/dist/nodeinfo/handler.test.d.ts +0 -3
  185. package/dist/nodeinfo/types.test.d.ts +0 -3
  186. package/dist/nodeinfo-DoESQxq5.js +0 -4
  187. package/dist/nodeinfo-DuMYTpbZ.cjs +0 -4
  188. package/dist/otel/exporter.test.d.ts +0 -3
  189. package/dist/runtime-c2Njxsry.cjs +0 -17
  190. package/dist/runtime-poamPCMb.js +0 -13
  191. package/dist/sig/http.test.d.ts +0 -3
  192. package/dist/sig/key.test.d.ts +0 -3
  193. package/dist/sig/ld.test.d.ts +0 -3
  194. package/dist/sig/owner.test.d.ts +0 -3
  195. package/dist/sig/proof.test.d.ts +0 -3
  196. package/dist/sig-BNhspNOf.js +0 -4
  197. package/dist/sig-vX39WyWI.cjs +0 -4
  198. package/dist/testing/mod.js +0 -10
  199. package/dist/utils/docloader.test.d.ts +0 -3
  200. package/dist/utils/kv-cache.test.d.ts +0 -3
  201. package/dist/utils-BQ9KqEK9.cjs +0 -4
  202. package/dist/utils-Dn5OPdSW.js +0 -4
  203. /package/dist/{mod-AGjRfPjT.d.ts → compat/transformers.test.d.mts} +0 -0
@@ -1,50 +1,23 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { assertEquals } from "../assert_equals-DSbWqCm3.js";
7
- import "../assert-MZs1qjMx.js";
8
- import "../assert_instance_of-DHz7EHNU.js";
9
- import { MemoryKvStore } from "../kv-QzKcOQgP.js";
10
- import "../deno-CbQK8e-e.js";
11
- import { createFederation, handleWebFinger } from "../middleware-BI1VCuPT.js";
12
- import "../client-CoCIaTNO.js";
13
- import "../router-D9eI0s4b.js";
14
- import "../types-CPz01LGH.js";
15
- import "../key-Cga1p73u.js";
16
- import "../http-CjaLjnRN.js";
17
- import "../ld-BWSOukKj.js";
18
- import "../owner-HASxJJP1.js";
19
- import "../proof-BXt2Oi8t.js";
20
- import "../docloader-CJeSPcS_.js";
21
- import "../kv-cache-El7We5sy.js";
22
- import "../inbox-B33isX44.js";
23
- import "../builder-DA7Qgx_F.js";
24
- import "../collection-CcnIw1qY.js";
25
- import "../keycache-DRxpZ5r9.js";
26
- import "../negotiation-5NPJL6zp.js";
27
- import "../retry-D4GJ670a.js";
28
- import "../send-BF3omx5-.js";
29
- import "../std__assert-DWivtrGR.js";
30
- import "../assert_rejects-Ce45JcFg.js";
31
- import "../assert_throws-BNXdRGWP.js";
32
- import "../assert_not_equals-C80BG-_5.js";
33
- import { createRequestContext } from "../context-pa9aIrwp.js";
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
5
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
+ import "../std__assert-Duiq_YC9.mjs";
7
+ import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
8
+ import { a as createFederation, o as handleWebFinger } from "../middleware-DoHz9oIo.mjs";
34
9
  import { test } from "@fedify/fixture";
35
10
  import { Image, Link, Person } from "@fedify/vocab";
36
-
37
11
  //#region src/federation/webfinger.test.ts
38
12
  test("handleWebFinger()", async (t) => {
39
13
  const url = new URL("https://example.com/.well-known/webfinger");
40
- function createContext(url$1) {
41
- const federation = createFederation({ kv: new MemoryKvStore() });
14
+ function createContext(url) {
42
15
  const context = createRequestContext({
43
- federation,
44
- url: url$1,
16
+ federation: createFederation({ kv: new MemoryKvStore() }),
17
+ url,
45
18
  data: void 0,
46
19
  getActorUri(identifier) {
47
- return new URL(`${url$1.origin}/users/${identifier}`);
20
+ return new URL(`${url.origin}/users/${identifier}`);
48
21
  },
49
22
  async getActor(handle) {
50
23
  return await actorDispatcher(context, handle);
@@ -54,10 +27,9 @@ test("handleWebFinger()", async (t) => {
54
27
  if (uri.protocol === "acct:") return null;
55
28
  if (!uri.pathname.startsWith("/users/")) return null;
56
29
  const paths = uri.pathname.split("/");
57
- const identifier = paths[paths.length - 1];
58
30
  return {
59
31
  type: "actor",
60
- identifier
32
+ identifier: paths[paths.length - 1]
61
33
  };
62
34
  }
63
35
  });
@@ -89,11 +61,10 @@ test("handleWebFinger()", async (t) => {
89
61
  await t.step("no actor dispatcher", async () => {
90
62
  const context = createContext(url);
91
63
  const request = context.request;
92
- const response = await handleWebFinger(request, {
64
+ assertEquals((await handleWebFinger(request, {
93
65
  context,
94
66
  onNotFound
95
- });
96
- assertEquals(response.status, 404);
67
+ })).status, 404);
97
68
  assertEquals(onNotFoundCalled, request);
98
69
  });
99
70
  onNotFoundCalled = null;
@@ -113,8 +84,7 @@ test("handleWebFinger()", async (t) => {
113
84
  const u = new URL(url);
114
85
  u.searchParams.set("resource", " invalid ");
115
86
  const context = createContext(u);
116
- const request = new Request(u);
117
- const response = await handleWebFinger(request, {
87
+ const response = await handleWebFinger(new Request(u), {
118
88
  context,
119
89
  actorDispatcher,
120
90
  onNotFound
@@ -220,12 +190,11 @@ test("handleWebFinger()", async (t) => {
220
190
  u.searchParams.set("resource", "acct:no-one@example.com");
221
191
  const context = createContext(u);
222
192
  const request = context.request;
223
- const response = await handleWebFinger(request, {
193
+ assertEquals((await handleWebFinger(request, {
224
194
  context,
225
195
  actorDispatcher,
226
196
  onNotFound
227
- });
228
- assertEquals(response.status, 404);
197
+ })).status, 404);
229
198
  assertEquals(onNotFoundCalled, request);
230
199
  });
231
200
  onNotFoundCalled = null;
@@ -521,16 +490,14 @@ test("handleWebFinger()", async (t) => {
521
490
  onNotFound
522
491
  });
523
492
  assertEquals(response.status, 200);
524
- const result = await response.json();
525
- const expectedWithCustomLinks = {
493
+ assertEquals(await response.json(), {
526
494
  ...expected,
527
495
  links: [...expected.links, {
528
496
  rel: "http://ostatus.org/schema/1.0/subscribe",
529
497
  template: "https://example.com/follow?acct={uri}"
530
498
  }]
531
- };
532
- assertEquals(result, expectedWithCustomLinks);
499
+ });
533
500
  });
534
501
  });
535
-
536
- //#endregion
502
+ //#endregion
503
+ export {};
@@ -5,7 +5,6 @@ import { TracerProvider } from "@opentelemetry/api";
5
5
  import { DocumentLoader } from "@fedify/vocab-runtime";
6
6
 
7
7
  //#region src/sig/key.d.ts
8
-
9
8
  /**
10
9
  * Generates a key pair which is appropriate for Fedify.
11
10
  * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
@@ -238,9 +237,5 @@ interface HttpMessageSignaturesSpecDeterminer {
238
237
  */
239
238
  rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
240
239
  }
241
- /**
242
- * The options for double-knock requests.
243
- * @since 1.6.0
244
- */
245
240
  //#endregion
246
- export { FetchKeyOptions, FetchKeyResult, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignRequestOptions, VerifyRequestOptions, exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, verifyRequest };
241
+ export { signRequest as a, FetchKeyResult as c, fetchKey as d, generateCryptoKeyPair as f, VerifyRequestOptions as i, KeyCache as l, HttpMessageSignaturesSpecDeterminer as n, verifyRequest as o, importJwk as p, SignRequestOptions as r, FetchKeyOptions as s, HttpMessageSignaturesSpec as t, exportJwk as u };
@@ -1,130 +1,16 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
5
3
  import { getLogger } from "@logtape/logtape";
6
4
  import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
7
5
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
6
  import { encodeHex } from "byte-encodings/hex";
7
+ import { FetchError, getDocumentLoader } from "@fedify/vocab-runtime";
9
8
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
10
9
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
11
10
  import { Item, decodeDict, encodeItem } from "structured-field-values";
12
- import { getDocumentLoader } from "@fedify/vocab-runtime";
13
-
14
11
  //#region deno.json
15
12
  var name = "@fedify/fedify";
16
- var version = "2.0.7";
17
- var license = "MIT";
18
- var exports = {
19
- ".": "./src/mod.ts",
20
- "./compat": "./src/compat/mod.ts",
21
- "./federation": "./src/federation/mod.ts",
22
- "./nodeinfo": "./src/nodeinfo/mod.ts",
23
- "./otel": "./src/otel/mod.ts",
24
- "./runtime": "./src/runtime/mod.ts",
25
- "./sig": "./src/sig/mod.ts",
26
- "./utils": "./src/utils/mod.ts",
27
- "./vocab": "./src/vocab/mod.ts"
28
- };
29
- var imports = {
30
- "@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
31
- "@std/assert": "jsr:@std/assert@^0.226.0",
32
- "@std/url": "jsr:@std/url@^0.225.1",
33
- "asn1js": "npm:asn1js@^3.0.7",
34
- "fast-check": "npm:fast-check@^3.22.0",
35
- "fetch-mock": "npm:fetch-mock@^12.5.2",
36
- "json-canon": "npm:json-canon@^1.0.1",
37
- "jsonld": "npm:jsonld@^9.0.0",
38
- "pkijs": "npm:pkijs@^3.3.3",
39
- "structured-field-values": "npm:structured-field-values@^2.0.4",
40
- "uri-template-router": "npm:uri-template-router@^1.0.0",
41
- "url-template": "npm:url-template@^3.1.1"
42
- };
43
- var exclude = [
44
- ".test-report.xml",
45
- "apidoc/",
46
- "dist/",
47
- "node_modules/",
48
- "npm/",
49
- "pnpm-lock.yaml",
50
- "src/cfworkers/dist/",
51
- "src/cfworkers/fixtures/",
52
- "src/cfworkers/imports.ts",
53
- "src/cfworkers/README.md",
54
- "src/cfworkers/server.ts",
55
- "src/cfworkers/server.js",
56
- "src/cfworkers/server.js.map"
57
- ];
58
- var publish = { "exclude": [
59
- "**/*.test.ts",
60
- "src/testing/",
61
- "tsdown.config.ts",
62
- "scripts/",
63
- "wrangler.toml"
64
- ] };
65
- var tasks = {
66
- "codegen": "deno task -f @fedify/vocab compile",
67
- "cache": {
68
- "command": "deno cache src/mod.ts",
69
- "dependencies": ["codegen"]
70
- },
71
- "check": {
72
- "command": "deno fmt --check && deno lint && deno check src/**/*.ts",
73
- "dependencies": ["codegen"]
74
- },
75
- "test": {
76
- "command": "deno test --check --doc --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel",
77
- "dependencies": ["codegen"]
78
- },
79
- "coverage": "deno task test --clean --coverage && deno coverage --html coverage",
80
- "bench": {
81
- "command": "deno bench --allow-read --allow-write --allow-net --allow-env --allow-run --unstable-kv",
82
- "dependencies": ["codegen"]
83
- },
84
- "apidoc": {
85
- "command": "deno doc --html --name=Fedify --output=apidoc/ src/mod.ts",
86
- "dependencies": ["codegen"]
87
- },
88
- "publish": {
89
- "command": "deno publish",
90
- "dependencies": ["codegen"]
91
- },
92
- "pnpm:install": "pnpm install --silent",
93
- "pnpm:build": {
94
- "command": "pnpm exec tsdown",
95
- "dependencies": ["pnpm:build-vocab"]
96
- },
97
- "test:node": {
98
- "command": "cd dist/ && node --test",
99
- "dependencies": ["pnpm:build"]
100
- },
101
- "test:bun": {
102
- "command": "cd dist/ && bun test --timeout 60000",
103
- "dependencies": ["pnpm:build"]
104
- },
105
- "test:cfworkers": {
106
- "command": "pnpm exec wrangler deploy --dry-run --outdir src/cfworkers && node --import=tsx src/cfworkers/client.ts",
107
- "dependencies": ["pnpm:build"]
108
- },
109
- "test-all": { "dependencies": [
110
- "check",
111
- "test",
112
- "test:node",
113
- "test:bun",
114
- "test:cfworkers"
115
- ] }
116
- };
117
- var deno_default = {
118
- name,
119
- version,
120
- license,
121
- exports,
122
- imports,
123
- exclude,
124
- publish,
125
- tasks
126
- };
127
-
13
+ var version = "2.0.9";
128
14
  //#endregion
129
15
  //#region src/sig/key.ts
130
16
  /**
@@ -140,8 +26,7 @@ function validateCryptoKey(key, type) {
140
26
  if (!key.extractable) throw new TypeError("The key is not extractable.");
141
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!");
142
28
  if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
143
- const algorithm = key.algorithm;
144
- 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.");
29
+ if (key.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.");
145
30
  }
146
31
  }
147
32
  /**
@@ -220,8 +105,7 @@ async function importJwk(jwk, type) {
220
105
  * @since 1.3.0
221
106
  */
222
107
  function fetchKey(keyId, cls, options = {}) {
223
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
224
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
108
+ const tracer = (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version);
225
109
  keyId = typeof keyId === "string" ? new URL(keyId) : keyId;
226
110
  return tracer.startActiveSpan("activitypub.fetch_key", {
227
111
  kind: SpanKind.CLIENT,
@@ -277,8 +161,7 @@ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, key
277
161
  logger.debug("Fetching key {keyId} to verify signature...", { keyId });
278
162
  let document;
279
163
  try {
280
- const remoteDocument = await (documentLoader ?? getDocumentLoader())(keyId);
281
- document = remoteDocument.document;
164
+ document = (await (documentLoader ?? getDocumentLoader())(keyId)).document;
282
165
  } catch (_) {
283
166
  logger.debug("Failed to fetch key {keyId}.", { keyId });
284
167
  await keyCache?.set(cacheKey, null);
@@ -302,8 +185,8 @@ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, key
302
185
  contextLoader,
303
186
  tracerProvider
304
187
  });
305
- } catch (e$1) {
306
- if (e$1 instanceof TypeError) {
188
+ } catch (e) {
189
+ if (e instanceof TypeError) {
307
190
  logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
308
191
  await keyCache?.set(cacheKey, null);
309
192
  return {
@@ -311,7 +194,7 @@ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, key
311
194
  cached: false
312
195
  };
313
196
  }
314
- throw e$1;
197
+ throw e;
315
198
  }
316
199
  }
317
200
  let key = null;
@@ -374,9 +257,9 @@ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, key
374
257
  cached: false
375
258
  };
376
259
  }
377
-
378
260
  //#endregion
379
261
  //#region src/sig/http.ts
262
+ const DEFAULT_MAX_REDIRECTION = 20;
380
263
  /**
381
264
  * Signs a request using the given private key.
382
265
  * @param request The request to sign.
@@ -388,9 +271,7 @@ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, key
388
271
  */
389
272
  async function signRequest(request, privateKey, keyId, options = {}) {
390
273
  validateCryptoKey(privateKey, "private");
391
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
392
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
393
- return await tracer.startActiveSpan("http_signatures.sign", async (span) => {
274
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
394
275
  try {
395
276
  const spec = options.spec ?? "draft-cavage-http-signatures-12";
396
277
  let signed;
@@ -399,7 +280,7 @@ async function signRequest(request, privateKey, keyId, options = {}) {
399
280
  if (span.isRecording()) {
400
281
  span.setAttribute(ATTR_HTTP_REQUEST_METHOD, signed.method);
401
282
  span.setAttribute(ATTR_URL_FULL, signed.url);
402
- for (const [name$1, value] of signed.headers) span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name$1), value);
283
+ for (const [name, value] of signed.headers) span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name), value);
403
284
  span.setAttribute("http_signatures.key_id", keyId.href);
404
285
  }
405
286
  return signed;
@@ -427,8 +308,8 @@ async function signRequestDraft(request, privateKey, keyId, span, currentTime, b
427
308
  }
428
309
  if (!headers.has("Date")) headers.set("Date", currentTime == null ? (/* @__PURE__ */ new Date()).toUTCString() : new Date(currentTime.toString()).toUTCString());
429
310
  const serialized = [["(request-target)", `${request.method.toLowerCase()} ${url.pathname}`], ...headers];
430
- const headerNames = serialized.map(([name$1]) => name$1);
431
- const message = serialized.map(([name$1, value]) => `${name$1}: ${value.trim()}`).join("\n");
311
+ const headerNames = serialized.map(([name]) => name);
312
+ const message = serialized.map(([name, value]) => `${name}: ${value.trim()}`).join("\n");
432
313
  const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, new TextEncoder().encode(message));
433
314
  const sigHeader = `keyId="${keyId.href}",algorithm="rsa-sha256",headers="${headerNames.join(" ")}",signature="${encodeBase64(signature)}"`;
434
315
  headers.set("Signature", sigHeader);
@@ -485,9 +366,7 @@ function createRfc9421SignatureBase(request, components, parameters) {
485
366
  * @returns The formatted signature string.
486
367
  */
487
368
  function formatRfc9421Signature(signature, components, parameters) {
488
- const signatureInputValue = `sig1=("${components.join("\" \"")}");${parameters}`;
489
- const signatureValue = `sig1=:${encodeBase64(signature)}:`;
490
- return [signatureInputValue, signatureValue];
369
+ return [`sig1=("${components.join("\" \"")}");${parameters}`, `sig1=:${encodeBase64(signature)}:`];
491
370
  }
492
371
  /**
493
372
  * Parse RFC 9421 Signature-Input header.
@@ -617,13 +496,11 @@ const supportedHashAlgorithms = {
617
496
  * could not be verified.
618
497
  */
619
498
  async function verifyRequest(request, options = {}) {
620
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
621
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
622
- return await tracer.startActiveSpan("http_signatures.verify", async (span) => {
499
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.verify", async (span) => {
623
500
  if (span.isRecording()) {
624
501
  span.setAttribute(ATTR_HTTP_REQUEST_METHOD, request.method);
625
502
  span.setAttribute(ATTR_URL_FULL, request.url);
626
- for (const [name$1, value] of request.headers) span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name$1), value);
503
+ for (const [name, value] of request.headers) span.setAttribute(ATTR_HTTP_REQUEST_HEADER(name), value);
627
504
  }
628
505
  try {
629
506
  let spec = options.spec;
@@ -806,11 +683,10 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
806
683
  logger.debug("Failed to verify; required headers missing in the Signature header: {headers}.", { headers });
807
684
  return null;
808
685
  }
809
- const message = headerNames.map((name$1) => `${name$1}: ` + (name$1 === "(request-target)" ? `${request.method.toLowerCase()} ${new URL(request.url).pathname}` : name$1 === "(created)" ? sigValues.created ?? "" : name$1 === "(expires)" ? sigValues.expires ?? "" : name$1 === "host" ? request.headers.get("host") ?? new URL(request.url).host : request.headers.get(name$1))).join("\n");
686
+ const message = headerNames.map((name) => `${name}: ` + (name === "(request-target)" ? `${request.method.toLowerCase()} ${new URL(request.url).pathname}` : name === "(created)" ? sigValues.created ?? "" : name === "(expires)" ? sigValues.expires ?? "" : name === "host" ? request.headers.get("host") ?? new URL(request.url).host : request.headers.get(name))).join("\n");
810
687
  const sig = decodeBase64(signature);
811
688
  span?.setAttribute("http_signatures.signature", encodeHex(sig));
812
- const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, sig, new TextEncoder().encode(message));
813
- if (!verified) {
689
+ if (!await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, sig, new TextEncoder().encode(message))) {
814
690
  if (cached) {
815
691
  logger.debug("Failed to verify with the cached key {keyId}; signature {signature} is invalid. Retrying with the freshly fetched key...", {
816
692
  keyId,
@@ -824,7 +700,7 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
824
700
  currentTime,
825
701
  keyCache: {
826
702
  get: () => Promise.resolve(void 0),
827
- set: async (keyId$1, key$1) => await keyCache?.set(keyId$1, key$1)
703
+ set: async (keyId, key) => await keyCache?.set(keyId, key)
828
704
  }
829
705
  });
830
706
  }
@@ -974,9 +850,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
974
850
  logger.debug("Failed to verify; Content-Digest header required but not found.", { components: sigInput.components });
975
851
  continue;
976
852
  }
977
- const body = await request.arrayBuffer();
978
- const digestValid = await verifyRfc9421ContentDigest(contentDigestHeader, body);
979
- if (!digestValid) {
853
+ if (!await verifyRfc9421ContentDigest(contentDigestHeader, await request.arrayBuffer())) {
980
854
  logger.debug("Failed to verify; Content-Digest verification failed.", { contentDigest: contentDigestHeader });
981
855
  continue;
982
856
  }
@@ -1022,8 +896,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
1022
896
  const signatureBaseBytes = new TextEncoder().encode(signatureBase);
1023
897
  span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
1024
898
  try {
1025
- const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes);
1026
- if (verified) {
899
+ if (await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes)) {
1027
900
  validKey = key;
1028
901
  break;
1029
902
  } else if (cached) {
@@ -1035,7 +908,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
1035
908
  currentTime,
1036
909
  keyCache: {
1037
910
  get: () => Promise.resolve(void 0),
1038
- set: async (keyId, key$1) => await keyCache?.set(keyId, key$1)
911
+ set: async (keyId, key) => await keyCache?.set(keyId, key)
1039
912
  },
1040
913
  spec: "rfc9421"
1041
914
  });
@@ -1088,7 +961,11 @@ function createRedirectRequest(request, location, body) {
1088
961
  * @since 1.6.0
1089
962
  */
1090
963
  async function doubleKnock(request, identity, options = {}) {
964
+ return await doubleKnockInternal(request, identity, options);
965
+ }
966
+ async function doubleKnockInternal(request, identity, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
1091
967
  const { specDeterminer, log, tracerProvider, signal } = options;
968
+ visited.add(request.url);
1092
969
  const origin = new URL(request.url).origin;
1093
970
  const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
1094
971
  const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
@@ -1103,11 +980,13 @@ async function doubleKnock(request, identity, options = {}) {
1103
980
  signal
1104
981
  });
1105
982
  if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
1106
- const location = response.headers.get("Location");
1107
- return doubleKnock(createRedirectRequest(request, location, body), identity, {
983
+ if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
984
+ const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
985
+ if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
986
+ return doubleKnockInternal(redirectRequest, identity, {
1108
987
  ...options,
1109
988
  body
1110
- });
989
+ }, redirected + 1, visited);
1111
990
  } else if (response.status === 400 || response.status === 401 || response.status > 401) {
1112
991
  const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
1113
992
  getLogger([
@@ -1131,11 +1010,13 @@ async function doubleKnock(request, identity, options = {}) {
1131
1010
  signal
1132
1011
  });
1133
1012
  if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
1134
- const location = response.headers.get("Location");
1135
- return doubleKnock(createRedirectRequest(request, location, body), identity, {
1013
+ if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
1014
+ const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
1015
+ if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
1016
+ return doubleKnockInternal(redirectRequest, identity, {
1136
1017
  ...options,
1137
1018
  body
1138
- });
1019
+ }, redirected + 1, visited);
1139
1020
  } else if (response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
1140
1021
  } else await specDeterminer?.rememberSpec(origin, firstTrySpec);
1141
1022
  return response;
@@ -1167,6 +1048,5 @@ function timingSafeEqual(a, b) {
1167
1048
  result |= lenA ^ lenB;
1168
1049
  return result === 0;
1169
1050
  }
1170
-
1171
1051
  //#endregion
1172
- export { deno_default, doubleKnock, exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, validateCryptoKey, verifyRequest };
1052
+ export { fetchKey as a, validateCryptoKey as c, exportJwk as i, name as l, signRequest as n, generateCryptoKeyPair as o, verifyRequest as r, importJwk as s, doubleKnock as t, version as u };
@@ -3,7 +3,6 @@ import { DocumentLoader } from "@fedify/vocab-runtime";
3
3
  import { TracerProvider } from "@opentelemetry/api";
4
4
 
5
5
  //#region src/sig/key.d.ts
6
-
7
6
  /**
8
7
  * Generates a key pair which is appropriate for Fedify.
9
8
  * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
@@ -236,9 +235,5 @@ interface HttpMessageSignaturesSpecDeterminer {
236
235
  */
237
236
  rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
238
237
  }
239
- /**
240
- * The options for double-knock requests.
241
- * @since 1.6.0
242
- */
243
238
  //#endregion
244
- export { FetchKeyOptions, FetchKeyResult, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignRequestOptions, VerifyRequestOptions, exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, verifyRequest };
239
+ export { signRequest as a, FetchKeyResult as c, fetchKey as d, generateCryptoKeyPair as f, VerifyRequestOptions as i, KeyCache as l, HttpMessageSignaturesSpecDeterminer as n, verifyRequest as o, importJwk as p, SignRequestOptions as r, FetchKeyOptions as s, HttpMessageSignaturesSpec as t, exportJwk as u };