pub struct Storage { /* private fields */ }Expand description
Encrypted persistent storage for keys and FROST shares.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn rotate_password(
&mut self,
old_password: &str,
new_password: &str,
) -> Result<()>
pub fn rotate_password( &mut self, old_password: &str, new_password: &str, ) -> Result<()>
Rotate the vault password.
Re-encrypts the data encryption key with a new password-derived key. Creates a backup of the header before rotation and restores it on failure.
Sourcepub fn rotate_data_key(&mut self, password: &str) -> Result<()>
pub fn rotate_data_key(&mut self, password: &str) -> Result<()>
Rotate the data encryption key.
Generates a new data encryption key and re-encrypts all stored keys and shares. Creates backups of the header and database before rotation and restores them on failure.
Source§impl Storage
impl Storage
Sourcepub fn set_state_publisher(&self, publisher: Arc<dyn StatePublisher>)
pub fn set_state_publisher(&self, publisher: Arc<dyn StatePublisher>)
Install the replication sink (keep-web). A later call replaces the previous sink.
Sourcepub fn apply_replicated_record(
&self,
table: &str,
record_id: &str,
encrypted: &[u8],
created_at: u64,
now: u64,
) -> Result<ReplicatedApply>
pub fn apply_replicated_record( &self, table: &str, record_id: &str, encrypted: &[u8], created_at: u64, now: u64, ) -> Result<ReplicatedApply>
Apply a record replicated from a peer (the keep-state consumer / standby side). Stores the
already-vault-encrypted encrypted bytes verbatim under table, keyed by hex record_id –
the standby shares the vault key, so it later decrypts them like its own. Never notifies the
publisher, so a consumed record is not echoed back to the relay. Rejects any table but the three
replicated ones, so a hostile or buggy peer cannot write shares or node-local state.
created_at is the replicated event’s signed timestamp; the record is applied only if it is
strictly newer than the highest already applied for this d-tag (rollback/replay guard). Returns
true if applied, false if ignored as stale.
Sourcepub fn apply_replicated_delete(
&self,
table: &str,
record_id: &str,
created_at: u64,
now: u64,
) -> Result<ReplicatedApply>
pub fn apply_replicated_delete( &self, table: &str, record_id: &str, created_at: u64, now: u64, ) -> Result<ReplicatedApply>
Apply a replicated delete (tombstone) from a peer. Never notifies the publisher. Same rollback +
future-bound guards as apply_replicated_record.
Sourcepub fn state_version(&self, table: &str, record_id: &str) -> Result<Option<u64>>
pub fn state_version(&self, table: &str, record_id: &str) -> Result<Option<u64>>
The persisted keep-state high-water-mark for a single replicated record’s d-tag, or None if it
has never been applied. A promoted standby seeds its publisher’s monotonic floor PER RECORD from
this (not from a global maximum), so a quiet record is not future-dated to the newest record’s
timestamp. Uses the same key derivation as the consumer’s guard, so it reads exactly the mark that
guard wrote. A corrupt (non-8-byte) entry propagates a decode error.
Sourcepub fn snapshot_replicable_records(
&self,
) -> Result<Vec<(&'static str, String, Vec<u8>)>>
pub fn snapshot_replicable_records( &self, ) -> Result<Vec<(&'static str, String, Vec<u8>)>>
Snapshot every replicable record currently in storage as (logical table, hex record id, at-rest encrypted bytes) – the same shape the StatePublisher hook emits for a live write. The
keep-state publisher replays this once at startup so records written BEFORE replication was wired
(which the write-time hook never observed) reach a fresh standby instead of being stranded.
Reads the raw stored ciphertext (hex(backend key) is the record id, the stored value is the
encrypted blob), so it matches the hook byte-for-byte and needs neither decryption nor the data
key. The three logical tables mirror [replicated_table].
Sourcepub fn create(path: &Path, password: &str, params: Argon2Params) -> Result<Self>
pub fn create(path: &Path, password: &str, params: Argon2Params) -> Result<Self>
Create new storage with the given password.
Create new storage whose data key is the caller-provided data_key rather than a fresh random
one, so every node in a cluster shares one vault key (keep-state replication).
Sourcepub fn create_with_backend(
path: &Path,
password: &str,
params: Argon2Params,
backend: Box<dyn StorageBackend>,
) -> Result<Self>
pub fn create_with_backend( path: &Path, password: &str, params: Argon2Params, backend: Box<dyn StorageBackend>, ) -> Result<Self>
Create new storage with a custom backend.
Sourcepub fn unlock_with_backend(
&mut self,
password: &str,
backend: Box<dyn StorageBackend>,
) -> Result<()>
pub fn unlock_with_backend( &mut self, password: &str, backend: Box<dyn StorageBackend>, ) -> Result<()>
Unlock with the given password using a custom backend.
Sourcepub fn verify_password(&self, password: &str) -> Result<()>
pub fn verify_password(&self, password: &str) -> Result<()>
Verify a password without changing the unlock state.
Sourcepub fn is_unlocked(&self) -> bool
pub fn is_unlocked(&self) -> bool
Returns true if unlocked.
Sourcepub fn argon2_params(&self) -> Argon2Params
pub fn argon2_params(&self) -> Argon2Params
The vault’s Argon2id parameters (from the header, readable before unlock). These are non-secret; callers use them to reproduce an unlock’s KDF cost (e.g. a timing equalizer) without unlocking the vault.
Sourcepub fn store_secret(&self, record: &SecretRecord) -> Result<()>
pub fn store_secret(&self, record: &SecretRecord) -> Result<()>
Store (insert or overwrite) an arbitrary-secret record, keyed by its
random id. The whole record – name, kind, AND plaintext value – is
bincode-serialized then encrypted under the vault data key, so nothing is
on disk in the clear and the entry title is protected too. Unlike
store_key this never notifies the replication sink: secrets are not
replicable (see Self::replicated_table).
Sourcepub fn load_secret(&self, id: &[u8; 32]) -> Result<SecretRecord>
pub fn load_secret(&self, id: &[u8; 32]) -> Result<SecretRecord>
Load a secret record by its 32-byte id.
Sourcepub fn list_secrets(&self) -> Result<Vec<SecretRecord>>
pub fn list_secrets(&self) -> Result<Vec<SecretRecord>>
List all stored secret records. O(n) full decrypt, matching list_keys;
fine for the modest counts a first-pass secret store holds.
Sourcepub fn store_sealed_secret(
&self,
record: &SecretRecord,
seal: &ThresholdSeal,
) -> Result<()>
pub fn store_sealed_secret( &self, record: &SecretRecord, seal: &ThresholdSeal, ) -> Result<()>
Store a secret whose VALUE is sealed behind a t-of-n OPRF quorum. The
record’s value must already be the DEK-ciphertext produced by
crate::secret::seal_value; seal is its matching wrapped DEK + OPRF
params. The record (name/kind/DEK-ciphertext) and the seal are each
encrypted under the vault data key and written in ONE atomic transaction,
so a crash can never leave a sealed value without its wrapped DEK (which
would make the value permanently undecryptable). Like store_secret, it
never notifies the replication sink: secrets are not replicable.
Sourcepub fn load_secret_seal(&self, id: &[u8; 32]) -> Result<Option<ThresholdSeal>>
pub fn load_secret_seal(&self, id: &[u8; 32]) -> Result<Option<ThresholdSeal>>
Load the ThresholdSeal for a secret id, or None when the secret is
not threshold-sealed (an ordinary plaintext-value secret). The presence of
a seal is what marks a secret as threshold-gated; its value is then the
DEK-ciphertext rather than plaintext.
Sourcepub fn delete_secret(&self, id: &[u8; 32]) -> Result<()>
pub fn delete_secret(&self, id: &[u8; 32]) -> Result<()>
Delete a secret record by id, along with its threshold seal if it has
one, in a single atomic transaction. Errors if no such secret exists.
Sourcepub fn schema_version(&self) -> Result<u32>
pub fn schema_version(&self) -> Result<u32>
Get the current schema version.
Sourcepub fn needs_migration(&self) -> Result<bool>
pub fn needs_migration(&self) -> Result<bool>
Check if migrations are needed.
Sourcepub fn run_migrations(&self) -> Result<MigrationResult>
pub fn run_migrations(&self) -> Result<MigrationResult>
Run pending migrations.
Store a FROST share.
Store multiple FROST shares atomically.
List all stored FROST shares.
Delete a FROST share.
Sourcepub fn store_descriptor(&self, descriptor: &WalletDescriptor) -> Result<()>
pub fn store_descriptor(&self, descriptor: &WalletDescriptor) -> Result<()>
Store a wallet descriptor. The storage key is
group_pubkey || version_be(version) so multiple versions for the
same group can coexist; replacing an existing version is a no-op
upsert against the same key.
Sourcepub fn get_descriptor(
&self,
group_pubkey: &[u8; 32],
) -> Result<Option<WalletDescriptor>>
pub fn get_descriptor( &self, group_pubkey: &[u8; 32], ) -> Result<Option<WalletDescriptor>>
Get the latest-version wallet descriptor for a group public key.
Returns None if no descriptor is stored for the group.
Only one row is decrypted (the highest-versioned one) regardless of how many versions exist for the group. The latest version is determined by the trailing 4 big-endian bytes of the key, so the payload only needs to be touched once we know which row to read.
Sourcepub fn get_descriptor_version(
&self,
group_pubkey: &[u8; 32],
version: u32,
) -> Result<Option<WalletDescriptor>>
pub fn get_descriptor_version( &self, group_pubkey: &[u8; 32], version: u32, ) -> Result<Option<WalletDescriptor>>
Get a specific version of the wallet descriptor for a group.
Sourcepub fn list_descriptors(&self) -> Result<Vec<WalletDescriptor>>
pub fn list_descriptors(&self) -> Result<Vec<WalletDescriptor>>
List the latest-version wallet descriptor for every group. Older
versions are not returned; use list_all_descriptor_versions when
every row is required (e.g. backup, rotation).
Sourcepub fn list_all_descriptor_versions(&self) -> Result<Vec<WalletDescriptor>>
pub fn list_all_descriptor_versions(&self) -> Result<Vec<WalletDescriptor>>
List every stored wallet descriptor row across all groups and
versions. Decrypts every row; prefer list_descriptors when only the
latest version per group is needed.
Sourcepub fn list_descriptors_for_group(
&self,
group_pubkey: &[u8; 32],
) -> Result<Vec<WalletDescriptor>>
pub fn list_descriptors_for_group( &self, group_pubkey: &[u8; 32], ) -> Result<Vec<WalletDescriptor>>
List all stored descriptor versions for a single group public key, sorted ascending by version. Decrypts only rows whose key prefix matches the group, avoiding a full-table scan.
Sourcepub fn upsert_device_registration(
&self,
group_pubkey: &[u8; 32],
registration: DeviceRegistration,
) -> Result<()>
pub fn upsert_device_registration( &self, group_pubkey: &[u8; 32], registration: DeviceRegistration, ) -> Result<()>
Atomically insert or update a device registration on the latest
descriptor for the given group. Serialized under descriptor_lock so
concurrent callers cannot lose each other’s updates across the
read-modify-write.
Only the latest version row is mutated: registrations on superseded
descriptor versions are not reachable through this path. This matches
the protocol’s “latest descriptor is authoritative” invariant. No
other path iterates list_descriptors and re-stores entries, so older
versions remain frozen at the registrations they captured at the time
of the corresponding descriptor finalization.
Sourcepub fn delete_descriptor(&self, group_pubkey: &[u8; 32]) -> Result<()>
pub fn delete_descriptor(&self, group_pubkey: &[u8; 32]) -> Result<()>
Delete every stored version of the wallet descriptor for a group.
All version rows are removed via the backend’s delete_batch; on
backends that implement it atomically (redb does) a crash mid-delete
cannot leave a partial set behind.
Sourcepub fn delete_descriptor_version(
&self,
group_pubkey: &[u8; 32],
version: u32,
) -> Result<()>
pub fn delete_descriptor_version( &self, group_pubkey: &[u8; 32], version: u32, ) -> Result<()>
Delete a single version of a wallet descriptor for a group.
Sourcepub fn store_relay_config(&self, config: &RelayConfig) -> Result<()>
pub fn store_relay_config(&self, config: &RelayConfig) -> Result<()>
Store a relay configuration.
Sourcepub fn get_relay_config(
&self,
group_pubkey: &[u8; 32],
) -> Result<Option<RelayConfig>>
pub fn get_relay_config( &self, group_pubkey: &[u8; 32], ) -> Result<Option<RelayConfig>>
Get a relay configuration by group public key.
Sourcepub fn list_relay_configs(&self) -> Result<Vec<RelayConfig>>
pub fn list_relay_configs(&self) -> Result<Vec<RelayConfig>>
List all stored relay configurations.
Sourcepub fn delete_relay_config(&self, group_pubkey: &[u8; 32]) -> Result<()>
pub fn delete_relay_config(&self, group_pubkey: &[u8; 32]) -> Result<()>
Delete a relay configuration.
Sourcepub fn get_kill_switch(&self) -> Result<bool>
pub fn get_kill_switch(&self) -> Result<bool>
Get the kill switch state from the vault.
Sourcepub fn set_kill_switch(&self, active: bool) -> Result<()>
pub fn set_kill_switch(&self, active: bool) -> Result<()>
Set the kill switch state in the vault.
Sourcepub fn get_proxy_config(&self) -> Result<ProxyConfig>
pub fn get_proxy_config(&self) -> Result<ProxyConfig>
Get the proxy configuration from the vault.
Sourcepub fn set_proxy_config(&self, config: &ProxyConfig) -> Result<()>
pub fn set_proxy_config(&self, config: &ProxyConfig) -> Result<()>
Set the proxy configuration in the vault.
Sourcepub fn store_health_status(&self, status: &KeyHealthStatus) -> Result<()>
pub fn store_health_status(&self, status: &KeyHealthStatus) -> Result<()>
Store a key health status record.
Sourcepub fn get_health_status(
&self,
group_pubkey: &[u8; 32],
share_index: u16,
) -> Result<Option<KeyHealthStatus>>
pub fn get_health_status( &self, group_pubkey: &[u8; 32], share_index: u16, ) -> Result<Option<KeyHealthStatus>>
Get a key health status record.
Sourcepub fn list_health_statuses(&self) -> Result<Vec<KeyHealthStatus>>
pub fn list_health_statuses(&self) -> Result<Vec<KeyHealthStatus>>
List all key health status records.