Skip to content

[crypto] WASM conditional import supportΒ #913

@tyllark

Description

@tyllark

Currently crypto/lib/src/sha512.dart is conditionally importing sha512_slowsinks.dart for web builds. dart.library.js is being used to differentiate between native and web builds, however that is the old interop library and the new library dart.library.js_interop is now the recommended way to conditionally import web implementations.

When building my package for WASM I'm getting the following error:

  StdErr:
  org-dartlang-app:///packages/crypto/src/sha512.dart:10:8: Error: Error when reading 'org-dartlang-app:///packages/crypto/src/sha512_fastsinks.dart': File not found
  import 'sha512_fastsinks.dart' if (dart.library.js) 'sha512_slowsinks.dart';
         ^
  org-dartlang-app:///packages/crypto/src/sha512.dart:46:31: Error: The method 'Sha384Sink' isn't defined for the type '_Sha384'.
   - '_Sha384' is from 'package:crypto/src/sha512.dart' ('org-dartlang-app:///packages/crypto/src/sha512.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Sha384Sink'.
        ByteConversionSink.from(Sha384Sink(sink));
                                ^^^^^^^^^^
  org-dartlang-app:///packages/crypto/src/sha512.dart:62:31: Error: The method 'Sha512Sink' isn't defined for the type '_Sha512'.
   - '_Sha512' is from 'package:crypto/src/sha512.dart' ('org-dartlang-app:///packages/crypto/src/sha512.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Sha512Sink'.
        ByteConversionSink.from(Sha512Sink(sink));
                                ^^^^^^^^^^
  org-dartlang-app:///packages/crypto/src/sha512.dart:78:31: Error: The method 'Sha512224Sink' isn't defined for the type '_Sha512224'.
   - '_Sha512224' is from 'package:crypto/src/sha512.dart' ('org-dartlang-app:///packages/crypto/src/sha512.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Sha512224Sink'.
        ByteConversionSink.from(Sha512224Sink(sink));
                                ^^^^^^^^^^^^^
  org-dartlang-app:///packages/crypto/src/sha512.dart:94:31: Error: The method 'Sha512256Sink' isn't defined for the type '_Sha512256'.
   - '_Sha512256' is from 'package:crypto/src/sha512.dart' ('org-dartlang-app:///packages/crypto/src/sha512.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Sha512256Sink'.
        ByteConversionSink.from(Sha512256Sink(sink));

When I change the conditional import locally to use dart.library.js_interop I'm able to build successfully. Please let me know if you need any additional info.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions