From ed9ffe34f40763e5d8d1dcb6688a849d12fba74f Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 17 Feb 2025 13:07:43 +0100 Subject: [PATCH] feat(federation): :arrow_up: Upgrade to Versia 0.5 --- api/inbox/index.ts | 6 +++--- api/users/:uuid/inbox/index.ts | 6 +++--- api/well-known/versia.ts | 2 +- bun.lock | 4 ++-- classes/database/note.ts | 4 ++++ classes/inbox/processor.test.ts | 4 ++-- classes/inbox/processor.ts | 14 ++++++++------ classes/queues/inbox.ts | 6 +++--- classes/workers/inbox.ts | 14 +++++++------- package.json | 2 +- 10 files changed, 34 insertions(+), 28 deletions(-) diff --git a/api/inbox/index.ts b/api/inbox/index.ts index 5256a6bc..524d787f 100644 --- a/api/inbox/index.ts +++ b/api/inbox/index.ts @@ -5,9 +5,9 @@ import { InboxJobType, inboxQueue } from "~/classes/queues/inbox"; const schemas = { header: z.object({ - "x-signature": z.string().optional(), - "x-nonce": z.string().optional(), - "x-signed-by": z + "versia-signature": z.string().optional(), + "versia-signed-at": z.coerce.number().optional(), + "versia-signed-by": z .string() .url() .or(z.string().startsWith("instance ")) diff --git a/api/users/:uuid/inbox/index.ts b/api/users/:uuid/inbox/index.ts index 9303240d..2976c025 100644 --- a/api/users/:uuid/inbox/index.ts +++ b/api/users/:uuid/inbox/index.ts @@ -9,9 +9,9 @@ const schemas = { uuid: z.string().uuid(), }), header: z.object({ - "x-signature": z.string().optional(), - "x-nonce": z.string().optional(), - "x-signed-by": z + "versia-signature": z.string().optional(), + "versia-signed-at": z.coerce.number().optional(), + "versia-signed-by": z .string() .url() .or(z.string().startsWith("instance ")) diff --git a/api/well-known/versia.ts b/api/well-known/versia.ts index 502a7fd7..0c21ec9b 100644 --- a/api/well-known/versia.ts +++ b/api/well-known/versia.ts @@ -41,7 +41,7 @@ export default apiRoute((app) => "pub.versia:custom_emojis", "pub.versia:instance_messaging", ], - versions: ["0.4.0"], + versions: ["0.5.0"], }, host: config.http.base_url.host, name: config.instance.name, diff --git a/bun.lock b/bun.lock index f3364542..f1b75bc3 100644 --- a/bun.lock +++ b/bun.lock @@ -17,7 +17,7 @@ "@oclif/core": "^4.2.6", "@sentry/bun": "^9.1.0", "@versia/client": "^0.1.5", - "@versia/federation": "0.1.4", + "@versia/federation": "^0.2.0", "@versia/kit": "workspace:*", "altcha-lib": "^1.2.0", "blurhash": "^2.0.5", @@ -745,7 +745,7 @@ "@versia/client": ["@versia/client@0.1.5", "", { "dependencies": { "@badgateway/oauth2-client": "^2.4.2", "zod": "^3.24.1" } }, "sha512-POD2/IT98EZZ32kWEPc3XUY2zApX94tuBftNWIMyoT04Sp7CPuvv1TT2fxM2kmgrC6kgbh4I6yirPpzVY+FpSA=="], - "@versia/federation": ["@versia/federation@0.1.4", "", { "dependencies": { "magic-regexp": "^0.8.0", "mime-types": "^2.1.35", "zod": "^3.23.8", "zod-validation-error": "^3.4.0" } }, "sha512-89us9ltMNXNqohRxIxf7A4yYY2m3eiifsVWFGuKIrflX2Hv3VyqyZOrXh8i2bou+1qll9zAiCHYWCkAmv7RqkQ=="], + "@versia/federation": ["@versia/federation@0.2.0", "", { "dependencies": { "magic-regexp": "^0.8.0", "mime-types": "^2.1.35", "zod": "^3.24.1", "zod-validation-error": "^3.4.0" } }, "sha512-Eb2l26aE+9218DT/YKhYJy6DsdCbM3VL2zuVXFvolMprF5sNLi/px5BF0/KgI3TN6FTo7ufXVPNqePvBt90aiQ=="], "@versia/kit": ["@versia/kit@workspace:packages/plugin-kit"], diff --git a/classes/database/note.ts b/classes/database/note.ts index 06dbcb09..1c9aaf86 100644 --- a/classes/database/note.ts +++ b/classes/database/note.ts @@ -914,6 +914,10 @@ export class Note extends BaseInterface { remote: false, }, }, + collections: { + replies: `/notes/${status.id}/replies`, + quotes: `/notes/${status.id}/quotes`, + }, attachments: (status.attachments ?? []).map((attachment) => new Media(attachment).toVersia(), ), diff --git a/classes/inbox/processor.test.ts b/classes/inbox/processor.test.ts index 4838b3ae..f650b4db 100644 --- a/classes/inbox/processor.test.ts +++ b/classes/inbox/processor.test.ts @@ -86,7 +86,7 @@ describe("InboxProcessor", () => { let mockSenderInstance: Instance; let mockHeaders: { signature: string; - nonce: string; + signedAt: Date; authorization?: string; }; let processor: InboxProcessor; @@ -115,7 +115,7 @@ describe("InboxProcessor", () => { // Setup basic mock headers mockHeaders = { signature: "test-signature", - nonce: "test-nonce", + signedAt: new Date(), }; // Setup basic mock body diff --git a/classes/inbox/processor.ts b/classes/inbox/processor.ts index bab8412f..5c3e2414 100644 --- a/classes/inbox/processor.ts +++ b/classes/inbox/processor.ts @@ -63,7 +63,7 @@ export class InboxProcessor { * * @param request Request object. * @param body Entity JSON body. - * @param sender Sender of the request's instance and key (from X-Signed-By header). Null if request is from a bridge. + * @param sender Sender of the request's instance and key (from Versia-Signed-By header). Null if request is from a bridge. * @param headers Various request headers. * @param logger LogTape logger instance. * @param requestIp Request IP address. Grabs it from the Hono context if not provided. @@ -81,7 +81,7 @@ export class InboxProcessor { } | null, private headers: { signature?: string; - nonce?: string; + signedAt?: Date; authorization?: string; }, private logger: Logger = getLogger(["federation", "inbox"]), @@ -108,8 +108,8 @@ export class InboxProcessor { this.sender.key, ); - if (!(this.headers.signature && this.headers.nonce)) { - throw new Error("Missing signature or nonce"); + if (!(this.headers.signature && this.headers.signedAt)) { + throw new Error("Missing signature or signature timestamp"); } // HACK: Making a fake Request object instead of passing the values directly is necessary because otherwise the validation breaks for some unknown reason @@ -117,8 +117,10 @@ export class InboxProcessor { new Request(this.request.url, { method: this.request.method, headers: { - "X-Signature": this.headers.signature, - "X-Nonce": this.headers.nonce, + "Versia-Signature": this.headers.signature, + "Versia-Signed-At": ( + this.headers.signedAt.getTime() / 1000 + ).toString(), }, body: this.request.body, }), diff --git a/classes/queues/inbox.ts b/classes/queues/inbox.ts index b6010f76..543f2db8 100644 --- a/classes/queues/inbox.ts +++ b/classes/queues/inbox.ts @@ -10,9 +10,9 @@ export enum InboxJobType { export type InboxJobData = { data: Entity; headers: { - "x-signature"?: string; - "x-nonce"?: string; - "x-signed-by"?: string; + "versia-signature"?: string; + "versia-signed-at"?: number; + "versia-signed-by"?: string; authorization?: string; }; request: { diff --git a/classes/workers/inbox.ts b/classes/workers/inbox.ts index ea8c9936..6c086d9b 100644 --- a/classes/workers/inbox.ts +++ b/classes/workers/inbox.ts @@ -61,13 +61,13 @@ export const getInboxWorker = (): Worker => } const { - "x-signature": signature, - "x-nonce": nonce, - "x-signed-by": signedBy, + "versia-signature": signature, + "versia-signed-at": signedAt, + "versia-signed-by": signedBy, } = headers as { - "x-signature": string; - "x-nonce": string; - "x-signed-by": string; + "versia-signature": string; + "versia-signed-at": number; + "versia-signed-by": string; }; const sender = await User.resolve(new URL(signedBy)); @@ -122,7 +122,7 @@ export const getInboxWorker = (): Worker => }, { signature, - nonce, + signedAt: new Date(signedAt * 1000), authorization: undefined, }, getLogger(["federation", "inbox"]), diff --git a/package.json b/package.json index 4551c3fb..60288f28 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "@oclif/core": "^4.2.6", "@sentry/bun": "^9.1.0", "@versia/client": "^0.1.5", - "@versia/federation": "0.1.4", + "@versia/federation": "^0.2.0", "@versia/kit": "workspace:*", "altcha-lib": "^1.2.0", "blurhash": "^2.0.5",