decentralised sync engine

feat: create jwt

serenity 0b587726 286f2e22

Changed files
+22
src
lib
utils
+22
src/lib/utils/jwt.ts
···
···
+
import type { Did } from "@/lib/types/atproto";
+
import { DID_DOCUMENT } from "@/lib/utils/didDoc";
+
import { createServiceJwt } from "@atcute/xrpc-server/auth";
+
+
export const createInterServiceJwt = async (audience: Did) => {
+
if (DID_DOCUMENT) {
+
// if DID_DOCUMENT is not undefined, it means the Lattice has a did:web document.
+
const keypair = DID_DOCUMENT.keys.atproto;
+
return await createServiceJwt({
+
keypair,
+
issuer: DID_DOCUMENT.didDoc.id,
+
audience,
+
lxm: null,
+
});
+
} else {
+
// else, we know that there is a did:plc that describes this lattice as an endpoint.
+
// in which case, we resolve with plc.directory and then ask the repo to create a JWT for us.
+
throw new Error(
+
"creation of inter-service JWTs with a did:plc is not yet implemented.",
+
);
+
}
+
};