feat: add DID-based authentication middleware

This commit is contained in:
Prad Nukala 2024-12-09 18:24:27 -05:00
parent f8d362352d
commit 6fbcb7cef5
10 changed files with 16 additions and 68 deletions

View File

@ -10,8 +10,8 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/onsonr/sonr/crypto/ucan"
"github.com/onsonr/sonr/pkg/common/didauth/producer"
"github.com/onsonr/sonr/pkg/common/ipfs"
"github.com/onsonr/sonr/pkg/common/producer"
"github.com/onsonr/sonr/pkg/gateway"
"github.com/onsonr/sonr/pkg/gateway/config"
)

View File

@ -8,7 +8,7 @@ import (
"syscall/js"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/common/dids"
"github.com/onsonr/sonr/pkg/common/didauth/controller"
"github.com/onsonr/sonr/pkg/vault"
"github.com/onsonr/sonr/pkg/vault/types"
)
@ -48,7 +48,7 @@ func main() {
e := echo.New()
e.Use(vault.WasmContextMiddleware)
e.Use(dids.Middleware(nil))
e.Use(controller.Middleware(nil))
vault.RegisterRoutes(e, config)
vault.ServeFetch(e)
}

View File

@ -1,4 +1,4 @@
package dids
package controller
import (
"github.com/labstack/echo/v4"

View File

@ -1,7 +1,7 @@
//go:build js && wasm
// +build js,wasm
package dids
package controller
import (
"fmt"

View File

@ -0,0 +1,2 @@
// Package didauth provides middleware and utilities for DID-based authentication
package didauth

View File

@ -1,6 +1,7 @@
package producer
import (
"github.com/onsonr/sonr/crypto/mpc"
"github.com/onsonr/sonr/crypto/ucan"
"github.com/onsonr/sonr/crypto/ucan/store"
"github.com/onsonr/sonr/pkg/common/ipfs"
@ -27,3 +28,11 @@ func Middleware(ipfs ipfs.Client, perms ucan.Permissions) echo.MiddlewareFunc {
}
}
}
func NewKeyset(c echo.Context) (mpc.Keyset, error) {
ks, err := mpc.NewKeyset()
if err != nil {
return nil, err
}
return ks, nil
}

View File

@ -1,63 +0,0 @@
package producer
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/crypto/mpc"
)
func NewKeyset(c echo.Context) (mpc.Keyset, error) {
ks, err := mpc.NewKeyset()
if err != nil {
return nil, err
}
return ks, nil
}
//
// func GetKeyset(c echo.Context) (mpc.Keyset, error) {
// cc, ok := c.(*SignerContext)
// if !ok {
// return nil, errors.New("not an SignerContext")
// }
// if !cc.hasKeyset {
// return nil, fmt.Errorf("keyset not found")
// }
// if cc.keyset == nil {
// return nil, fmt.Errorf("keyset is nil")
// }
// return cc.keyset, nil
// }
//
// func NewSource(c echo.Context) (mpc.KeyshareSource, error) {
// cc, ok := c.(*SignerContext)
// if !ok {
// return nil, errors.New("not an SignerContext")
// }
// if !cc.hasKeyset {
// return nil, fmt.Errorf("keyset not found")
// }
// if cc.keyset == nil {
// return nil, fmt.Errorf("keyset is nil")
// }
// src, err := mpc.NewSource(cc.keyset)
// if err != nil {
// return nil, err
// }
// cc.signer = src
// cc.hasSigner = true
// return src, nil
// }
//
// func GetSource(c echo.Context) (mpc.KeyshareSource, error) {
// cc, ok := c.(*SignerContext)
// if !ok {
// return nil, errors.New("not an SignerContext")
// }
// if !cc.hasSigner {
// return nil, fmt.Errorf("signer not found")
// }
// if cc.signer == nil {
// return nil, fmt.Errorf("signer is nil")
// }
// return cc.signer, nil
// }