From 603da5560f1b9ead31e4b861ee0875af987a02ff Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 21 Oct 2024 13:07:38 -0400 Subject: [PATCH] feat: add controller creation step to allocate --- x/vault/keeper/querier.go | 10 +++++++++- x/vault/types/errors.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/x/vault/keeper/querier.go b/x/vault/keeper/querier.go index 515ead882..304603244 100644 --- a/x/vault/keeper/querier.go +++ b/x/vault/keeper/querier.go @@ -63,28 +63,36 @@ func (k Querier) Allocate(goCtx context.Context, req *types.QueryAllocateRequest ctx.Logger().Error(fmt.Sprintf("Error getting current schema: %s", err.Error())) return nil, types.ErrInvalidSchema.Wrap(err.Error()) } + + // 2. Generate MPC Keyshares for new Account shares, err := mpc.GenerateKeyshares() if err != nil { ctx.Logger().Error(fmt.Sprintf("Error generating keyshares: %s", err.Error())) return nil, types.ErrInvalidSchema.Wrap(err.Error()) } + // 3. Create Controller from Keyshares con, err := didtypes.NewController(shares) if err != nil { ctx.Logger().Error(fmt.Sprintf("Error creating controller: %s", err.Error())) - return nil, err + return nil, types.ErrControllerCreation.Wrap(err.Error()) } + + // 4. Create a new vault PWA for service-worker v, err := types.NewVault("", con.SonrAddress(), con.ChainID(), sch) if err != nil { ctx.Logger().Error(fmt.Sprintf("Error creating vault: %s", err.Error())) return nil, types.ErrInvalidSchema.Wrap(err.Error()) } + + // 5. Add to IPFS and Return CID for User Claims in Gateway cid, err := k.ipfsClient.Unixfs().Add(context.Background(), v.FS) if err != nil { ctx.Logger().Error(fmt.Sprintf("Error adding to IPFS: %s", err.Error())) return nil, types.ErrVaultAssembly.Wrap(err.Error()) } + // 6. Return final response return &types.QueryAllocateResponse{ Success: true, Cid: cid.String(), diff --git a/x/vault/types/errors.go b/x/vault/types/errors.go index 7846490c0..1c13a8993 100644 --- a/x/vault/types/errors.go +++ b/x/vault/types/errors.go @@ -6,6 +6,7 @@ var ( ErrInvalidGenesisState = sdkerrors.Register(ModuleName, 100, "invalid genesis state") ErrInvalidSchema = sdkerrors.Register(ModuleName, 200, "invalid schema") ErrVaultAssembly = sdkerrors.Register(ModuleName, 201, "vault assembly") + ErrControllerCreation = sdkerrors.Register(ModuleName, 202, "failed to create controller") ErrUnsupportedKeyEncoding = sdkerrors.Register(ModuleName, 300, "unsupported key encoding") ErrUnsopportedChainCode = sdkerrors.Register(ModuleName, 301, "unsupported chain code") ErrUnsupportedKeyCurve = sdkerrors.Register(ModuleName, 302, "unsupported key curve")