decentralised sync engine
1import type { Did } from "@/lib/types/atproto";
2import { DID_DOCUMENT } from "@/lib/utils/didDoc";
3import { createServiceJwt } from "@atcute/xrpc-server/auth";
4
5export const createInterServiceJwt = async (audience: Did) => {
6 if (DID_DOCUMENT) {
7 // if DID_DOCUMENT is not undefined, it means the Lattice has a did:web document.
8 const keypair = DID_DOCUMENT.keys.atproto;
9 return await createServiceJwt({
10 keypair,
11 issuer: DID_DOCUMENT.didDoc.id,
12 audience,
13 lxm: null,
14 });
15 } else {
16 // else, we know that there is a did:plc that describes this lattice as an endpoint.
17 // in which case, we resolve with plc.directory and then ask the repo to create a JWT for us.
18 throw new Error(
19 "creation of inter-service JWTs with a did:plc is not yet implemented.",
20 );
21 }
22};