crossmintRecoveryMethodMaps function

List<CrossmintJsonMap> crossmintRecoveryMethodMaps(
  1. CrossmintWallet wallet
)

Every recovery method on the wallet, newest contract first.

Reads config.recoveryMethods and falls back to wrapping the deprecated config.adminSigner for responses that predate the list or send the list empty.

On an EVM wallet, the list has only the methods on the chain of the wallet. The admin signer is first when it is on that chain. If it is not, the first method on that chain is first.

Implementation

List<CrossmintJsonMap> crossmintRecoveryMethodMaps(CrossmintWallet wallet) {
  final Object? config = wallet.raw['config'];
  if (config is! Map<Object?, Object?>) {
    return const <CrossmintJsonMap>[];
  }
  final Object? adminSigner = config['adminSigner'];
  final CrossmintJsonMap? admin = adminSigner is Map<Object?, Object?>
      ? crossmintNormalizeMap(adminSigner)
      : null;
  final Object? methods = config['recoveryMethods'];
  if (methods is List<Object?> && methods.isNotEmpty) {
    final List<CrossmintJsonMap> all = methods
        .whereType<Map<Object?, Object?>>()
        .map(crossmintNormalizeMap)
        .toList(growable: false);
    final String? evmChain = _evmChainOf(wallet);
    if (evmChain == null) {
      return all;
    }
    final List<CrossmintJsonMap> onChain = all
        .where((CrossmintJsonMap method) => _isOnChain(method, evmChain))
        .toList();
    if (onChain.isEmpty) {
      return admin == null
          ? const <CrossmintJsonMap>[]
          : <CrossmintJsonMap>[admin];
    }
    final String? adminLocator = admin == null ? null : _locatorOf(admin);
    final int adminIndex = adminLocator == null
        ? -1
        : onChain.indexWhere(
            (CrossmintJsonMap method) => _locatorOf(method) == adminLocator,
          );
    if (adminIndex > 0) {
      onChain.insert(0, onChain.removeAt(adminIndex));
    }
    return List<CrossmintJsonMap>.unmodifiable(onChain);
  }
  if (admin != null) {
    return <CrossmintJsonMap>[admin];
  }
  return const <CrossmintJsonMap>[];
}