diff --git a/packages/wallet/wdk/src/sequence/sessions.ts b/packages/wallet/wdk/src/sequence/sessions.ts index 0ef04b30e..7c25f338b 100644 --- a/packages/wallet/wdk/src/sequence/sessions.ts +++ b/packages/wallet/wdk/src/sequence/sessions.ts @@ -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 { + // 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, @@ -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) }