import { existsSync } from "fs";
// ─── Android detection ───────────────────────────────────────────────────────
export const IS_ANDROID = process.platform === "android" ||
    process.env["PREFIX"]?.includes("com.termux") ||
    existsSync("/data/data/com.termux");
let _Entry = null;
let _keyringLoaded = false;
export function loadKeyring() {
    if (_keyringLoaded)
        return _Entry;
    _keyringLoaded = true;
    if (IS_ANDROID)
        return null;
    try {
        // eslint-disable-next-line @typescript-eslint/no-require-imports
        const mod = require("@napi-rs/keyring");
        _Entry = mod.Entry;
    }
    catch {
        _Entry = null;
    }
    return _Entry;
}
export function isKeychainAvailable(serviceName) {
    const EntryClass = loadKeyring();
    if (IS_ANDROID || !EntryClass)
        return false;
    try {
        new EntryClass(serviceName, "__test__");
        return true;
    }
    catch {
        return false;
    }
}
export function getKeychainEntry(serviceName, key) {
    const EntryClass = loadKeyring();
    if (!EntryClass)
        return null;
    try {
        return new EntryClass(serviceName, key);
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=keyring.js.map