@fedify/fedify 2.3.0-dev.994 → 2.3.0-pr.809.37

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 (138) hide show
  1. package/README.md +16 -7
  2. package/dist/{assert-DikXweDx.mjs → assert-OguE97r2.mjs} +1 -1
  3. package/dist/{assert_instance_of-C4Ri6VuN.mjs → assert_instance_of-DBC5X09g.mjs} +1 -1
  4. package/dist/{assert_not_equals--wG9hV7u.mjs → assert_not_equals-DkVK8oqV.mjs} +1 -1
  5. package/dist/{assert_rejects-B-qJtC9Z.mjs → assert_rejects-DN60FHPX.mjs} +28 -3
  6. package/dist/{assert_strict_equals-Dmjbg-bA.mjs → assert_strict_equals-XEgZAlrj.mjs} +1 -1
  7. package/dist/{assert_throws-4NwKEy2q.mjs → assert_throws-BOkhLGYc.mjs} +1 -1
  8. package/dist/{builder-yAlpiIqP.mjs → builder-Dl5Sdmc9.mjs} +96 -42
  9. package/dist/{chunk-nlSIicah.js → chunk-CRNNMoPX.js} +2 -2
  10. package/dist/circuit-breaker-CSWsyoef.mjs +337 -0
  11. package/dist/{client-z-8dc-e1.d.cts → client-CAM_bQXx.d.cts} +1 -0
  12. package/dist/{client-AtlibPOU.d.ts → client-CSddvgWN.d.ts} +1 -2
  13. package/dist/compat/mod.d.cts +2 -1
  14. package/dist/compat/mod.d.ts +2 -3
  15. package/dist/compat/mod.js +3 -3
  16. package/dist/compat/outgoing-jsonld.test.mjs +4 -4
  17. package/dist/compat/public-audience.test.mjs +4 -4
  18. package/dist/compat/transformers.test.mjs +5 -5
  19. package/dist/{context-BzH2-ajs.d.ts → context-BBVLF7lx.d.cts} +342 -269
  20. package/dist/{context-DJGagtNd.d.cts → context-BU6jSQdo.d.ts} +344 -266
  21. package/dist/{context-Dk_tacqz.mjs → context-DVoTs_wM.mjs} +64 -5
  22. package/dist/{deno-XBVlKnOX.mjs → deno-BID9qTPk.mjs} +1 -1
  23. package/dist/{docloader-DPp-X6gk.mjs → docloader-BYFuVwwi.mjs} +4 -4
  24. package/dist/{esm-DVILvP5e.mjs → esm-vrlUxr60.mjs} +4 -7
  25. package/dist/federation/builder.test.mjs +163 -11
  26. package/dist/federation/circuit-breaker.test.d.mts +2 -0
  27. package/dist/federation/circuit-breaker.test.mjs +446 -0
  28. package/dist/federation/collection.test.mjs +3 -3
  29. package/dist/federation/handler.test.mjs +1770 -29
  30. package/dist/federation/idempotency.test.mjs +5 -5
  31. package/dist/federation/inbox.test.mjs +4 -4
  32. package/dist/federation/keycache.test.mjs +5 -5
  33. package/dist/federation/kv.test.mjs +2 -2
  34. package/dist/federation/metrics.test.d.mts +2 -0
  35. package/dist/federation/metrics.test.mjs +634 -0
  36. package/dist/federation/middleware.test.mjs +4036 -146
  37. package/dist/federation/mod.cjs +195 -14
  38. package/dist/federation/mod.d.cts +6 -4
  39. package/dist/federation/mod.d.ts +6 -6
  40. package/dist/federation/mod.js +192 -14
  41. package/dist/federation/mq.test.mjs +176 -15
  42. package/dist/federation/negotiation.test.mjs +4 -4
  43. package/dist/federation/retry.test.mjs +3 -3
  44. package/dist/federation/router.test.mjs +190 -9
  45. package/dist/federation/send.test.mjs +153 -15
  46. package/dist/federation/temporal.test.d.mts +2 -0
  47. package/dist/federation/temporal.test.mjs +71 -0
  48. package/dist/federation/webfinger.test.mjs +150 -5
  49. package/dist/{http-B4rrzxtg.js → http-B47Jg9iX.js} +994 -64
  50. package/dist/{http-CSlLA54v.mjs → http-CO59u1Yk.mjs} +146 -47
  51. package/dist/{http-BrGqJDXL.cjs → http-CjZwUPiT.cjs} +1099 -61
  52. package/dist/{http-aQzN9Ayi.d.ts → http-VyDTd4G3.d.cts} +15 -3
  53. package/dist/{http-CrGuipxe.d.cts → http-lf8Hsd91.d.ts} +15 -1
  54. package/dist/{key-Bzx--sHD.mjs → key-Dqdlo3mG.mjs} +43 -18
  55. package/dist/{kv-CbLNp3zQ.d.cts → kv-D6hNiMTK.d.ts} +1 -0
  56. package/dist/{kv-cache-DI-Sk7-I.cjs → kv-cache-BQ1-zDKX.cjs} +20 -3
  57. package/dist/{kv-cache-EMIqoIuB.js → kv-cache-Dh2ZH9Gr.js} +20 -3
  58. package/dist/{kv-cache-U__xU4qR.mjs → kv-cache-DhLkLv0P.mjs} +21 -3
  59. package/dist/{kv-GFYnFoOl.d.ts → kv-gJ8LYbxX.d.cts} +1 -3
  60. package/dist/ld-JbCByP5P.mjs +626 -0
  61. package/dist/metrics-ColY3QKj.mjs +815 -0
  62. package/dist/{middleware-zjZ6AFCW.mjs → middleware-Buqzuiaf.mjs} +1 -1
  63. package/dist/{middleware-An4DjES4.cjs → middleware-CWQ3Yi07.cjs} +2318 -623
  64. package/dist/{middleware-K1g6bEkV.mjs → middleware-Cg4EyWsq.mjs} +1639 -373
  65. package/dist/{middleware-nidH7VZH.js → middleware-iAJY2aU-.js} +2260 -556
  66. package/dist/{mod-CR8soWa9.d.ts → mod-B0hW12_O.d.cts} +26 -4
  67. package/dist/mod-C0F6kvgS.d.cts +182 -0
  68. package/dist/{mod-Cr3f-ACa.d.cts → mod-COIAjwRS.d.ts} +26 -2
  69. package/dist/{mod-CMEbIaNh.d.cts → mod-DFvNJcNb.d.ts} +56 -4
  70. package/dist/mod-vPYVoa5n.d.ts +182 -0
  71. package/dist/{mod-CLgIXe9w.d.ts → mod-yvIXFAEi.d.cts} +56 -6
  72. package/dist/mod.cjs +9 -6
  73. package/dist/mod.d.cts +12 -10
  74. package/dist/mod.d.ts +12 -12
  75. package/dist/mod.js +11 -11
  76. package/dist/mq-D-nlpY04.d.ts +208 -0
  77. package/dist/mq-D8uSFzxe.d.cts +208 -0
  78. package/dist/{negotiation-SQvQgUqe.mjs → negotiation-DDstyBvc.mjs} +29 -0
  79. package/dist/nodeinfo/client.test.mjs +4 -4
  80. package/dist/nodeinfo/handler.test.mjs +4 -4
  81. package/dist/nodeinfo/mod.d.cts +2 -1
  82. package/dist/nodeinfo/mod.d.ts +2 -3
  83. package/dist/nodeinfo/mod.js +3 -3
  84. package/dist/nodeinfo/types.test.mjs +3 -3
  85. package/dist/otel/exporter.test.mjs +28 -25
  86. package/dist/otel/mod.cjs +6 -5
  87. package/dist/otel/mod.d.cts +5 -3
  88. package/dist/otel/mod.d.ts +5 -5
  89. package/dist/otel/mod.js +8 -7
  90. package/dist/{outgoing-jsonld-CNmZLixq.mjs → outgoing-jsonld-L_DbOaFe.mjs} +2 -2
  91. package/dist/{owner-C-tqfvxn.mjs → owner-B4LgOmzV.mjs} +2 -2
  92. package/dist/{owner-CptqhsOy.d.cts → owner-CnngXDNJ.d.ts} +2 -1
  93. package/dist/{owner-74ARJ5TL.d.ts → owner-DEvZuyOE.d.cts} +2 -3
  94. package/dist/{proof-BlmRPzrK.mjs → proof-BoSGOq9q.mjs} +26 -8
  95. package/dist/{proof-Bbbwf8_x.js → proof-CzhZuawt.js} +378 -15
  96. package/dist/{proof-BW89QMVB.cjs → proof-DvMI-3vq.cjs} +432 -15
  97. package/dist/runtime/mod.d.cts +1 -0
  98. package/dist/runtime/mod.d.ts +1 -2
  99. package/dist/runtime/mod.js +3 -3
  100. package/dist/{send-05pJLcb6.mjs → send-ByK1Q7DK.mjs} +72 -26
  101. package/dist/sig/http.test.mjs +356 -33
  102. package/dist/sig/key.test.mjs +103 -6
  103. package/dist/sig/ld.test.mjs +696 -7
  104. package/dist/sig/mod.cjs +2 -2
  105. package/dist/sig/mod.d.cts +4 -3
  106. package/dist/sig/mod.d.ts +4 -5
  107. package/dist/sig/mod.js +4 -4
  108. package/dist/sig/owner.test.mjs +6 -6
  109. package/dist/sig/proof.test.mjs +169 -8
  110. package/dist/{std__assert-CRDpx_HF.mjs → std__assert-BBjXFNOb.mjs} +5 -30
  111. package/dist/temporal-LpjyAjKb.mjs +95 -0
  112. package/dist/testing/mod.d.mts +110 -10
  113. package/dist/testing/mod.mjs +1 -2
  114. package/dist/{transformers-ve6e2xcg.js → transformers-BGMIq1cs.js} +2 -2
  115. package/dist/{types-hvL8ElAs.js → types-CAY3OdLq.js} +2 -2
  116. package/dist/utils/docloader.test.mjs +6 -6
  117. package/dist/utils/kv-cache.test.mjs +67 -2
  118. package/dist/utils/mod.cjs +1 -1
  119. package/dist/utils/mod.d.cts +2 -1
  120. package/dist/utils/mod.d.ts +2 -3
  121. package/dist/utils/mod.js +3 -3
  122. package/dist/vocab/cjs.test.mjs +1 -1
  123. package/dist/vocab/mod.d.cts +1 -0
  124. package/dist/vocab/mod.d.ts +1 -2
  125. package/dist/vocab/mod.js +2 -2
  126. package/package.json +16 -16
  127. package/dist/ld-DR78beiv.mjs +0 -279
  128. package/dist/middleware-BFBaR0mF.cjs +0 -4
  129. package/dist/mod-2d12ffz3.d.ts +0 -64
  130. package/dist/mod-D35TRn09.d.cts +0 -62
  131. package/dist/router-CrMLXoOr.mjs +0 -114
  132. package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  133. package/dist/{assert_equals-Ew3jOFa3.mjs → assert_equals-C-ZRDbaf.mjs} +0 -0
  134. package/dist/{client-D_1QpnWt.mjs → client-ByXmQhYD.mjs} +1 -1
  135. package/dist/{collection-D-HqUuA2.mjs → collection-Cc3DVAhE.mjs} +0 -0
  136. package/dist/{keycache-EGATflN-.mjs → keycache-BeU0LCII.mjs} +0 -0
  137. package/dist/{public-audience-DYFHzm_c.mjs → public-audience-Cvbr2Gzt.mjs} +1 -1
  138. /package/dist/{retry-bMXBL97A.mjs → retry-CXg_MBI-.mjs} +0 -0
