@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
@@ -1,4 +1,38 @@
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
+ "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,14 +1,28 @@
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;
1
15
  function kissHex(hex) {
2
16
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
3
17
  return '0x' + raw.toUpperCase();
4
18
  }
5
- export function convertFlatChunkToSDK(chunk) {
19
+ function convertFlatChunkToSDK(chunk) {
6
20
  return {
7
21
  isLeft: chunk.isLeft,
8
22
  mmrData: { data: chunk.data, value: 0n }
9
23
  };
10
24
  }
11
- export function convertLegacyProofToSDK(legacy) {
25
+ function convertLegacyProofToSDK(legacy) {
12
26
  return {
13
27
  proof: {
14
28
  chunks: legacy.proofChain.map(convertFlatChunkToSDK)
@@ -16,10 +30,10 @@ export function convertLegacyProofToSDK(legacy) {
16
30
  blockTime: legacy.blockTime
17
31
  };
18
32
  }
19
- export function createEmptyMMRProof() {
33
+ function createEmptyMMRProof() {
20
34
  return { chunks: [] };
21
35
  }
22
- export function createSignedByDescriptor(address, wotsRootPublicKey) {
36
+ function createSignedByDescriptor(address, wotsRootPublicKey) {
23
37
  return {
24
38
  address,
25
39
  scriptType: 'signedby',
@@ -29,7 +43,7 @@ export function createSignedByDescriptor(address, wotsRootPublicKey) {
29
43
  storeState: false
30
44
  };
31
45
  }
32
- export function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
46
+ function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
33
47
  return {
34
48
  address,
35
49
  scriptType: 'multisig',
@@ -41,7 +55,7 @@ export function createMultisigDescriptor(address, publicKey1, publicKey2, ownPub
41
55
  storeState: false
42
56
  };
43
57
  }
44
- export function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
58
+ function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
45
59
  const formattedKeys = publicKeys.map(pk => kissHex(pk)).join(' ');
46
60
  return {
47
61
  address,
@@ -54,7 +68,7 @@ export function createMofNMultisigDescriptor(address, threshold, publicKeys, own
54
68
  storeState: false
55
69
  };
56
70
  }
57
- export function createTimelockDescriptor(address, publicKey, unlockBlock) {
71
+ function createTimelockDescriptor(address, publicKey, unlockBlock) {
58
72
  return {
59
73
  address,
60
74
  scriptType: 'timelock',
@@ -65,7 +79,7 @@ export function createTimelockDescriptor(address, publicKey, unlockBlock) {
65
79
  storeState: false
66
80
  };
67
81
  }
68
- export function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
82
+ function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
69
83
  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)})`;
70
84
  const descriptor = {
71
85
  address,
@@ -83,7 +97,7 @@ export function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey
83
97
  }
84
98
  return descriptor;
85
99
  }
86
- export function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
100
+ function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
87
101
  return {
88
102
  address,
89
103
  scriptType: 'mast',
@@ -94,7 +108,7 @@ export function createMASTDescriptor(address, rootHash, branchScript, branchProo
94
108
  storeState: false
95
109
  };
96
110
  }
97
- export function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
111
+ function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
98
112
  const ownerPk = kissHex(ownerPublicKey);
99
113
  const script = `IF SIGNEDBY(PREVSTATE(0)) THEN RETURN TRUE ENDIF ASSERT VERIFYOUT(@INPUT PREVSTATE(1) PREVSTATE(2) PREVSTATE(3) TRUE) RETURN TRUE`;
100
114
  return {
@@ -119,7 +133,7 @@ export function createExchangeDescriptor(address, ownerPublicKey, desiredAddress
119
133
  storeState: true
120
134
  };
121
135
  }
122
- export function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
136
+ function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
123
137
  const script = `IF SIGNEDBY(PREVSTATE(1)) THEN RETURN TRUE ENDIF ASSERT SAMESTATE(1 1) RETURN VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${interestMultiplier} @TOKENID TRUE)`;
124
138
  return {
125
139
  address,
@@ -131,7 +145,7 @@ export function createFlashCashDescriptor(address, ownerPublicKey, interestMulti
131
145
  storeState: true
132
146
  };
133
147
  }
134
- export function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
148
+ function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
135
149
  const script = `IF @COINAGE LT ${cooldownBlocks} THEN RETURN FALSE ENDIF ASSERT SIGNEDBY(${kissHex(ownerPublicKey)}) AND VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${withdrawalPercent} @TOKENID TRUE)`;
136
150
  return {
137
151
  address,
@@ -1,6 +1,25 @@
1
- import { sha3_256 } from '@noble/hashes/sha3.js';
2
- import { serializeMMRProof } from '../mmr.js';
3
- import { mxToHex } from '../minima32.js';
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 sha3_js_1 = require("@noble/hashes/sha3.js");
21
+ const mmr_js_1 = require("../mmr.js");
22
+ const minima32_js_1 = require("../minima32.js");
4
23
  function hexToBytes(hex) {
5
24
  const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
6
25
  if (cleanHex.length % 2 !== 0) {
@@ -17,7 +36,7 @@ function normalizeHexValue(value) {
17
36
  return '0x00';
18
37
  const trimmed = value.trim();
19
38
  if (trimmed.toLowerCase().startsWith('mx')) {
20
- return mxToHex(trimmed);
39
+ return (0, minima32_js_1.mxToHex)(trimmed);
21
40
  }
22
41
  return trimmed.startsWith('0x') ? trimmed : '0x' + trimmed;
23
42
  }
@@ -34,7 +53,7 @@ function concat(...arrays) {
34
53
  }
35
54
  return result;
36
55
  }
37
- export function encodeMiniNumber(value, scale = 0) {
56
+ function encodeMiniNumber(value, scale = 0) {
38
57
  if (typeof value !== 'bigint') {
39
58
  throw new Error(`encodeMiniNumber requires bigint, got ${typeof value}`);
40
59
  }
@@ -65,7 +84,7 @@ export function encodeMiniNumber(value, scale = 0) {
65
84
  result.set(unscaledBytes, 2);
66
85
  return result;
67
86
  }
68
- export function encodeMiniData(data) {
87
+ function encodeMiniData(data) {
69
88
  const length = data.length;
70
89
  const lengthBytes = new Uint8Array([
71
90
  (length >> 24) & 0xff,
@@ -75,24 +94,24 @@ export function encodeMiniData(data) {
75
94
  ]);
76
95
  return concat(lengthBytes, data);
77
96
  }
78
- export function encodeMiniString(str) {
97
+ function encodeMiniString(str) {
79
98
  const utf8Bytes = new TextEncoder().encode(str);
80
99
  return encodeMiniData(utf8Bytes);
81
100
  }
82
101
  function encodeMiniByte(value) {
83
102
  return new Uint8Array([value ? 1 : 0]);
84
103
  }
85
- export function serializeMMRProofChunk(chunk) {
104
+ function serializeMMRProofChunk(chunk) {
86
105
  const parts = [];
87
106
  parts.push(encodeMiniByte(chunk.isLeft));
88
107
  parts.push(encodeMiniData(chunk.mmrData.data));
89
108
  parts.push(encodeMiniNumber(chunk.mmrData.value));
90
109
  return concat(...parts);
91
110
  }
92
- export function serializeRealMMRProof(proof, blockTime = 0n) {
93
- return serializeMMRProof(proof, blockTime);
111
+ function serializeRealMMRProof(proof, blockTime = 0n) {
112
+ return (0, mmr_js_1.serializeMMRProof)(proof, blockTime);
94
113
  }
95
- export function parseMMRProofFromHex(proofHex) {
114
+ function parseMMRProofFromHex(proofHex) {
96
115
  const bytes = hexToBytes(proofHex);
97
116
  let offset = 0;
98
117
  const { value: blockTime, bytesRead: btRead } = readMiniNumber(bytes, offset);
@@ -137,16 +156,16 @@ function readMMRProofChunk(bytes, offset) {
137
156
  bytesRead: pos - offset
138
157
  };
139
158
  }
140
- export function serializeScriptProofWithProof(script, proof, blockTime = 0n) {
159
+ function serializeScriptProofWithProof(script, proof, blockTime = 0n) {
141
160
  const scriptBytes = encodeMiniString(script);
142
161
  const proofBytes = serializeRealMMRProof(proof, blockTime);
143
162
  return concat(scriptBytes, proofBytes);
144
163
  }
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) {
164
+ exports.STATETYPE_HEX = 1;
165
+ exports.STATETYPE_NUMBER = 2;
166
+ exports.STATETYPE_STRING = 4;
167
+ exports.STATETYPE_BOOL = 8;
168
+ function encodeStateValue(stateValue) {
150
169
  if (stateValue.port < 0 || stateValue.port > 255) {
151
170
  throw new Error(`StateVariable port must be 0-255, got ${stateValue.port}`);
152
171
  }
@@ -155,7 +174,7 @@ export function encodeStateValue(stateValue) {
155
174
  let dataBytes;
156
175
  switch (stateValue.type) {
157
176
  case 'bool':
158
- typeByte = new Uint8Array([STATETYPE_BOOL]);
177
+ typeByte = new Uint8Array([exports.STATETYPE_BOOL]);
159
178
  if (typeof stateValue.value === 'boolean') {
160
179
  dataBytes = new Uint8Array([stateValue.value ? 1 : 0]);
161
180
  }
@@ -168,7 +187,7 @@ export function encodeStateValue(stateValue) {
168
187
  }
169
188
  break;
170
189
  case 'number':
171
- typeByte = new Uint8Array([STATETYPE_NUMBER]);
190
+ typeByte = new Uint8Array([exports.STATETYPE_NUMBER]);
172
191
  if (typeof stateValue.value === 'bigint') {
173
192
  dataBytes = encodeMiniNumber(stateValue.value);
174
193
  }
@@ -181,7 +200,7 @@ export function encodeStateValue(stateValue) {
181
200
  }
182
201
  break;
183
202
  case 'hex':
184
- typeByte = new Uint8Array([STATETYPE_HEX]);
203
+ typeByte = new Uint8Array([exports.STATETYPE_HEX]);
185
204
  if (typeof stateValue.value === 'string') {
186
205
  const normalizedHex = normalizeHexValue(stateValue.value);
187
206
  dataBytes = encodeMiniData(hexToBytes(normalizedHex));
@@ -194,7 +213,7 @@ export function encodeStateValue(stateValue) {
194
213
  }
195
214
  break;
196
215
  case 'string':
197
- typeByte = new Uint8Array([STATETYPE_STRING]);
216
+ typeByte = new Uint8Array([exports.STATETYPE_STRING]);
198
217
  if (typeof stateValue.value === 'string') {
199
218
  let bracketedValue = stateValue.value;
200
219
  if (!stateValue.value.startsWith('[') || !stateValue.value.endsWith(']')) {
@@ -211,7 +230,7 @@ export function encodeStateValue(stateValue) {
211
230
  }
212
231
  return concat(portByte, typeByte, dataBytes);
213
232
  }
214
- export function serializeStateVariables(stateValues) {
233
+ function serializeStateVariables(stateValues) {
215
234
  const parts = [];
216
235
  const countBytes = encodeMiniNumber(BigInt(stateValues.length));
217
236
  parts.push(countBytes);
@@ -221,7 +240,7 @@ export function serializeStateVariables(stateValues) {
221
240
  }
222
241
  return concat(...parts);
223
242
  }
224
- export function buildScriptProofFromDescriptor(descriptor) {
243
+ function buildScriptProofFromDescriptor(descriptor) {
225
244
  const proof = descriptor.mastProof || { chunks: [] };
226
245
  const serialized = serializeScriptProofWithProof(descriptor.script, proof);
227
246
  return {
@@ -230,7 +249,7 @@ export function buildScriptProofFromDescriptor(descriptor) {
230
249
  serialized
231
250
  };
232
251
  }
233
- export function deduplicateScriptDescriptors(descriptors) {
252
+ function deduplicateScriptDescriptors(descriptors) {
234
253
  const unique = new Map();
235
254
  for (const desc of descriptors) {
236
255
  const normalizedAddr = desc.address.toLowerCase();
@@ -240,7 +259,7 @@ export function deduplicateScriptDescriptors(descriptors) {
240
259
  }
241
260
  return unique;
242
261
  }
243
- export function serializeExtraScripts(extraScripts) {
262
+ function serializeExtraScripts(extraScripts) {
244
263
  const parts = [];
245
264
  const countBytes = encodeMiniNumber(BigInt(extraScripts.size));
246
265
  parts.push(countBytes);
@@ -252,7 +271,7 @@ export function serializeExtraScripts(extraScripts) {
252
271
  }
253
272
  return concat(...parts);
254
273
  }
255
- export function aggregateSignatures(totemSignature, externalSignatures) {
274
+ function aggregateSignatures(totemSignature, externalSignatures) {
256
275
  const allSigProofs = [];
257
276
  allSigProofs.push(serializeSignatureProof(totemSignature.publicKey, totemSignature.signature, { chunks: [] }));
258
277
  for (const extSig of externalSignatures) {
@@ -272,17 +291,16 @@ function serializeSignatureProof(publicKey, signature, proof) {
272
291
  parts.push(serializeRealMMRProof(proof));
273
292
  return concat(...parts);
274
293
  }
275
- export function validateExternalSignature(signature, transactionDigest) {
294
+ function validateExternalSignature(signature, transactionDigest) {
276
295
  if (!signature.publicKey || !signature.signature) {
277
296
  return false;
278
297
  }
279
298
  console.log(`[ValidateSignature] Validating signature from ${signature.publicKey.substring(0, 16)}...`);
280
299
  return true;
281
300
  }
282
- export function computeScriptAddress(script) {
301
+ function computeScriptAddress(script) {
283
302
  const cleanScript = script.trim().toUpperCase();
284
303
  const scriptBytes = new TextEncoder().encode(cleanScript);
285
- const hashBytes = sha3_256(scriptBytes);
304
+ const hashBytes = (0, sha3_js_1.sha3_256)(scriptBytes);
286
305
  return bytesToHex(hashBytes);
287
306
  }
288
- export { concat };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Transaction Serialization & Digest Computation
3
4
  *
@@ -10,14 +11,22 @@
10
11
  * precomputeTransactionCoinID() to set output coin IDs. Without this, the signed
11
12
  * digest won't match what the Minima node verifies, causing allsignaturesvalid=false.
12
13
  */
13
- import { sha3_256 } from '@noble/hashes/sha3.js';
14
- import { writeMiniNumber, writeMiniData, writeHashToStream, writeMiniByte, writeMMREntryNumber, concat, hexToBytes, } from './Streamable.js';
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.parseDecimalToMiniNumber = parseDecimalToMiniNumber;
16
+ exports.serializeCoin = serializeCoin;
17
+ exports.serializeTransaction = serializeTransaction;
18
+ exports.computeTransactionDigest = computeTransactionDigest;
19
+ exports.precomputeTransactionCoinID = precomputeTransactionCoinID;
20
+ exports.createDefaultTransaction = createDefaultTransaction;
21
+ exports.buildMinimaCoin = buildMinimaCoin;
22
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
23
+ const Streamable_js_1 = require("./Streamable.js");
15
24
  const ZERO_TXPOWID = new Uint8Array([0x00]);
16
25
  const STATETYPE_HEX = 1;
17
26
  const STATETYPE_NUMBER = 2;
18
27
  const STATETYPE_STRING = 4;
19
28
  const STATETYPE_BOOL = 8;
20
- export function parseDecimalToMiniNumber(decimal) {
29
+ function parseDecimalToMiniNumber(decimal) {
21
30
  if (!decimal || decimal === '') {
22
31
  return { scale: 0, unscaledValue: 0n };
23
32
  }
@@ -51,7 +60,7 @@ export function parseDecimalToMiniNumber(decimal) {
51
60
  return { scale, unscaledValue };
52
61
  }
53
62
  function encodeParsedMiniNumber(parsed) {
54
- return writeMiniNumber(parsed.unscaledValue, parsed.scale);
63
+ return (0, Streamable_js_1.writeMiniNumber)(parsed.unscaledValue, parsed.scale);
55
64
  }
56
65
  function normalizeAddressToHex(addr) {
57
66
  if (!addr) {
@@ -91,10 +100,10 @@ function serializeStateVariable(sv) {
91
100
  case 'number':
92
101
  typeByte = new Uint8Array([STATETYPE_NUMBER]);
93
102
  if (typeof sv.value === 'bigint') {
94
- dataBytes = writeMiniNumber(sv.value);
103
+ dataBytes = (0, Streamable_js_1.writeMiniNumber)(sv.value);
95
104
  }
96
105
  else if (typeof sv.value === 'string') {
97
- dataBytes = writeMiniNumber(BigInt(sv.value));
106
+ dataBytes = (0, Streamable_js_1.writeMiniNumber)(BigInt(sv.value));
98
107
  }
99
108
  else {
100
109
  throw new Error(`Invalid number StateVariable value: ${sv.value}`);
@@ -104,10 +113,10 @@ function serializeStateVariable(sv) {
104
113
  typeByte = new Uint8Array([STATETYPE_HEX]);
105
114
  if (typeof sv.value === 'string') {
106
115
  const normalizedHex = normalizeAddressToHex(sv.value);
107
- dataBytes = writeMiniData(hexToBytes(normalizedHex));
116
+ dataBytes = (0, Streamable_js_1.writeMiniData)((0, Streamable_js_1.hexToBytes)(normalizedHex));
108
117
  }
109
118
  else if (sv.value instanceof Uint8Array) {
110
- dataBytes = writeMiniData(sv.value);
119
+ dataBytes = (0, Streamable_js_1.writeMiniData)(sv.value);
111
120
  }
112
121
  else {
113
122
  throw new Error(`Invalid hex StateVariable value: ${sv.value}`);
@@ -121,7 +130,7 @@ function serializeStateVariable(sv) {
121
130
  bracketedValue = `[${sv.value}]`;
122
131
  }
123
132
  const utf8Bytes = new TextEncoder().encode(bracketedValue);
124
- dataBytes = writeMiniData(utf8Bytes);
133
+ dataBytes = (0, Streamable_js_1.writeMiniData)(utf8Bytes);
125
134
  }
126
135
  else {
127
136
  throw new Error(`Invalid string StateVariable value: ${sv.value}`);
@@ -130,23 +139,23 @@ function serializeStateVariable(sv) {
130
139
  default:
131
140
  throw new Error(`Unknown StateVariable type: ${sv.type}`);
132
141
  }
133
- return concat(portByte, typeByte, dataBytes);
142
+ return (0, Streamable_js_1.concat)(portByte, typeByte, dataBytes);
134
143
  }
135
144
  function serializeToken(token) {
136
145
  // Java Token.writeDataStream() order: coinId, script, scale, totalAmount, name, created
137
146
  const parts = [];
138
- parts.push(writeHashToStream(token.coinId));
139
- parts.push(writeMiniData(token.script));
140
- parts.push(writeMiniNumber(BigInt(token.scale)));
141
- parts.push(writeMiniNumber(token.totalAmount, 0));
142
- parts.push(writeMiniData(token.name));
143
- parts.push(writeMiniNumber(token.created ?? 0n));
144
- return concat(...parts);
147
+ parts.push((0, Streamable_js_1.writeHashToStream)(token.coinId));
148
+ parts.push((0, Streamable_js_1.writeMiniData)(token.script));
149
+ parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(token.scale)));
150
+ parts.push((0, Streamable_js_1.writeMiniNumber)(token.totalAmount, 0));
151
+ parts.push((0, Streamable_js_1.writeMiniData)(token.name));
152
+ parts.push((0, Streamable_js_1.writeMiniNumber)(token.created ?? 0n));
153
+ return (0, Streamable_js_1.concat)(...parts);
145
154
  }
146
- export function serializeCoin(coin) {
155
+ function serializeCoin(coin) {
147
156
  const parts = [];
148
- parts.push(writeHashToStream(coin.coinId));
149
- parts.push(writeHashToStream(coin.address));
157
+ parts.push((0, Streamable_js_1.writeHashToStream)(coin.coinId));
158
+ parts.push((0, Streamable_js_1.writeHashToStream)(coin.address));
150
159
  let amountBytes;
151
160
  if (coin.rawAmountBytes && coin.rawAmountBytes.length > 0) {
152
161
  amountBytes = coin.rawAmountBytes;
@@ -156,26 +165,26 @@ export function serializeCoin(coin) {
156
165
  amountBytes = encodeParsedMiniNumber(parsedAmount);
157
166
  }
158
167
  parts.push(amountBytes);
159
- parts.push(writeMiniData(coin.tokenId));
160
- parts.push(writeMiniByte(coin.storeState));
168
+ parts.push((0, Streamable_js_1.writeMiniData)(coin.tokenId));
169
+ parts.push((0, Streamable_js_1.writeMiniByte)(coin.storeState));
161
170
  let mmrBytes;
162
171
  if (coin.rawMmrEntryBytes && coin.rawMmrEntryBytes.length > 0) {
163
172
  mmrBytes = coin.rawMmrEntryBytes;
164
173
  }
165
174
  else {
166
- mmrBytes = writeMMREntryNumber(coin.mmrEntryNumber);
175
+ mmrBytes = (0, Streamable_js_1.writeMMREntryNumber)(coin.mmrEntryNumber);
167
176
  }
168
177
  parts.push(mmrBytes);
169
- parts.push(writeMiniByte(coin.spent));
178
+ parts.push((0, Streamable_js_1.writeMiniByte)(coin.spent));
170
179
  let createdBytes;
171
180
  if (coin.rawBlockCreatedBytes && coin.rawBlockCreatedBytes.length > 0) {
172
181
  createdBytes = coin.rawBlockCreatedBytes;
173
182
  }
174
183
  else {
175
- createdBytes = writeMiniNumber(coin.created);
184
+ createdBytes = (0, Streamable_js_1.writeMiniNumber)(coin.created);
176
185
  }
177
186
  parts.push(createdBytes);
178
- const stateCountBytes = writeMiniNumber(BigInt(coin.state.length));
187
+ const stateCountBytes = (0, Streamable_js_1.writeMiniNumber)(BigInt(coin.state.length));
179
188
  parts.push(stateCountBytes);
180
189
  for (const sv of coin.state) {
181
190
  let svBytes;
@@ -183,7 +192,7 @@ export function serializeCoin(coin) {
183
192
  const raw = sv;
184
193
  const portByte = new Uint8Array([raw.port]);
185
194
  const typeByte = new Uint8Array([raw.type]);
186
- svBytes = concat(portByte, typeByte, raw.rawData);
195
+ svBytes = (0, Streamable_js_1.concat)(portByte, typeByte, raw.rawData);
187
196
  }
188
197
  else {
189
198
  svBytes = serializeStateVariable(sv);
@@ -191,40 +200,40 @@ export function serializeCoin(coin) {
191
200
  parts.push(svBytes);
192
201
  }
193
202
  if (coin.rawTokenData && coin.rawTokenData.length > 0) {
194
- parts.push(writeMiniByte(true));
203
+ parts.push((0, Streamable_js_1.writeMiniByte)(true));
195
204
  parts.push(coin.rawTokenData);
196
205
  }
197
206
  else if (coin.token) {
198
- parts.push(writeMiniByte(true));
207
+ parts.push((0, Streamable_js_1.writeMiniByte)(true));
199
208
  parts.push(serializeToken(coin.token));
200
209
  }
201
210
  else {
202
- parts.push(writeMiniByte(false));
211
+ parts.push((0, Streamable_js_1.writeMiniByte)(false));
203
212
  }
204
- return concat(...parts);
213
+ return (0, Streamable_js_1.concat)(...parts);
205
214
  }
206
- export function serializeTransaction(tx) {
215
+ function serializeTransaction(tx) {
207
216
  const parts = [];
208
- parts.push(writeMiniNumber(BigInt(tx.inputs.length)));
217
+ parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.inputs.length)));
209
218
  for (const input of tx.inputs) {
210
219
  parts.push(serializeCoin(input));
211
220
  }
212
- parts.push(writeMiniNumber(BigInt(tx.outputs.length)));
221
+ parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.outputs.length)));
213
222
  for (const output of tx.outputs) {
214
223
  parts.push(serializeCoin(output));
215
224
  }
216
- parts.push(writeMiniNumber(BigInt(tx.state.length)));
225
+ parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.state.length)));
217
226
  for (const sv of tx.state) {
218
227
  parts.push(serializeStateVariable(sv));
219
228
  }
220
- parts.push(writeHashToStream(tx.linkHash));
221
- return concat(...parts);
229
+ parts.push((0, Streamable_js_1.writeHashToStream)(tx.linkHash));
230
+ return (0, Streamable_js_1.concat)(...parts);
222
231
  }
223
- export function computeTransactionDigest(tx) {
232
+ function computeTransactionDigest(tx) {
224
233
  const serialized = serializeTransaction(tx);
225
- return sha3_256(serialized);
234
+ return (0, sha3_js_1.sha3_256)(serialized);
226
235
  }
227
- export function precomputeTransactionCoinID(tx) {
236
+ function precomputeTransactionCoinID(tx) {
228
237
  if (tx.inputs.length === 0)
229
238
  return;
230
239
  const baseCoinId = tx.inputs[0].coinId;
@@ -233,13 +242,13 @@ export function precomputeTransactionCoinID(tx) {
233
242
  `(placeholder?). Real coinId from CoinProof required for signing.`);
234
243
  }
235
244
  for (let i = 0; i < tx.outputs.length; i++) {
236
- const baseCoinIdStream = writeMiniData(baseCoinId);
237
- const outputIndexStream = writeMiniNumber(BigInt(i));
238
- const combined = concat(baseCoinIdStream, outputIndexStream);
239
- tx.outputs[i].coinId = sha3_256(combined);
245
+ const baseCoinIdStream = (0, Streamable_js_1.writeMiniData)(baseCoinId);
246
+ const outputIndexStream = (0, Streamable_js_1.writeMiniNumber)(BigInt(i));
247
+ const combined = (0, Streamable_js_1.concat)(baseCoinIdStream, outputIndexStream);
248
+ tx.outputs[i].coinId = (0, sha3_js_1.sha3_256)(combined);
240
249
  }
241
250
  }
242
- export function createDefaultTransaction() {
251
+ function createDefaultTransaction() {
243
252
  return {
244
253
  linkHash: ZERO_TXPOWID,
245
254
  inputs: [],
@@ -247,7 +256,7 @@ export function createDefaultTransaction() {
247
256
  state: [],
248
257
  };
249
258
  }
250
- export function buildMinimaCoin(opts) {
259
+ function buildMinimaCoin(opts) {
251
260
  if (opts.coinProofData) {
252
261
  const cpd = opts.coinProofData;
253
262
  return {