@bsv/sdk 1.6.12 → 1.6.15
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/src/transaction/http/HttpClient.d.ts +2 -0
- package/dist/types/src/transaction/http/HttpClient.d.ts.map +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/configuration.md +6 -0
- package/docs/reference/debugging.md +5 -0
- package/docs/reference/errors.md +50 -0
- package/docs/reference/index.md +14 -1
- package/docs/reference/op-codes.md +20 -1
- package/docs/reference/transaction-signatures.md +2 -1
- package/docs/reference/transaction.md +9 -0
- 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
- package/src/transaction/http/HttpClient.ts +2 -0
|
@@ -11,12 +11,15 @@ The key difference is that these digital certificates use cryptographic signatur
|
|
|
11
11
|
## How Certificates Create Trust
|
|
12
12
|
|
|
13
13
|
### The Trust Problem
|
|
14
|
+
|
|
14
15
|
In the digital world, it's easy to claim anything about yourself. Anyone can create a website saying they're a doctor, lawyer, or certified professional. How do you know who to trust?
|
|
15
16
|
|
|
16
17
|
### The Certificate Solution
|
|
18
|
+
|
|
17
19
|
Certificates solve this by having trusted third parties vouch for specific claims. When a university issues you a digital diploma certificate, they're cryptographically signing a statement that says "We verify that this person graduated from our program."
|
|
18
20
|
|
|
19
21
|
Anyone can then verify:
|
|
22
|
+
|
|
20
23
|
1. **The certificate is authentic** (cryptographic signature is valid)
|
|
21
24
|
2. **It hasn't been tampered with** (any changes would break the signature)
|
|
22
25
|
3. **It's still valid** (hasn't expired or been revoked)
|
|
@@ -25,32 +28,39 @@ Anyone can then verify:
|
|
|
25
28
|
## Types of Certificates
|
|
26
29
|
|
|
27
30
|
### Self-Signed Certificates
|
|
28
|
-
|
|
31
|
+
|
|
32
|
+
These are claims you make about yourself, like "My name is John Doe" or "My email is <john@example.com>." While anyone can create these, they serve as a starting point for building your digital identity.
|
|
29
33
|
|
|
30
34
|
**When they're useful:**
|
|
35
|
+
|
|
31
36
|
- Basic profile information
|
|
32
37
|
- Contact preferences
|
|
33
38
|
- Personal statements
|
|
34
39
|
- Starting point for identity building
|
|
35
40
|
|
|
36
41
|
**Limitations:**
|
|
42
|
+
|
|
37
43
|
- Low trust value (anyone can claim anything)
|
|
38
44
|
- Not suitable for high-stakes verification
|
|
39
45
|
- Mainly useful for discovery and basic interaction
|
|
40
46
|
|
|
41
47
|
### Peer-Verified Certificates
|
|
48
|
+
|
|
42
49
|
These are endorsements from other users who can vouch for specific claims about you. Like professional references or character witnesses, they carry more weight when they come from trusted sources.
|
|
43
50
|
|
|
44
51
|
**Examples:**
|
|
52
|
+
|
|
45
53
|
- Colleague endorsing your professional skills
|
|
46
54
|
- Friend confirming your identity
|
|
47
55
|
- Community member vouching for your reputation
|
|
48
56
|
- Business partner confirming successful transactions
|
|
49
57
|
|
|
50
58
|
### Institutional Certificates
|
|
59
|
+
|
|
51
60
|
These come from recognized organizations with established authority and verification processes. They carry the most weight because the issuers have reputations to protect and rigorous verification procedures.
|
|
52
61
|
|
|
53
62
|
**Examples:**
|
|
63
|
+
|
|
54
64
|
- University degree certificates
|
|
55
65
|
- Professional licensing board certifications
|
|
56
66
|
- Government-issued identity documents
|
|
@@ -60,21 +70,27 @@ These come from recognized organizations with established authority and verifica
|
|
|
60
70
|
## Certificate Lifecycle
|
|
61
71
|
|
|
62
72
|
### Creation and Issuance
|
|
73
|
+
|
|
63
74
|
When someone wants to issue you a certificate, they typically:
|
|
75
|
+
|
|
64
76
|
1. **Verify your claim** through their established process
|
|
65
77
|
2. **Create a digital certificate** containing the verified information
|
|
66
78
|
3. **Sign it cryptographically** using their private key
|
|
67
79
|
4. **Deliver it to you** for use in proving the claim
|
|
68
80
|
|
|
69
81
|
### Validation and Trust
|
|
82
|
+
|
|
70
83
|
When someone wants to verify your certificate, they:
|
|
84
|
+
|
|
71
85
|
1. **Check the cryptographic signature** to ensure authenticity
|
|
72
86
|
2. **Verify it hasn't expired** or been revoked
|
|
73
87
|
3. **Assess the issuer's credibility** and authority
|
|
74
88
|
4. **Determine if it meets their requirements** for the specific use case
|
|
75
89
|
|
|
76
90
|
### Renewal and Maintenance
|
|
91
|
+
|
|
77
92
|
Certificates have limited lifespans for security reasons:
|
|
93
|
+
|
|
78
94
|
- **Expiration dates** ensure information stays current
|
|
79
95
|
- **Renewal processes** allow for re-verification
|
|
80
96
|
- **Revocation mechanisms** handle compromised or invalid certificates
|
|
@@ -83,21 +99,27 @@ Certificates have limited lifespans for security reasons:
|
|
|
83
99
|
## Trust Scoring and Reputation
|
|
84
100
|
|
|
85
101
|
### Building Credibility
|
|
102
|
+
|
|
86
103
|
Your overall trustworthiness comes from the combination of all your certificates:
|
|
104
|
+
|
|
87
105
|
- **Quantity**: More verifications generally increase trust
|
|
88
106
|
- **Quality**: Certificates from respected issuers carry more weight
|
|
89
107
|
- **Diversity**: Different types of verification provide broader confidence
|
|
90
108
|
- **Recency**: Fresh certificates are more valuable than old ones
|
|
91
109
|
|
|
92
110
|
### Confidence Levels
|
|
111
|
+
|
|
93
112
|
Different certificates provide different levels of assurance:
|
|
113
|
+
|
|
94
114
|
- **Self-asserted claims** provide basic information but low confidence
|
|
95
115
|
- **Peer verifications** offer moderate confidence from social proof
|
|
96
116
|
- **Service verifications** provide higher confidence from specialized validators
|
|
97
117
|
- **Institutional certificates** offer the highest confidence from established authorities
|
|
98
118
|
|
|
99
119
|
### Context Matters
|
|
120
|
+
|
|
100
121
|
The same certificate might be highly valuable in one context but irrelevant in another:
|
|
122
|
+
|
|
101
123
|
- A medical license is crucial for healthcare but irrelevant for software development
|
|
102
124
|
- A GitHub contribution history matters for programming jobs but not for teaching
|
|
103
125
|
- Age verification is essential for restricted services but unnecessary for professional networking
|
|
@@ -105,21 +127,27 @@ The same certificate might be highly valuable in one context but irrelevant in a
|
|
|
105
127
|
## Privacy and Selective Disclosure
|
|
106
128
|
|
|
107
129
|
### Controlling Information Flow
|
|
130
|
+
|
|
108
131
|
One of the key advantages of certificate-based identity is granular control over what you reveal:
|
|
132
|
+
|
|
109
133
|
- **Public certificates** are discoverable by anyone
|
|
110
134
|
- **Private certificates** are shared only with specific parties
|
|
111
135
|
- **Selective revelation** lets you prove specific claims without revealing everything
|
|
112
136
|
- **Progressive disclosure** allows trust to build gradually
|
|
113
137
|
|
|
114
138
|
### Zero-Knowledge Proofs
|
|
139
|
+
|
|
115
140
|
Advanced techniques allow you to prove things without revealing the underlying data:
|
|
141
|
+
|
|
116
142
|
- Prove you're over 21 without revealing your exact age
|
|
117
143
|
- Prove you have a degree without revealing which university
|
|
118
144
|
- Prove you're a resident without revealing your exact address
|
|
119
145
|
- Prove you're qualified without revealing all your credentials
|
|
120
146
|
|
|
121
147
|
### Consent and Control
|
|
148
|
+
|
|
122
149
|
You maintain control over your certificates:
|
|
150
|
+
|
|
123
151
|
- **Choose what to make public** vs. keep private
|
|
124
152
|
- **Decide who can access** specific information
|
|
125
153
|
- **Revoke access** when relationships change
|
|
@@ -128,28 +156,36 @@ You maintain control over your certificates:
|
|
|
128
156
|
## Real-World Applications
|
|
129
157
|
|
|
130
158
|
### Professional Verification
|
|
159
|
+
|
|
131
160
|
Instead of relying on self-reported resumes, employers can verify:
|
|
161
|
+
|
|
132
162
|
- Educational credentials directly from institutions
|
|
133
163
|
- Work history from previous employers
|
|
134
164
|
- Professional certifications from licensing bodies
|
|
135
165
|
- Skills endorsements from colleagues and clients
|
|
136
166
|
|
|
137
167
|
### Age and Identity Verification
|
|
168
|
+
|
|
138
169
|
Services requiring age or identity verification can:
|
|
170
|
+
|
|
139
171
|
- Verify age without collecting birthdates
|
|
140
172
|
- Confirm identity without storing personal documents
|
|
141
173
|
- Meet regulatory requirements while preserving privacy
|
|
142
174
|
- Reduce fraud through cryptographic verification
|
|
143
175
|
|
|
144
176
|
### Reputation Systems
|
|
177
|
+
|
|
145
178
|
Platforms can build more reliable reputation systems:
|
|
179
|
+
|
|
146
180
|
- Portable reputation that follows users between platforms
|
|
147
181
|
- Verifiable transaction history and feedback
|
|
148
182
|
- Reduced fake accounts and manipulation
|
|
149
183
|
- Incentives for honest behavior
|
|
150
184
|
|
|
151
185
|
### Access Control
|
|
186
|
+
|
|
152
187
|
Organizations can manage access more securely:
|
|
188
|
+
|
|
153
189
|
- Verify membership or employment status
|
|
154
190
|
- Confirm professional qualifications
|
|
155
191
|
- Validate security clearances
|
|
@@ -158,24 +194,28 @@ Organizations can manage access more securely:
|
|
|
158
194
|
## Benefits Over Traditional Systems
|
|
159
195
|
|
|
160
196
|
### Security
|
|
197
|
+
|
|
161
198
|
- **Cryptographic verification** is more secure than physical documents
|
|
162
199
|
- **Tamper evidence** makes forgery virtually impossible
|
|
163
200
|
- **Distributed validation** eliminates single points of failure
|
|
164
201
|
- **Revocation mechanisms** handle compromised credentials quickly
|
|
165
202
|
|
|
166
203
|
### Privacy
|
|
204
|
+
|
|
167
205
|
- **Minimal disclosure** reveals only necessary information
|
|
168
206
|
- **User control** over what information is shared
|
|
169
207
|
- **No central databases** to be breached or misused
|
|
170
208
|
- **Consent-based sharing** puts users in control
|
|
171
209
|
|
|
172
210
|
### Interoperability
|
|
211
|
+
|
|
173
212
|
- **Standard formats** work across different systems
|
|
174
213
|
- **Portable credentials** move between applications
|
|
175
214
|
- **Universal verification** works anywhere in the world
|
|
176
215
|
- **Cross-platform compatibility** reduces vendor lock-in
|
|
177
216
|
|
|
178
217
|
### Efficiency
|
|
218
|
+
|
|
179
219
|
- **Automated verification** reduces manual processes
|
|
180
220
|
- **Real-time validation** provides instant results
|
|
181
221
|
- **Reduced paperwork** streamlines credential management
|
|
@@ -184,28 +224,36 @@ Organizations can manage access more securely:
|
|
|
184
224
|
## Challenges and Considerations
|
|
185
225
|
|
|
186
226
|
### User Experience
|
|
227
|
+
|
|
187
228
|
Making certificate systems user-friendly requires:
|
|
229
|
+
|
|
188
230
|
- **Intuitive interfaces** that hide complexity
|
|
189
231
|
- **Clear explanations** of what certificates mean
|
|
190
232
|
- **Simple management tools** for organizing credentials
|
|
191
233
|
- **Seamless integration** with existing workflows
|
|
192
234
|
|
|
193
235
|
### Recovery and Backup
|
|
236
|
+
|
|
194
237
|
Unlike traditional documents, losing access to digital certificates can be permanent:
|
|
238
|
+
|
|
195
239
|
- **Backup strategies** are essential for important credentials
|
|
196
240
|
- **Recovery mechanisms** must balance security with usability
|
|
197
241
|
- **Key management** becomes critical for certificate access
|
|
198
242
|
- **Succession planning** for organizational certificates
|
|
199
243
|
|
|
200
244
|
### Adoption and Network Effects
|
|
245
|
+
|
|
201
246
|
Certificate systems become more valuable as adoption grows:
|
|
247
|
+
|
|
202
248
|
- **Issuer participation** is needed for valuable certificates
|
|
203
249
|
- **Verifier acceptance** determines practical utility
|
|
204
250
|
- **User adoption** creates network effects
|
|
205
251
|
- **Standardization** enables interoperability
|
|
206
252
|
|
|
207
253
|
### Legal and Regulatory
|
|
254
|
+
|
|
208
255
|
Integrating with existing legal frameworks requires:
|
|
256
|
+
|
|
209
257
|
- **Regulatory compliance** with identity verification laws
|
|
210
258
|
- **Legal recognition** of digital certificates
|
|
211
259
|
- **Audit trails** for compliance reporting
|
|
@@ -216,24 +264,28 @@ Integrating with existing legal frameworks requires:
|
|
|
216
264
|
As certificate-based identity systems mature, we can expect:
|
|
217
265
|
|
|
218
266
|
### Widespread Adoption
|
|
267
|
+
|
|
219
268
|
- **Government integration** with official identity documents
|
|
220
269
|
- **Educational institutions** issuing digital diplomas
|
|
221
270
|
- **Professional organizations** moving to digital certifications
|
|
222
271
|
- **Employers** accepting and requiring digital credentials
|
|
223
272
|
|
|
224
273
|
### Enhanced Privacy
|
|
274
|
+
|
|
225
275
|
- **Zero-knowledge proofs** becoming standard
|
|
226
276
|
- **Selective disclosure** built into all systems
|
|
227
277
|
- **Privacy-preserving verification** as the default
|
|
228
278
|
- **User control** over all personal data
|
|
229
279
|
|
|
230
280
|
### Improved User Experience
|
|
281
|
+
|
|
231
282
|
- **Seamless integration** with daily digital activities
|
|
232
283
|
- **Automated verification** reducing friction
|
|
233
284
|
- **Intelligent recommendations** for credential building
|
|
234
285
|
- **Universal acceptance** across platforms and services
|
|
235
286
|
|
|
236
287
|
### New Possibilities
|
|
288
|
+
|
|
237
289
|
- **Micro-credentials** for specific skills and achievements
|
|
238
290
|
- **Dynamic certificates** that update automatically
|
|
239
291
|
- **Composite credentials** combining multiple sources
|
package/docs/concepts/index.md
CHANGED
|
@@ -5,56 +5,71 @@ Essential concepts for understanding and using the BSV TypeScript SDK effectivel
|
|
|
5
5
|
## Core Bitcoin Concepts
|
|
6
6
|
|
|
7
7
|
### [Transaction Structure](./transaction-structure.md)
|
|
8
|
+
|
|
8
9
|
Understanding Bitcoin transactions, inputs, outputs, and how they work in the SDK.
|
|
9
10
|
|
|
10
11
|
### [Script Templates](./script-templates.md)
|
|
12
|
+
|
|
11
13
|
Standard and custom Bitcoin script patterns available in the SDK.
|
|
12
14
|
|
|
13
15
|
### [Digital Signatures](./signatures.md)
|
|
16
|
+
|
|
14
17
|
How digital signatures work in Bitcoin and their implementation in the SDK.
|
|
15
18
|
|
|
16
19
|
### [Transaction Verification](./verification.md)
|
|
20
|
+
|
|
17
21
|
Understanding how to verify Bitcoin transactions using the SDK.
|
|
18
22
|
|
|
19
23
|
### [SPV Verification](./spv-verification.md)
|
|
24
|
+
|
|
20
25
|
Simplified Payment Verification and merkle proof concepts for lightweight clients.
|
|
21
26
|
|
|
22
27
|
### [Transaction Fees](./fees.md)
|
|
28
|
+
|
|
23
29
|
How Bitcoin transaction fees work and fee optimization strategies.
|
|
24
30
|
|
|
25
31
|
## SDK Architecture
|
|
26
32
|
|
|
27
33
|
### [SDK Design Philosophy](./sdk-philosophy.md)
|
|
34
|
+
|
|
28
35
|
Core principles: zero dependencies, SPV-first approach, and vendor neutrality.
|
|
29
36
|
|
|
30
37
|
### [Wallet Integration](./wallet-integration.md)
|
|
38
|
+
|
|
31
39
|
How the SDK connects with Bitcoin wallets and manages authentication.
|
|
32
40
|
|
|
33
41
|
### [Chain Tracking](./chain-tracking.md)
|
|
42
|
+
|
|
34
43
|
Understanding how the SDK interacts with the Bitcoin network for transaction data.
|
|
35
44
|
|
|
36
45
|
## Data Formats
|
|
37
46
|
|
|
38
47
|
### [BEEF Format](./beef.md)
|
|
48
|
+
|
|
39
49
|
Bitcoin Extras Extension Format for efficient transaction data exchange.
|
|
40
50
|
|
|
41
51
|
### [Transaction Encoding](./transaction-encoding.md)
|
|
52
|
+
|
|
42
53
|
How transactions are serialized and deserialized in the SDK.
|
|
43
54
|
|
|
44
55
|
## Identity and Certificates
|
|
45
56
|
|
|
46
57
|
### [Decentralized Identity](./decentralized-identity.md)
|
|
58
|
+
|
|
47
59
|
Understanding BSV's decentralized identity system and certificate-based verification.
|
|
48
60
|
|
|
49
61
|
### [Identity Certificates](./identity-certificates.md)
|
|
62
|
+
|
|
50
63
|
How cryptographic certificates work for identity claims and verification.
|
|
51
64
|
|
|
52
65
|
## Security Model
|
|
53
66
|
|
|
54
67
|
### [Key Management](./key-management.md)
|
|
68
|
+
|
|
55
69
|
How private keys, public keys, and cryptographic operations work in the SDK.
|
|
56
70
|
|
|
57
71
|
### [Trust Model](./trust-model.md)
|
|
72
|
+
|
|
58
73
|
Understanding the security assumptions and trust relationships in SDK applications.
|
|
59
74
|
|
|
60
75
|
---
|
|
@@ -21,6 +21,7 @@ const publicKey = privateKey.toPublicKey()
|
|
|
21
21
|
Private keys are 256-bit numbers that control Bitcoin funds:
|
|
22
22
|
|
|
23
23
|
### Generation
|
|
24
|
+
|
|
24
25
|
```typescript
|
|
25
26
|
// Secure random generation
|
|
26
27
|
const privKey = PrivateKey.fromRandom()
|
|
@@ -30,6 +31,7 @@ const privKey2 = PrivateKey.fromString('hex_string')
|
|
|
30
31
|
```
|
|
31
32
|
|
|
32
33
|
### Formats
|
|
34
|
+
|
|
33
35
|
```typescript
|
|
34
36
|
// WIF (Wallet Import Format)
|
|
35
37
|
const wif = privateKey.toWif()
|
|
@@ -46,6 +48,7 @@ const der = privateKey.toDER()
|
|
|
46
48
|
Public keys are derived from private keys and can be shared safely:
|
|
47
49
|
|
|
48
50
|
### Derivation
|
|
51
|
+
|
|
49
52
|
```typescript
|
|
50
53
|
// Always derive from private key
|
|
51
54
|
const publicKey = privateKey.toPublicKey()
|
|
@@ -54,6 +57,7 @@ const publicKey = privateKey.toPublicKey()
|
|
|
54
57
|
```
|
|
55
58
|
|
|
56
59
|
### Formats
|
|
60
|
+
|
|
57
61
|
```typescript
|
|
58
62
|
// Compressed (33 bytes) - preferred
|
|
59
63
|
const compressed = publicKey.toString()
|
|
@@ -91,12 +95,14 @@ const childPubKey = childKey.toPublicKey()
|
|
|
91
95
|
## Security Considerations
|
|
92
96
|
|
|
93
97
|
### Private Key Security
|
|
98
|
+
|
|
94
99
|
- **Never expose**: Private keys should never be logged or transmitted
|
|
95
100
|
- **Secure storage**: Use encrypted storage for private keys
|
|
96
101
|
- **Random generation**: Always use cryptographically secure randomness
|
|
97
102
|
- **Access control**: Limit who can access private key operations
|
|
98
103
|
|
|
99
104
|
### Best Practices
|
|
105
|
+
|
|
100
106
|
```typescript
|
|
101
107
|
// Good: Generate securely
|
|
102
108
|
const key = PrivateKey.fromRandom()
|
|
@@ -149,6 +155,7 @@ const key3 = PrivateKey.fromDER(derBytes)
|
|
|
149
155
|
## Cryptographic Operations
|
|
150
156
|
|
|
151
157
|
The SDK provides secure implementations of:
|
|
158
|
+
|
|
152
159
|
- **ECDSA**: Digital signature algorithm
|
|
153
160
|
- **ECDH**: Key exchange protocol
|
|
154
161
|
- **Hash Functions**: SHA-256, RIPEMD-160
|
|
@@ -157,6 +164,7 @@ The SDK provides secure implementations of:
|
|
|
157
164
|
## Memory Management
|
|
158
165
|
|
|
159
166
|
Sensitive key data should be cleared when no longer needed:
|
|
167
|
+
|
|
160
168
|
- Use secure memory practices
|
|
161
169
|
- Clear variables containing key data
|
|
162
170
|
- Avoid keeping keys in memory longer than necessary
|
|
@@ -164,6 +172,7 @@ Sensitive key data should be cleared when no longer needed:
|
|
|
164
172
|
## Testing and Development
|
|
165
173
|
|
|
166
174
|
For development and testing:
|
|
175
|
+
|
|
167
176
|
- Use testnet for experiments
|
|
168
177
|
- Generate new keys for each test
|
|
169
178
|
- Never use mainnet keys in test code
|
|
@@ -22,7 +22,9 @@ const unlockingScript = template.unlock(privateKey, signature)
|
|
|
22
22
|
## Standard Templates
|
|
23
23
|
|
|
24
24
|
### P2PKH (Pay to Public Key Hash)
|
|
25
|
+
|
|
25
26
|
The most common Bitcoin script pattern:
|
|
27
|
+
|
|
26
28
|
```typescript
|
|
27
29
|
const p2pkh = new P2PKH()
|
|
28
30
|
const lock = p2pkh.lock(publicKeyHash)
|
|
@@ -30,7 +32,9 @@ const unlock = p2pkh.unlock(privateKey, signature)
|
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
### P2PK (Pay to Public Key)
|
|
35
|
+
|
|
33
36
|
Direct payment to a public key:
|
|
37
|
+
|
|
34
38
|
```typescript
|
|
35
39
|
const p2pk = new P2PK()
|
|
36
40
|
const lock = p2pk.lock(publicKey)
|
|
@@ -38,7 +42,9 @@ const unlock = p2pk.unlock(signature)
|
|
|
38
42
|
```
|
|
39
43
|
|
|
40
44
|
### OP_RETURN (Data Storage)
|
|
45
|
+
|
|
41
46
|
Store arbitrary data on-chain:
|
|
47
|
+
|
|
42
48
|
```typescript
|
|
43
49
|
const opReturn = new OpReturn()
|
|
44
50
|
const lock = opReturn.lock(data)
|
|
@@ -86,16 +92,19 @@ interface ScriptTemplate {
|
|
|
86
92
|
## Benefits
|
|
87
93
|
|
|
88
94
|
### Reusability
|
|
95
|
+
|
|
89
96
|
- Standard patterns for common use cases
|
|
90
97
|
- Consistent implementation across applications
|
|
91
98
|
- Reduced development time
|
|
92
99
|
|
|
93
100
|
### Security
|
|
101
|
+
|
|
94
102
|
- Well-tested script patterns
|
|
95
103
|
- Reduced risk of script errors
|
|
96
104
|
- Best practice implementations
|
|
97
105
|
|
|
98
106
|
### Maintainability
|
|
107
|
+
|
|
99
108
|
- Clear separation of script logic
|
|
100
109
|
- Easy to update and modify
|
|
101
110
|
- Testable components
|
|
@@ -103,6 +112,7 @@ interface ScriptTemplate {
|
|
|
103
112
|
## Working with Templates
|
|
104
113
|
|
|
105
114
|
### Transaction Integration
|
|
115
|
+
|
|
106
116
|
```typescript
|
|
107
117
|
// Use template in transaction
|
|
108
118
|
const output = {
|
|
@@ -118,6 +128,7 @@ const input = {
|
|
|
118
128
|
```
|
|
119
129
|
|
|
120
130
|
### Fee Estimation
|
|
131
|
+
|
|
121
132
|
```typescript
|
|
122
133
|
// Estimate script size for fee calculation
|
|
123
134
|
const estimatedSize = template.estimateLength([publicKeyHash])
|
|
@@ -127,6 +138,7 @@ const fee = estimatedSize * feePerByte
|
|
|
127
138
|
## Advanced Patterns
|
|
128
139
|
|
|
129
140
|
### Multi-Signature
|
|
141
|
+
|
|
130
142
|
```typescript
|
|
131
143
|
class MultiSigTemplate implements ScriptTemplate {
|
|
132
144
|
lock(threshold: number, publicKeys: string[]): Script {
|
|
@@ -140,6 +152,7 @@ class MultiSigTemplate implements ScriptTemplate {
|
|
|
140
152
|
```
|
|
141
153
|
|
|
142
154
|
### Conditional Scripts
|
|
155
|
+
|
|
143
156
|
```typescript
|
|
144
157
|
class ConditionalTemplate implements ScriptTemplate {
|
|
145
158
|
lock(condition: Script, trueScript: Script, falseScript: Script): Script {
|
|
@@ -5,6 +5,7 @@ This document details the core principles behind the BSV TypeScript SDK architec
|
|
|
5
5
|
## Zero Dependencies
|
|
6
6
|
|
|
7
7
|
The SDK is built without external dependencies to:
|
|
8
|
+
|
|
8
9
|
- Minimize security attack surface
|
|
9
10
|
- Reduce bundle size and complexity
|
|
10
11
|
- Ensure long-term stability
|
|
@@ -13,6 +14,7 @@ The SDK is built without external dependencies to:
|
|
|
13
14
|
## SPV-First Approach
|
|
14
15
|
|
|
15
16
|
The SDK prioritizes Simplified Payment Verification:
|
|
17
|
+
|
|
16
18
|
- **Lightweight**: No need to download the full blockchain
|
|
17
19
|
- **Efficient**: Verify transactions using merkle proofs
|
|
18
20
|
- **Scalable**: Works with millions of transactions
|
|
@@ -21,6 +23,7 @@ The SDK prioritizes Simplified Payment Verification:
|
|
|
21
23
|
## Vendor Neutrality
|
|
22
24
|
|
|
23
25
|
The SDK works with any compliant Bitcoin infrastructure:
|
|
26
|
+
|
|
24
27
|
- **Wallet Agnostic**: Supports any BRC-100 compliant wallet
|
|
25
28
|
- **Network Flexible**: Works with different chain tracking services
|
|
26
29
|
- **Service Independent**: No lock-in to specific providers
|
|
@@ -28,6 +31,7 @@ The SDK works with any compliant Bitcoin infrastructure:
|
|
|
28
31
|
## Modular Design
|
|
29
32
|
|
|
30
33
|
Components are designed to work independently:
|
|
34
|
+
|
|
31
35
|
- **Composable**: Mix and match functionality as needed
|
|
32
36
|
- **Extensible**: Easy to add custom implementations
|
|
33
37
|
- **Testable**: Each component can be tested in isolation
|
|
@@ -36,6 +40,7 @@ Components are designed to work independently:
|
|
|
36
40
|
## TypeScript-First
|
|
37
41
|
|
|
38
42
|
Built specifically for TypeScript to provide:
|
|
43
|
+
|
|
39
44
|
- **Type Safety**: Catch errors at compile time
|
|
40
45
|
- **Developer Experience**: Rich IDE support and autocomplete
|
|
41
46
|
- **Documentation**: Types serve as living documentation
|
|
@@ -44,6 +49,7 @@ Built specifically for TypeScript to provide:
|
|
|
44
49
|
## Security by Design
|
|
45
50
|
|
|
46
51
|
Security considerations are built into every component:
|
|
52
|
+
|
|
47
53
|
- **Cryptographic Primitives**: Secure implementations of Bitcoin cryptography
|
|
48
54
|
- **Input Validation**: All inputs are validated and sanitized
|
|
49
55
|
- **Error Handling**: Comprehensive error handling prevents information leakage
|
|
@@ -52,6 +58,7 @@ Security considerations are built into every component:
|
|
|
52
58
|
## Performance Focused
|
|
53
59
|
|
|
54
60
|
Optimized for real-world application needs:
|
|
61
|
+
|
|
55
62
|
- **Memory Efficient**: Minimal memory footprint
|
|
56
63
|
- **Fast Execution**: Optimized critical paths
|
|
57
64
|
- **Batch Processing**: Support for high-throughput scenarios
|
|
@@ -60,6 +67,7 @@ Optimized for real-world application needs:
|
|
|
60
67
|
## Developer-Friendly
|
|
61
68
|
|
|
62
69
|
Designed to make Bitcoin development accessible:
|
|
70
|
+
|
|
63
71
|
- **Clear APIs**: Intuitive method names and parameters
|
|
64
72
|
- **Comprehensive Documentation**: Tutorials, guides, and references
|
|
65
73
|
- **Working Examples**: Real code that developers can use immediately
|
|
@@ -22,6 +22,7 @@ const isValid = publicKey.verify(message, signature)
|
|
|
22
22
|
## Bitcoin Signatures
|
|
23
23
|
|
|
24
24
|
Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm):
|
|
25
|
+
|
|
25
26
|
- **secp256k1**: The elliptic curve used by Bitcoin
|
|
26
27
|
- **SHA-256**: Hash function for message digests
|
|
27
28
|
- **DER Encoding**: Standard format for signature serialization
|
|
@@ -31,25 +32,33 @@ Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm):
|
|
|
31
32
|
SIGHASH flags determine what parts of a transaction are signed:
|
|
32
33
|
|
|
33
34
|
### SIGHASH_ALL (Default)
|
|
35
|
+
|
|
34
36
|
Signs all inputs and outputs:
|
|
37
|
+
|
|
35
38
|
```typescript
|
|
36
39
|
const signature = privateKey.sign(txHash, 'all')
|
|
37
40
|
```
|
|
38
41
|
|
|
39
42
|
### SIGHASH_NONE
|
|
43
|
+
|
|
40
44
|
Signs all inputs but no outputs:
|
|
45
|
+
|
|
41
46
|
```typescript
|
|
42
47
|
const signature = privateKey.sign(txHash, 'none')
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
### SIGHASH_SINGLE
|
|
51
|
+
|
|
46
52
|
Signs all inputs and one corresponding output:
|
|
53
|
+
|
|
47
54
|
```typescript
|
|
48
55
|
const signature = privateKey.sign(txHash, 'single')
|
|
49
56
|
```
|
|
50
57
|
|
|
51
58
|
### SIGHASH_ANYONECANPAY
|
|
59
|
+
|
|
52
60
|
Can be combined with other flags to sign only one input:
|
|
61
|
+
|
|
53
62
|
```typescript
|
|
54
63
|
const signature = privateKey.sign(txHash, 'all|anyonecanpay')
|
|
55
64
|
```
|
|
@@ -102,16 +111,19 @@ const s = signature.s
|
|
|
102
111
|
## Security Considerations
|
|
103
112
|
|
|
104
113
|
### Nonce Security
|
|
114
|
+
|
|
105
115
|
- Each signature must use a unique, random nonce
|
|
106
116
|
- Reusing nonces can leak private keys
|
|
107
117
|
- The SDK handles nonce generation securely
|
|
108
118
|
|
|
109
119
|
### Signature Malleability
|
|
120
|
+
|
|
110
121
|
- Bitcoin signatures can be modified without invalidating them
|
|
111
122
|
- Use canonical signatures to prevent malleability
|
|
112
123
|
- The SDK produces canonical signatures by default
|
|
113
124
|
|
|
114
125
|
### Hash Types
|
|
126
|
+
|
|
115
127
|
- Choose appropriate SIGHASH types for your use case
|
|
116
128
|
- SIGHASH_ALL is safest for most applications
|
|
117
129
|
- Other types enable advanced transaction patterns
|
|
@@ -119,6 +131,7 @@ const s = signature.s
|
|
|
119
131
|
## Common Patterns
|
|
120
132
|
|
|
121
133
|
### Multi-Input Signing
|
|
134
|
+
|
|
122
135
|
```typescript
|
|
123
136
|
// Sign multiple inputs in a transaction
|
|
124
137
|
for (let i = 0; i < transaction.inputs.length; i++) {
|
|
@@ -128,6 +141,7 @@ for (let i = 0; i < transaction.inputs.length; i++) {
|
|
|
128
141
|
```
|
|
129
142
|
|
|
130
143
|
### Conditional Signatures
|
|
144
|
+
|
|
131
145
|
```typescript
|
|
132
146
|
// Different signatures for different conditions
|
|
133
147
|
const signature1 = privateKey1.sign(txHash, 'all')
|
|
@@ -137,6 +151,7 @@ const signature2 = privateKey2.sign(txHash, 'single')
|
|
|
137
151
|
## Error Handling
|
|
138
152
|
|
|
139
153
|
Common signature issues:
|
|
154
|
+
|
|
140
155
|
- Invalid private key format
|
|
141
156
|
- Incorrect message hash
|
|
142
157
|
- Malformed signature data
|