// Shared pairing primitives used by the live relay-adoption path. import type { DeviceType } from "./sync-types"; export interface PairingTransport { send(msg: Uint8Array): Promise; receive(): Promise; } export interface LocalIdentity { deviceId: string; deviceName: string; deviceType: DeviceType; longTermPublicKeyHex: string; signingPublicKeyHex?: string; /** Server-only field — Android/iOS sync hosts announce their port. */ wsPort?: number; /** Stable per-vault id, omitted while the vault is locked. */ vaultId?: string; /** Signed Pro license blob advertised after SAS confirmation. */ license?: string; relayUrl?: string; } /** Derive the cross-platform 8-digit SAS from a Noise handshake hash. */ export function derivePairingSAS(handshakeHash: Uint8Array): string { if (handshakeHash.length < 8) { throw new Error("handshake hash too short for SAS"); } // The big-endian rule is pinned by the Android cross-platform KATs. let value = 0n; for (const byte of handshakeHash.subarray(0, 8)) { value = (value << 8n) | BigInt(byte); } return String(value % 100_000_000n).padStart(8, "0"); }