@bsv/sdk 1.0.34 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cjs/mod.js +1 -0
  2. package/dist/cjs/mod.js.map +1 -1
  3. package/dist/cjs/package.json +1 -1
  4. package/dist/cjs/src/primitives/PrivateKey.js +5 -3
  5. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  6. package/dist/cjs/src/primitives/PublicKey.js +14 -1
  7. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  8. package/dist/cjs/src/script/templates/P2PKH.js +1 -0
  9. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  10. package/dist/cjs/src/transaction/Transaction.js +38 -8
  11. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  12. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  13. package/dist/esm/mod.js +1 -0
  14. package/dist/esm/mod.js.map +1 -1
  15. package/dist/esm/src/primitives/PrivateKey.js +5 -3
  16. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  17. package/dist/esm/src/primitives/PublicKey.js +14 -1
  18. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  19. package/dist/esm/src/script/templates/P2PKH.js +1 -0
  20. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  21. package/dist/esm/src/transaction/Transaction.js +40 -10
  22. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  23. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  24. package/dist/types/mod.d.ts +1 -0
  25. package/dist/types/mod.d.ts.map +1 -1
  26. package/dist/types/src/primitives/PrivateKey.d.ts +6 -4
  27. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  28. package/dist/types/src/primitives/PublicKey.d.ts +4 -2
  29. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  30. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  31. package/dist/types/src/transaction/Transaction.d.ts +9 -2
  32. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  33. package/dist/types/src/transaction/TransactionInput.d.ts +4 -0
  34. package/dist/types/src/transaction/TransactionInput.d.ts.map +1 -1
  35. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  36. package/docs/primitives.md +73 -67
  37. package/docs/script.md +13 -11
  38. package/docs/transaction.md +508 -39
  39. package/mod.ts +1 -0
  40. package/package.json +1 -1
  41. package/src/primitives/PrivateKey.ts +6 -4
  42. package/src/primitives/PublicKey.ts +13 -2
  43. package/src/script/templates/P2PKH.ts +1 -0
  44. package/src/transaction/Transaction.ts +41 -10
  45. package/src/transaction/TransactionInput.ts +4 -0
  46. package/src/transaction/__tests/Transaction.test.ts +61 -0
