@totemsdk/core 1.2.6 → 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/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/index.d.ts +9 -3
- package/dist/index.js +25 -2
- package/dist/minimaWireSerializer.js +2 -2
- package/dist/mmr.js +1 -1
- package/dist/transaction.js +10 -10
- package/dist/treekey.js +14 -0
- package/dist/wasm-sync.d.ts +2 -2
- package/dist/wasm-sync.js +3 -1
- package/dist/wots.d.ts +1 -1
- package/package.json +84 -45
- package/dist/wasm-bridge.d.ts +0 -54
- package/dist/wasm-bridge.js +0 -303
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TreeKey/TreeKeyNode Implementation matching Minima's TreeKey.java and TreeKeyNode.java
|
|
3
|
+
*
|
|
4
|
+
* This implements the hierarchical key tree structure where:
|
|
5
|
+
* - Each TreeKeyNode contains 64 Winternitz keys
|
|
6
|
+
* - The node's PUBLIC KEY = MMR root of all 64 Winternitz public keys
|
|
7
|
+
* - Signatures include the Winternitz leaf pubkey + signature + MMR proof
|
|
8
|
+
*
|
|
9
|
+
* Default structure: 3 levels x 64 keys = 64^3 = 262,144 one-time signatures
|
|
10
|
+
*/
|
|
11
|
+
import { MMRProof, Bytes } from './mmr.js';
|
|
12
|
+
import type { LoggerAdapter } from './adapters/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Enable TreeKey debug logging with a custom logger
|
|
15
|
+
* Use this for parity testing to capture wallet init intermediate values
|
|
16
|
+
*
|
|
17
|
+
* WARNING: Debug logging outputs sensitive cryptographic material including
|
|
18
|
+
* seeds and private key derivation. NEVER enable in production builds.
|
|
19
|
+
* This is intended for development/testing parity verification only.
|
|
20
|
+
*/
|
|
21
|
+
export declare function setTreeKeyLogger(logger: LoggerAdapter): void;
|
|
22
|
+
/**
|
|
23
|
+
* Disable TreeKey debug logging
|
|
24
|
+
*/
|
|
25
|
+
export declare function disableTreeKeyLogger(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Check if TreeKey debug logging is enabled
|
|
28
|
+
*/
|
|
29
|
+
export declare function isTreeKeyDebugEnabled(): boolean;
|
|
30
|
+
export declare const DEFAULT_KEYS_PER_LEVEL = 64;
|
|
31
|
+
export declare const DEFAULT_LEVELS = 3;
|
|
32
|
+
/**
|
|
33
|
+
* Progress callback for key generation
|
|
34
|
+
*/
|
|
35
|
+
export interface KeyGenProgress {
|
|
36
|
+
phase: 'wots_keys' | 'mmr_build' | 'address_derive' | 'complete';
|
|
37
|
+
current: number;
|
|
38
|
+
total: number;
|
|
39
|
+
message: string;
|
|
40
|
+
}
|
|
41
|
+
export type ProgressCallback = (progress: KeyGenProgress) => void;
|
|
42
|
+
/**
|
|
43
|
+
* SignatureProof structure matching Minima's SignatureProof.java
|
|
44
|
+
*
|
|
45
|
+
* Contains:
|
|
46
|
+
* - leafPubkey: The 32-byte WOTS public key DIGEST (SHA3-256 of full L×32 key)
|
|
47
|
+
* - signature: The 1088-byte Winternitz signature (L×32 bytes)
|
|
48
|
+
* - mmrProof: Proof linking the leaf pubkey to the tree node's root
|
|
49
|
+
*
|
|
50
|
+
* CRITICAL FIX (January 2026): Java's Winternitz.getPublicKey() returns a 32-byte digest!
|
|
51
|
+
*
|
|
52
|
+
* From BouncyCastle WinternitzOTSignature.getPublicKey() (lines 103-121):
|
|
53
|
+
* byte[] buf = new byte[keysize * mdsize]; // Full 1088 bytes (34×32)
|
|
54
|
+
* // ... hash each chain 255 times into buf ...
|
|
55
|
+
* messDigestOTS.update(buf, 0, buf.length); // Hash the full key
|
|
56
|
+
* byte[] tmp = new byte[mdsize]; // 32 bytes
|
|
57
|
+
* messDigestOTS.doFinal(tmp, 0); // SHA3-256
|
|
58
|
+
* return tmp; // Returns 32-byte DIGEST!
|
|
59
|
+
*
|
|
60
|
+
* Similarly, WinternitzOTSVerify.Verify() recovers the full key then hashes to 32 bytes.
|
|
61
|
+
* Winternitz.verify() then compares the 32-byte recovered digest to mPublicKey (32 bytes).
|
|
62
|
+
*
|
|
63
|
+
* Previous bug: We stored 1088-byte full keys, Java expected 32-byte digests → always failed.
|
|
64
|
+
*/
|
|
65
|
+
export interface SignatureProof {
|
|
66
|
+
leafPubkey: Bytes;
|
|
67
|
+
signature: Bytes;
|
|
68
|
+
mmrProof: MMRProof;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Full Signature structure matching Minima's Signature.java
|
|
72
|
+
*
|
|
73
|
+
* For a 3-level tree, contains 3 SignatureProofs:
|
|
74
|
+
* - Level 0: Signs level 1's root public key
|
|
75
|
+
* - Level 1: Signs level 2's root public key
|
|
76
|
+
* - Level 2: Signs the actual data
|
|
77
|
+
*/
|
|
78
|
+
export interface TreeSignature {
|
|
79
|
+
proofs: SignatureProof[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Compute root public key from a Winternitz signature proof
|
|
83
|
+
* Matches SignatureProof.getRootPublicKey() in Java
|
|
84
|
+
*/
|
|
85
|
+
export declare function getRootPublicKey(proof: SignatureProof): Bytes;
|
|
86
|
+
/**
|
|
87
|
+
* TreeKeyNode - One node in the key tree containing 64 Winternitz keys
|
|
88
|
+
*
|
|
89
|
+
* Matches TreeKeyNode.java (see attached_assets/TreeKeyNode_1767574401422.java):
|
|
90
|
+
*
|
|
91
|
+
* Key generation (lines 44-62):
|
|
92
|
+
* - Creates 64 Winternitz keys from a deterministic seed
|
|
93
|
+
* - For each key: MiniData pubkey = wots.getPublicKey() returns 32-byte DIGEST
|
|
94
|
+
* - Adds to MMR: MMRData.CreateMMRDataLeafNode(pubkey, MiniNumber.ZERO)
|
|
95
|
+
* - Public key = MMR root (mPublicKey = mTree.getRoot().getData())
|
|
96
|
+
*
|
|
97
|
+
* MMR leaf construction (see MMRData.java lines 30-36):
|
|
98
|
+
* MMRData.CreateMMRDataLeafNode(pubkeyDigest, MiniNumber.ZERO)
|
|
99
|
+
* → hash = Crypto.hashAllObjects(MiniNumber.ZERO, zData, zSumValue)
|
|
100
|
+
* → Serialization: [0x00,0x01,0x00] + [4-byte-len + pubkey] + [0x00,0x01,0x00]
|
|
101
|
+
*
|
|
102
|
+
* MMR parent construction (see MMRData.java lines 38-50):
|
|
103
|
+
* MMRData.CreateMMRDataParentNode(left, right)
|
|
104
|
+
* → hash = Crypto.hashAllObjects(MiniNumber.ONE, left.data, right.data, sumValue)
|
|
105
|
+
*
|
|
106
|
+
* IMPORTANT: Minima NEVER stores the 1088-byte full WOTS public key.
|
|
107
|
+
* Only the 32-byte digest is stored and used for MMR construction.
|
|
108
|
+
*/
|
|
109
|
+
export declare class TreeKeyNode {
|
|
110
|
+
private seed;
|
|
111
|
+
private childSeed;
|
|
112
|
+
private keysPerLevel;
|
|
113
|
+
private publicKeyDigests;
|
|
114
|
+
private mmrTree;
|
|
115
|
+
private rootPubkey;
|
|
116
|
+
private childCache;
|
|
117
|
+
constructor(privateSeed: Bytes, keysPerLevel?: number);
|
|
118
|
+
/**
|
|
119
|
+
* Async factory method for TreeKeyNode with progress reporting
|
|
120
|
+
* Yields to event loop every few keys to keep UI responsive
|
|
121
|
+
*/
|
|
122
|
+
static createWithProgress(privateSeed: Bytes, keysPerLevel?: number, onProgress?: ProgressCallback): Promise<TreeKeyNode>;
|
|
123
|
+
/**
|
|
124
|
+
* Get the public key for this tree node (MMR root of all 64 Winternitz keys)
|
|
125
|
+
*/
|
|
126
|
+
getPublicKey(): Bytes;
|
|
127
|
+
/**
|
|
128
|
+
* Get the full Winternitz public key at a specific index (0-63)
|
|
129
|
+
* Returns the full L×32 byte public key (1088 bytes), derived on-demand
|
|
130
|
+
*
|
|
131
|
+
* NOTE: This is only used for local signature verification in tests.
|
|
132
|
+
* Java's Winternitz.getPublicKey() returns a 32-byte digest, not this.
|
|
133
|
+
* For production code, use getWOTSPublicKeyDigest() instead.
|
|
134
|
+
*
|
|
135
|
+
* @deprecated Use getWOTSPublicKeyDigest() for Minima compatibility
|
|
136
|
+
*/
|
|
137
|
+
getWOTSPublicKey(index: number): Bytes;
|
|
138
|
+
/**
|
|
139
|
+
* Get the Winternitz public key digest at a specific index (0-63)
|
|
140
|
+
* Returns the 32-byte SHA3 hash of the full public key
|
|
141
|
+
*/
|
|
142
|
+
getWOTSPublicKeyDigest(index: number): Bytes;
|
|
143
|
+
/**
|
|
144
|
+
* Get the MMR proof for a specific key index
|
|
145
|
+
*/
|
|
146
|
+
getProof(keyIndex: number): MMRProof;
|
|
147
|
+
/**
|
|
148
|
+
* Sign data with a specific key from this node
|
|
149
|
+
* Returns a SignatureProof containing the 32-byte leaf pubkey DIGEST, signature, and MMR proof
|
|
150
|
+
*
|
|
151
|
+
* CRITICAL: Java's WinternitzOTSignature.getSignature() ALWAYS hashes the message first,
|
|
152
|
+
* regardless of input length. From BouncyCastle WinternitzOTSignature.java lines 137-138:
|
|
153
|
+
* messDigestOTS.update(message, 0, message.length);
|
|
154
|
+
* messDigestOTS.doFinal(hash, 0);
|
|
155
|
+
*
|
|
156
|
+
* We MUST always hash to match Java verification, which also always hashes.
|
|
157
|
+
*
|
|
158
|
+
* CRITICAL FIX (January 2026): leafPubkey is the 32-byte WOTS public key DIGEST.
|
|
159
|
+
* Java's Winternitz.getPublicKey() returns SHA3-256(full_key) = 32 bytes!
|
|
160
|
+
* Previous bug: We stored 1088-byte full keys, Java expected 32-byte digests → verification failed.
|
|
161
|
+
*/
|
|
162
|
+
sign(keyIndex: number, data: Bytes): SignatureProof;
|
|
163
|
+
/**
|
|
164
|
+
* Create a child TreeKeyNode at the specified index
|
|
165
|
+
* Matches TreeKeyNode.java getChild()
|
|
166
|
+
*
|
|
167
|
+
* PERFORMANCE FIX: Child nodes are now cached to avoid regenerating
|
|
168
|
+
* 64 WOTS keys on every getChild() call. This is critical for address
|
|
169
|
+
* derivation performance where getChild() is called 64 times.
|
|
170
|
+
*/
|
|
171
|
+
getChild(childIndex: number): TreeKeyNode;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* TreeKey - Full hierarchical key tree with multiple levels
|
|
175
|
+
*
|
|
176
|
+
* Matches TreeKey.java:
|
|
177
|
+
* - Default: 3 levels x 64 keys = 262,144 one-time signatures
|
|
178
|
+
* - Tracks usage count to determine which key to use
|
|
179
|
+
* - Produces multi-level signatures
|
|
180
|
+
*/
|
|
181
|
+
export declare class TreeKey {
|
|
182
|
+
private privateSeed;
|
|
183
|
+
private levels;
|
|
184
|
+
private keysPerLevel;
|
|
185
|
+
private root;
|
|
186
|
+
private publicKey;
|
|
187
|
+
private uses;
|
|
188
|
+
/**
|
|
189
|
+
* Parent-child signature cache for efficiency
|
|
190
|
+
* Key format: "l1" for root->level1, "l1,l2" for level1->level2
|
|
191
|
+
* Value: SignatureProof for parent signing child's pubkey
|
|
192
|
+
*/
|
|
193
|
+
private parentChildSigCache;
|
|
194
|
+
constructor(privateSeed: Bytes, keysPerLevel?: number, levels?: number);
|
|
195
|
+
/**
|
|
196
|
+
* Async factory method for TreeKey with progress reporting
|
|
197
|
+
* Reports progress as the root TreeKeyNode generates its 64 signing keys
|
|
198
|
+
*/
|
|
199
|
+
static createWithProgress(privateSeed: Bytes, keysPerLevel?: number, levels?: number, onProgress?: ProgressCallback): Promise<TreeKey>;
|
|
200
|
+
/**
|
|
201
|
+
* Get the root TreeKeyNode (for internal use)
|
|
202
|
+
*/
|
|
203
|
+
getRootNode(): TreeKeyNode;
|
|
204
|
+
/**
|
|
205
|
+
* Get the root public key (for watermark tracking)
|
|
206
|
+
*/
|
|
207
|
+
getRootPublicKey(): Bytes;
|
|
208
|
+
/**
|
|
209
|
+
* Get the wallet's public key (root of the key tree)
|
|
210
|
+
*/
|
|
211
|
+
getPublicKey(): Bytes;
|
|
212
|
+
/**
|
|
213
|
+
* Get the maximum number of signatures this tree can produce
|
|
214
|
+
*/
|
|
215
|
+
getMaxUses(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Get current usage count
|
|
218
|
+
*/
|
|
219
|
+
getUses(): number;
|
|
220
|
+
/**
|
|
221
|
+
* Set the usage counter (for resuming from a known state)
|
|
222
|
+
*/
|
|
223
|
+
setUses(uses: number): void;
|
|
224
|
+
/**
|
|
225
|
+
* Generate cache key for parent-child signature
|
|
226
|
+
* @param path - Array of indices leading to the child (e.g., [l1] or [l1, l2])
|
|
227
|
+
*/
|
|
228
|
+
private getCacheKey;
|
|
229
|
+
/**
|
|
230
|
+
* Check if a parent-child signature is cached
|
|
231
|
+
* @param path - Array of indices (e.g., [l1] for root->level1)
|
|
232
|
+
*/
|
|
233
|
+
hasParentChildSig(path: number[]): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Get a cached parent-child signature
|
|
236
|
+
* @param path - Array of indices (e.g., [l1] for root->level1)
|
|
237
|
+
*/
|
|
238
|
+
getParentChildSig(path: number[]): SignatureProof | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Cache a parent-child signature for reuse
|
|
241
|
+
* This allows the same signature to be reused across multiple signing operations
|
|
242
|
+
*
|
|
243
|
+
* @param path - Array of indices leading to the child (e.g., [l1] or [l1, l2])
|
|
244
|
+
* @param sig - SignatureProof from parent signing child's public key
|
|
245
|
+
*/
|
|
246
|
+
setParentChildSig(path: number[], sig: SignatureProof): void;
|
|
247
|
+
/**
|
|
248
|
+
* Get all cached parent-child signatures (for serialization/persistence)
|
|
249
|
+
*/
|
|
250
|
+
getCachedSignatures(): Map<string, SignatureProof>;
|
|
251
|
+
/**
|
|
252
|
+
* Restore cached signatures (for hydrating from persistence)
|
|
253
|
+
*/
|
|
254
|
+
restoreCachedSignatures(cache: Map<string, SignatureProof>): void;
|
|
255
|
+
/**
|
|
256
|
+
* Convert a usage number to the path through the tree
|
|
257
|
+
* Matches TreeKey.java baseConversion()
|
|
258
|
+
*
|
|
259
|
+
* For uses=0: [0,0,0]
|
|
260
|
+
* For uses=1: [0,0,1]
|
|
261
|
+
* For uses=64: [0,1,0]
|
|
262
|
+
* etc.
|
|
263
|
+
*/
|
|
264
|
+
private baseConversion;
|
|
265
|
+
/**
|
|
266
|
+
* Sign data with the current key and increment usage
|
|
267
|
+
*
|
|
268
|
+
* Matches TreeKey.java sign():
|
|
269
|
+
* - Determines path through tree based on usage count
|
|
270
|
+
* - Each level's key signs the next level's root public key
|
|
271
|
+
* - Final level signs the actual data
|
|
272
|
+
*
|
|
273
|
+
* CRITICAL FIX (January 2026): Build proofs bottom-up to sign child's getRootPublicKey()
|
|
274
|
+
*
|
|
275
|
+
* Java's TreeKey.verify() verifies non-leaf signatures against childsig.getRootPublicKey(),
|
|
276
|
+
* which is the 32-byte MMR root computed from the NEXT proof's leafPubkey + MMRproof.
|
|
277
|
+
*
|
|
278
|
+
* Uses parent-child signature caching for efficiency:
|
|
279
|
+
* - Parent-child signatures are cached and reused
|
|
280
|
+
* - Only the final data signature is computed fresh each time
|
|
281
|
+
*/
|
|
282
|
+
sign(data: Bytes): TreeSignature;
|
|
283
|
+
/**
|
|
284
|
+
* Get the public key for a level-1 address (single index)
|
|
285
|
+
* This is the MMR root of the level-1 TreeKeyNode's 64 Winternitz keys.
|
|
286
|
+
*
|
|
287
|
+
* Use this for wallet addresses where each address = one level-1 node.
|
|
288
|
+
*
|
|
289
|
+
* @param l1 - Level 1 index (0-63, corresponds to wallet address index)
|
|
290
|
+
* @returns 32-byte MMR root public key for SIGNEDBY scripts
|
|
291
|
+
*/
|
|
292
|
+
getAddressPublicKey(l1: number): Bytes;
|
|
293
|
+
/**
|
|
294
|
+
* Get the public key for a specific signing key at tree index (l1, l2)
|
|
295
|
+
* This navigates to the level-2 node for signing operations.
|
|
296
|
+
*
|
|
297
|
+
* @param l1 - Level 1 index (address)
|
|
298
|
+
* @param l2 - Level 2 index (signing key within address)
|
|
299
|
+
* @returns 32-byte MMR root public key of level-2 node
|
|
300
|
+
*/
|
|
301
|
+
getSigningNodePublicKey(l1: number, l2: number): Bytes;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Verify a tree signature against expected public key and data
|
|
305
|
+
*
|
|
306
|
+
* Matches TreeKey.java verify():
|
|
307
|
+
* - First proof's computed root must match expected public key
|
|
308
|
+
* - Each intermediate proof must sign the next level's root
|
|
309
|
+
* - Final proof must verify against the actual data
|
|
310
|
+
*/
|
|
311
|
+
export declare function verifyTreeSignature(expectedPubkey: Bytes, data: Bytes, signature: TreeSignature): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Serialize a TreeSignature to bytes
|
|
314
|
+
*
|
|
315
|
+
* Uses Streamable.writeSignature() for byte-exact compatibility
|
|
316
|
+
* with Java's Signature.writeDataStream().
|
|
317
|
+
*/
|
|
318
|
+
export declare function serializeTreeSignature(sig: TreeSignature): Bytes;
|
|
319
|
+
/**
|
|
320
|
+
* Deserialize a TreeSignature from bytes
|
|
321
|
+
*
|
|
322
|
+
* Matches Java's Signature.readDataStream():
|
|
323
|
+
* - Number of proofs: MiniNumber format
|
|
324
|
+
* - Each SignatureProof: MiniData(pubkey) + MiniData(signature) + MMRProof
|
|
325
|
+
*/
|
|
326
|
+
export declare function deserializeTreeSignature(data: Bytes): TreeSignature;
|
|
327
|
+
/**
|
|
328
|
+
* ============================================================================
|
|
329
|
+
* UNIFIED TREEKEY FACTORY
|
|
330
|
+
* ============================================================================
|
|
331
|
+
*
|
|
332
|
+
* Single hierarchical derivation scheme:
|
|
333
|
+
*
|
|
334
|
+
* root_priv_seed = deriveRootPrivSeed(baseSeed)
|
|
335
|
+
* child_seed_i = deriveUnifiedChildSeed(baseSeed, i)
|
|
336
|
+
* child_treekey_i = new TreeKey(child_seed_i, 64, 3) ← spend address i
|
|
337
|
+
* root_treekey = new TreeKey(root_priv_seed, 64, 3) ← identity anchor
|
|
338
|
+
*
|
|
339
|
+
* Child seeds are cryptographically descended from root_priv_seed, not siblings.
|
|
340
|
+
* Addresses are Minima-compatible (RETURN SIGNEDBY(pubkey) scripts, WOTS sigs).
|
|
341
|
+
* The root TreeKey is NEVER used as a spend address.
|
|
342
|
+
*
|
|
343
|
+
* Signature capacity: 64 addresses × 4 096 signatures each = 262 144 total.
|
|
344
|
+
* Root identity capacity: 4 096 attestation signatures.
|
|
345
|
+
* ============================================================================
|
|
346
|
+
*/
|
|
347
|
+
/**
|
|
348
|
+
* Create the unified child TreeKey for spend address at `index`.
|
|
349
|
+
*
|
|
350
|
+
* Derivation: child_seed_i = deriveUnifiedChildSeed(baseSeed, i)
|
|
351
|
+
* treeKey = new TreeKey(child_seed_i, 64, 3)
|
|
352
|
+
*
|
|
353
|
+
* @param baseSeed - 32-byte wallet base seed (from mnemonic)
|
|
354
|
+
* @param index - Address index (0-63)
|
|
355
|
+
* @returns TreeKey for this spend address with size=64, depth=3
|
|
356
|
+
*/
|
|
357
|
+
export declare function createUnifiedChildTreeKey(baseSeed: Bytes, index: number): TreeKey;
|
|
358
|
+
/**
|
|
359
|
+
* Async version with progress reporting for UI.
|
|
360
|
+
*
|
|
361
|
+
* @param baseSeed - 32-byte wallet base seed
|
|
362
|
+
* @param index - Address index (0-63)
|
|
363
|
+
* @param onProgress - Optional progress callback
|
|
364
|
+
* @returns Promise resolving to the child TreeKey
|
|
365
|
+
*/
|
|
366
|
+
export declare function createUnifiedChildTreeKeyAsync(baseSeed: Bytes, index: number, onProgress?: ProgressCallback): Promise<TreeKey>;
|
|
367
|
+
/**
|
|
368
|
+
* Create the unified root identity TreeKey (identity anchor, never a spend address).
|
|
369
|
+
*
|
|
370
|
+
* Derivation: root_priv_seed = deriveRootPrivSeed(baseSeed)
|
|
371
|
+
* treeKey = new TreeKey(root_priv_seed, 64, 3)
|
|
372
|
+
*
|
|
373
|
+
* @param baseSeed - 32-byte wallet base seed (from mnemonic)
|
|
374
|
+
* @returns Root identity TreeKey with size=64, depth=3
|
|
375
|
+
*/
|
|
376
|
+
export declare function createUnifiedRootTreeKey(baseSeed: Bytes): TreeKey;
|
|
377
|
+
/**
|
|
378
|
+
* Fast path for deriving a child address public key without constructing
|
|
379
|
+
* the full TreeKey. Useful during wallet initialisation.
|
|
380
|
+
*
|
|
381
|
+
* @param baseSeed - 32-byte wallet base seed
|
|
382
|
+
* @param index - Address index (0-63)
|
|
383
|
+
* @returns 32-byte address public key (MMR root of child TreeKey)
|
|
384
|
+
*/
|
|
385
|
+
export declare function deriveUnifiedAddressPublicKey(baseSeed: Bytes, index: number): Bytes;
|
|
386
|
+
/**
|
|
387
|
+
* @deprecated Use {@link createUnifiedChildTreeKey} instead.
|
|
388
|
+
* This wrapper preserves the LEGACY per-address seed derivation
|
|
389
|
+
* (`SHA3-256(baseSeed ‖ indexBytes(i))`) so that existing callers
|
|
390
|
+
* that import this symbol by name continue to derive the same keys.
|
|
391
|
+
* New code must use createUnifiedChildTreeKey which applies the unified
|
|
392
|
+
* two-step derivation (root_priv_seed → child_seed_i).
|
|
393
|
+
*/
|
|
394
|
+
export declare function createPerAddressTreeKey(baseSeed: Bytes, addressIndex: number): TreeKey;
|
|
395
|
+
/**
|
|
396
|
+
* @deprecated Use {@link createUnifiedChildTreeKeyAsync} instead.
|
|
397
|
+
* Preserves legacy per-address seed derivation for backward compatibility.
|
|
398
|
+
*/
|
|
399
|
+
export declare function createPerAddressTreeKeyAsync(baseSeed: Bytes, addressIndex: number, onProgress?: ProgressCallback): Promise<TreeKey>;
|