minimal-xec-wallet 1.0.5 → 2.0.2

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.
@@ -278,7 +278,7 @@ node transactions/send-xec.js ecash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy 1
278
278
  - **Gate.io**: XEC/USDT
279
279
 
280
280
  ### Development
281
- - **Library Source**: https://github.com/your-repo/minimal-xec-wallet
281
+ - **Library Source**: https://github.com/zh/minimal-xec-wallet
282
282
  - **API Documentation**: ../docs/
283
283
  - **Test Coverage**: Run `npm test`
284
284
 
@@ -0,0 +1,279 @@
1
+ # UTXO Analytics Examples
2
+
3
+ This directory contains comprehensive examples demonstrating the advanced UTXO analytics features added to the minimal-xec-wallet library. These features provide powerful tools for wallet optimization, security analysis, and privacy enhancement.
4
+
5
+ ## Overview
6
+
7
+ The UTXO analytics system includes:
8
+
9
+ - **UTXO Classification**: Analyze UTXOs by age, value, and privacy characteristics
10
+ - **Health Monitoring**: Monitor wallet health and detect potential issues
11
+ - **Smart Coin Selection**: Intelligent UTXO selection with multiple strategies
12
+ - **Dust Attack Detection**: Identify and mitigate privacy threats
13
+ - **Wallet Optimization**: Comprehensive optimization recommendations
14
+
15
+ ## Examples
16
+
17
+ ### 1. UTXO Classification Demo (`utxo-classification-demo.js`)
18
+
19
+ Demonstrates how to classify UTXOs and analyze their characteristics.
20
+
21
+ ```bash
22
+ node utxo-classification-demo.js
23
+ ```
24
+
25
+ **Features shown:**
26
+ - Enabling analytics in wallet configuration
27
+ - Classifying UTXOs by age (fresh, recent, mature, aged, ancient)
28
+ - Categorizing by value (dust, micro, small, medium, large, whale)
29
+ - Privacy scoring (0-100 based on fingerprinting risks)
30
+ - Health assessment and metadata extraction
31
+ - Filtering UTXOs by classification criteria
32
+
33
+ ### 2. Health Monitoring Demo (`health-monitoring-demo.js`)
34
+
35
+ Shows comprehensive health monitoring and issue detection.
36
+
37
+ ```bash
38
+ node health-monitoring-demo.js
39
+ ```
40
+
41
+ **Features shown:**
42
+ - Wallet health assessment
43
+ - Individual UTXO health scoring
44
+ - Alert generation for critical issues
45
+ - System-wide recommendations
46
+ - Performance impact analysis
47
+ - Economic viability calculations
48
+
49
+ ### 3. Advanced Coin Selection Demo (`advanced-coin-selection-demo.js`)
50
+
51
+ Demonstrates intelligent UTXO selection strategies.
52
+
53
+ ```bash
54
+ node advanced-coin-selection-demo.js
55
+ ```
56
+
57
+ **Features shown:**
58
+ - Efficient strategy (minimize fees)
59
+ - Privacy strategy (maximize anonymity)
60
+ - Balanced strategy (optimal trade-offs)
61
+ - Conservative strategy (prefer confirmed UTXOs)
62
+ - Classification-based filtering
63
+ - Performance comparisons
64
+
65
+ ### 4. Dust Attack Detection Demo (`dust-attack-detection-demo.js`)
66
+
67
+ Comprehensive dust attack detection and analysis.
68
+
69
+ ```bash
70
+ node dust-attack-detection-demo.js
71
+ ```
72
+
73
+ **Features shown:**
74
+ - Dust attack pattern recognition
75
+ - Suspicious UTXO identification
76
+ - Confidence scoring
77
+ - Risk level assessment
78
+ - Defense strategies
79
+ - Multiple attack scenarios
80
+
81
+ ### 5. Wallet Optimization Demo (`wallet-optimization-demo.js`)
82
+
83
+ Complete wallet optimization analysis and recommendations.
84
+
85
+ ```bash
86
+ node wallet-optimization-demo.js
87
+ ```
88
+
89
+ **Features shown:**
90
+ - Comprehensive wallet analysis
91
+ - Consolidation opportunity identification
92
+ - Privacy optimization suggestions
93
+ - Cost-benefit analysis
94
+ - Actionable optimization plans
95
+ - Long-term strategy recommendations
96
+
97
+ ## Configuration
98
+
99
+ To enable analytics in your wallet, use the following configuration:
100
+
101
+ ```javascript
102
+ const walletOptions = {
103
+ utxoAnalytics: {
104
+ enabled: true,
105
+ debug: false, // Set to true for detailed logging
106
+ classificationConfig: {
107
+ ageThresholds: {
108
+ fresh: 6, // ~1 hour (in blocks)
109
+ recent: 144, // ~1 day
110
+ mature: 1008, // ~1 week
111
+ aged: 4032 // ~1 month
112
+ },
113
+ valueThresholds: {
114
+ dust: 1000, // 10 XEC
115
+ micro: 5000, // 50 XEC
116
+ small: 50000, // 500 XEC
117
+ medium: 500000, // 5000 XEC
118
+ large: 5000000 // 50000 XEC
119
+ }
120
+ },
121
+ healthMonitorConfig: {
122
+ dustLimit: 546,
123
+ economicalThreshold: 2.0,
124
+ alertThresholds: {
125
+ highDustRatio: 0.7,
126
+ lowLiquidity: 0.3,
127
+ highConsolidationNeed: 0.5
128
+ },
129
+ suspiciousPatterns: {
130
+ dustAttackSize: 10,
131
+ rapidDeposits: 5,
132
+ timeWindow: 3600000 // 1 hour in milliseconds
133
+ }
134
+ }
135
+ }
136
+ }
137
+
138
+ const wallet = new MinimalXECWallet(mnemonic, walletOptions)
139
+ ```
140
+
141
+ ## Key Methods
142
+
143
+ ### Classification Methods
144
+
145
+ ```javascript
146
+ // Check if analytics are enabled
147
+ const hasAnalytics = wallet.utxos.hasAnalytics()
148
+
149
+ // Get UTXO classifications
150
+ const classifications = wallet.utxos.getUtxoClassifications()
151
+
152
+ // Get classification statistics
153
+ const stats = wallet.utxos.getClassificationStats()
154
+
155
+ // Filter UTXOs by classification
156
+ const filteredUtxos = wallet.utxos.getSpendableXecUtxos({
157
+ useClassifications: true,
158
+ classificationFilter: {
159
+ minHealthScore: 70,
160
+ minPrivacyScore: 60,
161
+ allowedAges: ['mature', 'aged', 'ancient']
162
+ }
163
+ })
164
+ ```
165
+
166
+ ### Health Monitoring Methods
167
+
168
+ ```javascript
169
+ // Get comprehensive health report
170
+ const healthReport = wallet.utxos.getWalletHealthReport()
171
+
172
+ // Get optimization recommendations
173
+ const recommendations = wallet.utxos.getOptimizationRecommendations()
174
+
175
+ // Detect security threats
176
+ const threats = wallet.utxos.detectSecurityThreats(walletAddress)
177
+ ```
178
+
179
+ ### Smart Coin Selection
180
+
181
+ ```javascript
182
+ // Select UTXOs with different strategies
183
+ const efficientSelection = wallet.utxos.selectOptimalUtxos(targetAmount, {
184
+ strategy: 'efficient',
185
+ feeRate: 1.0
186
+ })
187
+
188
+ const privacySelection = wallet.utxos.selectOptimalUtxos(targetAmount, {
189
+ strategy: 'privacy',
190
+ feeRate: 1.0
191
+ })
192
+
193
+ const balancedSelection = wallet.utxos.selectOptimalUtxos(targetAmount, {
194
+ strategy: 'balanced',
195
+ feeRate: 1.0
196
+ })
197
+ ```
198
+
199
+ ## Classification Categories
200
+
201
+ ### Age Classifications
202
+ - **Fresh**: ≤ 6 blocks (~1 hour)
203
+ - **Recent**: ≤ 144 blocks (~1 day)
204
+ - **Mature**: ≤ 1008 blocks (~1 week)
205
+ - **Aged**: ≤ 4032 blocks (~1 month)
206
+ - **Ancient**: > 4032 blocks
207
+ - **Unconfirmed**: blockHeight = -1
208
+
209
+ ### Value Classifications
210
+ - **Dust**: < 1,000 satoshis (< 10 XEC)
211
+ - **Micro**: < 5,000 satoshis (< 50 XEC)
212
+ - **Small**: < 50,000 satoshis (< 500 XEC)
213
+ - **Medium**: < 500,000 satoshis (< 5,000 XEC)
214
+ - **Large**: < 5,000,000 satoshis (< 50,000 XEC)
215
+ - **Whale**: ≥ 5,000,000 satoshis (≥ 50,000 XEC)
216
+
217
+ ### Health Classifications
218
+ - **Healthy**: Economical to spend, good privacy
219
+ - **At-Risk**: Marginally economical
220
+ - **Dust**: Too small to spend economically
221
+ - **Suspicious**: Potential dust attack indicators
222
+ - **Unconfirmed**: Not yet confirmed
223
+ - **Stuck**: Unconfirmed for too long
224
+
225
+ ## Selection Strategies
226
+
227
+ ### Efficient Strategy
228
+ - Minimizes transaction fees
229
+ - Prefers larger, economical UTXOs
230
+ - Optimizes for cost-effectiveness
231
+
232
+ ### Privacy Strategy
233
+ - Maximizes transaction privacy
234
+ - Avoids fingerprinting patterns
235
+ - Prefers aged, non-round amounts
236
+
237
+ ### Balanced Strategy
238
+ - Balances efficiency and privacy
239
+ - Considers health scores
240
+ - Good for general use
241
+
242
+ ### Conservative Strategy
243
+ - Prefers confirmed UTXOs
244
+ - Prioritizes reliability
245
+ - Best for important transactions
246
+
247
+ ## Security Features
248
+
249
+ ### Dust Attack Detection
250
+ - Pattern recognition for suspicious micro-UTXOs
251
+ - Confidence scoring for threat assessment
252
+ - Automatic quarantine recommendations
253
+
254
+ ### Privacy Analysis
255
+ - Round number detection
256
+ - Fingerprinting risk assessment
257
+ - Privacy score calculation
258
+
259
+ ### Health Monitoring
260
+ - Economic viability analysis
261
+ - Alert generation for issues
262
+ - Optimization recommendations
263
+
264
+ ## Performance Considerations
265
+
266
+ - Analytics are completely optional (disabled by default)
267
+ - Minimal impact on existing wallet operations
268
+ - Efficient caching and incremental updates
269
+ - Graceful degradation when analytics unavailable
270
+
271
+ ## Testing
272
+
273
+ All examples include both real wallet scenarios and mock data demonstrations. The mock data examples will run even when the wallet has no UTXOs, making them perfect for testing and learning.
274
+
275
+ ## Integration
276
+
277
+ These analytics features are designed to enhance existing wallet functionality without breaking changes. All existing wallet operations continue to work exactly as before when analytics are disabled.
278
+
279
+ For more information, see the main wallet documentation and unit tests in the `test/` directory.