Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM function fails to accept arguments, sometimes #154

Open
0x009922 opened this issue Feb 17, 2025 · 1 comment
Open

WASM function fails to accept arguments, sometimes #154

0x009922 opened this issue Feb 17, 2025 · 1 comment

Comments

@0x009922
Copy link

Steps to reproduce

  1. Open crypto-wasm dir in hyperledger-iroha/iroha-javascript repo
  2. Bump wasm-bindgen to 0.2.100 in Cargo.toml (as required by @deno/wasmbuild)
  3. Run deno run -A jsr:@deno/wasmbuild, it outputs the lib< directory
  4. Create and run the following test.ts file:
import { KeyPair } from './lib/iroha_crypto_wasm.js'

// 1.
// console.log(KeyPair.random().public_key().to_multihash_hex())

// 2.
console.log(KeyPair.derive_from_seed({ t: 'hex', c: 'beef' }).public_key().to_multihash_hex())

// 3.
console.log(KeyPair.derive_from_seed({ t: 'hex', c: 'beef' }, 'ed25519').public_key().to_multihash_hex())

Expected

ed01201F69AD5DEF05D7EEF87E257D6184E7B1BBE178FC8B4CA1F1422A5F6225A7A5DA
ed01201F69AD5DEF05D7EEF87E257D6184E7B1BBE178FC8B4CA1F1422A5F6225A7A5DA

Actual

  • When running case 2. alone: Error: invalid type: JsValue(Object({"t":"hex","c":"ab"})), expected unit
  • When running case 3. alone: Error: invalid type: string "ed25519", expected unit
  • When uncommenting case 1.: all three cases work (?)

Worth mentioning: I see that @deno/wasmbuild uses --target bundler, so I tried to build the package with wasm-pack build --target bundler and check if I observe the same issues with its output. It works without issues, however.

@0x009922
Copy link
Author

Found a difference between the output of @deno/wasmbuild build and wasm-pack build --target bundler - the latter one adds this:

wasm.__wbindgen_start();

So, it started to work after modifying the output of @deno/wasmbuild into this:

import * as wasm from "./iroha_crypto_bg.wasm";
export * from "./iroha_crypto_bg.js";
import { __wbg_set_wasm } from "./iroha_crypto_bg.js";
__wbg_set_wasm(wasm);
+ wasm.__wbindgen_start();

I guess @deno/wasmbuild should output this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant