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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +3 -0
  2. package/dist/{actor-Cc6B76eG.js → actor-BXHc5r-q.js} +1 -1
  3. package/dist/actor-Ba9Z1eNJ.cjs +42079 -0
  4. package/dist/{actor-C22bXuuC.d.ts → actor-DqFajh9s.d.ts} +2 -2
  5. package/dist/{actor-CTAuCsWy.js → actor-DzhunPC_.js} +7058 -2722
  6. package/dist/actor-f2NtjyCg.d.cts +128 -0
  7. package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
  8. package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
  9. package/dist/{builder-BOEBObR8.js → builder-u7usRsT3.js} +13 -8
  10. package/dist/chunk-DqRYRqnO.cjs +34 -0
  11. package/dist/client-94iWEfQa.d.cts +222 -0
  12. package/dist/{client-DF8anIB5.d.ts → client-BsGzbnV-.d.ts} +3 -75
  13. package/dist/{client-De-z2UnN.js → client-pY7-3icS.js} +3 -22
  14. package/dist/compat/mod.cjs +10 -0
  15. package/dist/compat/mod.d.cts +12 -0
  16. package/dist/compat/mod.d.ts +11 -12
  17. package/dist/compat/mod.js +5 -5
  18. package/dist/compat/transformers.test.js +20 -20
  19. package/dist/compat-DmDDELst.cjs +4 -0
  20. package/dist/compat-nxUqe4Z-.js +4 -0
  21. package/dist/{context-9gCpIkiz.d.ts → context-DG0huGW-.d.ts} +184 -127
  22. package/dist/context-DJ8aSy2Q.d.cts +2312 -0
  23. package/dist/{authdocloader-CLgDGafZ.js → docloader-CrbAy9Oc.js} +17 -8
  24. package/dist/{esm-CHdxdkuH.js → esm-C-Qa1zEM.js} +11 -11
  25. package/dist/federation/builder.test.js +9 -12
  26. package/dist/federation/collection.test.js +7 -9
  27. package/dist/federation/handler.test.js +27 -148
  28. package/dist/federation/idempotency.test.js +201 -0
  29. package/dist/federation/inbox.test.js +4 -6
  30. package/dist/federation/keycache.test.js +3 -4
  31. package/dist/federation/kv.test.js +7 -8
  32. package/dist/federation/middleware.test.js +242 -64
  33. package/dist/federation/mod.cjs +27 -0
  34. package/dist/federation/mod.d.cts +12 -0
  35. package/dist/federation/mod.d.ts +12 -13
  36. package/dist/federation/mod.js +13 -15
  37. package/dist/federation/mq.test.js +8 -10
  38. package/dist/federation/negotiation.test.js +26 -0
  39. package/dist/federation/retry.test.js +4 -5
  40. package/dist/federation/router.test.js +6 -8
  41. package/dist/federation/send.test.js +13 -15
  42. package/dist/federation-CRpdnOMS.cjs +244 -0
  43. package/dist/{federation-CMX7WzeL.js → federation-jcR8-ZxP.js} +3 -3
  44. package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
  45. package/dist/{http-DqSNLFNY.d.ts → http-BbO0ejuk.d.ts} +2 -2
  46. package/dist/{http-l0TEupZK.js → http-CUVx-vzb.js} +260 -10
  47. package/dist/{http-CcdM1brU.js → http-D2kIm9la.js} +3 -3
  48. package/dist/http-Dofes42e.cjs +1106 -0
  49. package/dist/http-M8k5mKc0.d.cts +253 -0
  50. package/dist/{inbox-B6DZbGNf.js → inbox-HjG5peXY.js} +24 -7
  51. package/dist/{key-CzLv1phF.js → key-CxdLUFS6.js} +3 -2
  52. package/dist/{keycache-B8HdZJSt.js → keycache-bU7COwsh.js} +1 -1
  53. package/dist/{keys-zZwiKkfx.js → keys-DMHs8XNn.js} +2 -1
  54. package/dist/kv-Bxr0Q87_.d.cts +81 -0
  55. package/dist/kv-cache-CGXcDejL.js +122 -0
  56. package/dist/kv-cache-DN9pfMBe.js +94 -0
  57. package/dist/kv-cache-Dkvbn6rg.cjs +134 -0
  58. package/dist/{ld-CBcQdZ6N.js → ld-CIhvSCCr.js} +5 -4
  59. package/dist/lookup-CHkCVZTU.js +260 -0
  60. package/dist/lookup-CfFkONZD.cjs +272 -0
  61. package/dist/{type-SK-d7Tbw.js → lookup-DQRtjvb1.js} +7266 -7087
  62. package/dist/middleware-Bot7EEwV.js +26 -0
  63. package/dist/middleware-CFJgmUMW.cjs +15 -0
  64. package/dist/{middleware-BRgu1IH8.js → middleware-CJlj5Olw.js} +86 -181
  65. package/dist/middleware-CjHl2NHA.js +15 -0
  66. package/dist/middleware-D74TgW2E.cjs +4225 -0
  67. package/dist/{middleware-CxEkcFW0.js → middleware-DMk2Mdn9.js} +117 -127
  68. package/dist/mod-0noXw66R.d.cts +107 -0
  69. package/dist/mod-B-hUPT2N.d.cts +1 -0
  70. package/dist/{mod-Drmz72EK.d.ts → mod-B2iOw50L.d.ts} +3 -3
  71. package/dist/mod-B9M-8jm2.d.ts +109 -0
  72. package/dist/{mod-Cxt4Kpf6.d.ts → mod-BlVovdcy.d.ts} +20 -2
  73. package/dist/{mod-Bqxcp7eN.d.ts → mod-BoHnwOCs.d.ts} +2 -2
  74. package/dist/mod-BxRCHTz-.d.cts +307 -0
  75. package/dist/mod-C2tOeRkN.d.cts +1 -0
  76. package/dist/mod-C58MZ7Wx.d.cts +113 -0
  77. package/dist/mod-DJcZDvjA.d.cts +80 -0
  78. package/dist/mod-DgdBYYa0.d.cts +266 -0
  79. package/dist/{mod-DBzN0aCM.d.ts → mod-Ds0mpFZU.d.ts} +1 -1
  80. package/dist/mod.cjs +137 -0
  81. package/dist/mod.d.cts +16 -0
  82. package/dist/mod.d.ts +16 -17
  83. package/dist/mod.js +19 -21
  84. package/dist/mq-DcJPkXD5.d.cts +140 -0
  85. package/dist/negotiation-C4nFufNk.js +71 -0
  86. package/dist/nodeinfo/client.test.js +30 -111
  87. package/dist/nodeinfo/handler.test.js +25 -26
  88. package/dist/nodeinfo/mod.cjs +10 -0
  89. package/dist/nodeinfo/mod.d.cts +3 -0
  90. package/dist/nodeinfo/mod.d.ts +3 -5
  91. package/dist/nodeinfo/mod.js +6 -7
  92. package/dist/nodeinfo/types.test.js +8 -15
  93. package/dist/nodeinfo-BnthBobC.js +4 -0
  94. package/dist/nodeinfo-CdN0rEnZ.cjs +4 -0
  95. package/dist/owner-B4HbyP8s.d.cts +67 -0
  96. package/dist/{owner-VEIjmR8r.js → owner-Dvh7mBvr.js} +3 -2
  97. package/dist/{owner-CQPnQVtf.d.ts → owner-kQRGVXG1.d.ts} +3 -3
  98. package/dist/proof-D0uThUvD.cjs +674 -0
  99. package/dist/{proof-DoSQAGkE.js → proof-Dgy35fzc.js} +3 -3
  100. package/dist/{proof-tgUlT8hw.js → proof-fqzaMJ4g.js} +11 -10
  101. package/dist/{send-BzS7w-QF.js → send-Drp20VO9.js} +2 -2
  102. package/dist/sig/http.test.js +13 -14
  103. package/dist/sig/key.test.js +9 -11
  104. package/dist/sig/ld.test.js +8 -10
  105. package/dist/sig/mod.cjs +28 -0
  106. package/dist/sig/mod.d.cts +6 -0
  107. package/dist/sig/mod.d.ts +5 -7
  108. package/dist/sig/mod.js +8 -10
  109. package/dist/sig/owner.test.js +10 -12
  110. package/dist/sig/proof.test.js +13 -14
  111. package/dist/sig-C34-oHBl.js +4 -0
  112. package/dist/sig-YYj5tCnr.cjs +4 -0
  113. package/dist/testing/docloader.test.js +6 -8
  114. package/dist/testing/mod.d.ts +387 -224
  115. package/dist/testing/mod.js +2 -3
  116. package/dist/{testing-Z2omCvKy.js → testing-g4UC4liW.js} +1 -2
  117. package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
  118. package/dist/transformers-CoBS-oFG.cjs +116 -0
  119. package/dist/{types-DgPvoUWN.js → types-BtUjyi5y.js} +8 -169
  120. package/dist/{types-BIgY6c-l.js → types-C2XVl6gj.js} +1 -3
  121. package/dist/types-CWgzGaqk.cjs +315 -0
  122. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +14 -15
  123. package/dist/utils/kv-cache.test.js +209 -0
  124. package/dist/utils/mod.cjs +12 -0
  125. package/dist/utils/mod.d.cts +5 -0
  126. package/dist/utils/mod.d.ts +7 -0
  127. package/dist/utils/mod.js +11 -0
  128. package/dist/utils-D-Va7aXC.js +4 -0
  129. package/dist/utils-DyRU1gdZ.cjs +4 -0
  130. package/dist/vocab/actor.test.js +8 -10
  131. package/dist/vocab/lookup.test.js +257 -9
  132. package/dist/vocab/mod.cjs +86 -0
  133. package/dist/vocab/mod.d.cts +4 -0
  134. package/dist/vocab/mod.d.ts +3 -5
  135. package/dist/vocab/mod.js +6 -7
  136. package/dist/vocab/type.test.js +2 -3
  137. package/dist/vocab/vocab.test.js +438 -15
  138. package/dist/{vocab-SOE1ifCr.d.ts → vocab-BCWe1Ih5.d.ts} +292 -21
  139. package/dist/{vocab-CvD6Vbml.js → vocab-BnR3nIU9.js} +26 -17
  140. package/dist/vocab-CeDBzu-f.d.cts +14903 -0
  141. package/dist/{lookup-Bn_HEC_d.js → vocab-DFaWWYDn.cjs} +108 -139
  142. package/dist/webfinger/handler.test.js +24 -25
  143. package/dist/webfinger/lookup.test.js +7 -9
  144. package/dist/webfinger/mod.cjs +8 -0
  145. package/dist/webfinger/mod.d.cts +2 -0
  146. package/dist/webfinger/mod.d.ts +1 -3
  147. package/dist/webfinger/mod.js +5 -6
  148. package/dist/webfinger-C72Y8lrh.js +4 -0
  149. package/dist/webfinger-vAtLmxOF.cjs +4 -0
  150. package/dist/x/cfworkers.cjs +100 -0
  151. package/dist/x/cfworkers.d.cts +59 -0
  152. package/dist/x/cfworkers.d.ts +2 -2
  153. package/dist/x/cfworkers.js +3 -3
  154. package/dist/x/cfworkers.test.js +6 -8
  155. package/dist/x/hono.cjs +61 -0
  156. package/dist/x/hono.d.cts +53 -0
  157. package/dist/x/hono.d.ts +10 -11
  158. package/dist/x/hono.js +3 -3
  159. package/dist/x/sveltekit.cjs +69 -0
  160. package/dist/x/sveltekit.d.cts +45 -0
  161. package/dist/x/sveltekit.d.ts +10 -11
  162. package/dist/x/sveltekit.js +3 -3
  163. package/package.json +79 -23
  164. package/dist/assert_throws-BOO88avQ.js +0 -39
  165. package/dist/authdocloader-BFVqUbyo.js +0 -52
  166. package/dist/compat-Bb5myD13.js +0 -4
  167. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  168. package/dist/docloader-DEhniCVa.js +0 -4615
  169. package/dist/key-CUZQgVlf.js +0 -10
  170. package/dist/key-Deb0_wWL.js +0 -10
  171. package/dist/key-DxA6xRtZ.js +0 -260
  172. package/dist/lookup-dtdr2ftf.js +0 -131
  173. package/dist/middleware-BE_geSiJ.js +0 -17
  174. package/dist/middleware-BnU6hzVp.js +0 -26
  175. package/dist/mod-TFoH2Ql8.d.ts +0 -104
  176. package/dist/nodeinfo/semver.test.js +0 -143
  177. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  178. package/dist/runtime/docloader.test.js +0 -522
  179. package/dist/runtime/key.test.js +0 -103
  180. package/dist/runtime/langstr.test.d.ts +0 -3
  181. package/dist/runtime/langstr.test.js +0 -39
  182. package/dist/runtime/mod.d.ts +0 -8
  183. package/dist/runtime/mod.js +0 -13
  184. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  185. package/dist/runtime/multibase/multibase.test.js +0 -358
  186. package/dist/runtime/url.test.d.ts +0 -3
  187. package/dist/runtime/url.test.js +0 -45
  188. package/dist/runtime-BSkOVUWM.js +0 -4
  189. package/dist/semver-dArNLkR9.js +0 -149
  190. package/dist/sig-BXJO--F9.js +0 -4
  191. package/dist/webfinger-C3GIyXIg.js +0 -4
  192. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  193. /package/dist/{collection-CSzG2j1P.js → collection-BzWsN9pB.js} +0 -0
  194. /package/dist/{denokv-Bv33Xxea.js → denokv-CCssOzMJ.js} +0 -0
  195. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
  196. /package/dist/{runtime/authdocloader.test.d.ts → federation/negotiation.test.d.ts} +0 -0
  197. /package/dist/{kv-C7sopW2E.d.ts → kv-BKNZ-Tb-.d.ts} +0 -0
  198. /package/dist/{mod-1pDWKvUL.d.ts → mod-CVgZgliM.d.ts} +0 -0
  199. /package/dist/{mod-g0xFzAP9.d.ts → mod-xIj-IT58.d.ts} +0 -0
  200. /package/dist/{mq-CRGm1e_F.d.ts → mq-CUKlBw08.d.ts} +0 -0
  201. /package/dist/{retry-D4GJ670a.js → retry-CfF8Gn4d.js} +0 -0
  202. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  203. /package/dist/{runtime → utils}/docloader.test.d.ts +0 -0
  204. /package/dist/{runtime/key.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
@@ -1,10 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import "./type-SK-d7Tbw.js";
7
- import "./actor-Cc6B76eG.js";
8
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-CzLv1phF.js";
9
-
10
- export { validateCryptoKey };
@@ -1,10 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import "./docloader-DEhniCVa.js";
6
- import "./actor-CTAuCsWy.js";
7
- import "./lookup-dtdr2ftf.js";
8
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-DxA6xRtZ.js";
9
-
10
- export { validateCryptoKey };
@@ -1,260 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { deno_default, getDocumentLoader } from "./docloader-DEhniCVa.js";
6
- import { CryptographicKey, Object as Object$1, isActor } from "./actor-CTAuCsWy.js";
7
- import { getLogger } from "@logtape/logtape";
8
- import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
-
10
- //#region src/sig/key.ts
11
- /**
12
- * Checks if the given key is valid and supported. No-op if the key is valid,
13
- * otherwise throws an error.
14
- * @param key The key to check.
15
- * @param type Which type of key to check. If not specified, the key can be
16
- * either public or private.
17
- * @throws {TypeError} If the key is invalid or unsupported.
18
- */
19
- function validateCryptoKey(key, type) {
20
- if (type != null && key.type !== type) throw new TypeError(`The key is not a ${type} key.`);
21
- if (!key.extractable) throw new TypeError("The key is not extractable.");
22
- 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!");
23
- if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
24
- const algorithm = key.algorithm;
25
- 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.");
26
- }
27
- }
28
- /**
29
- * Generates a key pair which is appropriate for Fedify.
30
- * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
31
- * Ed25519 are supported.
32
- * @returns The generated key pair.
33
- * @throws {TypeError} If the algorithm is unsupported.
34
- */
35
- function generateCryptoKeyPair(algorithm) {
36
- if (algorithm == null) getLogger([
37
- "fedify",
38
- "sig",
39
- "key"
40
- ]).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.");
41
- if (algorithm == null || algorithm === "RSASSA-PKCS1-v1_5") return crypto.subtle.generateKey({
42
- name: "RSASSA-PKCS1-v1_5",
43
- modulusLength: 4096,
44
- publicExponent: new Uint8Array([
45
- 1,
46
- 0,
47
- 1
48
- ]),
49
- hash: "SHA-256"
50
- }, true, ["sign", "verify"]);
51
- else if (algorithm === "Ed25519") return crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
52
- throw new TypeError("Unsupported algorithm: " + algorithm);
53
- }
54
- /**
55
- * Exports a key in JWK format.
56
- * @param key The key to export. Either public or private key.
57
- * @returns The exported key in JWK format. The key is suitable for
58
- * serialization and storage.
59
- * @throws {TypeError} If the key is invalid or unsupported.
60
- */
61
- async function exportJwk(key) {
62
- validateCryptoKey(key);
63
- const jwk = await crypto.subtle.exportKey("jwk", key);
64
- if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
65
- return jwk;
66
- }
67
- /**
68
- * Imports a key from JWK format.
69
- * @param jwk The key in JWK format.
70
- * @param type Which type of key to import, either `"public"` or `"private"`.
71
- * @returns The imported key.
72
- * @throws {TypeError} If the key is invalid or unsupported.
73
- */
74
- async function importJwk(jwk, type) {
75
- let key;
76
- if (jwk.kty === "RSA" && jwk.alg === "RS256") key = await crypto.subtle.importKey("jwk", jwk, {
77
- name: "RSASSA-PKCS1-v1_5",
78
- hash: "SHA-256"
79
- }, true, type === "public" ? ["verify"] : ["sign"]);
80
- else if (jwk.kty === "OKP" && jwk.crv === "Ed25519") {
81
- if (navigator?.userAgent === "Cloudflare-Workers") {
82
- jwk = { ...jwk };
83
- delete jwk.alg;
84
- }
85
- key = await crypto.subtle.importKey("jwk", jwk, "Ed25519", true, type === "public" ? ["verify"] : ["sign"]);
86
- } else throw new TypeError("Unsupported JWK format.");
87
- validateCryptoKey(key, type);
88
- return key;
89
- }
90
- /**
91
- * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
92
- * If the given URL contains an {@link Actor} object, it tries to find
93
- * the corresponding key in the `publicKey` or `assertionMethod` property.
94
- * @template T The type of the key to fetch. Either {@link CryptographicKey}
95
- * or {@link Multikey}.
96
- * @param keyId The URL of the key.
97
- * @param cls The class of the key to fetch. Either {@link CryptographicKey}
98
- * or {@link Multikey}.
99
- * @param options Options for fetching the key. See {@link FetchKeyOptions}.
100
- * @returns The fetched key or `null` if the key is not found.
101
- * @since 1.3.0
102
- */
103
- function fetchKey(keyId, cls, options = {}) {
104
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
105
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
106
- keyId = typeof keyId === "string" ? new URL(keyId) : keyId;
107
- return tracer.startActiveSpan("activitypub.fetch_key", {
108
- kind: SpanKind.CLIENT,
109
- attributes: {
110
- "http.method": "GET",
111
- "url.full": keyId.href,
112
- "url.scheme": keyId.protocol.replace(/:$/, ""),
113
- "url.domain": keyId.hostname,
114
- "url.path": keyId.pathname,
115
- "url.query": keyId.search.replace(/^\?/, ""),
116
- "url.fragment": keyId.hash.replace(/^#/, "")
117
- }
118
- }, async (span) => {
119
- try {
120
- const result = await fetchKeyInternal(keyId, cls, options);
121
- span.setAttribute("activitypub.actor.key.cached", result.cached);
122
- return result;
123
- } catch (e) {
124
- span.setStatus({
125
- code: SpanStatusCode.ERROR,
126
- message: String(e)
127
- });
128
- throw e;
129
- } finally {
130
- span.end();
131
- }
132
- });
133
- }
134
- async function fetchKeyInternal(keyId, cls, { documentLoader, contextLoader, keyCache, tracerProvider } = {}) {
135
- const logger = getLogger([
136
- "fedify",
137
- "sig",
138
- "key"
139
- ]);
140
- const cacheKey = typeof keyId === "string" ? new URL(keyId) : keyId;
141
- keyId = typeof keyId === "string" ? keyId : keyId.href;
142
- if (keyCache != null) {
143
- const cachedKey = await keyCache.get(cacheKey);
144
- if (cachedKey instanceof cls && cachedKey.publicKey != null) {
145
- logger.debug("Key {keyId} found in cache.", { keyId });
146
- return {
147
- key: cachedKey,
148
- cached: true
149
- };
150
- } else if (cachedKey === null) {
151
- logger.debug("Entry {keyId} found in cache, but it is unavailable.", { keyId });
152
- return {
153
- key: null,
154
- cached: true
155
- };
156
- }
157
- }
158
- logger.debug("Fetching key {keyId} to verify signature...", { keyId });
159
- let document;
160
- try {
161
- const remoteDocument = await (documentLoader ?? getDocumentLoader())(keyId);
162
- document = remoteDocument.document;
163
- } catch (_) {
164
- logger.debug("Failed to fetch key {keyId}.", { keyId });
165
- await keyCache?.set(cacheKey, null);
166
- return {
167
- key: null,
168
- cached: false
169
- };
170
- }
171
- let object;
172
- try {
173
- object = await Object$1.fromJsonLd(document, {
174
- documentLoader,
175
- contextLoader,
176
- tracerProvider
177
- });
178
- } catch (e) {
179
- if (!(e instanceof TypeError)) throw e;
180
- try {
181
- object = await cls.fromJsonLd(document, {
182
- documentLoader,
183
- contextLoader,
184
- tracerProvider
185
- });
186
- } catch (e$1) {
187
- if (e$1 instanceof TypeError) {
188
- logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
189
- await keyCache?.set(cacheKey, null);
190
- return {
191
- key: null,
192
- cached: false
193
- };
194
- }
195
- throw e$1;
196
- }
197
- }
198
- let key = null;
199
- if (object instanceof cls) key = object;
200
- else if (isActor(object)) {
201
- const keys = cls === CryptographicKey ? object.getPublicKeys({
202
- documentLoader,
203
- contextLoader,
204
- tracerProvider
205
- }) : object.getAssertionMethods({
206
- documentLoader,
207
- contextLoader,
208
- tracerProvider
209
- });
210
- let length = 0;
211
- let lastKey = null;
212
- for await (const k of keys) {
213
- length++;
214
- lastKey = k;
215
- if (k.id?.href === keyId) {
216
- key = k;
217
- break;
218
- }
219
- }
220
- const keyIdUrl = new URL(keyId);
221
- if (key == null && keyIdUrl.hash === "" && length === 1) key = lastKey;
222
- if (key == null) {
223
- logger.debug("Failed to verify; object {keyId} returned an {actorType}, but has no key matching {keyId}.", {
224
- keyId,
225
- actorType: object.constructor.name
226
- });
227
- await keyCache?.set(cacheKey, null);
228
- return {
229
- key: null,
230
- cached: false
231
- };
232
- }
233
- } else {
234
- logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
235
- await keyCache?.set(cacheKey, null);
236
- return {
237
- key: null,
238
- cached: false
239
- };
240
- }
241
- if (key.publicKey == null) {
242
- logger.debug("Failed to verify; key {keyId} has no publicKeyPem field.", { keyId });
243
- await keyCache?.set(cacheKey, null);
244
- return {
245
- key: null,
246
- cached: false
247
- };
248
- }
249
- if (keyCache != null) {
250
- await keyCache.set(cacheKey, key);
251
- logger.debug("Key {keyId} cached.", { keyId });
252
- }
253
- return {
254
- key,
255
- cached: false
256
- };
257
- }
258
-
259
- //#endregion
260
- export { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey };
@@ -1,131 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { UrlError, deno_default, getUserAgent, validatePublicUrl } from "./docloader-DEhniCVa.js";
6
- import { getLogger } from "@logtape/logtape";
7
- import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
-
9
- //#region src/webfinger/lookup.ts
10
- const logger = getLogger([
11
- "fedify",
12
- "webfinger",
13
- "lookup"
14
- ]);
15
- const DEFAULT_MAX_REDIRECTION = 5;
16
- /**
17
- * Looks up a WebFinger resource.
18
- * @param resource The resource URL to look up.
19
- * @param options Extra options for looking up the resource.
20
- * @returns The resource descriptor, or `null` if not found.
21
- * @since 0.2.0
22
- */
23
- async function lookupWebFinger(resource, options = {}) {
24
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
25
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
26
- return await tracer.startActiveSpan("webfinger.lookup", {
27
- kind: SpanKind.CLIENT,
28
- attributes: {
29
- "webfinger.resource": resource.toString(),
30
- "webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
31
- }
32
- }, async (span) => {
33
- try {
34
- const result = await lookupWebFingerInternal(resource, options);
35
- span.setStatus({ code: result === null ? SpanStatusCode.ERROR : SpanStatusCode.OK });
36
- return result;
37
- } catch (error) {
38
- span.setStatus({
39
- code: SpanStatusCode.ERROR,
40
- message: String(error)
41
- });
42
- throw error;
43
- } finally {
44
- span.end();
45
- }
46
- });
47
- }
48
- async function lookupWebFingerInternal(resource, options = {}) {
49
- if (typeof resource === "string") resource = new URL(resource);
50
- let protocol = "https:";
51
- let server;
52
- if (resource.protocol === "acct:") {
53
- const atPos = resource.pathname.lastIndexOf("@");
54
- if (atPos < 0) return null;
55
- server = resource.pathname.substring(atPos + 1);
56
- if (server === "") return null;
57
- } else {
58
- protocol = resource.protocol;
59
- server = resource.host;
60
- }
61
- let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
62
- url.searchParams.set("resource", resource.href);
63
- let redirected = 0;
64
- while (true) {
65
- logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
66
- let response;
67
- if (options.allowPrivateAddress !== true) try {
68
- await validatePublicUrl(url.href);
69
- } catch (e) {
70
- if (e instanceof UrlError) {
71
- logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
72
- return null;
73
- }
74
- throw e;
75
- }
76
- try {
77
- response = await fetch(url, {
78
- headers: {
79
- Accept: "application/jrd+json",
80
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
81
- },
82
- redirect: "manual",
83
- signal: options.signal
84
- });
85
- } catch (error) {
86
- logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
87
- url: url.href,
88
- error
89
- });
90
- return null;
91
- }
92
- if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
93
- redirected++;
94
- const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
95
- if (redirected >= maxRedirection) {
96
- logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
97
- return null;
98
- }
99
- const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
100
- if (redirectedUrl.protocol !== url.protocol) {
101
- logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
102
- protocol: url.protocol,
103
- redirectedProtocol: redirectedUrl.protocol
104
- });
105
- return null;
106
- }
107
- url = redirectedUrl;
108
- continue;
109
- }
110
- if (!response.ok) {
111
- logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
112
- url: url.href,
113
- status: response.status,
114
- statusText: response.statusText
115
- });
116
- return null;
117
- }
118
- try {
119
- return await response.json();
120
- } catch (e) {
121
- if (e instanceof SyntaxError) {
122
- logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
123
- return null;
124
- }
125
- throw e;
126
- }
127
- }
128
- }
129
-
130
- //#endregion
131
- export { lookupWebFinger };
@@ -1,17 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import "./transformers-Dna8Fg7k.js";
6
- import "./docloader-DEhniCVa.js";
7
- import "./actor-CTAuCsWy.js";
8
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-CxEkcFW0.js";
9
- import "./lookup-dtdr2ftf.js";
10
- import "./key-DxA6xRtZ.js";
11
- import "./http-l0TEupZK.js";
12
- import "./proof-tgUlT8hw.js";
13
- import "./types-DgPvoUWN.js";
14
- import "./authdocloader-BFVqUbyo.js";
15
- import "./vocab-CvD6Vbml.js";
16
-
17
- export { FederationImpl };
@@ -1,26 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import "./type-SK-d7Tbw.js";
7
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-BRgu1IH8.js";
8
- import "./semver-dArNLkR9.js";
9
- import "./client-De-z2UnN.js";
10
- import "./lookup-Bn_HEC_d.js";
11
- import "./types-BIgY6c-l.js";
12
- import "./actor-Cc6B76eG.js";
13
- import "./key-CzLv1phF.js";
14
- import "./http-CcdM1brU.js";
15
- import "./authdocloader-CLgDGafZ.js";
16
- import "./ld-CBcQdZ6N.js";
17
- import "./owner-VEIjmR8r.js";
18
- import "./proof-DoSQAGkE.js";
19
- import "./inbox-B6DZbGNf.js";
20
- import "./builder-BOEBObR8.js";
21
- import "./collection-CSzG2j1P.js";
22
- import "./keycache-B8HdZJSt.js";
23
- import "./retry-D4GJ670a.js";
24
- import "./send-BzS7w-QF.js";
25
-
26
- export { FederationImpl };
@@ -1,104 +0,0 @@
1
- import { Temporal } from "@js-temporal/polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
3
- import { DocumentLoader, DocumentLoaderFactoryOptions } from "./docloader-CxWcuWqQ.js";
4
- import { HttpMessageSignaturesSpecDeterminer } from "./http-DqSNLFNY.js";
5
- import { TracerProvider } from "@opentelemetry/api";
6
-
7
- //#region src/runtime/authdocloader.d.ts
8
- /**
9
- * Options for {@link getAuthenticatedDocumentLoader}.
10
- * @see {@link getAuthenticatedDocumentLoader}
11
- * @since 1.3.0
12
- */
13
- interface GetAuthenticatedDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
14
- /**
15
- * An optional spec determiner for HTTP Message Signatures.
16
- * It determines the spec to use for signing requests.
17
- * It is used for double-knocking
18
- * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
19
- * @since 1.6.0
20
- */
21
- specDeterminer?: HttpMessageSignaturesSpecDeterminer;
22
- /**
23
- * The OpenTelemetry tracer provider. If omitted, the global tracer provider
24
- * is used.
25
- * @since 1.6.0
26
- */
27
- tracerProvider?: TracerProvider;
28
- }
29
- /**
30
- * Gets an authenticated {@link DocumentLoader} for the given identity.
31
- * Note that an authenticated document loader intentionally does not cache
32
- * the fetched documents.
33
- * @param identity The identity to get the document loader for.
34
- * The actor's key pair.
35
- * @param options The options for the document loader.
36
- * @returns The authenticated document loader.
37
- * @throws {TypeError} If the key is invalid or unsupported.
38
- * @since 0.4.0
39
- */
40
- declare function getAuthenticatedDocumentLoader(identity: {
41
- keyId: URL;
42
- privateKey: CryptoKey;
43
- }, {
44
- allowPrivateAddress,
45
- userAgent,
46
- specDeterminer,
47
- tracerProvider
48
- }?: GetAuthenticatedDocumentLoaderOptions): DocumentLoader;
49
- //#endregion
50
- //#region src/runtime/key.d.ts
51
- /**
52
- * Imports a PEM-SPKI formatted public key.
53
- * @param pem The PEM-SPKI formatted public key.
54
- * @returns The imported public key.
55
- * @throws {TypeError} If the key is invalid or unsupported.
56
- * @since 0.5.0
57
- */
58
- declare function importSpki(pem: string): Promise<CryptoKey>;
59
- /**
60
- * Exports a public key in PEM-SPKI format.
61
- * @param key The public key to export.
62
- * @returns The exported public key in PEM-SPKI format.
63
- * @throws {TypeError} If the key is invalid or unsupported.
64
- * @since 0.5.0
65
- */
66
- declare function exportSpki(key: CryptoKey): Promise<string>;
67
- /**
68
- * Imports a PEM-PKCS#1 formatted public key.
69
- * @param pem The PEM-PKCS#1 formatted public key.
70
- * @returns The imported public key.
71
- * @throws {TypeError} If the key is invalid or unsupported.
72
- * @since 1.5.0
73
- */
74
- declare function importPkcs1(pem: string): Promise<CryptoKey>;
75
- /**
76
- * Imports a PEM formatted public key (SPKI or PKCS#1).
77
- * @param pem The PEM formatted public key to import (SPKI or PKCS#1).
78
- * @returns The imported public key.
79
- * @throws {TypeError} If the key is invalid or unsupported.
80
- * @since 1.5.0
81
- */
82
- declare function importPem(pem: string): Promise<CryptoKey>;
83
- /**
84
- * Imports a [Multibase]-encoded public key.
85
- *
86
- * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
87
- * @param key The Multibase-encoded public key.
88
- * @returns The imported public key.
89
- * @throws {TypeError} If the key is invalid or unsupported.
90
- * @since 0.10.0
91
- */
92
- declare function importMultibaseKey(key: string): Promise<CryptoKey>;
93
- /**
94
- * Exports a public key in [Multibase] format.
95
- *
96
- * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
97
- * @param key The public key to export.
98
- * @returns The exported public key in Multibase format.
99
- * @throws {TypeError} If the key is invalid or unsupported.
100
- * @since 0.10.0
101
- */
102
- declare function exportMultibaseKey(key: CryptoKey): Promise<string>;
103
- //#endregion
104
- export { GetAuthenticatedDocumentLoaderOptions, exportMultibaseKey, exportSpki, getAuthenticatedDocumentLoader, importMultibaseKey, importPem, importPkcs1, importSpki };