mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
feat: add controller creation step to allocate
This commit is contained in:
parent
937b65ae95
commit
603da5560f
@ -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(),
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user