resolve method

  1. @override
Future<AttestationResponse?> resolve({
  1. required String attestationId,
  2. required String? attestationJWT,
})
override

Implementation

@override
Future<AttestationResponse?> resolve({
  required String attestationId,
  required String? attestationJWT,
}) async {
  try {
    // resolve v2
    final hasAttestationJWT = (attestationJWT ?? '').isNotEmpty;
    final v2Response = await resolveV2(attestationId, attestationJWT);
    if (v2Response != null) {
      return v2Response;
    }

    // A v2 attestation was present but could not be validated. Do not fall
    // back to the v1 lookup; resolve to UNKNOWN instead.
    if (hasAttestationJWT) {
      throw AttestationNotValid(
        code: 400,
        message: 'Attestation for this dapp could not be validated',
      );
    }

    // resolve v1
    final uri = Uri.parse(
      '$_verifyUrl/attestation/$attestationId?v2Supported=true',
    );
    _core.logger.d('[$runtimeType] resolve attestationId: $attestationId');
    final response = await _httpClient.get(uri).timeout(Duration(seconds: 5));
    if (response.statusCode == 404 || response.body.isEmpty) {
      throw AttestationNotFound(
        code: 404,
        message: 'Attestion for this dapp could not be found',
      );
    }
    if (response.statusCode != 200) {
      throw Exception('Attestation response error: ${response.statusCode}');
    }
    return AttestationResponse.fromJson(jsonDecode(response.body));
  } catch (e, s) {
    if (e is! AttestationNotFound && e is! AttestationNotValid) {
      _core.logger.e('[$runtimeType] resolve error: $e, $s');
    }
    rethrow;
  }
}