Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gongamax committed Jul 16, 2024
2 parents 8b43d06 + f97a9da commit ef02b1f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
19 changes: 12 additions & 7 deletions code/app/(tabs)/home/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const HomeScreen = () => {
const savedWallet = await getValueFor('wallet');

// Get the identity of the user
const userIdentity = await getIdentity(savedWallet.address, identityFactory);
const userIdentity = await getIdentity(savedWallet.address, identityFactory, signer);

if (!userIdentity) {
Alert.alert('Warning', `Identity for wallet: ${savedWallet.address} not found.`);
Expand All @@ -181,9 +181,6 @@ const HomeScreen = () => {

// Create the user wallet object (ethers.Wallet)
const userWallet = getWallet(savedWallet.privateKey, provider);
console.log('User Wallet:', userWallet.address);
console.log('Saved wallet:', savedWallet.address);
console.log(userWallet.address !== savedWallet.address);
if (userWallet.address.toLowerCase() !== savedWallet.address) {
const onCancel = () => {
setModalVisible(false);
Expand Down Expand Up @@ -214,8 +211,17 @@ const HomeScreen = () => {
institution.institutionID.toString() === form.institutionCode
) {
const issuerWallet = getWallet(institution.wallet.privateKey, provider);
console.log('Issuer Wallet:', issuerWallet.address);
await addKeyToIdentity(userIdentity, userWallet, issuerWallet, 3, 1);
const issuerContract = getContractAt(institution.address, institution.abi, issuerWallet);
const issuerKeys = await issuerContract.getKeysByPurpose(3);
const userKeys = await userIdentity.getKeysByPurpose(3);
console.log('User Keys: ', userKeys);
if (!userKeys.includes(issuerKeys[0])) {
await addKeyToIdentity(userIdentity, userWallet, issuerWallet, 3, 1);
}
} else {
Alert.alert('Warning', 'Institution not found.');
setIsSubmitting(false);
return;
}
}
}
Expand All @@ -225,7 +231,6 @@ const HomeScreen = () => {
studentNumber: form.studentNumber,
name: form.name,
});
console.log('Student Claim:', studentClaim);

await addClaim(trustedIR, userIdentity, userIdentity, userWallet, CLAIM_TOPICS_OBJ.STUDENT, studentClaim);

Expand Down
6 changes: 4 additions & 2 deletions code/app/(tabs)/validation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ const Validation = () => {
const identityFactory = getContractAt(config.identityFactory.address, config.identityFactory.abi, signer);
console.log(userAddress);
const userIdentity = await getIdentity(userAddress, identityFactory, signer);

if (userIdentity) {
const certificates = await getClaimsByTopic(userIdentity, CLAIM_TOPICS_OBJ.CERTIFICATE);
console.log('claims:', certificates);
if(certificates.length === 0) {
Alert.alert('Error', 'No certificates found');
return;
}
const claimUri = certificates[0].uri;
console.log('claimUri:', claimUri);
if (claimUri === hash(certificateLink) || claimUri === hash(hashedContent)) {
Expand Down
4 changes: 2 additions & 2 deletions code/app/emission.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Emission = () => {
});
const certificateClaim = JSON.stringify({
registrationCode: form.registrationCode,
certificate: form.certificateUri ? encrypt(form.certificateUri, form.password) : 'Certificate hash: ' + fileHash,
certificate: form.certificateUri ? encrypt(form.certificateUri, form.password) : 'Certificate hash',
});

const certificateClaimUri = form.certificateUri ? form.certificateUri : fileHash;
Expand Down Expand Up @@ -278,7 +278,7 @@ const styles = StyleSheet.create({
color: Colors.black,
},
body: {
marginTop: -45,
marginTop: -20,
marginBottom: 20,
},
title: {
Expand Down
2 changes: 1 addition & 1 deletion code/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function App() {

const handleGuestPress = () => {
save('user_type', JSON.stringify({ type: 'Guest' }));
return router.replace('/(tabs)/validation');
return router.push('/(tabs)/validation');
};

return (
Expand Down
28 changes: 14 additions & 14 deletions code/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"rpc": "https://4442-2001-8a0-f972-ce00-5c99-9c8e-a23f-8595.ngrok-free.app",
"rpc": "https://bd63-2001-818-dd0a-8c00-412a-ac2-81c1-f41a.ngrok-free.app",
"deployer": {
"address": "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199",
"privateKey": "0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e"
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
},
"identityFactory": {
"address": "0x5095d3313C76E8d29163e40a0223A5816a8037D8",
"address": "0x36C02dA8a0983159322a80FFE9F24b1acfF8B570",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -413,7 +413,7 @@
},
"trex": {
"implementationAuthority": {
"address": "0xC92B72ecf468D2642992b195bea99F9B9BB4A838",
"address": "0x82e01223d51Eb87e16A03E24687EDF0F294da6f1",
"abi": [
{
"type": "constructor",
Expand Down Expand Up @@ -1515,7 +1515,7 @@
]
},
"claimsTopicRegistry": {
"address": "0x446C29FBFEF829F81E236a2376191F648dbEF995",
"address": "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -1715,7 +1715,7 @@
]
},
"trustedIssuersRegistry": {
"address": "0x37dD26d18abeC2d311e82177f9fa58E9DC14b579",
"address": "0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2146,7 +2146,7 @@
]
},
"identityRegistry": {
"address": "0xb11f9b33ee93B1f990a805fa68817A74e82A6891",
"address": "0xFD471836031dc5108809D173A067e8486B9047A3",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2911,7 +2911,7 @@
]
},
"identityRegistryStorage": {
"address": "0x5a8E771b5D0B3d2e4d218478CB7C9029d00c4e5a",
"address": "0xc351628EB244ec633d5f21fBD6621e1a683B1181",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3473,7 +3473,7 @@
]
},
"modularCompliance": {
"address": "0x72ed6e892932c90cDF3c2FDC436d06db4aF23EEC",
"address": "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3975,7 +3975,7 @@
]
},
"token": {
"address": "0x9A7848b9E60C7619f162880c7CA5Cbca80998034",
"address": "0x1429859428C0aBc9C2C47C8Ee9FBaf82cFA0F20f",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -5651,10 +5651,10 @@
{
"institutionID": 3117,
"wallet": {
"address": "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199",
"privateKey": "0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e"
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
},
"address": "0xb2AA9bf762878462382A34eB4EC1f041E0071081",
"address": "0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07",
"abi": [
{
"type": "constructor",
Expand Down
11 changes: 8 additions & 3 deletions code/services/ethereum/scripts/claims/getClaimsByTopic.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ async function getClaimsByTopic(identity, topic) {
).catch(error => {
console.error('[x] Error getting institution claims:', error);
});

} else if (topic === CLAIM_TOPICS_OBJ.CERTIFICATE) {
const certificateClaims = await identity.getClaimIdsByTopic(
ethers.id(CLAIM_TOPICS_OBJ.CERTIFICATE)
);
try {
certificateClaims = await identity.getClaimIdsByTopic(
ethers.id(CLAIM_TOPICS_OBJ.CERTIFICATE)
);
} catch (error) {
console.error('[x] Error getting certificate claims:', error);
}

await Promise.all(
certificateClaims.map(async claimId => {
Expand Down
Empty file.

0 comments on commit ef02b1f

Please sign in to comment.