bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
237 stars 122 forks source link

Uint64List not supported in web mode #178

Closed redDwarf03 closed 1 year ago

redDwarf03 commented 1 year ago

Hello

i have this issue in web mode :

"Error: Unsupported operation: Uint64List not supported on the web.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/typed_data_patch.dart 115:5       new
packages/pointycastle/block/modes/gcm.dart 81:36                              [_computeInitialCounter]
packages/pointycastle/block/modes/gcm.dart 61:16                              prepare
packages/pointycastle/src/impl/base_aead_block_cipher.dart 217:5              reset
packages/pointycastle/block/modes/gcm.dart 47:11                              reset
packages/pointycastle/src/impl/base_aead_block_cipher.dart 117:5              init
packages/pointycastle/block/modes/gcm.dart 40:11                              init
packages/crypto_keys/src/symmetric_operator.dart 71:16                        encrypt
packages/archethic_lib_dart/src/utils/crypto.dart 673:16                      aesAuthEncrypt
packages/archethic_lib_dart/src/utils/crypto.dart 400:11                      ecEncrypt
packages/archethic_lib_dart/src/services/api_service.dart 483:46              newKeychainTransaction
packages/aewallet/util/keychain_util.dart 98:54                               createKeyChain
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
packages/aewallet/util/keychain_util.dart 70:30                               createKeyChain
packages/aewallet/ui/views/intro/intro_backup_confirm.dart 547:28             createKeychain
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1653:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
"

any idea ? Thx

redDwarf03 commented 1 year ago
[✓] Flutter (Channel stable, 3.3.8, on macOS 13.0.1 22A400 darwin-arm, locale fr-FR)
    • Flutter version 3.3.8 on channel stable at /Users/SSe/SSe/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (il y a 12 jours), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/SSe/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.12+0-b1504.28-7817840)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • iPhone SE (3rd generation) (mobile)  • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)                     • macos                                • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available
mwcw commented 1 year ago

JS has no native intger support only IEEE-754 floating point numbers and the dart team do not provide an analog for that during transpilation process.

In this case IEEE-754 can only represent a subset of unsigned 64 bit integers.

richardheap commented 1 year ago

There seems to be a simple fix. Change this line var length = Uint8List.view((Uint64List(2)..[0] = iv.length * 8).buffer);

to var length = Uint8List.view((Uint32List(4)..[0] = iv.length * 8).buffer);

Which would seem to be equivalent for all practical values of IV length.

redDwarf03 commented 1 year ago

https://stackoverflow.com/questions/74523047/uint64list-not-supported-on-flutter-web/74526125#74526125

redDwarf03 commented 1 year ago

@mwcw, hello. With @richardheap and stackoverflow answers, is it possible to reopen this issue please ?

richardheap commented 1 year ago

@redDwarf03 Please make the changes yourself, test and submit a PR.

redDwarf03 commented 1 year ago

@richardheap . A PR is available.