@fedify/fedify 2.1.0 → 2.1.2

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 (207) hide show
  1. package/dist/{accept-D7sAxyNa.js → accept-Dd__NiUL.mjs} +10 -8
  2. package/dist/{assert-MZs1qjMx.js → assert-ddO5KLpe.mjs} +5 -9
  3. package/dist/{assert_equals-DSbWqCm3.js → assert_equals-Ew3jOFa3.mjs} +55 -69
  4. package/dist/{assert_instance_of-DHz7EHNU.js → assert_instance_of-C4Ri6VuN.mjs} +5 -9
  5. package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals--wG9hV7u.mjs} +6 -13
  6. package/dist/{assert_rejects-0h7I2Esa.js → assert_rejects-B-qJtC9Z.mjs} +6 -11
  7. package/dist/{assert_throws-rjdMBf31.js → assert_throws-4NwKEy2q.mjs} +5 -10
  8. package/dist/{builder-WiHhZvjW.js → builder-DkJDAzes.mjs} +32 -41
  9. package/dist/{chunk-CGaQZ11T.cjs → chunk-DDcVe30Y.cjs} +23 -24
  10. package/dist/{chunk-DJNbSFdH.js → chunk-nlSIicah.js} +8 -8
  11. package/dist/{client-BxMZiQaD.d.ts → client-AtlibPOU.d.ts} +1 -1
  12. package/dist/{client-CoCIaTNO.js → client-DEpOVgY1.mjs} +9 -13
  13. package/dist/{client-C97KOq3x.d.cts → client-z-8dc-e1.d.cts} +1 -1
  14. package/dist/{collection-CSzG2j1P.js → collection-BD6-SZ6O.mjs} +7 -12
  15. package/dist/compat/mod.cjs +5 -8
  16. package/dist/compat/mod.d.cts +78 -6
  17. package/dist/compat/mod.d.ts +78 -6
  18. package/dist/compat/mod.js +4 -8
  19. package/dist/compat/transformers.test.mjs +62 -0
  20. package/dist/{context-DyJjQQ_H.d.ts → context-BOiMZBu5.d.ts} +9 -18
  21. package/dist/{context-BcqA-0BL.d.cts → context-BhZVy7RB.d.cts} +9 -18
  22. package/dist/{context-Aqenou7c.js → context-Juj6bdHC.mjs} +7 -11
  23. package/dist/deno-C5VMwnFV.mjs +8 -0
  24. package/dist/{docloader-bVO2EvL9.js → docloader-X9mcJ9Tz.mjs} +8 -14
  25. package/dist/{esm-nLm00z9V.js → esm-DVILvP5e.mjs} +50 -89
  26. package/dist/federation/builder.test.d.mts +2 -0
  27. package/dist/federation/{builder.test.js → builder.test.mjs} +21 -44
  28. package/dist/federation/collection.test.d.mts +2 -0
  29. package/dist/federation/collection.test.mjs +21 -0
  30. package/dist/federation/handler.test.d.mts +2 -0
  31. package/dist/federation/{handler.test.js → handler.test.mjs} +69 -131
  32. package/dist/federation/idempotency.test.d.mts +2 -0
  33. package/dist/federation/{idempotency.test.js → idempotency.test.mjs} +31 -63
  34. package/dist/federation/inbox.test.d.mts +2 -0
  35. package/dist/federation/{inbox.test.js → inbox.test.mjs} +8 -12
  36. package/dist/federation/keycache.test.d.mts +2 -0
  37. package/dist/federation/{keycache.test.js → keycache.test.mjs} +13 -19
  38. package/dist/federation/kv.test.d.mts +2 -0
  39. package/dist/federation/{kv.test.js → kv.test.mjs} +11 -22
  40. package/dist/federation/middleware.test.d.mts +2 -0
  41. package/dist/federation/{middleware.test.js → middleware.test.mjs} +173 -262
  42. package/dist/federation/mod.cjs +327 -16
  43. package/dist/federation/mod.d.cts +3 -6
  44. package/dist/federation/mod.d.ts +3 -6
  45. package/dist/federation/mod.js +322 -13
  46. package/dist/federation/mq.test.d.mts +2 -0
  47. package/dist/federation/{mq.test.js → mq.test.mjs} +21 -35
  48. package/dist/federation/negotiation.test.d.mts +2 -0
  49. package/dist/federation/{negotiation.test.js → negotiation.test.mjs} +9 -16
  50. package/dist/federation/retry.test.d.mts +2 -0
  51. package/dist/federation/{retry.test.js → retry.test.mjs} +8 -11
  52. package/dist/federation/router.test.d.mts +2 -0
  53. package/dist/federation/{router.test.js → router.test.mjs} +11 -16
  54. package/dist/federation/send.test.d.mts +2 -0
  55. package/dist/federation/{send.test.js → send.test.mjs} +22 -30
  56. package/dist/federation/webfinger.test.d.mts +2 -0
  57. package/dist/federation/{webfinger.test.js → webfinger.test.mjs} +22 -56
  58. package/dist/{http-DhH623ma.js → http-BLZWcpzg.js} +67 -187
  59. package/dist/{http-CKDim8Tw.js → http-BTLPIzFa.mjs} +37 -45
  60. package/dist/{http-BudnHZE2.d.cts → http-CrGuipxe.d.cts} +1 -6
  61. package/dist/{http-gvnJbMS1.cjs → http-CxodXLwi.cjs} +186 -300
  62. package/dist/{http-Dax_FIBo.d.ts → http-aQzN9Ayi.d.ts} +1 -6
  63. package/dist/{inbox-CA9AUEGa.js → inbox-mcbmhjTW.mjs} +18 -26
  64. package/dist/{key-BsSCz8Z_.js → key-1MaItIGc.mjs} +29 -37
  65. package/dist/{keycache-CpGWAUbj.js → keycache-CCSwkQcY.mjs} +5 -10
  66. package/dist/{keys-BFve7QQv.js → keys-BAK-tUlf.mjs} +5 -9
  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-Bw2F2ABq.js → kv-cache-B01V7s3h.mjs} +4 -8
  70. package/dist/{kv-cache-DK4GFVWx.cjs → kv-cache-DjC82_4n.cjs} +27 -34
  71. package/dist/{kv-cache-CxoHCR44.js → kv-cache-GIDK1oLs.js} +6 -13
  72. package/dist/{kv-QzKcOQgP.js → kv-tL2TOE9X.mjs} +6 -10
  73. package/dist/{ld-Bo_Rx0Fc.js → ld-94uHZ1eO.mjs} +17 -31
  74. package/dist/{middleware-BkrUA3da.js → middleware-B5Er10wE.js} +336 -383
  75. package/dist/middleware-CDuHbSVE.mjs +5 -0
  76. package/dist/middleware-CTyq5KB0.cjs +4 -0
  77. package/dist/{middleware-CpAnWzjC.cjs → middleware-CqDJSLoG.cjs} +532 -587
  78. package/dist/{middleware-CZ8jOOa3.js → middleware-DMZGXHm3.mjs} +282 -317
  79. package/dist/{mod-Bx9jcLB8.d.cts → mod-B505FZBC.d.cts} +3 -3
  80. package/dist/{mod-em2Il1eD.d.cts → mod-Bp_CzKd4.d.cts} +2 -2
  81. package/dist/{mod-Cs2dYEwI.d.ts → mod-D7PAuO6k.d.ts} +3 -3
  82. package/dist/{mod-D6MdymW7.d.ts → mod-DKOAow7a.d.ts} +2 -2
  83. package/dist/{mod-Coe7KEgX.d.cts → mod-DoJBjjnO.d.cts} +2 -2
  84. package/dist/{mod-D6dOd--H.d.ts → mod-DvxszxXC.d.ts} +2 -2
  85. package/dist/mod.cjs +29 -74
  86. package/dist/mod.d.cts +11 -14
  87. package/dist/mod.d.ts +11 -15
  88. package/dist/mod.js +17 -71
  89. package/dist/{negotiation-BlAuS_nr.js → negotiation-DnsfFF8I.mjs} +7 -11
  90. package/dist/nodeinfo/client.test.d.mts +2 -0
  91. package/dist/nodeinfo/{client.test.js → client.test.mjs} +22 -40
  92. package/dist/nodeinfo/handler.test.d.mts +2 -0
  93. package/dist/nodeinfo/{handler.test.js → handler.test.mjs} +13 -43
  94. package/dist/nodeinfo/mod.cjs +5 -8
  95. package/dist/nodeinfo/mod.d.cts +2 -3
  96. package/dist/nodeinfo/mod.d.ts +2 -3
  97. package/dist/nodeinfo/mod.js +4 -8
  98. package/dist/nodeinfo/types.test.d.mts +2 -0
  99. package/dist/nodeinfo/{types.test.js → types.test.mjs} +9 -16
  100. package/dist/otel/exporter.test.d.mts +2 -0
  101. package/dist/otel/{exporter.test.js → exporter.test.mjs} +124 -178
  102. package/dist/otel/mod.cjs +15 -20
  103. package/dist/otel/mod.d.cts +2 -2
  104. package/dist/otel/mod.d.ts +2 -2
  105. package/dist/otel/mod.js +8 -14
  106. package/dist/{owner-gd0Q9FuU.d.ts → owner-74ARJ5TL.d.ts} +1 -1
  107. package/dist/{owner-Bj_IbwIT.js → owner-B4aIDhg_.mjs} +11 -16
  108. package/dist/{owner-1AbPBOOZ.d.cts → owner-CptqhsOy.d.cts} +1 -1
  109. package/dist/{proof-u6Y358J-.js → proof-DYZWMWOC.mjs} +21 -33
  110. package/dist/{proof-BhFF_JVj.cjs → proof-DqCjiFwb.cjs} +133 -157
  111. package/dist/{proof-D5BQTIcU.js → proof-j-of9m5W.js} +33 -59
  112. package/dist/{retry-mqLf4b-R.js → retry-B_E3V_Dx.mjs} +4 -7
  113. package/dist/{router-D9eI0s4b.js → router-CrMLXoOr.mjs} +4 -8
  114. package/dist/runtime/mod.cjs +11 -13
  115. package/dist/runtime/mod.d.cts +6 -2
  116. package/dist/runtime/mod.d.ts +0 -1
  117. package/dist/runtime/mod.js +4 -7
  118. package/dist/{send-CE8h59oe.js → send-uLjD0uAe.mjs} +8 -13
  119. package/dist/sig/accept.test.d.mts +2 -0
  120. package/dist/sig/{accept.test.js → accept.test.mjs} +35 -70
  121. package/dist/sig/http.test.d.mts +2 -0
  122. package/dist/sig/{http.test.js → http.test.mjs} +209 -280
  123. package/dist/sig/key.test.d.mts +2 -0
  124. package/dist/sig/{key.test.js → key.test.mjs} +11 -18
  125. package/dist/sig/ld.test.d.mts +2 -0
  126. package/dist/sig/{ld.test.js → ld.test.mjs} +22 -35
  127. package/dist/sig/mod.cjs +6 -9
  128. package/dist/sig/mod.d.cts +3 -3
  129. package/dist/sig/mod.d.ts +3 -3
  130. package/dist/sig/mod.js +5 -9
  131. package/dist/sig/owner.test.d.mts +2 -0
  132. package/dist/sig/{owner.test.js → owner.test.mjs} +19 -34
  133. package/dist/sig/proof.test.d.mts +2 -0
  134. package/dist/sig/{proof.test.js → proof.test.mjs} +16 -27
  135. package/dist/{std__assert-X-_kMxKM.js → std__assert-Duiq_YC9.mjs} +12 -24
  136. package/dist/testing/{mod.d.ts → mod.d.mts} +26 -90
  137. package/dist/testing/mod.mjs +6 -0
  138. package/dist/{transformers-3g8GZwkZ.cjs → transformers-NeAONrAq.cjs} +20 -25
  139. package/dist/{transformers-C3FLHUd6.js → transformers-ve6e2xcg.js} +3 -7
  140. package/dist/{types-CPz01LGH.js → types-DCP0WLdt.mjs} +4 -7
  141. package/dist/{types-Cd_hszr_.cjs → types-KC4QAoxe.cjs} +29 -34
  142. package/dist/{types-C93Ob9cU.js → types-hvL8ElAs.js} +8 -13
  143. package/dist/utils/docloader.test.d.mts +2 -0
  144. package/dist/utils/{docloader.test.js → docloader.test.mjs} +14 -25
  145. package/dist/utils/kv-cache.test.d.mts +2 -0
  146. package/dist/utils/{kv-cache.test.js → kv-cache.test.mjs} +25 -40
  147. package/dist/utils/mod.cjs +5 -9
  148. package/dist/utils/mod.d.cts +1 -3
  149. package/dist/utils/mod.d.ts +1 -3
  150. package/dist/utils/mod.js +4 -9
  151. package/dist/vocab/cjs.test.d.mts +2 -0
  152. package/dist/vocab/cjs.test.mjs +14 -0
  153. package/dist/vocab/mod.cjs +10 -12
  154. package/dist/vocab/mod.js +3 -5
  155. package/package.json +7 -7
  156. package/dist/compat/transformers.test.d.ts +0 -3
  157. package/dist/compat/transformers.test.js +0 -88
  158. package/dist/compat-Bb4NuTUO.js +0 -4
  159. package/dist/compat-DmDDELst.cjs +0 -4
  160. package/dist/deno-BRMCYThi.js +0 -121
  161. package/dist/federation/builder.test.d.ts +0 -3
  162. package/dist/federation/collection.test.d.ts +0 -3
  163. package/dist/federation/collection.test.js +0 -32
  164. package/dist/federation/handler.test.d.ts +0 -3
  165. package/dist/federation/idempotency.test.d.ts +0 -3
  166. package/dist/federation/inbox.test.d.ts +0 -3
  167. package/dist/federation/keycache.test.d.ts +0 -3
  168. package/dist/federation/kv.test.d.ts +0 -3
  169. package/dist/federation/middleware.test.d.ts +0 -3
  170. package/dist/federation/mq.test.d.ts +0 -3
  171. package/dist/federation/negotiation.test.d.ts +0 -3
  172. package/dist/federation/retry.test.d.ts +0 -3
  173. package/dist/federation/router.test.d.ts +0 -3
  174. package/dist/federation/send.test.d.ts +0 -3
  175. package/dist/federation/webfinger.test.d.ts +0 -3
  176. package/dist/federation-Bp3HI26G.cjs +0 -350
  177. package/dist/federation-DaMfqRm4.js +0 -332
  178. package/dist/middleware-BtT_mKsB.cjs +0 -12
  179. package/dist/middleware-CUMoHNCA.js +0 -12
  180. package/dist/middleware-CzeVJTA1.js +0 -27
  181. package/dist/mod-B7QkWzrL.d.cts +0 -80
  182. package/dist/mod-Bh8mqlYw.d.cts +0 -9
  183. package/dist/mod-D6HodEq7.d.ts +0 -7
  184. package/dist/mod-SMHOMNpZ.d.ts +0 -82
  185. package/dist/mod-gq_Xfdz8.d.cts +0 -1
  186. package/dist/nodeinfo/client.test.d.ts +0 -3
  187. package/dist/nodeinfo/handler.test.d.ts +0 -3
  188. package/dist/nodeinfo/types.test.d.ts +0 -3
  189. package/dist/nodeinfo-DoESQxq5.js +0 -4
  190. package/dist/nodeinfo-DuMYTpbZ.cjs +0 -4
  191. package/dist/otel/exporter.test.d.ts +0 -3
  192. package/dist/runtime-c2Njxsry.cjs +0 -17
  193. package/dist/runtime-poamPCMb.js +0 -13
  194. package/dist/sig/accept.test.d.ts +0 -3
  195. package/dist/sig/http.test.d.ts +0 -3
  196. package/dist/sig/key.test.d.ts +0 -3
  197. package/dist/sig/ld.test.d.ts +0 -3
  198. package/dist/sig/owner.test.d.ts +0 -3
  199. package/dist/sig/proof.test.d.ts +0 -3
  200. package/dist/sig-BNhspNOf.js +0 -4
  201. package/dist/sig-vX39WyWI.cjs +0 -4
  202. package/dist/testing/mod.js +0 -10
  203. package/dist/utils/docloader.test.d.ts +0 -3
  204. package/dist/utils/kv-cache.test.d.ts +0 -3
  205. package/dist/utils-BQ9KqEK9.cjs +0 -4
  206. package/dist/utils-Dn5OPdSW.js +0 -4
  207. /package/dist/{mod-AGjRfPjT.d.ts → compat/transformers.test.d.mts} +0 -0
