Skip to content

Commit 89987db

Browse files
add exports
1 parent 34e7282 commit 89987db

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/iden3comm/handlers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './revocation-status';
66
export * from './common';
77
export * from './credential-proposal';
88
export * from './message-handler';
9+
export * from './payment';

src/iden3comm/handlers/message-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BasicMessage, IPackageManager } from '../types';
22
import { AuthMessageHandlerOptions } from './auth';
33
import { RevocationStatusMessageHandlerOptions } from './revocation-status';
44
import { ContractMessageHandlerOptions } from './contract-request';
5-
import { PaymentRequestMessageHandlerOptions } from './payment';
5+
import { PaymentHandlerOptions, PaymentRequestMessageHandlerOptions } from './payment';
66
/**
77
* iden3 Protocol message handler interface
88
*/
@@ -119,6 +119,7 @@ export class MessageHandler {
119119
| ContractMessageHandlerOptions
120120
| RevocationStatusMessageHandlerOptions
121121
| PaymentRequestMessageHandlerOptions
122+
| PaymentHandlerOptions
122123
| { [key: string]: unknown }
123124
): Promise<Uint8Array | null> {
124125
const { unpackedMediaType, unpackedMessage: message } =

src/iden3comm/handlers/payment.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ export class PaymentHandler
196196
throw new Error(`failed request. no 'payments' in body`);
197197
}
198198

199-
const senderDID = DID.parse(paymentRequest.from);
200-
const receiverDID = DID.parse(paymentRequest.to);
199+
const senderDID = DID.parse(paymentRequest.to);
200+
const receiverDID = DID.parse(paymentRequest.from);
201201

202202
const payments: PaymentInfo[] = [];
203203
for (let i = 0; i < paymentRequest.body.payments.length; i++) {
@@ -221,7 +221,7 @@ export class PaymentHandler
221221
});
222222
}
223223

224-
const paymentMessage = createPayment(receiverDID, senderDID, payments);
224+
const paymentMessage = createPayment(senderDID, receiverDID, payments);
225225
const responseEncoded = byteEncoder.encode(JSON.stringify(paymentMessage));
226226
const packerOpts =
227227
this._params.packerParams.mediaType === MediaType.SignedMessage
@@ -273,6 +273,10 @@ export class PaymentHandler
273273
throw new Error(`failed request. empty 'from' field`);
274274
}
275275

276+
if (!paymentRequest.to) {
277+
throw new Error(`failed request. empty 'to' field`);
278+
}
279+
276280
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
277281

278282
const response = byteEncoder.encode(JSON.stringify(agentMessage));
@@ -283,7 +287,7 @@ export class PaymentHandler
283287
provingMethodAlg: proving.provingMethodGroth16AuthV2Instance.methodAlg
284288
};
285289

286-
const senderDID = DID.parse(paymentRequest.from);
290+
const senderDID = DID.parse(paymentRequest.to);
287291
return this._packerMgr.pack(this._params.packerParams.mediaType, response, {
288292
senderDID,
289293
...packerOpts
@@ -294,7 +298,7 @@ export class PaymentHandler
294298
* @inheritdoc IPaymentHandler#handlePayment
295299
*/
296300
async handlePayment(payment: PaymentMessage, opts: PaymentHandlerOptions) {
297-
if (opts.paymentRequest && opts.paymentRequest.from !== payment.to) {
301+
if (opts.paymentRequest.from !== payment.to) {
298302
throw new Error(
299303
`sender of the request is not a target of response - expected ${opts.paymentRequest.from}, given ${payment.to}`
300304
);

src/iden3comm/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './protocol/proof';
55
export * from './protocol/revocation';
66
export * from './protocol/contract-request';
77
export * from './protocol/proposal-request';
8+
export * from './protocol/payment';
89

910
export * from './packer';
1011
export * from './packageManager';

0 commit comments

Comments
 (0)