# Plan - Remove HOPKey imports and inject hop-crypto

This plan outlines the steps to remove direct `HOPKey` imports from cue modules and instead inject the `hop-crypto` library from the main `HolepunchWorker` down through `BeeWorker` to the individual hyperbee modules.

## Proposed Changes

### 1. Update `HolepunchWorker` (`src/index.js`)
- Update `setHOPCrypto` to pass the `crypto` object down to `this.BeeData`.
- Ensure `BeeData` has a `setHOPCrypto` method.

### 2. Update `HyperBee` (`src/storage/bees.js`)
- Add a `setHOPCrypto` method that:
    - Stores the `crypto` object.
    - Passes it to all initialized modules (e.g., `this.Cues`, `this.Boxes`, `this.Models`, etc.).
- Update module initialization to handle the case where `crypto` might not be set yet, or ensure it's passed if available.

### 3. Update Individual Modules
For each module currently importing `HOPKey` (`learn.js`, `models.js`, `media.js`, `markers.js`, `boxes.js`):
- Remove `import { HOPKey } from '../../hop-key-util.js'`.
- Update the `constructor` to accept an optional `crypto` object, or add a `setHOPCrypto` method.
- Update methods (like `get...History`) to use `this.crypto.range(...)` (or equivalent) instead of `HOPKey.range(...)`.

### 4. Remove `hop-key-util.js` (Optional/Contextual)
- 

## Detailed Steps

1.  **Modify `src/index.js`**:
    ```javascript
    setHOPCrypto = function (crypto) {
      this.crypto = crypto
      if (this.BeeData) this.BeeData.setHOPCrypto(crypto) // Add this
      console.log('hop-crypto in palce HP')
    }
    ```

2.  **Modify `src/storage/bees.js`**:
    - Add `setHOPCrypto` method.
    - It should iterate over `this.PublicLibrary`, `this.PeerLibrary`, `this.Peers`, `this.Results`, `this.Ledger`, `this.Chat`, `this.Clock`, `this.Spaces`, `this.Cues`, `this.Boxes`, `this.Models`, `this.Research`, `this.Markers`, `this.Products`, `this.Media`, `this.Learn`, `this.Lifestrap`.

3.  **Modify Cue Modules**:
    - Example for `src/storage/modules/cues/learn.js`:
    - Remove import.
    - Change `constructor(db)` to `constructor(db, crypto)`.
    - Change `HOPKey.range(lsID, category)` to `this.crypto.range(lsID, category)`.

## Verification Plan
- Check that `hop-crypto` is correctly passed from the entry point to the modules.
- Ensure that `get...History` methods still function correctly by using the injected `crypto` object.
- Verify no `HOPKey` imports remain in the specified files.
