@giancarl021/cli-core-vault-extension
Version:
Plain and secure storage extension for the @giancarl021/cli-core npm package
46 lines (43 loc) • 1.39 kB
JavaScript
import { platform } from 'node:os';
import { execSync } from 'node:child_process';
/**
* Checks if the current platform has a stable keychain available.
* @returns `true` if a stable keychain is available, `false` otherwise.
*/
function hasStableKeychain() {
const _platform = platform();
if (_platform === 'win32') {
// DPAPI is always available on Windows
return true;
}
if (_platform === 'darwin') {
// Check if the login keychain is available
try {
const output = execSync('security list-keychains', {
stdio: ['ignore', 'pipe', 'ignore']
}).toString('utf8');
return output.includes('login.keychain');
}
catch {
return false;
}
}
if (_platform === 'linux') {
// Check if the Secret Service API is available via D-Bus
if (!process.env.DBUS_SESSION_BUS_ADDRESS) {
return false;
}
try {
// Check if the 'org.freedesktop.secrets' service is available
const output = execSync('busctl --user list', {
stdio: ['ignore', 'pipe', 'ignore']
}).toString();
return output.includes('org.freedesktop.secrets');
}
catch {
return false;
}
}
return false;
}
export { hasStableKeychain as default };