export const DEEP_LINK_SCHEME = 'cardy'; export function buildLoginDeepLink(server: string, key: string): string { return `${DEEP_LINK_SCHEME}://login?server=${encodeURIComponent(server)}&key=${encodeURIComponent(key)}`; } export function parseLoginDeepLink(link: string): { server: string; key: string } | null { let url: URL; try { url = new URL(link.trim()); } catch { return null; } // Non-special schemes put "login" into host for "cardy://login?…". if (url.protocol !== `${DEEP_LINK_SCHEME}:` || url.host !== 'login') return null; const server = url.searchParams.get('server'); const key = url.searchParams.get('key'); if (!server || !key) return null; return { server, key }; }