@mwaddip/ergots-proof
v0.1.0
Published
Pure-TypeScript Ergo NiPoPoW proof verifier — parse, serialize, verify, compare; plus the P2P envelope codec.
Downloads
35
Maintainers
Readme
@mwaddip/ergots-proof
Pure-TypeScript Ergo NiPoPoW proof verifier. Browser-compatible. Validated byte-for-byte against ergo-nipopow (sigma-rust).
Install
npm install @mwaddip/ergots-proofUsage
import { verifyProof, parseProof, compareProofs } from '@mwaddip/ergots-proof';
const proofBytesA: Uint8Array = /* first proof from peer A */;
const proofBytesB: Uint8Array = /* second proof from peer B */;
// Verify (default checks Autolykos v2 PoW per header):
const result = verifyProof(proofBytesA);
console.log(result.suffixTipHeight, 'headers in proof:', result.totalHeaders);
// Or parse without verification:
const proof = parseProof(proofBytesA);
// Compare two proofs from different peers:
const aIsBetter = compareProofs(proofBytesA, proofBytesB);See API.md for the full reference (every export, its signature, error codes, and type definitions).
P2P envelope codec
The wire envelope for Ergo's P2P message codes 90 (GetNipopowProof) and 91 (NipopowProof) ships under a subpath:
import {
parseGetNipopowProof,
serializeNipopowProofEnvelope,
GET_NIPOPOW_PROOF,
NIPOPOW_PROOF,
} from '@mwaddip/ergots-proof/envelope';Browser compatibility
Runs unchanged in evergreen browsers and Node >= 20. No Buffer, no node:crypto, no dynamic Node built-ins. ESM-only.
The verifier is stateless: bytes in, structured result out. It does not fetch proofs, persist headers, or follow the chain tip — those concerns live in future packages (@mwaddip/ergots-gossip, @mwaddip/ergots-light-client).
What this package does NOT do
- Proof construction. Building a proof requires a local header chain with cached interlinks — that's a different package.
- Transport. Callers fetch proofs over their own channel.
- Storage. No header chain, no IndexedDB.
- Light-client sync. Bootstrapping from a verified proof + following the tip lives in
@mwaddip/ergots-light-client.
Verification scope
- NiPoPoW proof structure (parse + serialize + round-trip)
- Parent-linkage connections (sigma-rust's
has_valid_connectionssemantics, 11-entry lookback window) - Strict-increasing heights across the proof
- Per-header Autolykos v2 PoW (version 1 headers are structurally accepted; v1 PoW is not verified, mirroring sigma-rust's
Unsupportedbehavior) - Pairwise comparison (KMZ17 §4.3
is_better_than)
Reference implementation
This package is a clean-room TypeScript port of ergo-nipopow from sigma-rust. Every primitive is validated byte-for-byte against fixtures generated by the Rust reference, including 5 real mainnet headers and 1 real mainnet NiPoPoW proof from ergo-node-rust.
License
MIT
