@bsv/sdk 1.6.12 → 1.6.14

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 (82) hide show
  1. package/README.md +4 -4
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  4. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  5. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  6. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  7. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  8. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  9. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  10. package/dist/umd/bundle.js +1 -1
  11. package/docs/MARKDOWN_VALIDATION_GUIDE.md +175 -0
  12. package/docs/concepts/beef.md +8 -0
  13. package/docs/concepts/chain-tracking.md +12 -0
  14. package/docs/concepts/decentralized-identity.md +37 -0
  15. package/docs/concepts/fees.md +32 -0
  16. package/docs/concepts/identity-certificates.md +53 -1
  17. package/docs/concepts/index.md +15 -0
  18. package/docs/concepts/key-management.md +9 -0
  19. package/docs/concepts/script-templates.md +13 -0
  20. package/docs/concepts/sdk-philosophy.md +8 -0
  21. package/docs/concepts/signatures.md +15 -0
  22. package/docs/concepts/spv-verification.md +12 -0
  23. package/docs/concepts/transaction-encoding.md +19 -0
  24. package/docs/concepts/transaction-structure.md +4 -0
  25. package/docs/concepts/trust-model.md +16 -0
  26. package/docs/concepts/verification.md +31 -0
  27. package/docs/concepts/wallet-integration.md +6 -0
  28. package/docs/guides/development-wallet-setup.md +374 -0
  29. package/docs/guides/direct-transaction-creation.md +12 -2
  30. package/docs/guides/http-client-configuration.md +122 -48
  31. package/docs/guides/index.md +117 -9
  32. package/docs/guides/large-transactions.md +448 -0
  33. package/docs/guides/multisig-transactions.md +792 -0
  34. package/docs/guides/security-best-practices.md +494 -0
  35. package/docs/guides/transaction-batching.md +132 -0
  36. package/docs/guides/transaction-signing-methods.md +230 -79
  37. package/docs/index.md +0 -2
  38. package/docs/reference/auth.md +212 -159
  39. package/docs/reference/compat.md +120 -96
  40. package/docs/reference/configuration.md +6 -0
  41. package/docs/reference/debugging.md +5 -0
  42. package/docs/reference/errors.md +50 -0
  43. package/docs/reference/identity.md +21 -12
  44. package/docs/reference/index.md +14 -1
  45. package/docs/reference/kvstore.md +21 -19
  46. package/docs/reference/messages.md +3 -0
  47. package/docs/reference/op-codes.md +20 -1
  48. package/docs/reference/overlay-tools.md +46 -18
  49. package/docs/reference/primitives.md +571 -390
  50. package/docs/reference/registry.md +43 -20
  51. package/docs/reference/script.md +140 -105
  52. package/docs/reference/storage.md +32 -12
  53. package/docs/reference/totp.md +16 -11
  54. package/docs/reference/transaction-signatures.md +2 -1
  55. package/docs/reference/transaction.md +201 -120
  56. package/docs/reference/wallet.md +241 -64
  57. package/docs/tutorials/advanced-transaction.md +1 -4
  58. package/docs/tutorials/aes-encryption.md +3 -1
  59. package/docs/tutorials/authfetch-tutorial.md +29 -0
  60. package/docs/tutorials/ecdh-key-exchange.md +2 -0
  61. package/docs/tutorials/elliptic-curve-fundamentals.md +3 -0
  62. package/docs/tutorials/error-handling.md +1 -0
  63. package/docs/tutorials/first-transaction-low-level.md +1 -0
  64. package/docs/tutorials/first-transaction.md +5 -8
  65. package/docs/tutorials/hashes-and-hmacs.md +5 -31
  66. package/docs/tutorials/identity-management.md +27 -0
  67. package/docs/tutorials/index.md +114 -77
  68. package/docs/tutorials/key-management.md +5 -3
  69. package/docs/tutorials/protowallet-development.md +27 -0
  70. package/docs/tutorials/spv-merkle-proofs.md +9 -6
  71. package/docs/tutorials/testnet-transactions-low-level.md +25 -18
  72. package/docs/tutorials/transaction-broadcasting.md +10 -7
  73. package/docs/tutorials/transaction-types.md +5 -4
  74. package/docs/tutorials/type-42.md +0 -14
  75. package/docs/tutorials/uhrp-storage.md +23 -3
  76. package/package.json +1 -1
  77. package/src/identity/README.md +0 -1
  78. package/src/primitives/__tests/SymmetricKey.test.ts +45 -0
  79. package/src/primitives/__tests/SymmetricKeyCompatibility.test.ts +150 -0
  80. package/src/transaction/__tests/Transaction.test.ts +1 -1
  81. package/src/transaction/broadcasters/DefaultBroadcaster.ts +1 -1
  82. package/src/transaction/broadcasters/__tests/ARC.test.ts +1 -1
