Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Mnenonic Words.count check #308

@v-sharaev

Description

@v-sharaev

Hello

In BIP39.swift class Mnemonic has public init(_ string: String, language: BIP39Language = .english) throws

There have checking code:

// checking entropy
let wordList = string.components(separatedBy: " ")
guard wordList.count >= 12 else { throw EntropyError.notEnoughtWords }
guard wordList.count % 4 == 0 else { throw EntropyError.invalidNumberOfWords }

But it's not valid, because method
public init(entropySize: EntropySize = .b256, language: BIP39Language = .English)
generate 12, 15, 18, 21, 24 word. By BIP39 spec

If you write test:

do {
    let mnemonic = Mnemonics(entropySize: .b192, language: .english)
    let mnemonic2 = try Mnemonics(mnemonic.string, language: .english)
} catch let error {
    print(error) // web3swift.Mnemonics.EntropyError.invalidNumberOfWords
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions