@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.
Files changed (60) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/docs/fast-docs.png +0 -0
  3. package/docs/index.md +49 -44
  4. package/docs/swagger.png +0 -0
  5. package/package.json +1 -1
  6. package/docs/MARKDOWN_VALIDATION_GUIDE.md +0 -175
  7. package/docs/concepts/beef.md +0 -92
  8. package/docs/concepts/chain-tracking.md +0 -134
  9. package/docs/concepts/decentralized-identity.md +0 -221
  10. package/docs/concepts/fees.md +0 -249
  11. package/docs/concepts/identity-certificates.md +0 -307
  12. package/docs/concepts/index.md +0 -77
  13. package/docs/concepts/key-management.md +0 -185
  14. package/docs/concepts/script-templates.md +0 -176
  15. package/docs/concepts/sdk-philosophy.md +0 -80
  16. package/docs/concepts/signatures.md +0 -194
  17. package/docs/concepts/spv-verification.md +0 -118
  18. package/docs/concepts/transaction-encoding.md +0 -167
  19. package/docs/concepts/transaction-structure.md +0 -67
  20. package/docs/concepts/trust-model.md +0 -139
  21. package/docs/concepts/verification.md +0 -250
  22. package/docs/concepts/wallet-integration.md +0 -101
  23. package/docs/guides/development-wallet-setup.md +0 -374
  24. package/docs/guides/direct-transaction-creation.md +0 -147
  25. package/docs/guides/http-client-configuration.md +0 -488
  26. package/docs/guides/index.md +0 -138
  27. package/docs/guides/large-transactions.md +0 -448
  28. package/docs/guides/multisig-transactions.md +0 -792
  29. package/docs/guides/security-best-practices.md +0 -494
  30. package/docs/guides/transaction-batching.md +0 -132
  31. package/docs/guides/transaction-signing-methods.md +0 -419
  32. package/docs/reference/arc-config.md +0 -698
  33. package/docs/reference/brc-100.md +0 -33
  34. package/docs/reference/configuration.md +0 -835
  35. package/docs/reference/debugging.md +0 -705
  36. package/docs/reference/errors.md +0 -597
  37. package/docs/reference/index.md +0 -111
  38. package/docs/reference/network-config.md +0 -914
  39. package/docs/reference/op-codes.md +0 -325
  40. package/docs/reference/transaction-signatures.md +0 -95
  41. package/docs/tutorials/advanced-transaction.md +0 -572
  42. package/docs/tutorials/aes-encryption.md +0 -949
  43. package/docs/tutorials/authfetch-tutorial.md +0 -986
  44. package/docs/tutorials/ecdh-key-exchange.md +0 -549
  45. package/docs/tutorials/elliptic-curve-fundamentals.md +0 -606
  46. package/docs/tutorials/error-handling.md +0 -1216
  47. package/docs/tutorials/first-transaction-low-level.md +0 -205
  48. package/docs/tutorials/first-transaction.md +0 -275
  49. package/docs/tutorials/hashes-and-hmacs.md +0 -788
  50. package/docs/tutorials/identity-management.md +0 -729
  51. package/docs/tutorials/index.md +0 -219
  52. package/docs/tutorials/key-management.md +0 -538
  53. package/docs/tutorials/protowallet-development.md +0 -743
  54. package/docs/tutorials/script-construction.md +0 -690
  55. package/docs/tutorials/spv-merkle-proofs.md +0 -685
  56. package/docs/tutorials/testnet-transactions-low-level.md +0 -359
  57. package/docs/tutorials/transaction-broadcasting.md +0 -538
  58. package/docs/tutorials/transaction-types.md +0 -420
  59. package/docs/tutorials/type-42.md +0 -568
  60. package/docs/tutorials/uhrp-storage.md +0 -599
