···11-import { getRegistrationState } from "@/lib/state";
11+import { OWNER_DID, SERVICE_DID } from "@/lib/env";
22+import { getRegistrationState, setRegistrationState } from "@/lib/state";
33+import type { AtUri } from "@/lib/types/atproto";
44+import {
55+ systemsGmstnDevelopmentChannelRecordSchema,
66+ systemsGmstnDevelopmentChannelRecordSchema,
77+} from "@/lib/types/lexicon/systems.gmstn.development.channel";
88+import { prismCommitSchema } from "@/lib/types/prism";
29import type { RouteHandler, WsRouteHandler } from "@/lib/types/routes";
1010+import { getRecordFromAtUri } from "@/lib/utils/atproto";
311import { newErrorResponse } from "@/lib/utils/http/responses";
1212+import { rawDataToString } from "@/lib/utils/ws";
1313+import type { RawData } from "ws";
1414+import type WebSocket from "ws";
415516export const wrapHttpRegistrationCheck = (
617 routeHandler: RouteHandler,
···38493950 return wrappedFunction;
4051}
5252+5353+export const attachLatticeRegistrationListener = (socket: WebSocket) => {
5454+ socket.on("message", (rawData: RawData) => {
5555+ const data = rawDataToString(rawData);
5656+ const jsonData: unknown = JSON.parse(data);
5757+5858+ const { success: prismCommitParseSuccess, data: prismCommit } =
5959+ prismCommitSchema.safeParse(jsonData);
6060+ if (!prismCommitParseSuccess) return;
6161+6262+ const { did, commit } = prismCommit;
6363+ if (did !== OWNER_DID) return;
6464+6565+ const { rkey } = commit;
6666+6767+ // TODO: replace empty string with call to resolve did doc and the endpoint and yadda yadda etc. etc. you get it.
6868+ // 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
6969+ // that the domain/origin/whatever matches with the rkey (or record value if we decide to transition to that)
7070+ const latticeDomain = SERVICE_DID.startsWith("did:web:")
7171+ ? SERVICE_DID.slice(8)
7272+ : "";
7373+ if (rkey !== latticeDomain) return;
7474+7575+ setRegistrationState(true);
7676+ });
7777+};