@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.
- package/README.md +4 -4
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/MARKDOWN_VALIDATION_GUIDE.md +175 -0
- package/docs/concepts/beef.md +8 -0
- package/docs/concepts/chain-tracking.md +12 -0
- package/docs/concepts/decentralized-identity.md +37 -0
- package/docs/concepts/fees.md +32 -0
- package/docs/concepts/identity-certificates.md +53 -1
- package/docs/concepts/index.md +15 -0
- package/docs/concepts/key-management.md +9 -0
- package/docs/concepts/script-templates.md +13 -0
- package/docs/concepts/sdk-philosophy.md +8 -0
- package/docs/concepts/signatures.md +15 -0
- package/docs/concepts/spv-verification.md +12 -0
- package/docs/concepts/transaction-encoding.md +19 -0
- package/docs/concepts/transaction-structure.md +4 -0
- package/docs/concepts/trust-model.md +16 -0
- package/docs/concepts/verification.md +31 -0
- package/docs/concepts/wallet-integration.md +6 -0
- package/docs/guides/development-wallet-setup.md +374 -0
- package/docs/guides/direct-transaction-creation.md +12 -2
- package/docs/guides/http-client-configuration.md +122 -48
- package/docs/guides/index.md +117 -9
- package/docs/guides/large-transactions.md +448 -0
- package/docs/guides/multisig-transactions.md +792 -0
- package/docs/guides/security-best-practices.md +494 -0
- package/docs/guides/transaction-batching.md +132 -0
- package/docs/guides/transaction-signing-methods.md +230 -79
- package/docs/index.md +0 -2
- package/docs/reference/auth.md +212 -159
- package/docs/reference/compat.md +120 -96
- package/docs/reference/configuration.md +6 -0
- package/docs/reference/debugging.md +5 -0
- package/docs/reference/errors.md +50 -0
- package/docs/reference/identity.md +21 -12
- package/docs/reference/index.md +14 -1
- package/docs/reference/kvstore.md +21 -19
- package/docs/reference/messages.md +3 -0
- package/docs/reference/op-codes.md +20 -1
- package/docs/reference/overlay-tools.md +46 -18
- package/docs/reference/primitives.md +571 -390
- package/docs/reference/registry.md +43 -20
- package/docs/reference/script.md +140 -105
- package/docs/reference/storage.md +32 -12
- package/docs/reference/totp.md +16 -11
- package/docs/reference/transaction-signatures.md +2 -1
- package/docs/reference/transaction.md +201 -120
- package/docs/reference/wallet.md +241 -64
- package/docs/tutorials/advanced-transaction.md +1 -4
- package/docs/tutorials/aes-encryption.md +3 -1
- package/docs/tutorials/authfetch-tutorial.md +29 -0
- package/docs/tutorials/ecdh-key-exchange.md +2 -0
- package/docs/tutorials/elliptic-curve-fundamentals.md +3 -0
- package/docs/tutorials/error-handling.md +1 -0
- package/docs/tutorials/first-transaction-low-level.md +1 -0
- package/docs/tutorials/first-transaction.md +5 -8
- package/docs/tutorials/hashes-and-hmacs.md +5 -31
- package/docs/tutorials/identity-management.md +27 -0
- package/docs/tutorials/index.md +114 -77
- package/docs/tutorials/key-management.md +5 -3
- package/docs/tutorials/protowallet-development.md +27 -0
- package/docs/tutorials/spv-merkle-proofs.md +9 -6
- package/docs/tutorials/testnet-transactions-low-level.md +25 -18
- package/docs/tutorials/transaction-broadcasting.md +10 -7
- package/docs/tutorials/transaction-types.md +5 -4
- package/docs/tutorials/type-42.md +0 -14
- package/docs/tutorials/uhrp-storage.md +23 -3
- package/package.json +1 -1
- package/src/identity/README.md +0 -1
- package/src/primitives/__tests/SymmetricKey.test.ts +45 -0
- package/src/primitives/__tests/SymmetricKeyCompatibility.test.ts +150 -0
- package/src/transaction/__tests/Transaction.test.ts +1 -1
- package/src/transaction/broadcasters/DefaultBroadcaster.ts +1 -1
- package/src/transaction/broadcasters/__tests/ARC.test.ts +1 -1
|
@@ -5,6 +5,7 @@ Understanding Simplified Payment Verification and how it enables lightweight Bit
|
|
|
5
5
|
## What is SPV?
|
|
6
6
|
|
|
7
7
|
SPV allows verification of Bitcoin transactions without downloading the entire blockchain:
|
|
8
|
+
|
|
8
9
|
- **Lightweight**: Only requires block headers and merkle proofs
|
|
9
10
|
- **Secure**: Cryptographically verifiable using merkle trees
|
|
10
11
|
- **Efficient**: Scales to millions of transactions
|
|
@@ -13,14 +14,18 @@ SPV allows verification of Bitcoin transactions without downloading the entire b
|
|
|
13
14
|
## How SPV Works
|
|
14
15
|
|
|
15
16
|
### 1. Block Headers
|
|
17
|
+
|
|
16
18
|
Download only block headers (80 bytes each) instead of full blocks:
|
|
19
|
+
|
|
17
20
|
```typescript
|
|
18
21
|
// Block header contains merkle root
|
|
19
22
|
const header = await chainTracker.getBlockHeader(blockHash)
|
|
20
23
|
```
|
|
21
24
|
|
|
22
25
|
### 2. Merkle Proofs
|
|
26
|
+
|
|
23
27
|
Verify transaction inclusion using merkle proofs:
|
|
28
|
+
|
|
24
29
|
```typescript
|
|
25
30
|
import { MerklePath } from '@bsv/sdk'
|
|
26
31
|
|
|
@@ -30,7 +35,9 @@ const isValid = proof.verify(txid, merkleRoot)
|
|
|
30
35
|
```
|
|
31
36
|
|
|
32
37
|
### 3. Transaction Verification
|
|
38
|
+
|
|
33
39
|
Combine proofs with block headers for full verification:
|
|
40
|
+
|
|
34
41
|
```typescript
|
|
35
42
|
import { Transaction } from '@bsv/sdk'
|
|
36
43
|
|
|
@@ -45,6 +52,7 @@ const isValid = await Transaction.verify(
|
|
|
45
52
|
## Merkle Trees
|
|
46
53
|
|
|
47
54
|
Bitcoin uses merkle trees to efficiently prove transaction inclusion:
|
|
55
|
+
|
|
48
56
|
- **Binary Tree**: Each leaf is a transaction ID
|
|
49
57
|
- **Hash Pairs**: Parent nodes are hashes of child pairs
|
|
50
58
|
- **Root Hash**: Single hash representing all transactions
|
|
@@ -53,6 +61,7 @@ Bitcoin uses merkle trees to efficiently prove transaction inclusion:
|
|
|
53
61
|
## Security Model
|
|
54
62
|
|
|
55
63
|
SPV provides strong security guarantees:
|
|
64
|
+
|
|
56
65
|
- **Proof of Work**: Block headers contain proof of work
|
|
57
66
|
- **Cryptographic Hashes**: Merkle proofs use SHA-256
|
|
58
67
|
- **Chain Validation**: Verify header chain integrity
|
|
@@ -61,12 +70,14 @@ SPV provides strong security guarantees:
|
|
|
61
70
|
## Trade-offs
|
|
62
71
|
|
|
63
72
|
### Advantages
|
|
73
|
+
|
|
64
74
|
- **Low Resource Usage**: Minimal storage and bandwidth
|
|
65
75
|
- **Fast Synchronization**: Quick startup time
|
|
66
76
|
- **Scalability**: Works with any blockchain size
|
|
67
77
|
- **Privacy**: No need to reveal which transactions you care about
|
|
68
78
|
|
|
69
79
|
### Limitations
|
|
80
|
+
|
|
70
81
|
- **Trust Assumptions**: Relies on honest majority of miners
|
|
71
82
|
- **Network Dependency**: Requires connection to full nodes
|
|
72
83
|
- **Delayed Detection**: May not immediately detect invalid blocks
|
|
@@ -95,6 +106,7 @@ const result = await transaction.verify(chainTracker, {
|
|
|
95
106
|
## BEEF Integration
|
|
96
107
|
|
|
97
108
|
SPV works seamlessly with BEEF format:
|
|
109
|
+
|
|
98
110
|
- **Efficient Encoding**: BEEF includes merkle proofs
|
|
99
111
|
- **Batch Verification**: Verify multiple transactions together
|
|
100
112
|
- **Standardized Format**: Consistent across applications
|
|
@@ -7,7 +7,9 @@ How Bitcoin transactions are serialized and deserialized in different formats wi
|
|
|
7
7
|
The SDK supports multiple transaction encoding formats:
|
|
8
8
|
|
|
9
9
|
### Raw Transaction Format
|
|
10
|
+
|
|
10
11
|
Standard Bitcoin transaction serialization:
|
|
12
|
+
|
|
11
13
|
```typescript
|
|
12
14
|
import { Transaction } from '@bsv/sdk'
|
|
13
15
|
|
|
@@ -19,7 +21,9 @@ const tx = Transaction.fromHex(txHex)
|
|
|
19
21
|
```
|
|
20
22
|
|
|
21
23
|
### BEEF Format
|
|
24
|
+
|
|
22
25
|
Bitcoin Extras Extension Format for efficient data exchange:
|
|
26
|
+
|
|
23
27
|
```typescript
|
|
24
28
|
// Serialize to BEEF
|
|
25
29
|
const beefHex = transaction.toBEEF()
|
|
@@ -29,7 +33,9 @@ const tx = Transaction.fromHexBEEF(beefHex)
|
|
|
29
33
|
```
|
|
30
34
|
|
|
31
35
|
### Binary Format
|
|
36
|
+
|
|
32
37
|
Raw binary data for maximum efficiency:
|
|
38
|
+
|
|
33
39
|
```typescript
|
|
34
40
|
// Serialize to binary
|
|
35
41
|
const txBinary = transaction.toBinary()
|
|
@@ -41,6 +47,7 @@ const tx = Transaction.fromBinary(txBinary)
|
|
|
41
47
|
## Serialization Structure
|
|
42
48
|
|
|
43
49
|
### Standard Transaction
|
|
50
|
+
|
|
44
51
|
```
|
|
45
52
|
Version (4 bytes)
|
|
46
53
|
Input Count (varint)
|
|
@@ -51,6 +58,7 @@ Lock Time (4 bytes)
|
|
|
51
58
|
```
|
|
52
59
|
|
|
53
60
|
### Input Structure
|
|
61
|
+
|
|
54
62
|
```
|
|
55
63
|
Previous TX Hash (32 bytes)
|
|
56
64
|
Output Index (4 bytes)
|
|
@@ -60,6 +68,7 @@ Sequence (4 bytes)
|
|
|
60
68
|
```
|
|
61
69
|
|
|
62
70
|
### Output Structure
|
|
71
|
+
|
|
63
72
|
```
|
|
64
73
|
Value (8 bytes)
|
|
65
74
|
Script Length (varint)
|
|
@@ -69,6 +78,7 @@ Locking Script (variable)
|
|
|
69
78
|
## BEEF Enhancements
|
|
70
79
|
|
|
71
80
|
BEEF format adds:
|
|
81
|
+
|
|
72
82
|
- **Merkle Proofs**: SPV verification data
|
|
73
83
|
- **Block Headers**: Chain validation information
|
|
74
84
|
- **Metadata**: Additional transaction context
|
|
@@ -77,16 +87,19 @@ BEEF format adds:
|
|
|
77
87
|
## Encoding Considerations
|
|
78
88
|
|
|
79
89
|
### Size Optimization
|
|
90
|
+
|
|
80
91
|
- Use BEEF for transactions with proofs
|
|
81
92
|
- Use raw format for minimal overhead
|
|
82
93
|
- Consider compression for large batches
|
|
83
94
|
|
|
84
95
|
### Compatibility
|
|
96
|
+
|
|
85
97
|
- Raw format works with all Bitcoin software
|
|
86
98
|
- BEEF requires compatible parsers
|
|
87
99
|
- Binary format is most efficient but less portable
|
|
88
100
|
|
|
89
101
|
### Performance
|
|
102
|
+
|
|
90
103
|
- Binary operations are fastest
|
|
91
104
|
- Hex encoding is human-readable
|
|
92
105
|
- BEEF provides best feature/size ratio
|
|
@@ -94,6 +107,7 @@ BEEF format adds:
|
|
|
94
107
|
## Working with Encodings
|
|
95
108
|
|
|
96
109
|
### Conversion Between Formats
|
|
110
|
+
|
|
97
111
|
```typescript
|
|
98
112
|
// Start with a transaction
|
|
99
113
|
const tx = new Transaction()
|
|
@@ -107,6 +121,7 @@ const beef = tx.toBEEF()
|
|
|
107
121
|
```
|
|
108
122
|
|
|
109
123
|
### Validation
|
|
124
|
+
|
|
110
125
|
```typescript
|
|
111
126
|
// Verify encoding integrity
|
|
112
127
|
const originalTx = Transaction.fromHex(hex)
|
|
@@ -117,16 +132,19 @@ console.log(hex === roundTripHex) // true
|
|
|
117
132
|
## Use Cases
|
|
118
133
|
|
|
119
134
|
### Network Transmission
|
|
135
|
+
|
|
120
136
|
- Use hex for JSON APIs
|
|
121
137
|
- Use binary for efficient protocols
|
|
122
138
|
- Use BEEF for SPV applications
|
|
123
139
|
|
|
124
140
|
### Storage
|
|
141
|
+
|
|
125
142
|
- Raw format for blockchain storage
|
|
126
143
|
- BEEF for application databases
|
|
127
144
|
- Binary for memory-constrained environments
|
|
128
145
|
|
|
129
146
|
### Interoperability
|
|
147
|
+
|
|
130
148
|
- Hex for debugging and logging
|
|
131
149
|
- Raw format for wallet compatibility
|
|
132
150
|
- BEEF for modern Bitcoin applications
|
|
@@ -134,6 +152,7 @@ console.log(hex === roundTripHex) // true
|
|
|
134
152
|
## Error Handling
|
|
135
153
|
|
|
136
154
|
Common encoding issues:
|
|
155
|
+
|
|
137
156
|
- Invalid hex characters
|
|
138
157
|
- Truncated binary data
|
|
139
158
|
- Malformed BEEF structures
|
|
@@ -34,22 +34,26 @@ tx.addOutput({
|
|
|
34
34
|
## Key Concepts
|
|
35
35
|
|
|
36
36
|
### Inputs
|
|
37
|
+
|
|
37
38
|
- Reference previous transaction outputs (UTXOs)
|
|
38
39
|
- Include unlocking scripts to prove ownership
|
|
39
40
|
- Must be fully consumed (no partial spending)
|
|
40
41
|
|
|
41
42
|
### Outputs
|
|
43
|
+
|
|
42
44
|
- Create new UTXOs with specific values
|
|
43
45
|
- Include locking scripts that define spending conditions
|
|
44
46
|
- Can be spent by future transactions
|
|
45
47
|
|
|
46
48
|
### Transaction ID
|
|
49
|
+
|
|
47
50
|
- Unique identifier calculated from transaction data
|
|
48
51
|
- Used to reference the transaction in inputs
|
|
49
52
|
|
|
50
53
|
## Working with Transactions
|
|
51
54
|
|
|
52
55
|
The SDK provides methods to:
|
|
56
|
+
|
|
53
57
|
- Serialize transactions to hex format
|
|
54
58
|
- Calculate transaction fees
|
|
55
59
|
- Verify transaction validity
|
|
@@ -7,11 +7,13 @@ Understanding the security assumptions and trust relationships in BSV TypeScript
|
|
|
7
7
|
The SDK is designed around minimizing trust requirements:
|
|
8
8
|
|
|
9
9
|
### Trustless Verification
|
|
10
|
+
|
|
10
11
|
- **Cryptographic Proofs**: Verify transactions mathematically
|
|
11
12
|
- **SPV Security**: Validate without trusting third parties
|
|
12
13
|
- **Self-Sovereign**: Users control their own keys and data
|
|
13
14
|
|
|
14
15
|
### Minimized Dependencies
|
|
16
|
+
|
|
15
17
|
- **Zero External Dependencies**: Reduces attack surface
|
|
16
18
|
- **Self-Contained**: All cryptographic operations built-in
|
|
17
19
|
- **Auditable**: Open source and transparent implementation
|
|
@@ -19,19 +21,25 @@ The SDK is designed around minimizing trust requirements:
|
|
|
19
21
|
## Trust Relationships
|
|
20
22
|
|
|
21
23
|
### User Trust
|
|
24
|
+
|
|
22
25
|
Users must trust:
|
|
26
|
+
|
|
23
27
|
- **The SDK Code**: Open source and auditable
|
|
24
28
|
- **Their Wallet**: Manages private keys securely
|
|
25
29
|
- **Their Device**: Secure execution environment
|
|
26
30
|
|
|
27
31
|
### Network Trust
|
|
32
|
+
|
|
28
33
|
Applications rely on:
|
|
34
|
+
|
|
29
35
|
- **Bitcoin Network**: Honest majority of miners
|
|
30
36
|
- **Chain Trackers**: Provide accurate blockchain data
|
|
31
37
|
- **SPV Assumptions**: Valid merkle proofs and headers
|
|
32
38
|
|
|
33
39
|
### Service Trust
|
|
40
|
+
|
|
34
41
|
Optional trust relationships:
|
|
42
|
+
|
|
35
43
|
- **Wallet Providers**: If using hosted wallets
|
|
36
44
|
- **ARC Services**: For transaction broadcasting
|
|
37
45
|
- **Overlay Services**: For additional functionality
|
|
@@ -39,12 +47,14 @@ Optional trust relationships:
|
|
|
39
47
|
## Security Assumptions
|
|
40
48
|
|
|
41
49
|
### Cryptographic Security
|
|
50
|
+
|
|
42
51
|
- **secp256k1**: Elliptic curve is secure
|
|
43
52
|
- **SHA-256**: Hash function is collision-resistant
|
|
44
53
|
- **ECDSA**: Digital signature scheme is unforgeable
|
|
45
54
|
- **Random Number Generation**: Entropy source is secure
|
|
46
55
|
|
|
47
56
|
### Network Security
|
|
57
|
+
|
|
48
58
|
- **Proof of Work**: Mining provides security
|
|
49
59
|
- **Longest Chain**: Honest chain has most work
|
|
50
60
|
- **Block Finality**: Deep confirmations prevent reorganization
|
|
@@ -53,6 +63,7 @@ Optional trust relationships:
|
|
|
53
63
|
## Risk Mitigation
|
|
54
64
|
|
|
55
65
|
### Key Management
|
|
66
|
+
|
|
56
67
|
```typescript
|
|
57
68
|
// Minimize private key exposure
|
|
58
69
|
const wallet = new WalletClient() // Keys stay in wallet
|
|
@@ -62,6 +73,7 @@ const wallet = new WalletClient() // Keys stay in wallet
|
|
|
62
73
|
```
|
|
63
74
|
|
|
64
75
|
### Transaction Verification
|
|
76
|
+
|
|
65
77
|
```typescript
|
|
66
78
|
// Always verify important transactions
|
|
67
79
|
const isValid = await transaction.verify(chainTracker, {
|
|
@@ -71,6 +83,7 @@ const isValid = await transaction.verify(chainTracker, {
|
|
|
71
83
|
```
|
|
72
84
|
|
|
73
85
|
### Multiple Sources
|
|
86
|
+
|
|
74
87
|
```typescript
|
|
75
88
|
// Use multiple chain trackers
|
|
76
89
|
const config = {
|
|
@@ -84,6 +97,7 @@ const config = {
|
|
|
84
97
|
## Threat Model
|
|
85
98
|
|
|
86
99
|
### Attacks to Consider
|
|
100
|
+
|
|
87
101
|
- **Private Key Compromise**: Secure key storage
|
|
88
102
|
- **Man-in-the-Middle**: Use HTTPS and verify certificates
|
|
89
103
|
- **Service Downtime**: Implement fallback mechanisms
|
|
@@ -93,6 +107,7 @@ const config = {
|
|
|
93
107
|
## Application Design
|
|
94
108
|
|
|
95
109
|
### Security-First Design
|
|
110
|
+
|
|
96
111
|
```typescript
|
|
97
112
|
// Validate all inputs
|
|
98
113
|
function processTransaction(txHex: string) {
|
|
@@ -106,6 +121,7 @@ function processTransaction(txHex: string) {
|
|
|
106
121
|
```
|
|
107
122
|
|
|
108
123
|
### Error Handling
|
|
124
|
+
|
|
109
125
|
```typescript
|
|
110
126
|
// Handle trust failures gracefully
|
|
111
127
|
try {
|
|
@@ -19,21 +19,27 @@ const isValid = await transaction.verify(chainTracker, {
|
|
|
19
19
|
## Verification Levels
|
|
20
20
|
|
|
21
21
|
### Basic Validation
|
|
22
|
+
|
|
22
23
|
Check transaction structure and format:
|
|
24
|
+
|
|
23
25
|
- Valid input/output formats
|
|
24
26
|
- Correct serialization
|
|
25
27
|
- Proper script syntax
|
|
26
28
|
- Signature format validation
|
|
27
29
|
|
|
28
30
|
### Script Execution
|
|
31
|
+
|
|
29
32
|
Verify that unlocking scripts satisfy locking scripts:
|
|
33
|
+
|
|
30
34
|
- Execute Bitcoin script opcodes
|
|
31
35
|
- Validate signature operations
|
|
32
36
|
- Check script conditions
|
|
33
37
|
- Ensure proper stack state
|
|
34
38
|
|
|
35
39
|
### SPV Verification
|
|
40
|
+
|
|
36
41
|
Confirm transaction inclusion in the blockchain:
|
|
42
|
+
|
|
37
43
|
- Verify merkle proofs
|
|
38
44
|
- Validate block headers
|
|
39
45
|
- Check proof of work
|
|
@@ -42,7 +48,9 @@ Confirm transaction inclusion in the blockchain:
|
|
|
42
48
|
## SDK Verification Methods
|
|
43
49
|
|
|
44
50
|
### Transaction.verify()
|
|
51
|
+
|
|
45
52
|
Complete transaction verification:
|
|
53
|
+
|
|
46
54
|
```typescript
|
|
47
55
|
const result = await transaction.verify(chainTracker, {
|
|
48
56
|
merkleProof: merkleProof,
|
|
@@ -52,7 +60,9 @@ const result = await transaction.verify(chainTracker, {
|
|
|
52
60
|
```
|
|
53
61
|
|
|
54
62
|
### Script Verification
|
|
63
|
+
|
|
55
64
|
Verify individual scripts:
|
|
65
|
+
|
|
56
66
|
```typescript
|
|
57
67
|
const isValid = unlockingScript.verify(
|
|
58
68
|
lockingScript,
|
|
@@ -62,7 +72,9 @@ const isValid = unlockingScript.verify(
|
|
|
62
72
|
```
|
|
63
73
|
|
|
64
74
|
### Signature Verification
|
|
75
|
+
|
|
65
76
|
Check digital signatures:
|
|
77
|
+
|
|
66
78
|
```typescript
|
|
67
79
|
const publicKey = PrivateKey.fromWif(wif).toPublicKey()
|
|
68
80
|
const isValid = publicKey.verify(messageHash, signature)
|
|
@@ -71,7 +83,9 @@ const isValid = publicKey.verify(messageHash, signature)
|
|
|
71
83
|
## Verification Options
|
|
72
84
|
|
|
73
85
|
### Memory Limits
|
|
86
|
+
|
|
74
87
|
Control script execution memory usage:
|
|
88
|
+
|
|
75
89
|
```typescript
|
|
76
90
|
const options = {
|
|
77
91
|
maxMemoryLimit: 50000000 // 50MB limit
|
|
@@ -79,7 +93,9 @@ const options = {
|
|
|
79
93
|
```
|
|
80
94
|
|
|
81
95
|
### Scripts-Only Mode
|
|
96
|
+
|
|
82
97
|
Skip SPV verification for performance:
|
|
98
|
+
|
|
83
99
|
```typescript
|
|
84
100
|
const options = {
|
|
85
101
|
scriptsOnly: true
|
|
@@ -87,7 +103,9 @@ const options = {
|
|
|
87
103
|
```
|
|
88
104
|
|
|
89
105
|
### Custom Chain Tracker
|
|
106
|
+
|
|
90
107
|
Use specific data sources:
|
|
108
|
+
|
|
91
109
|
```typescript
|
|
92
110
|
const customTracker = new WhatsOnChain('testnet')
|
|
93
111
|
const isValid = await transaction.verify(customTracker)
|
|
@@ -96,6 +114,7 @@ const isValid = await transaction.verify(customTracker)
|
|
|
96
114
|
## BEEF Verification
|
|
97
115
|
|
|
98
116
|
BEEF format includes verification data:
|
|
117
|
+
|
|
99
118
|
```typescript
|
|
100
119
|
// BEEF transactions include proofs
|
|
101
120
|
const beefTx = Transaction.fromHexBEEF(beefData)
|
|
@@ -107,6 +126,7 @@ const isValid = await beefTx.verify(chainTracker)
|
|
|
107
126
|
## Error Handling
|
|
108
127
|
|
|
109
128
|
Common verification failures:
|
|
129
|
+
|
|
110
130
|
- Invalid signatures
|
|
111
131
|
- Script execution errors
|
|
112
132
|
- Missing merkle proofs
|
|
@@ -126,7 +146,9 @@ try {
|
|
|
126
146
|
## Performance Considerations
|
|
127
147
|
|
|
128
148
|
### Batch Verification
|
|
149
|
+
|
|
129
150
|
Verify multiple transactions efficiently:
|
|
151
|
+
|
|
130
152
|
```typescript
|
|
131
153
|
const results = await Promise.all(
|
|
132
154
|
transactions.map(tx => tx.verify(chainTracker))
|
|
@@ -134,7 +156,9 @@ const results = await Promise.all(
|
|
|
134
156
|
```
|
|
135
157
|
|
|
136
158
|
### Caching
|
|
159
|
+
|
|
137
160
|
Cache verification results:
|
|
161
|
+
|
|
138
162
|
```typescript
|
|
139
163
|
const verificationCache = new Map()
|
|
140
164
|
|
|
@@ -147,16 +171,19 @@ if (!verificationCache.has(txid)) {
|
|
|
147
171
|
## Security Best Practices
|
|
148
172
|
|
|
149
173
|
### Always Verify
|
|
174
|
+
|
|
150
175
|
- Verify transactions before trusting them
|
|
151
176
|
- Check both script execution and SPV proofs
|
|
152
177
|
- Validate input data before verification
|
|
153
178
|
|
|
154
179
|
### Multiple Sources
|
|
180
|
+
|
|
155
181
|
- Use multiple chain trackers for redundancy
|
|
156
182
|
- Cross-check verification results
|
|
157
183
|
- Implement fallback mechanisms
|
|
158
184
|
|
|
159
185
|
### Resource Limits
|
|
186
|
+
|
|
160
187
|
- Set appropriate memory limits
|
|
161
188
|
- Timeout long-running verifications
|
|
162
189
|
- Monitor verification performance
|
|
@@ -164,6 +191,7 @@ if (!verificationCache.has(txid)) {
|
|
|
164
191
|
## Common Use Cases
|
|
165
192
|
|
|
166
193
|
### Payment Verification
|
|
194
|
+
|
|
167
195
|
```typescript
|
|
168
196
|
// Verify received payment
|
|
169
197
|
const payment = Transaction.fromHex(paymentHex)
|
|
@@ -175,6 +203,7 @@ if (isValid) {
|
|
|
175
203
|
```
|
|
176
204
|
|
|
177
205
|
### Historical Transaction Audit
|
|
206
|
+
|
|
178
207
|
```typescript
|
|
179
208
|
// Verify old transactions
|
|
180
209
|
for (const txHex of historicalTransactions) {
|
|
@@ -187,6 +216,7 @@ for (const txHex of historicalTransactions) {
|
|
|
187
216
|
## Integration Patterns
|
|
188
217
|
|
|
189
218
|
### Wallet Integration
|
|
219
|
+
|
|
190
220
|
```typescript
|
|
191
221
|
// Wallets typically handle verification
|
|
192
222
|
const wallet = new WalletClient()
|
|
@@ -197,6 +227,7 @@ const action = await wallet.createAction({
|
|
|
197
227
|
```
|
|
198
228
|
|
|
199
229
|
### Application Verification
|
|
230
|
+
|
|
200
231
|
```typescript
|
|
201
232
|
// Applications verify received transactions
|
|
202
233
|
async function processIncomingTransaction(txHex: string) {
|
|
@@ -19,6 +19,7 @@ await wallet.authenticate()
|
|
|
19
19
|
## BRC-100 Compliance
|
|
20
20
|
|
|
21
21
|
The SDK follows the BRC-100 standard for wallet communication:
|
|
22
|
+
|
|
22
23
|
- **Standardized APIs**: Consistent interface across different wallets
|
|
23
24
|
- **Authentication**: Secure identity verification
|
|
24
25
|
- **Transaction Signing**: Wallet handles private key operations
|
|
@@ -51,16 +52,19 @@ const action = await wallet.createAction({
|
|
|
51
52
|
## Key Benefits
|
|
52
53
|
|
|
53
54
|
### Security
|
|
55
|
+
|
|
54
56
|
- Private keys never leave the wallet
|
|
55
57
|
- User controls transaction approval
|
|
56
58
|
- Secure authentication protocols
|
|
57
59
|
|
|
58
60
|
### User Experience
|
|
61
|
+
|
|
59
62
|
- Familiar wallet interface
|
|
60
63
|
- Consistent across applications
|
|
61
64
|
- Single sign-on capabilities
|
|
62
65
|
|
|
63
66
|
### Developer Simplicity
|
|
67
|
+
|
|
64
68
|
- No key management complexity
|
|
65
69
|
- Standardized APIs
|
|
66
70
|
- Automatic UTXO handling
|
|
@@ -68,6 +72,7 @@ const action = await wallet.createAction({
|
|
|
68
72
|
## Wallet Types
|
|
69
73
|
|
|
70
74
|
The SDK works with various wallet implementations:
|
|
75
|
+
|
|
71
76
|
- **Desktop Wallets**: Local applications with full control
|
|
72
77
|
- **Web Wallets**: Browser-based wallet services
|
|
73
78
|
- **Mobile Wallets**: Smartphone applications
|
|
@@ -76,6 +81,7 @@ The SDK works with various wallet implementations:
|
|
|
76
81
|
## Error Handling
|
|
77
82
|
|
|
78
83
|
Common wallet integration scenarios:
|
|
84
|
+
|
|
79
85
|
- Wallet not available or offline
|
|
80
86
|
- User denies transaction approval
|
|
81
87
|
- Insufficient funds in wallet
|