// Shared wire protocol only; customer/browser graphs never import CP modules. export const LOGIN_PURPOSE = "flarebot-owner-login" as const; export const HEALTH_PURPOSE = "flarebot-bootstrap-health" as const; export const PROVIDER_PURPOSE = "flarebot-provider-enabled" as const; export const DOMAIN_CONFIGURATION_PURPOSE = "flarebot-domain-configuration" as const; export const DOMAIN_HEALTH_PURPOSE = "flarebot-domain-health" as const; export const encode = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes)) .replaceAll("+", "-") .replaceAll("/", "_") .replaceAll("=", ""); export function decode(value: string): Uint8Array { if (!/^[A-Za-z0-9_-]+$/.test(value)) throw new Error("Invalid bridge encoding"); return Uint8Array.from( atob(value.replaceAll("-", "+").replaceAll("_", "/")), (c) => c.charCodeAt(0), ); } export const random = () => encode(crypto.getRandomValues(new Uint8Array(32))); export const opaque = (value: unknown): value is string => typeof value === "string" && /^[A-Za-z0-9_-]{43}$/.test(value); export interface BridgeClaims { iss: string; aud: string; sub: string; installationId: string; purpose: | typeof LOGIN_PURPOSE | typeof HEALTH_PURPOSE | typeof PROVIDER_PURPOSE | typeof DOMAIN_CONFIGURATION_PURPOSE | typeof DOMAIN_HEALTH_PURPOSE; iat: number; exp: number; jti: string; state: string; challenge: string; operationId?: string; artifactDigest?: string; version?: string; }