@bsv/sdk 1.2.1 → 1.2.3

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.
@@ -19,100 +19,77 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
19
19
 
20
20
  ---
21
21
 
22
- ### Interface: TransactionInput
23
-
24
- Represents an input to a Bitcoin transaction.
25
- This interface defines the structure and components required to construct
26
- a transaction input in the Bitcoin blockchain.
27
-
28
- Example
29
-
30
- ```ts
31
- // Creating a simple transaction input
32
- let txInput = {
33
- sourceTXID: '123abc...',
34
- sourceOutputIndex: 0,
35
- sequence: 0xFFFFFFFF
36
- };
22
+ ### Interface: ArcConfig
37
23
 
38
- // Using an unlocking script template
39
- txInput.unlockingScriptTemplate = {
40
- sign: async (tx, index) => { ... },
41
- estimateLength: async (tx, index) => { ... }
42
- };
43
- ```
24
+ Configuration options for the ARC broadcaster.
44
25
 
45
26
  ```ts
46
- export default interface TransactionInput {
47
- sourceTransaction?: Transaction;
48
- sourceTXID?: string;
49
- sourceOutputIndex: number;
50
- unlockingScript?: UnlockingScript;
51
- unlockingScriptTemplate?: {
52
- sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
53
- estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
54
- };
55
- sequence?: number;
27
+ export interface ArcConfig {
28
+ apiKey?: string;
29
+ httpClient?: HttpClient;
30
+ deploymentId?: string;
31
+ callbackUrl?: string;
32
+ callbackToken?: string;
33
+ headers?: Record<string, string>;
56
34
  }
57
35
  ```
58
36
 
