sonr/x/did/keeper/macaroon.go
Prad Nukala 60c48d2409
feature/did accounts (#23)
* feat: add support for DID number as primary key for Controllers

* refactor: rename pkg/proxy to app/proxy

* feat: add vault module keeper tests

* feat(vault): add DID keeper to vault module

* refactor: move vault client code to its own package

* refactor(vault): extract schema definition

* refactor: use vaulttypes for MsgAllocateVault

* refactor: update vault assembly logic to use new methods

* feat: add dwn-proxy command

* refactor: remove unused context.go file

* refactor: remove unused web-related code

* feat: add DWN proxy server

* feat: add BuildTx RPC to vault module

* fix: Implement BuildTx endpoint

* feat: add devbox integration to project
2024-09-25 19:45:28 -04:00

30 lines
766 B
Go

package keeper
import (
"crypto/sha256"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"gopkg.in/macaroon.v2"
)
// IssueMacaroon creates a macaroon with the specified parameters.
func (k Keeper) IssueMacaroon(ctx sdk.Context, sharedMPCPubKey, location, id string, blockExpiry uint64) (*macaroon.Macaroon, error) {
// Derive the root key by hashing the shared MPC public key
rootKey := sha256.Sum256([]byte(sharedMPCPubKey))
// Create the macaroon
m, err := macaroon.New(rootKey[:], []byte(id), location, macaroon.LatestVersion)
if err != nil {
return nil, err
}
// Add the block expiry caveat
caveat := fmt.Sprintf("block-expiry=%d", blockExpiry)
err = m.AddFirstPartyCaveat([]byte(caveat))
if err != nil {
return nil, err
}
return m, nil
}