merigo-labs / solana-wallet-adapter

MIT License
6 stars 2 forks source link

Sign Message working for phantom wallet but not working for solflare wallet #6

Closed Rohitbagul003 closed 1 year ago

Rohitbagul003 commented 1 year ago

is the signMessage Function and error log:-

void _signMessages() async {
    const String description = "Sign Messages";
    try {
      debugPrint("Create $description... account base58 ${solanaWalletAdapter?.connectedAccount?.addressBase58}");
      final List<String> messages = List.generate(1, (index) => base64Encode('Sign message $index'.codeUnits));
      debugPrint("description -> $description...");
      SignMessagesResult? result = await solanaWalletAdapter?.signMessages(
        messages: messages,
        addresses: [base58ToBase64(solanaWalletAdapter!.connectedAccount!.addressBase58)],
      );

      debugPrint("Signed Messages ${result?.signedPayloads.join('\n')}");
    } catch (error, stack) {
      print('$description Error: $error');
      print('$description Stack: $stack');
      debugPrint("catch error in sign ${error.toString()}, $stack");
    }
  }
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_180225248219124321319420724722714880108116204)
E/flutter (25465): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #2      NameService.getTwitterHandleForPublicKey (package:solflare/blockchain/solana/sdk/action/name_service/name_service.dart:28)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #3      PortfolioCubit._getTwitterHandle (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:238)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #4      Future.wait.<anonymous closure> (dart:async/future.dart:522)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #5      PortfolioCubit._getPortfolioData (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:151)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #6      PortfolioCubit.setTokenAccountCubit.<anonymous closure> (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:138)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): 
E/flutter (25465): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_180225248219124321319420724722714880108116204)
E/flutter (25465): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #2      SolanaSimulation.getIsTransactionRequest (package:solflare/blockchain/solana/sdk/action/simulation/solana_simulation.dart:45)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #3      DeepLinkNavigationRouter.handleSagaDeepLink (package:solflare/deeplink/navigation_router/deep_link_navigation_router.dart:123)
E/flutter (25465): <asynchronous suspension>
E/flutter (25465): #4      MainCubit._handleMobileWalletAdapterIntent.<anonymous closure> (package:solflare/shared/bloc/main/main_cubit.dart:190)
E/flutter (25465): <asynchronous suspension>
Rohitbagul003 commented 1 year ago

Closing this as in sign function I needed to change base64Encode to base64UrlEncode.

Updated function:-

void _signMessages() async {
    const String description = "Sign Messages";
    try {
      debugPrint("Create $description... account base58 ${solanaWalletAdapter?.connectedAccount?.addressBase58}");
      final List<String> messages = List.generate(1, (index) => base64UrlEncode('Sign message $index'.codeUnits));
      debugPrint("description -> $description...");
      SignMessagesResult? result = await solanaWalletAdapter?.signMessages(
        messages: messages,
        addresses: [base58ToBase64(solanaWalletAdapter!.connectedAccount!.addressBase58)],
      );

      debugPrint("Signed Messages ${result?.signedPayloads.join('\n')}");
    } catch (error, stack) {
      print('$description Error: $error');
      print('$description Stack: $stack');
      debugPrint("catch error in sign ${error.toString()}, $stack");
    }
  }