ProofOfWork class

Proof-of-Work helper built for deterministic simulation and testing.

Advanced features:

  • accepts a pluggable BigHash function for arbitrary hash spaces
  • mine supports an optional shouldStop callback for cancellation
  • verify helper to validate a candidate against a target
  • utilities to compute numeric target from compact difficulty bits

Constructors

ProofOfWork({required BigHash hashFn, int? seed})

Properties

hashCode int
The hash code for this object.
no setterinherited
hashFn BigHash
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

mine(String data, BigInt target, {int maxAttempts = 1000000, bool shouldStop()?}) MineResult
Mine data until hash <= target or maxAttempts reached.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
verify(String data, int nonce, BigInt target) bool
Verify that a nonce for data meets the target.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

targetFromCompact(int compact) BigInt
Compact bits -> target (toy implementation similar to Bitcoin's compact format).