/
credential.go
31 lines (27 loc) · 1.01 KB
/
credential.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package credential
import (
"fmt"
"golang.org/x/crypto/ed25519"
"github.com/workdaycredentials/ledger-common/proof"
)
// VerifyClaim verifies the digital signature of the Claim Proof associated with the given attribute
// and public key. An error will be returned if the signature is either invalid or if a Claim Proof
// cannot be found for the given attribute.
func VerifyClaim(cred *VerifiableCredential, attribute string, publicKey ed25519.PublicKey) error {
proofForAttr, found := cred.ClaimProofs[attribute]
if !found {
return fmt.Errorf("missing claim proof for attribute \"%s\"", attribute)
}
suite, err := proof.SignatureSuites().GetSuiteForCredentialsProof(&proofForAttr)
if err != nil {
return err
}
value := cred.CredentialSubject[attribute]
claim := VerifiableCredential{
Metadata: cred.Metadata,
CredentialSubject: map[string]interface{}{attribute: value},
Proof: &proofForAttr,
}
verifier := &proof.Ed25519Verifier{PubKey: publicKey}
return suite.Verify(&claim, verifier)
}