@totemsdk/omnia-factory 0.7.2 → 0.9.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/factory.js CHANGED
@@ -3,7 +3,7 @@ import { concatBytes } from '@totemsdk/core/wasm';
3
3
  import { buildScriptProof, computeScriptAddress } from '@totemsdk/core';
4
4
  import { buildFundingTx, omniaDraftToMinimaBytes, computeOmniaTxDigest, minimaOutputCoinIdsForDraft, serializeOmniaWitness, verifyChannelSignature, } from '@totemsdk/omnia';
5
5
  import { mineTxPoW, resolveTxPowTarget, serializeTxBody } from '@totemsdk/txpow';
6
- import { buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, FACTORY_ESCAPE_DELAY_BLOCKS } from './script.js';
6
+ import { buildAndHashFactoryScript, computeFactoryBalanceRoot, computeFactoryPartyRoot, factoryBalanceRootStateVariable, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartyRootStateVariable, FACTORY_ESCAPE_DELAY_BLOCKS, } from './script.js';
7
7
  import { computeFactoryStateCommitment } from './commitment.js';
8
8
  // ─── Balance conservation ────────────────────────────────────────────────────
9
9
  /**
@@ -110,12 +110,12 @@ function generateFactoryId(participants, tokenId, tokenScale) {
110
110
  * is 0; coloured coins use `tokenAmount = minimaRawAmount × 10^scale`.
111
111
  * Defaults to 0.
112
112
  */
