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

fix: merkle root format #29

Merged
merged 7 commits into from
May 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/Voting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, styled, Button } from '@mui/material';
import { IDKitWidget, useIDKit } from '@worldcoin/idkit';
import { usePublicClient } from 'wagmi';
import { useAccount } from 'wagmi';
import { decodeAbiParameters, encodePacked, Hex, parseAbiParameters } from 'viem';
import { Address, decodeAbiParameters, encodePacked, Hex, hexToBigInt, numberToHex, parseAbiParameters } from 'viem';
import JSConfetti from 'js-confetti';
import { useConnectModal } from '@rainbow-me/rainbowkit';
import { track } from '@vercel/analytics';
Expand Down Expand Up @@ -71,7 +71,14 @@ export const Voting = () => {
});
}

const [decodedMerfleRoot] = decodeAbiParameters(parseAbiParameters('uint256 merkle_root'), merkle_root as Hex);
// Format merkle root to bytes32
const merkle_root_bigInt = hexToBigInt(merkle_root as Address, { size: 32 });
const merkle_root_bytes32 = numberToHex(merkle_root_bigInt, { size: 32 });

const [decodedMerfleRoot] = decodeAbiParameters(
parseAbiParameters('uint256 merkle_root'),
merkle_root_bytes32 as Hex,
);
const [decodedNullifierHash] = decodeAbiParameters(
parseAbiParameters('uint256 nullifier_hash'),
nullifier_hash as Hex,
Expand Down
Loading