@totemsdk/omnia-splice 0.1.8 → 0.2.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/dist/durable-splice-store.d.ts +58 -0
- package/dist/durable-splice-store.js +117 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +10 -9
- 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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable splice-state store (RFC-007 G9).
|
|
3
|
+
*
|
|
4
|
+
* A splice is a two-party (or multi-party) op that spans propose → quiesce →
|
|
5
|
+
* accept → broadcast → finalize. If the host dies between "proposer signed
|
|
6
|
+
* `SpliceProposal`" and "acceptor co-signed `SpliceAcceptance`", the pending
|
|
7
|
+
* proposal — and the partial acceptance once made — must survive a restart so
|
|
8
|
+
* the partial splice commit is recoverable/reconcilable (never silently
|
|
9
|
+
* discarded or re-proposed with a fresh key slot).
|
|
10
|
+
*
|
|
11
|
+
* The store keeps one record per spliceId holding the proposal plus (once
|
|
12
|
+
* received) the acceptance. Backed by the shared revision-CAS snapshot store:
|
|
13
|
+
* corruption is surfaced (never treated as absence), no silent downgrade, and
|
|
14
|
+
* concurrent propose/accept transitions across splices are never lost.
|
|
15
|
+
*/
|
|
16
|
+
import type { StorageAdapterWithCapabilities, CasStore, WriteAckMode } from '@totemsdk/storage/types';
|
|
17
|
+
import type { SpliceProposal, SpliceAcceptance } from './types.js';
|
|
18
|
+
export type SpliceRecordStatus = 'pending' | 'accepted' | 'finalized';
|
|
19
|
+
/** One in-progress splice: proposal persisted first, acceptance added later. */
|
|
20
|
+
export interface SpliceRecord {
|
|
21
|
+
spliceId: string;
|
|
22
|
+
channelId: string;
|
|
23
|
+
proposal: SpliceProposal;
|
|
24
|
+
acceptance?: SpliceAcceptance;
|
|
25
|
+
status: SpliceRecordStatus;
|
|
26
|
+
updatedAt: number;
|
|
27
|
+
}
|
|
28
|
+
export interface SpliceStoreState {
|
|
29
|
+
/** spliceId → splice record. */
|
|
30
|
+
splices: Record<string, SpliceRecord>;
|
|
31
|
+
}
|
|
32
|
+
export interface DurableSpliceStoreOptions {
|
|
33
|
+
/** Key namespace prefix; default `totem_omnia_splice:v1:`. */
|
|
34
|
+
readonly namespace?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Required write acknowledgment; default `durably-acknowledged`. Pass
|
|
37
|
+
* `volatile` only for tests/scratch adapters (e.g. `MemoryStore`).
|
|
38
|
+
*/
|
|
39
|
+
readonly requireAckMode?: WriteAckMode;
|
|
40
|
+
}
|
|
41
|
+
export interface DurableSpliceStore {
|
|
42
|
+
/** Persist a freshly created splice proposal (pending, pre-acceptance). */
|
|
43
|
+
saveProposal(proposal: SpliceProposal): Promise<void>;
|
|
44
|
+
/** Attach an acceptance; updates status to `accepted`. */
|
|
45
|
+
saveAcceptance(acceptance: SpliceAcceptance): Promise<void>;
|
|
46
|
+
/** Retrieve a splice record by spliceId. */
|
|
47
|
+
getSplice(spliceId: string): Promise<SpliceRecord | undefined>;
|
|
48
|
+
/** All records, optionally filtered by channel. */
|
|
49
|
+
listSplices(channelId?: string): Promise<SpliceRecord[]>;
|
|
50
|
+
/** Pending (proposed but not yet accepted) splices — reconcilable after restart. */
|
|
51
|
+
listPending(): Promise<SpliceRecord[]>;
|
|
52
|
+
/** Mark a splice finalized (splice TX confirmed on-chain). */
|
|
53
|
+
markFinalized(spliceId: string): Promise<void>;
|
|
54
|
+
getRevision(): Promise<number>;
|
|
55
|
+
hasState(): Promise<boolean>;
|
|
56
|
+
getSnapshot(): Promise<SpliceStoreState>;
|
|
57
|
+
}
|
|
58
|
+
export declare function createDurableSpliceStore(adapter: StorageAdapterWithCapabilities & CasStore, options?: DurableSpliceStoreOptions): DurableSpliceStore;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Durable splice-state store (RFC-007 G9).
|
|
4
|
+
*
|
|
5
|
+
* A splice is a two-party (or multi-party) op that spans propose → quiesce →
|
|
6
|
+
* accept → broadcast → finalize. If the host dies between "proposer signed
|
|
7
|
+
* `SpliceProposal`" and "acceptor co-signed `SpliceAcceptance`", the pending
|
|
8
|
+
* proposal — and the partial acceptance once made — must survive a restart so
|
|
9
|
+
* the partial splice commit is recoverable/reconcilable (never silently
|
|
10
|
+
* discarded or re-proposed with a fresh key slot).
|
|
11
|
+
*
|
|
12
|
+
* The store keeps one record per spliceId holding the proposal plus (once
|
|
13
|
+
* received) the acceptance. Backed by the shared revision-CAS snapshot store:
|
|
14
|
+
* corruption is surfaced (never treated as absence), no silent downgrade, and
|
|
15
|
+
* concurrent propose/accept transitions across splices are never lost.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createDurableSpliceStore = createDurableSpliceStore;
|
|
19
|
+
const snapshot_1 = require("@totemsdk/storage/snapshot");
|
|
20
|
+
const errors_1 = require("@totemsdk/storage/errors");
|
|
21
|
+
const DEFAULT_NAMESPACE = 'totem_omnia_splice:v1:';
|
|
22
|
+
function assertSpliceState(state) {
|
|
23
|
+
if (typeof state !== 'object' || state === null || Array.isArray(state)) {
|
|
24
|
+
throw new errors_1.StorageError('omnia-splice store state is not an object', 'corrupt');
|
|
25
|
+
}
|
|
26
|
+
const value = state.splices;
|
|
27
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
28
|
+
throw new errors_1.StorageError('omnia-splice store state is missing section "splices"', 'corrupt');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function createDurableSpliceStore(adapter, options = {}) {
|
|
32
|
+
const snapshots = (0, snapshot_1.createRevisionedSnapshotStore)(adapter, {
|
|
33
|
+
namespace: options.namespace ?? DEFAULT_NAMESPACE,
|
|
34
|
+
requireAckMode: options.requireAckMode,
|
|
35
|
+
empty: () => ({ splices: {} }),
|
|
36
|
+
validate: assertSpliceState,
|
|
37
|
+
});
|
|
38
|
+
async function mutate(fn) {
|
|
39
|
+
await snapshots.mutate(fn);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
async saveProposal(proposal) {
|
|
43
|
+
await mutate((state) => {
|
|
44
|
+
const existing = state.splices[proposal.spliceId];
|
|
45
|
+
// A duplicate proposal for the same spliceId never overrides the first.
|
|
46
|
+
if (existing)
|
|
47
|
+
return state;
|
|
48
|
+
return {
|
|
49
|
+
...state,
|
|
50
|
+
splices: {
|
|
51
|
+
...state.splices,
|
|
52
|
+
[proposal.spliceId]: {
|
|
53
|
+
spliceId: proposal.spliceId,
|
|
54
|
+
channelId: proposal.channelId,
|
|
55
|
+
proposal,
|
|
56
|
+
status: 'pending',
|
|
57
|
+
updatedAt: Date.now(),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
async saveAcceptance(acceptance) {
|
|
64
|
+
await mutate((state) => {
|
|
65
|
+
const existing = state.splices[acceptance.spliceId];
|
|
66
|
+
if (!existing) {
|
|
67
|
+
throw new errors_1.StorageError(`acceptance for unknown splice ${acceptance.spliceId}`, 'write-failed', { key: acceptance.spliceId });
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
...state,
|
|
71
|
+
splices: {
|
|
72
|
+
...state.splices,
|
|
73
|
+
[acceptance.spliceId]: {
|
|
74
|
+
...existing,
|
|
75
|
+
acceptance,
|
|
76
|
+
status: 'accepted',
|
|
77
|
+
updatedAt: Date.now(),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
async getSplice(spliceId) {
|
|
84
|
+
return (await snapshots.load()).splices[spliceId];
|
|
85
|
+
},
|
|
86
|
+
async listSplices(channelId) {
|
|
87
|
+
const state = await snapshots.load();
|
|
88
|
+
const all = Object.values(state.splices);
|
|
89
|
+
if (channelId === undefined)
|
|
90
|
+
return all;
|
|
91
|
+
return all.filter((s) => s.channelId === channelId);
|
|
92
|
+
},
|
|
93
|
+
async listPending() {
|
|
94
|
+
const state = await snapshots.load();
|
|
95
|
+
return Object.values(state.splices).filter((s) => s.status === 'pending');
|
|
96
|
+
},
|
|
97
|
+
async markFinalized(spliceId) {
|
|
98
|
+
await mutate((state) => {
|
|
99
|
+
const existing = state.splices[spliceId];
|
|
100
|
+
if (!existing)
|
|
101
|
+
return state;
|
|
102
|
+
return {
|
|
103
|
+
...state,
|
|
104
|
+
splices: {
|
|
105
|
+
...state.splices,
|
|
106
|
+
[spliceId]: { ...existing, status: 'finalized', updatedAt: Date.now() },
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
getRevision: () => snapshots.getRevision(),
|
|
112
|
+
hasState: () => snapshots.hasState(),
|
|
113
|
+
async getSnapshot() {
|
|
114
|
+
return snapshots.load();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { proposeSpliceIn, proposeSpliceOut, acceptSplice } from './splice.js';
|
|
|
4
4
|
export { finalizeSplice, type FinalizeSpliceOptions } from './finalize.js';
|
|
5
5
|
export type { SpliceType, SpliceParams, SpliceTxDraft, SpliceTxInput, SpliceTxOutput, SpliceProposal, SpliceAcceptance, QuiescedChannel, SplicedChannel, SpliceLeaseProvider, SpliceSigningIndices, WotsSignature, } from './types.js';
|
|
6
6
|
export { SpliceError, PendingHTLCError, SpliceChannelStatusError, SpliceBalanceConservationError, SpliceSignatureMismatchError, SpliceMissingPartyError, SpliceInsufficientFundsError, } from './errors.js';
|
|
7
|
+
export { createDurableSpliceStore, } from './durable-splice-store.js';
|
|
8
|
+
export type { SpliceRecord, SpliceRecordStatus, SpliceStoreState, DurableSpliceStore, DurableSpliceStoreOptions, } from './durable-splice-store.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpliceInsufficientFundsError = exports.SpliceMissingPartyError = exports.SpliceSignatureMismatchError = exports.SpliceBalanceConservationError = exports.SpliceChannelStatusError = exports.PendingHTLCError = exports.SpliceError = exports.finalizeSplice = exports.acceptSplice = exports.proposeSpliceOut = exports.proposeSpliceIn = exports.computeSpliceTxDigest = exports.spliceDraftToMinimaBytes = exports.buildSpliceTx = exports.quiesceChannel = void 0;
|
|
3
|
+
exports.createDurableSpliceStore = exports.SpliceInsufficientFundsError = exports.SpliceMissingPartyError = exports.SpliceSignatureMismatchError = exports.SpliceBalanceConservationError = exports.SpliceChannelStatusError = exports.PendingHTLCError = exports.SpliceError = exports.finalizeSplice = 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");
|
|
@@ -21,3 +21,5 @@ Object.defineProperty(exports, "SpliceBalanceConservationError", { enumerable: t
|
|
|
21
21
|
Object.defineProperty(exports, "SpliceSignatureMismatchError", { enumerable: true, get: function () { return errors_js_1.SpliceSignatureMismatchError; } });
|
|
22
22
|
Object.defineProperty(exports, "SpliceMissingPartyError", { enumerable: true, get: function () { return errors_js_1.SpliceMissingPartyError; } });
|
|
23
23
|
Object.defineProperty(exports, "SpliceInsufficientFundsError", { enumerable: true, get: function () { return errors_js_1.SpliceInsufficientFundsError; } });
|
|
24
|
+
var durable_splice_store_js_1 = require("./durable-splice-store.js");
|
|
25
|
+
Object.defineProperty(exports, "createDurableSpliceStore", { enumerable: true, get: function () { return durable_splice_store_js_1.createDurableSpliceStore; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-splice",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Channel splicing for @totemsdk/omnia — resize Minima eltoo channels without a close+reopen cycle",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@totemsdk/
|
|
23
|
-
"@totemsdk/tx-builder": "^0.1
|
|
24
|
-
"@totemsdk/txpow": "^0.
|
|
25
|
-
"@totemsdk/
|
|
26
|
-
"@totemsdk/
|
|
22
|
+
"@totemsdk/core": "^1.2.11",
|
|
23
|
+
"@totemsdk/tx-builder": "^0.2.1",
|
|
24
|
+
"@totemsdk/txpow": "^1.0.2",
|
|
25
|
+
"@totemsdk/wots-lease": "^1.0.1",
|
|
26
|
+
"@totemsdk/omnia": "^1.0.2",
|
|
27
|
+
"@totemsdk/storage": "^0.1.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/jest": "^30.0.0",
|
|
@@ -40,13 +41,13 @@
|
|
|
40
41
|
},
|
|
41
42
|
"license": "MIT",
|
|
42
43
|
"author": "Totem SDK",
|
|
43
|
-
"homepage": "https://totem.ing",
|
|
44
|
+
"homepage": "https://docs.totem.ing",
|
|
44
45
|
"bugs": {
|
|
45
|
-
"url": "https://github.com/
|
|
46
|
+
"url": "https://github.com/Totem-Edge/totem-sdk/issues"
|
|
46
47
|
},
|
|
47
48
|
"repository": {
|
|
48
49
|
"type": "git",
|
|
49
|
-
"url": "git+https://github.com/
|
|
50
|
+
"url": "git+https://github.com/Totem-Edge/totem-sdk.git",
|
|
50
51
|
"directory": "packages/omnia-splice"
|
|
51
52
|
},
|
|
52
53
|
"keywords": [
|
|
Binary file
|
package/rust/pkg/package.json
CHANGED
|
Binary file
|