@totemsdk/core 1.2.5 → 1.2.7

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 (127) hide show
  1. package/dist/MiniNumber.js +19 -21
  2. package/dist/Streamable.js +31 -54
  3. package/dist/adapters/index.js +9 -18
  4. package/dist/adapters/types.js +11 -19
  5. package/dist/binio.js +7 -20
  6. package/dist/bip39.js +14 -24
  7. package/dist/canonical.d.ts +3 -0
  8. package/dist/canonical.js +22 -0
  9. package/dist/cjs/MiniNumber.d.ts +47 -0
  10. package/dist/cjs/MiniNumber.js +302 -0
  11. package/dist/cjs/Streamable.d.ts +268 -0
  12. package/dist/cjs/Streamable.js +439 -0
  13. package/dist/cjs/adapters/index.d.ts +190 -0
  14. package/dist/cjs/adapters/index.js +118 -0
  15. package/dist/cjs/adapters/types.d.ts +150 -0
  16. package/dist/cjs/adapters/types.js +81 -0
  17. package/dist/cjs/binio.d.ts +9 -0
  18. package/dist/cjs/binio.js +25 -0
  19. package/dist/cjs/bip39.d.ts +91 -0
  20. package/dist/cjs/bip39.js +434 -0
  21. package/dist/cjs/canonical.d.ts +3 -0
  22. package/dist/cjs/canonical.js +27 -0
  23. package/dist/cjs/derive.d.ts +2 -0
  24. package/dist/cjs/derive.js +13 -0
  25. package/dist/cjs/index.d.ts +49 -0
  26. package/dist/cjs/index.js +231 -0
  27. package/dist/cjs/javaStreamables.d.ts +254 -0
  28. package/dist/cjs/javaStreamables.js +391 -0
  29. package/dist/cjs/lease/LeaseMonitor.d.ts +44 -0
  30. package/dist/cjs/lease/LeaseMonitor.js +115 -0
  31. package/dist/cjs/lease/LeaseStore.d.ts +58 -0
  32. package/dist/cjs/lease/LeaseStore.js +151 -0
  33. package/dist/cjs/lease/WatermarkStore.d.ts +61 -0
  34. package/dist/cjs/lease/WatermarkStore.js +209 -0
  35. package/dist/cjs/lease/index.d.ts +14 -0
  36. package/dist/cjs/lease/index.js +22 -0
  37. package/dist/cjs/lease-client.d.ts +31 -0
  38. package/dist/cjs/lease-client.js +44 -0
  39. package/dist/cjs/legacy.d.ts +23 -0
  40. package/dist/cjs/legacy.js +163 -0
  41. package/dist/cjs/minima32.d.ts +18 -0
  42. package/dist/cjs/minima32.js +121 -0
  43. package/dist/cjs/minimaWireSerializer.d.ts +60 -0
  44. package/dist/cjs/minimaWireSerializer.js +77 -0
  45. package/dist/cjs/mmr.d.ts +157 -0
  46. package/dist/cjs/mmr.js +352 -0
  47. package/dist/cjs/mx.d.ts +1 -0
  48. package/dist/cjs/mx.js +10 -0
  49. package/dist/cjs/package.json +1 -0
  50. package/dist/cjs/params.d.ts +29 -0
  51. package/dist/cjs/params.js +20 -0
  52. package/dist/cjs/script.d.ts +7 -0
  53. package/dist/cjs/script.js +27 -0
  54. package/dist/cjs/scripts/contract-helpers.d.ts +252 -0
  55. package/dist/cjs/scripts/contract-helpers.js +407 -0
  56. package/dist/cjs/scripts/dapp-types.d.ts +119 -0
  57. package/dist/cjs/scripts/dapp-types.js +77 -0
  58. package/dist/cjs/scripts/index.d.ts +4 -0
  59. package/dist/cjs/scripts/index.js +38 -0
  60. package/dist/cjs/scripts/types.d.ts +81 -0
  61. package/dist/cjs/scripts/types.js +159 -0
  62. package/dist/cjs/scripts/witness-serializer.d.ts +29 -0
  63. package/dist/cjs/scripts/witness-serializer.js +306 -0
  64. package/dist/cjs/transaction.d.ts +106 -0
  65. package/dist/cjs/transaction.js +293 -0
  66. package/dist/cjs/treekey.d.ts +399 -0
  67. package/dist/cjs/treekey.js +827 -0
  68. package/dist/cjs/tx/TransactionLifecycle.d.ts +55 -0
  69. package/dist/cjs/tx/TransactionLifecycle.js +205 -0
  70. package/dist/cjs/tx/TransactionReceiptStore.d.ts +36 -0
  71. package/dist/cjs/tx/TransactionReceiptStore.js +93 -0
  72. package/dist/cjs/tx/TransactionService.d.ts +50 -0
  73. package/dist/cjs/tx/TransactionService.js +186 -0
  74. package/dist/cjs/tx/index.d.ts +13 -0
  75. package/dist/cjs/tx/index.js +20 -0
  76. package/dist/cjs/tx/types.d.ts +115 -0
  77. package/dist/cjs/tx/types.js +6 -0
  78. package/dist/cjs/util.d.ts +1 -0
  79. package/dist/cjs/util.js +5 -0
  80. package/dist/cjs/utils.d.ts +8 -0
  81. package/dist/cjs/utils.js +42 -0
  82. package/dist/cjs/verify.d.ts +18 -0
  83. package/dist/cjs/verify.js +174 -0
  84. package/dist/cjs/version.d.ts +12 -0
  85. package/dist/cjs/version.js +15 -0
  86. package/dist/cjs/wasm-sync.d.ts +71 -0
  87. package/dist/cjs/wasm-sync.js +97 -0
  88. package/dist/cjs/wots.d.ts +232 -0
  89. package/dist/cjs/wots.js +589 -0
  90. package/dist/derive.js +7 -11
  91. package/dist/index.d.ts +8 -2
  92. package/dist/index.js +50 -143
  93. package/dist/javaStreamables.js +34 -55
  94. package/dist/lease/LeaseMonitor.js +10 -10
  95. package/dist/lease/LeaseStore.js +8 -9
  96. package/dist/lease/WatermarkStore.js +8 -9
  97. package/dist/lease/index.js +4 -13
  98. package/dist/lease-client.js +3 -8
  99. package/dist/legacy.js +13 -140
  100. package/dist/minima32.js +13 -22
  101. package/dist/minimaWireSerializer.js +14 -20
  102. package/dist/mmr.js +27 -41
  103. package/dist/mx.js +1 -10
  104. package/dist/params.js +5 -9
  105. package/dist/script.js +7 -12
  106. package/dist/scripts/contract-helpers.js +25 -36
  107. package/dist/scripts/dapp-types.js +6 -11
  108. package/dist/scripts/index.js +4 -38
  109. package/dist/scripts/types.js +12 -26
  110. package/dist/scripts/witness-serializer.js +30 -48
  111. package/dist/transaction.js +46 -55
  112. package/dist/treekey.js +96 -89
  113. package/dist/tx/TransactionLifecycle.js +15 -11
  114. package/dist/tx/TransactionReceiptStore.js +9 -9
  115. package/dist/tx/TransactionService.js +14 -14
  116. package/dist/tx/index.js +3 -11
  117. package/dist/tx/types.js +1 -2
  118. package/dist/util.js +1 -5
  119. package/dist/utils.js +5 -12
  120. package/dist/verify.js +25 -36
  121. package/dist/version.js +2 -5
  122. package/dist/wasm-sync.d.ts +2 -2
  123. package/dist/wasm-sync.js +58 -61
  124. package/dist/wots.js +64 -94
  125. package/package.json +84 -45
  126. package/dist/wasm-bridge.d.ts +0 -54
  127. package/dist/wasm-bridge.js +0 -303
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,
@@ -1,38 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.computeScriptAddress = exports.validateExternalSignature = exports.aggregateSignatures = exports.serializeExtraScripts = exports.deduplicateScriptDescriptors = exports.buildScriptProofFromDescriptor = exports.serializeStateVariables = exports.encodeStateValue = exports.STATETYPE_BOOL = exports.STATETYPE_STRING = exports.STATETYPE_NUMBER = exports.STATETYPE_HEX = exports.serializeScriptProofWithProof = exports.serializeMMRProofChunk = exports.encodeMiniString = exports.encodeMiniData = exports.encodeMiniNumber = void 0;
18
- __exportStar(require("./types.js"), exports);
19
- __exportStar(require("./dapp-types.js"), exports);
20
- var witness_serializer_js_1 = require("./witness-serializer.js");
21
- Object.defineProperty(exports, "encodeMiniNumber", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniNumber; } });
22
- Object.defineProperty(exports, "encodeMiniData", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniData; } });
23
- Object.defineProperty(exports, "encodeMiniString", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniString; } });
24
- Object.defineProperty(exports, "serializeMMRProofChunk", { enumerable: true, get: function () { return witness_serializer_js_1.serializeMMRProofChunk; } });
25
- Object.defineProperty(exports, "serializeScriptProofWithProof", { enumerable: true, get: function () { return witness_serializer_js_1.serializeScriptProofWithProof; } });
26
- Object.defineProperty(exports, "STATETYPE_HEX", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_HEX; } });
27
- Object.defineProperty(exports, "STATETYPE_NUMBER", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_NUMBER; } });
28
- Object.defineProperty(exports, "STATETYPE_STRING", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_STRING; } });
29
- Object.defineProperty(exports, "STATETYPE_BOOL", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_BOOL; } });
30
- Object.defineProperty(exports, "encodeStateValue", { enumerable: true, get: function () { return witness_serializer_js_1.encodeStateValue; } });
31
- Object.defineProperty(exports, "serializeStateVariables", { enumerable: true, get: function () { return witness_serializer_js_1.serializeStateVariables; } });
32
- Object.defineProperty(exports, "buildScriptProofFromDescriptor", { enumerable: true, get: function () { return witness_serializer_js_1.buildScriptProofFromDescriptor; } });
33
- Object.defineProperty(exports, "deduplicateScriptDescriptors", { enumerable: true, get: function () { return witness_serializer_js_1.deduplicateScriptDescriptors; } });
34
- Object.defineProperty(exports, "serializeExtraScripts", { enumerable: true, get: function () { return witness_serializer_js_1.serializeExtraScripts; } });
35
- Object.defineProperty(exports, "aggregateSignatures", { enumerable: true, get: function () { return witness_serializer_js_1.aggregateSignatures; } });
36
- Object.defineProperty(exports, "validateExternalSignature", { enumerable: true, get: function () { return witness_serializer_js_1.validateExternalSignature; } });
37
- Object.defineProperty(exports, "computeScriptAddress", { enumerable: true, get: function () { return witness_serializer_js_1.computeScriptAddress; } });
38
- __exportStar(require("./contract-helpers.js"), exports);
1
+ export * from './types.js';
2
+ export * from './dapp-types.js';
3
+ export { encodeMiniNumber, encodeMiniData, encodeMiniString, serializeMMRProofChunk, serializeScriptProofWithProof, STATETYPE_HEX, STATETYPE_NUMBER, STATETYPE_STRING, STATETYPE_BOOL, encodeStateValue, serializeStateVariables, buildScriptProofFromDescriptor, deduplicateScriptDescriptors, serializeExtraScripts, aggregateSignatures, validateExternalSignature, computeScriptAddress, } from './witness-serializer.js';
4
+ export * from './contract-helpers.js';
@@ -1,28 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertFlatChunkToSDK = convertFlatChunkToSDK;
4
- exports.convertLegacyProofToSDK = convertLegacyProofToSDK;
5
- exports.createEmptyMMRProof = createEmptyMMRProof;
6
- exports.createSignedByDescriptor = createSignedByDescriptor;
7
- exports.createMultisigDescriptor = createMultisigDescriptor;
8
- exports.createMofNMultisigDescriptor = createMofNMultisigDescriptor;
9
- exports.createTimelockDescriptor = createTimelockDescriptor;
10
- exports.createHTLCDescriptor = createHTLCDescriptor;
11
- exports.createMASTDescriptor = createMASTDescriptor;
12
- exports.createExchangeDescriptor = createExchangeDescriptor;
13
- exports.createFlashCashDescriptor = createFlashCashDescriptor;
14
- exports.createSlowCashDescriptor = createSlowCashDescriptor;
15
1
  function kissHex(hex) {
16
2
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
17
3
  return '0x' + raw.toUpperCase();
18
4
  }
