Files
sonr/internal/gateway/handlers/register/handlers.go
T

50 lines
1.3 KiB
Go

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 {
d := randomCreateProfileData()
return response.TemplEcho(c, ProfileFormView(d))
}
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())
}