Bundle wasm generated code into a JS application

Viewed 108

I am currently trying to implement my own plugin using an open-source project. The open-source project bundles all the files together and deploys it. However when I tried to call any of the wasm methods, it complains that they do not exist. I have tried everything from adding babel-2015 to the project, to making sure that all JS files are compiled accordingly but to no avail. I suspect that it has something to do with the way the wasm methods are imported since they use load asynchronously.
The wasm files look like this: 1.pkg

  • package.json
  • my_wasm_bg.d.ts
  • my_wasm.d.ts
  • my_wasm_bg.js
  • my_wasm.js
  • my_wasm_bg.wasm

They are generated using wasm-pack build in rust. And the open source project has the following files imported by creating a new file that looks like this:

import * as wasm from "signer";
export function sign(amount,
     nonce,
     sender_id,
     receiver_id,
     priv) {
   
     const no_sig_transfer = wasm.NoSigTransfer.new(
       amount,
       nonce,
       sender_id,
       receiver_id
     );
   
     return no_sig_transfer.sign(priv)
   }
   
   export function priv_to_pubkey(priv_key) {
     return wasm.get_public_key(priv_key)
   }

but when I call it from the bundled file I get an error:

wasm.priv_to_pubkey is not a function

or it complains about the import:

'import' and 'export' may appear only with 'sourceType: module' (3:0)

Any suggestions?

I've tried using different builds for the wasm package as they have node compatible, web, etc. but for some reason it seems the wasm files are not accesible.

0 Answers
Related