/*
*Project: Yedad_Slot_Key
*Author: ADEL SOBHANI
*License : Apache-2.0
*/
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>YIP-09 Verifier (Full Logic)</title>
<style>
body { font-family: Tahoma; background: #0f172a; color: #f8fafc; padding: 20px; text-align: center; }
.card { max-width: 800px; background: #1e293b; padding: 30px; border-radius: 20px; margin: auto; border: 1px solid #334155; }
input { width: 80%; padding: 12px; margin: 10px 0; border-radius: 8px; border: none; background: #334155; color: #00d2ff; text-align: center; font-family: monospace; }
button { background: #e94560; color: white; border: none; padding: 15px 30px; border-radius: 10px; cursor: pointer; font-weight: bold; margin-top: 20px; }
.result-box { margin-top: 20px; padding: 20px; background: #0f172a; border-radius: 10px; display: none; text-align: left; border-left: 5px solid #10b981; }
.hash { word-break: break-all; font-family: 'Courier New', monospace; color: #00d2ff; font-size: 11px; }
</style>
</head>
<body>
<div class="card">
<h2 style="color: #e94560;">Ladder Verifier (Including Ladder ID)</h2>
<label>Private Key:</label><br>
<input type="text" id="privKey" value="yedad_key_100k_test">
<br><br>
<label>Ladder ID:</label><br>
<input type="number" id="ladderIdx" value="1">
<br><br>
<label>Slot Hash (Step N):</label><br>
<input type="text" id="targetHash" placeholder="Enter the hash in the slot here...">
<br>
<button id="runBtn" onclick="verifyLogic()">Calculate Entire Path and Discover Previous Step</button>
<div id="status" style="margin-top:15px; color:#f59e0b;"></div>
<div id="result" class="result-box">
<div style="color: #10b981; font-weight: bold; margin-bottom: 10px;">✅ Matching completed successfully!</div>
<div><strong>Ladder ID:</strong> <span id="resLadderId" style="color:#fff;"></span></div>
<div><strong>Step Found:</strong> <span id="foundStepNum" style="color: #fff;"></span></div>
<div style="margin-top: 10px;"><strong>Previous Step (to be submitted to the core for the next transaction):</strong></div>
<div id="foundHash" class="hash"></div>
</div>
</div>
<script>
const bytesToHex = bytes => Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
async function doubleSha256(inputBytes) {
const first = await crypto.subtle.digest('SHA-256', inputBytes);
const second = await crypto.subtle.digest('SHA-256', first);
return new Uint8Array(second);
}
async function verifyLogic() {
const keyText = document.getElementById('privKey').value;
const ladderIdx = BigInt(document.getElementById('ladderIdx').value);
const target = document.getElementById('targetHash').value.trim().toLowerCase();
const status = document.getElementById('status');
const resultDiv = document.getElementById('result');
const btn = document.getElementById('runBtn');
btn.disabled = true;
resultDiv.style.display = 'none';
status.innerText = "⏳ Reconstructing the ladder specific to this ID...";
try {
let current = new TextEncoder().encode(keyText);
for(let i=0; i<2048; i++) current = await doubleSha256(current);
let masterSeed = current;
let idBytes = new Uint8Array(8);
new DataView(idBytes.buffer).setBigUint64(0, ladderIdx, false);
let combined = new Uint8Array(masterSeed.length + idBytes.length);
combined.set(masterSeed); combined.set(idBytes, masterSeed.length);
current = combined;
for(let i=0; i<2048; i++) current = await doubleSha256(current);
let previousHash = bytesToHex(current);
let found = false;
for (let i = 1; i <= 100000; i++) {
let currentRaw = await doubleSha256(current); let currentHex = bytesToHex(currentRaw);
if (currentHex === target) {
document.getElementById('resLadderId').innerText = ladderIdx.toString();
document.getElementById('foundStepNum').innerText = (i - 1);
document.getElementById('foundHash').innerText = previousHash;
found = true;
break;
}
previousHash = currentHex;
current = currentRaw;
if (i % 20000 === 0) {
status.innerText = `🔍 Searching at step ${i.toLocaleString()}...`;
await new Promise(r => setTimeout(r, 0));
}
}
if (found) {
resultDiv.style.display = 'block';
status.innerText = "✨ The target step has been verified in this ladder.";
} else {
status.innerText = "❌ Error: This hash does not match with this ladder ID and private key.";
}
} catch (e) { status.innerText = "Error: " + e.message; }
finally { btn.disabled = false; }
}
</script>
</body>
</html>