From 3afd15a09e8c2aa54cfd07df9e89181818f53013 Mon Sep 17 00:00:00 2001 From: Anton Biriukov Date: Fri, 1 Sep 2023 09:14:57 -0400 Subject: [PATCH] feat(app): added issuance preview screen for demo app web (#585) Signed-off-by: Anton Biriukov --- demo/app/lib/wallet_sdk/wallet_sdk_js.dart | 60 ++++++++++++++++++- demo/app/lib/wallet_sdk/wallet_sdk_model.dart | 10 ++-- demo/app/web/package-lock.json | 14 ++--- demo/app/web/package.json | 2 +- demo/app/web/script.js | 11 ++++ 5 files changed, 83 insertions(+), 14 deletions(-) diff --git a/demo/app/lib/wallet_sdk/wallet_sdk_js.dart b/demo/app/lib/wallet_sdk/wallet_sdk_js.dart index 5bf86c19..ae1b9c04 100644 --- a/demo/app/lib/wallet_sdk/wallet_sdk_js.dart +++ b/demo/app/lib/wallet_sdk/wallet_sdk_js.dart @@ -100,6 +100,29 @@ extension JSSubmissionRequirementExt on JSSubmissionRequirement { external List nested; } +@JS() +@staticInterop +class JSSupportedCredentials {} + +extension JSSupportedCredentialsExt on JSSupportedCredentials { + + external String get format; + + external List get types; + + external List get display; +} + +@JS() +@staticInterop +class JSIssuerMetadata {} + +extension JSIssuerMetadataExt on JSIssuerMetadata { + external String get credentialIssuer; + external List get supportedCredentials; + external List get localizedIssuerDisplays; +} + @JS() external dynamic jsInitSDK(String didResolverURI); @@ -142,6 +165,9 @@ external dynamic jsVerifyCredentialsStatus(String credential); @JS() external dynamic jsWellKnownDidConfig(String issuerID); +@JS() +external dynamic jsGetIssuerMetadata(); + class WalletSDK extends WalletPlatform { @visibleForTesting final methodChannel = const MethodChannel('WalletSDKPlugin'); @@ -295,7 +321,39 @@ class WalletSDK extends WalletPlatform { } Future> getIssuerMetaData() async { - return throw Exception('Method not implemented'); + final JSIssuerMetadata data = await promiseToFuture(jsGetIssuerMetadata()); + + final List issuerMetadata = [IssuerMetaData( + credentialIssuer: data.credentialIssuer, + supportedCredentials: data.supportedCredentials + .map((e) => e as JSSupportedCredentials) + .map((supportedCredential) => SupportedCredentials( + format: supportedCredential.format, + types: supportedCredential.types.map((e) => e as String).toList(), + display: supportedCredential.display + .map((supportedCredentialDisplayData) => SupportedCredentialDisplayData( + name: supportedCredentialDisplayData.name, + locale: supportedCredentialDisplayData.locale, + logo: (supportedCredentialDisplayData.logo != null) ? supportedCredentialDisplayData.logo.url : '', + textColor: supportedCredentialDisplayData.text_color, + backgroundColor: supportedCredentialDisplayData.background_color + ) + ).toList(), + )).toList(), + localizedIssuerDisplays: data.localizedIssuerDisplays + .map((localizedIssuerDisplay) => IssuerDisplayData( + name: localizedIssuerDisplay.name, + locale: localizedIssuerDisplay.locale, + url: (localizedIssuerDisplay.url != null) ? localizedIssuerDisplay.url : '', + logo: (localizedIssuerDisplay.logo != null) ? localizedIssuerDisplay.logo.url : '', + textColor: localizedIssuerDisplay.text_color, + backgroundColor: localizedIssuerDisplay.background_color + )).toList(), + )]; + + debugPrint("Issuer Metadata: $issuerMetadata"); + + return issuerMetadata; } Future getVerifierDisplayData() async { diff --git a/demo/app/lib/wallet_sdk/wallet_sdk_model.dart b/demo/app/lib/wallet_sdk/wallet_sdk_model.dart index fa6526e9..79c4711c 100644 --- a/demo/app/lib/wallet_sdk/wallet_sdk_model.dart +++ b/demo/app/lib/wallet_sdk/wallet_sdk_model.dart @@ -238,16 +238,16 @@ class IssuerDisplayData { final String locale; final String url; String? logo; - final String backgroundColor; - final String textColor; + String? backgroundColor; + String? textColor; IssuerDisplayData({ required this.name, required this.locale, required this.url, - required this.logo, - required this.textColor, - required this.backgroundColor, + this.logo, + this.textColor, + this.backgroundColor, }); @override diff --git a/demo/app/web/package-lock.json b/demo/app/web/package-lock.json index 50ce1c2e..52202cba 100644 --- a/demo/app/web/package-lock.json +++ b/demo/app/web/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "@trustbloc-cicd/wallet-sdk-js": "1.2.2-snapshot-6b51a9f" + "@trustbloc-cicd/wallet-sdk-js": "1.2.3-snapshot-e878d55" } }, "../../../cmd/wallet-sdk-js": { @@ -30,9 +30,9 @@ "extraneous": true }, "node_modules/@trustbloc-cicd/wallet-sdk-js": { - "version": "1.2.2-snapshot-6b51a9f", - "resolved": "https://npm.pkg.github.com/download/@trustbloc-cicd/wallet-sdk-js/1.2.2-snapshot-6b51a9f/1fcd90e9cd6e36cf79f635e23c9a2a67ffec2b05", - "integrity": "sha512-LkzouaqSVDXjkxpWxNEWXRfZxEE70wjvXeyRDaxIzQT9Bi+iDzNzkFjwszQAIqZtZCCTbhz5C6Dn153Zl5xHxw==", + "version": "1.2.3-snapshot-e878d55", + "resolved": "https://npm.pkg.github.com/download/@trustbloc-cicd/wallet-sdk-js/1.2.3-snapshot-e878d55/047b1f53975150ece5cb9c9ec94229e6ab6abe7b", + "integrity": "sha512-ZDLDoORoFBBJMN6YdiALMJzRk4ySQk6rsyvjsK/gvDl7U/5jA6/m/hfZTwKgoQwEHa5Cd6kikrZqYLmwRbLypQ==", "license": "Apache-2.0", "engines": { "node": ">=12.13", @@ -42,9 +42,9 @@ }, "dependencies": { "@trustbloc-cicd/wallet-sdk-js": { - "version": "1.2.2-snapshot-6b51a9f", - "resolved": "https://npm.pkg.github.com/download/@trustbloc-cicd/wallet-sdk-js/1.2.2-snapshot-6b51a9f/1fcd90e9cd6e36cf79f635e23c9a2a67ffec2b05", - "integrity": "sha512-LkzouaqSVDXjkxpWxNEWXRfZxEE70wjvXeyRDaxIzQT9Bi+iDzNzkFjwszQAIqZtZCCTbhz5C6Dn153Zl5xHxw==" + "version": "1.2.3-snapshot-e878d55", + "resolved": "https://npm.pkg.github.com/download/@trustbloc-cicd/wallet-sdk-js/1.2.3-snapshot-e878d55/047b1f53975150ece5cb9c9ec94229e6ab6abe7b", + "integrity": "sha512-ZDLDoORoFBBJMN6YdiALMJzRk4ySQk6rsyvjsK/gvDl7U/5jA6/m/hfZTwKgoQwEHa5Cd6kikrZqYLmwRbLypQ==" } } } diff --git a/demo/app/web/package.json b/demo/app/web/package.json index 03053d26..fd16e73d 100644 --- a/demo/app/web/package.json +++ b/demo/app/web/package.json @@ -29,6 +29,6 @@ }, "homepage": "https://github.com/trustbloc/wallet-sdk/demo/app/#readme", "dependencies": { - "@trustbloc-cicd/wallet-sdk-js": "1.2.2-snapshot-6b51a9f" + "@trustbloc-cicd/wallet-sdk-js": "1.2.3-snapshot-e878d55" } } diff --git a/demo/app/web/script.js b/demo/app/web/script.js index 2c257181..a137004a 100644 --- a/demo/app/web/script.js +++ b/demo/app/web/script.js @@ -115,6 +115,17 @@ async function jsWellKnownDidConfig(issuerID) { }) } +async function jsGetIssuerMetadata() { + const issuerMetadata = await openID4CIInteraction.issuerMetadata() + const result = { + ...issuerMetadata, + supportedCredentials: JSON.parse(issuerMetadata.supportedCredentials), + localizedIssuerDisplays: JSON.parse(issuerMetadata.localizedIssuerDisplays) + }; + console.log("JS Issuer Metadata:", result); + return result; +} + // KMS database implementation function CreateDB(dbName) { const keystoreTable = "keyStore";