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.
- package/LICENSE +21 -0
- package/README.md +241 -0
- package/dist/minimal-xec-wallet.js +66268 -0
- package/dist/minimal-xec-wallet.min.js +55 -0
- package/examples/README.md +380 -0
- package/examples/advanced/browser-compatibility-test.js +263 -0
- package/examples/advanced/get-xec-price.js +149 -0
- package/examples/advanced/optimize-utxos.js +255 -0
- package/examples/advanced/send-op-return.js +216 -0
- package/examples/browser-test.html +350 -0
- package/examples/key-management/derive-addresses.js +191 -0
- package/examples/key-management/export-to-wif.js +114 -0
- package/examples/key-management/validate-address.js +214 -0
- package/examples/optimization/simple-consolidation-test.js +79 -0
- package/examples/optimization/test-utxo-consolidation.js +179 -0
- package/examples/test-examples.js +1204 -0
- package/examples/tokens/burn-tokens.js +293 -0
- package/examples/tokens/get-token-balance.js +169 -0
- package/examples/tokens/get-token-info.js +269 -0
- package/examples/tokens/list-all-tokens.js +162 -0
- package/examples/tokens/send-any-token.js +260 -0
- package/examples/tokens/test-main-wallet-integration.js +193 -0
- package/examples/transactions/send-all-xec.js +205 -0
- package/examples/transactions/send-to-multiple.js +217 -0
- package/examples/transactions/send-xec.js +191 -0
- package/examples/utils/show-qr.js +119 -0
- package/examples/utils/wallet-helper.js +176 -0
- package/examples/validation/comprehensive-infrastructure-test.js +210 -0
- package/examples/wallet-creation/create-new-wallet.js +67 -0
- package/examples/wallet-creation/import-from-wif.js +135 -0
- package/examples/wallet-creation/restore-from-mnemonic.js +100 -0
- package/examples/wallet-info/get-balance.js +99 -0
- package/examples/wallet-info/get-transactions.js +157 -0
- package/examples/wallet-info/get-utxos.js +145 -0
- package/examples/wallet.json +11 -0
- package/lib/adapters/robust-chronik-router.js +507 -0
- package/lib/adapters/router.js +651 -0
- package/lib/alp-token-handler.js +581 -0
- package/lib/browser-wasm-loader.js +271 -0
- package/lib/consolidate-utxos.js +338 -0
- package/lib/hybrid-token-manager.js +322 -0
- package/lib/key-derivation.js +466 -0
- package/lib/op-return.js +314 -0
- package/lib/security.js +270 -0
- package/lib/send-xec.js +396 -0
- package/lib/slp-token-handler.js +572 -0
- package/lib/token-protocol-detector.js +307 -0
- package/lib/utxos.js +303 -0
- 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
|
+
}
|