@totemsdk/omnia-factory 0.5.5 → 0.6.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.
@@ -146,8 +146,9 @@ async function createFactory(participants, tokenId, bundle, chainProvider, token
146
146
  // All parties co-sign the TX digest — the exact on-chain TX structure.
147
147
  pendingCommitment = (0, omnia_1.computeTxDraftDigest)(fundingDraft);
148
148
  const draftBytes = (0, omnia_1.omniaDraftToMinimaBytes)(fundingDraft);
149
- const txBody = (0, txpow_1.serializeTxBody)(draftBytes, new Uint8Array(0));
150
- const mined = await (0, txpow_1.mineTxPoW)(txBody, txpow_1.TX_POW_MIN_DIFFICULTY);
149
+ const txnDifficulty = await (0, txpow_1.resolveTxPowTarget)(chainProvider);
150
+ const txBody = (0, txpow_1.serializeTxBody)(draftBytes, new Uint8Array(0), { txnDifficulty });
151
+ const mined = await (0, txpow_1.mineTxPoW)(txBody, txnDifficulty);
151
152
  const fullTxPoW = (0, wasm_2.concatBytes)((0, wasm_2.concatBytes)(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
152
153
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
153
154
  fundingTxId = Buffer.from(mined.txpowId).toString('hex');
@@ -120,7 +120,7 @@ export declare function factoryEscapeStateVariable(escapeBlock: number): {
120
120
  *
121
121
  * Spend paths:
122
122
  * - **Cooperative / update** (any time): `MULTISIG(N …)` — all parties sign.
123
- * `SETTLEMENT=true` closes after minimal coinage (1 block).
123
+ * `settlement=true` closes after minimal coinage (1 block).
124
124
  * - **Unilateral escape** (after the absolute block in `STATE(103)`): any
125
125
  * single party k may withdraw its allocation `SHARE_k = PREVSTATE(base+k)`
126
126
  * (the spent coin's share) to its own settlement address, zero its state in
@@ -18,11 +18,11 @@ const scripts_1 = require("@totemsdk/core/scripts");
18
18
  const core_1 = require("@totemsdk/core");
19
19
  /**
20
20
  * Normalize a hex public key digest to the KISSVM-compatible format:
21
- * strip leading 0x/0X and render as upper-case hex with leading '0X'.
21
+ * strip leading 0x/0X and render as upper-case hex with a lowercase 0x prefix.
22
22
  */
23
23
  function kissHex(hex) {
24
24
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
25
- return '0X' + raw.toUpperCase();
25
+ return '0x' + raw.toUpperCase();
26
26
  }
27
27
  /** Blocks after the funding tip at which the unilateral escape opens. */
28
28
  exports.FACTORY_ESCAPE_DELAY_BLOCKS = 256;
@@ -153,7 +153,7 @@ function factoryDistributionOutputs(participants, tokenId = '0x00') {
153
153
  if (p.contributionAmount < 0n) {
154
154
  throw new Error(`factoryDistributionOutputs: participant[${i}].contributionAmount must be non-negative`);
155
155
  }
156
- return { address: '0x' + raw, amount: p.contributionAmount, tokenId };
156
+ return { address: (0, core_1.wotsAddressData)(raw), amount: p.contributionAmount, tokenId };
157
157
  });
158
158
  }
159
159
  /**
@@ -231,7 +231,7 @@ function factoryEscapeStateVariable(escapeBlock) {
231
231
  *
232
232
  * Spend paths:
233
233
  * - **Cooperative / update** (any time): `MULTISIG(N …)` — all parties sign.
234
- * `SETTLEMENT=true` closes after minimal coinage (1 block).
234
+ * `settlement=true` closes after minimal coinage (1 block).
235
235
  * - **Unilateral escape** (after the absolute block in `STATE(103)`): any
236
236
  * single party k may withdraw its allocation `SHARE_k = PREVSTATE(base+k)`
237
237
  * (the spent coin's share) to its own settlement address, zero its state in
@@ -251,9 +251,9 @@ function buildFactoryScript(participants, _options = {}) {
251
251
  }
252
252
  const count = participants.length;
253
253
  const pks = participants.map((p) => kissHex(p.publicKeyDigest));
254
- const payouts = participants.map((p) => kissHex(p.settlementAddress ?? p.publicKeyDigest));
254
+ const payouts = participants.map((p) => (0, core_1.wotsAddressData)(p.settlementAddress ?? p.publicKeyDigest));
255
255
  const lines = [
256
- 'LET SETTLEMENT=STATE(100)',
256
+ 'LET settlement=STATE(100)',
257
257
  `ASSERT SAMESTATE(${exports.FACTORY_ESCAPE_PORT} ${exports.FACTORY_ESCAPE_PORT})`,
258
258
  // RFC-048 §12.4/§12.5: the committed party-set root is immutable on every spend.
259
259
  `ASSERT SAMESTATE(${exports.FACTORY_PARTY_ROOT_PORT} ${exports.FACTORY_PARTY_ROOT_PORT})`,
@@ -261,10 +261,10 @@ function buildFactoryScript(participants, _options = {}) {
261
261
  ];
262
262
  participants.forEach((_, k) => {
263
263
  const port = exports.FACTORY_BALANCE_PORT_BASE + k;
264
- lines.push(` LET SHARE${k}=PREVSTATE(${port})`);
264
+ lines.push(` LET share=PREVSTATE(${port})`);
265
265
  lines.push(` IF SIGNEDBY(${pks[k]}) THEN`);
266
- lines.push(` IF SHARE${k} GT 0 THEN`);
267
- lines.push(` ASSERT VERIFYOUT(0 ${payouts[k]} SHARE${k} @TOKENID FALSE)`);
266
+ lines.push(` IF share GT 0 THEN`);
267
+ lines.push(` ASSERT VERIFYOUT(0 ${payouts[k]} share @TOKENID FALSE)`);
268
268
  for (let j = 0; j < count; j++) {
269
269
  if (j === k)
270
270
  continue;
@@ -274,8 +274,8 @@ function buildFactoryScript(participants, _options = {}) {
274
274
  // Whole-share guard (mirrors the VTXO script): when the withdrawing party's
275
275
  // share is the entire output there is no remainder, so a 0-amount output is
276
276
  // never required.
277
- lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
278
- lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
277
+ lines.push(` IF @AMOUNT GT share THEN`);
278
+ lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT - share @TOKENID TRUE)`);
279
279
  lines.push(' ENDIF');
280
280
  lines.push(' RETURN TRUE');
281
281
  lines.push(' ENDIF');
@@ -283,12 +283,12 @@ function buildFactoryScript(participants, _options = {}) {
283
283
  });
284
284
  lines.push('ENDIF');
285
285
  lines.push(`ASSERT MULTISIG(${count} ${pks.join(' ')})`);
286
- lines.push('IF SETTLEMENT THEN');
286
+ lines.push('IF settlement THEN');
287
287
  lines.push(' IF @COINAGE GTE 1 THEN RETURN TRUE ENDIF');
288
288
  lines.push('ELSE');
289
289
  lines.push(' RETURN TRUE');
290
290
  lines.push('ENDIF');
291
- return lines.join('\n');
291
+ return (0, core_1.toNodeScript)(lines.join('\n'));
292
292
  }
293
293
  function normalizeScript(script) {
294
294
  return script.trim().toUpperCase();
@@ -123,8 +123,9 @@ async function assembleFactorySettlement(factory, draft, signatures, chainProvid
123
123
  };
124
124
  if (chainProvider) {
125
125
  const draftBytes = (0, omnia_1.omniaDraftToMinimaBytes)(draft.settlementDraft);
126
- const txBody = (0, txpow_1.serializeTxBody)(draftBytes, witnessBytes);
127
- const mined = await (0, txpow_1.mineTxPoW)(txBody, txpow_1.TX_POW_MIN_DIFFICULTY);
126
+ const txnDifficulty = await (0, txpow_1.resolveTxPowTarget)(chainProvider);
127
+ const txBody = (0, txpow_1.serializeTxBody)(draftBytes, witnessBytes, { txnDifficulty });
128
+ const mined = await (0, txpow_1.mineTxPoW)(txBody, txnDifficulty);
128
129
  const fullTxPoW = (0, wasm_1.concatBytes)((0, wasm_1.concatBytes)(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
129
130
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
130
131
  payload.txpowId = Buffer.from(mined.txpowId).toString('hex');
package/dist/factory.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { sha3_256 } from '@totemsdk/core/wasm';
2
2
  import { concatBytes } from '@totemsdk/core/wasm';
3
3
  import { buildFundingTx, omniaDraftToMinimaBytes, computeTxDraftDigest, verifyChannelSignature, } from '@totemsdk/omnia';
4
- import { mineTxPoW, TX_POW_MIN_DIFFICULTY, serializeTxBody } from '@totemsdk/txpow';
4
+ import { mineTxPoW, resolveTxPowTarget, serializeTxBody } from '@totemsdk/txpow';
5
5
  import { buildAndHashFactoryScript, factoryBalanceStateVariables, factoryEscapeStateVariable, FACTORY_ESCAPE_DELAY_BLOCKS } from './script.js';
6
6
  import { computeFactoryStateCommitment } from './commitment.js';
7
7
  // ─── Balance conservation ────────────────────────────────────────────────────
@@ -137,8 +137,9 @@ export async function createFactory(participants, tokenId, bundle, chainProvider
137
137
  // All parties co-sign the TX digest — the exact on-chain TX structure.
138
138
  pendingCommitment = computeTxDraftDigest(fundingDraft);
139
139
  const draftBytes = omniaDraftToMinimaBytes(fundingDraft);
140
- const txBody = serializeTxBody(draftBytes, new Uint8Array(0));
141
- const mined = await mineTxPoW(txBody, TX_POW_MIN_DIFFICULTY);
140
+ const txnDifficulty = await resolveTxPowTarget(chainProvider);
141
+ const txBody = serializeTxBody(draftBytes, new Uint8Array(0), { txnDifficulty });
142
+ const mined = await mineTxPoW(txBody, txnDifficulty);
142
143
  const fullTxPoW = concatBytes(concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
143
144
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
144
145
  fundingTxId = Buffer.from(mined.txpowId).toString('hex');
package/dist/script.d.ts CHANGED
@@ -120,7 +120,7 @@ export declare function factoryEscapeStateVariable(escapeBlock: number): {
120
120
  *
121
121
  * Spend paths:
122
122
  * - **Cooperative / update** (any time): `MULTISIG(N …)` — all parties sign.
123
- * `SETTLEMENT=true` closes after minimal coinage (1 block).
123
+ * `settlement=true` closes after minimal coinage (1 block).
124
124
  * - **Unilateral escape** (after the absolute block in `STATE(103)`): any
125
125
  * single party k may withdraw its allocation `SHARE_k = PREVSTATE(base+k)`
126
126
  * (the spent coin's share) to its own settlement address, zero its state in
package/dist/script.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { computeScriptAddress } from '@totemsdk/core/scripts';
2
- import { MMRTree, hexToBytes, bytesToHex, serializeMMRProof, createMMRDataLeafNode } from '@totemsdk/core';
2
+ import { MMRTree, hexToBytes, bytesToHex, serializeMMRProof, createMMRDataLeafNode, toNodeScript, wotsAddressData } from '@totemsdk/core';
3
3
  /**
4
4
  * Normalize a hex public key digest to the KISSVM-compatible format:
5
- * strip leading 0x/0X and render as upper-case hex with leading '0X'.
5
+ * strip leading 0x/0X and render as upper-case hex with a lowercase 0x prefix.
6
6
  */
7
7
  function kissHex(hex) {
8
8
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
9
- return '0X' + raw.toUpperCase();
9
+ return '0x' + raw.toUpperCase();
10
10
  }
11
11
  /** Blocks after the funding tip at which the unilateral escape opens. */
12
12
  export const FACTORY_ESCAPE_DELAY_BLOCKS = 256;
@@ -137,7 +137,7 @@ export function factoryDistributionOutputs(participants, tokenId = '0x00') {
137
137
  if (p.contributionAmount < 0n) {
138
138
  throw new Error(`factoryDistributionOutputs: participant[${i}].contributionAmount must be non-negative`);
139
139
  }
140
- return { address: '0x' + raw, amount: p.contributionAmount, tokenId };
140
+ return { address: wotsAddressData(raw), amount: p.contributionAmount, tokenId };
141
141
  });
142
142
  }
143
143
  /**
@@ -215,7 +215,7 @@ export function factoryEscapeStateVariable(escapeBlock) {
215
215
  *
216
216
  * Spend paths:
217
217
  * - **Cooperative / update** (any time): `MULTISIG(N …)` — all parties sign.
218
- * `SETTLEMENT=true` closes after minimal coinage (1 block).
218
+ * `settlement=true` closes after minimal coinage (1 block).
219
219
  * - **Unilateral escape** (after the absolute block in `STATE(103)`): any
220
220
  * single party k may withdraw its allocation `SHARE_k = PREVSTATE(base+k)`
221
221
  * (the spent coin's share) to its own settlement address, zero its state in
@@ -235,9 +235,9 @@ export function buildFactoryScript(participants, _options = {}) {
235
235
  }
236
236
  const count = participants.length;
237
237
  const pks = participants.map((p) => kissHex(p.publicKeyDigest));
238
- const payouts = participants.map((p) => kissHex(p.settlementAddress ?? p.publicKeyDigest));
238
+ const payouts = participants.map((p) => wotsAddressData(p.settlementAddress ?? p.publicKeyDigest));
239
239
  const lines = [
240
- 'LET SETTLEMENT=STATE(100)',
240
+ 'LET settlement=STATE(100)',
241
241
  `ASSERT SAMESTATE(${FACTORY_ESCAPE_PORT} ${FACTORY_ESCAPE_PORT})`,
242
242
  // RFC-048 §12.4/§12.5: the committed party-set root is immutable on every spend.
243
243
  `ASSERT SAMESTATE(${FACTORY_PARTY_ROOT_PORT} ${FACTORY_PARTY_ROOT_PORT})`,
@@ -245,10 +245,10 @@ export function buildFactoryScript(participants, _options = {}) {
245
245
  ];
246
246
  participants.forEach((_, k) => {
247
247
  const port = FACTORY_BALANCE_PORT_BASE + k;
248
- lines.push(` LET SHARE${k}=PREVSTATE(${port})`);
248
+ lines.push(` LET share=PREVSTATE(${port})`);
249
249
  lines.push(` IF SIGNEDBY(${pks[k]}) THEN`);
250
- lines.push(` IF SHARE${k} GT 0 THEN`);
251
- lines.push(` ASSERT VERIFYOUT(0 ${payouts[k]} SHARE${k} @TOKENID FALSE)`);
250
+ lines.push(` IF share GT 0 THEN`);
251
+ lines.push(` ASSERT VERIFYOUT(0 ${payouts[k]} share @TOKENID FALSE)`);
252
252
  for (let j = 0; j < count; j++) {
253
253
  if (j === k)
254
254
  continue;
@@ -258,8 +258,8 @@ export function buildFactoryScript(participants, _options = {}) {
258
258
  // Whole-share guard (mirrors the VTXO script): when the withdrawing party's
259
259
  // share is the entire output there is no remainder, so a 0-amount output is
260
260
  // never required.
261
- lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
262
- lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
261
+ lines.push(` IF @AMOUNT GT share THEN`);
262
+ lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT - share @TOKENID TRUE)`);
263
263
  lines.push(' ENDIF');
264
264
  lines.push(' RETURN TRUE');
265
265
  lines.push(' ENDIF');
@@ -267,12 +267,12 @@ export function buildFactoryScript(participants, _options = {}) {
267
267
  });
268
268
  lines.push('ENDIF');
269
269
  lines.push(`ASSERT MULTISIG(${count} ${pks.join(' ')})`);
270
- lines.push('IF SETTLEMENT THEN');
270
+ lines.push('IF settlement THEN');
271
271
  lines.push(' IF @COINAGE GTE 1 THEN RETURN TRUE ENDIF');
272
272
  lines.push('ELSE');
273
273
  lines.push(' RETURN TRUE');
274
274
  lines.push('ENDIF');
275
- return lines.join('\n');
275
+ return toNodeScript(lines.join('\n'));
276
276
  }
277
277
  export function normalizeScript(script) {
278
278
  return script.trim().toUpperCase();
@@ -1,6 +1,6 @@
1
1
  import { concatBytes } from '@totemsdk/core/wasm';
2
2
  import { serializeTxDraft, omniaDraftToMinimaBytes, computeTxDraftDigest, toRawMinima, verifyChannelSignature, } from '@totemsdk/omnia';
3
- import { mineTxPoW, TX_POW_MIN_DIFFICULTY, serializeTxBody } from '@totemsdk/txpow';
3
+ import { mineTxPoW, resolveTxPowTarget, serializeTxBody } from '@totemsdk/txpow';
4
4
  /**
5
5
  * Build the cooperative settlement TX + digest (no signing). Exported so peers
6
6
  * can independently rebuild and bind a proposal (RFC-035 B3).
@@ -115,8 +115,9 @@ export async function assembleFactorySettlement(factory, draft, signatures, chai
115
115
  };
116
116
  if (chainProvider) {
117
117
  const draftBytes = omniaDraftToMinimaBytes(draft.settlementDraft);
118
- const txBody = serializeTxBody(draftBytes, witnessBytes);
119
- const mined = await mineTxPoW(txBody, TX_POW_MIN_DIFFICULTY);
118
+ const txnDifficulty = await resolveTxPowTarget(chainProvider);
119
+ const txBody = serializeTxBody(draftBytes, witnessBytes, { txnDifficulty });
120
+ const mined = await mineTxPoW(txBody, txnDifficulty);
120
121
  const fullTxPoW = concatBytes(concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
121
122
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
122
123
  payload.txpowId = Buffer.from(mined.txpowId).toString('hex');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-factory",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
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,12 +24,12 @@
24
24
  "LICENSE"
25
25
  ],
26
26
  "dependencies": {
27
- "@totemsdk/core": "^1.3.0",
28
- "@totemsdk/omnia": "^2.0.1",
29
- "@totemsdk/tx-builder": "^0.2.1",
30
- "@totemsdk/txpow": "^1.0.2",
27
+ "@totemsdk/core": "^1.4.0",
28
+ "@totemsdk/omnia": "^2.2.0",
31
29
  "@totemsdk/wots-lease": "^1.0.1",
32
- "@totemsdk/chain-provider": "^0.2.1",
30
+ "@totemsdk/tx-builder": "^0.2.1",
31
+ "@totemsdk/txpow": "^1.1.0",
32
+ "@totemsdk/chain-provider": "^0.3.0",
33
33
  "@totemsdk/storage": "^0.1.0"
34
34
  },
35
35
  "devDependencies": {