Skip to content

Commit

Permalink
chore(app): linted dart code (#605)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Biriukov <[email protected]>
  • Loading branch information
birtony authored Sep 13, 2023
1 parent 2ffa912 commit 7957a23
Show file tree
Hide file tree
Showing 30 changed files with 224 additions and 249 deletions.
2 changes: 1 addition & 1 deletion demo/app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ linter:
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
104 changes: 52 additions & 52 deletions demo/app/integration_test/openid4ci_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void main() async {
print("Init Wallet SDK Plugin");
print('Init Wallet SDK Plugin');
final walletSDKPlugin = WalletSDK();
print("Init SDK");
const didResolverURI = String.fromEnvironment("DID_RESOLVER_URI");
print('Init SDK');
const didResolverURI = String.fromEnvironment('DID_RESOLVER_URI');
await walletSDKPlugin.initSDK(didResolverURI);
var didKeyType = "";
var didKeyType = '';
testWidgets('Testing openid4vc with a single credential', (tester) async {
const didMethodTypes = String.fromEnvironment("WALLET_DID_METHODS");
const didMethodTypes = String.fromEnvironment('WALLET_DID_METHODS');
var didMethodTypesList = didMethodTypes.split(' ');

const issuanceURLs = String.fromEnvironment("INITIATE_ISSUANCE_URLS");
const issuanceURLs = String.fromEnvironment('INITIATE_ISSUANCE_URLS');
var issuanceURLsList = issuanceURLs.split(' ');

const verificationURLs = String.fromEnvironment("INITIATE_VERIFICATION_URLS");
const verificationURLs = String.fromEnvironment('INITIATE_VERIFICATION_URLS');
var verificationURLsList = verificationURLs.split(' ');

for (int i = 0; i < issuanceURLsList.length; i++) {
String didMethodType = didMethodTypesList[i];
print("wallet DID Type : $didMethodType");
print("wallet DID Key Type : $didKeyType");
print('wallet DID Type : $didMethodType');
print('wallet DID Key Type : $didKeyType');
var didDocData = await walletSDKPlugin.createDID(didMethodTypesList[i], didKeyType);
final didContent= didDocData.did;
print("wallet DID : $didContent");
print('wallet DID : $didContent');

String issuanceURL = issuanceURLsList[i];
print("issuanceURL : $issuanceURL");
print('issuanceURL : $issuanceURL');

var initializeResp = await walletSDKPlugin.initialize(issuanceURL, null);
var initializeRespEncoded = json.encode(initializeResp!);
Map<String, dynamic> initializeRespJson = json.decode(initializeRespEncoded);
var requirePIN = initializeRespJson["pinRequired"];
print("requirePIN: $requirePIN");
var requirePIN = initializeRespJson['pinRequired'];
print('requirePIN: $requirePIN');

final credential = await walletSDKPlugin.requestCredential("");
debugPrint("content: $credential");
final credential = await walletSDKPlugin.requestCredential('');
debugPrint('content: $credential');
for (final p in credential.split('.')) {
print("----");
print('----');
print(p);
}

expect(credential, hasLength(greaterThan(0)));

String verificationURL = verificationURLsList[i];
print("verificationURL : $verificationURL");
print('verificationURL : $verificationURL');

await walletSDKPlugin
.processAuthorizationRequest(authorizationRequest: verificationURL);

print("getSubmissionRequirements");
print('getSubmissionRequirements');

final requirements = await walletSDKPlugin.getSubmissionRequirements( storedCredentials: [credential]);

print("getSubmissionRequirements finished");
print('getSubmissionRequirements finished');

expect(requirements, hasLength(equals(1)));
expect(requirements[0].inputDescriptors, hasLength(equals(1)));
Expand All @@ -75,48 +75,48 @@ void main() async {
});

testWidgets('Testing openid4vc with multiple credentials', (tester) async {
const didMethodTypes = String.fromEnvironment("WALLET_DID_METHODS");
const didMethodTypes = String.fromEnvironment('WALLET_DID_METHODS');
var didMethodTypesList = didMethodTypes.split(' ');
String didMethodType = didMethodTypesList[0];
print("wallet DID type : $didMethodType");
print("wallet DID Key type : $didKeyType");
print('wallet DID type : $didMethodType');
print('wallet DID Key type : $didKeyType');
var didDocData = await walletSDKPlugin.createDID(didMethodTypesList[0], didKeyType);
var didContent= didDocData.did;
print("wallet DID : $didContent");
print('wallet DID : $didContent');

const issuanceURLs = String.fromEnvironment("INITIATE_ISSUANCE_URLS_MULTIPLE_CREDS");
const issuanceURLs = String.fromEnvironment('INITIATE_ISSUANCE_URLS_MULTIPLE_CREDS');
var issuanceURLsList = issuanceURLs.split(' ');

List<String> credentials = [];

// Issue multiple credentials
for (int i = 0; i < issuanceURLsList.length; i++) {
String issuanceURL = issuanceURLsList[i];
print("issuanceURL : $issuanceURL");
print('issuanceURL : $issuanceURL');

var initializeResp = await walletSDKPlugin.initialize(issuanceURL, null);
var initializeRespEncoded = json.encode(initializeResp!);
Map<String, dynamic> initializeRespJson = json.decode(initializeRespEncoded);
var requirePIN = initializeRespJson["pinRequired"];
print("requirePIN: $requirePIN");
var requirePIN = initializeRespJson['pinRequired'];
print('requirePIN: $requirePIN');

final credential = await walletSDKPlugin.requestCredential("");
final credential = await walletSDKPlugin.requestCredential('');

expect(credential, hasLength(greaterThan(0)));

credentials.add(credential);
}
print("issued credentials: $credentials");
print('issued credentials: $credentials');

const verificationURLs = String.fromEnvironment("INITIATE_VERIFICATION_URLS_MULTIPLE_CREDS");
const verificationURLs = String.fromEnvironment('INITIATE_VERIFICATION_URLS_MULTIPLE_CREDS');
var verificationURLsList = verificationURLs.split(' ');
String verificationURL = verificationURLsList[0];
print("verificationURL : $verificationURL");
print('verificationURL : $verificationURL');

final matchedCreds = await walletSDKPlugin
.processAuthorizationRequest(authorizationRequest: verificationURL, storedCredentials: credentials);

print("matchedCreds : $matchedCreds");
print('matchedCreds : $matchedCreds');

expect(matchedCreds, hasLength(equals(3)));

Expand All @@ -128,32 +128,32 @@ void main() async {
});

testWidgets('Testing openid4vc with the auth code flow', (tester) async {
const didMethodTypes = String.fromEnvironment("WALLET_DID_METHODS");
const didMethodTypes = String.fromEnvironment('WALLET_DID_METHODS');
var didMethodTypesList = didMethodTypes.split(' ');
String didMethodType = didMethodTypesList[0];
print("wallet DID type : $didMethodType");
print("wallet DID Key type : $didKeyType");
print('wallet DID type : $didMethodType');
print('wallet DID Key type : $didKeyType');
var didDocData = await walletSDKPlugin.createDID(didMethodTypesList[0], didKeyType);
print("wallet didDocData : $didDocData");
print('wallet didDocData : $didDocData');
var didContent= didDocData.did;
print("wallet DID : $didContent");
print('wallet DID : $didContent');

const issuanceURL = String.fromEnvironment("INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW");
debugPrint("issuanceURLs: $issuanceURL");
const issuanceURL = String.fromEnvironment('INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW');
debugPrint('issuanceURLs: $issuanceURL');

var authCodeArgs = {
"scopes": ["openid","profile"],
"clientID": "oidc4vc_client",
"redirectURI": "http://127.0.0.1/callback"
'scopes': ['openid','profile'],
'clientID': 'oidc4vc_client',
'redirectURI': 'http://127.0.0.1/callback'
};

var initializeResp = await walletSDKPlugin.initialize(issuanceURL, authCodeArgs);
var initializeRespEncoded = json.encode(initializeResp!);
Map<String, dynamic> initializeRespJson = json.decode(initializeRespEncoded);
var authorizationURLLink= initializeRespJson["authorizationURLLink"];
debugPrint("authorizationURLLink: $authorizationURLLink");
var authorizationURLLink= initializeRespJson['authorizationURLLink'];
debugPrint('authorizationURLLink: $authorizationURLLink');
// fetching redirect uri
var redirectURI;
String redirectURI = '';
final client = HttpClient();
var redirectUrl = Uri.parse(authorizationURLLink);
var request = await client.getUrl(redirectUrl);
Expand All @@ -164,27 +164,27 @@ void main() async {
final location = response.headers.value(HttpHeaders.locationHeader);
if (location != null) {
redirectUrl = redirectUrl.resolve(location);
if (location.contains("http://127.0.0.1/callback"))
if (location.contains('http://127.0.0.1/callback'))
{
redirectURI = location;
break;
}
if (redirectUrl.host.contains("cognito-mock.trustbloc.local")){
redirectUrl = Uri.parse(redirectUrl.toString().replaceAll("cognito-mock.trustbloc.local", "localhost"));
print("uri updated $redirectUrl");
if (redirectUrl.host.contains('cognito-mock.trustbloc.local')){
redirectUrl = Uri.parse(redirectUrl.toString().replaceAll('cognito-mock.trustbloc.local', 'localhost'));
print('uri updated $redirectUrl');
}
request = await client.getUrl(redirectUrl);
request.followRedirects = false;
response = await request.close();
}
}

debugPrint("redirectURI $redirectURI");
debugPrint('redirectURI $redirectURI');

final credential = await walletSDKPlugin.requestCredentialWithAuth(redirectURI);
debugPrint("content: $credential");
debugPrint('content: $credential');
for (final p in credential.split('.')) {
print("----");
print('----');
print(p);
}

Expand Down
3 changes: 1 addition & 2 deletions demo/app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Copyright Gen Digital Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

import 'dart:io';

import 'package:app/scenarios/handle_openid_url.dart';
import 'package:app/widgets/common_logo_appbar.dart';
Expand All @@ -22,7 +21,7 @@ final WalletSDKPlugin = WalletSDK();

void main() async {
WidgetsFlutterBinding.ensureInitialized();
const didResolverURI = String.fromEnvironment("didResolverURI");
const didResolverURI = String.fromEnvironment('didResolverURI');
await WalletSDKPlugin.initSDK(didResolverURI);

runApp(const MyApp());
Expand Down
4 changes: 2 additions & 2 deletions 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");
print("userLoginDetails -> $userLoggedIn");
String? userLoggedIn = p.getString('userLoggedIn');
print('userLoginDetails -> $userLoggedIn');
return UserLoginDetails(userLoggedIn);
}
34 changes: 17 additions & 17 deletions demo/app/lib/scenarios/handle_openid_issuance_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ import '../views/custom_error.dart';
void handleOpenIDIssuanceFlow(BuildContext context, String qrCodeURL) async {
var WalletSDKPlugin = WalletSDK();
var authCodeArgs;
if (qrCodeURL.contains("credential_offer_uri")) {
if (qrCodeURL.contains('credential_offer_uri')) {
authCodeArgs = await parseCredentialOfferUri(qrCodeURL);
log("credential offer uri auth code ${authCodeArgs}");
log('credential offer uri auth code $authCodeArgs');
} else {
if (qrCodeURL.contains("authorization_code")) {
if (qrCodeURL.contains('authorization_code')) {
authCodeArgs = await readIssuerAuthFlowConfig(qrCodeURL);
log("auth code arguments fetched from config file $authCodeArgs");
log('auth code arguments fetched from config file $authCodeArgs');
// While fetching auth code args based on issuer key from file, if no key-value pair is found then set the
// arguments to default scope and redirect url.
authCodeArgs ??= {
"scopes": ["openid", "profile"],
"redirectURI": "trustbloc-wallet://openid4vci/authcodeflow/callback"
'scopes': ['openid', 'profile'],
'redirectURI': 'trustbloc-wallet://openid4vci/authcodeflow/callback'
};
}
}
log("qr code url - $qrCodeURL");
var flowTypeData;
log('qr code url - $qrCodeURL');
Map<Object?, Object?>? flowTypeData;
try {
flowTypeData = await WalletSDKPlugin.initialize(qrCodeURL, authCodeArgs);
} catch (error) {
Expand All @@ -43,22 +43,22 @@ void handleOpenIDIssuanceFlow(BuildContext context, String qrCodeURL) async {
context,
MaterialPageRoute(
builder: (context) => CustomError(
titleBar: "QR Code Scanned",
requestErrorTitleMsg: "error while intializing the interaction",
requestErrorSubTitleMsg: "${errString}")));
titleBar: 'QR Code Scanned',
requestErrorTitleMsg: 'error while intializing the interaction',
requestErrorSubTitleMsg: errString)));
return;
}
var flowTypeDataEncoded = json.encode(flowTypeData);
Map<String, dynamic> responseJson = json.decode(flowTypeDataEncoded);
var authorizeResultPinRequired = responseJson["pinRequired"];
log("pin required flow - $authorizeResultPinRequired");
var authorizeResultPinRequired = responseJson['pinRequired'];
log('pin required flow - $authorizeResultPinRequired');
if (authorizeResultPinRequired == true) {
navigateToIssuancePreviewScreen(context, authorizeResultPinRequired);
return;
} else if (responseJson["authorizationURLLink"] != '') {
} else if (responseJson['authorizationURLLink'] != '') {
// initiate authCode Flow
log("initiating authCode Flow- ${responseJson["authorizationURLLink"]}");
Uri uri = Uri.parse(responseJson["authorizationURLLink"]);
Uri uri = Uri.parse(responseJson['authorizationURLLink']);
navigateToIssuancePreviewScreenAuthFlow(context, uri);
return;
} else {
Expand All @@ -70,10 +70,10 @@ void handleOpenIDIssuanceFlow(BuildContext context, String qrCodeURL) async {
readIssuerAuthFlowConfig(String qrCodeURL) async {
var decodedUri = Uri.decodeComponent(qrCodeURL);
final uri = Uri.parse(decodedUri);
var credentialIssuerKey = json.decode(uri.queryParameters["credential_offer"]!);
var credentialIssuerKey = json.decode(uri.queryParameters['credential_offer']!);
final String response = await rootBundle.loadString('lib/assets/issuerAuthFlowConfig.json');
final configData = await json.decode(response);
return configData[credentialIssuerKey["credential_issuer"]];
return configData[credentialIssuerKey['credential_issuer']];
}

parseCredentialOfferUri(String qrCodeURL) async {
Expand Down
3 changes: 1 addition & 2 deletions demo/app/lib/scenarios/handle_openid_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SPDX-License-Identifier: Apache-2.0
*/

import 'dart:developer';
import 'package:app/wallet_sdk/wallet_sdk.dart';
import 'package:app/scenarios/handle_openid_issuance_flow.dart';
import 'package:app/scenarios/handle_openid_vp_flow.dart';
import 'package:app/wallet_sdk/wallet_sdk_model.dart';
Expand All @@ -14,7 +13,7 @@ import 'package:flutter/material.dart';
void handleOpenIDUrl(BuildContext context, String qrCodeURL) async {
log('received qr code url - $qrCodeURL');
// Check if the flow is for the verifiable presentation or for issuance.
if (!qrCodeURL.contains("openid-vc")) {
if (!qrCodeURL.contains('openid-vc')) {
handleOpenIDIssuanceFlow(context, qrCodeURL);
} else {
handleOpenIDVpFlow(context, qrCodeURL);
Expand Down
Loading

0 comments on commit 7957a23

Please sign in to comment.