@totemsdk/chain-provider 0.3.1 → 0.3.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.
package/README.md CHANGED
@@ -74,7 +74,7 @@ import { LookupClientProvider } from '@totemsdk/chain-provider';
74
74
  import { connectLookupNode } from '@totemsdk/lookup-client';
75
75
 
76
76
  // Connect to your personal lookup node
77
- const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
77
+ const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
78
78
 
79
79
  const provider = new LookupClientProvider(client);
80
80
 
@@ -99,7 +99,7 @@ Fan out across providers: try sovereign first, fall back to hosted on any error.
99
99
  import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
100
100
  import { connectLookupNode } from '@totemsdk/lookup-client';
101
101
 
102
- const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
102
+ const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
103
103
  const hosted = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
104
104
 
105
105
  const provider = new CompositeProvider(
@@ -134,3 +134,8 @@ const provider = new LookupClientProvider(mockClient);
134
134
  - [`@totemsdk/lookup-client`](https://www.npmjs.com/package/@totemsdk/lookup-client) — connect to a personal lookup node over Hyperswarm DHT
135
135
  - [`@totemsdk/node`](https://www.npmjs.com/package/@totemsdk/node) — Node.js `MinimaProvider`
136
136
  - [`@totemsdk/omnia`](https://www.npmjs.com/package/@totemsdk/omnia) — uses `ChainStateProvider` for coin queries
137
+
138
+
139
+ ## Testing
140
+
141
+ Tests live outside the published package in `tests/unit/chain-provider/`. Package `test:*` scripts are repository delegates.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * chain-provider/amount.ts — unit boundary between the node and the SDK.
3
+ *
4
+ * Minima's RPC reports coin amounts as decimal MINIMA (`"0.2"`), while the
5
+ * Omnia channel/HTLC/router maths, the funding drafts and the wire formats all
6
+ * work in raw atoms. `BigInt("0.2")` throws, so a decimal amount reaching that
7
+ * code surfaces as `Cannot convert 0.2 to a BigInt` after the host has already
8
+ * committed to opening a channel.
9
+ *
10
+ * Convert once, at the adapter boundary (`MinimaRpcProvider.getCoins` /
11
+ * `getCoin`), so every chain-truth consumer sees one unit.
12
+ */
13
+ /** Minima has 44 decimal places: 1 MINIMA = 10^44 atoms. */
14
+ export declare const MINIMA_DECIMALS = 44;
15
+ /**
16
+ * Convert a decimal MINIMA/token amount to a raw-integer amount string.
17
+ *
18
+ * Exact by construction: a fraction longer than 44 places is only rejected when
19
+ * it actually carries value, and anything that is not a non-negative decimal is
20
+ * rejected outright. Fail closed — truncating here would silently change the
21
+ * funded amount.
22
+ */
23
+ export declare function amountToAtoms(value: string | bigint | number): string;
package/dist/amount.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * chain-provider/amount.ts — unit boundary between the node and the SDK.
3
+ *
4
+ * Minima's RPC reports coin amounts as decimal MINIMA (`"0.2"`), while the
5
+ * Omnia channel/HTLC/router maths, the funding drafts and the wire formats all
6
+ * work in raw atoms. `BigInt("0.2")` throws, so a decimal amount reaching that
7
+ * code surfaces as `Cannot convert 0.2 to a BigInt` after the host has already
8
+ * committed to opening a channel.
9
+ *
10
+ * Convert once, at the adapter boundary (`MinimaRpcProvider.getCoins` /
11
+ * `getCoin`), so every chain-truth consumer sees one unit.
12
+ */
13
+ /** Minima has 44 decimal places: 1 MINIMA = 10^44 atoms. */
14
+ export const MINIMA_DECIMALS = 44;
15
+ /**
16
+ * Convert a decimal MINIMA/token amount to a raw-integer amount string.
17
+ *
18
+ * Exact by construction: a fraction longer than 44 places is only rejected when
19
+ * it actually carries value, and anything that is not a non-negative decimal is
20
+ * rejected outright. Fail closed — truncating here would silently change the
21
+ * funded amount.
22
+ */
23
+ export function amountToAtoms(value) {
24
+ if (typeof value === 'bigint') {
25
+ if (value < 0n)
26
+ throw new Error(`amount must be non-negative, received ${value}`);
27
+ return value.toString();
28
+ }
29
+ const text = String(value).trim();
30
+ if (!/^\d*(\.\d*)?$/.test(text) || text === '' || text === '.') {
31
+ throw new Error(`amount '${value}' is not a non-negative decimal`);
32
+ }
33
+ const [whole = '0', fraction = ''] = text.split('.');
34
+ const excess = fraction.slice(MINIMA_DECIMALS);
35
+ if (/[1-9]/.test(excess)) {
36
+ throw new Error(`amount '${value}' has more than ${MINIMA_DECIMALS} decimal places and cannot be represented exactly`);
37
+ }
38
+ const padded = (fraction + '0'.repeat(MINIMA_DECIMALS)).slice(0, MINIMA_DECIMALS);
39
+ return (BigInt(whole || '0') * 10n ** BigInt(MINIMA_DECIMALS) + BigInt(padded || '0')).toString();
40
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * chain-provider/amount.ts — unit boundary between the node and the SDK.
3
+ *
4
+ * Minima's RPC reports coin amounts as decimal MINIMA (`"0.2"`), while the
5
+ * Omnia channel/HTLC/router maths, the funding drafts and the wire formats all
6
+ * work in raw atoms. `BigInt("0.2")` throws, so a decimal amount reaching that
7
+ * code surfaces as `Cannot convert 0.2 to a BigInt` after the host has already
8
+ * committed to opening a channel.
9
+ *
10
+ * Convert once, at the adapter boundary (`MinimaRpcProvider.getCoins` /
11
+ * `getCoin`), so every chain-truth consumer sees one unit.
12
+ */
13
+ /** Minima has 44 decimal places: 1 MINIMA = 10^44 atoms. */
14
+ export declare const MINIMA_DECIMALS = 44;
15
+ /**
16
+ * Convert a decimal MINIMA/token amount to a raw-integer amount string.
17
+ *
18
+ * Exact by construction: a fraction longer than 44 places is only rejected when
19
+ * it actually carries value, and anything that is not a non-negative decimal is
20
+ * rejected outright. Fail closed — truncating here would silently change the
21
+ * funded amount.
22
+ */
23
+ export declare function amountToAtoms(value: string | bigint | number): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * chain-provider/amount.ts — unit boundary between the node and the SDK.
4
+ *
5
+ * Minima's RPC reports coin amounts as decimal MINIMA (`"0.2"`), while the
6
+ * Omnia channel/HTLC/router maths, the funding drafts and the wire formats all
7
+ * work in raw atoms. `BigInt("0.2")` throws, so a decimal amount reaching that
8
+ * code surfaces as `Cannot convert 0.2 to a BigInt` after the host has already
9
+ * committed to opening a channel.
10
+ *
11
+ * Convert once, at the adapter boundary (`MinimaRpcProvider.getCoins` /
12
+ * `getCoin`), so every chain-truth consumer sees one unit.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MINIMA_DECIMALS = void 0;
16
+ exports.amountToAtoms = amountToAtoms;
17
+ /** Minima has 44 decimal places: 1 MINIMA = 10^44 atoms. */
18
+ exports.MINIMA_DECIMALS = 44;
19
+ /**
20
+ * Convert a decimal MINIMA/token amount to a raw-integer amount string.
21
+ *
22
+ * Exact by construction: a fraction longer than 44 places is only rejected when
23
+ * it actually carries value, and anything that is not a non-negative decimal is
24
+ * rejected outright. Fail closed — truncating here would silently change the
25
+ * funded amount.
26
+ */
27
+ function amountToAtoms(value) {
28
+ if (typeof value === 'bigint') {
29
+ if (value < 0n)
30
+ throw new Error(`amount must be non-negative, received ${value}`);
31
+ return value.toString();
32
+ }
33
+ const text = String(value).trim();
34
+ if (!/^\d*(\.\d*)?$/.test(text) || text === '' || text === '.') {
35
+ throw new Error(`amount '${value}' is not a non-negative decimal`);
36
+ }
37
+ const [whole = '0', fraction = ''] = text.split('.');
38
+ const excess = fraction.slice(exports.MINIMA_DECIMALS);
39
+ if (/[1-9]/.test(excess)) {
40
+ throw new Error(`amount '${value}' has more than ${exports.MINIMA_DECIMALS} decimal places and cannot be represented exactly`);
41
+ }
42
+ const padded = (fraction + '0'.repeat(exports.MINIMA_DECIMALS)).slice(0, exports.MINIMA_DECIMALS);
43
+ return (BigInt(whole || '0') * 10n ** BigInt(exports.MINIMA_DECIMALS) + BigInt(padded || '0')).toString();
44
+ }
@@ -3,8 +3,11 @@ export { DEPOSIT_ADDRESS_DOMAIN, depositAddressFor, verifyDeposit, verifyDeposit
3
3
  export { HostedProvider } from './providers/hosted.js';
4
4
  export type { HostedProviderConfig } from './providers/hosted.js';
5
5
  export { MinimaRpcProvider } from './providers/minima-rpc.js';
6
+ export { MINIMA_DECIMALS, amountToAtoms } from './amount.js';
6
7
  export { LookupClientProvider } from './providers/lookup-client.js';
7
8
  export type { LookupClientLike } from './providers/lookup-client.js';
8
9
  export { CompositeProvider } from './providers/composite.js';
9
10
  export { resolveChainProvider, parseMinimaRpcUrl, assertConsentedNodeUrl, isSelfHosted, } from './resolve.js';
10
11
  export type { ChainProviderMode, ChainProviderConfig, HostedRelayConfig, ResolveChainProviderOptions, ParsedMinimaRpcUrl, } from './resolve.js';
12
+ export { createMinimaRpcClient } from '@totemsdk/minima-rpc';
13
+ export type { MinimaRpcClient } from '@totemsdk/minima-rpc';
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSelfHosted = exports.assertConsentedNodeUrl = exports.parseMinimaRpcUrl = exports.resolveChainProvider = exports.CompositeProvider = exports.LookupClientProvider = exports.MinimaRpcProvider = exports.HostedProvider = exports.withDepositVerifier = exports.verifyDepositMmrProof = exports.verifyDeposit = exports.depositAddressFor = exports.DEPOSIT_ADDRESS_DOMAIN = void 0;
3
+ exports.createMinimaRpcClient = exports.isSelfHosted = exports.assertConsentedNodeUrl = exports.parseMinimaRpcUrl = exports.resolveChainProvider = exports.CompositeProvider = exports.LookupClientProvider = exports.amountToAtoms = exports.MINIMA_DECIMALS = exports.MinimaRpcProvider = exports.HostedProvider = exports.withDepositVerifier = exports.verifyDepositMmrProof = exports.verifyDeposit = exports.depositAddressFor = exports.DEPOSIT_ADDRESS_DOMAIN = void 0;
4
4
  var verify_deposit_js_1 = require("./verify-deposit.js");
5
5
  Object.defineProperty(exports, "DEPOSIT_ADDRESS_DOMAIN", { enumerable: true, get: function () { return verify_deposit_js_1.DEPOSIT_ADDRESS_DOMAIN; } });
6
6
  Object.defineProperty(exports, "depositAddressFor", { enumerable: true, get: function () { return verify_deposit_js_1.depositAddressFor; } });
@@ -11,6 +11,10 @@ var hosted_js_1 = require("./providers/hosted.js");
11
11
  Object.defineProperty(exports, "HostedProvider", { enumerable: true, get: function () { return hosted_js_1.HostedProvider; } });
12
12
  var minima_rpc_js_1 = require("./providers/minima-rpc.js");
13
13
  Object.defineProperty(exports, "MinimaRpcProvider", { enumerable: true, get: function () { return minima_rpc_js_1.MinimaRpcProvider; } });
14
+ // Unit boundary helpers: the node speaks decimal MINIMA, the SDK speaks atoms.
15
+ var amount_js_1 = require("./amount.js");
16
+ Object.defineProperty(exports, "MINIMA_DECIMALS", { enumerable: true, get: function () { return amount_js_1.MINIMA_DECIMALS; } });
17
+ Object.defineProperty(exports, "amountToAtoms", { enumerable: true, get: function () { return amount_js_1.amountToAtoms; } });
14
18
  var lookup_client_js_1 = require("./providers/lookup-client.js");
15
19
  Object.defineProperty(exports, "LookupClientProvider", { enumerable: true, get: function () { return lookup_client_js_1.LookupClientProvider; } });
16
20
  var composite_js_1 = require("./providers/composite.js");
@@ -20,3 +24,8 @@ Object.defineProperty(exports, "resolveChainProvider", { enumerable: true, get:
20
24
  Object.defineProperty(exports, "parseMinimaRpcUrl", { enumerable: true, get: function () { return resolve_js_1.parseMinimaRpcUrl; } });
21
25
  Object.defineProperty(exports, "assertConsentedNodeUrl", { enumerable: true, get: function () { return resolve_js_1.assertConsentedNodeUrl; } });
22
26
  Object.defineProperty(exports, "isSelfHosted", { enumerable: true, get: function () { return resolve_js_1.isSelfHosted; } });
27
+ // Raw command-level client for transaction assembly (RFC-073). The typed
28
+ // ChainStateProvider covers reads; transaction backends also need the node's
29
+ // command surface (`coinexport`, `txnimport`, `txnpost`, `sendtransaction`).
30
+ var minima_rpc_1 = require("@totemsdk/minima-rpc");
31
+ Object.defineProperty(exports, "createMinimaRpcClient", { enumerable: true, get: function () { return minima_rpc_1.createMinimaRpcClient; } });
@@ -10,7 +10,7 @@
10
10
  * ```ts
11
11
  * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
12
12
  *
13
- * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
13
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
14
14
  * const provider = new LookupClientProvider(client);
15
15
  *
16
16
  * const tip = await provider.getTip();
@@ -23,7 +23,7 @@
23
23
  * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
24
24
  * import { connectLookupNode } from '@totemsdk/lookup-client';
25
25
  *
26
- * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
26
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...', identitySeed: seed });
27
27
  * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
28
28
  *
29
29
  * const provider = new CompositeProvider(
@@ -11,7 +11,7 @@
11
11
  * ```ts
12
12
  * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
13
13
  *
14
- * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
14
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
15
15
  * const provider = new LookupClientProvider(client);
16
16
  *
17
17
  * const tip = await provider.getTip();
@@ -24,7 +24,7 @@
24
24
  * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
25
25
  * import { connectLookupNode } from '@totemsdk/lookup-client';
26
26
  *
27
- * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
27
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...', identitySeed: seed });
28
28
  * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
29
29
  *
30
30
  * const provider = new CompositeProvider(
@@ -1,5 +1,11 @@
1
1
  /**
2
2
  * MinimaRpcProvider — thin wrapper over @totemsdk/minima-rpc.
3
+ *
4
+ * Unit boundary: the node reports `amount` as decimal MINIMA (`"0.2"`), while
5
+ * Omnia channel/HTLC/funding maths is raw atoms. `getCoins` and `getCoin`
6
+ * normalise to atoms so `BigInt(coin.amount)` is always valid downstream.
7
+ * `verifyDeposit` is intentionally left on the node's decimal values: it
8
+ * evaluates the `coinexport` coinproof against a decimal `claimedAmount`.
3
9
  */
4
10
  import type { MinimaRpcClient } from '@totemsdk/minima-rpc';
5
11
  import type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, AddressInfo, ExportedCoin, BroadcastResult, DepositVerifier, VerifyDepositParams, DepositVerification } from '../types.js';
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
2
  /**
3
3
  * MinimaRpcProvider — thin wrapper over @totemsdk/minima-rpc.
4
+ *
5
+ * Unit boundary: the node reports `amount` as decimal MINIMA (`"0.2"`), while
6
+ * Omnia channel/HTLC/funding maths is raw atoms. `getCoins` and `getCoin`
7
+ * normalise to atoms so `BigInt(coin.amount)` is always valid downstream.
8
+ * `verifyDeposit` is intentionally left on the node's decimal values: it
9
+ * evaluates the `coinexport` coinproof against a decimal `claimedAmount`.
4
10
  */
5
11
  Object.defineProperty(exports, "__esModule", { value: true });
6
12
  exports.MinimaRpcProvider = void 0;
13
+ const amount_js_1 = require("../amount.js");
7
14
  const verify_deposit_js_1 = require("../verify-deposit.js");
8
15
  class MinimaRpcProvider {
9
16
  constructor(client) {
@@ -18,7 +25,11 @@ class MinimaRpcProvider {
18
25
  coinid: query.coinId,
19
26
  megammr: query.megammr,
20
27
  });
21
- return result;
28
+ // The node reports decimal MINIMA; Omnia's channel maths is in raw atoms.
29
+ return result.map((coin) => ({
30
+ ...coin,
31
+ amount: (0, amount_js_1.amountToAtoms)(coin.amount),
32
+ }));
22
33
  }
23
34
  async getAddressInfo(address) {
24
35
  const res = await this.client.addressInfo(address);
@@ -40,7 +51,11 @@ class MinimaRpcProvider {
40
51
  const exported = await this.client.coinExport(coinId);
41
52
  const coin = exported?.coinproof?.coin;
42
53
  if (coin) {
43
- return { ...coin, spent: coin.spent === true };
54
+ return {
55
+ ...coin,
56
+ amount: (0, amount_js_1.amountToAtoms)(coin.amount),
57
+ spent: coin.spent === true,
58
+ };
44
59
  }
45
60
  }
46
61
  catch {
package/dist/index.d.ts CHANGED
@@ -3,8 +3,11 @@ export { DEPOSIT_ADDRESS_DOMAIN, depositAddressFor, verifyDeposit, verifyDeposit
3
3
  export { HostedProvider } from './providers/hosted.js';
4
4
  export type { HostedProviderConfig } from './providers/hosted.js';
5
5
  export { MinimaRpcProvider } from './providers/minima-rpc.js';
6
+ export { MINIMA_DECIMALS, amountToAtoms } from './amount.js';
6
7
  export { LookupClientProvider } from './providers/lookup-client.js';
7
8
  export type { LookupClientLike } from './providers/lookup-client.js';
8
9
  export { CompositeProvider } from './providers/composite.js';
9
10
  export { resolveChainProvider, parseMinimaRpcUrl, assertConsentedNodeUrl, isSelfHosted, } from './resolve.js';
10
11
  export type { ChainProviderMode, ChainProviderConfig, HostedRelayConfig, ResolveChainProviderOptions, ParsedMinimaRpcUrl, } from './resolve.js';
12
+ export { createMinimaRpcClient } from '@totemsdk/minima-rpc';
13
+ export type { MinimaRpcClient } from '@totemsdk/minima-rpc';
package/dist/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  export { DEPOSIT_ADDRESS_DOMAIN, depositAddressFor, verifyDeposit, verifyDepositMmrProof, withDepositVerifier, } from './verify-deposit.js';
2
2
  export { HostedProvider } from './providers/hosted.js';
3
3
  export { MinimaRpcProvider } from './providers/minima-rpc.js';
4
+ // Unit boundary helpers: the node speaks decimal MINIMA, the SDK speaks atoms.
5
+ export { MINIMA_DECIMALS, amountToAtoms } from './amount.js';
4
6
  export { LookupClientProvider } from './providers/lookup-client.js';
5
7
  export { CompositeProvider } from './providers/composite.js';
6
8
  export { resolveChainProvider, parseMinimaRpcUrl, assertConsentedNodeUrl, isSelfHosted, } from './resolve.js';
9
+ // Raw command-level client for transaction assembly (RFC-073). The typed
10
+ // ChainStateProvider covers reads; transaction backends also need the node's
11
+ // command surface (`coinexport`, `txnimport`, `txnpost`, `sendtransaction`).
12
+ export { createMinimaRpcClient } from '@totemsdk/minima-rpc';
@@ -10,7 +10,7 @@
10
10
  * ```ts
11
11
  * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
12
12
  *
13
- * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
13
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
14
14
  * const provider = new LookupClientProvider(client);
15
15
  *
16
16
  * const tip = await provider.getTip();
@@ -23,7 +23,7 @@
23
23
  * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
24
24
  * import { connectLookupNode } from '@totemsdk/lookup-client';
25
25
  *
26
- * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
26
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...', identitySeed: seed });
27
27
  * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
28
28
  *
29
29
  * const provider = new CompositeProvider(
@@ -10,7 +10,7 @@
10
10
  * ```ts
11
11
  * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
12
12
  *
13
- * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
13
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...', identitySeed: seed });
14
14
  * const provider = new LookupClientProvider(client);
15
15
  *
16
16
  * const tip = await provider.getTip();
@@ -23,7 +23,7 @@
23
23
  * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
24
24
  * import { connectLookupNode } from '@totemsdk/lookup-client';
25
25
  *
26
- * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
26
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...', identitySeed: seed });
27
27
  * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
28
28
  *
29
29
  * const provider = new CompositeProvider(
@@ -1,5 +1,11 @@
1
1
  /**
2
2
  * MinimaRpcProvider — thin wrapper over @totemsdk/minima-rpc.
3
+ *
4
+ * Unit boundary: the node reports `amount` as decimal MINIMA (`"0.2"`), while
5
+ * Omnia channel/HTLC/funding maths is raw atoms. `getCoins` and `getCoin`
6
+ * normalise to atoms so `BigInt(coin.amount)` is always valid downstream.
7
+ * `verifyDeposit` is intentionally left on the node's decimal values: it
8
+ * evaluates the `coinexport` coinproof against a decimal `claimedAmount`.
3
9
  */
4
10
  import type { MinimaRpcClient } from '@totemsdk/minima-rpc';
5
11
  import type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, AddressInfo, ExportedCoin, BroadcastResult, DepositVerifier, VerifyDepositParams, DepositVerification } from '../types.js';
@@ -1,6 +1,13 @@
1
1
  /**
2
2
  * MinimaRpcProvider — thin wrapper over @totemsdk/minima-rpc.
3
+ *
4
+ * Unit boundary: the node reports `amount` as decimal MINIMA (`"0.2"`), while
5
+ * Omnia channel/HTLC/funding maths is raw atoms. `getCoins` and `getCoin`
6
+ * normalise to atoms so `BigInt(coin.amount)` is always valid downstream.
7
+ * `verifyDeposit` is intentionally left on the node's decimal values: it
8
+ * evaluates the `coinexport` coinproof against a decimal `claimedAmount`.
3
9
  */
10
+ import { amountToAtoms } from '../amount.js';
4
11
  import { depositAddressFor, evaluateDeposit, notFoundResult } from '../verify-deposit.js';
5
12
  export class MinimaRpcProvider {
6
13
  constructor(client) {
@@ -15,7 +22,11 @@ export class MinimaRpcProvider {
15
22
  coinid: query.coinId,
16
23
  megammr: query.megammr,
17
24
  });
18
- return result;
25
+ // The node reports decimal MINIMA; Omnia's channel maths is in raw atoms.
26
+ return result.map((coin) => ({
27
+ ...coin,
28
+ amount: amountToAtoms(coin.amount),
29
+ }));
19
30
  }
20
31
  async getAddressInfo(address) {
21
32
  const res = await this.client.addressInfo(address);
@@ -37,7 +48,11 @@ export class MinimaRpcProvider {
37
48
  const exported = await this.client.coinExport(coinId);
38
49
  const coin = exported?.coinproof?.coin;
39
50
  if (coin) {
40
- return { ...coin, spent: coin.spent === true };
51
+ return {
52
+ ...coin,
53
+ amount: amountToAtoms(coin.amount),
54
+ spent: coin.spent === true,
55
+ };
41
56
  }
42
57
  }
43
58
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/chain-provider",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Unified ChainStateProvider interface for Totem SDK — Hosted, Minima RPC, Composite",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "NOTICE"
24
24
  ],
25
25
  "dependencies": {
26
- "@totemsdk/core": "^1.4.1",
26
+ "@totemsdk/core": "^1.5.0",
27
27
  "@totemsdk/minima-rpc": "^0.5.1"
28
28
  },
29
29
  "devDependencies": {
@@ -68,6 +68,6 @@
68
68
  "scripts": {
69
69
  "build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
70
70
  "clean": "rm -rf dist",
71
- "test": "jest"
71
+ "test": "jest --config ../../tests/jest/chain-provider.cjs"
72
72
  }
73
73
  }