From fccb42761c0064953532b52c04f284a02873047e Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Thu, 3 Oct 2024 17:49:29 -0400 Subject: [PATCH] feat: add rudimentary DidController table --- cmd/hway/server/server.go | 1 - devbox.json | 76 +++-------- devbox.lock | 48 +++++++ pkg/nebula/components/home/hero_templ.go | 97 +++++--------- .../components/home/highlights_templ.go | 2 +- pkg/nebula/components/register/modal.templ | 3 +- pkg/nebula/components/register/modal_templ.go | 3 +- pkg/nebula/components/register/view.templ | 24 ++-- pkg/nebula/components/register/view_templ.go | 102 +-------------- pkg/nebula/components/ui/button_templ.go | 121 ++++++++++++++++++ pkg/nebula/models/RegistrationForm.pkl.go | 14 -- pkg/nebula/pages/pages.go | 24 ++++ pkg/nebula/pages/utils.go | 25 ---- x/did/keeper/controller.go | 27 ++++ x/did/keeper/keeper.go | 46 ------- x/macaroon/keeper/issuer.go | 29 +++++ 16 files changed, 309 insertions(+), 333 deletions(-) create mode 100644 pkg/nebula/components/ui/button_templ.go delete mode 100644 pkg/nebula/models/RegistrationForm.pkl.go delete mode 100644 pkg/nebula/pages/utils.go create mode 100644 x/did/keeper/controller.go create mode 100644 x/macaroon/keeper/issuer.go diff --git a/cmd/hway/server/server.go b/cmd/hway/server/server.go index 6dda84461..687a6f196 100644 --- a/cmd/hway/server/server.go +++ b/cmd/hway/server/server.go @@ -29,7 +29,6 @@ func New() *Server { s.GET("/login", pages.Login) s.GET("/register", pages.Register) s.GET("/profile", pages.Profile) - s.GET("/allocate", pages.Profile) return s } diff --git a/devbox.json b/devbox.json index c744e18b6..edf724e51 100644 --- a/devbox.json +++ b/devbox.json @@ -4,6 +4,7 @@ "go@1.22", "air@latest", "bun@latest", + "gum@latest", "ipfs@latest", "skate@latest", "templ@latest", @@ -29,65 +30,22 @@ }, "shell": { "scripts": { - "dev": [ - "air" - ], - "build:docker": [ - "make local-image" - ], - "build:hway": [ - "make nebula", - "make hway" - ], - "build:nebula": [ - "make nebula" - ], - "build:sonrd": [ - "make motr", - "make build" - ], - "build": [ - "make motr", - "make build", - "make hway" - ], - "gen:proto": [ - "make proto-gen" - ], - "gen:pkl": [ - "make pkl" - ], - "gen:templ": [ - "make templ" - ], - "start:hway": [ - "make templ", - "make hway", - "make start-hway" - ], - "start:testnet": [ - "make templ", - "make install", - "make sh-testnet" - ], - "start": [ - "process-compose up -d" - ], - "stop": [ - "process-compose down" - ], - "test:e2e": [ - "make templ", - "make test-e2e" - ], - "test:unit": [ - "make templ", - "make test-unit" - ], - "test": [ - "make templ", - "make test" - ] + "dev": ["air"], + "build:docker": ["make local-image"], + "build:hway": ["make nebula", "make hway"], + "build:nebula": ["make nebula"], + "build:sonrd": ["make motr", "make build"], + "build": ["make motr", "make build", "make hway"], + "gen:proto": ["make proto-gen"], + "gen:pkl": ["make pkl"], + "gen:templ": ["make templ"], + "start:hway": ["make templ", "make hway", "make start-hway"], + "start:testnet": ["make templ", "make install", "make sh-testnet"], + "start": ["process-compose up -d"], + "stop": ["process-compose down"], + "test:e2e": ["make templ", "make test-e2e"], + "test:unit": ["make templ", "make test-unit"], + "test": ["make templ", "make test"] } } } diff --git a/devbox.lock b/devbox.lock index 4d7e30e6d..bbbcf6533 100644 --- a/devbox.lock +++ b/devbox.lock @@ -294,6 +294,54 @@ "store_path": "/nix/store/6zbyhj72wh0645lj6b9c392aqqg11a84-skate-1.0.0" } } + }, + "templ@latest": { + "last_modified": "2024-09-10T15:01:03Z", + "resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#templ", + "source": "devbox-search", + "version": "0.2.778", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/n3yqslisz9v81k4w4vhci1v2bl1sqf9s-templ-0.2.778", + "default": true + } + ], + "store_path": "/nix/store/n3yqslisz9v81k4w4vhci1v2bl1sqf9s-templ-0.2.778" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/i4xjiw0vc25qpr3g01q0x401351w28hr-templ-0.2.778", + "default": true + } + ], + "store_path": "/nix/store/i4xjiw0vc25qpr3g01q0x401351w28hr-templ-0.2.778" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/77w522agb5fgsr36jkifcccr9x4xwkf9-templ-0.2.778", + "default": true + } + ], + "store_path": "/nix/store/77w522agb5fgsr36jkifcccr9x4xwkf9-templ-0.2.778" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/1g5ji5930j03cycpcjy12z6lr24l9c65-templ-0.2.778", + "default": true + } + ], + "store_path": "/nix/store/1g5ji5930j03cycpcjy12z6lr24l9c65-templ-0.2.778" + } + } } } } diff --git a/pkg/nebula/components/home/hero_templ.go b/pkg/nebula/components/home/hero_templ.go index 974fa8734..71f177a45 100644 --- a/pkg/nebula/components/home/hero_templ.go +++ b/pkg/nebula/components/home/hero_templ.go @@ -8,7 +8,10 @@ package home import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "github.com/onsonr/sonr/pkg/nebula/models" +import ( + "github.com/onsonr/sonr/pkg/nebula/components/ui" + "github.com/onsonr/sonr/pkg/nebula/models" +) func SectionHero(hero *models.Hero) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { @@ -38,7 +41,7 @@ func SectionHero(hero *models.Hero) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(hero.TitleFirst) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 14, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 17, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -51,7 +54,7 @@ func SectionHero(hero *models.Hero) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(hero.TitleEmphasis) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 16, Col: 28} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 19, Col: 28} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -64,7 +67,7 @@ func SectionHero(hero *models.Hero) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(hero.TitleSecond) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 21, Col: 25} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 24, Col: 25} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -77,65 +80,25 @@ func SectionHero(hero *models.Hero) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(hero.Subtitle) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 24, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 27, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(hero.PrimaryButton.Href) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 28, Col: 149} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + templ_7745c5c3_Err = ui.PrimaryButton(hero.PrimaryButton.Href, hero.PrimaryButton.Text).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") + templ_7745c5c3_Err = ui.SecondaryButton(hero.SecondaryButton.Href, hero.SecondaryButton.Text).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var7 string - templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(hero.PrimaryButton.Text) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 28, Col: 177} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(hero.SecondaryButton.Text) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/home/hero.templ`, Line: 31, Col: 180} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -171,21 +134,21 @@ func heroImage(hero *models.Hero) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent + 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("

