hashgreen / hoogii-wallet

Hoogii is a crypto wallet extension for Chia Network
https://hoogii.app
Apache License 2.0
21 stars 7 forks source link

Repeated phrases in mnemonics might be dropped together #103

Closed stmharry closed 1 year ago

stmharry commented 1 year ago

As implemented here: https://github.com/hashgreen/hoogii-wallet/blob/99f5d7b67df296eb8f2137200fe7d57d1c32cf77/src/tabs/pages/mnemonic/createMnemonic.tsx#L29

As BIP-39 does not prohibit repeated phrases, mnemonics like abandon abandon abandon ... can exist, and if the implementation selects abandon as the phrase to drop, all instances of abandon will be dropped. I recommend, thus, dropping phrases by their indices.

Below is a reference implementation

import { shuffle } from 'lodash';

const size = mnemonics.length;
const indices = Array.from({ length: size }, (_, i) => i);
shuffle(indices);

const emptyIndices = indices.slice(0, isDev ? 1 : 6);
const defaultValues = mnemonics.map((phrase, index) => (emptyIndices.includes(index) ? "" : phrase));

console.log(defaultValues);
hryjosn commented 1 year ago

Hi @stmharry, thanks for finding this issue, and we will fix and update it soon

hryjosn commented 1 year ago

@stmharry Fixed Good catch!