@bsv/sdk 1.9.2 → 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 (93) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/kvstore/GlobalKVStore.js +116 -98
  3. package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
  4. package/dist/cjs/src/kvstore/types.js.map +1 -1
  5. package/dist/cjs/src/overlay-tools/index.js +1 -0
  6. package/dist/cjs/src/overlay-tools/index.js.map +1 -1
  7. package/dist/cjs/src/overlay-tools/withDoubleSpendRetry.js +55 -0
  8. package/dist/cjs/src/overlay-tools/withDoubleSpendRetry.js.map +1 -0
  9. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  10. package/dist/esm/src/kvstore/GlobalKVStore.js +117 -99
  11. package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
  12. package/dist/esm/src/kvstore/types.js.map +1 -1
  13. package/dist/esm/src/overlay-tools/index.js +1 -0
  14. package/dist/esm/src/overlay-tools/index.js.map +1 -1
  15. package/dist/esm/src/overlay-tools/withDoubleSpendRetry.js +48 -0
  16. package/dist/esm/src/overlay-tools/withDoubleSpendRetry.js.map +1 -0
  17. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  18. package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
  19. package/dist/types/src/kvstore/types.d.ts +2 -0
  20. package/dist/types/src/kvstore/types.d.ts.map +1 -1
  21. package/dist/types/src/overlay-tools/index.d.ts +1 -0
  22. package/dist/types/src/overlay-tools/index.d.ts.map +1 -1
  23. package/dist/types/src/overlay-tools/withDoubleSpendRetry.d.ts +14 -0
  24. package/dist/types/src/overlay-tools/withDoubleSpendRetry.d.ts.map +1 -0
  25. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  26. package/dist/umd/bundle.js +2 -2
  27. package/dist/umd/bundle.js.map +1 -1
  28. package/docs/fast-docs.png +0 -0
  29. package/docs/index.md +49 -44
  30. package/docs/reference/kvstore.md +9 -0
  31. package/docs/reference/overlay-tools.md +32 -0
  32. package/docs/swagger.png +0 -0
  33. package/package.json +1 -1
  34. package/src/kvstore/GlobalKVStore.ts +134 -114
  35. package/src/kvstore/__tests/GlobalKVStore.test.ts +11 -1
  36. package/src/kvstore/types.ts +2 -0
  37. package/src/overlay-tools/index.ts +1 -0
  38. package/src/overlay-tools/withDoubleSpendRetry.ts +71 -0
  39. package/docs/MARKDOWN_VALIDATION_GUIDE.md +0 -175
  40. package/docs/concepts/beef.md +0 -92
  41. package/docs/concepts/chain-tracking.md +0 -134
  42. package/docs/concepts/decentralized-identity.md +0 -221
  43. package/docs/concepts/fees.md +0 -249
  44. package/docs/concepts/identity-certificates.md +0 -307
  45. package/docs/concepts/index.md +0 -77
  46. package/docs/concepts/key-management.md +0 -185
  47. package/docs/concepts/script-templates.md +0 -176
  48. package/docs/concepts/sdk-philosophy.md +0 -80
  49. package/docs/concepts/signatures.md +0 -194
  50. package/docs/concepts/spv-verification.md +0 -118
  51. package/docs/concepts/transaction-encoding.md +0 -167
  52. package/docs/concepts/transaction-structure.md +0 -67
  53. package/docs/concepts/trust-model.md +0 -139
  54. package/docs/concepts/verification.md +0 -250
  55. package/docs/concepts/wallet-integration.md +0 -101
  56. package/docs/guides/development-wallet-setup.md +0 -374
  57. package/docs/guides/direct-transaction-creation.md +0 -147
  58. package/docs/guides/http-client-configuration.md +0 -488
  59. package/docs/guides/index.md +0 -138
  60. package/docs/guides/large-transactions.md +0 -448
  61. package/docs/guides/multisig-transactions.md +0 -792
  62. package/docs/guides/security-best-practices.md +0 -494
  63. package/docs/guides/transaction-batching.md +0 -132
  64. package/docs/guides/transaction-signing-methods.md +0 -419
  65. package/docs/reference/arc-config.md +0 -698
  66. package/docs/reference/brc-100.md +0 -33
  67. package/docs/reference/configuration.md +0 -835
  68. package/docs/reference/debugging.md +0 -705
  69. package/docs/reference/errors.md +0 -597
  70. package/docs/reference/index.md +0 -111
  71. package/docs/reference/network-config.md +0 -914
  72. package/docs/reference/op-codes.md +0 -325
  73. package/docs/reference/transaction-signatures.md +0 -95
  74. package/docs/tutorials/advanced-transaction.md +0 -572
  75. package/docs/tutorials/aes-encryption.md +0 -949
  76. package/docs/tutorials/authfetch-tutorial.md +0 -986
  77. package/docs/tutorials/ecdh-key-exchange.md +0 -549
  78. package/docs/tutorials/elliptic-curve-fundamentals.md +0 -606
  79. package/docs/tutorials/error-handling.md +0 -1216
  80. package/docs/tutorials/first-transaction-low-level.md +0 -205
  81. package/docs/tutorials/first-transaction.md +0 -275
  82. package/docs/tutorials/hashes-and-hmacs.md +0 -788
  83. package/docs/tutorials/identity-management.md +0 -729
  84. package/docs/tutorials/index.md +0 -219
  85. package/docs/tutorials/key-management.md +0 -538
  86. package/docs/tutorials/protowallet-development.md +0 -743
  87. package/docs/tutorials/script-construction.md +0 -690
  88. package/docs/tutorials/spv-merkle-proofs.md +0 -685
  89. package/docs/tutorials/testnet-transactions-low-level.md +0 -359
  90. package/docs/tutorials/transaction-broadcasting.md +0 -538
  91. package/docs/tutorials/transaction-types.md +0 -420
  92. package/docs/tutorials/type-42.md +0 -568
  93. package/docs/tutorials/uhrp-storage.md +0 -599
