Update
CI / test (push) Successful in 4s

This commit is contained in:
2026-03-02 21:21:21 +00:00
parent 184c5cb59f
commit 6c26135cad
15 changed files with 206 additions and 13 deletions
+8 -2
View File
@@ -81,7 +81,7 @@ func (s *Service) RegisterBySignature(publicKey, signature string) error {
return nil
}
func (s *Service) CreateChallenge(publicKey string) (string, error) {
func (s *Service) CreateChallenge(publicKey, clientIP string) (string, error) {
if publicKey == "" {
return "", fmt.Errorf("%w: missing public key", ErrBadRequest)
}
@@ -93,6 +93,7 @@ func (s *Service) CreateChallenge(publicKey string) (string, error) {
err = s.store.CreateChallenge(store.Challenge{
Nonce: nonce,
PublicKey: publicKey,
IP: clientIP,
ExpiresAt: time.Now().UTC().Add(s.config.ChallengeTTL),
Used: false,
})
@@ -102,7 +103,7 @@ func (s *Service) CreateChallenge(publicKey string) (string, error) {
return nonce, nil
}
func (s *Service) Login(publicKey, nonce, signature string) (string, error) {
func (s *Service) Login(publicKey, nonce, signature, clientIP string) (string, error) {
ch, err := s.store.GetChallenge(nonce)
if err != nil {
return "", fmt.Errorf("%w: challenge not found", ErrUnauthorized)
@@ -132,6 +133,11 @@ func (s *Service) Login(publicKey, nonce, signature string) (string, error) {
PublicKey: publicKey,
ExpiresAt: time.Now().UTC().Add(s.config.SessionTTL),
})
s.store.SaveUserLogin(store.UserLogin{
PublicKey: publicKey,
IP: clientIP,
CreatedAt: time.Now().UTC(),
})
return token, nil
}