feature/1125 offload sync service worker (#1144)

- **feat: provide access to block time**
- **refactor: move block expiry calculation to helper function**
- **feat: register decentralized web node HTMX views**
- **feat: Reorganize methods in layout.templ file alphabetically**
- **feat: add support for layout variants**
- **feat: update Allocate RPC to use GET request with path parameters**
- **feat: add gRPC Gateway endpoint for Allocate**
- **refactor: rename SyncCurrent to Sync**
- **feat: improve code organization by making vault assembly private**
- **feat: add a new method for syncing DID documents**
This commit is contained in:
Prad Nukala
2024-10-18 13:07:52 -04:00
committed by GitHub
parent c2f7a53017
commit 2cd44c0b66
23 changed files with 571 additions and 4641 deletions
+7 -3
View File
@@ -6,7 +6,6 @@ import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/onsonr/sonr/internal/ctx"
didtypes "github.com/onsonr/sonr/x/did/types"
"gopkg.in/macaroon.v2"
)
@@ -15,7 +14,6 @@ var fourYears = time.Hour * 24 * 365 * 4
// IssueAdminMacaroon creates a macaroon with the specified parameters.
func (k Keeper) IssueAdminMacaroon(sdkctx sdk.Context, controller didtypes.ControllerI) (*macaroon.Macaroon, error) {
sctx := ctx.GetSonrCTX(sdkctx)
// Derive the root key by hashing the shared MPC public key
rootKey := sha256.Sum256([]byte(controller.PublicKey()))
// Create the macaroon
@@ -25,7 +23,7 @@ func (k Keeper) IssueAdminMacaroon(sdkctx sdk.Context, controller didtypes.Contr
}
// Add the block expiry caveat
caveat := fmt.Sprintf("block-expiry=%d", sctx.GetBlockExpiration(fourYears))
caveat := fmt.Sprintf("block-expiry=%d", calculateBlockExpiry(sdkctx, fourYears))
err = m.AddFirstPartyCaveat([]byte(caveat))
if err != nil {
return nil, err
@@ -53,3 +51,9 @@ func (k Keeper) IssueServiceMacaroon(sdkctx sdk.Context, sharedMPCPubKey, locati
return m, nil
}
func calculateBlockExpiry(sdkctx sdk.Context, duration time.Duration) uint64 {
blockTime := sdkctx.BlockTime()
avgBlockTime := float64(blockTime.Sub(blockTime).Seconds())
return uint64(duration.Seconds() / avgBlockTime)
}