@totemsdk/core 1.0.11 → 1.2.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/legacy.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * Legacy JS implementations — backward compatibility.
4
+ *
5
+ * These are the original TypeScript implementations preserved for
6
+ * environments where WASM is not available. The main entry point
7
+ * (`@totemsdk/core`) now delegates to WASM by default.
8
+ *
9
+ * Import legacy implementations directly:
10
+ * import { wotsSign } from '@totemsdk/core/legacy';
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.legacyGenerateWordList = exports.legacyPhraseToSeed = exports.convertWordListToSeed = exports.convertStringToSeed = exports.legacyValidatePhrase = exports.legacyCleanSeedPhrase = exports.WORD_LIST = exports.serializeRealMMRProof = exports.serializeMMRProof = exports.deserializeMMRProof = exports.parseMMRProofFromHex = exports.legacyVerifyMMRProof = exports.calculateProofRoot = exports.createMMRDataParentNode = exports.createMMRDataLeafNode = exports.mmrRootFromSingleLeaf = exports.mmrLeafExact = exports.MMRTree = exports.createPerAddressTreeKeyAsync = exports.createPerAddressTreeKey = exports.legacyDeriveUnifiedAddressPublicKey = exports.legacyCreateUnifiedRootTreeKey = exports.createUnifiedChildTreeKeyAsync = exports.legacyCreateUnifiedChildTreeKey = exports.DEFAULT_LEVELS = exports.DEFAULT_KEYS_PER_LEVEL = exports.getRootPublicKey = exports.deserializeTreeSignature = exports.serializeTreeSignature = exports.legacyVerifyTreeSignature = exports.TreeKeyNode = exports.TreeKey = exports.legacyWotsPublicKeyFromSeed = exports.legacyWotsVerifyDigest = exports.legacyWotsVerify = exports.legacyWotsPkFromSig = exports.wotsSignLegacy = exports.legacyWotsSign = exports.legacyWotsKeypairFromSeed = exports.legacyDerivePKdigest = exports.baseWWithChecksum = exports.toWinternitzDigits = exports.prfChainSeed = exports.h = exports.assert32 = exports.u32be = exports.u16be = exports.fromHex = exports.hex = exports.F = void 0;
28
+ exports.legacyPrecomputeTransactionCoinIDTx = exports.serializeMMREntry = exports.serializeMMRData = exports.serializeMMREntryNumber = exports.createMMREntryNumber = exports.deriveUnifiedChildSeed = exports.legacyDeriveRootPrivSeed = exports.legacyDerivePerAddressSeed = exports.indexToMiniDataBytes = exports.javaHashAllObjects = exports.serializeMiniNumberONE = exports.serializeMiniNumberZERO = exports.hashObject = exports.deriveChildTreeSeedJava = exports.legacyDeriveChainSeedJava = exports.hashAllObjects = exports.serializeMiniData = exports.serializeMiniNumber = exports.writeHashToStream = exports.legacyWriteMiniString = exports.bigIntToByteArray = exports.legacyBytesToHex = exports.legacyHexToBytes = exports.concat = exports.writeMMREntryNumber = exports.writeMiniByte = exports.legacyWriteMiniData = exports.legacyWriteMiniNumber = exports.convertMinimaAddress = exports.makeMinimaAddress = exports.decodeMx = exports.encodeMx = exports.mxToHex = exports.hexToMx = exports.legacyParseMxAddress = exports.legacyMakeMxAddress = exports.decodeMxRadix32Frame = exports.encodeMxRadix32Frame = exports.legacyWotsAddressFromKeypair = exports.scriptFromWotsPk = exports.addressToRoot = exports.scriptToAddress = exports.buildMinimaCoin = exports.createDefaultTransaction = exports.legacyPrecomputeTransactionCoinID = exports.legacyComputeTransactionDigest = exports.legacySerializeTransaction = exports.serializeCoin = exports.parseDecimalToMiniNumber = exports.generateSeedPhrase = void 0;
29
+ exports.legacyValidateChallenge = exports.legacyCreateChallenge = exports.normalizeHex = exports.deriveAddressFromPublicKey = exports.verifyTreeSignatureDetailed = exports.verifySignatureDetailed = exports.verifySignature = exports.legacyConcatBytes = void 0;
30
+ // WOTS — unique exports
31
+ var wots_js_1 = require("./wots.js");
32
+ Object.defineProperty(exports, "F", { enumerable: true, get: function () { return wots_js_1.F; } });
33
+ Object.defineProperty(exports, "hex", { enumerable: true, get: function () { return wots_js_1.hex; } });
34
+ Object.defineProperty(exports, "fromHex", { enumerable: true, get: function () { return wots_js_1.fromHex; } });
35
+ Object.defineProperty(exports, "u16be", { enumerable: true, get: function () { return wots_js_1.u16be; } });
36
+ Object.defineProperty(exports, "u32be", { enumerable: true, get: function () { return wots_js_1.u32be; } });
37
+ Object.defineProperty(exports, "assert32", { enumerable: true, get: function () { return wots_js_1.assert32; } });
38
+ Object.defineProperty(exports, "h", { enumerable: true, get: function () { return wots_js_1.h; } });
39
+ Object.defineProperty(exports, "prfChainSeed", { enumerable: true, get: function () { return wots_js_1.prfChainSeed; } });
40
+ Object.defineProperty(exports, "toWinternitzDigits", { enumerable: true, get: function () { return wots_js_1.toWinternitzDigits; } });
41
+ Object.defineProperty(exports, "baseWWithChecksum", { enumerable: true, get: function () { return wots_js_1.baseWWithChecksum; } });
42
+ Object.defineProperty(exports, "legacyDerivePKdigest", { enumerable: true, get: function () { return wots_js_1.derivePKdigest; } });
43
+ Object.defineProperty(exports, "legacyWotsKeypairFromSeed", { enumerable: true, get: function () { return wots_js_1.wotsKeypairFromSeed; } });
44
+ Object.defineProperty(exports, "legacyWotsSign", { enumerable: true, get: function () { return wots_js_1.wotsSign; } });
45
+ Object.defineProperty(exports, "wotsSignLegacy", { enumerable: true, get: function () { return wots_js_1.wotsSignLegacy; } });
46
+ Object.defineProperty(exports, "legacyWotsPkFromSig", { enumerable: true, get: function () { return wots_js_1.wotsPkFromSig; } });
47
+ Object.defineProperty(exports, "legacyWotsVerify", { enumerable: true, get: function () { return wots_js_1.wotsVerify; } });
48
+ Object.defineProperty(exports, "legacyWotsVerifyDigest", { enumerable: true, get: function () { return wots_js_1.wotsVerifyDigest; } });
49
+ Object.defineProperty(exports, "legacyWotsPublicKeyFromSeed", { enumerable: true, get: function () { return wots_js_1.wotsPublicKeyFromSeed; } });
50
+ // TreeKey — unique exports
51
+ var treekey_js_1 = require("./treekey.js");
52
+ Object.defineProperty(exports, "TreeKey", { enumerable: true, get: function () { return treekey_js_1.TreeKey; } });
53
+ Object.defineProperty(exports, "TreeKeyNode", { enumerable: true, get: function () { return treekey_js_1.TreeKeyNode; } });
54
+ Object.defineProperty(exports, "legacyVerifyTreeSignature", { enumerable: true, get: function () { return treekey_js_1.verifyTreeSignature; } });
55
+ Object.defineProperty(exports, "serializeTreeSignature", { enumerable: true, get: function () { return treekey_js_1.serializeTreeSignature; } });
56
+ Object.defineProperty(exports, "deserializeTreeSignature", { enumerable: true, get: function () { return treekey_js_1.deserializeTreeSignature; } });
57
+ Object.defineProperty(exports, "getRootPublicKey", { enumerable: true, get: function () { return treekey_js_1.getRootPublicKey; } });
58
+ Object.defineProperty(exports, "DEFAULT_KEYS_PER_LEVEL", { enumerable: true, get: function () { return treekey_js_1.DEFAULT_KEYS_PER_LEVEL; } });
59
+ Object.defineProperty(exports, "DEFAULT_LEVELS", { enumerable: true, get: function () { return treekey_js_1.DEFAULT_LEVELS; } });
60
+ Object.defineProperty(exports, "legacyCreateUnifiedChildTreeKey", { enumerable: true, get: function () { return treekey_js_1.createUnifiedChildTreeKey; } });
61
+ Object.defineProperty(exports, "createUnifiedChildTreeKeyAsync", { enumerable: true, get: function () { return treekey_js_1.createUnifiedChildTreeKeyAsync; } });
62
+ Object.defineProperty(exports, "legacyCreateUnifiedRootTreeKey", { enumerable: true, get: function () { return treekey_js_1.createUnifiedRootTreeKey; } });
63
+ Object.defineProperty(exports, "legacyDeriveUnifiedAddressPublicKey", { enumerable: true, get: function () { return treekey_js_1.deriveUnifiedAddressPublicKey; } });
64
+ Object.defineProperty(exports, "createPerAddressTreeKey", { enumerable: true, get: function () { return treekey_js_1.createPerAddressTreeKey; } });
65
+ Object.defineProperty(exports, "createPerAddressTreeKeyAsync", { enumerable: true, get: function () { return treekey_js_1.createPerAddressTreeKeyAsync; } });
66
+ // MMR — unique exports
67
+ var mmr_js_1 = require("./mmr.js");
68
+ Object.defineProperty(exports, "MMRTree", { enumerable: true, get: function () { return mmr_js_1.MMRTree; } });
69
+ Object.defineProperty(exports, "mmrLeafExact", { enumerable: true, get: function () { return mmr_js_1.mmrLeafExact; } });
70
+ Object.defineProperty(exports, "mmrRootFromSingleLeaf", { enumerable: true, get: function () { return mmr_js_1.mmrRootFromSingleLeaf; } });
71
+ Object.defineProperty(exports, "createMMRDataLeafNode", { enumerable: true, get: function () { return mmr_js_1.createMMRDataLeafNode; } });
72
+ Object.defineProperty(exports, "createMMRDataParentNode", { enumerable: true, get: function () { return mmr_js_1.createMMRDataParentNode; } });
73
+ Object.defineProperty(exports, "calculateProofRoot", { enumerable: true, get: function () { return mmr_js_1.calculateProofRoot; } });
74
+ Object.defineProperty(exports, "legacyVerifyMMRProof", { enumerable: true, get: function () { return mmr_js_1.verifyMMRProof; } });
75
+ Object.defineProperty(exports, "parseMMRProofFromHex", { enumerable: true, get: function () { return mmr_js_1.parseMMRProofFromHex; } });
76
+ Object.defineProperty(exports, "deserializeMMRProof", { enumerable: true, get: function () { return mmr_js_1.deserializeMMRProof; } });
77
+ Object.defineProperty(exports, "serializeMMRProof", { enumerable: true, get: function () { return mmr_js_1.serializeMMRProof; } });
78
+ Object.defineProperty(exports, "serializeRealMMRProof", { enumerable: true, get: function () { return mmr_js_1.serializeRealMMRProof; } });
79
+ // BIP39
80
+ var bip39_js_1 = require("./bip39.js");
81
+ Object.defineProperty(exports, "WORD_LIST", { enumerable: true, get: function () { return bip39_js_1.WORD_LIST; } });
82
+ Object.defineProperty(exports, "legacyCleanSeedPhrase", { enumerable: true, get: function () { return bip39_js_1.cleanSeedPhrase; } });
83
+ Object.defineProperty(exports, "legacyValidatePhrase", { enumerable: true, get: function () { return bip39_js_1.validatePhrase; } });
84
+ Object.defineProperty(exports, "convertStringToSeed", { enumerable: true, get: function () { return bip39_js_1.convertStringToSeed; } });
85
+ Object.defineProperty(exports, "convertWordListToSeed", { enumerable: true, get: function () { return bip39_js_1.convertWordListToSeed; } });
86
+ Object.defineProperty(exports, "legacyPhraseToSeed", { enumerable: true, get: function () { return bip39_js_1.phraseToSeed; } });
87
+ Object.defineProperty(exports, "legacyGenerateWordList", { enumerable: true, get: function () { return bip39_js_1.generateWordList; } });
88
+ Object.defineProperty(exports, "generateSeedPhrase", { enumerable: true, get: function () { return bip39_js_1.generateSeedPhrase; } });
89
+ // Transaction
90
+ var transaction_js_1 = require("./transaction.js");
91
+ Object.defineProperty(exports, "parseDecimalToMiniNumber", { enumerable: true, get: function () { return transaction_js_1.parseDecimalToMiniNumber; } });
92
+ Object.defineProperty(exports, "serializeCoin", { enumerable: true, get: function () { return transaction_js_1.serializeCoin; } });
93
+ Object.defineProperty(exports, "legacySerializeTransaction", { enumerable: true, get: function () { return transaction_js_1.serializeTransaction; } });
94
+ Object.defineProperty(exports, "legacyComputeTransactionDigest", { enumerable: true, get: function () { return transaction_js_1.computeTransactionDigest; } });
95
+ Object.defineProperty(exports, "legacyPrecomputeTransactionCoinID", { enumerable: true, get: function () { return transaction_js_1.precomputeTransactionCoinID; } });
96
+ Object.defineProperty(exports, "createDefaultTransaction", { enumerable: true, get: function () { return transaction_js_1.createDefaultTransaction; } });
97
+ Object.defineProperty(exports, "buildMinimaCoin", { enumerable: true, get: function () { return transaction_js_1.buildMinimaCoin; } });
98
+ // Derive
99
+ var derive_js_1 = require("./derive.js");
100
+ Object.defineProperty(exports, "scriptToAddress", { enumerable: true, get: function () { return derive_js_1.scriptToAddress; } });
101
+ Object.defineProperty(exports, "addressToRoot", { enumerable: true, get: function () { return derive_js_1.addressToRoot; } });
102
+ // Script
103
+ var script_js_1 = require("./script.js");
104
+ Object.defineProperty(exports, "scriptFromWotsPk", { enumerable: true, get: function () { return script_js_1.scriptFromWotsPk; } });
105
+ Object.defineProperty(exports, "legacyWotsAddressFromKeypair", { enumerable: true, get: function () { return script_js_1.wotsAddressFromKeypair; } });
106
+ // Minima32
107
+ var minima32_js_1 = require("./minima32.js");
108
+ Object.defineProperty(exports, "encodeMxRadix32Frame", { enumerable: true, get: function () { return minima32_js_1.encodeMxRadix32Frame; } });
109
+ Object.defineProperty(exports, "decodeMxRadix32Frame", { enumerable: true, get: function () { return minima32_js_1.decodeMxRadix32Frame; } });
110
+ Object.defineProperty(exports, "legacyMakeMxAddress", { enumerable: true, get: function () { return minima32_js_1.makeMxAddress; } });
111
+ Object.defineProperty(exports, "legacyParseMxAddress", { enumerable: true, get: function () { return minima32_js_1.parseMxAddress; } });
112
+ Object.defineProperty(exports, "hexToMx", { enumerable: true, get: function () { return minima32_js_1.hexToMx; } });
113
+ Object.defineProperty(exports, "mxToHex", { enumerable: true, get: function () { return minima32_js_1.mxToHex; } });
114
+ Object.defineProperty(exports, "encodeMx", { enumerable: true, get: function () { return minima32_js_1.encodeMx; } });
115
+ Object.defineProperty(exports, "decodeMx", { enumerable: true, get: function () { return minima32_js_1.decodeMx; } });
116
+ Object.defineProperty(exports, "makeMinimaAddress", { enumerable: true, get: function () { return minima32_js_1.makeMinimaAddress; } });
117
+ Object.defineProperty(exports, "convertMinimaAddress", { enumerable: true, get: function () { return minima32_js_1.convertMinimaAddress; } });
118
+ // Streamable
119
+ var Streamable_js_1 = require("./Streamable.js");
120
+ Object.defineProperty(exports, "legacyWriteMiniNumber", { enumerable: true, get: function () { return Streamable_js_1.writeMiniNumber; } });
121
+ Object.defineProperty(exports, "legacyWriteMiniData", { enumerable: true, get: function () { return Streamable_js_1.writeMiniData; } });
122
+ Object.defineProperty(exports, "writeMiniByte", { enumerable: true, get: function () { return Streamable_js_1.writeMiniByte; } });
123
+ Object.defineProperty(exports, "writeMMREntryNumber", { enumerable: true, get: function () { return Streamable_js_1.writeMMREntryNumber; } });
124
+ Object.defineProperty(exports, "concat", { enumerable: true, get: function () { return Streamable_js_1.concat; } });
125
+ Object.defineProperty(exports, "legacyHexToBytes", { enumerable: true, get: function () { return Streamable_js_1.hexToBytes; } });
126
+ Object.defineProperty(exports, "legacyBytesToHex", { enumerable: true, get: function () { return Streamable_js_1.bytesToHex; } });
127
+ Object.defineProperty(exports, "bigIntToByteArray", { enumerable: true, get: function () { return Streamable_js_1.bigIntToByteArray; } });
128
+ Object.defineProperty(exports, "legacyWriteMiniString", { enumerable: true, get: function () { return Streamable_js_1.writeMiniString; } });
129
+ Object.defineProperty(exports, "writeHashToStream", { enumerable: true, get: function () { return Streamable_js_1.writeHashToStream; } });
130
+ // JavaStreamables
131
+ var javaStreamables_js_1 = require("./javaStreamables.js");
132
+ Object.defineProperty(exports, "serializeMiniNumber", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMiniNumber; } });
133
+ Object.defineProperty(exports, "serializeMiniData", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMiniData; } });
134
+ Object.defineProperty(exports, "hashAllObjects", { enumerable: true, get: function () { return javaStreamables_js_1.hashAllObjects; } });
135
+ Object.defineProperty(exports, "legacyDeriveChainSeedJava", { enumerable: true, get: function () { return javaStreamables_js_1.deriveChainSeedJava; } });
136
+ Object.defineProperty(exports, "deriveChildTreeSeedJava", { enumerable: true, get: function () { return javaStreamables_js_1.deriveChildTreeSeedJava; } });
137
+ Object.defineProperty(exports, "hashObject", { enumerable: true, get: function () { return javaStreamables_js_1.hashObject; } });
138
+ Object.defineProperty(exports, "serializeMiniNumberZERO", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMiniNumberZERO; } });
139
+ Object.defineProperty(exports, "serializeMiniNumberONE", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMiniNumberONE; } });
140
+ Object.defineProperty(exports, "javaHashAllObjects", { enumerable: true, get: function () { return javaStreamables_js_1.javaHashAllObjects; } });
141
+ Object.defineProperty(exports, "indexToMiniDataBytes", { enumerable: true, get: function () { return javaStreamables_js_1.indexToMiniDataBytes; } });
142
+ Object.defineProperty(exports, "legacyDerivePerAddressSeed", { enumerable: true, get: function () { return javaStreamables_js_1.derivePerAddressSeed; } });
143
+ Object.defineProperty(exports, "legacyDeriveRootPrivSeed", { enumerable: true, get: function () { return javaStreamables_js_1.deriveRootPrivSeed; } });
144
+ Object.defineProperty(exports, "deriveUnifiedChildSeed", { enumerable: true, get: function () { return javaStreamables_js_1.deriveUnifiedChildSeed; } });
145
+ Object.defineProperty(exports, "createMMREntryNumber", { enumerable: true, get: function () { return javaStreamables_js_1.createMMREntryNumber; } });
146
+ Object.defineProperty(exports, "serializeMMREntryNumber", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMMREntryNumber; } });
147
+ Object.defineProperty(exports, "serializeMMRData", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMMRData; } });
148
+ Object.defineProperty(exports, "serializeMMREntry", { enumerable: true, get: function () { return javaStreamables_js_1.serializeMMREntry; } });
149
+ Object.defineProperty(exports, "legacyPrecomputeTransactionCoinIDTx", { enumerable: true, get: function () { return javaStreamables_js_1.precomputeTransactionCoinID; } });
150
+ // Utils
151
+ var utils_js_1 = require("./utils.js");
152
+ Object.defineProperty(exports, "legacyConcatBytes", { enumerable: true, get: function () { return utils_js_1.concatBytes; } });
153
+ // Params
154
+ __exportStar(require("./params.js"), exports);
155
+ // Verify
156
+ var verify_js_1 = require("./verify.js");
157
+ Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return verify_js_1.verifySignature; } });
158
+ Object.defineProperty(exports, "verifySignatureDetailed", { enumerable: true, get: function () { return verify_js_1.verifySignatureDetailed; } });
159
+ Object.defineProperty(exports, "verifyTreeSignatureDetailed", { enumerable: true, get: function () { return verify_js_1.verifyTreeSignatureDetailed; } });
160
+ Object.defineProperty(exports, "deriveAddressFromPublicKey", { enumerable: true, get: function () { return verify_js_1.deriveAddressFromPublicKey; } });
161
+ Object.defineProperty(exports, "normalizeHex", { enumerable: true, get: function () { return verify_js_1.normalizeHex; } });
162
+ Object.defineProperty(exports, "legacyCreateChallenge", { enumerable: true, get: function () { return verify_js_1.createChallenge; } });
163
+ Object.defineProperty(exports, "legacyValidateChallenge", { enumerable: true, get: function () { return verify_js_1.validateChallenge; } });
package/dist/treekey.d.ts CHANGED
@@ -326,58 +326,74 @@ export declare function serializeTreeSignature(sig: TreeSignature): Bytes;
326
326
  export declare function deserializeTreeSignature(data: Bytes): TreeSignature;
