@totemsdk/omnia-router 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +95 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @totemsdk/omnia-router
2
+
3
+ **Multi-hop payments and cross-token swaps across the channel network.**
4
+
5
+ Builds an in-memory channel graph, finds optimal payment paths using Dijkstra/Bellman-Ford, and executes HTLC-chained multi-hop payments with atomic rollback on failure.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @totemsdk/omnia-router
11
+ ```
12
+
13
+ ## What's inside
14
+
15
+ | Export | What it does |
16
+ |--------|-------------|
17
+ | `createChannelGraph()` | Create an in-memory routing topology |
18
+ | `addChannel(graph, channel)` / `removeChannel(graph, id)` | Maintain the graph |
19
+ | `findRoute(graph, from, to, amount)` | Dijkstra/Bellman-Ford path search over channel capacities and fees |
20
+ | `findCrossTokenRoute(graph, from, to, amount, tokenid)` | Find paths that include token swap intermediaries |
21
+ | `announceSwap(rate)` / `getSwapAnnouncements()` | Peers advertise exchange rates for cross-token routing |
22
+ | `executeMultiHopPayment(route, params)` | HTLC-chained execution; rolls back all HTLCs on any failure |
23
+ | `executeCrossTokenPayment(route, params)` | Multi-hop with a token swap at an intermediate node |
24
+ | `cancelPayment(paymentId)` | Cancel an in-flight payment and release all HTLCs |
25
+ | `buildPaymentRequest(params)` | Structured payment URI |
26
+ | `buildCrossTokenRequest(params)` | Structured cross-token payment URI |
27
+
28
+ ## Usage
29
+
30
+ ### Build a routing graph and find a path
31
+
32
+ ```typescript
33
+ import { createChannelGraph, addChannel, findRoute } from '@totemsdk/omnia-router';
34
+
35
+ const graph = createChannelGraph();
36
+
37
+ // Add all known channels (typically from lookup-node discovery)
38
+ for (const channel of myChannels) {
39
+ addChannel(graph, channel);
40
+ }
41
+
42
+ const route = findRoute(graph, 'MxAAA...', 'MxZZZ...', '25');
43
+ if (!route) {
44
+ throw new Error('No route found');
45
+ }
46
+
47
+ console.log('Hops:', route.hops.map(h => h.channel.id));
48
+ console.log('Total fees:', route.totalFees);
49
+ ```
50
+
51
+ ### Execute a multi-hop payment
52
+
53
+ ```typescript
54
+ import { executeMultiHopPayment } from '@totemsdk/omnia-router';
55
+
56
+ const result = await executeMultiHopPayment(route, {
57
+ signer,
58
+ preimage: crypto.getRandomValues(new Uint8Array(32)),
59
+ });
60
+
61
+ if (result.success) {
62
+ console.log('Payment delivered, preimage:', result.preimage);
63
+ }
64
+ ```
65
+
66
+ ### Cross-token swap payment
67
+
68
+ ```typescript
69
+ import { findCrossTokenRoute, executeCrossTokenPayment } from '@totemsdk/omnia-router';
70
+
71
+ // Find a path that swaps MIN → MYTOKEN at an intermediate node
72
+ const route = findCrossTokenRoute(graph, 'MxAAA...', 'MxZZZ...', '10', 'MYTOKEN_ID');
73
+ await executeCrossTokenPayment(route, { signer });
74
+ ```
75
+
76
+ ### Advertise a swap rate
77
+
78
+ ```typescript
79
+ import { announceSwap } from '@totemsdk/omnia-router';
80
+
81
+ // Tell the network you'll swap MIN ↔ MYTOKEN at a given rate
82
+ await announceSwap({
83
+ fromToken: '0x00',
84
+ toToken: 'MYTOKEN_ID',
85
+ rate: '100', // 1 MYTOKEN = 100 MIN
86
+ maxAmount: '500',
87
+ });
88
+ ```
89
+
90
+ ## See also
91
+
92
+ - [`@totemsdk/omnia`](../omnia) — channel state machine powering each hop
93
+ - [`@totemsdk/omnia-factory`](../omnia-factory) — factory channels included in the routing graph
94
+ - [`@totemsdk/omnia-hyperswarm`](../omnia-hyperswarm) — P2P transport for propagating routes
95
+ - [`@totemsdk/lookup-node`](../lookup-node) — peer discovery for channel graph construction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-router",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Multi-hop payment routing over Omnia channels — single-token and cross-token paths",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,11 +16,11 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@totemsdk/core": "1.0.6"
19
+ "@totemsdk/core": "1.0.9"
20
20
  },
21
21
  "peerDependencies": {
22
- "@totemsdk/omnia": "0.1.1",
23
- "@totemsdk/omnia-hyperswarm": "0.1.1"
22
+ "@totemsdk/omnia": "0.1.3",
23
+ "@totemsdk/omnia-hyperswarm": "0.1.3"
24
24
  },
25
25
  "peerDependenciesMeta": {
26
26
  "@totemsdk/omnia": {