@totemsdk/core 1.2.4 → 1.2.6

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