Skip to content

Commit

Permalink
feat(contracts): AG-52 added sha field
Browse files Browse the repository at this point in the history
added sha field to ecrypted structs in the DEC contract
  • Loading branch information
g3k0 committed Apr 22, 2024
1 parent 1273bff commit 6af9a66
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions contracts/DEC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract DEC {
Encrypted country;

struct Encrypted {
string sha;
string chiper;
string nonce;
}
Expand Down
1 change: 1 addition & 0 deletions lib/crypto-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function encryptString(
);

const response: Encrypted = JSON.parse(encrypted.toString());
response.sha = getHash(decryptedString).sha;

return response;
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type Encrypted = {
sha: string;
chiper: string;
nonce: string;
};
Expand All @@ -7,6 +8,6 @@ export type Decrypted = {
message: string;
};

export type Sha {
export type Sha = {
sha: string;
}
};
25 changes: 22 additions & 3 deletions test/DEC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ describe("DEC Contract", () => {
let dec: DEC;

const encryptedDataFactory = function (
sha: string,
chiper: string,
nonce: string,
): Encrypted {
return {
chiper,
nonce,
sha,
};
};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
});
Expand All @@ -115,6 +125,7 @@ describe("DEC Contract", () => {
const gMunicipality = encryptedDataFactory(
getMunicipality[0],
getMunicipality[1],
getMunicipality[2],
);

assert.equal(JSON.stringify(eMunicipality), JSON.stringify(gMunicipality));
Expand All @@ -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));
});
Expand All @@ -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));
});
Expand Down

0 comments on commit 6af9a66

Please sign in to comment.