def METHOD_NAME(keyring: LegacyKeyring) -> KeyData:
    key = KeyData.generate()
    index = 0
    while True:
        try:
            get_key_data(keyring, index)
            index += 1
        except KeychainUserNotFound:
            keyring.set_password(
                DEFAULT_SERVICE,
                get_private_key_user(DEFAULT_USER, index),
                bytes(key.public_key).hex() + key.entropy.hex(),
            )
            return key