weishirongzhen / flutter_trust_wallet_core

MIT License
89 stars 32 forks source link

Exception: [mnemonic is invalid] #25

Open nycm1989 opened 3 years ago

nycm1989 commented 3 years ago

wallet = HDWallet.createWithMnemonic("horror select baby exile convince sunset outside vehicle write decade powder energy")

throw Exception(["mnemonic is invalid"]);

The following _Exception was thrown while handling a gesture:
Exception: [mnemonic is invalid]

When the exception was thrown, this was the stack
#0      TWHDWalletImpl.createWithMnemonic
package:trust_test/…/dart_impl/tw_hd_wallet_impl.dart:13
#1      new HDWallet.createWithMnemonic
package:trust_test/…/core/hd_wallet.dart:16
#2      _TestInterfacePageState.build.<anonymous closure>
package:trust_test/components/testInterface.dart:54
#3      _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:989
#4      GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:182
...
weishirongzhen commented 3 years ago

what device you are tested on? and please run flutter doctor and paste log.

nycm1989 commented 3 years ago

what device you are tested on? and please run flutter doctor and paste log.

testet en pixel 5 api 30 from android studio emulator and samsung A21

[✓] Flutter (Channel stable, 2.2.1, on Linux, locale en_US.UTF-8)
    • Flutter version 2.2.1 at /home/neil/snap/flutter/common/flutter
    • Framework revision 02c026b03c (4 months ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /home/neil/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /snap/android-studio/114/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] Android Studio
    • Android Studio at /snap/android-studio/current/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /snap/android-studio/current/android-studio
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.60.0)
    • VS Code at /usr/share/code
    • Flutter extension version 3.26.0

[✓] Connected device (2 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 93.0.4577.63

when i make test in the emulator i had to delete '!' in tw_hd_wallet_impl.dart if (!TWMnemonicImpl.isValid(mnemonic)) throw Exception(["mnemonic is invalid"]); in my samsung A21 dont but the app is crashing in the two cases

I tried to import the proyect in the same level of the proyect folder and declarate it in pupspect like this

flutter_trust_wallet_core:
  path: ../flutter_trust_wallet_core

and work fine, but when i tried to create an address the app crash and trow a 'NULL POINT EXEPTION' from libTrustWalletCore.so

weishirongzhen commented 3 years ago

Add

    init {
        System.loadLibrary("TrustWalletCore")
    }

in you android project MainActivity.kt file

MainActivity.kt file will looks like

class MainActivity: FlutterActivity() {
    init {
        System.loadLibrary("TrustWalletCore")
    }
}
nycm1989 commented 3 years ago

Add

    init {
        System.loadLibrary("TrustWalletCore")
    }

in you android project MainActivity.kt file

MainActivity.kt file will looks like

class MainActivity: FlutterActivity() {
    init {
        System.loadLibrary("TrustWalletCore")
    }
}

Yeah, i did all and the plugin can create a random seeds but cant create a new wallet from the same seeds in HDWallet.createWithMnemonic, always trows a invalid exeption

nycm1989 commented 3 years ago

Add

    init {
        System.loadLibrary("TrustWalletCore")
    }

in you android project MainActivity.kt file

MainActivity.kt file will looks like

class MainActivity: FlutterActivity() {
    init {
        System.loadLibrary("TrustWalletCore")
    }
}

Using isValidWord method can get TRUE in the words from mnemonic but not in the complethe phrase, i use bip39 plugin to compare

FlutterTrustWalletCore.init();
String mnemonic = "horror select baby exile convince sunset outside vehicle write decade powder energy";
List<String> split = mnemonic.split(' ');

for (var element in split) {
  print((split.indexOf(element) + 1).toString() + ' ' + element + ' -> ' + Mnemonic.isValidWord(element).toString());
}

print('[TRUST PLUGIN] mnemonic -> ' + Mnemonic.isValid(mnemonic).toString());
print('[BIP39 PLUGIN] mnemonic -> ' + bip39.validateMnemonic(mnemonic).toString());

the console show this

1 horror -> true
2 select -> true
3 baby -> true
4 exile -> true
5 convince -> true
6 sunset -> true
7 outside -> true
8 vehicle -> true
9 write -> true
10 decade -> true
11 powder -> true
12 energy -> true
[TRUST PLUGIN] mnemonic -> false
[BIP39 PLUGIN] mnemonic -> true
phamducmanh1989 commented 2 years ago

change static int TWMnemonicIsValid to static bool TWMnemonicIsValid and refactor all references of it

weishirongzhen commented 2 years ago

try again with new version of trustwallet core native lib