diff --git a/app/app.go b/app/app.go index 70f2106a..6a346366 100644 --- a/app/app.go +++ b/app/app.go @@ -109,7 +109,7 @@ import ( minttypes "github.com/elesto-dao/elesto/v2/x/mint/types" ) -/// Global vars that define account prefix and name of chain +// Global vars that define account prefix and name of chain const ( AccountAddressPrefix = "elesto" Name = "elesto" diff --git a/app/export.go b/app/export.go index 7586684a..884aac63 100644 --- a/app/export.go +++ b/app/export.go @@ -51,7 +51,7 @@ func (app *App) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// in favor of export at a block height +// in favor of export at a block height func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/docs/README.md b/docs/README.md index 3292ee5c..ac6ec60c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,3 +1,4 @@ + # Elesto [![Go Reference](https://pkg.go.dev/badge/github.com/elesto-dao/elesto.svg)](https://pkg.go.dev/github.com/elesto-dao/elesto) diff --git a/go.mod b/go.mod index a3462fda..89c00659 100644 --- a/go.mod +++ b/go.mod @@ -19,10 +19,16 @@ require ( github.com/tendermint/starport v0.19.5 github.com/tendermint/tendermint v0.34.19 github.com/tendermint/tm-db v0.6.6 - github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f - google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd - google.golang.org/grpc v1.46.2 - google.golang.org/protobuf v1.28.0 + github.com/xeipuuv/gojsonschema v1.2.0 + google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc + google.golang.org/grpc v1.48.0 + google.golang.org/protobuf v1.28.1 +) + +require ( + github.com/ghodss/yaml v1.0.0 // indirect + github.com/golang/glog v1.0.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect ) require ( @@ -68,7 +74,7 @@ require ( github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect @@ -119,10 +125,10 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/zondax/hid v0.9.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect - golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 // indirect - golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect - golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect - golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect + golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect + golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect + golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect + golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.66.2 // indirect diff --git a/go.sum b/go.sum index d902f495..8f8b997e 100644 --- a/go.sum +++ b/go.sum @@ -838,8 +838,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqC github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -1599,8 +1599,9 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= -github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f h1:mvXjJIHRZyhNuGassLTcXTwjiWq7NmjdavZsUnmFybQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= @@ -1705,8 +1706,9 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 h1:3erb+vDS8lU1sxfDHF4/hhWyaXnhIaO+7RgL4fDZORA= golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1816,8 +1818,8 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1972,14 +1974,15 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= +golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= +golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -2233,8 +2236,8 @@ google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I= -google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= @@ -2252,8 +2255,8 @@ google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX7 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/proto/credential/v1/credential.proto b/proto/credential/v1/credential.proto index a70390f7..8867edeb 100644 --- a/proto/credential/v1/credential.proto +++ b/proto/credential/v1/credential.proto @@ -7,10 +7,6 @@ import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/struct.proto"; - - - - message CredentialDefinition { option (gogoproto.equal) = true; option (gogoproto.goproto_getters) = false; diff --git a/proto/credential/v1/genesis.proto b/proto/credential/v1/genesis.proto new file mode 100644 index 00000000..d4e7a175 --- /dev/null +++ b/proto/credential/v1/genesis.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package elestodao.elesto.credential.v1; + +import "gogoproto/gogo.proto"; +import "credential/v1/credential.proto"; + +option go_package = "github.com/elesto-dao/elesto/v2/x/credential"; + +message GenesisState{ + repeated CredentialDefinition credentialDefinitions = 1 [(gogoproto.nullable)=false]; + repeated PublicVerifiableCredential publicVerifiableCredentials = 2 [(gogoproto.nullable)=false]; +} \ No newline at end of file diff --git a/proto/credential/v1/query.proto b/proto/credential/v1/query.proto index d2aedf47..4a4dc68d 100644 --- a/proto/credential/v1/query.proto +++ b/proto/credential/v1/query.proto @@ -58,26 +58,33 @@ message QueryPublicCredentialResponse { } -message QueryPublicCredentialsRequest {} +message QueryPublicCredentialsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} message QueryPublicCredentialsResponse { repeated PublicVerifiableCredential credential = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2; } message QueryPublicCredentialsByHolderRequest { string did = 1; // holder DID + cosmos.base.query.v1beta1.PageRequest pagination = 2; } message QueryPublicCredentialsByHolderResponse { repeated PublicVerifiableCredential credential = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2; } message QueryPublicCredentialsByIssuerRequest { string did = 1; // issuer DID + cosmos.base.query.v1beta1.PageRequest pagination = 2; } message QueryPublicCredentialsByIssuerResponse { repeated PublicVerifiableCredential credential = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2; } message QueryCredentialDefinitionRequest { @@ -99,10 +106,12 @@ message QueryCredentialDefinitionsResponse { message QueryCredentialDefinitionsByPublisherRequest { string did = 1; // DID of the publisher + cosmos.base.query.v1beta1.PageRequest pagination = 2; } message QueryCredentialDefinitionsByPublisherResponse { repeated CredentialDefinition definitions = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/x/credential/client/cli/credential.go b/x/credential/client/cli/credential.go index d5b377f2..5252b35e 100644 --- a/x/credential/client/cli/credential.go +++ b/x/credential/client/cli/credential.go @@ -222,7 +222,6 @@ func NewMakeCredentialFromSchemaCmd() *cobra.Command { return cmd } -// func queryPublicCredential(qc credential.QueryClient, credentialID string) (wc *credential.WrappedCredential, err error) { // query the public credential result, err := qc.PublicCredential( diff --git a/x/credential/credential.go b/x/credential/credential.go index c087bd7a..9d7190a8 100644 --- a/x/credential/credential.go +++ b/x/credential/credential.go @@ -42,6 +42,7 @@ func NewCredentialDefinitionFromFile(id string, publisherDID did.DID, return def, nil } +// NewPublicVerifiableCredential creates a new Public Verifiable Credential func NewPublicVerifiableCredential(id string, opts ...PublicVerifiableCredentialOption) *PublicVerifiableCredential { pvc := &PublicVerifiableCredential{ Context: []string{"https://www.w3.org/2018/credentials/v1"}, diff --git a/x/credential/credential.pb.go b/x/credential/credential.pb.go index 5fea5c22..74805dfa 100644 --- a/x/credential/credential.pb.go +++ b/x/credential/credential.pb.go @@ -8,8 +8,8 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/structpb" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" diff --git a/x/credential/credential_test.go b/x/credential/credential_test.go index d411ee2f..f8fa2def 100644 --- a/x/credential/credential_test.go +++ b/x/credential/credential_test.go @@ -4,13 +4,14 @@ import ( _ "embed" "encoding/base64" "fmt" + "os" + "testing" + "time" + "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "os" - "testing" - "time" "github.com/stretchr/testify/assert" @@ -542,7 +543,6 @@ func TestWrappedCredential_Validate(t *testing.T) { wc.Proof = NewProof( pubKey.Type(), date.Format(time.RFC3339), - // TODO: define proof purposes did.AssertionMethod, issuerDID.NewVerificationMethodID(ki.GetAddress().String()), base64.StdEncoding.EncodeToString(signature), @@ -552,6 +552,42 @@ func TestWrappedCredential_Validate(t *testing.T) { }, assert.NoError, }, + { + "FAIL: invalid signature", + func() (*WrappedCredential, types.PubKey) { + // create the public key + kr := keyring.NewInMemory() + ki, err := kr.NewAccount( + "test1", + "coil animal waste sound canvas weekend struggle skirt donor boil around bounce grant right silent year subway boost banana unlock powder riot spawn nerve", + keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1, + ) + assert.NoError(t, err) + // get the issuer + issuerDID := did.NewChainDID("test", ki.GetAddress().String()) + // create the credential + wc, err := NewWrappedCredential(NewPublicVerifiableCredential("https://example.credential/01", WithType("SpecialCredential"), WithIssuerDID(issuerDID))) + wc.SetSubject(map[string]any{"id": "https://something.something"}) + // sign the credential + data, err := wc.GetBytes() + assert.NoError(t, err) + _, pubKey, err := kr.SignByAddress(ki.GetAddress(), data) + assert.NoError(t, err) + + // attach the proof + date := time.Date(2022, 02, 24, 0, 0, 0, 0, time.UTC) + wc.Proof = NewProof( + pubKey.Type(), + date.Format(time.RFC3339), + did.AssertionMethod, + issuerDID.NewVerificationMethodID(ki.GetAddress().String()), + base64.StdEncoding.EncodeToString([]byte("invalid signature")), + ) + assert.NoError(t, err) + return wc, ki.GetPubKey() + }, + assert.Error, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/credential/genesis.pb.go b/x/credential/genesis.pb.go new file mode 100644 index 00000000..0d996764 --- /dev/null +++ b/x/credential/genesis.pb.go @@ -0,0 +1,394 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: credential/v1/genesis.proto + +package credential + +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 GenesisState struct { + CredentialDefinitions []CredentialDefinition `protobuf:"bytes,1,rep,name=credentialDefinitions,proto3" json:"credentialDefinitions"` + PublicVerifiableCredentials []PublicVerifiableCredential `protobuf:"bytes,2,rep,name=publicVerifiableCredentials,proto3" json:"publicVerifiableCredentials"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_1b2ed9d58cb1a314, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetCredentialDefinitions() []CredentialDefinition { + if m != nil { + return m.CredentialDefinitions + } + return nil +} + +func (m *GenesisState) GetPublicVerifiableCredentials() []PublicVerifiableCredential { + if m != nil { + return m.PublicVerifiableCredentials + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "elestodao.elesto.credential.v1.GenesisState") +} + +func init() { proto.RegisterFile("credential/v1/genesis.proto", fileDescriptor_1b2ed9d58cb1a314) } + +var fileDescriptor_1b2ed9d58cb1a314 = []byte{ + // 250 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0x2e, 0x4a, 0x4d, + 0x49, 0xcd, 0x2b, 0xc9, 0x4c, 0xcc, 0xd1, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, + 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4b, 0xcd, 0x49, 0x2d, 0x2e, 0xc9, 0x4f, + 0x49, 0xcc, 0xd7, 0x83, 0xb0, 0xf4, 0x10, 0xaa, 0xf5, 0xca, 0x0c, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, + 0xf3, 0xc1, 0x4a, 0xf5, 0x41, 0x2c, 0x88, 0x2e, 0x29, 0x39, 0x54, 0x23, 0x91, 0xb4, 0x80, 0xe5, + 0x95, 0x5a, 0x99, 0xb8, 0x78, 0xdc, 0x21, 0xf6, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x15, 0x70, + 0x89, 0x22, 0x14, 0xb9, 0xa4, 0xa6, 0x65, 0xe6, 0x65, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0x4b, 0x30, + 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0x99, 0xe8, 0xe1, 0x77, 0x86, 0x9e, 0x33, 0x16, 0xcd, 0x4e, 0x2c, + 0x27, 0xee, 0xc9, 0x33, 0x04, 0x61, 0x37, 0x58, 0xa8, 0x89, 0x91, 0x4b, 0xba, 0xa0, 0x34, 0x29, + 0x27, 0x33, 0x39, 0x2c, 0xb5, 0x28, 0x33, 0x2d, 0x33, 0x31, 0x29, 0x27, 0x15, 0x61, 0x4a, 0xb1, + 0x04, 0x13, 0xd8, 0x62, 0x2b, 0x42, 0x16, 0x07, 0xe0, 0x34, 0x02, 0x6a, 0x3d, 0x3e, 0x4b, 0x9c, + 0xdc, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, + 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x27, 0x3d, 0xb3, 0x24, + 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0xb1, 0x6e, 0x4a, 0x62, 0x3e, 0x94, 0xa9, + 0x5f, 0x66, 0xa4, 0x5f, 0x81, 0x14, 0xaa, 0x49, 0x6c, 0xe0, 0x60, 0x35, 0x06, 0x04, 0x00, 0x00, + 0xff, 0xff, 0x60, 0xf0, 0x1a, 0xaf, 0xcb, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PublicVerifiableCredentials) > 0 { + for iNdEx := len(m.PublicVerifiableCredentials) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PublicVerifiableCredentials[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.CredentialDefinitions) > 0 { + for iNdEx := len(m.CredentialDefinitions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CredentialDefinitions[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 +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CredentialDefinitions) > 0 { + for _, e := range m.CredentialDefinitions { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.PublicVerifiableCredentials) > 0 { + for _, e := range m.PublicVerifiableCredentials { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + 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 CredentialDefinitions", 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.CredentialDefinitions = append(m.CredentialDefinitions, CredentialDefinition{}) + if err := m.CredentialDefinitions[len(m.CredentialDefinitions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicVerifiableCredentials", 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.PublicVerifiableCredentials = append(m.PublicVerifiableCredentials, PublicVerifiableCredential{}) + if err := m.PublicVerifiableCredentials[len(m.PublicVerifiableCredentials)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/credential/keeper/credential.go b/x/credential/keeper/credential.go index d8d8f1c0..844bc72d 100644 --- a/x/credential/keeper/credential.go +++ b/x/credential/keeper/credential.go @@ -11,13 +11,13 @@ import ( // SetCredentialDefinition persist a credential definition to the store. The credential definition ID is used as key. func (k Keeper) SetCredentialDefinition(ctx sdk.Context, def *credential.CredentialDefinition) { - k.Set(ctx, []byte(def.Id), credential.CredentialDefinitionKey, def, k.cdc.MustMarshal) + k.Set(ctx, credential.CredentialDefinitionKey, []byte(def.Id), def, k.cdc.MustMarshal) } // GetCredentialDefinition retrieve a credential definition by its key. // The boolean return will be false if the credential definition is not found func (k Keeper) GetCredentialDefinition(ctx sdk.Context, key string) (credential.CredentialDefinition, bool) { - val, found := k.Get(ctx, []byte(key), credential.CredentialDefinitionKey, func(value []byte) (interface{}, bool) { + val, found := k.Get(ctx, credential.CredentialDefinitionKey, []byte(key), func(value []byte) (interface{}, bool) { var data credential.CredentialDefinition ok := k.Unmarshal(value, &data) return data, ok @@ -40,13 +40,13 @@ func (k Keeper) GetCredentialDefinitions(ctx sdk.Context, req *credential.QueryC // SetPublicCredential persist a public verifiable credential to the store. The credential ID is used as key func (k Keeper) SetPublicCredential(ctx sdk.Context, pc *credential.PublicVerifiableCredential) { - k.Set(ctx, []byte(pc.Id), credential.PublicCredentialKey, pc, k.cdc.MustMarshal) + k.Set(ctx, credential.PublicCredentialKey, []byte(pc.Id), pc, k.cdc.MustMarshal) } // GetPublicCredential retrieve a public verifiable credential by its key. // The boolean return will be false if the credential is not found func (k Keeper) GetPublicCredential(ctx sdk.Context, key string) (credential.PublicVerifiableCredential, bool) { - val, found := k.Get(ctx, []byte(key), credential.PublicCredentialKey, func(value []byte) (interface{}, bool) { + val, found := k.Get(ctx, credential.PublicCredentialKey, []byte(key), func(value []byte) (interface{}, bool) { var data credential.PublicVerifiableCredential ok := k.Unmarshal(value, &data) return data, ok @@ -66,36 +66,34 @@ func (k Keeper) Unmarshal(data []byte, val codec.ProtoMarshaler) bool { } // GetCredentialDefinitionsWithFilter retrieve a list of credential definitions with filter -func (k Keeper) GetCredentialDefinitionsWithFilter(ctx sdk.Context, filter func(credentialDefinition *credential.CredentialDefinition) bool) []*credential.CredentialDefinition { - var cds []*credential.CredentialDefinition - - iterator := k.GetAll(ctx, credential.CredentialDefinitionKey) - defer iterator.Close() +func (k Keeper) GetCredentialDefinitionsWithFilter(ctx sdk.Context, paginate *query.PageRequest, filter func(credentialDefinition *credential.CredentialDefinition) bool) (cds []*credential.CredentialDefinition, pageRes *query.PageResponse, err error) { + store := ctx.KVStore(k.storeKey) + cdStore := prefix.NewStore(store, credential.CredentialDefinitionKey) - for ; iterator.Valid(); iterator.Next() { + pageRes, err = query.Paginate(cdStore, paginate, func(key []byte, value []byte) error { var cd credential.CredentialDefinition - k.cdc.MustUnmarshal(iterator.Value(), &cd) + k.cdc.MustUnmarshal(value, &cd) if filter(&cd) { cds = append(cds, &cd) } - } - return cds + return nil + }) + return } // GetPublicCredentialWithFilter retrieve a list of verifiable credentials // filtered by properties -func (k Keeper) GetPublicCredentialWithFilter(ctx sdk.Context, filter func(verifiableCredential *credential.PublicVerifiableCredential) bool) []*credential.PublicVerifiableCredential { - var pvcs []*credential.PublicVerifiableCredential - - iterator := k.GetAll(ctx, credential.PublicCredentialKey) - defer iterator.Close() +func (k Keeper) GetPublicCredentialWithFilter(ctx sdk.Context, pagination *query.PageRequest, filter func(verifiableCredential *credential.PublicVerifiableCredential) bool) (pvcs []*credential.PublicVerifiableCredential, pageRes *query.PageResponse, err error) { + store := ctx.KVStore(k.storeKey) + pcStore := prefix.NewStore(store, credential.PublicCredentialKey) - for ; iterator.Valid(); iterator.Next() { + pageRes, err = query.Paginate(pcStore, pagination, func(key []byte, value []byte) error { var pvc credential.PublicVerifiableCredential - k.cdc.MustUnmarshal(iterator.Value(), &pvc) + k.cdc.MustUnmarshal(value, &pvc) if filter(&pvc) { pvcs = append(pvcs, &pvc) } - } - return pvcs + return nil + }) + return } diff --git a/x/credential/keeper/genesis.go b/x/credential/keeper/genesis.go new file mode 100644 index 00000000..a9a5c8cd --- /dev/null +++ b/x/credential/keeper/genesis.go @@ -0,0 +1,50 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/elesto-dao/elesto/v2/x/credential" +) + +func InitGenesis(ctx sdk.Context, k Keeper, data *credential.GenesisState) { + for i := range data.CredentialDefinitions { + k.SetCredentialDefinition(ctx, &data.CredentialDefinitions[i]) + } + + for i := range data.PublicVerifiableCredentials { + k.SetPublicCredential(ctx, &data.PublicVerifiableCredentials[i]) + } +} + +func ExportGenesis(ctx sdk.Context, k Keeper) *credential.GenesisState { + var genState credential.GenesisState + cdsIterator := k.GetAll(ctx, credential.CredentialDefinitionKey) + defer cdsIterator.Close() + + for ; cdsIterator.Valid(); cdsIterator.Next() { + var cd credential.CredentialDefinition + ok := k.Unmarshal(cdsIterator.Value(), &cd) + if !ok { + panic(fmt.Errorf("cannot unmarshal %s", cdsIterator.Value())) + } + + genState.CredentialDefinitions = append(genState.CredentialDefinitions, cd) + } + + pvcIterator := k.GetAll(ctx, credential.PublicCredentialKey) + defer pvcIterator.Close() + + for ; pvcIterator.Valid(); pvcIterator.Next() { + var pvc credential.PublicVerifiableCredential + ok := k.Unmarshal(pvcIterator.Value(), &pvc) + if !ok { + panic(fmt.Errorf("cannot unmarshal %s", pvcIterator.Value())) + } + + genState.PublicVerifiableCredentials = append(genState.PublicVerifiableCredentials, pvc) + } + + return &genState +} diff --git a/x/credential/keeper/genesis_test.go b/x/credential/keeper/genesis_test.go new file mode 100644 index 00000000..a95a5f24 --- /dev/null +++ b/x/credential/keeper/genesis_test.go @@ -0,0 +1,61 @@ +package keeper_test + +import ( + "fmt" + + "github.com/elesto-dao/elesto/v2/x/credential" + "github.com/elesto-dao/elesto/v2/x/credential/keeper" + "github.com/elesto-dao/elesto/v2/x/did" +) + +func (s *KeeperTestSuite) TestGenesis() { + //default genesis on export + genState := keeper.ExportGenesis(s.ctx, s.keeper) + s.Require().Equal(genState, &credential.GenesisState{}) + + // add credential definitions and pvcs in genesis state + for i := 0; i < 5; i++ { + cD := credential.CredentialDefinition{ + Id: fmt.Sprintf("did:cosmos:elesto:cd-%v", i), + PublisherId: did.NewKeyDID(s.GetTestAccount().String()).String(), + Schema: []byte(dummyCredential), + Vocab: []byte(dummyVocabOk), + Name: "CredentialDef1", + Description: "", + IsPublic: true, + SupersededBy: "", + IsActive: true, + } + + // load the signed credential + wc, err := credential.NewWrappedPublicCredentialFromFile("testdata/dummy.credential.signed.json") + if err != nil { + s.Require().FailNowf("expected wrapped credential, got:", "%v", err) + } + + wc.PublicVerifiableCredential.Id = fmt.Sprintf("https://test.xyz/credential/%v", i) + genState.CredentialDefinitions = append(genState.CredentialDefinitions, cD) + genState.PublicVerifiableCredentials = append(genState.PublicVerifiableCredentials, *wc.PublicVerifiableCredential) + } + + // init genesis + keeper.InitGenesis(s.ctx, s.keeper, genState) + + // check credentials and pvcs in keeper + for i := 0; i < 5; i++ { + cd, found := s.keeper.GetCredentialDefinition(s.ctx, fmt.Sprintf("did:cosmos:elesto:cd-%v", i)) + s.Require().True(found) + s.Require().Equal(genState.CredentialDefinitions[i], cd) + + pvc, found := s.keeper.GetPublicCredential(s.ctx, fmt.Sprintf("https://test.xyz/credential/%v", i)) + s.Require().True(found) + s.Require().Equal(genState.PublicVerifiableCredentials[i], pvc) + } + + // check export genesis + newGenState := keeper.ExportGenesis(s.ctx, s.keeper) + s.Require().Len(newGenState.PublicVerifiableCredentials, 5) + s.Require().Len(newGenState.CredentialDefinitions, 5) + s.Require().Equal(newGenState.CredentialDefinitions, genState.CredentialDefinitions) + s.Require().Equal(newGenState.PublicVerifiableCredentials, genState.PublicVerifiableCredentials) +} diff --git a/x/credential/keeper/grpc_query.go b/x/credential/keeper/grpc_query.go index b7f9df57..540c87e9 100644 --- a/x/credential/keeper/grpc_query.go +++ b/x/credential/keeper/grpc_query.go @@ -13,6 +13,7 @@ import ( var _ credential.QueryServer = Keeper{} +// CredentialDefinition returns credential definition for an id func (k Keeper) CredentialDefinition( c context.Context, req *credential.QueryCredentialDefinitionRequest, @@ -32,6 +33,7 @@ func (k Keeper) CredentialDefinition( return &credential.QueryCredentialDefinitionResponse{Definition: &cd}, nil } +// CredentialDefinitionsByPublisher returns credential definitions for a particular publisher id func (k Keeper) CredentialDefinitionsByPublisher( c context.Context, req *credential.QueryCredentialDefinitionsByPublisherRequest, @@ -40,12 +42,13 @@ func (k Keeper) CredentialDefinitionsByPublisher( return nil, status.Error(codes.InvalidArgument, "publisher DID must be a valid DID") } ctx := sdk.UnwrapSDKContext(c) - cds := k.GetCredentialDefinitionsWithFilter(ctx, func(cd *credential.CredentialDefinition) bool { + cds, pr, err := k.GetCredentialDefinitionsWithFilter(ctx, req.Pagination, func(cd *credential.CredentialDefinition) bool { return cd.PublisherId == req.Did }) - return &credential.QueryCredentialDefinitionsByPublisherResponse{Definitions: cds}, nil + return &credential.QueryCredentialDefinitionsByPublisherResponse{Definitions: cds, Pagination: pr}, err } +// CredentialDefinitions returns all credential definitions func (k Keeper) CredentialDefinitions( c context.Context, req *credential.QueryCredentialDefinitionsRequest, @@ -55,6 +58,7 @@ func (k Keeper) CredentialDefinitions( return &credential.QueryCredentialDefinitionsResponse{Definitions: cd, Pagination: pr}, err } +// PublicCredential returns public credential for a particular id func (k Keeper) PublicCredential( c context.Context, req *credential.QueryPublicCredentialRequest, @@ -68,13 +72,14 @@ func (k Keeper) PublicCredential( } +// PublicCredentialsByHolder returns public credentials for particular holder func (k Keeper) PublicCredentialsByHolder( c context.Context, req *credential.QueryPublicCredentialsByHolderRequest, ) (*credential.QueryPublicCredentialsByHolderResponse, error) { ctx := sdk.UnwrapSDKContext(c) - pvcs := k.GetPublicCredentialWithFilter(ctx, func(vc *credential.PublicVerifiableCredential) bool { + pvcs, pr, err := k.GetPublicCredentialWithFilter(ctx, req.Pagination, func(vc *credential.PublicVerifiableCredential) bool { wc, err := credential.NewWrappedCredential(vc) if err != nil { return false @@ -86,27 +91,30 @@ func (k Keeper) PublicCredentialsByHolder( return subjectID == req.Did }) - return &credential.QueryPublicCredentialsByHolderResponse{Credential: pvcs}, nil + return &credential.QueryPublicCredentialsByHolderResponse{Credential: pvcs, Pagination: pr}, err } +// PublicCredentialsByIssuer returns public credentials for a particular issuer func (k Keeper) PublicCredentialsByIssuer( c context.Context, req *credential.QueryPublicCredentialsByIssuerRequest, ) (*credential.QueryPublicCredentialsByIssuerResponse, error) { ctx := sdk.UnwrapSDKContext(c) - pvcs := k.GetPublicCredentialWithFilter(ctx, func(vc *credential.PublicVerifiableCredential) bool { + pvcs, pr, err := k.GetPublicCredentialWithFilter(ctx, req.Pagination, func(vc *credential.PublicVerifiableCredential) bool { return vc.Issuer == req.Did }) - return &credential.QueryPublicCredentialsByIssuerResponse{Credential: pvcs}, nil + return &credential.QueryPublicCredentialsByIssuerResponse{Credential: pvcs, Pagination: pr}, err } +// PublicCredentials returns all public credentials func (k Keeper) PublicCredentials( c context.Context, req *credential.QueryPublicCredentialsRequest, ) (*credential.QueryPublicCredentialsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - pvcs := k.GetPublicCredentialWithFilter(ctx, func(vc *credential.PublicVerifiableCredential) bool { + pvcs, pr, err := k.GetPublicCredentialWithFilter(ctx, req.Pagination, func(vc *credential.PublicVerifiableCredential) bool { return true }) - return &credential.QueryPublicCredentialsResponse{Credential: pvcs}, nil + + return &credential.QueryPublicCredentialsResponse{Credential: pvcs, Pagination: pr}, err } diff --git a/x/credential/keeper/grpc_query_test.go b/x/credential/keeper/grpc_query_test.go index 6749bd6a..e1fc6216 100644 --- a/x/credential/keeper/grpc_query_test.go +++ b/x/credential/keeper/grpc_query_test.go @@ -1,19 +1,21 @@ -package keeper +package keeper_test import ( "context" "errors" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/elesto-dao/elesto/v2/x/credential" + "github.com/elesto-dao/elesto/v2/x/credential/keeper" "github.com/elesto-dao/elesto/v2/x/did" ) func (suite *KeeperTestSuite) TestKeeper_CredentialDefinition() { queryClient := suite.queryClient - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { msg string @@ -78,7 +80,7 @@ func (suite *KeeperTestSuite) TestKeeper_CredentialDefinition() { func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitionsByPublisher() { queryClient := suite.queryClient - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { msg string @@ -130,6 +132,7 @@ func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitionsByPublisher() { Definitions: []*credential.CredentialDefinition{ pcdr.CredentialDefinition, }, + Pagination: &query.PageResponse{Total: 2}, } }, nil, @@ -137,7 +140,7 @@ func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitionsByPublisher() { { "FAIL: credential definition not found", func() (*credential.QueryCredentialDefinitionsByPublisherRequest, *credential.QueryCredentialDefinitionsByPublisherResponse) { - return &credential.QueryCredentialDefinitionsByPublisherRequest{Did: "did:cosmos:elesto:cd-not-found"}, &credential.QueryCredentialDefinitionsByPublisherResponse{Definitions: nil} + return &credential.QueryCredentialDefinitionsByPublisherRequest{Did: "did:cosmos:elesto:cd-not-found"}, &credential.QueryCredentialDefinitionsByPublisherResponse{Definitions: nil, Pagination: &query.PageResponse{Total: 2}} }, nil, }, @@ -166,7 +169,7 @@ func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitionsByPublisher() { func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitions() { queryClient := suite.queryClient - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { msg string @@ -230,7 +233,7 @@ func (suite *KeeperTestSuite) TestKeeper_CredentialDefinitions() { func (suite *KeeperTestSuite) TestKeeper_PublicCredential() { queryClient := suite.queryClient - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { msg string @@ -245,7 +248,6 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredential() { wc *credential.WrappedCredential err error ) - // // publish the definition pcdr := credential.MsgPublishCredentialDefinitionRequest{ @@ -282,7 +284,7 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredential() { nil, }, { - "PASS: can get the credential", + "FAIL: credential not found", func() (*credential.QueryPublicCredentialRequest, *credential.QueryPublicCredentialResponse) { return &credential.QueryPublicCredentialRequest{Id: "https://does.not.exists"}, &credential.QueryPublicCredentialResponse{Credential: nil} }, @@ -306,7 +308,7 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredential() { func (suite *KeeperTestSuite) TestKeeper_PublicCredentials() { queryClient := suite.queryClient - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) _ = server testCases := []struct { @@ -317,7 +319,7 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredentials() { { "PASS: no credentials", func() (*credential.QueryPublicCredentialsRequest, *credential.QueryPublicCredentialsResponse) { - return &credential.QueryPublicCredentialsRequest{}, &credential.QueryPublicCredentialsResponse{Credential: nil} + return &credential.QueryPublicCredentialsRequest{}, &credential.QueryPublicCredentialsResponse{Credential: nil, Pagination: &query.PageResponse{}} }, nil, }, @@ -329,7 +331,6 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredentials() { wc *credential.WrappedCredential err error ) - // // publish the definition pcdr := credential.MsgPublishCredentialDefinitionRequest{ @@ -361,7 +362,7 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredentials() { }) suite.Require().NoError(err) - return &credential.QueryPublicCredentialsRequest{}, &credential.QueryPublicCredentialsResponse{Credential: []*credential.PublicVerifiableCredential{wc.PublicVerifiableCredential}} + return &credential.QueryPublicCredentialsRequest{}, &credential.QueryPublicCredentialsResponse{Credential: []*credential.PublicVerifiableCredential{wc.PublicVerifiableCredential}, Pagination: &query.PageResponse{Total: 1}} }, nil, }, @@ -380,3 +381,155 @@ func (suite *KeeperTestSuite) TestKeeper_PublicCredentials() { }) } } + +func (suite *KeeperTestSuite) TestKeeper_PublicCredentialsByHolder() { + queryClient := suite.queryClient + server := keeper.NewMsgServerImpl(suite.keeper) + _ = server + + testCases := []struct { + msg string + reqFn func() (*credential.QueryPublicCredentialsByHolderRequest, *credential.QueryPublicCredentialsByHolderResponse) + wantErr error + }{ + { + "PASS: no credentials", + func() (*credential.QueryPublicCredentialsByHolderRequest, *credential.QueryPublicCredentialsByHolderResponse) { + return &credential.QueryPublicCredentialsByHolderRequest{Did: did.NewKeyDID(suite.GetTestAccount().String()).String()}, &credential.QueryPublicCredentialsByHolderResponse{Credential: nil, Pagination: &query.PageResponse{}} + }, + nil, + }, + { + "PASS: can get the credential", + func() (*credential.QueryPublicCredentialsByHolderRequest, *credential.QueryPublicCredentialsByHolderResponse) { + var ( + id = "001" + wc *credential.WrappedCredential + err error + ) + + // publish the definition + pcdr := credential.MsgPublishCredentialDefinitionRequest{ + CredentialDefinition: &credential.CredentialDefinition{ + Id: "did:cosmos:elesto:ipcq-" + id, + PublisherId: did.NewKeyDID(suite.GetTestAccount().String()).String(), + Schema: []byte(dummySchemaOk), + Vocab: []byte(dummyVocabOk), + Name: "CredentialDef" + id, + Description: "", + IsPublic: true, + SupersededBy: "", + IsActive: true, + }, + Signer: suite.GetTestAccount().String(), + } + //create the credential definition + _, err = server.PublishCredentialDefinition(sdk.WrapSDKContext(suite.ctx), &pcdr) + suite.Require().NoError(err) + // load the signed credential + if wc, err = credential.NewWrappedPublicCredentialFromFile("testdata/dummy.credential.signed.json"); err != nil { + suite.Require().FailNowf("expected wrapped credential, got:", "%v", err) + } + // publish the credential + _, err = server.IssuePublicVerifiableCredential(sdk.WrapSDKContext(suite.ctx), &credential.MsgIssuePublicVerifiableCredentialRequest{ + CredentialDefinitionID: "did:cosmos:elesto:ipcq-" + id, + Credential: wc.PublicVerifiableCredential, + Signer: suite.GetTestAccount().String(), + }) + suite.Require().NoError(err) + + return &credential.QueryPublicCredentialsByHolderRequest{Did: did.NewKeyDID(suite.GetTestAccount().String()).String()}, &credential.QueryPublicCredentialsByHolderResponse{Credential: []*credential.PublicVerifiableCredential{wc.PublicVerifiableCredential}, Pagination: &query.PageResponse{Total: 1}} + }, + nil, + }, + } + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + req, expectedResp := tc.reqFn() + gotResp, err := queryClient.PublicCredentialsByHolder(context.Background(), req) + if tc.wantErr == nil { + suite.Require().NoError(err) + suite.Require().Equal(expectedResp, gotResp) + } else { + suite.Require().Error(err) + suite.Require().Equal(tc.wantErr.Error(), err.Error()) + } + }) + } +} + +func (suite *KeeperTestSuite) TestKeeper_PublicCredentialsByIssuer() { + queryClient := suite.queryClient + server := keeper.NewMsgServerImpl(suite.keeper) + _ = server + + testCases := []struct { + msg string + reqFn func() (*credential.QueryPublicCredentialsByIssuerRequest, *credential.QueryPublicCredentialsByIssuerResponse) + wantErr error + }{ + { + "PASS: no credentials", + func() (*credential.QueryPublicCredentialsByIssuerRequest, *credential.QueryPublicCredentialsByIssuerResponse) { + return &credential.QueryPublicCredentialsByIssuerRequest{Did: did.NewKeyDID(suite.GetTestAccount().String()).String()}, &credential.QueryPublicCredentialsByIssuerResponse{Credential: nil, Pagination: &query.PageResponse{}} + }, + nil, + }, + { + "PASS: can get the credential", + func() (*credential.QueryPublicCredentialsByIssuerRequest, *credential.QueryPublicCredentialsByIssuerResponse) { + var ( + id = "001" + wc *credential.WrappedCredential + err error + ) + + // publish the definition + pcdr := credential.MsgPublishCredentialDefinitionRequest{ + CredentialDefinition: &credential.CredentialDefinition{ + Id: "did:cosmos:elesto:ipcq-" + id, + PublisherId: did.NewKeyDID(suite.GetTestAccount().String()).String(), + Schema: []byte(dummySchemaOk), + Vocab: []byte(dummyVocabOk), + Name: "CredentialDef" + id, + Description: "", + IsPublic: true, + SupersededBy: "", + IsActive: true, + }, + Signer: suite.GetTestAccount().String(), + } + //create the credential definition + _, err = server.PublishCredentialDefinition(sdk.WrapSDKContext(suite.ctx), &pcdr) + suite.Require().NoError(err) + // load the signed credential + if wc, err = credential.NewWrappedPublicCredentialFromFile("testdata/dummy.credential.signed.json"); err != nil { + suite.Require().FailNowf("expected wrapped credential, got:", "%v", err) + } + // publish the credential + _, err = server.IssuePublicVerifiableCredential(sdk.WrapSDKContext(suite.ctx), &credential.MsgIssuePublicVerifiableCredentialRequest{ + CredentialDefinitionID: "did:cosmos:elesto:ipcq-" + id, + Credential: wc.PublicVerifiableCredential, + Signer: suite.GetTestAccount().String(), + }) + suite.Require().NoError(err) + + return &credential.QueryPublicCredentialsByIssuerRequest{Did: did.NewKeyDID(suite.GetTestAccount().String()).String()}, &credential.QueryPublicCredentialsByIssuerResponse{Credential: []*credential.PublicVerifiableCredential{wc.PublicVerifiableCredential}, Pagination: &query.PageResponse{Total: 1}} + }, + nil, + }, + } + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + req, expectedResp := tc.reqFn() + gotResp, err := queryClient.PublicCredentialsByIssuer(context.Background(), req) + if tc.wantErr == nil { + suite.Require().NoError(err) + suite.Require().Equal(expectedResp, gotResp) + } else { + suite.Require().Error(err) + suite.Require().Equal(tc.wantErr.Error(), err.Error()) + } + }) + } +} diff --git a/x/credential/keeper/keeper.go b/x/credential/keeper/keeper.go index b1381700..5c17f0ce 100644 --- a/x/credential/keeper/keeper.go +++ b/x/credential/keeper/keeper.go @@ -40,8 +40,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // Set sets a value in the db with a prefixed key func (k Keeper) Set(ctx sdk.Context, - key []byte, prefix []byte, + key []byte, i codec.ProtoMarshaler, marshal MarshalFn, ) { @@ -52,8 +52,8 @@ func (k Keeper) Set(ctx sdk.Context, // Get gets an item from the store by bytes func (k Keeper) Get( ctx sdk.Context, - key []byte, prefix []byte, + key []byte, unmarshal UnmarshalFn, ) (i interface{}, found bool) { store := ctx.KVStore(k.storeKey) diff --git a/x/credential/keeper/keeper_test.go b/x/credential/keeper/keeper_test.go index 0e6be431..ce63ce9e 100644 --- a/x/credential/keeper/keeper_test.go +++ b/x/credential/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package keeper +package keeper_test import ( "fmt" @@ -11,20 +11,22 @@ import ( cryptocdc "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - server "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/elesto-dao/elesto/v2/x/credential" - "github.com/elesto-dao/elesto/v2/x/did" - didkeeper "github.com/elesto-dao/elesto/v2/x/did/keeper" "github.com/rs/zerolog/log" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + + "github.com/elesto-dao/elesto/v2/x/credential" + "github.com/elesto-dao/elesto/v2/x/credential/keeper" + "github.com/elesto-dao/elesto/v2/x/did" + didkeeper "github.com/elesto-dao/elesto/v2/x/did/keeper" ) // Keeper test suit enables the keeper package to be tested @@ -32,7 +34,7 @@ type KeeperTestSuite struct { suite.Suite ctx sdk.Context - keeper Keeper + keeper keeper.Keeper queryClient credential.QueryClient keyring keyring.Keyring } @@ -94,7 +96,7 @@ func (suite *KeeperTestSuite) SetupTest() { memKeyDidDocument, ) - credentialKeeper := NewKeeper( + credentialKeeper := keeper.NewKeeper( marshaler, keyCreden, memKeyCreden, diff --git a/x/credential/keeper/msg_server.go b/x/credential/keeper/msg_server.go index 65804620..2ff8c15b 100644 --- a/x/credential/keeper/msg_server.go +++ b/x/credential/keeper/msg_server.go @@ -24,6 +24,7 @@ func NewMsgServerImpl(keeper Keeper) credential.MsgServer { var _ credential.MsgServer = msgServer{} +// PublishCredentialDefinition credential for publishing new credential definition func (k msgServer) PublishCredentialDefinition( goCtx context.Context, msg *credential.MsgPublishCredentialDefinitionRequest, @@ -65,6 +66,7 @@ func (k msgServer) PublishCredentialDefinition( return &credential.MsgPublishCredentialDefinitionResponse{}, nil } +// UpdateCredentialDefinition updates an existing credential definition func (k msgServer) UpdateCredentialDefinition( goCtx context.Context, msg *credential.MsgUpdateCredentialDefinitionRequest, @@ -95,7 +97,7 @@ func (k msgServer) UpdateCredentialDefinition( // update the SupersededBy field cd.SupersededBy = msg.SupersededBy - // update he data + // update the data k.SetCredentialDefinition(ctx, &cd) // emit the event @@ -105,6 +107,7 @@ func (k msgServer) UpdateCredentialDefinition( return &credential.MsgUpdateCredentialDefinitionResponse{}, nil } +// IssuePublicVerifiableCredential issues a new public verifiable credential func (k msgServer) IssuePublicVerifiableCredential( goCtx context.Context, msg *credential.MsgIssuePublicVerifiableCredentialRequest, diff --git a/x/credential/keeper/msg_server_test.go b/x/credential/keeper/msg_server_test.go index 63d60a36..4da304e1 100644 --- a/x/credential/keeper/msg_server_test.go +++ b/x/credential/keeper/msg_server_test.go @@ -1,4 +1,4 @@ -package keeper +package keeper_test import ( "context" @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elesto-dao/elesto/v2/x/credential" + "github.com/elesto-dao/elesto/v2/x/credential/keeper" "github.com/elesto-dao/elesto/v2/x/did" ) @@ -30,7 +31,7 @@ var ( func (suite *KeeperTestSuite) TestHandleMsgPublishCredentialDefinition() { - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { name string @@ -120,6 +121,8 @@ func (suite *KeeperTestSuite) TestHandleMsgPublishCredentialDefinition() { for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.name), func() { req := tc.reqFn() + req.ValidateBasic() + _, err := server.PublishCredentialDefinition(sdk.WrapSDKContext(suite.ctx), &req) if tc.wantErr == nil { suite.Require().NoError(err) @@ -133,7 +136,7 @@ func (suite *KeeperTestSuite) TestHandleMsgPublishCredentialDefinition() { func (suite *KeeperTestSuite) TestHandleMsgUpdateCredentialDefinition() { - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) query := suite.queryClient testCases := []struct { @@ -290,7 +293,7 @@ func (suite *KeeperTestSuite) TestHandleMsgUpdateCredentialDefinition() { func (suite *KeeperTestSuite) TestHandleMsgIssuePublicCredential() { - server := NewMsgServerImpl(suite.keeper) + server := keeper.NewMsgServerImpl(suite.keeper) testCases := []struct { name string @@ -640,7 +643,7 @@ func (suite *KeeperTestSuite) TestHandleMsgIssuePublicCredential() { Signer: suite.GetTestAccount().String(), } }, - fmt.Errorf("schema: did:cosmos:elesto:cd-17, errors: [@context: @context is required type: type is required issuer: issuer is required issuanceDate: issuanceDate is required id: id is required]: the credential doesn't match the definition schema"), + fmt.Errorf("schema: did:cosmos:elesto:cd-17, errors: [(root): @context is required (root): type is required (root): issuer is required (root): issuanceDate is required credentialSubject: id is required]: the credential doesn't match the definition schema"), }, } for _, tc := range testCases { diff --git a/x/credential/module/module.go b/x/credential/module/module.go index 966f1738..3da65ca1 100644 --- a/x/credential/module/module.go +++ b/x/credential/module/module.go @@ -5,8 +5,6 @@ import ( // this line is used by starport scaffolding # 1 "encoding/json" "math/rand" - "github.com/elesto-dao/elesto/v2/x/credential" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -18,6 +16,7 @@ import ( // this line is used by starport scaffolding # 1 "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/elesto-dao/elesto/v2/x/credential" "github.com/elesto-dao/elesto/v2/x/credential/client/cli" "github.com/elesto-dao/elesto/v2/x/credential/keeper" ) @@ -150,8 +149,8 @@ func (AppModule) InitGenesis( } // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. -func (AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return nil +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(keeper.ExportGenesis(ctx, am.keeper)) } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. diff --git a/x/credential/msg_validation_test.go b/x/credential/msg_validation_test.go index 55367c29..4af55652 100644 --- a/x/credential/msg_validation_test.go +++ b/x/credential/msg_validation_test.go @@ -177,7 +177,7 @@ func TestMsgUpdateCredentialDefinitionRequest_ValidateBasic(t *testing.T) { nil, }, { - "PASS: SupersededBy is not valid DID ", + "FAIL: SupersededBy is not valid DID ", fields{ Active: true, SupersededBy: "not a did", @@ -239,7 +239,7 @@ func TestMsgIssuePublicVerifiableCredentialRequest_ValidateBasic(t *testing.T) { nil, }, { - "FAIL: empty CredentialDefinitionID", + "FAIL: invalid CredentialDefinitionID", fields{ Credential: &PublicVerifiableCredential{ Id: "https://test.xyz/credential/1", @@ -261,7 +261,7 @@ func TestMsgIssuePublicVerifiableCredentialRequest_ValidateBasic(t *testing.T) { errors.New("credential definition DID must be set"), }, { - "FAIL: empty CredentialDefinitionID", + "FAIL: invalid CredentialDefinitionID", fields{ Credential: &PublicVerifiableCredential{ Id: "https://test.xyz/credential/1", diff --git a/x/credential/query.pb.go b/x/credential/query.pb.go index 8c2adfe5..cfffeabd 100644 --- a/x/credential/query.pb.go +++ b/x/credential/query.pb.go @@ -118,6 +118,7 @@ func (m *QueryPublicCredentialResponse) GetCredential() *PublicVerifiableCredent } type QueryPublicCredentialsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsRequest) Reset() { *m = QueryPublicCredentialsRequest{} } @@ -153,8 +154,16 @@ func (m *QueryPublicCredentialsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryPublicCredentialsRequest proto.InternalMessageInfo +func (m *QueryPublicCredentialsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + type QueryPublicCredentialsResponse struct { Credential []*PublicVerifiableCredential `protobuf:"bytes,1,rep,name=credential,proto3" json:"credential,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsResponse) Reset() { *m = QueryPublicCredentialsResponse{} } @@ -197,8 +206,16 @@ func (m *QueryPublicCredentialsResponse) GetCredential() []*PublicVerifiableCred return nil } +func (m *QueryPublicCredentialsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + type QueryPublicCredentialsByHolderRequest struct { - Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsByHolderRequest) Reset() { *m = QueryPublicCredentialsByHolderRequest{} } @@ -241,8 +258,16 @@ func (m *QueryPublicCredentialsByHolderRequest) GetDid() string { return "" } +func (m *QueryPublicCredentialsByHolderRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + type QueryPublicCredentialsByHolderResponse struct { Credential []*PublicVerifiableCredential `protobuf:"bytes,1,rep,name=credential,proto3" json:"credential,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsByHolderResponse) Reset() { @@ -287,8 +312,16 @@ func (m *QueryPublicCredentialsByHolderResponse) GetCredential() []*PublicVerifi return nil } +func (m *QueryPublicCredentialsByHolderResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + type QueryPublicCredentialsByIssuerRequest struct { - Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsByIssuerRequest) Reset() { *m = QueryPublicCredentialsByIssuerRequest{} } @@ -331,8 +364,16 @@ func (m *QueryPublicCredentialsByIssuerRequest) GetDid() string { return "" } +func (m *QueryPublicCredentialsByIssuerRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + type QueryPublicCredentialsByIssuerResponse struct { Credential []*PublicVerifiableCredential `protobuf:"bytes,1,rep,name=credential,proto3" json:"credential,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryPublicCredentialsByIssuerResponse) Reset() { @@ -377,6 +418,13 @@ func (m *QueryPublicCredentialsByIssuerResponse) GetCredential() []*PublicVerifi return nil } +func (m *QueryPublicCredentialsByIssuerResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + type QueryCredentialDefinitionRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } @@ -562,7 +610,8 @@ func (m *QueryCredentialDefinitionsResponse) GetPagination() *query.PageResponse } type QueryCredentialDefinitionsByPublisherRequest struct { - Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Did string `protobuf:"bytes,1,opt,name=did,proto3" json:"did,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryCredentialDefinitionsByPublisherRequest) Reset() { @@ -609,8 +658,16 @@ func (m *QueryCredentialDefinitionsByPublisherRequest) GetDid() string { return "" } +func (m *QueryCredentialDefinitionsByPublisherRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + type QueryCredentialDefinitionsByPublisherResponse struct { Definitions []*CredentialDefinition `protobuf:"bytes,1,rep,name=definitions,proto3" json:"definitions,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryCredentialDefinitionsByPublisherResponse) Reset() { @@ -657,6 +714,13 @@ func (m *QueryCredentialDefinitionsByPublisherResponse) GetDefinitions() []*Cred return nil } +func (m *QueryCredentialDefinitionsByPublisherResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + func init() { proto.RegisterType((*QueryPublicCredentialRequest)(nil), "elestodao.elesto.credential.v1.QueryPublicCredentialRequest") proto.RegisterType((*QueryPublicCredentialResponse)(nil), "elestodao.elesto.credential.v1.QueryPublicCredentialResponse") @@ -677,52 +741,52 @@ func init() { func init() { proto.RegisterFile("credential/v1/query.proto", fileDescriptor_fac323b79b6e0b88) } var fileDescriptor_fac323b79b6e0b88 = []byte{ - // 706 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x96, 0x5f, 0x6b, 0x13, 0x4d, - 0x14, 0xc6, 0x3b, 0x29, 0xef, 0x0b, 0x9e, 0x82, 0xd4, 0xd1, 0x42, 0xbb, 0xd6, 0x6d, 0xba, 0x68, - 0x5b, 0xa4, 0x9d, 0x21, 0x51, 0x10, 0x45, 0xa5, 0x46, 0xad, 0x0a, 0x0a, 0xb5, 0x48, 0x2f, 0x7a, - 0xb7, 0xc9, 0x4e, 0xd3, 0xc1, 0x74, 0x27, 0xcd, 0x6c, 0x82, 0xa5, 0x7a, 0x23, 0x82, 0xb7, 0x82, - 0x5f, 0x43, 0x10, 0x3f, 0x84, 0xa8, 0x77, 0x05, 0xbd, 0xf0, 0x52, 0x5a, 0x3f, 0x84, 0x97, 0x92, - 0x99, 0x49, 0xb2, 0x69, 0xf7, 0x4f, 0xd9, 0x54, 0xbd, 0x5b, 0xb2, 0xe7, 0x3c, 0xe7, 0xf9, 0xcd, - 0x9c, 0x73, 0x36, 0x30, 0x51, 0x69, 0x30, 0x8f, 0xf9, 0x01, 0x77, 0x6b, 0xb4, 0x55, 0xa0, 0x5b,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, 0x0f, 0x7d, 0xdf, 0xb7, 0x87, 0xd6, 0xe6, 0xab, 0x3c, 0xd8, 0x68, 0x96, 0x49, - 0x45, 0x6c, 0x1a, 0xd1, 0x05, 0xcf, 0x15, 0x1d, 0xfd, 0x56, 0x91, 0x3e, 0x0b, 0x15, 0x29, 0xff, - 0xaf, 0xfe, 0x7d, 0x5f, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x7b, 0xac, 0xb3, 0x42, 0x24, 0x0c, - 0x00, 0x00, + // 719 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x97, 0x5f, 0x6b, 0x13, 0x4d, + 0x14, 0xc6, 0x3b, 0x29, 0xef, 0x0b, 0x9e, 0x82, 0xd4, 0xd1, 0x42, 0xbb, 0xd6, 0x35, 0x5d, 0xb4, + 0x2d, 0xd2, 0xce, 0x90, 0x28, 0x08, 0xa2, 0xa2, 0x51, 0xab, 0x82, 0x42, 0x2d, 0xd2, 0x8b, 0xde, + 0x6d, 0xb2, 0xd3, 0x74, 0x30, 0xdd, 0x49, 0x33, 0x9b, 0x60, 0x29, 0x5e, 0xe8, 0x95, 0x97, 0x82, + 0x5f, 0x43, 0x10, 0x3f, 0x84, 0xa8, 0x17, 0x42, 0x41, 0x2f, 0xbc, 0x94, 0xd6, 0x0f, 0xe1, 0xa5, + 0x64, 0x66, 0x92, 0x6c, 0xda, 0xfd, 0x53, 0xb6, 0x51, 0xa9, 0x77, 0xa1, 0x3b, 0xe7, 0x39, 0xcf, + 0xef, 0x9c, 0x9d, 0x73, 0xb6, 0x30, 0x51, 0x69, 0x30, 0x8f, 0xf9, 0x01, 0x77, 0x6b, 0xb4, 0x55, + 0xa0, 0x1b, 0x4d, 0xd6, 0xd8, 0x24, 0xf5, 0x86, 0x08, 0x04, 0xb6, 0x59, 0x8d, 0xc9, 0x40, 0x78, + 0xae, 0x20, 0xfa, 0x17, 0xe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c1, 0x5a, 0xb3, 0x4c, 0x2a, 0x62, 0xdd, 0x88, + 0xce, 0x7b, 0xae, 0xe8, 0xe8, 0xb7, 0x8a, 0xf4, 0x69, 0x28, 0x49, 0xf9, 0x7f, 0xf5, 0x5f, 0xdc, + 0xc5, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x11, 0x3d, 0x06, 0x6e, 0x6c, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1118,6 +1182,18 @@ func (m *QueryPublicCredentialsRequest) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -1141,6 +1217,18 @@ func (m *QueryPublicCredentialsResponse) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Credential) > 0 { for iNdEx := len(m.Credential) - 1; iNdEx >= 0; iNdEx-- { { @@ -1178,6 +1266,18 @@ func (m *QueryPublicCredentialsByHolderRequest) MarshalToSizedBuffer(dAtA []byte _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Did) > 0 { i -= len(m.Did) copy(dAtA[i:], m.Did) @@ -1208,6 +1308,18 @@ func (m *QueryPublicCredentialsByHolderResponse) MarshalToSizedBuffer(dAtA []byt _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Credential) > 0 { for iNdEx := len(m.Credential) - 1; iNdEx >= 0; iNdEx-- { { @@ -1245,6 +1357,18 @@ func (m *QueryPublicCredentialsByIssuerRequest) MarshalToSizedBuffer(dAtA []byte _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Did) > 0 { i -= len(m.Did) copy(dAtA[i:], m.Did) @@ -1275,6 +1399,18 @@ func (m *QueryPublicCredentialsByIssuerResponse) MarshalToSizedBuffer(dAtA []byt _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Credential) > 0 { for iNdEx := len(m.Credential) - 1; iNdEx >= 0; iNdEx-- { { @@ -1461,6 +1597,18 @@ func (m *QueryCredentialDefinitionsByPublisherRequest) MarshalToSizedBuffer(dAtA _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Did) > 0 { i -= len(m.Did) copy(dAtA[i:], m.Did) @@ -1491,6 +1639,18 @@ func (m *QueryCredentialDefinitionsByPublisherResponse) MarshalToSizedBuffer(dAt _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Definitions) > 0 { for iNdEx := len(m.Definitions) - 1; iNdEx >= 0; iNdEx-- { { @@ -1551,6 +1711,10 @@ func (m *QueryPublicCredentialsRequest) Size() (n int) { } var l int _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1566,6 +1730,10 @@ func (m *QueryPublicCredentialsResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1579,6 +1747,10 @@ func (m *QueryPublicCredentialsByHolderRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1594,6 +1766,10 @@ func (m *QueryPublicCredentialsByHolderResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1607,6 +1783,10 @@ func (m *QueryPublicCredentialsByIssuerRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1622,6 +1802,10 @@ func (m *QueryPublicCredentialsByIssuerResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1693,6 +1877,10 @@ func (m *QueryCredentialDefinitionsByPublisherRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1708,6 +1896,10 @@ func (m *QueryCredentialDefinitionsByPublisherResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1914,6 +2106,42 @@ func (m *QueryPublicCredentialsRequest) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: QueryPublicCredentialsRequest: 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) + } + 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.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:]) @@ -1998,6 +2226,42 @@ func (m *QueryPublicCredentialsResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -2080,6 +2344,42 @@ func (m *QueryPublicCredentialsByHolderRequest) Unmarshal(dAtA []byte) error { } m.Did = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.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:]) @@ -2164,6 +2464,42 @@ func (m *QueryPublicCredentialsByHolderResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -2246,6 +2582,42 @@ func (m *QueryPublicCredentialsByIssuerRequest) Unmarshal(dAtA []byte) error { } m.Did = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.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:]) @@ -2330,6 +2702,42 @@ func (m *QueryPublicCredentialsByIssuerResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -2786,6 +3194,42 @@ func (m *QueryCredentialDefinitionsByPublisherRequest) Unmarshal(dAtA []byte) er } m.Did = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.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:]) @@ -2870,6 +3314,42 @@ func (m *QueryCredentialDefinitionsByPublisherResponse) Unmarshal(dAtA []byte) e return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/credential/query.pb.gw.go b/x/credential/query.pb.gw.go index d7b929cd..4fa86f10 100644 --- a/x/credential/query.pb.gw.go +++ b/x/credential/query.pb.gw.go @@ -87,10 +87,21 @@ func local_request_Query_PublicCredential_0(ctx context.Context, marshaler runti } +var ( + filter_Query_PublicCredentials_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + func request_Query_PublicCredentials_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryPublicCredentialsRequest 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_PublicCredentials_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.PublicCredentials(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -100,11 +111,22 @@ func local_request_Query_PublicCredentials_0(ctx context.Context, marshaler runt var protoReq QueryPublicCredentialsRequest 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_PublicCredentials_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.PublicCredentials(ctx, &protoReq) return msg, metadata, err } +var ( + filter_Query_PublicCredentialsByHolder_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_PublicCredentialsByHolder_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryPublicCredentialsByHolderRequest var metadata runtime.ServerMetadata @@ -127,6 +149,13 @@ func request_Query_PublicCredentialsByHolder_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PublicCredentialsByHolder_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.PublicCredentialsByHolder(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -154,11 +183,22 @@ func local_request_Query_PublicCredentialsByHolder_0(ctx context.Context, marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PublicCredentialsByHolder_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.PublicCredentialsByHolder(ctx, &protoReq) return msg, metadata, err } +var ( + filter_Query_PublicCredentialsByIssuer_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_PublicCredentialsByIssuer_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryPublicCredentialsByIssuerRequest var metadata runtime.ServerMetadata @@ -181,6 +221,13 @@ func request_Query_PublicCredentialsByIssuer_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PublicCredentialsByIssuer_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.PublicCredentialsByIssuer(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -208,6 +255,13 @@ func local_request_Query_PublicCredentialsByIssuer_0(ctx context.Context, marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PublicCredentialsByIssuer_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.PublicCredentialsByIssuer(ctx, &protoReq) return msg, metadata, err @@ -303,6 +357,10 @@ func local_request_Query_CredentialDefinitions_0(ctx context.Context, marshaler } +var ( + filter_Query_CredentialDefinitionsByPublisher_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_CredentialDefinitionsByPublisher_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryCredentialDefinitionsByPublisherRequest var metadata runtime.ServerMetadata @@ -325,6 +383,13 @@ func request_Query_CredentialDefinitionsByPublisher_0(ctx context.Context, marsh return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CredentialDefinitionsByPublisher_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.CredentialDefinitionsByPublisher(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -352,6 +417,13 @@ func local_request_Query_CredentialDefinitionsByPublisher_0(ctx context.Context, return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CredentialDefinitionsByPublisher_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.CredentialDefinitionsByPublisher(ctx, &protoReq) return msg, metadata, err diff --git a/x/credential/spec/02_state.md b/x/credential/spec/02_state.md index 48b2cff4..91a315f3 100644 --- a/x/credential/spec/02_state.md +++ b/x/credential/spec/02_state.md @@ -8,18 +8,95 @@ This document describes the state pertaining to: ## Credential Definition -TODO: add +```go -#### Source -TODO: add -+++ https://github.com/elesto-dao/elesto/blob/v1.0.0/proto/credential/credential.proto#L1 +type CredentialDefinition struct { + // the credential definition did + Id string + // the did of the publisher of the credential + PublisherId string + // The credential json-ld schema. + // The schema can be big and verbose (and expensive), but should not be compressed since + // it is used by the msg_server to verify public credentials and. if zipped, will open + // the node to a zip bomb attack vector + Schema []byte + // the credential vocabulary + // The vocabulary can be big and verbose (and expensive), but should not be compressed since + // it is used by the msg_server to verify public credentials and. if zipped, will open + // the node to a zip bomb attack vector + Vocab []byte + // the human readable name of the credential, should be included + // in the type of the issued credential + Name string + // the description of the credential, such as it's purpose + Description string + // wherever the credential is intended for public use (on-chain) or not (off-chain) + // if the value is false then the module will forbid the issuance of the credential on chain + IsPublic bool + // did of the credential should not be used anymore in favour of something else + SupersededBy string `protobuf:"bytes,8,opt,name=supersededBy,proto3" json:"supersededBy,omitempty"` + // the credential can be de-activated + IsActive bool +} +``` + +### CredentialStatus +```go +type CredentialStatus struct { + Id string + Type string + RevocationListIndex int32 + RevocationListCredential string +} +``` + + +### Proof +```go +type Proof struct { + Created string + Type string + ProofPurpose string + VerificationMethod string + Signature string +} +``` + +#### Source +- [credential.proto](../../../proto/credential/v1/credential.proto) ## Public Verifiable Credential +```go +type PublicVerifiableCredential struct { + // json-ld context + Context []string + // the credential id + Id string + // the credential types + Type []string + // the DID of the issuer + Issuer string + // the date-time of issuance + IssuanceDate *time.Time + // the date-time of expiration + ExpirationDate *time.Time + // credential status for the revocation lists + CredentialStatus *CredentialStatus + // the subject of the credential + // the preferred way to handle the subject will be to use the Struct type + // but at the moment is not supported + // google.protobuf.Struct credentialSubject = 7; + CredentialSubject []byte + // One or more cryptographic proofs that can be used to detect tampering + // and verify the authorship of a credential or presentation. The specific + // method used for an embedded proof MUST be included using the type property. + Proof *Proof +} +``` + +#### Source +- [credential.proto](../../../proto/credential/v1/credential.proto) -TODO: add -#### Source -TODO: add -+++ https://github.com/elesto-dao/elesto/blob/v1.0.0/proto/credential/credential.proto#L1 diff --git a/x/credential/spec/03_state_transitions.md b/x/credential/spec/03_state_transitions.md index c29333ef..bcfc81cd 100644 --- a/x/credential/spec/03_state_transitions.md +++ b/x/credential/spec/03_state_transitions.md @@ -3,20 +3,19 @@ ### PublishCredentialDefinition -TODO - Example: - + example-definition-id example-credential schema.json vocab.json +``` ```javascript /* gRPC message */ -PublishCredentialDefinition( +IssuePublishCredentialDefinition( MsgPublishCredentialDefinition( ) @@ -24,38 +23,39 @@ PublishCredentialDefinition( /* Resolved Credential Definition */ { + } ``` ##### Implementation Source -- server: https://github.com/elesto-dao/elesto/blob/v1.0.0/x/credential/keeper/msg_server.go#L27 -- client: https://github.com/elesto-dao/elesto/blob/v1.0.0/x/credential/client/cli/tx.go#L43 +- server: [msg_server.go](../keeper/msg_server.go) +- client: [tx.go](../client/cli/tx.go) +### ### IssuePublicVerifiableCredential -TODO - Example: - + --from regulator --node https://elesto.app.beta.starport.cloud:443 --chain-id cosmoscash-testnet \ + example-definition-id credential.json + +``` ```javascript /* gRPC message */ -PublishCredentialDefinition( - MsgPublishCredentialDefinition( +IssuePublicVerifiableCredential( + MsgIssuePublicVerifiableCredential( ) ) -/* Resolved Credential Definition */ +/* Issued PVC */ { } @@ -63,5 +63,27 @@ PublishCredentialDefinition( ##### Implementation Source -- server: https://github.com/elesto-dao/elesto/blob/v1.0.0/x/credential/keeper/msg_server.go#L27 -- client: https://github.com/elesto-dao/elesto/blob/v1.0.0/x/credential/client/cli/tx.go#L43 +- server: [msg_server.go](../keeper/msg_server.go) +- client: [tx.go](../client/cli/tx.go) + +### UpdateCredentialDefinition + +```javascript +/* gRPC message */ +UpdateCredentialDefinition( + MsgUpdateCredentialDefinition( + + ) +) + +/* Resolved Credential Definition */ +{ +} + +``` +##### Implementation Source + +- server: [msg_server.go](../keeper/msg_server.go) +- client: [tx.go](../client/cli/tx.go) + + diff --git a/x/credential/spec/04_messages.md b/x/credential/spec/04_messages.md index 36c174c7..f9054917 100644 --- a/x/credential/spec/04_messages.md +++ b/x/credential/spec/04_messages.md @@ -1,8 +1,7 @@ # Messages -TODO -In this section we describe the processing of the staking messages and the corresponding updates to the state. All created/modified state objects specified by each message are defined within the [state](./02_state_transitions.md) section. +In this section we describe the processing of the messsages and the corresponding updates to the state. All created/modified state objects specified by each message are defined within the [state](./03_state_transitions.md) section. @@ -10,9 +9,34 @@ In this section we describe the processing of the staking messages and the corre A `MsgPublishCredentialDefinition` is used to publish a credential definition on chain, it has the following fields -- `id` - the did string identifying the credential definition +- `credentialDefinition` - the credential definition to publish - `signer` - a string containing the cosmos address of the private key signing the transaction #### Source -https://github.com/elesto-dao/elesto/blob/v1.0.0/proto/credential/tx.proto#L45 + - [credentialDefinition](./02_state.md#credential-definition) + - [tx.proto](../../../proto/credential/v1/tx.proto) + + +### MsgUpdateCredentialDefinition + +A `MsgUpdateCredentialDefinition` is used to update a credential definition + +- `credentialDefinitionID` - id of credential definition that has to be updated +- `active` - update the active field +- `supersededBy` - update the SupersededBy field +- `signer` - a string containing the cosmos address of the private key signing the transaction + +#### Source +- [tx.proto](../../../proto/credential/v1/tx.proto) + +### MsgIssuePublicVerifiableCredential +A `MsgIssuePublicVerifiableCredential` is used to publish public verifiable credential for a credential definition +- `credential` - public verifiable credential to publish +- `credentialDefinitionID` - credential definition id for which public verifiable credential is published +- `signer` - a string containing the cosmos address of the private key signing the transaction + + +#### Source +- [tx.proto](../../../proto/credential/v1/tx.proto) +- [credential.proto](../../../proto/credential/v1/credential.proto) diff --git a/x/credential/spec/05_events.md b/x/credential/spec/05_events.md new file mode 100644 index 00000000..2c2a2cca --- /dev/null +++ b/x/credential/spec/05_events.md @@ -0,0 +1,21 @@ +# Events Emitted + +```go +type CredentialDefinitionPublishedEvent struct { + CredentialDefinitionID string + PublisherID string +} + +type CredentialDefinitionUpdatedEvent struct { + CredentialDefinitionID string +} + +type PublicCredentialIssuedEvent struct { + CredentialDefinitionID string + CredentialID string + IssuerID string +} +``` +###source +- [event.proto](../../../proto/credential/v1/event.proto) + diff --git a/x/did/client/cli/aries.go b/x/did/client/cli/aries.go index c7d89905..6cdd225b 100644 --- a/x/did/client/cli/aries.go +++ b/x/did/client/cli/aries.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "time" @@ -35,7 +34,7 @@ func request(method, url string, requestBody io.Reader, val interface{}) (err er return } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return } diff --git a/x/did/did.go b/x/did/did.go index 42ba1bf6..44a402e0 100644 --- a/x/did/did.go +++ b/x/did/did.go @@ -322,7 +322,7 @@ func WithVerifications(verifications ...*Verification) DocumentOption { } } -//WithServices add optional services +// WithServices add optional services func WithServices(services ...*Service) DocumentOption { return func(did *DidDocument) error { return did.AddServices(services...) diff --git a/x/did/simulation/operations.go b/x/did/simulation/operations.go index 2158a96f..08f8d868 100644 --- a/x/did/simulation/operations.go +++ b/x/did/simulation/operations.go @@ -295,8 +295,9 @@ func SimulateMsgUpdateDidDocument(k keeper.Keeper, bk did.BankKeeper, ak did.Acc if err != nil { return simtypes.NoOpMsg(did.ModuleName, TypeMsgUpdateDidDocument, "did not found, could not add vm", - ), nil, nil + ), nil, err } + err = didDoc.AddServices(service1, service2, service3) if err != nil { return simtypes.NoOpMsg(