1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! 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](Grant) for `Use` and `Reveal`, and the app's [`Authorize`] hook.
//! - **Use without revealing**: [`Vault::use_secret`] hands the value to a closure inside the
//! process; [`Vault::reveal`] retrieves it for approved identities, also
//! [sealed to a recipient key](Vault::reveal_sealed).
//! - **Environments**: a caller bound to [`Environment::Test`] can 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`], feature `keychain`), a weirdnet-sync secret store (feature `sync`) or
//! the caller.
//! - [`AsyncVault`] for Tokio (feature `tokio`, on by default), an `Authorize` over
//! weirdnet-access (feature `access`) and metadata-only MCP tools (feature `mcp`).
//!
//! ```
//! use std::sync::Arc;
//! use weirdnet_vault::*;
//!
//! # fn main() -> Result<()> {
//! 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()?;
//! # Ok(()) }
//! ```
//!
//! See the [design](https://github.com/WeirdBrains/weirdnet-vault/blob/main/docs/design/vault.md).
pub use AsyncVault;
pub use ;
pub use ;
pub use ;
pub use VaultHome;
pub use KeychainStore;
pub use SyncSecrets;
pub use ;
pub use ;
pub use RecipientSealed;
pub use ;
pub use ;
pub use ;
pub use ExchangeSecret;
pub use InitOutput;
pub use ;