Skip to content

Commit

Permalink
Revert "Use serde_as hex str for felts (#388)"
Browse files Browse the repository at this point in the history
This reverts commit eb48404.
  • Loading branch information
broody committed Jun 19, 2024
1 parent 031696d commit e62ba4f
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 152 deletions.
1 change: 0 additions & 1 deletion packages/account-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ starknet = "0.10"
serde = "1.0.197"
serde-wasm-bindgen = "0.6.5"
serde_json = "1.0.114"
serde_with = "2.3"
url = "2.3.1"
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.37"
Expand Down
116 changes: 32 additions & 84 deletions packages/account-wasm/pkg/account_wasm_bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ function getFloat64Memory0() {
return cachedFloat64Memory0;
}

let cachedBigInt64Memory0 = null;

function getBigInt64Memory0() {
if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {
cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);
}
return cachedBigInt64Memory0;
}

function debugString(val) {
// primitive types
const type = typeof val;
Expand Down Expand Up @@ -237,8 +228,8 @@ function makeMutClosure(arg0, arg1, dtor, f) {
CLOSURE_DTORS.register(real, state, state);
return real;
}
function __wbg_adapter_48(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h62caa38513d55a9d(arg0, arg1, addHeapObject(arg2));
function __wbg_adapter_40(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2518f74d6f823509(arg0, arg1, addHeapObject(arg2));
}

let cachedUint32Memory0 = null;
Expand Down Expand Up @@ -267,8 +258,8 @@ function handleError(f, args) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
}
function __wbg_adapter_169(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h36eeb9bb8ab1ea47(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_155(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h6a3c60c89c1d3e00(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}

const CartridgeAccountFinalization = (typeof FinalizationRegistry === 'undefined')
Expand Down Expand Up @@ -425,62 +416,34 @@ export function __wbindgen_string_get(arg0, arg1) {
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
};

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_is_bigint(arg0) {
const ret = typeof(getObject(arg0)) === 'bigint';
return ret;
};

export function __wbindgen_bigint_from_u64(arg0) {
const ret = BigInt.asUintN(64, arg0);
return addHeapObject(ret);
};

export function __wbindgen_jsval_eq(arg0, arg1) {
const ret = getObject(arg0) === getObject(arg1);
return ret;
};

export function __wbindgen_boolean_get(arg0) {
const v = getObject(arg0);
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
return ret;
};

export function __wbindgen_number_get(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'number' ? obj : undefined;
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
};

export function __wbindgen_is_object(arg0) {
const val = getObject(arg0);
const ret = typeof(val) === 'object' && val !== null;
return ret;
};

export function __wbindgen_in(arg0, arg1) {
const ret = getObject(arg0) in getObject(arg1);
export function __wbindgen_is_undefined(arg0) {
const ret = getObject(arg0) === undefined;
return ret;
};

export function __wbindgen_bigint_from_i64(arg0) {
const ret = arg0;
return addHeapObject(ret);
export function __wbindgen_in(arg0, arg1) {
const ret = getObject(arg0) in getObject(arg1);
return ret;
};

export function __wbindgen_is_undefined(arg0) {
const ret = getObject(arg0) === undefined;
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;
};

Expand All @@ -494,6 +457,19 @@ export function __wbindgen_jsval_loose_eq(arg0, arg1) {
return ret;
};

export function __wbindgen_boolean_get(arg0) {
const v = getObject(arg0);
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
return ret;
};

export function __wbindgen_number_get(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'number' ? obj : undefined;
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
};

export function __wbindgen_number_new(arg0) {
const ret = arg0;
return addHeapObject(ret);
Expand Down Expand Up @@ -831,35 +807,14 @@ export function __wbg_call_b3ca7c6051f9bec1() { return handleError(function (arg
return addHeapObject(ret);
}, arguments) };

export function __wbg_instanceof_Map_87917e0a7aaf4012(arg0) {
let result;
try {
result = getObject(arg0) instanceof Map;
} catch (_) {
result = false;
}
const ret = result;
return ret;
};

export function __wbg_isSafeInteger_f7b04ef02296c4d2(arg0) {
const ret = Number.isSafeInteger(getObject(arg0));
return ret;
};

export function __wbg_entries_95cc2c823b285a09(arg0) {
const ret = Object.entries(getObject(arg0));
return addHeapObject(ret);
};

export function __wbg_new_81740750da40724f(arg0, arg1) {
try {
var state0 = {a: arg0, b: arg1};
var cb0 = (arg0, arg1) => {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_169(a, state0.b, arg0, arg1);
return __wbg_adapter_155(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
Expand Down Expand Up @@ -946,13 +901,6 @@ export function __wbg_stringify_8887fe74e1c50d81() { return handleError(function
return addHeapObject(ret);
}, arguments) };

export function __wbindgen_bigint_get_as_i64(arg0, arg1) {
const v = getObject(arg1);
const ret = typeof(v) === 'bigint' ? v : undefined;
getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
};

export function __wbindgen_debug_string(arg0, arg1) {
const ret = debugString(getObject(arg1));
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
Expand All @@ -970,8 +918,8 @@ export function __wbindgen_memory() {
return addHeapObject(ret);
};

export function __wbindgen_closure_wrapper1479(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 463, __wbg_adapter_48);
export function __wbindgen_closure_wrapper1459(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 466, __wbg_adapter_40);
return addHeapObject(ret);
};

Binary file modified packages/account-wasm/pkg/account_wasm_bg.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function cartridgeaccount_signMessage(a: number, b: number, c: number): n
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h62caa38513d55a9d(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2518f74d6f823509(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_exn_store(a: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h36eeb9bb8ab1ea47(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h6a3c60c89c1d3e00(a: number, b: number, c: number, d: number): void;
30 changes: 15 additions & 15 deletions packages/account-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ mod utils;

use std::str::FromStr;

use account_sdk::account::outside_execution::OutsideExecutionAccount;
use account_sdk::account::outside_execution::{
OutsideExecution, OutsideExecutionAccount, OutsideExecutionCaller,
};
use account_sdk::account::session::hash::{AllowedMethod, Session};
use account_sdk::account::session::SessionAccount;
use account_sdk::account::{AccountHashSigner, CartridgeGuardianAccount, MessageSignerAccount};
Expand All @@ -24,9 +26,7 @@ use starknet::{
core::types::FieldElement,
providers::{jsonrpc::HttpTransport, JsonRpcClient},
};
use types::call::JsCall;
use types::invocation::JsInvocationsDetails;
use types::outside_execution::JsOutsideExecution;
use types::session::{JsCredentials, JsSession};
use url::Url;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -161,31 +161,31 @@ impl CartridgeAccount {
) -> Result<JsValue> {
utils::set_panic_hook();

let outside = JsOutsideExecution {
caller: short_string!("ANY_CALLER"),
let calls = calls
.into_iter()
.map(Call::try_from_js_value)
.collect::<Result<Vec<Call>>>()?;

let outside = OutsideExecution {
caller: OutsideExecutionCaller::Any,
calls,
execute_after: 0_u64,
execute_before: 3000000000_u64,
calls: calls
.into_iter()
.map(JsCall::try_from)
.collect::<Result<Vec<JsCall>>>()?,
nonce: SigningKey::from_random().secret_scalar(),
};

let signed = if let Some(session_details) = from_value(session_details)? {
self.session_account(session_details)
.await?
.sign_outside_execution(outside.clone().try_into()?)
.sign_outside_execution(outside.clone())
.await?
} else {
self.account
.sign_outside_execution(outside.clone().try_into()?)
.await?
self.account.sign_outside_execution(outside.clone()).await?
};

let response = PaymasterRequest::send(
self.rpc_url.clone(),
outside,
outside.into(),
self.account.address(),
self.account.chain_id(),
signed.signature,
Expand Down Expand Up @@ -231,7 +231,7 @@ impl CartridgeAccount {
self.account.address(),
self.account.chain_id(),
details.credentials.authorization,
session,
session.clone(),
))
}
}
8 changes: 0 additions & 8 deletions packages/account-wasm/src/paymaster.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::to_value;
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::types::FieldElement;
use url::Url;
use wasm_bindgen::JsError;
Expand All @@ -20,23 +18,17 @@ struct JsonRpcRequest<T> {
params: T,
}

#[serde_as]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct OutsideExecutionParams {
#[serde_as(as = "UfeHex")]
address: FieldElement,
#[serde_as(as = "UfeHex")]
chain_id: FieldElement,
outside_execution: JsOutsideExecution,
#[serde_as(as = "Vec<UfeHex>")]
signature: Vec<FieldElement>,
}

#[serde_as]
#[derive(Debug, Deserialize, Serialize)]
pub struct PaymasterResponse {
#[serde_as(as = "UfeHex")]
transaction_hash: FieldElement,
}

Expand Down
39 changes: 24 additions & 15 deletions packages/account-wasm/src/types/call.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::{
accounts::Call,
core::{types::FieldElement, utils::get_selector_from_name},
};
use starknet::{accounts::Call, core::types::FieldElement};
use std::str::FromStr;
use wasm_bindgen::prelude::*;

use super::TryFromJsValue;

#[serde_as]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JsCall {
#[serde_as(as = "UfeHex")]
pub contract_address: FieldElement,
pub entrypoint: String,
#[serde_as(as = "Vec<UfeHex>")]
pub to: FieldElement,
pub selector: FieldElement,
pub calldata: Vec<FieldElement>,
}

impl TryFrom<JsCall> for Call {
type Error = JsError;

fn try_from(value: JsCall) -> Result<Self, Self::Error> {
let calldata = value
.calldata
.iter()
.map(|c| FieldElement::from_str(&c.to_string()))
.collect::<Result<Vec<FieldElement>, _>>()?;

Ok(Call {
to: value.contract_address,
selector: get_selector_from_name(&value.entrypoint)?,
calldata: value.calldata,
to: value.to,
selector: value.selector,
calldata,
})
}
}
Expand All @@ -40,6 +39,16 @@ impl TryFrom<JsValue> for JsCall {
}
}

impl From<Call> for JsCall {
fn from(value: Call) -> Self {
JsCall {
to: value.to,
selector: value.selector,
calldata: value.calldata,
}
}
}

impl TryFromJsValue<Call> for Call {
fn try_from_js_value(value: JsValue) -> Result<Self, JsError> {
let js_call: JsCall = value.try_into()?;
Expand Down
Loading

0 comments on commit e62ba4f

Please sign in to comment.