Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container text-white mx-auto w-full max-w-xl mt-10 p-4 rounded-2xl">
  <h1 class="text-2xl text-center font-bold mb-6">BitNile Roulette Verifier</h1>

  <label for="serverSeed">Server Seed</label>
  <input id="serverSeed" type='text' class='w-full py-2 px-3 rounded-xl mt-1 mb-2' />

  <label for="clientSeed">Client Seed</label>
  <input id="clientSeed" type='text' class='w-full py-2 px-3 rounded-xl mt-1 mb-2' />
  
  <label for="nonce">Nonce</label>
  <input id="nonce" type='number' class='w-full py-2 px-3 rounded-xl mt-1 mb-2' />  

  <div id="verify" class='bg-white hover:bg-white/90 cursor-pointer text-center p-3 rounded-xl mt-3 text-black text-md font-medium'>
     Verify Game
  </div>
  
  <div id="result" class='my-6'>
  </div>
</div>
              
            
!

CSS

              
                body, input, select {
  background: #2a2e31;
}

.container {
  background: #1B1B1D;
}

label {
  color: #aaa;
}
              
            
!

JS

              
                import lodash from "https://esm.sh/lodash";

const createHmacString = (privateKey, message) => {
    const key = CryptoJS.enc.Utf8.parse(privateKey);
    const hmac = CryptoJS.HmacSHA256(message, key);
    return CryptoJS.enc.Hex.stringify(hmac);
}

function* byteGenerator({
  serverSeed,
  clientSeed,
  nonce,
  cursor,
}: {
  serverSeed: string;
  clientSeed: string;
  nonce: number;
  cursor: number;
}) {
  let currentRound = Math.floor(cursor / 32);
  let currentRoundCursor = cursor;
  currentRoundCursor -= currentRound * 32;

  while (true) {
    const message = `${clientSeed}:${nonce}:${currentRound}`;
    const hmacHex = createHmacString(serverSeed, message);
    const buffer = CryptoJS.enc.Hex.parse(hmacHex);

    while (currentRoundCursor < 32) {
      yield Number(buffer.words[Math.floor(currentRoundCursor / 4)] >> (8 * (3 - (currentRoundCursor % 4))) & 0xff);
      currentRoundCursor += 1;
    }
    currentRoundCursor = 0;
    currentRound += 1;
  }
}

function generateFloats({
  serverSeed,
  clientSeed,
  nonce,
  cursor,
  count,
}: {
  serverSeed: string;
  clientSeed: string;
  nonce: number;
  cursor: number;
  count: number;
}): number[] {
  const generator = byteGenerator({ serverSeed, clientSeed, nonce, cursor });
  const bytes = [];
  while (bytes.length < count * 4) {
    const nextValue = generator.next().value;
    if (typeof nextValue === "number") {
      bytes.push(nextValue);
    } else {
      throw new Error("Generator did not yield a number");
    }
  }

  return lodash.chunk(bytes, 4).map((bytesChunk) => {
    return bytesChunk.reduce((result, value, i) => {
      const divider = 256 ** (i + 1);
      const partialResult = value / divider;
      return result + partialResult;
    }, 0);
  });
}

document.getElementById('verify').onclick = () => {
  const serverSeed = document.getElementById('serverSeed').value
  const nonce = document.getElementById('nonce').value
  const clientSeed = document.getElementById('clientSeed').value

  if (!serverSeed) return error('Server seed is required')
  if (!nonce) return error('Server hash is required')
  if (!clientSeed) return error('Client seed is required')

  const floats = generateFloats({ serverSeed, clientSeed, nonce, cursor: 0, count: 1 });
  const rng = Math.floor(floats[0] * 38);
  const outcome = rng - 1;
  result.innerHTML = `<div class="text-center">
  

      <div class="text-gray-300">
          Result number: ${outcome}
        </div>
     
  </div>`
}

              
            
!
999px

Console