diff --git a/.github/workflows/ci-lint.yaml b/.github/workflows/ci-lint.yaml index 14f78f2..d84dfba 100644 --- a/.github/workflows/ci-lint.yaml +++ b/.github/workflows/ci-lint.yaml @@ -12,10 +12,10 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: 1.21.0 + go-version: 1.21.7 - name: Checkout code uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.60.3 diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 607ab68..33d55ec 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -13,7 +13,7 @@ jobs: test: strategy: matrix: - containers: [ 1.20.4, 1.19, 1.18 ] + containers: [ 1.21.7 ] runs-on: ubuntu-latest container: golang:${{ matrix.containers }} steps: diff --git a/.golangci.yml b/.golangci.yml index 037f4d5..5f31576 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ service: - golangci-lint-version: 1.45.x + golangci-lint-version: 1.60.3 run: timeout: 2m diff --git a/go.mod b/go.mod index ad5a05c..60bd6ff 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/iden3/iden3comm/v2 -go 1.18 +go 1.21.7 require ( github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 diff --git a/go.sum b/go.sum index fc59d9a..ae2fa89 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,10 @@ github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= +github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= @@ -18,12 +21,19 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU= +github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= +github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= +github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= +github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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= @@ -40,14 +50,18 @@ github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0 github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJLNCEi7YHVMkwwtfSr2k9splgdSM= github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564/go.mod h1:yekO+3ZShy19S+bsmnERmznGy9Rfg6dWWWpiGJjNAz8= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= +github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/ethereum/go-ethereum v1.11.5 h1:3M1uan+LAUvdn+7wCEFrcMM4LJTeuxDrPTg/f31a5QQ= github.com/ethereum/go-ethereum v1.11.5/go.mod h1:it7x0DWnTDMfVFdXcU6Ti4KEFQynLHVRarcSlPr0HBo= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= +github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= +github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= @@ -55,12 +69,18 @@ github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= +github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -68,11 +88,14 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ 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/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= +github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= github.com/iden3/contracts-abi/state/go/abi v1.0.1 h1:FsaLJSy3NSyJl5k1yfDxc5DhUHRY7Z/UCj0/1YueMrY= github.com/iden3/contracts-abi/state/go/abi v1.0.1/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w= github.com/iden3/driver-did-iden3 v0.0.5 h1:N3B9S3CBZHqWIZWspAiq2JFaLyq0eLZf26sN3ZEMAhQ= @@ -100,15 +123,21 @@ github.com/iden3/go-rapidsnark/witness/wazero v0.0.0-20230524142950-0986cf057d4e github.com/iden3/go-schema-processor/v2 v2.5.0 h1:MX84oFb9kYq0ntKiU4DrPPaRgCDUCKlurtHB6nvPPAs= github.com/iden3/go-schema-processor/v2 v2.5.0/go.mod h1:hMqYi4lKOzEGkmCRks/r4Crj8H4G8YaTt8H4jZHzX9Y= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= +github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= +github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80= github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU= github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= @@ -123,14 +152,21 @@ github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmt github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= 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/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= @@ -144,19 +180,27 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN 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_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= +github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y= github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= +github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= +github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= 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= @@ -167,6 +211,7 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ= github.com/tetratelabs/wazero v1.1.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= @@ -174,8 +219,11 @@ github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7Am github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q= +github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= @@ -187,6 +235,7 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y 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-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= +golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -232,14 +281,17 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y= +golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/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/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-jose/go-jose.v2 v2.6.1 h1:qEzJlIDmG9q5VO0M/o8tGS65QMHMS1w01TQJB1VPJ4U= gopkg.in/go-jose/go-jose.v2 v2.6.1/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI= diff --git a/protocol/payment.go b/protocol/payment.go index 427ed1c..fce2c0a 100644 --- a/protocol/payment.go +++ b/protocol/payment.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/iden3/driver-did-iden3/pkg/document" "github.com/iden3/go-schema-processor/v2/verifiable" "github.com/pkg/errors" @@ -34,9 +35,6 @@ const ( // Iden3PaymentRailsERC20V1Type is a Iden3PaymentRailsERC20V1 payment type Iden3PaymentRailsERC20V1Type PaymentType = "Iden3PaymentRailsERC20V1" - - // Eip712SignatureProofType is a EthereumEip712Signature2021 proof type - Eip712SignatureProofType ProofType = "EthereumEip712Signature2021" ) // PaymentType is type for Payment @@ -45,9 +43,6 @@ type PaymentType string // PaymentRequestType is type for Payment request type PaymentRequestType string -// ProofType is type for Proof -type ProofType string - // PaymentRequestMessage represents Iden3message for payment request. type PaymentRequestMessage struct { ID string `json:"id"` @@ -69,147 +64,88 @@ type PaymentRequestMessageBody struct { // PaymentRequestInfo represents the payments request information. type PaymentRequestInfo struct { - Type string `json:"type,omitempty"` Credentials []PaymentRequestInfoCredentials `json:"credentials"` Description string `json:"description"` Data PaymentRequestInfoData `json:"data"` } // PaymentRequestInfoData is a union type for field Data in PaymentRequestInfo. -// Only one of the fields can be set at a time. -type PaymentRequestInfoData struct { - dataType PaymentRequestType - crypto []Iden3PaymentRequestCryptoV1 - rails []Iden3PaymentRailsRequestV1 - railsERC20 []Iden3PaymentRailsERC20RequestV1 -} - -// NewPaymentRequestInfoDataCrypto creates a new PaymentRequestInfoData with Iden3PaymentRequestCryptoV1 data. -func NewPaymentRequestInfoDataCrypto(data Iden3PaymentRequestCryptoV1) PaymentRequestInfoData { - return PaymentRequestInfoData{ - dataType: Iden3PaymentRequestCryptoV1Type, - crypto: []Iden3PaymentRequestCryptoV1{data}, - } -} - -// NewPaymentRequestInfoDataRails creates a new PaymentRequestInfoData with Iden3PaymentRailsRequestV1 data. -func NewPaymentRequestInfoDataRails(data Iden3PaymentRailsRequestV1) PaymentRequestInfoData { - return PaymentRequestInfoData{ - dataType: Iden3PaymentRailsRequestV1Type, - rails: []Iden3PaymentRailsRequestV1{data}, - } -} +type PaymentRequestInfoData []PaymentRequestInfoDataItem -// NewPaymentRequestInfoDataRailsERC20 creates a new PaymentRequestInfoData with Iden3PaymentRailsERC20RequestV1 data. -func NewPaymentRequestInfoDataRailsERC20(data Iden3PaymentRailsERC20RequestV1) PaymentRequestInfoData { - return PaymentRequestInfoData{ - dataType: Iden3PaymentRailsERC20RequestV1Type, - railsERC20: []Iden3PaymentRailsERC20RequestV1{data}, - } -} - -// Type returns the type of the data in the union. You can use Data() to get the data. -func (p *PaymentRequestInfoData) Type() PaymentRequestType { - return p.dataType -} - -// Data returns the data in the union. You can use Type() to determine the type of the data. -func (p *PaymentRequestInfoData) Data() interface{} { - switch p.dataType { - case Iden3PaymentRequestCryptoV1Type: - return p.crypto - case Iden3PaymentRailsRequestV1Type: - return p.rails - case Iden3PaymentRailsERC20RequestV1Type: - return p.railsERC20 - } - return nil +// PaymentRequestInfoDataItem is the interface that any PaymentRequestInfoData.Data item must implement. +type PaymentRequestInfoDataItem interface { + PaymentRequestType() PaymentRequestType } // MarshalJSON marshals the PaymentRequestInfoData into JSON. func (p PaymentRequestInfoData) MarshalJSON() ([]byte, error) { - switch p.dataType { - case Iden3PaymentRequestCryptoV1Type: - return json.Marshal(p.crypto[0]) - case Iden3PaymentRailsRequestV1Type: - return json.Marshal(p.rails) - case Iden3PaymentRailsERC20RequestV1Type: - return json.Marshal(p.railsERC20) + if len(p) == 1 && p[0].PaymentRequestType() == Iden3PaymentRequestCryptoV1Type { + return json.Marshal(p[0]) } - return nil, errors.New("failed to marshal not initialized PaymentRequestInfoData") + return json.Marshal([]PaymentRequestInfoDataItem(p)) } // UnmarshalJSON unmarshal the PaymentRequestInfoData from JSON. func (p *PaymentRequestInfoData) UnmarshalJSON(data []byte) error { - var item struct { - Type PaymentRequestType `json:"type"` - } - var collection []struct { + type rawItem struct { Type PaymentRequestType `json:"type"` } - p.crypto, p.rails, p.railsERC20 = nil, nil, nil + var item rawItem + var collection []json.RawMessage - if err := json.Unmarshal(data, &item); err == nil { - p.dataType = item.Type - return p.unmarshalFromItem(item.Type, data) + // Let's see if this is a single item + err := json.Unmarshal(data, &item) + if err == nil { + o, errItem := p.unmarshalFromItem(item.Type, data) + if errItem != nil { + return errItem + } + *p = append(*p, o) + return nil } - if err := json.Unmarshal(data, &collection); err == nil { - if len(collection) == 0 { - return nil + // Let's see if this is a collection. Then we will unmarshal each single item + err = json.Unmarshal(data, &collection) + if err != nil { + return fmt.Errorf("PaymentRequestInfoData must be a PaymentRequestInfoDataItem or a collection: %w", err) + } + for n, rawItem := range collection { + if err := json.Unmarshal(rawItem, &item); err != nil { + return fmt.Errorf("field PaymentRequestInfoData[%d].Type not found: %w", n, err) } - - p.dataType = collection[0].Type - return p.unmarshalFromCollection(p.dataType, data) + o, err := p.unmarshalFromItem(item.Type, rawItem) + if err != nil { + return err + } + *p = append(*p, o) } - return errors.New("failed to unmarshal PaymentRequestInfoData. not a single item nor a collection") + return nil } -func (p *PaymentRequestInfoData) unmarshalFromItem(typ PaymentRequestType, data []byte) error { +func (p *PaymentRequestInfoData) unmarshalFromItem(typ PaymentRequestType, data []byte) (PaymentRequestInfoDataItem, error) { switch typ { case Iden3PaymentRequestCryptoV1Type: var o Iden3PaymentRequestCryptoV1 if err := json.Unmarshal(data, &o); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) + return nil, fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) } - p.crypto = []Iden3PaymentRequestCryptoV1{o} + return o, nil case Iden3PaymentRailsRequestV1Type: var o Iden3PaymentRailsRequestV1 if err := json.Unmarshal(data, &o); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) + return nil, fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) } - p.rails = []Iden3PaymentRailsRequestV1{o} + return o, nil case Iden3PaymentRailsERC20RequestV1Type: var o Iden3PaymentRailsERC20RequestV1 if err := json.Unmarshal(data, &o); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) - } - p.railsERC20 = []Iden3PaymentRailsERC20RequestV1{o} - default: - return errors.Errorf("unmarshalling PaymentRequestInfoData. unknown type: %s", typ) - } - return nil -} - -func (p *PaymentRequestInfoData) unmarshalFromCollection(typ PaymentRequestType, data []byte) error { - switch typ { - case Iden3PaymentRequestCryptoV1Type: - if err := json.Unmarshal(data, &p.crypto); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) - } - case Iden3PaymentRailsRequestV1Type: - if err := json.Unmarshal(data, &p.rails); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) - } - case Iden3PaymentRailsERC20RequestV1Type: - if err := json.Unmarshal(data, &p.railsERC20); err != nil { - return fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) + return nil, fmt.Errorf("unmarshalling PaymentRequestInfoData: %w", err) } + return o, nil default: - return errors.Errorf("unmarshalling PaymentRequestInfoData. unknown type: %s", typ) + return nil, errors.Errorf("unmarshalling PaymentRequestInfoData. unknown type: %s", typ) } - return nil } // Iden3PaymentRequestCryptoV1 represents the Iden3PaymentRequestCryptoV1 payment request data. @@ -224,6 +160,11 @@ type Iden3PaymentRequestCryptoV1 struct { Expiration string `json:"expiration,omitempty"` } +// PaymentRequestType implements the PaymentRequestInfoDataItem interface. +func (i Iden3PaymentRequestCryptoV1) PaymentRequestType() PaymentRequestType { + return Iden3PaymentRequestCryptoV1Type +} + // Iden3PaymentRailsRequestV1 represents the Iden3PaymentRailsRequestV1 payment request data. type Iden3PaymentRailsRequestV1 struct { Nonce string `json:"nonce"` @@ -237,6 +178,11 @@ type Iden3PaymentRailsRequestV1 struct { Currency string `json:"currency"` } +// PaymentRequestType implements the PaymentRequestInfoDataItem interface. +func (i Iden3PaymentRailsRequestV1) PaymentRequestType() PaymentRequestType { + return Iden3PaymentRailsRequestV1Type +} + // Iden3PaymentRailsERC20RequestV1 represents the Iden3PaymentRailsERC20RequestV1 payment request data. type Iden3PaymentRailsERC20RequestV1 struct { Nonce string `json:"nonce"` @@ -252,36 +198,41 @@ type Iden3PaymentRailsERC20RequestV1 struct { Features []PaymentFeatures `json:"features,omitempty"` } +// PaymentRequestType implements the PaymentRequestInfoDataItem interface. +func (i Iden3PaymentRailsERC20RequestV1) PaymentRequestType() PaymentRequestType { + return Iden3PaymentRailsERC20RequestV1Type +} + // PaymentFeatures represents type Features used in ERC20 payment request. type PaymentFeatures string // PaymentProof represents a payment proof. -type PaymentProof struct { - dataType ProofType - eip712Signature []EthereumEip712Signature2021 +type PaymentProof []PaymentProofItem + +// PaymentProofItem is the interface that any PaymentProof item must implement. +type PaymentProofItem interface { + PaymentProofItem() verifiable.ProofType } // UnmarshalJSON unmarshal the PaymentRequestInfoData from JSON. func (p *PaymentProof) UnmarshalJSON(data []byte) error { - p.dataType = Eip712SignatureProofType - var col []EthereumEip712Signature2021 + var col []*EthereumEip712Signature2021 if err := json.Unmarshal(data, &col); err != nil { var single EthereumEip712Signature2021 if err := json.Unmarshal(data, &single); err != nil { return fmt.Errorf("failed to unmarshal EthereumEip712Signature2021Col: %w", err) } - col = append(col, single) + col = append(col, &single) + } + for _, item := range col { + *p = append(*p, *item) } - p.eip712Signature = col return nil } // MarshalJSON marshals the PaymentProof into JSON. func (p PaymentProof) MarshalJSON() ([]byte, error) { - if p.dataType == Eip712SignatureProofType { - return json.Marshal(p.eip712Signature) - } - return nil, errors.New("failed to marshal not initialized PaymentProof") + return json.Marshal([]PaymentProofItem(p)) } // EthereumEip712Signature2021 represents the Ethereum EIP712 signature. @@ -294,6 +245,11 @@ type EthereumEip712Signature2021 struct { Eip712 Eip712Data `json:"eip712"` } +// PaymentProofItem implements the PaymentProofItem interface. +func (e EthereumEip712Signature2021) PaymentProofItem() verifiable.ProofType { + return document.EthereumEip712SignatureProof2021Type +} + // Eip712Data represents the EIP712 data. type Eip712Data struct { Types string `json:"types"` @@ -358,8 +314,8 @@ func NewPaymentRails(data Iden3PaymentRailsV1) Payment { } } -// NEwPaymentRailsERC20 creates a new Payment with Iden3PaymentRailsERC20V1 data. -func NEwPaymentRailsERC20(data Iden3PaymentRailsERC20V1) Payment { +// NewPaymentRailsERC20 creates a new Payment with Iden3PaymentRailsERC20V1 data. +func NewPaymentRailsERC20(data Iden3PaymentRailsERC20V1) Payment { return Payment{ dataType: Iden3PaymentRailsERC20V1Type, railsERC: &data, @@ -459,17 +415,15 @@ type PaymentContext struct { } // NewPaymentContextString creates a new PaymentContext with a string. -func NewPaymentContextString(str string) PaymentContext { - return PaymentContext{str: &str} -} - -// NewPaymentContextStringCol creates a new PaymentContext with a string collection. -func NewPaymentContextStringCol(strCol []string) PaymentContext { - return PaymentContext{strCol: strCol} +func NewPaymentContextString(str ...string) PaymentContext { + if len(str) == 1 { + return PaymentContext{str: &str[0]} + } + return PaymentContext{strCol: str} } // NewPaymentContextItemCol creates a new PaymentContext with an interface{} collection. -func NewPaymentContextItemCol(itemCol []interface{}) PaymentContext { +func NewPaymentContextItemCol(itemCol ...interface{}) PaymentContext { return PaymentContext{itemCol: itemCol} } diff --git a/protocol/payment_test.go b/protocol/payment_test.go index b63fe83..00ae118 100644 --- a/protocol/payment_test.go +++ b/protocol/payment_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "testing" + "github.com/iden3/driver-did-iden3/pkg/document" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -454,6 +455,111 @@ func TestPaymentRequestInfoDataUnmarshalMarshall(t *testing.T) { } ] ` + const paymentRequestMixedTypesInList = ` + [ + { + "@context": [ + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsRequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1" + ], + "type": "Iden3PaymentRailsRequestV1", + "recipient": "0xaddress", + "amount": "100", + "currency": "ETHWEI", + "expirationDate": "ISO string", + "nonce": "25", + "metadata": "0x", + "proof": [ + { + "type": "EthereumEip712Signature2021", + "proofPurpose": "assertionMethod", + "proofValue": "0xa05292e9874240c5c2bbdf5a8fefff870c9fc801bde823189fc013d8ce39c7e5431bf0585f01c7e191ea7bbb7110a22e018d7f3ea0ed81a5f6a3b7b828f70f2d1c", + "verificationMethod": "did:pkh:eip155:0:0x3e1cFE1b83E7C1CdB0c9558236c1f6C7B203C34e#blockchainAccountId", + "created": "2024-09-26T12:28:19.702580067Z", + "eip712": { + "types": "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + "primaryType": "Iden3PaymentRailsRequestV1", + "domain": { + "name": "MCPayment", + "version": "1.0.0", + "chainId": "0x0", + "verifyingContract": "0x0000000000000000000000000000000000000000" + } + } + } + ] + }, + { + "type": "Iden3PaymentRailsERC20RequestV1", + "@context": [ + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20RequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1" + ], + "tokenAddress": "0x2FE40749812FAC39a0F380649eF59E01bccf3a1A", + "features": [ + "EIP-2612" + ], + "recipient": "0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a", + "amount": "40", + "currency": "ERC20Token", + "expirationDate": "2024-10-28T16:02:36.816Z", + "nonce": "3008", + "metadata": "0x", + "proof": [ + { + "type": "EthereumEip712Signature2021", + "proofPurpose": "assertionMethod", + "proofValue": "0xc3d9d6fa9aa7af03863943f7568ce61303e84221e3e29277309fd42581742024402802816cca5542620c19895331f4bdc1ea6fed0d0c6a1cf8656556d3acfde61b", + "verificationMethod": "did:pkh:eip155:80002:0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a#blockchainAccountId", + "created": "2024-10-28T15:02:36.946Z", + "eip712": { + "types": "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + "primaryType": "Iden3PaymentRailsRequestV1", + "domain": { + "name": "MCPayment", + "version": "1.0.0", + "chainId": "80002", + "verifyingContract": "0x6f742EBA99C3043663f995a7f566e9F012C07925" + } + } + } + ] + }, + { + "@context": [ + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsRequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1" + ], + "type": "Iden3PaymentRailsRequestV1", + "recipient": "0xaddress2", + "amount": "200", + "currency": "ETHWEI", + "expirationDate": "ISO string", + "nonce": "25", + "metadata": "0x", + "proof": [ + { + "type": "EthereumEip712Signature2021", + "proofPurpose": "assertionMethod", + "proofValue": "0xa05292e9874240c5c2bbdf5a8fefff870c9fc801bde823189fc013d8ce39c7e5431bf0585f01c7e191ea7bbb7110a22e018d7f3ea0ed81a5f6a3b7b828f70f2d1c", + "verificationMethod": "did:pkh:eip155:0:0x3e1cFE1b83E7C1CdB0c9558236c1f6C7B203C34e#blockchainAccountId", + "created": "2024-09-26T12:28:19.702580067Z", + "eip712": { + "types": "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + "primaryType": "Iden3PaymentRailsRequestV1", + "domain": { + "name": "MCPayment", + "version": "1.0.0", + "chainId": "0x1", + "verifyingContract": "0x0000000000000000000000000000000000000002" + } + } + } + ] + } + ] + ` + for _, tc := range []struct { desc string payload []byte @@ -474,6 +580,11 @@ func TestPaymentRequestInfoDataUnmarshalMarshall(t *testing.T) { payload: []byte(paymentRequestRailsV1InList), expectedPayload: []byte(paymentRequestRailsV1InList), }, + { + desc: "Mixed types: Iden3PaymentRailsRequestV1 and Iden3PaymentRailsERC20RequestV1 in a list", + payload: []byte(paymentRequestMixedTypesInList), + expectedPayload: []byte(paymentRequestMixedTypesInList), + }, } { t.Run(tc.desc, func(t *testing.T) { var msg PaymentRequestInfoData @@ -485,6 +596,153 @@ func TestPaymentRequestInfoDataUnmarshalMarshall(t *testing.T) { } } +func TestPaymentRequestInfoData_Construction(t *testing.T) { + const paymentRequestMixedTypesInList = ` +[ + { + "@context": [ + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsRequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1" + ], + "type": "Iden3PaymentRailsRequestV1", + "recipient": "0xaddress", + "amount": "100", + "currency": "ETHWEI", + "proof": [ + { + "type": "EthereumEip712Signature2021", + "proofPurpose": "assertionMethod", + "proofValue": "0xa05292e9874240c5c2bbdf5a8fefff870c9fc801bde823189fc013d8ce39c7e5431bf0585f01c7e191ea7bbb7110a22e018d7f3ea0ed81a5f6a3b7b828f70f2d1c", + "verificationMethod": "did:pkh:eip155:0:0x3e1cFE1b83E7C1CdB0c9558236c1f6C7B203C34e#blockchainAccountId", + "created": "2024-09-26T12:28:19.702580067Z", + "eip712": { + "types": "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + "primaryType": "Iden3PaymentRailsRequestV1", + "domain": { + "name": "MCPayment", + "version": "1.0.0", + "chainId": "0x0", + "verifyingContract": "0x0000000000000000000000000000000000000000" + } + } + } + ], + "expirationDate": "ISO string", + "nonce": "25", + "metadata": "0x" + }, + { + "type": "Iden3PaymentRailsERC20RequestV1", + "@context": [ + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20RequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1" + ], + "tokenAddress": "0x2FE40749812FAC39a0F380649eF59E01bccf3a1A", + "features": [ + "EIP-2612" + ], + "recipient": "0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a", + "amount": "40", + "currency": "ERC20Token", + "proof": [ + { + "type": "EthereumEip712Signature2021", + "proofPurpose": "assertionMethod", + "proofValue": "0xc3d9d6fa9aa7af03863943f7568ce61303e84221e3e29277309fd42581742024402802816cca5542620c19895331f4bdc1ea6fed0d0c6a1cf8656556d3acfde61b", + "verificationMethod": "did:pkh:eip155:80002:0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a#blockchainAccountId", + "created": "2024-10-28T15:02:36.946Z", + "eip712": { + "types": "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + "primaryType": "Iden3PaymentRailsRequestV1", + "domain": { + "name": "MCPayment", + "version": "1.0.0", + "chainId": "80002", + "verifyingContract": "0x6f742EBA99C3043663f995a7f566e9F012C07925" + } + } + } + ], + "expirationDate": "2024-10-28T16:02:36.816Z", + "nonce": "3008", + "metadata": "0x" + } +] +` + data := PaymentRequestInfoData{ + Iden3PaymentRailsRequestV1{ + Nonce: "25", + Type: Iden3PaymentRailsRequestV1Type, + Context: NewPaymentContextString( + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsRequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1", + ), + Recipient: "0xaddress", + Amount: "100", + ExpirationDate: "ISO string", + Proof: PaymentProof{ + EthereumEip712Signature2021{ + Type: document.EthereumEip712SignatureProof2021Type, + ProofPurpose: "assertionMethod", + ProofValue: "0xa05292e9874240c5c2bbdf5a8fefff870c9fc801bde823189fc013d8ce39c7e5431bf0585f01c7e191ea7bbb7110a22e018d7f3ea0ed81a5f6a3b7b828f70f2d1c", + VerificationMethod: "did:pkh:eip155:0:0x3e1cFE1b83E7C1CdB0c9558236c1f6C7B203C34e#blockchainAccountId", + Created: "2024-09-26T12:28:19.702580067Z", + Eip712: Eip712Data{ + Types: "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + PrimaryType: "Iden3PaymentRailsRequestV1", + Domain: Eip712Domain{ + Name: "MCPayment", + Version: "1.0.0", + ChainID: "0x0", + VerifyingContract: "0x0000000000000000000000000000000000000000", + }, + }, + }, + }, + Metadata: "0x", + Currency: "ETHWEI", + }, + Iden3PaymentRailsERC20RequestV1{ + Nonce: "3008", + Type: Iden3PaymentRailsERC20RequestV1Type, + Context: NewPaymentContextString( + "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20RequestV1", + "https://w3id.org/security/suites/eip712sig-2021/v1", + ), + Recipient: "0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a", + Amount: "40", + ExpirationDate: "2024-10-28T16:02:36.816Z", + Proof: PaymentProof{ + EthereumEip712Signature2021{ + Type: document.EthereumEip712SignatureProof2021Type, + ProofPurpose: "assertionMethod", + ProofValue: "0xc3d9d6fa9aa7af03863943f7568ce61303e84221e3e29277309fd42581742024402802816cca5542620c19895331f4bdc1ea6fed0d0c6a1cf8656556d3acfde61b", + VerificationMethod: "did:pkh:eip155:80002:0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a#blockchainAccountId", + Created: "2024-10-28T15:02:36.946Z", + Eip712: Eip712Data{ + Types: "https://schema.iden3.io/core/json/Iden3PaymentRailsRequestV1.json", + PrimaryType: "Iden3PaymentRailsRequestV1", + Domain: Eip712Domain{ + Name: "MCPayment", + Version: "1.0.0", + ChainID: "80002", + VerifyingContract: "0x6f742EBA99C3043663f995a7f566e9F012C07925", + }, + }, + }, + }, + Metadata: "0x", + Currency: "ERC20Token", + TokenAddress: "0x2FE40749812FAC39a0F380649eF59E01bccf3a1A", + Features: []PaymentFeatures{"EIP-2612"}, + }, + } + payload, err := json.Marshal(data) + require.NoError(t, err) + + assert.JSONEq(t, paymentRequestMixedTypesInList, string(payload)) +} + func TestPaymentContext(t *testing.T) { for _, tc := range []struct { desc string