minimal-xec-wallet 1.0.1

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +241 -0
  3. package/dist/minimal-xec-wallet.js +66268 -0
  4. package/dist/minimal-xec-wallet.min.js +55 -0
  5. package/examples/README.md +380 -0
  6. package/examples/advanced/browser-compatibility-test.js +263 -0
  7. package/examples/advanced/get-xec-price.js +149 -0
  8. package/examples/advanced/optimize-utxos.js +255 -0
  9. package/examples/advanced/send-op-return.js +216 -0
  10. package/examples/browser-test.html +350 -0
  11. package/examples/key-management/derive-addresses.js +191 -0
  12. package/examples/key-management/export-to-wif.js +114 -0
  13. package/examples/key-management/validate-address.js +214 -0
  14. package/examples/optimization/simple-consolidation-test.js +79 -0
  15. package/examples/optimization/test-utxo-consolidation.js +179 -0
  16. package/examples/test-examples.js +1204 -0
  17. package/examples/tokens/burn-tokens.js +293 -0
  18. package/examples/tokens/get-token-balance.js +169 -0
  19. package/examples/tokens/get-token-info.js +269 -0
  20. package/examples/tokens/list-all-tokens.js +162 -0
  21. package/examples/tokens/send-any-token.js +260 -0
  22. package/examples/tokens/test-main-wallet-integration.js +193 -0
  23. package/examples/transactions/send-all-xec.js +205 -0
  24. package/examples/transactions/send-to-multiple.js +217 -0
  25. package/examples/transactions/send-xec.js +191 -0
  26. package/examples/utils/show-qr.js +119 -0
  27. package/examples/utils/wallet-helper.js +176 -0
  28. package/examples/validation/comprehensive-infrastructure-test.js +210 -0
  29. package/examples/wallet-creation/create-new-wallet.js +67 -0
  30. package/examples/wallet-creation/import-from-wif.js +135 -0
  31. package/examples/wallet-creation/restore-from-mnemonic.js +100 -0
  32. package/examples/wallet-info/get-balance.js +99 -0
  33. package/examples/wallet-info/get-transactions.js +157 -0
  34. package/examples/wallet-info/get-utxos.js +145 -0
  35. package/examples/wallet.json +11 -0
  36. package/lib/adapters/robust-chronik-router.js +507 -0
  37. package/lib/adapters/router.js +651 -0
  38. package/lib/alp-token-handler.js +581 -0
  39. package/lib/browser-wasm-loader.js +271 -0
  40. package/lib/consolidate-utxos.js +338 -0
  41. package/lib/hybrid-token-manager.js +322 -0
  42. package/lib/key-derivation.js +466 -0
  43. package/lib/op-return.js +314 -0
  44. package/lib/security.js +270 -0
  45. package/lib/send-xec.js +396 -0
  46. package/lib/slp-token-handler.js +572 -0
  47. package/lib/token-protocol-detector.js +307 -0
  48. package/lib/utxos.js +303 -0
  49. package/package.json +125 -0
