# Keystone Delegation Models

Keystones support both **Inward Delegation** (integrating external keys/challenges) and **Outward Delegation** (externalizing keystone responsibilities to other keystones).

---

## 1. Inward Delegation (Foreign Pools)

*   **Mechanism**: A keystone embeds challenges from an external identity (e.g., Alice's keystone containing Bob's co-signing/SSO pool).
*   **Purpose**: Allows external custodians or identities to co-sign or sign specific claims on behalf of this identity without sharing master secrets.
*   **Lifecycle**: Added/removed via standard pool evolution paths (`addPools` / `removePools`).

---

## 2. Outward Delegation (Delegate Keystones)

*   **Mechanism**: A parent keystone stores a `delegates` map in its `data` object mapping `delegateTjpAddr` to `DelegateKeystoneInfo`.
*   **Purpose**: Authorizes entire independent external keystones (such as a device key or client) to act on behalf of the parent identity.
*   **Lifecycle**: Registered and unregistered via `registerDelegate()` and `unregisterDelegate()`.
*   **Security Policies**:
    *   **Manage Verb Proof**: Mutating the delegates map is rejected during validation unless authorized by a signature proof using the parent's `manage` pool (`KEYSTONE_VERB_MANAGE`).
    *   **Ancestry Verification**: The delegate's `thisAddr` records the exact frame in the parent's timeline where the delegation took place. The validator enforces that `thisAddr` is a valid historical or current frame in the parent's timeline history.
    *   **Soft-Linking**: All relations use soft-links (embedded in `data`) to avoid merging cryptographic dependency graphs of different keystones.

---

## 3. The Multi-Tiered Identity Hierarchy

To balance high cryptographic security with practical daily usability (avoiding the performance and size overhead of constantly evolving a root identity), `ibgib` utilizes a multi-tiered delegation model:

```
           [ Tier 1: Root/Parent Keystone ] (High Security, Cold/Warm)
                         │
                         ▼ (Persistent Delegation via `delegates` map)
             [ Tier 2: Sync/Device Keystone ] (Medium/Low Security, e.g. Laptop/Phone)
                         │
                         ▼ (Ephemeral Delegation via signed Claims / sync verb)
               [ Tier 3: Session Keystone ] (Temporary, Tab-Specific)
```

### Tier 1: Root/Parent Keystone (Primary Identity)
*   **Role**: The primary, slow-evolving root of the user's decentralized identity.
*   **Secrets**: Typically derived from a strong, user-memorized passphrase.
*   **Activity**: Rarely evolved. Only updated to register or unregister client devices.
*   **Delegates**: Formally registers a device's keystone in its `delegates` map.

### Tier 2: Sync/Device Keystone
*   **Role**: A persistent client identity dedicated to a specific user device (e.g. laptop, phone).
*   **Secrets**: Stored locally on the device (e.g. keychains, secure storage).
*   **Activity**: Initiates business-level operations (like synchronization sagas) as the `senderIdentity`.
*   **Authorization**: Verifiers trace this device keystone back to the Root/Parent's registered `delegates` map.

### Tier 3: Session Keystone
*   **Role**: An ephemeral, memory-only keystone created for a single sync session or browser tab.
*   **Secrets**: Transient, thrown away on tab close or session timeout.
*   **Authorization**: Authorized by the Tier 2 Sync/Device Keystone using an ad-hoc signed co-signing/delegation claim. No root evolution required.
*   **Benefit**: Absolute isolation. If a device is compromised, the Root Keystone unregisters the Tier 2 Device delegate, instantly invalidating the device and all associated Tier 3 sessions.
