Relay pairing offer v2 (E2EE) + host connections
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ConnectionOfferV1Schema = z.object({
|
||||
v: z.literal(1),
|
||||
sessionId: z.string().min(1),
|
||||
endpoints: z.array(z.string().min(1)).min(1),
|
||||
/**
|
||||
* Relay-only pairing offer.
|
||||
*
|
||||
* `serverId` is a stable daemon identifier scoped to `PASEO_HOME`, and is also
|
||||
* used as the relay session identifier.
|
||||
*/
|
||||
export const ConnectionOfferV2Schema = z.object({
|
||||
v: z.literal(2),
|
||||
serverId: z.string().min(1),
|
||||
daemonPublicKeyB64: z.string().min(1),
|
||||
relay: z
|
||||
.object({
|
||||
endpoint: z.string().min(1),
|
||||
})
|
||||
.nullable()
|
||||
.optional(),
|
||||
relay: z.object({
|
||||
endpoint: z.string().min(1),
|
||||
}),
|
||||
});
|
||||
|
||||
export type ConnectionOfferV1 = z.infer<typeof ConnectionOfferV1Schema>;
|
||||
export type ConnectionOfferV2 = z.infer<typeof ConnectionOfferV2Schema>;
|
||||
|
||||
export const ConnectionOfferSchema = ConnectionOfferV2Schema;
|
||||
export type ConnectionOffer = ConnectionOfferV2;
|
||||
|
||||
@@ -69,14 +69,14 @@ export function buildDaemonWebSocketUrl(endpoint: string): string {
|
||||
|
||||
export function buildRelayWebSocketUrl(params: {
|
||||
endpoint: string;
|
||||
sessionId: string;
|
||||
serverId: string;
|
||||
role: RelayRole;
|
||||
}): string {
|
||||
const { host, port, isIpv6 } = parseHostPort(params.endpoint);
|
||||
const protocol = shouldUseSecureWebSocket(port) ? "wss" : "ws";
|
||||
const hostPart = isIpv6 ? `[${host}]` : host;
|
||||
const url = new URL(`${protocol}://${hostPart}:${port}/ws`);
|
||||
url.searchParams.set("session", params.sessionId);
|
||||
url.searchParams.set("serverId", params.serverId);
|
||||
url.searchParams.set("role", params.role);
|
||||
return url.toString();
|
||||
}
|
||||
@@ -108,10 +108,9 @@ export function isRelayClientWebSocketUrl(url: string): boolean {
|
||||
const parsed = new URL(url);
|
||||
return (
|
||||
parsed.searchParams.get("role") === "client" &&
|
||||
parsed.searchParams.has("session")
|
||||
parsed.searchParams.has("serverId")
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user