Skip to content

Add modify explicit session #812

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/wallet/wdk/src/sequence/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,25 @@ export class Sessions implements SessionsInterface {
return this.prepareSessionUpdate(walletAddress, newTopology, origin)
}

async modifyExplicitSession(
walletAddress: Address.Address,
sessionAddress: Address.Address,
permissions: CoreSigners.Session.ExplicitParams,
origin?: string,
): Promise<string> {
// This will add the session manager if it's missing
const topology = await this.getTopology(walletAddress, true)
const intermediateTopology = SessionConfig.removeExplicitSession(topology, sessionAddress)
if (!intermediateTopology) {
throw new Error('Incomplete session topology')
}
const newTopology = SessionConfig.addExplicitSession(intermediateTopology, {
...permissions,
signer: sessionAddress,
})
return this.prepareSessionUpdate(walletAddress, newTopology, origin)
}

async removeExplicitSession(
walletAddress: Address.Address,
sessionAddress: Address.Address,
Expand All @@ -318,7 +337,7 @@ export class Sessions implements SessionsInterface {
const topology = await this.getTopology(walletAddress)
const newTopology = SessionConfig.removeExplicitSession(topology, sessionAddress)
if (!newTopology) {
throw new Error('Session not found')
throw new Error('Incomplete session topology')
}
return this.prepareSessionUpdate(walletAddress, newTopology, origin)
}
Expand Down