I’m trying to write a program to use the key derivation mechanism.
I found the cardano-serialization-lib (GitHub - Emurgo/cardano-serialization-lib: This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.), which already implements most functions for me, but struggle to get it working.
I installed the package via npm:
npm install cardano-serialization-lib
When trying to run this code:
import pkg from 'bip39';
const {mnemonicToEntropy } = pkg;
import CardanoWasm from 'cardano-serialization-lib';
const entropy = mnemonicToEntropy(
[ "test", "walk", "nut", "penalty", "hip", "pave", "soap", "entry", "language", "right", "filter", "choice" ].join(' ')
);
const rootKey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(
Buffer.from(entropy, 'hex'),
Buffer.from(''),
);
I get this error:
(node:20133) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received undefined
at fileURLToPath (internal/url.js:1352:11)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:780:21)
at Loader.resolve (internal/modules/esm/loader.js:97:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:46:40)
at link (internal/modules/esm/module_job.js:45:36) {
code: 'ERR_INVALID_ARG_TYPE'
}
I’m guessing the path to the Rust library is not properly linked, but I’m nor really sure.
Any help is appreciated. Thank you.