327
327
  /**
328
328
  * ============================================================================
329
- * PER-ADDRESS TREEKEY FACTORY
329
+ * UNIFIED TREEKEY FACTORY
330
330
  * ============================================================================
331
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);
332
+ * Single hierarchical derivation scheme:
336
333
  *
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)
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
341
338
  *
342
- * Total wallet capacity: 64 addresses × 4096 signatures = 262,144 signatures
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.
343
345
  * ============================================================================
344
346
  */
345
347
  /**
346
- * Create a per-address TreeKey matching Minima Wallet.createNewKey()
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)
347
352
  *
348
353
  * @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
354
+ * @param index - Address index (0-63)
355
+ * @returns TreeKey for this spend address with size=64, depth=3
351
356
  */
352
- export declare function createPerAddressTreeKey(baseSeed: Bytes, addressIndex: number): TreeKey;
357
+ export declare function createUnifiedChildTreeKey(baseSeed: Bytes, index: number): TreeKey;
353
358
  /**
354
- * Async version with progress reporting for UI
359
+ * Async version with progress reporting for UI.
355
360
  *
356
361
  * @param baseSeed - 32-byte wallet base seed
357
- * @param addressIndex - Address index (0-63)
362
+ * @param index - Address index (0-63)
358
363
  * @param onProgress - Optional progress callback
359
- * @returns Promise resolving to TreeKey for this address
364
+ * @returns Promise resolving to the child TreeKey
360
365
  */
