SHA-256 Hash Verification Example

On this page, you can see an example implementation of the SHA-256 hash verification algorithm using JavaScript. You can use this code to independently verify our roulette results.

Code for hash verification
// Function for SHA-256 hash verification
async function verifyHash(number, salt, originalHash) {
    try {
        // Format string as "number:salt"
        const data = `${number}:${salt}`;

        // Encode string to byte array
        const encoder = new TextEncoder();
        const dataBuffer = encoder.encode(data);

        // Calculate SHA-256 hash
        const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);

        // Convert ArrayBuffer to hex string
        const hashArray = Array.from(new Uint8Array(hashBuffer));
        const computedHash = hashArray.map(b =>
            b.toString(16).padStart(2, '0')
        ).join('');

        // Check if computed hash matches the original
        const isValid = computedHash === originalHash;

        return {
            isValid,
            computedHash,
            originalHash,
            number,
            salt,
            input: data
        };
    } catch (error) {
        console.error('Error during hash verification:', error);
        return {
            isValid: false,
            error: error.message
        };
    }
}
How to use this code:
  1. Copy the function code verifyHash
  2. Add it to your JavaScript project
  3. Call the function with parameters: number, salt, and original hash
  4. The function will return an object with the verification result and additional information
Note: This code uses the Web Crypto API, available in most modern browsers.
Try it yourself
Leave empty for automatic calculation and comparison.
Verification Result
Waiting for verification...
-
-
-

How does hash verification work?

Data Generation

The system creates a string in the format "number:salt" (e.g., "5:a1b2c3d4e5f6"). Here, the number is the roulette round result (from 0 to 36), and the salt is a random string of characters.

Hash Calculation

This string is converted into a byte array, to which the SHA-256 algorithm is applied. The result is a 64-character string in hexadecimal format.

Publication and Verification

Only the hash is published before the round starts. After the round ends, the number and salt are revealed. You can independently compute the hash and verify that it matches the published one.

Why does this guarantee fairness?

Since the hash is published before betting begins, and the result and salt are revealed after the round ends, the system cannot change the outcome after players have placed their bets. The SHA-256 cryptographic algorithm guarantees that it is impossible to find another "number:salt" pair that would produce the same hash.