service

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package service implements the Sign-In with Ethereum (EIP-4361) login flow: it issues single-use nonces, verifies signed SIWE messages, and mints the JWTs that authenticate read endpoints. The cryptographic primitives (JWT issuer, SIWE verifier, JWKS) live in pkg/auth/jwt and the nonce store in pkg/auth/service/nonce_provider; this package orchestrates them and binds the authenticated address to a registered user's Canton party.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(r chi.Router, svc Service, logger *zap.Logger)

RegisterRoutes mounts the login and JWKS endpoints on r.

Types

type Issuer

type Issuer interface {
	Issue(evmAddress, cantonPartyID string) (string, time.Time, error)
	JWKS() jwt.JWKS
}

Issuer mints session JWTs and publishes the signing key set. Satisfied by *jwt.Issuer.

type NonceStore

type NonceStore interface {
	// Issue returns a nonce for address, valid for the store's TTL. Calling it again
	// for an address that still holds a live nonce returns the same value. It may
	// return an error if the store is at capacity.
	Issue(address string) (string, error)
	// Consume returns true exactly once for a live, previously-issued nonce and
	// removes it; false for unknown, expired, or already-consumed nonces.
	Consume(nonce string) bool
}

NonceStore issues and consumes single-use login nonces keyed by address. Consume must be atomic so a given nonce satisfies at most one login. Implementations live under nonce_provider (e.g. nonceprovider.InMemory).

type Service

type Service interface {
	// Nonce issues a single-use login nonce for the given EVM address.
	Nonce(address string) (string, error)
	// JWKS returns the public signing key set for token validation by other services.
	JWKS() jwt.JWKS
	// Login verifies a signed SIWE message and, if the recovered address belongs to
	// a registered user, issues a JWT bound to that user's Canton party.
	Login(ctx context.Context, message, signature string) (*auth.LoginResponse, error)
}

Service orchestrates the SIWE login flow.

func New

func New(
	verifier Verifier,
	issuer Issuer,
	nonces NonceStore,
	users UserLookup,
) Service

New builds a login Service from its collaborators.

func NewLog

func NewLog(svc Service, logger *zap.Logger) Service

NewLog creates a logging decorator for the login Service.

type UserLookup

type UserLookup interface {
	GetUserByEVMAddress(ctx context.Context, evmAddress string) (*user.User, error)
}

UserLookup resolves a registered user by EVM address so login can bind the token to the user's Canton party. Satisfied by *userstore.Store.

type Verifier

type Verifier interface {
	Verify(message, signature string) (common.Address, string, error)
}

Verifier validates a signed SIWE login message and returns the recovered EVM address and the message nonce. Satisfied by *jwt.SIWEVerifier.

Directories

Path Synopsis
Package nonceprovider contains implementations of the login nonce store.
Package nonceprovider contains implementations of the login nonce store.

Jump to

Keyboard shortcuts

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