@@ -1,20 +1,19 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { deno_default } from "./deno-BRMCYThi.js";
7
- import { fulfillAcceptSignature, parseAcceptSignature, validateAcceptSignature } from "./accept-D7sAxyNa.js";
8
- import { fetchKeyDetailed, validateCryptoKey } from "./key-BsSCz8Z_.js";
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { n as version, t as name } from "./deno-C5VMwnFV.mjs";
5
+ import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-Dd__NiUL.mjs";
6
+ import { o as validateCryptoKey, r as fetchKeyDetailed } from "./key-1MaItIGc.mjs";
9
7
  import { CryptographicKey } from "@fedify/vocab";
10
- import { getLogger } from "@logtape/logtape";
11
8
  import { SpanStatusCode, trace } from "@opentelemetry/api";
9
+ import { FetchError } from "@fedify/vocab-runtime";
10
+ import { getLogger } from "@logtape/logtape";
12
11
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
13
12
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
14
13
  import { encodeHex } from "byte-encodings/hex";
15
14
  import { Item, decodeDict, encodeItem } from "structured-field-values";
16
-
17
15
  //#region src/sig/http.ts
16
+ const DEFAULT_MAX_REDIRECTION = 20;
18
17
  /**
19
18
  * Signs a request using the given private key.
20
19
  * @param request The request to sign.
@@ -26,9 +25,7 @@ import { Item, decodeDict, encodeItem } from "structured-field-values";
26
25
  */
