@totemsdk/omnia-host 0.12.0 → 0.13.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.
Files changed (2) hide show
  1. package/dist/api/methods.js +106 -32
  2. package/package.json +5 -5
@@ -1697,21 +1697,7 @@ function createHostMethods(context) {
1697
1697
  });
1698
1698
  if (!route)
1699
1699
  return { success: false, error: 'No route found', errorCode: 'ROUTE_NOT_FOUND' };
1700
- return {
1701
- success: true,
1702
- route: {
1703
- ...route,
1704
- totalFees: route.totalFees.toString(),
1705
- hops: route.hops.map((hop) => ({
1706
- ...hop,
1707
- amount: hop.amount.toString(),
1708
- ...('isSwap' in hop && hop.isSwap ? {
1709
- amountIn: hop.amountIn.toString(),
1710
- amountOut: hop.amountOut.toString(),
1711
- } : {}),
1712
- })),
1713
- },
1714
- };
1700
+ return { success: true, route: serializeWireRoute(route) };
1715
1701
  };
1716
1702
  register('totem_omniaGetRoute', getRoute, 'omnia/getRoute');
1717
1703
  const getSwapRate = () => ({ success: true, announcements: [] });
@@ -2529,28 +2515,115 @@ function createHostMethods(context) {
2529
2515
  };
2530
2516
  register('totem_omniaSpliceIn', splice('in'), 'omnia/spliceIn');
2531
2517
  register('totem_omniaSpliceOut', splice('out'), 'omnia/spliceOut');
