mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
refactor: move vault package to app directory
This commit is contained in:
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GrantAuthorization(e echo.Context) error {
|
||||
// Implement authorization endpoint using passkey authentication
|
||||
// Store session data in cache
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetJWKS(e echo.Context) error {
|
||||
// Implement token endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetToken(e echo.Context) error {
|
||||
// Implement token endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import "github.com/labstack/echo/v4"
|
||||
|
||||
func HandleConnect(c echo.Context) error {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// ╭───────────────────────────────────────────────────────────╮
|
||||
// │ Login Handlers │
|
||||
// ╰───────────────────────────────────────────────────────────╯
|
||||
|
||||
// LoginSubjectCheck handles the login subject check.
|
||||
func LoginSubjectCheck(e echo.Context) error {
|
||||
return e.JSON(200, "HandleCredentialAssertion")
|
||||
}
|
||||
|
||||
// LoginSubjectStart handles the login subject start.
|
||||
func LoginSubjectStart(e echo.Context) error {
|
||||
opts := &protocol.PublicKeyCredentialRequestOptions{
|
||||
UserVerification: "preferred",
|
||||
Challenge: []byte("challenge"),
|
||||
}
|
||||
return e.JSON(200, opts)
|
||||
}
|
||||
|
||||
// LoginSubjectFinish handles the login subject finish.
|
||||
func LoginSubjectFinish(e echo.Context) error {
|
||||
var crr protocol.CredentialAssertionResponse
|
||||
if err := e.Bind(&crr); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.JSON(200, crr)
|
||||
}
|
||||
|
||||
// ╭───────────────────────────────────────────────────────────╮
|
||||
// │ Register Handlers │
|
||||
// ╰───────────────────────────────────────────────────────────╯
|
||||
|
||||
// RegisterSubjectCheck handles the register subject check.
|
||||
func RegisterSubjectCheck(e echo.Context) error {
|
||||
subject := e.FormValue("subject")
|
||||
return e.JSON(200, subject)
|
||||
}
|
||||
|
||||
// RegisterSubjectStart handles the register subject start.
|
||||
func RegisterSubjectStart(e echo.Context) error {
|
||||
// Get subject and address
|
||||
// subject := e.FormValue("subject")
|
||||
|
||||
// Get challenge
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterSubjectFinish handles the register subject finish.
|
||||
func RegisterSubjectFinish(e echo.Context) error {
|
||||
// Deserialize the JSON into a temporary struct
|
||||
var ccr protocol.CredentialCreationResponse
|
||||
if err := e.Bind(&ccr); err != nil {
|
||||
return err
|
||||
}
|
||||
//
|
||||
// // Parse the CredentialCreationResponse
|
||||
// parsedData, err := ccr.Parse()
|
||||
// if err != nil {
|
||||
// return e.JSON(500, err.Error())
|
||||
// }
|
||||
//
|
||||
// // Create the Credential
|
||||
// // credential := orm.NewCredential(parsedData, e.Request().Host, "")
|
||||
return e.JSON(201, ccr)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func HandleDash(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "index.templ", nil)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
session "github.com/onsonr/sonr/app/vault/internal"
|
||||
"github.com/onsonr/sonr/app/vault/internal/pages/index"
|
||||
"github.com/onsonr/sonr/pkg/common/response"
|
||||
)
|
||||
|
||||
func HandleIndex(c echo.Context) error {
|
||||
if isInitial(c) {
|
||||
return response.TemplEcho(c, index.InitialView())
|
||||
}
|
||||
if isExpired(c) {
|
||||
return response.TemplEcho(c, index.ReturningView())
|
||||
}
|
||||
return c.Render(http.StatusOK, "index.templ", nil)
|
||||
}
|
||||
|
||||
// ╭─────────────────────────────────────────────────────────╮
|
||||
// │ Utility Functions │
|
||||
// ╰─────────────────────────────────────────────────────────╯
|
||||
|
||||
// Initial users have no authorization, user handle, or vault address
|
||||
func isInitial(c echo.Context) bool {
|
||||
noAuth := !session.HasAuthorization(c)
|
||||
noUserHandle := !session.HasUserHandle(c)
|
||||
noVaultAddress := !session.HasVaultAddress(c)
|
||||
return noUserHandle && noVaultAddress && noAuth
|
||||
}
|
||||
|
||||
// Expired users have either a user handle or vault address
|
||||
func isExpired(c echo.Context) bool {
|
||||
noAuth := !session.HasAuthorization(c)
|
||||
hasUserHandle := session.HasUserHandle(c)
|
||||
hasVaultAddress := session.HasVaultAddress(c)
|
||||
return noAuth && hasUserHandle || noAuth && hasVaultAddress
|
||||
}
|
||||
|
||||
// Returning users have a valid authorization, and either a user handle or vault address
|
||||
func isReturning(c echo.Context) bool {
|
||||
hasAuth := session.HasAuthorization(c)
|
||||
hasUserHandle := session.HasUserHandle(c)
|
||||
hasVaultAddress := session.HasVaultAddress(c)
|
||||
return hasAuth && (hasUserHandle || hasVaultAddress)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1,93 @@
|
||||
package handlers
|
||||
|
||||
//
|
||||
// // Constants for supported payment methods
|
||||
// const (
|
||||
// MethodCard = "basic-card"
|
||||
// MethodGooglePay = "https://google.com/pay"
|
||||
// MethodApplePay = "https://apple.com/apple-pay"
|
||||
// MethodSonrWallet = "https://sonr.id/wallet"
|
||||
// )
|
||||
//
|
||||
// // InitiatePayment starts the payment request flow
|
||||
// func InitiatePayment(c echo.Context, request PaymentRequest) error {
|
||||
// return StartPayment(request).Render(c.Request().Context(), c.Response().Writer)
|
||||
// }
|
||||
//
|
||||
// // Helper functions to create payment requests
|
||||
// func NewBasicCardPayment(amount float64, currency string, label string) PaymentRequest {
|
||||
// return PaymentRequest{
|
||||
// MethodData: []PaymentMethodData{
|
||||
// {
|
||||
// SupportedMethods: MethodCard,
|
||||
// Data: map[string]any{
|
||||
// "supportedNetworks": []string{"visa", "mastercard"},
|
||||
// "supportedTypes": []string{"credit", "debit"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Details: PaymentDetails{
|
||||
// Total: PaymentItem{
|
||||
// Label: label,
|
||||
// Amount: Money{
|
||||
// Currency: currency,
|
||||
// Value: formatAmount(amount),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Options: PaymentOptions{
|
||||
// RequestPayerName: true,
|
||||
// RequestPayerEmail: true,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Example usage:
|
||||
// func PaymentHandler(c echo.Context) error {
|
||||
// request := NewBasicCardPayment(99.99, "USD", "Product Purchase")
|
||||
//
|
||||
// // Add display items
|
||||
// request.Details.DisplayItems = []PaymentItem{
|
||||
// {
|
||||
// Label: "Product Price",
|
||||
// Amount: Money{
|
||||
// Currency: "USD",
|
||||
// Value: "89.99",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Label: "Tax",
|
||||
// Amount: Money{
|
||||
// Currency: "USD",
|
||||
// Value: "10.00",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// // Add shipping options
|
||||
// request.Details.ShippingOptions = []ShippingOption{
|
||||
// {
|
||||
// ID: "standard",
|
||||
// Label: "Standard Shipping",
|
||||
// Amount: Money{
|
||||
// Currency: "USD",
|
||||
// Value: "0.00",
|
||||
// },
|
||||
// Selected: true,
|
||||
// },
|
||||
// {
|
||||
// ID: "express",
|
||||
// Label: "Express Shipping",
|
||||
// Amount: Money{
|
||||
// Currency: "USD",
|
||||
// Value: "10.00",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// return InitiatePayment(c, request)
|
||||
// }
|
||||
//
|
||||
// func formatAmount(amount float64) string {
|
||||
// return fmt.Sprintf("%.2f", amount)
|
||||
// }
|
||||
Reference in New Issue
Block a user