The first step is to hash the message or digital data. This is done by submitting the data through a hashing algorithm so that a hash value is generated (i.e., the message digest). As mentioned, the messages can vary significantly in size, but when they are hashed, all their hash values have the same length. This is the most basic property of a hash function.
However, hashing the data is not a must for producing a digital signature because one can use a private key to sign a message that wasn’t hashed at all. But for cryptocurrencies, the data is always hashed because dealing with fixed-length digests facilitates the whole process.
After the information is hashed, the sender of the message needs to sign it. This is the moment where public-key cryptography comes into play. There are several types of digital signature algorithms, each with its own particular mechanism. But essentially, the hashed message will be signed with a private key, and the receiver of the message can then check its validity by using the corresponding public key (provided by the signer).