Closed 0x009922 closed 3 years ago
Also this PR closes https://github.com/hyperledger/iroha-javascript/issues/67
This PR now includes preparations to publishment of its packages. All CI/CD pipeline should look like this:
pnpm i
pnpm type-check
pnpm test
pnpm build
pnpm publish-all
I've added an installation notes to the READMEs of @iroha2/client
, @iroha2/crypto
and @iroha2/data-model
.
In short, the end user should just configure package manager to fetch @iroha2
-scoped packages from nexus:
# .npmrc
@iroha2:registry=https://nexus.iroha.tech/repository/npm-group/
iroha_crypto
crate.Unresolved problems
@iroha/crypto
is only ESM-compatibleUsage of
@iroha/crypto
is still not very clear and requires a native ES modules environment. In web it works fine withvite
, and also in node withesbuild-register
. Other cases are not very well researched.iroha_crypto_core
crateIt is a copy of
iroha_crypto
crate from hyperledger/iroha (iroha2-dev) repo, refactored to be no-std compatible. The better way to make it I see here is to refactor the main crate to be no-std compatible and use it directly iniroha_crypto_wasm
crate in this repo.Don't forget to
free()
crypto structures!They will never be garbage collected manually, so if you don't want memory leaks, you have to
free()
every created structures manually when they have to be dropped.Inefficiency of exposed API by
wasm_bindgen
There is a lot of data cloning that looks like unnecessary, but I can't determine and don't know how to design it in better way. Maybe we will see it after some real-world usage.
Also,
wasm_bindgen
has some undocumented behavior (or I haven't found any documentation) - Rust's ownership rules works on incoming exposed structures! For example:This will be compilted to JS-wrappers like this:
And when you use it like this:
So, OK, ownership rules affect generated bindings with
wasm_bindgen
, but it is completely unclear from the JS side! There is no any borrow-checker in JS that will fail compilation in case when ownership rules have been violated. So I removed all cases when incoming values are being moved and I always borrow them and copy when it is necessary.How to solve it? Idk, maybe we have to completely redesign the WASM crate to exclude any possibility to use it improperly. We need more usage examples.