second-brain-sync 0.13.0

Bidirectional sync for second-brain: SSH transport, JSONL change log, conflict resolution
Documentation
use age::x25519::Recipient;
use anyhow::{Result, anyhow, ensure};
use second_brain_core::keys::{every_held_epoch, hand_over};

use super::Keyring;
use crate::pairing::{KeyHandover, KeyRequest};

impl Keyring<'_> {
    /// Every epoch this device holds, of its current identity and of every
    /// earlier one, wrapped for a device restoring a backup. A removed
    /// device still hands over: a thief's revocation must not keep the user
    /// from restoring with keys from a device they hold.
    pub fn hand_over_keys(&self, request: &KeyRequest, name: &str) -> Result<KeyHandover> {
        let recipient = request
            .age_recipient
            .parse::<Recipient>()
            .map_err(|e| anyhow!("the restoring device sent an invalid age recipient: {e}"))?;
        let held = every_held_epoch(self.store, &self.device)?;
        ensure!(
            !held.is_empty(),
            "this device holds no key epoch, so it has nothing to hand over"
        );
        Ok(KeyHandover {
            machine_id: self.own().to_string(),
            name: name.to_string(),
            envelopes: hand_over(&held, &recipient)?,
        })
    }
}