feat: cupcake zcash (#3704)
What changed, and why it matters
This commit adds support for a new Zcash air-gapped hardware wallet mode called 'Cupcake' (a QR-signer). It changes how Zcash wallets are restored from QR codes, how shielding transactions are committed, and how transparent address rotation is skipped for QR-signer wallets. There are no obvious security bugs in the diff, but the new code paths introduce areas where future mistakes could matter: restoring a wallet from a QR-encoded full viewing key, signing transactions via animated QR codes, and skipping address rotation for a new wallet type.
Review the new UR/QR signing and restore flows for input validation, ensure the bc-ur-dart dependency is trustworthy and pinned securely, verify that disabling transparent address rotation for QR-signer wallets does not leak privacy or reuse addresses unexpectedly, and test that the `popped` guard fully prevents double-pops across all scanner entry points.
Security signals we found
New air-gap transaction signing flow (UR/QR PCZT encoding/decoding)
Wallet restoration from QR-encoded Zcash viewing key (ufvk) and account metadata
Transparent address rotation disabled for hardware/QR-signer wallets
Manual shielding now routed through UR QR page for non-hardware wallets in some paths
Dependency added on third-party bc-ur-dart git package
Scanner pop-state race condition fixed with `popped` guard
Evidence from the diff
The patch implements Cupcake-style Zcash support: UR-encoded PCZT (partially-created Zcash transaction) QR flows, account restoration from UR-encoded Zcash accounts, and guards that disable transparent t-address rotation for QR-signer/hardware wallets. Key changes include: new zcash_ur.dart helpers using bc-ur-dart; PendingZcashTransaction.commitUR() now emits/accepts zcash-pczt URs; scanner pages avoid duplicate pops with a popped guard; restore from QR now recognizes ur:zcash-accounts and returns a RestoredWallet with accountIndex/privateKey; ZcashWalletBase treats hardwareWalletType != null as requiring manual shielding; and address rotation is gated by canRotateTransparentAddress (true only for software wallets).
Changed components
cw_zcash Zcash wallet implementationQR scanner / UR scanner pagesZcash restore-from-QR flowZcash shielding / manual shield modalAnimated UR QR transaction pageZcash address rotation subsystemInspect captured patch +337 / −57
### cw_zcash/lib/cw_zcash.dart
@@ -11,6 +11,7 @@ export 'src/zcash_wallet_service.dart';
export 'src/models.dart';
export 'src/zcash_transaction_credentials.dart';
export 'src/pending_zcash_transaction.dart';
+export 'src/zcash_ur.dart';
export 'src/zcash_network.dart';
export 'src/zcash_receive_page_options.dart';
export 'src/zcash_wallet_addresses.dart';
### cw_zcash/lib/src/models.dart
@@ -41,9 +41,12 @@ class ZcashFromKeysWalletCredentials extends WalletCredentials {
final String? password,
required final int? height,
required this.privateKey,
+ this.accountIndex = 0,
this.network = 0,
+ super.hardwareWalletType,
}) : super(name: name, password: password, height: height);
final String? privateKey;
+ final int accountIndex;
int network;
}
### cw_zcash/lib/src/pending_zcash_transaction.dart
@@ -80,8 +80,46 @@ class PendingZcashTransaction with PendingTransaction {
}
@override
- Future<Map<String, String>> commitUR() => throw UnimplementedError('UR not supported for Zcash');
+ Future<Map<String, String>> commitUR() async {
+ zcashWallet.onCommitAirgapUr = _commitScannedUr;
+ return {'Cupcake': encodeZcashPcztUr(txPlan.pczt).join('\n')};
+ }
+
+ Future<void> _commitScannedUr(String raw) async {
+ final parts = raw.split(RegExp(r'\s+')).where((part) => part.startsWith('ur:')).toList();
+ var signed = txPlan.copyWith(pczt: decodeZcashPcztUr(parts));
+ await ZcashWalletBase.runWithCoin(
+ accountId: zcashWallet.accountId,
+ func: (coin) async {
+ try {
+ await zkool_pay.extractTransaction(package: signed);
+ } on Exception {
+ signed = await zkool_pay.finalizeSignedPczt(package: signed);
+ }
+ final result = await zkool_pay.broadcast(
+ package: signed,
+ account: zcashWallet.accountId,
+ c: coin,
+ );
+ printV("result: $result");
+ final txId = ZcashWalletService.normalizeTxId(result);
+ if (txId.length != 64) {
+ throw TransactionCommitFailed(errorMessage: result);
+ }
+ _txId = txId;
+ if (isShieldingTx) {
+ zcashWallet.noteShieldBroadcast();
+ await ZcashWalletService.addShieldedTx(txId);
+ } else {
+ zcashWallet.rememberPendingOutgoingAmount(txId, amount);
+ }
+ },
+ );
+ await zcashWallet.updateTransactions();
+ await zcashWallet.updateBalance(
+ runAutoShield: !isShieldingTx, runIronwoodMigrate: !isShieldingTx);
+ }
@override
- bool shouldCommitUR() => false;
+ bool shouldCommitUR() => zcashWallet.isQrSigner;
}
### cw_zcash/lib/src/zcash_taddress_rotation.dart
@@ -388,6 +388,10 @@ class ZcashTaddressRotation {
}
static Future<void> createAndSweepTAddressesForAccount(final int cId) async {
+ final wallet = ZcashWalletBase.walletsByAccountId[cId];
+ if (wallet != null && !wallet.canRotateTransparentAddress) {
+ return;
+ }
if (!_isWalletSynced(cId)) {
printV("rotation sweep waiting for wallet sync (account $cId)");
return;
### cw_zcash/lib/src/zcash_ur.dart
@@ -0,0 +1,38 @@
+import 'dart:typed_data';
+
+import 'package:ur/ur.dart';
+import 'package:ur/ur_decoder.dart';
+import 'package:ur/ur_encoder.dart';
+import 'package:zkool/src/zcash_ur.dart';
+
+export 'package:zkool/src/zcash_ur.dart'
+ show ZcashUrAccount, ZcashUrAccounts, zcashAccountsType, zcashPcztType;
+
+const zcashPcztFragmentLength = 120;
+
+List<String> encodeZcashPcztUr(Uint8List pczt, {int fragmentLength = zcashPcztFragmentLength}) {
+ final encoder = UREncoder(UR(zcashPcztType, encodeZcashPczt(pczt)), fragmentLength);
+ final parts = <String>[];
+ while (!encoder.isComplete) {
+ parts.add(encoder.nextPart());
+ }
+ return parts;
+}
+
+Uint8List cborFromUrParts(List<String> parts) {
+ final decoder = URDecoder();
+ for (final part in parts) {
+ final trimmed = part.trim();
+ if (trimmed.isEmpty) continue;
+ decoder.receivePart(trimmed);
+ }
+ if (!decoder.isSuccess()) {
+ throw const FormatException('Incomplete Zcash QR');
+ }
+ return (decoder.result as UR).cbor;
+}
+
+Uint8List decodeZcashPcztUr(List<String> parts) => decodeZcashPczt(cborFromUrParts(parts));
+
+ZcashUrAccounts decodeZcashAccountsUr(List<String> parts) =>
+ decodeZcashAccounts(cborFromUrParts(parts));
### cw_zcash/lib/src/zcash_wallet.dart
@@ -68,6 +68,8 @@ abstract class ZcashWalletBase
int accountId;
+ bool get isQrSigner => hardwareWalletType == HardwareWalletType.cupcake;
+
bool get canRotateTransparentAddress => isSoftwareWallet;
bool get canUseLegacyShielded => isSoftwareWallet;
@@ -83,6 +85,8 @@ abstract class ZcashWalletBase
return true;
}
+ Future<void> Function(String ur)? onCommitAirgapUr;
+
final Map<String, BigInt> _pendingOutgoingAmounts = {};
void rememberPendingOutgoingAmount(final String txId, final Money amount) {
@@ -416,6 +420,7 @@ abstract class ZcashWalletBase
for (final wallet in walletsByAccountId.values) {
unawaited(wallet.updateBalance());
unawaited(wallet.updateTransactions());
+ if (!wallet.canRotateTransparentAddress) continue;
unawaited(
ZcashTaddressRotation.updateCache(mainAccountId: wallet.accountId)
.catchError((final e) {
@@ -1179,15 +1184,19 @@ abstract class ZcashWalletBase
Future<void> init() async {
try {
- await ZcashTaddressRotation.init();
+ if (canRotateTransparentAddress) {
+ await ZcashTaddressRotation.init();
+ }
await walletAddresses.init();
await updateBalance();
await updateTransactions();
- unawaited(
- ZcashTaddressRotation.updateCache(mainAccountId: accountId)
- .catchError((final e) => printV("rotation cache refresh: $e")),
- );
+ if (canRotateTransparentAddress) {
+ unawaited(
+ ZcashTaddressRotation.updateCache(mainAccountId: accountId)
+ .catchError((final e) => printV("rotation cache refresh: $e")),
+ );
+ }
await _initKeys();
} catch (e) {
printV("Wallet init error: $e");
@@ -1453,7 +1462,7 @@ abstract class ZcashWalletBase
try {
await _updateIronwoodActive();
- if (!isHardwareWallet) {
+ if (!isHardwareWallet && !isQrSigner) {
if (runAutoShield) {
await _autoShield();
}
@@ -1477,7 +1486,7 @@ abstract class ZcashWalletBase
final ironwood = bal.field0.length > 3 ? bal.field0[3] : BigInt.zero;
// After NU6.3, Orchard notes are migrated to Ironwood - show them as unconfirmed.
- // Unavailable uses the same per-note totals and thresholds as auto-shield/migration guards.
+ // Transparent/sapling uses the shield floor; orchard uses zkool's migrate minimum.
final BigInt availableAmount;
final BigInt unavailableAmount;
final sweepableUnavailable =
@@ -1593,6 +1602,27 @@ abstract class ZcashWalletBase
}
final zcashSecretExtendedKeyRegex = RegExp(r'^secret-extended-key-main1[a-z0-9]+$');
+ if (keys.startsWith('uview')) {
+ final height = (credentials.height ?? 0) > 0
+ ? credentials.height!
+ : (network == ZcashNetwork.mainnet ? 419200 : 280000);
+ final accountId = await newAccount(
+ name: credentials.name,
+ height: height,
+ seed: keys,
+ passphrase: "",
+ hw: 0,
+ aIndex: fromKeysCredentials.accountIndex,
+ );
+ await saveAccountId(credentials.name, accountId);
+ final wallet = await open(
+ name: credentials.name,
+ password: credentials.password!,
+ walletInfo: credentials.walletInfo!,
+ );
+ await wallet.init();
+ return wallet;
+ }
if (!zcashSecretExtendedKeyRegex.hasMatch(keys)) {
throw BadKeysException('Key is not in secret-extended-key-main1 format');
}
### cw_zcash/lib/src/zcash_wallet_addresses.dart
@@ -164,6 +164,8 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
return latestAddress;
}
+ bool get canRotateTransparentAddress => walletInfo.hardwareWalletType == null;
+
Future<void> _init() async {
await _initAddresses();
@@ -176,21 +178,23 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
saplingAddress = addr.saddr ?? 'unknown addr.saddr';
orchardAddress = addr.oaddr ?? 'unknown addr.oaddr';
unifiedAddress = addr.ua ?? 'unknown addr.ua';
- _transparentObservableAddress = await ZcashTaddressRotation.addressForAccount(accountId);
- final rotationAddrs = await ZcashTaddressRotation.allAddressesForAccount(accountId);
- addressInfos = {
- 0: [
- for (int i = 0; i < rotationAddrs.length; i++)
- WalletInfoAddressInfo(
- walletInfoId: walletInfo.internalId,
- mapKey: i + 1,
- accountIndex: 0,
- address: rotationAddrs[i],
- label: "",
- ),
- ],
- };
- await _syncRotationHiddenAddresses();
+ if (canRotateTransparentAddress) {
+ _transparentObservableAddress = await ZcashTaddressRotation.addressForAccount(accountId);
+ final rotationAddrs = await ZcashTaddressRotation.allAddressesForAccount(accountId);
+ addressInfos = {
+ 0: [
+ for (int i = 0; i < rotationAddrs.length; i++)
+ WalletInfoAddressInfo(
+ walletInfoId: walletInfo.internalId,
+ mapKey: i + 1,
+ accountIndex: 0,
+ address: rotationAddrs[i],
+ label: "",
+ ),
+ ],
+ };
+ await _syncRotationHiddenAddresses();
+ }
await _applyAddressForCurrentType();
if (isPlaceholderAddress(walletInfo.address)) {
@@ -205,6 +209,7 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
}
Future<void> refreshRotationAddresses() async {
+ if (!canRotateTransparentAddress) return;
_transparentObservableAddress = await ZcashTaddressRotation.addressForAccount(accountId);
final rotationAddrs = await ZcashTaddressRotation.allAddressesForAccount(accountId);
addressInfos = {
@@ -231,7 +236,7 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
}
Future<void> _applyAddressForCurrentType() async {
- if (_addressPageType == ZcashAddressType.transparentRotated) {
+ if (_addressPageType == ZcashAddressType.transparentRotated && canRotateTransparentAddress) {
final addr = await ZcashTaddressRotation.addressForAccount(accountId);
if (addr != null) {
address = addr;
@@ -268,7 +273,9 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
await walletInfo.setManualAddresses(manualAddresses.toList());
await walletInfo.save();
await _initAddresses();
- await _syncRotationHiddenAddresses();
+ if (canRotateTransparentAddress) {
+ await _syncRotationHiddenAddresses();
+ }
} catch (e) {
printV("Error saving addresses: $e");
}
### cw_zcash/pubspec.yaml
@@ -20,6 +20,10 @@ dependencies:
url: https://github.com/cake-tech/zkool2.git
ref: cb3e96f10e58a8fc8632b40636a0c64aa21fb653
sqflite_common_ffi: any
+ ur:
+ git:
+ url: https://github.com/bukata-sa/bc-ur-dart
+ ref: 5738f70d0ec3d50977ac3dd01fed62939600238b
dependency_overrides:
decimal: ^2.3.3
### lib/entities/qr_scanner.dart
@@ -81,6 +81,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
}
void _handleBarcodeInternal(BarcodeCapture barcodes) {
+ if (popped) return;
for (final barcode in barcodes.barcodes) {
// don't handle unknown QR codes
if (barcode.rawValue?.trim().isEmpty ?? false == false) continue;
@@ -91,15 +92,17 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
urCodes.add(barcode.rawValue!);
ur = URQRToURQRData(urCodes);
});
- if (decoder.estimatedPercentComplete() == 1) {
- setState(() {
- popped = true;
- });
+ // URQR frames keep arriving after the payload is reconstructed.
+ // Popping on each of them dismisses the page below the scanner.
+ if (decoder.isSuccess()) {
+ popped = true;
+ final value = ur.inputs.join("\n");
SchedulerBinding.instance.addPostFrameCallback((_) {
- Navigator.of(context).pop(ur.inputs.join("\n"));
+ if (!mounted) return;
+ Navigator.of(context).pop(value);
});
+ return;
}
- ;
}
}
if (urCodes.isNotEmpty) return;
### lib/new-ui/pages/scan_page.dart
@@ -441,6 +441,9 @@ class _ScanPageState extends State<ScanPage> {
}
void _handleBarcodeInternal(BarcodeCapture barcodes) {
+ if (popped) {
+ return;
+ }
for (final barcode in barcodes.barcodes) {
if (barcode.rawValue?.trim().isEmpty ?? false == false) continue;
if (barcode.rawValue!.startsWith("ur:")) {
@@ -450,15 +453,15 @@ class _ScanPageState extends State<ScanPage> {
urCodes.add(barcode.rawValue!);
ur = URQRToURQRData(urCodes);
});
- if (decoder.estimatedPercentComplete() == 1) {
- setState(() {
- popped = true;
- });
+ if (decoder.isSuccess()) {
+ popped = true;
+ final value = ur.inputs.join("\n");
SchedulerBinding.instance.addPostFrameCallback((_) {
- Navigator.of(context).pop(ur.inputs.join("\n"));
+ if (!mounted) return;
+ Navigator.of(context).pop(value);
});
+ return;
}
- ;
}
}
if (urCodes.isNotEmpty) return;
### lib/new-ui/widgets/coins_page/unconfirmed_balance_widget.dart
@@ -1,4 +1,6 @@
import "package:cake_wallet/di.dart";
+import "package:cw_core/exceptions/cake_exception.dart";
+import "package:cake_wallet/routes.dart";
import 'package:cake_wallet/generated/i18n.dart';
import "package:cake_wallet/new-ui/widgets/coins_page/zcash_manual_shield_modal.dart";
import "package:cake_wallet/new-ui/widgets/coins_page/zcash_migration_modal.dart";
@@ -23,6 +25,33 @@ class UnconfirmedBalanceWidget extends StatelessWidget {
final DashboardViewModel dashboardViewModel;
+ Future<void> _shield(BuildContext context) async {
+ final wallet = dashboardViewModel.wallet;
+ if (wallet.isHardwareWallet) {
+ final hwVM = getIt<HardwareWalletViewModel>(param1: wallet.hardwareWalletType);
+ final connectionEnsured = await hwVM.ensureDeviceConnection(context, wallet);
+ if (!connectionEnsured) {
+ return;
+ }
+ final pendingTx = await zcash!.createShieldingTransaction(wallet);
+ if (pendingTx == null) {
+ throw TransactionGenerationException(S.of(context).shield_amount_below_minimum);
+ }
+ await pendingTx.commit();
+ return;
+ }
+
+ final pendingTx = await zcash!.createShieldingTransaction(wallet);
+ if (pendingTx == null) {
+ throw TransactionGenerationException(S.of(context).shield_amount_below_minimum);
+ }
+ final urstr = await pendingTx.commitUR();
+ if (!context.mounted) {
+ return;
+ }
+ await Navigator.of(context).pushNamed(Routes.urqrAnimatedPage, arguments: urstr);
+ }
+
@override
Widget build(BuildContext context) {
final currency = dashboardViewModel.wallet.currency;
@@ -49,18 +78,7 @@ class UnconfirmedBalanceWidget extends StatelessWidget {
onTap: () {
final modal = ZcashManualShieldModal(
balance: balance.toStringWithSymbol(),
- onShield: () async {
- if (dashboardViewModel.wallet.hardwareWalletType != null) {
- final hwVM = getIt<HardwareWalletViewModel>(
- param1: dashboardViewModel.wallet.hardwareWalletType,
- );
- final connectionEnsured = await hwVM.ensureDeviceConnection(context, dashboardViewModel.wallet);
- if (connectionEnsured) {
- final pendingTx = await zcash!.createShieldingTransaction(dashboardViewModel.wallet);
- await pendingTx?.commit();
- }
- }
- },
+ onShield: () => _shield(context),
);
showMaterialModalBottomSheet(
backgroundColor: Colors.transparent,
### lib/new-ui/widgets/coins_page/zcash_manual_shield_modal.dart
@@ -2,8 +2,11 @@ import "package:cake_wallet/generated/i18n.dart";
import "package:cake_wallet/new-ui/widgets/new_future_primary_button.dart";
import "package:cake_wallet/new-ui/widgets/new_primary_button.dart";
import "package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart";
+import "package:cake_wallet/src/widgets/alert_with_one_action.dart";
import "package:cake_wallet/src/widgets/cake_image_widget.dart";
import "package:cake_wallet/themes/core/theme_extension.dart";
+import "package:cake_wallet/utils/show_pop_up.dart";
+import "package:cw_core/exceptions/cake_exception.dart";
import "package:flutter/material.dart";
class ZcashManualShieldModal extends StatelessWidget {
@@ -13,7 +16,23 @@ class ZcashManualShieldModal extends StatelessWidget {
final Future<void> Function() onShield;
Future<void> _onShield(BuildContext context) async {
- await onShield.call();
+ try {
+ await onShield.call();
+ } on CakeException catch (e) {
+ if (!context.mounted) {
+ return;
+ }
+ await showPopUp<void>(
+ context: context,
+ builder: (context) => AlertWithOneAction(
+ alertTitle: S.of(context).error,
+ alertContent: e.message,
+ buttonText: S.of(context).ok,
+ buttonAction: Navigator.of(context).pop,
+ ),
+ );
+ return;
+ }
if (context.mounted) {
Navigator.of(context).pop();
### lib/src/screens/restore/restore_options_page.dart
@@ -177,6 +177,7 @@ class _RestoreOptionsBodyState extends State<_RestoreOptionsBody> {
if (mounted) setState(() => isRestoring = false);
});
} catch (e) {
+ if (mounted) setState(() => isRestoring = false);
_showQRScanError(context, e.toString());
}
}
### lib/src/screens/ur/animated_ur_page.dart
@@ -11,6 +11,7 @@ import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/animated_ur_model.dart';
+import 'package:cake_wallet/zcash/zcash.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
@@ -64,7 +65,7 @@ class AnimatedURPage extends BasePage {
hardwareWalletType: animatedURmodel.wallet.hardwareWalletType,
),
),
- if (["ur:xmr-txunsigned", "ur:xmr-output", "ur:psbt", BBQR.header].contains(urQrType)) ...{
+ if (["ur:xmr-txunsigned", "ur:xmr-output", "ur:psbt", "ur:zcash-pczt", BBQR.header].contains(urQrType)) ...{
Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
@@ -106,6 +107,27 @@ class AnimatedURPage extends BasePage {
if (ur == null) return;
await bitcoin!.commitPsbtUR(animatedURmodel.wallet, ur.trim().split("\n"));
Navigator.of(context).pop(true);
+ break;
+ case "ur:zcash-pczt":
+ final ur = await presentQRScanner(context, showManualInput: false);
+ if (ur == null || !context.mounted) return;
+ unawaited(
+ showDialog<void>(
+ context: context,
+ useRootNavigator: true,
+ barrierDismissible: false,
+ builder: (_) => const Center(child: CircularProgressIndicator()),
+ ),
+ );
+ try {
+ await zcash!.commitZcashPcztUR(animatedURmodel.wallet, ur);
+ } finally {
+ if (context.mounted) {
+ Navigator.of(context, rootNavigator: true).pop();
+ }
+ }
+ if (context.mounted) Navigator.of(context).pop(true);
+ break;
default:
throw UnimplementedError("unable to handle UR: ${urQrType}");
}
### lib/view_model/dashboard/dashboard_view_model.dart
@@ -385,7 +385,8 @@ abstract class DashboardViewModelBase with Store {
wallet.type == WalletType.zcash && (zcash?.hasOrchardMigratableBalance(wallet) ?? false);
@computed
- bool get requiresManualShield => wallet.type == WalletType.zcash && wallet.isHardwareWallet;
+ bool get requiresManualShield =>
+ wallet.type == WalletType.zcash && wallet.hardwareWalletType != null;
@computed
bool get isSyncHeavy {
### lib/view_model/restore/restore_wallet.dart
@@ -21,7 +21,8 @@ class RestoredWallet {
this.txDescription,
this.recipientName,
this.height,
- this.privateKey});
+ this.privateKey,
+ this.accountIndex});
final WalletRestoreMode restoreMode;
final WalletType type;
@@ -39,6 +40,7 @@ class RestoredWallet {
final String? recipientName;
final int? height;
final String? privateKey;
+ final int? accountIndex;
factory RestoredWallet.fromKey(Map<String, dynamic> json) {
try {
### lib/view_model/restore/wallet_restore_from_qr_code.dart
@@ -10,6 +10,7 @@ import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import "package:cake_wallet/wallet_types.g.dart";
+import 'package:cake_wallet/zcash/zcash.dart';
import 'package:cw_core/currency_for_wallet_type.dart';
import "package:cw_core/exceptions/cake_exception.dart";
import 'package:cw_core/wallet_type.dart';
@@ -122,6 +123,27 @@ class WalletRestoreFromQRCode {
if (code == null) throw ScanValueException("QR scan is cancelled");
if (code.isEmpty) throw ScanValueException('Unexpected scan QR code value: value is empty');
+ final accountsQr = zcash?.decodeZcashAccountsQr(code);
+ if (accountsQr != null) {
+ if (accountsQr.accounts.isEmpty) {
+ throw ScanValueException('No Zcash accounts found');
+ }
+ final account = accountsQr.accounts.firstWhere(
+ (item) => item.index == 0,
+ orElse: () => accountsQr.accounts.first,
+ );
+ final name = account.name;
+ return RestoredWallet(
+ restoreMode: WalletRestoreMode.keys,
+ type: WalletType.zcash,
+ address: null,
+ name: name == null || name.isEmpty ? null : name,
+ privateKey: account.ufvk,
+ accountIndex: account.index,
+ height: 0,
+ );
+ }
+
if (code.startsWith("[")) code = code.substring(code.indexOf("]") + 1);
String formattedUri = '';
@@ -261,6 +283,14 @@ class WalletRestoreFromQRCode {
return WalletRestoreMode.keys;
}
+ if (type == WalletType.zcash && credentials.containsKey('private_key')) {
+ final privateKey = credentials['private_key'] as String;
+ if (privateKey.isEmpty) {
+ throw ScanValueException('Unexpected restore mode: private_key');
+ }
+ return WalletRestoreMode.keys;
+ }
+
if (type == WalletType.monero) {
final codeParsed = json.decode(credentials['raw_qr'].toString());
if (codeParsed["version"] != 0)
### lib/view_model/wallet_restore_view_model.dart
@@ -331,7 +331,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
name: name,
privateKey: options['private_key'] as String,
password: password,
- height: height);
+ height: height,
+ accountIndex: restoredWallet?.accountIndex ?? 0,
+ hardwareWalletType: hardwareWalletType);
default:
break;
}
### lib/zcash/cw_zcash.dart
@@ -23,12 +23,16 @@ class CWZcash extends Zcash {
{required String name,
required String privateKey,
required String password,
- required int height}) {
+ required int height,
+ int accountIndex = 0,
+ HardwareWalletType? hardwareWalletType}) {
return ZcashFromKeysWalletCredentials(
name: name,
height: height,
privateKey: privateKey,
password: password,
+ accountIndex: accountIndex,
+ hardwareWalletType: hardwareWalletType,
);
}
@@ -233,6 +237,33 @@ class CWZcash extends Zcash {
return (wallet as ZcashWallet).hasOrchardMigratableBalance();
}
+ @override
+ Future<void> commitZcashPcztUR(Object wallet, String ur) {
+ final commit = (wallet as ZcashWallet).onCommitAirgapUr;
+ if (commit == null) {
+ throw TransactionSendingException('No Zcash QR transaction is waiting to be signed');
+ }
+ return commit(ur);
+ }
+
+ @override
+ ZcashAccountsQr? decodeZcashAccountsQr(String code) {
+ if (!code.contains('ur:$zcashAccountsType')) return null;
+ final parts = code.split(RegExp(r'\s+')).where((part) => part.startsWith('ur:')).toList();
+ final decoded = decodeZcashAccountsUr(parts);
+ return ZcashAccountsQr(
+ decoded.accounts
+ .map(
+ (account) => ZcashAccountQr(
+ ufvk: account.ufvk,
+ index: account.index,
+ name: account.name,
+ ),
+ )
+ .toList(),
+ );
+ }
+
@override
Future<void> setHardwareWalletService(WalletBase wallet, HardwareWalletService service) async {
if (service is ZcashHardwareWalletService) {
### res/values/strings_en.arb
@@ -1216,6 +1216,7 @@
"share_this_node": "Share this node",
"shared_seed_wallet_groups": "Shared Seed Wallet Groups",
"shared_seed_wallets": "Shared Seed Wallets",
+ "shield_amount_below_minimum": "The unshielded amount is below the minimum that can be shielded.",
"shield_device_funds": "Shield Device Funds",
"shield_funds": "Shield Funds",
"shield_them_to_use_device": "Shield them to use this device",
### tool/configure.dart
@@ -1760,6 +1760,7 @@ import 'package:cw_core/receive_page_option.dart';
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/hardware/hardware_wallet_service.dart';
import 'package:cw_core/pending_transaction.dart';
+import 'package:cw_core/exceptions/cake_exception.dart';
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart' as ledger;
""";
@@ -1772,6 +1773,20 @@ import 'package:cw_zcash/src/zcash_wallet_addresses.dart';
""";
const zcashCwPart = "part 'cw_zcash.dart';";
const zcashContent = """
+class ZcashAccountQr {
+ const ZcashAccountQr({required this.ufvk, required this.index, this.name});
+
+ final String ufvk;
+ final int index;
+ final String? name;
+}
+
+class ZcashAccountsQr {
+ const ZcashAccountsQr(this.accounts);
+
+ final List<ZcashAccountQr> accounts;
+}
+
abstract class Zcash {
List<String> getZcashWordList(String language);
WalletService createZcashWalletService(bool isDirect);
@@ -1790,7 +1805,12 @@ abstract class Zcash {
required int? height,
int network = 0});
WalletCredentials createZcashRestoreWalletFromPrivateKey(
- {required String name, required String privateKey, required String password, required int height});
+ {required String name,
+ required String privateKey,
+ required String password,
+ required int height,
+ int accountIndex = 0,
+ HardwareWalletType? hardwareWalletType});
WalletCredentials createZcashHardwareWalletCredentials({
required String name,
required HardwareWalletService hardwareWalletService,
@@ -1836,6 +1856,8 @@ abstract class Zcash {
Future<void> rescanInternalChange(WalletBase wallet);
bool ironwoodActive(WalletAddresses walletAddresses);
bool hasOrchardMigratableBalance(WalletBase wallet);
+ Future<void> commitZcashPcztUR(Object wallet, String ur);
+ ZcashAccountsQr? decodeZcashAccountsQr(String code);
Future<PendingTransaction?> createShieldingTransaction(WalletBase wallet);
}
""";Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.