-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(maci-signup): implement signup with MACI and EAS #14
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Button } from "./ui/Button" | ||
import { useEffect } from "react" | ||
import { useAccount } from "wagmi" | ||
import { useProfile } from "~/hooks/useProfile" | ||
|
||
/** | ||
* Signup to the MACI contract for voting | ||
* @returns | ||
*/ | ||
export const MaciSignup = () => { | ||
|
||
const { address } = useAccount() | ||
const profile = useProfile(address) | ||
|
||
console.log("address", address) | ||
console.log("profile", profile) | ||
|
||
useEffect(() => { | ||
const _getAttestations = async () => { | ||
// const profile = useProfile(address) // Fetch the profile for the current Ethereum address | ||
console.log("profile", profile.data) | ||
} | ||
|
||
_getAttestations() | ||
}, []) | ||
|
||
const signup = () => { | ||
console.log("signup") | ||
|
||
} | ||
|
||
return ( | ||
<Button onClick={signup}>Signup to MACI</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { signup } from "maci-cli"; | ||
import { useAccount } from "wagmi"; | ||
import { eas } from "~/config"; | ||
import { genRandomBabyJubValue } from "maci-crypto"; | ||
import { Keypair, PrivKey } from "maci-domainobjs"; | ||
import { config } from "~/config"; | ||
import { toBytes } from "viem"; | ||
import { useEthersSigner } from "~/hooks/useEthersSigner"; | ||
|
||
/** | ||
* Signup to MACI | ||
*/ | ||
export const maciSignup = async () => { | ||
// get the ethereum address of the connected user | ||
const { address } = useAccount(); | ||
|
||
// get the signer | ||
const signer = useEthersSigner() | ||
|
||
// generate the maci keypair from a signature | ||
// 1. request signature | ||
|
||
// 2. generate private key (mock for now) | ||
const privateKey = new PrivKey(genRandomBabyJubValue()); | ||
|
||
// 3. generate keypair | ||
const keypair = new Keypair(privateKey) | ||
|
||
// 4. save them to local storage | ||
localStorage.setItem("maciPrivateKey", privateKey.serialize()); | ||
localStorage.setItem("maciPublicKey", keypair.pubKey.serialize()); | ||
|
||
// 5. get the attestation and eas related data | ||
const schema = eas.schemas.badgeholder; | ||
const attester = eas.schemas.badgeholderAttester; | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Badgeholder is the same as voter. const { data: isApproved } = useApprovedVoter(address);
// and on server-side
const isApproved = await fetchApprovedVoter(address); |
||
const attestation = "todo" | ||
|
||
// 6. call the maci signup function | ||
const stateIndex = await signup({ | ||
maciPubKey: keypair.pubKey.serialize(), | ||
maciAddress: config.maciAddress, | ||
sgDataArg: toBytes(attestation).toString(), | ||
// for now we can leave out the initial voice credit proxy data | ||
// signer to be added once new package is published | ||
}) | ||
|
||
// 7. save the state index to local storage | ||
localStorage.setItem("userStateIndex", stateIndex.toString()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also be added to env.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary, but recommended, because it can verify if it's configured correctly before running the app via a Zod schema. For example: