Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline Calender #480

Merged
merged 19 commits into from Oct 26, 2022
Merged

Baseline Calender #480

merged 19 commits into from Oct 26, 2022

Conversation

vaibhavgeek
Copy link
Collaborator

@vaibhavgeek vaibhavgeek commented Jul 11, 2022

Description

This pull request completes Milestone 1 and Milestone 2 of (ethereum-oasis-op/baseline-blips#24) which involves creation of backend APIs and circom circuit.

https://github.com/eea-oasis/baseline/tree/feature-calendar-BLIP/examples/calendar

Baseline Calendar is an example project which involves a privacy centric way of scheduling appointments. More details can be found here

Related Issue

ethereum-oasis-op/baseline-grants#70

Motivation and Context

To create a fully working implementation of baseline that can be used as another example of the power baseline has.

How Has This Been Tested

All the API endpoints have been tested manually, the circuit has been tested with custom inputs.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Request to be added as a Code Owner/Maintainer

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I commit to abide by the Responsibilities of Code Owners/Maintainers.

Copy link
Collaborator

@skosito skosito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vaibhavgeek i did one pass, and there are some comments, but i realized this is not ready for review, not sure if your intention was to go step by step, but here are some suggestions:

  • please update readme to indicate what is done, what is missing
  • if you are adding more changes, like frontend etc, please open new PR, and make this one self contained
  • please leave TODOs instead of copying whole files from other repos (for example, battleship circom file here is copied as calendar circom file)
  • since most of this code is actually using this repo https://github.com/amaurym/login-with-metamask-demo you will have to check licence and follow on rules of that licence, which i think it is just providing original licence and copyright claims if there are any, and also reference that repo
  • your readme is just grant application readme, please change that to explain intention of calendar example, how it is example of baseline process, how to run it etc, because atm this is a crud backend app without baseline in it - again i realize this can be just first step, but it is not indicated anywhere what is the scope of PR
  • please rename calender to calendar everywhere

examples/calender/README.md Outdated Show resolved Hide resolved
examples/calender/backend/config.ts Outdated Show resolved Hide resolved
examples/calender/backend/db.ts Outdated Show resolved Hide resolved
examples/calender/backend/db.ts Outdated Show resolved Hide resolved
examples/calender/backend/models/appointment.model.ts Outdated Show resolved Hide resolved
examples/calender/backend/services/time/controller.ts Outdated Show resolved Hide resolved
examples/calender/backend/services/time/controller.ts Outdated Show resolved Hide resolved
examples/calender/backend/services/time/controller.ts Outdated Show resolved Hide resolved
examples/calender/backend/services/time/controller.ts Outdated Show resolved Hide resolved
examples/calender/circuits/calender.circom Outdated Show resolved Hide resolved
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`
}
})).data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

headers: {
Authorization: `Bearer ${accessToken}`
}
})).data.appointment;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code .

}
}

const coinbase = await web3.eth.getCoinbase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need coinbase instance for this PR?
Can we not use ethereum instance to get the selected Address?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes the case scenario if the person has coinbase wallet but not metamask, so it serves for both.

setLoading(true);

// Look if user with current publicAddress is already present on backend
const users = (await axios.get<User[]>(`${process.env.REACT_APP_BACKEND_URL}/users?publicAddress=${publicAddress}`)).data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

const {publicAddressSigned, signature} = await handleSignMessage({"publicAddressSigned": publicAddress, "nonce": users[0].nonce});
const auth = await handleAuthenticate({"publicAddress": publicAddressSigned, "signature": signature});
await onLoggedIn(auth)
onLoggedIn(auth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we calling the same onLoggedIn twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed one instance of login.

const {publicAddressSigned, signature} = await handleSignMessage({"publicAddressSigned": publicAddress, "nonce": user.nonce});
const auth = await handleAuthenticate({"publicAddress": publicAddressSigned, "signature": signature});
await onLoggedIn(auth)
onLoggedIn(auth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed one instance of login.

headers: {
Authorization: `Bearer ${accessToken}`
}
})).data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

headers: {
Authorization: `Bearer ${accessToken}`
}
})).data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`
}
})).data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible error if axios call fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

const timesInitial = () => {
const timeReturn = [];
var someDate = new Date(selectedDate);
someDate.setHours(8, 0, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a JSDoc as to what is happening here and at line 78

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets the Time availability API. I feel the code is self explanatory here.

const booked = await getTimeAvailAPI(id);
booked.forEach((booking: any) => {
const tempTimes = [...times];
var foundIndex = tempTimes.findIndex(x => parseInt((x.startTime.getTime()/1000).toString()) == (booked.timeStart/1000));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I didn't understand the logic here.
Are we assuming that x.startTime andbooked.timeStart are going to be A * 1000 values? what if x.startTime is 1234567, and hence logic returns 1234.567`

Is that acceptable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the condition is just on equality. It's just that server responses were few ms delayed and hence there was an error if I just directly compared them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

const username = user && user.username;

return (
<div className="Profile">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite same content is in another file too. Can this be extracted out, and used in different files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two files, would have made sense if there were more than 2 instances.

username: string,
publicAddress: string,
nonce: string,
createdAt: string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need createdAt and updatedAt in front-end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an IEF, do we need this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone else wants to test out the circuit independently without running the entire backend-frontend, this file helps a lot. I strongly recommend to keep it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but the purpose of this file is not clear. Can you add a JSDoc comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests out the fixed merkle tree.

);

/*
// Changed by Jordi point
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not written manually

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, but the unused content can be deleted, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather keep it because the comments are also generated by the circuit compiler. It will get overwritten when the person runs the compiler themselves. The same is also seen in battleship example.

);

vk.beta2 = Pairing.G2Point(
[7510344623763166301235773457354776013635624944306764504873170219490212633507,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If somebody tries to extend this work, it will be better to add comments to signify what these numbers relate to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is polynomialization of the circuit by circom code, not manually written code. This is generated on running
sh setup.sh and sh proof.sh files.

skosito
skosito previously approved these changes Oct 26, 2022
Copy link
Collaborator

@skosito skosito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved from my side too, we will merge after comments from @Manik-Jain are addressed too

@Manik-Jain
Copy link
Collaborator

@vaibhavgeek Could you please push your latest changes? I see the comments, but not the updated code.
Probably you missed to push your changes. The last commit was made on October 24, 2022 to remove console logs.

https://github.com/eea-oasis/baseline/pull/480/commits

@vaibhavgeek
Copy link
Collaborator Author

@Manik-Jain I have made changes to the files requested in the frontend as well, thanks for reviewing the pull request in detail.

Copy link
Collaborator

@Therecanbeonlyone1969 Therecanbeonlyone1969 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your comments were addressed with the last commit @Manik-Jain

@Manik-Jain Manik-Jain merged commit d7aaf71 into main Oct 26, 2022
@Manik-Jain Manik-Jain deleted the feature-calendar-BLIP branch October 26, 2022 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants