bitcoinjs / bip39

JavaScript implementation of Bitcoin BIP39: Mnemonic code for generating deterministic keys
ISC License
1.07k stars 431 forks source link

Bip39.ValidateMnemonic() always returns false in react #193

Open onyxaudit opened 3 months ago

onyxaudit commented 3 months ago

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

zaidmstrr commented 2 months ago

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

GildedPleb commented 1 month ago

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

vite react swc

GildedPleb commented 1 month ago

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(

, );