···
import { OWNER_DID, SERVER_PORT, SERVICE_DID } from "@/lib/env";
import { setRegistrationState } from "@/lib/state";
import type { AtUri, Did } from "@/lib/types/atproto";
4
+
import type { SessionInfo } from "@/lib/types/handshake";
import { systemsGmstnDevelopmentChannelRecordSchema } from "@/lib/types/lexicon/systems.gmstn.development.channel";
import { getRecordFromAtUri, stringToAtUri } from "@/lib/utils/atproto";
import { getConstellationBacklink } from "@/lib/utils/constellation";
8
+
import { isDomain } from "@/lib/utils/domains";
9
+
import { initiateHandshakeTo } from "@/lib/utils/handshake";
import { newErrorResponse } from "@/lib/utils/http/responses";
import { connectToPrism } from "@/lib/utils/prism";
···
channelsByShard.set(storeAtAtUri, [...prevUris, currentChannelUri]);
119
+
const channelSessions = new Map<AtUri, SessionInfo>();
121
+
const channelsByShardEntries = channelsByShard.entries();
123
+
for (const entry of channelsByShardEntries) {
124
+
const shardAtUri = entry[0];
126
+
let shardDid: Did | undefined;
127
+
// TODO: if the rkey of the shard URI is not a valid domain, then it must be a did:plc
128
+
// we need to find a better way to enforce this. we really should explore just resolving the
129
+
// record and then checking the record value for the actual domain instead.
130
+
// did resolution hard;;
132
+
isDomain(shardAtUri.rKey ?? "") ||
133
+
shardAtUri.rKey?.startsWith("localhost:")
135
+
// from the isDomain check, if we pass, we can conclude that
136
+
shardDid = `did:web:${encodeURIComponent(shardAtUri.rKey ?? "")}`;
138
+
shardDid = `did:plc:${encodeURIComponent(shardAtUri.rKey ?? "")}`;
141
+
const channelAtUris = entry[1];
143
+
const handshakeResult = await initiateHandshakeTo({
145
+
channels: channelAtUris,
147
+
if (!handshakeResult.ok) return;
148
+
const sessionInfo = handshakeResult.data;
149
+
console.log("Handshake to", shardAtUri.rKey, "complete!");
150
+
console.log("Session info:", sessionInfo);
151
+
channelSessions.set(shardAtUri, sessionInfo);
const server = await setupServer();
for (const [url, route] of Object.entries(routes)) {