@totemsdk/core 1.0.0

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 (175) hide show
  1. package/dist/Streamable.d.ts +268 -0
  2. package/dist/Streamable.js +416 -0
  3. package/dist/adapters/index.d.ts +190 -0
  4. package/dist/adapters/index.js +107 -0
  5. package/dist/adapters/types.d.ts +149 -0
  6. package/dist/adapters/types.js +67 -0
  7. package/dist/binio.d.ts +9 -0
  8. package/dist/binio.js +30 -0
  9. package/dist/bip39.d.ts +91 -0
  10. package/dist/bip39.js +417 -0
  11. package/dist/derive.d.ts +2 -0
  12. package/dist/derive.js +9 -0
  13. package/dist/index.d.ts +30 -0
  14. package/dist/index.js +53 -0
  15. package/dist/javaStreamables.d.ts +233 -0
  16. package/dist/javaStreamables.js +332 -0
  17. package/dist/lease/LeaseMonitor.d.ts +44 -0
  18. package/dist/lease/LeaseMonitor.js +107 -0
  19. package/dist/lease/LeaseStore.d.ts +57 -0
  20. package/dist/lease/LeaseStore.js +144 -0
  21. package/dist/lease/WatermarkStore.d.ts +61 -0
  22. package/dist/lease/WatermarkStore.js +202 -0
  23. package/dist/lease/index.d.ts +14 -0
  24. package/dist/lease/index.js +13 -0
  25. package/dist/lease-client.d.ts +31 -0
  26. package/dist/lease-client.js +39 -0
  27. package/dist/minima32.d.ts +18 -0
  28. package/dist/minima32.js +112 -0
  29. package/dist/minimaWireSerializer.d.ts +60 -0
  30. package/dist/minimaWireSerializer.js +71 -0
  31. package/dist/mmr.d.ts +156 -0
  32. package/dist/mmr.js +342 -0
  33. package/dist/mx.d.ts +1 -0
  34. package/dist/mx.js +1 -0
  35. package/dist/params.d.ts +29 -0
  36. package/dist/params.js +16 -0
  37. package/dist/script.d.ts +7 -0
  38. package/dist/script.js +22 -0
  39. package/dist/scripts/contract-helpers.d.ts +252 -0
  40. package/dist/scripts/contract-helpers.js +394 -0
  41. package/dist/scripts/dapp-types.d.ts +119 -0
  42. package/dist/scripts/dapp-types.js +72 -0
  43. package/dist/scripts/index.d.ts +4 -0
  44. package/dist/scripts/index.js +4 -0
  45. package/dist/scripts/types.d.ts +81 -0
  46. package/dist/scripts/types.js +145 -0
  47. package/dist/scripts/witness-serializer.d.ts +29 -0
  48. package/dist/scripts/witness-serializer.js +288 -0
  49. package/dist/transaction.d.ts +106 -0
  50. package/dist/transaction.js +284 -0
  51. package/dist/treekey.d.ts +383 -0
  52. package/dist/treekey.js +762 -0
  53. package/dist/tx/TransactionLifecycle.d.ts +55 -0
  54. package/dist/tx/TransactionLifecycle.js +189 -0
  55. package/dist/tx/TransactionReceiptStore.d.ts +36 -0
  56. package/dist/tx/TransactionReceiptStore.js +85 -0
  57. package/dist/tx/TransactionService.d.ts +50 -0
  58. package/dist/tx/TransactionService.js +178 -0
  59. package/dist/tx/index.d.ts +13 -0
  60. package/dist/tx/index.js +12 -0
  61. package/dist/tx/types.d.ts +114 -0
  62. package/dist/tx/types.js +5 -0
  63. package/dist/util.d.ts +1 -0
  64. package/dist/util.js +1 -0
  65. package/dist/utils.d.ts +8 -0
  66. package/dist/utils.js +35 -0
  67. package/dist/verify.d.ts +18 -0
  68. package/dist/verify.js +162 -0
  69. package/dist/version.d.ts +12 -0
  70. package/dist/version.js +12 -0
  71. package/dist/wots.d.ts +232 -0
  72. package/dist/wots.js +538 -0
  73. package/package.json +65 -0
  74. package/src/Streamable.d.ts +265 -0
  75. package/src/Streamable.js +431 -0
  76. package/src/Streamable.ts +567 -0
  77. package/src/__tests__/Streamable.parity.test.ts +422 -0
  78. package/src/__tests__/perAddressDerivation.parity.test.ts +152 -0
  79. package/src/__tests__/wots-parity.test.ts +289 -0
  80. package/src/adapters/index.d.ts +190 -0
  81. package/src/adapters/index.js +117 -0
  82. package/src/adapters/index.ts +301 -0
  83. package/src/adapters/types.ts +235 -0
  84. package/src/addr.oracle.test.ts +25 -0
  85. package/src/address.test.ts +55 -0
  86. package/src/binio.ts +21 -0
  87. package/src/bip39.d.ts +91 -0
  88. package/src/bip39.js +427 -0
  89. package/src/bip39.ts +432 -0
  90. package/src/derive.d.ts +2 -0
  91. package/src/derive.js +13 -0
  92. package/src/derive.ts +11 -0
  93. package/src/index.d.ts +26 -0
  94. package/src/index.js +128 -0
  95. package/src/index.test.ts +5 -0
  96. package/src/index.ts +206 -0
  97. package/src/javaStreamables.d.ts +233 -0
  98. package/src/javaStreamables.js +328 -0
  99. package/src/javaStreamables.ts +403 -0
  100. package/src/lease/LeaseMonitor.d.ts +44 -0
  101. package/src/lease/LeaseMonitor.js +111 -0
  102. package/src/lease/LeaseMonitor.ts +157 -0
  103. package/src/lease/LeaseStore.d.ts +57 -0
  104. package/src/lease/LeaseStore.js +148 -0
  105. package/src/lease/LeaseStore.ts +203 -0
  106. package/src/lease/WatermarkStore.d.ts +61 -0
  107. package/src/lease/WatermarkStore.js +206 -0
  108. package/src/lease/WatermarkStore.ts +270 -0
  109. package/src/lease/index.d.ts +14 -0
  110. package/src/lease/index.js +22 -0
  111. package/src/lease/index.ts +41 -0
  112. package/src/lease-client.d.ts +31 -0
  113. package/src/lease-client.js +44 -0
  114. package/src/lease-client.ts +69 -0
  115. package/src/minima32.d.ts +10 -0
  116. package/src/minima32.js +113 -0
  117. package/src/minima32.test.ts +11 -0
  118. package/src/minima32.ts +127 -0
  119. package/src/minimaWireSerializer.d.ts +189 -0
  120. package/src/minimaWireSerializer.js +311 -0
  121. package/src/minimaWireSerializer.test.ts +466 -0
  122. package/src/minimaWireSerializer.ts +117 -0
  123. package/src/mmr.d.ts +153 -0
  124. package/src/mmr.js +351 -0
  125. package/src/mmr.oracle.test.ts +28 -0
  126. package/src/mmr.ts +429 -0
  127. package/src/mx.test.ts +25 -0
  128. package/src/mx.ts +1 -0
  129. package/src/params.d.ts +29 -0
  130. package/src/params.d.ts.map +1 -0
  131. package/src/params.js +20 -0
  132. package/src/params.js.map +1 -0
  133. package/src/params.ts +44 -0
  134. package/src/script.d.ts +7 -0
  135. package/src/script.js +27 -0
  136. package/src/script.ts +24 -0
  137. package/src/scripts/contract-helpers.ts +609 -0
  138. package/src/scripts/dapp-types.ts +240 -0
  139. package/src/scripts/index.ts +22 -0
  140. package/src/scripts/types.ts +247 -0
  141. package/src/scripts/witness-serializer.ts +384 -0
  142. package/src/transaction.ts +430 -0
  143. package/src/treekey.d.ts +383 -0
  144. package/src/treekey.js +778 -0
  145. package/src/treekey.parity.test.ts +459 -0
  146. package/src/treekey.ts +979 -0
  147. package/src/tx/TransactionLifecycle.d.ts +55 -0
  148. package/src/tx/TransactionLifecycle.js +188 -0
  149. package/src/tx/TransactionLifecycle.ts +280 -0
  150. package/src/tx/TransactionReceiptStore.d.ts +36 -0
  151. package/src/tx/TransactionReceiptStore.js +89 -0
  152. package/src/tx/TransactionReceiptStore.ts +112 -0
  153. package/src/tx/TransactionService.d.ts +31 -0
  154. package/src/tx/TransactionService.js +140 -0
  155. package/src/tx/TransactionService.ts +250 -0
  156. package/src/tx/index.d.ts +13 -0
  157. package/src/tx/index.js +20 -0
  158. package/src/tx/index.ts +44 -0
  159. package/src/tx/types.d.ts +80 -0
  160. package/src/tx/types.js +6 -0
  161. package/src/tx/types.ts +127 -0
  162. package/src/util.d.ts +1 -0
  163. package/src/util.js +5 -0
  164. package/src/util.ts +1 -0
  165. package/src/utils.d.ts +8 -0
  166. package/src/utils.js +42 -0
  167. package/src/utils.ts +38 -0
  168. package/src/verify.ts +209 -0
  169. package/src/version.ts +13 -0
  170. package/src/wots.d.ts +224 -0
  171. package/src/wots.d.ts.map +1 -0
  172. package/src/wots.js +559 -0
  173. package/src/wots.js.map +1 -0
  174. package/src/wots.ts +636 -0
  175. package/test-vectors.json +45 -0
