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

Session Key Manager module implementation #258

Merged
merged 5 commits into from
Aug 22, 2023

Conversation

AmanRaj1608
Copy link
Contributor

SessionKeyManagerModule implementation

User flow to add a session key

const biconomyAccount = new BiconomySmartAccount();
const biconomySessionManager = await SessionKeyManagerModule.create();

const sessionKeyData = await createSessionData({
  validUntil: 0,
  validAfter: 0,
  sessionValidationModuleAddress: "0xeeee address of module (eg: erc20)",
  sessionKeyData: "0xabc data",
});

const tx = {
  to: await biconomyAccount.address,
  data: sessionKeyData,
  value: 0,
}

const partialUserOp = await biconomySmartAccount.buildUserOp([tx]);
const userOpResponse = await biconomySmartAccount.sendUserOp(partialUserOp);

// after success tx set the sessionKey in the session manager
if(userOpResponse.status === "success") {
  await biconomySessionManager.setSessionKey(sessionKey);  
}

User flow to do a transaction with session key

const biconomyAccount = new BiconomySmartAccount();
const biconomySessionManager = await SessionKeyManagerModule.create();

const tx = {
  to: "0xabc",
  data: "0x",
  value: 0.1,
}

// Not sure what is the process here cc: @livingrockrises @tomarsachin2271 
// - does the SDK calls the signUserOp with the session key?
// - or the user calls the signUserOp with the session key?

const partialUserOp = await biconomySmartAccount.buildUserOp([tx]);
const sig = await biconomySessionManager.signUserOp(partialUserOp, sessionSigner);
partialUserOp.signature = sig;

const userOpResponse = await biconomySmartAccount.sendUserOp(partialUserOp);

@linear
Copy link

linear bot commented Aug 20, 2023

SMA-61 Session Key Manager Module implementation

Implement the SessionKeyManagerModule with

  • create → static constructor
  • createSessionData → generates the sessionData
  • signUserOp → signs the userOp from sessionEOA

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

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

left some comments

@AmanRaj1608 AmanRaj1608 merged commit 6771d66 into feat/modular-SA-V2-integration Aug 22, 2023
packages/modules/src/BaseValidationModule.ts Outdated Show resolved Hide resolved
instance.sessionStorageClient = new SessionLocalStorage(moduleConfig.smartAccountAddress)

const existingSessionData = await instance.sessionStorageClient.getAllSessionData()
const existingSessionDataLeafs = existingSessionData.map((sessionData) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Exclude the sessions whose validUltil date has passed or status is EXPIRED.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the merkle tree will still have the data its just it will be validate on chain? It should have all the data as per the discussion we had today

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah as per the discussion, all the pending state sessions should be part of the merkle tree. Even though this recommended change doesn't affect the functionality in any way but it's just optimised way of doing things, where we can get rid of expired session leafs.
Coz over time the leaves will keep on getting added and there's a limit of data that can be stored in local storage.

Not critical but we can add a TODO here to handle this later may be.

@AmanRaj1608 AmanRaj1608 deleted the SMA-61-SessionManager branch September 29, 2023 03:32
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.

3 participants