bip39 icon indicating copy to clipboard operation
bip39 copied to clipboard

Bip39.ValidateMnemonic() always returns false in react

Open onyxaudit opened this issue 11 months ago • 3 comments

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()

onyxaudit avatar Mar 03 '24 09:03 onyxaudit

Its returning 'true' in my case. Check your system and try again.

zaidmstrr avatar Apr 24 '24 15:04 zaidmstrr

Returns false for me as well. Firefox 123.01 Chrome 122.0.6 MacOS Sonoma 14.3.1

vite react swc

GildedPleb avatar May 01 '24 18:05 GildedPleb

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>, );

GildedPleb avatar May 01 '24 18:05 GildedPleb