···
+
import { OWNER_DID, SERVICE_DID } from "@/lib/env";
+
import { getRegistrationState, setRegistrationState } from "@/lib/state";
+
import type { AtUri } from "@/lib/types/atproto";
+
systemsGmstnDevelopmentChannelRecordSchema,
+
systemsGmstnDevelopmentChannelRecordSchema,
+
} from "@/lib/types/lexicon/systems.gmstn.development.channel";
+
import { prismCommitSchema } from "@/lib/types/prism";
import type { RouteHandler, WsRouteHandler } from "@/lib/types/routes";
+
import { getRecordFromAtUri } from "@/lib/utils/atproto";
import { newErrorResponse } from "@/lib/utils/http/responses";
+
import { rawDataToString } from "@/lib/utils/ws";
+
import type { RawData } from "ws";
+
import type WebSocket from "ws";
export const wrapHttpRegistrationCheck = (
routeHandler: RouteHandler,
···
+
export const attachLatticeRegistrationListener = (socket: WebSocket) => {
+
socket.on("message", (rawData: RawData) => {
+
const data = rawDataToString(rawData);
+
const jsonData: unknown = JSON.parse(data);
+
const { success: prismCommitParseSuccess, data: prismCommit } =
+
prismCommitSchema.safeParse(jsonData);
+
if (!prismCommitParseSuccess) return;
+
const { did, commit } = prismCommit;
+
if (did !== OWNER_DID) return;
+
const { rkey } = commit;
+
// TODO: replace empty string with call to resolve did doc and the endpoint and yadda yadda etc. etc. you get it.
+
// if you don't, then the tl;dr is you need to resolve the did:plc document to get the service endpoint describing this lattice and ensure
+
// that the domain/origin/whatever matches with the rkey (or record value if we decide to transition to that)
+
const latticeDomain = SERVICE_DID.startsWith("did:web:")
+
if (rkey !== latticeDomain) return;
+
setRegistrationState(true);