Skip to content

Commit 197398a

Browse files
committed
feat: integrate Rust WASM SDK for encoding
- Use Rust SDK through WASM for all encoding operations - Remove ZKsync-specific dependencies (viem/zksync) - Remove paymaster and EIP-712 logic - Simplify to standard EVM-compatible implementation
1 parent 7adb034 commit 197398a

File tree

47 files changed

+1083
-1365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1083
-1365
lines changed

packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/src/erc4337/account/modular_smart_account/add_passkey.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub async fn add_passkey<P: Provider + Send + Sync + Clone>(
4949
Ok(())
5050
}
5151

52-
fn add_passkey_call_data(
52+
pub fn add_passkey_call_data(
5353
passkey: PasskeyPayload,
5454
webauthn_validator: Address,
5555
) -> Bytes {
@@ -66,7 +66,7 @@ fn add_passkey_call_data(
6666
encode_calls(calls).into()
6767
}
6868

69-
fn add_validation_key_call_data(passkey: PasskeyPayload) -> Bytes {
69+
pub fn add_validation_key_call_data(passkey: PasskeyPayload) -> Bytes {
7070
let credential_id = passkey.credential_id;
7171
let origin_domain = passkey.origin_domain;
7272
let new_key = passkey.passkey;

packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/src/erc4337/account/modular_smart_account/deploy.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ use alloy::{
1414
sol_types::{SolCall, SolEvent, SolValue},
1515
};
1616

17+
// For encoding module data compatible with deployProxySsoAccount
18+
sol! {
19+
struct ModuleData {
20+
address module_address;
21+
bytes parameters;
22+
}
23+
}
24+
1725
pub struct MSAInitializeAccount(initializeAccountCall);
1826

1927
impl MSAInitializeAccount {
@@ -128,6 +136,67 @@ fn get_account_created_address(
128136
Ok(address)
129137
}
130138

139+
// ===== ENCODING FUNCTIONS FOR TYPESCRIPT SDK =====
140+
141+
/// Encode complete calldata for deployProxySsoAccount
142+
/// This is the single function that should be used from TypeScript
143+
///
144+
/// # Parameters
145+
/// * `account_id` - Unique account ID (bytes32)
146+
/// * `passkey` - Optional passkey payload
147+
/// * `passkey_validator` - Address of passkey validator (required if passkey is provided)
148+
/// * `session_validator` - Address of session validator
149+
/// * `session_data` - Optional session initialization data (already encoded)
150+
/// * `recovery_validator` - Address of recovery validator
151+
/// * `oidc_recovery_validator` - Address of OIDC recovery validator
152+
///
153+
/// # Returns
154+
/// Complete calldata for calling deployProxySsoAccount on the factory
155+
pub fn encode_deploy_account_call_data(
156+
account_id: FixedBytes<32>,
157+
passkey: Option<PasskeyPayload>,
158+
passkey_validator: Option<Address>,
159+
session_validator: Address,
160+
session_data: Option<Bytes>,
161+
recovery_validator: Address,
162+
oidc_recovery_validator: Address,
163+
) -> Bytes {
164+
let mut modules: Vec<Address> = Vec::new();
165+
let mut data: Vec<Bytes> = Vec::new();
166+
167+
// Add passkey validator if provided
168+
if let Some(passkey_payload) = passkey {
169+
let passkey_params = passkey_payload.abi_encode_params();
170+
modules.push(passkey_validator.expect("passkey_validator required when passkey is provided"));
171+
data.push(passkey_params.into());
172+
}
173+
174+
// Add session validator
175+
let session_params = session_data.unwrap_or_else(|| Bytes::new());
176+
modules.push(session_validator);
177+
data.push(session_params);
178+
179+
// Add guardian recovery validator
180+
modules.push(recovery_validator);
181+
data.push(Bytes::new());
182+
183+
// Add OIDC recovery validator
184+
modules.push(oidc_recovery_validator);
185+
data.push(Bytes::new());
186+
187+
// Encode the complete call to deployAccount
188+
// deployAccount(bytes32 accountId, bytes initData)
189+
// The initData contains the MSAInitializeAccount call
190+
let init_data: Bytes = MSAInitializeAccount::new(modules, data).encode().into();
191+
192+
MSAFactory::deployAccountCall {
193+
accountId: account_id,
194+
initData: init_data,
195+
}
196+
.abi_encode()
197+
.into()
198+
}
199+
131200
#[cfg(test)]
132201
mod tests {
133202
use super::*;

packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/src/erc4337/account/modular_smart_account/session/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub async fn create_session<P: Provider + Send + Sync + Clone>(
4242
Ok(())
4343
}
4444

45-
fn add_session_call_data(
45+
pub fn add_session_call_data(
4646
spec: SessionSpec,
4747
session_key_validator: Address,
4848
) -> Bytes {

packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/src/erc4337/account/modular_smart_account/session/revoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub async fn revoke_session<P: Provider + Send + Sync + Clone>(
4040
Ok(())
4141
}
4242

43-
fn revoke_session_call_data(
43+
pub fn revoke_session_call_data(
4444
session_hash: FixedBytes<32>,
4545
session_key_validator: Address,
4646
) -> Bytes {

0 commit comments

Comments
 (0)