Skip to content
Open
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 docs/building/native-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ to build them in `dev` mode.
| Flutter and platform plugins | Target SDKs and the platform's C/C++ build tools in either mode |
| OpenAlias / DNSSEC (every app) | Rustup on the Flutter host in both modes; `dnssec_resolver` builds from source with Rust **1.90.0** |
| Xelis (Stack Wallet) | Rustup; its hook installs Rust **1.99.1** and the required target; Android needs NDK r28 or newer |
| Zcash (Stack Wallet) | Rustup; the `zcash_flutter` hook builds `zcash-ffi` from crates.io sources with the toolchain its `rust-toolchain.toml` pins (Rust **1.99.1**), which the hook installs when it is missing, so no default toolchain is needed. Every app depends on `zcash_flutter`, because `lib/` uses the API it re-exports, but only an app configured with the `ZCASH` flag builds and bundles `zcash-ffi`; the others turn the hook off with `hooks.user_defines.zcash_flutter.enabled: false` |
| Spark (Stack Wallet and Campfire) | CMake and a C++ compiler; its native-assets hook builds from source |
| Coinlib secp256k1 | A separate platform build, described in each host guide |
| MWEB (Stack Wallet) | Go **1.24.1** or newer; CI uses 1.24.13. The Windows executable has a separate WSL build (Go 1.24.0 or newer) or prebuilt download |
Expand Down
12 changes: 11 additions & 1 deletion lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ignore: unused_import
import 'dart:io';

import 'package:meta/meta.dart';

