remove unused code
Godwin Asuquo committed
Feb 3, 2022 at 11:23 UTC
c162e34ef4a024dc046a4f6fcdacc9a3e0f855f8
2 files changed
+9
-104
cw_core/lib/node.dart
+9
-8
@@ -97,15 +97,16 @@ class Node extends HiveObject with Keyable {
97
98
Future<bool> requestMoneroNode() async {
99
100
- try {
101
- final path = '/json_rpc';
102
- final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
103
- final realm = 'monero-rpc';
104
- final body = {
100
+ final path = '/json_rpc';
101
+ final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
102
+ final realm = 'monero-rpc';
103
+ final body = {
104
'jsonrpc': '2.0',
105
'id': '0',
106
'method': 'get_info'
108
- };
107
+ };
108
+
109
+ try {
110
final authenticatingClient = HttpClient();
111
112
authenticatingClient.addCredentials(
@@ -127,8 +128,8 @@ class Node extends HiveObject with Keyable {
128
final resBody = json.decode(response.body) as Map<String, dynamic>;
129
return !(resBody['result']['offline'] as bool);
130
} catch (_) {
130
- return false;
131
- }
131
+ return false;
132
+ }
133
}
134
135
Future<bool> requestElectrumServer() async {
lib/entities/digest_request.dart
deleted
-96
@@ -1,96 +0,0 @@
1
-import 'dart:convert';
2
-import 'package:dio/dio.dart' as __dio;
3
-import 'package:crypto/crypto.dart' as crypto;
4
-import 'dart:math' as math;
5
-
6
-class DigestRequest {
7
- final md5 = crypto.md5;
8
-
9
- String generateCnonce() {
10
- final rnd = math.Random.secure();
11
- final values = List<int>.generate(32, (i) => rnd.nextInt(256));
12
- return base64Url.encode(values).substring(0, 8);
13
- }
14
-
15
- String generateHA1({String realm, String username, String password}) {
16
- final ha1CredentialsData =
17
- Utf8Encoder().convert('$username:$realm:$password');
18
- final ha1 = md5.convert(ha1CredentialsData).toString();
19
-
20
- return ha1;
21
- }
22
-
23
- String generateHA2({String method, String uri}) {
24
- final ha2Data = Utf8Encoder().convert('$method:$uri');
25
- final ha2 = md5.convert(ha2Data).toString();
26
-
27
- return ha2;
28
- }
29
-
30
- String generateResponseString(
31
- {String ha1,
32
- String ha2,
33
- String nonce,
34
- String nonceCount,
35
- String cnonce,
36
- String qop}) {
37
- final responseData =
38
- Utf8Encoder().convert('$ha1:$nonce:$nonceCount:$cnonce:$qop:$ha2');
39
- final response = md5.convert(responseData).toString();
40
-
41
- return response;
42
- }
43
-
44
- Map<String, String> parsetAuthorizationHeader({String source}) {
45
- final authHeaderParts =
46
- source.substring(7).split(',').map((item) => item.trim());
47
- final authenticate = Map<String, String>();
48
-
49
- for (final part in authHeaderParts) {
50
- final kv = part.split('=');
51
- authenticate[kv[0]] =
52
- kv.getRange(1, kv.length).join('=').replaceAll('"', '');
53
- }
54
-
55
- return authenticate;
56
- }
57
-
58
- Future<__dio.Response> request(
59
- {String uri, String login, String password}) async {
60
- const path = '/json_rpc';
61
- const method = 'POST';
62
- final url = Uri.http(uri, path);
63
- final dio = __dio.Dio();
64
- final headers = {'Content-type': 'application/json'};
65
- final body =
66
- json.encode({"jsonrpc": "2.0", "id": "0", "method": "get_info"});
67
- final credentialsResponse = await dio.post<Object>(url.toString(),
68
- options: __dio.Options(headers: headers, validateStatus: (_) => true));
69
- final authenticate = parsetAuthorizationHeader(
70
- source: credentialsResponse.headers['www-authenticate'].first);
71
- final qop = authenticate['qop'];
72
- final algorithm = 'MD5';
73
- final realm = 'monero-rpc';
74
- final nonce = authenticate['nonce'];
75
- final cnonce = generateCnonce();
76
- final nonceCount = '00000001';
77
- final ha1 = generateHA1(realm: realm, username: login, password: password);
78
- final ha2 = generateHA2(method: method, uri: path);
79
- final response = generateResponseString(
80
- ha1: ha1,
81
- ha2: ha2,
82
- nonce: nonce,
83
- nonceCount: nonceCount,
84
- cnonce: cnonce,
85
- qop: qop);
86
-
87
- final authorizationHeaders = {
88
- 'Content-type': 'application/json',
89
- 'Authorization':
90
- 'Digest username="$login",realm="$realm",nonce="$nonce",uri="$path",algorithm="$algorithm",qop=$qop,nc=$nonceCount,cnonce="$cnonce",response="$response"'
91
- };
92
-
93
- return await dio.post<Object>(url.toString(),
94
- options: __dio.Options(headers: authorizationHeaders), data: body);
95
- }
96
-}