whitelist

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package whitelist is the registration-whitelist domain. Its Service provides two things from one place:

  • the authorization gate (Checker.IsWhitelisted) shared by the registration service and the Ethereum JSON-RPC facade. The skip decision (skip_whitelist_check) is baked into the Service at construction time, so consumers only ever ask "is this address allowed?" without carrying their own skip flag and branch; and
  • the admin operations (Manager: add, remove, cursor-paginated list) exposed under /admin/whitelist.

Index

Constants

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 200
)

Cursor pagination bounds for List, mirroring the token list endpoint.

Variables

View Source
var ErrEntryNotFound = errors.New("whitelist entry not found")

ErrEntryNotFound is returned by Remove when the address was not whitelisted.

Functions

func RegisterAdminRoutes

func RegisterAdminRoutes(r chi.Router, mgr Manager, token string, logger *zap.Logger)

RegisterAdminRoutes mounts the privileged whitelist-management endpoints under /admin on r, gated by a static bearer token.

Types

type Checker

type Checker interface {
	IsWhitelisted(ctx context.Context, evmAddress string) (bool, error)
}

Checker reports whether an EVM address is permitted. It is the narrow gate consumed by the registration service and the eth-rpc facade.

type Manager

type Manager interface {
	Add(ctx context.Context, evmAddress, note string) error
	Remove(ctx context.Context, evmAddress string) error
	List(ctx context.Context, cursor string, limit int) (*Page, error)
}

Manager is the admin surface (add/remove/list) consumed by the HTTP layer.

type Page

type Page struct {
	Items      []user.WhitelistEntry `json:"items"`
	NextCursor string                `json:"next_cursor,omitempty"`
	HasMore    bool                  `json:"has_more"`
}

Page is the cursor-paginated whitelist listing returned by List.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the whitelist domain. When skip is true the gate authorizes every address (skip_whitelist_check); the admin operations are unaffected.

func New

func New(store Store, skip bool) *Service

New returns a whitelist Service backed by store. When skip is true every address is authorized by IsWhitelisted.

func (*Service) Add

func (s *Service) Add(ctx context.Context, evmAddress, note string) error

Add validates the address and upserts it (with an optional note). It is idempotent: re-adding an address updates its note rather than erroring, so callers can ensure-present without a prior read.

func (*Service) IsWhitelisted

func (s *Service) IsWhitelisted(ctx context.Context, evmAddress string) (bool, error)

IsWhitelisted reports whether evmAddress may register/transact. With skip enabled it always returns true without touching the store.

func (*Service) List

func (s *Service) List(ctx context.Context, cursor string, limit int) (*Page, error)

List returns one cursor-delimited page of whitelisted addresses, ordered by address. It fetches one extra row to determine HasMore without a separate count query; NextCursor is the last returned address (pass it back as cursor for the next page). limit is clamped to [1, MaxLimit] so a non-HTTP caller can't request a zero/negative page (which would yield an empty page that still reports HasMore and loop a paging client forever) or an unbounded one.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, evmAddress string) error

Remove validates the address and removes it, returning a not-found error when the address was not whitelisted so the operator gets clear feedback.

type Store

type Store interface {
	IsWhitelisted(ctx context.Context, evmAddress string) (bool, error)
	AddToWhitelist(ctx context.Context, evmAddress, note string) error
	RemoveFromWhitelist(ctx context.Context, evmAddress string) (removed bool, err error)
	ListWhitelist(ctx context.Context, cursor string, limit int) ([]*user.WhitelistEntry, error)
}

Store is the persistence the whitelist needs. It is satisfied by the user store. ListWhitelist returns up to limit entries after cursor (the previous page's last evm_address; empty starts from the beginning).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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