Skip to content

Commit

Permalink
Changed deploy claim issuer. Script not working propertly yet
Browse files Browse the repository at this point in the history
  • Loading branch information
49513 - Diogo Rodrigues committed Jul 16, 2024
1 parent ef02b1f commit baeed71
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 31 deletions.
21 changes: 10 additions & 11 deletions code/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
},
"identityFactory": {
"address": "0x36C02dA8a0983159322a80FFE9F24b1acfF8B570",
"address": "0x4C4a2f8c81640e47606d3fd77B353E87Ba015584",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -413,7 +413,7 @@
},
"trex": {
"implementationAuthority": {
"address": "0x82e01223d51Eb87e16A03E24687EDF0F294da6f1",
"address": "0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7",
"abi": [
{
"type": "constructor",
Expand Down Expand Up @@ -1515,7 +1515,7 @@
]
},
"claimsTopicRegistry": {
"address": "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0",
"address": "0x202CCe504e04bEd6fC0521238dDf04Bc9E8E15aB",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -1715,7 +1715,7 @@
]
},
"trustedIssuersRegistry": {
"address": "0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650",
"address": "0xf4B146FbA71F41E0592668ffbF264F1D186b2Ca8",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2146,7 +2146,7 @@
]
},
"identityRegistry": {
"address": "0xFD471836031dc5108809D173A067e8486B9047A3",
"address": "0x4EE6eCAD1c2Dae9f525404De8555724e3c35d07B",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2911,7 +2911,7 @@
]
},
"identityRegistryStorage": {
"address": "0xc351628EB244ec633d5f21fBD6621e1a683B1181",
"address": "0x172076E0166D1F9Cc711C77Adf8488051744980C",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3473,7 +3473,7 @@
]
},
"modularCompliance": {
"address": "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc",
"address": "0xBEc49fA140aCaA83533fB00A2BB19bDdd0290f25",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3975,7 +3975,7 @@
]
},
"token": {
"address": "0x1429859428C0aBc9C2C47C8Ee9FBaf82cFA0F20f",
"address": "0xD84379CEae14AA33C123Af12424A37803F885889",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -5651,10 +5651,9 @@
{
"institutionID": 3117,
"wallet": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"address": "0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07",
"address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
"abi": [
{
"type": "constructor",
Expand Down
57 changes: 57 additions & 0 deletions code/deployClaimIssuer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Set the path to the directory where the deploy claim issuer script is located
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Set the path to the config file
DEPLOY_CLAIM_ISSUER="$CURRENT_DIR/services/ethereum/scripts/claimIssuer/deploy-claim-issuer.js"

# Function to check if input is empty
is_empty() {
if [[ -z "$1" ]]; then
return 0
else
return 1
fi
}

# Ask the user for trusted issuer registry address
while true; do
read -p "[W] Enter the address of the trusted issuer registry: " TRUSTED_ISSUER_REGISTRY
if is_empty "$TRUSTED_ISSUER_REGISTRY"; then
echo "Trusted issuer registry cannot be empty. Please try again."
else
break
fi
done

# Ask for institution wallet private key
while true; do
read -s -p "[$] Institution Wallet Private Key: " INSTITUTION_WALLET_PRIVATE_KEY
echo
if is_empty "$INSTITUTION_WALLET_PRIVATE_KEY"; then
echo "Institution wallet private key cannot be empty. Please try again."
else
break
fi
done

# Ask for the institution code
while true; do
read -p "[#] Institution Code: " INSTITUTION_CODE
echo
if is_empty "$INSTITUTION_CODE"; then
echo "Code cannot be empty. Please try again."
else
break
fi
done

# Call the deploy claim issuer script
node -e "
const deployClaimIssuer = require('$DEPLOY_CLAIM_ISSUER').deployClaimIssuer;
deployClaimIssuer('$TRUSTED_ISSUER_REGISTRY', undefined, undefined, '$INSTITUTION_WALLET_PRIVATE_KEY', '$INSTITUTION_CODE');
"



26 changes: 19 additions & 7 deletions code/services/ethereum/scripts/claimIssuer/deploy-claim-issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
const config = require('../../../../config.json');
const { useRpcProvider } = require('../utils/useRpcProvider');
const { addClaim } = require('../claims/add-claim');
const { CLAIM_TOPICS_OBJ } = require('../claims/claimTopics');
const { CLAIM_TOPICS_OBJ, CLAIM_TOPICS } = require('../claims/claimTopics');
const { addIssuerToConfig } = require('../../../config/addIssuerToConfig');

const SIGN_CLAIM_PURPOSE = 3;
Expand All @@ -27,20 +27,32 @@ const ECDSA_KEY_TYPE = 1;
*/
async function deployClaimIssuer(
TIR,
claimTopics,
issuerWallet,
issuerWallet = undefined,
deployerTIR = undefined,
institutionCode = undefined,
privateKey = undefined
privateKey = undefined,
institutionCode = undefined
) {
try {
if (deployerTIR === undefined) {
if (!deployerTIR ) {
deployerTIR = useRpcProvider(
config.rpc,
config.deployer.privateKey
); // app owner
}

if (!issuerWallet) {
console.log('Creating issuer wallet');
console.log('privateKey:', privateKey);
const provider = new ethers.JsonRpcProvider(config.rpc);
issuerWallet = new ethers.Wallet(privateKey, provider);
}

console.log('TIR:', TIR);
console.log('issuerWallet:', issuerWallet);
console.log('deployerTIR:', deployerTIR);
console.log('privateKey:', privateKey);
console.log('institutionCode:', institutionCode);

console.log(
'[!] Deploying ClaimIssuer for wallet with address:',
issuerWallet.address
Expand Down Expand Up @@ -73,7 +85,7 @@ async function deployClaimIssuer(
`[+] Deployed ClaimIssuer: ${await claimIssuerContract.getAddress()}`
);

const ethersClaimTopics = claimTopics.map(topic => ethers.id(topic));
const ethersClaimTopics = CLAIM_TOPICS.map(topic => ethers.id(topic));

// Add the claimIssuer to the trusted issuers registry
await TIR.connect(deployerTIR).addTrustedIssuer(
Expand Down
3 changes: 1 addition & 2 deletions code/services/ethereum/scripts/deploy-full-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ async function main() {
// Initial trusted issuers for the CLAIM_TOPICS = ['INSTITUTION', 'STUDENT', 'CERTIFICATE'] is the app owner
await deployClaimIssuer(
trustedIR,
CLAIM_TOPICS,
deployer,
deployer,
config.deployer.privateKey,
3117,
config.deployer.privateKey
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const {
CLAIM_TOPICS
} = require('../../scripts/claims/claimTopics');
const { getClaimsByTopic } = require('../../scripts/claims/getClaimsByTopic');
const hash = require('../../scripts/utils/encryption/hash');
const { deployIdentity } = require('../../scripts/identities/deploy-identity');
const { getIdentity } = require('../../scripts/identities/getIdentity');

describe('ClaimIssuer Creation', () => {
it('Should add claim issuer', async () => {
Expand All @@ -24,7 +21,6 @@ describe('ClaimIssuer Creation', () => {

const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
claimTopics,
deployerWallet,
deployerWallet
);
Expand Down Expand Up @@ -63,14 +59,12 @@ describe('ClaimIssuer Creation', () => {

const cicAndTir1 = await deployClaimIssuer(
trustedIssuersRegistry,
claimTopics,
claimIssuerDeployer1,
tirDeployer
);

const cicAndTir2 = await deployClaimIssuer(
trustedIssuersRegistry,
claimTopics,
claimIssuerDeployer2,
tirDeployer
);
Expand All @@ -89,9 +83,9 @@ describe('ClaimIssuer Creation', () => {

const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
CLAIM_TOPICS,
aliceWallet,
deployerWallet,
undefined,
3117
);

Expand All @@ -108,4 +102,32 @@ describe('ClaimIssuer Creation', () => {

expect(ethers.toUtf8String(claims[0].data)).to.be.equal('3117');
});

it('Should create a claim issuer with some data', async () => {
const { deployerWallet, trustedIssuersRegistry, identityFactory } =
await loadFixture(deployFullTREXSuiteFixture);

const privKey = '0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656'

const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
undefined,
deployerWallet,
privKey,
3311
);

expect((await cicAndTir.TIR.getTrustedIssuers())[0]).to.be.equal(
await cicAndTir.claimIssuerContract.getAddress()
);

// console.log('Wallet:', deployerWallet);

// const claims = await getClaimsByTopic(
// cicAndTir.claimIssuerContract,
// CLAIM_TOPICS_OBJ.INSTITUTION
// );

// expect(ethers.toUtf8String(claims[0].data)).to.be.equal('3311');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('Verification of Trusted Issuer', () => {
// Deploy a claim issuer
const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
claimTopics,
deployerWallet,
deployerWallet
);
Expand All @@ -44,7 +43,6 @@ describe('Verification of Trusted Issuer', () => {
// Deploy a claim issuer
const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
claimTopics,
deployerWallet,
deployerWallet
);
Expand Down
1 change: 0 additions & 1 deletion code/services/ethereum/test/claims/addClaims.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Claims Test', () => {
// Deploy a claim issuer
const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
CLAIM_TOPICS,
claimIssuerWallet,
deployerWallet
);
Expand Down
1 change: 0 additions & 1 deletion code/services/ethereum/test/claims/getClaims.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('get all the claims of an identity by topic', function () {
// Deploy a claim issuer
const cicAndTir = await deployClaimIssuer(
trustedIssuersRegistry,
CLAIM_TOPICS,
claimIssuerWallet,
deployerWallet
);
Expand Down

0 comments on commit baeed71

Please sign in to comment.