Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Feb 5, 2024
1 parent 8a3fe41 commit a9d810a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.18
require (
github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564
github.com/gofrs/uuid/v5 v5.0.0
github.com/google/uuid v1.6.0
github.com/iden3/go-circuits/v2 v2.0.1
github.com/iden3/go-iden3-core/v2 v2.0.3
github.com/iden3/go-iden3-crypto v0.0.15
github.com/iden3/go-jwz/v2 v2.0.1
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240126124145-b6f321093157
github.com/jarcoal/httpmock v1.3.1
github.com/lestrrat-go/jwx/v2 v2.0.12
github.com/mr-tron/base58 v1.2.0
github.com/pkg/errors v0.9.1
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/iden3/go-circuits/v2 v2.0.1 h1:tcJtBE8aLJsf9qpBoTUKE143Mne025cunQnSExMXaKo=
github.com/iden3/go-circuits/v2 v2.0.1/go.mod h1:VIFIp51+IH0hOzjnKhb84bCeyq7hq76zX/C14ua6zh4=
github.com/iden3/go-iden3-core/v2 v2.0.3 h1:ce9Jbw10zDsinWXFc05SiK2Hof/wu4zV4/ai5gQy29k=
Expand All @@ -37,8 +39,6 @@ github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e
github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e/go.mod h1:UEBifEzw62T6VzIHJeHuUgeLg2U/J9ttf7hOwQEqnYk=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240126124145-b6f321093157 h1:bvZczBLCisoDGtWF8knmjlLLn7/VWEhfAHV0X6BXAHY=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240126124145-b6f321093157/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -57,7 +57,6 @@ github.com/lestrrat-go/jwx/v2 v2.0.12/go.mod h1:Mq4KN1mM7bp+5z/W5HS8aCNs5RKZ911G
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f h1:HlPa7RcxTCrva5izPfTEfvYecO7LTahgmMRD1Qp13xg=
Expand Down
23 changes: 17 additions & 6 deletions resolvers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/gofrs/uuid/v5"
"github.com/google/uuid"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2"
Expand Down Expand Up @@ -35,7 +35,8 @@ func GetSenderDID(ctx context.Context) *w3c.DID {

// AgentResolverConfig options for credential status verification
type AgentResolverConfig struct {
PackageManager *iden3comm.PackageManager
PackageManager *iden3comm.PackageManager
customHTTPClient *http.Client
}

// AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status.
Expand All @@ -52,6 +53,9 @@ func NewAgentResolver(config AgentResolverConfig) *AgentResolver {
func (r AgentResolver) Resolve(ctx context.Context,
status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) {

if status.Type != verifiable.Iden3commRevocationStatusV1 {
return out, errors.New("invalid status type")
}
revocationBody := protocol.RevocationStatusRequestMessageBody{
RevocationNonce: status.RevocationNonce,
}
Expand All @@ -60,11 +64,11 @@ func (r AgentResolver) Resolve(ctx context.Context,
return out, errors.WithStack(err)
}

idUUID, err := uuid.NewV4()
idUUID, err := uuid.NewV7()
if err != nil {
return out, err
}
threadUUID, err := uuid.NewV4()
threadUUID, err := uuid.NewV7()
if err != nil {
return out, err
}
Expand Down Expand Up @@ -95,7 +99,14 @@ func (r AgentResolver) Resolve(ctx context.Context,
return out, errors.WithStack(err)
}

resp, err := http.DefaultClient.Post(status.ID, "application/json", bytes.NewBuffer(iden3commMsg))
var httpClient *http.Client
if r.config.customHTTPClient != nil {
httpClient = r.config.customHTTPClient
} else {
httpClient = http.DefaultClient
}

resp, err := httpClient.Post(status.ID, "application/json", bytes.NewBuffer(iden3commMsg))
if err != nil {
return out, errors.WithStack(err)
}
Expand Down Expand Up @@ -129,5 +140,5 @@ func (r AgentResolver) Resolve(ctx context.Context,
return out, errors.WithStack(err)
}

return revocationStatus.RevocationStatus, nil
return revocationStatus.RevocationStatus, err
}
22 changes: 13 additions & 9 deletions resolvers/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ package resolvers
import (
"context"
"encoding/json"
"fmt"
"testing"

"net/http"
"net/http/httptest"

"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAgentResolver(t *testing.T) {
credStatusJSON := `{
"id": "http://localhost:8001/api/v1/agent",
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"body":{"issuer":{"claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f"},"mtp":{"existence":false,"siblings":[]}},"from":"did:polygonid:polygon:mumbai:2qJp131YoXVu8iLNGfL3TkQAWEr3pqimh2iaPgH3BJ","id":"9ece0dad-9267-4a52-b611-f0615b0143fb","thid":"8bdc87dc-1755-41d5-b483-26562836068e","to":"did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE","typ":"application/iden3comm-plain-json","type":"https://iden3-communication.io/revocation/1.0/status"}`))
}))
defer mockServer.Close()

credStatusJSON := fmt.Sprintf(`{
"id": "%s",
"revocationNonce": 3262660310,
"type": "Iden3commRevocationStatusV1.0"
}`
}`, mockServer.URL)

var credStatus verifiable.CredentialStatus
err := json.Unmarshal([]byte(credStatusJSON), &credStatus)
Expand All @@ -40,11 +49,6 @@ func TestAgentResolver(t *testing.T) {

agentResolver := NewAgentResolver(agentConfig)

httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", "http://localhost:8001/api/v1/agent",
httpmock.NewStringResponder(200, `{"body":{"issuer":{"claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f"},"mtp":{"existence":false,"siblings":[]}},"from":"did:polygonid:polygon:mumbai:2qJp131YoXVu8iLNGfL3TkQAWEr3pqimh2iaPgH3BJ","id":"9ece0dad-9267-4a52-b611-f0615b0143fb","thid":"8bdc87dc-1755-41d5-b483-26562836068e","to":"did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE","typ":"application/iden3comm-plain-json","type":"https://iden3-communication.io/revocation/1.0/status"}`))

ctx := context.Background()
ctx = verifiable.WithIssuerDID(ctx, issuerDID)
ctx = WithSenderDID(ctx, senderDID)
Expand Down

0 comments on commit a9d810a

Please sign in to comment.