11import type { Address , Hex } from "viem" ;
2- import { createPublicClient , createWalletClient , http , publicActions } from "viem" ;
2+ import { createPublicClient , http } from "viem" ;
33import { createBundlerClient } from "viem/account-abstraction" ;
4- import { privateKeyToAccount } from "viem/accounts" ;
54import type { Chain } from "viem/chains" ;
5+ import { getGeneralPaymasterInput } from "viem/zksync" ;
66import { createPasskeyClient } from "zksync-sso-4337/client" ;
77
8- import contractsConfig from "../contracts-anvil.json" ;
9-
108// Anvil chain configuration (chain ID 31337)
119const anvilChain : Chain = {
1210 id : 31337 ,
@@ -31,11 +29,26 @@ export const useClientStore = defineStore("client", () => {
3129
3230 const getBundlerClient = ( ) => {
3331 const publicClient = getPublicClient ( ) ;
32+ const runtimeConfig = useRuntimeConfig ( ) ;
33+ const paymasterAddress = runtimeConfig . public . contracts . paymaster as Address ;
34+ const bundlerUrl = runtimeConfig . public . bundlerUrl as string ;
3435
3536 return createBundlerClient ( {
3637 client : publicClient ,
3738 chain,
38- transport : http ( contractsConfig . bundlerUrl ) ,
39+ transport : http ( bundlerUrl ) ,
40+ paymaster : {
41+ async getPaymasterData ( ) {
42+ return {
43+ paymasterAndData : `${ paymasterAddress } ${ getGeneralPaymasterInput ( { innerInput : "0x" } ) . substring ( 2 ) } ` as Hex ,
44+ } ;
45+ } ,
46+ async getPaymasterStubData ( ) {
47+ return {
48+ paymasterAndData : `${ paymasterAddress } ${ getGeneralPaymasterInput ( { innerInput : "0x" } ) . substring ( 2 ) } ` as Hex ,
49+ } ;
50+ } ,
51+ } ,
3952 userOperation : {
4053 async estimateFeesPerGas ( ) {
4154 const feesPerGas = await publicClient . estimateFeesPerGas ( ) ;
@@ -54,12 +67,13 @@ export const useClientStore = defineStore("client", () => {
5467 if ( ! address . value ) throw new Error ( "Address is not set" ) ;
5568 if ( ! credentialId . value ) throw new Error ( "Credential ID is not set" ) ;
5669
70+ const runtimeConfig = useRuntimeConfig ( ) ;
5771 const bundlerClient = getBundlerClient ( ) ;
5872
5973 const client = createPasskeyClient ( {
6074 account : {
6175 address : address . value ,
62- validatorAddress : contractsConfig . webauthnValidator as Address ,
76+ validatorAddress : runtimeConfig . public . contracts . webauthnValidator as Address ,
6377 credentialId : credentialId . value ,
6478 rpId : window . location . hostname ,
6579 origin : window . location . origin ,
@@ -72,31 +86,20 @@ export const useClientStore = defineStore("client", () => {
7286 return client ;
7387 } ;
7488
75- const getThrowAwayClient = ( ) => {
76- const throwAwayClient = createWalletClient ( {
77- account : privateKeyToAccount (
78- "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" , // Anvil rich account
79- ) ,
80- chain,
81- transport : http ( ) ,
82- } )
83- . extend ( publicActions ) ;
84- return throwAwayClient ;
85- } ;
86-
8789 const getConfigurableClient = ( {
8890 address : addr ,
8991 credentialId : credId ,
9092 } : {
9193 address : Address ;
9294 credentialId : Hex ;
9395 } ) => {
96+ const runtimeConfig = useRuntimeConfig ( ) ;
9497 const bundlerClient = getBundlerClient ( ) ;
9598
9699 return createPasskeyClient ( {
97100 account : {
98101 address : addr ,
99- validatorAddress : contractsConfig . webauthnValidator as Address ,
102+ validatorAddress : runtimeConfig . public . contracts . webauthnValidator as Address ,
100103 credentialId : credId ,
101104 rpId : window . location . hostname ,
102105 origin : window . location . origin ,
@@ -109,11 +112,9 @@ export const useClientStore = defineStore("client", () => {
109112
110113 return {
111114 chain,
112- contractsConfig,
113115 getPublicClient,
114116 getBundlerClient,
115117 getClient,
116- getThrowAwayClient,
117118 getConfigurableClient,
118119 } ;
119120} ) ;
0 commit comments