Merged
Conversation
Take learnings from last one
Starting fresh for signatures
basic setup before integrating with viem
not integrated, so will need to test this!
back to where I was before, but now with more steps and a worse UI. Might even try to import the old UI and ask it to update for viem clients. Or might just try to rebase and start on the tests fresh, at least we're not getting stuck on the wasm build issues yet, it looks pretty simple so far!
adding passkey deps
tests still fail
still failing, but some progress?
fails locally with not active which is easy
going to rebase to get latest
paaing locally?
now time for cleanup
- Add Session API Guide with complete examples and best practices - Create Migration Guide from low-level WASM API to viem - Add JSDoc comments to ZkSyncSsoClient class - Update README with quick start examples and documentation links - Cover troubleshooting, security, and advanced topics - Update markdownlint config to allow long lines in docs/
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a comprehensive session key SDK implementation for Viem, enabling delegated transaction signing with enforced policy limits. The implementation bridges Rust WASM bindings with TypeScript SDK layers to provide session management capabilities.
Key changes include:
- New Rust WASM FFI functions for session encoding, signature generation, and nonce calculation
- TypeScript SDK types and utilities for session specifications, policies, and validation
- Viem-compatible session smart account implementation
- Demo application integration with E2E tests
- Support for deploying accounts with pre-installed session validators
Reviewed Changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/sdk-platforms/rust/.../lib.rs | Adds WASM FFI exports for session operations (encoding, signing, nonce calculation) and updates deployment to support session validators |
| packages/sdk-platforms/rust/.../signature_wasm.rs | Implements WASM-safe session signature generation without system time dependencies |
| packages/sdk-platforms/rust/.../encode.rs | Provides session execute encoding and stub signature generation for gas estimation |
| packages/sdk-platforms/rust/.../deploy.rs | Extends deployment to support optional session validator installation and adds comprehensive tests |
| packages/sdk-platforms/web/src/session.test.ts | Unit tests for session WASM bindings |
| packages/sdk-platforms/web/src/node.ts | Exports session-related WASM functions for Node.js environment |
| packages/sdk-platforms/web/src/bundler.ts | Exports session-related WASM functions for bundler environment |
| packages/sdk-4337/src/client/session/types.ts | TypeScript type definitions for session specs, policies, and limits |
| packages/sdk-4337/src/client/session/utils.ts | Utility functions for session spec JSON conversion and transaction validation |
| packages/sdk-4337/src/client/session/account.ts | Viem-compatible session smart account implementation |
| packages/sdk-4337/src/client/actions/createSession.ts | Action for creating sessions on-chain via EOA or passkey signer |
| packages/sdk-4337/src/client/actions/deploy.ts | Updates deployment action to support optional session validator installation |
| examples/demo-app/components/*.vue | UI components for session configuration, creation, and transaction sending |
| examples/demo-app/tests/web-sdk-test.spec.ts | E2E tests for session deployment, creation, and transaction flows |
| pnpm-lock.yaml | Dependency updates (Vue 3.5.22→3.5.24, wasm-pack 0.12.1→0.13.1, @types/bun 1.3.1→1.3.2) |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
just in case
The sessionSpecToJSON function was missing the field when serializing constraints in call policies. This caused 'Invalid SessionSpec JSON' errors when the WASM bindings tried to parse the JSON. Each Constraint has a limit: UsageLimit field that was being omitted during JSON serialization, causing the Rust deserializer to fail at the position where it expected the limit field. This fix ensures all Constraint objects include their limit field in the serialized JSON, matching the expected schema.
JackHamer09
reviewed
Nov 17, 2025
not needed
uses rust now to encode
deps are the same
not needed
linked to web-sdk
JackHamer09
approved these changes
Nov 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Viem Session SDK - PR Description
Generated Description Below
📋 Summary
This PR implements comprehensive session key support for the viem-based ERC-4337
SDK, enabling delegated transaction signing with enforced on-chain policy
limits. The implementation bridges Rust WASM bindings with TypeScript SDK layers
to provide full session management capabilities.
🎯 What's Changed
Core Features Added
Session Account Implementation (
packages/sdk-4337/src/client/session/)toSessionSmartAccount()- Creates viem-compatible smart accounts usingsession keys
keyed_nonce()Session Creation
(
packages/sdk-4337/src/client/actions/createSession.ts)Session Deployment Support
(
packages/sdk-4337/src/client/actions/deploy.ts)Session Types & Utilities
(
packages/sdk-4337/src/client/session/types.ts)TransferPolicy)
compatibility
Rust Core Enhancements
Location:
packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-core/WASM-Safe Session Signature Generation (
session/signature_wasm.rs)session_signature_no_validation()- Creates session signatures withouttimestamp validation
get_period_id_no_validation()- Computes period IDs without system timedependencies
std::time::SystemTime)Session Encoding Utilities (
session/encode.rs)encode_session_user_operation()- Encodes session execute callsgenerate_session_stub_signature()- Generates stub signatures for gasestimation
Session Deployment (
session/deploy.rs)SessionValidatorConfigstruct for deployment configurationKeyed Nonce Support (
session/send.rs)keyed_nonce()- Derives session-specific nonce keys from signer addressesWASM Bindings
Location:
packages/sdk-platforms/rust/zksync-sso-erc4337-ffi-web/New WASM exports for web/node environments:
encode_session_execute_call_data()- Encode session execute callsgenerate_session_stub_signature_wasm()- Generate stub signaturessession_signature_no_validation_wasm()- Create real session signatureskeyed_nonce_decimal()- Compute keyed nonces (returns decimal string)Updated exports in:
packages/sdk-platforms/web/src/bundler.tspackages/sdk-platforms/web/src/node.tsDemo Application Integration
Location:
examples/demo-app/SessionConfig Component (
components/SessionConfig.vue)SessionCreator Component (
components/SessionCreator.vue)SessionTransactionSender Component
(
components/SessionTransactionSender.vue)toSessionSmartAccount()and bundler clientE2E Tests (
tests/web-sdk-test.spec.ts)🔧 Technical Highlights
Design Decisions
WASM-Safe Time Handling
std::timefunctionsNumeric Enum Values
LimitTypeandConstraintConditionuse numeric values (0, 1, 2, etc.)LIMIT_PERIODSconstants for time-based allowancesSessionSpec JSON Format
JSON.stringify()serde_jsonparsing on Rust sideKeyed Nonce Architecture
Stub Signatures for Gas Estimation
getStubSignature()for viem account abstractionTest Coverage
Rust Tests:
rustfmtTypeScript Tests:
E2E Tests:
Test Fix (Latest Change):
test_send_transaction_session_missing_keyed_noncein Rustbundler returns "AA23 reverted"
validation failure)
📦 Files Changed
Created (11 files)
packages/sdk-4337/src/client/session/account.ts- Session smart accountpackages/sdk-4337/src/client/session/types.ts- TypeScript typespackages/sdk-4337/src/client/session/utils.ts- Helper functionspackages/sdk-4337/src/client/session/index.ts- Exportspackages/sdk-4337/src/client/session/session.test.ts- Unit tests (NEW)packages/sdk-4337/src/client/actions/createSession.ts- CreateSessionaction
packages/sdk-platforms/web/src/session.test.ts- WASM binding tests (NEW)crates/.../session/signature_wasm.rs- WASM-safe signature generationcrates/.../session/encode.rs- Session encoding utilitiesexamples/demo-app/components/SessionConfig.vue- Session UIexamples/demo-app/components/SessionCreator.vue- Session creation UIexamples/demo-app/components/SessionTransactionSender.vue- Sessiontransaction UI
Modified (10 files)
packages/sdk-4337/src/client/actions/deploy.ts- Session deployment supportpackages/sdk-4337/src/client/actions/index.ts- Added createSession exportpackages/sdk-platforms/rust/.../session/send.rs- Test fix for AA23 error(LATEST)
packages/sdk-platforms/rust/.../session/deploy.rs- SessionValidatorConfigpackages/sdk-platforms/rust/.../ffi-web/src/lib.rs- WASM exportspackages/sdk-platforms/web/src/bundler.ts- Session function exportspackages/sdk-platforms/web/src/node.ts- Session function exportsexamples/demo-app/pages/web-sdk-test.vue- Session integrationexamples/demo-app/tests/web-sdk-test.spec.ts- E2E testsexamples/demo-app/public/contracts.json- Contract addresses🚀 API Usage Example
🔍 Breaking Changes
For New Users
None - this is a new feature addition.
For Legacy SDK Users (Migrating from
packages/sdk)LimitType.Lifetime = 1→ Use numeric enums directlysendTransaction()→sendUserOperation()withcallsarray
SessionConfig→SessionSpec(alias provided forcompatibility)
✅ CI Status
All checks passing:
cargo +nightly fmt)📝 Latest Changes (Test Fix)
Commit: Fix failing nextest in Rust CI
Problem: Test
test_send_transaction_session_missing_keyed_noncewasfailing because it expected error messages containing "User operation" or
"estimate", but the bundler returns the specific ERC-4337 error code "AA23
reverted" (validation failure during UserOperation execution).
Solution: Updated error assertion to accept AA23 error code:
Result: Test now passes successfully (1/1 passing in 18.4 seconds).
🎯 Next Steps
🙏 Review Notes
addModule)createSessionaction)createSessionmustexactly match the spec in
toSessionSmartAccount(including zero addressesvs. real addresses)
validation fails, now properly handled in tests
timestamps for browser safety