From 203b66175e233ecd2abb7ddb062a49b0301b5616 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Wed, 15 May 2024 16:09:18 +0100 Subject: [PATCH] add new helper method for mnemonic validity checking --- Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift b/Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift index 79b59e9..201308d 100644 --- a/Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift +++ b/Sources/KukaiCryptoSwift/Mnemonic/Mnemonic.swift @@ -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 { @@ -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) } /**