@bsv/sdk 1.2.3 → 1.2.5

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 (82) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/auth/Certificate.js +1 -1
  3. package/dist/cjs/src/auth/Certificate.js.map +1 -1
  4. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  5. package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  6. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +1 -1
  7. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  8. package/dist/cjs/src/transaction/Beef.js +19 -10
  9. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  10. package/dist/cjs/src/transaction/Transaction.js +38 -6
  11. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  12. package/dist/cjs/src/transaction/broadcasters/ARC.js +57 -17
  13. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  14. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js +2 -2
  15. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  16. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  17. package/dist/cjs/src/wallet/KeyDeriver.js.map +1 -1
  18. package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
  19. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  20. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  21. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  22. package/dist/esm/src/auth/Certificate.js +1 -1
  23. package/dist/esm/src/auth/Certificate.js.map +1 -1
  24. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  25. package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  26. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +1 -1
  27. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  28. package/dist/esm/src/transaction/Beef.js +19 -10
  29. package/dist/esm/src/transaction/Beef.js.map +1 -1
  30. package/dist/esm/src/transaction/Transaction.js +38 -6
  31. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  32. package/dist/esm/src/transaction/broadcasters/ARC.js +57 -17
  33. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  34. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +2 -2
  35. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  36. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  37. package/dist/esm/src/wallet/KeyDeriver.js.map +1 -1
  38. package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
  39. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  40. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  41. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  42. package/dist/types/src/auth/Certificate.d.ts.map +1 -1
  43. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  44. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts.map +1 -1
  45. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  46. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  47. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  48. package/dist/types/src/transaction/broadcasters/ARC.d.ts +12 -1
  49. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  50. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +2 -1
  51. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  52. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  53. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  54. package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
  55. package/dist/types/src/wallet/Wallet.interfaces.d.ts +11 -11
  56. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  57. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  58. package/dist/types/src/wallet/WalletError.d.ts.map +1 -1
  59. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  60. package/dist/umd/bundle.js +1 -1
  61. package/docs/transaction.md +22 -2
  62. package/docs/wallet.md +11 -11
  63. package/package.json +1 -1
  64. package/src/auth/Certificate.ts +9 -9
  65. package/src/auth/index.ts +1 -1
  66. package/src/overlay-tools/LookupResolver.ts +7 -7
  67. package/src/overlay-tools/OverlayAdminTokenTemplate.ts +4 -4
  68. package/src/overlay-tools/SHIPBroadcaster.ts +9 -9
  69. package/src/overlay-tools/index.ts +1 -1
  70. package/src/transaction/Beef.ts +33 -48
  71. package/src/transaction/BeefParty.ts +4 -4
  72. package/src/transaction/BeefTx.ts +1 -1
  73. package/src/transaction/Transaction.ts +38 -10
  74. package/src/transaction/__tests/Transaction.test.ts +133 -4
  75. package/src/transaction/broadcasters/ARC.ts +72 -27
  76. package/src/transaction/broadcasters/DefaultBroadcaster.ts +4 -4
  77. package/src/wallet/CachedKeyDeriver.ts +10 -10
  78. package/src/wallet/KeyDeriver.ts +8 -8
  79. package/src/wallet/ProtoWallet.ts +176 -176
  80. package/src/wallet/Wallet.interfaces.ts +19 -19
  81. package/src/wallet/WalletClient.ts +30 -30
  82. package/src/wallet/WalletError.ts +2 -2
@@ -498,6 +498,7 @@ export default class ARC implements Broadcaster {
498
498
  constructor(URL: string, apiKey?: string);
499
499
  constructor(URL: string, config?: string | ArcConfig)
500
500
  async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
501
+ async broadcastMany(txs: Transaction[]): Promise<Array<object>>
501
502
  }
502
503
  ```
503
504
 
@@ -556,6 +557,25 @@ Argument Details
556
557
  + **tx**
557
558
  + The transaction to be broadcasted.
558
559
 
560
+ #### Method broadcastMany
561
+
562
+ Broadcasts multiple transactions via ARC.
563
+ Handles mixed responses where some transactions succeed and others fail.
564
+
565
+ ```ts
566
+ async broadcastMany(txs: Transaction[]): Promise<Array<object>>
567
+ ```
568
+ See also: [Transaction](#class-transaction)
569
+
570
+ Returns
571
+
572
+ A promise that resolves to an array of objects.
573
+
574
+ Argument Details
575
+
576
+ + **txs**
577
+ + Array of transactions to be broadcasted.
578
+
559
579
  </details>
560
580
 
561
581
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -2038,10 +2058,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
2038
2058
  ### Function: defaultBroadcaster
2039
2059
 
2040
2060
  ```ts
2041
- export function defaultBroadcaster(): Broadcaster
2061
+ export function defaultBroadcaster(isTestnet: boolean = false, config: ArcConfig = {}): Broadcaster
2042
2062
  ```
2043
2063
 
2044
- See also: [Broadcaster](#interface-broadcaster)
2064
+ See also: [ArcConfig](#interface-arcconfig), [Broadcaster](#interface-broadcaster)
2045
2065
 
2046
2066
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
2047
2067
 
package/docs/wallet.md CHANGED
@@ -111,8 +111,8 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
111
111
  export interface CreateActionArgs {
112
112
  description: DescriptionString5to50Bytes;
113
113
  inputBEEF?: BEEF;
114
- inputs?: Array<CreateActionInput>;
115
- outputs?: Array<CreateActionOutput>;
114
+ inputs?: CreateActionInput[];
115
+ outputs?: CreateActionOutput[];
116
116
  lockTime?: PositiveIntegerOrZero;
117
117
  version?: PositiveIntegerOrZero;
118
118
  labels?: LabelStringUnder300Bytes[];
@@ -188,7 +188,7 @@ export interface CreateActionResult {
188
188
  txid?: TXIDHexString;
189
189
  tx?: AtomicBEEF;
190
190
  noSendChange?: OutpointString[];
191
- sendWithResults?: Array<SendWithResult>;
191
+ sendWithResults?: SendWithResult[];
192
192
  signableTransaction?: SignableTransaction;
193
193
  }
194
194
  ```
@@ -262,7 +262,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
262
262
  ```ts
263
263
  export interface DiscoverCertificatesResult {
264
264
  totalCertificates: PositiveIntegerOrZero;
265
- certificates: Array<IdentityCertificate>;
265
+ certificates: IdentityCertificate[];
266
266
  }
267
267
  ```
268
268
 
@@ -325,7 +325,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
325
325
  ```ts
326
326
  export interface InternalizeActionArgs {
327
327
  tx: AtomicBEEF;
328
- outputs: Array<InternalizeOutput>;
328
+ outputs: InternalizeOutput[];
329
329
  description: DescriptionString5to50Bytes;
330
330
  labels?: LabelStringUnder300Bytes[];
331
331
  seekPermission?: BooleanDefaultTrue;
@@ -426,7 +426,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
426
426
  ```ts
427
427
  export interface ListActionsResult {
428
428
  totalActions: PositiveIntegerOrZero;
429
- actions: Array<WalletAction>;
429
+ actions: WalletAction[];
430
430
  }
431
431
  ```
432
432
 
@@ -458,7 +458,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
458
458
  ```ts
459
459
  export interface ListCertificatesResult {
460
460
  totalCertificates: PositiveIntegerOrZero;
461
- certificates: Array<WalletCertificate>;
461
+ certificates: WalletCertificate[];
462
462
  }
463
463
  ```
464
464
 
@@ -495,7 +495,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
495
495
  export interface ListOutputsResult {
496
496
  totalOutputs: PositiveIntegerOrZero;
497
497
  BEEF?: BEEF;
498
- outputs: Array<WalletOutput>;
498
+ outputs: WalletOutput[];
499
499
  }
500
500
  ```
501
501
 
@@ -657,7 +657,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
657
657
  export interface SignActionResult {
658
658
  txid?: TXIDHexString;
659
659
  tx?: AtomicBEEF;
660
- sendWithResults?: Array<SendWithResult>;
660
+ sendWithResults?: SendWithResult[];
661
661
  }
