Skip to content

Commit

Permalink
Merge pull request #261 from zama-ai/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
jatZama authored Jan 18, 2024
2 parents 47ff9ca + cba380d commit ece52c0
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 67 deletions.
6 changes: 3 additions & 3 deletions docs/client/examples/getbalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const getBalance = async () => {

// Sign the public key
const signature = await signer.signTypedData(
generatedToken.token.domain,
{ Reencrypt: generatedToken.token.types.Reencrypt }, // Need to remove EIP712Domain from types
generatedToken.token.message,
generatedToken.eip712.domain,
{ Reencrypt: generatedToken.eip712.types.Reencrypt }, // Need to remove EIP712Domain from types
generatedToken.eip712.message,
);
instance.setPublicKeySignature(CONTRACT_ADDRESS, signature);

Expand Down
48 changes: 23 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"scripts": {
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && npm run typechain",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && pnpm typechain",
"deploy:contracts": "hardhat deploy",
"lint": "npm run lint:sol && npm run lint:ts && npm run prettier:check",
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
Expand Down Expand Up @@ -66,7 +65,7 @@
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.8.0",
"fhevmjs": "^0.2.0",
"fhevmjs": "^0.3.1",
"fs-extra": "^10.1.0",
"ganache": "^7.9.0",
"hardhat": "^2.19.4",
Expand Down
2 changes: 1 addition & 1 deletion tasks/taskIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ task('task:identity:balanceOf')

const instance = await createInstance(erc20Address, signers[user], ethers);

const token = instance.getTokenSignature(erc20Address)!;
const token = instance.getPublicKey(erc20Address)!;

const balance = await erc20.connect(signers[user]).balanceOf(signers[user], token.publicKey, token.signature);
console.log(`=> ${chalk.bold('Balance')}: ${instance.decrypt(erc20Address, balance)} tokens`);
Expand Down
14 changes: 7 additions & 7 deletions tasks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ export const createInstance = async (contractAddress: string, account: Signer, e
publicKey = decoded[0];
}
const instance = await fhevmjs.createInstance({ chainId, publicKey });
await generateToken(contractAddress, account, instance);
await generatePublicKey(contractAddress, account, instance);
return instance;
};

const generateToken = async (contractAddress: string, signer: Signer, instance: FhevmInstance) => {
const generatePublicKey = async (contractAddress: string, signer: Signer, instance: FhevmInstance) => {
// Generate token to decrypt
const generatedToken = instance.generateToken({
const generatedToken = instance.generatePublicKey({
verifyingContract: contractAddress,
});

// Sign the public key
const signature = await signer.signTypedData(
generatedToken.token.domain,
{ Reencrypt: generatedToken.token.types.Reencrypt }, // Need to remove EIP712Domain from types
generatedToken.token.message,
generatedToken.eip712.domain,
{ Reencrypt: generatedToken.eip712.types.Reencrypt }, // Need to remove EIP712Domain from types
generatedToken.eip712.message,
);
instance.setTokenSignature(contractAddress, signature);
instance.setSignature(contractAddress, signature);
};
6 changes: 3 additions & 3 deletions test/blindAuction/BlindAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('BlindAuction', function () {
const txAliceStop = await this.blindAuction.connect(this.signers.alice).stop();
await txAliceStop.wait();

const tokenCarol = this.instances.carol.getTokenSignature(this.contractAddress)!;
const tokenCarol = this.instances.carol.getPublicKey(this.contractAddress)!;
const carolBidAmountCheckEnc = await this.blindAuction
.connect(this.signers.carol)
.getBid(tokenCarol.publicKey, tokenCarol.signature);
const carolBidAmountCheckDec = this.instances.carol.decrypt(this.contractAddress, carolBidAmountCheckEnc);
expect(carolBidAmountCheckDec).to.equal(20);

const tokenBob = this.instances.bob.getTokenSignature(this.contractAddress)!;
const tokenBob = this.instances.bob.getPublicKey(this.contractAddress)!;
const bobBidAmountCheckEnc = await this.blindAuction
.connect(this.signers.bob)
.getBid(tokenBob.publicKey, tokenBob.signature);
Expand All @@ -101,7 +101,7 @@ describe('BlindAuction', function () {
await txCarolWithdraw.wait();

const instance = await createInstances(this.contractERC20Address, ethers, this.signers);
const tokenAlice = instance.alice.getTokenSignature(this.contractERC20Address)!;
const tokenAlice = instance.alice.getPublicKey(this.contractERC20Address)!;
const encryptedBalanceAlice = await this.erc20.balanceOf(
this.signers.alice,
tokenAlice.publicKey,
Expand Down
14 changes: 7 additions & 7 deletions test/encryptedERC20/EncryptedERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('EncryptedERC20', function () {
const transaction = await this.erc20.mint(1000);
await transaction.wait();
// Call the method
const token = this.instances.alice.getTokenSignature(this.contractAddress) || {
const token = this.instances.alice.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand All @@ -44,7 +44,7 @@ describe('EncryptedERC20', function () {
const tx = await this.erc20['transfer(address,bytes)'](this.signers.bob.address, encryptedTransferAmount);
await tx.wait();

const tokenAlice = this.instances.alice.getTokenSignature(this.contractAddress)!;
const tokenAlice = this.instances.alice.getPublicKey(this.contractAddress)!;

const encryptedBalanceAlice = await this.erc20.balanceOf(
this.signers.alice,
Expand All @@ -59,7 +59,7 @@ describe('EncryptedERC20', function () {

const bobErc20 = this.erc20.connect(this.signers.bob);

const tokenBob = this.instances.bob.getTokenSignature(this.contractAddress)!;
const tokenBob = this.instances.bob.getPublicKey(this.contractAddress)!;

const encryptedBalanceBob = await bobErc20.balanceOf(this.signers.bob, tokenBob.publicKey, tokenBob.signature);

Expand All @@ -77,7 +77,7 @@ describe('EncryptedERC20', function () {
const tx = await this.erc20['transfer(address,bytes)'](this.signers.bob.address, encryptedTransferAmount);
await tx.wait();

const tokenAlice = this.instances.alice.getTokenSignature(this.contractAddress)!;
const tokenAlice = this.instances.alice.getPublicKey(this.contractAddress)!;

const encryptedBalanceAlice = await this.erc20.balanceOf(
this.signers.alice,
Expand All @@ -92,7 +92,7 @@ describe('EncryptedERC20', function () {

const bobErc20 = this.erc20.connect(this.signers.bob);

const tokenBob = this.instances.bob.getTokenSignature(this.contractAddress)!;
const tokenBob = this.instances.bob.getPublicKey(this.contractAddress)!;

const encryptedBalanceBob = await bobErc20.balanceOf(this.signers.bob, tokenBob.publicKey, tokenBob.signature);

Expand All @@ -119,7 +119,7 @@ describe('EncryptedERC20', function () {
);
await tx2.wait();

const tokenAlice = this.instances.alice.getTokenSignature(this.contractAddress)!;
const tokenAlice = this.instances.alice.getPublicKey(this.contractAddress)!;
const encryptedBalanceAlice = await this.erc20.balanceOf(
this.signers.alice,
tokenAlice.publicKey,
Expand All @@ -130,7 +130,7 @@ describe('EncryptedERC20', function () {
const balanceAlice = this.instances.alice.decrypt(this.contractAddress, encryptedBalanceAlice);
expect(balanceAlice).to.equal(10000); // check that transfer did not happen, as expected

const tokenBob = this.instances.bob.getTokenSignature(this.contractAddress)!;
const tokenBob = this.instances.bob.getPublicKey(this.contractAddress)!;
const encryptedBalanceBob = await bobErc20.balanceOf(this.signers.bob, tokenBob.publicKey, tokenBob.signature);
// Decrypt the balance
const balanceBob = this.instances.bob.decrypt(this.contractAddress, encryptedBalanceBob);
Expand Down
4 changes: 2 additions & 2 deletions test/governor/Comp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Comp', function () {

await transferTransac.wait();

const aliceToken = this.instances.alice.getTokenSignature(this.contractAddress) || {
const aliceToken = this.instances.alice.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand All @@ -36,7 +36,7 @@ describe('Comp', function () {
const aliceBalance = this.instances.alice.decrypt(this.contractAddress, encryptedAliceBalance);
expect(aliceBalance).to.equal(800000);

const bobToken = this.instances.bob.getTokenSignature(this.contractAddress) || {
const bobToken = this.instances.bob.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand Down
8 changes: 4 additions & 4 deletions test/identity/compliantERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('CompliantERC20', function () {

const country1Admin = new ethers.Wallet(WALLET_COUNTRY1_PK).connect(ethers.provider);
const country1Instance = await createInstance(this.contractAddress, country1Admin, ethers);
const token = country1Instance.getTokenSignature(this.contractAddress) || {
const token = country1Instance.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand All @@ -109,7 +109,7 @@ describe('CompliantERC20', function () {

expect(encryptedDaveBalance).to.throw;

const carolToken = this.instances.carol.getTokenSignature(this.contractAddress) || {
const carolToken = this.instances.carol.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand Down Expand Up @@ -172,12 +172,12 @@ describe('CompliantERC20', function () {
const txT2 = await this.identifiedErc20['transfer(address,bytes)'](this.signers.dave, amount10k);
await Promise.all([txT1.wait(), txT2.wait()]);

const carolToken = this.instances.carol.getTokenSignature(this.contractAddress) || {
const carolToken = this.instances.carol.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};

const daveToken = this.instances.dave.getTokenSignature(this.contractAddress) || {
const daveToken = this.instances.dave.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand Down
2 changes: 1 addition & 1 deletion test/identity/identityRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Identity', function () {
await allowed.wait();

// Carol use this token to access information
const token = this.instances.carol.getTokenSignature(this.contractAddress) || {
const token = this.instances.carol.getPublicKey(this.contractAddress) || {
signature: '',
publicKey: '',
};
Expand Down
Loading

0 comments on commit ece52c0

Please sign in to comment.