@bsv/sdk 1.0.34 → 1.0.36
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/mod.js +1 -0
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +1 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +2 -2
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/primitives.md +61 -59
- package/docs/script.md +13 -11
- package/docs/transaction.md +489 -35
- package/mod.ts +1 -0
- package/package.json +1 -1
- package/src/transaction/Transaction.ts +2 -2
package/docs/transaction.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# API
|
|
2
2
|
|
|
3
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
3
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
4
4
|
|
|
5
5
|
## Interfaces
|
|
6
6
|
|
|
7
|
-
| |
|
|
8
|
-
| --- |
|
|
9
|
-
| [
|
|
10
|
-
| [
|
|
11
|
-
| [
|
|
12
|
-
| [
|
|
13
|
-
| [
|
|
14
|
-
| [
|
|
15
|
-
| [
|
|
7
|
+
| | |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [ArcConfig](#interface-arcconfig) | [HttpClient](#interface-httpclient) |
|
|
10
|
+
| [BroadcastFailure](#interface-broadcastfailure) | [HttpClientRequestOptions](#interface-httpclientrequestoptions) |
|
|
11
|
+
| [BroadcastResponse](#interface-broadcastresponse) | [HttpsNodejs](#interface-httpsnodejs) |
|
|
12
|
+
| [Broadcaster](#interface-broadcaster) | [NodejsHttpClientRequest](#interface-nodejshttpclientrequest) |
|
|
13
|
+
| [ChainTracker](#interface-chaintracker) | [TransactionInput](#interface-transactioninput) |
|
|
14
|
+
| [FeeModel](#interface-feemodel) | [TransactionOutput](#interface-transactionoutput) |
|
|
15
|
+
| [Fetch](#interface-fetch) | [WhatsOnChainConfig](#interface-whatsonchainconfig) |
|
|
16
|
+
| [FetchOptions](#interface-fetchoptions) | |
|
|
16
17
|
|
|
17
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
18
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
18
19
|
|
|
19
20
|
---
|
|
20
21
|
|
|
@@ -55,7 +56,7 @@ export default interface TransactionInput {
|
|
|
55
56
|
}
|
|
56
57
|
```
|
|
57
58
|
|
|
58
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
59
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
59
60
|
|
|
60
61
|
---
|
|
61
62
|
### Interface: TransactionOutput
|
|
@@ -83,7 +84,7 @@ export default interface TransactionOutput {
|
|
|
83
84
|
}
|
|
84
85
|
```
|
|
85
86
|
|
|
86
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
87
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
87
88
|
|
|
88
89
|
---
|
|
89
90
|
### Interface: FeeModel
|
|
@@ -97,7 +98,7 @@ export default interface FeeModel {
|
|
|
97
98
|
}
|
|
98
99
|
```
|
|
99
100
|
|
|
100
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
101
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
101
102
|
|
|
102
103
|
---
|
|
103
104
|
### Interface: BroadcastResponse
|
|
@@ -112,7 +113,7 @@ export interface BroadcastResponse {
|
|
|
112
113
|
}
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
116
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
116
117
|
|
|
117
118
|
---
|
|
118
119
|
### Interface: BroadcastFailure
|
|
@@ -127,7 +128,7 @@ export interface BroadcastFailure {
|
|
|
127
128
|
}
|
|
128
129
|
```
|
|
129
130
|
|
|
130
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
131
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
131
132
|
|
|
132
133
|
---
|
|
133
134
|
### Interface: Broadcaster
|
|
@@ -141,7 +142,7 @@ export interface Broadcaster {
|
|
|
141
142
|
}
|
|
142
143
|
```
|
|
143
144
|
|
|
144
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
145
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
145
146
|
|
|
146
147
|
---
|
|
147
148
|
### Interface: ChainTracker
|
|
@@ -169,18 +170,270 @@ export default interface ChainTracker {
|
|
|
169
170
|
}
|
|
170
171
|
```
|
|
171
172
|
|
|
172
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
173
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
### Interface: HttpClient
|
|
177
|
+
|
|
178
|
+
An interface for HTTP client used to make HTTP requests.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
export interface HttpClient {
|
|
182
|
+
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>): Promise<HttpClientResponse<T>>;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
<details>
|
|
187
|
+
|
|
188
|
+
<summary>Interface HttpClient Details</summary>
|
|
189
|
+
|
|
190
|
+
#### Method request
|
|
191
|
+
|
|
192
|
+
Makes a request to the server.
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>): Promise<HttpClientResponse<T>>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Argument Details
|
|
199
|
+
|
|
200
|
+
+ **url**
|
|
201
|
+
+ The URL to make the request to.
|
|
202
|
+
+ **options**
|
|
203
|
+
+ The request configuration.
|
|
204
|
+
|
|
205
|
+
</details>
|
|
206
|
+
|
|
207
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
### Interface: HttpClientRequestOptions
|
|
211
|
+
|
|
212
|
+
An interface for configuration of the request to be passed to the request method.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
export interface HttpClientRequestOptions<Data = any> {
|
|
216
|
+
method?: string;
|
|
217
|
+
headers?: Record<string, string>;
|
|
218
|
+
data?: Data;
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
<details>
|
|
223
|
+
|
|
224
|
+
<summary>Interface HttpClientRequestOptions Details</summary>
|
|
225
|
+
|
|
226
|
+
#### Property data
|
|
227
|
+
|
|
228
|
+
An object or null to set request's body.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
data?: Data
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Property headers
|
|
235
|
+
|
|
236
|
+
An object literal set request's headers.
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
headers?: Record<string, string>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### Property method
|
|
243
|
+
|
|
244
|
+
A string to set request's method.
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
method?: string
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
</details>
|
|
251
|
+
|
|
252
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
### Interface: HttpsNodejs
|
|
256
|
+
|
|
257
|
+
Node.js Https module interface limited to options needed by ts-sdk
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
export interface HttpsNodejs {
|
|
261
|
+
request(url: string, options: HttpClientRequestOptions, callback: (res: any) => void): NodejsHttpClientRequest;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
### Interface: NodejsHttpClientRequest
|
|
269
|
+
|
|
270
|
+
Nodejs result of the Node.js https.request call limited to options needed by ts-sdk
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
export interface NodejsHttpClientRequest {
|
|
274
|
+
write(chunk: string): void;
|
|
275
|
+
end(): void;
|
|
276
|
+
on(event: string, callback: (data: any) => void): void;
|
|
277
|
+
end(): void;
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
### Interface: Fetch
|
|
285
|
+
|
|
286
|
+
fetch function interface limited to options needed by ts-sdk
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
export interface Fetch {
|
|
290
|
+
(url: string, options: FetchOptions): Promise<Response>;
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
### Interface: FetchOptions
|
|
298
|
+
|
|
299
|
+
An interface for configuration of the request to be passed to the fetch method
|
|
300
|
+
limited to options needed by ts-sdk.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
export interface FetchOptions {
|
|
304
|
+
method?: string;
|
|
305
|
+
headers?: Record<string, string>;
|
|
306
|
+
body?: string | null;
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
<details>
|
|
311
|
+
|
|
312
|
+
<summary>Interface FetchOptions Details</summary>
|
|
313
|
+
|
|
314
|
+
#### Property body
|
|
315
|
+
|
|
316
|
+
An object or null to set request's body.
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
body?: string | null
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Property headers
|
|
323
|
+
|
|
324
|
+
An object literal set request's headers.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
headers?: Record<string, string>
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Property method
|
|
331
|
+
|
|
332
|
+
A string to set request's method.
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
method?: string
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
</details>
|
|
339
|
+
|
|
340
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
### Interface: ArcConfig
|
|
344
|
+
|
|
345
|
+
Configuration options for the ARC broadcaster.
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
export interface ArcConfig {
|
|
349
|
+
apiKey?: string;
|
|
350
|
+
deploymentId?: string;
|
|
351
|
+
httpClient?: HttpClient;
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
<details>
|
|
356
|
+
|
|
357
|
+
<summary>Interface ArcConfig Details</summary>
|
|
358
|
+
|
|
359
|
+
#### Property apiKey
|
|
360
|
+
|
|
361
|
+
Authentication token for the ARC API
|
|
362
|
+
|
|
363
|
+
```ts
|
|
364
|
+
apiKey?: string
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
#### Property deploymentId
|
|
368
|
+
|
|
369
|
+
Deployment id used annotating api calls in XDeployment-ID header - this value will be randomly generated if not set
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
deploymentId?: string
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### Property httpClient
|
|
376
|
+
|
|
377
|
+
The HTTP client used to make requests to the ARC API.
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
httpClient?: HttpClient
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
</details>
|
|
384
|
+
|
|
385
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
### Interface: WhatsOnChainConfig
|
|
389
|
+
|
|
390
|
+
Configuration options for the WhatsOnChain ChainTracker.
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
export interface WhatsOnChainConfig {
|
|
394
|
+
apiKey?: string;
|
|
395
|
+
httpClient?: HttpClient;
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
<details>
|
|
400
|
+
|
|
401
|
+
<summary>Interface WhatsOnChainConfig Details</summary>
|
|
402
|
+
|
|
403
|
+
#### Property apiKey
|
|
404
|
+
|
|
405
|
+
Authentication token for the WhatsOnChain API
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
apiKey?: string
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
#### Property httpClient
|
|
412
|
+
|
|
413
|
+
The HTTP client used to make requests to the API.
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
httpClient?: HttpClient
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
</details>
|
|
420
|
+
|
|
421
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
173
422
|
|
|
174
423
|
---
|
|
175
424
|
## Classes
|
|
176
425
|
|
|
177
426
|
| |
|
|
178
427
|
| --- |
|
|
428
|
+
| [ARC](#class-arc) |
|
|
429
|
+
| [FetchHttpClient](#class-fetchhttpclient) |
|
|
179
430
|
| [MerklePath](#class-merklepath) |
|
|
431
|
+
| [NodejsHttpClient](#class-nodejshttpclient) |
|
|
180
432
|
| [SatoshisPerKilobyte](#class-satoshisperkilobyte) |
|
|
181
433
|
| [Transaction](#class-transaction) |
|
|
434
|
+
| [WhatsOnChain](#class-whatsonchain) |
|
|
182
435
|
|
|
183
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
436
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
184
437
|
|
|
185
438
|
---
|
|
186
439
|
|
|
@@ -232,7 +485,7 @@ Argument Details
|
|
|
232
485
|
|
|
233
486
|
</details>
|
|
234
487
|
|
|
235
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
488
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
236
489
|
|
|
237
490
|
---
|
|
238
491
|
### Class: MerklePath
|
|
@@ -396,7 +649,144 @@ Argument Details
|
|
|
396
649
|
|
|
397
650
|
</details>
|
|
398
651
|
|
|
399
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
652
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
653
|
+
|
|
654
|
+
---
|
|
655
|
+
### Class: NodejsHttpClient
|
|
656
|
+
|
|
657
|
+
Adapter for Node.js Https module to be used as HttpClient
|
|
658
|
+
|
|
659
|
+
```ts
|
|
660
|
+
export class NodejsHttpClient implements HttpClient {
|
|
661
|
+
constructor(private https: HttpsNodejs)
|
|
662
|
+
async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
|
|
663
|
+
}
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
667
|
+
|
|
668
|
+
---
|
|
669
|
+
### Class: FetchHttpClient
|
|
670
|
+
|
|
671
|
+
Adapter for Node.js Https module to be used as HttpClient
|
|
672
|
+
|
|
673
|
+
```ts
|
|
674
|
+
export class FetchHttpClient implements HttpClient {
|
|
675
|
+
constructor(private fetch: Fetch)
|
|
676
|
+
async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
681
|
+
|
|
682
|
+
---
|
|
683
|
+
### Class: ARC
|
|
684
|
+
|
|
685
|
+
Represents an ARC transaction broadcaster.
|
|
686
|
+
|
|
687
|
+
```ts
|
|
688
|
+
export default class ARC implements Broadcaster {
|
|
689
|
+
readonly URL: string;
|
|
690
|
+
readonly apiKey: string | undefined;
|
|
691
|
+
readonly deploymentId: string;
|
|
692
|
+
constructor(URL: string, config?: ArcConfig);
|
|
693
|
+
constructor(URL: string, apiKey?: string);
|
|
694
|
+
constructor(URL: string, config?: string | ArcConfig)
|
|
695
|
+
async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
|
|
696
|
+
}
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
<details>
|
|
700
|
+
|
|
701
|
+
<summary>Class ARC Details</summary>
|
|
702
|
+
|
|
703
|
+
#### Constructor
|
|
704
|
+
|
|
705
|
+
Constructs an instance of the ARC broadcaster.
|
|
706
|
+
|
|
707
|
+
```ts
|
|
708
|
+
constructor(URL: string, config?: ArcConfig)
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Argument Details
|
|
712
|
+
|
|
713
|
+
+ **URL**
|
|
714
|
+
+ The URL endpoint for the ARC API.
|
|
715
|
+
+ **config**
|
|
716
|
+
+ Configuration options for the ARC broadcaster.
|
|
717
|
+
|
|
718
|
+
#### Constructor
|
|
719
|
+
|
|
720
|
+
Constructs an instance of the ARC broadcaster.
|
|
721
|
+
|
|
722
|
+
```ts
|
|
723
|
+
constructor(URL: string, apiKey?: string)
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Argument Details
|
|
727
|
+
|
|
728
|
+
+ **URL**
|
|
729
|
+
+ The URL endpoint for the ARC API.
|
|
730
|
+
+ **apiKey**
|
|
731
|
+
+ The API key used for authorization with the ARC API.
|
|
732
|
+
|
|
733
|
+
#### Method broadcast
|
|
734
|
+
|
|
735
|
+
Broadcasts a transaction via ARC.
|
|
736
|
+
|
|
737
|
+
```ts
|
|
738
|
+
async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
Returns
|
|
742
|
+
|
|
743
|
+
A promise that resolves to either a success or failure response.
|
|
744
|
+
|
|
745
|
+
Argument Details
|
|
746
|
+
|
|
747
|
+
+ **tx**
|
|
748
|
+
+ The transaction to be broadcasted.
|
|
749
|
+
|
|
750
|
+
</details>
|
|
751
|
+
|
|
752
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
753
|
+
|
|
754
|
+
---
|
|
755
|
+
### Class: WhatsOnChain
|
|
756
|
+
|
|
757
|
+
Represents a chain tracker based on What's On Chain .
|
|
758
|
+
|
|
759
|
+
```ts
|
|
760
|
+
export default class WhatsOnChain implements ChainTracker {
|
|
761
|
+
readonly network: string;
|
|
762
|
+
readonly apiKey: string;
|
|
763
|
+
constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
|
|
764
|
+
async isValidRootForHeight(root: string, height: number): Promise<boolean>
|
|
765
|
+
}
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
<details>
|
|
769
|
+
|
|
770
|
+
<summary>Class WhatsOnChain Details</summary>
|
|
771
|
+
|
|
772
|
+
#### Constructor
|
|
773
|
+
|
|
774
|
+
Constructs an instance of the WhatsOnChain ChainTracker.
|
|
775
|
+
|
|
776
|
+
```ts
|
|
777
|
+
constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
Argument Details
|
|
781
|
+
|
|
782
|
+
+ **network**
|
|
783
|
+
+ The BSV network to use when calling the WhatsOnChain API.
|
|
784
|
+
+ **config**
|
|
785
|
+
+ Configuration options for the WhatsOnChain ChainTracker.
|
|
786
|
+
|
|
787
|
+
</details>
|
|
788
|
+
|
|
789
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
400
790
|
|
|
401
791
|
---
|
|
402
792
|
### Class: Transaction
|
|
@@ -427,16 +817,16 @@ export default class Transaction {
|
|
|
427
817
|
merklePath?: MerklePath;
|
|
428
818
|
static fromBEEF(beef: number[]): Transaction
|
|
429
819
|
static parseScriptOffsets(bin: number[]): {
|
|
430
|
-
inputs: {
|
|
820
|
+
inputs: Array<{
|
|
431
821
|
vin: number;
|
|
432
822
|
offset: number;
|
|
433
823
|
length: number;
|
|
434
|
-
}
|
|
435
|
-
outputs: {
|
|
824
|
+
}>;
|
|
825
|
+
outputs: Array<{
|
|
436
826
|
vout: number;
|
|
437
827
|
offset: number;
|
|
438
828
|
length: number;
|
|
439
|
-
}
|
|
829
|
+
}>;
|
|
440
830
|
}
|
|
441
831
|
static fromBinary(bin: number[]): Transaction
|
|
442
832
|
static fromHex(hex: string): Transaction
|
|
@@ -447,7 +837,7 @@ export default class Transaction {
|
|
|
447
837
|
updateMetadata(metadata: Record<string, any>): void
|
|
448
838
|
async fee(model?: FeeModel, changeDistribution: "equal" | "random" = "equal"): Promise<void>
|
|
449
839
|
async sign(): Promise<void>
|
|
450
|
-
async broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure>
|
|
840
|
+
async broadcast(broadcaster: Broadcaster = defaultBroadcaster()): Promise<BroadcastResponse | BroadcastFailure>
|
|
451
841
|
toBinary(): number[]
|
|
452
842
|
toEF(): number[]
|
|
453
843
|
toHexEF(): string
|
|
@@ -457,7 +847,7 @@ export default class Transaction {
|
|
|
457
847
|
id(): number[];
|
|
458
848
|
id(enc: "hex"): string;
|
|
459
849
|
id(enc?: "hex"): number[] | string
|
|
460
|
-
async verify(chainTracker: ChainTracker | "scripts only"): Promise<boolean>
|
|
850
|
+
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker()): Promise<boolean>
|
|
461
851
|
toBEEF(): number[]
|
|
462
852
|
}
|
|
463
853
|
```
|
|
@@ -501,7 +891,7 @@ Argument Details
|
|
|
501
891
|
Broadcasts a transaction.
|
|
502
892
|
|
|
503
893
|
```ts
|
|
504
|
-
async broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure>
|
|
894
|
+
async broadcast(broadcaster: Broadcaster = defaultBroadcaster()): Promise<BroadcastResponse | BroadcastFailure>
|
|
505
895
|
```
|
|
506
896
|
|
|
507
897
|
Returns
|
|
@@ -675,16 +1065,16 @@ This supports the efficient retreival of script data from transaction data.
|
|
|
675
1065
|
|
|
676
1066
|
```ts
|
|
677
1067
|
static parseScriptOffsets(bin: number[]): {
|
|
678
|
-
inputs: {
|
|
1068
|
+
inputs: Array<{
|
|
679
1069
|
vin: number;
|
|
680
1070
|
offset: number;
|
|
681
1071
|
length: number;
|
|
682
|
-
}
|
|
683
|
-
outputs: {
|
|
1072
|
+
}>;
|
|
1073
|
+
outputs: Array<{
|
|
684
1074
|
vout: number;
|
|
685
1075
|
offset: number;
|
|
686
1076
|
length: number;
|
|
687
|
-
}
|
|
1077
|
+
}>;
|
|
688
1078
|
}
|
|
689
1079
|
```
|
|
690
1080
|
|
|
@@ -797,7 +1187,7 @@ Argument Details
|
|
|
797
1187
|
Verifies the legitimacy of the Bitcoin transaction according to the rules of SPV by ensuring all the input transactions link back to valid block headers, the chain of spends for all inputs are valid, and the sum of inputs is not less than the sum of outputs.
|
|
798
1188
|
|
|
799
1189
|
```ts
|
|
800
|
-
async verify(chainTracker: ChainTracker | "scripts only"): Promise<boolean>
|
|
1190
|
+
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker()): Promise<boolean>
|
|
801
1191
|
```
|
|
802
1192
|
|
|
803
1193
|
Returns
|
|
@@ -807,14 +1197,78 @@ Whether the transaction is valid according to the rules of SPV.
|
|
|
807
1197
|
Argument Details
|
|
808
1198
|
|
|
809
1199
|
+ **chainTracker**
|
|
810
|
-
+ An instance of ChainTracker, a Bitcoin block header tracker. If the value is set to 'scripts only', headers will not be verified.
|
|
1200
|
+
+ An instance of ChainTracker, a Bitcoin block header tracker. If the value is set to 'scripts only', headers will not be verified. If not provided then the default chain tracker will be used.
|
|
811
1201
|
|
|
812
1202
|
</details>
|
|
813
1203
|
|
|
814
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
1204
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
815
1205
|
|
|
816
1206
|
---
|
|
817
1207
|
## Functions
|
|
818
1208
|
|
|
1209
|
+
| |
|
|
1210
|
+
| --- |
|
|
1211
|
+
| [defaultBroadcaster](#function-defaultbroadcaster) |
|
|
1212
|
+
| [defaultChainTracker](#function-defaultchaintracker) |
|
|
1213
|
+
| [defaultHttpClient](#function-defaulthttpclient) |
|
|
1214
|
+
|
|
1215
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1216
|
+
|
|
1217
|
+
---
|
|
1218
|
+
|
|
1219
|
+
### Function: defaultHttpClient
|
|
1220
|
+
|
|
1221
|
+
Returns a default HttpClient implementation based on the environment that it is run on.
|
|
1222
|
+
This method will attempt to use `window.fetch` if available (in browser environments).
|
|
1223
|
+
If running in a Node.js environment, it falls back to using the Node.js `https` module
|
|
1224
|
+
|
|
1225
|
+
```ts
|
|
1226
|
+
export function defaultHttpClient(): HttpClient
|
|
1227
|
+
```
|
|
1228
|
+
|
|
1229
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1230
|
+
|
|
1231
|
+
---
|
|
1232
|
+
### Function: defaultBroadcaster
|
|
1233
|
+
|
|
1234
|
+
```ts
|
|
1235
|
+
export function defaultBroadcaster(): Broadcaster
|
|
1236
|
+
```
|
|
1237
|
+
|
|
1238
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1239
|
+
|
|
1240
|
+
---
|
|
1241
|
+
### Function: defaultChainTracker
|
|
1242
|
+
|
|
1243
|
+
```ts
|
|
1244
|
+
export function defaultChainTracker(): ChainTracker
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1247
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1248
|
+
|
|
1249
|
+
---
|
|
1250
|
+
## Types
|
|
1251
|
+
|
|
1252
|
+
### Type: HttpClientResponse
|
|
1253
|
+
|
|
1254
|
+
An interface for the response returned by the request method.
|
|
1255
|
+
|
|
1256
|
+
```ts
|
|
1257
|
+
export type HttpClientResponse<T = any> = {
|
|
1258
|
+
data: T;
|
|
1259
|
+
status: number;
|
|
1260
|
+
statusText: string;
|
|
1261
|
+
ok: true;
|
|
1262
|
+
} | {
|
|
1263
|
+
data: any;
|
|
1264
|
+
status: number;
|
|
1265
|
+
statusText: string;
|
|
1266
|
+
ok: false;
|
|
1267
|
+
}
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1271
|
+
|
|
1272
|
+
---
|
|
819
1273
|
## Variables
|
|
820
1274
|
|
package/mod.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./src/script/templates/index.js"
|
|
|
4
4
|
export * from "./src/transaction/index.js"
|
|
5
5
|
export * from "./src/transaction/fee-models/index.js"
|
|
6
6
|
export * from "./src/transaction/broadcasters/index.js"
|
|
7
|
+
export * from "./src/transaction/chaintrackers/index.js"
|
|
7
8
|
export * from "./src/transaction/http/index.js"
|
|
8
9
|
export * from "./src/messages/index.js"
|
|
9
10
|
export * from "./src/compat/index.js"
|
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@ import { Broadcaster, BroadcastResponse, BroadcastFailure } from './Broadcaster.
|
|
|
10
10
|
import MerklePath from './MerklePath.js'
|
|
11
11
|
import Spend from '../script/Spend.js'
|
|
12
12
|
import ChainTracker from './ChainTracker.js'
|
|
13
|
-
import {defaultBroadcaster} from
|
|
14
|
-
import {defaultChainTracker} from
|
|
13
|
+
import { defaultBroadcaster } from './broadcasters/DefaultBroadcaster.js'
|
|
14
|
+
import { defaultChainTracker } from './chaintrackers/DefaultChainTracker.js'
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Represents a complete Bitcoin transaction. This class encapsulates all the details
|