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

fix(app): fixed data handling logic in verification flow for web #590

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion demo/app/lib/models/store_credential_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserLoginDetails {
Future<UserLoginDetails> getUser() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final SharedPreferences p = prefs;
String? userLoggedIn = p.getString("userLoggedIn");
String? userLoggedIn = p.getString("userLoggedIn");
print("userLoginDetails -> $userLoggedIn");
return UserLoginDetails(userLoggedIn);
}
11 changes: 5 additions & 6 deletions demo/app/lib/scenarios/handle_openid_vp_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ void handleOpenIDVpFlow(BuildContext context, String qrCodeURL) async {

// Check if the flow is for the verifiable presentation or for issuance.
UserLoginDetails userLoginDetails = await getUser();
var username = userLoginDetails.username!;
var username = userLoginDetails.username;
storedCredentials = await storageService.retrieveCredentials(username!);
log("stored credentials -> $storedCredentials");

credentials = storedCredentials.map((e) => e.value.rawCredential).toList();

credentials = storedCredentials.map((e) => e.value.rawCredential).toList();
try {
await walletSDKPlugin.processAuthorizationRequest(
authorizationRequest: qrCodeURL, storedCredentials: credentials);
await walletSDKPlugin.processAuthorizationRequest(
authorizationRequest: qrCodeURL);
} on PlatformException catch (error) {
if (!context.mounted) return;
Navigator.push(
context,
MaterialPageRoute(
Expand Down
8 changes: 4 additions & 4 deletions demo/app/lib/views/credential_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CredentialPreviewState extends State<CredentialPreview> {
@override
void initState() {
super.initState();
WalletSDKPlugin.parseCredentialDisplayData(widget.credentialData.credentialDisplayData!).then(
WalletSDKPlugin.parseCredentialDisplayData(widget.credentialData.credentialDisplayData).then(
(response) {
setState(() {
issuerDisplayData = response.first.issuerName;
Expand All @@ -54,7 +54,7 @@ class CredentialPreviewState extends State<CredentialPreview> {
}
))
);
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) async {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
UserLoginDetails userLoginDetails = await getUser();
userLoggedIn = userLoginDetails.username!;
});
Expand Down Expand Up @@ -109,7 +109,7 @@ class CredentialPreviewState extends State<CredentialPreview> {
],
),
),
subtitle: Text(serviceURL!, textAlign: TextAlign.center, style: const TextStyle(fontSize: 12,fontWeight: FontWeight.normal)),
subtitle: Text(serviceURL, textAlign: TextAlign.center, style: const TextStyle(fontSize: 12,fontWeight: FontWeight.normal)),

),
const SizedBox(height: 20),
Expand Down Expand Up @@ -142,7 +142,7 @@ class CredentialPreviewState extends State<CredentialPreview> {
),
PrimaryButton(
onPressed: () async {
_storageService.addCredential(CredentialDataObject("$userLoggedIn-${uuid.v1()}", widget.credentialData!));
_storageService.addCredential(CredentialDataObject("$userLoggedIn-${uuid.v1()}", widget.credentialData));
_navigateToCredentialAdded();
},
width: double.infinity,
Expand Down
2 changes: 1 addition & 1 deletion demo/app/lib/views/presentation_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PresentationPreviewState extends State<PresentationPreview> {
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) async {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final verifiedDisplayData = await WalletSDKPlugin.getVerifierDisplayData();
log("verifiedDisplayData ${verifiedDisplayData.logoURI}");
var resp = await WalletSDKPlugin.wellKnownDidConfig(verifiedDisplayData.did);
Expand Down
53 changes: 43 additions & 10 deletions demo/app/lib/wallet_sdk/wallet_sdk_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ extension JSResolvedDisplayDataExt on JSResolvedDisplayData {
external List<dynamic> get credentialDisplays;
}

@JS()
@staticInterop

class JSVerifierDisplayData {}

extension JSVerifierDisplayDataExt on JSVerifierDisplayData {
external String get name;
external String get did;
external String get logoURI;
external String get purpose;
}

@JS()
@staticInterop

class JSWellKnownDIDConfig {}

extension JSWellKnownDIDConfigExt on JSWellKnownDIDConfig {
external bool get isValid;
external String get serviceURL;
}

@JS()
@staticInterop
class JSCredentialDisplayData {}
Expand Down Expand Up @@ -100,6 +122,18 @@ extension JSSubmissionRequirementExt on JSSubmissionRequirement {
external List<dynamic> nested;
}

@JS()
@staticInterop
class JSInputDescriptor {}

extension JSInputDescriptorExt on JSInputDescriptor {
external String get id;
external String get name;
external String get purpose;
external List<String> get matchedVCsID;
external List<dynamic> get matchedVCs;
}

@JS()
@staticInterop
class JSSupportedCredentials {}
Expand Down Expand Up @@ -304,11 +338,9 @@ class WalletSDK extends WalletPlatform {
.toList();
}

Future<List<String>> processAuthorizationRequest(
{required String authorizationRequest, List<String>? storedCredentials}) async {
Future<void> processAuthorizationRequest({required String authorizationRequest}) async {
await promiseToFuture(jsCreateOpenID4VPInteraction(authorizationRequest));

return [];
return;
}

Future<List<SubmissionRequirement>> getSubmissionRequirements({required List<String> storedCredentials}) async {
Expand All @@ -317,18 +349,19 @@ class WalletSDK extends WalletPlatform {
return Future.wait(reqs.map((s) => mapSubmissionRequirement(s)));
}

Future<InputDescriptor> mapInputDescriptor(dynamic d) async {
final List<dynamic> jsMatchedVCs = d.matchedVCs;
Future<InputDescriptor> mapInputDescriptor(JSInputDescriptor d) async {
final List<dynamic> jsMatchedVCs = d.matchedVCs.map((e) => e).toList();

final matchedVCs = jsMatchedVCs.map<String>((vc) => vc).toList();
final matchedVCsIds = await Future.wait<String>(jsMatchedVCs.map((vc) => promiseToFuture(jsGetCredentialID(vc))));

return InputDescriptor(
name: d.name, purpose: d.purpose, id: d.id, matchedVCs: matchedVCs, matchedVCsID: matchedVCsIds);
name: d.name, purpose: d.purpose, id: d.id, matchedVCs: matchedVCs, matchedVCsID: matchedVCsIds
);
}

Future<SubmissionRequirement> mapSubmissionRequirement(JSSubmissionRequirement jsReq) async {
final descriptors = await Future.wait(jsReq.descriptors.map(mapInputDescriptor));
final descriptors = await Future.wait(jsReq.descriptors.map((e) => mapInputDescriptor(e)));
final nested = await Future.wait(jsReq.nested.map((n) => mapSubmissionRequirement(n)));

return SubmissionRequirement(
Expand All @@ -349,7 +382,7 @@ class WalletSDK extends WalletPlatform {
}

Future<WellKnownDidConfig> wellKnownDidConfig(String issuerID) async {
final jsConfig = await promiseToFuture(jsWellKnownDidConfig(issuerID));
final JSWellKnownDIDConfig jsConfig = await promiseToFuture(jsWellKnownDidConfig(issuerID));

return WellKnownDidConfig(isValid: jsConfig.isValid, serviceURL: jsConfig.serviceURL);
}
Expand Down Expand Up @@ -398,7 +431,7 @@ class WalletSDK extends WalletPlatform {
}

Future<VerifierDisplayData> getVerifierDisplayData() async {
final data = await promiseToFuture(jsVerifierDisplayData());
final JSVerifierDisplayData data = await promiseToFuture(jsVerifierDisplayData());
return VerifierDisplayData(name: data.name, did: data.did, logoURI: data.logoURI, purpose: data.purpose);
}

Expand Down
Loading