import { get , sortBy } from "lodash" ; import { keccak256 } from "js-sha3" ; import { Salt } from "./types" ; import { OpenAttestationDocument } from "../__generated__/schema.3.0" ; export const digestCredential = ( document , salts , obfuscatedData ) => { const hashedUnhashedDataArray = salts . filter ( ( salt ) => get ( document , salt . path ) ) . map ( ( salt ) => { return keccak256 ( JSON . stringify ( { [ salt . path ] : `${ salt . value }:${ get ( document , salt . path ) }` } ) ) ; } ) ; const combinedHashes = obfuscatedData . concat ( hashedUnhashedDataArray ) ; const sortedHashes = sortBy ( combinedHashes ) ; return keccak256 ( JSON . stringify ( sortedHashes ) ) ; } ;