mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(federation): ✨ Log signatures generated when serving entites via HTTP
This commit is contained in:
parent
1216e278e8
commit
aca837cb16
|
|
@ -2,6 +2,7 @@ import { applyConfig, handleZodError } from "@/api";
|
||||||
import { errorResponse, response } from "@/response";
|
import { errorResponse, response } from "@/response";
|
||||||
import type { Hono } from "@hono/hono";
|
import type { Hono } from "@hono/hono";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { SignatureConstructor } from "@lysand-org/federation";
|
import { SignatureConstructor } from "@lysand-org/federation";
|
||||||
import type { Entity } from "@lysand-org/federation/types";
|
import type { Entity } from "@lysand-org/federation/types";
|
||||||
import { and, eq, inArray, sql } from "drizzle-orm";
|
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||||
|
|
@ -99,13 +100,23 @@ export default (app: Hono) =>
|
||||||
|
|
||||||
const author = foundAuthor ?? User.getServerActor();
|
const author = foundAuthor ?? User.getServerActor();
|
||||||
|
|
||||||
const { headers } = await (
|
const { headers, signedString } = await (
|
||||||
await SignatureConstructor.fromStringKey(
|
await SignatureConstructor.fromStringKey(
|
||||||
author.data.privateKey ?? "",
|
author.data.privateKey ?? "",
|
||||||
author.getUri(),
|
author.getUri(),
|
||||||
)
|
)
|
||||||
).sign("POST", reqUrl, objectString);
|
).sign("POST", reqUrl, objectString);
|
||||||
|
|
||||||
|
if (config.debug.federation) {
|
||||||
|
const logger = getLogger("federation");
|
||||||
|
|
||||||
|
// Log public key
|
||||||
|
logger.debug`Sender public key: ${author.data.publicKey}`;
|
||||||
|
|
||||||
|
// Log signed string
|
||||||
|
logger.debug`Signed string:\n${signedString}`;
|
||||||
|
}
|
||||||
|
|
||||||
return response(objectString, 200, {
|
return response(objectString, 200, {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...headers.toJSON(),
|
...headers.toJSON(),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { applyConfig, handleZodError } from "@/api";
|
||||||
import { errorResponse, redirect, response } from "@/response";
|
import { errorResponse, redirect, response } from "@/response";
|
||||||
import type { Hono } from "@hono/hono";
|
import type { Hono } from "@hono/hono";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { SignatureConstructor } from "@lysand-org/federation";
|
import { SignatureConstructor } from "@lysand-org/federation";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { config } from "~/packages/config-manager";
|
import { config } from "~/packages/config-manager";
|
||||||
|
|
@ -83,13 +84,23 @@ export default (app: Hono) =>
|
||||||
reqUrl.protocol = "https:";
|
reqUrl.protocol = "https:";
|
||||||
}
|
}
|
||||||
|
|
||||||
const { headers } = await (
|
const { headers, signedString } = await (
|
||||||
await SignatureConstructor.fromStringKey(
|
await SignatureConstructor.fromStringKey(
|
||||||
user.data.privateKey ?? "",
|
user.data.privateKey ?? "",
|
||||||
user.getUri(),
|
user.getUri(),
|
||||||
)
|
)
|
||||||
).sign("POST", reqUrl, userString);
|
).sign("POST", reqUrl, userString);
|
||||||
|
|
||||||
|
if (config.debug.federation) {
|
||||||
|
const logger = getLogger("federation");
|
||||||
|
|
||||||
|
// Log public key
|
||||||
|
logger.debug`Sender public key: ${user.data.publicKey}`;
|
||||||
|
|
||||||
|
// Log signed string
|
||||||
|
logger.debug`Signed string:\n${signedString}`;
|
||||||
|
}
|
||||||
|
|
||||||
return response(userString, 200, {
|
return response(userString, 200, {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...headers.toJSON(),
|
...headers.toJSON(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue