Keygrain
Deterministic password, SSH key, and wallet derivation from a master secret.
Install
pip install keygrain
CLI Usage
export KEYGRAIN_SECRET="your-master-secret"
keygrain me@example.com --site github.com
keygrain ssh --name github
keygrain wallet --name savings
Sync + Local Cache (read-only)
The CLI can download your synced services from the Keygrain server and store them in a local encrypted cache, then retrieve passwords / TOTP codes / SSH keys offline. The CLI is read-only: it never writes to the server. Add or change services with the browser extension or the Android app.
# Download and cache your account's services (the only networked command):
keygrain sync --email me@example.com
# List cached services (offline; no network):
keygrain list
keygrain list --type totp
keygrain list --site github.com
# Retrieve one credential (offline; no network):
keygrain get --site github.com # password (default)
keygrain get --site github.com --totp # current TOTP code
keygrain get --site github.com --ssh # authorized_keys line
keygrain get --site github.com --ssh --private # OpenSSH private key
keygrain get --id 550e8400-e29b-41d4-a716-446655440000 # select by exact id
# Seal a machine into offline-only mode (and lift it):
keygrain sync --lock
keygrain sync --unlock
# Self-hosted server:
keygrain sync --server https://sync.example.com
Site matching is a whole-label suffix match (github.com matches
accounts.github.com but bank does not match fakebank.com). Any ambiguous
match is a hard error listing the candidates — the CLI never guesses. The
resolved (site, service-email) is always echoed to stderr before a secret is
printed to stdout.
The cache lives at ~/.keygrain/accounts/<slug>.kg (AES-256-GCM, 0600). The
master secret is never written to disk.
What a compromised sync server can (and cannot) do
The sync server only ever stores an encrypted blob plus a small unauthenticated
metadata array (id + updated_at per service); it never sees your master secret
or any derived credential. A hostile or compromised server therefore cannot
exfiltrate secrets, decrypt your services, or leak data across accounts — the blob
is AES-256-GCM encrypted under a key derived from your secret, and the CLI verifies
its checksum and GCM tag before use.
The one thing a hostile server can influence is that unauthenticated metadata: by
tampering with the id values it could, at most, cause get --id <uuid> to resolve
to a different service that is still your own — it cannot inject a foreign or
attacker-controlled entry. The mandatory stderr echo of the resolved
(site, service-email) before any secret is printed is the guard: always read that
line to confirm you got the credential you intended. (The CLI also drops any
metadata id that is not UUID-shaped and strips control characters, so tampered
ids cannot inject terminal escape sequences.)
Providing the master secret
sync, list, and get accept the master secret from exactly one of:
# Interactive hidden prompt (default when run in a terminal):
keygrain get --site github.com
# Environment variable — for CI/CD with injected secrets:
keygrain get --site github.com --secret-env KEYGRAIN_SECRET
# File — for Docker/Kubernetes secrets mounted as files:
keygrain get --site github.com --secret-file /run/secrets/keygrain_secret
A raw --secret VALUE argument is intentionally not provided (it would leak
via ps / shell history). The CLI does not auto-load .env files.
Library Usage
from keygrain import derive_password, normalize_site
password = derive_password(
secret=b"my-secret",
email="me@example.com",
site=normalize_site("github.com"),
)
Features
- Argon2id key strengthening (64 MiB, 3 iterations)
- HMAC-SHA256 derivation — single password compromise reveals nothing
- TOTP seed derivation
- SSH Ed25519 key derivation
- BIP-39 wallet mnemonic derivation
- BIP-85 child mnemonic derivation
- Cross-platform compatible (Python, Kotlin, JavaScript)
Documentation
License
MIT
Metadata
Release files for keygrain 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| keygrain-1.1.0.tar.gz | 77.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keygrain-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 123.2 kB
Release files / keygrain-1.1.0.tar.gz
| Download URL | keygrain-1.1.0.tar.gz |
|---|---|
| Size | 77.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d115efc9c44b4d89b5c3fcff8418a03ae3dc2b59eb9e46b7fdc23fd4519e0699
|
|
BLAKE2b-256 checksum How to use checksums |
f034c9d6741ad0243f24aa9769d14f3d4daa64dde0183ad1e88638f6e4f69383
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.
Transparency logRelease files / keygrain-1.1.0-py3-none-any.whl
| Download URL | keygrain-1.1.0-py3-none-any.whl |
|---|---|
| Size | 45.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34aed9bbcdbf87f3ac6f863cba2b6c4da58e178caf80bbeab87219cc76b57e16
|
|
BLAKE2b-256 checksum How to use checksums |
abc56f86b8ad4d2897ab7575e9fcb4a0329f71761ec004e53d228bfbd1479d56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.
Transparency logSecurity for keygrain 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for keygrain-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.