import { WrappedDocument } from "./types" ; import { digestCredential } from "./digest" ; import { checkProof } from "../shared/merkle" ; import { decodeSalt , salt } from "./salt" ; export const verify = < T extends WrappedDocument > ( document ) : document is WrappedDocument < T > => { if ( ! document . proof ) { return false ; } const { proof , ... documentWithoutProof } = document ; const decodedSalts = decodeSalt ( document . proof . salts ) ; const visibleSalts = salt ( documentWithoutProof ) ; if ( visibleSalts . length !== decodedSalts . length ) return false ; const digest = digestCredential ( documentWithoutProof , decodedSalts , document . proof . privacy . obfuscated ) ; const targetHash = document . proof . targetHash ; if ( digest !== targetHash ) return false ; return checkProof ( document . proof . proofs , document . proof . merkleRoot , document . proof . targetHash ) ; } ;