Skip to content

Commit a4b62af

Browse files
committed
signup argent
1 parent a07a134 commit a4b62af

File tree

19 files changed

+715
-87
lines changed

19 files changed

+715
-87
lines changed

examples/starknet-react-next/src/components/providers/StarknetProvider.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ const cartridge = new CartridgeConnector({
6666
},
6767
// theme: "dope-wars",
6868
// colorMode: "light"
69-
// prefunds: [
70-
// {
71-
// address: ETH_TOKEN_ADDRESS,
72-
// min: "300000000000000",
73-
// },
74-
// {
75-
// address: PAPER_TOKEN_ADDRESS,
76-
// min: "100",
77-
// },
78-
// ],
69+
prefunds: [
70+
{
71+
address: ETH_TOKEN_ADDRESS,
72+
min: "300000000000000",
73+
},
74+
// {
75+
// address: PAPER_TOKEN_ADDRESS,
76+
// min: "100",
77+
// },
78+
],
7979
});
8080

8181
function provider(chain: Chain) {

packages/account-wasm/pkg/account_wasm.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export class CartridgeAccount {
6262
*/
6363
sessionJson(): any;
6464
/**
65+
* @param {any[]} policies
66+
* @param {bigint} expires_at
67+
* @param {any} external_account
68+
* @returns {any}
69+
*/
70+
static registerSessionCalldata(policies: any[], expires_at: bigint, external_account: any): any;
71+
/**
6572
*/
6673
revokeSession(): void;
6774
/**
@@ -78,4 +85,18 @@ export class CartridgeAccount {
7885
* @returns {Promise<any>}
7986
*/
8087
delegateAccount(): Promise<any>;
88+
/**
89+
* @param {any} salt
90+
* @param {any} external_owner
91+
* @returns {any}
92+
*/
93+
static getUdcDeployedAddress(salt: any, external_owner: any): any;
94+
/**
95+
* @returns {any}
96+
*/
97+
static getAccountClassHash(): any;
98+
/**
99+
* @returns {any}
100+
*/
101+
static getUdcAddress(): any;
81102
}

packages/account-wasm/pkg/account_wasm_bg.js

+92-35
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ function getInt32Memory0() {
104104
return cachedInt32Memory0;
105105
}
106106

107-
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
108-
109-
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
110-
111-
cachedTextDecoder.decode();
107+
let cachedFloat64Memory0 = null;
112108

113-
function getStringFromWasm0(ptr, len) {
114-
ptr = ptr >>> 0;
115-
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
109+
function getFloat64Memory0() {
110+
if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
111+
cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
112+
}
113+
return cachedFloat64Memory0;
116114
}
117115

118116
function addHeapObject(obj) {
@@ -124,13 +122,15 @@ function addHeapObject(obj) {
124122
return idx;
125123
}
126124

127-
let cachedFloat64Memory0 = null;
125+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
128126

129-
function getFloat64Memory0() {
130-
if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
131-
cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
132-
}
133-
return cachedFloat64Memory0;
127+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
128+
129+
cachedTextDecoder.decode();
130+
131+
function getStringFromWasm0(ptr, len) {
132+
ptr = ptr >>> 0;
133+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
134134
}
135135

136136
let cachedBigInt64Memory0 = null;
@@ -238,7 +238,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
238238
return real;
239239
}
240240
function __wbg_adapter_48(arg0, arg1, arg2) {
241-
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4f854f1ab9269aba(arg0, arg1, addHeapObject(arg2));
241+
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18209be10352b66c(arg0, arg1, addHeapObject(arg2));
242242
}
243243

244244
let cachedUint32Memory0 = null;
@@ -267,8 +267,8 @@ function handleError(f, args) {
267267
wasm.__wbindgen_exn_store(addHeapObject(e));
268268
}
269269
}
270-
function __wbg_adapter_176(arg0, arg1, arg2, arg3) {
271-
wasm.wasm_bindgen__convert__closures__invoke2_mut__h124d41d3678e7072(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
270+
function __wbg_adapter_180(arg0, arg1, arg2, arg3) {
271+
wasm.wasm_bindgen__convert__closures__invoke2_mut__h09491c54862df783(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
272272
}
273273

274274
const CartridgeAccountFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -435,6 +435,29 @@ export class CartridgeAccount {
435435
}
436436
}
437437
/**
438+
* @param {any[]} policies
439+
* @param {bigint} expires_at
440+
* @param {any} external_account
441+
* @returns {any}
442+
*/
443+
static registerSessionCalldata(policies, expires_at, external_account) {
444+
try {
445+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
446+
const ptr0 = passArrayJsValueToWasm0(policies, wasm.__wbindgen_malloc);
447+
const len0 = WASM_VECTOR_LEN;
448+
wasm.cartridgeaccount_registerSessionCalldata(retptr, ptr0, len0, expires_at, addHeapObject(external_account));
449+
var r0 = getInt32Memory0()[retptr / 4 + 0];
450+
var r1 = getInt32Memory0()[retptr / 4 + 1];
451+
var r2 = getInt32Memory0()[retptr / 4 + 2];
452+
if (r2) {
453+
throw takeObject(r1);
454+
}
455+
return takeObject(r0);
456+
} finally {
457+
wasm.__wbindgen_add_to_stack_pointer(16);
458+
}
459+
}
460+
/**
438461
*/
439462
revokeSession() {
440463
try {
@@ -474,6 +497,40 @@ export class CartridgeAccount {
474497
const ret = wasm.cartridgeaccount_delegateAccount(this.__wbg_ptr);
475498
return takeObject(ret);
476499
}
500+
/**
501+
* @param {any} salt
502+
* @param {any} external_owner
503+
* @returns {any}
504+
*/
505+
static getUdcDeployedAddress(salt, external_owner) {
506+
try {
507+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
508+
wasm.cartridgeaccount_getUdcDeployedAddress(retptr, addHeapObject(salt), addHeapObject(external_owner));
509+
var r0 = getInt32Memory0()[retptr / 4 + 0];
510+
var r1 = getInt32Memory0()[retptr / 4 + 1];
511+
var r2 = getInt32Memory0()[retptr / 4 + 2];
512+
if (r2) {
513+
throw takeObject(r1);
514+
}
515+
return takeObject(r0);
516+
} finally {
517+
wasm.__wbindgen_add_to_stack_pointer(16);
518+
}
519+
}
520+
/**
521+
* @returns {any}
522+
*/
523+
static getAccountClassHash() {
524+
const ret = wasm.cartridgeaccount_getAccountClassHash();
525+
return takeObject(ret);
526+
}
527+
/**
528+
* @returns {any}
529+
*/
530+
static getUdcAddress() {
531+
const ret = wasm.cartridgeaccount_getUdcAddress();
532+
return takeObject(ret);
533+
}
477534
}
478535

479536
export function __wbindgen_object_drop_ref(arg0) {
@@ -489,21 +546,6 @@ export function __wbindgen_string_get(arg0, arg1) {
489546
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
490547
};
491548

492-
export function __wbindgen_error_new(arg0, arg1) {
493-
const ret = new Error(getStringFromWasm0(arg0, arg1));
494-
return addHeapObject(ret);
495-
};
496-
497-
export function __wbindgen_string_new(arg0, arg1) {
498-
const ret = getStringFromWasm0(arg0, arg1);
499-
return addHeapObject(ret);
500-
};
501-
502-
export function __wbindgen_object_clone_ref(arg0) {
503-
const ret = getObject(arg0);
504-
return addHeapObject(ret);
505-
};
506-
507549
export function __wbindgen_is_undefined(arg0) {
508550
const ret = getObject(arg0) === undefined;
509551
return ret;
@@ -553,6 +595,21 @@ export function __wbindgen_bigint_from_u64(arg0) {
553595
return addHeapObject(ret);
554596
};
555597

598+
export function __wbindgen_error_new(arg0, arg1) {
599+
const ret = new Error(getStringFromWasm0(arg0, arg1));
600+
return addHeapObject(ret);
601+
};
602+
603+
export function __wbindgen_string_new(arg0, arg1) {
604+
const ret = getStringFromWasm0(arg0, arg1);
605+
return addHeapObject(ret);
606+
};
607+
608+
export function __wbindgen_object_clone_ref(arg0) {
609+
const ret = getObject(arg0);
610+
return addHeapObject(ret);
611+
};
612+
556613
export function __wbindgen_jsval_loose_eq(arg0, arg1) {
557614
const ret = getObject(arg0) == getObject(arg1);
558615
return ret;
@@ -931,7 +988,7 @@ export function __wbg_new_81740750da40724f(arg0, arg1) {
931988
const a = state0.a;
932989
state0.a = 0;
933990
try {
934-
return __wbg_adapter_176(a, state0.b, arg0, arg1);
991+
return __wbg_adapter_180(a, state0.b, arg0, arg1);
935992
} finally {
936993
state0.a = a;
937994
}
@@ -1042,8 +1099,8 @@ export function __wbindgen_memory() {
10421099
return addHeapObject(ret);
10431100
};
10441101

1045-
export function __wbindgen_closure_wrapper2261(arg0, arg1, arg2) {
1046-
const ret = makeMutClosure(arg0, arg1, 486, __wbg_adapter_48);
1102+
export function __wbindgen_closure_wrapper2263(arg0, arg1, arg2) {
1103+
const ret = makeMutClosure(arg0, arg1, 493, __wbg_adapter_48);
10471104
return addHeapObject(ret);
10481105
};
10491106

3.53 KB
Binary file not shown.

packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ export function cartridgeaccount_execute(a: number, b: number, c: number, d: num
99
export function cartridgeaccount_executeFromOutside(a: number, b: number, c: number, d: number): number;
1010
export function cartridgeaccount_hasSession(a: number, b: number, c: number, d: number): void;
1111
export function cartridgeaccount_sessionJson(a: number, b: number): void;
12+
export function cartridgeaccount_registerSessionCalldata(a: number, b: number, c: number, d: number, e: number): void;
1213
export function cartridgeaccount_revokeSession(a: number, b: number): void;
1314
export function cartridgeaccount_signMessage(a: number, b: number, c: number): number;
1415
export function cartridgeaccount_deploySelf(a: number, b: number): number;
1516
export function cartridgeaccount_delegateAccount(a: number): number;
17+
export function cartridgeaccount_getUdcDeployedAddress(a: number, b: number, c: number): void;
18+
export function cartridgeaccount_getAccountClassHash(): number;
19+
export function cartridgeaccount_getUdcAddress(): number;
1620
export function __wbindgen_malloc(a: number, b: number): number;
1721
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
1822
export const __wbindgen_export_2: WebAssembly.Table;
19-
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4f854f1ab9269aba(a: number, b: number, c: number): void;
23+
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18209be10352b66c(a: number, b: number, c: number): void;
2024
export function __wbindgen_add_to_stack_pointer(a: number): number;
2125
export function __wbindgen_exn_store(a: number): void;
22-
export function wasm_bindgen__convert__closures__invoke2_mut__h124d41d3678e7072(a: number, b: number, c: number, d: number): void;
26+
export function wasm_bindgen__convert__closures__invoke2_mut__h09491c54862df783(a: number, b: number, c: number, d: number): void;

packages/account-wasm/src/lib.rs

+61-2
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,28 @@ mod utils;
77
use std::str::FromStr;
88
use std::sync::Arc;
99

10-
use account_sdk::abigen::controller::OutsideExecution;
10+
use account_sdk::abigen::controller::{self, OutsideExecution, Signer};
1111
use account_sdk::account::outside_execution::OutsideExecutionCaller;
12-
use account_sdk::account::session::hash::AllowedMethod;
12+
use account_sdk::account::session::hash::{AllowedMethod, Session};
13+
use account_sdk::account::session::raw_session::RawSession;
1314
use account_sdk::account::MessageSignerAccount;
15+
use account_sdk::constants::{ACCOUNT_CLASS_HASH, UDC_ADDRESS};
1416
use account_sdk::controller::Controller;
1517
use account_sdk::provider::CartridgeJsonRpcProvider;
1618
use account_sdk::signers::webauthn::{CredentialID, WebauthnSigner};
19+
use account_sdk::signers::HashSigner;
1720
use base64::engine::general_purpose;
1821
use base64::Engine;
22+
use cainome::cairo_serde::{CairoSerde, ContractAddress};
1923
use coset::{CborSerializable, CoseKey};
2024
use serde_wasm_bindgen::{from_value, to_value};
2125
use signer::BrowserBackend;
2226
use starknet::core::types::Call;
2327
use starknet::core::types::Felt;
28+
use starknet::core::utils::{get_udc_deployed_address, UdcUniqueness};
2429
use starknet::macros::short_string;
2530
use starknet::signers::SigningKey;
31+
use types::deployment::JsDeployment;
2632
use url::Url;
2733
use wasm_bindgen::prelude::*;
2834

@@ -222,6 +228,23 @@ impl CartridgeAccount {
222228
.map_or_else(|| Ok(JsValue::NULL), Ok)
223229
}
224230

231+
#[wasm_bindgen(js_name = registerSessionCalldata)]
232+
pub fn register_session_calldata(policies: Vec<JsValue>, expires_at: u64, external_account: JsValue) -> Result<JsValue> {
233+
let methods = policies
234+
.into_iter()
235+
.map(AllowedMethod::try_from_js_value)
236+
.collect::<std::result::Result<Vec<_>, _>>()?;
237+
238+
let signer = SigningKey::from_random();
239+
let session = Session::new(methods, expires_at, &signer.signer())?;
240+
241+
let calldata = [
242+
<RawSession as CairoSerde>::cairo_serialize(&session.raw()),
243+
vec![from_value(external_account)?],
244+
].concat();
245+
Ok(to_value(&calldata)?)
246+
}
247+
225248
#[wasm_bindgen(js_name = revokeSession)]
226249
pub fn revoke_session(&self) -> Result<()> {
227250
unimplemented!("Revoke Session not implemented");
@@ -267,4 +290,40 @@ impl CartridgeAccount {
267290

268291
Ok(to_value(&res)?)
269292
}
293+
294+
#[wasm_bindgen(js_name = getUdcDeployedAddress)]
295+
pub fn get_udc_deployed_address(salt: JsValue, external_owner: JsValue) -> Result<JsValue> {
296+
set_panic_hook();
297+
298+
let salt = from_value::<Felt>(salt)?;
299+
let external_owner = from_value::<ContractAddress>(external_owner)?;
300+
301+
// let constructor_calldata = vec![];
302+
let guardian = SigningKey::from_random();
303+
let mut constructor_calldata =
304+
controller::Owner::cairo_serialize(&controller::Owner::Account(external_owner));
305+
constructor_calldata.extend(Option::<Signer>::cairo_serialize(&Some(guardian.signer())));
306+
307+
let res = get_udc_deployed_address(
308+
salt,
309+
ACCOUNT_CLASS_HASH,
310+
&UdcUniqueness::NotUnique,
311+
&constructor_calldata,
312+
);
313+
314+
Ok(to_value(&JsDeployment {
315+
address: res,
316+
calldata: constructor_calldata,
317+
})?)
318+
}
319+
320+
#[wasm_bindgen(js_name = getAccountClassHash)]
321+
pub fn get_account_class_hash() -> JsValue {
322+
to_value(&ACCOUNT_CLASS_HASH).unwrap()
323+
}
324+
325+
#[wasm_bindgen(js_name = getUdcAddress)]
326+
pub fn get_udc_address() -> JsValue {
327+
to_value(&UDC_ADDRESS).unwrap()
328+
}
270329
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use serde::{Deserialize, Serialize};
2+
use serde_with::serde_as;
3+
use starknet::core::serde::unsigned_field_element::UfeHex;
4+
use starknet::core::types::Felt;
5+
6+
#[serde_as]
7+
#[derive(Clone, Debug, Deserialize, Serialize)]
8+
#[serde(rename_all = "camelCase")]
9+
pub struct JsDeployment {
10+
#[serde_as(as = "UfeHex")]
11+
pub address: Felt,
12+
13+
#[serde_as(as = "Vec<UfeHex>")]
14+
pub calldata: Vec<Felt>,
15+
}

packages/account-wasm/src/types/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod invocation;
88
pub(crate) mod outside_execution;
99
pub(crate) mod policy;
1010
pub(crate) mod session;
11+
pub(crate) mod deployment;
1112

1213
pub(crate) trait TryFromJsValue<T> {
1314
fn try_from_js_value(value: JsValue) -> Result<T, EncodingError>;

0 commit comments

Comments
 (0)