@fedify/fedify 2.0.0-pr.410.1558 → 2.0.0-pr.412.1692

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 (184) hide show
  1. package/dist/actor-CrTGiTZd.cjs +42609 -0
  2. package/dist/{actor-CkjTCNqi.js → actor-D5S46edz.js} +1 -1
  3. package/dist/actor-D6K058Tb.d.cts +128 -0
  4. package/dist/{actor-DmsbGzXS.js → actor-G2S5sPEA.js} +6951 -2127
  5. package/dist/{actor-C22bXuuC.d.ts → actor-T6RyhRgk.d.ts} +1 -1
  6. package/dist/{authdocloader-BwV2NPfz.js → authdocloader-C5AvdCCi.js} +6 -6
  7. package/dist/authdocloader-CQMPmpaO.cjs +58 -0
  8. package/dist/{authdocloader-BJxkviIL.js → authdocloader-SjwloJUA.js} +3 -3
  9. package/dist/{builder-DbOVAz8i.js → builder-OA47XRft.js} +10 -4
  10. package/dist/chunk-DqRYRqnO.cjs +34 -0
  11. package/dist/{client-DrNZd6r_.js → client-Bmd-i8x8.js} +3 -22
  12. package/dist/client-CegPX0Rn.d.cts +222 -0
  13. package/dist/{client-DF8anIB5.d.ts → client-bgSdkFa2.d.ts} +2 -74
  14. package/dist/compat/mod.cjs +10 -0
  15. package/dist/compat/mod.d.cts +13 -0
  16. package/dist/compat/mod.d.ts +8 -8
  17. package/dist/compat/mod.js +5 -5
  18. package/dist/compat/transformers.test.js +19 -19
  19. package/dist/compat-DmDDELst.cjs +4 -0
  20. package/dist/compat-nxUqe4Z-.js +4 -0
  21. package/dist/{context-9gCpIkiz.d.ts → context-ByZprN0S.d.ts} +67 -7
  22. package/dist/context-C5BsZkDr.d.cts +2315 -0
  23. package/dist/docloader-7Ey7wNHx.cjs +4861 -0
  24. package/dist/{docloader-DnepZfu_.js → docloader-CkweNhUH.js} +189 -9
  25. package/dist/docloader-D-MrRyHl.d.cts +219 -0
  26. package/dist/{esm-D1HqBE3n.js → esm-CwHz8Y8t.js} +1 -1
  27. package/dist/federation/builder.test.js +6 -7
  28. package/dist/federation/collection.test.js +4 -4
  29. package/dist/federation/handler.test.js +23 -143
  30. package/dist/federation/idempotency.test.js +202 -0
  31. package/dist/federation/inbox.test.js +4 -4
  32. package/dist/federation/keycache.test.js +4 -4
  33. package/dist/federation/kv.test.js +4 -3
  34. package/dist/federation/middleware.test.js +231 -52
  35. package/dist/federation/mod.cjs +29 -0
  36. package/dist/federation/mod.d.cts +13 -0
  37. package/dist/federation/mod.d.ts +8 -8
  38. package/dist/federation/mod.js +15 -15
  39. package/dist/federation/mq.test.js +3 -3
  40. package/dist/federation/negotiation.test.d.ts +3 -0
  41. package/dist/federation/negotiation.test.js +28 -0
  42. package/dist/federation/retry.test.js +3 -3
  43. package/dist/federation/router.test.js +3 -3
  44. package/dist/federation/send.test.js +10 -10
  45. package/dist/{federation-CMX7WzeL.js → federation-D1U8YY9t.js} +3 -3
  46. package/dist/federation-H2_En3j5.cjs +244 -0
  47. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  48. package/dist/http-BiBofurJ.cjs +826 -0
  49. package/dist/{http-BEJUSX6j.js → http-C5tC93Hn.js} +7 -7
  50. package/dist/http-D-e6AFwR.d.cts +253 -0
  51. package/dist/{http-DqSNLFNY.d.ts → http-D6Uj2x2y.d.ts} +1 -1
  52. package/dist/{http-BgCF3jDs.js → http-DGjdMiLc.js} +3 -3
  53. package/dist/{inbox-Bq4EChoK.js → inbox-BoDY3z8G.js} +24 -7
  54. package/dist/key-CZR7QraT.cjs +290 -0
  55. package/dist/key-Cf8MffVe.cjs +10 -0
  56. package/dist/{key-D-0OLe9C.js → key-CkxrAIyp.js} +5 -5
  57. package/dist/key-Dk0j88Jo.js +10 -0
  58. package/dist/{key-BD3lpBWw.js → key-Epcl5jpz.js} +3 -3
  59. package/dist/{key-BYNqWXyu.js → key-IxRhZpOF.js} +2 -2
  60. package/dist/{keycache-yZDAc3-e.js → keycache-TEniXNel.js} +1 -1
  61. package/dist/{keys-Dtc-g6xq.js → keys-bZxcrZ9Z.js} +1 -1
  62. package/dist/kv-63Cil1MD.d.cts +81 -0
  63. package/dist/{ld-BJ484qSg.js → ld-DW7A0uIc.js} +4 -4
  64. package/dist/{lookup-Cj0sX50U.js → lookup-DhQCVVja.js} +21 -12
  65. package/dist/lookup-DiV4LFBg.cjs +137 -0
  66. package/dist/{lookup-BzogF2gp.js → lookup-cVRa2QM-.js} +4 -4
  67. package/dist/middleware-Be1JStOx.js +17 -0
  68. package/dist/middleware-CDOK7WOb.js +26 -0
  69. package/dist/{middleware-CiH0ptqy.js → middleware-Cgr3PtaJ.js} +58 -149
  70. package/dist/{middleware-DIZ1dnwT.js → middleware-DvvYAIsd.js} +87 -91
  71. package/dist/middleware-EjIW2mZB.cjs +17 -0
  72. package/dist/middleware-TfuVoceY.cjs +4231 -0
  73. package/dist/mod-8DMWKtQE.d.cts +80 -0
  74. package/dist/{mod-Drmz72EK.d.ts → mod-BhUKmBJD.d.ts} +2 -2
  75. package/dist/mod-C2tOeRkN.d.cts +1 -0
  76. package/dist/{mod-TFoH2Ql8.d.ts → mod-CerN_Sza.d.ts} +1 -1
  77. package/dist/mod-Cj1tHXBR.d.cts +102 -0
  78. package/dist/mod-CxkWO3Mg.d.cts +307 -0
  79. package/dist/{mod-Bqxcp7eN.d.ts → mod-D6hQoxC5.d.ts} +2 -2
  80. package/dist/mod-Djzcw2ry.d.cts +266 -0
  81. package/dist/{mod-Cxt4Kpf6.d.ts → mod-DlU8ISoa.d.ts} +19 -1
  82. package/dist/mod-FZd39qVq.d.cts +1 -0
  83. package/dist/mod-jQ4OODsl.d.cts +113 -0
  84. package/dist/mod.cjs +150 -0
  85. package/dist/mod.d.cts +17 -0
  86. package/dist/mod.d.ts +11 -11
  87. package/dist/mod.js +21 -21
  88. package/dist/mq-B7R1Q-M5.d.cts +140 -0
  89. package/dist/negotiation-5NPJL6zp.js +71 -0
  90. package/dist/nodeinfo/client.test.js +27 -106
  91. package/dist/nodeinfo/handler.test.js +20 -20
  92. package/dist/nodeinfo/mod.cjs +11 -0
  93. package/dist/nodeinfo/mod.d.cts +5 -0
  94. package/dist/nodeinfo/mod.d.ts +2 -2
  95. package/dist/nodeinfo/mod.js +7 -7
  96. package/dist/nodeinfo/types.test.js +5 -10
  97. package/dist/nodeinfo-Co9lJrWl.cjs +4 -0
  98. package/dist/nodeinfo-DfycQ8Wf.js +4 -0
  99. package/dist/{owner-9FMX4wQT.js → owner-6Vc3UXXE.js} +2 -2
  100. package/dist/owner-BN_tO3cY.d.cts +67 -0
  101. package/dist/{owner-CQPnQVtf.d.ts → owner-hd9lvQcP.d.ts} +2 -2
  102. package/dist/{proof-Arx4Q9Q6.js → proof-C1jhbeNv.js} +3 -3
  103. package/dist/proof-CRJWXFfT.cjs +673 -0
  104. package/dist/{proof-DnTD0avk.js → proof-Chi90OXv.js} +9 -9
  105. package/dist/runtime/authdocloader.test.js +9 -9
  106. package/dist/runtime/docloader.test.js +4 -4
  107. package/dist/runtime/key.test.js +5 -5
  108. package/dist/runtime/langstr.test.js +3 -3
  109. package/dist/runtime/link.test.d.ts +3 -0
  110. package/dist/runtime/link.test.js +61 -0
  111. package/dist/runtime/mod.cjs +25 -0
  112. package/dist/runtime/mod.d.cts +6 -0
  113. package/dist/runtime/mod.d.ts +3 -3
  114. package/dist/runtime/mod.js +10 -10
  115. package/dist/runtime/multibase/multibase.test.js +3 -3
  116. package/dist/runtime/url.test.js +3 -3
  117. package/dist/runtime-C58AJWSv.cjs +4 -0
  118. package/dist/runtime-DPYEDf-o.js +4 -0
  119. package/dist/{send-CcxHe0p3.js → send-DjATl6i3.js} +2 -2
  120. package/dist/sig/http.test.js +9 -9
  121. package/dist/sig/key.test.js +6 -6
  122. package/dist/sig/ld.test.js +7 -7
  123. package/dist/sig/mod.cjs +30 -0
  124. package/dist/sig/mod.d.cts +8 -0
  125. package/dist/sig/mod.d.ts +5 -5
  126. package/dist/sig/mod.js +10 -10
  127. package/dist/sig/owner.test.js +7 -7
  128. package/dist/sig/proof.test.js +7 -7
  129. package/dist/sig-ByHXzqUi.cjs +4 -0
  130. package/dist/sig-Cj3tk-ig.js +4 -0
  131. package/dist/testing/docloader.test.js +3 -3
  132. package/dist/testing/mod.d.ts +273 -28
  133. package/dist/testing/mod.js +3 -3
  134. package/dist/{testing-DFgpNAI6.js → testing-BnfPB5T-.js} +2 -2
  135. package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
  136. package/dist/transformers-CoBS-oFG.cjs +116 -0
  137. package/dist/{type-B2h-NRAo.js → type-NEA09tSC.js} +7262 -2258
  138. package/dist/{types-BIgY6c-l.js → types-BSuWJsOm.js} +1 -3
  139. package/dist/types-CmmUQisS.cjs +315 -0
  140. package/dist/{types-B1QuBj5L.js → types-dLXLjVLf.js} +8 -169
  141. package/dist/vocab/actor.test.js +5 -5
  142. package/dist/vocab/lookup.test.js +255 -5
  143. package/dist/vocab/mod.cjs +87 -0
  144. package/dist/vocab/mod.d.cts +6 -0
  145. package/dist/vocab/mod.d.ts +3 -3
  146. package/dist/vocab/mod.js +7 -7
  147. package/dist/vocab/type.test.js +3 -3
  148. package/dist/vocab/vocab.test.js +433 -9
  149. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BI0Ak5lL.d.ts} +290 -0
  150. package/dist/vocab-C5Y-0fGj.cjs +291 -0
  151. package/dist/vocab-Dw1-yVGg.d.cts +14922 -0
  152. package/dist/{vocab-BREfYr1a.js → vocab-rWbHpc2J.js} +26 -17
  153. package/dist/webfinger/handler.test.js +19 -19
  154. package/dist/webfinger/lookup.test.js +4 -4
  155. package/dist/webfinger/mod.cjs +9 -0
  156. package/dist/webfinger/mod.d.cts +4 -0
  157. package/dist/webfinger/mod.js +6 -6
  158. package/dist/webfinger-BjOEdFPs.cjs +4 -0
  159. package/dist/webfinger-De_bU0iE.js +4 -0
  160. package/dist/x/cfworkers.cjs +100 -0
  161. package/dist/x/cfworkers.d.cts +59 -0
  162. package/dist/x/cfworkers.js +3 -3
  163. package/dist/x/cfworkers.test.js +3 -3
  164. package/dist/x/hono.cjs +61 -0
  165. package/dist/x/hono.d.cts +54 -0
  166. package/dist/x/hono.d.ts +7 -7
  167. package/dist/x/hono.js +3 -3
  168. package/dist/x/sveltekit.cjs +69 -0
  169. package/dist/x/sveltekit.d.cts +46 -0
  170. package/dist/x/sveltekit.d.ts +7 -7
  171. package/dist/x/sveltekit.js +3 -3
  172. package/package.json +68 -13
  173. package/dist/compat-Bb5myD13.js +0 -4
  174. package/dist/key-BmFoI4_J.js +0 -10
  175. package/dist/middleware-D2W4gwdv.js +0 -17
  176. package/dist/middleware-LmK3pQ2z.js +0 -26
  177. package/dist/nodeinfo/semver.test.js +0 -143
  178. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  179. package/dist/runtime-BSkOVUWM.js +0 -4
  180. package/dist/semver-dArNLkR9.js +0 -149
  181. package/dist/sig-BXJO--F9.js +0 -4
  182. package/dist/webfinger-C3GIyXIg.js +0 -4
  183. /package/dist/{collection-CSzG2j1P.js → collection-CcnIw1qY.js} +0 -0
  184. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
 
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { deno_default } from "./docloader-DnepZfu_.js";
6
- import { CryptographicKey } from "./actor-DmsbGzXS.js";
7
- import { fetchKey, validateCryptoKey } from "./key-D-0OLe9C.js";
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { deno_default } from "./docloader-CkweNhUH.js";
6
+ import { CryptographicKey } from "./actor-G2S5sPEA.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-CkxrAIyp.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
@@ -658,7 +658,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
658
658
  const signatureBaseBytes = new TextEncoder().encode(signatureBase);