0K

Assets packed with power beyond your imagination.

0K

Assets packed with power beyond your imagination.

0M+

Assets packed with power beyond your imagination.

0K

Assets packed with power beyond your imagination.

") diff --git a/pkg/nebula/components/home/highlights_templ.go b/pkg/nebula/components/home/highlights_templ.go index 93099482b..c00f80c0d 100644 --- a/pkg/nebula/components/home/highlights_templ.go +++ b/pkg/nebula/components/home/highlights_templ.go @@ -29,7 +29,7 @@ func Highlights() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

The Internet Rebuilt for You

Sonr is a comprehensive system for Identity Management which proteects users across their digital personas while providing Developers a cost-effective solution for decentralized authentication.

\"Feature \"Illustration\"
\"Feature \"Illustration\"
\"Feature \"Illustration\"
\"Feature \"Illustration\"
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

The Internet Rebuilt for You

Sonr is a comprehensive system for Identity Management which proteects users across their digital personas while providing Developers a cost-effective solution for decentralized authentication.

\"Feature
\"Feature
\"Feature
\"Feature
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/pkg/nebula/components/register/modal.templ b/pkg/nebula/components/register/modal.templ index e87126118..33e0372f3 100644 --- a/pkg/nebula/components/register/modal.templ +++ b/pkg/nebula/components/register/modal.templ @@ -3,7 +3,6 @@ package register import ( "github.com/labstack/echo/v4" "github.com/onsonr/sonr/pkg/nebula/components/blocks" - "github.com/onsonr/sonr/pkg/nebula/models/formstate" ) templ Modal(c echo.Context) { @@ -47,7 +46,7 @@ templ Modal(c echo.Context) {

Enter your account information below to create your account.

@blocks.Breadcrumbs() - @basicInfoForm(formstate.Initial) + @basicInfoForm() @blocks.Spacer()
diff --git a/pkg/nebula/components/register/modal_templ.go b/pkg/nebula/components/register/modal_templ.go index 75c368787..38f0c23c5 100644 --- a/pkg/nebula/components/register/modal_templ.go +++ b/pkg/nebula/components/register/modal_templ.go @@ -11,7 +11,6 @@ import templruntime "github.com/a-h/templ/runtime" import ( "github.com/labstack/echo/v4" "github.com/onsonr/sonr/pkg/nebula/components/blocks" - "github.com/onsonr/sonr/pkg/nebula/models/formstate" ) func Modal(c echo.Context) templ.Component { @@ -43,7 +42,7 @@ func Modal(c echo.Context) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = basicInfoForm(formstate.Initial).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = basicInfoForm().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/pkg/nebula/components/register/view.templ b/pkg/nebula/components/register/view.templ index cb19f58b3..64bdcbe22 100644 --- a/pkg/nebula/components/register/view.templ +++ b/pkg/nebula/components/register/view.templ @@ -1,19 +1,11 @@ package register -import ( - "github.com/onsonr/sonr/pkg/nebula/components/blocks" - "github.com/onsonr/sonr/pkg/nebula/models/formstate" -) - -templ basicInfoForm(state formstate.FormState) { - switch (state) { - default: -
-
-
-
-
-
-
- } +templ basicInfoForm() { +
+
+
+
+
+
+
} diff --git a/pkg/nebula/components/register/view_templ.go b/pkg/nebula/components/register/view_templ.go index b4fa6d8c4..e29262c8e 100644 --- a/pkg/nebula/components/register/view_templ.go +++ b/pkg/nebula/components/register/view_templ.go @@ -8,13 +8,7 @@ package register import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import ( - "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/pkg/nebula/components/blocks" - "github.com/onsonr/sonr/pkg/nebula/models/formstate" -) - -func View(c echo.Context) templ.Component { +func basicInfoForm() 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 { @@ -35,67 +29,7 @@ func View(c echo.Context) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - 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_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - 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_Err = blocks.Spacer().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = blocks.Breadcrumbs().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = basicInfoForm(formstate.Initial).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = blocks.Spacer().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) - templ_7745c5c3_Err = blocks.Card("register-view", blocks.SizeMedium).Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) - templ_7745c5c3_Err = blocks.Layout("Sonr.ID", true).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -103,36 +37,4 @@ func View(c echo.Context) templ.Component { }) } -func basicInfoForm(state formstate.FormState) 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_Var4 := templ.GetChildren(ctx) - if templ_7745c5c3_Var4 == nil { - templ_7745c5c3_Var4 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - switch state { - default: - _, 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/pkg/nebula/components/ui/button_templ.go b/pkg/nebula/components/ui/button_templ.go new file mode 100644 index 000000000..86b8787f9 --- /dev/null +++ b/pkg/nebula/components/ui/button_templ.go @@ -0,0 +1,121 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.778 +package ui + +//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" + +func PrimaryButton(href string, text string) 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 + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(text) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/ui/button.templ`, Line: 5, Col: 133} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func SecondaryButton(href string, text string) 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_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(text) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/components/ui/button.templ`, Line: 11, Col: 132} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, 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/pkg/nebula/models/RegistrationForm.pkl.go b/pkg/nebula/models/RegistrationForm.pkl.go deleted file mode 100644 index 28fc721cc..000000000 --- a/pkg/nebula/models/RegistrationForm.pkl.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated from Pkl module `models`. DO NOT EDIT. -package models - -import "github.com/onsonr/sonr/pkg/nebula/models/formstate" - -type RegistrationForm struct { - Title string `pkl:"title"` - - Description string `pkl:"description"` - - State formstate.FormState `pkl:"state"` - - Inputs []*Input `pkl:"inputs"` -} diff --git a/pkg/nebula/pages/pages.go b/pkg/nebula/pages/pages.go index a5826b630..9f90b41a1 100644 --- a/pkg/nebula/pages/pages.go +++ b/pkg/nebula/pages/pages.go @@ -1,6 +1,9 @@ package pages import ( + "bytes" + + "github.com/a-h/templ" "github.com/labstack/echo/v4" "github.com/onsonr/sonr/pkg/nebula/components/grant" @@ -34,3 +37,24 @@ func Profile(c echo.Context) error { func Register(c echo.Context) error { return echoResponse(c, register.Modal(c)) } + +// ╭───────────────────────────────────────────────────────────╮ +// │ Helper Methods │ +// ╰───────────────────────────────────────────────────────────╯ + +func echoResponse(c echo.Context, cmp templ.Component) error { + // Create a buffer to store the rendered HTML + buf := &bytes.Buffer{} + // Render the component to the buffer + err := cmp.Render(c.Request().Context(), buf) + if err != nil { + return err + } + + // Set the content type + c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) + + // Write the buffered content to the response + _, err = c.Response().Write(buf.Bytes()) + return err +} diff --git a/pkg/nebula/pages/utils.go b/pkg/nebula/pages/utils.go deleted file mode 100644 index de34ff40c..000000000 --- a/pkg/nebula/pages/utils.go +++ /dev/null @@ -1,25 +0,0 @@ -package pages - -import ( - "bytes" - - "github.com/a-h/templ" - "github.com/labstack/echo/v4" -) - -func echoResponse(c echo.Context, cmp templ.Component) error { - // Create a buffer to store the rendered HTML - buf := &bytes.Buffer{} - // Render the component to the buffer - err := cmp.Render(c.Request().Context(), buf) - if err != nil { - return err - } - - // Set the content type - c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) - - // Write the buffered content to the response - _, err = c.Response().Write(buf.Bytes()) - return err -} diff --git a/x/did/keeper/controller.go b/x/did/keeper/controller.go new file mode 100644 index 000000000..20f1a3763 --- /dev/null +++ b/x/did/keeper/controller.go @@ -0,0 +1,27 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/onsonr/crypto/mpc" + "github.com/onsonr/sonr/x/did/types" +) + +func (k Keeper) NewController(ctx sdk.Context) (uint64, types.ControllerI, error) { + shares, err := mpc.GenerateKeyshares() + if err != nil { + return 0, nil, err + } + controller, err := types.NewController(shares) + if err != nil { + return 0, nil, err + } + entry, err := controller.GetTableEntry() + if err != nil { + return 0, nil, err + } + num, err := k.OrmDB.ControllerTable().InsertReturningNumber(ctx, entry) + if err != nil { + return 0, nil, err + } + return num, controller, nil +} diff --git a/x/did/keeper/keeper.go b/x/did/keeper/keeper.go index d8ad08f63..6ea70aea1 100644 --- a/x/did/keeper/keeper.go +++ b/x/did/keeper/keeper.go @@ -1,22 +1,16 @@ package keeper import ( - "crypto/sha256" - "fmt" - "cosmossdk.io/collections" storetypes "cosmossdk.io/core/store" "cosmossdk.io/log" "cosmossdk.io/orm/model/ormdb" nftkeeper "cosmossdk.io/x/nft/keeper" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" stakkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/onsonr/crypto/mpc" - "gopkg.in/macaroon.v2" apiv1 "github.com/onsonr/sonr/api/did/v1" "github.com/onsonr/sonr/x/did/types" @@ -91,43 +85,3 @@ func NewKeeper( k.Schema = schema return k } - -func (k Keeper) NewController(ctx sdk.Context) (uint64, types.ControllerI, error) { - shares, err := mpc.GenerateKeyshares() - if err != nil { - return 0, nil, err - } - controller, err := types.NewController(shares) - if err != nil { - return 0, nil, err - } - entry, err := controller.GetTableEntry() - if err != nil { - return 0, nil, err - } - num, err := k.OrmDB.ControllerTable().InsertReturningNumber(ctx, entry) - if err != nil { - return 0, nil, err - } - return num, controller, nil -} - -// IssueMacaroon creates a macaroon with the specified parameters. -func (k Keeper) IssueMacaroon(ctx sdk.Context, sharedMPCPubKey, location, id string, blockExpiry uint64) (*macaroon.Macaroon, error) { - // Derive the root key by hashing the shared MPC public key - rootKey := sha256.Sum256([]byte(sharedMPCPubKey)) - // Create the macaroon - m, err := macaroon.New(rootKey[:], []byte(id), location, macaroon.LatestVersion) - if err != nil { - return nil, err - } - - // Add the block expiry caveat - caveat := fmt.Sprintf("block-expiry=%d", blockExpiry) - err = m.AddFirstPartyCaveat([]byte(caveat)) - if err != nil { - return nil, err - } - - return m, nil -} diff --git a/x/macaroon/keeper/issuer.go b/x/macaroon/keeper/issuer.go new file mode 100644 index 000000000..b2bb9dd75 --- /dev/null +++ b/x/macaroon/keeper/issuer.go @@ -0,0 +1,29 @@ +package keeper + +import ( + "crypto/sha256" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "gopkg.in/macaroon.v2" +) + +// IssueMacaroon creates a macaroon with the specified parameters. +func (k Keeper) IssueMacaroon(ctx sdk.Context, sharedMPCPubKey, location, id string, blockExpiry uint64) (*macaroon.Macaroon, error) { + // Derive the root key by hashing the shared MPC public key + rootKey := sha256.Sum256([]byte(sharedMPCPubKey)) + // Create the macaroon + m, err := macaroon.New(rootKey[:], []byte(id), location, macaroon.LatestVersion) + if err != nil { + return nil, err + } + + // Add the block expiry caveat + caveat := fmt.Sprintf("block-expiry=%d", blockExpiry) + err = m.AddFirstPartyCaveat([]byte(caveat)) + if err != nil { + return nil, err + } + + return m, nil +}