From a51b316daff847aef506e773ef02ad9bc1436594 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Sun, 24 Dec 2023 11:56:28 -0600 Subject: [PATCH] Adding Middleware to crypto --- crypto/middleware.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crypto/middleware.go b/crypto/middleware.go index ef52dc4..45d9b20 100644 --- a/crypto/middleware.go +++ b/crypto/middleware.go @@ -4,6 +4,8 @@ import ( "context" "errors" "strings" + + "github.com/labstack/echo/v4" ) var cryptoCtxKey = &contextKey{"crypto"} @@ -36,3 +38,13 @@ func KWForContext(ctx context.Context) *KeyWallet { } return kw } + +// Middleware adds global entropy value to the context +func Middleware(entropy string) echo.MiddlewareFunc { + return func(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + c.SetRequest(c.Request().WithContext(Context(c.Request().Context(), entropy))) + return next(c) + } + } +} -- 2.45.2