From 6af9a66b6d8f4c9892f703e1900281e15dd994ab Mon Sep 17 00:00:00 2001 From: Christian Palazzo Date: Mon, 22 Apr 2024 21:00:43 +0200 Subject: [PATCH] feat(contracts): AG-52 added sha field added sha field to ecrypted structs in the DEC contract --- contracts/DEC.sol | 1 + lib/crypto-utils.ts | 1 + lib/types.ts | 5 +++-- test/DEC.ts | 25 ++++++++++++++++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/contracts/DEC.sol b/contracts/DEC.sol index cce90c4..315e5d4 100644 --- a/contracts/DEC.sol +++ b/contracts/DEC.sol @@ -12,6 +12,7 @@ contract DEC { Encrypted country; struct Encrypted { + string sha; string chiper; string nonce; } diff --git a/lib/crypto-utils.ts b/lib/crypto-utils.ts index bdecb4e..7ecf019 100644 --- a/lib/crypto-utils.ts +++ b/lib/crypto-utils.ts @@ -40,6 +40,7 @@ export function encryptString( ); const response: Encrypted = JSON.parse(encrypted.toString()); + response.sha = getHash(decryptedString).sha; return response; } catch (e) { diff --git a/lib/types.ts b/lib/types.ts index 581156e..8c72439 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,4 +1,5 @@ export type Encrypted = { + sha: string; chiper: string; nonce: string; }; @@ -7,6 +8,6 @@ export type Decrypted = { message: string; }; -export type Sha { +export type Sha = { sha: string; -} +}; diff --git a/test/DEC.ts b/test/DEC.ts index d81ea9f..73dc93e 100644 --- a/test/DEC.ts +++ b/test/DEC.ts @@ -8,12 +8,14 @@ describe("DEC Contract", () => { let dec: DEC; const encryptedDataFactory = function ( + sha: string, chiper: string, nonce: string, ): Encrypted { return { chiper, nonce, + sha, }; }; @@ -53,21 +55,25 @@ describe("DEC Contract", () => { const enTaxCode = encryptedDataFactory( registeredTaxCode[0], registeredTaxCode[1], + registeredTaxCode[2], ); const enMunicipality = encryptedDataFactory( registeredMunicipality[0], registeredMunicipality[1], + registeredMunicipality[2], ); const enRegion = encryptedDataFactory( registeredRegion[0], registeredRegion[1], + registeredRegion[2], ); const enCountry = encryptedDataFactory( registeredCountry[0], registeredCountry[1], + registeredCountry[2], ); const decodedTaxCode = decryptString( @@ -102,7 +108,11 @@ describe("DEC Contract", () => { const getTaxCode = await dec.getTaxCode(); - const gTaxCode = encryptedDataFactory(getTaxCode[0], getTaxCode[1]); + const gTaxCode = encryptedDataFactory( + getTaxCode[0], + getTaxCode[1], + getTaxCode[2], + ); assert.equal(JSON.stringify(eTaxCode), JSON.stringify(gTaxCode)); }); @@ -115,6 +125,7 @@ describe("DEC Contract", () => { const gMunicipality = encryptedDataFactory( getMunicipality[0], getMunicipality[1], + getMunicipality[2], ); assert.equal(JSON.stringify(eMunicipality), JSON.stringify(gMunicipality)); @@ -125,7 +136,11 @@ describe("DEC Contract", () => { const getRegion = await dec.getRegion(); - const gRegion = encryptedDataFactory(getRegion[0], getRegion[1]); + const gRegion = encryptedDataFactory( + getRegion[0], + getRegion[1], + getRegion[2], + ); assert.equal(JSON.stringify(eRegion), JSON.stringify(gRegion)); }); @@ -135,7 +150,11 @@ describe("DEC Contract", () => { const getCountry = await dec.getCountry(); - const gCountry = encryptedDataFactory(getCountry[0], getCountry[1]); + const gCountry = encryptedDataFactory( + getCountry[0], + getCountry[1], + getCountry[2], + ); assert.equal(JSON.stringify(eCountry), JSON.stringify(gCountry)); });