Documentation
¶
Overview ¶
Package pow contains the PoW service, that handles the logic of proof-of-work for the application. It currently uses hashcash v1, but can be extended to support other PoW systems. It stores the challenges in a store, that can be in memory, Redis, or any other storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrChallengeNotFound is returned when the challenge is not found in the store. ErrChallengeNotFound = errors.New("challenge not found") // ErrChallengeKeyEmpty is returned when the challenge key is empty. // This should never happen and could lead to incorrect storage of challenges. ErrChallengeKeyEmpty = errors.New("challenge key is empty") // ErrChallengeDifficultyInvalid is returned when the challenge difficulty is invalid. ErrChallengeDifficultyInvalid = errors.New("challenge difficulty is invalid") // ErrChallengeSaltLengthInvalid is returned when the challenge salt length is invalid. ErrChallengeSaltLengthInvalid = errors.New("challenge salt length is invalid") )
Functions ¶
This section is empty.
Types ¶
type ChallengeKey ¶
type ChallengeKey struct {
// contains filtered or unexported fields
}
ChallengeKey is a key for a challenge.
func NewChallengeKey ¶
func NewChallengeKey(clientID string, resourceID string) *ChallengeKey
NewChallengeKey returns a new challenge key.
func (*ChallengeKey) ClientID ¶
func (c *ChallengeKey) ClientID() string
ClientID returns the client ID.
func (*ChallengeKey) ResourceID ¶
func (c *ChallengeKey) ResourceID() string
ResourceID returns the resource ID.
func (*ChallengeKey) String ¶
func (c *ChallengeKey) String() string
String returns a string representation of the challenge key.
type ChallengeStore ¶
type ChallengeStore interface { // Add adds a challenge to the store. Add(ctx context.Context, key, value string) error // Get checks if a challenge is in the store. Get(ctx context.Context, key string) (bool, error) // Delete deletes a challenge from the store. Delete(ctx context.Context, key string) error }
ChallengeStore is an interface for storing which challenges are currently active.
type Service ¶
type Service struct { // ChallengeStore is a store for challenges. Store ChallengeStore // contains filtered or unexported fields }
Service is a PoW service.
func NewService ¶
func NewService(logger *zap.Logger, store ChallengeStore) *Service
NewService creates a new PoW service.
func (*Service) CheckSolution ¶
CheckSolution checks if the solution with the given challenge key exists in the store and if it is correct.