Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use snake-case for did.proto + proto lint fixes #171

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ lint:
- cosmos_proto
- google
- confio
# TODO: `did` is excluded to odey the W3C spec which uses camel-case, but I guess we can use snake-case.
- panacea/did
breaking:
use:
- FILE
Expand Down
19 changes: 10 additions & 9 deletions proto/panacea/did/v2/did.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ message DIDDocument {
Strings contexts = 1 [json_name = "@context", (gogoproto.jsontag) = "@context", (gogoproto.customtype) = "JSONStringOrStrings"];
string id = 2;
Strings controller = 3 [(gogoproto.customtype) = "JSONStringOrStrings"];
repeated VerificationMethod verificationMethods = 4 [json_name = "verificationMethod", (gogoproto.jsontag) = "verificationMethod,omitempty"];
repeated VerificationMethod verification_methods = 4 [json_name = "verificationMethod", (gogoproto.jsontag) = "verificationMethod,omitempty"];
// TODO: the repeated gogoproto.customtype has an issue: https://github.com/gogo/protobuf/issues/478
repeated VerificationRelationship authentications = 5 [json_name = "authentication", (gogoproto.jsontag) = "authentication,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship assertionMethods = 6 [json_name = "assertionMethod", (gogoproto.jsontag) = "assertionMethod,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship keyAgreements = 7 [json_name = "keyAgreement", (gogoproto.jsontag) = "keyAgreement,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship capabilityInvocations = 8 [json_name = "capabilityInvocation", (gogoproto.jsontag) = "capabilityInvocation,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship capabilityDelegations = 9 [json_name = "capabilityDelegation", (gogoproto.jsontag) = "capabilityDelegation,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship assertion_methods = 6 [json_name = "assertionMethod", (gogoproto.jsontag) = "assertionMethod,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship key_agreements = 7 [json_name = "keyAgreement", (gogoproto.jsontag) = "keyAgreement,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship capability_invocations = 8 [json_name = "capabilityInvocation", (gogoproto.jsontag) = "capabilityInvocation,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated VerificationRelationship capability_delegations = 9 [json_name = "capabilityDelegation", (gogoproto.jsontag) = "capabilityDelegation,omitempty", (gogoproto.customtype) = "VerificationRelationship"];
repeated Service services = 10 [json_name = "service", (gogoproto.jsontag) = "service,omitempty"];
}

Expand All @@ -31,11 +31,12 @@ message VerificationMethod {
string id = 1;
string type = 2;
string controller = 3;
string pubKeyBase58 = 4 [json_name = "publicKeyBase58", (gogoproto.jsontag) = "publicKeyBase58"];
string public_key_base58 = 4 [json_name = "publicKeyBase58", (gogoproto.jsontag) = "publicKeyBase58"];
}

// VerificationRelationship defines a W3C verification relationship
message VerificationRelationship {
// VerificationRelationship can be one of a single ID or a VerificationMethod.
oneof content {
string verification_method_id = 1;
VerificationMethod verification_method = 2;
Expand All @@ -46,17 +47,17 @@ message VerificationRelationship {
message Service {
string id = 1;
string type = 2;
string serviceEndpoint = 3;
string service_endpoint = 3 [json_name = "serviceEndpoint", (gogoproto.jsontag) = "serviceEndpoint,omitempty"];
}

// DIDDocumentWithSeq defines a message for DID Document with a sequence number for preventing replay attacks.
message DIDDocumentWithSeq {
DIDDocument document = 1;
uint64 seq = 2 [json_name = "sequence", (gogoproto.jsontag) = "sequence"];
uint64 sequence = 2;
}

// DataWithSeq defines a message for data with a sequence number for preventing replay attacks.
message DataWithSeq {
bytes data = 1;
uint64 seq = 2;
uint64 sequence = 2;
}
4 changes: 2 additions & 2 deletions proto/panacea/did/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ option go_package = "github.com/medibloc/panacea-core/x/did/types";

// Query defines the gRPC querier service.
service Query {
// DIDDocumentWithSeq returns a DID Document with a sequence number.
rpc DIDDocumentWithSeq(QueryDIDRequest) returns (QueryDIDResponse) {
// DID returns a DID Document with a sequence number.
rpc DID(QueryDIDRequest) returns (QueryDIDResponse) {
Comment on lines -14 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to

{"path":"proto/panacea/did/v2/query.proto","start_line":15,"start_column":58,"end_line":15,"end_column":74,"type":"RPC_RESPONSE_STANDARD_NAME","message":"RPC response type "QueryDIDResponse" should be named "DIDDocumentWithSeqResponse" or "QueryDIDDocumentWithSeqResponse"."}

Similar as

rpc Topic(QueryTopicRequest) returns (QueryTopicResponse) {

option (google.api.http).get = "/panacea/did/v2/dids/{did}";
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/did/client/cli/queryDID.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CmdGetDID() *cobra.Command {
Did: id,
}

res, err := queryClient.DIDDocumentWithSeq(context.Background(), params)
res, err := queryClient.DID(context.Background(), params)

if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions x/did/client/cli/txDID.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ func signUsingCurrentSeq(clientCtx client.Context, did string, privKey crypto.Pr
Did: did,
}

res, err := queryClient.DIDDocumentWithSeq(context.Background(), params)
res, err := queryClient.DID(context.Background(), params)
if err != nil {
return []byte{}, err
}

return types.Sign(data, res.DidDocumentWithSeq.Seq, privKey)
return types.Sign(data, res.DidDocumentWithSeq.Sequence, privKey)
}
20 changes: 10 additions & 10 deletions x/did/client/cli/txDID_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (suite txTestSuite) TestNewMsgCreateDID() {

// check if verificationMethod is correct
verificationMethod, _ := msg.Document.VerificationMethodByID(msg.VerificationMethodId)
pubKey, _ := secp256k1util.PubKeyFromBase58(verificationMethod.PubKeyBase58)
pubKey, _ := secp256k1util.PubKeyFromBase58(verificationMethod.PublicKeyBase58)
suite.Require().Equal(privKey.PubKey(), pubKey)

// check if the signature can be verifiable with the initial sequence
Expand Down Expand Up @@ -126,7 +126,7 @@ func (suite txTestSuite) TestReadDIDDocOneContext() {
suite.Require().Equal(1, len(doc.VerificationMethods))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.VerificationMethods[0].Controller)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.VerificationMethods[0].Id)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PubKeyBase58)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PublicKeyBase58)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.VerificationMethods[0].Type)
suite.Require().Equal(1, len(doc.Authentications))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.Authentications[0].GetVerificationMethodId())
Expand All @@ -145,7 +145,7 @@ func (suite txTestSuite) TestReadDIDDocTwoContexts() {
suite.Require().Equal(1, len(doc.VerificationMethods))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.VerificationMethods[0].Controller)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.VerificationMethods[0].Id)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PubKeyBase58)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PublicKeyBase58)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.VerificationMethods[0].Type)
suite.Require().Equal(1, len(doc.Authentications))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.Authentications[0].GetVerificationMethodId())
Expand All @@ -163,7 +163,7 @@ func (suite txTestSuite) TestReadDIDDocMultiRelationship() {
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.Id)
suite.Require().Equal(2, len(doc.VerificationMethods))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.VerificationMethods[0].Controller)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PubKeyBase58)
suite.Require().Equal("hfiFwEqzHPx3RbQBmkgg4UEMtejfbL27CspYNKiVuURN", doc.VerificationMethods[0].PublicKeyBase58)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.VerificationMethods[0].Type)
suite.Require().Equal(2, len(doc.Authentications))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.VerificationMethods[0].Id)
Expand All @@ -172,27 +172,27 @@ func (suite txTestSuite) TestReadDIDDocMultiRelationship() {
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.Authentications[1].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.Authentications[1].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key2", doc.Authentications[1].GetVerificationMethod().Id)
suite.Require().Equal("zH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV", doc.Authentications[1].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("zH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV", doc.Authentications[1].GetVerificationMethod().PublicKeyBase58)

suite.Require().Equal(3, len(doc.AssertionMethods))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.AssertionMethods[0].GetVerificationMethodId())
suite.Require().Nil(doc.AssertionMethods[0].GetVerificationMethod())
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.AssertionMethods[1].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.AssertionMethods[1].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key2", doc.AssertionMethods[1].GetVerificationMethod().Id)
suite.Require().Equal("aH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPs", doc.AssertionMethods[1].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("aH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPs", doc.AssertionMethods[1].GetVerificationMethod().PublicKeyBase58)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.AssertionMethods[2].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.AssertionMethods[2].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key3", doc.AssertionMethods[2].GetVerificationMethod().Id)
suite.Require().Equal("bH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPo", doc.AssertionMethods[2].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("bH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPo", doc.AssertionMethods[2].GetVerificationMethod().PublicKeyBase58)

suite.Require().Equal(3, len(doc.KeyAgreements))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.KeyAgreements[0].GetVerificationMethodId())
suite.Require().Nil(doc.KeyAgreements[0].GetVerificationMethod())
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.KeyAgreements[1].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.KeyAgreements[1].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key2", doc.KeyAgreements[1].GetVerificationMethod().Id)
suite.Require().Equal("oH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPP", doc.KeyAgreements[1].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("oH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPP", doc.KeyAgreements[1].GetVerificationMethod().PublicKeyBase58)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key3", doc.KeyAgreements[2].GetVerificationMethodId())
suite.Require().Nil(doc.KeyAgreements[2].GetVerificationMethod())

Expand All @@ -202,13 +202,13 @@ func (suite txTestSuite) TestReadDIDDocMultiRelationship() {
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.CapabilityInvocations[1].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.CapabilityInvocations[1].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key2", doc.CapabilityInvocations[1].GetVerificationMethod().Id)
suite.Require().Equal("PH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPp", doc.CapabilityInvocations[1].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("PH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPp", doc.CapabilityInvocations[1].GetVerificationMethod().PublicKeyBase58)

suite.Require().Equal(2, len(doc.CapabilityDelegations))
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key1", doc.CapabilityDelegations[0].GetVerificationMethodId())
suite.Require().Nil(doc.CapabilityDelegations[0].GetVerificationMethod())
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ", doc.CapabilityDelegations[1].GetVerificationMethod().Controller)
suite.Require().Equal("Secp256k1VerificationKey2018", doc.CapabilityDelegations[1].GetVerificationMethod().Type)
suite.Require().Equal("did:panacea:27FnaDeQZApXhsRZZDARhWYs2nKFaw3p7evGd9zUSrBZ#key2", doc.CapabilityDelegations[1].GetVerificationMethod().Id)
suite.Require().Equal("qH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPQ", doc.CapabilityDelegations[1].GetVerificationMethod().PubKeyBase58)
suite.Require().Equal("qH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPQ", doc.CapabilityDelegations[1].GetVerificationMethod().PublicKeyBase58)
}
2 changes: 1 addition & 1 deletion x/did/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (suite genesisTestSuite) TestGenesis() {

didKeeper.SetDIDDocument(suite.Ctx, did1, doc1)
didKeeper.SetDIDDocument(suite.Ctx, did2, doc2)
doc2Deactivated := doc2.Deactivate(doc2.Seq + 1)
doc2Deactivated := doc2.Deactivate(doc2.Sequence + 1)
didKeeper.SetDIDDocument(suite.Ctx, did2, doc2Deactivated)

// export a genesis
Expand Down
2 changes: 1 addition & 1 deletion x/did/keeper/grpc_query_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"google.golang.org/grpc/status"
)

func (k Keeper) DIDDocumentWithSeq(c context.Context, req *types.QueryDIDRequest) (*types.QueryDIDResponse, error) {
func (k Keeper) DID(c context.Context, req *types.QueryDIDRequest) (*types.QueryDIDResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand Down
2 changes: 1 addition & 1 deletion x/did/keeper/grpc_query_did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (suite queryDIDTestSuite) TestDIDDocumentWithSeq() {
didKeeper.SetDIDDocument(suite.Ctx, did, docWithSeq)

req := types.QueryDIDRequest{Did: did}
res, err := didKeeper.DIDDocumentWithSeq(sdk.WrapSDKContext(suite.Ctx), &req)
res, err := didKeeper.DID(sdk.WrapSDKContext(suite.Ctx), &req)
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(docWithSeq, *res.DidDocumentWithSeq)
Expand Down
8 changes: 4 additions & 4 deletions x/did/keeper/msg_server_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m msgServer) UpdateDID(goCtx context.Context, msg *types.MsgUpdateDID) (*t
return nil, sdkerrors.Wrapf(types.ErrDIDDeactivated, "DID: %s", msg.Did)
}

newSeq, err := VerifyDIDOwnership(msg.Document, docWithSeq.Seq, docWithSeq.Document, msg.VerificationMethodId, msg.Signature)
newSeq, err := VerifyDIDOwnership(msg.Document, docWithSeq.Sequence, docWithSeq.Document, msg.VerificationMethodId, msg.Signature)
if err != nil {
return nil, err
}
Expand All @@ -70,7 +70,7 @@ func (m msgServer) DeactivateDID(goCtx context.Context, msg *types.MsgDeactivate
Id: msg.Did,
}

newSeq, err := VerifyDIDOwnership(&doc, docWithSeq.Seq, docWithSeq.Document, msg.VerificationMethodId, msg.Signature)
newSeq, err := VerifyDIDOwnership(&doc, docWithSeq.Sequence, docWithSeq.Document, msg.VerificationMethodId, msg.Signature)
if err != nil {
return nil, err
}
Expand All @@ -92,9 +92,9 @@ func VerifyDIDOwnership(signData *types.DIDDocument, seq uint64, doc *types.DIDD
if verificationMethod.Type != types.ES256K_2019 && verificationMethod.Type != types.ES256K_2018 {
return 0, sdkerrors.Wrapf(types.ErrVerificationMethodKeyTypeNotImplemented, "VerificationMethod: %v", verificationMethod.Type)
}
pubKeySecp256k1, err := secp256k1util.PubKeyFromBase58(verificationMethod.PubKeyBase58)
pubKeySecp256k1, err := secp256k1util.PubKeyFromBase58(verificationMethod.PublicKeyBase58)
if err != nil {
return 0, sdkerrors.Wrapf(types.ErrInvalidSecp256k1PublicKey, "PublicKey: %v", verificationMethod.PubKeyBase58)
return 0, sdkerrors.Wrapf(types.ErrInvalidSecp256k1PublicKey, "PublicKey: %v", verificationMethod.PublicKeyBase58)
}
newSeq, ok := types.Verify(sig, signData, seq, pubKeySecp256k1)
if !ok {
Expand Down
Loading