Skip to content

Commit

Permalink
pass resolveOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Jan 18, 2024
1 parent 93422f8 commit f1f7487
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
15 changes: 12 additions & 3 deletions verifiable/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ func (vc *W3CCredential) VerifyProof(proofType ProofType, didResolver DIDResolve
return err
}

return verifyBJJSignatureProof(proof, coreClaim, didResolver, verifyConfig)
var userDID *w3c.DID
credSubjID, ok := vc.CredentialSubject["id"]
if ok {
credSubjString := fmt.Sprintf("%v", credSubjID)
userDID, err = w3c.ParseDID(credSubjString)
if err != nil {
return err
}
}
return verifyBJJSignatureProof(proof, coreClaim, didResolver, userDID, verifyConfig)
case Iden3SparseMerkleTreeProofType:
var proof Iden3SparseMerkleTreeProof
err = json.Unmarshal(credProofBytes, &proof)
Expand All @@ -87,7 +96,7 @@ func (vc *W3CCredential) VerifyProof(proofType ProofType, didResolver DIDResolve
}
}

func verifyBJJSignatureProof(proof BJJSignatureProof2021, coreClaim *core.Claim, didResolver DIDResolver, verifyConfig W3CProofVerificationConfig) error {
func verifyBJJSignatureProof(proof BJJSignatureProof2021, coreClaim *core.Claim, didResolver DIDResolver, userDID *w3c.DID, verifyConfig W3CProofVerificationConfig) error {
// issuer claim
authClaim := &core.Claim{}
err := authClaim.FromHex(proof.IssuerData.AuthCoreClaim)
Expand Down Expand Up @@ -161,7 +170,7 @@ func verifyBJJSignatureProof(proof BJJSignatureProof2021, coreClaim *core.Claim,
}
}

_, err = ValidateCredentialStatus(proof.IssuerData.CredentialStatus, coreClaim.GetRevocationNonce(), verifyConfig.StatusResolverRegistry)
_, err = ValidateCredentialStatus(proof.IssuerData.CredentialStatus, coreClaim.GetRevocationNonce(), verifyConfig.StatusResolverRegistry, issuerDID, userDID)
if err != nil {
return err
}
Expand Down
14 changes: 10 additions & 4 deletions verifiable/credential_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"fmt"
"math/big"

"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-iden3-crypto/poseidon"
"github.com/iden3/go-merkletree-sql/v2"
"github.com/pkg/errors"
)

func ValidateCredentialStatus(credStatus any, revNonce uint64, credStatusResolverRegistry *CredentialStatusResolverRegistry) (RevocationStatus, error) {
revocationStatus, err := resolveRevStatus(credStatus, credStatusResolverRegistry)
func ValidateCredentialStatus(credStatus any, revNonce uint64, credStatusResolverRegistry *CredentialStatusResolverRegistry, issuerDID, userDID *w3c.DID) (RevocationStatus, error) {
revocationStatus, err := resolveRevStatus(credStatus, credStatusResolverRegistry, issuerDID, userDID)
if err != nil {
return revocationStatus, err
}
Expand Down Expand Up @@ -45,7 +46,7 @@ func ValidateCredentialStatus(credStatus any, revNonce uint64, credStatusResolve
return revocationStatus, nil
}

func resolveRevStatus(status any, credStatusResolverRegistry *CredentialStatusResolverRegistry) (out RevocationStatus, err error) {
func resolveRevStatus(status any, credStatusResolverRegistry *CredentialStatusResolverRegistry, issuerDID, userDID *w3c.DID) (out RevocationStatus, err error) {
var statusType CredentialStatusType
var credentialStatusTyped CredentialStatus

Expand Down Expand Up @@ -76,7 +77,12 @@ func resolveRevStatus(status any, credStatusResolverRegistry *CredentialStatusRe
if err != nil {
return out, err
}
return resolver.Resolve(context.Background(), credentialStatusTyped)

resolveOpts := CredentialStatusResolveOptions{
IssuerDID: issuerDID,
UserDID: userDID,
}
return resolver.Resolve(context.Background(), credentialStatusTyped, &resolveOpts)
}

// marshal/unmarshal object from one type to other
Expand Down
6 changes: 3 additions & 3 deletions verifiable/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type test1Resolver struct{}

func (test1Resolver) Resolve(context context.Context, status CredentialStatus) (out RevocationStatus, err error) {
func (test1Resolver) Resolve(context context.Context, status CredentialStatus, opts *CredentialStatusResolveOptions) (out RevocationStatus, err error) {
statusJSON := `{"issuer":{"state":"34824a8e1defc326f935044e32e9f513377dbfc031d79475a0190830554d4409","rootOfRoots":"37eabc712cdaa64793561b16b8143f56f149ad1b0c35297a1b125c765d1c071e","claimsTreeRoot":"4436ea12d352ddb84d2ac7a27bbf7c9f1bfc7d3ff69f3e6cf4348f424317fd0b","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}`
var rs RevocationStatus
_ = json.Unmarshal([]byte(statusJSON), &rs)
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestW3CCredential_ValidateBJJSignatureProof(t *testing.T) {

type test2Resolver struct{}

func (test2Resolver) Resolve(context context.Context, status CredentialStatus) (out RevocationStatus, err error) {
func (test2Resolver) Resolve(context context.Context, status CredentialStatus, opts *CredentialStatusResolveOptions) (out RevocationStatus, err error) {
statusJSON := `{"issuer":{"state":"da6184809dbad90ccc52bb4dbfe2e8ff3f516d87c74d75bcc68a67101760b817","rootOfRoots":"0000000000000000000000000000000000000000000000000000000000000000","claimsTreeRoot":"aec50251fdc67959254c74ab4f2e746a7cd1c6f494c8ac028d655dfbccea430e","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}`
var rs RevocationStatus
_ = json.Unmarshal([]byte(statusJSON), &rs)
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestW3CCredential_ValidateIden3SparseMerkleTreeProof(t *testing.T) {

type test3Resolver struct{}

func (test3Resolver) Resolve(context context.Context, status CredentialStatus) (out RevocationStatus, err error) {
func (test3Resolver) Resolve(context context.Context, status CredentialStatus, opts *CredentialStatusResolveOptions) (out RevocationStatus, err error) {
statusJSON := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}`
var rs RevocationStatus
_ = json.Unmarshal([]byte(statusJSON), &rs)
Expand Down
2 changes: 1 addition & 1 deletion verifiable/status_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IssuerResolver struct {

const limitReaderBytes = 16 * 1024

func (IssuerResolver) Resolve(context context.Context, credentialStatus CredentialStatus) (out RevocationStatus, err error) {
func (IssuerResolver) Resolve(context context.Context, credentialStatus CredentialStatus, opts *CredentialStatusResolveOptions) (out RevocationStatus, err error) {
httpReq, err := http.NewRequestWithContext(context, http.MethodGet, credentialStatus.ID,
http.NoBody)
if err != nil {
Expand Down

0 comments on commit f1f7487

Please sign in to comment.