implemented getting user from signature
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user