import { get } from "lodash" ; import { digestDocument } from "./digest" ; import { OpenAttestationDocument } from "../__generated__/schema.2.0" ; import { WrappedDocument } from "./types" ; import { checkProof } from "../shared/merkle" ; export const verify = < T extends OpenAttestationDocument = OpenAttestationDocument > ( document ) : document is WrappedDocument < T > => { const signature = get ( document , "signature" ) ; if ( ! signature ) { return false ; } const digest = digestDocument ( document ) ; const targetHash = get ( document , "signature.targetHash" ) ; if ( digest !== targetHash ) return false ; return checkProof ( document ?. signature ?. proof ?? [ ] , document ?. signature ?. merkleRoot , document ?. signature ?. targetHash ) ; } ;