ardriveapp / arweave-dart

Dart package for interfacing with the Arweave network.
Apache License 2.0
7 stars 3 forks source link

Generating wallet on web hangs #30

Open elliotsayes opened 2 years ago

elliotsayes commented 2 years ago

Calling Wallet.generate() when compiled for web seems to never complete.

To reproduce:

  1. create test/wallets_test.html:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Wallets Test</title>
    <script src="js/avsc.min.js"></script>
    <script src="js/tagparser.js"></script>
    <link rel="x-dart-test" href="wallets_test.dart" />
    <script defer src="packages/test/dart.js"></script>
    </head>
    <body>
    // ...
    </body>
    </html>
  2. run dart test test/wallets_test.dart -N "generate wallet" --platform chrome
  3. observe output never completes: 01:17 +0: wallets: generate wallet
elliotsayes commented 2 years ago

Root issue appears to be from pointycastle library final pair = keyGen.generateKeyPair(); https://github.com/bcgit/pc-dart/issues/113

elliotsayes commented 2 years ago

Workaround: use fast_rsa package to generate the keys, then load using Wallet.fromJwk(). Becausefast_rsa is a flutter package (for web it uses wasm under the hood) it cannot be used in arweave-dart directly. Still it takes ~30 seconds on average, much slower than ~1s for native dart, but comparable to arweave.app

Example usage:

final wallet = await RSA.generate(keyLength)
    .then((kp) => RSA.convertPrivateKeyToJWK(kp.privateKey))
    .then((jwk) => Wallet.fromJwk(jwk));
karlprieb commented 2 years ago

Hi @elliotsayes thank you for your report!

We did some tests and conclude the same as you. We tested with a simple Flutter Web project and we could generate a wallet, but it took more than 10 minutes having frozen UI. We also tested fast_rsa and it works perfectly :)

Our approach to this issue will be to create an interface to abstract the wallet generation. We want to keep using pointycastle for pure Dart projects and implement fast_rsa for Flutter projects.

As we don't have this feature on ArDrive Web we will not work on this fix for now, but it's on our roadmap and when the time comes we will release this implementation.

elliotsayes commented 2 years ago

Hi @karlprieb that makes sense to me. What I don't understand though is why dart does not support plugins (i.e. js on web) without flutter SDK... seems like they want to tie you to flutter if you are using dart libraries