diff --git a/app/app.go b/app/app.go index 44bd05ce2..3c3cbf93a 100644 --- a/app/app.go +++ b/app/app.go @@ -100,7 +100,7 @@ import ( ) const Name = "cheqd-node" -const ProtocolVersion = 1; +const ProtocolVersion = 1 // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals @@ -156,7 +156,7 @@ var ( minttypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, govtypes.ModuleName: {authtypes.Burner}, } ) @@ -348,7 +348,7 @@ func New( app.EvidenceKeeper = *evidenceKeeper app.cheqdKeeper = *cheqdkeeper.NewKeeper( - appCodec, keys[cheqdtypes.StoreKey], keys[cheqdtypes.MemStoreKey], + appCodec, keys[cheqdtypes.StoreKey], ) // this line is used by starport scaffolding # stargate/app/keeperDefinition diff --git a/docs/errors.md b/docs/errors.md new file mode 100644 index 000000000..067f4a5ee --- /dev/null +++ b/docs/errors.md @@ -0,0 +1,21 @@ +# Registered cheqd errors + +## Overview + +| Name | Code | Description | +|---|---|---| +| ErrBadRequest | 1000 | The request the client made is incorrect or corrupt | +| ErrBadRequestIsRequired | 1001 | The request does not contain required property | +| ErrBadRequestIsNotDid | 1002 | The request contains invalid `id` property | +| ErrBadRequestInvalidVerMethod | 1003 | The request contains invalid verification method | +| ErrBadRequestInvalidService | 1004 | The request contains invalid service | +| ErrBadRequestIsNotDidFragment | 1005 | The request contains invalid verification method id | +| ErrInvalidSignature | 1100 | Invalid signature detected | +| ErrDidDocExists | 1200 | An attempt to create a DID Doc that exists in the ledger detected | +| ErrDidDocNotFound | 1201 | The DID Doc not found in the ledger | +| ErrVerificationMethodNotFound | 1202 | The DID Doc does not contain the requested verification method | +| ErrUnexpectedDidVersion | 1203 | Replay protected failed. An attempt to update DID Doc with wrong version detected | +| ErrInvalidPublicKey | 1204 | Unable to decode public key | +| ErrInvalidDidStateValue | 1300 | Unable to unmarshall stored document | +| ErrSetToState | 1304 | Unable to set value into the ledger | +| ErrNotImplemented | 1501 | The method is not implemented | diff --git a/go.mod b/go.mod index eef43ac37..8d19c7566 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/cheqd/cheqd-node go 1.15 require ( + github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/cosmos-sdk v0.44.2 github.com/cosmos/ibc-go v1.0.1 github.com/gogo/protobuf v1.3.3 @@ -10,10 +11,12 @@ require ( github.com/google/go-cmp v0.5.6 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/multiformats/go-multibase v0.0.3 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.2.1 github.com/spf13/pflag v1.0.5 + github.com/stretchr/testify v1.7.0 github.com/tendermint/tendermint v0.34.13 github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 diff --git a/go.sum b/go.sum index e1724b236..df9c4bb05 100644 --- a/go.sum +++ b/go.sum @@ -721,9 +721,17 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd github.com/moricho/tparallel v0.2.1/go.mod h1:fXEIZxG2vdfl0ZF8b42f5a78EhjjD5mX8qUplsoSU4k= github.com/mozilla/scribe v0.0.0-20180711195314-fb71baf557c1/go.mod h1:FIczTrinKo8VaLxe6PWTPEXRXDIHz2QAwiaBaP5/4a8= github.com/mozilla/tls-observatory v0.0.0-20210609171429-7bc42856d2e5/go.mod h1:FUqVoUPHSEdDR0MnFM3Dh8AU0pZHLXUD127SAJGER/s= +github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= +github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk= +github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= diff --git a/proto/cheqd/common.proto b/proto/cheqd/common.proto new file mode 100644 index 000000000..b00b43501 --- /dev/null +++ b/proto/cheqd/common.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package cheqdid.cheqdnode.cheqd; + +option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; + +message KeyValuePair { + string key = 1; + string value = 2; +} diff --git a/proto/cheqd/did.proto b/proto/cheqd/did.proto new file mode 100644 index 000000000..57f88d385 --- /dev/null +++ b/proto/cheqd/did.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; +package cheqdid.cheqdnode.cheqd; + +option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; + +import "google/protobuf/any.proto"; +import "cheqd/common.proto"; + +message Did { + string id = 1; + repeated string controller = 2; //optional + repeated VerificationMethod verification_method = 3; // optional + repeated string authentication = 4; // optional + repeated string assertion_method = 5; // optional + repeated string capability_invocation = 6; // optional + repeated string capability_delegation = 7; // optional + repeated string key_agreement = 8; // optional + repeated ServiceEndpoint service = 9; // optional + repeated string also_known_as = 10; // optional + repeated string context = 11; +} + +message VerificationMethod { + string id = 1; + string type = 2; + string controller = 3; + repeated KeyValuePair public_key_jwk = 4; // optional + string public_key_multibase = 5; // optional +} + +message ServiceEndpoint { + string id = 1; + string type = 2; + string service_endpoint = 3; +} + + diff --git a/proto/cheqd/genesis.proto b/proto/cheqd/genesis.proto index df22b451c..7eae54093 100644 --- a/proto/cheqd/genesis.proto +++ b/proto/cheqd/genesis.proto @@ -2,13 +2,12 @@ syntax = "proto3"; package cheqdid.cheqdnode.cheqd; // this line is used by starport scaffolding # genesis/proto/import -import "cheqd/nym.proto"; +import "cheqd/did.proto"; option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; // GenesisState defines the capability module's genesis state. message GenesisState { // this line is used by starport scaffolding # genesis/proto/state - repeated Nym nymList = 1; // this line is used by starport scaffolding # genesis/proto/stateField } diff --git a/proto/cheqd/nym.proto b/proto/cheqd/nym.proto deleted file mode 100644 index 01fcd2406..000000000 --- a/proto/cheqd/nym.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; -package cheqdid.cheqdnode.cheqd; - -option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; - -import "gogoproto/gogo.proto"; - -message Nym { - string creator = 1; - uint64 id = 2; - string alias = 3; - string verkey = 4; - string did = 5; - string role = 6; -} diff --git a/proto/cheqd/query.proto b/proto/cheqd/query.proto index fd555b4fc..bde693475 100644 --- a/proto/cheqd/query.proto +++ b/proto/cheqd/query.proto @@ -4,36 +4,23 @@ package cheqdid.cheqdnode.cheqd; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; // this line is used by starport scaffolding # 1 -import "cheqd/nym.proto"; +import "cheqd/did.proto"; +import "cheqd/stateValue.proto"; option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; // Query defines the gRPC querier service. service Query { - // this line is used by starport scaffolding # 2 - rpc Nym(QueryGetNymRequest) returns (QueryGetNymResponse) { - option (google.api.http).get = "/cheqd/cheqd/cheqd/nym/{id}"; + rpc Did(QueryGetDidRequest) returns (QueryGetDidResponse) { + option (google.api.http).get = "/cheqd/cheqdnode/cheqd/did/{id}"; } - rpc NymAll(QueryAllNymRequest) returns (QueryAllNymResponse) { - option (google.api.http).get = "/cheqd/cheqd/cheqd/nym"; - } - -} - -// this line is used by starport scaffolding # 3 -message QueryGetNymRequest { - uint64 id = 1; } -message QueryGetNymResponse { - Nym Nym = 1; +message QueryGetDidRequest { + string id = 1; } -message QueryAllNymRequest { - cosmos.base.query.v1beta1.PageRequest pagination = 1; -} - -message QueryAllNymResponse { - repeated Nym Nym = 1; - cosmos.base.query.v1beta1.PageResponse pagination = 2; -} +message QueryGetDidResponse { + Did did = 1; + Metadata metadata = 2; +} \ No newline at end of file diff --git a/proto/cheqd/stateValue.proto b/proto/cheqd/stateValue.proto new file mode 100644 index 000000000..eeac2de53 --- /dev/null +++ b/proto/cheqd/stateValue.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package cheqdid.cheqdnode.cheqd; +import "google/protobuf/any.proto"; + +// this line is used by starport scaffolding # proto/tx/import +option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; + +message StateValue { + google.protobuf.Any data = 1; + Metadata metadata = 2; // optional +} + +// metadata +message Metadata { + string created = 1; + string updated = 2; + bool deactivated = 3; + string version_id = 4; +} diff --git a/proto/cheqd/tx.proto b/proto/cheqd/tx.proto index 169a86819..456d8e4f3 100644 --- a/proto/cheqd/tx.proto +++ b/proto/cheqd/tx.proto @@ -1,5 +1,7 @@ syntax = "proto3"; package cheqdid.cheqdnode.cheqd; +import "google/protobuf/any.proto"; +import "cheqd/did.proto"; // this line is used by starport scaffolding # proto/tx/import @@ -7,39 +9,54 @@ option go_package = "github.com/cheqd/cheqd-node/x/cheqd/types"; // Msg defines the Msg service. service Msg { - // this line is used by starport scaffolding # proto/tx/rpc - rpc CreateNym(MsgCreateNym) returns (MsgCreateNymResponse); - rpc UpdateNym(MsgUpdateNym) returns (MsgUpdateNymResponse); - rpc DeleteNym(MsgDeleteNym) returns (MsgDeleteNymResponse); + rpc CreateDid(MsgWriteRequest) returns (MsgCreateDidResponse); + rpc UpdateDid(MsgWriteRequest) returns (MsgUpdateDidResponse); } // this line is used by starport scaffolding # proto/tx/message -message MsgCreateNym { - string creator = 1; - string alias = 2; - string verkey = 3; - string did = 4; - string role = 5; +message MsgWriteRequest { + google.protobuf.Any data = 1; + repeated SignInfo signatures = 2; } -message MsgCreateNymResponse { - uint64 id = 1; +message SignInfo { + string verification_method_id = 1; + string signature = 2; } -message MsgUpdateNym { - string creator = 1; - uint64 id = 2; - string alias = 3; - string verkey = 4; - string did = 5; - string role = 6; +message MsgCreateDid { + string id = 1; + repeated string controller = 2; + repeated VerificationMethod verification_method = 3; + repeated string authentication = 4; + repeated string assertion_method = 5; + repeated string capability_invocation = 6; + repeated string capability_delegation = 7; + repeated string key_agreement = 8; + repeated string also_known_as = 9; + repeated ServiceEndpoint service = 10; + repeated string context = 11; } -message MsgUpdateNymResponse { } +message MsgCreateDidResponse { + string id = 1; +} -message MsgDeleteNym { - string creator = 1; - uint64 id = 2; +message MsgUpdateDid { + string id = 1; + repeated string controller = 2; + repeated VerificationMethod verification_method = 3; + repeated string authentication = 4; + repeated string assertion_method = 5; + repeated string capability_invocation = 6; + repeated string capability_delegation = 7; + repeated string key_agreement = 8; + repeated string also_known_as = 9; + repeated ServiceEndpoint service = 10; + repeated string context = 11; + string version_id = 12; } -message MsgDeleteNymResponse { } +message MsgUpdateDidResponse { + string id = 1; +} diff --git a/vue/src/views/Types.vue b/vue/src/views/Types.vue index 3048bf95e..aaaae1ed6 100644 --- a/vue/src/views/Types.vue +++ b/vue/src/views/Types.vue @@ -2,7 +2,7 @@
- +
diff --git a/x/cheqd/client/cli/query.go b/x/cheqd/client/cli/query.go deleted file mode 100644 index e75613db1..000000000 --- a/x/cheqd/client/cli/query.go +++ /dev/null @@ -1,33 +0,0 @@ -package cli - -import ( - "fmt" - // "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cheqd/cheqd-node/x/cheqd/types" -) - -// GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(queryRoute string) *cobra.Command { - // Group cheqd queries under a subcommand - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - // this line is used by starport scaffolding # 1 - - cmd.AddCommand(CmdListNym()) - cmd.AddCommand(CmdShowNym()) - - return cmd -} diff --git a/x/cheqd/client/cli/queryNym.go b/x/cheqd/client/cli/queryNym.go deleted file mode 100644 index 1a3d855cc..000000000 --- a/x/cheqd/client/cli/queryNym.go +++ /dev/null @@ -1,76 +0,0 @@ -package cli - -import ( - "context" - "strconv" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/spf13/cobra" -) - -func CmdListNym() *cobra.Command { - cmd := &cobra.Command{ - Use: "list-nym", - Short: "list all nym", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryAllNymRequest{ - Pagination: pageReq, - } - - res, err := queryClient.NymAll(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func CmdShowNym() *cobra.Command { - cmd := &cobra.Command{ - Use: "show-nym [id]", - Short: "shows a nym", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - queryClient := types.NewQueryClient(clientCtx) - - id, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - params := &types.QueryGetNymRequest{ - Id: id, - } - - res, err := queryClient.Nym(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/cheqd/client/cli/tx.go b/x/cheqd/client/cli/tx.go deleted file mode 100644 index b13d9eec3..000000000 --- a/x/cheqd/client/cli/tx.go +++ /dev/null @@ -1,26 +0,0 @@ -package cli - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cheqd/cheqd-node/x/cheqd/types" -) - -// GetTxCmd returns the transaction commands for this module -func GetTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - // this line is used by starport scaffolding # 1 - - return cmd -} diff --git a/x/cheqd/client/cli/txNym.go b/x/cheqd/client/cli/txNym.go deleted file mode 100644 index 3c9646072..000000000 --- a/x/cheqd/client/cli/txNym.go +++ /dev/null @@ -1,104 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" -) - -func CmdCreateNym() *cobra.Command { - cmd := &cobra.Command{ - Use: "create-nym [alias] [verkey] [did] [role]", - Short: "Creates a new nym", - Args: cobra.ExactArgs(4), - RunE: func(cmd *cobra.Command, args []string) error { - argsAlias := string(args[0]) - argsVerkey := string(args[1]) - argsDid := string(args[2]) - argsRole := string(args[3]) - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgCreateNym(clientCtx.GetFromAddress().String(), string(argsAlias), string(argsVerkey), string(argsDid), string(argsRole)) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - -func CmdUpdateNym() *cobra.Command { - cmd := &cobra.Command{ - Use: "update-nym [id] [alias] [verkey] [did] [role]", - Short: "Update a nym", - Args: cobra.ExactArgs(5), - RunE: func(cmd *cobra.Command, args []string) error { - id, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - argsAlias := string(args[1]) - argsVerkey := string(args[2]) - argsDid := string(args[3]) - argsRole := string(args[4]) - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgUpdateNym(clientCtx.GetFromAddress().String(), id, string(argsAlias), string(argsVerkey), string(argsDid), string(argsRole)) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - -func CmdDeleteNym() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete-nym [id] [alias] [verkey] [did] [role]", - Short: "Delete a nym by id", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - id, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgDeleteNym(clientCtx.GetFromAddress().String(), id) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/cheqd/client/rest/queryNym.go b/x/cheqd/client/rest/queryNym.go deleted file mode 100644 index c3950a0a9..000000000 --- a/x/cheqd/client/rest/queryNym.go +++ /dev/null @@ -1,39 +0,0 @@ -package rest - -import ( - "fmt" - "net/http" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" -) - -func listNymHandler(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - res, height, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/list-nym", types.QuerierRoute), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - clientCtx = clientCtx.WithHeight(height) - rest.PostProcessResponse(w, clientCtx, res) - } -} - -func getNymHandler(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - id := mux.Vars(r)["id"] - - res, height, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/get-nym/%s", types.QuerierRoute, id), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - clientCtx = clientCtx.WithHeight(height) - rest.PostProcessResponse(w, clientCtx, res) - } -} diff --git a/x/cheqd/client/rest/rest.go b/x/cheqd/client/rest/rest.go deleted file mode 100644 index c080f16e8..000000000 --- a/x/cheqd/client/rest/rest.go +++ /dev/null @@ -1,35 +0,0 @@ -package rest - -import ( - "github.com/gorilla/mux" - - "github.com/cosmos/cosmos-sdk/client" - // this line is used by starport scaffolding # 1 -) - -const ( - MethodGet = "GET" -) - -// RegisterRoutes registers cheqd-related REST handlers to a router -func RegisterRoutes(clientCtx client.Context, r *mux.Router) { - // this line is used by starport scaffolding # 2 - registerQueryRoutes(clientCtx, r) - registerTxHandlers(clientCtx, r) - -} - -func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { - // this line is used by starport scaffolding # 3 - r.HandleFunc("/cheqd/nyms/{id}", getNymHandler(clientCtx)).Methods("GET") - r.HandleFunc("/cheqd/nyms", listNymHandler(clientCtx)).Methods("GET") - -} - -func registerTxHandlers(clientCtx client.Context, r *mux.Router) { - // this line is used by starport scaffolding # 4 - r.HandleFunc("/cheqd/nyms", createNymHandler(clientCtx)).Methods("POST") - r.HandleFunc("/cheqd/nyms/{id}", updateNymHandler(clientCtx)).Methods("POST") - r.HandleFunc("/cheqd/nyms/{id}", deleteNymHandler(clientCtx)).Methods("POST") - -} diff --git a/x/cheqd/client/rest/txNym.go b/x/cheqd/client/rest/txNym.go deleted file mode 100644 index e09929127..000000000 --- a/x/cheqd/client/rest/txNym.go +++ /dev/null @@ -1,153 +0,0 @@ -package rest - -import ( - "net/http" - "strconv" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" -) - -type createNymRequest struct { - BaseReq rest.BaseReq `json:"base_req"` - Creator string `json:"creator"` - Alias string `json:"alias"` - Verkey string `json:"verkey"` - Did string `json:"did"` - Role string `json:"role"` -} - -func createNymHandler(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req createNymRequest - if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { - rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request") - return - } - - baseReq := req.BaseReq.Sanitize() - if !baseReq.ValidateBasic(w) { - return - } - - _, err := sdk.AccAddressFromBech32(req.Creator) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - parsedAlias := req.Alias - - parsedVerkey := req.Verkey - - parsedDid := req.Did - - parsedRole := req.Role - - msg := types.NewMsgCreateNym( - req.Creator, - parsedAlias, - parsedVerkey, - parsedDid, - parsedRole, - ) - - tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg) - } -} - -type updateNymRequest struct { - BaseReq rest.BaseReq `json:"base_req"` - Creator string `json:"creator"` - Alias string `json:"alias"` - Verkey string `json:"verkey"` - Did string `json:"did"` - Role string `json:"role"` -} - -func updateNymHandler(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - id, err := strconv.ParseUint(mux.Vars(r)["id"], 10, 64) - if err != nil { - return - } - - var req updateNymRequest - if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { - rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request") - return - } - - baseReq := req.BaseReq.Sanitize() - if !baseReq.ValidateBasic(w) { - return - } - - _, err = sdk.AccAddressFromBech32(req.Creator) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - parsedAlias := req.Alias - - parsedVerkey := req.Verkey - - parsedDid := req.Did - - parsedRole := req.Role - - msg := types.NewMsgUpdateNym( - req.Creator, - id, - parsedAlias, - parsedVerkey, - parsedDid, - parsedRole, - ) - - tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg) - } -} - -type deleteNymRequest struct { - BaseReq rest.BaseReq `json:"base_req"` - Creator string `json:"creator"` -} - -func deleteNymHandler(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - id, err := strconv.ParseUint(mux.Vars(r)["id"], 10, 64) - if err != nil { - return - } - - var req deleteNymRequest - if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { - rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request") - return - } - - baseReq := req.BaseReq.Sanitize() - if !baseReq.ValidateBasic(w) { - return - } - - _, err = sdk.AccAddressFromBech32(req.Creator) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - msg := types.NewMsgDeleteNym( - req.Creator, - id, - ) - - tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg) - } -} diff --git a/x/cheqd/genesis.go b/x/cheqd/genesis.go index 2b7248a3c..77803b6ae 100644 --- a/x/cheqd/genesis.go +++ b/x/cheqd/genesis.go @@ -9,14 +9,6 @@ import ( // InitGenesis initializes the cheqd module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - // this line is used by starport scaffolding # genesis/module/init - // Set all the nym - for _, elem := range genState.NymList { - k.SetNym(ctx, *elem) - } - - // Set nym count - k.SetNymCount(ctx, uint64(len(genState.NymList))) } @@ -24,13 +16,5 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { genesis := types.DefaultGenesis() - // this line is used by starport scaffolding # genesis/module/export - // Get all nym - nymList := k.GetAllNym(ctx) - for _, elem := range nymList { - elem := elem - genesis.NymList = append(genesis.NymList, &elem) - } - return genesis } diff --git a/x/cheqd/handler.go b/x/cheqd/handler.go index 3cddc2763..d2ad6a239 100644 --- a/x/cheqd/handler.go +++ b/x/cheqd/handler.go @@ -2,7 +2,6 @@ package cheqd import ( "fmt" - "github.com/cheqd/cheqd-node/x/cheqd/keeper" "github.com/cheqd/cheqd-node/x/cheqd/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,18 +15,20 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) - switch msg := msg.(type) { - // this line is used by starport scaffolding # 1 - case *types.MsgCreateNym: - res, err := msgServer.CreateNym(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) + parsedMsg, isMsgIdentity := msg.(*types.MsgWriteRequest) + if !isMsgIdentity { + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } - case *types.MsgUpdateNym: - res, err := msgServer.UpdateNym(sdk.WrapSDKContext(ctx), msg) + switch parsedMsg.Data.TypeUrl { + // this line is used by starport scaffolding # 1 + case types.MessageCreateDid: + res, err := msgServer.CreateDid(sdk.WrapSDKContext(ctx), parsedMsg) return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgDeleteNym: - res, err := msgServer.DeleteNym(sdk.WrapSDKContext(ctx), msg) + case types.MessageUpdateDid: + res, err := msgServer.UpdateDid(sdk.WrapSDKContext(ctx), parsedMsg) return sdk.WrapServiceResult(ctx, res, err) default: diff --git a/x/cheqd/keeper/did.go b/x/cheqd/keeper/did.go new file mode 100644 index 000000000..ce0f116de --- /dev/null +++ b/x/cheqd/keeper/did.go @@ -0,0 +1,93 @@ +package keeper + +import ( + "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "strconv" +) + +// GetDidCount get the total number of did +func (k Keeper) GetDidCount(ctx sdk.Context) uint64 { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidCountKey)) + byteKey := types.KeyPrefix(types.DidCountKey) + bz := store.Get(byteKey) + + // Count doesn't exist: no element + if bz == nil { + return 0 + } + + // Parse bytes + count, err := strconv.ParseUint(string(bz), 10, 64) + if err != nil { + // Panic because the count should be always formattable to iint64 + panic("cannot decode count") + } + + return count +} + +// SetDidCount set the total number of did +func (k Keeper) SetDidCount(ctx sdk.Context, count uint64) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidCountKey)) + byteKey := types.KeyPrefix(types.DidCountKey) + bz := []byte(strconv.FormatUint(count, 10)) + store.Set(byteKey, bz) +} + +// AppendDid appends a did in the store with a new id and updates the count +func (k Keeper) AppendDid(ctx sdk.Context, did types.Did, metadata *types.Metadata) (*string, error) { + // Create the did + count := k.GetDidCount(ctx) + err := k.SetDid(ctx, did, metadata) + if err != nil { + return nil, err + } + + // Update did count + k.SetDidCount(ctx, count+1) + return &did.Id, nil +} + +// SetDid set a specific did in the store +func (k Keeper) SetDid(ctx sdk.Context, did types.Did, metadata *types.Metadata) error { + stateValue, err := types.NewStateValue(&did, metadata) + if err != nil { + return types.ErrSetToState.Wrap(err.Error()) + } + + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey)) + b := k.cdc.MustMarshal(stateValue) + store.Set(GetDidIDBytes(did.Id), b) + return nil +} + +// GetDid returns a did from its id +func (k Keeper) GetDid(ctx *sdk.Context, id string) (*types.StateValue, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey)) + + if !k.HasDid(*ctx, id) { + return nil, sdkerrors.ErrNotFound + } + + var value types.StateValue + var bytes = store.Get(GetDidIDBytes(id)) + if err := k.cdc.Unmarshal(bytes, &value); err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidType, err.Error()) + } + + return &value, nil +} + +// HasDid checks if the did exists in the store +func (k Keeper) HasDid(ctx sdk.Context, id string) bool { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey)) + return store.Has(GetDidIDBytes(id)) +} + +// GetDidIDBytes returns the byte representation of the ID +func GetDidIDBytes(id string) []byte { + return []byte(id) +} diff --git a/x/cheqd/keeper/grpc_query_did.go b/x/cheqd/keeper/grpc_query_did.go new file mode 100644 index 000000000..e5cfa8d27 --- /dev/null +++ b/x/cheqd/keeper/grpc_query_did.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "context" + + "github.com/cheqd/cheqd-node/x/cheqd/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) Did(c context.Context, req *types.QueryGetDidRequest) (*types.QueryGetDidResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(c) + + state, err := k.GetDid(&ctx, req.Id) + if err != nil { + return nil, err + } + + did, err := state.GetDid() + if err != nil { + return nil, err + } + + return &types.QueryGetDidResponse{Did: did, Metadata: state.Metadata}, nil +} diff --git a/x/cheqd/keeper/grpc_query_nym.go b/x/cheqd/keeper/grpc_query_nym.go deleted file mode 100644 index 742275f76..000000000 --- a/x/cheqd/keeper/grpc_query_nym.go +++ /dev/null @@ -1,59 +0,0 @@ -package keeper - -import ( - "context" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/query" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func (k Keeper) NymAll(c context.Context, req *types.QueryAllNymRequest) (*types.QueryAllNymResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - var nyms []*types.Nym - ctx := sdk.UnwrapSDKContext(c) - - store := ctx.KVStore(k.storeKey) - nymStore := prefix.NewStore(store, types.KeyPrefix(types.NymKey)) - - pageRes, err := query.Paginate(nymStore, req.Pagination, func(key []byte, value []byte) error { - var nym types.Nym - if err := k.cdc.Unmarshal(value, &nym); err != nil { - return err - } - - nyms = append(nyms, &nym) - return nil - }) - - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryAllNymResponse{Nym: nyms, Pagination: pageRes}, nil -} - -func (k Keeper) Nym(c context.Context, req *types.QueryGetNymRequest) (*types.QueryGetNymResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - var nym types.Nym - ctx := sdk.UnwrapSDKContext(c) - - if !k.HasNym(ctx, req.Id) { - return nil, sdkerrors.ErrKeyNotFound - } - - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - k.cdc.MustUnmarshal(store.Get(GetNymIDBytes(req.Id)), &nym) - - return &types.QueryGetNymResponse{Nym: &nym}, nil -} diff --git a/x/cheqd/keeper/keeper.go b/x/cheqd/keeper/keeper.go index a6fb59069..384aa2b6b 100644 --- a/x/cheqd/keeper/keeper.go +++ b/x/cheqd/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/libs/log" @@ -14,18 +15,29 @@ type ( Keeper struct { cdc codec.Codec storeKey sdk.StoreKey - memKey sdk.StoreKey } ) -func NewKeeper(cdc codec.Codec, storeKey, memKey sdk.StoreKey) *Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, - memKey: memKey, } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// IsDidUsed checks if the did is used by DIDDoc +func (k Keeper) IsDidUsed(ctx sdk.Context, did string) bool { + return k.HasDid(ctx, did) +} + +func (k Keeper) EnsureDidIsNotUsed(ctx sdk.Context, did string) error { + if k.HasDid(ctx, did) { + return sdkerrors.Wrap(types.ErrDidDocExists, fmt.Sprintf("DID is already used by DIDDoc %s", did)) + } + + return nil +} diff --git a/x/cheqd/keeper/msg_server_did.go b/x/cheqd/keeper/msg_server_did.go new file mode 100644 index 000000000..d1f187042 --- /dev/null +++ b/x/cheqd/keeper/msg_server_did.go @@ -0,0 +1,194 @@ +package keeper + +import ( + "context" + "fmt" + "github.com/cheqd/cheqd-node/x/cheqd/utils/strings" + "reflect" + + "github.com/cheqd/cheqd-node/x/cheqd/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (k msgServer) CreateDid(goCtx context.Context, msg *types.MsgWriteRequest) (*types.MsgCreateDidResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + prefix := types.DidPrefix + ":" + types.DidMethod + ":" + ctx.ChainID() + ":" + + var didMsg types.MsgCreateDid + err := k.cdc.Unmarshal(msg.Data.Value, &didMsg) + if err != nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) + } + + if err := didMsg.Validate(prefix); err != nil { + return nil, err + } + + if err := k.VerifySignature(&ctx, &didMsg, didMsg.GetSigners(), msg.GetSignatures()); err != nil { + return nil, err + } + + // Checks that the did doesn't exist + if err := k.EnsureDidIsNotUsed(ctx, didMsg.Id); err != nil { + return nil, err + } + + var did = types.Did{ + Id: didMsg.Id, + Controller: didMsg.Controller, + VerificationMethod: didMsg.VerificationMethod, + Authentication: didMsg.Authentication, + AssertionMethod: didMsg.AssertionMethod, + CapabilityInvocation: didMsg.CapabilityInvocation, + CapabilityDelegation: didMsg.CapabilityDelegation, + KeyAgreement: didMsg.KeyAgreement, + AlsoKnownAs: didMsg.AlsoKnownAs, + Service: didMsg.Service, + Context: didMsg.Context, + } + + metadata := types.NewMetadata(ctx) + id, err := k.AppendDid(ctx, did, &metadata) + if err != nil { + return nil, err + } + + return &types.MsgCreateDidResponse{ + Id: *id, + }, nil +} + +func (k msgServer) UpdateDid(goCtx context.Context, msg *types.MsgWriteRequest) (*types.MsgUpdateDidResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + prefix := types.DidPrefix + ":" + types.DidMethod + ":" + ctx.ChainID() + ":" + + var didMsg types.MsgUpdateDid + err := k.cdc.Unmarshal(msg.Data.Value, &didMsg) + if err != nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) + } + + if err := didMsg.Validate(prefix); err != nil { + return nil, err + } + + // Checks that the did doesn't exist + if !k.HasDid(ctx, didMsg.Id) { + return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %s doesn't exist", didMsg.Id)) + } + + oldStateValue, err := k.GetDid(&ctx, didMsg.Id) + if err != nil { + return nil, err + } + + oldDIDDoc, err := oldStateValue.GetDid() + if err != nil { + return nil, err + } + + if err := k.VerifySignatureOnDidUpdate(&ctx, oldDIDDoc, &didMsg, msg.Signatures); err != nil { + return nil, err + } + + // replay protection + if oldStateValue.Metadata.VersionId != didMsg.VersionId { + errMsg := fmt.Sprintf("Ecpected %s with version %s. Got version %s", didMsg.Id, oldStateValue.Metadata.VersionId, didMsg.VersionId) + return nil, sdkerrors.Wrap(types.ErrUnexpectedDidVersion, errMsg) + } + + var did = types.Did{ + Id: didMsg.Id, + Controller: didMsg.Controller, + VerificationMethod: didMsg.VerificationMethod, + Authentication: didMsg.Authentication, + AssertionMethod: didMsg.AssertionMethod, + CapabilityInvocation: didMsg.CapabilityInvocation, + CapabilityDelegation: didMsg.CapabilityDelegation, + KeyAgreement: didMsg.KeyAgreement, + AlsoKnownAs: didMsg.AlsoKnownAs, + Service: didMsg.Service, + Context: didMsg.Context, + } + + metadata := types.NewMetadata(ctx) + metadata.Created = oldStateValue.Metadata.Created + metadata.Deactivated = oldStateValue.Metadata.Deactivated + + if err = k.SetDid(ctx, did, &metadata); err != nil { + return nil, err + } + + return &types.MsgUpdateDidResponse{ + Id: didMsg.Id, + }, nil +} + +func (k msgServer) VerifySignatureOnDidUpdate(ctx *sdk.Context, oldDIDDoc *types.Did, newDIDDoc *types.MsgUpdateDid, signatures []*types.SignInfo) error { + var signers = newDIDDoc.GetSigners() + + // Get Old DID Doc controller if it's nil then assign self + oldController := oldDIDDoc.Controller + if len(oldController) == 0 { + oldController = []string{oldDIDDoc.Id} + } + + // Get New DID Doc controller if it's nil then assign self + newController := newDIDDoc.Controller + if len(newController) == 0 { + newController = []string{newDIDDoc.Id} + } + + // DID Doc controller has been changed + if removedControllers := strings.Complement(oldController, newController); len(removedControllers) > 0 { + for _, controller := range removedControllers { + signers = append(signers, types.Signer{Signer: controller}) + } + } + + for _, oldVM := range oldDIDDoc.VerificationMethod { + newVM := FindVerificationMethod(newDIDDoc.VerificationMethod, oldVM.Id) + + // Verification Method has been deleted + if newVM == nil { + signers = AppendSignerIfNeed(signers, oldVM.Controller, newDIDDoc) + continue + } + + // Verification Method has been changed + if !reflect.DeepEqual(oldVM, newVM) { + signers = AppendSignerIfNeed(signers, newVM.Controller, newDIDDoc) + } + + // Verification Method Controller has been changed, need to add old controller + if newVM.Controller != oldVM.Controller { + signers = AppendSignerIfNeed(signers, oldVM.Controller, newDIDDoc) + } + } + + if err := k.VerifySignature(ctx, newDIDDoc, signers, signatures); err != nil { + return err + } + + return nil +} + +func AppendSignerIfNeed(signers []types.Signer, controller string, msg *types.MsgUpdateDid) []types.Signer { + for _, signer := range signers { + if signer.Signer == controller { + return signers + } + } + + signer := types.Signer{ + Signer: controller, + } + + if controller == msg.Id { + signer.VerificationMethod = msg.VerificationMethod + signer.Authentication = msg.Authentication + } + + return append(signers, signer) +} diff --git a/x/cheqd/keeper/msg_server_nym.go b/x/cheqd/keeper/msg_server_nym.go deleted file mode 100644 index 0376050b7..000000000 --- a/x/cheqd/keeper/msg_server_nym.go +++ /dev/null @@ -1,56 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -func (k msgServer) CreateNym(goCtx context.Context, msg *types.MsgCreateNym) (*types.MsgCreateNymResponse, error) { - return nil, sdkerrors.Wrap(sdkerrors.ErrNotSupported, "NYM creation isn't supported") -} - -func (k msgServer) UpdateNym(goCtx context.Context, msg *types.MsgUpdateNym) (*types.MsgUpdateNymResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - var nym = types.Nym{ - Creator: msg.Creator, - Id: msg.Id, - Alias: msg.Alias, - Verkey: msg.Verkey, - Did: msg.Did, - Role: msg.Role, - } - - // Checks that the element exists - if !k.HasNym(ctx, msg.Id) { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id)) - } - - // Checks if the the msg sender is the same as the current owner - if msg.Creator != k.GetNymOwner(ctx, msg.Id) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - k.SetNym(ctx, nym) - - return &types.MsgUpdateNymResponse{}, nil -} - -func (k msgServer) DeleteNym(goCtx context.Context, msg *types.MsgDeleteNym) (*types.MsgDeleteNymResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - if !k.HasNym(ctx, msg.Id) { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id)) - } - if msg.Creator != k.GetNymOwner(ctx, msg.Id) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - k.RemoveNym(ctx, msg.Id) - - return &types.MsgDeleteNymResponse{}, nil -} diff --git a/x/cheqd/keeper/nym.go b/x/cheqd/keeper/nym.go deleted file mode 100644 index d961d6348..000000000 --- a/x/cheqd/keeper/nym.go +++ /dev/null @@ -1,129 +0,0 @@ -package keeper - -import ( - "encoding/binary" - "strconv" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GetNymCount get the total number of nym -func (k Keeper) GetNymCount(ctx sdk.Context) uint64 { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymCountKey)) - byteKey := types.KeyPrefix(types.NymCountKey) - bz := store.Get(byteKey) - - // Count doesn't exist: no element - if bz == nil { - return 0 - } - - // Parse bytes - count, err := strconv.ParseUint(string(bz), 10, 64) - if err != nil { - // Panic because the count should be always formattable to iint64 - panic("cannot decode count") - } - - return count -} - -// SetNymCount set the total number of nym -func (k Keeper) SetNymCount(ctx sdk.Context, count uint64) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymCountKey)) - byteKey := types.KeyPrefix(types.NymCountKey) - bz := []byte(strconv.FormatUint(count, 10)) - store.Set(byteKey, bz) -} - -// AppendNym appends a nym in the store with a new id and update the count -func (k Keeper) AppendNym( - ctx sdk.Context, - creator string, - alias string, - verkey string, - did string, - role string, -) uint64 { - // Create the nym - count := k.GetNymCount(ctx) - var nym = types.Nym{ - Creator: creator, - Id: count, - Alias: alias, - Verkey: verkey, - Did: did, - Role: role, - } - - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - value := k.cdc.MustMarshal(&nym) - store.Set(GetNymIDBytes(nym.Id), value) - - // Update nym count - k.SetNymCount(ctx, count+1) - - return count -} - -// SetNym set a specific nym in the store -func (k Keeper) SetNym(ctx sdk.Context, nym types.Nym) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - b := k.cdc.MustMarshal(&nym) - store.Set(GetNymIDBytes(nym.Id), b) -} - -// GetNym returns a nym from its id -func (k Keeper) GetNym(ctx sdk.Context, id uint64) types.Nym { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - var nym types.Nym - k.cdc.MustUnmarshal(store.Get(GetNymIDBytes(id)), &nym) - return nym -} - -// HasNym checks if the nym exists in the store -func (k Keeper) HasNym(ctx sdk.Context, id uint64) bool { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - return store.Has(GetNymIDBytes(id)) -} - -// GetNymOwner returns the creator of the nym -func (k Keeper) GetNymOwner(ctx sdk.Context, id uint64) string { - return k.GetNym(ctx, id).Creator -} - -// RemoveNym removes a nym from the store -func (k Keeper) RemoveNym(ctx sdk.Context, id uint64) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - store.Delete(GetNymIDBytes(id)) -} - -// GetAllNym returns all nym -func (k Keeper) GetAllNym(ctx sdk.Context) (list []types.Nym) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NymKey)) - iterator := sdk.KVStorePrefixIterator(store, []byte{}) - - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - var val types.Nym - k.cdc.MustUnmarshal(iterator.Value(), &val) - list = append(list, val) - } - - return -} - -// GetNymIDBytes returns the byte representation of the ID -func GetNymIDBytes(id uint64) []byte { - bz := make([]byte, 8) - binary.BigEndian.PutUint64(bz, id) - return bz -} - -// GetNymIDFromBytes returns ID in uint64 format from a byte array -func GetNymIDFromBytes(bz []byte) uint64 { - return binary.BigEndian.Uint64(bz) -} diff --git a/x/cheqd/keeper/query.go b/x/cheqd/keeper/query.go index f5d130fed..c4a323118 100644 --- a/x/cheqd/keeper/query.go +++ b/x/cheqd/keeper/query.go @@ -19,12 +19,8 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { ) switch path[0] { - // this line is used by starport scaffolding # 2 - case types.QueryGetNym: - return getNym(ctx, path[1], k, legacyQuerierCdc) - - case types.QueryListNym: - return listNym(ctx, k, legacyQuerierCdc) + case types.QueryGetDid: + return getDid(ctx, path[1], k, legacyQuerierCdc) default: err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) diff --git a/x/cheqd/keeper/query_did.go b/x/cheqd/keeper/query_did.go new file mode 100644 index 000000000..fd5b2913f --- /dev/null +++ b/x/cheqd/keeper/query_did.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func getDid(ctx sdk.Context, id string, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + if !keeper.HasDid(ctx, id) { + return nil, sdkerrors.ErrKeyNotFound + } + + msg, err := keeper.GetDid(&ctx, id) + if err != nil { + return nil, err + } + + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, msg) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + + return bz, nil +} diff --git a/x/cheqd/keeper/query_nym.go b/x/cheqd/keeper/query_nym.go deleted file mode 100644 index 0790c7b5b..000000000 --- a/x/cheqd/keeper/query_nym.go +++ /dev/null @@ -1,39 +0,0 @@ -package keeper - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "strconv" -) - -func listNym(ctx sdk.Context, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { - msgs := keeper.GetAllNym(ctx) - - bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, msgs) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return bz, nil -} - -func getNym(ctx sdk.Context, key string, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { - id, err := strconv.ParseUint(key, 10, 64) - if err != nil { - return nil, err - } - - if !keeper.HasNym(ctx, id) { - return nil, sdkerrors.ErrKeyNotFound - } - - msg := keeper.GetNym(ctx, id) - - bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, msg) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return bz, nil -} diff --git a/x/cheqd/keeper/utils.go b/x/cheqd/keeper/utils.go new file mode 100644 index 000000000..f9f9004a5 --- /dev/null +++ b/x/cheqd/keeper/utils.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "crypto/ed25519" + "github.com/cheqd/cheqd-node/x/cheqd/types" +) + +func FindPublicKey(signer types.Signer, id string) (ed25519.PublicKey, error) { + for _, authentication := range signer.Authentication { + if authentication == id { + vm := FindVerificationMethod(signer.VerificationMethod, id) + if vm == nil { + return nil, types.ErrVerificationMethodNotFound.Wrap(id) + } + return vm.GetPublicKey() + } + } + + return nil, types.ErrVerificationMethodNotFound.Wrap(id) +} + +func FindVerificationMethod(vms []*types.VerificationMethod, id string) *types.VerificationMethod { + for _, vm := range vms { + if vm.Id == id { + return vm + } + } + + return nil +} diff --git a/x/cheqd/keeper/verify.go b/x/cheqd/keeper/verify.go new file mode 100644 index 000000000..7a3ee6c31 --- /dev/null +++ b/x/cheqd/keeper/verify.go @@ -0,0 +1,80 @@ +package keeper + +import ( + "crypto/ed25519" + "encoding/base64" + "fmt" + "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/cheqd/cheqd-node/x/cheqd/utils" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (k *Keeper) VerifySignature(ctx *sdk.Context, msg types.IdentityMsg, signers []types.Signer, signatures []*types.SignInfo) error { + if len(signers) == 0 { + return types.ErrInvalidSignature.Wrap("At least one signer should be present") + } + + if len(signatures) == 0 { + return types.ErrInvalidSignature.Wrap("At least one signature should be present") + } + + signingInput := msg.GetSignBytes() + + for _, signer := range signers { + if signer.VerificationMethod == nil { + state, err := k.GetDid(ctx, signer.Signer) + if err != nil { + return types.ErrDidDocNotFound.Wrap(signer.Signer) + } + + didDoc, err := state.GetDid() + if err != nil { + return types.ErrDidDocNotFound.Wrap(signer.Signer) + } + + signer.Authentication = didDoc.Authentication + signer.VerificationMethod = didDoc.VerificationMethod + } + + valid, err := VerifyIdentitySignature(signer, signatures, signingInput) + if err != nil { + return sdkerrors.Wrap(types.ErrInvalidSignature, err.Error()) + } + + if !valid { + return sdkerrors.Wrap(types.ErrInvalidSignature, signer.Signer) + } + } + + return nil +} + +func VerifyIdentitySignature(signer types.Signer, signatures []*types.SignInfo, signingInput []byte) (bool, error) { + result := true + foundOne := false + + for _, info := range signatures { + did, _ := utils.SplitDidUrlIntoDidAndFragment(info.VerificationMethodId) + if did == signer.Signer { + pubKey, err := FindPublicKey(signer, info.VerificationMethodId) + if err != nil { + return false, err + } + + signature, err := base64.StdEncoding.DecodeString(info.Signature) + if err != nil { + return false, err + } + + result = result && ed25519.Verify(pubKey, signingInput, signature) + foundOne = true + } + } + + if !foundOne { + return false, fmt.Errorf("signature %s not found", signer.Signer) + } + + return result, nil +} diff --git a/x/cheqd/module.go b/x/cheqd/module.go index fc9fa31e2..f2a253d6b 100644 --- a/x/cheqd/module.go +++ b/x/cheqd/module.go @@ -12,8 +12,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" - "github.com/cheqd/cheqd-node/x/cheqd/client/cli" - "github.com/cheqd/cheqd-node/x/cheqd/client/rest" + // TODO implement client later + //"github.com/cheqd/cheqd-node/x/cheqd/client/cli" + //"github.com/cheqd/cheqd-node/x/cheqd/client/rest" "github.com/cheqd/cheqd-node/x/cheqd/keeper" "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/cosmos/cosmos-sdk/client" @@ -75,7 +76,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod // RegisterRESTRoutes registers the capability module's REST service handlers. func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { - rest.RegisterRoutes(clientCtx, rtr) + //rest.RegisterRoutes(clientCtx, rtr) } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. @@ -88,12 +89,14 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r // GetTxCmd returns the capability module's root tx command. func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() + //return cli.GetTxCmd() + return nil } // GetQueryCmd returns the capability module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(types.StoreKey) + //return cli.GetQueryCmd(types.StoreKey) + return nil } // ---------------------------------------------------------------------------- diff --git a/x/cheqd/tests/constants.go b/x/cheqd/tests/constants.go new file mode 100644 index 000000000..8edd81904 --- /dev/null +++ b/x/cheqd/tests/constants.go @@ -0,0 +1,16 @@ +package tests + +const ( + AliceDID = "did:cheqd:test:alice" + BobDID = "did:cheqd:test:bob" + CharlieDID = "did:cheqd:test:charlie" + AliceKey1 = AliceDID + "#key-1" + AliceKey2 = AliceDID + "#key-2" + BobKey1 = BobDID + "#key-1" + BobKey2 = BobDID + "#key-2" + BobKey3 = BobDID + "#key-3" + BobKey4 = BobDID + "#key-4" + CharlieKey1 = CharlieDID + "#key-1" + CharlieKey2 = CharlieDID + "#key-2" + CharlieKey3 = CharlieDID + "#key-3" +) diff --git a/x/cheqd/tests/handler_test.go b/x/cheqd/tests/handler_test.go new file mode 100644 index 000000000..c78b70cac --- /dev/null +++ b/x/cheqd/tests/handler_test.go @@ -0,0 +1,1055 @@ +package tests + +import ( + "crypto/ed25519" + "github.com/btcsuite/btcutil/base58" + "testing" + + "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/stretchr/testify/require" +) + +func TestCreateDID(t *testing.T) { + setup := Setup() + keys := setup.CreatePreparedDID() + + cases := []struct { + valid bool + name string + keys map[string]KeyPair + signers []string + msg *types.MsgCreateDid + errMsg string + }{ + { + valid: true, + name: "Works", + keys: map[string]KeyPair{ + "did:cheqd:test:123456qwertyui2#key-1": GenerateKeyPair(), + }, + signers: []string{"did:cheqd:test:123456qwertyui2#key-1"}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui2", + Authentication: []string{"did:cheqd:test:123456qwertyui2#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui2#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui2", + }, + }, + }, + }, + { + valid: true, + name: "Works with Key Agreement", + keys: map[string]KeyPair{ + "did:cheqd:test:KeyAgreement#key-1": GenerateKeyPair(), + AliceKey1: keys[AliceKey1], + }, + signers: []string{AliceKey1}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:KeyAgreement", + KeyAgreement: []string{"did:cheqd:test:KeyAgreement#key-1"}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:KeyAgreement#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:KeyAgreement", + }, + }, + }, + }, + { + valid: true, + name: "Works with Assertion Method", + keys: map[string]KeyPair{ + "did:cheqd:test:AssertionMethod#key-1": GenerateKeyPair(), + AliceKey1: keys[AliceKey1], + }, + signers: []string{AliceKey1}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:AssertionMethod", + AssertionMethod: []string{"did:cheqd:test:AssertionMethod#key-1"}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:AssertionMethod#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:AssertionMethod", + }, + }, + }, + }, + { + valid: true, + name: "Works with Capability Delegation", + keys: map[string]KeyPair{ + "did:cheqd:test:CapabilityDelegation#key-1": GenerateKeyPair(), + AliceKey1: keys[AliceKey1], + }, + signers: []string{AliceKey1}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:CapabilityDelegation", + CapabilityDelegation: []string{"did:cheqd:test:CapabilityDelegation#key-1"}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:CapabilityDelegation#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:CapabilityDelegation", + }, + }, + }, + }, + { + valid: true, + name: "Works with Capability Invocation", + keys: map[string]KeyPair{ + "did:cheqd:test:CapabilityInvocation#key-1": GenerateKeyPair(), + AliceKey1: keys[AliceKey1], + }, + signers: []string{AliceKey1}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:CapabilityInvocation", + CapabilityInvocation: []string{"did:cheqd:test:CapabilityInvocation#key-1"}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:CapabilityInvocation#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:CapabilityInvocation", + }, + }, + }, + }, + { + valid: true, + name: "With controller works", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, BobDID}, + }, + signers: []string{AliceKey1, BobKey3}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + BobKey3: keys[BobKey3], + }, + }, + { + valid: true, + name: "Full message works", + keys: map[string]KeyPair{ + "did:cheqd:test:123456qwertyui#key-1": GenerateKeyPair(), + "did:cheqd:test:123456qwertyui#key-2": GenerateKeyPair(), + "did:cheqd:test:123456qwertyui#key-3": GenerateKeyPair(), + "did:cheqd:test:123456qwertyui#key-4": GenerateKeyPair(), + "did:cheqd:test:123456qwertyui#key-5": GenerateKeyPair(), + AliceKey1: keys[AliceKey1], + BobKey1: keys[BobKey1], + BobKey2: keys[BobKey2], + BobKey3: keys[BobKey3], + CharlieKey1: keys[CharlieKey1], + CharlieKey2: keys[CharlieKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{ + "did:cheqd:test:123456qwertyui#key-1", + "did:cheqd:test:123456qwertyui#key-5", + AliceKey1, + BobKey1, + BobKey2, + BobKey3, + CharlieKey1, + CharlieKey2, + CharlieKey3, + }, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui", + Authentication: []string{ + "did:cheqd:test:123456qwertyui#key-1", + "did:cheqd:test:123456qwertyui#key-5", + }, + Context: []string{"abc", "de"}, + CapabilityInvocation: []string{"did:cheqd:test:123456qwertyui#key-2"}, + CapabilityDelegation: []string{"did:cheqd:test:123456qwertyui#key-3"}, + KeyAgreement: []string{"did:cheqd:test:123456qwertyui#key-4"}, + AlsoKnownAs: []string{"did:cheqd:test:123456eqweqwe"}, + Service: []*types.ServiceEndpoint{ + { + Id: "did:cheqd:test:123456qwertyui#service-1", + Type: "DIDCommMessaging", + ServiceEndpoint: "ServiceEndpoint", + }, + }, + Controller: []string{"did:cheqd:test:123456qwertyui", AliceDID, BobDID, CharlieDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + { + Id: "did:cheqd:test:123456qwertyui#key-2", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + { + Id: "did:cheqd:test:123456qwertyui#key-3", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + { + Id: "did:cheqd:test:123456qwertyui#key-4", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + { + Id: "did:cheqd:test:123456qwertyui#key-5", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + }, + { + valid: false, + name: "Second controller did not sign request", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, BobDID}, + }, + signers: []string{AliceKey1}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + }, + errMsg: "signature did:cheqd:test:bob not found: invalid signature detected", + }, + { + valid: false, + name: "Bad request", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + }, + signers: []string{AliceKey1}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + }, + errMsg: "The message must contain either a Controller or a Authentication: bad request", + }, + { + valid: false, + name: "No signature", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, BobDID}, + }, + errMsg: "At least one signature should be present: invalid signature detected", + }, + { + valid: false, + name: "Empty request", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, BobDID}, + }, + errMsg: "At least one signature should be present: invalid signature detected", + }, + { + valid: false, + name: "Controller not found", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, "did:cheqd:test:notfound"}, + }, + signers: []string{AliceKey1}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + }, + errMsg: "did:cheqd:test:notfound: DID Doc not found", + }, + { + valid: false, + name: "Wrong signature", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID}, + }, + signers: []string{AliceKey1}, + keys: map[string]KeyPair{ + AliceKey1: keys[BobKey1], + }, + errMsg: "did:cheqd:test:alice: invalid signature detected", + }, + { + valid: false, + name: "Controller verification method not found", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{BobDID}, + }, + signers: []string{BobKey4}, + keys: map[string]KeyPair{ + BobKey4: keys[BobKey4], + }, + errMsg: "did:cheqd:test:bob#key-4: verification method not found: invalid signature detected", + }, + { + valid: false, + name: "Second controller verification method not found", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, BobDID, CharlieDID}, + }, + signers: []string{AliceKey1, BobKey4, CharlieKey3}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + BobKey4: keys[BobKey4], + CharlieKey3: keys[CharlieKey3], + }, + errMsg: "did:cheqd:test:bob#key-4: verification method not found: invalid signature detected", + }, + { + valid: false, + name: "DID signed by wrong controller", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui", + Authentication: []string{"did:cheqd:test:123456qwertyui#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + signers: []string{AliceKey1}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + }, + errMsg: "signature did:cheqd:test:123456qwertyui not found: invalid signature detected", + }, + { + valid: false, + name: "DID self-signed by not existing verification method", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui", + Authentication: []string{"did:cheqd:test:123456qwertyui#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + signers: []string{"did:cheqd:test:123456qwertyui#key-2"}, + keys: map[string]KeyPair{ + "did:cheqd:test:123456qwertyui#key-2": GenerateKeyPair(), + }, + errMsg: "did:cheqd:test:123456qwertyui#key-2: verification method not found: invalid signature detected", + }, + { + valid: false, + name: "Self-signature not found", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui", + Controller: []string{AliceDID, "did:cheqd:test:123456qwertyui"}, + Authentication: []string{"did:cheqd:test:123456qwertyui#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + signers: []string{AliceKey1, "did:cheqd:test:123456qwertyui#key-2"}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + "did:cheqd:test:123456qwertyui#key-2": GenerateKeyPair(), + }, + errMsg: "did:cheqd:test:123456qwertyui#key-2: verification method not found: invalid signature detected", + }, + { + valid: false, + name: "DID Doc already exists", + keys: map[string]KeyPair{ + "did:cheqd:test:123456qwertyui#key-1": GenerateKeyPair(), + }, + signers: []string{"did:cheqd:test:123456qwertyui#key-1"}, + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:123456qwertyui", + Authentication: []string{"did:cheqd:test:123456qwertyui#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + errMsg: "DID is already used by DIDDoc did:cheqd:test:123456qwertyui: DID Doc exists", + }, + { + valid: false, + name: "Verification Method ID doesnt match", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, CharlieDID}, + Authentication: []string{"#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + signers: []string{AliceKey1, CharlieKey3}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + CharlieKey3: keys[CharlieKey3], + }, + errMsg: "did:cheqd:test:123456qwertyui#key-1 not belong did:cheqd:test:controller1 DID Doc: invalid verification method", + }, + { + valid: false, + name: "Full Verification Method ID doesnt match", + msg: &types.MsgCreateDid{ + Id: "did:cheqd:test:controller1", + Controller: []string{AliceDID, CharlieDID}, + Authentication: []string{"did:cheqd:test:123456qwertyui#key-1"}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:123456qwertyui#key-1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:123456qwertyui", + }, + }, + }, + signers: []string{AliceKey1, CharlieKey3}, + keys: map[string]KeyPair{ + AliceKey1: keys[AliceKey1], + CharlieKey3: keys[CharlieKey3], + }, + errMsg: "did:cheqd:test:123456qwertyui#key-1 not belong did:cheqd:test:controller1 DID Doc: invalid verification method", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + msg := tc.msg + + for _, vm := range msg.VerificationMethod { + vm.PublicKeyMultibase = "z" + base58.Encode(tc.keys[vm.Id].PublicKey) + } + + signerKeys := map[string]ed25519.PrivateKey{} + for _, signer := range tc.signers { + signerKeys[signer] = tc.keys[signer].PrivateKey + } + + did, err := setup.SendCreateDid(msg, signerKeys) + + if tc.valid { + require.Nil(t, err) + require.Equal(t, tc.msg.Id, did.Id) + require.Equal(t, tc.msg.Controller, did.Controller) + require.Equal(t, tc.msg.VerificationMethod, did.VerificationMethod) + require.Equal(t, tc.msg.Authentication, did.Authentication) + require.Equal(t, tc.msg.AssertionMethod, did.AssertionMethod) + require.Equal(t, tc.msg.CapabilityInvocation, did.CapabilityInvocation) + require.Equal(t, tc.msg.CapabilityDelegation, did.CapabilityDelegation) + require.Equal(t, tc.msg.KeyAgreement, did.KeyAgreement) + require.Equal(t, tc.msg.AlsoKnownAs, did.AlsoKnownAs) + require.Equal(t, tc.msg.Service, did.Service) + require.Equal(t, tc.msg.Context, did.Context) + } else { + require.Error(t, err) + require.Equal(t, tc.errMsg, err.Error()) + } + }) + } +} + +func TestUpdateDid(t *testing.T) { + setup := Setup() + keys := setup.CreatePreparedDID() + + cases := []struct { + valid bool + name string + keys map[string]KeyPair + signers []string + msg *types.MsgUpdateDid + errMsg string + }{ + { + valid: true, + name: "Works", + keys: map[string]KeyPair{ + AliceKey2: keys[AliceKey2], + }, + signers: []string{AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + valid: false, + name: "Try to add controller without self-signature", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + }, + signers: []string{BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID}, + Authentication: []string{AliceKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:alice not found: invalid signature detected", + }, + { + valid: false, + name: "Add controller and replace authentication without old signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey1: keys[AliceKey1], + }, + signers: []string{BobKey1, AliceKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID}, + Authentication: []string{AliceKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "did:cheqd:test:alice#key-1: verification method not found: invalid signature detected", + }, + { + valid: true, + name: "Add controller work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + }, + signers: []string{BobKey1, AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + valid: false, + name: "Add controller work without signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + }, + signers: []string{BobKey1, AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:charlie not found: invalid signature detected", + }, + { + valid: false, + name: "Replace controller work without new signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + }, + signers: []string{BobKey1, AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:charlie not found: invalid signature detected", + }, + { + valid: false, + name: "Replace controller without old signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:bob not found: invalid signature detected", + }, + { + valid: true, + name: "Replace controller work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + valid: true, + name: "Add second controller works", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + valid: true, + name: "Add verification method without signature controller work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey1: keys[AliceKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + KeyAgreement: []string{AliceKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + valid: false, + name: "Remove verification method without signature controller do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey1: keys[AliceKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:alice not found: invalid signature detected", + }, + { + valid: false, + name: "Remove verification method wrong authentication detected", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey1: keys[AliceKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey1, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "did:cheqd:test:alice#key-1: verification method not found: invalid signature detected", + }, + { + valid: true, + name: "Add second authentication works", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey1: keys[AliceKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey1, AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + }, + { + valid: false, + name: "Remove self authentication without signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:alice not found: invalid signature detected", + }, + { + valid: false, + name: "Change self controller verification without signature do not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey1, AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: CharlieDID, + }, + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:alice not found: invalid signature detected", + }, + { + valid: true, + name: "Remove self authentication works", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Controller: []string{BobDID, CharlieDID}, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + }, + { + valid: false, + name: "Change controller to self without old controllers signatures does not work", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:bob not found: invalid signature detected", + }, + { + valid: true, + name: "Change controller to self works", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + }, + { + valid: false, + name: "Change verification method controller without old signature", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: CharlieDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:bob not found: invalid signature detected", + }, + { + valid: false, + name: "Change verification method controller without new signature", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, BobKey1}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: CharlieDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:charlie not found: invalid signature detected", + }, + { + valid: true, + name: "Change verification method controller", + keys: map[string]KeyPair{ + BobKey1: keys[BobKey1], + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, BobKey1, CharlieKey3}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: CharlieDID, + }, + }, + }, + }, + { + valid: false, + name: "Change to self verification method without controller signature", + keys: map[string]KeyPair{ + AliceKey2: keys[AliceKey2], + }, + signers: []string{AliceKey2}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + errMsg: "signature did:cheqd:test:charlie not found: invalid signature detected", + }, + { + valid: true, + name: "Change to self verification method without controller signature", + keys: map[string]KeyPair{ + AliceKey2: keys[AliceKey2], + CharlieKey3: keys[CharlieKey3], + }, + signers: []string{AliceKey2, CharlieKey3}, + msg: &types.MsgUpdateDid{ + Id: AliceDID, + Authentication: []string{AliceKey2}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + msg := tc.msg + + for _, vm := range msg.VerificationMethod { + vm.PublicKeyMultibase = "z" + base58.Encode(tc.keys[vm.Id].PublicKey) + } + + signerKeys := map[string]ed25519.PrivateKey{} + for _, signer := range tc.signers { + signerKeys[signer] = tc.keys[signer].PrivateKey + } + + did, err := setup.SendUpdateDid(msg, signerKeys) + + if tc.valid { + require.Nil(t, err) + require.Equal(t, tc.msg.Id, did.Id) + require.Equal(t, tc.msg.Controller, did.Controller) + require.Equal(t, tc.msg.VerificationMethod, did.VerificationMethod) + require.Equal(t, tc.msg.Authentication, did.Authentication) + require.Equal(t, tc.msg.AssertionMethod, did.AssertionMethod) + require.Equal(t, tc.msg.CapabilityInvocation, did.CapabilityInvocation) + require.Equal(t, tc.msg.CapabilityDelegation, did.CapabilityDelegation) + require.Equal(t, tc.msg.KeyAgreement, did.KeyAgreement) + require.Equal(t, tc.msg.AlsoKnownAs, did.AlsoKnownAs) + require.Equal(t, tc.msg.Service, did.Service) + require.Equal(t, tc.msg.Context, did.Context) + } else { + require.Error(t, err) + require.Equal(t, tc.errMsg, err.Error()) + } + }) + } +} + +func TestHandler_DidDocAlreadyExists(t *testing.T) { + setup := Setup() + + _, _, _ = setup.InitDid("did:cheqd:test:alice") + _, _, err := setup.InitDid("did:cheqd:test:alice") + + require.Error(t, err) + require.Equal(t, "DID is already used by DIDDoc did:cheqd:test:alice: DID Doc exists", err.Error()) +} diff --git a/x/cheqd/tests/handler_test_setup.go b/x/cheqd/tests/handler_test_setup.go new file mode 100644 index 000000000..38abdc74e --- /dev/null +++ b/x/cheqd/tests/handler_test_setup.go @@ -0,0 +1,342 @@ +package tests + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/base64" + "github.com/btcsuite/btcutil/base58" + "github.com/cheqd/cheqd-node/x/cheqd" + "time" + + "github.com/cheqd/cheqd-node/app/params" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" + + "github.com/cheqd/cheqd-node/x/cheqd/keeper" + "github.com/cheqd/cheqd-node/x/cheqd/types" + ptypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type KeyPair struct { + PrivateKey ed25519.PrivateKey + PublicKey ed25519.PublicKey +} + +type TestSetup struct { + Cdc codec.Codec + Ctx sdk.Context + Keeper keeper.Keeper + Handler sdk.Handler +} + +func Setup() TestSetup { + // Init Codec + encodingConfig := params.MakeEncodingConfig() + cdc := encodingConfig.Codec + + // Init KVSore + db := dbm.NewMemDB() + + dbStore := store.NewCommitMultiStore(db) + storeKey := sdk.NewKVStoreKey(types.StoreKey) + dbStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, nil) + + _ = dbStore.LoadLatestVersion() + + // Init Keepers + newKeeper := keeper.NewKeeper(cdc, storeKey) + + // Create Tx + txBytes := make([]byte, 28) + _, _ = rand.Read(txBytes) + + // Create context + blockTime, _ := time.Parse(time.RFC3339, "2021-01-01T00:00:00.000Z") + ctx := sdk.NewContext(dbStore, + tmproto.Header{ChainID: "test", Time: blockTime}, + false, log.NewNopLogger()).WithTxBytes(txBytes) + + handler := cheqd.NewHandler(*newKeeper) + + setup := TestSetup{ + Cdc: cdc, + Ctx: ctx, + Keeper: *newKeeper, + Handler: handler, + } + + return setup +} + +func (s *TestSetup) CreateDid(pubKey ed25519.PublicKey, did string) *types.MsgCreateDid { + PublicKeyMultibase := "z" + base58.Encode(pubKey) + + VerificationMethod := types.VerificationMethod{ + Id: did + "#key-1", + Type: "Ed25519VerificationKey2020", + Controller: did, + PublicKeyMultibase: PublicKeyMultibase, + } + + Service := types.ServiceEndpoint{ + Id: "#service-2", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + + return &types.MsgCreateDid{ + Id: did, + Controller: nil, + VerificationMethod: []*types.VerificationMethod{&VerificationMethod}, + Authentication: []string{did + "#key-1"}, + AssertionMethod: []string{did + "#key-1"}, + CapabilityInvocation: []string{did + "#key-1"}, + CapabilityDelegation: []string{did + "#key-1"}, + KeyAgreement: []string{did + "#key-1"}, + AlsoKnownAs: []string{did + "#key-1"}, + Context: []string{"Context"}, + Service: []*types.ServiceEndpoint{&Service}, + } +} + +func (s *TestSetup) CreateToUpdateDid(did *types.MsgCreateDid) *types.MsgUpdateDid { + return &types.MsgUpdateDid{ + Id: did.Id, + Controller: did.Controller, + VerificationMethod: did.VerificationMethod, + Authentication: did.Authentication, + AssertionMethod: did.AssertionMethod, + CapabilityInvocation: did.CapabilityInvocation, + CapabilityDelegation: did.CapabilityDelegation, + KeyAgreement: did.KeyAgreement, + AlsoKnownAs: did.AlsoKnownAs, + Service: did.Service, + Context: did.Context, + } +} + +func (s *TestSetup) WrapRequest(data *ptypes.Any, keys map[string]ed25519.PrivateKey) *types.MsgWriteRequest { + result := types.MsgWriteRequest{ + Data: data, + } + + var signatures []*types.SignInfo + signingInput := result.Data.Value + + for privKeyId, privKey := range keys { + signature := base64.StdEncoding.EncodeToString(ed25519.Sign(privKey, signingInput)) + signatures = append(signatures, &types.SignInfo{ + VerificationMethodId: privKeyId, + Signature: signature, + }) + } + + return &types.MsgWriteRequest{ + Data: data, + Signatures: signatures, + } +} + +func GenerateKeyPair() KeyPair { + PublicKey, PrivateKey, _ := ed25519.GenerateKey(rand.Reader) + return KeyPair{PrivateKey, PublicKey} +} + +func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.MsgCreateDid, error) { + pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) + + // add new Did + didMsg := s.CreateDid(pubKey, did) + data, err := ptypes.NewAnyWithValue(didMsg) + if err != nil { + return nil, nil, err + } + + keyId := did + "#key-1" + keys := map[string]ed25519.PrivateKey{keyId: privKey} + + result, err := s.Handler(s.Ctx, s.WrapRequest(data, keys)) + if err != nil { + return nil, nil, err + } + + didResponse := types.MsgCreateDidResponse{} + if err := didResponse.Unmarshal(result.Data); err != nil { + return nil, nil, err + } + + return keys, didMsg, nil +} + +func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDid, keys map[string]ed25519.PrivateKey) (*types.Did, error) { + // query Did + state, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) + if len(msg.VersionId) == 0 { + msg.VersionId = state.Metadata.VersionId + } + + data, err := ptypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + _, err = s.Handler(s.Ctx, s.WrapRequest(data, keys)) + if err != nil { + return nil, err + } + + updated, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) + return updated.GetDid() +} + +func (s *TestSetup) SendCreateDid(msg *types.MsgCreateDid, keys map[string]ed25519.PrivateKey) (*types.Did, error) { + data, err := ptypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + _, err = s.Handler(s.Ctx, s.WrapRequest(data, keys)) + if err != nil { + return nil, err + } + + created, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) + return created.GetDid() +} + +func ConcatKeys(dst map[string]ed25519.PrivateKey, src map[string]ed25519.PrivateKey) map[string]ed25519.PrivateKey { + for k, v := range src { + dst[k] = v + } + + return dst +} + +func (s TestSetup) CreatePreparedDID() map[string]KeyPair { + prefilledDids := []struct { + keys map[string]KeyPair + signers []string + msg *types.MsgCreateDid + }{ + { + keys: map[string]KeyPair{ + AliceKey1: GenerateKeyPair(), + AliceKey2: GenerateKeyPair(), + }, + signers: []string{AliceKey1}, + msg: &types.MsgCreateDid{ + Id: AliceDID, + Authentication: []string{AliceKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: "Ed25519VerificationKey2020", + Controller: AliceDID, + }, + }, + }, + }, + { + keys: map[string]KeyPair{ + BobKey1: GenerateKeyPair(), + BobKey2: GenerateKeyPair(), + BobKey3: GenerateKeyPair(), + BobKey4: GenerateKeyPair(), + }, + signers: []string{BobKey2}, + msg: &types.MsgCreateDid{ + Id: BobDID, + Authentication: []string{ + BobKey1, + BobKey2, + BobKey3, + }, + CapabilityDelegation: []string{ + BobKey4, + }, + VerificationMethod: []*types.VerificationMethod{ + { + Id: BobKey1, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + { + Id: BobKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + { + Id: BobKey3, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + { + Id: BobKey4, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + }, + { + keys: map[string]KeyPair{ + CharlieKey1: GenerateKeyPair(), + CharlieKey2: GenerateKeyPair(), + CharlieKey3: GenerateKeyPair(), + }, + signers: []string{CharlieKey2}, + msg: &types.MsgCreateDid{ + Id: CharlieDID, + Authentication: []string{ + CharlieKey1, + CharlieKey2, + CharlieKey3, + }, + VerificationMethod: []*types.VerificationMethod{ + { + Id: CharlieKey1, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + { + Id: CharlieKey2, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + { + Id: CharlieKey3, + Type: "Ed25519VerificationKey2020", + Controller: BobDID, + }, + }, + }, + }, + } + + keys := map[string]KeyPair{} + + for _, prefilled := range prefilledDids { + msg := prefilled.msg + + for _, vm := range msg.VerificationMethod { + vm.PublicKeyMultibase = "z" + base58.Encode(prefilled.keys[vm.Id].PublicKey) + } + + signerKeys := map[string]ed25519.PrivateKey{} + for _, signer := range prefilled.signers { + signerKeys[signer] = prefilled.keys[signer].PrivateKey + } + + for keyId, key := range prefilled.keys { + keys[keyId] = key + } + + _, _ = s.SendCreateDid(msg, signerKeys) + } + + return keys +} diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go new file mode 100644 index 000000000..4d6e6c97d --- /dev/null +++ b/x/cheqd/tests/signature_verification_test.go @@ -0,0 +1,136 @@ +package tests + +import ( + "crypto/ed25519" + "crypto/rand" + "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/stretchr/testify/require" + "reflect" + "testing" +) + +func TestDIDDocControllerChanged(t *testing.T) { + setup := Setup() + + //Init did + aliceKeys, aliceDid, _ := setup.InitDid("did:cheqd:test:alice") + bobKeys, _, _ := setup.InitDid("did:cheqd:test:bob") + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Controller = append(updatedDidDoc.Controller, "did:cheqd:test:bob") + receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, ConcatKeys(aliceKeys, bobKeys)) + + // check + require.NotEqual(t, aliceDid.Controller, receivedDid.Controller) + require.NotEqual(t, []string{"did:cheqd:test:alice", "did:cheqd:test:bob"}, receivedDid.Controller) + require.Equal(t, []string{"did:cheqd:test:bob"}, receivedDid.Controller) +} + +func TestDIDDocVerificationMethodChangedWithoutOldSignature(t *testing.T) { + setup := Setup() + + //Init did + _, aliceDid, _ := setup.InitDid("did:cheqd:test:alice") + bobKeys, _, _ := setup.InitDid("did:cheqd:test:bob") + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod[0].Type = "Ed25519VerificationKey2020" + _, err := setup.SendUpdateDid(updatedDidDoc, bobKeys) + + // check + require.Error(t, err) + require.Equal(t, "signature did:cheqd:test:alice not found: invalid signature detected", err.Error()) +} + +func TestDIDDocVerificationMethodControllerChangedWithoutOldSignature(t *testing.T) { + setup := Setup() + + //Init did + _, aliceDid, _ := setup.InitDid("did:cheqd:test:alice") + bobKeys, _, _ := setup.InitDid("did:cheqd:test:bob") + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod[0].Controller = "did:cheqd:test:bob" + _, err := setup.SendUpdateDid(updatedDidDoc, bobKeys) + + // check + require.Error(t, err) + require.Equal(t, "signature did:cheqd:test:alice not found: invalid signature detected", err.Error()) +} + +func TestDIDDocControllerChangedWithoutOldSignature(t *testing.T) { + setup := Setup() + + //Init did + _, aliceDid, _ := setup.InitDid("did:cheqd:test:alice") + bobKeys, _, _ := setup.InitDid("did:cheqd:test:bob") + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Controller = append(updatedDidDoc.Controller, "did:cheqd:test:bob") + _, err := setup.SendUpdateDid(updatedDidDoc, bobKeys) + + // check + require.Error(t, err) + require.Equal(t, "signature did:cheqd:test:alice not found: invalid signature detected", err.Error()) +} + +func TestDIDDocVerificationMethodDeletedWithoutOldSignature(t *testing.T) { + setup := Setup() + + //Init did + _, bodDidDoc, _ := setup.InitDid("did:cheqd:test:bob") + + pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) + aliceDid := setup.CreateDid(pubKey, "did:cheqd:test:alice") + + aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ + Id: "did:cheqd:test:alice#key-2", + Controller: "did:cheqd:test:bob", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: bodDidDoc.VerificationMethod[0].PublicKeyMultibase, + }) + + aliceDid.Authentication = append(aliceDid.Authentication, "did:cheqd:test:alice#key-2") + + aliceKeys := map[string]ed25519.PrivateKey{"did:cheqd:test:alice#key-1": privKey} + _, _ = setup.SendCreateDid(aliceDid, aliceKeys) + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} + updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} + _, err := setup.SendUpdateDid(updatedDidDoc, aliceKeys) + + // check + require.Error(t, err) + require.Equal(t, "signature did:cheqd:test:bob not found: invalid signature detected", err.Error()) +} + +func TestDIDDocVerificationMethodDeleted(t *testing.T) { + setup := Setup() + + //Init did + bobKeys, bodDidDoc, _ := setup.InitDid("did:cheqd:test:bob") + + pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) + aliceDid := setup.CreateDid(pubKey, "did:cheqd:test:alice") + + aliceDid.Authentication = append(aliceDid.Authentication, "did:cheqd:test:alice#key-2") + aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ + Id: "did:cheqd:test:alice#key-2", + Controller: "did:cheqd:test:bob", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: bodDidDoc.VerificationMethod[0].PublicKeyMultibase, + }) + + aliceKeys := map[string]ed25519.PrivateKey{"did:cheqd:test:alice#key-1": privKey} + _, _ = setup.SendCreateDid(aliceDid, aliceKeys) + + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} + updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} + receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, ConcatKeys(aliceKeys, bobKeys)) + + // check + require.NotEqual(t, len(aliceDid.VerificationMethod), len(receivedDid.VerificationMethod)) + require.True(t, reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])) +} diff --git a/x/cheqd/types/codec.go b/x/cheqd/types/codec.go index 1f7a72c3a..e610f88ff 100644 --- a/x/cheqd/types/codec.go +++ b/x/cheqd/types/codec.go @@ -9,20 +9,19 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { // this line is used by starport scaffolding # 2 - cdc.RegisterConcrete(&MsgCreateNym{}, "cheqd/CreateNym", nil) - cdc.RegisterConcrete(&MsgUpdateNym{}, "cheqd/UpdateNym", nil) - cdc.RegisterConcrete(&MsgDeleteNym{}, "cheqd/DeleteNym", nil) - + cdc.RegisterConcrete(&MsgCreateDid{}, "cheqd/CreateDid", nil) + cdc.RegisterConcrete(&MsgUpdateDid{}, "cheqd/UpdateDid", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 registry.RegisterImplementations((*sdk.Msg)(nil), - &MsgCreateNym{}, - &MsgUpdateNym{}, - &MsgDeleteNym{}, + &MsgWriteRequest{}, ) + registry.RegisterInterface(MessageCreateDid, (*IdentityMsg)(nil), &MsgCreateDid{}) + registry.RegisterInterface(MessageUpdateDid, (*IdentityMsg)(nil), &MsgUpdateDid{}) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/cheqd/types/common.pb.go b/x/cheqd/types/common.pb.go new file mode 100644 index 000000000..a79926b07 --- /dev/null +++ b/x/cheqd/types/common.pb.go @@ -0,0 +1,366 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cheqd/common.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type KeyValuePair struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *KeyValuePair) Reset() { *m = KeyValuePair{} } +func (m *KeyValuePair) String() string { return proto.CompactTextString(m) } +func (*KeyValuePair) ProtoMessage() {} +func (*KeyValuePair) Descriptor() ([]byte, []int) { + return fileDescriptor_6b29d37841ff3c67, []int{0} +} +func (m *KeyValuePair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *KeyValuePair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_KeyValuePair.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *KeyValuePair) XXX_Merge(src proto.Message) { + xxx_messageInfo_KeyValuePair.Merge(m, src) +} +func (m *KeyValuePair) XXX_Size() int { + return m.Size() +} +func (m *KeyValuePair) XXX_DiscardUnknown() { + xxx_messageInfo_KeyValuePair.DiscardUnknown(m) +} + +var xxx_messageInfo_KeyValuePair proto.InternalMessageInfo + +func (m *KeyValuePair) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *KeyValuePair) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func init() { + proto.RegisterType((*KeyValuePair)(nil), "cheqdid.cheqdnode.cheqd.KeyValuePair") +} + +func init() { proto.RegisterFile("cheqd/common.proto", fileDescriptor_6b29d37841ff3c67) } + +var fileDescriptor_6b29d37841ff3c67 = []byte{ + // 164 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4a, 0xce, 0x48, 0x2d, + 0x4c, 0xd1, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, + 0x07, 0x8b, 0x65, 0xa6, 0xe8, 0x81, 0xe9, 0xbc, 0xfc, 0x94, 0x54, 0x08, 0x4b, 0xc9, 0x8c, 0x8b, + 0xc7, 0x3b, 0xb5, 0x32, 0x2c, 0x31, 0xa7, 0x34, 0x35, 0x20, 0x31, 0xb3, 0x48, 0x48, 0x80, 0x8b, + 0x39, 0x3b, 0xb5, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc4, 0x14, 0x12, 0xe1, 0x62, + 0x2d, 0x03, 0x49, 0x4b, 0x30, 0x81, 0xc5, 0x20, 0x1c, 0x27, 0xe7, 0x13, 0x8f, 0xe4, 0x18, 0x2f, + 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, + 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xd2, 0x4c, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x87, 0xba, 0x04, 0x44, 0xea, 0x82, 0x2c, 0xd5, 0xaf, 0x80, 0x0a, 0x95, 0x54, 0x16, 0xa4, + 0x16, 0x27, 0xb1, 0x81, 0x1d, 0x67, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xd6, 0xe2, 0x8e, + 0xb2, 0x00, 0x00, 0x00, +} + +func (m *KeyValuePair) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *KeyValuePair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *KeyValuePair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintCommon(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintCommon(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCommon(dAtA []byte, offset int, v uint64) int { + offset -= sovCommon(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *KeyValuePair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovCommon(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovCommon(uint64(l)) + } + return n +} + +func sovCommon(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCommon(x uint64) (n int) { + return sovCommon(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *KeyValuePair) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: KeyValuePair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: KeyValuePair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCommon + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCommon + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Key = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCommon + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCommon + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCommon(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCommon + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCommon(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommon + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommon + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommon + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCommon + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCommon + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCommon + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCommon = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCommon = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCommon = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cheqd/types/did.go b/x/cheqd/types/did.go new file mode 100644 index 000000000..752b2a0b9 --- /dev/null +++ b/x/cheqd/types/did.go @@ -0,0 +1,19 @@ +package types + +import "github.com/multiformats/go-multibase" + +func (v VerificationMethod) GetPublicKey() ([]byte, error) { + if len(v.PublicKeyMultibase) > 0 { + _, key, err := multibase.Decode(v.PublicKeyMultibase) + if err != nil { + return nil, ErrInvalidPublicKey.Wrapf("Cannot decode verification method '%s' public key", v.Id) + } + return key, nil + } + + if len(v.PublicKeyJwk) > 0 { + return nil, ErrInvalidPublicKey.Wrap("JWK format not supported") + } + + return nil, ErrInvalidPublicKey.Wrapf("verification method '%s' public key not found", v.Id) +} diff --git a/x/cheqd/types/did.pb.go b/x/cheqd/types/did.pb.go new file mode 100644 index 000000000..09af7a4af --- /dev/null +++ b/x/cheqd/types/did.pb.go @@ -0,0 +1,1559 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cheqd/did.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/codec/types" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Did struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Controller []string `protobuf:"bytes,2,rep,name=controller,proto3" json:"controller,omitempty"` + VerificationMethod []*VerificationMethod `protobuf:"bytes,3,rep,name=verification_method,json=verificationMethod,proto3" json:"verification_method,omitempty"` + Authentication []string `protobuf:"bytes,4,rep,name=authentication,proto3" json:"authentication,omitempty"` + AssertionMethod []string `protobuf:"bytes,5,rep,name=assertion_method,json=assertionMethod,proto3" json:"assertion_method,omitempty"` + CapabilityInvocation []string `protobuf:"bytes,6,rep,name=capability_invocation,json=capabilityInvocation,proto3" json:"capability_invocation,omitempty"` + CapabilityDelegation []string `protobuf:"bytes,7,rep,name=capability_delegation,json=capabilityDelegation,proto3" json:"capability_delegation,omitempty"` + KeyAgreement []string `protobuf:"bytes,8,rep,name=key_agreement,json=keyAgreement,proto3" json:"key_agreement,omitempty"` + Service []*ServiceEndpoint `protobuf:"bytes,9,rep,name=service,proto3" json:"service,omitempty"` + AlsoKnownAs []string `protobuf:"bytes,10,rep,name=also_known_as,json=alsoKnownAs,proto3" json:"also_known_as,omitempty"` + Context []string `protobuf:"bytes,11,rep,name=context,proto3" json:"context,omitempty"` +} + +func (m *Did) Reset() { *m = Did{} } +func (m *Did) String() string { return proto.CompactTextString(m) } +func (*Did) ProtoMessage() {} +func (*Did) Descriptor() ([]byte, []int) { + return fileDescriptor_382ab0c0f6b6850e, []int{0} +} +func (m *Did) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Did) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Did.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Did) XXX_Merge(src proto.Message) { + xxx_messageInfo_Did.Merge(m, src) +} +func (m *Did) XXX_Size() int { + return m.Size() +} +func (m *Did) XXX_DiscardUnknown() { + xxx_messageInfo_Did.DiscardUnknown(m) +} + +var xxx_messageInfo_Did proto.InternalMessageInfo + +func (m *Did) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Did) GetController() []string { + if m != nil { + return m.Controller + } + return nil +} + +func (m *Did) GetVerificationMethod() []*VerificationMethod { + if m != nil { + return m.VerificationMethod + } + return nil +} + +func (m *Did) GetAuthentication() []string { + if m != nil { + return m.Authentication + } + return nil +} + +func (m *Did) GetAssertionMethod() []string { + if m != nil { + return m.AssertionMethod + } + return nil +} + +func (m *Did) GetCapabilityInvocation() []string { + if m != nil { + return m.CapabilityInvocation + } + return nil +} + +func (m *Did) GetCapabilityDelegation() []string { + if m != nil { + return m.CapabilityDelegation + } + return nil +} + +func (m *Did) GetKeyAgreement() []string { + if m != nil { + return m.KeyAgreement + } + return nil +} + +func (m *Did) GetService() []*ServiceEndpoint { + if m != nil { + return m.Service + } + return nil +} + +func (m *Did) GetAlsoKnownAs() []string { + if m != nil { + return m.AlsoKnownAs + } + return nil +} + +func (m *Did) GetContext() []string { + if m != nil { + return m.Context + } + return nil +} + +type VerificationMethod struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + Controller string `protobuf:"bytes,3,opt,name=controller,proto3" json:"controller,omitempty"` + PublicKeyJwk []*KeyValuePair `protobuf:"bytes,4,rep,name=public_key_jwk,json=publicKeyJwk,proto3" json:"public_key_jwk,omitempty"` + PublicKeyMultibase string `protobuf:"bytes,5,opt,name=public_key_multibase,json=publicKeyMultibase,proto3" json:"public_key_multibase,omitempty"` +} + +func (m *VerificationMethod) Reset() { *m = VerificationMethod{} } +func (m *VerificationMethod) String() string { return proto.CompactTextString(m) } +func (*VerificationMethod) ProtoMessage() {} +func (*VerificationMethod) Descriptor() ([]byte, []int) { + return fileDescriptor_382ab0c0f6b6850e, []int{1} +} +func (m *VerificationMethod) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VerificationMethod) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VerificationMethod.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VerificationMethod) XXX_Merge(src proto.Message) { + xxx_messageInfo_VerificationMethod.Merge(m, src) +} +func (m *VerificationMethod) XXX_Size() int { + return m.Size() +} +func (m *VerificationMethod) XXX_DiscardUnknown() { + xxx_messageInfo_VerificationMethod.DiscardUnknown(m) +} + +var xxx_messageInfo_VerificationMethod proto.InternalMessageInfo + +func (m *VerificationMethod) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *VerificationMethod) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *VerificationMethod) GetController() string { + if m != nil { + return m.Controller + } + return "" +} + +func (m *VerificationMethod) GetPublicKeyJwk() []*KeyValuePair { + if m != nil { + return m.PublicKeyJwk + } + return nil +} + +func (m *VerificationMethod) GetPublicKeyMultibase() string { + if m != nil { + return m.PublicKeyMultibase + } + return "" +} + +type ServiceEndpoint struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + ServiceEndpoint string `protobuf:"bytes,3,opt,name=service_endpoint,json=serviceEndpoint,proto3" json:"service_endpoint,omitempty"` +} + +func (m *ServiceEndpoint) Reset() { *m = ServiceEndpoint{} } +func (m *ServiceEndpoint) String() string { return proto.CompactTextString(m) } +func (*ServiceEndpoint) ProtoMessage() {} +func (*ServiceEndpoint) Descriptor() ([]byte, []int) { + return fileDescriptor_382ab0c0f6b6850e, []int{2} +} +func (m *ServiceEndpoint) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ServiceEndpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ServiceEndpoint.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ServiceEndpoint) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServiceEndpoint.Merge(m, src) +} +func (m *ServiceEndpoint) XXX_Size() int { + return m.Size() +} +func (m *ServiceEndpoint) XXX_DiscardUnknown() { + xxx_messageInfo_ServiceEndpoint.DiscardUnknown(m) +} + +var xxx_messageInfo_ServiceEndpoint proto.InternalMessageInfo + +func (m *ServiceEndpoint) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *ServiceEndpoint) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *ServiceEndpoint) GetServiceEndpoint() string { + if m != nil { + return m.ServiceEndpoint + } + return "" +} + +func init() { + proto.RegisterType((*Did)(nil), "cheqdid.cheqdnode.cheqd.Did") + proto.RegisterType((*VerificationMethod)(nil), "cheqdid.cheqdnode.cheqd.VerificationMethod") + proto.RegisterType((*ServiceEndpoint)(nil), "cheqdid.cheqdnode.cheqd.ServiceEndpoint") +} + +func init() { proto.RegisterFile("cheqd/did.proto", fileDescriptor_382ab0c0f6b6850e) } + +var fileDescriptor_382ab0c0f6b6850e = []byte{ + // 520 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0x6f, 0x12, 0x41, + 0x14, 0xc7, 0x59, 0xb6, 0x2d, 0xf2, 0x68, 0xa1, 0x19, 0x6b, 0x1c, 0x7b, 0xd8, 0x10, 0x8c, 0x06, + 0x62, 0x04, 0xd3, 0x7e, 0x82, 0xd6, 0x7a, 0x50, 0xd2, 0xc4, 0x60, 0xd2, 0x83, 0x31, 0x59, 0x67, + 0x77, 0x5e, 0x61, 0x64, 0x77, 0x06, 0x77, 0x67, 0xa1, 0xfb, 0x2d, 0xfc, 0x58, 0x1e, 0x7b, 0xd3, + 0xa3, 0x81, 0x0f, 0xe1, 0xd5, 0xec, 0xec, 0x82, 0x08, 0x21, 0xf1, 0x02, 0xb3, 0xbf, 0xf7, 0xff, + 0xbf, 0x99, 0xf7, 0xe6, 0x0d, 0x34, 0xfc, 0x11, 0x7e, 0xe5, 0x3d, 0x2e, 0x78, 0x77, 0x12, 0x29, + 0xad, 0xc8, 0x63, 0x03, 0x04, 0xef, 0x9a, 0x7f, 0xa9, 0x38, 0xe6, 0xab, 0xd3, 0x27, 0x43, 0xa5, + 0x86, 0x01, 0xf6, 0x8c, 0xcc, 0x4b, 0x6e, 0x7b, 0x4c, 0xa6, 0xb9, 0xe7, 0x94, 0xe4, 0x49, 0x7c, + 0x15, 0x86, 0x4a, 0xe6, 0xac, 0xf5, 0xdb, 0x06, 0xfb, 0x4a, 0x70, 0x52, 0x87, 0xb2, 0xe0, 0xd4, + 0x6a, 0x5a, 0xed, 0xea, 0xa0, 0x2c, 0x38, 0x71, 0x00, 0x7c, 0x25, 0x75, 0xa4, 0x82, 0x00, 0x23, + 0x5a, 0x6e, 0xda, 0xed, 0xea, 0x60, 0x8d, 0x90, 0x4f, 0xf0, 0x70, 0x8a, 0x91, 0xb8, 0x15, 0x3e, + 0xd3, 0x42, 0x49, 0x37, 0x44, 0x3d, 0x52, 0x9c, 0xda, 0x4d, 0xbb, 0x5d, 0x3b, 0x7b, 0xd1, 0xdd, + 0x71, 0xba, 0xee, 0xcd, 0x9a, 0xe7, 0xda, 0x58, 0x06, 0x64, 0xba, 0xc5, 0xc8, 0x73, 0xa8, 0xb3, + 0x44, 0x8f, 0x50, 0xea, 0x82, 0xd3, 0x3d, 0x73, 0x82, 0x0d, 0x4a, 0x3a, 0x70, 0xcc, 0xe2, 0x18, + 0xa3, 0xf5, 0x23, 0xec, 0x1b, 0x65, 0x63, 0xc5, 0x8b, 0x94, 0xe7, 0xf0, 0xc8, 0x67, 0x13, 0xe6, + 0x89, 0x40, 0xe8, 0xd4, 0x15, 0x72, 0xaa, 0x8a, 0xcc, 0x07, 0x46, 0x7f, 0xf2, 0x37, 0xf8, 0x76, + 0x15, 0xdb, 0x30, 0x71, 0x0c, 0x70, 0x98, 0x9b, 0x2a, 0x9b, 0xa6, 0xab, 0x55, 0x8c, 0x3c, 0x85, + 0xa3, 0x31, 0xa6, 0x2e, 0x1b, 0x46, 0x88, 0x21, 0x4a, 0x4d, 0x1f, 0x18, 0xf1, 0xe1, 0x18, 0xd3, + 0x8b, 0x25, 0x23, 0x97, 0x50, 0x89, 0x31, 0x9a, 0x0a, 0x1f, 0x69, 0xd5, 0xf4, 0xac, 0xbd, 0xb3, + 0x67, 0x1f, 0x72, 0xdd, 0x1b, 0xc9, 0x27, 0x4a, 0x48, 0x3d, 0x58, 0x1a, 0x49, 0x0b, 0x8e, 0x58, + 0x10, 0x2b, 0x77, 0x2c, 0xd5, 0x4c, 0xba, 0x2c, 0xa6, 0x60, 0x36, 0xaa, 0x65, 0xb0, 0x9f, 0xb1, + 0x8b, 0x98, 0x50, 0xa8, 0x64, 0xb7, 0x86, 0x77, 0x9a, 0xd6, 0x4c, 0x74, 0xf9, 0xd9, 0xfa, 0x61, + 0x01, 0xd9, 0xbe, 0x8e, 0xad, 0x41, 0x20, 0xb0, 0xa7, 0xd3, 0x09, 0xd2, 0xb2, 0x21, 0x66, 0xbd, + 0x31, 0x1c, 0xb6, 0x89, 0xac, 0x0f, 0x47, 0x1f, 0xea, 0x93, 0xc4, 0x0b, 0x84, 0xef, 0x66, 0x8d, + 0xf8, 0x32, 0x1b, 0x9b, 0xeb, 0xab, 0x9d, 0x3d, 0xdb, 0x59, 0x63, 0x1f, 0xd3, 0x1b, 0x16, 0x24, + 0xf8, 0x9e, 0x89, 0x68, 0x70, 0x98, 0x9b, 0xfb, 0x98, 0xbe, 0x9b, 0x8d, 0xc9, 0x2b, 0x38, 0x59, + 0x4b, 0x16, 0x26, 0x81, 0x16, 0x1e, 0x8b, 0x91, 0xee, 0x9b, 0x6d, 0xc9, 0x4a, 0x7b, 0xbd, 0x8c, + 0xb4, 0x3e, 0x43, 0x63, 0xa3, 0x67, 0xff, 0x55, 0x55, 0x07, 0x8e, 0x8b, 0xce, 0xba, 0x58, 0xf8, + 0x8a, 0xda, 0x1a, 0xf1, 0xbf, 0xe9, 0x2e, 0x5f, 0x7f, 0x9f, 0x3b, 0xd6, 0xfd, 0xdc, 0xb1, 0x7e, + 0xcd, 0x1d, 0xeb, 0xdb, 0xc2, 0x29, 0xdd, 0x2f, 0x9c, 0xd2, 0xcf, 0x85, 0x53, 0xfa, 0xd8, 0x19, + 0x0a, 0x3d, 0x4a, 0xbc, 0xae, 0xaf, 0xc2, 0x5e, 0xf1, 0xdc, 0xb2, 0xdf, 0x97, 0x59, 0xad, 0xbd, + 0xbb, 0x02, 0x65, 0xdb, 0xc5, 0xde, 0x81, 0x79, 0x81, 0xe7, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, + 0xeb, 0x2c, 0x24, 0xc7, 0xdc, 0x03, 0x00, 0x00, +} + +func (m *Did) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Did) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Did) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Context) > 0 { + for iNdEx := len(m.Context) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Context[iNdEx]) + copy(dAtA[i:], m.Context[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.Context[iNdEx]))) + i-- + dAtA[i] = 0x5a + } + } + if len(m.AlsoKnownAs) > 0 { + for iNdEx := len(m.AlsoKnownAs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AlsoKnownAs[iNdEx]) + copy(dAtA[i:], m.AlsoKnownAs[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.AlsoKnownAs[iNdEx]))) + i-- + dAtA[i] = 0x52 + } + } + if len(m.Service) > 0 { + for iNdEx := len(m.Service) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Service[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDid(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + } + if len(m.KeyAgreement) > 0 { + for iNdEx := len(m.KeyAgreement) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.KeyAgreement[iNdEx]) + copy(dAtA[i:], m.KeyAgreement[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.KeyAgreement[iNdEx]))) + i-- + dAtA[i] = 0x42 + } + } + if len(m.CapabilityDelegation) > 0 { + for iNdEx := len(m.CapabilityDelegation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityDelegation[iNdEx]) + copy(dAtA[i:], m.CapabilityDelegation[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.CapabilityDelegation[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if len(m.CapabilityInvocation) > 0 { + for iNdEx := len(m.CapabilityInvocation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityInvocation[iNdEx]) + copy(dAtA[i:], m.CapabilityInvocation[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.CapabilityInvocation[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if len(m.AssertionMethod) > 0 { + for iNdEx := len(m.AssertionMethod) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AssertionMethod[iNdEx]) + copy(dAtA[i:], m.AssertionMethod[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.AssertionMethod[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.Authentication) > 0 { + for iNdEx := len(m.Authentication) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Authentication[iNdEx]) + copy(dAtA[i:], m.Authentication[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.Authentication[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.VerificationMethod) > 0 { + for iNdEx := len(m.VerificationMethod) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VerificationMethod[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDid(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Controller) > 0 { + for iNdEx := len(m.Controller) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Controller[iNdEx]) + copy(dAtA[i:], m.Controller[iNdEx]) + i = encodeVarintDid(dAtA, i, uint64(len(m.Controller[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintDid(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *VerificationMethod) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *VerificationMethod) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VerificationMethod) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PublicKeyMultibase) > 0 { + i -= len(m.PublicKeyMultibase) + copy(dAtA[i:], m.PublicKeyMultibase) + i = encodeVarintDid(dAtA, i, uint64(len(m.PublicKeyMultibase))) + i-- + dAtA[i] = 0x2a + } + if len(m.PublicKeyJwk) > 0 { + for iNdEx := len(m.PublicKeyJwk) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PublicKeyJwk[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDid(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.Controller) > 0 { + i -= len(m.Controller) + copy(dAtA[i:], m.Controller) + i = encodeVarintDid(dAtA, i, uint64(len(m.Controller))) + i-- + dAtA[i] = 0x1a + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintDid(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x12 + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintDid(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ServiceEndpoint) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ServiceEndpoint) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ServiceEndpoint) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ServiceEndpoint) > 0 { + i -= len(m.ServiceEndpoint) + copy(dAtA[i:], m.ServiceEndpoint) + i = encodeVarintDid(dAtA, i, uint64(len(m.ServiceEndpoint))) + i-- + dAtA[i] = 0x1a + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintDid(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x12 + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintDid(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintDid(dAtA []byte, offset int, v uint64) int { + offset -= sovDid(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Did) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + if len(m.Controller) > 0 { + for _, s := range m.Controller { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.VerificationMethod) > 0 { + for _, e := range m.VerificationMethod { + l = e.Size() + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.Authentication) > 0 { + for _, s := range m.Authentication { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.AssertionMethod) > 0 { + for _, s := range m.AssertionMethod { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.CapabilityInvocation) > 0 { + for _, s := range m.CapabilityInvocation { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.CapabilityDelegation) > 0 { + for _, s := range m.CapabilityDelegation { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.KeyAgreement) > 0 { + for _, s := range m.KeyAgreement { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.Service) > 0 { + for _, e := range m.Service { + l = e.Size() + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.AlsoKnownAs) > 0 { + for _, s := range m.AlsoKnownAs { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + if len(m.Context) > 0 { + for _, s := range m.Context { + l = len(s) + n += 1 + l + sovDid(uint64(l)) + } + } + return n +} + +func (m *VerificationMethod) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + l = len(m.Controller) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + if len(m.PublicKeyJwk) > 0 { + for _, e := range m.PublicKeyJwk { + l = e.Size() + n += 1 + l + sovDid(uint64(l)) + } + } + l = len(m.PublicKeyMultibase) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + return n +} + +func (m *ServiceEndpoint) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + l = len(m.ServiceEndpoint) + if l > 0 { + n += 1 + l + sovDid(uint64(l)) + } + return n +} + +func sovDid(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDid(x uint64) (n int) { + return sovDid(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Did) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Did: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Did: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Controller", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Controller = append(m.Controller, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationMethod", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VerificationMethod = append(m.VerificationMethod, &VerificationMethod{}) + if err := m.VerificationMethod[len(m.VerificationMethod)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authentication", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authentication = append(m.Authentication, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AssertionMethod", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssertionMethod = append(m.AssertionMethod, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityInvocation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CapabilityInvocation = append(m.CapabilityInvocation, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityDelegation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CapabilityDelegation = append(m.CapabilityDelegation, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KeyAgreement", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KeyAgreement = append(m.KeyAgreement, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Service", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Service = append(m.Service, &ServiceEndpoint{}) + if err := m.Service[len(m.Service)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AlsoKnownAs", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AlsoKnownAs = append(m.AlsoKnownAs, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Context = append(m.Context, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDid(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDid + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *VerificationMethod) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VerificationMethod: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VerificationMethod: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Controller", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Controller = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKeyJwk", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKeyJwk = append(m.PublicKeyJwk, &KeyValuePair{}) + if err := m.PublicKeyJwk[len(m.PublicKeyJwk)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKeyMultibase", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKeyMultibase = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDid(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDid + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ServiceEndpoint) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ServiceEndpoint: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ServiceEndpoint: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ServiceEndpoint", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ServiceEndpoint = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDid(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDid + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDid(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDid + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDid + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDid + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDid = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDid = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDid = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cheqd/types/errors.go b/x/cheqd/types/errors.go index 20213b8bb..88c0b1e75 100644 --- a/x/cheqd/types/errors.go +++ b/x/cheqd/types/errors.go @@ -8,5 +8,19 @@ import ( // x/cheqd module sentinel errors var ( - ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") + ErrBadRequest = sdkerrors.Register(ModuleName, 1000, "bad request") + ErrBadRequestIsRequired = sdkerrors.Register(ModuleName, 1001, "is required") + ErrBadRequestIsNotDid = sdkerrors.Register(ModuleName, 1002, "is not DID") + ErrBadRequestInvalidVerMethod = sdkerrors.Register(ModuleName, 1003, "invalid verification method") + ErrBadRequestInvalidService = sdkerrors.Register(ModuleName, 1004, "invalid service") + ErrBadRequestIsNotDidFragment = sdkerrors.Register(ModuleName, 1005, "is not DID fragment") + ErrInvalidSignature = sdkerrors.Register(ModuleName, 1100, "invalid signature detected") + ErrDidDocExists = sdkerrors.Register(ModuleName, 1200, "DID Doc exists") + ErrDidDocNotFound = sdkerrors.Register(ModuleName, 1201, "DID Doc not found") + ErrVerificationMethodNotFound = sdkerrors.Register(ModuleName, 1202, "verification method not found") + ErrUnexpectedDidVersion = sdkerrors.Register(ModuleName, 1203, "unexpected DID version") + ErrInvalidPublicKey = sdkerrors.Register(ModuleName, 1204, "invalid public key") + ErrInvalidDidStateValue = sdkerrors.Register(ModuleName, 1300, "invalid did state value") + ErrSetToState = sdkerrors.Register(ModuleName, 1304, "cannot set to state") + ErrNotImplemented = sdkerrors.Register(ModuleName, 1501, "not implemented") ) diff --git a/x/cheqd/types/genesis.go b/x/cheqd/types/genesis.go index f863e6807..a1a600376 100644 --- a/x/cheqd/types/genesis.go +++ b/x/cheqd/types/genesis.go @@ -1,9 +1,5 @@ package types -import ( - "fmt" -) - // DefaultIndex is the default capability global index const DefaultIndex uint64 = 1 @@ -11,7 +7,7 @@ const DefaultIndex uint64 = 1 func DefaultGenesis() *GenesisState { return &GenesisState{ // this line is used by starport scaffolding # genesis/types/default - NymList: []*Nym{}, + } } @@ -19,15 +15,7 @@ func DefaultGenesis() *GenesisState { // failure. func (gs GenesisState) Validate() error { // this line is used by starport scaffolding # genesis/types/validate - // Check for duplicated ID in nym - nymIdMap := make(map[uint64]bool) - - for _, elem := range gs.NymList { - if _, ok := nymIdMap[elem.Id]; ok { - return fmt.Errorf("duplicated id for nym") - } - nymIdMap[elem.Id] = true - } + // Check for duplicated ID in credDef return nil } diff --git a/x/cheqd/types/genesis.pb.go b/x/cheqd/types/genesis.pb.go index 3ef28b0ae..b73171728 100644 --- a/x/cheqd/types/genesis.pb.go +++ b/x/cheqd/types/genesis.pb.go @@ -24,8 +24,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the capability module's genesis state. type GenesisState struct { - // this line is used by starport scaffolding # genesis/proto/state - NymList []*Nym `protobuf:"bytes,1,rep,name=nymList,proto3" json:"nymList,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -61,13 +59,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetNymList() []*Nym { - if m != nil { - return m.NymList - } - return nil -} - func init() { proto.RegisterType((*GenesisState)(nil), "cheqdid.cheqdnode.cheqd.GenesisState") } @@ -75,18 +66,16 @@ func init() { func init() { proto.RegisterFile("cheqd/genesis.proto", fileDescriptor_125930f9f5015ae5) } var fileDescriptor_125930f9f5015ae5 = []byte{ - // 171 bytes of a gzipped FileDescriptorProto + // 141 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0xce, 0x48, 0x2d, 0x4c, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x07, 0x0b, 0x66, 0xa6, 0xe8, 0x81, 0xe9, 0xbc, 0xfc, 0x94, 0x54, 0x08, 0x4b, 0x8a, 0x1f, - 0xa2, 0x3a, 0xaf, 0x32, 0x17, 0xa2, 0x52, 0xc9, 0x8d, 0x8b, 0xc7, 0x1d, 0xa2, 0x35, 0xb8, 0x24, - 0xb1, 0x24, 0x55, 0xc8, 0x8c, 0x8b, 0x3d, 0xaf, 0x32, 0xd7, 0x27, 0xb3, 0xb8, 0x44, 0x82, 0x51, - 0x81, 0x59, 0x83, 0xdb, 0x48, 0x46, 0x0f, 0x87, 0x59, 0x7a, 0x7e, 0x95, 0xb9, 0x41, 0x30, 0xc5, - 0x4e, 0xce, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, - 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x99, 0x9e, 0x59, - 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0xb1, 0x1d, 0x4c, 0xea, 0x82, 0x4c, 0xd2, - 0xaf, 0x80, 0x0a, 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xdd, 0x64, 0x0c, 0x08, 0x00, - 0x00, 0xff, 0xff, 0x3b, 0xc6, 0xb7, 0xed, 0xd4, 0x00, 0x00, 0x00, + 0xa2, 0x1a, 0x24, 0x05, 0x56, 0xa9, 0xc4, 0xc7, 0xc5, 0xe3, 0x0e, 0xd1, 0x1a, 0x5c, 0x92, 0x58, + 0x92, 0xea, 0xe4, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x9a, 0xe9, + 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x10, 0x53, 0xc0, 0xa4, 0x2e, 0xc8, + 0x74, 0xfd, 0x0a, 0xa8, 0x50, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x6c, 0x63, 0x40, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x53, 0x0e, 0xbf, 0x9c, 0x00, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -109,20 +98,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.NymList) > 0 { - for iNdEx := len(m.NymList) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.NymList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } return len(dAtA) - i, nil } @@ -143,12 +118,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - if len(m.NymList) > 0 { - for _, e := range m.NymList { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } return n } @@ -187,40 +156,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NymList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NymList = append(m.NymList, &Nym{}) - if err := m.NymList[len(m.NymList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/cheqd/types/identity_msg.go b/x/cheqd/types/identity_msg.go new file mode 100644 index 000000000..f532c6959 --- /dev/null +++ b/x/cheqd/types/identity_msg.go @@ -0,0 +1,15 @@ +package types + +type ( + IdentityMsg interface { + Validate(namespace string) error + GetSigners() []Signer + GetSignBytes() []byte + } + + Signer struct { + Signer string + Authentication []string + VerificationMethod []*VerificationMethod + } +) diff --git a/x/cheqd/types/keys.go b/x/cheqd/types/keys.go index 9511d9455..5bd568d94 100644 --- a/x/cheqd/types/keys.go +++ b/x/cheqd/types/keys.go @@ -13,8 +13,9 @@ const ( // QuerierRoute defines the module's query routing key QuerierRoute = ModuleName - // MemStoreKey defines the in-memory store key - MemStoreKey = "mem_capability" + DidMethod = ModuleName + + DidPrefix = "did" ) func KeyPrefix(p string) []byte { @@ -22,6 +23,6 @@ func KeyPrefix(p string) []byte { } const ( - NymKey = "Nym-value-" - NymCountKey = "Nym-count-" + DidKey = "did:" + DidCountKey = "did-count:" ) diff --git a/x/cheqd/types/messages.go b/x/cheqd/types/messages.go new file mode 100644 index 000000000..9fbe723d9 --- /dev/null +++ b/x/cheqd/types/messages.go @@ -0,0 +1,9 @@ +package types + +const ( + MessageCreateDid = "/cheqdid.cheqdnode.cheqd.MsgCreateDid" +) + +const ( + MessageUpdateDid = "/cheqdid.cheqdnode.cheqd.MsgUpdateDid" +) diff --git a/x/cheqd/types/messages_did.go b/x/cheqd/types/messages_did.go new file mode 100644 index 000000000..ed8e300ca --- /dev/null +++ b/x/cheqd/types/messages_did.go @@ -0,0 +1,376 @@ +package types + +import ( + "github.com/cheqd/cheqd-node/x/cheqd/utils" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "strings" +) + +func NewMsgCreateDid( + id string, + controller []string, + verificationMethod []*VerificationMethod, + authentication []string, + assertionMethod []string, + capabilityInvocation []string, + capabilityDelegation []string, + keyAgreement []string, + alsoKnownAs []string, + service []*ServiceEndpoint, + context []string, +) *MsgCreateDid { + return &MsgCreateDid{ + Id: id, + Controller: controller, + VerificationMethod: verificationMethod, + Authentication: authentication, + AssertionMethod: assertionMethod, + CapabilityInvocation: capabilityInvocation, + CapabilityDelegation: capabilityDelegation, + KeyAgreement: keyAgreement, + AlsoKnownAs: alsoKnownAs, + Service: service, + Context: context, + } +} + +var _ IdentityMsg = &MsgCreateDid{} + +func (msg *MsgCreateDid) GetSigners() []Signer { + if len(msg.Controller) > 0 { + result := make([]Signer, len(msg.Controller)) + + for i, controller := range msg.Controller { + if controller == msg.Id { + result[i] = Signer{ + Signer: controller, + Authentication: msg.Authentication, + VerificationMethod: msg.VerificationMethod, + } + } else { + result[i] = Signer{ + Signer: controller, + } + } + } + + return result + } + + if len(msg.Authentication) > 0 { + return []Signer{ + { + Signer: msg.Id, + Authentication: msg.Authentication, + VerificationMethod: msg.VerificationMethod, + }, + } + } + + return []Signer{} +} + +func (msg *MsgCreateDid) Validate(namespace string) error { + if !utils.IsValidDid(namespace, msg.Id) { + return ErrBadRequestIsNotDid.Wrap("Id") + } + + if notValid, i := utils.IsNotValidDIDArray(namespace, msg.Controller); notValid { + return ErrBadRequestIsNotDid.Wrapf("Controller item %s at position %d", msg.Controller[i], i) + } + + if err := ValidateVerificationMethods(namespace, msg.Id, msg.VerificationMethod); err != nil { + return err + } + + if err := ValidateServices(namespace, msg.Id, msg.Service); err != nil { + return err + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.Authentication); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("Authentication item %s", msg.Authentication[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.CapabilityInvocation); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("CapabilityInvocation item %s", msg.CapabilityInvocation[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.CapabilityDelegation); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("CapabilityDelegation item %s", msg.CapabilityDelegation[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.KeyAgreement); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("KeyAgreement item %s", msg.KeyAgreement[i]) + } + + if len(msg.Authentication) == 0 && len(msg.Controller) == 0 { + return ErrBadRequest.Wrap("The message must contain either a Controller or a Authentication") + } + + for _, i := range msg.Authentication { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.KeyAgreement { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.CapabilityDelegation { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.CapabilityInvocation { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + return nil +} + +func (msg *MsgCreateDid) GetSignBytes() []byte { + return ModuleCdc.MustMarshal(msg) +} + +var _ IdentityMsg = &MsgUpdateDid{} + +func NewMsgUpdateDid( + id string, + controller []string, + verificationMethod []*VerificationMethod, + authentication []string, + assertionMethod []string, + capabilityInvocation []string, + capabilityDelegation []string, + keyAgreement []string, + alsoKnownAs []string, + service []*ServiceEndpoint, + context []string, +) *MsgUpdateDid { + return &MsgUpdateDid{ + Id: id, + Controller: controller, + VerificationMethod: verificationMethod, + Authentication: authentication, + AssertionMethod: assertionMethod, + CapabilityInvocation: capabilityInvocation, + CapabilityDelegation: capabilityDelegation, + KeyAgreement: keyAgreement, + AlsoKnownAs: alsoKnownAs, + Service: service, + Context: context, + } +} + +func (msg *MsgUpdateDid) GetSigners() []Signer { + if len(msg.Controller) > 0 { + result := make([]Signer, len(msg.Controller)) + + for i, controller := range msg.Controller { + if controller == msg.Id { + result[i] = Signer{ + Signer: controller, + Authentication: msg.Authentication, + VerificationMethod: msg.VerificationMethod, + } + } else { + result[i] = Signer{ + Signer: controller, + } + } + } + + return result + } + + if len(msg.Authentication) > 0 { + return []Signer{ + { + Signer: msg.Id, + Authentication: msg.Authentication, + VerificationMethod: msg.VerificationMethod, + }, + } + } + + return []Signer{} +} + +func (msg *MsgUpdateDid) Validate(namespace string) error { + if !utils.IsValidDid(namespace, msg.Id) { + return ErrBadRequestIsNotDid.Wrap("Id") + } + + if notValid, i := utils.IsNotValidDIDArray(namespace, msg.Controller); notValid { + return ErrBadRequestIsNotDid.Wrapf("Controller item %s at position %d", msg.Controller[i], i) + } + + if err := ValidateVerificationMethods(namespace, msg.Id, msg.VerificationMethod); err != nil { + return err + } + + if err := ValidateServices(namespace, msg.Id, msg.Service); err != nil { + return err + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.Authentication); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("Authentication item %s", msg.Authentication[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.CapabilityInvocation); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("CapabilityInvocation item %s", msg.CapabilityInvocation[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.CapabilityDelegation); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("CapabilityDelegation item %s", msg.CapabilityDelegation[i]) + } + + if notValid, i := utils.IsNotValidDIDArrayFragment(namespace, msg.KeyAgreement); notValid { + return ErrBadRequestIsNotDidFragment.Wrapf("KeyAgreement item %s", msg.KeyAgreement[i]) + } + + if len(msg.Authentication) == 0 && len(msg.Controller) == 0 { + return ErrBadRequest.Wrap("The message must contain either a Controller or a Authentication") + } + + for _, i := range msg.Authentication { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.KeyAgreement { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.CapabilityDelegation { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + for _, i := range msg.CapabilityInvocation { + if !IncludeVerificationMethod(msg.Id, msg.VerificationMethod, i) { + return ErrVerificationMethodNotFound.Wrap(i) + } + } + + return nil +} + +func (msg *MsgUpdateDid) GetSignBytes() []byte { + return ModuleCdc.MustMarshal(msg) +} + +func ValidateVerificationMethods(namespace string, did string, vms []*VerificationMethod) error { + for i, vm := range vms { + if err := ValidateVerificationMethod(namespace, vm); err != nil { + return ErrBadRequestInvalidVerMethod.Wrap(sdkerrors.Wrapf(err, "index %d, value %s", i, vm.Id).Error()) + } + } + + for i, vm := range vms { + if !strings.HasPrefix(vm.Id, did) { + return ErrBadRequestInvalidVerMethod.Wrapf("%s not belong %s DID Doc", vm.Id, did) + } + + if IncludeVerificationMethod(did, vms[i+1:], vm.Id) { + return ErrBadRequestInvalidVerMethod.Wrapf("%s is duplicated", vm.Id) + } + } + + return nil +} + +func ValidateVerificationMethod(namespace string, vm *VerificationMethod) error { + if !utils.IsFullDidFragment(namespace, vm.Id) { + return ErrBadRequestIsNotDidFragment.Wrap(vm.Id) + } + + if len(vm.PublicKeyMultibase) != 0 && len(vm.PublicKeyJwk) != 0 { + return ErrBadRequest.Wrap("contains multiple verification material properties") + } + + switch utils.GetVerificationMethodType(vm.Type) { + case utils.PublicKeyJwk: + if len(vm.PublicKeyJwk) == 0 { + return ErrBadRequest.Wrapf("%s: should contain `PublicKeyJwk` verification material property", vm.Type) + } + case utils.PublicKeyMultibase: + if len(vm.PublicKeyMultibase) == 0 { + return ErrBadRequest.Wrapf("%s: should contain `PublicKeyMultibase` verification material property", vm.Type) + } + default: + return ErrBadRequest.Wrapf("%s: unsupported verification method type", vm.Type) + } + + if len(vm.PublicKeyMultibase) == 0 && vm.PublicKeyJwk == nil { + return ErrBadRequest.Wrap("The verification method must contain either a PublicKeyMultibase or a PublicKeyJwk") + } + + if len(vm.Controller) == 0 { + return ErrBadRequestIsRequired.Wrap("Controller") + } + + return nil +} + +func ValidateServices(namespace string, did string, services []*ServiceEndpoint) error { + for i, s := range services { + if err := ValidateService(namespace, s); err != nil { + return ErrBadRequestInvalidService.Wrap(sdkerrors.Wrapf(err, "index %d, value %s", i, s.Id).Error()) + } + } + + for i, s := range services { + if !strings.HasPrefix(utils.ResolveId(did, s.Id), did) { + return ErrBadRequestInvalidService.Wrapf("%s not belong %s DID Doc", s.Id, did) + } + + if IncludeService(did, services[i+1:], s.Id) { + return ErrBadRequestInvalidService.Wrapf("%s is duplicated", s.Id) + } + } + + return nil +} + +func ValidateService(namespace string, s *ServiceEndpoint) error { + if !utils.IsDidFragment(namespace, s.Id) { + return ErrBadRequestIsNotDidFragment.Wrap(s.Id) + } + + if !utils.IsValidDidServiceType(s.Type) { + return ErrBadRequest.Wrapf("%s: unsupported service type", s.Type) + } + + return nil +} + +func IncludeVerificationMethod(did string, vms []*VerificationMethod, id string) bool { + for _, vm := range vms { + if vm.Id == utils.ResolveId(did, id) { + return true + } + } + + return false +} + +func IncludeService(did string, services []*ServiceEndpoint, id string) bool { + for _, s := range services { + if utils.ResolveId(did, s.Id) == utils.ResolveId(did, id) { + return true + } + } + + return false +} diff --git a/x/cheqd/types/messages_nym.go b/x/cheqd/types/messages_nym.go deleted file mode 100644 index 5e0120041..000000000 --- a/x/cheqd/types/messages_nym.go +++ /dev/null @@ -1,126 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -var _ sdk.Msg = &MsgCreateNym{} - -func NewMsgCreateNym(creator string, alias string, verkey string, did string, role string) *MsgCreateNym { - return &MsgCreateNym{ - Creator: creator, - Alias: alias, - Verkey: verkey, - Did: did, - Role: role, - } -} - -func (msg *MsgCreateNym) Route() string { - return RouterKey -} - -func (msg *MsgCreateNym) Type() string { - return "CreateNym" -} - -func (msg *MsgCreateNym) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - panic(err) - } - return []sdk.AccAddress{creator} -} - -func (msg *MsgCreateNym) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) -} - -func (msg *MsgCreateNym) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) - } - return nil -} - -var _ sdk.Msg = &MsgUpdateNym{} - -func NewMsgUpdateNym(creator string, id uint64, alias string, verkey string, did string, role string) *MsgUpdateNym { - return &MsgUpdateNym{ - Id: id, - Creator: creator, - Alias: alias, - Verkey: verkey, - Did: did, - Role: role, - } -} - -func (msg *MsgUpdateNym) Route() string { - return RouterKey -} - -func (msg *MsgUpdateNym) Type() string { - return "UpdateNym" -} - -func (msg *MsgUpdateNym) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - panic(err) - } - return []sdk.AccAddress{creator} -} - -func (msg *MsgUpdateNym) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) -} - -func (msg *MsgUpdateNym) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) - } - return nil -} - -var _ sdk.Msg = &MsgCreateNym{} - -func NewMsgDeleteNym(creator string, id uint64) *MsgDeleteNym { - return &MsgDeleteNym{ - Id: id, - Creator: creator, - } -} -func (msg *MsgDeleteNym) Route() string { - return RouterKey -} - -func (msg *MsgDeleteNym) Type() string { - return "DeleteNym" -} - -func (msg *MsgDeleteNym) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - panic(err) - } - return []sdk.AccAddress{creator} -} - -func (msg *MsgDeleteNym) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) -} - -func (msg *MsgDeleteNym) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) - } - return nil -} diff --git a/x/cheqd/types/messages_write_request.go b/x/cheqd/types/messages_write_request.go new file mode 100644 index 000000000..58155697e --- /dev/null +++ b/x/cheqd/types/messages_write_request.go @@ -0,0 +1,48 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgWriteRequest{} + +func NewMsgWriteRequest(data *types.Any, signatures []*SignInfo) *MsgWriteRequest { + return &MsgWriteRequest{ + Data: data, + Signatures: signatures, + } +} + +func (msg *MsgWriteRequest) Route() string { + return RouterKey +} + +func (msg *MsgWriteRequest) Type() string { + return "WriteRequest" +} + +func (msg *MsgWriteRequest) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{} +} + +func (msg *MsgWriteRequest) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshal(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgWriteRequest) ValidateBasic() error { + if msg.Data == nil { + return ErrBadRequestIsRequired.Wrap("Data") + } + + if len(msg.Signatures) == 0 { + return ErrBadRequestIsRequired.Wrap("Signatures") + } + + if len(msg.Data.TypeUrl) == 0 || len(msg.Data.Value) == 0 { + return ErrBadRequest.Wrap("Invalid Data: it cannot be empty") + } + + return nil +} diff --git a/x/cheqd/types/msg_test.go b/x/cheqd/types/msg_test.go new file mode 100644 index 000000000..e1495922a --- /dev/null +++ b/x/cheqd/types/msg_test.go @@ -0,0 +1,831 @@ +package types + +import ( + "testing" + + ctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/stretchr/testify/require" +) + +const Prefix = "did:cheqd:test:" + +func TestNewMsgWriteRequestValidation(t *testing.T) { + cases := []struct { + valid bool + msg *MsgWriteRequest + errMsg string + }{ + {true, NewMsgWriteRequest(&ctypes.Any{TypeUrl: "1", Value: []byte{1}}, []*SignInfo{{VerificationMethodId: "foo", Signature: "bar"}}), ""}, + {false, NewMsgWriteRequest(&ctypes.Any{TypeUrl: "1"}, []*SignInfo{{VerificationMethodId: "foo", Signature: "bar"}}), "Invalid Data: it cannot be empty: bad request"}, + {false, NewMsgWriteRequest(&ctypes.Any{Value: []byte{1}}, []*SignInfo{{VerificationMethodId: "foo", Signature: "bar"}}), "Invalid Data: it cannot be empty: bad request"}, + {false, NewMsgWriteRequest(nil, nil), "Data: is required"}, + {false, NewMsgWriteRequest(&ctypes.Any{TypeUrl: "1", Value: []byte{1}}, nil), "Signatures: is required"}, + } + + for _, tc := range cases { + err := tc.msg.ValidateBasic() + + if tc.valid { + require.Nil(t, err) + } else { + require.Error(t, err) + require.Equal(t, tc.errMsg, err.Error()) + } + } +} + +func TestNewMsgCreateDid(t *testing.T) { + cases := []struct { + valid bool + msg *MsgCreateDid + errMsg string + }{ + { + false, + &MsgCreateDid{}, + "Id: is not DID", + }, + { + false, + &MsgCreateDid{Id: ""}, + "Id: is not DID", + }, + { + false, + &MsgCreateDid{Id: "did:ch:test:alice"}, + "Id: is not DID", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice"}, + "The message must contain either a Controller or a Authentication: bad request", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{}, + }, + "The message must contain either a Controller or a Authentication: bad request", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{{}}, + }, + "index 0, value : : is not DID fragment: invalid verification method", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", Authentication: []string{"dd"}}, + "Authentication item dd: is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", Authentication: []string{""}}, + "Authentication item : is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", Authentication: []string{"did:cheqd:test:alice"}}, + "Authentication item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Authentication: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{"dd"}}, + "CapabilityInvocation item dd: is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{""}}, + "CapabilityInvocation item : is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{"did:cheqd:test:alice"}}, + "CapabilityInvocation item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + CapabilityInvocation: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{"dd"}}, + "CapabilityDelegation item dd: is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{""}}, + "CapabilityDelegation item : is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{"did:cheqd:test:alice"}}, + "CapabilityDelegation item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + CapabilityDelegation: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{"dd"}}, + "KeyAgreement item dd: is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{""}}, + "KeyAgreement item : is not DID fragment", + }, + { + false, + &MsgCreateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{"did:cheqd:test:alice"}}, + "KeyAgreement item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + KeyAgreement: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + KeyAgreement: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd::alice"}, + }, + "Controller item did:cheqd::alice at position 0: is not DID", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "dasda"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value dasda: dasda: is not DID fragment: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "did:cheqd:test:alice#key-1"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: : unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "did:cheqd:test:alice#key-1", Type: "YES"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: YES: unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "JsonWebKey2020", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: JsonWebKey2020: should contain `PublicKeyJwk` verification material property: bad request: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "JsonWebKey2020", + PublicKeyMultibase: "tetetet", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: JsonWebKey2020: should contain `PublicKeyJwk` verification material property: bad request: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1 is duplicated: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-2", + Type: "JsonWebKey2020", + PublicKeyJwk: []*KeyValuePair{ + { + Key: "x", + Value: "sadad", + }, + }, + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-3", + Type: "JsonWebKey20212", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 2, value did:cheqd:test:alice#key-3: JsonWebKey20212: unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + {}, + }, + }, + "index 0, value : : is not DID fragment: invalid service", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "weqweqw", + }, + }, + }, + "index 0, value weqweqw: weqweqw: is not DID fragment: invalid service", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "#service-1", + }, + }, + }, + "index 0, value #service-1: : unsupported service type: bad request: invalid service", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + }, + }, + "#service-1 is duplicated: invalid service", + }, + { + false, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "did:cheqd:test:alice#service-1", + Type: "DIDCommMessaging", + }, + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + }, + }, + "did:cheqd:test:alice#service-1 is duplicated: invalid service", + }, + { + true, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + VerificationMethod: []*VerificationMethod{}, + }, + "", + }, + { + true, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{}, + }, + "", + }, + { + true, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}}, + "", + }, + { + true, + &MsgCreateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice", "did:cheqd:test:bob"}, + Authentication: []string{"#key-1", "did:cheqd:test:alice#key-2"}, + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "JsonWebKey2020", + PublicKeyJwk: []*KeyValuePair{ + { + Key: "x", + Value: "sadad", + }, + }, + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-2", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + }, + "", + }, + } + + for _, tc := range cases { + err := tc.msg.Validate(Prefix) + + if tc.valid { + require.Nil(t, err) + } else { + require.Error(t, err) + require.Equal(t, tc.errMsg, err.Error()) + } + } +} + +func TestNewMsgUpdateDid(t *testing.T) { + cases := []struct { + valid bool + msg *MsgUpdateDid + errMsg string + }{ + { + false, + &MsgUpdateDid{}, + "Id: is not DID", + }, + { + false, + &MsgUpdateDid{Id: ""}, + "Id: is not DID", + }, + { + false, + &MsgUpdateDid{Id: "did:ch:test:alice"}, + "Id: is not DID", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice"}, + "The message must contain either a Controller or a Authentication: bad request", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{}, + }, + "The message must contain either a Controller or a Authentication: bad request", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{{}}, + }, + "index 0, value : : is not DID fragment: invalid verification method", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", Authentication: []string{"dd"}}, + "Authentication item dd: is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", Authentication: []string{""}}, + "Authentication item : is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", Authentication: []string{"did:cheqd:test:alice"}}, + "Authentication item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Authentication: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{"dd"}}, + "CapabilityInvocation item dd: is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{""}}, + "CapabilityInvocation item : is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityInvocation: []string{"did:cheqd:test:alice"}}, + "CapabilityInvocation item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + CapabilityInvocation: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{"dd"}}, + "CapabilityDelegation item dd: is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{""}}, + "CapabilityDelegation item : is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", CapabilityDelegation: []string{"did:cheqd:test:alice"}}, + "CapabilityDelegation item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + CapabilityDelegation: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{"dd"}}, + "KeyAgreement item dd: is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{""}}, + "KeyAgreement item : is not DID fragment", + }, + { + false, + &MsgUpdateDid{Id: "did:cheqd:test:alice", KeyAgreement: []string{"did:cheqd:test:alice"}}, + "KeyAgreement item did:cheqd:test:alice: is not DID fragment", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + KeyAgreement: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1: verification method not found", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + KeyAgreement: []string{"did:cheqd:test:alice#key-1"}, + Controller: []string{"did:cheqd::alice"}, + }, + "Controller item did:cheqd::alice at position 0: is not DID", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "dasda"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value dasda: dasda: is not DID fragment: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "did:cheqd:test:alice#key-1"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: : unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + {Id: "did:cheqd:test:alice#key-1", Type: "YES"}, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: YES: unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: Ed25519VerificationKey2020: should contain `PublicKeyMultibase` verification material property: bad request: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "JsonWebKey2020", + PublicKeyJwk: []*KeyValuePair{ + {Key: "x", Value: "y"}, + }, + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 0, value did:cheqd:test:alice#key-1: Controller: is required: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "did:cheqd:test:alice#key-1 is duplicated: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-2", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-3", + Type: "JsonWebKey20212", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + Controller: []string{"did:cheqd:test:alice"}, + }, + "index 2, value did:cheqd:test:alice#key-3: JsonWebKey20212: unsupported verification method type: bad request: invalid verification method", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + {}, + }, + }, + "index 0, value : : is not DID fragment: invalid service", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "weqweqw", + }, + }, + }, + "index 0, value weqweqw: weqweqw: is not DID fragment: invalid service", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "#service-1", + }, + }, + }, + "index 0, value #service-1: : unsupported service type: bad request: invalid service", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + }, + }, + "#service-1 is duplicated: invalid service", + }, + { + false, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{ + { + Id: "did:cheqd:test:alice#service-1", + Type: "DIDCommMessaging", + }, + { + Id: "#service-1", + Type: "DIDCommMessaging", + }, + }, + }, + "did:cheqd:test:alice#service-1 is duplicated: invalid service", + }, + { + true, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + VerificationMethod: []*VerificationMethod{}, + }, + "", + }, + { + true, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}, + Service: []*ServiceEndpoint{}, + }, + "", + }, + { + true, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice"}}, + "", + }, + { + true, + &MsgUpdateDid{ + Id: "did:cheqd:test:alice", + Controller: []string{"did:cheqd:test:alice", "did:cheqd:test:bob"}, + Authentication: []string{"#key-1", "did:cheqd:test:alice#key-2"}, + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:test:alice#key-1", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + { + Id: "did:cheqd:test:alice#key-2", + Type: "Ed25519VerificationKey2020", + PublicKeyMultibase: "tetetet", + Controller: "did:cheqd:test:alice", + }, + }, + }, + "", + }, + } + + for _, tc := range cases { + err := tc.msg.Validate(Prefix) + + if tc.valid { + require.Nil(t, err) + } else { + require.Error(t, err) + require.Equal(t, tc.errMsg, err.Error()) + } + } +} diff --git a/x/cheqd/types/nym.pb.go b/x/cheqd/types/nym.pb.go deleted file mode 100644 index 336975c5c..000000000 --- a/x/cheqd/types/nym.pb.go +++ /dev/null @@ -1,559 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cheqd/nym.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type Nym struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` - Alias string `protobuf:"bytes,3,opt,name=alias,proto3" json:"alias,omitempty"` - Verkey string `protobuf:"bytes,4,opt,name=verkey,proto3" json:"verkey,omitempty"` - Did string `protobuf:"bytes,5,opt,name=did,proto3" json:"did,omitempty"` - Role string `protobuf:"bytes,6,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *Nym) Reset() { *m = Nym{} } -func (m *Nym) String() string { return proto.CompactTextString(m) } -func (*Nym) ProtoMessage() {} -func (*Nym) Descriptor() ([]byte, []int) { - return fileDescriptor_8ac64d8a3297565c, []int{0} -} -func (m *Nym) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Nym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Nym.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Nym) XXX_Merge(src proto.Message) { - xxx_messageInfo_Nym.Merge(m, src) -} -func (m *Nym) XXX_Size() int { - return m.Size() -} -func (m *Nym) XXX_DiscardUnknown() { - xxx_messageInfo_Nym.DiscardUnknown(m) -} - -var xxx_messageInfo_Nym proto.InternalMessageInfo - -func (m *Nym) GetCreator() string { - if m != nil { - return m.Creator - } - return "" -} - -func (m *Nym) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -func (m *Nym) GetAlias() string { - if m != nil { - return m.Alias - } - return "" -} - -func (m *Nym) GetVerkey() string { - if m != nil { - return m.Verkey - } - return "" -} - -func (m *Nym) GetDid() string { - if m != nil { - return m.Did - } - return "" -} - -func (m *Nym) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func init() { - proto.RegisterType((*Nym)(nil), "cheqdid.cheqdnode.cheqd.Nym") -} - -func init() { proto.RegisterFile("cheqd/nym.proto", fileDescriptor_8ac64d8a3297565c) } - -var fileDescriptor_8ac64d8a3297565c = []byte{ - // 230 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0xce, 0x48, 0x2d, - 0x4c, 0xd1, 0xcf, 0xab, 0xcc, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x07, 0x0b, 0x64, - 0xa6, 0xe8, 0x81, 0xe9, 0xbc, 0xfc, 0x94, 0x54, 0x08, 0x4b, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, - 0xac, 0x46, 0x1f, 0xc4, 0x82, 0x28, 0x57, 0x6a, 0x66, 0xe4, 0x62, 0xf6, 0xab, 0xcc, 0x15, 0x92, - 0xe0, 0x62, 0x4f, 0x2e, 0x4a, 0x4d, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, - 0x82, 0x71, 0x85, 0xf8, 0xb8, 0x98, 0x32, 0x53, 0x24, 0x98, 0x14, 0x18, 0x35, 0x58, 0x82, 0x98, - 0x32, 0x53, 0x84, 0x44, 0xb8, 0x58, 0x13, 0x73, 0x32, 0x13, 0x8b, 0x25, 0x98, 0xc1, 0xea, 0x20, - 0x1c, 0x21, 0x31, 0x2e, 0xb6, 0xb2, 0xd4, 0xa2, 0xec, 0xd4, 0x4a, 0x09, 0x16, 0xb0, 0x30, 0x94, - 0x27, 0x24, 0xc0, 0xc5, 0x9c, 0x92, 0x99, 0x22, 0xc1, 0x0a, 0x16, 0x04, 0x31, 0x85, 0x84, 0xb8, - 0x58, 0x8a, 0xf2, 0x73, 0x52, 0x25, 0xd8, 0xc0, 0x42, 0x60, 0xb6, 0x93, 0xf3, 0x89, 0x47, 0x72, - 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, - 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, - 0xe7, 0xe7, 0xea, 0x43, 0xbc, 0x0a, 0x26, 0x75, 0x41, 0x1e, 0xd3, 0xaf, 0x80, 0x0a, 0x95, 0x54, - 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x7d, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x9b, - 0x3d, 0x7c, 0x13, 0x01, 0x00, 0x00, -} - -func (m *Nym) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Nym) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Nym) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Role) > 0 { - i -= len(m.Role) - copy(dAtA[i:], m.Role) - i = encodeVarintNym(dAtA, i, uint64(len(m.Role))) - i-- - dAtA[i] = 0x32 - } - if len(m.Did) > 0 { - i -= len(m.Did) - copy(dAtA[i:], m.Did) - i = encodeVarintNym(dAtA, i, uint64(len(m.Did))) - i-- - dAtA[i] = 0x2a - } - if len(m.Verkey) > 0 { - i -= len(m.Verkey) - copy(dAtA[i:], m.Verkey) - i = encodeVarintNym(dAtA, i, uint64(len(m.Verkey))) - i-- - dAtA[i] = 0x22 - } - if len(m.Alias) > 0 { - i -= len(m.Alias) - copy(dAtA[i:], m.Alias) - i = encodeVarintNym(dAtA, i, uint64(len(m.Alias))) - i-- - dAtA[i] = 0x1a - } - if m.Id != 0 { - i = encodeVarintNym(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x10 - } - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintNym(dAtA, i, uint64(len(m.Creator))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintNym(dAtA []byte, offset int, v uint64) int { - offset -= sovNym(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Nym) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Creator) - if l > 0 { - n += 1 + l + sovNym(uint64(l)) - } - if m.Id != 0 { - n += 1 + sovNym(uint64(m.Id)) - } - l = len(m.Alias) - if l > 0 { - n += 1 + l + sovNym(uint64(l)) - } - l = len(m.Verkey) - if l > 0 { - n += 1 + l + sovNym(uint64(l)) - } - l = len(m.Did) - if l > 0 { - n += 1 + l + sovNym(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovNym(uint64(l)) - } - return n -} - -func sovNym(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozNym(x uint64) (n int) { - return sovNym(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Nym) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Nym: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Nym: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNym - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNym - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Creator = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alias", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNym - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNym - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Alias = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Verkey", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNym - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNym - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Verkey = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Did", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNym - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNym - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Did = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNym - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNym - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNym - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Role = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipNym(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthNym - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipNym(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowNym - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowNym - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowNym - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthNym - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupNym - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthNym - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthNym = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowNym = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupNym = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/cheqd/types/query.go b/x/cheqd/types/query.go index 5eae625a2..8a6cb7eb4 100644 --- a/x/cheqd/types/query.go +++ b/x/cheqd/types/query.go @@ -1,6 +1,5 @@ package types const ( - QueryGetNym = "get-nym" - QueryListNym = "list-nym" + QueryGetDid = "get-did" ) diff --git a/x/cheqd/types/query.pb.go b/x/cheqd/types/query.pb.go index 648292659..eb1c4f90f 100644 --- a/x/cheqd/types/query.pb.go +++ b/x/cheqd/types/query.pb.go @@ -6,7 +6,7 @@ package types import ( context "context" fmt "fmt" - query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/query" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" @@ -29,23 +29,22 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// this line is used by starport scaffolding # 3 -type QueryGetNymRequest struct { - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +type QueryGetDidRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } -func (m *QueryGetNymRequest) Reset() { *m = QueryGetNymRequest{} } -func (m *QueryGetNymRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetNymRequest) ProtoMessage() {} -func (*QueryGetNymRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetDidRequest) Reset() { *m = QueryGetDidRequest{} } +func (m *QueryGetDidRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetDidRequest) ProtoMessage() {} +func (*QueryGetDidRequest) Descriptor() ([]byte, []int) { return fileDescriptor_bf3698559b3858f5, []int{0} } -func (m *QueryGetNymRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetDidRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetNymRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetDidRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetNymRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetDidRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -55,41 +54,42 @@ func (m *QueryGetNymRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *QueryGetNymRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetNymRequest.Merge(m, src) +func (m *QueryGetDidRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetDidRequest.Merge(m, src) } -func (m *QueryGetNymRequest) XXX_Size() int { +func (m *QueryGetDidRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetNymRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetNymRequest.DiscardUnknown(m) +func (m *QueryGetDidRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetDidRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetNymRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetDidRequest proto.InternalMessageInfo -func (m *QueryGetNymRequest) GetId() uint64 { +func (m *QueryGetDidRequest) GetId() string { if m != nil { return m.Id } - return 0 + return "" } -type QueryGetNymResponse struct { - Nym *Nym `protobuf:"bytes,1,opt,name=Nym,proto3" json:"Nym,omitempty"` +type QueryGetDidResponse struct { + Did *Did `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Metadata *Metadata `protobuf:"bytes,2,opt,name=metadata,proto3" json:"metadata,omitempty"` } -func (m *QueryGetNymResponse) Reset() { *m = QueryGetNymResponse{} } -func (m *QueryGetNymResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetNymResponse) ProtoMessage() {} -func (*QueryGetNymResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetDidResponse) Reset() { *m = QueryGetDidResponse{} } +func (m *QueryGetDidResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetDidResponse) ProtoMessage() {} +func (*QueryGetDidResponse) Descriptor() ([]byte, []int) { return fileDescriptor_bf3698559b3858f5, []int{1} } -func (m *QueryGetNymResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetDidResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetDidResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetNymResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetDidResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -99,157 +99,62 @@ func (m *QueryGetNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *QueryGetNymResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetNymResponse.Merge(m, src) +func (m *QueryGetDidResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetDidResponse.Merge(m, src) } -func (m *QueryGetNymResponse) XXX_Size() int { +func (m *QueryGetDidResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetNymResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetNymResponse.DiscardUnknown(m) +func (m *QueryGetDidResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetDidResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetNymResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetDidResponse proto.InternalMessageInfo -func (m *QueryGetNymResponse) GetNym() *Nym { +func (m *QueryGetDidResponse) GetDid() *Did { if m != nil { - return m.Nym + return m.Did } return nil } -type QueryAllNymRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllNymRequest) Reset() { *m = QueryAllNymRequest{} } -func (m *QueryAllNymRequest) String() string { return proto.CompactTextString(m) } -func (*QueryAllNymRequest) ProtoMessage() {} -func (*QueryAllNymRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bf3698559b3858f5, []int{2} -} -func (m *QueryAllNymRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllNymRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllNymRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllNymRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllNymRequest.Merge(m, src) -} -func (m *QueryAllNymRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryAllNymRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllNymRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAllNymRequest proto.InternalMessageInfo - -func (m *QueryAllNymRequest) GetPagination() *query.PageRequest { +func (m *QueryGetDidResponse) GetMetadata() *Metadata { if m != nil { - return m.Pagination - } - return nil -} - -type QueryAllNymResponse struct { - Nym []*Nym `protobuf:"bytes,1,rep,name=Nym,proto3" json:"Nym,omitempty"` - Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryAllNymResponse) Reset() { *m = QueryAllNymResponse{} } -func (m *QueryAllNymResponse) String() string { return proto.CompactTextString(m) } -func (*QueryAllNymResponse) ProtoMessage() {} -func (*QueryAllNymResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bf3698559b3858f5, []int{3} -} -func (m *QueryAllNymResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryAllNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryAllNymResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryAllNymResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryAllNymResponse.Merge(m, src) -} -func (m *QueryAllNymResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryAllNymResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryAllNymResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryAllNymResponse proto.InternalMessageInfo - -func (m *QueryAllNymResponse) GetNym() []*Nym { - if m != nil { - return m.Nym - } - return nil -} - -func (m *QueryAllNymResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination + return m.Metadata } return nil } func init() { - proto.RegisterType((*QueryGetNymRequest)(nil), "cheqdid.cheqdnode.cheqd.QueryGetNymRequest") - proto.RegisterType((*QueryGetNymResponse)(nil), "cheqdid.cheqdnode.cheqd.QueryGetNymResponse") - proto.RegisterType((*QueryAllNymRequest)(nil), "cheqdid.cheqdnode.cheqd.QueryAllNymRequest") - proto.RegisterType((*QueryAllNymResponse)(nil), "cheqdid.cheqdnode.cheqd.QueryAllNymResponse") + proto.RegisterType((*QueryGetDidRequest)(nil), "cheqdid.cheqdnode.cheqd.QueryGetDidRequest") + proto.RegisterType((*QueryGetDidResponse)(nil), "cheqdid.cheqdnode.cheqd.QueryGetDidResponse") } func init() { proto.RegisterFile("cheqd/query.proto", fileDescriptor_bf3698559b3858f5) } var fileDescriptor_bf3698559b3858f5 = []byte{ - // 398 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x4b, 0xe3, 0x40, - 0x18, 0xc6, 0x3b, 0xe9, 0x6e, 0x0f, 0xb3, 0xb0, 0xcb, 0xce, 0xc2, 0x6e, 0xe9, 0x76, 0xc3, 0x92, - 0x5d, 0xfc, 0xef, 0x0c, 0xad, 0x9f, 0xa0, 0x8a, 0xf6, 0x56, 0xb4, 0x47, 0xf1, 0x92, 0x34, 0x43, - 0x3a, 0x90, 0xcc, 0xa4, 0x9d, 0xa9, 0x18, 0xc4, 0x8b, 0xe2, 0x55, 0x04, 0xf1, 0x3b, 0x79, 0x2c, - 0x78, 0xf1, 0x28, 0xad, 0x1f, 0x44, 0x32, 0x13, 0x31, 0x51, 0x4b, 0x7b, 0x49, 0xc2, 0xcb, 0xf3, - 0xbc, 0xcf, 0xef, 0x7d, 0xdf, 0xc0, 0xef, 0xbd, 0x3e, 0x1d, 0xf8, 0x64, 0x30, 0xa2, 0xc3, 0x04, - 0xc7, 0x43, 0xa1, 0x04, 0xfa, 0xa5, 0x4b, 0xcc, 0xc7, 0xfa, 0xcd, 0x85, 0x4f, 0xcd, 0x57, 0xad, - 0x1e, 0x08, 0x11, 0x84, 0x94, 0xb8, 0x31, 0x23, 0x2e, 0xe7, 0x42, 0xb9, 0x8a, 0x09, 0x2e, 0x8d, - 0xad, 0xb6, 0xd6, 0x13, 0x32, 0x12, 0x92, 0x78, 0xae, 0xa4, 0xa6, 0x1f, 0x39, 0x6e, 0x78, 0x54, - 0xb9, 0x0d, 0x12, 0xbb, 0x01, 0xe3, 0x5a, 0x9c, 0x69, 0xbf, 0x99, 0x54, 0x9e, 0x44, 0xa6, 0xe0, - 0xfc, 0x87, 0xe8, 0x20, 0xb5, 0xb4, 0xa9, 0xea, 0x24, 0x51, 0x97, 0x0e, 0x46, 0x54, 0x2a, 0xf4, - 0x15, 0x5a, 0xcc, 0xaf, 0x82, 0xbf, 0x60, 0xe5, 0x53, 0xd7, 0x62, 0xbe, 0xb3, 0x0b, 0x7f, 0x14, - 0x54, 0x32, 0x16, 0x5c, 0x52, 0x84, 0x61, 0xb9, 0x93, 0x44, 0x5a, 0xf7, 0xa5, 0x59, 0xc7, 0x33, - 0xf0, 0x71, 0x6a, 0x49, 0x85, 0xce, 0x51, 0x16, 0xd6, 0x0a, 0xc3, 0x5c, 0xd8, 0x1e, 0x84, 0xaf, - 0x9c, 0x59, 0xb3, 0x25, 0x6c, 0x86, 0xc2, 0xe9, 0x50, 0xd8, 0x2c, 0x29, 0x1b, 0x0a, 0xef, 0xbb, - 0x01, 0xcd, 0xbc, 0xdd, 0x9c, 0xd3, 0xb9, 0x02, 0x19, 0xe5, 0x4b, 0xfb, 0xb7, 0x94, 0xe5, 0x85, - 0x28, 0x51, 0xbb, 0xc0, 0x63, 0x69, 0x9e, 0xe5, 0xb9, 0x3c, 0x26, 0x2c, 0x0f, 0xd4, 0xbc, 0xb5, - 0xe0, 0x67, 0x0d, 0x84, 0x2e, 0x81, 0x66, 0x40, 0xeb, 0x33, 0xd3, 0xdf, 0x1f, 0xa1, 0xb6, 0xb1, - 0x98, 0xd8, 0x04, 0x3b, 0xff, 0xce, 0xef, 0x9f, 0x6e, 0xac, 0x3f, 0xe8, 0x37, 0x31, 0x27, 0xce, - 0x3f, 0x79, 0x12, 0x91, 0x53, 0xe6, 0x9f, 0xa1, 0x0b, 0x00, 0x2b, 0x9d, 0x24, 0x6a, 0x85, 0xe1, - 0x3c, 0x94, 0xc2, 0x89, 0xe6, 0xa1, 0x14, 0x17, 0xee, 0xd8, 0x1a, 0xa5, 0x8a, 0x7e, 0x7e, 0x8c, - 0xb2, 0xbd, 0x73, 0x37, 0xb1, 0xc1, 0x78, 0x62, 0x83, 0xc7, 0x89, 0x0d, 0xae, 0xa7, 0x76, 0x69, - 0x3c, 0xb5, 0x4b, 0x0f, 0x53, 0xbb, 0x74, 0xb8, 0x1a, 0x30, 0xd5, 0x1f, 0x79, 0xb8, 0x27, 0xa2, - 0xbc, 0x6b, 0x33, 0x0d, 0x24, 0x27, 0x59, 0x49, 0x25, 0x31, 0x95, 0x5e, 0x45, 0xff, 0xbf, 0x5b, - 0xcf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2d, 0xd8, 0x3e, 0x60, 0x48, 0x03, 0x00, 0x00, + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xbf, 0x4b, 0xc3, 0x40, + 0x14, 0xc7, 0x7b, 0x29, 0x8a, 0x9e, 0xa0, 0x78, 0x82, 0x96, 0x52, 0xa2, 0x2d, 0x82, 0xbf, 0x73, + 0xb4, 0xce, 0x2e, 0x5a, 0x70, 0x72, 0xb0, 0x83, 0x83, 0xdb, 0xa5, 0xf7, 0x48, 0x0f, 0xda, 0x5c, + 0xda, 0x7b, 0x11, 0x8b, 0xb8, 0x88, 0x8b, 0x9b, 0xd0, 0x7f, 0xca, 0xb1, 0xe0, 0xe2, 0x28, 0xad, + 0x7f, 0x88, 0xe4, 0x2e, 0x14, 0x45, 0x0a, 0x4e, 0x09, 0x5f, 0x3e, 0x9f, 0xef, 0xcb, 0x7b, 0xa1, + 0xeb, 0xed, 0x0e, 0xf4, 0x25, 0xef, 0xa7, 0x30, 0x18, 0x06, 0xc9, 0x40, 0xa3, 0x66, 0x5b, 0x36, + 0x52, 0x32, 0xb0, 0xcf, 0x58, 0x4b, 0x70, 0x6f, 0xe5, 0x4a, 0xa4, 0x75, 0xd4, 0x05, 0x2e, 0x12, + 0xc5, 0x45, 0x1c, 0x6b, 0x14, 0xa8, 0x74, 0x6c, 0x9c, 0x56, 0x3e, 0x6c, 0x6b, 0xd3, 0xd3, 0x86, + 0x87, 0xc2, 0x80, 0xeb, 0xe3, 0x77, 0xf5, 0x10, 0x50, 0xd4, 0x79, 0x22, 0x22, 0x15, 0x5b, 0x38, + 0x67, 0xd7, 0xdc, 0xd4, 0x6c, 0x88, 0x0b, 0x36, 0x5d, 0x60, 0x50, 0x20, 0xdc, 0x88, 0x6e, 0x0a, + 0x2e, 0xaf, 0xed, 0x52, 0x76, 0x9d, 0x55, 0x5d, 0x02, 0x36, 0x95, 0x6c, 0x41, 0x3f, 0x05, 0x83, + 0x6c, 0x95, 0x7a, 0x4a, 0x96, 0xc8, 0x0e, 0xd9, 0x5f, 0x6e, 0x79, 0x4a, 0xd6, 0x9e, 0x09, 0xdd, + 0xf8, 0x85, 0x99, 0x44, 0xc7, 0x06, 0x58, 0x40, 0x8b, 0x32, 0x07, 0x57, 0x1a, 0x95, 0x60, 0xce, + 0x5e, 0x41, 0xa6, 0x64, 0x20, 0x3b, 0xa3, 0x4b, 0x3d, 0x40, 0x21, 0x05, 0x8a, 0x92, 0x67, 0xa5, + 0xea, 0x5c, 0xe9, 0x2a, 0x07, 0x5b, 0x33, 0xa5, 0x31, 0x22, 0x74, 0xc1, 0x7e, 0x06, 0x7b, 0x21, + 0xb4, 0xd8, 0x54, 0x92, 0x1d, 0xcd, 0xd5, 0xff, 0x6e, 0x55, 0x3e, 0xfe, 0x1f, 0xec, 0x76, 0xab, + 0xed, 0x3d, 0xbd, 0x7f, 0x8d, 0xbc, 0x2a, 0xdb, 0xe6, 0xee, 0x74, 0x33, 0x87, 0xcf, 0x6e, 0xcb, + 0x1f, 0x94, 0x7c, 0x3c, 0xbf, 0x78, 0x9b, 0xf8, 0x64, 0x3c, 0xf1, 0xc9, 0xe7, 0xc4, 0x27, 0xaf, + 0x53, 0xbf, 0x30, 0x9e, 0xfa, 0x85, 0x8f, 0xa9, 0x5f, 0xb8, 0x3d, 0x88, 0x14, 0x76, 0xd2, 0x30, + 0x68, 0xeb, 0xde, 0xcf, 0x92, 0x13, 0xdb, 0x72, 0x9f, 0x47, 0x38, 0x4c, 0xc0, 0x84, 0x8b, 0xf6, + 0x77, 0x9c, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x66, 0x9f, 0x6e, 0xbd, 0x2f, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -264,9 +169,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // this line is used by starport scaffolding # 2 - Nym(ctx context.Context, in *QueryGetNymRequest, opts ...grpc.CallOption) (*QueryGetNymResponse, error) - NymAll(ctx context.Context, in *QueryAllNymRequest, opts ...grpc.CallOption) (*QueryAllNymResponse, error) + Did(ctx context.Context, in *QueryGetDidRequest, opts ...grpc.CallOption) (*QueryGetDidResponse, error) } type queryClient struct { @@ -277,18 +180,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Nym(ctx context.Context, in *QueryGetNymRequest, opts ...grpc.CallOption) (*QueryGetNymResponse, error) { - out := new(QueryGetNymResponse) - err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Query/Nym", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) NymAll(ctx context.Context, in *QueryAllNymRequest, opts ...grpc.CallOption) (*QueryAllNymResponse, error) { - out := new(QueryAllNymResponse) - err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Query/NymAll", in, out, opts...) +func (c *queryClient) Did(ctx context.Context, in *QueryGetDidRequest, opts ...grpc.CallOption) (*QueryGetDidResponse, error) { + out := new(QueryGetDidResponse) + err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Query/Did", in, out, opts...) if err != nil { return nil, err } @@ -297,58 +191,35 @@ func (c *queryClient) NymAll(ctx context.Context, in *QueryAllNymRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { - // this line is used by starport scaffolding # 2 - Nym(context.Context, *QueryGetNymRequest) (*QueryGetNymResponse, error) - NymAll(context.Context, *QueryAllNymRequest) (*QueryAllNymResponse, error) + Did(context.Context, *QueryGetDidRequest) (*QueryGetDidResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Nym(ctx context.Context, req *QueryGetNymRequest) (*QueryGetNymResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Nym not implemented") -} -func (*UnimplementedQueryServer) NymAll(ctx context.Context, req *QueryAllNymRequest) (*QueryAllNymResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method NymAll not implemented") +func (*UnimplementedQueryServer) Did(ctx context.Context, req *QueryGetDidRequest) (*QueryGetDidResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Did not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Nym_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetNymRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Nym(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cheqdid.cheqdnode.cheqd.Query/Nym", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Nym(ctx, req.(*QueryGetNymRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_NymAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryAllNymRequest) +func _Query_Did_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetDidRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).NymAll(ctx, in) + return srv.(QueryServer).Did(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cheqdid.cheqdnode.cheqd.Query/NymAll", + FullMethod: "/cheqdid.cheqdnode.cheqd.Query/Did", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).NymAll(ctx, req.(*QueryAllNymRequest)) + return srv.(QueryServer).Did(ctx, req.(*QueryGetDidRequest)) } return interceptor(ctx, in, info, handler) } @@ -358,47 +229,15 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Nym", - Handler: _Query_Nym_Handler, - }, - { - MethodName: "NymAll", - Handler: _Query_NymAll_Handler, + MethodName: "Did", + Handler: _Query_Did_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "cheqd/query.proto", } -func (m *QueryGetNymRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryGetNymRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryGetNymRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Id != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryGetNymResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetDidRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -408,32 +247,27 @@ func (m *QueryGetNymResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetNymResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetDidRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetDidRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Nym != nil { - { - size, err := m.Nym.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Id))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryAllNymRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetDidResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -443,19 +277,19 @@ func (m *QueryAllNymRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryAllNymRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetDidResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryAllNymRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetDidResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Pagination != nil { + if m.Metadata != nil { { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -463,34 +297,11 @@ func (m *QueryAllNymRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintQuery(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryAllNymResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err + dAtA[i] = 0x12 } - return dAtA[:n], nil -} - -func (m *QueryAllNymResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryAllNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { + if m.Did != nil { { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Did.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -498,21 +309,7 @@ func (m *QueryAllNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintQuery(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 - } - if len(m.Nym) > 0 { - for iNdEx := len(m.Nym) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Nym[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -528,58 +325,31 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryGetNymRequest) Size() (n int) { +func (m *QueryGetDidRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Id != 0 { - n += 1 + sovQuery(uint64(m.Id)) - } - return n -} - -func (m *QueryGetNymResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Nym != nil { - l = m.Nym.Size() + l = len(m.Id) + if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryAllNymRequest) Size() (n int) { +func (m *QueryGetDidResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Pagination != nil { - l = m.Pagination.Size() + if m.Did != nil { + l = m.Did.Size() n += 1 + l + sovQuery(uint64(l)) } - return n -} - -func (m *QueryAllNymResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Nym) > 0 { - for _, e := range m.Nym { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() + if m.Metadata != nil { + l = m.Metadata.Size() n += 1 + l + sovQuery(uint64(l)) } return n @@ -591,7 +361,7 @@ func sovQuery(x uint64) (n int) { func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *QueryGetNymRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetDidRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -614,86 +384,17 @@ func (m *QueryGetNymRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetNymRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetDidRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetNymRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryGetNymResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryGetNymResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetNymResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetDidRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Nym", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -703,27 +404,23 @@ func (m *QueryGetNymResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthQuery } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthQuery } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Nym == nil { - m.Nym = &Nym{} - } - if err := m.Nym.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Id = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -746,7 +443,7 @@ func (m *QueryGetNymResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryAllNymRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetDidResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -769,15 +466,15 @@ func (m *QueryAllNymRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryAllNymRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetDidResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllNymRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetDidResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Did", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -804,100 +501,16 @@ func (m *QueryAllNymRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryAllNymResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryAllNymResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryAllNymResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Nym", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF + if m.Did == nil { + m.Did = &Did{} } - m.Nym = append(m.Nym, &Nym{}) - if err := m.Nym[len(m.Nym)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Did.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -924,10 +537,10 @@ func (m *QueryAllNymResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} + if m.Metadata == nil { + m.Metadata = &Metadata{} } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/cheqd/types/query.pb.gw.go b/x/cheqd/types/query.pb.gw.go index c33151e80..42585a95b 100644 --- a/x/cheqd/types/query.pb.gw.go +++ b/x/cheqd/types/query.pb.gw.go @@ -33,8 +33,8 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join -func request_Query_Nym_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetNymRequest +func request_Query_Did_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetDidRequest var metadata runtime.ServerMetadata var ( @@ -49,19 +49,19 @@ func request_Query_Nym_0(ctx context.Context, marshaler runtime.Marshaler, clien return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint64(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } - msg, err := client.Nym(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.Did(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_Nym_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetNymRequest +func local_request_Query_Did_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetDidRequest var metadata runtime.ServerMetadata var ( @@ -76,49 +76,13 @@ func local_request_Query_Nym_0(ctx context.Context, marshaler runtime.Marshaler, return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint64(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } - msg, err := server.Nym(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_NymAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_NymAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllNymRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_NymAll_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.NymAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_NymAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryAllNymRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_NymAll_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.NymAll(ctx, &protoReq) + msg, err := server.Did(ctx, &protoReq) return msg, metadata, err } @@ -129,30 +93,7 @@ func local_request_Query_NymAll_0(ctx context.Context, marshaler runtime.Marshal // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Nym_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Nym_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Nym_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_NymAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Did_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -163,7 +104,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_NymAll_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_Did_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -171,7 +112,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_NymAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Did_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -216,27 +157,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Nym_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Nym_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Nym_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_NymAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Did_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -245,14 +166,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_NymAll_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_Did_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_NymAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Did_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -260,13 +181,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Nym_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 0, 2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"cheqd", "nym", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Query_NymAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 0, 2, 0, 2, 1}, []string{"cheqd", "nym"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Did_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 0, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"cheqd", "cheqdnode", "did", "id"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( - forward_Query_Nym_0 = runtime.ForwardResponseMessage - - forward_Query_NymAll_0 = runtime.ForwardResponseMessage + forward_Query_Did_0 = runtime.ForwardResponseMessage ) diff --git a/x/cheqd/types/stateValue.go b/x/cheqd/types/stateValue.go new file mode 100644 index 000000000..9e3265fb4 --- /dev/null +++ b/x/cheqd/types/stateValue.go @@ -0,0 +1,48 @@ +package types + +import ( + "encoding/base64" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gogo/protobuf/proto" + "github.com/tendermint/tendermint/crypto/tmhash" +) + +const ( + StateValueDid = "/cheqdid.cheqdnode.cheqd.Did" +) + +func NewStateValue(msg proto.Message, metadata *Metadata) (*StateValue, error) { + data, err := types.NewAnyWithValue(msg) + if err != nil { + return nil, ErrInvalidDidStateValue.Wrap(err.Error()) + } + + return &StateValue{Data: data, Metadata: metadata}, nil +} + +func NewMetadata(ctx sdk.Context) Metadata { + created := ctx.BlockTime().String() + txHash := base64.StdEncoding.EncodeToString(tmhash.Sum(ctx.TxBytes())) + + return Metadata{Created: created, Updated: created, Deactivated: false, VersionId: txHash} +} + +func (m StateValue) GetDid() (*Did, error) { + value, isValue := m.Data.GetCachedValue().(Did) + if isValue { + return &value, nil + } + + if m.Data.TypeUrl != StateValueDid { + return nil, ErrInvalidDidStateValue.Wrap(m.Data.TypeUrl) + } + + state := Did{} + err := state.Unmarshal(m.Data.Value) + if err != nil { + return nil, ErrInvalidDidStateValue.Wrap(err.Error()) + } + + return &state, nil +} diff --git a/x/cheqd/types/stateValue.pb.go b/x/cheqd/types/stateValue.pb.go new file mode 100644 index 000000000..107e6d124 --- /dev/null +++ b/x/cheqd/types/stateValue.pb.go @@ -0,0 +1,706 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cheqd/stateValue.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type StateValue struct { + Data *types.Any `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Metadata *Metadata `protobuf:"bytes,2,opt,name=metadata,proto3" json:"metadata,omitempty"` +} + +func (m *StateValue) Reset() { *m = StateValue{} } +func (m *StateValue) String() string { return proto.CompactTextString(m) } +func (*StateValue) ProtoMessage() {} +func (*StateValue) Descriptor() ([]byte, []int) { + return fileDescriptor_8f10490b1a4abc33, []int{0} +} +func (m *StateValue) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StateValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StateValue.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StateValue) XXX_Merge(src proto.Message) { + xxx_messageInfo_StateValue.Merge(m, src) +} +func (m *StateValue) XXX_Size() int { + return m.Size() +} +func (m *StateValue) XXX_DiscardUnknown() { + xxx_messageInfo_StateValue.DiscardUnknown(m) +} + +var xxx_messageInfo_StateValue proto.InternalMessageInfo + +func (m *StateValue) GetData() *types.Any { + if m != nil { + return m.Data + } + return nil +} + +func (m *StateValue) GetMetadata() *Metadata { + if m != nil { + return m.Metadata + } + return nil +} + +// metadata +type Metadata struct { + Created string `protobuf:"bytes,1,opt,name=created,proto3" json:"created,omitempty"` + Updated string `protobuf:"bytes,2,opt,name=updated,proto3" json:"updated,omitempty"` + Deactivated bool `protobuf:"varint,3,opt,name=deactivated,proto3" json:"deactivated,omitempty"` + VersionId string `protobuf:"bytes,4,opt,name=version_id,json=versionId,proto3" json:"version_id,omitempty"` +} + +func (m *Metadata) Reset() { *m = Metadata{} } +func (m *Metadata) String() string { return proto.CompactTextString(m) } +func (*Metadata) ProtoMessage() {} +func (*Metadata) Descriptor() ([]byte, []int) { + return fileDescriptor_8f10490b1a4abc33, []int{1} +} +func (m *Metadata) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Metadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Metadata.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Metadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_Metadata.Merge(m, src) +} +func (m *Metadata) XXX_Size() int { + return m.Size() +} +func (m *Metadata) XXX_DiscardUnknown() { + xxx_messageInfo_Metadata.DiscardUnknown(m) +} + +var xxx_messageInfo_Metadata proto.InternalMessageInfo + +func (m *Metadata) GetCreated() string { + if m != nil { + return m.Created + } + return "" +} + +func (m *Metadata) GetUpdated() string { + if m != nil { + return m.Updated + } + return "" +} + +func (m *Metadata) GetDeactivated() bool { + if m != nil { + return m.Deactivated + } + return false +} + +func (m *Metadata) GetVersionId() string { + if m != nil { + return m.VersionId + } + return "" +} + +func init() { + proto.RegisterType((*StateValue)(nil), "cheqdid.cheqdnode.cheqd.StateValue") + proto.RegisterType((*Metadata)(nil), "cheqdid.cheqdnode.cheqd.Metadata") +} + +func init() { proto.RegisterFile("cheqd/stateValue.proto", fileDescriptor_8f10490b1a4abc33) } + +var fileDescriptor_8f10490b1a4abc33 = []byte{ + // 282 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0xc3, 0x30, + 0x10, 0x86, 0xe3, 0x52, 0x41, 0xea, 0x6e, 0x16, 0x82, 0x80, 0x84, 0x15, 0x3a, 0x85, 0x01, 0x47, + 0x82, 0x99, 0x01, 0x98, 0x18, 0x58, 0x82, 0xc4, 0xc0, 0x82, 0x9c, 0xf8, 0x48, 0x23, 0xb5, 0x71, + 0x48, 0x9c, 0x8a, 0x4c, 0xbc, 0x02, 0x8f, 0xc5, 0xd8, 0x91, 0x11, 0x25, 0x2f, 0x82, 0x7a, 0x4e, + 0x2a, 0x96, 0x2e, 0xb6, 0xef, 0xff, 0xff, 0xcf, 0xa7, 0x3b, 0x7a, 0x94, 0xcc, 0xe1, 0x5d, 0x85, + 0x95, 0x91, 0x06, 0x9e, 0xe5, 0xa2, 0x06, 0x51, 0x94, 0xda, 0x68, 0x76, 0x8c, 0x7a, 0xa6, 0x04, + 0xde, 0xb9, 0x56, 0x60, 0x5f, 0xa7, 0x27, 0xa9, 0xd6, 0xe9, 0x02, 0x42, 0x8c, 0xc5, 0xf5, 0x5b, + 0x28, 0xf3, 0xc6, 0x32, 0xb3, 0x9a, 0xd2, 0xa7, 0xed, 0x3f, 0x2c, 0xa0, 0x63, 0x25, 0x8d, 0xf4, + 0x88, 0x4f, 0x82, 0xe9, 0xd5, 0xa1, 0xb0, 0x9c, 0x18, 0x38, 0x71, 0x9b, 0x37, 0x11, 0x26, 0xd8, + 0x0d, 0x75, 0x97, 0x60, 0x24, 0xa6, 0x47, 0x98, 0x3e, 0x17, 0x3b, 0xda, 0x8b, 0xc7, 0x3e, 0x18, + 0x6d, 0x91, 0xd9, 0x27, 0x75, 0x07, 0x95, 0x79, 0xf4, 0x20, 0x29, 0x41, 0x1a, 0x50, 0xd8, 0x77, + 0x12, 0x0d, 0xe5, 0xc6, 0xa9, 0x0b, 0x85, 0xce, 0xc8, 0x3a, 0x7d, 0xc9, 0x7c, 0x3a, 0x55, 0x20, + 0x13, 0x93, 0xad, 0xd0, 0xdd, 0xf3, 0x49, 0xe0, 0x46, 0xff, 0x25, 0x76, 0x46, 0xe9, 0x0a, 0xca, + 0x2a, 0xd3, 0xf9, 0x6b, 0xa6, 0xbc, 0x31, 0xe2, 0x93, 0x5e, 0x79, 0x50, 0x77, 0xf7, 0xdf, 0x2d, + 0x27, 0xeb, 0x96, 0x93, 0xdf, 0x96, 0x93, 0xaf, 0x8e, 0x3b, 0xeb, 0x8e, 0x3b, 0x3f, 0x1d, 0x77, + 0x5e, 0x2e, 0xd2, 0xcc, 0xcc, 0xeb, 0x58, 0x24, 0x7a, 0x19, 0xda, 0x45, 0xe3, 0x79, 0xb9, 0x19, + 0x28, 0xfc, 0xe8, 0x25, 0xd3, 0x14, 0x50, 0xc5, 0xfb, 0xb8, 0x98, 0xeb, 0xbf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x80, 0xeb, 0x46, 0x6b, 0x91, 0x01, 0x00, 0x00, +} + +func (m *StateValue) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StateValue) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StateValue) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Metadata != nil { + { + size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStateValue(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Data != nil { + { + size, err := m.Data.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStateValue(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Metadata) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Metadata) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Metadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VersionId) > 0 { + i -= len(m.VersionId) + copy(dAtA[i:], m.VersionId) + i = encodeVarintStateValue(dAtA, i, uint64(len(m.VersionId))) + i-- + dAtA[i] = 0x22 + } + if m.Deactivated { + i-- + if m.Deactivated { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if len(m.Updated) > 0 { + i -= len(m.Updated) + copy(dAtA[i:], m.Updated) + i = encodeVarintStateValue(dAtA, i, uint64(len(m.Updated))) + i-- + dAtA[i] = 0x12 + } + if len(m.Created) > 0 { + i -= len(m.Created) + copy(dAtA[i:], m.Created) + i = encodeVarintStateValue(dAtA, i, uint64(len(m.Created))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintStateValue(dAtA []byte, offset int, v uint64) int { + offset -= sovStateValue(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *StateValue) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Data != nil { + l = m.Data.Size() + n += 1 + l + sovStateValue(uint64(l)) + } + if m.Metadata != nil { + l = m.Metadata.Size() + n += 1 + l + sovStateValue(uint64(l)) + } + return n +} + +func (m *Metadata) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Created) + if l > 0 { + n += 1 + l + sovStateValue(uint64(l)) + } + l = len(m.Updated) + if l > 0 { + n += 1 + l + sovStateValue(uint64(l)) + } + if m.Deactivated { + n += 2 + } + l = len(m.VersionId) + if l > 0 { + n += 1 + l + sovStateValue(uint64(l)) + } + return n +} + +func sovStateValue(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozStateValue(x uint64) (n int) { + return sovStateValue(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *StateValue) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StateValue: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StateValue: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStateValue + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStateValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Data == nil { + m.Data = &types.Any{} + } + if err := m.Data.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStateValue + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStateValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Metadata == nil { + m.Metadata = &Metadata{} + } + if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStateValue(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStateValue + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Metadata) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Metadata: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Metadata: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthStateValue + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStateValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Created = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Updated", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthStateValue + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStateValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Updated = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Deactivated", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Deactivated = bool(v != 0) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VersionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStateValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthStateValue + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStateValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VersionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStateValue(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStateValue + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipStateValue(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowStateValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowStateValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowStateValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthStateValue + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupStateValue + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthStateValue + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthStateValue = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowStateValue = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupStateValue = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cheqd/types/tx.pb.go b/x/cheqd/types/tx.pb.go index 9d70276dd..96dec2205 100644 --- a/x/cheqd/types/tx.pb.go +++ b/x/cheqd/types/tx.pb.go @@ -6,6 +6,7 @@ package types import ( context "context" fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" @@ -28,26 +29,23 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // this line is used by starport scaffolding # proto/tx/message -type MsgCreateNym struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Alias string `protobuf:"bytes,2,opt,name=alias,proto3" json:"alias,omitempty"` - Verkey string `protobuf:"bytes,3,opt,name=verkey,proto3" json:"verkey,omitempty"` - Did string `protobuf:"bytes,4,opt,name=did,proto3" json:"did,omitempty"` - Role string `protobuf:"bytes,5,opt,name=role,proto3" json:"role,omitempty"` -} - -func (m *MsgCreateNym) Reset() { *m = MsgCreateNym{} } -func (m *MsgCreateNym) String() string { return proto.CompactTextString(m) } -func (*MsgCreateNym) ProtoMessage() {} -func (*MsgCreateNym) Descriptor() ([]byte, []int) { +type MsgWriteRequest struct { + Data *types.Any `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Signatures []*SignInfo `protobuf:"bytes,2,rep,name=signatures,proto3" json:"signatures,omitempty"` +} + +func (m *MsgWriteRequest) Reset() { *m = MsgWriteRequest{} } +func (m *MsgWriteRequest) String() string { return proto.CompactTextString(m) } +func (*MsgWriteRequest) ProtoMessage() {} +func (*MsgWriteRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{0} } -func (m *MsgCreateNym) XXX_Unmarshal(b []byte) error { +func (m *MsgWriteRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCreateNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgWriteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCreateNym.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgWriteRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -57,69 +55,49 @@ func (m *MsgCreateNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgCreateNym) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateNym.Merge(m, src) +func (m *MsgWriteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWriteRequest.Merge(m, src) } -func (m *MsgCreateNym) XXX_Size() int { +func (m *MsgWriteRequest) XXX_Size() int { return m.Size() } -func (m *MsgCreateNym) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateNym.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateNym proto.InternalMessageInfo - -func (m *MsgCreateNym) GetCreator() string { - if m != nil { - return m.Creator - } - return "" -} - -func (m *MsgCreateNym) GetAlias() string { - if m != nil { - return m.Alias - } - return "" +func (m *MsgWriteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWriteRequest.DiscardUnknown(m) } -func (m *MsgCreateNym) GetVerkey() string { - if m != nil { - return m.Verkey - } - return "" -} +var xxx_messageInfo_MsgWriteRequest proto.InternalMessageInfo -func (m *MsgCreateNym) GetDid() string { +func (m *MsgWriteRequest) GetData() *types.Any { if m != nil { - return m.Did + return m.Data } - return "" + return nil } -func (m *MsgCreateNym) GetRole() string { +func (m *MsgWriteRequest) GetSignatures() []*SignInfo { if m != nil { - return m.Role + return m.Signatures } - return "" + return nil } -type MsgCreateNymResponse struct { - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +type SignInfo struct { + VerificationMethodId string `protobuf:"bytes,1,opt,name=verification_method_id,json=verificationMethodId,proto3" json:"verification_method_id,omitempty"` + Signature string `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` } -func (m *MsgCreateNymResponse) Reset() { *m = MsgCreateNymResponse{} } -func (m *MsgCreateNymResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCreateNymResponse) ProtoMessage() {} -func (*MsgCreateNymResponse) Descriptor() ([]byte, []int) { +func (m *SignInfo) Reset() { *m = SignInfo{} } +func (m *SignInfo) String() string { return proto.CompactTextString(m) } +func (*SignInfo) ProtoMessage() {} +func (*SignInfo) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{1} } -func (m *MsgCreateNymResponse) XXX_Unmarshal(b []byte) error { +func (m *SignInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCreateNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *SignInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCreateNymResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_SignInfo.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -129,46 +107,58 @@ func (m *MsgCreateNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *MsgCreateNymResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateNymResponse.Merge(m, src) +func (m *SignInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignInfo.Merge(m, src) } -func (m *MsgCreateNymResponse) XXX_Size() int { +func (m *SignInfo) XXX_Size() int { return m.Size() } -func (m *MsgCreateNymResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateNymResponse.DiscardUnknown(m) +func (m *SignInfo) XXX_DiscardUnknown() { + xxx_messageInfo_SignInfo.DiscardUnknown(m) } -var xxx_messageInfo_MsgCreateNymResponse proto.InternalMessageInfo +var xxx_messageInfo_SignInfo proto.InternalMessageInfo -func (m *MsgCreateNymResponse) GetId() uint64 { +func (m *SignInfo) GetVerificationMethodId() string { if m != nil { - return m.Id + return m.VerificationMethodId } - return 0 + return "" } -type MsgUpdateNym struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` - Alias string `protobuf:"bytes,3,opt,name=alias,proto3" json:"alias,omitempty"` - Verkey string `protobuf:"bytes,4,opt,name=verkey,proto3" json:"verkey,omitempty"` - Did string `protobuf:"bytes,5,opt,name=did,proto3" json:"did,omitempty"` - Role string `protobuf:"bytes,6,opt,name=role,proto3" json:"role,omitempty"` +func (m *SignInfo) GetSignature() string { + if m != nil { + return m.Signature + } + return "" } -func (m *MsgUpdateNym) Reset() { *m = MsgUpdateNym{} } -func (m *MsgUpdateNym) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateNym) ProtoMessage() {} -func (*MsgUpdateNym) Descriptor() ([]byte, []int) { +type MsgCreateDid struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Controller []string `protobuf:"bytes,2,rep,name=controller,proto3" json:"controller,omitempty"` + VerificationMethod []*VerificationMethod `protobuf:"bytes,3,rep,name=verification_method,json=verificationMethod,proto3" json:"verification_method,omitempty"` + Authentication []string `protobuf:"bytes,4,rep,name=authentication,proto3" json:"authentication,omitempty"` + AssertionMethod []string `protobuf:"bytes,5,rep,name=assertion_method,json=assertionMethod,proto3" json:"assertion_method,omitempty"` + CapabilityInvocation []string `protobuf:"bytes,6,rep,name=capability_invocation,json=capabilityInvocation,proto3" json:"capability_invocation,omitempty"` + CapabilityDelegation []string `protobuf:"bytes,7,rep,name=capability_delegation,json=capabilityDelegation,proto3" json:"capability_delegation,omitempty"` + KeyAgreement []string `protobuf:"bytes,8,rep,name=key_agreement,json=keyAgreement,proto3" json:"key_agreement,omitempty"` + AlsoKnownAs []string `protobuf:"bytes,9,rep,name=also_known_as,json=alsoKnownAs,proto3" json:"also_known_as,omitempty"` + Service []*ServiceEndpoint `protobuf:"bytes,10,rep,name=service,proto3" json:"service,omitempty"` + Context []string `protobuf:"bytes,11,rep,name=context,proto3" json:"context,omitempty"` +} + +func (m *MsgCreateDid) Reset() { *m = MsgCreateDid{} } +func (m *MsgCreateDid) String() string { return proto.CompactTextString(m) } +func (*MsgCreateDid) ProtoMessage() {} +func (*MsgCreateDid) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{2} } -func (m *MsgUpdateNym) XXX_Unmarshal(b []byte) error { +func (m *MsgCreateDid) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCreateDid) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateNym.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCreateDid.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -178,75 +168,111 @@ func (m *MsgUpdateNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgUpdateNym) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateNym.Merge(m, src) +func (m *MsgCreateDid) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateDid.Merge(m, src) } -func (m *MsgUpdateNym) XXX_Size() int { +func (m *MsgCreateDid) XXX_Size() int { return m.Size() } -func (m *MsgUpdateNym) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateNym.DiscardUnknown(m) +func (m *MsgCreateDid) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateDid.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateNym proto.InternalMessageInfo +var xxx_messageInfo_MsgCreateDid proto.InternalMessageInfo -func (m *MsgUpdateNym) GetCreator() string { +func (m *MsgCreateDid) GetId() string { if m != nil { - return m.Creator + return m.Id } return "" } -func (m *MsgUpdateNym) GetId() uint64 { +func (m *MsgCreateDid) GetController() []string { if m != nil { - return m.Id + return m.Controller } - return 0 + return nil } -func (m *MsgUpdateNym) GetAlias() string { +func (m *MsgCreateDid) GetVerificationMethod() []*VerificationMethod { if m != nil { - return m.Alias + return m.VerificationMethod } - return "" + return nil } -func (m *MsgUpdateNym) GetVerkey() string { +func (m *MsgCreateDid) GetAuthentication() []string { if m != nil { - return m.Verkey + return m.Authentication } - return "" + return nil } -func (m *MsgUpdateNym) GetDid() string { +func (m *MsgCreateDid) GetAssertionMethod() []string { if m != nil { - return m.Did + return m.AssertionMethod } - return "" + return nil } -func (m *MsgUpdateNym) GetRole() string { +func (m *MsgCreateDid) GetCapabilityInvocation() []string { if m != nil { - return m.Role + return m.CapabilityInvocation } - return "" + return nil +} + +func (m *MsgCreateDid) GetCapabilityDelegation() []string { + if m != nil { + return m.CapabilityDelegation + } + return nil +} + +func (m *MsgCreateDid) GetKeyAgreement() []string { + if m != nil { + return m.KeyAgreement + } + return nil +} + +func (m *MsgCreateDid) GetAlsoKnownAs() []string { + if m != nil { + return m.AlsoKnownAs + } + return nil +} + +func (m *MsgCreateDid) GetService() []*ServiceEndpoint { + if m != nil { + return m.Service + } + return nil +} + +func (m *MsgCreateDid) GetContext() []string { + if m != nil { + return m.Context + } + return nil } -type MsgUpdateNymResponse struct { +type MsgCreateDidResponse struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } -func (m *MsgUpdateNymResponse) Reset() { *m = MsgUpdateNymResponse{} } -func (m *MsgUpdateNymResponse) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateNymResponse) ProtoMessage() {} -func (*MsgUpdateNymResponse) Descriptor() ([]byte, []int) { +func (m *MsgCreateDidResponse) Reset() { *m = MsgCreateDidResponse{} } +func (m *MsgCreateDidResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateDidResponse) ProtoMessage() {} +func (*MsgCreateDidResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{3} } -func (m *MsgUpdateNymResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgCreateDidResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpdateNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCreateDidResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpdateNymResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCreateDidResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -256,35 +282,52 @@ func (m *MsgUpdateNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *MsgUpdateNymResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateNymResponse.Merge(m, src) +func (m *MsgCreateDidResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateDidResponse.Merge(m, src) } -func (m *MsgUpdateNymResponse) XXX_Size() int { +func (m *MsgCreateDidResponse) XXX_Size() int { return m.Size() } -func (m *MsgUpdateNymResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateNymResponse.DiscardUnknown(m) +func (m *MsgCreateDidResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateDidResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpdateNymResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgCreateDidResponse proto.InternalMessageInfo -type MsgDeleteNym struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` +func (m *MsgCreateDidResponse) GetId() string { + if m != nil { + return m.Id + } + return "" } -func (m *MsgDeleteNym) Reset() { *m = MsgDeleteNym{} } -func (m *MsgDeleteNym) String() string { return proto.CompactTextString(m) } -func (*MsgDeleteNym) ProtoMessage() {} -func (*MsgDeleteNym) Descriptor() ([]byte, []int) { +type MsgUpdateDid struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Controller []string `protobuf:"bytes,2,rep,name=controller,proto3" json:"controller,omitempty"` + VerificationMethod []*VerificationMethod `protobuf:"bytes,3,rep,name=verification_method,json=verificationMethod,proto3" json:"verification_method,omitempty"` + Authentication []string `protobuf:"bytes,4,rep,name=authentication,proto3" json:"authentication,omitempty"` + AssertionMethod []string `protobuf:"bytes,5,rep,name=assertion_method,json=assertionMethod,proto3" json:"assertion_method,omitempty"` + CapabilityInvocation []string `protobuf:"bytes,6,rep,name=capability_invocation,json=capabilityInvocation,proto3" json:"capability_invocation,omitempty"` + CapabilityDelegation []string `protobuf:"bytes,7,rep,name=capability_delegation,json=capabilityDelegation,proto3" json:"capability_delegation,omitempty"` + KeyAgreement []string `protobuf:"bytes,8,rep,name=key_agreement,json=keyAgreement,proto3" json:"key_agreement,omitempty"` + AlsoKnownAs []string `protobuf:"bytes,9,rep,name=also_known_as,json=alsoKnownAs,proto3" json:"also_known_as,omitempty"` + Service []*ServiceEndpoint `protobuf:"bytes,10,rep,name=service,proto3" json:"service,omitempty"` + Context []string `protobuf:"bytes,11,rep,name=context,proto3" json:"context,omitempty"` + VersionId string `protobuf:"bytes,12,opt,name=version_id,json=versionId,proto3" json:"version_id,omitempty"` +} + +func (m *MsgUpdateDid) Reset() { *m = MsgUpdateDid{} } +func (m *MsgUpdateDid) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateDid) ProtoMessage() {} +func (*MsgUpdateDid) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{4} } -func (m *MsgDeleteNym) XXX_Unmarshal(b []byte) error { +func (m *MsgUpdateDid) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgDeleteNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgUpdateDid) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgDeleteNym.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgUpdateDid.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -294,47 +337,118 @@ func (m *MsgDeleteNym) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgDeleteNym) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgDeleteNym.Merge(m, src) +func (m *MsgUpdateDid) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateDid.Merge(m, src) } -func (m *MsgDeleteNym) XXX_Size() int { +func (m *MsgUpdateDid) XXX_Size() int { return m.Size() } -func (m *MsgDeleteNym) XXX_DiscardUnknown() { - xxx_messageInfo_MsgDeleteNym.DiscardUnknown(m) +func (m *MsgUpdateDid) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateDid.DiscardUnknown(m) } -var xxx_messageInfo_MsgDeleteNym proto.InternalMessageInfo +var xxx_messageInfo_MsgUpdateDid proto.InternalMessageInfo -func (m *MsgDeleteNym) GetCreator() string { +func (m *MsgUpdateDid) GetId() string { if m != nil { - return m.Creator + return m.Id } return "" } -func (m *MsgDeleteNym) GetId() uint64 { +func (m *MsgUpdateDid) GetController() []string { if m != nil { - return m.Id + return m.Controller + } + return nil +} + +func (m *MsgUpdateDid) GetVerificationMethod() []*VerificationMethod { + if m != nil { + return m.VerificationMethod + } + return nil +} + +func (m *MsgUpdateDid) GetAuthentication() []string { + if m != nil { + return m.Authentication + } + return nil +} + +func (m *MsgUpdateDid) GetAssertionMethod() []string { + if m != nil { + return m.AssertionMethod + } + return nil +} + +func (m *MsgUpdateDid) GetCapabilityInvocation() []string { + if m != nil { + return m.CapabilityInvocation + } + return nil +} + +func (m *MsgUpdateDid) GetCapabilityDelegation() []string { + if m != nil { + return m.CapabilityDelegation + } + return nil +} + +func (m *MsgUpdateDid) GetKeyAgreement() []string { + if m != nil { + return m.KeyAgreement + } + return nil +} + +func (m *MsgUpdateDid) GetAlsoKnownAs() []string { + if m != nil { + return m.AlsoKnownAs + } + return nil +} + +func (m *MsgUpdateDid) GetService() []*ServiceEndpoint { + if m != nil { + return m.Service + } + return nil +} + +func (m *MsgUpdateDid) GetContext() []string { + if m != nil { + return m.Context + } + return nil +} + +func (m *MsgUpdateDid) GetVersionId() string { + if m != nil { + return m.VersionId } - return 0 + return "" } -type MsgDeleteNymResponse struct { +type MsgUpdateDidResponse struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } -func (m *MsgDeleteNymResponse) Reset() { *m = MsgDeleteNymResponse{} } -func (m *MsgDeleteNymResponse) String() string { return proto.CompactTextString(m) } -func (*MsgDeleteNymResponse) ProtoMessage() {} -func (*MsgDeleteNymResponse) Descriptor() ([]byte, []int) { +func (m *MsgUpdateDidResponse) Reset() { *m = MsgUpdateDidResponse{} } +func (m *MsgUpdateDidResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateDidResponse) ProtoMessage() {} +func (*MsgUpdateDidResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d0277a2196c64ae2, []int{5} } -func (m *MsgDeleteNymResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgUpdateDidResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgDeleteNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgUpdateDidResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgDeleteNymResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgUpdateDidResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -344,53 +458,76 @@ func (m *MsgDeleteNymResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *MsgDeleteNymResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgDeleteNymResponse.Merge(m, src) +func (m *MsgUpdateDidResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateDidResponse.Merge(m, src) } -func (m *MsgDeleteNymResponse) XXX_Size() int { +func (m *MsgUpdateDidResponse) XXX_Size() int { return m.Size() } -func (m *MsgDeleteNymResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgDeleteNymResponse.DiscardUnknown(m) +func (m *MsgUpdateDidResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateDidResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgDeleteNymResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgUpdateDidResponse proto.InternalMessageInfo + +func (m *MsgUpdateDidResponse) GetId() string { + if m != nil { + return m.Id + } + return "" +} func init() { - proto.RegisterType((*MsgCreateNym)(nil), "cheqdid.cheqdnode.cheqd.MsgCreateNym") - proto.RegisterType((*MsgCreateNymResponse)(nil), "cheqdid.cheqdnode.cheqd.MsgCreateNymResponse") - proto.RegisterType((*MsgUpdateNym)(nil), "cheqdid.cheqdnode.cheqd.MsgUpdateNym") - proto.RegisterType((*MsgUpdateNymResponse)(nil), "cheqdid.cheqdnode.cheqd.MsgUpdateNymResponse") - proto.RegisterType((*MsgDeleteNym)(nil), "cheqdid.cheqdnode.cheqd.MsgDeleteNym") - proto.RegisterType((*MsgDeleteNymResponse)(nil), "cheqdid.cheqdnode.cheqd.MsgDeleteNymResponse") + proto.RegisterType((*MsgWriteRequest)(nil), "cheqdid.cheqdnode.cheqd.MsgWriteRequest") + proto.RegisterType((*SignInfo)(nil), "cheqdid.cheqdnode.cheqd.SignInfo") + proto.RegisterType((*MsgCreateDid)(nil), "cheqdid.cheqdnode.cheqd.MsgCreateDid") + proto.RegisterType((*MsgCreateDidResponse)(nil), "cheqdid.cheqdnode.cheqd.MsgCreateDidResponse") + proto.RegisterType((*MsgUpdateDid)(nil), "cheqdid.cheqdnode.cheqd.MsgUpdateDid") + proto.RegisterType((*MsgUpdateDidResponse)(nil), "cheqdid.cheqdnode.cheqd.MsgUpdateDidResponse") } func init() { proto.RegisterFile("cheqd/tx.proto", fileDescriptor_d0277a2196c64ae2) } var fileDescriptor_d0277a2196c64ae2 = []byte{ - // 348 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0xce, 0x48, 0x2d, - 0x4c, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x07, 0xf3, 0x33, 0x53, - 0xf4, 0xc0, 0x74, 0x5e, 0x7e, 0x4a, 0x2a, 0x84, 0xa5, 0x54, 0xc3, 0xc5, 0xe3, 0x5b, 0x9c, 0xee, - 0x5c, 0x94, 0x9a, 0x58, 0x92, 0xea, 0x57, 0x99, 0x2b, 0x24, 0xc1, 0xc5, 0x9e, 0x0c, 0xe2, 0xe4, - 0x17, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x42, 0x22, 0x5c, 0xac, 0x89, 0x39, - 0x99, 0x89, 0xc5, 0x12, 0x4c, 0x60, 0x71, 0x08, 0x47, 0x48, 0x8c, 0x8b, 0xad, 0x2c, 0xb5, 0x28, - 0x3b, 0xb5, 0x52, 0x82, 0x19, 0x2c, 0x0c, 0xe5, 0x09, 0x09, 0x70, 0x31, 0xa7, 0x64, 0xa6, 0x48, - 0xb0, 0x80, 0x05, 0x41, 0x4c, 0x21, 0x21, 0x2e, 0x96, 0xa2, 0xfc, 0x9c, 0x54, 0x09, 0x56, 0xb0, - 0x10, 0x98, 0xad, 0xa4, 0xc6, 0x25, 0x82, 0x6c, 0x7b, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, - 0xaa, 0x10, 0x1f, 0x17, 0x53, 0x66, 0x0a, 0xd8, 0x01, 0x2c, 0x41, 0x4c, 0x99, 0x29, 0x4a, 0x3d, - 0x8c, 0x60, 0x67, 0x86, 0x16, 0xa4, 0x10, 0x74, 0x26, 0x44, 0x2b, 0x13, 0x4c, 0x2b, 0xc2, 0xd9, - 0xcc, 0xd8, 0x9d, 0xcd, 0x82, 0xcd, 0xd9, 0xac, 0x98, 0xce, 0x66, 0x43, 0x72, 0xb6, 0x18, 0xd8, - 0xd9, 0x70, 0xd7, 0xc0, 0x9c, 0xad, 0x64, 0x01, 0x76, 0xa5, 0x4b, 0x6a, 0x4e, 0x2a, 0x89, 0xae, - 0x84, 0x9a, 0x08, 0xd7, 0x09, 0x33, 0xd1, 0x68, 0x1d, 0x13, 0x17, 0xb3, 0x6f, 0x71, 0xba, 0x50, - 0x22, 0x17, 0x27, 0x22, 0x8e, 0x54, 0xf5, 0x70, 0xc4, 0xa6, 0x1e, 0x72, 0x60, 0x4a, 0xe9, 0x12, - 0xa5, 0x0c, 0x1e, 0xe6, 0x89, 0x5c, 0x9c, 0x88, 0xf0, 0xc5, 0x6b, 0x05, 0x5c, 0x19, 0x7e, 0x2b, - 0x30, 0xc2, 0x07, 0x64, 0x05, 0x22, 0x70, 0xf0, 0x5a, 0x01, 0x57, 0x86, 0xdf, 0x0a, 0x8c, 0x00, - 0x73, 0x72, 0x3e, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, - 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, - 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x48, 0xee, 0x00, 0x93, 0xba, 0x20, 0x13, - 0xf5, 0x2b, 0xa0, 0x42, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x4c, 0x63, 0x0c, 0x08, - 0x00, 0x00, 0xff, 0xff, 0xec, 0xc5, 0x32, 0x06, 0x46, 0x03, 0x00, 0x00, + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x55, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x6d, 0xd2, 0x7e, 0x6d, 0x7d, 0xd3, 0x9f, 0x4f, 0x43, 0x00, 0x53, 0x81, 0x55, 0x8c, 0x54, + 0xa5, 0x42, 0x75, 0xa4, 0x96, 0x17, 0x48, 0x5b, 0x16, 0x11, 0xca, 0xc6, 0x08, 0x90, 0x10, 0xc2, + 0x9a, 0x78, 0x6e, 0x9d, 0x51, 0xdd, 0x19, 0xd7, 0x33, 0x09, 0xf5, 0x06, 0xf1, 0x08, 0xbc, 0x01, + 0xaf, 0xc3, 0xb2, 0xec, 0x58, 0xa2, 0xf6, 0x45, 0x90, 0xc7, 0x8e, 0x13, 0x25, 0x84, 0x15, 0x3b, + 0xd8, 0x24, 0x99, 0x73, 0xcf, 0x3d, 0x73, 0xee, 0xe4, 0x68, 0x06, 0xb6, 0xc2, 0x01, 0x5e, 0xb2, + 0xb6, 0xbe, 0xf2, 0x92, 0x54, 0x6a, 0x49, 0xee, 0x9b, 0x35, 0x67, 0x9e, 0xf9, 0x16, 0x92, 0x61, + 0xf1, 0x6b, 0xe7, 0x41, 0x24, 0x65, 0x14, 0x63, 0xdb, 0xd0, 0xfa, 0xc3, 0xb3, 0x36, 0x15, 0x59, + 0xd1, 0xb3, 0xb3, 0x5d, 0x68, 0xe4, 0x5d, 0x06, 0x70, 0x3f, 0xc2, 0x76, 0x4f, 0x45, 0x6f, 0x52, + 0xae, 0xd1, 0xc7, 0xcb, 0x21, 0x2a, 0x4d, 0x5a, 0xb0, 0xc2, 0xa8, 0xa6, 0x76, 0x6d, 0xb7, 0xd6, + 0x6a, 0x1c, 0x36, 0xbd, 0x42, 0xcd, 0x1b, 0xab, 0x79, 0x1d, 0x91, 0xf9, 0x86, 0x41, 0x3a, 0x00, + 0x8a, 0x47, 0x82, 0xea, 0x61, 0x8a, 0xca, 0xae, 0xef, 0x2e, 0xb7, 0x1a, 0x87, 0x8f, 0xbd, 0x05, + 0xb6, 0xbc, 0x97, 0x3c, 0x12, 0x5d, 0x71, 0x26, 0xfd, 0xa9, 0x26, 0xf7, 0x3d, 0xac, 0x8f, 0x71, + 0xf2, 0x0c, 0xee, 0x8d, 0x30, 0xe5, 0x67, 0x3c, 0xa4, 0x9a, 0x4b, 0x11, 0x5c, 0xa0, 0x1e, 0x48, + 0x16, 0x70, 0x66, 0xac, 0x58, 0x7e, 0x73, 0xba, 0xda, 0x33, 0xc5, 0x2e, 0x23, 0x0f, 0xc1, 0xaa, + 0xf4, 0xec, 0xba, 0x21, 0x4e, 0x00, 0xf7, 0xd3, 0x0a, 0x6c, 0xf4, 0x54, 0x74, 0x92, 0x22, 0xd5, + 0x78, 0xca, 0x19, 0xd9, 0x82, 0x7a, 0x25, 0x58, 0xe7, 0x8c, 0x38, 0x00, 0xa1, 0x14, 0x3a, 0x95, + 0x71, 0x8c, 0xa9, 0x99, 0xc1, 0xf2, 0xa7, 0x10, 0xf2, 0x0e, 0xee, 0xfc, 0xc2, 0x94, 0xbd, 0x6c, + 0x86, 0x7d, 0xba, 0x70, 0xd8, 0xd7, 0x73, 0x56, 0x7d, 0x32, 0x6f, 0x9f, 0xec, 0xc1, 0x16, 0x1d, + 0xea, 0x01, 0x0a, 0x5d, 0xe2, 0xf6, 0x8a, 0x71, 0x30, 0x83, 0x92, 0x7d, 0xf8, 0x9f, 0x2a, 0x85, + 0xe9, 0xb4, 0x85, 0xff, 0x0c, 0x73, 0xbb, 0xc2, 0x4b, 0xc9, 0x23, 0xb8, 0x1b, 0xd2, 0x84, 0xf6, + 0x79, 0xcc, 0x75, 0x16, 0x70, 0x31, 0x92, 0xa5, 0xf2, 0xaa, 0xe1, 0x37, 0x27, 0xc5, 0x6e, 0x55, + 0x9b, 0x69, 0x62, 0x18, 0x63, 0x54, 0x34, 0xad, 0xcd, 0x36, 0x9d, 0x56, 0x35, 0xf2, 0x04, 0x36, + 0xcf, 0x31, 0x0b, 0x68, 0x94, 0x22, 0x5e, 0xa0, 0xd0, 0xf6, 0xba, 0x21, 0x6f, 0x9c, 0x63, 0xd6, + 0x19, 0x63, 0xc4, 0x85, 0x4d, 0x1a, 0x2b, 0x19, 0x9c, 0x0b, 0xf9, 0x41, 0x04, 0x54, 0xd9, 0x96, + 0x21, 0x35, 0x72, 0xf0, 0x45, 0x8e, 0x75, 0x14, 0x39, 0x86, 0x35, 0x85, 0xe9, 0x88, 0x87, 0x68, + 0x83, 0x39, 0xd7, 0xd6, 0xe2, 0x10, 0x15, 0xbc, 0xe7, 0x82, 0x25, 0x92, 0x0b, 0xed, 0x8f, 0x1b, + 0x89, 0x0d, 0x6b, 0xf9, 0xbf, 0x86, 0x57, 0xda, 0x6e, 0x98, 0x1d, 0xc6, 0x4b, 0x77, 0x0f, 0x9a, + 0xd3, 0x09, 0xf0, 0x51, 0x25, 0x52, 0x28, 0x9c, 0x4d, 0x82, 0xfb, 0xa5, 0x88, 0xca, 0xab, 0x84, + 0xfd, 0x8b, 0xca, 0xdf, 0x19, 0x15, 0xf2, 0x08, 0x60, 0x84, 0xa9, 0xca, 0x4f, 0x8e, 0x33, 0x7b, + 0xa3, 0xb8, 0x4c, 0x4a, 0xa4, 0xcb, 0xca, 0x24, 0x55, 0x01, 0x59, 0x94, 0xa4, 0xc3, 0x6f, 0x35, + 0x58, 0xee, 0xa9, 0x88, 0x30, 0xb0, 0x26, 0x17, 0xcf, 0x62, 0xa3, 0x33, 0x17, 0xf0, 0xce, 0xc1, + 0xef, 0x98, 0xf3, 0x39, 0x66, 0x60, 0x4d, 0x32, 0xfb, 0x87, 0x76, 0x99, 0x9b, 0xf1, 0xf8, 0xe4, + 0xeb, 0x8d, 0x53, 0xbb, 0xbe, 0x71, 0x6a, 0x3f, 0x6e, 0x9c, 0xda, 0xe7, 0x5b, 0x67, 0xe9, 0xfa, + 0xd6, 0x59, 0xfa, 0x7e, 0xeb, 0x2c, 0xbd, 0xdd, 0x8f, 0xb8, 0x1e, 0x0c, 0xfb, 0x5e, 0x28, 0x2f, + 0xda, 0xc5, 0xf3, 0x62, 0x3e, 0x0f, 0x72, 0xc5, 0xf6, 0x55, 0x09, 0xe9, 0x2c, 0x41, 0xd5, 0x5f, + 0x35, 0x8f, 0xc8, 0xd1, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x51, 0x45, 0x39, 0xaa, 0xcb, 0x06, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -405,10 +542,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - // this line is used by starport scaffolding # proto/tx/rpc - CreateNym(ctx context.Context, in *MsgCreateNym, opts ...grpc.CallOption) (*MsgCreateNymResponse, error) - UpdateNym(ctx context.Context, in *MsgUpdateNym, opts ...grpc.CallOption) (*MsgUpdateNymResponse, error) - DeleteNym(ctx context.Context, in *MsgDeleteNym, opts ...grpc.CallOption) (*MsgDeleteNymResponse, error) + CreateDid(ctx context.Context, in *MsgWriteRequest, opts ...grpc.CallOption) (*MsgCreateDidResponse, error) + UpdateDid(ctx context.Context, in *MsgWriteRequest, opts ...grpc.CallOption) (*MsgUpdateDidResponse, error) } type msgClient struct { @@ -419,27 +554,18 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) CreateNym(ctx context.Context, in *MsgCreateNym, opts ...grpc.CallOption) (*MsgCreateNymResponse, error) { - out := new(MsgCreateNymResponse) - err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Msg/CreateNym", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) UpdateNym(ctx context.Context, in *MsgUpdateNym, opts ...grpc.CallOption) (*MsgUpdateNymResponse, error) { - out := new(MsgUpdateNymResponse) - err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Msg/UpdateNym", in, out, opts...) +func (c *msgClient) CreateDid(ctx context.Context, in *MsgWriteRequest, opts ...grpc.CallOption) (*MsgCreateDidResponse, error) { + out := new(MsgCreateDidResponse) + err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Msg/CreateDid", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) DeleteNym(ctx context.Context, in *MsgDeleteNym, opts ...grpc.CallOption) (*MsgDeleteNymResponse, error) { - out := new(MsgDeleteNymResponse) - err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Msg/DeleteNym", in, out, opts...) +func (c *msgClient) UpdateDid(ctx context.Context, in *MsgWriteRequest, opts ...grpc.CallOption) (*MsgUpdateDidResponse, error) { + out := new(MsgUpdateDidResponse) + err := c.cc.Invoke(ctx, "/cheqdid.cheqdnode.cheqd.Msg/UpdateDid", in, out, opts...) if err != nil { return nil, err } @@ -448,80 +574,57 @@ func (c *msgClient) DeleteNym(ctx context.Context, in *MsgDeleteNym, opts ...grp // MsgServer is the server API for Msg service. type MsgServer interface { - // this line is used by starport scaffolding # proto/tx/rpc - CreateNym(context.Context, *MsgCreateNym) (*MsgCreateNymResponse, error) - UpdateNym(context.Context, *MsgUpdateNym) (*MsgUpdateNymResponse, error) - DeleteNym(context.Context, *MsgDeleteNym) (*MsgDeleteNymResponse, error) + CreateDid(context.Context, *MsgWriteRequest) (*MsgCreateDidResponse, error) + UpdateDid(context.Context, *MsgWriteRequest) (*MsgUpdateDidResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) CreateNym(ctx context.Context, req *MsgCreateNym) (*MsgCreateNymResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateNym not implemented") -} -func (*UnimplementedMsgServer) UpdateNym(ctx context.Context, req *MsgUpdateNym) (*MsgUpdateNymResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateNym not implemented") +func (*UnimplementedMsgServer) CreateDid(ctx context.Context, req *MsgWriteRequest) (*MsgCreateDidResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateDid not implemented") } -func (*UnimplementedMsgServer) DeleteNym(ctx context.Context, req *MsgDeleteNym) (*MsgDeleteNymResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeleteNym not implemented") +func (*UnimplementedMsgServer) UpdateDid(ctx context.Context, req *MsgWriteRequest) (*MsgUpdateDidResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateDid not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_CreateNym_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCreateNym) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).CreateNym(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cheqdid.cheqdnode.cheqd.Msg/CreateNym", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CreateNym(ctx, req.(*MsgCreateNym)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_UpdateNym_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpdateNym) +func _Msg_CreateDid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWriteRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UpdateNym(ctx, in) + return srv.(MsgServer).CreateDid(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cheqdid.cheqdnode.cheqd.Msg/UpdateNym", + FullMethod: "/cheqdid.cheqdnode.cheqd.Msg/CreateDid", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpdateNym(ctx, req.(*MsgUpdateNym)) + return srv.(MsgServer).CreateDid(ctx, req.(*MsgWriteRequest)) } return interceptor(ctx, in, info, handler) } -func _Msg_DeleteNym_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgDeleteNym) +func _Msg_UpdateDid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWriteRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).DeleteNym(ctx, in) + return srv.(MsgServer).UpdateDid(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cheqdid.cheqdnode.cheqd.Msg/DeleteNym", + FullMethod: "/cheqdid.cheqdnode.cheqd.Msg/UpdateDid", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).DeleteNym(ctx, req.(*MsgDeleteNym)) + return srv.(MsgServer).UpdateDid(ctx, req.(*MsgWriteRequest)) } return interceptor(ctx, in, info, handler) } @@ -531,23 +634,19 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "CreateNym", - Handler: _Msg_CreateNym_Handler, - }, - { - MethodName: "UpdateNym", - Handler: _Msg_UpdateNym_Handler, + MethodName: "CreateDid", + Handler: _Msg_CreateDid_Handler, }, { - MethodName: "DeleteNym", - Handler: _Msg_DeleteNym_Handler, + MethodName: "UpdateDid", + Handler: _Msg_UpdateDid_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "cheqd/tx.proto", } -func (m *MsgCreateNym) Marshal() (dAtA []byte, err error) { +func (m *MsgWriteRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -557,55 +656,46 @@ func (m *MsgCreateNym) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCreateNym) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgWriteRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCreateNym) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgWriteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Role) > 0 { - i -= len(m.Role) - copy(dAtA[i:], m.Role) - i = encodeVarintTx(dAtA, i, uint64(len(m.Role))) - i-- - dAtA[i] = 0x2a - } - if len(m.Did) > 0 { - i -= len(m.Did) - copy(dAtA[i:], m.Did) - i = encodeVarintTx(dAtA, i, uint64(len(m.Did))) - i-- - dAtA[i] = 0x22 - } - if len(m.Verkey) > 0 { - i -= len(m.Verkey) - copy(dAtA[i:], m.Verkey) - i = encodeVarintTx(dAtA, i, uint64(len(m.Verkey))) - i-- - dAtA[i] = 0x1a - } - if len(m.Alias) > 0 { - i -= len(m.Alias) - copy(dAtA[i:], m.Alias) - i = encodeVarintTx(dAtA, i, uint64(len(m.Alias))) - i-- - dAtA[i] = 0x12 + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Signatures[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } } - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + if m.Data != nil { + { + size, err := m.Data.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgCreateNymResponse) Marshal() (dAtA []byte, err error) { +func (m *SignInfo) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -615,25 +705,34 @@ func (m *MsgCreateNymResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCreateNymResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *SignInfo) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCreateNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *SignInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Id != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Id)) + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x12 + } + if len(m.VerificationMethodId) > 0 { + i -= len(m.VerificationMethodId) + copy(dAtA[i:], m.VerificationMethodId) + i = encodeVarintTx(dAtA, i, uint64(len(m.VerificationMethodId))) i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgUpdateNym) Marshal() (dAtA []byte, err error) { +func (m *MsgCreateDid) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -643,60 +742,127 @@ func (m *MsgUpdateNym) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateNym) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCreateDid) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateNym) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCreateDid) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Role) > 0 { - i -= len(m.Role) - copy(dAtA[i:], m.Role) - i = encodeVarintTx(dAtA, i, uint64(len(m.Role))) - i-- - dAtA[i] = 0x32 + if len(m.Context) > 0 { + for iNdEx := len(m.Context) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Context[iNdEx]) + copy(dAtA[i:], m.Context[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Context[iNdEx]))) + i-- + dAtA[i] = 0x5a + } } - if len(m.Did) > 0 { - i -= len(m.Did) - copy(dAtA[i:], m.Did) - i = encodeVarintTx(dAtA, i, uint64(len(m.Did))) - i-- - dAtA[i] = 0x2a + if len(m.Service) > 0 { + for iNdEx := len(m.Service) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Service[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } } - if len(m.Verkey) > 0 { - i -= len(m.Verkey) - copy(dAtA[i:], m.Verkey) - i = encodeVarintTx(dAtA, i, uint64(len(m.Verkey))) - i-- - dAtA[i] = 0x22 + if len(m.AlsoKnownAs) > 0 { + for iNdEx := len(m.AlsoKnownAs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AlsoKnownAs[iNdEx]) + copy(dAtA[i:], m.AlsoKnownAs[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.AlsoKnownAs[iNdEx]))) + i-- + dAtA[i] = 0x4a + } } - if len(m.Alias) > 0 { - i -= len(m.Alias) - copy(dAtA[i:], m.Alias) - i = encodeVarintTx(dAtA, i, uint64(len(m.Alias))) - i-- - dAtA[i] = 0x1a + if len(m.KeyAgreement) > 0 { + for iNdEx := len(m.KeyAgreement) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.KeyAgreement[iNdEx]) + copy(dAtA[i:], m.KeyAgreement[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.KeyAgreement[iNdEx]))) + i-- + dAtA[i] = 0x42 + } } - if m.Id != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x10 + if len(m.CapabilityDelegation) > 0 { + for iNdEx := len(m.CapabilityDelegation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityDelegation[iNdEx]) + copy(dAtA[i:], m.CapabilityDelegation[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.CapabilityDelegation[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if len(m.CapabilityInvocation) > 0 { + for iNdEx := len(m.CapabilityInvocation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityInvocation[iNdEx]) + copy(dAtA[i:], m.CapabilityInvocation[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.CapabilityInvocation[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if len(m.AssertionMethod) > 0 { + for iNdEx := len(m.AssertionMethod) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AssertionMethod[iNdEx]) + copy(dAtA[i:], m.AssertionMethod[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.AssertionMethod[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.Authentication) > 0 { + for iNdEx := len(m.Authentication) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Authentication[iNdEx]) + copy(dAtA[i:], m.Authentication[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authentication[iNdEx]))) + i-- + dAtA[i] = 0x22 + } } - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + if len(m.VerificationMethod) > 0 { + for iNdEx := len(m.VerificationMethod) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VerificationMethod[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Controller) > 0 { + for iNdEx := len(m.Controller) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Controller[iNdEx]) + copy(dAtA[i:], m.Controller[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Controller[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintTx(dAtA, i, uint64(len(m.Id))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgUpdateNymResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgCreateDidResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -706,20 +872,27 @@ func (m *MsgUpdateNymResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateNymResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCreateDidResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCreateDidResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintTx(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } -func (m *MsgDeleteNym) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdateDid) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -729,32 +902,134 @@ func (m *MsgDeleteNym) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgDeleteNym) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdateDid) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgDeleteNym) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdateDid) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Id != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Id)) + if len(m.VersionId) > 0 { + i -= len(m.VersionId) + copy(dAtA[i:], m.VersionId) + i = encodeVarintTx(dAtA, i, uint64(len(m.VersionId))) i-- - dAtA[i] = 0x10 + dAtA[i] = 0x62 + } + if len(m.Context) > 0 { + for iNdEx := len(m.Context) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Context[iNdEx]) + copy(dAtA[i:], m.Context[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Context[iNdEx]))) + i-- + dAtA[i] = 0x5a + } + } + if len(m.Service) > 0 { + for iNdEx := len(m.Service) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Service[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } + } + if len(m.AlsoKnownAs) > 0 { + for iNdEx := len(m.AlsoKnownAs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AlsoKnownAs[iNdEx]) + copy(dAtA[i:], m.AlsoKnownAs[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.AlsoKnownAs[iNdEx]))) + i-- + dAtA[i] = 0x4a + } + } + if len(m.KeyAgreement) > 0 { + for iNdEx := len(m.KeyAgreement) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.KeyAgreement[iNdEx]) + copy(dAtA[i:], m.KeyAgreement[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.KeyAgreement[iNdEx]))) + i-- + dAtA[i] = 0x42 + } + } + if len(m.CapabilityDelegation) > 0 { + for iNdEx := len(m.CapabilityDelegation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityDelegation[iNdEx]) + copy(dAtA[i:], m.CapabilityDelegation[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.CapabilityDelegation[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if len(m.CapabilityInvocation) > 0 { + for iNdEx := len(m.CapabilityInvocation) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.CapabilityInvocation[iNdEx]) + copy(dAtA[i:], m.CapabilityInvocation[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.CapabilityInvocation[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if len(m.AssertionMethod) > 0 { + for iNdEx := len(m.AssertionMethod) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AssertionMethod[iNdEx]) + copy(dAtA[i:], m.AssertionMethod[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.AssertionMethod[iNdEx]))) + i-- + dAtA[i] = 0x2a + } } - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + if len(m.Authentication) > 0 { + for iNdEx := len(m.Authentication) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Authentication[iNdEx]) + copy(dAtA[i:], m.Authentication[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authentication[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.VerificationMethod) > 0 { + for iNdEx := len(m.VerificationMethod) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VerificationMethod[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Controller) > 0 { + for iNdEx := len(m.Controller) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Controller[iNdEx]) + copy(dAtA[i:], m.Controller[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Controller[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintTx(dAtA, i, uint64(len(m.Id))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgDeleteNymResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdateDidResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -764,16 +1039,23 @@ func (m *MsgDeleteNymResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgDeleteNymResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdateDidResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgDeleteNymResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdateDidResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintTx(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -788,110 +1070,215 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgCreateNym) Size() (n int) { +func (m *MsgWriteRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Creator) - if l > 0 { + if m.Data != nil { + l = m.Data.Size() n += 1 + l + sovTx(uint64(l)) } - l = len(m.Alias) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + if len(m.Signatures) > 0 { + for _, e := range m.Signatures { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } } - l = len(m.Verkey) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *SignInfo) Size() (n int) { + if m == nil { + return 0 } - l = len(m.Did) + var l int + _ = l + l = len(m.VerificationMethodId) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Role) + l = len(m.Signature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } return n } -func (m *MsgCreateNymResponse) Size() (n int) { +func (m *MsgCreateDid) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Id != 0 { - n += 1 + sovTx(uint64(m.Id)) + l = len(m.Id) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Controller) > 0 { + for _, s := range m.Controller { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.VerificationMethod) > 0 { + for _, e := range m.VerificationMethod { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Authentication) > 0 { + for _, s := range m.Authentication { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.AssertionMethod) > 0 { + for _, s := range m.AssertionMethod { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.CapabilityInvocation) > 0 { + for _, s := range m.CapabilityInvocation { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.CapabilityDelegation) > 0 { + for _, s := range m.CapabilityDelegation { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.KeyAgreement) > 0 { + for _, s := range m.KeyAgreement { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.AlsoKnownAs) > 0 { + for _, s := range m.AlsoKnownAs { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Service) > 0 { + for _, e := range m.Service { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Context) > 0 { + for _, s := range m.Context { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } } return n } -func (m *MsgUpdateNym) Size() (n int) { +func (m *MsgCreateDidResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Creator) + l = len(m.Id) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.Id != 0 { - n += 1 + sovTx(uint64(m.Id)) - } - l = len(m.Alias) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Verkey) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Did) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Role) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgUpdateNymResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l return n } -func (m *MsgDeleteNym) Size() (n int) { +func (m *MsgUpdateDid) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Creator) + l = len(m.Id) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.Id != 0 { - n += 1 + sovTx(uint64(m.Id)) + if len(m.Controller) > 0 { + for _, s := range m.Controller { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.VerificationMethod) > 0 { + for _, e := range m.VerificationMethod { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Authentication) > 0 { + for _, s := range m.Authentication { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.AssertionMethod) > 0 { + for _, s := range m.AssertionMethod { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.CapabilityInvocation) > 0 { + for _, s := range m.CapabilityInvocation { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.CapabilityDelegation) > 0 { + for _, s := range m.CapabilityDelegation { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.KeyAgreement) > 0 { + for _, s := range m.KeyAgreement { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.AlsoKnownAs) > 0 { + for _, s := range m.AlsoKnownAs { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Service) > 0 { + for _, e := range m.Service { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Context) > 0 { + for _, s := range m.Context { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.VersionId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) } return n } -func (m *MsgDeleteNymResponse) Size() (n int) { +func (m *MsgUpdateDidResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l + l = len(m.Id) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -901,7 +1288,729 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { +func (m *MsgWriteRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWriteRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWriteRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Data == nil { + m.Data = &types.Any{} + } + if err := m.Data.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signatures = append(m.Signatures, &SignInfo{}) + if err := m.Signatures[len(m.Signatures)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationMethodId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VerificationMethodId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateDid) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateDid: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateDid: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Controller", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Controller = append(m.Controller, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VerificationMethod", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VerificationMethod = append(m.VerificationMethod, &VerificationMethod{}) + if err := m.VerificationMethod[len(m.VerificationMethod)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authentication", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authentication = append(m.Authentication, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AssertionMethod", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssertionMethod = append(m.AssertionMethod, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityInvocation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CapabilityInvocation = append(m.CapabilityInvocation, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityDelegation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CapabilityDelegation = append(m.CapabilityDelegation, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KeyAgreement", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KeyAgreement = append(m.KeyAgreement, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AlsoKnownAs", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AlsoKnownAs = append(m.AlsoKnownAs, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Service", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Service = append(m.Service, &ServiceEndpoint{}) + if err := m.Service[len(m.Service)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Context = append(m.Context, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateDidResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateDidResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateDidResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateDid) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -924,15 +2033,15 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCreateNym: wiretype end group for non-group") + return fmt.Errorf("proto: MsgUpdateDid: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateNym: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgUpdateDid: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -960,11 +2069,11 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Creator = string(dAtA[iNdEx:postIndex]) + m.Id = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alias", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Controller", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -992,13 +2101,13 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Alias = string(dAtA[iNdEx:postIndex]) + m.Controller = append(m.Controller, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Verkey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VerificationMethod", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1008,27 +2117,29 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Verkey = string(dAtA[iNdEx:postIndex]) + m.VerificationMethod = append(m.VerificationMethod, &VerificationMethod{}) + if err := m.VerificationMethod[len(m.VerificationMethod)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Did", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Authentication", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1056,11 +2167,11 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Did = string(dAtA[iNdEx:postIndex]) + m.Authentication = append(m.Authentication, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AssertionMethod", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1088,63 +2199,13 @@ func (m *MsgCreateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Role = string(dAtA[iNdEx:postIndex]) + m.AssertionMethod = append(m.AssertionMethod, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCreateNymResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgCreateNymResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateNymResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityInvocation", wireType) } - m.Id = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1154,64 +2215,27 @@ func (m *MsgCreateNymResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Id |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTx } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx } - if iNdEx >= l { + if postIndex > l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateNym: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateNym: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + m.CapabilityInvocation = append(m.CapabilityInvocation, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 7: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CapabilityDelegation", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1239,13 +2263,13 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Creator = string(dAtA[iNdEx:postIndex]) + m.CapabilityDelegation = append(m.CapabilityDelegation, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KeyAgreement", wireType) } - m.Id = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1255,14 +2279,27 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Id |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 3: + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KeyAgreement = append(m.KeyAgreement, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 9: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Alias", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AlsoKnownAs", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1290,13 +2327,13 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Alias = string(dAtA[iNdEx:postIndex]) + m.AlsoKnownAs = append(m.AlsoKnownAs, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 4: + case 10: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Verkey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Service", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1306,27 +2343,29 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Verkey = string(dAtA[iNdEx:postIndex]) + m.Service = append(m.Service, &ServiceEndpoint{}) + if err := m.Service[len(m.Service)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 5: + case 11: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Did", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1354,11 +2393,11 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Did = string(dAtA[iNdEx:postIndex]) + m.Context = append(m.Context, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 6: + case 12: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VersionId", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1386,7 +2425,7 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Role = string(dAtA[iNdEx:postIndex]) + m.VersionId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1409,57 +2448,7 @@ func (m *MsgUpdateNym) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpdateNymResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateNymResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateNymResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgDeleteNym) Unmarshal(dAtA []byte) error { +func (m *MsgUpdateDidResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1482,15 +2471,15 @@ func (m *MsgDeleteNym) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgDeleteNym: wiretype end group for non-group") + return fmt.Errorf("proto: MsgUpdateDidResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDeleteNym: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgUpdateDidResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1518,77 +2507,8 @@ func (m *MsgDeleteNym) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Creator = string(dAtA[iNdEx:postIndex]) + m.Id = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgDeleteNymResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgDeleteNymResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDeleteNymResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/cheqd/utils/did.go b/x/cheqd/utils/did.go new file mode 100644 index 000000000..a15435926 --- /dev/null +++ b/x/cheqd/utils/did.go @@ -0,0 +1,78 @@ +package utils + +import ( + "regexp" + "strings" +) + +var DidForbiddenSymbolsRegexp, _ = regexp.Compile(`^[^#?&/\\]+$`) + +func SplitDidUrlIntoDidAndFragment(didUrl string) (string, string) { + fragments := strings.Split(didUrl, "#") + return fragments[0], fragments[1] +} + +func IsDidFragment(prefix string, didUrl string) bool { + if !strings.Contains(didUrl, "#") { + return false + } + + if didUrl[0] == '#' { + return true + } + + did, _ := SplitDidUrlIntoDidAndFragment(didUrl) + return IsValidDid(prefix, did) +} + +func IsFullDidFragment(prefix string, didUrl string) bool { + if !strings.Contains(didUrl, "#") { + return false + } + + did, _ := SplitDidUrlIntoDidAndFragment(didUrl) + return IsValidDid(prefix, did) +} + +func ResolveId(did string, methodId string) string { + result := methodId + + methodDid, methodFragment := SplitDidUrlIntoDidAndFragment(methodId) + if len(methodDid) == 0 { + result = did + "#" + methodFragment + } + + return result +} + +func IsNotValidDIDArray(prefix string, array []string) (bool, int) { + for i, did := range array { + if !IsValidDid(prefix, did) { + return true, i + } + } + + return false, 0 +} + +func IsNotValidDIDArrayFragment(prefix string, array []string) (bool, int) { + for i, did := range array { + if !IsDidFragment(prefix, did) { + return true, i + } + } + + return false, 0 +} + +func IsValidDid(prefix string, did string) bool { + if len(did) == 0 { + return false + } + + if !DidForbiddenSymbolsRegexp.MatchString(did) { + return false + } + + return strings.HasPrefix(did, prefix) +} diff --git a/x/cheqd/utils/did_doc.go b/x/cheqd/utils/did_doc.go new file mode 100644 index 000000000..abf3e33d8 --- /dev/null +++ b/x/cheqd/utils/did_doc.go @@ -0,0 +1,26 @@ +package utils + +import "github.com/cheqd/cheqd-node/x/cheqd/utils/strings" + +const ( + PublicKeyJwk = "PublicKeyJwk" + PublicKeyMultibase = "PublicKeyMultibase" +) + +var VerificationMethodType = map[string]string{ + "JsonWebKey2020": PublicKeyJwk, + "Ed25519VerificationKey2020": PublicKeyMultibase, +} + +var ServiceType = []string{ + "LinkedDomains", + "DIDCommMessaging", +} + +func GetVerificationMethodType(vmType string) string { + return VerificationMethodType[vmType] +} + +func IsValidDidServiceType(sType string) bool { + return strings.Contains(ServiceType, sType) +} diff --git a/x/cheqd/utils/did_test.go b/x/cheqd/utils/did_test.go new file mode 100644 index 000000000..76d8bd56a --- /dev/null +++ b/x/cheqd/utils/did_test.go @@ -0,0 +1,36 @@ +package utils + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestIsDid(t *testing.T) { + cases := []struct { + valid bool + did string + }{ + {true, "did:cheqd:test:wyywywywyw"}, + {true, "did:cheqd:test:wyywywywyw:sdadasda"}, + {false, "did1:cheqd:test:wyywywywyw:sdadasda"}, + {false, "did:cheqd2:test:wyywywywyw:sdadasda"}, + {false, "did:cheqd:test4:wyywywywyw:sdadasda"}, + {false, ""}, + {false, "did:cheqd"}, + {false, "did:cheqd:test"}, + {false, "did:cheqd:test:dsdasdad#weqweqwew"}, + {false, "did:cheqd:test:sdasdasdasd/qeweqweqwee"}, + {false, "did:cheqd:test:sdasdasdasd?=qeweqweqwee"}, + {false, "did:cheqd:test:sdasdasdasd&qeweqweqwee"}, + } + + for _, tc := range cases { + isDid := IsValidDid("did:cheqd:test:", tc.did) + + if tc.valid { + require.True(t, isDid) + } else { + require.False(t, isDid) + } + } +} diff --git a/x/cheqd/utils/strings/array.go b/x/cheqd/utils/strings/array.go new file mode 100644 index 000000000..0b4ffeab3 --- /dev/null +++ b/x/cheqd/utils/strings/array.go @@ -0,0 +1,31 @@ +package strings + +func IndexOf(vs []string, t string) int { + for i, v := range vs { + if v == t { + return i + } + } + + return -1 +} + +func Contains(vs []string, t string) bool { + return IndexOf(vs, t) >= 0 +} + +func Filter(vs []string, f func(string) bool) []string { + vsf := make([]string, 0) + for _, v := range vs { + if f(v) { + vsf = append(vsf, v) + } + } + return vsf +} + +func Complement(vs []string, ts []string) []string { + return Filter(vs, func(s string) bool { + return !Contains(ts, s) + }) +} diff --git a/x/cheqd/utils/strings/arrays_test.go b/x/cheqd/utils/strings/arrays_test.go new file mode 100644 index 000000000..c8fe87b24 --- /dev/null +++ b/x/cheqd/utils/strings/arrays_test.go @@ -0,0 +1,29 @@ +package strings + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestComplement(t *testing.T) { + cases := []struct { + first []string + second []string + expected []string + }{ + {[]string{}, []string{}, []string{}}, + {nil, []string{}, []string{}}, + {nil, nil, []string{}}, + {[]string{"1", "2"}, []string{"1", "2"}, []string{}}, + {[]string{"1", "2", "3"}, []string{}, []string{"1", "2", "3"}}, + {[]string{"1", "2", "3"}, nil, []string{"1", "2", "3"}}, + {[]string{"1", "2", "3"}, []string{"4", "5", "6"}, []string{"1", "2", "3"}}, + {[]string{"1", "2", "3"}, []string{"1", "5", "2"}, []string{"3"}}, + {[]string{"4", "1", "6", "2", "3"}, []string{"1", "5", "2"}, []string{"4", "6", "3"}}, + } + + for _, tc := range cases { + actual := Complement(tc.first, tc.second) + require.Equal(t, tc.expected, actual) + } +}