@totemsdk/omnia-vtxo 0.6.1 → 0.7.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.
Files changed (52) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +60 -0
  3. package/README.md +1 -1
  4. package/dist/anchor.d.ts +14 -2
  5. package/dist/anchor.js +33 -10
  6. package/dist/cjs/anchor.d.ts +14 -2
  7. package/dist/cjs/anchor.js +32 -9
  8. package/dist/cjs/claim-policy.d.ts +94 -0
  9. package/dist/cjs/claim-policy.js +149 -0
  10. package/dist/cjs/commitment.d.ts +12 -0
  11. package/dist/cjs/commitment.js +21 -1
  12. package/dist/cjs/durable-store.js +8 -0
  13. package/dist/cjs/exit-entitlement.d.ts +35 -0
  14. package/dist/cjs/exit-entitlement.js +70 -0
  15. package/dist/cjs/exit-tx.d.ts +6 -0
  16. package/dist/cjs/exit-tx.js +31 -10
  17. package/dist/cjs/index.d.ts +4 -0
  18. package/dist/cjs/index.js +4 -0
  19. package/dist/cjs/memory-store.js +8 -0
  20. package/dist/cjs/owner-pool.d.ts +95 -0
  21. package/dist/cjs/owner-pool.js +194 -0
  22. package/dist/cjs/receipt.d.ts +8 -1
  23. package/dist/cjs/receipt.js +29 -7
  24. package/dist/cjs/transfer.d.ts +20 -0
  25. package/dist/cjs/transfer.js +39 -0
  26. package/dist/cjs/types.d.ts +8 -0
  27. package/dist/cjs/yield.d.ts +2 -0
  28. package/dist/cjs/yield.js +26 -0
  29. package/dist/claim-policy.d.ts +94 -0
  30. package/dist/claim-policy.js +144 -0
  31. package/dist/commitment.d.ts +12 -0
  32. package/dist/commitment.js +18 -0
  33. package/dist/durable-store.js +8 -0
  34. package/dist/exit-entitlement.d.ts +35 -0
  35. package/dist/exit-entitlement.js +66 -0
  36. package/dist/exit-tx.d.ts +6 -0
  37. package/dist/exit-tx.js +32 -11
  38. package/dist/index.d.ts +4 -0
  39. package/dist/index.js +4 -0
  40. package/dist/memory-store.js +8 -0
  41. package/dist/owner-pool.d.ts +95 -0
  42. package/dist/owner-pool.js +183 -0
  43. package/dist/receipt.d.ts +8 -1
  44. package/dist/receipt.js +28 -8
  45. package/dist/transfer.d.ts +20 -0
  46. package/dist/transfer.js +38 -0
  47. package/dist/types.d.ts +8 -0
  48. package/dist/yield.d.ts +2 -0
  49. package/dist/yield.js +23 -0
  50. package/package.json +9 -7
  51. package/rust/pkg/package.json +1 -1
  52. package/rust/pkg-node/package.json +1 -1