659
659
  span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
660
660
  try {
661
- const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes, signatureBaseBytes);
661
+ const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes);
662
662
  if (verified) {
663
663
  validKey = key;
664
664
  break;
@@ -0,0 +1,253 @@
1
+ import { DocumentLoader } from "./docloader-D-MrRyHl.cjs";
2
+ import { CryptographicKey, Multikey } from "./vocab-Dw1-yVGg.cjs";
3
+ import { TracerProvider } from "@opentelemetry/api";
4
+
5
+ //#region src/sig/key.d.ts
6
+
7
+ /**
8
+ * Generates a key pair which is appropriate for Fedify.
9
+ * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
10
+ * Ed25519 are supported.
11
+ * @returns The generated key pair.
12
+ * @throws {TypeError} If the algorithm is unsupported.
13
+ */
14
+ declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed25519"): Promise<CryptoKeyPair>;
15
+ /**
16
+ * Exports a key in JWK format.
17
+ * @param key The key to export. Either public or private key.
18
+ * @returns The exported key in JWK format. The key is suitable for
19
+ * serialization and storage.
20
+ * @throws {TypeError} If the key is invalid or unsupported.
21
+ */
22
+ declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
23
+ /**
24
+ * Imports a key from JWK format.
25
+ * @param jwk The key in JWK format.
26
+ * @param type Which type of key to import, either `"public"` or `"private"`.
27
+ * @returns The imported key.
28
+ * @throws {TypeError} If the key is invalid or unsupported.
29
+ */
30
+ declare function importJwk(jwk: JsonWebKey, type: "public" | "private"): Promise<CryptoKey>;
31
+ /**
32
+ * Options for {@link fetchKey}.
33
+ * @since 1.3.0
34
+ */
35
+ interface FetchKeyOptions {
36
+ /**
37
+ * The document loader for loading remote JSON-LD documents.
38
+ */
39
+ documentLoader?: DocumentLoader;
40
+ /**
41
+ * The context loader for loading remote JSON-LD contexts.
42
+ */
43
+ contextLoader?: DocumentLoader;
44
+ /**
45
+ * The key cache to use for caching public keys.
46
+ * @since 0.12.0
47
+ */
48
+ keyCache?: KeyCache;
49
+ /**
50
+ * The OpenTelemetry tracer provider to use for tracing. If omitted,
51
+ * the global tracer provider is used.
52
+ * @since 1.3.0
53
+ */
54
+ tracerProvider?: TracerProvider;
55
+ }
56
+ /**
57
+ * The result of {@link fetchKey}.
58
+ * @since 1.3.0
59
+ */
60
+ interface FetchKeyResult<T extends CryptographicKey | Multikey> {
61
+ /**
62
+ * The fetched (or cached) key.
63
+ */
64
+ readonly key: T & {
65
+ publicKey: CryptoKey;
66
+ } | null;
67
+ /**
68
+ * Whether the key is fetched from the cache.
69
+ */
70
+ readonly cached: boolean;
71
+ }
72
+ /**
73
+ * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
74
+ * If the given URL contains an {@link Actor} object, it tries to find
75
+ * the corresponding key in the `publicKey` or `assertionMethod` property.
76
+ * @template T The type of the key to fetch. Either {@link CryptographicKey}
77
+ * or {@link Multikey}.
78
+ * @param keyId The URL of the key.
79
+ * @param cls The class of the key to fetch. Either {@link CryptographicKey}
80
+ * or {@link Multikey}.
81
+ * @param options Options for fetching the key. See {@link FetchKeyOptions}.
82
+ * @returns The fetched key or `null` if the key is not found.
83
+ * @since 1.3.0
84
+ */
85
+ declare function fetchKey<T extends CryptographicKey | Multikey>(keyId: URL | string, cls: (new (...args: any[]) => T) & {
86
+ fromJsonLd(jsonLd: unknown, options: {
87
+ documentLoader?: DocumentLoader;
88
+ contextLoader?: DocumentLoader;
89
+ tracerProvider?: TracerProvider;
90
+ }): Promise<T>;
91
+ }, options?: FetchKeyOptions): Promise<FetchKeyResult<T>>;
92
+ /**
93
+ * A cache for storing cryptographic keys.
94
+ * @since 0.12.0
95
+ */
96
+ interface KeyCache {
97
+ /**
98
+ * Gets a key from the cache.
99
+ * @param keyId The key ID.
100
+ * @returns The key if found, `null` if the key is not available (e.g.,
101
+ * fetching the key was tried but failed), or `undefined`
102
+ * if the cache is not available.
103
+ */
104
+ get(keyId: URL): Promise<CryptographicKey | Multikey | null | undefined>;
105
+ /**
106
+ * Sets a key to the cache.
107
+ *
108
+ * Note that this caches unavailable keys (i.e., `null`) as well,
109
+ * and it is recommended to make unavailable keys expire after a short period.
110
+ * @param keyId The key ID.
111
+ * @param key The key to cache. `null` means the key is not available
112
+ * (e.g., fetching the key was tried but failed).
113
+ */
114
+ set(keyId: URL, key: CryptographicKey | Multikey | null): Promise<void>;
115
+ }
116
+ //#endregion
117
+ //#region src/sig/http.d.ts
118
+ /**
119
+ * The standard to use for signing and verifying HTTP signatures.
120
+ * @since 1.6.0
121
+ */
122
+ type HttpMessageSignaturesSpec =
123
+ /**
124
+ * The Signing HTTP Messages (draft-cavage-http-signatures-12) specification,
125
+ * which is widely adopted and used in the fediverse (as of May 2025).
126
+ */
127
+ "draft-cavage-http-signatures-12"
128
+ /**
129
+ * The HTTP Message Signatures (RFC 9421) specification, which is the
130
+ * finalized standard but not widely adopted yet (as of May 2025).
131
+ */ | "rfc9421";
132
+ /**
133
+ * Options for {@link signRequest}.
134
+ * @since 1.3.0
135
+ */
136
+ interface SignRequestOptions {
137
+ /**
138
+ * The HTTP message signatures specification to use for signing.
139
+ * @default `"draft-cavage-http-signatures-12"`
140
+ * @since 1.6.0
141
+ */
142
+ spec?: HttpMessageSignaturesSpec;
143
+ /**
144
+ * The current time. If not specified, the current time is used. This is
145
+ * useful for testing.
146
+ * @since 1.6.0
147
+ */
148
+ currentTime?: Temporal.Instant;
149
+ /**
150
+ * The request body as ArrayBuffer. If provided, avoids cloning the request body.
151
+ * @since 1.7.7
152
+ */
153
+ body?: ArrayBuffer | null;
154
+ /**
155
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
156
+ * is used.
157
+ */
158
+ tracerProvider?: TracerProvider;
159
+ }
160
+ /**
161
+ * Signs a request using the given private key.
162
+ * @param request The request to sign.
163
+ * @param privateKey The private key to use for signing.
164
+ * @param keyId The key ID to use for the signature. It will be used by the
165
+ * verifier.
166
+ * @returns The signed request.
167
+ * @throws {TypeError} If the private key is invalid or unsupported.
168
+ */
169
+ declare function signRequest(request: Request, privateKey: CryptoKey, keyId: URL, options?: SignRequestOptions): Promise<Request>;
170
+ /**
171
+ * Options for {@link verifyRequest}.
172
+ */
173
+ interface VerifyRequestOptions {
174
+ /**
175
+ * The document loader to use for fetching the public key.
176
+ */
177
+ documentLoader?: DocumentLoader;
178
+ /**
179
+ * The context loader to use for JSON-LD context retrieval.
180
+ */
181
+ contextLoader?: DocumentLoader;
182
+ /**
183
+ * The time window to allow for the request date. The actual time window is
184
+ * twice the value of this option, with the current time as the center.
185
+ * Or if it is `false`, no time check is performed.
186
+ *
187
+ * An hour by default.
188
+ */
189
+ timeWindow?: Temporal.Duration | Temporal.DurationLike | false;
190
+ /**
191
+ * The current time. If not specified, the current time is used. This is
192
+ * useful for testing.
193
+ */
194
+ currentTime?: Temporal.Instant;
195
+ /**
196
+ * The key cache to use for caching public keys.
197
+ * @since 0.12.0
198
+ */
199
+ keyCache?: KeyCache;
200
+ /**
201
+ * The HTTP message signatures specification to use for verifying.
202
+ * @default `"draft-cavage-http-signatures-12"`
203
+ * @since 1.6.0
204
+ */
205
+ spec?: HttpMessageSignaturesSpec;
206
+ /**
207
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
208
+ * is used.
209
+ * @since 1.3.0
210
+ */
211
+ tracerProvider?: TracerProvider;
212
+ }
213
+ /**
214
+ * Verifies the signature of a request.
215
+ *
216
+ * Note that this function consumes the request body, so it should not be used
217
+ * if the request body is already consumed. Consuming the request body after
218
+ * calling this function is okay, since this function clones the request
219
+ * under the hood.
220
+ *
221
+ * @param request The request to verify.
222
+ * @param options Options for verifying the request.
223
+ * @returns The public key of the verified signature, or `null` if the signature
224
+ * could not be verified.
225
+ */
226
+ declare function verifyRequest(request: Request, options?: VerifyRequestOptions): Promise<CryptographicKey | null>;
227
+ /**
228
+ * A spec determiner for HTTP Message Signatures.
229
+ * It determines the spec to use for signing requests.
230
+ * It is used for double-knocking
231
+ * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
232
+ * @since 1.6.0
233
+ */
234
+ interface HttpMessageSignaturesSpecDeterminer {
235
+ /**
236
+ * Determines the spec to use for signing requests.
237
+ * @param origin The origin of the URL to make the request to.
238
+ * @returns The spec to use for signing requests.
239
+ */
240
+ determineSpec(origin: string): HttpMessageSignaturesSpec | Promise<HttpMessageSignaturesSpec>;
241
+ /**
242
+ * Remembers the successfully used spec for the given origin.
243
+ * @param origin The origin of the URL that was requested.
244
+ * @param spec The spec to remember.
245
+ */
246
+ rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
247
+ }
248
+ /**
249
+ * The options for double-knock requests.
250
+ * @since 1.6.0
251
+ */
252
+ //#endregion
253
+ export { FetchKeyOptions, FetchKeyResult, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignRequestOptions, VerifyRequestOptions, exportJwk, fetchKey, generateCryptoKeyPair, importJwk, signRequest, verifyRequest };
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  import { DocumentLoader } from "./docloader-CxWcuWqQ.js";
4
- import { CryptographicKey, Multikey } from "./vocab-SOE1ifCr.js";
4
+ import { CryptographicKey, Multikey } from "./vocab-BI0Ak5lL.js";
5
5
  import { TracerProvider } from "@opentelemetry/api";
6
6
 
7
7
  //#region src/sig/key.d.ts
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { CryptographicKey, deno_default } from "./type-B2h-NRAo.js";
7
- import { fetchKey, validateCryptoKey } from "./key-BYNqWXyu.js";
6
+ import { CryptographicKey, deno_default } from "./type-NEA09tSC.js";
7
+ import { fetchKey, validateCryptoKey } from "./key-IxRhZpOF.js";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
10
  import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
@@ -658,7 +658,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
658
658
  const signatureBaseBytes = new TextEncoder().encode(signatureBase);
659
659
  span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
660
660
  try {
661
- const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes, signatureBaseBytes);
661
+ const verified = await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes);
662
662
  if (verified) {
663
663
  validKey = key;
664
664
  break;
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { Activity, deno_default, getTypeId } from "./type-B2h-NRAo.js";
6
+ import { Activity, deno_default, getTypeId } from "./type-NEA09tSC.js";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
9
9
 
@@ -41,17 +41,34 @@ var InboxListenerSet = class InboxListenerSet {
41
41
  return this.dispatchWithClass(activity)?.listener ?? null;
42
42
  }
43
43
  };