import 'models/isar/models/ethereum/eth_contract.dart';
import 'utilities/default_eth_tokens.dart';
import 'wallets/crypto_currency/crypto_currency.dart';
Expand Down Expand Up @@ -28,7 +30,15 @@ abstract class AppConfig {

static ({String light, String dark})? get appIconAsset => _appIconAsset;

static List<CryptoCurrency> get coins => _supportedCoins;
static List<CryptoCurrency> get coins => _coinsOverride ?? _supportedCoins;

static List<CryptoCurrency>? _coinsOverride;

/// Replaces [coins] for tests of a coin this app config does not list.
/// Null restores the configured list.
@visibleForTesting
static set coinsOverride(List<CryptoCurrency>? coins) =>
_coinsOverride = coins == null ? null : List.unmodifiable(coins);

static List<EthContract> get defaultEthTokens => _defaultEthTokens;

Expand Down
13 changes: 10 additions & 3 deletions lib/models/isar/models/blockchain_data/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ class Address extends CryptoCurrencyAddress {
final json = jsonDecode(jsonString);
final derivationPathString = json["derivationPath"] as String?;

final DerivationPath? derivationPath =
derivationPathString == null ? null : DerivationPath();
final DerivationPath? derivationPath = derivationPathString == null
? null
: DerivationPath();
if (derivationPath != null) {
derivationPath.value = derivationPathString!;
}
Expand Down Expand Up @@ -176,7 +177,9 @@ enum AddressType {
cardanoShelley,
xelis,
fact0rn,
mweb;
mweb,
zcashUnified,
zcashSapling;

String get readableName {
switch (this) {
Expand Down Expand Up @@ -220,6 +223,10 @@ enum AddressType {
return "FACT0RN";
case AddressType.mweb:
return "MWEB";
case AddressType.zcashUnified:
return "Zcash Unified";
case AddressType.zcashSapling:
return "Zcash Sapling";
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/models/isar/models/blockchain_data/address.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/services/price.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PriceAPI {
Nano: "nano",
Banano: "banano",
Xelis: "xelis",
Zcash: "zcash",
Salvium: "salvium",
};

Expand Down
8 changes: 8 additions & 0 deletions lib/services/wallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import '../wallets/wallet/impl/epiccash_wallet.dart';
import '../wallets/wallet/impl/mimblewimblecoin_wallet.dart';
import '../wallets/wallet/intermediate/cryptonote_wallet.dart';
import '../wallets/wallet/intermediate/lib_salvium_wallet.dart';
import '../wallets/wallet/intermediate/zcash_wallet_persistence.dart';
import '../wallets/wallet/wallet.dart';
import '../wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart';
import 'event_bus/events/wallet_added_event.dart';
Expand Down Expand Up @@ -143,6 +144,13 @@ class Wallets {
);
if (await directory.exists()) await directory.delete(recursive: true);
}
if (info.coin is Zcash) {
await deleteZcashWalletPersistence(
applicationRoot: await StackFileSystem.applicationRootDirectory(),
walletId: walletId,
secureStorage: secureStorage,
);
}

await secureStorage.delete(key: Wallet.mnemonicKey(walletId: walletId));
await secureStorage.delete(
Expand Down
1 change: 1 addition & 0 deletions lib/utilities/desktop_startup_and_reset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract final class DesktopStartupAndReset {
'epiccash',
'mimblewimblecoin',
'xelis',
'zcash',
'drift',
'sqlite',
'mwebd',
Expand Down
8 changes: 8 additions & 0 deletions lib/utilities/native_library_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool _always() => true;
bool _hasMonero() => AppConfig.coins.whereType<Monero>().isNotEmpty;
bool _hasWownero() => AppConfig.coins.whereType<Wownero>().isNotEmpty;
bool _hasSalvium() => AppConfig.coins.whereType<Salvium>().isNotEmpty;
bool _hasZcash() => AppConfig.coins.whereType<Zcash>().isNotEmpty;

/// coinlib's secp256k1, named as in its secp256k1_io.dart. Every non
/// cryptonote wallet needs it.
Expand Down Expand Up @@ -91,6 +92,13 @@ const nativeLibraries = [
macos: "SalviumWallet.framework/SalviumWallet",
isBundled: _hasSalvium,
),
NativeLibrary(
displayName: "Zcash wallets",
windows: "zcash_ffi.dll",
linux: "libzcash_ffi.so",
macos: "zcash_ffi.framework/zcash_ffi",
isBundled: _hasZcash,
),
secp256k1NativeLibrary,
];

Expand Down
176 changes: 176 additions & 0 deletions lib/wallets/crypto_currency/coins/zcash.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import 'package:meta/meta.dart';
import 'package:zcash_flutter/zcash_flutter.dart' as zcash;

import '../../../models/isar/models/blockchain_data/address.dart';
import '../../../models/node_model.dart';
import '../../../utilities/default_nodes.dart';
import '../../../utilities/enums/derive_path_type_enum.dart';
import '../crypto_currency.dart';
import '../intermediate/bip39_currency.dart';

class Zcash extends Bip39Currency {
Zcash(super.network) {
switch (network) {
case CryptoCurrencyNetwork.main:
_identifier = 'zcash';
_prettyName = 'Zcash';
_ticker = 'ZEC';
nativeNetwork = zcash.ZcashNetwork.mainnet;
case CryptoCurrencyNetwork.test:
_identifier = 'zcashTestNet';
_prettyName = 'tZcash';
_ticker = 'tZEC';
nativeNetwork = zcash.ZcashNetwork.testnet;
default:
throw ArgumentError.value(network, 'network', 'Unsupported network');
}
}

/// A local regtest chain, for tests that drive a real node. Stack Wallet
/// has no regtest network of its own, so this is a test network with
/// regtest's address encodings and consensus rules.
@visibleForTesting
Zcash.regtest() : super(CryptoCurrencyNetwork.test) {
_identifier = 'zcashRegtest';
_prettyName = 'Zcash Regtest';
_ticker = 'rZEC';
nativeNetwork = zcash.ZcashNetwork.regtest;
}

late final String _identifier;
late final String _prettyName;
late final String _ticker;

/// The network as the Zcash backend names it.
late final zcash.ZcashNetwork nativeNetwork;

// Regtest shares Stack Wallet's test network with testnet, so the base
// comparison by type and network would make the two equal.
@override
bool operator ==(Object other) =>
other is Zcash && other.nativeNetwork == nativeNetwork;

@override
int get hashCode => Object.hash(Zcash, nativeNetwork);

@override
String get identifier => _identifier;

@override
String get mainNetId => 'zcash';

@override
String get prettyName => _prettyName;

@override
String get ticker => _ticker;

@override
String get uriScheme => 'zcash';

@override
int get minConfirms => 1;

@override
int get minCoinbaseConfirms => 100;

@override
String get genesisHash => throw UnimplementedError('Not used for Zcash');

/// Whether [address] is one this wallet can pay: a Unified, Sapling or
/// transparent address of this network. Sprout and TEX addresses decode,
/// but a shielded payment cannot go to them.
@override
bool validateAddress(String address) => getAddressType(address) != null;

@override
AddressType? getAddressType(String address) {
try {
return switch (zcash
.decodeNativeAddress(address: address, network: nativeNetwork)
.receiverType) {
zcash.ZcashAddressReceiverType.unified => AddressType.zcashUnified,
zcash.ZcashAddressReceiverType.sapling => AddressType.zcashSapling,
zcash.ZcashAddressReceiverType.p2pkh => AddressType.p2pkh,
zcash.ZcashAddressReceiverType.p2sh => AddressType.p2sh,
_ => null,
};
} on StateError {
return null;
} on FormatException {
return null;
}
}

@override
NodeModel defaultNode({required bool isPrimary}) {
final (host, port, useSSL) = switch (nativeNetwork) {
zcash.ZcashNetwork.mainnet => ('zec.rocks', 443, true),
zcash.ZcashNetwork.testnet => ('testnet.zec.rocks', 443, true),
zcash.ZcashNetwork.regtest => ('127.0.0.1', 9067, false),
};
return NodeModel(
host: host,
port: port,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: useSSL,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
torEnabled: false,
clearnetEnabled: true,
isPrimary: isPrimary,
);
}

// The lightwalletd connection is gRPC over a direct socket and is not
// routed through Tor.
@override
bool get torSupport => false;

@override
int get defaultSeedPhraseLength => 24;

@override
int get fractionDigits => 8;

@override
bool get hasBuySupport => false;

@override
bool get hasMnemonicPassphraseSupport => true;

@override
List<int> get possibleMnemonicLengths => const [12, 15, 18, 21, 24];

@override
AddressType get defaultAddressType => AddressType.zcashUnified;

@override
BigInt get satsPerCoin => BigInt.from(100000000);

@override
int get targetBlockTimeSeconds => 75;

@override
DerivePathType get defaultDerivePathType => throw UnsupportedError(
'Zcash does not use a Bitcoin-style derivation path selector',
);

@override
Uri defaultBlockExplorer(String txid) => switch (nativeNetwork) {
zcash.ZcashNetwork.mainnet => Uri.https(
'mainnet.zcashexplorer.app',
'/transactions/$txid',
),
zcash.ZcashNetwork.testnet => Uri.https(
'testnet.zcashexplorer.app',
'/transactions/$txid',
),
zcash.ZcashNetwork.regtest => throw UnsupportedError(
'Zcash regtest transactions do not have a public block explorer',
),
};
}
1 change: 1 addition & 0 deletions lib/wallets/crypto_currency/crypto_currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export 'coins/stellar.dart';
export 'coins/tezos.dart';
export 'coins/wownero.dart';
export 'coins/xelis.dart';
export 'coins/zcash.dart';

enum CryptoCurrencyNetwork {
main,
Expand Down
4 changes: 4 additions & 0 deletions lib/wallets/isar/models/wallet_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading