Skip to content

Commit

Permalink
fix(sign): use right signature algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Mar 8, 2024
1 parent bab12a0 commit 5bb6d2d
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions client/credential/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5bb6d2d

Please sign in to comment.