@@ -1,13 +1,13 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
- import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import "../std__assert-CRDpx_HF.mjs";
7
- import { t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
8
- import { l as verifyRequest } from "../http-CSlLA54v.mjs";
4
+ import { t as esm_default } from "../esm-vrlUxr60.mjs";
5
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
+ import "../std__assert-BBjXFNOb.mjs";
7
+ import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
8
+ import { l as verifyRequest } from "../http-CO59u1Yk.mjs";
9
9
  import { i as rsaPrivateKey2 } from "../keys-DGu1NFwu.mjs";
10
- import { t as getAuthenticatedDocumentLoader } from "../docloader-DPp-X6gk.mjs";
10
+ import { t as getAuthenticatedDocumentLoader } from "../docloader-BYFuVwwi.mjs";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  import { UrlError } from "@fedify/vocab-runtime";
13
13
  //#region src/utils/docloader.test.ts
@@ -1,9 +1,9 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as kvCache, t as MockKvStore } from "../kv-cache-U__xU4qR.mjs";
5
- import { mockDocumentLoader, test } from "@fedify/fixture";
4
+ import { n as kvCache, t as MockKvStore } from "../kv-cache-DhLkLv0P.mjs";
6
5
  import { deepStrictEqual, throws } from "node:assert";
6
+ import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
7
7
  import { preloadedContexts } from "@fedify/vocab-runtime";
8
8
  //#region src/utils/kv-cache.test.ts
9
9
  test("kvCache()", async (t) => {
@@ -139,6 +139,71 @@ test("kvCache()", async (t) => {
139
139
  }
140
140
  });
141
141
  });
142
+ await t.step("records activitypub.document.cache with miss then hit", async () => {
143
+ const kv = new MockKvStore();
144
+ const [meterProvider, recorder] = createTestMeterProvider();
145
+ const loader = kvCache({
146
+ kv,
147
+ loader: mockDocumentLoader,
148
+ rules: [["https://example.com/object", { days: 1 }]],
149
+ prefix: ["_test", "doc-cache"],
150
+ meterProvider,
151
+ kind: "object"
152
+ });
153
+ await loader("https://example.com/object");
154
+ const afterMiss = recorder.getMeasurements("activitypub.document.cache");
155
+ deepStrictEqual(afterMiss.length, 1);
156
+ deepStrictEqual(afterMiss[0].type, "counter");
157
+ deepStrictEqual(afterMiss[0].value, 1);
158
+ deepStrictEqual(afterMiss[0].attributes["activitypub.lookup.kind"], "object");
159
+ deepStrictEqual(afterMiss[0].attributes["activitypub.lookup.result"], "miss");
160
+ deepStrictEqual(afterMiss[0].attributes["activitypub.remote.host"], "example.com");
161
+ await loader("https://example.com/object");
162
+ const all = recorder.getMeasurements("activitypub.document.cache");
163
+ deepStrictEqual(all.length, 2);
164
+ deepStrictEqual(all[1].attributes["activitypub.lookup.result"], "hit");
165
+ deepStrictEqual(all[1].attributes["activitypub.lookup.kind"], "object");
166
+ deepStrictEqual(all[1].attributes["activitypub.remote.host"], "example.com");
167
+ });
168
+ await t.step("preloaded contexts emit no activitypub.document.cache", async () => {
169
+ const kv = new MockKvStore();
170
+ const [meterProvider, recorder] = createTestMeterProvider();
171
+ await kvCache({
172
+ kv,
173
+ loader: mockDocumentLoader,
174
+ prefix: ["_test", "doc-cache-preloaded"],
175
+ meterProvider,
176
+ kind: "context"
177
+ })("https://www.w3.org/ns/activitystreams");
178
+ deepStrictEqual(recorder.getMeasurements("activitypub.document.cache").length, 0, "preloaded contexts must bypass the KV cache and the cache metric");
179
+ });
180
+ await t.step("no cache rule match emits no activitypub.document.cache", async () => {
181
+ const kv = new MockKvStore();
182
+ const [meterProvider, recorder] = createTestMeterProvider();
183
+ await kvCache({
184
+ kv,
185
+ loader: mockDocumentLoader,
186
+ rules: [],
187
+ prefix: ["_test", "doc-cache-no-rule"],
188
+ meterProvider,
189
+ kind: "object"
190
+ })("https://example.com/object");
191
+ deepStrictEqual(recorder.getMeasurements("activitypub.document.cache").length, 0);
192
+ });
193
+ await t.step("omitting meterProvider records no cache measurements", async () => {
194
+ const kv = new MockKvStore();
195
+ const [meterProvider, recorder] = createTestMeterProvider();
196
+ const loader = kvCache({
197
+ kv,
198
+ loader: mockDocumentLoader,
199
+ rules: [["https://example.com/object", { days: 1 }]],
200
+ prefix: ["_test", "doc-cache-no-mp"]
201
+ });
202
+ await loader("https://example.com/object");
203
+ await loader("https://example.com/object");
204
+ deepStrictEqual(recorder.getMeasurements("activitypub.document.cache").length, 0);
205
+ deepStrictEqual(typeof meterProvider.getMeter, "function");
206
+ });
142
207
  await t.step("preloaded contexts bypass cache", async () => {
143
208
  const kv = new MockKvStore();
144
209
  let loaderCalled = false;
@@ -1,6 +1,6 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_kv_cache = require("../kv-cache-DI-Sk7-I.cjs");
4
+ const require_kv_cache = require("../kv-cache-BQ1-zDKX.cjs");
5
5
  exports.getAuthenticatedDocumentLoader = require_kv_cache.getAuthenticatedDocumentLoader;
6
6
  exports.kvCache = require_kv_cache.kvCache;
@@ -1,2 +1,3 @@
1
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-CMEbIaNh.cjs";
1
+ /// <reference lib="esnext.temporal" />
2
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-yvIXFAEi.cjs";
2
3
  export { getAuthenticatedDocumentLoader, kvCache };
@@ -1,4 +1,3 @@
1
- import { Temporal } from "@js-temporal/polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
3
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-CLgIXe9w.js";
1
+ /// <reference lib="esnext.temporal" />
2
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-DFvNJcNb.js";
4
3
  export { getAuthenticatedDocumentLoader, kvCache };
package/dist/utils/mod.js CHANGED
@@ -1,4 +1,4 @@
1
- import "@js-temporal/polyfill";
2
- import "urlpattern-polyfill";
3
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-EMIqoIuB.js";
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
3
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-Dh2ZH9Gr.js";
4
4
  export { getAuthenticatedDocumentLoader, kvCache };
@@ -2,8 +2,8 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { createRequire } from "node:module";
5
- import { test } from "@fedify/fixture";
6
5
  import { strictEqual } from "node:assert";
6
+ import { test } from "@fedify/fixture";
7
7
  //#region src/vocab/cjs.test.ts
8
8
  test("CommonJS vocab entry exports Object", { ignore: "Deno" in globalThis }, () => {
9
9
  const vocab = createRequire(import.meta.url)("./mod.cjs");
@@ -1 +1,2 @@
1
+ /// <reference lib="esnext.temporal" />
1
2
  export * from "@fedify/vocab";
@@ -1,3 +1,2 @@
1
- import { Temporal } from "@js-temporal/polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
1
+ /// <reference lib="esnext.temporal" />
3
2
  export * from "@fedify/vocab";
package/dist/vocab/mod.js CHANGED
@@ -1,3 +1,3 @@
1
- import "@js-temporal/polyfill";
2
- import "urlpattern-polyfill";
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
3
3
  export * from "@fedify/vocab";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "2.3.0-dev.994+9071ca0a",
3
+ "version": "2.3.0-pr.809.37+0574ba5c",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -140,22 +140,22 @@
140
140
  },
141
141
  "dependencies": {
142
142
  "@js-temporal/polyfill": "^0.5.1",
143
- "@logtape/logtape": "^2.0.5",
144
- "@opentelemetry/api": "^1.9.0",
145
- "@opentelemetry/core": "^2.5.0",
146
- "@opentelemetry/sdk-trace-base": "^2.5.0",
147
- "@opentelemetry/semantic-conventions": "^1.39.0",
143
+ "@logtape/logtape": "^2.1.0",
144
+ "@opentelemetry/api": "^1.9.1",
145
+ "@opentelemetry/core": "^2.7.1",
146
+ "@opentelemetry/sdk-metrics": "2.7.1",
147
+ "@opentelemetry/sdk-trace-base": "^2.7.1",
148
+ "@opentelemetry/semantic-conventions": "^1.40.0",
148
149
  "byte-encodings": "^1.0.11",
149
- "es-toolkit": "1.43.0",
150
+ "es-toolkit": "1.46.1",
150
151
  "json-canon": "^1.0.1",
151
152
  "jsonld": "^9.0.0",
152
153
  "structured-field-values": "^2.0.4",
153
- "uri-template-router": "^1.0.0",
154
- "url-template": "^3.1.1",
155
154
  "urlpattern-polyfill": "^10.1.0",
156
- "@fedify/vocab-runtime": "2.3.0-dev.994+9071ca0a",
157
- "@fedify/webfinger": "2.3.0-dev.994+9071ca0a",
158
- "@fedify/vocab": "2.3.0-dev.994+9071ca0a"
155
+ "@fedify/uri-template": "2.3.0-pr.809.37+0574ba5c",
156
+ "@fedify/vocab": "2.3.0-pr.809.37+0574ba5c",
157
+ "@fedify/webfinger": "2.3.0-pr.809.37+0574ba5c",
158
+ "@fedify/vocab-runtime": "2.3.0-pr.809.37+0574ba5c"
159
159
  },
160
160
  "devDependencies": {
161
161
  "@std/assert": "npm:@jsr/std__assert@^0.226.0",
@@ -163,12 +163,12 @@
163
163
  "@types/node": "^24.2.1",
164
164
  "fetch-mock": "^12.5.4",
165
165
  "miniflare": "^4.20250523.0",
166
- "tsdown": "^0.21.6",
167
- "tsx": "^4.19.4",
168
- "typescript": "^5.9.2",
166
+ "tsdown": "^0.22.0",
167
+ "tsx": "^4.21.0",
168
+ "typescript": "^6.0.0",
169
169
  "wrangler": "^4.17.0",
170
170
  "@fedify/fixture": "2.0.0",
171
- "@fedify/vocab-tools": "^2.3.0-dev.994+9071ca0a"
171
+ "@fedify/vocab-tools": "^2.3.0-pr.809.37+0574ba5c"
172
172
  },
173
173
  "scripts": {
174
174
  "build:self": "tsdown",
@@ -1,279 +0,0 @@
1
- import "@js-temporal/polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-XBVlKnOX.mjs";
5
- import { n as fetchKey, o as validateCryptoKey } from "./key-Bzx--sHD.mjs";
6
- import { Activity, CryptographicKey, Object as Object$1, getTypeId } from "@fedify/vocab";
7
- import { SpanStatusCode, trace } from "@opentelemetry/api";
8
- import { getDocumentLoader } from "@fedify/vocab-runtime";
9
- import { getLogger } from "@logtape/logtape";
10
- import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
11
- import { encodeHex } from "byte-encodings/hex";
12
- import jsonld from "@fedify/vocab-runtime/jsonld";
13
- //#region src/sig/ld.ts
14
- const logger = getLogger([
15
- "fedify",
16
- "sig",
17
- "ld"
18
- ]);
19
- /**
20
- * Attaches a LD signature to the given JSON-LD document.
21
- * @param jsonLd The JSON-LD document to attach the signature to. It is not
22
- * modified.
23
- * @param signature The signature to attach.
24
- * @returns The JSON-LD document with the attached signature.
25
- * @throws {TypeError} If the input document is not a valid JSON-LD document.
26
- * @since 1.0.0
27
- */
28
- function attachSignature(jsonLd, signature) {
29
- if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
30
- return {
31
- ...jsonLd,
32
- signature
33
- };
34
- }
35
- /**
36
- * Creates a LD signature for the given JSON-LD document.
37
- * @param jsonLd The JSON-LD document to sign.
38
- * @param privateKey The private key to sign the document.
39
- * @param keyId The ID of the public key that corresponds to the private key.
40
- * @param options Additional options for creating the signature.
41
- * See also {@link CreateSignatureOptions}.
42
- * @return The created signature.
43
- * @throws {TypeError} If the private key is invalid or unsupported.
44
- * @since 1.0.0
45
- */
46
- async function createSignature(jsonLd, privateKey, keyId, { contextLoader, created } = {}) {
47
- validateCryptoKey(privateKey, "private");
48
- if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
49
- const options = {
50
- "@context": "https://w3id.org/identity/v1",
51
- creator: keyId.href,
52
- created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
53
- };
54
- const message = await hashJsonLd(options, contextLoader) + await hashJsonLd(jsonLd, contextLoader);
55
- const messageBytes = new TextEncoder().encode(message);
56
- const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
57
- return {
58
- ...options,
59
- type: "RsaSignature2017",
60
- signatureValue: encodeBase64(signature)
61
- };
62
- }
63
- /**
64
- * Signs the given JSON-LD document with the private key and returns the signed
65
- * JSON-LD document.
66
- * @param jsonLd The JSON-LD document to sign.
67
- * @param privateKey The private key to sign the document.
68
- * @param keyId The key ID to use in the signature. It will be used by the
69
- * verifier to fetch the corresponding public key.
70
- * @param options Additional options for signing the document.
71
- * See also {@link SignJsonLdOptions}.
72
- * @returns The signed JSON-LD document.
73
- * @throws {TypeError} If the private key is invalid or unsupported.
74
- * @since 1.0.0
75
- */
76
- async function signJsonLd(jsonLd, privateKey, keyId, options) {
77
- return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.sign", { attributes: { "ld_signatures.key_id": keyId.href } }, async (span) => {
78
- try {
79
- const signature = await createSignature(jsonLd, privateKey, keyId, options);
80
- if (span.isRecording()) {
81
- span.setAttribute("ld_signatures.type", signature.type);
82
- span.setAttribute("ld_signatures.signature", encodeHex(decodeBase64(signature.signatureValue)));
83
- }
84
- return attachSignature(jsonLd, signature);
85
- } catch (error) {
86
- span.setStatus({
87
- code: SpanStatusCode.ERROR,
88
- message: String(error)
89
- });
90
- throw error;
91
- } finally {
92
- span.end();
93
- }
94
- });
95
- }
96
- /**
97
- * Checks if the given JSON-LD document has a Linked Data Signature-like
98
- * object, without restricting it to a single suite-specific shape.
99
- * @param jsonLd The JSON-LD document to check.
100
- * @returns `true` if the document has a signature-like object; `false`
101
- * otherwise.
102
- * @since 2.2.0
103
- */
104
- function hasSignatureLike(jsonLd) {
105
- if (typeof jsonLd !== "object" || jsonLd == null) return false;
106
- const signature = jsonLd.signature;
107
- const hasReference = (value) => {
108
- if (typeof value === "string") return true;
109
- if (Array.isArray(value)) return value.some(hasReference);
110
- return typeof value === "object" && value != null && ("id" in value && typeof value.id === "string" || "@id" in value && typeof value["@id"] === "string");
111
- };
112
- const hasSignatureObject = (value) => {
113
- if (typeof value !== "object" || value == null) return false;
114
- const signatureRecord = value;
115
- return (typeof signatureRecord.type === "string" || Array.isArray(signatureRecord.type) && signatureRecord.type.some((item) => typeof item === "string")) && (hasReference(signatureRecord.creator) || hasReference(signatureRecord.verificationMethod)) && (typeof signatureRecord.signatureValue === "string" || typeof signatureRecord.jws === "string");
116
- };
117
- return Array.isArray(signature) ? signature.some(hasSignatureObject) : hasSignatureObject(signature);
118
- }
119
- /**
120
- * Checks if the given JSON-LD document has a Linked Data Signature.
121
- * @param jsonLd The JSON-LD document to check.
122
- * @returns `true` if the document has a signature; `false` otherwise.
123
- * @since 1.0.0
124
- */
125
- function hasSignature(jsonLd) {
126
- if (typeof jsonLd !== "object" || jsonLd == null) return false;
127
- if ("signature" in jsonLd) {
128
- const signature = jsonLd.signature;
129
- if (typeof signature !== "object" || signature == null) return false;
130
- return "type" in signature && signature.type === "RsaSignature2017" && "creator" in signature && typeof signature.creator === "string" && "created" in signature && typeof signature.created === "string" && "signatureValue" in signature && typeof signature.signatureValue === "string";
131
- }
132
- return false;
133
- }
134
- /**
135
- * Detaches Linked Data Signatures from the given JSON-LD document.
136
- * @param jsonLd The JSON-LD document to modify.
137
- * @returns The modified JSON-LD document. If the input document does not
138
- * contain a signature, the original document is returned.
139
- * @since 1.0.0
140
- */
141
- function detachSignature(jsonLd) {
142
- if (typeof jsonLd !== "object" || jsonLd == null) return jsonLd;
143
- const doc = { ...jsonLd };
144
- delete doc.signature;
145
- return doc;
146
- }
147
- /**
148
- * Verifies Linked Data Signatures of the given JSON-LD document.
149
- * @param jsonLd The JSON-LD document to verify.
150
- * @param options Options for verifying the signature.
151
- * @returns The public key that signed the document or `null` if the signature
152
- * is invalid or the key is not found.
153
- * @since 1.0.0
154
- */
155
- async function verifySignature(jsonLd, options = {}) {
156
- if (!hasSignature(jsonLd)) return null;
157
- const sig = jsonLd.signature;
158
- let signature;
159
- try {
160
- signature = decodeBase64(sig.signatureValue);
161
- } catch (error) {
162
- logger.debug("Failed to verify; invalid base64 signatureValue: {signatureValue}", {
163
- ...sig,
164
- error
165
- });
166
- return null;
167
- }
168
- const { key, cached } = await fetchKey(new URL(sig.creator), CryptographicKey, options);
169
- if (key == null) return null;
170
- const sigOpts = {
171
- ...sig,
172
- "@context": "https://w3id.org/identity/v1"
173
- };
174
- delete sigOpts.type;
175
- delete sigOpts.id;
176
- delete sigOpts.signatureValue;
177
- let sigOptsHash;
178
- try {
179
- sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
180
- } catch (error) {
181
- logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
182
- signatureOptions: sigOpts,
183
- error
184
- });
185
- return null;
186
- }
187
- const document = { ...jsonLd };
188
- delete document.signature;
189
- let docHash;
190
- try {
191
- docHash = await hashJsonLd(document, options.contextLoader);
192
- } catch (error) {
193
- logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
194
- document,
195
- error
196
- });
197
- return null;
198
- }
199
- const encoder = new TextEncoder();
200
- const message = sigOptsHash + docHash;
201
- const messageBytes = encoder.encode(message);
202
- if (await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes)) return key;
203
- if (cached) {
204
- logger.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
205
- keyId: sig.creator,
206
- ...sig
207
- });
208
- const { key } = await fetchKey(new URL(sig.creator), CryptographicKey, {
209
- ...options,
210
- keyCache: {
211
- get: () => Promise.resolve(void 0),
212
- set: async (keyId, key) => await options.keyCache?.set(keyId, key)
213
- }
214
- });
215
- if (key == null) return null;
216
- return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes) ? key : null;
217
- }
218
- logger.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
219
- keyId: sig.creator,
220
- ...sig,
221
- message
222
- });
223
- return null;
224
- }
225
- /**
226
- * Verify the authenticity of the given JSON-LD document using Linked Data
227
- * Signatures. If the document is signed, this function verifies the signature
228
- * and checks if the document is attributed to the owner of the public key.
229
- * If the document is not signed, this function returns `false`.
230
- * @param jsonLd The JSON-LD document to verify.
231
- * @param options Options for verifying the document.
232
- * @returns `true` if the document is authentic; `false` otherwise.
233
- */
234
- async function verifyJsonLd(jsonLd, options = {}) {
235
- return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.verify", async (span) => {
236
- try {
237
- const object = await Object$1.fromJsonLd(jsonLd, options);
238
- if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
239
- span.setAttribute("activitypub.object.type", getTypeId(object).href);
240
- if (typeof jsonLd === "object" && jsonLd != null && "signature" in jsonLd && typeof jsonLd.signature === "object" && jsonLd.signature != null) {
241
- if ("creator" in jsonLd.signature && typeof jsonLd.signature.creator === "string") span.setAttribute("ld_signatures.key_id", jsonLd.signature.creator);
242
- if ("signatureValue" in jsonLd.signature && typeof jsonLd.signature.signatureValue === "string") span.setAttribute("ld_signatures.signature", jsonLd.signature.signatureValue);
243
- if ("type" in jsonLd.signature && typeof jsonLd.signature.type === "string") span.setAttribute("ld_signatures.type", jsonLd.signature.type);
244
- }
245
- const attributions = new Set(object.attributionIds.map((uri) => uri.href));
246
- if (object instanceof Activity) for (const uri of object.actorIds) attributions.add(uri.href);
247
- const key = await verifySignature(jsonLd, options);
248
- if (key == null) return false;
249
- if (key.ownerId == null) {
250
- logger.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
251
- return false;
252
- }
253
- attributions.delete(key.ownerId.href);
254
- if (attributions.size > 0) {
255
- logger.debug("Some attributions are not authenticated by the Linked Data Signatures: {attributions}.", { attributions: [...attributions] });
256
- return false;
257
- }
258
- return true;
259
- } catch (error) {
260
- span.setStatus({
261
- code: SpanStatusCode.ERROR,
262
- message: String(error)
263
- });
264
- throw error;
265
- } finally {
266
- span.end();
267
- }
268
- });
269
- }
270
- async function hashJsonLd(jsonLd, contextLoader) {
271
- const canon = await jsonld.canonize(jsonLd, {
272
- format: "application/n-quads",
273
- documentLoader: contextLoader ?? getDocumentLoader()
274
- });
275
- const encoder = new TextEncoder();
276
- return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
277
- }
278
- //#endregion
279
- export { signJsonLd as a, hasSignatureLike as i, createSignature as n, verifyJsonLd as o, detachSignature as r, verifySignature as s, attachSignature as t };
@@ -1,4 +0,0 @@
1
- const { Temporal } = require("@js-temporal/polyfill");
2
- const { URLPattern } = require("urlpattern-polyfill");
3
- const require_middleware = require("./middleware-An4DjES4.cjs");
4
- exports.FederationImpl = require_middleware.FederationImpl;
@@ -1,64 +0,0 @@
1
- import { Temporal } from "@js-temporal/polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
3
- import { $ as ActorAliasMapper, St as WebFingerLinksDispatcher, et as ActorDispatcher, l as RequestContext, tt as ActorHandleMapper } from "./context-BzH2-ajs.js";
4
- import { Span, Tracer } from "@opentelemetry/api";
5
-
6
- //#region src/federation/webfinger.d.ts
7
- /**
8
- * Parameters for {@link handleWebFinger}.
9
- */
10
- interface WebFingerHandlerParameters<TContextData> {
11
- /**
12
- * The request context.
13
- */
14
- context: RequestContext<TContextData>;
15
- /**
16
- * The canonical hostname of the server, if it's explicitly configured.
17
- * @since 1.5.0
18
- */
19
- host?: string;
20
- /**
21
- * The callback for dispatching the actor.
22
- */
23
- actorDispatcher?: ActorDispatcher<TContextData>;
24
- /**
25
- * The callback for mapping a WebFinger username to the corresponding actor's
26
- * internal identifier, or `null` if the username is not found.
27
- * @since 0.15.0
28
- */
29
- actorHandleMapper?: ActorHandleMapper<TContextData>;
30
- /**
31
- * The callback for mapping a WebFinger query to the corresponding actor's
32
- * internal identifier or username, or `null` if the query is not found.
33
- * @since 1.4.0
34
- */
35
- actorAliasMapper?: ActorAliasMapper<TContextData>;
36
- /**
37
- * The callback for dispatching the Links of webFinger.
38
- */
39
- webFingerLinksDispatcher?: WebFingerLinksDispatcher<TContextData>;
40
- /**
41
- * The function to call when the actor is not found.
42
- */
43
- onNotFound(request: Request): Response | Promise<Response>;
44
- /**
45
- * The OpenTelemetry tracer.
46
- * @since 1.3.0
47
- */
48
- tracer?: Tracer;
49
- /**
50
- * The span for the request.
51
- * @since 1.3.0
52
- */
53
- span?: Span;
54
- }
55
- /**
56
- * Handles a WebFinger request. You would not typically call this function
57
- * directly, but instead use {@link Federation.fetch} method.
58
- * @param request The WebFinger request to handle.
59
- * @param parameters The parameters for handling the request.
60
- * @returns The response to the request.
61
- */
62
- declare function handleWebFinger<TContextData>(request: Request, options: WebFingerHandlerParameters<TContextData>): Promise<Response>;
63
- //#endregion
64
- export { handleWebFinger as n, WebFingerHandlerParameters as t };
@@ -1,62 +0,0 @@
1
- import { $ as ActorAliasMapper, St as WebFingerLinksDispatcher, et as ActorDispatcher, l as RequestContext, tt as ActorHandleMapper } from "./context-DJGagtNd.cjs";
2
- import { Span, Tracer } from "@opentelemetry/api";
3
-
4
- //#region src/federation/webfinger.d.ts
5
- /**
6
- * Parameters for {@link handleWebFinger}.
7
- */
8
- interface WebFingerHandlerParameters<TContextData> {
9
- /**
10
- * The request context.
11
- */
12
- context: RequestContext<TContextData>;
13
- /**
14
- * The canonical hostname of the server, if it's explicitly configured.
15
- * @since 1.5.0
16
- */
17
- host?: string;
18
- /**
19
- * The callback for dispatching the actor.
20
- */
21
- actorDispatcher?: ActorDispatcher<TContextData>;
22
- /**
23
- * The callback for mapping a WebFinger username to the corresponding actor's
24
- * internal identifier, or `null` if the username is not found.
25
- * @since 0.15.0
26
- */
27
- actorHandleMapper?: ActorHandleMapper<TContextData>;
28
- /**
29
- * The callback for mapping a WebFinger query to the corresponding actor's
30
- * internal identifier or username, or `null` if the query is not found.
31
- * @since 1.4.0
32
- */
33
- actorAliasMapper?: ActorAliasMapper<TContextData>;
34
- /**
35
- * The callback for dispatching the Links of webFinger.
36
- */
37
- webFingerLinksDispatcher?: WebFingerLinksDispatcher<TContextData>;
38
- /**
39
- * The function to call when the actor is not found.
40
- */
41
- onNotFound(request: Request): Response | Promise<Response>;
42
- /**
43
- * The OpenTelemetry tracer.
44
- * @since 1.3.0
45
- */
46
- tracer?: Tracer;
47
- /**
48
- * The span for the request.
49
- * @since 1.3.0
50
- */
51
- span?: Span;
52
- }
53
- /**
54
- * Handles a WebFinger request. You would not typically call this function
55
- * directly, but instead use {@link Federation.fetch} method.
56
- * @param request The WebFinger request to handle.
57
- * @param parameters The parameters for handling the request.
58
- * @returns The response to the request.
59
- */
60
- declare function handleWebFinger<TContextData>(request: Request, options: WebFingerHandlerParameters<TContextData>): Promise<Response>;
61
- //#endregion
62
- export { handleWebFinger as n, WebFingerHandlerParameters as t };