SHA-256 in the browser
Calculate a real SHA-256 digest with the browser Web Crypto API.
Hash a known input
This complete example hashes the UTF-8 text abc. It uses only the standard browser API and runs locally. It is a hash demonstration, not the mining engine or a production proof.
const bytes = new TextEncoder().encode('abc');
const digest = await crypto.subtle.digest('SHA-256', bytes);
const hex = Array.from(new Uint8Array(digest), (byte) =>
byte.toString(16).padStart(2, '0')
).join('');
const expected =
'ba7816bf8f01cfea414140de5dae2223' +
'b00361a396177a9cb410ff61f20015ad';
if (hex !== expected) throw new Error('SHA-256 check failed.');
console.log(hex);Text and bytes differ
A digest depends on the exact bytes. The text 2a is two UTF-8 bytes, while the hexadecimal byte 0x2a is one byte. Text encodings and binary encodings are not interchangeable.
const textBytes = new TextEncoder().encode('2a');
const binaryBytes = new Uint8Array([0x2a]);
console.log(Array.from(textBytes)); // [50, 97]
console.log(Array.from(binaryBytes)); // [42]Read the output
SHA-256 produces 32 bytes. Rendering each byte as two hexadecimal characters gives a 64-character string. Padding preserves leading zeroes. The same bytes always produce the same digest.
Use the desk for mining
The actual desk manages its current challenge and search engine. These examples make no requests to the mining service and do not demonstrate opening or completing a round.