-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maci-signup): implement signup with MACI and EAS
- Loading branch information
Showing
8 changed files
with
2,256 additions
and
48 deletions.
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; | ||
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()); | ||
} |