27
26
  async function signRequest(request, privateKey, keyId, options = {}) {
28
27
  validateCryptoKey(privateKey, "private");
29
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
30
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
31
- return await tracer.startActiveSpan("http_signatures.sign", async (span) => {
28
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
32
29
  try {
33
30
  const spec = options.spec ?? "draft-cavage-http-signatures-12";
34
31
  let signed;
@@ -136,9 +133,7 @@ const derivedComponents = {
136
133
  * @returns The formatted signature string.
137
134
  */
138
135
  function formatRfc9421Signature(signature, components, parameters, label = "sig1") {
139
- const signatureInputValue = `${label}=(${components.map((c) => formatComponentId(c)).join(" ")});${parameters}`;
140
- const signatureValue = `${label}=:${encodeBase64(signature)}:`;
141
- return [signatureInputValue, signatureValue];
136
+ return [`${label}=(${components.map((c) => formatComponentId(c)).join(" ")});${parameters}`, `${label}=:${encodeBase64(signature)}:`];
142
137
  }
143
138
  /**
144
139
  * Parse RFC 9421 Signature-Input header.
@@ -244,12 +239,11 @@ async function signRequestRfc9421(request, privateKey, keyId, span, currentTime,
244
239
  value: "content-digest",
245
240
  params: {}
246
241
  }] : []];
247
- const expires = rfc9421Options?.expires === true ? (currentTime.epochMilliseconds / 1e3 | 0) + 3600 : void 0;
248
242
  const signatureParams = formatRfc9421SignatureParameters({
249
243
  algorithm: "rsa-v1_5-sha256",
250
244
  keyId,
251
245
  created,
252
- expires,
246
+ expires: rfc9421Options?.expires === true ? (currentTime.epochMilliseconds / 1e3 | 0) + 3600 : void 0,
253
247
  nonce: rfc9421Options?.nonce,
254
248
  tag: rfc9421Options?.tag
255
249
  });
@@ -359,9 +353,7 @@ async function verifyRequest(request, options = {}) {
359
353
  * @since 2.1.0
360
354
  */
361
355
  async function verifyRequestDetailed(request, options = {}) {
362
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
363
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
364
- return await tracer.startActiveSpan("http_signatures.verify", async (span) => {
356
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.verify", async (span) => {
365
357
  if (span.isRecording()) {
366
358
  span.setAttribute(ATTR_HTTP_REQUEST_METHOD, request.method);
367
359
  span.setAttribute(ATTR_URL_FULL, request.url);
@@ -556,8 +548,7 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
556
548
  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");
557
549
  const sig = decodeBase64(signature);
558
550
  span?.setAttribute("http_signatures.signature", encodeHex(sig));
559
- const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, sig, new TextEncoder().encode(message));
560
- if (!verified) {
551
+ if (!await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, sig, new TextEncoder().encode(message))) {
561
552
  if (cached) {
562
553
  logger.debug("Failed to verify with the cached key {keyId}; signature {signature} is invalid. Retrying with the freshly fetched key...", {
563
554
  keyId,
@@ -571,7 +562,7 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
571
562
  currentTime,
572
563
  keyCache: {
573
564
  get: () => Promise.resolve(void 0),
574
- set: async (keyId$1, key$1) => await keyCache?.set(keyId$1, key$1)
565
+ set: async (keyId, key) => await keyCache?.set(keyId, key)
575
566
  }
576
567
  });
577
568
  }
@@ -733,9 +724,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
733
724
  failure = invalidSignatureResult(keyId);
734
725
  continue;
735
726
  }
736
- const body = await request.arrayBuffer();
737
- const digestValid = await verifyRfc9421ContentDigest(contentDigestHeader, body);
738
- if (!digestValid) {
727
+ if (!await verifyRfc9421ContentDigest(contentDigestHeader, await request.arrayBuffer())) {
739
728
  logger.debug("Failed to verify; Content-Digest verification failed.", { contentDigest: contentDigestHeader });
740
729
  failure = invalidSignatureResult(keyId);
741
730
  continue;
@@ -793,8 +782,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
793
782
  const signatureBaseBytes = new TextEncoder().encode(signatureBase);
794
783
  span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
795
784
  try {
796
- const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes);
797
- if (verified) return {
785
+ if (await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes)) return {
798
786
  verified: true,
799
787
  key,
800
788
  signatureLabel: sigName
@@ -808,7 +796,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
808
796
  currentTime,
809
797
  keyCache: {
810
798
  get: () => Promise.resolve(void 0),
811
- set: async (keyId$1, key$1) => await keyCache?.set(keyId$1, key$1)
799
+ set: async (keyId, key) => await keyCache?.set(keyId, key)
812
800
  },
813
801
  spec: "rfc9421"
814
802
  });
@@ -865,7 +853,11 @@ function createRedirectRequest(request, location, body) {
865
853
  * @since 1.6.0
866
854
  */
867
855
  async function doubleKnock(request, identity, options = {}) {
856
+ return await doubleKnockInternal(request, identity, options);
857
+ }
858
+ async function doubleKnockInternal(request, identity, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
868
859
  const { specDeterminer, log, tracerProvider, signal } = options;
860
+ visited.add(request.url);
869
861
  const origin = new URL(request.url).origin;
870
862
  const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
871
863
  const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
@@ -880,11 +872,13 @@ async function doubleKnock(request, identity, options = {}) {
880
872
  signal
881
873
  });
882
874
  if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
883
- const location = response.headers.get("Location");
884
- return doubleKnock(createRedirectRequest(request, location, body), identity, {
875
+ if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
876
+ const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
877
+ if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
878
+ return doubleKnockInternal(redirectRequest, identity, {
885
879
  ...options,
886
880
  body
887
- });
881
+ }, redirected + 1, visited);
888
882
  } else if (response.status === 400 || response.status === 401 || response.status > 401) {
889
883
  const logger = getLogger([
890
884
  "fedify",
@@ -927,13 +921,10 @@ async function doubleKnock(request, identity, options = {}) {
927
921
  redirect: "manual",
928
922
  signal
929
923
  });
930
- if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
931
- const location = response.headers.get("Location");
932
- return doubleKnock(createRedirectRequest(request, location, body), identity, {
933
- ...options,
934
- body
935
- });
936
- }
924
+ if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(createRedirectRequest(request, response.headers.get("Location"), body), identity, {
925
+ ...options,
926
+ body
927
+ });
937
928
  }
938
929
  if (fulfilled && response.status < 300) {
939
930
  await specDeterminer?.rememberSpec(origin, "rfc9421");
@@ -959,11 +950,13 @@ async function doubleKnock(request, identity, options = {}) {
959
950
  signal
960
951
  });
961
952
  if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
962
- const location = response.headers.get("Location");
963
- return doubleKnock(createRedirectRequest(request, location, body), identity, {
953
+ if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
954
+ const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
955
+ if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
956
+ return doubleKnockInternal(redirectRequest, identity, {
964
957
  ...options,
965
958
  body
966
- });
959
+ }, redirected + 1, visited);
967
960
  } else if (response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
968
961
  } else await specDeterminer?.rememberSpec(origin, firstTrySpec);
969
962
  return response;
@@ -995,6 +988,5 @@ function timingSafeEqual(a, b) {
995
988
  result |= lenA ^ lenB;
996
989
  return result === 0;
997
990
  }
998
-
999
991
  //#endregion
1000
- export { createRfc9421SignatureBase, doubleKnock, formatRfc9421Signature, formatRfc9421SignatureParameters, parseRfc9421Signature, parseRfc9421SignatureInput, signRequest, timingSafeEqual, verifyRequest, verifyRequestDetailed };
992
+ export { parseRfc9421Signature as a, timingSafeEqual as c, formatRfc9421SignatureParameters as i, verifyRequest as l, doubleKnock as n, parseRfc9421SignatureInput as o, formatRfc9421Signature as r, signRequest as s, createRfc9421SignatureBase as t, verifyRequestDetailed 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
@@ -536,9 +535,5 @@ interface HttpMessageSignaturesSpecDeterminer {
536
535
  */
537
536
  rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
538
537
  }
539
- /**
540
- * The options for double-knock requests.
541
- * @since 1.6.0
542
- */
543
538
  //#endregion
544
- export { AcceptSignatureMember, AcceptSignatureParameters, FetchKeyDetailedResult, FetchKeyErrorResult, FetchKeyOptions, FetchKeyResult, FulfillAcceptSignatureResult, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, Rfc9421SignRequestOptions, SignRequestOptions, VerifyRequestDetailedResult, VerifyRequestFailureReason, VerifyRequestOptions, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, importJwk, parseAcceptSignature, signRequest, validateAcceptSignature, verifyRequest, verifyRequestDetailed };
539
+ export { exportJwk as C, importJwk as D, generateCryptoKeyPair as E, KeyCache as S, fetchKeyDetailed as T, validateAcceptSignature as _, VerifyRequestDetailedResult as a, FetchKeyOptions as b, signRequest as c, AcceptSignatureMember as d, AcceptSignatureParameters as f, parseAcceptSignature as g, fulfillAcceptSignature as h, SignRequestOptions as i, verifyRequest as l, formatAcceptSignature as m, HttpMessageSignaturesSpecDeterminer as n, VerifyRequestFailureReason as o, FulfillAcceptSignatureResult as p, Rfc9421SignRequestOptions as r, VerifyRequestOptions as s, HttpMessageSignaturesSpec as t, verifyRequestDetailed as u, FetchKeyDetailedResult as v, fetchKey as w, FetchKeyResult as x, FetchKeyErrorResult as y };