From 0d65ad45bbb8ddb83ac07dfd8cc8437228db8d76 Mon Sep 17 00:00:00 2001 From: arzumify Date: Wed, 8 Jan 2025 14:18:25 +0000 Subject: [PATCH] Added helper functions --- go.mod | 7 ++++++- go.sum | 4 ++++ main.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c08fdb8..404741b 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,9 @@ module git.ailur.dev/ailur/fg-nucleus-library go 1.23.3 -require github.com/google/uuid v1.6.0 +require ( + git.ailur.dev/ailur/fg-library/v3 v3.5.0 + github.com/google/uuid v1.6.0 +) + +require github.com/go-chi/chi/v5 v5.2.0 // indirect diff --git a/go.sum b/go.sum index 7790d7c..1c81f82 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,6 @@ +git.ailur.dev/ailur/fg-library/v3 v3.5.0 h1:BGDlS4nQ2PyZWNU4gH3eckVqhZUFIM/zKIj/HXx8RmA= +git.ailur.dev/ailur/fg-library/v3 v3.5.0/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= +github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0= +github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/main.go b/main.go index f5dd187..0a76f8c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,10 @@ package library import ( + "crypto/ed25519" + library "git.ailur.dev/ailur/fg-library/v3" "github.com/google/uuid" + "time" ) type OAuthInformation struct { @@ -27,3 +30,54 @@ type Quota struct { User uuid.UUID `validate:"required"` Bytes int64 `validate:"required"` } + +var ( + StorageService = uuid.MustParse("00000000-0000-0000-0000-000000000003") + OAuthService = uuid.MustParse("00000000-0000-0000-0000-000000000004") +) + +func OAuthSignup(oauth OAuthInformation, information library.ServiceInitializationInformation) (OAuthResponse, error) { + message, err := information.SendAndAwaitISMessage(OAuthService, 1, oauth, time.Second*3) + if err != nil { + return OAuthResponse{}, err + } + + return message.Message.(OAuthResponse), nil + +} + +func GetPublicKey(information library.ServiceInitializationInformation) (ed25519.PublicKey, error) { + message, err := information.SendAndAwaitISMessage(OAuthService, 2, nil, time.Second*3) + if err != nil { + return nil, err + } + + return message.Message.(ed25519.PublicKey), nil +} + +func GetOAuthHostname(information library.ServiceInitializationInformation) (string, error) { + message, err := information.SendAndAwaitISMessage(OAuthService, 0, nil, time.Second*3) + if err != nil { + return "", err + } + + return message.Message.(string), nil +} + +func InitializeOAuth(oauth OAuthInformation, information library.ServiceInitializationInformation) (oauthResponse OAuthResponse, pk ed25519.PublicKey, hostname string, err error) { + pk, err = GetPublicKey(information) + if err != nil { + return + } + hostname, err = GetOAuthHostname(information) + if err != nil { + return + } + + oauthResponse, err = OAuthSignup(oauth, information) + if err != nil { + return + } + + return +}