From 5bb6d2dced285b3519f012b840fef8192993193d Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:51:29 +0100 Subject: [PATCH 1/3] fix(sign): use right signature algorithm --- client/credential/sign.go | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/client/credential/sign.go b/client/credential/sign.go index 8b5fb61e..84fc1fc4 100644 --- a/client/credential/sign.go +++ b/client/credential/sign.go @@ -9,9 +9,14 @@ import ( "strings" "time" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2020" + + "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ecdsasecp256k1signature2019" + "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2018" "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable" "github.com/piprate/json-gold/ld" "github.com/spf13/cobra" @@ -249,13 +254,32 @@ func signVerifiableCredential( return err } - return vc.AddLinkedDataProof(&verifiable.LinkedDataProofContext{ - Created: &date, - SignatureType: "Ed25519Signature2018", - Suite: ed25519signature2018.New(suite.WithSigner(signer)), - SignatureRepresentation: verifiable.SignatureProofValue, - VerificationMethod: didKeyID, - }, jsonld.WithDocumentLoader(documentLoader)) + pubKey, err := signer.PubKey() + if err != nil { + return err + } + + switch pubKey.(type) { + case *ed25519.PubKey: + return vc.AddLinkedDataProof(&verifiable.LinkedDataProofContext{ + Created: &date, + SignatureType: "Ed25519Signature2020", + Suite: ed25519signature2020.New(suite.WithSigner(signer)), + SignatureRepresentation: verifiable.SignatureProofValue, + VerificationMethod: didKeyID, + }, jsonld.WithDocumentLoader(documentLoader)) + case *secp256k1.PubKey: + return vc.AddLinkedDataProof(&verifiable.LinkedDataProofContext{ + Created: &date, + SignatureType: "EcdsaSecp256k1Signature2019", + Suite: ecdsasecp256k1signature2019.New(suite.WithSigner(signer)), + SignatureRepresentation: verifiable.SignatureJWS, + VerificationMethod: didKeyID, + }, jsonld.WithDocumentLoader(documentLoader)) + default: + return fmt.Errorf("invalid pubkey type: %s; expected oneof %+q", + pubKey.Type(), []string{(&ed25519.PubKey{}).Type(), (&secp256k1.PubKey{}).Type()}) + } } func parseStringAsDate(cmd *cobra.Command, flag string) (time.Time, error) { From a783c0228d34f0e4d2b21c2b457ab478b38fd667 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Fri, 8 Mar 2024 22:42:54 +0100 Subject: [PATCH 2/3] fix(sign): properly expand input path --- client/credential/sign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/credential/sign.go b/client/credential/sign.go index 84fc1fc4..daca271b 100644 --- a/client/credential/sign.go +++ b/client/credential/sign.go @@ -213,7 +213,7 @@ func readFromFileOrStdin(filename string) ([]byte, error) { // expandPath expands the given path, replacing the "~" symbol with the user's home directory. func expandPath(path string) (string, error) { - if len(path) == 0 || strings.HasPrefix(path, symbolHome) { + if len(path) == 0 || !strings.HasPrefix(path, symbolHome) { return path, nil } From dfa82834492b6bf4da38c751c2431c50faa31370 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Fri, 8 Mar 2024 22:45:30 +0100 Subject: [PATCH 3/3] style: reorganize imports --- client/credential/sign.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/credential/sign.go b/client/credential/sign.go index daca271b..6d360a11 100644 --- a/client/credential/sign.go +++ b/client/credential/sign.go @@ -9,14 +9,10 @@ import ( "strings" "time" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2020" - - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ecdsasecp256k1signature2019" - "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld" "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite" + "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ecdsasecp256k1signature2019" + "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2020" "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable" "github.com/piprate/json-gold/ld" "github.com/spf13/cobra" @@ -26,6 +22,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerr "github.com/cosmos/cosmos-sdk/types/errors"