361
- export declare function createPerAddressTreeKeyAsync(baseSeed: Bytes, addressIndex: number, onProgress?: ProgressCallback): Promise<TreeKey>;
366
+ export declare function createUnifiedChildTreeKeyAsync(baseSeed: Bytes, index: number, onProgress?: ProgressCallback): Promise<TreeKey>;
362
367
  /**
363
- * Derive address public key from base seed and address index
368
+ * Create the unified root identity TreeKey (identity anchor, never a spend address).
364
369
  *
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.
370
+ * Derivation: root_priv_seed = deriveRootPrivSeed(baseSeed)
371
+ * treeKey = new TreeKey(root_priv_seed, 64, 3)
368
372
  *
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)
373
+ * @param baseSeed - 32-byte wallet base seed (from mnemonic)
374
+ * @returns Root identity TreeKey with size=64, depth=3
372
375
  */
373
- export declare function deriveAddressPublicKey(baseSeed: Bytes, addressIndex: number): Bytes;
376
+ export declare function createUnifiedRootTreeKey(baseSeed: Bytes): TreeKey;
374
377
  /**
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.
378
+ * Fast path for deriving a child address public key without constructing
379
+ * the full TreeKey. Useful during wallet initialisation.
379
380
  *
380
- * @param treeKey - Per-address TreeKey
381
- * @returns 32-byte address public key (TreeKey root)
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).
382
393
  */
