From 3d3158fd2e2801d4e0f0954210dee31170f3bc5a Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Tue, 15 Jul 2025 09:28:26 +1200 Subject: [PATCH] Add modify explicit session --- packages/wallet/wdk/src/sequence/sessions.ts | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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) }