2024-10-10 13:44:17 -04:00
|
|
|
package ctx
|
|
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2024-10-10 13:44:17 -04:00
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
|
dwngen "github.com/onsonr/sonr/internal/dwn/gen"
|
|
|
|
|
)
|
2024-10-10 13:44:17 -04:00
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
type HeaderKey string
|
2024-10-10 13:44:17 -04:00
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
const (
|
|
|
|
|
HeaderAuthorization HeaderKey = "Authorization"
|
2024-10-10 13:44:17 -04:00
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
HeaderIPFSGatewayURL HeaderKey = "X-IPFS-Gateway"
|
|
|
|
|
HeaderSonrChainID HeaderKey = "X-Sonr-ChainID"
|
|
|
|
|
HeaderSonrKeyshare HeaderKey = "X-Sonr-Keyshare"
|
|
|
|
|
)
|
2024-10-10 13:44:17 -04:00
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
func (h HeaderKey) String() string {
|
|
|
|
|
return string(h)
|
2024-10-10 13:44:17 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-15 14:31:19 -04:00
|
|
|
func injectConfig(c echo.Context, config *dwngen.Config) {
|
|
|
|
|
WriteHeader(c, HeaderIPFSGatewayURL, config.IpfsGatewayUrl)
|
|
|
|
|
WriteHeader(c, HeaderSonrChainID, config.SonrChainId)
|
|
|
|
|
WriteHeader(c, HeaderSonrKeyshare, config.MotrKeyshare)
|
|
|
|
|
WriteCookie(c, CookieKeySonrAddr, config.MotrAddress)
|
|
|
|
|
|
|
|
|
|
schemaBz, err := json.Marshal(config.VaultSchema)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Logger().Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteCookie(c, CookieKeyVaultSchema, string(schemaBz))
|
2024-10-10 13:44:17 -04:00
|
|
|
}
|