From 135d0249f772effed97422ff5c3c50d31e9eacd6 Mon Sep 17 00:00:00 2001 From: talwinder kaur Date: Thu, 4 Jul 2024 07:34:52 -0400 Subject: [PATCH] feat(app): Add support of attachment object in the claims (#794) Signed-off-by: Talwinder Kaur --- .../walletsdk/flutter/app/MainActivity.kt | 10 ++++++++++ demo/app/ios/Runner/flutterPlugin.swift | 10 ++++++++++ demo/app/lib/wallet_sdk/wallet_sdk_model.dart | 11 +++++++++-- .../credential_verified_information_view.dart | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/demo/app/android/app/src/main/kotlin/walletsdk/flutter/app/MainActivity.kt b/demo/app/android/app/src/main/kotlin/walletsdk/flutter/app/MainActivity.kt index 1377d3da..1343d9b6 100644 --- a/demo/app/android/app/src/main/kotlin/walletsdk/flutter/app/MainActivity.kt +++ b/demo/app/android/app/src/main/kotlin/walletsdk/flutter/app/MainActivity.kt @@ -826,6 +826,16 @@ class MainActivity : FlutterActivity() { claims["rawValue"] = claim.rawValue() claims["valueType"] = claim.valueType() claims["label"] = claim.label() + + if (claim.valueType() == "attachment") { + // For type=attachment, ignore the RawValue() and Value(), instead use Attachment() method. + claims["rawValue"] = "" + claims["value"] = "" + val attachmentResp = claim.attachment() + claims["uri"] = attachmentResp.uri() + } + + claimList.addAll(listOf(claims)) } var overview = credentialDisplay.overview() diff --git a/demo/app/ios/Runner/flutterPlugin.swift b/demo/app/ios/Runner/flutterPlugin.swift index 4e6fe9d1..98cc8b88 100644 --- a/demo/app/ios/Runner/flutterPlugin.swift +++ b/demo/app/ios/Runner/flutterPlugin.swift @@ -1099,6 +1099,15 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin { claims["rawValue"] = claim.rawValue() claims["valueType"] = claim.valueType() claims["label"] = claim.label() + + + if claim.valueType() == "attachment" { + // For type=attachment, ignore the RawValue() and Value(), instead use Attachment() method. + claims["rawValue"] = "" + claims["value"] = "" + let attachmentResp = claim.attachment() + claims["uri"] = attachmentResp!.uri() + } claimList.append(claims) } } @@ -1116,6 +1125,7 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin { result(resolveDisplayResp) } + public func parseIssuerDisplay(arguments: Dictionary, result: @escaping FlutterResult) { guard let issuerDisplayData = arguments["issuerDisplayData"] as? String else{ return result(FlutterError.init(code: "NATIVE_ERR", diff --git a/demo/app/lib/wallet_sdk/wallet_sdk_model.dart b/demo/app/lib/wallet_sdk/wallet_sdk_model.dart index e52b629d..579b1b1a 100644 --- a/demo/app/lib/wallet_sdk/wallet_sdk_model.dart +++ b/demo/app/lib/wallet_sdk/wallet_sdk_model.dart @@ -387,6 +387,7 @@ class CredentialDisplayData { class CredentialDisplayClaim { final String rawValue; final String valueType; + final String? uri; final String label; final String? value; final int? order; @@ -395,6 +396,7 @@ class CredentialDisplayClaim { const CredentialDisplayClaim({ required this.rawValue, required this.valueType, + required this.uri, required this.label, this.value, this.order, @@ -407,22 +409,24 @@ class CredentialDisplayClaim { runtimeType == other.runtimeType && rawValue == other.rawValue && valueType == other.valueType && + uri == other.uri && label == other.label && value == other.value && order == other.order); @override - int get hashCode => rawValue.hashCode ^ valueType.hashCode ^ label.hashCode ^ value.hashCode ^ order.hashCode; + int get hashCode => rawValue.hashCode ^ valueType.hashCode ^ label.hashCode ^ value.hashCode ^ order.hashCode ^ uri.hashCode; @override String toString() { - return 'CredentialDisplayClaim{ rawValue: $rawValue, valueType: $valueType, label: $label, value: $value, order: $order,}'; + return 'CredentialDisplayClaim{ rawValue: $rawValue, valueType: $valueType, label: $label, value: $value, order: $order, uri: $uri}'; } CredentialDisplayClaim copyWith({ String? rawValue, String? valueType, String? label, + String? uri, String? value, int? order, }) { @@ -430,6 +434,7 @@ class CredentialDisplayClaim { rawValue: rawValue ?? this.rawValue, valueType: valueType ?? this.valueType, label: label ?? this.label, + uri: uri ?? this.uri, value: value ?? this.value, order: order ?? this.order, ); @@ -441,6 +446,7 @@ class CredentialDisplayClaim { 'valueType': valueType, 'label': label, 'value': value, + 'uri': uri, 'order': order, }; } @@ -450,6 +456,7 @@ class CredentialDisplayClaim { rawValue: map['rawValue'] as String, valueType: map['valueType'] as String, label: map['label'] as String, + uri: map['uri'] as String?, value: map['value'] as String?, order: map['order'] as int?, ); diff --git a/demo/app/lib/widgets/credential_verified_information_view.dart b/demo/app/lib/widgets/credential_verified_information_view.dart index 337caf46..bab5b6a1 100644 --- a/demo/app/lib/widgets/credential_verified_information_view.dart +++ b/demo/app/lib/widgets/credential_verified_information_view.dart @@ -51,7 +51,7 @@ class CredentialVerifiedState extends State { controller: credDataController, shrinkWrap: true, itemBuilder: (context, position) { - if (credPrev[position].valueType != 'image') { + if (credPrev[position].valueType == 'string') { return Row( children: [ const Divider( @@ -138,11 +138,17 @@ class CredentialVerifiedState extends State { crossAxisAlignment: CrossAxisAlignment.end, mainAxisSize: MainAxisSize.min, children: [ - Image.memory( - const Base64Decoder().convert(credPrev[position].rawValue.split(',').last), - width: 80, - height: 80, - ), + credPrev[position].uri == null ? + Image.memory( + const Base64Decoder().convert(credPrev[position].rawValue.split(',').last), + width: 80, + height: 80, + ): + Image.memory( + const Base64Decoder().convert(credPrev[position].uri!.split(',').last), + width: 80, + height: 80, + ) ], ), ),