Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main branch release 2.3.5+1 #462

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 125 additions & 83 deletions lib/iden3comm/data/data_sources/remote_iden3comm_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import 'package:polygonid_flutter_sdk/iden3comm/domain/exceptions/iden3comm_exce

class RemoteIden3commDataSource {
final Dio dio;
final http.Client client;
final StacktraceManager _stacktraceManager;

RemoteIden3commDataSource(
this.dio,
this.client,
this._stacktraceManager,
);

Expand Down Expand Up @@ -98,92 +96,40 @@ class RemoteIden3commDataSource {
throw NetworkException(errorMessage: "Invalid url", statusCode: 0);
}

http.Response response = await client.post(
uri,
body: authToken,
headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'text/plain',
},
);

if (response.statusCode != 200) {
logger().d(
'refreshCredential Error: code: ${response.statusCode} msg: ${response.body}');
_stacktraceManager.addError(
'refreshCredential Error: $url response with\ncode: ${response.statusCode}\nmsg: ${response.body}');
throw NetworkException(
errorMessage: response.body, statusCode: response.statusCode);
} else {
FetchClaimResponseDTO fetchResponse =
FetchClaimResponseDTO.fromJson(json.decode(response.body));
try {
final response = await dio.post(
url,
data: authToken,
options: Options(
headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'text/plain',
},
receiveTimeout: const Duration(seconds: 30),
),
);

if (fetchResponse.type == FetchClaimResponseType.issuance) {
return ClaimDTO(
id: fetchResponse.credential.id,
issuer: fetchResponse.from,
did: profileDid,
type: fetchResponse.credential.credentialSubject.type,
expiration: fetchResponse.credential.expirationDate,
info: fetchResponse.credential,
credentialRawValue: response.body,
);
} else {
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: UnsupportedFetchClaimTypeException");
if (response.statusCode != 200) {
logger().d(
'refreshCredential Error: code: ${response.statusCode} msg: ${response.data}');
_stacktraceManager.addError(
"[RemoteIden3commDataSource] fetchClaim: UnsupportedFetchClaimTypeException");
throw UnsupportedFetchClaimTypeException(
type: fetchResponse.type.name,
errorMessage:
'Unsupported fetch claim type: ${fetchResponse.type.name}\nShould be ${FetchClaimResponseType.issuance.name}',
);
}
}
}

Future<ClaimDTO> fetchClaim({
required String authToken,
required String url,
required String did,
}) {
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: did:$did\nurl: $url\nauthToken: $authToken");
logger().i(
"[RemoteIden3commDataSource] fetchClaim: did:$did\nurl: $url\nauthToken: $authToken");
return Future.value(Uri.parse(url))
.then((uri) => client.post(
uri,
body: authToken,
headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'text/plain',
},
))
.then((response) {
logger()
.d("fetchClaim: code: ${response.statusCode} msg: ${response.body}");
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: ${response.statusCode} ${response.body}");
if (response.statusCode == 200) {
Map<String, dynamic> jsonResponse = json.decode(response.body);
final fetchResponse = FetchClaimResponseDTO.fromJson(jsonResponse);
'refreshCredential Error: $url response with\ncode: ${response.statusCode}\nmsg: ${response.data}');
throw NetworkException(
errorMessage: response.data, statusCode: response.statusCode ?? 0);
} else {
FetchClaimResponseDTO fetchResponse =
FetchClaimResponseDTO.fromJson(response.data);

if (fetchResponse.type == FetchClaimResponseType.issuance) {
logger().i(
"[RemoteIden3commDataSource] fetchClaim: ${fetchResponse.credential.toJson()}");
final claimDTO = ClaimDTO(
return ClaimDTO(
id: fetchResponse.credential.id,
issuer: fetchResponse.from,
did: did,
did: profileDid,
type: fetchResponse.credential.credentialSubject.type,
expiration: fetchResponse.credential.expirationDate,
info: fetchResponse.credential,
credentialRawValue: response.body,
credentialRawValue: json.encode(response.data),
);
logger().i(
"[RemoteIden3commDataSource] fetchClaim: ${claimDTO.info.toJson()}");
return claimDTO;
} else {
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: UnsupportedFetchClaimTypeException");
Expand All @@ -195,17 +141,113 @@ class RemoteIden3commDataSource {
'Unsupported fetch claim type: ${fetchResponse.type.name}\nShould be ${FetchClaimResponseType.issuance.name}',
);
}
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionTimeout ||
e.type == DioExceptionType.receiveTimeout) {
_stacktraceManager.addError(
'refreshCredential error: $url response with\ncode: ${e.response?.statusCode}\nmsg: ${e.response?.data}');
throw NetworkException(
errorMessage: "Connection timeout while refreshing credential.",
statusCode: e.response?.statusCode ?? 0,
);
} else {
_stacktraceManager.addError(
'refreshCredential error: $url response with\ncode: ${e.response?.statusCode}\nmsg: ${e.response?.data}');
rethrow;
}
} catch (e) {
logger().e('refreshCredential error: $e');
rethrow;
}
}

