StatusList2021Entry.fromJson constructor

StatusList2021Entry.fromJson(
  1. dynamic jsonData
)

Implementation

factory StatusList2021Entry.fromJson(dynamic jsonData) {
  var data = credentialToMap(jsonData);

  String id;
  if (data.containsKey('id')) {
    id = data['id'];
  } else {
    throw FormatException('id property is needed in Credential Status');
  }

  String type;
  if (data.containsKey('type')) {
    type = data['type'];
    if (type != 'StatusList2021Entry') {
      throw Exception('type must be StatusList2021Entry');
    }
  } else {
    throw FormatException('type property is needed in credentialStatus');
  }

  String statusListIndex;
  if (data.containsKey('statusListIndex')) {
    statusListIndex = data['statusListIndex'];
  } else {
    throw Exception('statusListIndex needed');
  }

  String statusListCredential;
  if (data.containsKey('statusListCredential')) {
    statusListCredential = data['statusListCredential'];
  } else {
    throw Exception('statusListCredential needed');
  }

  CredentialStatus2021Purpose statusPurpose;
  var purpose = data['statusPurpose'];
  if (purpose == CredentialStatus2021Purpose.revocation.value) {
    statusPurpose = CredentialStatus2021Purpose.revocation;
  } else if (purpose == CredentialStatus2021Purpose.suspension.value) {
    statusPurpose = CredentialStatus2021Purpose.suspension;
  } else {
    throw Exception('Unknown StatusPurpose');
  }

  return StatusList2021Entry(
      id: id,
      statusListCredential: statusListCredential,
      statusListIndex: statusListIndex,
      statusPurpose: statusPurpose,
      originalData: data);
}