diff --git a/Cargo.lock b/Cargo.lock index 9556fd4..ad9e837 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2202,7 +2202,7 @@ dependencies = [ "serde", "serde_json", "serde_with", - "starknet", + "starknet 0.10.0", "starknet-crypto 0.6.2", "starknet_api", "strum 0.25.0", @@ -2250,6 +2250,28 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "lambdaworks-crypto" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +dependencies = [ + "lambdaworks-math", + "serde", + "sha2", + "sha3", +] + +[[package]] +name = "lambdaworks-math" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2273,9 +2295,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libmimalloc-sys" -version = "0.1.38" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7bb23d733dfcc8af652a78b7bf232f0e967710d044732185e561e47c0336b6" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" dependencies = [ "cc", "libc", @@ -2360,9 +2382,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mimalloc" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9186d86b79b52f4a77af65604b51225e8db1d6ee7e3f41aec1e40829c71a176" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" dependencies = [ "libmimalloc-sys", ] @@ -2794,9 +2816,9 @@ dependencies = [ [[package]] name = "proptest" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bitflags 2.5.0", "num-traits 0.2.19", @@ -3436,7 +3458,7 @@ dependencies = [ "serde", "serde_json", "serde_with", - "starknet", + "starknet 0.11.0", "tempfile", "thiserror", "tokio", @@ -3465,7 +3487,7 @@ dependencies = [ "serde", "shellexpand", "slot", - "starknet", + "starknet 0.11.0", "thiserror", "tokio", "url", @@ -3531,14 +3553,29 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20b9a7b7bfd87287af85854f7458b8170ba6aa59c39113436532b7ff3d2fcbd8" dependencies = [ - "starknet-accounts", - "starknet-contract", - "starknet-core", + "starknet-accounts 0.9.0", + "starknet-contract 0.9.0", + "starknet-core 0.10.0", "starknet-crypto 0.6.2", "starknet-ff", - "starknet-macros", - "starknet-providers", - "starknet-signers", + "starknet-macros 0.1.7", + "starknet-providers 0.10.0", + "starknet-signers 0.8.0", +] + +[[package]] +name = "starknet" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e633a772f59214c296d5037c95c36b72792c9360323818da2b625c7b4ec4b49" +dependencies = [ + "starknet-accounts 0.10.0", + "starknet-contract 0.10.0", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", + "starknet-macros 0.2.0", + "starknet-providers 0.11.0", + "starknet-signers 0.9.0", ] [[package]] @@ -3549,9 +3586,24 @@ checksum = "2095d7584608ae1707bd1cf2889368ab3734d9f54e4fcef4765cba1f3b3f7618" dependencies = [ "async-trait", "auto_impl", - "starknet-core", - "starknet-providers", - "starknet-signers", + "starknet-core 0.10.0", + "starknet-providers 0.10.0", + "starknet-signers 0.8.0", + "thiserror", +] + +[[package]] +name = "starknet-accounts" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee8a6b588a22c7e79f5d8d4e33413387db63a8beb98be8610138541794cc0a5" +dependencies = [ + "async-trait", + "auto_impl", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", + "starknet-providers 0.11.0", + "starknet-signers 0.9.0", "thiserror", ] @@ -3564,9 +3616,24 @@ dependencies = [ "serde", "serde_json", "serde_with", - "starknet-accounts", - "starknet-core", - "starknet-providers", + "starknet-accounts 0.9.0", + "starknet-core 0.10.0", + "starknet-providers 0.10.0", + "thiserror", +] + +[[package]] +name = "starknet-contract" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5f91344f1e0b81873b6dc235c50ae4d084c6ea4dd4a1e3e27ad895803adb610" +dependencies = [ + "serde", + "serde_json", + "serde_with", + "starknet-accounts 0.10.0", + "starknet-core 0.11.1", + "starknet-providers 0.11.0", "thiserror", ] @@ -3588,6 +3655,24 @@ dependencies = [ "starknet-ff", ] +[[package]] +name = "starknet-core" +version = "0.11.1" +source = "git+https://github.com/kariy/starknet-rs?branch=dojo-patch#a8ed922690258ca218c80154007aa446ad03929c" +dependencies = [ + "base64 0.21.7", + "crypto-bigint", + "flate2", + "hex", + "serde", + "serde_json", + "serde_json_pythonic", + "serde_with", + "sha3", + "starknet-crypto 0.7.0", + "starknet-types-core", +] + [[package]] name = "starknet-crypto" version = "0.5.2" @@ -3602,7 +3687,7 @@ dependencies = [ "num-traits 0.2.19", "rfc6979", "sha2", - "starknet-crypto-codegen", + "starknet-crypto-codegen 0.3.3", "starknet-curve 0.3.0", "starknet-ff", "zeroize", @@ -3622,12 +3707,51 @@ dependencies = [ "num-traits 0.2.19", "rfc6979", "sha2", - "starknet-crypto-codegen", + "starknet-crypto-codegen 0.3.3", "starknet-curve 0.4.2", "starknet-ff", "zeroize", ] +[[package]] +name = "starknet-crypto" +version = "0.7.0" +source = "git+https://github.com/kariy/starknet-rs?branch=dojo-patch#a8ed922690258ca218c80154007aa446ad03929c" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "rfc6979", + "sha2", + "starknet-crypto-codegen 0.4.0 (git+https://github.com/kariy/starknet-rs?branch=dojo-patch)", + "starknet-curve 0.5.0 (git+https://github.com/kariy/starknet-rs?branch=dojo-patch)", + "starknet-types-core", + "zeroize", +] + +[[package]] +name = "starknet-crypto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2a821ad8d98c6c3e4d0e5097f3fe6e2ed120ada9d32be87cd1330c7923a2f0" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "rfc6979", + "sha2", + "starknet-crypto-codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-curve 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-types-core", + "zeroize", +] + [[package]] name = "starknet-crypto-codegen" version = "0.3.3" @@ -3639,6 +3763,27 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "starknet-crypto-codegen" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" +dependencies = [ + "starknet-curve 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-types-core", + "syn 2.0.66", +] + +[[package]] +name = "starknet-crypto-codegen" +version = "0.4.0" +source = "git+https://github.com/kariy/starknet-rs?branch=dojo-patch#a8ed922690258ca218c80154007aa446ad03929c" +dependencies = [ + "starknet-curve 0.5.0 (git+https://github.com/kariy/starknet-rs?branch=dojo-patch)", + "starknet-types-core", + "syn 2.0.66", +] + [[package]] name = "starknet-curve" version = "0.3.0" @@ -3657,6 +3802,23 @@ dependencies = [ "starknet-ff", ] +[[package]] +name = "starknet-curve" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56935b306dcf0b8f14bb2a1257164b8478bb8be4801dfae0923f5b266d1b457c" +dependencies = [ + "starknet-types-core", +] + +[[package]] +name = "starknet-curve" +version = "0.5.0" +source = "git+https://github.com/kariy/starknet-rs?branch=dojo-patch#a8ed922690258ca218c80154007aa446ad03929c" +dependencies = [ + "starknet-types-core", +] + [[package]] name = "starknet-ff" version = "0.3.7" @@ -3678,7 +3840,17 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95d549d3078bdbe775d0deaa8ddb57a19942989ce7c1f2dfd60beeb322bb4945" dependencies = [ - "starknet-core", + "starknet-core 0.10.0", + "syn 2.0.66", +] + +[[package]] +name = "starknet-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fe4f8d615329410578cbedcdbaa4a36c7f28f68c3f3ac56006cfbdaeaa2b41" +dependencies = [ + "starknet-core 0.11.1", "syn 2.0.66", ] @@ -3697,7 +3869,28 @@ dependencies = [ "serde", "serde_json", "serde_with", - "starknet-core", + "starknet-core 0.10.0", + "thiserror", + "url", +] + +[[package]] +name = "starknet-providers" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c85e0a0f4563ae95dfeae14ea0f0c70610efc0ec2462505c64eff5765e7b97" +dependencies = [ + "async-trait", + "auto_impl", + "ethereum-types", + "flate2", + "getrandom", + "log", + "reqwest", + "serde", + "serde_json", + "serde_with", + "starknet-core 0.11.1", "thiserror", "url", ] @@ -3713,11 +3906,42 @@ dependencies = [ "crypto-bigint", "eth-keystore", "rand", - "starknet-core", + "starknet-core 0.10.0", "starknet-crypto 0.6.2", "thiserror", ] +[[package]] +name = "starknet-signers" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17da2139119dbe3aacf1d5d4338798a5c489d17f424916ceb9d2efd83554f87" +dependencies = [ + "async-trait", + "auto_impl", + "crypto-bigint", + "eth-keystore", + "getrandom", + "rand", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", + "thiserror", +] + +[[package]] +name = "starknet-types-core" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" +dependencies = [ + "lambdaworks-crypto", + "lambdaworks-math", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "serde", +] + [[package]] name = "starknet_api" version = "0.10.0" @@ -4204,9 +4428,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unescaper" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0adf6ad32eb5b3cadff915f7b770faaac8f7ff0476633aa29eb0d9584d889d34" +checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" dependencies = [ "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 47443bd..549c0cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,21 @@ slot = { path = "slot" } anyhow = "1.0.75" axum = "0.6" -katana-primitives = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.3" } graphql_client = "0.13.0" hyper = "0.14.27" tokio = { version = "1.18.2", features = ["full", "sync"] } serde = "1" serde_json = "1" -starknet = "0.10.0" thiserror = "1.0.32" url = "2.2.2" rand = "0.8.4" + +starknet = "0.11.0" +starknet-types-core = "~0.1.4" + +[patch.crates-io] +# Remove this patch once the following PR is merged: +# +# To enable std feature on `starknet-types-core`. +# To re-export the entire `felt` module from `starknet-types-core`. +starknet-core = { git = "https://github.com/kariy/starknet-rs", branch = "dojo-patch" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 58220c3..f9efa70 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -17,7 +17,7 @@ dialoguer = "0.11.0" env_logger = "0.10" log = "0.4" graphql_client.workspace = true -katana-primitives.workspace = true +katana-primitives = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.3" } hyper.workspace = true tokio.workspace = true thiserror.workspace = true diff --git a/cli/src/command/auth/session.rs b/cli/src/command/auth/session.rs index c5ebeac..723dd1e 100644 --- a/cli/src/command/auth/session.rs +++ b/cli/src/command/auth/session.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use anyhow::{anyhow, ensure, Result}; use clap::Parser; use slot::session::{self, Policy}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider}; use url::Url; @@ -35,7 +35,7 @@ fn parse_policy(value: &str) -> Result { let mut parts = value.split(','); let target = parts.next().ok_or(anyhow!("missing target"))?.to_owned(); - let target = FieldElement::from_str(&target)?; + let target = Felt::from_str(&target)?; let method = parts.next().ok_or(anyhow!("missing method"))?.to_owned(); ensure!(parts.next().is_none(), " bruh"); @@ -43,7 +43,7 @@ fn parse_policy(value: &str) -> Result { Ok(Policy { target, method }) } -async fn get_network_chain_id(url: Url) -> Result { +async fn get_network_chain_id(url: Url) -> Result { let provider = JsonRpcClient::new(HttpTransport::new(url)); Ok(provider.chain_id().await?) } diff --git a/cli/src/command/deployments/accounts.rs b/cli/src/command/deployments/accounts.rs index a647700..9ad1e13 100644 --- a/cli/src/command/deployments/accounts.rs +++ b/cli/src/command/deployments/accounts.rs @@ -8,10 +8,11 @@ use katana_primitives::genesis::allocation::{ DevAllocationsGenerator, DevGenesisAccount, GenesisAccount, }; use katana_primitives::genesis::Genesis; +use katana_primitives::FieldElement; use slot::graphql::deployments::katana_accounts::KatanaAccountsDeploymentConfig::KatanaConfig; use slot::graphql::deployments::{katana_accounts::*, KatanaAccounts}; use slot::graphql::{GraphQLQuery, Response}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; use slot::api::Client; use slot::credential::Credentials; @@ -51,13 +52,23 @@ impl AccountsArgs { Some(accounts) => { let mut accounts_vec = Vec::new(); for account in accounts { + // TODO(kariy): update these after updating katana-primitives let address = ContractAddress::from( - FieldElement::from_hex_be(&account.address).unwrap(), + FieldElement::from_bytes_be( + &Felt::from_hex(&account.address).unwrap().to_bytes_be(), + ) + .unwrap(), ); - let public_key = - FieldElement::from_hex_be(&account.public_key).unwrap(); - let private_key = - FieldElement::from_hex_be(&account.private_key).unwrap(); + + let public_key = FieldElement::from_bytes_be( + &Felt::from_hex(&account.public_key).unwrap().to_bytes_be(), + ) + .unwrap(); + let private_key = FieldElement::from_bytes_be( + &Felt::from_hex(&account.private_key).unwrap().to_bytes_be(), + ) + .unwrap(); + let genesis_account = GenesisAccount { public_key, ..GenesisAccount::default() diff --git a/cli/src/command/deployments/services/torii.rs b/cli/src/command/deployments/services/torii.rs index 6d3c88d..f47369c 100644 --- a/cli/src/command/deployments/services/torii.rs +++ b/cli/src/command/deployments/services/torii.rs @@ -1,5 +1,5 @@ use clap::Args; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; #[derive(Clone, Debug, Args, serde::Serialize)] #[command(next_help_heading = "Torii create options")] @@ -16,7 +16,7 @@ pub struct ToriiCreateArgs { #[arg(long)] #[arg(value_name = "world")] #[arg(help = "World address.")] - pub world: FieldElement, + pub world: Felt, #[arg(short, long)] #[arg(help = "Specify a block to start indexing from.")] diff --git a/slot/src/account.rs b/slot/src/account.rs index 8d512e6..5a746fa 100644 --- a/slot/src/account.rs +++ b/slot/src/account.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_with::serde_as; use starknet::core::serde::unsigned_field_element::UfeHex; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] @@ -10,7 +10,7 @@ pub struct Account { pub name: Option, #[serde_as(as = "UfeHex")] #[serde(rename = "contractAddress")] - pub contract_address: FieldElement, + pub contract_address: Felt, pub credentials: AccountCredentials, } diff --git a/slot/src/graphql/auth/mod.rs b/slot/src/graphql/auth/mod.rs index a0dc2e2..afbb073 100644 --- a/slot/src/graphql/auth/mod.rs +++ b/slot/src/graphql/auth/mod.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use graphql_client::GraphQLQuery; use me::MeMe; -use starknet::core::types::{FieldElement, FromStrError}; +use starknet::core::types::{Felt, FromStrError}; use crate::account::{Account, AccountCredentials, WebAuthnCredential}; @@ -38,7 +38,7 @@ impl TryFrom for Account { id: value.id, name: value.name, credentials: value.credentials.try_into()?, - contract_address: FieldElement::from_str(&address)?, + contract_address: Felt::from_str(&address)?, }) } } @@ -89,7 +89,7 @@ mod tests { assert_eq!(account.id, "id"); assert_eq!(account.name, Some("name".to_string())); - assert_eq!(account.contract_address, FieldElement::ONE); + assert_eq!(account.contract_address, Felt::ONE); assert_eq!(account.credentials.webauthn.len(), 1); assert_eq!(account.credentials.webauthn[0].id, "id".to_string()); assert_eq!( diff --git a/slot/src/session.rs b/slot/src/session.rs index 4604992..01dfdd0 100644 --- a/slot/src/session.rs +++ b/slot/src/session.rs @@ -6,7 +6,7 @@ use axum::response::{IntoResponse, Response}; use axum::{extract::State, routing::post, Json, Router}; use hyper::StatusCode; use serde::{Deserialize, Serialize}; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; use tokio::sync::mpsc::{channel, Receiver, Sender}; use tower_http::cors::CorsLayer; use tracing::info; @@ -24,7 +24,7 @@ const SESSION_FILE_BASE_NAME: &str = "session.json"; #[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Policy { /// The target contract address. - pub target: FieldElement, + pub target: Felt, /// The method name. pub method: String, } @@ -44,8 +44,8 @@ pub struct SessionDetails { #[serde(rename_all = "camelCase")] pub struct SessionCredentials { /// The signing key of the session. - pub private_key: FieldElement, - pub authorization: Vec, + pub private_key: Felt, + pub authorization: Vec, } /// Retrieves the session for the given chain id of the currently authenticated user. @@ -55,7 +55,7 @@ pub struct SessionCredentials { /// /// This function will return an error if there is no authenticated user. /// -pub fn get(chain: FieldElement) -> Result, Error> { +pub fn get(chain: Felt) -> Result, Error> { get_at(utils::config_dir(), chain) } @@ -65,7 +65,7 @@ pub fn get(chain: FieldElement) -> Result, Error> { /// /// This function will return an error if there is no authenticated user. /// -pub fn store(chain: FieldElement, session: &SessionDetails) -> Result { +pub fn store(chain: Felt, session: &SessionDetails) -> Result { store_at(utils::config_dir(), chain, session) } @@ -92,7 +92,7 @@ where /// Get the session token of the chain id `chain` for the currently authenticated user. It will /// use `config_dir` as the root path to look for the session file. -fn get_at

(config_dir: P, chain: FieldElement) -> Result, Error> +fn get_at

(config_dir: P, chain: Felt) -> Result, Error> where P: AsRef, { @@ -113,11 +113,7 @@ where /// Stores the session token of the chain id `chain` for the currently authenticated user. It will /// use `config_dir` as the root path to store the session file. -fn store_at

( - config_dir: P, - chain: FieldElement, - session: &SessionDetails, -) -> Result +fn store_at

(config_dir: P, chain: Felt, session: &SessionDetails) -> Result where P: AsRef, { @@ -260,7 +256,7 @@ fn callback_server(result_sender: Sender) -> anyhow::Result PathBuf { +fn get_user_relative_file_path(username: &str, chain_id: Felt) -> PathBuf { let file_name = format!("{chain_id:#x}-{}", SESSION_FILE_BASE_NAME); PathBuf::from(username).join(file_name) } @@ -273,7 +269,7 @@ mod tests { use crate::error::Error::Unauthorized; use crate::session::{get_at, get_user_relative_file_path, store_at, SessionDetails}; use crate::utils; - use starknet::{core::types::FieldElement, macros::felt}; + use starknet::{core::types::Felt, macros::felt}; use std::ffi::OsStr; use std::path::{Component, Path}; use tokio::sync::mpsc::channel; @@ -317,7 +313,7 @@ mod tests { #[test] fn get_session_unauthenticated() { - let chain = FieldElement::ONE; + let chain = Felt::ONE; let err = get(chain).unwrap_err(); let Unauthorized = err else { panic!("expected Unauthorized error, got {err:?}");