@@ -1,221 +0,0 @@
1
- # Decentralized Identity
2
-
3
- Understanding how decentralized identity works in BSV and why it matters for building trustless applications.
4
-
5
- ## What is Decentralized Identity?
6
-
7
- Imagine a world where you control your own identity credentials, just like you control your own wallet. Instead of relying on Facebook, Google, or government agencies to verify who you are, you can prove your identity using cryptographic certificates that anyone can independently verify.
8
-
9
- This is the promise of decentralized identity: **self-sovereign identity** that puts users in control while maintaining security and trust.
10
-
11
- ## Why Decentralized Identity Matters
12
-
13
- ### The Problem with Centralized Identity
14
-
15
- Traditional identity systems have significant limitations:
16
-
17
- - **Single Points of Failure**: If the identity provider goes down, you lose access
18
- - **Privacy Concerns**: Companies collect and monetize your personal data
19
- - **Vendor Lock-in**: You can't easily move your identity between services
20
- - **Censorship Risk**: Providers can revoke your identity for any reason
21
- - **Data Breaches**: Centralized databases are attractive targets for hackers
22
-
23
- ### The Decentralized Solution
24
-
25
- Decentralized identity addresses these issues by:
26
-
27
- - **User Control**: You own and manage your identity data
28
- - **No Central Authority**: No single entity controls the verification process
29
- - **Interoperability**: Your identity works across different applications
30
- - **Privacy by Design**: You choose what information to reveal and when
31
- - **Censorship Resistance**: No one can arbitrarily revoke your identity
32
-
33
- ## How It Works in BSV
34
-
35
- ### Identity Keys vs Transaction Keys
36
-
37
- BSV uses different types of keys for different purposes:
38
-
39
- **Identity Keys** are long-term, stable identifiers used for:
40
-
41
- - Establishing your digital identity
42
- - Signing identity certificates
43
- - Resolving your public profile information
44
- - Authenticating with services
45
-
46
- **Transaction Keys** are used for:
47
-
48
- - Signing Bitcoin transactions
49
- - Managing UTXOs and payments
50
- - Protocol-specific operations
51
-
52
- This separation provides both security and privacy benefits.
53
-
54
- ### Identity Resolution
55
-
56
- Your identity key serves as a unique identifier that can be used to discover:
57
-
58
- - Your chosen display name and profile information
59
- - Verification badges and trust indicators
60
- - Public certificates and credentials
61
- - Contact preferences and communication methods
62
-
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.
64
-
65
- ### Certificate-Based Trust
66
-
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:
68
-
69
- - **Self-Signed Certificates**: Claims you make about yourself
70
- - **Peer Certificates**: Verifications from other users
71
- - **Institutional Certificates**: Credentials from recognized organizations
72
- - **Service Certificates**: Verifications from specialized services
73
-
74
- ## Trust and Verification Models
75
-
76
- ### Web of Trust
77
-
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.
79
-
80
- ### Institutional Trust
81
-
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.
83
-
84
- ### Hybrid Approaches
85
-
86
- Most real-world applications use a combination of trust models, adjusting requirements based on context. For example:
87
-
88
- - **Low-risk interactions** might accept self-signed certificates
89
- - **Financial transactions** might require institutional verification
90
- - **Professional networking** might emphasize peer verification within industry groups
91
-
92
- ## Privacy and Selective Disclosure
93
-
94
- ### Controlling Your Information
95
-
96
- One of the key benefits of decentralized identity is granular control over your personal information. You can:
97
-
98
- - Choose which attributes to make publicly discoverable
99
- - Reveal different information to different parties
100
- - Prove claims without revealing underlying data
101
- - Revoke access to previously shared information
102
-
103
- ### Zero-Knowledge Proofs
104
-
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.
106
-
107
- ### Progressive Disclosure
108
-
109
- As trust builds between parties, you might choose to reveal more information. This allows relationships to develop naturally while maintaining privacy protection.
110
-
111
- ## Identity Lifecycle
112
-
113
- ### Getting Started
114
-
115
- Creating a decentralized identity involves:
116
-
117
- 1. **Generating an identity key pair** (handled by your wallet)
118
- 2. **Creating basic profile information** (name, avatar, contact preferences)
119
- 3. **Obtaining initial certificates** to establish credibility
120
- 4. **Making your identity discoverable** through resolution networks
121
-
122
- ### Building Trust
123
-
124
- Over time, you accumulate certificates and verifications that build your reputation:
125
-
126
- - Verify your email address and social media accounts
127
- - Get endorsements from colleagues and friends
128
- - Obtain professional certifications and credentials
129
- - Participate in community verification programs
130
-
131
- ### Maintaining Privacy
132
-
133
- As your identity grows, you maintain control by:
134
-
135
- - Regularly reviewing what information is public
136
- - Updating privacy preferences as needs change
137
- - Revoking outdated or unwanted certificates
138
- - Managing consent for data sharing
139
-
140
- ## Real-World Applications
141
-
142
- ### Passwordless Authentication
143
-
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.
145
-
146
- ### Professional Networking
147
-
148
- Verify professional credentials, work history, and skills through cryptographic certificates rather than relying on self-reported information on traditional platforms.
149
-
150
- ### Age and Identity Verification
151
-
152
- Prove your age for restricted services without revealing your exact birthdate, or verify your identity for account creation without sharing unnecessary personal information.
153
-
154
- ### Reputation Systems
155
-
156
- Build portable reputation that follows you across different platforms and applications, creating incentives for good behavior and reducing fraud.
157
-
158
- ### Decentralized Social Networks
159
-
160
- Participate in social networks where your identity and connections are owned by you, not the platform, enabling true social media portability.
161
-
162
- ## Benefits for Developers
163
-
164
- ### Simplified User Onboarding
165
-
166
- Instead of building complex registration and verification systems, applications can rely on existing identity infrastructure and certificates.
167
-
168
- ### Enhanced Security
169
-
170
- Cryptographic identity verification is more secure than traditional username/password systems and reduces the risk of account takeovers.
171
-
172
- ### Regulatory Compliance
173
-
174
- Decentralized identity can help meet KYC (Know Your Customer) and AML (Anti-Money Laundering) requirements while preserving user privacy.
175
-
176
- ### Interoperability
177
-
178
- Users can bring their identity and reputation from other applications, reducing friction and improving user experience.
179
-
180
- ## Challenges and Considerations
181
-
182
- ### User Experience
183
-
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.
185
-
186
- ### Recovery and Backup
187
-
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.
189
-
190
- ### Network Effects
191
-
192
- The value of decentralized identity increases as more people and organizations participate. Early adoption requires overcoming the "chicken and egg" problem.
193
-
194
- ### Scalability
195
-
196
- As identity networks grow, efficient resolution and verification mechanisms become increasingly important to maintain performance.
197
-
198
- ## The Future of Identity
199
-
200
- Decentralized identity represents a fundamental shift toward user sovereignty and privacy. As the technology matures and adoption grows, we can expect to see:
201
-
202
- - **Seamless Integration** with everyday applications and services
203
- - **Enhanced Privacy Protection** through advanced cryptographic techniques
204
- - **Global Interoperability** across different identity systems and networks
205
- - **Reduced Identity Fraud** through cryptographic verification
206
- - **New Business Models** that respect user privacy and data ownership
207
-
208
- By understanding these concepts, developers can build applications that respect user privacy, enhance security, and contribute to a more open and decentralized internet.
209
-
210
- ## Related Concepts
211
-
212
- - [Identity Certificates](./identity-certificates.md) - How cryptographic certificates enable trust
213
- - [Digital Signatures](./signatures.md) - Cryptographic foundations of identity verification
214
- - [Trust Model](./trust-model.md) - Security assumptions in decentralized systems
215
- - [Key Management](./key-management.md) - Managing cryptographic keys securely
216
-
217
- ## Further Reading
218
-
219
- - [Identity Management Tutorial](../tutorials/identity-management.md) - Hands-on implementation guide
220
- - [AuthFetch Tutorial](../tutorials/authfetch-tutorial.md) - Authenticated communication using identity
221
- - [Security Best Practices](../guides/security-best-practices.md) - Secure identity implementation patterns
@@ -1,249 +0,0 @@
1
- # Transaction Fees
2
-
3
- Understanding Bitcoin transaction fees and how they work in the BSV TypeScript SDK.
4
-
5
- ## What are Transaction Fees?
6
-
7
- Transaction fees are payments to miners for including transactions in blocks:
8
-
9
- ```typescript
10
- import { Transaction } from '@bsv/sdk'
11
-
12
- // Calculate transaction fee
13
- const tx = new Transaction()
14
- const feeRequired = tx.getFee()
15
-
16
- // Set custom fee rate
17
- const customFee = tx.getFee(feePerKB)
18
- ```
19
-
20
- ## Fee Calculation
21
-
22
- Fees are calculated based on transaction size:
23
-
24
- - **Fee Rate**: Satoshis per kilobyte (sat/kB)
25
- - **Transaction Size**: Total bytes in serialized transaction
26
- - **Total Fee**: Size × Fee Rate
27
-
28
- ## SDK Fee Handling
29
-
30
- ### Automatic Fee Calculation
31
-
32
- The SDK calculates fees automatically:
33
-
34
- ```typescript
35
- // Wallet handles fees automatically
36
- const wallet = new WalletClient()
37
- const action = await wallet.createAction({
38
- outputs: [{
39
- satoshis: 1000,
40
- lockingScript: script
41
- }]
42
- })
43
- // Fee calculated and deducted automatically
44
- ```
45
-
46
- ### Manual Fee Control
47
-
48
- For advanced use cases:
49
-
50
- ```typescript
51
- // Calculate fee manually
52
- const tx = new Transaction()
53
- tx.addInput(/* input */)
54
- tx.addOutput(/* output */)
55
-
56
- const estimatedSize = tx.getSerializedSize()
57
- const feeRequired = estimatedSize * feePerByte
58
- ```
59
-
60
- ## Fee Rates
61
-
62
- ### Network Fee Rates
63
-
64
- BSV typically uses low, predictable fees:
65
-
66
- - **Standard Rate**: ~0.5 sat/byte
67
- - **Priority Rate**: ~1.0 sat/byte
68
- - **Economy Rate**: ~0.1 sat/byte
69
-
70
- ### Dynamic Fee Estimation
71
-
72
- ```typescript
73
- // Get current network fee rates
74
- const feeRates = await chainTracker.getFeeRates()
75
- const recommendedFee = feeRates.standard
76
- ```
77
-
78
- ## Fee Components
79
-
80
- ### Input Costs
81
-
82
- Each input adds to transaction size:
83
-
84
- - Previous transaction hash (32 bytes)
85
- - Output index (4 bytes)
86
- - Unlocking script (variable)
87
- - Sequence number (4 bytes)
88
-
89
- ### Output Costs
90
-
91
- Each output adds to transaction size:
92
-
93
- - Value (8 bytes)
94
- - Locking script length (1-9 bytes)
95
- - Locking script (variable)
96
-
97
- ### Base Transaction
98
-
99
- Fixed overhead for every transaction:
100
-
101
- - Version (4 bytes)
102
- - Input count (1-9 bytes)
103
- - Output count (1-9 bytes)
104
- - Lock time (4 bytes)
105
-
106
- ## Fee Optimization
107
-
108
- ### UTXO Selection
109
-
110
- Choose UTXOs efficiently:
111
-
112
- ```typescript
113
- // Prefer fewer, larger UTXOs to reduce fees
114
- const utxos = await wallet.getUTXOs()
115
- const selected = selectOptimalUTXOs(utxos, targetAmount)
116
- ```
117
-
118
- ### Output Consolidation
119
-
120
- Combine multiple payments:
121
-
122
- ```typescript
123
- // Batch multiple outputs in one transaction
124
- const outputs = [
125
- { satoshis: 1000, lockingScript: script1 },
126
- { satoshis: 2000, lockingScript: script2 },
127
- { satoshis: 1500, lockingScript: script3 }
128
- ]
129
- ```
130
-
131
- ### Script Efficiency
132
-
133
- Use efficient script templates:
134
-
135
- ```typescript
136
- // P2PKH is more efficient than complex scripts
137
- const p2pkh = new P2PKH()
138
- const efficientScript = p2pkh.lock(publicKeyHash)
139
- ```
140
-
141
- ## Fee Estimation
142
-
143
- ### Size Estimation
144
-
145
- Estimate transaction size before creation:
146
-
147
- ```typescript
148
- // Estimate size for fee calculation
149
- const estimatedInputs = 2
150
- const estimatedOutputs = 3
151
- const estimatedSize = estimateTransactionSize(estimatedInputs, estimatedOutputs)
152
- const estimatedFee = estimatedSize * feeRate
153
- ```
154
-
155
- ### Template-Based Estimation
156
-
157
- ```typescript
158
- // Use script templates for accurate estimation
159
- const template = new P2PKH()
160
- const scriptSize = template.estimateLength([publicKeyHash])
161
- ```
162
-
163
- ## Error Handling
164
-
165
- Common fee-related issues:
166
-
167
- - Insufficient funds for fees
168
- - Fee rate too low for network
169
- - Transaction size miscalculation
170
-
171
- ```typescript
172
- try {
173
- const action = await wallet.createAction({
174
- outputs: outputs
175
- })
176
- } catch (error) {
177
- if (error.message.includes('Insufficient funds')) {
178
- // Handle insufficient balance for fees
179
- console.log('Not enough funds to cover transaction and fees')
180
- }
181
- }
182
- ```
183
-
184
- ## Best Practices
185
-
186
- ### Fee Management
187
-
188
- - Always account for fees in balance calculations
189
- - Use appropriate fee rates for urgency
190
- - Monitor network conditions for fee adjustments
191
- - Implement fee estimation before transaction creation
192
-
193
- ### Cost Optimization
194
-
195
- - Batch transactions when possible
196
- - Use efficient script templates
197
- - Optimize UTXO selection
198
- - Consider transaction timing
199
-
200
- ### User Experience
201
-
202
- - Display estimated fees to users
203
- - Provide fee rate options (economy, standard, priority)
204
- - Handle insufficient fund errors gracefully
205
- - Show fee breakdown for transparency
206
-
207
- ## Wallet Integration
208
-
209
- Most applications rely on wallets for fee handling:
210
-
211
- ```typescript
212
- // Wallet manages fees automatically
213
- const wallet = new WalletClient()
214
-
215
- // Fees are calculated and deducted automatically
216
- const result = await wallet.createAction({
217
- description: 'Payment with automatic fees',
218
- outputs: [/* outputs */]
219
- })
220
- ```
221
-
222
- ## Advanced Fee Strategies
223
-
224
- ### Replace-by-Fee (RBF)
225
-
226
- Increase fees for faster confirmation:
227
-
228
- ```typescript
229
- // Create transaction with RBF enabled
230
- const tx = new Transaction()
231
- tx.setRBF(true) // Enable replace-by-fee
232
- ```
233
-
234
- ### Child-Pays-for-Parent (CPFP)
235
-
236
- Use dependent transactions to increase effective fee rate:
237
-
238
- ```typescript
239
- // Create child transaction with higher fee
240
- const childTx = new Transaction()
241
- childTx.addInput(/* from parent transaction */)
242
- // Higher fee rate pulls parent transaction along
243
- ```
244
-
245
- ## Next Steps
246
-
247
- - Understand [Transaction Structure](./transaction-structure.md) for size calculation
248
- - Learn about [Wallet Integration](./wallet-integration.md) for automatic fee handling
249
- - Explore [Script Templates](./script-templates.md) for efficient fee optimization