@fedify/fedify 1.7.15 → 1.7.16

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 (129) hide show
  1. package/dist/actor-BzWaWDTY.js +146 -0
  2. package/dist/actor.js +34648 -5
  3. package/dist/{assert.js → assert-C-mZuSQl.js} +1 -1
  4. package/dist/{assert_instance_of.js → assert_instance_of-lS0Jr2iu.js} +1 -1
  5. package/dist/{assert_is_error.js → assert_is_error-CIYFACrT.js} +1 -1
  6. package/dist/{assert_not_equals.js → assert_not_equals-C1azCAB0.js} +1 -1
  7. package/dist/{assert_rejects.js → assert_rejects-Bkh5lA1a.js} +2 -2
  8. package/dist/{assert_throws.js → assert_throws-CmpfkWEM.js} +2 -2
  9. package/dist/authdocloader-1vrHbYJF.js +51 -0
  10. package/dist/authdocloader.js +2 -4
  11. package/dist/{builder.js → builder-8YjpOSrf.js} +5 -5
  12. package/dist/{client.js → client-CJ3nfMyp.js} +2 -2
  13. package/dist/compat/transformers.test.js +30 -30
  14. package/dist/{context.js → context-OXYKUfFL.js} +4 -4
  15. package/dist/docloader-I3SkMpZK.js +4421 -0
  16. package/dist/docloader.js +61 -4
  17. package/dist/{esm.js → esm-BRXvTSrx.js} +1 -1
  18. package/dist/federation/builder.test.js +17 -17
  19. package/dist/federation/collection.test.js +8 -8
  20. package/dist/federation/handler.test.js +36 -36
  21. package/dist/federation/inbox.test.js +11 -11
  22. package/dist/federation/keycache.test.js +12 -12
  23. package/dist/federation/kv.test.js +8 -8
  24. package/dist/federation/middleware.test.js +39 -39
  25. package/dist/federation/mq.test.js +10 -10
  26. package/dist/federation/retry.test.js +5 -5
  27. package/dist/federation/router.test.js +9 -9
  28. package/dist/federation/send.test.js +23 -23
  29. package/dist/http-CiQH4CF3.js +789 -0
  30. package/dist/http.js +4 -5
  31. package/dist/{inbox.js → inbox-BqBPO0vG.js} +3 -3
  32. package/dist/key-Ba-IjS2c.js +259 -0
  33. package/dist/key-CdNa4Um6.js +16 -0
  34. package/dist/key.js +1 -7
  35. package/dist/key2.js +2 -4
  36. package/dist/{keycache.js → keycache-BdgRTisV.js} +1 -1
  37. package/dist/{keys.js → keys-CLFIvF3E.js} +1 -1
  38. package/dist/{ld.js → ld-Dm1tdWDX.js} +4 -4
  39. package/dist/{lookup2.js → lookup-BumKjgCt.js} +4 -4
  40. package/dist/lookup-CoCshjhM.js +129 -0
  41. package/dist/lookup.js +1 -3
  42. package/dist/middleware-Dvd4BUlF.js +2661 -0
  43. package/dist/middleware-pC0Ld2I6.js +32 -0
  44. package/dist/middleware.js +1222 -364
  45. package/dist/middleware2.js +6 -21
  46. package/dist/nodeinfo/client.test.js +12 -12
  47. package/dist/nodeinfo/handler.test.js +34 -34
  48. package/dist/nodeinfo/semver.test.js +8 -8
  49. package/dist/nodeinfo/types.test.js +9 -9
  50. package/dist/{owner.js → owner-BO3ZhyYg.js} +3 -3
  51. package/dist/proof-Btlfk6hr.js +255 -0
  52. package/dist/proof.js +330 -8
  53. package/dist/runtime/authdocloader.test.js +20 -20
  54. package/dist/runtime/docloader.test.js +13 -13
  55. package/dist/runtime/key.test.js +15 -15
  56. package/dist/runtime/langstr.test.js +8 -8
  57. package/dist/runtime/multibase/multibase.test.js +8 -8
  58. package/dist/runtime/url.test.js +7 -7
  59. package/dist/{send.js → send-Dj-482tr.js} +2 -2
  60. package/dist/sig/http.test.js +20 -20
  61. package/dist/sig/key.test.js +17 -17
  62. package/dist/sig/ld.test.js +18 -18
  63. package/dist/sig/owner.test.js +20 -20
  64. package/dist/sig/proof.test.js +19 -19
  65. package/dist/{std__assert.js → std__assert-BdP_WkD-.js} +1 -1
  66. package/dist/testing/docloader.test.js +8 -8
  67. package/dist/testing/mod.js +2 -2
  68. package/dist/{testing.js → testing-qaAD4B0t.js} +1 -1
  69. package/dist/types-CB_2uuCA.js +51 -0
  70. package/dist/types.js +397 -3
  71. package/dist/vocab/actor.test.js +16 -16
  72. package/dist/vocab/lookup.test.js +17 -17
  73. package/dist/vocab/type.test.js +9 -9
  74. package/dist/vocab/vocab.test.js +17 -17
  75. package/dist/vocab-B8zleLsO.js +34386 -0
  76. package/dist/vocab.js +133 -34351
  77. package/dist/webfinger/handler.test.js +34 -34
  78. package/dist/webfinger/lookup.test.js +11 -11
  79. package/dist/x/cfworkers.test.js +7 -7
  80. package/package.json +1 -1
  81. /package/dist/{assert_equals.js → assert_equals-Dy0MG_Zw.js} +0 -0
  82. /package/dist/{chunk.js → chunk-DvTpRkcT.js} +0 -0
  83. /package/dist/{collection.js → collection-XNLQhehO.js} +0 -0
  84. /package/dist/compat/{transformers.test.d.ts → transformers.test-DnJbd34u.d.ts} +0 -0
  85. /package/dist/{denokv.js → denokv-NcJeZ6rP.js} +0 -0
  86. /package/dist/{docloader2.js → docloader-BDSHZfTJ.js} +0 -0
  87. /package/dist/federation/{builder.test.d.ts → builder.test-Bpt6NOZ6.d.ts} +0 -0
  88. /package/dist/federation/{collection.test.d.ts → collection.test-DKJ6JOZz.d.ts} +0 -0
  89. /package/dist/federation/{handler.test.d.ts → handler.test-BMT7uLC0.d.ts} +0 -0
  90. /package/dist/federation/{inbox.test.d.ts → inbox.test-Do6i02Qp.d.ts} +0 -0
  91. /package/dist/federation/{keycache.test.d.ts → keycache.test-BT83IPZY.d.ts} +0 -0
  92. /package/dist/federation/{kv.test.d.ts → kv.test-kFzzF2VN.d.ts} +0 -0
  93. /package/dist/federation/{middleware.test.d.ts → middleware.test-B1R4_e3-.d.ts} +0 -0
  94. /package/dist/federation/{mq.test.d.ts → mq.test-l79EQQOe.d.ts} +0 -0
  95. /package/dist/federation/{retry.test.d.ts → retry.test-BqS50VCX.d.ts} +0 -0
  96. /package/dist/federation/{router.test.d.ts → router.test-CYQl4po-.d.ts} +0 -0
  97. /package/dist/federation/{send.test.d.ts → send.test-COUnNUzv.d.ts} +0 -0
  98. /package/dist/{kv.js → kv-QeuZ51go.js} +0 -0
  99. /package/dist/{langstr.js → langstr-pFHBDU4y.js} +0 -0
  100. /package/dist/{multibase.js → multibase-DBcKTV2a.js} +0 -0
  101. /package/dist/nodeinfo/{client.test.d.ts → client.test-CZLe79hL.d.ts} +0 -0
  102. /package/dist/nodeinfo/{handler.test.d.ts → handler.test-B-EDZ_hK.d.ts} +0 -0
  103. /package/dist/nodeinfo/{semver.test.d.ts → semver.test-BEuuQSEM.d.ts} +0 -0
  104. /package/dist/nodeinfo/{types.test.d.ts → types.test-B5AT89WV.d.ts} +0 -0
  105. /package/dist/{retry.js → retry-BQet39_l.js} +0 -0
  106. /package/dist/{router.js → router-BuDkN4RQ.js} +0 -0
  107. /package/dist/runtime/{authdocloader.test.d.ts → authdocloader.test-hCRKzn9v.d.ts} +0 -0
  108. /package/dist/runtime/{docloader.test.d.ts → docloader.test-CVd7i_5h.d.ts} +0 -0
  109. /package/dist/runtime/{key.test.d.ts → key.test-DBsILYSD.d.ts} +0 -0
  110. /package/dist/runtime/{langstr.test.d.ts → langstr.test-CiKxuuRY.d.ts} +0 -0
  111. /package/dist/runtime/multibase/{multibase.test.d.ts → multibase.test-Brh6gPBP.d.ts} +0 -0
  112. /package/dist/runtime/{url.test.d.ts → url.test-DlRqkU2j.d.ts} +0 -0
  113. /package/dist/{semver.js → semver-D9d-VO-_.js} +0 -0
  114. /package/dist/sig/{http.test.d.ts → http.test-BpXNAWNI.d.ts} +0 -0
  115. /package/dist/sig/{key.test.d.ts → key.test-B2iLIugy.d.ts} +0 -0
  116. /package/dist/sig/{ld.test.d.ts → ld.test-D-cI70Gw.d.ts} +0 -0
  117. /package/dist/sig/{owner.test.d.ts → owner.test-B_YRjMPj.d.ts} +0 -0
  118. /package/dist/sig/{proof.test.d.ts → proof.test-BagEM_-4.d.ts} +0 -0
  119. /package/dist/testing/{docloader.test.d.ts → docloader.test-lrzf6sDZ.d.ts} +0 -0
  120. /package/dist/testing/{mod.d.ts → mod-3uM8ZvS7.d.ts} +0 -0
  121. /package/dist/{type.js → type-DFsmi-p1.js} +0 -0
  122. /package/dist/{url.js → url-BdNvnK9P.js} +0 -0
  123. /package/dist/vocab/{actor.test.d.ts → actor.test-ClC-iVWk.d.ts} +0 -0
  124. /package/dist/vocab/{lookup.test.d.ts → lookup.test-Cq1I-27w.d.ts} +0 -0
  125. /package/dist/vocab/{type.test.d.ts → type.test-bfFiYGcs.d.ts} +0 -0
  126. /package/dist/vocab/{vocab.test.d.ts → vocab.test-h-ZTisfu.d.ts} +0 -0
  127. /package/dist/webfinger/{handler.test.d.ts → handler.test-DiUeEDDD.d.ts} +0 -0
  128. /package/dist/webfinger/{lookup.test.d.ts → lookup.test-D9onm3U3.d.ts} +0 -0
  129. /package/dist/x/{cfworkers.test.d.ts → cfworkers.test-KXHlJ29z.d.ts} +0 -0