@@ -0,0 +1,183 @@
1
+ /**
2
+ * V1 transferable owner-pool covenant.
3
+ *
4
+ * A single-owner claim coin whose **current owner is committed in state**, not
5
+ * in the script. The owner can:
6
+ *
7
+ * - transfer the whole coin by signing a state update that recreates it at
8
+ * the same address/amount with a new owner (epoch increments); or
9
+ * - exit after `exitBlock` to the committed owner address, with no operator
10
+ * signature or liveness.
11
+ *
12
+ * The script authenticates the **previous** committed owner
13
+ * (`SIGNEDBY(PREVSTATE(103))`), so a spender cannot substitute their own key.
14
+ * `PREVSTATE(104)` is the committed payout address. This is the V1 recovery
15
+ * path: a recipient holds a coin they can spend unilaterally.
16
+ */
17
+ import { computeScriptAddress, toNodeScript, wotsAddressData } from '@totemsdk/core';
18
+ export const OWNER_POOL_ROOT_PORT = 100;
19
+ export const OWNER_POOL_EPOCH_PORT = 101;
20
+ export const OWNER_POOL_EXIT_BLOCK_PORT = 102;
21
+ export const OWNER_POOL_PK_PORT = 103;
22
+ export const OWNER_POOL_ADDR_PORT = 104;
23
+ /** Derive the committed payout address from an owner public-key digest. */
24
+ export function ownerAddressFor(ownerPk) {
25
+ return wotsAddressData(ownerPk);
26
+ }
27
+ /**
28
+ * The transferable owner-pool script. State ports 100–104 are the only state;
29
+ * there are no fixed holder constants.
30
+ */
31
+ export function buildOwnerPoolScript() {
32
+ return toNodeScript([
33
+ // Unilateral exit: only the previously committed owner, only after the
34
+ // committed block, and only to the committed owner address.
35
+ 'IF @BLOCK GT PREVSTATE(102) THEN',
36
+ ' ASSERT SIGNEDBY(PREVSTATE(103))',
37
+ ' ASSERT VERIFYOUT(0 PREVSTATE(104) @AMOUNT @TOKENID FALSE)',
38
+ ' RETURN TRUE',
39
+ 'ENDIF',
40
+ // Transfer: the previous owner authorizes a new owner. Root and exit block
41
+ // are immutable; the coin stays at the same address with the same amount.
42
+ 'ASSERT SIGNEDBY(PREVSTATE(103))',
43
+ 'ASSERT STATE(101) GT PREVSTATE(101)',
44
+ 'ASSERT STATE(100) EQ PREVSTATE(100)',
45
+ 'ASSERT STATE(102) EQ PREVSTATE(102)',
46
+ 'ASSERT STATE(103) NEQ PREVSTATE(103)',
47
+ 'ASSERT STATE(103) NEQ 0x00',
48
+ 'ASSERT STATE(104) NEQ 0x00',
49
+ 'ASSERT VERIFYOUT(0 @ADDRESS @AMOUNT @TOKENID TRUE)',
50
+ 'RETURN TRUE',
51
+ ].join('\n'));
52
+ }
53
+ export function buildOwnerPoolState(state) {
54
+ if (!Number.isInteger(state.exitBlock) || state.exitBlock < 0) {
55
+ throw new Error(`owner pool: invalid exitBlock ${String(state.exitBlock)}`);
56
+ }
57
+ if (!/^0x[0-9a-fA-F]{64}$/.test(state.ownerPk)) {
58
+ throw new Error('owner pool: ownerPk must be a 0x-prefixed 32-byte hex digest');
59
+ }
60
+ if (!state.ownerAddr)
61
+ throw new Error('owner pool: ownerAddr is required');
62
+ return [
63
+ { port: OWNER_POOL_ROOT_PORT, value: state.root, type: 'string' },
64
+ { port: OWNER_POOL_EPOCH_PORT, value: BigInt(state.epoch), type: 'number' },
65
+ { port: OWNER_POOL_EXIT_BLOCK_PORT, value: BigInt(state.exitBlock), type: 'number' },
66
+ { port: OWNER_POOL_PK_PORT, value: state.ownerPk, type: 'string' },
67
+ { port: OWNER_POOL_ADDR_PORT, value: state.ownerAddr, type: 'string' },
68
+ ];
69
+ }
70
+ export function ownerPoolAddress() {
71
+ return computeScriptAddress(buildOwnerPoolScript());
72
+ }
73
+ /**
74
+ * Build the transfer transaction: same script address, same amount/token,
75
+ * new owner state and a higher epoch.
76
+ */
77
+ export function buildOwnerTransferDraft(params) {
78
+ if (params.to.epoch <= params.from.epoch) {
79
+ throw new Error('owner transfer: new epoch must be greater than the previous epoch');
80
+ }
81
+ if (params.to.exitBlock !== params.from.exitBlock) {
82
+ throw new Error('owner transfer: exitBlock is immutable');
83
+ }
84
+ if (params.to.ownerAddr !== ownerAddressFor(params.to.ownerPk)) {
85
+ throw new Error('owner transfer: ownerAddr must be derived from ownerPk');
86
+ }
87
+ return {
88
+ type: 'settlement',
89
+ inputs: [{
90
+ coinId: params.coin.coinId,
91
+ address: params.coin.address,
92
+ amount: params.coin.amount,
93
+ tokenId: params.coin.tokenId,
94
+ scriptHex: params.coin.scriptHex ?? buildOwnerPoolScript(),
95
+ ...(params.coin.mmrEntry !== undefined ? { mmrEntry: params.coin.mmrEntry } : {}),
96
+ }],
97
+ outputs: [{
98
+ address: params.coin.address,
99
+ amount: params.coin.amount,
100
+ tokenId: params.coin.tokenId,
101
+ storeState: true,
102
+ stateVariables: buildOwnerPoolState(params.to),
103
+ }],
104
+ storeState: true,
105
+ stateVariables: buildOwnerPoolState(params.to),
106
+ };
107
+ }
108
+ /** Build the unilateral exit: full amount to the committed owner address. */
109
+ export function buildOwnerExitDraft(params) {
110
+ if (params.state.ownerAddr !== ownerAddressFor(params.state.ownerPk)) {
111
+ throw new Error('owner exit: ownerAddr must be derived from ownerPk');
112
+ }
113
+ return {
114
+ type: 'settlement',
115
+ inputs: [{
116
+ coinId: params.coin.coinId,
117
+ address: params.coin.address,
118
+ amount: params.coin.amount,
119
+ tokenId: params.coin.tokenId,
120
+ scriptHex: params.coin.scriptHex ?? buildOwnerPoolScript(),
121
+ ...(params.coin.mmrEntry !== undefined ? { mmrEntry: params.coin.mmrEntry } : {}),
122
+ }],
123
+ outputs: [{
124
+ address: params.state.ownerAddr,
125
+ amount: params.coin.amount,
126
+ tokenId: params.coin.tokenId,
127
+ storeState: false,
128
+ stateVariables: [],
129
+ }],
130
+ storeState: false,
131
+ stateVariables: [],
132
+ };
133
+ }
134
+ // ── Signed transaction assembly ───────────────────────────────────────────────
135
+ import { computeOmniaTxDigest, omniaDraftToMinimaBytes, serializeOmniaWitness, serializeTxDraft, } from '@totemsdk/omnia';
136
+ import { concatBytes } from '@totemsdk/core';
137
+ import { serializeTxBody, mineTxPoW, TX_POW_MIN_DIFFICULTY } from '@totemsdk/txpow';
138
+ async function assembleOwnerPoolTx(draft, kind, state, deps) {
139
+ const digest = computeOmniaTxDigest(draft);
140
+ const signature = await deps.signDigest(digest);
141
+ const witness = serializeOmniaWitness({
142
+ signatures: [signature],
143
+ coinProofs: deps.coinProofs ?? [],
144
+ scriptProofs: deps.scriptProofs ?? [],
145
+ });
146
+ const result = {
147
+ kind,
148
+ txHex: serializeTxDraft(draft),
149
+ digest: Buffer.from(digest).toString('hex'),
150
+ witnessHex: Buffer.from(witness).toString('hex'),
151
+ state,
152
+ };
153
+ if (deps.chainProvider) {
154
+ const draftBytes = omniaDraftToMinimaBytes(draft);
155
+ if (typeof deps.chainProvider.submitTransaction === 'function') {
156
+ const submitted = await deps.chainProvider.submitTransaction(draftBytes, witness);
157
+ if (submitted?.success === false) {
158
+ throw new Error(`owner-pool submit failed: ${submitted.message ?? 'unknown error'}`);
159
+ }
160
+ result.txpowId = submitted?.txpowid;
161
+ }
162
+ else {
163
+ const mine = deps.mine ?? ((txBody, difficulty) => mineTxPoW(txBody, difficulty));
164
+ const txBody = serializeTxBody(draftBytes, witness);
165
+ const mined = await mine(txBody, TX_POW_MIN_DIFFICULTY);
166
+ const fullTxPoW = concatBytes(concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01])), txBody);
167
+ const broadcast = await deps.chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
168
+ if (broadcast?.success === false) {
169
+ throw new Error(`owner-pool broadcast failed: ${broadcast.message ?? 'unknown error'}`);
170
+ }
171
+ result.txpowId = broadcast?.txpowid ?? Buffer.from(mined.txpowId).toString('hex');
172
+ }
173
+ }
174
+ return result;
175
+ }
176
+ /** Sign and assemble the owner-rotation transfer transaction. */
177
+ export async function buildOwnerTransferTransaction(params, deps) {
178
+ return assembleOwnerPoolTx(buildOwnerTransferDraft(params), 'owner-transfer', params.to, deps);
179
+ }
180
+ /** Sign and assemble the unilateral owner exit transaction. */
181
+ export async function buildOwnerExitTransaction(params, deps) {
182
+ return assembleOwnerPoolTx(buildOwnerExitDraft(params), 'owner-exit', params.state, deps);
183
+ }
package/dist/receipt.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * conservation. This prevents a caller from getting the operator to co-sign an
8
8
  * arbitrary `(root, epoch, ids)` tuple whose root does not commit the outputs.
