@totemsdk/omnia-vtxo 0.5.1 → 0.5.3
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/pool-script.d.ts +13 -5
- package/dist/cjs/pool-script.js +18 -7
- package/dist/pool-script.d.ts +13 -5
- package/dist/pool-script.js +17 -6
- package/package.json +2 -2
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* The pool is an on-chain state output holding `totalCapacity`. An epoch's batch
|
|
5
5
|
* root is committed as STATE(100), the epoch number in STATE(101), the absolute
|
|
6
6
|
* exit-eligibility block in STATE(102), and each holder's committed share in
|
|
7
|
-
* STATE(
|
|
7
|
+
* STATE(base+k).
|
|
8
8
|
*
|
|
9
9
|
* Custody (RFC-039 / CUSTODY-POLICY §2):
|
|
10
10
|
* - **Per-share unilateral exit.** After `@BLOCK GT PREVSTATE(102)` each holder
|
|
11
|
-
* may withdraw **only its own committed share** (`PREVSTATE(
|
|
11
|
+
* may withdraw **only its own committed share** (`PREVSTATE(base+k)`, the spent
|
|
12
12
|
* coin's share), to its own key, zeroing that share in the successor
|
|
13
|
-
* (`STATE(
|
|
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
16
|
* `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
|
|
@@ -22,8 +22,16 @@
|
|
|
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
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* State port base for per-holder shares: holder k ⇒ `base + k`. Kept below the
|
|
27
|
+
* MSHS-2 floor so Omnia ports never collide with MASH (ports are bytes, 0–255).
|
|
28
|
+
* See RFC-048 §12 / RFC-049 §5.
|
|
29
|
+
*/
|
|
30
|
+
export declare const POOL_SHARE_PORT_BASE = 128;
|
|
31
|
+
/** Lowest port reserved for MSHS-2 (MASH); Omnia ports MUST stay below this. */
|
|
32
|
+
export declare const MSHS_PORT_FLOOR = 234;
|
|
33
|
+
/** Maximum holders whose share ports remain below the MSHS floor. */
|
|
34
|
+
export declare const POOL_MAX_HOLDERS: number;
|
|
27
35
|
export interface PoolScriptParams {
|
|
28
36
|
/** Operator WOTS public-key digest (64 hex). */
|
|
29
37
|
operatorPublicKeyDigest: string;
|
package/dist/cjs/pool-script.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* The pool is an on-chain state output holding `totalCapacity`. An epoch's batch
|
|
6
6
|
* root is committed as STATE(100), the epoch number in STATE(101), the absolute
|
|
7
7
|
* exit-eligibility block in STATE(102), and each holder's committed share in
|
|
8
|
-
* STATE(
|
|
8
|
+
* STATE(base+k).
|
|
9
9
|
*
|
|
10
10
|
* Custody (RFC-039 / CUSTODY-POLICY §2):
|
|
11
11
|
* - **Per-share unilateral exit.** After `@BLOCK GT PREVSTATE(102)` each holder
|
|
12
|
-
* may withdraw **only its own committed share** (`PREVSTATE(
|
|
12
|
+
* may withdraw **only its own committed share** (`PREVSTATE(base+k)`, the spent
|
|
13
13
|
* coin's share), to its own key, zeroing that share in the successor
|
|
14
|
-
* (`STATE(
|
|
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
17
|
* `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
|
|
@@ -24,13 +24,21 @@
|
|
|
24
24
|
* exit block, and cannot stop a holder's exit. It is a liveness-only peer.
|
|
25
25
|
*/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.POOL_SHARE_PORT_BASE = void 0;
|
|
27
|
+
exports.POOL_MAX_HOLDERS = exports.MSHS_PORT_FLOOR = exports.POOL_SHARE_PORT_BASE = void 0;
|
|
28
28
|
exports.buildPoolScript = buildPoolScript;
|
|
29
29
|
exports.poolScriptAddress = poolScriptAddress;
|
|
30
30
|
exports.buildAndHashPoolScript = buildAndHashPoolScript;
|
|
31
31
|
const core_1 = require("@totemsdk/core");
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* State port base for per-holder shares: holder k ⇒ `base + k`. Kept below the
|
|
34
|
+
* MSHS-2 floor so Omnia ports never collide with MASH (ports are bytes, 0–255).
|
|
35
|
+
* See RFC-048 §12 / RFC-049 §5.
|
|
36
|
+
*/
|
|
37
|
+
exports.POOL_SHARE_PORT_BASE = 128;
|
|
38
|
+
/** Lowest port reserved for MSHS-2 (MASH); Omnia ports MUST stay below this. */
|
|
39
|
+
exports.MSHS_PORT_FLOOR = 234;
|
|
40
|
+
/** Maximum holders whose share ports remain below the MSHS floor. */
|
|
41
|
+
exports.POOL_MAX_HOLDERS = exports.MSHS_PORT_FLOOR - exports.POOL_SHARE_PORT_BASE;
|
|
34
42
|
function pkHex(digest, label) {
|
|
35
43
|
const raw = digest.replace(/^0x/i, '');
|
|
36
44
|
if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
|
|
@@ -44,6 +52,9 @@ function buildPoolScript(params) {
|
|
|
44
52
|
if (!Array.isArray(params.holders) || params.holders.length < 1) {
|
|
45
53
|
throw new Error('pool requires at least one holder');
|
|
46
54
|
}
|
|
55
|
+
if (params.holders.length > exports.POOL_MAX_HOLDERS) {
|
|
56
|
+
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})`);
|
|
57
|
+
}
|
|
47
58
|
const holders = params.holders.map((h, i) => pkHex(h, `holder[${i}]`));
|
|
48
59
|
if (!Number.isInteger(params.exitBlock) || params.exitBlock < 0) {
|
|
49
60
|
throw new Error(`exitBlock must be a non-negative integer, got ${JSON.stringify(params.exitBlock)}`);
|
|
@@ -68,7 +79,7 @@ function buildPoolScript(params) {
|
|
|
68
79
|
// Remainder (other holders' shares) stays in the pool; skip it when the
|
|
69
80
|
// withdrawing holder's share is the whole pool (no room for another output).
|
|
70
81
|
lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
|
|
71
|
-
lines.push(` RETURN VERIFYOUT(
|
|
82
|
+
lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
|
|
72
83
|
lines.push(' ENDIF');
|
|
73
84
|
lines.push(' RETURN TRUE');
|
|
74
85
|
lines.push(' ENDIF');
|
package/dist/pool-script.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* The pool is an on-chain state output holding `totalCapacity`. An epoch's batch
|
|
5
5
|
* root is committed as STATE(100), the epoch number in STATE(101), the absolute
|
|
6
6
|
* exit-eligibility block in STATE(102), and each holder's committed share in
|
|
7
|
-
* STATE(
|
|
7
|
+
* STATE(base+k).
|
|
8
8
|
*
|
|
9
9
|
* Custody (RFC-039 / CUSTODY-POLICY §2):
|
|
10
10
|
* - **Per-share unilateral exit.** After `@BLOCK GT PREVSTATE(102)` each holder
|
|
11
|
-
* may withdraw **only its own committed share** (`PREVSTATE(
|
|
11
|
+
* may withdraw **only its own committed share** (`PREVSTATE(base+k)`, the spent
|
|
12
12
|
* coin's share), to its own key, zeroing that share in the successor
|
|
13
|
-
* (`STATE(
|
|
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
16
|
* `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
|
|
@@ -22,8 +22,16 @@
|
|
|
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
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* State port base for per-holder shares: holder k ⇒ `base + k`. Kept below the
|
|
27
|
+
* MSHS-2 floor so Omnia ports never collide with MASH (ports are bytes, 0–255).
|
|
28
|
+
* See RFC-048 §12 / RFC-049 §5.
|
|
29
|
+
*/
|
|
30
|
+
export declare const POOL_SHARE_PORT_BASE = 128;
|
|
31
|
+
/** Lowest port reserved for MSHS-2 (MASH); Omnia ports MUST stay below this. */
|
|
32
|
+
export declare const MSHS_PORT_FLOOR = 234;
|
|
33
|
+
/** Maximum holders whose share ports remain below the MSHS floor. */
|
|
34
|
+
export declare const POOL_MAX_HOLDERS: number;
|
|
27
35
|
export interface PoolScriptParams {
|
|
28
36
|
/** Operator WOTS public-key digest (64 hex). */
|
|
29
37
|
operatorPublicKeyDigest: string;
|
package/dist/pool-script.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* The pool is an on-chain state output holding `totalCapacity`. An epoch's batch
|
|
5
5
|
* root is committed as STATE(100), the epoch number in STATE(101), the absolute
|
|
6
6
|
* exit-eligibility block in STATE(102), and each holder's committed share in
|
|
7
|
-
* STATE(
|
|
7
|
+
* STATE(base+k).
|
|
8
8
|
*
|
|
9
9
|
* Custody (RFC-039 / CUSTODY-POLICY §2):
|
|
10
10
|
* - **Per-share unilateral exit.** After `@BLOCK GT PREVSTATE(102)` each holder
|
|
11
|
-
* may withdraw **only its own committed share** (`PREVSTATE(
|
|
11
|
+
* may withdraw **only its own committed share** (`PREVSTATE(base+k)`, the spent
|
|
12
12
|
* coin's share), to its own key, zeroing that share in the successor
|
|
13
|
-
* (`STATE(
|
|
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
16
|
* `MULTISIG(operator + all holders)`, epoch-monotone (`ASSERT EPOCH GT
|
|
@@ -23,8 +23,16 @@
|
|
|
23
23
|
* exit block, and cannot stop a holder's exit. It is a liveness-only peer.
|
|
24
24
|
*/
|
|
25
25
|
import { computeScriptAddress } from '@totemsdk/core';
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* State port base for per-holder shares: holder k ⇒ `base + k`. Kept below the
|
|
28
|
+
* MSHS-2 floor so Omnia ports never collide with MASH (ports are bytes, 0–255).
|
|
29
|
+
* See RFC-048 §12 / RFC-049 §5.
|
|
30
|
+
*/
|
|
31
|
+
export const POOL_SHARE_PORT_BASE = 128;
|
|
32
|
+
/** Lowest port reserved for MSHS-2 (MASH); Omnia ports MUST stay below this. */
|
|
33
|
+
export const MSHS_PORT_FLOOR = 234;
|
|
34
|
+
/** Maximum holders whose share ports remain below the MSHS floor. */
|
|
35
|
+
export const POOL_MAX_HOLDERS = MSHS_PORT_FLOOR - POOL_SHARE_PORT_BASE;
|
|
28
36
|
function pkHex(digest, label) {
|
|
29
37
|
const raw = digest.replace(/^0x/i, '');
|
|
30
38
|
if (!/^[0-9a-fA-F]{64}$/.test(raw)) {
|
|
@@ -38,6 +46,9 @@ export function buildPoolScript(params) {
|
|
|
38
46
|
if (!Array.isArray(params.holders) || params.holders.length < 1) {
|
|
39
47
|
throw new Error('pool requires at least one holder');
|
|
40
48
|
}
|
|
49
|
+
if (params.holders.length > POOL_MAX_HOLDERS) {
|
|
50
|
+
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})`);
|
|
51
|
+
}
|
|
41
52
|
const holders = params.holders.map((h, i) => pkHex(h, `holder[${i}]`));
|
|
42
53
|
if (!Number.isInteger(params.exitBlock) || params.exitBlock < 0) {
|
|
43
54
|
throw new Error(`exitBlock must be a non-negative integer, got ${JSON.stringify(params.exitBlock)}`);
|
|
@@ -62,7 +73,7 @@ export function buildPoolScript(params) {
|
|
|
62
73
|
// Remainder (other holders' shares) stays in the pool; skip it when the
|
|
63
74
|
// withdrawing holder's share is the whole pool (no room for another output).
|
|
64
75
|
lines.push(` IF @AMOUNT GT SHARE${k} THEN`);
|
|
65
|
-
lines.push(` RETURN VERIFYOUT(
|
|
76
|
+
lines.push(` RETURN VERIFYOUT(1 @ADDRESS @AMOUNT SUB SHARE${k} @TOKENID TRUE)`);
|
|
66
77
|
lines.push(' ENDIF');
|
|
67
78
|
lines.push(' RETURN TRUE');
|
|
68
79
|
lines.push(' ENDIF');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-vtxo",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@totemsdk/chain-provider": "^0.2.1",
|
|
28
|
-
"@totemsdk/core": "^1.3.0",
|
|
29
28
|
"@totemsdk/omnia": "^2.0.1",
|
|
30
29
|
"@totemsdk/storage": "^0.1.0",
|
|
31
30
|
"@totemsdk/txpow": "^1.0.2",
|
|
31
|
+
"@totemsdk/core": "^1.3.0",
|
|
32
32
|
"@totemsdk/wots-lease": "^1.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|