@totemsdk/core 1.0.9 → 1.0.10

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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -5
  3. package/dist/Streamable.js +54 -31
  4. package/dist/adapters/index.js +18 -8
  5. package/dist/adapters/types.js +19 -8
  6. package/dist/binio.js +5 -1
  7. package/dist/bip39.js +24 -14
  8. package/dist/derive.js +11 -7
  9. package/dist/index.js +130 -22
  10. package/dist/javaStreamables.js +49 -30
  11. package/dist/lease/LeaseMonitor.js +7 -3
  12. package/dist/lease/LeaseStore.js +7 -3
  13. package/dist/lease/WatermarkStore.js +7 -3
  14. package/dist/lease/index.js +13 -4
  15. package/dist/lease-client.js +8 -3
  16. package/dist/minima32.js +22 -13
  17. package/dist/minimaWireSerializer.js +20 -14
  18. package/dist/mmr.js +35 -23
  19. package/dist/mx.js +10 -1
  20. package/dist/params.js +9 -5
  21. package/dist/script.js +12 -7
  22. package/dist/scripts/contract-helpers.js +37 -26
  23. package/dist/scripts/dapp-types.js +11 -6
  24. package/dist/scripts/index.js +38 -4
  25. package/dist/scripts/types.js +26 -12
  26. package/dist/scripts/witness-serializer.js +48 -30
  27. package/dist/transaction.js +55 -46
  28. package/dist/treekey.js +74 -58
  29. package/dist/tx/TransactionLifecycle.js +11 -5
  30. package/dist/tx/TransactionReceiptStore.js +7 -3
  31. package/dist/tx/TransactionService.js +14 -10
  32. package/dist/tx/index.js +11 -3
  33. package/dist/tx/types.js +2 -1
  34. package/dist/util.js +5 -1
  35. package/dist/utils.js +12 -5
  36. package/dist/verify.js +36 -25
  37. package/dist/version.js +5 -2
  38. package/dist/wots.js +94 -64
  39. package/package.json +31 -6
  40. package/src/Streamable.d.ts +0 -268
  41. package/src/Streamable.js +0 -416
  42. package/src/Streamable.ts +0 -567
  43. package/src/__tests__/Streamable.parity.test.ts +0 -422
  44. package/src/__tests__/perAddressDerivation.parity.test.ts +0 -152
  45. package/src/__tests__/roottree-prepare.test.ts +0 -101
  46. package/src/__tests__/wots-parity.test.ts +0 -289
  47. package/src/adapters/index.d.ts +0 -190
  48. package/src/adapters/index.js +0 -117
  49. package/src/adapters/index.ts +0 -301
  50. package/src/adapters/types.ts +0 -235
  51. package/src/addr.oracle.test.ts +0 -25
  52. package/src/address.test.ts +0 -55
  53. package/src/binio.ts +0 -21
  54. package/src/bip39.d.ts +0 -91
  55. package/src/bip39.js +0 -427
  56. package/src/bip39.ts +0 -432
  57. package/src/derive.d.ts +0 -2
  58. package/src/derive.js +0 -13
  59. package/src/derive.ts +0 -11
  60. package/src/index.d.ts +0 -26
  61. package/src/index.js +0 -128
  62. package/src/index.test.ts +0 -5
  63. package/src/index.ts +0 -221
  64. package/src/javaStreamables.d.ts +0 -233
  65. package/src/javaStreamables.js +0 -332
  66. package/src/javaStreamables.ts +0 -403
  67. package/src/lease/LeaseMonitor.d.ts +0 -44
  68. package/src/lease/LeaseMonitor.js +0 -111
  69. package/src/lease/LeaseMonitor.ts +0 -157
  70. package/src/lease/LeaseStore.d.ts +0 -57
  71. package/src/lease/LeaseStore.js +0 -148
  72. package/src/lease/LeaseStore.ts +0 -203
  73. package/src/lease/WatermarkStore.d.ts +0 -61
  74. package/src/lease/WatermarkStore.js +0 -206
  75. package/src/lease/WatermarkStore.ts +0 -270
  76. package/src/lease/index.d.ts +0 -14
  77. package/src/lease/index.js +0 -22
  78. package/src/lease/index.ts +0 -41
  79. package/src/lease-client.d.ts +0 -31
  80. package/src/lease-client.js +0 -44
  81. package/src/lease-client.ts +0 -69
  82. package/src/minima32.d.ts +0 -10
  83. package/src/minima32.js +0 -113
  84. package/src/minima32.test.ts +0 -11
  85. package/src/minima32.ts +0 -127
  86. package/src/minimaWireSerializer.d.ts +0 -189
  87. package/src/minimaWireSerializer.js +0 -311
  88. package/src/minimaWireSerializer.test.ts +0 -466
  89. package/src/minimaWireSerializer.ts +0 -117
  90. package/src/mmr.d.ts +0 -157
  91. package/src/mmr.js +0 -340
  92. package/src/mmr.oracle.test.ts +0 -28
  93. package/src/mmr.ts +0 -429
  94. package/src/mx.test.ts +0 -25
  95. package/src/mx.ts +0 -1
  96. package/src/params.d.ts +0 -29
  97. package/src/params.d.ts.map +0 -1
  98. package/src/params.js +0 -20
  99. package/src/params.js.map +0 -1
  100. package/src/params.ts +0 -44
  101. package/src/script.d.ts +0 -7
  102. package/src/script.js +0 -27
  103. package/src/script.ts +0 -24
  104. package/src/scripts/contract-helpers.ts +0 -609
  105. package/src/scripts/dapp-types.ts +0 -240
  106. package/src/scripts/index.ts +0 -22
  107. package/src/scripts/types.d.ts +0 -81
  108. package/src/scripts/types.js +0 -145
  109. package/src/scripts/types.ts +0 -247
  110. package/src/scripts/witness-serializer.ts +0 -384
  111. package/src/transaction.ts +0 -430
  112. package/src/treekey.d.ts +0 -383
  113. package/src/treekey.js +0 -774
  114. package/src/treekey.parity.test.ts +0 -459
  115. package/src/treekey.ts +0 -975
  116. package/src/tx/TransactionLifecycle.d.ts +0 -55
  117. package/src/tx/TransactionLifecycle.js +0 -188
  118. package/src/tx/TransactionLifecycle.ts +0 -280
  119. package/src/tx/TransactionReceiptStore.d.ts +0 -36
  120. package/src/tx/TransactionReceiptStore.js +0 -89
  121. package/src/tx/TransactionReceiptStore.ts +0 -112
  122. package/src/tx/TransactionService.d.ts +0 -31
  123. package/src/tx/TransactionService.js +0 -140
  124. package/src/tx/TransactionService.ts +0 -252
  125. package/src/tx/index.d.ts +0 -13
  126. package/src/tx/index.js +0 -20
  127. package/src/tx/index.ts +0 -44
  128. package/src/tx/types.d.ts +0 -80
  129. package/src/tx/types.js +0 -6
  130. package/src/tx/types.ts +0 -130
  131. package/src/util.d.ts +0 -1
  132. package/src/util.js +0 -5
  133. package/src/util.ts +0 -1
  134. package/src/utils.d.ts +0 -8
  135. package/src/utils.js +0 -42
  136. package/src/utils.ts +0 -38
  137. package/src/verify.ts +0 -210
  138. package/src/version.ts +0 -13
  139. package/src/wots.d.ts +0 -224
  140. package/src/wots.d.ts.map +0 -1
  141. package/src/wots.js +0 -565
  142. package/src/wots.js.map +0 -1
  143. package/src/wots.ts +0 -651
  144. package/test-vectors.json +0 -45
