This is a simple API that allows you to generate a proof of work challenges and verify the proof of work.
The API has two endpoints:
The proof of work challenge is to find a proof which, when concatenated and hashed (via SHA 512) with a challenge string that starts with a certain number of zeros. The number of zeros is determined by the difficulty level. The difficulty level is a number between 1 and 10. The higher the difficulty level, the more zeros the string must start with.
The current difficulty is {{difficulty}}.
The example code for performing a proof of work challenge is:
const crypto = require('crypto'); const axios = require('axios'); async function getChallenge() { const response = await axios.get('https://api.us.dev/pow/challenge'); return response.data; } async function submitSolution(challenge, proof) { const response = await axios.post('https://api.us.dev/pow/challenge', { challenge, proof }); return response.data; } function hashProof(challenge, proof) { return crypto.createHash('sha512').update(challenge + proof).digest('hex'); } function verifyChallenge(hash: string, difficulty: number) { return hash.startsWith('0'.repeat(difficulty)); } async function proofOfWork() { const challenge = await getChallenge(); let proof = 0; let hash = ''; do { proof++; hash = hashProof(challenge, proof); } while (!verifyChallenge(hash, 5)); return await submitSolution(challenge, proof); } proofOfWork().then(console.log).catch(console.error);
If you're a developer you should use the GET /pow/challenge endpoint to get the challenge, then pass the challenge to your client, then have the client find a solution to the challenge and then submit their proof as part of their later action. Your service should then verify the solution using the POST /pow/challenge endpoint (or your own local implementation) to verify the solution.