sonr/x/did/keeper/server.go

182 lines
5.3 KiB
Go
Raw Normal View History

2024-07-05 22:20:13 -04:00
package keeper
import (
"context"
2024-09-14 14:27:45 -04:00
"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"
2024-07-05 22:20:13 -04:00
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
sdk "github.com/cosmos/cosmos-sdk/types"
2024-07-05 22:20:13 -04:00
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"cosmossdk.io/errors"
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
didv1 "github.com/onsonr/hway/api/did/v1"
2024-07-05 22:20:13 -04:00
"github.com/onsonr/hway/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}
}
2024-09-14 14:27:45 -04:00
// # 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)
}
// # SyncController
//
// SyncController implements types.MsgServer.
func (ms msgServer) SyncController(ctx context.Context, msg *types.MsgSyncController) (*types.MsgSyncControllerResponse, error) {
// ctx := sdk.UnwrapSDKContext(goCtx)
return &types.MsgSyncControllerResponse{}, nil
}
// # UpdateParams
//
2024-07-05 22:20:13 -04:00
// UpdateParams updates the x/did module parameters.
2024-09-14 14:27:45 -04:00
func (ms msgServer) UpdateParams(
ctx context.Context,
msg *types.MsgUpdateParams,
) (*types.MsgUpdateParamsResponse, error) {
2024-07-05 22:20:13 -04:00
if ms.k.authority != msg.Authority {
2024-09-14 14:27:45 -04:00
return nil, errors.Wrapf(
govtypes.ErrInvalidSigner,
"invalid authority; expected %s, got %s",
ms.k.authority,
msg.Authority,
)
2024-07-05 22:20:13 -04:00
}
return nil, ms.k.Params.Set(ctx, msg.Params)
}
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
// Authenticate implements types.MsgServer.
func (ms msgServer) Authenticate(ctx context.Context, msg *types.MsgAuthenticate) (*types.MsgAuthenticateResponse, error) {
if ms.k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
}
2024-07-05 22:20:13 -04:00
// ctx := sdk.UnwrapSDKContext(goCtx)
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
return &types.MsgAuthenticateResponse{}, nil
2024-07-05 22:20:13 -04:00
}
2024-07-26 12:14:20 -04:00
// RegisterController implements types.MsgServer.
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
func (ms msgServer) RegisterController(goCtx context.Context, msg *types.MsgRegisterController) (*types.MsgRegisterControllerResponse, 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 &types.MsgRegisterControllerResponse{}, nil
}
// RegisterService implements types.MsgServer.
func (ms msgServer) RegisterService(goCtx context.Context, msg *types.MsgRegisterService) (*types.MsgRegisterServiceResponse, error) {
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
if ms.k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
svc := didv1.Service{
ControllerDid: msg.Authority,
}
err := ms.k.OrmDB.ServiceTable().Insert(ctx, &svc)
if err != nil {
return nil, err
}
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
return &types.MsgRegisterServiceResponse{}, nil
}
// ProveWitness implements types.MsgServer.
func (ms msgServer) ProveWitness(ctx context.Context, msg *types.MsgProveWitness) (*types.MsgProveWitnessResponse, error) {
// ctx := sdk.UnwrapSDKContext(goCtx)
return &types.MsgProveWitnessResponse{}, nil
}
// SyncVault implements types.MsgServer.
func (ms msgServer) SyncVault(ctx context.Context, msg *types.MsgSyncVault) (*types.MsgSyncVaultResponse, error) {
2024-07-26 12:14:20 -04:00
// ctx := sdk.UnwrapSDKContext(goCtx)
feat: add enums.pulsar.go file for PermissionScope enum (#4) * feat: add enums.pulsar.go file for PermissionScope enum * refactor: remove PERMISSION_SCOPE_IDENTIFIERS_ENS enum value * feat: Add MsgRegisterService to handle service registration The commit message for these changes would be: feat: Add MsgRegisterService to handle service registration This commit adds a new message type `MsgRegisterService` to the DID module's transaction proto file. This message allows users to register a new service with a given permission scope and origin URI. The domain must have a valid TXT record containing the public key. The changes include: - Adding the `MsgRegisterService` message type with fields for authority, origin URI, and scopes - Adding the `MsgRegisterServiceResponse` message type to handle the response - Updating the Msg service to include a new `RegisterService` RPC method - Implementing the `RegisterService` method in the keeper This feature allows users to register new services on the DID chain, which is an important part of the overall DID functionality. * (no commit message provided) * fix: Add ProveWitness and SyncVault RPCs The commit message should be: feat: Add ProveWitness and SyncVault RPCs This change adds two new RPCs to the DID module: 1. ProveWitness: An operation to prove the controller has a valid property using ZK Accumulators. 2. SyncVault: Synchronizes the controller with the Vault Motr DWN WASM Wallet. These new RPCs allow for more advanced DID management functionality. * fix: Remove unused `Meta` message from `genesis.proto` * refactor: Simplify the types and properties to keep a consistent structure for the blockchain * (no commit message provided) * {} * feat: add Equal methods for AssetInfo and ChainInfo types
2024-08-10 18:27:11 -04:00
return &types.MsgSyncVaultResponse{}, nil
2024-07-26 12:14:20 -04:00
}