11 #include <boost/algorithm/string.hpp> 21 bool isValidUtf8(
const std::string &s) {
23 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
26 auto utf16 = utf16conv.from_bytes(s.data());
35 if (phrase.empty() || !isValidUtf8(std::string(phrase))) {
39 auto password_pos = phrase.find(
"///");
40 std::string_view mnemonic_list;
42 if (password_pos != std::string_view::npos) {
44 password = phrase.substr(password_pos + 3);
45 mnemonic_list = phrase.substr(0, password_pos);
47 mnemonic_list = phrase;
50 if (mnemonic_list.find(
"/") != std::string_view::npos) {
52 ->error(
"junctions are not supported yet");
57 std::vector<std::string> word_list;
58 boost::split(word_list, mnemonic_list, boost::algorithm::is_space());
60 Mnemonic mnemonic{std::move(word_list), std::string(password)};
70 return "Mnemonic provided is not valid";
72 return "unknown MnemonicError";
static outcome::result< Mnemonic > parse(std::string_view phrase)
parse mnemonic from phrase
OUTCOME_CPP_DEFINE_CATEGORY(kagome::crypto::bip39, MnemonicError, e)
Logger createLogger(const std::string &tag)