Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sessions dx #486

Merged
merged 63 commits into from
May 14, 2024
Merged

chore: sessions dx #486

merged 63 commits into from
May 14, 2024

Conversation

joepegler
Copy link
Collaborator

@joepegler joepegler commented May 3, 2024

Improved dx around creating and using a session. See here for an example


PR-Codex overview

This PR focuses on improving session management and smart account functionalities.

Detailed summary

  • Added session storage options for better session management
  • Enhanced ERC20 session validation module
  • Updated error messages for clarity
  • Improved smart account ownership transfer handling

The following files were skipped due to too many changes: src/modules/interfaces/ISessionStorage.ts, src/account/utils/Logger.ts, examples/SEND_SOME_ETH_WITH_SPONSORSHIP.md, src/modules/session-storage/utils.ts, src/modules/utils/Constants.ts, src/modules/utils/Types.ts, examples/SEND_A_MULTI_TX_AND_PAY_GAS_WITH_TOKEN.md, examples/INITIALISE_A_SMART_CONTRACT.md, src/account/BiconomySmartAccountV2.ts, src/modules/utils/Helper.ts, src/modules/session-storage/SessionFileStorage.ts, examples/CREATE_AND_USE_A_SESSION.md, src/modules/session-storage/SessionMemoryStorage.ts, examples/CREATE_AND_USE_A_BATCH_SESSION.md, src/modules/session-storage/SessionLocalStorage.ts, src/modules/sessions/sessionSmartAccountClient.ts, README.md, tests/modules/read.test.ts, src/modules/sessions/batch.ts, src/modules/sessions/abi.ts, tests/modules/write.test.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@joepegler joepegler changed the title Feature/sma 792 sessions devex chore: sessions devex May 3, 2024
@joepegler joepegler changed the title chore: sessions devex chore: sessions dx May 3, 2024
Copy link

github-actions bot commented May 3, 2024

size-limit report 📦

Path Size
core (esm) 53.68 KB (+2.6% 🔺)
core (cjs) 58.61 KB (+2.96% 🔺)
account (tree-shaking) 51.85 KB (+1.09% 🔺)
bundler (tree-shaking) 2.37 KB (+1.51% 🔺)
paymaster (tree-shaking) 2.29 KB (+0.95% 🔺)
modules (tree-shaking) 40.48 KB (+1.07% 🔺)

@joepegler joepegler marked this pull request as ready for review May 3, 2024 16:22
src/modules/sessions/abi.ts Outdated Show resolved Hide resolved
src/modules/sessions/abi.ts Outdated Show resolved Hide resolved
src/modules/sessions/multi.ts Outdated Show resolved Hide resolved
src/modules/sessions/sessionSmartAccountClient.ts Outdated Show resolved Hide resolved
const { sessionKeyAddress, sessionStorageClient } =
await createAndStoreNewSessionKey(smartAccount, chain);

const { wait, session } = await createSession(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a situation where passed smartAccount and sessionKeyAddress arguments would be different then the ones calculate above ? If not, we could improve this even more by removing the need to pass smartAccount and sessionKeyAddress in the "createSession" method. You could bind the method to the smartAccount like await smartAccount.createSession([{contractAddress: "0x...", functionSelector: "safeMint(address)", rules: ....}], sessionStorageClient, {paymasterServiceData ...})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for a technical reason, at some point soon I want to move sessions into it's own repo because it imports merkletree. If I add the 'createSession' method to the smartAccount then the session code would need to live in the accounts package permanently, like paymaster and bundler etc. Keeping this setup will facilitate the future removal of the relatively large sessions package from our accounts package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is specific to creating a session struct using ABI svm?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it will also send tx on-chain to set session using current active validation module(default ecdsa) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is for ABI svm. Just using a more accessible term. Yes it encorporates the tx to change the validation module, if required

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the userop that gets built for this only supports single tx? setting one session struct on-chain on SKM.
or calldata batch is enabled where you set multiple sessions and also get session ids back in return along with tx hash.

using via multi-chain validation module goes one step further where you can send multiple userops (each op can have multiple session enabling as part of calldata batch on particular chain) that enables several same session on multiple chains

examples/SEND_SOME_ETH_WITH_SPONSORSHIP.md Outdated Show resolved Hide resolved
joepegler and others added 4 commits May 9, 2024 10:16
Co-authored-by: Vasile Gabriel Marian <56271768+VGabriel45@users.noreply.github.com>
Co-authored-by: Vasile Gabriel Marian <56271768+VGabriel45@users.noreply.github.com>
Co-authored-by: Vasile Gabriel Marian <56271768+VGabriel45@users.noreply.github.com>
Co-authored-by: Vasile Gabriel Marian <56271768+VGabriel45@users.noreply.github.com>
const smartAccountAddress = await smartAccount.getAccountAddress();

const { sessionKeyAddress, sessionStorageClient } =
await createAndStoreNewSessionKey(smartAccount, chain);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will just create a new key pair? store it where?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createAndStoreNewSessionKey has three arguments. The third is optional and isn't used here: ISessionStorage. If the third argument isn't used then it will pick a storage client for you by default: localStorage if in the browser and FileStorage if not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it and this storage client stores leaf info and by default stores pk in there as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current majorly used devx i have seen from dapps and demos is
i. client creates session keypair and passes session key eoa to us. keeps pk with them but pases ethers signer object

ii. during the op you pass which session key eoa and which SVM address (or session id) useful to find a leaf and corresponding proof - for dummy sig, original sig stuff

Copy link
Collaborator Author

@joepegler joepegler May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. Passing the whole store back to the sdk doesn't make sense. I thought it would be more convenient but it's less secure. I will simplify this a bit and make the store less engrained.

@livingrockrises
Copy link
Collaborator

can you also add list of all new methods added and description natspecs

This is already in the PR... Is there something you've noticed that I've missed?

createMultiSession

createSession

createSessionSmartAccountClient

and the one that was missing: createAndStoreNewSessionKey

I like createSessionKeyEOA (later could become createSessionKeyEOAWithPermissions with mpc network capabilities)
such can be used later on to change the implementation and register user on silence network

@joepegler joepegler force-pushed the feature/SMA-792_sessions-devex branch from 9c05c9d to 81d8d39 Compare May 13, 2024 10:34
This reverts commit c49a1b2.

chore: lint

chore: parseReferenceValue

chore: fix helper

chore: helper
@joepegler joepegler force-pushed the feature/SMA-792_sessions-devex branch from 81d8d39 to 5c47361 Compare May 13, 2024 11:02
joepegler and others added 19 commits May 13, 2024 12:15
* feat/transfer_ownership(in progress)

* cleanup

* fix linting

* added test for transferOwnership with session key manager module

* Fix linting

* refactor: refactor based on PR review

* improve ts doc + refactor tests

* added "moduleAddress" param to transferOwnership()

* fix module tests

* removed console.logs

* fixed lint + removed unused import

* remove unused import

* added argument type for module address

---------

Co-authored-by: GabiDev <gv@popoo.io>
* release v4.3.0

* refactor: increase timeout for transferOwnership tests

---------

Co-authored-by: GabiDev <gv@popoo.io>
@joepegler joepegler merged commit b9b2077 into main May 14, 2024
5 checks passed
@joepegler joepegler deleted the feature/SMA-792_sessions-devex branch May 14, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants