Functional Weave
Code in Rust

auth.recovery-codes@1.0.0

impl/python/hash_recovery_code.py

619 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .auth_recovery_codes_normalise_recovery_code import normalise_recovery_code  ← normaliseRecoveryCode, another function of this group · built into the same file, even by a slim install
from .crypto_sha256 import sha256  ← from crypto.sha256 ^1.0.0 · built alongside by fune
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)))