native-keyvault
v0.0.3
Published
A simple cross platform native keyvault for storing secrets securely on your local machine. Supports Windows, macOS, and Linux with native encryption methods and optional fallback.
Readme
Native Keyvault
A cross-platform Node.js credential storage library that securely stores passwords using native OS credential managers with an encrypted fallback option.
Features
- Cross-platform support: macOS (Keychain), Windows (Credential Manager), Linux (libsecret)
- Automatic fallback: Falls back to encrypted file storage if native storage fails
- Secure encryption: AES-256-GCM encryption for fallback storage
- Simple API: Just three methods:
save(),get(), anddelete()
Installation
pnpm add native-keyvaultPlatform Requirements
Linux only: Requires libsecret-tools for native credential storage:
sudo apt-get install libsecret-toolsmacOS and Windows have native support built into the OS.
Usage
import { CredentialStore } from 'native-keyvault'
const store = new CredentialStore('my-app')
store.save('[email protected]', 'my-secure-password')
const password = store.get('[email protected]')
console.log(password)
store.delete('[email protected]')Force Fallback Mode
If you want to always use encrypted file storage instead of the native credential manager:
const store = new CredentialStore('my-app', { fallback: true })API
new CredentialStore(service, options?)
Creates a new credential store instance.
service(string): Identifier for your applicationoptions.fallback(boolean): Force fallback storage instead of native. Default:false
save(account, password)
Saves a credential.
account(string): Account identifier (e.g., email, username)password(string): Password to store
get(account): string | null
Retrieves a credential.
account(string): Account identifier- Returns: Password string or
nullif not found
delete(account)
Deletes a credential.
account(string): Account identifier to delete
How It Works
Native Storage (default): Uses OS-specific credential managers
- macOS: Keychain via
securitycommand - Windows: Credential Manager via
cmdkey - Linux: libsecret via
secret-tool
- macOS: Keychain via
Fallback Storage: If native storage fails or is unavailable
- Stores encrypted credentials in
~/.cache/{service}/credentials.json - Uses AES-256-GCM encryption with a randomly generated key
- Key stored in
~/.cache/{service}/key.binwith restricted permissions (600)
- Stores encrypted credentials in
Security Considerations
- Passwords are passed to native tools via stdin to avoid process list exposure
- Fallback encryption uses industry-standard AES-256-GCM
- Fallback storage files are created with restricted permissions (owner read/write only)
- Native credential managers provide OS-level security features
License
MIT
