mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
* fix: update commitizen version * feat: add WASM build tags to db actions * feat: Update all actions to follow `AddAsset` for error handling * feat: remove database dependency in dwn and motr commands * feat: add basic info form to registration view * feat: implement basic browser navigation component * refactor: move database related files to middleware * fix: remove unused test command * fix: update source directory for buf-publish workflow * feat: embed dwn config data * feat: add Sync RPC to query service * refactor: rename package to for better organization * feat: add new javascript exception handling for server requests * refactor: move dwn.wasm to embed directory * refactor: move server files to a new directory * refactor: move session related code to client package * refactor: Update dwn.wasm build path * refactor: move dwn wasm build to vfs * feat: introduce config loading middleware * feat: introduce DWN config and address JSON * refactor: move dwn wasm build output to embed directory * feat: introduce config and IndexedDB model * refactor: move DWN config file generation to vfs * refactor: move config package to * feat: add Sonr.ID IPFS gateway proxy * feat: add SWT data structure * feat: update index.html to use Sonr styles and scripts * feat(dwn): remove index.html server endpoint * feat: add Navigator API for web credential management
121 lines
3.0 KiB
Go
121 lines
3.0 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"cosmossdk.io/errors"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
"github.com/onsonr/sonr/x/did/builder"
|
|
"github.com/onsonr/sonr/x/did/types"
|
|
)
|
|
|
|
type msgServer struct {
|
|
k Keeper
|
|
}
|
|
|
|
var _ types.MsgServer = msgServer{}
|
|
|
|
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
|
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
|
return &msgServer{k: keeper}
|
|
}
|
|
|
|
// # AuthorizeService
|
|
//
|
|
// AuthorizeService implements types.MsgServer.
|
|
func (ms msgServer) AuthorizeService(goCtx context.Context, msg *types.MsgAuthorizeService) (*types.MsgAuthorizeServiceResponse, error) {
|
|
if ms.k.authority != msg.Controller {
|
|
return nil, errors.Wrapf(
|
|
govtypes.ErrInvalidSigner,
|
|
"invalid authority; expected %s, got %s",
|
|
ms.k.authority,
|
|
msg.Controller,
|
|
)
|
|
}
|
|
return &types.MsgAuthorizeServiceResponse{}, nil
|
|
}
|
|
|
|
// # AllocateVault
|
|
//
|
|
// AllocateVault implements types.MsgServer.
|
|
func (ms msgServer) AllocateVault(
|
|
goCtx context.Context,
|
|
msg *types.MsgAllocateVault,
|
|
) (*types.MsgAllocateVaultResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
// 1.Check if the service origin is valid
|
|
if ms.k.IsValidServiceOrigin(ctx, msg.Origin) {
|
|
return nil, types.ErrInvalidServiceOrigin
|
|
}
|
|
|
|
cid, expiryBlock, err := ms.k.assembleInitialVault(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
regOpts, err := builder.GetPublicKeyCredentialCreationOptions(msg.Origin, msg.Subject, cid, ms.k.GetParams(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Convert to string
|
|
regOptsJSON, err := json.Marshal(regOpts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.MsgAllocateVaultResponse{
|
|
ExpiryBlock: expiryBlock,
|
|
Cid: cid,
|
|
RegistrationOptions: string(regOptsJSON),
|
|
}, nil
|
|
}
|
|
|
|
// # RegisterController
|
|
//
|
|
// RegisterController implements types.MsgServer.
|
|
func (ms msgServer) RegisterController(
|
|
goCtx context.Context,
|
|
msg *types.MsgRegisterController,
|
|
) (*types.MsgRegisterControllerResponse, error) {
|
|
_ = sdk.UnwrapSDKContext(goCtx)
|
|
return &types.MsgRegisterControllerResponse{}, nil
|
|
}
|
|
|
|
// # RegisterService
|
|
//
|
|
// RegisterService implements types.MsgServer.
|
|
func (ms msgServer) RegisterService(
|
|
goCtx context.Context,
|
|
msg *types.MsgRegisterService,
|
|
) (*types.MsgRegisterServiceResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
// 1.Check if the service origin is valid
|
|
if !ms.k.IsValidServiceOrigin(ctx, msg.Service.Origin) {
|
|
return nil, types.ErrInvalidServiceOrigin
|
|
}
|
|
return ms.k.insertService(ctx, msg.Service)
|
|
}
|
|
|
|
// # UpdateParams
|
|
//
|
|
// UpdateParams updates the x/did module parameters.
|
|
func (ms msgServer) UpdateParams(
|
|
ctx context.Context,
|
|
msg *types.MsgUpdateParams,
|
|
) (*types.MsgUpdateParamsResponse, error) {
|
|
if ms.k.authority != msg.Authority {
|
|
return nil, errors.Wrapf(
|
|
govtypes.ErrInvalidSigner,
|
|
"invalid authority; expected %s, got %s",
|
|
ms.k.authority,
|
|
msg.Authority,
|
|
)
|
|
}
|
|
return nil, ms.k.Params.Set(ctx, msg.Params)
|
|
}
|