2518
+ function parseWireRoute(value) {
2519
+ if (!value || typeof value !== 'object')
2520
+ throw new Error('route must be an object');
2521
+ const raw = value;
2522
+ if (!Array.isArray(raw.hops) || raw.hops.length === 0)
2523
+ throw new Error('route.hops must be a non-empty array');
2524
+ const hops = raw.hops.map((entry, index) => {
2525
+ if (!entry || typeof entry !== 'object')
2526
+ throw new Error(`route.hops[${index}] must be an object`);
2527
+ const hop = entry;
2528
+ const base = {
2529
+ channelId: String(hop.channelId ?? ''),
2530
+ from: String(hop.from ?? ''),
2531
+ to: String(hop.to ?? ''),
2532
+ amount: typeof hop.amount === 'bigint' ? hop.amount : BigInt(String(hop.amount ?? '0')),
2533
+ tokenId: String(hop.tokenId ?? ''),
2534
+ ...(typeof hop.htlcId === 'string' ? { htlcId: hop.htlcId } : {}),
2535
+ };
2536
+ if (hop.isSwap === true) {
2537
+ return {
2538
+ ...base,
2539
+ isSwap: true,
2540
+ tokenIn: String(hop.tokenIn ?? ''),
2541
+ tokenOut: String(hop.tokenOut ?? ''),
2542
+ amountIn: typeof hop.amountIn === 'bigint' ? hop.amountIn : BigInt(String(hop.amountIn ?? '0')),
2543
+ amountOut: typeof hop.amountOut === 'bigint' ? hop.amountOut : BigInt(String(hop.amountOut ?? '0')),
2544
+ rate: String(hop.rate ?? ''),
2545
+ inboundChannelId: String(hop.inboundChannelId ?? ''),
2546
+ outboundChannelId: String(hop.outboundChannelId ?? ''),
2547
+ };
2548
+ }
2549
+ return base;
2550
+ });
2551
+ const route = {
2552
+ hops,
2553
+ totalFees: typeof raw.totalFees === 'bigint' ? raw.totalFees : BigInt(String(raw.totalFees ?? '0')),
2554
+ tokenIn: String(raw.tokenIn ?? ''),
2555
+ tokenOut: String(raw.tokenOut ?? ''),
2556
+ estimatedBlocks: Number(raw.estimatedBlocks ?? 0),
2557
+ };
2558
+ if (hops.some((hop) => hop.isSwap)) {
2559
+ route.swapHops = hops.filter((hop) => hop.isSwap);
2560
+ }
2561
+ return route;
2562
+ }
2563
+ function serializeWireRoute(route) {
2564
+ return {
2565
+ tokenIn: route.tokenIn,
2566
+ tokenOut: route.tokenOut,
2567
+ totalFees: route.totalFees.toString(),
2568
+ estimatedBlocks: route.estimatedBlocks,
2569
+ hops: route.hops.map((hop) => {
2570
+ const base = {
2571
+ channelId: hop.channelId,
2572
+ from: hop.from,
2573
+ to: hop.to,
2574
+ amount: hop.amount.toString(),
2575
+ tokenId: hop.tokenId,
2576
+ ...(hop.htlcId ? { htlcId: hop.htlcId } : {}),
2577
+ };
2578
+ if ('isSwap' in hop && hop.isSwap) {
2579
+ return {
2580
+ ...base,
2581
+ isSwap: true,
2582
+ tokenIn: hop.tokenIn,
2583
+ tokenOut: hop.tokenOut,
2584
+ amountIn: hop.amountIn.toString(),
2585
+ amountOut: hop.amountOut.toString(),
2586
+ rate: hop.rate,
2587
+ inboundChannelId: hop.inboundChannelId,
2588
+ outboundChannelId: hop.outboundChannelId,
2589
+ };
2590
+ }
2591
+ return base;
2592
+ }),
2593
+ };
2594
+ }
2532
2595
  const payMultiHop = async (raw) => {
2533
2596
  const params = paramsObject(raw);
2534
2597
  requireMutationContext(context);
2535
- const route = params.route;
2536
- if (!route || typeof route !== 'object' || !Array.isArray(route.hops)) {
2537
- throw new Error('route with hops is required');
2538
- }
2539
- const paymentRequest = params.paymentRequest;
2540
- if (!paymentRequest || typeof paymentRequest !== 'object') {
2541
- throw new Error('paymentRequest is required');
2542
- }
2543
- const request = paymentRequest;
2598
+ const from = context.localParticipant?.publicKeyDigest;
2599
+ if (!from)
2600
+ throw new Error('Local participant is not configured');
2601
+ const amount = requiredBigInt(params, 'amount');
2602
+ const tokenId = requiredString(params, 'tokenId');
2603
+ const targetTokenId = typeof params.targetTokenId === 'string' ? params.targetTokenId : undefined;
2604
+ const parsedRoute = params.route
2605
+ ? parseWireRoute(params.route)
2606
+ : await context.routing.getRoute({
2607
+ from,
2608
+ to: normalizeRouteNode(requiredString(params, 'toPartyId')),
2609
+ amount,
2610
+ tokenId,
2611
+ ...(targetTokenId ? { targetTokenId } : {}),
2612
+ ...(typeof params.maxHops === 'number' ? { maxHops: params.maxHops } : {}),
2613
+ });
2614
+ if (!parsedRoute)
2615
+ throw new Error('No route found');
2616
+ const isCrossToken = parsedRoute.hops.some((hop) => 'isSwap' in hop && hop.isSwap === true);
2544
2617
  const parsedRequest = {
2545
- hashlock: requiredString(request, 'hashlock'),
2546
- amount: requiredBigInt(request, 'amount'),
2547
- tokenId: requiredString(request, 'tokenId'),
2548
- expiryBlock: requiredBigInt(request, 'expiryBlock'),
2549
- preimage: typeof request.preimage === 'string' ? request.preimage : undefined,
2550
- description: typeof request.description === 'string' ? request.description : undefined,
2618
+ hashlock: requiredString(params, 'hashlock'),
2619
+ amount,
2620
+ tokenId,
2621
+ expiryBlock: requiredBigInt(params, 'expiryBlock'),
2622
+ ...(typeof params.preimage === 'string' ? { preimage: params.preimage } : {}),
2623
+ ...(typeof params.description === 'string' ? { description: params.description } : {}),
2551
2624
  };
2552
- const parsedRoute = route;
2553
- const isCrossToken = 'swapHops' in parsedRoute && Array.isArray(parsedRoute.swapHops) && parsedRoute.swapHops.length > 0;
2625
+ if (!parsedRequest.preimage)
2626
+ throw new Error('preimage is required');
2554
2627
  const ops = {
2555
2628
  addHTLC: (channel, htlcParams, leaseProvider) => (0, omnia_1.addHTLC)(channel, htlcParams, leaseProvider, context.signer),
2556
2629
  fulfillHTLC: (channel, htlcId, preimage, leaseProvider) => (0, omnia_1.fulfillHTLC)(channel, htlcId, preimage, leaseProvider, context.signer),
@@ -2588,6 +2661,7 @@ function createHostMethods(context) {
2588
2661
  success: true,
2589
2662
  preimage: result.preimage,
2590
2663
  settledHops: result.settledHops,
2664
+ route: serializeWireRoute(parsedRoute),
2591
2665
  };
2592
2666
  });
2593
2667
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-host",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Durable Omnia node daemon for channel lifecycle, routing, and control APIs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,14 +29,14 @@
29
29
  "@totemsdk/manifest": "^2.0.2",
30
30
  "@totemsdk/minima-rpc": "^0.4.0",
31
31
  "@totemsdk/omnia": "^2.3.1",
32
+ "@totemsdk/omnia-pool": "^0.5.3",
32
33
  "@totemsdk/omnia-factory": "^0.7.0",
33
34
  "@totemsdk/omnia-router": "^0.4.0",
34
35
  "@totemsdk/omnia-splice": "^0.3.0",
35
- "@totemsdk/omnia-pool": "^0.5.3",
36
- "@totemsdk/p2p-hub": "^0.1.0",
37
- "@totemsdk/storage": "^0.2.0",
38
36
  "@totemsdk/omnia-vtxo": "^0.6.1",
39
- "@totemsdk/wots-lease": "^1.0.1"
37
+ "@totemsdk/wots-lease": "^1.0.1",
38
+ "@totemsdk/storage": "^0.2.1",
39
+ "@totemsdk/p2p-hub": "^0.1.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jest": "^30.0.0",