44
- async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider }) {
44
+ async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
45
45
  const logger = getLogger([
46
46
  "fedify",
47
47
  "federation",
48
48
  "inbox"
49
49
  ]);
50
- const cacheKey = activity.id == null ? null : [
51
- ...kvPrefixes.activityIdempotence,
52
- ctx.origin,
53
- activity.id.href
54
- ];
50
+ let cacheKey = null;
51
+ if (activity.id != null) {
52
+ const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href);
53
+ const strategy = idempotencyStrategy ?? "per-inbox";
54
+ let keyString;
55
+ if (typeof strategy === "function") {
56
+ const result = await strategy(inboxContext, activity);
57
+ keyString = result;
58
+ } else switch (strategy) {
59
+ case "global":
60
+ keyString = activity.id.href;
61
+ break;
62
+ case "per-origin":
63
+ keyString = `${ctx.origin}\n${activity.id.href}`;
64
+ break;
65
+ case "per-inbox":
66
+ keyString = `${ctx.origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
67
+ break;
68
+ default: keyString = `${ctx.origin}\n${activity.id.href}`;
69
+ }
70
+ if (keyString != null) cacheKey = [...kvPrefixes.activityIdempotence, keyString];
71
+ }
55
72
  if (cacheKey != null) {
56
73
  const cached = await kv.get(cacheKey);
57
74
  if (cached === true) {
@@ -0,0 +1,290 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ const require_chunk = require('./chunk-DqRYRqnO.cjs');
6
+ const require_docloader = require('./docloader-7Ey7wNHx.cjs');
7
+ const require_actor = require('./actor-CrTGiTZd.cjs');
8
+ const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
9
+ const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
10
+
11
+ //#region src/sig/key.ts
12
+ /**
13
+ * Checks if the given key is valid and supported. No-op if the key is valid,
14
+ * otherwise throws an error.
15
+ * @param key The key to check.
16
+ * @param type Which type of key to check. If not specified, the key can be
17
+ * either public or private.
18
+ * @throws {TypeError} If the key is invalid or unsupported.
19
+ */
20
+ function validateCryptoKey(key, type) {
21
+ if (type != null && key.type !== type) throw new TypeError(`The key is not a ${type} key.`);
22
+ if (!key.extractable) throw new TypeError("The key is not extractable.");
23
+ 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!");
24
+ if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
25
+ const algorithm = key.algorithm;
26
+ 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.");
27
+ }
28
+ }
29
+ /**
30
+ * Generates a key pair which is appropriate for Fedify.
31
+ * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
32
+ * Ed25519 are supported.
33
+ * @returns The generated key pair.
34
+ * @throws {TypeError} If the algorithm is unsupported.
35
+ */
36
+ function generateCryptoKeyPair(algorithm) {
37
+ if (algorithm == null) (0, __logtape_logtape.getLogger)([
38
+ "fedify",
39
+ "sig",
40
+ "key"
41
+ ]).warn("No algorithm specified. Using RSASSA-PKCS1-v1_5 by default, but it is recommended to specify the algorithm explicitly as the parameter will be required in the future.");
42
+ if (algorithm == null || algorithm === "RSASSA-PKCS1-v1_5") return crypto.subtle.generateKey({
43
+ name: "RSASSA-PKCS1-v1_5",
44
+ modulusLength: 4096,
45
+ publicExponent: new Uint8Array([
46
+ 1,
47
+ 0,
48
+ 1
49
+ ]),
50
+ hash: "SHA-256"
51
+ }, true, ["sign", "verify"]);
52
+ else if (algorithm === "Ed25519") return crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
53
+ throw new TypeError("Unsupported algorithm: " + algorithm);
54
+ }
55
+ /**
56
+ * Exports a key in JWK format.
57
+ * @param key The key to export. Either public or private key.
58
+ * @returns The exported key in JWK format. The key is suitable for
59
+ * serialization and storage.
60
+ * @throws {TypeError} If the key is invalid or unsupported.
61
+ */
62
+ async function exportJwk(key) {
63
+ validateCryptoKey(key);
64
+ const jwk = await crypto.subtle.exportKey("jwk", key);
65
+ if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
66
+ return jwk;
67
+ }
68
+ /**
69
+ * Imports a key from JWK format.
70
+ * @param jwk The key in JWK format.
71
+ * @param type Which type of key to import, either `"public"` or `"private"`.
72
+ * @returns The imported key.
73
+ * @throws {TypeError} If the key is invalid or unsupported.
74
+ */
75
+ async function importJwk(jwk, type) {
76
+ let key;
77
+ if (jwk.kty === "RSA" && jwk.alg === "RS256") key = await crypto.subtle.importKey("jwk", jwk, {
78
+ name: "RSASSA-PKCS1-v1_5",
79
+ hash: "SHA-256"
80
+ }, true, type === "public" ? ["verify"] : ["sign"]);
81
+ else if (jwk.kty === "OKP" && jwk.crv === "Ed25519") {
82
+ if (navigator?.userAgent === "Cloudflare-Workers") {
83
+ jwk = { ...jwk };
84
+ delete jwk.alg;
85
+ }
86
+ key = await crypto.subtle.importKey("jwk", jwk, "Ed25519", true, type === "public" ? ["verify"] : ["sign"]);
87
+ } else throw new TypeError("Unsupported JWK format.");
88
+ validateCryptoKey(key, type);
89
+ return key;
90
+ }
91
+ /**
92
+ * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
93
+ * If the given URL contains an {@link Actor} object, it tries to find
94
+ * the corresponding key in the `publicKey` or `assertionMethod` property.
95
+ * @template T The type of the key to fetch. Either {@link CryptographicKey}
96
+ * or {@link Multikey}.
97
+ * @param keyId The URL of the key.
98
+ * @param cls The class of the key to fetch. Either {@link CryptographicKey}
99
+ * or {@link Multikey}.
100
+ * @param options Options for fetching the key. See {@link FetchKeyOptions}.
101
+ * @returns The fetched key or `null` if the key is not found.
102
+ * @since 1.3.0
103
+ */
104
+ function fetchKey(keyId, cls, options = {}) {
105
+ const tracerProvider = options.tracerProvider ?? __opentelemetry_api.trace.getTracerProvider();
106
+ const tracer = tracerProvider.getTracer(require_docloader.deno_default.name, require_docloader.deno_default.version);
107
+ keyId = typeof keyId === "string" ? new URL(keyId) : keyId;
108
+ return tracer.startActiveSpan("activitypub.fetch_key", {
109
+ kind: __opentelemetry_api.SpanKind.CLIENT,
110
+ attributes: {
111
+ "http.method": "GET",
112
+ "url.full": keyId.href,
113
+ "url.scheme": keyId.protocol.replace(/:$/, ""),
114
+ "url.domain": keyId.hostname,
115
+ "url.path": keyId.pathname,
116
+ "url.query": keyId.search.replace(/^\?/, ""),
117
+ "url.fragment": keyId.hash.replace(/^#/, "")
118
+ }
119
+ }, async (span) => {
120
+ try {
121
+ const result = await fetchKeyInternal(keyId, cls, options);
122
+ span.setAttribute("activitypub.actor.key.cached", result.cached);
123
+ return result;
124
+ } catch (e) {
125
+ span.setStatus({
126
+ code: __opentelemetry_api.SpanStatusCode.ERROR,
127
+ message: String(e)
128
+ });
129
+ throw e;
130
+ } finally {
131
+ span.end();
132
+ }
133
+ });
134
+ }
135
+ async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, keyCache, tracerProvider } = {}) {
136
+ const logger = (0, __logtape_logtape.getLogger)([
137
+ "fedify",
138
+ "sig",
139
+ "key"
140
+ ]);
141
+ const cacheKey = typeof keyId === "string" ? new URL(keyId) : keyId;
142
+ keyId = typeof keyId === "string" ? keyId : keyId.href;
143
+ if (keyCache != null) {
144
+ const cachedKey = await keyCache.get(cacheKey);
145
+ if (cachedKey instanceof cls && cachedKey.publicKey != null) {
146
+ logger.debug("Key {keyId} found in cache.", { keyId });
147
+ return {
148
+ key: cachedKey,
149
+ cached: true
150
+ };
151
+ } else if (cachedKey === null) {
152
+ logger.debug("Entry {keyId} found in cache, but it is unavailable.", { keyId });
153
+ return {
154
+ key: null,
155
+ cached: true
156
+ };
157
+ }
158
+ }
159
+ logger.debug("Fetching key {keyId} to verify signature...", { keyId });
160
+ let document;
161
+ try {
162
+ const remoteDocument = await (documentLoader ?? require_docloader.getDocumentLoader())(keyId);
163
+ document = remoteDocument.document;
164
+ } catch (_) {
165
+ logger.debug("Failed to fetch key {keyId}.", { keyId });
166
+ await keyCache?.set(cacheKey, null);
167
+ return {
168
+ key: null,
169
+ cached: false
170
+ };
171
+ }
172
+ let object;
173
+ try {
174
+ object = await require_actor.Object.fromJsonLd(document, {
175
+ documentLoader,
176
+ contextLoader,
177
+ tracerProvider
178
+ });
179
+ } catch (e) {
180
+ if (!(e instanceof TypeError)) throw e;
181
+ try {
182
+ object = await cls.fromJsonLd(document, {
183
+ documentLoader,
184
+ contextLoader,
185
+ tracerProvider
186
+ });
187
+ } catch (e$1) {
188
+ if (e$1 instanceof TypeError) {
189
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
190
+ await keyCache?.set(cacheKey, null);
191
+ return {
192
+ key: null,
193
+ cached: false
194
+ };
195
+ }
196
+ throw e$1;
197
+ }
198
+ }
199
+ let key = null;
200
+ if (object instanceof cls) key = object;
201
+ else if (require_actor.isActor(object)) {
202
+ const keys = cls === require_actor.CryptographicKey ? object.getPublicKeys({
203
+ documentLoader,
204
+ contextLoader,
205
+ tracerProvider
206
+ }) : object.getAssertionMethods({
207
+ documentLoader,
208
+ contextLoader,
209
+ tracerProvider
210
+ });
211
+ let length = 0;
212
+ let lastKey = null;
213
+ for await (const k of keys) {
214
+ length++;
215
+ lastKey = k;
216
+ if (k.id?.href === keyId) {
217
+ key = k;
218
+ break;
219
+ }
220
+ }
221
+ const keyIdUrl = new URL(keyId);
222
+ if (key == null && keyIdUrl.hash === "" && length === 1) key = lastKey;
223
+ if (key == null) {
224
+ logger.debug("Failed to verify; object {keyId} returned an {actorType}, but has no key matching {keyId}.", {
225
+ keyId,
226
+ actorType: object.constructor.name
227
+ });
228
+ await keyCache?.set(cacheKey, null);
229
+ return {
230
+ key: null,
231
+ cached: false
232
+ };
233
+ }
234
+ } else {
235
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
236
+ await keyCache?.set(cacheKey, null);
237
+ return {
238
+ key: null,
239
+ cached: false
240
+ };
241
+ }
242
+ if (key.publicKey == null) {
243
+ logger.debug("Failed to verify; key {keyId} has no publicKeyPem field.", { keyId });
244
+ await keyCache?.set(cacheKey, null);
245
+ return {
246
+ key: null,
247
+ cached: false
248
+ };
249
+ }
250
+ if (keyCache != null) {
251
+ await keyCache.set(cacheKey, key);
252
+ logger.debug("Key {keyId} cached.", { keyId });
253
+ }
254
+ return {
255
+ key,
256
+ cached: false
257
+ };
258
+ }
259
+
260
+ //#endregion
261
+ Object.defineProperty(exports, 'exportJwk', {
262
+ enumerable: true,
263
+ get: function () {
264
+ return exportJwk;
265
+ }
266
+ });
267
+ Object.defineProperty(exports, 'fetchKey', {
268
+ enumerable: true,
269
+ get: function () {
270
+ return fetchKey;
271
+ }
272
+ });
273
+ Object.defineProperty(exports, 'generateCryptoKeyPair', {
274
+ enumerable: true,
275
+ get: function () {
276
+ return generateCryptoKeyPair;
277
+ }
278
+ });
279
+ Object.defineProperty(exports, 'importJwk', {
280
+ enumerable: true,
281
+ get: function () {
282
+ return importJwk;
283
+ }
284
+ });
285
+ Object.defineProperty(exports, 'validateCryptoKey', {
286
+ enumerable: true,
287
+ get: function () {
288
+ return validateCryptoKey;
289
+ }
290
+ });
@@ -0,0 +1,10 @@
1
+
2
+ const { Temporal } = require("@js-temporal/polyfill");
3
+ const { URLPattern } = require("urlpattern-polyfill");
4
+
5
+ require('./docloader-7Ey7wNHx.cjs');
6
+ require('./actor-CrTGiTZd.cjs');
7
+ require('./lookup-DiV4LFBg.cjs');
8
+ const require_key = require('./key-CZR7QraT.cjs');
9
+
10
+ exports.validateCryptoKey = require_key.validateCryptoKey;
@@ -1,9 +1,9 @@
1
1
 
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { deno_default, getDocumentLoader } from "./docloader-DnepZfu_.js";
6
- import { CryptographicKey, Object as Object$1, isActor } from "./actor-DmsbGzXS.js";
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { deno_default, getDocumentLoader } from "./docloader-CkweNhUH.js";
6
+ import { CryptographicKey, Object as Object$1, isActor } from "./actor-G2S5sPEA.js";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
 
@@ -0,0 +1,10 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import "./docloader-CkweNhUH.js";
6
+ import "./actor-G2S5sPEA.js";
7
+ import "./lookup-cVRa2QM-.js";
8
+ import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-CkxrAIyp.js";
9
+
10
+ export { validateCryptoKey };