@bsv/message-box-client 1.4.4 → 1.4.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.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/PeerPayClient.js +2 -2
- package/dist/cjs/src/PeerPayClient.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/PeerPayClient.js +2 -2
- package/dist/esm/src/PeerPayClient.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- 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/PeerPayClient.ts +12 -12
package/package.json
CHANGED
package/src/PeerPayClient.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { WalletInterface, P2PKH, PublicKey, createNonce, AtomicBEEF, AuthFetch,
|
|
|
16
16
|
|
|
17
17
|
import * as Logger from './Utils/logger.js'
|
|
18
18
|
|
|
19
|
-
function safeParse<T>
|
|
19
|
+
function safeParse<T>(input: any): T {
|
|
20
20
|
try {
|
|
21
21
|
return typeof input === 'string' ? JSON.parse(input) : input
|
|
22
22
|
} catch (e) {
|
|
@@ -80,7 +80,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
80
80
|
private _authFetchInstance?: AuthFetch
|
|
81
81
|
private readonly messageBox: string
|
|
82
82
|
|
|
83
|
-
constructor
|
|
83
|
+
constructor(config: PeerPayClientConfig) {
|
|
84
84
|
const { messageBoxHost = 'https://messagebox.babbage.systems', walletClient, enableLogging = false, originator } = config
|
|
85
85
|
|
|
86
86
|
// 🔹 Pass enableLogging to MessageBoxClient
|
|
@@ -91,7 +91,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
91
91
|
this.originator = originator
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
private get authFetchInstance
|
|
94
|
+
private get authFetchInstance(): AuthFetch {
|
|
95
95
|
if (this._authFetchInstance === null || this._authFetchInstance === undefined) {
|
|
96
96
|
this._authFetchInstance = new AuthFetch(this.peerPayWalletClient, undefined, undefined, this.originator)
|
|
97
97
|
}
|
|
@@ -110,14 +110,14 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
110
110
|
* @returns {Promise<PaymentToken>} A valid payment token containing transaction details.
|
|
111
111
|
* @throws {Error} If the recipient's public key cannot be derived.
|
|
112
112
|
*/
|
|
113
|
-
async createPaymentToken
|
|
113
|
+
async createPaymentToken(payment: PaymentParams): Promise<PaymentToken> {
|
|
114
114
|
if (payment.amount <= 0) {
|
|
115
115
|
throw new Error('Invalid payment details: recipient and valid amount are required')
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
// Generate derivation paths using correct nonce function
|
|
119
|
-
const derivationPrefix = await createNonce(this.peerPayWalletClient, this.originator)
|
|
120
|
-
const derivationSuffix = await createNonce(this.peerPayWalletClient, this.originator)
|
|
119
|
+
const derivationPrefix = await createNonce(this.peerPayWalletClient, 'self', this.originator)
|
|
120
|
+
const derivationSuffix = await createNonce(this.peerPayWalletClient, 'self', this.originator)
|
|
121
121
|
|
|
122
122
|
Logger.log(`[PP CLIENT] Derivation Prefix: ${derivationPrefix}`)
|
|
123
123
|
Logger.log(`[PP CLIENT] Derivation Suffix: ${derivationSuffix}`)
|
|
@@ -187,7 +187,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
187
187
|
* @returns {Promise<any>} Resolves with the payment result.
|
|
188
188
|
* @throws {Error} If the recipient is missing or the amount is invalid.
|
|
189
189
|
*/
|
|
190
|
-
async sendPayment
|
|
190
|
+
async sendPayment(payment: PaymentParams, hostOverride?: string): Promise<any> {
|
|
191
191
|
if (payment.recipient == null || payment.recipient.trim() === '' || payment.amount <= 0) {
|
|
192
192
|
throw new Error('Invalid payment details: recipient and valid amount are required')
|
|
193
193
|
}
|
|
@@ -216,7 +216,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
216
216
|
* @returns {Promise<void>} Resolves when the payment has been sent.
|
|
217
217
|
* @throws {Error} If payment token generation fails.
|
|
218
218
|
*/
|
|
219
|
-
async sendLivePayment
|
|
219
|
+
async sendLivePayment(payment: PaymentParams, overrideHost?: string): Promise<void> {
|
|
220
220
|
const paymentToken = await this.createPaymentToken(payment)
|
|
221
221
|
|
|
222
222
|
try {
|
|
@@ -250,7 +250,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
250
250
|
* @param {string} [obj.overrideHost] - Optional host override for WebSocket connection.
|
|
251
251
|
* @returns {Promise<void>} Resolves when the listener is successfully set up.
|
|
252
252
|
*/
|
|
253
|
-
async listenForLivePayments
|
|
253
|
+
async listenForLivePayments({
|
|
254
254
|
onPayment,
|
|
255
255
|
overrideHost
|
|
256
256
|
}: {
|
|
@@ -286,7 +286,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
286
286
|
* @returns {Promise<any>} Resolves with the payment result if successful.
|
|
287
287
|
* @throws {Error} If payment processing fails.
|
|
288
288
|
*/
|
|
289
|
-
async acceptPayment
|
|
289
|
+
async acceptPayment(payment: IncomingPayment): Promise<any> {
|
|
290
290
|
try {
|
|
291
291
|
Logger.log(`[PP CLIENT] Processing payment: ${JSON.stringify(payment, null, 2)}`)
|
|
292
292
|
|
|
@@ -327,7 +327,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
327
327
|
* @param {IncomingPayment} payment - The payment object containing transaction details.
|
|
328
328
|
* @returns {Promise<void>} Resolves when the payment is either acknowledged or refunded.
|
|
329
329
|
*/
|
|
330
|
-
async rejectPayment
|
|
330
|
+
async rejectPayment(payment: IncomingPayment): Promise<void> {
|
|
331
331
|
Logger.log(`[PP CLIENT] Rejecting payment: ${JSON.stringify(payment, null, 2)}`)
|
|
332
332
|
|
|
333
333
|
if (payment.token.amount - 1000 < 1000) {
|
|
@@ -388,7 +388,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
388
388
|
* @param {string} [overrideHost] - Optional host override to list payments from
|
|
389
389
|
* @returns {Promise<IncomingPayment[]>} Resolves with an array of pending payments.
|
|
390
390
|
*/
|
|
391
|
-
async listIncomingPayments
|
|
391
|
+
async listIncomingPayments(overrideHost?: string): Promise<IncomingPayment[]> {
|
|
392
392
|
const messages = await this.listMessages({ messageBox: this.messageBox, host: overrideHost })
|
|
393
393
|
return messages.map((msg: any) => {
|
|
394
394
|
const parsedToken = safeParse<PaymentToken>(msg.body)
|