@@ -0,0 +1,175 @@
1
+ # Markdown Validation Guide for Teranode Documentation
2
+
3
+ This guide provides comprehensive solutions to prevent and catch markdown formatting issues that cause problems in Material MkDocs rendering.
4
+
5
+ ## 🛠️ Available Validation Tools
6
+
7
+ ### 1. Pre-commit Hooks (Automatic)
8
+
9
+ **Setup**: Already configured in `.pre-commit-config.yaml`
10
+
11
+ - **markdownlint**: Catches formatting issues before commits
12
+ - **Configuration**: `.markdownlint.yml` with rules tailored for Material MkDocs
13
+
14
+ **Usage**:
15
+
16
+ ```bash
17
+ # Install pre-commit hooks
18
+ pre-commit install
19
+
20
+ # Run manually on all files
21
+ pre-commit run markdownlint --all-files
22
+ ```
23
+
24
+ ### 2. Custom Validation Script
25
+
26
+ **Location**: `scripts/validate-markdown.py`
27
+
28
+ **Features**:
29
+
30
+ - Detects missing blank lines before lists
31
+ - Finds inconsistent nested bullet indentation
32
+ - Identifies configuration parameters missing Type/Default/Impact details
33
+ - Can automatically fix issues with `--fix` flag
34
+
35
+ **Usage**:
36
+
37
+ ```bash
38
+ # Validate all documentation
39
+ python3 scripts/validate-markdown.py docs/
40
+
41
+ # Validate and auto-fix issues
42
+ python3 scripts/validate-markdown.py docs/ --fix
43
+
44
+ # Validate single file
45
+ python3 scripts/validate-markdown.py docs/topics/services/alert.md
46
+ ```
47
+
48
+ ### 3. VS Code Extensions (Real-time)
49
+
50
+ **Recommended Extensions**:
51
+
52
+ - **markdownlint**: Real-time linting in editor
53
+ - **Markdown All in One**: Preview and formatting
54
+ - **Material Theme**: Better syntax highlighting
55
+
56
+ **Setup**:
57
+
58
+ 1. Install extensions
59
+ 2. Add to VS Code settings.json:
60
+
61
+ ```json
62
+ {
63
+ "markdownlint.config": {
64
+ "MD007": { "indent": 4 },
65
+ "MD032": true,
66
+ "MD013": false
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## 🎯 Common Issues & Prevention
72
+
73
+ ### Issue 1: Missing Blank Lines Before Lists
74
+
75
+ **Problem**: Lists render inline instead of as proper lists
76
+ **Solution**: Always add blank line before lists
77
+
78
+ ```markdown
79
+ ❌ Wrong:
80
+ Configuration options:
81
+
82
+ - Option 1
83
+ - Option 2
84
+
85
+ ✅ Correct:
86
+ Configuration options:
87
+
88
+ - Option 1
89
+ - Option 2
90
+ ```
91
+
92
+ ### Issue 2: Inconsistent Nested Indentation
93
+
94
+ **Problem**: Nested items don't render as nested
95
+ **Solution**: Use exactly 4 spaces for nested items
96
+
97
+ ```markdown
98
+ ❌ Wrong:
99
+
100
+ - Main item
101
+ - Nested item (2 spaces)
102
+
103
+ ✅ Correct:
104
+
105
+ - Main item
106
+ - Nested item (4 spaces)
107
+ ```
108
+
109
+ ### Issue 3: Configuration Parameter Formatting
110
+
111
+ **Problem**: Inconsistent parameter documentation
112
+ **Solution**: Use standard format for all parameters
113
+
114
+ ```markdown
115
+ ✅ Standard Format:
116
+ 1. **`parameter_name`**: Brief description.
117
+ - Type: string
118
+ - Default: "value"
119
+ - Impact: Detailed explanation of what this controls.
120
+ ```
121
+
122
+ ## 🚀 Workflow Integration
123
+
124
+ ### Daily Development
125
+
126
+ 1. **VS Code Extensions**: Real-time feedback while editing
127
+ 2. **Pre-commit Hooks**: Automatic validation before commits
128
+ 3. **Custom Script**: Bulk validation and fixes
129
+
130
+ ### CI/CD Pipeline
131
+
132
+ 1. **GitHub Actions**: Validate all PRs
133
+ 2. **Deployment**: Only deploy if validation passes
134
+
135
+ ### Periodic Maintenance
136
+
137
+ ```bash
138
+ # Weekly validation run
139
+ python3 scripts/validate-markdown.py docs/ --fix
140
+ git add -A
141
+ git commit -m "docs: fix markdown formatting issues"
142
+ ```
143
+
144
+ ## 📋 Validation Checklist
145
+
146
+ Before committing documentation changes:
147
+
148
+ - [ ] Run custom validation script
149
+ - [ ] Check pre-commit hooks pass
150
+ - [ ] Preview in Material MkDocs locally
151
+ - [ ] Verify nested lists render correctly
152
+ - [ ] Confirm configuration parameters follow standard format
153
+
154
+ ## 🔧 Quick Fixes
155
+
156
+ **Fix all formatting issues in docs**:
157
+
158
+ ```bash
159
+ python3 scripts/validate-markdown.py docs/ --fix
160
+ ```
161
+
162
+ **Run markdownlint**:
163
+
164
+ ```bash
165
+ markdownlint docs/ --config .markdownlint.yml --fix
166
+ ```
167
+
168
+ **Preview locally**:
169
+
170
+ ```bash
171
+ mkdocs serve
172
+ # Open http://localhost:8000
173
+ ```
174
+
175
+ This multi-layered approach ensures high-quality, consistently formatted documentation that renders perfectly in Material MkDocs.
@@ -5,6 +5,7 @@ Bitcoin Extras Extension Format (BEEF) - an efficient way to package Bitcoin tra
5
5
  ## What is BEEF?
6
6
 
7
7
  BEEF is a standardized format that combines:
8
+
8
9
  - **Transaction Data**: The actual Bitcoin transaction
9
10
  - **Merkle Proofs**: SPV verification data
10
11
  - **Block Headers**: Chain validation information
@@ -28,16 +29,19 @@ const isValid = await tx.verify(chainTracker)
28
29
  ## Key Benefits
29
30
 
30
31
  ### Efficiency
32
+
31
33
  - **Compact**: Includes only necessary verification data
32
34
  - **Self-Contained**: No external lookups required
33
35
  - **Batch Processing**: Multiple transactions in one package
34
36
 
35
37
  ### SPV Integration
38
+
36
39
  - **Merkle Proofs**: Verify transaction inclusion
37
40
  - **Block Headers**: Validate proof of work
38
41
  - **Chain Context**: Understand transaction position
39
42
 
40
43
  ### Interoperability
44
+
41
45
  - **Standardized**: Consistent format across applications
42
46
  - **Portable**: Easy to transmit and store
43
47
  - **Compatible**: Works with SPV clients
@@ -45,6 +49,7 @@ const isValid = await tx.verify(chainTracker)
45
49
  ## Use Cases
46
50
 
47
51
  ### Transaction Broadcasting
52
+
48
53
  ```typescript
