Skip to content

Commit

Permalink
feat(app): added issuance preview screen for demo app web (#585)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Biriukov <[email protected]>
  • Loading branch information
birtony authored Sep 1, 2023
1 parent e878d55 commit 3afd15a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
60 changes: 59 additions & 1 deletion demo/app/lib/wallet_sdk/wallet_sdk_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ extension JSSubmissionRequirementExt on JSSubmissionRequirement {
external List<dynamic> nested;
}

@JS()
@staticInterop
class JSSupportedCredentials {}

extension JSSupportedCredentialsExt on JSSupportedCredentials {

external String get format;

external List<dynamic> get types;

external List<dynamic> get display;
}

@JS()
@staticInterop
class JSIssuerMetadata {}

extension JSIssuerMetadataExt on JSIssuerMetadata {
external String get credentialIssuer;
external List<dynamic> get supportedCredentials;
external List<dynamic> get localizedIssuerDisplays;
}

@JS()
external dynamic jsInitSDK(String didResolverURI);

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -295,7 +321,39 @@ class WalletSDK extends WalletPlatform {
}

Future<List<IssuerMetaData>> getIssuerMetaData() async {
return throw Exception('Method not implemented');
final JSIssuerMetadata data = await promiseToFuture(jsGetIssuerMetadata());

final List<IssuerMetaData> 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<VerifierDisplayData> getVerifierDisplayData() async {
Expand Down
10 changes: 5 additions & 5 deletions demo/app/lib/wallet_sdk/wallet_sdk_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions demo/app/web/package-lock.json

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

2 changes: 1 addition & 1 deletion demo/app/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 11 additions & 0 deletions demo/app/web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 3afd15a

Please sign in to comment.