@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/src/treekey.d.ts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
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';
|
|
12
|
+
import type { LoggerAdapter } from './adapters';
|
|
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
|
+
* PER-ADDRESS TREEKEY FACTORY
|
|
330
|
+
* ============================================================================
|
|
331
|
+
*
|
|
332
|
+
* Minima Wallet.createNewKey() creates independent TreeKeys per address:
|
|
333
|
+
* MiniData modifier = new MiniData(new BigInteger(Integer.toString(numkeys)));
|
|
334
|
+
* MiniData privseed = Crypto.getInstance().hashObjects(baseSeed, modifier);
|
|
335
|
+
* TreeKey treekey = TreeKey.createDefault(privseed);
|
|
336
|
+
*
|
|
337
|
+
* Each address gets its own TreeKey with:
|
|
338
|
+
* - Unique seed derived from baseSeed + addressIndex
|
|
339
|
+
* - Size=64, depth=3 (matching TreeKey.createDefault)
|
|
340
|
+
* - 4096 one-time signatures per address (64×64)
|
|
341
|
+
*
|
|
342
|
+
* Total wallet capacity: 64 addresses × 4096 signatures = 262,144 signatures
|
|
343
|
+
* ============================================================================
|
|
344
|
+
*/
|
|
345
|
+
/**
|
|
346
|
+
* Create a per-address TreeKey matching Minima Wallet.createNewKey()
|
|
347
|
+
*
|
|
348
|
+
* @param baseSeed - 32-byte wallet base seed (from mnemonic)
|
|
349
|
+
* @param addressIndex - Address index (0-63)
|
|
350
|
+
* @returns TreeKey for this address with size=64, depth=3
|
|
351
|
+
*/
|
|
352
|
+
export declare function createPerAddressTreeKey(baseSeed: Bytes, addressIndex: number): TreeKey;
|
|
353
|
+
/**
|
|
354
|
+
* Async version with progress reporting for UI
|
|
355
|
+
*
|
|
356
|
+
* @param baseSeed - 32-byte wallet base seed
|
|
357
|
+
* @param addressIndex - Address index (0-63)
|
|
358
|
+
* @param onProgress - Optional progress callback
|
|
359
|
+
* @returns Promise resolving to TreeKey for this address
|
|
360
|
+
*/
|
|
361
|
+
export declare function createPerAddressTreeKeyAsync(baseSeed: Bytes, addressIndex: number, onProgress?: ProgressCallback): Promise<TreeKey>;
|
|
362
|
+
/**
|
|
363
|
+
* Derive address public key from base seed and address index
|
|
364
|
+
*
|
|
365
|
+
* This is the fast path for getting an address public key without
|
|
366
|
+
* needing to construct the full TreeKey. Useful for address derivation
|
|
367
|
+
* during wallet initialization.
|
|
368
|
+
*
|
|
369
|
+
* @param baseSeed - 32-byte wallet base seed
|
|
370
|
+
* @param addressIndex - Address index (0-63)
|
|
371
|
+
* @returns 32-byte address public key (MMR root of per-address TreeKey)
|
|
372
|
+
*/
|
|
373
|
+
export declare function deriveAddressPublicKey(baseSeed: Bytes, addressIndex: number): Bytes;
|
|
374
|
+
/**
|
|
375
|
+
* Get the address public key from a per-address TreeKey
|
|
376
|
+
*
|
|
377
|
+
* In the per-address architecture, each address has its own TreeKey,
|
|
378
|
+
* and the address public key is simply the TreeKey's root public key.
|
|
379
|
+
*
|
|
380
|
+
* @param treeKey - Per-address TreeKey
|
|
381
|
+
* @returns 32-byte address public key (TreeKey root)
|
|
382
|
+
*/
|
|
383
|
+
export declare function getPerAddressPublicKey(treeKey: TreeKey): Bytes;
|