From 9d7db7cf14d3b3e28b18d4b6efe03164cda3de7a Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:22:01 +0900 Subject: [PATCH 01/12] chore: add ci jobs and format toml --- .cargo/config.toml | 1 + .github/workflows/ci.yml | 80 ++++++++++++++ .github/workflows/rust.yml | 22 ---- .taplo.toml | 10 ++ .typos.toml | 3 + Cargo.lock | 216 ++----------------------------------- Cargo.toml | 41 ++++--- clippy.toml | 1 + rust-toolchain.toml | 12 +++ 9 files changed, 133 insertions(+), 253 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/rust.yml create mode 100644 .taplo.toml create mode 100644 .typos.toml create mode 100644 clippy.toml create mode 100644 rust-toolchain.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1 @@ + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f94565a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +# ensure that the workflow is only triggered once per PR, subsequent pushes to the PR will cancel +# and restart the workflow. See https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + RUST_BACKTRACE: 1 + RUST_TEST_THREADS: 1 + CARGO_TERM_COLOR: always + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install taplo + uses: baptiste0928/cargo-install@v3 + with: + crate: taplo-cli + + - name: Check format + run: | + cargo fmt --all -- --check + cargo clippy --all-targets -- -D warnings + + - name: Check typos + uses: crate-ci/typos@master + + - name: Check toml format + run: taplo validate --colors never --no-schema + + test: + name: test + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: ./packages/hub + + steps: + - uses: actions/checkout@v3 + + - uses: taiki-e/install-action@v2 + with: + tool: nextest + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Run migration tests + run: cargo nextest run + + - name: Run tests + run: cargo nextest run + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: success() || failure() # always run even if the previous step fails + with: + report_paths: '**/target/nextest/default/junit.xml' + + # empty job for branch protection + ci-check: + runs-on: ubuntu-latest + needs: [lint, test] + timeout-minutes: 1 \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index a1ad462..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: tests - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build - run: cargo build --verbose - - name: Run tests default - run: cargo test --verbose - - name: Run tests - run: cargo test diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..d627cf2 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,10 @@ +[formatting] +align_comments = false +allowed_blank_lines = 1 +array_auto_collapse = false +array_auto_expand = false +include = ["*.toml"] +indent_string = " " # 4 spaces +keys = ["dependencies"] +reorder_arrays = true +reorder_keys = true diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..0c80ac3 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,3 @@ +[files] +extend-exclude = [] +ignore-files = true diff --git a/Cargo.lock b/Cargo.lock index 56a1e20..e035460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,9 +132,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85" dependencies = [ "proc-macro2", "quote", @@ -394,7 +394,6 @@ version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ - "jobserver", "libc", ] @@ -465,32 +464,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - -[[package]] -name = "const_format" -version = "0.2.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" -dependencies = [ - "const_format_proc_macros", -] - -[[package]] -name = "const_format_proc_macros" -version = "0.2.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - [[package]] name = "constant_time_eq" version = "0.3.0" @@ -713,15 +686,6 @@ dependencies = [ "const-oid 0.7.1", ] -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" -dependencies = [ - "powerfmt", -] - [[package]] name = "did-key" version = "0.0.15" @@ -1254,19 +1218,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "git2" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" -dependencies = [ - "bitflags 1.3.2", - "libc", - "libgit2-sys", - "log", - "url", -] - [[package]] name = "group" version = "0.10.0" @@ -1579,9 +1530,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown", @@ -1602,12 +1553,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is_debug" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06d198e9919d9822d5f7083ba8530e04de87841eaf21ead9af8f2304efd57c89" - [[package]] name = "itoa" version = "0.4.8" @@ -1620,15 +1565,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "jobserver" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.67" @@ -1736,18 +1672,6 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" -[[package]] -name = "libgit2-sys" -version = "0.14.2+1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" -dependencies = [ - "cc", - "libc", - "libz-sys", - "pkg-config", -] - [[package]] name = "libloading" version = "0.7.4" @@ -1817,18 +1741,6 @@ dependencies = [ "libsecp256k1-core", ] -[[package]] -name = "libz-sys" -version = "1.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1922,7 +1834,6 @@ dependencies = [ "serde_jcs", "serde_json", "sha2 0.10.8", - "shadow-rs", "thiserror", "x25519-dalek", ] @@ -2070,15 +1981,6 @@ dependencies = [ "autocfg", ] -[[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.2" @@ -2225,12 +2127,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "pkg-config" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" - [[package]] name = "poly1305" version = "0.7.2" @@ -2254,12 +2150,6 @@ dependencies = [ "universal-hash", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2789,9 +2679,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.30" +version = "0.9.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" +checksum = "a0623d197252096520c6f2a5e1171ee436e5af99a5d7caa2891e55e61950e6d9" dependencies = [ "indexmap", "itoa 1.0.10", @@ -2858,19 +2748,6 @@ dependencies = [ "keccak", ] -[[package]] -name = "shadow-rs" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427f07ab5f873000cf55324882e12a88c0a7ea7025df4fc1e7e35e688877a583" -dependencies = [ - "const_format", - "git2", - "is_debug", - "time", - "tzdb 0.5.10", -] - [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3086,37 +2963,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "time" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" -dependencies = [ - "deranged", - "itoa 1.0.10", - "libc", - "num_threads", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" -dependencies = [ - "time-core", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -3219,46 +3065,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "tz-rs" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4" -dependencies = [ - "const_fn", -] - -[[package]] -name = "tzdb" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a18ee5bde3433d683d41859650804a5ad89cad17f153a53f1e6a96e0da2d969" -dependencies = [ - "iana-time-zone", - "tz-rs", - "tzdb 0.6.1", -] - -[[package]] -name = "tzdb" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b580f6b365fa89f5767cdb619a55d534d04a4e14c2d7e5b9a31e94598687fb1" -dependencies = [ - "iana-time-zone", - "tz-rs", - "tzdb_data", -] - -[[package]] -name = "tzdb_data" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629555d2921f3f0dc0de98699415a8b2b61dfcd3a0b082a327f7ed748bbb2b76" -dependencies = [ - "tz-rs", -] - [[package]] name = "unicode-bidi" version = "0.3.15" @@ -3298,9 +3104,9 @@ dependencies = [ [[package]] name = "unsafe-libyaml" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" [[package]] name = "untrusted" @@ -3334,12 +3140,6 @@ dependencies = [ "getrandom 0.2.12", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index c7e37d6..32bde80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,17 @@ [package] -name = "nodex-didcomm" -version = "0.1.0" +categories = ["cryptography", "embedded"] edition = "2018" +keywords = ["did", "embedded", "iot", "root-of-trust"] +name = "nodex-didcomm" readme = "README.md" -keywords = ["iot", "embedded", "root-of-trust", "did"] -categories = ["embedded", "cryptography"] +version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-rt = { version = "2.7.0" } +anyhow = "1.0.80" arrayref = { version = "0.3.6" } +async-trait = "0.1.77" chrono = { version = "0.4" } cuid = { version = "1.3.1" } data-encoding = { version = "2.3.2" } @@ -19,34 +20,28 @@ getrandom = { version = "0.2" } hdwallet = { version = "0.3.1" } hex = { version = "0.4.3" } hmac = { version = "0.12.1" } -home-config = { version = "0.6.0", features = ["json", "yaml", "toml"] } +home-config = { version = "0.6.0", features = ["json", "toml", "yaml"] } ibig = { version = "0.3.5" } -libloading = { version = "0.7.4" } -log = { version = "0.4.0" } k256 = { version = "0.10.4", features = [ - "ecdh", - "ecdsa", - "sha256", - "keccak256", - "serde", + "ecdh", + "ecdsa", + "keccak256", + "serde", + "sha256", ] } +libloading = { version = "0.7.4" } +log = { version = "0.4.0" } reqwest = { version = "0.11", features = [ - "json", - "rustls-tls", + "json", + "rustls-tls", ], default-features = false } serde = { version = "1.0.131", features = ["derive"] } serde_jcs = { version = "0.1.0" } serde_json = { version = "1.0.71" } -shadow-rs = "0.21.0" sha2 = { version = "0.10.2" } -x25519-dalek = { version = "1.1.1" } -anyhow = "1.0.80" thiserror = "1.0.57" -async-trait = "0.1.77" - - -[build-dependencies] -shadow-rs = "0.21.0" +x25519-dalek = { version = "1.1.1" } [dev-dependencies] +actix-rt = { version = "2.7.0" } rstest = { version = "0.17.0" } diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ + diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..fe924cc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,12 @@ +[toolchain] +channel = "1.76.0" +components = [ + "cargo", + "clippy", + "rust-analyzer", + "rust-src", + "rustc", + "rustfmt", +] +profile = "minimal" +targets = [] From d7e88698e46f52dc591b79a530e04999dff24f9c Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:24:17 +0900 Subject: [PATCH 02/12] chore: add templates and codeowners --- .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e388a79 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @nodecross/maintainer diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 89a0d467e2d74db9ab48cccb219607a8c8018ccc Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:24:43 +0900 Subject: [PATCH 03/12] chore: apply rustfmt --- src/config/did.rs | 2 +- src/nodex/extension/secure_keystore.rs | 2 +- src/nodex/extension/trng.rs | 2 +- src/nodex/keyring/keypair.rs | 6 +----- src/nodex/mod.rs | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/config/did.rs b/src/config/did.rs index 3117c24..c204cdb 100644 --- a/src/config/did.rs +++ b/src/config/did.rs @@ -1,11 +1,11 @@ use home_config::HomeConfig; use serde::{Deserialize, Serialize}; +use std::error::Error; use std::fs; use std::fs::OpenOptions; use std::io; use std::io::Write; use std::path::Path; -use std::error::Error; use thiserror::Error; #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/src/nodex/extension/secure_keystore.rs b/src/nodex/extension/secure_keystore.rs index 0f5411e..1f07daf 100644 --- a/src/nodex/extension/secure_keystore.rs +++ b/src/nodex/extension/secure_keystore.rs @@ -2,8 +2,8 @@ use std::{ffi::CStr, num::NonZeroU32}; use thiserror::Error; use crate::{ - config::did_config, config::did::{Extension, KeyPair}, + config::did_config, }; #[repr(C)] diff --git a/src/nodex/extension/trng.rs b/src/nodex/extension/trng.rs index 70c0a17..7ce4427 100644 --- a/src/nodex/extension/trng.rs +++ b/src/nodex/extension/trng.rs @@ -1,5 +1,5 @@ use crate::{ - config::{did_config, did::Extension}, + config::{did::Extension, did_config}, nodex::runtime::random::{Random, RandomError}, }; use std::{ffi::CStr, num::NonZeroU32}; diff --git a/src/nodex/keyring/keypair.rs b/src/nodex/keyring/keypair.rs index 4b191db..a5fa1c6 100644 --- a/src/nodex/keyring/keypair.rs +++ b/src/nodex/keyring/keypair.rs @@ -1,10 +1,6 @@ use super::secp256k1::{Secp256k1, Secp256k1Context, Secp256k1Error}; use crate::{ - config::{ - did_config, - SingletonDidConfig, - did::KeyPair - }, + config::{did::KeyPair, did_config, SingletonDidConfig}, nodex::{ extension::secure_keystore::{SecureKeyStore, SecureKeyStoreType}, extension::{secure_keystore::SecureKeyStoreError, trng::Trng}, diff --git a/src/nodex/mod.rs b/src/nodex/mod.rs index f62aab4..f42033d 100644 --- a/src/nodex/mod.rs +++ b/src/nodex/mod.rs @@ -4,4 +4,4 @@ pub mod keyring; pub mod runtime; pub mod schema; pub mod sidetree; -pub mod utils; \ No newline at end of file +pub mod utils; From a630673ba72fe94147e716484f51f3789b94d1b0 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:29:05 +0900 Subject: [PATCH 04/12] fix: add echo steps to ci-check job --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f94565a..5a4d084 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,4 +77,7 @@ jobs: ci-check: runs-on: ubuntu-latest needs: [lint, test] - timeout-minutes: 1 \ No newline at end of file + timeout-minutes: 1 + steps: + - name: Check + run: echo "All checks passed" \ No newline at end of file From 7a0063a1d4347e1437765272e2454754c4ec1a9a Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:29:47 +0900 Subject: [PATCH 05/12] chore: change job name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a4d084..b27e013 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: run: taplo validate --colors never --no-schema test: - name: test + name: Test runs-on: ubuntu-latest timeout-minutes: 10 defaults: From 4f17fb228bdc1f9d533947acf8288ede0075b0a4 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:39:05 +0900 Subject: [PATCH 06/12] fix: fix clippy warinings and fix test job steps --- .github/workflows/ci.yml | 7 ------- src/client/nodex.rs | 6 ++++++ src/config/server.rs | 7 ------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b27e013..0fd89dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,10 +47,6 @@ jobs: name: Test runs-on: ubuntu-latest timeout-minutes: 10 - defaults: - run: - working-directory: ./packages/hub - steps: - uses: actions/checkout@v3 @@ -61,9 +57,6 @@ jobs: - name: Cache dependencies uses: Swatinem/rust-cache@v2 - - name: Run migration tests - run: cargo nextest run - - name: Run tests run: cargo nextest run diff --git a/src/client/nodex.rs b/src/client/nodex.rs index 1b65faf..6288ced 100644 --- a/src/client/nodex.rs +++ b/src/client/nodex.rs @@ -31,6 +31,12 @@ pub struct SideTreeError { pub error: SideTreeErrorBody, } +impl Default for NodeX { + fn default() -> Self { + Self::new() + } +} + impl NodeX { pub fn new() -> Self { let server_config = server_config(); diff --git a/src/config/server.rs b/src/config/server.rs index e3665c0..d3e0297 100644 --- a/src/config/server.rs +++ b/src/config/server.rs @@ -4,7 +4,6 @@ use std::env; pub struct ServerConfig { did_http_endpoint: String, did_attachment_link: String, - hub_http_endpoint: String, } impl Default for ServerConfig { @@ -19,13 +18,10 @@ impl ServerConfig { env::var("NODEX_DID_HTTP_ENDPOINT").unwrap_or("https://did.nodecross.io".to_string()); let link = env::var("NODEX_DID_ATTACHMENT_LINK").unwrap_or("https://did.getnodex.io".to_string()); - let hub_endpoint = - env::var("NODEX_HUB_HTTP_ENDPOINT").unwrap_or("https://hub.nodecross.io".to_string()); ServerConfig { did_http_endpoint: did_endpoint, did_attachment_link: link, - hub_http_endpoint: hub_endpoint, } } pub fn did_http_endpoint(&self) -> String { @@ -34,7 +30,4 @@ impl ServerConfig { pub fn did_attachment_link(&self) -> String { self.did_attachment_link.clone() } - pub fn hub_http_endpoint(&self) -> String { - self.hub_http_endpoint.clone() - } } From 2455c6219f125ad5642aabe157d0ec30fe21079a Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 00:53:48 +0900 Subject: [PATCH 07/12] chore: fix typo and add mise.toml --- .mise.toml | 2 ++ src/nodex/cipher/jws.rs | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .mise.toml diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..99c507f --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +"cargo:typos-cli" = "latest" diff --git a/src/nodex/cipher/jws.rs b/src/nodex/cipher/jws.rs index b1df60e..a44fb41 100644 --- a/src/nodex/cipher/jws.rs +++ b/src/nodex/cipher/jws.rs @@ -67,15 +67,15 @@ impl Jws { } pub fn verify(object: &Value, jws: &str, context: &Secp256k1) -> Result { - let splitted: Vec = jws.to_string().split('.').map(|v| v.to_string()).collect(); + let split: Vec = jws.split('.').map(|v| v.to_string()).collect(); - if splitted.len() != 3 { + if split.len() != 3 { return Err(JwsError::InvalidJws(jws.to_string())); } - let _header = splitted[0].clone(); - let __payload = splitted[1].clone(); - let _signature = splitted[2].clone(); + let _header = split[0].clone(); + let __payload = split[1].clone(); + let _signature = split[2].clone(); // NOTE: header let decoded = From 1197d115e45fa190ea215c7121792c2e9e9cb87a Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 01:13:04 +0900 Subject: [PATCH 08/12] chore: add clippy.toml/rustfmt.toml and remove dbg macro --- clippy.toml | 25 +++++++++++++++++++++++++ src/services/encrypted.rs | 1 - 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clippy.toml b/clippy.toml index 8b13789..f44aa50 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,26 @@ +allow-unwrap-in-tests = true +avoid-breaking-exported-api = false +max-fn-params-bools = 2 + +# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file +max-include-file-size = 1000000 + +# https://rust-lang.github.io/rust-clippy/master/index.html#/type_complexity +type-complexity-threshold = 350 + +# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods +disallowed-macros = [ + 'dbg', + 'std::unimplemented', + 'std::eprint', + 'std::eprintln', + 'std::print', + 'std::println', +] + +# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names +disallowed-names = [] + +# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types +disallowed-types = [] \ No newline at end of file diff --git a/src/services/encrypted.rs b/src/services/encrypted.rs index bcd401e..2ac10b1 100644 --- a/src/services/encrypted.rs +++ b/src/services/encrypted.rs @@ -108,7 +108,6 @@ impl DIDCommEncryptedService { .to(&[to_did]) .body(&body) .map_err(|e| anyhow::anyhow!("Failed to initialize message with error = {:?}", e))?; - dbg!(&message); // NOTE: Has attachment if let Some(value) = metadata { From bcfc5cda61449b7d54aabf76b11bbdb2229e2073 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 01:17:06 +0900 Subject: [PATCH 09/12] chore: Add empty line to ci.yaml and add rustfmt.toml --- .github/workflows/{ci.yml => ci.yaml} | 2 +- rustfmt.toml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) rename .github/workflows/{ci.yml => ci.yaml} (97%) create mode 100644 rustfmt.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yaml similarity index 97% rename from .github/workflows/ci.yml rename to .github/workflows/ci.yaml index 0fd89dd..d1c3dc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yaml @@ -73,4 +73,4 @@ jobs: timeout-minutes: 1 steps: - name: Check - run: echo "All checks passed" \ No newline at end of file + run: echo "All checks passed" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..aa92088 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,14 @@ +edition = "2021" +indent_style = "Block" +use_small_heuristics = "Max" +version = "Two" + +# Simplification +merge_derives = true +remove_nested_parens = true +use_field_init_shorthand = true +use_try_shorthand = true + +# Sort +reorder_imports = true +reorder_modules = true From dcf389c67d617c46cf33a1aaeef5156deb025294 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 01:27:49 +0900 Subject: [PATCH 10/12] chore: apply rustfmt and clippy --- clippy.toml | 2 +- src/client/nodex.rs | 36 ++----- src/config/did.rs | 32 ++----- src/config/mod.rs | 4 +- src/config/server.rs | 5 +- src/nodex/cipher/credential_signer.rs | 19 +--- src/nodex/cipher/jws.rs | 7 +- src/nodex/extension/secure_keystore.rs | 5 +- src/nodex/extension/trng.rs | 4 +- src/nodex/keyring/keypair.rs | 34 ++----- src/nodex/keyring/secp256k1.rs | 125 ++++++++++--------------- src/nodex/runtime/bip32.rs | 4 +- src/nodex/runtime/multihash.rs | 20 +--- src/nodex/runtime/secp256k1.rs | 4 +- src/nodex/sidetree/payload.rs | 18 +--- src/nodex/utils/http_client.rs | 30 ++---- src/services/did_vc.rs | 19 +--- src/services/encrypted.rs | 63 +++++-------- 18 files changed, 129 insertions(+), 302 deletions(-) diff --git a/clippy.toml b/clippy.toml index f44aa50..cd878eb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -16,7 +16,7 @@ disallowed-macros = [ 'std::eprint', 'std::eprintln', 'std::print', - 'std::println', + # 'std::println', ] # https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names diff --git a/src/client/nodex.rs b/src/client/nodex.rs index 6288ced..df28c8b 100644 --- a/src/client/nodex.rs +++ b/src/client/nodex.rs @@ -40,9 +40,8 @@ impl Default for NodeX { impl NodeX { pub fn new() -> Self { let server_config = server_config(); - let client_config: HttpClientConfig = HttpClientConfig { - base_url: server_config.did_http_endpoint(), - }; + let client_config: HttpClientConfig = + HttpClientConfig { base_url: server_config.did_http_endpoint() }; let client = match HttpClient::new(&client_config) { Ok(v) => v, @@ -52,9 +51,7 @@ impl NodeX { } }; - NodeX { - http_client: client, - } + NodeX { http_client: client } } // NOTE: DONE @@ -72,9 +69,8 @@ impl NodeX { let mut keyring = keyring::keypair::KeyPairing::create_keyring()?; // NOTE: create payload - let public = keyring - .get_sign_key_pair() - .to_public_key("signingKey", &["auth", "general"])?; + let public = + keyring.get_sign_key_pair().to_public_key("signingKey", &["auth", "general"])?; let update = keyring.get_recovery_key_pair().to_jwk(false)?; let recovery = keyring.get_update_key_pair().to_jwk(false)?; let payload = OperationPayloadBuilder::did_create_payload(&DIDCreateRequest { @@ -83,10 +79,7 @@ impl NodeX { service_endpoints: vec![], })?; - let res = self - .http_client - .post("/api/v1/operations", &payload) - .await?; + let res = self.http_client.post("/api/v1/operations", &payload).await?; if res.status().is_success() { let json = res.json::().await?; @@ -98,11 +91,7 @@ impl NodeX { } else { let status = res.status(); let error = res.json::().await?; - Err(SideTreeError { - status_code: status, - error, - } - .into()) + Err(SideTreeError { status_code: status, error }.into()) } } @@ -111,21 +100,14 @@ impl NodeX { &self, did: &str, ) -> anyhow::Result> { - let res = self - .http_client - .get(&(format!("/api/v1/identifiers/{}", &did))) - .await?; + let res = self.http_client.get(&(format!("/api/v1/identifiers/{}", &did))).await?; match res.status() { StatusCode::OK => Ok(Some(res.json::().await?)), StatusCode::NOT_FOUND => Ok(None), other => { let error = res.json::().await?; - Err(SideTreeError { - status_code: other, - error, - } - .into()) + Err(SideTreeError { status_code: other, error }.into()) } } } diff --git a/src/config/did.rs b/src/config/did.rs index c204cdb..f7c8bfb 100644 --- a/src/config/did.rs +++ b/src/config/did.rs @@ -63,10 +63,7 @@ impl KeyPairConfig { let pk = hex::decode(&self.public_key)?; let sk = hex::decode(&self.secret_key)?; - Ok(KeyPair { - public_key: pk, - secret_key: sk, - }) + Ok(KeyPair { public_key: pk, secret_key: sk }) } } @@ -92,17 +89,8 @@ impl Default for ConfigRoot { fn default() -> Self { ConfigRoot { did: None, - key_pairs: KeyPairsConfig { - sign: None, - update: None, - recover: None, - encrypt: None, - }, - extensions: ExtensionsConfig { - trng: None, - secure_keystore: None, - cipher: None, - }, + key_pairs: KeyPairsConfig { sign: None, update: None, recover: None, encrypt: None }, + extensions: ExtensionsConfig { trng: None, secure_keystore: None, cipher: None }, is_initialized: false, schema_version: 1, } @@ -167,9 +155,7 @@ impl DidConfig { } pub fn write(&self) -> Result<(), DidConfigError> { - self.config - .save_json(&self.root) - .map_err(DidConfigError::WriteError) + self.config.save_json(&self.root).map_err(DidConfigError::WriteError) } fn decode(&self, value: &Option) -> Option> { @@ -284,10 +270,7 @@ impl DidConfig { None => return None, }; - Some(KeyPair { - public_key: pk, - secret_key: sk, - }) + Some(KeyPair { public_key: pk, secret_key: sk }) } None => None, } @@ -311,10 +294,7 @@ impl DidConfig { None => return None, }; - Some(KeyPair { - public_key: pk, - secret_key: sk, - }) + Some(KeyPair { public_key: pk, secret_key: sk }) } None => None, } diff --git a/src/config/mod.rs b/src/config/mod.rs index 8ee37d1..6269bd9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -27,9 +27,7 @@ pub fn did_config() -> Box { unsafe { ONCE.call_once(|| { - let singleton = SingletonDidConfig { - inner: Arc::new(Mutex::new(DidConfig::new())), - }; + let singleton = SingletonDidConfig { inner: Arc::new(Mutex::new(DidConfig::new())) }; SINGLETON = Some(Box::new(singleton)) }); diff --git a/src/config/server.rs b/src/config/server.rs index d3e0297..eda2d5c 100644 --- a/src/config/server.rs +++ b/src/config/server.rs @@ -19,10 +19,7 @@ impl ServerConfig { let link = env::var("NODEX_DID_ATTACHMENT_LINK").unwrap_or("https://did.getnodex.io".to_string()); - ServerConfig { - did_http_endpoint: did_endpoint, - did_attachment_link: link, - } + ServerConfig { did_http_endpoint: did_endpoint, did_attachment_link: link } } pub fn did_http_endpoint(&self) -> String { self.did_http_endpoint.clone() diff --git a/src/nodex/cipher/credential_signer.rs b/src/nodex/cipher/credential_signer.rs index 53fb656..6798d1c 100644 --- a/src/nodex/cipher/credential_signer.rs +++ b/src/nodex/cipher/credential_signer.rs @@ -117,10 +117,7 @@ impl CredentialSigner { // throw new Error() // } - let proof = object - .proof - .take() - .ok_or(CredentialSignerError::ProofNotFound)?; + let proof = object.proof.take().ok_or(CredentialSignerError::ProofNotFound)?; // FIXME: // if (proof === undefined) { @@ -189,9 +186,7 @@ pub mod tests { let model = GeneralVcDataModel { id: None, r#type: vec!["type".to_string()], - issuer: Issuer { - id: "issuer".to_string(), - }, + issuer: Issuer { id: "issuer".to_string() }, context: vec!["context".to_string()], issuance_date: "issuance_date".to_string(), credential_subject: CredentialSubject { @@ -241,9 +236,7 @@ pub mod tests { let model = GeneralVcDataModel { id: None, r#type: vec!["type".to_string()], - issuer: Issuer { - id: "issuer".to_string(), - }, + issuer: Issuer { id: "issuer".to_string() }, context: vec!["context".to_string()], issuance_date: "issuance_date".to_string(), credential_subject: CredentialSubject { @@ -268,11 +261,7 @@ pub mod tests { let (verified_model, verified) = match CredentialSigner::verify( vc, - &CredentialSignerSuite { - did: None, - key_id: None, - context, - }, + &CredentialSignerSuite { did: None, key_id: None, context }, ) { Ok(v) => v, Err(_) => panic!(), diff --git a/src/nodex/cipher/jws.rs b/src/nodex/cipher/jws.rs index a44fb41..38a79c7 100644 --- a/src/nodex/cipher/jws.rs +++ b/src/nodex/cipher/jws.rs @@ -40,11 +40,8 @@ pub enum JwsError { impl Jws { pub fn encode(object: &Value, context: &Secp256k1) -> Result { // NOTE: header - let header = JWSHeader { - alg: "ES256K".to_string(), - b64: false, - crit: vec!["b64".to_string()], - }; + let header = + JWSHeader { alg: "ES256K".to_string(), b64: false, crit: vec!["b64".to_string()] }; let header = runtime::base64_url::Base64Url::encode( json!(&header).to_string().as_bytes(), &PaddingType::NoPadding, diff --git a/src/nodex/extension/secure_keystore.rs b/src/nodex/extension/secure_keystore.rs index 1f07daf..1598ca6 100644 --- a/src/nodex/extension/secure_keystore.rs +++ b/src/nodex/extension/secure_keystore.rs @@ -215,10 +215,7 @@ impl SecureKeyStore { if let Some(exit_status) = NonZeroU32::new(result) { Err(SecureKeyStoreError::ExternalFunctionFailed(exit_status)) } else { - Ok(Some(KeyPair { - public_key, - secret_key, - })) + Ok(Some(KeyPair { public_key, secret_key })) } } } diff --git a/src/nodex/extension/trng.rs b/src/nodex/extension/trng.rs index 7ce4427..9a69de3 100644 --- a/src/nodex/extension/trng.rs +++ b/src/nodex/extension/trng.rs @@ -50,9 +50,7 @@ impl Trng { return Err(TrngError::ExternalFunctionFailed(exit_status)); } - Ok(CStr::from_ptr(buffer_ptr as *const core::ffi::c_char) - .to_bytes() - .to_vec()) + Ok(CStr::from_ptr(buffer_ptr as *const core::ffi::c_char).to_bytes().to_vec()) } } diff --git a/src/nodex/keyring/keypair.rs b/src/nodex/keyring/keypair.rs index a5fa1c6..a0ef380 100644 --- a/src/nodex/keyring/keypair.rs +++ b/src/nodex/keyring/keypair.rs @@ -49,9 +49,7 @@ impl KeyPairing { secure_keystore: &SecureKeyStore, key_type: SecureKeyStoreType, ) -> Result { - let key_pair = secure_keystore - .read(&key_type)? - .ok_or(KeyPairingError::KeyNotFound)?; + let key_pair = secure_keystore.read(&key_type)?.ok_or(KeyPairingError::KeyNotFound)?; Secp256k1::new(&Secp256k1Context { public: key_pair.public_key, @@ -65,14 +63,7 @@ impl KeyPairing { let recovery = load_secp256k1(&secure_keystore, SecureKeyStoreType::Recover)?; let encrypt = load_secp256k1(&secure_keystore, SecureKeyStoreType::Encrypt)?; - Ok(KeyPairing { - sign, - update, - recovery, - encrypt, - config, - secure_keystore, - }) + Ok(KeyPairing { sign, update, recovery, encrypt, config, secure_keystore }) } pub fn create_keyring() -> Result { @@ -88,14 +79,7 @@ impl KeyPairing { let recovery = Self::generate_secp256k1(&seed, Self::RECOVERY_DERIVATION_PATH)?; let encrypt = Self::generate_secp256k1(&seed, Self::ENCRYPT_DERIVATION_PATH)?; - Ok(KeyPairing { - sign, - update, - recovery, - encrypt, - config, - secure_keystore, - }) + Ok(KeyPairing { sign, update, recovery, encrypt, config, secure_keystore }) } pub fn get_sign_key_pair(&self) -> Secp256k1 { @@ -120,11 +104,8 @@ impl KeyPairing { ) -> Result { let node = runtime::bip32::BIP32::get_node(seed, derivation_path)?; - Secp256k1::new(&Secp256k1Context { - public: node.public_key, - secret: node.private_key, - }) - .map_err(KeyPairingError::KeyInitializationError) + Secp256k1::new(&Secp256k1Context { public: node.public_key, secret: node.private_key }) + .map_err(KeyPairingError::KeyInitializationError) } pub fn save(&mut self, did: &str) { @@ -175,10 +156,7 @@ impl KeyPairing { } pub fn get_identifier(&self) -> Result { - self.config - .lock() - .get_did() - .ok_or(KeyPairingError::DIDNotFound) + self.config.lock().get_did().ok_or(KeyPairingError::DIDNotFound) } } diff --git a/src/nodex/keyring/secp256k1.rs b/src/nodex/keyring/secp256k1.rs index cd8c894..49c1558 100644 --- a/src/nodex/keyring/secp256k1.rs +++ b/src/nodex/keyring/secp256k1.rs @@ -76,15 +76,9 @@ impl Secp256k1 { if context.public.len() == Self::COMPRESSED_PUBLIC_KEY_SIZE { let public = Secp256k1::transform_uncompressed_public_key(&context.public)?; - Ok(Secp256k1 { - public, - private: context.secret.clone(), - }) + Ok(Secp256k1 { public, private: context.secret.clone() }) } else if context.public.len() == Self::UNCOMPRESSED_PUBLIC_KEY_SIZE { - Ok(Secp256k1 { - public: context.public.clone(), - private: context.secret.clone(), - }) + Ok(Secp256k1 { public: context.public.clone(), private: context.secret.clone() }) } else { Err(Secp256k1Error::InvalidPublicKeySize) } @@ -175,11 +169,7 @@ impl Secp256k1 { id: key_id.to_string(), r#type: "EcdsaSecp256k1VerificationKey2019".to_string(), jwk, - purpose: purpose - .to_vec() - .iter() - .map(|value| value.to_string()) - .collect(), + purpose: purpose.to_vec().iter().map(|value| value.to_string()).collect(), }) } @@ -261,13 +251,12 @@ pub mod tests { #[test] pub fn test_to_hex_key_pair() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = node.to_hex_key_pair(); @@ -280,13 +269,12 @@ pub mod tests { #[test] pub fn test_get_point_x() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = match node.get_point_x() { Ok(v) => v, @@ -305,13 +293,12 @@ pub mod tests { #[test] pub fn test_get_point_y() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = match node.get_point_y() { Ok(v) => v, @@ -330,13 +317,12 @@ pub mod tests { #[test] pub fn test_validate_point() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = match node.validate_point() { Ok(v) => v, @@ -348,13 +334,12 @@ pub mod tests { #[test] pub fn test_to_jwk_with_private_key() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = match node.to_jwk(true) { Ok(v) => v, @@ -365,22 +350,18 @@ pub mod tests { assert_eq!(result.crv, "secp256k1"); assert_eq!(result.x, "cJZFMvCD9F_o6MzqlqIvYBjUakBvWDqyJrGSg6pgXEQ"); assert_eq!(result.y, "hRuSdOaizirUK0Fp43319ss46BYEs8ouvhHdCFhitJA"); - assert_eq!( - result.d, - Some("xzmAWrA9pi3b4DOQrN92FWQKpu0xuPGCQ_BKVyxSjts".to_string()) - ); + assert_eq!(result.d, Some("xzmAWrA9pi3b4DOQrN92FWQKpu0xuPGCQ_BKVyxSjts".to_string())); assert_eq!(result.kid, None); } #[test] pub fn test_to_jwk_without_private_key() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let result = match node.to_jwk(false) { Ok(v) => v, @@ -397,13 +378,12 @@ pub mod tests { #[test] pub fn test_from_jwk_with_private_key() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let jwk = match node.to_jwk(false) { Ok(v) => v, @@ -428,13 +408,12 @@ pub mod tests { #[test] pub fn test_from_jwk_without_private_key() { - let node = match Secp256k1::new(&Secp256k1Context { - public: public_key(), - secret: private_key(), - }) { - Ok(v) => v, - Err(_) => panic!(), - }; + let node = + match Secp256k1::new(&Secp256k1Context { public: public_key(), secret: private_key() }) + { + Ok(v) => v, + Err(_) => panic!(), + }; let jwk = match node.to_jwk(true) { Ok(v) => v, diff --git a/src/nodex/runtime/bip32.rs b/src/nodex/runtime/bip32.rs index a0b5e57..b61f18f 100644 --- a/src/nodex/runtime/bip32.rs +++ b/src/nodex/runtime/bip32.rs @@ -22,9 +22,7 @@ impl BIP32 { let chain = DefaultKeyChain::new(master); let path = ChainPath::new(derivation_path); - let (private_key, _) = chain - .derive_private_key(path) - .map_err(BIP32Error::Hdwallet)?; + let (private_key, _) = chain.derive_private_key(path).map_err(BIP32Error::Hdwallet)?; let public_key = ExtendedPubKey::from_private_key(&private_key); diff --git a/src/nodex/runtime/multihash.rs b/src/nodex/runtime/multihash.rs index 905fde1..f98407e 100644 --- a/src/nodex/runtime/multihash.rs +++ b/src/nodex/runtime/multihash.rs @@ -79,16 +79,10 @@ impl Multihash { let digest = encoded[2..].to_vec(); if digest.len() != usize::from(length) { - return Err(MultihashError::SizeValidationFailed( - usize::from(length), - digest.len(), - )); + return Err(MultihashError::SizeValidationFailed(usize::from(length), digest.len())); } - Ok(DecodedContainer { - hash: digest, - algorithm: u64::from(code), - }) + Ok(DecodedContainer { hash: digest, algorithm: u64::from(code) }) } } @@ -138,20 +132,14 @@ mod tests { Err(_) => panic!(), }; - assert_eq!( - result, - String::from("EiAEX1W46vVid7IjJyFY5ibjmyrgepTjW0rYrw-wo4xLCw") - ); + assert_eq!(result, String::from("EiAEX1W46vVid7IjJyFY5ibjmyrgepTjW0rYrw-wo4xLCw")); } #[test] fn test_hash_then_encode() { let result = Multihash::hash_then_encode(message().as_bytes()); - assert_eq!( - result, - String::from("EiBfRiXU9h7bUngHRV9I-L4njnHoSqlNIxEf-rO2MJOnEw") - ); + assert_eq!(result, String::from("EiBfRiXU9h7bUngHRV9I-L4njnHoSqlNIxEf-rO2MJOnEw")); } #[test] diff --git a/src/nodex/runtime/secp256k1.rs b/src/nodex/runtime/secp256k1.rs index 22a3567..82719f6 100644 --- a/src/nodex/runtime/secp256k1.rs +++ b/src/nodex/runtime/secp256k1.rs @@ -27,9 +27,7 @@ impl Secp256k1 { let sk = SecretKey::from_be_bytes(private_key)?; let pk = PublicKey::from_sec1_bytes(public_key)?; - Ok(diffie_hellman(sk.to_nonzero_scalar(), pk.as_affine()) - .as_bytes() - .to_vec()) + Ok(diffie_hellman(sk.to_nonzero_scalar(), pk.as_affine()).as_bytes().to_vec()) } #[allow(dead_code)] diff --git a/src/nodex/sidetree/payload.rs b/src/nodex/sidetree/payload.rs index 229a7c8..5efcba5 100644 --- a/src/nodex/sidetree/payload.rs +++ b/src/nodex/sidetree/payload.rs @@ -277,25 +277,15 @@ impl OperationPayloadBuilder { public_keys: params.public_keys.clone(), service_endpoints: params.service_endpoints.clone(), }; - let patch: DIDReplaceAction = DIDReplaceAction { - action: "replace".to_string(), - document, - }; + let patch: DIDReplaceAction = DIDReplaceAction { action: "replace".to_string(), document }; - let delta = json!(DIDReplaceDeltaObject { - patches: vec![patch], - update_commitment, - }) - .to_string(); + let delta = + json!(DIDReplaceDeltaObject { patches: vec![patch], update_commitment }).to_string(); let delta_bytes = delta.as_bytes(); let delta_hash = Base64Url::encode(&Multihash::hash(delta_bytes), &PaddingType::NoPadding); - let suffix = json!(DIDReplaceSuffixObject { - delta_hash, - recovery_commitment, - }) - .to_string(); + let suffix = json!(DIDReplaceSuffixObject { delta_hash, recovery_commitment }).to_string(); let suffix_bytes = suffix.as_bytes(); diff --git a/src/nodex/utils/http_client.rs b/src/nodex/utils/http_client.rs index 84f0291..5756847 100644 --- a/src/nodex/utils/http_client.rs +++ b/src/nodex/utils/http_client.rs @@ -18,18 +18,12 @@ impl HttpClient { let url = Url::parse(&_config.base_url.to_string())?; let client: reqwest::Client = reqwest::Client::new(); - Ok(HttpClient { - instance: client, - base_url: url, - }) + Ok(HttpClient { instance: client, base_url: url }) } fn default_headers(&self) -> HeaderMap { let mut headers = HeaderMap::new(); - headers.insert( - reqwest::header::CONTENT_TYPE, - HeaderValue::from_static("application/json"), - ); + headers.insert(reqwest::header::CONTENT_TYPE, HeaderValue::from_static("application/json")); headers } @@ -102,9 +96,8 @@ pub mod tests { #[actix_rt::test] #[ignore] async fn it_should_success_get() { - let client_config: HttpClientConfig = HttpClientConfig { - base_url: "https://httpbin.org".to_string(), - }; + let client_config: HttpClientConfig = + HttpClientConfig { base_url: "https://httpbin.org".to_string() }; let client = match HttpClient::new(&client_config) { Ok(v) => v, @@ -127,9 +120,8 @@ pub mod tests { #[actix_rt::test] #[ignore] async fn it_should_success_post() { - let client_config: HttpClientConfig = HttpClientConfig { - base_url: "https://httpbin.org".to_string(), - }; + let client_config: HttpClientConfig = + HttpClientConfig { base_url: "https://httpbin.org".to_string() }; let client = match HttpClient::new(&client_config) { Ok(v) => v, @@ -152,9 +144,8 @@ pub mod tests { #[actix_rt::test] #[ignore] async fn it_should_success_put() { - let client_config: HttpClientConfig = HttpClientConfig { - base_url: "https://httpbin.org".to_string(), - }; + let client_config: HttpClientConfig = + HttpClientConfig { base_url: "https://httpbin.org".to_string() }; let client = match HttpClient::new(&client_config) { Ok(v) => v, @@ -177,9 +168,8 @@ pub mod tests { #[actix_rt::test] #[ignore] async fn it_should_success_delete() { - let client_config: HttpClientConfig = HttpClientConfig { - base_url: "https://httpbin.org".to_string(), - }; + let client_config: HttpClientConfig = + HttpClientConfig { base_url: "https://httpbin.org".to_string() }; let client = match HttpClient::new(&client_config) { Ok(v) => v, diff --git a/src/services/did_vc.rs b/src/services/did_vc.rs index 2fc3091..4d77372 100644 --- a/src/services/did_vc.rs +++ b/src/services/did_vc.rs @@ -19,9 +19,7 @@ pub struct DIDVCService { impl DIDVCService { pub fn new(did_repository: R) -> Self { - Self { - did_repository: Box::new(did_repository), - } + Self { did_repository: Box::new(did_repository) } } } @@ -42,9 +40,7 @@ impl DIDVCService { issuance_date: DateTime, ) -> Result { let keyring = keyring::keypair::KeyPairing::load_keyring()?; - let did = keyring - .get_identifier() - .map_err(|_| DIDVCServiceError::MyDIDNotSet)?; + let did = keyring.get_identifier().map_err(|_| DIDVCServiceError::MyDIDNotSet)?; let r#type = "VerifiableCredential".to_string(); let context = "https://www.w3.org/2018/credentials/v1".to_string(); @@ -56,10 +52,7 @@ impl DIDVCService { r#type: vec![r#type], context: vec![context], issuance_date, - credential_subject: CredentialSubject { - id: None, - container: message.clone(), - }, + credential_subject: CredentialSubject { id: None, container: message.clone() }, expiration_date: None, proof: None, }; @@ -96,11 +89,7 @@ impl DIDVCService { let (verified_model, verified) = CredentialSigner::verify( model, - &CredentialSignerSuite { - did: None, - key_id: None, - context, - }, + &CredentialSignerSuite { did: None, key_id: None, context }, ) .context("failed to verify credential")?; diff --git a/src/services/encrypted.rs b/src/services/encrypted.rs index 2ac10b1..c828906 100644 --- a/src/services/encrypted.rs +++ b/src/services/encrypted.rs @@ -54,10 +54,7 @@ impl DIDCommEncryptedService { did_repository: R, vc_service: DIDVCService, ) -> DIDCommEncryptedService { - DIDCommEncryptedService { - did_repository: Box::new(did_repository), - vc_service, - } + DIDCommEncryptedService { did_repository: Box::new(did_repository), vc_service } } pub async fn generate( @@ -72,9 +69,11 @@ impl DIDCommEncryptedService { let my_did = my_keyring.get_identifier()?; // NOTE: recipient to - let did_document = self.did_repository.find_identifier(to_did).await?.ok_or( - DIDCommEncryptedServiceError::DIDNotFound(to_did.to_string()), - )?; + let did_document = self + .did_repository + .find_identifier(to_did) + .await? + .ok_or(DIDCommEncryptedServiceError::DIDNotFound(to_did.to_string()))?; let public_keys = did_document .did_document @@ -103,11 +102,10 @@ impl DIDCommEncryptedService { let body = self.vc_service.generate(message, issuance_date)?; let body = serde_json::to_string(&body).context("failed to serialize")?; - let mut message = Message::new() - .from(&my_did) - .to(&[to_did]) - .body(&body) - .map_err(|e| anyhow::anyhow!("Failed to initialize message with error = {:?}", e))?; + let mut message = + Message::new().from(&my_did).to(&[to_did]).body(&body).map_err(|e| { + anyhow::anyhow!("Failed to initialize message with error = {:?}", e) + })?; // NOTE: Has attachment if let Some(value) = metadata { @@ -119,10 +117,7 @@ impl DIDCommEncryptedService { .with_json(&value.to_string()); message.append_attachment( - AttachmentBuilder::new(true) - .with_id(&id) - .with_format("metadata") - .with_data(data), + AttachmentBuilder::new(true).with_id(&id).with_format("metadata").with_data(data), ) } @@ -169,15 +164,10 @@ impl DIDCommEncryptedService { .did_repository .find_identifier(other_did) .await? - .ok_or(DIDCommEncryptedServiceError::DIDNotFound( - other_did.to_string(), - ))?; + .ok_or(DIDCommEncryptedServiceError::DIDNotFound(other_did.to_string()))?; let public_keys = did_document.did_document.public_key.with_context(|| { - format!( - "public_key is not found in did_document. did = {}", - other_did - ) + format!("public_key is not found in did_document. did = {}", other_did) })?; // FIXME: workaround @@ -206,12 +196,10 @@ impl DIDCommEncryptedService { ) .map_err(|e| anyhow::anyhow!("failed to decrypt message : {:?}", e))?; - let metadata = message - .attachment_iter() - .find(|item| match item.format.clone() { - Some(value) => value == "metadata", - None => false, - }); + let metadata = message.attachment_iter().find(|item| match item.format.clone() { + Some(value) => value == "metadata", + None => false, + }); let body = message .clone() @@ -222,22 +210,13 @@ impl DIDCommEncryptedService { match metadata { Some(metadata) => { - let metadata = metadata - .data - .json - .as_ref() - .ok_or(anyhow::anyhow!("metadata not found"))?; + let metadata = + metadata.data.json.as_ref().ok_or(anyhow::anyhow!("metadata not found"))?; let metadata = serde_json::from_str::(metadata) .context("failed to parse metadata to json")?; - Ok(VerifiedContainer { - message: body, - metadata: Some(metadata), - }) + Ok(VerifiedContainer { message: body, metadata: Some(metadata) }) } - None => Ok(VerifiedContainer { - message: body, - metadata: None, - }), + None => Ok(VerifiedContainer { message: body, metadata: None }), } } } From baa2c2cc96960989832899c4f85d6d83efbe1190 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 01:30:12 +0900 Subject: [PATCH 11/12] chore: reformat toml --- clippy.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy.toml b/clippy.toml index cd878eb..b7d2efa 100644 --- a/clippy.toml +++ b/clippy.toml @@ -12,10 +12,10 @@ type-complexity-threshold = 350 # https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods disallowed-macros = [ 'dbg', - 'std::unimplemented', 'std::eprint', 'std::eprintln', 'std::print', + 'std::unimplemented', # 'std::println', ] @@ -23,4 +23,4 @@ disallowed-macros = [ disallowed-names = [] # https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types -disallowed-types = [] \ No newline at end of file +disallowed-types = [] From 92ce97576ffb382f25aa0d312cf906330b676c17 Mon Sep 17 00:00:00 2001 From: Ryo Abe Date: Tue, 19 Mar 2024 01:33:42 +0900 Subject: [PATCH 12/12] chore: restrict permission of ci jobs --- .github/workflows/ci.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d1c3dc2..385eb4b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,9 @@ jobs: name: Lint runs-on: ubuntu-latest timeout-minutes: 10 + permissions: + contents: read + checks: write steps: - uses: actions/checkout@v4 @@ -47,6 +50,9 @@ jobs: name: Test runs-on: ubuntu-latest timeout-minutes: 10 + permissions: + contents: read + checks: write steps: - uses: actions/checkout@v3