Igris/internal/usecase/auth_service.go
2025-09-06 17:25:10 +03:30

61 lines
1.5 KiB
Go

package usecase
import (
"backend/internal/domain"
"context"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
)
type AuthService interface {
GenerateChallenge(ctx context.Context, pubKey string) (*domain.Challenge, error)
Authenticate(ctx context.Context, pubKey string, signature string, challenge *domain.Challenge, chainID uint) (*UserToken, error)
}
type authService struct {
userRepo *domain.UserRepo
sessionRepo *domain.SessionRepo
challengeExp uint
tokenExp uint
refreshTokenExp uint
}
type UserToken struct {
AuthorizationToken string
RefreshToken string
ExpiresAt int64
}
func NewAuthService(
userRepo *domain.UserRepo,
sessionRepo *domain.SessionRepo,
challengeExp uint,
tokenExp uint,
refreshTokenExp uint) AuthService {
return &authService{
userRepo: userRepo,
sessionRepo: sessionRepo,
challengeExp: challengeExp,
tokenExp: tokenExp,
refreshTokenExp: refreshTokenExp,
}
}
func (s *authService) GenerateChallenge(ctx context.Context, pubKey string) (*domain.Challenge, error) {
if !common.IsHexAddress(pubKey) {
return nil, domain.ErrWalletInvalid
}
challenge := &domain.Challenge{
Message: uuid.New(),
TimeStamp: time.Now().UTC(),
ExpiresAt: time.Now().Add(time.Duration(s.challengeExp) * time.Minute),
}
return challenge, nil
}
func (s *authService) Authenticate(ctx context.Context, pubKey string, signature string, challenge *domain.Challenge, chainID uint) (*UserToken, error) {
return nil, nil
}