@totemsdk/omnia-vtxo 0.2.1 → 0.3.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 (83) hide show
  1. package/dist/anchor.d.ts +87 -0
  2. package/dist/anchor.js +107 -0
  3. package/dist/cjs/anchor.d.ts +87 -0
  4. package/dist/cjs/anchor.js +114 -0
  5. package/dist/cjs/commitment.d.ts +41 -0
  6. package/dist/cjs/commitment.js +173 -0
  7. package/dist/cjs/constants.d.ts +10 -0
  8. package/dist/cjs/constants.js +13 -0
  9. package/dist/cjs/durable-store.d.ts +33 -0
  10. package/dist/cjs/durable-store.js +93 -0
  11. package/dist/cjs/errors.d.ts +33 -0
  12. package/dist/cjs/errors.js +77 -0
  13. package/dist/cjs/exit-tx.d.ts +55 -0
  14. package/dist/cjs/exit-tx.js +81 -0
  15. package/dist/cjs/exit.d.ts +29 -0
  16. package/dist/cjs/exit.js +115 -0
  17. package/dist/cjs/index.d.ts +21 -0
  18. package/dist/cjs/index.js +37 -0
  19. package/dist/cjs/memory-store.d.ts +17 -0
  20. package/dist/cjs/memory-store.js +51 -0
  21. package/dist/cjs/merge.d.ts +8 -0
  22. package/dist/cjs/merge.js +106 -0
  23. package/dist/cjs/operator.d.ts +29 -0
  24. package/dist/cjs/operator.js +65 -0
  25. package/dist/cjs/package.json +1 -0
  26. package/dist/cjs/policy.d.ts +22 -0
  27. package/dist/cjs/policy.js +27 -0
  28. package/dist/cjs/pool-script.d.ts +19 -0
  29. package/dist/cjs/pool-script.js +41 -0
  30. package/dist/cjs/pool.d.ts +5 -0
  31. package/dist/cjs/pool.js +60 -0
  32. package/dist/cjs/receipt.d.ts +31 -0
  33. package/dist/cjs/receipt.js +52 -0
  34. package/dist/cjs/refresh.d.ts +8 -0
  35. package/dist/cjs/refresh.js +84 -0
  36. package/dist/cjs/serialization.d.ts +5 -0
  37. package/dist/cjs/serialization.js +31 -0
  38. package/dist/cjs/split.d.ts +8 -0
  39. package/dist/cjs/split.js +96 -0
  40. package/dist/cjs/transfer.d.ts +8 -0
  41. package/dist/cjs/transfer.js +152 -0
  42. package/dist/cjs/types.d.ts +166 -0
  43. package/dist/cjs/types.js +2 -0
  44. package/dist/cjs/verify.d.ts +23 -0
  45. package/dist/cjs/verify.js +121 -0
  46. package/dist/cjs/vtxo.d.ts +14 -0
  47. package/dist/cjs/vtxo.js +96 -0
  48. package/dist/commitment.d.ts +8 -0
  49. package/dist/commitment.js +38 -36
  50. package/dist/constants.d.ts +0 -2
  51. package/dist/constants.js +4 -9
  52. package/dist/durable-store.js +8 -11
  53. package/dist/errors.js +10 -23
  54. package/dist/exit-tx.d.ts +55 -0
  55. package/dist/exit-tx.js +74 -0
  56. package/dist/exit.d.ts +4 -1
  57. package/dist/exit.js +20 -26
  58. package/dist/index.d.ts +5 -0
  59. package/dist/index.js +21 -32
  60. package/dist/memory-store.js +3 -7
  61. package/dist/merge.js +15 -19
  62. package/dist/operator.d.ts +29 -0
  63. package/dist/operator.js +61 -0
  64. package/dist/policy.d.ts +1 -1
  65. package/dist/policy.js +3 -7
  66. package/dist/pool-script.d.ts +19 -0
  67. package/dist/pool-script.js +36 -0
  68. package/dist/pool.js +21 -27
  69. package/dist/receipt.d.ts +31 -0
  70. package/dist/receipt.js +48 -0
  71. package/dist/refresh.js +10 -14
  72. package/dist/serialization.js +4 -10
  73. package/dist/split.js +13 -17
  74. package/dist/transfer.js +13 -17
  75. package/dist/types.d.ts +3 -1
  76. package/dist/types.js +1 -2
  77. package/dist/verify.js +7 -13
  78. package/dist/vtxo.js +13 -19
  79. package/package.json +18 -8
  80. package/rust/pkg/omnia_vtxo_wasm_bg.wasm +0 -0
  81. package/rust/pkg/package.json +1 -1
  82. package/rust/pkg-node/omnia_vtxo_wasm_bg.wasm +0 -0
  83. package/rust/pkg-node/package.json +1 -1
