From 353bbc25923be5a944c8c5e88910381ac7a73ef9 Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Wed, 19 Jul 2023 14:57:54 +0300 Subject: [PATCH] Update backend to handle new type --- sponsoredTransactions/backend/Cargo.lock | 259 +- sponsoredTransactions/backend/Cargo.toml | 1 + sponsoredTransactions/backend/src/handlers.rs | 20 +- sponsoredTransactions/backend/src/main.rs | 15 +- sponsoredTransactions/backend/src/types.rs | 28 +- sponsoredTransactions/frontend/.eslintrc.js | 57 + sponsoredTransactions/frontend/CHANGELOG.md | 2 +- sponsoredTransactions/frontend/package.json | 19 +- sponsoredTransactions/frontend/src/Root.tsx | 4 +- .../frontend/src/SponsoredTransactions.tsx | 292 +- .../src/WalletConnectorTypeButton.tsx | 12 +- .../frontend/src/constants.ts | 17 +- sponsoredTransactions/frontend/src/utils.ts | 101 +- sponsoredTransactions/frontend/yarn.lock | 2557 ++++++++++++++++- 14 files changed, 2909 insertions(+), 475 deletions(-) create mode 100644 sponsoredTransactions/frontend/.eslintrc.js diff --git a/sponsoredTransactions/backend/Cargo.lock b/sponsoredTransactions/backend/Cargo.lock index 5d0f6112..10728946 100644 --- a/sponsoredTransactions/backend/Cargo.lock +++ b/sponsoredTransactions/backend/Cargo.lock @@ -144,6 +144,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "bitflags" version = "1.3.2" @@ -488,6 +494,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -947,7 +963,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ - "base64", + "base64 0.13.1", "bitflags", "bytes", "headers-core", @@ -1138,7 +1154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1150,7 +1166,7 @@ dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1278,7 +1294,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1429,6 +1445,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "os_str_bytes" version = "6.4.1" @@ -1467,7 +1489,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1781,6 +1803,21 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rkyv" version = "0.7.39" @@ -1844,7 +1881,31 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile 1.0.3", + "schannel", + "security-framework", ] [[package]] @@ -1853,7 +1914,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" dependencies = [ - "base64", + "base64 0.13.1", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64 0.21.2", ] [[package]] @@ -1874,6 +1944,15 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1892,6 +1971,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "seahash" version = "4.1.0" @@ -1916,6 +2005,29 @@ dependencies = [ "cc", ] +[[package]] +name = "security-framework" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.14" @@ -2061,6 +2173,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "sponsored-transaction-backend" version = "1.0.0" @@ -2077,6 +2195,7 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tonic", "uuid", "warp", ] @@ -2232,6 +2351,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + [[package]] name = "tokio-stream" version = "0.1.11" @@ -2287,7 +2417,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64", + "base64 0.13.1", "bytes", "futures-core", "futures-util", @@ -2300,7 +2430,10 @@ dependencies = [ "pin-project", "prost", "prost-derive", + "rustls-native-certs", + "rustls-pemfile 1.0.3", "tokio", + "tokio-rustls", "tokio-stream", "tokio-util", "tower", @@ -2416,7 +2549,7 @@ version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" dependencies = [ - "base64", + "base64 0.13.1", "byteorder", "bytes", "http", @@ -2486,6 +2619,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.3.1" @@ -2547,7 +2686,7 @@ dependencies = [ "multipart", "percent-encoding", "pin-project", - "rustls-pemfile", + "rustls-pemfile 0.2.1", "scoped-tls", "serde", "serde_json", @@ -2632,6 +2771,26 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2669,13 +2828,37 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.0", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm 0.42.0", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -2684,42 +2867,84 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "zeroize" version = "1.3.0" diff --git a/sponsoredTransactions/backend/Cargo.toml b/sponsoredTransactions/backend/Cargo.toml index a69ab46d..650bc33e 100644 --- a/sponsoredTransactions/backend/Cargo.toml +++ b/sponsoredTransactions/backend/Cargo.toml @@ -9,6 +9,7 @@ license-file = "../../LICENSE" [dependencies] tokio = { version = "1", features = ["full"] } +tonic = {version = "0.8", features = ["tls", "tls-roots"]} # Use system trust roots. warp = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/sponsoredTransactions/backend/src/handlers.rs b/sponsoredTransactions/backend/src/handlers.rs index 04c2ae79..5e6eace7 100644 --- a/sponsoredTransactions/backend/src/handlers.rs +++ b/sponsoredTransactions/backend/src/handlers.rs @@ -124,17 +124,27 @@ pub async fn submit_transaction( hex::decode_to_slice(request_signature, &mut signature) .map_err(|_| LogError::SignatureError)?; - let mut inner_signature_map: BTreeMap = BTreeMap::new(); - inner_signature_map.insert(0, types::SignatureEd25519(signature)); + let mut inner_signature_map = BTreeMap::new(); + inner_signature_map.insert( + 0, + types::Signature::Ed25519(types::SignatureEd25519(signature)), + ); - let mut signature_map: BTreeMap> = BTreeMap::new(); - signature_map.insert(0, inner_signature_map); + let mut signature_map = BTreeMap::new(); + signature_map.insert( + 0, + types::CredentialSignatures { + sigs: inner_signature_map, + }, + ); log::debug!("Create Parameter."); let param: PermitParam = PermitParam { message, - signature: signature_map, + signature: AccountSignatures { + sigs: signature_map, + }, signer, }; diff --git a/sponsoredTransactions/backend/src/main.rs b/sponsoredTransactions/backend/src/main.rs index ba840d7e..f50acc86 100644 --- a/sponsoredTransactions/backend/src/main.rs +++ b/sponsoredTransactions/backend/src/main.rs @@ -10,6 +10,8 @@ use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; use tokio::sync::Mutex; +use tonic::transport::ClientTlsConfig; +use warp::http; use warp::Filter; /// Structure used to receive the correct command line arguments. @@ -59,7 +61,18 @@ async fn main() -> anyhow::Result<()> { log_builder.filter_level(app.log_level); // filter filter_module(module_path!(), app.log_level); log_builder.init(); - let mut client_update_operator = concordium_rust_sdk::v2::Client::new(app.endpoint).await?; + let endpoint = if app + .endpoint + .uri() + .scheme() + .map_or(false, |x| x == &http::uri::Scheme::HTTPS) + { + app.endpoint.tls_config(ClientTlsConfig::new())? + } else { + app.endpoint + }; + + let mut client_update_operator = concordium_rust_sdk::v2::Client::new(endpoint).await?; let client_transfer = client_update_operator.clone(); diff --git a/sponsoredTransactions/backend/src/types.rs b/sponsoredTransactions/backend/src/types.rs index 013f0656..c52ba0c4 100644 --- a/sponsoredTransactions/backend/src/types.rs +++ b/sponsoredTransactions/backend/src/types.rs @@ -102,8 +102,7 @@ pub struct UpdateOperatorParams(#[concordium(size_length = 2)] pub Vec>, + pub signature: AccountSignatures, pub signer: AccountAddress, pub message: PermitMessage, } @@ -129,3 +128,28 @@ pub struct Server { // The rate_limits are transient and are reset on server restart. pub rate_limits: Arc>>, } + +pub(crate) type CredentialIndex = u8; +pub(crate) type KeyIndex = u8; + +#[derive(Serial, Debug, Clone)] +#[non_exhaustive] +/// A cryptographic signature indexed by the signature scheme. Currently only a +/// single scheme is supported, `ed25519`. +pub enum Signature { + Ed25519(SignatureEd25519), +} + +#[derive(Debug, Serial, Clone)] +#[concordium(transparent)] +pub struct AccountSignatures { + #[concordium(size_length = 1)] + pub sigs: BTreeMap, +} + +#[derive(Debug, Serial, Clone)] +#[concordium(transparent)] +pub struct CredentialSignatures { + #[concordium(size_length = 1)] + pub sigs: BTreeMap, +} diff --git a/sponsoredTransactions/frontend/.eslintrc.js b/sponsoredTransactions/frontend/.eslintrc.js new file mode 100644 index 00000000..0da2dbe4 --- /dev/null +++ b/sponsoredTransactions/frontend/.eslintrc.js @@ -0,0 +1,57 @@ +module.exports = { + parser: '@typescript-eslint/parser', + extends: ['airbnb', 'airbnb-typescript', 'plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended'], + parserOptions: { + ecmaVersion: 2020, + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + project: 'tsconfig.json', + createDefaultProgram: true, + }, + env: { + browser: true, + jest: true, + node: true, + }, + rules: { + 'import/prefer-default-export': 0, + 'no-restricted-exports': 0, + 'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], + 'react/jsx-props-no-spreading': 0, + 'react/require-default-props': 0, + 'class-methods-use-this': 0, + 'jsx-a11y/no-autofocus': 0, + 'no-await-in-loop': 0, + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: [ + '**/*.stories.tsx', + '**/build/**/*', + '**/*.config.js', + '**/*.config.ts', + '**/test/**/*', + ], + }, + ], + 'jsx-a11y/label-has-associated-control': [ + 'error', + { + required: { + some: ['nesting', 'id'], + }, + }, + ], + 'prettier/prettier': [ + 'error', + { + trailingComma: 'es5', + singleQuote: true, + printWidth: 120, + tabWidth: 4, + }, + ], + }, +}; diff --git a/sponsoredTransactions/frontend/CHANGELOG.md b/sponsoredTransactions/frontend/CHANGELOG.md index ff02fada..73b89de3 100644 --- a/sponsoredTransactions/frontend/CHANGELOG.md +++ b/sponsoredTransactions/frontend/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.0 -- Remove tap to register public key +- Remove tab to register public key ## 1.1.0 diff --git a/sponsoredTransactions/frontend/package.json b/sponsoredTransactions/frontend/package.json index f9132864..3577e03d 100644 --- a/sponsoredTransactions/frontend/package.json +++ b/sponsoredTransactions/frontend/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "@concordium/browser-wallet-api-helpers": "2.4.0", - "@concordium/react-components": "^0.2.1", + "@concordium/react-components": "^0.3.0", "@concordium/web-sdk": "^3.4.0", "@thi.ng/leb128": "^2.1.18", "@types/sha256": "^0.2.0", @@ -26,12 +26,29 @@ "@types/node": "^18.7.23", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.5", + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", "cross-env": "^7.0.3", "esbuild": "^0.14.42", "esbuild-plugin-svgr": "^1.0.1", + "eslint": "7", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-airbnb-typescript": "^17.0.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-jsx-a11y": "^6.5.1", + "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-react": "^7.29.4", + "eslint-plugin-react-hooks": "^4.4.0", "fs": "^0.0.1-security", "live-server": "^1.2.2", + "prettier": "^2.6.2", "process": "^0.11.10", + "stylelint": "^14.7.1", + "stylelint-config-prettier": "^9.0.3", + "stylelint-config-standard-scss": "^3.0.0", + "stylelint-prettier": "^2.0.0", + "stylelint-scss": "^4.2.0", "ts-node": "^10.8.0", "typescript": "^4.7.2" }, diff --git a/sponsoredTransactions/frontend/src/Root.tsx b/sponsoredTransactions/frontend/src/Root.tsx index fe1279cd..bb65adee 100644 --- a/sponsoredTransactions/frontend/src/Root.tsx +++ b/sponsoredTransactions/frontend/src/Root.tsx @@ -11,7 +11,9 @@ export default function Root() { return (
- {(props) => } + + {(props) => } +
); diff --git a/sponsoredTransactions/frontend/src/SponsoredTransactions.tsx b/sponsoredTransactions/frontend/src/SponsoredTransactions.tsx index 61490a30..9f403b13 100644 --- a/sponsoredTransactions/frontend/src/SponsoredTransactions.tsx +++ b/sponsoredTransactions/frontend/src/SponsoredTransactions.tsx @@ -3,13 +3,14 @@ import React, { useEffect, useState, ChangeEvent } from 'react'; import Switch from 'react-switch'; +import { toBuffer, JsonRpcClient, serializeTypeValue, deserializeTypeValue } from '@concordium/web-sdk'; import { - toBuffer, - JsonRpcClient, - serializeTypeValue, - deserializeTypeValue -} from '@concordium/web-sdk'; -import { withJsonRpcClient, WalletConnectionProps, useConnection, useConnect } from '@concordium/react-components'; + withJsonRpcClient, + WalletConnectionProps, + useConnection, + useConnect, + typeSchemaFromBase64, +} from '@concordium/react-components'; import { version } from '../package.json'; import { submitUpdateOperator, submitTransfer, mint } from './utils'; @@ -68,32 +69,6 @@ const ButtonStyleDisabled = { fontSize: '14px', }; -const ButtonStyleSelected = { - color: 'white', - borderRadius: 10, - margin: '7px 0px 7px 0px', - padding: '10px', - width: '100%', - border: '0px solid', - backgroundColor: '#174039', - cursor: 'pointer', - fontWeight: 300, - fontSize: '14px', -}; - -const ButtonStyleNotSelected = { - color: 'white', - borderRadius: 10, - margin: '7px 0px 7px 0px', - padding: '10px', - width: '100%', - border: '0px solid', - backgroundColor: '#308274', - cursor: 'pointer', - fontWeight: 300, - fontSize: '14px', -}; - const InputFieldStyle = { backgroundColor: '#181817', color: 'white', @@ -146,25 +121,21 @@ async function calculateTransferMessage(nonce: string, tokenID: string, from: st return ''; } - const transfer = - [ - { - amount: '1', - data: '', - from: { - Account: [from], - }, - to: { - Account: [to], - }, - token_id: tokenID, + const transfer = [ + { + amount: '1', + data: [], + from: { + Account: [from], + }, + to: { + Account: [to], }, - ] + token_id: tokenID, + }, + ]; - const payload = serializeTypeValue( - transfer, - toBuffer(TRANSFER_SCHEMA, 'base64') - ); + const payload = serializeTypeValue(transfer, toBuffer(TRANSFER_SCHEMA, 'base64')); const message = { contract_address: { @@ -177,10 +148,7 @@ async function calculateTransferMessage(nonce: string, tokenID: string, from: st payload: Array.from(payload), }; - const serializedMessage = serializeTypeValue( - message, - toBuffer(SERIALIZATION_HELPER_SCHEMA, 'base64') - ); + const serializedMessage = serializeTypeValue(message, toBuffer(SERIALIZATION_HELPER_SCHEMA, 'base64')); return serializedMessage; } @@ -215,20 +183,17 @@ async function calculateUpdateOperatorMessage(nonce: string, operator: string, a Remove: [], }; - const updateOperator = - [ - { - operator: { - Account: [operator], - }, - update: operatorAction, - } - ] + const updateOperator = [ + { + operator: { + Account: [operator], + }, + update: operatorAction, + }, + ]; + + const payload = serializeTypeValue(updateOperator, toBuffer(UPDATE_OPERATOR_SCHEMA, 'base64')); - const payload = serializeTypeValue( - updateOperator, - toBuffer(UPDATE_OPERATOR_SCHEMA, 'base64') - ); const message = { contract_address: { @@ -241,22 +206,18 @@ async function calculateUpdateOperatorMessage(nonce: string, operator: string, a payload: Array.from(payload), }; - const serializedMessage = serializeTypeValue( - message, - toBuffer(SERIALIZATION_HELPER_SCHEMA, 'base64') - ); + const serializedMessage = serializeTypeValue(message, toBuffer(SERIALIZATION_HELPER_SCHEMA, 'base64')); return serializedMessage; } -async function getPublicKey(rpcClient: JsonRpcClient, account: string) { +async function getPublicKey(rpcClient: any, account: string) { const res = await rpcClient.getAccountInfo(account); const publicKey = res?.accountCredentials[0].value.contents.credentialPublicKeys.keys[0].verifyKey; return publicKey; } -async function getNonceOf(rpcClient: JsonRpcClient, account: string) { - +async function getNonceOf(rpcClient: any, account: string) { const param = serializeTypeValue( { queries: [ @@ -281,14 +242,10 @@ async function getNonceOf(rpcClient: JsonRpcClient, account: string) { } // @ts-ignore - const returnValues:any[][] = deserializeTypeValue - (toBuffer(res.returnValue, 'hex'), - toBuffer(NONCE_OF_RETURN_VALUE_SCHEMA, 'base64') - ); - - // { - // None: undefined; Some: any[][]; - // }[][] | undefined + const returnValues: any[][] = deserializeTypeValue( + toBuffer(res.returnValue, 'hex'), + toBuffer(NONCE_OF_RETURN_VALUE_SCHEMA, 'base64') + ); if (returnValues === undefined) { throw new Error( @@ -296,19 +253,9 @@ async function getNonceOf(rpcClient: JsonRpcClient, account: string) { ); } - // if (None !== undefined) { - // // [public key, nonce] of a user that has not registered a public key yet - // return ['', 0]; - // } - - // console.log(returnValues[0]) - - // console.log(returnValues[0][0]) - // console.log("returnValues") - if (returnValues !== undefined) { - // [public key, nonce] of a user that has registered a public key already - return returnValues[0][0] + // Return next nonce of a user + return returnValues[0][0]; } throw new Error( @@ -361,7 +308,7 @@ export default function SponsoredTransactions(props: WalletConnectionProps) { const [isPermitUpdateOperator, setPermitUpdateOperator] = useState(true); const [nextNonce, setNextNonce] = useState(0); - const [accountInfoPublicKey, setAccountInfoPublicKey] = useState(''); + const [accountInfoPublicKey, setAccountInfoPublicKey] = useState(''); const [operator, setOperator] = useState(''); const [addOperator, setAddOperator] = useState(true); @@ -477,14 +424,13 @@ export default function SponsoredTransactions(props: WalletConnectionProps) { } }, [connection, account]); - useEffect(() => { // Get next nonce record from smart contract. if (connection && account) { withJsonRpcClient(connection, (rpcClient) => getNonceOf(rpcClient, account)) - .then((nonce) => { - if (nonce !== undefined) { - setNextNonce(nonce); + .then((nonceValue) => { + if (nonceValue !== undefined) { + setNextNonce(nonceValue); } setNextNonceError(''); }) @@ -566,72 +512,6 @@ export default function SponsoredTransactions(props: WalletConnectionProps) {
Your next nonce is:
{nextNonce}
{nextNonceError &&
Error: {nextNonceError}.
} - {/*
-
-
- - { - setIsRegisterPublicKeyPage(!isRegisterPublicKeyPage); - setSignature(''); - setSigningError(''); - setTokenID(''); - setFrom(''); - setTo(''); - setOperator(''); - setNonce(''); - setSigner(''); - setTransactionError(''); - setTxHash(''); - clearInputFields(); - }} - onColor="#308274" - offColor="#308274" - onHandleColor="#174039" - offHandleColor="#174039" - checked={!isRegisterPublicKeyPage} - checkedIcon={false} - uncheckedIcon={false} - /> -
*/} )} {genesisHash && genesisHash !== network.genesisHash && ( @@ -776,10 +656,15 @@ export default function SponsoredTransactions(props: WalletConnectionProps) { : await calculateTransferMessage(nonce, tokenID, from, to); if (serializedMessage !== '') { - const promise = connection.signMessage(account, { - data: serializedMessage.toString('hex'), - schema: SERIALIZATION_HELPER_SCHEMA, - }) + const promise = connection.signMessage( + account, + { + type: 'BinaryMessage', + value: serializedMessage, + schema: typeSchemaFromBase64(SERIALIZATION_HELPER_SCHEMA), + } + ); + promise .then((permitSignature) => { setSignature(permitSignature[0][0]); @@ -801,14 +686,6 @@ export default function SponsoredTransactions(props: WalletConnectionProps) { )}
- {/* {publicKey !== '' && ( - <> -
Your registered public key is:
-
{accountInfoPublicKey}
-
Your next nonce is:
-
{nextNonce}
- - )} */}