@bsv/sdk 1.9.3 → 1.9.4
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/dist/cjs/package.json +1 -1
- package/docs/fast-docs.png +0 -0
- package/docs/index.md +49 -44
- package/docs/swagger.png +0 -0
- package/package.json +1 -1
- package/docs/MARKDOWN_VALIDATION_GUIDE.md +0 -175
- package/docs/concepts/beef.md +0 -92
- package/docs/concepts/chain-tracking.md +0 -134
- package/docs/concepts/decentralized-identity.md +0 -221
- package/docs/concepts/fees.md +0 -249
- package/docs/concepts/identity-certificates.md +0 -307
- package/docs/concepts/index.md +0 -77
- package/docs/concepts/key-management.md +0 -185
- package/docs/concepts/script-templates.md +0 -176
- package/docs/concepts/sdk-philosophy.md +0 -80
- package/docs/concepts/signatures.md +0 -194
- package/docs/concepts/spv-verification.md +0 -118
- package/docs/concepts/transaction-encoding.md +0 -167
- package/docs/concepts/transaction-structure.md +0 -67
- package/docs/concepts/trust-model.md +0 -139
- package/docs/concepts/verification.md +0 -250
- package/docs/concepts/wallet-integration.md +0 -101
- package/docs/guides/development-wallet-setup.md +0 -374
- package/docs/guides/direct-transaction-creation.md +0 -147
- package/docs/guides/http-client-configuration.md +0 -488
- package/docs/guides/index.md +0 -138
- package/docs/guides/large-transactions.md +0 -448
- package/docs/guides/multisig-transactions.md +0 -792
- package/docs/guides/security-best-practices.md +0 -494
- package/docs/guides/transaction-batching.md +0 -132
- package/docs/guides/transaction-signing-methods.md +0 -419
- package/docs/reference/arc-config.md +0 -698
- package/docs/reference/brc-100.md +0 -33
- package/docs/reference/configuration.md +0 -835
- package/docs/reference/debugging.md +0 -705
- package/docs/reference/errors.md +0 -597
- package/docs/reference/index.md +0 -111
- package/docs/reference/network-config.md +0 -914
- package/docs/reference/op-codes.md +0 -325
- package/docs/reference/transaction-signatures.md +0 -95
- package/docs/tutorials/advanced-transaction.md +0 -572
- package/docs/tutorials/aes-encryption.md +0 -949
- package/docs/tutorials/authfetch-tutorial.md +0 -986
- package/docs/tutorials/ecdh-key-exchange.md +0 -549
- package/docs/tutorials/elliptic-curve-fundamentals.md +0 -606
- package/docs/tutorials/error-handling.md +0 -1216
- package/docs/tutorials/first-transaction-low-level.md +0 -205
- package/docs/tutorials/first-transaction.md +0 -275
- package/docs/tutorials/hashes-and-hmacs.md +0 -788
- package/docs/tutorials/identity-management.md +0 -729
- package/docs/tutorials/index.md +0 -219
- package/docs/tutorials/key-management.md +0 -538
- package/docs/tutorials/protowallet-development.md +0 -743
- package/docs/tutorials/script-construction.md +0 -690
- package/docs/tutorials/spv-merkle-proofs.md +0 -685
- package/docs/tutorials/testnet-transactions-low-level.md +0 -359
- package/docs/tutorials/transaction-broadcasting.md +0 -538
- package/docs/tutorials/transaction-types.md +0 -420
- package/docs/tutorials/type-42.md +0 -568
- package/docs/tutorials/uhrp-storage.md +0 -599
package/docs/reference/errors.md
DELETED
|
@@ -1,597 +0,0 @@
|
|
|
1
|
-
# Error Reference
|
|
2
|
-
|
|
3
|
-
Complete reference for error codes, messages, and troubleshooting in the BSV TypeScript SDK.
|
|
4
|
-
|
|
5
|
-
## Error Categories
|
|
6
|
-
|
|
7
|
-
### Transaction Errors
|
|
8
|
-
|
|
9
|
-
#### INSUFFICIENT_FUNDS
|
|
10
|
-
|
|
11
|
-
**Code**: `INSUFFICIENT_FUNDS`
|
|
12
|
-
**Message**: "Insufficient funds to create transaction"
|
|
13
|
-
**Cause**: Wallet doesn't have enough UTXOs to cover transaction outputs and fees
|
|
14
|
-
**Solutions**:
|
|
15
|
-
|
|
16
|
-
- Check wallet balance with `listOutputs()`
|
|
17
|
-
- Reduce transaction amount
|
|
18
|
-
- Wait for pending transactions to confirm
|
|
19
|
-
- Use smaller fee rates
|
|
20
|
-
|
|
21
|
-
#### INVALID_TRANSACTION
|
|
22
|
-
|
|
23
|
-
**Code**: `INVALID_TRANSACTION`
|
|
24
|
-
**Message**: "Transaction validation failed"
|
|
25
|
-
**Cause**: Transaction structure or signatures are invalid
|
|
26
|
-
**Solutions**:
|
|
27
|
-
|
|
28
|
-
- Verify all inputs are properly signed
|
|
29
|
-
- Check script templates are correct
|
|
30
|
-
- Ensure transaction format is valid
|
|
31
|
-
- Validate all output amounts are positive
|
|
32
|
-
|
|
33
|
-
#### TRANSACTION_TOO_LARGE
|
|
34
|
-
|
|
35
|
-
**Code**: `TRANSACTION_TOO_LARGE`
|
|
36
|
-
**Message**: "Transaction exceeds maximum size limit"
|
|
37
|
-
**Cause**: Transaction size exceeds network limits
|
|
38
|
-
**Solutions**:
|
|
39
|
-
|
|
40
|
-
- Reduce number of inputs/outputs
|
|
41
|
-
- Use more efficient script templates
|
|
42
|
-
- Split into multiple transactions
|
|
43
|
-
- Optimize data storage methods
|
|
44
|
-
|
|
45
|
-
#### INVALID_SCRIPT
|
|
46
|
-
|
|
47
|
-
**Code**: `INVALID_SCRIPT`
|
|
48
|
-
**Message**: "Script execution failed"
|
|
49
|
-
**Cause**: Locking or unlocking script contains errors
|
|
50
|
-
**Solutions**:
|
|
51
|
-
|
|
52
|
-
- Validate script syntax with `Script.fromASM()`
|
|
53
|
-
- Check opcode usage and limits
|
|
54
|
-
- Verify script template implementation
|
|
55
|
-
- Test script execution in isolation
|
|
56
|
-
|
|
57
|
-
### Wallet Errors
|
|
58
|
-
|
|
59
|
-
#### WALLET_NOT_CONNECTED
|
|
60
|
-
|
|
61
|
-
**Code**: `WALLET_NOT_CONNECTED`
|
|
62
|
-
**Message**: "Wallet connection not established"
|
|
63
|
-
**Cause**: WalletClient not connected to substrate
|
|
64
|
-
**Solutions**:
|
|
65
|
-
|
|
66
|
-
- Call `await wallet.connectToSubstrate()`
|
|
67
|
-
- Check wallet application is running
|
|
68
|
-
- Verify network connectivity
|
|
69
|
-
- Restart wallet application if needed
|
|
70
|
-
|
|
71
|
-
#### AUTHENTICATION_FAILED
|
|
72
|
-
|
|
73
|
-
**Code**: `AUTHENTICATION_FAILED`
|
|
74
|
-
**Message**: "Wallet authentication failed"
|
|
75
|
-
**Cause**: User denied access or authentication expired
|
|
76
|
-
**Solutions**:
|
|
77
|
-
|
|
78
|
-
- Re-authenticate with wallet
|
|
79
|
-
- Check originator domain permissions
|
|
80
|
-
- Verify wallet trust settings
|
|
81
|
-
- Clear cached authentication state
|
|
82
|
-
|
|
83
|
-
#### WALLET_LOCKED
|
|
84
|
-
|
|
85
|
-
**Code**: `WALLET_LOCKED`
|
|
86
|
-
**Message**: "Wallet is locked or requires password"
|
|
87
|
-
**Cause**: Wallet requires user authentication
|
|
88
|
-
**Solutions**:
|
|
89
|
-
|
|
90
|
-
- Unlock wallet application
|
|
91
|
-
- Enter wallet password
|
|
92
|
-
- Check wallet auto-lock settings
|
|
93
|
-
- Verify user session is active
|
|
94
|
-
|
|
95
|
-
#### ACTION_REJECTED
|
|
96
|
-
|
|
97
|
-
**Code**: `ACTION_REJECTED`
|
|
98
|
-
**Message**: "User rejected the transaction"
|
|
99
|
-
**Cause**: User declined transaction in wallet UI
|
|
100
|
-
**Solutions**:
|
|
101
|
-
|
|
102
|
-
- Retry transaction with user consent
|
|
103
|
-
- Adjust transaction parameters
|
|
104
|
-
- Provide clearer transaction description
|
|
105
|
-
- Check transaction amounts and fees
|
|
106
|
-
|
|
107
|
-
### Network Errors
|
|
108
|
-
|
|
109
|
-
#### NETWORK_ERROR
|
|
110
|
-
|
|
111
|
-
**Code**: `NETWORK_ERROR`
|
|
112
|
-
**Message**: "Network request failed"
|
|
113
|
-
**Cause**: Connection issues with blockchain nodes
|
|
114
|
-
**Solutions**:
|
|
115
|
-
|
|
116
|
-
- Check internet connectivity
|
|
117
|
-
- Verify node endpoints are accessible
|
|
118
|
-
- Try alternative chain trackers
|
|
119
|
-
- Implement retry logic with exponential backoff
|
|
120
|
-
|
|
121
|
-
#### NODE_UNAVAILABLE
|
|
122
|
-
|
|
123
|
-
**Code**: `NODE_UNAVAILABLE`
|
|
124
|
-
**Message**: "Blockchain node is unavailable"
|
|
125
|
-
**Cause**: Target node is down or unreachable
|
|
126
|
-
**Solutions**:
|
|
127
|
-
|
|
128
|
-
- Switch to backup node endpoints
|
|
129
|
-
- Check node status and health
|
|
130
|
-
- Use multiple chain tracker instances
|
|
131
|
-
- Implement failover mechanisms
|
|
132
|
-
|
|
133
|
-
#### BROADCAST_FAILED
|
|
134
|
-
|
|
135
|
-
**Code**: `BROADCAST_FAILED`
|
|
136
|
-
**Message**: "Transaction broadcast failed"
|
|
137
|
-
**Cause**: Network rejected transaction or broadcast error
|
|
138
|
-
**Solutions**:
|
|
139
|
-
|
|
140
|
-
- Verify transaction is valid
|
|
141
|
-
- Check network fees are adequate
|
|
142
|
-
- Retry broadcast after delay
|
|
143
|
-
- Use alternative broadcast endpoints
|
|
144
|
-
|
|
145
|
-
#### TIMEOUT_ERROR
|
|
146
|
-
|
|
147
|
-
**Code**: `TIMEOUT_ERROR`
|
|
148
|
-
**Message**: "Request timeout exceeded"
|
|
149
|
-
**Cause**: Network request took too long
|
|
150
|
-
**Solutions**:
|
|
151
|
-
|
|
152
|
-
- Increase timeout values
|
|
153
|
-
- Check network latency
|
|
154
|
-
- Use faster endpoints
|
|
155
|
-
- Implement request cancellation
|
|
156
|
-
|
|
157
|
-
### Cryptographic Errors
|
|
158
|
-
|
|
159
|
-
#### INVALID_PRIVATE_KEY
|
|
160
|
-
|
|
161
|
-
**Code**: `INVALID_PRIVATE_KEY`
|
|
162
|
-
**Message**: "Private key is invalid or out of range"
|
|
163
|
-
**Cause**: Private key doesn't meet secp256k1 requirements
|
|
164
|
-
**Solutions**:
|
|
165
|
-
|
|
166
|
-
- Generate new key with `PrivateKey.fromRandom()`
|
|
167
|
-
- Validate key is within curve order
|
|
168
|
-
- Check key format and encoding
|
|
169
|
-
- Use proper key derivation methods
|
|
170
|
-
|
|
171
|
-
#### INVALID_PUBLIC_KEY
|
|
172
|
-
|
|
173
|
-
**Code**: `INVALID_PUBLIC_KEY`
|
|
174
|
-
**Message**: "Public key is invalid or not on curve"
|
|
175
|
-
**Cause**: Public key point is invalid
|
|
176
|
-
**Solutions**:
|
|
177
|
-
|
|
178
|
-
- Verify key derivation from private key
|
|
179
|
-
- Check point coordinates are valid
|
|
180
|
-
- Validate key format (compressed/uncompressed)
|
|
181
|
-
- Use `PublicKey.fromPrivateKey()` for generation
|
|
182
|
-
|
|
183
|
-
#### SIGNATURE_VERIFICATION_FAILED
|
|
184
|
-
|
|
185
|
-
**Code**: `SIGNATURE_VERIFICATION_FAILED`
|
|
186
|
-
**Message**: "Digital signature verification failed"
|
|
187
|
-
**Cause**: Signature doesn't match message and public key
|
|
188
|
-
**Solutions**:
|
|
189
|
-
|
|
190
|
-
- Verify message hash is correct
|
|
191
|
-
- Check signature format (DER encoding)
|
|
192
|
-
- Ensure correct public key is used
|
|
193
|
-
- Validate signature components (r, s values)
|
|
194
|
-
|
|
195
|
-
#### ENCRYPTION_FAILED
|
|
196
|
-
|
|
197
|
-
**Code**: `ENCRYPTION_FAILED`
|
|
198
|
-
**Message**: "Symmetric encryption operation failed"
|
|
199
|
-
**Cause**: AES encryption/decryption error
|
|
200
|
-
**Solutions**:
|
|
201
|
-
|
|
202
|
-
- Verify encryption key is valid
|
|
203
|
-
- Check data format and encoding
|
|
204
|
-
- Ensure proper IV/nonce usage
|
|
205
|
-
- Validate authentication tags
|
|
206
|
-
|
|
207
|
-
### SPV Verification Errors
|
|
208
|
-
|
|
209
|
-
#### INVALID_MERKLE_PROOF
|
|
210
|
-
|
|
211
|
-
**Code**: `INVALID_MERKLE_PROOF`
|
|
212
|
-
**Message**: "Merkle proof verification failed"
|
|
213
|
-
**Cause**: Merkle path doesn't lead to valid root
|
|
214
|
-
**Solutions**:
|
|
215
|
-
|
|
216
|
-
- Verify merkle path structure
|
|
217
|
-
- Check transaction hash calculation
|
|
218
|
-
- Validate block header merkle root
|
|
219
|
-
- Ensure proof completeness
|
|
220
|
-
|
|
221
|
-
#### BLOCK_HEADER_INVALID
|
|
222
|
-
|
|
223
|
-
**Code**: `BLOCK_HEADER_INVALID`
|
|
224
|
-
**Message**: "Block header validation failed"
|
|
225
|
-
**Cause**: Block header doesn't meet consensus rules
|
|
226
|
-
**Solutions**:
|
|
227
|
-
|
|
228
|
-
- Verify header hash and difficulty
|
|
229
|
-
- Check timestamp validity
|
|
230
|
-
- Validate previous block hash
|
|
231
|
-
- Ensure proper header format
|
|
232
|
-
|
|
233
|
-
#### CHAIN_VALIDATION_FAILED
|
|
234
|
-
|
|
235
|
-
**Code**: `CHAIN_VALIDATION_FAILED`
|
|
236
|
-
**Message**: "Blockchain validation failed"
|
|
237
|
-
**Cause**: Chain doesn't follow consensus rules
|
|
238
|
-
**Solutions**:
|
|
239
|
-
|
|
240
|
-
- Verify chain continuity
|
|
241
|
-
- Check difficulty adjustments
|
|
242
|
-
- Validate block timestamps
|
|
243
|
-
- Ensure proper chain selection
|
|
244
|
-
|
|
245
|
-
### Configuration Errors
|
|
246
|
-
|
|
247
|
-
#### INVALID_CONFIG
|
|
248
|
-
|
|
249
|
-
**Code**: `INVALID_CONFIG`
|
|
250
|
-
**Message**: "SDK configuration is invalid"
|
|
251
|
-
**Cause**: Configuration parameters are incorrect
|
|
252
|
-
**Solutions**:
|
|
253
|
-
|
|
254
|
-
- Validate configuration schema
|
|
255
|
-
- Check required parameters are present
|
|
256
|
-
- Verify network settings
|
|
257
|
-
- Use default configuration as baseline
|
|
258
|
-
|
|
259
|
-
#### UNSUPPORTED_NETWORK
|
|
260
|
-
|
|
261
|
-
**Code**: `UNSUPPORTED_NETWORK`
|
|
262
|
-
**Message**: "Network type is not supported"
|
|
263
|
-
**Cause**: Invalid network specification
|
|
264
|
-
**Solutions**:
|
|
265
|
-
|
|
266
|
-
- Use supported networks: mainnet, testnet, regtest
|
|
267
|
-
- Check network configuration
|
|
268
|
-
- Verify chain parameters
|
|
269
|
-
- Update SDK to latest version
|
|
270
|
-
|
|
271
|
-
## Error Interface
|
|
272
|
-
|
|
273
|
-
All SDK errors implement the `WalletErrorObject` interface:
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
interface WalletErrorObject {
|
|
277
|
-
code: string
|
|
278
|
-
description: string
|
|
279
|
-
stack?: string
|
|
280
|
-
context?: Record<string, any>
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Error Handling Patterns
|
|
285
|
-
|
|
286
|
-
### Basic Error Handling
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
try {
|
|
290
|
-
const result = await wallet.createAction({
|
|
291
|
-
description: 'Test transaction',
|
|
292
|
-
outputs: [{
|
|
293
|
-
satoshis: 100,
|
|
294
|
-
lockingScript: Script.fromASM('OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG').toHex()
|
|
295
|
-
}]
|
|
296
|
-
})
|
|
297
|
-
} catch (error) {
|
|
298
|
-
if (error.code === 'INSUFFICIENT_FUNDS') {
|
|
299
|
-
console.log('Not enough funds available')
|
|
300
|
-
// Handle insufficient funds
|
|
301
|
-
} else if (error.code === 'WALLET_NOT_CONNECTED') {
|
|
302
|
-
console.log('Wallet connection required')
|
|
303
|
-
await wallet.connectToSubstrate()
|
|
304
|
-
} else {
|
|
305
|
-
console.error('Unexpected error:', error)
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### Retry Logic with Exponential Backoff
|
|
311
|
-
|
|
312
|
-
```typescript
|
|
313
|
-
async function retryOperation<T>(
|
|
314
|
-
operation: () => Promise<T>,
|
|
315
|
-
maxRetries: number = 3,
|
|
316
|
-
baseDelay: number = 1000
|
|
317
|
-
): Promise<T> {
|
|
318
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
319
|
-
try {
|
|
320
|
-
return await operation()
|
|
321
|
-
} catch (error) {
|
|
322
|
-
if (attempt === maxRetries) throw error
|
|
323
|
-
|
|
324
|
-
// Only retry on network errors
|
|
325
|
-
if (!['NETWORK_ERROR', 'TIMEOUT_ERROR', 'NODE_UNAVAILABLE'].includes(error.code)) {
|
|
326
|
-
throw error
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const delay = baseDelay * Math.pow(2, attempt)
|
|
330
|
-
await new Promise(resolve => setTimeout(resolve, delay))
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
throw new Error('Max retries exceeded')
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### Comprehensive Error Categorization
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
function categorizeError(error: WalletErrorObject): 'user' | 'network' | 'system' | 'config' {
|
|
341
|
-
const userErrors = ['ACTION_REJECTED', 'AUTHENTICATION_FAILED', 'WALLET_LOCKED']
|
|
342
|
-
const networkErrors = ['NETWORK_ERROR', 'NODE_UNAVAILABLE', 'BROADCAST_FAILED', 'TIMEOUT_ERROR']
|
|
343
|
-
const systemErrors = ['INVALID_TRANSACTION', 'SIGNATURE_VERIFICATION_FAILED', 'ENCRYPTION_FAILED']
|
|
344
|
-
const configErrors = ['INVALID_CONFIG', 'UNSUPPORTED_NETWORK']
|
|
345
|
-
|
|
346
|
-
if (userErrors.includes(error.code)) return 'user'
|
|
347
|
-
if (networkErrors.includes(error.code)) return 'network'
|
|
348
|
-
if (systemErrors.includes(error.code)) return 'system'
|
|
349
|
-
if (configErrors.includes(error.code)) return 'config'
|
|
350
|
-
|
|
351
|
-
return 'system' // Default category
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## Troubleshooting Guide
|
|
356
|
-
|
|
357
|
-
### Common Issues and Solutions
|
|
358
|
-
|
|
359
|
-
#### "RPC Error: no header should have returned false"
|
|
360
|
-
|
|
361
|
-
**Symptoms**: Error during `createAction` calls
|
|
362
|
-
**Cause**: Wallet input selection issues
|
|
363
|
-
**Solutions**:
|
|
364
|
-
|
|
365
|
-
1. Restart wallet application
|
|
366
|
-
2. Ensure wallet is fully synced
|
|
367
|
-
3. Use slightly larger amounts (200-500 satoshis)
|
|
368
|
-
4. Wait for wallet synchronization
|
|
369
|
-
5. Check for sufficient confirmed UTXOs
|
|
370
|
-
|
|
371
|
-
#### "Insufficient funds" with Available Balance
|
|
372
|
-
|
|
373
|
-
**Symptoms**: Error despite wallet showing balance
|
|
374
|
-
**Cause**: UTXOs not properly selected by wallet
|
|
375
|
-
**Solutions**:
|
|
376
|
-
|
|
377
|
-
1. Check UTXO status with `listOutputs()`
|
|
378
|
-
2. Verify UTXOs are confirmed
|
|
379
|
-
3. Restart wallet to refresh UTXO cache
|
|
380
|
-
4. Use manual input selection if supported
|
|
381
|
-
|
|
382
|
-
#### Transaction Broadcast Failures
|
|
383
|
-
|
|
384
|
-
**Symptoms**: Valid transactions rejected by network
|
|
385
|
-
**Cause**: Various network or validation issues
|
|
386
|
-
**Solutions**:
|
|
387
|
-
|
|
388
|
-
1. Verify transaction format and signatures
|
|
389
|
-
2. Check fee rates are adequate
|
|
390
|
-
3. Ensure inputs are unspent
|
|
391
|
-
4. Try alternative broadcast endpoints
|
|
392
|
-
|
|
393
|
-
#### Wallet Connection Issues
|
|
394
|
-
|
|
395
|
-
**Symptoms**: Cannot connect to wallet substrate
|
|
396
|
-
**Cause**: Wallet not running or permission issues
|
|
397
|
-
**Solutions**:
|
|
398
|
-
|
|
399
|
-
1. Ensure wallet application is running
|
|
400
|
-
2. Check originator domain permissions
|
|
401
|
-
3. Clear browser cache and cookies
|
|
402
|
-
4. Verify wallet trust settings
|
|
403
|
-
|
|
404
|
-
### Diagnostic Tools
|
|
405
|
-
|
|
406
|
-
#### Transaction Validation
|
|
407
|
-
|
|
408
|
-
```typescript
|
|
409
|
-
function validateTransaction(tx: Transaction): string[] {
|
|
410
|
-
const errors: string[] = []
|
|
411
|
-
|
|
412
|
-
if (tx.inputs.length === 0) {
|
|
413
|
-
errors.push('Transaction must have at least one input')
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (tx.outputs.length === 0) {
|
|
417
|
-
errors.push('Transaction must have at least one output')
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const totalInput = tx.inputs.reduce((sum, input) => sum + input.satoshis, 0)
|
|
421
|
-
const totalOutput = tx.outputs.reduce((sum, output) => sum + output.satoshis, 0)
|
|
422
|
-
|
|
423
|
-
if (totalInput <= totalOutput) {
|
|
424
|
-
errors.push('Insufficient input value to cover outputs and fees')
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return errors
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
#### Network Connectivity Test
|
|
432
|
-
|
|
433
|
-
```typescript
|
|
434
|
-
async function testNetworkConnectivity(chainTracker: ChainTracker): Promise<boolean> {
|
|
435
|
-
try {
|
|
436
|
-
const height = await chainTracker.getHeight()
|
|
437
|
-
return height > 0
|
|
438
|
-
} catch (error) {
|
|
439
|
-
console.error('Network connectivity test failed:', error)
|
|
440
|
-
return false
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
#### Wallet Health Check
|
|
446
|
-
|
|
447
|
-
```typescript
|
|
448
|
-
async function checkWalletHealth(wallet: WalletClient): Promise<{
|
|
449
|
-
connected: boolean
|
|
450
|
-
authenticated: boolean
|
|
451
|
-
balance: number
|
|
452
|
-
errors: string[]
|
|
453
|
-
}> {
|
|
454
|
-
const result = {
|
|
455
|
-
connected: false,
|
|
456
|
-
authenticated: false,
|
|
457
|
-
balance: 0,
|
|
458
|
-
errors: [] as string[]
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
try {
|
|
462
|
-
await wallet.connectToSubstrate()
|
|
463
|
-
result.connected = true
|
|
464
|
-
} catch (error) {
|
|
465
|
-
result.errors.push(`Connection failed: ${error.message}`)
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
try {
|
|
469
|
-
const outputs = await wallet.listOutputs({ limit: 1 })
|
|
470
|
-
result.authenticated = true
|
|
471
|
-
result.balance = outputs.totalValue || 0
|
|
472
|
-
} catch (error) {
|
|
473
|
-
result.errors.push(`Authentication failed: ${error.message}`)
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
return result
|
|
477
|
-
}
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
## Error Recovery Strategies
|
|
481
|
-
|
|
482
|
-
### Automatic Recovery
|
|
483
|
-
|
|
484
|
-
```typescript
|
|
485
|
-
class ErrorRecoveryManager {
|
|
486
|
-
private retryAttempts = new Map<string, number>()
|
|
487
|
-
private maxRetries = 3
|
|
488
|
-
|
|
489
|
-
async executeWithRecovery<T>(
|
|
490
|
-
operation: () => Promise<T>,
|
|
491
|
-
operationId: string
|
|
492
|
-
): Promise<T> {
|
|
493
|
-
try {
|
|
494
|
-
const result = await operation()
|
|
495
|
-
this.retryAttempts.delete(operationId)
|
|
496
|
-
return result
|
|
497
|
-
} catch (error) {
|
|
498
|
-
return this.handleError(error, operation, operationId)
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
private async handleError<T>(
|
|
503
|
-
error: WalletErrorObject,
|
|
504
|
-
operation: () => Promise<T>,
|
|
505
|
-
operationId: string
|
|
506
|
-
): Promise<T> {
|
|
507
|
-
const attempts = this.retryAttempts.get(operationId) || 0
|
|
508
|
-
|
|
509
|
-
if (attempts >= this.maxRetries) {
|
|
510
|
-
this.retryAttempts.delete(operationId)
|
|
511
|
-
throw error
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// Implement recovery strategies based on error type
|
|
515
|
-
switch (error.code) {
|
|
516
|
-
case 'WALLET_NOT_CONNECTED':
|
|
517
|
-
await this.reconnectWallet()
|
|
518
|
-
break
|
|
519
|
-
case 'NETWORK_ERROR':
|
|
520
|
-
await this.switchToBackupNode()
|
|
521
|
-
break
|
|
522
|
-
case 'INSUFFICIENT_FUNDS':
|
|
523
|
-
await this.waitForConfirmations()
|
|
524
|
-
break
|
|
525
|
-
default:
|
|
526
|
-
throw error // No recovery strategy available
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
this.retryAttempts.set(operationId, attempts + 1)
|
|
530
|
-
return this.executeWithRecovery(operation, operationId)
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
private async reconnectWallet(): Promise<void> {
|
|
534
|
-
// Implement wallet reconnection logic
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
private async switchToBackupNode(): Promise<void> {
|
|
538
|
-
// Implement node failover logic
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
private async waitForConfirmations(): Promise<void> {
|
|
542
|
-
// Wait for pending transactions to confirm
|
|
543
|
-
await new Promise(resolve => setTimeout(resolve, 30000))
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
## Best Practices
|
|
549
|
-
|
|
550
|
-
### Error Logging
|
|
551
|
-
|
|
552
|
-
```typescript
|
|
553
|
-
class ErrorLogger {
|
|
554
|
-
static log(error: WalletErrorObject, context?: Record<string, any>): void {
|
|
555
|
-
const logEntry = {
|
|
556
|
-
timestamp: new Date().toISOString(),
|
|
557
|
-
code: error.code,
|
|
558
|
-
message: error.description,
|
|
559
|
-
context: { ...error.context, ...context },
|
|
560
|
-
stack: error.stack
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// Log to appropriate destination based on severity
|
|
564
|
-
if (this.isCriticalError(error.code)) {
|
|
565
|
-
console.error('CRITICAL ERROR:', logEntry)
|
|
566
|
-
} else {
|
|
567
|
-
console.warn('ERROR:', logEntry)
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
private static isCriticalError(code: string): boolean {
|
|
572
|
-
return [
|
|
573
|
-
'INVALID_PRIVATE_KEY',
|
|
574
|
-
'SIGNATURE_VERIFICATION_FAILED',
|
|
575
|
-
'CHAIN_VALIDATION_FAILED'
|
|
576
|
-
].includes(code)
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
### User-Friendly Error Messages
|
|
582
|
-
|
|
583
|
-
```typescript
|
|
584
|
-
function getUserFriendlyMessage(error: WalletErrorObject): string {
|
|
585
|
-
const messages: Record<string, string> = {
|
|
586
|
-
'INSUFFICIENT_FUNDS': 'You don\'t have enough funds for this transaction.',
|
|
587
|
-
'ACTION_REJECTED': 'Transaction was cancelled.',
|
|
588
|
-
'WALLET_NOT_CONNECTED': 'Please connect your wallet to continue.',
|
|
589
|
-
'NETWORK_ERROR': 'Network connection issue. Please try again.',
|
|
590
|
-
'INVALID_TRANSACTION': 'Transaction format is invalid. Please check your inputs.'
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return messages[error.code] || 'An unexpected error occurred. Please try again.'
|
|
594
|
-
}
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
This comprehensive error reference provides developers with the tools and knowledge needed to handle all types of errors that may occur when using the BSV TypeScript SDK.
|
package/docs/reference/index.md
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# Reference Documentation
|
|
2
|
-
|
|
3
|
-
Complete technical specifications and API documentation for the BSV TypeScript SDK.
|
|
4
|
-
|
|
5
|
-
## Standards and Interfaces
|
|
6
|
-
|
|
7
|
-
### [BRC-100 Wallet Interface](./brc-100.md)
|
|
8
|
-
|
|
9
|
-
- Unified wallet-to-application interface standard
|
|
10
|
-
- WalletClient implementation details
|
|
11
|
-
- JSON API specifications
|
|
12
|
-
|
|
13
|
-
## Core Classes
|
|
14
|
-
|
|
15
|
-
### [Transaction Class](./transaction.md)
|
|
16
|
-
|
|
17
|
-
- Constructor options and methods
|
|
18
|
-
- Input/output management
|
|
19
|
-
- Serialization formats
|
|
20
|
-
|
|
21
|
-
### [PrivateKey/PublicKey Classes](./primitives.md)
|
|
22
|
-
|
|
23
|
-
- Key generation methods
|
|
24
|
-
- Import/export formats
|
|
25
|
-
- Cryptographic operations
|
|
26
|
-
|
|
27
|
-
### [Transaction Signatures Reference](./transaction-signatures.md)
|
|
28
|
-
|
|
29
|
-
- ECDSA signature components
|
|
30
|
-
- DER encoding format
|
|
31
|
-
- Signature hash types (SIGHASH flags)
|
|
32
|
-
|
|
33
|
-
### [Script Classes](./script.md)
|
|
34
|
-
|
|
35
|
-
- Script construction utilities
|
|
36
|
-
- Standard script templates
|
|
37
|
-
- Custom script patterns
|
|
38
|
-
|
|
39
|
-
### [OP Codes Reference](./op-codes.md)
|
|
40
|
-
|
|
41
|
-
- Complete opcode listing and descriptions
|
|
42
|
-
- Opcode categories and usage patterns
|
|
43
|
-
- Script execution examples
|
|
44
|
-
|
|
45
|
-
## Module Reference
|
|
46
|
-
|
|
47
|
-
### [Primitives Module](./primitives.md)
|
|
48
|
-
|
|
49
|
-
- Cryptographic primitives
|
|
50
|
-
- Hash functions
|
|
51
|
-
- Security implementation notes
|
|
52
|
-
|
|
53
|
-
### [Transaction Module](./transaction.md)
|
|
54
|
-
|
|
55
|
-
- Transaction lifecycle
|
|
56
|
-
- Fee calculation details
|
|
57
|
-
- Broadcasting options
|
|
58
|
-
- SPV verification
|
|
59
|
-
|
|
60
|
-
### [Wallet Module](./wallet.md)
|
|
61
|
-
|
|
62
|
-
- Wallet architecture patterns
|
|
63
|
-
- Integration guidelines
|
|
64
|
-
- BRC-100 compliance notes
|
|
65
|
-
|
|
66
|
-
## Configuration Reference
|
|
67
|
-
|
|
68
|
-
### [SDK Configuration Options](./configuration.md)
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
interface SDKConfig {
|
|
72
|
-
network: 'mainnet' | 'testnet' | 'regtest'
|
|
73
|
-
arc: ARCConfig
|
|
74
|
-
fees: FeeConfig
|
|
75
|
-
security: SecurityConfig
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### [ARC Configuration](./arc-config.md)
|
|
80
|
-
|
|
81
|
-
- Endpoint configuration
|
|
82
|
-
- Authentication methods
|
|
83
|
-
- Rate limiting options
|
|
84
|
-
- Failover settings
|
|
85
|
-
|
|
86
|
-
### [Network Configuration](./network-config.md)
|
|
87
|
-
|
|
88
|
-
- Mainnet vs testnet settings
|
|
89
|
-
- Custom network parameters
|
|
90
|
-
- Node endpoint configurations
|
|
91
|
-
|
|
92
|
-
## Error Reference
|
|
93
|
-
|
|
94
|
-
### [Error Codes and Messages](./errors.md)
|
|
95
|
-
|
|
96
|
-
- Transaction validation errors
|
|
97
|
-
- Network connectivity errors
|
|
98
|
-
- Cryptographic operation errors
|
|
99
|
-
- Troubleshooting steps
|
|
100
|
-
|
|
101
|
-
### [Debugging Guide](./debugging.md)
|
|
102
|
-
|
|
103
|
-
- SDK logging configuration
|
|
104
|
-
- Debug mode activation
|
|
105
|
-
- Transaction inspection tools
|
|
106
|
-
|
|
107
|
-
## Swagger
|
|
108
|
-
|
|
109
|
-
[BRC-100](https://brc.dev/100) defines a Unified, Vendor-Neutral, Unchanging, and Open BSV Blockchain Standard Wallet-to-Application Interface which is implemented in this library within the WalletClient class. The API is laid out here as a swagger openapi document to offer a fast-track to understanding the interface which is implemented across multiple substrates. The JSON api is generally considered a developer friendly introduction to the WalletClient, where an binary equivalent ABI may be preferred for production use cases.
|
|
110
|
-
|
|
111
|
-
- [Wallet JSON API Swagger](../swagger)
|