@hardkas/toolkit 0.11.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/LICENSE +21 -0
  3. package/dist/dag/consensus.d.ts +20 -0
  4. package/dist/dag/consensus.d.ts.map +1 -0
  5. package/dist/dag/consensus.js +131 -0
  6. package/dist/dag/consensus.js.map +1 -0
  7. package/dist/dag/index.d.ts +28 -0
  8. package/dist/dag/index.d.ts.map +1 -0
  9. package/dist/dag/index.js +57 -0
  10. package/dist/dag/index.js.map +1 -0
  11. package/dist/dag/store.d.ts +11 -0
  12. package/dist/dag/store.d.ts.map +1 -0
  13. package/dist/dag/store.js +32 -0
  14. package/dist/dag/store.js.map +1 -0
  15. package/dist/dag/topology.d.ts +14 -0
  16. package/dist/dag/topology.d.ts.map +1 -0
  17. package/dist/dag/topology.js +98 -0
  18. package/dist/dag/topology.js.map +1 -0
  19. package/dist/dag/types.d.ts +21 -0
  20. package/dist/dag/types.d.ts.map +1 -0
  21. package/dist/dag/types.js +2 -0
  22. package/dist/dag/types.js.map +1 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +10 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/indexer.d.ts +34 -0
  28. package/dist/indexer.d.ts.map +1 -0
  29. package/dist/indexer.js +111 -0
  30. package/dist/indexer.js.map +1 -0
  31. package/dist/jobs.d.ts +18 -0
  32. package/dist/jobs.d.ts.map +1 -0
  33. package/dist/jobs.js +33 -0
  34. package/dist/jobs.js.map +1 -0
  35. package/dist/payment.d.ts +25 -0
  36. package/dist/payment.d.ts.map +1 -0
  37. package/dist/payment.js +66 -0
  38. package/dist/payment.js.map +1 -0
  39. package/dist/silver/index.d.ts +20 -0
  40. package/dist/silver/index.d.ts.map +1 -0
  41. package/dist/silver/index.js +94 -0
  42. package/dist/silver/index.js.map +1 -0
  43. package/dist/silver/templates.d.ts +2 -0
  44. package/dist/silver/templates.d.ts.map +1 -0
  45. package/dist/silver/templates.js +28 -0
  46. package/dist/silver/templates.js.map +1 -0
  47. package/dist/silver/types.d.ts +34 -0
  48. package/dist/silver/types.d.ts.map +1 -0
  49. package/dist/silver/types.js +2 -0
  50. package/dist/silver/types.js.map +1 -0
  51. package/dist/snapshot/backends/FsSnapshotBackend.d.ts +14 -0
  52. package/dist/snapshot/backends/FsSnapshotBackend.d.ts.map +1 -0
  53. package/dist/snapshot/backends/FsSnapshotBackend.js +82 -0
  54. package/dist/snapshot/backends/FsSnapshotBackend.js.map +1 -0
  55. package/dist/snapshot/backends/MemorySnapshotBackend.d.ts +13 -0
  56. package/dist/snapshot/backends/MemorySnapshotBackend.d.ts.map +1 -0
  57. package/dist/snapshot/backends/MemorySnapshotBackend.js +55 -0
  58. package/dist/snapshot/backends/MemorySnapshotBackend.js.map +1 -0
  59. package/dist/snapshot/index.d.ts +19 -0
  60. package/dist/snapshot/index.d.ts.map +1 -0
  61. package/dist/snapshot/index.js +84 -0
  62. package/dist/snapshot/index.js.map +1 -0
  63. package/dist/snapshot/serialization.d.ts +18 -0
  64. package/dist/snapshot/serialization.d.ts.map +1 -0
  65. package/dist/snapshot/serialization.js +31 -0
  66. package/dist/snapshot/serialization.js.map +1 -0
  67. package/dist/snapshot/types.d.ts +44 -0
  68. package/dist/snapshot/types.d.ts.map +1 -0
  69. package/dist/snapshot/types.js +2 -0
  70. package/dist/snapshot/types.js.map +1 -0
  71. package/dist/stores/invoice-store.d.ts +26 -0
  72. package/dist/stores/invoice-store.d.ts.map +1 -0
  73. package/dist/stores/invoice-store.js +34 -0
  74. package/dist/stores/invoice-store.js.map +1 -0
  75. package/dist/stores/utxo-control-store.d.ts +23 -0
  76. package/dist/stores/utxo-control-store.d.ts.map +1 -0
  77. package/dist/stores/utxo-control-store.js +64 -0
  78. package/dist/stores/utxo-control-store.js.map +1 -0
  79. package/dist/utxos.d.ts +128 -0
  80. package/dist/utxos.d.ts.map +1 -0
  81. package/dist/utxos.js +331 -0
  82. package/dist/utxos.js.map +1 -0
  83. package/dist/wallet.d.ts +34 -0
  84. package/dist/wallet.d.ts.map +1 -0
  85. package/dist/wallet.js +72 -0
  86. package/dist/wallet.js.map +1 -0
  87. package/package.json +28 -0
  88. package/src/dag/consensus.ts +150 -0
  89. package/src/dag/index.ts +73 -0
  90. package/src/dag/store.ts +40 -0
  91. package/src/dag/topology.ts +108 -0
  92. package/src/dag/types.ts +20 -0
  93. package/src/index.ts +9 -0
  94. package/src/indexer.ts +128 -0
  95. package/src/jobs.ts +46 -0
  96. package/src/payment.ts +81 -0
  97. package/src/silver/index.ts +102 -0
  98. package/src/silver/templates.ts +27 -0
  99. package/src/silver/types.ts +37 -0
  100. package/src/snapshot/backends/FsSnapshotBackend.ts +100 -0
  101. package/src/snapshot/backends/MemorySnapshotBackend.ts +65 -0
  102. package/src/snapshot/index.ts +102 -0
  103. package/src/snapshot/serialization.ts +35 -0
  104. package/src/snapshot/types.ts +45 -0
  105. package/src/stores/invoice-store.ts +53 -0
  106. package/src/stores/utxo-control-store.ts +78 -0
  107. package/src/utxos.ts +451 -0
  108. package/src/wallet.ts +93 -0
  109. package/test/silver.test.ts +59 -0
  110. package/test/snapshot.test.ts +99 -0
  111. package/test/toolkit.test.ts +109 -0
  112. package/tsconfig.json +9 -0
  113. package/vitest.config.ts +8 -0