662
662
  ```
663
663
 
@@ -1116,8 +1116,8 @@ export interface WalletAction {
1116
1116
  labels?: LabelStringUnder300Bytes[];
1117
1117
  version: PositiveIntegerOrZero;
1118
1118
  lockTime: PositiveIntegerOrZero;
1119
- inputs?: Array<WalletActionInput>;
1120
- outputs?: Array<WalletActionOutput>;
1119
+ inputs?: WalletActionInput[];
1120
+ outputs?: WalletActionOutput[];
1121
1121
  }
1122
1122
  ```
1123
1123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -54,14 +54,14 @@ export default class Certificate {
54
54
  * @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - All the fields present in the certificate.
55
55
  * @param {HexString} signature - Certificate signature by the certifier's private key, DER encoded hex string.
56
56
  */
57
- constructor(
57
+ constructor (
58
58
  type: Base64String,
59
59
  serialNumber: Base64String,
60
60
  subject: PubKeyHex,
61
61
  certifier: PubKeyHex,
62
62
  revocationOutpoint: OutpointString,
63
63
  fields: Record<CertificateFieldNameUnder50Bytes, string>,
64
- signature?: HexString,
64
+ signature?: HexString
65
65
  ) {
66
66
  this.type = type
67
67
  this.serialNumber = serialNumber
@@ -78,7 +78,7 @@ export default class Certificate {
78
78
  * @param {boolean} [includeSignature=true] - Whether to include the signature in the serialization.
79
79
  * @returns {number[]} - The serialized certificate in binary format.
80
80
  */
81
- toBin(includeSignature: boolean = true): number[] {
81
+ toBin (includeSignature: boolean = true): number[] {
82
82
  const writer = new Utils.Writer()
83
83
 
84
84
  // Write type (Base64String, 32 bytes)
@@ -134,7 +134,7 @@ export default class Certificate {
134
134
  * @param {number[]} bin - The binary data representing the certificate.
135
135
  * @returns {Certificate} - The deserialized Certificate object.
136
136
  */
137
- static fromBin(bin: number[]): Certificate {
137
+ static fromBin (bin: number[]): Certificate {
138
138
  const reader = new Utils.Reader(bin)
139
139
 
140
140
  // Read type
@@ -166,7 +166,7 @@ export default class Certificate {
166
166
  // Field name
167
167
  const fieldNameLength = reader.readVarIntNum()
168
168
  const fieldNameBytes = reader.read(fieldNameLength)
169
- const fieldName = Utils.toUTF8(fieldNameBytes) as CertificateFieldNameUnder50Bytes
169
+ const fieldName = Utils.toUTF8(fieldNameBytes)
170
170
 
171
171
  // Field value
172
172
  const fieldValueLength = reader.readVarIntNum()
@@ -177,7 +177,7 @@ export default class Certificate {
177
177
  }
178
178
 
179
179
  // Read signature if present
180
- let signature: string | undefined = undefined
180
+ let signature: string | undefined
181
181
  if (!reader.eof()) {
182
182
  const signatureLength = reader.readVarIntNum()
183
183
  const signatureBytes = reader.read(signatureLength)
@@ -200,7 +200,7 @@ export default class Certificate {
200
200
  *
201
201
  * @returns {Promise<boolean>} - A promise that resolves to true if the signature is valid.
202
202
  */
203
- async verify(): Promise<boolean> {
203
+ async verify (): Promise<boolean> {
204
204
  // A verifier can be any wallet capable of verifying signatures
205
205
  const verifier = new ProtoWallet('anyone')
206
206
  const verificationData = this.toBin(false) // Exclude the signature from the verification data
@@ -221,7 +221,7 @@ export default class Certificate {
221
221
  * @param {Wallet} certifier - The wallet representing the certifier.
222
222
  * @returns {Promise<void>}
223
223
  */
224
- async sign(certifier: Wallet): Promise<void> {
224
+ async sign (certifier: Wallet): Promise<void> {
225
225
  const preimage = this.toBin(false) // Exclude the signature when signing
226
226
  const { signature } = await certifier.createSignature({
227
227
  data: preimage,
@@ -230,4 +230,4 @@ export default class Certificate {
230
230
  })
231
231
  this.signature = Utils.toHex(signature)
232
232
  }
233
- }
233
+ }
package/src/auth/index.ts CHANGED
@@ -1 +1 @@
1
- export { default as Certificate } from './Certificate.js'
1
+ export { default as Certificate } from './Certificate.js'
@@ -70,7 +70,7 @@ export interface OverlayLookupFacilitator {
70
70
  * @param url - Overlay Service URL to send the lookup question to.
71
71
  * @param question - Lookup question to find an answer to.
72
72
  * @param timeout - Specifics how long to wait for a lookup answer in milliseconds.
73
- * @returns
73
+ * @returns
74
74
  */
75
75
  lookup: (url: string, question: LookupQuestion, timeout?: number) => Promise<LookupAnswer>
76
76
  }
@@ -78,11 +78,11 @@ export interface OverlayLookupFacilitator {
78
78
  export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
79
79
  fetchClient: typeof fetch
80
80
 
81
- constructor(httpClient = fetch) {
81
+ constructor (httpClient = fetch) {
82
82
  this.fetchClient = httpClient
83
83
  }
84
84
 
85
- async lookup(url: string, question: LookupQuestion, timeout: number = 5000): Promise<LookupAnswer> {
85
+ async lookup (url: string, question: LookupQuestion, timeout: number = 5000): Promise<LookupAnswer> {
86
86
  if (!url.startsWith('https:')) {
87
87
  throw new Error('HTTPS facilitator can only use URLs that start with "https:"')
88
88
  }
@@ -98,7 +98,7 @@ export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
98
98
  body: JSON.stringify({ service: question.service, query: question.query })
99
99
  })
100
100
 
101
- const response: Response = await Promise.race([fetchPromise, timeoutPromise]) as unknown as Response
101
+ const response: Response = await Promise.race([fetchPromise, timeoutPromise]) as Response
102
102
 
103
103
  if (response.ok) {
104
104
  return await response.json()
@@ -117,7 +117,7 @@ export default class LookupResolver {
117
117
  private readonly hostOverrides: Record<string, string[]>
118
118
  private readonly additionalHosts: Record<string, string[]>
119
119
 
120
- constructor(config?: LookupResolverConfig) {
120
+ constructor (config?: LookupResolverConfig) {
121
121
  const { facilitator, slapTrackers, hostOverrides, additionalHosts } = config ?? {} as LookupResolverConfig
122
122
  this.facilitator = facilitator ?? new HTTPSOverlayLookupFacilitator()
123
123
  this.slapTrackers = slapTrackers ?? DEFAULT_SLAP_TRACKERS
@@ -128,7 +128,7 @@ export default class LookupResolver {
128
128
  /**
129
129
  * Given a LookupQuestion, returns a LookupAnswer. Aggregates across multiple services and supports resiliency.
130
130
  */
131
- async query(question: LookupQuestion, timeout?: number): Promise<LookupAnswer> {
131
+ async query (question: LookupQuestion, timeout?: number): Promise<LookupAnswer> {
132
132
  let competentHosts: string[] = []
133
133
  if (question.service === 'ls_slap') {
134
134
  competentHosts = this.slapTrackers
@@ -196,7 +196,7 @@ export default class LookupResolver {
196
196
  * @param service Service for which competent hosts are to be returned
197
197
  * @returns Array of hosts competent for resolving queries
198
198
  */
199
- private async findCompetentHosts(service: string): Promise<string[]> {
199
+ private async findCompetentHosts (service: string): Promise<string[]> {
200
200
  const query: LookupQuestion = {
201
201
  service: 'ls_slap',
202
202
  query: {
@@ -15,7 +15,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
15
15
  * @param script Locking script comprising a SHIP or SLAP token to decode
16
16
  * @returns Decoded SHIP or SLAP advertisement
17
17
  */
18
- static decode(script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
18
+ static decode (script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
19
19
  const result = PushDrop.decode(script)
20
20
  if (result.fields.length < 4) {
21
21
  throw new Error('Invalid SHIP/SLAP advertisement!')
@@ -39,7 +39,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
39
39
  * Constructs a new Overlay Admin template instance
40
40
  * @param wallet Wallet to use for locking and unlocking
41
41
  */
42
- constructor(wallet: Wallet) {
42
+ constructor (wallet: Wallet) {
43
43
  this.pushDrop = new PushDrop(wallet)
44
44
  }
45
45
 
@@ -50,7 +50,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
50
50
  * @param topicOrService Topic or service to advertise
51
51
  * @returns Locking script comprising the advertisement token
52
52
  */
53
- async lock(protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
53
+ async lock (protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
54
54
  const { publicKey: identityKey } = await this.pushDrop.wallet.getPublicKey({ identityKey: true })
55
55
  return await this.pushDrop.lock(
56
56
  [
@@ -70,7 +70,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
70
70
  * @param protocol SHIP or SLAP, depending on the token to unlock
71
71
  * @returns Script unlocker capable of unlocking the advertisement token
72
72
  */
73
- unlock(protocol: 'SHIP' | 'SLAP'): {
73
+ unlock (protocol: 'SHIP' | 'SLAP'): {
74
74
  sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>
75
75
  estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>
76
76
  } {
@@ -61,11 +61,11 @@ const MAX_SHIP_QUERY_TIMEOUT = 1000
61
61
  export class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilitator {
62
62
  httpClient: typeof fetch
63
63
 
64
- constructor(httpClient = fetch) {
64
+ constructor (httpClient = fetch) {
65
65
  this.httpClient = httpClient
66
66
  }
67
67
 
68
- async send(url: string, taggedBEEF: TaggedBEEF): Promise<STEAK> {
68
+ async send (url: string, taggedBEEF: TaggedBEEF): Promise<STEAK> {
69
69
  if (!url.startsWith('https:')) {
70
70
  throw new Error('HTTPS facilitator can only use URLs that start with "https:"')
71
71
  }
@@ -102,7 +102,7 @@ export default class SHIPCast implements Broadcaster {
102
102
  * @param {string[]} topics - The list of SHIP topic names where transactions are to be sent.
103
103
  * @param {SHIPBroadcasterConfig} config - Configuration options for the SHIP broadcaster.
104
104
  */
105
- constructor(topics: string[], config?: SHIPBroadcasterConfig) {
105
+ constructor (topics: string[], config?: SHIPBroadcasterConfig) {
106
106
  if (topics.length === 0) {
107
107
  throw new Error('At least one topic is required for broadcast.')
108
108
  }
@@ -129,7 +129,7 @@ export default class SHIPCast implements Broadcaster {
129
129
  * @param {Transaction} tx - The transaction to be sent.
130
130
  * @returns {Promise<BroadcastResponse | BroadcastFailure>} A promise that resolves to either a success or failure response.
131
131
  */
132
- async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure> {
132
+ async broadcast (tx: Transaction): Promise<BroadcastResponse | BroadcastFailure> {
133
133
  let beef: number[]
134
134
  try {
135
135
  beef = tx.toBEEF()
@@ -271,7 +271,7 @@ export default class SHIPCast implements Broadcaster {
271
271
  }
272
272
  }
273
273
 
274
- private checkAcknowledgmentFromAllHosts(hostAcknowledgments: Record<string, Set<string>>, requiredTopics: string[], require: 'all' | 'any'): boolean {
274
+ private checkAcknowledgmentFromAllHosts (hostAcknowledgments: Record<string, Set<string>>, requiredTopics: string[], require: 'all' | 'any'): boolean {
275
275
  for (const acknowledgedTopics of Object.values(hostAcknowledgments)) {
276
276
  if (require === 'all') {
277
277
  for (const topic of requiredTopics) {
@@ -295,7 +295,7 @@ export default class SHIPCast implements Broadcaster {
295
295
  return true
296
296
  }
297
297
 
298
- private checkAcknowledgmentFromAnyHost(hostAcknowledgments: Record<string, Set<string>>, requiredTopics: string[], require: 'all' | 'any'): boolean {
298
+ private checkAcknowledgmentFromAnyHost (hostAcknowledgments: Record<string, Set<string>>, requiredTopics: string[], require: 'all' | 'any'): boolean {
299
299
  if (require === 'all') {
300
300
  // All required topics must be acknowledged by at least one host
301
301
  for (const acknowledgedTopics of Object.values(hostAcknowledgments)) {
@@ -324,7 +324,7 @@ export default class SHIPCast implements Broadcaster {
324
324
  }
325
325
  }
326
326
 
327
- private checkAcknowledgmentFromSpecificHosts(hostAcknowledgments: Record<string, Set<string>>, requirements: Record<string, 'all' | 'any' | string[]>): boolean {
327
+ private checkAcknowledgmentFromSpecificHosts (hostAcknowledgments: Record<string, Set<string>>, requirements: Record<string, 'all' | 'any' | string[]>): boolean {
328
328
  for (const [host, requiredTopicsOrAllAny] of Object.entries(requirements)) {
329
329
  const acknowledgedTopics = hostAcknowledgments[host]
330
330
  if (!acknowledgedTopics) {
@@ -370,7 +370,7 @@ export default class SHIPCast implements Broadcaster {
370
370
  *
371
371
  * @returns A mapping of URLs for hosts interested in this transaction. Keys are URLs, values are which of our topics the specific host cares about.
372
372
  */
373
- private async findInterestedHosts(): Promise<Record<string, Set<string>>> {
373
+ private async findInterestedHosts (): Promise<Record<string, Set<string>>> {
374
374
  // TODO: cache the list of interested hosts to avoid spamming SHIP trackers.
375
375
  // TODO: Monetize the operation of the SHIP tracker system.
376
376
  // TODO: Cache ship/slap lookup with expiry (every 5min)
@@ -381,7 +381,7 @@ export default class SHIPCast implements Broadcaster {
381
381
  service: 'ls_ship',
382
382
  query: {
383
383
  topics: this.topics
384
- },
384
+ }
385
385
  }, MAX_SHIP_QUERY_TIMEOUT)
386
386
  if (answer.type !== 'output-list') {
387
387
  throw new Error('SHIP answer is not an output list.')
@@ -2,4 +2,4 @@ export * from './LookupResolver.js'
2
2
  export * from './SHIPBroadcaster.js'
3
3
  export { default as OverlayAdminTokenTemplate } from './OverlayAdminTokenTemplate.js'
4
4
  export { default as LookupResolver } from './LookupResolver.js'
5
- export { default as SHIPBroadcaster } from './SHIPBroadcaster.js'
5
+ export { default as SHIPBroadcaster } from './SHIPBroadcaster.js'
@@ -17,12 +17,12 @@ export type BeefVersion = undefined | 'V1' | 'V2'
17
17
  *
18
18
  * BUMP standard: BRC-74: BSV Unified Merkle Path (BUMP) Format
19
19
  * https://github.com/bitcoin-sv/BRCs/blob/master/transactions/0074.md
20
- *
20
+ *
21
21
  * BRC-95: Atomic BEEF Transactions
22
22
  * https://github.com/bitcoin-sv/BRCs/blob/master/transactions/0095.md
23
- *
23
+ *
24
24
  * The Atomic BEEF format is supported by the binary deserialization static method `fromBinary`.
25
- *
25
+ *
26
26
  * BRC-96: BEEF V2, Txid Only Extension
27
27
  * https://github.com/bitcoin-sv/BRCs/blob/master/transactions/0096.md
28
28
  *
@@ -57,7 +57,7 @@ export type BeefVersion = undefined | 'V1' | 'V2'
57
57
  *
58
58
  * A valid `Beef` is only required when sent to a party with no shared history,
59
59
  * such as a transaction processor.
60
- *
60
+ *
61
61
  * IMPORTANT NOTE:
62
62
  * It is fundamental to the BEEF value proposition that only valid transactions and valid
63
63
  * merkle path (BUMP) data be added to it. Merging invalid data breaks the `verify` and `isValid`
@@ -108,14 +108,13 @@ export class Beef {
108
108
  /**
109
109
  * Finds a Transaction in this `Beef`
110
110
  * and adds any missing input SourceTransactions from this `Beef`.
111
- *
111
+ *
112
112
  * The result is suitable for signing.
113
- *
113
+ *
114
114
  * @param txid The id of the target transaction.
115
115
  * @returns Transaction with all available input `SourceTransaction`s from this Beef.
116
116
  */
117
117
  findTransactionForSigning (txid: string): Transaction | undefined {
118
-
119
118
  const beefTx = this.findTxid(txid)
120
119
  if (!beefTx) return undefined
121
120
 
@@ -130,24 +129,22 @@ export class Beef {
130
129
 
131
130
  return beefTx.tx
132
131
  }
132
+
133
133
  /**
134
134
  * Builds the proof tree rooted at a specific `Transaction`.
135
- *
135
+ *
136
136
  * To succeed, the Beef must contain all the required transaction and merkle path data.
137
- *
137
+ *
138
138
  * @param txid The id of the target transaction.
139
139
  * @returns Transaction with input `SourceTransaction` and `MerklePath` populated from this Beef.
140
140
  */
141
141
  findAtomicTransaction (txid: string): Transaction | undefined {
142
-
143
142
  const beefTx = this.findTxid(txid)
144
143
  if (!beefTx) return undefined
145
144
 
146
145
  const addInputProof = (beef: Beef, tx: Transaction) => {
147
146
  const mp = beef.findBump(tx.id('hex'))
148
- if (mp)
149
- tx.merklePath = mp
150
- else {
147
+ if (mp) { tx.merklePath = mp } else {
151
148
  for (const i of tx.inputs) {
152
149
  if (!i.sourceTransaction) {
153
150
  const itx = beef.findTxid(i.sourceTXID)
@@ -159,8 +156,7 @@ export class Beef {
159
156
  const mp = beef.findBump(i.sourceTransaction.id('hex'))
160
157
  if (mp) {
161
158
  i.sourceTransaction.merklePath = mp
162
- }
163
- else {
159
+ } else {
164
160
  addInputProof(beef, i.sourceTransaction)
165
161
  }
166
162
  }
@@ -397,7 +393,7 @@ export class Beef {
397
393
 
398
394
  /**
399
395
  * Serializes this data to `writer`
400
- * @param writer
396
+ * @param writer
401
397
  */
402
398
  toWriter (writer: Writer) {
403
399
  writer.writeUInt32LE(this.magic)
@@ -425,20 +421,18 @@ export class Beef {
425
421
 
426
422
  /**
427
423
  * Serialize this Beef as AtomicBEEF.
428
- *
424
+ *
429
425
  * `txid` must exist and be the last transaction
430
426
  * in sorted (dependency) order.
431
- *
432
- * @param txid
427
+ *
428
+ * @param txid
433
429
  * @returns serialized contents of this Beef with AtomicBEEF prefix.
434
430
  */
435
- toBinaryAtomic(txid: string) {
431
+ toBinaryAtomic (txid: string) {
436
432
  this.sortTxs()
437
433
  const tx = this.findTxid(txid)
438
- if (!tx)
439
- throw new Error(`${txid} does not exist in this Beef`)
440
- if (this.txs[this.txs.length - 1] !== tx)
441
- throw new Error(`${txid} is not the last transaction in this Beef`)
434
+ if (!tx) { throw new Error(`${txid} does not exist in this Beef`) }
435
+ if (this.txs[this.txs.length - 1] !== tx) { throw new Error(`${txid} is not the last transaction in this Beef`) }
442
436
  const writer = new Writer()
443
437
  writer.writeUInt32LE(ATOMIC_BEEF)
444
438
  writer.write(toArray(txid, 'hex'))
@@ -456,7 +450,7 @@ export class Beef {
456
450
 
457
451
  static fromReader (br: Reader): Beef {
458
452
  let version = br.readUInt32LE()
459
- let atomicTxid: string | undefined = undefined
453
+ let atomicTxid: string | undefined
460
454
  if (version === ATOMIC_BEEF) {
461
455
  // Skip the txid and re-read the BEEF version
462
456
  atomicTxid = toHex(br.read(32))
@@ -527,19 +521,18 @@ export class Beef {
527
521
  * - Oldest Tx Anchored by Path
528
522
  * - Newer Txs depending on Older parents
529
523
  * - Newest Tx
530
- *
524
+ *
531
525
  * with proof (MerklePath) last, longest chain of dependencies first
532
- *
526
+ *
533
527
  * @returns `{ missingInputs, notValid, valid, withMissingInputs }`
534
528
  */
535
- sortTxs ()
536
- : {
537
- missingInputs: string[],
538
- notValid: string[],
539
- valid: string[],
540
- withMissingInputs: string[],
541
- txidOnly: string[]
542
- } {
529
+ sortTxs (): {
530
+ missingInputs: string[]
531
+ notValid: string[]
532
+ valid: string[]
533
+ withMissingInputs: string[]
534
+ txidOnly: string[]
535
+ } {
543
536
  // Hashtable of valid txids (with proof or all inputs chain to proof)
544
537
  const validTxids: Record<string, boolean> = {}
545
538
 
@@ -560,10 +553,7 @@ export class Beef {
560
553
  if (tx.isValid) {
561
554
  validTxids[tx.txid] = true
562
555
  result.push(tx)
563
- } else if (tx.isTxidOnly)
564
- txidOnly.push(tx)
565
- else
566
- queue.push(tx)
556
+ } else if (tx.isTxidOnly) { txidOnly.push(tx) } else { queue.push(tx) }
567
557
  }
568
558
 
569
559
  // Hashtable of unknown input txids used to fund transactions without their own proof.
@@ -587,10 +577,7 @@ export class Beef {
587
577
  }
588
578
  }
589
579
  }
590
- if (hasMissingInput)
591
- txsMissingInputs.push(tx)
592
- else
593
- queue.push(tx)
580
+ if (hasMissingInput) { txsMissingInputs.push(tx) } else { queue.push(tx) }
594
581
  }
595
582
 
596
583
  // As long as we have unsorted transactions...
@@ -601,11 +588,9 @@ export class Beef {
601
588
  if (tx.inputTxids.every(txid => validTxids[txid])) {
602
589
  validTxids[tx.txid] = true
603
590
  result.push(tx)
604
- } else
605
- queue.push(tx)
591
+ } else { queue.push(tx) }
606
592
  }
607
- if (oldQueue.length === queue.length)
608
- break;
593
+ if (oldQueue.length === queue.length) { break }
609
594
  }
610
595
 
611
596
  // transactions that don't have proofs and don't chain to proofs
@@ -652,7 +637,7 @@ export class Beef {
652
637
  /**
653
638
  * @returns array of transaction txids that either have a proof or whose inputs chain back to a proven transaction.
654
639
  */
655
- getValidTxids() : string[] {
640
+ getValidTxids (): string[] {
656
641
  const r = this.sortTxs()
657
642
  return r.valid
658
643
  }
@@ -94,13 +94,13 @@ export class BeefParty extends Beef {
94
94
 
95
95
  /**
96
96
  * Merge a `beef` received from a specific `party`.
97
- *
97
+ *
98
98
  * Updates this `BeefParty` to track all the txids
99
99
  * corresponding to transactions for which `party`
100
100
  * has raw transaction and validity proof data.
101
- *
102
- * @param party
103
- * @param beef
101
+ *
102
+ * @param party
103
+ * @param beef
104
104
  */
105
105
  mergeBeefFromParty (party: string, beef: number[] | Beef) {
106
106
  const b: Beef = Array.isArray(beef) ? Beef.fromBinary(beef) : beef
@@ -20,7 +20,7 @@ export default class BeefTx {
20
20
  inputTxids: string[] = []
21
21
  /**
22
22
  * true if `hasProof` or all inputs chain to `hasProof`.
23
- *
23
+ *
24
24
  * Typically set by sorting transactions by proven dependency chains.
25
25
  */
26
26
  isValid?: boolean = undefined