package/dist/minima32.js CHANGED
@@ -1,5 +1,14 @@
1
+ "use strict";
1
2
  // Minima "Mx" Base32 — matches org.minima.utils.BaseConverter.encode32/decode32
2
3
  // Source behavior: BigInteger radix-32, then i→w, l→y, o→z, uppercased, prefixed with "Mx".
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.convertMinimaAddress = exports.makeMinimaAddress = exports.decodeMx = exports.encodeMx = void 0;
6
+ exports.encodeMxRadix32Frame = encodeMxRadix32Frame;
7
+ exports.decodeMxRadix32Frame = decodeMxRadix32Frame;
8
+ exports.makeMxAddress = makeMxAddress;
9
+ exports.parseMxAddress = parseMxAddress;
10
+ exports.hexToMx = hexToMx;
11
+ exports.mxToHex = mxToHex;
3
12
  function bytesToBigInt(bytes) {
4
13
  let x = 0n;
5
14
  for (const b of bytes)
@@ -18,13 +27,13 @@ function bigIntToBytes(x) {
18
27
  }
19
28
  return out;
20
29
  }
21
- export function encodeMxRadix32Frame(frame) {
30
+ function encodeMxRadix32Frame(frame) {
22
31
  let s = bytesToBigInt(frame).toString(32).toLowerCase();
23
32
  // JAR swaps (avoid ambiguous letters) then uppercase and add prefix
24
33
  s = s.replace(/i/g, 'w').replace(/l/g, 'y').replace(/o/g, 'z');
25
34
  return 'Mx' + s.toUpperCase();
26
35
  }
27
- export function decodeMxRadix32Frame(mx) {
36
+ function decodeMxRadix32Frame(mx) {
28
37
  let s = mx.trim().toLowerCase();
29
38
  if (s.startsWith('mx'))
30
39
  s = s.slice(2);
@@ -39,9 +48,9 @@ export function decodeMxRadix32Frame(mx) {
39
48
  }
40
49
  return bigIntToBytes(x);
41
50
  }
42
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
51
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
43
52
  /** Encode raw 32 bytes to Mx address with frame and checksum */
44
- export function makeMxAddress(root32) {
53
+ function makeMxAddress(root32) {
45
54
  if (root32.length !== 32) {
46
55
  throw new Error(`Expected 32 bytes, got ${root32.length}`);
47
56
  }
@@ -52,12 +61,12 @@ export function makeMxAddress(root32) {
52
61
  frame[2] = 32; // Length low byte
53
62
  frame.set(root32, 3);
54
63
  // Calculate checksum of the raw 32 bytes
55
- const chk = nobleSha3(root32);
64
+ const chk = (0, sha3_js_1.sha3_256)(root32);
56
65
  frame.set(chk.slice(0, 4), 35);
57
66
  return encodeMxRadix32Frame(frame);
58
67
  }
59
68
  /** Decode Mx address to raw 32 bytes, validating frame and checksum */
60
- export function parseMxAddress(mx) {
69
+ function parseMxAddress(mx) {
61
70
  const frame = decodeMxRadix32Frame(mx);
62
71
  // Validate frame structure
63
72
  if (frame[0] !== 0x01) {
@@ -70,7 +79,7 @@ export function parseMxAddress(mx) {
70
79
  const root32 = frame.slice(3, 35);
71
80
  const checksum = frame.slice(35, 39);
72
81
  // Validate checksum
73
- const expectedChk = nobleSha3(root32);
82
+ const expectedChk = (0, sha3_js_1.sha3_256)(root32);
74
83
  const expected = expectedChk.slice(0, 4);
75
84
  for (let i = 0; i < 4; i++) {
76
85
  if (checksum[i] !== expected[i]) {
@@ -93,20 +102,20 @@ function bytesToHex(bytes) {
93
102
  return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase();
94
103
  }
95
104
  /** Make an Mx address from a hex string (legacy API compatibility) */
96
- export function hexToMx(hex) {
105
+ function hexToMx(hex) {
97
106
  const bytes = hexToBytes(hex);
98
107
  return makeMxAddress(bytes);
99
108
  }
100
109
  /** Convert an Mx address back to uppercase hex (legacy API compatibility) */
101
- export function mxToHex(mx) {
110
+ function mxToHex(mx) {
102
111
  const bytes = parseMxAddress(mx);
103
112
  return bytesToHex(bytes);
104
113
  }
105
114
  /** @deprecated Use makeMxAddress */
106
- export const encodeMx = makeMxAddress;
115
+ exports.encodeMx = makeMxAddress;
107
116
  /** @deprecated Use parseMxAddress */
108
- export const decodeMx = parseMxAddress;
117
+ exports.decodeMx = parseMxAddress;
109
118
  /** @deprecated Use hexToMx */
110
- export const makeMinimaAddress = hexToMx;
119
+ exports.makeMinimaAddress = hexToMx;
111
120
  /** @deprecated Use mxToHex */
112
- export const convertMinimaAddress = mxToHex;
121
+ exports.convertMinimaAddress = mxToHex;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Minima Wire Format Serializer
3
4
  *
@@ -7,10 +8,15 @@
7
8
  * @deprecated (2026-01) - Most functions deprecated. Use Streamable.ts directly for
8
9
  * byte-level serialization. This file remains for HierarchicalWitnessBundle hex APIs.
9
10
  */
10
- import { concat, hexToBytes, bytesToHex, writeMiniNumber, writeMiniData, } from './Streamable.js';
11
- // Re-export primitives for backward compatibility
12
- export { writeMiniNumber as serializeMiniNumber, writeMiniData as serializeMiniData };
13
- export { hexToBytes as fromHex, bytesToHex as toHex };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.toHex = exports.fromHex = exports.serializeMiniData = exports.serializeMiniNumber = void 0;
13
+ exports.serializeHierarchicalWitness = serializeHierarchicalWitness;
14
+ exports.serializeHierarchicalWitnessToHex = serializeHierarchicalWitnessToHex;
15
+ const Streamable_js_1 = require("./Streamable.js");
16
+ Object.defineProperty(exports, "fromHex", { enumerable: true, get: function () { return Streamable_js_1.hexToBytes; } });
17
+ Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return Streamable_js_1.bytesToHex; } });
18
+ Object.defineProperty(exports, "serializeMiniNumber", { enumerable: true, get: function () { return Streamable_js_1.writeMiniNumber; } });
19
+ Object.defineProperty(exports, "serializeMiniData", { enumerable: true, get: function () { return Streamable_js_1.writeMiniData; } });
14
20
  /**
15
21
  * Serialize a SignatureProof from pre-serialized byte arrays
16
22
  *
@@ -21,7 +27,7 @@ export { hexToBytes as fromHex, bytesToHex as toHex };
21
27
  * 3. MMRProof bytes (pre-serialized)
22
28
  */
23
29
  function serializeSignatureProofFromBytes(publicKey, signature, mmrProofBytes) {
24
- return concat(writeMiniData(publicKey), writeMiniData(signature), mmrProofBytes // Already serialized - pass through directly
30
+ return (0, Streamable_js_1.concat)((0, Streamable_js_1.writeMiniData)(publicKey), (0, Streamable_js_1.writeMiniData)(signature), mmrProofBytes // Already serialized - pass through directly
25
31
  );
26
32
  }
27
33
  /**
@@ -43,20 +49,20 @@ function serializeSignatureProofFromBytes(publicKey, signature, mmrProofBytes) {
43
49
  * IMPORTANT: Uses pre-serialized MMR proof bytes directly to avoid
44
50
  * double-serialization (deserialize then re-serialize).
45
51
  */
46
- export function serializeHierarchicalWitness(bundle) {
52
+ function serializeHierarchicalWitness(bundle) {
47
53
  const parts = [];
48
54
  // Witness.signatureCount (MiniNumber) - 1 Signature object containing N proofs
49
- parts.push(writeMiniNumber(1n));
55
+ parts.push((0, Streamable_js_1.writeMiniNumber)(1n));
50
56
  // Signature.proofCount (MiniNumber) - N SignatureProofs inside the Signature
51
- parts.push(writeMiniNumber(BigInt(bundle.proofs.length)));
57
+ parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(bundle.proofs.length)));
52
58
  for (const proofHex of bundle.proofs) {
53
- const publicKey = hexToBytes(proofHex.leafPubkey);
54
- const signature = hexToBytes(proofHex.signature);
55
- const mmrProofBytes = hexToBytes(proofHex.mmrProof); // Already serialized
59
+ const publicKey = (0, Streamable_js_1.hexToBytes)(proofHex.leafPubkey);
60
+ const signature = (0, Streamable_js_1.hexToBytes)(proofHex.signature);
61
+ const mmrProofBytes = (0, Streamable_js_1.hexToBytes)(proofHex.mmrProof); // Already serialized
56
62
  // Serialize SignatureProof with pre-serialized MMR bytes
57
63
  parts.push(serializeSignatureProofFromBytes(publicKey, signature, mmrProofBytes));
58
64
  }
59
- return concat(...parts);
65
+ return (0, Streamable_js_1.concat)(...parts);
60
66
  }
61
67
  /**
62
68
  * @deprecated (2026-01) This function's output is NOT used in the main Totem transaction flow.
@@ -65,7 +71,7 @@ export function serializeHierarchicalWitness(bundle) {
65
71
  *
66
72
  * Serialize hierarchical witness bundle to hex string for transport
67
73
  */
68
- export function serializeHierarchicalWitnessToHex(bundle) {
74
+ function serializeHierarchicalWitnessToHex(bundle) {
69
75
  const bytes = serializeHierarchicalWitness(bundle);
70
- return bytesToHex(bytes);
76
+ return (0, Streamable_js_1.bytesToHex)(bytes);
71
77
  }
package/dist/mmr.js CHANGED
@@ -1,12 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeMMRProof = exports.MMRTree = exports.serializeRealMMRProof = void 0;
4
+ exports.serializeMMRProof = serializeMMRProof;
5
+ exports.mmrLeafExact = mmrLeafExact;
6
+ exports.mmrRootFromSingleLeaf = mmrRootFromSingleLeaf;
7
+ exports.createMMRDataLeafNode = createMMRDataLeafNode;
8
+ exports.createMMRDataParentNode = createMMRDataParentNode;
9
+ exports.calculateProofRoot = calculateProofRoot;
10
+ exports.verifyMMRProof = verifyMMRProof;
11
+ exports.parseMMRProofFromHex = parseMMRProofFromHex;
1
12
  // packages/totem-sdk/packages/core/src/mmr.ts
2
13
  // Full MMR implementation matching Minima's MMR.java, MMRData.java, and TreeKeyNode.java
3
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
4
- import { serializeMiniNumber, serializeMiniData, javaHashAllObjects } from "./javaStreamables.js";
14
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
15
+ const javaStreamables_js_1 = require("./javaStreamables.js");
5
16
  // Import canonical wire serialization from Streamable.ts (single source of truth)
6
- import { writeMMRProof } from "./Streamable.js";
17
+ const Streamable_js_1 = require("./Streamable.js");
7
18
  // Re-export for API compatibility (existing code imports from mmr.ts)
8
19
  // Using a wrapper function for better compatibility with dynamic imports
9
- export function serializeMMRProof(proof, blockTime = 0n) {
20
+ function serializeMMRProof(proof, blockTime = 0n) {
10
21
  // Convert to Streamable format and serialize
11
22
  const streamableProof = {
12
23
  blockTime: blockTime,
@@ -15,12 +26,12 @@ export function serializeMMRProof(proof, blockTime = 0n) {
15
26
  mmrData: { data: c.mmrData.data, value: c.mmrData.value }
16
27
  }))
17
28
  };
18
- return writeMMRProof(streamableProof);
29
+ return (0, Streamable_js_1.writeMMRProof)(streamableProof);
19
30
  }
20
- export const serializeRealMMRProof = serializeMMRProof;
31
+ exports.serializeRealMMRProof = serializeMMRProof;
21
32
  /** SHA3-256 helper returning 32 bytes */
22
33
  function sha3(data) {
23
- return nobleSha3(data);
34
+ return (0, sha3_js_1.sha3_256)(data);
24
35
  }
25
36
  /** concat utility */
26
37
  function concat(...parts) {
@@ -59,14 +70,14 @@ function encodeMiniStringUTF8(text) {
59
70
  * Byte-exact one-leaf MMR leaf used by Minima Address.java path:
60
71
  * sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
61
72
  */
62
- export function mmrLeafExact(script) {
73
+ function mmrLeafExact(script) {
63
74
  const zero = encodeMiniNumberZERO();
64
75
  const mstr = encodeMiniStringUTF8(script);
65
76
  const all = concat(zero, mstr, zero);
66
77
  return sha3(all); // 32-byte leaf hash
67
78
  }
68
79
  /** In a single-leaf MMR the root equals the leaf commitment. */
69
- export function mmrRootFromSingleLeaf(script) {
80
+ function mmrRootFromSingleLeaf(script) {
70
81
  return mmrLeafExact(script);
71
82
  }
72
83
  /**
@@ -86,20 +97,20 @@ export function mmrRootFromSingleLeaf(script) {
86
97
  * 2. MiniData (pubkey): [4-byte length] + [bytes] (writeDataStream, NOT writeHashToStream)
87
98
  * 3. MiniNumber.ZERO: [0x00, 0x01, 0x00]
88
99
  */
89
- export function createMMRDataLeafNode(pubkey, sumValue = 0n) {
100
+ function createMMRDataLeafNode(pubkey, sumValue = 0n) {
90
101
  // Use cached ZERO serialization for efficiency
91
102
  const zero = new Uint8Array([0x00, 0x01, 0x00]); // MiniNumber.ZERO
92
103
  // IMPORTANT: hashAllObjects uses writeDataStream which is 4-byte length prefixed
93
- const pubkeySerialized = serializeMiniData(pubkey);
104
+ const pubkeySerialized = (0, javaStreamables_js_1.serializeMiniData)(pubkey);
94
105
  // For sumValue, serialize as MiniNumber
95
106
  let sumSerialized;
96
107
  if (sumValue === 0n) {
97
108
  sumSerialized = new Uint8Array([0x00, 0x01, 0x00]); // MiniNumber.ZERO
98
109
  }
99
110
  else {
100
- sumSerialized = serializeMiniNumber(Number(sumValue));
111
+ sumSerialized = (0, javaStreamables_js_1.serializeMiniNumber)(Number(sumValue));
101
112
  }
102
- const hash = javaHashAllObjects(zero, pubkeySerialized, sumSerialized);
113
+ const hash = (0, javaStreamables_js_1.javaHashAllObjects)(zero, pubkeySerialized, sumSerialized);
103
114
  return { data: hash, value: sumValue };
104
115
  }
105
116
  /**
@@ -119,22 +130,22 @@ export function createMMRDataLeafNode(pubkey, sumValue = 0n) {
119
130
  * 3. MiniData (right.data): [4-byte length] + [bytes]
120
131
  * 4. MiniNumber (sumvalue): serialized MiniNumber
121
132
  */
122
- export function createMMRDataParentNode(left, right) {
133
+ function createMMRDataParentNode(left, right) {
123
134
  const sumValue = left.value + right.value;
124
135
  // MiniNumber.ONE: [0x00, 0x01, 0x01]
125
136
  const one = new Uint8Array([0x00, 0x01, 0x01]);
126
137
  // Serialize left and right data as MiniData (4-byte length-prefixed)
127
- const leftDataSerialized = serializeMiniData(left.data);
128
- const rightDataSerialized = serializeMiniData(right.data);
138
+ const leftDataSerialized = (0, javaStreamables_js_1.serializeMiniData)(left.data);
139
+ const rightDataSerialized = (0, javaStreamables_js_1.serializeMiniData)(right.data);
129
140
  // Serialize sum value
130
141
  let sumSerialized;
131
142
  if (sumValue === 0n) {
132
143
  sumSerialized = new Uint8Array([0x00, 0x01, 0x00]); // MiniNumber.ZERO
133
144
  }
134
145
  else {
135
- sumSerialized = serializeMiniNumber(Number(sumValue));
146
+ sumSerialized = (0, javaStreamables_js_1.serializeMiniNumber)(Number(sumValue));
136
147
  }
137
- const hash = javaHashAllObjects(one, leftDataSerialized, rightDataSerialized, sumSerialized);
148
+ const hash = (0, javaStreamables_js_1.javaHashAllObjects)(one, leftDataSerialized, rightDataSerialized, sumSerialized);
138
149
  return { data: hash, value: sumValue };
139
150
  }
140
151
  /**
@@ -143,7 +154,7 @@ export function createMMRDataParentNode(left, right) {
143
154
  *
144
155
  * This matches TreeKeyNode.java which always uses 64 leaves (2^6)
145
156
  */
146
- export class MMRTree {
157
+ class MMRTree {
147
158
  constructor() {
148
159
  this.entries = new Map();
149
160
  this.leafCount = 0;
@@ -241,6 +252,7 @@ export class MMRTree {
241
252
  return entry?.mmrData || null;
242
253
  }
243
254
  }
255
+ exports.MMRTree = MMRTree;
244
256
  /**
245
257
  * Calculate root from leaf data and proof
246
258
  * Matches SignatureProof.getRootPublicKey() in Java
@@ -249,7 +261,7 @@ export class MMRTree {
249
261
  * MMRData pubentry = MMRData.CreateMMRDataLeafNode(mPublicKey, MiniNumber.ZERO);
250
262
  * return mProof.calculateProof(pubentry).getData();
251
263
  */
252
- export function calculateProofRoot(leafData, proof) {
264
+ function calculateProofRoot(leafData, proof) {
253
265
  let current = leafData;
254
266
  for (const chunk of proof.chunks) {
255
267
  if (chunk.isLeft) {
@@ -266,7 +278,7 @@ export function calculateProofRoot(leafData, proof) {
266
278
  /**
267
279
  * Verify a proof: check that leaf + proof computes to expected root
268
280
  */
269
- export function verifyMMRProof(leafPubkey, proof, expectedRoot) {
281
+ function verifyMMRProof(leafPubkey, proof, expectedRoot) {
270
282
  const leafData = createMMRDataLeafNode(leafPubkey, 0n);
271
283
  const computedRoot = calculateProofRoot(leafData, proof);
272
284
  if (computedRoot.length !== expectedRoot.length)
@@ -292,7 +304,7 @@ export function verifyMMRProof(leafPubkey, proof, expectedRoot) {
292
304
  *
293
305
  * @returns { proof: MMRProof, blockTime: bigint }
294
306
  */
295
- export function parseMMRProofFromHex(data) {
307
+ function parseMMRProofFromHex(data) {
296
308
  let offset = 0;
297
309
  // Read blockTime as MiniNumber
298
310
  const { value: blockTime, bytesRead: btRead } = readMiniNumber(data, offset);
@@ -339,4 +351,4 @@ function readMiniNumber(data, offset) {
339
351
  return { value, bytesRead: 2 + length };
340
352
  }
341
353
  /** @deprecated Use parseMMRProofFromHex */
342
- export const deserializeMMRProof = parseMMRProofFromHex;
354
+ exports.deserializeMMRProof = parseMMRProofFromHex;
package/dist/mx.js CHANGED
@@ -1 +1,10 @@
1
- export { hexToMx, mxToHex, makeMinimaAddress, convertMinimaAddress, encodeMx, decodeMx } from './minima32.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeMx = exports.encodeMx = exports.convertMinimaAddress = exports.makeMinimaAddress = exports.mxToHex = exports.hexToMx = void 0;
4
+ var minima32_js_1 = require("./minima32.js");
5
+ Object.defineProperty(exports, "hexToMx", { enumerable: true, get: function () { return minima32_js_1.hexToMx; } });
6
+ Object.defineProperty(exports, "mxToHex", { enumerable: true, get: function () { return minima32_js_1.mxToHex; } });
7
+ Object.defineProperty(exports, "makeMinimaAddress", { enumerable: true, get: function () { return minima32_js_1.makeMinimaAddress; } });
8
+ Object.defineProperty(exports, "convertMinimaAddress", { enumerable: true, get: function () { return minima32_js_1.convertMinimaAddress; } });
9
+ Object.defineProperty(exports, "encodeMx", { enumerable: true, get: function () { return minima32_js_1.encodeMx; } });
10
+ Object.defineProperty(exports, "decodeMx", { enumerable: true, get: function () { return minima32_js_1.decodeMx; } });
package/dist/params.js CHANGED
@@ -1,4 +1,8 @@
1
- export const WOTS_MINIMA = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WOTS_V2_SPEC = exports.WOTS_V1_DEV = exports.WOTS_MINIMA = void 0;
4
+ exports.getParamSet = getParamSet;
5
+ exports.WOTS_MINIMA = {
2
6
  name: 'minima',
3
7
  n: 256,
4
8
  w: 8,
@@ -9,8 +13,8 @@ export const WOTS_MINIMA = {
9
13
  maxDigit: 255,
10
14
  };
11
15
  // Legacy aliases for backwards compatibility during migration
12
- export const WOTS_V1_DEV = WOTS_MINIMA;
13
- export const WOTS_V2_SPEC = WOTS_MINIMA;
14
- export function getParamSet(_env) {
15
- return WOTS_MINIMA;
16
+ exports.WOTS_V1_DEV = exports.WOTS_MINIMA;
17
+ exports.WOTS_V2_SPEC = exports.WOTS_MINIMA;
18
+ function getParamSet(_env) {
19
+ return exports.WOTS_MINIMA;
16
20
  }
package/dist/script.js CHANGED
@@ -1,17 +1,22 @@
1
- import { bytesToHex } from "./util.js";
2
- import { scriptToAddress } from "./derive.js";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scriptFromWotsPk = scriptFromWotsPk;
4
+ exports.wotsAddressFromKeypair = wotsAddressFromKeypair;
5
+ exports.hexToBytes = hexToBytes;
6
+ const util_js_1 = require("./util.js");
7
+ const derive_js_1 = require("./derive.js");
3
8
  /** Produce KISSVM script that authorizes with a WOTS PK digest (32 bytes). */
4
- export function scriptFromWotsPk(pkDigest32) {
9
+ function scriptFromWotsPk(pkDigest32) {
5
10
  // Minima uses SHA3-256 in SIGNEDBY paths; here we embed the digest as hex.
6
- return `RETURN SIGNEDBY(${bytesToHex(pkDigest32)})`;
11
+ return `RETURN SIGNEDBY(${(0, util_js_1.bytesToHex)(pkDigest32)})`;
7
12
  }
8
13
  /** Address from WOTS keypair (client-only): script -> MMR leaf -> Mx */
9
- export function wotsAddressFromKeypair(kp) {
14
+ function wotsAddressFromKeypair(kp) {
10
15
  const script = scriptFromWotsPk(kp.pk);
11
- return scriptToAddress(script);
16
+ return (0, derive_js_1.scriptToAddress)(script);
12
17
  }
13
18
  /** tiny utils */
14
- export function hexToBytes(hex) {
19
+ function hexToBytes(hex) {
15
20
  let h = hex.startsWith("0x") ? hex.slice(2) : hex;
16
21
  if (h.length % 2)
17
22
  h = "0" + h;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Contract Helpers
3
4
  *
@@ -13,10 +14,12 @@
13
14
  * Each helper validates inputs and builds the appropriate ScriptDescriptor
14
15
  * for use with the EnhancedTransactionBuilder.
15
16
  */
16
- import { sha3_256 } from '@noble/hashes/sha3.js';
17
- import { sha256 } from '@noble/hashes/sha2.js';
18
- import { randomBytes } from '@noble/hashes/utils.js';
19
- import { createTimelockDescriptor, createHTLCDescriptor, createMASTDescriptor, createExchangeDescriptor, createFlashCashDescriptor, createSlowCashDescriptor } from './types.js';
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.StatefulGameHelper = exports.SlowCashHelper = exports.FlashCashHelper = exports.VaultHelper = exports.ExchangeHelper = exports.MASTHelper = exports.HTLCHelper = exports.TimelockHelper = void 0;
19
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
20
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
21
+ const utils_js_1 = require("@noble/hashes/utils.js");
22
+ const types_js_1 = require("./types.js");
20
23
  function kissHex(hex) {
21
24
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
22
25
  return '0x' + raw.toUpperCase();
@@ -37,7 +40,7 @@ function bytesToHex(bytes) {
37
40
  *
38
41
  * Creates timelocked scripts that can only be spent after a certain block.
39
42
  */
40
- export class TimelockHelper {
43
+ class TimelockHelper {
41
44
  /**
42
45
  * Create a timelock script that unlocks at a specific block.
43
46
  */
@@ -64,22 +67,23 @@ export class TimelockHelper {
64
67
  * Build ScriptDescriptor for a timelock spend.
65
68
  */
66
69
  static buildDescriptor(address, publicKey, unlockBlock) {
67
- return createTimelockDescriptor(address, publicKey, unlockBlock);
70
+ return (0, types_js_1.createTimelockDescriptor)(address, publicKey, unlockBlock);
68
71
  }
69
72
  }
73
+ exports.TimelockHelper = TimelockHelper;
70
74
  /**
71
75
  * HTLC Helper
72
76
  *
73
77
  * Creates Hashed Timelock Contracts for atomic swaps and lightning-style payments.
74
78
  */
75
- export class HTLCHelper {
79
+ class HTLCHelper {
76
80
  /**
77
81
  * Generate a random preimage and its hash.
78
82
  */
79
83
  static generateSecret() {
80
- const preimageBytes = randomBytes(32);
84
+ const preimageBytes = (0, utils_js_1.randomBytes)(32);
81
85
  const preimage = bytesToHex(preimageBytes);
82
- const hashBytes = sha3_256(preimageBytes);
86
+ const hashBytes = (0, sha3_js_1.sha3_256)(preimageBytes);
83
87
  const hash = bytesToHex(hashBytes);
84
88
  return { preimage, hash };
85
89
  }
@@ -89,11 +93,11 @@ export class HTLCHelper {
89
93
  static hashPreimage(preimage, algorithm = 'sha3') {
90
94
  const preimageBytes = hexToBytes(preimage);
91
95
  if (algorithm === 'sha2') {
92
- const hashBytes = sha256(preimageBytes);
96
+ const hashBytes = (0, sha2_js_1.sha256)(preimageBytes);
93
97
  return bytesToHex(hashBytes);
94
98
  }
95
99
  else {
96
- const hashBytes = sha3_256(preimageBytes);
100
+ const hashBytes = (0, sha3_js_1.sha3_256)(preimageBytes);
97
101
  return bytesToHex(hashBytes);
98
102
  }
99
103
  }
@@ -121,27 +125,28 @@ export class HTLCHelper {
121
125
  * Build ScriptDescriptor to claim HTLC with preimage.
122
126
  */
123
127
  static buildClaimDescriptor(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock, preimage) {
124
- return createHTLCDescriptor(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock, false, preimage);
128
+ return (0, types_js_1.createHTLCDescriptor)(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock, false, preimage);
125
129
  }
126
130
  /**
127
131
  * Build ScriptDescriptor to refund HTLC after timeout.
128
132
  */
129
133
  static buildRefundDescriptor(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock) {
130
- return createHTLCDescriptor(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock, true);
134
+ return (0, types_js_1.createHTLCDescriptor)(address, senderPublicKey, recipientPublicKey, hashLock, timeoutBlock, true);
131
135
  }
132
136
  }
137
+ exports.HTLCHelper = HTLCHelper;
133
138
  /**
134
139
  * MAST Helper
135
140
  *
136
141
  * Creates Merkelized Abstract Syntax Tree contracts for privacy and scalability.
137
142
  */
138
- export class MASTHelper {
143
+ class MASTHelper {
139
144
  /**
140
145
  * Compute hash of a script for MAST leaf.
141
146
  */
142
147
  static hashScript(script) {
143
148
  const scriptBytes = new TextEncoder().encode(script.trim().toUpperCase());
144
- const hashBytes = sha3_256(scriptBytes);
149
+ const hashBytes = (0, sha3_js_1.sha3_256)(scriptBytes);
145
150
  return bytesToHex(hashBytes);
146
151
  }
147
152
  /**
@@ -172,7 +177,7 @@ export class MASTHelper {
172
177
  proofs.set(scripts[i], { proof: proofHex, index: i });
173
178
  }
174
179
  const combinedBytes = hexToBytes(hashes[0].slice(2) + hashes[1].slice(2));
175
- const rootBytes = sha3_256(combinedBytes);
180
+ const rootBytes = (0, sha3_js_1.sha3_256)(combinedBytes);
176
181
  const root = bytesToHex(rootBytes);
177
182
  return { root, proofs };
178
183
  }
@@ -188,15 +193,16 @@ export class MASTHelper {
188
193
  * Build ScriptDescriptor for spending a MAST branch.
189
194
  */
190
195
  static buildDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
191
- return createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey);
196
+ return (0, types_js_1.createMASTDescriptor)(address, rootHash, branchScript, branchProof, wotsPublicKey);
192
197
  }
193
198
  }
199
+ exports.MASTHelper = MASTHelper;
194
200
  /**
195
201
  * Exchange Contract Helper
196
202
  *
197
203
  * Creates DEX-style exchange contracts using VERIFYOUT.
198
204
  */
199
- export class ExchangeHelper {
205
+ class ExchangeHelper {
200
206
  /**
201
207
  * Create an exchange offer script.
202
208
  *
@@ -223,7 +229,7 @@ export class ExchangeHelper {
223
229
  * Build ScriptDescriptor for taking an exchange offer.
224
230
  */
225
231
  static buildTakeOfferDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
226
- return createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId);
232
+ return (0, types_js_1.createExchangeDescriptor)(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId);
227
233
  }
228
234
  /**
229
235
  * Validate VERIFYOUT for an exchange transaction.
@@ -245,12 +251,13 @@ export class ExchangeHelper {
245
251
  return { valid: true };
246
252
  }
247
253
  }
254
+ exports.ExchangeHelper = ExchangeHelper;
248
255
  /**
249
256
  * Vault Helper
250
257
  *
251
258
  * Creates vault/covenant contracts with safe house enforcement.
252
259
  */
253
- export class VaultHelper {
260
+ class VaultHelper {
254
261
  /**
255
262
  * Generate safe house script from vault parameters.
256
263
  */
@@ -282,12 +289,13 @@ export class VaultHelper {
282
289
  ];
283
290
  }
284
291
  }
292
+ exports.VaultHelper = VaultHelper;
285
293
  /**
286
294
  * Flash Cash Helper
287
295
  *
288
296
  * Creates flash loan contracts for single-transaction borrowing.
289
297
  */
290
- export class FlashCashHelper {
298
+ class FlashCashHelper {
291
299
  /**
292
300
  * Create a flash cash contract.
293
301
  */
@@ -307,15 +315,16 @@ export class FlashCashHelper {
307
315
  * Build ScriptDescriptor for borrowing flash cash.
308
316
  */
309
317
  static buildBorrowDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
310
- return createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier);
318
+ return (0, types_js_1.createFlashCashDescriptor)(address, ownerPublicKey, interestMultiplier);
311
319
  }
312
320
  }
321
+ exports.FlashCashHelper = FlashCashHelper;
313
322
  /**
314
323
  * Slow Cash Helper
315
324
  *
316
325
  * Creates rate-limited withdrawal contracts.
317
326
  */
318
- export class SlowCashHelper {
327
+ class SlowCashHelper {
319
328
  /**
320
329
  * Create a slow cash contract.
321
330
  */
@@ -342,15 +351,16 @@ export class SlowCashHelper {
342
351
  * Build ScriptDescriptor for slow cash withdrawal.
343
352
  */
344
353
  static buildWithdrawalDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
345
- return createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent, cooldownBlocks);
354
+ return (0, types_js_1.createSlowCashDescriptor)(address, ownerPublicKey, withdrawalPercent, cooldownBlocks);
346
355
  }
347
356
  }
357
+ exports.SlowCashHelper = SlowCashHelper;
348
358
  /**
349
359
  * Stateful Game Helper
350
360
  *
351
361
  * Creates multi-round stateful contracts (like coin flip).
352
362
  */
353
- export class StatefulGameHelper {
363
+ class StatefulGameHelper {
354
364
  /**
355
365
  * Create a round increment assertion.
356
366
  */
@@ -376,10 +386,11 @@ export class StatefulGameHelper {
376
386
  return currentRound === previousRound + 1;
377
387
  }
378
388
  }
389
+ exports.StatefulGameHelper = StatefulGameHelper;
379
390
  function computeScriptAddress(script) {
380
391
  const cleanScript = script.trim().toUpperCase();
381
392
  const scriptBytes = new TextEncoder().encode(cleanScript);
382
- const hashBytes = sha3_256(scriptBytes);
393
+ const hashBytes = (0, sha3_js_1.sha3_256)(scriptBytes);
383
394
  return bytesToHex(hashBytes);
384
395
  }
385
396
  function encodeSimpleProof(siblingHash, isLeft) {
@@ -1,12 +1,17 @@
1
- export const TOTEM_SEND_TRANSACTION_VERSION = 1;
2
- export function validateSendTransactionRequest(request) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TOTEM_SEND_TRANSACTION_VERSION = void 0;
4
+ exports.validateSendTransactionRequest = validateSendTransactionRequest;
5
+ exports.simpleTotemSendRequest = simpleTotemSendRequest;
6
+ exports.TOTEM_SEND_TRANSACTION_VERSION = 1;
7
+ function validateSendTransactionRequest(request) {
3
8
  const errors = [];
4
9
  if (!request || typeof request !== 'object') {
5
10
  return { valid: false, errors: ['Request must be an object'] };
6
11
  }
7
12
  const req = request;
8
- if (req.version !== TOTEM_SEND_TRANSACTION_VERSION) {
9
- errors.push(`Invalid version: expected ${TOTEM_SEND_TRANSACTION_VERSION}, got ${req.version}`);
13
+ if (req.version !== exports.TOTEM_SEND_TRANSACTION_VERSION) {
14
+ errors.push(`Invalid version: expected ${exports.TOTEM_SEND_TRANSACTION_VERSION}, got ${req.version}`);
10
15
  }
11
16
  const validIntents = [
12
17
  'send', 'token_send', 'swap', 'liquidity_add', 'liquidity_remove',
@@ -59,9 +64,9 @@ export function validateSendTransactionRequest(request) {
59
64
  }
60
65
  return { valid: errors.length === 0, errors };
61
66
  }
62
- export function simpleTotemSendRequest(to, amount, tokenId) {
67
+ function simpleTotemSendRequest(to, amount, tokenId) {
63
68
  return {
64
- version: TOTEM_SEND_TRANSACTION_VERSION,
69
+ version: exports.TOTEM_SEND_TRANSACTION_VERSION,
65
70
  intent: tokenId && tokenId !== '0x00' ? 'token_send' : 'send',
66
71
  outputs: [{
67
72
  address: to,