@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.
- package/dist/cjs/package.json +1 -1
- package/docs/fast-docs.png +0 -0
- package/docs/index.md +49 -44
- package/docs/swagger.png +0 -0
- package/package.json +1 -1
- package/docs/MARKDOWN_VALIDATION_GUIDE.md +0 -175
- package/docs/concepts/beef.md +0 -92
- package/docs/concepts/chain-tracking.md +0 -134
- package/docs/concepts/decentralized-identity.md +0 -221
- package/docs/concepts/fees.md +0 -249
- package/docs/concepts/identity-certificates.md +0 -307
- package/docs/concepts/index.md +0 -77
- package/docs/concepts/key-management.md +0 -185
- package/docs/concepts/script-templates.md +0 -176
- package/docs/concepts/sdk-philosophy.md +0 -80
- package/docs/concepts/signatures.md +0 -194
- package/docs/concepts/spv-verification.md +0 -118
- package/docs/concepts/transaction-encoding.md +0 -167
- package/docs/concepts/transaction-structure.md +0 -67
- package/docs/concepts/trust-model.md +0 -139
- package/docs/concepts/verification.md +0 -250
- package/docs/concepts/wallet-integration.md +0 -101
- package/docs/guides/development-wallet-setup.md +0 -374
- package/docs/guides/direct-transaction-creation.md +0 -147
- package/docs/guides/http-client-configuration.md +0 -488
- package/docs/guides/index.md +0 -138
- package/docs/guides/large-transactions.md +0 -448
- package/docs/guides/multisig-transactions.md +0 -792
- package/docs/guides/security-best-practices.md +0 -494
- package/docs/guides/transaction-batching.md +0 -132
- package/docs/guides/transaction-signing-methods.md +0 -419
- package/docs/reference/arc-config.md +0 -698
- package/docs/reference/brc-100.md +0 -33
- package/docs/reference/configuration.md +0 -835
- package/docs/reference/debugging.md +0 -705
- package/docs/reference/errors.md +0 -597
- package/docs/reference/index.md +0 -111
- package/docs/reference/network-config.md +0 -914
- package/docs/reference/op-codes.md +0 -325
- package/docs/reference/transaction-signatures.md +0 -95
- package/docs/tutorials/advanced-transaction.md +0 -572
- package/docs/tutorials/aes-encryption.md +0 -949
- package/docs/tutorials/authfetch-tutorial.md +0 -986
- package/docs/tutorials/ecdh-key-exchange.md +0 -549
- package/docs/tutorials/elliptic-curve-fundamentals.md +0 -606
- package/docs/tutorials/error-handling.md +0 -1216
- package/docs/tutorials/first-transaction-low-level.md +0 -205
- package/docs/tutorials/first-transaction.md +0 -275
- package/docs/tutorials/hashes-and-hmacs.md +0 -788
- package/docs/tutorials/identity-management.md +0 -729
- package/docs/tutorials/index.md +0 -219
- package/docs/tutorials/key-management.md +0 -538
- package/docs/tutorials/protowallet-development.md +0 -743
- package/docs/tutorials/script-construction.md +0 -690
- package/docs/tutorials/spv-merkle-proofs.md +0 -685
- package/docs/tutorials/testnet-transactions-low-level.md +0 -359
- package/docs/tutorials/transaction-broadcasting.md +0 -538
- package/docs/tutorials/transaction-types.md +0 -420
- package/docs/tutorials/type-42.md +0 -568
- package/docs/tutorials/uhrp-storage.md +0 -599
|
@@ -1,698 +0,0 @@
|
|
|
1
|
-
# ARC Configuration Reference
|
|
2
|
-
|
|
3
|
-
Complete reference for configuring ARC (Application Resource Center) connections and settings in the BSV TypeScript SDK.
|
|
4
|
-
|
|
5
|
-
## ARC Configuration Interface
|
|
6
|
-
|
|
7
|
-
### ARCConfig
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
interface ARCConfig {
|
|
11
|
-
url: string
|
|
12
|
-
apiKey?: string
|
|
13
|
-
deploymentId?: string
|
|
14
|
-
timeout?: number
|
|
15
|
-
retries?: number
|
|
16
|
-
retryDelay?: number
|
|
17
|
-
headers?: Record<string, string>
|
|
18
|
-
authentication?: ARCAuthentication
|
|
19
|
-
endpoints?: ARCEndpoints
|
|
20
|
-
limits?: ARCLimits
|
|
21
|
-
monitoring?: ARCMonitoring
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### ARCAuthentication
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
interface ARCAuthentication {
|
|
29
|
-
type: 'apiKey' | 'bearer' | 'basic' | 'custom'
|
|
30
|
-
credentials: {
|
|
31
|
-
apiKey?: string
|
|
32
|
-
token?: string
|
|
33
|
-
username?: string
|
|
34
|
-
password?: string
|
|
35
|
-
custom?: Record<string, any>
|
|
36
|
-
}
|
|
37
|
-
refreshToken?: string
|
|
38
|
-
expiresAt?: number
|
|
39
|
-
autoRefresh?: boolean
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### ARCEndpoints
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
interface ARCEndpoints {
|
|
47
|
-
submit?: string
|
|
48
|
-
query?: string
|
|
49
|
-
status?: string
|
|
50
|
-
health?: string
|
|
51
|
-
fees?: string
|
|
52
|
-
utxos?: string
|
|
53
|
-
balance?: string
|
|
54
|
-
history?: string
|
|
55
|
-
broadcast?: string
|
|
56
|
-
merkleProof?: string
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### ARCLimits
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
interface ARCLimits {
|
|
64
|
-
maxTransactionSize?: number
|
|
65
|
-
maxBatchSize?: number
|
|
66
|
-
maxConcurrentRequests?: number
|
|
67
|
-
rateLimit?: {
|
|
68
|
-
requests: number
|
|
69
|
-
window: number // milliseconds
|
|
70
|
-
}
|
|
71
|
-
quotas?: {
|
|
72
|
-
daily?: number
|
|
73
|
-
monthly?: number
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### ARCMonitoring
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
interface ARCMonitoring {
|
|
82
|
-
enabled: boolean
|
|
83
|
-
healthCheck?: {
|
|
84
|
-
interval: number // milliseconds
|
|
85
|
-
timeout: number
|
|
86
|
-
retries: number
|
|
87
|
-
}
|
|
88
|
-
metrics?: {
|
|
89
|
-
enabled: boolean
|
|
90
|
-
endpoint?: string
|
|
91
|
-
interval: number
|
|
92
|
-
}
|
|
93
|
-
alerts?: {
|
|
94
|
-
enabled: boolean
|
|
95
|
-
thresholds: {
|
|
96
|
-
errorRate: number
|
|
97
|
-
responseTime: number
|
|
98
|
-
availability: number
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Predefined ARC Configurations
|
|
105
|
-
|
|
106
|
-
### Mainnet ARC Providers
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
const MAINNET_ARC_CONFIGS: Record<string, ARCConfig> = {
|
|
110
|
-
taal: {
|
|
111
|
-
url: 'https://arc.taal.com',
|
|
112
|
-
timeout: 30000,
|
|
113
|
-
retries: 3,
|
|
114
|
-
retryDelay: 1000,
|
|
115
|
-
endpoints: {
|
|
116
|
-
submit: '/v1/tx',
|
|
117
|
-
query: '/v1/tx/{txid}',
|
|
118
|
-
status: '/v1/tx/{txid}/status',
|
|
119
|
-
health: '/v1/health',
|
|
120
|
-
fees: '/v1/policy/fees',
|
|
121
|
-
broadcast: '/v1/tx/broadcast'
|
|
122
|
-
},
|
|
123
|
-
limits: {
|
|
124
|
-
maxTransactionSize: 10000000, // 10MB
|
|
125
|
-
maxBatchSize: 100,
|
|
126
|
-
maxConcurrentRequests: 10,
|
|
127
|
-
rateLimit: {
|
|
128
|
-
requests: 1000,
|
|
129
|
-
window: 60000 // 1 minute
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
monitoring: {
|
|
133
|
-
enabled: true,
|
|
134
|
-
healthCheck: {
|
|
135
|
-
interval: 30000,
|
|
136
|
-
timeout: 5000,
|
|
137
|
-
retries: 3
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
gorillapool: {
|
|
143
|
-
url: 'https://arc.gorillapool.io',
|
|
144
|
-
timeout: 30000,
|
|
145
|
-
retries: 3,
|
|
146
|
-
retryDelay: 1000,
|
|
147
|
-
endpoints: {
|
|
148
|
-
submit: '/v1/tx',
|
|
149
|
-
query: '/v1/tx/{txid}',
|
|
150
|
-
status: '/v1/tx/{txid}/status',
|
|
151
|
-
health: '/v1/health',
|
|
152
|
-
fees: '/v1/policy/fees'
|
|
153
|
-
},
|
|
154
|
-
limits: {
|
|
155
|
-
maxTransactionSize: 10000000,
|
|
156
|
-
maxBatchSize: 50,
|
|
157
|
-
maxConcurrentRequests: 5,
|
|
158
|
-
rateLimit: {
|
|
159
|
-
requests: 500,
|
|
160
|
-
window: 60000
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
monitoring: {
|
|
164
|
-
enabled: true,
|
|
165
|
-
healthCheck: {
|
|
166
|
-
interval: 60000,
|
|
167
|
-
timeout: 10000,
|
|
168
|
-
retries: 2
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Testnet ARC Providers
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
const TESTNET_ARC_CONFIGS: Record<string, ARCConfig> = {
|
|
179
|
-
taal_testnet: {
|
|
180
|
-
url: 'https://arc-testnet.taal.com',
|
|
181
|
-
timeout: 30000,
|
|
182
|
-
retries: 3,
|
|
183
|
-
retryDelay: 1000,
|
|
184
|
-
endpoints: {
|
|
185
|
-
submit: '/v1/tx',
|
|
186
|
-
query: '/v1/tx/{txid}',
|
|
187
|
-
status: '/v1/tx/{txid}/status',
|
|
188
|
-
health: '/v1/health',
|
|
189
|
-
fees: '/v1/policy/fees'
|
|
190
|
-
},
|
|
191
|
-
limits: {
|
|
192
|
-
maxTransactionSize: 10000000,
|
|
193
|
-
maxBatchSize: 100,
|
|
194
|
-
maxConcurrentRequests: 20,
|
|
195
|
-
rateLimit: {
|
|
196
|
-
requests: 2000,
|
|
197
|
-
window: 60000
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
monitoring: {
|
|
201
|
-
enabled: true,
|
|
202
|
-
healthCheck: {
|
|
203
|
-
interval: 30000,
|
|
204
|
-
timeout: 5000,
|
|
205
|
-
retries: 3
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## ARC Configuration Builder
|
|
213
|
-
|
|
214
|
-
### ARCConfigBuilder Class
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
class ARCConfigBuilder {
|
|
218
|
-
private config: Partial<ARCConfig> = {}
|
|
219
|
-
|
|
220
|
-
url(url: string): ARCConfigBuilder {
|
|
221
|
-
this.config.url = url
|
|
222
|
-
return this
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
apiKey(apiKey: string): ARCConfigBuilder {
|
|
226
|
-
this.config.apiKey = apiKey
|
|
227
|
-
return this
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
timeout(timeout: number): ARCConfigBuilder {
|
|
231
|
-
this.config.timeout = timeout
|
|
232
|
-
return this
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
retries(retries: number, delay?: number): ARCConfigBuilder {
|
|
236
|
-
this.config.retries = retries
|
|
237
|
-
if (delay !== undefined) {
|
|
238
|
-
this.config.retryDelay = delay
|
|
239
|
-
}
|
|
240
|
-
return this
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
authentication(auth: ARCAuthentication): ARCConfigBuilder {
|
|
244
|
-
this.config.authentication = auth
|
|
245
|
-
return this
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
endpoints(endpoints: Partial<ARCEndpoints>): ARCConfigBuilder {
|
|
249
|
-
this.config.endpoints = { ...this.config.endpoints, ...endpoints }
|
|
250
|
-
return this
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
limits(limits: Partial<ARCLimits>): ARCConfigBuilder {
|
|
254
|
-
this.config.limits = { ...this.config.limits, ...limits }
|
|
255
|
-
return this
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
monitoring(monitoring: Partial<ARCMonitoring>): ARCConfigBuilder {
|
|
259
|
-
this.config.monitoring = { ...this.config.monitoring, ...monitoring }
|
|
260
|
-
return this
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
headers(headers: Record<string, string>): ARCConfigBuilder {
|
|
264
|
-
this.config.headers = { ...this.config.headers, ...headers }
|
|
265
|
-
return this
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
build(): ARCConfig {
|
|
269
|
-
if (!this.config.url) {
|
|
270
|
-
throw new Error('ARC URL is required')
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
url: this.config.url,
|
|
275
|
-
timeout: this.config.timeout || 30000,
|
|
276
|
-
retries: this.config.retries || 3,
|
|
277
|
-
retryDelay: this.config.retryDelay || 1000,
|
|
278
|
-
...this.config
|
|
279
|
-
} as ARCConfig
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Usage Examples
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
// Basic ARC configuration
|
|
288
|
-
const basicARC = new ARCConfigBuilder()
|
|
289
|
-
.url('https://arc.example.com')
|
|
290
|
-
.apiKey('your-api-key')
|
|
291
|
-
.timeout(15000)
|
|
292
|
-
.build()
|
|
293
|
-
|
|
294
|
-
// Advanced ARC configuration with authentication
|
|
295
|
-
const advancedARC = new ARCConfigBuilder()
|
|
296
|
-
.url('https://arc.example.com')
|
|
297
|
-
.authentication({
|
|
298
|
-
type: 'bearer',
|
|
299
|
-
credentials: {
|
|
300
|
-
token: 'your-bearer-token'
|
|
301
|
-
},
|
|
302
|
-
autoRefresh: true
|
|
303
|
-
})
|
|
304
|
-
.endpoints({
|
|
305
|
-
submit: '/api/v2/transactions',
|
|
306
|
-
query: '/api/v2/transactions/{txid}',
|
|
307
|
-
status: '/api/v2/status/{txid}'
|
|
308
|
-
})
|
|
309
|
-
.limits({
|
|
310
|
-
maxTransactionSize: 5000000,
|
|
311
|
-
maxBatchSize: 50,
|
|
312
|
-
rateLimit: {
|
|
313
|
-
requests: 100,
|
|
314
|
-
window: 60000
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
.monitoring({
|
|
318
|
-
enabled: true,
|
|
319
|
-
healthCheck: {
|
|
320
|
-
interval: 30000,
|
|
321
|
-
timeout: 5000,
|
|
322
|
-
retries: 3
|
|
323
|
-
},
|
|
324
|
-
metrics: {
|
|
325
|
-
enabled: true,
|
|
326
|
-
interval: 60000
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
.build()
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
## ARC Client Configuration
|
|
333
|
-
|
|
334
|
-
### ARCClient Interface
|
|
335
|
-
|
|
336
|
-
```typescript
|
|
337
|
-
interface ARCClient {
|
|
338
|
-
config: ARCConfig
|
|
339
|
-
submit(transaction: Transaction): Promise<ARCResponse>
|
|
340
|
-
query(txid: string): Promise<ARCTransactionStatus>
|
|
341
|
-
getStatus(txid: string): Promise<ARCStatus>
|
|
342
|
-
getFees(): Promise<ARCFeeQuote>
|
|
343
|
-
getHealth(): Promise<ARCHealthStatus>
|
|
344
|
-
broadcast(rawTx: string): Promise<ARCBroadcastResponse>
|
|
345
|
-
}
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
### ARCResponse Types
|
|
349
|
-
|
|
350
|
-
```typescript
|
|
351
|
-
interface ARCResponse {
|
|
352
|
-
txid: string
|
|
353
|
-
status: 'success' | 'error' | 'pending'
|
|
354
|
-
message?: string
|
|
355
|
-
timestamp: number
|
|
356
|
-
blockHash?: string
|
|
357
|
-
blockHeight?: number
|
|
358
|
-
merklePath?: string
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
interface ARCTransactionStatus {
|
|
362
|
-
txid: string
|
|
363
|
-
status: 'seen' | 'mined' | 'confirmed' | 'rejected'
|
|
364
|
-
blockHash?: string
|
|
365
|
-
blockHeight?: number
|
|
366
|
-
timestamp: number
|
|
367
|
-
confirmations?: number
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
interface ARCFeeQuote {
|
|
371
|
-
standard: number
|
|
372
|
-
data: number
|
|
373
|
-
timestamp: number
|
|
374
|
-
expiresAt: number
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
interface ARCHealthStatus {
|
|
378
|
-
status: 'healthy' | 'degraded' | 'unhealthy'
|
|
379
|
-
version: string
|
|
380
|
-
timestamp: number
|
|
381
|
-
checks: {
|
|
382
|
-
database: boolean
|
|
383
|
-
network: boolean
|
|
384
|
-
mempool: boolean
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
## Multi-ARC Configuration
|
|
390
|
-
|
|
391
|
-
### ARC Pool Configuration
|
|
392
|
-
|
|
393
|
-
```typescript
|
|
394
|
-
interface ARCPoolConfig {
|
|
395
|
-
primary: ARCConfig
|
|
396
|
-
fallbacks: ARCConfig[]
|
|
397
|
-
strategy: 'failover' | 'round-robin' | 'load-balance'
|
|
398
|
-
healthCheck: {
|
|
399
|
-
enabled: boolean
|
|
400
|
-
interval: number
|
|
401
|
-
timeout: number
|
|
402
|
-
}
|
|
403
|
-
failover: {
|
|
404
|
-
maxRetries: number
|
|
405
|
-
retryDelay: number
|
|
406
|
-
backoffMultiplier: number
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
class ARCPool {
|
|
411
|
-
private configs: ARCConfig[]
|
|
412
|
-
private currentIndex = 0
|
|
413
|
-
private healthStatus = new Map<string, boolean>()
|
|
414
|
-
|
|
415
|
-
constructor(private poolConfig: ARCPoolConfig) {
|
|
416
|
-
this.configs = [poolConfig.primary, ...poolConfig.fallbacks]
|
|
417
|
-
this.startHealthChecks()
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async submit(transaction: Transaction): Promise<ARCResponse> {
|
|
421
|
-
const config = this.selectARC()
|
|
422
|
-
const client = new ARCClient(config)
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
return await client.submit(transaction)
|
|
426
|
-
} catch (error) {
|
|
427
|
-
this.markUnhealthy(config.url)
|
|
428
|
-
|
|
429
|
-
if (this.hasHealthyFallbacks()) {
|
|
430
|
-
return this.submit(transaction) // Retry with fallback
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
throw error
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
private selectARC(): ARCConfig {
|
|
438
|
-
switch (this.poolConfig.strategy) {
|
|
439
|
-
case 'failover':
|
|
440
|
-
return this.selectFailover()
|
|
441
|
-
case 'round-robin':
|
|
442
|
-
return this.selectRoundRobin()
|
|
443
|
-
case 'load-balance':
|
|
444
|
-
return this.selectLoadBalanced()
|
|
445
|
-
default:
|
|
446
|
-
return this.configs[0]
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
private selectFailover(): ARCConfig {
|
|
451
|
-
for (const config of this.configs) {
|
|
452
|
-
if (this.healthStatus.get(config.url) !== false) {
|
|
453
|
-
return config
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return this.configs[0] // Fallback to primary
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
private selectRoundRobin(): ARCConfig {
|
|
460
|
-
const healthyConfigs = this.configs.filter(
|
|
461
|
-
config => this.healthStatus.get(config.url) !== false
|
|
462
|
-
)
|
|
463
|
-
|
|
464
|
-
if (healthyConfigs.length === 0) {
|
|
465
|
-
return this.configs[0]
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const config = healthyConfigs[this.currentIndex % healthyConfigs.length]
|
|
469
|
-
this.currentIndex++
|
|
470
|
-
return config
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
private selectLoadBalanced(): ARCConfig {
|
|
474
|
-
// Simple load balancing based on response times
|
|
475
|
-
const healthyConfigs = this.configs.filter(
|
|
476
|
-
config => this.healthStatus.get(config.url) !== false
|
|
477
|
-
)
|
|
478
|
-
|
|
479
|
-
if (healthyConfigs.length === 0) {
|
|
480
|
-
return this.configs[0]
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// Return random healthy config (can be enhanced with actual load metrics)
|
|
484
|
-
return healthyConfigs[Math.floor(Math.random() * healthyConfigs.length)]
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
private startHealthChecks(): void {
|
|
488
|
-
if (!this.poolConfig.healthCheck.enabled) return
|
|
489
|
-
|
|
490
|
-
setInterval(async () => {
|
|
491
|
-
for (const config of this.configs) {
|
|
492
|
-
try {
|
|
493
|
-
const client = new ARCClient(config)
|
|
494
|
-
await client.getHealth()
|
|
495
|
-
this.healthStatus.set(config.url, true)
|
|
496
|
-
} catch (error) {
|
|
497
|
-
this.healthStatus.set(config.url, false)
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}, this.poolConfig.healthCheck.interval)
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
private markUnhealthy(url: string): void {
|
|
504
|
-
this.healthStatus.set(url, false)
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
private hasHealthyFallbacks(): boolean {
|
|
508
|
-
return this.configs.some(config =>
|
|
509
|
-
this.healthStatus.get(config.url) !== false
|
|
510
|
-
)
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
## Environment-Based ARC Configuration
|
|
516
|
-
|
|
517
|
-
### Environment Configuration
|
|
518
|
-
|
|
519
|
-
```typescript
|
|
520
|
-
class ARCEnvironmentConfig {
|
|
521
|
-
static fromEnvironment(): ARCConfig {
|
|
522
|
-
const config: ARCConfig = {
|
|
523
|
-
url: process.env.BSV_ARC_URL || 'https://arc.taal.com',
|
|
524
|
-
apiKey: process.env.BSV_ARC_API_KEY,
|
|
525
|
-
timeout: parseInt(process.env.BSV_ARC_TIMEOUT || '30000'),
|
|
526
|
-
retries: parseInt(process.env.BSV_ARC_RETRIES || '3'),
|
|
527
|
-
retryDelay: parseInt(process.env.BSV_ARC_RETRY_DELAY || '1000')
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Add authentication if provided
|
|
531
|
-
if (process.env.BSV_ARC_AUTH_TYPE) {
|
|
532
|
-
config.authentication = {
|
|
533
|
-
type: process.env.BSV_ARC_AUTH_TYPE as any,
|
|
534
|
-
credentials: {
|
|
535
|
-
apiKey: process.env.BSV_ARC_API_KEY,
|
|
536
|
-
token: process.env.BSV_ARC_TOKEN,
|
|
537
|
-
username: process.env.BSV_ARC_USERNAME,
|
|
538
|
-
password: process.env.BSV_ARC_PASSWORD
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// Add custom headers
|
|
544
|
-
const headerPrefix = 'BSV_ARC_HEADER_'
|
|
545
|
-
const headers: Record<string, string> = {}
|
|
546
|
-
|
|
547
|
-
Object.keys(process.env).forEach(key => {
|
|
548
|
-
if (key.startsWith(headerPrefix)) {
|
|
549
|
-
const headerName = key.substring(headerPrefix.length).toLowerCase()
|
|
550
|
-
headers[headerName] = process.env[key]!
|
|
551
|
-
}
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
if (Object.keys(headers).length > 0) {
|
|
555
|
-
config.headers = headers
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return config
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
static validate(config: ARCConfig): void {
|
|
562
|
-
if (!config.url) {
|
|
563
|
-
throw new Error('ARC URL is required')
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (!config.url.startsWith('http')) {
|
|
567
|
-
throw new Error('ARC URL must be a valid HTTP/HTTPS URL')
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (config.timeout && config.timeout < 1000) {
|
|
571
|
-
throw new Error('ARC timeout must be at least 1000ms')
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
if (config.retries && config.retries < 0) {
|
|
575
|
-
throw new Error('ARC retries must be non-negative')
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if (config.authentication?.type === 'apiKey' && !config.authentication.credentials.apiKey) {
|
|
579
|
-
throw new Error('API key is required for apiKey authentication')
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (config.authentication?.type === 'bearer' && !config.authentication.credentials.token) {
|
|
583
|
-
throw new Error('Bearer token is required for bearer authentication')
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
## ARC Configuration Best Practices
|
|
590
|
-
|
|
591
|
-
### Security Best Practices
|
|
592
|
-
|
|
593
|
-
```typescript
|
|
594
|
-
// 1. Never hardcode API keys
|
|
595
|
-
const secureConfig = new ARCConfigBuilder()
|
|
596
|
-
.url(process.env.ARC_URL!)
|
|
597
|
-
.apiKey(process.env.ARC_API_KEY!) // Use environment variables
|
|
598
|
-
.build()
|
|
599
|
-
|
|
600
|
-
// 2. Use HTTPS URLs only
|
|
601
|
-
const httpsConfig = new ARCConfigBuilder()
|
|
602
|
-
.url('https://arc.example.com') // Always use HTTPS
|
|
603
|
-
.build()
|
|
604
|
-
|
|
605
|
-
// 3. Implement proper authentication rotation
|
|
606
|
-
const rotatingAuthConfig = new ARCConfigBuilder()
|
|
607
|
-
.url('https://arc.example.com')
|
|
608
|
-
.authentication({
|
|
609
|
-
type: 'bearer',
|
|
610
|
-
credentials: { token: getCurrentToken() },
|
|
611
|
-
autoRefresh: true,
|
|
612
|
-
expiresAt: getTokenExpiry()
|
|
613
|
-
})
|
|
614
|
-
.build()
|
|
615
|
-
```
|
|
616
|
-
|
|
617
|
-
### Performance Best Practices
|
|
618
|
-
|
|
619
|
-
```typescript
|
|
620
|
-
// 1. Configure appropriate timeouts
|
|
621
|
-
const performantConfig = new ARCConfigBuilder()
|
|
622
|
-
.url('https://arc.example.com')
|
|
623
|
-
.timeout(15000) // 15 seconds for most operations
|
|
624
|
-
.retries(3)
|
|
625
|
-
.build()
|
|
626
|
-
|
|
627
|
-
// 2. Use connection pooling for high-throughput applications
|
|
628
|
-
const pooledConfig: ARCPoolConfig = {
|
|
629
|
-
primary: MAINNET_ARC_CONFIGS.taal,
|
|
630
|
-
fallbacks: [MAINNET_ARC_CONFIGS.gorillapool],
|
|
631
|
-
strategy: 'load-balance',
|
|
632
|
-
healthCheck: {
|
|
633
|
-
enabled: true,
|
|
634
|
-
interval: 30000,
|
|
635
|
-
timeout: 5000
|
|
636
|
-
},
|
|
637
|
-
failover: {
|
|
638
|
-
maxRetries: 3,
|
|
639
|
-
retryDelay: 1000,
|
|
640
|
-
backoffMultiplier: 2
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// 3. Monitor and optimize rate limits
|
|
645
|
-
const rateLimitedConfig = new ARCConfigBuilder()
|
|
646
|
-
.url('https://arc.example.com')
|
|
647
|
-
.limits({
|
|
648
|
-
rateLimit: {
|
|
649
|
-
requests: 100,
|
|
650
|
-
window: 60000 // 100 requests per minute
|
|
651
|
-
},
|
|
652
|
-
maxConcurrentRequests: 5
|
|
653
|
-
})
|
|
654
|
-
.build()
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
### Reliability Best Practices
|
|
658
|
-
|
|
659
|
-
```typescript
|
|
660
|
-
// 1. Always configure fallbacks
|
|
661
|
-
const reliableConfig: ARCPoolConfig = {
|
|
662
|
-
primary: MAINNET_ARC_CONFIGS.taal,
|
|
663
|
-
fallbacks: [
|
|
664
|
-
MAINNET_ARC_CONFIGS.gorillapool,
|
|
665
|
-
// Add more fallbacks as needed
|
|
666
|
-
],
|
|
667
|
-
strategy: 'failover',
|
|
668
|
-
healthCheck: { enabled: true, interval: 30000, timeout: 5000 },
|
|
669
|
-
failover: { maxRetries: 3, retryDelay: 1000, backoffMultiplier: 2 }
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// 2. Enable comprehensive monitoring
|
|
673
|
-
const monitoredConfig = new ARCConfigBuilder()
|
|
674
|
-
.url('https://arc.example.com')
|
|
675
|
-
.monitoring({
|
|
676
|
-
enabled: true,
|
|
677
|
-
healthCheck: {
|
|
678
|
-
interval: 30000,
|
|
679
|
-
timeout: 5000,
|
|
680
|
-
retries: 3
|
|
681
|
-
},
|
|
682
|
-
metrics: {
|
|
683
|
-
enabled: true,
|
|
684
|
-
interval: 60000
|
|
685
|
-
},
|
|
686
|
-
alerts: {
|
|
687
|
-
enabled: true,
|
|
688
|
-
thresholds: {
|
|
689
|
-
errorRate: 0.05, // 5% error rate
|
|
690
|
-
responseTime: 10000, // 10 seconds
|
|
691
|
-
availability: 0.99 // 99% availability
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
})
|
|
695
|
-
.build()
|
|
696
|
-
```
|
|
697
|
-
|
|
698
|
-
This comprehensive ARC configuration reference provides developers with all the tools and patterns needed to effectively configure and manage ARC connections in their BSV TypeScript SDK applications.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# BRC-100 Wallet Interface
|
|
2
|
-
|
|
3
|
-
[BRC-100](https://brc.dev/100) defines a Unified, Vendor-Neutral, Unchanging, and Open BSV Blockchain Standard Wallet-to-Application Interface which is implemented in this library within the WalletClient class. The API is laid out here as a swagger openapi document to offer a fast-track to understanding the interface which is implemented across multiple substrates. The JSON api is generally considered a developer friendly introduction to the WalletClient, where an binary equivalent ABI may be preferred for production use cases.
|
|
4
|
-
|
|
5
|
-
## Wallet JSON API
|
|
6
|
-
|
|
7
|
-
- [Wallet JSON API Swagger](../swagger)
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
The BRC-100 standard provides a consistent interface for applications to interact with BSV wallets, regardless of the underlying wallet implementation. This ensures that applications can work with any BRC-100 compliant wallet without modification.
|
|
12
|
-
|
|
13
|
-
## Key Features
|
|
14
|
-
|
|
15
|
-
- **Vendor Neutral**: Works with any BRC-100 compliant wallet
|
|
16
|
-
- **Standardized Interface**: Consistent API across all implementations
|
|
17
|
-
- **Multiple Substrates**: Supports various communication methods
|
|
18
|
-
- **Future Proof**: Unchanging standard ensures long-term compatibility
|
|
19
|
-
|
|
20
|
-
## Implementation
|
|
21
|
-
|
|
22
|
-
The BSV TypeScript SDK implements BRC-100 through the `WalletClient` class, which provides:
|
|
23
|
-
|
|
24
|
-
- Transaction creation and signing
|
|
25
|
-
- UTXO management
|
|
26
|
-
- Authentication and authorization
|
|
27
|
-
- Substrate-agnostic communication
|
|
28
|
-
|
|
29
|
-
## Related Documentation
|
|
30
|
-
|
|
31
|
-
- [WalletClient Reference](./wallet.md)
|
|
32
|
-
- [Authentication Reference](./auth.md)
|
|
33
|
-
- [Transaction Reference](./transaction.md)
|