Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
2
Indexable
Never
import { Identity } from "@semaphore-protocol/identity";
import { Group } from "@semaphore-protocol/group";
import { useEffect, useState } from "react";

const {
  generateProof,
  verifyProof,
  packToSolidityProof,
} = require("@semaphore-protocol/proof");

export const useGenerateProof = (identityKey) => {
  const [identity, setIdentity] = useState(new Identity(identityKey));
  const [identityCommitment, setIdentityCommitment] = useState(
    identity.generateCommitment().toString()
  );

  const [externalNullifier, setExternalNullifier] = useState(100);
  const [signal, setSignal] = useState("proposal_1");
  const [foolProof, setFoolProof] = useState(null);

  let fetchData = async () => {
    const group = new Group(16);
    group.addMember(identityCommitment);
    console.log("group...", group);

    let foolProofTemp = await generateProof(
      identity,
      group,
      externalNullifier,
      signal,
      {
        zkeyFilePath:
          "https://www.trusted-setup-pse.org/semaphore/16/semaphore.zkey",
        wasmFilePath:
          "https://www.trusted-setup-pse.org/semaphore/16/semaphore.wasm",
      }
    );
    console.log("foolProofTemp...", foolProofTemp);
    setFoolProof(foolProofTemp);
  };

  useEffect(() => {
    fetchData();
  }, []);

  return [foolProof];
};

//  const fullProof = await generateProof(
//     identity,
//     group,
//     externalNullifier,
//     signal,
//     {
//       zkeyFilePath:
//         'https://www.trusted-setup-pse.org/semaphore/16/semaphore.zkey',
//       wasmFilePath:
//         'https://www.trusted-setup-pse.org/semaphore/16/semaphore.wasm',
//     },
//   )