383
- export declare function getPerAddressPublicKey(treeKey: TreeKey): Bytes;
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>;
package/dist/treekey.js CHANGED
@@ -18,10 +18,12 @@ exports.getRootPublicKey = getRootPublicKey;
18
18
  exports.verifyTreeSignature = verifyTreeSignature;
19
19
  exports.serializeTreeSignature = serializeTreeSignature;
20
20
  exports.deserializeTreeSignature = deserializeTreeSignature;
21
+ exports.createUnifiedChildTreeKey = createUnifiedChildTreeKey;
22
+ exports.createUnifiedChildTreeKeyAsync = createUnifiedChildTreeKeyAsync;
23
+ exports.createUnifiedRootTreeKey = createUnifiedRootTreeKey;
24
+ exports.deriveUnifiedAddressPublicKey = deriveUnifiedAddressPublicKey;
21
25
  exports.createPerAddressTreeKey = createPerAddressTreeKey;
22
26
  exports.createPerAddressTreeKeyAsync = createPerAddressTreeKeyAsync;
23
- exports.deriveAddressPublicKey = deriveAddressPublicKey;
24
- exports.getPerAddressPublicKey = getPerAddressPublicKey;
25
27
  const javaStreamables_js_1 = require("./javaStreamables.js");
26
28
  const wots_js_1 = require("./wots.js");
