@tuwaio/satellite-evm 1.0.0-fix-test-alpha.59.8fde9e1 → 1.0.0-fix-test-alpha.61.e356934
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -29
- package/dist/index.d.ts +7 -29
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseWallet, SatelliteAdapter, ConnectorsInitProps } from '@tuwaio/satellite-core';
|
|
2
2
|
import { Connector, CreateConnectorFn, Config, CreateConfigParameters } from '@wagmi/core';
|
|
3
3
|
import { Chain } from 'viem/chains';
|
|
4
|
+
import { Transport } from 'viem';
|
|
4
5
|
|
|
5
6
|
/** EVM-specific connector type */
|
|
6
7
|
type ConnectorEVM = Connector<CreateConnectorFn>;
|
|
@@ -118,36 +119,13 @@ declare function checkIsWalletAddressContract({ config, address, chainId, chains
|
|
|
118
119
|
}): Promise<boolean>;
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
|
-
* Creates
|
|
122
|
+
* Creates default HTTP transports for each chain in the configuration
|
|
122
123
|
*
|
|
123
|
-
* @
|
|
124
|
-
*
|
|
125
|
-
* It automatically sets up HTTP transports for each chain if custom transports are not provided.
|
|
126
|
-
*
|
|
127
|
-
* @param config - Combined configuration parameters for Satellite and Wagmi
|
|
128
|
-
* @param config.chains - Array of supported blockchain networks
|
|
129
|
-
* @param config.transports - Optional custom transport configurations for each chain
|
|
130
|
-
* @param config.projectId - WalletConnect project ID
|
|
131
|
-
* @param config.appName - Application name for wallet connection UI
|
|
132
|
-
* @param config.appUrl - Application URL for metadata
|
|
133
|
-
* @param config.appLogoUrl - URL to application logo
|
|
134
|
-
* @param config.appLogo - Optional inline logo data
|
|
135
|
-
* @param config.appIcons - Array of application icon URLs
|
|
136
|
-
* @param config.description - Application description for wallet connection UI
|
|
137
|
-
*
|
|
138
|
-
* @returns Configured Wagmi instance
|
|
124
|
+
* @param chains - Array of chain configurations from wagmi
|
|
125
|
+
* @returns Object mapping chain IDs to their corresponding HTTP transport instances
|
|
139
126
|
*
|
|
140
|
-
* @
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const config = createWagmiConfig({
|
|
143
|
-
* chains: [mainnet, polygon],
|
|
144
|
-
* projectId: "your_project_id",
|
|
145
|
-
* appName: "My dApp",
|
|
146
|
-
* appUrl: "https://mydapp.com",
|
|
147
|
-
* appLogoUrl: "https://mydapp.com/logo.png"
|
|
148
|
-
* });
|
|
149
|
-
* ```
|
|
127
|
+
* @public
|
|
150
128
|
*/
|
|
151
|
-
declare const
|
|
129
|
+
declare const createDefaultTransports: (chains: CreateConfigParameters["chains"]) => Record<number, Transport>;
|
|
152
130
|
|
|
153
|
-
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract,
|
|
131
|
+
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports, initAllConnectors, safeSdkOptions, satelliteEVMAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseWallet, SatelliteAdapter, ConnectorsInitProps } from '@tuwaio/satellite-core';
|
|
2
2
|
import { Connector, CreateConnectorFn, Config, CreateConfigParameters } from '@wagmi/core';
|
|
3
3
|
import { Chain } from 'viem/chains';
|
|
4
|
+
import { Transport } from 'viem';
|
|
4
5
|
|
|
5
6
|
/** EVM-specific connector type */
|
|
6
7
|
type ConnectorEVM = Connector<CreateConnectorFn>;
|
|
@@ -118,36 +119,13 @@ declare function checkIsWalletAddressContract({ config, address, chainId, chains
|
|
|
118
119
|
}): Promise<boolean>;
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
|
-
* Creates
|
|
122
|
+
* Creates default HTTP transports for each chain in the configuration
|
|
122
123
|
*
|
|
123
|
-
* @
|
|
124
|
-
*
|
|
125
|
-
* It automatically sets up HTTP transports for each chain if custom transports are not provided.
|
|
126
|
-
*
|
|
127
|
-
* @param config - Combined configuration parameters for Satellite and Wagmi
|
|
128
|
-
* @param config.chains - Array of supported blockchain networks
|
|
129
|
-
* @param config.transports - Optional custom transport configurations for each chain
|
|
130
|
-
* @param config.projectId - WalletConnect project ID
|
|
131
|
-
* @param config.appName - Application name for wallet connection UI
|
|
132
|
-
* @param config.appUrl - Application URL for metadata
|
|
133
|
-
* @param config.appLogoUrl - URL to application logo
|
|
134
|
-
* @param config.appLogo - Optional inline logo data
|
|
135
|
-
* @param config.appIcons - Array of application icon URLs
|
|
136
|
-
* @param config.description - Application description for wallet connection UI
|
|
137
|
-
*
|
|
138
|
-
* @returns Configured Wagmi instance
|
|
124
|
+
* @param chains - Array of chain configurations from wagmi
|
|
125
|
+
* @returns Object mapping chain IDs to their corresponding HTTP transport instances
|
|
139
126
|
*
|
|
140
|
-
* @
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const config = createWagmiConfig({
|
|
143
|
-
* chains: [mainnet, polygon],
|
|
144
|
-
* projectId: "your_project_id",
|
|
145
|
-
* appName: "My dApp",
|
|
146
|
-
* appUrl: "https://mydapp.com",
|
|
147
|
-
* appLogoUrl: "https://mydapp.com/logo.png"
|
|
148
|
-
* });
|
|
149
|
-
* ```
|
|
127
|
+
* @public
|
|
150
128
|
*/
|
|
151
|
-
declare const
|
|
129
|
+
declare const createDefaultTransports: (chains: CreateConfigParameters["chains"]) => Record<number, Transport>;
|
|
152
130
|
|
|
153
|
-
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract,
|
|
131
|
+
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports, initAllConnectors, safeSdkOptions, satelliteEVMAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var orbitCore=require('@tuwaio/orbit-core'),orbitEvm=require('@tuwaio/orbit-evm'),core=require('@wagmi/core'),viem=require('viem'),chains=require('viem/chains'),connectors=require('@wagmi/connectors'),utils=require('viem/utils');var f=new Map;async function y({config:
|
|
1
|
+
'use strict';var orbitCore=require('@tuwaio/orbit-core'),orbitEvm=require('@tuwaio/orbit-evm'),core=require('@wagmi/core'),viem=require('viem'),chains=require('viem/chains'),connectors=require('@wagmi/connectors'),utils=require('viem/utils');var f=new Map;async function y({config:t,address:n,chainId:r,chains:o}){if(f.has(n))return f.get(n);if(orbitEvm.createViemClient(r,o)){let e=!!await core.getBytecode(t,{address:n});return f.set(n,e),e}else return false}function le(t,n){if(!t)throw new Error("Satellite EVM adapter requires a wagmi config object.");return {key:orbitCore.OrbitAdapter.EVM,connect:async({walletType:r,chainId:o})=>{let s=core.getConnectors(t).find(e=>orbitCore.getWalletTypeFromConnectorName(orbitCore.OrbitAdapter.EVM,orbitCore.formatWalletName(e.name))===r);if(!s)throw new Error("Cannot find connector with this wallet type");try{await s.isAuthorized()&&await core.disconnect(t,{connector:s}),await core.connect(t,{connector:s,chainId:o}),n&&!orbitCore.isSafeApp&&await n();let e=core.getAccount(t);return {walletType:r,address:e.address??viem.zeroAddress,chainId:e.chainId??chains.mainnet.id,rpcURL:e.chain?.rpcUrls.default.http[0]??chains.mainnet.rpcUrls.default.http[0],isConnected:e.isConnected,isContractAddress:!1,walletIcon:s?.icon?.trim(),connector:s}}catch(e){throw new Error(e instanceof Error?e.message:String(e))}},disconnect:async()=>{let r=core.getConnectors(t);await Promise.allSettled(r.map(async o=>{await core.disconnect(t,{connector:o});}));},getConnectors:()=>{let r=core.getConnectors(t);return {adapter:orbitCore.OrbitAdapter.EVM,connectors:r.map(o=>o)}},checkAndSwitchNetwork:async r=>await orbitEvm.checkAndSwitchChain(Number(r),t),getBalance:async(r,o)=>{let a=await core.getBalance(t,{address:r,chainId:Number(o)});return {value:viem.formatUnits(a.value,a.decimals),symbol:a.symbol}},getExplorerUrl:r=>{let{chain:o}=core.getAccount(t),a=o?.blockExplorers?.default.url;return r?`${a}/${r}`:a},getName:r=>orbitEvm.getName(r),getAvatar:r=>orbitEvm.getAvatar(r),checkIsContractWallet:async({address:r,chainId:o})=>{let a=core.getChains(t);return await y({config:t,address:r,chainId:o,chains:a})},getSafeConnectorChainId:async()=>{let o=core.getConnectors(t).find(a=>a.name==="Safe");if(o)return await o.getChainId()}}}u.type="impersonated";function u(t){let n=t.features??{},r=false,o,a;return core.createConnector(s=>({id:"impersonated",name:"Impersonated Connector",type:u.type,async setup(){o=s.chains[0].id;},async connect({chainId:e}={}){if(n.connectError)throw typeof n.connectError=="boolean"?new viem.UserRejectedRequestError(new Error("Failed to connect.")):n.connectError;let{request:c}=await this.getProvider(),d=await c({method:"eth_requestAccounts"}),m=await this.getChainId();return e&&m!==e&&(m=(await this.switchChain({chainId:e})).id),r=true,{accounts:d,chainId:m}},async disconnect(){r=false,a=void 0;},async getAccounts(){if(!r)throw new Error("Not connected connector");let{request:e}=await this.getProvider();return (await e({method:"eth_accounts"})).map(viem.getAddress)},async getChainId(){let{request:e}=await this.getProvider(),c=await e({method:"eth_chainId"});return viem.fromHex(c,"number")},async isAuthorized(){return r?!!(await this.getAccounts()).length:false},async switchChain({chainId:e}){let c=s.chains.find(m=>m.id===e);if(!c)throw new viem.SwitchChainError(new core.ChainNotConfiguredError);let{request:d}=await this.getProvider();return await d({method:"wallet_switchEthereumChain",params:[{chainId:viem.numberToHex(e)}]}),c},onAccountsChanged(e){e.length===0?this.onDisconnect():s.emitter.emit("change",{accounts:e.map(viem.getAddress)});},onChainChanged(e){let c=Number(e);s.emitter.emit("change",{chainId:c});},async onDisconnect(){s.emitter.emit("disconnect"),r=false,a=void 0;},async getProvider({chainId:e}={}){a=orbitCore.impersonatedHelpers?.getImpersonated()?[orbitCore.impersonatedHelpers.getImpersonated()||viem.zeroAddress]:void 0;let d=(s.chains.find(i=>i.id===e)??s.chains[0]).rpcUrls.default.http[0];return viem.custom({request:async({method:i,params:h})=>{if(i==="eth_chainId")return viem.numberToHex(o);if(i==="eth_requestAccounts")return a;if(i==="eth_signTypedData_v4"&&n.signTypedDataError)throw typeof n.signTypedDataError=="boolean"?new viem.UserRejectedRequestError(new Error("Failed to sign typed data.")):n.signTypedDataError;if(i==="wallet_switchEthereumChain"){if(n.switchChainError)throw typeof n.switchChainError=="boolean"?new viem.UserRejectedRequestError(new Error("Failed to switch chain.")):n.switchChainError;o=viem.fromHex(h[0].chainId,"number"),this.onChainChanged(o.toString());return}if(i==="personal_sign"){if(n.signMessageError)throw typeof n.signMessageError=="boolean"?new viem.UserRejectedRequestError(new Error("Failed to sign message.")):n.signMessageError;i="eth_sign",h=[h[1],h[0]];}let C={method:i,params:h},{error:g,result:S}=await utils.rpc.http(d,{body:C});if(g)throw new viem.RpcRequestError({body:C,error:g,url:d});return S}})({retryCount:1})}}))}var Y={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},be=t=>{let n=connectors.injected(),r=connectors.coinbaseWallet({appName:t.appName,appLogoUrl:t.appLogoUrl}),o=connectors.safe({...Y}),a=[n,r,o,u({})],s=t.appUrl&&t.appIcons&&t.appName&&t.description?{name:t.appName,description:t.description,url:t.appUrl,icons:t.appIcons}:void 0;if(t.projectId){let e=connectors.walletConnect({projectId:t.projectId,metadata:s});a.push(e);}return a};var xe=t=>t.reduce((n,r)=>{let o=r.id;return n[o]=viem.http(),n},{});exports.checkIsWalletAddressContract=y;exports.createDefaultTransports=xe;exports.initAllConnectors=be;exports.safeSdkOptions=Y;exports.satelliteEVMAdapter=le;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.ts","../src/connectors/ImpersonatedConnector.ts","../src/connectors/index.ts","../src/utils/createWagmiConfig.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","disconnect","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","e","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","impersonated","parameters","features","connected","connectedChainId","accountAddress","createConnector","UserRejectedRequestError","request","accounts","currentChainId","getAddress","hexChainId","fromHex","x","SwitchChainError","ChainNotConfiguredError","numberToHex","impersonatedHelpers","custom","method","params","body","error","result","rpc","RpcRequestError","safeSdkOptions","initAllConnectors","props","injectedConnector","injected","coinbaseConnector","coinbaseWallet","gnosisSafeConnector","safe","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http","createWagmiConfig","transports","projectId","appLogoUrl","appLogo","appUrl","appIcons","appName","description","createConfig"],"mappings":"kPAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,CAAAA,CACA,QAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CACF,CAAA,CASqB,CAEnB,GAAIL,EAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAMjC,GAFeG,yBAAAA,CAAiBF,CAAAA,CAAmBC,CAAM,CAAA,CAE7C,CAOV,IAAME,CAAAA,CAAa,CAAC,CALQ,MAAMC,gBAAAA,CAAYN,CAAAA,CAAQ,CACpD,OAAA,CAASC,CACX,CAAC,CAAA,CAID,OAAAH,CAAAA,CAAa,GAAA,CAAIG,CAAAA,CAASI,CAAU,CAAA,CAE7BA,CACT,CAAA,KAEE,OAAO,MAEX,CC3CO,SAASE,EAAAA,CACdP,CAAAA,CACAQ,CAAAA,CACgC,CAChC,GAAI,CAACR,EAAQ,MAAM,IAAI,KAAA,CAAM,uDAAuD,CAAA,CAEpF,OAAO,CAEL,GA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AAY0D,CAAAA,EAAcL,EAAAA,CAAwBzE,CAAM,EACxD,MAAA,CAAAA,CAAAA,CACA,GAAGuD,CACL,CAAC,CACH","file":"index.js","sourcesContent":["import { createViemClient } from '@tuwaio/orbit-evm';\nimport { Config, getBytecode } from '@wagmi/core';\nimport { Address } from 'viem';\nimport { Chain } from 'viem/chains';\n\n/**\n * An in-memory cache for wallets bytecode to avoid redundant requests to the blockchain.\n * Key is the wallet address, value is boolean indicating if it's a contract address.\n * @internal\n */\nconst walletsCache = new Map<string, boolean>();\n\n/**\n * Checks if a given wallet address is a smart contract by examining its bytecode\n *\n * @remarks\n * This function uses an in-memory cache to store results and avoid redundant blockchain requests.\n * The cache persists for the lifetime of the application session.\n *\n * @param config - Wagmi configuration object\n * @param address - Ethereum address to check\n * @param chainId - ID of the blockchain network\n * @param chains - Array of supported chain configurations\n *\n * @returns Promise resolving to boolean indicating if the address is a contract\n * - true: Address is a smart contract\n * - false: Address is an EOA (Externally Owned Account) or client creation failed\n *\n * @example\n * ```typescript\n * const isContract = await checkIsWalletAddressContract({\n * config: wagmiConfig,\n * address: \"0x1234...\",\n * chainId: 1,\n * chains: [mainnet, polygon]\n * });\n * ```\n *\n * @throws Will throw an error if getBytecode request fails\n */\nexport async function checkIsWalletAddressContract({\n config,\n address,\n chainId,\n chains,\n}: {\n /** Wagmi configuration for blockchain interaction */\n config: Config;\n /** Ethereum address to check */\n address: string;\n /** Chain ID where the check should be performed */\n chainId: number | string;\n /** Array of supported chain configurations */\n chains: readonly [Chain, ...Chain[]];\n}): Promise<boolean> {\n // Check cache first to avoid redundant blockchain requests\n if (walletsCache.has(address)) {\n return walletsCache.get(address)!;\n }\n\n // Create Viem client for blockchain interaction\n const client = createViemClient(chainId as number, chains);\n\n if (client) {\n // Get bytecode from the blockchain\n const codeOfWalletAddress = await getBytecode(config, {\n address: address as Address,\n });\n\n // Cache the result\n const isContract = !!codeOfWalletAddress;\n walletsCache.set(address, isContract);\n\n return isContract;\n } else {\n // Return false if client creation failed\n return false;\n }\n}\n","import { formatWalletName, getWalletTypeFromConnectorName, isSafeApp, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { checkAndSwitchChain, getAvatar, getName } from '@tuwaio/orbit-evm';\nimport { SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { Config, connect, disconnect, getAccount, getBalance, getChains, getConnectors } from '@wagmi/core';\nimport { Address, formatUnits, zeroAddress } from 'viem';\nimport { mainnet } from 'viem/chains';\n\nimport { ConnectorEVM } from '../types';\nimport { checkIsWalletAddressContract } from '../utils/checkIsWalletAddressContract';\n\n/**\n * Creates an EVM-compatible adapter for Satellite\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Ethereum Virtual Machine (EVM) compatible chains.\n * It uses wagmi as the underlying library for wallet connections and chain interactions.\n *\n * @param config - Wagmi configuration object containing chain and connector settings\n * @param signInWithSiwe - Optional function for signing in with SIWE\n * @returns A configured SatelliteAdapter instance for EVM chains\n * @throws Error if config is not provided\n *\n * @example\n * ```typescript\n * const config = createConfig({\n * chains: [mainnet, polygon],\n * connectors: [\n * new InjectedConnector(),\n * new WalletConnectConnector({ projectId: 'your_project_id' })\n * ]\n * });\n *\n * const evmAdapter = satelliteEVMAdapter(config);\n * ```\n */\nexport function satelliteEVMAdapter(\n config: Config,\n signInWithSiwe?: () => Promise<void>,\n): SatelliteAdapter<ConnectorEVM> {\n if (!config) throw new Error('Satellite EVM adapter requires a wagmi config object.');\n\n return {\n /** Identifies this adapter as EVM-compatible */\n key: OrbitAdapter.EVM,\n\n /**\n * Connects to an EVM wallet\n * @returns Connected wallet information\n * @throws Error if connector not found or connection fails\n */\n connect: async ({ walletType, chainId }) => {\n const connectors = getConnectors(config);\n const connector = connectors.find(\n (connector) =>\n getWalletTypeFromConnectorName(OrbitAdapter.EVM, formatWalletName(connector.name)) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n if (await connector.isAuthorized()) {\n await disconnect(config, { connector });\n }\n await connect(config, { connector, chainId: chainId as number });\n if (signInWithSiwe && !isSafeApp) {\n await signInWithSiwe();\n }\n const account = getAccount(config);\n\n return {\n walletType,\n address: account.address ?? zeroAddress,\n chainId: account.chainId ?? mainnet.id,\n rpcURL: account.chain?.rpcUrls.default.http[0] ?? mainnet.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n isContractAddress: false,\n walletIcon: connector?.icon?.trim(),\n connector,\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Disconnects the currently connected wallet\n */\n disconnect: async () => {\n const connectors = getConnectors(config);\n await Promise.allSettled(\n connectors.map(async (connector) => {\n await disconnect(config, { connector });\n }),\n );\n },\n\n /**\n * Retrieves available EVM wallet connectors\n * @returns Object containing adapter type and list of available connectors\n */\n getConnectors: () => {\n const connectors = getConnectors(config);\n return {\n adapter: OrbitAdapter.EVM,\n connectors: connectors.map((connector) => {\n return connector;\n }) as ConnectorEVM[],\n };\n },\n\n /**\n * Switches the connected wallet to specified network\n * @param chainId - Target chain ID to switch to\n */\n checkAndSwitchNetwork: async (chainId) => await checkAndSwitchChain(Number(chainId), config),\n\n getBalance: async (address, chainId) => {\n const balance = await getBalance(config, { address: address as Address, chainId: Number(chainId) });\n return {\n value: formatUnits(balance.value, balance.decimals),\n symbol: balance.symbol,\n };\n },\n\n /**\n * Generates blockchain explorer URLs for the current network\n * @param url - Optional path to append to base explorer URL\n * @returns Complete explorer URL or base explorer URL if no path provided\n */\n getExplorerUrl: (url) => {\n const { chain } = getAccount(config);\n const baseExplorerLink = chain?.blockExplorers?.default.url;\n return url ? `${baseExplorerLink}/${url}` : baseExplorerLink;\n },\n\n /**\n * Resolves ENS name for given address\n * @param address - Ethereum address to resolve\n * @returns ENS name if available, null otherwise\n */\n getName: (address: string) => getName(address as `0x${string}`),\n\n /**\n * Retrieves avatar for ENS name\n * @param name - ENS name to get avatar for\n * @returns Avatar URL if available, null otherwise\n */\n getAvatar: (name: string) => getAvatar(name),\n\n /**\n * Checks if given address is a smart contract\n * @param address - Address to check\n * @param chainId - Chain ID on which to perform the check\n * @returns Promise resolving to boolean indicating if address is a contract\n */\n checkIsContractWallet: async ({ address, chainId }) => {\n const chains = getChains(config);\n return await checkIsWalletAddressContract({ config, address, chainId, chains });\n },\n\n getSafeConnectorChainId: async () => {\n const connectors = getConnectors(config);\n const safeConnector = connectors.find((c) => c.name === 'Safe');\n if (safeConnector) {\n return await safeConnector.getChainId();\n } else {\n return undefined;\n }\n },\n };\n}\n","import { impersonatedHelpers } from '@tuwaio/orbit-core';\nimport { ChainNotConfiguredError, createConnector } from '@wagmi/core';\nimport {\n type Address,\n custom,\n type EIP1193RequestFn,\n fromHex,\n getAddress,\n type Hex,\n numberToHex,\n RpcRequestError,\n SwitchChainError,\n type Transport,\n UserRejectedRequestError,\n type WalletRpcSchema,\n zeroAddress,\n} from 'viem';\nimport { rpc } from 'viem/utils';\n\n/**\n * Configuration parameters for impersonated wallet connector\n */\nexport type ImpersonatedParameters = {\n /** Optional feature flags for testing error scenarios */\n features?: {\n /** Simulate connection error */\n connectError?: boolean | Error;\n /** Simulate chain switching error */\n switchChainError?: boolean | Error;\n /** Simulate message signing error */\n signMessageError?: boolean | Error;\n /** Simulate typed data signing error */\n signTypedDataError?: boolean | Error;\n /** Enable reconnection behavior */\n reconnect?: boolean;\n };\n};\n\n/**\n * Creates a wagmi connector for impersonating Ethereum accounts\n *\n * @remarks\n * This connector allows testing wallet interactions without an actual wallet by impersonating\n * an Ethereum address. It implements the EIP-1193 provider interface and can simulate\n * various error scenarios for testing purposes.\n *\n * @param parameters - Configuration options for the impersonated connector\n * @returns A wagmi connector instance\n *\n * @example\n * ```typescript\n * const connector = impersonated({\n * getAccountAddress: () => \"0x1234...\",\n * features: {\n * // Simulate errors for testing\n * connectError: false,\n * signMessageError: false\n * }\n * });\n * ```\n */\nimpersonated.type = 'impersonated' as const;\nexport function impersonated(parameters: ImpersonatedParameters) {\n const features = parameters.features ?? {};\n\n type Provider = ReturnType<Transport<'custom', NonNullable<unknown>, EIP1193RequestFn<WalletRpcSchema>>>;\n let connected = false;\n let connectedChainId: number;\n let accountAddress: Hex[] | undefined = undefined;\n\n return createConnector<Provider>((config) => ({\n id: 'impersonated',\n name: 'Impersonated Connector',\n type: impersonated.type,\n\n /**\n * Initial setup - sets default chain ID\n */\n async setup() {\n connectedChainId = config.chains[0].id;\n },\n /**\n * Simulates wallet connection\n * @throws {UserRejectedRequestError} When connection is rejected\n */\n // @ts-expect-error - not typed correctly\n async connect({ chainId } = {}) {\n if (features.connectError) {\n if (typeof features.connectError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to connect.'));\n throw features.connectError;\n }\n\n const { request } = await this.getProvider();\n const accounts = await request({\n method: 'eth_requestAccounts',\n });\n\n let currentChainId = await this.getChainId();\n if (chainId && currentChainId !== chainId) {\n const chain = await this.switchChain!({ chainId });\n currentChainId = chain.id;\n }\n\n connected = true;\n return { accounts, chainId: currentChainId };\n },\n\n /**\n * Simulates wallet disconnection\n */\n async disconnect() {\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Returns impersonated accounts\n * @throws {Error} When not connected\n */\n async getAccounts() {\n if (!connected) throw new Error('Not connected connector');\n const { request } = await this.getProvider();\n const accounts = await request({ method: 'eth_accounts' });\n return accounts.map(getAddress);\n },\n\n /**\n * Returns current chain ID\n */\n async getChainId() {\n const { request } = await this.getProvider();\n const hexChainId = await request({ method: 'eth_chainId' });\n return fromHex(hexChainId, 'number');\n },\n\n /**\n * Checks if wallet is connected and authorized\n */\n async isAuthorized() {\n if (!connected) return false;\n const accounts = await this.getAccounts();\n return !!accounts.length;\n },\n\n /**\n * Simulates switching to a different chain\n * @throws {SwitchChainError} When chain is not configured\n * @throws {UserRejectedRequestError} When switch is rejected\n */\n async switchChain({ chainId }) {\n const chain = config.chains.find((x) => x.id === chainId);\n if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());\n // @ts-expect-error - request is not typed correctly\n const { request } = await this.getProvider();\n await request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: numberToHex(chainId) }],\n });\n return chain;\n },\n\n /**\n * Handles account changes\n */\n onAccountsChanged(accounts) {\n if (accounts.length === 0) this.onDisconnect();\n else config.emitter.emit('change', { accounts: accounts.map(getAddress) });\n },\n\n /**\n * Handles chain changes\n */\n onChainChanged(chain) {\n const chainId = Number(chain);\n config.emitter.emit('change', { chainId });\n },\n\n /**\n * Handles disconnection\n */\n async onDisconnect() {\n config.emitter.emit('disconnect');\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Creates an EIP-1193 compatible provider\n * @returns Custom provider instance\n */\n async getProvider({ chainId }: { chainId?: number } = {}) {\n accountAddress = impersonatedHelpers?.getImpersonated()\n ? [(impersonatedHelpers.getImpersonated() as Address) || zeroAddress]\n : undefined;\n const chain = config.chains.find((x) => x.id === chainId) ?? config.chains[0];\n const url = chain.rpcUrls.default.http[0]!;\n\n const request: EIP1193RequestFn = async ({ method, params }) => {\n // eth methods\n if (method === 'eth_chainId') return numberToHex(connectedChainId);\n if (method === 'eth_requestAccounts') return accountAddress;\n if (method === 'eth_signTypedData_v4')\n if (features.signTypedDataError) {\n if (typeof features.signTypedDataError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign typed data.'));\n throw features.signTypedDataError;\n }\n\n // wallet methods\n if (method === 'wallet_switchEthereumChain') {\n if (features.switchChainError) {\n if (typeof features.switchChainError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to switch chain.'));\n throw features.switchChainError;\n }\n type Params = [{ chainId: Hex }];\n connectedChainId = fromHex((params as Params)[0].chainId, 'number');\n this.onChainChanged(connectedChainId.toString());\n return;\n }\n\n // other methods\n if (method === 'personal_sign') {\n if (features.signMessageError) {\n if (typeof features.signMessageError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign message.'));\n throw features.signMessageError;\n }\n // Change `personal_sign` to `eth_sign` and swap params\n method = 'eth_sign';\n type Params = [data: Hex, address: Address];\n params = [(params as Params)[1], (params as Params)[0]];\n }\n\n const body = { method, params };\n const { error, result } = await rpc.http(url, { body });\n if (error) throw new RpcRequestError({ body, error, url });\n\n return result;\n };\n return custom({ request })({ retryCount: 1 });\n },\n }));\n}\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { coinbaseWallet, injected, safe, walletConnect } from '@wagmi/connectors';\nimport { CreateConnectorFn } from '@wagmi/core';\n\nimport { impersonated } from './ImpersonatedConnector';\n\n/**\n * Configuration options for Gnosis Safe SDK\n * @remarks\n * Defines allowed domains and debug mode for Safe integration\n */\nexport const safeSdkOptions = {\n /** Regular expressions for allowed Safe wallet domains */\n allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/, /metissafe.tech$/],\n /** Enable debug mode */\n debug: false,\n};\n\n/**\n * Initializes all supported wallet connectors based on provided configuration\n *\n * @remarks\n * Creates instances of various wallet connectors including:\n * - Coinbase Wallet\n * - Gnosis Safe\n * - WalletConnect (if projectId provided)\n * - Impersonated wallet (for development/testing)\n *\n * The order of connectors in the returned array determines their priority\n * in the wallet connection UI.\n *\n * @param props - Configuration options for initializing connectors\n * @returns Array of wallet connector instances\n *\n * @example\n * ```typescript\n * const connectors = initAllConnectors({\n * appName: \"My dApp\",\n * projectId: \"wallet_connect_project_id\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const initAllConnectors = (props: ConnectorsInitProps): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const coinbaseConnector = coinbaseWallet({\n appName: props.appName,\n appLogoUrl: props.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n\n const connectors = [injectedConnector, coinbaseConnector, gnosisSafeConnector, impersonated({})];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n props.appUrl && props.appIcons && props.appName && props.description\n ? {\n name: props.appName,\n description: props.description,\n url: props.appUrl,\n icons: props.appIcons,\n }\n : undefined;\n\n if (props.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: props.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - connector has some different types\n connectors.push(walletConnectConnector);\n }\n\n return connectors;\n};\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { Config, createConfig, CreateConfigParameters, CreateConnectorFn } from '@wagmi/core';\nimport { http, Transport } from 'viem';\n\nimport { initAllConnectors } from '../connectors';\n\n/**\n * Creates default HTTP transports for each chain in the configuration\n *\n * @param chains - Array of chain configurations from wagmi\n * @returns Object mapping chain IDs to their corresponding HTTP transport instances\n *\n * @internal\n */\nconst createDefaultTransports = (chains: CreateConfigParameters['chains']): Record<number, Transport> => {\n return chains.reduce(\n (acc, chain) => {\n const key = chain.id;\n acc[key] = http() as Transport;\n return acc;\n },\n {} as Record<number, Transport>,\n );\n};\n\n/**\n * Creates a Wagmi configuration with initialized connectors and transports\n *\n * @remarks\n * This function combines Satellite connector initialization with Wagmi configuration.\n * It automatically sets up HTTP transports for each chain if custom transports are not provided.\n *\n * @param config - Combined configuration parameters for Satellite and Wagmi\n * @param config.chains - Array of supported blockchain networks\n * @param config.transports - Optional custom transport configurations for each chain\n * @param config.projectId - WalletConnect project ID\n * @param config.appName - Application name for wallet connection UI\n * @param config.appUrl - Application URL for metadata\n * @param config.appLogoUrl - URL to application logo\n * @param config.appLogo - Optional inline logo data\n * @param config.appIcons - Array of application icon URLs\n * @param config.description - Application description for wallet connection UI\n *\n * @returns Configured Wagmi instance\n *\n * @example\n * ```typescript\n * const config = createWagmiConfig({\n * chains: [mainnet, polygon],\n * projectId: \"your_project_id\",\n * appName: \"My dApp\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const createWagmiConfig = ({\n chains,\n transports,\n projectId,\n appLogoUrl,\n appLogo,\n appUrl,\n appIcons,\n appName,\n description,\n ...params\n}: ConnectorsInitProps & Omit<CreateConfigParameters, 'client'>): Config => {\n // Initialize wallet connectors with provided configuration\n const connectors = initAllConnectors({\n projectId,\n appLogoUrl,\n appLogo,\n appUrl,\n appIcons,\n appName,\n description,\n }) as CreateConnectorFn[];\n\n // Create and return the complete Wagmi configuration\n return createConfig({\n connectors,\n // Use custom transports if provided, otherwise create default HTTP transports\n transports: transports ?? createDefaultTransports(chains),\n chains,\n ...params,\n });\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.ts","../src/connectors/ImpersonatedConnector.ts","../src/connectors/index.ts","../src/utils/createDefaultTransports.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","disconnect","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","impersonated","parameters","features","connected","connectedChainId","accountAddress","createConnector","UserRejectedRequestError","request","accounts","currentChainId","getAddress","hexChainId","fromHex","x","SwitchChainError","ChainNotConfiguredError","numberToHex","impersonatedHelpers","custom","method","params","body","error","result","rpc","RpcRequestError","safeSdkOptions","initAllConnectors","props","injectedConnector","injected","coinbaseConnector","coinbaseWallet","gnosisSafeConnector","safe","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http"],"mappings":"kPAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CACF,CAAA,CASqB,CAEnB,GAAIL,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAMjC,GAFeG,yBAAAA,CAAiBF,CAAAA,CAAmBC,CA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m';\nimport { Config, getBytecode } from '@wagmi/core';\nimport { Address } from 'viem';\nimport { Chain } from 'viem/chains';\n\n/**\n * An in-memory cache for wallets bytecode to avoid redundant requests to the blockchain.\n * Key is the wallet address, value is boolean indicating if it's a contract address.\n * @internal\n */\nconst walletsCache = new Map<string, boolean>();\n\n/**\n * Checks if a given wallet address is a smart contract by examining its bytecode\n *\n * @remarks\n * This function uses an in-memory cache to store results and avoid redundant blockchain requests.\n * The cache persists for the lifetime of the application session.\n *\n * @param config - Wagmi configuration object\n * @param address - Ethereum address to check\n * @param chainId - ID of the blockchain network\n * @param chains - Array of supported chain configurations\n *\n * @returns Promise resolving to boolean indicating if the address is a contract\n * - true: Address is a smart contract\n * - false: Address is an EOA (Externally Owned Account) or client creation failed\n *\n * @example\n * ```typescript\n * const isContract = await checkIsWalletAddressContract({\n * config: wagmiConfig,\n * address: \"0x1234...\",\n * chainId: 1,\n * chains: [mainnet, polygon]\n * });\n * ```\n *\n * @throws Will throw an error if getBytecode request fails\n */\nexport async function checkIsWalletAddressContract({\n config,\n address,\n chainId,\n chains,\n}: {\n /** Wagmi configuration for blockchain interaction */\n config: Config;\n /** Ethereum address to check */\n address: string;\n /** Chain ID where the check should be performed */\n chainId: number | string;\n /** Array of supported chain configurations */\n chains: readonly [Chain, ...Chain[]];\n}): Promise<boolean> {\n // Check cache first to avoid redundant blockchain requests\n if (walletsCache.has(address)) {\n return walletsCache.get(address)!;\n }\n\n // Create Viem client for blockchain interaction\n const client = createViemClient(chainId as number, chains);\n\n if (client) {\n // Get bytecode from the blockchain\n const codeOfWalletAddress = await getBytecode(config, {\n address: address as Address,\n });\n\n // Cache the result\n const isContract = !!codeOfWalletAddress;\n walletsCache.set(address, isContract);\n\n return isContract;\n } else {\n // Return false if client creation failed\n return false;\n }\n}\n","import { formatWalletName, getWalletTypeFromConnectorName, isSafeApp, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { checkAndSwitchChain, getAvatar, getName } from '@tuwaio/orbit-evm';\nimport { SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { Config, connect, disconnect, getAccount, getBalance, getChains, getConnectors } from '@wagmi/core';\nimport { Address, formatUnits, zeroAddress } from 'viem';\nimport { mainnet } from 'viem/chains';\n\nimport { ConnectorEVM } from '../types';\nimport { checkIsWalletAddressContract } from '../utils/checkIsWalletAddressContract';\n\n/**\n * Creates an EVM-compatible adapter for Satellite\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Ethereum Virtual Machine (EVM) compatible chains.\n * It uses wagmi as the underlying library for wallet connections and chain interactions.\n *\n * @param config - Wagmi configuration object containing chain and connector settings\n * @param signInWithSiwe - Optional function for signing in with SIWE\n * @returns A configured SatelliteAdapter instance for EVM chains\n * @throws Error if config is not provided\n *\n * @example\n * ```typescript\n * const config = createConfig({\n * chains: [mainnet, polygon],\n * connectors: [\n * new InjectedConnector(),\n * new WalletConnectConnector({ projectId: 'your_project_id' })\n * ]\n * });\n *\n * const evmAdapter = satelliteEVMAdapter(config);\n * ```\n */\nexport function satelliteEVMAdapter(\n config: Config,\n signInWithSiwe?: () => Promise<void>,\n): SatelliteAdapter<ConnectorEVM> {\n if (!config) throw new Error('Satellite EVM adapter requires a wagmi config object.');\n\n return {\n /** Identifies this adapter as EVM-compatible */\n key: OrbitAdapter.EVM,\n\n /**\n * Connects to an EVM wallet\n * @returns Connected wallet information\n * @throws Error if connector not found or connection fails\n */\n connect: async ({ walletType, chainId }) => {\n const connectors = getConnectors(config);\n const connector = connectors.find(\n (connector) =>\n getWalletTypeFromConnectorName(OrbitAdapter.EVM, formatWalletName(connector.name)) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n if (await connector.isAuthorized()) {\n await disconnect(config, { connector });\n }\n await connect(config, { connector, chainId: chainId as number });\n if (signInWithSiwe && !isSafeApp) {\n await signInWithSiwe();\n }\n const account = getAccount(config);\n\n return {\n walletType,\n address: account.address ?? zeroAddress,\n chainId: account.chainId ?? mainnet.id,\n rpcURL: account.chain?.rpcUrls.default.http[0] ?? mainnet.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n isContractAddress: false,\n walletIcon: connector?.icon?.trim(),\n connector,\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Disconnects the currently connected wallet\n */\n disconnect: async () => {\n const connectors = getConnectors(config);\n await Promise.allSettled(\n connectors.map(async (connector) => {\n await disconnect(config, { connector });\n }),\n );\n },\n\n /**\n * Retrieves available EVM wallet connectors\n * @returns Object containing adapter type and list of available connectors\n */\n getConnectors: () => {\n const connectors = getConnectors(config);\n return {\n adapter: OrbitAdapter.EVM,\n connectors: connectors.map((connector) => {\n return connector;\n }) as ConnectorEVM[],\n };\n },\n\n /**\n * Switches the connected wallet to specified network\n * @param chainId - Target chain ID to switch to\n */\n checkAndSwitchNetwork: async (chainId) => await checkAndSwitchChain(Number(chainId), config),\n\n getBalance: async (address, chainId) => {\n const balance = await getBalance(config, { address: address as Address, chainId: Number(chainId) });\n return {\n value: formatUnits(balance.value, balance.decimals),\n symbol: balance.symbol,\n };\n },\n\n /**\n * Generates blockchain explorer URLs for the current network\n * @param url - Optional path to append to base explorer URL\n * @returns Complete explorer URL or base explorer URL if no path provided\n */\n getExplorerUrl: (url) => {\n const { chain } = getAccount(config);\n const baseExplorerLink = chain?.blockExplorers?.default.url;\n return url ? `${baseExplorerLink}/${url}` : baseExplorerLink;\n },\n\n /**\n * Resolves ENS name for given address\n * @param address - Ethereum address to resolve\n * @returns ENS name if available, null otherwise\n */\n getName: (address: string) => getName(address as `0x${string}`),\n\n /**\n * Retrieves avatar for ENS name\n * @param name - ENS name to get avatar for\n * @returns Avatar URL if available, null otherwise\n */\n getAvatar: (name: string) => getAvatar(name),\n\n /**\n * Checks if given address is a smart contract\n * @param address - Address to check\n * @param chainId - Chain ID on which to perform the check\n * @returns Promise resolving to boolean indicating if address is a contract\n */\n checkIsContractWallet: async ({ address, chainId }) => {\n const chains = getChains(config);\n return await checkIsWalletAddressContract({ config, address, chainId, chains });\n },\n\n getSafeConnectorChainId: async () => {\n const connectors = getConnectors(config);\n const safeConnector = connectors.find((c) => c.name === 'Safe');\n if (safeConnector) {\n return await safeConnector.getChainId();\n } else {\n return undefined;\n }\n },\n };\n}\n","import { impersonatedHelpers } from '@tuwaio/orbit-core';\nimport { ChainNotConfiguredError, createConnector } from '@wagmi/core';\nimport {\n type Address,\n custom,\n type EIP1193RequestFn,\n fromHex,\n getAddress,\n type Hex,\n numberToHex,\n RpcRequestError,\n SwitchChainError,\n type Transport,\n UserRejectedRequestError,\n type WalletRpcSchema,\n zeroAddress,\n} from 'viem';\nimport { rpc } from 'viem/utils';\n\n/**\n * Configuration parameters for impersonated wallet connector\n */\nexport type ImpersonatedParameters = {\n /** Optional feature flags for testing error scenarios */\n features?: {\n /** Simulate connection error */\n connectError?: boolean | Error;\n /** Simulate chain switching error */\n switchChainError?: boolean | Error;\n /** Simulate message signing error */\n signMessageError?: boolean | Error;\n /** Simulate typed data signing error */\n signTypedDataError?: boolean | Error;\n /** Enable reconnection behavior */\n reconnect?: boolean;\n };\n};\n\n/**\n * Creates a wagmi connector for impersonating Ethereum accounts\n *\n * @remarks\n * This connector allows testing wallet interactions without an actual wallet by impersonating\n * an Ethereum address. It implements the EIP-1193 provider interface and can simulate\n * various error scenarios for testing purposes.\n *\n * @param parameters - Configuration options for the impersonated connector\n * @returns A wagmi connector instance\n *\n * @example\n * ```typescript\n * const connector = impersonated({\n * getAccountAddress: () => \"0x1234...\",\n * features: {\n * // Simulate errors for testing\n * connectError: false,\n * signMessageError: false\n * }\n * });\n * ```\n */\nimpersonated.type = 'impersonated' as const;\nexport function impersonated(parameters: ImpersonatedParameters) {\n const features = parameters.features ?? {};\n\n type Provider = ReturnType<Transport<'custom', NonNullable<unknown>, EIP1193RequestFn<WalletRpcSchema>>>;\n let connected = false;\n let connectedChainId: number;\n let accountAddress: Hex[] | undefined = undefined;\n\n return createConnector<Provider>((config) => ({\n id: 'impersonated',\n name: 'Impersonated Connector',\n type: impersonated.type,\n\n /**\n * Initial setup - sets default chain ID\n */\n async setup() {\n connectedChainId = config.chains[0].id;\n },\n /**\n * Simulates wallet connection\n * @throws {UserRejectedRequestError} When connection is rejected\n */\n // @ts-expect-error - not typed correctly\n async connect({ chainId } = {}) {\n if (features.connectError) {\n if (typeof features.connectError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to connect.'));\n throw features.connectError;\n }\n\n const { request } = await this.getProvider();\n const accounts = await request({\n method: 'eth_requestAccounts',\n });\n\n let currentChainId = await this.getChainId();\n if (chainId && currentChainId !== chainId) {\n const chain = await this.switchChain!({ chainId });\n currentChainId = chain.id;\n }\n\n connected = true;\n return { accounts, chainId: currentChainId };\n },\n\n /**\n * Simulates wallet disconnection\n */\n async disconnect() {\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Returns impersonated accounts\n * @throws {Error} When not connected\n */\n async getAccounts() {\n if (!connected) throw new Error('Not connected connector');\n const { request } = await this.getProvider();\n const accounts = await request({ method: 'eth_accounts' });\n return accounts.map(getAddress);\n },\n\n /**\n * Returns current chain ID\n */\n async getChainId() {\n const { request } = await this.getProvider();\n const hexChainId = await request({ method: 'eth_chainId' });\n return fromHex(hexChainId, 'number');\n },\n\n /**\n * Checks if wallet is connected and authorized\n */\n async isAuthorized() {\n if (!connected) return false;\n const accounts = await this.getAccounts();\n return !!accounts.length;\n },\n\n /**\n * Simulates switching to a different chain\n * @throws {SwitchChainError} When chain is not configured\n * @throws {UserRejectedRequestError} When switch is rejected\n */\n async switchChain({ chainId }) {\n const chain = config.chains.find((x) => x.id === chainId);\n if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());\n // @ts-expect-error - request is not typed correctly\n const { request } = await this.getProvider();\n await request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: numberToHex(chainId) }],\n });\n return chain;\n },\n\n /**\n * Handles account changes\n */\n onAccountsChanged(accounts) {\n if (accounts.length === 0) this.onDisconnect();\n else config.emitter.emit('change', { accounts: accounts.map(getAddress) });\n },\n\n /**\n * Handles chain changes\n */\n onChainChanged(chain) {\n const chainId = Number(chain);\n config.emitter.emit('change', { chainId });\n },\n\n /**\n * Handles disconnection\n */\n async onDisconnect() {\n config.emitter.emit('disconnect');\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Creates an EIP-1193 compatible provider\n * @returns Custom provider instance\n */\n async getProvider({ chainId }: { chainId?: number } = {}) {\n accountAddress = impersonatedHelpers?.getImpersonated()\n ? [(impersonatedHelpers.getImpersonated() as Address) || zeroAddress]\n : undefined;\n const chain = config.chains.find((x) => x.id === chainId) ?? config.chains[0];\n const url = chain.rpcUrls.default.http[0]!;\n\n const request: EIP1193RequestFn = async ({ method, params }) => {\n // eth methods\n if (method === 'eth_chainId') return numberToHex(connectedChainId);\n if (method === 'eth_requestAccounts') return accountAddress;\n if (method === 'eth_signTypedData_v4')\n if (features.signTypedDataError) {\n if (typeof features.signTypedDataError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign typed data.'));\n throw features.signTypedDataError;\n }\n\n // wallet methods\n if (method === 'wallet_switchEthereumChain') {\n if (features.switchChainError) {\n if (typeof features.switchChainError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to switch chain.'));\n throw features.switchChainError;\n }\n type Params = [{ chainId: Hex }];\n connectedChainId = fromHex((params as Params)[0].chainId, 'number');\n this.onChainChanged(connectedChainId.toString());\n return;\n }\n\n // other methods\n if (method === 'personal_sign') {\n if (features.signMessageError) {\n if (typeof features.signMessageError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign message.'));\n throw features.signMessageError;\n }\n // Change `personal_sign` to `eth_sign` and swap params\n method = 'eth_sign';\n type Params = [data: Hex, address: Address];\n params = [(params as Params)[1], (params as Params)[0]];\n }\n\n const body = { method, params };\n const { error, result } = await rpc.http(url, { body });\n if (error) throw new RpcRequestError({ body, error, url });\n\n return result;\n };\n return custom({ request })({ retryCount: 1 });\n },\n }));\n}\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { coinbaseWallet, injected, safe, walletConnect } from '@wagmi/connectors';\nimport { CreateConnectorFn } from '@wagmi/core';\n\nimport { impersonated } from './ImpersonatedConnector';\n\n/**\n * Configuration options for Gnosis Safe SDK\n * @remarks\n * Defines allowed domains and debug mode for Safe integration\n */\nexport const safeSdkOptions = {\n /** Regular expressions for allowed Safe wallet domains */\n allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/, /metissafe.tech$/],\n /** Enable debug mode */\n debug: false,\n};\n\n/**\n * Initializes all supported wallet connectors based on provided configuration\n *\n * @remarks\n * Creates instances of various wallet connectors including:\n * - Coinbase Wallet\n * - Gnosis Safe\n * - WalletConnect (if projectId provided)\n * - Impersonated wallet (for development/testing)\n *\n * The order of connectors in the returned array determines their priority\n * in the wallet connection UI.\n *\n * @param props - Configuration options for initializing connectors\n * @returns Array of wallet connector instances\n *\n * @example\n * ```typescript\n * const connectors = initAllConnectors({\n * appName: \"My dApp\",\n * projectId: \"wallet_connect_project_id\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const initAllConnectors = (props: ConnectorsInitProps): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const coinbaseConnector = coinbaseWallet({\n appName: props.appName,\n appLogoUrl: props.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n\n const connectors = [injectedConnector, coinbaseConnector, gnosisSafeConnector, impersonated({})];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n props.appUrl && props.appIcons && props.appName && props.description\n ? {\n name: props.appName,\n description: props.description,\n url: props.appUrl,\n icons: props.appIcons,\n }\n : undefined;\n\n if (props.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: props.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - connector has some different types\n connectors.push(walletConnectConnector);\n }\n\n return connectors;\n};\n","import { CreateConfigParameters } from '@wagmi/core';\nimport { http, Transport } from 'viem';\n\n/**\n * Creates default HTTP transports for each chain in the configuration\n *\n * @param chains - Array of chain configurations from wagmi\n * @returns Object mapping chain IDs to their corresponding HTTP transport instances\n *\n * @public\n */\nexport const createDefaultTransports = (chains: CreateConfigParameters['chains']): Record<number, Transport> => {\n return chains.reduce(\n (acc, chain) => {\n const key = chain.id;\n acc[key] = http() as Transport;\n return acc;\n },\n {} as Record<number, Transport>,\n );\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {OrbitAdapter,getWalletTypeFromConnectorName,formatWalletName,isSafeApp,impersonatedHelpers}from'@tuwaio/orbit-core';import {createViemClient,getAvatar,getName,checkAndSwitchChain}from'@tuwaio/orbit-evm';import {getBytecode,getConnectors,getChains,getAccount,getBalance,disconnect,connect,
|
|
1
|
+
import {OrbitAdapter,getWalletTypeFromConnectorName,formatWalletName,isSafeApp,impersonatedHelpers}from'@tuwaio/orbit-core';import {createViemClient,getAvatar,getName,checkAndSwitchChain}from'@tuwaio/orbit-evm';import {getBytecode,getConnectors,getChains,getAccount,getBalance,disconnect,connect,createConnector,ChainNotConfiguredError}from'@wagmi/core';import {formatUnits,zeroAddress,http,custom,numberToHex,UserRejectedRequestError,fromHex,RpcRequestError,getAddress,SwitchChainError}from'viem';import {mainnet}from'viem/chains';import {injected,coinbaseWallet,safe,walletConnect}from'@wagmi/connectors';import {rpc}from'viem/utils';var f=new Map;async function y({config:t,address:n,chainId:r,chains:o}){if(f.has(n))return f.get(n);if(createViemClient(r,o)){let e=!!await getBytecode(t,{address:n});return f.set(n,e),e}else return false}function le(t,n){if(!t)throw new Error("Satellite EVM adapter requires a wagmi config object.");return {key:OrbitAdapter.EVM,connect:async({walletType:r,chainId:o})=>{let s=getConnectors(t).find(e=>getWalletTypeFromConnectorName(OrbitAdapter.EVM,formatWalletName(e.name))===r);if(!s)throw new Error("Cannot find connector with this wallet type");try{await s.isAuthorized()&&await disconnect(t,{connector:s}),await connect(t,{connector:s,chainId:o}),n&&!isSafeApp&&await n();let e=getAccount(t);return {walletType:r,address:e.address??zeroAddress,chainId:e.chainId??mainnet.id,rpcURL:e.chain?.rpcUrls.default.http[0]??mainnet.rpcUrls.default.http[0],isConnected:e.isConnected,isContractAddress:!1,walletIcon:s?.icon?.trim(),connector:s}}catch(e){throw new Error(e instanceof Error?e.message:String(e))}},disconnect:async()=>{let r=getConnectors(t);await Promise.allSettled(r.map(async o=>{await disconnect(t,{connector:o});}));},getConnectors:()=>{let r=getConnectors(t);return {adapter:OrbitAdapter.EVM,connectors:r.map(o=>o)}},checkAndSwitchNetwork:async r=>await checkAndSwitchChain(Number(r),t),getBalance:async(r,o)=>{let a=await getBalance(t,{address:r,chainId:Number(o)});return {value:formatUnits(a.value,a.decimals),symbol:a.symbol}},getExplorerUrl:r=>{let{chain:o}=getAccount(t),a=o?.blockExplorers?.default.url;return r?`${a}/${r}`:a},getName:r=>getName(r),getAvatar:r=>getAvatar(r),checkIsContractWallet:async({address:r,chainId:o})=>{let a=getChains(t);return await y({config:t,address:r,chainId:o,chains:a})},getSafeConnectorChainId:async()=>{let o=getConnectors(t).find(a=>a.name==="Safe");if(o)return await o.getChainId()}}}u.type="impersonated";function u(t){let n=t.features??{},r=false,o,a;return createConnector(s=>({id:"impersonated",name:"Impersonated Connector",type:u.type,async setup(){o=s.chains[0].id;},async connect({chainId:e}={}){if(n.connectError)throw typeof n.connectError=="boolean"?new UserRejectedRequestError(new Error("Failed to connect.")):n.connectError;let{request:c}=await this.getProvider(),d=await c({method:"eth_requestAccounts"}),m=await this.getChainId();return e&&m!==e&&(m=(await this.switchChain({chainId:e})).id),r=true,{accounts:d,chainId:m}},async disconnect(){r=false,a=void 0;},async getAccounts(){if(!r)throw new Error("Not connected connector");let{request:e}=await this.getProvider();return (await e({method:"eth_accounts"})).map(getAddress)},async getChainId(){let{request:e}=await this.getProvider(),c=await e({method:"eth_chainId"});return fromHex(c,"number")},async isAuthorized(){return r?!!(await this.getAccounts()).length:false},async switchChain({chainId:e}){let c=s.chains.find(m=>m.id===e);if(!c)throw new SwitchChainError(new ChainNotConfiguredError);let{request:d}=await this.getProvider();return await d({method:"wallet_switchEthereumChain",params:[{chainId:numberToHex(e)}]}),c},onAccountsChanged(e){e.length===0?this.onDisconnect():s.emitter.emit("change",{accounts:e.map(getAddress)});},onChainChanged(e){let c=Number(e);s.emitter.emit("change",{chainId:c});},async onDisconnect(){s.emitter.emit("disconnect"),r=false,a=void 0;},async getProvider({chainId:e}={}){a=impersonatedHelpers?.getImpersonated()?[impersonatedHelpers.getImpersonated()||zeroAddress]:void 0;let d=(s.chains.find(i=>i.id===e)??s.chains[0]).rpcUrls.default.http[0];return custom({request:async({method:i,params:h})=>{if(i==="eth_chainId")return numberToHex(o);if(i==="eth_requestAccounts")return a;if(i==="eth_signTypedData_v4"&&n.signTypedDataError)throw typeof n.signTypedDataError=="boolean"?new UserRejectedRequestError(new Error("Failed to sign typed data.")):n.signTypedDataError;if(i==="wallet_switchEthereumChain"){if(n.switchChainError)throw typeof n.switchChainError=="boolean"?new UserRejectedRequestError(new Error("Failed to switch chain.")):n.switchChainError;o=fromHex(h[0].chainId,"number"),this.onChainChanged(o.toString());return}if(i==="personal_sign"){if(n.signMessageError)throw typeof n.signMessageError=="boolean"?new UserRejectedRequestError(new Error("Failed to sign message.")):n.signMessageError;i="eth_sign",h=[h[1],h[0]];}let C={method:i,params:h},{error:g,result:S}=await rpc.http(d,{body:C});if(g)throw new RpcRequestError({body:C,error:g,url:d});return S}})({retryCount:1})}}))}var Y={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},be=t=>{let n=injected(),r=coinbaseWallet({appName:t.appName,appLogoUrl:t.appLogoUrl}),o=safe({...Y}),a=[n,r,o,u({})],s=t.appUrl&&t.appIcons&&t.appName&&t.description?{name:t.appName,description:t.description,url:t.appUrl,icons:t.appIcons}:void 0;if(t.projectId){let e=walletConnect({projectId:t.projectId,metadata:s});a.push(e);}return a};var xe=t=>t.reduce((n,r)=>{let o=r.id;return n[o]=http(),n},{});export{y as checkIsWalletAddressContract,xe as createDefaultTransports,be as initAllConnectors,Y as safeSdkOptions,le as satelliteEVMAdapter};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.ts","../src/connectors/ImpersonatedConnector.ts","../src/connectors/index.ts","../src/utils/createWagmiConfig.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","disconnect","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","e","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","impersonated","parameters","features","connected","connectedChainId","accountAddress","createConnector","UserRejectedRequestError","request","accounts","currentChainId","getAddress","hexChainId","fromHex","x","SwitchChainError","ChainNotConfiguredError","numberToHex","impersonatedHelpers","custom","method","params","body","error","result","rpc","RpcRequestError","safeSdkOptions","initAllConnectors","props","injectedConnector","injected","coinbaseConnector","coinbaseWallet","gnosisSafeConnector","safe","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http","createWagmiConfig","transports","projectId","appLogoUrl","appLogo","appUrl","appIcons","appName","description","createConfig"],"mappings":"yoBAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,CAAAA,CACA,QAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CACF,CAAA,CASqB,CAEnB,GAAIL,EAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,GAA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A,CACA,OAAA,CAAAC,CAAAA,CACA,OAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,GAAG9B,CACL,CAAA,GAA4E,CAE1E,IAAMnC,CAAAA,CAAa0C,CAAAA,CAAkB,CACnC,SAAA,CAAAiB,CAAAA,CACA,WAAAC,CAAAA,CAEA,MAAA,CAAAE,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,EACA,WAAA,CAAAC,CACF,CAAC,CAAA,CAGD,OAAOC,YAAAA,CAAa,CAClB,UAAA,CAAAlE,EAEA,UAAA,CAAY0D,CAAAA,EAAcL,EAAAA,CAAwBzE,CAAM,EACxD,MAAA,CAAAA,CAAAA,CACA,GAAGuD,CACL,CAAC,CACH","file":"index.mjs","sourcesContent":["import { createViemClient } from '@tuwaio/orbit-evm';\nimport { Config, getBytecode } from '@wagmi/core';\nimport { Address } from 'viem';\nimport { Chain } from 'viem/chains';\n\n/**\n * An in-memory cache for wallets bytecode to avoid redundant requests to the blockchain.\n * Key is the wallet address, value is boolean indicating if it's a contract address.\n * @internal\n */\nconst walletsCache = new Map<string, boolean>();\n\n/**\n * Checks if a given wallet address is a smart contract by examining its bytecode\n *\n * @remarks\n * This function uses an in-memory cache to store results and avoid redundant blockchain requests.\n * The cache persists for the lifetime of the application session.\n *\n * @param config - Wagmi configuration object\n * @param address - Ethereum address to check\n * @param chainId - ID of the blockchain network\n * @param chains - Array of supported chain configurations\n *\n * @returns Promise resolving to boolean indicating if the address is a contract\n * - true: Address is a smart contract\n * - false: Address is an EOA (Externally Owned Account) or client creation failed\n *\n * @example\n * ```typescript\n * const isContract = await checkIsWalletAddressContract({\n * config: wagmiConfig,\n * address: \"0x1234...\",\n * chainId: 1,\n * chains: [mainnet, polygon]\n * });\n * ```\n *\n * @throws Will throw an error if getBytecode request fails\n */\nexport async function checkIsWalletAddressContract({\n config,\n address,\n chainId,\n chains,\n}: {\n /** Wagmi configuration for blockchain interaction */\n config: Config;\n /** Ethereum address to check */\n address: string;\n /** Chain ID where the check should be performed */\n chainId: number | string;\n /** Array of supported chain configurations */\n chains: readonly [Chain, ...Chain[]];\n}): Promise<boolean> {\n // Check cache first to avoid redundant blockchain requests\n if (walletsCache.has(address)) {\n return walletsCache.get(address)!;\n }\n\n // Create Viem client for blockchain interaction\n const client = createViemClient(chainId as number, chains);\n\n if (client) {\n // Get bytecode from the blockchain\n const codeOfWalletAddress = await getBytecode(config, {\n address: address as Address,\n });\n\n // Cache the result\n const isContract = !!codeOfWalletAddress;\n walletsCache.set(address, isContract);\n\n return isContract;\n } else {\n // Return false if client creation failed\n return false;\n }\n}\n","import { formatWalletName, getWalletTypeFromConnectorName, isSafeApp, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { checkAndSwitchChain, getAvatar, getName } from '@tuwaio/orbit-evm';\nimport { SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { Config, connect, disconnect, getAccount, getBalance, getChains, getConnectors } from '@wagmi/core';\nimport { Address, formatUnits, zeroAddress } from 'viem';\nimport { mainnet } from 'viem/chains';\n\nimport { ConnectorEVM } from '../types';\nimport { checkIsWalletAddressContract } from '../utils/checkIsWalletAddressContract';\n\n/**\n * Creates an EVM-compatible adapter for Satellite\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Ethereum Virtual Machine (EVM) compatible chains.\n * It uses wagmi as the underlying library for wallet connections and chain interactions.\n *\n * @param config - Wagmi configuration object containing chain and connector settings\n * @param signInWithSiwe - Optional function for signing in with SIWE\n * @returns A configured SatelliteAdapter instance for EVM chains\n * @throws Error if config is not provided\n *\n * @example\n * ```typescript\n * const config = createConfig({\n * chains: [mainnet, polygon],\n * connectors: [\n * new InjectedConnector(),\n * new WalletConnectConnector({ projectId: 'your_project_id' })\n * ]\n * });\n *\n * const evmAdapter = satelliteEVMAdapter(config);\n * ```\n */\nexport function satelliteEVMAdapter(\n config: Config,\n signInWithSiwe?: () => Promise<void>,\n): SatelliteAdapter<ConnectorEVM> {\n if (!config) throw new Error('Satellite EVM adapter requires a wagmi config object.');\n\n return {\n /** Identifies this adapter as EVM-compatible */\n key: OrbitAdapter.EVM,\n\n /**\n * Connects to an EVM wallet\n * @returns Connected wallet information\n * @throws Error if connector not found or connection fails\n */\n connect: async ({ walletType, chainId }) => {\n const connectors = getConnectors(config);\n const connector = connectors.find(\n (connector) =>\n getWalletTypeFromConnectorName(OrbitAdapter.EVM, formatWalletName(connector.name)) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n if (await connector.isAuthorized()) {\n await disconnect(config, { connector });\n }\n await connect(config, { connector, chainId: chainId as number });\n if (signInWithSiwe && !isSafeApp) {\n await signInWithSiwe();\n }\n const account = getAccount(config);\n\n return {\n walletType,\n address: account.address ?? zeroAddress,\n chainId: account.chainId ?? mainnet.id,\n rpcURL: account.chain?.rpcUrls.default.http[0] ?? mainnet.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n isContractAddress: false,\n walletIcon: connector?.icon?.trim(),\n connector,\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Disconnects the currently connected wallet\n */\n disconnect: async () => {\n const connectors = getConnectors(config);\n await Promise.allSettled(\n connectors.map(async (connector) => {\n await disconnect(config, { connector });\n }),\n );\n },\n\n /**\n * Retrieves available EVM wallet connectors\n * @returns Object containing adapter type and list of available connectors\n */\n getConnectors: () => {\n const connectors = getConnectors(config);\n return {\n adapter: OrbitAdapter.EVM,\n connectors: connectors.map((connector) => {\n return connector;\n }) as ConnectorEVM[],\n };\n },\n\n /**\n * Switches the connected wallet to specified network\n * @param chainId - Target chain ID to switch to\n */\n checkAndSwitchNetwork: async (chainId) => await checkAndSwitchChain(Number(chainId), config),\n\n getBalance: async (address, chainId) => {\n const balance = await getBalance(config, { address: address as Address, chainId: Number(chainId) });\n return {\n value: formatUnits(balance.value, balance.decimals),\n symbol: balance.symbol,\n };\n },\n\n /**\n * Generates blockchain explorer URLs for the current network\n * @param url - Optional path to append to base explorer URL\n * @returns Complete explorer URL or base explorer URL if no path provided\n */\n getExplorerUrl: (url) => {\n const { chain } = getAccount(config);\n const baseExplorerLink = chain?.blockExplorers?.default.url;\n return url ? `${baseExplorerLink}/${url}` : baseExplorerLink;\n },\n\n /**\n * Resolves ENS name for given address\n * @param address - Ethereum address to resolve\n * @returns ENS name if available, null otherwise\n */\n getName: (address: string) => getName(address as `0x${string}`),\n\n /**\n * Retrieves avatar for ENS name\n * @param name - ENS name to get avatar for\n * @returns Avatar URL if available, null otherwise\n */\n getAvatar: (name: string) => getAvatar(name),\n\n /**\n * Checks if given address is a smart contract\n * @param address - Address to check\n * @param chainId - Chain ID on which to perform the check\n * @returns Promise resolving to boolean indicating if address is a contract\n */\n checkIsContractWallet: async ({ address, chainId }) => {\n const chains = getChains(config);\n return await checkIsWalletAddressContract({ config, address, chainId, chains });\n },\n\n getSafeConnectorChainId: async () => {\n const connectors = getConnectors(config);\n const safeConnector = connectors.find((c) => c.name === 'Safe');\n if (safeConnector) {\n return await safeConnector.getChainId();\n } else {\n return undefined;\n }\n },\n };\n}\n","import { impersonatedHelpers } from '@tuwaio/orbit-core';\nimport { ChainNotConfiguredError, createConnector } from '@wagmi/core';\nimport {\n type Address,\n custom,\n type EIP1193RequestFn,\n fromHex,\n getAddress,\n type Hex,\n numberToHex,\n RpcRequestError,\n SwitchChainError,\n type Transport,\n UserRejectedRequestError,\n type WalletRpcSchema,\n zeroAddress,\n} from 'viem';\nimport { rpc } from 'viem/utils';\n\n/**\n * Configuration parameters for impersonated wallet connector\n */\nexport type ImpersonatedParameters = {\n /** Optional feature flags for testing error scenarios */\n features?: {\n /** Simulate connection error */\n connectError?: boolean | Error;\n /** Simulate chain switching error */\n switchChainError?: boolean | Error;\n /** Simulate message signing error */\n signMessageError?: boolean | Error;\n /** Simulate typed data signing error */\n signTypedDataError?: boolean | Error;\n /** Enable reconnection behavior */\n reconnect?: boolean;\n };\n};\n\n/**\n * Creates a wagmi connector for impersonating Ethereum accounts\n *\n * @remarks\n * This connector allows testing wallet interactions without an actual wallet by impersonating\n * an Ethereum address. It implements the EIP-1193 provider interface and can simulate\n * various error scenarios for testing purposes.\n *\n * @param parameters - Configuration options for the impersonated connector\n * @returns A wagmi connector instance\n *\n * @example\n * ```typescript\n * const connector = impersonated({\n * getAccountAddress: () => \"0x1234...\",\n * features: {\n * // Simulate errors for testing\n * connectError: false,\n * signMessageError: false\n * }\n * });\n * ```\n */\nimpersonated.type = 'impersonated' as const;\nexport function impersonated(parameters: ImpersonatedParameters) {\n const features = parameters.features ?? {};\n\n type Provider = ReturnType<Transport<'custom', NonNullable<unknown>, EIP1193RequestFn<WalletRpcSchema>>>;\n let connected = false;\n let connectedChainId: number;\n let accountAddress: Hex[] | undefined = undefined;\n\n return createConnector<Provider>((config) => ({\n id: 'impersonated',\n name: 'Impersonated Connector',\n type: impersonated.type,\n\n /**\n * Initial setup - sets default chain ID\n */\n async setup() {\n connectedChainId = config.chains[0].id;\n },\n /**\n * Simulates wallet connection\n * @throws {UserRejectedRequestError} When connection is rejected\n */\n // @ts-expect-error - not typed correctly\n async connect({ chainId } = {}) {\n if (features.connectError) {\n if (typeof features.connectError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to connect.'));\n throw features.connectError;\n }\n\n const { request } = await this.getProvider();\n const accounts = await request({\n method: 'eth_requestAccounts',\n });\n\n let currentChainId = await this.getChainId();\n if (chainId && currentChainId !== chainId) {\n const chain = await this.switchChain!({ chainId });\n currentChainId = chain.id;\n }\n\n connected = true;\n return { accounts, chainId: currentChainId };\n },\n\n /**\n * Simulates wallet disconnection\n */\n async disconnect() {\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Returns impersonated accounts\n * @throws {Error} When not connected\n */\n async getAccounts() {\n if (!connected) throw new Error('Not connected connector');\n const { request } = await this.getProvider();\n const accounts = await request({ method: 'eth_accounts' });\n return accounts.map(getAddress);\n },\n\n /**\n * Returns current chain ID\n */\n async getChainId() {\n const { request } = await this.getProvider();\n const hexChainId = await request({ method: 'eth_chainId' });\n return fromHex(hexChainId, 'number');\n },\n\n /**\n * Checks if wallet is connected and authorized\n */\n async isAuthorized() {\n if (!connected) return false;\n const accounts = await this.getAccounts();\n return !!accounts.length;\n },\n\n /**\n * Simulates switching to a different chain\n * @throws {SwitchChainError} When chain is not configured\n * @throws {UserRejectedRequestError} When switch is rejected\n */\n async switchChain({ chainId }) {\n const chain = config.chains.find((x) => x.id === chainId);\n if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());\n // @ts-expect-error - request is not typed correctly\n const { request } = await this.getProvider();\n await request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: numberToHex(chainId) }],\n });\n return chain;\n },\n\n /**\n * Handles account changes\n */\n onAccountsChanged(accounts) {\n if (accounts.length === 0) this.onDisconnect();\n else config.emitter.emit('change', { accounts: accounts.map(getAddress) });\n },\n\n /**\n * Handles chain changes\n */\n onChainChanged(chain) {\n const chainId = Number(chain);\n config.emitter.emit('change', { chainId });\n },\n\n /**\n * Handles disconnection\n */\n async onDisconnect() {\n config.emitter.emit('disconnect');\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Creates an EIP-1193 compatible provider\n * @returns Custom provider instance\n */\n async getProvider({ chainId }: { chainId?: number } = {}) {\n accountAddress = impersonatedHelpers?.getImpersonated()\n ? [(impersonatedHelpers.getImpersonated() as Address) || zeroAddress]\n : undefined;\n const chain = config.chains.find((x) => x.id === chainId) ?? config.chains[0];\n const url = chain.rpcUrls.default.http[0]!;\n\n const request: EIP1193RequestFn = async ({ method, params }) => {\n // eth methods\n if (method === 'eth_chainId') return numberToHex(connectedChainId);\n if (method === 'eth_requestAccounts') return accountAddress;\n if (method === 'eth_signTypedData_v4')\n if (features.signTypedDataError) {\n if (typeof features.signTypedDataError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign typed data.'));\n throw features.signTypedDataError;\n }\n\n // wallet methods\n if (method === 'wallet_switchEthereumChain') {\n if (features.switchChainError) {\n if (typeof features.switchChainError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to switch chain.'));\n throw features.switchChainError;\n }\n type Params = [{ chainId: Hex }];\n connectedChainId = fromHex((params as Params)[0].chainId, 'number');\n this.onChainChanged(connectedChainId.toString());\n return;\n }\n\n // other methods\n if (method === 'personal_sign') {\n if (features.signMessageError) {\n if (typeof features.signMessageError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign message.'));\n throw features.signMessageError;\n }\n // Change `personal_sign` to `eth_sign` and swap params\n method = 'eth_sign';\n type Params = [data: Hex, address: Address];\n params = [(params as Params)[1], (params as Params)[0]];\n }\n\n const body = { method, params };\n const { error, result } = await rpc.http(url, { body });\n if (error) throw new RpcRequestError({ body, error, url });\n\n return result;\n };\n return custom({ request })({ retryCount: 1 });\n },\n }));\n}\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { coinbaseWallet, injected, safe, walletConnect } from '@wagmi/connectors';\nimport { CreateConnectorFn } from '@wagmi/core';\n\nimport { impersonated } from './ImpersonatedConnector';\n\n/**\n * Configuration options for Gnosis Safe SDK\n * @remarks\n * Defines allowed domains and debug mode for Safe integration\n */\nexport const safeSdkOptions = {\n /** Regular expressions for allowed Safe wallet domains */\n allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/, /metissafe.tech$/],\n /** Enable debug mode */\n debug: false,\n};\n\n/**\n * Initializes all supported wallet connectors based on provided configuration\n *\n * @remarks\n * Creates instances of various wallet connectors including:\n * - Coinbase Wallet\n * - Gnosis Safe\n * - WalletConnect (if projectId provided)\n * - Impersonated wallet (for development/testing)\n *\n * The order of connectors in the returned array determines their priority\n * in the wallet connection UI.\n *\n * @param props - Configuration options for initializing connectors\n * @returns Array of wallet connector instances\n *\n * @example\n * ```typescript\n * const connectors = initAllConnectors({\n * appName: \"My dApp\",\n * projectId: \"wallet_connect_project_id\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const initAllConnectors = (props: ConnectorsInitProps): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const coinbaseConnector = coinbaseWallet({\n appName: props.appName,\n appLogoUrl: props.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n\n const connectors = [injectedConnector, coinbaseConnector, gnosisSafeConnector, impersonated({})];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n props.appUrl && props.appIcons && props.appName && props.description\n ? {\n name: props.appName,\n description: props.description,\n url: props.appUrl,\n icons: props.appIcons,\n }\n : undefined;\n\n if (props.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: props.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - connector has some different types\n connectors.push(walletConnectConnector);\n }\n\n return connectors;\n};\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { Config, createConfig, CreateConfigParameters, CreateConnectorFn } from '@wagmi/core';\nimport { http, Transport } from 'viem';\n\nimport { initAllConnectors } from '../connectors';\n\n/**\n * Creates default HTTP transports for each chain in the configuration\n *\n * @param chains - Array of chain configurations from wagmi\n * @returns Object mapping chain IDs to their corresponding HTTP transport instances\n *\n * @internal\n */\nconst createDefaultTransports = (chains: CreateConfigParameters['chains']): Record<number, Transport> => {\n return chains.reduce(\n (acc, chain) => {\n const key = chain.id;\n acc[key] = http() as Transport;\n return acc;\n },\n {} as Record<number, Transport>,\n );\n};\n\n/**\n * Creates a Wagmi configuration with initialized connectors and transports\n *\n * @remarks\n * This function combines Satellite connector initialization with Wagmi configuration.\n * It automatically sets up HTTP transports for each chain if custom transports are not provided.\n *\n * @param config - Combined configuration parameters for Satellite and Wagmi\n * @param config.chains - Array of supported blockchain networks\n * @param config.transports - Optional custom transport configurations for each chain\n * @param config.projectId - WalletConnect project ID\n * @param config.appName - Application name for wallet connection UI\n * @param config.appUrl - Application URL for metadata\n * @param config.appLogoUrl - URL to application logo\n * @param config.appLogo - Optional inline logo data\n * @param config.appIcons - Array of application icon URLs\n * @param config.description - Application description for wallet connection UI\n *\n * @returns Configured Wagmi instance\n *\n * @example\n * ```typescript\n * const config = createWagmiConfig({\n * chains: [mainnet, polygon],\n * projectId: \"your_project_id\",\n * appName: \"My dApp\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const createWagmiConfig = ({\n chains,\n transports,\n projectId,\n appLogoUrl,\n appLogo,\n appUrl,\n appIcons,\n appName,\n description,\n ...params\n}: ConnectorsInitProps & Omit<CreateConfigParameters, 'client'>): Config => {\n // Initialize wallet connectors with provided configuration\n const connectors = initAllConnectors({\n projectId,\n appLogoUrl,\n appLogo,\n appUrl,\n appIcons,\n appName,\n description,\n }) as CreateConnectorFn[];\n\n // Create and return the complete Wagmi configuration\n return createConfig({\n connectors,\n // Use custom transports if provided, otherwise create default HTTP transports\n transports: transports ?? createDefaultTransports(chains),\n chains,\n ...params,\n });\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.ts","../src/connectors/ImpersonatedConnector.ts","../src/connectors/index.ts","../src/utils/createDefaultTransports.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","disconnect","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","impersonated","parameters","features","connected","connectedChainId","accountAddress","createConnector","UserRejectedRequestError","request","accounts","currentChainId","getAddress","hexChainId","fromHex","x","SwitchChainError","ChainNotConfiguredError","numberToHex","impersonatedHelpers","custom","method","params","body","error","result","rpc","RpcRequestError","safeSdkOptions","initAllConnectors","props","injectedConnector","injected","coinbaseConnector","coinbaseWallet","gnosisSafeConnector","safe","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http"],"mappings":"4nBAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CACF,CAAA,CASqB,CAEnB,GAAIL,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAMjC,GAFeG,gBAAAA,CAAiBF,CAAAA,CAAmBC,CAAM,EAE7C,CAOV,IAAME,CAAAA,CAAa,CAAC,CALQ,MAAMC,WAAAA,CAAYN,CAAAA,CAAQ,CACpD,OAAA,CAASC,CACX,CAAC,CAAA,CAID,OAAAH,CAAAA,CAAa,GAAA,CAAIG,EAASI,CAAU,CAAA,CAE7BA,CACT,CAAA,KAEE,OAAO,MAEX,CC3CO,SAASE,EAAAA,CACdP,CAAAA,CACAQ,CAAAA,CACgC,CAChC,GAAI,CAACR,CAAAA,CAAQ,MAAM,IAAI,KAAA,CAAM,uDAAuD,CAAA,CAEpF,OAAO,CAEL,GAAA,CAAKS,YAAAA,CAAa,GAAA,CAOlB,OAAA,CAAS,MAAO,CAAE,UAAA,CAAAC,CAAAA,CAAY,OAAA,CAAAR,CAAQ,CAAA,GAAM,CAE1C,IAAMS,CAAAA,CADaC,aAAAA,CAAcZ,CAAM,CAAA,CACV,IAAA,CAC1BW,CAAAA,EACCE,8BAAAA,CAA+BJ,YAAAA,CAAa,GAAA,CAAKK,gBAAAA,CAAiBH,CAAAA,CAAU,IAAI,CAAC,CAAA,GAAMD,CAC3F,EACA,GAAI,CAACC,CAAAA,CAAW,MAAM,IAAI,KAAA,CAAM,6CAA6C,CAAA,CAE7E,GAAI,CACE,MAAMA,CAAAA,CAAU,YAAA,EAAa,EAC/B,MAAMI,UAAAA,C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M,SAAA,CACjB,QAAA,CAAUO,CACZ,CAAC,CAAA,CAEDlD,CAAAA,CAAW,IAAA,CAAKmD,CAAsB,EACxC,CAEA,OAAOnD,CACT,EClEO,IAAMqD,EAAAA,CAA2BxE,CAAAA,EAC/BA,EAAO,MAAA,CACZ,CAACyE,CAAAA,CAAKhD,CAAAA,GAAU,CACd,IAAMiD,CAAAA,CAAMjD,CAAAA,CAAM,GAClB,OAAAgD,CAAAA,CAAIC,CAAG,CAAA,CAAIC,IAAAA,EAAK,CACTF,CACT,CAAA,CACA,EACF","file":"index.mjs","sourcesContent":["import { createViemClient } from '@tuwaio/orbit-evm';\nimport { Config, getBytecode } from '@wagmi/core';\nimport { Address } from 'viem';\nimport { Chain } from 'viem/chains';\n\n/**\n * An in-memory cache for wallets bytecode to avoid redundant requests to the blockchain.\n * Key is the wallet address, value is boolean indicating if it's a contract address.\n * @internal\n */\nconst walletsCache = new Map<string, boolean>();\n\n/**\n * Checks if a given wallet address is a smart contract by examining its bytecode\n *\n * @remarks\n * This function uses an in-memory cache to store results and avoid redundant blockchain requests.\n * The cache persists for the lifetime of the application session.\n *\n * @param config - Wagmi configuration object\n * @param address - Ethereum address to check\n * @param chainId - ID of the blockchain network\n * @param chains - Array of supported chain configurations\n *\n * @returns Promise resolving to boolean indicating if the address is a contract\n * - true: Address is a smart contract\n * - false: Address is an EOA (Externally Owned Account) or client creation failed\n *\n * @example\n * ```typescript\n * const isContract = await checkIsWalletAddressContract({\n * config: wagmiConfig,\n * address: \"0x1234...\",\n * chainId: 1,\n * chains: [mainnet, polygon]\n * });\n * ```\n *\n * @throws Will throw an error if getBytecode request fails\n */\nexport async function checkIsWalletAddressContract({\n config,\n address,\n chainId,\n chains,\n}: {\n /** Wagmi configuration for blockchain interaction */\n config: Config;\n /** Ethereum address to check */\n address: string;\n /** Chain ID where the check should be performed */\n chainId: number | string;\n /** Array of supported chain configurations */\n chains: readonly [Chain, ...Chain[]];\n}): Promise<boolean> {\n // Check cache first to avoid redundant blockchain requests\n if (walletsCache.has(address)) {\n return walletsCache.get(address)!;\n }\n\n // Create Viem client for blockchain interaction\n const client = createViemClient(chainId as number, chains);\n\n if (client) {\n // Get bytecode from the blockchain\n const codeOfWalletAddress = await getBytecode(config, {\n address: address as Address,\n });\n\n // Cache the result\n const isContract = !!codeOfWalletAddress;\n walletsCache.set(address, isContract);\n\n return isContract;\n } else {\n // Return false if client creation failed\n return false;\n }\n}\n","import { formatWalletName, getWalletTypeFromConnectorName, isSafeApp, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { checkAndSwitchChain, getAvatar, getName } from '@tuwaio/orbit-evm';\nimport { SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { Config, connect, disconnect, getAccount, getBalance, getChains, getConnectors } from '@wagmi/core';\nimport { Address, formatUnits, zeroAddress } from 'viem';\nimport { mainnet } from 'viem/chains';\n\nimport { ConnectorEVM } from '../types';\nimport { checkIsWalletAddressContract } from '../utils/checkIsWalletAddressContract';\n\n/**\n * Creates an EVM-compatible adapter for Satellite\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Ethereum Virtual Machine (EVM) compatible chains.\n * It uses wagmi as the underlying library for wallet connections and chain interactions.\n *\n * @param config - Wagmi configuration object containing chain and connector settings\n * @param signInWithSiwe - Optional function for signing in with SIWE\n * @returns A configured SatelliteAdapter instance for EVM chains\n * @throws Error if config is not provided\n *\n * @example\n * ```typescript\n * const config = createConfig({\n * chains: [mainnet, polygon],\n * connectors: [\n * new InjectedConnector(),\n * new WalletConnectConnector({ projectId: 'your_project_id' })\n * ]\n * });\n *\n * const evmAdapter = satelliteEVMAdapter(config);\n * ```\n */\nexport function satelliteEVMAdapter(\n config: Config,\n signInWithSiwe?: () => Promise<void>,\n): SatelliteAdapter<ConnectorEVM> {\n if (!config) throw new Error('Satellite EVM adapter requires a wagmi config object.');\n\n return {\n /** Identifies this adapter as EVM-compatible */\n key: OrbitAdapter.EVM,\n\n /**\n * Connects to an EVM wallet\n * @returns Connected wallet information\n * @throws Error if connector not found or connection fails\n */\n connect: async ({ walletType, chainId }) => {\n const connectors = getConnectors(config);\n const connector = connectors.find(\n (connector) =>\n getWalletTypeFromConnectorName(OrbitAdapter.EVM, formatWalletName(connector.name)) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n if (await connector.isAuthorized()) {\n await disconnect(config, { connector });\n }\n await connect(config, { connector, chainId: chainId as number });\n if (signInWithSiwe && !isSafeApp) {\n await signInWithSiwe();\n }\n const account = getAccount(config);\n\n return {\n walletType,\n address: account.address ?? zeroAddress,\n chainId: account.chainId ?? mainnet.id,\n rpcURL: account.chain?.rpcUrls.default.http[0] ?? mainnet.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n isContractAddress: false,\n walletIcon: connector?.icon?.trim(),\n connector,\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n /**\n * Disconnects the currently connected wallet\n */\n disconnect: async () => {\n const connectors = getConnectors(config);\n await Promise.allSettled(\n connectors.map(async (connector) => {\n await disconnect(config, { connector });\n }),\n );\n },\n\n /**\n * Retrieves available EVM wallet connectors\n * @returns Object containing adapter type and list of available connectors\n */\n getConnectors: () => {\n const connectors = getConnectors(config);\n return {\n adapter: OrbitAdapter.EVM,\n connectors: connectors.map((connector) => {\n return connector;\n }) as ConnectorEVM[],\n };\n },\n\n /**\n * Switches the connected wallet to specified network\n * @param chainId - Target chain ID to switch to\n */\n checkAndSwitchNetwork: async (chainId) => await checkAndSwitchChain(Number(chainId), config),\n\n getBalance: async (address, chainId) => {\n const balance = await getBalance(config, { address: address as Address, chainId: Number(chainId) });\n return {\n value: formatUnits(balance.value, balance.decimals),\n symbol: balance.symbol,\n };\n },\n\n /**\n * Generates blockchain explorer URLs for the current network\n * @param url - Optional path to append to base explorer URL\n * @returns Complete explorer URL or base explorer URL if no path provided\n */\n getExplorerUrl: (url) => {\n const { chain } = getAccount(config);\n const baseExplorerLink = chain?.blockExplorers?.default.url;\n return url ? `${baseExplorerLink}/${url}` : baseExplorerLink;\n },\n\n /**\n * Resolves ENS name for given address\n * @param address - Ethereum address to resolve\n * @returns ENS name if available, null otherwise\n */\n getName: (address: string) => getName(address as `0x${string}`),\n\n /**\n * Retrieves avatar for ENS name\n * @param name - ENS name to get avatar for\n * @returns Avatar URL if available, null otherwise\n */\n getAvatar: (name: string) => getAvatar(name),\n\n /**\n * Checks if given address is a smart contract\n * @param address - Address to check\n * @param chainId - Chain ID on which to perform the check\n * @returns Promise resolving to boolean indicating if address is a contract\n */\n checkIsContractWallet: async ({ address, chainId }) => {\n const chains = getChains(config);\n return await checkIsWalletAddressContract({ config, address, chainId, chains });\n },\n\n getSafeConnectorChainId: async () => {\n const connectors = getConnectors(config);\n const safeConnector = connectors.find((c) => c.name === 'Safe');\n if (safeConnector) {\n return await safeConnector.getChainId();\n } else {\n return undefined;\n }\n },\n };\n}\n","import { impersonatedHelpers } from '@tuwaio/orbit-core';\nimport { ChainNotConfiguredError, createConnector } from '@wagmi/core';\nimport {\n type Address,\n custom,\n type EIP1193RequestFn,\n fromHex,\n getAddress,\n type Hex,\n numberToHex,\n RpcRequestError,\n SwitchChainError,\n type Transport,\n UserRejectedRequestError,\n type WalletRpcSchema,\n zeroAddress,\n} from 'viem';\nimport { rpc } from 'viem/utils';\n\n/**\n * Configuration parameters for impersonated wallet connector\n */\nexport type ImpersonatedParameters = {\n /** Optional feature flags for testing error scenarios */\n features?: {\n /** Simulate connection error */\n connectError?: boolean | Error;\n /** Simulate chain switching error */\n switchChainError?: boolean | Error;\n /** Simulate message signing error */\n signMessageError?: boolean | Error;\n /** Simulate typed data signing error */\n signTypedDataError?: boolean | Error;\n /** Enable reconnection behavior */\n reconnect?: boolean;\n };\n};\n\n/**\n * Creates a wagmi connector for impersonating Ethereum accounts\n *\n * @remarks\n * This connector allows testing wallet interactions without an actual wallet by impersonating\n * an Ethereum address. It implements the EIP-1193 provider interface and can simulate\n * various error scenarios for testing purposes.\n *\n * @param parameters - Configuration options for the impersonated connector\n * @returns A wagmi connector instance\n *\n * @example\n * ```typescript\n * const connector = impersonated({\n * getAccountAddress: () => \"0x1234...\",\n * features: {\n * // Simulate errors for testing\n * connectError: false,\n * signMessageError: false\n * }\n * });\n * ```\n */\nimpersonated.type = 'impersonated' as const;\nexport function impersonated(parameters: ImpersonatedParameters) {\n const features = parameters.features ?? {};\n\n type Provider = ReturnType<Transport<'custom', NonNullable<unknown>, EIP1193RequestFn<WalletRpcSchema>>>;\n let connected = false;\n let connectedChainId: number;\n let accountAddress: Hex[] | undefined = undefined;\n\n return createConnector<Provider>((config) => ({\n id: 'impersonated',\n name: 'Impersonated Connector',\n type: impersonated.type,\n\n /**\n * Initial setup - sets default chain ID\n */\n async setup() {\n connectedChainId = config.chains[0].id;\n },\n /**\n * Simulates wallet connection\n * @throws {UserRejectedRequestError} When connection is rejected\n */\n // @ts-expect-error - not typed correctly\n async connect({ chainId } = {}) {\n if (features.connectError) {\n if (typeof features.connectError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to connect.'));\n throw features.connectError;\n }\n\n const { request } = await this.getProvider();\n const accounts = await request({\n method: 'eth_requestAccounts',\n });\n\n let currentChainId = await this.getChainId();\n if (chainId && currentChainId !== chainId) {\n const chain = await this.switchChain!({ chainId });\n currentChainId = chain.id;\n }\n\n connected = true;\n return { accounts, chainId: currentChainId };\n },\n\n /**\n * Simulates wallet disconnection\n */\n async disconnect() {\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Returns impersonated accounts\n * @throws {Error} When not connected\n */\n async getAccounts() {\n if (!connected) throw new Error('Not connected connector');\n const { request } = await this.getProvider();\n const accounts = await request({ method: 'eth_accounts' });\n return accounts.map(getAddress);\n },\n\n /**\n * Returns current chain ID\n */\n async getChainId() {\n const { request } = await this.getProvider();\n const hexChainId = await request({ method: 'eth_chainId' });\n return fromHex(hexChainId, 'number');\n },\n\n /**\n * Checks if wallet is connected and authorized\n */\n async isAuthorized() {\n if (!connected) return false;\n const accounts = await this.getAccounts();\n return !!accounts.length;\n },\n\n /**\n * Simulates switching to a different chain\n * @throws {SwitchChainError} When chain is not configured\n * @throws {UserRejectedRequestError} When switch is rejected\n */\n async switchChain({ chainId }) {\n const chain = config.chains.find((x) => x.id === chainId);\n if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());\n // @ts-expect-error - request is not typed correctly\n const { request } = await this.getProvider();\n await request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: numberToHex(chainId) }],\n });\n return chain;\n },\n\n /**\n * Handles account changes\n */\n onAccountsChanged(accounts) {\n if (accounts.length === 0) this.onDisconnect();\n else config.emitter.emit('change', { accounts: accounts.map(getAddress) });\n },\n\n /**\n * Handles chain changes\n */\n onChainChanged(chain) {\n const chainId = Number(chain);\n config.emitter.emit('change', { chainId });\n },\n\n /**\n * Handles disconnection\n */\n async onDisconnect() {\n config.emitter.emit('disconnect');\n connected = false;\n accountAddress = undefined;\n },\n\n /**\n * Creates an EIP-1193 compatible provider\n * @returns Custom provider instance\n */\n async getProvider({ chainId }: { chainId?: number } = {}) {\n accountAddress = impersonatedHelpers?.getImpersonated()\n ? [(impersonatedHelpers.getImpersonated() as Address) || zeroAddress]\n : undefined;\n const chain = config.chains.find((x) => x.id === chainId) ?? config.chains[0];\n const url = chain.rpcUrls.default.http[0]!;\n\n const request: EIP1193RequestFn = async ({ method, params }) => {\n // eth methods\n if (method === 'eth_chainId') return numberToHex(connectedChainId);\n if (method === 'eth_requestAccounts') return accountAddress;\n if (method === 'eth_signTypedData_v4')\n if (features.signTypedDataError) {\n if (typeof features.signTypedDataError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign typed data.'));\n throw features.signTypedDataError;\n }\n\n // wallet methods\n if (method === 'wallet_switchEthereumChain') {\n if (features.switchChainError) {\n if (typeof features.switchChainError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to switch chain.'));\n throw features.switchChainError;\n }\n type Params = [{ chainId: Hex }];\n connectedChainId = fromHex((params as Params)[0].chainId, 'number');\n this.onChainChanged(connectedChainId.toString());\n return;\n }\n\n // other methods\n if (method === 'personal_sign') {\n if (features.signMessageError) {\n if (typeof features.signMessageError === 'boolean')\n throw new UserRejectedRequestError(new Error('Failed to sign message.'));\n throw features.signMessageError;\n }\n // Change `personal_sign` to `eth_sign` and swap params\n method = 'eth_sign';\n type Params = [data: Hex, address: Address];\n params = [(params as Params)[1], (params as Params)[0]];\n }\n\n const body = { method, params };\n const { error, result } = await rpc.http(url, { body });\n if (error) throw new RpcRequestError({ body, error, url });\n\n return result;\n };\n return custom({ request })({ retryCount: 1 });\n },\n }));\n}\n","import { ConnectorsInitProps } from '@tuwaio/satellite-core';\nimport { coinbaseWallet, injected, safe, walletConnect } from '@wagmi/connectors';\nimport { CreateConnectorFn } from '@wagmi/core';\n\nimport { impersonated } from './ImpersonatedConnector';\n\n/**\n * Configuration options for Gnosis Safe SDK\n * @remarks\n * Defines allowed domains and debug mode for Safe integration\n */\nexport const safeSdkOptions = {\n /** Regular expressions for allowed Safe wallet domains */\n allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/, /metissafe.tech$/],\n /** Enable debug mode */\n debug: false,\n};\n\n/**\n * Initializes all supported wallet connectors based on provided configuration\n *\n * @remarks\n * Creates instances of various wallet connectors including:\n * - Coinbase Wallet\n * - Gnosis Safe\n * - WalletConnect (if projectId provided)\n * - Impersonated wallet (for development/testing)\n *\n * The order of connectors in the returned array determines their priority\n * in the wallet connection UI.\n *\n * @param props - Configuration options for initializing connectors\n * @returns Array of wallet connector instances\n *\n * @example\n * ```typescript\n * const connectors = initAllConnectors({\n * appName: \"My dApp\",\n * projectId: \"wallet_connect_project_id\",\n * appUrl: \"https://mydapp.com\",\n * appLogoUrl: \"https://mydapp.com/logo.png\"\n * });\n * ```\n */\nexport const initAllConnectors = (props: ConnectorsInitProps): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const coinbaseConnector = coinbaseWallet({\n appName: props.appName,\n appLogoUrl: props.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n\n const connectors = [injectedConnector, coinbaseConnector, gnosisSafeConnector, impersonated({})];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n props.appUrl && props.appIcons && props.appName && props.description\n ? {\n name: props.appName,\n description: props.description,\n url: props.appUrl,\n icons: props.appIcons,\n }\n : undefined;\n\n if (props.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: props.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - connector has some different types\n connectors.push(walletConnectConnector);\n }\n\n return connectors;\n};\n","import { CreateConfigParameters } from '@wagmi/core';\nimport { http, Transport } from 'viem';\n\n/**\n * Creates default HTTP transports for each chain in the configuration\n *\n * @param chains - Array of chain configurations from wagmi\n * @returns Object mapping chain IDs to their corresponding HTTP transport instances\n *\n * @public\n */\nexport const createDefaultTransports = (chains: CreateConfigParameters['chains']): Record<number, Transport> => {\n return chains.reduce(\n (acc, chain) => {\n const key = chain.id;\n acc[key] = http() as Transport;\n return acc;\n },\n {} as Record<number, Transport>,\n );\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/satellite-evm",
|
|
3
|
-
"version": "1.0.0-fix-test-alpha.
|
|
3
|
+
"version": "1.0.0-fix-test-alpha.61.e356934",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"viem": "^2.38.2",
|
|
62
62
|
"vitest": "^3.2.4",
|
|
63
63
|
"zustand": "^5.0.8",
|
|
64
|
-
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.
|
|
65
|
-
"@tuwaio/orbit-evm": "^1.0.0-fix-test-alpha.
|
|
66
|
-
"@tuwaio/satellite-core": "^1.0.0-fix-test-alpha.
|
|
64
|
+
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.61.e356934",
|
|
65
|
+
"@tuwaio/orbit-evm": "^1.0.0-fix-test-alpha.61.e356934",
|
|
66
|
+
"@tuwaio/satellite-core": "^1.0.0-fix-test-alpha.61.e356934"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"start": "tsup src/index.ts --watch",
|