Skip to content

Commit 30035b0

Browse files
committed
Improve comments and code
1 parent 0a65920 commit 30035b0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/security/nexoSecurityManager.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ class NexoSecurityManager {
5050
* Encrypts a SaleToPOI message.
5151
*
5252
* @param messageHeader - The Nexo message header
53-
* @param saleToPoiMessageJson - The message body in JSON string format
53+
* @param payload - The payload in JSON string format
5454
* @param credentials - The encryption credentials
5555
* @returns A instance of SaleToPOISecuredMessage with MessageHeader, NexoBlob (the encrypted payload) and SecurityTrailer
5656
*/
5757
public static encrypt(
5858
messageHeader: MessageHeader,
59-
saleToPoiMessageJson: string,
59+
payload: string,
6060
credentials: EncryptionCredentialDetails,
6161
): SaleToPOISecuredMessage {
6262

6363
try {
6464

6565
const derivedKey: NexoDerivedKey = NexoDerivedKeyGenerator.deriveKeyMaterial(credentials.Passphrase);
66-
const saleToPoiMessageByteArray = Buffer.from(saleToPoiMessageJson, "utf-8");
66+
const saleToPoiMessageByteArray = Buffer.from(payload, "utf-8");
6767
const ivNonce = NexoSecurityManager.generateRandomIvNonce();
6868
const encryptedSaleToPoiMessage = NexoSecurityManager.crypt(
6969
saleToPoiMessageByteArray,
@@ -127,10 +127,7 @@ class NexoSecurityManager {
127127
const receivedHmac = Buffer.from(saleToPoiSecureMessage.SecurityTrailer.Hmac, "base64");
128128
NexoSecurityManager.validateHmac(receivedHmac, decryptedSaleToPoiMessageByteArray, derivedKey);
129129

130-
const decryptedPayload = decryptedSaleToPoiMessageByteArray.toString("utf-8");
131-
// Re-add braces to make it a valid JSON object string, reversing the operation from `encrypt`.
132-
//return `{${decryptedPayload}}`;
133-
return decryptedPayload
130+
return decryptedSaleToPoiMessageByteArray.toString("utf-8");
134131

135132
} catch (err: any) {
136133
// an error has occurred

0 commit comments

Comments
 (0)