Skip to content

Commit

Permalink
feat: Implement service worker for IPFS vault
Browse files Browse the repository at this point in the history
  • Loading branch information
prnk28 committed Oct 8, 2024
1 parent fa7b111 commit c608a06
Show file tree
Hide file tree
Showing 34 changed files with 740 additions and 758 deletions.
49 changes: 27 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,45 +289,50 @@ testnet-basic: setup-testnet
sh-testnet: mod-tidy
CHAIN_ID="sonr-testnet-1" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh

.PHONY: setup-testnet set-testnet-configs testnet testnet-basic sh-testnet
start-hway: hway
@echo "(start-proxy) Starting proxy server"
./build/hway start

.PHONY: setup-testnet set-testnet-configs testnet testnet-basic sh-testnet start-hway


###############################################################################
### templ & vault ###
### custom generation ###
###############################################################################

.PHONY: build-motr build-hway gen-templ gen-pkl build-nebula

build-hway:
@echo "(motr) Building Highway gateway"
go build -o ./build/hway ./cmd/hway

build-motr:
@echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault"
GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./cmd/motr/motr.go
.PHONY: gen-templ gen-pkl

gen-templ:
@echo "(templ) Generating templ files"
templ generate

build-nebula:
@echo "(nebula) Building nebula"
cd pkg/nebula && bun run build
templ generate

gen-pkl:
@echo "(pkl) Building PKL"
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/DWN.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/ORM.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/Txns.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/UIUX.pkl

start-caddy:
@echo "(start-caddy) Starting caddy"
./build/caddy run --config ./config/caddy/Caddyfile

start-hway: hway
@echo "(start-proxy) Starting proxy server"
./build/hway start

###############################################################################
### motr, hway & nebula ###
###############################################################################

.PHONY: build-motr build-hway build-nebula

build-hway: gen-templ gen-pkl
@echo "(motr) Building Highway gateway"
go build -o ./build/hway ./cmd/hway

build-motr: gen-templ gen-pkl
@echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault"
GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./cmd/motr/motr.go

build-nebula:
@echo "(nebula) Building nebula"
cd pkg/nebula && bun run build


###############################################################################
### help ###
Expand Down
25 changes: 11 additions & 14 deletions cmd/motr/motr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/labstack/echo/v4"
promise "github.com/nlepage/go-js-promise"

"github.com/onsonr/sonr/cmd/motr/state"
"github.com/onsonr/sonr/internal/session"
"github.com/onsonr/sonr/pkg/nebula/router"
"github.com/onsonr/sonr/pkg/nebula/routes"
"github.com/onsonr/sonr/pkg/nebula/worker"
)

func main() {
Expand All @@ -30,21 +30,18 @@ func main() {

func registerState(e *echo.Echo) {
g := e.Group("state")
g.POST("/login/:identifier", state.HandleCredentialAssertion)
// g.GET("/discovery", state.GetDiscovery)
g.GET("/jwks", state.GetJWKS)
g.GET("/token", state.GetToken)
g.POST("/:origin/grant/:subject", state.GrantAuthorization)
g.POST("/register/:subject", state.HandleCredentialCreation)
g.POST("/register/:subject/check", state.CheckSubjectIsValid)
g.POST("/login/:identifier", worker.HandleCredentialAssertion)
g.GET("/jwks", worker.GetJWKS)
g.GET("/token", worker.GetToken)
g.POST("/:origin/grant/:subject", worker.GrantAuthorization)
g.POST("/register/:subject", worker.HandleCredentialCreation)
g.POST("/register/:subject/check", worker.CheckSubjectIsValid)
}

func registerViews(e *echo.Echo) {
e.GET("/home", router.Home)
e.GET("/login", router.Login)
e.GET("/register", router.Register)
e.GET("/profile", router.Profile)
e.GET("/authorize", router.Authorize)
e.GET("/home", routes.Home)
e.GET("/login", routes.LoginStart)
e.GET("/register", routes.RegisterStart)
}

// Serve serves HTTP requests using handler or http.DefaultServeMux if handler is nil.
Expand Down
1 change: 0 additions & 1 deletion cmd/motr/state/manifest.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/motr/state/wellknown.go

This file was deleted.

16 changes: 4 additions & 12 deletions pkg/dwn/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
_ "embed"
"encoding/json"

"github.com/a-h/templ"
"github.com/ipfs/boxo/files"
"github.com/onsonr/sonr/pkg/nebula/global"
)

//go:embed app.wasm
Expand All @@ -28,12 +28,8 @@ func NewVaultDirectory(cnfg *Config) (files.Node, error) {
return nil, err
}

dwnStr, err := templ.JSONString(cnfg)
if err != nil {
return nil, err
}
w := bytes.NewBuffer(nil)
err = indexFile(dwnStr).Render(context.Background(), w)
err = global.IndexFile().Render(context.Background(), w)
if err != nil {
return nil, err
}
Expand All @@ -47,13 +43,9 @@ func NewVaultDirectory(cnfg *Config) (files.Node, error) {
}

// Use IndexHTML template to generate the index file
func IndexHTMLFile(c *Config) (files.Node, error) {
str, err := templ.JSONString(c)
if err != nil {
return nil, err
}
func IndexHTMLFile() (files.Node, error) {
w := bytes.NewBuffer(nil)
err = indexFile(str).Render(context.Background(), w)
err := global.IndexFile().Render(context.Background(), w)
if err != nil {
return nil, err
}
Expand Down
104 changes: 0 additions & 104 deletions pkg/dwn/index.templ

This file was deleted.

Loading

0 comments on commit c608a06

Please sign in to comment.