@@ -0,0 +1,112 @@
1
+ // Minima "Mx" Base32 — matches org.minima.utils.BaseConverter.encode32/decode32
2
+ // Source behavior: BigInteger radix-32, then i→w, l→y, o→z, uppercased, prefixed with "Mx".
3
+ function bytesToBigInt(bytes) {
4
+ let x = 0n;
5
+ for (const b of bytes)
6
+ x = (x << 8n) | BigInt(b);
7
+ return x;
8
+ }
9
+ function bigIntToBytes(x) {
10
+ if (x === 0n)
11
+ return new Uint8Array([0]); // not normally hit for framed addresses
12
+ let hex = x.toString(16);
13
+ if (hex.length % 2)
14
+ hex = '0' + hex;
15
+ const out = new Uint8Array(hex.length / 2);
16
+ for (let i = 0; i < out.length; i++) {
17
+ out[i] = parseInt(hex.slice(2 * i, 2 * i + 2), 16);
18
+ }
19
+ return out;
20
+ }
21
+ export function encodeMxRadix32Frame(frame) {
22
+ let s = bytesToBigInt(frame).toString(32).toLowerCase();
23
+ // JAR swaps (avoid ambiguous letters) then uppercase and add prefix
24
+ s = s.replace(/i/g, 'w').replace(/l/g, 'y').replace(/o/g, 'z');
25
+ return 'Mx' + s.toUpperCase();
26
+ }
27
+ export function decodeMxRadix32Frame(mx) {
28
+ let s = mx.trim().toLowerCase();
29
+ if (s.startsWith('mx'))
30
+ s = s.slice(2);
31
+ s = s.replace(/w/g, 'i').replace(/y/g, 'l').replace(/z/g, 'o'); // reverse swaps
32
+ // parse base-32 by hand (radix 32)
33
+ let x = 0n;
34
+ for (const ch of s) {
35
+ const v = parseInt(ch, 32);
36
+ if (Number.isNaN(v))
37
+ throw new Error(`Invalid base32 character: ${ch}`);
38
+ x = x * 32n + BigInt(v);
39
+ }
40
+ return bigIntToBytes(x);
41
+ }
42
+ import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3';
43
+ /** Encode raw 32 bytes to Mx address with frame and checksum */
44
+ export function makeMxAddress(root32) {
45
+ if (root32.length !== 32) {
46
+ throw new Error(`Expected 32 bytes, got ${root32.length}`);
47
+ }
48
+ // Build frame: [sentinel(1), length(2), data(32), checksum(4)]
49
+ const frame = new Uint8Array(1 + 2 + 32 + 4);
50
+ frame[0] = 0x01; // Sentinel byte
51
+ frame[1] = 0; // Length high byte
52
+ frame[2] = 32; // Length low byte
53
+ frame.set(root32, 3);
54
+ // Calculate checksum of the raw 32 bytes
55
+ const chk = nobleSha3(root32);
56
+ frame.set(chk.slice(0, 4), 35);
57
+ return encodeMxRadix32Frame(frame);
58
+ }
59
+ /** Decode Mx address to raw 32 bytes, validating frame and checksum */
60
+ export function parseMxAddress(mx) {
61
+ const frame = decodeMxRadix32Frame(mx);
62
+ // Validate frame structure
63
+ if (frame[0] !== 0x01) {
64
+ throw new Error(`Invalid sentinel byte: ${frame[0]}`);
65
+ }
66
+ const len = (frame[1] << 8) | frame[2];
67
+ if (len !== 32) {
68
+ throw new Error(`Invalid length: ${len}, expected 32`);
69
+ }
70
+ const root32 = frame.slice(3, 35);
71
+ const checksum = frame.slice(35, 39);
72
+ // Validate checksum
73
+ const expectedChk = nobleSha3(root32);
74
+ const expected = expectedChk.slice(0, 4);
75
+ for (let i = 0; i < 4; i++) {
76
+ if (checksum[i] !== expected[i]) {
77
+ throw new Error('Invalid checksum');
78
+ }
79
+ }
80
+ return root32;
81
+ }
82
+ // Aliases for backward compatibility
83
+ function hexToBytes(hex) {
84
+ let h = hex.startsWith("0x") ? hex.slice(2) : hex;
85
+ if (h.length % 2)
86
+ h = "0" + h;
87
+ const out = new Uint8Array(h.length / 2);
88
+ for (let i = 0; i < out.length; i++)
89
+ out[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
90
+ return out;
91
+ }
92
+ function bytesToHex(bytes) {
93
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase();
94
+ }
95
+ /** Make an Mx address from a hex string (legacy API compatibility) */
96
+ export function hexToMx(hex) {
97
+ const bytes = hexToBytes(hex);
98
+ return makeMxAddress(bytes);
99
+ }
100
+ /** Convert an Mx address back to uppercase hex (legacy API compatibility) */
101
+ export function mxToHex(mx) {
102
+ const bytes = parseMxAddress(mx);
103
+ return bytesToHex(bytes);
104
+ }
105
+ /** @deprecated Use makeMxAddress */
106
+ export const encodeMx = makeMxAddress;
107
+ /** @deprecated Use parseMxAddress */
108
+ export const decodeMx = parseMxAddress;
109
+ /** @deprecated Use hexToMx */
110
+ export const makeMinimaAddress = hexToMx;
111
+ /** @deprecated Use mxToHex */
112
+ export const convertMinimaAddress = mxToHex;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Minima Wire Format Serializer
3
+ *
4
+ * High-level serialization for hex-string bundles (used in service.ts).
5
+ * Primitive serialization functions are imported from Streamable.ts.
6
+ *
7
+ * @deprecated (2026-01) - Most functions deprecated. Use Streamable.ts directly for
8
+ * byte-level serialization. This file remains for HierarchicalWitnessBundle hex APIs.
9
+ */
10
+ import { hexToBytes, bytesToHex, writeMiniNumber, writeMiniData, type Bytes } from './Streamable.js';
11
+ export { writeMiniNumber as serializeMiniNumber, writeMiniData as serializeMiniData };
12
+ export { hexToBytes as fromHex, bytesToHex as toHex };
13
+ export type { Bytes };
14
+ /**
15
+ * SignatureProof with hex strings (for bundle transport)
16
+ */
17
+ export interface SignatureProofHex {
18
+ leafPubkey: string;
19
+ signature: string;
20
+ mmrProof: string;
21
+ }
22
+ /**
23
+ * HierarchicalWitnessBundle - used by service.ts for transaction signing
24
+ * All fields are hex strings for JSON transport
25
+ */
26
+ export interface HierarchicalWitnessBundle {
27
+ addressIndex: number;
28
+ l1: number;
29
+ l2: number;
30
+ rootPublicKey: string;
31
+ proofs: SignatureProofHex[];
32
+ }
33
+ /**
34
+ * Serialize hierarchical witness bundle to Minima wire format
35
+ *
36
+ * This converts the HierarchicalWitnessBundle (with hex strings) to
37
+ * the proper Witness signature format matching Witness.java → Signature.java hierarchy.
38
+ *
39
+ * CRITICAL FIX (2026-01): Must use double-nesting to match Java format:
40
+ * - Witness.writeDataStream writes: [signatureCount][Signature[0].writeDataStream()]...
41
+ * - Signature.writeDataStream writes: [proofCount][SignatureProof[0]]...
42
+ *
43
+ * So the final format is:
44
+ * [1] = signatureCount (we have 1 Signature object in Witness)
45
+ * [N] = proofCount inside that Signature (2 for address-based TreeKey)
46
+ * [SignatureProof[0]]
47
+ * [SignatureProof[1]]
48
+ *
49
+ * IMPORTANT: Uses pre-serialized MMR proof bytes directly to avoid
50
+ * double-serialization (deserialize then re-serialize).
51
+ */
52
+ export declare function serializeHierarchicalWitness(bundle: HierarchicalWitnessBundle): Bytes;
53
+ /**
54
+ * @deprecated (2026-01) This function's output is NOT used in the main Totem transaction flow.
55
+ * MinimaTransactionBuilder.serializeWitness in the extension handles actual witness serialization.
56
+ * Kept for API compatibility and potential future direct SDK usage.
57
+ *
58
+ * Serialize hierarchical witness bundle to hex string for transport
59
+ */
60
+ export declare function serializeHierarchicalWitnessToHex(bundle: HierarchicalWitnessBundle): string;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Minima Wire Format Serializer
3
+ *
4
+ * High-level serialization for hex-string bundles (used in service.ts).
5
+ * Primitive serialization functions are imported from Streamable.ts.
6
+ *
7
+ * @deprecated (2026-01) - Most functions deprecated. Use Streamable.ts directly for
8
+ * byte-level serialization. This file remains for HierarchicalWitnessBundle hex APIs.
9
+ */
10
+ import { concat, hexToBytes, bytesToHex, writeMiniNumber, writeMiniData, } from './Streamable.js';
11
+ // Re-export primitives for backward compatibility
12
+ export { writeMiniNumber as serializeMiniNumber, writeMiniData as serializeMiniData };
13
+ export { hexToBytes as fromHex, bytesToHex as toHex };
14
+ /**
15
+ * Serialize a SignatureProof from pre-serialized byte arrays
16
+ *
17
+ * This avoids double-serialization by passing MMR proof bytes through directly.
18
+ * Format matches SignatureProof.writeDataStream():
19
+ * 1. MiniData (publicKey) - 4-byte length + bytes
20
+ * 2. MiniData (signature) - 4-byte length + bytes
21
+ * 3. MMRProof bytes (pre-serialized)
22
+ */
23
+ function serializeSignatureProofFromBytes(publicKey, signature, mmrProofBytes) {
24
+ return concat(writeMiniData(publicKey), writeMiniData(signature), mmrProofBytes // Already serialized - pass through directly
25
+ );
26
+ }
27
+ /**
28
+ * Serialize hierarchical witness bundle to Minima wire format
29
+ *
30
+ * This converts the HierarchicalWitnessBundle (with hex strings) to
31
+ * the proper Witness signature format matching Witness.java → Signature.java hierarchy.
32
+ *
33
+ * CRITICAL FIX (2026-01): Must use double-nesting to match Java format:
34
+ * - Witness.writeDataStream writes: [signatureCount][Signature[0].writeDataStream()]...
35
+ * - Signature.writeDataStream writes: [proofCount][SignatureProof[0]]...
36
+ *
37
+ * So the final format is:
38
+ * [1] = signatureCount (we have 1 Signature object in Witness)
39
+ * [N] = proofCount inside that Signature (2 for address-based TreeKey)
40
+ * [SignatureProof[0]]
41
+ * [SignatureProof[1]]
42
+ *
43
+ * IMPORTANT: Uses pre-serialized MMR proof bytes directly to avoid
44
+ * double-serialization (deserialize then re-serialize).
45
+ */
46
+ export function serializeHierarchicalWitness(bundle) {
47
+ const parts = [];
48
+ // Witness.signatureCount (MiniNumber) - 1 Signature object containing N proofs
49
+ parts.push(writeMiniNumber(1n));
50
+ // Signature.proofCount (MiniNumber) - N SignatureProofs inside the Signature
51
+ parts.push(writeMiniNumber(BigInt(bundle.proofs.length)));
52
+ for (const proofHex of bundle.proofs) {
53
+ const publicKey = hexToBytes(proofHex.leafPubkey);
54
+ const signature = hexToBytes(proofHex.signature);
55
+ const mmrProofBytes = hexToBytes(proofHex.mmrProof); // Already serialized
56
+ // Serialize SignatureProof with pre-serialized MMR bytes
57
+ parts.push(serializeSignatureProofFromBytes(publicKey, signature, mmrProofBytes));
58
+ }
59
+ return concat(...parts);
60
+ }
61
+ /**
62
+ * @deprecated (2026-01) This function's output is NOT used in the main Totem transaction flow.
63
+ * MinimaTransactionBuilder.serializeWitness in the extension handles actual witness serialization.
64
+ * Kept for API compatibility and potential future direct SDK usage.
65
+ *
66
+ * Serialize hierarchical witness bundle to hex string for transport
67
+ */
68
+ export function serializeHierarchicalWitnessToHex(bundle) {
69
+ const bytes = serializeHierarchicalWitness(bundle);
70
+ return bytesToHex(bytes);
71
+ }
package/dist/mmr.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ export declare function serializeMMRProof(proof: {
2
+ chunks: Array<{
3
+ isLeft: boolean;
4
+ mmrData: {
5
+ data: Bytes;
6
+ value: bigint;
7
+ };
8
+ }>;
9
+ }, blockTime?: bigint): Bytes;
10
+ export declare const serializeRealMMRProof: typeof serializeMMRProof;
11
+ export type Bytes = Uint8Array;
12
+ /**
13
+ * Byte-exact one-leaf MMR leaf used by Minima Address.java path:
14
+ * sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
15
+ */
16
+ export declare function mmrLeafExact(script: string): Bytes;
17
+ /** In a single-leaf MMR the root equals the leaf commitment. */
18
+ export declare function mmrRootFromSingleLeaf(script: string): Bytes;
19
+ /**
20
+ * MMRData structure matching Minima's MMRData.java
21
+ * Contains hash and value (for sum tree functionality)
22
+ */
23
+ export interface MMRData {
24
+ data: Bytes;
25
+ value: bigint;
26
+ }
27
+ /**
28
+ * MMREntry structure matching Minima's MMREntry.java
29
+ * Represents a node in the MMR at a specific row and position
30
+ */
31
+ export interface MMREntry {
32
+ row: number;
33
+ entryNumber: bigint;
34
+ mmrData: MMRData;
35
+ }
36
+ /**
37
+ * MMRProofChunk - one step in the proof path
38
+ * Matches Minima's MMRProof structure
39
+ */
40
+ export interface MMRProofChunk {
41
+ isLeft: boolean;
42
+ mmrData: MMRData;
43
+ }
44
+ /**
45
+ * MMRProof structure matching Minima's MMRProof.java
46
+ * Contains proof chunks to verify leaf membership in the tree
47
+ */
48
+ export interface MMRProof {
49
+ chunks: MMRProofChunk[];
50
+ }
51
+ /**
52
+ * Create MMRData leaf node matching Minima's MMRData.CreateMMRDataLeafNode
53
+ *
54
+ * From MMRData.java:
55
+ * MiniData hash = Crypto.getInstance().hashAllObjects(MiniNumber.ZERO, zData, zSumValue);
56
+ *
57
+ * CRITICAL: Crypto.hashAllObjects uses writeDataStream for Streamables:
58
+ * - MiniNumber: scale + len + data (see serializeMiniNumber)
59
+ * - MiniData: 4-byte length + data (see serializeMiniData)
60
+ *
61
+ * For TreeKeyNode, zData is the Winternitz public key (MiniData) and zSumValue is ZERO
62
+ *
63
+ * Serialization order:
64
+ * 1. MiniNumber.ZERO: [0x00, 0x01, 0x00]
65
+ * 2. MiniData (pubkey): [4-byte length] + [bytes] (writeDataStream, NOT writeHashToStream)
66
+ * 3. MiniNumber.ZERO: [0x00, 0x01, 0x00]
67
+ */
68
+ export declare function createMMRDataLeafNode(pubkey: Bytes, sumValue?: bigint): MMRData;
69
+ /**
70
+ * Create MMRData parent node matching Minima's MMRData.CreateMMRDataParentNode
71
+ *
72
+ * From MMRData.java:
73
+ * MiniNumber sumvalue = zLeft.getValue().add(zRight.getValue());
74
+ * MiniData combinedhash = Crypto.getInstance().hashAllObjects(
75
+ * MiniNumber.ONE, zLeft.getData(), zRight.getData(), sumvalue);
76
+ *
77
+ * CRITICAL: The getData() returns MiniData (the hash), which is serialized
78
+ * with writeDataStream (4-byte length) in hashAllObjects.
79
+ *
80
+ * Serialization order:
81
+ * 1. MiniNumber.ONE: [0x00, 0x01, 0x01]
82
+ * 2. MiniData (left.data): [4-byte length] + [bytes]
83
+ * 3. MiniData (right.data): [4-byte length] + [bytes]
84
+ * 4. MiniNumber (sumvalue): serialized MiniNumber
85
+ */
86
+ export declare function createMMRDataParentNode(left: MMRData, right: MMRData): MMRData;
87
+ /**
88
+ * Simple MMR Tree for TreeKeyNode
89
+ * Builds a perfect binary tree from N entries (N must be power of 2 for simplicity)
90
+ *
91
+ * This matches TreeKeyNode.java which always uses 64 leaves (2^6)
92
+ */
93
+ export declare class MMRTree {
94
+ private entries;
95
+ private leafCount;
96
+ private maxRow;
97
+ private getKey;
98
+ private setEntry;
99
+ private getEntry;
100
+ /**
101
+ * Add a leaf entry to the MMR
102
+ * Matches MMR.java addEntry() but simplified for power-of-2 trees
103
+ */
104
+ addLeaf(data: MMRData): MMREntry;
105
+ /**
106
+ * Build tree from array of Winternitz public keys
107
+ * Used by TreeKeyNode to compute wallet public key
108
+ */
109
+ static fromPublicKeys(pubkeys: Bytes[]): MMRTree;
110
+ /**
111
+ * Get the root of the tree
112
+ * For a perfect binary tree with N leaves, root is at row log2(N), entry 0
113
+ */
114
+ getRoot(): MMRData | null;
115
+ /**
116
+ * Get proof for a leaf at given index
117
+ * Matches MMR.java getProofToPeak()
118
+ */
119
+ getProof(leafIndex: number): MMRProof;
120
+ /**
121
+ * Get the leaf MMRData at a specific index
122
+ */
123
+ getLeaf(index: number): MMRData | null;
124
+ }
125
+ /**
126
+ * Calculate root from leaf data and proof
127
+ * Matches SignatureProof.getRootPublicKey() in Java
128
+ *
129
+ * From SignatureProof.java:
130
+ * MMRData pubentry = MMRData.CreateMMRDataLeafNode(mPublicKey, MiniNumber.ZERO);
131
+ * return mProof.calculateProof(pubentry).getData();
132
+ */
133
+ export declare function calculateProofRoot(leafData: MMRData, proof: MMRProof): Bytes;
134
+ /**
135
+ * Verify a proof: check that leaf + proof computes to expected root
136
+ */
137
+ export declare function verifyMMRProof(leafPubkey: Bytes, proof: MMRProof, expectedRoot: Bytes): boolean;
138
+ /**
139
+ * Deserialize MMRProof from bytes matching Minima's MMRProof.readDataStream()
140
+ *
141
+ * Format:
142
+ * 1. blockTime (MiniNumber)
143
+ * 2. chain length (MiniNumber)
144
+ * 3. Each chunk: isLeft (1 byte) + MMRData (hash with 4-byte length prefix + value MiniNumber)
145
+ *
146
+ * CRITICAL: Java MMRData.readDataStream uses mData.readHashFromStream() which reads
147
+ * a 4-byte big-endian length prefix followed by the hash bytes.
148
+ *
149
+ * @returns { proof: MMRProof, blockTime: bigint }
150
+ */
151
+ export declare function parseMMRProofFromHex(data: Bytes): {
152
+ proof: MMRProof;
153
+ blockTime: bigint;
154
+ };
155
+ /** @deprecated Use parseMMRProofFromHex */
156
+ export declare const deserializeMMRProof: typeof parseMMRProofFromHex;