from .auth_recovery_codes_normalise_recovery_code import normalise_recovery_code from .crypto_sha256 import sha256 from .encoding_hex_hex_encode import hex_encode from .encoding_utf8_utf8_encode import utf8_encode def hash_recovery_code(code: str) -> str: """The hex SHA-256 of "fune.recovery-code:" and the normalised code: what to store. A fast unsalted hash is enough because each code carries 80 random bits.""" normal = normalise_recovery_code(code) if normal is None: raise ValueError("not a recovery code") return hex_encode(sha256(utf8_encode("fune.recovery-code:" + normal)))