getCredential method

Implementation

@override
Future<CrossmintCredentialRecord> getCredential(
  CrossmintCredentialQuery query,
) async {
  final CrossmintJsonMap response = await _service.getCredential(query);
  final CrossmintJsonMap? unencryptedCredential = readOptionalMap(
    response['unencryptedCredential'],
  );
  final CrossmintJsonMap? encryptedCredential = readOptionalMap(
    response['encryptedCredential'],
  );
  final String? credentialId =
      readOptionalString(response, const <String>['id', 'credentialId']) ??
      (unencryptedCredential == null
          ? null
          : readOptionalString(unencryptedCredential, const <String>[
              'id',
              'credentialId',
            ])) ??
      (encryptedCredential == null
          ? null
          : readOptionalString(encryptedCredential, const <String>[
              'id',
              'credentialId',
            ]));
  if (credentialId == null) {
    throw CrossmintCredentialsException(
      'Missing required identifier for credential.',
      cause: response,
    );
  }
  return CrossmintCredentialRecord(id: credentialId, raw: response);
}