Files
sonr/pkg/didauth/producer/middleware.go
T

38 lines
882 B
Go
Raw Normal View History

2024-12-05 20:36:58 -05:00
package producer
import (
"github.com/onsonr/sonr/crypto/mpc"
2024-12-05 20:36:58 -05:00
"github.com/onsonr/sonr/crypto/ucan"
"github.com/onsonr/sonr/pkg/ipfsapi"
2024-12-05 20:36:58 -05:00
"github.com/labstack/echo/v4"
)
// Middleware returns middleware to spawn controllers and validate UCAN tokens
func Middleware(ipc ipfsapi.Client, perms ucan.Permissions) echo.MiddlewareFunc {
2024-12-05 20:36:58 -05:00
// Setup token store and parser
store := ipfsapi.NewUCANStore(ipc)
2024-12-05 20:36:58 -05:00
parser := ucan.NewTokenParser(perms.GetConstructor(), store, store)
// Return middleware
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
ctx := ProducerContext{
Context: c,
IPFSClient: ipc,
2024-12-05 20:36:58 -05:00
TokenParser: parser,
TokenStore: store,
}
return next(ctx)
}
}
}
func NewKeyset(c echo.Context) (mpc.Enclave, error) {
ks, err := mpc.GenEnclave()
if err != nil {
return nil, err
}
return ks, nil
}