This commit is contained in:
Raven Scott
2026-05-20 21:02:45 -04:00
parent 1f3f4b24a2
commit 14d0980b4f
734 changed files with 682 additions and 746 deletions
@@ -0,0 +1,114 @@
# API: hyper-p2p-decentralized-oracle
**Protocol:** `hyper-p2p-decentralized-oracle/v1`
**Export:** `HyperP2PDecentralizedOracle`
## Overview
Production oracles module: Hyperswarm discovery + Protomux when `topic` is set.
## Constructor
```js
const mod = new HyperP2PDecentralizedOracle(opts)
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `keyPair` | KeyPair | random Ed25519 | keyPair |
| `storageDir` | `<cwd>/{module}-storage` | `<cwd>/{module}-storage` | Hypercore/Hyperbee storage root |
| `hyperbee` | varies | null // peer dep, mock if not provided | hyperbee |
| `quorumSize` | number | 3 | quorumSize |
| `reportTTL` | number | 1000 * 60 * 5 // 5 min | reportTTL |
| `disputeWindow` | number | 1000 * 60 * 2 // 2 min | disputeWindow |
| `topic` | varies | null | topic |
| `enableBackgroundTimers` | boolean | `false` | Periodic timers (off in tests) |
## Methods
### `ready(—)`
- **Returns:** `Promise`
- **Throws:** — (none documented in method body)
### `submitReport(feedId, data, metadata = {})`
- **Returns:** `Promise`
- **Throws:**
- `Error: Oracle closed`
### `receiveReport(report, peerInfo = {})`
- **Returns:** `Promise`
- **Throws:** — (none documented in method body)
### `query(feedId, opts = {})`
- **Returns:** `Promise`
- **Throws:**
- `Error: Oracle closed`
### `raiseDispute(feedId, reportId, reason = 'inconsistent-data')`
- **Returns:** `Promise`
- **Throws:**
- `Error: Report not found`
### `voteOnDispute(disputeId, feedId, vote, voterKey)`
- **Returns:** `Promise`
- **Throws:** — (none documented in method body)
### `getMetrics(—)`
- **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 | Payload |
|-------|---------|
| `cleanup` | timestamp |
| `close` | no payload |
| `dispute-raised` | payload object |
| `dispute-resolved` | status |
| `error` | err |
| `hyperbee-fallback` | err |
| `persistence-loaded` | no payload |
| `quorum-reached` | aggregate |
| `ready` | no payload |
| `report-received` | peer |
| `report-submitted` | payload object |
| `verification-failed` | reportId, peer |
## getStats()
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
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `hyper-p2p-decentralized-oracle/v1`.
## Testing
```bash
npm install && npm test
```
Integration: [`../../real_tests/integration/decentralized-oracle-two-node.js`](../../../real_tests/integration/decentralized-oracle-two-node.js)
@@ -0,0 +1,44 @@
# Architecture: hyper-p2p-decentralized-oracle
**Category:** Oracles
```mermaid
flowchart LR
App[Application] --> Mod[HyperP2PDecentralizedOracle]
Mod --> Mux[Protomux hyper-p2p-decentralized-oracle/v1]
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 | fields | direction | behavior |
|------|--------|-----------|----------|
| `oracle-update` | feeds, type | gossip | Handled in onmessage / gossipSend |
| `report` | report | 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-attestation-chain`, `hyper-p2p-quorum-pool`.