package/dist/http.js CHANGED
@@ -1,16 +1,15 @@
1
1
 
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
4
 
6
- import { d as version, u as name } from "./docloader.js";
7
- import { o as CryptographicKey } from "./vocab.js";
5
+ import { d as name, f as version } from "./docloader.js";
6
+ import { y as CryptographicKey } from "./actor.js";
8
7
  import { a as validateCryptoKey, n as fetchKey } from "./key2.js";
9
8
  import { getLogger } from "@logtape/logtape";
10
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
11
- import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
12
10
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
13
11
  import { encodeHex } from "byte-encodings/hex";
12
+ import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
14
13
  import { Item, decodeDict, encodeItem } from "structured-field-values";
15
14
 
16
15
  //#region sig/http.ts
@@ -786,4 +785,4 @@ function timingSafeEqual(a, b) {
786
785
  }
787
786
 
788
787
  //#endregion
789
- 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 };
788
+ export { signRequest as n, verifyRequest as r, doubleKnock as t };
@@ -3,9 +3,9 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { d as version, u as name } from "./docloader.js";
7
- import { t as Activity } from "./vocab.js";
8
- import { t as getTypeId } from "./type.js";
6
+ import { d as version, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { t as Activity } from "./vocab-B8zleLsO.js";
8
+ import { t as getTypeId } from "./type-DFsmi-p1.js";
9
9
  import { getLogger } from "@logtape/logtape";
10
10
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
11
11
 
@@ -0,0 +1,259 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { d as version, i as getDocumentLoader, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { _ as Object$1, o as CryptographicKey } from "./vocab-B8zleLsO.js";
8
+ import { i as isActor } from "./actor-BzWaWDTY.js";
9
+ import { getLogger } from "@logtape/logtape";
10
+ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
11
+
12
+ //#region sig/key.ts
13
+ /**
14
+ * Checks if the given key is valid and supported. No-op if the key is valid,
15
+ * otherwise throws an error.
16
+ * @param key The key to check.
17
+ * @param type Which type of key to check. If not specified, the key can be
18
+ * either public or private.
19
+ * @throws {TypeError} If the key is invalid or unsupported.
20
+ */
21
+ function validateCryptoKey(key, type) {
22
+ if (type != null && key.type !== type) throw new TypeError(`The key is not a ${type} key.`);
23
+ if (!key.extractable) throw new TypeError("The key is not extractable.");
24
+ 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!");
25
+ if (key.algorithm.name === "RSASSA-PKCS1-v1_5") {
26
+ if (key.algorithm.hash.name !== "SHA-256") throw new TypeError("For compatibility with the existing Fediverse software (e.g., Mastodon), hash algorithm for RSASSA-PKCS1-v1_5 keys must be SHA-256.");
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) 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
+ * @typeParam 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 tracer = (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, 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
+ document = (await (documentLoader ?? getDocumentLoader())(keyId)).document;
162
+ } catch (_) {
163
+ logger.debug("Failed to fetch key {keyId}.", { keyId });
164
+ await keyCache?.set(cacheKey, null);
165
+ return {
166
+ key: null,
167
+ cached: false
168
+ };
169
+ }
170
+ let object;
171
+ try {
172
+ object = await Object$1.fromJsonLd(document, {
173
+ documentLoader,
174
+ contextLoader,
175
+ tracerProvider
176
+ });
177
+ } catch (e) {
178
+ if (!(e instanceof TypeError)) throw e;
179
+ try {
180
+ object = await cls.fromJsonLd(document, {
181
+ documentLoader,
182
+ contextLoader,
183
+ tracerProvider
184
+ });
185
+ } catch (e$1) {
186
+ if (e$1 instanceof TypeError) {
187
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
188
+ await keyCache?.set(cacheKey, null);
189
+ return {
190
+ key: null,
191
+ cached: false
192
+ };
193
+ }
194
+ throw e$1;
195
+ }
196
+ }
197
+ let key = null;
198
+ if (object instanceof cls) key = object;
199
+ else if (isActor(object)) {
200
+ const keys = cls === CryptographicKey ? object.getPublicKeys({
201
+ documentLoader,
202
+ contextLoader,
203
+ tracerProvider
204
+ }) : object.getAssertionMethods({
205
+ documentLoader,
206
+ contextLoader,
207
+ tracerProvider
208
+ });
209
+ let length = 0;
210
+ let lastKey = null;
211
+ for await (const k of keys) {
212
+ length++;
213
+ lastKey = k;
214
+ if (k.id?.href === keyId) {
215
+ key = k;
216
+ break;
217
+ }
218
+ }
219
+ const keyIdUrl = new URL(keyId);
220
+ if (key == null && keyIdUrl.hash === "" && length === 1) key = lastKey;
221
+ if (key == null) {
222
+ logger.debug("Failed to verify; object {keyId} returned an {actorType}, but has no key matching {keyId}.", {
223
+ keyId,
224
+ actorType: object.constructor.name
225
+ });
226
+ await keyCache?.set(cacheKey, null);
227
+ return {
228
+ key: null,
229
+ cached: false
230
+ };
231
+ }
232
+ } else {
233
+ logger.debug("Failed to verify; key {keyId} returned an invalid object.", { keyId });
234
+ await keyCache?.set(cacheKey, null);
235
+ return {
236
+ key: null,
237
+ cached: false
238
+ };
239
+ }
240
+ if (key.publicKey == null) {
241
+ logger.debug("Failed to verify; key {keyId} has no publicKeyPem field.", { keyId });
242
+ await keyCache?.set(cacheKey, null);
243
+ return {
244
+ key: null,
245
+ cached: false
246
+ };
247
+ }
248
+ if (keyCache != null) {
249
+ await keyCache.set(cacheKey, key);
250
+ logger.debug("Key {keyId} cached.", { keyId });
251
+ }
252
+ return {
253
+ key,
254
+ cached: false
255
+ };
256
+ }
257
+
258
+ //#endregion
259
+ export { validateCryptoKey as a, importJwk as i, fetchKey as n, generateCryptoKeyPair as r, exportJwk as t };
@@ -0,0 +1,16 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import "./chunk-DvTpRkcT.js";
7
+ import "./docloader-I3SkMpZK.js";
8
+ import "./url-BdNvnK9P.js";
9
+ import "./multibase-DBcKTV2a.js";
10
+ import "./vocab-B8zleLsO.js";
11
+ import "./langstr-pFHBDU4y.js";
12
+ import "./lookup-CoCshjhM.js";
13
+ import "./actor-BzWaWDTY.js";
14
+ import { a as validateCryptoKey, i as importJwk, n as fetchKey, r as generateCryptoKeyPair, t as exportJwk } from "./key-Ba-IjS2c.js";
15
+
16
+ export { validateCryptoKey };
package/dist/key.js CHANGED
@@ -1,16 +1,10 @@
1
1
 
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
4
 
6
- import "./chunk.js";
7
5
  import "./docloader.js";
8
- import "./url.js";
9
- import "./multibase.js";
10
- import "./vocab.js";
11
- import "./langstr.js";
12
- import "./lookup.js";
13
6
  import "./actor.js";
7
+ import "./lookup.js";
14
8
  import { a as validateCryptoKey, i as importJwk, n as fetchKey, r as generateCryptoKeyPair, t as exportJwk } from "./key2.js";
15
9
 
16
10
  export { validateCryptoKey };
package/dist/key2.js CHANGED
@@ -1,11 +1,9 @@
1
1
 
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
4
 
6
- import { d as version, i as getDocumentLoader, u as name } from "./docloader.js";
7
- import { _ as Object$1, o as CryptographicKey } from "./vocab.js";
8
- import { i as isActor } from "./actor.js";
5
+ import { d as name, f as version, i as getDocumentLoader } from "./docloader.js";
6
+ import { i as isActor, q as Object$1, y as CryptographicKey } from "./actor.js";
9
7
  import { getLogger } from "@logtape/logtape";
10
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
11
9
 
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { h as Multikey, o as CryptographicKey } from "./vocab.js";
6
+ import { h as Multikey, o as CryptographicKey } from "./vocab-B8zleLsO.js";
7
7
 
8
8
  //#region federation/keycache.ts
9
9
  var KvKeyCache = class {
@@ -3,7 +3,7 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { P as importSpki, h as Multikey, o as CryptographicKey } from "./vocab.js";
6
+ import { P as importSpki, h as Multikey, o as CryptographicKey } from "./vocab-B8zleLsO.js";
7
7
 
8
8
  //#region testing/keys.ts
9
9
  const rsaPublicKey1 = new CryptographicKey({
@@ -3,10 +3,10 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { d as version, i as getDocumentLoader, u as name } from "./docloader.js";
7
- import { _ as Object$1, o as CryptographicKey, t as Activity } from "./vocab.js";
8
- import { t as getTypeId } from "./type.js";
9
- import { a as validateCryptoKey, n as fetchKey } from "./key2.js";
6
+ import { d as version, i as getDocumentLoader, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { _ as Object$1, o as CryptographicKey, t as Activity } from "./vocab-B8zleLsO.js";
8
+ import { t as getTypeId } from "./type-DFsmi-p1.js";
9
+ import { a as validateCryptoKey, n as fetchKey } from "./key-Ba-IjS2c.js";
10
10
  import { getLogger } from "@logtape/logtape";
11
11
  import { SpanStatusCode, trace } from "@opentelemetry/api";
12
12
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
@@ -3,10 +3,10 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { d as version, i as getDocumentLoader, u as name } from "./docloader.js";
7
- import { _ as Object$1 } from "./vocab.js";
8
- import { t as lookupWebFinger } from "./lookup.js";
9
- import { t as getTypeId } from "./type.js";
6
+ import { d as version, i as getDocumentLoader, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { _ as Object$1 } from "./vocab-B8zleLsO.js";
8
+ import { t as lookupWebFinger } from "./lookup-CoCshjhM.js";
9
+ import { t as getTypeId } from "./type-DFsmi-p1.js";
10
10
  import { getLogger } from "@logtape/logtape";
11
11
  import { SpanStatusCode, trace } from "@opentelemetry/api";
12
12
  import { delay } from "@es-toolkit/es-toolkit";
@@ -0,0 +1,129 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ globalThis.addEventListener = () => {};
5
+
6
+ import { d as version, o as getUserAgent, u as name } from "./docloader-I3SkMpZK.js";
7
+ import { a as validatePublicUrl, t as UrlError } from "./url-BdNvnK9P.js";
8
+ import { getLogger } from "@logtape/logtape";
9
+ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
+
11
+ //#region webfinger/lookup.ts
12
+ const logger = getLogger([
13
+ "fedify",
14
+ "webfinger",
15
+ "lookup"
16
+ ]);
17
+ const MAX_REDIRECTION = 5;
18
+ /**
19
+ * Looks up a WebFinger resource.
20
+ * @param resource The resource URL to look up.
21
+ * @param options Extra options for looking up the resource.
22
+ * @returns The resource descriptor, or `null` if not found.
23
+ * @since 0.2.0
24
+ */
25
+ async function lookupWebFinger(resource, options = {}) {
26
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).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
+ });
84
+ } catch (error) {
85
+ logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
86
+ url: url.href,
87
+ error
88
+ });
89
+ return null;
90
+ }
91
+ if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
92
+ redirected++;
93
+ if (redirected >= MAX_REDIRECTION) {
94
+ logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
95
+ return null;
96
+ }
97
+ const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
98
+ if (redirectedUrl.protocol !== url.protocol) {
99
+ logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
100
+ protocol: url.protocol,
101
+ redirectedProtocol: redirectedUrl.protocol
102
+ });
103
+ return null;
104
+ }
105
+ url = redirectedUrl;
106
+ continue;
107
+ }
108
+ if (!response.ok) {
109
+ logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
110
+ url: url.href,
111
+ status: response.status,
112
+ statusText: response.statusText
113
+ });
114
+ return null;
115
+ }
116
+ try {
117
+ return await response.json();
118
+ } catch (e) {
119
+ if (e instanceof SyntaxError) {
120
+ logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
121
+ return null;
122
+ }
123
+ throw e;
124
+ }
125
+ }
126
+ }
127
+
128
+ //#endregion
129
+ export { lookupWebFinger as t };
package/dist/lookup.js CHANGED
@@ -1,10 +1,8 @@
1
1
 
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
4
 
6
- import { d as version, o as getUserAgent, u as name } from "./docloader.js";
7
- import { a as validatePublicUrl, t as UrlError } from "./url.js";
5
+ import { d as name, f as version, l as UrlError, o as getUserAgent, u as validatePublicUrl } from "./docloader.js";
8
6
  import { getLogger } from "@logtape/logtape";
9
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
8