Skip to content

Commit

Permalink
add new helper method for mnemonic validity checking
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed May 15, 2024
1 parent 05b8b40 commit 203b661
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public struct Mnemonic: Equatable, Codable {
}

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

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

return Mnemonic.isValidChecksum(phrase: words, wordlist: vocabulary)
return true
}

/**
Check a mnemonic is of the correct length, is made up of valid BIP39 words, and the checksum matches
*/
public func isValid(in vocabulary: WordList = .english) -> Bool {
return isValidWords() && Mnemonic.isValidChecksum(phrase: words, wordlist: vocabulary)
}

/**
Expand Down

0 comments on commit 203b661

Please sign in to comment.