@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.
- package/dist/Streamable.d.ts +268 -0
- package/dist/Streamable.js +416 -0
- package/dist/adapters/index.d.ts +190 -0
- package/dist/adapters/index.js +107 -0
- package/dist/adapters/types.d.ts +149 -0
- package/dist/adapters/types.js +67 -0
- package/dist/binio.d.ts +9 -0
- package/dist/binio.js +30 -0
- package/dist/bip39.d.ts +91 -0
- package/dist/bip39.js +417 -0
- package/dist/derive.d.ts +2 -0
- package/dist/derive.js +9 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +53 -0
- package/dist/javaStreamables.d.ts +233 -0
- package/dist/javaStreamables.js +332 -0
- package/dist/lease/LeaseMonitor.d.ts +44 -0
- package/dist/lease/LeaseMonitor.js +107 -0
- package/dist/lease/LeaseStore.d.ts +57 -0
- package/dist/lease/LeaseStore.js +144 -0
- package/dist/lease/WatermarkStore.d.ts +61 -0
- package/dist/lease/WatermarkStore.js +202 -0
- package/dist/lease/index.d.ts +14 -0
- package/dist/lease/index.js +13 -0
- package/dist/lease-client.d.ts +31 -0
- package/dist/lease-client.js +39 -0
- package/dist/minima32.d.ts +18 -0
- package/dist/minima32.js +112 -0
- package/dist/minimaWireSerializer.d.ts +60 -0
- package/dist/minimaWireSerializer.js +71 -0
- package/dist/mmr.d.ts +156 -0
- package/dist/mmr.js +342 -0
- package/dist/mx.d.ts +1 -0
- package/dist/mx.js +1 -0
- package/dist/params.d.ts +29 -0
- package/dist/params.js +16 -0
- package/dist/script.d.ts +7 -0
- package/dist/script.js +22 -0
- package/dist/scripts/contract-helpers.d.ts +252 -0
- package/dist/scripts/contract-helpers.js +394 -0
- package/dist/scripts/dapp-types.d.ts +119 -0
- package/dist/scripts/dapp-types.js +72 -0
- package/dist/scripts/index.d.ts +4 -0
- package/dist/scripts/index.js +4 -0
- package/dist/scripts/types.d.ts +81 -0
- package/dist/scripts/types.js +145 -0
- package/dist/scripts/witness-serializer.d.ts +29 -0
- package/dist/scripts/witness-serializer.js +288 -0
- package/dist/transaction.d.ts +106 -0
- package/dist/transaction.js +284 -0
- package/dist/treekey.d.ts +383 -0
- package/dist/treekey.js +762 -0
- package/dist/tx/TransactionLifecycle.d.ts +55 -0
- package/dist/tx/TransactionLifecycle.js +189 -0
- package/dist/tx/TransactionReceiptStore.d.ts +36 -0
- package/dist/tx/TransactionReceiptStore.js +85 -0
- package/dist/tx/TransactionService.d.ts +50 -0
- package/dist/tx/TransactionService.js +178 -0
- package/dist/tx/index.d.ts +13 -0
- package/dist/tx/index.js +12 -0
- package/dist/tx/types.d.ts +114 -0
- package/dist/tx/types.js +5 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +35 -0
- package/dist/verify.d.ts +18 -0
- package/dist/verify.js +162 -0
- package/dist/version.d.ts +12 -0
- package/dist/version.js +12 -0
- package/dist/wots.d.ts +232 -0
- package/dist/wots.js +538 -0
- package/package.json +65 -0
- package/src/Streamable.d.ts +265 -0
- package/src/Streamable.js +431 -0
- package/src/Streamable.ts +567 -0
- package/src/__tests__/Streamable.parity.test.ts +422 -0
- package/src/__tests__/perAddressDerivation.parity.test.ts +152 -0
- package/src/__tests__/wots-parity.test.ts +289 -0
- package/src/adapters/index.d.ts +190 -0
- package/src/adapters/index.js +117 -0
- package/src/adapters/index.ts +301 -0
- package/src/adapters/types.ts +235 -0
- package/src/addr.oracle.test.ts +25 -0
- package/src/address.test.ts +55 -0
- package/src/binio.ts +21 -0
- package/src/bip39.d.ts +91 -0
- package/src/bip39.js +427 -0
- package/src/bip39.ts +432 -0
- package/src/derive.d.ts +2 -0
- package/src/derive.js +13 -0
- package/src/derive.ts +11 -0
- package/src/index.d.ts +26 -0
- package/src/index.js +128 -0
- package/src/index.test.ts +5 -0
- package/src/index.ts +206 -0
- package/src/javaStreamables.d.ts +233 -0
- package/src/javaStreamables.js +328 -0
- package/src/javaStreamables.ts +403 -0
- package/src/lease/LeaseMonitor.d.ts +44 -0
- package/src/lease/LeaseMonitor.js +111 -0
- package/src/lease/LeaseMonitor.ts +157 -0
- package/src/lease/LeaseStore.d.ts +57 -0
- package/src/lease/LeaseStore.js +148 -0
- package/src/lease/LeaseStore.ts +203 -0
- package/src/lease/WatermarkStore.d.ts +61 -0
- package/src/lease/WatermarkStore.js +206 -0
- package/src/lease/WatermarkStore.ts +270 -0
- package/src/lease/index.d.ts +14 -0
- package/src/lease/index.js +22 -0
- package/src/lease/index.ts +41 -0
- package/src/lease-client.d.ts +31 -0
- package/src/lease-client.js +44 -0
- package/src/lease-client.ts +69 -0
- package/src/minima32.d.ts +10 -0
- package/src/minima32.js +113 -0
- package/src/minima32.test.ts +11 -0
- package/src/minima32.ts +127 -0
- package/src/minimaWireSerializer.d.ts +189 -0
- package/src/minimaWireSerializer.js +311 -0
- package/src/minimaWireSerializer.test.ts +466 -0
- package/src/minimaWireSerializer.ts +117 -0
- package/src/mmr.d.ts +153 -0
- package/src/mmr.js +351 -0
- package/src/mmr.oracle.test.ts +28 -0
- package/src/mmr.ts +429 -0
- package/src/mx.test.ts +25 -0
- package/src/mx.ts +1 -0
- package/src/params.d.ts +29 -0
- package/src/params.d.ts.map +1 -0
- package/src/params.js +20 -0
- package/src/params.js.map +1 -0
- package/src/params.ts +44 -0
- package/src/script.d.ts +7 -0
- package/src/script.js +27 -0
- package/src/script.ts +24 -0
- package/src/scripts/contract-helpers.ts +609 -0
- package/src/scripts/dapp-types.ts +240 -0
- package/src/scripts/index.ts +22 -0
- package/src/scripts/types.ts +247 -0
- package/src/scripts/witness-serializer.ts +384 -0
- package/src/transaction.ts +430 -0
- package/src/treekey.d.ts +383 -0
- package/src/treekey.js +778 -0
- package/src/treekey.parity.test.ts +459 -0
- package/src/treekey.ts +979 -0
- package/src/tx/TransactionLifecycle.d.ts +55 -0
- package/src/tx/TransactionLifecycle.js +188 -0
- package/src/tx/TransactionLifecycle.ts +280 -0
- package/src/tx/TransactionReceiptStore.d.ts +36 -0
- package/src/tx/TransactionReceiptStore.js +89 -0
- package/src/tx/TransactionReceiptStore.ts +112 -0
- package/src/tx/TransactionService.d.ts +31 -0
- package/src/tx/TransactionService.js +140 -0
- package/src/tx/TransactionService.ts +250 -0
- package/src/tx/index.d.ts +13 -0
- package/src/tx/index.js +20 -0
- package/src/tx/index.ts +44 -0
- package/src/tx/types.d.ts +80 -0
- package/src/tx/types.js +6 -0
- package/src/tx/types.ts +127 -0
- package/src/util.d.ts +1 -0
- package/src/util.js +5 -0
- package/src/util.ts +1 -0
- package/src/utils.d.ts +8 -0
- package/src/utils.js +42 -0
- package/src/utils.ts +38 -0
- package/src/verify.ts +209 -0
- package/src/version.ts +13 -0
- package/src/wots.d.ts +224 -0
- package/src/wots.d.ts.map +1 -0
- package/src/wots.js +559 -0
- package/src/wots.js.map +1 -0
- package/src/wots.ts +636 -0
- package/test-vectors.json +45 -0
package/dist/minima32.js
ADDED
|
@@ -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;
|