Skip to content

Commit 3e10058

Browse files
committed
fix: address code review comments
bigInt to number breaks types
1 parent 78121d0 commit 3e10058

File tree

2 files changed

+32
-23
lines changed
  • packages
    • sdk-4337/src/client/session
    • sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/src/erc4337/account/modular_smart_account/session

2 files changed

+32
-23
lines changed

packages/sdk-4337/src/client/session/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ export function getSessionHash(spec: SessionSpec): Hex {
146146
const createSessionFunction = SessionKeyValidatorAbi.find(
147147
(x) => x.type === "function" && x.name === "createSession",
148148
);
149-
if (!createSessionFunction) throw new Error("createSession function not found in ABI");
149+
if (!createSessionFunction) throw new Error("createSession function not found in SessionKeyValidator ABI");
150150

151151
const sessionSpecParam = createSessionFunction.inputs.find((x) => x.name === "sessionSpec");
152-
if (!sessionSpecParam) throw new Error("sessionSpec param not found in createSession ABI");
152+
if (!sessionSpecParam) throw new Error("sessionSpec parameter not found in createSession function inputs");
153153

154154
const encoded = encodeAbiParameters(
155155
[sessionSpecParam],
156+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
156157
[spec as any],
157158
);
158159
return keccak256(encoded);

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,30 @@ mod tests {
117117
},
118118
};
119119
use alloy::{
120-
primitives::{U256, Uint, address, bytes, fixed_bytes, keccak256},
120+
primitives::{Address, Bytes, U256, Uint, address, bytes, fixed_bytes, keccak256},
121121
signers::{SignerSync, local::PrivateKeySigner},
122122
sol_types::SolValue,
123123
};
124124
use std::str::FromStr;
125125

126+
fn generate_session_proof(
127+
session_spec: &SessionSpec,
128+
account_address: Address,
129+
signer_private_key: &str,
130+
) -> eyre::Result<Bytes> {
131+
let session_lib_spec: crate::erc4337::account::modular_smart_account::session::contract::SessionLib::SessionSpec =
132+
session_spec.clone().into();
133+
let session_hash = keccak256(session_lib_spec.abi_encode());
134+
let digest = keccak256((session_hash, account_address).abi_encode());
135+
136+
let session_signer_instance =
137+
PrivateKeySigner::from_str(signer_private_key)?;
138+
Ok(session_signer_instance
139+
.sign_hash_sync(&digest)?
140+
.as_bytes()
141+
.into())
142+
}
143+
126144
#[tokio::test]
127145
async fn test_create_session() -> eyre::Result<()> {
128146
let (
@@ -250,16 +268,11 @@ mod tests {
250268
};
251269

252270
// Calculate proof
253-
let session_lib_spec: crate::erc4337::account::modular_smart_account::session::contract::SessionLib::SessionSpec = session_spec.clone().into();
254-
let session_hash = keccak256(session_lib_spec.abi_encode());
255-
let digest = keccak256((session_hash, address).abi_encode());
256-
257-
let session_signer_instance =
258-
PrivateKeySigner::from_str(&signer_private_key)?;
259-
let proof = session_signer_instance
260-
.sign_hash_sync(&digest)?
261-
.as_bytes()
262-
.into();
271+
let proof = generate_session_proof(
272+
&session_spec,
273+
address,
274+
&signer_private_key,
275+
)?;
263276

264277
create_session(CreateSessionParams {
265278
account_address: address,
@@ -410,16 +423,11 @@ mod tests {
410423
};
411424

412425
// Calculate proof
413-
let session_lib_spec: crate::erc4337::account::modular_smart_account::session::contract::SessionLib::SessionSpec = session_spec.clone().into();
414-
let session_hash = keccak256(session_lib_spec.abi_encode());
415-
let digest = keccak256((session_hash, address).abi_encode());
416-
417-
let session_signer_instance =
418-
PrivateKeySigner::from_str(&signer_private_key)?;
419-
let proof = session_signer_instance
420-
.sign_hash_sync(&digest)?
421-
.as_bytes()
422-
.into();
426+
let proof = generate_session_proof(
427+
&session_spec,
428+
address,
429+
&signer_private_key,
430+
)?;
423431

424432
create_session(CreateSessionParams {
425433
account_address: address,

0 commit comments

Comments
 (0)