diff --git a/packages/account-wasm/pkg/account_wasm_bg.js b/packages/account-wasm/pkg/account_wasm_bg.js index 519eb8ee8..e1feb6033 100644 --- a/packages/account-wasm/pkg/account_wasm_bg.js +++ b/packages/account-wasm/pkg/account_wasm_bg.js @@ -443,6 +443,11 @@ export function __wbindgen_object_drop_ref(arg0) { takeObject(arg0); }; +export function __wbindgen_string_new(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); +}; + export function __wbindgen_error_new(arg0, arg1) { const ret = new Error(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); @@ -477,6 +482,16 @@ export function __wbindgen_jsval_eq(arg0, arg1) { return ret; }; +export function __wbindgen_cb_drop(arg0) { + const obj = takeObject(arg0).original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; +}; + export function __wbindgen_boolean_get(arg0) { const v = getObject(arg0); const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; @@ -511,16 +526,6 @@ export function __wbindgen_is_undefined(arg0) { return ret; }; -export function __wbindgen_cb_drop(arg0) { - const obj = takeObject(arg0).original; - if (obj.cnt-- == 1) { - obj.a = 0; - return true; - } - const ret = false; - return ret; -}; - export function __wbindgen_jsval_loose_eq(arg0, arg1) { const ret = getObject(arg0) == getObject(arg1); return ret; @@ -531,11 +536,6 @@ export function __wbindgen_number_new(arg0) { return addHeapObject(ret); }; -export function __wbindgen_string_new(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); -}; - export function __wbg_getwithrefkey_edc2c8960f0f1191(arg0, arg1) { const ret = getObject(arg0)[getObject(arg1)]; return addHeapObject(ret); @@ -1002,8 +1002,8 @@ export function __wbindgen_memory() { return addHeapObject(ret); }; -export function __wbindgen_closure_wrapper1519(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 512, __wbg_adapter_48); +export function __wbindgen_closure_wrapper1521(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 516, __wbg_adapter_48); return addHeapObject(ret); }; diff --git a/packages/account-wasm/pkg/account_wasm_bg.wasm b/packages/account-wasm/pkg/account_wasm_bg.wasm index 5c5398f73..39f9ab20d 100644 Binary files a/packages/account-wasm/pkg/account_wasm_bg.wasm and b/packages/account-wasm/pkg/account_wasm_bg.wasm differ diff --git a/packages/account-wasm/src/lib.rs b/packages/account-wasm/src/lib.rs index 53f049861..a78f0e676 100644 --- a/packages/account-wasm/src/lib.rs +++ b/packages/account-wasm/src/lib.rs @@ -48,8 +48,9 @@ use types::invocation::JsInvocationsDetails; use types::outside_execution::JsOutsideExecution; use types::session::{JsCredentials, JsSession}; use url::Url; -use utils::{policies_match, set_panic_hook}; +use utils::{calculate_contract_address, policies_match, set_panic_hook}; use wasm_bindgen::prelude::*; +use web_sys::console; use crate::types::TryFromJsValue; @@ -61,6 +62,8 @@ pub struct CartridgeAccount { device_signer: DeviceSigner, username: String, rpc_url: Url, + rp_id: String, + origin: String, } #[wasm_bindgen] @@ -118,6 +121,8 @@ impl CartridgeAccount { device_signer, username, rpc_url, + rp_id, + origin, }) } @@ -315,6 +320,18 @@ impl CartridgeAccount { constructor_calldata[0] = Felt::TWO; // incorrect signer enum from serialization constructor_calldata.push(Felt::ONE); // no guardian + let address = calculate_contract_address( + starknetutils::cairo_short_string_to_felt(&self.username)?, + Felt::from_str(ACCOUNT_CLASS_HASH)?, + &constructor_calldata, + ); + console::log_1(&format!("constructor {:#?}", constructor_calldata).into()); + console::log_1(&format!("deployment address: {:#x}", address).into()); + console::log_1(&format!("backend address: {:#x}", self.account.address()).into()); + console::log_1(&format!("rp_id: {}", self.rp_id).into()); + console::log_1(&format!("origin: {}", self.origin).into()); + console::log_1(&format!("username: {}", self.username).into()); + let factory = CartridgeAccountFactory::new( Felt::from_str(ACCOUNT_CLASS_HASH)?, self.account.chain_id(), diff --git a/packages/account-wasm/src/utils.rs b/packages/account-wasm/src/utils.rs index 038769048..7124e64d0 100644 --- a/packages/account-wasm/src/utils.rs +++ b/packages/account-wasm/src/utils.rs @@ -1,11 +1,26 @@ use std::collections::HashMap; use starknet::accounts::Call; -use starknet::core::types::Felt; +use starknet::core::crypto::compute_hash_on_elements; +use starknet::core::types::{Felt, NonZeroFelt}; use starknet::core::utils::get_selector_from_name; use crate::types::policy::JsPolicy; +const PREFIX_CONTRACT_ADDRESS: Felt = Felt::from_raw([ + 533439743893157637, + 8635008616843941496, + 17289941567720117366, + 3829237882463328880, +]); + +const ADDR_BOUND: NonZeroFelt = NonZeroFelt::from_raw([ + 576459263475590224, + 18446744073709255680, + 160989183, + 18446743986131443745, +]); + pub fn set_panic_hook() { // When the `console_error_panic_hook` feature is enabled, we can call the // `set_panic_hook` function at least once during initialization, and then @@ -32,3 +47,18 @@ pub fn policies_match(calls: &[Call], policies: &[JsPolicy]) -> bool { .iter() .all(|call| policy_map.contains_key(&call.selector)) } + +pub fn calculate_contract_address( + salt: Felt, + class_hash: Felt, + constructor_calldata: &[Felt], +) -> Felt { + compute_hash_on_elements(&[ + PREFIX_CONTRACT_ADDRESS, + Felt::ZERO, + salt, + class_hash, + compute_hash_on_elements(constructor_calldata), + ]) + .mod_floor(&ADDR_BOUND) +} diff --git a/packages/keychain/src/components/connect/Login.tsx b/packages/keychain/src/components/connect/Login.tsx index 081bf0511..d81746c59 100644 --- a/packages/keychain/src/components/connect/Login.tsx +++ b/packages/keychain/src/components/connect/Login.tsx @@ -127,7 +127,7 @@ export function Login({ {...field} onChange={(e) => { setError(undefined); - field.onChange(e); + field.onChange(e.target.value.toLowerCase()); }} autoFocus placeholder="Username" diff --git a/packages/keychain/src/components/connect/Signup.tsx b/packages/keychain/src/components/connect/Signup.tsx index a6e815794..84027ea84 100644 --- a/packages/keychain/src/components/connect/Signup.tsx +++ b/packages/keychain/src/components/connect/Signup.tsx @@ -173,7 +173,7 @@ function Form({ isSlot, onLogin, onSuccess }: SignupProps) { error={meta.error || errors?.username} onChange={(e) => { setError(undefined); - field.onChange(e); + field.onChange(e.target.value.toLowerCase()); }} onClear={() => { setError(undefined);