diff --git a/internal/gateway/handlers/index/handlers.go b/internal/gateway/handlers/index/handlers.go new file mode 100644 index 000000000..1a56d8aa0 --- /dev/null +++ b/internal/gateway/handlers/index/handlers.go @@ -0,0 +1,13 @@ +package index + +import ( + "github.com/labstack/echo/v4" + "github.com/onsonr/sonr/pkg/common/response" +) + +func Handler(c echo.Context) error { + if isExpired(c) { + return response.TemplEcho(c, ReturningView()) + } + return response.TemplEcho(c, InitialView()) +} diff --git a/internal/gateway/handlers/index_handler.go b/internal/gateway/handlers/index/model.go similarity index 54% rename from internal/gateway/handlers/index_handler.go rename to internal/gateway/handlers/index/model.go index 6b62a0c9b..10d691bc3 100644 --- a/internal/gateway/handlers/index_handler.go +++ b/internal/gateway/handlers/index/model.go @@ -1,23 +1,10 @@ -package handlers +package index import ( "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/internal/gateway/pages/index" "github.com/onsonr/sonr/internal/gateway/session" - "github.com/onsonr/sonr/pkg/common/response" ) -func HandleIndex(c echo.Context) error { - if isExpired(c) { - return response.TemplEcho(c, index.ReturningView()) - } - return response.TemplEcho(c, index.InitialView()) -} - -// ╭─────────────────────────────────────────────────────────╮ -// │ Utility Functions │ -// ╰─────────────────────────────────────────────────────────╯ - // Initial users have no authorization, user handle, or vault address func isInitial(c echo.Context) bool { sess, err := session.Get(c) diff --git a/internal/gateway/pages/index/page.templ b/internal/gateway/handlers/index/views.templ similarity index 100% rename from internal/gateway/pages/index/page.templ rename to internal/gateway/handlers/index/views.templ diff --git a/internal/gateway/pages/index/page_templ.go b/internal/gateway/handlers/index/views_templ.go similarity index 100% rename from internal/gateway/pages/index/page_templ.go rename to internal/gateway/handlers/index/views_templ.go diff --git a/internal/gateway/handlers/register/forms.templ b/internal/gateway/handlers/register/forms.templ new file mode 100644 index 000000000..c7a320fb3 --- /dev/null +++ b/internal/gateway/handlers/register/forms.templ @@ -0,0 +1,189 @@ +package register + +import "github.com/onsonr/sonr/pkg/common/styles/layout" + +templ formCreateProfile(action string, method string, data CreateProfileData) { +
+} + +templ formRegisterPasskey(action, method string, data RegisterPasskeyData) { + +} + +templ formRegisterPasskey(action, method string, data RegisterPasskeyData) { + +} diff --git a/internal/gateway/handlers/register/forms_templ.go b/internal/gateway/handlers/register/forms_templ.go new file mode 100644 index 000000000..d3611269d --- /dev/null +++ b/internal/gateway/handlers/register/forms_templ.go @@ -0,0 +1,369 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.793 +package register + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import "github.com/onsonr/sonr/pkg/common/styles/layout" + +func formCreateProfile(action string, method string, data CreateProfileData) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func formRegisterPasskey(action, method string, data RegisterPasskeyData) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func formRegisterPasskey(action, method string, data RegisterPasskeyData) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +var _ = templruntime.GeneratedTemplate diff --git a/internal/gateway/handlers/register/handlers.go b/internal/gateway/handlers/register/handlers.go new file mode 100644 index 000000000..4592c414a --- /dev/null +++ b/internal/gateway/handlers/register/handlers.go @@ -0,0 +1,52 @@ +package register + +import ( + "fmt" + "net/http" + + "github.com/go-webauthn/webauthn/protocol" + "github.com/labstack/echo/v4" + "github.com/onsonr/sonr/crypto/mpc" + "github.com/onsonr/sonr/pkg/common/response" +) + +func HandleCreateProfile(c echo.Context) error { + dat := CreateProfileData{ + FirstNumber: 1, + LastNumber: 2, + } + return response.TemplEcho(c, ProfileFormView(dat)) +} + +func HandlePasskeyStart(c echo.Context) error { + challenge, _ := protocol.CreateChallenge() + handle := c.FormValue("handle") + firstName := c.FormValue("first_name") + lastName := c.FormValue("last_name") + + ks, err := mpc.NewKeyset() + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + dat := RegisterPasskeyData{ + Address: ks.Address(), + Handle: handle, + Name: fmt.Sprintf("%s %s", firstName, lastName), + Challenge: challenge.String(), + CreationBlock: "00001", + } + return response.TemplEcho(c, LinkCredentialView(dat)) +} + +func HandlePasskeyFinish(c echo.Context) error { + // Get the raw credential JSON string + credentialJSON := c.FormValue("credential") + if credentialJSON == "" { + return echo.NewHTTPError(http.StatusBadRequest, "missing credential data") + } + _, err := extractCredentialDescriptor(credentialJSON) + if err != nil { + return err + } + return response.TemplEcho(c, LoadingVaultView()) +} diff --git a/internal/gateway/pages/register/creds.templ b/internal/gateway/handlers/register/inputs.templ similarity index 62% rename from internal/gateway/pages/register/creds.templ rename to internal/gateway/handlers/register/inputs.templ index 03f868385..e5bc0f8b3 100644 --- a/internal/gateway/pages/register/creds.templ +++ b/internal/gateway/handlers/register/inputs.templ @@ -1,76 +1,5 @@ package register -type RegisterPasskeyData struct { - Address string - Handle string - Name string - Challenge string - CreationBlock string -} - -templ formRegisterPasskey(action, method string, data RegisterPasskeyData) { - -} templ passkeyDropzone(addr string, userHandle string, challenge string) {") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var7 string - templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(handle) + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(handle) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 173, Col: 43} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 102, Col: 43} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -314,12 +179,12 @@ func sonrProfile(addr string, name string, handle string, creationBlock string) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(shortenAddress(addr)) + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(shortenAddress(addr)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 180, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 109, Col: 58} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -327,12 +192,12 @@ func sonrProfile(addr string, name string, handle string, creationBlock string) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(creationBlock) + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(creationBlock) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 185, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 114, Col: 55} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -340,12 +205,12 @@ func sonrProfile(addr string, name string, handle string, creationBlock string) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var10 string - templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(name) + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 189, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 118, Col: 32} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -373,9 +238,9 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var11 := templ.GetChildren(ctx) - if templ_7745c5c3_Var11 == nil { - templ_7745c5c3_Var11 = templ.NopComponent + templ_7745c5c3_Var8 := templ.GetChildren(ctx) + if templ_7745c5c3_Var8 == nil { + templ_7745c5c3_Var8 = templ.NopComponent } ctx = templ.ClearChildren(ctx) if isDefault { @@ -383,12 +248,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var12 string - templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 198, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 127, Col: 27} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -396,12 +261,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var13 string - templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) + var templ_7745c5c3_Var10 string + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 199, Col: 39} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 128, Col: 39} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -409,12 +274,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var14 string - templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(name) + var templ_7745c5c3_Var11 string + templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 200, Col: 9} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 129, Col: 9} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -427,12 +292,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var15 string - templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 204, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 133, Col: 27} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -440,12 +305,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var16 string - templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) + var templ_7745c5c3_Var13 string + templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(ticker) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 205, Col: 39} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 134, Col: 39} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -453,12 +318,12 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var17 string - templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(name) + var templ_7745c5c3_Var14 string + templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/pages/register/creds.templ`, Line: 206, Col: 9} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/gateway/handlers/register/inputs.templ`, Line: 135, Col: 9} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -471,12 +336,4 @@ func cryptoWalletOption(ticker string, name string, isDefault bool) templ.Compon }) } -// Helper function to shorten address -func shortenAddress(address string) string { - if len(address) <= 20 { - return address - } - return address[:16] + "..." + address[len(address)-4:] -} - var _ = templruntime.GeneratedTemplate diff --git a/internal/gateway/handlers/register/model.go b/internal/gateway/handlers/register/model.go new file mode 100644 index 000000000..8172118b1 --- /dev/null +++ b/internal/gateway/handlers/register/model.go @@ -0,0 +1,72 @@ +package register + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/labstack/echo/v4" + "github.com/onsonr/sonr/internal/gateway/database" +) + +type CreateProfileData struct { + TurnstileSiteKey string + FirstNumber int + LastNumber int +} + +type RegisterPasskeyData struct { + Address string + Handle string + Name string + Challenge string + CreationBlock string +} + +// Helper function to shorten address +func shortenAddress(address string) string { + if len(address) <= 20 { + return address + } + return address[:16] + "..." + address[len(address)-4:] +} + +func (d CreateProfileData) IsHumanLabel() string { + return fmt.Sprintf("What is %d + %d?", d.FirstNumber, d.LastNumber) +} + +func extractCredentialDescriptor(jsonString string) (*database.Credential, error) { + cred := &database.Credential{} + // Unmarshal the credential JSON + if err := json.Unmarshal([]byte(jsonString), cred); err != nil { + return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("invalid credential format: %v", err)) + } + + // Validate required fields + if cred.ID == "" || cred.RawID == "" { + return nil, echo.NewHTTPError(http.StatusBadRequest, "missing credential ID") + } + if cred.Type != "public-key" { + return nil, echo.NewHTTPError(http.StatusBadRequest, "invalid credential type") + } + if cred.Response.AttestationObject == "" || cred.Response.ClientDataJSON == "" { + return nil, echo.NewHTTPError(http.StatusBadRequest, "missing attestation data") + } + + // Log detailed credential information + fmt.Printf("Credential Details:\n"+ + "ID: %s\n"+ + "Raw ID: %s\n"+ + "Type: %s\n"+ + "Authenticator Attachment: %s\n"+ + "Transports: %v\n"+ + "Attestation Object Size: %d bytes\n"+ + "Client Data Size: %d bytes\n", + cred.ID, + cred.RawID, + cred.Type, + cred.AuthenticatorAttachment, + cred.Transports, + ) + return cred, nil +} diff --git a/internal/gateway/pages/register/page.templ b/internal/gateway/handlers/register/views.templ similarity index 100% rename from internal/gateway/pages/register/page.templ rename to internal/gateway/handlers/register/views.templ diff --git a/internal/gateway/pages/register/page_templ.go b/internal/gateway/handlers/register/views_templ.go similarity index 100% rename from internal/gateway/pages/register/page_templ.go rename to internal/gateway/handlers/register/views_templ.go diff --git a/internal/gateway/handlers/register_handler.go b/internal/gateway/handlers/register_handler.go deleted file mode 100644 index c398121c8..000000000 --- a/internal/gateway/handlers/register_handler.go +++ /dev/null @@ -1,97 +0,0 @@ -package handlers - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "net/http" - - "github.com/go-webauthn/webauthn/protocol" - "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/crypto/mpc" - "github.com/onsonr/sonr/internal/gateway/database" - "github.com/onsonr/sonr/internal/gateway/pages/register" - "github.com/onsonr/sonr/pkg/common/response" -) - -func HandleRegisterView(c echo.Context) error { - dat := register.CreateProfileData{ - FirstNumber: 1, - LastNumber: 2, - } - return response.TemplEcho(c, register.ProfileFormView(dat)) -} - -func HandleRegisterStart(c echo.Context) error { - challenge, _ := protocol.CreateChallenge() - handle := c.FormValue("handle") - firstName := c.FormValue("first_name") - lastName := c.FormValue("last_name") - - ks, err := mpc.NewKeyset() - if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) - } - dat := register.RegisterPasskeyData{ - Address: ks.Address(), - Handle: handle, - Name: fmt.Sprintf("%s %s", firstName, lastName), - Challenge: challenge.String(), - CreationBlock: "00001", - } - return response.TemplEcho(c, register.LinkCredentialView(dat)) -} - -func HandleRegisterFinish(c echo.Context) error { - // Get the raw credential JSON string - credentialJSON := c.FormValue("credential") - if credentialJSON == "" { - return echo.NewHTTPError(http.StatusBadRequest, "missing credential data") - } - cred := database.Credential{} - // Unmarshal the credential JSON - if err := json.Unmarshal([]byte(credentialJSON), &cred); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("invalid credential format: %v", err)) - } - - // Validate required fields - if cred.ID == "" || cred.RawID == "" { - return echo.NewHTTPError(http.StatusBadRequest, "missing credential ID") - } - if cred.Type != "public-key" { - return echo.NewHTTPError(http.StatusBadRequest, "invalid credential type") - } - if cred.Response.AttestationObject == "" || cred.Response.ClientDataJSON == "" { - return echo.NewHTTPError(http.StatusBadRequest, "missing attestation data") - } - - // Decode attestation object and client data - attestationObj, err := base64.RawURLEncoding.DecodeString(cred.Response.AttestationObject) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "invalid attestation object encoding") - } - - clientData, err := base64.RawURLEncoding.DecodeString(cred.Response.ClientDataJSON) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "invalid client data encoding") - } - - // Log detailed credential information - fmt.Printf("Credential Details:\n"+ - "ID: %s\n"+ - "Raw ID: %s\n"+ - "Type: %s\n"+ - "Authenticator Attachment: %s\n"+ - "Transports: %v\n"+ - "Attestation Object Size: %d bytes\n"+ - "Client Data Size: %d bytes\n", - cred.ID, - cred.RawID, - cred.Type, - cred.AuthenticatorAttachment, - cred.Transports, - len(attestationObj), - len(clientData)) - - return response.TemplEcho(c, register.LoadingVaultView()) -} diff --git a/internal/gateway/handlers/spawn_handler.go b/internal/gateway/handlers/spawn_handler.go deleted file mode 100644 index 4da1905aa..000000000 --- a/internal/gateway/handlers/spawn_handler.go +++ /dev/null @@ -1,33 +0,0 @@ -package handlers - -// -// type SpawnVaultRequest struct { -// Name string `json:"name"` -// } -// -// func SpawnVault(c echo.Context) error { -// ks, err := mpc.NewKeyset() -// if err != nil { -// return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) -// } -// src, err := mpc.NewSource(ks) -// if err != nil { -// return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) -// } -// tk, err := src.OriginToken() -// if err != nil { -// return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) -// } -// // Create the vault keyshare auth token -// kscid, err := tk.CID() -// if err != nil { -// return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) -// } -// // Create the vault config -// dir, err := config.NewFS(config.GetVaultConfig(src.Address(), kscid.String())) -// path, err := clients.IPFSAdd(c, dir) -// if err != nil { -// return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) -// } -// return c.Redirect(http.StatusFound, path) -// } diff --git a/internal/gateway/pages/index/error.templ b/internal/gateway/pages/index/error.templ deleted file mode 100644 index cdaaabf87..000000000 --- a/internal/gateway/pages/index/error.templ +++ /dev/null @@ -1,29 +0,0 @@ -package index - -import "github.com/onsonr/sonr/pkg/common/styles/layout" - -templ NoWebauthnErrorView() { - @layout.Root("Error | Sonr.ID") { -
- You don't have any WebAuthn devices connected to your computer. -
-You don't have any WebAuthn devices connected to your computer.
- The decentralized identity layer for the web. -
-- Continue with your existing Sonr.ID. -
-The decentralized identity layer for the web.
Continue with your existing Sonr.ID.