Skip to content

Commit

Permalink
fix: fixed message parsing (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 authored Jan 23, 2024
1 parent 1b95ef3 commit 0aa0acd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/restapi/src/lib/chat/helpers/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface IDecryptMessage {
chainId: number;
currentChat: IFeeds;
inbox: IFeeds[];
pgpHelper:IPGPHelper;
pgpHelper: IPGPHelper;
}

export const encryptAndSign = async ({
Expand Down Expand Up @@ -158,7 +158,7 @@ export const decryptFeeds = async ({
feeds: IFeeds[];
connectedUser: IUser;
pgpPrivateKey?: string;
pgpHelper: PGP.IPGPHelper
pgpHelper: PGP.IPGPHelper;
env: ENV;
}): Promise<IFeeds[]> => {
let otherPeer: IUser;
Expand Down Expand Up @@ -542,12 +542,19 @@ export const decryptAndVerifyMessage = async (
secretKey,
});
if (message.messageObj) {
decryptedMessage.messageObj = JSON.parse(
aesDecrypt({
cipherText: message.messageObj as string,
secretKey,
})
);
const decryptedMessageObj = aesDecrypt({
cipherText: message.messageObj as string,
secretKey,
});
/**
* @dev - messageObj can be an invalid JSON string which needs to be handled
* @dev - swift sdk sends messageObj as invalid json string
*/
try {
decryptedMessage.messageObj = JSON.parse(decryptedMessageObj);
} catch (err) {
decryptedMessage.messageObj = decryptedMessageObj;
}
}
} catch (err) {
decryptedMessage.messageContent = decryptedMessage.messageObj =
Expand Down

0 comments on commit 0aa0acd

Please sign in to comment.