@@ -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
- | [BroadcastFailure](#interface-broadcastfailure) |
10
- | [BroadcastResponse](#interface-broadcastresponse) |
11
- | [Broadcaster](#interface-broadcaster) |
12
- | [ChainTracker](#interface-chaintracker) |
13
- | [FeeModel](#interface-feemodel) |
14
- | [TransactionInput](#interface-transactioninput) |
15
- | [TransactionOutput](#interface-transactionoutput) |
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
 
@@ -46,6 +47,7 @@ export default interface TransactionInput {
46
47
  sourceTransaction?: Transaction;
47
48
  sourceTXID?: string;
48
49
  sourceOutputIndex: number;
50
+ sourceSatoshis?: number;
49
51
  unlockingScript?: UnlockingScript;
50
52
  unlockingScriptTemplate?: {
51
53
  sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
@@ -55,7 +57,7 @@ export default interface TransactionInput {
55
57
  }
56
58
  ```
57
59
 
58
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
60
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
59
61
 
60
62
  ---
61
63
  ### Interface: TransactionOutput
@@ -83,7 +85,7 @@ export default interface TransactionOutput {
83
85
  }
84
86
  ```
85
87
 
86
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
88
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
87
89
 
88
90
  ---
89
91
  ### Interface: FeeModel
@@ -97,7 +99,7 @@ export default interface FeeModel {
97
99
  }
98
100
  ```
99
101
 
100
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
102
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
101
103
 
102
104
  ---
103
105
  ### Interface: BroadcastResponse
@@ -112,7 +114,7 @@ export interface BroadcastResponse {
112
114
  }
113
115
  ```
114
116
 
115
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
117
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
116
118
 
117
119
  ---
118
120
  ### Interface: BroadcastFailure
@@ -127,7 +129,7 @@ export interface BroadcastFailure {
127
129
  }
128
130
  ```
129
131
 
130
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
132
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
131
133
 
132
134
  ---
133
135
  ### Interface: Broadcaster
@@ -141,7 +143,7 @@ export interface Broadcaster {
141
143
  }
142
144
  ```
143
145
 
144
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
146
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
145
147
 
146
148
  ---
147
149
  ### Interface: ChainTracker
@@ -169,18 +171,270 @@ export default interface ChainTracker {
169
171
  }
170
172
  ```
171
173
 
172
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
174
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
175
+
176
+ ---
177
+ ### Interface: HttpClient
178
+
179
+ An interface for HTTP client used to make HTTP requests.
180
+
181
+ ```ts
182
+ export interface HttpClient {
183
+ request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>): Promise<HttpClientResponse<T>>;
184
+ }
185
+ ```
186
+
187
+ <details>
188
+
189
+ <summary>Interface HttpClient Details</summary>
190
+
191
+ #### Method request
192
+
193
+ Makes a request to the server.
194
+
195
+ ```ts
196
+ request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>): Promise<HttpClientResponse<T>>
197
+ ```
198
+
199
+ Argument Details
200
+
201
+ + **url**
202
+ + The URL to make the request to.
203
+ + **options**
204
+ + The request configuration.
205
+
206
+ </details>
207
+
208
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
209
+
210
+ ---
211
+ ### Interface: HttpClientRequestOptions
212
+
213
+ An interface for configuration of the request to be passed to the request method.
214
+
215
+ ```ts
216
+ export interface HttpClientRequestOptions<Data = any> {
217
+ method?: string;
218
+ headers?: Record<string, string>;
219
+ data?: Data;
220
+ }
221
+ ```
222
+
223
+ <details>
224
+
225
+ <summary>Interface HttpClientRequestOptions Details</summary>
226
+
227
+ #### Property data
228
+
229
+ An object or null to set request's body.
230
+
231
+ ```ts
232
+ data?: Data
233
+ ```
234
+
235
+ #### Property headers
236
+
237
+ An object literal set request's headers.
238
+
239
+ ```ts
240
+ headers?: Record<string, string>
241
+ ```
242
+
243
+ #### Property method
244
+
245
+ A string to set request's method.
246
+
247
+ ```ts
248
+ method?: string
249
+ ```
250
+
251
+ </details>
252
+
253
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
254
+
255
+ ---
256
+ ### Interface: HttpsNodejs
257
+
258
+ Node.js Https module interface limited to options needed by ts-sdk
259
+
260
+ ```ts
261
+ export interface HttpsNodejs {
262
+ request(url: string, options: HttpClientRequestOptions, callback: (res: any) => void): NodejsHttpClientRequest;
263
+ }
264
+ ```
265
+
266
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
267
+
268
+ ---
269
+ ### Interface: NodejsHttpClientRequest
270
+
271
+ Nodejs result of the Node.js https.request call limited to options needed by ts-sdk
272
+
273
+ ```ts
274
+ export interface NodejsHttpClientRequest {
275
+ write(chunk: string): void;
276
+ end(): void;
277
+ on(event: string, callback: (data: any) => void): void;
278
+ end(): void;
279
+ }
280
+ ```
281
+
282
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
283
+
284
+ ---
285
+ ### Interface: Fetch
286
+
287
+ fetch function interface limited to options needed by ts-sdk
288
+
289
+ ```ts
290
+ export interface Fetch {
291
+ (url: string, options: FetchOptions): Promise<Response>;
292
+ }
293
+ ```
294
+
295
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
296
+
297
+ ---
298
+ ### Interface: FetchOptions
299
+
300
+ An interface for configuration of the request to be passed to the fetch method
301
+ limited to options needed by ts-sdk.
302
+
303
+ ```ts
304
+ export interface FetchOptions {
305
+ method?: string;
306
+ headers?: Record<string, string>;
307
+ body?: string | null;
308
+ }
309
+ ```
310
+
311
+ <details>
312
+
313
+ <summary>Interface FetchOptions Details</summary>
314
+
315
+ #### Property body
316
+
317
+ An object or null to set request's body.
318
+
319
+ ```ts
320
+ body?: string | null
321
+ ```
322
+
323
+ #### Property headers
324
+
325
+ An object literal set request's headers.
326
+
327
+ ```ts
328
+ headers?: Record<string, string>
329
+ ```
330
+
331
+ #### Property method
332
+
333
+ A string to set request's method.
334
+
335
+ ```ts
336
+ method?: string
337
+ ```
338
+
339
+ </details>
340
+
341
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
342
+
343
+ ---
344
+ ### Interface: ArcConfig
345
+
346
+ Configuration options for the ARC broadcaster.
347
+
348
+ ```ts
349
+ export interface ArcConfig {
350
+ apiKey?: string;
351
+ deploymentId?: string;
352
+ httpClient?: HttpClient;
353
+ }
354
+ ```
355
+
356
+ <details>
357
+
358
+ <summary>Interface ArcConfig Details</summary>
359
+
360
+ #### Property apiKey
361
+
362
+ Authentication token for the ARC API
363
+
364
+ ```ts
365
+ apiKey?: string
366
+ ```
367
+
368
+ #### Property deploymentId
369
+
370
+ Deployment id used annotating api calls in XDeployment-ID header - this value will be randomly generated if not set
371
+
372
+ ```ts
373
+ deploymentId?: string
374
+ ```
375
+
376
+ #### Property httpClient
377
+
378
+ The HTTP client used to make requests to the ARC API.
379
+
380
+ ```ts
381
+ httpClient?: HttpClient
382
+ ```
383
+
384
+ </details>
385
+
386
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
387
+
388
+ ---
389
+ ### Interface: WhatsOnChainConfig
390
+
391
+ Configuration options for the WhatsOnChain ChainTracker.
392
+
393
+ ```ts
394
+ export interface WhatsOnChainConfig {
395
+ apiKey?: string;
396
+ httpClient?: HttpClient;
397
+ }
398
+ ```
399
+
400
+ <details>
401
+
402
+ <summary>Interface WhatsOnChainConfig Details</summary>
403
+
404
+ #### Property apiKey
405
+
406
+ Authentication token for the WhatsOnChain API
407
+
408
+ ```ts
409
+ apiKey?: string
410
+ ```
411
+
412
+ #### Property httpClient
413
+
414
+ The HTTP client used to make requests to the API.
415
+
416
+ ```ts
417
+ httpClient?: HttpClient
418
+ ```
419
+
420
+ </details>
421
+
422
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
173
423
 
174
424
  ---
175
425
  ## Classes
176
426
 
177
427
  | |
178
428
  | --- |
429
+ | [ARC](#class-arc) |
430
+ | [FetchHttpClient](#class-fetchhttpclient) |
179
431
  | [MerklePath](#class-merklepath) |
432
+ | [NodejsHttpClient](#class-nodejshttpclient) |
180
433
  | [SatoshisPerKilobyte](#class-satoshisperkilobyte) |
181
434
  | [Transaction](#class-transaction) |
435
+ | [WhatsOnChain](#class-whatsonchain) |
182
436
 
183
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
437
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
184
438
 
185
439
  ---
186
440
 
@@ -232,7 +486,7 @@ Argument Details
232
486
 
233
487
  </details>
234
488
 
235
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
489
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
236
490
 
237
491
  ---
238
492
  ### Class: MerklePath
@@ -396,7 +650,144 @@ Argument Details
396
650
 
397
651
  </details>
398
652
 
399
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
653
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
654
+
655
+ ---
656
+ ### Class: NodejsHttpClient
657
+
658
+ Adapter for Node.js Https module to be used as HttpClient
659
+
660
+ ```ts
661
+ export class NodejsHttpClient implements HttpClient {
662
+ constructor(private https: HttpsNodejs)
663
+ async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
664
+ }
665
+ ```
666
+
667
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
668
+
669
+ ---
670
+ ### Class: FetchHttpClient
671
+
672
+ Adapter for Node.js Https module to be used as HttpClient
673
+
674
+ ```ts
675
+ export class FetchHttpClient implements HttpClient {
676
+ constructor(private fetch: Fetch)
677
+ async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
678
+ }
679
+ ```
680
+
681
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
682
+
683
+ ---
684
+ ### Class: ARC
685
+
686
+ Represents an ARC transaction broadcaster.
687
+
688
+ ```ts
689
+ export default class ARC implements Broadcaster {
690
+ readonly URL: string;
691
+ readonly apiKey: string | undefined;
692
+ readonly deploymentId: string;
693
+ constructor(URL: string, config?: ArcConfig);
694
+ constructor(URL: string, apiKey?: string);
695
+ constructor(URL: string, config?: string | ArcConfig)
696
+ async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
697
+ }
698
+ ```
699
+
700
+ <details>
701
+
702
+ <summary>Class ARC Details</summary>
703
+
704
+ #### Constructor
705
+
706
+ Constructs an instance of the ARC broadcaster.
707
+
708
+ ```ts
709
+ constructor(URL: string, config?: ArcConfig)
710
+ ```
711
+
712
+ Argument Details
713
+
714
+ + **URL**
715
+ + The URL endpoint for the ARC API.
716
+ + **config**
717
+ + Configuration options for the ARC broadcaster.
718
+
719
+ #### Constructor
720
+
721
+ Constructs an instance of the ARC broadcaster.
722
+
723
+ ```ts
724
+ constructor(URL: string, apiKey?: string)
725
+ ```
726
+
727
+ Argument Details
728
+
729
+ + **URL**
730
+ + The URL endpoint for the ARC API.
731
+ + **apiKey**
732
+ + The API key used for authorization with the ARC API.
733
+
734
+ #### Method broadcast
735
+
736
+ Broadcasts a transaction via ARC.
737
+
738
+ ```ts
739
+ async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
740
+ ```
741
+
742
+ Returns
743
+
744
+ A promise that resolves to either a success or failure response.
745
+
746
+ Argument Details
747
+
748
+ + **tx**
749
+ + The transaction to be broadcasted.
750
+
751
+ </details>
752
+
753
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
754
+
755
+ ---
756
+ ### Class: WhatsOnChain
757
+
758
+ Represents a chain tracker based on What's On Chain .
759
+
760
+ ```ts
761
+ export default class WhatsOnChain implements ChainTracker {
762
+ readonly network: string;
763
+ readonly apiKey: string;
764
+ constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
765
+ async isValidRootForHeight(root: string, height: number): Promise<boolean>
766
+ }
767
+ ```
768
+
769
+ <details>
770
+
771
+ <summary>Class WhatsOnChain Details</summary>
772
+
773
+ #### Constructor
774
+
775
+ Constructs an instance of the WhatsOnChain ChainTracker.
776
+
777
+ ```ts
778
+ constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
779
+ ```
780
+
781
+ Argument Details
782
+
783
+ + **network**
784
+ + The BSV network to use when calling the WhatsOnChain API.
785
+ + **config**
786
+ + Configuration options for the WhatsOnChain ChainTracker.
787
+
788
+ </details>
789
+
790
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
400
791
 
401
792
  ---
402
793
  ### Class: Transaction
@@ -427,16 +818,16 @@ export default class Transaction {
427
818
  merklePath?: MerklePath;
428
819
  static fromBEEF(beef: number[]): Transaction
429
820
  static parseScriptOffsets(bin: number[]): {
430
- inputs: {
821
+ inputs: Array<{
431
822
  vin: number;
432
823
  offset: number;
433
824
  length: number;
434
- }[];
435
- outputs: {
825
+ }>;
826
+ outputs: Array<{
436
827
  vout: number;
437
828
  offset: number;
438
829
  length: number;
439
- }[];
830
+ }>;
440
831
  }
441
832
  static fromBinary(bin: number[]): Transaction
442
833
  static fromHex(hex: string): Transaction
@@ -445,9 +836,10 @@ export default class Transaction {
445
836
  addInput(input: TransactionInput): void
446
837
  addOutput(output: TransactionOutput): void
447
838
  updateMetadata(metadata: Record<string, any>): void
448
- async fee(model?: FeeModel, changeDistribution: "equal" | "random" = "equal"): Promise<void>
839
+ async fee(modelOrFee?: FeeModel | number, changeDistribution: "equal" | "random" = "equal"): Promise<void>
840
+ getFee(): number
449
841
  async sign(): Promise<void>
450
- async broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure>
842
+ async broadcast(broadcaster: Broadcaster = defaultBroadcaster()): Promise<BroadcastResponse | BroadcastFailure>
451
843
  toBinary(): number[]
452
844
  toEF(): number[]
453
845
  toHexEF(): string
@@ -457,7 +849,7 @@ export default class Transaction {
457
849
  id(): number[];
458
850
  id(enc: "hex"): string;
459
851
  id(enc?: "hex"): number[] | string
460
- async verify(chainTracker: ChainTracker | "scripts only"): Promise<boolean>
852
+ async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker()): Promise<boolean>
461
853
  toBEEF(): number[]
462
854
  }
463
855
  ```
@@ -501,7 +893,7 @@ Argument Details
501
893
  Broadcasts a transaction.
502
894
 
503
895
  ```ts
504
- async broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure>
896
+ async broadcast(broadcaster: Broadcaster = defaultBroadcaster()): Promise<BroadcastResponse | BroadcastFailure>
505
897
  ```
506
898
 
507
899
  Returns
@@ -517,15 +909,16 @@ Argument Details
517
909
 
518
910
  Computes fees prior to signing.
519
911
  If no fee model is provided, uses a SatoshisPerKilobyte fee model that pays 10 sat/kb.
912
+ If fee is a number, the transaction uses that value as fee.
520
913
 
521
914
  ```ts
522
- async fee(model?: FeeModel, changeDistribution: "equal" | "random" = "equal"): Promise<void>
915
+ async fee(modelOrFee?: FeeModel | number, changeDistribution: "equal" | "random" = "equal"): Promise<void>
523
916
  ```
524
917
 
525
918
  Argument Details
526
919
 
527
- + **model**
528
- + The initialized fee model to use
920
+ + **modelOrFee**
921
+ + The initialized fee model to use or fixed fee for the transaction
529
922
  + **changeDistribution**
530
923
  + Specifies how the change should be distributed
531
924
  amongst the change outputs
@@ -600,6 +993,18 @@ Argument Details
600
993
  + **hex**
601
994
  + The hexadecimal string representation of the transaction BEEF.
602
995
 
996
+ #### Method getFee
997
+
998
+ Utility method that returns the current fee based on inputs and outputs
999
+
1000
+ ```ts
1001
+ getFee(): number
1002
+ ```
1003
+
1004
+ Returns
1005
+
1006
+ The current transaction fee
1007
+
603
1008
  #### Method hash
604
1009
 
605
1010
  Calculates the transaction's hash.
@@ -675,16 +1080,16 @@ This supports the efficient retreival of script data from transaction data.
675
1080
 
676
1081
  ```ts
677
1082
  static parseScriptOffsets(bin: number[]): {
678
- inputs: {
1083
+ inputs: Array<{
679
1084
  vin: number;
680
1085
  offset: number;
681
1086
  length: number;
682
- }[];
683
- outputs: {
1087
+ }>;
1088
+ outputs: Array<{
684
1089
  vout: number;
685
1090
  offset: number;
686
1091
  length: number;
687
- }[];
1092
+ }>;
688
1093
  }
689
1094
  ```
690
1095
 
@@ -797,7 +1202,7 @@ Argument Details
797
1202
  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
1203
 
799
1204
  ```ts
800
- async verify(chainTracker: ChainTracker | "scripts only"): Promise<boolean>
1205
+ async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker()): Promise<boolean>
801
1206
  ```
802
1207
 
803
1208
  Returns
@@ -807,14 +1212,78 @@ Whether the transaction is valid according to the rules of SPV.
807
1212
  Argument Details
808
1213
 
809
1214
  + **chainTracker**
810
- + An instance of ChainTracker, a Bitcoin block header tracker. If the value is set to 'scripts only', headers will not be verified.
1215
+ + 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
1216
 
812
1217
  </details>
813
1218
 
814
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Variables](#variables)
1219
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
815
1220
 
816
1221
  ---
817
1222
  ## Functions
818
1223
 
1224
+ | |
1225
+ | --- |
1226
+ | [defaultBroadcaster](#function-defaultbroadcaster) |
1227
+ | [defaultChainTracker](#function-defaultchaintracker) |
1228
+ | [defaultHttpClient](#function-defaulthttpclient) |
1229
+
1230
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1231
+
1232
+ ---
1233
+
1234
+ ### Function: defaultHttpClient
1235
+
1236
+ Returns a default HttpClient implementation based on the environment that it is run on.
1237
+ This method will attempt to use `window.fetch` if available (in browser environments).
1238
+ If running in a Node.js environment, it falls back to using the Node.js `https` module
1239
+
1240
+ ```ts
1241
+ export function defaultHttpClient(): HttpClient
1242
+ ```
1243
+
1244
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1245
+
1246
+ ---
1247
+ ### Function: defaultBroadcaster
1248
+
1249
+ ```ts
1250
+ export function defaultBroadcaster(): Broadcaster
1251
+ ```
1252
+
1253
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1254
+
1255
+ ---
1256
+ ### Function: defaultChainTracker
1257
+
1258
+ ```ts
1259
+ export function defaultChainTracker(): ChainTracker
1260
+ ```
1261
+
1262
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1263
+
1264
+ ---
1265
+ ## Types
1266
+
1267
+ ### Type: HttpClientResponse
1268
+
1269
+ An interface for the response returned by the request method.
1270
+
1271
+ ```ts
1272
+ export type HttpClientResponse<T = any> = {
1273
+ data: T;
1274
+ status: number;
1275
+ statusText: string;
1276
+ ok: true;
1277
+ } | {
1278
+ data: any;
1279
+ status: number;
1280
+ statusText: string;
1281
+ ok: false;
1282
+ }
1283
+ ```
1284
+
1285
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1286
+
1287
+ ---
819
1288
  ## Variables
820
1289