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/sign cmd #595

Merged
merged 3 commits into from
Mar 9, 2024
Merged
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
40 changes: 31 additions & 9 deletions client/credential/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

"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/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"
Expand All @@ -21,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"
Expand Down Expand Up @@ -208,7 +211,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
}

Expand Down Expand Up @@ -249,13 +252,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) {
Expand Down
Loading