@totemsdk/omnia-splice 0.3.2 → 0.3.4

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.
@@ -200,9 +200,10 @@ async function finalizeSplice(channel, proposal, acceptance, options) {
200
200
  const params = proposal.params;
201
201
  // Observe the actual successor. The old channel coin is spent by the splice,
202
202
  // so `txid-0` is only a placeholder; the live coin id comes from the funding
203
- // address. Until it is confirmed the channel must not be reported active.
203
+ // address. Until it is confirmed the channel must not be reported active —
204
+ // with no observer we cannot know, so it stays funding_pending (CAN-011).
204
205
  let spliceFundingCoinId = `${spliceFundingTxId}-0`;
205
- let successorStatus = 'active';
206
+ let successorStatus = 'funding_pending';
206
207
  if (options?.chainProvider) {
207
208
  const observed = await (0, successor_js_1.observeSpliceSuccessor)(options.chainProvider, {
208
209
  address: channel.fundingAddress,
@@ -12,6 +12,7 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.observeSpliceSuccessor = observeSpliceSuccessor;
14
14
  exports.recoverInterruptedSplices = recoverInterruptedSplices;
15
+ const core_1 = require("@totemsdk/core");
15
16
  const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
16
17
  /**
17
18
  * Find the successor coin at the channel address, excluding the spent old
@@ -28,10 +29,19 @@ async function observeSpliceSuccessor(chain, options) {
28
29
  const deadline = now() + timeoutMs;
29
30
  for (;;) {
30
31
  const coins = await chain.getCoins({ address: options.address, tokenId: options.tokenId });
31
- const candidate = coins.find((coin) => !coin.spent
32
+ const candidates = coins.filter((coin) => !coin.spent
32
33
  && coin.address.toLowerCase() === options.address.toLowerCase()
33
34
  && coin.tokenid.toLowerCase() === options.tokenId.toLowerCase()
34
- && BigInt(coin.amount) === options.amount);
35
+ && (0, core_1.coinAmountAtoms)(coin) === options.amount);
36
+ // CAN-012: the channel input floats (COINID_ELTOO), so the coin id cannot be
37
+ // predicted from the transaction. Two coins matching the same address, token
38
+ // and amount are indistinguishable here; picking the first would silently
39
+ // adopt a coin the channel does not control.
40
+ if (candidates.length > 1) {
41
+ throw new Error(`Ambiguous splice successor: ${candidates.length} unspent coins match `
42
+ + `${options.address} token ${options.tokenId} amount ${options.amount}`);
43
+ }
44
+ const candidate = candidates[0];
35
45
  if (candidate) {
36
46
  const tip = await chain.getTip();
37
47
  const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
package/dist/finalize.js CHANGED
@@ -197,9 +197,10 @@ export async function finalizeSplice(channel, proposal, acceptance, options) {
197
197
  const params = proposal.params;
198
198
  // Observe the actual successor. The old channel coin is spent by the splice,
199
199
  // so `txid-0` is only a placeholder; the live coin id comes from the funding
200
- // address. Until it is confirmed the channel must not be reported active.
200
+ // address. Until it is confirmed the channel must not be reported active —
201
+ // with no observer we cannot know, so it stays funding_pending (CAN-011).
201
202
  let spliceFundingCoinId = `${spliceFundingTxId}-0`;
202
- let successorStatus = 'active';
203
+ let successorStatus = 'funding_pending';
203
204
  if (options?.chainProvider) {
204
205
  const observed = await observeSpliceSuccessor(options.chainProvider, {
205
206
  address: channel.fundingAddress,
package/dist/successor.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * provides that observation plus a small journal seam so a process that dies
9
9
  * between broadcast and confirmation can finish or retry safely.
10
10
  */
11
+ import { coinAmountAtoms } from '@totemsdk/core';
11
12
  const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
12
13
  /**
13
14
  * Find the successor coin at the channel address, excluding the spent old
@@ -24,10 +25,19 @@ export async function observeSpliceSuccessor(chain, options) {
24
25
  const deadline = now() + timeoutMs;
25
26
  for (;;) {
26
27
  const coins = await chain.getCoins({ address: options.address, tokenId: options.tokenId });
27
- const candidate = coins.find((coin) => !coin.spent
28
+ const candidates = coins.filter((coin) => !coin.spent
28
29
  && coin.address.toLowerCase() === options.address.toLowerCase()
29
30
  && coin.tokenid.toLowerCase() === options.tokenId.toLowerCase()
30
- && BigInt(coin.amount) === options.amount);
31
+ && coinAmountAtoms(coin) === options.amount);
32
+ // CAN-012: the channel input floats (COINID_ELTOO), so the coin id cannot be
33
+ // predicted from the transaction. Two coins matching the same address, token
34
+ // and amount are indistinguishable here; picking the first would silently
35
+ // adopt a coin the channel does not control.
36
+ if (candidates.length > 1) {
37
+ throw new Error(`Ambiguous splice successor: ${candidates.length} unspent coins match `
38
+ + `${options.address} token ${options.tokenId} amount ${options.amount}`);
39
+ }
40
+ const candidate = candidates[0];
31
41
  if (candidate) {
32
42
  const tip = await chain.getTip();
33
43
  const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-splice",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Channel splicing for @totemsdk/omnia — resize Minima eltoo channels without a close+reopen cycle",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -25,11 +25,11 @@
25
25
  "NOTICE"
26
26
  ],
27
27
  "dependencies": {
28
- "@totemsdk/omnia": "^2.4.1",
29
- "@totemsdk/core": "^1.4.2",
28
+ "@totemsdk/omnia": "^3.0.0",
29
+ "@totemsdk/core": "^1.6.0",
30
30
  "@totemsdk/txpow": "^1.1.1",
31
- "@totemsdk/wots-lease": "^1.0.2",
32
- "@totemsdk/tx-builder": "^0.3.1",
31
+ "@totemsdk/tx-builder": "^0.3.4",
32
+ "@totemsdk/wots-lease": "^1.0.3",
33
33
  "@totemsdk/storage": "^0.2.2"
34
34
  },
35
35
  "devDependencies": {
@@ -74,6 +74,7 @@
74
74
  "build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
75
75
  "clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
76
76
  "test": "jest --config ../../tests/jest/omnia-splice.cjs",
77
- "build:wasm": "cd rust && wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node"
77
+ "build:wasm": "cd rust && wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node",
78
+ "test:integration": "node --test ../../tests/qualification/security-train/test/omnia-splice-sequence.test.mjs"
78
79
  }
79
80
  }