Sha256Challenge

class Sha256Challenge(val version: Int, val difficulty: Int, val salt: String) : ChallengeType<Sha256MetaData>

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.

Constructors

Link copied to clipboard
constructor(version: Int, difficulty: Int, salt: String)

Properties

Link copied to clipboard

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.

Link copied to clipboard
open override val id: Int

the id of the challenge as identified by the client.

Link copied to clipboard

the salt string that is the bulk of the input to hash.

Link copied to clipboard

the version of hashcash to use, only 1 is supported.

Functions

Link copied to clipboard
open override fun encode(buffer: JagByteBuf)

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.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun estimateMessageSize(): Int

Estimates the size of the message, allowing Netty to accurately track the number of bytes writing it would require.

Link copied to clipboard

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.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String