Ryanhub - file viewer
filename: html/api/services/register/challenge.php
branch: main
back to repo
<?php
require_once __DIR__ . '/../../lib/response.php';
require_once __DIR__ . '/../../lib/db.php';

// create a random challenge id, difficulty, and expiry
$challenge = bin2hex(random_bytes(8));
$difficulty = 5; // default difficulty (hex leading zeros)
$expires = time() + 30; 

// store in db
$q = $pdo->prepare('INSERT INTO pow_challenges (challenge, difficulty, expires_at) VALUES (?, ?, ?)');
$q->execute([$challenge, $difficulty, $expires]);

json([
    'challenge' => $challenge,
    'difficulty' => $difficulty,
    'expires' => $expires,
]);