pow

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MPL-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pow is the shared leading-zero SHA-256 work unit. purpose is only a label; bits are the cost. Not used in handshakes or DHT.

Index

Constants

View Source
const (
	// Domain is the hash prefix. A trailing 0x00 separates it from purpose.
	Domain = "a2al-pow-v1"
	// DefaultBits is the system default difficulty. 0 means off.
	DefaultBits = 8
)

Variables

This section is empty.

Functions

func Hash

func Hash(purpose string, from, to a2al.Address, ts int64, nonce []byte) [32]byte

Hash is SHA256(Domain || 0x00 || purpose || 0x00 || from || to || tsBE8 || nonce).

func LeadingZeros

func LeadingZeros(sum [32]byte) int

LeadingZeros returns the number of leading zero bits in sum.

func Solve

func Solve(ctx context.Context, purpose string, from, to a2al.Address, ts int64, bits int) ([]byte, error)

Solve searches for a nonce with at least bits leading zeros. bits <= 0 returns a nil nonce without hashing.

func Verify

func Verify(purpose string, from, to a2al.Address, ts int64, nonce []byte, bits int) bool

Verify reports whether nonce meets bits for this (purpose, from, to, ts). bits <= 0 always succeeds (PoW off).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL