diff --git a/Cargo.lock b/Cargo.lock index edd4c36a60..86d7175cb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,14 +15,14 @@ dependencies = [ [[package]] name = "account_sdk" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/controller?rev=fea57f1#fea57f16ba2c52e89311787aaaea8875b35e38f4" +source = "git+https://github.com/cartridge-gg/controller#61d2fd0cd856daa01b2da52b762368542c03da6f" dependencies = [ "anyhow", "async-trait", "auto_impl", "base64 0.22.1", "base64urlsafedata", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "coset", "ecdsa", "futures", @@ -37,6 +37,7 @@ dependencies = [ "primitive-types", "reqwest 0.11.27", "serde", + "serde-wasm-bindgen", "serde_cbor_2", "serde_json", "serde_with 3.9.0", @@ -47,6 +48,7 @@ dependencies = [ "thiserror", "tokio", "toml 0.8.19", + "tsify-next", "u256-literal", "url", "urlencoding", @@ -2277,10 +2279,35 @@ source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.1#db76fb849d1b7f3 dependencies = [ "anyhow", "async-trait", - "cainome-cairo-serde", - "cainome-parser", - "cainome-rs", - "cainome-rs-macro", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "camino", + "clap", + "clap_complete", + "convert_case 0.6.0", + "serde", + "serde_json", + "starknet 0.12.0", + "starknet-types-core", + "thiserror", + "tracing", + "tracing-subscriber", + "url", +] + +[[package]] +name = "cainome" +version = "0.2.3" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +dependencies = [ + "anyhow", + "async-trait", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "camino", "clap", "clap_complete", @@ -2305,6 +2332,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cainome-cairo-serde" +version = "0.1.0" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +dependencies = [ + "serde", + "starknet 0.12.0", + "thiserror", +] + [[package]] name = "cainome-parser" version = "0.1.0" @@ -2318,14 +2355,45 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cainome-parser" +version = "0.1.0" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +dependencies = [ + "convert_case 0.6.0", + "quote", + "serde_json", + "starknet 0.12.0", + "syn 2.0.77", + "thiserror", +] + [[package]] name = "cainome-rs" version = "0.1.0" source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.1#db76fb849d1b7f3e9a2e943868bcd8616cf72e90" dependencies = [ "anyhow", - "cainome-cairo-serde", - "cainome-parser", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "camino", + "prettyplease 0.2.22", + "proc-macro2", + "quote", + "serde_json", + "starknet 0.12.0", + "syn 2.0.77", + "thiserror", +] + +[[package]] +name = "cainome-rs" +version = "0.1.0" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +dependencies = [ + "anyhow", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "camino", "prettyplease 0.2.22", "proc-macro2", @@ -2342,9 +2410,27 @@ version = "0.1.0" source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.1#db76fb849d1b7f3e9a2e943868bcd8616cf72e90" dependencies = [ "anyhow", - "cainome-cairo-serde", - "cainome-parser", - "cainome-rs", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", + "proc-macro-error", + "proc-macro2", + "quote", + "serde_json", + "starknet 0.12.0", + "syn 2.0.77", + "thiserror", +] + +[[package]] +name = "cainome-rs-macro" +version = "0.1.0" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +dependencies = [ + "anyhow", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "proc-macro-error", "proc-macro2", "quote", @@ -4389,7 +4475,7 @@ version = "1.0.0-alpha.13" dependencies = [ "assert_matches", "async-trait", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "camino", "chrono", "convert_case 0.6.0", @@ -4514,7 +4600,7 @@ dependencies = [ name = "dojo-types" version = "1.0.0-alpha.13" dependencies = [ - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "crypto-bigint", "hex", "itertools 0.12.1", @@ -4550,7 +4636,7 @@ dependencies = [ "assert_fs", "assert_matches", "async-trait", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "cairo-lang-filesystem", "cairo-lang-project", "cairo-lang-starknet", @@ -8045,7 +8131,7 @@ dependencies = [ "alloy-primitives", "anyhow", "assert_matches", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "dojo-metrics", "dojo-test-utils", "dojo-utils", @@ -12347,6 +12433,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -12728,8 +12825,8 @@ dependencies = [ [[package]] name = "slot" -version = "0.16.0" -source = "git+https://github.com/cartridge-gg/slot?rev=630ed37#630ed377d55662847d2219c8662f6d0867f3e2fb" +version = "0.17.0" +source = "git+https://github.com/cartridge-gg/slot?rev=544cbc6#544cbc60162795ca83377c8b1d959bae6ba0e073" dependencies = [ "account_sdk", "anyhow", @@ -12866,7 +12963,7 @@ dependencies = [ "assert_fs", "async-trait", "bigdecimal", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "cairo-lang-compiler", "cairo-lang-defs", "cairo-lang-filesystem", @@ -12930,7 +13027,7 @@ dependencies = [ "assert_fs", "async-trait", "bigdecimal", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "cairo-lang-compiler", "cairo-lang-defs", "cairo-lang-filesystem", @@ -14536,7 +14633,7 @@ dependencies = [ "async-trait", "base64 0.21.7", "bitflags 2.6.0", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "camino", "chrono", "crypto-bigint", @@ -14574,7 +14671,7 @@ dependencies = [ "async-recursion", "async-trait", "base64 0.21.7", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "camino", "chrono", "convert_case 0.6.0", @@ -14611,7 +14708,7 @@ dependencies = [ name = "torii-grpc" version = "1.0.0-alpha.13" dependencies = [ - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "camino", "crypto-bigint", "dojo-test-utils", @@ -14655,7 +14752,7 @@ name = "torii-relay" version = "1.0.0-alpha.13" dependencies = [ "anyhow", - "cainome", + "cainome 0.2.3 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "chrono", "crypto-bigint", "dojo-types", @@ -14949,6 +15046,31 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tsify-next" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4a645dca4ee0800f5ab60ce166deba2db6a0315de795a2691e138a3d55d756" +dependencies = [ + "gloo-utils 0.2.0", + "serde", + "serde_json", + "tsify-next-macros", + "wasm-bindgen", +] + +[[package]] +name = "tsify-next-macros" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d5c06f8a51d759bb58129e30b2631739e7e1e4579fad1f30ac09a6c88e488a6" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.77", +] + [[package]] name = "tungstenite" version = "0.21.0" diff --git a/Cargo.toml b/Cargo.toml index fd827c9873..2beaae44eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,7 +230,7 @@ alloy-sol-types = { version = "0.8.3", default-features = false } criterion = "0.5.1" # Slot integration. Dojo don't need to manually include `account_sdk` as dependency as `slot` already re-exports it. -slot = { git = "https://github.com/cartridge-gg/slot", rev = "630ed37" } +slot = { git = "https://github.com/cartridge-gg/slot", rev = "544cbc6" } alloy-contract = { version = "0.3", default-features = false } alloy-json-rpc = { version = "0.3", default-features = false } diff --git a/bin/sozo/src/commands/options/account/controller.rs b/bin/sozo/src/commands/options/account/controller.rs index 8e85dd7822..408570914d 100644 --- a/bin/sozo/src/commands/options/account/controller.rs +++ b/bin/sozo/src/commands/options/account/controller.rs @@ -8,7 +8,7 @@ use dojo_world::contracts::naming::get_name_from_tag; use dojo_world::manifest::{BaseManifest, Class, DojoContract, Manifest}; use dojo_world::migration::strategy::generate_salt; use scarb::core::Config; -use slot::account_sdk::account::session::hash::{AllowedMethod, ProvedMethod}; +use slot::account_sdk::account::session::hash::{Policy, ProvedPolicy}; use slot::account_sdk::account::session::merkle::MerkleTree; use slot::account_sdk::account::session::SessionAccount; use slot::session::{FullSessionInfo, PolicyMethod}; @@ -74,7 +74,7 @@ where // Check if the session exists, if not create a new one let session_details = match slot::session::get(chain_id)? { Some(session) => { - trace!(expires_at = %session.session.expires_at, policies = session.session.allowed_methods.len(), "Found existing session."); + trace!(expires_at = %session.session.expires_at, policies = session.session.policies.len(), "Found existing session."); let policies = collect_policies(world_addr_or_name, contract_address, config)?; // check if the policies have changed @@ -85,7 +85,7 @@ where } else { trace!( new_policies = policies.len(), - existing_policies = session.session.allowed_methods.len(), + existing_policies = session.session.policies.len(), "Policies have changed. Creating new session." ); @@ -113,26 +113,25 @@ where // This function would compute the merkle root of the new policies and compare it with the root in // the existing SessionMetadata. fn is_equal_to_existing(new_policies: &[PolicyMethod], session_info: &FullSessionInfo) -> bool { - let allowed_methods = new_policies + let new_policies = new_policies .iter() - .map(|p| AllowedMethod::new(p.target, get_selector_from_name(&p.method).unwrap())) - .collect::>(); + .map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap())) + .collect::>(); - // Copied from somewhere - let hashes = allowed_methods.iter().map(AllowedMethod::as_merkle_leaf).collect::>(); + // Copied from Session::new + let hashes = new_policies.iter().map(Policy::as_merkle_leaf).collect::>(); - let allowed_methods = allowed_methods + let new_policies = new_policies .into_iter() .enumerate() - .map(|(i, method)| ProvedMethod { - method, + .map(|(i, policy)| ProvedPolicy { + policy, proof: MerkleTree::compute_proof(hashes.clone(), i), }) - .collect::>(); + .collect::>(); - let root = MerkleTree::compute_root(hashes[0], allowed_methods[0].proof.clone()); - - root == session_info.session.allowed_methods_root + let new_policies_root = MerkleTree::compute_root(hashes[0], new_policies[0].proof.clone()); + new_policies_root == session_info.session.authorization_root } /// Policies are the building block of a session key. It's what defines what methods are allowed for