-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CW-865-Create-new-seed-UI-for-Show-seed-keys…
…-page-to-match-onboarding-seed-verification-UI
- Loading branch information
Showing
15 changed files
with
168 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:cw_core/crypto_currency.dart'; | ||
import 'package:cw_core/utils/print_verbose.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
class WellKnownRecord { | ||
WellKnownRecord({ | ||
required this.address, | ||
required this.name, | ||
}); | ||
|
||
final String name; | ||
final String address; | ||
|
||
static Future<String?> checkWellKnownUsername(String username, CryptoCurrency currency) async { | ||
String jsonLocation = ""; | ||
switch (currency) { | ||
case CryptoCurrency.nano: | ||
jsonLocation = "nano-currency"; | ||
break; | ||
// TODO: add other currencies | ||
default: | ||
return null; | ||
} | ||
|
||
// split the string by the @ symbol: | ||
try { | ||
final List<String> splitStrs = username.split("@"); | ||
String name = splitStrs.first.toLowerCase(); | ||
final String domain = splitStrs.last; | ||
|
||
if (splitStrs.length == 3) { | ||
// for username like @[email protected] instead of [email protected] | ||
name = splitStrs[1]; | ||
} | ||
|
||
if (name.isEmpty) { | ||
name = "_"; | ||
} | ||
|
||
// lookup domain/.well-known/nano-currency.json and check if it has a nano address: | ||
final http.Response response = await http.get( | ||
Uri.parse("https://$domain/.well-known/$jsonLocation.json?names=$name"), | ||
headers: <String, String>{"Accept": "application/json"}, | ||
); | ||
|
||
if (response.statusCode != 200) { | ||
return null; | ||
} | ||
final Map<String, dynamic> decoded = json.decode(response.body) as Map<String, dynamic>; | ||
|
||
// Access the first element in the names array and retrieve its address | ||
final List<dynamic> names = decoded["names"] as List<dynamic>; | ||
for (final dynamic item in names) { | ||
if (item["name"].toLowerCase() == name) { | ||
return item["address"] as String; | ||
} | ||
} | ||
} catch (e) { | ||
printV("error checking well-known username: $e"); | ||
} | ||
return null; | ||
} | ||
|
||
static String formatDomainName(String name) { | ||
String formattedName = name; | ||
|
||
if (name.contains("@")) { | ||
formattedName = name.replaceAll("@", "."); | ||
} | ||
|
||
return formattedName; | ||
} | ||
|
||
static Future<WellKnownRecord?> fetchAddressAndName({ | ||
required String formattedName, | ||
required CryptoCurrency currency, | ||
}) async { | ||
String name = formattedName; | ||
|
||
printV("formattedName: $formattedName"); | ||
|
||
final address = await checkWellKnownUsername(formattedName, currency); | ||
|
||
if (address == null) { | ||
return null; | ||
} | ||
|
||
return WellKnownRecord(address: address, name: name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters