@@ -168,32 +168,6 @@ export type SmartSessionClient = {
168168 signMessage : ( { message } : { message : SignableMessage } ) => Promise < Hex > ;
169169} ;
170170
171- const getOwnerAccount = ( owner : WalletClient | string ) : { account : Account | WalletClient ; address : Address } => {
172- if ( typeof owner === 'string' ) {
173- return {
174- account : toAccount ( {
175- address : owner as `0x${string } `,
176- signMessage : async ( ) => {
177- throw new Error ( 'This account cannot sign messages' ) ;
178- } ,
179- signTransaction : async ( ) => {
180- throw new Error ( 'This account cannot sign transactions' ) ;
181- } ,
182- signTypedData : async ( ) => {
183- throw new Error ( 'This account cannot sign typed data' ) ;
184- } ,
185- } ) ,
186- address : owner as `0x${string } `,
187- } ;
188- }
189- if ( ! owner . account ) {
190- throw new Error ( 'Wallet client must be an account' ) ;
191- }
192- return {
193- account : owner ,
194- address : owner . account . address ,
195- } ;
196- } ;
197171// Gets the legacy Geo smart account wallet client. If the smart account returned
198172// by this function is deployed, it means it might need to be updated to have the 7579 module installed
199173const getLegacySmartAccountWalletClient = async ( {
@@ -202,7 +176,7 @@ const getLegacySmartAccountWalletClient = async ({
202176 rpcUrl = DEFAULT_RPC_URL ,
203177 apiKey = DEFAULT_API_KEY ,
204178} : {
205- owner : WalletClient | string ;
179+ owner : WalletClient | Account ;
206180 chain ?: Chain ;
207181 rpcUrl ?: string ;
208182 apiKey ?: string ;
@@ -215,7 +189,7 @@ const getLegacySmartAccountWalletClient = async ({
215189
216190 const safeAccount = await toSafeSmartAccount ( {
217191 client : publicClient ,
218- owners : [ getOwnerAccount ( owner ) . account ] ,
192+ owners : [ owner ] ,
219193 entryPoint : {
220194 // optional, defaults to 0.7
221195 address : entryPoint07Address ,
@@ -257,29 +231,31 @@ const get7579SmartAccountWalletClient = async ({
257231 rpcUrl = DEFAULT_RPC_URL ,
258232 apiKey = DEFAULT_API_KEY ,
259233} : {
260- owner : WalletClient | string ;
234+ owner : WalletClient | Account ;
261235 address ?: Hex ;
262236 chain ?: Chain ;
263237 rpcUrl ?: string ;
264238 apiKey ?: string ;
265239} ) : Promise < SmartAccountClient > => {
266- const ownerAccount = getOwnerAccount ( owner ) ;
267-
268240 const transport = http ( rpcUrl ) ;
269241 const publicClient = createPublicClient ( {
270242 transport,
271243 chain,
272244 } ) ;
245+ const ownerAddress = 'account' in owner ? owner . account ?. address : owner . address ;
246+ if ( ! ownerAddress ) {
247+ throw new Error ( 'Owner address not found' ) ;
248+ }
273249
274250 const ownableValidator = getOwnableValidator ( {
275- owners : [ ownerAccount . address ] ,
251+ owners : [ ownerAddress ] ,
276252 threshold : 1 ,
277253 } ) ;
278254 const smartSessionsValidator = getSmartSessionsValidator ( { } ) ;
279255
280256 const safeAccountParams : ToSafeSmartAccountParameters < '0.7' , Hex > = {
281257 client : publicClient ,
282- owners : [ ownerAccount . account ] ,
258+ owners : [ owner ] ,
283259 version : '1.4.1' as const ,
284260 entryPoint : {
285261 address : entryPoint07Address ,
@@ -349,7 +325,7 @@ export const getSmartAccountWalletClient = async ({
349325 rpcUrl = DEFAULT_RPC_URL ,
350326 apiKey = DEFAULT_API_KEY ,
351327} : {
352- owner : WalletClient | string ;
328+ owner : WalletClient | Account ;
353329 address ?: Hex ;
354330 chain ?: Chain ;
355331 rpcUrl ?: string ;
@@ -559,7 +535,7 @@ const getSpaceActions = (space: { address: Hex; type: 'personal' | 'public' }) =
559535// It will return the permissionId that can be used to create a smart session client.
560536export const createSmartSession = async (
561537 walletClient : WalletClient ,
562- smartAccountClient : SmartAccountClient ,
538+ accountAddress : Hex ,
563539 sessionPrivateKey : Hex ,
564540 chain : Chain ,
565541 rpcUrl : string ,
@@ -576,12 +552,21 @@ export const createSmartSession = async (
576552 additionalActions ?: Action [ ] ;
577553 } = { } ,
578554) : Promise < Hex > => {
555+ const smartAccountClient = await getSmartAccountWalletClient ( {
556+ owner : walletClient ,
557+ address : accountAddress ,
558+ chain,
559+ rpcUrl,
560+ } ) ;
579561 if ( ! smartAccountClient . account ) {
580- throw new Error ( 'Invalid smart account ' ) ;
562+ throw new Error ( 'Invalid wallet client ' ) ;
581563 }
582564 if ( ! smartAccountClient . account . isDeployed ( ) ) {
583565 throw new Error ( 'Smart account must be deployed' ) ;
584566 }
567+ if ( await smartAccountNeedsUpdate ( smartAccountClient , chain , rpcUrl ) ) {
568+ throw new Error ( 'Smart account needs to be updated' ) ;
569+ }
585570 if ( ! smartAccountClient . chain ) {
586571 throw new Error ( 'Invalid smart account chain' ) ;
587572 }
@@ -746,16 +731,30 @@ export const createSmartSession = async (
746731// This is the function that we use on the end user app to create a smart session client that can send transactions to the smart account.
747732// The session must have previously been created by the createSmartSession function.
748733// The client also includes a signMessage function that can be used to sign messages with the session key.
749- export const getSmartSessionClient = (
750- smartAccountClient : SmartAccountClient ,
751- sessionPrivateKey : Hex ,
752- permissionId : Hex ,
753- chain : Chain ,
754- rpcUrl : string ,
755- ) : SmartSessionClient => {
756- if ( ! smartAccountClient . account ) {
757- throw new Error ( 'Invalid smart account' ) ;
758- }
734+ export const getSmartSessionClient = async ( {
735+ accountAddress,
736+ chain = GEOGENESIS ,
737+ rpcUrl = DEFAULT_RPC_URL ,
738+ apiKey = DEFAULT_API_KEY ,
739+ sessionPrivateKey,
740+ permissionId,
741+ } : {
742+ accountAddress : Hex ;
743+ chain ?: Chain ;
744+ rpcUrl ?: string ;
745+ apiKey ?: string ;
746+ sessionPrivateKey : Hex ;
747+ permissionId : Hex ;
748+ } ) : Promise < SmartSessionClient > => {
749+ const sessionKeyAccount = privateKeyToAccount ( sessionPrivateKey ) ;
750+ const smartAccountClient = await getSmartAccountWalletClient ( {
751+ owner : sessionKeyAccount , // Won't really be used, but we need to pass in an account
752+ address : accountAddress ,
753+ chain,
754+ rpcUrl,
755+ apiKey,
756+ } ) ;
757+
759758 const sessionDetails = {
760759 mode : SmartSessionMode . USE ,
761760 permissionId,
@@ -768,7 +767,7 @@ export const getSmartSessionClient = (
768767 transport : http ( rpcUrl ) ,
769768 chain,
770769 } ) ;
771- const sessionKeyAccount = privateKeyToAccount ( sessionPrivateKey ) ;
770+
772771 return {
773772 sendTransaction : async < const calls extends readonly unknown [ ] > ( { calls } : { calls : calls } ) => {
774773 if ( ! smartAccountClient . account ) {
0 commit comments