Skip to content

Commit 203b661

Browse files
committed
add new helper method for mnemonic validity checking
1 parent 05b8b40 commit 203b661

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ public struct Mnemonic: Equatable, Codable {
165165
}
166166

167167
/**
168-
Check a mnemonic is of the correct length, and is made up of valid BIP39 words
168+
Check a mnemonic contains valid words and a valid length (all other checks are ignored)
169169
*/
170-
public func isValid(in vocabulary: WordList = .english) -> Bool {
170+
public func isValidWords(in vocabulary: WordList = .english) -> Bool {
171171
let words = self.words
172172

173173
if words.count != 12 && words.count != 15 && words.count != 18 && words.count != 21 && words.count != 24 {
@@ -182,7 +182,14 @@ public struct Mnemonic: Equatable, Codable {
182182
}
183183
}
184184

185-
return Mnemonic.isValidChecksum(phrase: words, wordlist: vocabulary)
185+
return true
186+
}
187+
188+
/**
189+
Check a mnemonic is of the correct length, is made up of valid BIP39 words, and the checksum matches
190+
*/
191+
public func isValid(in vocabulary: WordList = .english) -> Bool {
192+
return isValidWords() && Mnemonic.isValidChecksum(phrase: words, wordlist: vocabulary)
186193
}
187194

188195
/**

0 commit comments

Comments
 (0)