-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
249 lines (196 loc) · 9.1 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import 'dart:async';
import 'dart:convert';
import 'package:dmrtd/extensions.dart';
import 'package:eosio_port_mobile_app/connection/connectors/connectorChainEOS.dart';
import 'package:eosio_port_mobile_app/screen/nfc/authn/authn.dart';
import 'package:eosio_port_mobile_app/screen/qr/QRscreen.dart';
import 'package:eosio_port_mobile_app/screen/requestType.dart';
import 'package:eosio_port_mobile_app/constants/constants.dart';
import 'package:eosio_port_mobile_app/utils/storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:eosio_port_mobile_app/screen/main/stepper/stepEnterAccount/stepEnterAccount.dart';
import 'package:eosio_port_mobile_app/screen/main/stepper/stepAttestation/stepAttestation.dart';
import 'package:eosio_port_mobile_app/screen/main/stepperIndex.dart';
import 'package:flutter/services.dart';
import 'package:flutter_document_reader_api/document_reader.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:eosio_port_mobile_app/screen/theme.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:logging/logging.dart';
//import 'package:device_preview/device_preview.dart' as DevPreview;
import 'package:eosio_port_mobile_app/utils/logging/loggerHandler.dart' as LH;
import 'package:eosio_port_mobile_app/connection/tools/eosio/eosio.dart';
import 'package:eosio_port_mobile_app/screen/qr/readQR.dart';
import 'package:eosio_port_mobile_app/screen/index/index.dart';
import 'package:package_info_plus/package_info_plus.dart';
//only for test
import 'package:idenfy_sdk_flutter/idenfy_sdk_flutter.dart';
var RUN_IN_DEVICE_PREVIEW_MODE = false;
final _logStorage = Logger('Storage initialization');
final _logMain = Logger('Main');
void getAppMetadata() async{
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
String buildSignature = packageInfo.buildSignature;
_logMain.debug("App name: $appName, "
"package name: $packageName, "
"build number: $buildNumber, "
"version: $version, "
"build signature: $buildSignature");
}
void main() async{
WidgetsFlutterBinding.ensureInitialized();
final rawSrvCrt = await rootBundle.load('assets/certs/port_server.cer');
ServerSecurityContext.init(rawSrvCrt.buffer.asUint8List());
await Firebase.initializeApp();
runApp(Port());
}
Map<NetworkType, Network> fillNetworkTypes(Map<NetworkType, Network> networks){
_logStorage.fine("Fill network type if it's empty.");
if (networks != null && networks.isNotEmpty) {
_logStorage.fine("Main.fillNetworkTypes;Netowrk types is already written in database.");
}
NetworkType.values.forEach((element) {
if (NETWORK_CHAINS[element] != null && NETWORK_CHAINS[element]![NETWORK_CHAIN_NAME] != null
&& NETWORK_CHAINS[element]![NETWORK_CHAIN_ID] != null) {
_logStorage.finer("Network type: $element, "
"name: ${NETWORK_CHAINS[element]![NETWORK_CHAIN_NAME]}"
"chainID: ${NETWORK_CHAINS[element]![NETWORK_CHAIN_ID]}");
if ( NETWORK_CHAINS[element]![NETWORK_CHAIN_DEFAULT] == true)
networks[element] = Network(networkType: element,
name: NETWORK_CHAINS[element]![NETWORK_CHAIN_NAME] as String,
chainID: NETWORK_CHAINS[element]![NETWORK_CHAIN_ID] as String);
else
networks[element] = Network(networkType: element,
name: "Custom",
chainID: "Write you own chainID.");
}
});
return networks;
}
Future<void> fillDatabase() async
{
Storage storage = new Storage();
Map<NetworkType, Network> nets = fillNetworkTypes(storage.nodeSet.networks);
if (nets != null)
storage.nodeSet.networks = nets;
await storage.load(callback: (bool isAlreadyUpdated, bool isValid, {String? exc}) {
if (storage.nodeSet.nodes.isEmpty) {
storage.nodeSet.add(networkType: NetworkType.KYLIN,
isSelected: true,
server: NodeServer(host: Uri.parse("https://kylin.eosnode.io:443")));
storage.nodeSet.add(networkType: NetworkType.EOSIO_TESTNET,
isSelected: false,
server: NodeServer(host: Uri.parse("https://eosio.eosnode.io:443")));
storage.nodeSet.add(networkType: NetworkType.EOSIO_TESTNET,
isSelected: false,
server: NodeServer(host: Uri.parse("https://456786.eosnode.io:443")));
storage.nodeSet.add(networkType: NetworkType.MAINNET,
isSelected: false,
server: NodeServer(host: Uri.parse("https://mainenet.eosnode.io:443")));
storage.nodeSet.add(networkType: NetworkType.CUSTOM,
isSelected: false,
server: NodeServer(host: Uri.parse("https://custom.eosnode.io:443")));
}
if (storage.cloudSet.servers.isEmpty){
storage.cloudSet.add(networkTypeServer: NetworkTypeServer.MAIN_SERVER,
isSelected: true,
server: ServerCloud(name: "ZeroPass server", host: Uri.parse("https://portdevq8mjmnrw-portdev1.functions.fnc.fr-par.scw.cloud")));
storage.cloudSet.servers[NetworkTypeServer.MAIN_SERVER]!.selected.set(server:
ServerCloud(name: "ZeroPass server", host: Uri.parse("https://portdevq8mjmnrw-portdev1.functions.fnc.fr-par.scw.cloud")));
}
ServerCloud? serverCloud = storage.getServerCloudSelected(networkTypeServer: NetworkTypeServer.MAIN_SERVER);
StepDataEnterAccount storageStepEnterAccount = storage.getStorageData(0) as StepDataEnterAccount;
storageStepEnterAccount.isUnlocked = true;
StepDataAttestation stepDataAttestation = storage.getStorageData(2) as StepDataAttestation ;
stepDataAttestation.requestType = RequestType.ATTESTATION_REQUEST;
});
Keys keys= Keys();
keys.add(PrivateKey(TEST_PRIVATE_KEY));
//Eosio eosio=Eosio(storageNode: NodeServer(host: Uri.parse("https://jungle3.greymass.com")), version: EosioVersion.v2, privateKeys: keys);
ConnectorChainEOS connectorChainEOS = ConnectorChainEOS(url: Uri.parse("https://jungle3.greymass.com1"), keys:keys);
connectorChainEOS.getData(dscBinary: "");
storage.save();
storage.load();
}
/*
* To load from disc previously stored values
*/
void loadDatabase({required Future<void> Function(Storage, bool, bool, {String? exc}) callbackStatus})
{
Storage storage = new Storage();
storage.load(callback: (isAlreadyUpdated, isValid, {String? exc}){
callbackStatus.call(storage, isAlreadyUpdated, isValid, exc:exc);
});
}
class Port extends StatelessWidget {
dynamic routes = {
'/index' : (context) => IndexScreen(),
'/home' : (context) => PortStepperScreen(), //looking for dynamic links
'/homeMagnetLink' : (context) => PortStepperWidget(), //dynamic link skipped
'/QR' : (context) => QRscreen()
};
void initialActions() async{
//clean old logger handler
Logger.root.level = Level.ALL;
LH.LoggerHandler loggerHandler = LH.LoggerHandler();
loggerHandler.cleanLegacyLogs();
//update database
loadDatabase(callbackStatus: (storage, isAlreadyUpdated, isValid, {String? exc}) async {
if(isValid) {
if(storage.loggingEnabled){
bool isStarted = await loggerHandler.startLoggingToAppMemory();
if(!isStarted) {
print("main: couldn't start logging!");
loggerHandler.stopLoggingToAppMemory((){}, (){});
}
}
}
});
fillDatabase().then((value) {});
}
void test(BuildContext context) async{
List certificates = [];
final manifestJson = await DefaultAssetBundle.of(context).loadString('AssetManifest.json');
final certPaths = json.decode(manifestJson).keys.where((String key) => key.startsWith('assets/certificates'));
for (var path in certPaths) {
var findExt = path.split('.');
var pkdResourceType = 0;
if (findExt.length > 0)
pkdResourceType = PKDResourceType.getType(findExt[findExt.length - 1].toLowerCase());
ByteData byteData = await rootBundle.load(path);
var certBase64 = base64.encode(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
certificates.add({"binaryData": certBase64, "resourceType": pkdResourceType});
}
DocumentReader.addPKDCertificates(certificates).then((value) => print("certificates added"));
////////////////////////////////////temp end
}
@override
Widget build(BuildContext context) {
this.initialActions();
this.test(context);
//print metadata
getAppMetadata();
return PlatformProvider(
//initialPlatform: initialPlatform,
builder: (BuildContext context) => PlatformApp(
title: 'Port',
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate
],
material: (_, __) => MaterialAppData(
theme: AndroidTheme().getLight(),
darkTheme: AndroidTheme().getDark(),
routes: routes),
cupertino: (_, __) => CupertinoAppData(
theme: iosThemeData(),
routes: routes),
home: Index()
));
}
}