From d80156120fba4f3bd7439ba9447054a2bd06fc45 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 13:09:09 +0200 Subject: [PATCH 01/20] add AgentResolver --- go.mod | 7 ++-- go.sum | 24 ++++++++++--- resolvers/agent.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 resolvers/agent.go diff --git a/go.mod b/go.mod index 41c67ad..1ef3989 100644 --- a/go.mod +++ b/go.mod @@ -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.1 + github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07 github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 @@ -27,15 +27,18 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/google/uuid v1.3.0 // indirect github.com/iden3/go-merkletree-sql/v2 v2.0.4 // indirect github.com/iden3/go-rapidsnark/prover v0.0.10 // indirect github.com/iden3/go-rapidsnark/verifier v0.0.5 // indirect github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 // indirect github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e // indirect + github.com/iden3/merkletree-proof v0.0.3 // indirect github.com/ipfs/boxo v0.12.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-ipfs-api v0.7.0 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/lestrrat-go/blackmagic v1.0.1 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect github.com/lestrrat-go/httprc v1.0.4 // indirect @@ -61,7 +64,7 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/tetratelabs/wazero v1.1.0 // indirect golang.org/x/crypto v0.12.0 // indirect - golang.org/x/sys v0.11.0 // indirect + golang.org/x/sys v0.15.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect diff --git a/go.sum b/go.sum index 6276c5f..09ec435 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,7 @@ github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2y github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg= github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -24,6 +25,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.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= @@ -44,16 +47,25 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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.1.1 h1:kS9D2ynuF2hgLM9e+IHV0kt6Tz4W/wXv+TXwUVQQi6M= -github.com/iden3/go-schema-processor/v2 v2.1.1/go.mod h1:wIa6h8BPWnXBImIIElYu5eLVW513pHjyTOj6KyVHenQ= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112104457-588f5e23c256 h1:YgbE+3XppqguY4RQP3Bhtwipg2Aa0J/5p8xaca9otpc= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112104457-588f5e23c256/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07 h1:LNJeXIfIM4lvnv/aHXkb2Fkk4JaRq9SeJKVUzjXw7UQ= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= +github.com/iden3/merkletree-proof v0.0.3 h1:01fSpjv2JIwVBYqV7ugLm0gjF+yo0aw41zDTWP5+81s= +github.com/iden3/merkletree-proof v0.0.3/go.mod h1:cNPG00p4ALlIXnRFmM1T2zy4547jV8cgyOZsObDrORg= 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= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/ipfs/go-ipfs-api v0.7.0 h1:CMBNCUl0b45coC+lQCXEVpMhwoqjiaCwUIrM+coYW2Q= github.com/ipfs/go-ipfs-api v0.7.0/go.mod h1:AIxsTNB0+ZhkqIfTZpdZ0VR/cpX5zrXjATa3prSay3g= +github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +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= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80= github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU= @@ -98,12 +110,15 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f h1:HlPa7RcxTCrva5izPfTEfvYecO7LTahgmMRD1Qp13xg= github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f/go.mod h1:WZ501QQMbZZ+3pXFPhQKzNwS1+jls0oqov3uQ2WasLs= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU= github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -141,8 +156,9 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -163,8 +179,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/go-jose/go-jose.v2 v2.6.1 h1:qEzJlIDmG9q5VO0M/o8tGS65QMHMS1w01TQJB1VPJ4U= gopkg.in/go-jose/go-jose.v2 v2.6.1/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/resolvers/agent.go b/resolvers/agent.go new file mode 100644 index 0000000..a40a339 --- /dev/null +++ b/resolvers/agent.go @@ -0,0 +1,90 @@ +package resolvers + +import ( + "bytes" + "encoding/json" + "io" + "net/http" + + "github.com/gofrs/uuid/v5" + "github.com/iden3/go-schema-processor/v2/verifiable" + "github.com/iden3/iden3comm/v2" + "github.com/iden3/iden3comm/v2/packers" + "github.com/iden3/iden3comm/v2/protocol" + "github.com/pkg/errors" +) + +type AgentResolver struct { +} + +func (AgentResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { + revocationBody := protocol.RevocationStatusRequestMessageBody{ + RevocationNonce: status.RevocationNonce, + } + rawBody, err := json.Marshal(revocationBody) + if err != nil { + return out, errors.WithStack(err) + } + + idUUID, err := uuid.NewV4() + if err != nil { + return out, err + } + threadUUID, err := uuid.NewV4() + if err != nil { + return out, err + } + msg := iden3comm.BasicMessage{ + ID: idUUID.String(), + ThreadID: threadUUID.String(), + From: *cfg.UserDID, + To: *cfg.IssuerDID, + Type: protocol.RevocationStatusRequestMessageType, + Body: rawBody, + } + bytesMsg, err := json.Marshal(msg) + if err != nil { + return out, errors.WithStack(err) + } + + iden3commMsg, err := cfg.PackageManager.Pack(packers.MediaTypePlainMessage, bytesMsg, nil) + if err != nil { + return out, errors.WithStack(err) + } + + resp, err := http.DefaultClient.Post(status.ID, "application/json", bytes.NewBuffer(iden3commMsg)) + if err != nil { + return out, errors.WithStack(err) + } + defer func() { + err2 := resp.Body.Close() + if err != nil { + err = errors.WithStack(err2) + } + }() + + if resp.StatusCode != http.StatusOK { + return out, errors.Errorf("bad status code: %d", resp.StatusCode) + } + + b, err := io.ReadAll(resp.Body) + if err != nil { + return out, errors.WithStack(err) + } + + basicMessage, _, err := cfg.PackageManager.Unpack(b) + if err != nil { + return out, errors.WithStack(err) + } + + if basicMessage.Type != protocol.RevocationStatusResponseMessageType { + return out, errors.Errorf("unexpected message type: %s", basicMessage.Type) + } + + var revocationStatus protocol.RevocationStatusResponseMessageBody + if err := json.Unmarshal(basicMessage.Body, &revocationStatus); err != nil { + return out, errors.WithStack(err) + } + + return revocationStatus.RevocationStatus, nil +} From acd7549e468b515bec75cacf9f96731587cfc9f5 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 13:19:01 +0200 Subject: [PATCH 02/20] add comments --- resolvers/agent.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resolvers/agent.go b/resolvers/agent.go index a40a339..9c3f84f 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -14,9 +14,11 @@ import ( "github.com/pkg/errors" ) +// AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status. type AgentResolver struct { } +// Resolve is a method to resolve a credential status from an agent. func (AgentResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { revocationBody := protocol.RevocationStatusRequestMessageBody{ RevocationNonce: status.RevocationNonce, From 882c5106fe1f104699865b774884003626931d99 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 15:47:48 +0200 Subject: [PATCH 03/20] update schema-processor --- go.mod | 4 +--- go.sum | 10 ++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 1ef3989..448730b 100644 --- a/go.mod +++ b/go.mod @@ -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.2-0.20240112110437-1ae002a26f07 + github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 @@ -27,13 +27,11 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/iden3/go-merkletree-sql/v2 v2.0.4 // indirect github.com/iden3/go-rapidsnark/prover v0.0.10 // indirect github.com/iden3/go-rapidsnark/verifier v0.0.5 // indirect github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 // indirect github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e // indirect - github.com/iden3/merkletree-proof v0.0.3 // indirect github.com/ipfs/boxo v0.12.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-ipfs-api v0.7.0 // indirect diff --git a/go.sum b/go.sum index 09ec435..2ddb02d 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.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= @@ -47,12 +45,8 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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.1.2-0.20240112104457-588f5e23c256 h1:YgbE+3XppqguY4RQP3Bhtwipg2Aa0J/5p8xaca9otpc= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112104457-588f5e23c256/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07 h1:LNJeXIfIM4lvnv/aHXkb2Fkk4JaRq9SeJKVUzjXw7UQ= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= -github.com/iden3/merkletree-proof v0.0.3 h1:01fSpjv2JIwVBYqV7ugLm0gjF+yo0aw41zDTWP5+81s= -github.com/iden3/merkletree-proof v0.0.3/go.mod h1:cNPG00p4ALlIXnRFmM1T2zy4547jV8cgyOZsObDrORg= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a h1:Tn2zsP2WUDEz11kK6sqL3pRS5JVASAwtFWHaewSENzM= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a/go.mod h1:pvsn5IdeVgChvgiRmeSKHgSmUiDmMtaeso9ggtFxwj0= 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= From 685f4cd2fb6e79f021b2ffbc0cbbd3ec75478c61 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 10:55:51 +0200 Subject: [PATCH 04/20] update go-schema-processor --- go.mod | 2 +- go.sum | 2 ++ resolvers/agent.go | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 448730b..5ef2a33 100644 --- a/go.mod +++ b/go.mod @@ -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.2-0.20240112134442-898b55d2849a + github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 2ddb02d..c51f170 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,8 @@ 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.1.2-0.20240112134442-898b55d2849a h1:Tn2zsP2WUDEz11kK6sqL3pRS5JVASAwtFWHaewSENzM= github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a/go.mod h1:pvsn5IdeVgChvgiRmeSKHgSmUiDmMtaeso9ggtFxwj0= +github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 h1:631Z7Ipm8GYM9DMV1irvcZ1gubCqD/cdICXQ5MVA0Jo= +github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357/go.mod h1:C9Y8uMQA4W7SwoslPwXWE00NWxdqar0+M8heq7c0GGM= 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= diff --git a/resolvers/agent.go b/resolvers/agent.go index 9c3f84f..980b8f2 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -2,6 +2,7 @@ package resolvers import ( "bytes" + "context" "encoding/json" "io" "net/http" @@ -19,7 +20,7 @@ type AgentResolver struct { } // Resolve is a method to resolve a credential status from an agent. -func (AgentResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { +func (AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { revocationBody := protocol.RevocationStatusRequestMessageBody{ RevocationNonce: status.RevocationNonce, } @@ -39,8 +40,8 @@ func (AgentResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable. msg := iden3comm.BasicMessage{ ID: idUUID.String(), ThreadID: threadUUID.String(), - From: *cfg.UserDID, - To: *cfg.IssuerDID, + From: cfg.UserDID.String(), + To: cfg.IssuerDID.String(), Type: protocol.RevocationStatusRequestMessageType, Body: rawBody, } From 1df169956e5e62e286e1dbda564fe0b31d0f91d8 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 18:45:58 +0200 Subject: [PATCH 05/20] refactor & add unit test --- go.mod | 3 ++- go.sum | 3 +++ resolvers/agent.go | 43 ++++++++++++++++++++++++++---- resolvers/agent_test.go | 59 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 resolvers/agent_test.go diff --git a/go.mod b/go.mod index 5ef2a33..62af9a6 100644 --- a/go.mod +++ b/go.mod @@ -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.20240116084732-b5c2484f9357 + github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116162647-433544ddcc47 github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 @@ -35,6 +35,7 @@ require ( github.com/ipfs/boxo v0.12.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-ipfs-api v0.7.0 // indirect + github.com/jarcoal/httpmock v1.3.1 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/lestrrat-go/blackmagic v1.0.1 // indirect diff --git a/go.sum b/go.sum index c51f170..f4d5cae 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,8 @@ github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a h1: github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a/go.mod h1:pvsn5IdeVgChvgiRmeSKHgSmUiDmMtaeso9ggtFxwj0= github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 h1:631Z7Ipm8GYM9DMV1irvcZ1gubCqD/cdICXQ5MVA0Jo= 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/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= @@ -56,6 +58,7 @@ github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LK github.com/ipfs/go-ipfs-api v0.7.0 h1:CMBNCUl0b45coC+lQCXEVpMhwoqjiaCwUIrM+coYW2Q= github.com/ipfs/go-ipfs-api v0.7.0/go.mod h1:AIxsTNB0+ZhkqIfTZpdZ0VR/cpX5zrXjATa3prSay3g= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= +github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/resolvers/agent.go b/resolvers/agent.go index 980b8f2..535ac5f 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -8,6 +8,7 @@ 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" @@ -15,12 +16,44 @@ import ( "github.com/pkg/errors" ) +// AgentResolverConfig options for credential status verification +type AgentResolverConfig struct { + PackageManager *iden3comm.PackageManager + UserDID *w3c.DID + IssuerDID *w3c.DID +} + +// AgentResolverOpts returns configuration options for AgentResolverOpts +type AgentResolverOpts func(opts *AgentResolverConfig) + +// WithPackageManager return new options +func WithPackageManager(pm *iden3comm.PackageManager) AgentResolverOpts { + return func(opts *AgentResolverConfig) { + opts.PackageManager = pm + } +} + +// WithUserDID return new options +func WithUserDID(userDID *w3c.DID) AgentResolverOpts { + return func(opts *AgentResolverConfig) { + opts.UserDID = userDID + } +} + +// WithIssuerDID return new options +func WithIssuerDID(issuerDID *w3c.DID) AgentResolverOpts { + return func(opts *AgentResolverConfig) { + opts.IssuerDID = issuerDID + } +} + // AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status. type AgentResolver struct { + config AgentResolverConfig } // Resolve is a method to resolve a credential status from an agent. -func (AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { +func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { revocationBody := protocol.RevocationStatusRequestMessageBody{ RevocationNonce: status.RevocationNonce, } @@ -40,8 +73,8 @@ func (AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStat msg := iden3comm.BasicMessage{ ID: idUUID.String(), ThreadID: threadUUID.String(), - From: cfg.UserDID.String(), - To: cfg.IssuerDID.String(), + From: r.config.UserDID.String(), + To: r.config.IssuerDID.String(), Type: protocol.RevocationStatusRequestMessageType, Body: rawBody, } @@ -50,7 +83,7 @@ func (AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStat return out, errors.WithStack(err) } - iden3commMsg, err := cfg.PackageManager.Pack(packers.MediaTypePlainMessage, bytesMsg, nil) + iden3commMsg, err := r.config.PackageManager.Pack(packers.MediaTypePlainMessage, bytesMsg, nil) if err != nil { return out, errors.WithStack(err) } @@ -75,7 +108,7 @@ func (AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStat return out, errors.WithStack(err) } - basicMessage, _, err := cfg.PackageManager.Unpack(b) + basicMessage, _, err := r.config.PackageManager.Unpack(b) if err != nil { return out, errors.WithStack(err) } diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go new file mode 100644 index 0000000..94cc151 --- /dev/null +++ b/resolvers/agent_test.go @@ -0,0 +1,59 @@ +package resolvers + +import ( + "context" + "encoding/json" + "testing" + + "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", + "revocationNonce": 3262660310, + "type": "Iden3commRevocationStatusV1.0" + }` + + var credStatus verifiable.CredentialStatus + err := json.Unmarshal([]byte(credStatusJson), &credStatus) + require.NoError(t, err) + + pm := iden3comm.NewPackageManager() + err = pm.RegisterPackers(&packers.PlainMessagePacker{}) + require.NoError(t, err) + + issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qJp131YoXVu8iLNGfL3TkQAWEr3pqimh2iaPgH3BJ") + require.NoError(t, err) + userDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE") + + opts := []AgentResolverOpts{WithPackageManager(pm), WithIssuerDID(issuerDID), WithUserDID(userDID)} + + agentConfig := AgentResolverConfig{} + for _, o := range opts { + o(&agentConfig) + } + + agentResolver := AgentResolver{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"}`)) + + revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus) + require.NoError(t, err) + + expectedRevocationStatusJson := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}` + var expectedRevocationStatus verifiable.RevocationStatus + _ = json.Unmarshal([]byte(expectedRevocationStatusJson), &expectedRevocationStatus) + + assert.Equal(t, revocationStatus, expectedRevocationStatus) + +} From 332c21dd3c6ef22ae693e2bb4ea585c7610224ce Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 18:51:40 +0200 Subject: [PATCH 06/20] fix linter --- resolvers/agent_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index 94cc151..921b29f 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -15,14 +15,14 @@ import ( ) func TestAgentResolver(t *testing.T) { - credStatusJson := `{ + credStatusJSON := `{ "id": "http://localhost:8001/api/v1/agent", "revocationNonce": 3262660310, "type": "Iden3commRevocationStatusV1.0" }` var credStatus verifiable.CredentialStatus - err := json.Unmarshal([]byte(credStatusJson), &credStatus) + err := json.Unmarshal([]byte(credStatusJSON), &credStatus) require.NoError(t, err) pm := iden3comm.NewPackageManager() @@ -32,6 +32,7 @@ func TestAgentResolver(t *testing.T) { issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qJp131YoXVu8iLNGfL3TkQAWEr3pqimh2iaPgH3BJ") require.NoError(t, err) userDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE") + require.NoError(t, err) opts := []AgentResolverOpts{WithPackageManager(pm), WithIssuerDID(issuerDID), WithUserDID(userDID)} @@ -50,9 +51,9 @@ func TestAgentResolver(t *testing.T) { revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus) require.NoError(t, err) - expectedRevocationStatusJson := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}` + expectedRevocationStatusJSON := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}` var expectedRevocationStatus verifiable.RevocationStatus - _ = json.Unmarshal([]byte(expectedRevocationStatusJson), &expectedRevocationStatus) + _ = json.Unmarshal([]byte(expectedRevocationStatusJSON), &expectedRevocationStatus) assert.Equal(t, revocationStatus, expectedRevocationStatus) From 82684e8b630252fd304b8e261f24192f4d724bea Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Wed, 17 Jan 2024 12:22:01 +0200 Subject: [PATCH 07/20] rm options --- resolvers/agent.go | 24 ------------------------ resolvers/agent_test.go | 9 ++++----- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index 535ac5f..dea8045 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -23,30 +23,6 @@ type AgentResolverConfig struct { IssuerDID *w3c.DID } -// AgentResolverOpts returns configuration options for AgentResolverOpts -type AgentResolverOpts func(opts *AgentResolverConfig) - -// WithPackageManager return new options -func WithPackageManager(pm *iden3comm.PackageManager) AgentResolverOpts { - return func(opts *AgentResolverConfig) { - opts.PackageManager = pm - } -} - -// WithUserDID return new options -func WithUserDID(userDID *w3c.DID) AgentResolverOpts { - return func(opts *AgentResolverConfig) { - opts.UserDID = userDID - } -} - -// WithIssuerDID return new options -func WithIssuerDID(issuerDID *w3c.DID) AgentResolverOpts { - return func(opts *AgentResolverConfig) { - opts.IssuerDID = issuerDID - } -} - // AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status. type AgentResolver struct { config AgentResolverConfig diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index 921b29f..9e11197 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -34,11 +34,10 @@ func TestAgentResolver(t *testing.T) { userDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE") require.NoError(t, err) - opts := []AgentResolverOpts{WithPackageManager(pm), WithIssuerDID(issuerDID), WithUserDID(userDID)} - - agentConfig := AgentResolverConfig{} - for _, o := range opts { - o(&agentConfig) + agentConfig := AgentResolverConfig{ + PackageManager: pm, + IssuerDID: issuerDID, + UserDID: userDID, } agentResolver := AgentResolver{agentConfig} From b75d0d2c9a8fe149b46b5f18b3521e430aa589e2 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Thu, 18 Jan 2024 18:23:16 +0200 Subject: [PATCH 08/20] add NewAgentResolver --- resolvers/agent.go | 5 +++++ resolvers/agent_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index dea8045..539da4b 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -28,6 +28,11 @@ type AgentResolver struct { config AgentResolverConfig } +// NewAgentResolver returns new agent resolver +func NewAgentResolver(config AgentResolverConfig) *AgentResolver { + return &AgentResolver{config} +} + // 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) { revocationBody := protocol.RevocationStatusRequestMessageBody{ diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index 9e11197..313eed4 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -40,7 +40,7 @@ func TestAgentResolver(t *testing.T) { UserDID: userDID, } - agentResolver := AgentResolver{agentConfig} + agentResolver := NewAgentResolver(agentConfig) httpmock.Activate() defer httpmock.DeactivateAndReset() From a2e694eb8e5cbcadc1b6c65572c4bc0aee53a2b3 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Thu, 18 Jan 2024 20:02:38 +0200 Subject: [PATCH 09/20] add Resolve Options --- go.mod | 2 +- go.sum | 4 ++++ resolvers/agent.go | 9 +++------ resolvers/agent_test.go | 8 +++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 62af9a6..1d58e83 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f4d5cae..6acfbae 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/resolvers/agent.go b/resolvers/agent.go index 539da4b..afa8bee 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -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" @@ -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. @@ -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, } @@ -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, } diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index 313eed4..20aac1d 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -36,8 +36,6 @@ func TestAgentResolver(t *testing.T) { agentConfig := AgentResolverConfig{ PackageManager: pm, - IssuerDID: issuerDID, - UserDID: userDID, } agentResolver := NewAgentResolver(agentConfig) @@ -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":[]}}` From 78abb1a9af19846b0de8afc386fff520ecb95c2e Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 19 Jan 2024 13:14:39 +0200 Subject: [PATCH 10/20] use CredentialStatusResolveOpt... --- go.mod | 2 +- go.sum | 2 ++ resolvers/agent.go | 11 ++++++++--- resolvers/agent_test.go | 7 ++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 1d58e83..884fb83 100644 --- a/go.mod +++ b/go.mod @@ -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.2.1-0.20240118174550-f1f74877ba9e + github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7 github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 6acfbae..37b1637 100644 --- a/go.sum +++ b/go.sum @@ -55,6 +55,8 @@ github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118172924-93422f880285 h1: 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/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7 h1:jPilJUWMv+BkPRyB13UATZv24SSkrMNBPTxPliqGA90= +github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7/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= diff --git a/resolvers/agent.go b/resolvers/agent.go index afa8bee..3de4e1f 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -31,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, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) { +func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialStatus, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { revocationBody := protocol.RevocationStatusRequestMessageBody{ RevocationNonce: status.RevocationNonce, } @@ -48,11 +48,16 @@ func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialSt if err != nil { return out, err } + + config := verifiable.CredentialStatusResolveConfig{} + for _, o := range opts { + o(&config) + } msg := iden3comm.BasicMessage{ ID: idUUID.String(), ThreadID: threadUUID.String(), - From: opts.UserDID.String(), - To: opts.IssuerDID.String(), + From: config.UserDID.String(), + To: config.IssuerDID.String(), Type: protocol.RevocationStatusRequestMessageType, Body: rawBody, } diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index 20aac1d..f0645bc 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -45,11 +45,8 @@ 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"}`)) - resolveOpts := verifiable.CredentialStatusResolveOptions{ - IssuerDID: issuerDID, - UserDID: userDID, - } - revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus, &resolveOpts) + resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID), verifiable.WithUserDID(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":[]}}` From c84e85ad8c11d3ea299b1b9a44aaca0899966649 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Thu, 25 Jan 2024 10:45:34 -0500 Subject: [PATCH 11/20] Upgrade to new version of go-schema-processor, add user/issuser DID getter/setter --- go.mod | 27 ++--------------- go.sum | 67 ++--------------------------------------- resolvers/agent.go | 52 ++++++++++++++++++++++++++++---- resolvers/agent_test.go | 6 ++-- 4 files changed, 55 insertions(+), 97 deletions(-) diff --git a/go.mod b/go.mod index 884fb83..61e7f48 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,8 @@ 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.2.1-0.20240119110812-6363011261f7 + github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240124111525-52e3f8db0f62 + 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 @@ -19,9 +20,6 @@ require ( ) require ( - github.com/benbjohnson/clock v1.3.5 // indirect - github.com/blang/semver/v4 v4.0.0 // indirect - github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dchest/blake512 v1.0.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect @@ -32,39 +30,18 @@ require ( github.com/iden3/go-rapidsnark/verifier v0.0.5 // indirect github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 // indirect github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e // indirect - github.com/ipfs/boxo v0.12.0 // indirect - github.com/ipfs/go-cid v0.4.1 // indirect - github.com/ipfs/go-ipfs-api v0.7.0 // indirect - github.com/jarcoal/httpmock v1.3.1 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/lestrrat-go/blackmagic v1.0.1 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect github.com/lestrrat-go/httprc v1.0.4 // indirect github.com/lestrrat-go/iter v1.0.2 // indirect github.com/lestrrat-go/option v1.0.1 // indirect - github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p v0.28.1 // indirect - github.com/minio/sha256-simd v1.0.1 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/multiformats/go-base32 v0.1.0 // indirect - github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr v0.9.0 // indirect - github.com/multiformats/go-multibase v0.2.0 // indirect - github.com/multiformats/go-multicodec v0.9.0 // indirect - github.com/multiformats/go-multihash v0.2.3 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect - github.com/multiformats/go-varint v0.0.7 // indirect github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect github.com/segmentio/asm v1.2.0 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/tetratelabs/wazero v1.1.0 // indirect golang.org/x/crypto v0.12.0 // indirect golang.org/x/sys v0.15.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index 37b1637..2ff5476 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,9 @@ -github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= -github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= -github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= -github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= -github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg= -github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/blake512 v1.0.0 h1:oDFEQFIqFSeuA34xLtXZ/rWxCXdSjirjzPhey5EUvmA= github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI= -github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= @@ -21,8 +13,6 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= 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/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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/iden3/go-circuits/v2 v2.0.1 h1:tcJtBE8aLJsf9qpBoTUKE143Mne025cunQnSExMXaKo= @@ -45,28 +35,10 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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.1.2-0.20240112134442-898b55d2849a h1:Tn2zsP2WUDEz11kK6sqL3pRS5JVASAwtFWHaewSENzM= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a/go.mod h1:pvsn5IdeVgChvgiRmeSKHgSmUiDmMtaeso9ggtFxwj0= -github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 h1:631Z7Ipm8GYM9DMV1irvcZ1gubCqD/cdICXQ5MVA0Jo= -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/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7 h1:jPilJUWMv+BkPRyB13UATZv24SSkrMNBPTxPliqGA90= -github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7/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= -github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= -github.com/ipfs/go-ipfs-api v0.7.0 h1:CMBNCUl0b45coC+lQCXEVpMhwoqjiaCwUIrM+coYW2Q= -github.com/ipfs/go-ipfs-api v0.7.0/go.mod h1:AIxsTNB0+ZhkqIfTZpdZ0VR/cpX5zrXjATa3prSay3g= +github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240124111525-52e3f8db0f62 h1:FmIHPoJq3MROiqd1rmscO4CdfqGcUgaXujyGsEbtIwA= +github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240124111525-52e3f8db0f62/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/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 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= @@ -85,34 +57,9 @@ 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/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= -github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= -github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.28.1 h1:YurK+ZAI6cKfASLJBVFkpVBdl3wGhFi6fusOt725ii8= -github.com/libp2p/go-libp2p v0.28.1/go.mod h1:s3Xabc9LSwOcnv9UD4nORnXKTsWkPMkIMB/JIGXVnzk= -github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= -github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +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/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= -github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= -github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= -github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= -github.com/multiformats/go-multiaddr v0.9.0 h1:3h4V1LHIk5w4hJHekMKWALPXErDfz/sggzwC/NcqbDQ= -github.com/multiformats/go-multiaddr v0.9.0/go.mod h1:mI67Lb1EeTOYb8GQfL/7wpIZwc46ElrvzhYnoJOmTT0= -github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= -github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= -github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= -github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= -github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= -github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= -github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= -github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f h1:HlPa7RcxTCrva5izPfTEfvYecO7LTahgmMRD1Qp13xg= github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f/go.mod h1:WZ501QQMbZZ+3pXFPhQKzNwS1+jls0oqov3uQ2WasLs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -126,8 +73,6 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -180,10 +125,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/go-jose/go-jose.v2 v2.6.1 h1:qEzJlIDmG9q5VO0M/o8tGS65QMHMS1w01TQJB1VPJ4U= @@ -191,5 +132,3 @@ gopkg.in/go-jose/go-jose.v2 v2.6.1/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEI gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= -lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= diff --git a/resolvers/agent.go b/resolvers/agent.go index 3de4e1f..147a1a8 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -8,6 +8,7 @@ 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" @@ -15,6 +16,39 @@ import ( "github.com/pkg/errors" ) +type ctxKeyIssuerDID struct{} +type ctxKeyUserDID struct{} + +// WithIssuerDID puts the issuer DID in the context +func WithIssuerDID(ctx context.Context, issuerDID *w3c.DID) context.Context { + return context.WithValue(ctx, ctxKeyIssuerDID{}, issuerDID) +} + +// GetIssuerDID extract the issuer DID from the context. +// Or nil if nothing is found. +func GetIssuerDID(ctx context.Context) *w3c.DID { + return getTpCtx[w3c.DID](ctx, ctxKeyIssuerDID{}) +} + +// WithUserDID puts the user DID in the context +func WithUserDID(ctx context.Context, userDID *w3c.DID) context.Context { + return context.WithValue(ctx, ctxKeyUserDID{}, userDID) +} + +// GetUserDID extract the user DID from the context. +// Or nil if nothing is found. +func GetUserDID(ctx context.Context) *w3c.DID { + return getTpCtx[w3c.DID](ctx, ctxKeyUserDID{}) +} + +func getTpCtx[T any](ctx context.Context, key any) *T { + v := ctx.Value(key) + if v == nil { + return nil + } + return v.(*T) +} + // AgentResolverConfig options for credential status verification type AgentResolverConfig struct { PackageManager *iden3comm.PackageManager @@ -31,7 +65,9 @@ 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, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { +func (r AgentResolver) Resolve(ctx context.Context, + status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + revocationBody := protocol.RevocationStatusRequestMessageBody{ RevocationNonce: status.RevocationNonce, } @@ -49,15 +85,19 @@ func (r AgentResolver) Resolve(_ context.Context, status verifiable.CredentialSt return out, err } - config := verifiable.CredentialStatusResolveConfig{} - for _, o := range opts { - o(&config) + userDID := GetUserDID(ctx) + if userDID == nil { + return out, errors.New("user DID not found in the context") + } + issuerDID := GetUserDID(ctx) + if issuerDID == nil { + return out, errors.New("issuer DID not found in the context") } msg := iden3comm.BasicMessage{ ID: idUUID.String(), ThreadID: threadUUID.String(), - From: config.UserDID.String(), - To: config.IssuerDID.String(), + From: userDID.String(), + To: issuerDID.String(), Type: protocol.RevocationStatusRequestMessageType, Body: rawBody, } diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index f0645bc..a17b253 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -45,8 +45,10 @@ 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"}`)) - resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID), verifiable.WithUserDID(userDID)} - revocationStatus, err := agentResolver.Resolve(context.Background(), credStatus, resolveOpts...) + ctx := context.Background() + ctx = WithIssuerDID(ctx, issuerDID) + ctx = WithUserDID(ctx, userDID) + revocationStatus, err := agentResolver.Resolve(ctx, credStatus) require.NoError(t, err) expectedRevocationStatusJSON := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}` From aac3cbdc2623d5f48e0a237fdb026e91bdc162d3 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Fri, 26 Jan 2024 07:56:22 -0500 Subject: [PATCH 12/20] Extract issuer setter/getter to go-schema-processor. Rename user DID setter/getter to sender DID. --- go.mod | 2 +- go.sum | 4 ++-- resolvers/agent.go | 44 +++++++++++++---------------------------- resolvers/agent_test.go | 9 +++++---- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index 61e7f48..d26d8f2 100644 --- a/go.mod +++ b/go.mod @@ -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.2.1-0.20240124111525-52e3f8db0f62 + 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 diff --git a/go.sum b/go.sum index 2ff5476..182caa4 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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.20240124111525-52e3f8db0f62 h1:FmIHPoJq3MROiqd1rmscO4CdfqGcUgaXujyGsEbtIwA= -github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240124111525-52e3f8db0f62/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k= +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= diff --git a/resolvers/agent.go b/resolvers/agent.go index 147a1a8..cb53294 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -16,37 +16,21 @@ import ( "github.com/pkg/errors" ) -type ctxKeyIssuerDID struct{} -type ctxKeyUserDID struct{} +type ctxKeySenderDID struct{} -// WithIssuerDID puts the issuer DID in the context -func WithIssuerDID(ctx context.Context, issuerDID *w3c.DID) context.Context { - return context.WithValue(ctx, ctxKeyIssuerDID{}, issuerDID) +// WithSenderDID puts the user DID in the context +func WithSenderDID(ctx context.Context, userDID *w3c.DID) context.Context { + return context.WithValue(ctx, ctxKeySenderDID{}, userDID) } -// GetIssuerDID extract the issuer DID from the context. -// Or nil if nothing is found. -func GetIssuerDID(ctx context.Context) *w3c.DID { - return getTpCtx[w3c.DID](ctx, ctxKeyIssuerDID{}) -} - -// WithUserDID puts the user DID in the context -func WithUserDID(ctx context.Context, userDID *w3c.DID) context.Context { - return context.WithValue(ctx, ctxKeyUserDID{}, userDID) -} - -// GetUserDID extract the user DID from the context. -// Or nil if nothing is found. -func GetUserDID(ctx context.Context) *w3c.DID { - return getTpCtx[w3c.DID](ctx, ctxKeyUserDID{}) -} - -func getTpCtx[T any](ctx context.Context, key any) *T { - v := ctx.Value(key) +// GetSenderDID extract the sender's DID from the context. +// Returns nil if nothing is found. +func GetSenderDID(ctx context.Context) *w3c.DID { + v := ctx.Value(ctxKeySenderDID{}) if v == nil { return nil } - return v.(*T) + return v.(*w3c.DID) } // AgentResolverConfig options for credential status verification @@ -85,18 +69,18 @@ func (r AgentResolver) Resolve(ctx context.Context, return out, err } - userDID := GetUserDID(ctx) - if userDID == nil { - return out, errors.New("user DID not found in the context") + senderDID := GetSenderDID(ctx) + if senderDID == nil { + return out, errors.New("sender DID not found in the context") } - issuerDID := GetUserDID(ctx) + issuerDID := verifiable.GetIssuerDID(ctx) if issuerDID == nil { return out, errors.New("issuer DID not found in the context") } msg := iden3comm.BasicMessage{ ID: idUUID.String(), ThreadID: threadUUID.String(), - From: userDID.String(), + From: senderDID.String(), To: issuerDID.String(), Type: protocol.RevocationStatusRequestMessageType, Body: rawBody, diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index a17b253..a725f42 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -31,7 +31,7 @@ func TestAgentResolver(t *testing.T) { issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qJp131YoXVu8iLNGfL3TkQAWEr3pqimh2iaPgH3BJ") require.NoError(t, err) - userDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE") + senderDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qFDziX3k3h7To2jDJbQiXFtcozbgSNNvQpb6TgtPE") require.NoError(t, err) agentConfig := AgentResolverConfig{ @@ -46,14 +46,15 @@ func TestAgentResolver(t *testing.T) { 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 = WithIssuerDID(ctx, issuerDID) - ctx = WithUserDID(ctx, userDID) + ctx = verifiable.WithIssuerDID(ctx, issuerDID) + ctx = WithSenderDID(ctx, senderDID) revocationStatus, err := agentResolver.Resolve(ctx, credStatus) require.NoError(t, err) expectedRevocationStatusJSON := `{"issuer":{"state":"96161f3fbbdd68c72bc430dae474e27b157586b33b9fbf4a3f07d75ce275570f","rootOfRoots":"eaa48e4a7d3fe2fabbd939c7df1048c3f647a9a7c9dfadaae836ec78ba673229","claimsTreeRoot":"d9597e2fef206c9821f2425e513a68c8c793bc93c9216fb883fedaaf72abf51c","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000"},"mtp":{"existence":false,"siblings":[]}}` var expectedRevocationStatus verifiable.RevocationStatus - _ = json.Unmarshal([]byte(expectedRevocationStatusJSON), &expectedRevocationStatus) + err = json.Unmarshal([]byte(expectedRevocationStatusJSON), &expectedRevocationStatus) + require.NoError(t, err) assert.Equal(t, revocationStatus, expectedRevocationStatus) From a9d810a6e6e81e073d6382630c0dd37c3e444f56 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 12:04:00 +0200 Subject: [PATCH 13/20] resolve comments --- go.mod | 2 +- go.sum | 5 ++--- resolvers/agent.go | 23 +++++++++++++++++------ resolvers/agent_test.go | 22 +++++++++++++--------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index d26d8f2..e7c8991 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 182caa4..f378b6f 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/resolvers/agent.go b/resolvers/agent.go index cb53294..dca8017 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -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" @@ -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. @@ -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, } @@ -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 } @@ -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) } @@ -129,5 +140,5 @@ func (r AgentResolver) Resolve(ctx context.Context, return out, errors.WithStack(err) } - return revocationStatus.RevocationStatus, nil + return revocationStatus.RevocationStatus, err } diff --git a/resolvers/agent_test.go b/resolvers/agent_test.go index a725f42..4e5a522 100644 --- a/resolvers/agent_test.go +++ b/resolvers/agent_test.go @@ -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) @@ -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) From b62f00734a9c8af27606e20edd7e801fe1300466 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 12:07:07 +0200 Subject: [PATCH 14/20] fix linter --- resolvers/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index dca8017..1757856 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -136,7 +136,7 @@ func (r AgentResolver) Resolve(ctx context.Context, } var revocationStatus protocol.RevocationStatusResponseMessageBody - if err := json.Unmarshal(basicMessage.Body, &revocationStatus); err != nil { + if err = json.Unmarshal(basicMessage.Body, &revocationStatus); err != nil { return out, errors.WithStack(err) } From 609e66813a5c12b154dc251ecbca46f2746f4d76 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 15:49:58 +0200 Subject: [PATCH 15/20] accept all 200 codes --- resolvers/agent.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index 1757856..6f78735 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -117,7 +117,8 @@ func (r AgentResolver) Resolve(ctx context.Context, } }() - if resp.StatusCode != http.StatusOK { + statusOK := resp.StatusCode >= 200 && resp.StatusCode < 300 + if !statusOK { return out, errors.Errorf("bad status code: %d", resp.StatusCode) } From e72b4f47072f5149b626fee8d4d0143128ef66ff Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 16:11:00 +0200 Subject: [PATCH 16/20] errors.WithStack --- resolvers/agent.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index 6f78735..15325ac 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -66,11 +66,11 @@ func (r AgentResolver) Resolve(ctx context.Context, idUUID, err := uuid.NewV7() if err != nil { - return out, err + return out, errors.WithStack(err) } threadUUID, err := uuid.NewV7() if err != nil { - return out, err + return out, errors.WithStack(err) } senderDID := GetSenderDID(ctx) From 5af1576978367ba2ca7cbef4736427903321be7a Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 19:41:25 +0200 Subject: [PATCH 17/20] make customHTTPClient public --- resolvers/agent.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index 15325ac..ca6a0b8 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -36,7 +36,7 @@ func GetSenderDID(ctx context.Context) *w3c.DID { // AgentResolverConfig options for credential status verification type AgentResolverConfig struct { PackageManager *iden3comm.PackageManager - customHTTPClient *http.Client + CustomHTTPClient *http.Client } // AgentResolver is a struct that allows to interact with the issuer's agent to get revocation status. @@ -99,11 +99,9 @@ func (r AgentResolver) Resolve(ctx context.Context, return out, errors.WithStack(err) } - var httpClient *http.Client - if r.config.customHTTPClient != nil { - httpClient = r.config.customHTTPClient - } else { - httpClient = http.DefaultClient + httpClient := http.DefaultClient + if r.config.CustomHTTPClient != nil { + httpClient = r.config.CustomHTTPClient } resp, err := httpClient.Post(status.ID, "application/json", bytes.NewBuffer(iden3commMsg)) From bec4dff115844749b1b132eb2f084e04c369206d Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 20:01:05 +0200 Subject: [PATCH 18/20] rewrite body close err only if proof err nil --- resolvers/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/agent.go b/resolvers/agent.go index ca6a0b8..a27612f 100644 --- a/resolvers/agent.go +++ b/resolvers/agent.go @@ -110,7 +110,7 @@ func (r AgentResolver) Resolve(ctx context.Context, } defer func() { err2 := resp.Body.Close() - if err != nil { + if err == nil { err = errors.WithStack(err2) } }() From 67db65e482b423be0993cb750f4ccd18be72a0cd Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 6 Feb 2024 15:23:49 +0200 Subject: [PATCH 19/20] upgrae go-schema-processor/v2 to 2.3.0 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e7c8991..51e1260 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,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.2.1-0.20240126124145-b6f321093157 + github.com/iden3/go-schema-processor/v2 v2.3.0 github.com/lestrrat-go/jwx/v2 v2.0.12 github.com/mr-tron/base58 v1.2.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index f378b6f..87e2257 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ 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/iden3/go-schema-processor/v2 v2.3.0 h1:86tnt1myHntcG+9pJ3I+0ycc6V59sITrsPSt0k7/DhU= +github.com/iden3/go-schema-processor/v2 v2.3.0/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k= 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= From ad9a4c39eddcc9a2967463025aea26029538f89e Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 6 Feb 2024 16:51:16 +0200 Subject: [PATCH 20/20] rm gofrs package --- go.mod | 1 - go.sum | 4 ---- packager_test.go | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 51e1260..afa7a54 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ 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 diff --git a/go.sum b/go.sum index 87e2257..8b2e6b0 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,6 @@ github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJL github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564/go.mod h1:yekO+3ZShy19S+bsmnERmznGy9Rfg6dWWWpiGJjNAz8= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -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= @@ -37,8 +35,6 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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/iden3/go-schema-processor/v2 v2.3.0 h1:86tnt1myHntcG+9pJ3I+0ycc6V59sITrsPSt0k7/DhU= github.com/iden3/go-schema-processor/v2 v2.3.0/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/packager_test.go b/packager_test.go index 4adbb87..b00adc9 100644 --- a/packager_test.go +++ b/packager_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/gofrs/uuid/v5" + "github.com/google/uuid" "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-jwz/v2" "github.com/iden3/iden3comm/v2" @@ -156,7 +156,7 @@ func createFetchCredentialMessage(typ iden3comm.MediaType, from, to *w3c.DID) ([ msg.From = from.String() msg.To = to.String() msg.Typ = typ - claimID, err := uuid.NewV4() + claimID, err := uuid.NewV7() if err != nil { return nil, err }