compareW3cCredentialAndPlaintext function

bool compareW3cCredentialAndPlaintext(
  1. dynamic w3cCred,
  2. dynamic plaintext
)

Checks weather a W3C-Credential containing all attribute hashes belongs to a Plaintext Credential or not.

Implementation

bool compareW3cCredentialAndPlaintext(dynamic w3cCred, dynamic plaintext) {
  var w3cMap = credentialToMap(w3cCred);
  var plainMap = credentialToMap(plaintext);
  if (w3cMap.containsKey('credentialSubject')) {
    w3cMap = w3cMap['credentialSubject'];
  }
  if (plainMap['id'] != w3cMap['id']) {
    throw Exception('Ids of given credentials do not match');
  }
  if (plainMap['hashAlg'] != 'keccak-256') {
    throw Exception(
        'Hashing Algorithm ${plainMap['hashAlg']} is not supported');
  }
  return _checkHashes(w3cMap, plainMap);
}