export async function enrollDevice(apiUrl, inviteToken, identityPkHex, ephemeralPkHex, proofHex, platform) {
    const res = await fetch(`${apiUrl}/api/v1/enroll`, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
            invite_token: inviteToken,
            identity_public_key: identityPkHex,
            ephemeral_public_key: ephemeralPkHex,
            proof_of_possession: proofHex,
            platform: platform ?? "node",
        }),
    });
    if (!res.ok) {
        const detail = await res.text();
        throw new Error(`Enrollment failed (${res.status}): ${detail}`);
    }
    return res.json();
}
export async function pollDeviceStatus(apiUrl, deviceId) {
    const res = await fetch(`${apiUrl}/api/v1/devices/${deviceId}/status`);
    if (res.status === 429) {
        // Rate limited — caller should back off and retry
        return { device_id: deviceId, status: "PENDING", fingerprint: "", rateLimited: true };
    }
    if (!res.ok) {
        const detail = await res.text();
        throw new Error(`Status poll failed (${res.status}): ${detail}`);
    }
    return res.json();
}
export async function activateDevice(apiUrl, deviceId) {
    const res = await fetch(`${apiUrl}/api/v1/devices/${deviceId}/activate`, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({}),
    });
    if (!res.ok) {
        const detail = await res.text();
        throw new Error(`Activation failed (${res.status}): ${detail}`);
    }
    return res.json();
}
//# sourceMappingURL=transport.js.map