diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b14905dbbf..4ec94cfb7a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,7 +36,7 @@ jobs: - name: MegaLinter id: ml - uses: oxsecurity/megalinter@v7.1.0 + uses: oxsecurity/megalinter@v8 - name: Archive production artifacts if: success() || failure() diff --git a/.mega-linter.yml b/.mega-linter.yml index 2e4d3c64b2..d065f68b12 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -12,6 +12,7 @@ DISABLE_LINTERS: - REPOSITORY_CHECKOV - REPOSITORY_SECRETLINT - REPOSITORY_KICS + - REPOSITORY_GRYPE - SCALA_SCALAFIX - SQL_TSQLLINT - C_CPPLINT # For pollux/lib/anoncreds/src/main/c @@ -30,6 +31,7 @@ DISABLE_LINTERS: DISABLE_ERRORS_LINTERS: - KOTLIN_KTLINT + - KOTLIN_DETEKT - PROTOBUF_PROTOLINT - MARKDOWN_MARKDOWN_LINK_CHECK - ACTION_ACTIONLINT diff --git a/build.sbt b/build.sbt index ca50625deb..0df784ff60 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,8 @@ inThisBuild( // scalacOptions += "-Yexplicit-nulls", // scalacOptions += "-Ysafe-init", // scalacOptions += "-Werror", // <=> "-Xfatal-warnings" - scalacOptions += "-Dquill.macro.log=false", // disable quill macro logs // TODO https://github.com/zio/zio-protoquill/issues/470 + scalacOptions += "-Dquill.macro.log=false", // disable quill macro logs // TODO https://github.com/zio/zio-protoquill/issues/470, + scalacOptions ++= Seq("-Xmax-inlines", "50") // manually increase max-inlines above 32 (https://github.com/circe/circe/issues/2162) ) ) @@ -53,6 +54,7 @@ lazy val V = new { val zioCatsInterop = "3.3.0" // TODO "23.1.0.2" // https://mvnrepository.com/artifact/dev.zio/zio-interop-cats val zioMetricsConnector = "2.3.1" val zioMock = "1.0.0-RC12" + val zioKafka = "2.7.5" val mockito = "3.2.18.0" val monocle = "3.2.0" @@ -102,7 +104,11 @@ lazy val D = new { val zioLog: ModuleID = "dev.zio" %% "zio-logging" % V.zioLogging val zioSLF4J: ModuleID = "dev.zio" %% "zio-logging-slf4j" % V.zioLogging val zioJson: ModuleID = "dev.zio" %% "zio-json" % V.zioJson + val zioConcurrent: ModuleID = "dev.zio" %% "zio-concurrent" % V.zio val zioHttp: ModuleID = "dev.zio" %% "zio-http" % V.zioHttp + val zioKafka: ModuleID = "dev.zio" %% "zio-kafka" % V.zioKafka excludeAll ( + ExclusionRule("dev.zio", "zio_3"), ExclusionRule("dev.zio", "zio-streams_3") + ) val zioCatsInterop: ModuleID = "dev.zio" %% "zio-interop-cats" % V.zioCatsInterop val zioMetricsConnectorMicrometer: ModuleID = "dev.zio" %% "zio-metrics-connectors-micrometer" % V.zioMetricsConnector val tapirPrometheusMetrics: ModuleID = "com.softwaremill.sttp.tapir" %% "tapir-prometheus-metrics" % V.tapir @@ -185,7 +191,9 @@ lazy val D_Shared = new { D.typesafeConfig, D.scalaPbGrpc, D.zio, + D.zioConcurrent, D.zioHttp, + D.zioKafka, D.scalaUri, D.zioPrelude, // FIXME: split shared DB stuff as subproject? @@ -341,12 +349,11 @@ lazy val D_Pollux_VC_JWT = new { lazy val D_EventNotification = new { val zio = "dev.zio" %% "zio" % V.zio - val zioConcurrent = "dev.zio" %% "zio-concurrent" % V.zio val zioTest = "dev.zio" %% "zio-test" % V.zio % Test val zioTestSbt = "dev.zio" %% "zio-test-sbt" % V.zio % Test val zioTestMagnolia = "dev.zio" %% "zio-test-magnolia" % V.zio % Test - val zioDependencies: Seq[ModuleID] = Seq(zio, zioConcurrent, zioTest, zioTestSbt, zioTestMagnolia) + val zioDependencies: Seq[ModuleID] = Seq(zio, zioTest, zioTestSbt, zioTestMagnolia) val baseDependencies: Seq[ModuleID] = zioDependencies } diff --git a/cloud-agent/client/generator/openapitools.json b/cloud-agent/client/generator/openapitools.json index 5571688218..f227cf2df3 100644 --- a/cloud-agent/client/generator/openapitools.json +++ b/cloud-agent/client/generator/openapitools.json @@ -2,6 +2,6 @@ "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", "spaces": 2, "generator-cli": { - "version": "7.4.0" + "version": "7.7.0" } } diff --git a/cloud-agent/client/generator/package.json b/cloud-agent/client/generator/package.json index 79c2bf504e..f9fb3d43dc 100644 --- a/cloud-agent/client/generator/package.json +++ b/cloud-agent/client/generator/package.json @@ -13,7 +13,7 @@ "publish:clients": "./publish-clients.sh" }, "dependencies": { - "@openapitools/openapi-generator-cli": "2.7.0", + "@openapitools/openapi-generator-cli": "2.13.13", "npm-run-all": "^4.1.5" } } diff --git a/cloud-agent/client/generator/yarn.lock b/cloud-agent/client/generator/yarn.lock index faf654ad56..b9236b8e57 100644 --- a/cloud-agent/client/generator/yarn.lock +++ b/cloud-agent/client/generator/yarn.lock @@ -14,33 +14,31 @@ resolved "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz" integrity sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA== -"@nestjs/axios@0.1.0": - version "0.1.0" - resolved "https://registry.npmjs.org/@nestjs/axios/-/axios-0.1.0.tgz" - integrity sha512-b2TT2X6BFbnNoeteiaxCIiHaFcSbVW+S5yygYqiIq5i6H77yIU3IVuLdpQkHq8/EqOWFwMopLN8jdkUT71Am9w== - dependencies: - axios "0.27.2" +"@nestjs/axios@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@nestjs/axios/-/axios-3.0.3.tgz#a663cb13cff07ea6b9a7107263de2ae472d41118" + integrity sha512-h6TCn3yJwD6OKqqqfmtRS5Zo4E46Ip2n+gK1sqwzNBC+qxQ9xpCu+ODVRFur6V3alHSCSBxb3nNtt73VEdluyA== -"@nestjs/common@9.3.11": - version "9.3.11" - resolved "https://registry.npmjs.org/@nestjs/common/-/common-9.3.11.tgz" - integrity sha512-IFZ2G/5UKWC2Uo7tJ4SxGed2+aiA+sJyWeWsGTogKVDhq90oxVBToh+uCDeI31HNUpqYGoWmkletfty42zUd8A== +"@nestjs/common@10.4.3": + version "10.4.3" + resolved "https://registry.yarnpkg.com/@nestjs/common/-/common-10.4.3.tgz#b9059313d928aea335a4a185a621e32c1858c845" + integrity sha512-4hbLd3XIJubHSylYd/1WSi4VQvG68KM/ECYpMDqA3k3J1/T17SAg40sDoq3ZoO5OZgU0xuNyjuISdOTjs11qVg== dependencies: - uid "2.0.1" + uid "2.0.2" iterare "1.2.1" - tslib "2.5.0" + tslib "2.7.0" -"@nestjs/core@9.3.11": - version "9.3.11" - resolved "https://registry.npmjs.org/@nestjs/core/-/core-9.3.11.tgz" - integrity sha512-CI27a2JFd5rvvbgkalWqsiwQNhcP4EAG5BUK8usjp29wVp1kx30ghfBT8FLqIgmkRVo65A0IcEnWsxeXMntkxQ== +"@nestjs/core@10.4.3": + version "10.4.3" + resolved "https://registry.yarnpkg.com/@nestjs/core/-/core-10.4.3.tgz#b2a3dcfc6a948a74618feeee8affc3186afe52da" + integrity sha512-6OQz+5C8mT8yRtfvE5pPCq+p6w5jDot+oQku1KzQ24ABn+lay1KGuJwcKZhdVNuselx+8xhdMxknZTA8wrGLIg== dependencies: - uid "2.0.1" + uid "2.0.2" "@nuxtjs/opencollective" "0.3.2" fast-safe-stringify "2.1.1" iterare "1.2.1" - path-to-regexp "3.2.0" - tslib "2.5.0" + path-to-regexp "3.3.0" + tslib "2.7.0" "@nuxtjs/opencollective@0.3.2": version "0.3.2" @@ -51,27 +49,36 @@ consola "^2.15.0" node-fetch "^2.6.1" -"@openapitools/openapi-generator-cli@2.7.0": - version "2.7.0" - resolved "https://registry.npmjs.org/@openapitools/openapi-generator-cli/-/openapi-generator-cli-2.7.0.tgz" - integrity sha512-ieEpHTA/KsDz7ANw03lLPYyjdedDEXYEyYoGBRWdduqXWSX65CJtttjqa8ZaB1mNmIjMtchUHwAYQmTLVQ8HYg== +"@openapitools/openapi-generator-cli@2.13.13": + version "2.13.13" + resolved "https://registry.yarnpkg.com/@openapitools/openapi-generator-cli/-/openapi-generator-cli-2.13.13.tgz#380fd9556500b558f066a9ee0c46678f7803422b" + integrity sha512-uioqbxB6TfiLoOEE3T8kqTn/ffaRzOwS3ATMQnoMvh2lwADKMT6bDLfE3YO3XTEj+HflXcsLXQGK6PLiqa8Mmw== dependencies: - "@nestjs/axios" "0.1.0" - "@nestjs/common" "9.3.11" - "@nestjs/core" "9.3.11" + "@nestjs/axios" "3.0.3" + "@nestjs/common" "10.4.3" + "@nestjs/core" "10.4.3" "@nuxtjs/opencollective" "0.3.2" + axios "1.7.7" chalk "4.1.2" commander "8.3.0" compare-versions "4.1.4" concurrently "6.5.1" console.table "0.10.0" fs-extra "10.1.0" - glob "7.1.6" - inquirer "8.2.5" + glob "9.3.5" + https-proxy-agent "7.0.5" + inquirer "8.2.6" lodash "4.17.21" reflect-metadata "0.1.13" - rxjs "7.8.0" - tslib "2.0.3" + rxjs "7.8.1" + tslib "2.7.0" + +agent-base@^7.0.2: + version "7.1.1" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317" + integrity sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA== + dependencies: + debug "^4.3.4" ansi-escapes@^4.2.1: version "4.3.2" @@ -129,13 +136,14 @@ available-typed-arrays@^1.0.5: resolved "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -axios@0.27.2: - version "0.27.2" - resolved "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== +axios@1.7.7: + version "1.7.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" + integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== dependencies: - follow-redirects "^1.14.9" + follow-redirects "^1.15.6" form-data "^4.0.0" + proxy-from-env "^1.1.0" balanced-match@^1.0.0: version "1.0.2" @@ -164,6 +172,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + buffer@^5.5.0: version "5.7.1" resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz" @@ -323,6 +338,13 @@ date-fns@^2.16.1: dependencies: "@babel/runtime" "^7.21.0" +debug@4, debug@^4.3.4: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + defaults@^1.0.3: version "1.0.4" resolved "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz" @@ -456,10 +478,10 @@ figures@^3.0.0: dependencies: escape-string-regexp "^1.0.5" -follow-redirects@^1.14.9: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== +follow-redirects@^1.15.6: + version "1.15.9" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" + integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ== for-each@^0.3.3: version "0.3.3" @@ -534,17 +556,15 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -glob@7.1.6: - version "7.1.6" - resolved "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz" - integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== +glob@9.3.5: + version "9.3.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21" + integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q== dependencies: fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" + minimatch "^8.0.2" + minipass "^4.2.4" + path-scurry "^1.6.1" globalthis@^1.0.3: version "1.0.3" @@ -616,6 +636,14 @@ hosted-git-info@^2.1.4: resolved "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz" integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== +https-proxy-agent@7.0.5: + version "7.0.5" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz#9e8b5013873299e11fab6fd548405da2d6c602b2" + integrity sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw== + dependencies: + agent-base "^7.0.2" + debug "4" + iconv-lite@^0.4.24: version "0.4.24" resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz" @@ -628,23 +656,15 @@ ieee754@^1.1.13: resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz" integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz" - integrity sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA== - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2, inherits@^2.0.3, inherits@^2.0.4: +inherits@^2.0.3, inherits@^2.0.4: version "2.0.4" resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== -inquirer@8.2.5: - version "8.2.5" - resolved "https://registry.npmjs.org/inquirer/-/inquirer-8.2.5.tgz" - integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ== +inquirer@8.2.6: + version "8.2.6" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.6.tgz#733b74888195d8d400a67ac332011b5fae5ea562" + integrity sha512-M1WuAmb7pn9zdFRtQYk26ZBoY043Sse0wVDdk4Bppr+JOXyQYybdtvK+l9wUibhtjdjvtoiNy8tk+EgsYIUqKg== dependencies: ansi-escapes "^4.2.1" chalk "^4.1.1" @@ -660,7 +680,7 @@ inquirer@8.2.5: string-width "^4.1.0" strip-ansi "^6.0.0" through "^2.3.6" - wrap-ansi "^7.0.0" + wrap-ansi "^6.0.1" internal-slot@^1.0.5: version "1.0.5" @@ -841,6 +861,11 @@ log-symbols@^4.1.0: chalk "^4.1.0" is-unicode-supported "^0.1.0" +lru-cache@^10.2.0: + version "10.4.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" + integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== + memorystream@^0.3.1: version "0.3.1" resolved "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz" @@ -870,6 +895,28 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" +minimatch@^8.0.2: + version "8.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229" + integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA== + dependencies: + brace-expansion "^2.0.1" + +minipass@^4.2.4: + version "4.2.8" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a" + integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ== + +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0": + version "7.1.2" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" + integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== + +ms@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + mute-stream@0.0.8: version "0.0.8" resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz" @@ -932,13 +979,6 @@ object.assign@^4.1.4: has-symbols "^1.0.3" object-keys "^1.1.1" -once@^1.3.0: - version "1.4.0" - resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz" - integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== - dependencies: - wrappy "1" - onetime@^5.1.0: version "5.1.2" resolved "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz" @@ -974,11 +1014,6 @@ parse-json@^4.0.0: error-ex "^1.3.1" json-parse-better-errors "^1.0.1" -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz" - integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg== - path-key@^2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz" @@ -989,10 +1024,18 @@ path-parse@^1.0.7: resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== -path-to-regexp@3.2.0: - version "3.2.0" - resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.2.0.tgz" - integrity sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA== +path-scurry@^1.6.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" + integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== + dependencies: + lru-cache "^10.2.0" + minipass "^5.0.0 || ^6.0.2 || ^7.0.0" + +path-to-regexp@3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.3.0.tgz#f7f31d32e8518c2660862b644414b6d5c63a611b" + integrity sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw== path-type@^3.0.0: version "3.0.0" @@ -1011,6 +1054,11 @@ pify@^3.0.0: resolved "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz" integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg== +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + read-pkg@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz" @@ -1075,10 +1123,10 @@ run-async@^2.4.0: resolved "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz" integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== -rxjs@7.8.0: - version "7.8.0" - resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz" - integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg== +rxjs@7.8.1, rxjs@^7.5.5: + version "7.8.1" + resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz" + integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== dependencies: tslib "^2.1.0" @@ -1089,13 +1137,6 @@ rxjs@^6.6.3: dependencies: tslib "^1.9.0" -rxjs@^7.5.5: - version "7.8.1" - resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz" - integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== - dependencies: - tslib "^2.1.0" - safe-array-concat@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.0.0.tgz" @@ -1304,15 +1345,10 @@ tree-kill@^1.2.2: resolved "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz" integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== -tslib@2.0.3: - version "2.0.3" - resolved "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz" - integrity sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ== - -tslib@2.5.0: - version "2.5.0" - resolved "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz" - integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== +tslib@2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" + integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== tslib@^1.9.0: version "1.14.1" @@ -1368,10 +1404,10 @@ typed-array-length@^1.0.4: for-each "^0.3.3" is-typed-array "^1.1.9" -uid@2.0.1: - version "2.0.1" - resolved "https://registry.npmjs.org/uid/-/uid-2.0.1.tgz" - integrity sha512-PF+1AnZgycpAIEmNtjxGBVmKbZAQguaa4pBUq6KNaGEcpzZ2klCNZLM34tsjp76maN00TttiiUf6zkIBpJQm2A== +uid@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/uid/-/uid-2.0.2.tgz#4b5782abf0f2feeefc00fa88006b2b3b7af3e3b9" + integrity sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g== dependencies: "@lukeed/csprng" "^1.0.0" @@ -1452,6 +1488,15 @@ which@^1.2.9: dependencies: isexe "^2.0.0" +wrap-ansi@^6.0.1: + version "6.2.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" @@ -1461,11 +1506,6 @@ wrap-ansi@^7.0.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrappy@1: - version "1.0.2" - resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" - integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== - y18n@^5.0.5: version "5.0.8" resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz" diff --git a/cloud-agent/client/kotlin/.openapi-generator-ignore b/cloud-agent/client/kotlin/.openapi-generator-ignore index d9ad2d6500..658834d27c 100644 --- a/cloud-agent/client/kotlin/.openapi-generator-ignore +++ b/cloud-agent/client/kotlin/.openapi-generator-ignore @@ -17,6 +17,9 @@ src/main/kotlin/org/hyperledger/identus/client/models/DateTimeParameter.kt src/main/kotlin/org/hyperledger/identus/client/models/DidParameter.kt src/main/kotlin/org/hyperledger/identus/client/models/VcVerificationParameter.kt +src/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequest.kt +src/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequestSchemaId.kt + src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTest.kt src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTypeTest.kt @@ -25,3 +28,7 @@ src/test/kotlin/org/hyperledger/identus/client/models/ServiceTypeTest.kt src/test/kotlin/org/hyperledger/identus/client/models/StatusPurposeTest.kt src/test/kotlin/org/hyperledger/identus/client/models/CredentialSubjectTest.kt + +src/test/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequestTest.kt +src/test/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequestSchemaIdTest.kt + diff --git a/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.jar b/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.jar index c1962a79e2..d64cd49177 100644 Binary files a/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.jar and b/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.properties b/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.properties index 8707e8b506..e7646dead0 100644 --- a/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/cloud-agent/client/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/cloud-agent/client/kotlin/gradlew b/cloud-agent/client/kotlin/gradlew index aeb74cbb43..9d0ce634cb 100755 --- a/cloud-agent/client/kotlin/gradlew +++ b/cloud-agent/client/kotlin/gradlew @@ -69,34 +69,35 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum warn () { - echo "$*" +echo "$*" } >&2 die () { - echo - echo "$*" - echo - exit 1 +echo +echo "$*" +echo +exit 1 } >&2 # OS specific support (must be 'true' or 'false'). @@ -105,10 +106,10 @@ msys=false darwin=false nonstop=false case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -116,43 +117,46 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi +fi else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi +fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac fi # Collect all arguments for the java command, stacking in reverse order: @@ -165,55 +169,55 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" # Stop when "xargs" is not available. if ! command -v xargs >/dev/null 2>&1 then - die "xargs is not available" +die "xargs is not available" fi # Use "xargs" to parse quoted args. @@ -236,10 +240,10 @@ fi # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' exec "$JAVACMD" "$@" diff --git a/cloud-agent/client/kotlin/gradlew.bat b/cloud-agent/client/kotlin/gradlew.bat index 93e3f59f13..9d0ce634cb 100644 --- a/cloud-agent/client/kotlin/gradlew.bat +++ b/cloud-agent/client/kotlin/gradlew.bat @@ -1,92 +1,249 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/cloud-agent/client/kotlin/settings.gradle b/cloud-agent/client/kotlin/settings.gradle index b5dc286913..4765fb4704 100644 --- a/cloud-agent/client/kotlin/settings.gradle +++ b/cloud-agent/client/kotlin/settings.gradle @@ -1,2 +1 @@ - -rootProject.name = 'cloud-agent-client-kotlin' \ No newline at end of file +rootProject.name = 'cloud-agent-client-kotlin' diff --git a/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/adapters/StringOrStringArrayAdapter.kt b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/adapters/StringOrStringArrayAdapter.kt new file mode 100644 index 0000000000..cebdbbe604 --- /dev/null +++ b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/adapters/StringOrStringArrayAdapter.kt @@ -0,0 +1,33 @@ +package org.hyperledger.identus.client.adapters + +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement +import com.google.gson.JsonSerializer +import com.google.gson.JsonNull +import com.google.gson.JsonParseException +import com.google.gson.JsonPrimitive +import com.google.gson.JsonSerializationContext +import java.lang.reflect.Type + +class StringOrStringArrayAdapter : JsonSerializer>, JsonDeserializer> { + + // Deserialize logic: String or Array of Strings to List + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): List { + return when { + json.isJsonArray -> context.deserialize(json, typeOfT) + json.isJsonPrimitive -> listOf(json.asString) + json.isJsonNull -> emptyList() + else -> throw JsonParseException("Unexpected type for field") + } + } + + // Serialize logic: List to String or Array of Strings + override fun serialize(src: List?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { + return when { + src.isNullOrEmpty() -> JsonNull.INSTANCE + src.size == 1 -> JsonPrimitive(src[0]) // If only one string, serialize as a single string + else -> context!!.serialize(src) // Otherwise, serialize as a list + } + } +} \ No newline at end of file diff --git a/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequest.kt b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequest.kt new file mode 100644 index 0000000000..7518b6a52e --- /dev/null +++ b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequest.kt @@ -0,0 +1,86 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.hyperledger.identus.client.models + +import com.google.gson.annotations.JsonAdapter +import com.google.gson.annotations.SerializedName +import org.hyperledger.identus.client.adapters.StringOrStringArrayAdapter + +/** + * + * + * @param claims The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. 'schemaId' or 'credentialDefinitionId'). + * @param issuingDID The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form. + * @param validityPeriod The validity period in seconds of the verifiable credential that will be issued. + * @param schemaId + * @param credentialDefinitionId The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent's database. Note that this parameter only applies when the offer is of type 'AnonCreds'. + * @param credentialFormat The credential format for this offer (defaults to 'JWT') + * @param automaticIssuance Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued. + * @param issuingKid Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"#\" Note the cryto algorithm used with depend type of the key. + * @param connectionId The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent's database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance. + * @param goalCode A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance. + * @param goal A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance. + */ + + +data class CreateIssueCredentialRecordRequest( + + /* The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. 'schemaId' or 'credentialDefinitionId'). */ + @SerializedName("claims") + val claims: kotlin.Any?, + + /* The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form. */ + @SerializedName("issuingDID") + val issuingDID: kotlin.String, + + /* The validity period in seconds of the verifiable credential that will be issued. */ + @SerializedName("validityPeriod") + val validityPeriod: kotlin.Double? = null, + + @SerializedName("schemaId") + @JsonAdapter(StringOrStringArrayAdapter::class) + val schemaId: kotlin.collections.List? = null, + + /* The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent's database. Note that this parameter only applies when the offer is of type 'AnonCreds'. */ + @SerializedName("credentialDefinitionId") + val credentialDefinitionId: java.util.UUID? = null, + + /* The credential format for this offer (defaults to 'JWT') */ + @SerializedName("credentialFormat") + val credentialFormat: kotlin.String? = null, + + /* Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued. */ + @SerializedName("automaticIssuance") + val automaticIssuance: kotlin.Boolean? = null, + + /* Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"#\" Note the cryto algorithm used with depend type of the key. */ + @SerializedName("issuingKid") + val issuingKid: kotlin.String? = null, + + /* The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent's database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance. */ + @SerializedName("connectionId") + val connectionId: java.util.UUID? = null, + + /* A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance. */ + @SerializedName("goalCode") + val goalCode: kotlin.String? = null, + + /* A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance. */ + @SerializedName("goal") + val goal: kotlin.String? = null + +) + diff --git a/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/Service.kt b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/Service.kt index a331caee07..0ec683b89b 100644 --- a/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/Service.kt +++ b/cloud-agent/client/kotlin/src/main/kotlin/org/hyperledger/identus/client/models/Service.kt @@ -15,35 +15,10 @@ package org.hyperledger.identus.client.models -import com.google.gson.* +import com.google.gson.JsonElement import com.google.gson.annotations.JsonAdapter import com.google.gson.annotations.SerializedName -import java.lang.reflect.Type - -class StringOrStringArrayAdapter : JsonSerializer>, JsonDeserializer> { - - // Deserialize logic: String or Array of Strings to List - override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): List { - return when { - json?.isJsonArray == true -> { - context!!.deserialize(json, typeOfT) - } - json?.isJsonPrimitive == true -> { - listOf(json.asString) - } - else -> throw JsonParseException("Unexpected type for field") - } - } - - // Serialize logic: List to String or Array of Strings - override fun serialize(src: List?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { - return when { - src == null -> JsonNull.INSTANCE - src.size == 1 -> JsonPrimitive(src[0]) // If only one string, serialize as a single string - else -> context!!.serialize(src) // Otherwise, serialize as a list - } - } -} +import org.hyperledger.identus.client.adapters.StringOrStringArrayAdapter data class Service( @@ -58,4 +33,4 @@ data class Service( @SerializedName("serviceEndpoint") val serviceEndpoint: JsonElement? = null, -) + ) diff --git a/cloud-agent/client/typescript/.openapi-generator-ignore b/cloud-agent/client/typescript/.openapi-generator-ignore index af11cd214d..cf11c2202e 100644 --- a/cloud-agent/client/typescript/.openapi-generator-ignore +++ b/cloud-agent/client/typescript/.openapi-generator-ignore @@ -6,3 +6,4 @@ models/CredentialRequest.ts models/Proof2.ts models/Service.ts models/UpdateManagedDIDServiceAction.ts +models/CreateIssueCredentialRecordRequest.ts diff --git a/cloud-agent/client/typescript/models/CreateIssueCredentialRecordRequest.ts b/cloud-agent/client/typescript/models/CreateIssueCredentialRecordRequest.ts new file mode 100644 index 0000000000..14190cd10d --- /dev/null +++ b/cloud-agent/client/typescript/models/CreateIssueCredentialRecordRequest.ts @@ -0,0 +1,135 @@ +/** + * Identus Cloud Agent API Reference + * The Identus Cloud Agent API facilitates the integration and management of self-sovereign identity capabilities within applications. It supports DID (Decentralized Identifiers) management, verifiable credential exchange, and secure messaging based on DIDComm standards. The API is designed to be interoperable with various blockchain and DLT (Distributed Ledger Technology) platforms, ensuring wide compatibility and flexibility. Key features include connection management, credential issuance and verification, and secure, privacy-preserving communication between entities. Additional information and the full list of capabilities can be found in the [Open Enterprise Agent documentation](https://docs.atalaprism.io/docs/category/prism-cloud-agent) + * + * OpenAPI spec version: 1.39.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { HttpFile } from '../http/http'; + +export class CreateIssueCredentialRecordRequest { + /** + * The validity period in seconds of the verifiable credential that will be issued. + */ + 'validityPeriod'?: number; + 'schemaId'?: string | Array; + /** + * The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent\'s database. Note that this parameter only applies when the offer is of type \'AnonCreds\'. + */ + 'credentialDefinitionId'?: string; + /** + * The credential format for this offer (defaults to \'JWT\') + */ + 'credentialFormat'?: string; + /** + * The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. \'schemaId\' or \'credentialDefinitionId\'). + */ + 'claims': any | null; + /** + * Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued. + */ + 'automaticIssuance'?: boolean; + /** + * The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form. + */ + 'issuingDID': string; + /** + * Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"#\" Note the cryto algorithm used with depend type of the key. + */ + 'issuingKid'?: string; + /** + * The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent\'s database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance. + */ + 'connectionId'?: string; + /** + * A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance. + */ + 'goalCode'?: string; + /** + * A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance. + */ + 'goal'?: string; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "validityPeriod", + "baseName": "validityPeriod", + "type": "number", + "format": "double" + }, + { + "name": "schemaId", + "baseName": "schemaId", + "type": "CreateIssueCredentialRecordRequestSchemaId", + "format": "" + }, + { + "name": "credentialDefinitionId", + "baseName": "credentialDefinitionId", + "type": "string", + "format": "uuid" + }, + { + "name": "credentialFormat", + "baseName": "credentialFormat", + "type": "string", + "format": "" + }, + { + "name": "claims", + "baseName": "claims", + "type": "any", + "format": "" + }, + { + "name": "automaticIssuance", + "baseName": "automaticIssuance", + "type": "boolean", + "format": "" + }, + { + "name": "issuingDID", + "baseName": "issuingDID", + "type": "string", + "format": "" + }, + { + "name": "issuingKid", + "baseName": "issuingKid", + "type": "string", + "format": "" + }, + { + "name": "connectionId", + "baseName": "connectionId", + "type": "string", + "format": "uuid" + }, + { + "name": "goalCode", + "baseName": "goalCode", + "type": "string", + "format": "" + }, + { + "name": "goal", + "baseName": "goal", + "type": "string", + "format": "" + } ]; + + static getAttributeTypeMap() { + return CreateIssueCredentialRecordRequest.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/cloud-agent/service/server/src/main/resources/application.conf b/cloud-agent/service/server/src/main/resources/application.conf index 13f2a0b4bb..7b5bebb01a 100644 --- a/cloud-agent/service/server/src/main/resources/application.conf +++ b/cloud-agent/service/server/src/main/resources/application.conf @@ -34,22 +34,10 @@ pollux { publicEndpointUrl = "http://localhost:"${agent.httpEndpoint.http.port} publicEndpointUrl = ${?POLLUX_STATUS_LIST_REGISTRY_PUBLIC_URL} } - issueBgJobRecordsLimit = 25 - issueBgJobRecordsLimit = ${?ISSUE_BG_JOB_RECORDS_LIMIT} - issueBgJobRecurrenceDelay = 2 seconds - issueBgJobRecurrenceDelay = ${?ISSUE_BG_JOB_RECURRENCE_DELAY} - issueBgJobProcessingParallelism = 5 - issueBgJobProcessingParallelism = ${?ISSUE_BG_JOB_PROCESSING_PARALLELISM} - presentationBgJobRecordsLimit = 25 - presentationBgJobRecordsLimit = ${?PRESENTATION_BG_JOB_RECORDS_LIMIT} - presentationBgJobRecurrenceDelay = 2 seconds - presentationBgJobRecurrenceDelay = ${?PRESENTATION_BG_JOB_RECURRENCE_DELAY} - presentationBgJobProcessingParallelism = 5 - presentationBgJobProcessingParallelism = ${?PRESENTATION_BG_JOB_PROCESSING_PARALLELISM} - syncRevocationStatusesBgJobRecurrenceDelay = 2 seconds - syncRevocationStatusesBgJobRecurrenceDelay = ${?SYNC_REVOCATION_STATUSES_BG_JOB_RECURRENCE_DELAY} - syncRevocationStatusesBgJobProcessingParallelism = 5 - syncRevocationStatusesBgJobProcessingParallelism = ${?SYNC_REVOCATION_STATUSES_BG_JOB_PROCESSING_PARALLELISM} + statusListSyncTriggerRecurrenceDelay = 30 seconds + statusListSyncTriggerRecurrenceDelay = ${?STATUS_LIST_SYNC_TRIGGER_RECURRENCE_DELAY} + didStateSyncTriggerRecurrenceDelay = 30 seconds + didStateSyncTriggerRecurrenceDelay = ${?DID_STATE_SYNC_TRIGGER_RECURRENCE_DELAY} credential.sdJwt.expiry = 30 days credential.sdJwt.expiry = ${?CREDENTIAL_SD_JWT_EXPIRY} presentationInvitationExpiry = 300 seconds @@ -81,8 +69,6 @@ connect { connectBgJobRecordsLimit = ${?CONNECT_BG_JOB_RECORDS_LIMIT} connectBgJobRecurrenceDelay = 2 seconds connectBgJobRecurrenceDelay = ${?CONNECT_BG_JOB_RECURRENCE_DELAY} - connectBgJobProcessingParallelism = 5 - connectBgJobProcessingParallelism = ${?CONNECT_BG_JOB_PROCESSING_PARALLELISM} connectInvitationExpiry = 300 seconds connectInvitationExpiry = ${?CONNECT_INVITATION_EXPIRY} } @@ -262,4 +248,49 @@ agent { authApiKey = "default" authApiKey = ${?DEFAULT_WALLET_AUTH_API_KEY} } + messagingService { + connectFlow { + consumerCount = 5 + retryStrategy { + maxRetries = 4 + initialDelay = 5.seconds + maxDelay = 40.seconds + } + } + issueFlow { + consumerCount = 5 + retryStrategy { + maxRetries = 4 + initialDelay = 5.seconds + maxDelay = 40.seconds + } + } + presentFlow { + consumerCount = 5 + retryStrategy { + maxRetries = 4 + initialDelay = 5.seconds + maxDelay = 40.seconds + } + } + didStateSync { + consumerCount = 5 + } + statusListSync { + consumerCount = 5 + } + inMemoryQueueCapacity = 1000 + kafkaEnabled = false + kafkaEnabled = ${?DEFAULT_KAFKA_ENABLED} + kafka { + bootstrapServers = "kafka:9092" + consumers { + autoCreateTopics = false, + maxPollRecords = 500 + maxPollInterval = 5.minutes + pollTimeout = 50.millis + rebalanceSafeCommits = true + } + } + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/CloudAgentApp.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/CloudAgentApp.scala index d3af09cf2b..d010d4c5f6 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/CloudAgentApp.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/CloudAgentApp.scala @@ -5,12 +5,9 @@ import org.hyperledger.identus.agent.server.config.AppConfig import org.hyperledger.identus.agent.server.http.{ZHttp4sBlazeServer, ZHttpEndpoints} import org.hyperledger.identus.agent.server.jobs.* import org.hyperledger.identus.agent.walletapi.model.{Entity, Wallet, WalletSeed} -import org.hyperledger.identus.agent.walletapi.service.{EntityService, ManagedDIDService, WalletManagementService} -import org.hyperledger.identus.agent.walletapi.storage.DIDNonSecretStorage +import org.hyperledger.identus.agent.walletapi.service.{EntityService, WalletManagementService} import org.hyperledger.identus.castor.controller.{DIDRegistrarServerEndpoints, DIDServerEndpoints} -import org.hyperledger.identus.castor.core.service.DIDService import org.hyperledger.identus.connect.controller.ConnectionServerEndpoints -import org.hyperledger.identus.connect.core.service.ConnectionService import org.hyperledger.identus.credentialstatus.controller.CredentialStatusServiceEndpoints import org.hyperledger.identus.event.controller.EventServerEndpoints import org.hyperledger.identus.event.notification.EventNotificationConfig @@ -18,108 +15,35 @@ import org.hyperledger.identus.iam.authentication.apikey.ApiKeyAuthenticator import org.hyperledger.identus.iam.entity.http.EntityServerEndpoints import org.hyperledger.identus.iam.wallet.http.WalletManagementServerEndpoints import org.hyperledger.identus.issue.controller.IssueServerEndpoints -import org.hyperledger.identus.mercury.{DidOps, HttpClient} import org.hyperledger.identus.oid4vci.CredentialIssuerServerEndpoints -import org.hyperledger.identus.pollux.core.service.{CredentialService, PresentationService} import org.hyperledger.identus.pollux.credentialdefinition.CredentialDefinitionRegistryServerEndpoints import org.hyperledger.identus.pollux.credentialschema.{ SchemaRegistryServerEndpoints, VerificationPolicyServerEndpoints } import org.hyperledger.identus.pollux.prex.PresentationExchangeServerEndpoints -import org.hyperledger.identus.pollux.vc.jwt.DidResolver as JwtDidResolver import org.hyperledger.identus.presentproof.controller.PresentProofServerEndpoints -import org.hyperledger.identus.resolvers.DIDResolver -import org.hyperledger.identus.shared.http.UriResolver -import org.hyperledger.identus.shared.models.{HexString, WalletAccessContext, WalletAdministrationContext, WalletId} -import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds +import org.hyperledger.identus.shared.models.* import org.hyperledger.identus.system.controller.SystemServerEndpoints import org.hyperledger.identus.verification.controller.VcVerificationServerEndpoints import zio.* -import zio.metrics.* - object CloudAgentApp { def run = for { _ <- AgentInitialization.run - _ <- issueCredentialDidCommExchangesJob.debug.fork - _ <- presentProofExchangeJob.debug.fork - _ <- connectDidCommExchangesJob.debug.fork - _ <- syncDIDPublicationStateFromDltJob.debug.fork - _ <- syncRevocationStatusListsJob.debug.fork + _ <- ConnectBackgroundJobs.connectFlowsHandler + _ <- IssueBackgroundJobs.issueFlowsHandler + _ <- PresentBackgroundJobs.presentFlowsHandler + _ <- DIDStateSyncBackgroundJobs.didStateSyncTrigger + _ <- DIDStateSyncBackgroundJobs.didStateSyncHandler + _ <- StatusListJobs.statusListsSyncTrigger + _ <- StatusListJobs.statusListSyncHandler _ <- AgentHttpServer.run.tapDefect(e => ZIO.logErrorCause("Agent HTTP Server failure", e)).fork fiber <- DidCommHttpServer.run.tapDefect(e => ZIO.logErrorCause("DIDComm HTTP Server failure", e)).fork _ <- WebhookPublisher.layer.build.map(_.get[WebhookPublisher]).flatMap(_.run.fork) _ <- fiber.join *> ZIO.log(s"Server End") _ <- ZIO.never } yield () - - private val issueCredentialDidCommExchangesJob: RIO[ - AppConfig & DidOps & DIDResolver & JwtDidResolver & HttpClient & CredentialService & DIDNonSecretStorage & - DIDService & ManagedDIDService & PresentationService & WalletManagementService, - Unit - ] = - for { - config <- ZIO.service[AppConfig] - _ <- (IssueBackgroundJobs.issueCredentialDidCommExchanges @@ Metric - .gauge("issuance_flow_did_com_exchange_job_ms_gauge") - .trackDurationWith(_.toMetricsSeconds)) - .repeat(Schedule.spaced(config.pollux.issueBgJobRecurrenceDelay)) - .unit - } yield () - - private val presentProofExchangeJob: RIO[ - AppConfig & DidOps & UriResolver & DIDResolver & JwtDidResolver & HttpClient & PresentationService & - CredentialService & DIDNonSecretStorage & DIDService & ManagedDIDService, - Unit - ] = - for { - config <- ZIO.service[AppConfig] - _ <- (PresentBackgroundJobs.presentProofExchanges @@ Metric - .gauge("present_proof_flow_did_com_exchange_job_ms_gauge") - .trackDurationWith(_.toMetricsSeconds)) - .repeat(Schedule.spaced(config.pollux.presentationBgJobRecurrenceDelay)) - .unit - } yield () - - private val connectDidCommExchangesJob: RIO[ - AppConfig & DidOps & DIDResolver & HttpClient & ConnectionService & ManagedDIDService & DIDNonSecretStorage & - WalletManagementService, - Unit - ] = - for { - config <- ZIO.service[AppConfig] - _ <- (ConnectBackgroundJobs.didCommExchanges @@ Metric - .gauge("connection_flow_did_com_exchange_job_ms_gauge") - .trackDurationWith(_.toMetricsSeconds)) - .repeat(Schedule.spaced(config.connect.connectBgJobRecurrenceDelay)) - .unit - } yield () - - private val syncRevocationStatusListsJob = { - for { - config <- ZIO.service[AppConfig] - _ <- (StatusListJobs.syncRevocationStatuses @@ Metric - .gauge("revocation_status_list_sync_job_ms_gauge") - .trackDurationWith(_.toMetricsSeconds)) - .repeat(Schedule.spaced(config.pollux.syncRevocationStatusesBgJobRecurrenceDelay)) - } yield () - } - - private val syncDIDPublicationStateFromDltJob: URIO[ManagedDIDService & WalletManagementService, Unit] = - ZIO - .serviceWithZIO[WalletManagementService](_.listWallets().map(_._1)) - .flatMap { wallets => - ZIO.foreach(wallets) { wallet => - DIDStateSyncBackgroundJobs.syncDIDPublicationStateFromDlt - .provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id))) - } - } - .catchAll(e => ZIO.logError(s"error while syncing DID publication state: $e")) - .repeat(Schedule.spaced(10.seconds)) - .unit - .provideSomeLayer(ZLayer.succeed(WalletAdministrationContext.Admin())) - } object AgentHttpServer { diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/MainApp.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/MainApp.scala index 9f163a0a11..922593389a 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/MainApp.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/MainApp.scala @@ -7,7 +7,6 @@ import org.hyperledger.identus.agent.server.http.ZioHttpClient import org.hyperledger.identus.agent.server.sql.Migrations as AgentMigrations import org.hyperledger.identus.agent.walletapi.service.{ EntityServiceImpl, - ManagedDIDService, ManagedDIDServiceWithEventNotificationImpl, WalletManagementServiceImpl } @@ -16,7 +15,6 @@ import org.hyperledger.identus.agent.walletapi.sql.{ JdbcEntityRepository, JdbcWalletNonSecretStorage } -import org.hyperledger.identus.agent.walletapi.storage.GenericSecretStorage import org.hyperledger.identus.castor.controller.{DIDControllerImpl, DIDRegistrarControllerImpl} import org.hyperledger.identus.castor.core.model.did.{ Service as DidDocumentService, @@ -36,7 +34,7 @@ import org.hyperledger.identus.iam.authentication.{DefaultAuthenticator, Oid4vci import org.hyperledger.identus.iam.authentication.apikey.JdbcAuthenticationRepository import org.hyperledger.identus.iam.authorization.core.EntityPermissionManagementService import org.hyperledger.identus.iam.authorization.DefaultPermissionManagementService -import org.hyperledger.identus.iam.entity.http.controller.{EntityController, EntityControllerImpl} +import org.hyperledger.identus.iam.entity.http.controller.EntityControllerImpl import org.hyperledger.identus.iam.wallet.http.controller.WalletManagementControllerImpl import org.hyperledger.identus.issue.controller.IssueControllerImpl import org.hyperledger.identus.mercury.* @@ -47,7 +45,6 @@ import org.hyperledger.identus.pollux.core.service.* import org.hyperledger.identus.pollux.core.service.verification.VcVerificationServiceImpl import org.hyperledger.identus.pollux.credentialdefinition.controller.CredentialDefinitionControllerImpl import org.hyperledger.identus.pollux.credentialschema.controller.{ - CredentialSchemaController, CredentialSchemaControllerImpl, VerificationPolicyControllerImpl } @@ -66,6 +63,9 @@ import org.hyperledger.identus.pollux.sql.repository.{ } import org.hyperledger.identus.presentproof.controller.PresentProofControllerImpl import org.hyperledger.identus.resolvers.DIDResolver +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.WalletIdAndRecordId +import org.hyperledger.identus.shared.models.WalletId import org.hyperledger.identus.system.controller.SystemControllerImpl import org.hyperledger.identus.verification.controller.VcVerificationControllerImpl import zio.* @@ -77,6 +77,7 @@ import zio.metrics.connectors.micrometer.MicrometerConfig import zio.metrics.jvm.DefaultJvmMetrics import java.security.Security +import java.util.UUID object MainApp extends ZIOAppDefault { @@ -167,7 +168,6 @@ object MainApp extends ZIOAppDefault { ) _ <- preMigrations _ <- migrations - app <- CloudAgentApp.run .provide( DidCommX.liveLayer, @@ -252,6 +252,11 @@ object MainApp extends ZIOAppDefault { // HTTP client SystemModule.zioHttpClientLayer, Scope.default, + // Messaging Service + ZLayer.fromZIO(ZIO.service[AppConfig].map(_.agent.messagingService)), + messaging.MessagingService.serviceLayer, + messaging.MessagingService.producerLayer[UUID, WalletIdAndRecordId], + messaging.MessagingService.producerLayer[WalletId, WalletId] ) } yield app diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/config/AppConfig.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/config/AppConfig.scala index 0f75561812..364ff510bc 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/config/AppConfig.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/config/AppConfig.scala @@ -4,7 +4,7 @@ import org.hyperledger.identus.castor.core.model.did.VerificationRelationship import org.hyperledger.identus.iam.authentication.AuthenticationConfig import org.hyperledger.identus.pollux.vc.jwt.* import org.hyperledger.identus.shared.db.DbConfig -import zio.config.* +import org.hyperledger.identus.shared.messaging.MessagingServiceConfig import zio.config.magnolia.* import zio.Config @@ -70,22 +70,13 @@ final case class PolluxConfig( database: DatabaseConfig, credentialSdJwtExpirationTime: Duration, statusListRegistry: StatusListRegistryConfig, - issueBgJobRecordsLimit: Int, - issueBgJobRecurrenceDelay: Duration, - issueBgJobProcessingParallelism: Int, - presentationBgJobRecordsLimit: Int, - presentationBgJobRecurrenceDelay: Duration, - presentationBgJobProcessingParallelism: Int, - syncRevocationStatusesBgJobRecurrenceDelay: Duration, - syncRevocationStatusesBgJobProcessingParallelism: Int, + statusListSyncTriggerRecurrenceDelay: Duration, + didStateSyncTriggerRecurrenceDelay: Duration, presentationInvitationExpiry: Duration, issuanceInvitationExpiry: Duration, ) final case class ConnectConfig( database: DatabaseConfig, - connectBgJobRecordsLimit: Int, - connectBgJobRecurrenceDelay: Duration, - connectBgJobProcessingParallelism: Int, connectInvitationExpiry: Duration, ) @@ -173,7 +164,8 @@ final case class AgentConfig( verification: VerificationConfig, secretStorage: SecretStorageConfig, webhookPublisher: WebhookPublisherConfig, - defaultWallet: DefaultWalletConfig + defaultWallet: DefaultWalletConfig, + messagingService: MessagingServiceConfig ) { def validate: Either[String, Unit] = for { diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/CustomServerInterceptors.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/CustomServerInterceptors.scala index 0d73369e82..44ffa1cea8 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/CustomServerInterceptors.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/CustomServerInterceptors.scala @@ -1,9 +1,11 @@ package org.hyperledger.identus.agent.server.http +import org.http4s.{MediaType, Request, Response, Status} +import org.http4s.headers.`Content-Type` +import org.http4s.server.ServiceErrorHandler import org.hyperledger.identus.api.http.ErrorResponse import org.hyperledger.identus.shared.models.{Failure, StatusCode, UnmanagedFailureException} import org.log4s.* -import sttp.tapir.* import sttp.tapir.json.zio.jsonBody import sttp.tapir.server.interceptor.* import sttp.tapir.server.interceptor.decodefailure.{DecodeFailureHandler, DefaultDecodeFailureHandler} @@ -11,6 +13,7 @@ import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler.F import sttp.tapir.server.interceptor.exception.ExceptionHandler import sttp.tapir.server.interceptor.reject.RejectHandler import sttp.tapir.server.model.ValuedEndpointOutput +import zio.{Task, ZIO} import scala.language.implicitConversions @@ -19,7 +22,7 @@ object CustomServerInterceptors { private val logger: Logger = getLogger private val endpointOutput = jsonBody[ErrorResponse] - private def defectHandler(response: ErrorResponse, maybeCause: Option[Throwable] = None) = { + private def tapirDefectHandler(response: ErrorResponse, maybeCause: Option[Throwable] = None) = { val statusCode = sttp.model.StatusCode(response.status) // Log defect as 'error' when status code matches a server error (5xx). Log other defects as 'debug'. (statusCode, maybeCause) match @@ -27,39 +30,43 @@ object CustomServerInterceptors { case (sc, None) if sc.isServerError => logger.error(endpointOutput.codec.encode(response)) case (_, Some(cause)) => logger.debug(cause)(endpointOutput.codec.encode(response)) case (_, None) => logger.debug(endpointOutput.codec.encode(response)) - Some(ValuedEndpointOutput(endpointOutput, response).prepend(sttp.tapir.statusCode, statusCode)) + ValuedEndpointOutput(endpointOutput, response).prepend(sttp.tapir.statusCode, statusCode) } - def exceptionHandler[F[_]]: ExceptionHandler[F] = ExceptionHandler.pure[F](ctx => + def tapirExceptionHandler[F[_]]: ExceptionHandler[F] = ExceptionHandler.pure[F](ctx => ctx.e match - case UnmanagedFailureException(failure: Failure) => defectHandler(failure) + case UnmanagedFailureException(failure: Failure) => Some(tapirDefectHandler(failure)) case e => - defectHandler( - ErrorResponse( - StatusCode.InternalServerError.code, - s"error:InternalServerError", - "Internal Server Error", - Some( - s"An unexpected error occurred when processing the request: " + - s"path=['${ctx.request.showShort}']" - ) - ), - Some(ctx.e) + Some( + tapirDefectHandler( + ErrorResponse( + StatusCode.InternalServerError.code, + s"error:InternalServerError", + "Internal Server Error", + Some( + s"An unexpected error occurred when processing the request: " + + s"path=['${ctx.request.showShort}']" + ) + ), + Some(ctx.e) + ) ) ) - def rejectHandler[F[_]]: RejectHandler[F] = RejectHandler.pure[F](resultFailure => - defectHandler( - ErrorResponse( - StatusCode.NotFound.code, - s"error:ResourcePathNotFound", - "Resource Path Not Found", - Some(s"The requested resource path doesn't exist.") + def tapirRejectHandler[F[_]]: RejectHandler[F] = RejectHandler.pure[F](resultFailure => + Some( + tapirDefectHandler( + ErrorResponse( + StatusCode.NotFound.code, + s"error:ResourcePathNotFound", + "Resource Path Not Found", + Some(s"The requested resource path doesn't exist.") + ) ) ) ) - def decodeFailureHandler: DecodeFailureHandler = (ctx: DecodeFailureContext) => { + def tapirDecodeFailureHandler: DecodeFailureHandler = (ctx: DecodeFailureContext) => { /** As per the Tapir Decode Failures documentation: * @@ -79,17 +86,39 @@ object CustomServerInterceptors { DefaultDecodeFailureHandler.respond(ctx) match case Some((sc, _)) => val details = FailureMessages.failureMessage(ctx) - defectHandler( - ErrorResponse( - sc.code, - s"error:RequestBodyDecodingFailure", - "Request Body Decoding Failure", - Some( - s"An error occurred when decoding the request body: " + - s"path=['${ctx.request.showShort}'], details=[$details]" + Some( + tapirDefectHandler( + ErrorResponse( + sc.code, + s"error:RequestBodyDecodingFailure", + "Request Body Decoding Failure", + Some( + s"An error occurred when decoding the request body: " + + s"path=['${ctx.request.showShort}'], details=[$details]" + ) ) ) ) case None => None } + + def http4sServiceErrorHandler: ServiceErrorHandler[Task] = (req: Request[Task]) => { case t: Throwable => + val res = tapirDefectHandler( + ErrorResponse( + StatusCode.InternalServerError.code, + s"error:InternalServerError", + "Internal Server Error", + Some( + s"An unexpected error occurred when servicing the request: " + + s"path=['${req.method.name} ${req.uri.copy(scheme = None, authority = None, fragment = None).toString}']" + ) + ), + Some(t) + ) + ZIO.succeed( + Response(Status.InternalServerError) + .withEntity(endpointOutput.codec.encode(res.value._2)) + .withContentType(`Content-Type`(MediaType.application.json)) + ) + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/ZHttp4sBlazeServer.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/ZHttp4sBlazeServer.scala index 05d56eb62b..1293185891 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/ZHttp4sBlazeServer.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/http/ZHttp4sBlazeServer.scala @@ -93,9 +93,9 @@ class ZHttp4sBlazeServer(micrometerRegistry: PrometheusMeterRegistry, metricsNam options <- ZIO.attempt { Http4sServerOptions .customiseInterceptors[Task] - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) .serverLog(None) .metricsInterceptor( srv.metricsInterceptor( @@ -123,6 +123,7 @@ class ZHttp4sBlazeServer(micrometerRegistry: PrometheusMeterRegistry, metricsNam ZIO.executor.flatMap(executor => BlazeServerBuilder[Task] .withExecutionContext(executor.asExecutionContext) + .withServiceErrorHandler(CustomServerInterceptors.http4sServiceErrorHandler) .bindHttp(port, "0.0.0.0") .withHttpApp(Router("/" -> http4sEndpoints).orNotFound) .serve diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala index 1708ca1517..67867bb2fb 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala @@ -19,7 +19,6 @@ import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation import org.hyperledger.identus.pollux.core.model.error.{CredentialServiceError, PresentationError} import org.hyperledger.identus.pollux.core.model.DidCommID import org.hyperledger.identus.pollux.core.service.CredentialService -import org.hyperledger.identus.pollux.sdjwt.SDJWT.* import org.hyperledger.identus.pollux.vc.jwt.{ DIDResolutionFailed, DIDResolutionSucceeded, @@ -29,8 +28,11 @@ import org.hyperledger.identus.pollux.vc.jwt.{ * } import org.hyperledger.identus.shared.crypto.* +import org.hyperledger.identus.shared.messaging.ConsumerJobConfig +import org.hyperledger.identus.shared.messaging.MessagingService.RetryStep import org.hyperledger.identus.shared.models.{KeyId, WalletAccessContext} -import zio.{ZIO, ZLayer} +import zio.{durationInt, Duration, ZIO, ZLayer} +import zio.prelude.OrdOps import java.time.Instant import java.util.Base64 @@ -229,4 +231,20 @@ trait BackgroundJobsHelper { case _ => ZIO.unit } } + + def retryStepsFromConfig(topicName: String, jobConfig: ConsumerJobConfig): Seq[RetryStep] = { + val retryTopics = jobConfig.retryStrategy match + case None => Seq.empty + case Some(rs) => + (1 to rs.maxRetries).map(i => + ( + s"$topicName-retry-$i", + rs.initialDelay.multipliedBy(Math.pow(2, i - 1).toLong).min(rs.maxDelay) + ) + ) + val topics = retryTopics prepended (topicName, 0.seconds) appended (s"$topicName-DLQ", Duration.Infinity) + (0 until topics.size - 1).map { i => + RetryStep(topics(i)._1, jobConfig.consumerCount, topics(i)._2, topics(i + 1)._1) + } + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/ConnectBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/ConnectBackgroundJobs.scala index 46335fd059..07cfd05a22 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/ConnectBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/ConnectBackgroundJobs.scala @@ -2,49 +2,63 @@ package org.hyperledger.identus.agent.server.jobs import org.hyperledger.identus.agent.server.config.AppConfig import org.hyperledger.identus.agent.server.jobs.BackgroundJobError.ErrorResponseReceivedFromPeerAgent -import org.hyperledger.identus.agent.walletapi.model.error.DIDSecretStorageError -import org.hyperledger.identus.agent.walletapi.model.error.DIDSecretStorageError.{KeyNotFoundError, WalletNotFoundError} import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService import org.hyperledger.identus.agent.walletapi.storage.DIDNonSecretStorage -import org.hyperledger.identus.connect.core.model.error.ConnectionServiceError.{ - InvalidStateForOperation, - RecordIdNotFound -} import org.hyperledger.identus.connect.core.model.ConnectionRecord import org.hyperledger.identus.connect.core.model.ConnectionRecord.* import org.hyperledger.identus.connect.core.service.ConnectionService import org.hyperledger.identus.mercury.* -import org.hyperledger.identus.mercury.model.error.SendMessageError import org.hyperledger.identus.resolvers.DIDResolver -import org.hyperledger.identus.shared.models.WalletAccessContext +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.{Message, WalletIdAndRecordId} +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds import zio.* import zio.metrics.* +import java.util.UUID + object ConnectBackgroundJobs extends BackgroundJobsHelper { - val didCommExchanges = { - for { - connectionService <- ZIO.service[ConnectionService] - config <- ZIO.service[AppConfig] - records <- connectionService - .findRecordsByStatesForAllWallets( - ignoreWithZeroRetries = true, - limit = config.connect.connectBgJobRecordsLimit, - ConnectionRecord.ProtocolState.ConnectionRequestPending, - ConnectionRecord.ProtocolState.ConnectionResponsePending - ) - _ <- ZIO.foreachPar(records)(performExchange).withParallelism(config.connect.connectBgJobProcessingParallelism) - } yield () - } + private val TOPIC_NAME = "connect" + + val connectFlowsHandler = for { + appConfig <- ZIO.service[AppConfig] + _ <- messaging.MessagingService.consumeWithRetryStrategy( + "identus-cloud-agent", + ConnectBackgroundJobs.handleMessage, + retryStepsFromConfig(TOPIC_NAME, appConfig.agent.messagingService.connectFlow) + ) + } yield () - private def performExchange( - record: ConnectionRecord - ): URIO[ + private def handleMessage(message: Message[UUID, WalletIdAndRecordId]): RIO[ DidOps & DIDResolver & HttpClient & ConnectionService & ManagedDIDService & DIDNonSecretStorage & AppConfig, Unit - ] = { + ] = + (for { + _ <- ZIO.logDebug(s"!!! Handling recordId: ${message.value} via Kafka queue") + connectionService <- ZIO.service[ConnectionService] + walletAccessContext = WalletAccessContext(WalletId.fromUUID(message.value.walletId)) + record <- connectionService + .findRecordById(message.value.recordId) + .provideSome(ZLayer.succeed(walletAccessContext)) + .someOrElseZIO(ZIO.dieMessage("Record Not Found")) + _ <- performExchange(record) + .tapSomeError { case (walletAccessContext, errorResponse) => + for { + connectService <- ZIO.service[ConnectionService] + _ <- connectService + .reportProcessingFailure(record.id, Some(errorResponse)) + .provideSomeLayer(ZLayer.succeed(walletAccessContext)) + } yield () + } + .catchAll { e => ZIO.fail(RuntimeException(s"Attempt failed with: ${e}")) } + } yield ()) @@ Metric + .gauge("connection_flow_did_com_exchange_job_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) + + private def performExchange(record: ConnectionRecord) = { import ProtocolState.* import Role.* @@ -179,26 +193,10 @@ object ConnectBackgroundJobs extends BackgroundJobsHelper { @@ Metric .gauge("connection_flow_inviter_process_connection_record_ms_gauge") .trackDurationWith(_.toMetricsSeconds) - case _ => ZIO.unit + case r => ZIO.logWarning(s"Invalid candidate record received for processing: $r") *> ZIO.unit } exchange - .tapError({ - case walletNotFound: WalletNotFoundError => - ZIO.logErrorCause( - s"Connect - Error processing record: ${record.id}", - Cause.fail(walletNotFound) - ) - case ((walletAccessContext, errorResponse)) => - for { - connectService <- ZIO.service[ConnectionService] - _ <- connectService - .reportProcessingFailure(record.id, Some(errorResponse)) - .provideSomeLayer(ZLayer.succeed(walletAccessContext)) - } yield () - }) - .catchAll(e => ZIO.logErrorCause(s"Connect - Error processing record: ${record.id} ", Cause.fail(e))) - .catchAllDefect(d => ZIO.logErrorCause(s"Connect - Defect processing record: ${record.id}", Cause.fail(d))) } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/DIDStateSyncBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/DIDStateSyncBackgroundJobs.scala index 5d4ff494ea..2ee44e91bc 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/DIDStateSyncBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/DIDStateSyncBackgroundJobs.scala @@ -1,17 +1,54 @@ package org.hyperledger.identus.agent.server.jobs -import org.hyperledger.identus.agent.walletapi.model.error.GetManagedDIDError -import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService -import org.hyperledger.identus.shared.models.WalletAccessContext +import org.hyperledger.identus.agent.server.config.AppConfig +import org.hyperledger.identus.agent.walletapi.service.{ManagedDIDService, WalletManagementService} +import org.hyperledger.identus.shared.messaging.{Message, MessagingService, Producer} +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletAdministrationContext, WalletId} +import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds import zio.* +import zio.metrics.Metric -object DIDStateSyncBackgroundJobs { +object DIDStateSyncBackgroundJobs extends BackgroundJobsHelper { - val syncDIDPublicationStateFromDlt: ZIO[WalletAccessContext with ManagedDIDService, GetManagedDIDError, Unit] = - for { + private val TOPIC_NAME = "sync-did-state" + + val didStateSyncTrigger = { + (for { + config <- ZIO.service[AppConfig] + producer <- ZIO.service[Producer[WalletId, WalletId]] + trigger = for { + walletManagementService <- ZIO.service[WalletManagementService] + wallets <- walletManagementService.listWallets().map(_._1) + _ <- ZIO.logInfo(s"Triggering DID state sync for '${wallets.size}' wallets") + _ <- ZIO.foreach(wallets)(w => producer.produce(TOPIC_NAME, w.id, w.id)) + } yield () + _ <- trigger + .catchAll(e => ZIO.logError(s"error while syncing DID publication state: $e")) + .provideSomeLayer(ZLayer.succeed(WalletAdministrationContext.Admin())) + .repeat(Schedule.spaced(config.pollux.didStateSyncTriggerRecurrenceDelay)) + } yield ()).debug.fork + } + + val didStateSyncHandler = for { + appConfig <- ZIO.service[AppConfig] + _ <- MessagingService.consumeWithRetryStrategy( + "identus-cloud-agent", + DIDStateSyncBackgroundJobs.handleMessage, + retryStepsFromConfig(TOPIC_NAME, appConfig.agent.messagingService.didStateSync) + ) + } yield () + + private def handleMessage(message: Message[WalletId, WalletId]): RIO[ManagedDIDService, Unit] = { + val effect = for { managedDidService <- ZIO.service[ManagedDIDService] _ <- managedDidService.syncManagedDIDState _ <- managedDidService.syncUnconfirmedUpdateOperations } yield () - + effect + .provideSomeLayer(ZLayer.succeed(WalletAccessContext(message.value))) + .catchAll(t => ZIO.logErrorCause("Unable to syncing DID publication state", Cause.fail(t))) + @@ Metric + .gauge("did_publication_state_sync_job_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/IssueBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/IssueBackgroundJobs.scala index ffc617df3c..3cdde2853f 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/IssueBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/IssueBackgroundJobs.scala @@ -2,40 +2,61 @@ package org.hyperledger.identus.agent.server.jobs import org.hyperledger.identus.agent.server.config.AppConfig import org.hyperledger.identus.agent.server.jobs.BackgroundJobError.ErrorResponseReceivedFromPeerAgent -import org.hyperledger.identus.agent.walletapi.model.error.DIDSecretStorageError.WalletNotFoundError -import org.hyperledger.identus.castor.core.model.did.* +import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService +import org.hyperledger.identus.agent.walletapi.storage.DIDNonSecretStorage import org.hyperledger.identus.mercury.* -import org.hyperledger.identus.mercury.protocol.issuecredential.* import org.hyperledger.identus.pollux.core.model.* import org.hyperledger.identus.pollux.core.model.error.CredentialServiceError import org.hyperledger.identus.pollux.core.service.CredentialService -import org.hyperledger.identus.shared.models.Failure +import org.hyperledger.identus.resolvers.DIDResolver +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.{Message, WalletIdAndRecordId} +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds import zio.* import zio.metrics.* +import java.util.UUID + object IssueBackgroundJobs extends BackgroundJobsHelper { - val issueCredentialDidCommExchanges = { - for { + private val TOPIC_NAME = "issue" + + val issueFlowsHandler = for { + appConfig <- ZIO.service[AppConfig] + _ <- messaging.MessagingService.consumeWithRetryStrategy( + "identus-cloud-agent", + IssueBackgroundJobs.handleMessage, + retryStepsFromConfig(TOPIC_NAME, appConfig.agent.messagingService.issueFlow) + ) + } yield () + + private def handleMessage(message: Message[UUID, WalletIdAndRecordId]): RIO[ + HttpClient & DidOps & DIDResolver & (CredentialService & DIDNonSecretStorage & (ManagedDIDService & AppConfig)), + Unit + ] = { + (for { + _ <- ZIO.logDebug(s"!!! Handling recordId: ${message.value} via Kafka queue") credentialService <- ZIO.service[CredentialService] - config <- ZIO.service[AppConfig] - records <- credentialService - .getIssueCredentialRecordsByStatesForAllWallets( - ignoreWithZeroRetries = true, - limit = config.pollux.issueBgJobRecordsLimit, - IssueCredentialRecord.ProtocolState.OfferPending, - IssueCredentialRecord.ProtocolState.RequestPending, - IssueCredentialRecord.ProtocolState.RequestGenerated, - IssueCredentialRecord.ProtocolState.RequestReceived, - IssueCredentialRecord.ProtocolState.CredentialPending, - IssueCredentialRecord.ProtocolState.CredentialGenerated - ) - _ <- ZIO - .foreachPar(records)(performIssueCredentialExchange) - .withParallelism(config.pollux.issueBgJobProcessingParallelism) - } yield () + walletAccessContext = WalletAccessContext(WalletId.fromUUID(message.value.walletId)) + record <- credentialService + .findById(DidCommID(message.value.recordId.toString)) + .provideSome(ZLayer.succeed(walletAccessContext)) + .someOrElseZIO(ZIO.dieMessage(s"Record Not Found: ${message.value.recordId}")) + _ <- performIssueCredentialExchange(record) + .tapSomeError { case (walletAccessContext, errorResponse) => + for { + credentialService <- ZIO.service[CredentialService] + _ <- credentialService + .reportProcessingFailure(record.id, Some(errorResponse)) + .provideSomeLayer(ZLayer.succeed(walletAccessContext)) + } yield () + } + .catchAll { e => ZIO.fail(RuntimeException(s"Attempt failed with: ${e}")) } + } yield ()) @@ Metric + .gauge("issuance_flow_did_com_exchange_job_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) } private def counterMetric(key: String) = Metric @@ -136,7 +157,7 @@ object IssueBackgroundJobs extends BackgroundJobsHelper { "issuance_flow_issuer_send_credential_msg_succeed_counter" ) - val aux = for { + val exchange = for { _ <- ZIO.logDebug(s"Running action with records => $record") _ <- record match { // Offer should be sent from Issuer to Holder @@ -227,8 +248,8 @@ object IssueBackgroundJobs extends BackgroundJobsHelper { val holderPendingToGeneratedFlow = for { walletAccessContext <- ZIO .fromOption(offer.to) + .mapError(_ => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) .flatMap(buildWalletAccessContextLayer) - .mapError(e => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) result <- for { credentialService <- ZIO.service[CredentialService] _ <- credentialService @@ -273,8 +294,8 @@ object IssueBackgroundJobs extends BackgroundJobsHelper { val holderPendingToGeneratedFlow = for { walletAccessContext <- ZIO .fromOption(offer.to) + .mapError(_ => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) .flatMap(buildWalletAccessContextLayer) - .mapError(e => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) result <- for { credentialService <- ZIO.service[CredentialService] _ <- credentialService @@ -319,8 +340,8 @@ object IssueBackgroundJobs extends BackgroundJobsHelper { val holderPendingToGeneratedFlow = for { walletAccessContext <- ZIO .fromOption(offer.to) + .mapError(_ => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) .flatMap(buildWalletAccessContextLayer) - .mapError(e => CredentialServiceError.CredentialOfferMissingField(id.value, "recipient")) result <- for { credentialService <- ZIO.service[CredentialService] @@ -629,33 +650,12 @@ object IssueBackgroundJobs extends BackgroundJobsHelper { @@ IssuerSendCredentialAll @@ Metric .gauge("issuance_flow_issuer_send_cred_flow_ms_gauge") .trackDurationWith(_.toMetricsSeconds) - - case record: IssueCredentialRecord => - ZIO.logDebug(s"IssuanceRecord: ${record.id} - ${record.protocolState}") *> ZIO.unit + case r: IssueCredentialRecord => + ZIO.logWarning(s"Invalid candidate record received for processing: $r") *> ZIO.unit } } yield () - aux - .tapError( - { - case walletNotFound: WalletNotFoundError => ZIO.unit - case CredentialServiceError.RecordNotFound(_, _) => ZIO.unit - case CredentialServiceError.UnsupportedDidFormat(_) => ZIO.unit - case failure: Failure => ZIO.unit - case ((walletAccessContext, failure)) => - for { - credentialService <- ZIO.service[CredentialService] - _ <- credentialService - .reportProcessingFailure(record.id, Some(failure)) - .provideSomeLayer(ZLayer.succeed(walletAccessContext)) - } yield () - } - ) - .catchAll(e => ZIO.logErrorCause(s"Issue Credential - Error processing record: ${record.id} ", Cause.fail(e))) - .catchAllDefect(d => - ZIO.logErrorCause(s"Issue Credential - Defect processing record: ${record.id}", Cause.fail(d)) - ) - + exchange } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala index 9938b6b50b..4bfb247176 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala @@ -30,17 +30,18 @@ import org.hyperledger.identus.pollux.sdjwt.{HolderPrivateKey, IssuerPublicKey, import org.hyperledger.identus.pollux.vc.jwt.{DidResolver as JwtDidResolver, Issuer as JwtIssuer, JWT, JwtPresentation} import org.hyperledger.identus.resolvers.DIDResolver import org.hyperledger.identus.shared.http.* -import org.hyperledger.identus.shared.models.* +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.{Message, WalletIdAndRecordId} +import org.hyperledger.identus.shared.models.{Failure, *} import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds import zio.* -import zio.json.* -import zio.json.ast.Json import zio.metrics.* import zio.prelude.Validation import zio.prelude.ZValidation.{Failure as ZFailure, *} -import java.time.{Clock, Instant, ZoneId} +import java.time.{Instant, ZoneId} +import java.util.UUID object PresentBackgroundJobs extends BackgroundJobsHelper { @@ -55,47 +56,50 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { private type MESSAGING_RESOURCES = DidOps & DIDResolver & HttpClient - val presentProofExchanges: ZIO[RESOURCES, Throwable, Unit] = { - for { + private val TOPIC_NAME = "present" + + val presentFlowsHandler = for { + appConfig <- ZIO.service[AppConfig] + _ <- messaging.MessagingService.consumeWithRetryStrategy( + "identus-cloud-agent", + PresentBackgroundJobs.handleMessage, + retryStepsFromConfig(TOPIC_NAME, appConfig.agent.messagingService.presentFlow) + ) + } yield () + + private def handleMessage(message: Message[UUID, WalletIdAndRecordId]): RIO[ + RESOURCES, + Unit + ] = { + (for { + _ <- ZIO.logDebug(s"!!! Present Proof Handling recordId: ${message.value} via Kafka queue") presentationService <- ZIO.service[PresentationService] - config <- ZIO.service[AppConfig] - records <- presentationService - .getPresentationRecordsByStatesForAllWallets( - ignoreWithZeroRetries = true, - limit = config.pollux.presentationBgJobRecordsLimit, - PresentationRecord.ProtocolState.RequestPending, - PresentationRecord.ProtocolState.PresentationPending, - PresentationRecord.ProtocolState.PresentationGenerated, - PresentationRecord.ProtocolState.PresentationReceived - ) - .mapError(err => Throwable(s"Error occurred while getting Presentation records: $err")) - _ <- ZIO.logInfo(s"Processing ${records.size} Presentation records") - _ <- ZIO - .foreachPar(records)(performPresentProofExchange) - .withParallelism(config.pollux.presentationBgJobProcessingParallelism) - } yield () + walletAccessContext = WalletAccessContext(WalletId.fromUUID(message.value.walletId)) + record <- presentationService + .findPresentationRecord(DidCommID(message.value.recordId.toString)) + .provideSome(ZLayer.succeed(walletAccessContext)) + .someOrElseZIO(ZIO.dieMessage("Record Not Found")) + _ <- performPresentProofExchange(record) + .tapSomeError { case f: Failure => + for { + presentationService <- ZIO.service[PresentationService] + _ <- presentationService + .reportProcessingFailure(record.id, Some(f)) + } yield () + } + .catchAll { e => ZIO.fail(RuntimeException(s"Attempt failed with: ${e}")) } + } yield ()) @@ Metric + .gauge("present_proof_flow_did_com_exchange_job_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) } private def counterMetric(key: String) = Metric .counterInt(key) .fromConst(1) - private def performPresentProofExchange(record: PresentationRecord): URIO[RESOURCES, Unit] = - aux(record) - .catchAll { - case ex: Failure => - ZIO - .service[PresentationService] - .flatMap(_.reportProcessingFailure(record.id, Some(ex))) - case ex => ZIO.logErrorCause(s"PresentBackgroundJobs - Error processing record: ${record.id}", Cause.fail(ex)) - } - .catchAllDefect(d => - ZIO.logErrorCause(s"PresentBackgroundJobs - Defect processing record: ${record.id}", Cause.fail(d)) - ) - - private def aux(record: PresentationRecord): ZIO[RESOURCES, ERROR, Unit] = { + private def performPresentProofExchange(record: PresentationRecord): ZIO[RESOURCES, ERROR, Unit] = { import org.hyperledger.identus.pollux.core.model.PresentationRecord.ProtocolState.* - for { + val exchange = for { _ <- ZIO.logDebug(s"Running action with records => $record") _ <- record match { case PresentationRecord( @@ -604,6 +608,8 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { ZIO.logWarning(s"Unhandled PresentationRecord state: ${record.protocolState}") } } yield () + + exchange } object Prover { diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/StatusListJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/StatusListJobs.scala index 71d02db3e2..1fe5d77551 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/StatusListJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/StatusListJobs.scala @@ -1,131 +1,181 @@ package org.hyperledger.identus.agent.server.jobs import org.hyperledger.identus.agent.server.config.AppConfig +import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService import org.hyperledger.identus.castor.core.model.did.VerificationRelationship +import org.hyperledger.identus.castor.core.service.DIDService import org.hyperledger.identus.mercury.* import org.hyperledger.identus.mercury.protocol.revocationnotificaiton.RevocationNotification +import org.hyperledger.identus.pollux.core.model.{CredInStatusList, CredentialStatusListWithCreds} import org.hyperledger.identus.pollux.core.service.{CredentialService, CredentialStatusListService} -import org.hyperledger.identus.pollux.vc.jwt.revocation.{VCStatusList2021, VCStatusList2021Error} -import org.hyperledger.identus.shared.models.* +import org.hyperledger.identus.pollux.vc.jwt.revocation.{BitString, VCStatusList2021, VCStatusList2021Error} +import org.hyperledger.identus.resolvers.DIDResolver +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.{Message, Producer, WalletIdAndRecordId} +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds import zio.* import zio.metrics.Metric +import java.util.UUID + object StatusListJobs extends BackgroundJobsHelper { - val syncRevocationStatuses = - for { - credentialStatusListService <- ZIO.service[CredentialStatusListService] - credentialService <- ZIO.service[CredentialService] - credentialStatusListsWithCreds <- credentialStatusListService.getCredentialsAndItsStatuses - @@ Metric - .gauge("revocation_status_list_sync_get_status_lists_w_creds_ms_gauge") - .trackDurationWith(_.toMetricsSeconds) + private val TOPIC_NAME = "sync-status-list" - updatedVcStatusListsCredsEffects = credentialStatusListsWithCreds.map { statusListWithCreds => - val vcStatusListCredString = statusListWithCreds.statusListCredential - val walletAccessContext = WalletAccessContext(statusListWithCreds.walletId) + val statusListsSyncTrigger = { + (for { + config <- ZIO.service[AppConfig] + producer <- ZIO.service[Producer[UUID, WalletIdAndRecordId]] + trigger = for { + credentialStatusListService <- ZIO.service[CredentialStatusListService] + walletAndStatusListIds <- credentialStatusListService.getCredentialStatusListIds + _ <- ZIO.logInfo(s"Triggering status list revocation sync for '${walletAndStatusListIds.size}' status lists") + _ <- ZIO.foreach(walletAndStatusListIds) { (walletId, statusListId) => + producer.produce(TOPIC_NAME, walletId.toUUID, WalletIdAndRecordId(walletId.toUUID, statusListId)) + } + } yield () + _ <- trigger.repeat(Schedule.spaced(config.pollux.statusListSyncTriggerRecurrenceDelay)) + } yield ()).debug.fork + } - val effect = for { - vcStatusListCredJson <- ZIO - .fromEither(io.circe.parser.parse(vcStatusListCredString)) - .mapError(_.underlying) - issuer <- createJwtVcIssuer( - statusListWithCreds.issuer, - VerificationRelationship.AssertionMethod, - None - ) - vcStatusListCred <- VCStatusList2021 - .decodeFromJson(vcStatusListCredJson, issuer) - .mapError(x => new Throwable(x.msg)) - bitString <- vcStatusListCred.getBitString.mapError(x => new Throwable(x.msg)) - updateBitStringEffects = statusListWithCreds.credentials.map { cred => - if cred.isCanceled then { - val sendMessageEffect = for { - maybeIssueCredentialRecord <- credentialService.findById(cred.issueCredentialRecordId) - issueCredentialRecord <- ZIO - .fromOption(maybeIssueCredentialRecord) - .mapError(_ => - new Throwable(s"Issue credential record not found by id: ${cred.issueCredentialRecordId}") - ) - issueCredentialData <- ZIO - .fromOption(issueCredentialRecord.issueCredentialData) - .mapError(_ => - new Throwable( - s"Issue credential data not found in issue credential record by id: ${cred.issueCredentialRecordId}" - ) - ) - issueCredentialProtocolThreadId <- ZIO - .fromOption(issueCredentialData.thid) - .mapError(_ => new Throwable("thid not found in issue credential data")) - revocationNotification = RevocationNotification.build( - issueCredentialData.from, - issueCredentialData.to, - issueCredentialProtocolThreadId = issueCredentialProtocolThreadId - ) - didCommAgent <- buildDIDCommAgent(issueCredentialData.from) - response <- MessagingService - .send(revocationNotification.makeMessage) - .provideSomeLayer(didCommAgent) @@ Metric - .gauge("revocation_status_list_sync_revocation_notification_ms_gauge") - .trackDurationWith(_.toMetricsSeconds) - } yield response + val statusListSyncHandler = for { + appConfig <- ZIO.service[AppConfig] + _ <- messaging.MessagingService.consumeWithRetryStrategy( + "identus-cloud-agent", + StatusListJobs.handleMessage, + retryStepsFromConfig(TOPIC_NAME, appConfig.agent.messagingService.statusListSync) + ) + } yield () - val updateBitStringEffect = bitString.setRevokedInPlace(cred.statusListIndex, true) + private def handleMessage(message: Message[UUID, WalletIdAndRecordId]): RIO[ + DIDService & ManagedDIDService & CredentialService & DidOps & DIDResolver & HttpClient & + CredentialStatusListService, + Unit + ] = { + (for { + _ <- ZIO.logDebug(s"!!! Handling recordId: ${message.value} via Kafka queue") + credentialStatusListService <- ZIO.service[CredentialStatusListService] + walletAccessContext = WalletAccessContext(WalletId.fromUUID(message.value.walletId)) + statusListWithCreds <- credentialStatusListService + .getCredentialStatusListWithCreds(message.value.recordId) + .provideSome(ZLayer.succeed(walletAccessContext)) + _ <- updateStatusList(statusListWithCreds) + } yield ()) @@ Metric + .gauge("revocation_status_list_sync_job_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) + } - val updateAndNotify = for { - updated <- updateBitStringEffect.mapError(x => new Throwable(x.message)) - _ <- - if !cred.isProcessed then - sendMessageEffect.flatMap { resp => - if (resp.status >= 200 && resp.status < 300) - ZIO.logInfo("successfully sent revocation notification message") - else ZIO.logError(s"failed to send revocation notification message") - } - else ZIO.unit - } yield updated - updateAndNotify.provideSomeLayer(ZLayer.succeed(walletAccessContext)) @@ Metric - .gauge("revocation_status_list_sync_process_single_credential_ms_gauge") - .trackDurationWith(_.toMetricsSeconds) - } else ZIO.unit - } - _ <- ZIO - .collectAll(updateBitStringEffects) + private def updateStatusList(statusListWithCreds: CredentialStatusListWithCreds) = { + for { + credentialStatusListService <- ZIO.service[CredentialStatusListService] + vcStatusListCredString = statusListWithCreds.statusListCredential + walletAccessContext = WalletAccessContext(statusListWithCreds.walletId) + effect = for { + vcStatusListCredJson <- ZIO + .fromEither(io.circe.parser.parse(vcStatusListCredString)) + .mapError(_.underlying) + issuer <- createJwtVcIssuer(statusListWithCreds.issuer, VerificationRelationship.AssertionMethod, None) + vcStatusListCred <- VCStatusList2021 + .decodeFromJson(vcStatusListCredJson, issuer) + .mapError(x => new Throwable(x.msg)) + bitString <- vcStatusListCred.getBitString.mapError(x => new Throwable(x.msg)) + _ <- ZIO.collectAll( + statusListWithCreds.credentials.map(c => + updateBitStringForCredentialAndNotify(bitString, c, walletAccessContext) + ) + ) + unprocessedEntityIds = statusListWithCreds.credentials.collect { + case x if !x.isProcessed && x.isCanceled => x.id + } + _ <- credentialStatusListService + .markAsProcessedMany(unprocessedEntityIds) + @@ Metric + .gauge("revocation_status_list_sync_mark_as_processed_many_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) - unprocessedEntityIds = statusListWithCreds.credentials.collect { - case x if !x.isProcessed && x.isCanceled => x.id - } - _ <- credentialStatusListService - .markAsProcessedMany(unprocessedEntityIds) - @@ Metric - .gauge("revocation_status_list_sync_mark_as_processed_many_ms_gauge") - .trackDurationWith(_.toMetricsSeconds) + updatedVcStatusListCred <- vcStatusListCred.updateBitString(bitString).mapError { + case VCStatusList2021Error.EncodingError(msg: String) => new Throwable(msg) + case VCStatusList2021Error.DecodingError(msg: String) => new Throwable(msg) + } + vcStatusListCredJsonString <- updatedVcStatusListCred.toJsonWithEmbeddedProof.map(_.spaces2) + _ <- credentialStatusListService.updateStatusListCredential( + statusListWithCreds.id, + vcStatusListCredJsonString + ) + } yield () + _ <- effect + .catchAll(e => + ZIO.logErrorCause(s"Error processing status list record: ${statusListWithCreds.id} ", Cause.fail(e)) + ) + .catchAllDefect(d => + ZIO.logErrorCause(s"Defect processing status list record: ${statusListWithCreds.id}", Cause.fail(d)) + ) + .provideSomeLayer(ZLayer.succeed(walletAccessContext)) + } yield () + } - updatedVcStatusListCred <- vcStatusListCred.updateBitString(bitString).mapError { - case VCStatusList2021Error.EncodingError(msg: String) => new Throwable(msg) - case VCStatusList2021Error.DecodingError(msg: String) => new Throwable(msg) - } - vcStatusListCredJsonString <- updatedVcStatusListCred.toJsonWithEmbeddedProof - .map(_.spaces2) - _ <- credentialStatusListService - .updateStatusListCredential(statusListWithCreds.id, vcStatusListCredJsonString) - } yield () + private def updateBitStringForCredentialAndNotify( + bitString: BitString, + credInStatusList: CredInStatusList, + walletAccessContext: WalletAccessContext + ) = { + for { + credentialService <- ZIO.service[CredentialService] + _ <- + if credInStatusList.isCanceled then { + val updateBitStringEffect = bitString.setRevokedInPlace(credInStatusList.statusListIndex, true) + val notifyEffect = sendRevocationNotificationMessage(credInStatusList) + val updateAndNotify = for { + updated <- updateBitStringEffect.mapError(x => new Throwable(x.message)) + _ <- + if !credInStatusList.isProcessed then + notifyEffect.flatMap { resp => + if (resp.status >= 200 && resp.status < 300) + ZIO.logInfo("successfully sent revocation notification message") + else ZIO.logError(s"failed to send revocation notification message") + } + else ZIO.unit + } yield updated + updateAndNotify.provideSomeLayer(ZLayer.succeed(walletAccessContext)) @@ Metric + .gauge("revocation_status_list_sync_process_single_credential_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) + } else ZIO.unit + } yield () + } - effect - .catchAll(e => - ZIO.logErrorCause(s"Error processing status list record: ${statusListWithCreds.id} ", Cause.fail(e)) - ) - .catchAllDefect(d => - ZIO.logErrorCause(s"Defect processing status list record: ${statusListWithCreds.id}", Cause.fail(d)) + private def sendRevocationNotificationMessage( + credInStatusList: CredInStatusList + ) = { + for { + credentialService <- ZIO.service[CredentialService] + maybeIssueCredentialRecord <- credentialService.findById(credInStatusList.issueCredentialRecordId) + issueCredentialRecord <- ZIO + .fromOption(maybeIssueCredentialRecord) + .mapError(_ => + new Throwable(s"Issue credential record not found by id: ${credInStatusList.issueCredentialRecordId}") + ) + issueCredentialData <- ZIO + .fromOption(issueCredentialRecord.issueCredentialData) + .mapError(_ => + new Throwable( + s"Issue credential data not found in issue credential record by id: ${credInStatusList.issueCredentialRecordId}" ) - .provideSomeLayer(ZLayer.succeed(walletAccessContext)) - - } - config <- ZIO.service[AppConfig] - _ <- (ZIO - .collectAll(updatedVcStatusListsCredsEffects) @@ Metric - .gauge("revocation_status_list_sync_process_status_lists_w_creds_ms_gauge") - .trackDurationWith(_.toMetricsSeconds)) - .withParallelism(config.pollux.syncRevocationStatusesBgJobProcessingParallelism) - } yield () + ) + issueCredentialProtocolThreadId <- ZIO + .fromOption(issueCredentialData.thid) + .mapError(_ => new Throwable("thid not found in issue credential data")) + revocationNotification = RevocationNotification.build( + issueCredentialData.from, + issueCredentialData.to, + issueCredentialProtocolThreadId = issueCredentialProtocolThreadId + ) + didCommAgent <- buildDIDCommAgent(issueCredentialData.from) + response <- MessagingService + .send(revocationNotification.makeMessage) + .provideSomeLayer(didCommAgent) @@ Metric + .gauge("revocation_status_list_sync_revocation_notification_ms_gauge") + .trackDurationWith(_.toMetricsSeconds) + } yield response + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerError.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerError.scala index 5a27032b75..4c7208fda0 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerError.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerError.scala @@ -1,6 +1,6 @@ package org.hyperledger.identus.didcomm.controller -import org.hyperledger.identus.mercury.model.DidId +import org.hyperledger.identus.mercury.model.{DidId, PIURI} import org.hyperledger.identus.shared.models.{Failure, KeyId, StatusCode} sealed trait DIDCommControllerError extends Failure { @@ -39,4 +39,10 @@ object DIDCommControllerError { override def userFacingMessage: String = s"The Peer DID does not contain the required key: DID=${did.value}, keyId=${keyId.value}" } + + final case class UnsupportedPIURI(piuri: PIURI) extends DIDCommControllerError { + override def statusCode: StatusCode = StatusCode.UnprocessableContent + override def userFacingMessage: String = + s"The Protocol Identifier URI (URI) found in the DIDComm message is not supported: PIURI=$piuri" + } } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala index b910ace0f4..b13d522e03 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala @@ -184,8 +184,8 @@ class DIDCommControllerImpl( /* * Unknown Message */ - private val handleUnknownMessage: PartialFunction[Message, UIO[String]] = { case _ => - ZIO.succeed("Unknown Message Type") + private val handleUnknownMessage: PartialFunction[Message, IO[UnsupportedPIURI, String]] = { case msg => + ZIO.fail(UnsupportedPIURI(msg.piuri)) } } diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/issue/controller/IssueControllerTestTools.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/issue/controller/IssueControllerTestTools.scala index c7d1bd7a8f..4cb227e8ff 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/issue/controller/IssueControllerTestTools.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/issue/controller/IssueControllerTestTools.scala @@ -69,9 +69,9 @@ trait IssueControllerTestTools extends PostgresTestContainerSupport { def bootstrapOptions[F[_]](monadError: MonadError[F]): CustomiseInterceptors[F, Any] = { new CustomiseInterceptors[F, Any](_ => ()) - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) } def httpBackend(controller: IssueController, authenticator: AuthenticatorWithAuthZ[BaseEntity]) = { diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala index 6facffe5ed..fb4ce6f7ab 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala @@ -12,16 +12,15 @@ import org.hyperledger.identus.oid4vci.storage.InMemoryIssuanceSessionService import org.hyperledger.identus.pollux.core.model.oid4vci.CredentialConfiguration import org.hyperledger.identus.pollux.core.model.CredentialFormat import org.hyperledger.identus.pollux.core.repository.{ - CredentialRepository, CredentialRepositoryInMemory, CredentialStatusListRepositoryInMemory } import org.hyperledger.identus.pollux.core.service.* import org.hyperledger.identus.pollux.core.service.uriResolvers.ResourceUrlResolver import org.hyperledger.identus.pollux.vc.jwt.PrismDidResolver +import org.hyperledger.identus.shared.messaging.{MessagingService, MessagingServiceConfig, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.{Clock, Random, URLayer, ZIO, ZLayer} -import zio.json.* import zio.json.ast.Json import zio.mock.MockSpecDefault import zio.test.* @@ -54,6 +53,8 @@ object OIDCCredentialIssuerServiceSpec GenericSecretStorageInMemory.layer, LinkSecretServiceImpl.layer, CredentialServiceImpl.layer, + (MessagingServiceConfig.inMemoryLayer >>> MessagingService.serviceLayer >>> + MessagingService.producerLayer[UUID, WalletIdAndRecordId]).orDie, OIDCCredentialIssuerServiceImpl.layer ) diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionTestTools.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionTestTools.scala index 19636104a5..55b93f3007 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionTestTools.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionTestTools.scala @@ -97,9 +97,9 @@ trait CredentialDefinitionTestTools extends PostgresTestContainerSupport { def bootstrapOptions[F[_]](monadError: MonadError[F]) = { new CustomiseInterceptors[F, Any](_ => ()) - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) } def httpBackend( diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/schema/CredentialSchemaTestTools.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/schema/CredentialSchemaTestTools.scala index 5917f13f1c..7f72581960 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/schema/CredentialSchemaTestTools.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/schema/CredentialSchemaTestTools.scala @@ -96,9 +96,9 @@ trait CredentialSchemaTestTools extends PostgresTestContainerSupport { def bootstrapOptions[F[_]](monadError: MonadError[F]) = { new CustomiseInterceptors[F, Any](_ => ()) - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) } def httpBackend( diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/system/controller/SystemControllerTestTools.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/system/controller/SystemControllerTestTools.scala index 95ed827fec..80f15ce237 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/system/controller/SystemControllerTestTools.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/system/controller/SystemControllerTestTools.scala @@ -41,9 +41,9 @@ trait SystemControllerTestTools { def bootstrapOptions[F[_]](monadError: MonadError[F]): CustomiseInterceptors[F, Any] = { new CustomiseInterceptors[F, Any](_ => ()) - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) } def httpBackend(controller: SystemController) = { diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/verification/controller/VcVerificationControllerTestTools.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/verification/controller/VcVerificationControllerTestTools.scala index d3ca097e3d..e4da96b640 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/verification/controller/VcVerificationControllerTestTools.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/verification/controller/VcVerificationControllerTestTools.scala @@ -70,9 +70,9 @@ trait VcVerificationControllerTestTools extends PostgresTestContainerSupport { def bootstrapOptions[F[_]](monadError: MonadError[F]): CustomiseInterceptors[F, Any] = { new CustomiseInterceptors[F, Any](_ => ()) - .exceptionHandler(CustomServerInterceptors.exceptionHandler) - .rejectHandler(CustomServerInterceptors.rejectHandler) - .decodeFailureHandler(CustomServerInterceptors.decodeFailureHandler) + .exceptionHandler(CustomServerInterceptors.tapirExceptionHandler) + .rejectHandler(CustomServerInterceptors.tapirRejectHandler) + .decodeFailureHandler(CustomServerInterceptors.tapirDecodeFailureHandler) } def httpBackend(controller: VcVerificationController, authenticator: AuthenticatorWithAuthZ[BaseEntity]) = { diff --git a/cloud-agent/service/wallet-api/src/main/resources/sql/agent/V15__add_did_index_table.sql b/cloud-agent/service/wallet-api/src/main/resources/sql/agent/V15__add_did_index_table.sql new file mode 100644 index 0000000000..5a59c4a121 --- /dev/null +++ b/cloud-agent/service/wallet-api/src/main/resources/sql/agent/V15__add_did_index_table.sql @@ -0,0 +1,19 @@ +-- Last used DID Index per wallet (solving race condition) +CREATE TABLE public.last_did_index_per_wallet +( + "wallet_id" UUID REFERENCES public.wallet ("wallet_id") NOT NULL PRIMARY KEY, + "last_used_index" INT NOT NULL +); + +ALTER TABLE public.last_did_index_per_wallet + ENABLE ROW LEVEL SECURITY; + +CREATE +POLICY last_did_index_per_wallet_wallet_isolation +ON public.last_did_index_per_wallet +USING (wallet_id = current_setting('app.current_wallet_id')::UUID); + +INSERT INTO public.last_did_index_per_wallet(wallet_id, last_used_index) +SELECT wallet_id, MAX(did_index) +FROM public.prism_did_wallet_state +GROUP BY wallet_id; \ No newline at end of file diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala index 861f3a8b10..37e8543b94 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala @@ -1,8 +1,7 @@ package org.hyperledger.identus.agent.walletapi.service import org.hyperledger.identus.agent.walletapi.model.* -import org.hyperledger.identus.agent.walletapi.model.error.* -import org.hyperledger.identus.agent.walletapi.model.error.given +import org.hyperledger.identus.agent.walletapi.model.error.{*, given} import org.hyperledger.identus.agent.walletapi.service.handler.{DIDCreateHandler, DIDUpdateHandler, PublicationHandler} import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService.DEFAULT_MASTER_KEY_ID import org.hyperledger.identus.agent.walletapi.storage.{DIDNonSecretStorage, DIDSecretStorage, WalletSecretStorage} @@ -32,7 +31,6 @@ class ManagedDIDServiceImpl private[walletapi] ( override private[walletapi] val nonSecretStorage: DIDNonSecretStorage, walletSecretStorage: WalletSecretStorage, apollo: Apollo, - createDIDSem: Semaphore ) extends ManagedDIDService { private val AGREEMENT_KEY_ID = KeyId("agreement") @@ -127,7 +125,7 @@ class ManagedDIDServiceImpl private[walletapi] ( def createAndStoreDID( didTemplate: ManagedDIDTemplate ): ZIO[WalletAccessContext, CreateManagedDIDError, LongFormPrismDID] = { - val effect = for { + for { _ <- ZIO .fromEither(ManagedDIDTemplateValidator.validate(didTemplate, defaultDidDocumentServices)) .mapError { x => @@ -144,15 +142,6 @@ class ManagedDIDServiceImpl private[walletapi] ( .mapError(CreateManagedDIDError.InvalidOperation.apply) _ <- material.persist.mapError(CreateManagedDIDError.WalletStorageError.apply) } yield PrismDID.buildLongFormFromOperation(material.operation) - - // This synchronizes createDID effect to only allow 1 execution at a time - // to avoid concurrent didIndex update. Long-term solution should be - // solved at the DB level. - // - // Performance may be improved by not synchronizing the whole operation, - // but only the counter increment part allowing multiple in-flight create operations - // once didIndex is acquired. - createDIDSem.withPermit(effect) } def updateManagedDID( @@ -385,7 +374,6 @@ object ManagedDIDServiceImpl { nonSecretStorage <- ZIO.service[DIDNonSecretStorage] walletSecretStorage <- ZIO.service[WalletSecretStorage] apollo <- ZIO.service[Apollo] - createDIDSem <- Semaphore.make(1) } yield ManagedDIDServiceImpl( defaultDidDocumentServices, didService, @@ -393,8 +381,7 @@ object ManagedDIDServiceImpl { secretStorage, nonSecretStorage, walletSecretStorage, - apollo, - createDIDSem + apollo ) } } diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala index 795e6d6199..02b5142152 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala @@ -20,7 +20,6 @@ class ManagedDIDServiceWithEventNotificationImpl( override private[walletapi] val nonSecretStorage: DIDNonSecretStorage, walletSecretStorage: WalletSecretStorage, apollo: Apollo, - createDIDSem: Semaphore, eventNotificationService: EventNotificationService ) extends ManagedDIDServiceImpl( defaultDidDocumentServices, @@ -29,8 +28,7 @@ class ManagedDIDServiceWithEventNotificationImpl( secretStorage, nonSecretStorage, walletSecretStorage, - apollo, - createDIDSem + apollo ) { private val didStatusUpdatedEventName = "DIDStatusUpdated" @@ -81,7 +79,6 @@ object ManagedDIDServiceWithEventNotificationImpl { nonSecretStorage, walletSecretStorage, apollo, - createDIDSem, eventNotificationService ) } diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/handler/DIDCreateHandler.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/handler/DIDCreateHandler.scala index 66fec256bb..d87ef1c91d 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/handler/DIDCreateHandler.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/handler/DIDCreateHandler.scala @@ -31,12 +31,7 @@ private[walletapi] class DIDCreateHandler( walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) seed <- walletSecretStorage.findWalletSeed .someOrElseZIO(ZIO.dieMessage(s"Wallet seed for wallet $walletId does not exist")) - didIndex <- nonSecretStorage - .getMaxDIDIndex() - .mapBoth( - CreateManagedDIDError.WalletStorageError.apply, - maybeIdx => maybeIdx.map(_ + 1).getOrElse(0) - ) + didIndex <- nonSecretStorage.incrementAndGetNextDIDIndex generated <- operationFactory.makeCreateOperation(masterKeyId, seed.toByteArray)(didIndex, didTemplate) (createOperation, keys) = generated state = ManagedDIDState(createOperation, didIndex, PublicationState.Created()) diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/JdbcDIDNonSecretStorage.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/JdbcDIDNonSecretStorage.scala index bfdca44f73..7f86258e80 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/JdbcDIDNonSecretStorage.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/JdbcDIDNonSecretStorage.scala @@ -1,27 +1,21 @@ package org.hyperledger.identus.agent.walletapi.sql +import cats.implicits.toFunctorOps import doobie.* import doobie.implicits.* import doobie.postgres.implicits.* import org.hyperledger.identus.agent.walletapi.model.* import org.hyperledger.identus.agent.walletapi.storage.DIDNonSecretStorage -import org.hyperledger.identus.castor.core.model.did.{ - EllipticCurve, - InternalKeyPurpose, - PrismDID, - ScheduledDIDOperationStatus, - VerificationRelationship -} +import org.hyperledger.identus.castor.core.model.did.* import org.hyperledger.identus.mercury.model.DidId import org.hyperledger.identus.shared.db.ContextAwareTask -import org.hyperledger.identus.shared.db.Implicits.* -import org.hyperledger.identus.shared.db.Implicits.given +import org.hyperledger.identus.shared.db.Implicits.{*, given} import org.hyperledger.identus.shared.models.{KeyId, WalletAccessContext, WalletId} import zio.* import zio.interop.catz.* import java.time.Instant -import scala.collection.immutable.ArraySeq +import java.util.Objects class JdbcDIDNonSecretStorage(xa: Transactor[ContextAwareTask], xb: Transactor[Task]) extends DIDNonSecretStorage { @@ -109,11 +103,11 @@ class JdbcDIDNonSecretStorage(xa: Transactor[ContextAwareTask], xb: Transactor[T _ <- insertHdKeyIO.updateMany(randKeyValues(now)) } yield () - for { + (for { walletCtx <- ZIO.service[WalletAccessContext] now <- Clock.instant _ <- txnIO(now, walletCtx.walletId).transactWallet(xa) - } yield () + } yield ()).orDie } override def updateManagedDID(did: PrismDID, patch: ManagedDIDStatePatch): RIO[WalletAccessContext, Unit] = { @@ -151,6 +145,41 @@ class JdbcDIDNonSecretStorage(xa: Transactor[ContextAwareTask], xb: Transactor[T cxnIO.transactWallet(xa).map(_.flatten) } + override def incrementAndGetNextDIDIndex: URIO[WalletAccessContext, Int] = { + def acquireAdvisoryLock(walletId: WalletId): ConnectionIO[Unit] = { + // Should be specific to this process + val PROCESS_UNIQUE_ID = 465263 + val hashCode = Objects.hash(walletId.hashCode(), PROCESS_UNIQUE_ID) + sql"SELECT pg_advisory_xact_lock($hashCode)".query[Unit].unique.void + } + + def insertWalletDIDIndexIfNotExists(walletId: WalletId): ConnectionIO[Int] = { + sql""" + | INSERT INTO public.last_did_index_per_wallet (wallet_id, last_used_index) + | VALUES ($walletId, -1) + | ON CONFLICT (wallet_id) DO NOTHING""".stripMargin.update.run + } + + def incrementWalletDIDIndex(walletId: WalletId): ConnectionIO[Int] = { + sql""" + | UPDATE public.last_did_index_per_wallet + | SET last_used_index = last_used_index + 1 + | WHERE wallet_id = $walletId + | RETURNING last_used_index""".stripMargin.query[Int].unique + } + + for { + walletCtx <- ZIO.service[WalletAccessContext] + walletId = walletCtx.walletId + cnxIO = for { + _ <- acquireAdvisoryLock(walletId) + _ <- insertWalletDIDIndexIfNotExists(walletId) + index <- incrementWalletDIDIndex(walletId) + } yield index + index <- cnxIO.transactWallet(xa).orDie + } yield index + } + override def getHdKeyCounter(did: PrismDID): RIO[WalletAccessContext, Option[HdKeyIndexCounter]] = { val status: ScheduledDIDOperationStatus = ScheduledDIDOperationStatus.Confirmed val cxnIO = diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/storage/DIDNonSecretStorage.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/storage/DIDNonSecretStorage.scala index 1830dc1600..612338b1ad 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/storage/DIDNonSecretStorage.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/storage/DIDNonSecretStorage.scala @@ -21,6 +21,8 @@ trait DIDNonSecretStorage { def getMaxDIDIndex(): RIO[WalletAccessContext, Option[Int]] + def incrementAndGetNextDIDIndex: URIO[WalletAccessContext, Int] + def getHdKeyCounter(did: PrismDID): RIO[WalletAccessContext, Option[HdKeyIndexCounter]] /** Return a tuple of key metadata and the operation hash */ diff --git a/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/storage/MockDIDNonSecretStorage.scala b/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/storage/MockDIDNonSecretStorage.scala index f14df4d00d..6a29b2769d 100644 --- a/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/storage/MockDIDNonSecretStorage.scala +++ b/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/storage/MockDIDNonSecretStorage.scala @@ -49,6 +49,9 @@ case class MockDIDNonSecretStorage(proxy: Proxy) extends DIDNonSecretStorage { override def getMaxDIDIndex(): RIO[WalletAccessContext, Option[Int]] = proxy(MockDIDNonSecretStorage.GetMaxDIDIndex) + override def incrementAndGetNextDIDIndex: URIO[WalletAccessContext, RuntimeFlags] = + proxy(MockDIDNonSecretStorage.IncrementAndGetNextDIDIndex) + override def getHdKeyCounter(did: PrismDID): RIO[WalletAccessContext, Option[HdKeyIndexCounter]] = proxy(MockDIDNonSecretStorage.GetHdKeyCounter, did) @@ -89,6 +92,7 @@ object MockDIDNonSecretStorage extends Mock[DIDNonSecretStorage] { ] object UpdateManagedDID extends Effect[(PrismDID, ManagedDIDStatePatch), Throwable, Unit] object GetMaxDIDIndex extends Effect[Unit, Throwable, Option[Int]] + object IncrementAndGetNextDIDIndex extends Effect[Unit, Nothing, Int] object GetHdKeyCounter extends Effect[PrismDID, Throwable, Option[HdKeyIndexCounter]] object GetKeyMeta extends Effect[(PrismDID, KeyId), Throwable, Option[(ManagedDIDKeyMeta, Array[Byte])]] object InsertHdKeyMeta extends Effect[(PrismDID, KeyId, ManagedDIDKeyMeta, Array[Byte]), Throwable, Unit] diff --git a/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/WalletIdAndRecordId.scala b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/WalletIdAndRecordId.scala new file mode 100644 index 0000000000..687f5e9aa1 --- /dev/null +++ b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/WalletIdAndRecordId.scala @@ -0,0 +1,19 @@ +//package org.hyperledger.identus.connect.core.model +// +//import org.hyperledger.identus.messaging.Serde +//import zio.json.{DecoderOps, DeriveJsonDecoder, DeriveJsonEncoder, EncoderOps, JsonDecoder, JsonEncoder} +// +//import java.nio.charset.StandardCharsets +//import java.util.UUID +// +//case class WalletIdAndRecordId(walletId: UUID, recordId: UUID) +// +//object WalletIdAndRecordId { +// given encoder: JsonEncoder[WalletIdAndRecordId] = DeriveJsonEncoder.gen[WalletIdAndRecordId] +// given decoder: JsonDecoder[WalletIdAndRecordId] = DeriveJsonDecoder.gen[WalletIdAndRecordId] +// given ser: Serde[WalletIdAndRecordId] = new Serde[WalletIdAndRecordId] { +// override def serialize(t: WalletIdAndRecordId): Array[Byte] = t.toJson.getBytes(StandardCharsets.UTF_8) +// override def deserialize(ba: Array[Byte]): WalletIdAndRecordId = +// new String(ba, StandardCharsets.UTF_8).fromJson[WalletIdAndRecordId].getOrElse(throw RuntimeException("")) +// } +//} diff --git a/connect/core/src/main/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImpl.scala b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImpl.scala index a4072aea05..db91377abc 100644 --- a/connect/core/src/main/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImpl.scala +++ b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImpl.scala @@ -1,14 +1,13 @@ package org.hyperledger.identus.connect.core.service -import org.hyperledger.identus.* import org.hyperledger.identus.connect.core.model.{ConnectionRecord, ConnectionRecordBeforeStored} -import org.hyperledger.identus.connect.core.model.error.ConnectionServiceError import org.hyperledger.identus.connect.core.model.error.ConnectionServiceError.* import org.hyperledger.identus.connect.core.model.ConnectionRecord.* import org.hyperledger.identus.connect.core.repository.ConnectionRepository import org.hyperledger.identus.mercury.model.DidId import org.hyperledger.identus.mercury.protocol.connection.* import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation +import org.hyperledger.identus.shared.messaging.{Producer, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.* import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.Base64Utils @@ -21,9 +20,12 @@ import java.util.UUID private class ConnectionServiceImpl( connectionRepository: ConnectionRepository, + messageProducer: Producer[UUID, WalletIdAndRecordId], maxRetries: Int = 5, // TODO move to config ) extends ConnectionService { + private val TOPIC_NAME = "connect" + override def createConnectionInvitation( label: Option[String], goalCode: Option[String], @@ -147,6 +149,11 @@ private class ConnectionServiceImpl( @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_invitee_pending_to_req_sent" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + // TODO Should we use a singleton producer or create a new one each time?? (underlying Kafka Producer is thread safe) + _ <- messageProducer + .produce(TOPIC_NAME, record.id, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id)) + .orDie maybeRecord <- connectionRepository .findById(record.id) record <- ZIO.getOrFailWith(RecordIdNotFound(recordId))(maybeRecord) @@ -220,6 +227,10 @@ private class ConnectionServiceImpl( @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_inviter_pending_to_res_sent" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id)) + .orDie record <- connectionRepository.getById(record.id) } yield record @@ -306,6 +317,6 @@ private class ConnectionServiceImpl( } object ConnectionServiceImpl { - val layer: URLayer[ConnectionRepository, ConnectionService] = - ZLayer.fromFunction(ConnectionServiceImpl(_)) + val layer: URLayer[ConnectionRepository & Producer[UUID, WalletIdAndRecordId], ConnectionService] = + ZLayer.fromFunction(ConnectionServiceImpl(_, _)) } diff --git a/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImplSpec.scala b/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImplSpec.scala index b0fa8d43fd..7067b55bf6 100644 --- a/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImplSpec.scala +++ b/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceImplSpec.scala @@ -3,17 +3,17 @@ package org.hyperledger.identus.connect.core.service import io.circe.syntax.* import org.hyperledger.identus.connect.core.model.error.ConnectionServiceError import org.hyperledger.identus.connect.core.model.error.ConnectionServiceError.InvalidStateForOperation -import org.hyperledger.identus.connect.core.model.ConnectionRecord import org.hyperledger.identus.connect.core.model.ConnectionRecord.* import org.hyperledger.identus.connect.core.repository.ConnectionRepositoryInMemory import org.hyperledger.identus.mercury.model.{DidId, Message} import org.hyperledger.identus.mercury.protocol.connection.ConnectionResponse +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.WalletIdAndRecordId import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* import zio.test.* import zio.test.Assertion.* -import java.time.Instant import java.util.UUID object ConnectionServiceImplSpec extends ZIOSpecDefault { @@ -310,7 +310,13 @@ object ConnectionServiceImplSpec extends ZIOSpecDefault { } } } - ).provide(connectionServiceLayer, ZLayer.succeed(WalletAccessContext(WalletId.random))) + ).provide( + connectionServiceLayer, + messaging.MessagingServiceConfig.inMemoryLayer, + messaging.MessagingService.serviceLayer, + messaging.MessagingService.producerLayer[UUID, WalletIdAndRecordId], + ZLayer.succeed(WalletAccessContext(WalletId.random)), + ) } } diff --git a/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceNotifierSpec.scala b/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceNotifierSpec.scala index b9e54811b9..185bd95b95 100644 --- a/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceNotifierSpec.scala +++ b/connect/core/src/test/scala/org/hyperledger/identus/connect/core/service/ConnectionServiceNotifierSpec.scala @@ -7,11 +7,12 @@ import org.hyperledger.identus.event.notification.* import org.hyperledger.identus.mercury.model.DidId import org.hyperledger.identus.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse} import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.WalletIdAndRecordId import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* import zio.mock.Expectation import zio.test.* -import zio.ZIO.* import java.time.Instant import java.util.UUID @@ -151,7 +152,10 @@ object ConnectionServiceNotifierSpec extends ZIOSpecDefault { ConnectionRepositoryInMemory.layer ++ inviteeExpectations.toLayer ) >>> ConnectionServiceNotifier.layer, - ZLayer.succeed(WalletAccessContext(WalletId.random)) + ZLayer.succeed(WalletAccessContext(WalletId.random)), + messaging.MessagingServiceConfig.inMemoryLayer, + messaging.MessagingService.serviceLayer, + messaging.MessagingService.producerLayer[UUID, WalletIdAndRecordId] ) ) } diff --git a/event-notification/src/test/scala/org/hyperledger/identus/messaging/MessagingServiceTest.scala b/event-notification/src/test/scala/org/hyperledger/identus/messaging/MessagingServiceTest.scala new file mode 100644 index 0000000000..54aea505f6 --- /dev/null +++ b/event-notification/src/test/scala/org/hyperledger/identus/messaging/MessagingServiceTest.scala @@ -0,0 +1,49 @@ +package org.hyperledger.identus.messaging + +import org.hyperledger.identus.shared.messaging +import org.hyperledger.identus.shared.messaging.{Message, MessagingService, Serde} +import zio.{durationInt, Random, Schedule, Scope, URIO, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer} +import zio.json.{DecoderOps, DeriveJsonDecoder, DeriveJsonEncoder, EncoderOps, JsonDecoder, JsonEncoder} + +import java.nio.charset.StandardCharsets +import java.util.UUID + +case class Customer(name: String) + +object Customer { + given encoder: JsonEncoder[Customer] = DeriveJsonEncoder.gen[Customer] + given decoder: JsonDecoder[Customer] = DeriveJsonDecoder.gen[Customer] + given serde: Serde[Customer] = new Serde[Customer]: + override def serialize(t: Customer): Array[Byte] = + t.toJson.getBytes(StandardCharsets.UTF_8) + override def deserialize(ba: Array[Byte]): Customer = + new String(ba, StandardCharsets.UTF_8).fromJson[Customer].getOrElse(Customer("Parsing Error")) +} + +object MessagingServiceTest extends ZIOAppDefault { + override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] = { + val effect = for { + ms <- ZIO.service[MessagingService] + consumer <- ms.makeConsumer[UUID, Customer]("identus-cloud-agent") + producer <- ms.makeProducer[UUID, Customer]() + f1 <- consumer + .consume("Connect")(handle) + .fork + f2 <- Random.nextUUID + .flatMap(uuid => producer.produce("Connect", uuid, Customer(s"Name $uuid"))) + .repeat(Schedule.spaced(500.millis)) + .fork + _ <- ZIO.never + } yield () + effect.provide( + messaging.MessagingServiceConfig.inMemoryLayer, + messaging.MessagingService.serviceLayer, + ZLayer.succeed("Sample 'R' passed to handler") + ) + } + + def handle[K, V](msg: Message[K, V]): URIO[String, Unit] = for { + tag <- ZIO.service[String] + _ <- ZIO.logInfo(s"Handling new message [$tag]: ${msg.offset} - ${msg.key} - ${msg.value}") + } yield () +} diff --git a/event-notification/src/test/scala/org/hyperledger/identus/messaging/kafka/InMemoryMessagingServiceSpec.scala b/event-notification/src/test/scala/org/hyperledger/identus/messaging/kafka/InMemoryMessagingServiceSpec.scala new file mode 100644 index 0000000000..c6b068f16b --- /dev/null +++ b/event-notification/src/test/scala/org/hyperledger/identus/messaging/kafka/InMemoryMessagingServiceSpec.scala @@ -0,0 +1,66 @@ +package org.hyperledger.identus.messaging.kafka + +import org.hyperledger.identus.shared.messaging.* +import zio.* +import zio.test.* +import zio.test.Assertion.* + +object InMemoryMessagingServiceSpec extends ZIOSpecDefault { + val testLayer = MessagingServiceConfig.inMemoryLayer >+> MessagingService.serviceLayer >+> + MessagingService.producerLayer[String, String] >+> + MessagingService.consumerLayer[String, String]("test-group") + + def spec = suite("InMemoryMessagingServiceSpec")( + test("should produce and consume messages") { + + val key = "key" + val value = "value" + val topic = "test-topic" + for { + producer <- ZIO.service[Producer[String, String]] + consumer <- ZIO.service[Consumer[String, String]] + promise <- Promise.make[Nothing, Message[String, String]] + _ <- producer.produce(topic, key, value) + _ <- consumer + .consume(topic) { msg => + promise.succeed(msg).unit + } + .fork + receivedMessage <- promise.await + } yield assert(receivedMessage)(equalTo(Message(key, value, 1L, 0))) + }.provideLayer(testLayer), + test("should produce and consume 5 messages") { + val topic = "test-topic" + val messages = List( + ("key1", "value1"), + ("key2", "value2"), + ("key3", "value3"), + ("key4", "value4"), + ("key5", "value5") + ) + + for { + producer <- ZIO.service[Producer[String, String]] + consumer <- ZIO.service[Consumer[String, String]] + promise <- Promise.make[Nothing, List[Message[String, String]]] + ref <- Ref.make(List.empty[Message[String, String]]) + + _ <- ZIO.foreach(messages) { case (key, value) => + producer.produce(topic, key, value) *> ZIO.debug(s"Produced message: $key -> $value") + } + _ <- consumer + .consume(topic) { msg => + ZIO.debug(s"Consumed message: ${msg.key} -> ${msg.value}") *> + ref.update(_ :+ msg) *> ref.get.flatMap { msgs => + if (msgs.size == messages.size) promise.succeed(msgs).unit else ZIO.unit + } + } + .fork + receivedMessages <- promise.await + _ <- ZIO.debug(s"Received messages: ${receivedMessages.map(m => (m.key, m.value))}") + } yield assert(receivedMessages.map(m => (m.key, m.value)).sorted)( + equalTo(messages.sorted) + ) + }.provideLayer(testLayer), + ) +} diff --git a/infrastructure/shared/docker-compose-with-kafka.yml b/infrastructure/shared/docker-compose-with-kafka.yml new file mode 100644 index 0000000000..3e24ad6128 --- /dev/null +++ b/infrastructure/shared/docker-compose-with-kafka.yml @@ -0,0 +1,256 @@ +--- +services: + ########################## + # Database + ########################## + db: + image: postgres:13 + environment: + POSTGRES_MULTIPLE_DATABASES: "pollux,connect,agent,node_db" + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + volumes: + - pg_data_db:/var/lib/postgresql/data + - ./postgres/init-script.sh:/docker-entrypoint-initdb.d/init-script.sh + - ./postgres/max_conns.sql:/docker-entrypoint-initdb.d/max_conns.sql + ports: + - "127.0.0.1:${PG_PORT:-5432}:5432" + healthcheck: + test: ["CMD", "pg_isready", "-U", "postgres", "-d", "agent"] + + interval: 10s + timeout: 5s + retries: 5 + + pgadmin: + image: dpage/pgadmin4 + environment: + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} + PGADMIN_CONFIG_SERVER_MODE: "False" + volumes: + - pgadmin:/var/lib/pgadmin + ports: + - "127.0.0.1:${PGADMIN_PORT:-5050}:80" + depends_on: + db: + condition: service_healthy + profiles: + - debug + + ########################## + # Services + ########################## + + prism-node: + image: ghcr.io/input-output-hk/prism-node:${PRISM_NODE_VERSION} + environment: + NODE_PSQL_HOST: db:5432 + NODE_REFRESH_AND_SUBMIT_PERIOD: + NODE_MOVE_SCHEDULED_TO_PENDING_PERIOD: + NODE_WALLET_MAX_TPS: + depends_on: + db: + condition: service_healthy + + vault-server: + image: hashicorp/vault:latest + # ports: + # - "8200:8200" + environment: + VAULT_ADDR: "http://0.0.0.0:8200" + VAULT_DEV_ROOT_TOKEN_ID: ${VAULT_DEV_ROOT_TOKEN_ID} + command: server -dev -dev-root-token-id=${VAULT_DEV_ROOT_TOKEN_ID} + cap_add: + - IPC_LOCK + healthcheck: + test: ["CMD", "vault", "status"] + interval: 10s + timeout: 5s + retries: 5 + + cloud-agent: + image: ghcr.io/hyperledger/identus-cloud-agent:${AGENT_VERSION} + environment: + POLLUX_DB_HOST: db + POLLUX_DB_PORT: 5432 + POLLUX_DB_NAME: pollux + POLLUX_DB_USER: postgres + POLLUX_DB_PASSWORD: postgres + CONNECT_DB_HOST: db + CONNECT_DB_PORT: 5432 + CONNECT_DB_NAME: connect + CONNECT_DB_USER: postgres + CONNECT_DB_PASSWORD: postgres + AGENT_DB_HOST: db + AGENT_DB_PORT: 5432 + AGENT_DB_NAME: agent + AGENT_DB_USER: postgres + AGENT_DB_PASSWORD: postgres + POLLUX_STATUS_LIST_REGISTRY_PUBLIC_URL: http://${DOCKERHOST}:${PORT}/cloud-agent + DIDCOMM_SERVICE_URL: http://${DOCKERHOST}:${PORT}/didcomm + REST_SERVICE_URL: http://${DOCKERHOST}:${PORT}/cloud-agent + PRISM_NODE_HOST: prism-node + PRISM_NODE_PORT: 50053 + VAULT_ADDR: ${VAULT_ADDR:-http://vault-server:8200} + VAULT_TOKEN: ${VAULT_DEV_ROOT_TOKEN_ID:-root} + SECRET_STORAGE_BACKEND: postgres + DEV_MODE: true + DEFAULT_WALLET_ENABLED: + DEFAULT_WALLET_SEED: + DEFAULT_WALLET_WEBHOOK_URL: + DEFAULT_WALLET_WEBHOOK_API_KEY: + DEFAULT_WALLET_AUTH_API_KEY: + DEFAULT_KAFKA_ENABLED: true + GLOBAL_WEBHOOK_URL: + GLOBAL_WEBHOOK_API_KEY: + WEBHOOK_PARALLELISM: + ADMIN_TOKEN: + API_KEY_SALT: + API_KEY_ENABLED: + API_KEY_AUTHENTICATE_AS_DEFAULT_USER: + API_KEY_AUTO_PROVISIONING: + depends_on: + db: + condition: service_healthy + prism-node: + condition: service_started + vault-server: + condition: service_healthy + init-kafka: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://cloud-agent:8085/_system/health"] + interval: 30s + timeout: 10s + retries: 5 + extra_hosts: + - "host.docker.internal:host-gateway" + + swagger-ui: + image: swaggerapi/swagger-ui:v5.1.0 + environment: + - 'URLS=[ + { name: "Cloud Agent", url: "/docs/cloud-agent/api/docs.yaml" } + ]' + + # apisix: + # image: apache/apisix:2.15.0-alpine + # volumes: + # - ./apisix/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro + # - ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro + # ports: + # - "${PORT}:9080/tcp" + # depends_on: + # - cloud-agent + # - swagger-ui + + nginx: + image: nginx:latest + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + ports: + - "${PORT}:80/tcp" + depends_on: + - cloud-agent + - swagger-ui + + zookeeper: + image: confluentinc/cp-zookeeper:latest + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + # ports: + # - 22181:2181 + + kafka: + image: confluentinc/cp-kafka:latest + depends_on: + - zookeeper + # ports: + # - 29092:29092 + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: false + healthcheck: + test: + [ + "CMD", + "kafka-topics", + "--list", + "--bootstrap-server", + "localhost:9092", + ] + interval: 5s + timeout: 10s + retries: 5 + + init-kafka: + image: confluentinc/cp-kafka:latest + depends_on: + kafka: + condition: service_healthy + entrypoint: ["/bin/sh", "-c"] + command: | + " + # blocks until kafka is reachable + kafka-topics --bootstrap-server kafka:9092 --list + echo -e 'Creating kafka topics' + + # Connect + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect --replication-factor 1 --partitions 20 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-1 --replication-factor 1 --partitions 20 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-2 --replication-factor 1 --partitions 20 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-3 --replication-factor 1 --partitions 20 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-4 --replication-factor 1 --partitions 20 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-DLQ --replication-factor 1 --partitions 1 + + # Issue + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-1 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-2 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-3 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-4 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-DLQ --replication-factor 1 --partitions 1 + + # Present + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-1 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-2 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-3 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-4 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-DLQ --replication-factor 1 --partitions 1 + + # DID Publication State Sync + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-did-state --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-did-state-DLQ --replication-factor 1 --partitions 5 + + # Status List Sync + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-status-list --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-status-list-DLQ --replication-factor 1 --partitions 5 + + tail -f /dev/null + " + healthcheck: + test: + [ + "CMD-SHELL", + "kafka-topics --bootstrap-server kafka:9092 --list | grep -q 'sync-status-list'", + ] + interval: 5s + timeout: 10s + retries: 5 + +volumes: + pg_data_db: + pgadmin: +# Temporary commit network setting due to e2e CI bug +# to be enabled later after debugging +#networks: +# default: +# name: ${NETWORK} diff --git a/infrastructure/shared/nginx/nginx.conf b/infrastructure/shared/nginx/nginx.conf new file mode 100644 index 0000000000..937dc35a3f --- /dev/null +++ b/infrastructure/shared/nginx/nginx.conf @@ -0,0 +1,42 @@ +user nginx; + +events { + worker_connections 1000; +} + +http { + # Docker embedded DNS server (overriding TTL) + resolver 127.0.0.11 valid=5s; + + # Upstreams + upstream cloud_agent_8090 { + server cloud-agent:8090; + } + + upstream cloud_agent_8085 { + server cloud-agent:8085; + } + + # Server configuration + server { + listen 80; + + # Route /cloud-agent/* + location ~ ^/cloud-agent/(.*) { + # Proxy rewrite + set $upstream_servers cloud-agent; + rewrite ^/cloud-agent/(.*) /$1 break; + proxy_pass http://$upstream_servers:8085; + proxy_connect_timeout 5s; + } + + # Route /didcomm* + location ~ ^/didcomm(.*) { + # Proxy rewrite + set $upstream_servers cloud-agent; + rewrite ^/didcomm(.*) /$1 break; + proxy_pass http://$upstream_servers:8090; + proxy_connect_timeout 5s; + } + } +} \ No newline at end of file diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/DidCommID.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/DidCommID.scala index 47fcced892..ed18017d45 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/DidCommID.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/DidCommID.scala @@ -7,4 +7,6 @@ opaque type DidCommID = String object DidCommID: def apply(value: String): DidCommID = value def apply(): DidCommID = UUID.randomUUID.toString() - extension (id: DidCommID) def value: String = id + extension (id: DidCommID) + def value: String = id + def uuid: UUID = UUID.fromString(id) diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepository.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepository.scala index 6a86509592..6d8cdbb50d 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepository.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepository.scala @@ -1,30 +1,61 @@ package org.hyperledger.identus.pollux.core.repository import org.hyperledger.identus.pollux.core.model.* +import org.hyperledger.identus.pollux.vc.jwt.revocation.{BitString, VCStatusList2021} +import org.hyperledger.identus.pollux.vc.jwt.revocation.BitStringError.{ + DecodingError, + EncodingError, + IndexOutOfBounds, + InvalidSize +} import org.hyperledger.identus.pollux.vc.jwt.Issuer -import org.hyperledger.identus.shared.models.WalletAccessContext +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* import java.util.UUID trait CredentialStatusListRepository { - def getCredentialStatusListsWithCreds: UIO[List[CredentialStatusListWithCreds]] + def createStatusListVC( + jwtIssuer: Issuer, + statusListRegistryUrl: String, + id: UUID + ): IO[Throwable, String] = { + for { + bitString <- BitString.getInstance().mapError { + case InvalidSize(message) => new Throwable(message) + case EncodingError(message) => new Throwable(message) + case DecodingError(message) => new Throwable(message) + case IndexOutOfBounds(message) => new Throwable(message) + } + emptyStatusListCredential <- VCStatusList2021 + .build( + vcId = s"$statusListRegistryUrl/credential-status/$id", + revocationData = bitString, + jwtIssuer = jwtIssuer + ) + .mapError(x => new Throwable(x.msg)) + + credentialWithEmbeddedProof <- emptyStatusListCredential.toJsonWithEmbeddedProof + } yield credentialWithEmbeddedProof.spaces2 + } + + def getCredentialStatusListIds: UIO[Seq[(WalletId, UUID)]] + + def getCredentialStatusListsWithCreds(statusListId: UUID): URIO[WalletAccessContext, CredentialStatusListWithCreds] def findById( id: UUID ): UIO[Option[CredentialStatusList]] - def getLatestOfTheWallet: URIO[WalletAccessContext, Option[CredentialStatusList]] + def incrementAndGetStatusListIndex( + jwtIssuer: Issuer, + statusListRegistryUrl: String + ): URIO[WalletAccessContext, (UUID, Int)] def existsForIssueCredentialRecordId( id: DidCommID ): URIO[WalletAccessContext, Boolean] - def createNewForTheWallet( - jwtIssuer: Issuer, - statusListRegistryServiceName: String - ): URIO[WalletAccessContext, CredentialStatusList] - def allocateSpaceForCredential( issueCredentialRecordId: DidCommID, credentialStatusListId: UUID, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala index 4e059f8e05..a95e80925e 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala @@ -28,6 +28,7 @@ import org.hyperledger.identus.pollux.sdjwt.* import org.hyperledger.identus.pollux.vc.jwt.{Issuer as JwtIssuer, *} import org.hyperledger.identus.shared.crypto.{Ed25519KeyPair, Secp256k1KeyPair} import org.hyperledger.identus.shared.http.UriResolver +import org.hyperledger.identus.shared.messaging.{Producer, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.* import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.Base64Utils @@ -42,7 +43,8 @@ import scala.language.implicitConversions object CredentialServiceImpl { val layer: URLayer[ CredentialRepository & CredentialStatusListRepository & DidResolver & UriResolver & GenericSecretStorage & - CredentialDefinitionService & LinkSecretService & DIDService & ManagedDIDService, + CredentialDefinitionService & LinkSecretService & DIDService & ManagedDIDService & + Producer[UUID, WalletIdAndRecordId], CredentialService ] = { ZLayer.fromZIO { @@ -56,7 +58,7 @@ object CredentialServiceImpl { linkSecretService <- ZIO.service[LinkSecretService] didService <- ZIO.service[DIDService] manageDidService <- ZIO.service[ManagedDIDService] - issueCredentialSem <- Semaphore.make(1) + messageProducer <- ZIO.service[Producer[UUID, WalletIdAndRecordId]] } yield CredentialServiceImpl( credentialRepo, credentialStatusListRepo, @@ -68,7 +70,7 @@ object CredentialServiceImpl { didService, manageDidService, 5, - issueCredentialSem + messageProducer ) } } @@ -88,12 +90,14 @@ class CredentialServiceImpl( didService: DIDService, managedDIDService: ManagedDIDService, maxRetries: Int = 5, // TODO move to config - issueCredentialSem: Semaphore + messageProducer: Producer[UUID, WalletIdAndRecordId], ) extends CredentialService { import CredentialServiceImpl.* import IssueCredentialRecord.* + private val TOPIC_NAME = "issue" + override def getIssueCredentialRecords( ignoreWithZeroRetries: Boolean, offset: Option[Int], @@ -187,6 +191,10 @@ class CredentialServiceImpl( count <- credentialRepository .create(record) @@ CustomMetricsAspect .startRecordingTime(s"${record.id}_issuer_offer_pending_to_sent_ms_gauge") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie } yield record } @@ -500,6 +508,10 @@ class CredentialServiceImpl( ) case (format, maybeSubjectId) => ZIO.dieMessage(s"Invalid subjectId input for $format offer acceptance: $maybeSubjectId") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -661,6 +673,10 @@ class CredentialServiceImpl( s"${record.id}_issuance_flow_holder_req_pending_to_generated", "issuance_flow_holder_req_pending_to_generated_ms_gauge" ) @@ CustomMetricsAspect.startRecordingTime(s"${record.id}_issuance_flow_holder_req_generated_to_sent") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -707,6 +723,10 @@ class CredentialServiceImpl( s"${record.id}_issuance_flow_holder_req_pending_to_generated", "issuance_flow_holder_req_pending_to_generated_ms_gauge" ) @@ CustomMetricsAspect.startRecordingTime(s"${record.id}_issuance_flow_holder_req_generated_to_sent") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -751,6 +771,10 @@ class CredentialServiceImpl( ProtocolState.OfferSent ) _ <- credentialRepository.updateWithJWTRequestCredential(record.id, request, ProtocolState.RequestReceived) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -769,6 +793,10 @@ class CredentialServiceImpl( @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_issuance_flow_issuer_credential_pending_to_generated" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -913,6 +941,10 @@ class CredentialServiceImpl( s"${record.id}_issuance_flow_issuer_credential_pending_to_generated", "issuance_flow_issuer_credential_pending_to_generated_ms_gauge" ) @@ CustomMetricsAspect.startRecordingTime(s"${record.id}_issuance_flow_issuer_credential_generated_to_sent") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- credentialRepository.getById(record.id) } yield record } @@ -1275,32 +1307,26 @@ class CredentialServiceImpl( record: IssueCredentialRecord, statusListRegistryUrl: String, jwtIssuer: JwtIssuer - ): URIO[WalletAccessContext, CredentialStatus] = { - val effect = for { - lastStatusList <- credentialStatusListRepository.getLatestOfTheWallet - currentStatusList <- lastStatusList - .fold(credentialStatusListRepository.createNewForTheWallet(jwtIssuer, statusListRegistryUrl))( - ZIO.succeed(_) - ) - size = currentStatusList.size - lastUsedIndex = currentStatusList.lastUsedIndex - statusListToBeUsed <- - if lastUsedIndex < size then ZIO.succeed(currentStatusList) - else credentialStatusListRepository.createNewForTheWallet(jwtIssuer, statusListRegistryUrl) + ): URIO[WalletAccessContext, CredentialStatus] = + for { + cslAndIndex <- credentialStatusListRepository.incrementAndGetStatusListIndex( + jwtIssuer, + statusListRegistryUrl + ) + statusListId = cslAndIndex._1 + indexInStatusList = cslAndIndex._2 _ <- credentialStatusListRepository.allocateSpaceForCredential( issueCredentialRecordId = record.id, - credentialStatusListId = statusListToBeUsed.id, - statusListIndex = statusListToBeUsed.lastUsedIndex + 1 + credentialStatusListId = statusListId, + statusListIndex = indexInStatusList ) } yield CredentialStatus( - id = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}#${statusListToBeUsed.lastUsedIndex + 1}", + id = s"$statusListRegistryUrl/credential-status/$statusListId#$indexInStatusList", `type` = "StatusList2021Entry", statusPurpose = StatusPurpose.Revocation, - statusListIndex = lastUsedIndex + 1, - statusListCredential = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}" + statusListIndex = indexInStatusList, + statusListCredential = s"$statusListRegistryUrl/credential-status/$statusListId" ) - issueCredentialSem.withPermit(effect) - } override def generateAnonCredsCredential( recordId: DidCommID diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListService.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListService.scala index 5a186d2826..418b3faa0c 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListService.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListService.scala @@ -6,7 +6,7 @@ import org.hyperledger.identus.pollux.core.model.error.CredentialStatusListServi StatusListNotFound, StatusListNotFoundForIssueCredentialRecord } -import org.hyperledger.identus.shared.models.WalletAccessContext +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* import java.util.UUID @@ -20,7 +20,9 @@ trait CredentialStatusListService { id: DidCommID ): ZIO[WalletAccessContext, StatusListNotFoundForIssueCredentialRecord | InvalidRoleForOperation, Unit] - def getCredentialsAndItsStatuses: UIO[Seq[CredentialStatusListWithCreds]] + def getCredentialStatusListIds: UIO[Seq[(WalletId, UUID)]] + + def getCredentialStatusListWithCreds(statusListId: UUID): URIO[WalletAccessContext, CredentialStatusListWithCreds] def updateStatusListCredential( id: UUID, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListServiceImpl.scala index 92565a8559..ef752f8648 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialStatusListServiceImpl.scala @@ -8,7 +8,7 @@ import org.hyperledger.identus.pollux.core.model.error.CredentialStatusListServi } import org.hyperledger.identus.pollux.core.model.IssueCredentialRecord.Role import org.hyperledger.identus.pollux.core.repository.CredentialStatusListRepository -import org.hyperledger.identus.shared.models.WalletAccessContext +import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* import java.util.UUID @@ -18,8 +18,11 @@ class CredentialStatusListServiceImpl( credentialStatusListRepository: CredentialStatusListRepository, ) extends CredentialStatusListService { - def getCredentialsAndItsStatuses: UIO[Seq[CredentialStatusListWithCreds]] = - credentialStatusListRepository.getCredentialStatusListsWithCreds + def getCredentialStatusListIds: UIO[Seq[(WalletId, UUID)]] = + credentialStatusListRepository.getCredentialStatusListIds + + def getCredentialStatusListWithCreds(statusListId: UUID): URIO[WalletAccessContext, CredentialStatusListWithCreds] = + credentialStatusListRepository.getCredentialStatusListsWithCreds(statusListId) def getById(id: UUID): IO[StatusListNotFound, CredentialStatusList] = for { diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala index 94aa1af79b..20426ec477 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala @@ -105,7 +105,7 @@ trait PresentationService { def findPresentationRecord( recordId: DidCommID - ): ZIO[WalletAccessContext, PresentationError, Option[PresentationRecord]] + ): URIO[WalletAccessContext, Option[PresentationRecord]] def findPresentationRecordByThreadId( thid: DidCommID diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala index 8200595ebf..3d18a25bbe 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala @@ -20,6 +20,7 @@ import org.hyperledger.identus.pollux.core.service.serdes.* import org.hyperledger.identus.pollux.sdjwt.{CredentialCompact, HolderPrivateKey, PresentationCompact, SDJWT} import org.hyperledger.identus.pollux.vc.jwt.* import org.hyperledger.identus.shared.http.UriResolver +import org.hyperledger.identus.shared.messaging.{Producer, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.* import org.hyperledger.identus.shared.utils.aspects.CustomMetricsAspect import org.hyperledger.identus.shared.utils.Base64Utils @@ -37,11 +38,14 @@ private class PresentationServiceImpl( linkSecretService: LinkSecretService, presentationRepository: PresentationRepository, credentialRepository: CredentialRepository, - maxRetries: Int = 5, // TODO move to config + messageProducer: Producer[UUID, WalletIdAndRecordId], + maxRetries: Int = 5, // TODO move to config, ) extends PresentationService { import PresentationRecord.* + private val TOPIC_NAME = "present" + override def markPresentationGenerated( recordId: DidCommID, presentation: Presentation @@ -57,6 +61,10 @@ private class PresentationServiceImpl( ) @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_present_proof_flow_prover_presentation_generated_to_sent_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(recordId) } yield record } @@ -298,7 +306,7 @@ private class PresentationServiceImpl( override def findPresentationRecord( recordId: DidCommID - ): ZIO[WalletAccessContext, PresentationError, Option[PresentationRecord]] = + ): URIO[WalletAccessContext, Option[PresentationRecord]] = presentationRepository.findPresentationRecord(recordId) override def findPresentationRecordByThreadId( @@ -459,6 +467,10 @@ private class PresentationServiceImpl( @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_present_proof_flow_verifier_req_pending_to_sent_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie } yield record } @@ -531,6 +543,10 @@ private class PresentationServiceImpl( ) _ <- presentationRepository.createPresentationRecord(record) _ <- ZIO.logDebug(s"Received and created the RequestPresentation: $request") + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie } yield record } @@ -813,6 +829,10 @@ private class PresentationServiceImpl( @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_present_proof_flow_prover_presentation_pending_to_generated_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(recordId) } yield record } @@ -841,6 +861,10 @@ private class PresentationServiceImpl( ) @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_present_proof_flow_prover_presentation_pending_to_generated_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(recordId) } yield record } @@ -875,6 +899,10 @@ private class PresentationServiceImpl( ) @@ CustomMetricsAspect.startRecordingTime( s"${record.id}_present_proof_flow_prover_presentation_pending_to_generated_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(record.id) } yield record } @@ -961,6 +989,10 @@ private class PresentationServiceImpl( .startRecordingTime( s"${record.id}_present_proof_flow_verifier_presentation_received_to_verification_success_or_failure_ms_gauge" ) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(record.id) } yield record } @@ -977,6 +1009,10 @@ private class PresentationServiceImpl( requestPresentation = createDidCommRequestPresentationFromProposal(request) _ <- presentationRepository .updateWithRequestPresentation(recordId, requestPresentation, ProtocolState.PresentationPending) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(recordId) } yield record } @@ -993,6 +1029,10 @@ private class PresentationServiceImpl( record <- getRecordFromThreadId(thid) _ <- presentationRepository .updateWithProposePresentation(record.id, proposePresentation, ProtocolState.ProposalReceived) + walletAccessContext <- ZIO.service[WalletAccessContext] + _ <- messageProducer + .produce(TOPIC_NAME, record.id.uuid, WalletIdAndRecordId(walletAccessContext.walletId.toUUID, record.id.uuid)) + .orDie record <- getRecord(record.id) } yield record } @@ -1305,8 +1345,9 @@ private class PresentationServiceImpl( object PresentationServiceImpl { val layer: URLayer[ - UriResolver & LinkSecretService & PresentationRepository & CredentialRepository, + UriResolver & LinkSecretService & PresentationRepository & CredentialRepository & + Producer[UUID, WalletIdAndRecordId], PresentationService ] = - ZLayer.fromFunction(PresentationServiceImpl(_, _, _, _)) + ZLayer.fromFunction(PresentationServiceImpl(_, _, _, _, _)) } diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala index 80d358cdbf..350c161100 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala @@ -14,6 +14,7 @@ import org.hyperledger.identus.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCr import org.hyperledger.identus.shared.models.* import zio.* import zio.json.* +import zio.URIO import java.time.Instant import java.util.UUID @@ -275,7 +276,7 @@ class PresentationServiceNotifier( override def findPresentationRecord( recordId: DidCommID - ): ZIO[WalletAccessContext, PresentationError, Option[PresentationRecord]] = + ): URIO[WalletAccessContext, Option[PresentationRecord]] = svc.findPresentationRecord(recordId) override def findPresentationRecordByThreadId( diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepositoryInMemory.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepositoryInMemory.scala index 8ea5ca21d1..3e4f885f2b 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepositoryInMemory.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialStatusListRepositoryInMemory.scala @@ -1,15 +1,9 @@ package org.hyperledger.identus.pollux.core.repository -import org.hyperledger.identus.castor.core.model.did.{CanonicalPrismDID, PrismDID} +import org.hyperledger.identus.castor.core.model.did.PrismDID import org.hyperledger.identus.pollux.core.model.* -import org.hyperledger.identus.pollux.vc.jwt.{revocation, Issuer, StatusPurpose} -import org.hyperledger.identus.pollux.vc.jwt.revocation.{BitString, VCStatusList2021} -import org.hyperledger.identus.pollux.vc.jwt.revocation.BitStringError.{ - DecodingError, - EncodingError, - IndexOutOfBounds, - InvalidSize -} +import org.hyperledger.identus.pollux.vc.jwt.{Issuer, StatusPurpose} +import org.hyperledger.identus.pollux.vc.jwt.revocation.BitString import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* @@ -73,65 +67,69 @@ class CredentialStatusListRepositoryInMemory( exists = stores.flatMap(_.values).exists(_.issueCredentialRecordId == id) } yield exists - def getLatestOfTheWallet: URIO[WalletAccessContext, Option[CredentialStatusList]] = for { - storageRef <- walletToStatusListStorageRefs - storage <- storageRef.get - latest = storage.toSeq - .sortBy(_._2.createdAt) { (x, y) => if x.isAfter(y) then -1 else 1 /* DESC */ } - .headOption - .map(_._2) - } yield latest - - def createNewForTheWallet( + override def incrementAndGetStatusListIndex( jwtIssuer: Issuer, statusListRegistryUrl: String - ): URIO[WalletAccessContext, CredentialStatusList] = { + ): URIO[WalletAccessContext, (UUID, Int)] = + def getLatestOfTheWallet: URIO[WalletAccessContext, Option[CredentialStatusList]] = for { + storageRef <- walletToStatusListStorageRefs + storage <- storageRef.get + latest = storage.toSeq + .sortBy(_._2.createdAt) { (x, y) => if x.isAfter(y) then -1 else 1 /* DESC */ } + .headOption + .map(_._2) + } yield latest - val id = UUID.randomUUID() - val issued = Instant.now() - val issuerDid = jwtIssuer.did - val canonical = PrismDID.fromString(issuerDid.toString).fold(e => throw RuntimeException(e), _.asCanonical) + def createNewForTheWallet( + id: UUID, + jwtIssuer: Issuer, + issued: Instant, + credentialStr: String + ): URIO[WalletAccessContext, CredentialStatusList] = { + val issuerDid = jwtIssuer.did + val canonical = PrismDID.fromString(issuerDid.toString).fold(e => throw RuntimeException(e), _.asCanonical) - val embeddedProofCredential = for { - bitString <- BitString.getInstance().mapError { - case InvalidSize(message) => new Throwable(message) - case EncodingError(message) => new Throwable(message) - case DecodingError(message) => new Throwable(message) - case IndexOutOfBounds(message) => new Throwable(message) - } - resourcePath = - s"credential-status/$id" - emptyJwtCredential <- VCStatusList2021 - .build( - vcId = s"$statusListRegistryUrl/credential-status/$id", - revocationData = bitString, - jwtIssuer = jwtIssuer + for { + storageRef <- walletToStatusListStorageRefs + walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) + newCredentialStatusList = CredentialStatusList( + id = id, + walletId = walletId, + issuer = canonical, + issued = issued, + purpose = StatusPurpose.Revocation, + statusListCredential = credentialStr, + size = BitString.MIN_SL2021_SIZE, + lastUsedIndex = 0, + createdAt = Instant.now(), + updatedAt = None ) - .mapError(x => new Throwable(x.msg)) + _ <- storageRef.update(r => r + (newCredentialStatusList.id -> newCredentialStatusList)) + } yield newCredentialStatusList + } - credentialWithEmbeddedProof <- emptyJwtCredential.toJsonWithEmbeddedProof - } yield credentialWithEmbeddedProof.spaces2 + def updateLastUsedIndex(statusListId: UUID, lastUsedIndex: Int) = + for { + walletToStatusListStorageRef <- walletToStatusListStorageRefs + _ <- walletToStatusListStorageRef.update(r => { + val value = r.get(statusListId) + value.fold(r) { v => + val updated = v.copy(lastUsedIndex = lastUsedIndex, updatedAt = Some(Instant.now)) + r.updated(statusListId, updated) + } + }) + } yield () for { - credential <- embeddedProofCredential.orDie - storageRef <- walletToStatusListStorageRefs - walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) - newCredentialStatusList = CredentialStatusList( - id = id, - walletId = walletId, - issuer = canonical, - issued = issued, - purpose = StatusPurpose.Revocation, - statusListCredential = credential, - size = BitString.MIN_SL2021_SIZE, - lastUsedIndex = 0, - createdAt = Instant.now(), - updatedAt = None - ) - _ <- storageRef.update(r => r + (newCredentialStatusList.id -> newCredentialStatusList)) - } yield newCredentialStatusList - - } + id <- ZIO.succeed(UUID.randomUUID()) + newStatusListVC <- createStatusListVC(jwtIssuer, statusListRegistryUrl, id).orDie + maybeStatusList <- getLatestOfTheWallet + statusList <- maybeStatusList match + case Some(csl) if csl.lastUsedIndex < csl.size => ZIO.succeed(csl) + case _ => createNewForTheWallet(id, jwtIssuer, Instant.now(), newStatusListVC) + newIndex = statusList.lastUsedIndex + 1 + _ <- updateLastUsedIndex(statusList.id, newIndex) + } yield (statusList.id, newIndex) def allocateSpaceForCredential( issueCredentialRecordId: DidCommID, @@ -152,14 +150,6 @@ class CredentialStatusListRepositoryInMemory( for { credentialInStatusListStorageRef <- statusListToCredInStatusListStorageRefs(credentialStatusListId) _ <- credentialInStatusListStorageRef.update(r => r + (newCredentialInStatusList.id -> newCredentialInStatusList)) - walletToStatusListStorageRef <- walletToStatusListStorageRefs - _ <- walletToStatusListStorageRef.update(r => { - val value = r.get(credentialStatusListId) - value.fold(r) { v => - val updated = v.copy(lastUsedIndex = statusListIndex, updatedAt = Some(Instant.now)) - r.updated(credentialStatusListId, updated) - } - }) } yield () } @@ -188,37 +178,39 @@ class CredentialStatusListRepositoryInMemory( } yield () } - def getCredentialStatusListsWithCreds: UIO[List[CredentialStatusListWithCreds]] = { + override def getCredentialStatusListIds: UIO[Seq[(WalletId, UUID)]] = for { statusListsRefs <- allStatusListsStorageRefs statusLists <- statusListsRefs.get - statusListWithCredEffects = statusLists.map { (id, statusList) => - val credsinStatusListEffect = statusListToCredInStatusListStorageRefs(id).flatMap(_.get.map(_.values.toList)) - credsinStatusListEffect.map { credsInStatusList => - CredentialStatusListWithCreds( - id = id, - walletId = statusList.walletId, - issuer = statusList.issuer, - issued = statusList.issued, - purpose = statusList.purpose, - statusListCredential = statusList.statusListCredential, - size = statusList.size, - lastUsedIndex = statusList.lastUsedIndex, - credentials = credsInStatusList.map { cred => - CredInStatusList( - id = cred.id, - issueCredentialRecordId = cred.issueCredentialRecordId, - statusListIndex = cred.statusListIndex, - isCanceled = cred.isCanceled, - isProcessed = cred.isProcessed, - ) - } - ) - } + } yield statusLists.values.toList.map(csl => (csl.walletId, csl.id)) - }.toList - res <- ZIO.collectAll(statusListWithCredEffects) - } yield res + def getCredentialStatusListsWithCreds( + statusListId: UUID + ): URIO[WalletAccessContext, CredentialStatusListWithCreds] = { + for { + statusListsRefs <- allStatusListsStorageRefs + statusLists <- statusListsRefs.get + statusList = statusLists(statusListId) + credsInStatusList <- statusListToCredInStatusListStorageRefs(statusList.id).flatMap(_.get.map(_.values.toList)) + } yield CredentialStatusListWithCreds( + id = statusList.id, + walletId = statusList.walletId, + issuer = statusList.issuer, + issued = statusList.issued, + purpose = statusList.purpose, + statusListCredential = statusList.statusListCredential, + size = statusList.size, + lastUsedIndex = statusList.lastUsedIndex, + credentials = credsInStatusList.map { cred => + CredInStatusList( + id = cred.id, + issueCredentialRecordId = cred.issueCredentialRecordId, + statusListIndex = cred.statusListIndex, + isCanceled = cred.isCanceled, + isProcessed = cred.isProcessed, + ) + } + ) } def updateStatusListCredential( diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceSpecHelper.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceSpecHelper.scala index a03eb88803..8ae2fd6602 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceSpecHelper.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceSpecHelper.scala @@ -3,7 +3,6 @@ package org.hyperledger.identus.pollux.core.service import io.circe.Json import org.hyperledger.identus.agent.walletapi.memory.GenericSecretStorageInMemory import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService -import org.hyperledger.identus.agent.walletapi.storage.GenericSecretStorage import org.hyperledger.identus.castor.core.model.did.PrismDID import org.hyperledger.identus.castor.core.service.DIDService import org.hyperledger.identus.mercury.model.{AttachmentDescriptor, DidId} @@ -18,6 +17,7 @@ import org.hyperledger.identus.pollux.core.repository.{ import org.hyperledger.identus.pollux.prex.{ClaimFormat, Ldp, PresentationDefinition} import org.hyperledger.identus.pollux.vc.jwt.* import org.hyperledger.identus.shared.http.UriResolver +import org.hyperledger.identus.shared.messaging.{MessagingService, MessagingServiceConfig, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* @@ -41,6 +41,8 @@ trait CredentialServiceSpecHelper { credentialDefinitionServiceLayer, GenericSecretStorageInMemory.layer, LinkSecretServiceImpl.layer, + (MessagingServiceConfig.inMemoryLayer >>> MessagingService.serviceLayer >>> + MessagingService.producerLayer[UUID, WalletIdAndRecordId]).orDie, CredentialServiceImpl.layer ) diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala index 4f58c2f570..dad75bfcee 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala @@ -16,7 +16,7 @@ import org.hyperledger.identus.pollux.core.service.serdes.{AnoncredCredentialPro import org.hyperledger.identus.pollux.sdjwt.{HolderPrivateKey, PresentationCompact} import org.hyperledger.identus.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCredentialPayload} import org.hyperledger.identus.shared.models.* -import zio.{mock, Duration, IO, UIO, URLayer, ZIO, ZLayer} +import zio.{mock, Duration, IO, UIO, URIO, URLayer, ZIO, ZLayer} import zio.json.* import zio.mock.{Mock, Proxy} @@ -329,7 +329,8 @@ object MockPresentationService extends Mock[PresentationService] { state: PresentationRecord.ProtocolState* ): IO[PresentationError, Seq[PresentationRecord]] = ??? - override def findPresentationRecord(recordId: DidCommID): IO[PresentationError, Option[PresentationRecord]] = ??? + override def findPresentationRecord(recordId: DidCommID): URIO[WalletAccessContext, Option[PresentationRecord]] = + ??? override def findPresentationRecordByThreadId( thid: DidCommID diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpecHelper.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpecHelper.scala index e438d4687b..1e59c4704a 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpecHelper.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpecHelper.scala @@ -1,6 +1,5 @@ package org.hyperledger.identus.pollux.core.service -import com.nimbusds.jose.jwk.* import org.hyperledger.identus.agent.walletapi.memory.GenericSecretStorageInMemory import org.hyperledger.identus.castor.core.model.did.DID import org.hyperledger.identus.mercury.{AgentPeerService, PeerDID} @@ -14,6 +13,7 @@ import org.hyperledger.identus.pollux.core.service.uriResolvers.ResourceUrlResol import org.hyperledger.identus.pollux.vc.jwt.* import org.hyperledger.identus.shared.crypto.KmpSecp256k1KeyOps import org.hyperledger.identus.shared.http.UriResolver +import org.hyperledger.identus.shared.messaging.{MessagingService, MessagingServiceConfig, WalletIdAndRecordId} import org.hyperledger.identus.shared.models.{WalletAccessContext, WalletId} import zio.* @@ -42,7 +42,9 @@ trait PresentationServiceSpecHelper { uriResolverLayer, linkSecretLayer, PresentationRepositoryInMemory.layer, - CredentialRepositoryInMemory.layer + CredentialRepositoryInMemory.layer, + (MessagingServiceConfig.inMemoryLayer >>> MessagingService.serviceLayer >>> + MessagingService.producerLayer[UUID, WalletIdAndRecordId]).orDie, ) ++ defaultWalletLayer def createIssuer(did: String): Issuer = { diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialRepository.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialRepository.scala index 151ebd9e3f..53a3296dc3 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialRepository.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialRepository.scala @@ -504,7 +504,8 @@ class JdbcCredentialRepository(xa: Transactor[ContextAwareTask], xb: Transactor[ | credential_format, | schema_uris, | credential_definition_uri, - | subject_id + | subject_id, + | key_id | FROM public.issue_credential_records | WHERE 1=1 | AND issue_credential_data IS NOT NULL diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialStatusListRepository.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialStatusListRepository.scala index f0a9dc2dbe..f4b27410cf 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialStatusListRepository.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcCredentialStatusListRepository.scala @@ -1,6 +1,8 @@ package org.hyperledger.identus.pollux.sql.repository +import cats.implicits.toFunctorOps import doobie.* +import doobie.free.connection.ConnectionOp import doobie.implicits.* import doobie.postgres.* import doobie.postgres.implicits.* @@ -8,8 +10,7 @@ import org.hyperledger.identus.castor.core.model.did.* import org.hyperledger.identus.pollux.core.model.* import org.hyperledger.identus.pollux.core.repository.CredentialStatusListRepository import org.hyperledger.identus.pollux.vc.jwt.{Issuer, StatusPurpose} -import org.hyperledger.identus.pollux.vc.jwt.revocation.{BitString, BitStringError, VCStatusList2021} -import org.hyperledger.identus.pollux.vc.jwt.revocation.BitStringError.* +import org.hyperledger.identus.pollux.vc.jwt.revocation.BitString import org.hyperledger.identus.shared.db.ContextAwareTask import org.hyperledger.identus.shared.db.Implicits.* import org.hyperledger.identus.shared.db.Implicits.given @@ -18,7 +19,7 @@ import zio.* import zio.interop.catz.* import java.time.Instant -import java.util.UUID +import java.util.{Objects, UUID} class JdbcCredentialStatusListRepository(xa: Transactor[ContextAwareTask], xb: Transactor[Task]) extends CredentialStatusListRepository { @@ -47,9 +48,19 @@ class JdbcCredentialStatusListRepository(xa: Transactor[ContextAwareTask], xb: T .orDie } - def getLatestOfTheWallet: URIO[WalletAccessContext, Option[CredentialStatusList]] = { + override def incrementAndGetStatusListIndex( + jwtIssuer: Issuer, + statusListRegistryUrl: String + ): URIO[WalletAccessContext, (UUID, Int)] = { - val cxnIO = + def acquireAdvisoryLock(walletId: WalletId): ConnectionIO[Unit] = { + // Should be specific to this process + val PROCESS_UNIQUE_ID = 235457 + val hashCode = Objects.hash(walletId.hashCode(), PROCESS_UNIQUE_ID) + sql"SELECT pg_advisory_xact_lock($hashCode)".query[Unit].unique.void + } + + def getLatestOfTheWallet: ConnectionIO[Option[CredentialStatusList]] = sql""" | SELECT | id, @@ -62,74 +73,70 @@ class JdbcCredentialStatusListRepository(xa: Transactor[ContextAwareTask], xb: T | last_used_index, | created_at, | updated_at - | FROM public.credential_status_lists order by created_at DESC limit 1 + | FROM public.credential_status_lists + | ORDER BY created_at DESC limit 1 |""".stripMargin .query[CredentialStatusList] .option - cxnIO - .transactWallet(xa) - .orDie - - } + def createNewForTheWallet( + id: UUID, + issuerDid: String, + issued: Instant, + credentialStr: String + ): ConnectionIO[CredentialStatusList] = + sql""" + |INSERT INTO public.credential_status_lists ( + | id, + | issuer, + | issued, + | purpose, + | status_list_credential, + | size, + | last_used_index, + | wallet_id + | ) + |VALUES ( + | $id, + | $issuerDid, + | $issued, + | ${StatusPurpose.Revocation}::public.enum_credential_status_list_purpose, + | $credentialStr::JSON, + | ${BitString.MIN_SL2021_SIZE}, + | 0, + | current_setting('app.current_wallet_id')::UUID + | ) + |RETURNING id, wallet_id, issuer, issued, purpose, status_list_credential, size, last_used_index, created_at, updated_at + """.stripMargin + .query[CredentialStatusList] + .unique - def createNewForTheWallet( - jwtIssuer: Issuer, - statusListRegistryUrl: String - ): URIO[WalletAccessContext, CredentialStatusList] = { - - val id = UUID.randomUUID() - val issued = Instant.now() - val issuerDid = jwtIssuer.did.toString - - val credentialWithEmbeddedProof = for { - bitString <- BitString.getInstance().mapError { - case InvalidSize(message) => new Throwable(message) - case EncodingError(message) => new Throwable(message) - case DecodingError(message) => new Throwable(message) - case IndexOutOfBounds(message) => new Throwable(message) - } - resourcePath = - s"credential-status/$id" - emptyStatusListCredential <- VCStatusList2021 - .build( - vcId = s"$statusListRegistryUrl/credential-status/$id", - revocationData = bitString, - jwtIssuer = jwtIssuer - ) - .mapError(x => new Throwable(x.msg)) - - credentialWithEmbeddedProof <- emptyStatusListCredential.toJsonWithEmbeddedProof - } yield credentialWithEmbeddedProof.spaces2 + def updateLastUsedIndex(statusListId: UUID, lastUsedIndex: Int): ConnectionIO[Int] = + sql""" + | UPDATE public.credential_status_lists + | SET + | last_used_index = $lastUsedIndex, + | updated_at = ${Instant.now()} + | WHERE + | id = $statusListId + |""".stripMargin.update.run (for { - credentialStr <- credentialWithEmbeddedProof - query = sql""" - |INSERT INTO public.credential_status_lists ( - | id, - | issuer, - | issued, - | purpose, - | status_list_credential, - | size, - | last_used_index, - | wallet_id - | ) - |VALUES ( - | $id, - | $issuerDid, - | $issued, - | ${StatusPurpose.Revocation}::public.enum_credential_status_list_purpose, - | $credentialStr::JSON, - | ${BitString.MIN_SL2021_SIZE}, - | 0, - | current_setting('app.current_wallet_id')::UUID - | ) - |RETURNING id, wallet_id, issuer, issued, purpose, status_list_credential, size, last_used_index, created_at, updated_at - """.stripMargin.query[CredentialStatusList].unique - newStatusList <- query.transactWallet(xa) - } yield newStatusList).orDie - + id <- ZIO.succeed(UUID.randomUUID()) + newStatusListVC <- createStatusListVC(jwtIssuer, statusListRegistryUrl, id) + walletCtx <- ZIO.service[WalletAccessContext] + walletId = walletCtx.walletId + cnxIO = for { + _ <- acquireAdvisoryLock(walletId) + maybeStatusList <- getLatestOfTheWallet + statusList <- maybeStatusList match + case Some(csl) if csl.lastUsedIndex < csl.size => cats.free.Free.pure[ConnectionOp, CredentialStatusList](csl) + case _ => createNewForTheWallet(id, jwtIssuer.did.toString, Instant.now(), newStatusListVC) + newIndex = statusList.lastUsedIndex + 1 + _ <- updateLastUsedIndex(statusList.id, newIndex) + } yield (statusList.id, newIndex) + result <- cnxIO.transactWallet(xa) + } yield result).orDie } def allocateSpaceForCredential( @@ -214,9 +221,24 @@ class JdbcCredentialStatusListRepository(xa: Transactor[ContextAwareTask], xb: T } yield () } - def getCredentialStatusListsWithCreds: UIO[List[CredentialStatusListWithCreds]] = { + def getCredentialStatusListIds: UIO[Seq[(WalletId, UUID)]] = { + val cxnIO = + sql""" + | SELECT + | wallet_id, + | id + | FROM public.credential_status_lists + |""".stripMargin + .query[(WalletId, UUID)] + .to[Seq] + cxnIO + .transact(xb) + .orDie + } - // Might need to add wallet Id in the select query, because I'm selecting all of them + def getCredentialStatusListsWithCreds( + statusListId: UUID + ): URIO[WalletAccessContext, CredentialStatusListWithCreds] = { val cxnIO = sql""" | SELECT @@ -235,42 +257,35 @@ class JdbcCredentialStatusListRepository(xa: Transactor[ContextAwareTask], xb: T | cisl.is_processed | FROM public.credential_status_lists csl | LEFT JOIN public.credentials_in_status_list cisl ON csl.id = cisl.credential_status_list_id + | WHERE + | csl.id = $statusListId |""".stripMargin .query[CredentialStatusListWithCred] .to[List] - - val credentialStatusListsWithCredZio = cxnIO - .transact(xb) - .orDie - - for { - credentialStatusListsWithCred <- credentialStatusListsWithCredZio - } yield { - credentialStatusListsWithCred - .groupBy(_.credentialStatusListId) - .map { case (id, items) => - CredentialStatusListWithCreds( - id, - items.head.walletId, - items.head.issuer, - items.head.issued, - items.head.purpose, - items.head.statusListCredential, - items.head.size, - items.head.lastUsedIndex, - items.map { item => - CredInStatusList( - item.credentialInStatusListId, - item.issueCredentialRecordId, - item.statusListIndex, - item.isCanceled, - item.isProcessed, - ) - } + .transactWallet(xa) + .orDie + + cxnIO.map(items => + CredentialStatusListWithCreds( + statusListId, + items.head.walletId, + items.head.issuer, + items.head.issued, + items.head.purpose, + items.head.statusListCredential, + items.head.size, + items.head.lastUsedIndex, + items.map { item => + CredInStatusList( + item.credentialInStatusListId, + item.issueCredentialRecordId, + item.statusListIndex, + item.isCanceled, + item.isProcessed, ) } - .toList - } + ) + ) } def updateStatusListCredential( diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala index 1e477640c1..71b4cad3dc 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala @@ -459,7 +459,6 @@ class JdbcPresentationRepository( | id = $recordId | AND protocol_state = $from """.stripMargin.update - cxnIO.run .transactWallet(xa) .orDie diff --git a/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala b/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala index 3d24747bd1..5638ba028a 100644 --- a/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala +++ b/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala @@ -79,7 +79,7 @@ sealed trait CredentialPayload { def issuer: String | CredentialIssuer - def maybeCredentialStatus: Option[CredentialStatus] + def maybeCredentialStatus: Option[CredentialStatus | List[CredentialStatus]] def maybeRefreshService: Option[RefreshService] @@ -145,7 +145,7 @@ case class JwtVc( maybeValidFrom: Option[Instant], maybeValidUntil: Option[Instant], maybeIssuer: Option[String | CredentialIssuer], - maybeCredentialStatus: Option[CredentialStatus], + maybeCredentialStatus: Option[CredentialStatus | List[CredentialStatus]], maybeRefreshService: Option[RefreshService], maybeEvidence: Option[Json], maybeTermsOfUse: Option[Json] @@ -182,7 +182,7 @@ case class W3cCredentialPayload( maybeExpirationDate: Option[Instant], override val maybeCredentialSchema: Option[CredentialSchema | List[CredentialSchema]], override val credentialSubject: Json, - override val maybeCredentialStatus: Option[CredentialStatus], + override val maybeCredentialStatus: Option[CredentialStatus | List[CredentialStatus]], override val maybeRefreshService: Option[RefreshService], override val maybeEvidence: Option[Json], override val maybeTermsOfUse: Option[Json], @@ -239,6 +239,11 @@ object CredentialPayload { ("statusListCredential", credentialStatus.statusListCredential.asJson) ) + implicit val credentialStatusOrListEncoder: Encoder[CredentialStatus | List[CredentialStatus]] = Encoder.instance { + case status: CredentialStatus => Encoder[CredentialStatus].apply(status) + case statusList: List[CredentialStatus] => Encoder[List[CredentialStatus]].apply(statusList) + } + implicit val stringOrCredentialIssuerEncoder: Encoder[String | CredentialIssuer] = Encoder.instance { case string: String => Encoder[String].apply(string) case credentialIssuer: CredentialIssuer => Encoder[CredentialIssuer].apply(credentialIssuer) @@ -383,6 +388,11 @@ object CredentialPayload { .map(schema => schema: CredentialSchema | List[CredentialSchema]) .or(Decoder[List[CredentialSchema]].map(schema => schema: CredentialSchema | List[CredentialSchema])) + implicit val credentialStatusOrListDecoder: Decoder[CredentialStatus | List[CredentialStatus]] = + Decoder[CredentialStatus] + .map(status => status: CredentialStatus | List[CredentialStatus]) + .or(Decoder[List[CredentialStatus]].map(status => status: CredentialStatus | List[CredentialStatus])) + implicit val w3cCredentialPayloadDecoder: Decoder[W3cCredentialPayload] = (c: HCursor) => for { @@ -404,7 +414,7 @@ object CredentialPayload { .downField("credentialSchema") .as[Option[CredentialSchema | List[CredentialSchema]]] credentialSubject <- c.downField("credentialSubject").as[Json] - maybeCredentialStatus <- c.downField("credentialStatus").as[Option[CredentialStatus]] + maybeCredentialStatus <- c.downField("credentialStatus").as[Option[CredentialStatus | List[CredentialStatus]]] maybeRefreshService <- c.downField("refreshService").as[Option[RefreshService]] maybeEvidence <- c.downField("evidence").as[Option[Json]] maybeTermsOfUse <- c.downField("termsOfUse").as[Option[Json]] @@ -443,7 +453,7 @@ object CredentialPayload { .downField("credentialSchema") .as[Option[CredentialSchema | List[CredentialSchema]]] credentialSubject <- c.downField("credentialSubject").as[Json] - maybeCredentialStatus <- c.downField("credentialStatus").as[Option[CredentialStatus]] + maybeCredentialStatus <- c.downField("credentialStatus").as[Option[CredentialStatus | List[CredentialStatus]]] maybeRefreshService <- c.downField("refreshService").as[Option[RefreshService]] maybeEvidence <- c.downField("evidence").as[Option[Json]] maybeTermsOfUse <- c.downField("termsOfUse").as[Option[Json]] @@ -837,7 +847,7 @@ object JwtCredential { } yield Validation.validateWith(signatureValidation, dateVerification, revocationVerification)((a, _, _) => a) } - private def verifyRevocationStatusJwt(jwt: JWT)(uriResolver: UriResolver): IO[String, Validation[String, Unit]] = { + def verifyRevocationStatusJwt(jwt: JWT)(uriResolver: UriResolver): IO[String, Validation[String, Unit]] = { val decodeJWT = ZIO .fromTry(JwtCirce.decodeRaw(jwt.value, options = JwtOptions(false, false, false))) @@ -847,12 +857,19 @@ object JwtCredential { decodedJWT <- decodeJWT jwtCredentialPayload <- ZIO.fromEither(decode[JwtCredentialPayload](decodedJWT)).mapError(_.getMessage) credentialStatus = jwtCredentialPayload.vc.maybeCredentialStatus - result = credentialStatus.fold(ZIO.succeed(Validation.unit))(status => - CredentialVerification.verifyCredentialStatus(status)(uriResolver) + .map { + { + case status: CredentialStatus => List(status) + case statusList: List[CredentialStatus] => statusList + } + } + .getOrElse(List.empty) + results <- ZIO.collectAll( + credentialStatus.map(status => CredentialVerification.verifyCredentialStatus(status)(uriResolver)) ) + result = Validation.validateAll(results).flatMap(_ => Validation.unit) } yield result - - res.flatten + res } } @@ -927,11 +944,20 @@ object W3CCredential { private def verifyRevocationStatusW3c( w3cPayload: W3cVerifiableCredentialPayload, )(uriResolver: UriResolver): IO[String, Validation[String, Unit]] = { - // If credential does not have credential status list, it does not support revocation - // and we assume revocation status is valid. - w3cPayload.payload.maybeCredentialStatus.fold(ZIO.succeed(Validation.unit))(status => - CredentialVerification.verifyCredentialStatus(status)(uriResolver) - ) + val credentialStatus = w3cPayload.payload.maybeCredentialStatus + .map { + { + case status: CredentialStatus => List(status) + case statusList: List[CredentialStatus] => statusList + } + } + .getOrElse(List.empty) + for { + results <- ZIO.collectAll( + credentialStatus.map(status => CredentialVerification.verifyCredentialStatus(status)(uriResolver)) + ) + result = Validation.validateAll(results).flatMap(_ => Validation.unit) + } yield result } def verify(w3cPayload: W3cVerifiableCredentialPayload, options: CredentialVerification.CredentialVerificationOptions)( diff --git a/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala b/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala index e09f9e6e96..8222a4fe64 100644 --- a/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala +++ b/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala @@ -7,6 +7,7 @@ import io.circe.* import io.circe.syntax.* import org.hyperledger.identus.castor.core.model.did.{DID, VerificationRelationship} import org.hyperledger.identus.pollux.vc.jwt.CredentialPayload.Implicits.* +import org.hyperledger.identus.pollux.vc.jwt.StatusPurpose.Revocation import org.hyperledger.identus.shared.http.* import zio.* import zio.prelude.Validation @@ -62,7 +63,11 @@ object JWTVerificationTest extends ZIOSpecDefault { |} |""".stripMargin - private def createJwtCredential(issuer: IssuerWithKey, issuerAsObject: Boolean = false): JWT = { + private def createJwtCredential( + issuer: IssuerWithKey, + issuerAsObject: Boolean = false, + credentialStatus: Option[CredentialStatus | List[CredentialStatus]] = None + ): JWT = { val validFrom = Instant.parse("2010-01-05T00:00:00Z") // ISSUANCE DATE val jwtCredentialNbf = Instant.parse("2010-01-01T00:00:00Z") // ISSUANCE DATE val validUntil = Instant.parse("2010-01-09T00:00:00Z") // EXPIRATION DATE @@ -75,7 +80,7 @@ object JWTVerificationTest extends ZIOSpecDefault { `type` = Set("VerifiableCredential", "UniversityDegreeCredential"), maybeCredentialSchema = None, credentialSubject = Json.obj("id" -> Json.fromString("1")), - maybeCredentialStatus = None, + maybeCredentialStatus = credentialStatus, maybeRefreshService = None, maybeEvidence = None, maybeTermsOfUse = None, @@ -190,6 +195,51 @@ object JWTVerificationTest extends ZIOSpecDefault { ) ) }, + test("fail verification if proof is valid but credential is revoked at the give status list index given list") { + val revokedStatus: List[CredentialStatus] = List( + org.hyperledger.identus.pollux.vc.jwt.CredentialStatus( + id = "http://localhost:8085/credential-status/664382dc-9e6d-4d0c-99d1-85e2c74eb5e9#1", + statusPurpose = StatusPurpose.Revocation, + `type` = "StatusList2021Entry", + statusListCredential = "http://localhost:8085/credential-status/664382dc-9e6d-4d0c-99d1-85e2c74eb5e9", + statusListIndex = 1 + ), + org.hyperledger.identus.pollux.vc.jwt.CredentialStatus( + id = "http://localhost:8085/credential-status/664382dc-9e6d-4d0c-99d1-85e2c74eb5e9#2", + statusPurpose = StatusPurpose.Suspension, + `type` = "StatusList2021Entry", + statusListCredential = "http://localhost:8085/credential-status/664382dc-9e6d-4d0c-99d1-85e2c74eb5e9", + statusListIndex = 1 + ) + ) + + val urlResolver = new UriResolver { + override def resolve(uri: String): IO[GenericUriResolverError, String] = { + ZIO.succeed(statusListCredentialString) + } + } + + val genericUriResolver = GenericUriResolver( + Map( + "data" -> DataUrlResolver(), + "http" -> urlResolver, + "https" -> urlResolver + ) + ) + val issuer = createUser("did:prism:issuer") + val jwtCredential = createJwtCredential(issuer, credentialStatus = Some(revokedStatus)) + + for { + validation <- JwtCredential.verifyRevocationStatusJwt(jwtCredential)(genericUriResolver) + } yield assertTrue( + validation.fold( + chunk => + chunk.length == 2 && chunk.head.contentEquals("Credential is revoked") && chunk.tail.head + .contentEquals("Credential is revoked"), + _ => false + ) + ) + }, test("validate dates happy path") { val issuer = createUser("did:prism:issuer") val jwtCredential = createJwtCredential(issuer) @@ -223,6 +273,29 @@ object JWTVerificationTest extends ZIOSpecDefault { jwtWithObjectIssuerIssuer.equals(jwtIssuer) ) }, + test("validate credential status list") { + val issuer = createUser("did:prism:issuer") + val status = CredentialStatus(id = "id", `type` = "type", statusPurpose = Revocation, 1, "1") + val encodedJwtWithStatusList = createJwtCredential( + issuer, + false, + Some(List(status)) + ) + val econdedJwtWithStatusObject = createJwtCredential(issuer, true, Some(status)) + for { + decodeJwtWithStatusList <- JwtCredential + .decodeJwt(encodedJwtWithStatusList) + decodeJwtWithStatusObject <- JwtCredential + .decodeJwt(econdedJwtWithStatusObject) + statusFromList = decodeJwtWithStatusList.vc.maybeCredentialStatus.map { + case list: List[CredentialStatus] => list.head + case _: CredentialStatus => throw new IllegalStateException("List expected") + }.get + statusFromObjet = decodeJwtWithStatusObject.vc.maybeCredentialStatus.get + } yield assertTrue( + statusFromList.equals(statusFromObjet) + ) + }, test("validate dates should fail given after valid until") { val issuer = createUser("did:prism:issuer") val jwtCredential = createJwtCredential(issuer) diff --git a/project/build.properties b/project/build.properties index ee4c672cd0..0b699c3052 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.1 +sbt.version=1.10.2 diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingService.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingService.scala new file mode 100644 index 0000000000..8c3a60e56e --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingService.scala @@ -0,0 +1,106 @@ +package org.hyperledger.identus.shared.messaging + +import org.hyperledger.identus.shared.messaging.kafka.{InMemoryMessagingService, ZKafkaMessagingServiceImpl} +import zio.{durationInt, Cause, Duration, EnvironmentTag, RIO, RLayer, Task, URIO, URLayer, ZIO, ZLayer} + +import java.time.Instant +trait MessagingService { + def makeConsumer[K, V](groupId: String)(implicit kSerde: Serde[K], vSerde: Serde[V]): Task[Consumer[K, V]] + def makeProducer[K, V]()(implicit kSerde: Serde[K], vSerde: Serde[V]): Task[Producer[K, V]] +} + +object MessagingService { + + case class RetryStep(topicName: String, consumerCount: Int, consumerBackoff: Duration, nextTopicName: Option[String]) + + object RetryStep { + def apply(topicName: String, consumerCount: Int, consumerBackoff: Duration, nextTopicName: String): RetryStep = + RetryStep(topicName, consumerCount, consumerBackoff, Some(nextTopicName)) + } + + def consumeWithRetryStrategy[K: EnvironmentTag, V: EnvironmentTag, HR]( + groupId: String, + handler: Message[K, V] => RIO[HR, Unit], + steps: Seq[RetryStep] + )(implicit kSerde: Serde[K], vSerde: Serde[V]): RIO[HR & Producer[K, V] & MessagingService, Unit] = { + for { + messagingService <- ZIO.service[MessagingService] + messageProducer <- ZIO.service[Producer[K, V]] + _ <- ZIO.foreachPar(steps) { step => + ZIO.foreachPar(1 to step.consumerCount)(_ => + for { + consumer <- messagingService.makeConsumer[K, V](groupId) + _ <- consumer + .consume[HR](step.topicName) { m => + for { + // Wait configured backoff before processing message + millisSpentInQueue <- ZIO.succeed(Instant.now().toEpochMilli - m.timestamp) + sleepDelay = step.consumerBackoff.toMillis - millisSpentInQueue + _ <- ZIO.when(sleepDelay > 0)(ZIO.sleep(Duration.fromMillis(sleepDelay))) + _ <- handler(m) + .catchAll { t => + for { + _ <- ZIO.logErrorCause(s"Error processing message: ${m.key} ", Cause.fail(t)) + _ <- step.nextTopicName match + case Some(name) => + messageProducer + .produce(name, m.key, m.value) + .catchAll(t => + ZIO.logErrorCause("Unable to send message to the next topic", Cause.fail(t)) + ) + case None => ZIO.unit + } yield () + } + .catchAllDefect(t => ZIO.logErrorCause(s"Defect processing message: ${m.key} ", Cause.fail(t))) + } yield () + } + .debug + .fork + } yield () + ) + } + } yield () + } + + def consume[K: EnvironmentTag, V: EnvironmentTag, HR]( + groupId: String, + topicName: String, + consumerCount: Int, + handler: Message[K, V] => RIO[HR, Unit] + )(implicit kSerde: Serde[K], vSerde: Serde[V]): RIO[HR & Producer[K, V] & MessagingService, Unit] = + consumeWithRetryStrategy(groupId, handler, Seq(RetryStep(topicName, consumerCount, 0.seconds, None))) + + val serviceLayer: URLayer[MessagingServiceConfig, MessagingService] = + ZLayer + .service[MessagingServiceConfig] + .flatMap(config => + if (config.get.kafkaEnabled) ZKafkaMessagingServiceImpl.layer + else InMemoryMessagingService.layer + ) + + def producerLayer[K: EnvironmentTag, V: EnvironmentTag](implicit + kSerde: Serde[K], + vSerde: Serde[V] + ): RLayer[MessagingService, Producer[K, V]] = ZLayer.fromZIO(for { + messagingService <- ZIO.service[MessagingService] + producer <- messagingService.makeProducer[K, V]() + } yield producer) + + def consumerLayer[K: EnvironmentTag, V: EnvironmentTag](groupId: String)(implicit + kSerde: Serde[K], + vSerde: Serde[V] + ): RLayer[MessagingService, Consumer[K, V]] = ZLayer.fromZIO(for { + messagingService <- ZIO.service[MessagingService] + consumer <- messagingService.makeConsumer[K, V](groupId) + } yield consumer) + +} + +case class Message[K, V](key: K, value: V, offset: Long, timestamp: Long) + +trait Consumer[K, V] { + def consume[HR](topic: String, topics: String*)(handler: Message[K, V] => URIO[HR, Unit]): RIO[HR, Unit] +} +trait Producer[K, V] { + def produce(topic: String, key: K, value: V): Task[Unit] +} diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingServiceConfig.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingServiceConfig.scala new file mode 100644 index 0000000000..dd63c1a424 --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/MessagingServiceConfig.scala @@ -0,0 +1,58 @@ +package org.hyperledger.identus.shared.messaging + +import zio.{ULayer, ZLayer} + +import java.time.Duration + +case class MessagingServiceConfig( + connectFlow: ConsumerJobConfig, + issueFlow: ConsumerJobConfig, + presentFlow: ConsumerJobConfig, + didStateSync: ConsumerJobConfig, + statusListSync: ConsumerJobConfig, + inMemoryQueueCapacity: Int, + kafkaEnabled: Boolean, + kafka: Option[KafkaConfig] +) + +final case class ConsumerJobConfig( + consumerCount: Int, + retryStrategy: Option[ConsumerRetryStrategy] +) + +final case class ConsumerRetryStrategy( + maxRetries: Int, + initialDelay: Duration, + maxDelay: Duration +) + +final case class KafkaConfig( + bootstrapServers: String, + consumers: KafkaConsumersConfig +) + +final case class KafkaConsumersConfig( + autoCreateTopics: Boolean, + maxPollRecords: Int, + maxPollInterval: Duration, + pollTimeout: Duration, + rebalanceSafeCommits: Boolean +) + +object MessagingServiceConfig { + + val inMemoryLayer: ULayer[MessagingServiceConfig] = + ZLayer.succeed( + MessagingServiceConfig( + ConsumerJobConfig(1, None), + ConsumerJobConfig(1, None), + ConsumerJobConfig(1, None), + ConsumerJobConfig(1, None), + ConsumerJobConfig(1, None), + 100, + false, + None + ) + ) + +} diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/Serde.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/Serde.scala new file mode 100644 index 0000000000..94eadf3849 --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/Serde.scala @@ -0,0 +1,55 @@ +package org.hyperledger.identus.shared.messaging + +import org.hyperledger.identus.shared.models.WalletId + +import java.nio.charset.StandardCharsets +import java.nio.ByteBuffer +import java.util.UUID + +case class ByteArrayWrapper(ba: Array[Byte]) + +trait Serde[T] { + def serialize(t: T): Array[Byte] + def deserialize(ba: Array[Byte]): T +} + +object Serde { + given byteArraySerde: Serde[ByteArrayWrapper] = new Serde[ByteArrayWrapper] { + override def serialize(t: ByteArrayWrapper): Array[Byte] = t.ba + override def deserialize(ba: Array[Byte]): ByteArrayWrapper = ByteArrayWrapper(ba) + } + + given stringSerde: Serde[String] = new Serde[String] { + override def serialize(t: String): Array[Byte] = t.getBytes() + override def deserialize(ba: Array[Byte]): String = new String(ba, StandardCharsets.UTF_8) + } + + given intSerde: Serde[Int] = new Serde[Int] { + override def serialize(t: Int): Array[Byte] = { + val buffer = java.nio.ByteBuffer.allocate(4) + buffer.putInt(t) + buffer.array() + } + override def deserialize(ba: Array[Byte]): Int = ByteBuffer.wrap(ba).getInt() + } + + given uuidSerde: Serde[UUID] = new Serde[UUID] { + override def serialize(t: UUID): Array[Byte] = { + val buffer = java.nio.ByteBuffer.allocate(16) + buffer.putLong(t.getMostSignificantBits) + buffer.putLong(t.getLeastSignificantBits) + buffer.array() + } + override def deserialize(ba: Array[Byte]): UUID = { + val byteBuffer = ByteBuffer.wrap(ba) + val high = byteBuffer.getLong + val low = byteBuffer.getLong + new UUID(high, low) + } + } + + given walletIdSerde(using uuidSerde: Serde[UUID]): Serde[WalletId] = new Serde[WalletId] { + override def serialize(w: WalletId): Array[Byte] = uuidSerde.serialize(w.toUUID) + override def deserialize(ba: Array[Byte]): WalletId = WalletId.fromUUID(uuidSerde.deserialize(ba)) + } +} diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/WalletIdAndRecordId.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/WalletIdAndRecordId.scala new file mode 100644 index 0000000000..ff1c9e8d76 --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/WalletIdAndRecordId.scala @@ -0,0 +1,20 @@ +package org.hyperledger.identus.shared.messaging + +import zio.json.{DecoderOps, DeriveJsonDecoder, DeriveJsonEncoder, EncoderOps, JsonDecoder, JsonEncoder} + +import java.nio.charset.StandardCharsets +import java.util.UUID + +case class WalletIdAndRecordId(walletId: UUID, recordId: UUID) + +object WalletIdAndRecordId { + given encoder: JsonEncoder[WalletIdAndRecordId] = DeriveJsonEncoder.gen[WalletIdAndRecordId] + given decoder: JsonDecoder[WalletIdAndRecordId] = DeriveJsonDecoder.gen[WalletIdAndRecordId] + given ser: Serde[WalletIdAndRecordId] = new Serde[WalletIdAndRecordId] { + override def serialize(t: WalletIdAndRecordId): Array[Byte] = t.toJson.getBytes(StandardCharsets.UTF_8) + override def deserialize(ba: Array[Byte]): WalletIdAndRecordId = + new String(ba, StandardCharsets.UTF_8) + .fromJson[WalletIdAndRecordId] + .getOrElse(throw RuntimeException("Deserialization Error WalletIdAndRecordId")) + } +} diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/InMemoryMessagingService.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/InMemoryMessagingService.scala new file mode 100644 index 0000000000..54d8c935c2 --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/InMemoryMessagingService.scala @@ -0,0 +1,146 @@ +package org.hyperledger.identus.shared.messaging.kafka + +import org.hyperledger.identus.shared.messaging.* +import org.hyperledger.identus.shared.messaging.kafka.InMemoryMessagingService.* +import zio.* +import zio.concurrent.ConcurrentMap +import zio.stream.* + +import java.util.concurrent.TimeUnit + +case class ConsumerGroupKey(groupId: GroupId, topic: Topic) + +class InMemoryMessagingService( + topicQueues: ConcurrentMap[Topic, (Queue[Message[_, _]], Ref[Offset])], + queueCapacity: Int, + processedMessagesMap: ConcurrentMap[ + ConsumerGroupKey, + ConcurrentMap[Offset, TimeStamp] + ] +) extends MessagingService { + + override def makeConsumer[K, V](groupId: String)(using kSerde: Serde[K], vSerde: Serde[V]): Task[Consumer[K, V]] = { + ZIO.succeed(new InMemoryConsumer[K, V](groupId, topicQueues, processedMessagesMap)) + } + + override def makeProducer[K, V]()(using kSerde: Serde[K], vSerde: Serde[V]): Task[Producer[K, V]] = + ZIO.succeed(new InMemoryProducer[K, V](topicQueues, queueCapacity)) +} + +class InMemoryConsumer[K, V]( + groupId: GroupId, + topicQueues: ConcurrentMap[Topic, (Queue[Message[_, _]], Ref[Offset])], + processedMessagesMap: ConcurrentMap[ConsumerGroupKey, ConcurrentMap[Offset, TimeStamp]] +) extends Consumer[K, V] { + override def consume[HR](topic: String, topics: String*)(handler: Message[K, V] => URIO[HR, Unit]): RIO[HR, Unit] = { + val allTopics = topic +: topics + def getQueueStream(topic: String): ZStream[Any, Nothing, (String, Message[K, V])] = + ZStream.repeatZIO { + topicQueues.get(topic).flatMap { + case Some((queue, _)) => + ZIO.debug(s"Connected to queue for topic $topic in group $groupId") *> + ZIO.succeed(ZStream.fromQueue(queue).collect { case msg: Message[K, V] @unchecked => (topic, msg) }) + case None => + ZIO.sleep(1.second) *> ZIO.succeed(ZStream.empty) + } + }.flatten + + val streams = allTopics.map(getQueueStream) + ZStream + .mergeAllUnbounded()(streams: _*) + .tap { case (topic, msg) => ZIO.log(s"Processing message in group $groupId, topic:$topic : $msg") } + .filterZIO { case (topic, msg) => + for { + currentTime <- Clock.currentTime(TimeUnit.MILLISECONDS) + key = ConsumerGroupKey(groupId, topic) + topicProcessedMessages <- processedMessagesMap.get(key).flatMap { + case Some(map) => ZIO.succeed(map) + case None => + for { + newMap <- ConcurrentMap.empty[Offset, TimeStamp] + _ <- processedMessagesMap.put(key, newMap) + } yield newMap + } + isNew <- topicProcessedMessages + .putIfAbsent(Offset(msg.offset), TimeStamp(currentTime)) + .map(_.isEmpty) + } yield isNew + } + .mapZIO { case (_, msg) => handler(msg) } + .tap(_ => ZIO.log(s"Message processed in group $groupId, topic:$topic")) + .runDrain + } +} + +class InMemoryProducer[K, V]( + topicQueues: ConcurrentMap[Topic, (Queue[Message[_, _]], Ref[Offset])], + queueCapacity: Int +) extends Producer[K, V] { + override def produce(topic: String, key: K, value: V): Task[Unit] = for { + queueAndOffsetRef <- topicQueues.get(topic).flatMap { + case Some(qAndOffSetRef) => ZIO.succeed(qAndOffSetRef) + case None => + for { + newQueue <- Queue.sliding[Message[_, _]](queueCapacity) + newOffSetRef <- Ref.make(Offset(0L)) + _ <- topicQueues.put(topic, (newQueue, newOffSetRef)) + } yield (newQueue, newOffSetRef) + } + (queue, offsetRef) = queueAndOffsetRef + currentTime <- Clock.currentTime(TimeUnit.MILLISECONDS) + messageId <- offsetRef.updateAndGet(x => Offset(x.value + 1)) // unique atomic id incremented per topic + _ <- queue.offer(Message(key, value, messageId.value, currentTime)) + } yield () +} + +object InMemoryMessagingService { + type Topic = String + type GroupId = String + + opaque type Offset = Long + object Offset: + def apply(value: Long): Offset = value + extension (id: Offset) def value: Long = id + + opaque type TimeStamp = Long + object TimeStamp: + def apply(value: Long): TimeStamp = value + extension (ts: TimeStamp) def value: Long = ts + + val layer: URLayer[MessagingServiceConfig, MessagingService] = + ZLayer.fromZIO { + for { + config <- ZIO.service[MessagingServiceConfig] + queueMap <- ConcurrentMap.empty[Topic, (Queue[Message[_, _]], Ref[Offset])] + processedMessagesMap <- ConcurrentMap.empty[ConsumerGroupKey, ConcurrentMap[Offset, TimeStamp]] + _ <- cleanupTaskForProcessedMessages(processedMessagesMap) + } yield new InMemoryMessagingService(queueMap, config.inMemoryQueueCapacity, processedMessagesMap) + } + + private def cleanupTaskForProcessedMessages( + processedMessagesMap: ConcurrentMap[ConsumerGroupKey, ConcurrentMap[Offset, TimeStamp]], + maxAge: Duration = 60.minutes // Maximum age for entries + ): UIO[Unit] = { + def cleanupOldEntries(map: ConcurrentMap[Offset, TimeStamp]): UIO[Unit] = for { + currentTime <- Clock.currentTime(TimeUnit.MILLISECONDS) + entries <- map.toList + _ <- ZIO.foreachDiscard(entries) { case (key, timestamp) => + if (currentTime - timestamp > maxAge.toMillis) + map.remove(key) *> ZIO.log(s"Removed old entry with key: $key and timestamp: $timestamp") + else + ZIO.unit + } + } yield () + + (for { + entries <- processedMessagesMap.toList + _ <- ZIO.foreachDiscard(entries) { case (key, map) => + ZIO.log(s"Cleaning up entries for group: ${key.groupId} and topic: ${key.topic}") *> + cleanupOldEntries(map) + } + } yield ()) + .repeat(Schedule.spaced(10.minutes)) + .fork + .unit + } +} diff --git a/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/ZKafkaMessagingServiceImpl.scala b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/ZKafkaMessagingServiceImpl.scala new file mode 100644 index 0000000000..9180fc4d62 --- /dev/null +++ b/shared/core/src/main/scala/org/hyperledger/identus/shared/messaging/kafka/ZKafkaMessagingServiceImpl.scala @@ -0,0 +1,136 @@ +package org.hyperledger.identus.shared.messaging.kafka + +import org.apache.kafka.clients.consumer.ConsumerConfig +import org.apache.kafka.common.header.Headers +import org.hyperledger.identus.shared.messaging.* +import zio.{Duration, RIO, Task, URIO, URLayer, ZIO, ZLayer} +import zio.kafka.consumer.{ + Consumer as ZKConsumer, + ConsumerSettings as ZKConsumerSettings, + Subscription as ZKSubscription +} +import zio.kafka.producer.{Producer as ZKProducer, ProducerSettings as ZKProducerSettings} +import zio.kafka.serde.{Deserializer as ZKDeserializer, Serializer as ZKSerializer} + +class ZKafkaMessagingServiceImpl( + bootstrapServers: List[String], + autoCreateTopics: Boolean, + maxPollRecords: Int, + maxPollInterval: Duration, + pollTimeout: Duration, + rebalanceSafeCommits: Boolean +) extends MessagingService { + override def makeConsumer[K, V](groupId: String)(implicit kSerde: Serde[K], vSerde: Serde[V]): Task[Consumer[K, V]] = + ZIO.succeed( + new ZKafkaConsumerImpl[K, V]( + bootstrapServers, + groupId, + kSerde, + vSerde, + autoCreateTopics, + maxPollRecords, + maxPollInterval, + pollTimeout, + rebalanceSafeCommits + ) + ) + + override def makeProducer[K, V]()(implicit kSerde: Serde[K], vSerde: Serde[V]): Task[Producer[K, V]] = + ZIO.succeed(new ZKafkaProducerImpl[K, V](bootstrapServers, kSerde, vSerde)) +} + +object ZKafkaMessagingServiceImpl { + val layer: URLayer[MessagingServiceConfig, MessagingService] = + ZLayer.fromZIO { + for { + config <- ZIO.service[MessagingServiceConfig] + kafkaConfig <- config.kafka match + case Some(cfg) => ZIO.succeed(cfg) + case None => ZIO.dieMessage("Kafka config is undefined") + } yield new ZKafkaMessagingServiceImpl( + kafkaConfig.bootstrapServers.split(',').toList, + kafkaConfig.consumers.autoCreateTopics, + kafkaConfig.consumers.maxPollRecords, + kafkaConfig.consumers.maxPollInterval, + kafkaConfig.consumers.pollTimeout, + kafkaConfig.consumers.rebalanceSafeCommits + ) + } +} + +class ZKafkaConsumerImpl[K, V]( + bootstrapServers: List[String], + groupId: String, + kSerde: Serde[K], + vSerde: Serde[V], + autoCreateTopics: Boolean, + maxPollRecords: Int, + maxPollInterval: Duration, + pollTimeout: Duration, + rebalanceSafeCommits: Boolean +) extends Consumer[K, V] { + private val zkConsumer = ZLayer.scoped( + ZKConsumer.make( + ZKConsumerSettings(bootstrapServers) + .withProperty(ConsumerConfig.ALLOW_AUTO_CREATE_TOPICS_CONFIG, autoCreateTopics.toString) + .withGroupId(groupId) + // 'max.poll.records' default is 500. This is a Kafka property. + .withMaxPollRecords(maxPollRecords) + // 'max.poll.interval.ms' default is 5 minutes. This is a Kafka property. + .withMaxPollInterval(maxPollInterval) // Should be max.poll.records x 'max processing time per record' + // 'pollTimeout' default is 50 millis. This is a ZIO Kafka property. + .withPollTimeout(pollTimeout) + // .withOffsetRetrieval(OffsetRetrieval.Auto(AutoOffsetStrategy.Earliest)) + .withRebalanceSafeCommits(rebalanceSafeCommits) + // .withMaxRebalanceDuration(30.seconds) + ) + ) + + private val zkKeyDeserializer = new ZKDeserializer[Any, K] { + override def deserialize(topic: String, headers: Headers, data: Array[Byte]): RIO[Any, K] = + ZIO.succeed(kSerde.deserialize(data)) + } + + private val zkValueDeserializer = new ZKDeserializer[Any, V] { + override def deserialize(topic: String, headers: Headers, data: Array[Byte]): RIO[Any, V] = + ZIO.succeed(vSerde.deserialize(data)) + } + + override def consume[HR](topic: String, topics: String*)(handler: Message[K, V] => URIO[HR, Unit]): RIO[HR, Unit] = + ZKConsumer + .plainStream(ZKSubscription.topics(topic, topics*), zkKeyDeserializer, zkValueDeserializer) + .provideSomeLayer(zkConsumer) + .mapZIO(record => + handler(Message(record.key, record.value, record.offset.offset, record.timestamp)).as(record.offset) + ) + .aggregateAsync(ZKConsumer.offsetBatches) + .mapZIO(_.commit) + .runDrain +} + +class ZKafkaProducerImpl[K, V](bootstrapServers: List[String], kSerde: Serde[K], vSerde: Serde[V]) + extends Producer[K, V] { + private val zkProducer = ZLayer.scoped( + ZKProducer.make( + ZKProducerSettings(bootstrapServers) + ) + ) + + private val zkKeySerializer = new ZKSerializer[Any, K] { + override def serialize(topic: String, headers: Headers, value: K): RIO[Any, Array[Byte]] = + ZIO.succeed(kSerde.serialize(value)) + } + + private val zkValueSerializer = new ZKSerializer[Any, V] { + override def serialize(topic: String, headers: Headers, value: V): RIO[Any, Array[Byte]] = + ZIO.succeed(vSerde.serialize(value)) + } + + override def produce(topic: String, key: K, value: V): Task[Unit] = + ZKProducer + .produce(topic, key, value, zkKeySerializer, zkValueSerializer) + .tap(metadata => ZIO.logInfo(s"Message produced: ${metadata.offset()}")) + .map(_ => ()) + .provideSome(zkProducer) + +} diff --git a/tests/integration-tests/README.md b/tests/integration-tests/README.md index 2fef57bf71..4b0e925bcd 100644 --- a/tests/integration-tests/README.md +++ b/tests/integration-tests/README.md @@ -116,10 +116,6 @@ The configuration files are divided into the following sections: * `agents`: contains the configuration for the agents (ICA) that will be started. By default, all agents will be destroyed after the test run is finished. * `roles`: contains the configuration for the roles (Issuer, Holder, Verifier, Admin). A role can be assigned to one or more agents that we set in `agents` section or already running locally or in the cloud. -> You could keep services and agents running for debugging purposes -> by specifying `keep_running = true` for the service or agent -> in the configuration file and setting `TESTCONTAINERS_RYUK_DISABLED` variable to `true`. - Please, check [test/resources/configs/basic.conf](./src/test/resources/configs/basic.conf) for a quick example of a basic configuration. You could explore the `configs` directory for more complex examples. diff --git a/tests/integration-tests/build.gradle.kts b/tests/integration-tests/build.gradle.kts index 3efb0d40a8..4e2020e689 100644 --- a/tests/integration-tests/build.gradle.kts +++ b/tests/integration-tests/build.gradle.kts @@ -33,7 +33,7 @@ dependencies { testImplementation("io.ktor:ktor-server-netty:2.3.0") testImplementation("io.ktor:ktor-client-apache:2.3.0") // RestAPI client - testImplementation("org.hyperledger.identus:cloud-agent-client-kotlin:1.39.1-e8ad592") + testImplementation("org.hyperledger.identus:cloud-agent-client-kotlin:1.39.1-19ab426") // Test helpers library testImplementation("io.iohk.atala:atala-automation:0.4.0") // Hoplite for configuration diff --git a/tests/integration-tests/src/test/kotlin/config/services/Agent.kt b/tests/integration-tests/src/test/kotlin/config/services/Agent.kt index f4d7cc0962..a4e97a603d 100644 --- a/tests/integration-tests/src/test/kotlin/config/services/Agent.kt +++ b/tests/integration-tests/src/test/kotlin/config/services/Agent.kt @@ -16,7 +16,6 @@ data class Agent( @ConfigAlias("prism_node") val prismNode: VerifiableDataRegistry?, val keycloak: Keycloak?, val vault: Vault?, - @ConfigAlias("keep_running") override val keepRunning: Boolean = false, ) : ServiceBase() { override val logServices = listOf("identus-cloud-agent") diff --git a/tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt b/tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt index d73a8814b5..86027fe3ad 100644 --- a/tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt +++ b/tests/integration-tests/src/test/kotlin/config/services/Keycloak.kt @@ -17,7 +17,6 @@ data class Keycloak( val realm: String = "atala-demo", @ConfigAlias("client_id") val clientId: String = "cloud-agent", @ConfigAlias("client_secret") val clientSecret: String = "cloud-agent-secret", - @ConfigAlias("keep_running") override val keepRunning: Boolean = false, @ConfigAlias("compose_file") val keycloakComposeFile: String = "src/test/resources/containers/keycloak.yml", @ConfigAlias("logger_name") val loggerName: String = "keycloak", @ConfigAlias("extra_envs") val extraEnvs: Map = emptyMap(), diff --git a/tests/integration-tests/src/test/kotlin/config/services/ServiceBase.kt b/tests/integration-tests/src/test/kotlin/config/services/ServiceBase.kt index 8c598b61d6..9c2483084a 100644 --- a/tests/integration-tests/src/test/kotlin/config/services/ServiceBase.kt +++ b/tests/integration-tests/src/test/kotlin/config/services/ServiceBase.kt @@ -15,7 +15,6 @@ abstract class ServiceBase : Startable { } abstract val container: ComposeContainer - abstract val keepRunning: Boolean open val logServices: List = emptyList() private val logWriters: MutableList = mutableListOf() @@ -41,8 +40,6 @@ abstract class ServiceBase : Startable { logWriters.forEach { it.close() } - if (!keepRunning) { - container.stop() - } + container.stop() } } diff --git a/tests/integration-tests/src/test/kotlin/config/services/Vault.kt b/tests/integration-tests/src/test/kotlin/config/services/Vault.kt index 85f1a02b27..a14a44620b 100644 --- a/tests/integration-tests/src/test/kotlin/config/services/Vault.kt +++ b/tests/integration-tests/src/test/kotlin/config/services/Vault.kt @@ -14,7 +14,6 @@ import java.io.File data class Vault( @ConfigAlias("http_port") val httpPort: Int, @ConfigAlias("vault_auth_type") val authType: VaultAuthType = VaultAuthType.APP_ROLE, - @ConfigAlias("keep_running") override val keepRunning: Boolean = false, ) : ServiceBase() { private val logger = Logger.get() override val logServices: List = listOf("vault") diff --git a/tests/integration-tests/src/test/kotlin/config/services/VerifiableDataRegistry.kt b/tests/integration-tests/src/test/kotlin/config/services/VerifiableDataRegistry.kt index 2997f567cc..f4fbcdba66 100644 --- a/tests/integration-tests/src/test/kotlin/config/services/VerifiableDataRegistry.kt +++ b/tests/integration-tests/src/test/kotlin/config/services/VerifiableDataRegistry.kt @@ -8,7 +8,6 @@ import java.io.File data class VerifiableDataRegistry( @ConfigAlias("http_port") val httpPort: Int, val version: String, - @ConfigAlias("keep_running") override val keepRunning: Boolean = false, ) : ServiceBase() { override val logServices: List = listOf("prism-node") private val vdrComposeFile = "src/test/resources/containers/vdr.yml" diff --git a/tests/integration-tests/src/test/kotlin/steps/connectionless/ConnectionLessSteps.kt b/tests/integration-tests/src/test/kotlin/steps/connectionless/ConnectionLessSteps.kt new file mode 100644 index 0000000000..627281d15a --- /dev/null +++ b/tests/integration-tests/src/test/kotlin/steps/connectionless/ConnectionLessSteps.kt @@ -0,0 +1,81 @@ +package steps.connectionless + +import interactions.Post +import interactions.body +import io.cucumber.java.en.* +import io.iohk.atala.automation.extensions.get +import io.iohk.atala.automation.serenity.ensure.Ensure +import net.serenitybdd.rest.SerenityRest +import net.serenitybdd.screenplay.Actor +import org.apache.http.HttpStatus.SC_CREATED +import org.apache.http.HttpStatus.SC_OK +import org.hyperledger.identus.client.models.* + +class ConnectionLessSteps { + + @When("{actor} creates a {string} credential offer invitation with {string} form DID") + fun inviterGeneratesACredentialOfferInvitation(issuer: Actor, credentialFormat: String, didForm: String) { + val claims = linkedMapOf( + "firstName" to "Automation", + "lastName" to "Execution", + "email" to "email@example.com", + ) + val did: String = if (didForm == "short") { + issuer.recall("shortFormDid") + } else { + issuer.recall("longFormDid") + } + val credentialOfferRequest = CreateIssueCredentialRecordRequest( + claims = claims, + issuingDID = did, + validityPeriod = 3600.0, + credentialFormat = credentialFormat, + automaticIssuance = false, + goalCode = "issue-vc", + goal = "To issue a Faber College Graduate credential", + ) + + issuer.attemptsTo( + Post.to("/issue-credentials/credential-offers/invitation").body(credentialOfferRequest), + ) + + val credentialRecord = SerenityRest.lastResponse().get() + + issuer.attemptsTo( + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED), + Ensure.that(credentialRecord.goalCode!!).isEqualTo("issue-vc"), + Ensure.that(credentialRecord.protocolState).isEqualTo(IssueCredentialRecord.ProtocolState.INVITATION_GENERATED), + Ensure.that(credentialRecord.role).isEqualTo(IssueCredentialRecord.Role.ISSUER), + ) + + // Acme remembers connection to send it out of band to Bob + issuer.remember("credentialRecord", credentialRecord) + issuer.remember("thid", credentialRecord.thid) + } + + @And("{actor} accepts the credential offer invitation from {actor}") + fun holderAcceptsCredentialOfferInvitation(holder: Actor, issuer: Actor) { + // Bob accepts connection using achieved out-of-band invitation + val credentialOfferInvitationRecord = issuer.recall("credentialRecord") + holder.attemptsTo( + Post.to("/issue-credentials/credential-offers/accept-invitation") + .with { + it.body( + AcceptCredentialOfferInvitation( + credentialOfferInvitationRecord.invitation?.invitationUrl?.split("=")?.getOrNull(1) + ?: throw IllegalStateException("Invalid invitation URL format"), + ), + ) + }, + ) + val holderIssueCredentialRecord = SerenityRest.lastResponse().get() + + holder.attemptsTo( + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), + Ensure.that(holderIssueCredentialRecord.protocolState).isEqualTo(IssueCredentialRecord.ProtocolState.OFFER_RECEIVED), + Ensure.that(holderIssueCredentialRecord.role).isEqualTo(IssueCredentialRecord.Role.HOLDER), + ) + holder.remember("recordId", holderIssueCredentialRecord.recordId) + holder.remember("thid", holderIssueCredentialRecord.thid) + } +} diff --git a/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt b/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt index b5026a7163..a25abc6ade 100644 --- a/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/credentials/JwtCredentialSteps.kt @@ -35,7 +35,7 @@ class JwtCredentialSteps { } val credentialOfferRequest = CreateIssueCredentialRecordRequest( - schemaId = schemaId, + schemaId = schemaId?.let { listOf(it) }, claims = claims, issuingDID = did, connectionId = issuer.recall("connection-with-${holder.name}").connectionId, diff --git a/tests/integration-tests/src/test/kotlin/steps/oid4vci/IssueCredentialSteps.kt b/tests/integration-tests/src/test/kotlin/steps/oid4vci/IssueCredentialSteps.kt index 3cd1873033..6a2e906361 100644 --- a/tests/integration-tests/src/test/kotlin/steps/oid4vci/IssueCredentialSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/oid4vci/IssueCredentialSteps.kt @@ -5,6 +5,7 @@ import com.nimbusds.jose.JWSAlgorithm import com.nimbusds.jose.jwk.JWK import eu.europa.ec.eudi.openid4vci.* import interactions.Post +import interactions.body import io.cucumber.java.en.Then import io.cucumber.java.en.When import io.iohk.atala.automation.extensions.get @@ -40,16 +41,13 @@ class IssueCredentialSteps { issuer.recall("longFormDid") } issuer.attemptsTo( - Post.to("/oid4vci/issuers/${credentialIssuer.id}/credential-offers") - .with { - it.body( - CredentialOfferRequest( - credentialConfigurationId = configurationId, - issuingDID = did, - claims = claims, - ), - ) - }, + Post.to("/oid4vci/issuers/${credentialIssuer.id}/credential-offers").body( + CredentialOfferRequest( + credentialConfigurationId = configurationId, + issuingDID = did, + claims = claims, + ), + ), Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED), ) val offerUri = SerenityRest.lastResponse().get().credentialOffer diff --git a/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageCredentialConfigSteps.kt b/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageCredentialConfigSteps.kt index 470babb703..8a53c311f9 100644 --- a/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageCredentialConfigSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageCredentialConfigSteps.kt @@ -1,20 +1,37 @@ package steps.oid4vci +import com.google.gson.JsonObject import common.CredentialSchema -import interactions.* -import io.cucumber.java.en.* +import interactions.Delete +import interactions.Get +import interactions.Post +import interactions.body +import io.cucumber.java.en.Given +import io.cucumber.java.en.Then +import io.cucumber.java.en.When import io.iohk.atala.automation.extensions.get import io.iohk.atala.automation.serenity.ensure.Ensure import net.serenitybdd.rest.SerenityRest import net.serenitybdd.screenplay.Actor import org.apache.http.HttpStatus -import org.hyperledger.identus.client.models.* +import org.apache.http.HttpStatus.SC_OK +import org.hyperledger.identus.client.models.CreateCredentialConfigurationRequest +import org.hyperledger.identus.client.models.CredentialFormat +import org.hyperledger.identus.client.models.CredentialIssuer +import org.hyperledger.identus.client.models.IssuerMetadata +import java.util.UUID class ManageCredentialConfigSteps { @Given("{actor} has {string} credential configuration created from {}") fun issuerHasExistingCredentialConfig(issuer: Actor, configurationId: String, schema: CredentialSchema) { ManageIssuerSteps().issuerHasExistingCredentialIssuer(issuer) - issuerCreateCredentialConfiguration(issuer, schema, configurationId) + val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") + issuer.attemptsTo( + Get("/oid4vci/issuers/${credentialIssuer.id}/credential-configurations/$configurationId"), + ) + if (SerenityRest.lastResponse().statusCode != SC_OK) { + issuerCreateCredentialConfiguration(issuer, schema, configurationId) + } } @When("{actor} uses {} to create a credential configuration {string}") @@ -22,17 +39,15 @@ class ManageCredentialConfigSteps { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") val schemaGuid = issuer.recall(schema.name) val baseUrl = issuer.recall("baseUrl") + issuer.attemptsTo( - Post.to("/oid4vci/issuers/${credentialIssuer.id}/credential-configurations") - .with { - it.body( - CreateCredentialConfigurationRequest( - configurationId = configurationId, - format = CredentialFormat.JWT_VC_JSON, - schemaId = "$baseUrl/schema-registry/schemas/$schemaGuid/schema", - ), - ) - }, + Post.to("/oid4vci/issuers/${credentialIssuer.id}/credential-configurations").body( + CreateCredentialConfigurationRequest( + configurationId = configurationId, + format = CredentialFormat.JWT_VC_JSON, + schemaId = "$baseUrl/schema-registry/schemas/$schemaGuid/schema", + ), + ), Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED), ) } @@ -42,7 +57,75 @@ class ManageCredentialConfigSteps { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") issuer.attemptsTo( Delete("/oid4vci/issuers/${credentialIssuer.id}/credential-configurations/$configurationId"), - Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK), + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), + ) + } + + @When("{actor} deletes a non existent {} credential configuration") + fun issuerDeletesANonExistentCredentialConfiguration(issuer: Actor, configurationId: String) { + val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") + issuer.attemptsTo( + Delete("/oid4vci/issuers/${credentialIssuer.id}/credential-configurations/$configurationId"), + ) + } + + @When("{actor} creates a new credential configuration request") + fun issuerCreatesANewConfigurationRequest(issuer: Actor) { + val credentialConfiguration = JsonObject() + issuer.remember("credentialConfiguration", credentialConfiguration) + } + + @When("{actor} uses {} issuer id for credential configuration") + fun issuerUsesIssuerId(issuer: Actor, issuerId: String) { + if (issuerId == "existing") { + val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") + issuer.remember("credentialConfigurationId", credentialIssuer.id) + } else if (issuerId == "wrong") { + issuer.remember("credentialConfigurationId", UUID.randomUUID().toString()) + } + } + + @When("{actor} adds '{}' configuration id for credential configuration request") + fun issuerAddsConfigurationIdToCredentialConfigurationRequest(issuer: Actor, configurationId: String) { + val credentialIssuer = issuer.recall("credentialConfiguration") + val configurationIdProperty = if (configurationId == "null") { + null + } else { + configurationId + } + credentialIssuer.addProperty("configurationId", configurationIdProperty) + } + + @When("{actor} adds '{}' format for credential configuration request") + fun issuerAddsFormatToCredentialConfigurationRequest(issuer: Actor, format: String) { + val credentialIssuer = issuer.recall("credentialConfiguration") + val formatProperty = if (format == "null") { + null + } else { + format + } + credentialIssuer.addProperty("format", formatProperty) + } + + @When("{actor} adds '{}' schemaId for credential configuration request") + fun issuerAddsSchemaIdToCredentialConfigurationRequest(issuer: Actor, schema: String) { + val credentialIssuer = issuer.recall("credentialConfiguration") + val schemaIdProperty = if (schema == "null") { + null + } else { + val baseUrl = issuer.recall("baseUrl") + val schemaGuid = issuer.recall(schema) + "$baseUrl/schema-registry/schemas/$schemaGuid/schema" + } + credentialIssuer.addProperty("schemaId", schemaIdProperty) + } + + @When("{actor} sends the create a credential configuration request") + fun issuerSendsTheCredentialConfigurationRequest(issuer: Actor) { + val credentialConfiguration = issuer.recall("credentialConfiguration") + val credentialIssuerId = issuer.recall("credentialConfigurationId").toString() + issuer.attemptsTo( + Post.to("/oid4vci/issuers/$credentialIssuerId/credential-configurations").body(credentialConfiguration), ) } @@ -51,7 +134,7 @@ class ManageCredentialConfigSteps { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") issuer.attemptsTo( Get("/oid4vci/issuers/${credentialIssuer.id}/.well-known/openid-credential-issuer"), - Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK), + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), ) val metadata = SerenityRest.lastResponse().get() val credConfig = metadata.credentialConfigurationsSupported[configurationId]!! @@ -65,11 +148,19 @@ class ManageCredentialConfigSteps { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") issuer.attemptsTo( Get("/oid4vci/issuers/${credentialIssuer.id}/.well-known/openid-credential-issuer"), - Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK), + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), ) val metadata = SerenityRest.lastResponse().get() issuer.attemptsTo( Ensure.that(metadata.credentialConfigurationsSupported.keys).doesNotContain(configurationId), ) } + + @Then("{actor} should see that create credential configuration has failed with '{}' status code and '{}' detail") + fun issuerShouldSeeCredentialConfigurationRequestHasFailed(issuer: Actor, statusCode: Int, errorDetail: String) { + issuer.attemptsTo( + Ensure.thatTheLastResponse().statusCode().isEqualTo(statusCode), + Ensure.that(SerenityRest.lastResponse().body.asString()).contains(errorDetail), + ) + } } diff --git a/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageIssuerSteps.kt b/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageIssuerSteps.kt index 7db69f0b41..e78408078f 100644 --- a/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageIssuerSteps.kt +++ b/tests/integration-tests/src/test/kotlin/steps/oid4vci/ManageIssuerSteps.kt @@ -1,7 +1,15 @@ package steps.oid4vci -import interactions.* -import io.cucumber.java.en.* +import com.google.gson.GsonBuilder +import com.google.gson.JsonObject +import interactions.Delete +import interactions.Get +import interactions.Patch +import interactions.Post +import interactions.body +import io.cucumber.java.en.Given +import io.cucumber.java.en.Then +import io.cucumber.java.en.When import io.iohk.atala.automation.extensions.get import io.iohk.atala.automation.serenity.ensure.Ensure import net.serenitybdd.rest.SerenityRest @@ -9,16 +17,26 @@ import net.serenitybdd.screenplay.Actor import org.apache.http.HttpStatus import org.apache.http.HttpStatus.SC_CREATED import org.apache.http.HttpStatus.SC_OK -import org.hyperledger.identus.client.models.* +import org.hyperledger.identus.client.models.AuthorizationServer +import org.hyperledger.identus.client.models.CreateCredentialIssuerRequest +import org.hyperledger.identus.client.models.CredentialIssuer +import org.hyperledger.identus.client.models.CredentialIssuerPage +import org.hyperledger.identus.client.models.IssuerMetadata +import org.hyperledger.identus.client.models.PatchAuthorizationServer +import org.hyperledger.identus.client.models.PatchCredentialIssuerRequest class ManageIssuerSteps { - private val UPDATE_AUTH_SERVER_URL = "http://example.com" - private val UPDATE_AUTH_SERVER_CLIENT_ID = "foo" - private val UPDATE_AUTH_SERVER_CLIENT_SECRET = "bar" + companion object { + private const val UPDATE_AUTH_SERVER_URL = "http://example.com" + private const val UPDATE_AUTH_SERVER_CLIENT_ID = "foo" + private const val UPDATE_AUTH_SERVER_CLIENT_SECRET = "bar" + } @Given("{actor} has an existing oid4vci issuer") fun issuerHasExistingCredentialIssuer(issuer: Actor) { - issuerCreateCredentialIssuer(issuer) + if (!issuer.recallAll().containsKey("oid4vciCredentialIssuer")) { + issuerCreateCredentialIssuer(issuer) + } } @When("{actor} creates an oid4vci issuer") @@ -69,19 +87,29 @@ class ManageIssuerSteps { fun issuerUpdateCredentialIssuer(issuer: Actor) { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") issuer.attemptsTo( - Patch.to("/oid4vci/issuers/${credentialIssuer.id}") - .with { - it.body( - PatchCredentialIssuerRequest( - authorizationServer = PatchAuthorizationServer( - url = UPDATE_AUTH_SERVER_URL, - clientId = UPDATE_AUTH_SERVER_CLIENT_ID, - clientSecret = UPDATE_AUTH_SERVER_CLIENT_SECRET, - ), - ), - ) - }, - Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK), + Patch.to("/oid4vci/issuers/${credentialIssuer.id}").body( + PatchCredentialIssuerRequest( + authorizationServer = PatchAuthorizationServer( + url = UPDATE_AUTH_SERVER_URL, + clientId = UPDATE_AUTH_SERVER_CLIENT_ID, + clientSecret = UPDATE_AUTH_SERVER_CLIENT_SECRET, + ), + ), + ), + Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK), + ) + } + + @When("{actor} tries to update the oid4vci issuer '{}' property using '{}' value") + fun issuerTriesToUpdateTheOID4VCIIssuer(issuer: Actor, property: String, value: String) { + val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") + val body = JsonObject() + val propertyValue = if (value == "null") { null } else { value } + body.addProperty(property, propertyValue) + + val gson = GsonBuilder().serializeNulls().create() + issuer.attemptsTo( + Patch.to("/oid4vci/issuers/${credentialIssuer.id}").body(gson.toJson(body)), ) } @@ -94,6 +122,60 @@ class ManageIssuerSteps { ) } + @When("{actor} tries to create oid4vci issuer with '{}', '{}', '{}' and '{}'") + fun issuerTriesToCreateOIDCIssuer( + issuer: Actor, + id: String, + url: String, + clientId: String, + clientSecret: String, + ) { + val idProperty = if (id == "null") { + null + } else { + id + } + val urlProperty = if (url == "null") { + null + } else { + url + } + val clientIdProperty = if (clientId == "null") { + null + } else { + clientId + } + val clientSecretProperty = if (clientSecret == "null") { + null + } else { + clientSecret + } + + val body = JsonObject() + val authorizationServer = JsonObject() + + body.addProperty("id", idProperty) + body.add("authorizationServer", authorizationServer) + + authorizationServer.addProperty("url", urlProperty) + authorizationServer.addProperty("clientId", clientIdProperty) + authorizationServer.addProperty("clientSecret", clientSecretProperty) + + val gson = GsonBuilder().serializeNulls().create() + issuer.attemptsTo( + Post.to("/oid4vci/issuers").body(gson.toJson(body)), + ) + } + + @Then("{actor} should see the oid4vci '{}' http status response with '{}' detail") + fun issuerShouldSeeTheOIDC4VCIError(issuer: Actor, httpStatus: Int, errorDetail: String) { + SerenityRest.lastResponse().body.prettyPrint() + issuer.attemptsTo( + Ensure.that(SerenityRest.lastResponse().statusCode).isEqualTo(httpStatus), + Ensure.that(SerenityRest.lastResponse().body.asString()).contains(errorDetail), + ) + } + @Then("{actor} sees the oid4vci issuer updated with new values") fun issuerSeesUpdatedCredentialIssuer(issuer: Actor) { val credentialIssuer = issuer.recall("oid4vciCredentialIssuer") @@ -143,4 +225,11 @@ class ManageIssuerSteps { Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_NOT_FOUND), ) } + + @Then("{actor} should see the update oid4vci issuer returned '{}' http status") + fun issuerShouldSeeTheUpdateOID4VCIIssuerReturnedHttpStatus(issuer: Actor, statusCode: Int) { + issuer.attemptsTo( + Ensure.thatTheLastResponse().statusCode().isEqualTo(statusCode), + ) + } } diff --git a/tests/integration-tests/src/test/resources/containers/agent.yml b/tests/integration-tests/src/test/resources/containers/agent.yml index 5d3048eea3..74bf287ada 100644 --- a/tests/integration-tests/src/test/resources/containers/agent.yml +++ b/tests/integration-tests/src/test/resources/containers/agent.yml @@ -42,6 +42,8 @@ services: REST_SERVICE_URL: POLLUX_STATUS_LIST_REGISTRY_PUBLIC_URL: API_KEY_ENABLED: + STATUS_LIST_SYNC_TRIGGER_RECURRENCE_DELAY: 5 seconds + DID_STATE_SYNC_TRIGGER_RECURRENCE_DELAY: 5 seconds # Secret storage configuration SECRET_STORAGE_BACKEND: VAULT_ADDR: "http://host.docker.internal:${VAULT_HTTP_PORT}" @@ -52,9 +54,13 @@ services: KEYCLOAK_CLIENT_ID: KEYCLOAK_CLIENT_SECRET: KEYCLOAK_UMA_AUTO_UPGRADE_RPT: true # no configurable at the moment + # Kafka Messaging Service + DEFAULT_KAFKA_ENABLED: true depends_on: postgres: condition: service_healthy + init-kafka: + condition: service_healthy ports: - "${AGENT_DIDCOMM_PORT}:${AGENT_DIDCOMM_PORT}" - "${AGENT_HTTP_PORT}:${AGENT_HTTP_PORT}" @@ -72,3 +78,91 @@ services: # Extra hosts for Linux networking extra_hosts: - "host.docker.internal:host-gateway" + zookeeper: + image: confluentinc/cp-zookeeper:latest + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + # ports: + # - 22181:2181 + + kafka: + image: confluentinc/cp-kafka:latest + depends_on: + - zookeeper + # ports: + # - 29092:29092 + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: false + healthcheck: + test: + [ + "CMD", + "kafka-topics", + "--list", + "--bootstrap-server", + "localhost:9092", + ] + interval: 5s + timeout: 10s + retries: 5 + + init-kafka: + image: confluentinc/cp-kafka:latest + depends_on: + kafka: + condition: service_healthy + entrypoint: ["/bin/sh", "-c"] + command: | + " + # blocks until kafka is reachable + kafka-topics --bootstrap-server kafka:9092 --list + echo -e 'Creating kafka topics' + + # Connect + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-1 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-2 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-3 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-retry-4 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic connect-DLQ --replication-factor 1 --partitions 1 + + # Issue + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-1 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-2 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-3 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-retry-4 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic issue-DLQ --replication-factor 1 --partitions 1 + + # Present + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-1 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-2 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-3 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-retry-4 --replication-factor 1 --partitions 5 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic present-DLQ --replication-factor 1 --partitions 1 + + # DID Publication State Sync + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-did-state --replication-factor 1 --partitions 5 + + # Status List Sync + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic sync-status-list --replication-factor 1 --partitions 5 + + tail -f /dev/null + " + healthcheck: + test: + [ + "CMD-SHELL", + "kafka-topics --bootstrap-server kafka:9092 --list | grep -q 'sync-status-list'", + ] + interval: 5s + timeout: 10s + retries: 5 diff --git a/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature b/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature index 2e9689f772..79b541c1f6 100644 --- a/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature +++ b/tests/integration-tests/src/test/resources/features/credential/jwt/issuance.feature @@ -1,6 +1,7 @@ @jwt @issuance Feature: Issue JWT credential + Scenario: Issuing jwt credential with published PRISM DID Given Issuer and Holder have an existing connection And Issuer has a published DID for JWT @@ -39,3 +40,12 @@ Feature: Issue JWT credential And Holder accepts jwt credential offer And Issuer issues the credential Then Holder receives the issued credential + + Scenario: Connectionless issuance of JWT credential using OOB invitation + Given Issuer has a published DID for JWT + And Holder has an unpublished DID for JWT + When Issuer creates a "JWT" credential offer invitation with "short" form DID + And Holder accepts the credential offer invitation from Issuer + And Holder accepts jwt credential offer + And Issuer issues the credential + Then Holder receives the issued credential \ No newline at end of file diff --git a/tests/integration-tests/src/test/resources/features/credential/sdjwt/issuance.feature b/tests/integration-tests/src/test/resources/features/credential/sdjwt/issuance.feature index 29af552150..a96c24f04f 100644 --- a/tests/integration-tests/src/test/resources/features/credential/sdjwt/issuance.feature +++ b/tests/integration-tests/src/test/resources/features/credential/sdjwt/issuance.feature @@ -23,6 +23,17 @@ Feature: Issue SD-JWT credential Then Holder receives the issued credential Then Holder checks the sd-jwt credential contents with holder binding + Scenario: Connectionless issuance of sd-jwt credential with holder binding + And Issuer has a published DID for SD_JWT + And Holder has an unpublished DID for SD_JWT + When Issuer creates a "SDJWT" credential offer invitation with "short" form DID + And Holder accepts the credential offer invitation from Issuer + And Holder accepts credential offer for sd-jwt with 'auth-1' key binding + And Issuer issues the credential + Then Holder receives the issued credential + Then Holder checks the sd-jwt credential contents with holder binding + + # Scenario: Issuing sd-jwt with wrong algorithm # Given Issuer and Holder have an existing connection # When Issuer prepares a custom PRISM DID diff --git a/tests/integration-tests/src/test/resources/features/oid4vci/issue_jwt.feature b/tests/integration-tests/src/test/resources/features/oid4vci/issue_jwt.feature index 2f30658ad8..53d010c2c5 100644 --- a/tests/integration-tests/src/test/resources/features/oid4vci/issue_jwt.feature +++ b/tests/integration-tests/src/test/resources/features/oid4vci/issue_jwt.feature @@ -1,20 +1,20 @@ @oid4vci Feature: Issue JWT Credentials using OID4VCI authorization code flow -Background: + Background: Given Issuer has a published DID for JWT And Issuer has published STUDENT_SCHEMA schema And Issuer has an existing oid4vci issuer And Issuer has "StudentProfile" credential configuration created from STUDENT_SCHEMA -Scenario: Issuing credential with published PRISM DID + Scenario: Issuing credential with published PRISM DID When Issuer creates an offer using "StudentProfile" configuration with "short" form DID And Holder receives oid4vci offer from Issuer And Holder resolves oid4vci issuer metadata and login via front-end channel And Holder presents the access token with JWT proof on CredentialEndpoint Then Holder sees credential issued successfully from CredentialEndpoint -Scenario: Issuing credential with unpublished PRISM DID + Scenario: Issuing credential with unpublished PRISM DID When Issuer creates an offer using "StudentProfile" configuration with "long" form DID And Holder receives oid4vci offer from Issuer And Holder resolves oid4vci issuer metadata and login via front-end channel diff --git a/tests/integration-tests/src/test/resources/features/oid4vci/manage_credential_config.feature b/tests/integration-tests/src/test/resources/features/oid4vci/manage_credential_config.feature index 3253069abe..cacdeb6cdb 100644 --- a/tests/integration-tests/src/test/resources/features/oid4vci/manage_credential_config.feature +++ b/tests/integration-tests/src/test/resources/features/oid4vci/manage_credential_config.feature @@ -1,16 +1,39 @@ @oid4vci Feature: Manage OID4VCI credential configuration -Background: + Background: Given Issuer has a published DID for JWT And Issuer has published STUDENT_SCHEMA schema And Issuer has an existing oid4vci issuer -Scenario: Successfully create credential configuration - When Issuer uses STUDENT_SCHEMA to create a credential configuration "StudentProfile" + Scenario: Successfully create credential configuration + Given Issuer has "StudentProfile" credential configuration created from STUDENT_SCHEMA Then Issuer sees the "StudentProfile" configuration on IssuerMetadata endpoint -Scenario: Successfully delete credential configuration + Scenario: Successfully delete credential configuration Given Issuer has "StudentProfile" credential configuration created from STUDENT_SCHEMA When Issuer deletes "StudentProfile" credential configuration Then Issuer cannot see the "StudentProfile" configuration on IssuerMetadata endpoint + + Scenario Outline: Create configuration with expect code + When Issuer creates a new credential configuration request + And Issuer uses issuer id for credential configuration + And Issuer adds '' configuration id for credential configuration request + And Issuer adds '' format for credential configuration request + And Issuer adds '' schemaId for credential configuration request + And Issuer sends the create a credential configuration request + Then Issuer should see that create credential configuration has failed with '' status code and '' detail + Examples: + | issuerId | configurationId | format | schemaId | httpStatus | errorDetail | description | + | wrong | StudentProfile | jwt_vc_json | STUDENT_SCHEMA | 404 | There is no credential issue | wrong issuer id | + | existing | null | jwt_vc_json | STUDENT_SCHEMA | 400 | configurationId | null configuration id | + | existing | StudentProfile | null | STUDENT_SCHEMA | 400 | format | null format | + | existing | StudentProfile | wrong-format | STUDENT_SCHEMA | 400 | format | wrong format | + | existing | StudentProfile | jwt_vc_json | null | 400 | schemaId | null schema | + | existing | StudentProfile | jwt_vc_json | malformed-schema | 400 | | malformed schema | + | existing | StudentProfile | jwt_vc_json | STUDENT_SCHEMA | 201 | | right values | + | existing | StudentProfile | jwt_vc_json | STUDENT_SCHEMA | 409 | Duplicated credential | duplicated configuration id | + + Scenario: Delete non existent credential configuration + When Issuer deletes a non existent "NonExistentProfile" credential configuration + Then Issuer should see that create credential configuration has failed with '404' status code and 'There is no credential configuration' detail diff --git a/tests/integration-tests/src/test/resources/features/oid4vci/manage_issuer.feature b/tests/integration-tests/src/test/resources/features/oid4vci/manage_issuer.feature index d2b6bd4aa6..6259934824 100644 --- a/tests/integration-tests/src/test/resources/features/oid4vci/manage_issuer.feature +++ b/tests/integration-tests/src/test/resources/features/oid4vci/manage_issuer.feature @@ -1,19 +1,40 @@ @oid4vci Feature: Manage OID4VCI credential issuer -Scenario: Successfully create credential issuer + Scenario: Successfully create credential issuer When Issuer creates an oid4vci issuer Then Issuer sees the oid4vci issuer exists on the agent And Issuer sees the oid4vci issuer on IssuerMetadata endpoint -Scenario: Successfully update credential issuer + Scenario: Successfully update credential issuer Given Issuer has an existing oid4vci issuer When Issuer updates the oid4vci issuer Then Issuer sees the oid4vci issuer updated with new values And Issuer sees the oid4vci IssuerMetadata endpoint updated with new values -Scenario: Successfully delete credential issuer + Scenario: Successfully delete credential issuer Given Issuer has an existing oid4vci issuer When Issuer deletes the oid4vci issuer Then Issuer cannot see the oid4vci issuer on the agent And Issuer cannot see the oid4vci IssuerMetadata endpoint + + Scenario Outline: Create issuer with expect response + When Issuer tries to create oid4vci issuer with '', '', '' and '' + Then Issuer should see the oid4vci '' http status response with '' detail + Examples: + | id | url | clientId | clientSecret | httpStatus | errorDetail | description | + | null | null | null | null | 400 | authorizationServer.url | null values | + | null | malformed | id | secret | 400 | Relative URL 'malformed' is not | malformed url | + | null | http://example.com | id | null | 400 | authorizationServer.clientSecret | null client secret | + | null | http://example.com | null | secret | 400 | authorizationServer.clientId | null client id | + | null | null | id | secret | 400 | authorizationServer.url | null url | + | 4048ef76-749d-4296-8c6c-07c8a20733a0 | http://example.com | id | secret | 201 | | right values | + | 4048ef76-749d-4296-8c6c-07c8a20733a0 | http://example.com | id | secret | 500 | | duplicated id | + + Scenario Outline: Update issuer with expect response + Given Issuer has an existing oid4vci issuer + When Issuer tries to update the oid4vci issuer '' property using '' value + Then Issuer should see the oid4vci '' http status response with '' detail + Examples: + | property | value | httpStatus | errorDetail | description | + | url | malformed | 404 | | Invalid URL | diff --git a/tests/performance-tests/agent-performance-tests-k6/.env b/tests/performance-tests/agent-performance-tests-k6/.env index 5d67c0931e..24d8296cbe 100644 --- a/tests/performance-tests/agent-performance-tests-k6/.env +++ b/tests/performance-tests/agent-performance-tests-k6/.env @@ -1,3 +1,3 @@ -AGENT_VERSION=1.39.0-SNAPSHOT -PRISM_NODE_VERSION=2.3.0 +AGENT_VERSION=1.39.1-SNAPSHOT +PRISM_NODE_VERSION=2.5.0 VAULT_DEV_ROOT_TOKEN_ID=root diff --git a/tests/performance-tests/agent-performance-tests-k6/package.json b/tests/performance-tests/agent-performance-tests-k6/package.json index 3286629382..6e41d3a533 100644 --- a/tests/performance-tests/agent-performance-tests-k6/package.json +++ b/tests/performance-tests/agent-performance-tests-k6/package.json @@ -26,7 +26,7 @@ "webpack": "webpack" }, "dependencies": { - "@hyperledger/identus-cloud-agent-client-ts": "^1.39.0-e077cdd", + "@hyperledger/identus-cloud-agent-client-ts": "^1.39.1-19ab426", "uuid": "^9.0.0" } } diff --git a/tests/performance-tests/agent-performance-tests-k6/yarn.lock b/tests/performance-tests/agent-performance-tests-k6/yarn.lock index e743505b63..736d3f9bc0 100644 --- a/tests/performance-tests/agent-performance-tests-k6/yarn.lock +++ b/tests/performance-tests/agent-performance-tests-k6/yarn.lock @@ -993,10 +993,10 @@ resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== -"@hyperledger/identus-cloud-agent-client-ts@^1.39.0-e077cdd": - version "1.39.0-e077cdd" - resolved "https://npm.pkg.github.com/download/@hyperledger/identus-cloud-agent-client-ts/1.39.0-e077cdd/06803b9bd2fa7d63805f83df22250882e84c94dd#06803b9bd2fa7d63805f83df22250882e84c94dd" - integrity sha512-3FSz2WlrykyF5LqnrI+wcbrY33i8CeyBNQmEYZ9fp84JL3qhWvnF92dBIS9qpgAQY/qIg5vHvL7RIRNrAxQfOw== +"@hyperledger/identus-cloud-agent-client-ts@^1.39.1-bbcedb1": + version "1.39.1-bbcedb1" + resolved "https://npm.pkg.github.com/download/@hyperledger/identus-cloud-agent-client-ts/1.39.1-bbcedb1/88aaeabfc4d2d8949e21014c2a5c9297ed055d42#88aaeabfc4d2d8949e21014c2a5c9297ed055d42" + integrity sha512-FjYV4HN5H/LD/v6dOw/vMaqU3f8v1IKzEMtUfj9qmLHVmr1FwxkZWSj6wE27I+sY/0sGAPCF/rPbvO27UWdtYQ== dependencies: es6-promise "^4.2.4" url-parse "^1.4.3"