fix: added bip39 mnemonic validation
@@ -75,15 +75,20 @@ func (m Mnemonic) Words() []string {
//
// Keys are lazily generated
func NewMnemonic(words []string) (Mnemonic, error) {
+ joinedString := strings.Join(words, " ")
+
if len(words) == 24 || len(words) == 12 || len(words) == 22 {
if len(words) == 22 {
return Mnemonic{
- words: strings.Join(words, " "),
+ words: joinedString,
}.legacyValidate()
- }
+ } else if bip39.IsMnemonicValid(joinedString) {
return Mnemonic{
- words: strings.Join(words, " "),
+ words: joinedString,
}, nil
+ } else {
+ return Mnemonic{}, fmt.Errorf("invalid mnemonic composition")
+ }
} else {
return Mnemonic{}, fmt.Errorf("invalid mnemonic string")
}
