Create message array

Important

Before extracting and verifying proof, please ensure that you have fetched Verifiable Credential.

Create a Uint8Array array (vcmessages) by converting stringified JSON representations of Verifiable Credential (VC) attributes and selectively disclosed keys. Verify that the selective disclosure keys align with the keys in the credential subject, and raise an error if there is a mismatch.

const {
  id,
  "@context": context,
  type,
  issuer,
  issuanceDate,
  credentialSchema,
  credentialStatus,
  credentialSubject,
} = vc;
const vcmessages = [
  Uint8Array.from(Buffer.from(JSON.stringify(id), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(context), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(type), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(issuer), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(issuanceDate), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(credentialSchema), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(credentialStatus), "utf8")),
];

Object.keys(credentialSubject).forEach((key) => {
  if (selectiveDisclosureKeys.includes(key)) {
    vcmessages.push(
      Uint8Array.from(
        Buffer.from(JSON.stringify(credentialSubject[key]), "utf8")
      )
    );
  } else {
    throw new Error(
      `The selective disclosure keys and the keys in credential subject don't match. Please ensure that it is a valid VC.`
    );
  }
});

Next Up: Extract and Verify →