From 69b8fc5ba5be112343b996be0422b007b7ddbaab Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 13:58:18 +0200 Subject: [PATCH 01/26] add rhs/onchain resolvers --- go.mod | 42 ++++++-- go.sum | 138 ++++++++++++++++++------ resolvers/onchain.go | 245 +++++++++++++++++++++++++++++++++++++++++++ resolvers/rhs.go | 179 +++++++++++++++++++++++++++++++ 4 files changed, 568 insertions(+), 36 deletions(-) create mode 100644 resolvers/onchain.go create mode 100644 resolvers/rhs.go diff --git a/go.mod b/go.mod index 3923254..e375719 100644 --- a/go.mod +++ b/go.mod @@ -5,31 +5,61 @@ go 1.19 require ( github.com/ethereum/go-ethereum v1.12.2 github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 + github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - github.com/stretchr/testify v1.8.2 + github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095 + github.com/pkg/errors v0.9.1 + github.com/stretchr/testify v1.8.4 ) require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect + github.com/benbjohnson/clock v1.3.5 // indirect + github.com/blang/semver/v4 v4.0.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.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/deckarep/golang-set/v2 v2.1.0 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/websocket v1.4.2 // indirect + github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/iden3/go-iden3-crypto v0.0.15 // indirect + github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc // 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/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/mr-tron/base58 v1.2.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/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.12.0 // indirect golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect - golang.org/x/sys v0.9.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + golang.org/x/sys v0.15.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // 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 f724d3a..476e771 100644 --- a/go.sum +++ b/go.sum @@ -2,13 +2,19 @@ github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= +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/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +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/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= @@ -16,16 +22,19 @@ github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5w github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +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/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= -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/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +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= +github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJLNCEi7YHVMkwwtfSr2k9splgdSM= github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= github.com/ethereum/go-ethereum v1.12.2 h1:eGHJ4ij7oyVqUQn48LBz3B7pvQ8sV0wGJiIE6gDq/6Y= github.com/ethereum/go-ethereum v1.12.2/go.mod h1:1cRAEV+rp/xX0zraSCBnu9Py3HQ+geRMj3HdR+k0wfI= @@ -38,66 +47,130 @@ github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +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/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= -github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= +github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 h1:/g4rru+OM5WAhVNXEpowKH+vWZLGjgpk5+O8Stu4QBo= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48/go.mod h1:kJmVPMk4HfWyl2kcta34aad/K4TAfCwB29xX9PsR7LQ= +github.com/iden3/go-circuits/v2 v2.0.0 h1:Bw0mpsqeip06d6I2ktgfhTVB7Jk9mSHi8myHZWkoc6w= +github.com/iden3/go-iden3-core/v2 v2.0.3 h1:ce9Jbw10zDsinWXFc05SiK2Hof/wu4zV4/ai5gQy29k= +github.com/iden3/go-iden3-core/v2 v2.0.3/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw= github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= +github.com/iden3/go-jwz/v2 v2.0.0 h1:VsU2PrmcchPMx/V0IhamMZRNjiQYZoyJopO8K8uSZOY= github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY= github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= +github.com/iden3/go-rapidsnark/prover v0.0.10 h1:NvOfRPpex/k646UsqOcUy7a7uVl17t4ok9kWvpQg4+k= +github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0xSrBi0jqM4= +github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= +github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= +github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= +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/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095 h1:zdTrMCf4n0Xu1nFra8igYHRUtHSga315quJeLxqTm2Q= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= +github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= +github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= +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/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= +github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= +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/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 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/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= +github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8= +github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= +github.com/lestrrat-go/jwx/v2 v2.0.12 h1:3d589+5w/b9b7S3DneICPW16AqTyYXB7VRjgluSDWeA= +github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= +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/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +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/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +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/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +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/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/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= -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= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= @@ -105,25 +178,30 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/urfave/cli/v2 v2.24.1 h1:/QYYr7g0EhwXEML8jO+8OYt5trPnLHS0p3mrgExJ5NU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/sys v0.5.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/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +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/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/go-jose/go-jose.v2 v2.6.1 h1:qEzJlIDmG9q5VO0M/o8tGS65QMHMS1w01TQJB1VPJ4U= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= -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= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= diff --git a/resolvers/onchain.go b/resolvers/onchain.go new file mode 100644 index 0000000..925cbd2 --- /dev/null +++ b/resolvers/onchain.go @@ -0,0 +1,245 @@ +package resolvers + +import ( + "encoding/hex" + "fmt" + "math/big" + "net/url" + "strconv" + "strings" + "sync" + + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" + "github.com/iden3/go-merkletree-sql/v2" + "github.com/iden3/go-schema-processor/v2/utils" + "github.com/iden3/go-schema-processor/v2/verifiable" + "github.com/pkg/errors" +) + +// OnChainIssuer is a struct that allows to interact with the onchain contract and build the revocation status. +type OnChainResolver struct { +} + +// resolve is a method to resolve a credential status from the blockchain. +func (*OnChainResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { + parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) + if err != nil { + return out, err + } + + issuerID, err := core.IDFromDID(*parsedIssuerDID) + if err != nil { + return out, err + } + + var zeroID core.ID + if issuerID == zeroID { + return out, errors.New("issuer ID is empty") + } + + onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID) + if err != nil { + return out, err + } + + if onchainRevStatus.revNonce != status.RevocationNonce { + return out, fmt.Errorf( + "revocationNonce is not equal to the one "+ + "in OnChainCredentialStatus ID {%d} {%d}", + onchainRevStatus.revNonce, status.RevocationNonce) + } + + isStateContractHasID, err := stateContractHasID(&issuerID, cfg.StateResolver) + if err != nil { + return out, err + } + + var resp verifiable.RevocationStatus + if isStateContractHasID { + resp, err = cfg.StateResolver.GetRevocationStatus(issuerID.BigInt(), + onchainRevStatus.revNonce) + if err != nil { + msg := err.Error() + if isErrInvalidRootsLength(err) { + msg = "roots were not saved to identity tree store" + } + return out, fmt.Errorf( + "GetRevocationProof smart contract call [GetRevocationStatus]: %s", + msg) + } + } else { + if onchainRevStatus.genesisState == nil { + return out, errors.New( + "genesis state is not specified in OnChainCredentialStatus ID") + } + resp, err = cfg.StateResolver.GetRevocationStatusByIDAndState( + issuerID.BigInt(), onchainRevStatus.genesisState, + onchainRevStatus.revNonce) + if err != nil { + return out, fmt.Errorf( + "GetRevocationProof smart contract call [GetRevocationStatusByIdAndState]: %s", + err.Error()) + } + } + + return resp, nil +} + +func newOnchainRevStatusFromURI(stateID string) (onChainRevStatus, error) { + var s onChainRevStatus + + uri, err := url.Parse(stateID) + if err != nil { + return s, errors.New("OnChainCredentialStatus ID is not a valid URI") + } + + contract := uri.Query().Get("contractAddress") + if contract == "" { + return s, errors.New("OnChainCredentialStatus contract address is empty") + } + + contractParts := strings.Split(contract, ":") + if len(contractParts) != 2 { + return s, errors.New( + "OnChainCredentialStatus contract address is not valid") + } + + s.chainID, err = newChainIDFromString(contractParts[0]) + if err != nil { + return s, err + } + s.contractAddress = contractParts[1] + + revocationNonce := uri.Query().Get("revocationNonce") + if revocationNonce == "" { + return s, errors.New("revocationNonce is empty in OnChainCredentialStatus ID") + } + + s.revNonce, err = strconv.ParseUint(revocationNonce, 10, 64) + if err != nil { + return s, errors.New("revocationNonce is not a number in OnChainCredentialStatus ID") + } + + // state may be nil if params is absent in query + s.genesisState, err = newIntFromHexQueryParam(uri, "state") + if err != nil { + return s, err + } + + return s, nil +} + +func newChainIDFromString(in string) (core.ChainID, error) { + var chainID uint64 + var err error + if strings.HasPrefix(in, "0x") || + strings.HasPrefix(in, "0X") { + chainID, err = strconv.ParseUint(in[2:], 16, 64) + if err != nil { + return 0, err + } + } else { + chainID, err = strconv.ParseUint(in, 10, 64) + if err != nil { + return 0, err + } + } + return core.ChainID(chainID), nil +} + +// newIntFromHexQueryParam search for query param `paramName`, parse it +// as hex string of LE bytes of *big.Int. Return nil if param is not found. +func newIntFromHexQueryParam(uri *url.URL, paramName string) (*big.Int, error) { + stateParam := uri.Query().Get(paramName) + if stateParam == "" { + return nil, nil + } + + stateParam = strings.TrimSuffix(stateParam, "0x") + stateBytes, err := hex.DecodeString(stateParam) + if err != nil { + return nil, err + } + + return newIntFromBytesLE(stateBytes), nil +} + +func newIntFromBytesLE(bs []byte) *big.Int { + return new(big.Int).SetBytes(utils.SwapEndianness(bs)) +} + +func stateContractHasID(id *core.ID, resolver verifiable.CredStatusStateResolver) (bool, error) { + + idsInStateContractLock.RLock() + ok := idsInStateContract[*id] + idsInStateContractLock.RUnlock() + if ok { + return ok, nil + } + + idsInStateContractLock.Lock() + defer idsInStateContractLock.Unlock() + + ok = idsInStateContract[*id] + if ok { + return ok, nil + } + + _, err := lastStateFromContract(resolver, id) + if errors.Is(err, errIdentityDoesNotExist) { + return false, nil + } else if err != nil { + return false, err + } + + idsInStateContract[*id] = true + return true, err +} + +type onChainRevStatus struct { + chainID core.ChainID + contractAddress string + revNonce uint64 + genesisState *big.Int +} + +func isErrInvalidRootsLength(err error) bool { + if err == nil { + return false + } + return err.Error() == "execution reverted: Invalid roots length" +} + +var errIdentityDoesNotExist = errors.New("identity does not exist") + +func isErrIdentityDoesNotExist(err error) bool { + if err == nil { + return false + } + return err.Error() == "execution reverted: Identity does not exist" +} + +var idsInStateContract = map[core.ID]bool{} +var idsInStateContractLock sync.RWMutex + +func lastStateFromContract(resolver verifiable.CredStatusStateResolver, + id *core.ID) (*merkletree.Hash, error) { + var zeroID core.ID + if id == nil || *id == zeroID { + return nil, errors.New("ID is empty") + } + + resp, err := resolver.GetStateInfoByID(id.BigInt()) + if isErrIdentityDoesNotExist(err) { + return nil, errIdentityDoesNotExist + } else if err != nil { + return nil, err + } + + if resp.State == "" { + return nil, errors.New("got empty state") + } + + return merkletree.NewHashFromString(resp.State) +} diff --git a/resolvers/rhs.go b/resolvers/rhs.go new file mode 100644 index 0000000..091065a --- /dev/null +++ b/resolvers/rhs.go @@ -0,0 +1,179 @@ +package resolvers + +import ( + "bytes" + "context" + "math/big" + "net/url" + "strings" + "time" + + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" + "github.com/iden3/go-merkletree-sql/v2" + "github.com/iden3/go-schema-processor/v2/verifiable" + mp "github.com/iden3/merkletree-proof/http" + "github.com/pkg/errors" +) + +// RHSResolver is a struct that allows to interact with the RHS service to get revocation status. +type RHSResolver struct { +} + +// resolve is a method to resolve a credential status from the RHS. +func (RHSResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { + parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) + if err != nil { + return out, err + } + + issuerID, err := core.IDFromDID(*parsedIssuerDID) + if err != nil { + return out, err + } + + revNonce := new(big.Int).SetUint64(status.RevocationNonce) + + baseRHSURL, genesisState, err := rhsBaseURL(status.ID) + if err != nil { + return out, err + } + + state, err := identityStateForRHS(cfg.StateResolver, &issuerID, genesisState) + if err != nil { + return out, err + } + + rhsCli, err := newRhsCli(baseRHSURL) + if err != nil { + return out, err + } + + out.Issuer, err = issuerFromRHS(context.Background(), *rhsCli, state) + if errors.Is(err, mp.ErrNodeNotFound) { + if genesisState != nil && state.Equals(genesisState) { + return out, errors.New("genesis state is not found in RHS") + } else { + return out, errors.New("current state is not found in RHS") + } + } else if err != nil { + return out, err + } + + revNonceHash, err := merkletree.NewHashFromBigInt(revNonce) + if err != nil { + return out, err + } + + revTreeRootHash, err := merkletree.NewHashFromHex(*out.Issuer.RevocationTreeRoot) + if err != nil { + return out, err + } + proof, err := rhsCli.GenerateProof(context.Background(), revTreeRootHash, + revNonceHash) + if err != nil { + return out, err + } + + out.MTP = *proof + + return out, nil +} + +func identityStateForRHS(resolver verifiable.CredStatusStateResolver, issuerID *core.ID, + genesisState *merkletree.Hash) (*merkletree.Hash, error) { + + state, err := lastStateFromContract(resolver, issuerID) + if !errors.Is(err, errIdentityDoesNotExist) { + return state, err + } + + if genesisState == nil { + return nil, errors.New("current state is not found for the identity") + } + + stateIsGenesis, err := genesisStateMatch(genesisState, *issuerID) + if err != nil { + return nil, err + } + + if !stateIsGenesis { + return nil, errors.New("state is not genesis for the identity") + } + + return genesisState, nil +} + +// check if genesis state matches the state from the ID +func genesisStateMatch(state *merkletree.Hash, id core.ID) (bool, error) { + var tp [2]byte + copy(tp[:], id[:2]) + otherID, err := core.NewIDFromIdenState(tp, state.BigInt()) + if err != nil { + return false, err + } + return bytes.Equal(otherID[:], id[:]), nil +} + +func issuerFromRHS(ctx context.Context, rhsCli mp.ReverseHashCli, + state *merkletree.Hash) (verifiable.Issuer, error) { + + var issuer verifiable.Issuer + + stateNode, err := rhsCli.GetNode(ctx, state) + if err != nil { + return issuer, err + } + + if len(stateNode.Children) != 3 { + return issuer, errors.New( + "invalid state node, should have 3 children") + } + + stateHex := state.Hex() + issuer.State = &stateHex + claimsTreeRootHex := stateNode.Children[0].Hex() + issuer.ClaimsTreeRoot = &claimsTreeRootHex + revocationTreeRootHex := stateNode.Children[1].Hex() + issuer.RevocationTreeRoot = &revocationTreeRootHex + rootOfRootsHex := stateNode.Children[2].Hex() + issuer.RootOfRoots = &rootOfRootsHex + + return issuer, err +} + +func newRhsCli(rhsURL string) (*mp.ReverseHashCli, error) { + if rhsURL == "" { + return nil, errors.New("reverse hash service url is empty") + } + + return &mp.ReverseHashCli{ + URL: rhsURL, + HTTPTimeout: 10 * time.Second, + }, nil +} + +func rhsBaseURL(rhsURL string) (string, *merkletree.Hash, error) { + u, err := url.Parse(rhsURL) + if err != nil { + return "", nil, err + } + var state *merkletree.Hash + stateStr := u.Query().Get("state") + if stateStr != "" { + state, err = merkletree.NewHashFromHex(stateStr) + if err != nil { + return "", nil, err + } + } + + if strings.HasSuffix(u.Path, "/node") { + u.Path = strings.TrimSuffix(u.Path, "node") + } + if strings.HasSuffix(u.Path, "/node/") { + u.Path = strings.TrimSuffix(u.Path, "node/") + } + + u.RawQuery = "" + return u.String(), state, nil +} From d10e96150b3711eee18e3e968f4f6fefdb06f333 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 14:03:01 +0200 Subject: [PATCH 02/26] upgrade schema-processor --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e375719..9ecca10 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095 + github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index 476e771..3d446b6 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07 h1: github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112110437-1ae002a26f07/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095 h1:zdTrMCf4n0Xu1nFra8igYHRUtHSga315quJeLxqTm2Q= github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf h1:uBJE8DSujo7CMvpCVgvxhtLYAkApZWqNNVufQ7RZN1s= +github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf/go.mod h1:lCal6bZ+j4vlO6rOHBpGIxWprryZPbVXbfqIXmlL+UM= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ= From 4c57b76f57d53d54de6df3ffea95bffa11bd4dbb Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 14:14:58 +0200 Subject: [PATCH 03/26] run mod tidy --- go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.sum b/go.sum index 3d446b6..03e2282 100644 --- a/go.sum +++ b/go.sum @@ -82,10 +82,6 @@ github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0 github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= -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/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095 h1:zdTrMCf4n0Xu1nFra8igYHRUtHSga315quJeLxqTm2Q= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112113022-8b3a33d14095/go.mod h1:PZhGp+EBaCW2yPW2/Sh0wSbXIZGLfxwOnV8rs8t/ZBk= github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf h1:uBJE8DSujo7CMvpCVgvxhtLYAkApZWqNNVufQ7RZN1s= github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf/go.mod h1:lCal6bZ+j4vlO6rOHBpGIxWprryZPbVXbfqIXmlL+UM= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= From b877e70a433cd472398fe08492cdee4fc11bba5b Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 14:45:32 +0200 Subject: [PATCH 04/26] tidy tests modules --- tests/integration/go.mod | 10 +++++----- tests/integration/go.sum | 36 ++++++++++++++---------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/tests/integration/go.mod b/tests/integration/go.mod index a24ad06..237bfe5 100644 --- a/tests/integration/go.mod +++ b/tests/integration/go.mod @@ -7,7 +7,7 @@ require ( github.com/iden3/go-iden3-crypto v0.0.15 github.com/iden3/go-merkletree-sql/v2 v2.0.4 github.com/iden3/merkletree-proof v0.0.3 - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 ) require ( @@ -15,21 +15,21 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/websocket v1.4.2 // indirect + github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.12.0 // indirect golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect - golang.org/x/sys v0.9.0 // indirect + golang.org/x/sys v0.15.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/tests/integration/go.sum b/tests/integration/go.sum index d077c20..eb76c90 100644 --- a/tests/integration/go.sum +++ b/tests/integration/go.sum @@ -17,15 +17,13 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= -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/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +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= github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= github.com/ethereum/go-ethereum v1.12.2 h1:eGHJ4ij7oyVqUQn48LBz3B7pvQ8sV0wGJiIE6gDq/6Y= github.com/ethereum/go-ethereum v1.12.2/go.mod h1:1cRAEV+rp/xX0zraSCBnu9Py3HQ+geRMj3HdR+k0wfI= @@ -45,8 +43,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= 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/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= @@ -86,13 +84,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= -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= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= @@ -102,24 +95,23 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/urfave/cli/v2 v2.24.1 h1:/QYYr7g0EhwXEML8jO+8OYt5trPnLHS0p3mrgExJ5NU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +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/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +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/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= -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= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= From a48efbb1377eece0a94f8e07cea5c4ebea381f41 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 15:17:10 +0200 Subject: [PATCH 05/26] fix OnChain Resolve --- resolvers/onchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 925cbd2..1a7e789 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -22,7 +22,7 @@ type OnChainResolver struct { } // resolve is a method to resolve a credential status from the blockchain. -func (*OnChainResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { +func (OnChainResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) if err != nil { return out, err From c5463cdcdde735e4d55bd97da92ac2fbde612ab7 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 15:17:54 +0200 Subject: [PATCH 06/26] uppercase comment --- resolvers/rhs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/rhs.go b/resolvers/rhs.go index 091065a..3b5fff3 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -20,7 +20,7 @@ import ( type RHSResolver struct { } -// resolve is a method to resolve a credential status from the RHS. +// Resolve is a method to resolve a credential status from the RHS. func (RHSResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) if err != nil { From d1f493d39e7d22e86064f49659b47918717eecdb Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 12 Jan 2024 15:48:14 +0200 Subject: [PATCH 07/26] update schema-processor --- go.mod | 2 +- go.sum | 4 ++-- resolvers/onchain.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 9ecca10..fc3e1a0 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf + github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112134442-898b55d2849a github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index 03e2282..3279ddc 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0 github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf h1:uBJE8DSujo7CMvpCVgvxhtLYAkApZWqNNVufQ7RZN1s= -github.com/iden3/go-schema-processor/v2 v2.1.2-0.20240112120206-b771bd539fcf/go.mod h1:lCal6bZ+j4vlO6rOHBpGIxWprryZPbVXbfqIXmlL+UM= +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/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 1a7e789..8853599 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -21,7 +21,7 @@ import ( type OnChainResolver struct { } -// resolve is a method to resolve a credential status from the blockchain. +// Resolve is a method to resolve a credential status from the blockchain. func (OnChainResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) if err != nil { From a68dd0fd34174f62374a5a651c401bf0de32559f Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 10:51:18 +0200 Subject: [PATCH 08/26] update go-schema-processor --- go.mod | 2 +- go.sum | 2 ++ resolvers/onchain.go | 11 +++-------- resolvers/rhs.go | 14 ++++---------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index fc3e1a0..2f6e275 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - 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/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index 3279ddc..f8c15e0 100644 --- a/go.sum +++ b/go.sum @@ -84,6 +84,8 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 8853599..ce837dc 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -1,6 +1,7 @@ package resolvers import ( + "context" "encoding/hex" "fmt" "math/big" @@ -10,7 +11,6 @@ import ( "sync" core "github.com/iden3/go-iden3-core/v2" - "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/utils" "github.com/iden3/go-schema-processor/v2/verifiable" @@ -22,13 +22,8 @@ type OnChainResolver struct { } // Resolve is a method to resolve a credential status from the blockchain. -func (OnChainResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { - parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) - if err != nil { - return out, err - } - - issuerID, err := core.IDFromDID(*parsedIssuerDID) +func (OnChainResolver) Resolve(context context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*cfg.IssuerDID) if err != nil { return out, err } diff --git a/resolvers/rhs.go b/resolvers/rhs.go index 3b5fff3..4c5af11 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -9,7 +9,6 @@ import ( "time" core "github.com/iden3/go-iden3-core/v2" - "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" mp "github.com/iden3/merkletree-proof/http" @@ -21,13 +20,8 @@ type RHSResolver struct { } // Resolve is a method to resolve a credential status from the RHS. -func (RHSResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { - parsedIssuerDID, err := w3c.ParseDID(*cfg.IssuerDID) - if err != nil { - return out, err - } - - issuerID, err := core.IDFromDID(*parsedIssuerDID) +func (RHSResolver) Resolve(context context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*cfg.IssuerDID) if err != nil { return out, err } @@ -49,7 +43,7 @@ func (RHSResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.Cr return out, err } - out.Issuer, err = issuerFromRHS(context.Background(), *rhsCli, state) + out.Issuer, err = issuerFromRHS(context, *rhsCli, state) if errors.Is(err, mp.ErrNodeNotFound) { if genesisState != nil && state.Equals(genesisState) { return out, errors.New("genesis state is not found in RHS") @@ -69,7 +63,7 @@ func (RHSResolver) Resolve(status verifiable.CredentialStatus, cfg verifiable.Cr if err != nil { return out, err } - proof, err := rhsCli.GenerateProof(context.Background(), revTreeRootHash, + proof, err := rhsCli.GenerateProof(context, revTreeRootHash, revNonceHash) if err != nil { return out, err From dbc1f6b1fbb2ef79d71136d0ce51e57626e1ba0d Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 19:39:49 +0200 Subject: [PATCH 09/26] rework to eth clients --- go.mod | 2 + go.sum | 4 ++ resolvers/onchain.go | 154 +++++++++++++++++++++++++++++++++++++++---- resolvers/rhs.go | 29 ++++++-- 4 files changed, 168 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 2f6e275..cf0f69e 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,8 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect + github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 // indirect + github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 // indirect github.com/iden3/go-iden3-crypto v0.0.15 // indirect github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc // indirect github.com/ipfs/boxo v0.12.0 // indirect diff --git a/go.sum b/go.sum index f8c15e0..1929dbf 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,12 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= +github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 h1:Fu1/tAINi9FzZ0nKoEVOGXWzL1l15tR1loJx5sQEQ8k= +github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0/go.mod h1:8fkd2xyUG/V7ovpvZRyD2LyK2zZ4ALbgf5vJGyhzKdg= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 h1:/g4rru+OM5WAhVNXEpowKH+vWZLGjgpk5+O8Stu4QBo= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48/go.mod h1:kJmVPMk4HfWyl2kcta34aad/K4TAfCwB29xX9PsR7LQ= +github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 h1:iPvYa/AhhGo3juoUFDm/fBE2CZKy4WfQu7JY90tRf9Q= +github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w= github.com/iden3/go-circuits/v2 v2.0.0 h1:Bw0mpsqeip06d6I2ktgfhTVB7Jk9mSHi8myHZWkoc6w= github.com/iden3/go-iden3-core/v2 v2.0.3 h1:ce9Jbw10zDsinWXFc05SiK2Hof/wu4zV4/ai5gQy29k= github.com/iden3/go-iden3-core/v2 v2.0.3/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index ce837dc..24ae6b1 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -10,20 +10,34 @@ import ( "strings" "sync" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" + onchainABI "github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi" + "github.com/iden3/contracts-abi/state/go/abi" core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/utils" "github.com/iden3/go-schema-processor/v2/verifiable" "github.com/pkg/errors" ) -// OnChainIssuer is a struct that allows to interact with the onchain contract and build the revocation status. +// OnChainResolverConfig options for credential status verification +type OnChainResolverConfig struct { + EthClients map[core.ChainID]*ethclient.Client + StateContractAddr common.Address + IssuerDID *w3c.DID +} + +// OnChainResolver is a struct that allows to interact with the onchain contract and build the revocation status. type OnChainResolver struct { + config OnChainResolverConfig } // Resolve is a method to resolve a credential status from the blockchain. -func (OnChainResolver) Resolve(context context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*cfg.IssuerDID) +func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*r.config.IssuerDID) if err != nil { return out, err } @@ -33,6 +47,15 @@ func (OnChainResolver) Resolve(context context.Context, status verifiable.Creden return out, errors.New("issuer ID is empty") } + ethClient, err := getEthClientForDID(r.config.IssuerDID, r.config.EthClients) + if err != nil { + return out, err + } + contractCaller, err := onchainABI.NewOnchainCredentialStatusResolverCaller(r.config.StateContractAddr, ethClient) + if err != nil { + return out, err + } + onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID) if err != nil { return out, err @@ -45,14 +68,16 @@ func (OnChainResolver) Resolve(context context.Context, status verifiable.Creden onchainRevStatus.revNonce, status.RevocationNonce) } - isStateContractHasID, err := stateContractHasID(&issuerID, cfg.StateResolver) + isStateContractHasID, err := stateContractHasID(ctx, r.config.StateContractAddr, ethClient, &issuerID) if err != nil { return out, err } - var resp verifiable.RevocationStatus + opts := &bind.CallOpts{Context: ctx} + + var resp onchainABI.IOnchainCredentialStatusResolverCredentialStatus if isStateContractHasID { - resp, err = cfg.StateResolver.GetRevocationStatus(issuerID.BigInt(), + resp, err = contractCaller.GetRevocationStatus(opts, issuerID.BigInt(), onchainRevStatus.revNonce) if err != nil { msg := err.Error() @@ -68,7 +93,8 @@ func (OnChainResolver) Resolve(context context.Context, status verifiable.Creden return out, errors.New( "genesis state is not specified in OnChainCredentialStatus ID") } - resp, err = cfg.StateResolver.GetRevocationStatusByIDAndState( + resp, err = contractCaller.GetRevocationStatusByIdAndState( + opts, issuerID.BigInt(), onchainRevStatus.genesisState, onchainRevStatus.revNonce) if err != nil { @@ -78,7 +104,7 @@ func (OnChainResolver) Resolve(context context.Context, status verifiable.Creden } } - return resp, nil + return toRevocationStatus(resp) } func newOnchainRevStatusFromURI(stateID string) (onChainRevStatus, error) { @@ -164,7 +190,7 @@ func newIntFromBytesLE(bs []byte) *big.Int { return new(big.Int).SetBytes(utils.SwapEndianness(bs)) } -func stateContractHasID(id *core.ID, resolver verifiable.CredStatusStateResolver) (bool, error) { +func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (bool, error) { idsInStateContractLock.RLock() ok := idsInStateContract[*id] @@ -181,7 +207,7 @@ func stateContractHasID(id *core.ID, resolver verifiable.CredStatusStateResolver return ok, nil } - _, err := lastStateFromContract(resolver, id) + _, err := lastStateFromContract(ctx, stateAddr, ethClient, id) if errors.Is(err, errIdentityDoesNotExist) { return false, nil } else if err != nil { @@ -218,23 +244,123 @@ func isErrIdentityDoesNotExist(err error) bool { var idsInStateContract = map[core.ID]bool{} var idsInStateContractLock sync.RWMutex -func lastStateFromContract(resolver verifiable.CredStatusStateResolver, +func lastStateFromContract(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (*merkletree.Hash, error) { var zeroID core.ID if id == nil || *id == zeroID { return nil, errors.New("ID is empty") } - resp, err := resolver.GetStateInfoByID(id.BigInt()) + contractCaller, err := abi.NewStateCaller(stateAddr, ethClient) + if err != nil { + return nil, err + } + + opts := &bind.CallOpts{Context: ctx} + resp, err := contractCaller.GetStateInfoById(opts, id.BigInt()) if isErrIdentityDoesNotExist(err) { return nil, errIdentityDoesNotExist } else if err != nil { return nil, err } - if resp.State == "" { + if resp.State == nil { return nil, errors.New("got empty state") } - return merkletree.NewHashFromString(resp.State) + return merkletree.NewHashFromBigInt(resp.State) +} + +func getEthClientForDID(did *w3c.DID, ethClients map[core.ChainID]*ethclient.Client) (*ethclient.Client, error) { + chainID, err := core.ChainIDfromDID(*did) + if err != nil { + return nil, err + } + + ethClient, ok := ethClients[chainID] + if !ok { + return nil, errors.Errorf("chain id is not registered for network %v", chainID) + } + return ethClient, nil +} + +func toRevocationStatus(status onchainABI.IOnchainCredentialStatusResolverCredentialStatus) (out verifiable.RevocationStatus, err error) { + var existence bool + var nodeAux *merkletree.NodeAux + + if status.Mtp.Existence { + existence = true + } else { + existence = false + if status.Mtp.AuxExistence { + nodeAux = &merkletree.NodeAux{} + nodeAux.Key, err = merkletree.NewHashFromBigInt(status.Mtp.AuxIndex) + if err != nil { + return out, errors.New("aux index is not a number") + } + nodeAux.Value, err = merkletree.NewHashFromBigInt(status.Mtp.AuxValue) + if err != nil { + return out, errors.New("aux value is not a number") + } + } + } + + depth := calculateDepth(status.Mtp.Siblings) + allSiblings := make([]*merkletree.Hash, depth) + for i := 0; i < depth; i++ { + sh, err := merkletree.NewHashFromBigInt(status.Mtp.Siblings[i]) + if err != nil { + return out, errors.New("sibling is not a number") + } + allSiblings[i] = sh + } + + proof, err := merkletree.NewProofFromData(existence, allSiblings, nodeAux) + if err != nil { + return out, errors.New("failed to create proof") + } + + state, err := merkletree.NewHashFromBigInt(status.Issuer.State) + if err != nil { + return out, errors.New("state is not a number") + } + + claimsRoot, err := merkletree.NewHashFromBigInt(status.Issuer.ClaimsTreeRoot) + if err != nil { + return out, errors.New("state is not a number") + } + + revocationRoot, err := merkletree.NewHashFromBigInt(status.Issuer.RevocationTreeRoot) + if err != nil { + return out, errors.New("state is not a number") + } + + rootOfRoots, err := merkletree.NewHashFromBigInt(status.Issuer.RootOfRoots) + if err != nil { + return out, errors.New("state is not a number") + } + + stateHex := state.Hex() + claimsRootHex := claimsRoot.Hex() + revocationRootHex := revocationRoot.Hex() + rootOfRootsHex := rootOfRoots.Hex() + + return verifiable.RevocationStatus{ + MTP: *proof, + Issuer: verifiable.Issuer{ + State: &stateHex, + ClaimsTreeRoot: &claimsRootHex, + RevocationTreeRoot: &revocationRootHex, + RootOfRoots: &rootOfRootsHex, + }, + }, nil +} + +func calculateDepth(siblings []*big.Int) int { + for i := len(siblings) - 1; i >= 0; i-- { + if siblings[i].Cmp(big.NewInt(0)) != 0 { + return i + 1 + } + } + return 0 } diff --git a/resolvers/rhs.go b/resolvers/rhs.go index 4c5af11..33be37c 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -8,20 +8,31 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" mp "github.com/iden3/merkletree-proof/http" "github.com/pkg/errors" ) +// RHSResolverConfig options for credential status verification +type RHSResolverConfig struct { + EthClients map[core.ChainID]*ethclient.Client + StateContractAddr common.Address + IssuerDID *w3c.DID +} + // RHSResolver is a struct that allows to interact with the RHS service to get revocation status. type RHSResolver struct { + config RHSResolverConfig } // Resolve is a method to resolve a credential status from the RHS. -func (RHSResolver) Resolve(context context.Context, status verifiable.CredentialStatus, cfg verifiable.CredentialStatusConfig) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*cfg.IssuerDID) +func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*r.config.IssuerDID) if err != nil { return out, err } @@ -33,7 +44,11 @@ func (RHSResolver) Resolve(context context.Context, status verifiable.Credential return out, err } - state, err := identityStateForRHS(cfg.StateResolver, &issuerID, genesisState) + ethClient, err := getEthClientForDID(r.config.IssuerDID, r.config.EthClients) + if err != nil { + return out, err + } + state, err := identityStateForRHS(ctx, r.config.StateContractAddr, ethClient, &issuerID, genesisState) if err != nil { return out, err } @@ -43,7 +58,7 @@ func (RHSResolver) Resolve(context context.Context, status verifiable.Credential return out, err } - out.Issuer, err = issuerFromRHS(context, *rhsCli, state) + out.Issuer, err = issuerFromRHS(ctx, *rhsCli, state) if errors.Is(err, mp.ErrNodeNotFound) { if genesisState != nil && state.Equals(genesisState) { return out, errors.New("genesis state is not found in RHS") @@ -63,7 +78,7 @@ func (RHSResolver) Resolve(context context.Context, status verifiable.Credential if err != nil { return out, err } - proof, err := rhsCli.GenerateProof(context, revTreeRootHash, + proof, err := rhsCli.GenerateProof(ctx, revTreeRootHash, revNonceHash) if err != nil { return out, err @@ -74,10 +89,10 @@ func (RHSResolver) Resolve(context context.Context, status verifiable.Credential return out, nil } -func identityStateForRHS(resolver verifiable.CredStatusStateResolver, issuerID *core.ID, +func identityStateForRHS(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, issuerID *core.ID, genesisState *merkletree.Hash) (*merkletree.Hash, error) { - state, err := lastStateFromContract(resolver, issuerID) + state, err := lastStateFromContract(ctx, stateAddr, ethClient, issuerID) if !errors.Is(err, errIdentityDoesNotExist) { return state, err } From 9ce688ce45d7166afca3b998ede6321f7cd8c570 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 20:04:22 +0200 Subject: [PATCH 10/26] add rhs test --- resolvers/rhs.go | 24 ++++++++++++++++++++ resolvers/rhs_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 resolvers/rhs_test.go diff --git a/resolvers/rhs.go b/resolvers/rhs.go index 33be37c..b550a03 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -25,6 +25,30 @@ type RHSResolverConfig struct { IssuerDID *w3c.DID } +// RHSResolverOpts returns configuration options for AgentResolverOpts +type RHSResolverOpts func(opts *RHSResolverConfig) + +// WithEthClients return new options +func WithEthClients(ethClients map[core.ChainID]*ethclient.Client) RHSResolverOpts { + return func(opts *RHSResolverConfig) { + opts.EthClients = ethClients + } +} + +// WithStateContractAddr return new options +func WithStateContractAddr(address common.Address) RHSResolverOpts { + return func(opts *RHSResolverConfig) { + opts.StateContractAddr = address + } +} + +// WithIssuerDID return new options +func WithIssuerDID(issuerDID *w3c.DID) RHSResolverOpts { + return func(opts *RHSResolverConfig) { + opts.IssuerDID = issuerDID + } +} + // RHSResolver is a struct that allows to interact with the RHS service to get revocation status. type RHSResolver struct { config RHSResolverConfig diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go new file mode 100644 index 0000000..ee542af --- /dev/null +++ b/resolvers/rhs_test.go @@ -0,0 +1,51 @@ +package resolvers + +import ( + "context" + "encoding/json" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" + "github.com/iden3/go-schema-processor/v2/verifiable" + "github.com/stretchr/testify/require" +) + +func TestRhsResolver(t *testing.T) { + credStatusJSON := `{ + "id": "https://rhs-staging.polygonid.me/node?state=f9dd6aa4e1abef52b6c94ab7eb92faf1a283b371d263e25ac835c9c04894741e", + "revocationNonce": 0, + "statusIssuer": { + "id": "https://ad40-91-210-251-7.ngrok-free.app/api/v1/identities/did%3Apolygonid%3Apolygon%3Amumbai%3A2qLGnFZiHrhdNh5KwdkGvbCN1sR2pUaBpBahAXC3zf/claims/revocation/status/0", + "revocationNonce": 0, + "type": "SparseMerkleTreeProof" + }, + "type": "Iden3ReverseSparseMerkleTreeProof" + }` + + var credStatus verifiable.CredentialStatus + err := json.Unmarshal([]byte(credStatusJSON), &credStatus) + require.NoError(t, err) + + issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qLGnFZiHrhdNh5KwdkGvbCN1sR2pUaBpBahAXC3zf") + require.NoError(t, err) + stateAddr := common.HexToAddress("0x134B1BE34911E39A8397ec6289782989729807a4") + client, err := ethclient.Dial("") + require.NoError(t, err) + var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) + ethClients[80001] = client + + opts := []RHSResolverOpts{WithEthClients(ethClients), WithIssuerDID(issuerDID), WithStateContractAddr(stateAddr)} + + config := RHSResolverConfig{} + for _, o := range opts { + o(&config) + } + + rhsResolver := RHSResolver{config} + _, err = rhsResolver.Resolve(context.Background(), credStatus) + require.NoError(t, err) + +} From 14cf5076ed9fbea3840d9e3202c99ca6c95ff911 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 20:18:06 +0200 Subject: [PATCH 11/26] mock RPC call in RHS test --- go.mod | 1 + go.sum | 1 + resolvers/rhs_test.go | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cf0f69e..8ca6d53 100644 --- a/go.mod +++ b/go.mod @@ -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/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect diff --git a/go.sum b/go.sum index 1929dbf..4d80ded 100644 --- a/go.sum +++ b/go.sum @@ -100,6 +100,7 @@ github.com/ipfs/go-ipfs-api v0.7.0 h1:CMBNCUl0b45coC+lQCXEVpMhwoqjiaCwUIrM+coYW2 github.com/ipfs/go-ipfs-api v0.7.0/go.mod h1:AIxsTNB0+ZhkqIfTZpdZ0VR/cpX5zrXjATa3prSay3g= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= 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/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= 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= diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index ee542af..de88fb0 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -10,6 +10,7 @@ import ( core "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-schema-processor/v2/verifiable" + "github.com/jarcoal/httpmock" "github.com/stretchr/testify/require" ) @@ -32,7 +33,18 @@ func TestRhsResolver(t *testing.T) { issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qLGnFZiHrhdNh5KwdkGvbCN1sR2pUaBpBahAXC3zf") require.NoError(t, err) stateAddr := common.HexToAddress("0x134B1BE34911E39A8397ec6289782989729807a4") - client, err := ethclient.Dial("") + + httpmock.Activate() + defer httpmock.DeactivateAndReset() + + httpmock.RegisterMatcherResponder("POST", "http://my-rpc/v2/1111", + httpmock.BodyContainsString(`{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"data":"0xb4bdea550010961e749448c0c935c85ae263d271b383a2f1fa92ebb74ac9b652efab1202","from":"0x0000000000000000000000000000000000000000","to":"0x134b1be34911e39a8397ec6289782989729807a4"},"latest"]}`), + httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":1,"result":"0x0010961e749448c0c935c85ae263d271b383a2f1fa92ebb74ac9b652efab120209444d55300819a07594d731c0bf7d3713f5e9324e0435f926c3ef1d8e4a823400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065846207000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000029cf4ff0000000000000000000000000000000000000000000000000000000000000000"}`)) + + httpmock.RegisterResponder("GET", "https://rhs-staging.polygonid.me/node/34824a8e1defc326f935044e32e9f513377dbfc031d79475a0190830554d4409", + httpmock.NewStringResponder(200, `{"node":{"hash":"34824a8e1defc326f935044e32e9f513377dbfc031d79475a0190830554d4409","children":["4436ea12d352ddb84d2ac7a27bbf7c9f1bfc7d3ff69f3e6cf4348f424317fd0b","0000000000000000000000000000000000000000000000000000000000000000","37eabc712cdaa64793561b16b8143f56f149ad1b0c35297a1b125c765d1c071e"]},"status":"OK"}`)) + + client, err := ethclient.Dial("http://my-rpc/v2/1111") require.NoError(t, err) var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) ethClients[80001] = client From 8a2b1049d84ca4e6c91da07838918b08323c7d46 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 16 Jan 2024 20:38:10 +0200 Subject: [PATCH 12/26] fix onchainABI address --- resolvers/onchain.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 24ae6b1..07709d5 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -51,12 +51,13 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti if err != nil { return out, err } - contractCaller, err := onchainABI.NewOnchainCredentialStatusResolverCaller(r.config.StateContractAddr, ethClient) + + onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID) if err != nil { return out, err } - onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID) + contractCaller, err := onchainABI.NewOnchainCredentialStatusResolverCaller(onchainRevStatus.contractAddress, ethClient) if err != nil { return out, err } @@ -130,7 +131,7 @@ func newOnchainRevStatusFromURI(stateID string) (onChainRevStatus, error) { if err != nil { return s, err } - s.contractAddress = contractParts[1] + s.contractAddress = common.HexToAddress(contractParts[1]) revocationNonce := uri.Query().Get("revocationNonce") if revocationNonce == "" { @@ -220,7 +221,7 @@ func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient type onChainRevStatus struct { chainID core.ChainID - contractAddress string + contractAddress common.Address revNonce uint64 genesisState *big.Int } From 8b4d1260ff827f16a968f04c5099e9bf737ea01a Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Wed, 17 Jan 2024 12:14:19 +0200 Subject: [PATCH 13/26] add onchain resolver unit test --- go.mod | 6 ++-- go.sum | 3 +- resolvers/onchain_test.go | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 resolvers/onchain_test.go diff --git a/go.mod b/go.mod index 8ca6d53..ce999ed 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,13 @@ go 1.19 require ( github.com/ethereum/go-ethereum v1.12.2 + github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 + github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 + github.com/jarcoal/httpmock v1.3.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 ) @@ -28,14 +31,11 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect - github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 // indirect - github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 // indirect github.com/iden3/go-iden3-crypto v0.0.15 // indirect github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc // 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/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect diff --git a/go.sum b/go.sum index 4d80ded..722c38a 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,6 @@ github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0 github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= -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/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= @@ -124,6 +122,7 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= 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= diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go new file mode 100644 index 0000000..4c02d06 --- /dev/null +++ b/resolvers/onchain_test.go @@ -0,0 +1,65 @@ +package resolvers + +import ( + "context" + "encoding/json" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" + "github.com/iden3/go-schema-processor/v2/verifiable" + "github.com/jarcoal/httpmock" + "github.com/stretchr/testify/require" +) + +func TestOnChainResolver(t *testing.T) { + credStatusJSON := `{ + "id": "did:polygonid:polygon:mumbai:2qHjMLYdcnQ39SFXLhujJe35ZRm9X8zcqUo3nR7PJ9/credentialStatus?revocationNonce=2407271101&contractAddress=80001:0x76EB7216F2400aC18C842D8C76739F3B8E619DB9&state=325723250b520e12a42b26330144a8462b45245a498af755f1cb925580340c0f", + "revocationNonce": 2407271101, + "type": "Iden3OnchainSparseMerkleTreeProof2023" + }` + + var credStatus verifiable.CredentialStatus + err := json.Unmarshal([]byte(credStatusJSON), &credStatus) + require.NoError(t, err) + + issuerDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qHjMLYdcnQ39SFXLhujJe35ZRm9X8zcqUo3nR7PJ9") + require.NoError(t, err) + stateAddr := common.HexToAddress("0x134B1BE34911E39A8397ec6289782989729807a4") + client, err := ethclient.Dial("http://my-rpc/v2/1111") + require.NoError(t, err) + var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) + ethClients[80001] = client + + config := OnChainResolverConfig{ + IssuerDID: issuerDID, + EthClients: ethClients, + StateContractAddr: stateAddr, + } + + onChainResolver := OnChainResolver{config} + + httpmock.Activate() + defer httpmock.DeactivateAndReset() + + httpmock.RegisterMatcherResponder("POST", "http://my-rpc/v2/1111", + httpmock.BodyContainsString(`{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"data":"0xb4bdea55000af701e50b7414a0d1e05669487bf90a4e61fa7e031a73070a2543f1731202","from":"0x0000000000000000000000000000000000000000","to":"0x134b1be34911e39a8397ec6289782989729807a4"},"latest"]}`), + httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":1,"result":"0x000af701e50b7414a0d1e05669487bf90a4e61fa7e031a73070a2543f17312022f129fd9ea47a95fd13c5205e813ad32636abfb5e6d731dcf8c129d3cca880d800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065a79fd200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ac964c0000000000000000000000000000000000000000000000000000000000000000"}`)) + + httpmock.RegisterMatcherResponder("POST", "http://my-rpc/v2/1111", + httpmock.BodyContainsString(`{"jsonrpc":"2.0","id":2,"method":"eth_call","params":[{"data":"0x110c96a7000af701e50b7414a0d1e05669487bf90a4e61fa7e031a73070a2543f1731202000000000000000000000000000000000000000000000000000000008f7c0abd","from":"0x0000000000000000000000000000000000000000","to":"0x76eb7216f2400ac18c842d8c76739f3b8e619db9"},"latest"]}`), + httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":2,"result":"0x00000000000000000000000000000000000000000000000000000000000000202f129fd9ea47a95fd13c5205e813ad32636abfb5e6d731dcf8c129d3cca880d81530b53742768d91fd4b17e9ebbd276270cf00885feee7d9a013722ead3f5cf900000000000000000000000000000000000000000000000000000000000000002e29026e7eda49f6cd839e02ca72fd0bba794804757f02007ef39dda84bfaa7f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000008f7c0abd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"} + `)) + + status, err := onChainResolver.Resolve(context.Background(), credStatus) + require.NoError(t, err) + require.NotNil(t, status) + require.Equal(t, *status.Issuer.State, "d880a8ccd329c1f8dc31d7e6b5bf6a6332ad13e805523cd15fa947ead99f122f") + require.Equal(t, *status.Issuer.RootOfRoots, "7faabf84da9df37e00027f75044879ba0bfd72ca029e83cdf649da7e6e02292e") + require.Equal(t, *status.Issuer.ClaimsTreeRoot, "f95c3fad2e7213a0d9e7ee5f8800cf706227bdebe9174bfd918d764237b53015") + require.Equal(t, *status.Issuer.RevocationTreeRoot, "0000000000000000000000000000000000000000000000000000000000000000") + require.Equal(t, status.MTP.Existence, false) + +} From 271a4836107b796b1be2b0e25f33cb6b21e344d3 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Wed, 17 Jan 2024 12:20:52 +0200 Subject: [PATCH 14/26] rm options --- resolvers/rhs.go | 31 +------------------------------ resolvers/rhs_test.go | 9 ++++----- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/resolvers/rhs.go b/resolvers/rhs.go index b550a03..c05e18c 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" core "github.com/iden3/go-iden3-core/v2" - "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" mp "github.com/iden3/merkletree-proof/http" @@ -19,35 +18,7 @@ import ( ) // RHSResolverConfig options for credential status verification -type RHSResolverConfig struct { - EthClients map[core.ChainID]*ethclient.Client - StateContractAddr common.Address - IssuerDID *w3c.DID -} - -// RHSResolverOpts returns configuration options for AgentResolverOpts -type RHSResolverOpts func(opts *RHSResolverConfig) - -// WithEthClients return new options -func WithEthClients(ethClients map[core.ChainID]*ethclient.Client) RHSResolverOpts { - return func(opts *RHSResolverConfig) { - opts.EthClients = ethClients - } -} - -// WithStateContractAddr return new options -func WithStateContractAddr(address common.Address) RHSResolverOpts { - return func(opts *RHSResolverConfig) { - opts.StateContractAddr = address - } -} - -// WithIssuerDID return new options -func WithIssuerDID(issuerDID *w3c.DID) RHSResolverOpts { - return func(opts *RHSResolverConfig) { - opts.IssuerDID = issuerDID - } -} +type RHSResolverConfig OnChainResolverConfig // RHSResolver is a struct that allows to interact with the RHS service to get revocation status. type RHSResolver struct { diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index de88fb0..ed7cd55 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -49,11 +49,10 @@ func TestRhsResolver(t *testing.T) { var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) ethClients[80001] = client - opts := []RHSResolverOpts{WithEthClients(ethClients), WithIssuerDID(issuerDID), WithStateContractAddr(stateAddr)} - - config := RHSResolverConfig{} - for _, o := range opts { - o(&config) + config := RHSResolverConfig{ + IssuerDID: issuerDID, + EthClients: ethClients, + StateContractAddr: stateAddr, } rhsResolver := RHSResolver{config} From 158dea54cefb8e9487dcf00deb0482018c2f8bf7 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Thu, 18 Jan 2024 18:28:19 +0200 Subject: [PATCH 15/26] add resolvers initializers --- resolvers/onchain.go | 5 +++++ resolvers/onchain_test.go | 2 +- resolvers/rhs.go | 5 +++++ resolvers/rhs_test.go | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 07709d5..789db1e 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -35,6 +35,11 @@ type OnChainResolver struct { config OnChainResolverConfig } +// NewOnChainResolver returns new onChain resolver +func NewOnChainResolver(config OnChainResolverConfig) *OnChainResolver { + return &OnChainResolver{config} +} + // Resolve is a method to resolve a credential status from the blockchain. func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { issuerID, err := core.IDFromDID(*r.config.IssuerDID) diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go index 4c02d06..4e0f2ce 100644 --- a/resolvers/onchain_test.go +++ b/resolvers/onchain_test.go @@ -39,7 +39,7 @@ func TestOnChainResolver(t *testing.T) { StateContractAddr: stateAddr, } - onChainResolver := OnChainResolver{config} + onChainResolver := NewOnChainResolver(config) httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/resolvers/rhs.go b/resolvers/rhs.go index c05e18c..efd262b 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -25,6 +25,11 @@ type RHSResolver struct { config RHSResolverConfig } +// NewRHSResolver returns new RHS resolver +func NewRHSResolver(config RHSResolverConfig) *RHSResolver { + return &RHSResolver{config} +} + // Resolve is a method to resolve a credential status from the RHS. func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { issuerID, err := core.IDFromDID(*r.config.IssuerDID) diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index ed7cd55..7f4b0a1 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -55,7 +55,7 @@ func TestRhsResolver(t *testing.T) { StateContractAddr: stateAddr, } - rhsResolver := RHSResolver{config} + rhsResolver := NewRHSResolver(config) _, err = rhsResolver.Resolve(context.Background(), credStatus) require.NoError(t, err) From bfedc01feb1895ca77d8dc20369dbd33c2a9ced6 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Thu, 18 Jan 2024 20:08:35 +0200 Subject: [PATCH 16/26] add resolve options --- go.mod | 2 +- go.sum | 2 ++ resolvers/onchain.go | 13 ++++++------- resolvers/onchain_test.go | 3 +-- resolvers/rhs.go | 6 +++--- resolvers/rhs_test.go | 3 +-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index ce999ed..2e16276 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116084732-b5c2484f9357 + github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240118174550-f1f74877ba9e github.com/jarcoal/httpmock v1.3.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 722c38a..bfc08a1 100644 --- a/go.sum +++ b/go.sum @@ -88,6 +88,8 @@ github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepi github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= 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.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/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 789db1e..4911ddb 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -27,7 +27,6 @@ import ( type OnChainResolverConfig struct { EthClients map[core.ChainID]*ethclient.Client StateContractAddr common.Address - IssuerDID *w3c.DID } // OnChainResolver is a struct that allows to interact with the onchain contract and build the revocation status. @@ -41,8 +40,8 @@ func NewOnChainResolver(config OnChainResolverConfig) *OnChainResolver { } // Resolve is a method to resolve a credential status from the blockchain. -func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*r.config.IssuerDID) +func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*opts.IssuerDID) if err != nil { return out, err } @@ -52,7 +51,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti return out, errors.New("issuer ID is empty") } - ethClient, err := getEthClientForDID(r.config.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(opts.IssuerDID, r.config.EthClients) if err != nil { return out, err } @@ -79,11 +78,11 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti return out, err } - opts := &bind.CallOpts{Context: ctx} + contractOpts := &bind.CallOpts{Context: ctx} var resp onchainABI.IOnchainCredentialStatusResolverCredentialStatus if isStateContractHasID { - resp, err = contractCaller.GetRevocationStatus(opts, issuerID.BigInt(), + resp, err = contractCaller.GetRevocationStatus(contractOpts, issuerID.BigInt(), onchainRevStatus.revNonce) if err != nil { msg := err.Error() @@ -100,7 +99,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti "genesis state is not specified in OnChainCredentialStatus ID") } resp, err = contractCaller.GetRevocationStatusByIdAndState( - opts, + contractOpts, issuerID.BigInt(), onchainRevStatus.genesisState, onchainRevStatus.revNonce) if err != nil { diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go index 4e0f2ce..7424492 100644 --- a/resolvers/onchain_test.go +++ b/resolvers/onchain_test.go @@ -34,7 +34,6 @@ func TestOnChainResolver(t *testing.T) { ethClients[80001] = client config := OnChainResolverConfig{ - IssuerDID: issuerDID, EthClients: ethClients, StateContractAddr: stateAddr, } @@ -53,7 +52,7 @@ func TestOnChainResolver(t *testing.T) { httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":2,"result":"0x00000000000000000000000000000000000000000000000000000000000000202f129fd9ea47a95fd13c5205e813ad32636abfb5e6d731dcf8c129d3cca880d81530b53742768d91fd4b17e9ebbd276270cf00885feee7d9a013722ead3f5cf900000000000000000000000000000000000000000000000000000000000000002e29026e7eda49f6cd839e02ca72fd0bba794804757f02007ef39dda84bfaa7f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000008f7c0abd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"} `)) - status, err := onChainResolver.Resolve(context.Background(), credStatus) + status, err := onChainResolver.Resolve(context.Background(), credStatus, &verifiable.CredentialStatusResolveOptions{IssuerDID: issuerDID}) require.NoError(t, err) require.NotNil(t, status) require.Equal(t, *status.Issuer.State, "d880a8ccd329c1f8dc31d7e6b5bf6a6332ad13e805523cd15fa947ead99f122f") diff --git a/resolvers/rhs.go b/resolvers/rhs.go index efd262b..ab16cdd 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -31,8 +31,8 @@ func NewRHSResolver(config RHSResolverConfig) *RHSResolver { } // Resolve is a method to resolve a credential status from the RHS. -func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*r.config.IssuerDID) +func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) { + issuerID, err := core.IDFromDID(*opts.IssuerDID) if err != nil { return out, err } @@ -44,7 +44,7 @@ func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialSt return out, err } - ethClient, err := getEthClientForDID(r.config.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(opts.IssuerDID, r.config.EthClients) if err != nil { return out, err } diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index 7f4b0a1..312f3f9 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -50,13 +50,12 @@ func TestRhsResolver(t *testing.T) { ethClients[80001] = client config := RHSResolverConfig{ - IssuerDID: issuerDID, EthClients: ethClients, StateContractAddr: stateAddr, } rhsResolver := NewRHSResolver(config) - _, err = rhsResolver.Resolve(context.Background(), credStatus) + _, err = rhsResolver.Resolve(context.Background(), credStatus, &verifiable.CredentialStatusResolveOptions{IssuerDID: issuerDID}) require.NoError(t, err) } From c68b9896140355ac4c6b27e32c43f31b8dcb76ab Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Fri, 19 Jan 2024 13:17:25 +0200 Subject: [PATCH 17/26] use CredentialStatusResolveOpt... --- go.mod | 2 +- go.sum | 2 ++ resolvers/onchain.go | 10 +++++++--- resolvers/onchain_test.go | 3 ++- resolvers/rhs.go | 11 ++++++++--- resolvers/rhs_test.go | 3 ++- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 2e16276..ae8106e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - 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/jarcoal/httpmock v1.3.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index bfc08a1..14438ba 100644 --- a/go.sum +++ b/go.sum @@ -90,6 +90,8 @@ 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.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/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 4911ddb..9747bdf 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -40,8 +40,12 @@ func NewOnChainResolver(config OnChainResolverConfig) *OnChainResolver { } // Resolve is a method to resolve a credential status from the blockchain. -func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*opts.IssuerDID) +func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { + config := verifiable.CredentialStatusResolveConfig{} + for _, o := range opts { + o(&config) + } + issuerID, err := core.IDFromDID(*config.IssuerDID) if err != nil { return out, err } @@ -51,7 +55,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti return out, errors.New("issuer ID is empty") } - ethClient, err := getEthClientForDID(opts.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(config.IssuerDID, r.config.EthClients) if err != nil { return out, err } diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go index 7424492..f7e511b 100644 --- a/resolvers/onchain_test.go +++ b/resolvers/onchain_test.go @@ -52,7 +52,8 @@ func TestOnChainResolver(t *testing.T) { httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":2,"result":"0x00000000000000000000000000000000000000000000000000000000000000202f129fd9ea47a95fd13c5205e813ad32636abfb5e6d731dcf8c129d3cca880d81530b53742768d91fd4b17e9ebbd276270cf00885feee7d9a013722ead3f5cf900000000000000000000000000000000000000000000000000000000000000002e29026e7eda49f6cd839e02ca72fd0bba794804757f02007ef39dda84bfaa7f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000008f7c0abd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"} `)) - status, err := onChainResolver.Resolve(context.Background(), credStatus, &verifiable.CredentialStatusResolveOptions{IssuerDID: issuerDID}) + resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID)} + status, err := onChainResolver.Resolve(context.Background(), credStatus, resolveOpts...) require.NoError(t, err) require.NotNil(t, status) require.Equal(t, *status.Issuer.State, "d880a8ccd329c1f8dc31d7e6b5bf6a6332ad13e805523cd15fa947ead99f122f") diff --git a/resolvers/rhs.go b/resolvers/rhs.go index ab16cdd..b316117 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -31,8 +31,13 @@ func NewRHSResolver(config RHSResolverConfig) *RHSResolver { } // Resolve is a method to resolve a credential status from the RHS. -func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts *verifiable.CredentialStatusResolveOptions) (out verifiable.RevocationStatus, err error) { - issuerID, err := core.IDFromDID(*opts.IssuerDID) +func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { + config := verifiable.CredentialStatusResolveConfig{} + for _, o := range opts { + o(&config) + } + + issuerID, err := core.IDFromDID(*config.IssuerDID) if err != nil { return out, err } @@ -44,7 +49,7 @@ func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialSt return out, err } - ethClient, err := getEthClientForDID(opts.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(config.IssuerDID, r.config.EthClients) if err != nil { return out, err } diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index 312f3f9..782f975 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -55,7 +55,8 @@ func TestRhsResolver(t *testing.T) { } rhsResolver := NewRHSResolver(config) - _, err = rhsResolver.Resolve(context.Background(), credStatus, &verifiable.CredentialStatusResolveOptions{IssuerDID: issuerDID}) + resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID)} + _, err = rhsResolver.Resolve(context.Background(), credStatus, resolveOpts...) require.NoError(t, err) } From 63a5654ee752bd9d041daa397d7b6f1bdd2abb28 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Fri, 26 Jan 2024 10:28:52 -0500 Subject: [PATCH 18/26] Upgrade go-schema-processor. Remove CredentialStatusResolveOpt, get issuer DID from the context instead. --- go.mod | 30 +++----------- go.sum | 85 +++++---------------------------------- resolvers/onchain.go | 17 ++++---- resolvers/onchain_test.go | 4 +- resolvers/rhs.go | 20 ++++----- resolvers/rhs_test.go | 4 +- 6 files changed, 41 insertions(+), 119 deletions(-) diff --git a/go.mod b/go.mod index ae8106e..7a1956f 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240119110812-6363011261f7 + github.com/iden3/go-schema-processor/v2 v2.2.1-0.20240126124145-b6f321093157 github.com/jarcoal/httpmock v1.3.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 @@ -17,10 +17,7 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect - github.com/benbjohnson/clock v1.3.5 // indirect - github.com/blang/semver/v4 v4.0.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.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/deckarep/golang-set/v2 v2.1.0 // indirect @@ -28,34 +25,20 @@ require ( github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.1 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect + github.com/huin/goupnp v1.2.0 // indirect github.com/iden3/go-iden3-crypto v0.0.15 // indirect - github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc // 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/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/klauspost/compress v1.16.5 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/mr-tron/base58 v1.2.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/prometheus/client_model v0.4.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect golang.org/x/crypto v0.12.0 // indirect @@ -64,5 +47,4 @@ require ( google.golang.org/protobuf v1.30.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // 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 14438ba..83763d1 100644 --- a/go.sum +++ b/go.sum @@ -2,19 +2,13 @@ github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= -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/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= -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/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= @@ -22,8 +16,6 @@ github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5w github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -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/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= 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= @@ -34,7 +26,6 @@ github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpO github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= 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= -github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJLNCEi7YHVMkwwtfSr2k9splgdSM= github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= github.com/ethereum/go-ethereum v1.12.2 h1:eGHJ4ij7oyVqUQn48LBz3B7pvQ8sV0wGJiIE6gDq/6Y= github.com/ethereum/go-ethereum v1.12.2/go.mod h1:1cRAEV+rp/xX0zraSCBnu9Py3HQ+geRMj3HdR+k0wfI= @@ -47,16 +38,14 @@ github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= -github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= 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/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= @@ -67,91 +56,41 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= +github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 h1:Fu1/tAINi9FzZ0nKoEVOGXWzL1l15tR1loJx5sQEQ8k= github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0/go.mod h1:8fkd2xyUG/V7ovpvZRyD2LyK2zZ4ALbgf5vJGyhzKdg= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48 h1:/g4rru+OM5WAhVNXEpowKH+vWZLGjgpk5+O8Stu4QBo= github.com/iden3/contracts-abi/rhs-storage/go/abi v0.0.0-20231006141557-7d13ef7e3c48/go.mod h1:kJmVPMk4HfWyl2kcta34aad/K4TAfCwB29xX9PsR7LQ= github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 h1:iPvYa/AhhGo3juoUFDm/fBE2CZKy4WfQu7JY90tRf9Q= github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w= -github.com/iden3/go-circuits/v2 v2.0.0 h1:Bw0mpsqeip06d6I2ktgfhTVB7Jk9mSHi8myHZWkoc6w= github.com/iden3/go-iden3-core/v2 v2.0.3 h1:ce9Jbw10zDsinWXFc05SiK2Hof/wu4zV4/ai5gQy29k= github.com/iden3/go-iden3-core/v2 v2.0.3/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw= github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= -github.com/iden3/go-jwz/v2 v2.0.0 h1:VsU2PrmcchPMx/V0IhamMZRNjiQYZoyJopO8K8uSZOY= github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY= github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= -github.com/iden3/go-rapidsnark/prover v0.0.10 h1:NvOfRPpex/k646UsqOcUy7a7uVl17t4ok9kWvpQg4+k= -github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0xSrBi0jqM4= -github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= -github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= -github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e h1:WeiFCrpj5pLRtSA4Mg03yTrSZhHHqN/k5b6bwxd9/tY= -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.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/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc h1:VciWdH3N9hufuIn6w/SOys8+Bzjy8LD0l1f5aN2sghE= -github.com/iden3/iden3comm/v2 v2.0.1-0.20231030214854-7a0511d0e7cc/go.mod h1:wrXoxi8eoQSLopatRW5+hYF9lDRvzGL2As9ZE88q/kA= -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.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/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= 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/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -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/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 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/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= -github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8= -github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= -github.com/lestrrat-go/jwx/v2 v2.0.12 h1:3d589+5w/b9b7S3DneICPW16AqTyYXB7VRjgluSDWeA= -github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= -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/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= -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/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= 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/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= 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= @@ -163,22 +102,19 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAm github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= +github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= -github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= @@ -190,26 +126,25 @@ golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU= golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.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/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= 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.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 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= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= 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= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 9747bdf..6946e66 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -40,12 +40,15 @@ func NewOnChainResolver(config OnChainResolverConfig) *OnChainResolver { } // Resolve is a method to resolve a credential status from the blockchain. -func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { - config := verifiable.CredentialStatusResolveConfig{} - for _, o := range opts { - o(&config) +func (r OnChainResolver) Resolve(ctx context.Context, + status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + + issuerDID := verifiable.GetIssuerDID(ctx) + if issuerDID == nil { + return out, errors.New("issuer DID is not set in context") } - issuerID, err := core.IDFromDID(*config.IssuerDID) + + issuerID, err := core.IDFromDID(*issuerDID) if err != nil { return out, err } @@ -55,7 +58,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.Credenti return out, errors.New("issuer ID is empty") } - ethClient, err := getEthClientForDID(config.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(issuerDID, r.config.EthClients) if err != nil { return out, err } @@ -356,7 +359,7 @@ func toRevocationStatus(status onchainABI.IOnchainCredentialStatusResolverCreden return verifiable.RevocationStatus{ MTP: *proof, - Issuer: verifiable.Issuer{ + Issuer: verifiable.TreeState{ State: &stateHex, ClaimsTreeRoot: &claimsRootHex, RevocationTreeRoot: &revocationRootHex, diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go index f7e511b..f66900e 100644 --- a/resolvers/onchain_test.go +++ b/resolvers/onchain_test.go @@ -52,8 +52,8 @@ func TestOnChainResolver(t *testing.T) { httpmock.NewStringResponder(200, `{"jsonrpc":"2.0","id":2,"result":"0x00000000000000000000000000000000000000000000000000000000000000202f129fd9ea47a95fd13c5205e813ad32636abfb5e6d731dcf8c129d3cca880d81530b53742768d91fd4b17e9ebbd276270cf00885feee7d9a013722ead3f5cf900000000000000000000000000000000000000000000000000000000000000002e29026e7eda49f6cd839e02ca72fd0bba794804757f02007ef39dda84bfaa7f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000008f7c0abd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"} `)) - resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID)} - status, err := onChainResolver.Resolve(context.Background(), credStatus, resolveOpts...) + ctx := verifiable.WithIssuerDID(context.Background(), issuerDID) + status, err := onChainResolver.Resolve(ctx, credStatus) require.NoError(t, err) require.NotNil(t, status) require.Equal(t, *status.Issuer.State, "d880a8ccd329c1f8dc31d7e6b5bf6a6332ad13e805523cd15fa947ead99f122f") diff --git a/resolvers/rhs.go b/resolvers/rhs.go index b316117..6ea6e18 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" - core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" mp "github.com/iden3/merkletree-proof/http" @@ -31,13 +31,15 @@ func NewRHSResolver(config RHSResolverConfig) *RHSResolver { } // Resolve is a method to resolve a credential status from the RHS. -func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus, opts ...verifiable.CredentialStatusResolveOpt) (out verifiable.RevocationStatus, err error) { - config := verifiable.CredentialStatusResolveConfig{} - for _, o := range opts { - o(&config) +func (r RHSResolver) Resolve(ctx context.Context, + status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + + issuerDID := verifiable.GetIssuerDID(ctx) + if issuerDID == nil { + return out, errors.New("issuer DID is not set in context") } - issuerID, err := core.IDFromDID(*config.IssuerDID) + issuerID, err := core.IDFromDID(*issuerDID) if err != nil { return out, err } @@ -49,7 +51,7 @@ func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialSt return out, err } - ethClient, err := getEthClientForDID(config.IssuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(issuerDID, r.config.EthClients) if err != nil { return out, err } @@ -130,9 +132,9 @@ func genesisStateMatch(state *merkletree.Hash, id core.ID) (bool, error) { } func issuerFromRHS(ctx context.Context, rhsCli mp.ReverseHashCli, - state *merkletree.Hash) (verifiable.Issuer, error) { + state *merkletree.Hash) (verifiable.TreeState, error) { - var issuer verifiable.Issuer + var issuer verifiable.TreeState stateNode, err := rhsCli.GetNode(ctx, state) if err != nil { diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index 782f975..7ab5416 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -55,8 +55,8 @@ func TestRhsResolver(t *testing.T) { } rhsResolver := NewRHSResolver(config) - resolveOpts := []verifiable.CredentialStatusResolveOpt{verifiable.WithIssuerDID(issuerDID)} - _, err = rhsResolver.Resolve(context.Background(), credStatus, resolveOpts...) + ctx := verifiable.WithIssuerDID(context.Background(), issuerDID) + _, err = rhsResolver.Resolve(ctx, credStatus) require.NoError(t, err) } From 169a09b81402d168cca6532c957eec2902fad47d Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Mon, 5 Feb 2024 05:27:00 -0500 Subject: [PATCH 19/26] do not hold an exclusive lock while performing network operations --- resolvers/onchain.go | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 6946e66..a64993e 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -204,19 +204,8 @@ func newIntFromBytesLE(bs []byte) *big.Int { func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (bool, error) { - idsInStateContractLock.RLock() - ok := idsInStateContract[*id] - idsInStateContractLock.RUnlock() - if ok { - return ok, nil - } - - idsInStateContractLock.Lock() - defer idsInStateContractLock.Unlock() - - ok = idsInStateContract[*id] - if ok { - return ok, nil + if idsInStateContract.has(*id) { + return true, nil } _, err := lastStateFromContract(ctx, stateAddr, ethClient, id) @@ -226,7 +215,7 @@ func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient return false, err } - idsInStateContract[*id] = true + idsInStateContract.add(*id) return true, err } @@ -253,8 +242,24 @@ func isErrIdentityDoesNotExist(err error) bool { return err.Error() == "execution reverted: Identity does not exist" } -var idsInStateContract = map[core.ID]bool{} -var idsInStateContractLock sync.RWMutex +type syncedIDsSet struct { + sync.RWMutex + m map[core.ID]bool +} + +func (is *syncedIDsSet) has(id core.ID) bool { + is.RLock() + defer is.RUnlock() + return is.m[id] +} + +func (is *syncedIDsSet) add(id core.ID) { + is.Lock() + defer is.Unlock() + is.m[id] = true +} + +var idsInStateContract syncedIDsSet func lastStateFromContract(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (*merkletree.Hash, error) { @@ -339,17 +344,17 @@ func toRevocationStatus(status onchainABI.IOnchainCredentialStatusResolverCreden claimsRoot, err := merkletree.NewHashFromBigInt(status.Issuer.ClaimsTreeRoot) if err != nil { - return out, errors.New("state is not a number") + return out, errors.New("claims tree root is not a number") } revocationRoot, err := merkletree.NewHashFromBigInt(status.Issuer.RevocationTreeRoot) if err != nil { - return out, errors.New("state is not a number") + return out, errors.New("revocation tree root is not a number") } rootOfRoots, err := merkletree.NewHashFromBigInt(status.Issuer.RootOfRoots) if err != nil { - return out, errors.New("state is not a number") + return out, errors.New("root of roots tree root is not a number") } stateHex := state.Hex() From 90dd276041ffa2e883056106e32393eefea9fd7b Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Mon, 5 Feb 2024 05:33:41 -0500 Subject: [PATCH 20/26] fix writing to nil map --- resolvers/onchain.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index a64993e..e335812 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -256,6 +256,9 @@ func (is *syncedIDsSet) has(id core.ID) bool { func (is *syncedIDsSet) add(id core.ID) { is.Lock() defer is.Unlock() + if is.m == nil { + is.m = make(map[core.ID]bool) + } is.m[id] = true } From 346909b2475cb1321087c8fd69002a7922e756f8 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 16:56:00 +0200 Subject: [PATCH 21/26] resolve comments --- resolvers/onchain.go | 45 ++++++++++++++++++++++++++------------- resolvers/onchain_test.go | 8 +++---- resolvers/rhs.go | 28 ++++++++++++++++-------- resolvers/rhs_test.go | 8 +++---- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index e335812..f967ba9 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -23,26 +23,28 @@ import ( "github.com/pkg/errors" ) -// OnChainResolverConfig options for credential status verification -type OnChainResolverConfig struct { - EthClients map[core.ChainID]*ethclient.Client - StateContractAddr common.Address -} - // OnChainResolver is a struct that allows to interact with the onchain contract and build the revocation status. type OnChainResolver struct { - config OnChainResolverConfig + ethClients map[core.ChainID]*ethclient.Client + stateContractAddresses map[core.ChainID]common.Address } // NewOnChainResolver returns new onChain resolver -func NewOnChainResolver(config OnChainResolverConfig) *OnChainResolver { - return &OnChainResolver{config} +func NewOnChainResolver(ethClients map[core.ChainID]*ethclient.Client, stateContractAddresses map[core.ChainID]common.Address) *OnChainResolver { + return &OnChainResolver{ + ethClients: ethClients, + stateContractAddresses: stateContractAddresses, + } } // Resolve is a method to resolve a credential status from the blockchain. func (r OnChainResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + if status.Type != verifiable.Iden3OnchainSparseMerkleTreeProof2023 { + return out, errors.New("invalid status type") + } + issuerDID := verifiable.GetIssuerDID(ctx) if issuerDID == nil { return out, errors.New("issuer DID is not set in context") @@ -50,15 +52,15 @@ func (r OnChainResolver) Resolve(ctx context.Context, issuerID, err := core.IDFromDID(*issuerDID) if err != nil { - return out, err + return out, errors.WithMessage((err), "can't parse issuer DID") } - var zeroID core.ID - if issuerID == zeroID { - return out, errors.New("issuer ID is empty") + ethClient, err := getEthClientForDID(issuerDID, r.ethClients) + if err != nil { + return out, err } - ethClient, err := getEthClientForDID(issuerDID, r.config.EthClients) + stateAddr, err := getStateContractForDID(issuerDID, r.stateContractAddresses) if err != nil { return out, err } @@ -80,7 +82,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, onchainRevStatus.revNonce, status.RevocationNonce) } - isStateContractHasID, err := stateContractHasID(ctx, r.config.StateContractAddr, ethClient, &issuerID) + isStateContractHasID, err := stateContractHasID(ctx, stateAddr, ethClient, &issuerID) if err != nil { return out, err } @@ -304,6 +306,19 @@ func getEthClientForDID(did *w3c.DID, ethClients map[core.ChainID]*ethclient.Cli return ethClient, nil } +func getStateContractForDID(did *w3c.DID, stateContracts map[core.ChainID]common.Address) (out common.Address, err error) { + chainID, err := core.ChainIDfromDID(*did) + if err != nil { + return out, err + } + + contractAddr, ok := stateContracts[chainID] + if !ok { + return out, errors.Errorf("chain id is not registered for network %v", chainID) + } + return contractAddr, nil +} + func toRevocationStatus(status onchainABI.IOnchainCredentialStatusResolverCredentialStatus) (out verifiable.RevocationStatus, err error) { var existence bool var nodeAux *merkletree.NodeAux diff --git a/resolvers/onchain_test.go b/resolvers/onchain_test.go index f66900e..7899505 100644 --- a/resolvers/onchain_test.go +++ b/resolvers/onchain_test.go @@ -33,12 +33,10 @@ func TestOnChainResolver(t *testing.T) { var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) ethClients[80001] = client - config := OnChainResolverConfig{ - EthClients: ethClients, - StateContractAddr: stateAddr, - } + var stateAddresses map[core.ChainID]common.Address = make(map[core.ChainID]common.Address) + stateAddresses[80001] = stateAddr - onChainResolver := NewOnChainResolver(config) + onChainResolver := NewOnChainResolver(ethClients, stateAddresses) httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/resolvers/rhs.go b/resolvers/rhs.go index 6ea6e18..77e9afc 100644 --- a/resolvers/rhs.go +++ b/resolvers/rhs.go @@ -10,30 +10,35 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" - "github.com/iden3/go-iden3-core/v2" + core "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" mp "github.com/iden3/merkletree-proof/http" "github.com/pkg/errors" ) -// RHSResolverConfig options for credential status verification -type RHSResolverConfig OnChainResolverConfig - // RHSResolver is a struct that allows to interact with the RHS service to get revocation status. type RHSResolver struct { - config RHSResolverConfig + ethClients map[core.ChainID]*ethclient.Client + stateContractAddresses map[core.ChainID]common.Address } // NewRHSResolver returns new RHS resolver -func NewRHSResolver(config RHSResolverConfig) *RHSResolver { - return &RHSResolver{config} +func NewRHSResolver(ethClients map[core.ChainID]*ethclient.Client, stateContractAddresses map[core.ChainID]common.Address) *RHSResolver { + return &RHSResolver{ + ethClients: ethClients, + stateContractAddresses: stateContractAddresses, + } } // Resolve is a method to resolve a credential status from the RHS. func (r RHSResolver) Resolve(ctx context.Context, status verifiable.CredentialStatus) (out verifiable.RevocationStatus, err error) { + if status.Type != verifiable.Iden3ReverseSparseMerkleTreeProof { + return out, errors.New("invalid status type") + } + issuerDID := verifiable.GetIssuerDID(ctx) if issuerDID == nil { return out, errors.New("issuer DID is not set in context") @@ -51,11 +56,16 @@ func (r RHSResolver) Resolve(ctx context.Context, return out, err } - ethClient, err := getEthClientForDID(issuerDID, r.config.EthClients) + ethClient, err := getEthClientForDID(issuerDID, r.ethClients) + if err != nil { + return out, err + } + + stateAddr, err := getStateContractForDID(issuerDID, r.stateContractAddresses) if err != nil { return out, err } - state, err := identityStateForRHS(ctx, r.config.StateContractAddr, ethClient, &issuerID, genesisState) + state, err := identityStateForRHS(ctx, stateAddr, ethClient, &issuerID, genesisState) if err != nil { return out, err } diff --git a/resolvers/rhs_test.go b/resolvers/rhs_test.go index 7ab5416..ed388c7 100644 --- a/resolvers/rhs_test.go +++ b/resolvers/rhs_test.go @@ -49,12 +49,10 @@ func TestRhsResolver(t *testing.T) { var ethClients map[core.ChainID]*ethclient.Client = make(map[core.ChainID]*ethclient.Client) ethClients[80001] = client - config := RHSResolverConfig{ - EthClients: ethClients, - StateContractAddr: stateAddr, - } + var stateAddresses map[core.ChainID]common.Address = make(map[core.ChainID]common.Address) + stateAddresses[80001] = stateAddr - rhsResolver := NewRHSResolver(config) + rhsResolver := NewRHSResolver(ethClients, stateAddresses) ctx := verifiable.WithIssuerDID(context.Background(), issuerDID) _, err = rhsResolver.Resolve(ctx, credStatus) require.NoError(t, err) From 33166dd06764700eb7bace03800892c127cefe48 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 17:12:20 +0200 Subject: [PATCH 22/26] add rev nonce match check --- resolvers/onchain.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index f967ba9..07d268f 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -65,7 +65,7 @@ func (r OnChainResolver) Resolve(ctx context.Context, return out, err } - onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID) + onchainRevStatus, err := newOnchainRevStatusFromURI(status.ID, status.RevocationNonce) if err != nil { return out, err } @@ -121,10 +121,10 @@ func (r OnChainResolver) Resolve(ctx context.Context, return toRevocationStatus(resp) } -func newOnchainRevStatusFromURI(stateID string) (onChainRevStatus, error) { +func newOnchainRevStatusFromURI(statusID string, statusRevNonce uint64) (onChainRevStatus, error) { var s onChainRevStatus - uri, err := url.Parse(stateID) + uri, err := url.Parse(statusID) if err != nil { return s, errors.New("OnChainCredentialStatus ID is not a valid URI") } @@ -146,16 +146,20 @@ func newOnchainRevStatusFromURI(stateID string) (onChainRevStatus, error) { } s.contractAddress = common.HexToAddress(contractParts[1]) - revocationNonce := uri.Query().Get("revocationNonce") - if revocationNonce == "" { - return s, errors.New("revocationNonce is empty in OnChainCredentialStatus ID") - } + queryRevNonceString := uri.Query().Get("revocationNonce") + if queryRevNonceString != "" { + queryRevNonce, err := strconv.ParseUint(queryRevNonceString, 10, 64) + if err != nil { + return s, errors.New("query revocationNonce is not a number in OnChainCredentialStatus ID") + } + if queryRevNonce != statusRevNonce { + return s, errors.New("query revocation nonce doesn't match with credential status nonce") + } - s.revNonce, err = strconv.ParseUint(revocationNonce, 10, 64) - if err != nil { - return s, errors.New("revocationNonce is not a number in OnChainCredentialStatus ID") } + s.revNonce = statusRevNonce + // state may be nil if params is absent in query s.genesisState, err = newIntFromHexQueryParam(uri, "state") if err != nil { From e1df98f6903eb3314d7c4a48c50b288e06be421e Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 17:20:18 +0200 Subject: [PATCH 23/26] fix trimSuffix --- resolvers/onchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 07d268f..8f97328 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -195,7 +195,7 @@ func newIntFromHexQueryParam(uri *url.URL, paramName string) (*big.Int, error) { return nil, nil } - stateParam = strings.TrimSuffix(stateParam, "0x") + stateParam = strings.TrimPrefix(stateParam, "0x") stateBytes, err := hex.DecodeString(stateParam) if err != nil { return nil, err From 011dfe721e90ad0c2b5495058d5c41d2d6ab03c8 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 5 Feb 2024 17:54:24 +0200 Subject: [PATCH 24/26] assertUnderlineTypeInt32 --- resolvers/onchain.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 8f97328..9cce1b4 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -170,21 +170,19 @@ func newOnchainRevStatusFromURI(statusID string, statusRevNonce uint64) (onChain } func newChainIDFromString(in string) (core.ChainID, error) { - var chainID uint64 - var err error - if strings.HasPrefix(in, "0x") || - strings.HasPrefix(in, "0X") { - chainID, err = strconv.ParseUint(in[2:], 16, 64) - if err != nil { - return 0, err - } - } else { - chainID, err = strconv.ParseUint(in, 10, 64) - if err != nil { - return 0, err - } + radix := 10 + if strings.HasPrefix(in, "0x") || strings.HasPrefix(in, "0X") { + radix = 16 + in = in[2:] } - return core.ChainID(chainID), nil + + var chainID core.ChainID + assertUnderlineTypeInt32(chainID) + i, err := strconv.ParseInt(in, radix, 32) + if err != nil { + return 0, fmt.Errorf("can't parse ChainID type: %w", err) + } + return core.ChainID(i), nil } // newIntFromHexQueryParam search for query param `paramName`, parse it @@ -403,3 +401,6 @@ func calculateDepth(siblings []*big.Int) int { } return 0 } + +// function to fail a compilation if underlined type is not int32 +func assertUnderlineTypeInt32[T ~int32](_ T) {} From 472552c7cdb8802ddbab8b8f870524466b20fdf8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 6 Feb 2024 14:19:33 +0200 Subject: [PATCH 25/26] add more context to errors --- resolvers/onchain.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resolvers/onchain.go b/resolvers/onchain.go index 9cce1b4..ca0d2ca 100644 --- a/resolvers/onchain.go +++ b/resolvers/onchain.go @@ -126,7 +126,7 @@ func newOnchainRevStatusFromURI(statusID string, statusRevNonce uint64) (onChain uri, err := url.Parse(statusID) if err != nil { - return s, errors.New("OnChainCredentialStatus ID is not a valid URI") + return s, errors.Wrapf(err, "OnChainCredentialStatus ID is not a valid URI") } contract := uri.Query().Get("contractAddress") @@ -136,8 +136,8 @@ func newOnchainRevStatusFromURI(statusID string, statusRevNonce uint64) (onChain contractParts := strings.Split(contract, ":") if len(contractParts) != 2 { - return s, errors.New( - "OnChainCredentialStatus contract address is not valid") + return s, errors.Errorf( + "OnChainCredentialStatus contract address '%s' is not valid", contract) } s.chainID, err = newChainIDFromString(contractParts[0]) @@ -303,7 +303,7 @@ func getEthClientForDID(did *w3c.DID, ethClients map[core.ChainID]*ethclient.Cli ethClient, ok := ethClients[chainID] if !ok { - return nil, errors.Errorf("chain id is not registered for network %v", chainID) + return nil, errors.Errorf("chain id is not registered for network '%d'", chainID) } return ethClient, nil } @@ -316,7 +316,7 @@ func getStateContractForDID(did *w3c.DID, stateContracts map[core.ChainID]common contractAddr, ok := stateContracts[chainID] if !ok { - return out, errors.Errorf("chain id is not registered for network %v", chainID) + return out, errors.Errorf("chain id is not registered for network '%d'", chainID) } return contractAddr, nil } From f3cc97be8c0fe2993e5682b88eb8a9b6d4e84075 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 6 Feb 2024 15:24:33 +0200 Subject: [PATCH 26/26] upgrade go-schema-processor/v2 to 2.3.p --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7a1956f..c691914 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-iden3-core/v2 v2.0.3 github.com/iden3/go-merkletree-sql/v2 v2.0.4 - 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/jarcoal/httpmock v1.3.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 83763d1..69f4890 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,8 @@ github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= 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/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=