@totemsdk/omnia-splice 0.2.1 → 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.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 +1 -0
- package/dist/index.js +8 -25
- 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 +14 -8
- 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.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": [
|
|
@@ -20,10 +25,10 @@
|
|
|
20
25
|
],
|
|
21
26
|
"dependencies": {
|
|
22
27
|
"@totemsdk/core": "^1.2.11",
|
|
28
|
+
"@totemsdk/omnia": "^2.0.0",
|
|
23
29
|
"@totemsdk/tx-builder": "^0.2.1",
|
|
24
30
|
"@totemsdk/txpow": "^1.0.2",
|
|
25
31
|
"@totemsdk/wots-lease": "^1.0.1",
|
|
26
|
-
"@totemsdk/omnia": "^1.0.2",
|
|
27
32
|
"@totemsdk/storage": "^0.1.0"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
@@ -66,8 +71,9 @@
|
|
|
66
71
|
"channel-resize",
|
|
67
72
|
"htlc"
|
|
68
73
|
],
|
|
74
|
+
"type": "module",
|
|
69
75
|
"scripts": {
|
|
70
|
-
"build": "
|
|
76
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
71
77
|
"clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
|
|
72
78
|
"test": "jest",
|
|
73
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
|