Create message array

Important

Before you create message array please ensure you have extracted relevant details(link).

Create a Uint8Array of various keys from the VC, maintaining an array for keys to handle the revealed indexes during selective disclosure.

// creation of the Uint8Array of VC.
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")),
  Uint8Array.from(Buffer.from(JSON.stringify(credentialSubject.id), "utf8")),
  Uint8Array.from(Buffer.from(JSON.stringify(credentialSubject.name), "utf8")),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.birthDate), "utf8")
  ),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.customerReference), "utf8")
  ),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.expiryDate), "utf8")
  ),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.publicAddress), "utf8")
  ),
  Uint8Array.from(Buffer.from(JSON.stringify(credentialSubject.type), "utf8")),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.licenseNumber), "utf8")
  ),
  Uint8Array.from(
    Buffer.from(JSON.stringify(credentialSubject.stateOfIssuance), "utf8")
  ),
];
const vcmessagesIndexes = [
  "id",
  "context",
  "type",
  "issuer",
  "issuanceDate",
  "credentialSchema",
  "credentialStatus",
  "credentialSubject.id",
  "credentialSubject.name",
  "credentialSubject.birthDate",
  "credentialSubject.customerReference",
  "credentialSubject.expiryDate",
  "credentialSubject.publicAddress",
  "credentialSubject.type",
  "credentialSubject.licenseNumber",
  "credentialSubject.stateOfIssuance",
];

For your choice of verifiable credential, add their indexes. Here, we have added for Passport and Driver's Licence.

if (credentialSubject.type === "PassportCredential") {
  vcmessages.push(
    Uint8Array.from(
      Buffer.from(JSON.stringify(credentialSubject.passportNumber), "utf8")
    ),
    Uint8Array.from(
      Buffer.from(JSON.stringify(credentialSubject.nationality), "utf8")
    )
  );
  vcmessagesIndexes.push(
    "credentialSubject.passportNumber",
    "credentialSubject.nationality"
  );
} else {
  vcmessages.push(
    Uint8Array.from(
      Buffer.from(JSON.stringify(credentialSubject.licenseNumber), "utf8")
    ),
    Uint8Array.from(
      Buffer.from(JSON.stringify(credentialSubject.stateOfIssuance), "utf8")
    )
  );
  vcmessagesIndexes.push(
    "credentialSubject.licenseNumber",
    "credentialSubject.stateOfIssuance"
  );
}

Next Up: Verify →