Skip to content

Commit

Permalink
feat: added scripts for reading and removing signers
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Nov 28, 2024
1 parent 477ec78 commit d7ca775
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions tasks/taskDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import fs from 'fs';
import { task, types } from 'hardhat/config';
import type { TaskArguments } from 'hardhat/types';

import { KMSVerifier } from '../types';

task('task:deployGateway')
.addParam('privateKey', 'The deployer private key')
.addParam('ownerAddress', 'The owner address')
Expand Down Expand Up @@ -134,12 +136,18 @@ task('task:addSigners')
false,
types.boolean,
)
.addOptionalParam('customKmsVerifierAddress')
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer);
const kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = await factory.attach(kmsAdd);
for (let idx = 0; idx < taskArguments.numSigners; idx++) {
if (!taskArguments.useAddress) {
Expand All @@ -156,3 +164,47 @@ task('task:addSigners')
}
}
});

task('task:getAllSigners')
.addOptionalParam(
'customKmsVerifierAddress',
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.kmsverifier',
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier');
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = (await factory.attach(kmsAdd).connect(ethers.provider)) as KMSVerifier;
const listCurrentKMSSigners = await kmsVerifier.getSigners();
console.log('The list of current KMS Signers stored inside KMSVerifier contract is: ', listCurrentKMSSigners);
});

task('task:removeSigner')
.addParam('privateKey', 'The deployer private key')
.addParam('kmsSignerAddress', 'The KMS Signer address you wish to remove')
.addOptionalParam(
'customKmsVerifierAddress',
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.kmsverifier',
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer);
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = (await factory.attach(kmsAdd)) as KMSVerifier;
const tx = await kmsVerifier.removeSigner(taskArguments.kmsSignerAddress);
await tx.wait();
console.log(`KMS signer with address (${taskArguments.kmsSignerAddress}) was removed from KMSVerifier contract`);
});

0 comments on commit d7ca775

Please sign in to comment.