At this point in time deploying Rust and WebAssembly to the web or other locations unfortunately isn't a trivial task to do.
wasm-pack docs about deployment
Before this I was sure that web target works fine both in web and nodejs environment, and it was! But unfortunately not in all cases and with some reservations and pitfalls. It is ok, so why not just expose different entrypoints in the same library? Because such approach produces huge problems for the libraries that would depend on this one and be target-agnostic, e.g. @iroha2/client pkg.
The solution
In this PR library contains main "types" entrypoint in /types and target-specific ones in sub-directories. It has the main type - IrohaCryptoInterface, and each target-specific implementation exports the same crypto object that is compatible with this type (it is included into type-check of the monorepo as test). And with this type it is possible to write libraries that depends on it and injects a particular implementation in runtime.
What not to check
wasm-pack outputs at packages/iroha-crypto/(web|node|bundler) dirs. Btw there are index.js and index.d.ts files generated separately from it but also automatically.
The problem
Before this I was sure that
web
target works fine both in web and nodejs environment, and it was! But unfortunately not in all cases and with some reservations and pitfalls. It is ok, so why not just expose different entrypoints in the same library? Because such approach produces huge problems for the libraries that would depend on this one and be target-agnostic, e.g.@iroha2/client
pkg.The solution
In this PR library contains main "types" entrypoint in
/types
and target-specific ones in sub-directories. It has the main type -IrohaCryptoInterface
, and each target-specific implementation exports the samecrypto
object that is compatible with this type (it is included into type-check of the monorepo as test). And with this type it is possible to write libraries that depends on it and injects a particular implementation in runtime.What not to check
wasm-pack
outputs atpackages/iroha-crypto/(web|node|bundler)
dirs. Btw there areindex.js
andindex.d.ts
files generated separately from it but also automatically.