@@ -1,118 +0,0 @@
1
- # SPV Verification
2
-
3
- Understanding Simplified Payment Verification and how it enables lightweight Bitcoin applications.
4
-
5
- ## What is SPV?
6
-
7
- SPV allows verification of Bitcoin transactions without downloading the entire blockchain:
8
-
9
- - **Lightweight**: Only requires block headers and merkle proofs
10
- - **Secure**: Cryptographically verifiable using merkle trees
11
- - **Efficient**: Scales to millions of transactions
12
- - **Practical**: Enables mobile and web applications
13
-
14
- ## How SPV Works
15
-
16
- ### 1. Block Headers
17
-
18
- Download only block headers (80 bytes each) instead of full blocks:
19
-
20
- ```typescript
21
- // Block header contains merkle root
22
- const header = await chainTracker.getBlockHeader(blockHash)
23
- ```
24
-
25
- ### 2. Merkle Proofs
26
-
27
- Verify transaction inclusion using merkle proofs:
28
-
29
- ```typescript
30
- import { MerklePath } from '@bsv/sdk'
31
-
32
- // Verify transaction is in block
33
- const proof = MerklePath.fromHex(proofHex)
34
- const isValid = proof.verify(txid, merkleRoot)
35
- ```
36
-
37
- ### 3. Transaction Verification
38
-
39
- Combine proofs with block headers for full verification:
40
-
41
- ```typescript
42
- import { Transaction } from '@bsv/sdk'
43
-
44
- // Verify transaction with SPV
45
- const isValid = await Transaction.verify(
46
- transaction,
47
- chainTracker,
48
- { merkleProof: proof }
49
- )
50
- ```
51
-
52
- ## Merkle Trees
53
-
54
- Bitcoin uses merkle trees to efficiently prove transaction inclusion:
55
-
56
- - **Binary Tree**: Each leaf is a transaction ID
57
- - **Hash Pairs**: Parent nodes are hashes of child pairs
58
- - **Root Hash**: Single hash representing all transactions
59
- - **Proof Path**: Minimal data needed to verify inclusion
60
-
61
- ## Security Model
62
-
63
- SPV provides strong security guarantees:
64
-
65
- - **Proof of Work**: Block headers contain proof of work
66
- - **Cryptographic Hashes**: Merkle proofs use SHA-256
67
- - **Chain Validation**: Verify header chain integrity
68
- - **Fraud Detection**: Invalid proofs are cryptographically detectable
69
-
70
- ## Trade-offs
71
-
72
- ### Advantages
73
-
74
- - **Low Resource Usage**: Minimal storage and bandwidth
75
- - **Fast Synchronization**: Quick startup time
76
- - **Scalability**: Works with any blockchain size
77
- - **Privacy**: No need to reveal which transactions you care about
78
-
79
- ### Limitations
80
-
81
- - **Trust Assumptions**: Relies on honest majority of miners
82
- - **Network Dependency**: Requires connection to full nodes
83
- - **Delayed Detection**: May not immediately detect invalid blocks
84
-
85
- ## SDK Implementation
86
-
87
- The SDK provides comprehensive SPV support:
88
-
89
- ```typescript
90
- // Configure SPV verification
91
- const config = {
92
- spv: {
93
- enabled: true,
94
- maxMemoryLimit: 100000000, // 100MB
95
- chainTracker: chainTracker
96
- }
97
- }
98
-
99
- // Verify transaction with SPV
100
- const result = await transaction.verify(chainTracker, {
101
- merkleProof: proof,
102
- blockHeader: header
103
- })
104
- ```
105
-
106
- ## BEEF Integration
107
-
108
- SPV works seamlessly with BEEF format:
109
-
110
- - **Efficient Encoding**: BEEF includes merkle proofs
111
- - **Batch Verification**: Verify multiple transactions together
112
- - **Standardized Format**: Consistent across applications
113
-
114
- ## Next Steps
115
-
116
- - Learn about [BEEF Format](./beef.md) for efficient data exchange
117
- - Understand [Transaction Encoding](./transaction-encoding.md) formats
118
- - Explore [Trust Model](./trust-model.md) considerations
@@ -1,167 +0,0 @@
1
- # Transaction Encoding
2
-
3
- How Bitcoin transactions are serialized and deserialized in different formats within the BSV TypeScript SDK.
4
-
5
- ## Encoding Formats
6
-
7
- The SDK supports multiple transaction encoding formats:
8
-
9
- ### Raw Transaction Format
10
-
11
- Standard Bitcoin transaction serialization:
12
-
13
- ```typescript
14
- import { Transaction } from '@bsv/sdk'
15
-
16
- // Serialize to hex
17
- const txHex = transaction.toHex()
18
-
19
- // Deserialize from hex
20
- const tx = Transaction.fromHex(txHex)
21
- ```
22
-
23
- ### BEEF Format
24
-
25
- Bitcoin Extras Extension Format for efficient data exchange:
26
-
27
- ```typescript
28
- // Serialize to BEEF
29
- const beefHex = transaction.toBEEF()
30
-
31
- // Deserialize from BEEF
32
- const tx = Transaction.fromHexBEEF(beefHex)
33
- ```
34
-
35
- ### Binary Format
36
-
37
- Raw binary data for maximum efficiency:
38
-
39
- ```typescript
40
- // Serialize to binary
41
- const txBinary = transaction.toBinary()
42
-
43
- // Deserialize from binary
44
- const tx = Transaction.fromBinary(txBinary)
45
- ```
46
-
47
- ## Serialization Structure
48
-
49
- ### Standard Transaction
50
-
51
- ```
52
- Version (4 bytes)
53
- Input Count (varint)
54
- Inputs (variable)
55
- Output Count (varint)
56
- Outputs (variable)
57
- Lock Time (4 bytes)
58
- ```
59
-
60
- ### Input Structure
61
-
62
- ```
63
- Previous TX Hash (32 bytes)
64
- Output Index (4 bytes)
65
- Script Length (varint)
66
- Unlocking Script (variable)
67
- Sequence (4 bytes)
68
- ```
69
-
70
- ### Output Structure
71
-
72
- ```
73
- Value (8 bytes)
74
- Script Length (varint)
75
- Locking Script (variable)
76
- ```
77
-
78
- ## BEEF Enhancements
79
-
80
- BEEF format adds:
81
-
82
- - **Merkle Proofs**: SPV verification data
83
- - **Block Headers**: Chain validation information
84
- - **Metadata**: Additional transaction context
85
- - **Compression**: Efficient encoding for large datasets
86
-
87
- ## Encoding Considerations
88
-
89
- ### Size Optimization
90
-
91
- - Use BEEF for transactions with proofs
92
- - Use raw format for minimal overhead
93
- - Consider compression for large batches
94
-
95
- ### Compatibility
96
-
97
- - Raw format works with all Bitcoin software
98
- - BEEF requires compatible parsers
99
- - Binary format is most efficient but less portable
100
-
101
- ### Performance
102
-
103
- - Binary operations are fastest
104
- - Hex encoding is human-readable
105
- - BEEF provides best feature/size ratio
106
-
107
- ## Working with Encodings
108
-
109
- ### Conversion Between Formats
110
-
111
- ```typescript
112
- // Start with a transaction
113
- const tx = new Transaction()
114
-
115
- // Convert between formats
116
- const hex = tx.toHex()
117
- const binary = tx.toBinary()
118
- const beef = tx.toBEEF()
119
-
120
- // All represent the same transaction
121
- ```
122
-
123
- ### Validation
124
-
125
- ```typescript
126
- // Verify encoding integrity
127
- const originalTx = Transaction.fromHex(hex)
128
- const roundTripHex = originalTx.toHex()
129
- console.log(hex === roundTripHex) // true
130
- ```
131
-
132
- ## Use Cases
133
-
134
- ### Network Transmission
135
-
136
- - Use hex for JSON APIs
137
- - Use binary for efficient protocols
138
- - Use BEEF for SPV applications
139
-
140
- ### Storage
141
-
142
- - Raw format for blockchain storage
143
- - BEEF for application databases
144
- - Binary for memory-constrained environments
145
-
146
- ### Interoperability
147
-
148
- - Hex for debugging and logging
149
- - Raw format for wallet compatibility
150
- - BEEF for modern Bitcoin applications
151
-
152
- ## Error Handling
153
-
154
- Common encoding issues:
155
-
156
- - Invalid hex characters
157
- - Truncated binary data
158
- - Malformed BEEF structures
159
- - Version compatibility problems
160
-
161
- The SDK provides comprehensive validation and error reporting.
162
-
163
- ## Next Steps
164
-
165
- - Understand [BEEF Format](./beef.md) in detail
166
- - Learn about [SPV Verification](./spv-verification.md) with BEEF
167
- - Explore [Transaction Structure](./transaction-structure.md) fundamentals
@@ -1,67 +0,0 @@
1
- # Transaction Structure
2
-
3
- Understanding how Bitcoin transactions work and their representation in the BSV TypeScript SDK.
4
-
5
- ## Basic Transaction Components
6
-
7
- A Bitcoin transaction consists of:
8
-
9
- - **Inputs**: References to previous transaction outputs being spent
10
- - **Outputs**: New transaction outputs being created
11
- - **Metadata**: Version, lock time, and other transaction properties
12
-
13
- ## Transaction in the SDK
14
-
15
- ```typescript
16
- import { Transaction } from '@bsv/sdk'
17
-
18
- // Create a new transaction
19
- const tx = new Transaction()
20
-
21
- // Add inputs and outputs
22
- tx.addInput({
23
- sourceTransaction: previousTx,
24
- sourceOutputIndex: 0,
25
- unlockingScript: unlockingScript
26
- })
27
-
28
- tx.addOutput({
29
- satoshis: 1000,
30
- lockingScript: lockingScript
31
- })
32
- ```
33
-
34
- ## Key Concepts
35
-
36
- ### Inputs
37
-
38
- - Reference previous transaction outputs (UTXOs)
39
- - Include unlocking scripts to prove ownership
40
- - Must be fully consumed (no partial spending)
41
-
42
- ### Outputs
43
-
44
- - Create new UTXOs with specific values
45
- - Include locking scripts that define spending conditions
46
- - Can be spent by future transactions
47
-
48
- ### Transaction ID
49
-
50
- - Unique identifier calculated from transaction data
51
- - Used to reference the transaction in inputs
52
-
53
- ## Working with Transactions
54
-
55
- The SDK provides methods to:
56
-
57
- - Serialize transactions to hex format
58
- - Calculate transaction fees
59
- - Verify transaction validity
60
- - Sign transaction inputs
61
-
62
- ## Next Steps
63
-
64
- - Learn about [BEEF Format](./beef.md) for efficient transaction representation with validation data
65
- - Learn about [Script Templates](./script-templates.md) for locking/unlocking scripts
66
- - Understand [Digital Signatures](./signatures.md) for transaction authorization
67
- - Explore [Transaction Encoding](./transaction-encoding.md) for serialization formats
@@ -1,139 +0,0 @@
1
- # Trust Model
2
-
3
- Understanding the security assumptions and trust relationships in BSV TypeScript SDK applications.
4
-
5
- ## Core Trust Principles
6
-
7
- The SDK is designed around minimizing trust requirements:
8
-
9
- ### Trustless Verification
10
-
11
- - **Cryptographic Proofs**: Verify transactions mathematically
12
- - **SPV Security**: Validate without trusting third parties
13
- - **Self-Sovereign**: Users control their own keys and data
14
-
15
- ### Minimized Dependencies
16
-
17
- - **Zero External Dependencies**: Reduces attack surface
18
- - **Self-Contained**: All cryptographic operations built-in
19
- - **Auditable**: Open source and transparent implementation
20
-
21
- ## Trust Relationships
22
-
23
- ### User Trust
24
-
25
- Users must trust:
26
-
27
- - **The SDK Code**: Open source and auditable
28
- - **Their Wallet**: Manages private keys securely
29
- - **Their Device**: Secure execution environment
30
-
31
- ### Network Trust
32
-
33
- Applications rely on:
34
-
35
- - **Bitcoin Network**: Honest majority of miners
36
- - **Chain Trackers**: Provide accurate blockchain data
37
- - **SPV Assumptions**: Valid merkle proofs and headers
38
-
39
- ### Service Trust
40
-
41
- Optional trust relationships:
42
-
43
- - **Wallet Providers**: If using hosted wallets
44
- - **ARC Services**: For transaction broadcasting
45
- - **Overlay Services**: For additional functionality
46
-
47
- ## Security Assumptions
48
-
49
- ### Cryptographic Security
50
-
51
- - **secp256k1**: Elliptic curve is secure
52
- - **SHA-256**: Hash function is collision-resistant
53
- - **ECDSA**: Digital signature scheme is unforgeable
54
- - **Random Number Generation**: Entropy source is secure
55
-
56
- ### Network Security
57
-
58
- - **Proof of Work**: Mining provides security
59
- - **Longest Chain**: Honest chain has most work
60
- - **Block Finality**: Deep confirmations prevent reorganization
61
- - **Network Connectivity**: Access to honest nodes
62
-
63
- ## Risk Mitigation
64
-
65
- ### Key Management
66
-
67
- ```typescript
68
- // Minimize private key exposure
69
- const wallet = new WalletClient() // Keys stay in wallet
70
-
71
- // Avoid direct key handling
72
- // const privateKey = PrivateKey.fromString() // Higher risk
73
- ```
74
-
75
- ### Transaction Verification
76
-
77
- ```typescript
78
- // Always verify important transactions
79
- const isValid = await transaction.verify(chainTracker, {
80
- merkleProof: proof,
81
- blockHeader: header
82
- })
83
- ```
84
-
85
- ### Multiple Sources
86
-
87
- ```typescript
88
- // Use multiple chain trackers
89
- const config = {
90
- chainTracker: {
91
- primary: 'WhatsOnChain',
92
- fallbacks: ['GorillaPool', 'TAAL']
93
- }
94
- }
95
- ```
96
-
97
- ## Threat Model
98
-
99
- ### Attacks to Consider
100
-
101
- - **Private Key Compromise**: Secure key storage
102
- - **Man-in-the-Middle**: Use HTTPS and verify certificates
103
- - **Service Downtime**: Implement fallback mechanisms
104
- - **Double Spending**: Wait for confirmations
105
- - **Replay Attacks**: Use unique transaction IDs
106
-
107
- ## Application Design
108
-
109
- ### Security-First Design
110
-
111
- ```typescript
112
- // Validate all inputs
113
- function processTransaction(txHex: string) {
114
- if (!isValidHex(txHex)) {
115
- throw new Error('Invalid transaction hex')
116
- }
117
-
118
- const tx = Transaction.fromHex(txHex)
119
- // Process verified transaction
120
- }
121
- ```
122
-
123
- ### Error Handling
124
-
125
- ```typescript
126
- // Handle trust failures gracefully
127
- try {
128
- const result = await chainTracker.getTransaction(txid)
129
- } catch (error) {
130
- // Fallback to alternative source
131
- const backup = await fallbackTracker.getTransaction(txid)
132
- }
133
- ```
134
-
135
- ## Next Steps
136
-
137
- - Review [Key Management](./key-management.md) security practices
138
- - Understand [SPV Verification](./spv-verification.md) assumptions
139
- - Learn about [Wallet Integration](./wallet-integration.md) trust models