implemented getting user from signature

This commit is contained in:
Hazel Noack
2025-06-27 15:33:12 +02:00
parent 885aefc96c
commit 5f63d7385d
4 changed files with 57 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
package game
import (
"crypto/ed25519"
"encoding/base64"
petname "github.com/dustinkirkland/golang-petname"
)
@@ -37,3 +40,15 @@ func GetSession(name string) *Session {
func (s *Session) AddUser(user User) {
s.Users = append(s.Users, user)
}
func (s Session) VerifySignature(signature string, message []byte) *User {
for _, u := range s.Users {
sig, _ := base64.StdEncoding.DecodeString(signature)
if ed25519.Verify(u.PublicKey, message, sig) {
return &u
}
}
return nil
}