UNPKG

hash160

Version:
122 lines (107 loc) 3.02 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hash160 Demo</title> <style> body { background: linear-gradient(135deg, #9d50bb, #6e48aa); background-attachment: fixed; color: #fff; font-family: 'Arial', sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; position: relative; } .container { background-color: rgba(106, 57, 171, 0.8); padding: 30px; border-radius: 15px; text-align: center; width: 400px; } h1 { color: #fff; font-size: 32px; } label, p { font-size: 18px; margin-bottom: 15px; margin-top: 15px; } input { width: 80%; padding: 12px; font-size: 18px; border: none; border-radius: 5px; margin-top: 10px; } p { color: #ffa07a; font-weight: bold; } a { position: absolute; bottom: 10px; right: 10px; color: #fff; font-size: 14px; text-decoration: none; } a:hover { text-decoration: underline; } </style> </head> <body> <div class="container"> <h1>Hash160 Calculator</h1> <label for="dataInput">Enter data:</label> <input type="text" id="dataInput" oninput="calculateHash()" /> <!-- Checkbox for input type selection --> <label> <input type="checkbox" id="isHex" /> Hex </label> <p id="output"></p> </div> <a href="https://github.com/brain-wallet/hash160" target="_blank" rel="noopener noreferrer" >View Source</a > <script type="module"> import hash160 from './index.js' window.calculateHash = async () => { const data = document.getElementById('dataInput').value const isHex = document.getElementById('isHex').checked // If input type is hex, validate the hex input and convert to Uint8Array if (isHex && !/^[0-9a-fA-F]+$/.test(data)) { document.getElementById('output').innerText = 'Invalid hex input' return } const processedData = isHex ? hexToUint8Array(data) : data const hashResult = await hash160(processedData) // Pass the processed data to your hash function document.getElementById( 'output' ).innerText = `Hash160 of "${data}" is: ${hashResult}` } // Function to convert hex to Uint8Array function hexToUint8Array(hexString) { const byteArray = [] for (let i = 0; i < hexString.length; i += 2) { byteArray.push(parseInt(hexString.slice(i, i + 2), 16)) } return new Uint8Array(byteArray) } </script> </body> </html>