Expand description
An encrypted secret and credential store for Weirdnet servers and apps.
- Per-entry sealed values in a SQLCipher database: each version of each value is sealed
on its own (XChaCha20-Poly1305, bound to its secret, version, environment and scope), with
metadata (name, kind, labels, scope) beside it. Plaintext only lives in
Plaintext, which is wiped on drop and never serialized. - Scoped access: every call goes through an environment check, per-identity
grants for
UseandReveal, and the app’sAuthorizehook. - Use without revealing:
Vault::use_secrethands the value to a closure inside the process;Vault::revealretrieves it for approved identities, also sealed to a recipient key. - Environments: a caller bound to
Environment::Testcan never touch a live secret. - Rotation without downtime: stage, try, promote, roll back, retire.
- A hash-chained, append-only audit log with time-range queries.
- Keys from a password (weirdnet-keys keyring,
VaultHome), an OS keychain (KeychainStore, featurekeychain), a weirdnet-sync secret store (featuresync) or the caller. AsyncVaultfor Tokio (featuretokio, on by default), anAuthorizeover weirdnet-access (featureaccess) and metadata-only MCP tools (featuremcp).
use std::sync::Arc;
use weirdnet_vault::*;
let policy = Arc::new(RolePolicy::with_example_roles());
let tenant = Scope::new(["tenant-7"])?;
let account = tenant.child("provider-a")?;
policy.assign("admin", &Scope::root(), "admin")?;
policy.assign("bot", &tenant, "trader")?;
policy.assign("alice", &tenant, "viewer")?;
let vault = Vault::open_in_memory(policy.clone(), VaultOptions::new())?;
let admin = Caller::live("admin");
let key = vault.create(&admin, NewSecret::new(account.clone(), "api", Environment::Live).kind("api-key"), b"key:secret")?;
vault.grant(&admin, GrantTarget::Scope(account.clone()), "bot", &[GrantAction::Use], None)?;
// The bot signs with the key; the key never comes back.
let signed = vault.use_secret(&Caller::live("bot"), &key.id, |s| s.len())?;
assert_eq!(signed, 10);
// It may not retrieve it, and a viewer may only see metadata.
assert!(vault.reveal(&Caller::live("bot"), &key.id).is_err());
assert_eq!(vault.list(&Caller::live("alice"), &tenant)?.len(), 1);
assert!(vault.use_secret(&Caller::live("alice"), &key.id, |_| ()).is_err());
// A dry-run context never reaches a live secret.
assert!(matches!(vault.use_secret(&Caller::test("bot"), &key.id, |_| ()), Err(VaultError::EnvironmentMismatch { .. })));
vault.verify_audit()?;See the design.
Modules§
- access
- An
Authorizeover weirdnet-access’s host-side enforcement (featureaccess). - mcp
- Metadata-only MCP tools over weirdnet-mcp (feature
mcp).
Structs§
- Access
Request - One request, as the
Authorizehook sees it. - Async
Vault - A cheap-to-clone handle that runs every vault call on Tokio’s blocking pool, so database and crypto work never stalls the runtime.
- Audit
Head - The newest record’s position and hash. Publish it somewhere else (another node, a signed note) to make a rewritten log detectable.
- Audit
Query - Filters for
Vault::audit. Everything is optional; records come back oldest first. - Audit
Record - One audit record. It says who did what, where and when, and how it ended; it never holds a secret value.
- Caller
- Who is asking: an identity the app has authenticated (a Weirdnet user id, a device peer id, an API-key id, …) bound to an environment.
- Clock
- The time source (ms since the Unix epoch). Tests pass their own.
- Exchange
Secret - An X25519 secret for one exchange (wiped on drop).
- Grant
- An approval for one identity.
- GrantId
- A grant’s id (a random UUID).
- Init
Output - Result of
init. Show once, then drop. - Key32
- A 256-bit secret key, wiped on drop and never printed.
- Keychain
Store - The OS keychain: macOS Keychain, Windows Credential Manager, or the Secret Service on
Linux and the BSDs. Entries are
(service, name). - Memory
KeyStore - An in-memory key store (tests, examples).
- NewSecret
- What to create.
- Plaintext
- A secret value in memory: wiped on drop, never cloned, printed or serialized.
- Recipient
Sealed - A retrieved value sealed to one recipient: an ephemeral X25519 key agreement, HKDF over the shared secret bound to both public keys, the secret id and version, then XChaCha20-Poly1305. Only the holder of the recipient’s secret key can open it, so it can travel over any channel.
- Role
Policy - A small role policy: roles are named sets of actions, and identities hold roles on scopes (a role on a scope covers everything below it). It can change while the vault runs.
- Scope
- A hierarchical key such as
tenant-7/provider-a. A scope contains itself and every scope below it; the empty scope is the root and contains everything. - Secret
Id - A secret’s id (a random UUID).
- Secret
Meta - A secret’s metadata: the only secret type that is serializable, and so the only one safe to send to clients or MCP. It never holds a value.
- Vault
- An open vault. It is
Send + Sync; share it withArc(or useAsyncVaultfrom Tokio). - Vault
Home - A vault folder:
envelope.toml,service/(the keyring’s files) andvault.db. - Vault
Options - Vault-wide settings.
- Version
Meta - One version’s metadata (never its value).
- Zeroizing
Zeroizingis a wrapper for anyZ: Zeroizetype which implements aDrophandler which zeroizes dropped values.
Enums§
- Action
- What a caller wants to do.
- Decision
- The hook’s answer.
- Environment
- Which world a secret belongs to, enforced on every call.
- Grant
Action - What a grant approves.
- Grant
Target - What a grant covers: one secret, or every secret in a scope (and below it).
- Outcome
- How a request ended.
- Vault
Error - Everything that can go wrong.
- Version
State - Where a version stands.
- Which
- Which version to use or retrieve.
Constants§
- GENESIS
- The
prev_hashof the first record: 64 zeros. - MAX_
DEPTH - The most segments a scope may have.
- MAX_
DETAIL - The longest detail text kept, in bytes.
- MAX_
LABELS - The most labels a secret may have.
- MAX_
LIMIT - The most records one query returns.
- MAX_
SEGMENT - The longest scope segment, in bytes.
Traits§
- Authorize
- The app’s access policy. Every vault call asks it, after the environment check and (for
Action::UseandAction::Reveal) the grant check. - KeyStore
- Keeps secret bytes by name.
Functions§
- load_
or_ create_ key - The 32-byte key stored under
name, or a new random one, stored and read back. - verify_
chain - Checks a contiguous run of records: each is intact, follows the one before (or
prev_hash, when given) and has the next sequence number. Returns the failingseq.
Type Aliases§
- Labels
- Free-form labels.
- Result
ResultwithVaultError.- Secret
String - Secret string type.