Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Highlights include:
- [Tezos](https://tezos.com/)
- [Wownero](https://wownero.org/)
- [Xelis](https://xelis.org/)
- [Zcash](https://z.cash/)
- All private keys and seeds stay on device and are never shared.
- Easy backup and restore feature to save all the information that's important to you.
- Trading cryptocurrencies through our partners.
Expand Down
1 change: 1 addition & 0 deletions integration_test/wallet_creation/coin_matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ const defaultWordCounts = <String, int>{
'tezos': 24,
'wownero': 16,
'xelis': 25,
'zcash': 24,
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import '../../../utilities/text_styles.dart';
import '../../../utilities/util.dart';
import '../../../wallets/crypto_currency/crypto_currency.dart';
import '../../../wallets/isar/models/wallet_info.dart';
import '../../../wallets/wallet/impl/zcash_wallet.dart';
import '../../../wallets/wallet/intermediate/cryptonote_wallet.dart';
import '../../../wallets/wallet/wallet.dart';
import '../../../wallets/wallet/wallet_mixin_interfaces/mnemonic_interface.dart';
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../widgets/desktop/desktop_app_bar.dart';
import '../../../widgets/desktop/desktop_scaffold.dart';
import '../../../widgets/dialogs/tor_warning_dialog.dart';
import '../../../widgets/rounded_container.dart';
import '../../../widgets/rounded_white_container.dart';
import '../../../widgets/stack_dialog.dart';
Expand Down Expand Up @@ -67,6 +69,18 @@ class _NewWalletRecoveryPhraseWarningViewState
late final bool isDesktop;

Future<void> _initNewWallet() async {
// A new Zcash wallet asks its node for the chain tip, and Zcash does not
// connect through Tor.
if (coin is Zcash && ref.read(prefsChangeNotifierProvider).useTor) {
final shouldContinue =
await showDialog<bool>(
context: context,
builder: (_) => TorWarningDialog(coin: coin),
) ??
false;
if (!shouldContinue || !mounted) return;
}

Exception? ex;
final result = await showLoading(
whileFuture: _initNewFuture(),
Expand Down Expand Up @@ -240,6 +254,21 @@ class _NewWalletRecoveryPhraseWarningViewState

if (wallet is CryptonoteWallet) {
await wallet.init(wordCount: wordCount);
} else if (wallet is ZcashWallet) {
// A new wallet starts scanning at the chain tip, which it asks its
// node for. Without an answer there is no wallet to keep.
final wallets = ref.read(pWallets);
final secureStore = ref.read(secureStoreProvider);
try {
await wallet.init(isRestore: false);
} catch (e) {
await wallet.exit();
await wallets.deleteWallet(info, secureStore);
throw Exception(
"A new Zcash wallet asks its node for the current block. "
"Check the connection and the node, then try again.\n\n$e",
);
}
} else {
await wallet.init();
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import '../../../wallets/isar/models/wallet_info.dart';
import '../../../wallets/wallet/impl/epiccash_wallet.dart';
import '../../../wallets/wallet/impl/mimblewimblecoin_wallet.dart';
import '../../../wallets/wallet/impl/xelis_wallet.dart';
import '../../../wallets/wallet/impl/zcash_wallet.dart';
import '../../../wallets/wallet/intermediate/cryptonote_wallet.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
Expand All @@ -54,6 +55,7 @@ import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../widgets/desktop/desktop_app_bar.dart';
import '../../../widgets/desktop/desktop_scaffold.dart';
import '../../../widgets/desktop/primary_button.dart';
import '../../../widgets/dialogs/tor_warning_dialog.dart';
import '../../../widgets/icon_widgets/clipboard_icon.dart';
import '../../../widgets/icon_widgets/qrcode_icon.dart';
import '../../../widgets/table_view/table_view.dart';
Expand Down Expand Up @@ -211,6 +213,19 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {

Future<void> attemptRestore() async {
if (_formKey.currentState!.validate()) {
// A Zcash restore asks its node about the birthday, and Zcash does not
// connect through Tor.
if (widget.coin is Zcash &&
ref.read(prefsChangeNotifierProvider).useTor) {
final shouldContinue =
await showDialog<bool>(
context: context,
builder: (_) => TorWarningDialog(coin: widget.coin),
) ??
false;
if (!shouldContinue || !mounted) return;
}

if (mounted) setState(() => _hideSeedWords = true);

String mnemonic = "";
Expand Down Expand Up @@ -307,13 +322,17 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {

if (mounted) setState(() => _hideSeedWords = false);

final cancelled = restored;
// A Zcash restore saves its scan state as it goes, so
// it stops before its files are deleted.
if (cancelled is ZcashWallet) await cancelled.exit();

await ref
.read(pWallets)
.deleteWallet(info, ref.read(secureStoreProvider));

// Stop the cancelled restore's network work now: its
// recover() fails and the wallet is never added.
final cancelled = restored;
if (cancelled is ElectrumXInterface) {
await cancelled.electrumXClient.closeAdapter();
}
Expand Down Expand Up @@ -368,6 +387,10 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
await wallet.init(isRestore: true);
break;

case ZcashWallet():
await wallet.init(isRestore: true);
break;

default:
await wallet.init();
}
Expand Down Expand Up @@ -496,6 +519,11 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
!Wallets.sharedInstance.wallets.contains(unused)) {
await unused.electrumXClient.closeAdapter();
}
// Nor its connection to a Zcash node.
if (unused is ZcashWallet &&
!Wallets.sharedInstance.wallets.contains(unused)) {
await unused.exit();
}
}

if (!Platform.isLinux && !isDesktop) {
Expand Down
16 changes: 14 additions & 2 deletions lib/pages/send_view/send_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,9 @@ class _SendViewState extends ConsumerState<SendView> with SendFeeForm {
),
);
} else {
final memo = coin is Stellar ? memoController.text : null;
final memo = coin is Stellar || coin is Zcash
? memoController.text
: null;
txDataFuture = wallet.prepareSend(
txData: TxData(
xelisSendAll: coin is Xelis && _xelisSendAll,
Expand Down Expand Up @@ -1174,6 +1176,16 @@ class _SendViewState extends ConsumerState<SendView> with SendFeeForm {
: ref.read(pWalletBalanceSecondary(walletId)).spendable;
break;
}
} else if (coin is Zcash) {
// A Zcash send does not take its fee out of the amount, so the amount
// leaves room for it.
final spendable = ref.read(pWalletBalance(walletId)).spendable;
final fee = await ref
.read(pWallets)
.getWallet(walletId)
.estimateFeeFor(spendable, BigInt.zero);
if (!mounted) return;
amount = fee < spendable ? spendable - fee : spendable;
} else {
amount = ref.read(pWalletBalance(walletId)).spendable;
}
Expand Down Expand Up @@ -1212,7 +1224,7 @@ class _SendViewState extends ConsumerState<SendView> with SendFeeForm {
coin = widget.coin;
isFiro = coin is Firo;
isEth = coin is Ethereum;
hasOptionalMemo = coin is Stellar || coin is Solana;
hasOptionalMemo = coin is Stellar || coin is Solana || coin is Zcash;

_data = widget.autoFillData;
walletId = widget.walletId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ import '../../../../../utilities/flutter_secure_storage_interface.dart';
import '../../../../../utilities/format.dart';
import '../../../../../utilities/logger.dart';
import '../../../../../utilities/prefs.dart';
import '../../../../../utilities/stack_file_system.dart';
import '../../../../../utilities/util.dart';
import '../../../../../wallets/crypto_currency/coins/zcash.dart';
import '../../../../../wallets/crypto_currency/intermediate/frost_currency.dart';
import '../../../../../wallets/isar/models/frost_wallet_info.dart';
import '../../../../../wallets/isar/models/wallet_info.dart';
import '../../../../../wallets/wallet/impl/bitcoin_frost_wallet.dart';
import '../../../../../wallets/wallet/impl/epiccash_wallet.dart';
import '../../../../../wallets/wallet/impl/mimblewimblecoin_wallet.dart';
import '../../../../../wallets/wallet/impl/xelis_wallet.dart';
import '../../../../../wallets/wallet/impl/zcash_wallet.dart';
import '../../../../../wallets/wallet/intermediate/cryptonote_wallet.dart';
import '../../../../../wallets/wallet/intermediate/zcash_wallet_persistence.dart';
import '../../../../../wallets/wallet/wallet.dart';
import '../../../../../wallets/wallet/wallet_mixin_interfaces/mnemonic_interface.dart';
import '../../../../../wallets/wallet/wallet_mixin_interfaces/private_key_interface.dart';
Expand Down Expand Up @@ -495,6 +499,10 @@ abstract class SWB {
await wallet.init(isRestore: true);
break;

case ZcashWallet():
await wallet.init(isRestore: true);
break;

default:
await wallet.init();
}
Expand Down Expand Up @@ -1132,6 +1140,26 @@ abstract class SWB {
.findAll())
.toSet();
final walletIdsToDelete = allWalletIds.difference(revertToState.walletIds);
// A Zcash wallet also has its scan state on disk, and the key to it in
// secure storage.
final added = await MainDB.instance.isar.walletInfo.getAllByWalletId(
walletIdsToDelete.toList(),
);
for (final info in added.nonNulls.where((info) => info.coin is Zcash)) {
try {
await deleteZcashWalletPersistence(
applicationRoot: await StackFileSystem.applicationRootDirectory(),
walletId: info.walletId,
secureStorage: secureStorageInterface,
);
} catch (e, s) {
Logging.instance.w(
"SWB revert: Zcash state of ${info.walletId}",
error: e,
stackTrace: s,
);
}
}
await MainDB.instance.isar.writeTxn(() async {
await MainDB.instance.isar.walletInfo.deleteAllByWalletId(
walletIdsToDelete.toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,16 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
: ref.read(pWalletBalanceSecondary(walletId)).spendable;
break;
}
} else if (coin is Zcash) {
// A Zcash send does not take its fee out of the amount, so the amount
// leaves room for it.
final spendable = ref.read(pWalletBalance(walletId)).spendable;
final fee = await ref
.read(pWallets)
.getWallet(walletId)
.estimateFeeFor(spendable, BigInt.zero);
if (!mounted) return;
amount = fee < spendable ? spendable - fee : spendable;
} else {
amount = ref.read(pWalletBalance(walletId)).spendable;
}
Expand Down Expand Up @@ -1324,7 +1334,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
coin = ref.read(pWalletInfo(walletId)).coin;
clipboard = widget.clipboard;

hasOptionalMemo = coin is Stellar || coin is Solana;
hasOptionalMemo = coin is Stellar || coin is Solana || coin is Zcash;
usesSlatepacks =
ref.read(pWallets).getWallet(walletId) is SlatepackInterface;

Expand Down
5 changes: 4 additions & 1 deletion lib/providers/wallet/send_fee_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ bool _isFeeAmountIndependent(CryptoCurrency coin) =>

/// Stellar and Cardano give the same fee at every rate.
bool canPickFeeRateType(CryptoCurrency coin, BalanceType balanceType) =>
!_isSparkFee(coin, balanceType) && coin is! Stellar && coin is! Cardano;
!_isSparkFee(coin, balanceType) &&
coin is! Stellar &&
coin is! Cardano &&
coin is! Zcash;

bool canUseCustomFee(CryptoCurrency coin) =>
coin is ElectrumXCurrencyInterface || coin is Ethereum;
Expand Down
22 changes: 22 additions & 0 deletions lib/utilities/test_node_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:on_chain/ada/ada.dart';
import 'package:socks5_proxy/socks.dart';

import '../app_config.dart';
import '../models/node_model.dart';
import '../networking/http.dart';
import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
import '../providers/global/prefs_provider.dart';
Expand All @@ -20,6 +21,7 @@ import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart'
import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart';
import '../wallets/crypto_currency/intermediate/nano_currency.dart';
import '../wallets/wallet/impl/solana_wallet.dart';
import '../wallets/wallet/intermediate/zcash_account_session.dart';
import '../wl_gen/interfaces/lib_xelis_interface.dart';
import '../widgets/tls_certificate_dialog.dart' as electrum_tls;
import 'connection_check/electrum_connection_check.dart';
Expand Down Expand Up @@ -368,6 +370,26 @@ Future<bool> testNodeConnection({
testPassed = false;
}
break;

case Zcash():
testPassed = await ZcashAccountSession.answers(
NodeModel(
host: formData.host!,
port: formData.port!,
name: "",
id: "",
useSSL: formData.useSSL ?? false,
enabled: true,
coinName: cryptoCurrency.identifier,
isFailover: false,
isDown: false,
torEnabled: false,
clearnetEnabled: true,
isPrimary: false,
),
cryptoCurrency.nativeNetwork,
);
break;
}

return testPassed;
Expand Down
21 changes: 21 additions & 0 deletions lib/wallets/wallet/intermediate/zcash_account_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ class ZcashReadinessTimeoutException implements Exception {
class ZcashAccountSession {
static const int maximumBlockHeight = 0xffffffff;

/// Whether [node] is a lightwalletd of [network] that answers, for the
/// node form's connection test.
static Future<bool> answers(
NodeModel node,
zcash.ZcashNetwork network, {
ZcashLightwalletdClientFactory? clientFactory,
}) async {
final session = ZcashAccountSession(
network: network,
clientFactory: clientFactory,
);
try {
await session.replaceNode(node);
return true;
} catch (_) {
return false;
} finally {
await session.close();
}
}

ZcashAccountSession({
required this.network,
ZcashLightwalletdClientFactory? clientFactory,
Expand Down
1 change: 1 addition & 0 deletions scripts/app_config/configure_stack_wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ final List<CryptoCurrency> _supportedCoins = List.unmodifiable([
Tezos(CryptoCurrencyNetwork.main),
Wownero(CryptoCurrencyNetwork.main),
Xelis(CryptoCurrencyNetwork.main),
Zcash(CryptoCurrencyNetwork.main),
Bitcoin(CryptoCurrencyNetwork.test),
Bitcoin(CryptoCurrencyNetwork.test4),
Bitcoincash(CryptoCurrencyNetwork.test),
Expand Down
1 change: 1 addition & 0 deletions scripts/ensure_test_app_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final List<CryptoCurrency> _supportedCoins = List.unmodifiable([
Tezos(CryptoCurrencyNetwork.main),
Wownero(CryptoCurrencyNetwork.main),
Xelis(CryptoCurrencyNetwork.main),
Zcash(CryptoCurrencyNetwork.main),
Bitcoin(CryptoCurrencyNetwork.test),
Bitcoin(CryptoCurrencyNetwork.test4),
Bitcoincash(CryptoCurrencyNetwork.test),
Expand Down
4 changes: 3 additions & 1 deletion scripts/test_wallet_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ ArgParser argumentParser() => ArgParser()
..addFlag(
'all-coins',
negatable: false,
help: 'Accumulate all 24 wallets in one installation.',
help:
'Accumulate all ${defaultWordCounts.length} wallets in one '
'installation.',
)
..addFlag(
'disposable-mobile',
Expand Down
6 changes: 3 additions & 3 deletions scripts/tests/wallet_creation_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void main() {
.map((line) => jsonDecode(line) as Map<String, dynamic>)
.toList();

test('the shared matrix covers the 24 base wallets and excludes FROST', () {
expect(defaultWordCounts, hasLength(24));
test('the shared matrix covers the 25 base wallets and excludes FROST', () {
expect(defaultWordCounts, hasLength(25));
expect(
defaultWordCounts.keys,
containsAll(['eCash', 'epicCash', 'monero', 'solana']),
Expand Down Expand Up @@ -269,7 +269,7 @@ void main() {
final suite = runner(omitCoin: 'xelis');
expect(await suite.run(options(['--device', 'linux', '--all-coins'])), 1);
expect(suite.results.first['failure'], 'incomplete_results');
expect(suite.results.first['completed_coins'], hasLength(23));
expect(suite.results.first['completed_coins'], hasLength(24));
expect(await events(), hasLength(1));
},
);
Expand Down
Loading