From 2079eb3682be5e7237efd18c4b38c5de18531739 Mon Sep 17 00:00:00 2001 From: volodymyr-basiuk <31999965+volodymyr-basiuk@users.noreply.github.com> Date: Fri, 17 May 2024 10:46:02 +0300 Subject: [PATCH] change type of payments id field (#234) * change type of payments id field * make body required --- package-lock.json | 4 ++-- package.json | 2 +- src/iden3comm/handlers/payment.ts | 8 ++++---- src/iden3comm/types/protocol/payment.ts | 10 +++++----- tests/handlers/payment.test.ts | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index d466ce9f..f3e6ca77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.14.0", + "version": "1.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.14.0", + "version": "1.14.1", "license": "AGPL-3.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index 5dab6016..154ce722 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.14.0", + "version": "1.14.1", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", diff --git a/src/iden3comm/handlers/payment.ts b/src/iden3comm/handlers/payment.ts index f88b8f47..1d980e7e 100644 --- a/src/iden3comm/handlers/payment.ts +++ b/src/iden3comm/handlers/payment.ts @@ -191,7 +191,7 @@ export class PaymentHandler throw new Error(`failed request. empty 'from' field`); } - if (!paymentRequest.body?.payments?.length) { + if (!paymentRequest.body.payments?.length) { throw new Error(`failed request. no 'payments' in body`); } @@ -285,13 +285,13 @@ export class PaymentHandler ); } - if (!payment.body?.payments.length) { + if (!payment.body.payments.length) { throw new Error(`failed request. empty 'payments' field in body`); } for (let i = 0; i < payment.body.payments.length; i++) { - const p = payment.body?.payments[i]; - const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id); + const p = payment.body.payments[i]; + const paymentRequestData = opts.paymentRequest.body.payments.find((r) => r.data.id === p.id); if (!paymentRequestData) { throw new Error(`can't find payment request for payment id ${p.id}`); } diff --git a/src/iden3comm/types/protocol/payment.ts b/src/iden3comm/types/protocol/payment.ts index 7e3cd6a1..592a7719 100644 --- a/src/iden3comm/types/protocol/payment.ts +++ b/src/iden3comm/types/protocol/payment.ts @@ -3,7 +3,7 @@ import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../. /** @beta PaymentRequestMessage is struct the represents payment-request message */ export type PaymentRequestMessage = BasicMessage & { - body?: PaymentRequestMessageBody; + body: PaymentRequestMessageBody; }; /** @beta PaymentRequestMessageBody is struct the represents body for payment-request */ @@ -28,8 +28,8 @@ export type PaymentRequestInfo = { export type PaymentRequestDataInfo = { type: PaymentRequestDataType; amount: string; - id: number; - chainId: number; + id: string; + chainId: string; address: string; currency: string; signature?: string; @@ -37,7 +37,7 @@ export type PaymentRequestDataInfo = { /** @beta PaymentMessage is struct the represents payment message */ export type PaymentMessage = BasicMessage & { - body?: PaymentMessageBody; + body: PaymentMessageBody; }; /** @beta PaymentMessageBody is struct the represents body for payment message */ @@ -47,7 +47,7 @@ export type PaymentMessageBody = { /** @beta PaymentInfo is struct the represents payment info for payment */ export type PaymentInfo = { - id: number; + id: string; type: PaymentType; paymentData: { txId: string; diff --git a/tests/handlers/payment.test.ts b/tests/handlers/payment.test.ts index 932c375e..85c5b7a1 100644 --- a/tests/handlers/payment.test.ts +++ b/tests/handlers/payment.test.ts @@ -133,8 +133,8 @@ describe('payment-request handler', () => { data: { type: PaymentRequestDataType.Iden3PaymentRequestCryptoV1, amount: '0.001', - id: 12432, - chainId: 80002, + id: '12432', + chainId: '80002', address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992', currency: 'ETH' }, @@ -232,7 +232,7 @@ describe('payment-request handler', () => { const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]); const payment = createPayment(userDID, issuerDID, [ { - id: paymentRequest.body?.payments[0].data.id || 0, + id: paymentRequest.body.payments[0].data.id, type: PaymentType.Iden3PaymentCryptoV1, paymentData: { txId: '0x312312334' @@ -272,7 +272,7 @@ describe('payment-request handler', () => { const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]); const payment = createPayment(userDID, issuerDID, [ { - id: paymentRequest.body?.payments[0].data.id || 0, + id: paymentRequest.body.payments[0].data.id, type: PaymentType.Iden3PaymentCryptoV1, paymentData: { txId: '0xe9bea8e7adfe1092a8a4ca2cd75f4d21cc54b9b7a31bd8374b558d11b58a6a1a'