@totemsdk/omnia-splice 0.2.1 → 0.3.1
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/LICENSE +202 -21
- package/NOTICE +60 -0
- package/dist/cjs/coordination.d.ts +55 -0
- package/dist/cjs/coordination.js +137 -0
- package/dist/cjs/durable-splice-store.d.ts +58 -0
- package/dist/cjs/durable-splice-store.js +117 -0
- package/dist/cjs/errors.d.ts +22 -0
- package/dist/cjs/errors.js +54 -0
- package/dist/cjs/finalize.d.ts +92 -0
- package/dist/cjs/finalize.js +222 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/quiesce.d.ts +57 -0
- package/dist/cjs/quiesce.js +67 -0
- package/dist/cjs/splice-tx.d.ts +38 -0
- package/dist/cjs/splice-tx.js +210 -0
- package/dist/cjs/splice.d.ts +95 -0
- package/dist/cjs/splice.js +377 -0
- package/dist/cjs/types.d.ts +130 -0
- package/dist/cjs/types.js +2 -0
- package/dist/coordination.d.ts +55 -0
- package/dist/coordination.js +134 -0
- package/dist/durable-splice-store.js +7 -10
- package/dist/errors.js +7 -17
- package/dist/finalize.d.ts +1 -1
- package/dist/finalize.js +26 -33
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -25
- package/dist/quiesce.js +7 -10
- package/dist/splice-tx.js +13 -18
- package/dist/splice.d.ts +25 -1
- package/dist/splice.js +92 -26
- package/dist/types.js +1 -2
- package/package.json +22 -15
- package/rust/pkg/omnia_splice_wasm_bg.wasm +0 -0
- package/rust/pkg/package.json +2 -2
- package/rust/pkg-node/omnia_splice_wasm_bg.wasm +0 -0
- package/rust/pkg-node/package.json +2 -2
package/dist/quiesce.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.quiesceChannel = quiesceChannel;
|
|
4
|
-
const omnia_1 = require("@totemsdk/omnia");
|
|
5
|
-
const errors_js_1 = require("./errors.js");
|
|
1
|
+
import { updateState } from '@totemsdk/omnia';
|
|
2
|
+
import { PendingHTLCError, SpliceChannelStatusError } from './errors.js';
|
|
6
3
|
/**
|
|
7
4
|
* Quiesce a channel before splicing.
|
|
8
5
|
*
|
|
@@ -35,9 +32,9 @@ const errors_js_1 = require("./errors.js");
|
|
|
35
32
|
* @throws {SpliceChannelStatusError} If channel is not active.
|
|
36
33
|
* @throws {PendingHTLCError} If HTLCs remain pending after resolution.
|
|
37
34
|
*/
|
|
38
|
-
async function quiesceChannel(channel, leaseProvider, options) {
|
|
35
|
+
export async function quiesceChannel(channel, leaseProvider, options) {
|
|
39
36
|
if (channel.status !== 'active') {
|
|
40
|
-
throw new
|
|
37
|
+
throw new SpliceChannelStatusError('active', channel.status);
|
|
41
38
|
}
|
|
42
39
|
const pendingHTLCs = channel.pendingHTLCs.filter(h => h.status === 'pending');
|
|
43
40
|
if (pendingHTLCs.length > 0) {
|
|
@@ -45,14 +42,14 @@ async function quiesceChannel(channel, leaseProvider, options) {
|
|
|
45
42
|
await options.awaitResolution(pendingHTLCs);
|
|
46
43
|
const stillPending = channel.pendingHTLCs.filter(h => h.status === 'pending').length;
|
|
47
44
|
if (stillPending > 0) {
|
|
48
|
-
throw new
|
|
45
|
+
throw new PendingHTLCError(stillPending);
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
else {
|
|
52
|
-
throw new
|
|
49
|
+
throw new PendingHTLCError(pendingHTLCs.length);
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
|
-
const { channel: updatedChannel, signedState, error } = await
|
|
52
|
+
const { channel: updatedChannel, signedState, error } = await updateState(channel, { newBalances: channel.balances }, leaseProvider.wotsLease, leaseProvider.signer);
|
|
56
53
|
if (error) {
|
|
57
54
|
throw new Error(`quiesceChannel: updateState blocked — ${error}. Splice cannot proceed.`);
|
|
58
55
|
}
|
package/dist/splice-tx.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.computeSpliceTxDigest = computeSpliceTxDigest;
|
|
6
|
-
const core_1 = require("@totemsdk/core");
|
|
7
|
-
const core_2 = require("@totemsdk/core");
|
|
8
|
-
const omnia_1 = require("@totemsdk/omnia");
|
|
9
|
-
const errors_js_1 = require("./errors.js");
|
|
1
|
+
import { sha3_256 } from '@totemsdk/core';
|
|
2
|
+
import { serializeTransaction, } from '@totemsdk/core';
|
|
3
|
+
import { COINID_ELTOO } from '@totemsdk/omnia';
|
|
4
|
+
import { SpliceBalanceConservationError, SpliceInsufficientFundsError } from './errors.js';
|
|
10
5
|
const STATE_SETTLEMENT_PORT = 100;
|
|
11
6
|
const STATE_SEQUENCE_PORT = 101;
|
|
12
7
|
/**
|
|
@@ -31,17 +26,17 @@ const STATE_SEQUENCE_PORT = 101;
|
|
|
31
26
|
* @throws {SpliceBalanceConservationError} If output amounts do not sum to newTotalValue.
|
|
32
27
|
* @throws {SpliceInsufficientFundsError} If splice-out exceeds channel holdings.
|
|
33
28
|
*/
|
|
34
|
-
function buildSpliceTx(channel, params) {
|
|
29
|
+
export function buildSpliceTx(channel, params) {
|
|
35
30
|
const tokenId = channel.tokenId ?? '0x00';
|
|
36
31
|
if (params.type === 'splice_out') {
|
|
37
32
|
const withdrawAmount = params.withdrawAmount ?? 0n;
|
|
38
33
|
const extraSum = (params.extraOutputs ?? []).reduce((a, o) => a + o.amount, 0n);
|
|
39
34
|
const totalOutflow = withdrawAmount + extraSum;
|
|
40
35
|
if (totalOutflow > channel.totalValue) {
|
|
41
|
-
throw new
|
|
36
|
+
throw new SpliceInsufficientFundsError(channel.totalValue, totalOutflow);
|
|
42
37
|
}
|
|
43
38
|
if (params.newTotalValue < 0n) {
|
|
44
|
-
throw new
|
|
39
|
+
throw new SpliceInsufficientFundsError(channel.totalValue, totalOutflow);
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
const balanceSum = Object.values(params.newBalances).reduce((a, b) => a + b, 0n);
|
|
@@ -50,11 +45,11 @@ function buildSpliceTx(channel, params) {
|
|
|
50
45
|
// Withdrawals and extra outputs are separate outputs, already factored out by the
|
|
51
46
|
// caller when computing `newTotalValue`.
|
|
52
47
|
if (balanceSum !== params.newTotalValue) {
|
|
53
|
-
throw new
|
|
48
|
+
throw new SpliceBalanceConservationError(params.newTotalValue, balanceSum);
|
|
54
49
|
}
|
|
55
50
|
const inputs = [
|
|
56
51
|
{
|
|
57
|
-
coinId:
|
|
52
|
+
coinId: COINID_ELTOO,
|
|
58
53
|
address: channel.fundingAddress,
|
|
59
54
|
amount: channel.totalValue,
|
|
60
55
|
tokenId,
|
|
@@ -112,7 +107,7 @@ function buildSpliceTx(channel, params) {
|
|
|
112
107
|
* suitable for WOTS signing. Both parties sign the same bytes independently;
|
|
113
108
|
* the final splice TX assembles both signatures into the witness.
|
|
114
109
|
*/
|
|
115
|
-
function spliceDraftToMinimaBytes(draft) {
|
|
110
|
+
export function spliceDraftToMinimaBytes(draft) {
|
|
116
111
|
const toHex = (b) => Buffer.from(b).toString('hex');
|
|
117
112
|
const svToJson = (port, value, type) => {
|
|
118
113
|
let data;
|
|
@@ -169,13 +164,13 @@ function spliceDraftToMinimaBytes(draft) {
|
|
|
169
164
|
svToJson(STATE_SETTLEMENT_PORT, false, 'bool'),
|
|
170
165
|
svToJson(STATE_SEQUENCE_PORT, 0n, 'number'),
|
|
171
166
|
];
|
|
172
|
-
return
|
|
167
|
+
return serializeTransaction(JSON.stringify({ inputs, outputs, state, linkhash: '0x00' }));
|
|
173
168
|
}
|
|
174
169
|
/**
|
|
175
170
|
* Compute a 32-byte digest over the splice TX draft for WOTS signing.
|
|
176
171
|
* This is the canonical message both parties sign to authorize the splice.
|
|
177
172
|
*/
|
|
178
|
-
function computeSpliceTxDigest(draft) {
|
|
173
|
+
export function computeSpliceTxDigest(draft) {
|
|
179
174
|
const canonical = JSON.stringify({
|
|
180
175
|
channelId: draft.channelId,
|
|
181
176
|
inputs: draft.inputs.map(i => ({
|
|
@@ -206,5 +201,5 @@ function computeSpliceTxDigest(draft) {
|
|
|
206
201
|
.map(([k, v]) => [k, v.toString()]),
|
|
207
202
|
},
|
|
208
203
|
});
|
|
209
|
-
return
|
|
204
|
+
return sha3_256(new TextEncoder().encode(canonical));
|
|
210
205
|
}
|
package/dist/splice.d.ts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import type { OmniaChannel } from '@totemsdk/omnia';
|
|
2
|
-
import type { SpliceProposal, SpliceAcceptance, SpliceLeaseProvider, QuiescedChannel } from './types.js';
|
|
2
|
+
import type { SpliceParams, SpliceProposal, SpliceAcceptance, SpliceLeaseProvider, QuiescedChannel } from './types.js';
|
|
3
|
+
/** A splice proposal whose proposer signature has not been applied yet. */
|
|
4
|
+
export interface UnsignedSpliceProposal {
|
|
5
|
+
spliceId: string;
|
|
6
|
+
channelId: string;
|
|
7
|
+
params: SpliceParams;
|
|
8
|
+
spliceTxHex: string;
|
|
9
|
+
spliceTxDraft: SpliceProposal['spliceTxDraft'];
|
|
10
|
+
proposerPublicKeyDigest: string;
|
|
11
|
+
digest: Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the deterministic splice draft/digest without signing. Used by the
|
|
15
|
+
* wallet/coordinator flow: the caller signs `digest` and attaches the
|
|
16
|
+
* signature before finalization.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildSpliceProposal(channel: OmniaChannel | QuiescedChannel, params: SpliceParams, proposerPublicKeyDigest: string): UnsignedSpliceProposal;
|
|
19
|
+
/** Build an unsigned splice-in proposal (see `buildSpliceProposal`). */
|
|
20
|
+
export declare function buildSpliceInProposal(channel: OmniaChannel | QuiescedChannel, additionalCoinId: string, additionalAmount: bigint, proposerPublicKeyDigest: string, newBalances?: Record<string, bigint>): UnsignedSpliceProposal;
|
|
21
|
+
/** Build an unsigned splice-out proposal (see `buildSpliceProposal`). */
|
|
22
|
+
export declare function buildSpliceOutProposal(channel: OmniaChannel | QuiescedChannel, withdrawAmount: bigint, withdrawAddress: string, proposerPublicKeyDigest: string, newBalances?: Record<string, bigint>, extraOutputs?: Array<{
|
|
23
|
+
address: string;
|
|
24
|
+
amount: bigint;
|
|
25
|
+
tokenId?: string;
|
|
26
|
+
}>): UnsignedSpliceProposal;
|
|
3
27
|
/**
|
|
4
28
|
* Initiating party proposes a splice-in: add external funds to the channel.
|
|
5
29
|
*
|
package/dist/splice.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.proposeSpliceIn = proposeSpliceIn;
|
|
4
|
-
exports.proposeSpliceOut = proposeSpliceOut;
|
|
5
|
-
exports.acceptSplice = acceptSplice;
|
|
6
|
-
const splice_tx_js_1 = require("./splice-tx.js");
|
|
7
|
-
const errors_js_1 = require("./errors.js");
|
|
1
|
+
import { buildSpliceTx, computeSpliceTxDigest, spliceDraftToMinimaBytes } from './splice-tx.js';
|
|
2
|
+
import { PendingHTLCError, SpliceChannelStatusError, SpliceMissingPartyError, } from './errors.js';
|
|
8
3
|
/**
|
|
9
4
|
* Scale existing balances proportionally to a new total, preserving relative
|
|
10
5
|
* ratios. The last party absorbs rounding so that sum(result) === newTotal
|
|
@@ -51,11 +46,11 @@ function generateSpliceId() {
|
|
|
51
46
|
*/
|
|
52
47
|
function validateChannelQuiesced(channel) {
|
|
53
48
|
if (channel.status !== 'quiesced') {
|
|
54
|
-
throw new
|
|
49
|
+
throw new SpliceChannelStatusError('quiesced', channel.status);
|
|
55
50
|
}
|
|
56
51
|
const pending = channel.pendingHTLCs.filter(h => h.status === 'pending').length;
|
|
57
52
|
if (pending > 0) {
|
|
58
|
-
throw new
|
|
53
|
+
throw new PendingHTLCError(pending);
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
/**
|
|
@@ -96,14 +91,85 @@ function validateProposalParams(channel, params) {
|
|
|
96
91
|
* to diverge from the actual on-chain TX outputs.
|
|
97
92
|
*/
|
|
98
93
|
function bindDraftToParams(channel, proposal) {
|
|
99
|
-
const recomputed =
|
|
100
|
-
const expected =
|
|
101
|
-
const actual =
|
|
94
|
+
const recomputed = buildSpliceTx(channel, proposal.params);
|
|
95
|
+
const expected = computeSpliceTxDigest(recomputed);
|
|
96
|
+
const actual = computeSpliceTxDigest(proposal.spliceTxDraft);
|
|
102
97
|
if (!expected.every((b, i) => b === actual[i])) {
|
|
103
98
|
throw new Error('Proposal spliceTxDraft is inconsistent with proposal.params — ' +
|
|
104
99
|
'the TX draft may have been tampered with');
|
|
105
100
|
}
|
|
106
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Build the deterministic splice draft/digest without signing. Used by the
|
|
104
|
+
* wallet/coordinator flow: the caller signs `digest` and attaches the
|
|
105
|
+
* signature before finalization.
|
|
106
|
+
*/
|
|
107
|
+
export function buildSpliceProposal(channel, params, proposerPublicKeyDigest) {
|
|
108
|
+
validateChannelQuiesced(channel);
|
|
109
|
+
validateProposalParams(channel, params);
|
|
110
|
+
const proposerInChannel = channel.parties.find(p => p.publicKeyDigest === proposerPublicKeyDigest);
|
|
111
|
+
if (!proposerInChannel)
|
|
112
|
+
throw new SpliceMissingPartyError(proposerPublicKeyDigest);
|
|
113
|
+
const draft = buildSpliceTx(channel, params);
|
|
114
|
+
return {
|
|
115
|
+
spliceId: generateSpliceId(),
|
|
116
|
+
channelId: channel.channelId,
|
|
117
|
+
params,
|
|
118
|
+
spliceTxHex: Buffer.from(spliceDraftToMinimaBytes(draft)).toString('hex'),
|
|
119
|
+
spliceTxDraft: draft,
|
|
120
|
+
proposerPublicKeyDigest,
|
|
121
|
+
digest: computeSpliceTxDigest(draft),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Build an unsigned splice-in proposal (see `buildSpliceProposal`). */
|
|
125
|
+
export function buildSpliceInProposal(channel, additionalCoinId, additionalAmount, proposerPublicKeyDigest, newBalances) {
|
|
126
|
+
validateChannelQuiesced(channel);
|
|
127
|
+
const newTotal = channel.totalValue + additionalAmount;
|
|
128
|
+
const effectiveNewBalances = newBalances ?? scaleBalances(channel.balances, channel.totalValue, newTotal);
|
|
129
|
+
return buildSpliceProposal(channel, {
|
|
130
|
+
type: 'splice_in',
|
|
131
|
+
newTotalValue: newTotal,
|
|
132
|
+
newBalances: effectiveNewBalances,
|
|
133
|
+
additionalCoinId,
|
|
134
|
+
additionalAmount,
|
|
135
|
+
}, proposerPublicKeyDigest);
|
|
136
|
+
}
|
|
137
|
+
/** Build an unsigned splice-out proposal (see `buildSpliceProposal`). */
|
|
138
|
+
export function buildSpliceOutProposal(channel, withdrawAmount, withdrawAddress, proposerPublicKeyDigest, newBalances, extraOutputs) {
|
|
139
|
+
validateChannelQuiesced(channel);
|
|
140
|
+
const extraSum = (extraOutputs ?? []).reduce((a, o) => a + o.amount, 0n);
|
|
141
|
+
const totalOutflow = withdrawAmount + extraSum;
|
|
142
|
+
if (totalOutflow > channel.totalValue) {
|
|
143
|
+
throw new Error(`buildSpliceOutProposal: total outflow (withdraw ${withdrawAmount} + extra outputs ${extraSum} = ${totalOutflow}) ` +
|
|
144
|
+
`exceeds channel totalValue (${channel.totalValue})`);
|
|
145
|
+
}
|
|
146
|
+
const remainingTotal = channel.totalValue - totalOutflow;
|
|
147
|
+
const effectiveNewBalances = newBalances ?? (() => {
|
|
148
|
+
const ratio = channel.totalValue > 0n ? remainingTotal * 1000n / channel.totalValue : 0n;
|
|
149
|
+
const adjusted = {};
|
|
150
|
+
let assigned = 0n;
|
|
151
|
+
const partyIds = Object.keys(channel.balances);
|
|
152
|
+
for (let i = 0; i < partyIds.length - 1; i++) {
|
|
153
|
+
const pid = partyIds[i];
|
|
154
|
+
const prev = channel.balances[pid] ?? 0n;
|
|
155
|
+
const scaled = (prev * ratio) / 1000n;
|
|
156
|
+
adjusted[pid] = scaled;
|
|
157
|
+
assigned += scaled;
|
|
158
|
+
}
|
|
159
|
+
const lastId = partyIds[partyIds.length - 1];
|
|
160
|
+
if (lastId)
|
|
161
|
+
adjusted[lastId] = remainingTotal - assigned;
|
|
162
|
+
return adjusted;
|
|
163
|
+
})();
|
|
164
|
+
return buildSpliceProposal(channel, {
|
|
165
|
+
type: 'splice_out',
|
|
166
|
+
newTotalValue: remainingTotal,
|
|
167
|
+
newBalances: effectiveNewBalances,
|
|
168
|
+
withdrawAmount,
|
|
169
|
+
withdrawAddress,
|
|
170
|
+
extraOutputs,
|
|
171
|
+
}, proposerPublicKeyDigest);
|
|
172
|
+
}
|
|
107
173
|
/**
|
|
108
174
|
* Initiating party proposes a splice-in: add external funds to the channel.
|
|
109
175
|
*
|
|
@@ -125,7 +191,7 @@ function bindDraftToParams(channel, proposal) {
|
|
|
125
191
|
* `sum(newBalances) === newTotalValue` is preserved.
|
|
126
192
|
* @returns SpliceProposal signed by the proposer with lease reservation data.
|
|
127
193
|
*/
|
|
128
|
-
async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leaseProvider, newBalances) {
|
|
194
|
+
export async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leaseProvider, newBalances) {
|
|
129
195
|
validateChannelQuiesced(channel);
|
|
130
196
|
const newTotal = channel.totalValue + additionalAmount;
|
|
131
197
|
const effectiveNewBalances = newBalances ?? scaleBalances(channel.balances, channel.totalValue, newTotal);
|
|
@@ -136,13 +202,13 @@ async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leas
|
|
|
136
202
|
additionalCoinId,
|
|
137
203
|
additionalAmount,
|
|
138
204
|
};
|
|
139
|
-
const draft =
|
|
140
|
-
const digest =
|
|
141
|
-
const spliceTxHex = Buffer.from(
|
|
205
|
+
const draft = buildSpliceTx(channel, params);
|
|
206
|
+
const digest = computeSpliceTxDigest(draft);
|
|
207
|
+
const spliceTxHex = Buffer.from(spliceDraftToMinimaBytes(draft)).toString('hex');
|
|
142
208
|
const { signer, wotsLease } = leaseProvider;
|
|
143
209
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
144
210
|
if (!partyInChannel) {
|
|
145
|
-
throw new
|
|
211
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
146
212
|
}
|
|
147
213
|
const reservation = await wotsLease.reserveKeyUse({
|
|
148
214
|
treeId: signer.publicKeyDigest,
|
|
@@ -180,7 +246,7 @@ async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leas
|
|
|
180
246
|
* @param extraOutputs - Optional additional on-chain outputs (third-party payments).
|
|
181
247
|
* @returns SpliceProposal signed by the proposer with lease reservation data.
|
|
182
248
|
*/
|
|
183
|
-
async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseProvider, newBalances, extraOutputs) {
|
|
249
|
+
export async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseProvider, newBalances, extraOutputs) {
|
|
184
250
|
validateChannelQuiesced(channel);
|
|
185
251
|
const extraSum = (extraOutputs ?? []).reduce((a, o) => a + o.amount, 0n);
|
|
186
252
|
const totalOutflow = withdrawAmount + extraSum;
|
|
@@ -214,13 +280,13 @@ async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseP
|
|
|
214
280
|
withdrawAddress,
|
|
215
281
|
extraOutputs,
|
|
216
282
|
};
|
|
217
|
-
const draft =
|
|
218
|
-
const digest =
|
|
219
|
-
const spliceTxHex = Buffer.from(
|
|
283
|
+
const draft = buildSpliceTx(channel, params);
|
|
284
|
+
const digest = computeSpliceTxDigest(draft);
|
|
285
|
+
const spliceTxHex = Buffer.from(spliceDraftToMinimaBytes(draft)).toString('hex');
|
|
220
286
|
const { signer, wotsLease } = leaseProvider;
|
|
221
287
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
222
288
|
if (!partyInChannel) {
|
|
223
|
-
throw new
|
|
289
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
224
290
|
}
|
|
225
291
|
const reservation = await wotsLease.reserveKeyUse({
|
|
226
292
|
treeId: signer.publicKeyDigest,
|
|
@@ -265,26 +331,26 @@ async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseP
|
|
|
265
331
|
* @param leaseProvider - Provides the acceptor signer and WOTS lease.
|
|
266
332
|
* @returns SpliceAcceptance containing acceptor co-signature and lease data.
|
|
267
333
|
*/
|
|
268
|
-
async function acceptSplice(channel, proposal, leaseProvider) {
|
|
334
|
+
export async function acceptSplice(channel, proposal, leaseProvider) {
|
|
269
335
|
validateChannelQuiesced(channel);
|
|
270
336
|
if (proposal.channelId !== channel.channelId) {
|
|
271
337
|
throw new Error(`Proposal channelId '${proposal.channelId}' does not match channel '${channel.channelId}'`);
|
|
272
338
|
}
|
|
273
339
|
const proposerInChannel = channel.parties.find(p => p.publicKeyDigest === proposal.proposerPublicKeyDigest);
|
|
274
340
|
if (!proposerInChannel) {
|
|
275
|
-
throw new
|
|
341
|
+
throw new SpliceMissingPartyError(proposal.proposerPublicKeyDigest);
|
|
276
342
|
}
|
|
277
343
|
const { signer, wotsLease } = leaseProvider;
|
|
278
344
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
279
345
|
if (!partyInChannel) {
|
|
280
|
-
throw new
|
|
346
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
281
347
|
}
|
|
282
348
|
if (signer.publicKeyDigest === proposal.proposerPublicKeyDigest) {
|
|
283
349
|
throw new Error('Acceptor and proposer cannot be the same party');
|
|
284
350
|
}
|
|
285
351
|
validateProposalParams(channel, proposal.params);
|
|
286
352
|
bindDraftToParams(channel, proposal);
|
|
287
|
-
const digest =
|
|
353
|
+
const digest = computeSpliceTxDigest(proposal.spliceTxDraft);
|
|
288
354
|
const reservation = await wotsLease.reserveKeyUse({
|
|
289
355
|
treeId: signer.publicKeyDigest,
|
|
290
356
|
purpose: 'omnia-splice-accept',
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-splice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Channel splicing for @totemsdk/omnia — resize Minima eltoo channels without a close+reopen cycle",
|
|
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": [
|
|
@@ -16,15 +21,16 @@
|
|
|
16
21
|
"rust/pkg/",
|
|
17
22
|
"rust/pkg-node/",
|
|
18
23
|
"README.md",
|
|
19
|
-
"LICENSE"
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"NOTICE"
|
|
20
26
|
],
|
|
21
27
|
"dependencies": {
|
|
22
|
-
"@totemsdk/core": "^1.2
|
|
23
|
-
"@totemsdk/
|
|
24
|
-
"@totemsdk/
|
|
25
|
-
"@totemsdk/
|
|
26
|
-
"@totemsdk/omnia": "^
|
|
27
|
-
"@totemsdk/storage": "^0.
|
|
28
|
+
"@totemsdk/core": "^1.4.2",
|
|
29
|
+
"@totemsdk/txpow": "^1.1.1",
|
|
30
|
+
"@totemsdk/wots-lease": "^1.0.2",
|
|
31
|
+
"@totemsdk/tx-builder": "^0.2.2",
|
|
32
|
+
"@totemsdk/omnia": "^2.4.0",
|
|
33
|
+
"@totemsdk/storage": "^0.2.2"
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
36
|
"@types/jest": "^30.0.0",
|
|
@@ -39,7 +45,7 @@
|
|
|
39
45
|
"publishConfig": {
|
|
40
46
|
"access": "public"
|
|
41
47
|
},
|
|
42
|
-
"license": "
|
|
48
|
+
"license": "Apache-2.0",
|
|
43
49
|
"author": "Totem SDK",
|
|
44
50
|
"homepage": "https://docs.totem.ing",
|
|
45
51
|
"bugs": {
|
|
@@ -66,8 +72,9 @@
|
|
|
66
72
|
"channel-resize",
|
|
67
73
|
"htlc"
|
|
68
74
|
],
|
|
75
|
+
"type": "module",
|
|
69
76
|
"scripts": {
|
|
70
|
-
"build": "
|
|
77
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
71
78
|
"clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
|
|
72
79
|
"test": "jest",
|
|
73
80
|
"build:wasm": "cd rust && wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node"
|
|
Binary file
|
package/rust/pkg/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
],
|
|
7
7
|
"description": "Channel splice commitment layer — splice TX digest computation, balance scaling, proposal validation (Rust/WASM)",
|
|
8
8
|
"version": "0.1.0",
|
|
9
|
-
"license": "
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/Totem-Edge/totem-sdk"
|
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
"./omnia_splice_wasm.js",
|
|
25
25
|
"./snippets/*"
|
|
26
26
|
]
|
|
27
|
-
}
|
|
27
|
+
}
|
|
Binary file
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"description": "Channel splice commitment layer — splice TX digest computation, balance scaling, proposal validation (Rust/WASM)",
|
|
7
7
|
"version": "0.1.0",
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/Totem-Edge/totem-sdk"
|
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
"main": "omnia_splice_wasm.js",
|
|
19
19
|
"homepage": "https://totem.ing",
|
|
20
20
|
"types": "omnia_splice_wasm.d.ts"
|
|
21
|
-
}
|
|
21
|
+
}
|