diff --git a/packages/account-wasm/pkg/account_wasm.d.ts b/packages/account-wasm/pkg/account_wasm.d.ts index a6974162e..0bc2599c8 100644 --- a/packages/account-wasm/pkg/account_wasm.d.ts +++ b/packages/account-wasm/pkg/account_wasm.d.ts @@ -1,10 +1,5 @@ /* tslint:disable */ /* eslint-disable */ -export interface JsInvocationsDetails { - nonce: Felt; - maxFee: Felt; -} - export interface JsOutsideExecution { caller: Felt; executeBefore: number; @@ -13,10 +8,9 @@ export interface JsOutsideExecution { nonce: Felt; } -export interface JsPolicy { - target: string; - method: string; -} +export type Felts = JsFelt[]; + +export type JsFelt = Felt; export interface JsCall { contractAddress: Felt; @@ -24,13 +18,19 @@ export interface JsCall { calldata: Felt[]; } -export interface JsEstimateFeeDetails { +export interface JsInvocationsDetails { nonce: Felt; + maxFee: Felt; } -export type Felts = JsFelt[]; +export interface JsPolicy { + target: string; + method: string; +} -export type JsFelt = Felt; +export interface JsEstimateFeeDetails { + nonce: Felt; +} export interface JsSession { policies: JsPolicy[]; @@ -115,13 +115,6 @@ export class CartridgeAccount { */ sessionJson(): any; /** -* @param {(JsPolicy)[]} policies -* @param {bigint} expires_at -* @param {any} external_account -* @returns {any} -*/ - static registerSessionCalldata(policies: (JsPolicy)[], expires_at: bigint, external_account: any): any; -/** */ revokeSession(): void; /** @@ -139,19 +132,14 @@ export class CartridgeAccount { */ delegateAccount(): Promise; /** -* @param {any} salt -* @param {any} external_owner -* @returns {any} -*/ - static getUdcDeployedAddress(salt: any, external_owner: any): any; -/** -* @returns {any} -*/ - static getAccountClassHash(): any; -/** +* @param {any} owner +* @param {any} username +* @param {(JsPolicy)[]} policies +* @param {bigint} expires_at +* @param {bigint} initial_deposit * @returns {any} */ - static getUdcAddress(): any; + static externalDeploymentCalls(owner: any, username: any, policies: (JsPolicy)[], expires_at: bigint, initial_deposit: bigint): any; } /** */ diff --git a/packages/account-wasm/pkg/account_wasm.js b/packages/account-wasm/pkg/account_wasm.js index 99312ca8c..235ccaf9b 100644 --- a/packages/account-wasm/pkg/account_wasm.js +++ b/packages/account-wasm/pkg/account_wasm.js @@ -1,3 +1,4 @@ + import * as wasm from "./account_wasm_bg.wasm"; import { __wbg_set_wasm } from "./account_wasm_bg.js"; __wbg_set_wasm(wasm); diff --git a/packages/account-wasm/pkg/account_wasm_bg.js b/packages/account-wasm/pkg/account_wasm_bg.js index 605b3c8b4..e81394a98 100644 --- a/packages/account-wasm/pkg/account_wasm_bg.js +++ b/packages/account-wasm/pkg/account_wasm_bg.js @@ -35,13 +35,13 @@ function takeObject(idx) { let WASM_VECTOR_LEN = 0; -let cachedUint8Memory0 = null; +let cachedUint8ArrayMemory0 = null; -function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } - return cachedUint8Memory0; + return cachedUint8ArrayMemory0; } const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; @@ -66,7 +66,7 @@ function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } @@ -74,7 +74,7 @@ function passStringToWasm0(arg, malloc, realloc) { let len = arg.length; let ptr = malloc(len, 1) >>> 0; - const mem = getUint8Memory0(); + const mem = getUint8ArrayMemory0(); let offset = 0; @@ -89,7 +89,7 @@ function passStringToWasm0(arg, malloc, realloc) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; @@ -104,13 +104,13 @@ function isLikeNone(x) { return x === undefined || x === null; } -let cachedInt32Memory0 = null; +let cachedDataViewMemory0 = null; -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } - return cachedInt32Memory0; + return cachedDataViewMemory0; } const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; @@ -121,16 +121,7 @@ cachedTextDecoder.decode(); function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -let cachedFloat64Memory0 = null; - -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function debugString(val) { @@ -229,23 +220,14 @@ function makeMutClosure(arg0, arg1, dtor, f) { return real; } function __wbg_adapter_44(arg0, arg1, arg2) { - wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h3f3a3deef6344805(arg0, arg1, addHeapObject(arg2)); -} - -let cachedUint32Memory0 = null; - -function getUint32Memory0() { - if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { - cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); - } - return cachedUint32Memory0; + wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha5780fd1342283cf(arg0, arg1, addHeapObject(arg2)); } function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; - const mem = getUint32Memory0(); + const mem = getDataViewMemory0(); for (let i = 0; i < array.length; i++) { - mem[ptr / 4 + i] = addHeapObject(array[i]); + mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true); } WASM_VECTOR_LEN = array.length; return ptr; @@ -258,13 +240,13 @@ function handleError(f, args) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } -function __wbg_adapter_177(arg0, arg1, arg2, arg3) { - wasm.wasm_bindgen__convert__closures__invoke2_mut__hbcb2218b5bd12b96(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); +function __wbg_adapter_186(arg0, arg1, arg2, arg3) { + wasm.wasm_bindgen__convert__closures__invoke2_mut__h11630e69f33a5871(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); } const CartridgeAccountFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } - : new FinalizationRegistry(ptr => wasm.__wbg_cartridgeaccount_free(ptr >>> 0)); + : new FinalizationRegistry(ptr => wasm.__wbg_cartridgeaccount_free(ptr >>> 0, 1)); /** */ export class CartridgeAccount { @@ -286,7 +268,7 @@ export class CartridgeAccount { free() { const ptr = this.__destroy_into_raw(); - wasm.__wbg_cartridgeaccount_free(ptr); + wasm.__wbg_cartridgeaccount_free(ptr, 0); } /** * Creates a new `CartridgeAccount` instance. @@ -327,9 +309,9 @@ export class CartridgeAccount { const ptr5 = passStringToWasm0(public_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len5 = WASM_VECTOR_LEN; wasm.cartridgeaccount_new(retptr, ptr0, len0, ptr1, len1, addHeapObject(chain_id), addHeapObject(address), ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -411,9 +393,9 @@ export class CartridgeAccount { const ptr0 = passArrayJsValueToWasm0(calls, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.cartridgeaccount_hasSession(retptr, this.__wbg_ptr, ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -429,32 +411,9 @@ export class CartridgeAccount { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.cartridgeaccount_sessionJson(retptr, this.__wbg_ptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; - if (r2) { - throw takeObject(r1); - } - return takeObject(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } - } - /** - * @param {(JsPolicy)[]} policies - * @param {bigint} expires_at - * @param {any} external_account - * @returns {any} - */ - static registerSessionCalldata(policies, expires_at, external_account) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArrayJsValueToWasm0(policies, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - wasm.cartridgeaccount_registerSessionCalldata(retptr, ptr0, len0, expires_at, addHeapObject(external_account)); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -469,8 +428,8 @@ export class CartridgeAccount { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.cartridgeaccount_revokeSession(retptr, this.__wbg_ptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } @@ -504,17 +463,22 @@ export class CartridgeAccount { return takeObject(ret); } /** - * @param {any} salt - * @param {any} external_owner + * @param {any} owner + * @param {any} username + * @param {(JsPolicy)[]} policies + * @param {bigint} expires_at + * @param {bigint} initial_deposit * @returns {any} */ - static getUdcDeployedAddress(salt, external_owner) { + static externalDeploymentCalls(owner, username, policies, expires_at, initial_deposit) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.cartridgeaccount_getUdcDeployedAddress(retptr, addHeapObject(salt), addHeapObject(external_owner)); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + const ptr0 = passArrayJsValueToWasm0(policies, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.cartridgeaccount_externalDeploymentCalls(retptr, addHeapObject(owner), addHeapObject(username), ptr0, len0, expires_at, initial_deposit); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -523,25 +487,11 @@ export class CartridgeAccount { wasm.__wbindgen_add_to_stack_pointer(16); } } - /** - * @returns {any} - */ - static getAccountClassHash() { - const ret = wasm.cartridgeaccount_getAccountClassHash(); - return takeObject(ret); - } - /** - * @returns {any} - */ - static getUdcAddress() { - const ret = wasm.cartridgeaccount_getUdcAddress(); - return takeObject(ret); - } } const CartridgeSessionAccountFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } - : new FinalizationRegistry(ptr => wasm.__wbg_cartridgesessionaccount_free(ptr >>> 0)); + : new FinalizationRegistry(ptr => wasm.__wbg_cartridgesessionaccount_free(ptr >>> 0, 1)); /** */ export class CartridgeSessionAccount { @@ -563,7 +513,7 @@ export class CartridgeSessionAccount { free() { const ptr = this.__destroy_into_raw(); - wasm.__wbg_cartridgesessionaccount_free(ptr); + wasm.__wbg_cartridgesessionaccount_free(ptr, 0); } /** * @param {string} rpc_url @@ -582,9 +532,9 @@ export class CartridgeSessionAccount { const ptr1 = passArrayJsValueToWasm0(session_authorization, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; wasm.cartridgesessionaccount_new(retptr, ptr0, len0, addHeapObject(signer), addHeapObject(address), addHeapObject(chain_id), ptr1, len1, addHeapObject(session)); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -608,9 +558,9 @@ export class CartridgeSessionAccount { const ptr0 = passStringToWasm0(rpc_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; wasm.cartridgesessionaccount_new_as_registered(retptr, ptr0, len0, addHeapObject(signer), addHeapObject(address), addHeapObject(owner_guid), addHeapObject(chain_id), addHeapObject(session)); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } @@ -666,8 +616,8 @@ export function __wbindgen_string_get(arg0, arg1) { const ret = typeof(obj) === 'string' ? obj : undefined; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_json_parse(arg0, arg1) { @@ -680,8 +630,8 @@ export function __wbindgen_json_serialize(arg0, arg1) { const ret = JSON.stringify(obj === undefined ? null : obj); const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_error_new(arg0, arg1) { @@ -703,8 +653,8 @@ export function __wbindgen_boolean_get(arg0) { 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); + getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); }; export function __wbindgen_bigint_from_i64(arg0) { @@ -737,8 +687,8 @@ export function __wbg_String_b9412f8799faab3e(arg0, arg1) { const ret = String(getObject(arg1)); const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_number_new(arg0) { @@ -759,11 +709,11 @@ export function __wbg_fetch_bc7c8e27076a5c84(arg0) { return addHeapObject(ret); }; -export function __wbg_queueMicrotask_481971b0d87f3dd4(arg0) { +export function __wbg_queueMicrotask_12a30234db4045d3(arg0) { queueMicrotask(getObject(arg0)); }; -export function __wbg_queueMicrotask_3cbae2ec6b6cd3d6(arg0) { +export function __wbg_queueMicrotask_48421b3cc9052b68(arg0) { const ret = getObject(arg0).queueMicrotask; return addHeapObject(ret); }; @@ -783,7 +733,7 @@ export function __wbindgen_cb_drop(arg0) { return ret; }; -export function __wbg_instanceof_Window_f401953a2cf86220(arg0) { +export function __wbg_instanceof_Window_5012736c80a01584(arg0) { let result; try { result = getObject(arg0) instanceof Window; @@ -794,60 +744,50 @@ export function __wbg_instanceof_Window_f401953a2cf86220(arg0) { return ret; }; -export function __wbg_location_2951b5ee34f19221(arg0) { +export function __wbg_location_af118da6c50d4c3f(arg0) { const ret = getObject(arg0).location; return addHeapObject(ret); }; -export function __wbg_navigator_6c8fa55c5cc8796e(arg0) { +export function __wbg_navigator_6210380287bf8581(arg0) { const ret = getObject(arg0).navigator; return addHeapObject(ret); }; -export function __wbg_localStorage_e381d34d0c40c761() { return handleError(function (arg0) { +export function __wbg_localStorage_90db5cb66e840248() { return handleError(function (arg0) { const ret = getObject(arg0).localStorage; return isLikeNone(ret) ? 0 : addHeapObject(ret); }, arguments) }; -export function __wbg_debug_5fb96680aecf5dc8(arg0) { +export function __wbg_debug_5a33c41aeac15ee6(arg0) { console.debug(getObject(arg0)); }; -export function __wbg_log_5bb5f88f245d7762(arg0) { +export function __wbg_log_b103404cc5920657(arg0) { console.log(getObject(arg0)); }; -export function __wbg_fetch_921fad6ef9e883dd(arg0, arg1) { +export function __wbg_fetch_ba7fe179e527d942(arg0, arg1) { const ret = getObject(arg0).fetch(getObject(arg1)); return addHeapObject(ret); }; -export function __wbg_origin_ee93e29ace71f568() { return handleError(function (arg0, arg1) { - const ret = getObject(arg1).origin; - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; -}, arguments) }; - -export function __wbg_getItem_164e8e5265095b87() { return handleError(function (arg0, arg1, arg2, arg3) { - const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3)); - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; +export function __wbg_create_98c8d4ceb117be17() { return handleError(function (arg0, arg1) { + const ret = getObject(arg0).create(getObject(arg1)); + return addHeapObject(ret); }, arguments) }; -export function __wbg_setItem_ba2bb41d73dac079() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4)); +export function __wbg_get_a641ab434d58b2eb() { return handleError(function (arg0, arg1) { + const ret = getObject(arg0).get(getObject(arg1)); + return addHeapObject(ret); }, arguments) }; -export function __wbg_getClientExtensionResults_a849d498bd960116(arg0) { +export function __wbg_getClientExtensionResults_b2b730757f0acc3b(arg0) { const ret = getObject(arg0).getClientExtensionResults(); return addHeapObject(ret); }; -export function __wbg_instanceof_Response_849eb93e75734b6e(arg0) { +export function __wbg_instanceof_Response_e91b7eb7c611a9ae(arg0) { let result; try { result = getObject(arg0) instanceof Response; @@ -858,75 +798,109 @@ export function __wbg_instanceof_Response_849eb93e75734b6e(arg0) { return ret; }; -export function __wbg_url_5f6dc4009ac5f99d(arg0, arg1) { +export function __wbg_url_1bf85c8abeb8c92d(arg0, arg1) { const ret = getObject(arg1).url; const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; -export function __wbg_status_61a01141acd3cf74(arg0) { +export function __wbg_status_ae8de515694c5c7c(arg0) { const ret = getObject(arg0).status; return ret; }; -export function __wbg_headers_9620bfada380764a(arg0) { +export function __wbg_headers_5e283e8345689121(arg0) { const ret = getObject(arg0).headers; return addHeapObject(ret); }; -export function __wbg_arrayBuffer_29931d52c7206b02() { return handleError(function (arg0) { +export function __wbg_arrayBuffer_a5fbad63cc7e663b() { return handleError(function (arg0) { const ret = getObject(arg0).arrayBuffer(); return addHeapObject(ret); }, arguments) }; -export function __wbg_text_450a059667fd91fd() { return handleError(function (arg0) { +export function __wbg_text_a94b91ea8700357a() { return handleError(function (arg0) { const ret = getObject(arg0).text(); return addHeapObject(ret); }, arguments) }; -export function __wbg_create_21f4f173d36edabb() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).create(getObject(arg1)); +export function __wbg_signal_41e46ccad44bb5e2(arg0) { + const ret = getObject(arg0).signal; return addHeapObject(ret); -}, arguments) }; +}; -export function __wbg_get_af826bc073cbd7b3() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).get(getObject(arg1)); +export function __wbg_new_ebf2727385ee825c() { return handleError(function () { + const ret = new AbortController(); return addHeapObject(ret); }, arguments) }; -export function __wbg_credentials_301bbb1c5ba6b52c(arg0) { - const ret = getObject(arg0).credentials; - return addHeapObject(ret); +export function __wbg_abort_8659d889a7877ae3(arg0) { + getObject(arg0).abort(); }; -export function __wbg_new_ab6fd82b10560829() { return handleError(function () { +export function __wbg_origin_648082c4831a5be8() { return handleError(function (arg0, arg1) { + const ret = getObject(arg1).origin; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +}, arguments) }; + +export function __wbg_getItem_cab39762abab3e70() { return handleError(function (arg0, arg1, arg2, arg3) { + const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3)); + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +}, arguments) }; + +export function __wbg_setItem_9482185c870abba6() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4)); +}, arguments) }; + +export function __wbg_new_e27c93803e1acc42() { return handleError(function () { const ret = new Headers(); return addHeapObject(ret); }, arguments) }; -export function __wbg_append_7bfcb4937d1d5e29() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { +export function __wbg_append_f3a4426bb50622c5() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4)); }, arguments) }; -export function __wbg_newwithstrandinit_3fd6fba4083ff2d0() { return handleError(function (arg0, arg1, arg2) { +export function __wbg_newwithstrandinit_a31c69e4cc337183() { return handleError(function (arg0, arg1, arg2) { const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2)); return addHeapObject(ret); }, arguments) }; -export function __wbg_signal_a61f78a3478fd9bc(arg0) { - const ret = getObject(arg0).signal; - return addHeapObject(ret); +export function __wbg_setbody_734cb3d7ee8e6e96(arg0, arg1) { + getObject(arg0).body = getObject(arg1); }; -export function __wbg_new_0d76b0581eca6298() { return handleError(function () { - const ret = new AbortController(); - return addHeapObject(ret); -}, arguments) }; +export function __wbg_setcredentials_2b67800db3f7b621(arg0, arg1) { + getObject(arg0).credentials = ["omit","same-origin","include",][arg1]; +}; -export function __wbg_abort_2aa7521d5690750e(arg0) { - getObject(arg0).abort(); +export function __wbg_setheaders_be10a5ab566fd06f(arg0, arg1) { + getObject(arg0).headers = getObject(arg1); +}; + +export function __wbg_setmethod_dc68a742c2db5c6a(arg0, arg1, arg2) { + getObject(arg0).method = getStringFromWasm0(arg1, arg2); +}; + +export function __wbg_setmode_a781aae2bd3df202(arg0, arg1) { + getObject(arg0).mode = ["same-origin","no-cors","cors","navigate",][arg1]; +}; + +export function __wbg_setsignal_91c4e8ebd04eb935(arg0, arg1) { + getObject(arg0).signal = getObject(arg1); +}; + +export function __wbg_credentials_fb876d53c9170fe4(arg0) { + const ret = getObject(arg0).credentials; + return addHeapObject(ret); }; export function __wbg_crypto_1d1f22824a6a080c(arg0) { @@ -972,91 +946,91 @@ export function __wbg_getRandomValues_3aa56aa6edec874c() { return handleError(fu getObject(arg0).getRandomValues(getObject(arg1)); }, arguments) }; -export function __wbg_new_16b304a2cfa7ff4a() { +export function __wbg_new_a220cf903aa02ca2() { const ret = new Array(); return addHeapObject(ret); }; -export function __wbg_newnoargs_e258087cd0daa0ea(arg0, arg1) { +export function __wbg_newnoargs_76313bd6ff35d0f2(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; -export function __wbg_new_d9bc3a0147634640() { +export function __wbg_new_8608a2b51a5f6737() { const ret = new Map(); return addHeapObject(ret); }; -export function __wbg_next_40fc327bfc8770e6(arg0) { +export function __wbg_next_de3e9db4440638b2(arg0) { const ret = getObject(arg0).next; return addHeapObject(ret); }; -export function __wbg_next_196c84450b364254() { return handleError(function (arg0) { +export function __wbg_next_f9cb570345655b9a() { return handleError(function (arg0) { const ret = getObject(arg0).next(); return addHeapObject(ret); }, arguments) }; -export function __wbg_done_298b57d23c0fc80c(arg0) { +export function __wbg_done_bfda7aa8f252b39f(arg0) { const ret = getObject(arg0).done; return ret; }; -export function __wbg_value_d93c65011f51a456(arg0) { +export function __wbg_value_6d39332ab4788d86(arg0) { const ret = getObject(arg0).value; return addHeapObject(ret); }; -export function __wbg_iterator_2cee6dadfd956dfa() { +export function __wbg_iterator_888179a48810a9fe() { const ret = Symbol.iterator; return addHeapObject(ret); }; -export function __wbg_get_e3c254076557e348() { return handleError(function (arg0, arg1) { +export function __wbg_get_224d16597dbbfd96() { return handleError(function (arg0, arg1) { const ret = Reflect.get(getObject(arg0), getObject(arg1)); return addHeapObject(ret); }, arguments) }; -export function __wbg_call_27c0f87801dedf93() { return handleError(function (arg0, arg1) { +export function __wbg_call_1084a111329e68ce() { return handleError(function (arg0, arg1) { const ret = getObject(arg0).call(getObject(arg1)); return addHeapObject(ret); }, arguments) }; -export function __wbg_new_72fb9a18b5ae2624() { +export function __wbg_new_525245e2b9901204() { const ret = new Object(); return addHeapObject(ret); }; -export function __wbg_self_ce0dbfc45cf2f5be() { return handleError(function () { +export function __wbg_self_3093d5d1f7bcb682() { return handleError(function () { const ret = self.self; return addHeapObject(ret); }, arguments) }; -export function __wbg_window_c6fb939a7f436783() { return handleError(function () { +export function __wbg_window_3bcfc4d31bc012f8() { return handleError(function () { const ret = window.window; return addHeapObject(ret); }, arguments) }; -export function __wbg_globalThis_d1e6af4856ba331b() { return handleError(function () { +export function __wbg_globalThis_86b222e13bdf32ed() { return handleError(function () { const ret = globalThis.globalThis; return addHeapObject(ret); }, arguments) }; -export function __wbg_global_207b558942527489() { return handleError(function () { +export function __wbg_global_e5a3fe56f8be9485() { return handleError(function () { const ret = global.global; return addHeapObject(ret); }, arguments) }; -export function __wbg_set_d4638f722068f043(arg0, arg1, arg2) { +export function __wbg_set_673dda6c73d19609(arg0, arg1, arg2) { getObject(arg0)[arg1 >>> 0] = takeObject(arg2); }; -export function __wbg_push_a5b05aedc7234f9f(arg0, arg1) { +export function __wbg_push_37c89022f34c01ca(arg0, arg1) { const ret = getObject(arg0).push(getObject(arg1)); return ret; }; -export function __wbg_instanceof_ArrayBuffer_836825be07d4c9d2(arg0) { +export function __wbg_instanceof_ArrayBuffer_61dfc3198373c902(arg0) { let result; try { result = getObject(arg0) instanceof ArrayBuffer; @@ -1067,24 +1041,24 @@ export function __wbg_instanceof_ArrayBuffer_836825be07d4c9d2(arg0) { return ret; }; -export function __wbg_call_b3ca7c6051f9bec1() { return handleError(function (arg0, arg1, arg2) { +export function __wbg_call_89af060b4e1523f2() { return handleError(function (arg0, arg1, arg2) { const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); return addHeapObject(ret); }, arguments) }; -export function __wbg_set_8417257aaedc936b(arg0, arg1, arg2) { +export function __wbg_set_49185437f0ab06f8(arg0, arg1, arg2) { const ret = getObject(arg0).set(getObject(arg1), getObject(arg2)); return addHeapObject(ret); }; -export function __wbg_new_81740750da40724f(arg0, arg1) { +export function __wbg_new_b85e72ed1bfd57f9(arg0, arg1) { try { var state0 = {a: arg0, b: arg1}; var cb0 = (arg0, arg1) => { const a = state0.a; state0.a = 0; try { - return __wbg_adapter_177(a, state0.b, arg0, arg1); + return __wbg_adapter_186(a, state0.b, arg0, arg1); } finally { state0.a = a; } @@ -1096,46 +1070,46 @@ export function __wbg_new_81740750da40724f(arg0, arg1) { } }; -export function __wbg_resolve_b0083a7967828ec8(arg0) { +export function __wbg_resolve_570458cb99d56a43(arg0) { const ret = Promise.resolve(getObject(arg0)); return addHeapObject(ret); }; -export function __wbg_then_0c86a60e8fcfe9f6(arg0, arg1) { +export function __wbg_then_95e6edc0f89b73b1(arg0, arg1) { const ret = getObject(arg0).then(getObject(arg1)); return addHeapObject(ret); }; -export function __wbg_then_a73caa9a87991566(arg0, arg1, arg2) { +export function __wbg_then_876bb3c633745cc6(arg0, arg1, arg2) { const ret = getObject(arg0).then(getObject(arg1), getObject(arg2)); return addHeapObject(ret); }; -export function __wbg_buffer_12d079cc21e14bdb(arg0) { +export function __wbg_buffer_b7b08af79b0b0974(arg0) { const ret = getObject(arg0).buffer; return addHeapObject(ret); }; -export function __wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb(arg0, arg1, arg2) { +export function __wbg_newwithbyteoffsetandlength_8a2cb9ca96b27ec9(arg0, arg1, arg2) { const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; -export function __wbg_new_63b92bc8671ed464(arg0) { +export function __wbg_new_ea1883e1e5e86686(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; -export function __wbg_set_a47bac70306a19a7(arg0, arg1, arg2) { +export function __wbg_set_d1e79e2388520f18(arg0, arg1, arg2) { getObject(arg0).set(getObject(arg1), arg2 >>> 0); }; -export function __wbg_length_c20a40f15020d68a(arg0) { +export function __wbg_length_8339fcf5d8ecd12e(arg0) { const ret = getObject(arg0).length; return ret; }; -export function __wbg_instanceof_Uint8Array_2b3bbecd033d19f6(arg0) { +export function __wbg_instanceof_Uint8Array_247a91427532499e(arg0) { let result; try { result = getObject(arg0) instanceof Uint8Array; @@ -1146,27 +1120,27 @@ export function __wbg_instanceof_Uint8Array_2b3bbecd033d19f6(arg0) { return ret; }; -export function __wbg_newwithlength_e9b4878cebadb3d3(arg0) { +export function __wbg_newwithlength_ec548f448387c968(arg0) { const ret = new Uint8Array(arg0 >>> 0); return addHeapObject(ret); }; -export function __wbg_subarray_a1f73cd4b5b42fe1(arg0, arg1, arg2) { +export function __wbg_subarray_7c2e3576afe181d1(arg0, arg1, arg2) { const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; -export function __wbg_has_0af94d20077affa2() { return handleError(function (arg0, arg1) { +export function __wbg_has_4bfbc01db38743f7() { return handleError(function (arg0, arg1) { const ret = Reflect.has(getObject(arg0), getObject(arg1)); return ret; }, arguments) }; -export function __wbg_set_1f9b04f170055d33() { return handleError(function (arg0, arg1, arg2) { +export function __wbg_set_eacc7d73fefaafdf() { return handleError(function (arg0, arg1, arg2) { const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2)); return ret; }, arguments) }; -export function __wbg_stringify_8887fe74e1c50d81() { return handleError(function (arg0) { +export function __wbg_stringify_bbf45426c92a6bf5() { return handleError(function (arg0) { const ret = JSON.stringify(getObject(arg0)); return addHeapObject(ret); }, arguments) }; @@ -1175,8 +1149,8 @@ export function __wbindgen_debug_string(arg0, arg1) { const ret = debugString(getObject(arg1)); const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbindgen_throw(arg0, arg1) { @@ -1188,8 +1162,8 @@ export function __wbindgen_memory() { return addHeapObject(ret); }; -export function __wbindgen_closure_wrapper2425(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 479, __wbg_adapter_44); +export function __wbindgen_closure_wrapper2430(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 472, __wbg_adapter_44); return addHeapObject(ret); }; diff --git a/packages/account-wasm/pkg/account_wasm_bg.wasm b/packages/account-wasm/pkg/account_wasm_bg.wasm index 67621169b..43b44ac10 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/pkg/account_wasm_bg.wasm.d.ts b/packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts index a002e9dbf..77999073c 100644 --- a/packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts +++ b/packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts @@ -1,7 +1,7 @@ /* tslint:disable */ /* eslint-disable */ export const memory: WebAssembly.Memory; -export function __wbg_cartridgeaccount_free(a: number): void; +export function __wbg_cartridgeaccount_free(a: number, b: number): void; export function cartridgeaccount_new(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number): void; export function cartridgeaccount_ownerGuid(a: number): number; export function cartridgeaccount_registerSession(a: number, b: number, c: number, d: number, e: number): number; @@ -11,15 +11,12 @@ export function cartridgeaccount_execute(a: number, b: number, c: number, d: num export function cartridgeaccount_executeFromOutside(a: number, b: number, c: number, d: number): number; export function cartridgeaccount_hasSession(a: number, b: number, c: number, d: number): void; export function cartridgeaccount_sessionJson(a: number, b: number): void; -export function cartridgeaccount_registerSessionCalldata(a: number, b: number, c: number, d: number, e: number): void; export function cartridgeaccount_revokeSession(a: number, b: number): void; export function cartridgeaccount_signMessage(a: number, b: number, c: number): number; export function cartridgeaccount_deploySelf(a: number, b: number): number; export function cartridgeaccount_delegateAccount(a: number): number; -export function cartridgeaccount_getUdcDeployedAddress(a: number, b: number, c: number): void; -export function cartridgeaccount_getAccountClassHash(): number; -export function cartridgeaccount_getUdcAddress(): number; -export function __wbg_cartridgesessionaccount_free(a: number): void; +export function cartridgeaccount_externalDeploymentCalls(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; +export function __wbg_cartridgesessionaccount_free(a: number, b: number): void; export function cartridgesessionaccount_new(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; export function cartridgesessionaccount_new_as_registered(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; export function cartridgesessionaccount_sign(a: number, b: number, c: number, d: number): number; @@ -28,7 +25,7 @@ export function cartridgesessionaccount_execute_from_outside(a: number, b: numbe 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__h3f3a3deef6344805(a: number, b: number, c: number): void; +export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha5780fd1342283cf(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__hbcb2218b5bd12b96(a: number, b: number, c: number, d: number): void; +export function wasm_bindgen__convert__closures__invoke2_mut__h11630e69f33a5871(a: number, b: number, c: number, d: number): void; diff --git a/packages/account-wasm/src/lib.rs b/packages/account-wasm/src/lib.rs index 97055cf17..738fe4bc6 100644 --- a/packages/account-wasm/src/lib.rs +++ b/packages/account-wasm/src/lib.rs @@ -13,11 +13,11 @@ use account_sdk::account::session::hash::Session; use account_sdk::account::session::raw_session::RawSession; use account_sdk::account::session::SessionAccount; use account_sdk::account::{AccountHashAndCallsSigner, MessageSignerAccount}; -use account_sdk::constants::{ACCOUNT_CLASS_HASH, UDC_ADDRESS}; +use account_sdk::constants::{ACCOUNT_CLASS_HASH, ETH_CONTRACT_ADDRESS, UDC_ADDRESS}; use account_sdk::controller::Controller; use account_sdk::provider::{CartridgeJsonRpcProvider, CartridgeProvider}; use account_sdk::signers::webauthn::{CredentialID, WebauthnSigner}; -use account_sdk::signers::{HashSigner, Signer}; +use account_sdk::signers::{HashSigner, Signer, SignerTrait}; use base64::engine::general_purpose; use base64::Engine; use cainome::cairo_serde::{CairoSerde, ContractAddress}; @@ -37,6 +37,7 @@ use types::session::JsSession; use types::{Felts, JsFelt}; use url::Url; use wasm_bindgen::prelude::*; +use web_sys::console; use crate::errors::OperationError; use crate::types::invocation::JsInvocationsDetails; @@ -256,28 +257,6 @@ impl CartridgeAccount { .map_or_else(|| Ok(JsValue::NULL), Ok) } - #[wasm_bindgen(js_name = registerSessionCalldata)] - pub fn register_session_calldata( - policies: Vec, - expires_at: u64, - external_account: JsValue, - ) -> Result { - let methods = policies - .into_iter() - .map(TryFrom::try_from) - .collect::, _>>()?; - - let signer = SigningKey::from_random(); - let session = Session::new(methods, expires_at, &signer.signer())?; - - let calldata = [ - ::cairo_serialize(&session.raw()), - vec![from_value(external_account)?], - ] - .concat(); - Ok(to_value(&calldata)?) - } - #[wasm_bindgen(js_name = revokeSession)] pub fn revoke_session(&self) -> Result<()> { unimplemented!("Revoke Session not implemented"); @@ -324,39 +303,90 @@ impl CartridgeAccount { Ok(JsFelt(res)) } - #[wasm_bindgen(js_name = getUdcDeployedAddress)] - pub fn get_udc_deployed_address(salt: JsValue, external_owner: JsValue) -> Result { - set_panic_hook(); - - let salt = from_value::(salt)?; - let external_owner = from_value::(external_owner)?; + #[wasm_bindgen(js_name = externalDeploymentCalls)] + pub fn external_deployment_calls( + owner: JsValue, + username: JsValue, + policies: Vec, + expires_at: u64, + initial_deposit: u64, + ) -> Result { + let mut js_calls: Vec = vec![]; + let salt = from_value::(username)?; + let owner = from_value::(owner)?; let mut constructor_calldata = - controller::Owner::cairo_serialize(&controller::Owner::Account(external_owner)); + controller::Owner::cairo_serialize(&controller::Owner::Account(owner)); constructor_calldata.extend(Option::::cairo_serialize(&None)); - let res = get_udc_deployed_address( + let address = get_udc_deployed_address( salt, ACCOUNT_CLASS_HASH, &UdcUniqueness::NotUnique, &constructor_calldata, ); + let mut udc_deploy_calldata = vec![ + ACCOUNT_CLASS_HASH, + salt, + Felt::ZERO, // unique false + ]; + udc_deploy_calldata.push(constructor_calldata.len().into()); + udc_deploy_calldata.extend(constructor_calldata); + + // Universal Deployer Contract calldata + js_calls.push(JsCall { + contract_address: UDC_ADDRESS, + entrypoint: "deployContract".to_string(), + calldata: udc_deploy_calldata, + }); + + // Set Delegate account + js_calls.push(JsCall { + contract_address: address, + entrypoint: "set_delegate_account".to_string(), + calldata: vec![owner.into()], + }); + + // Register new session + let methods = policies + .into_iter() + .map(TryFrom::try_from) + .collect::, _>>()?; + let session_signer = SigningKey::from_random(); + let session = Session::new(methods, expires_at, &session_signer.signer())?; + + js_calls.push(JsCall { + contract_address: address, + entrypoint: "register_session".to_string(), + calldata: [ + ::cairo_serialize(&session.raw()), + vec![owner.into()], + ] + .concat(), + }); + + // Transfer ETH calldata + if initial_deposit > 0 { + js_calls.push(JsCall { + contract_address: ETH_CONTRACT_ADDRESS, + entrypoint: "approve".to_string(), + calldata: vec![address, initial_deposit.into(), Felt::ZERO], + }); + + js_calls.push(JsCall { + contract_address: ETH_CONTRACT_ADDRESS, + entrypoint: "transfer".to_string(), + calldata: vec![address, initial_deposit.into(), Felt::ZERO], + }); + } + Ok(to_value(&JsDeployment { - address: res, - calldata: constructor_calldata, + address: address, + calls: js_calls, + session_key: session_signer.secret_scalar(), })?) } - - #[wasm_bindgen(js_name = getAccountClassHash)] - pub fn get_account_class_hash() -> JsValue { - to_value(&ACCOUNT_CLASS_HASH).unwrap() - } - - #[wasm_bindgen(js_name = getUdcAddress)] - pub fn get_udc_address() -> JsValue { - to_value(&UDC_ADDRESS).unwrap() - } } #[wasm_bindgen] diff --git a/packages/account-wasm/src/types/call.rs b/packages/account-wasm/src/types/call.rs index 87a2b39fa..18b9b1aa7 100644 --- a/packages/account-wasm/src/types/call.rs +++ b/packages/account-wasm/src/types/call.rs @@ -45,3 +45,13 @@ impl TryFrom for types::Call { }) } } + +impl From for JsCall { + fn from(value: types::Call) -> Self { + JsCall { + contract_address: value.to.into(), + entrypoint: value.selector.to_string(), + calldata: value.calldata, + } + } +} diff --git a/packages/account-wasm/src/types/deployment.rs b/packages/account-wasm/src/types/deployment.rs index e4b9e4788..af765f0be 100644 --- a/packages/account-wasm/src/types/deployment.rs +++ b/packages/account-wasm/src/types/deployment.rs @@ -3,13 +3,14 @@ use serde_with::serde_as; use starknet::core::serde::unsigned_field_element::UfeHex; use starknet::core::types::Felt; +use super::call::JsCall; + #[serde_as] #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct JsDeployment { #[serde_as(as = "UfeHex")] pub address: Felt, - - #[serde_as(as = "Vec")] - pub calldata: Vec, + pub calls: Vec, + pub session_key: Felt, } diff --git a/packages/account_sdk/src/constants.rs b/packages/account_sdk/src/constants.rs index dbf99a1cd..b14aecbee 100644 --- a/packages/account_sdk/src/constants.rs +++ b/packages/account_sdk/src/constants.rs @@ -12,3 +12,6 @@ pub const ACCOUNT_COMPILED_CLASS_HASH: Felt = pub const ERC_20_COMPILED_CLASS_HASH: Felt = felt!("0x732654ca6baa90ff202d2fcc35fb39766eb34842a7e5ac6dbf7714af71f1dab"); + +pub const ETH_CONTRACT_ADDRESS: Felt = + felt!("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"); \ No newline at end of file diff --git a/packages/keychain/src/components/connect/Login.tsx b/packages/keychain/src/components/connect/Login.tsx index 1e98d9b8a..def5b2336 100644 --- a/packages/keychain/src/components/connect/Login.tsx +++ b/packages/keychain/src/components/connect/Login.tsx @@ -13,7 +13,6 @@ import { ErrorAlert } from "components/ErrorAlert"; export function Login(props: LoginProps) { const theme = useControllerTheme(); - console.debug("login render"); return ( (); const [state, setState] = useState(SignupState.CONNECT); - const [controllerAddress, setControllerAddress] = useState(""); - const [controllerCalldata, setControllerCalldata] = useState([]); const [title, setTitle] = useState(""); @@ -152,17 +147,6 @@ function SignupArgentInner({ username }: { username: string }) { const typedData = registerTypedData(username, { low, high }, chainId); const sig = await extAccount.signMessage(typedData); await finalizeAccountSignup(extAccount.address, chainId, sig as string[]); - - // set controller address & calldata - const salt = shortString.encodeShortString(username); - const { address, calldata } = CartridgeAccount.getUdcDeployedAddress( - salt, - extAccount.address, - ); - - setControllerAddress(address); - setControllerCalldata(calldata); - setState(SignupState.DEPLOY); } catch (e) { console.log(e); @@ -173,83 +157,59 @@ function SignupArgentInner({ username }: { username: string }) { const onDeploy = useCallback(async () => { if (!extAccount) return; - const calls = tokens.flatMap((t) => { - const amount = cairo.uint256(t.min); - return [ - { - contractAddress: t.address, - entrypoint: "approve", - calldata: CallData.compile({ - recipient: controllerAddress, - amount, - }), - }, - { - contractAddress: t.address, - entrypoint: "transfer", - calldata: CallData.compile({ - recipient: controllerAddress, - amount, - }), - }, - ]; - }); - - // deployContract - const salt = shortString.encodeShortString(username); - calls.push({ - contractAddress: CartridgeAccount.getUdcAddress(), - entrypoint: "deployContract", - calldata: CallData.compile({ - classHash: CartridgeAccount.getAccountClassHash(), - salt, - unique: false, - calldata: controllerCalldata, - }), - }); - - // registerSession - calls.push({ - contractAddress: controllerAddress, - entrypoint: "register_session", - calldata: CartridgeAccount.registerSessionCalldata( + try { + setIsDeploying(true); + + const { + address: controllerAddress, + calls: deploymentCalls, + sessionKey, + } = CartridgeAccount.externalDeploymentCalls( + extAccount.address, + shortString.encodeShortString(username), policies.map((p) => { return { target: p.target, method: p.method }; }), 3000000000n, - extAccount.address, - ), - }); - - console.log( - calls - .map((call) => { - return CallData.compile(call) - .map((i) => `0x${BigInt(i).toString(16)}`) - .join(" "); - }) - .join(" / "), - ); + 100000000000000000n, + ); - try { - setIsDeploying(true); - const res = await extAccount.execute(calls); + const res = await extAccount.execute(deploymentCalls); await extAccount.waitForTransaction(res.transaction_hash, { retryInterval: 1000, }); + + // Test session account + const sessionAccount = CartridgeSessionAccount.new_as_registered( + rpcUrl, + sessionKey, + controllerAddress, + extAccount.address, + chainId, + { + policies: policies.map((p) => { + return { target: p.target, method: p.method }; + }), + expiresAt: 3000000000, + }, + ); + + const res2 = await sessionAccount.execute([ + { + contractAddress: ETH_CONTRACT_ADDRESS, + entrypoint: "transfer", + calldata: [extAccount.address, "0x2386F26FC10000", "0"], + }, + ]); + + console.log(res2); } catch (e) { console.log(e); setError(e); + } finally { + setIsDeploying(false); } - setIsDeploying(false); - }, [ - extAccount, - controllerAddress, - controllerCalldata, - policies, - tokens, - username, - ]); + }, [extAccount, policies, tokens, username]); // const onCopy = useCallback(() => { // navigator.clipboard.writeText(controllerAddress); @@ -283,9 +243,7 @@ function SignupArgentInner({ username }: { username: string }) { "Please connect your ArgentX wallet"} {state === SignupState.SIGN_MESSAGE && "Sign message to create your controller"} - {state === SignupState.DEPLOY && ( - - )} + {state === SignupState.DEPLOY && <>} } // TODO: Add line icons @@ -407,7 +365,6 @@ function SignupArgentInner({ username }: { username: string }) {