Sha256Challenge
A SHA-256 challenge is a challenge which forces the client to find a hash which has at least difficulty number of leading zero bits in the hash. As hashing returns pseudo-random results, as a general rule of thumb, the work needed to solve a challenge doubles with each difficulty increase, since each bit can be either true or false, and the solution must have at least difficulty amount of false (zero) bits. Since the requirement is that there are at least difficulty amount of leading zero bits, these challenges aren't constrained to only having a single successful answer.
Properties
the difficulty of the challenge, as explained above, is the number of leading zero bits the hash must have for it to be considered successful. The default difficulty in OldSchool RuneScape is 18 as of writing this. When Proof of Work was first introduced, this value was 16. It is possible that the value gets dynamically increased as the pressure increases, or if there are a lot of requests from a single IP.
Functions
A function to encode the given challenge into the byte buffer that the client expects. The role of encoding is moved over to the implementation as the server can provide its own implementations, should the client support any.
Estimates the size of the message, allowing Netty to accurately track the number of bytes writing it would require.
Gets the base string that is part of the input for the hash. A long will be appended to this base string at the end, which will additionally be the solution to the challenge. The full string of baseString + the long is what must result in difficulty number of leading zero bits after having been hashed.