Update Docs

This commit is contained in:
Raven Scott
2026-05-20 20:55:52 -04:00
parent 260dc9da44
commit 1f3f4b24a2
215 changed files with 8565 additions and 2444 deletions
+59 -22
View File
@@ -4,6 +4,10 @@
**Export:** `HyperP2PTimeCapsule`
## Overview
Production experimental (wave 4) module: Hyperswarm discovery + Protomux when `topic` is set.
## Constructor
```js
@@ -12,35 +16,68 @@ const mod = new HyperP2PTimeCapsule(opts)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `topic` | `string` \| `Buffer` | `null` | Hyperswarm topic |
| `keyPair` | `KeyPair` | random | Ed25519 key pair |
| `enableBackgroundTimers` | `boolean` | `false` | Background timers (off in tests) |
| `topic` | varies | null | topic |
| `keyPair` | KeyPair | random Ed25519 | keyPair |
## Methods
| Method | Returns | Throws |
|--------|---------|--------|
| `getStats()` | `object` | — |
| `close()` | `Promise<void>` | — |
| `attest(...)` | `Promise` or value | May throw `Error` on invalid input |
| `canOpen(...)` | `Promise` or value | May throw `Error` on invalid input |
| `getCapsule(...)` | `Promise` or value | May throw `Error` on invalid input |
| `open(...)` | `Promise` or value | May throw `Error` on invalid input |
| `ready(...)` | `Promise` or value | May throw `Error` on invalid input |
| `seal(...)` | `Promise` or value | May throw `Error` on invalid input |
### `seal(payload, opts = {})`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
### `attest(id, voterId = null)`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
### `canOpen(id)`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
### `open(id)`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
### `getCapsule(id)`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
### `ready(—)`
- **Returns:** `Promise`
- **Throws:** — (none documented in method body)
### `getStats(—)`
- **Returns:** `object`
- **Throws:** — (none documented in method body)
### `close(—)`
- **Returns:** `Promise<void>`
- **Throws:** — (none documented in method body)
## Events
| Event | Description |
|-------|-------------|
| `attest` | Emitted on state change |
| `closed` | Emitted on state change |
| `open` | Emitted on state change |
| `seal` | Emitted on state change |
| Event | Payload |
|-------|---------|
| `attest` | voterId, count |
| `closed` | no payload |
| `open` | payload |
| `seal` | payload object |
## Metrics
## getStats()
`getStats()` returns operation counters (`ops`, `errors`, etc.) or `mode: 'local'` for library-only modules.
Returns `{ ...this._stats }` — typically `ops`, `errors`, and module-specific counters (`created`, `relays`, `open`, `peers`, etc.).
Library-only modules may include `mode: 'local'`.
## Errors
Stable message substrings: see [`../_shared/ERROR_CODES.md`](../_shared/ERROR_CODES.md).
## P2P
@@ -52,4 +89,4 @@ When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `time-capsule
npm install && npm test
```
Integration: [`../../real_tests/integration/time-capsule-two-node.js`](../../real_tests/integration/time-capsule-two-node.js)
Integration: [`../../real_tests/integration/time-capsule-two-node.js`](../../real_tests/integration/time-capsule-two-node.js)
+27 -10
View File
@@ -9,20 +9,37 @@ flowchart LR
Mux --> Swarm[Hyperswarm]
```
## Sequence (P2P)
```mermaid
sequenceDiagram
participant App
participant Mod as Module
participant SW as Hyperswarm
participant Peer
App->>Mod: ready(topic)
Mod->>SW: join(topic)
SW->>Peer: connection
Mod->>Peer: gossip / Protomux
Peer-->>Mod: onmessage
Mod-->>App: emit(event)
```
## Wire messages
| type | payload | direction |
|------|---------|-----------|
| `attest` | JSON payload | gossip |
| `open` | JSON payload | gossip |
| `seal` | JSON payload | gossip |
| type | fields | direction | behavior |
|------|--------|-----------|----------|
| `attest` | id, voterId | gossip | Handled in onmessage / gossipSend |
| `open` | payload, type | gossip | Handled in onmessage / gossipSend |
| `seal` | capsule, id, type, voterId | gossip | Handled in onmessage / gossipSend |
## State model
- In-memory `Map` / `Set` structures for hot path
- Optional Hyperbee/Hypercore persistence when `storageDir` or `memoryOnly` is configured
- `close()` tears down swarm, timers, and clears ephemeral state
## Composition
Composes with: `hyper-p2p-pheromone-trail`, `hyper-p2p-whisper-mesh`, `hyper-p2p-entropy-beacon`.
See [`../_shared/WAVE6_NETWORK_STACK.md`](../_shared/WAVE6_NETWORK_STACK.md) when using network-stack modules.
## State
In-memory structures; gossip merges remote updates when `topic` is configured.