@@ -134,8 +134,21 @@ export class SessionManager implements SapientSigner {
134134 }
135135
136136 async findSignersForCalls ( wallet : Address . Address , chainId : number , calls : Payload . Call [ ] ) : Promise < SessionSigner [ ] > {
137+ if ( ! Address . isEqual ( this . wallet . address , wallet ) ) {
138+ throw new Error ( 'Wallet address mismatch' )
139+ }
137140 // Only use signers that match the topology
138141 const topology = await this . topology
142+ return this . _findSignersForCalls ( wallet , chainId , calls , topology )
143+ }
144+
145+ private async _findSignersForCalls (
146+ wallet : Address . Address ,
147+ chainId : number ,
148+ calls : Payload . Call [ ] ,
149+ topology : SessionConfig . SessionsTopology ,
150+ ) : Promise < SessionSigner [ ] > {
151+ // Only use signers that match the topology
139152 const identitySigner = SessionConfig . getIdentitySigner ( topology )
140153 if ( ! identitySigner ) {
141154 throw new Error ( 'Identity signer not found' )
@@ -176,11 +189,24 @@ export class SessionManager implements SapientSigner {
176189 wallet : Address . Address ,
177190 chainId : number ,
178191 calls : Payload . Call [ ] ,
192+ ) : Promise < Payload . Call | null > {
193+ if ( ! Address . isEqual ( wallet , this . wallet . address ) ) {
194+ throw new Error ( 'Wallet address mismatch' )
195+ }
196+ const topology = await this . topology
197+ return this . _prepareIncrement ( wallet , chainId , calls , topology )
198+ }
199+
200+ private async _prepareIncrement (
201+ wallet : Address . Address ,
202+ chainId : number ,
203+ calls : Payload . Call [ ] ,
204+ topology : SessionConfig . SessionsTopology ,
179205 ) : Promise < Payload . Call | null > {
180206 if ( calls . length === 0 ) {
181207 throw new Error ( 'No calls provided' )
182208 }
183- const signers = await this . findSignersForCalls ( wallet , chainId , calls )
209+ const signers = await this . _findSignersForCalls ( wallet , chainId , calls , topology )
184210
185211 // Create a map of signers to their associated calls
186212 const signerToCalls = new Map < SessionSigner , Payload . Call [ ] > ( )
@@ -258,7 +284,7 @@ export class SessionManager implements SapientSigner {
258284 throw new Error ( `Space ${ payload . space } is too large` )
259285 }
260286
261- const signers = await this . findSignersForCalls ( wallet , chainId , payload . calls )
287+ const signers = await this . _findSignersForCalls ( wallet , chainId , payload . calls , topology )
262288 if ( signers . length !== payload . calls . length ) {
263289 throw new Error ( 'No signer supported for call' )
264290 }
@@ -274,7 +300,7 @@ export class SessionManager implements SapientSigner {
274300 )
275301
276302 // Check if the last call is an increment usage call
277- const expectedIncrement = await this . prepareIncrement ( wallet , chainId , payload . calls )
303+ const expectedIncrement = await this . _prepareIncrement ( wallet , chainId , payload . calls , topology )
278304 if ( expectedIncrement ) {
279305 let actualIncrement : Payload . Call
280306 if (
0 commit comments