package/dist/utxos.js ADDED
@@ -0,0 +1,331 @@
1
+ export class WalletUtxoApi {
2
+ fetchUtxos;
3
+ address;
4
+ estimateFee;
5
+ store;
6
+ constructor(fetchUtxos, address, estimateFee, store) {
7
+ this.fetchUtxos = fetchUtxos;
8
+ this.address = address;
9
+ this.estimateFee = estimateFee;
10
+ this.store = store;
11
+ }
12
+ /**
13
+ * List UTXOs currently available in the wallet.
14
+ * Frozen UTXOs are excluded by default unless includeFrozen: true.
15
+ */
16
+ async list(opts) {
17
+ const all = await this.fetchUtxos();
18
+ const state = this.store.getState();
19
+ if (opts?.includeFrozen) {
20
+ return all;
21
+ }
22
+ return all.filter(u => !state.frozen[u.transactionId] && !state.frozen[`${u.transactionId}:${u.outputIndex}`]);
23
+ }
24
+ /**
25
+ * Return basic statistics about the UTXO set.
26
+ */
27
+ async statistics(opts) {
28
+ const allUtxos = await this.fetchUtxos();
29
+ const state = this.store.getState();
30
+ let totalUtxos = 0;
31
+ let availableUtxos = 0;
32
+ let frozenUtxos = 0;
33
+ let totalValue = 0n;
34
+ let availableValue = 0n;
35
+ let frozenValue = 0n;
36
+ let largest = -1n;
37
+ let smallest = -1n;
38
+ const includeFrozen = opts?.includeFrozen ?? false;
39
+ for (const u of allUtxos) {
40
+ const amt = BigInt(u.amountSompi);
41
+ const isFrozen = !!(state.frozen[u.transactionId] || state.frozen[`${u.transactionId}:${u.outputIndex}`]);
42
+ totalUtxos++;
43
+ totalValue += amt;
44
+ if (isFrozen) {
45
+ frozenUtxos++;
46
+ frozenValue += amt;
47
+ }
48
+ else {
49
+ availableUtxos++;
50
+ availableValue += amt;
51
+ }
52
+ // Largest/smallest only counts what is included
53
+ if (includeFrozen || !isFrozen) {
54
+ if (largest === -1n || amt > largest)
55
+ largest = amt;
56
+ if (smallest === -1n || amt < smallest)
57
+ smallest = amt;
58
+ }
59
+ }
60
+ const countForAvg = includeFrozen ? totalUtxos : availableUtxos;
61
+ const valueForAvg = includeFrozen ? totalValue : availableValue;
62
+ return {
63
+ totalUtxos,
64
+ availableUtxos,
65
+ frozenUtxos,
66
+ totalValue,
67
+ availableValue,
68
+ frozenValue,
69
+ averageValue: countForAvg === 0 ? 0n : valueForAvg / BigInt(countForAvg),
70
+ largest: largest === -1n ? 0n : largest,
71
+ smallest: smallest === -1n ? 0n : smallest,
72
+ includeFrozen
73
+ };
74
+ }
75
+ /**
76
+ * Classify UTXOs into dust and normal based on a threshold.
77
+ * Default threshold: 10 KAS (1_000_000_000 sompi).
78
+ */
79
+ async analyzeDust(opts) {
80
+ const threshold = opts?.thresholdSompi ?? 1000000000n;
81
+ const utxos = await this.list({ includeFrozen: opts?.includeFrozen });
82
+ const dustUtxos = [];
83
+ const normalUtxos = [];
84
+ let totalDustValue = 0n;
85
+ for (const u of utxos) {
86
+ const amt = BigInt(u.amountSompi);
87
+ if (amt < threshold) {
88
+ dustUtxos.push(u);
89
+ totalDustValue += amt;
90
+ }
91
+ else {
92
+ normalUtxos.push(u);
93
+ }
94
+ }
95
+ return {
96
+ dustUtxos,
97
+ normalUtxos,
98
+ totalDustValue,
99
+ dustPercentage: utxos.length > 0 ? dustUtxos.length / utxos.length : 0
100
+ };
101
+ }
102
+ /**
103
+ * High-level diagnostic analysis of the wallet's UTXO health.
104
+ */
105
+ async analyze(opts) {
106
+ const stats = await this.statistics(opts);
107
+ const dust = await this.analyzeDust(opts);
108
+ const fragmentationScore = dust.dustPercentage;
109
+ const actions = [];
110
+ // We base actions on available counts
111
+ const activeUtxoCount = opts?.includeFrozen ? stats.totalUtxos : stats.availableUtxos;
112
+ if (fragmentationScore > 0.5 && activeUtxoCount > 10) {
113
+ actions.push("consolidate");
114
+ }
115
+ else if (dust.dustUtxos.length > 5) {
116
+ actions.push("mergeDust");
117
+ }
118
+ // Simplistic threshold for splitLarge: if there are very few UTXOs but high value
119
+ if (activeUtxoCount < 3 && stats.largest > 10000000000n) {
120
+ actions.push("splitLarge");
121
+ }
122
+ if (actions.length === 0) {
123
+ actions.push("none");
124
+ }
125
+ return {
126
+ utxoCount: activeUtxoCount,
127
+ fragmentationScore,
128
+ dustCount: dust.dustUtxos.length,
129
+ totalValue: opts?.includeFrozen ? stats.totalValue : stats.availableValue,
130
+ recommendedActions: actions
131
+ };
132
+ }
133
+ /**
134
+ * Plan a UTXO management operation without executing it.
135
+ */
136
+ async plan(opts) {
137
+ const utxos = await this.list({ includeFrozen: opts.includeFrozen });
138
+ const myAddress = await this.address();
139
+ if (opts.strategy === "consolidation") {
140
+ // In a real scenario, the CoinSelector would chunk this to respect mass limits.
141
+ // For Phase 1A, we will just select up to 84 (a safe mass limit approximation for Kaspa).
142
+ const MAX_INPUTS = 84;
143
+ // Sort smallest first to consolidate dust
144
+ const sorted = [...utxos].sort((a, b) => (BigInt(a.amountSompi) < BigInt(b.amountSompi) ? -1 : 1));
145
+ const inputs = sorted.slice(0, MAX_INPUTS);
146
+ const estimatedFee = await this.estimateFee(inputs.length, 1);
147
+ const totalInputValue = inputs.reduce((sum, u) => sum + BigInt(u.amountSompi), 0n);
148
+ const warnings = [];
149
+ if (inputs.length < 2) {
150
+ warnings.push("Not enough UTXOs to consolidate.");
151
+ }
152
+ if (totalInputValue <= estimatedFee) {
153
+ warnings.push("Consolidation fee exceeds the value of the selected UTXOs.");
154
+ }
155
+ // If we spent these 84 UTXOs individually in the future, we would pay for 1 input each time.
156
+ // 84 txs with 1 input vs 1 tx with 84 inputs.
157
+ // This is a naive calculation for "estimated savings".
158
+ const individualFee = await this.estimateFee(1, 2);
159
+ const estimatedSavings = (individualFee * BigInt(inputs.length)) - estimatedFee;
160
+ return {
161
+ strategy: opts.strategy,
162
+ inputs,
163
+ outputs: [{ address: myAddress, amount: totalInputValue - estimatedFee }],
164
+ estimatedFee,
165
+ estimatedSavings: estimatedSavings > 0n ? estimatedSavings : 0n,
166
+ warnings
167
+ };
168
+ }
169
+ throw new Error(`Strategy '${opts.strategy}' not fully implemented yet.`);
170
+ }
171
+ /**
172
+ * Convenience alias for planning a consolidation.
173
+ */
174
+ async consolidate(opts) {
175
+ return this.plan({ strategy: "consolidation", includeFrozen: opts?.includeFrozen });
176
+ }
177
+ _assertNotFrozen(utxoId, includeFrozen) {
178
+ if (!includeFrozen && this.store.getState().frozen[utxoId]) {
179
+ throw new Error(`UTXO ${utxoId} is frozen and cannot be planned for execution`);
180
+ }
181
+ }
182
+ /**
183
+ * Plans the splitting of a specific large UTXO.
184
+ * Supports symmetric splits (intoCount) OR asymmetric splits (outputs).
185
+ */
186
+ async splitPlan(opts) {
187
+ this._assertNotFrozen(opts.utxoId, opts.includeFrozen);
188
+ const utxos = await this.list({ includeFrozen: opts.includeFrozen });
189
+ const targetUtxo = utxos.find(u => u.transactionId === opts.utxoId || `${u.transactionId}:${u.outputIndex}` === opts.utxoId);
190
+ if (!targetUtxo) {
191
+ throw new Error(`UTXO ${opts.utxoId} not found in wallet.`);
192
+ }
193
+ const myAddress = await this.address();
194
+ const warnings = [];
195
+ const planOutputs = [];
196
+ const targetAmount = BigInt(targetUtxo.amountSompi);
197
+ let outputCount = 0;
198
+ if (opts.intoCount !== undefined && opts.outputs === undefined) {
199
+ outputCount = opts.intoCount;
200
+ if (outputCount < 2)
201
+ throw new Error("splitPlan requires intoCount >= 2.");
202
+ const estimatedFee = await this.estimateFee(1, outputCount);
203
+ const remainingAmount = targetAmount - estimatedFee;
204
+ if (remainingAmount <= 0n) {
205
+ throw new Error("Target UTXO does not have enough funds to cover the split and fees.");
206
+ }
207
+ const chunkAmount = remainingAmount / BigInt(outputCount);
208
+ for (let i = 0; i < outputCount; i++) {
209
+ planOutputs.push({ address: myAddress, amount: chunkAmount });
210
+ }
211
+ }
212
+ else if (opts.outputs !== undefined && opts.intoCount === undefined) {
213
+ outputCount = opts.outputs.length;
214
+ if (outputCount < 2)
215
+ throw new Error("splitPlan requires outputs.length >= 2.");
216
+ const estimatedFee = await this.estimateFee(1, outputCount + 1); // +1 for change
217
+ let sumOutputs = 0n;
218
+ for (const out of opts.outputs) {
219
+ sumOutputs += out.amountSompi;
220
+ planOutputs.push({ address: myAddress, amount: out.amountSompi });
221
+ }
222
+ const changeAmount = targetAmount - sumOutputs - estimatedFee;
223
+ if (changeAmount < 0n) {
224
+ throw new Error("Target UTXO does not have enough funds to cover the requested outputs and fees.");
225
+ }
226
+ if (changeAmount > 0n) {
227
+ // Add change output
228
+ planOutputs.push({ address: myAddress, amount: changeAmount });
229
+ }
230
+ }
231
+ else {
232
+ throw new Error("splitPlan requires exactly one of 'intoCount' or 'outputs' to be defined.");
233
+ }
234
+ const estimatedFee = await this.estimateFee(1, planOutputs.length);
235
+ return {
236
+ strategy: "split",
237
+ inputs: [targetUtxo],
238
+ outputs: planOutputs,
239
+ estimatedFee,
240
+ estimatedSavings: 0n,
241
+ warnings
242
+ };
243
+ }
244
+ /**
245
+ * Plans the explicit merging of specific UTXOs.
246
+ */
247
+ async mergePlan(opts) {
248
+ for (const id of opts.utxoIds) {
249
+ this._assertNotFrozen(id, opts.includeFrozen);
250
+ }
251
+ const utxos = await this.list({ includeFrozen: opts.includeFrozen });
252
+ const inputs = [];
253
+ for (const id of opts.utxoIds) {
254
+ const u = utxos.find(utxo => utxo.transactionId === id || `${utxo.transactionId}:${utxo.outputIndex}` === id);
255
+ if (!u) {
256
+ throw new Error(`UTXO ${id} not found in wallet.`);
257
+ }
258
+ inputs.push(u);
259
+ }
260
+ if (inputs.length < 2) {
261
+ throw new Error("mergePlan requires at least 2 UTXOs to merge.");
262
+ }
263
+ const estimatedFee = await this.estimateFee(inputs.length, 1);
264
+ const totalInputValue = inputs.reduce((sum, u) => sum + BigInt(u.amountSompi), 0n);
265
+ const myAddress = await this.address();
266
+ const warnings = [];
267
+ if (totalInputValue <= estimatedFee) {
268
+ warnings.push("Merge fee exceeds the value of the selected UTXOs.");
269
+ }
270
+ const individualFee = await this.estimateFee(1, 2);
271
+ const estimatedSavings = (individualFee * BigInt(inputs.length)) - estimatedFee;
272
+ return {
273
+ strategy: "merge",
274
+ inputs,
275
+ outputs: [{ address: myAddress, amount: totalInputValue > estimatedFee ? totalInputValue - estimatedFee : 0n }],
276
+ estimatedFee,
277
+ estimatedSavings: estimatedSavings > 0n ? estimatedSavings : 0n,
278
+ warnings
279
+ };
280
+ }
281
+ /**
282
+ * Plans sweeping the entire wallet to a single destination address.
283
+ */
284
+ async sweepPlan(opts) {
285
+ const utxos = await this.list({ includeFrozen: opts.includeFrozen });
286
+ if (utxos.length === 0) {
287
+ throw new Error("Cannot sweep an empty wallet.");
288
+ }
289
+ const estimatedFee = await this.estimateFee(utxos.length, 1);
290
+ const totalInputValue = utxos.reduce((sum, u) => sum + BigInt(u.amountSompi), 0n);
291
+ const warnings = [];
292
+ if (totalInputValue <= estimatedFee) {
293
+ warnings.push("Sweep fee exceeds the entire wallet balance.");
294
+ }
295
+ return {
296
+ strategy: "sweep",
297
+ inputs: utxos,
298
+ outputs: [{ address: opts.destinationAddress, amount: totalInputValue > estimatedFee ? totalInputValue - estimatedFee : 0n }],
299
+ estimatedFee,
300
+ estimatedSavings: 0n,
301
+ warnings
302
+ };
303
+ }
304
+ // --- Coin Control Persistence ---
305
+ async controlState() {
306
+ return this.store.getState();
307
+ }
308
+ async freeze(utxoId, reason) {
309
+ this.store.freeze(utxoId, reason);
310
+ }
311
+ async unfreeze(utxoId) {
312
+ this.store.unfreeze(utxoId);
313
+ }
314
+ labels = {
315
+ set: async (utxoId, label) => {
316
+ this.store.setLabel(utxoId, label);
317
+ },
318
+ get: async (utxoId) => {
319
+ return this.store.getLabel(utxoId);
320
+ }
321
+ };
322
+ notes = {
323
+ set: async (utxoId, note) => {
324
+ this.store.setNote(utxoId, note);
325
+ },
326
+ get: async (utxoId) => {
327
+ return this.store.getNote(utxoId);
328
+ }
329
+ };
330
+ }
331
+ //# sourceMappingURL=utxos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utxos.js","sourceRoot":"","sources":["../src/utxos.ts"],"names":[],"mappings":"AAyDA,MAAM,OAAO,aAAa;IAEL;IACA;IACA;IACA;IAJnB,YACmB,UAAiC,EACjC,OAA8B,EAC9B,WAAiE,EACjE,KAAuB;QAHvB,eAAU,GAAV,UAAU,CAAuB;QACjC,YAAO,GAAP,OAAO,CAAuB;QAC9B,gBAAW,GAAX,WAAW,CAAsD;QACjE,UAAK,GAAL,KAAK,CAAkB;IACvC,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,IAAmB;QAC5B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ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YAAY;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,MAAe;QAC1C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc;QAC3B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAEM,MAAM,GAAG;QACd,GAAG,EAAE,KAAK,EAAE,MAAc,EAAE,KAAa,EAAiB,EAAE;YAC1D,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;QACD,GAAG,EAAE,KAAK,EAAE,MAAc,EAA+B,EAAE;YACzD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;IAEK,KAAK,GAAG;QACb,GAAG,EAAE,KAAK,EAAE,MAAc,EAAE,IAAY,EAAiB,EAAE;YACzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;QACD,GAAG,EAAE,KAAK,EAAE,MAAc,EAA+B,EAAE;YACzD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;KACF,CAAC;CACH"}
@@ -0,0 +1,34 @@
1
+ import { WalletUtxoApi } from './utxos.js';
2
+ export interface WalletToolkitOptions {
3
+ storePath?: string;
4
+ network?: "simnet" | "testnet" | "mainnet";
5
+ }
6
+ export declare class WalletToolkit {
7
+ readonly name: string;
8
+ private readonly store;
9
+ private readonly options;
10
+ private walletManager;
11
+ private addressManager;
12
+ private walletQuery;
13
+ private _utxosApi;
14
+ private constructor();
15
+ static open(name: string, options?: WalletToolkitOptions): WalletToolkit;
16
+ create(): Promise<void>;
17
+ address(): Promise<string>;
18
+ balance(): Promise<bigint>;
19
+ get utxos(): WalletUtxoApi;
20
+ history(): Promise<any[]>;
21
+ estimateFee(opts: {
22
+ to: string;
23
+ amount: bigint;
24
+ }): Promise<any>;
25
+ planSend(opts: {
26
+ to: string;
27
+ amount: bigint;
28
+ }): Promise<any>;
29
+ sendSimulated(opts: {
30
+ to: string;
31
+ amount: bigint;
32
+ }): Promise<string>;
33
+ }
34
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,WAAW,oBAAoB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;CAC9C;AAED,qBAAa,aAAa;aAQF,IAAI,EAAE,MAAM;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAT5B,OAAO,CAAC,aAAa,CAAoB;IACzC,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,WAAW,CAAc;IAEjC,OAAO,CAAC,SAAS,CAAgB;IAEjC,OAAO;WAsBO,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,aAAa;IAKtE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAY1B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvC,IAAW,KAAK,IAAI,aAAa,CAEhC;IAEY,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAKzB,WAAW,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAU/D,QAAQ,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAI5D,aAAa,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAGpF"}
package/dist/wallet.js ADDED
@@ -0,0 +1,72 @@
1
+ import { WalletManagerImpl, WalletStateStoreJson, AddressManager } from '@hardkas/accounts';
2
+ import { WalletQuery } from '@hardkas/query';
3
+ import { WalletUtxoApi } from './utxos.js';
4
+ import { UtxoControlStore } from './stores/utxo-control-store.js';
5
+ export class WalletToolkit {
6
+ name;
7
+ store;
8
+ options;
9
+ walletManager;
10
+ addressManager;
11
+ walletQuery;
12
+ _utxosApi;
13
+ constructor(name, store, options) {
14
+ this.name = name;
15
+ this.store = store;
16
+ this.options = options;
17
+ this.walletManager = new WalletManagerImpl();
18
+ this.addressManager = AddressManager;
19
+ this.walletQuery = new WalletQuery({});
20
+ const utxoControlPath = options.storePath
21
+ ? options.storePath.replace('.json', '-utxo-control.json')
22
+ : 'default-utxo-control.json';
23
+ const utxoStore = new UtxoControlStore(utxoControlPath);
24
+ this._utxosApi = new WalletUtxoApi(async () => (await this.walletQuery.getUtxos([await this.address()])), async () => this.address(), async (inputs, outputs) => BigInt(inputs * 1000 + outputs * 1000), // Dummy fee estimation
25
+ utxoStore);
26
+ }
27
+ static open(name, options = {}) {
28
+ const store = new WalletStateStoreJson({ filePath: options.storePath || 'default.json' });
29
+ return new WalletToolkit(name, store, options);
30
+ }
31
+ async create() {
32
+ this.walletManager.create({ walletId: this.name });
33
+ }
34
+ async address() {
35
+ // High level facade: gets receive address
36
+ const seedRef = this.walletManager.getSeedRef(this.name);
37
+ return this.addressManager.derive({
38
+ seedRef,
39
+ accountIndex: 0,
40
+ chain: 'receive',
41
+ addressIndex: 0,
42
+ network: this.options.network || 'simnet'
43
+ }).address;
44
+ }
45
+ async balance() {
46
+ const addr = await this.address();
47
+ return (await this.walletQuery.getBalance([addr]));
48
+ }
49
+ get utxos() {
50
+ return this._utxosApi;
51
+ }
52
+ async history() {
53
+ const addr = await this.address();
54
+ return (await this.walletQuery.getHistory({ addresses: [addr] }));
55
+ }
56
+ async estimateFee(opts) {
57
+ const u = await this.utxos.list();
58
+ // Since we are mocking the facade, just return a fake fee
59
+ return {
60
+ selectedUtxos: [],
61
+ fee: 1000n,
62
+ totalOut: BigInt(opts.amount) + 1000n
63
+ };
64
+ }
65
+ async planSend(opts) {
66
+ return {};
67
+ }
68
+ async sendSimulated(opts) {
69
+ return `simulated_tx_${Date.now()}`;
70
+ }
71
+ }
72
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAOlE,MAAM,OAAO,aAAa;IAQF;IACC;IACA;IATb,aAAa,CAAoB;IACjC,cAAc,CAAwB;IACtC,WAAW,CAAc;IAEzB,SAAS,CAAgB;IAEjC,YACoB,IAAY,EACX,KAA2B,EAC3B,OAA6B;QAF9B,SAAI,GAAJ,IAAI,CAAQ;QACX,UAAK,GAAL,KAAK,CAAsB;QAC3B,YAAO,GAAP,OAAO,CAAsB;QAE9C,IAAI,CAAC,aAAa,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAC7C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,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main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "dependencies": {
9
+ "fs-extra": "^11.2.0",
10
+ "@hardkas/tx-builder": "0.11.1-alpha",
11
+ "@hardkas/core": "0.11.1-alpha",
12
+ "@hardkas/jobs": "0.11.1-alpha",
13
+ "@hardkas/accounts": "0.11.1-alpha",
14
+ "@hardkas/query-store": "0.11.1-alpha",
15
+ "@hardkas/artifacts": "0.11.1-alpha",
16
+ "@hardkas/query": "0.11.1-alpha"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.6.3",
20
+ "vitest": "^2.1.2",
21
+ "@types/node": "^20.12.7",
22
+ "@types/fs-extra": "^11.0.4"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "test": "vitest run"
27
+ }
28
+ }
@@ -0,0 +1,150 @@
1
+ import { LocalDagStore } from './store.js';
2
+ import { DAGTopology } from './topology.js';
3
+ import { DagBlock, DagStatistics } from './types.js';
4
+
5
+ export class ConsensusView {
6
+ // Memoize calculated blue scores to prevent exponential recursion
7
+ private blueScoreCache = new Map<string, number>();
8
+
9
+ public constructor(
10
+ private readonly store: LocalDagStore,
11
+ private readonly topology: DAGTopology
12
+ ) {}
13
+
14
+ public clearCache(): void {
15
+ this.blueScoreCache.clear();
16
+ }
17
+
18
+ public async blueScore(hash: string): Promise<number> {
19
+ // If provided explicitly in the payload, use it
20
+ const b = await this.topology.block(hash);
21
+ if (b.blueScore !== undefined) {
22
+ return b.blueScore;
23
+ }
24
+
25
+ if (this.blueScoreCache.has(hash)) {
26
+ return this.blueScoreCache.get(hash)!;
27
+ }
28
+
29
+ if (b.parents.length === 0) {
30
+ this.blueScoreCache.set(hash, 0);
31
+ return 0;
32
+ }
33
+
34
+ let maxScore = 0;
35
+ for (const p of b.parents) {
36
+ try {
37
+ const score = await this.blueScore(p);
38
+ if (score > maxScore) maxScore = score;
39
+ } catch (e) {
40
+ // Ignore missing parents (orphans)
41
+ }
42
+ }
43
+
44
+ const calculatedScore = maxScore + 1;
45
+ this.blueScoreCache.set(hash, calculatedScore);
46
+ return calculatedScore;
47
+ }
48
+
49
+ public async confirmations(hash: string): Promise<number> {
50
+ const isOrphan = await this.isOrphan(hash);
51
+ if (isOrphan) return 0;
52
+
53
+ const allBlocks = this.store.getAllBlocks();
54
+ const tips = allBlocks.filter(b => this.store.getChildrenHashes(b.hash).length === 0);
55
+
56
+ if (tips.length === 0) return 0;
57
+
58
+ let maxScore = -1;
59
+ let heaviestTip: DagBlock | null = null;
60
+
61
+ for (const tip of tips) {
62
+ const score = await this.blueScore(tip.hash);
63
+ if (score > maxScore) {
64
+ maxScore = score;
65
+ heaviestTip = tip;
66
+ }
67
+ }
68
+
69
+ if (!heaviestTip) return 0;
70
+
71
+ // Verify reachability: does the heaviest tip actually include this block in its past?
72
+ const reachable = await this.topology.reachability(hash, heaviestTip.hash);
73
+ if (!reachable) return 0;
74
+
75
+ const blockScore = await this.blueScore(hash);
76
+ return Math.max(0, maxScore - blockScore);
77
+ }
78
+
79
+ private async isOrphan(hash: string): Promise<boolean> {
80
+ const b = this.store.getBlock(hash);
81
+ if (!b) return false;
82
+ if (b.parents.length === 0) return false;
83
+
84
+ for (const p of b.parents) {
85
+ if (!this.store.getBlock(p)) return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ public async trace(txid: string): Promise<{ txid: string, status: string, foundIn: string[] }> {
91
+ const allBlocks = this.store.getAllBlocks();
92
+ const foundInBlocks: string[] = [];
93
+
94
+ for (const block of allBlocks) {
95
+ if (block.transactions && block.transactions.some(tx => tx.id === txid)) {
96
+ foundInBlocks.push(block.hash);
97
+ }
98
+ }
99
+
100
+ if (foundInBlocks.length === 0) {
101
+ return { txid, status: "not_found", foundIn: [] };
102
+ }
103
+
104
+ if (foundInBlocks.length === 1) {
105
+ const blockHash = foundInBlocks[0]!;
106
+ const isOrphan = await this.isOrphan(blockHash);
107
+ return { txid, status: isOrphan ? "orphan" : "accepted", foundIn: foundInBlocks };
108
+ }
109
+
110
+ // Parallel branch conflict detection
111
+ let isConflict = false;
112
+ for (let i = 0; i < foundInBlocks.length; i++) {
113
+ for (let j = i + 1; j < foundInBlocks.length; j++) {
114
+ const b1 = foundInBlocks[i]!;
115
+ const b2 = foundInBlocks[j]!;
116
+
117
+ const reach1 = await this.topology.reachability(b1, b2);
118
+ const reach2 = await this.topology.reachability(b2, b1);
119
+
120
+ if (!reach1 && !reach2) {
121
+ isConflict = true;
122
+ break;
123
+ }
124
+ }
125
+ }
126
+
127
+ return {
128
+ txid,
129
+ status: isConflict ? "conflict" : "merged",
130
+ foundIn: foundInBlocks
131
+ };
132
+ }
133
+
134
+ public async statistics(): Promise<DagStatistics> {
135
+ const allBlocks = this.store.getAllBlocks();
136
+ const tips = allBlocks.filter(b => this.store.getChildrenHashes(b.hash).length === 0);
137
+
138
+ let highestBlueScore = 0;
139
+ for (const b of allBlocks) {
140
+ const score = await this.blueScore(b.hash);
141
+ if (score > highestBlueScore) highestBlueScore = score;
142
+ }
143
+
144
+ return {
145
+ totalBlocks: allBlocks.length,
146
+ totalTips: tips.length,
147
+ highestBlueScore
148
+ };
149
+ }
150
+ }