monero-ts: Failed to parse URL

Error [TypeError]: Failed to parse URL from /home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/dist/monero_wallet_keys.wasm at LibraryUtils.deserializeError (/home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js:253:106) at LibraryUtils.invokeWorker (/home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js:242:26) at async MoneroWalletKeysProxy.createWallet (/home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/src/main/ts/wallet/MoneroWalletKeys.js:381:5) at async MoneroWalletKeys.createWallet (/home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/src/main/ts/wallet/MoneroWalletKeys.js:63:25) Worker error: TypeError: Failed to parse URL from /home/xxx/Documents/GitHub/xxx-router/node_modules/monero-ts/dist/dist/monero_wallet_keys.wasm at Object.fetch (node:internal/deps/undici/undici:11576:11)

import moneroTs from "monero-ts";

    moneroTs.createWalletKeys({networkType: moneroTs.MoneroNetworkType.MAINNET, language: "English"}).then( async (result)=>{
      const address=await result.getAddress(0,0);
      const seed=await result.getSeed();
      console.log(seed)
      const duplicateWallet=await moneroTs.createWalletKeys({networkType:moneroTs.MoneroNetworkType.MAINNET,seed:seed});
      const address2=await result.getAddress(0,0);
      console.log(address)
      console.log(address2)
});

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

The issue is triggered when evaluating if condition in function InstantiateAsync() in monero_wallet_keys.js:

if (!wasmBinary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(wasmBinaryFile) && !isFileURI(wasmBinaryFile) && typeof fetch == "function") {

The trigger is the availability of functioin WebAssembly.instantiateStreaming().

Prior node.js 18.1.0 WebAssembly.instantiateStreaming() was not available, hence if condition resolves to false. Also for later node.js releases, flag --no-experimental-fetch can be used, which makes WebAssembly.instantiateStreaming() unavailable, hence the fault is not triggered.

So:

  • to avoid the error: use node.js flag --no-experimental-fetch (or node.js < 18.1.0)
  • to reporoduce the error: use node.js > 18.1.0 and without flag --no-experimental-fetch

When WebAssembly.instantiateStreaming() is not available, the error is not triggered, but also isFileURI(wasmBinaryFile) is not evaluated. In case WebAssembly.instantiateStreaming() is available, isFileURI(wasmBinaryFile) returns false since wasmBinaryFile is not prefixed with file://.

Hope this analysis helps and can lead to a solution. In the meantime use the flag --no-experimental-fetch, which will avoid the issue.