@bsv/message-box-client 1.4.2 → 1.4.4
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 +4 -3
- package/dist/cjs/src/PeerPayClient.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/PeerPayClient.js +3 -3
- package/dist/esm/src/PeerPayClient.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/PeerPayClient.d.ts +3 -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 +16 -14
- package/src/types/permissions.ts +1 -1
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>(input: any): 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) {
|
|
@@ -59,6 +59,7 @@ export interface PaymentToken {
|
|
|
59
59
|
}
|
|
60
60
|
transaction: AtomicBEEF
|
|
61
61
|
amount: number
|
|
62
|
+
outputIndex?: number
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
@@ -68,6 +69,7 @@ export interface IncomingPayment {
|
|
|
68
69
|
messageId: string
|
|
69
70
|
sender: string
|
|
70
71
|
token: PaymentToken
|
|
72
|
+
outputIndex?: number
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
/**
|
|
@@ -76,9 +78,9 @@ export interface IncomingPayment {
|
|
|
76
78
|
export class PeerPayClient extends MessageBoxClient {
|
|
77
79
|
private readonly peerPayWalletClient: WalletInterface
|
|
78
80
|
private _authFetchInstance?: AuthFetch
|
|
79
|
-
private messageBox: string
|
|
81
|
+
private readonly messageBox: string
|
|
80
82
|
|
|
81
|
-
constructor(config: PeerPayClientConfig) {
|
|
83
|
+
constructor (config: PeerPayClientConfig) {
|
|
82
84
|
const { messageBoxHost = 'https://messagebox.babbage.systems', walletClient, enableLogging = false, originator } = config
|
|
83
85
|
|
|
84
86
|
// 🔹 Pass enableLogging to MessageBoxClient
|
|
@@ -89,7 +91,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
89
91
|
this.originator = originator
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
private get authFetchInstance(): AuthFetch {
|
|
94
|
+
private get authFetchInstance (): AuthFetch {
|
|
93
95
|
if (this._authFetchInstance === null || this._authFetchInstance === undefined) {
|
|
94
96
|
this._authFetchInstance = new AuthFetch(this.peerPayWalletClient, undefined, undefined, this.originator)
|
|
95
97
|
}
|
|
@@ -108,14 +110,14 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
108
110
|
* @returns {Promise<PaymentToken>} A valid payment token containing transaction details.
|
|
109
111
|
* @throws {Error} If the recipient's public key cannot be derived.
|
|
110
112
|
*/
|
|
111
|
-
async createPaymentToken(payment: PaymentParams): Promise<PaymentToken> {
|
|
113
|
+
async createPaymentToken (payment: PaymentParams): Promise<PaymentToken> {
|
|
112
114
|
if (payment.amount <= 0) {
|
|
113
115
|
throw new Error('Invalid payment details: recipient and valid amount are required')
|
|
114
116
|
};
|
|
115
117
|
|
|
116
118
|
// Generate derivation paths using correct nonce function
|
|
117
|
-
const derivationPrefix = await createNonce(this.peerPayWalletClient)
|
|
118
|
-
const derivationSuffix = await createNonce(this.peerPayWalletClient)
|
|
119
|
+
const derivationPrefix = await createNonce(this.peerPayWalletClient, this.originator)
|
|
120
|
+
const derivationSuffix = await createNonce(this.peerPayWalletClient, this.originator)
|
|
119
121
|
|
|
120
122
|
Logger.log(`[PP CLIENT] Derivation Prefix: ${derivationPrefix}`)
|
|
121
123
|
Logger.log(`[PP CLIENT] Derivation Suffix: ${derivationSuffix}`)
|
|
@@ -185,7 +187,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
185
187
|
* @returns {Promise<any>} Resolves with the payment result.
|
|
186
188
|
* @throws {Error} If the recipient is missing or the amount is invalid.
|
|
187
189
|
*/
|
|
188
|
-
async sendPayment(payment: PaymentParams, hostOverride?: string): Promise<any> {
|
|
190
|
+
async sendPayment (payment: PaymentParams, hostOverride?: string): Promise<any> {
|
|
189
191
|
if (payment.recipient == null || payment.recipient.trim() === '' || payment.amount <= 0) {
|
|
190
192
|
throw new Error('Invalid payment details: recipient and valid amount are required')
|
|
191
193
|
}
|
|
@@ -214,7 +216,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
214
216
|
* @returns {Promise<void>} Resolves when the payment has been sent.
|
|
215
217
|
* @throws {Error} If payment token generation fails.
|
|
216
218
|
*/
|
|
217
|
-
async sendLivePayment(payment: PaymentParams, overrideHost?: string): Promise<void> {
|
|
219
|
+
async sendLivePayment (payment: PaymentParams, overrideHost?: string): Promise<void> {
|
|
218
220
|
const paymentToken = await this.createPaymentToken(payment)
|
|
219
221
|
|
|
220
222
|
try {
|
|
@@ -248,7 +250,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
248
250
|
* @param {string} [obj.overrideHost] - Optional host override for WebSocket connection.
|
|
249
251
|
* @returns {Promise<void>} Resolves when the listener is successfully set up.
|
|
250
252
|
*/
|
|
251
|
-
async listenForLivePayments({
|
|
253
|
+
async listenForLivePayments ({
|
|
252
254
|
onPayment,
|
|
253
255
|
overrideHost
|
|
254
256
|
}: {
|
|
@@ -284,7 +286,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
284
286
|
* @returns {Promise<any>} Resolves with the payment result if successful.
|
|
285
287
|
* @throws {Error} If payment processing fails.
|
|
286
288
|
*/
|
|
287
|
-
async acceptPayment(payment: IncomingPayment): Promise<any> {
|
|
289
|
+
async acceptPayment (payment: IncomingPayment): Promise<any> {
|
|
288
290
|
try {
|
|
289
291
|
Logger.log(`[PP CLIENT] Processing payment: ${JSON.stringify(payment, null, 2)}`)
|
|
290
292
|
|
|
@@ -296,7 +298,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
296
298
|
derivationSuffix: payment.token.customInstructions.derivationSuffix,
|
|
297
299
|
senderIdentityKey: payment.sender
|
|
298
300
|
},
|
|
299
|
-
outputIndex: STANDARD_PAYMENT_OUTPUT_INDEX,
|
|
301
|
+
outputIndex: payment.token.outputIndex ?? STANDARD_PAYMENT_OUTPUT_INDEX,
|
|
300
302
|
protocol: 'wallet payment'
|
|
301
303
|
}],
|
|
302
304
|
labels: ['peerpay'],
|
|
@@ -325,7 +327,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
325
327
|
* @param {IncomingPayment} payment - The payment object containing transaction details.
|
|
326
328
|
* @returns {Promise<void>} Resolves when the payment is either acknowledged or refunded.
|
|
327
329
|
*/
|
|
328
|
-
async rejectPayment(payment: IncomingPayment): Promise<void> {
|
|
330
|
+
async rejectPayment (payment: IncomingPayment): Promise<void> {
|
|
329
331
|
Logger.log(`[PP CLIENT] Rejecting payment: ${JSON.stringify(payment, null, 2)}`)
|
|
330
332
|
|
|
331
333
|
if (payment.token.amount - 1000 < 1000) {
|
|
@@ -386,7 +388,7 @@ export class PeerPayClient extends MessageBoxClient {
|
|
|
386
388
|
* @param {string} [overrideHost] - Optional host override to list payments from
|
|
387
389
|
* @returns {Promise<IncomingPayment[]>} Resolves with an array of pending payments.
|
|
388
390
|
*/
|
|
389
|
-
async listIncomingPayments(overrideHost?: string): Promise<IncomingPayment[]> {
|
|
391
|
+
async listIncomingPayments (overrideHost?: string): Promise<IncomingPayment[]> {
|
|
390
392
|
const messages = await this.listMessages({ messageBox: this.messageBox, host: overrideHost })
|
|
391
393
|
return messages.map((msg: any) => {
|
|
392
394
|
const parsedToken = safeParse<PaymentToken>(msg.body)
|
package/src/types/permissions.ts
CHANGED