/**
 * remote/relay-protocol — the wire contract for the sovereign relay.
 *
 * The relay is a zero-knowledge rendezvous: the PC ("host") and the phone
 * ("guest") both dial OUT to it (no inbound ports, NAT-friendly); the relay
 * forwards opaque ciphertext frames host↔guest and never decrypts them.
 *
 * Two layers:
 *   - the RELAY layer (this file's HTTP paths + `RelayFrame`) — what the relay
 *     sees: routing + ciphertext blobs + the public keys exchanged at pairing
 *     (public keys are safe in clear);
 *   - the SESSION layer (`RelayMessage`) — the plaintext INSIDE the E2E
 *     envelope, which only the two endpoints can read.
 *
 * @public @since 2.12.0 — preste remote-control T2
 */
export const RELAY_PROTOCOL_VERSION = 1;
/** Encode a pairing payload as a compact `preste-pair://` URL. */
export function encodePairingPayload(p) {
    const json = JSON.stringify(p);
    return `preste-pair://${Buffer.from(json, "utf-8").toString("base64url")}`;
}
/** Decode a `preste-pair://` URL back to a pairing payload. Throws on garbage. */
export function decodePairingPayload(uri) {
    const prefix = "preste-pair://";
    if (!uri.startsWith(prefix)) {
        throw new Error("relay: not a preste-pair:// URI");
    }
    const json = Buffer.from(uri.slice(prefix.length), "base64url").toString("utf-8");
    const p = JSON.parse(json);
    if (typeof p.relayUrl !== "string" ||
        typeof p.sessionId !== "string" ||
        typeof p.pairingToken !== "string" ||
        typeof p.hostPubKey !== "string") {
        throw new Error("relay: malformed pairing payload");
    }
    return p;
}
// ─── Relay HTTP endpoint paths ───────────────────────────────────────────────
export const relayPaths = {
    /** POST — host registers a session. */
    session: "/relay/session",
    /** POST — guest joins with the pairing token. */
    join: (id) => `/relay/session/${id}/join`,
    /** GET (SSE) — host receives frames from the guest. */
    hostStream: (id) => `/relay/session/${id}/host-stream`,
    /** POST — host sends a frame to the guest. */
    hostSend: (id) => `/relay/session/${id}/host-send`,
    /** GET (SSE) — guest receives frames from the host. */
    guestStream: (id) => `/relay/session/${id}/guest-stream`,
    /** POST — guest sends a frame to the host. */
    guestSend: (id) => `/relay/session/${id}/guest-send`,
};
//# sourceMappingURL=relay-protocol.js.map