9
9
  */
10
- import type { OmniaVtxo, OmniaVtxoOperator, VtxoOperatorReceipt } from './types.js';
10
+ import type { OmniaVtxo, OmniaVtxoOperator, OmniaVtxoPool, VtxoOperatorReceipt } from './types.js';
11
11
  /** The batch the receipt belongs to — the operator's source of truth. */
12
12
  export interface VtxoReceiptBatch {
13
13
  /** The VTXOs committed in this epoch's batch. */
@@ -26,6 +26,13 @@ export interface VtxoReceiptBatch {
26
26
  * @throws if the root does not commit the leaves, the epoch is stale, an output
27
27
  * is not in the batch, or conservation fails.
28
28
  */
29
+ export declare function buildVtxoReceiptPayload(receipt: VtxoOperatorReceipt, batch: VtxoReceiptBatch): Uint8Array;
29
30
  export declare function signVtxoReceipt(operator: OmniaVtxoOperator, receipt: VtxoOperatorReceipt, batch: VtxoReceiptBatch): Promise<VtxoOperatorReceipt>;
30
31
  /** Verify a co-signed receipt against the operator and the batch root. */
31
32
  export declare function verifyVtxoReceipt(operator: OmniaVtxoOperator, receipt: VtxoOperatorReceipt, root: string): Promise<boolean>;
33
+ /**
34
+ * Verify a receipt against the pool's current anchored state, not a
35
+ * caller-supplied root. Rejects a receipt from another pool/epoch and requires
36
+ * the pool's committed root to be present.
37
+ */
38
+ export declare function verifyVtxoReceiptForPool(operator: OmniaVtxoOperator, receipt: VtxoOperatorReceipt, pool: Pick<OmniaVtxoPool, 'poolId' | 'epoch' | 'commitmentRoot'>): Promise<boolean>;
package/dist/receipt.js CHANGED
@@ -7,13 +7,13 @@
7
7
  * conservation. This prevents a caller from getting the operator to co-sign an
8
8
  * arbitrary `(root, epoch, ids)` tuple whose root does not commit the outputs.
9
9
  */
10
- import { computeBatchCommitmentBytes, computeCommitmentRoot, computeVtxoLeaf } from './commitment.js';
10
+ import { computeCommitmentRoot, computeVtxoLeaf, computeVtxoReceiptCommitmentBytes } from './commitment.js';
11
11
  /**
12
12
  * Co-sign a receipt with the operator, after verifying the batch.
13
13
  * @throws if the root does not commit the leaves, the epoch is stale, an output
14
14
  * is not in the batch, or conservation fails.
15
15
  */
16
- export async function signVtxoReceipt(operator, receipt, batch) {
16
+ export function buildVtxoReceiptPayload(receipt, batch) {
17
17
  if (receipt.epoch !== batch.epoch) {
18
18
  throw new Error(`receipt epoch ${receipt.epoch} does not match batch epoch ${batch.epoch}`);
19
19
  }
@@ -29,13 +29,19 @@ export async function signVtxoReceipt(operator, receipt, batch) {
29
29
  if (recomputedRoot !== batch.root) {
30
30
  throw new Error('batch root does not commit the batch leaves');
31
31
  }
32
- if (batch.inputsAmount !== undefined) {
33
- const outputSum = batch.outputs.reduce((sum, v) => sum + v.amount, 0n);
34
- if (outputSum > batch.inputsAmount) {
35
- throw new Error(`conservation violated: outputs ${outputSum} exceed inputs ${batch.inputsAmount}`);
32
+ const outputSum = batch.outputs.reduce((sum, v) => sum + v.amount, 0n);
33
+ if (receipt.op !== 'mint') {
34
+ if (batch.inputsAmount === undefined) {
35
+ throw new Error(`conservation required for ${receipt.op} receipts`);
36
+ }
37
+ if (outputSum !== batch.inputsAmount) {
38
+ throw new Error(`conservation violated: outputs ${outputSum} != inputs ${batch.inputsAmount}`);
36
39
  }
37
40
  }
38
- const data = computeBatchCommitmentBytes(receipt.poolId, receipt.epoch, batch.root, receipt.outputIds);
41
+ return computeVtxoReceiptCommitmentBytes(receipt, batch.root);
42
+ }
43
+ export async function signVtxoReceipt(operator, receipt, batch) {
44
+ const data = buildVtxoReceiptPayload(receipt, batch);
39
45
  const signature = await operator.sign(data);
40
46
  return { ...receipt, signature };
41
47
  }
@@ -43,6 +49,20 @@ export async function signVtxoReceipt(operator, receipt, batch) {
43
49
  export async function verifyVtxoReceipt(operator, receipt, root) {
44
50
  if (!receipt.signature)
45
51
  return false;
46
- const data = computeBatchCommitmentBytes(receipt.poolId, receipt.epoch, root, receipt.outputIds);
52
+ const data = computeVtxoReceiptCommitmentBytes(receipt, root);
47
53
  return operator.verify(data, receipt.signature);
48
54
  }
55
+ /**
56
+ * Verify a receipt against the pool's current anchored state, not a
57
+ * caller-supplied root. Rejects a receipt from another pool/epoch and requires
58
+ * the pool's committed root to be present.
59
+ */
60
+ export async function verifyVtxoReceiptForPool(operator, receipt, pool) {
61
+ if (receipt.poolId !== pool.poolId)
62
+ return false;
63
+ if (receipt.epoch !== pool.epoch)
64
+ return false;
65
+ if (!pool.commitmentRoot)
66
+ return false;
67
+ return verifyVtxoReceipt(operator, receipt, pool.commitmentRoot);
68
+ }
@@ -1,8 +1,28 @@
1
1
  import { OmniaVtxo, TransferVtxoParams, TransferResult, VtxoOperatorReceipt } from './types.js';
2
+ import { type VtxoExitEntitlement } from './exit-entitlement.js';
3
+ import { type ExitTxParams, type ExitTxDeps } from './exit-tx.js';
2
4
  /**
3
5
  * Transfers a VTXO (fully or partially) to a recipient.
6
+ *
7
+ * **Offline safety.** The returned output VTXOs are new claims. A Merkle proof
8
+ * establishes membership in a committed set; it does NOT prove the input was
9
+ * never spent elsewhere. The local host rejects a second transfer through its
10
+ * shared state, but disconnected receivers do not share that state. Treat a
11
+ * received VTXO as final only after an anti-double-spend check (online/operator
12
+ * spend check, operator-co-signed transfer, or an explicitly risk-bounded
13
+ * policy), and have the operator commit the new outputs — they do not
14
+ * automatically belong to the previous pool root.
15
+ *
4
16
  * @param now - Timestamp in ms. Defaults to Date.now() if omitted — pass explicitly for determinism.
5
17
  */
6
18
  export declare function transferVtxo(vtxo: OmniaVtxo, params: TransferVtxoParams, now?: number): TransferResult & {
7
19
  receipt: VtxoOperatorReceipt;
8
20
  };
21
+ /**
22
+ * V1 transfer: build the recipient's independent exit before moving the claim,
23
+ * then transfer only if the exit package verifies against the input VTXO.
24
+ */
25
+ export declare function transferVtxoWithExit(vtxo: OmniaVtxo, params: Omit<TransferVtxoParams, 'exitEntitlement'>, exitParams: ExitTxParams, exitDeps: ExitTxDeps, now?: number): Promise<TransferResult & {
26
+ receipt: VtxoOperatorReceipt;
27
+ exitEntitlement: VtxoExitEntitlement;
28
+ }>;
package/dist/transfer.js CHANGED
@@ -1,7 +1,19 @@
1
1
  import { VtxoStatusError, VtxoAmountError } from './errors.js';
2
2
  import { computeVtxoId, buildVtxoProofSet, computeReceiptId } from './commitment.js';
3
+ import { verifyVtxoExitEntitlement, createVtxoExitEntitlement } from './exit-entitlement.js';
4
+ import { buildExitTransaction } from './exit-tx.js';
3
5
  /**
4
6
  * Transfers a VTXO (fully or partially) to a recipient.
7
+ *
8
+ * **Offline safety.** The returned output VTXOs are new claims. A Merkle proof
9
+ * establishes membership in a committed set; it does NOT prove the input was
10
+ * never spent elsewhere. The local host rejects a second transfer through its
11
+ * shared state, but disconnected receivers do not share that state. Treat a
12
+ * received VTXO as final only after an anti-double-spend check (online/operator
13
+ * spend check, operator-co-signed transfer, or an explicitly risk-bounded
14
+ * policy), and have the operator commit the new outputs — they do not
15
+ * automatically belong to the previous pool root.
16
+ *
5
17
  * @param now - Timestamp in ms. Defaults to Date.now() if omitted — pass explicitly for determinism.
6
18
  */
7
19
  export function transferVtxo(vtxo, params, now) {
@@ -15,6 +27,15 @@ export function transferVtxo(vtxo, params, now) {
15
27
  if (params.amount > vtxo.amount) {
16
28
  throw new VtxoAmountError(`Transfer amount ${params.amount} exceeds VTXO amount ${vtxo.amount}`);
17
29
  }
30
+ if (params.exitEntitlement) {
31
+ if (params.amount !== vtxo.amount) {
32
+ throw new VtxoAmountError('exit entitlement requires a full-value transfer');
33
+ }
34
+ const check = verifyVtxoExitEntitlement(params.exitEntitlement, vtxo);
35
+ if (!check.valid) {
36
+ throw new VtxoAmountError(`invalid exit entitlement: ${check.errors.join('; ')}`);
37
+ }
38
+ }
18
39
  const isPartial = params.amount < vtxo.amount;
19
40
  const changeAmount = vtxo.amount - params.amount;
20
41
  const outputId = computeVtxoId({
@@ -59,6 +80,7 @@ export function transferVtxo(vtxo, params, now) {
59
80
  tokenId: vtxo.tokenId,
60
81
  status: 'active',
61
82
  epoch: vtxo.epoch,
83
+ ...(params.exitEntitlement ? { exitEntitlement: params.exitEntitlement } : {}),
62
84
  proof: {
63
85
  leaf: '',
64
86
  root: '',
@@ -147,3 +169,19 @@ export function transferVtxo(vtxo, params, now) {
147
169
  },
148
170
  };
149
171
  }
172
+ /**
173
+ * V1 transfer: build the recipient's independent exit before moving the claim,
174
+ * then transfer only if the exit package verifies against the input VTXO.
175
+ */
176
+ export async function transferVtxoWithExit(vtxo, params, exitParams, exitDeps, now) {
177
+ if (exitParams.vtxo.vtxoId !== vtxo.vtxoId) {
178
+ throw new VtxoAmountError('exit entitlement VTXO does not match transfer input');
179
+ }
180
+ if (params.amount !== vtxo.amount) {
181
+ throw new VtxoAmountError('transferVtxoWithExit requires a full-value transfer');
182
+ }
183
+ const exit = await buildExitTransaction(exitParams, exitDeps);
184
+ const entitlement = createVtxoExitEntitlement(exitParams, exit);
185
+ const transferred = transferVtxo(vtxo, { ...params, exitEntitlement: entitlement }, now);
186
+ return { ...transferred, exitEntitlement: entitlement };
187
+ }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { VtxoClaimPolicy } from './claim-policy.js';
2
+ import type { VtxoExitEntitlement } from './exit-entitlement.js';
1
3
  export type VtxoId = string;
2
4
  export type VtxoStatus = 'active' | 'transferred' | 'split' | 'merged' | 'refreshed' | 'exiting' | 'exited' | 'spent' | 'expired' | 'invalid';
3
5
  export type VtxoOp = 'mint' | 'transfer' | 'split' | 'merge' | 'refresh' | 'exit_initiated' | 'exit_complete' | 'spent';
@@ -50,6 +52,10 @@ export interface OmniaVtxo {
50
52
  expiresAt?: number;
51
53
  /** The on-chain funding proof recorded at mint (deep proof, #28). */
52
54
  fundingProof?: unknown;
55
+ /** Opt-in multiparty claim policy (M8–M18). */
56
+ claimPolicy?: VtxoClaimPolicy;
57
+ /** V1: independently executable exit package delivered to the owner. */
58
+ exitEntitlement?: VtxoExitEntitlement;
53
59
  /** Set when an exit draft consumed this VTXO — prevents double-exit. */
54
60
  exitConsumedAt?: number;
55
61
  exitReceiptId?: string;
@@ -99,6 +105,8 @@ export interface TransferVtxoParams {
99
105
  amount: bigint;
100
106
  nonce: string;
101
107
  changeNonce?: string;
108
+ /** V1: exit package the recipient must receive with the claim. */
109
+ exitEntitlement?: VtxoExitEntitlement;
102
110
  }
103
111
  export interface SplitVtxoParams {
104
112
  amounts: bigint[];
@@ -0,0 +1,2 @@
1
+ /** Deterministic pro-rata yield distribution for multiparty VTXO/pool claims. */
2
+ export declare function distributeYield(total: bigint, weights: Record<string, bigint>): Record<string, bigint>;
package/dist/yield.js ADDED
@@ -0,0 +1,23 @@
1
+ /** Deterministic pro-rata yield distribution for multiparty VTXO/pool claims. */
2
+ export function distributeYield(total, weights) {
3
+ if (total < 0n)
4
+ throw new Error('yield total must be non-negative');
5
+ const entries = Object.entries(weights).filter(([, weight]) => weight > 0n);
6
+ if (entries.length === 0)
7
+ throw new Error('yield requires positive weights');
8
+ const denominator = entries.reduce((sum, [, weight]) => sum + weight, 0n);
9
+ if (denominator <= 0n)
10
+ throw new Error('yield weight sum must be positive');
11
+ const out = {};
12
+ let allocated = 0n;
13
+ for (const [id, weight] of entries) {
14
+ const share = (total * weight) / denominator;
15
+ out[id] = share;
16
+ allocated += share;
17
+ }
18
+ // Deterministic remainder assignment to the first entry.
19
+ const remainder = total - allocated;
20
+ if (remainder > 0n)
21
+ out[entries[0][0]] += remainder;
22
+ return out;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-vtxo",
3
- "version": "0.6.1",
3
+ "version": "0.7.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",
@@ -21,14 +21,15 @@
21
21
  "rust/pkg/",
22
22
  "rust/pkg-node/",
23
23
  "README.md",
24
- "LICENSE"
24
+ "LICENSE",
25
+ "NOTICE"
25
26
  ],
26
27
  "dependencies": {
27
- "@totemsdk/core": "^1.4.0",
28
28
  "@totemsdk/chain-provider": "^0.3.0",
29
- "@totemsdk/omnia": "^2.3.0",
30
- "@totemsdk/storage": "^0.1.0",
29
+ "@totemsdk/core": "^1.4.0",
31
30
  "@totemsdk/txpow": "^1.1.0",
31
+ "@totemsdk/omnia": "^2.3.2",
32
+ "@totemsdk/storage": "^0.2.1",
32
33
  "@totemsdk/wots-lease": "^1.0.1"
33
34
  },
34
35
  "devDependencies": {
@@ -36,7 +37,8 @@
36
37
  "@types/node": "^20.0.0",
37
38
  "jest": "^30.4.2",
38
39
  "ts-jest": "^29.0.0",
39
- "typescript": "^7.0.2"
40
+ "typescript": "^7.0.2",
41
+ "@totemsdk/kissvm": "^1.3.0"
40
42
  },
41
43
  "engines": {
42
44
  "node": ">=18.0.0"
@@ -44,7 +46,7 @@
44
46
  "publishConfig": {
45
47
  "access": "public"
46
48
  },
47
- "license": "MIT",
49
+ "license": "Apache-2.0",
48
50
  "author": "Totem SDK",
49
51
  "homepage": "https://docs.totem.ing",
50
52
  "bugs": {
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "description": "Virtual UTXO commitment layer — Merkle tree hashing, VTXO ID computation, proof verification, amount conservation (Rust/WASM)",
8
8
  "version": "0.1.0",
9
- "license": "MIT",
9
+ "license": "Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/Totem-Edge/totem-sdk"
@@ -5,7 +5,7 @@
5
5
  ],
6
6
  "description": "Virtual UTXO commitment layer — Merkle tree hashing, VTXO ID computation, proof verification, amount conservation (Rust/WASM)",
7
7
  "version": "0.1.0",
8
- "license": "MIT",
8
+ "license": "Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/Totem-Edge/totem-sdk"