Future<ClaimDTO> fetchClaim({
required String authToken,
required String url,
required String did,
}) {
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: did:$did\nurl: $url\nauthToken: $authToken");
logger().i(
"[RemoteIden3commDataSource] fetchClaim: did:$did\nurl: $url\nauthToken: $authToken");

try {
return Future.value(Uri.parse(url))
.then((uri) => dio.post(
url,
data: authToken,
options: Options(
headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'text/plain',
},
receiveTimeout: const Duration(seconds: 30),
),
))
.then((response) {
logger().d(
'fetchClaim Error: code: ${response.statusCode} msg: ${response.body}');
"fetchClaim: code: ${response.statusCode} msg: ${response.data}");
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: ${response.statusCode} ${response.data}");
if (response.statusCode == 200) {
final fetchResponse = FetchClaimResponseDTO.fromJson(response.data);

if (fetchResponse.type == FetchClaimResponseType.issuance) {
logger().i(
"[RemoteIden3commDataSource] fetchClaim: ${fetchResponse.credential.toJson()}");
final claimDTO = ClaimDTO(
id: fetchResponse.credential.id,
issuer: fetchResponse.from,
did: did,
type: fetchResponse.credential.credentialSubject.type,
expiration: fetchResponse.credential.expirationDate,
info: fetchResponse.credential,
credentialRawValue: jsonEncode(response.data),
);
logger().i(
"[RemoteIden3commDataSource] fetchClaim: ${claimDTO.info.toJson()}");
return claimDTO;
} else {
_stacktraceManager.addTrace(
"[RemoteIden3commDataSource] fetchClaim: UnsupportedFetchClaimTypeException");
_stacktraceManager.addError(
"[RemoteIden3commDataSource] fetchClaim: UnsupportedFetchClaimTypeException");
throw UnsupportedFetchClaimTypeException(
type: fetchResponse.type.name,
errorMessage:
'Unsupported fetch claim type: ${fetchResponse.type.name}\nShould be ${FetchClaimResponseType.issuance.name}',
);
}
} else {
logger().d(
'fetchClaim Error: code: ${response.statusCode} msg: ${response.data}');
_stacktraceManager.addError(
'fetchClaim Error: $url response with\ncode: ${response.statusCode}\nmsg: ${response.data}');
throw NetworkException(
errorMessage: response.data,
statusCode: response.statusCode ?? 0,
);
}
});
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionTimeout ||
e.type == DioExceptionType.receiveTimeout) {
_stacktraceManager.addError(
'fetchClaim Error: $url response with\ncode: ${response.statusCode}\nmsg: ${response.body}');
'fetchClaim error: $url response with\ncode: ${e.response?.statusCode}\nmsg: ${e.response?.data}');
throw NetworkException(
errorMessage: response.body,
statusCode: response.statusCode,
errorMessage: "Connection timeout while fetching claim.",
statusCode: e.response?.statusCode ?? 0,
);
} else {
_stacktraceManager.addError(
'fetchClaim error: $url response with\ncode: ${e.response?.statusCode}\nmsg: ${e.response?.data}');
rethrow;
}
});
} catch (e) {
logger().e('fetchClaim error: $e');
rethrow;
}
}

Future<Map<String, dynamic>> fetchSchema({required String url}) async {
Expand Down
11 changes: 5 additions & 6 deletions lib/sdk/di/injector.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading