Merge pull request #1456 from cypherstack/feat/openalias
What changed, and why it matters
This commit adds OpenAlias support for Monero sends in Stack Wallet. OpenAlias lets users type a human-readable alias (like alice@example.com) instead of a long crypto address; the wallet then looks up the corresponding Monero address via DNS. The change introduces a new lookup service, wires it into the mobile and desktop send flows, and shows the resolved alias on the confirmation screen. It also adds many tests. There is no direct evidence in the commit of a security vulnerability, but any DNS-based alias system introduces new trust and privacy considerations.
Reviewers should verify that cs_openalias and its transitive dependencies (dnssec_resolver, doh_transport, openalias) correctly enforce DNSSEC and do not allow downgrade or clearnet fallback. Confirm that resolved addresses cannot be substituted after preview but before signing, and that the cached resolution TTL cannot be exploited to replay an outdated address. Consider auditing how the app handles a malicious or compromised resolver, and ensure the UI clearly distinguishes an OpenAlias-resolved send from a direct-address send.
Security signals we found
New network dependency: DNS/OpenAlias lookups can leak recipient alias and resolver metadata to DNS/DoH servers and the network path
Tor routing is enforced when Tor is enabled, with no clearnet fallback, reducing network-level exposure
Incognito mode blocks lookups entirely, preventing accidental network leakage
Resolved address is validated by the coin's validateAddress before being used in transaction construction
Alias is displayed on the confirmation screen so the user can verify what was resolved
DNSSEC validation is delegated to the cs_openalias/dnssec_resolver packages; commit does not show implementation details
Potential for DNS spoofing or malicious OpenAlias records if DNSSEC validation is incomplete or bypassed
No evidence in the diff of input sanitization beyond existing address validation and the package's own alias parsing
Evidence from the diff
The merge adds the cs_openalias package and a new OpenAliasService that performs DNS lookups for OpenAlias records, optionally routed through Tor, and only when external calls are enabled. Monero is configured with openAliasApplication = ‘xmr’. SendView and DesktopSend now detect OpenAlias inputs, validate them as send targets, resolve them to addresses before building transactions, cache resolutions with a TTL, and pass the original alias into TxData so it can be displayed on ConfirmTransactionView. The service refuses lookups in Incognito mode and when Tor is enabled but unavailable. Tests cover resolution, caching, cancellation, errors, and UI integration.
Changed components
lib/services/openalias/open_alias_service.dartlib/pages/send_view/send_view.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dartlib/pages/send_view/confirm_transaction_view.dartlib/wallets/crypto_currency/coins/monero.dartlib/wallets/crypto_currency/crypto_currency.dartlib/wallets/models/tx_data.dartpubspec.lock / pubspec.template.yaml (cs_openalias, dnssec_resolver, doh_transport, openalias, socks_socket dependencies)Inspect captured patch +1909 / −38
### lib/pages/send_view/confirm_transaction_view.dart
@@ -769,6 +769,25 @@ class _ConfirmTransactionViewState
children: [
Text("Send $unit", style: STextStyles.pageTitleH1(context)),
const SizedBox(height: 12),
+ if (widget.txData.openAlias != null) ...[
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text(
+ "OpenAlias",
+ style: STextStyles.smallMed12(context),
+ ),
+ const SizedBox(height: 4),
+ Text(
+ widget.txData.openAlias!,
+ style: STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 12),
+ ],
RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -1125,6 +1144,41 @@ class _ConfirmTransactionViewState
.extension<StackColors>()!
.background,
),
+ if (widget.txData.openAlias != null) ...[
+ Padding(
+ padding: const EdgeInsets.all(12),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "OpenAlias",
+ style: STextStyles.desktopTextExtraExtraSmall(
+ context,
+ ),
+ ),
+ const SizedBox(height: 2),
+ SelectableText(
+ widget.txData.openAlias!,
+ style:
+ STextStyles.desktopTextExtraExtraSmall(
+ context,
+ ).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textDark,
+ ),
+ ),
+ ],
+ ),
+ ),
+ Container(
+ height: 1,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .background,
+ ),
+ ],
Padding(
padding: const EdgeInsets.all(12),
child: Column(
### lib/pages/send_view/send_view.dart
@@ -11,6 +11,7 @@
import 'dart:async';
import 'dart:io';
+import 'package:cs_openalias/cs_openalias.dart';
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -30,6 +31,7 @@ import '../../providers/ui/fee_rate_type_state_provider.dart';
import '../../providers/ui/preview_tx_button_state_provider.dart';
import '../../providers/wallet/public_private_balance_state_provider.dart';
import '../../route_generator.dart';
+import '../../services/openalias/open_alias_service.dart';
import '../../services/spark_names_service.dart';
import '../../themes/coin_icon_provider.dart';
import '../../themes/stack_colors.dart';
@@ -149,7 +151,17 @@ class _SendViewState extends ConsumerState<SendView> {
late final bool isEth;
Amount? _cachedAmountToSend;
- String? _address;
+ String? _addressValue;
+ OpenAliasResolved? _openAlias;
+
+ String? get _address => _addressValue;
+
+ // Clearing and retyping an alias passes through other text, so the lookup
+ // is dropped then rather than kept for the same alias typed again.
+ set _address(String? value) {
+ _addressValue = value;
+ if (openAliasKey(value ?? "") != _openAlias?.alias) _openAlias = null;
+ }
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
@@ -237,8 +249,15 @@ class _SendViewState extends ConsumerState<SendView> {
}
void _addRecipientTapped() {
+ final resolved = _openAlias;
+ final address =
+ resolved != null &&
+ resolved.alias == openAliasKey(_address ?? "") &&
+ ref.read(pOpenAliasService).isCurrent(resolved)
+ ? resolved.address
+ : _address ?? "";
_setMultiRecipients([
- (address: _address ?? "", amount: ref.read(pSendAmount), label: null),
+ (address: address, amount: ref.read(pSendAmount), label: null),
(address: "", amount: null, label: null),
]);
}
@@ -703,8 +722,9 @@ class _SendViewState extends ConsumerState<SendView> {
}
}
- ref.read(pValidSendToAddress.notifier).state = wallet.cryptoCurrency
- .validateAddress(address ?? "");
+ ref.read(pValidSendToAddress.notifier).state =
+ wallet.cryptoCurrency.validateAddress(address ?? "") ||
+ (coin.openAliasApplication != null && isOpenAlias(address ?? ""));
}
}
@@ -1018,11 +1038,75 @@ class _SendViewState extends ConsumerState<SendView> {
}
}
+ /// Looks up the OpenAlias in the address field. Returns null if the lookup
+ /// failed or was cancelled.
+ Future<OpenAliasResolved?> _resolveOpenAlias(String application) async {
+ final resolution = ref
+ .read(pOpenAliasService)
+ .resolve(
+ _address!,
+ isValidAddress: coin.validateAddress,
+ application: application,
+ coinName: coin.prettyName,
+ );
+ unawaited(
+ showDialog<void>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: false,
+ builder: (context) => BuildingTransactionDialog(
+ coin: coin,
+ isSpark: false,
+ onCancel: () {
+ resolution.cancel();
+ Navigator.of(context).pop();
+ },
+ ),
+ ),
+ );
+ final outcome = await resolution.outcome;
+ if (!mounted) return null;
+ switch (outcome) {
+ case OpenAliasCancelled():
+ return null;
+ case OpenAliasResolved():
+ Navigator.of(context, rootNavigator: true).pop();
+ return outcome;
+ case OpenAliasFailed(:final title, :final message):
+ Navigator.of(context, rootNavigator: true).pop();
+ unawaited(
+ showDialog<void>(
+ context: context,
+ builder: (context) => StackOkDialog(title: title, message: message),
+ ),
+ );
+ return null;
+ }
+ }
+
Future<void> _previewTransaction() async {
// wait for keyboard to disappear
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 100));
final wallet = ref.read(pWallets).getWallet(walletId);
+ String? openAlias;
+ String? resolvedAddress;
+ final application = coin.openAliasApplication;
+ if (application != null &&
+ !coin.validateAddress(_address ?? "") &&
+ isOpenAlias(_address ?? "")) {
+ var resolved = _openAlias;
+ if (resolved == null ||
+ resolved.alias != openAliasKey(_address!) ||
+ !ref.read(pOpenAliasService).isCurrent(resolved)) {
+ resolved = _openAlias = await _resolveOpenAlias(application);
+ }
+ if (resolved == null || !mounted) return;
+ openAlias = resolved.alias;
+ resolvedAddress = resolved.address;
+ _setValidAddressProviders(resolvedAddress);
+ }
+ late final recipientAddress = resolvedAddress ?? _address!;
final Amount amount = ref.read(pSendAmount)!;
final Amount availableBalance;
@@ -1166,12 +1250,13 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
sparkRecipients: [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos: (coinControlEnabled && selectedUTXOs.isNotEmpty)
@@ -1184,14 +1269,15 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos: (coinControlEnabled && selectedUTXOs.isNotEmpty)
@@ -1210,24 +1296,25 @@ class _SendViewState extends ConsumerState<SendView> {
? null
: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
]
: null,
+ openAlias: openAlias,
),
);
break;
@@ -1239,12 +1326,15 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
- addressType: wallet.cryptoCurrency.getAddressType(_address!)!,
+ addressType: wallet.cryptoCurrency.getAddressType(
+ recipientAddress,
+ )!,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
@@ -1266,14 +1356,15 @@ class _SendViewState extends ConsumerState<SendView> {
_multiRecipients?.toTxRecipients(wallet.cryptoCurrency) ??
[
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
+ openAlias: openAlias,
memo: memo,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
@@ -1379,6 +1470,7 @@ class _SendViewState extends ConsumerState<SendView> {
if (!mounted) {
return;
}
+ _openAlias = null;
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -10,6 +10,7 @@
import 'dart:async';
+import 'package:cs_openalias/cs_openalias.dart';
import 'package:decimal/decimal.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
@@ -37,6 +38,7 @@ import '../../../../providers/ui/fee_rate_type_state_provider.dart';
import '../../../../providers/ui/preview_tx_button_state_provider.dart';
import '../../../../providers/wallet/desktop_fee_providers.dart';
import '../../../../providers/wallet/public_private_balance_state_provider.dart';
+import '../../../../services/openalias/open_alias_service.dart';
import '../../../../services/spark_names_service.dart';
import '../../../../themes/stack_colors.dart';
import '../../../../utilities/address_utils.dart';
@@ -73,6 +75,7 @@ import '../../../../widgets/desktop/desktop_dialog_close_button.dart';
import '../../../../widgets/desktop/primary_button.dart';
import '../../../../widgets/desktop/qr_code_scanner_dialog.dart';
import '../../../../widgets/desktop/secondary_button.dart';
+import '../../../../widgets/desktop/simple_desktop_dialog.dart';
import '../../../../widgets/dialogs/firo_exchange_address_dialog.dart';
import '../../../../widgets/epic_txs_method_toggle.dart';
import '../../../../widgets/eth_fee_form.dart';
@@ -135,7 +138,17 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
String? _onChainNote;
Amount? _cachedAmountToSend;
- String? _address;
+ String? _addressValue;
+ OpenAliasResolved? _openAlias;
+
+ String? get _address => _addressValue;
+
+ // Clearing and retyping an alias passes through other text, so the lookup
+ // is dropped then rather than kept for the same alias typed again.
+ set _address(String? value) {
+ _addressValue = value;
+ if (openAliasKey(value ?? "") != _openAlias?.alias) _openAlias = null;
+ }
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
@@ -437,12 +450,84 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
}
+ /// Looks up the OpenAlias in the address field. Returns null if the lookup
+ /// failed or was cancelled.
+ Future<OpenAliasResolved?> _resolveOpenAlias(String application) async {
+ final resolution = ref
+ .read(pOpenAliasService)
+ .resolve(
+ _address!,
+ isValidAddress: coin.validateAddress,
+ application: application,
+ coinName: coin.prettyName,
+ );
+ unawaited(
+ showDialog<void>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: false,
+ builder: (context) => DesktopDialog(
+ maxWidth: 400,
+ maxHeight: double.infinity,
+ child: Padding(
+ padding: const EdgeInsets.all(32),
+ child: BuildingTransactionDialog(
+ coin: coin,
+ isSpark: false,
+ onCancel: () {
+ resolution.cancel();
+ Navigator.of(context).pop();
+ },
+ ),
+ ),
+ ),
+ ),
+ );
+ final outcome = await resolution.outcome;
+ if (!mounted) return null;
+ switch (outcome) {
+ case OpenAliasCancelled():
+ return null;
+ case OpenAliasResolved():
+ Navigator.of(context, rootNavigator: true).pop();
+ return outcome;
+ case OpenAliasFailed(:final title, :final message):
+ Navigator.of(context, rootNavigator: true).pop();
+ unawaited(
+ showDialog<void>(
+ context: context,
+ builder: (context) =>
+ SimpleDesktopDialog(title: title, message: message),
+ ),
+ );
+ return null;
+ }
+ }
+
Future<void> previewSend() async {
final nonceInput = _nonceInput;
if (!nonceInput.isValid) return;
final nonce = nonceInput.value;
final wallet = ref.read(pWallets).getWallet(walletId);
+ String? openAlias;
+ String? resolvedAddress;
+ final application = coin.openAliasApplication;
+ if (application != null &&
+ !coin.validateAddress(_address ?? "") &&
+ isOpenAlias(_address ?? "")) {
+ var resolved = _openAlias;
+ if (resolved == null ||
+ resolved.alias != openAliasKey(_address!) ||
+ !ref.read(pOpenAliasService).isCurrent(resolved)) {
+ resolved = _openAlias = await _resolveOpenAlias(application);
+ }
+ if (resolved == null || !mounted) return;
+ openAlias = resolved.alias;
+ resolvedAddress = resolved.address;
+ _setValidAddressProviders(resolvedAddress);
+ }
+ late final recipientAddress = resolvedAddress ?? _address!;
// Handle MWC slatepack transactions directly.
if (isMimblewimblecoin && ref.read(pIsSlatepack(widget.walletId))) {
@@ -632,12 +717,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
sparkRecipients: [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos:
@@ -652,14 +738,15 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos:
@@ -680,24 +767,25 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
? null
: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
]
: null,
+ openAlias: openAlias,
),
);
break;
@@ -709,12 +797,15 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
- addressType: wallet.cryptoCurrency.getAddressType(_address!)!,
+ addressType: wallet.cryptoCurrency.getAddressType(
+ recipientAddress,
+ )!,
),
],
+ openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
// these will need to be mweb utxos
@@ -735,14 +826,15 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
_multiRecipients?.toTxRecipients(wallet.cryptoCurrency) ??
[
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
+ openAlias: openAlias,
memo: memo,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
@@ -875,6 +967,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
if (!mounted) {
return;
}
+ _openAlias = null;
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
@@ -1021,8 +1114,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
}
- ref.read(pValidSendToAddress.notifier).state = wallet.cryptoCurrency
- .validateAddress(address ?? "");
+ ref.read(pValidSendToAddress.notifier).state =
+ wallet.cryptoCurrency.validateAddress(address ?? "") ||
+ (coin.openAliasApplication != null && isOpenAlias(address ?? ""));
}
}
@@ -1095,8 +1189,15 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
void _addRecipientTapped() {
+ final resolved = _openAlias;
+ final address =
+ resolved != null &&
+ resolved.alias == openAliasKey(_address ?? "") &&
+ ref.read(pOpenAliasService).isCurrent(resolved)
+ ? resolved.address
+ : _address ?? "";
_setMultiRecipients([
- (address: _address ?? "", amount: ref.read(pSendAmount), label: null),
+ (address: address, amount: ref.read(pSendAmount), label: null),
(address: "", amount: null, label: null),
]);
}
### lib/services/openalias/open_alias_service.dart
@@ -0,0 +1,229 @@
+import 'dart:io';
+
+import 'package:cs_openalias/cs_openalias.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import '../../app_config.dart';
+import '../../utilities/logger.dart';
+import '../../utilities/prefs.dart';
+import '../tor_service.dart';
+
+final pOpenAliasService = Provider<OpenAliasService>((_) => OpenAliasService());
+
+const openAliasLookupFailedTitle = 'OpenAlias lookup failed';
+
+String openAliasErrorMessage(CsOpenAliasException e, String coinName) =>
+ switch (e) {
+ CsOpenAliasInvalidAliasException() =>
+ 'Enter a valid address or OpenAlias.',
+ CsOpenAliasNoRecordException() =>
+ 'No $coinName OpenAlias record was found for ${e.alias}.',
+ CsOpenAliasInvalidRecordException() =>
+ 'This alias has an invalid or unsupported $coinName record for this '
+ 'wallet.',
+ CsOpenAliasDnssecException() =>
+ 'DNSSEC verification failed or is unavailable. Ask the recipient for a '
+ 'verified alias or address.',
+ CsOpenAliasNetworkException() =>
+ 'OpenAlias lookup failed. Check your connection and try again.',
+ CsOpenAliasCancelledException() => 'OpenAlias lookup cancelled.',
+ };
+
+String openAliasKey(String input) => input.trim().toLowerCase();
+
+typedef OpenAliasLookup = CsOpenAliasOperation<CsOpenAliasRecipient> Function(
+ String alias, {
+ required bool Function(String address) isValidAddress,
+ required String application,
+ required CsOpenAliasProxy? proxy,
+});
+
+/// Thrown by [OpenAliasService.lookup] when no lookup may be sent.
+final class OpenAliasUnavailableException implements Exception {
+ const OpenAliasUnavailableException(this.message);
+
+ final String message;
+
+ @override
+ String toString() => message;
+}
+
+/// Starts OpenAlias lookups that follow the Incognito and Tor settings.
+class OpenAliasService {
+ OpenAliasService({
+ bool Function()? externalCalls,
+ bool Function()? useTor,
+ bool Function()? supportsTor,
+ ({InternetAddress host, int port}) Function()? torProxy,
+ OpenAliasLookup? lookup,
+ DateTime Function()? now,
+ }) : _externalCalls = externalCalls ?? (() => Prefs.instance.externalCalls),
+ _useTor = useTor ?? (() => Prefs.instance.useTor),
+ _supportsTor =
+ supportsTor ?? (() => AppConfig.hasFeature(AppFeature.tor)),
+ _torProxy = torProxy ?? (() => TorService.sharedInstance.getProxyInfo()),
+ _lookup = lookup ?? resolveOpenAlias,
+ _now = now ?? DateTime.now;
+
+ final bool Function() _externalCalls;
+ final bool Function() _useTor;
+ final bool Function() _supportsTor;
+ final ({InternetAddress host, int port}) Function() _torProxy;
+ final OpenAliasLookup _lookup;
+ final DateTime Function() _now;
+
+ /// Why no lookup can be sent now, or null when one can.
+ String? unavailableReason() => _route().unavailable;
+
+ /// Looks up the [application] record of [alias], through Tor when Tor is
+ /// on. Throws [OpenAliasUnavailableException] without sending anything when
+ /// Incognito mode is on or Tor is on but unavailable.
+ CsOpenAliasOperation<CsOpenAliasRecipient> lookup(
+ String alias, {
+ required bool Function(String address) isValidAddress,
+ required String application,
+ }) {
+ final route = _route();
+ final unavailable = route.unavailable;
+ if (unavailable != null) {
+ throw OpenAliasUnavailableException(unavailable);
+ }
+ return _lookup(
+ alias,
+ isValidAddress: isValidAddress,
+ application: application,
+ proxy: route.proxy,
+ );
+ }
+
+ /// Whether [resolved] is still within the TTL of its answer.
+ bool isCurrent(OpenAliasResolved resolved) =>
+ resolved.expiresAt.isAfter(_now());
+
+ /// Starts [lookup] for the alias typed into a send field.
+ OpenAliasResolution resolve(
+ String input, {
+ required bool Function(String address) isValidAddress,
+ required String application,
+ required String coinName,
+ }) => OpenAliasResolution._(
+ () =>
+ lookup(input, isValidAddress: isValidAddress, application: application),
+ alias: openAliasKey(input),
+ coinName: coinName,
+ now: _now,
+ );
+
+ ({String? unavailable, CsOpenAliasProxy? proxy}) _route() {
+ if (!_externalCalls()) {
+ return (
+ unavailable:
+ 'OpenAlias lookups are off in Incognito mode. To use OpenAlias, '
+ 'switch ${AppConfig.prefix} Experience to Easy Crypto in Advanced '
+ 'settings.',
+ proxy: null,
+ );
+ }
+ if (!_useTor()) {
+ return (unavailable: null, proxy: null);
+ }
+ if (_supportsTor()) {
+ try {
+ final info = _torProxy();
+ return (
+ unavailable: null,
+ proxy: CsOpenAliasProxy(address: info.host.address, port: info.port),
+ );
+ } catch (_) {
+ // Tor is not connected. Unlike Electrum, never fall back to clearnet,
+ // even with the kill switch off: the resolver and the network path
+ // would see this address asking for the alias domain.
+ }
+ }
+ return (
+ unavailable: 'Tor is unavailable. No lookup was sent.',
+ proxy: null,
+ );
+ }
+}
+
+sealed class OpenAliasOutcome {
+ const OpenAliasOutcome();
+}
+
+final class OpenAliasResolved extends OpenAliasOutcome {
+ const OpenAliasResolved({
+ required this.alias,
+ required this.address,
+ required this.expiresAt,
+ });
+
+ final String alias;
+ final String address;
+ final DateTime expiresAt;
+}
+
+final class OpenAliasFailed extends OpenAliasOutcome {
+ const OpenAliasFailed(this.message);
+
+ String get title => openAliasLookupFailedTitle;
+ final String message;
+}
+
+final class OpenAliasCancelled extends OpenAliasOutcome {
+ const OpenAliasCancelled();
+}
+
+// Bounds reuse even if a resolver hands back an inflated TTL.
+const _maxReuse = Duration(hours: 1);
+
+/// A lookup started by [OpenAliasService.resolve].
+final class OpenAliasResolution {
+ OpenAliasResolution._(
+ CsOpenAliasOperation<CsOpenAliasRecipient> Function() start, {
+ required String alias,
+ required String coinName,
+ required DateTime Function() now,
+ }) {
+ outcome = _run(start, alias, coinName, now);
+ }
+
+ late final Future<OpenAliasOutcome> outcome;
+ CsOpenAliasOperation<CsOpenAliasRecipient>? _operation;
+ bool _cancelled = false;
+
+ void cancel() {
+ _cancelled = true;
+ _operation?.cancel();
+ }
+
+ Future<OpenAliasOutcome> _run(
+ CsOpenAliasOperation<CsOpenAliasRecipient> Function() start,
+ String alias,
+ String coinName,
+ DateTime Function() now,
+ ) async {
+ try {
+ // The TTL is what remained when the answer arrived; count it from the
+ // start so a slow lookup cannot extend it.
+ final started = now();
+ _operation = start();
+ final recipient = await _operation!.result;
+ if (_cancelled) return const OpenAliasCancelled();
+ final ttl = recipient.ttl < _maxReuse ? recipient.ttl : _maxReuse;
+ return OpenAliasResolved(
+ alias: alias,
+ address: recipient.address,
+ expiresAt: started.add(ttl),
+ );
+ } catch (e, s) {
+ if (_cancelled) return const OpenAliasCancelled();
+ Logging.instance.w("OpenAlias lookup failed", error: e, stackTrace: s);
+ return OpenAliasFailed(switch (e) {
+ CsOpenAliasException() => openAliasErrorMessage(e, coinName),
+ OpenAliasUnavailableException(:final message) => message,
+ _ => 'The OpenAlias lookup failed.',
+ });
+ }
+ }
+}
### lib/wallets/crypto_currency/coins/monero.dart
@@ -45,6 +45,9 @@ class Monero extends CryptonoteCurrency {
@override
bool get torSupport => true;
+ @override
+ String? get openAliasApplication => "xmr";
+
@override
bool validateAddress(String address) {
if (address.contains("111")) {
### lib/wallets/crypto_currency/crypto_currency.dart
@@ -63,6 +63,10 @@ abstract class CryptoCurrency {
// Override in subclass if the currency has Tor support:
bool get torSupport => false;
+ // Override in subclass if the currency supports OpenAlias: the application
+ // of its records, e.g. "xmr" for `oa1:xmr` records.
+ String? get openAliasApplication => null;
+
int get minConfirms;
int get minCoinbaseConfirms => minConfirms;
int? get mwebPegoutMaturity => null;
### lib/wallets/models/tx_data.dart
@@ -57,6 +57,11 @@ class TxData {
final String? memo;
final List<TxRecipient>? recipients;
+
+ /// The OpenAlias, trimmed and lowercased, that the recipient's address was
+ /// resolved from.
+ final String? openAlias;
+
final Set<BaseInput>? utxos;
final List<BaseInput>? usedUTXOs;
@@ -137,6 +142,7 @@ class TxData {
this.noteOnChain,
this.memo,
this.recipients,
+ this.openAlias,
this.utxos,
this.usedUTXOs,
this.changeAddress,
@@ -287,6 +293,7 @@ class TxData {
Set<BaseInput>? utxos,
List<BaseInput>? usedUTXOs,
List<TxRecipient>? recipients,
+ String? openAlias,
String? frostMSConfig,
List<String>? frostSigners,
String? changeAddress,
@@ -341,6 +348,7 @@ class TxData {
utxos: utxos ?? this.utxos,
usedUTXOs: usedUTXOs ?? this.usedUTXOs,
recipients: recipients ?? this.recipients,
+ openAlias: openAlias ?? this.openAlias,
frostMSConfig: frostMSConfig ?? this.frostMSConfig,
frostSigners: frostSigners ?? this.frostSigners,
changeAddress: changeAddress ?? this.changeAddress,
### pubspec.lock
@@ -516,6 +516,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
+ cs_openalias:
+ dependency: "direct main"
+ description:
+ name: cs_openalias
+ sha256: a14c689a3e1f1440fa694992bafdda81b11e3677290fd4633b2423e67c0ca484
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.1"
cs_salvium:
dependency: "direct main"
description:
@@ -829,6 +837,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
+ dnssec_resolver:
+ dependency: transitive
+ description:
+ name: dnssec_resolver
+ sha256: "07c297c779d92f493c5de247e799a464447d8accd499c5b481c160247bece971"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.1"
+ doh_transport:
+ dependency: transitive
+ description:
+ name: doh_transport
+ sha256: "290ef817e1bf0e674d7efebe1c6bbfccc2c5b7d08271e7c6952e4d845a56ee95"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.1"
drift:
dependency: "direct main"
description:
@@ -889,11 +913,11 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: b6fa44d015d3bfa06934b73219928c29ca48a290
- resolved-ref: b6fa44d015d3bfa06934b73219928c29ca48a290
+ ref: "76ffad6ecc1e31de47d9187fd39c831db0aa987f"
+ resolved-ref: "76ffad6ecc1e31de47d9187fd39c831db0aa987f"
url: "https://github.com/cypherstack/electrum_adapter.git"
source: git
- version: "3.0.2"
+ version: "4.0.1"
emojis:
dependency: "direct main"
description:
@@ -1232,8 +1256,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "14427bcbbe1e754bce4a1b93cdb0a31ce56d792b"
- resolved-ref: "14427bcbbe1e754bce4a1b93cdb0a31ce56d792b"
+ ref: "7548bf1c6e79a82e991c3feb61c1908dfe324275"
+ resolved-ref: "7548bf1c6e79a82e991c3feb61c1908dfe324275"
url: "https://github.com/cypherstack/fusiondart.git"
source: git
version: "1.0.0"
@@ -1750,6 +1774,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.5.0"
+ openalias:
+ dependency: transitive
+ description:
+ name: openalias
+ sha256: be84930643f2720ddc48dd5de69d47ba5c647df35f8f9b873eb285f5e57fb5ad
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.1"
package_config:
dependency: transitive
description:
@@ -2140,13 +2172,13 @@ packages:
source: hosted
version: "2.1.1"
socks_socket:
- dependency: transitive
+ dependency: "direct main"
description:
name: socks_socket
- sha256: "53bc7eae40a3aa16ea810b0e9de3bb23ba7beb0b40d09357b89190f2f44374cc"
+ sha256: "09149ed1278584554aeacc60c7aeec5bd80154e6ce1136f00d97485d09d5a338"
url: "https://pub.dev"
source: hosted
- version: "1.1.1"
+ version: "2.0.0"
solana:
dependency: "direct main"
description:
### scripts/app_config/templates/pubspec.template.yaml
@@ -117,10 +117,12 @@ dependencies:
fusiondart:
git:
url: https://github.com/cypherstack/fusiondart.git
- ref: 14427bcbbe1e754bce4a1b93cdb0a31ce56d792b
+ ref: 7548bf1c6e79a82e991c3feb61c1908dfe324275
# Utility plugins
http: ^1.6.0
+ cs_openalias: ^0.0.1
+ socks_socket: ^2.0.0
local_auth: ^2.3.0
permission_handler: ^13.0.1
flutter_local_notifications: ^22.3.0
@@ -229,7 +231,7 @@ dependencies:
electrum_adapter:
git:
url: https://github.com/cypherstack/electrum_adapter.git
- ref: b6fa44d015d3bfa06934b73219928c29ca48a290
+ ref: 76ffad6ecc1e31de47d9187fd39c831db0aa987f
stream_channel: ^2.1.0
solana:
git: # TODO [prio=low]: Revert to official package once Tor support is merged upstream.
### test/pages/send_view/open_alias_preview_test.dart
@@ -0,0 +1,771 @@
+import 'dart:async';
+
+import 'package:cs_openalias/cs_openalias.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:platform/platform.dart' as platform;
+import 'package:stackwallet/models/balance.dart';
+import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
+import 'package:stackwallet/models/isar/stack_theme.dart';
+import 'package:stackwallet/models/paymint/fee_object_model.dart';
+import 'package:stackwallet/models/send_view_auto_fill_data.dart';
+import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
+import 'package:stackwallet/pages/send_view/frost_ms/recipient.dart';
+import 'package:stackwallet/pages/send_view/send_view.dart';
+import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart';
+import 'package:stackwallet/providers/providers.dart';
+import 'package:stackwallet/providers/ui/preview_tx_button_state_provider.dart';
+import 'package:stackwallet/services/openalias/open_alias_service.dart';
+import 'package:stackwallet/services/wallets.dart';
+import 'package:stackwallet/themes/coin_icon_provider.dart';
+import 'package:stackwallet/themes/coin_image_provider.dart';
+import 'package:stackwallet/themes/stack_colors.dart';
+import 'package:stackwallet/themes/theme_providers.dart';
+import 'package:stackwallet/utilities/amount/amount.dart';
+import 'package:stackwallet/utilities/amount/amount_unit.dart';
+import 'package:stackwallet/utilities/prefs.dart';
+import 'package:stackwallet/utilities/util.dart';
+import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
+import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart';
+import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
+import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
+import 'package:stackwallet/wallets/models/tx_data.dart';
+import 'package:stackwallet/wallets/wallet/intermediate/cryptonote_wallet.dart';
+import 'package:stackwallet/wallets/wallet/wallet.dart';
+import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
+import 'package:stackwallet/widgets/desktop/primary_button.dart';
+
+import '../../sample_data/theme_json.dart';
+
+const literal =
+ '4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FH'
+ 'XDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn';
+const alias = 'Alice@Example.com';
+const balance = 10000000000000;
+
+Amount amount(int value) =>
+ Amount(rawValue: BigInt.from(value), fractionDigits: 12);
+
+bool _isValid(String address) =>
+ address == literal || address == 'second-recipient';
+
+AddressType _addressType(String address) {
+ if (!_isValid(address)) throw StateError('Unresolved recipient: $address');
+ return AddressType.cryptonote;
+}
+
+class _Monero extends Monero {
+ _Monero() : super(CryptoCurrencyNetwork.main);
+ @override
+ bool validateAddress(String address) => _isValid(address);
+ @override
+ AddressType? getAddressType(String address) => _addressType(address);
+}
+
+class _Wownero extends Wownero {
+ _Wownero([this.application]) : super(CryptoCurrencyNetwork.main);
+ String? application;
+ @override
+ String? get openAliasApplication => application;
+ @override
+ bool validateAddress(String address) => _isValid(address);
+ @override
+ AddressType? getAddressType(String address) => _addressType(address);
+}
+
+class _Info extends Fake implements WalletInfo {
+ _Info(this.coin);
+ @override
+ final CryptoCurrency coin;
+ @override
+ String get walletId => 'wallet';
+ @override
+ String get name => 'Test wallet';
+ @override
+ bool get isMwebEnabled => false;
+ @override
+ Balance get cachedBalance => Balance(
+ total: amount(balance),
+ spendable: amount(balance),
+ blockedTotal: amount(0),
+ pendingSpendable: amount(0),
+ );
+}
+
+class _Wallet extends Fake implements CryptonoteWallet {
+ _Wallet(this.cryptoCurrency) : info = _Info(cryptoCurrency);
+ @override
+ final CryptonoteCurrency cryptoCurrency;
+ @override
+ final WalletInfo info;
+ final prepared = <TxData>[];
+ @override
+ bool get supportsMultiRecipient => true;
+ @override
+ Future<FeeObject> get fees async => FeeObject(
+ numberOfBlocksFast: 1,
+ numberOfBlocksAverage: 2,
+ numberOfBlocksSlow: 3,
+ fast: BigInt.one,
+ medium: BigInt.one,
+ slow: BigInt.one,
+ );
+ @override
+ int getTxPriorityHigh() => 3;
+ @override
+ int getTxPriorityMedium() => 2;
+ @override
+ int getTxPriorityNormal() => 1;
+ @override
+ Future<Amount> estimateFeeFor(Amount value, BigInt feeRate) async =>
+ amount(10);
+ @override
+ Future<TxData> prepareSend({required TxData txData}) async {
+ prepared.add(txData);
+ return txData.copyWith(fee: amount(10));
+ }
+
+ @override
+ Future<void> cancelSend({required TxData txData}) async {}
+}
+
+class _Wallets extends Fake implements Wallets {
+ _Wallets(this.wallet);
+ final Wallet wallet;
+ @override
+ Wallet getWallet(String walletId) => wallet;
+}
+
+class _Prefs extends ChangeNotifier implements Prefs {
+ @override
+ String get currency => 'USD';
+ @override
+ bool get externalCalls => false;
+ @override
+ bool get enableCoinControl => false;
+ @override
+ AmountUnit amountUnit(CryptoCurrency coin) => AmountUnit.normal;
+ // Short balances keep the mobile balance row within 390 px in the test font.
+ @override
+ int maxDecimals(CryptoCurrency coin) => 2;
+ @override
+ dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
+class _Lookup {
+ _Lookup(this.alias, this.isValidAddress, this.application);
+ final String alias;
+ final bool Function(String) isValidAddress;
+ final String application;
+ final result = Completer<CsOpenAliasRecipient>();
+ int cancels = 0;
+}
+
+class _Harness {
+ _Harness(this.desktop, {CryptonoteCurrency? coin, this.incognito = false})
+ : coin = coin ?? _Monero();
+
+ final bool desktop;
+ final CryptonoteCurrency coin;
+ final bool incognito;
+ late final _Wallet wallet = _Wallet(coin);
+ late final ProviderContainer container;
+ final navigator = GlobalKey<NavigatorState>();
+ final lookups = <_Lookup>[];
+ var now = DateTime.utc(2026, 10, 28, 12);
+
+ late final service = OpenAliasService(
+ externalCalls: () => !incognito,
+ useTor: () => false,
+ now: () => now,
+ lookup:
+ (
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) {
+ final lookup = _Lookup(alias, isValidAddress, application);
+ lookups.add(lookup);
+ return CsOpenAliasOperation(lookup.result.future, () {
+ lookup.cancels++;
+ if (!lookup.result.isCompleted) {
+ lookup.result.completeError(
+ CsOpenAliasCancelledException('cancelled', alias: alias),
+ );
+ }
+ });
+ },
+ );
+
+ Future<void> mount(
+ WidgetTester tester, {
+ SendViewAutoFillData? autofill,
+ }) async {
+ final size = desktop ? const Size(1200, 900) : const Size(390, 844);
+ final previousPlatform = Util.layoutPlatform;
+ final previousWidth = Util.screenWidth;
+ final previousIsIpad = Util.isIpad;
+ Util.layoutPlatform = platform.FakePlatform(
+ operatingSystem: desktop ? 'macos' : 'android',
+ );
+ Util.isIpad = false;
+ tester.view.physicalSize = size;
+ tester.view.devicePixelRatio = 1;
+ Util.screenWidth = size.width;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ addTearDown(() {
+ Util.layoutPlatform = previousPlatform;
+ Util.screenWidth = previousWidth;
+ Util.isIpad = previousIsIpad;
+ });
+ expect(Util.isDesktop, desktop);
+ final theme = StackTheme.fromJson(json: lightThemeJsonMap);
+ container = ProviderContainer(
+ overrides: [
+ themeProvider.overrideWithProvider(StateProvider((_) => theme)),
+ pWallets.overrideWithValue(_Wallets(wallet)),
+ pWalletInfo('wallet').overrideWithValue(wallet.info),
+ pWalletCoin('wallet').overrideWithValue(coin),
+ pWalletName('wallet').overrideWithValue('Test wallet'),
+ pWalletBalance('wallet').overrideWithValue(wallet.info.cachedBalance),
+ prefsChangeNotifierProvider.overrideWithValue(_Prefs()),
+ coinIconProvider(coin)
+ .overrideWithValue('test/sample_data/light/assets/dummy.svg'),
+ coinImageSecondaryProvider(coin).overrideWithValue('dummy.svg'),
+ pOpenAliasService.overrideWithValue(service),
+ ],
+ );
+ addTearDown(() async {
+ await tester.pumpWidget(const SizedBox());
+ await tester.pumpAndSettle();
+ container.dispose();
+ });
+ await tester.pumpWidget(
+ UncontrolledProviderScope(
+ container: container,
+ child: MaterialApp(
+ navigatorKey: navigator,
+ theme: ThemeData(
+ extensions: [StackColors.fromStackColorTheme(theme)],
+ ),
+ home: const Scaffold(body: Text('Home')),
+ ),
+ ),
+ );
+ unawaited(
+ navigator.currentState!.push(
+ MaterialPageRoute<void>(
+ builder: (_) => desktop
+ ? Scaffold(
+ body: SingleChildScrollView(
+ child: DesktopSend(
+ walletId: 'wallet',
+ autoFillData: autofill,
+ ),
+ ),
+ )
+ : SendView(
+ walletId: 'wallet',
+ coin: coin,
+ autoFillData: autofill,
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ expect(tester.takeException(), isNull);
+ }
+
+ Finder get field => find.byKey(const Key('sendViewAddressFieldKey'));
+ Finder get button => find.text(desktop ? 'Preview send' : 'Preview');
+ Finder get ok => find.text(desktop ? 'Ok' : 'OK');
+ TxData confirmed(WidgetTester tester) => tester
+ .widget<ConfirmTransactionView>(find.byType(ConfirmTransactionView))
+ .txData;
+ // The send screen is offstage under the mobile confirm screen.
+ String text(WidgetTester tester) => tester
+ .widget<TextField>(
+ find.byKey(const Key('sendViewAddressFieldKey'), skipOffstage: false),
+ )
+ .controller!
+ .text;
+ bool enabled(WidgetTester tester) => desktop
+ ? tester
+ .widget<PrimaryButton>(
+ find.ancestor(of: button, matching: find.byType(PrimaryButton)),
+ )
+ .enabled
+ : tester
+ .widget<TextButton>(
+ find.ancestor(of: button, matching: find.byType(TextButton)),
+ )
+ .onPressed !=
+ null;
+
+ Future<void> enter(WidgetTester tester, String destination) async {
+ await tester.enterText(field, destination);
+ await tester.pumpAndSettle();
+ }
+
+ Future<void> setAmount(
+ WidgetTester tester, [
+ int value = 1000000000000,
+ ]) async {
+ container.read(pSendAmount.notifier).state = amount(value);
+ await tester.pumpAndSettle();
+ }
+
+ /// Taps Preview and stops while the lookup is pending; the progress dialog
+ /// animates, so this never settles.
+ Future<void> preview(WidgetTester tester) async {
+ await tester.ensureVisible(button);
+ await tester.tap(button);
+ await tester.pump(const Duration(milliseconds: 150));
+ await tester.pump();
+ }
+
+ Future<void> finish(WidgetTester tester) async {
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 3));
+ await tester.pumpAndSettle();
+ expect(tester.takeException(), isNull);
+ }
+
+ void succeed() => lookups.last.result.complete(
+ CsOpenAliasRecipient(
+ domain: 'alice.example.com',
+ address: literal,
+ fields: const {'recipient_address': literal},
+ ttl: const Duration(seconds: 60),
+ ),
+ );
+
+ /// Previews, completes the lookup and goes back to the form.
+ Future<void> previewAndReturn(WidgetTester tester) async {
+ await preview(tester);
+ succeed();
+ await finish(tester);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+ }
+}
+
+void main() {
+ for (final desktop in [false, true]) {
+ final layout = desktop ? 'desktop 1200x900' : 'mobile 390x844';
+
+ testWidgets('$layout an alias in the Monero field enables Preview', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.setAmount(tester);
+ await h.enter(tester, 'not an alias');
+ expect(find.text('Invalid address'), findsOneWidget);
+ expect(h.enabled(tester), isFalse);
+ await h.enter(tester, alias);
+ expect(find.text('Invalid address'), findsNothing);
+ expect(h.enabled(tester), isTrue);
+ expect(h.lookups, isEmpty);
+ });
+
+ testWidgets('$layout an alias in the Wownero field stays invalid', (
+ tester,
+ ) async {
+ final h = _Harness(desktop, coin: _Wownero());
+ await h.mount(tester);
+ await h.setAmount(tester);
+ await h.enter(tester, alias);
+ expect(find.text('Invalid address'), findsOneWidget);
+ expect(h.enabled(tester), isFalse);
+ });
+
+ testWidgets('$layout a coin with its own tag looks up that tag', (
+ tester,
+ ) async {
+ final h = _Harness(desktop, coin: _Wownero('wow'));
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ expect(h.enabled(tester), isTrue);
+ await h.preview(tester);
+ expect(h.lookups.single.application, 'wow');
+ h.lookups.single.result.completeError(
+ const CsOpenAliasNoRecordException('', alias: 'alice.example.com'),
+ );
+ await h.finish(tester);
+ expect(
+ find.text(
+ 'No Wownero OpenAlias record was found for alice.example.com.',
+ ),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('$layout Preview checks the tag again before a lookup', (
+ tester,
+ ) async {
+ final coin = _Wownero('wow');
+ final h = _Harness(desktop, coin: coin);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ expect(h.enabled(tester), isTrue);
+ coin.application = null;
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, isEmpty);
+ });
+
+ testWidgets('$layout Preview resolves the alias and confirms the address', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ final lookup = h.lookups.single;
+ expect(lookup.alias, alias);
+ expect(lookup.application, 'xmr');
+ expect(lookup.isValidAddress(literal), isTrue);
+ expect(lookup.isValidAddress(alias), isFalse);
+ expect(find.text('Cancel'), findsOneWidget);
+ expect(h.wallet.prepared, isEmpty);
+
+ h.succeed();
+ await h.finish(tester);
+ expect(h.wallet.prepared.single.recipients!.single.address, literal);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ expect(h.confirmed(tester).openAlias, 'alice@example.com');
+ expect(find.text('OpenAlias'), findsOneWidget);
+ expect(find.text('alice@example.com'), findsOneWidget);
+ expect(find.text(literal), findsWidgets);
+ expect(h.text(tester), alias);
+ });
+
+ testWidgets('$layout a repeated Preview reuses the resolved alias', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+ expect(find.byType(ConfirmTransactionView), findsNothing);
+ expect(h.text(tester), alias);
+ expect(h.enabled(tester), isTrue);
+
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, hasLength(1));
+ expect(h.wallet.prepared, hasLength(2));
+ expect(h.wallet.prepared.last.recipients!.single.address, literal);
+ expect(h.wallet.prepared.last.openAlias, 'alice@example.com');
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ expect(h.confirmed(tester).openAlias, 'alice@example.com');
+ expect(find.text('OpenAlias'), findsOneWidget);
+ expect(find.text('alice@example.com'), findsOneWidget);
+ expect(find.text(literal), findsWidgets);
+ });
+
+ testWidgets('$layout an edited alias is looked up again', (tester) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+
+ await h.enter(tester, 'bob@example.com');
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ expect(h.lookups.last.alias, 'bob@example.com');
+ h.lookups.last.result.complete(
+ CsOpenAliasRecipient(
+ domain: 'bob.example.com',
+ address: 'second-recipient',
+ fields: const {'recipient_address': 'second-recipient'},
+ ttl: const Duration(minutes: 5),
+ ),
+ );
+ await h.finish(tester);
+ expect(
+ h.confirmed(tester).recipients!.single.address,
+ 'second-recipient',
+ );
+ expect(h.confirmed(tester).openAlias, 'bob@example.com');
+ expect(h.text(tester), 'bob@example.com');
+ });
+
+ testWidgets('$layout an expired resolution is looked up again', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+
+ h.now = h.now.add(const Duration(seconds: 61));
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ h.succeed();
+ await h.finish(tester);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ expect(h.confirmed(tester).openAlias, 'alice@example.com');
+ });
+
+ testWidgets('$layout a resolution within its TTL is reused', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+
+ h.now = h.now.add(const Duration(seconds: 59));
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, hasLength(1));
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ });
+
+ testWidgets('$layout clearing and retyping the alias looks it up again', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+
+ await h.enter(tester, '');
+ await h.enter(tester, alias);
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ h.succeed();
+ await h.finish(tester);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ });
+
+ testWidgets('$layout the lookup runs before the send-all confirmation', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester, balance);
+ await h.preview(tester);
+ expect(h.lookups, hasLength(1));
+ expect(find.text('Confirm send all'), findsNothing);
+ h.succeed();
+ await tester.pumpAndSettle();
+ expect(find.text('Confirm send all'), findsOneWidget);
+ expect(h.wallet.prepared, isEmpty);
+ expect(h.text(tester), alias);
+ });
+
+ testWidgets('$layout Cancel during the lookup cancels it', (tester) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ await tester.tap(find.text('Cancel'));
+ await h.finish(tester);
+ expect(h.lookups.single.cancels, 1);
+ expect(h.wallet.prepared, isEmpty);
+ expect(find.byType(ConfirmTransactionView), findsNothing);
+ expect(find.text('Generating transaction'), findsNothing);
+ expect(find.text(openAliasLookupFailedTitle), findsNothing);
+ expect(h.text(tester), alias);
+ expect(h.enabled(tester), isTrue);
+ });
+
+ testWidgets('$layout a lookup failure shows the OpenAlias error', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester, balance);
+ await h.preview(tester);
+ const error = CsOpenAliasNoRecordException(
+ 'no oa1:xmr record',
+ alias: 'alice.example.com',
+ );
+ h.lookups.single.result.completeError(error);
+ await h.finish(tester);
+ expect(find.text('OpenAlias lookup failed'), findsOneWidget);
+ expect(
+ find.text(
+ 'No Monero OpenAlias record was found for alice.example.com.',
+ ),
+ findsOneWidget,
+ );
+ expect(find.text('Generating transaction'), findsNothing);
+ expect(find.text('Confirm send all'), findsNothing);
+ expect(find.text('Transaction failed'), findsNothing);
+ expect(h.wallet.prepared, isEmpty);
+ await tester.tap(h.ok);
+ await tester.pumpAndSettle();
+ expect(find.byType(ConfirmTransactionView), findsNothing);
+ expect(h.text(tester), alias);
+ });
+
+ testWidgets('$layout Incognito shows the reason and sends nothing', (
+ tester,
+ ) async {
+ final h = _Harness(desktop, incognito: true);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ expect(h.enabled(tester), isTrue);
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(find.text('OpenAlias lookup failed'), findsOneWidget);
+ expect(find.text(h.service.unavailableReason()!), findsOneWidget);
+ expect(h.lookups, isEmpty);
+ expect(h.wallet.prepared, isEmpty);
+ });
+
+ for (final input in ['literal', 'contact']) {
+ testWidgets('$layout a $input address never starts a lookup', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(
+ tester,
+ autofill: input == 'contact'
+ ? SendViewAutoFillData(address: literal, contactLabel: alias)
+ : null,
+ );
+ if (input == 'literal') await h.enter(tester, literal);
+ await h.setAmount(tester);
+ expect(h.enabled(tester), isTrue);
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, isEmpty);
+ expect(h.wallet.prepared.single.recipients!.single.address, literal);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ expect(h.confirmed(tester).openAlias, isNull);
+ expect(find.text('OpenAlias'), findsNothing);
+ });
+ }
+
+ testWidgets('$layout Add recipient after a Preview carries the address', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is CustomTextButton && widget.text == 'Add recipient',
+ ),
+ );
+ await tester.pumpAndSettle();
+ final forms = find.byType(Recipient);
+ expect(forms, findsNWidgets(2));
+ expect(
+ find.descendant(of: forms.first, matching: find.text(literal)),
+ findsOneWidget,
+ );
+ expect(h.lookups, hasLength(1));
+ });
+
+ testWidgets(
+ '$layout Add recipient after an expired Preview keeps the alias',
+ (tester) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+ h.now = h.now.add(const Duration(seconds: 61));
+
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is CustomTextButton && widget.text == 'Add recipient',
+ ),
+ );
+ await tester.pumpAndSettle();
+ final forms = find.byType(Recipient);
+ expect(forms, findsNWidgets(2));
+ expect(
+ find.descendant(of: forms.first, matching: find.text(alias)),
+ findsOneWidget,
+ );
+ expect(
+ find.descendant(of: forms.first, matching: find.text(literal)),
+ findsNothing,
+ );
+ expect(h.lookups, hasLength(1));
+ },
+ );
+
+ testWidgets('$layout multiple recipients never start a lookup', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is CustomTextButton && widget.text == 'Add recipient',
+ ),
+ );
+ await tester.pumpAndSettle();
+ final forms = find.byType(Recipient);
+ expect(forms, findsNWidgets(2));
+ Finder inForms(Key key) =>
+ find.descendant(of: forms, matching: find.byKey(key));
+ final addresses = inForms(const Key('sendViewAddressFieldKey'));
+ await tester.enterText(addresses.first, literal);
+ await tester.enterText(addresses.last, 'second-recipient');
+ await tester.enterText(
+ inForms(const Key('amountInputFieldCryptoTextFieldKey')).last,
+ '2',
+ );
+ await tester.pumpAndSettle();
+ expect(h.enabled(tester), isTrue);
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, isEmpty);
+ expect(h.wallet.prepared.single.recipients!.map((e) => e.address), [
+ literal,
+ 'second-recipient',
+ ]);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ expect(h.confirmed(tester).openAlias, isNull);
+ });
+ }
+}
### test/services/openalias/cs_openalias_native_test.dart
@@ -0,0 +1,41 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:cs_openalias/cs_openalias.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:stackwallet/services/openalias/open_alias_service.dart';
+
+void main() {
+ test(
+ 'Flutter loads the facade native validator and queries through Tor',
+ () async {
+ // A local stand-in for Tor: the first connection proves the native
+ // validator started and sent a query; the lookup is then cancelled.
+ final proxy = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
+ addTearDown(proxy.close);
+ final connected = Completer<void>();
+ proxy.listen((socket) {
+ if (!connected.isCompleted) connected.complete();
+ socket.destroy();
+ });
+ final operation =
+ OpenAliasService(
+ externalCalls: () => true,
+ useTor: () => true,
+ supportsTor: () => true,
+ torProxy: () =>
+ (host: InternetAddress.loopbackIPv4, port: proxy.port),
+ ).lookup(
+ 'alice.example',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ );
+ await connected.future.timeout(const Duration(seconds: 10));
+ operation.cancel();
+ await expectLater(
+ operation.result,
+ throwsA(isA<CsOpenAliasCancelledException>()),
+ );
+ },
+ );
+}
### test/services/openalias/open_alias_live_test.dart
@@ -0,0 +1,61 @@
+import 'dart:io';
+
+import 'package:cs_openalias/cs_openalias.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:stackwallet/services/openalias/open_alias_service.dart';
+import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
+
+void main() {
+ final skip = Platform.environment['OPENALIAS_LIVE_TESTS'] != '1';
+ final service = OpenAliasService(
+ externalCalls: () => true,
+ useTor: () => false,
+ );
+ final validate = Monero(CryptoCurrencyNetwork.main).validateAddress;
+
+ test(
+ 'live signed alias uses native DNSSEC and Monero address validation',
+ () async {
+ final result = await service
+ .lookup(
+ 'donate.getmonero.org',
+ isValidAddress: validate,
+ application: 'xmr',
+ )
+ .result;
+ expect(result.domain, 'donate.getmonero.org');
+ expect(validate(result.address), isTrue);
+ },
+ skip: skip,
+ );
+
+ test('live nonexistent name is reported with the alias', () async {
+ await expectLater(
+ service
+ .lookup(
+ 'dan@cypherstack',
+ isValidAddress: validate,
+ application: 'xmr',
+ )
+ .result,
+ throwsA(
+ isA<CsOpenAliasNoRecordException>().having(
+ (e) => openAliasErrorMessage(e, 'Monero'),
+ 'openAliasErrorMessage',
+ 'No Monero OpenAlias record was found for dan.cypherstack.',
+ ),
+ ),
+ );
+ }, skip: skip);
+
+ for (final domain in ['openalias.org', 'dnssec-failed.org']) {
+ test('live unsigned or bogus DNS is rejected: $domain', () async {
+ await expectLater(
+ service
+ .lookup(domain, isValidAddress: validate, application: 'xmr')
+ .result,
+ throwsA(isA<CsOpenAliasException>()),
+ );
+ }, skip: skip);
+ }
+}
### test/services/openalias/open_alias_service_test.dart
@@ -0,0 +1,435 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:cs_openalias/cs_openalias.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:stackwallet/services/openalias/open_alias_service.dart';
+
+const incognito =
+ 'OpenAlias lookups are off in Incognito mode. To use OpenAlias, switch '
+ 'Stack Experience to Easy Crypto in Advanced settings.';
+const torUnavailable = 'Tor is unavailable. No lookup was sent.';
+
+class _Calls {
+ final aliases = <String>[];
+ final proxies = <CsOpenAliasProxy?>[];
+ final validators = <bool Function(String)>[];
+ final applications = <String>[];
+ final operations = <CsOpenAliasOperation<CsOpenAliasRecipient>>[];
+
+ CsOpenAliasOperation<CsOpenAliasRecipient> lookup(
+ String alias, {
+ required bool Function(String address) isValidAddress,
+ required String application,
+ required CsOpenAliasProxy? proxy,
+ }) {
+ aliases.add(alias);
+ proxies.add(proxy);
+ validators.add(isValidAddress);
+ applications.add(application);
+ final operation = CsOpenAliasOperation<CsOpenAliasRecipient>(
+ Future.error(CsOpenAliasNoRecordException('no record', alias: alias)),
+ () {},
+ );
+ operations.add(operation);
+ return operation;
+ }
+}
+
+OpenAliasService _service(
+ OpenAliasLookup lookup, {
+ bool external = true,
+ DateTime Function()? now,
+}) => OpenAliasService(
+ externalCalls: () => external,
+ useTor: () => false,
+ lookup: lookup,
+ now: now,
+);
+
+OpenAliasService _answering(Duration ttl, DateTime Function() now) => _service(
+ (alias, {required isValidAddress, required application, required proxy}) =>
+ CsOpenAliasOperation(
+ Future.value(
+ CsOpenAliasRecipient(
+ domain: 'alice.example.com',
+ address: 'resolved',
+ fields: const {'recipient_address': 'resolved'},
+ ttl: ttl,
+ ),
+ ),
+ () {},
+ ),
+ now: now,
+);
+
+final _start = DateTime.utc(2026, 10, 28, 12);
+
+OpenAliasResolution _resolve(OpenAliasService service) => service.resolve(
+ ' Alice@Example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ coinName: 'Monero',
+);
+
+void main() {
+ test('isOpenAlias accepts names and rejects addresses', () {
+ for (final input in ['Alice@Example.com', 'donate.getmonero.org.']) {
+ expect(isOpenAlias(input), isTrue, reason: input);
+ }
+ for (final input in [
+ '',
+ 'alice',
+ 'a@b@example.com',
+ 'alice example.com',
+ '4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FH',
+ ]) {
+ expect(isOpenAlias(input), isFalse, reason: input);
+ }
+ });
+
+ test('every lookup failure has a user message', () {
+ const alias = 'alice.example.com';
+ final messages = {
+ for (final e in <CsOpenAliasException>[
+ const CsOpenAliasInvalidAliasException('', alias: alias),
+ const CsOpenAliasNoRecordException('', alias: alias),
+ const CsOpenAliasInvalidRecordException('', alias: alias),
+ const CsOpenAliasDnssecException(
+ '',
+ alias: alias,
+ status: CsOpenAliasDnssecStatus.bogus,
+ ),
+ const CsOpenAliasNetworkException('', alias: alias),
+ const CsOpenAliasCancelledException('', alias: alias),
+ ])
+ openAliasErrorMessage(e, 'Monero'),
+ };
+ expect(messages, hasLength(6));
+ expect(
+ messages,
+ contains('No Monero OpenAlias record was found for alice.example.com.'),
+ );
+ });
+
+ test('Incognito mode sends nothing and names the setting', () {
+ final calls = _Calls();
+ final service = OpenAliasService(
+ externalCalls: () => false,
+ useTor: () => false,
+ lookup: calls.lookup,
+ );
+ expect(service.unavailableReason(), incognito);
+ expect(
+ () => service.lookup(
+ 'alice@example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ ),
+ throwsA(
+ isA<OpenAliasUnavailableException>().having(
+ (e) => e.message,
+ 'message',
+ incognito,
+ ),
+ ),
+ );
+ expect(calls.aliases, isEmpty);
+ });
+
+ test('Tor that is unsupported or not connected has no direct fallback', () {
+ final calls = _Calls();
+ for (final (supported, torProxy)
+ in <(bool, ({InternetAddress host, int port}) Function())>[
+ (false, () => (host: InternetAddress.loopbackIPv4, port: 9050)),
+ (true, () => throw Exception('Tor is not connected')),
+ ]) {
+ final service = OpenAliasService(
+ externalCalls: () => true,
+ useTor: () => true,
+ supportsTor: () => supported,
+ torProxy: torProxy,
+ lookup: calls.lookup,
+ );
+ expect(service.unavailableReason(), torUnavailable);
+ expect(
+ () => service.lookup(
+ 'alice@example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ ),
+ throwsA(
+ isA<OpenAliasUnavailableException>().having(
+ (e) => e.message,
+ 'message',
+ torUnavailable,
+ ),
+ ),
+ );
+ }
+ expect(calls.aliases, isEmpty);
+ });
+
+ test('the Tor proxy is passed only when Tor is on', () {
+ for (final tor in [true, false]) {
+ final calls = _Calls();
+ final service = OpenAliasService(
+ externalCalls: () => true,
+ useTor: () => tor,
+ supportsTor: () => true,
+ torProxy: () => (host: InternetAddress.loopbackIPv4, port: 9050),
+ lookup: calls.lookup,
+ );
+ expect(service.unavailableReason(), isNull);
+ service.lookup(
+ 'alice@example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ );
+ expect(calls.proxies.single?.address, tor ? '127.0.0.1' : null);
+ expect(calls.proxies.single?.port, tor ? 9050 : null);
+ }
+ });
+
+ test('the facade operation and arguments pass through unchanged', () {
+ final calls = _Calls();
+ final service = OpenAliasService(
+ externalCalls: () => true,
+ useTor: () => false,
+ lookup: calls.lookup,
+ );
+ bool validate(String address) => address == 'valid';
+ final operation = service.lookup(
+ ' Alice@Example.com',
+ isValidAddress: validate,
+ application: 'btc',
+ );
+ expect(calls.aliases.single, ' Alice@Example.com');
+ expect(calls.validators.single, same(validate));
+ expect(calls.applications.single, 'btc');
+ expect(operation, same(calls.operations.single));
+ });
+
+ test('the settings are read once for every lookup', () {
+ final calls = _Calls();
+ var reads = 0;
+ var external = true;
+ final service = OpenAliasService(
+ externalCalls: () {
+ reads++;
+ return external;
+ },
+ useTor: () => false,
+ lookup: calls.lookup,
+ );
+ service.lookup(
+ 'alice@example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ );
+ expect(reads, 1);
+ external = false;
+ expect(
+ () => service.lookup(
+ 'alice@example.com',
+ isValidAddress: (_) => true,
+ application: 'xmr',
+ ),
+ throwsA(isA<OpenAliasUnavailableException>()),
+ );
+ expect(reads, 2);
+ expect(calls.aliases, hasLength(1));
+ });
+
+ group('resolve', () {
+ test('returns the normalized alias and the address', () async {
+ final aliases = <String>[];
+ final service = _service((
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) {
+ aliases.add(alias);
+ return CsOpenAliasOperation(
+ Future.value(
+ CsOpenAliasRecipient(
+ domain: 'alice.example.com',
+ address: 'resolved',
+ fields: const {'recipient_address': 'resolved'},
+ ttl: const Duration(minutes: 5),
+ ),
+ ),
+ () {},
+ );
+ });
+ final outcome = await _resolve(service).outcome;
+ expect(aliases.single, ' Alice@Example.com');
+ expect(
+ outcome,
+ isA<OpenAliasResolved>()
+ .having((e) => e.alias, 'alias', 'alice@example.com')
+ .having((e) => e.address, 'address', 'resolved'),
+ );
+ });
+
+ test('the answer expires after its TTL', () async {
+ final outcome = await _resolve(
+ _answering(const Duration(seconds: 60), () => _start),
+ ).outcome;
+ expect(
+ outcome,
+ isA<OpenAliasResolved>().having(
+ (e) => e.expiresAt,
+ 'expiresAt',
+ _start.add(const Duration(seconds: 60)),
+ ),
+ );
+ });
+
+ test('the TTL counts from when the lookup started', () async {
+ var now = _start;
+ final completer = Completer<CsOpenAliasRecipient>();
+ final service = _service(
+ (
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) => CsOpenAliasOperation(completer.future, () {}),
+ now: () => now,
+ );
+ final resolution = _resolve(service);
+ now = _start.add(const Duration(seconds: 30));
+ completer.complete(
+ CsOpenAliasRecipient(
+ domain: 'alice.example.com',
+ address: 'resolved',
+ fields: const {'recipient_address': 'resolved'},
+ ttl: const Duration(seconds: 60),
+ ),
+ );
+ final outcome = await resolution.outcome as OpenAliasResolved;
+ expect(outcome.expiresAt, _start.add(const Duration(seconds: 60)));
+ });
+
+ test('a TTL over an hour is cut to an hour', () async {
+ final outcome = await _resolve(
+ _answering(const Duration(days: 2), () => _start),
+ ).outcome;
+ expect(
+ outcome,
+ isA<OpenAliasResolved>().having(
+ (e) => e.expiresAt,
+ 'expiresAt',
+ _start.add(const Duration(hours: 1)),
+ ),
+ );
+ });
+
+ test('a zero TTL is never current', () async {
+ final service = _answering(Duration.zero, () => _start);
+ final outcome = await _resolve(service).outcome as OpenAliasResolved;
+ expect(outcome.expiresAt, _start);
+ expect(service.isCurrent(outcome), isFalse);
+ });
+
+ test('isCurrent follows the clock', () async {
+ var now = _start;
+ final service = _answering(const Duration(seconds: 60), () => now);
+ final outcome = await _resolve(service).outcome as OpenAliasResolved;
+ expect(service.isCurrent(outcome), isTrue);
+ now = _start.add(const Duration(seconds: 59));
+ expect(service.isCurrent(outcome), isTrue);
+ now = _start.add(const Duration(seconds: 60));
+ expect(service.isCurrent(outcome), isFalse);
+ });
+
+ test('a lookup failure becomes its user message', () async {
+ final service = _service((
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) {
+ return CsOpenAliasOperation(
+ Future.error(
+ const CsOpenAliasNoRecordException('', alias: 'alice.example.com'),
+ ),
+ () {},
+ );
+ });
+ final outcome = await _resolve(service).outcome;
+ expect(
+ outcome,
+ isA<OpenAliasFailed>()
+ .having((e) => e.title, 'title', openAliasLookupFailedTitle)
+ .having(
+ (e) => e.message,
+ 'message',
+ 'No Monero OpenAlias record was found for alice.example.com.',
+ ),
+ );
+ });
+
+ test('an unavailable lookup shows the reason', () async {
+ final calls = _Calls();
+ final outcome = await _resolve(_service(calls.lookup, external: false))
+ .outcome;
+ expect(
+ outcome,
+ isA<OpenAliasFailed>().having((e) => e.message, 'message', incognito),
+ );
+ expect(calls.aliases, isEmpty);
+ });
+
+ test('any other error is logged, not shown', () async {
+ final service = _service((
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) {
+ throw ArgumentError('bad application');
+ });
+ final logged = <String>[];
+ final outcome = await runZoned(
+ () => _resolve(service).outcome,
+ zoneSpecification: ZoneSpecification(
+ print: (_, _, _, line) => logged.add(line),
+ ),
+ );
+ expect(
+ outcome,
+ isA<OpenAliasFailed>().having(
+ (e) => e.message,
+ 'message',
+ 'The OpenAlias lookup failed.',
+ ),
+ );
+ expect(logged.single, contains('bad application'));
+ });
+
+ test('cancel cancels the lookup', () async {
+ final result = Completer<CsOpenAliasRecipient>();
+ var cancels = 0;
+ final service = _service((
+ alias, {
+ required isValidAddress,
+ required application,
+ required proxy,
+ }) {
+ return CsOpenAliasOperation(result.future, () {
+ cancels++;
+ result.completeError(
+ CsOpenAliasCancelledException('cancelled', alias: alias),
+ );
+ });
+ });
+ final resolution = _resolve(service);
+ resolution.cancel();
+ expect(cancels, 1);
+ expect(await resolution.outcome, isA<OpenAliasCancelled>());
+ });
+ });
+}
### test/wallets/open_alias_application_test.dart
@@ -0,0 +1,25 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:cs_openalias/cs_openalias.dart' show isOpenAliasApplication;
+import 'package:stackwallet/app_config.dart';
+import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
+
+void main() {
+ test('every coin has no OpenAlias application or a valid one', () {
+ for (final coin in AppConfig.coins) {
+ final application = coin.openAliasApplication;
+ if (application != null) {
+ expect(
+ isOpenAliasApplication(application),
+ isTrue,
+ reason: coin.identifier,
+ );
+ }
+ }
+ if (AppConfig.coins.any((e) => e is Monero)) {
+ expect(
+ AppConfig.coins.map((e) => e.openAliasApplication),
+ contains('xmr'),
+ );
+ }
+ });
+}
### test/wallets/tx_data_test.dart
@@ -15,4 +15,17 @@ void main() {
false,
);
});
+
+ test('openAlias defaults to null and copies', () {
+ expect(TxData().openAlias, isNull);
+ expect(TxData().copyWith().openAlias, isNull);
+
+ final txData = TxData(openAlias: 'donate@getmonero.org');
+ expect(txData.openAlias, 'donate@getmonero.org');
+ expect(txData.copyWith(note: 'note').openAlias, 'donate@getmonero.org');
+ expect(
+ TxData().copyWith(openAlias: 'alice@example.com').openAlias,
+ 'alice@example.com',
+ );
+ });
}Why this scored 31/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.