@bsv/message-box-client 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/message-box-client",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -642,8 +642,7 @@ export class MessageBoxClient {
642
642
  skipEncryption,
643
643
  checkPermissions,
644
644
  originator
645
- }: SendMessageParams): Promise<SendMessageResponse> {
646
- await this.assertInitialized()
645
+ }: SendMessageParams, overrideHost?: string): Promise<SendMessageResponse> {
647
646
  if (recipient == null || recipient.trim() === '') {
648
647
  throw new Error('[MB CLIENT ERROR] Recipient identity key is required')
649
648
  }
@@ -655,12 +654,12 @@ export class MessageBoxClient {
655
654
  }
656
655
 
657
656
  // Ensure room is joined before sending
658
- await this.joinRoom(messageBox)
657
+ await this.joinRoom(messageBox, originator, overrideHost)
659
658
 
660
659
  // Fallback to HTTP if WebSocket is not connected
661
660
  if (this.socket == null || !this.socket.connected) {
662
661
  Logger.warn('[MB CLIENT WARNING] WebSocket not connected, falling back to HTTP')
663
- const targetHost = await this.resolveHostForRecipient(recipient)
662
+ const targetHost = overrideHost ?? await this.resolveHostForRecipient(recipient)
664
663
  return await this.sendMessage({ recipient, messageBox, body }, targetHost)
665
664
  }
666
665
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { MessageBoxClient } from './MessageBoxClient.js'
14
14
  import { PeerMessage } from './types.js'
15
- import { WalletClient, P2PKH, PublicKey, createNonce, AtomicBEEF, AuthFetch, Base64String } from '@bsv/sdk'
15
+ import { WalletInterface, P2PKH, PublicKey, createNonce, AtomicBEEF, AuthFetch, Base64String } from '@bsv/sdk'
16
16
  import * as Logger from './Utils/logger.js'
17
17
 
18
18
  function safeParse<T> (input: any): T {
@@ -34,7 +34,7 @@ const STANDARD_PAYMENT_OUTPUT_INDEX = 0
34
34
  */
35
35
  export interface PeerPayClientConfig {
36
36
  messageBoxHost?: string
37
- walletClient: WalletClient
37
+ walletClient: WalletInterface
38
38
  enableLogging?: boolean // Added optional logging flag
39
39
  }
40
40
 
@@ -71,7 +71,7 @@ export interface IncomingPayment {
71
71
  * PeerPayClient enables peer-to-peer Bitcoin payments using MessageBox.
72
72
  */
73
73
  export class PeerPayClient extends MessageBoxClient {
74
- private readonly peerPayWalletClient: WalletClient
74
+ private readonly peerPayWalletClient: WalletInterface
75
75
  private _authFetchInstance?: AuthFetch
76
76
 
77
77
  constructor (config: PeerPayClientConfig) {
@@ -198,16 +198,17 @@ export class PeerPayClient extends MessageBoxClient {
198
198
  * Sends Bitcoin to a PeerPay recipient over WebSockets.
199
199
  *
200
200
  * This function generates a payment token and transmits it over WebSockets
201
- * using `sendLiveMessage`. The recipients identity key is explicitly included
201
+ * using `sendLiveMessage`. The recipient's identity key is explicitly included
202
202
  * to ensure proper message routing.
203
203
  *
204
204
  * @param {PaymentParams} payment - The payment details.
205
205
  * @param {string} payment.recipient - The recipient's identity key.
206
206
  * @param {number} payment.amount - The amount in satoshis to send.
207
+ * @param {string} [overrideHost] - Optional host override for WebSocket connection.
207
208
  * @returns {Promise<void>} Resolves when the payment has been sent.
208
209
  * @throws {Error} If payment token generation fails.
209
210
  */
210
- async sendLivePayment (payment: PaymentParams): Promise<void> {
211
+ async sendLivePayment (payment: PaymentParams, overrideHost?: string): Promise<void> {
211
212
  const paymentToken = await this.createPaymentToken(payment)
212
213
 
213
214
  try {
@@ -216,7 +217,7 @@ export class PeerPayClient extends MessageBoxClient {
216
217
  recipient: payment.recipient,
217
218
  messageBox: STANDARD_PAYMENT_MESSAGEBOX,
218
219
  body: JSON.stringify(paymentToken)
219
- })
220
+ }, overrideHost)
220
221
  } catch (err) {
221
222
  Logger.warn('[PP CLIENT] sendLiveMessage failed, falling back to HTTP:', err)
222
223
 
@@ -225,7 +226,7 @@ export class PeerPayClient extends MessageBoxClient {
225
226
  recipient: payment.recipient,
226
227
  messageBox: STANDARD_PAYMENT_MESSAGEBOX,
227
228
  body: JSON.stringify(paymentToken)
228
- })
229
+ }, overrideHost)
229
230
  }
230
231
  }
231
232
 
@@ -238,6 +239,7 @@ export class PeerPayClient extends MessageBoxClient {
238
239
  *
239
240
  * @param {Object} obj - The configuration object.
240
241
  * @param {Function} obj.onPayment - Callback function triggered when a payment is received.
242
+ * @param {string} [obj.overrideHost] - Optional host override for WebSocket connection.
241
243
  * @returns {Promise<void>} Resolves when the listener is successfully set up.
242
244
  */
243
245
  async listenForLivePayments ({
@@ -148,7 +148,7 @@ describe('PeerPayClient Unit Tests', () => {
148
148
  recipient: 'recipientKey',
149
149
  messageBox: 'payment_inbox',
150
150
  body: '{"customInstructions":{"derivationPrefix":"prefix","derivationSuffix":"suffix"},"transaction":[1,2,3,4,5],"amount":2}'
151
- })
151
+ }, undefined)
152
152
  })
153
153
  })
154
154