diff --git a/packages/espressocash_app/ios/Podfile.lock b/packages/espressocash_app/ios/Podfile.lock index cc5afe168b..6b8f13c1a7 100644 --- a/packages/espressocash_app/ios/Podfile.lock +++ b/packages/espressocash_app/ios/Podfile.lock @@ -296,7 +296,7 @@ SPEC CHECKSUMS: FirebaseSharedSwift: 76e1529c32101d80e4f1ca2fba7c39d59f0a390a Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_inappwebview_ios: 97215cf7d4677db55df76782dbd2930c5e1c1ea0 - flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778 + flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a GoogleMLKit: 97ac7af399057e99182ee8edfa8249e3226a4065 diff --git a/packages/espressocash_app/lib/features/sign_in/services/sign_in_bloc.dart b/packages/espressocash_app/lib/features/sign_in/services/sign_in_bloc.dart index f1425b1467..0fa0729eea 100644 --- a/packages/espressocash_app/lib/features/sign_in/services/sign_in_bloc.dart +++ b/packages/espressocash_app/lib/features/sign_in/services/sign_in_bloc.dart @@ -1,7 +1,6 @@ import 'package:bip39/bip39.dart' as bip39; import 'package:bloc_concurrency/bloc_concurrency.dart'; import 'package:dfunc/dfunc.dart'; - import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; diff --git a/packages/espressocash_app/lib/features/stellar/constants.dart b/packages/espressocash_app/lib/features/stellar/constants.dart new file mode 100644 index 0000000000..8d237f8226 --- /dev/null +++ b/packages/espressocash_app/lib/features/stellar/constants.dart @@ -0,0 +1,28 @@ +import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; + +const _isStellarProd = + bool.fromEnvironment('STELLAR_PROD', defaultValue: false); + +final stellarNetwork = _isStellarProd ? Network.PUBLIC : Network.TESTNET; +final stellarSdk = _isStellarProd ? StellarSDK.PUBLIC : StellarSDK.TESTNET; + +const _devBaseUrl = 'https://extstellar.moneygram.com/stellaradapterservice'; +const _prodBaseUrl = 'https://stellar.moneygram.com/stellaradapterservice'; +const moneygramBaseUrl = _isStellarProd ? _prodBaseUrl : _devBaseUrl; + +const _devSigningKey = + 'GCSESAP5ILVM6CWIEGK2SDOCQU7PHVFYYT7JNKRDAQNVQWKD5YEE5ZJ4'; +const _prodSigningKey = + 'GD5NUMEX7LYHXGXCAD4PGW7JDMOUY2DKRGY5XZHJS5IONVHDKCJYGVCL'; +const moneygramSigningKey = _isStellarProd ? _prodSigningKey : _devSigningKey; + +const _devAssetIssuer = + 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'; +const _prodAssetIssuer = + 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'; +const moneygramAssetIssuer = + _isStellarProd ? _prodAssetIssuer : _devAssetIssuer; + +const _devAuthDomain = 'stellar-dev.espressocash.com'; +const _prodAuthDomain = 'espressocash.com'; +const espressoClientDomain = _isStellarProd ? _prodAuthDomain : _devAuthDomain; diff --git a/packages/espressocash_app/lib/features/stellar/models/stellar_wallet.dart b/packages/espressocash_app/lib/features/stellar/models/stellar_wallet.dart new file mode 100644 index 0000000000..d9fd16ada1 --- /dev/null +++ b/packages/espressocash_app/lib/features/stellar/models/stellar_wallet.dart @@ -0,0 +1,19 @@ +import 'dart:typed_data'; + +import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; + +Future createStellarWallet({required String mnemonic}) async { + final wallet = await Wallet.from(mnemonic); + + return StellarWallet(await wallet.getKeyPair()); +} + +class StellarWallet { + const StellarWallet(this.keyPair); + + final KeyPair keyPair; + + String get address => keyPair.accountId; + + Uint8List sign(Uint8List payload) => keyPair.sign(payload); +} diff --git a/packages/espressocash_app/lib/features/stellar/service/stellar_client.dart b/packages/espressocash_app/lib/features/stellar/service/stellar_client.dart new file mode 100644 index 0000000000..7ed997eccd --- /dev/null +++ b/packages/espressocash_app/lib/features/stellar/service/stellar_client.dart @@ -0,0 +1,24 @@ +import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; + +class StellarClient { + const StellarClient(this._sdk); + + final StellarSDK _sdk; + + Future getXlmBalance(String accountId) async { + try { + final account = await _sdk.accounts.account(accountId); + final nativeAsset = AssetTypeNative(); + + for (final balance in account.balances) { + if (balance.assetType == nativeAsset.type) { + return double.parse(balance.balance); + } + } + } on Exception { + return 0.0; + } + + return 0.0; + } +} diff --git a/packages/espressocash_app/lib/features/stellar/stellar_module.dart b/packages/espressocash_app/lib/features/stellar/stellar_module.dart new file mode 100644 index 0000000000..4565b6c04d --- /dev/null +++ b/packages/espressocash_app/lib/features/stellar/stellar_module.dart @@ -0,0 +1,23 @@ +import 'package:injectable/injectable.dart'; + +import '../accounts/auth_scope.dart'; +import '../accounts/data/account_repository.dart'; +import 'constants.dart'; +import 'models/stellar_wallet.dart'; +import 'service/stellar_client.dart'; + +@module +abstract class StellarModule { + const StellarModule(); + + @Singleton(scope: authScope) + @preResolve + Future wallet(AccountRepository repository) async { + final mnemonic = await repository.loadMnemonic(); + + return createStellarWallet(mnemonic: mnemonic); + } + + @LazySingleton(scope: authScope) + StellarClient stellarClient() => StellarClient(stellarSdk); +} diff --git a/packages/espressocash_app/pubspec.lock b/packages/espressocash_app/pubspec.lock index 6bb8993d8d..08379ef071 100644 --- a/packages/espressocash_app/pubspec.lock +++ b/packages/espressocash_app/pubspec.lock @@ -707,10 +707,10 @@ packages: dependency: "direct dev" description: name: flutter_native_splash - sha256: edf39bcf4d74aca1eb2c1e43c3e445fd9f494013df7f0da752fefe72020eedc0 + sha256: "17d9671396fb8ec45ad10f4a975eb8a0f70bedf0fdaf0720b31ea9de6da8c4da" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.3.7" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -1342,10 +1342,10 @@ packages: dependency: transitive description: name: petitparser - sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750 url: "https://pub.dev" source: hosted - version: "6.0.2" + version: "5.4.0" pinenacl: dependency: transitive description: @@ -1749,6 +1749,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" + stellar_flutter_sdk: + dependency: "direct main" + description: + name: stellar_flutter_sdk + sha256: "7d505963fe11d0f90b3f798964c485ed9fa64731c38f14c9b2fb76d5d5bd6cd8" + url: "https://pub.dev" + source: hosted + version: "1.8.1" storybook_flutter: dependency: "direct main" description: @@ -1845,6 +1853,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + toml: + dependency: transitive + description: + name: toml + sha256: "69756bc12eccf279b72217a87310d217efc4b3752f722e890f672801f19ac485" + url: "https://pub.dev" + source: hosted + version: "0.13.1" tuple: dependency: transitive description: @@ -1893,6 +1909,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.2" + unorm_dart: + dependency: transitive + description: + name: unorm_dart + sha256: "5b35bff83fce4d76467641438f9e867dc9bcfdb8c1694854f230579d68cd8f4b" + url: "https://pub.dev" + source: hosted + version: "0.2.0" url_launcher: dependency: "direct main" description: @@ -2065,10 +2089,10 @@ packages: dependency: transitive description: name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84" url: "https://pub.dev" source: hosted - version: "6.5.0" + version: "6.3.0" yaml: dependency: transitive description: diff --git a/packages/espressocash_app/pubspec.yaml b/packages/espressocash_app/pubspec.yaml index ba1c6ee307..e8eb6b2446 100644 --- a/packages/espressocash_app/pubspec.yaml +++ b/packages/espressocash_app/pubspec.yaml @@ -72,6 +72,7 @@ dependencies: solana_mobile_wallet: path: ../solana_mobile_wallet/ sqlite3_flutter_libs: ^0.5.18 + stellar_flutter_sdk: ^1.8.0 storybook_flutter: ^0.14.0 uni_links: ^0.5.1 url_launcher: ^6.2.2 @@ -84,7 +85,7 @@ dev_dependencies: flutter_driver: sdk: flutter flutter_gen_runner: ^5.4.0 - flutter_native_splash: ^2.3.8 + flutter_native_splash: ^2.3.7 flutter_test: sdk: flutter freezed: ^2.4.6