@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.
- package/LICENSE +21 -0
- package/README.md +5 -5
- package/dist/Streamable.js +54 -31
- package/dist/adapters/index.js +18 -8
- package/dist/adapters/types.js +19 -8
- package/dist/binio.js +5 -1
- package/dist/bip39.js +24 -14
- package/dist/derive.js +11 -7
- package/dist/index.js +130 -22
- package/dist/javaStreamables.js +49 -30
- package/dist/lease/LeaseMonitor.js +7 -3
- package/dist/lease/LeaseStore.js +7 -3
- package/dist/lease/WatermarkStore.js +7 -3
- package/dist/lease/index.js +13 -4
- package/dist/lease-client.js +8 -3
- package/dist/minima32.js +22 -13
- package/dist/minimaWireSerializer.js +20 -14
- package/dist/mmr.js +35 -23
- package/dist/mx.js +10 -1
- package/dist/params.js +9 -5
- package/dist/script.js +12 -7
- package/dist/scripts/contract-helpers.js +37 -26
- package/dist/scripts/dapp-types.js +11 -6
- package/dist/scripts/index.js +38 -4
- package/dist/scripts/types.js +26 -12
- package/dist/scripts/witness-serializer.js +48 -30
- package/dist/transaction.js +55 -46
- package/dist/treekey.js +74 -58
- package/dist/tx/TransactionLifecycle.js +11 -5
- package/dist/tx/TransactionReceiptStore.js +7 -3
- package/dist/tx/TransactionService.js +14 -10
- package/dist/tx/index.js +11 -3
- package/dist/tx/types.js +2 -1
- package/dist/util.js +5 -1
- package/dist/utils.js +12 -5
- package/dist/verify.js +36 -25
- package/dist/version.js +5 -2
- package/dist/wots.js +94 -64
- package/package.json +31 -6
- package/src/Streamable.d.ts +0 -268
- package/src/Streamable.js +0 -416
- package/src/Streamable.ts +0 -567
- package/src/__tests__/Streamable.parity.test.ts +0 -422
- package/src/__tests__/perAddressDerivation.parity.test.ts +0 -152
- package/src/__tests__/roottree-prepare.test.ts +0 -101
- package/src/__tests__/wots-parity.test.ts +0 -289
- package/src/adapters/index.d.ts +0 -190
- package/src/adapters/index.js +0 -117
- package/src/adapters/index.ts +0 -301
- package/src/adapters/types.ts +0 -235
- package/src/addr.oracle.test.ts +0 -25
- package/src/address.test.ts +0 -55
- package/src/binio.ts +0 -21
- package/src/bip39.d.ts +0 -91
- package/src/bip39.js +0 -427
- package/src/bip39.ts +0 -432
- package/src/derive.d.ts +0 -2
- package/src/derive.js +0 -13
- package/src/derive.ts +0 -11
- package/src/index.d.ts +0 -26
- package/src/index.js +0 -128
- package/src/index.test.ts +0 -5
- package/src/index.ts +0 -221
- package/src/javaStreamables.d.ts +0 -233
- package/src/javaStreamables.js +0 -332
- package/src/javaStreamables.ts +0 -403
- package/src/lease/LeaseMonitor.d.ts +0 -44
- package/src/lease/LeaseMonitor.js +0 -111
- package/src/lease/LeaseMonitor.ts +0 -157
- package/src/lease/LeaseStore.d.ts +0 -57
- package/src/lease/LeaseStore.js +0 -148
- package/src/lease/LeaseStore.ts +0 -203
- package/src/lease/WatermarkStore.d.ts +0 -61
- package/src/lease/WatermarkStore.js +0 -206
- package/src/lease/WatermarkStore.ts +0 -270
- package/src/lease/index.d.ts +0 -14
- package/src/lease/index.js +0 -22
- package/src/lease/index.ts +0 -41
- package/src/lease-client.d.ts +0 -31
- package/src/lease-client.js +0 -44
- package/src/lease-client.ts +0 -69
- package/src/minima32.d.ts +0 -10
- package/src/minima32.js +0 -113
- package/src/minima32.test.ts +0 -11
- package/src/minima32.ts +0 -127
- package/src/minimaWireSerializer.d.ts +0 -189
- package/src/minimaWireSerializer.js +0 -311
- package/src/minimaWireSerializer.test.ts +0 -466
- package/src/minimaWireSerializer.ts +0 -117
- package/src/mmr.d.ts +0 -157
- package/src/mmr.js +0 -340
- package/src/mmr.oracle.test.ts +0 -28
- package/src/mmr.ts +0 -429
- package/src/mx.test.ts +0 -25
- package/src/mx.ts +0 -1
- package/src/params.d.ts +0 -29
- package/src/params.d.ts.map +0 -1
- package/src/params.js +0 -20
- package/src/params.js.map +0 -1
- package/src/params.ts +0 -44
- package/src/script.d.ts +0 -7
- package/src/script.js +0 -27
- package/src/script.ts +0 -24
- package/src/scripts/contract-helpers.ts +0 -609
- package/src/scripts/dapp-types.ts +0 -240
- package/src/scripts/index.ts +0 -22
- package/src/scripts/types.d.ts +0 -81
- package/src/scripts/types.js +0 -145
- package/src/scripts/types.ts +0 -247
- package/src/scripts/witness-serializer.ts +0 -384
- package/src/transaction.ts +0 -430
- package/src/treekey.d.ts +0 -383
- package/src/treekey.js +0 -774
- package/src/treekey.parity.test.ts +0 -459
- package/src/treekey.ts +0 -975
- package/src/tx/TransactionLifecycle.d.ts +0 -55
- package/src/tx/TransactionLifecycle.js +0 -188
- package/src/tx/TransactionLifecycle.ts +0 -280
- package/src/tx/TransactionReceiptStore.d.ts +0 -36
- package/src/tx/TransactionReceiptStore.js +0 -89
- package/src/tx/TransactionReceiptStore.ts +0 -112
- package/src/tx/TransactionService.d.ts +0 -31
- package/src/tx/TransactionService.js +0 -140
- package/src/tx/TransactionService.ts +0 -252
- package/src/tx/index.d.ts +0 -13
- package/src/tx/index.js +0 -20
- package/src/tx/index.ts +0 -44
- package/src/tx/types.d.ts +0 -80
- package/src/tx/types.js +0 -6
- package/src/tx/types.ts +0 -130
- package/src/util.d.ts +0 -1
- package/src/util.js +0 -5
- package/src/util.ts +0 -1
- package/src/utils.d.ts +0 -8
- package/src/utils.js +0 -42
- package/src/utils.ts +0 -38
- package/src/verify.ts +0 -210
- package/src/version.ts +0 -13
- package/src/wots.d.ts +0 -224
- package/src/wots.d.ts.map +0 -1
- package/src/wots.js +0 -565
- package/src/wots.js.map +0 -1
- package/src/wots.ts +0 -651
- package/test-vectors.json +0 -45
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Totem SDK Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -83,8 +83,8 @@ const { valid, error } = validateChallenge(challenge, {
|
|
|
83
83
|
|
|
84
84
|
## See also
|
|
85
85
|
|
|
86
|
-
- [`@totemsdk/connect`](
|
|
87
|
-
- [`@totemsdk/node`](
|
|
88
|
-
- [`@totemsdk/wots-lease`](
|
|
89
|
-
- [`@totemsdk/tx-builder`](
|
|
90
|
-
- [`@totemsdk/root-identity`](
|
|
86
|
+
- [`@totemsdk/connect`](https://www.npmjs.com/package/@totemsdk/connect) — dApp gateway built on top of core
|
|
87
|
+
- [`@totemsdk/node`](https://www.npmjs.com/package/@totemsdk/node) — core wired for Node.js server-side use
|
|
88
|
+
- [`@totemsdk/wots-lease`](https://www.npmjs.com/package/@totemsdk/wots-lease) — cloud-coordinated WOTS key safety
|
|
89
|
+
- [`@totemsdk/tx-builder`](https://www.npmjs.com/package/@totemsdk/tx-builder) — full transaction construction
|
|
90
|
+
- [`@totemsdk/root-identity`](https://www.npmjs.com/package/@totemsdk/root-identity) — multi-address identity from one seed
|
package/dist/Streamable.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Streamable.ts - Canonical Java-Compatible Serialization Primitives
|
|
3
4
|
*
|
|
@@ -20,7 +21,29 @@
|
|
|
20
21
|
* Created: 2026-01-20
|
|
21
22
|
* Purpose: Single source of truth for all Minima type serialization
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.encodeMiniString = exports.encodeMiniData = exports.encodeMiniNumber = exports.STATETYPE_BOOL = exports.STATETYPE_STRING = exports.STATETYPE_NUMBER = exports.STATETYPE_HEX = void 0;
|
|
26
|
+
exports.hexToBytes = hexToBytes;
|
|
27
|
+
exports.bytesToHex = bytesToHex;
|
|
28
|
+
exports.concat = concat;
|
|
29
|
+
exports.writeMiniByte = writeMiniByte;
|
|
30
|
+
exports.writeMiniData = writeMiniData;
|
|
31
|
+
exports.writeMiniString = writeMiniString;
|
|
32
|
+
exports.bigIntToByteArray = bigIntToByteArray;
|
|
33
|
+
exports.writeMiniNumber = writeMiniNumber;
|
|
34
|
+
exports.writeHashToStream = writeHashToStream;
|
|
35
|
+
exports.writeMMREntryNumber = writeMMREntryNumber;
|
|
36
|
+
exports.normalizeHexString = normalizeHexString;
|
|
37
|
+
exports.writeStateVariable = writeStateVariable;
|
|
38
|
+
exports.writeMMRData = writeMMRData;
|
|
39
|
+
exports.writeMMRProofChunk = writeMMRProofChunk;
|
|
40
|
+
exports.writeMMRProof = writeMMRProof;
|
|
41
|
+
exports.writeSignatureProof = writeSignatureProof;
|
|
42
|
+
exports.writeSignature = writeSignature;
|
|
43
|
+
exports.writeWitness = writeWitness;
|
|
44
|
+
exports.writeHierarchicalWitness = writeHierarchicalWitness;
|
|
45
|
+
exports.writeHierarchicalWitnessToHex = writeHierarchicalWitnessToHex;
|
|
46
|
+
function hexToBytes(hex) {
|
|
24
47
|
const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
25
48
|
if (cleanHex.length === 0) {
|
|
26
49
|
return new Uint8Array(0);
|
|
@@ -34,10 +57,10 @@ export function hexToBytes(hex) {
|
|
|
34
57
|
}
|
|
35
58
|
return bytes;
|
|
36
59
|
}
|
|
37
|
-
|
|
60
|
+
function bytesToHex(bytes) {
|
|
38
61
|
return '0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
39
62
|
}
|
|
40
|
-
|
|
63
|
+
function concat(...arrays) {
|
|
41
64
|
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
42
65
|
const result = new Uint8Array(totalLength);
|
|
43
66
|
let offset = 0;
|
|
@@ -52,7 +75,7 @@ export function concat(...arrays) {
|
|
|
52
75
|
*
|
|
53
76
|
* Format: single byte (0-255)
|
|
54
77
|
*/
|
|
55
|
-
|
|
78
|
+
function writeMiniByte(value) {
|
|
56
79
|
if (typeof value === 'boolean') {
|
|
57
80
|
return new Uint8Array([value ? 1 : 0]);
|
|
58
81
|
}
|
|
@@ -66,7 +89,7 @@ export function writeMiniByte(value) {
|
|
|
66
89
|
*
|
|
67
90
|
* Format: 4-byte big-endian int length + raw bytes
|
|
68
91
|
*/
|
|
69
|
-
|
|
92
|
+
function writeMiniData(data) {
|
|
70
93
|
const length = data.length;
|
|
71
94
|
const lengthBytes = new Uint8Array([
|
|
72
95
|
(length >> 24) & 0xff,
|
|
@@ -82,7 +105,7 @@ export function writeMiniData(data) {
|
|
|
82
105
|
* Format: MiniData encoding of UTF-8 bytes
|
|
83
106
|
* = 4-byte int length + UTF-8 bytes
|
|
84
107
|
*/
|
|
85
|
-
|
|
108
|
+
function writeMiniString(str) {
|
|
86
109
|
const utf8Bytes = new TextEncoder().encode(str);
|
|
87
110
|
return writeMiniData(utf8Bytes);
|
|
88
111
|
}
|
|
@@ -96,7 +119,7 @@ export function writeMiniString(str) {
|
|
|
96
119
|
* @param value - The BigInt value (must be non-negative)
|
|
97
120
|
* @returns Uint8Array in two's complement format
|
|
98
121
|
*/
|
|
99
|
-
|
|
122
|
+
function bigIntToByteArray(value) {
|
|
100
123
|
if (value < 0n) {
|
|
101
124
|
throw new Error(`bigIntToByteArray does not support negative values: ${value}`);
|
|
102
125
|
}
|
|
@@ -129,7 +152,7 @@ export function bigIntToByteArray(value) {
|
|
|
129
152
|
* @param value - The unscaled BigInt value
|
|
130
153
|
* @param scale - The scale (decimal places), default 0
|
|
131
154
|
*/
|
|
132
|
-
|
|
155
|
+
function writeMiniNumber(value, scale = 0) {
|
|
133
156
|
if (typeof value !== 'bigint') {
|
|
134
157
|
throw new Error(`writeMiniNumber requires bigint, got ${typeof value}`);
|
|
135
158
|
}
|
|
@@ -153,7 +176,7 @@ export function writeMiniNumber(value, scale = 0) {
|
|
|
153
176
|
* Format: 4-byte big-endian int length + hash bytes
|
|
154
177
|
* (Same as MiniData)
|
|
155
178
|
*/
|
|
156
|
-
|
|
179
|
+
function writeHashToStream(hash) {
|
|
157
180
|
return writeMiniData(hash);
|
|
158
181
|
}
|
|
159
182
|
/**
|
|
@@ -171,7 +194,7 @@ export function writeHashToStream(hash) {
|
|
|
171
194
|
* [00 01 00] - MiniNumber: scale=0, len=1, data=0x00
|
|
172
195
|
* [00 00 00 LL ...] - MiniData: 4-byte len + BigInteger bytes
|
|
173
196
|
*/
|
|
174
|
-
|
|
197
|
+
function writeMMREntryNumber(value, scale = 0) {
|
|
175
198
|
if (value < 0n) {
|
|
176
199
|
throw new Error(`writeMMREntryNumber does not support negative values: ${value}`);
|
|
177
200
|
}
|
|
@@ -185,10 +208,10 @@ export function writeMMREntryNumber(value, scale = 0) {
|
|
|
185
208
|
/**
|
|
186
209
|
* StateVariable type constants from Java StateVariable.java
|
|
187
210
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
exports.STATETYPE_HEX = 1;
|
|
212
|
+
exports.STATETYPE_NUMBER = 2;
|
|
213
|
+
exports.STATETYPE_STRING = 4;
|
|
214
|
+
exports.STATETYPE_BOOL = 8;
|
|
192
215
|
/**
|
|
193
216
|
* Normalize hex/address string to 0x format.
|
|
194
217
|
* Handles both Mx (Minima Base32) and 0x formats.
|
|
@@ -197,7 +220,7 @@ export const STATETYPE_BOOL = 8;
|
|
|
197
220
|
* Note: For Mx conversion, caller should use mxToHex from minima-base32
|
|
198
221
|
* This function handles 0x prefix normalization only.
|
|
199
222
|
*/
|
|
200
|
-
|
|
223
|
+
function normalizeHexString(value) {
|
|
201
224
|
if (!value) {
|
|
202
225
|
return '0x00';
|
|
203
226
|
}
|
|
@@ -219,7 +242,7 @@ export function normalizeHexString(value) {
|
|
|
219
242
|
* @param sv - StateVariable with high-level value
|
|
220
243
|
* @param mxToHex - Optional function to convert Mx addresses to 0x hex
|
|
221
244
|
*/
|
|
222
|
-
|
|
245
|
+
function writeStateVariable(sv, mxToHex) {
|
|
223
246
|
if (sv.port < 0 || sv.port > 255) {
|
|
224
247
|
throw new Error(`StateVariable port must be 0-255, got ${sv.port}`);
|
|
225
248
|
}
|
|
@@ -228,7 +251,7 @@ export function writeStateVariable(sv, mxToHex) {
|
|
|
228
251
|
let dataBytes;
|
|
229
252
|
switch (sv.type) {
|
|
230
253
|
case 'bool':
|
|
231
|
-
typeByte = writeMiniByte(STATETYPE_BOOL);
|
|
254
|
+
typeByte = writeMiniByte(exports.STATETYPE_BOOL);
|
|
232
255
|
if (typeof sv.value === 'boolean') {
|
|
233
256
|
dataBytes = writeMiniByte(sv.value);
|
|
234
257
|
}
|
|
@@ -240,7 +263,7 @@ export function writeStateVariable(sv, mxToHex) {
|
|
|
240
263
|
}
|
|
241
264
|
break;
|
|
242
265
|
case 'number':
|
|
243
|
-
typeByte = writeMiniByte(STATETYPE_NUMBER);
|
|
266
|
+
typeByte = writeMiniByte(exports.STATETYPE_NUMBER);
|
|
244
267
|
if (typeof sv.value === 'bigint') {
|
|
245
268
|
dataBytes = writeMiniNumber(sv.value);
|
|
246
269
|
}
|
|
@@ -252,7 +275,7 @@ export function writeStateVariable(sv, mxToHex) {
|
|
|
252
275
|
}
|
|
253
276
|
break;
|
|
254
277
|
case 'hex':
|
|
255
|
-
typeByte = writeMiniByte(STATETYPE_HEX);
|
|
278
|
+
typeByte = writeMiniByte(exports.STATETYPE_HEX);
|
|
256
279
|
if (typeof sv.value === 'string') {
|
|
257
280
|
let normalizedHex = sv.value;
|
|
258
281
|
if (sv.value.toLowerCase().startsWith('mx') && mxToHex) {
|
|
@@ -271,7 +294,7 @@ export function writeStateVariable(sv, mxToHex) {
|
|
|
271
294
|
}
|
|
272
295
|
break;
|
|
273
296
|
case 'string':
|
|
274
|
-
typeByte = writeMiniByte(STATETYPE_STRING);
|
|
297
|
+
typeByte = writeMiniByte(exports.STATETYPE_STRING);
|
|
275
298
|
if (typeof sv.value === 'string') {
|
|
276
299
|
let bracketedValue = sv.value;
|
|
277
300
|
if (!sv.value.startsWith('[') || !sv.value.endsWith(']')) {
|
|
@@ -295,7 +318,7 @@ export function writeStateVariable(sv, mxToHex) {
|
|
|
295
318
|
* mData.writeHashToStream(zOut); // 4-byte len + hash
|
|
296
319
|
* mValue.writeDataStream(zOut); // MiniNumber
|
|
297
320
|
*/
|
|
298
|
-
|
|
321
|
+
function writeMMRData(mmrData) {
|
|
299
322
|
const hashBytes = writeHashToStream(mmrData.data);
|
|
300
323
|
const valueBytes = writeMiniNumber(mmrData.value, 0);
|
|
301
324
|
return concat(hashBytes, valueBytes);
|
|
@@ -307,7 +330,7 @@ export function writeMMRData(mmrData) {
|
|
|
307
330
|
* mLeft.writeDataStream(zOut); // MiniByte (1 byte)
|
|
308
331
|
* mMMRData.writeDataStream(zOut); // MMRData
|
|
309
332
|
*/
|
|
310
|
-
|
|
333
|
+
function writeMMRProofChunk(chunk) {
|
|
311
334
|
const leftByte = writeMiniByte(chunk.isLeft);
|
|
312
335
|
const dataBytes = writeMMRData(chunk.mmrData);
|
|
313
336
|
return concat(leftByte, dataBytes);
|
|
@@ -320,7 +343,7 @@ export function writeMMRProofChunk(chunk) {
|
|
|
320
343
|
* MiniNumber.WriteToStream(zOut, len); // Array length as MiniNumber
|
|
321
344
|
* for each chunk: chunk.writeDataStream(zOut);
|
|
322
345
|
*/
|
|
323
|
-
|
|
346
|
+
function writeMMRProof(proof) {
|
|
324
347
|
const blockTimeBytes = writeMiniNumber(proof.blockTime, 0);
|
|
325
348
|
const lengthBytes = writeMiniNumber(BigInt(proof.chunks.length), 0);
|
|
326
349
|
const parts = [blockTimeBytes, lengthBytes];
|
|
@@ -337,7 +360,7 @@ export function writeMMRProof(proof) {
|
|
|
337
360
|
* mSignature.writeDataStream(zOut); // MiniData
|
|
338
361
|
* mProof.writeDataStream(zOut); // MMRProof
|
|
339
362
|
*/
|
|
340
|
-
|
|
363
|
+
function writeSignatureProof(sigProof) {
|
|
341
364
|
const pubKeyBytes = writeMiniData(sigProof.leafPubkey);
|
|
342
365
|
const sigBytes = writeMiniData(sigProof.signature);
|
|
343
366
|
const proofBytes = writeMMRProof(sigProof.mmrProof);
|
|
@@ -350,7 +373,7 @@ export function writeSignatureProof(sigProof) {
|
|
|
350
373
|
* MiniNumber.WriteToStream(zOut, mSignatures.size());
|
|
351
374
|
* for each sig: sig.writeDataStream(zOut);
|
|
352
375
|
*/
|
|
353
|
-
|
|
376
|
+
function writeSignature(sig) {
|
|
354
377
|
const lengthBytes = writeMiniNumber(BigInt(sig.proofs.length), 0);
|
|
355
378
|
const parts = [lengthBytes];
|
|
356
379
|
for (const proof of sig.proofs) {
|
|
@@ -369,7 +392,7 @@ export function writeSignature(sig) {
|
|
|
369
392
|
* MiniNumber.WriteToStream(zOut, mScriptProofs.size());
|
|
370
393
|
* for each sp: sp.writeDataStream(zOut);
|
|
371
394
|
*/
|
|
372
|
-
|
|
395
|
+
function writeWitness(witness) {
|
|
373
396
|
const parts = [];
|
|
374
397
|
// Signatures
|
|
375
398
|
parts.push(writeMiniNumber(BigInt(witness.signatures.length), 0));
|
|
@@ -392,7 +415,7 @@ export function writeWitness(witness) {
|
|
|
392
415
|
* Write a simplified hierarchical witness (signatures only)
|
|
393
416
|
* Used for WOTS transaction signing flow
|
|
394
417
|
*/
|
|
395
|
-
|
|
418
|
+
function writeHierarchicalWitness(bundle) {
|
|
396
419
|
const lengthBytes = writeMiniNumber(BigInt(bundle.signatures.length), 0);
|
|
397
420
|
const parts = [lengthBytes];
|
|
398
421
|
for (const sig of bundle.signatures) {
|
|
@@ -403,7 +426,7 @@ export function writeHierarchicalWitness(bundle) {
|
|
|
403
426
|
/**
|
|
404
427
|
* Write hierarchical witness and return as hex string
|
|
405
428
|
*/
|
|
406
|
-
|
|
429
|
+
function writeHierarchicalWitnessToHex(bundle) {
|
|
407
430
|
return bytesToHex(writeHierarchicalWitness(bundle));
|
|
408
431
|
}
|
|
409
432
|
// ============================================================
|
|
@@ -411,6 +434,6 @@ export function writeHierarchicalWitnessToHex(bundle) {
|
|
|
411
434
|
// ============================================================
|
|
412
435
|
// The extension's WitnessSerializer uses encode* naming, while SDK uses write* naming.
|
|
413
436
|
// These aliases provide compatibility with extension code.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
437
|
+
exports.encodeMiniNumber = writeMiniNumber;
|
|
438
|
+
exports.encodeMiniData = writeMiniData;
|
|
439
|
+
exports.encodeMiniString = writeMiniString;
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @module @totemsdk/core/adapters
|
|
3
4
|
* Platform-agnostic adapter interfaces for SDK portability
|
|
@@ -9,13 +10,17 @@
|
|
|
9
10
|
*
|
|
10
11
|
* Each platform provides its own implementation of these adapters.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.NoopLifecycleAdapter = exports.DefaultTimerAdapter = exports.NoopMetrics = exports.ConsoleLogger = exports.NoopLogger = exports.WebSocketReadyState = void 0;
|
|
15
|
+
exports.createCancellationToken = createCancellationToken;
|
|
16
|
+
exports.createAdapterRegistry = createAdapterRegistry;
|
|
17
|
+
exports.WebSocketReadyState = {
|
|
13
18
|
CONNECTING: 0,
|
|
14
19
|
OPEN: 1,
|
|
15
20
|
CLOSING: 2,
|
|
16
21
|
CLOSED: 3,
|
|
17
22
|
};
|
|
18
|
-
|
|
23
|
+
function createCancellationToken() {
|
|
19
24
|
let cancelled = false;
|
|
20
25
|
const callbacks = new Set();
|
|
21
26
|
const token = {
|
|
@@ -40,7 +45,7 @@ export function createCancellationToken() {
|
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
|
-
|
|
48
|
+
function createAdapterRegistry(adapters) {
|
|
44
49
|
const required = [
|
|
45
50
|
'storage', 'auth', 'websocket', 'http', 'config', 'logger', 'timer', 'crypto'
|
|
46
51
|
];
|
|
@@ -51,13 +56,14 @@ export function createAdapterRegistry(adapters) {
|
|
|
51
56
|
}
|
|
52
57
|
return adapters;
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
class NoopLogger {
|
|
55
60
|
debug(_message, ..._args) { }
|
|
56
61
|
info(_message, ..._args) { }
|
|
57
62
|
warn(_message, ..._args) { }
|
|
58
63
|
error(_message, ..._args) { }
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
exports.NoopLogger = NoopLogger;
|
|
66
|
+
class ConsoleLogger {
|
|
61
67
|
constructor(prefix = '[SDK]') {
|
|
62
68
|
this.prefix = prefix;
|
|
63
69
|
}
|
|
@@ -74,13 +80,15 @@ export class ConsoleLogger {
|
|
|
74
80
|
console.error(`${this.prefix} ${message}`, ...args);
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
84
|
+
class NoopMetrics {
|
|
78
85
|
increment(_name, _value, _tags) { }
|
|
79
86
|
gauge(_name, _value, _tags) { }
|
|
80
87
|
timing(_name, _durationMs, _tags) { }
|
|
81
88
|
histogram(_name, _value, _tags) { }
|
|
82
89
|
}
|
|
83
|
-
|
|
90
|
+
exports.NoopMetrics = NoopMetrics;
|
|
91
|
+
class DefaultTimerAdapter {
|
|
84
92
|
setTimeout(callback, ms) {
|
|
85
93
|
return setTimeout(callback, ms);
|
|
86
94
|
}
|
|
@@ -97,7 +105,8 @@ export class DefaultTimerAdapter {
|
|
|
97
105
|
return Date.now();
|
|
98
106
|
}
|
|
99
107
|
}
|
|
100
|
-
|
|
108
|
+
exports.DefaultTimerAdapter = DefaultTimerAdapter;
|
|
109
|
+
class NoopLifecycleAdapter {
|
|
101
110
|
onSuspend(_callback) {
|
|
102
111
|
return () => { };
|
|
103
112
|
}
|
|
@@ -105,3 +114,4 @@ export class NoopLifecycleAdapter {
|
|
|
105
114
|
return () => { };
|
|
106
115
|
}
|
|
107
116
|
}
|
|
117
|
+
exports.NoopLifecycleAdapter = NoopLifecycleAdapter;
|
package/dist/adapters/types.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @module @totemsdk/core/adapters/types
|
|
3
4
|
* Shared type definitions for SDK modules
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.QuotaExceededError = exports.TransactionError = exports.LeaseError = exports.AuthenticationError = exports.NetworkError = exports.StorageError = exports.SdkError = void 0;
|
|
8
|
+
exports.createEventEmitter = createEventEmitter;
|
|
9
|
+
class SdkError extends Error {
|
|
6
10
|
constructor(message, code, cause) {
|
|
7
11
|
super(message);
|
|
8
12
|
this.code = code;
|
|
@@ -10,44 +14,51 @@ export class SdkError extends Error {
|
|
|
10
14
|
this.name = 'SdkError';
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
exports.SdkError = SdkError;
|
|
18
|
+
class StorageError extends SdkError {
|
|
14
19
|
constructor(message, cause) {
|
|
15
20
|
super(message, 'STORAGE_ERROR', cause);
|
|
16
21
|
this.name = 'StorageError';
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
|
-
|
|
24
|
+
exports.StorageError = StorageError;
|
|
25
|
+
class NetworkError extends SdkError {
|
|
20
26
|
constructor(message, cause) {
|
|
21
27
|
super(message, 'NETWORK_ERROR', cause);
|
|
22
28
|
this.name = 'NetworkError';
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
exports.NetworkError = NetworkError;
|
|
32
|
+
class AuthenticationError extends SdkError {
|
|
26
33
|
constructor(message, cause) {
|
|
27
34
|
super(message, 'AUTH_ERROR', cause);
|
|
28
35
|
this.name = 'AuthenticationError';
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
|
-
|
|
38
|
+
exports.AuthenticationError = AuthenticationError;
|
|
39
|
+
class LeaseError extends SdkError {
|
|
32
40
|
constructor(message, cause) {
|
|
33
41
|
super(message, 'LEASE_ERROR', cause);
|
|
34
42
|
this.name = 'LeaseError';
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
|
-
|
|
45
|
+
exports.LeaseError = LeaseError;
|
|
46
|
+
class TransactionError extends SdkError {
|
|
38
47
|
constructor(message, cause) {
|
|
39
48
|
super(message, 'TRANSACTION_ERROR', cause);
|
|
40
49
|
this.name = 'TransactionError';
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
|
-
|
|
52
|
+
exports.TransactionError = TransactionError;
|
|
53
|
+
class QuotaExceededError extends SdkError {
|
|
44
54
|
constructor(message, quotaInfo, cause) {
|
|
45
55
|
super(message, 'QUOTA_EXCEEDED', cause);
|
|
46
56
|
this.quotaInfo = quotaInfo;
|
|
47
57
|
this.name = 'QuotaExceededError';
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
|
-
|
|
60
|
+
exports.QuotaExceededError = QuotaExceededError;
|
|
61
|
+
function createEventEmitter() {
|
|
51
62
|
const listeners = new Map();
|
|
52
63
|
return {
|
|
53
64
|
on(event, listener) {
|
package/dist/binio.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
3
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
4
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
6
|
};
|
|
6
7
|
var _BinWriter_buf;
|
|
7
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BinWriter = void 0;
|
|
10
|
+
class BinWriter {
|
|
8
11
|
constructor() {
|
|
9
12
|
_BinWriter_buf.set(this, []);
|
|
10
13
|
}
|
|
@@ -27,4 +30,5 @@ export class BinWriter {
|
|
|
27
30
|
writeBytes(b) { for (const x of b)
|
|
28
31
|
__classPrivateFieldGet(this, _BinWriter_buf, "f").push(x); }
|
|
29
32
|
}
|
|
33
|
+
exports.BinWriter = BinWriter;
|
|
30
34
|
_BinWriter_buf = new WeakMap();
|
package/dist/bip39.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Minima-Compatible BIP39 Seed Phrase Handling
|
|
3
4
|
*
|
|
@@ -11,12 +12,21 @@
|
|
|
11
12
|
* - cleanSeedPhrase(): Normalizes input with prefix matching
|
|
12
13
|
* - convertStringToSeed(): Hashes phrase bytes with SHA3-256
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.WORD_LIST = void 0;
|
|
17
|
+
exports.cleanSeedPhrase = cleanSeedPhrase;
|
|
18
|
+
exports.validatePhrase = validatePhrase;
|
|
19
|
+
exports.convertStringToSeed = convertStringToSeed;
|
|
20
|
+
exports.convertWordListToSeed = convertWordListToSeed;
|
|
21
|
+
exports.phraseToSeed = phraseToSeed;
|
|
22
|
+
exports.generateWordList = generateWordList;
|
|
23
|
+
exports.generateSeedPhrase = generateSeedPhrase;
|
|
24
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
15
25
|
/**
|
|
16
26
|
* Official BIP39 English word list (2048 words)
|
|
17
27
|
* From https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
|
|
18
28
|
*/
|
|
19
|
-
|
|
29
|
+
exports.WORD_LIST = [
|
|
20
30
|
"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract",
|
|
21
31
|
"absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid",
|
|
22
32
|
"acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual",
|
|
@@ -288,7 +298,7 @@ export const WORD_LIST = [
|
|
|
288
298
|
* @returns Canonical uppercase phrase with full words from BIP39 list
|
|
289
299
|
* @throws Error if any word cannot be matched
|
|
290
300
|
*/
|
|
291
|
-
|
|
301
|
+
function cleanSeedPhrase(seedPhrase) {
|
|
292
302
|
const tokens = seedPhrase.trim().split(/\s+/);
|
|
293
303
|
const matchedWords = [];
|
|
294
304
|
for (const rawToken of tokens) {
|
|
@@ -298,7 +308,7 @@ export function cleanSeedPhrase(seedPhrase) {
|
|
|
298
308
|
}
|
|
299
309
|
let found = false;
|
|
300
310
|
if (token.length < 4) {
|
|
301
|
-
for (const word of WORD_LIST) {
|
|
311
|
+
for (const word of exports.WORD_LIST) {
|
|
302
312
|
if (token === word) {
|
|
303
313
|
matchedWords.push(word);
|
|
304
314
|
found = true;
|
|
@@ -307,7 +317,7 @@ export function cleanSeedPhrase(seedPhrase) {
|
|
|
307
317
|
}
|
|
308
318
|
}
|
|
309
319
|
else {
|
|
310
|
-
for (const word of WORD_LIST) {
|
|
320
|
+
for (const word of exports.WORD_LIST) {
|
|
311
321
|
if (word.startsWith(token)) {
|
|
312
322
|
matchedWords.push(word);
|
|
313
323
|
found = true;
|
|
@@ -328,7 +338,7 @@ export function cleanSeedPhrase(seedPhrase) {
|
|
|
328
338
|
* @param phrase - Space-separated words (any case)
|
|
329
339
|
* @returns true if all words are valid BIP39 words
|
|
330
340
|
*/
|
|
331
|
-
|
|
341
|
+
function validatePhrase(phrase) {
|
|
332
342
|
try {
|
|
333
343
|
cleanSeedPhrase(phrase);
|
|
334
344
|
return true;
|
|
@@ -351,10 +361,10 @@ export function validatePhrase(phrase) {
|
|
|
351
361
|
* @param phrase - Canonical phrase (should be cleaned first with cleanSeedPhrase)
|
|
352
362
|
* @returns 32-byte SHA3-256 seed
|
|
353
363
|
*/
|
|
354
|
-
|
|
364
|
+
function convertStringToSeed(phrase) {
|
|
355
365
|
const encoder = new TextEncoder();
|
|
356
366
|
const phraseBytes = encoder.encode(phrase);
|
|
357
|
-
return sha3_256(phraseBytes);
|
|
367
|
+
return (0, sha3_js_1.sha3_256)(phraseBytes);
|
|
358
368
|
}
|
|
359
369
|
/**
|
|
360
370
|
* Convert word array to seed matching Minima's BIP39.convertWordListToSeed()
|
|
@@ -367,7 +377,7 @@ export function convertStringToSeed(phrase) {
|
|
|
367
377
|
* @param words - Array of BIP39 words
|
|
368
378
|
* @returns 32-byte SHA3-256 seed
|
|
369
379
|
*/
|
|
370
|
-
|
|
380
|
+
function convertWordListToSeed(words) {
|
|
371
381
|
const phrase = words.join(' ').trim();
|
|
372
382
|
return convertStringToSeed(phrase);
|
|
373
383
|
}
|
|
@@ -381,7 +391,7 @@ export function convertWordListToSeed(words) {
|
|
|
381
391
|
* @returns 32-byte seed for TreeKey
|
|
382
392
|
* @throws Error if phrase contains invalid words
|
|
383
393
|
*/
|
|
384
|
-
|
|
394
|
+
function phraseToSeed(rawPhrase) {
|
|
385
395
|
const canonical = cleanSeedPhrase(rawPhrase);
|
|
386
396
|
return convertStringToSeed(canonical);
|
|
387
397
|
}
|
|
@@ -391,7 +401,7 @@ export function phraseToSeed(rawPhrase) {
|
|
|
391
401
|
*
|
|
392
402
|
* @returns Array of 24 random BIP39 words (lowercase)
|
|
393
403
|
*/
|
|
394
|
-
|
|
404
|
+
function generateWordList() {
|
|
395
405
|
const words = [];
|
|
396
406
|
const randomValues = new Uint32Array(24);
|
|
397
407
|
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
@@ -403,8 +413,8 @@ export function generateWordList() {
|
|
|
403
413
|
}
|
|
404
414
|
}
|
|
405
415
|
for (let i = 0; i < 24; i++) {
|
|
406
|
-
const index = randomValues[i] % WORD_LIST.length;
|
|
407
|
-
words.push(WORD_LIST[index]);
|
|
416
|
+
const index = randomValues[i] % exports.WORD_LIST.length;
|
|
417
|
+
words.push(exports.WORD_LIST[index]);
|
|
408
418
|
}
|
|
409
419
|
return words;
|
|
410
420
|
}
|
|
@@ -412,6 +422,6 @@ export function generateWordList() {
|
|
|
412
422
|
* Generate a new random seed phrase as a string
|
|
413
423
|
* @returns 24-word phrase in UPPERCASE (canonical form)
|
|
414
424
|
*/
|
|
415
|
-
|
|
425
|
+
function generateSeedPhrase() {
|
|
416
426
|
return generateWordList().join(' ').toUpperCase();
|
|
417
427
|
}
|
package/dist/derive.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scriptToAddress = scriptToAddress;
|
|
4
|
+
exports.addressToRoot = addressToRoot;
|
|
5
|
+
const mmr_js_1 = require("./mmr.js");
|
|
6
|
+
const minima32_js_1 = require("./minima32.js");
|
|
7
|
+
function scriptToAddress(script) {
|
|
8
|
+
const root32 = (0, mmr_js_1.mmrRootFromSingleLeaf)(script);
|
|
9
|
+
return (0, minima32_js_1.makeMxAddress)(root32);
|
|
6
10
|
}
|
|
7
|
-
|
|
8
|
-
return parseMxAddress(mx);
|
|
11
|
+
function addressToRoot(mx) {
|
|
12
|
+
return (0, minima32_js_1.parseMxAddress)(mx);
|
|
9
13
|
}
|