@fedify/fedify 1.9.0-pr.407.1544 → 1.9.0-pr.421.1747
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.
- package/dist/{actor-Ch5yFYFG.d.ts → actor-C1Euqngb.d.ts} +1 -1
- package/dist/{actor-CeBu8hLy.js → actor-CNV1ck1S.js} +1 -1
- package/dist/actor-DaFSkBV-.cjs +42606 -0
- package/dist/{actor-BY--uubW.js → actor-J-9oLs-V.js} +6951 -2127
- package/dist/actor-Ydzhc8dj.d.cts +128 -0
- package/dist/{authdocloader-C89pKQKE.js → authdocloader-D4qQkXT9.js} +6 -6
- package/dist/{authdocloader-jHzDqZo2.js → authdocloader-DKEFUico.js} +3 -3
- package/dist/authdocloader-DM1vtjbY.cjs +58 -0
- package/dist/{builder-ClMKBUks.js → builder-2yBgTZpU.js} +14 -8
- package/dist/chunk-DqRYRqnO.cjs +34 -0
- package/dist/client-DjT_tegg.d.cts +294 -0
- package/dist/{client-DB3mC1oJ.js → client-nAHORZym.js} +1 -1
- package/dist/compat/mod.cjs +10 -0
- package/dist/compat/mod.d.cts +13 -0
- package/dist/compat/mod.d.ts +7 -7
- package/dist/compat/mod.js +5 -5
- package/dist/compat/transformers.test.js +16 -16
- package/dist/compat-DmDDELst.cjs +4 -0
- package/dist/compat-nxUqe4Z-.js +4 -0
- package/dist/{context-DFruNLny.d.ts → context-CXUibY4L.d.ts} +179 -116
- package/dist/context-CwUAkopp.d.cts +2324 -0
- package/dist/{docloader-BJTPo7_i.js → docloader-BRrqMbX0.js} +188 -8
- package/dist/docloader-D-MrRyHl.d.cts +219 -0
- package/dist/docloader-FAn755Ez.cjs +4862 -0
- package/dist/{esm-BjUpSZdQ.js → esm-CZDlG8Yt.js} +1 -1
- package/dist/federation/builder.test.js +5 -5
- package/dist/federation/collection.test.js +3 -3
- package/dist/federation/handler.test.js +17 -17
- package/dist/federation/idempotency.test.d.ts +3 -0
- package/dist/federation/idempotency.test.js +202 -0
- package/dist/federation/inbox.test.js +4 -4
- package/dist/federation/keycache.test.js +4 -4
- package/dist/federation/kv.test.js +4 -3
- package/dist/federation/middleware.test.js +18 -18
- package/dist/federation/mod.cjs +29 -0
- package/dist/federation/mod.d.cts +13 -0
- package/dist/federation/mod.d.ts +7 -7
- package/dist/federation/mod.js +15 -15
- package/dist/federation/mq.test.js +3 -3
- package/dist/federation/retry.test.js +3 -3
- package/dist/federation/router.test.js +3 -3
- package/dist/federation/send.test.js +10 -10
- package/dist/{federation-CMX7WzeL.js → federation-D1U8YY9t.js} +3 -3
- package/dist/federation-H2_En3j5.cjs +244 -0
- package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
- package/dist/{http-sU0Wj-tv.js → http-B0Rp4UOp.js} +7 -7
- package/dist/http-B1_DzfAU.d.cts +253 -0
- package/dist/{http-3pAI0mqb.js → http-CyMjXkYA.js} +3 -3
- package/dist/http-D7xo4v5M.cjs +826 -0
- package/dist/{http-D8Q4xH0d.d.ts → http-wsGR6KkT.d.ts} +1 -1
- package/dist/{inbox-Dg825gXU.js → inbox-CAt-VuhL.js} +29 -7
- package/dist/key-BZBF55sg.cjs +10 -0
- package/dist/key-CKScBmP1.js +10 -0
- package/dist/{key-l5QMtRss.js → key-D7A24D7c.js} +5 -5
- package/dist/key-DFZ_CvG0.cjs +290 -0
- package/dist/{key-RzI0hV7H.js → key-DbX-_KvI.js} +2 -2
- package/dist/{key-BWgRsIwz.js → key-uBD0-2wc.js} +3 -3
- package/dist/{keycache-BGlP5YTm.js → keycache-DVVM5m9f.js} +1 -1
- package/dist/{keys-BRbwmdDJ.js → keys-Hl2h0ZG0.js} +1 -1
- package/dist/kv-63Cil1MD.d.cts +81 -0
- package/dist/{ld-C9E9DPBz.js → ld-e-G3iYdn.js} +4 -4
- package/dist/{lookup-oZxe6kZr.js → lookup-DNGo5BR6.js} +21 -12
- package/dist/lookup-DSSOyhz2.cjs +137 -0
- package/dist/{lookup-CN62_yPh.js → lookup-Zzj9McvA.js} +4 -4
- package/dist/{middleware-extU7qDB.js → middleware-4mR2kSKQ.js} +96 -65
- package/dist/middleware-B-YooLeX.cjs +17 -0
- package/dist/middleware-BG51vY-0.js +17 -0
- package/dist/{middleware-jQ1GPh2U.js → middleware-BWW4nCk1.js} +57 -54
- package/dist/middleware-CVb0KXM7.cjs +4271 -0
- package/dist/middleware-DXunR6sJ.js +26 -0
- package/dist/mod-BUbqxBev.d.cts +307 -0
- package/dist/{mod-CiXjux2r.d.ts → mod-BcObK1Lz.d.ts} +2 -2
- package/dist/mod-C2tOeRkN.d.cts +1 -0
- package/dist/{mod-Cy6pkZSn.d.ts → mod-CDObsV1d.d.ts} +19 -1
- package/dist/{mod-BAuhKa9d.d.ts → mod-CIbqfZW0.d.ts} +1 -1
- package/dist/{mod-B7Pc0I7F.d.ts → mod-DgcYoyZK.d.ts} +2 -2
- package/dist/mod-Dt-G9ZOS.d.cts +102 -0
- package/dist/mod-FZd39qVq.d.cts +1 -0
- package/dist/mod-fjqfsrty.d.cts +266 -0
- package/dist/mod-jQ4OODsl.d.cts +113 -0
- package/dist/mod-mXx9V0q5.d.cts +80 -0
- package/dist/mod.cjs +152 -0
- package/dist/mod.d.cts +17 -0
- package/dist/mod.d.ts +10 -10
- package/dist/mod.js +20 -20
- package/dist/mq-B7R1Q-M5.d.cts +140 -0
- package/dist/nodeinfo/client.test.js +5 -5
- package/dist/nodeinfo/handler.test.js +16 -16
- package/dist/nodeinfo/mod.cjs +13 -0
- package/dist/nodeinfo/mod.d.cts +5 -0
- package/dist/nodeinfo/mod.js +6 -6
- package/dist/nodeinfo/semver.test.js +3 -3
- package/dist/nodeinfo/types.test.js +3 -3
- package/dist/nodeinfo-Co9lJrWl.cjs +4 -0
- package/dist/nodeinfo-DfycQ8Wf.js +4 -0
- package/dist/owner-6KSEp9eV.d.cts +67 -0
- package/dist/{owner-D38zBIMc.d.ts → owner-BbeUDvOu.d.ts} +2 -2
- package/dist/{owner-B836JKuZ.js → owner-C4sPn9c4.js} +2 -2
- package/dist/{proof-D63mA1Rv.js → proof-C3QoDkRC.js} +3 -3
- package/dist/proof-DT8hWqV6.cjs +673 -0
- package/dist/{proof-DLwnfKak.js → proof-iy7cOAt6.js} +9 -9
- package/dist/runtime/authdocloader.test.js +9 -9
- package/dist/runtime/docloader.test.js +4 -4
- package/dist/runtime/key.test.js +5 -5
- package/dist/runtime/langstr.test.js +3 -3
- package/dist/runtime/link.test.d.ts +3 -0
- package/dist/runtime/link.test.js +61 -0
- package/dist/runtime/mod.cjs +25 -0
- package/dist/runtime/mod.d.cts +6 -0
- package/dist/runtime/mod.d.ts +3 -3
- package/dist/runtime/mod.js +10 -10
- package/dist/runtime/multibase/multibase.test.js +3 -3
- package/dist/runtime/url.test.js +3 -3
- package/dist/runtime-C58AJWSv.cjs +4 -0
- package/dist/runtime-DPYEDf-o.js +4 -0
- package/dist/{send-CE9GFSCd.js → send-BOn6IbzV.js} +2 -2
- package/dist/sig/http.test.js +9 -9
- package/dist/sig/key.test.js +6 -6
- package/dist/sig/ld.test.js +7 -7
- package/dist/sig/mod.cjs +30 -0
- package/dist/sig/mod.d.cts +8 -0
- package/dist/sig/mod.d.ts +5 -5
- package/dist/sig/mod.js +10 -10
- package/dist/sig/owner.test.js +7 -7
- package/dist/sig/proof.test.js +7 -7
- package/dist/sig-ByHXzqUi.cjs +4 -0
- package/dist/sig-Cj3tk-ig.js +4 -0
- package/dist/testing/docloader.test.js +3 -3
- package/dist/testing/mod.d.ts +385 -110
- package/dist/testing/mod.js +3 -3
- package/dist/{testing-B2tgn0a4.js → testing-DaKcIaFF.js} +2 -2
- package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
- package/dist/transformers-CoBS-oFG.cjs +116 -0
- package/dist/{type-OboVsUha.js → type-D50ufokc.js} +7261 -2257
- package/dist/{types-BLr6AjjI.js → types-BCmRSiaD.js} +4 -4
- package/dist/types-wG2EuWYS.cjs +488 -0
- package/dist/vocab/actor.test.js +5 -5
- package/dist/vocab/lookup.test.js +255 -5
- package/dist/vocab/mod.cjs +87 -0
- package/dist/vocab/mod.d.cts +6 -0
- package/dist/vocab/mod.d.ts +3 -3
- package/dist/vocab/mod.js +7 -7
- package/dist/vocab/type.test.js +3 -3
- package/dist/vocab/vocab.test.js +433 -9
- package/dist/vocab-B_AjsPE2.cjs +291 -0
- package/dist/{vocab-BEEm2I6u.d.ts → vocab-CDHNj5zp.d.ts} +290 -0
- package/dist/vocab-Cfs0937i.d.cts +14919 -0
- package/dist/{vocab-Z7alheNv.js → vocab-CtBL6Aur.js} +26 -17
- package/dist/webfinger/handler.test.js +16 -16
- package/dist/webfinger/lookup.test.js +4 -4
- package/dist/webfinger/mod.cjs +9 -0
- package/dist/webfinger/mod.d.cts +4 -0
- package/dist/webfinger/mod.js +6 -6
- package/dist/webfinger-BjOEdFPs.cjs +4 -0
- package/dist/webfinger-De_bU0iE.js +4 -0
- package/dist/x/cfworkers.cjs +100 -0
- package/dist/x/cfworkers.d.cts +59 -0
- package/dist/x/cfworkers.js +3 -3
- package/dist/x/cfworkers.test.js +3 -3
- package/dist/x/hono.cjs +61 -0
- package/dist/x/hono.d.cts +54 -0
- package/dist/x/hono.d.ts +6 -6
- package/dist/x/hono.js +3 -3
- package/dist/x/sveltekit.cjs +69 -0
- package/dist/x/sveltekit.d.cts +46 -0
- package/dist/x/sveltekit.d.ts +6 -6
- package/dist/x/sveltekit.js +3 -3
- package/package.json +68 -13
- package/dist/compat-Bb5myD13.js +0 -4
- package/dist/key-_XZAOE9D.js +0 -10
- package/dist/middleware-Ccahu3ql.js +0 -26
- package/dist/middleware-fO804EqJ.js +0 -17
- package/dist/nodeinfo-CyEbLjHs.js +0 -4
- package/dist/runtime-BSkOVUWM.js +0 -4
- package/dist/sig-BXJO--F9.js +0 -4
- package/dist/webfinger-C3GIyXIg.js +0 -4
@@ -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-
|
4
|
+
import { CryptographicKey, Multikey } from "./vocab-CDHNj5zp.js";
|
5
5
|
import { TracerProvider } from "@opentelemetry/api";
|
6
6
|
|
7
7
|
//#region src/sig/key.d.ts
|
@@ -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-
|
6
|
+
import { Activity, deno_default, getTypeId } from "./type-D50ufokc.js";
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
8
8
|
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
9
9
|
|
@@ -41,17 +41,39 @@ var InboxListenerSet = class InboxListenerSet {
|
|
41
41
|
return this.dispatchWithClass(activity)?.listener ?? null;
|
42
42
|
}
|
43
43
|
};
|
44
|
-
|
44
|
+
let warnedAboutDefaultIdempotency = false;
|
45
|
+
async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
|
45
46
|
const logger = getLogger([
|
46
47
|
"fedify",
|
47
48
|
"federation",
|
48
49
|
"inbox"
|
49
50
|
]);
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
let cacheKey = null;
|
52
|
+
if (activity.id != null) {
|
53
|
+
const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href);
|
54
|
+
const strategy = idempotencyStrategy ?? "per-origin";
|
55
|
+
if (idempotencyStrategy === void 0 && !warnedAboutDefaultIdempotency) {
|
56
|
+
logger.warn("Using default idempotency strategy 'per-origin'. This default will change to 'per-inbox' in Fedify 2.0. Please explicitly set the idempotency strategy using .withIdempotency().");
|
57
|
+
warnedAboutDefaultIdempotency = true;
|
58
|
+
}
|
59
|
+
let keyString;
|
60
|
+
if (typeof strategy === "function") {
|
61
|
+
const result = await strategy(inboxContext, activity);
|
62
|
+
keyString = result;
|
63
|
+
} else switch (strategy) {
|
64
|
+
case "global":
|
65
|
+
keyString = activity.id.href;
|
66
|
+
break;
|
67
|
+
case "per-origin":
|
68
|
+
keyString = `${ctx.origin}\n${activity.id.href}`;
|
69
|
+
break;
|
70
|
+
case "per-inbox":
|
71
|
+
keyString = `${ctx.origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
|
72
|
+
break;
|
73
|
+
default: keyString = `${ctx.origin}\n${activity.id.href}`;
|
74
|
+
}
|
75
|
+
if (keyString != null) cacheKey = [...kvPrefixes.activityIdempotence, keyString];
|
76
|
+
}
|
55
77
|
if (cacheKey != null) {
|
56
78
|
const cached = await kv.get(cacheKey);
|
57
79
|
if (cached === true) {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
3
|
+
const { URLPattern } = require("urlpattern-polyfill");
|
4
|
+
|
5
|
+
require('./docloader-FAn755Ez.cjs');
|
6
|
+
require('./actor-DaFSkBV-.cjs');
|
7
|
+
require('./lookup-DSSOyhz2.cjs');
|
8
|
+
const require_key = require('./key-DFZ_CvG0.cjs');
|
9
|
+
|
10
|
+
exports.validateCryptoKey = require_key.validateCryptoKey;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
3
|
+
import { URLPattern } from "urlpattern-polyfill";
|
4
|
+
|
5
|
+
import "./docloader-BRrqMbX0.js";
|
6
|
+
import "./actor-J-9oLs-V.js";
|
7
|
+
import "./lookup-Zzj9McvA.js";
|
8
|
+
import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-D7A24D7c.js";
|
9
|
+
|
10
|
+
export { validateCryptoKey };
|
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
import { deno_default, getDocumentLoader } from "./docloader-
|
6
|
-
import { CryptographicKey, Object as Object$1, isActor } from "./actor-
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
3
|
+
import { URLPattern } from "urlpattern-polyfill";
|
4
|
+
|
5
|
+
import { deno_default, getDocumentLoader } from "./docloader-BRrqMbX0.js";
|
6
|
+
import { CryptographicKey, Object as Object$1, isActor } from "./actor-J-9oLs-V.js";
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
9
9
|
|
@@ -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-FAn755Ez.cjs');
|
7
|
+
const require_actor = require('./actor-DaFSkBV-.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
|
+
});
|
@@ -3,8 +3,8 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
globalThis.addEventListener = () => {};
|
5
5
|
|
6
|
-
import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-
|
7
|
-
import { isActor } from "./actor-
|
6
|
+
import { CryptographicKey, Object as Object$1, deno_default, getDocumentLoader } from "./type-D50ufokc.js";
|
7
|
+
import { isActor } from "./actor-CNV1ck1S.js";
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
9
9
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
10
10
|
|
@@ -3,8 +3,8 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
globalThis.addEventListener = () => {};
|
5
5
|
|
6
|
-
import "./type-
|
7
|
-
import "./actor-
|
8
|
-
import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-
|
6
|
+
import "./type-D50ufokc.js";
|
7
|
+
import "./actor-CNV1ck1S.js";
|
8
|
+
import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-DbX-_KvI.js";
|
9
9
|
|
10
10
|
export { validateCryptoKey };
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
globalThis.addEventListener = () => {};
|
5
5
|
|
6
|
-
import { CryptographicKey, Multikey } from "./type-
|
6
|
+
import { CryptographicKey, Multikey } from "./type-D50ufokc.js";
|
7
7
|
|
8
8
|
//#region src/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 { CryptographicKey, Multikey, importSpki } from "./type-
|
6
|
+
import { CryptographicKey, Multikey, importSpki } from "./type-D50ufokc.js";
|
7
7
|
|
8
8
|
//#region src/testing/keys.ts
|
9
9
|
const rsaPublicKey1 = new CryptographicKey({
|
@@ -0,0 +1,81 @@
|
|
1
|
+
//#region src/federation/kv.d.ts
|
2
|
+
/**
|
3
|
+
* A key for a key–value store. An array of one or more strings.
|
4
|
+
*
|
5
|
+
* @since 0.5.0
|
6
|
+
*/
|
7
|
+
type KvKey = readonly [string] | readonly [string, ...string[]];
|
8
|
+
/**
|
9
|
+
* Additional options for setting a value in a key–value store.
|
10
|
+
*
|
11
|
+
* @since 0.5.0
|
12
|
+
*/
|
13
|
+
interface KvStoreSetOptions {
|
14
|
+
/**
|
15
|
+
* The time-to-live (TTL) for the value.
|
16
|
+
*/
|
17
|
+
ttl?: Temporal.Duration;
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* An abstract interface for a key–value store.
|
21
|
+
*
|
22
|
+
* @since 0.5.0
|
23
|
+
*/
|
24
|
+
interface KvStore {
|
25
|
+
/**
|
26
|
+
* Gets the value for the given key.
|
27
|
+
* @param key The key to get the value for.
|
28
|
+
* @returns The value for the key, or `undefined` if the key does not exist.
|
29
|
+
* @template T The type of the value to get.
|
30
|
+
*/
|
31
|
+
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
32
|
+
/**
|
33
|
+
* Sets the value for the given key.
|
34
|
+
* @param key The key to set the value for.
|
35
|
+
* @param value The value to set.
|
36
|
+
* @param options Additional options for setting the value.
|
37
|
+
*/
|
38
|
+
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
39
|
+
/**
|
40
|
+
* Deletes the value for the given key.
|
41
|
+
* @param key The key to delete.
|
42
|
+
*/
|
43
|
+
delete(key: KvKey): Promise<void>;
|
44
|
+
/**
|
45
|
+
* Compare-and-swap (CAS) operation for the key–value store.
|
46
|
+
* @param key The key to perform the CAS operation on.
|
47
|
+
* @param expectedValue The expected value for the key.
|
48
|
+
* @param newValue The new value to set if the expected value matches.
|
49
|
+
* @param options Additional options for setting the value.
|
50
|
+
* @return `true` if the CAS operation was successful, `false` otherwise.
|
51
|
+
* @since 1.8.0
|
52
|
+
*/
|
53
|
+
cas?: (key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions) => Promise<boolean>;
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* A key–value store that stores values in memory.
|
57
|
+
* Do not use this in production as it does not persist values.
|
58
|
+
*
|
59
|
+
* @since 0.5.0
|
60
|
+
*/
|
61
|
+
declare class MemoryKvStore implements KvStore {
|
62
|
+
#private;
|
63
|
+
/**
|
64
|
+
* {@inheritDoc KvStore.get}
|
65
|
+
*/
|
66
|
+
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
67
|
+
/**
|
68
|
+
* {@inheritDoc KvStore.set}
|
69
|
+
*/
|
70
|
+
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
71
|
+
/**
|
72
|
+
* {@inheritDoc KvStore.delete}
|
73
|
+
*/
|
74
|
+
delete(key: KvKey): Promise<void>;
|
75
|
+
/**
|
76
|
+
* {@inheritDoc KvStore.cas}
|
77
|
+
*/
|
78
|
+
cas(key: KvKey, expectedValue: unknown, newValue: unknown, options?: KvStoreSetOptions): Promise<boolean>;
|
79
|
+
}
|
80
|
+
//#endregion
|
81
|
+
export { KvKey, KvStore, KvStoreSetOptions, MemoryKvStore };
|
@@ -3,8 +3,8 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
globalThis.addEventListener = () => {};
|
5
5
|
|
6
|
-
import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-
|
7
|
-
import { fetchKey, validateCryptoKey } from "./key-
|
6
|
+
import { Activity, CryptographicKey, Object as Object$1, deno_default, getDocumentLoader, getTypeId } from "./type-D50ufokc.js";
|
7
|
+
import { fetchKey, validateCryptoKey } from "./key-DbX-_KvI.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";
|
@@ -182,7 +182,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
182
182
|
const encoder = new TextEncoder();
|
183
183
|
const message = sigOptsHash + docHash;
|
184
184
|
const messageBytes = encoder.encode(message);
|
185
|
-
const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature, messageBytes);
|
185
|
+
const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes);
|
186
186
|
if (verified) return key;
|
187
187
|
if (cached) {
|
188
188
|
logger.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
|
@@ -197,7 +197,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
197
197
|
}
|
198
198
|
});
|
199
199
|
if (key$1 == null) return null;
|
200
|
-
const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature, messageBytes);
|
200
|
+
const verified$1 = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key$1.publicKey, signature.slice(), messageBytes);
|
201
201
|
return verified$1 ? key$1 : null;
|
202
202
|
}
|
203
203
|
logger.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
globalThis.addEventListener = () => {};
|
5
5
|
|
6
|
-
import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-
|
6
|
+
import { Object as Object$1, deno_default, getDocumentLoader, getTypeId, lookupWebFinger } from "./type-D50ufokc.js";
|
7
7
|
import { cloneDeep, delay } from "es-toolkit";
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
9
9
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
@@ -240,14 +240,13 @@ async function lookupObject(identifier, options = {}) {
|
|
240
240
|
async function lookupObjectInternal(identifier, options = {}) {
|
241
241
|
const documentLoader = options.documentLoader ?? getDocumentLoader({ userAgent: options.userAgent });
|
242
242
|
if (typeof identifier === "string") identifier = toAcctUrl(identifier) ?? new URL(identifier);
|
243
|
-
let
|
243
|
+
let remoteDoc = null;
|
244
244
|
if (identifier.protocol === "http:" || identifier.protocol === "https:") try {
|
245
|
-
|
246
|
-
document = remoteDoc.document;
|
245
|
+
remoteDoc = await documentLoader(identifier.href, { signal: options.signal });
|
247
246
|
} catch (error) {
|
248
247
|
logger.debug("Failed to fetch remote document:\n{error}", { error });
|
249
248
|
}
|
250
|
-
if (
|
249
|
+
if (remoteDoc == null) {
|
251
250
|
const jrd = await lookupWebFinger(identifier, {
|
252
251
|
userAgent: options.userAgent,
|
253
252
|
tracerProvider: options.tracerProvider,
|
@@ -258,8 +257,7 @@ async function lookupObjectInternal(identifier, options = {}) {
|
|
258
257
|
for (const l of jrd.links) {
|
259
258
|
if (l.type !== "application/activity+json" && !l.type?.match(/application\/ld\+json;\s*profile="https:\/\/www.w3.org\/ns\/activitystreams"/) || l.rel !== "self" || l.href == null) continue;
|
260
259
|
try {
|
261
|
-
|
262
|
-
document = remoteDoc.document;
|
260
|
+
remoteDoc = await documentLoader(l.href, { signal: options.signal });
|
263
261
|
break;
|
264
262
|
} catch (error) {
|
265
263
|
logger.debug("Failed to fetch remote document:\n{error}", { error });
|
@@ -267,23 +265,34 @@ async function lookupObjectInternal(identifier, options = {}) {
|
|
267
265
|
}
|
268
266
|
}
|
269
267
|
}
|
270
|
-
if (
|
268
|
+
if (remoteDoc == null) return null;
|
269
|
+
let object;
|
271
270
|
try {
|
272
|
-
|
271
|
+
object = await Object$1.fromJsonLd(remoteDoc.document, {
|
273
272
|
documentLoader,
|
274
273
|
contextLoader: options.contextLoader,
|
275
|
-
tracerProvider: options.tracerProvider
|
274
|
+
tracerProvider: options.tracerProvider,
|
275
|
+
baseUrl: new URL(remoteDoc.documentUrl)
|
276
276
|
});
|
277
277
|
} catch (error) {
|
278
278
|
if (error instanceof TypeError) {
|
279
279
|
logger.debug("Failed to parse JSON-LD document: {error}\n{document}", {
|
280
|
-
|
281
|
-
|
280
|
+
...remoteDoc,
|
281
|
+
error
|
282
282
|
});
|
283
283
|
return null;
|
284
284
|
}
|
285
285
|
throw error;
|
286
286
|
}
|
287
|
+
if (options.crossOrigin !== "trust" && object.id != null && object.id.origin !== new URL(remoteDoc.documentUrl).origin) {
|
288
|
+
if (options.crossOrigin === "throw") throw new Error(`The object's @id (${object.id.href}) has a different origin than the document URL (${remoteDoc.documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to "trust".`);
|
289
|
+
logger.warn("The object's @id ({objectId}) has a different origin than the document URL ({documentUrl}); refusing to return the object. If you want to bypass this check and are aware of the security implications, set the crossOrigin option to \"trust\".", {
|
290
|
+
...remoteDoc,
|
291
|
+
objectId: object.id.href
|
292
|
+
});
|
293
|
+
return null;
|
294
|
+
}
|
295
|
+
return object;
|
287
296
|
}
|
288
297
|
/**
|
289
298
|
* Traverses a collection, yielding each item in the collection.
|