@totemsdk/omnia-splice 0.2.0 → 0.3.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/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 +9 -0
- package/dist/cjs/index.js +28 -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 +71 -0
- package/dist/cjs/splice.js +303 -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.d.ts +58 -0
- package/dist/durable-splice-store.js +114 -0
- 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 -0
- package/dist/index.js +8 -23
- package/dist/quiesce.js +7 -10
- package/dist/splice-tx.js +13 -18
- package/dist/splice.js +21 -26
- package/dist/types.js +1 -2
- package/package.json +19 -12
- package/rust/pkg/omnia_splice_wasm_bg.wasm +0 -0
- package/rust/pkg/package.json +1 -1
- package/rust/pkg-node/omnia_splice_wasm_bg.wasm +0 -0
- package/rust/pkg-node/package.json +1 -1
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.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,9 +91,9 @@ 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');
|
|
@@ -125,7 +120,7 @@ function bindDraftToParams(channel, proposal) {
|
|
|
125
120
|
* `sum(newBalances) === newTotalValue` is preserved.
|
|
126
121
|
* @returns SpliceProposal signed by the proposer with lease reservation data.
|
|
127
122
|
*/
|
|
128
|
-
async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leaseProvider, newBalances) {
|
|
123
|
+
export async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leaseProvider, newBalances) {
|
|
129
124
|
validateChannelQuiesced(channel);
|
|
130
125
|
const newTotal = channel.totalValue + additionalAmount;
|
|
131
126
|
const effectiveNewBalances = newBalances ?? scaleBalances(channel.balances, channel.totalValue, newTotal);
|
|
@@ -136,13 +131,13 @@ async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leas
|
|
|
136
131
|
additionalCoinId,
|
|
137
132
|
additionalAmount,
|
|
138
133
|
};
|
|
139
|
-
const draft =
|
|
140
|
-
const digest =
|
|
141
|
-
const spliceTxHex = Buffer.from(
|
|
134
|
+
const draft = buildSpliceTx(channel, params);
|
|
135
|
+
const digest = computeSpliceTxDigest(draft);
|
|
136
|
+
const spliceTxHex = Buffer.from(spliceDraftToMinimaBytes(draft)).toString('hex');
|
|
142
137
|
const { signer, wotsLease } = leaseProvider;
|
|
143
138
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
144
139
|
if (!partyInChannel) {
|
|
145
|
-
throw new
|
|
140
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
146
141
|
}
|
|
147
142
|
const reservation = await wotsLease.reserveKeyUse({
|
|
148
143
|
treeId: signer.publicKeyDigest,
|
|
@@ -180,7 +175,7 @@ async function proposeSpliceIn(channel, additionalCoinId, additionalAmount, leas
|
|
|
180
175
|
* @param extraOutputs - Optional additional on-chain outputs (third-party payments).
|
|
181
176
|
* @returns SpliceProposal signed by the proposer with lease reservation data.
|
|
182
177
|
*/
|
|
183
|
-
async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseProvider, newBalances, extraOutputs) {
|
|
178
|
+
export async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseProvider, newBalances, extraOutputs) {
|
|
184
179
|
validateChannelQuiesced(channel);
|
|
185
180
|
const extraSum = (extraOutputs ?? []).reduce((a, o) => a + o.amount, 0n);
|
|
186
181
|
const totalOutflow = withdrawAmount + extraSum;
|
|
@@ -214,13 +209,13 @@ async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseP
|
|
|
214
209
|
withdrawAddress,
|
|
215
210
|
extraOutputs,
|
|
216
211
|
};
|
|
217
|
-
const draft =
|
|
218
|
-
const digest =
|
|
219
|
-
const spliceTxHex = Buffer.from(
|
|
212
|
+
const draft = buildSpliceTx(channel, params);
|
|
213
|
+
const digest = computeSpliceTxDigest(draft);
|
|
214
|
+
const spliceTxHex = Buffer.from(spliceDraftToMinimaBytes(draft)).toString('hex');
|
|
220
215
|
const { signer, wotsLease } = leaseProvider;
|
|
221
216
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
222
217
|
if (!partyInChannel) {
|
|
223
|
-
throw new
|
|
218
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
224
219
|
}
|
|
225
220
|
const reservation = await wotsLease.reserveKeyUse({
|
|
226
221
|
treeId: signer.publicKeyDigest,
|
|
@@ -265,26 +260,26 @@ async function proposeSpliceOut(channel, withdrawAmount, withdrawAddress, leaseP
|
|
|
265
260
|
* @param leaseProvider - Provides the acceptor signer and WOTS lease.
|
|
266
261
|
* @returns SpliceAcceptance containing acceptor co-signature and lease data.
|
|
267
262
|
*/
|
|
268
|
-
async function acceptSplice(channel, proposal, leaseProvider) {
|
|
263
|
+
export async function acceptSplice(channel, proposal, leaseProvider) {
|
|
269
264
|
validateChannelQuiesced(channel);
|
|
270
265
|
if (proposal.channelId !== channel.channelId) {
|
|
271
266
|
throw new Error(`Proposal channelId '${proposal.channelId}' does not match channel '${channel.channelId}'`);
|
|
272
267
|
}
|
|
273
268
|
const proposerInChannel = channel.parties.find(p => p.publicKeyDigest === proposal.proposerPublicKeyDigest);
|
|
274
269
|
if (!proposerInChannel) {
|
|
275
|
-
throw new
|
|
270
|
+
throw new SpliceMissingPartyError(proposal.proposerPublicKeyDigest);
|
|
276
271
|
}
|
|
277
272
|
const { signer, wotsLease } = leaseProvider;
|
|
278
273
|
const partyInChannel = channel.parties.find(p => p.publicKeyDigest === signer.publicKeyDigest);
|
|
279
274
|
if (!partyInChannel) {
|
|
280
|
-
throw new
|
|
275
|
+
throw new SpliceMissingPartyError(signer.publicKeyDigest);
|
|
281
276
|
}
|
|
282
277
|
if (signer.publicKeyDigest === proposal.proposerPublicKeyDigest) {
|
|
283
278
|
throw new Error('Acceptor and proposer cannot be the same party');
|
|
284
279
|
}
|
|
285
280
|
validateProposalParams(channel, proposal.params);
|
|
286
281
|
bindDraftToParams(channel, proposal);
|
|
287
|
-
const digest =
|
|
282
|
+
const digest = computeSpliceTxDigest(proposal.spliceTxDraft);
|
|
288
283
|
const reservation = await wotsLease.reserveKeyUse({
|
|
289
284
|
treeId: signer.publicKeyDigest,
|
|
290
285
|
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.0",
|
|
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": [
|
|
@@ -19,11 +24,12 @@
|
|
|
19
24
|
"LICENSE"
|
|
20
25
|
],
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@totemsdk/
|
|
23
|
-
"@totemsdk/
|
|
24
|
-
"@totemsdk/
|
|
25
|
-
"@totemsdk/
|
|
26
|
-
"@totemsdk/
|
|
27
|
+
"@totemsdk/core": "^1.2.11",
|
|
28
|
+
"@totemsdk/omnia": "^2.0.0",
|
|
29
|
+
"@totemsdk/tx-builder": "^0.2.1",
|
|
30
|
+
"@totemsdk/txpow": "^1.0.2",
|
|
31
|
+
"@totemsdk/wots-lease": "^1.0.1",
|
|
32
|
+
"@totemsdk/storage": "^0.1.0"
|
|
27
33
|
},
|
|
28
34
|
"devDependencies": {
|
|
29
35
|
"@types/jest": "^30.0.0",
|
|
@@ -65,8 +71,9 @@
|
|
|
65
71
|
"channel-resize",
|
|
66
72
|
"htlc"
|
|
67
73
|
],
|
|
74
|
+
"type": "module",
|
|
68
75
|
"scripts": {
|
|
69
|
-
"build": "
|
|
76
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
70
77
|
"clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
|
|
71
78
|
"test": "jest",
|
|
72
79
|
"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
|
Binary file
|