@bsv/overlay 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,11 @@
4
4
 
5
5
  ---
6
6
 
7
- Here, you will find documentation for common example usages of the Overlay Services Engine.
7
+ Here, you will find documentation for common example usages of the Overlay Services Engine. These examples focus on direct `@bsv/overlay` integration. For a ready-to-run HTTP overlay node, use [`@bsv/overlay-express`](https://github.com/bsv-blockchain/overlay-express) and [`overlay-express-examples`](https://github.com/bsv-blockchain/overlay-express-examples).
8
8
 
9
9
  ## Available Examples
10
10
 
11
- - [Getting Started (WIP)](./gs-wip.md) — Introduction and getting started guide
11
+ - [Getting Started](./gs-wip.md) — Introduction and low-level engine setup guide
12
12
 
13
13
  ---
14
14
 
@@ -6,106 +6,114 @@
6
6
 
7
7
  ## Introduction to BSV Overlay Services Engine
8
8
 
9
- The BSV Overlay Services Engine is designed to process transactions and manage data within a blockchain-based system, specifically targeting the Bitcoin SV (BSV) blockchain. It integrates various components such as Topic Managers, Lookup Services, Storage, and Chain Tracker to provide a robust environment for managing transaction data and overlay services.
9
+ The BSV Overlay Services Engine is the low-level runtime for topic managers and lookup services. It validates candidate outputs, stores admitted UTXOs, tracks spends, answers lookup questions, and coordinates synchronization between overlay nodes.
10
+
11
+ If you want to run an HTTP overlay node, start with [`@bsv/overlay-express`](https://github.com/bsv-blockchain/overlay-express). If you want a local or cloud application runtime, use LARS or CARS with the BRC-102 `deployment-info.json` structure. Use `@bsv/overlay` directly when you are building custom infrastructure around the engine.
10
12
 
11
13
  ### Components of the System
12
14
 
13
- 1. **Topic Managers**: Responsible for managing the admittance of transactions related to specific topics.
14
- 2. **Lookup Services**: Handle the lookup of UTXO (Unspent Transaction Output) data for transactions.
15
- 3. **Storage**: Manages persistent data storage, tracking UTXOs and their states within the system.
16
- 4. **Chain Tracker**: Verifies SPV (Simplified Payment Verification) data associated with transactions to ensure their validity.
15
+ 1. **Topic Managers** decide which transaction outputs are admitted for a topic.
16
+ 2. **Lookup Services** index admitted and spent outputs and answer domain-specific lookup questions.
17
+ 3. **Storage** persists admitted outputs, spend state, history, sync state, and interaction timestamps.
18
+ 4. **Chain Tracker** verifies SPV data for transactions unless the engine is configured for script-only validation.
19
+ 5. **Broadcaster** submits accepted transactions to the network.
20
+ 6. **Advertiser** publishes SHIP and SLAP availability records when peer discovery is enabled.
17
21
 
18
22
  ### Setting Up the Engine
19
23
 
20
- Before you can use the engine, you must initialize it with the required components:
21
-
22
- ```ts
23
- import { Engine, KnexStorage } from "@bsv/overlay";
24
- import { HelloTopicManager, HelloLookupService } from 'hello-services';
25
- import { WoChain } from "@bsv/sdk";
26
-
27
- // Initialize components
28
- const managers = {
29
- "exampleTopic": new HelloTopicManager()
30
- };
24
+ Install the current packages:
31
25
 
32
- const lookupServices = {
33
- "exampleLookup": new HelloLookupService()
34
- };
26
+ ```bash
27
+ npm i @bsv/overlay @bsv/sdk knex
28
+ ```
35
29
 
36
- const storage = new KnexStorage();
37
- const chainTracker = new WoChain();
30
+ Create the engine with your concrete implementations:
38
31
 
39
- // Create the engine instance
40
- const engine = new Engine(managers, lookupServices, storage, chainTracker);
32
+ ```ts
33
+ import { Engine, KnexStorage } from '@bsv/overlay'
34
+ import { WhatsOnChain, NodejsHttpClient, ARC } from '@bsv/sdk'
35
+ import knexFactory from 'knex'
36
+
37
+ import { ExampleLookupService } from './services/ExampleLookupService.js'
38
+ import { ExampleTopicManager } from './services/ExampleTopicManager.js'
39
+
40
+ const knex = knexFactory({
41
+ client: 'mysql2',
42
+ connection: process.env.KNEX_URL
43
+ })
44
+
45
+ const engine = new Engine(
46
+ {
47
+ tm_example: new ExampleTopicManager()
48
+ },
49
+ {
50
+ ls_example: new ExampleLookupService()
51
+ },
52
+ new KnexStorage(knex),
53
+ new WhatsOnChain('test', { httpClient: new NodejsHttpClient() }),
54
+ process.env.HOSTING_URL,
55
+ process.env.SHIP_TRACKERS?.split(',') ?? [],
56
+ process.env.SLAP_TRACKERS?.split(',') ?? [],
57
+ new ARC(process.env.ARC_URL ?? 'https://arc.taal.com', {
58
+ apiKey: process.env.ARC_API_KEY
59
+ }),
60
+ undefined,
61
+ {
62
+ tm_example: 'SHIP'
63
+ }
64
+ )
41
65
  ```
42
66
 
67
+ Use the string `'scripts only'` for the chain tracker only when the service intentionally skips SPV validation and relies only on script-level checks.
68
+
43
69
  ### Submitting a Transaction
44
70
 
45
- To submit a transaction for processing by the Overlay Services:
71
+ Submit tagged BEEF bytes with the topics that should evaluate the transaction:
46
72
 
47
73
  ```ts
48
74
  import { Transaction } from '@bsv/sdk'
49
75
 
50
- const tx = new Transaction(/* ... */);
76
+ const tx = new Transaction(/* ... */)
51
77
 
52
- const transaction = {
53
- beef: tx.toBEEF(),
54
- topics: ['exampleTopic']
55
- }
78
+ const steak = await engine.submit({
79
+ beef: tx.toBEEF(),
80
+ topics: ['tm_example']
81
+ })
56
82
 
57
- // Submit transaction
58
- engine.submit(transaction).then(steak => {
59
- console.log("Transaction processed:", steak);
60
- }).catch(error => {
61
- console.error("Error processing transaction:", error);
62
- });
83
+ console.log('Transaction processed:', steak)
63
84
  ```
64
85
 
65
86
  ### Lookup Queries
66
87
 
67
- To perform a lookup query using the engine:
88
+ Ask a lookup service a domain-specific question:
68
89
 
69
90
  ```ts
70
- const question = {
71
- service: 'exampleLookup',
72
- query: {
73
- name: 'Bob'
74
- }
75
- }
76
-
77
- // Perform a lookup
78
- engine.lookup(question).then(answer => {
79
- console.log("Lookup result:", answer);
80
- }).catch(error => {
81
- console.error("Error performing lookup:", error);
82
- });
91
+ const answer = await engine.lookup({
92
+ service: 'ls_example',
93
+ query: {
94
+ identityKey: '03...'
95
+ }
96
+ })
97
+
98
+ console.log('Lookup result:', answer)
83
99
  ```
84
100
 
85
- ### Managing UTXOs
101
+ ### Service Documentation
86
102
 
87
- The system's core functionality involves managing UTXOs:
103
+ Overlay clients and dashboards can retrieve service documentation and metadata directly from the engine:
88
104
 
89
- 1. **Inserting a New UTXO**: Store new UTXO data when transactions are processed.
90
- 2. **Deleting a UTXO**: Remove UTXOs that are no longer needed or have been consumed by newer transactions.
91
- 3. **Tracking UTXO Consumption**: Monitor which transactions consume which UTXOs.
105
+ ```ts
106
+ const topicDocs = await engine.getDocumentationForTopicManger('tm_example')
107
+ const lookupDocs = await engine.getDocumentationForLookupServiceProvider('ls_example')
92
108
 
93
- ### Retrieving Documentation
109
+ const topics = await engine.listTopicManagers()
110
+ const lookupServices = await engine.listLookupServiceProviders()
111
+ ```
94
112
 
95
- To retrieve documentation for specific managers or services:
113
+ ### Deployment Path
96
114
 
97
- ```ts
98
- // For a topic manager
99
- engine.getDocumentationForTopicManger("exampleTopic").then(doc => {
100
- console.log("Documentation for Topic Manager:", doc);
101
- });
102
-
103
- // For a lookup service
104
- engine.getDocumentationForLookupServiceProvider("exampleLookup").then(doc => {
105
- console.log("Documentation for Lookup Service:", doc);
106
- });
107
- ```
115
+ For a public overlay node, wire the engine into HTTP routes using `@bsv/overlay-express` instead of hand-rolling routes. Overlay Express already exposes the standard submit, lookup, sync, health, documentation, and admin surfaces expected by the rest of the BSV overlay ecosystem.
108
116
 
109
117
  ### Conclusion
110
118
 
111
- The BSV Overlay Services Engine provides a powerful toolset for managing transactions and data on the Bitcoin SV blockchain. It's designed to handle complex data structures and ensure the integrity and security of transactions through rigorous validation and management processes. By following this tutorial, developers can effectively integrate and utilize these capabilities within their blockchain applications.
119
+ The BSV Overlay Services Engine is the shared core for overlay validation, indexing, lookup, and synchronization. Keep direct engine usage focused on infrastructure-level integrations, and use Overlay Express, LARS, and CARS for the standard application path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/overlay",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Overlay Services Engine",
6
6
  "main": "dist/cjs/mod.js",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@bsv/gasp": "^1.2.2",
77
- "@bsv/sdk": "^2.0.4",
77
+ "@bsv/sdk": "^2.0.14",
78
78
  "knex": "^3.1.0"
79
79
  }
80
80
  }