bip39
bip39 copied to clipboard
Bip39.ValidateMnemonic() always returns false in react
here is the code
const bip39 = require("bip39")
const hey = () =>{ const worddd = 'arrow wear carbon enact shadow expand sword custom tape ice display deliver' const yrsss = bip39.validateMnemonic(worddd) if (yrsss) { console.log(true) } }
hey()
Its returning 'true' in my case. Check your system and try again.
Returns false for me as well. Firefox 123.01 Chrome 122.0.6 MacOS Sonoma 14.3.1
vite react swc
In vite, i had to add this to get it to work:
npm i buffer
// vite.config.ts import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc";
// https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], optimizeDeps: { include: ["bip39"], }, resolve: { alias: { buffer: "buffer", // Ensures that imports/requires of 'buffer' are aliased to the 'buffer' package }, }, });
// src/main.tsx import "./index.css";
// eslint-disable-next-line unicorn/prefer-node-protocol, node/prefer-global/buffer import { Buffer } from "buffer"; import React from "react"; import ReactDOM from "react-dom/client";
import App from "./app"; window.Buffer = Buffer;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion ReactDOM.createRoot(document.querySelector("#root")!).render( <React.StrictMode> <App /> </React.StrictMode>, );