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

Bip32PrivateKey.from_bip39_entropy() function failing to execute. #714

Open
B35000 opened this issue Jan 31, 2025 · 8 comments
Open

Bip32PrivateKey.from_bip39_entropy() function failing to execute. #714

B35000 opened this issue Jan 31, 2025 · 8 comments

Comments

@B35000
Copy link

B35000 commented Jan 31, 2025

Im trying to use the library to generate a valid cardano wallet address from a valid Bip39 mnemonic in my CRA project but the very first function is failing to execute for some reason. My import statements look like this:

import { mnemonicToSeedSync, mnemonicToSeed, mnemonicToEntropy, entropyToMnemonic } from 'bip39';
import { Bip32PrivateKey } from "@emurgo/cardano-serialization-lib-browser";

and the code im using:

generate_cardano_wallet = async (mnemonic) => {
  const entropy = mnemonicToEntropy(mnemonic);
  const rootKey = Bip32PrivateKey.from_bip39_entropy( //<------------this call is failing
    Buffer.from(entropy, "hex"), 
    new Uint8Array(3) // for testing
  );
  const accountKey = rootKey.derive(1852).derive(1815).derive(0);
  const publicKey = accountKey.to_public();
  const address = publicKey.to_bech32()
  console.log(address)
}

the expected output was to log an address in the console, but instead im receiving this error:

malloc is not a function
TypeError: malloc is not a function
    at passArray8ToWasm0 (http://localhost:3000/E5UI/static/js/bundle.js:109438:15)
    at Bip32PrivateKey.from_bip39_entropy (http://localhost:3000/E5UI/static/js/bundle.js:112981:18)
    at App.generate_cardano_wallet (http://localhost:3000/E5UI/main.7ea1aca2f9067558cb18.hot-update.js:2100:111)
    at App.make_api_call20 (http://localhost:3000/E5UI/main.7ea1aca2f9067558cb18.hot-update.js:2076:34)
    at App.componentDidMount (http://localhost:3000/E5UI/main.7ea1aca2f9067558cb18.hot-update.js:2275:10)
    at commitLayoutEffectOnFiber (http://localhost:3000/E5UI/static/js/bundle.js:533264:34)
    at commitLayoutMountEffects_complete (http://localhost:3000/E5UI/static/js/bundle.js:534431:13)
    at commitLayoutEffects_begin (http://localhost:3000/E5UI/static/js/bundle.js:534420:11)
    at commitLayoutEffects (http://localhost:3000/E5UI/static/js/bundle.js:534366:7)
    at commitRootImpl (http://localhost:3000/E5UI/static/js/bundle.js:536275:9)

The library version in my package.json: "@emurgo/cardano-serialization-lib-browser": "^12.1.1" NPM version: 9.6.7, Node version: 18.17.1

@gitmachtl
Copy link

hey @B35000 ,

i do it like:

var entropy = Buffer.from(bip39.mnemonicToEntropy(mnemonics),'hex')
var rootKey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(entropy,''); //generate a ed25519e key from the provided entropy(mnemonics)

@B35000
Copy link
Author

B35000 commented Jan 31, 2025

From what im seeing, were looking at the exact same code except for the import statement. In your example you're using emurgo/cardano-serialization-lib-nodejs which is for node.js while im using @emurgo/cardano-serialization-lib-browser which is for the browser environment.

Thanks for the response.

@gitmachtl
Copy link

gitmachtl commented Jan 31, 2025

why do you need

new Uint8Array(3) // for testing

?

for the password, have your tried it without a second parameter?

@B35000
Copy link
Author

B35000 commented Jan 31, 2025

The call requires two parameters, the entropy and a uint8Array value as the password. I just pass an empty uint8Array for testing. Ive tried passing an empty string instead but still get the same error.

@gitmachtl
Copy link

gitmachtl commented Jan 31, 2025

I just pass a '' as the second parameter. I am not aware of any wallet that uses this password. I only know it from HW-Wallets as an additional Passphrase in addition to the Mnemonic. Have you tried that?

EDIT: ah just reading that you have tried it already

@lisicky
Copy link
Contributor

lisicky commented Jan 31, 2025

Hi @B35000 could you publish on GH isolated example to reproduce issue on our side ?
@gitmachtl thanks for your help !

@B35000
Copy link
Author

B35000 commented Feb 1, 2025

Ive created a basic CRA project that illustrated the issue here
its suppose to autogenerate and display an address for you every time you refresh the browser, but the function in question is failing to execute.

@lisicky
Copy link
Contributor

lisicky commented Feb 3, 2025

@B35000 the problem here is that react-scripts doesn’t support wasm files. But in your case you can use craco
Here is example:

#installation 
npm install @craco/craco --save

Package.json changes:

  "scripts": {
    "start": "craco start”,
    "build": "craco build”,
    "test": "craco test”,
    "eject": "react-scripts eject”
  },

craco.config.js

module.exports = {
  webpack: {
    configure: (webpackConfig) => {
      webpackConfig.experiments = {
        ...webpackConfig.experiments,
        asyncWebAssembly: true,
      };

      webpackConfig.module.rules.push({
        test: /\.wasm$/,
        type: "webassembly/async",
      });

      return webpackConfig;
    },
  },
};

Aslo if you are gonna to deploy your web app somewhere make sure that your web server is configured to provide wasm files or your bundler inlines it into web app bundle.

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

3 participants