@@ -0,0 +1,380 @@
1
+ # Minimal XEC Wallet - Examples
2
+
3
+ This directory contains comprehensive examples demonstrating how to use the minimal-xec-wallet library for eCash (XEC) blockchain operations.
4
+
5
+ ## šŸ“ Directory Structure
6
+
7
+ ```
8
+ examples/
9
+ ā”œā”€ā”€ wallet-creation/ # Create, restore, import wallets
10
+ ā”œā”€ā”€ wallet-info/ # Check balance, UTXOs, transactions
11
+ ā”œā”€ā”€ transactions/ # Send XEC, multi-output, send-all
12
+ ā”œā”€ā”€ advanced/ # OP_RETURN, optimization, price checking
13
+ ā”œā”€ā”€ key-management/ # Address derivation, validation
14
+ ā”œā”€ā”€ utils/ # Helper utilities (QR codes, wallet helper)
15
+ ā”œā”€ā”€ test-examples.js # End-to-end testing script
16
+ └── README.md # This file
17
+ ```
18
+
19
+ ## šŸš€ Quick Start
20
+
21
+ ### 1. Install Dependencies
22
+
23
+ ```bash
24
+ npm install
25
+ ```
26
+
27
+ ### 2. Create Your First Wallet
28
+
29
+ ```bash
30
+ cd examples
31
+ node wallet-creation/create-new-wallet.js
32
+ ```
33
+
34
+ This creates a `wallet.json` file that all other examples will use.
35
+
36
+ ### 3. Fund Your Wallet
37
+
38
+ Your wallet needs XEC for transaction examples:
39
+
40
+ ```bash
41
+ # Show your address with QR code for easy funding
42
+ node utils/show-qr.js $(node -e "console.log(require('./wallet.json').xecAddress)")
43
+ ```
44
+
45
+ Send XEC to the displayed address using:
46
+ - [CashTab Wallet](https://cashtab.com)
47
+ - Cryptocurrency exchanges (Binance, KuCoin, Gate.io)
48
+ - Another XEC wallet
49
+
50
+ ### 4. Check Balance
51
+
52
+ ```bash
53
+ node wallet-info/get-balance.js
54
+ ```
55
+
56
+ ### 5. Run All Examples
57
+
58
+ ```bash
59
+ # Automated test suite with funding break
60
+ node test-examples.js
61
+ ```
62
+
63
+ ## šŸ“š Example Categories
64
+
65
+ ### šŸ”‘ Wallet Creation (`wallet-creation/`)
66
+
67
+ | Example | Description | Requirements |
68
+ |---------|-------------|--------------|
69
+ | `create-new-wallet.js` | Generate new wallet with random mnemonic | None |
70
+ | `restore-from-mnemonic.js` | Restore wallet from 12-word phrase | Mnemonic phrase |
71
+ | `import-from-wif.js` | Import wallet from private key | WIF or hex private key |
72
+
73
+ **Usage:**
74
+ ```bash
75
+ # Create new wallet
76
+ node wallet-creation/create-new-wallet.js
77
+
78
+ # Restore from mnemonic (interactive or command line)
79
+ node wallet-creation/restore-from-mnemonic.js
80
+ node wallet-creation/restore-from-mnemonic.js word1 word2 ... word12
81
+
82
+ # Import from private key (supports all WIF formats)
83
+ node wallet-creation/import-from-wif.js L1234...abcd # Mainnet compressed
84
+ node wallet-creation/import-from-wif.js 51234...abcd # Mainnet uncompressed
85
+ node wallet-creation/import-from-wif.js c1234...abcd # Testnet compressed
86
+ node wallet-creation/import-from-wif.js 1234567890abcdef... # Hex private key
87
+ ```
88
+
89
+ ### šŸ’° Wallet Information (`wallet-info/`)
90
+
91
+ | Example | Description | Requirements |
92
+ |---------|-------------|--------------|
93
+ | `get-balance.js` | Display XEC balance and USD value | Wallet |
94
+ | `get-utxos.js` | List all UTXOs with analysis | Wallet |
95
+ | `get-transactions.js` | Show transaction history | Wallet |
96
+
97
+ **Usage:**
98
+ ```bash
99
+ node wallet-info/get-balance.js
100
+ node wallet-info/get-utxos.js
101
+ node wallet-info/get-transactions.js
102
+ ```
103
+
104
+ ### šŸ’ø Transactions (`transactions/`)
105
+
106
+ | Example | Description | Requirements |
107
+ |---------|-------------|--------------|
108
+ | `send-xec.js` | Send XEC to single recipient | Funded wallet |
109
+ | `send-to-multiple.js` | Send XEC to multiple recipients | Funded wallet |
110
+ | `send-all-xec.js` | Send all XEC (empty wallet) | Funded wallet |
111
+
112
+ **Usage:**
113
+ ```bash
114
+ # Send 100 XEC to an address
115
+ node transactions/send-xec.js ecash:qp1234...abc 100
116
+
117
+ # Send to multiple recipients
118
+ node transactions/send-to-multiple.js ecash:qp123...abc 50 ecash:qr456...def 30
119
+
120
+ # Send all XEC (empty wallet)
121
+ node transactions/send-all-xec.js ecash:qp1234...abc
122
+ ```
123
+
124
+ ### ⚔ Advanced Features (`advanced/`)
125
+
126
+ | Example | Description | Requirements |
127
+ |---------|-------------|--------------|
128
+ | `send-op-return.js` | Embed data in blockchain | Funded wallet |
129
+ | `optimize-utxos.js` | Consolidate UTXOs for efficiency | Multiple UTXOs |
130
+ | `get-xec-price.js` | Get current XEC/USD price | Internet connection |
131
+ | `browser-compatibility-test.js` | Test browser WebAssembly compatibility | None |
132
+
133
+ **Usage:**
134
+ ```bash
135
+ # Embed message in blockchain
136
+ node advanced/send-op-return.js "Hello XEC blockchain!"
137
+
138
+ # UTXO optimization (preview)
139
+ node advanced/optimize-utxos.js --dry-run
140
+ node advanced/optimize-utxos.js
141
+
142
+ # Get current XEC price
143
+ node advanced/get-xec-price.js
144
+
145
+ # Test browser compatibility (WebAssembly support)
146
+ node advanced/browser-compatibility-test.js
147
+ open browser-test.html # Interactive browser test
148
+ ```
149
+
150
+ ### šŸ” Key Management (`key-management/`)
151
+
152
+ | Example | Description | Requirements |
153
+ |---------|-------------|--------------|
154
+ | `derive-addresses.js` | Generate multiple addresses | HD wallet (mnemonic) |
155
+ | `validate-address.js` | Validate XEC address format | None |
156
+ | `export-to-wif.js` | Export private key to WIF format | Existing wallet |
157
+
158
+ **Usage:**
159
+ ```bash
160
+ # Generate 10 addresses from mnemonic
161
+ node key-management/derive-addresses.js 10
162
+
163
+ # Validate address format
164
+ node key-management/validate-address.js ecash:qp1234...abc
165
+
166
+ # Export private key to WIF (all formats)
167
+ node key-management/export-to-wif.js
168
+ ```
169
+
170
+ ### šŸŖ™ Token Operations (`tokens/`)
171
+
172
+ | Example | Description | Requirements |
173
+ |---------|-------------|--------------|
174
+ | `list-all-tokens.js` | List all SLP and ALP tokens in wallet | Wallet with tokens |
175
+ | `get-token-balance.js` | Get balance for specific token ID | Token ID |
176
+ | `get-token-info.js` | Get comprehensive token metadata | Token ID |
177
+ | `send-any-token.js` | Send SLP or ALP tokens to recipients | Funded wallet, tokens |
178
+ | `burn-tokens.js` | Burn specific amount of tokens | Tokens to burn |
179
+ | `test-main-wallet-integration.js` | Integration test for token API | Test tokens |
180
+
181
+ **Usage:**
182
+ ```bash
183
+ # List all tokens (auto-detects SLP and ALP)
184
+ node tokens/list-all-tokens.js
185
+
186
+ # Get balance for specific token
187
+ node tokens/get-token-balance.js abc123def456...
188
+
189
+ # Send tokens (works with both SLP and ALP)
190
+ node tokens/send-any-token.js tokenId recipientAddress amount
191
+
192
+ # Get token information
193
+ node tokens/get-token-info.js abc123def456...
194
+
195
+ # Burn tokens permanently
196
+ node tokens/burn-tokens.js tokenId amount
197
+ ```
198
+
199
+ ### šŸ› ļø Utilities (`utils/`)
200
+
201
+ | Utility | Description | Requirements |
202
+ |---------|-------------|--------------|
203
+ | `wallet-helper.js` | Wallet persistence library | Used by all examples |
204
+ | `show-qr.js` | Display QR code for address | Valid XEC address |
205
+
206
+ **Usage:**
207
+ ```bash
208
+ # Show QR code for easy mobile scanning
209
+ node utils/show-qr.js ecash:qp1234567890abcdef1234567890abcdef1234567890
210
+ ```
211
+
212
+ ## 🧪 Testing Examples
213
+
214
+ ### Automated Testing
215
+
216
+ The `test-examples.js` script runs all examples in sequence with proper funding workflow:
217
+
218
+ ```bash
219
+ node test-examples.js
220
+ ```
221
+
222
+ **Test Flow:**
223
+ 1. **Phase 1: Wallet Creation** - Creates and validates wallet
224
+ 2. **Funding Break** - Shows QR code, waits for funding
225
+ 3. **Phase 2: Utilities** - Tests non-transaction features
226
+ 4. **Phase 3: Transactions** - Tests real XEC transactions (with confirmation)
227
+ 5. **Phase 4: Token Operations** - Tests SLP/ALP token functionality
228
+
229
+ ### Manual Testing
230
+
231
+ Test individual examples:
232
+
233
+ ```bash
234
+ # Test wallet creation
235
+ node wallet-creation/create-new-wallet.js
236
+
237
+ # Test balance checking
238
+ node wallet-info/get-balance.js
239
+
240
+ # Test transactions (requires funding)
241
+ node transactions/send-xec.js ecash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy 1
242
+ ```
243
+
244
+ ## šŸ’” Best Practices
245
+
246
+ ### Security
247
+
248
+ - **Never commit wallet.json** - Contains private keys
249
+ - **Keep mnemonic phrases secure** - Anyone with your mnemonic can access funds
250
+ - **Test with small amounts first** - Verify addresses before large transactions
251
+ - **Backup your wallet** - Save mnemonic phrase safely
252
+
253
+ ### Development Workflow
254
+
255
+ 1. **Start with wallet creation examples**
256
+ 2. **Fund wallet for transaction testing**
257
+ 3. **Use dry-run modes when available**
258
+ 4. **Validate addresses before sending**
259
+ 5. **Monitor transactions with block explorer**
260
+
261
+ ### Error Handling
262
+
263
+ - **Insufficient funds** - Check balance, fund wallet
264
+ - **Invalid addresses** - Use address validation utility
265
+ - **Network errors** - Check internet connection, try again
266
+ - **Transaction failures** - Check fees, UTXOs, network status
267
+
268
+ ## šŸ”— Useful Resources
269
+
270
+ ### XEC Network
271
+ - **Block Explorer**: https://explorer.e.cash
272
+ - **CashTab Wallet**: https://cashtab.com
273
+ - **eCash.org**: https://e.cash
274
+
275
+ ### Exchanges (to buy XEC)
276
+ - **Binance**: XEC/USDT, XEC/BTC
277
+ - **KuCoin**: XEC/USDT
278
+ - **Gate.io**: XEC/USDT
279
+
280
+ ### Development
281
+ - **Library Source**: https://github.com/your-repo/minimal-xec-wallet
282
+ - **API Documentation**: ../docs/
283
+ - **Test Coverage**: Run `npm test`
284
+
285
+ ## šŸ› Troubleshooting
286
+
287
+ ### Common Issues
288
+
289
+ **1. "No wallet.json file found"**
290
+ ```bash
291
+ # Solution: Create a wallet first
292
+ node wallet-creation/create-new-wallet.js
293
+ ```
294
+
295
+ **2. "Insufficient funds"**
296
+ ```bash
297
+ # Solution: Fund your wallet
298
+ node utils/show-qr.js $(node -e "console.log(require('./wallet.json').xecAddress)")
299
+ # Then send XEC to the displayed address
300
+ ```
301
+
302
+ **3. "Invalid address format"**
303
+ ```bash
304
+ # Solution: Validate the address
305
+ node key-management/validate-address.js YOUR_ADDRESS
306
+ ```
307
+
308
+ **4. "Network connection error"**
309
+ - Check internet connection
310
+ - Try again in a few moments
311
+ - Chronik indexer might be temporarily unavailable
312
+
313
+ **5. "Transaction failed"**
314
+ - Check wallet balance
315
+ - Verify recipient address
316
+ - Ensure sufficient fee coverage
317
+
318
+ ### Getting Help
319
+
320
+ 1. **Check error messages** - They usually explain the issue
321
+ 2. **Validate inputs** - Use validation utilities
322
+ 3. **Test with small amounts** - Before large transactions
323
+ 4. **Check network status** - Via block explorer
324
+ 5. **Review documentation** - This README and source code
325
+
326
+ ## šŸ“ Example Output
327
+
328
+ ### Successful Wallet Creation
329
+ ```
330
+ šŸš€ Creating new XEC wallet...
331
+
332
+ āœ… New wallet created successfully!
333
+
334
+ šŸ“‹ New Wallet Details:
335
+ ══════════════════════════════════════════════════════
336
+ Mnemonic: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
337
+ XEC Address: ecash:qrdczda80g7red03zqd02uuxjhfqxrthdywrq8cx3a
338
+ HD Path: m/44'/899'/0'/0/0
339
+ ══════════════════════════════════════════════════════
340
+
341
+ āœ… Wallet saved to: /path/to/examples/wallet.json
342
+ šŸ“ XEC Address: ecash:qrdczda80g7red03zqd02uuxjhfqxrthdywrq8cx3a
343
+ ```
344
+
345
+ ### Successful Transaction
346
+ ```
347
+ šŸ’ø Sending XEC transaction...
348
+
349
+ šŸ“‹ Transaction Details:
350
+ ════════════════════════════════════════════════════════════
351
+ From: ecash:qrdczda80g7red03zqd02uuxjhfqxrthdywrq8cx3a
352
+ To: ecash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy
353
+ Amount: 100 XEC
354
+ Current Balance: 1,000 XEC
355
+ ════════════════════════════════════════════════════════════
356
+
357
+ āœ… Transaction sent successfully!
358
+ ════════════════════════════════════════════════════════════
359
+ Transaction ID: abc123def456...
360
+ Amount Sent: 100 XEC
361
+ Fee Paid: 0.01 XEC
362
+ New Balance: 899.99 XEC
363
+ ════════════════════════════════════════════════════════════
364
+ ```
365
+
366
+ ## šŸŽÆ Next Steps
367
+
368
+ After running the examples:
369
+
370
+ 1. **Explore the source code** - Learn how each feature works
371
+ 2. **Build your own application** - Use these examples as templates
372
+ 3. **Work with eTokens** - SLP and ALP token operations
373
+ 4. **Contribute improvements** - Submit PRs for enhancements
374
+ 5. **Join the community** - eCash developer channels
375
+
376
+ ---
377
+
378
+ **āš ļø Important**: These examples use real XEC on the mainnet. Always test with small amounts first!
379
+
380
+ **šŸ” Security Reminder**: Keep your mnemonic phrase secure. Anyone with access to it can control your funds.
@@ -0,0 +1,263 @@
1
+ /*
2
+ Browser Compatibility Test - WebAssembly Loading
3
+
4
+ Tests various WASM loading strategies for browser compatibility.
5
+ Demonstrates fallback mechanisms for older browsers.
6
+ */
7
+
8
+ /* global WebAssembly, Worker, navigator, crypto */
9
+
10
+ const MinimalXECWallet = require('../../index')
11
+
12
+ // Browser compatibility detection utility
13
+ function detectBrowserCapabilities () {
14
+ const capabilities = {
15
+ webAssembly: false,
16
+ webAssemblyCompile: false,
17
+ webAssemblyInstantiate: false,
18
+ webWorkers: false,
19
+ cryptoSubtle: false,
20
+ userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'Node.js'
21
+ }
22
+
23
+ try {
24
+ // WebAssembly support
25
+ if (typeof WebAssembly !== 'undefined') {
26
+ capabilities.webAssembly = true
27
+
28
+ if (typeof WebAssembly.compile === 'function') {
29
+ capabilities.webAssemblyCompile = true
30
+ }
31
+
32
+ if (typeof WebAssembly.instantiate === 'function') {
33
+ capabilities.webAssemblyInstantiate = true
34
+ }
35
+ }
36
+
37
+ // Web Worker support
38
+ if (typeof Worker !== 'undefined') {
39
+ capabilities.webWorkers = true
40
+ }
41
+
42
+ // Crypto.subtle support
43
+ if (typeof crypto !== 'undefined' && crypto.subtle) {
44
+ capabilities.cryptoSubtle = true
45
+ }
46
+ } catch (err) {
47
+ console.warn('Error detecting browser capabilities:', err.message)
48
+ }
49
+
50
+ return capabilities
51
+ }
52
+
53
+ // Test WebAssembly loading strategies
54
+ async function testWASMStrategies () {
55
+ console.log('🧪 Testing WebAssembly Loading Strategies...\n')
56
+
57
+ const capabilities = detectBrowserCapabilities()
58
+
59
+ console.log('šŸ“Š Browser Capabilities:')
60
+ console.log('═══════════════════════════════════════════════')
61
+ console.log(`WebAssembly Support: ${capabilities.webAssembly ? 'āœ…' : 'āŒ'}`)
62
+ console.log(`WebAssembly.compile: ${capabilities.webAssemblyCompile ? 'āœ…' : 'āŒ'}`)
63
+ console.log(`WebAssembly.instantiate: ${capabilities.webAssemblyInstantiate ? 'āœ…' : 'āŒ'}`)
64
+ console.log(`Web Workers: ${capabilities.webWorkers ? 'āœ…' : 'āŒ'}`)
65
+ console.log(`Crypto.subtle: ${capabilities.cryptoSubtle ? 'āœ…' : 'āŒ'}`)
66
+ console.log(`User Agent: ${capabilities.userAgent}`)
67
+ console.log('═══════════════════════════════════════════════\n')
68
+
69
+ // Test different loading strategies
70
+ const strategies = [
71
+ {
72
+ name: 'Async Compilation',
73
+ available: capabilities.webAssemblyCompile,
74
+ description: 'Modern async WebAssembly.compile() method'
75
+ },
76
+ {
77
+ name: 'Web Worker Compilation',
78
+ available: capabilities.webWorkers && capabilities.webAssembly,
79
+ description: 'Compile WASM in worker thread (bypasses main thread restrictions)'
80
+ },
81
+ {
82
+ name: 'Chunked Loading',
83
+ available: capabilities.webAssembly,
84
+ description: 'Split large WASM into smaller chunks'
85
+ },
86
+ {
87
+ name: 'JavaScript Fallbacks',
88
+ available: true,
89
+ description: 'Pure JavaScript crypto implementations (always available)'
90
+ }
91
+ ]
92
+
93
+ console.log('āš™ļø Available Loading Strategies:')
94
+ console.log('═══════════════════════════════════════════════')
95
+ strategies.forEach((strategy, index) => {
96
+ const status = strategy.available ? 'āœ… Available' : 'āŒ Not Available'
97
+ console.log(`${index + 1}. ${strategy.name}: ${status}`)
98
+ console.log(` ${strategy.description}`)
99
+ })
100
+ console.log('═══════════════════════════════════════════════\n')
101
+
102
+ return capabilities
103
+ }
104
+
105
+ // Test wallet initialization with WASM compatibility
106
+ async function testWalletCompatibility () {
107
+ console.log('šŸ¦ Testing Wallet Initialization...\n')
108
+
109
+ try {
110
+ console.log('Creating wallet instance...')
111
+ const startTime = Date.now()
112
+
113
+ // Create wallet (this will trigger WASM initialization)
114
+ const wallet = new MinimalXECWallet()
115
+
116
+ console.log('Waiting for wallet creation...')
117
+ await wallet.walletInfoPromise
118
+
119
+ console.log('Waiting for WASM initialization...')
120
+ const wasmResult = await wallet.wasmInitPromise
121
+
122
+ console.log('Initializing wallet services...')
123
+ await wallet.initialize()
124
+
125
+ const endTime = Date.now()
126
+ const initTime = endTime - startTime
127
+
128
+ console.log('āœ… Wallet initialization completed!')
129
+ console.log('═══════════════════════════════════════════════')
130
+ console.log(`Initialization Time: ${initTime}ms`)
131
+ console.log(`WASM Initialized: ${wasmResult ? 'āœ…' : 'āŒ (using fallbacks)'}`)
132
+ console.log(`Wallet Address: ${wallet.walletInfo.xecAddress}`)
133
+ console.log(`Wallet Created: ${wallet.walletInfoCreated ? 'āœ…' : 'āŒ'}`)
134
+ console.log(`Services Initialized: ${wallet.isInitialized ? 'āœ…' : 'āŒ'}`)
135
+ console.log('═══════════════════════════════════════════════\n')
136
+
137
+ return {
138
+ success: true,
139
+ initTime,
140
+ wasmResult,
141
+ address: wallet.walletInfo.xecAddress
142
+ }
143
+ } catch (err) {
144
+ console.error('āŒ Wallet initialization failed:')
145
+ console.error('═══════════════════════════════════════════════')
146
+ console.error(`Error: ${err.message}`)
147
+ console.error('═══════════════════════════════════════════════\n')
148
+
149
+ return {
150
+ success: false,
151
+ error: err.message
152
+ }
153
+ }
154
+ }
155
+
156
+ // Test basic wallet operations
157
+ async function testBasicOperations () {
158
+ console.log('šŸ”§ Testing Basic Wallet Operations...\n')
159
+
160
+ try {
161
+ const wallet = new MinimalXECWallet()
162
+ await wallet.walletInfoPromise
163
+ await wallet.wasmInitPromise
164
+ await wallet.initialize()
165
+
166
+ console.log('Testing wallet operations...')
167
+
168
+ // Test address validation
169
+ const isValidAddress = wallet._validateAddress(wallet.walletInfo.xecAddress)
170
+ console.log(`Address validation: ${isValidAddress ? 'āœ…' : 'āŒ'}`)
171
+
172
+ // Test key derivation
173
+ const keyPair = await wallet.getKeyPair(0)
174
+ console.log(`Key derivation: ${keyPair && keyPair.xecAddress ? 'āœ…' : 'āŒ'}`)
175
+
176
+ // Test WIF operations
177
+ const wif = wallet.exportPrivateKeyAsWIF()
178
+ const isValidWIF = wallet.validateWIF(wif)
179
+ console.log(`WIF operations: ${isValidWIF ? 'āœ…' : 'āŒ'}`)
180
+
181
+ // Test balance query (will fail without funds, but should not crash)
182
+ try {
183
+ await wallet.getXecBalance()
184
+ console.log('Balance query: āœ…')
185
+ } catch (err) {
186
+ console.log(`Balance query: āš ļø (${err.message})`)
187
+ }
188
+
189
+ console.log('\nāœ… Basic operations test completed!')
190
+ return true
191
+ } catch (err) {
192
+ console.error(`āŒ Basic operations failed: ${err.message}`)
193
+ return false
194
+ }
195
+ }
196
+
197
+ // Main test function
198
+ async function runCompatibilityTests () {
199
+ console.log('šŸš€ Minimal XEC Wallet - Browser Compatibility Test\n')
200
+ console.log('This test checks WebAssembly loading and fallback mechanisms.\n')
201
+
202
+ const results = {
203
+ capabilities: null,
204
+ walletInit: null,
205
+ basicOps: null
206
+ }
207
+
208
+ try {
209
+ // Test 1: Browser capabilities
210
+ results.capabilities = await testWASMStrategies()
211
+
212
+ // Test 2: Wallet initialization
213
+ results.walletInit = await testWalletCompatibility()
214
+
215
+ // Test 3: Basic operations (only if wallet init succeeded)
216
+ if (results.walletInit.success) {
217
+ results.basicOps = await testBasicOperations()
218
+ }
219
+
220
+ // Final report
221
+ console.log('\nšŸ“‹ Compatibility Test Summary:')
222
+ console.log('═══════════════════════════════════════════════')
223
+ console.log(`Browser Support: ${results.capabilities.webAssembly ? 'Modern' : 'Legacy'}`)
224
+ console.log(`Wallet Initialization: ${results.walletInit.success ? 'āœ…' : 'āŒ'}`)
225
+ console.log(`Basic Operations: ${results.basicOps ? 'āœ…' : results.walletInit.success ? 'Skipped' : 'āŒ'}`)
226
+
227
+ if (results.walletInit.success) {
228
+ console.log(`Initialization Time: ${results.walletInit.initTime}ms`)
229
+ console.log(`WASM Status: ${results.walletInit.wasmResult ? 'Active' : 'Fallback'}`)
230
+ }
231
+
232
+ console.log('═══════════════════════════════════════════════')
233
+
234
+ if (results.walletInit.success) {
235
+ console.log('\nšŸŽ‰ SUCCESS: Wallet is compatible with this browser!')
236
+ console.log('You can use all wallet features normally.')
237
+ } else {
238
+ console.log('\nāš ļø WARNING: Wallet initialization failed in this browser.')
239
+ console.log('Please check browser console for detailed error messages.')
240
+ }
241
+
242
+ console.log('\nšŸ“š For more info: https://github.com/your-repo/minimal-xec-wallet#browser-compatibility')
243
+ } catch (err) {
244
+ console.error('\nšŸ’„ Compatibility test crashed:', err.message)
245
+ console.error('Please report this issue with your browser details.')
246
+ }
247
+ }
248
+
249
+ // Run tests if this file is executed directly
250
+ if (require.main === module) {
251
+ runCompatibilityTests().catch(err => {
252
+ console.error('Test execution failed:', err)
253
+ process.exit(1)
254
+ })
255
+ }
256
+
257
+ module.exports = {
258
+ detectBrowserCapabilities,
259
+ testWASMStrategies,
260
+ testWalletCompatibility,
261
+ testBasicOperations,
262
+ runCompatibilityTests
263
+ }