49
54
  // Broadcast transaction with proof
50
55
  const beefTx = Transaction.fromHexBEEF(beefData)
@@ -52,11 +57,13 @@ await beefTx.broadcast(arcConfig)
52
57
  ```
53
58
 
54
59
  ### Data Exchange
60
+
55
61
  - Share transactions between applications
56
62
  - Provide verification data to SPV clients
57
63
  - Archive transactions with proofs
58
64
 
59
65
  ### Wallet Integration
66
+
60
67
  - Import transactions with full context
61
68
  - Verify historical transactions
62
69
  - Synchronize between devices
@@ -64,6 +71,7 @@ await beefTx.broadcast(arcConfig)
64
71
  ## BEEF Structure
65
72
 
66
73
  The format includes:
74
+
67
75
  1. **Version**: BEEF format version
68
76
  2. **Transactions**: One or more Bitcoin transactions
69
77
  3. **Proofs**: Merkle proofs for each transaction
@@ -19,21 +19,25 @@ const txData = await chainTracker.getTransaction('txid')
19
19
  ## Key Functions
20
20
 
21
21
  ### Transaction Lookup
22
+
22
23
  - Retrieve transaction details by ID
23
24
  - Get transaction status and confirmations
24
25
  - Access transaction inputs and outputs
25
26
 
26
27
  ### UTXO Queries
28
+
27
29
  - Find unspent transaction outputs
28
30
  - Check UTXO availability and value
29
31
  - Retrieve UTXO locking scripts
30
32
 
31
33
  ### Block Information
34
+
32
35
  - Get block headers and merkle proofs
33
36
  - Verify transaction inclusion in blocks
34
37
  - Access block timestamps and difficulty
35
38
 
36
39
  ### Network Status
40
+
37
41
  - Check network connectivity
38
42
  - Monitor chain tip and height
39
43
  - Get fee rate recommendations
@@ -41,6 +45,7 @@ const txData = await chainTracker.getTransaction('txid')
41
45
  ## SPV Integration
42
46
 
43
47
  Chain trackers enable SPV (Simplified Payment Verification):
48
+
44
49
  - **Merkle Proofs**: Verify transaction inclusion without full blocks
45
50
  - **Header Chain**: Maintain block headers for proof verification
46
51
  - **Lightweight**: Minimal data requirements compared to full nodes
@@ -63,16 +68,19 @@ const config = {
63
68
  ## Benefits
64
69
 
65
70
  ### Scalability
71
+
66
72
  - No need to store the entire blockchain
67
73
  - Fast startup and synchronization
68
74
  - Minimal storage requirements
69
75
 
70
76
  ### Reliability
77
+
71
78
  - Multiple provider support
72
79
  - Automatic failover capabilities
73
80
  - Redundant data sources
74
81
 
75
82
  ### Performance
83
+
76
84
  - Targeted data queries
77
85
  - Caching of frequently accessed data
78
86
  - Optimized for application needs
@@ -80,6 +88,7 @@ const config = {
80
88
  ## Common Patterns
81
89
 
82
90
  ### Transaction Verification
91
+
83
92
  ```typescript