113
- export async function createFactory(participants, tokenId, bundle, chainProvider, tokenScale = 0, funding) {
113
+ export async function createFactory(participants, tokenId, bundle, chainProvider, tokenScale = 0, funding, scriptOptions = { settlement: 'full-distribution', enforceCheckpoints: true }) {
114
114
  // One plan, one factory ID: build the opening once and reuse it for the
115
115
  // proposal, the local record and the funding transaction. Rebuilding here
116
116
  // would generate a different ID (the ID includes a random nonce) and the
117
117
  // peer would accept a factory this host never stored.
118
- const plan = await buildFactoryOpening(participants, tokenId, tokenScale, chainProvider, funding);
118
+ const plan = await buildFactoryOpening(participants, tokenId, tokenScale, chainProvider, funding, scriptOptions);
119
119
  return createFactoryFromPlan(plan, bundle, chainProvider);
120
120
  }
121
121
  function findProposer(factory, bundle) {
@@ -182,20 +182,34 @@ export async function createFactoryFromPlan(plan, bundle, chainProvider) {
182
182
  * Build a factory and (when every participant supplies a funding coin) its
183
183
  * deterministic funding draft, without signing or broadcasting.
184
184
  */
185
- export async function buildFactoryOpening(participants, tokenId, tokenScale, chainProvider, funding) {
185
+ export async function buildFactoryOpening(participants, tokenId, tokenScale, chainProvider, funding,
186
+ /**
187
+ * OMN-058: `enforceCheckpoints` uses the checkpoint-mode covenant, so every
188
+ * allocation change must consume and recreate the factory coin (RFC-079 §4).
189
+ */
190
+ scriptOptions = { settlement: 'full-distribution', enforceCheckpoints: true }) {
186
191
  if (participants.length < 2) {
187
192
  throw new Error(`Factory requires at least 2 participants, got ${participants.length}`);
188
193
  }
194
+ // OMN-095: without checkpoint enforcement a unilateral exit pays the funding
195
+ // split, so the latest off-chain allocation is unenforceable. Refuse to build
196
+ // that silently; it is allowed only as an explicit, acknowledged mode.
197
+ if (scriptOptions.enforceCheckpoints !== true && scriptOptions.allowUnenforceableAllocations !== true) {
198
+ throw new Error('refusing to build a factory whose allocations are not checkpoint-enforced: '
199
+ + 'a unilateral exit would pay the funding split, not the latest allocation. '
200
+ + 'Pass { allowUnenforceableAllocations: true } only for a factory that will never rely on unilateral exits.');
201
+ }
189
202
  const totalValue = participants.reduce((sum, p) => sum + p.contributionAmount, 0n);
190
203
  const allocations = {};
191
204
  for (const p of participants)
192
205
  allocations[p.partyId] = p.contributionAmount;
193
- const { script, address } = buildAndHashFactoryScript(participants);
206
+ const { script, address } = buildAndHashFactoryScript(participants, scriptOptions);
194
207
  const factoryId = generateFactoryId(participants, tokenId, tokenScale);
195
208
  let fundingTxBytes;
196
209
  let fundingDigest;
197
210
  let fundingCoinId;
198
211
  let pendingCommitment;
212
+ let seededStateVariables;
199
213
  const allHaveCoinId = participants.every(p => p.fundingCoinId);
200
214
  if (allHaveCoinId && chainProvider) {
201
215
  const materialByParty = new Map((funding ?? []).map(m => [m.partyId, m]));
@@ -208,7 +222,18 @@ export async function buildFactoryOpening(participants, tokenId, tokenScale, cha
208
222
  }
209
223
  const tip = await chainProvider.getTip();
210
224
  const escapeBlock = tip.block + FACTORY_ESCAPE_DELAY_BLOCKS;
211
- const fundingDraft = buildFundingTx(script, address, totalValue, tokenId, tokenScale, participants.map(p => p.fundingCoinId), participants.map(p => p.contributionAmount), inputAddresses, [...factoryBalanceStateVariables(participants), factoryEscapeStateVariable(escapeBlock)]);
225
+ const fundingStateVariables = [
226
+ ...factoryBalanceStateVariables(participants),
227
+ factoryEscapeStateVariable(escapeBlock),
228
+ // OMN-058: the checkpoint sequence starts at zero on the funding coin.
229
+ { port: 104, value: 0n, type: 'number' },
230
+ // OMN-060: the covenant asserts SAMESTATE over these roots, so they must
231
+ // exist in the funding output or the assertion is vacuous.
232
+ factoryPartyRootStateVariable(computeFactoryPartyRoot(participants)),
233
+ factoryBalanceRootStateVariable(computeFactoryBalanceRoot(allocations)),
234
+ ];
235
+ seededStateVariables = fundingStateVariables;
236
+ const fundingDraft = buildFundingTx(script, address, totalValue, tokenId, tokenScale, participants.map(p => p.fundingCoinId), participants.map(p => p.contributionAmount), inputAddresses, fundingStateVariables);
212
237
  fundingDigest = computeOmniaTxDigest(fundingDraft);
213
238
  fundingTxBytes = omniaDraftToMinimaBytes(fundingDraft);
214
239
  fundingCoinId = minimaOutputCoinIdsForDraft(fundingDraft)[0];
@@ -241,8 +266,18 @@ export async function buildFactoryOpening(participants, tokenId, tokenScale, cha
241
266
  fundingCoinId: undefined,
242
267
  pendingCommitment: Buffer.from(pendingCommitment).toString('hex'),
243
268
  pendingSignatures: {},
269
+ enforceCheckpoints: scriptOptions.enforceCheckpoints === true,
270
+ allocationEnforcement: scriptOptions.enforceCheckpoints === true ? 'checkpoint' : 'none',
271
+ };
272
+ return {
273
+ factory,
274
+ fundingTxBytes,
275
+ fundingDigest,
276
+ fundingCoinId,
277
+ fundingMaterials: funding,
278
+ ...(seededStateVariables ? { fundingStateVariables: seededStateVariables } : {}),
279
+ onChain: fundingTxBytes !== undefined,
244
280
  };
245
- return { factory, fundingTxBytes, fundingDigest, fundingCoinId, fundingMaterials: funding, onChain: fundingTxBytes !== undefined };
246
281
  }
247
282
  /**
248
283
  * Broadcast the prepared factory funding (when on-chain) and record opening
@@ -296,6 +331,21 @@ export async function finalizeFactoryOpening(plan, opts, chainProvider) {
296
331
  fundingTxId,
297
332
  fundingCoinId: plan.fundingCoinId,
298
333
  };
334
+ // OMN-063: submission is not finality. Only a coin observed at the required
335
+ // depth may become an active factory.
336
+ const required = opts.minConfirmations ?? 1;
337
+ if (required > 0) {
338
+ let confirmed = false;
339
+ if (plan.fundingCoinId && typeof chainProvider.getTip === 'function') {
340
+ const coin = await chainProvider.getCoin(plan.fundingCoinId);
341
+ const tip = await chainProvider.getTip();
342
+ const created = Number(coin?.created ?? 0);
343
+ confirmed = Boolean(coin && !coin.spent && created > 0 && tip.block - created + 1 >= required);
344
+ }
345
+ if (!confirmed) {
346
+ return { ...factory, pendingSignatures: { ...opts.openingSignatures } };
347
+ }
348
+ }
299
349
  }
300
350
  factory = { ...factory, pendingSignatures: { ...opts.openingSignatures } };
301
351
  const allSigned = factory.participants.every(p => factory.pendingSignatures[p.partyId] !== undefined);
@@ -457,6 +507,10 @@ export async function reallocate(factory, fromPartyId, toPartyId, amount, leaseP
457
507
  if (factory.status !== 'active') {
458
508
  throw new Error(`reallocate requires factory status 'active', got '${factory.status}'`);
459
509
  }
510
+ if (factory.enforceCheckpoints) {
511
+ throw new Error(`factory ${factory.factoryId} uses checkpoint mode: reallocating changes the committed allocation `
512
+ + 'and must be committed with a factory checkpoint transaction first.');
513
+ }
460
514
  if (amount <= 0n) {
461
515
  throw new Error(`Reallocation amount must be positive, got ${amount}`);
462
516
  }
@@ -594,23 +648,81 @@ export function assertFactoryFinalized(known, incoming, senderPublicKeyDigest) {
594
648
  if (JSON.stringify(jsonSafeForCompare(last.allocations)) !== JSON.stringify(jsonSafeForCompare(known.allocations))) {
595
649
  throw new Error('FACTORY_FINALIZED changes allocations in the accept entry');
596
650
  }
597
- return { ...incoming, pendingSignatures: {} };
651
+ // Rebuild from local state: the peer may only supply the funding references.
652
+ return {
653
+ ...known,
654
+ status: 'active',
655
+ currentSequence: 1,
656
+ stateLog: [...(known.stateLog ?? []), last],
657
+ pendingCommitment: undefined,
658
+ pendingSignatures: {},
659
+ fundingTxId: incoming.fundingTxId ?? known.fundingTxId,
660
+ fundingCoinId: incoming.fundingCoinId ?? known.fundingCoinId,
661
+ };
598
662
  }
599
663
  if (known.status === 'active' && incoming.status === 'active') {
600
- // Funding references may be filled in after activation; terms are already checked.
601
- return { ...incoming };
664
+ // Funding references may be filled in after activation. Nothing else may
665
+ // change: a peer cannot rewrite sequence, log, allocations or the VC set.
666
+ if (incoming.currentSequence !== known.currentSequence) {
667
+ throw new Error('FACTORY_FINALIZED changes the active sequence');
668
+ }
669
+ if (JSON.stringify(jsonSafeForCompare(incoming.stateLog ?? [])) !== JSON.stringify(jsonSafeForCompare(known.stateLog ?? []))) {
670
+ throw new Error('FACTORY_FINALIZED changes the active state log');
671
+ }
672
+ if (JSON.stringify(jsonSafeForCompare(incoming.allocations)) !== JSON.stringify(jsonSafeForCompare(known.allocations))) {
673
+ throw new Error('FACTORY_FINALIZED changes the active allocations');
674
+ }
675
+ if (JSON.stringify(jsonSafeForCompare(incoming.virtualChannels ?? [])) !== JSON.stringify(jsonSafeForCompare(known.virtualChannels ?? []))) {
676
+ throw new Error('FACTORY_FINALIZED changes the active virtual-channel set');
677
+ }
678
+ if (incoming.pendingCommitment || (incoming.pendingSignatures && Object.keys(incoming.pendingSignatures).length > 0)) {
679
+ throw new Error('FACTORY_FINALIZED carries pending opening state on an active factory');
680
+ }
681
+ return {
682
+ ...known,
683
+ fundingTxId: known.fundingTxId ?? incoming.fundingTxId,
684
+ fundingCoinId: known.fundingCoinId ?? incoming.fundingCoinId,
685
+ };
602
686
  }
603
687
  if (known.status === 'opening' && incoming.status === 'opening') {
604
- // Funding references only; signatures may not be removed or altered.
688
+ // Funding references and additional *valid* opening signatures only.
689
+ if (incoming.currentSequence !== known.currentSequence) {
690
+ throw new Error('FACTORY_FINALIZED changes the opening sequence');
691
+ }
692
+ if (JSON.stringify(jsonSafeForCompare(incoming.stateLog ?? [])) !== JSON.stringify(jsonSafeForCompare(known.stateLog ?? []))) {
693
+ throw new Error('FACTORY_FINALIZED changes the opening state log');
694
+ }
695
+ if (!known.pendingCommitment) {
696
+ throw new Error('FACTORY_FINALIZED for a proposal without a pending commitment');
697
+ }
698
+ const commitment = Buffer.from(known.pendingCommitment.replace(/^0x/i, ''), 'hex');
605
699
  const knownSigs = known.pendingSignatures ?? {};
606
700
  const incomingSigs = incoming.pendingSignatures ?? {};
607
- for (const [partyId, sig] of Object.entries(knownSigs)) {
608
- const next = incomingSigs[partyId];
609
- if (!next || Buffer.from(next).toString('hex') !== Buffer.from(sig).toString('hex')) {
701
+ const byParty = new Map(known.participants.map((participant) => [participant.partyId, participant]));
702
+ for (const [partyId, sig] of Object.entries(incomingSigs)) {
703
+ const participant = byParty.get(partyId);
704
+ if (!participant) {
705
+ throw new Error(`FACTORY_FINALIZED carries a signature from unknown party '${partyId}'`);
706
+ }
707
+ const previous = knownSigs[partyId];
708
+ if (previous && Buffer.from(previous).toString('hex') !== Buffer.from(sig).toString('hex')) {
610
709
  throw new Error(`FACTORY_FINALIZED removes or alters the signature for '${partyId}'`);
611
710
  }
711
+ if (!verifyChannelSignature(sig, commitment, participant.publicKeyDigest)) {
712
+ throw new Error(`FACTORY_FINALIZED carries an invalid signature for '${partyId}'`);
713
+ }
612
714
  }
613
- return { ...incoming, pendingSignatures: { ...incomingSigs } };
715
+ for (const partyId of Object.keys(knownSigs)) {
716
+ if (!incomingSigs[partyId]) {
717
+ throw new Error(`FACTORY_FINALIZED removes or alters the signature for '${partyId}'`);
718
+ }
719
+ }
720
+ return {
721
+ ...known,
722
+ fundingTxId: known.fundingTxId ?? incoming.fundingTxId,
723
+ fundingCoinId: known.fundingCoinId ?? incoming.fundingCoinId,
724
+ pendingSignatures: { ...incomingSigs },
725
+ };
614
726
  }
615
727
  throw new Error('FACTORY_FINALIZED has an unsupported status transition');
616
728
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  export type { FactoryOpeningPlan, FinalizeFactoryOpeningOptions } from './factory.js';
2
2
  export type { FactoryStatus, FactoryParticipant, FactoryFundingMaterial, FactorySignature, FactoryLogEntry, ChannelFactory, FactorySettlementPayload, FactoryDisputePayload, FactoryLeaseOps, WotsLeaseBundle, OmniaChannel, } from './types.js';
3
- 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
+ export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, factoryDistributionOutputs, buildFactoryDistributionScript, buildFactoryPresignedDistributionScript, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_CHECKPOINT_SEQUENCE_PORT, FACTORY_ESCAPE_DELAY_BLOCKS, FACTORY_MAX_PARTICIPANTS, FACTORY_PARTY_ROOT_PORT, FACTORY_BALANCE_ROOT_PORT, MSHS_PORT_FLOOR, scriptAddress, normalizeScript, } from './script.js';
4
4
  export { computeFactoryStateCommitment } from './commitment.js';
5
+ export { assertFactoryDistributable, buildFactoryDistribution, factoryDistributionPayouts, } from './distribution.js';
6
+ export type { FactoryDistribution, FactoryDistributionEntry, } from './distribution.js';
7
+ export { buildFactoryCheckpoint, factoryCheckpointStateVariables, assertFactoryCheckpointTransition, factoryCheckpointSnapshot, } from './checkpoint.js';
8
+ export type { FactoryCheckpoint, FactoryCheckpointParams, FactoryCheckpointSnapshot, } from './checkpoint.js';
5
9
  export type { FactoryDistributionOutput, FactoryDistributionScriptConfig } from './script.js';
6
10
  export { createFactory, createFactoryFromPlan, proposeFactoryOpening, buildFactoryOpening, finalizeFactoryOpening, acceptFactory, reallocate, enforceConservation, signFactoryOpening, verifyFactorySignature, applyFactorySignature, assertFactoryFinalized, } from './factory.js';
7
11
  export type { FactoryOpeningSignature } from './factory.js';
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
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';
1
+ export { buildFactoryScript, buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, factoryPartySetRoot, factoryPartyRootStateVariable, factoryPartyProof, factoryBalanceSetRoot, factoryBalanceProof, factoryDistributionOutputs, buildFactoryDistributionScript, buildFactoryPresignedDistributionScript, FACTORY_BALANCE_PORT_BASE, FACTORY_ESCAPE_PORT, FACTORY_CHECKPOINT_SEQUENCE_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
+ export { assertFactoryDistributable, buildFactoryDistribution, factoryDistributionPayouts, } from './distribution.js';
4
+ export { buildFactoryCheckpoint, factoryCheckpointStateVariables, assertFactoryCheckpointTransition, factoryCheckpointSnapshot, } from './checkpoint.js';
3
5
  export { createFactory, createFactoryFromPlan, proposeFactoryOpening, buildFactoryOpening, finalizeFactoryOpening, acceptFactory, reallocate, enforceConservation, signFactoryOpening, verifyFactorySignature, applyFactorySignature, assertFactoryFinalized, } from './factory.js';
4
6
  // RFC-035 B2 — factory opening round-trip over the coordination transport.
5
7
  export { createFactoryCoordination, } from './coordination.js';
package/dist/script.d.ts CHANGED
@@ -3,6 +3,12 @@ import type { FactoryParticipant } from './types.js';
3
3
  export declare const FACTORY_ESCAPE_DELAY_BLOCKS = 256;
4
4
  /** State port carrying the absolute escape block (STATE(103)). */
5
5
  export declare const FACTORY_ESCAPE_PORT = 103;
6
+ /**
7
+ * OMN-058/RFC-079 §4: checkpoint sequence (STATE(104)). Seeded at funding and
8
+ * advanced by exactly one on every checkpoint spend, so a checkpoint can never
9
+ * be replayed against a newer state.
10
+ */
11
+ export declare const FACTORY_CHECKPOINT_SEQUENCE_PORT = 104;
6
12
  /**
7
13
  * State port carrying the committed party-set root (STATE(111)) — the MMR root
8
14
  * of the participant public-key digests (RFC-048 §12.4/§12.5). It is pinned on
@@ -71,13 +77,41 @@ export interface FactoryDistributionScriptConfig {
71
77
  balanceRootPort?: number;
72
78
  }
73
79
  /**
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.
80
+ * Pre-signed all-party distribution (RFC-048 §12.4) — kept as a **separate**
81
+ * mechanism for a dedicated distribution coin.
82
+ *
83
+ * This script authorizes the spend with `MULTISIG` after the escape height. It
84
+ * does **not** verify the payout set; allocation correctness comes from the
85
+ * pre-signed transaction that the parties exchange. Do not describe or use it as
86
+ * an allocation verifier — use `buildFactoryDistributionScript` (output-enforced)
87
+ * or the `settlement: 'full-distribution'` funding branch instead.
88
+ */
89
+ export declare function buildFactoryPresignedDistributionScript(config: FactoryDistributionScriptConfig): string;
90
+ /**
91
+ * OMN-058/RFC-079 §4A — output-enforced full distribution for a factory coin.
92
+ *
93
+ * After the committed escape block, any participant may settle the factory by
94
+ * paying **every** committed share. The covenant reads the shares from the spent
95
+ * coin (`PREVSTATE`), pins the output count, each destination, each amount and
96
+ * the total, so neither the broadcaster nor an outsider can redirect or resize a
97
+ * payout. One participant signature authorizes the trigger.
98
+ *
99
+ * Use `buildFactoryDistribution` to materialize the matching transaction.
79
100
  */
80
101
  export declare function buildFactoryDistributionScript(config: FactoryDistributionScriptConfig): string;
102
+ /**
103
+ * OMN-060: deterministic party-set root committed by STATE(111).
104
+ * Canonical: parties sorted by id, `id:pubkeyDigest`.
105
+ */
106
+ export declare function computeFactoryPartyRoot(participants: FactoryParticipant[]): string;
107
+ /** OMN-060: deterministic balance root committed by STATE(112). */
108
+ export declare function computeFactoryBalanceRoot(allocations: Record<string, bigint>): string;
109
+ /** Committed balance-set root state variable (STATE(112)) for the funding output. */
110
+ export declare function factoryBalanceRootStateVariable(root: string): {
111
+ port: number;
112
+ value: string;
113
+ type: 'hex';
114
+ };
81
115
  /** Committed party-set root state variable (STATE(111)) for the factory funding output. */
82
116
  export declare function factoryPartyRootStateVariable(root: string): {
83
117
  port: number;
@@ -97,6 +131,34 @@ export declare const FACTORY_MAX_PARTICIPANTS: number;
97
131
  export interface FactoryScriptOptions {
98
132
  /** Reserved for callers; the escape block is carried in STATE(103) at funding. */
99
133
  escapeBlock?: number;
134
+ /**
135
+ * OMN-058 checkpoint mode (RFC-079 §4). When true, the cooperative branch only
136
+ * accepts a same-script, same-value successor whose sequence advanced by one.
137
+ * Every allocation change then has an on-chain artifact, and the unilateral
138
+ * escape pays the latest checkpoint instead of the original funding split.
139
+ *
140
+ * The factory builders (`buildFactoryOpening`, `openFactory`) pass `true`;
141
+ * this option only defaults to off when the script is built directly.
142
+ *
143
+ * Setting it to `false` selects the legacy off-chain mode, where a unilateral
144
+ * exit pays the funding split and a newer allocation is **not** enforceable.
145
+ * OMN-095: that mode now requires `allowUnenforceableAllocations` so it is a
146
+ * deliberate release restriction rather than an accidental default.
147
+ */
148
+ enforceCheckpoints?: boolean;
149
+ /**
150
+ * OMN-095: acknowledge that `enforceCheckpoints: false` produces a factory
151
+ * whose latest off-chain allocation cannot be enforced on chain. Required to
152
+ * build such a factory; the resulting `ChannelFactory.allocationEnforcement`
153
+ * is `'none'`.
154
+ */
155
+ allowUnenforceableAllocations?: boolean;
156
+ /**
157
+ * OMN-058/RFC-079 §4A: add the output-enforced full-distribution branch.
158
+ * Any participant can settle every committed share in one transaction; the
159
+ * covenant pins each destination, amount, the output count and conservation.
160
+ */
161
+ settlement?: 'per-party' | 'full-distribution';
100
162
  }
101
163
  /**
102
164
  * Per-party allocation state variables (port base+k = party k's balance), seeded
@@ -107,6 +169,7 @@ export declare function factoryBalanceStateVariables(participants: FactoryPartic
107
169
  port: number;
108
170
  value: bigint;
109
171
  type: 'number';
172
+ scale: number;
110
173
  }[];
111
174
  /** Absolute escape-block state variable (STATE(103)) for the factory funding output. */
112
175
  export declare function factoryEscapeStateVariable(escapeBlock: number): {
@@ -115,23 +178,28 @@ export declare function factoryEscapeStateVariable(escapeBlock: number): {
115
178
  type: 'number';
116
179
  };
117
180
  /**
118
- * Build the N-of-N MULTISIG MAST funding script for a channel factory
119
- * (RFC-039, CUSTODY-POLICY §2).
181
+ * Build the factory funding script.
120
182
  *
121
183
  * Spend paths:
122
- * - **Cooperative / update** (any time): `MULTISIG(N …)` — all parties sign.
123
- * `settlement=true` closes after minimal coinage (1 block).
124
- * - **Unilateral escape** (after the absolute block in `STATE(103)`): any
125
- * single party k may withdraw its allocation `SHARE_k = PREVSTATE(base+k)`
126
- * (the spent coin's share) to its own settlement address, zero its state in
127
- * the successor (`STATE(base+k) EQ 0`), keep the other parties' balances
128
- * unchanged, and return the remainder to the factory script. Repeated
129
- * withdrawals cannot double-claim because each zeroes its own port. `STATE(103)` is immutable on every spend (`SAMESTATE(103 103)`),
130
- * so the escape clock cannot be pushed by any counterparty.
184
+ * - **Cooperative / checkpoint** (any time, all parties): `MULTISIG(N …)`.
185
+ * With `enforceCheckpoints`, the successor must stay at this script, keep the
186
+ * value and advance `STATE(104)` by exactly one.
187
+ * - **Unilateral escape** (after the absolute block in `STATE(103)`): any single
188
+ * party may withdraw its committed share `PREVSTATE(base+k)` to its own
189
+ * settlement address. With a remainder, the successor keeps the script, the
190
+ * other shares are untouched and the withdrawing port is zeroed.
191
+ * - **Full distribution** (`settlement: 'full-distribution'`, after the same
192
+ * block): one transaction pays **every** committed share. The covenant pins
193
+ * the output count, each destination and each amount read from `PREVSTATE`,
194
+ * so a broadcaster cannot redirect or resize a payout. One participant
195
+ * signature is enough to trigger it.
196
+ *
197
+ * The escape branches are terminal (no successor state), so the state-continuity
198
+ * assertions live in the cooperative path only.
131
199
  *
132
200
  * Minimum 2 participants required.
133
201
  */
134
- export declare function buildFactoryScript(participants: FactoryParticipant[], _options?: FactoryScriptOptions): string;
202
+ export declare function buildFactoryScript(participants: FactoryParticipant[], options?: FactoryScriptOptions): string;
135
203
  export declare function normalizeScript(script: string): string;
136
204
  /** Compute the SHA3-256 script-hash address for a factory script. */
137
205
  export declare function scriptAddress(script: string): string;