diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea81f7f8de..ba1fd7f367 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -289,7 +289,7 @@ jobs: rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }} skip-docker-setup: true - name: "Run workspace unit tests" - run: RUST_TEST_THREADS=1 cargo test --workspace --lib --exclude aries-vcx-agent --exclude libvdrtools --exclude wallet_migrator + run: RUST_TEST_THREADS=1 cargo test --workspace --lib --exclude aries-vcx-agent --exclude libvdrtools --exclude wallet_migrator --exclude mediator test-integration-aries-vcx: needs: workflow-setup @@ -402,6 +402,8 @@ jobs: - name: "Run integration tests" run: (cd agents/node/vcxagent-core && AGENCY_URL=http://localhost:8080 npm run test:integration) + + ########################################################################################## ############################ NPMJS PUBLISHING ####################################### diff --git a/.github/workflows/mediator.pr.yml b/.github/workflows/mediator.pr.yml new file mode 100644 index 0000000000..e93633ea6d --- /dev/null +++ b/.github/workflows/mediator.pr.yml @@ -0,0 +1,56 @@ +name: CI mediator + +on: + push: + branches: + - main + pull_request: + branches: + - "**" + paths: + - 'agents/rust/mediator/**' + +env: + DOCKER_BUILDKIT: 1 + MAIN_BRANCH: main + URL_DOCKER_REGISTRY: ghcr.io + DOCKER_IMAGE_AGENCY: ghcr.io/absaoss/vcxagencynode/vcxagency-node:2.6.0 + DOCKER_IMAGE_POOL: ghcr.io/hyperledger/aries-vcx/indy_pool_localhost:1.15.0 + + DOCKER_REPO_LOCAL_VDRPROXY: vdrproxy + + RUST_TOOLCHAIN_VERSON: 1.70.0 + NODE_VERSION: 18.x + +jobs: + + test-integration-mediator: + runs-on: ubuntu-22.04 + services: + mysql: + image: mysql:latest + env: + MYSQL_DATABASE: mediator-persistence.mysql + MYSQL_USER: admin + MYSQL_PASSWORD: github.ci.password.no.prod + MYSQL_ROOT_PASSWORD: github.ci.password.no.prod + ports: + - '3326:3306' + env: + MYSQL_URL: mysql://admin:github.ci.password.no.prod@localhost:3326/mediator-persistence.mysql + steps: + - name: "Git checkout" + uses: actions/checkout@v3 + - name: "Setup rust testing environment" + uses: ./.github/actions/setup-testing-rust + with: + rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }} + skip-docker-setup: true + skip-vdrproxy-setup: true + - name: Install prerequisites (sqlx) + # uses: Swatinem/rust-cache@v2 + run: cargo install sqlx-cli + - name: Setup database + run: DATABASE_URL=${MYSQL_URL} sqlx migrate run --source agents/rust/mediator/mediation/migrations + - name: "Run mediator integration tests" + run: cargo run --bin mediator & sleep 5 && cargo test --verbose --package mediator -- --nocapture; \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 9889f1a9da..8a3009ce89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -622,6 +622,67 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-macros" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdca6a10ecad987bda04e95606ef85a5417dcaac1a78455242d72e031e2b6b62" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -690,9 +751,9 @@ dependencies = [ [[package]] name = "blocking" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94c4ef1f913d78636d78d538eec1f18de81e481f44b1be0a81060090530846e1" +checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" dependencies = [ "async-channel", "async-lock", @@ -778,9 +839,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" +checksum = "12024c4645c97566567129c204f65d5815a8c9aecf30fcbe682b2fe034996d36" dependencies = [ "serde", ] @@ -869,6 +930,39 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "client-tui" +version = "0.1.1" +dependencies = [ + "aries_vcx_core", + "axum", + "client-webapi", + "cursive", + "futures", + "log", + "mediation", + "mediator", + "messages", + "serde_json", + "tokio", +] + +[[package]] +name = "client-webapi" +version = "0.1.1" +dependencies = [ + "aries_vcx_core", + "axum", + "log", + "mediation", + "mediator", + "messages", + "reqwest", + "serde_json", + "tokio", + "tower-http", +] + [[package]] name = "cmake" version = "0.1.50" @@ -987,6 +1081,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.8" @@ -1006,6 +1110,31 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossterm" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +dependencies = [ + "bitflags 1.3.2", + "crossterm_winapi", + "libc", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -1026,6 +1155,48 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "cursive" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5438eb16bdd8af51b31e74764fef5d0a9260227a5ec82ba75c9d11ce46595839" +dependencies = [ + "ahash", + "cfg-if", + "crossbeam-channel", + "crossterm", + "cursive_core", + "lazy_static", + "libc", + "log", + "maplit", + "ncurses", + "signal-hook", + "term_size", + "unicode-segmentation", + "unicode-width", +] + +[[package]] +name = "cursive_core" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4db3b58161228d0dcb45c7968c5e74c3f03ad39e8983e58ad7d57061aa2cd94d" +dependencies = [ + "ahash", + "crossbeam-channel", + "enum-map", + "enumset", + "lazy_static", + "log", + "num", + "owning_ref", + "time 0.3.20", + "unicode-segmentation", + "unicode-width", + "xi-unicode", +] + [[package]] name = "curve25519-dalek" version = "4.1.1" @@ -1507,6 +1678,47 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum-map" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c188012f8542dee7b3996e44dd89461d64aa471b0a7c71a1ae2f595d259e96e5" +dependencies = [ + "enum-map-derive", +] + +[[package]] +name = "enum-map-derive" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04d0b288e3bb1d861c4403c1774a6f7a798781dfc519b3647df2a3dd4ae95f25" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "enumset" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226c0da7462c13fb57e5cc9e0dc8f0635e7d27f276a3a7fd30054647f669007d" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af" +dependencies = [ + "darling 0.20.3", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -1541,25 +1753,14 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "error-chain" version = "0.10.0" @@ -1623,6 +1824,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "fast_qr" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb3b08010bdea9b4ab23deabd626509ee241a793b7da9148d9101c677adcf4d" + [[package]] name = "fastrand" version = "1.9.0" @@ -1662,9 +1869,9 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -2054,6 +2261,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" + [[package]] name = "httparse" version = "1.8.0" @@ -2156,6 +2369,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", + "serde", ] [[package]] @@ -2166,6 +2380,7 @@ checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", "hashbrown 0.14.1", + "serde", ] [[package]] @@ -2397,7 +2612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.17", + "rustix 0.38.19", "windows-sys", ] @@ -2436,9 +2651,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -2487,9 +2702,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -2592,9 +2807,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "local-channel" @@ -2653,6 +2868,18 @@ dependencies = [ "hashbrown 0.14.1", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md-5" version = "0.10.6" @@ -2663,6 +2890,54 @@ dependencies = [ "digest", ] +[[package]] +name = "mediation" +version = "0.2.3" +dependencies = [ + "async-trait", + "axum", + "axum-macros", + "dotenvy", + "env_logger 0.10.0", + "futures", + "log", + "reqwest", + "serde", + "serde_json", + "serde_with", + "sqlx", + "tokio", +] + +[[package]] +name = "mediator" +version = "0.1.1" +dependencies = [ + "anyhow", + "aries-vcx", + "aries_vcx_core", + "async-trait", + "axum", + "axum-macros", + "diddoc_legacy", + "dotenvy", + "env_logger 0.10.0", + "fast_qr", + "futures", + "log", + "mediation", + "messages", + "reqwest", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower-http", + "url", + "uuid 1.4.1", +] + [[package]] name = "memchr" version = "2.6.4" @@ -2870,6 +3145,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ncurses" +version = "5.101.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e2c5d34d72657dc4b638a1c25d40aae81e4f1c699062f72f467237920752032" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "nom" version = "7.1.3" @@ -2886,6 +3172,19 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -2915,6 +3214,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -2936,11 +3244,22 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", "libm", @@ -2956,6 +3275,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.32.1" @@ -3027,6 +3355,15 @@ version = "6.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +[[package]] +name = "owning_ref" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "parking" version = "2.1.1" @@ -3105,6 +3442,26 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-project" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -3245,9 +3602,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -3376,9 +3733,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.6" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" dependencies = [ "aho-corasick", "memchr", @@ -3388,9 +3745,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.9" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" dependencies = [ "aho-corasick", "memchr", @@ -3399,9 +3756,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "56d84fdd47036b038fc80dd333d10b6aab10d5d31f4a366e20014def75328d33" [[package]] name = "reqwest" @@ -3531,14 +3888,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.17" +version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25469e9ae0f3d0047ca8b93fc56843f38e6774f0914a107ff8b41be8be8e0b7" +checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.8", + "linux-raw-sys 0.4.10", "windows-sys", ] @@ -3654,27 +4011,27 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", @@ -3692,6 +4049,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3704,6 +4071,35 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca3b16a3d82c4088f343b7480a93550b3eabe1a358569c2dfe38bbcead07237" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.0.2", + "serde", + "serde_json", + "serde_with_macros", + "time 0.3.20", +] + +[[package]] +name = "serde_with_macros" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e6be15c453eb305019bfa438b1593c731f36a289a7853f7707ee29e870b3b3c" +dependencies = [ + "darling 0.20.3", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "sha1" version = "0.10.6" @@ -3761,6 +4157,27 @@ dependencies = [ "thiserror", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -4072,6 +4489,12 @@ dependencies = [ "url", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -4167,6 +4590,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "synstructure" version = "0.12.6" @@ -4209,10 +4638,20 @@ dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall 0.3.5", - "rustix 0.38.17", + "rustix 0.38.19", "windows-sys", ] +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "termcolor" version = "1.3.0" @@ -4272,6 +4711,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" dependencies = [ "itoa", + "libc", + "num_threads", "serde", "time-core", "time-macros", @@ -4309,9 +4750,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ "backtrace", "bytes", @@ -4400,6 +4841,47 @@ dependencies = [ "serde", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" +dependencies = [ + "bitflags 2.4.0", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -4519,6 +5001,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + [[package]] name = "unicode-xid" version = "0.2.4" @@ -5051,6 +5539,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "xi-unicode" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" + [[package]] name = "zeroize" version = "1.6.0" @@ -5124,11 +5618,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 831240db36..a4994fc3b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,9 @@ members = [ "messages", "shared_vcx", "diddoc_legacy", + "agents/rust/mediator", + "agents/rust/mediator/client-webapi", + "agents/rust/mediator/client-tui", "agents/rust/aries-vcx-agent", "wrappers/vcx-napi-rs", "aries_vcx_core", diff --git a/agents/rust/mediator/.cargo/config.toml b/agents/rust/mediator/.cargo/config.toml new file mode 100644 index 0000000000..5dbf66b1f3 --- /dev/null +++ b/agents/rust/mediator/.cargo/config.toml @@ -0,0 +1,2 @@ +# [build] +# target-dir = "../target" diff --git a/agents/rust/mediator/.gitignore b/agents/rust/mediator/.gitignore new file mode 100644 index 0000000000..9d60d03a8f --- /dev/null +++ b/agents/rust/mediator/.gitignore @@ -0,0 +1,3 @@ +/target +.vscode +.err \ No newline at end of file diff --git a/agents/rust/mediator/Cargo.toml b/agents/rust/mediator/Cargo.toml new file mode 100644 index 0000000000..ddaa147abe --- /dev/null +++ b/agents/rust/mediator/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "mediator" +version = "0.1.1" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["client"] +client = [] + +[dependencies] +anyhow = "1.0.75" +aries-vcx = { path = "../../../aries_vcx" } +aries_vcx_core = { path = "../../../aries_vcx_core", features = [ + "vdrtools_wallet", +] } +async-trait = "0.1.73" +axum = "0.6" +axum-macros = "0.3.8" +diddoc_legacy = { path = "../../../diddoc_legacy" } +dotenvy = "0.15" +env_logger = "0.10.0" +fast_qr = { version = "0.10.2", features = ["svg"] } +futures = "0.3.28" +log = "0.4.20" +messages = { path = "../../../messages" } +reqwest = { version = "0.11.20", features = ["json"] } +serde = "1.0.188" +serde_json = "1.0.106" +sqlx = "0.7" +thiserror = "1.0.49" +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +tower-http = { version = "0.4.4", features = ["catch-panic"] } +url = "2.4.1" +uuid = "1.4.1" +mediation = { path = "./mediation" } + +[dev-dependencies] +reqwest = { version = "0.11.20", features = ["blocking"] } diff --git a/agents/rust/mediator/README.md b/agents/rust/mediator/README.md new file mode 100644 index 0000000000..8dab48f829 --- /dev/null +++ b/agents/rust/mediator/README.md @@ -0,0 +1,80 @@ +# Aries VCX Mediator + +A mediator service for Aries Agents. + +**Status**: Dev + +## Build + +This project depends on `aries-vcx` and is tightly integrated to work with it. +As such we expect this `mediator` module to be in a subdirectory of aries-vcx repo. +You may transplant it, but expect to change the `Cargo.toml` and adjust the dependencies on aries modules manually. + +When ready it's simple to build. + +```bash +# Dev environment build +cargo build +``` + +## Usage + +You can run and test the produced binaries using cargo. + +```bash +cargo run --bin mediator +``` + +```bash +# For testing / demo purposes +cargo run --bin client-tui + +# To also see panic and debug info produced by tui +cargo run --bin client-tui 2> err || cat err +``` + +### Configurable Options + +Currently the mediator reads the following environment variables. + +```yaml +`ENDPOINT_ROOT`: +- **Description**: This is the address at which the mediator will listen for connections. +- **Default**: "127.0.0.1:8005" +- **Usage**: `ENDPOINT_ROOT=127.0.0.1:3000 cargo run` + +`MYSQL_URL`: +- **Description**: MySQL url for the MYSQL database used for mediator persistence. +- **Default**: - +- **Usage**: `MYSQL_URL=mysql://admin:password1235@localhost:3306/mediator-persistence.db` +``` + +## API + +Currently exposed endpoints. + +```yaml +`/register`: +- **Description** : | + Shows an Aries Out Of Band (OOB) invitation which can be used to connect to the mediator using a conformant Aries Agent. + Use `Accept` header with value "application/json" to receive same in json format. + +`/register.json`: +- **Description** : Returns OOB invitation in json format. +``` + +```yaml +`/didcomm`: +- **Description** : | + Endpoint for Aries DIDCOMM communication. + Encrypted Aries messages (envelops) can be passed and received from this endpoint in json serialized format. +``` + +### Client API + +```yaml +`/client/register-using-oob`: +- **Input**: Json body containing OOB invite to connect to. +- **Description** : Attempts to connect to the Aries service defined in the OOB invite using DIDCOMM channel. + +``` diff --git a/agents/rust/mediator/client-tui/Cargo.toml b/agents/rust/mediator/client-tui/Cargo.toml new file mode 100644 index 0000000000..e5f8e3585b --- /dev/null +++ b/agents/rust/mediator/client-tui/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "client-tui" +version = "0.1.1" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aries_vcx_core = { path = "../../../../aries_vcx_core", features = [ + "vdrtools_wallet", +] } +axum = "0.6.20" +client-webapi = { path = "../client-webapi" } +cursive = { version = "0.20.0", features = ["crossterm-backend"] } +futures = "0.3.28" +log = "0.4.20" +mediation = { path = "../mediation" } +mediator = { path = ".." } +messages = { path = "../../../../messages" } +serde_json = "1.0.107" + +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } diff --git a/agents/rust/mediator/client-tui/src/main.rs b/agents/rust/mediator/client-tui/src/main.rs new file mode 100644 index 0000000000..5cba16f032 --- /dev/null +++ b/agents/rust/mediator/client-tui/src/main.rs @@ -0,0 +1,22 @@ +/// Aries Agent TUI +mod tui; +#[tokio::main] +async fn main() { + use mediator::{ + aries_agent::AgentBuilder, + utils::binary_utils::{load_dot_env, setup_logging}, + }; + + load_dot_env(); + setup_logging(); + log::info!("TUI initializing!"); + let agent = AgentBuilder::new_demo_agent().await.unwrap(); + tui::init_tui(agent).await; +} + +// fn main() { +// print!( +// "This is a placeholder binary. Please enable \"client_tui\" feature to to build the \ +// functional client_tui binary." +// ) +// } diff --git a/agents/rust/mediator/client-tui/src/tui.rs b/agents/rust/mediator/client-tui/src/tui.rs new file mode 100644 index 0000000000..59f0a8e1a7 --- /dev/null +++ b/agents/rust/mediator/client-tui/src/tui.rs @@ -0,0 +1,139 @@ +use std::sync::Arc; + +use aries_vcx_core::wallet::base_wallet::BaseWallet; +use axum::{extract::State, Json}; +use client_webapi::http_routes::handle_register; +use cursive::{ + direction::Orientation, + event::Key, + view::{Nameable, SizeConstraint}, + views::{ + Dialog, DummyView, LinearLayout, Panel, ResizedView, ScrollView, SelectView, TextArea, + TextView, + }, + Cursive, CursiveExt, View, +}; +use futures::executor::block_on; +use log::info; +use mediation::storage::MediatorPersistence; +use mediator::aries_agent::Agent; +use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation; + +pub async fn init_tui(agent: Agent) { + let mut cursive = Cursive::new(); + cursive.add_global_callback(Key::Esc, |s| s.quit()); + cursive.set_user_data(Arc::new(agent)); + + let mut main = LinearLayout::horizontal().with_name("main"); + let endpoint_selector = endpoints_ui::(); + main.get_mut().add_child(endpoint_selector); + cursive.add_layer(main); + cursive.run() +} + +pub fn endpoints_ui() -> Panel { + let mut endpoint_selector = SelectView::new(); + // Set available endpoints + endpoint_selector.add_item_str("/client/register"); + endpoint_selector.add_item_str("/client/trustping"); + + endpoint_selector.set_on_submit(|s, endpoint: &str| { + // Match ui generators for available endpoints + let view = match endpoint { + "/client/register" => client_register_ui::(), + "/client/contacts" => contact_selector_ui::(s), + _ => dummy_ui(), + }; + // Replace previously exposed ui + s.find_name::("main").unwrap().remove_child(1); + s.find_name::("main") + .unwrap() + .insert_child(1, view); + }); + + make_standard(endpoint_selector, Orientation::Vertical).title("Select endpoint") +} + +pub fn client_register_ui() -> Panel +{ + let input = TextArea::new().with_name("oob_text_area"); + let input = ResizedView::new( + SizeConstraint::AtLeast(20), + SizeConstraint::AtLeast(5), + input, + ); + let input = Dialog::around(input) + .button("Clear", |s| { + s.find_name::