Skip to content

🔐 Allow choose proof purpose when signing VC #727

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

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions client/credential/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
flagOverwrite = "overwrite"
flagDate = "date"
flagSchemaMap = "schema-map"
flagPurpose = "purpose"
)

const (
Expand Down Expand Up @@ -65,6 +66,9 @@ It will read a verifiable credential from a file (or stdin), sign it, and print
"Multiple mappings can be provided by repeating the flag. Example usage: "+
"--%[1]s originalURI1=alternativeURI1 --%[1]s originalURI2=alternativeURI2",
flagSchemaMap))
cmd.Flags().String(flagPurpose, "assertionMethod", "Proof that describes credential purpose, helps prevent it from being "+
"misused for some other purpose. Example of commonly used proof purpose values: "+
"authentication, assertionMethod, keyAgreement, capabilityDelegation, capabilityInvocation.")

_ = cmd.MarkFlagRequired(flags.FlagFrom)

Expand Down Expand Up @@ -120,7 +124,13 @@ func runSignCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
err = signVerifiableCredential(documentLoader, vc, signer, date)

purpose, err := cmd.Flags().GetString(flagPurpose)
if err != nil {
return err
}

err = signVerifiableCredential(documentLoader, vc, signer, date, purpose)
if err != nil {
return errorsmod.Wrapf(sdkerr.ErrInvalidRequest, "failed to sign: %v", err)
}
Expand Down Expand Up @@ -245,7 +255,7 @@ func loadVerifiableCredential(documentLoader ld.DocumentLoader, bs []byte) (*ver
}

func signVerifiableCredential(
documentLoader ld.DocumentLoader, vc *verifiable.Credential, signer KeyringSigner, date time.Time,
documentLoader ld.DocumentLoader, vc *verifiable.Credential, signer KeyringSigner, date time.Time, purpose string,
) error {
didKeyID, err := signer.DIDKeyID()
if err != nil {
Expand All @@ -265,6 +275,7 @@ func signVerifiableCredential(
Suite: ed25519signature2020.New(suite.WithSigner(signer)),
SignatureRepresentation: verifiable.SignatureProofValue,
VerificationMethod: didKeyID,
Purpose: purpose,
}, jsonld.WithDocumentLoader(documentLoader))
case *secp256k1.PubKey:
return vc.AddLinkedDataProof(&verifiable.LinkedDataProofContext{
Expand All @@ -273,6 +284,7 @@ func signVerifiableCredential(
Suite: ecdsasecp256k1signature2019.New(suite.WithSigner(signer)),
SignatureRepresentation: verifiable.SignatureJWS,
VerificationMethod: didKeyID,
Purpose: purpose,
}, jsonld.WithDocumentLoader(documentLoader))
default:
return fmt.Errorf("invalid pubkey type: %s; expected oneof %+q",
Expand Down
1 change: 1 addition & 0 deletions docs/command/axoned_credential_sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ axoned credential sign [file] [flags]
--keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "test")
--keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used
--overwrite Overwrite existing signatures with a new one. If disabled, new signature will be appended
--purpose string Proof that describes credential purpose, helps prevent it from being misused for some other purpose. Example of commonly used proof purpose values: authentication, assertionMethod, keyAgreement, capabilityDelegation, capabilityInvocation. (default "assertionMethod")
--schema-map strings Map original URIs to alternative URIs for resolving JSON-LD schemas. Useful for redirecting network-based URIs to local filesystem paths or other URIs. Each mapping should be in the format 'originalURI=alternativeURI'. Multiple mappings can be provided by repeating the flag. Example usage: --schema-map originalURI1=alternativeURI1 --schema-map originalURI2=alternativeURI2
```

Expand Down
Loading