19
- function convertFlatChunkToSDK(chunk) {
5
+ export function convertFlatChunkToSDK(chunk) {
20
6
  return {
21
7
  isLeft: chunk.isLeft,
22
8
  mmrData: { data: chunk.data, value: 0n }
23
9
  };
24
10
  }
25
- function convertLegacyProofToSDK(legacy) {
11
+ export function convertLegacyProofToSDK(legacy) {
26
12
  return {
27
13
  proof: {
28
14
  chunks: legacy.proofChain.map(convertFlatChunkToSDK)
@@ -30,10 +16,10 @@ function convertLegacyProofToSDK(legacy) {
30
16
  blockTime: legacy.blockTime
31
17
  };
32
18
  }
33
- function createEmptyMMRProof() {
19
+ export function createEmptyMMRProof() {
34
20
  return { chunks: [] };
35
21
  }
36
- function createSignedByDescriptor(address, wotsRootPublicKey) {
22
+ export function createSignedByDescriptor(address, wotsRootPublicKey) {
37
23
  return {
38
24
  address,
39
25
  scriptType: 'signedby',
@@ -43,7 +29,7 @@ function createSignedByDescriptor(address, wotsRootPublicKey) {
43
29
  storeState: false
44
30
  };
45
31
  }
46
- function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
32
+ export function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
47
33
  return {
48
34
  address,
49
35
  scriptType: 'multisig',
@@ -55,7 +41,7 @@ function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey)
55
41
  storeState: false
56
42
  };
57
43
  }
58
- function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
44
+ export function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
59
45
  const formattedKeys = publicKeys.map(pk => kissHex(pk)).join(' ');
60
46
  return {
61
47
  address,
@@ -68,7 +54,7 @@ function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicK
68
54
  storeState: false
69
55
  };
70
56
  }
71
- function createTimelockDescriptor(address, publicKey, unlockBlock) {
57
+ export function createTimelockDescriptor(address, publicKey, unlockBlock) {
72
58
  return {
73
59
  address,
74
60
  scriptType: 'timelock',
@@ -79,7 +65,7 @@ function createTimelockDescriptor(address, publicKey, unlockBlock) {
79
65
  storeState: false
80
66
  };
81
67
  }
82
- function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
68
+ export function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
83
69
  const script = `IF @BLOCK GT ${timeoutBlock} AND SIGNEDBY(${kissHex(ownerPublicKey)}) THEN RETURN TRUE ENDIF RETURN (SIGNEDBY(${kissHex(recipientPublicKey)}) AND SHA3(STATE(1)) EQ ${kissHex(hashLock)})`;
84
70
  const descriptor = {
85
71
  address,
@@ -97,7 +83,7 @@ function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashL
97
83
  }
98
84
  return descriptor;
99
85
  }
100
- function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
86
+ export function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
101
87
  return {
102
88
  address,
103
89
  scriptType: 'mast',
@@ -108,7 +94,7 @@ function createMASTDescriptor(address, rootHash, branchScript, branchProof, wots
108
94
  storeState: false
109
95
  };
110
96
  }
111
- function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
97
+ export function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
112
98
  const ownerPk = kissHex(ownerPublicKey);
113
99
  const script = `IF SIGNEDBY(PREVSTATE(0)) THEN RETURN TRUE ENDIF ASSERT VERIFYOUT(@INPUT PREVSTATE(1) PREVSTATE(2) PREVSTATE(3) TRUE) RETURN TRUE`;
114
100
  return {
@@ -133,7 +119,7 @@ function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desir
133
119
  storeState: true
134
120
  };
135
121
  }
136
- function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
122
+ export function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
137
123
  const script = `IF SIGNEDBY(PREVSTATE(1)) THEN RETURN TRUE ENDIF ASSERT SAMESTATE(1 1) RETURN VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${interestMultiplier} @TOKENID TRUE)`;
138
124
  return {
139
125
  address,
@@ -145,7 +131,7 @@ function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier =
145
131
  storeState: true
146
132
  };
147
133
  }
148
- function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
134
+ export function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
149
135
  const script = `IF @COINAGE LT ${cooldownBlocks} THEN RETURN FALSE ENDIF ASSERT SIGNEDBY(${kissHex(ownerPublicKey)}) AND VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${withdrawalPercent} @TOKENID TRUE)`;
150
136
  return {
151
137
  address,
@@ -1,25 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STATETYPE_BOOL = exports.STATETYPE_STRING = exports.STATETYPE_NUMBER = exports.STATETYPE_HEX = void 0;
4
- exports.encodeMiniNumber = encodeMiniNumber;
5
- exports.encodeMiniData = encodeMiniData;
6
- exports.encodeMiniString = encodeMiniString;
7
- exports.serializeMMRProofChunk = serializeMMRProofChunk;
8
- exports.serializeRealMMRProof = serializeRealMMRProof;
9
- exports.parseMMRProofFromHex = parseMMRProofFromHex;
10
- exports.serializeScriptProofWithProof = serializeScriptProofWithProof;
11
- exports.encodeStateValue = encodeStateValue;
12
- exports.serializeStateVariables = serializeStateVariables;
13
- exports.buildScriptProofFromDescriptor = buildScriptProofFromDescriptor;
14
- exports.deduplicateScriptDescriptors = deduplicateScriptDescriptors;
15
- exports.serializeExtraScripts = serializeExtraScripts;
16
- exports.aggregateSignatures = aggregateSignatures;
17
- exports.validateExternalSignature = validateExternalSignature;
18
- exports.computeScriptAddress = computeScriptAddress;
19
- exports.concat = concat;
20
- const wasm_sync_js_1 = require("../wasm-sync.js");
21
- const mmr_js_1 = require("../mmr.js");
22
- const minima32_js_1 = require("../minima32.js");
1
+ import { sha3_256 } from '../wasm-sync.js';
2
+ import { serializeMMRProof } from '../mmr.js';
3
+ import { mxToHex } from '../minima32.js';
23
4
  function hexToBytes(hex) {
24
5
  const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
25
6
  if (cleanHex.length % 2 !== 0) {
@@ -36,7 +17,7 @@ function normalizeHexValue(value) {
36
17
  return '0x00';
37
18
  const trimmed = value.trim();
38
19
  if (trimmed.toLowerCase().startsWith('mx')) {
39
- return (0, minima32_js_1.mxToHex)(trimmed);
20
+ return mxToHex(trimmed);
40
21
  }
41
22
  return trimmed.startsWith('0x') ? trimmed : '0x' + trimmed;
42
23
  }
@@ -53,7 +34,7 @@ function concat(...arrays) {
53
34
  }
54
35
  return result;
55
36
  }
56
- function encodeMiniNumber(value, scale = 0) {
37
+ export function encodeMiniNumber(value, scale = 0) {
57
38
  if (typeof value !== 'bigint') {
58
39
  throw new Error(`encodeMiniNumber requires bigint, got ${typeof value}`);
59
40
  }
@@ -84,7 +65,7 @@ function encodeMiniNumber(value, scale = 0) {
84
65
  result.set(unscaledBytes, 2);
85
66
  return result;
86
67
  }
87
- function encodeMiniData(data) {
68
+ export function encodeMiniData(data) {
88
69
  const length = data.length;
89
70
  const lengthBytes = new Uint8Array([
90
71
  (length >> 24) & 0xff,
@@ -94,24 +75,24 @@ function encodeMiniData(data) {
94
75
  ]);
95
76
  return concat(lengthBytes, data);
96
77
  }
97
- function encodeMiniString(str) {
78
+ export function encodeMiniString(str) {
98
79
  const utf8Bytes = new TextEncoder().encode(str);
99
80
  return encodeMiniData(utf8Bytes);
100
81
  }
101
82
  function encodeMiniByte(value) {
102
83
  return new Uint8Array([value ? 1 : 0]);
103
84
  }
104
- function serializeMMRProofChunk(chunk) {
85
+ export function serializeMMRProofChunk(chunk) {
105
86
  const parts = [];
106
87
  parts.push(encodeMiniByte(chunk.isLeft));
107
88
  parts.push(encodeMiniData(chunk.mmrData.data));
108
89
  parts.push(encodeMiniNumber(chunk.mmrData.value));
109
90
  return concat(...parts);
110
91
  }
111
- function serializeRealMMRProof(proof, blockTime = 0n) {
112
- return (0, mmr_js_1.serializeMMRProof)(proof, blockTime);
92
+ export function serializeRealMMRProof(proof, blockTime = 0n) {
93
+ return serializeMMRProof(proof, blockTime);
113
94
  }
114
- function parseMMRProofFromHex(proofHex) {
95
+ export function parseMMRProofFromHex(proofHex) {
115
96
  const bytes = hexToBytes(proofHex);
116
97
  let offset = 0;
117
98
  const { value: blockTime, bytesRead: btRead } = readMiniNumber(bytes, offset);
@@ -156,16 +137,16 @@ function readMMRProofChunk(bytes, offset) {
156
137
  bytesRead: pos - offset
157
138
  };
158
139
  }
159
- function serializeScriptProofWithProof(script, proof, blockTime = 0n) {
140
+ export function serializeScriptProofWithProof(script, proof, blockTime = 0n) {
160
141
  const scriptBytes = encodeMiniString(script);
161
142
  const proofBytes = serializeRealMMRProof(proof, blockTime);
162
143
  return concat(scriptBytes, proofBytes);
163
144
  }
164
- exports.STATETYPE_HEX = 1;
165
- exports.STATETYPE_NUMBER = 2;
166
- exports.STATETYPE_STRING = 4;
167
- exports.STATETYPE_BOOL = 8;
168
- function encodeStateValue(stateValue) {
145
+ export const STATETYPE_HEX = 1;
146
+ export const STATETYPE_NUMBER = 2;
147
+ export const STATETYPE_STRING = 4;
148
+ export const STATETYPE_BOOL = 8;
149
+ export function encodeStateValue(stateValue) {
169
150
  if (stateValue.port < 0 || stateValue.port > 255) {
170
151
  throw new Error(`StateVariable port must be 0-255, got ${stateValue.port}`);
171
152
  }
@@ -174,7 +155,7 @@ function encodeStateValue(stateValue) {
174
155
  let dataBytes;
175
156
  switch (stateValue.type) {
176
157
  case 'bool':
177
- typeByte = new Uint8Array([exports.STATETYPE_BOOL]);
158
+ typeByte = new Uint8Array([STATETYPE_BOOL]);
178
159
  if (typeof stateValue.value === 'boolean') {
179
160
  dataBytes = new Uint8Array([stateValue.value ? 1 : 0]);
180
161
  }
@@ -187,7 +168,7 @@ function encodeStateValue(stateValue) {
187
168
  }
188
169
  break;
189
170
  case 'number':
190
- typeByte = new Uint8Array([exports.STATETYPE_NUMBER]);
171
+ typeByte = new Uint8Array([STATETYPE_NUMBER]);
191
172
  if (typeof stateValue.value === 'bigint') {
192
173
  dataBytes = encodeMiniNumber(stateValue.value);
193
174
  }
@@ -200,7 +181,7 @@ function encodeStateValue(stateValue) {
200
181
  }
201
182
  break;
202
183
  case 'hex':
203
- typeByte = new Uint8Array([exports.STATETYPE_HEX]);
184
+ typeByte = new Uint8Array([STATETYPE_HEX]);
204
185
  if (typeof stateValue.value === 'string') {
205
186
  const normalizedHex = normalizeHexValue(stateValue.value);
206
187
  dataBytes = encodeMiniData(hexToBytes(normalizedHex));
@@ -213,7 +194,7 @@ function encodeStateValue(stateValue) {
213
194
  }
214
195
  break;
215
196
  case 'string':
216
- typeByte = new Uint8Array([exports.STATETYPE_STRING]);
197
+ typeByte = new Uint8Array([STATETYPE_STRING]);
217
198
  if (typeof stateValue.value === 'string') {
218
199
  let bracketedValue = stateValue.value;
219
200
  if (!stateValue.value.startsWith('[') || !stateValue.value.endsWith(']')) {
@@ -230,7 +211,7 @@ function encodeStateValue(stateValue) {
230
211
  }
231
212
  return concat(portByte, typeByte, dataBytes);
232
213
  }
233
- function serializeStateVariables(stateValues) {
214
+ export function serializeStateVariables(stateValues) {
234
215
  const parts = [];
235
216
  const countBytes = encodeMiniNumber(BigInt(stateValues.length));
236
217
  parts.push(countBytes);
@@ -240,7 +221,7 @@ function serializeStateVariables(stateValues) {
240
221
  }
241
222
  return concat(...parts);
242
223
  }
243
- function buildScriptProofFromDescriptor(descriptor) {
224
+ export function buildScriptProofFromDescriptor(descriptor) {
244
225
  const proof = descriptor.mastProof || { chunks: [] };
245
226
  const serialized = serializeScriptProofWithProof(descriptor.script, proof);
246
227
  return {
@@ -249,7 +230,7 @@ function buildScriptProofFromDescriptor(descriptor) {
249
230
  serialized
250
231
  };
251
232
  }
252
- function deduplicateScriptDescriptors(descriptors) {
233
+ export function deduplicateScriptDescriptors(descriptors) {
253
234
  const unique = new Map();
254
235
  for (const desc of descriptors) {
255
236
  const normalizedAddr = desc.address.toLowerCase();
@@ -259,7 +240,7 @@ function deduplicateScriptDescriptors(descriptors) {
259
240
  }
260
241
  return unique;
261
242
  }
262
- function serializeExtraScripts(extraScripts) {
243
+ export function serializeExtraScripts(extraScripts) {
263
244
  const parts = [];
264
245
  const countBytes = encodeMiniNumber(BigInt(extraScripts.size));
265
246
  parts.push(countBytes);
@@ -271,7 +252,7 @@ function serializeExtraScripts(extraScripts) {
271
252
  }
272
253
  return concat(...parts);
273
254
  }
274
- function aggregateSignatures(totemSignature, externalSignatures) {
255
+ export function aggregateSignatures(totemSignature, externalSignatures) {
275
256
  const allSigProofs = [];
276
257
  allSigProofs.push(serializeSignatureProof(totemSignature.publicKey, totemSignature.signature, { chunks: [] }));
277
258
  for (const extSig of externalSignatures) {
@@ -291,16 +272,17 @@ function serializeSignatureProof(publicKey, signature, proof) {
291
272
  parts.push(serializeRealMMRProof(proof));
292
273
  return concat(...parts);
293
274
  }
294
- function validateExternalSignature(signature, transactionDigest) {
275
+ export function validateExternalSignature(signature, transactionDigest) {
295
276
  if (!signature.publicKey || !signature.signature) {
296
277
  return false;
297
278
  }
298
279
  console.log(`[ValidateSignature] Validating signature from ${signature.publicKey.substring(0, 16)}...`);
299
280
  return true;
300
281
  }
301
- function computeScriptAddress(script) {
282
+ export function computeScriptAddress(script) {
302
283
  const cleanScript = script.trim().toUpperCase();
303
284
  const scriptBytes = new TextEncoder().encode(cleanScript);
304
- const hashBytes = (0, wasm_sync_js_1.sha3_256)(scriptBytes);
285
+ const hashBytes = sha3_256(scriptBytes);
305
286
  return bytesToHex(hashBytes);
306
287
  }
288
+ export { concat };