Skip to content

Commit

Permalink
add Resolve Options
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Jan 18, 2024
1 parent b75d0d2 commit a2e694e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
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.1.3-0.20240116162647-433544ddcc47
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118174550-f1f74877ba9e
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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 h1:
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357/go.mod h1:C9Y8uMQA4W7SwoslPwXWE00NWxdqar0+M8heq7c0GGM=
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116162647-433544ddcc47 h1:QeTEz2Tia3/+S8Lm/pcpJzxyZx8N5aQc7fUHZhCAhMQ=
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116162647-433544ddcc47/go.mod h1:mNO8FahWsgbmnMXtOENwie+jexmERHAzd9DpuSoziIY=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118172924-93422f880285 h1:kCgbZh6BKapdHAGeBeUlkkgJBzvVYr0GQqoMTOvei7Q=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118172924-93422f880285/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118174550-f1f74877ba9e h1:G05e04aqR8CSl4sHLT+yDseWugTFPZ9kCCUfuTLDrxA=
github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118174550-f1f74877ba9e/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k=
github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ=
github.com/ipfs/boxo v0.12.0/go.mod h1:xAnfiU6PtxWCnRqu7dcXQ10bB5/kvI1kXRotuGqGBhg=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
9 changes: 3 additions & 6 deletions resolvers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"

"github.com/gofrs/uuid/v5"
"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"
Expand All @@ -19,8 +18,6 @@ import (
// AgentResolverConfig options for credential status verification
type AgentResolverConfig struct {
PackageManager *iden3comm.PackageManager
UserDID *w3c.DID
IssuerDID *w3c.DID
}

// AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status.
Expand All @@ -34,7 +31,7 @@ func NewAgentResolver(config AgentResolverConfig) *AgentResolver {
}

// Resolve is a method to resolve a credential status from an agent.
func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) {
func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) {
revocationBody := protocol.RevocationStatusRequestMessageBody{
RevocationNonce: status.RevocationNonce,
}
Expand All @@ -54,8 +51,8 @@ func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialSt
msg := iden3comm.BasicMessage{
ID: idUUID.String(),
ThreadID: threadUUID.String(),
From: r.config.UserDID.String(),
To: r.config.IssuerDID.String(),
From: opts.UserDID.String(),
To: opts.IssuerDID.String(),
Type: protocol.RevocationStatusRequestMessageType,
Body: rawBody,
}
Expand Down
8 changes: 5 additions & 3 deletions resolvers/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func TestAgentResolver(t *testing.T) {

agentConfig := AgentResolverConfig{
PackageManager: pm,
IssuerDID: issuerDID,
UserDID: userDID,
}

agentResolver := NewAgentResolver(agentConfig)
Expand All @@ -47,7 +45,11 @@ func TestAgentResolver(t *testing.T) {
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"}`))

revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus)
resolveOpts := verifiable.CredentialStatusResolveOptions{
IssuerDID: issuerDID,
UserDID: userDID,
}
revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus, &resolveOpts)
require.NoError(t, err)

expectedRevocationStatusJSON := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}`
Expand Down

0 comments on commit a2e694e

Please sign in to comment.