Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

Encrypted persistent storage for keys and FROST shares.

Implementations§

Source§

impl Storage

Source

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.

Source

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

Source

pub fn set_state_publisher(&self, publisher: Arc<dyn StatePublisher>)

Install the replication sink (keep-web). A later call replaces the previous sink.

Source

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.

Source

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.

Source

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.

Source

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].

Source

pub fn create(path: &Path, password: &str, params: Argon2Params) -> Result<Self>

Create new storage with the given password.

Source

pub fn create_with_shared_data_key( path: &Path, password: &str, params: Argon2Params, data_key: Zeroizing<[u8; 32]>, ) -> Result<Self>

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).

Source

pub fn create_with_backend( path: &Path, password: &str, params: Argon2Params, backend: Box<dyn StorageBackend>, ) -> Result<Self>

Create new storage with a custom backend.

Source

pub fn open(path: &Path) -> Result<Self>

Open existing storage.

Source

pub fn unlock(&mut self, password: &str) -> Result<()>

Unlock with the given password.

Source

pub fn unlock_with_backend( &mut self, password: &str, backend: Box<dyn StorageBackend>, ) -> Result<()>

Unlock with the given password using a custom backend.

Source

pub fn verify_password(&self, password: &str) -> Result<()>

Verify a password without changing the unlock state.

Source

pub fn lock(&mut self)

Lock and clear keys from memory.

Source

pub fn is_unlocked(&self) -> bool

Returns true if unlocked.

Source

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.

Source

pub fn data_key(&self) -> Option<&SecretKey>

The data encryption key, if unlocked.

Source

pub fn store_key(&self, record: &KeyRecord) -> Result<()>

Store a key record.

Source

pub fn load_key(&self, id: &[u8; 32]) -> Result<KeyRecord>

Load a key record.

Source

pub fn list_keys(&self) -> Result<Vec<KeyRecord>>

List all stored key records.

Source

pub fn delete_key(&self, id: &[u8; 32]) -> Result<()>

Delete a key record.

Source

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).

Source

pub fn load_secret(&self, id: &[u8; 32]) -> Result<SecretRecord>

Load a secret record by its 32-byte id.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn path(&self) -> &Path

The storage directory path.

Source

pub fn schema_version(&self) -> Result<u32>

Get the current schema version.

Source

pub fn needs_migration(&self) -> Result<bool>

Check if migrations are needed.

Source

pub fn run_migrations(&self) -> Result<MigrationResult>

Run pending migrations.

Source

pub fn store_share(&self, share: &StoredShare) -> Result<()>

Store a FROST share.

Source

pub fn store_shares_atomic(&self, shares: &[StoredShare]) -> Result<()>

Store multiple FROST shares atomically.

Source

pub fn list_shares(&self) -> Result<Vec<StoredShare>>

List all stored FROST shares.

Source

pub fn delete_share( &self, group_pubkey: &[u8; 32], identifier: u16, ) -> Result<()>

Delete a FROST share.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_descriptor_version( &self, group_pubkey: &[u8; 32], version: u32, ) -> Result<()>

Delete a single version of a wallet descriptor for a group.

Source

pub fn store_relay_config(&self, config: &RelayConfig) -> Result<()>

Store a relay configuration.

Source

pub fn get_relay_config( &self, group_pubkey: &[u8; 32], ) -> Result<Option<RelayConfig>>

Get a relay configuration by group public key.

Source

pub fn list_relay_configs(&self) -> Result<Vec<RelayConfig>>

List all stored relay configurations.

Source

pub fn delete_relay_config(&self, group_pubkey: &[u8; 32]) -> Result<()>

Delete a relay configuration.

Source

pub fn get_kill_switch(&self) -> Result<bool>

Get the kill switch state from the vault.

Source

pub fn set_kill_switch(&self, active: bool) -> Result<()>

Set the kill switch state in the vault.

Source

pub fn get_proxy_config(&self) -> Result<ProxyConfig>

Get the proxy configuration from the vault.

Source

pub fn set_proxy_config(&self, config: &ProxyConfig) -> Result<()>

Set the proxy configuration in the vault.

Source

pub fn store_health_status(&self, status: &KeyHealthStatus) -> Result<()>

Store a key health status record.

Source

pub fn get_health_status( &self, group_pubkey: &[u8; 32], share_index: u16, ) -> Result<Option<KeyHealthStatus>>

Get a key health status record.

Source

pub fn list_health_statuses(&self) -> Result<Vec<KeyHealthStatus>>

List all key health status records.

Source

pub fn delete_health_status( &self, group_pubkey: &[u8; 32], share_index: u16, ) -> Result<()>

Delete a key health status record.

Trait Implementations§

Source§

impl Drop for Storage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more