@bsv/message-box-client 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/MessageBoxClient.js +3 -4
- package/dist/cjs/src/MessageBoxClient.js.map +1 -1
- package/dist/cjs/src/PeerPayClient.js +6 -4
- package/dist/cjs/src/PeerPayClient.js.map +1 -1
- package/dist/cjs/src/__tests/PeerPayClientUnit.test.js +1 -1
- package/dist/cjs/src/__tests/PeerPayClientUnit.test.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/MessageBoxClient.js +3 -4
- package/dist/esm/src/MessageBoxClient.js.map +1 -1
- package/dist/esm/src/PeerPayClient.js +6 -4
- package/dist/esm/src/PeerPayClient.js.map +1 -1
- package/dist/esm/src/__tests/PeerPayClientUnit.test.js +1 -1
- package/dist/esm/src/__tests/PeerPayClientUnit.test.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/MessageBoxClient.d.ts +1 -1
- package/dist/types/src/MessageBoxClient.d.ts.map +1 -1
- package/dist/types/src/PeerPayClient.d.ts +4 -2
- package/dist/types/src/PeerPayClient.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/package.json +1 -1
- package/src/MessageBoxClient.ts +3 -4
- package/src/PeerPayClient.ts +6 -4
- package/src/__tests/PeerPayClientUnit.test.ts +1 -1
package/package.json
CHANGED
package/src/MessageBoxClient.ts
CHANGED
|
@@ -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
|
|
package/src/PeerPayClient.ts
CHANGED
|
@@ -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 recipient
|
|
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
|
|