@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.
- package/dist/MiniNumber.js +19 -21
- package/dist/Streamable.js +31 -54
- package/dist/adapters/index.js +9 -18
- package/dist/adapters/types.js +11 -19
- package/dist/binio.js +7 -20
- package/dist/bip39.js +14 -24
- package/dist/canonical.d.ts +3 -0
- package/dist/canonical.js +22 -0
- package/dist/cjs/MiniNumber.d.ts +47 -0
- package/dist/cjs/MiniNumber.js +302 -0
- package/dist/cjs/Streamable.d.ts +268 -0
- package/dist/cjs/Streamable.js +439 -0
- package/dist/cjs/adapters/index.d.ts +190 -0
- package/dist/cjs/adapters/index.js +118 -0
- package/dist/cjs/adapters/types.d.ts +150 -0
- package/dist/cjs/adapters/types.js +81 -0
- package/dist/cjs/binio.d.ts +9 -0
- package/dist/cjs/binio.js +25 -0
- package/dist/cjs/bip39.d.ts +91 -0
- package/dist/cjs/bip39.js +434 -0
- package/dist/cjs/canonical.d.ts +3 -0
- package/dist/cjs/canonical.js +27 -0
- package/dist/cjs/derive.d.ts +2 -0
- package/dist/cjs/derive.js +13 -0
- package/dist/cjs/index.d.ts +49 -0
- package/dist/cjs/index.js +231 -0
- package/dist/cjs/javaStreamables.d.ts +254 -0
- package/dist/cjs/javaStreamables.js +391 -0
- package/dist/cjs/lease/LeaseMonitor.d.ts +44 -0
- package/dist/cjs/lease/LeaseMonitor.js +115 -0
- package/dist/cjs/lease/LeaseStore.d.ts +58 -0
- package/dist/cjs/lease/LeaseStore.js +151 -0
- package/dist/cjs/lease/WatermarkStore.d.ts +61 -0
- package/dist/cjs/lease/WatermarkStore.js +209 -0
- package/dist/cjs/lease/index.d.ts +14 -0
- package/dist/cjs/lease/index.js +22 -0
- package/dist/cjs/lease-client.d.ts +31 -0
- package/dist/cjs/lease-client.js +44 -0
- package/dist/cjs/legacy.d.ts +23 -0
- package/dist/cjs/legacy.js +163 -0
- package/dist/cjs/minima32.d.ts +18 -0
- package/dist/cjs/minima32.js +121 -0
- package/dist/cjs/minimaWireSerializer.d.ts +60 -0
- package/dist/cjs/minimaWireSerializer.js +77 -0
- package/dist/cjs/mmr.d.ts +157 -0
- package/dist/cjs/mmr.js +352 -0
- package/dist/cjs/mx.d.ts +1 -0
- package/dist/cjs/mx.js +10 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/params.d.ts +29 -0
- package/dist/cjs/params.js +20 -0
- package/dist/cjs/script.d.ts +7 -0
- package/dist/cjs/script.js +27 -0
- package/dist/cjs/scripts/contract-helpers.d.ts +252 -0
- package/dist/cjs/scripts/contract-helpers.js +407 -0
- package/dist/cjs/scripts/dapp-types.d.ts +119 -0
- package/dist/cjs/scripts/dapp-types.js +77 -0
- package/dist/cjs/scripts/index.d.ts +4 -0
- package/dist/cjs/scripts/index.js +38 -0
- package/dist/cjs/scripts/types.d.ts +81 -0
- package/dist/cjs/scripts/types.js +159 -0
- package/dist/cjs/scripts/witness-serializer.d.ts +29 -0
- package/dist/cjs/scripts/witness-serializer.js +306 -0
- package/dist/cjs/transaction.d.ts +106 -0
- package/dist/cjs/transaction.js +293 -0
- package/dist/cjs/treekey.d.ts +399 -0
- package/dist/cjs/treekey.js +827 -0
- package/dist/cjs/tx/TransactionLifecycle.d.ts +55 -0
- package/dist/cjs/tx/TransactionLifecycle.js +205 -0
- package/dist/cjs/tx/TransactionReceiptStore.d.ts +36 -0
- package/dist/cjs/tx/TransactionReceiptStore.js +93 -0
- package/dist/cjs/tx/TransactionService.d.ts +50 -0
- package/dist/cjs/tx/TransactionService.js +186 -0
- package/dist/cjs/tx/index.d.ts +13 -0
- package/dist/cjs/tx/index.js +20 -0
- package/dist/cjs/tx/types.d.ts +115 -0
- package/dist/cjs/tx/types.js +6 -0
- package/dist/cjs/util.d.ts +1 -0
- package/dist/cjs/util.js +5 -0
- package/dist/cjs/utils.d.ts +8 -0
- package/dist/cjs/utils.js +42 -0
- package/dist/cjs/verify.d.ts +18 -0
- package/dist/cjs/verify.js +174 -0
- package/dist/cjs/version.d.ts +12 -0
- package/dist/cjs/version.js +15 -0
- package/dist/cjs/wasm-sync.d.ts +71 -0
- package/dist/cjs/wasm-sync.js +97 -0
- package/dist/cjs/wots.d.ts +232 -0
- package/dist/cjs/wots.js +589 -0
- package/dist/derive.js +7 -11
- package/dist/index.d.ts +8 -2
- package/dist/index.js +50 -143
- package/dist/javaStreamables.js +34 -55
- package/dist/lease/LeaseMonitor.js +10 -10
- package/dist/lease/LeaseStore.js +8 -9
- package/dist/lease/WatermarkStore.js +8 -9
- package/dist/lease/index.js +4 -13
- package/dist/lease-client.js +3 -8
- package/dist/legacy.js +13 -140
- package/dist/minima32.js +13 -22
- package/dist/minimaWireSerializer.js +14 -20
- package/dist/mmr.js +27 -41
- package/dist/mx.js +1 -10
- package/dist/params.js +5 -9
- package/dist/script.js +7 -12
- package/dist/scripts/contract-helpers.js +25 -36
- package/dist/scripts/dapp-types.js +6 -11
- package/dist/scripts/index.js +4 -38
- package/dist/scripts/types.js +12 -26
- package/dist/scripts/witness-serializer.js +30 -48
- package/dist/transaction.js +46 -55
- package/dist/treekey.js +96 -89
- package/dist/tx/TransactionLifecycle.js +15 -11
- package/dist/tx/TransactionReceiptStore.js +9 -9
- package/dist/tx/TransactionService.js +14 -14
- package/dist/tx/index.js +3 -11
- package/dist/tx/types.js +1 -2
- package/dist/util.js +1 -5
- package/dist/utils.js +5 -12
- package/dist/verify.js +25 -36
- package/dist/version.js +2 -5
- package/dist/wasm-sync.d.ts +2 -2
- package/dist/wasm-sync.js +58 -61
- package/dist/wots.js +64 -94
- package/package.json +84 -45
- package/dist/wasm-bridge.d.ts +0 -54
- package/dist/wasm-bridge.js +0 -303
package/dist/transaction.js
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
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
|
|
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 =
|
|
94
|
+
dataBytes = writeMiniNumber(sv.value, 0);
|
|
104
95
|
}
|
|
105
96
|
else if (typeof sv.value === 'string') {
|
|
106
|
-
dataBytes =
|
|
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 =
|
|
107
|
+
dataBytes = writeMiniData(hexToBytes(normalizedHex));
|
|
117
108
|
}
|
|
118
109
|
else if (sv.value instanceof Uint8Array) {
|
|
119
|
-
dataBytes =
|
|
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 =
|
|
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
|
|
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(
|
|
148
|
-
parts.push(
|
|
149
|
-
parts.push(
|
|
150
|
-
parts.push(
|
|
151
|
-
parts.push(
|
|
152
|
-
parts.push(
|
|
153
|
-
return
|
|
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(
|
|
158
|
-
parts.push(
|
|
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(
|
|
169
|
-
parts.push(
|
|
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 =
|
|
166
|
+
mmrBytes = writeMMREntryNumber(coin.mmrEntryNumber);
|
|
176
167
|
}
|
|
177
168
|
parts.push(mmrBytes);
|
|
178
|
-
parts.push(
|
|
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 =
|
|
175
|
+
createdBytes = writeMiniNumber(coin.created, 0);
|
|
185
176
|
}
|
|
186
177
|
parts.push(createdBytes);
|
|
187
|
-
const stateCountBytes =
|
|
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 =
|
|
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(
|
|
194
|
+
parts.push(writeMiniByte(true));
|
|
204
195
|
parts.push(coin.rawTokenData);
|
|
205
196
|
}
|
|
206
197
|
else if (coin.token) {
|
|
207
|
-
parts.push(
|
|
198
|
+
parts.push(writeMiniByte(true));
|
|
208
199
|
parts.push(serializeToken(coin.token));
|
|
209
200
|
}
|
|
210
201
|
else {
|
|
211
|
-
parts.push(
|
|
202
|
+
parts.push(writeMiniByte(false));
|
|
212
203
|
}
|
|
213
|
-
return
|
|
204
|
+
return concat(...parts);
|
|
214
205
|
}
|
|
215
|
-
function serializeTransaction(tx) {
|
|
206
|
+
export function serializeTransaction(tx) {
|
|
216
207
|
const parts = [];
|
|
217
|
-
parts.push(
|
|
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(
|
|
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(
|
|
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(
|
|
230
|
-
return
|
|
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
|
|
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 =
|
|
246
|
-
const outputIndexStream =
|
|
247
|
-
const combined =
|
|
248
|
-
tx.outputs[i].coinId =
|
|
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 {
|