feature/refactor did state (#10)

* feat(did): remove account types

* feat: Refactor Property to Proof in zkprop.go

* feat: add ZKP proof mechanism for verifications

* fix: return bool and error from pinInitialVault

* feat: implement KeyshareSet for managing user and validator keyshares

* feat: Update Credential type in protobuf

* feat: update credential schema with sign count

* feat: migrate  and  modules to middleware

* refactor: rename vault module to ORM

* chore(dwn): add service worker registration to index template

* feat: integrate service worker for offline functionality

* refactor(did): use DIDNamespace enum for verification method in proto reflection

* refactor: update protobuf definitions to support Keyshare

* feat: expose did keeper in app keepers

* Add Motr Web App

* refactor: rename motr/handlers/discovery.go to motr/handlers/openid.go

* refactor: move session related code to middleware

* feat: add database operations for managing assets, chains, and credentials

* feat: add htmx support for UI updates

* refactor: extract common helper scripts

* chore: remove unused storage GUI components

* refactor: Move frontend rendering to dedicated handlers

* refactor: rename  to

* refactor: move alert implementation to templ

* feat: add alert component with icon, title, and message

* feat: add new RequestHeaders struct to store request headers

* Feature/create home view (#9)

* refactor: move view logic to new htmx handler

* refactor: remove unnecessary dependencies

* refactor: remove unused dependencies

* feat(devbox): integrate air for local development

* feat: implement openid connect discovery document

* refactor: rename  to

* refactor(did): update service handling to support DNS discovery

* feat: add support for user and validator keyshares

* refactor: move keyshare signing logic to signer
This commit is contained in:
Prad Nukala
2024-09-11 15:10:54 -04:00
committed by GitHub
parent 4f2d342649
commit bbfe2a2329
197 changed files with 14668 additions and 27810 deletions
+90 -15
View File
@@ -7,37 +7,112 @@ import (
"errors"
"github.com/labstack/echo/v4"
wasmhttp "github.com/nlepage/go-wasm-http-server"
"github.com/onsonr/sonr/internal/vfs/wasm"
"github.com/donseba/go-htmx"
"github.com/onsonr/sonr/internal/db"
)
var edb *db.DB
var dwn *DWN
func main() {
// Initialize the database
initDB()
e := echo.New()
e.POST("/api/insert/:account/:address", itemsHandler)
wasmhttp.Serve(e)
type DWN struct {
*echo.Echo
DB *db.DB
Htmx *htmx.HTMX
}
func initDB() {
var err error
edb, err = db.Open(db.New())
func main() {
dwn = initRails()
dwn.GET("/", htmxHandler)
dwn.POST("/accounts", accountsHandler)
wasm.Serve(dwn.Echo)
}
// initRails initializes the Rails application
func initRails() *DWN {
// Open the database
cnfg := db.New()
db, err := cnfg.Open()
if err != nil {
panic(err.Error())
}
// Initialize the htmx handler
return &DWN{
Echo: echo.New(),
DB: db,
Htmx: htmx.New(),
}
}
func itemsHandler(e echo.Context) error {
func accountsHandler(e echo.Context) error {
switch e.Request().Method {
case "GET":
case "POST":
edb.AddAccount(e.Param("account"), e.Param("address"))
case "PUT":
// dwn.DB.AddAccount(e.Param("account"), e.Param("address"))
default:
e.Error(errors.New("Method not allowed"))
}
return e.JSON(200, "OK")
}
func htmxHandler(e echo.Context) error {
// initiate a new htmx handler
h := dwn.Htmx.NewHandler(e.Response(), e.Request())
// check if the request is a htmx request
if h.IsHxRequest() {
// do something
}
// check if the request is boosted
if h.IsHxBoosted() {
// do something
}
// check if the request is a history restore request
if h.IsHxHistoryRestoreRequest() {
// do something
}
// check if the request is a prompt request
if h.RenderPartial() {
// do something
}
// set the headers for the response, see docs for more options
h.PushURL("http://push.url")
h.ReTarget("#ReTarged")
// write the output like you normally do.
// check the inspector tool in the browser to see that the headers are set.
_, err := h.Write([]byte("OK"))
return err
}
//
// func credentialsHandler(e echo.Context) error {
// switch e.Request().Method {
// case "GET":
// dwn.DB.GetCredentials(e.Param("account"))
// case "PUT":
// dwn.DB.AddCredentials(e.Param("account"), e.Param("address"))
// default:
// e.Error(errors.New("Method not allowed"))
// }
// return e.JSON(200, "OK")
// }
//
// func keysharesHandler(e echo.Context) error {
// switch e.Request().Method {
// case "GET":
// dwn.DB.GetKeyshares(e.Param("account"))
// case "PUT":
// dwn.DB.AddKeyshares(e.Param("account"), e.Param("address"))
// default:
// e.Error(errors.New("Method not allowed"))
// }
// return e.JSON(200, "OK")
// }