27
29
  const params_js_1 = require("./params.js");
@@ -706,69 +708,95 @@ function deserializeTreeSignature(data) {
706
708
  }
707
709
  /**
708
710
  * ============================================================================
709
- * PER-ADDRESS TREEKEY FACTORY
711
+ * UNIFIED TREEKEY FACTORY
710
712
  * ============================================================================
711
713
  *
712
- * Minima Wallet.createNewKey() creates independent TreeKeys per address:
713
- * MiniData modifier = new MiniData(new BigInteger(Integer.toString(numkeys)));
714
- * MiniData privseed = Crypto.getInstance().hashObjects(baseSeed, modifier);
715
- * TreeKey treekey = TreeKey.createDefault(privseed);
714
+ * Single hierarchical derivation scheme:
716
715
  *
717
- * Each address gets its own TreeKey with:
718
- * - Unique seed derived from baseSeed + addressIndex
719
- * - Size=64, depth=3 (matching TreeKey.createDefault)
720
- * - 4096 one-time signatures per address (64×64)
716
+ * root_priv_seed = deriveRootPrivSeed(baseSeed)
717
+ * child_seed_i = deriveUnifiedChildSeed(baseSeed, i)
718
+ * child_treekey_i = new TreeKey(child_seed_i, 64, 3) ← spend address i
719
+ * root_treekey = new TreeKey(root_priv_seed, 64, 3) ← identity anchor
721
720
  *
722
- * Total wallet capacity: 64 addresses × 4096 signatures = 262,144 signatures
721
+ * Child seeds are cryptographically descended from root_priv_seed, not siblings.
722
+ * Addresses are Minima-compatible (RETURN SIGNEDBY(pubkey) scripts, WOTS sigs).
723
+ * The root TreeKey is NEVER used as a spend address.
724
+ *
725
+ * Signature capacity: 64 addresses × 4 096 signatures each = 262 144 total.
726
+ * Root identity capacity: 4 096 attestation signatures.
723
727
  * ============================================================================
724
728
  */
