Set revealed indexes

Important

Before you set revealed indexes please ensure you have verifief the VC received from the Issuer.

Set the revealed indexes based on the requested keys by the verifier to enable selective disclosure of specific information. Check that the requested keys align with the available fields in the VC, ensuring a seamless and secure disclosure process.

const revealedIndexes = [];
const selectiveDisclosureKeys = ['id', 'name', 'nationality'];
const selectiveDisclosureKeysWithPrefix = [];
selectiveDisclosureKeys.forEach((key) => {
  selectiveDisclosureKeysWithPrefix.push("credentialSubject." + key);
});
if (!hasAllFields(vcmessagesIndexes, selectiveDisclosureKeysWithPrefix)) {
  throw new Error(
    `Error occurred, the fields asked for are not contained in ${requestCredentialType}.`
  );
}
vcmessagesIndexes.forEach((vcindex, index) => {
  if (
    (vcindex.includes("credentialSubject") &&
      selectiveDisclosureKeysWithPrefix.includes(vcindex)) ||
    !vcindex.includes("credentialSubject")
  ) {
    revealedIndexes.push(index);
  }
});

function hasAllFields(master, sub) {
  const hasFields = [];
  sub.forEach((field) => hasFields.push(master.includes(field)));
  return !hasFields.includes(false);
}

Next Up: Create proof →