59
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
37
+ See also: [HttpClient](#interface-httpclient)
60
38
 
61
- ---
62
- ### Interface: TransactionOutput
39
+ <details>
63
40
 
64
- Represents an output in a Bitcoin transaction.
65
- This interface defines the structure and components necessary to construct
66
- a transaction output, which secures owned Bitcoins to be unlocked later.
41
+ <summary>Interface ArcConfig Details</summary>
67
42
 
68
- Example
43
+ #### Property apiKey
44
+
45
+ Authentication token for the ARC API
69
46
 
70
47
  ```ts
71
- // Creating a simple transaction output
72
- let txOutput = {
73
- satoshis: 1000,
74
- lockingScript: LockingScript.fromASM('OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG'),
75
- change: false
76
- };
48
+ apiKey?: string
77
49
  ```
78
50
 
51
+ #### Property callbackToken
52
+
53
+ default access token for notification callback endpoint. It will be used as a Authorization header for the http callback
54
+
79
55
  ```ts
80
- export default interface TransactionOutput {
81
- satoshis?: number;
82
- lockingScript: LockingScript;
83
- change?: boolean;
84
- }
56
+ callbackToken?: string
85
57
  ```
86
58
 
87
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
59
+ #### Property callbackUrl
88
60
 
89
- ---
90
- ### Interface: FeeModel
61
+ notification callback endpoint for proofs and double spend notification
91
62
 
92
- Represents the interface for a transaction fee model.
93
- This interface defines a standard method for computing a fee when given a transaction.
63
+ ```ts
64
+ callbackUrl?: string
65
+ ```
66
+
67
+ #### Property deploymentId
68
+
69
+ Deployment id used annotating api calls in XDeployment-ID header - this value will be randomly generated if not set
94
70
 
95
71
  ```ts
96
- export default interface FeeModel {
97
- computeFee: (transaction: Transaction) => Promise<number>;
98
- }
72
+ deploymentId?: string
99
73
  ```
100
74
 
101
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
75
+ #### Property headers
102
76
 
103
- ---
104
- ### Interface: BroadcastResponse
77
+ additional headers to be attached to all tx submissions.
105
78
 
106
- Defines the structure of a successful broadcast response.
79
+ ```ts
80
+ headers?: Record<string, string>
81
+ ```
82
+
83
+ #### Property httpClient
84
+
85
+ The HTTP client used to make requests to the ARC API.
107
86
 
108
87
  ```ts
109
- export interface BroadcastResponse {
110
- status: "success";
111
- txid: string;
112
- message: string;
113
- competingTxs?: string[];
114
- }
88
+ httpClient?: HttpClient
115
89
  ```
90
+ See also: [HttpClient](#interface-httpclient)
91
+
92
+ </details>
116
93
 
117
94
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
118
95
 
@@ -133,6 +110,22 @@ export interface BroadcastFailure {
133
110
 
134
111
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
135
112
 
113
+ ---
114
+ ### Interface: BroadcastResponse
115
+
116
+ Defines the structure of a successful broadcast response.
117
+
118
+ ```ts
119
+ export interface BroadcastResponse {
120
+ status: "success";
121
+ txid: string;
122
+ message: string;
123
+ competingTxs?: string[];
124
+ }
125
+ ```
126
+
127
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
128
+
136
129
  ---
137
130
  ### Interface: Broadcaster
138
131
 
@@ -145,6 +138,8 @@ export interface Broadcaster {
145
138
  }
146
139
  ```
147
140
 
141
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse), [Transaction](#class-transaction)
142
+
148
143
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
149
144
 
150
145
  ---
@@ -176,17 +171,65 @@ export default interface ChainTracker {
176
171
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
177
172
 
178
173
  ---
179
- ### Interface: MerklePathLeaf
174
+ ### Interface: FeeModel
175
+
176
+ Represents the interface for a transaction fee model.
177
+ This interface defines a standard method for computing a fee when given a transaction.
180
178
 
181
179
  ```ts
182
- export interface MerklePathLeaf {
183
- offset: number;
184
- hash?: string;
185
- txid?: boolean;
186
- duplicate?: boolean;
180
+ export default interface FeeModel {
181
+ computeFee: (transaction: Transaction) => Promise<number>;
182
+ }
183
+ ```
184
+
185
+ See also: [Transaction](#class-transaction)
186
+
187
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
188
+
189
+ ---
190
+ ### Interface: FetchOptions
191
+
192
+ An interface for configuration of the request to be passed to the fetch method
193
+ limited to options needed by ts-sdk.
194
+
195
+ ```ts
196
+ export interface FetchOptions {
197
+ method?: string;
198
+ headers?: Record<string, string>;
199
+ body?: string | null;
187
200
  }
188
201
  ```
189
202
 
203
+ <details>
204
+
205
+ <summary>Interface FetchOptions Details</summary>
206
+
207
+ #### Property body
208
+
209
+ An object or null to set request's body.
210
+
211
+ ```ts
212
+ body?: string | null
213
+ ```
214
+
215
+ #### Property headers
216
+
217
+ An object literal set request's headers.
218
+
219
+ ```ts
220
+ headers?: Record<string, string>
221
+ ```
222
+
223
+ #### Property method
224
+
225
+ A string to set request's method.
226
+
227
+ ```ts
228
+ method?: string
229
+ ```
230
+
231
+ </details>
232
+
190
233
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
191
234
 
192
235
  ---
@@ -200,6 +243,8 @@ export interface HttpClient {
200
243
  }
201
244
  ```
202
245
 
246
+ See also: [HttpClientRequestOptions](#interface-httpclientrequestoptions), [HttpClientResponse](#type-httpclientresponse)
247
+
203
248
  <details>
204
249
 
205
250
  <summary>Interface HttpClient Details</summary>
@@ -211,6 +256,7 @@ Makes a request to the server.
211
256
  ```ts
212
257
  request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>
213
258
  ```
259
+ See also: [HttpClientRequestOptions](#interface-httpclientrequestoptions), [HttpClientResponse](#type-httpclientresponse)
214
260
 
215
261
  </details>
216
262
 
@@ -272,138 +318,108 @@ export interface HttpsNodejs {
272
318
  }
273
319
  ```
274
320
 
321
+ See also: [HttpClientRequestOptions](#interface-httpclientrequestoptions), [NodejsHttpClientRequest](#interface-nodejshttpclientrequest)
322
+
275
323
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
276
324
 
277
325
  ---
278
- ### Interface: NodejsHttpClientRequest
279
-
280
- Nodejs result of the Node.js https.request call limited to options needed by ts-sdk
326
+ ### Interface: MerklePathLeaf
281
327
 
282
328
  ```ts
283
- export interface NodejsHttpClientRequest {
284
- write: (chunk: string) => void;
285
- on: (event: string, callback: (data: any) => void) => void;
286
- end: (() => void) & (() => void);
329
+ export interface MerklePathLeaf {
330
+ offset: number;
331
+ hash?: string;
332
+ txid?: boolean;
333
+ duplicate?: boolean;
287
334
  }
288
335
  ```
289
336
 
290
337
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
291
338
 
292
339
  ---
293
- ### Interface: FetchOptions
340
+ ### Interface: NodejsHttpClientRequest
294
341
 
295
- An interface for configuration of the request to be passed to the fetch method
296
- limited to options needed by ts-sdk.
342
+ Nodejs result of the Node.js https.request call limited to options needed by ts-sdk
297
343
 
298
344
  ```ts
299
- export interface FetchOptions {
300
- method?: string;
301
- headers?: Record<string, string>;
302
- body?: string | null;
345
+ export interface NodejsHttpClientRequest {
346
+ write: (chunk: string) => void;
347
+ on: (event: string, callback: (data: any) => void) => void;
348
+ end: (() => void) & (() => void);
303
349
  }
304
350
  ```
305
351
 
306
- <details>
352
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
307
353
 
308
- <summary>Interface FetchOptions Details</summary>
354
+ ---
355
+ ### Interface: TransactionInput
309
356
 
310
- #### Property body
357
+ Represents an input to a Bitcoin transaction.
358
+ This interface defines the structure and components required to construct
359
+ a transaction input in the Bitcoin blockchain.
311
360
 
312
- An object or null to set request's body.
361
+ Example
313
362
 
314
363
  ```ts
315
- body?: string | null
316
- ```
317
-
318
- #### Property headers
364
+ // Creating a simple transaction input
365
+ let txInput = {
366
+ sourceTXID: '123abc...',
367
+ sourceOutputIndex: 0,
368
+ sequence: 0xFFFFFFFF
369
+ };
319
370
 
320
- An object literal set request's headers.
371
+ // Using an unlocking script template
372
+ txInput.unlockingScriptTemplate = {
373
+ sign: async (tx, index) => { ... },
374
+ estimateLength: async (tx, index) => { ... }
375
+ };
376
+ ```
321
377
 
322
378
  ```ts
323
- headers?: Record<string, string>
379
+ export default interface TransactionInput {
380
+ sourceTransaction?: Transaction;
381
+ sourceTXID?: string;
382
+ sourceOutputIndex: number;
383
+ unlockingScript?: UnlockingScript;
384
+ unlockingScriptTemplate?: {
385
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
386
+ estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
387
+ };
388
+ sequence?: number;
389
+ }
324
390
  ```
325
391
 
326
- #### Property method
392
+ See also: [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
327
393
 
328
- A string to set request's method.
329
-
330
- ```ts
331
- method?: string
332
- ```
333
-
334
- </details>
335
-
336
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
394
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
337
395
 
338
396
  ---
339
- ### Interface: ArcConfig
340
-
341
- Configuration options for the ARC broadcaster.
342
-
343
- ```ts
344
- export interface ArcConfig {
345
- apiKey?: string;
346
- httpClient?: HttpClient;
347
- deploymentId?: string;
348
- callbackUrl?: string;
349
- callbackToken?: string;
350
- headers?: Record<string, string>;
351
- }
352
- ```
353
-
354
- <details>
355
-
356
- <summary>Interface ArcConfig Details</summary>
357
-
358
- #### Property apiKey
359
-
360
- Authentication token for the ARC API
361
-
362
- ```ts
363
- apiKey?: string
364
- ```
365
-
366
- #### Property callbackToken
367
-
368
- default access token for notification callback endpoint. It will be used as a Authorization header for the http callback
369
-
370
- ```ts
371
- callbackToken?: string
372
- ```
373
-
374
- #### Property callbackUrl
375
-
376
- notification callback endpoint for proofs and double spend notification
377
-
378
- ```ts
379
- callbackUrl?: string
380
- ```
381
-
382
- #### Property deploymentId
383
-
384
- Deployment id used annotating api calls in XDeployment-ID header - this value will be randomly generated if not set
385
-
386
- ```ts
387
- deploymentId?: string
388
- ```
397
+ ### Interface: TransactionOutput
389
398
 
390
- #### Property headers
399
+ Represents an output in a Bitcoin transaction.
400
+ This interface defines the structure and components necessary to construct
401
+ a transaction output, which secures owned Bitcoins to be unlocked later.
391
402
 
392
- additional headers to be attached to all tx submissions.
403
+ Example
393
404
 
394
405
  ```ts
395
- headers?: Record<string, string>
406
+ // Creating a simple transaction output
407
+ let txOutput = {
408
+ satoshis: 1000,
409
+ lockingScript: LockingScript.fromASM('OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG'),
410
+ change: false
411
+ };
396
412
  ```
397
413
 
398
- #### Property httpClient
399
-
400
- The HTTP client used to make requests to the ARC API.
401
-
402
414
  ```ts
403
- httpClient?: HttpClient
415
+ export default interface TransactionOutput {
416
+ satoshis?: number;
417
+ lockingScript: LockingScript;
418
+ change?: boolean;
419
+ }
404
420
  ```
405
421
 
406
- </details>
422
+ See also: [LockingScript](#class-lockingscript)
407
423
 
408
424
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
409
425
 
@@ -419,6 +435,8 @@ export interface WhatsOnChainConfig {
419
435
  }
420
436
  ```
421
437
 
438
+ See also: [HttpClient](#interface-httpclient)
439
+
422
440
  <details>
423
441
 
424
442
  <summary>Interface WhatsOnChainConfig Details</summary>
@@ -438,6 +456,7 @@ The HTTP client used to make requests to the API.
438
456
  ```ts
439
457
  httpClient?: HttpClient
440
458
  ```
459
+ See also: [HttpClient](#interface-httpclient)
441
460
 
442
461
  </details>
443
462
 
@@ -463,807 +482,935 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
463
482
 
464
483
  ---
465
484
 
466
- ### Class: SatoshisPerKilobyte
485
+ ### Class: ARC
467
486
 
468
- Represents the "satoshis per kilobyte" transaction fee model.
487
+ Represents an ARC transaction broadcaster.
469
488
 
470
489
  ```ts
471
- export default class SatoshisPerKilobyte implements FeeModel {
472
- value: number;
473
- constructor(value: number)
474
- async computeFee(tx: Transaction): Promise<number>
490
+ export default class ARC implements Broadcaster {
491
+ readonly URL: string;
492
+ readonly apiKey: string | undefined;
493
+ readonly deploymentId: string;
494
+ readonly callbackUrl: string | undefined;
495
+ readonly callbackToken: string | undefined;
496
+ readonly headers: Record<string, string> | undefined;
497
+ constructor(URL: string, config?: ArcConfig);
498
+ constructor(URL: string, apiKey?: string);
499
+ constructor(URL: string, config?: string | ArcConfig)
500
+ async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
475
501
  }
476
502
  ```
477
503
 
504
+ See also: [ArcConfig](#interface-arcconfig), [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse), [Broadcaster](#interface-broadcaster), [Transaction](#class-transaction)
505
+
478
506
  <details>
479
507
 
480
- <summary>Class SatoshisPerKilobyte Details</summary>
508
+ <summary>Class ARC Details</summary>
481
509
 
482
510
  #### Constructor
483
511
 
484
- Constructs an instance of the sat/kb fee model.
512
+ Constructs an instance of the ARC broadcaster.
485
513
 
486
514
  ```ts
487
- constructor(value: number)
515
+ constructor(URL: string, config?: ArcConfig)
488
516
  ```
517
+ See also: [ArcConfig](#interface-arcconfig)
489
518
 
490
519
  Argument Details
491
520
 
492
- + **value**
493
- + The number of satoshis per kilobyte to charge as a fee.
521
+ + **URL**
522
+ + The URL endpoint for the ARC API.
523
+ + **config**
524
+ + Configuration options for the ARC broadcaster.
494
525
 
495
- #### Method computeFee
526
+ #### Constructor
496
527
 
497
- Computes the fee for a given transaction.
528
+ Constructs an instance of the ARC broadcaster.
498
529
 
499
530
  ```ts
500
- async computeFee(tx: Transaction): Promise<number>
531
+ constructor(URL: string, apiKey?: string)
532
+ ```
533
+
534
+ Argument Details
535
+
536
+ + **URL**
537
+ + The URL endpoint for the ARC API.
538
+ + **apiKey**
539
+ + The API key used for authorization with the ARC API.
540
+
541
+ #### Method broadcast
542
+
543
+ Broadcasts a transaction via ARC.
544
+
545
+ ```ts
546
+ async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
501
547
  ```
548
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse), [Transaction](#class-transaction)
502
549
 
503
550
  Returns
504
551
 
505
- The fee in satoshis for the transaction, as a BigNumber.
552
+ A promise that resolves to either a success or failure response.
506
553
 
507
554
  Argument Details
508
555
 
509
556
  + **tx**
510
- + The transaction for which a fee is to be computed.
557
+ + The transaction to be broadcasted.
511
558
 
512
559
  </details>
513
560
 
514
561
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
515
562
 
516
563
  ---
517
- ### Class: MerklePath
518
-
519
- Represents a Merkle Path, which is used to provide a compact proof of inclusion for a
520
- transaction in a block. This class encapsulates all the details required for creating
521
- and verifying Merkle Proofs.
522
-
523
- Example
524
-
525
- ```ts
526
- // Creating and verifying a Merkle Path
527
- const merklePath = MerklePath.fromHex('...');
528
- const isValid = merklePath.verify(txid, chainTracker);
529
- ```
564
+ ### Class: Beef
530
565
 
531
566
  ```ts
532
- export default class MerklePath {
533
- blockHeight: number;
534
- path: Array<Array<{
535
- offset: number;
536
- hash?: string;
537
- txid?: boolean;
538
- duplicate?: boolean;
539
- }>>;
540
- static fromHex(hex: string): MerklePath
541
- static fromReader(reader: Reader): MerklePath
542
- static fromBinary(bump: number[]): MerklePath
543
- constructor(blockHeight: number, path: Array<Array<{
544
- offset: number;
545
- hash?: string;
546
- txid?: boolean;
547
- duplicate?: boolean;
548
- }>>)
567
+ export class Beef {
568
+ bumps: MerklePath[] = [];
569
+ txs: BeefTx[] = [];
570
+ version: BeefVersion = undefined;
571
+ atomicTxid: string | undefined = undefined;
572
+ constructor(version?: BeefVersion)
573
+ get magic(): number
574
+ findTxid(txid: string): BeefTx | undefined
575
+ findBump(txid: string): MerklePath | undefined
576
+ findTransactionForSigning(txid: string): Transaction | undefined
577
+ findAtomicTransaction(txid: string): Transaction | undefined
578
+ mergeBump(bump: MerklePath): number
579
+ mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
580
+ mergeTransaction(tx: Transaction): BeefTx
581
+ removeExistingTxid(txid: string)
582
+ mergeTxidOnly(txid: string): BeefTx
583
+ mergeBeefTx(btx: BeefTx): BeefTx
584
+ mergeBeef(beef: number[] | Beef)
585
+ isValid(allowTxidOnly?: boolean): boolean
586
+ async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
587
+ toWriter(writer: Writer)
549
588
  toBinary(): number[]
589
+ toBinaryAtomic(txid: string)
550
590
  toHex(): string
551
- computeRoot(txid?: string): string
552
- findOrComputeLeaf(height: number, offset: number): MerklePathLeaf | undefined
553
- async verify(txid: string, chainTracker: ChainTracker): Promise<boolean>
554
- combine(other: MerklePath): void
555
- trim()
591
+ static fromReader(br: Reader): Beef
592
+ static fromBinary(bin: number[]): Beef
593
+ static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
594
+ sortTxs(): {
595
+ missingInputs: string[];
596
+ notValid: string[];
597
+ valid: string[];
598
+ withMissingInputs: string[];
599
+ txidOnly: string[];
600
+ }
601
+ clone(): Beef
602
+ trimKnownTxids(knownTxids: string[])
603
+ getValidTxids(): string[]
604
+ toLogString(): string
556
605
  }
557
606
  ```
558
607
 
559
- <details>
608
+ See also: [BeefTx](#class-beeftx), [BeefVersion](#type-beefversion), [ChainTracker](#interface-chaintracker), [MerklePath](#class-merklepath), [Reader](#class-reader), [Transaction](#class-transaction), [Writer](#class-writer), [toHex](#variable-tohex), [verify](#variable-verify)
560
609
 
561
- <summary>Class MerklePath Details</summary>
610
+ <details>
562
611
 
563
- #### Method combine
612
+ <summary>Class Beef Details</summary>
564
613
 
565
- Combines this MerklePath with another to create a compound proof.
614
+ #### Method clone
566
615
 
567
616
  ```ts
568
- combine(other: MerklePath): void
617
+ clone(): Beef
569
618
  ```
619
+ See also: [Beef](#class-beef)
570
620
 
571
- Argument Details
572
-
573
- + **other**
574
- + Another MerklePath to combine with this path.
621
+ Returns
575
622
 
576
- Throws
623
+ a shallow copy of this beef
577
624
 
578
- - If the paths have different block heights or roots.
625
+ #### Method findAtomicTransaction
579
626
 
580
- #### Method computeRoot
627
+ Builds the proof tree rooted at a specific `Transaction`.
581
628
 
582
- Computes the Merkle root from the provided transaction ID.
629
+ To succeed, the Beef must contain all the required transaction and merkle path data.
583
630
 
584
631
  ```ts
585
- computeRoot(txid?: string): string
632
+ findAtomicTransaction(txid: string): Transaction | undefined
586
633
  ```
634
+ See also: [Transaction](#class-transaction)
587
635
 
588
636
  Returns
589
637
 
590
- - The computed Merkle root as a hexadecimal string.
638
+ Transaction with input `SourceTransaction` and `MerklePath` populated from this Beef.
591
639
 
592
640
  Argument Details
593
641
 
594
642
  + **txid**
595
- + The transaction ID to compute the Merkle root for. If not provided, the root will be computed from an unspecified branch, and not all branches will be validated!
596
-
597
- Throws
598
-
599
- - If the transaction ID is not part of the Merkle Path.
600
-
601
- #### Method findOrComputeLeaf
602
-
603
- Find leaf with `offset` at `height` or compute from level below, recursively.
643
+ + The id of the target transaction.
604
644
 
605
- Does not add computed leaves to path.
645
+ #### Method findBump
606
646
 
607
647
  ```ts
608
- findOrComputeLeaf(height: number, offset: number): MerklePathLeaf | undefined
648
+ findBump(txid: string): MerklePath | undefined
609
649
  ```
650
+ See also: [MerklePath](#class-merklepath)
610
651
 
611
- #### Method fromBinary
652
+ Returns
612
653
 
613
- Creates a MerklePath instance from a binary array.
654
+ `MerklePath` with level zero hash equal to txid or undefined.
655
+
656
+ #### Method findTransactionForSigning
657
+
658
+ Finds a Transaction in this `Beef`
659
+ and adds any missing input SourceTransactions from this `Beef`.
660
+
661
+ The result is suitable for signing.
614
662
 
615
663
  ```ts
616
- static fromBinary(bump: number[]): MerklePath
664
+ findTransactionForSigning(txid: string): Transaction | undefined
617
665
  ```
666
+ See also: [Transaction](#class-transaction)
618
667
 
619
668
  Returns
620
669
 
621
- - A new MerklePath instance.
670
+ Transaction with all available input `SourceTransaction`s from this Beef.
622
671
 
623
672
  Argument Details
624
673
 
625
- + **bump**
626
- + The binary array representation of the Merkle Path.
674
+ + **txid**
675
+ + The id of the target transaction.
627
676
 
628
- #### Method fromHex
677
+ #### Method findTxid
629
678
 
630
- Creates a MerklePath instance from a hexadecimal string.
679
+ ```ts
680
+ findTxid(txid: string): BeefTx | undefined
681
+ ```
682
+ See also: [BeefTx](#class-beeftx)
683
+
684
+ Returns
685
+
686
+ `BeefTx` in `txs` with `txid`.
687
+
688
+ Argument Details
689
+
690
+ + **txid**
691
+ + of `beefTx` to find
692
+
693
+ #### Method fromBinary
694
+
695
+ Constructs an instance of the Beef class based on the provided binary array
631
696
 
632
697
  ```ts
633
- static fromHex(hex: string): MerklePath
698
+ static fromBinary(bin: number[]): Beef
634
699
  ```
700
+ See also: [Beef](#class-beef)
635
701
 
636
702
  Returns
637
703
 
638
- - A new MerklePath instance.
704
+ An instance of the Beef class constructed from the binary data
639
705
 
640
706
  Argument Details
641
707
 
642
- + **hex**
643
- + The hexadecimal string representation of the Merkle Path.
708
+ + **bin**
709
+ + The binary array from which to construct BEEF
644
710
 
645
- #### Method toBinary
711
+ #### Method fromString
646
712
 
647
- Converts the MerklePath to a binary array format.
713
+ Constructs an instance of the Beef class based on the provided string
648
714
 
649
715
  ```ts
650
- toBinary(): number[]
716
+ static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
651
717
  ```
718
+ See also: [Beef](#class-beef)
652
719
 
653
720
  Returns
654
721
 
655
- - The binary array representation of the Merkle Path.
722
+ An instance of the Beef class constructed from the string
656
723
 
657
- #### Method toHex
724
+ Argument Details
658
725
 
659
- Converts the MerklePath to a hexadecimal string format.
726
+ + **s**
727
+ + The string value from which to construct BEEF
728
+ + **enc**
729
+ + The encoding of the string value from which BEEF should be constructed
730
+
731
+ #### Method getValidTxids
660
732
 
661
733
  ```ts
662
- toHex(): string
734
+ getValidTxids(): string[]
663
735
  ```
664
736
 
665
737
  Returns
666
738
 
667
- - The hexadecimal string representation of the Merkle Path.
739
+ array of transaction txids that either have a proof or whose inputs chain back to a proven transaction.
668
740
 
669
- #### Method trim
741
+ #### Method isValid
670
742
 
671
- Remove all internal nodes that are not required by level zero txid nodes.
672
- Assumes that at least all required nodes are present.
673
- Leaves all levels sorted by increasing offset.
743
+ Sorts `txs` and checks structural validity of beef.
744
+
745
+ Does NOT verify merkle roots.
746
+
747
+ Validity requirements:
748
+ 1. No 'known' txids, unless `allowTxidOnly` is true.
749
+ 2. All transactions have bumps or their inputs chain back to bumps (or are known).
750
+ 3. Order of transactions satisfies dependencies before dependents.
751
+ 4. No transactions with duplicate txids.
674
752
 
675
753
  ```ts
676
- trim()
754
+ isValid(allowTxidOnly?: boolean): boolean
677
755
  ```
678
756
 
679
- #### Method verify
757
+ Argument Details
680
758
 
681
- Verifies if the given transaction ID is part of the Merkle tree at the specified block height.
759
+ + **allowTxidOnly**
760
+ + optional. If true, transaction txid only is assumed valid
761
+
762
+ #### Method mergeBump
763
+
764
+ Merge a MerklePath that is assumed to be fully valid.
682
765
 
683
766
  ```ts
684
- async verify(txid: string, chainTracker: ChainTracker): Promise<boolean>
767
+ mergeBump(bump: MerklePath): number
685
768
  ```
769
+ See also: [MerklePath](#class-merklepath)
686
770
 
687
771
  Returns
688
772
 
689
- - True if the transaction ID is valid within the Merkle Path at the specified block height.
773
+ index of merged bump
774
+
775
+ #### Method mergeRawTx
776
+
777
+ Merge a serialized transaction.
778
+
779
+ Checks that a transaction with the same txid hasn't already been merged.
780
+
781
+ Replaces existing transaction with same txid.
782
+
783
+ ```ts
784
+ mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
785
+ ```
786
+ See also: [BeefTx](#class-beeftx)
787
+
788
+ Returns
789
+
790
+ txid of rawTx
690
791
 
691
792
  Argument Details
692
793
 
693
- + **txid**
694
- + The transaction ID to verify.
695
- + **chainTracker**
696
- + The ChainTracker instance used to verify the Merkle root.
794
+ + **bumpIndex**
795
+ + Optional. If a number, must be valid index into bumps array.
697
796
 
698
- </details>
797
+ #### Method mergeTransaction
699
798
 
700
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
799
+ Merge a `Transaction` and any referenced `merklePath` and `sourceTransaction`, recursifely.
701
800
 
702
- ---
703
- ### Class: NodejsHttpClient
801
+ Replaces existing transaction with same txid.
704
802
 
705
- Adapter for Node.js Https module to be used as HttpClient
803
+ Attempts to match an existing bump to the new transaction.
706
804
 
707
805
  ```ts
708
- export class NodejsHttpClient implements HttpClient {
709
- constructor(private readonly https: HttpsNodejs)
710
- async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
711
- }
806
+ mergeTransaction(tx: Transaction): BeefTx
712
807
  ```
808
+ See also: [BeefTx](#class-beeftx), [Transaction](#class-transaction)
713
809
 
714
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
810
+ Returns
715
811
 
716
- ---
717
- ### Class: FetchHttpClient
812
+ txid of tx
718
813
 
719
- Adapter for Node.js Https module to be used as HttpClient
814
+ #### Method removeExistingTxid
815
+
816
+ Removes an existing transaction from the BEEF, given its TXID
720
817
 
721
818
  ```ts
722
- export class FetchHttpClient implements HttpClient {
723
- constructor(private readonly fetch: Fetch)
724
- async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
725
- }
819
+ removeExistingTxid(txid: string)
726
820
  ```
727
821
 
728
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
822
+ Argument Details
729
823
 
730
- ---
731
- ### Class: ARC
824
+ + **txid**
825
+ + TXID of the transaction to remove
732
826
 
733
- Represents an ARC transaction broadcaster.
827
+ #### Method sortTxs
828
+
829
+ Sort the `txs` by input txid dependency order:
830
+ - Oldest Tx Anchored by Path
831
+ - Newer Txs depending on Older parents
832
+ - Newest Tx
833
+
834
+ with proof (MerklePath) last, longest chain of dependencies first
734
835
 
735
836
  ```ts
736
- export default class ARC implements Broadcaster {
737
- readonly URL: string;
738
- readonly apiKey: string | undefined;
739
- readonly deploymentId: string;
740
- readonly callbackUrl: string | undefined;
741
- readonly callbackToken: string | undefined;
742
- readonly headers: Record<string, string> | undefined;
743
- constructor(URL: string, config?: ArcConfig);
744
- constructor(URL: string, apiKey?: string);
745
- constructor(URL: string, config?: string | ArcConfig)
746
- async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
747
- }
837
+ sortTxs(): {
838
+ missingInputs: string[];
839
+ notValid: string[];
840
+ valid: string[];
841
+ withMissingInputs: string[];
842
+ txidOnly: string[];
843
+ }
748
844
  ```
749
845
 
750
- <details>
846
+ Returns
751
847
 
752
- <summary>Class ARC Details</summary>
848
+ `{ missingInputs, notValid, valid, withMissingInputs }`
753
849
 
754
- #### Constructor
850
+ #### Method toBinary
755
851
 
756
- Constructs an instance of the ARC broadcaster.
852
+ Returns a binary array representing the serialized BEEF
757
853
 
758
854
  ```ts
759
- constructor(URL: string, config?: ArcConfig)
855
+ toBinary(): number[]
760
856
  ```
761
857
 
762
- Argument Details
858
+ Returns
763
859
 
764
- + **URL**
765
- + The URL endpoint for the ARC API.
766
- + **config**
767
- + Configuration options for the ARC broadcaster.
860
+ A binary array representing the BEEF
768
861
 
769
- #### Constructor
862
+ #### Method toBinaryAtomic
770
863
 
771
- Constructs an instance of the ARC broadcaster.
864
+ Serialize this Beef as AtomicBEEF.
865
+
866
+ `txid` must exist and be the last transaction
867
+ in sorted (dependency) order.
772
868
 
773
869
  ```ts
774
- constructor(URL: string, apiKey?: string)
870
+ toBinaryAtomic(txid: string)
775
871
  ```
776
872
 
777
- Argument Details
873
+ Returns
778
874
 
779
- + **URL**
780
- + The URL endpoint for the ARC API.
781
- + **apiKey**
782
- + The API key used for authorization with the ARC API.
875
+ serialized contents of this Beef with AtomicBEEF prefix.
783
876
 
784
- #### Method broadcast
877
+ #### Method toHex
785
878
 
786
- Broadcasts a transaction via ARC.
879
+ Returns a hex string representing the serialized BEEF
787
880
 
788
881
  ```ts
789
- async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
882
+ toHex(): string
790
883
  ```
791
884
 
792
885
  Returns
793
886
 
794
- A promise that resolves to either a success or failure response.
887
+ A hex string representing the BEEF
795
888
 
796
- Argument Details
889
+ #### Method toLogString
797
890
 
798
- + **tx**
799
- + The transaction to be broadcasted.
891
+ ```ts
892
+ toLogString(): string
893
+ ```
800
894
 
801
- </details>
895
+ Returns
802
896
 
803
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
897
+ Summary of `Beef` contents as multi-line string.
804
898
 
805
- ---
806
- ### Class: WhatsOnChain
899
+ #### Method toWriter
807
900
 
808
- Represents a chain tracker based on What's On Chain .
901
+ Serializes this data to `writer`
809
902
 
810
903
  ```ts
811
- export default class WhatsOnChain implements ChainTracker {
812
- readonly network: string;
813
- readonly apiKey: string;
814
- constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
815
- async isValidRootForHeight(root: string, height: number): Promise<boolean>
816
- }
904
+ toWriter(writer: Writer)
817
905
  ```
906
+ See also: [Writer](#class-writer)
818
907
 
819
- <details>
908
+ #### Method trimKnownTxids
820
909
 
821
- <summary>Class WhatsOnChain Details</summary>
910
+ Ensure that all the txids in `knownTxids` are txidOnly
822
911
 
823
- #### Constructor
912
+ ```ts
913
+ trimKnownTxids(knownTxids: string[])
914
+ ```
824
915
 
825
- Constructs an instance of the WhatsOnChain ChainTracker.
916
+ #### Method verify
917
+
918
+ Sorts `txs` and confirms validity of transaction data contained in beef
919
+ by validating structure of this beef and confirming computed merkle roots
920
+ using `chainTracker`.
921
+
922
+ Validity requirements:
923
+ 1. No 'known' txids, unless `allowTxidOnly` is true.
924
+ 2. All transactions have bumps or their inputs chain back to bumps (or are known).
925
+ 3. Order of transactions satisfies dependencies before dependents.
926
+ 4. No transactions with duplicate txids.
826
927
 
827
928
  ```ts
828
- constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
929
+ async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
829
930
  ```
931
+ See also: [ChainTracker](#interface-chaintracker)
830
932
 
831
933
  Argument Details
832
934
 
833
- + **network**
834
- + The BSV network to use when calling the WhatsOnChain API.
835
- + **config**
836
- + Configuration options for the WhatsOnChain ChainTracker.
935
+ + **chainTracker**
936
+ + Used to verify computed merkle path roots for all bump txids.
937
+ + **allowTxidOnly**
938
+ + optional. If true, transaction txid is assumed valid
837
939
 
838
940
  </details>
839
941
 
840
942
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
841
943
 
842
944
  ---
843
- ### Class: BeefTx
945
+ ### Class: BeefParty
844
946
 
845
- A single bitcoin transaction associated with a `Beef` validity proof set.
947
+ Extends `Beef` that is used to exchange transaction validity data with more than one external party.
846
948
 
847
- Simple case is transaction data included directly, either as raw bytes or fully parsed data, or both.
949
+ Use `addKnownTxidsForParty` to keep track of who knows what to reduce re-transmission of potentially large transactions.
848
950
 
849
- Supports 'known' transactions which are represented by just their txid.
850
- It is assumed that intended consumer of this beef already has validity proof for such a transaction,
851
- which they can merge if necessary to create a valid beef.
951
+ Use `getTrimmedBeefForParty` to obtain a `Beef` trimmed of transaction validity data known to a specific party.
952
+
953
+ Typical usage scenario:
954
+
955
+ 1. Query a wallet storage provider for spendable outputs.
956
+ 2. The provider replies with a Beef validating the returned outputs.
957
+ 3. Construct a new transaction using some of the queried outputs as inputs, including Beef validating all the inputs.
958
+ 4. Receive new valid raw transaction after processing and Beef validating change outputs added to original inputs.
959
+ 5. Return to step 1, continuing to build on old and new spendable outputs.
960
+
961
+ By default, each Beef is required to be complete and valid: All transactions appear as full serialized bitcoin transactions and
962
+ each transaction either has a merkle path proof (it has been mined) or all of its input transactions are included.
963
+
964
+ The size and redundancy of these Beefs becomes a problem when chained transaction creation out-paces the block mining rate.
852
965
 
853
966
  ```ts
854
- export default class BeefTx {
855
- _bumpIndex?: number;
856
- _tx?: Transaction;
857
- _rawTx?: number[];
858
- _txid?: string;
859
- inputTxids: string[] = [];
860
- isValid?: boolean = undefined;
861
- get bumpIndex(): number | undefined
862
- set bumpIndex(v: number | undefined)
863
- get hasProof(): boolean
864
- get isTxidOnly(): boolean
865
- get txid()
866
- get tx()
867
- get rawTx()
868
- constructor(tx: Transaction | number[] | string, bumpIndex?: number)
869
- toWriter(writer: Writer, magic: number): void
870
- static fromReader(br: Reader, magic: number): BeefTx
967
+ export class BeefParty extends Beef {
968
+ knownTo: Record<string, Record<string, boolean>> = {};
969
+ constructor(parties?: string[])
970
+ isParty(party: string)
971
+ addParty(party: string)
972
+ getKnownTxidsForParty(party: string): string[]
973
+ getTrimmedBeefForParty(party: string): Beef
974
+ addKnownTxidsForParty(party: string, knownTxids: string[])
975
+ mergeBeefFromParty(party: string, beef: number[] | Beef)
871
976
  }
872
977
  ```
873
978
 
979
+ See also: [Beef](#class-beef)
980
+
874
981
  <details>
875
982
 
876
- <summary>Class BeefTx Details</summary>
983
+ <summary>Class BeefParty Details</summary>
877
984
 
878
985
  #### Constructor
879
986
 
880
987
  ```ts
881
- constructor(tx: Transaction | number[] | string, bumpIndex?: number)
988
+ constructor(parties?: string[])
882
989
  ```
883
990
 
884
991
  Argument Details
885
992
 
886
- + **tx**
887
- + If string, must be a valid txid. If `number[]` must be a valid serialized transaction.
888
- + **bumpIndex**
889
- + If transaction already has a proof in the beef to which it will be added.
993
+ + **parties**
994
+ + Optional array of initial unique party identifiers.
890
995
 
891
- #### Property isValid
996
+ #### Property knownTo
892
997
 
893
- true if `hasProof` or all inputs chain to `hasProof`.
998
+ keys are party identifiers.
999
+ values are records of txids with truthy value for which the party already has validity proof.
894
1000
 
895
- Typically set by sorting transactions by proven dependency chains.
1001
+ ```ts
1002
+ knownTo: Record<string, Record<string, boolean>> = {}
1003
+ ```
1004
+
1005
+ #### Method addKnownTxidsForParty
1006
+
1007
+ Make note of additional txids "known" to `party`.
896
1008
 
897
1009
  ```ts
898
- isValid?: boolean = undefined
1010
+ addKnownTxidsForParty(party: string, knownTxids: string[])
899
1011
  ```
900
1012
 
901
- </details>
1013
+ Argument Details
902
1014
 
903
- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1015
+ + **party**
1016
+ + unique identifier, added if new.
904
1017
 
905
- ---
906
- ### Class: Beef
1018
+ #### Method addParty
1019
+
1020
+ Adds a new unique party identifier to this `BeefParty`.
907
1021
 
908
1022
  ```ts
909
- export class Beef {
910
- bumps: MerklePath[] = [];
911
- txs: BeefTx[] = [];
912
- version: BeefVersion = undefined;
913
- atomicTxid: string | undefined = undefined;
914
- constructor(version?: BeefVersion)
915
- get magic(): number
916
- findTxid(txid: string): BeefTx | undefined
917
- findBump(txid: string): MerklePath | undefined
918
- findTransactionForSigning(txid: string): Transaction | undefined
919
- findAtomicTransaction(txid: string): Transaction | undefined
920
- mergeBump(bump: MerklePath): number
921
- mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
922
- mergeTransaction(tx: Transaction): BeefTx
923
- removeExistingTxid(txid: string)
924
- mergeTxidOnly(txid: string): BeefTx
925
- mergeBeefTx(btx: BeefTx): BeefTx
926
- mergeBeef(beef: number[] | Beef)
927
- isValid(allowTxidOnly?: boolean): boolean
928
- async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
929
- toWriter(writer: Writer)
930
- toBinary(): number[]
931
- toBinaryAtomic(txid: string)
932
- toHex(): string
933
- static fromReader(br: Reader): Beef
934
- static fromBinary(bin: number[]): Beef
935
- static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
936
- sortTxs(): {
937
- missingInputs: string[];
938
- notValid: string[];
939
- valid: string[];
940
- withMissingInputs: string[];
941
- txidOnly: string[];
942
- }
943
- clone(): Beef
944
- trimKnownTxids(knownTxids: string[])
945
- getValidTxids(): string[]
946
- toLogString(): string
947
- }
1023
+ addParty(party: string)
948
1024
  ```
949
1025
 
950
- <details>
1026
+ #### Method getKnownTxidsForParty
951
1027
 
952
- <summary>Class Beef Details</summary>
1028
+ ```ts
1029
+ getKnownTxidsForParty(party: string): string[]
1030
+ ```
953
1031
 
954
- #### Method clone
1032
+ Returns
1033
+
1034
+ Array of txids "known" to `party`.
1035
+
1036
+ #### Method getTrimmedBeefForParty
955
1037
 
956
1038
  ```ts
957
- clone(): Beef
1039
+ getTrimmedBeefForParty(party: string): Beef
958
1040
  ```
1041
+ See also: [Beef](#class-beef)
959
1042
 
960
1043
  Returns
961
1044
 
962
- a shallow copy of this beef
1045
+ trimmed beef of unknown transactions and proofs for `party`
1046
+
1047
+ #### Method isParty
1048
+
1049
+ ```ts
1050
+ isParty(party: string)
1051
+ ```
1052
+
1053
+ Returns
1054
+
1055
+ `true` if `party` has already beed added to this `BeefParty`.
1056
+
1057
+ #### Method mergeBeefFromParty
1058
+
1059
+ Merge a `beef` received from a specific `party`.
1060
+
1061
+ Updates this `BeefParty` to track all the txids
1062
+ corresponding to transactions for which `party`
1063
+ has raw transaction and validity proof data.
1064
+
1065
+ ```ts
1066
+ mergeBeefFromParty(party: string, beef: number[] | Beef)
1067
+ ```
1068
+ See also: [Beef](#class-beef)
1069
+
1070
+ </details>
1071
+
1072
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1073
+
1074
+ ---
1075
+ ### Class: BeefTx
1076
+
1077
+ A single bitcoin transaction associated with a `Beef` validity proof set.
1078
+
1079
+ Simple case is transaction data included directly, either as raw bytes or fully parsed data, or both.
1080
+
1081
+ Supports 'known' transactions which are represented by just their txid.
1082
+ It is assumed that intended consumer of this beef already has validity proof for such a transaction,
1083
+ which they can merge if necessary to create a valid beef.
1084
+
1085
+ ```ts
1086
+ export default class BeefTx {
1087
+ _bumpIndex?: number;
1088
+ _tx?: Transaction;
1089
+ _rawTx?: number[];
1090
+ _txid?: string;
1091
+ inputTxids: string[] = [];
1092
+ isValid?: boolean = undefined;
1093
+ get bumpIndex(): number | undefined
1094
+ set bumpIndex(v: number | undefined)
1095
+ get hasProof(): boolean
1096
+ get isTxidOnly(): boolean
1097
+ get txid()
1098
+ get tx()
1099
+ get rawTx()
1100
+ constructor(tx: Transaction | number[] | string, bumpIndex?: number)
1101
+ toWriter(writer: Writer, magic: number): void
1102
+ static fromReader(br: Reader, magic: number): BeefTx
1103
+ }
1104
+ ```
1105
+
1106
+ See also: [Reader](#class-reader), [Transaction](#class-transaction), [Writer](#class-writer)
963
1107
 
964
- #### Method findAtomicTransaction
1108
+ <details>
965
1109
 
966
- Builds the proof tree rooted at a specific `Transaction`.
1110
+ <summary>Class BeefTx Details</summary>
967
1111
 
968
- To succeed, the Beef must contain all the required transaction and merkle path data.
1112
+ #### Constructor
969
1113
 
970
1114
  ```ts
971
- findAtomicTransaction(txid: string): Transaction | undefined
1115
+ constructor(tx: Transaction | number[] | string, bumpIndex?: number)
972
1116
  ```
1117
+ See also: [Transaction](#class-transaction)
973
1118
 
974
- Returns
1119
+ Argument Details
975
1120
 
976
- Transaction with input `SourceTransaction` and `MerklePath` populated from this Beef.
1121
+ + **tx**
1122
+ + If string, must be a valid txid. If `number[]` must be a valid serialized transaction.
1123
+ + **bumpIndex**
1124
+ + If transaction already has a proof in the beef to which it will be added.
977
1125
 
978
- Argument Details
1126
+ #### Property isValid
979
1127
 
980
- + **txid**
981
- + The id of the target transaction.
1128
+ true if `hasProof` or all inputs chain to `hasProof`.
982
1129
 
983
- #### Method findBump
1130
+ Typically set by sorting transactions by proven dependency chains.
984
1131
 
985
1132
  ```ts
986
- findBump(txid: string): MerklePath | undefined
1133
+ isValid?: boolean = undefined
987
1134
  ```
988
1135
 
989
- Returns
990
-
991
- `MerklePath` with level zero hash equal to txid or undefined.
1136
+ </details>
992
1137
 
993
- #### Method findTransactionForSigning
1138
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
994
1139
 
995
- Finds a Transaction in this `Beef`
996
- and adds any missing input SourceTransactions from this `Beef`.
1140
+ ---
1141
+ ### Class: FetchHttpClient
997
1142
 
998
- The result is suitable for signing.
1143
+ Adapter for Node.js Https module to be used as HttpClient
999
1144
 
1000
1145
  ```ts
1001
- findTransactionForSigning(txid: string): Transaction | undefined
1146
+ export class FetchHttpClient implements HttpClient {
1147
+ constructor(private readonly fetch: Fetch)
1148
+ async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
1149
+ }
1002
1150
  ```
1003
1151
 
1004
- Returns
1152
+ See also: [Fetch](#type-fetch), [HttpClient](#interface-httpclient), [HttpClientRequestOptions](#interface-httpclientrequestoptions), [HttpClientResponse](#type-httpclientresponse)
1005
1153
 
1006
- Transaction with all available input `SourceTransaction`s from this Beef.
1154
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1007
1155
 
1008
- Argument Details
1156
+ ---
1157
+ ### Class: MerklePath
1009
1158
 
1010
- + **txid**
1011
- + The id of the target transaction.
1159
+ Represents a Merkle Path, which is used to provide a compact proof of inclusion for a
1160
+ transaction in a block. This class encapsulates all the details required for creating
1161
+ and verifying Merkle Proofs.
1012
1162
 
1013
- #### Method findTxid
1163
+ Example
1014
1164
 
1015
1165
  ```ts
1016
- findTxid(txid: string): BeefTx | undefined
1166
+ // Creating and verifying a Merkle Path
1167
+ const merklePath = MerklePath.fromHex('...');
1168
+ const isValid = merklePath.verify(txid, chainTracker);
1017
1169
  ```
1018
1170
 
1019
- Returns
1171
+ ```ts
1172
+ export default class MerklePath {
1173
+ blockHeight: number;
1174
+ path: Array<Array<{
1175
+ offset: number;
1176
+ hash?: string;
1177
+ txid?: boolean;
1178
+ duplicate?: boolean;
1179
+ }>>;
1180
+ static fromHex(hex: string): MerklePath
1181
+ static fromReader(reader: Reader): MerklePath
1182
+ static fromBinary(bump: number[]): MerklePath
1183
+ constructor(blockHeight: number, path: Array<Array<{
1184
+ offset: number;
1185
+ hash?: string;
1186
+ txid?: boolean;
1187
+ duplicate?: boolean;
1188
+ }>>)
1189
+ toBinary(): number[]
1190
+ toHex(): string
1191
+ computeRoot(txid?: string): string
1192
+ findOrComputeLeaf(height: number, offset: number): MerklePathLeaf | undefined
1193
+ async verify(txid: string, chainTracker: ChainTracker): Promise<boolean>
1194
+ combine(other: MerklePath): void
1195
+ trim()
1196
+ }
1197
+ ```
1020
1198
 
1021
- `BeefTx` in `txs` with `txid`.
1199
+ See also: [ChainTracker](#interface-chaintracker), [MerklePathLeaf](#interface-merklepathleaf), [Reader](#class-reader), [toHex](#variable-tohex), [verify](#variable-verify)
1022
1200
 
1023
- Argument Details
1201
+ <details>
1024
1202
 
1025
- + **txid**
1026
- + of `beefTx` to find
1203
+ <summary>Class MerklePath Details</summary>
1027
1204
 
1028
- #### Method fromBinary
1205
+ #### Method combine
1029
1206
 
1030
- Constructs an instance of the Beef class based on the provided binary array
1207
+ Combines this MerklePath with another to create a compound proof.
1031
1208
 
1032
1209
  ```ts
1033
- static fromBinary(bin: number[]): Beef
1210
+ combine(other: MerklePath): void
1034
1211
  ```
1212
+ See also: [MerklePath](#class-merklepath)
1035
1213
 
1036
- Returns
1214
+ Argument Details
1037
1215
 
1038
- An instance of the Beef class constructed from the binary data
1216
+ + **other**
1217
+ + Another MerklePath to combine with this path.
1039
1218
 
1040
- Argument Details
1219
+ Throws
1041
1220
 
1042
- + **bin**
1043
- + The binary array from which to construct BEEF
1221
+ - If the paths have different block heights or roots.
1044
1222
 
1045
- #### Method fromString
1223
+ #### Method computeRoot
1046
1224
 
1047
- Constructs an instance of the Beef class based on the provided string
1225
+ Computes the Merkle root from the provided transaction ID.
1048
1226
 
1049
1227
  ```ts
1050
- static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
1228
+ computeRoot(txid?: string): string
1051
1229
  ```
1052
1230
 
1053
1231
  Returns
1054
1232
 
1055
- An instance of the Beef class constructed from the string
1233
+ - The computed Merkle root as a hexadecimal string.
1056
1234
 
1057
1235
  Argument Details
1058
1236
 
1059
- + **s**
1060
- + The string value from which to construct BEEF
1061
- + **enc**
1062
- + The encoding of the string value from which BEEF should be constructed
1063
-
1064
- #### Method getValidTxids
1065
-
1066
- ```ts
1067
- getValidTxids(): string[]
1068
- ```
1069
-
1070
- Returns
1237
+ + **txid**
1238
+ + The transaction ID to compute the Merkle root for. If not provided, the root will be computed from an unspecified branch, and not all branches will be validated!
1071
1239
 
1072
- array of transaction txids that either have a proof or whose inputs chain back to a proven transaction.
1240
+ Throws
1073
1241
 
1074
- #### Method isValid
1242
+ - If the transaction ID is not part of the Merkle Path.
1075
1243
 
1076
- Sorts `txs` and checks structural validity of beef.
1244
+ #### Method findOrComputeLeaf
1077
1245
 
1078
- Does NOT verify merkle roots.
1246
+ Find leaf with `offset` at `height` or compute from level below, recursively.
1079
1247
 
1080
- Validity requirements:
1081
- 1. No 'known' txids, unless `allowTxidOnly` is true.
1082
- 2. All transactions have bumps or their inputs chain back to bumps (or are known).
1083
- 3. Order of transactions satisfies dependencies before dependents.
1084
- 4. No transactions with duplicate txids.
1248
+ Does not add computed leaves to path.
1085
1249
 
1086
1250
  ```ts
1087
- isValid(allowTxidOnly?: boolean): boolean
1251
+ findOrComputeLeaf(height: number, offset: number): MerklePathLeaf | undefined
1088
1252
  ```
1253
+ See also: [MerklePathLeaf](#interface-merklepathleaf)
1089
1254
 
1090
- Argument Details
1091
-
1092
- + **allowTxidOnly**
1093
- + optional. If true, transaction txid only is assumed valid
1094
-
1095
- #### Method mergeBump
1255
+ #### Method fromBinary
1096
1256
 
1097
- Merge a MerklePath that is assumed to be fully valid.
1257
+ Creates a MerklePath instance from a binary array.
1098
1258
 
1099
1259
  ```ts
1100
- mergeBump(bump: MerklePath): number
1260
+ static fromBinary(bump: number[]): MerklePath
1101
1261
  ```
1262
+ See also: [MerklePath](#class-merklepath)
1102
1263
 
1103
1264
  Returns
1104
1265
 
1105
- index of merged bump
1266
+ - A new MerklePath instance.
1106
1267
 
1107
- #### Method mergeRawTx
1268
+ Argument Details
1108
1269
 
1109
- Merge a serialized transaction.
1270
+ + **bump**
1271
+ + The binary array representation of the Merkle Path.
1110
1272
 
1111
- Checks that a transaction with the same txid hasn't already been merged.
1273
+ #### Method fromHex
1112
1274
 
1113
- Replaces existing transaction with same txid.
1275
+ Creates a MerklePath instance from a hexadecimal string.
1114
1276
 
1115
1277
  ```ts
1116
- mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
1278
+ static fromHex(hex: string): MerklePath
1117
1279
  ```
1280
+ See also: [MerklePath](#class-merklepath)
1118
1281
 
1119
1282
  Returns
1120
1283
 
1121
- txid of rawTx
1284
+ - A new MerklePath instance.
1122
1285
 
1123
1286
  Argument Details
1124
1287
 
1125
- + **bumpIndex**
1126
- + Optional. If a number, must be valid index into bumps array.
1127
-
1128
- #### Method mergeTransaction
1129
-
1130
- Merge a `Transaction` and any referenced `merklePath` and `sourceTransaction`, recursifely.
1288
+ + **hex**
1289
+ + The hexadecimal string representation of the Merkle Path.
1131
1290
 
1132
- Replaces existing transaction with same txid.
1291
+ #### Method toBinary
1133
1292
 
1134
- Attempts to match an existing bump to the new transaction.
1293
+ Converts the MerklePath to a binary array format.
1135
1294
 
1136
1295
  ```ts
1137
- mergeTransaction(tx: Transaction): BeefTx
1296
+ toBinary(): number[]
1138
1297
  ```
1139
1298
 
1140
1299
  Returns
1141
1300
 
1142
- txid of tx
1143
-
1144
- #### Method removeExistingTxid
1145
-
1146
- Removes an existing transaction from the BEEF, given its TXID
1147
-
1148
- ```ts
1149
- removeExistingTxid(txid: string)
1150
- ```
1151
-
1152
- Argument Details
1153
-
1154
- + **txid**
1155
- + TXID of the transaction to remove
1156
-
1157
- #### Method sortTxs
1301
+ - The binary array representation of the Merkle Path.
1158
1302
 
1159
- Sort the `txs` by input txid dependency order:
1160
- - Oldest Tx Anchored by Path
1161
- - Newer Txs depending on Older parents
1162
- - Newest Tx
1303
+ #### Method toHex
1163
1304
 
1164
- with proof (MerklePath) last, longest chain of dependencies first
1305
+ Converts the MerklePath to a hexadecimal string format.
1165
1306
 
1166
1307
  ```ts
1167
- sortTxs(): {
1168
- missingInputs: string[];
1169
- notValid: string[];
1170
- valid: string[];
1171
- withMissingInputs: string[];
1172
- txidOnly: string[];
1173
- }
1308
+ toHex(): string
1174
1309
  ```
1175
1310
 
1176
1311
  Returns
1177
1312
 
1178
- `{ missingInputs, notValid, valid, withMissingInputs }`
1313
+ - The hexadecimal string representation of the Merkle Path.
1179
1314
 
1180
- #### Method toBinary
1315
+ #### Method trim
1181
1316
 
1182
- Returns a binary array representing the serialized BEEF
1317
+ Remove all internal nodes that are not required by level zero txid nodes.
1318
+ Assumes that at least all required nodes are present.
1319
+ Leaves all levels sorted by increasing offset.
1183
1320
 
1184
1321
  ```ts
1185
- toBinary(): number[]
1322
+ trim()
1186
1323
  ```
1187
1324
 
1188
- Returns
1189
-
1190
- A binary array representing the BEEF
1191
-
1192
- #### Method toBinaryAtomic
1193
-
1194
- Serialize this Beef as AtomicBEEF.
1325
+ #### Method verify
1195
1326
 
1196
- `txid` must exist and be the last transaction
1197
- in sorted (dependency) order.
1327
+ Verifies if the given transaction ID is part of the Merkle tree at the specified block height.
1198
1328
 
1199
1329
  ```ts
1200
- toBinaryAtomic(txid: string)
1330
+ async verify(txid: string, chainTracker: ChainTracker): Promise<boolean>
1201
1331
  ```
1332
+ See also: [ChainTracker](#interface-chaintracker)
1202
1333
 
1203
1334
  Returns
1204
1335
 
1205
- serialized contents of this Beef with AtomicBEEF prefix.
1336
+ - True if the transaction ID is valid within the Merkle Path at the specified block height.
1206
1337
 
1207
- #### Method toHex
1338
+ Argument Details
1208
1339
 
1209
- Returns a hex string representing the serialized BEEF
1340
+ + **txid**
1341
+ + The transaction ID to verify.
1342
+ + **chainTracker**
1343
+ + The ChainTracker instance used to verify the Merkle root.
1210
1344
 
1211
- ```ts
1212
- toHex(): string
1213
- ```
1345
+ </details>
1214
1346
 
1215
- Returns
1347
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1216
1348
 
1217
- A hex string representing the BEEF
1349
+ ---
1350
+ ### Class: NodejsHttpClient
1218
1351
 
1219
- #### Method toLogString
1352
+ Adapter for Node.js Https module to be used as HttpClient
1220
1353
 
1221
1354
  ```ts
1222
- toLogString(): string
1355
+ export class NodejsHttpClient implements HttpClient {
1356
+ constructor(private readonly https: HttpsNodejs)
1357
+ async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
1358
+ }
1223
1359
  ```
1224
1360
 
1225
- Returns
1361
+ See also: [HttpClient](#interface-httpclient), [HttpClientRequestOptions](#interface-httpclientrequestoptions), [HttpClientResponse](#type-httpclientresponse), [HttpsNodejs](#interface-httpsnodejs)
1226
1362
 
1227
- Summary of `Beef` contents as multi-line string.
1363
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1228
1364
 
1229
- #### Method toWriter
1365
+ ---
1366
+ ### Class: SatoshisPerKilobyte
1230
1367
 
1231
- Serializes this data to `writer`
1368
+ Represents the "satoshis per kilobyte" transaction fee model.
1232
1369
 
1233
1370
  ```ts
1234
- toWriter(writer: Writer)
1371
+ export default class SatoshisPerKilobyte implements FeeModel {
1372
+ value: number;
1373
+ constructor(value: number)
1374
+ async computeFee(tx: Transaction): Promise<number>
1375
+ }
1235
1376
  ```
1236
1377
 
1237
- #### Method trimKnownTxids
1378
+ See also: [FeeModel](#interface-feemodel), [Transaction](#class-transaction)
1238
1379
 
1239
- Ensure that all the txids in `knownTxids` are txidOnly
1380
+ <details>
1381
+
1382
+ <summary>Class SatoshisPerKilobyte Details</summary>
1383
+
1384
+ #### Constructor
1385
+
1386
+ Constructs an instance of the sat/kb fee model.
1240
1387
 
1241
1388
  ```ts
1242
- trimKnownTxids(knownTxids: string[])
1389
+ constructor(value: number)
1243
1390
  ```
1244
1391
 
1245
- #### Method verify
1392
+ Argument Details
1246
1393
 
1247
- Sorts `txs` and confirms validity of transaction data contained in beef
1248
- by validating structure of this beef and confirming computed merkle roots
1249
- using `chainTracker`.
1394
+ + **value**
1395
+ + The number of satoshis per kilobyte to charge as a fee.
1250
1396
 
1251
- Validity requirements:
1252
- 1. No 'known' txids, unless `allowTxidOnly` is true.
1253
- 2. All transactions have bumps or their inputs chain back to bumps (or are known).
1254
- 3. Order of transactions satisfies dependencies before dependents.
1255
- 4. No transactions with duplicate txids.
1397
+ #### Method computeFee
1398
+
1399
+ Computes the fee for a given transaction.
1256
1400
 
1257
1401
  ```ts
1258
- async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
1402
+ async computeFee(tx: Transaction): Promise<number>
1259
1403
  ```
1404
+ See also: [Transaction](#class-transaction)
1405
+
1406
+ Returns
1407
+
1408
+ The fee in satoshis for the transaction, as a BigNumber.
1260
1409
 
1261
1410
  Argument Details
1262
1411
 
1263
- + **chainTracker**
1264
- + Used to verify computed merkle path roots for all bump txids.
1265
- + **allowTxidOnly**
1266
- + optional. If true, transaction txid is assumed valid
1412
+ + **tx**
1413
+ + The transaction for which a fee is to be computed.
1267
1414
 
1268
1415
  </details>
1269
1416
 
@@ -1340,6 +1487,8 @@ export default class Transaction {
1340
1487
  }
1341
1488
  ```
1342
1489
 
1490
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse), [Broadcaster](#interface-broadcaster), [ChainTracker](#interface-chaintracker), [FeeModel](#interface-feemodel), [MerklePath](#class-merklepath), [Reader](#class-reader), [TransactionInput](#interface-transactioninput), [TransactionOutput](#interface-transactionoutput), [defaultBroadcaster](#function-defaultbroadcaster), [defaultChainTracker](#function-defaultchaintracker), [sign](#variable-sign), [toHex](#variable-tohex), [verify](#variable-verify)
1491
+
1343
1492
  <details>
1344
1493
 
1345
1494
  <summary>Class Transaction Details</summary>
@@ -1351,6 +1500,7 @@ Adds a new input to the transaction.
1351
1500
  ```ts
1352
1501
  addInput(input: TransactionInput): void
1353
1502
  ```
1503
+ See also: [TransactionInput](#interface-transactioninput)
1354
1504
 
1355
1505
  Argument Details
1356
1506
 
@@ -1368,6 +1518,7 @@ Adds a new output to the transaction.
1368
1518
  ```ts
1369
1519
  addOutput(output: TransactionOutput): void
1370
1520
  ```
1521
+ See also: [TransactionOutput](#interface-transactionoutput)
1371
1522
 
1372
1523
  Argument Details
1373
1524
 
@@ -1381,6 +1532,7 @@ Broadcasts a transaction.
1381
1532
  ```ts
1382
1533
  async broadcast(broadcaster: Broadcaster = defaultBroadcaster()): Promise<BroadcastResponse | BroadcastFailure>
1383
1534
  ```
1535
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse), [Broadcaster](#interface-broadcaster), [defaultBroadcaster](#function-defaultbroadcaster)
1384
1536
 
1385
1537
  Returns
1386
1538
 
@@ -1400,6 +1552,7 @@ If fee is a number, the transaction uses that value as fee.
1400
1552
  ```ts
1401
1553
  async fee(modelOrFee?: FeeModel | number, changeDistribution: "equal" | "random" = "equal"): Promise<void>
1402
1554
  ```
1555
+ See also: [FeeModel](#interface-feemodel)
1403
1556
 
1404
1557
  Argument Details
1405
1558
 
@@ -1421,6 +1574,7 @@ Throws errors if the Atomic BEEF data does not strictly adhere to the BRC-95 spe
1421
1574
  ```ts
1422
1575
  static fromAtomicBEEF(beef: number[]): Transaction
1423
1576
  ```
1577
+ See also: [Transaction](#class-transaction)
1424
1578
 
1425
1579
  Returns
1426
1580
 
@@ -1441,6 +1595,7 @@ If no TXID is provided, the last transaction in the BEEF data is returned.
1441
1595
  ```ts
1442
1596
  static fromBEEF(beef: number[], txid?: string): Transaction
1443
1597
  ```
1598
+ See also: [Transaction](#class-transaction)
1444
1599
 
1445
1600
  Returns
1446
1601
 
@@ -1460,6 +1615,7 @@ Creates a Transaction instance from a binary array.
1460
1615
  ```ts
1461
1616
  static fromBinary(bin: number[]): Transaction
1462
1617
  ```
1618
+ See also: [Transaction](#class-transaction)
1463
1619
 
1464
1620
  Returns
1465
1621
 
@@ -1477,6 +1633,7 @@ Creates a new transaction, linked to its inputs and their associated merkle path
1477
1633
  ```ts
1478
1634
  static fromEF(ef: number[]): Transaction
1479
1635
  ```
1636
+ See also: [Transaction](#class-transaction)
1480
1637
 
1481
1638
  Returns
1482
1639
 
@@ -1494,6 +1651,7 @@ Creates a Transaction instance from a hexadecimal string.
1494
1651
  ```ts
1495
1652
  static fromHex(hex: string): Transaction
1496
1653
  ```
1654
+ See also: [Transaction](#class-transaction)
1497
1655
 
1498
1656
  Returns
1499
1657
 
@@ -1514,6 +1672,7 @@ If no TXID is provided, the last transaction in the BEEF data is returned.
1514
1672
  ```ts
1515
1673
  static fromHexBEEF(hex: string, txid?: string): Transaction
1516
1674
  ```
1675
+ See also: [Transaction](#class-transaction)
1517
1676
 
1518
1677
  Returns
1519
1678
 
@@ -1533,6 +1692,7 @@ Creates a Transaction instance from a hexadecimal string encoded EF.
1533
1692
  ```ts
1534
1693
  static fromHexEF(hex: string): Transaction
1535
1694
  ```
1695
+ See also: [Transaction](#class-transaction)
1536
1696
 
1537
1697
  Returns
1538
1698
 
@@ -1799,6 +1959,7 @@ Verifies the legitimacy of the Bitcoin transaction according to the rules of SPV
1799
1959
  ```ts
1800
1960
  async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel): Promise<boolean>
1801
1961
  ```
1962
+ See also: [ChainTracker](#interface-chaintracker), [FeeModel](#interface-feemodel), [defaultChainTracker](#function-defaultchaintracker)
1802
1963
 
1803
1964
  Returns
1804
1965
 
@@ -1820,126 +1981,40 @@ tx.verify(new WhatsOnChain(), new SatoshisPerKilobyte(1))
1820
1981
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1821
1982
 
1822
1983
  ---
1823
- ### Class: BeefParty
1824
-
1825
- Extends `Beef` that is used to exchange transaction validity data with more than one external party.
1826
-
1827
- Use `addKnownTxidsForParty` to keep track of who knows what to reduce re-transmission of potentially large transactions.
1828
-
1829
- Use `getTrimmedBeefForParty` to obtain a `Beef` trimmed of transaction validity data known to a specific party.
1830
-
1831
- Typical usage scenario:
1832
-
1833
- 1. Query a wallet storage provider for spendable outputs.
1834
- 2. The provider replies with a Beef validating the returned outputs.
1835
- 3. Construct a new transaction using some of the queried outputs as inputs, including Beef validating all the inputs.
1836
- 4. Receive new valid raw transaction after processing and Beef validating change outputs added to original inputs.
1837
- 5. Return to step 1, continuing to build on old and new spendable outputs.
1838
-
1839
- By default, each Beef is required to be complete and valid: All transactions appear as full serialized bitcoin transactions and
1840
- each transaction either has a merkle path proof (it has been mined) or all of its input transactions are included.
1984
+ ### Class: WhatsOnChain
1841
1985
 
1842
- The size and redundancy of these Beefs becomes a problem when chained transaction creation out-paces the block mining rate.
1986
+ Represents a chain tracker based on What's On Chain .
1843
1987
 
1844
1988
  ```ts
1845
- export class BeefParty extends Beef {
1846
- knownTo: Record<string, Record<string, boolean>> = {};
1847
- constructor(parties?: string[])
1848
- isParty(party: string)
1849
- addParty(party: string)
1850
- getKnownTxidsForParty(party: string): string[]
1851
- getTrimmedBeefForParty(party: string): Beef
1852
- addKnownTxidsForParty(party: string, knownTxids: string[])
1853
- mergeBeefFromParty(party: string, beef: number[] | Beef)
1989
+ export default class WhatsOnChain implements ChainTracker {
1990
+ readonly network: string;
1991
+ readonly apiKey: string;
1992
+ constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
1993
+ async isValidRootForHeight(root: string, height: number): Promise<boolean>
1854
1994
  }
1855
1995
  ```
1856
1996
 
1997
+ See also: [ChainTracker](#interface-chaintracker), [WhatsOnChainConfig](#interface-whatsonchainconfig)
1998
+
1857
1999
  <details>
1858
2000
 
1859
- <summary>Class BeefParty Details</summary>
2001
+ <summary>Class WhatsOnChain Details</summary>
1860
2002
 
1861
2003
  #### Constructor
1862
2004
 
1863
- ```ts
1864
- constructor(parties?: string[])
1865
- ```
1866
-
1867
- Argument Details
1868
-
1869
- + **parties**
1870
- + Optional array of initial unique party identifiers.
1871
-
1872
- #### Property knownTo
1873
-
1874
- keys are party identifiers.
1875
- values are records of txids with truthy value for which the party already has validity proof.
1876
-
1877
- ```ts
1878
- knownTo: Record<string, Record<string, boolean>> = {}
1879
- ```
1880
-
1881
- #### Method addKnownTxidsForParty
1882
-
1883
- Make note of additional txids "known" to `party`.
2005
+ Constructs an instance of the WhatsOnChain ChainTracker.
1884
2006
 
1885
2007
  ```ts
1886
- addKnownTxidsForParty(party: string, knownTxids: string[])
2008
+ constructor(network: "main" | "test" | "stn" = "main", config: WhatsOnChainConfig = {})
1887
2009
  ```
2010
+ See also: [WhatsOnChainConfig](#interface-whatsonchainconfig)
1888
2011
 
1889
2012
  Argument Details
1890
2013
 
1891
- + **party**
1892
- + unique identifier, added if new.
1893
-
1894
- #### Method addParty
1895
-
1896
- Adds a new unique party identifier to this `BeefParty`.
1897
-
1898
- ```ts
1899
- addParty(party: string)
1900
- ```
1901
-
1902
- #### Method getKnownTxidsForParty
1903
-
1904
- ```ts
1905
- getKnownTxidsForParty(party: string): string[]
1906
- ```
1907
-
1908
- Returns
1909
-
1910
- Array of txids "known" to `party`.
1911
-
1912
- #### Method getTrimmedBeefForParty
1913
-
1914
- ```ts
1915
- getTrimmedBeefForParty(party: string): Beef
1916
- ```
1917
-
1918
- Returns
1919
-
1920
- trimmed beef of unknown transactions and proofs for `party`
1921
-
1922
- #### Method isParty
1923
-
1924
- ```ts
1925
- isParty(party: string)
1926
- ```
1927
-
1928
- Returns
1929
-
1930
- `true` if `party` has already beed added to this `BeefParty`.
1931
-
1932
- #### Method mergeBeefFromParty
1933
-
1934
- Merge a `beef` received from a specific `party`.
1935
-
1936
- Updates this `BeefParty` to track all the txids
1937
- corresponding to transactions for which `party`
1938
- has raw transaction and validity proof data.
1939
-
1940
- ```ts
1941
- mergeBeefFromParty(party: string, beef: number[] | Beef)
1942
- ```
2014
+ + **network**
2015
+ + The BSV network to use when calling the WhatsOnChain API.
2016
+ + **config**
2017
+ + Configuration options for the WhatsOnChain ChainTracker.
1943
2018
 
1944
2019
  </details>
1945
2020
 
@@ -1960,25 +2035,25 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
1960
2035
 
1961
2036
  ---
1962
2037
 
1963
- ### Function: isBroadcastResponse
1964
-
1965
- Convenience type guard for response from `Broadcaster.broadcast`
2038
+ ### Function: defaultBroadcaster
1966
2039
 
1967
2040
  ```ts
1968
- export function isBroadcastResponse(r: BroadcastResponse | BroadcastFailure): r is BroadcastResponse
2041
+ export function defaultBroadcaster(): Broadcaster
1969
2042
  ```
1970
2043
 
2044
+ See also: [Broadcaster](#interface-broadcaster)
2045
+
1971
2046
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1972
2047
 
1973
2048
  ---
1974
- ### Function: isBroadcastFailure
1975
-
1976
- Convenience type guard for response from `Broadcaster.broadcast`
2049
+ ### Function: defaultChainTracker
1977
2050
 
1978
2051
  ```ts
1979
- export function isBroadcastFailure(r: BroadcastResponse | BroadcastFailure): r is BroadcastFailure
2052
+ export function defaultChainTracker(): ChainTracker
1980
2053
  ```
1981
2054
 
2055
+ See also: [ChainTracker](#interface-chaintracker)
2056
+
1982
2057
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1983
2058
 
1984
2059
  ---
@@ -1992,24 +2067,34 @@ If running in a Node.js environment, it falls back to using the Node.js `https`
1992
2067
  export function defaultHttpClient(): HttpClient
1993
2068
  ```
1994
2069
 
2070
+ See also: [HttpClient](#interface-httpclient)
2071
+
1995
2072
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
1996
2073
 
1997
2074
  ---
1998
- ### Function: defaultBroadcaster
2075
+ ### Function: isBroadcastFailure
2076
+
2077
+ Convenience type guard for response from `Broadcaster.broadcast`
1999
2078
 
2000
2079
  ```ts
2001
- export function defaultBroadcaster(): Broadcaster
2080
+ export function isBroadcastFailure(r: BroadcastResponse | BroadcastFailure): r is BroadcastFailure
2002
2081
  ```
2003
2082
 
2083
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse)
2084
+
2004
2085
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2005
2086
 
2006
2087
  ---
2007
- ### Function: defaultChainTracker
2088
+ ### Function: isBroadcastResponse
2089
+
2090
+ Convenience type guard for response from `Broadcaster.broadcast`
2008
2091
 
2009
2092
  ```ts
2010
- export function defaultChainTracker(): ChainTracker
2093
+ export function isBroadcastResponse(r: BroadcastResponse | BroadcastFailure): r is BroadcastResponse
2011
2094
  ```
2012
2095
 
2096
+ See also: [BroadcastFailure](#interface-broadcastfailure), [BroadcastResponse](#interface-broadcastresponse)
2097
+
2013
2098
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2014
2099
 
2015
2100
  ---
@@ -2025,22 +2110,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
2025
2110
 
2026
2111
  ---
2027
2112
 
2028
- ### Type: HttpClientResponse
2029
-
2030
- An interface for the response returned by the request method.
2113
+ ### Type: BeefVersion
2031
2114
 
2032
2115
  ```ts
2033
- export type HttpClientResponse<T = any> = {
2034
- data: T;
2035
- status: number;
2036
- statusText: string;
2037
- ok: true;
2038
- } | {
2039
- data: any;
2040
- status: number;
2041
- statusText: string;
2042
- ok: false;
2043
- }
2116
+ export type BeefVersion = undefined | "V1" | "V2"
2044
2117
  ```
2045
2118
 
2046
2119
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -2056,13 +2129,27 @@ Makes a request to the server.
2056
2129
  export type Fetch = (url: string, options: FetchOptions) => Promise<Response>
2057
2130
  ```
2058
2131
 
2132
+ See also: [FetchOptions](#interface-fetchoptions)
2133
+
2059
2134
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2060
2135
 
2061
2136
  ---
2062
- ### Type: BeefVersion
2137
+ ### Type: HttpClientResponse
2138
+
2139
+ An interface for the response returned by the request method.
2063
2140
 
2064
2141
  ```ts
2065
- export type BeefVersion = undefined | "V1" | "V2"
2142
+ export type HttpClientResponse<T = any> = {
2143
+ data: T;
2144
+ status: number;
2145
+ statusText: string;
2146
+ ok: true;
2147
+ } | {
2148
+ data: any;
2149
+ status: number;
2150
+ statusText: string;
2151
+ ok: false;
2152
+ }
2066
2153
  ```
2067
2154
 
2068
2155
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -2081,19 +2168,19 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
2081
2168
 
2082
2169
  ---
2083
2170
 
2084
- ### Variable: BEEF_MAGIC
2171
+ ### Variable: ATOMIC_BEEF
2085
2172
 
2086
2173
  ```ts
2087
- BEEF_MAGIC = 4022206465
2174
+ ATOMIC_BEEF = 16843009
2088
2175
  ```
2089
2176
 
2090
2177
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2091
2178
 
2092
2179
  ---
2093
- ### Variable: BEEF_MAGIC_V2
2180
+ ### Variable: BEEF_MAGIC
2094
2181
 
2095
2182
  ```ts
2096
- BEEF_MAGIC_V2 = 4022206466
2183
+ BEEF_MAGIC = 4022206465
2097
2184
  ```
2098
2185
 
2099
2186
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -2108,10 +2195,10 @@ BEEF_MAGIC_TXID_ONLY_EXTENSION = 4022206465
2108
2195
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2109
2196
 
2110
2197
  ---
2111
- ### Variable: ATOMIC_BEEF
2198
+ ### Variable: BEEF_MAGIC_V2
2112
2199
 
2113
2200
  ```ts
2114
- ATOMIC_BEEF = 16843009
2201
+ BEEF_MAGIC_V2 = 4022206466
2115
2202
  ```
2116
2203
 
2117
2204
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)