Skip to content

Commit

Permalink
feat: add multichain enable functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Oct 16, 2024
1 parent 24f3625 commit fc47e6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/module/smart-sessions/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,15 @@ export const getDisableActionPoliciesAction = ({
export const getEnableSessionDetails = async ({
sessions,
sessionIndex,
enableMode,
account,
client,
clients,
}: {
sessions: Session[]
sessionIndex?: number
enableMode?: SmartSessionModeType
account: Account
client: PublicClient
clients: PublicClient[]
}) => {
const chainDigests = []
const chainSessions: ChainSession[] = []
Expand All @@ -604,6 +606,14 @@ export const getEnableSessionDetails = async ({
session,
})

const client = clients.find(
(c) => BigInt(c.chain?.id ?? 0) === session.chainId,
)

if (!client) {
throw new Error(`Client not found for chainId ${session.chainId}`)
}

const sessionNonce = await getSessionNonce({
client,
account,
Expand All @@ -614,7 +624,7 @@ export const getEnableSessionDetails = async ({
client,
account,
session,
mode: SmartSessionMode.ENABLE,
mode: enableMode || SmartSessionMode.ENABLE,
permissionId,
})

Expand All @@ -629,7 +639,7 @@ export const getEnableSessionDetails = async ({
...session,
account: account.address,
smartSession: SMART_SESSIONS_ADDRESS,
mode: 1,
mode: Number(enableMode) || Number(SmartSessionMode.ENABLE),
nonce: sessionNonce,
},
})
Expand All @@ -644,7 +654,7 @@ export const getEnableSessionDetails = async ({

return {
permissionEnableHash,
mode: SmartSessionMode.ENABLE,
mode: enableMode || SmartSessionMode.ENABLE,
permissionId,
signature: '0x' as Hex,
enableSessionData: {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/modules/smartSessionsValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const testSmartSessionsValidator = async ({
const sessionDetails = await getEnableSessionDetails({
sessions: [session],
account,
client: publicClient,
clients: [publicClient],
})

sessionDetails.enableSessionData.enableSession.permissionEnableSig =
Expand Down

0 comments on commit fc47e6e

Please sign in to comment.