@totemsdk/txpow
v0.1.5
Published
TxPoW envelope serialization and proof-of-work mining for the Minima protocol
Maintainers
Readme
@totemsdk/txpow
TxPoW — Minima's spam-prevention proof-of-work on every transaction.
Every Minima transaction must carry a proof-of-work envelope before it can be broadcast. This package handles the full TxPoW lifecycle: serialize, mine, verify, and calibrate.
Install
npm install @totemsdk/txpowWhat's inside
| Export | What it does |
|--------|-------------|
| serializeTxHeader / serializeTxBody / serializeTxPoW | Byte-identical TxPoW envelope assembly |
| computeTxPoWId | Derive the canonical TxPoW ID used for deduplication |
| mineTxPoW(txBody, target) | Local PoW mining loop — returns { minedHeaderBytes } |
| fetchTxPowTarget(axiaBaseUrl) | Fetch current network difficulty from Axia |
| verifyProofOfWork(txpowId, difficulty) | Verify a received TxPoW (for relay nodes) |
| calibrateHashRate() | Benchmark local hardware hash rate |
| estimateMiningCost(difficulty) | Estimate mining time at current hash rate |
| MAX_HASH, TX_POW_MIN_DIFFICULTY, CASCADE_LEVELS, MAIN_NET_CHAIN_ID | Chain constants |
Usage
Mine and broadcast a transaction
import {
mineTxPoW,
fetchTxPowTarget,
serializeTxPoW,
computeTxPoWId,
} from '@totemsdk/txpow';
// 1. Fetch current difficulty
const target = await fetchTxPowTarget('https://api.axia.to');
// 2. Mine (this runs the PoW loop — may take seconds)
const { minedHeaderBytes } = await mineTxPoW(txBodyBytes, target);
// 3. Assemble the final TxPoW envelope
const txpowBytes = serializeTxPoW(minedHeaderBytes, txBodyBytes);
const txpowId = computeTxPoWId(txpowBytes);
console.log('TxPoW ID:', txpowId);
// 4. Broadcast
await provider.broadcastTxPoW(Buffer.from(txpowBytes).toString('hex'));Verify received TxPoW
import { verifyProofOfWork } from '@totemsdk/txpow';
const ok = verifyProofOfWork(txpowId, difficulty);
if (!ok) throw new Error('Invalid proof-of-work');Calibrate hardware
import { calibrateHashRate, estimateMiningCost } from '@totemsdk/txpow';
const hashesPerSecond = await calibrateHashRate();
const estimatedMs = estimateMiningCost(targetDifficulty, hashesPerSecond);
console.log(`Expected mining time: ${estimatedMs}ms`);See also
@totemsdk/tx-builder— constructtxBodyBytesbefore mining@totemsdk/node— Node.js wallet that uses txpow internally@totemsdk/chain-provider—broadcastTxPoWendpoint
