From 935675f7e8a33f87459d7fe817d260495948075b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 9 Oct 2023 15:34:08 -0400 Subject: [PATCH] fix: translate seed phrase length into bits --- .../lume/LumeIdentity/components.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/lume/LumeIdentity/components.tsx b/src/components/lume/LumeIdentity/components.tsx index 7e55f38..b0b0318 100644 --- a/src/components/lume/LumeIdentity/components.tsx +++ b/src/components/lume/LumeIdentity/components.tsx @@ -20,6 +20,23 @@ async function seedToKey(seed: string) { return bip39.mnemonicToSeed(seed); } +function getStrength(wordCount: number) { + switch (wordCount) { + case 12: + return 128; + case 15: + return 160; + case 18: + return 192; + case 21: + return 224; + case 24: + return 256; + default: + throw new Error("Invalid word count"); + } +} + // Extracted components const SubmitButtonComponent = () => { const { setVisibleComponent } = useSwitchableComponent(); @@ -101,7 +118,9 @@ const SeedPhraseGenerationComponent = ({ phraseLength = 12 }) => { const { signIn } = useLumeIndentity(); const phrases = useMemo(() => { - return bip39.generateMnemonic(wordlist, phraseLength).split(" "); + return bip39 + .generateMnemonic(wordlist, getStrength(phraseLength)) + .split(" "); }, [phraseLength]); const key = useMemo(() => {