antibot

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

README

antibot

Import path: github.com/InsideGallery/core/antibot

Overview

antibot provides a small SHA-256 proof-of-work helper. A challenge is solved when the hex digest of message + nonce starts with the configured number of zero characters.

Main APIs

  • ProofOfWork stores the requested Difficulty.
  • NewProofOfWork(difficulty int) creates a proof-of-work checker.
  • (*ProofOfWork).Validate(message string, nonce int) checks whether a nonce satisfies the challenge.
  • (*ProofOfWork).FindNonce(message string) searches from nonce 0 upward and returns the nonce and hash.

Usage

pow := antibot.NewProofOfWork(4)

nonce, hash := pow.FindNonce("Hello, world!")
valid := pow.Validate("Hello, world!", nonce)

_ = hash
_ = valid

Notes

FindNonce is CPU-bound and has no context, timeout, or maximum nonce. Callers should choose a difficulty appropriate for the request path and enforce their own cancellation when needed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProofOfWork

type ProofOfWork struct {
	Difficulty int
}

ProofOfWork represents the structure of our PoW

func NewProofOfWork

func NewProofOfWork(difficulty int) *ProofOfWork

NewProofOfWork creates a new ProofOfWork with a given difficulty

func (*ProofOfWork) FindNonce

func (pow *ProofOfWork) FindNonce(message string) (int, string)

FindNonce finds a nonce that solves the PoW challenge

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate(message string, nonce int) bool

Validate checks if a given nonce solves the challenge for a message

Jump to

Keyboard shortcuts

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