@totemsdk/omnia-router 0.2.0 → 0.3.0
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.
- package/dist/cjs/durable-router-ledger.d.ts +60 -0
- package/dist/cjs/durable-router-ledger.js +88 -0
- package/dist/cjs/execute.d.ts +45 -0
- package/dist/cjs/execute.js +303 -0
- package/dist/cjs/forward.d.ts +50 -0
- package/dist/cjs/forward.js +56 -0
- package/dist/cjs/graph.d.ts +32 -0
- package/dist/cjs/graph.js +102 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pathfind.d.ts +25 -0
- package/dist/cjs/pathfind.js +253 -0
- package/dist/cjs/request.d.ts +19 -0
- package/dist/cjs/request.js +38 -0
- package/dist/cjs/types.d.ts +200 -0
- package/dist/cjs/types.js +10 -0
- package/dist/durable-router-ledger.d.ts +60 -0
- package/dist/durable-router-ledger.js +85 -0
- package/dist/execute.d.ts +9 -1
- package/dist/execute.js +50 -9
- package/dist/forward.d.ts +50 -0
- package/dist/forward.js +53 -0
- package/dist/graph.js +7 -14
- package/dist/index.d.ts +6 -1
- package/dist/index.js +7 -21
- package/dist/pathfind.js +6 -12
- package/dist/request.js +5 -9
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -2
- package/package.json +16 -9
package/dist/index.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "announceSwap", { enumerable: true, get: function () { return graph_js_1.announceSwap; } });
|
|
9
|
-
Object.defineProperty(exports, "getSwapAnnouncements", { enumerable: true, get: function () { return graph_js_1.getSwapAnnouncements; } });
|
|
10
|
-
var pathfind_js_1 = require("./pathfind.js");
|
|
11
|
-
Object.defineProperty(exports, "findRoute", { enumerable: true, get: function () { return pathfind_js_1.findRoute; } });
|
|
12
|
-
Object.defineProperty(exports, "findCrossTokenRoute", { enumerable: true, get: function () { return pathfind_js_1.findCrossTokenRoute; } });
|
|
13
|
-
Object.defineProperty(exports, "applyRate", { enumerable: true, get: function () { return pathfind_js_1.applyRate; } });
|
|
14
|
-
Object.defineProperty(exports, "parseRateToScaled", { enumerable: true, get: function () { return pathfind_js_1.parseRateToScaled; } });
|
|
15
|
-
var request_js_1 = require("./request.js");
|
|
16
|
-
Object.defineProperty(exports, "buildPaymentRequest", { enumerable: true, get: function () { return request_js_1.buildPaymentRequest; } });
|
|
17
|
-
Object.defineProperty(exports, "buildCrossTokenRequest", { enumerable: true, get: function () { return request_js_1.buildCrossTokenRequest; } });
|
|
18
|
-
var execute_js_1 = require("./execute.js");
|
|
19
|
-
Object.defineProperty(exports, "executeMultiHopPayment", { enumerable: true, get: function () { return execute_js_1.executeMultiHopPayment; } });
|
|
20
|
-
Object.defineProperty(exports, "executeCrossTokenPayment", { enumerable: true, get: function () { return execute_js_1.executeCrossTokenPayment; } });
|
|
21
|
-
Object.defineProperty(exports, "cancelPayment", { enumerable: true, get: function () { return execute_js_1.cancelPayment; } });
|
|
1
|
+
export { createChannelGraph, addChannel, removeChannel, announceSwap, getSwapAnnouncements, } from './graph.js';
|
|
2
|
+
export { findRoute, findCrossTokenRoute, applyRate, parseRateToScaled, } from './pathfind.js';
|
|
3
|
+
export { buildPaymentRequest, buildCrossTokenRequest, } from './request.js';
|
|
4
|
+
export { executeMultiHopPayment, executeCrossTokenPayment, cancelPayment, buildRouterFeeProof, computeRouterFeeProofHash, ROUTER_FEE_PROOF_DOMAIN, } from './execute.js';
|
|
5
|
+
// RFC-035 B4 — pluggable forwarding envelopes (cleartext now; onion behind the same seam).
|
|
6
|
+
export { createCleartextRoutingCodec } from './forward.js';
|
|
7
|
+
export { createDurableRouterLedger, } from './durable-router-ledger.js';
|
package/dist/pathfind.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRateToScaled = parseRateToScaled;
|
|
4
|
-
exports.applyRate = applyRate;
|
|
5
|
-
exports.findRoute = findRoute;
|
|
6
|
-
exports.findCrossTokenRoute = findCrossTokenRoute;
|
|
7
|
-
const graph_js_1 = require("./graph.js");
|
|
1
|
+
import { getSwapAnnouncements } from './graph.js';
|
|
8
2
|
const SCALE = 100000000n;
|
|
9
3
|
// ─── Numeric helpers ──────────────────────────────────────────────────────────
|
|
10
4
|
/**
|
|
11
5
|
* Parse a decimal rate string to a scaled bigint (SCALE = 10^8).
|
|
12
6
|
* "0.95" → 95_000_000n, "1.5" → 150_000_000n, "2" → 200_000_000n.
|
|
13
7
|
*/
|
|
14
|
-
function parseRateToScaled(rate) {
|
|
8
|
+
export function parseRateToScaled(rate) {
|
|
15
9
|
const neg = rate.startsWith('-');
|
|
16
10
|
const abs = neg ? rate.slice(1) : rate;
|
|
17
11
|
const dot = abs.indexOf('.');
|
|
@@ -23,7 +17,7 @@ function parseRateToScaled(rate) {
|
|
|
23
17
|
return neg ? -result : result;
|
|
24
18
|
}
|
|
25
19
|
/** Apply rate to amount: amountOut = amountIn × rateScaled / SCALE */
|
|
26
|
-
function applyRate(amountIn, rate) {
|
|
20
|
+
export function applyRate(amountIn, rate) {
|
|
27
21
|
const rateScaled = parseRateToScaled(rate);
|
|
28
22
|
return (amountIn * rateScaled) / SCALE;
|
|
29
23
|
}
|
|
@@ -34,7 +28,7 @@ function applyRate(amountIn, rate) {
|
|
|
34
28
|
*
|
|
35
29
|
* Returns null if no path exists within maxHops.
|
|
36
30
|
*/
|
|
37
|
-
function findRoute(graph, from, to, amount, tokenId, opts) {
|
|
31
|
+
export function findRoute(graph, from, to, amount, tokenId, opts) {
|
|
38
32
|
return _reconstruct(graph, from, to, amount, tokenId, opts?.maxHops ?? 8);
|
|
39
33
|
}
|
|
40
34
|
/** Full path reconstruction (used once Dijkstra confirms a route exists). */
|
|
@@ -98,8 +92,8 @@ function _reconstruct(graph, from, to, amount, tokenId, maxHops) {
|
|
|
98
92
|
* Selection criteria: lowest total fee (including swap fee), then fewest hops,
|
|
99
93
|
* then fewest swap hops.
|
|
100
94
|
*/
|
|
101
|
-
function findCrossTokenRoute(graph, from, to, amountIn, tokenIn, tokenOut, opts) {
|
|
102
|
-
const announcements =
|
|
95
|
+
export function findCrossTokenRoute(graph, from, to, amountIn, tokenIn, tokenOut, opts) {
|
|
96
|
+
const announcements = getSwapAnnouncements(graph, tokenIn, tokenOut);
|
|
103
97
|
if (announcements.length === 0)
|
|
104
98
|
return null;
|
|
105
99
|
let best = null;
|
package/dist/request.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPaymentRequest = buildPaymentRequest;
|
|
4
|
-
exports.buildCrossTokenRequest = buildCrossTokenRequest;
|
|
5
|
-
const core_1 = require("@totemsdk/core");
|
|
1
|
+
import { F, hex } from '@totemsdk/core';
|
|
6
2
|
/**
|
|
7
3
|
* Generate a random 32-byte preimage, compute SHA3-256(preimage) as the
|
|
8
4
|
* hashlock, and return a PaymentRequest that is ready to share.
|
|
@@ -14,11 +10,11 @@ const core_1 = require("@totemsdk/core");
|
|
|
14
10
|
* Compatible with Bare/Pear environments: uses globalThis.crypto.getRandomValues
|
|
15
11
|
* (Web Crypto API, available in Node ≥18, browsers, and Pear/Bare runtimes).
|
|
16
12
|
*/
|
|
17
|
-
function buildPaymentRequest(amount, tokenId, expiryBlock, description) {
|
|
13
|
+
export function buildPaymentRequest(amount, tokenId, expiryBlock, description) {
|
|
18
14
|
const preimageBytes = new Uint8Array(32);
|
|
19
15
|
globalThis.crypto.getRandomValues(preimageBytes);
|
|
20
|
-
const preimage = '0x' +
|
|
21
|
-
const hashlock = '0x' +
|
|
16
|
+
const preimage = '0x' + hex(preimageBytes);
|
|
17
|
+
const hashlock = '0x' + hex(F(preimageBytes));
|
|
22
18
|
return {
|
|
23
19
|
hashlock,
|
|
24
20
|
preimage,
|
|
@@ -33,6 +29,6 @@ function buildPaymentRequest(amount, tokenId, expiryBlock, description) {
|
|
|
33
29
|
* to receive. The API is identical to buildPaymentRequest — the distinction
|
|
34
30
|
* is conceptual (recipient generates hashlock; sender sources liquidity).
|
|
35
31
|
*/
|
|
36
|
-
function buildCrossTokenRequest(amountOut, tokenOut, expiryBlock, description) {
|
|
32
|
+
export function buildCrossTokenRequest(amountOut, tokenOut, expiryBlock, description) {
|
|
37
33
|
return buildPaymentRequest(amountOut, tokenOut, expiryBlock, description);
|
|
38
34
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -170,6 +170,20 @@ export interface PaymentRequest {
|
|
|
170
170
|
expiryBlock: bigint;
|
|
171
171
|
description?: string;
|
|
172
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* A verifiable fee-provenance record for a settled hop (#29): the artifact a
|
|
175
|
+
* pool's `recordPoolFee` earn-proof consumes. Binds channel + HTLC + recipient
|
|
176
|
+
* + amount so a fee record traces to a real fulfilled payment.
|
|
177
|
+
*/
|
|
178
|
+
export interface RouterFeeProof {
|
|
179
|
+
channelId: string;
|
|
180
|
+
htlcId: string;
|
|
181
|
+
recipientPublicKeyDigest: string;
|
|
182
|
+
amount: bigint;
|
|
183
|
+
tokenId: string;
|
|
184
|
+
settledAt: number;
|
|
185
|
+
proofHash: string;
|
|
186
|
+
}
|
|
173
187
|
export interface PaymentResult {
|
|
174
188
|
success: boolean;
|
|
175
189
|
/** Hex preimage revealed during settlement (present on success) */
|
|
@@ -177,6 +191,8 @@ export interface PaymentResult {
|
|
|
177
191
|
error?: string;
|
|
178
192
|
/** htlcIds that were successfully settled */
|
|
179
193
|
settledHops: string[];
|
|
194
|
+
/** Verifiable fee proofs for each settled hop — feeds recordPoolFee earn-proofs. */
|
|
195
|
+
feeProofs?: RouterFeeProof[];
|
|
180
196
|
}
|
|
181
197
|
export interface RouteOptions {
|
|
182
198
|
/** Maximum number of hops (default: 8) */
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @totemsdk/omnia-router — public types
|
|
4
3
|
*
|
|
@@ -7,4 +6,4 @@
|
|
|
7
6
|
* has no hard runtime dependency on @totemsdk/omnia — callers pass the
|
|
8
7
|
* real objects (structural typing ensures compatibility).
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Multi-hop payment routing over Omnia channels — single-token and cross-token paths",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/cjs/index.d.ts",
|
|
15
|
+
"default": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
},
|
|
14
19
|
"files": [
|
|
@@ -17,10 +22,11 @@
|
|
|
17
22
|
"LICENSE"
|
|
18
23
|
],
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@totemsdk/core": "^1.2.
|
|
25
|
+
"@totemsdk/core": "^1.2.11",
|
|
26
|
+
"@totemsdk/storage": "^0.1.0"
|
|
21
27
|
},
|
|
22
28
|
"peerDependencies": {
|
|
23
|
-
"@totemsdk/omnia": "^
|
|
29
|
+
"@totemsdk/omnia": "^2.0.0"
|
|
24
30
|
},
|
|
25
31
|
"peerDependenciesMeta": {
|
|
26
32
|
"@totemsdk/omnia": {
|
|
@@ -68,8 +74,9 @@
|
|
|
68
74
|
"htlc",
|
|
69
75
|
"dijkstra"
|
|
70
76
|
],
|
|
77
|
+
"type": "module",
|
|
71
78
|
"scripts": {
|
|
72
|
-
"build": "tsc",
|
|
79
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
73
80
|
"build:go": "cd go && go build -o ../bin/omnia-router ./cmd/omnia-router",
|
|
74
81
|
"clean": "rm -rf dist bin",
|
|
75
82
|
"test": "jest"
|