@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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Transaction Serialization & Digest Computation
4
3
  *
@@ -11,22 +10,14 @@
11
10
  * precomputeTransactionCoinID() to set output coin IDs. Without this, the signed
12
11
  * digest won't match what the Minima node verifies, causing allsignaturesvalid=false.
13
12
  */
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 wasm_sync_js_1 = require("./wasm-sync.js");
23
- const Streamable_js_1 = require("./Streamable.js");
13
+ import { sha3_256 } from './wasm-sync.js';
14
+ import { writeMiniNumber, writeMiniData, writeHashToStream, writeMiniByte, writeMMREntryNumber, concat, hexToBytes, } from './Streamable.js';
24
15
  const ZERO_TXPOWID = new Uint8Array([0x00]);
25
16
  const STATETYPE_HEX = 1;
26
17
  const STATETYPE_NUMBER = 2;
27
18
  const STATETYPE_STRING = 4;
28
19
  const STATETYPE_BOOL = 8;
29
- function parseDecimalToMiniNumber(decimal) {
20
+ export function parseDecimalToMiniNumber(decimal) {
30
21
  if (!decimal || decimal === '') {
31
22
  return { scale: 0, unscaledValue: 0n };
32
23
  }
@@ -60,7 +51,7 @@ function parseDecimalToMiniNumber(decimal) {
60
51
  return { scale, unscaledValue };
61
52
  }
62
53
  function encodeParsedMiniNumber(parsed) {
63
- return (0, Streamable_js_1.writeMiniNumber)(parsed.unscaledValue, parsed.scale);
54
+ return writeMiniNumber(parsed.unscaledValue, parsed.scale);
64
55
  }
65
56
  function normalizeAddressToHex(addr) {
66
57
  if (!addr) {
@@ -100,10 +91,10 @@ function serializeStateVariable(sv) {
100
91
  case 'number':
101
92
  typeByte = new Uint8Array([STATETYPE_NUMBER]);
102
93
  if (typeof sv.value === 'bigint') {
103
- dataBytes = (0, Streamable_js_1.writeMiniNumber)(sv.value);
94
+ dataBytes = writeMiniNumber(sv.value, 0);
104
95
  }
105
96
  else if (typeof sv.value === 'string') {
106
- dataBytes = (0, Streamable_js_1.writeMiniNumber)(BigInt(sv.value));
97
+ dataBytes = writeMiniNumber(BigInt(sv.value), 0);
107
98
  }
108
99
  else {
109
100
  throw new Error(`Invalid number StateVariable value: ${sv.value}`);
@@ -113,10 +104,10 @@ function serializeStateVariable(sv) {
113
104
  typeByte = new Uint8Array([STATETYPE_HEX]);
114
105
  if (typeof sv.value === 'string') {
115
106
  const normalizedHex = normalizeAddressToHex(sv.value);
116
- dataBytes = (0, Streamable_js_1.writeMiniData)((0, Streamable_js_1.hexToBytes)(normalizedHex));
107
+ dataBytes = writeMiniData(hexToBytes(normalizedHex));
117
108
  }
118
109
  else if (sv.value instanceof Uint8Array) {
119
- dataBytes = (0, Streamable_js_1.writeMiniData)(sv.value);
110
+ dataBytes = writeMiniData(sv.value);
120
111
  }
121
112
  else {
122
113
  throw new Error(`Invalid hex StateVariable value: ${sv.value}`);
@@ -130,7 +121,7 @@ function serializeStateVariable(sv) {
130
121
  bracketedValue = `[${sv.value}]`;
131
122
  }
132
123
  const utf8Bytes = new TextEncoder().encode(bracketedValue);
133
- dataBytes = (0, Streamable_js_1.writeMiniData)(utf8Bytes);
124
+ dataBytes = writeMiniData(utf8Bytes);
134
125
  }
135
126
  else {
136
127
  throw new Error(`Invalid string StateVariable value: ${sv.value}`);
@@ -139,23 +130,23 @@ function serializeStateVariable(sv) {
139
130
  default:
140
131
  throw new Error(`Unknown StateVariable type: ${sv.type}`);
141
132
  }
142
- return (0, Streamable_js_1.concat)(portByte, typeByte, dataBytes);
133
+ return concat(portByte, typeByte, dataBytes);
143
134
  }
144
135
  function serializeToken(token) {
145
136
  // Java Token.writeDataStream() order: coinId, script, scale, totalAmount, name, created
146
137
  const 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);
138
+ parts.push(writeHashToStream(token.coinId));
139
+ parts.push(writeMiniData(token.script));
140
+ parts.push(writeMiniNumber(BigInt(token.scale), 0));
141
+ parts.push(writeMiniNumber(token.totalAmount, 0));
142
+ parts.push(writeMiniData(token.name));
143
+ parts.push(writeMiniNumber(token.created ?? 0n, 0));
144
+ return concat(...parts);
154
145
  }
155
- function serializeCoin(coin) {
146
+ export function serializeCoin(coin) {
156
147
  const parts = [];
157
- parts.push((0, Streamable_js_1.writeHashToStream)(coin.coinId));
158
- parts.push((0, Streamable_js_1.writeHashToStream)(coin.address));
148
+ parts.push(writeHashToStream(coin.coinId));
149
+ parts.push(writeHashToStream(coin.address));
159
150
  let amountBytes;
160
151
  if (coin.rawAmountBytes && coin.rawAmountBytes.length > 0) {
161
152
  amountBytes = coin.rawAmountBytes;
@@ -165,26 +156,26 @@ function serializeCoin(coin) {
165
156
  amountBytes = encodeParsedMiniNumber(parsedAmount);
166
157
  }
167
158
  parts.push(amountBytes);
168
- parts.push((0, Streamable_js_1.writeMiniData)(coin.tokenId));
169
- parts.push((0, Streamable_js_1.writeMiniByte)(coin.storeState));
159
+ parts.push(writeMiniData(coin.tokenId));
160
+ parts.push(writeMiniByte(coin.storeState));
170
161
  let mmrBytes;
171
162
  if (coin.rawMmrEntryBytes && coin.rawMmrEntryBytes.length > 0) {
172
163
  mmrBytes = coin.rawMmrEntryBytes;
173
164
  }
174
165
  else {
175
- mmrBytes = (0, Streamable_js_1.writeMMREntryNumber)(coin.mmrEntryNumber);
166
+ mmrBytes = writeMMREntryNumber(coin.mmrEntryNumber);
176
167
  }
177
168
  parts.push(mmrBytes);
178
- parts.push((0, Streamable_js_1.writeMiniByte)(coin.spent));
169
+ parts.push(writeMiniByte(coin.spent));
179
170
  let createdBytes;
180
171
  if (coin.rawBlockCreatedBytes && coin.rawBlockCreatedBytes.length > 0) {
181
172
  createdBytes = coin.rawBlockCreatedBytes;
182
173
  }
183
174
  else {
184
- createdBytes = (0, Streamable_js_1.writeMiniNumber)(coin.created);
175
+ createdBytes = writeMiniNumber(coin.created, 0);
185
176
  }
186
177
  parts.push(createdBytes);
187
- const stateCountBytes = (0, Streamable_js_1.writeMiniNumber)(BigInt(coin.state.length));
178
+ const stateCountBytes = writeMiniNumber(BigInt(coin.state.length), 0);
188
179
  parts.push(stateCountBytes);
189
180
  for (const sv of coin.state) {
190
181
  let svBytes;
@@ -192,7 +183,7 @@ function serializeCoin(coin) {
192
183
  const raw = sv;
193
184
  const portByte = new Uint8Array([raw.port]);
194
185
  const typeByte = new Uint8Array([raw.type]);
195
- svBytes = (0, Streamable_js_1.concat)(portByte, typeByte, raw.rawData);
186
+ svBytes = concat(portByte, typeByte, raw.rawData);
196
187
  }
197
188
  else {
198
189
  svBytes = serializeStateVariable(sv);
@@ -200,40 +191,40 @@ function serializeCoin(coin) {
200
191
  parts.push(svBytes);
201
192
  }
202
193
  if (coin.rawTokenData && coin.rawTokenData.length > 0) {
203
- parts.push((0, Streamable_js_1.writeMiniByte)(true));
194
+ parts.push(writeMiniByte(true));
204
195
  parts.push(coin.rawTokenData);
205
196
  }
206
197
  else if (coin.token) {
207
- parts.push((0, Streamable_js_1.writeMiniByte)(true));
198
+ parts.push(writeMiniByte(true));
208
199
  parts.push(serializeToken(coin.token));
209
200
  }
210
201
  else {
211
- parts.push((0, Streamable_js_1.writeMiniByte)(false));
202
+ parts.push(writeMiniByte(false));
212
203
  }
213
- return (0, Streamable_js_1.concat)(...parts);
204
+ return concat(...parts);
214
205
  }
215
- function serializeTransaction(tx) {
206
+ export function serializeTransaction(tx) {
216
207
  const parts = [];
217
- parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.inputs.length)));
208
+ parts.push(writeMiniNumber(BigInt(tx.inputs.length), 0));
218
209
  for (const input of tx.inputs) {
219
210
  parts.push(serializeCoin(input));
220
211
  }
221
- parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.outputs.length)));
212
+ parts.push(writeMiniNumber(BigInt(tx.outputs.length), 0));
222
213
  for (const output of tx.outputs) {
223
214
  parts.push(serializeCoin(output));
224
215
  }
225
- parts.push((0, Streamable_js_1.writeMiniNumber)(BigInt(tx.state.length)));
216
+ parts.push(writeMiniNumber(BigInt(tx.state.length), 0));
226
217
  for (const sv of tx.state) {
227
218
  parts.push(serializeStateVariable(sv));
228
219
  }
229
- parts.push((0, Streamable_js_1.writeHashToStream)(tx.linkHash));
230
- return (0, Streamable_js_1.concat)(...parts);
220
+ parts.push(writeHashToStream(tx.linkHash));
221
+ return concat(...parts);
231
222
  }
232
- function computeTransactionDigest(tx) {
223
+ export function computeTransactionDigest(tx) {
233
224
  const serialized = serializeTransaction(tx);
234
- return (0, wasm_sync_js_1.sha3_256)(serialized);
225
+ return sha3_256(serialized);
235
226
  }
236
- function precomputeTransactionCoinID(tx) {
227
+ export function precomputeTransactionCoinID(tx) {
237
228
  if (tx.inputs.length === 0)
238
229
  return;
239
230
  const baseCoinId = tx.inputs[0].coinId;
@@ -242,13 +233,13 @@ function precomputeTransactionCoinID(tx) {
242
233
  `(placeholder?). Real coinId from CoinProof required for signing.`);
243
234
  }
244
235
  for (let i = 0; i < tx.outputs.length; i++) {
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, wasm_sync_js_1.sha3_256)(combined);
236
+ const baseCoinIdStream = writeMiniData(baseCoinId);
237
+ const outputIndexStream = writeMiniNumber(BigInt(i), 0);
238
+ const combined = concat(baseCoinIdStream, outputIndexStream);
239
+ tx.outputs[i].coinId = sha3_256(combined);
249
240
  }
250
241
  }
251
- function createDefaultTransaction() {
242
+ export function createDefaultTransaction() {
252
243
  return {
253
244
  linkHash: ZERO_TXPOWID,
254
245
  inputs: [],
@@ -256,7 +247,7 @@ function createDefaultTransaction() {
256
247
  state: [],
257
248
  };
258
249
  }
259
- function buildMinimaCoin(opts) {
250
+ export function buildMinimaCoin(opts) {
260
251
  if (opts.coinProofData) {
261
252
  const cpd = opts.coinProofData;
262
253
  return {