Skip to content

Commit

Permalink
add back logs
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Jul 16, 2024
1 parent 96393e2 commit 59a7e97
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
34 changes: 17 additions & 17 deletions packages/account-wasm/pkg/account_wasm_bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
};

Binary file modified packages/account-wasm/pkg/account_wasm_bg.wasm
Binary file not shown.
19 changes: 18 additions & 1 deletion packages/account-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -61,6 +62,8 @@ pub struct CartridgeAccount {
device_signer: DeviceSigner,
username: String,
rpc_url: Url,
rp_id: String,
origin: String,
}

#[wasm_bindgen]
Expand Down Expand Up @@ -118,6 +121,8 @@ impl CartridgeAccount {
device_signer,
username,
rpc_url,
rp_id,
origin,
})
}

Expand Down Expand Up @@ -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(),
Expand Down
32 changes: 31 additions & 1 deletion packages/account-wasm/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

0 comments on commit 59a7e97

Please sign in to comment.