Error-out when you scan an account id when trying to recover an account

This commit is contained in:
bemusementpark 2024-07-10 23:38:07 +09:30
parent 84b1fb6527
commit 71f04678cf

View File

@ -128,13 +128,12 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed) decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed)
} catch (decodeException: Exception) { } catch (decodeException: Exception) {
// It's not a valid mnemonic, if it's pure-hexadecimal then we'll interpret it as a // It's not a valid mnemonic, if it's pure-hexadecimal then we'll interpret it as a
// hexadecimal-byte encoded mnemonic. // hexadecimal-byte encoded mnemonic... unless it's 66 chars or longer, then it could be
if (!mnemonicOrHex.isHex()) throw decodeException // an account id.
try { mnemonicOrHex.takeIf { it.length < 66 && it.isHex() }
Hex.fromStringCondensed(mnemonicOrHex) .runCatching { Hex.fromStringCondensed(this) }
} catch (_: Exception) { .getOrNull()
throw decodeException ?: throw decodeException
}
} }
} }