84
93
  // Verify a transaction exists
85
94
  const exists = await chainTracker.getTransaction(txid)
@@ -89,6 +98,7 @@ if (exists) {
89
98
  ```
90
99
 
91
100
  ### UTXO Validation
101
+
92
102
  ```typescript
93
103
  // Check if UTXO is still unspent
94
104
  const utxo = await chainTracker.getUTXO(txid, outputIndex)
@@ -100,6 +110,7 @@ if (utxo) {
100
110
  ## Error Handling
101
111
 
102
112
  Chain tracker operations can fail due to:
113
+
103
114
  - Network connectivity issues
104
115
  - Service provider downtime
105
116
  - Invalid transaction IDs
@@ -110,6 +121,7 @@ The SDK provides automatic retry and failover mechanisms.
110
121
  ## Configuration
111
122
 
112
123
  Chain trackers can be configured for:
124
+
113
125
  - **Network**: Mainnet, testnet, or regtest
114
126
  - **Endpoints**: Custom service URLs
115
127
  - **Timeouts**: Request timeout settings
@@ -11,7 +11,9 @@ This is the promise of decentralized identity: **self-sovereign identity** that
11
11
  ## Why Decentralized Identity Matters
12
12
 
13
13
  ### The Problem with Centralized Identity
14
+
14
15
  Traditional identity systems have significant limitations:
16
+
15
17
  - **Single Points of Failure**: If the identity provider goes down, you lose access
16
18
  - **Privacy Concerns**: Companies collect and monetize your personal data
17
19
  - **Vendor Lock-in**: You can't easily move your identity between services
@@ -19,7 +21,9 @@ Traditional identity systems have significant limitations:
19
21
  - **Data Breaches**: Centralized databases are attractive targets for hackers
20
22
 
21
23
  ### The Decentralized Solution
24
+
22
25
  Decentralized identity addresses these issues by:
26
+
23
27
  - **User Control**: You own and manage your identity data
24
28
  - **No Central Authority**: No single entity controls the verification process
25
29
  - **Interoperability**: Your identity works across different applications
@@ -29,15 +33,18 @@ Decentralized identity addresses these issues by:
29
33
  ## How It Works in BSV
30
34
 
31
35
  ### Identity Keys vs Transaction Keys
36
+
32
37
  BSV uses different types of keys for different purposes:
33
38
 
34
39
  **Identity Keys** are long-term, stable identifiers used for:
40
+
35
41
  - Establishing your digital identity
36
42
  - Signing identity certificates
37
43
  - Resolving your public profile information
38
44
  - Authenticating with services
39
45
 
40
46
  **Transaction Keys** are used for:
47
+
41
48
  - Signing Bitcoin transactions
42
49
  - Managing UTXOs and payments
43
50
  - Protocol-specific operations
@@ -45,7 +52,9 @@ BSV uses different types of keys for different purposes:
45
52
  This separation provides both security and privacy benefits.
46
53
 
47
54
  ### Identity Resolution
55
+
48
56
  Your identity key serves as a unique identifier that can be used to discover:
57
+
49
58
  - Your chosen display name and profile information
50
59
  - Verification badges and trust indicators
51
60
  - Public certificates and credentials
@@ -54,6 +63,7 @@ Your identity key serves as a unique identifier that can be used to discover:
54
63
  Think of it like a decentralized phone book where your identity key is your number, but instead of just finding your phone number, people can discover rich identity information that you've chosen to make public.
55
64
 
56
65
  ### Certificate-Based Trust
66
+
57
67
  Instead of trusting a central authority, decentralized identity relies on a web of cryptographic certificates. These certificates are like digital testimonials that others can independently verify:
58
68
 
59
69
  - **Self-Signed Certificates**: Claims you make about yourself
@@ -64,13 +74,17 @@ Instead of trusting a central authority, decentralized identity relies on a web
64
74
  ## Trust and Verification Models
65
75
 
66
76
  ### Web of Trust
77
+
67
78
  In a web of trust model, users verify each other's identities, creating networks of trusted relationships. This is similar to how you might trust a friend's recommendation about a restaurant - the more trusted connections someone has, the more credible they become.
68
79
 
69
80
  ### Institutional Trust
81
+
70
82
  Some applications require higher assurance levels, so they rely on certificates from recognized institutions like universities, professional licensing boards, or government agencies. These certificates carry more weight because the issuers have established reputations and verification processes.
71
83
 
72
84
  ### Hybrid Approaches
85
+
73
86
  Most real-world applications use a combination of trust models, adjusting requirements based on context. For example:
87
+
74
88
  - **Low-risk interactions** might accept self-signed certificates
75
89
  - **Financial transactions** might require institutional verification
76
90
  - **Professional networking** might emphasize peer verification within industry groups
@@ -78,36 +92,46 @@ Most real-world applications use a combination of trust models, adjusting requir
78
92
  ## Privacy and Selective Disclosure
79
93
 
80
94
  ### Controlling Your Information
95
+
81
96
  One of the key benefits of decentralized identity is granular control over your personal information. You can:
97
+
82
98
  - Choose which attributes to make publicly discoverable
83
99
  - Reveal different information to different parties
84
100
  - Prove claims without revealing underlying data
85
101
  - Revoke access to previously shared information
86
102
 
87
103
  ### Zero-Knowledge Proofs
104
+
88
105
  Advanced cryptographic techniques allow you to prove things about yourself without revealing the underlying information. For example, you could prove you're over 21 without revealing your exact age or birthdate.
89
106
 
90
107
  ### Progressive Disclosure
108
+
91
109
  As trust builds between parties, you might choose to reveal more information. This allows relationships to develop naturally while maintaining privacy protection.
92
110
 
93
111
  ## Identity Lifecycle
94
112
 
95
113
  ### Getting Started
114
+
96
115
  Creating a decentralized identity involves:
116
+
97
117
  1. **Generating an identity key pair** (handled by your wallet)
98
118
  2. **Creating basic profile information** (name, avatar, contact preferences)
99
119
  3. **Obtaining initial certificates** to establish credibility
100
120
  4. **Making your identity discoverable** through resolution networks
101
121
 
102
122
  ### Building Trust
123
+
103
124
  Over time, you accumulate certificates and verifications that build your reputation:
125
+
104
126
  - Verify your email address and social media accounts
105
127
  - Get endorsements from colleagues and friends
106
128
  - Obtain professional certifications and credentials
107
129
  - Participate in community verification programs
108
130
 
109
131
  ### Maintaining Privacy
132
+
110
133
  As your identity grows, you maintain control by:
134
+
111
135
  - Regularly reviewing what information is public
112
136
  - Updating privacy preferences as needs change
113
137
  - Revoking outdated or unwanted certificates
@@ -116,46 +140,59 @@ As your identity grows, you maintain control by:
116
140
  ## Real-World Applications
117
141
 
118
142
  ### Passwordless Authentication
143
+
119
144
  Instead of remembering dozens of passwords, you can authenticate using your identity certificates. This is more secure than passwords and eliminates the need for password managers.
120
145
 
121
146
  ### Professional Networking
147
+
122
148
  Verify professional credentials, work history, and skills through cryptographic certificates rather than relying on self-reported information on traditional platforms.
123
149
 
124
150
  ### Age and Identity Verification
151
+
125
152
  Prove your age for restricted services without revealing your exact birthdate, or verify your identity for account creation without sharing unnecessary personal information.
126
153
 
127
154
  ### Reputation Systems
155
+
128
156
  Build portable reputation that follows you across different platforms and applications, creating incentives for good behavior and reducing fraud.
129
157
 
130
158
  ### Decentralized Social Networks
159
+
131
160
  Participate in social networks where your identity and connections are owned by you, not the platform, enabling true social media portability.
132
161
 
133
162
  ## Benefits for Developers
134
163
 
135
164
  ### Simplified User Onboarding
165
+
136
166
  Instead of building complex registration and verification systems, applications can rely on existing identity infrastructure and certificates.
137
167
 
138
168
  ### Enhanced Security
169
+
139
170
  Cryptographic identity verification is more secure than traditional username/password systems and reduces the risk of account takeovers.
140
171
 
141
172
  ### Regulatory Compliance
173
+
142
174
  Decentralized identity can help meet KYC (Know Your Customer) and AML (Anti-Money Laundering) requirements while preserving user privacy.
143
175
 
144
176
  ### Interoperability
177
+
145
178
  Users can bring their identity and reputation from other applications, reducing friction and improving user experience.
146
179
 
147
180
  ## Challenges and Considerations
148
181
 
149
182
  ### User Experience
183
+
150
184
  Decentralized identity requires users to understand new concepts like key management and certificate verification. Good wallet software and user interfaces are essential for adoption.
151
185
 
152
186
  ### Recovery and Backup
187
+
153
188
  Unlike centralized systems where you can reset your password, losing access to your identity keys can be permanent. Robust backup and recovery mechanisms are crucial.
154
189
 
155
190
  ### Network Effects
191
+
156
192
  The value of decentralized identity increases as more people and organizations participate. Early adoption requires overcoming the "chicken and egg" problem.
157
193
 
158
194
  ### Scalability
195
+
159
196
  As identity networks grow, efficient resolution and verification mechanisms become increasingly important to maintain performance.
160
197
 
161
198
  ## The Future of Identity
@@ -20,6 +20,7 @@ const customFee = tx.getFee(feePerKB)
20
20
  ## Fee Calculation
21
21
 
22
22
  Fees are calculated based on transaction size:
23
+
23
24
  - **Fee Rate**: Satoshis per kilobyte (sat/kB)
24
25
  - **Transaction Size**: Total bytes in serialized transaction
25
26
  - **Total Fee**: Size × Fee Rate
@@ -27,7 +28,9 @@ Fees are calculated based on transaction size:
27
28
  ## SDK Fee Handling
28
29
 
29
30
  ### Automatic Fee Calculation
31
+
30
32
  The SDK calculates fees automatically:
33
+
31
34
  ```typescript
32
35
  // Wallet handles fees automatically
33
36
  const wallet = new WalletClient()
@@ -41,7 +44,9 @@ const action = await wallet.createAction({
41
44
  ```
42
45
 
43
46
  ### Manual Fee Control
47
+
44
48
  For advanced use cases:
49
+
45
50
  ```typescript
46
51
  // Calculate fee manually
47
52
  const tx = new Transaction()
@@ -55,12 +60,15 @@ const feeRequired = estimatedSize * feePerByte
55
60
  ## Fee Rates
56
61
 
57
62
  ### Network Fee Rates
63
+
58
64
  BSV typically uses low, predictable fees:
65
+
59
66
  - **Standard Rate**: ~0.5 sat/byte
60
67
  - **Priority Rate**: ~1.0 sat/byte
61
68
  - **Economy Rate**: ~0.1 sat/byte
62
69
 
63
70
  ### Dynamic Fee Estimation
71
+
64
72
  ```typescript
65
73
  // Get current network fee rates
66
74
  const feeRates = await chainTracker.getFeeRates()
@@ -70,20 +78,26 @@ const recommendedFee = feeRates.standard
70
78
  ## Fee Components
71
79
 
72
80
  ### Input Costs
81
+
73
82
  Each input adds to transaction size:
83
+
74
84
  - Previous transaction hash (32 bytes)
75
85
  - Output index (4 bytes)
76
86
  - Unlocking script (variable)
77
87
  - Sequence number (4 bytes)
78
88
 
79
89
  ### Output Costs
90
+
80
91
  Each output adds to transaction size:
92
+
81
93
  - Value (8 bytes)
82
94
  - Locking script length (1-9 bytes)
83
95
  - Locking script (variable)
84
96
 
85
97
  ### Base Transaction
98
+
86
99
  Fixed overhead for every transaction:
100
+
87
101
  - Version (4 bytes)
88
102
  - Input count (1-9 bytes)
89
103
  - Output count (1-9 bytes)
@@ -92,7 +106,9 @@ Fixed overhead for every transaction:
92
106
  ## Fee Optimization
93
107
 
94
108
  ### UTXO Selection
109
+
95
110
  Choose UTXOs efficiently:
111
+
96
112
  ```typescript
97
113
  // Prefer fewer, larger UTXOs to reduce fees
98
114
  const utxos = await wallet.getUTXOs()
@@ -100,7 +116,9 @@ const selected = selectOptimalUTXOs(utxos, targetAmount)
100
116
  ```
101
117
 
102
118
  ### Output Consolidation
119
+
103
120
  Combine multiple payments:
121
+
104
122
  ```typescript
105
123
  // Batch multiple outputs in one transaction
106
124
  const outputs = [
@@ -111,7 +129,9 @@ const outputs = [
111
129
  ```
112
130
 
113
131
  ### Script Efficiency
132
+
114
133
  Use efficient script templates:
134
+
115
135
  ```typescript
116
136
  // P2PKH is more efficient than complex scripts
117
137
  const p2pkh = new P2PKH()
@@ -121,7 +141,9 @@ const efficientScript = p2pkh.lock(publicKeyHash)
121
141
  ## Fee Estimation
122
142
 
123
143
  ### Size Estimation
144
+
124
145
  Estimate transaction size before creation:
146
+
125
147
  ```typescript
126
148
  // Estimate size for fee calculation
127
149
  const estimatedInputs = 2
@@ -131,6 +153,7 @@ const estimatedFee = estimatedSize * feeRate
131
153
  ```
132
154
 
133
155
  ### Template-Based Estimation
156
+
134
157
  ```typescript
135
158
  // Use script templates for accurate estimation
136
159
  const template = new P2PKH()
@@ -140,6 +163,7 @@ const scriptSize = template.estimateLength([publicKeyHash])
140
163
  ## Error Handling
141
164
 
142
165
  Common fee-related issues:
166
+
143
167
  - Insufficient funds for fees
144
168
  - Fee rate too low for network
145
169
  - Transaction size miscalculation
@@ -160,18 +184,21 @@ try {
160
184
  ## Best Practices
161
185
 
162
186
  ### Fee Management
187
+
163
188
  - Always account for fees in balance calculations
164
189
  - Use appropriate fee rates for urgency
165
190
  - Monitor network conditions for fee adjustments
166
191
  - Implement fee estimation before transaction creation
167
192
 
168
193
  ### Cost Optimization
194
+
169
195
  - Batch transactions when possible
170
196
  - Use efficient script templates
171
197
  - Optimize UTXO selection
172
198
  - Consider transaction timing
173
199
 
174
200
  ### User Experience
201
+
175
202
  - Display estimated fees to users
176
203
  - Provide fee rate options (economy, standard, priority)
177
204
  - Handle insufficient fund errors gracefully
@@ -180,6 +207,7 @@ try {
180
207
  ## Wallet Integration
181
208
 
182
209
  Most applications rely on wallets for fee handling:
210
+
183
211
  ```typescript
184
212
  // Wallet manages fees automatically
185
213
  const wallet = new WalletClient()
@@ -194,7 +222,9 @@ const result = await wallet.createAction({
194
222
  ## Advanced Fee Strategies
195
223
 
196
224
  ### Replace-by-Fee (RBF)
225
+
197
226
  Increase fees for faster confirmation:
227
+
198
228
  ```typescript
199
229
  // Create transaction with RBF enabled
200
230
  const tx = new Transaction()
@@ -202,7 +232,9 @@ tx.setRBF(true) // Enable replace-by-fee
202
232
  ```
203
233
 
204
234
  ### Child-Pays-for-Parent (CPFP)
235
+
205
236
  Use dependent transactions to increase effective fee rate:
237
+
206
238
  ```typescript
207
239
  // Create child transaction with higher fee
208
240
  const childTx = new Transaction()