@totemsdk/omnia-factory 0.5.4 → 0.5.5
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/index.d.ts +2 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/script.d.ts +35 -0
- package/dist/cjs/script.js +60 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/script.d.ts +35 -0
- package/dist/script.js +57 -0
- package/package.json +3 -3
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { FactoryStatus, FactoryParticipant, FactorySignature, FactoryLogEntry, ChannelFactory, FactorySettlementPayload, FactoryDisputePayload, FactoryLeaseOps, WotsLeaseBundle, OmniaChannel, } from './types.js';
|
|
2
|
-
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
2
|
+
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, factoryDistributionOutputs, buildFactoryDistributionScript, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, FACTORY_BALANCE_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
3
3
|
export { computeFactoryStateCommitment } from './commitment.js';
|
|
4
|
+
export type { FactoryDistributionOutput, FactoryDistributionScriptConfig } from './script.js';
|
|
4
5
|
export { createFactory, acceptFactory, reallocate, enforceConservation, signFactoryOpening, verifyFactorySignature, applyFactorySignature, } from './factory.js';
|
|
5
6
|
export type { FactoryOpeningSignature } from './factory.js';
|
|
6
7
|
export { createFactoryCoordination, type FactoryCoordination, type FactoryCoordinationDeps, type FactoryApproval, type FactoryApprovalRequest, } from './coordination.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.createDurableFactoryStore = exports.assembleFactorySettlement = exports.verifyFactorySettlementSignature = exports.signFactorySettlement = exports.buildFactorySettlement = exports.buildDisputePayload = exports.closeFactory = exports.assembleVirtualChannelOpen = exports.verifyVirtualChannelOpenSignature = exports.signVirtualChannelOpen = exports.buildVirtualChannelOpen = exports.closeVirtualChannel = exports.openVirtualChannel = exports.createFactoryCoordination = exports.applyFactorySignature = exports.verifyFactorySignature = exports.signFactoryOpening = exports.enforceConservation = exports.reallocate = exports.acceptFactory = exports.createFactory = exports.computeFactoryStateCommitment = exports.normalizeScript = exports.scriptAddress = exports.MSHS_PORT_FLOOR = exports.FACTORY_PARTY_ROOT_PORT = exports.FACTORY_MAX_PARTICIPANTS = exports.FACTORY_ESCAPE_DELAY_BLOCKS = exports.FACTORY_ESCAPE_PORT = exports.FACTORY_BALANCE_PORT_BASE = exports.factoryBalanceProof = exports.factoryBalanceSetRoot = exports.factoryPartyProof = exports.factoryPartyRootStateVariable = exports.factoryPartySetRoot = exports.factoryEscapeStateVariable = exports.factoryBalanceStateVariables = exports.buildAndHashFactoryScript = exports.buildFactoryScript = void 0;
|
|
3
|
+
exports.createDurableFactoryStore = exports.assembleFactorySettlement = exports.verifyFactorySettlementSignature = exports.signFactorySettlement = exports.buildFactorySettlement = exports.buildDisputePayload = exports.closeFactory = exports.assembleVirtualChannelOpen = exports.verifyVirtualChannelOpenSignature = exports.signVirtualChannelOpen = exports.buildVirtualChannelOpen = exports.closeVirtualChannel = exports.openVirtualChannel = exports.createFactoryCoordination = exports.applyFactorySignature = exports.verifyFactorySignature = exports.signFactoryOpening = exports.enforceConservation = exports.reallocate = exports.acceptFactory = exports.createFactory = exports.computeFactoryStateCommitment = exports.normalizeScript = exports.scriptAddress = exports.MSHS_PORT_FLOOR = exports.FACTORY_BALANCE_ROOT_PORT = exports.FACTORY_PARTY_ROOT_PORT = exports.FACTORY_MAX_PARTICIPANTS = exports.FACTORY_ESCAPE_DELAY_BLOCKS = exports.FACTORY_ESCAPE_PORT = exports.FACTORY_BALANCE_PORT_BASE = exports.buildFactoryDistributionScript = exports.factoryDistributionOutputs = exports.factoryBalanceProof = exports.factoryBalanceSetRoot = exports.factoryPartyProof = exports.factoryPartyRootStateVariable = exports.factoryPartySetRoot = exports.factoryEscapeStateVariable = exports.factoryBalanceStateVariables = exports.buildAndHashFactoryScript = exports.buildFactoryScript = void 0;
|
|
4
4
|
var script_js_1 = require("./script.js");
|
|
5
5
|
Object.defineProperty(exports, "buildFactoryScript", { enumerable: true, get: function () { return script_js_1.buildFactoryScript; } });
|
|
6
6
|
Object.defineProperty(exports, "buildAndHashFactoryScript", { enumerable: true, get: function () { return script_js_1.buildAndHashFactoryScript; } });
|
|
@@ -11,11 +11,14 @@ Object.defineProperty(exports, "factoryPartyRootStateVariable", { enumerable: tr
|
|
|
11
11
|
Object.defineProperty(exports, "factoryPartyProof", { enumerable: true, get: function () { return script_js_1.factoryPartyProof; } });
|
|
12
12
|
Object.defineProperty(exports, "factoryBalanceSetRoot", { enumerable: true, get: function () { return script_js_1.factoryBalanceSetRoot; } });
|
|
13
13
|
Object.defineProperty(exports, "factoryBalanceProof", { enumerable: true, get: function () { return script_js_1.factoryBalanceProof; } });
|
|
14
|
+
Object.defineProperty(exports, "factoryDistributionOutputs", { enumerable: true, get: function () { return script_js_1.factoryDistributionOutputs; } });
|
|
15
|
+
Object.defineProperty(exports, "buildFactoryDistributionScript", { enumerable: true, get: function () { return script_js_1.buildFactoryDistributionScript; } });
|
|
14
16
|
Object.defineProperty(exports, "FACTORY_BALANCE_PORT_BASE", { enumerable: true, get: function () { return script_js_1.FACTORY_BALANCE_PORT_BASE; } });
|
|
15
17
|
Object.defineProperty(exports, "FACTORY_ESCAPE_PORT", { enumerable: true, get: function () { return script_js_1.FACTORY_ESCAPE_PORT; } });
|
|
16
18
|
Object.defineProperty(exports, "FACTORY_ESCAPE_DELAY_BLOCKS", { enumerable: true, get: function () { return script_js_1.FACTORY_ESCAPE_DELAY_BLOCKS; } });
|
|
17
19
|
Object.defineProperty(exports, "FACTORY_MAX_PARTICIPANTS", { enumerable: true, get: function () { return script_js_1.FACTORY_MAX_PARTICIPANTS; } });
|
|
18
20
|
Object.defineProperty(exports, "FACTORY_PARTY_ROOT_PORT", { enumerable: true, get: function () { return script_js_1.FACTORY_PARTY_ROOT_PORT; } });
|
|
21
|
+
Object.defineProperty(exports, "FACTORY_BALANCE_ROOT_PORT", { enumerable: true, get: function () { return script_js_1.FACTORY_BALANCE_ROOT_PORT; } });
|
|
19
22
|
Object.defineProperty(exports, "MSHS_PORT_FLOOR", { enumerable: true, get: function () { return script_js_1.MSHS_PORT_FLOOR; } });
|
|
20
23
|
Object.defineProperty(exports, "scriptAddress", { enumerable: true, get: function () { return script_js_1.scriptAddress; } });
|
|
21
24
|
Object.defineProperty(exports, "normalizeScript", { enumerable: true, get: function () { return script_js_1.normalizeScript; } });
|
package/dist/cjs/script.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export declare const FACTORY_ESCAPE_PORT = 103;
|
|
|
12
12
|
* (proof-based) scaling.
|
|
13
13
|
*/
|
|
14
14
|
export declare const FACTORY_PARTY_ROOT_PORT = 111;
|
|
15
|
+
/**
|
|
16
|
+
* State port carrying the committed balance set-root (STATE(112)) — the MMR root
|
|
17
|
+
* over `(pubkey, balance)` leaves (RFC-048 §12.4). Pinned on every spend.
|
|
18
|
+
*/
|
|
19
|
+
export declare const FACTORY_BALANCE_ROOT_PORT = 112;
|
|
15
20
|
/** MMR root (hex, no `0x`) over the participants' public-key digests.
|
|
16
21
|
*
|
|
17
22
|
* Minima's `MMRTree` builds a perfect binary tree (power-of-two leaves), so the
|
|
@@ -43,6 +48,36 @@ export declare function factoryBalanceSetRoot(participants: FactoryParticipant[]
|
|
|
43
48
|
* balance escape (leaf sum = the participant's balance).
|
|
44
49
|
*/
|
|
45
50
|
export declare function factoryBalanceProof(participants: FactoryParticipant[], index: number): string;
|
|
51
|
+
export interface FactoryDistributionOutput {
|
|
52
|
+
/** Payout destination (hex pubkey digest). */
|
|
53
|
+
address: string;
|
|
54
|
+
/** Committed balance (atoms). */
|
|
55
|
+
amount: bigint;
|
|
56
|
+
tokenId: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The exact payout set the pre-signed all-party distribution must contain — one
|
|
60
|
+
* output per participant, paying its committed balance (RFC-048 §12.4). Its sum
|
|
61
|
+
* equals `factoryBalanceSetRoot(...).rootSum`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function factoryDistributionOutputs(participants: FactoryParticipant[], tokenId?: string): FactoryDistributionOutput[];
|
|
64
|
+
export interface FactoryDistributionScriptConfig {
|
|
65
|
+
participants: FactoryParticipant[];
|
|
66
|
+
/** State port carrying the escape block. Default `FACTORY_ESCAPE_PORT` (103). */
|
|
67
|
+
escapePort?: number;
|
|
68
|
+
/** State port carrying the committed party-set root. Default `FACTORY_PARTY_ROOT_PORT` (111). */
|
|
69
|
+
partyRootPort?: number;
|
|
70
|
+
/** State port carrying the committed balance set-root. Default `FACTORY_BALANCE_ROOT_PORT` (112). */
|
|
71
|
+
balanceRootPort?: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Scalable factory escape covenant (RFC-048 §12.4) — the pre-signed all-party
|
|
75
|
+
* distribution. After the committed escape block **any** party may broadcast the
|
|
76
|
+
* distribution (all-party `MULTISIG`), with no counterparty liveness and no
|
|
77
|
+
* on-chain root recomputation. The committed party-set and balance roots are
|
|
78
|
+
* pinned (`SAMESTATE`) so the set and balances cannot move.
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildFactoryDistributionScript(config: FactoryDistributionScriptConfig): string;
|
|
46
81
|
/** Committed party-set root state variable (STATE(111)) for the factory funding output. */
|
|
47
82
|
export declare function factoryPartyRootStateVariable(root: string): {
|
|
48
83
|
port: number;
|
package/dist/cjs/script.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FACTORY_MAX_PARTICIPANTS = exports.MSHS_PORT_FLOOR = exports.FACTORY_BALANCE_PORT_BASE = exports.FACTORY_PARTY_ROOT_PORT = exports.FACTORY_ESCAPE_PORT = exports.FACTORY_ESCAPE_DELAY_BLOCKS = void 0;
|
|
3
|
+
exports.FACTORY_MAX_PARTICIPANTS = exports.MSHS_PORT_FLOOR = exports.FACTORY_BALANCE_PORT_BASE = exports.FACTORY_BALANCE_ROOT_PORT = exports.FACTORY_PARTY_ROOT_PORT = exports.FACTORY_ESCAPE_PORT = exports.FACTORY_ESCAPE_DELAY_BLOCKS = void 0;
|
|
4
4
|
exports.factoryPartySetRoot = factoryPartySetRoot;
|
|
5
5
|
exports.factoryPartyProof = factoryPartyProof;
|
|
6
6
|
exports.factoryBalanceSetRoot = factoryBalanceSetRoot;
|
|
7
7
|
exports.factoryBalanceProof = factoryBalanceProof;
|
|
8
|
+
exports.factoryDistributionOutputs = factoryDistributionOutputs;
|
|
9
|
+
exports.buildFactoryDistributionScript = buildFactoryDistributionScript;
|
|
8
10
|
exports.factoryPartyRootStateVariable = factoryPartyRootStateVariable;
|
|
9
11
|
exports.factoryBalanceStateVariables = factoryBalanceStateVariables;
|
|
10
12
|
exports.factoryEscapeStateVariable = factoryEscapeStateVariable;
|
|
@@ -35,6 +37,11 @@ exports.FACTORY_ESCAPE_PORT = 103;
|
|
|
35
37
|
* (proof-based) scaling.
|
|
36
38
|
*/
|
|
37
39
|
exports.FACTORY_PARTY_ROOT_PORT = 111;
|
|
40
|
+
/**
|
|
41
|
+
* State port carrying the committed balance set-root (STATE(112)) — the MMR root
|
|
42
|
+
* over `(pubkey, balance)` leaves (RFC-048 §12.4). Pinned on every spend.
|
|
43
|
+
*/
|
|
44
|
+
exports.FACTORY_BALANCE_ROOT_PORT = 112;
|
|
38
45
|
/** Public-key digests for the party set, padded to a power of two (Minima MMR). */
|
|
39
46
|
function padPartySet(participants) {
|
|
40
47
|
if (!Array.isArray(participants) || participants.length === 0) {
|
|
@@ -129,6 +136,58 @@ function buildBalanceTree(participants) {
|
|
|
129
136
|
}
|
|
130
137
|
return tree;
|
|
131
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* The exact payout set the pre-signed all-party distribution must contain — one
|
|
141
|
+
* output per participant, paying its committed balance (RFC-048 §12.4). Its sum
|
|
142
|
+
* equals `factoryBalanceSetRoot(...).rootSum`.
|
|
143
|
+
*/
|
|
144
|
+
function factoryDistributionOutputs(participants, tokenId = '0x00') {
|
|
145
|
+
if (!Array.isArray(participants) || participants.length === 0) {
|
|
146
|
+
throw new Error('factoryDistributionOutputs requires at least one participant');
|
|
147
|
+
}
|
|
148
|
+
return participants.map((p, i) => {
|
|
149
|
+
const raw = (p.settlementAddress ?? p.publicKeyDigest ?? '').replace(/^0x/i, '');
|
|
150
|
+
if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
|
|
151
|
+
throw new Error(`factoryDistributionOutputs: participant[${i}] payout address must be a 64-hex digest`);
|
|
152
|
+
}
|
|
153
|
+
if (p.contributionAmount < 0n) {
|
|
154
|
+
throw new Error(`factoryDistributionOutputs: participant[${i}].contributionAmount must be non-negative`);
|
|
155
|
+
}
|
|
156
|
+
return { address: '0x' + raw, amount: p.contributionAmount, tokenId };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Scalable factory escape covenant (RFC-048 §12.4) — the pre-signed all-party
|
|
161
|
+
* distribution. After the committed escape block **any** party may broadcast the
|
|
162
|
+
* distribution (all-party `MULTISIG`), with no counterparty liveness and no
|
|
163
|
+
* on-chain root recomputation. The committed party-set and balance roots are
|
|
164
|
+
* pinned (`SAMESTATE`) so the set and balances cannot move.
|
|
165
|
+
*/
|
|
166
|
+
function buildFactoryDistributionScript(config) {
|
|
167
|
+
const participants = config.participants;
|
|
168
|
+
if (!Array.isArray(participants) || participants.length < 1) {
|
|
169
|
+
throw new Error('buildFactoryDistributionScript requires at least one participant');
|
|
170
|
+
}
|
|
171
|
+
const pks = participants.map((p, i) => {
|
|
172
|
+
if (!p.publicKeyDigest)
|
|
173
|
+
throw new Error(`participant[${i}].publicKeyDigest is required`);
|
|
174
|
+
return kissHex(p.publicKeyDigest);
|
|
175
|
+
});
|
|
176
|
+
const escapePort = config.escapePort ?? exports.FACTORY_ESCAPE_PORT;
|
|
177
|
+
const partyRootPort = config.partyRootPort ?? exports.FACTORY_PARTY_ROOT_PORT;
|
|
178
|
+
const balanceRootPort = config.balanceRootPort ?? exports.FACTORY_BALANCE_ROOT_PORT;
|
|
179
|
+
return [
|
|
180
|
+
'// Scalable factory escape — pre-signed all-party distribution (RFC-048 §12.4)',
|
|
181
|
+
`ASSERT SAMESTATE(${escapePort} ${escapePort})`,
|
|
182
|
+
`ASSERT SAMESTATE(${partyRootPort} ${partyRootPort})`,
|
|
183
|
+
`ASSERT SAMESTATE(${balanceRootPort} ${balanceRootPort})`,
|
|
184
|
+
`IF @BLOCK GT PREVSTATE(${escapePort}) THEN`,
|
|
185
|
+
` ASSERT MULTISIG(${participants.length} ${pks.join(' ')})`,
|
|
186
|
+
` RETURN TRUE`,
|
|
187
|
+
`ENDIF`,
|
|
188
|
+
`RETURN FALSE`,
|
|
189
|
+
].join('\n');
|
|
190
|
+
}
|
|
132
191
|
/** Committed party-set root state variable (STATE(111)) for the factory funding output. */
|
|
133
192
|
function factoryPartyRootStateVariable(root) {
|
|
134
193
|
const raw = root.replace(/^0x/i, '');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { FactoryStatus, FactoryParticipant, FactorySignature, FactoryLogEntry, ChannelFactory, FactorySettlementPayload, FactoryDisputePayload, FactoryLeaseOps, WotsLeaseBundle, OmniaChannel, } from './types.js';
|
|
2
|
-
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
2
|
+
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, factoryDistributionOutputs, buildFactoryDistributionScript, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, FACTORY_BALANCE_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
3
3
|
export { computeFactoryStateCommitment } from './commitment.js';
|
|
4
|
+
export type { FactoryDistributionOutput, FactoryDistributionScriptConfig } from './script.js';
|
|
4
5
|
export { createFactory, acceptFactory, reallocate, enforceConservation, signFactoryOpening, verifyFactorySignature, applyFactorySignature, } from './factory.js';
|
|
5
6
|
export type { FactoryOpeningSignature } from './factory.js';
|
|
6
7
|
export { createFactoryCoordination, type FactoryCoordination, type FactoryCoordinationDeps, type FactoryApproval, type FactoryApprovalRequest, } from './coordination.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
1
|
+
export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, factoryDistributionOutputs, buildFactoryDistributionScript, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, FACTORY_BALANCE_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
|
|
2
2
|
export { computeFactoryStateCommitment } from './commitment.js';
|
|
3
3
|
export { createFactory, acceptFactory, reallocate, enforceConservation, signFactoryOpening, verifyFactorySignature, applyFactorySignature, } from './factory.js';
|
|
4
4
|
// RFC-035 B2 — factory opening round-trip over the coordination transport.
|
package/dist/script.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export declare const FACTORY_ESCAPE_PORT = 103;
|
|
|
12
12
|
* (proof-based) scaling.
|
|
13
13
|
*/
|
|
14
14
|
export declare const FACTORY_PARTY_ROOT_PORT = 111;
|
|
15
|
+
/**
|
|
16
|
+
* State port carrying the committed balance set-root (STATE(112)) — the MMR root
|
|
17
|
+
* over `(pubkey, balance)` leaves (RFC-048 §12.4). Pinned on every spend.
|
|
18
|
+
*/
|
|
19
|
+
export declare const FACTORY_BALANCE_ROOT_PORT = 112;
|
|
15
20
|
/** MMR root (hex, no `0x`) over the participants' public-key digests.
|
|
16
21
|
*
|
|
17
22
|
* Minima's `MMRTree` builds a perfect binary tree (power-of-two leaves), so the
|
|
@@ -43,6 +48,36 @@ export declare function factoryBalanceSetRoot(participants: FactoryParticipant[]
|
|
|
43
48
|
* balance escape (leaf sum = the participant's balance).
|
|
44
49
|
*/
|
|
45
50
|
export declare function factoryBalanceProof(participants: FactoryParticipant[], index: number): string;
|
|
51
|
+
export interface FactoryDistributionOutput {
|
|
52
|
+
/** Payout destination (hex pubkey digest). */
|
|
53
|
+
address: string;
|
|
54
|
+
/** Committed balance (atoms). */
|
|
55
|
+
amount: bigint;
|
|
56
|
+
tokenId: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The exact payout set the pre-signed all-party distribution must contain — one
|
|
60
|
+
* output per participant, paying its committed balance (RFC-048 §12.4). Its sum
|
|
61
|
+
* equals `factoryBalanceSetRoot(...).rootSum`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function factoryDistributionOutputs(participants: FactoryParticipant[], tokenId?: string): FactoryDistributionOutput[];
|
|
64
|
+
export interface FactoryDistributionScriptConfig {
|
|
65
|
+
participants: FactoryParticipant[];
|
|
66
|
+
/** State port carrying the escape block. Default `FACTORY_ESCAPE_PORT` (103). */
|
|
67
|
+
escapePort?: number;
|
|
68
|
+
/** State port carrying the committed party-set root. Default `FACTORY_PARTY_ROOT_PORT` (111). */
|
|
69
|
+
partyRootPort?: number;
|
|
70
|
+
/** State port carrying the committed balance set-root. Default `FACTORY_BALANCE_ROOT_PORT` (112). */
|
|
71
|
+
balanceRootPort?: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Scalable factory escape covenant (RFC-048 §12.4) — the pre-signed all-party
|
|
75
|
+
* distribution. After the committed escape block **any** party may broadcast the
|
|
76
|
+
* distribution (all-party `MULTISIG`), with no counterparty liveness and no
|
|
77
|
+
* on-chain root recomputation. The committed party-set and balance roots are
|
|
78
|
+
* pinned (`SAMESTATE`) so the set and balances cannot move.
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildFactoryDistributionScript(config: FactoryDistributionScriptConfig): string;
|
|
46
81
|
/** Committed party-set root state variable (STATE(111)) for the factory funding output. */
|
|
47
82
|
export declare function factoryPartyRootStateVariable(root: string): {
|
|
48
83
|
port: number;
|
package/dist/script.js
CHANGED
|
@@ -21,6 +21,11 @@ export const FACTORY_ESCAPE_PORT = 103;
|
|
|
21
21
|
* (proof-based) scaling.
|
|
22
22
|
*/
|
|
23
23
|
export const FACTORY_PARTY_ROOT_PORT = 111;
|
|
24
|
+
/**
|
|
25
|
+
* State port carrying the committed balance set-root (STATE(112)) — the MMR root
|
|
26
|
+
* over `(pubkey, balance)` leaves (RFC-048 §12.4). Pinned on every spend.
|
|
27
|
+
*/
|
|
28
|
+
export const FACTORY_BALANCE_ROOT_PORT = 112;
|
|
24
29
|
/** Public-key digests for the party set, padded to a power of two (Minima MMR). */
|
|
25
30
|
function padPartySet(participants) {
|
|
26
31
|
if (!Array.isArray(participants) || participants.length === 0) {
|
|
@@ -115,6 +120,58 @@ function buildBalanceTree(participants) {
|
|
|
115
120
|
}
|
|
116
121
|
return tree;
|
|
117
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The exact payout set the pre-signed all-party distribution must contain — one
|
|
125
|
+
* output per participant, paying its committed balance (RFC-048 §12.4). Its sum
|
|
126
|
+
* equals `factoryBalanceSetRoot(...).rootSum`.
|
|
127
|
+
*/
|
|
128
|
+
export function factoryDistributionOutputs(participants, tokenId = '0x00') {
|
|
129
|
+
if (!Array.isArray(participants) || participants.length === 0) {
|
|
130
|
+
throw new Error('factoryDistributionOutputs requires at least one participant');
|
|
131
|
+
}
|
|
132
|
+
return participants.map((p, i) => {
|
|
133
|
+
const raw = (p.settlementAddress ?? p.publicKeyDigest ?? '').replace(/^0x/i, '');
|
|
134
|
+
if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
|
|
135
|
+
throw new Error(`factoryDistributionOutputs: participant[${i}] payout address must be a 64-hex digest`);
|
|
136
|
+
}
|
|
137
|
+
if (p.contributionAmount < 0n) {
|
|
138
|
+
throw new Error(`factoryDistributionOutputs: participant[${i}].contributionAmount must be non-negative`);
|
|
139
|
+
}
|
|
140
|
+
return { address: '0x' + raw, amount: p.contributionAmount, tokenId };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Scalable factory escape covenant (RFC-048 §12.4) — the pre-signed all-party
|
|
145
|
+
* distribution. After the committed escape block **any** party may broadcast the
|
|
146
|
+
* distribution (all-party `MULTISIG`), with no counterparty liveness and no
|
|
147
|
+
* on-chain root recomputation. The committed party-set and balance roots are
|
|
148
|
+
* pinned (`SAMESTATE`) so the set and balances cannot move.
|
|
149
|
+
*/
|
|
150
|
+
export function buildFactoryDistributionScript(config) {
|
|
151
|
+
const participants = config.participants;
|
|
152
|
+
if (!Array.isArray(participants) || participants.length < 1) {
|
|
153
|
+
throw new Error('buildFactoryDistributionScript requires at least one participant');
|
|
154
|
+
}
|
|
155
|
+
const pks = participants.map((p, i) => {
|
|
156
|
+
if (!p.publicKeyDigest)
|
|
157
|
+
throw new Error(`participant[${i}].publicKeyDigest is required`);
|
|
158
|
+
return kissHex(p.publicKeyDigest);
|
|
159
|
+
});
|
|
160
|
+
const escapePort = config.escapePort ?? FACTORY_ESCAPE_PORT;
|
|
161
|
+
const partyRootPort = config.partyRootPort ?? FACTORY_PARTY_ROOT_PORT;
|
|
162
|
+
const balanceRootPort = config.balanceRootPort ?? FACTORY_BALANCE_ROOT_PORT;
|
|
163
|
+
return [
|
|
164
|
+
'// Scalable factory escape — pre-signed all-party distribution (RFC-048 §12.4)',
|
|
165
|
+
`ASSERT SAMESTATE(${escapePort} ${escapePort})`,
|
|
166
|
+
`ASSERT SAMESTATE(${partyRootPort} ${partyRootPort})`,
|
|
167
|
+
`ASSERT SAMESTATE(${balanceRootPort} ${balanceRootPort})`,
|
|
168
|
+
`IF @BLOCK GT PREVSTATE(${escapePort}) THEN`,
|
|
169
|
+
` ASSERT MULTISIG(${participants.length} ${pks.join(' ')})`,
|
|
170
|
+
` RETURN TRUE`,
|
|
171
|
+
`ENDIF`,
|
|
172
|
+
`RETURN FALSE`,
|
|
173
|
+
].join('\n');
|
|
174
|
+
}
|
|
118
175
|
/** Committed party-set root state variable (STATE(111)) for the factory funding output. */
|
|
119
176
|
export function factoryPartyRootStateVariable(root) {
|
|
120
177
|
const raw = root.replace(/^0x/i, '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-factory",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Channel factory layer for Omnia — N-of-N MULTISIG funding, virtual channel management, and factory settlement",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"types": "dist/cjs/index.d.ts",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@totemsdk/omnia": "^2.0.1",
|
|
28
27
|
"@totemsdk/core": "^1.3.0",
|
|
28
|
+
"@totemsdk/omnia": "^2.0.1",
|
|
29
29
|
"@totemsdk/tx-builder": "^0.2.1",
|
|
30
|
-
"@totemsdk/wots-lease": "^1.0.1",
|
|
31
30
|
"@totemsdk/txpow": "^1.0.2",
|
|
31
|
+
"@totemsdk/wots-lease": "^1.0.1",
|
|
32
32
|
"@totemsdk/chain-provider": "^0.2.1",
|
|
33
33
|
"@totemsdk/storage": "^0.1.0"
|
|
34
34
|
},
|