Back

Version 2

3/30/2024
// SPDX-License-Identifier: 0BSD

type InstanceActorConfig = {
hostname: string;
publicKeyPem: string;
};

const createActorAcctUri = (hostname: string) => `acct:${hostname}@${hostname}`;
const createActorId = (hostname: string) => new URL(`https://${hostname}/actor`);
const createPublicKeyId = (actorId: string | URL) => {
const publicKeyId = new URL(actorId);
publicKeyId.hash = "main-key";
return publicKeyId;
};

export function createInstanceActor(config: InstanceActorConfig) {
const jrd = createJRD(config.hostname);
const actor = createActor(config);
return {
acctUri: jrd.subject,
actorId: actor.id,
publicKeyId: actor.publicKey.id,
activityPubHandler,
webfingerHandler,
};

function activityPubHandler() {
const res = Response.json(actor);
res.headers.set("content-type", "application/activity+json");
return res;
}

function webfingerHandler() {
const res = Response.json(jrd);
res.headers.set("content-type", "application/jrd+json; charset=utf-8");
return res;
Updated: March 30, 2024