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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stoyan Zhekov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# minimal-xec-wallet
|
|
2
|
+
|
|
3
|
+
A minimalist eCash (XEC) wallet npm library for web applications with full SLP and ALP token support.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/minimal-xec-wallet)
|
|
6
|
+
[](./test/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
## ๐ฏ Features
|
|
10
|
+
|
|
11
|
+
### โ
Core Wallet Operations
|
|
12
|
+
- **HD Wallets**: BIP44 hierarchical deterministic key generation
|
|
13
|
+
- **Import/Export**: Support for mnemonic phrases, WIF, and hex private keys
|
|
14
|
+
- **Address Management**: XEC address generation and validation
|
|
15
|
+
- **Balance Queries**: Real-time XEC balance with confirmed/unconfirmed breakdown
|
|
16
|
+
|
|
17
|
+
### โ
XEC Transactions
|
|
18
|
+
- **Send XEC**: Single and multi-output transactions
|
|
19
|
+
- **Send All**: Empty wallet functionality
|
|
20
|
+
- **Fee Optimization**: Intelligent UTXO selection and fee calculation
|
|
21
|
+
- **UTXO Consolidation**: Automatic optimization for better performance
|
|
22
|
+
|
|
23
|
+
### โ
eToken Support (SLP + ALP)
|
|
24
|
+
- **Protocol Auto-Detection**: Automatic SLP/ALP protocol identification
|
|
25
|
+
- **Token Operations**: Send, burn, list tokens across both protocols
|
|
26
|
+
- **Token Metadata**: Automatic fetching of token info (name, symbol, decimals)
|
|
27
|
+
- **Hybrid Management**: Unified API for both SLP and ALP tokens
|
|
28
|
+
|
|
29
|
+
### โ
Advanced Features
|
|
30
|
+
- **OP_RETURN**: Embed data in blockchain transactions
|
|
31
|
+
- **Security**: AES-256 mnemonic encryption, dust attack protection
|
|
32
|
+
- **Network Resilience**: Multiple Chronik endpoint failover
|
|
33
|
+
- **Price Queries**: Real-time XEC/USD pricing
|
|
34
|
+
|
|
35
|
+
## ๐ Quick Start
|
|
36
|
+
|
|
37
|
+
### Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install minimal-xec-wallet
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Basic Usage
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const MinimalXECWallet = require('minimal-xec-wallet')
|
|
47
|
+
|
|
48
|
+
// Create new wallet
|
|
49
|
+
const wallet = new MinimalXECWallet()
|
|
50
|
+
await wallet.initialize()
|
|
51
|
+
|
|
52
|
+
// Check balance
|
|
53
|
+
const balance = await wallet.getXecBalance()
|
|
54
|
+
console.log(`Balance: ${balance} XEC`)
|
|
55
|
+
|
|
56
|
+
// Send XEC
|
|
57
|
+
const txid = await wallet.sendXec([
|
|
58
|
+
{ address: 'ecash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy', amountSats: 10000 }
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
// List all tokens (SLP + ALP)
|
|
62
|
+
const tokens = await wallet.listETokens()
|
|
63
|
+
tokens.forEach(token => {
|
|
64
|
+
console.log(`${token.ticker}: ${token.balance}`)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Send tokens
|
|
68
|
+
await wallet.sendETokens('tokenId...', [
|
|
69
|
+
{ address: 'ecash:qp123...', amount: 100 }
|
|
70
|
+
])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Browser Usage
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script src="https://unpkg.com/minimal-xec-wallet/dist/minimal-xec-wallet.min.js"></script>
|
|
77
|
+
<script>
|
|
78
|
+
const wallet = new MinimalXecWallet()
|
|
79
|
+
|
|
80
|
+
// Initialize with automatic browser compatibility
|
|
81
|
+
wallet.initialize().then(() => {
|
|
82
|
+
console.log('Wallet ready for all browsers!')
|
|
83
|
+
// Use same API as Node.js
|
|
84
|
+
})
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Browser Compatibility**: Automatic WebAssembly loading with JavaScript fallbacks for older browsers. See [Browser Compatibility Guide](./docs/BROWSER_COMPATIBILITY.md) for details.
|
|
89
|
+
|
|
90
|
+
## ๐ Documentation
|
|
91
|
+
|
|
92
|
+
### API Reference
|
|
93
|
+
- **[Complete API Documentation](./WALLET_API.md)** - All methods with examples
|
|
94
|
+
- **[Examples Collection](./examples/README.md)** - 25+ working examples
|
|
95
|
+
- **[Development Docs](./docs/README.md)** - Architecture and implementation details
|
|
96
|
+
- **[Browser Compatibility Guide](./docs/BROWSER_COMPATIBILITY.md)** - WebAssembly and fallback support
|
|
97
|
+
|
|
98
|
+
### Quick Links
|
|
99
|
+
- **[Wallet Creation Examples](./examples/wallet-creation/)** - Create, restore, import wallets
|
|
100
|
+
- **[Transaction Examples](./examples/transactions/)** - Send XEC, multi-output, send-all
|
|
101
|
+
- **[Token Examples](./examples/tokens/)** - SLP/ALP token operations
|
|
102
|
+
- **[Advanced Examples](./examples/advanced/)** - OP_RETURN, optimization, price queries, compatibility testing
|
|
103
|
+
|
|
104
|
+
## ๐งช Testing
|
|
105
|
+
|
|
106
|
+
### Run Tests
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# All tests (424 unit + 29 integration)
|
|
110
|
+
npm run test:all
|
|
111
|
+
|
|
112
|
+
# Unit tests only (fast)
|
|
113
|
+
npm run test:unit
|
|
114
|
+
|
|
115
|
+
# Integration tests (requires network)
|
|
116
|
+
npm run test:integration
|
|
117
|
+
|
|
118
|
+
# Test coverage report
|
|
119
|
+
npm run test:coverage
|
|
120
|
+
|
|
121
|
+
# Browser compatibility test
|
|
122
|
+
node examples/advanced/browser-compatibility-test.js
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Example Testing
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Run all examples with guided testing
|
|
129
|
+
node examples/test-examples.js
|
|
130
|
+
|
|
131
|
+
# Test specific functionality
|
|
132
|
+
node examples/tokens/list-all-tokens.js
|
|
133
|
+
node examples/transactions/send-xec.js
|
|
134
|
+
|
|
135
|
+
# Test browser compatibility
|
|
136
|
+
node examples/advanced/browser-compatibility-test.js
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## ๐๏ธ Architecture
|
|
140
|
+
|
|
141
|
+
### Modern Design
|
|
142
|
+
- **Modular Architecture**: Clean separation of concerns
|
|
143
|
+
- **Protocol Agnostic**: Supports both SLP and ALP token standards
|
|
144
|
+
- **Network Resilient**: Multiple Chronik endpoint failover
|
|
145
|
+
- **Security First**: Built-in protections against common attacks
|
|
146
|
+
|
|
147
|
+
### Core Components
|
|
148
|
+
- **HybridTokenManager**: Unified SLP/ALP token operations
|
|
149
|
+
- **RobustChronikRouter**: Network failover and error handling
|
|
150
|
+
- **ConsolidateUtxos**: UTXO optimization engine
|
|
151
|
+
- **KeyDerivation**: HD wallet key management
|
|
152
|
+
|
|
153
|
+
### Dependencies
|
|
154
|
+
- **chronik-client**: eCash blockchain indexer
|
|
155
|
+
- **ecash-lib**: Core eCash transaction building
|
|
156
|
+
- **@scure/bip39**: Secure mnemonic generation
|
|
157
|
+
- **crypto-js**: AES encryption for mnemonics
|
|
158
|
+
|
|
159
|
+
## ๐ง Advanced Configuration
|
|
160
|
+
|
|
161
|
+
### Custom Options
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
const wallet = new MinimalXECWallet(mnemonic, {
|
|
165
|
+
hdPath: "m/44'/899'/0'/0/0", // Custom derivation path
|
|
166
|
+
fee: 2.0, // Fee rate in sats/byte
|
|
167
|
+
chronikUrls: ['https://chronik.e.cash'], // Custom endpoints
|
|
168
|
+
enableDonations: false, // Privacy mode
|
|
169
|
+
password: 'secure123' // Mnemonic encryption
|
|
170
|
+
})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Environment Variables
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Test mode
|
|
177
|
+
NODE_ENV=test npm test
|
|
178
|
+
|
|
179
|
+
# Development mode
|
|
180
|
+
NODE_ENV=development npm start
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## ๐ค Contributing
|
|
184
|
+
|
|
185
|
+
### Development Setup
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
git clone https://github.com/zh/minimal-xec-wallet
|
|
189
|
+
cd minimal-xec-wallet
|
|
190
|
+
npm install
|
|
191
|
+
npm run test:unit
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Code Quality
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Linting
|
|
198
|
+
npm run lint
|
|
199
|
+
|
|
200
|
+
# Build for browser
|
|
201
|
+
npm run build
|
|
202
|
+
|
|
203
|
+
# Generate API docs
|
|
204
|
+
npm run docs
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## ๐ Project Stats
|
|
208
|
+
|
|
209
|
+
- **424 Unit Tests** - Comprehensive coverage of all features
|
|
210
|
+
- **29 Integration Tests** - Real network validation
|
|
211
|
+
- **25+ Examples** - Working code for all use cases
|
|
212
|
+
- **6 Token Protocols** - SLP Type 1, ALP Standard, auto-detection
|
|
213
|
+
- **7 Chronik Endpoints** - Robust network failover
|
|
214
|
+
|
|
215
|
+
## ๐ Resources
|
|
216
|
+
|
|
217
|
+
### eCash Ecosystem
|
|
218
|
+
- **[eCash.org](https://e.cash)** - Official eCash website
|
|
219
|
+
- **[CashTab Wallet](https://cashtab.com)** - Reference web wallet
|
|
220
|
+
- **[Block Explorer](https://explorer.e.cash)** - Transaction lookup
|
|
221
|
+
|
|
222
|
+
### Development
|
|
223
|
+
- **[Chronik Indexer](https://chronik.e.cash/)** - Blockchain API
|
|
224
|
+
- **[ecash-lib Documentation](https://www.npmjs.com/package/ecash-lib)** - Core library
|
|
225
|
+
- **[SLP Specification](https://github.com/badger-cash/slp-specification)** - Token standard
|
|
226
|
+
- **[ALP Specification](https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/doc/standards/empp.md)** - ALP token standard
|
|
227
|
+
|
|
228
|
+
## ๐ License
|
|
229
|
+
|
|
230
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
231
|
+
|
|
232
|
+
## ๐ค Support
|
|
233
|
+
|
|
234
|
+
- **Issues**: [GitHub Issues](https://github.com/your-repo/minimal-xec-wallet/issues)
|
|
235
|
+
- **Examples**: See `./examples` directory for working code
|
|
236
|
+
- **API Docs**: Run `npm run docs` for detailed API documentation
|
|
237
|
+
- **Community**: eCash developer channels
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
**Security Notice**: This library handles real cryptocurrency. Always test with small amounts first and keep your mnemonic phrases secure.
|