@totemsdk/omnia-splice 0.3.5 → 0.4.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/finalize.d.ts +15 -0
- package/dist/cjs/finalize.js +24 -3
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/successor.d.ts +46 -0
- package/dist/cjs/successor.js +72 -3
- package/dist/finalize.d.ts +15 -0
- package/dist/finalize.js +24 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/successor.d.ts +46 -0
- package/dist/successor.js +70 -3
- package/package.json +5 -5
package/dist/cjs/finalize.d.ts
CHANGED
|
@@ -51,12 +51,27 @@ export interface FinalizeSpliceOptions {
|
|
|
51
51
|
chainProvider?: SpliceChainObserver;
|
|
52
52
|
/** Confirmations required before activation. Default 1. */
|
|
53
53
|
confirmations?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Require proof that the successor is an output of this splice transaction
|
|
56
|
+
* before the channel is reported active (OMN-074). Default true: without that
|
|
57
|
+
* binding, any coin with a matching address, token and amount would activate
|
|
58
|
+
* the channel. Set false only when provenance is established elsewhere.
|
|
59
|
+
*/
|
|
60
|
+
requireSuccessorLineage?: boolean;
|
|
54
61
|
/** Successor observation timeout. Default 30s. */
|
|
55
62
|
successorTimeoutMs?: number;
|
|
56
63
|
/** Observation poll interval. Default 1s. */
|
|
57
64
|
successorPollMs?: number;
|
|
58
65
|
/** Durable journal written before broadcast, cleared after confirmation. */
|
|
59
66
|
pendingSpliceStore?: PendingSpliceStore;
|
|
67
|
+
/**
|
|
68
|
+
* Persist the successor channel before the recovery journal is cleared
|
|
69
|
+
* (OMN-076). The host owns the channel store, so it supplies this hook;
|
|
70
|
+
* `finalizeSplice` calls it after the successor is constructed and before
|
|
71
|
+
* `pendingSpliceStore.clear`, so a crash in between leaves a recoverable
|
|
72
|
+
* journal entry rather than an on-chain successor with no local record.
|
|
73
|
+
*/
|
|
74
|
+
persistSuccessor?: (channel: SplicedChannel) => Promise<void> | void;
|
|
60
75
|
/** Serialized Minima CoinProof for every spending input (OMN-053). */
|
|
61
76
|
coinProofs?: Uint8Array[];
|
|
62
77
|
/** Serialized Minima ScriptProof for every spending input (OMN-053). */
|
package/dist/cjs/finalize.js
CHANGED
|
@@ -178,6 +178,14 @@ async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
178
178
|
txHex,
|
|
179
179
|
txpowId: spliceFundingTxId,
|
|
180
180
|
broadcastAt: Date.now(),
|
|
181
|
+
// OMN-075: name the successor this splice must produce. Recovery prefers
|
|
182
|
+
// this over the caller's global observation parameters, so two
|
|
183
|
+
// interrupted splices can never be reconciled against each other.
|
|
184
|
+
expected: {
|
|
185
|
+
address: channel.fundingAddress,
|
|
186
|
+
tokenId: channel.tokenId,
|
|
187
|
+
amount: proposal.params.newTotalValue.toString(),
|
|
188
|
+
},
|
|
181
189
|
};
|
|
182
190
|
await options.pendingSpliceStore?.save(record);
|
|
183
191
|
const result = await options.broadcast(txHex);
|
|
@@ -226,6 +234,11 @@ async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
226
234
|
confirmations: options.confirmations ?? 1,
|
|
227
235
|
timeoutMs: options.successorTimeoutMs ?? 30000,
|
|
228
236
|
pollIntervalMs: options.successorPollMs ?? 1000,
|
|
237
|
+
// OMN-074: the successor must be an output of this splice and the splice
|
|
238
|
+
// must consume the predecessor funding coin.
|
|
239
|
+
spliceTxId: spliceFundingTxId,
|
|
240
|
+
predecessorCoinId: channel.fundingCoinId,
|
|
241
|
+
requireLineage: options.requireSuccessorLineage ?? true,
|
|
229
242
|
});
|
|
230
243
|
if (observed) {
|
|
231
244
|
spliceFundingCoinId = observed.coinId;
|
|
@@ -235,9 +248,6 @@ async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
235
248
|
successorStatus = 'funding_pending';
|
|
236
249
|
}
|
|
237
250
|
}
|
|
238
|
-
if (successorStatus === 'active') {
|
|
239
|
-
await options?.pendingSpliceStore?.clear(proposal.spliceId);
|
|
240
|
-
}
|
|
241
251
|
const splicedChannel = {
|
|
242
252
|
...channel,
|
|
243
253
|
status: successorStatus,
|
|
@@ -264,8 +274,19 @@ async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
264
274
|
],
|
|
265
275
|
updatedAt: Date.now(),
|
|
266
276
|
};
|
|
277
|
+
// OMN-076: persist the successor, retire the predecessor, then complete the
|
|
278
|
+
// journal entry — in that order. Clearing the journal first left a crash
|
|
279
|
+
// window where the successor was on chain, the predecessor was still local,
|
|
280
|
+
// and no recovery record existed. With `persistSuccessor` supplied by the
|
|
281
|
+
// caller (the host owns the channel store), that window is closed.
|
|
282
|
+
if (options?.persistSuccessor) {
|
|
283
|
+
await options.persistSuccessor(splicedChannel);
|
|
284
|
+
}
|
|
267
285
|
// Mark the old (quiesced) channel as spliced — it is now invalidated.
|
|
268
286
|
// Any further operations on `channel` should be rejected by status checks.
|
|
269
287
|
channel.status = 'spliced';
|
|
288
|
+
if (successorStatus === 'active') {
|
|
289
|
+
await options?.pendingSpliceStore?.clear(proposal.spliceId);
|
|
290
|
+
}
|
|
270
291
|
return splicedChannel;
|
|
271
292
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { buildSpliceTx, spliceDraftToMinimaBytes, computeSpliceTxDigest } from '
|
|
|
3
3
|
export { proposeSpliceIn, proposeSpliceOut, acceptSplice, buildSpliceProposal, buildSpliceInProposal, buildSpliceOutProposal, } from './splice.js';
|
|
4
4
|
export type { UnsignedSpliceProposal } from './splice.js';
|
|
5
5
|
export { finalizeSplice, type FinalizeSpliceOptions } from './finalize.js';
|
|
6
|
-
export { observeSpliceSuccessor, recoverInterruptedSplices, type SpliceChainObserver, type SpliceSuccessorOptions, type ObservedSuccessor, type PendingSpliceRecord, type PendingSpliceStore, type SpliceRecoveryResult, } from './successor.js';
|
|
6
|
+
export { observeSpliceSuccessor, recoverInterruptedSplices, SpliceSuccessorLineageError, type SpliceChainObserver, type SpliceSuccessorOptions, type ObservedSuccessor, type PendingSpliceRecord, type PendingSpliceStore, type SpliceRecoveryResult, } from './successor.js';
|
|
7
7
|
export type { SpliceType, SpliceParams, SpliceTxDraft, SpliceTxInput, SpliceTxOutput, SpliceProposal, SpliceAcceptance, QuiescedChannel, SplicedChannel, SpliceLeaseProvider, SpliceSigningIndices, WotsSignature, } from './types.js';
|
|
8
8
|
export { SpliceError, PendingHTLCError, SpliceChannelStatusError, SpliceBalanceConservationError, SpliceSignatureMismatchError, SpliceMissingPartyError, SpliceInsufficientFundsError, } from './errors.js';
|
|
9
9
|
export { createDurableSpliceStore, } from './durable-splice-store.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSpliceCoordination = exports.createDurableSpliceStore = exports.SpliceInsufficientFundsError = exports.SpliceMissingPartyError = exports.SpliceSignatureMismatchError = exports.SpliceBalanceConservationError = exports.SpliceChannelStatusError = exports.PendingHTLCError = exports.SpliceError = exports.recoverInterruptedSplices = exports.observeSpliceSuccessor = exports.finalizeSplice = exports.buildSpliceOutProposal = exports.buildSpliceInProposal = exports.buildSpliceProposal = exports.acceptSplice = exports.proposeSpliceOut = exports.proposeSpliceIn = exports.computeSpliceTxDigest = exports.spliceDraftToMinimaBytes = exports.buildSpliceTx = exports.quiesceChannel = void 0;
|
|
3
|
+
exports.createSpliceCoordination = exports.createDurableSpliceStore = exports.SpliceInsufficientFundsError = exports.SpliceMissingPartyError = exports.SpliceSignatureMismatchError = exports.SpliceBalanceConservationError = exports.SpliceChannelStatusError = exports.PendingHTLCError = exports.SpliceError = exports.SpliceSuccessorLineageError = exports.recoverInterruptedSplices = exports.observeSpliceSuccessor = exports.finalizeSplice = exports.buildSpliceOutProposal = exports.buildSpliceInProposal = exports.buildSpliceProposal = exports.acceptSplice = exports.proposeSpliceOut = exports.proposeSpliceIn = exports.computeSpliceTxDigest = exports.spliceDraftToMinimaBytes = exports.buildSpliceTx = exports.quiesceChannel = void 0;
|
|
4
4
|
var quiesce_js_1 = require("./quiesce.js");
|
|
5
5
|
Object.defineProperty(exports, "quiesceChannel", { enumerable: true, get: function () { return quiesce_js_1.quiesceChannel; } });
|
|
6
6
|
var splice_tx_js_1 = require("./splice-tx.js");
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "finalizeSplice", { enumerable: true, get: functi
|
|
|
19
19
|
var successor_js_1 = require("./successor.js");
|
|
20
20
|
Object.defineProperty(exports, "observeSpliceSuccessor", { enumerable: true, get: function () { return successor_js_1.observeSpliceSuccessor; } });
|
|
21
21
|
Object.defineProperty(exports, "recoverInterruptedSplices", { enumerable: true, get: function () { return successor_js_1.recoverInterruptedSplices; } });
|
|
22
|
+
Object.defineProperty(exports, "SpliceSuccessorLineageError", { enumerable: true, get: function () { return successor_js_1.SpliceSuccessorLineageError; } });
|
|
22
23
|
var errors_js_1 = require("./errors.js");
|
|
23
24
|
Object.defineProperty(exports, "SpliceError", { enumerable: true, get: function () { return errors_js_1.SpliceError; } });
|
|
24
25
|
Object.defineProperty(exports, "PendingHTLCError", { enumerable: true, get: function () { return errors_js_1.PendingHTLCError; } });
|
package/dist/cjs/successor.d.ts
CHANGED
|
@@ -28,6 +28,35 @@ export interface SpliceChainObserver {
|
|
|
28
28
|
getTip(): Promise<{
|
|
29
29
|
block: number;
|
|
30
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Full transaction body by TxPoW id (OMN-074).
|
|
33
|
+
*
|
|
34
|
+
* Optional only so adapters can be upgraded independently. When it is present,
|
|
35
|
+
* successor observation proves the coin is an output of the splice that named
|
|
36
|
+
* it; when it is absent and lineage is required, observation fails closed.
|
|
37
|
+
*/
|
|
38
|
+
getTransaction?(txpowid: string): Promise<{
|
|
39
|
+
txpowid: string;
|
|
40
|
+
inputs: Array<{
|
|
41
|
+
coinId: string;
|
|
42
|
+
address?: string;
|
|
43
|
+
amount?: string;
|
|
44
|
+
tokenId?: string;
|
|
45
|
+
}>;
|
|
46
|
+
outputs: Array<{
|
|
47
|
+
coinId?: string;
|
|
48
|
+
address: string;
|
|
49
|
+
amount: string;
|
|
50
|
+
tokenId?: string;
|
|
51
|
+
}>;
|
|
52
|
+
} | null>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Raised when a successor coin cannot be tied to the splice transaction that is
|
|
56
|
+
* supposed to have created it (OMN-074).
|
|
57
|
+
*/
|
|
58
|
+
export declare class SpliceSuccessorLineageError extends Error {
|
|
59
|
+
constructor(message: string);
|
|
31
60
|
}
|
|
32
61
|
export interface SpliceSuccessorOptions {
|
|
33
62
|
/** Channel funding address the successor must pay to. */
|
|
@@ -46,9 +75,24 @@ export interface SpliceSuccessorOptions {
|
|
|
46
75
|
now?: () => number;
|
|
47
76
|
/** Injected sleep (tests). */
|
|
48
77
|
sleep?: (ms: number) => Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* The splice transaction this successor must belong to (OMN-074). Supplying
|
|
80
|
+
* it turns lineage verification on by default.
|
|
81
|
+
*/
|
|
82
|
+
spliceTxId?: string;
|
|
83
|
+
/** Coin the splice must consume — normally the channel's funding coin. */
|
|
84
|
+
predecessorCoinId?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Require proof that the successor is an output of `spliceTxId`. Defaults to
|
|
87
|
+
* true when `spliceTxId` is supplied. Set false only for a caller that has
|
|
88
|
+
* established provenance some other way.
|
|
89
|
+
*/
|
|
90
|
+
requireLineage?: boolean;
|
|
49
91
|
}
|
|
50
92
|
export interface ObservedSuccessor {
|
|
51
93
|
coinId: string;
|
|
94
|
+
/** True when the coin was proven to be an output of the splice transaction. */
|
|
95
|
+
lineageVerified: boolean;
|
|
52
96
|
confirmations: number;
|
|
53
97
|
confirmed: boolean;
|
|
54
98
|
coin: {
|
|
@@ -97,6 +141,8 @@ export interface SpliceRecoveryResult {
|
|
|
97
141
|
coinId?: string;
|
|
98
142
|
rebroadcast: boolean;
|
|
99
143
|
error?: string;
|
|
144
|
+
/** True when the successor was proven to be an output of the recorded splice. */
|
|
145
|
+
lineageVerified?: boolean;
|
|
100
146
|
}
|
|
101
147
|
/**
|
|
102
148
|
* Reconcile interrupted broadcasts.
|
package/dist/cjs/successor.js
CHANGED
|
@@ -10,10 +10,66 @@
|
|
|
10
10
|
* between broadcast and confirmation can finish or retry safely.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SpliceSuccessorLineageError = void 0;
|
|
13
14
|
exports.observeSpliceSuccessor = observeSpliceSuccessor;
|
|
14
15
|
exports.recoverInterruptedSplices = recoverInterruptedSplices;
|
|
15
16
|
const core_1 = require("@totemsdk/core");
|
|
17
|
+
/**
|
|
18
|
+
* Raised when a successor coin cannot be tied to the splice transaction that is
|
|
19
|
+
* supposed to have created it (OMN-074).
|
|
20
|
+
*/
|
|
21
|
+
class SpliceSuccessorLineageError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'SpliceSuccessorLineageError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SpliceSuccessorLineageError = SpliceSuccessorLineageError;
|
|
16
28
|
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
function sameCoinId(a, b) {
|
|
30
|
+
return a.replace(/^0x/i, '').toLowerCase() === b.replace(/^0x/i, '').toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
function sameText(a, b) {
|
|
33
|
+
return (a ?? '').replace(/^0x/i, '').toLowerCase() === (b ?? '').replace(/^0x/i, '').toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Prove that `coinId` is an output of `spliceTxId` (OMN-074).
|
|
37
|
+
*
|
|
38
|
+
* Address/token/amount matching cannot distinguish "the splice created this
|
|
39
|
+
* coin" from "some other transaction paid a matching coin to the same address".
|
|
40
|
+
* The only trustworthy binding is the transaction body: it must be visible, it
|
|
41
|
+
* must spend the predecessor, and the successor must appear among its outputs.
|
|
42
|
+
*/
|
|
43
|
+
async function assertSuccessorLineage(chain, coinId, options) {
|
|
44
|
+
const required = options.requireLineage ?? options.spliceTxId !== undefined;
|
|
45
|
+
if (!required)
|
|
46
|
+
return;
|
|
47
|
+
if (!options.spliceTxId) {
|
|
48
|
+
throw new SpliceSuccessorLineageError('successor lineage is required but no splice transaction id was supplied');
|
|
49
|
+
}
|
|
50
|
+
if (!chain.getTransaction) {
|
|
51
|
+
throw new SpliceSuccessorLineageError('chain adapter cannot look up transactions; splice successor lineage cannot be proven');
|
|
52
|
+
}
|
|
53
|
+
const transaction = await chain.getTransaction(options.spliceTxId);
|
|
54
|
+
if (!transaction) {
|
|
55
|
+
throw new SpliceSuccessorLineageError(`splice transaction ${options.spliceTxId} is not visible on chain`);
|
|
56
|
+
}
|
|
57
|
+
if (options.predecessorCoinId
|
|
58
|
+
&& !transaction.inputs.some((input) => sameCoinId(input.coinId, options.predecessorCoinId))) {
|
|
59
|
+
throw new SpliceSuccessorLineageError(`splice transaction ${options.spliceTxId} does not spend predecessor ${options.predecessorCoinId}`);
|
|
60
|
+
}
|
|
61
|
+
const matchedByCoinId = transaction.outputs.some((output) => output.coinId !== undefined && sameCoinId(output.coinId, coinId));
|
|
62
|
+
if (matchedByCoinId)
|
|
63
|
+
return;
|
|
64
|
+
// Nodes that omit output coin ids: accept exactly one output that pays the
|
|
65
|
+
// successor address, token and amount. More than one is ambiguous.
|
|
66
|
+
const matches = transaction.outputs.filter((output) => sameText(output.address, options.address)
|
|
67
|
+
&& sameText(output.tokenId, options.tokenId)
|
|
68
|
+
&& (0, core_1.coinAmountAtoms)({ amount: output.amount }) === options.amount);
|
|
69
|
+
if (matches.length !== 1) {
|
|
70
|
+
throw new SpliceSuccessorLineageError(`successor ${coinId} is not an output of splice transaction ${options.spliceTxId}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
17
73
|
/**
|
|
18
74
|
* Find the successor coin at the channel address, excluding the spent old
|
|
19
75
|
* coin. A coin with `spent: true` is never a valid successor. Confirmation
|
|
@@ -47,7 +103,8 @@ async function observeSpliceSuccessor(chain, options) {
|
|
|
47
103
|
const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
|
|
48
104
|
const confirmations = Number.isFinite(created) && created > 0 ? Math.max(0, tip.block - created + 1) : 0;
|
|
49
105
|
if (confirmations >= required) {
|
|
50
|
-
|
|
106
|
+
await assertSuccessorLineage(chain, candidate.coinid, options);
|
|
107
|
+
return { coinId: candidate.coinid, confirmations, confirmed: true, lineageVerified: true, coin: candidate };
|
|
51
108
|
}
|
|
52
109
|
// Found but not deep enough; keep polling until the deadline.
|
|
53
110
|
}
|
|
@@ -56,7 +113,13 @@ async function observeSpliceSuccessor(chain, options) {
|
|
|
56
113
|
const tip = await chain.getTip();
|
|
57
114
|
const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
|
|
58
115
|
const confirmations = Number.isFinite(created) && created > 0 ? Math.max(0, tip.block - created + 1) : 0;
|
|
59
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
coinId: candidate.coinid,
|
|
118
|
+
confirmations,
|
|
119
|
+
confirmed: confirmations >= required,
|
|
120
|
+
lineageVerified: false,
|
|
121
|
+
coin: candidate,
|
|
122
|
+
};
|
|
60
123
|
}
|
|
61
124
|
return null;
|
|
62
125
|
}
|
|
@@ -88,6 +151,11 @@ async function recoverInterruptedSplices(store, chain, observe, broadcast) {
|
|
|
88
151
|
}
|
|
89
152
|
: {}),
|
|
90
153
|
timeoutMs: observe.timeoutMs ?? 0,
|
|
154
|
+
spliceTxId: record.txpowId,
|
|
155
|
+
// Verify automatically when the adapter can, and always when the caller
|
|
156
|
+
// asked for it (OMN-074). Recovery of an already-broadcast splice is the
|
|
157
|
+
// last chance to bind the successor to its transaction.
|
|
158
|
+
requireLineage: observe.requireLineage ?? typeof chain.getTransaction === 'function',
|
|
91
159
|
};
|
|
92
160
|
const observed = await observeSpliceSuccessor(chain, options);
|
|
93
161
|
if (observed) {
|
|
@@ -105,6 +173,7 @@ async function recoverInterruptedSplices(store, chain, observe, broadcast) {
|
|
|
105
173
|
spliceId: record.spliceId,
|
|
106
174
|
status: 'active',
|
|
107
175
|
coinId: observed.coinId,
|
|
176
|
+
lineageVerified: observed.lineageVerified,
|
|
108
177
|
rebroadcast: false,
|
|
109
178
|
});
|
|
110
179
|
continue;
|
|
@@ -126,7 +195,7 @@ async function recoverInterruptedSplices(store, chain, observe, broadcast) {
|
|
|
126
195
|
results.push({
|
|
127
196
|
spliceId: record.spliceId,
|
|
128
197
|
status: 'funding_pending',
|
|
129
|
-
...(observed ? { coinId: observed.coinId } : {}),
|
|
198
|
+
...(observed ? { coinId: observed.coinId, lineageVerified: observed.lineageVerified } : {}),
|
|
130
199
|
rebroadcast: true,
|
|
131
200
|
});
|
|
132
201
|
}
|
package/dist/finalize.d.ts
CHANGED
|
@@ -51,12 +51,27 @@ export interface FinalizeSpliceOptions {
|
|
|
51
51
|
chainProvider?: SpliceChainObserver;
|
|
52
52
|
/** Confirmations required before activation. Default 1. */
|
|
53
53
|
confirmations?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Require proof that the successor is an output of this splice transaction
|
|
56
|
+
* before the channel is reported active (OMN-074). Default true: without that
|
|
57
|
+
* binding, any coin with a matching address, token and amount would activate
|
|
58
|
+
* the channel. Set false only when provenance is established elsewhere.
|
|
59
|
+
*/
|
|
60
|
+
requireSuccessorLineage?: boolean;
|
|
54
61
|
/** Successor observation timeout. Default 30s. */
|
|
55
62
|
successorTimeoutMs?: number;
|
|
56
63
|
/** Observation poll interval. Default 1s. */
|
|
57
64
|
successorPollMs?: number;
|
|
58
65
|
/** Durable journal written before broadcast, cleared after confirmation. */
|
|
59
66
|
pendingSpliceStore?: PendingSpliceStore;
|
|
67
|
+
/**
|
|
68
|
+
* Persist the successor channel before the recovery journal is cleared
|
|
69
|
+
* (OMN-076). The host owns the channel store, so it supplies this hook;
|
|
70
|
+
* `finalizeSplice` calls it after the successor is constructed and before
|
|
71
|
+
* `pendingSpliceStore.clear`, so a crash in between leaves a recoverable
|
|
72
|
+
* journal entry rather than an on-chain successor with no local record.
|
|
73
|
+
*/
|
|
74
|
+
persistSuccessor?: (channel: SplicedChannel) => Promise<void> | void;
|
|
60
75
|
/** Serialized Minima CoinProof for every spending input (OMN-053). */
|
|
61
76
|
coinProofs?: Uint8Array[];
|
|
62
77
|
/** Serialized Minima ScriptProof for every spending input (OMN-053). */
|
package/dist/finalize.js
CHANGED
|
@@ -175,6 +175,14 @@ export async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
175
175
|
txHex,
|
|
176
176
|
txpowId: spliceFundingTxId,
|
|
177
177
|
broadcastAt: Date.now(),
|
|
178
|
+
// OMN-075: name the successor this splice must produce. Recovery prefers
|
|
179
|
+
// this over the caller's global observation parameters, so two
|
|
180
|
+
// interrupted splices can never be reconciled against each other.
|
|
181
|
+
expected: {
|
|
182
|
+
address: channel.fundingAddress,
|
|
183
|
+
tokenId: channel.tokenId,
|
|
184
|
+
amount: proposal.params.newTotalValue.toString(),
|
|
185
|
+
},
|
|
178
186
|
};
|
|
179
187
|
await options.pendingSpliceStore?.save(record);
|
|
180
188
|
const result = await options.broadcast(txHex);
|
|
@@ -223,6 +231,11 @@ export async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
223
231
|
confirmations: options.confirmations ?? 1,
|
|
224
232
|
timeoutMs: options.successorTimeoutMs ?? 30000,
|
|
225
233
|
pollIntervalMs: options.successorPollMs ?? 1000,
|
|
234
|
+
// OMN-074: the successor must be an output of this splice and the splice
|
|
235
|
+
// must consume the predecessor funding coin.
|
|
236
|
+
spliceTxId: spliceFundingTxId,
|
|
237
|
+
predecessorCoinId: channel.fundingCoinId,
|
|
238
|
+
requireLineage: options.requireSuccessorLineage ?? true,
|
|
226
239
|
});
|
|
227
240
|
if (observed) {
|
|
228
241
|
spliceFundingCoinId = observed.coinId;
|
|
@@ -232,9 +245,6 @@ export async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
232
245
|
successorStatus = 'funding_pending';
|
|
233
246
|
}
|
|
234
247
|
}
|
|
235
|
-
if (successorStatus === 'active') {
|
|
236
|
-
await options?.pendingSpliceStore?.clear(proposal.spliceId);
|
|
237
|
-
}
|
|
238
248
|
const splicedChannel = {
|
|
239
249
|
...channel,
|
|
240
250
|
status: successorStatus,
|
|
@@ -261,8 +271,19 @@ export async function finalizeSplice(channel, proposal, acceptance, options) {
|
|
|
261
271
|
],
|
|
262
272
|
updatedAt: Date.now(),
|
|
263
273
|
};
|
|
274
|
+
// OMN-076: persist the successor, retire the predecessor, then complete the
|
|
275
|
+
// journal entry — in that order. Clearing the journal first left a crash
|
|
276
|
+
// window where the successor was on chain, the predecessor was still local,
|
|
277
|
+
// and no recovery record existed. With `persistSuccessor` supplied by the
|
|
278
|
+
// caller (the host owns the channel store), that window is closed.
|
|
279
|
+
if (options?.persistSuccessor) {
|
|
280
|
+
await options.persistSuccessor(splicedChannel);
|
|
281
|
+
}
|
|
264
282
|
// Mark the old (quiesced) channel as spliced — it is now invalidated.
|
|
265
283
|
// Any further operations on `channel` should be rejected by status checks.
|
|
266
284
|
channel.status = 'spliced';
|
|
285
|
+
if (successorStatus === 'active') {
|
|
286
|
+
await options?.pendingSpliceStore?.clear(proposal.spliceId);
|
|
287
|
+
}
|
|
267
288
|
return splicedChannel;
|
|
268
289
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { buildSpliceTx, spliceDraftToMinimaBytes, computeSpliceTxDigest } from '
|
|
|
3
3
|
export { proposeSpliceIn, proposeSpliceOut, acceptSplice, buildSpliceProposal, buildSpliceInProposal, buildSpliceOutProposal, } from './splice.js';
|
|
4
4
|
export type { UnsignedSpliceProposal } from './splice.js';
|
|
5
5
|
export { finalizeSplice, type FinalizeSpliceOptions } from './finalize.js';
|
|
6
|
-
export { observeSpliceSuccessor, recoverInterruptedSplices, type SpliceChainObserver, type SpliceSuccessorOptions, type ObservedSuccessor, type PendingSpliceRecord, type PendingSpliceStore, type SpliceRecoveryResult, } from './successor.js';
|
|
6
|
+
export { observeSpliceSuccessor, recoverInterruptedSplices, SpliceSuccessorLineageError, type SpliceChainObserver, type SpliceSuccessorOptions, type ObservedSuccessor, type PendingSpliceRecord, type PendingSpliceStore, type SpliceRecoveryResult, } from './successor.js';
|
|
7
7
|
export type { SpliceType, SpliceParams, SpliceTxDraft, SpliceTxInput, SpliceTxOutput, SpliceProposal, SpliceAcceptance, QuiescedChannel, SplicedChannel, SpliceLeaseProvider, SpliceSigningIndices, WotsSignature, } from './types.js';
|
|
8
8
|
export { SpliceError, PendingHTLCError, SpliceChannelStatusError, SpliceBalanceConservationError, SpliceSignatureMismatchError, SpliceMissingPartyError, SpliceInsufficientFundsError, } from './errors.js';
|
|
9
9
|
export { createDurableSpliceStore, } from './durable-splice-store.js';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { quiesceChannel } from './quiesce.js';
|
|
|
2
2
|
export { buildSpliceTx, spliceDraftToMinimaBytes, computeSpliceTxDigest } from './splice-tx.js';
|
|
3
3
|
export { proposeSpliceIn, proposeSpliceOut, acceptSplice, buildSpliceProposal, buildSpliceInProposal, buildSpliceOutProposal, } from './splice.js';
|
|
4
4
|
export { finalizeSplice } from './finalize.js';
|
|
5
|
-
export { observeSpliceSuccessor, recoverInterruptedSplices, } from './successor.js';
|
|
5
|
+
export { observeSpliceSuccessor, recoverInterruptedSplices, SpliceSuccessorLineageError, } from './successor.js';
|
|
6
6
|
export { SpliceError, PendingHTLCError, SpliceChannelStatusError, SpliceBalanceConservationError, SpliceSignatureMismatchError, SpliceMissingPartyError, SpliceInsufficientFundsError, } from './errors.js';
|
|
7
7
|
export { createDurableSpliceStore, } from './durable-splice-store.js';
|
|
8
8
|
// RFC-035 B1 — splice peer round-trip over the coordination transport.
|
package/dist/successor.d.ts
CHANGED
|
@@ -28,6 +28,35 @@ export interface SpliceChainObserver {
|
|
|
28
28
|
getTip(): Promise<{
|
|
29
29
|
block: number;
|
|
30
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Full transaction body by TxPoW id (OMN-074).
|
|
33
|
+
*
|
|
34
|
+
* Optional only so adapters can be upgraded independently. When it is present,
|
|
35
|
+
* successor observation proves the coin is an output of the splice that named
|
|
36
|
+
* it; when it is absent and lineage is required, observation fails closed.
|
|
37
|
+
*/
|
|
38
|
+
getTransaction?(txpowid: string): Promise<{
|
|
39
|
+
txpowid: string;
|
|
40
|
+
inputs: Array<{
|
|
41
|
+
coinId: string;
|
|
42
|
+
address?: string;
|
|
43
|
+
amount?: string;
|
|
44
|
+
tokenId?: string;
|
|
45
|
+
}>;
|
|
46
|
+
outputs: Array<{
|
|
47
|
+
coinId?: string;
|
|
48
|
+
address: string;
|
|
49
|
+
amount: string;
|
|
50
|
+
tokenId?: string;
|
|
51
|
+
}>;
|
|
52
|
+
} | null>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Raised when a successor coin cannot be tied to the splice transaction that is
|
|
56
|
+
* supposed to have created it (OMN-074).
|
|
57
|
+
*/
|
|
58
|
+
export declare class SpliceSuccessorLineageError extends Error {
|
|
59
|
+
constructor(message: string);
|
|
31
60
|
}
|
|
32
61
|
export interface SpliceSuccessorOptions {
|
|
33
62
|
/** Channel funding address the successor must pay to. */
|
|
@@ -46,9 +75,24 @@ export interface SpliceSuccessorOptions {
|
|
|
46
75
|
now?: () => number;
|
|
47
76
|
/** Injected sleep (tests). */
|
|
48
77
|
sleep?: (ms: number) => Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* The splice transaction this successor must belong to (OMN-074). Supplying
|
|
80
|
+
* it turns lineage verification on by default.
|
|
81
|
+
*/
|
|
82
|
+
spliceTxId?: string;
|
|
83
|
+
/** Coin the splice must consume — normally the channel's funding coin. */
|
|
84
|
+
predecessorCoinId?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Require proof that the successor is an output of `spliceTxId`. Defaults to
|
|
87
|
+
* true when `spliceTxId` is supplied. Set false only for a caller that has
|
|
88
|
+
* established provenance some other way.
|
|
89
|
+
*/
|
|
90
|
+
requireLineage?: boolean;
|
|
49
91
|
}
|
|
50
92
|
export interface ObservedSuccessor {
|
|
51
93
|
coinId: string;
|
|
94
|
+
/** True when the coin was proven to be an output of the splice transaction. */
|
|
95
|
+
lineageVerified: boolean;
|
|
52
96
|
confirmations: number;
|
|
53
97
|
confirmed: boolean;
|
|
54
98
|
coin: {
|
|
@@ -97,6 +141,8 @@ export interface SpliceRecoveryResult {
|
|
|
97
141
|
coinId?: string;
|
|
98
142
|
rebroadcast: boolean;
|
|
99
143
|
error?: string;
|
|
144
|
+
/** True when the successor was proven to be an output of the recorded splice. */
|
|
145
|
+
lineageVerified?: boolean;
|
|
100
146
|
}
|
|
101
147
|
/**
|
|
102
148
|
* Reconcile interrupted broadcasts.
|
package/dist/successor.js
CHANGED
|
@@ -9,7 +9,61 @@
|
|
|
9
9
|
* between broadcast and confirmation can finish or retry safely.
|
|
10
10
|
*/
|
|
11
11
|
import { coinAmountAtoms } from '@totemsdk/core';
|
|
12
|
+
/**
|
|
13
|
+
* Raised when a successor coin cannot be tied to the splice transaction that is
|
|
14
|
+
* supposed to have created it (OMN-074).
|
|
15
|
+
*/
|
|
16
|
+
export class SpliceSuccessorLineageError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'SpliceSuccessorLineageError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
12
22
|
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
23
|
+
function sameCoinId(a, b) {
|
|
24
|
+
return a.replace(/^0x/i, '').toLowerCase() === b.replace(/^0x/i, '').toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
function sameText(a, b) {
|
|
27
|
+
return (a ?? '').replace(/^0x/i, '').toLowerCase() === (b ?? '').replace(/^0x/i, '').toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prove that `coinId` is an output of `spliceTxId` (OMN-074).
|
|
31
|
+
*
|
|
32
|
+
* Address/token/amount matching cannot distinguish "the splice created this
|
|
33
|
+
* coin" from "some other transaction paid a matching coin to the same address".
|
|
34
|
+
* The only trustworthy binding is the transaction body: it must be visible, it
|
|
35
|
+
* must spend the predecessor, and the successor must appear among its outputs.
|
|
36
|
+
*/
|
|
37
|
+
async function assertSuccessorLineage(chain, coinId, options) {
|
|
38
|
+
const required = options.requireLineage ?? options.spliceTxId !== undefined;
|
|
39
|
+
if (!required)
|
|
40
|
+
return;
|
|
41
|
+
if (!options.spliceTxId) {
|
|
42
|
+
throw new SpliceSuccessorLineageError('successor lineage is required but no splice transaction id was supplied');
|
|
43
|
+
}
|
|
44
|
+
if (!chain.getTransaction) {
|
|
45
|
+
throw new SpliceSuccessorLineageError('chain adapter cannot look up transactions; splice successor lineage cannot be proven');
|
|
46
|
+
}
|
|
47
|
+
const transaction = await chain.getTransaction(options.spliceTxId);
|
|
48
|
+
if (!transaction) {
|
|
49
|
+
throw new SpliceSuccessorLineageError(`splice transaction ${options.spliceTxId} is not visible on chain`);
|
|
50
|
+
}
|
|
51
|
+
if (options.predecessorCoinId
|
|
52
|
+
&& !transaction.inputs.some((input) => sameCoinId(input.coinId, options.predecessorCoinId))) {
|
|
53
|
+
throw new SpliceSuccessorLineageError(`splice transaction ${options.spliceTxId} does not spend predecessor ${options.predecessorCoinId}`);
|
|
54
|
+
}
|
|
55
|
+
const matchedByCoinId = transaction.outputs.some((output) => output.coinId !== undefined && sameCoinId(output.coinId, coinId));
|
|
56
|
+
if (matchedByCoinId)
|
|
57
|
+
return;
|
|
58
|
+
// Nodes that omit output coin ids: accept exactly one output that pays the
|
|
59
|
+
// successor address, token and amount. More than one is ambiguous.
|
|
60
|
+
const matches = transaction.outputs.filter((output) => sameText(output.address, options.address)
|
|
61
|
+
&& sameText(output.tokenId, options.tokenId)
|
|
62
|
+
&& coinAmountAtoms({ amount: output.amount }) === options.amount);
|
|
63
|
+
if (matches.length !== 1) {
|
|
64
|
+
throw new SpliceSuccessorLineageError(`successor ${coinId} is not an output of splice transaction ${options.spliceTxId}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
13
67
|
/**
|
|
14
68
|
* Find the successor coin at the channel address, excluding the spent old
|
|
15
69
|
* coin. A coin with `spent: true` is never a valid successor. Confirmation
|
|
@@ -43,7 +97,8 @@ export async function observeSpliceSuccessor(chain, options) {
|
|
|
43
97
|
const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
|
|
44
98
|
const confirmations = Number.isFinite(created) && created > 0 ? Math.max(0, tip.block - created + 1) : 0;
|
|
45
99
|
if (confirmations >= required) {
|
|
46
|
-
|
|
100
|
+
await assertSuccessorLineage(chain, candidate.coinid, options);
|
|
101
|
+
return { coinId: candidate.coinid, confirmations, confirmed: true, lineageVerified: true, coin: candidate };
|
|
47
102
|
}
|
|
48
103
|
// Found but not deep enough; keep polling until the deadline.
|
|
49
104
|
}
|
|
@@ -52,7 +107,13 @@ export async function observeSpliceSuccessor(chain, options) {
|
|
|
52
107
|
const tip = await chain.getTip();
|
|
53
108
|
const created = candidate.created !== undefined ? Number(candidate.created) : NaN;
|
|
54
109
|
const confirmations = Number.isFinite(created) && created > 0 ? Math.max(0, tip.block - created + 1) : 0;
|
|
55
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
coinId: candidate.coinid,
|
|
112
|
+
confirmations,
|
|
113
|
+
confirmed: confirmations >= required,
|
|
114
|
+
lineageVerified: false,
|
|
115
|
+
coin: candidate,
|
|
116
|
+
};
|
|
56
117
|
}
|
|
57
118
|
return null;
|
|
58
119
|
}
|
|
@@ -84,6 +145,11 @@ export async function recoverInterruptedSplices(store, chain, observe, broadcast
|
|
|
84
145
|
}
|
|
85
146
|
: {}),
|
|
86
147
|
timeoutMs: observe.timeoutMs ?? 0,
|
|
148
|
+
spliceTxId: record.txpowId,
|
|
149
|
+
// Verify automatically when the adapter can, and always when the caller
|
|
150
|
+
// asked for it (OMN-074). Recovery of an already-broadcast splice is the
|
|
151
|
+
// last chance to bind the successor to its transaction.
|
|
152
|
+
requireLineage: observe.requireLineage ?? typeof chain.getTransaction === 'function',
|
|
87
153
|
};
|
|
88
154
|
const observed = await observeSpliceSuccessor(chain, options);
|
|
89
155
|
if (observed) {
|
|
@@ -101,6 +167,7 @@ export async function recoverInterruptedSplices(store, chain, observe, broadcast
|
|
|
101
167
|
spliceId: record.spliceId,
|
|
102
168
|
status: 'active',
|
|
103
169
|
coinId: observed.coinId,
|
|
170
|
+
lineageVerified: observed.lineageVerified,
|
|
104
171
|
rebroadcast: false,
|
|
105
172
|
});
|
|
106
173
|
continue;
|
|
@@ -122,7 +189,7 @@ export async function recoverInterruptedSplices(store, chain, observe, broadcast
|
|
|
122
189
|
results.push({
|
|
123
190
|
spliceId: record.spliceId,
|
|
124
191
|
status: 'funding_pending',
|
|
125
|
-
...(observed ? { coinId: observed.coinId } : {}),
|
|
192
|
+
...(observed ? { coinId: observed.coinId, lineageVerified: observed.lineageVerified } : {}),
|
|
126
193
|
rebroadcast: true,
|
|
127
194
|
});
|
|
128
195
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-splice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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,12 +25,12 @@
|
|
|
25
25
|
"NOTICE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@totemsdk/omnia": "^
|
|
28
|
+
"@totemsdk/omnia": "^4.0.0",
|
|
29
29
|
"@totemsdk/core": "^1.6.1",
|
|
30
|
-
"@totemsdk/tx-builder": "^0.
|
|
31
|
-
"@totemsdk/txpow": "^1.1.1",
|
|
30
|
+
"@totemsdk/tx-builder": "^0.4.0",
|
|
32
31
|
"@totemsdk/wots-lease": "^1.0.3",
|
|
33
|
-
"@totemsdk/
|
|
32
|
+
"@totemsdk/txpow": "^1.1.1",
|
|
33
|
+
"@totemsdk/storage": "^0.2.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^20.0.0",
|