Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExpired = errors.New("expired hashcash")
ErrExpired is returned when the current time is past that of ExpiresAt
var ErrInvalidDate = errors.New("invalid date")
ErrInvalidDate is returned when the date cannot be parsed as a positive int64
var ErrInvalidDifficulty = errors.New("the number of bits of difficulty is too low or too high")
ErrInvalidDifficulty is returned when the difficulty is outside of the acceptable range
var ErrInvalidSolution = errors.New("the given solution is not valid")
ErrInvalidSolution is returned when the given hashcash is not properly solved
var ErrInvalidSubject = errors.New("the subject is invalid or rejected")
ErrInvalidSubject is returned when the subject is invalid or does not match that passed to Verify()
var ErrInvalidTag = errors.New("expected tag to be 'H'")
ErrInvalidTag is returned when the Hashcash version is unsupported
var ErrParse = errors.New("could not split the hashcash parts")
ErrParse is returned when fewer than 6 or more than 7 segments are split
var ErrUnsupportedAlgorithm = errors.New("the given algorithm is invalid or not supported")
ErrUnsupportedAlgorithm is returned when the given algorithm is not supported
var MaxDifficulty = 26
MaxDifficulty is the upper bound for all Solve() operations
var Sep = ":"
Sep is the separator character to use
Functions ¶
This section is empty.
Types ¶
type Hashcash ¶
type Hashcash struct { Tag string `json:"tag"` // Always "H" for "HTTP" Difficulty int `json:"difficulty"` // Number of "partial pre-image" (zero) bits in the hashed code ExpiresAt time.Time `json:"exp"` // The timestamp that the hashcash expires, as seconds since the Unix epoch Subject string `json:"sub"` // Resource data string being transmitted, e.g., a domain or URL Nonce string `json:"nonce"` // Unique string of random characters, encoded as url-safe base-64 Alg string `json:"alg"` // always SHA-256 for now Solution string `json:"solution"` // Binary counter, encoded as url-safe base-64 }
Hashcash represents a parsed Hashcash string
func Parse ¶
Parse will (obviously) parse the hashcash string, without verifying any of the parameters.
func (*Hashcash) Solve ¶
Solve will search for a solution, returning an error if the difficulty is above the local or global MaxDifficulty, the Algorithm is unsupported.