···
1
-
import { getRegistrationState } from "@/lib/state";
1
+
import { OWNER_DID, SERVICE_DID } from "@/lib/env";
2
+
import { getRegistrationState, setRegistrationState } from "@/lib/state";
3
+
import type { AtUri } from "@/lib/types/atproto";
5
+
systemsGmstnDevelopmentChannelRecordSchema,
6
+
systemsGmstnDevelopmentChannelRecordSchema,
7
+
} from "@/lib/types/lexicon/systems.gmstn.development.channel";
8
+
import { prismCommitSchema } from "@/lib/types/prism";
import type { RouteHandler, WsRouteHandler } from "@/lib/types/routes";
10
+
import { getRecordFromAtUri } from "@/lib/utils/atproto";
import { newErrorResponse } from "@/lib/utils/http/responses";
12
+
import { rawDataToString } from "@/lib/utils/ws";
13
+
import type { RawData } from "ws";
14
+
import type WebSocket from "ws";
export const wrapHttpRegistrationCheck = (
routeHandler: RouteHandler,
···
53
+
export const attachLatticeRegistrationListener = (socket: WebSocket) => {
54
+
socket.on("message", (rawData: RawData) => {
55
+
const data = rawDataToString(rawData);
56
+
const jsonData: unknown = JSON.parse(data);
58
+
const { success: prismCommitParseSuccess, data: prismCommit } =
59
+
prismCommitSchema.safeParse(jsonData);
60
+
if (!prismCommitParseSuccess) return;
62
+
const { did, commit } = prismCommit;
63
+
if (did !== OWNER_DID) return;
65
+
const { rkey } = commit;
67
+
// TODO: replace empty string with call to resolve did doc and the endpoint and yadda yadda etc. etc. you get it.
68
+
// 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
69
+
// that the domain/origin/whatever matches with the rkey (or record value if we decide to transition to that)
70
+
const latticeDomain = SERVICE_DID.startsWith("did:web:")
71
+
? SERVICE_DID.slice(8)
73
+
if (rkey !== latticeDomain) return;
75
+
setRegistrationState(true);