Skip to content

Latest commit

 

History

History
85 lines (75 loc) · 2.51 KB

how-to-consume-proofs.md

File metadata and controls

85 lines (75 loc) · 2.51 KB

✅ How to consume proofs?

Check if user provided JSON proof is valid

The proof source code is stored in this repository, and all the necessary utilities are bundled in an npm package. To install the package, follow these steps:

npm i idmask-zk-programs

To verify user provided JSON proof:

import { verify } from 'o1js'
import { proofOfAge } from 'idmask-zk-programs'

// this is a user supplied JSON proof
const proof = {
  publicInput: ["21"],
  publicOutput: ["1"],
  maxProofsVerified: 0,
  proof: "KChzdGF...KSkpKSkp"
}
const { verificationKey } = proofOfAge.compile()
const isProofValid = await verify(proof, verificationKey)

console.log(
  `Is proof valid? ${isProofValid}`,
  `Proof of age of at least ${proof.publicInput[0]} years`
)

Check if provided public address has an associated proof

// user Mina address
const address = 'B62qqgtZqqnDr7BzyNnYguqnHQnpMDyTSEYfWj4r1qkEYcfvszkp8zt' 
const graphQLArchiveNodeUrl = 'https://berkeley.graphql.minaexplorer.com/'
const zkAppAddress = 'B62qqpAFkz374qJpuFKYZPjT1KxSmnLoY4zEc878FaW4DSxgYNXZiny'

const response = await fetch(graphQLArchiveNodeUrl, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: `
      query MyQuery {
        events(query: {
          zkAppCommandHash: {
            zkappCommand: {
              accountUpdates: {
                body: {publicKey: "${zkAppAddress}"}
              },
              feePayer: {
                body: {
                  publicKey: "${address}"
                }
              }
            }
          },
          canonical: true
        }) {
          dateTime
          event
          zkAppCommandHash {
            zkappCommand {
              feePayer {
                body {
                  publicKey
                }
              }
            }
          }
        }
      }
    `,
  }),
})
const response_ = await response.json()

const hasProof = response_.data.events.length > 0

console.log(
  `Address has an asocaited proof? ${hasProof}`,
  `Age of at least ${response_.data.events[0].event[0]}`
)