package/dist/transfer.js CHANGED
@@ -1,27 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transferVtxo = transferVtxo;
4
- const errors_js_1 = require("./errors.js");
5
- const commitment_js_1 = require("./commitment.js");
6
- const constants_js_1 = require("./constants.js");
1
+ import { VtxoStatusError, VtxoAmountError } from './errors.js';
2
+ import { computeVtxoId, buildVtxoProofSet, computeReceiptId } from './commitment.js';
7
3
  /**
8
4
  * Transfers a VTXO (fully or partially) to a recipient.
9
5
  * @param now - Timestamp in ms. Defaults to Date.now() if omitted — pass explicitly for determinism.
10
6
  */
11
- function transferVtxo(vtxo, params, now) {
7
+ export function transferVtxo(vtxo, params, now) {
12
8
  const ts = now !== undefined ? now : Date.now();
13
9
  if (vtxo.status !== 'active') {
14
- throw new errors_js_1.VtxoStatusError(`Cannot transfer VTXO ${vtxo.vtxoId}: status is '${vtxo.status}'`, vtxo.status);
10
+ throw new VtxoStatusError(`Cannot transfer VTXO ${vtxo.vtxoId}: status is '${vtxo.status}'`, vtxo.status);
15
11
  }
16
12
  if (params.amount <= BigInt(0)) {
17
- throw new errors_js_1.VtxoAmountError(`Transfer amount must be > 0, got ${params.amount}`);
13
+ throw new VtxoAmountError(`Transfer amount must be > 0, got ${params.amount}`);
18
14
  }
19
15
  if (params.amount > vtxo.amount) {
20
- throw new errors_js_1.VtxoAmountError(`Transfer amount ${params.amount} exceeds VTXO amount ${vtxo.amount}`);
16
+ throw new VtxoAmountError(`Transfer amount ${params.amount} exceeds VTXO amount ${vtxo.amount}`);
21
17
  }
22
18
  const isPartial = params.amount < vtxo.amount;
23
19
  const changeAmount = vtxo.amount - params.amount;
24
- const outputId = (0, commitment_js_1.computeVtxoId)({
20
+ const outputId = computeVtxoId({
25
21
  poolId: vtxo.poolId,
26
22
  owner: params.recipient,
27
23
  amount: params.amount,
@@ -32,7 +28,7 @@ function transferVtxo(vtxo, params, now) {
32
28
  let changeId;
33
29
  if (isPartial) {
34
30
  const changeNonce = params.changeNonce ?? params.nonce + ':change';
35
- changeId = (0, commitment_js_1.computeVtxoId)({
31
+ changeId = computeVtxoId({
36
32
  poolId: vtxo.poolId,
37
33
  owner: vtxo.owner,
38
34
  amount: changeAmount,
@@ -69,7 +65,7 @@ function transferVtxo(vtxo, params, now) {
69
65
  siblings: [],
70
66
  positions: [],
71
67
  epoch: vtxo.epoch,
72
- batchId: constants_js_1.MOCK_BATCH_ID,
68
+ batchId: '',
73
69
  },
74
70
  history: [
75
71
  {
@@ -99,7 +95,7 @@ function transferVtxo(vtxo, params, now) {
99
95
  siblings: [],
100
96
  positions: [],
101
97
  epoch: vtxo.epoch,
102
- batchId: constants_js_1.MOCK_BATCH_ID,
98
+ batchId: '',
103
99
  },
104
100
  history: [
105
101
  {
@@ -116,7 +112,7 @@ function transferVtxo(vtxo, params, now) {
116
112
  outputIds.push(changeId);
117
113
  }
118
114
  const activeOutputs = changeVtxo ? [outputVtxo, changeVtxo] : [outputVtxo];
119
- const { proofs } = (0, commitment_js_1.buildVtxoProofSet)(activeOutputs);
115
+ const { proofs } = buildVtxoProofSet(activeOutputs);
120
116
  const patchedOutput = { ...outputVtxo, proof: proofs[outputId] };
121
117
  const patchedChange = changeVtxo
122
118
  ? { ...changeVtxo, proof: proofs[changeId] }
@@ -133,7 +129,7 @@ function transferVtxo(vtxo, params, now) {
133
129
  tokenId: vtxo.tokenId,
134
130
  at: ts,
135
131
  };
136
- const receiptId = (0, commitment_js_1.computeReceiptId)(vtxo.poolId, 'transfer', [vtxo.vtxoId], outputIds, ts);
132
+ const receiptId = computeReceiptId(vtxo.poolId, 'transfer', [vtxo.vtxoId], outputIds, ts);
137
133
  return {
138
134
  input: inputVtxo,
139
135
  output: patchedOutput,
@@ -147,7 +143,7 @@ function transferVtxo(vtxo, params, now) {
147
143
  outputIds,
148
144
  epoch: vtxo.epoch,
149
145
  at: ts,
150
- signature: constants_js_1.MOCK_OPERATOR_SIGNATURE,
146
+ signature: '',
151
147
  },
152
148
  };
153
149
  }
package/dist/types.d.ts CHANGED
@@ -53,6 +53,8 @@ export interface OmniaVtxo {
53
53
  /** Set when an exit draft consumed this VTXO — prevents double-exit. */
54
54
  exitConsumedAt?: number;
55
55
  exitReceiptId?: string;
56
+ /** The confirming exit transaction's txpowId (set on `markExited`). */
57
+ exitTxpowId?: string;
56
58
  }
57
59
  export interface VtxoTransfer {
58
60
  inputId: VtxoId;
@@ -139,7 +141,7 @@ export interface ExitDraft {
139
141
  owner: string;
140
142
  amount: bigint;
141
143
  tokenId: string;
142
- draftType: 'mock-exit';
144
+ draftType: 'vtxo-exit';
143
145
  timelockSeconds: number;
144
146
  createdAt: number;
145
147
  /** The verified share this exit is capped at (the VTXO's amount). */
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/verify.js CHANGED
@@ -1,11 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyVtxo = verifyVtxo;
4
- exports.verifyVtxoProof = verifyVtxoProof;
5
- exports.verifyVtxoTransfer = verifyVtxoTransfer;
6
- exports.verifyConservation = verifyConservation;
7
- const commitment_js_1 = require("./commitment.js");
8
- function verifyVtxo(vtxo) {
1
+ import { computeVtxoLeaf, verifyMerkleProof } from './commitment.js';
2
+ export function verifyVtxo(vtxo) {
9
3
  const errors = [];
10
4
  if (!vtxo.vtxoId)
11
5
  errors.push('Missing vtxoId');
@@ -27,9 +21,9 @@ function verifyVtxo(vtxo) {
27
21
  }
28
22
  return { valid: errors.length === 0, errors };
29
23
  }
30
- function verifyVtxoProof(vtxo, proof) {
24
+ export function verifyVtxoProof(vtxo, proof) {
31
25
  const errors = [];
32
- const expectedLeaf = (0, commitment_js_1.computeVtxoLeaf)(vtxo);
26
+ const expectedLeaf = computeVtxoLeaf(vtxo);
33
27
  if (proof.leaf !== expectedLeaf) {
34
28
  errors.push(`Proof leaf mismatch: expected ${expectedLeaf}, got ${proof.leaf}`);
35
29
  }
@@ -38,7 +32,7 @@ function verifyVtxoProof(vtxo, proof) {
38
32
  sibling,
39
33
  position: proof.positions[i],
40
34
  }));
41
- const valid = (0, commitment_js_1.verifyMerkleProof)(proof.leaf, proofNodes, proof.root);
35
+ const valid = verifyMerkleProof(proof.leaf, proofNodes, proof.root);
42
36
  if (!valid) {
43
37
  errors.push('Merkle proof verification failed');
44
38
  }
@@ -50,7 +44,7 @@ function verifyVtxoProof(vtxo, proof) {
50
44
  }
51
45
  return { valid: errors.length === 0, errors };
52
46
  }
53
- function verifyVtxoTransfer(input, output, transfer) {
47
+ export function verifyVtxoTransfer(input, output, transfer) {
54
48
  const errors = [];
55
49
  if (transfer.inputId !== input.vtxoId) {
56
50
  errors.push(`Transfer inputId ${transfer.inputId} does not match input VTXO ${input.vtxoId}`);
@@ -77,7 +71,7 @@ function verifyVtxoTransfer(input, output, transfer) {
77
71
  *
78
72
  * Always requires: same `poolId` and `tokenId` across all inputs and outputs.
79
73
  */
80
- function verifyConservation(params) {
74
+ export function verifyConservation(params) {
81
75
  const errors = [];
82
76
  const { inputs, outputs, mode = 'lte' } = params;
83
77
  if (inputs.length === 0 || outputs.length === 0) {
package/dist/vtxo.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isVtxoActive = isVtxoActive;
4
- exports.mintVtxo = mintVtxo;
5
- exports.markVtxoSpent = markVtxoSpent;
6
- const errors_js_1 = require("./errors.js");
7
- const constants_js_1 = require("./constants.js");
8
- const commitment_js_1 = require("./commitment.js");
9
- const pool_js_1 = require("./pool.js");
10
- function isVtxoActive(vtxo) {
1
+ import { VtxoStatusError } from './errors.js';
2
+ import { computeVtxoId, buildVtxoProofSet, computeReceiptId } from './commitment.js';
3
+ import { assertPoolCanMint } from './pool.js';
4
+ export function isVtxoActive(vtxo) {
11
5
  return vtxo.status === 'active';
12
6
  }
13
7
  /**
@@ -16,10 +10,10 @@ function isVtxoActive(vtxo) {
16
10
  * @param params - Mint parameters (owner, amount, nonce).
17
11
  * @param now - Timestamp in ms. Defaults to Date.now() if omitted — pass explicitly for determinism.
18
12
  */
19
- function mintVtxo(pool, params, now) {
13
+ export function mintVtxo(pool, params, now) {
20
14
  const ts = now !== undefined ? now : Date.now();
21
- (0, pool_js_1.assertPoolCanMint)(pool, params.amount);
22
- const vtxoId = (0, commitment_js_1.computeVtxoId)({
15
+ assertPoolCanMint(pool, params.amount);
16
+ const vtxoId = computeVtxoId({
23
17
  poolId: pool.poolId,
24
18
  owner: params.owner,
25
19
  amount: params.amount,
@@ -40,7 +34,7 @@ function mintVtxo(pool, params, now) {
40
34
  siblings: [],
41
35
  positions: [],
42
36
  epoch: pool.epoch,
43
- batchId: constants_js_1.MOCK_BATCH_ID,
37
+ batchId: '',
44
38
  },
45
39
  fundingProof: params.fundingProof,
46
40
  history: [
@@ -55,7 +49,7 @@ function mintVtxo(pool, params, now) {
55
49
  updatedAt: ts,
56
50
  expiresAt: params.expiresAt,
57
51
  };
58
- const { root, proofs } = (0, commitment_js_1.buildVtxoProofSet)([vtxo]);
52
+ const { root, proofs } = buildVtxoProofSet([vtxo]);
59
53
  const proof = proofs[vtxoId];
60
54
  const mintedVtxo = { ...vtxo, proof };
61
55
  const updatedPool = {
@@ -63,7 +57,7 @@ function mintVtxo(pool, params, now) {
63
57
  availableCapacity: pool.availableCapacity - params.amount,
64
58
  commitmentRoot: root,
65
59
  };
66
- const receiptId = (0, commitment_js_1.computeReceiptId)(pool.poolId, 'mint', [], [vtxoId], ts);
60
+ const receiptId = computeReceiptId(pool.poolId, 'mint', [], [vtxoId], ts);
67
61
  const receipt = {
68
62
  receiptId,
69
63
  poolId: pool.poolId,
@@ -72,7 +66,7 @@ function mintVtxo(pool, params, now) {
72
66
  outputIds: [vtxoId],
73
67
  epoch: pool.epoch,
74
68
  at: ts,
75
- signature: constants_js_1.MOCK_OPERATOR_SIGNATURE,
69
+ signature: '',
76
70
  };
77
71
  return { pool: updatedPool, vtxo: mintedVtxo, receipt };
78
72
  }
@@ -80,10 +74,10 @@ function mintVtxo(pool, params, now) {
80
74
  * Marks an active VTXO as spent.
81
75
  * @param now - Timestamp in ms. Defaults to Date.now() if omitted — pass explicitly for determinism.
82
76
  */
83
- function markVtxoSpent(vtxo, now) {
77
+ export function markVtxoSpent(vtxo, now) {
84
78
  const ts = now !== undefined ? now : Date.now();
85
79
  if (!isVtxoActive(vtxo)) {
86
- throw new errors_js_1.VtxoStatusError(`Cannot mark VTXO ${vtxo.vtxoId} as spent: status is '${vtxo.status}'`, vtxo.status);
80
+ throw new VtxoStatusError(`Cannot mark VTXO ${vtxo.vtxoId} as spent: status is '${vtxo.status}'`, vtxo.status);
87
81
  }
88
82
  return {
89
83
  ...vtxo,
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-vtxo",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Virtual UTXO / payment-pool claim layer for Omnia — cash-like off-chain balance primitive for Totem Edge",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "dist/cjs/index.js",
6
+ "types": "dist/cjs/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/index.d.ts",
10
- "require": "./dist/index.js",
11
- "import": "./dist/index.js"
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/cjs/index.d.ts",
15
+ "default": "./dist/cjs/index.js"
16
+ }
12
17
  }
13
18
  },
14
19
  "files": [
@@ -19,8 +24,12 @@
19
24
  "LICENSE"
20
25
  ],
21
26
  "dependencies": {
27
+ "@totemsdk/chain-provider": "^0.2.1",
28
+ "@totemsdk/omnia": "^1.0.3",
22
29
  "@totemsdk/core": "^1.2.11",
23
- "@totemsdk/storage": "^0.1.0"
30
+ "@totemsdk/storage": "^0.1.0",
31
+ "@totemsdk/wots-lease": "^1.0.1",
32
+ "@totemsdk/txpow": "^1.0.2"
24
33
  },
25
34
  "devDependencies": {
26
35
  "@types/jest": "^30.0.0",
@@ -62,8 +71,9 @@
62
71
  "off-chain",
63
72
  "ark"
64
73
  ],
74
+ "type": "module",
65
75
  "scripts": {
66
- "build": "npm run build:wasm && tsc && node ../../scripts/clean-wasm-output-ignores.mjs",
76
+ "build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
67
77
  "clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
68
78
  "test": "jest",
69
79
  "build:wasm": "cd rust && wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node"
Binary file
@@ -24,4 +24,4 @@
24
24
  "./omnia_vtxo_wasm.js",
25
25
  "./snippets/*"
26
26
  ]
27
- }
27
+ }
@@ -18,4 +18,4 @@
18
18
  "main": "omnia_vtxo_wasm.js",
19
19
  "homepage": "https://totem.ing",
20
20
  "types": "omnia_vtxo_wasm.d.ts"
21
- }
21
+ }