725
729
  /**
726
- * Create a per-address TreeKey matching Minima Wallet.createNewKey()
730
+ * Create the unified child TreeKey for spend address at `index`.
731
+ *
732
+ * Derivation: child_seed_i = deriveUnifiedChildSeed(baseSeed, i)
733
+ * treeKey = new TreeKey(child_seed_i, 64, 3)
727
734
  *
728
735
  * @param baseSeed - 32-byte wallet base seed (from mnemonic)
729
- * @param addressIndex - Address index (0-63)
730
- * @returns TreeKey for this address with size=64, depth=3
736
+ * @param index - Address index (0-63)
737
+ * @returns TreeKey for this spend address with size=64, depth=3
731
738
  */
732
- function createPerAddressTreeKey(baseSeed, addressIndex) {
733
- const addressSeed = (0, javaStreamables_js_1.derivePerAddressSeed)(baseSeed, addressIndex);
734
- return new TreeKey(addressSeed, 64, 3);
739
+ function createUnifiedChildTreeKey(baseSeed, index) {
740
+ const childSeed = (0, javaStreamables_js_1.deriveUnifiedChildSeed)(baseSeed, index);
741
+ return new TreeKey(childSeed, 64, 3);
735
742
  }
736
743
  /**
737
- * Async version with progress reporting for UI
744
+ * Async version with progress reporting for UI.
738
745
  *
739
746
  * @param baseSeed - 32-byte wallet base seed
740
- * @param addressIndex - Address index (0-63)
747
+ * @param index - Address index (0-63)
741
748
  * @param onProgress - Optional progress callback
742
- * @returns Promise resolving to TreeKey for this address
749
+ * @returns Promise resolving to the child TreeKey
743
750
  */
744
- async function createPerAddressTreeKeyAsync(baseSeed, addressIndex, onProgress) {
745
- const addressSeed = (0, javaStreamables_js_1.derivePerAddressSeed)(baseSeed, addressIndex);
746
- return TreeKey.createWithProgress(addressSeed, 64, 3, onProgress);
751
+ async function createUnifiedChildTreeKeyAsync(baseSeed, index, onProgress) {
752
+ const childSeed = (0, javaStreamables_js_1.deriveUnifiedChildSeed)(baseSeed, index);
753
+ return TreeKey.createWithProgress(childSeed, 64, 3, onProgress);
747
754
  }
748
755
  /**
749
- * Derive address public key from base seed and address index
756
+ * Create the unified root identity TreeKey (identity anchor, never a spend address).
750
757
  *
751
- * This is the fast path for getting an address public key without
752
- * needing to construct the full TreeKey. Useful for address derivation
753
- * during wallet initialization.
758
+ * Derivation: root_priv_seed = deriveRootPrivSeed(baseSeed)
759
+ * treeKey = new TreeKey(root_priv_seed, 64, 3)
754
760
  *
755
- * @param baseSeed - 32-byte wallet base seed
756
- * @param addressIndex - Address index (0-63)
757
- * @returns 32-byte address public key (MMR root of per-address TreeKey)
761
+ * @param baseSeed - 32-byte wallet base seed (from mnemonic)
762
+ * @returns Root identity TreeKey with size=64, depth=3
758
763
  */
759
- function deriveAddressPublicKey(baseSeed, addressIndex) {
760
- const treeKey = createPerAddressTreeKey(baseSeed, addressIndex);
761
- return treeKey.getPublicKey();
764
+ function createUnifiedRootTreeKey(baseSeed) {
765
+ const rootPrivSeed = (0, javaStreamables_js_1.deriveRootPrivSeed)(baseSeed);
766
+ return new TreeKey(rootPrivSeed, 64, 3);
762
767
  }
763
768
  /**
764
- * Get the address public key from a per-address TreeKey
769
+ * Fast path for deriving a child address public key without constructing
770
+ * the full TreeKey. Useful during wallet initialisation.
765
771
  *
766
- * In the per-address architecture, each address has its own TreeKey,
767
- * and the address public key is simply the TreeKey's root public key.
768
- *
769
- * @param treeKey - Per-address TreeKey
770
- * @returns 32-byte address public key (TreeKey root)
772
+ * @param baseSeed - 32-byte wallet base seed
773
+ * @param index - Address index (0-63)
774
+ * @returns 32-byte address public key (MMR root of child TreeKey)
771
775
  */
772
- function getPerAddressPublicKey(treeKey) {
773
- return treeKey.getPublicKey();
776
+ function deriveUnifiedAddressPublicKey(baseSeed, index) {
777
+ return createUnifiedChildTreeKey(baseSeed, index).getPublicKey();
778
+ }
779
+ // ---------------------------------------------------------------------------
780
+ // Deprecated aliases — kept for migration compatibility only.
781
+ // Downstream consumers should migrate to createUnifiedChildTreeKey.
782
+ // ---------------------------------------------------------------------------
783
+ /**
784
+ * @deprecated Use {@link createUnifiedChildTreeKey} instead.
785
+ * This wrapper preserves the LEGACY per-address seed derivation
786
+ * (`SHA3-256(baseSeed ‖ indexBytes(i))`) so that existing callers
787
+ * that import this symbol by name continue to derive the same keys.
788
+ * New code must use createUnifiedChildTreeKey which applies the unified
789
+ * two-step derivation (root_priv_seed → child_seed_i).
790
+ */
791
+ function createPerAddressTreeKey(baseSeed, addressIndex) {
792
+ const perAddressSeed = (0, javaStreamables_js_1.derivePerAddressSeed)(baseSeed instanceof Uint8Array ? baseSeed : new Uint8Array(baseSeed), addressIndex);
793
+ return new TreeKey(perAddressSeed, 64, 3);
794
+ }
795
+ /**
796
+ * @deprecated Use {@link createUnifiedChildTreeKeyAsync} instead.
797
+ * Preserves legacy per-address seed derivation for backward compatibility.
798
+ */
799
+ async function createPerAddressTreeKeyAsync(baseSeed, addressIndex, onProgress) {
800
+ const perAddressSeed = (0, javaStreamables_js_1.derivePerAddressSeed)(baseSeed instanceof Uint8Array ? baseSeed : new Uint8Array(baseSeed), addressIndex);
801
+ return TreeKey.createWithProgress(perAddressSeed, 64, 3, onProgress);
774
802
  }
@@ -41,8 +41,6 @@ class TransactionService {
41
41
  burn: params.burn || null,
42
42
  paramSet: this.config.paramSet || 'v2-spec',
43
43
  addressIndex: params.addressIndex,
44
- walletMode: params.walletMode || 'AnonTree',
45
- perAddressPublicKey: params.perAddressPublicKey ?? null,
46
44
  }, {
47
45
  headers: {
48
46
  'Content-Type': 'application/json',
@@ -106,9 +104,9 @@ class TransactionService {
106
104
  if (digestBytes.length !== 32) {
107
105
  throw new Error(`Invalid digest length: ${digestBytes.length}, expected 32 bytes`);
108
106
  }
109
- // Derive per-address TreeKey matching Minima Wallet.java
110
- this.logger.debug(` Deriving per-address TreeKey for index ${addressIndex}...`);
111
- const treeKey = (0, treekey_js_1.createPerAddressTreeKey)(seed, addressIndex);
107
+ // Derive unified child TreeKey for this address index
108
+ this.logger.debug(` Deriving unified child TreeKey for index ${addressIndex}...`);
109
+ const treeKey = (0, treekey_js_1.createUnifiedChildTreeKey)(seed, addressIndex);
112
110
  // Convert (l1, l2) to Java-compatible 'uses' counter
113
111
  // Java's TreeKey.sign() uses baseConversion(uses) to compute path
114
112
  const KEYS_PER_LEVEL = 64;
@@ -14,8 +14,6 @@ export interface PrepareRequest {
14
14
  burn?: string;
15
15
  txId?: string;
16
16
  addressIndex?: number;
17
- walletMode?: 'AnonTree' | 'RootTree';
18
- perAddressPublicKey?: string;
19
17
  }
20
18
  export interface PrepareResponse {
21
19
  addressIndex: number;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * WASM Bridge — thin TypeScript wrappers around @totemsdk/core-wasm.
3
+ *
4
+ * This module provides the same public API as the legacy JS implementations
5
+ * but delegates to Rust/WASM for all cryptographic operations.
6
+ *
7
+ * The legacy JS implementations remain available via:
8
+ * import { ... } from '@totemsdk/core/legacy';
9
+ */
10
+ import type { WotsKeypair } from '../types.js';
11
+ export declare function getParams(): Promise<{
12
+ w: number;
13
+ n: number;
14
+ L: number;
15
+ maxDigit: number;
16
+ maxSignatures: number;
17
+ signatureLevels: number;
18
+ addressPrefix: string;
19
+ }>;
20
+ export declare function sha3_256(data: Uint8Array): Promise<Uint8Array>;
21
+ export declare function expandPrivateKey(seed: Uint8Array): Promise<Uint8Array[]>;
22
+ export declare function hashChain(x: Uint8Array, rounds: number): Promise<Uint8Array>;
23
+ export declare function derivePKdigest(seed: Uint8Array, keyIndex: number): Promise<Uint8Array>;
24
+ export declare function deriveFullPublicKey(seed: Uint8Array, keyIndex: number): Promise<Uint8Array>;
25
+ export declare function wotsSign(seed: Uint8Array, keyIndex: number, message: Uint8Array): Promise<Uint8Array>;
26
+ export declare function wotsVerify(sig: Uint8Array, message: Uint8Array, pkFull: Uint8Array): Promise<boolean>;
27
+ export declare function wotsVerifyDigest(sig: Uint8Array, message: Uint8Array, pkDigest: Uint8Array): Promise<boolean>;
28
+ export declare function wotsPkFromSig(message: Uint8Array, signature: Uint8Array): Promise<Uint8Array>;
29
+ export declare function wotsPublicKeyFromSeed(seed: Uint8Array, keyIndex?: number): Promise<Uint8Array>;
30
+ export declare function wotsKeypairFromSeed(seed: Uint8Array, index: number): Promise<WotsKeypair>;
31
+ export declare function deriveChainSeedJava(seed: Uint8Array, keyIndex: number): Promise<Uint8Array>;
32
+ export declare function derivePerAddressSeed(rootSeed: Uint8Array, addressIndex: number): Promise<Uint8Array>;
33
+ export declare function deriveRootPrivSeed(bip39Seed: Uint8Array): Promise<Uint8Array>;
34
+ export declare function phraseToSeed(phrase: string): Promise<Uint8Array>;
35
+ export declare function generateWordList(): Promise<string>;
36
+ export declare function validatePhrase(phrase: string): Promise<boolean>;
37
+ export declare function cleanSeedPhrase(phrase: string): Promise<string>;
38
+ export declare function makeMxAddress(root32: Uint8Array): Promise<string>;
39
+ export declare function parseMxAddress(address: string): Promise<Uint8Array>;
40
+ export declare function wotsAddressFromKeypair(seed: Uint8Array, keyIndex: number): Promise<string>;
41
+ export declare function serializeTransaction(tx: any): Promise<Uint8Array>;
42
+ export declare function computeTransactionDigest(serializedTx: Uint8Array): Promise<Uint8Array>;
43
+ export declare function precomputeTransactionCoinID(txid: Uint8Array, outputIndex: number): Promise<Uint8Array>;
44
+ export declare function verifyTreeSignature(rootPublicKey: Uint8Array, message: Uint8Array, signature: any): Promise<boolean>;
45
+ export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): Promise<boolean>;
46
+ export declare function createChallenge(domain: string, statement: string): Promise<string>;
47
+ export declare function validateChallenge(challengeJson: string, domain: string): Promise<boolean>;
48
+ export declare function writeMiniNumber(value: number, scale?: number): Promise<Uint8Array>;
49
+ export declare function writeMiniData(data: Uint8Array): Promise<Uint8Array>;
50
+ export declare function writeMiniString(s: string): Promise<Uint8Array>;
51
+ export declare function bytesToHex(bytes: Uint8Array): Promise<string>;
52
+ export declare function hexToBytes(hexStr: string): Promise<Uint8Array>;
53
+ export declare function concatBytes(...arrays: Uint8Array[]): Promise<Uint8Array>;
54
+ export { getParams as getParamSet } from './wasm-bridge.js';