@totemsdk/omnia-vtxo 0.5.4 → 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.
package/dist/anchor.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * real PoW.
9
9
  */
10
10
  import { computeOmniaTxDigest, omniaDraftToMinimaBytes, } from '@totemsdk/omnia';
11
- import { serializeTxBody, mineTxPoW, TX_POW_MIN_DIFFICULTY } from '@totemsdk/txpow';
11
+ import { serializeTxBody, mineTxPoW, resolveTxPowTarget } from '@totemsdk/txpow';
12
12
  import { concatBytes } from '@totemsdk/core';
13
13
  import { buildAndHashPoolScript, POOL_SHARE_PORT_BASE } from './pool-script.js';
14
14
  /** Pool output state: STATE(100)=root, STATE(101)=epoch, STATE(102)=exitBlock, STATE(300+k)=share k. */
@@ -75,8 +75,9 @@ export async function anchorBatch(params, deps) {
75
75
  if (deps.chainProvider) {
76
76
  const mine = deps.mine ?? ((txBody, difficulty) => mineTxPoW(txBody, difficulty));
77
77
  const draftBytes = omniaDraftToMinimaBytes(draft);
78
- const txBody = serializeTxBody(draftBytes, signature);
79
- const mined = await mine(txBody, TX_POW_MIN_DIFFICULTY);
78
+ const txnDifficulty = await resolveTxPowTarget(deps.chainProvider);
79
+ const txBody = serializeTxBody(draftBytes, signature, { txnDifficulty });
80
+ const mined = await mine(txBody, txnDifficulty);
80
81
  const fullTxPoW = concatBytes(concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
81
82
  await deps.chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
82
83
  result.txpowId = Buffer.from(mined.txpowId).toString('hex');
@@ -82,8 +82,9 @@ async function anchorBatch(params, deps) {
82
82
  if (deps.chainProvider) {
83
83
  const mine = deps.mine ?? ((txBody, difficulty) => (0, txpow_1.mineTxPoW)(txBody, difficulty));
84
84
  const draftBytes = (0, omnia_1.omniaDraftToMinimaBytes)(draft);
85
- const txBody = (0, txpow_1.serializeTxBody)(draftBytes, signature);
86
- const mined = await mine(txBody, txpow_1.TX_POW_MIN_DIFFICULTY);
85
+ const txnDifficulty = await (0, txpow_1.resolveTxPowTarget)(deps.chainProvider);
86
+ const txBody = (0, txpow_1.serializeTxBody)(draftBytes, signature, { txnDifficulty });
87
+ const mined = await mine(txBody, txnDifficulty);
87
88
  const fullTxPoW = (0, core_1.concatBytes)((0, core_1.concatBytes)(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
88
89
  await deps.chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
89
90
  result.txpowId = Buffer.from(mined.txpowId).toString('hex');
@@ -32,7 +32,7 @@ function buildExitTransactionDraft(params) {
32
32
  if (share <= 0n)
33
33
  throw new Error('exit: holder share must be positive');
34
34
  const outputs = [{
35
- address: params.vtxo.owner,
35
+ address: (0, core_1.wotsAddressData)(params.vtxo.owner),
36
36
  amount: share,
37
37
  tokenId: params.vtxo.tokenId,
38
38
  storeState: false,
@@ -13,7 +13,7 @@
13
13
  * (`STATE(base+k) EQ 0`) and returning the remainder to the pool. A holder
14
14
  * cannot pay itself more than its share, so one holder can never rug the others.
15
15
  * - **Cooperative update.** Before the exit window the pool may only move by
16
- * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
16
+ * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT epoch GT
17
17
  * PREVSTATE(101)`), with the exit block immutable (`ASSERT SAMESTATE(102
18
18
  * 102)`) so no one can push the escape clock, and value confined to the same
19
19
  * script address (`ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)`)
@@ -14,7 +14,7 @@
14
14
  * (`STATE(base+k) EQ 0`) and returning the remainder to the pool. A holder
15
15
  * cannot pay itself more than its share, so one holder can never rug the others.
16
16
  * - **Cooperative update.** Before the exit window the pool may only move by
17
- * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
17
+ * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT epoch GT
18
18
  * PREVSTATE(101)`), with the exit block immutable (`ASSERT SAMESTATE(102
19
19
  * 102)`) so no one can push the escape clock, and value confined to the same
20
20
  * script address (`ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)`)
@@ -48,7 +48,7 @@ function pkHex(digest, label) {
48
48
  if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
49
49
  throw new Error(`${label} public key digest must be 64 hex chars, got ${JSON.stringify(digest)}`);
50
50
  }
51
- return '0X' + raw.toUpperCase();
51
+ return '0x' + raw.toUpperCase();
52
52
  }
53
53
  /** Per-share-constrained, epoch-monotone, state-carrying pool script. */
54
54
  function buildPoolScript(params) {
@@ -60,20 +60,21 @@ function buildPoolScript(params) {
60
60
  throw new Error(`pool supports at most ${exports.POOL_MAX_HOLDERS} holders (got ${params.holders.length}) — share ports would reach the MSHS-2 band (≥${exports.MSHS_PORT_FLOOR})`);
61
61
  }
62
62
  const holders = params.holders.map((h, i) => pkHex(h, `holder[${i}]`));
63
+ const holderAddrs = params.holders.map((h) => (0, core_1.wotsAddressData)(h));
63
64
  if (!Number.isInteger(params.exitBlock) || params.exitBlock < 0) {
64
65
  throw new Error(`exitBlock must be a non-negative integer, got ${JSON.stringify(params.exitBlock)}`);
65
66
  }
66
67
  const lines = [
67
- 'LET EPOCH=STATE(101)',
68
- 'LET EXITBLOCK=PREVSTATE(102)',
69
- 'IF @BLOCK GT EXITBLOCK THEN',
68
+ 'LET epoch=STATE(101)',
69
+ 'LET exitblock=PREVSTATE(102)',
70
+ 'IF @BLOCK GT exitblock THEN',
70
71
  ];
71
72
  holders.forEach((holder, k) => {
72
73
  const port = exports.POOL_SHARE_PORT_BASE + k;
73
- lines.push(` LET SHARE${k}=PREVSTATE(${port})`);
74
+ lines.push(` LET share=PREVSTATE(${port})`);
74
75
  lines.push(` IF SIGNEDBY(${holder}) THEN`);
75
- lines.push(` IF SHARE${k} GT 0 THEN`);
76
- lines.push(` ASSERT VERIFYOUT(0 ${holder} SHARE${k} @TOKENID FALSE)`);
76
+ lines.push(` IF share GT 0 THEN`);
77
+ lines.push(` ASSERT VERIFYOUT(0 ${holderAddrs[k]} share @TOKENID FALSE)`);
77
78
  for (let j = 0; j < holders.length; j++) {
78
79
  if (j === k)
79
80
  continue;
@@ -82,19 +83,19 @@ function buildPoolScript(params) {
82
83
  lines.push(` ASSERT STATE(${port}) EQ 0`);
83
84
  // Remainder (other holders' shares) stays in the pool; skip it when the
84
85
  // withdrawing holder's share is the whole pool (no room for another output).
85
- lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
86
- lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
86
+ lines.push(` IF @AMOUNT GT share THEN`);
87
+ lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT - share @TOKENID TRUE)`);
87
88
  lines.push(' ENDIF');
88
89
  lines.push(' RETURN TRUE');
89
90
  lines.push(' ENDIF');
90
91
  lines.push(' ENDIF');
91
92
  });
92
93
  lines.push('ENDIF');
93
- lines.push('ASSERT EPOCH GT PREVSTATE(101)');
94
+ lines.push('ASSERT epoch GT PREVSTATE(101)');
94
95
  lines.push('ASSERT SAMESTATE(102 102)');
95
96
  lines.push('ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)');
96
97
  lines.push(`RETURN MULTISIG(${holders.length + 1} ${operator} ${holders.join(' ')})`);
97
- return lines.join('\n');
98
+ return (0, core_1.toNodeScript)(lines.join('\n'));
98
99
  }
99
100
  function poolScriptAddress(script) {
100
101
  return (0, core_1.computeScriptAddress)(script);
package/dist/exit-tx.js CHANGED
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import { computeOmniaTxDigest, omniaDraftToMinimaBytes, serializeTxDraft, } from '@totemsdk/omnia';
15
15
  import { serializeTxBody, mineTxPoW, TX_POW_MIN_DIFFICULTY } from '@totemsdk/txpow';
16
- import { concatBytes } from '@totemsdk/core';
16
+ import { concatBytes, wotsAddressData } from '@totemsdk/core';
17
17
  import { poolStateVariables } from './anchor.js';
18
18
  /** State port carrying an optional exit delay on the holder's output. */
19
19
  export const EXIT_DELAY_PORT = 110;
@@ -25,7 +25,7 @@ export function buildExitTransactionDraft(params) {
25
25
  if (share <= 0n)
26
26
  throw new Error('exit: holder share must be positive');
27
27
  const outputs = [{
28
- address: params.vtxo.owner,
28
+ address: wotsAddressData(params.vtxo.owner),
29
29
  amount: share,
30
30
  tokenId: params.vtxo.tokenId,
31
31
  storeState: false,
@@ -13,7 +13,7 @@
13
13
  * (`STATE(base+k) EQ 0`) and returning the remainder to the pool. A holder
14
14
  * cannot pay itself more than its share, so one holder can never rug the others.
15
15
  * - **Cooperative update.** Before the exit window the pool may only move by
16
- * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
16
+ * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT epoch GT
17
17
  * PREVSTATE(101)`), with the exit block immutable (`ASSERT SAMESTATE(102
18
18
  * 102)`) so no one can push the escape clock, and value confined to the same
19
19
  * script address (`ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)`)
@@ -13,7 +13,7 @@
13
13
  * (`STATE(base+k) EQ 0`) and returning the remainder to the pool. A holder
14
14
  * cannot pay itself more than its share, so one holder can never rug the others.
15
15
  * - **Cooperative update.** Before the exit window the pool may only move by
16
- * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
16
+ * `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT epoch GT
17
17
  * PREVSTATE(101)`), with the exit block immutable (`ASSERT SAMESTATE(102
18
18
  * 102)`) so no one can push the escape clock, and value confined to the same
19
19
  * script address (`ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)`)
@@ -22,7 +22,7 @@
22
22
  * The operator holds no unilateral path: it cannot move funds, cannot advance the
23
23
  * exit block, and cannot stop a holder's exit. It is a liveness-only peer.
24
24
  */
25
- import { computeScriptAddress } from '@totemsdk/core';
25
+ import { computeScriptAddress, toNodeScript, wotsAddressData } from '@totemsdk/core';
26
26
  /**
27
27
  * State port base for per-holder shares: holder k ⇒ `base + k`. Kept below the
28
28
  * MSHS-2 floor so Omnia ports never collide with MASH (ports are bytes, 0–255).
@@ -42,7 +42,7 @@ function pkHex(digest, label) {
42
42
  if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
43
43
  throw new Error(`${label} public key digest must be 64 hex chars, got ${JSON.stringify(digest)}`);
44
44
  }
45
- return '0X' + raw.toUpperCase();
45
+ return '0x' + raw.toUpperCase();
46
46
  }
47
47
  /** Per-share-constrained, epoch-monotone, state-carrying pool script. */
48
48
  export function buildPoolScript(params) {
@@ -54,20 +54,21 @@ export function buildPoolScript(params) {
54
54
  throw new Error(`pool supports at most ${POOL_MAX_HOLDERS} holders (got ${params.holders.length}) — share ports would reach the MSHS-2 band (≥${MSHS_PORT_FLOOR})`);
55
55
  }
56
56
  const holders = params.holders.map((h, i) => pkHex(h, `holder[${i}]`));
57
+ const holderAddrs = params.holders.map((h) => wotsAddressData(h));
57
58
  if (!Number.isInteger(params.exitBlock) || params.exitBlock < 0) {
58
59
  throw new Error(`exitBlock must be a non-negative integer, got ${JSON.stringify(params.exitBlock)}`);
59
60
  }
60
61
  const lines = [
61
- 'LET EPOCH=STATE(101)',
62
- 'LET EXITBLOCK=PREVSTATE(102)',
63
- 'IF @BLOCK GT EXITBLOCK THEN',
62
+ 'LET epoch=STATE(101)',
63
+ 'LET exitblock=PREVSTATE(102)',
64
+ 'IF @BLOCK GT exitblock THEN',
64
65
  ];
65
66
  holders.forEach((holder, k) => {
66
67
  const port = POOL_SHARE_PORT_BASE + k;
67
- lines.push(` LET SHARE${k}=PREVSTATE(${port})`);
68
+ lines.push(` LET share=PREVSTATE(${port})`);
68
69
  lines.push(` IF SIGNEDBY(${holder}) THEN`);
69
- lines.push(` IF SHARE${k} GT 0 THEN`);
70
- lines.push(` ASSERT VERIFYOUT(0 ${holder} SHARE${k} @TOKENID FALSE)`);
70
+ lines.push(` IF share GT 0 THEN`);
71
+ lines.push(` ASSERT VERIFYOUT(0 ${holderAddrs[k]} share @TOKENID FALSE)`);
71
72
  for (let j = 0; j < holders.length; j++) {
72
73
  if (j === k)
73
74
  continue;
@@ -76,19 +77,19 @@ export function buildPoolScript(params) {
76
77
  lines.push(` ASSERT STATE(${port}) EQ 0`);
77
78
  // Remainder (other holders' shares) stays in the pool; skip it when the
78
79
  // withdrawing holder's share is the whole pool (no room for another output).
79
- lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
80
- lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
80
+ lines.push(` IF @AMOUNT GT share THEN`);
81
+ lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT - share @TOKENID TRUE)`);
81
82
  lines.push(' ENDIF');
82
83
  lines.push(' RETURN TRUE');
83
84
  lines.push(' ENDIF');
84
85
  lines.push(' ENDIF');
85
86
  });
86
87
  lines.push('ENDIF');
87
- lines.push('ASSERT EPOCH GT PREVSTATE(101)');
88
+ lines.push('ASSERT epoch GT PREVSTATE(101)');
88
89
  lines.push('ASSERT SAMESTATE(102 102)');
89
90
  lines.push('ASSERT VERIFYOUT(@INPUT @ADDRESS @AMOUNT @TOKENID TRUE)');
90
91
  lines.push(`RETURN MULTISIG(${holders.length + 1} ${operator} ${holders.join(' ')})`);
91
- return lines.join('\n');
92
+ return toNodeScript(lines.join('\n'));
92
93
  }
93
94
  export function poolScriptAddress(script) {
94
95
  return computeScriptAddress(script);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-vtxo",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
4
4
  "description": "Virtual UTXO / payment-pool claim layer for Omnia — cash-like off-chain balance primitive for Totem Edge",
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/chain-provider": "^0.2.1",
28
- "@totemsdk/core": "^1.3.0",
29
- "@totemsdk/omnia": "^2.0.1",
27
+ "@totemsdk/chain-provider": "^0.3.0",
28
+ "@totemsdk/core": "^1.4.0",
29
+ "@totemsdk/txpow": "^1.1.0",
30
30
  "@totemsdk/storage": "^0.1.0",
31
- "@totemsdk/txpow": "^1.0.2",
31
+ "@totemsdk/omnia": "^2.2.0",
32
32
  "@totemsdk/wots-lease": "^1.0.1"
33
33
  },
34
34
  "devDependencies": {