@tuwaio/satellite-evm 1.0.0-fix-gemini-alpha.1.81f88ab → 1.0.0-fix-packages-alpha.1.bd0ce80
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/README.md +8 -44
- package/dist/index.d.mts +3 -38
- package/dist/index.d.ts +3 -38
- 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 +12 -17
package/README.md
CHANGED
|
@@ -29,18 +29,19 @@ Built on top of `@tuwaio/satellite-core`, this package integrates seamlessly wit
|
|
|
29
29
|
## 💾 Installation
|
|
30
30
|
|
|
31
31
|
### Requirements
|
|
32
|
+
|
|
32
33
|
- Node.js 20+
|
|
33
34
|
- TypeScript 5.9+
|
|
34
35
|
|
|
35
36
|
```bash
|
|
36
37
|
# Using pnpm (recommended)
|
|
37
|
-
pnpm add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @
|
|
38
|
+
pnpm add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @tuwaio/orbit-core @tuwaio/orbit-evm
|
|
38
39
|
|
|
39
40
|
# Using npm
|
|
40
|
-
npm install @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @
|
|
41
|
+
npm install @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @tuwaio/orbit-core @tuwaio/orbit-evm
|
|
41
42
|
|
|
42
43
|
# Using yarn
|
|
43
|
-
yarn add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @
|
|
44
|
+
yarn add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zustand @tuwaio/orbit-core @tuwaio/orbit-evm
|
|
44
45
|
````
|
|
45
46
|
|
|
46
47
|
-----
|
|
@@ -50,30 +51,19 @@ yarn add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core immer zus
|
|
|
50
51
|
### Basic Configuration
|
|
51
52
|
|
|
52
53
|
```typescript
|
|
53
|
-
import { createDefaultTransports
|
|
54
|
-
import { createConfig
|
|
54
|
+
import { createDefaultTransports } from '@tuwaio/satellite-evm';
|
|
55
|
+
import { createConfig } from '@wagmi/core';
|
|
56
|
+
import { injected } from '@wagmi/connectors';
|
|
55
57
|
import { mainnet, sepolia } from 'viem/chains';
|
|
56
58
|
import type { Chain } from 'viem/chains';
|
|
57
59
|
|
|
58
|
-
export const appConfig = {
|
|
59
|
-
appName: 'Satellite EVM Test App',
|
|
60
|
-
// Ensure you have WalletConnect Project ID in your environment variables
|
|
61
|
-
projectId: process.env.NEXT_PUBLIC_WALLET_PROJECT_ID ?? 'YOUR_OWN_PROJECT_ID',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
60
|
export const appEVMChains = [
|
|
65
61
|
mainnet,
|
|
66
62
|
sepolia,
|
|
67
63
|
] as readonly [Chain, ...Chain[]];
|
|
68
64
|
|
|
69
65
|
export const wagmiConfig = createConfig({
|
|
70
|
-
connectors:
|
|
71
|
-
...appConfig,
|
|
72
|
-
// Optional: Add app details for WalletConnect modal
|
|
73
|
-
description: 'My awesome dApp',
|
|
74
|
-
appUrl: '[https://my-dapp.com](https://my-dapp.com)',
|
|
75
|
-
appIcons: ['[https://my-dapp.com/icon.png](https://my-dapp.com/icon.png)'],
|
|
76
|
-
}),
|
|
66
|
+
connectors: [injected()],
|
|
77
67
|
transports: createDefaultTransports(appEVMChains), // Automatically creates http transports
|
|
78
68
|
chains: appEVMChains,
|
|
79
69
|
ssr: true, // Enable SSR support if needed (e.g., in Next.js)
|
|
@@ -189,35 +179,9 @@ function RootLayout({ children }: { children: React.ReactNode }) {
|
|
|
189
179
|
|
|
190
180
|
## 🛠️ Core Utilities
|
|
191
181
|
|
|
192
|
-
- **`initAllConnectors`**: Initializes default EVM connectors (`injected`, `coinbaseWallet`, `safe`, `walletConnect` if `projectId` is provided, and a development `impersonated` connector).
|
|
193
182
|
- **`createDefaultTransports`**: Helper to create default `http` transports for each chain in your `wagmiConfig`.
|
|
194
183
|
- **`checkIsWalletAddressContract`**: Utility to check if a connected address is a smart contract address. The result is cached in memory.
|
|
195
184
|
|
|
196
|
-
-----
|
|
197
|
-
|
|
198
|
-
## 🌐 Supported Wallets
|
|
199
|
-
|
|
200
|
-
- MetaMask
|
|
201
|
-
- WalletConnect v2
|
|
202
|
-
- Coinbase Wallet
|
|
203
|
-
- Safe (Gnosis Safe)
|
|
204
|
-
- And other EVM-compatible wallets injected into the browser
|
|
205
|
-
|
|
206
|
-
-----
|
|
207
|
-
|
|
208
|
-
## 🔗 Chain Support
|
|
209
|
-
|
|
210
|
-
Supports any EVM chain configured in your `wagmiConfig`. Examples:
|
|
211
|
-
|
|
212
|
-
- Ethereum Mainnet
|
|
213
|
-
- Sepolia Testnet
|
|
214
|
-
- Polygon
|
|
215
|
-
- Arbitrum
|
|
216
|
-
- Optimism
|
|
217
|
-
- And other EVM-compatible networks
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
185
|
## 🤝 Contributing & Support
|
|
222
186
|
|
|
223
187
|
Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BaseWallet, SatelliteAdapter
|
|
1
|
+
import { BaseWallet, SatelliteAdapter } from '@tuwaio/satellite-core';
|
|
2
2
|
import { Connector, CreateConnectorFn, Config, CreateConfigParameters } from '@wagmi/core';
|
|
3
|
-
import { GeminiParameters, PortoParameters } from '@wagmi/connectors';
|
|
4
3
|
import { Chain } from 'viem/chains';
|
|
5
4
|
import { Transport } from 'viem';
|
|
6
5
|
|
|
@@ -42,7 +41,7 @@ interface EVMWallet extends BaseWallet {
|
|
|
42
41
|
declare function satelliteEVMAdapter(config: Config, signInWithSiwe?: () => Promise<void>): SatelliteAdapter<ConnectorEVM>;
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
|
-
* Configuration options for
|
|
44
|
+
* Configuration options for Safe SDK
|
|
46
45
|
* @remarks
|
|
47
46
|
* Defines allowed domains and debug mode for Safe integration
|
|
48
47
|
*/
|
|
@@ -52,40 +51,6 @@ declare const safeSdkOptions: {
|
|
|
52
51
|
/** Enable debug mode */
|
|
53
52
|
debug: boolean;
|
|
54
53
|
};
|
|
55
|
-
/**
|
|
56
|
-
* Initializes all supported wallet connectors based on provided configuration
|
|
57
|
-
*
|
|
58
|
-
* @remarks
|
|
59
|
-
* Creates instances of various wallet connectors including:
|
|
60
|
-
* - Injected wallets (e.g., MetaMask, Phantom, Trust Wallet, etc.)
|
|
61
|
-
* - Coinbase Wallet
|
|
62
|
-
* - Gnosis Safe
|
|
63
|
-
* - WalletConnect (if projectId provided)
|
|
64
|
-
* - Impersonated wallet (for development/testing)
|
|
65
|
-
*
|
|
66
|
-
* The order of connectors in the returned array determines their priority
|
|
67
|
-
* in the wallet connection UI.
|
|
68
|
-
*
|
|
69
|
-
* @param props - Configuration options for initializing connectors
|
|
70
|
-
* @param geminiParameters - Optional parameters for Gemini wallet connector
|
|
71
|
-
* @param portoParameters - Optional parameters for Porto wallet connector
|
|
72
|
-
* @returns Array of wallet connector instances
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const connectors = initAllConnectors({
|
|
77
|
-
* appName: "My dApp",
|
|
78
|
-
* projectId: "wallet_connect_project_id",
|
|
79
|
-
* appUrl: "https://mydapp.com",
|
|
80
|
-
* appLogoUrl: "https://mydapp.com/logo.png"
|
|
81
|
-
* });
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
declare const initAllConnectors: ({ initialParameters, geminiParameters, portoParameters, }: {
|
|
85
|
-
initialParameters: ConnectorsInitProps;
|
|
86
|
-
geminiParameters?: GeminiParameters;
|
|
87
|
-
portoParameters?: PortoParameters;
|
|
88
|
-
}) => readonly CreateConnectorFn[];
|
|
89
54
|
|
|
90
55
|
/**
|
|
91
56
|
* Checks if a given wallet address is a smart contract by examining its bytecode
|
|
@@ -136,4 +101,4 @@ declare function checkIsWalletAddressContract({ config, address, chainId, chains
|
|
|
136
101
|
*/
|
|
137
102
|
declare const createDefaultTransports: (chains: CreateConfigParameters["chains"]) => Record<number, Transport>;
|
|
138
103
|
|
|
139
|
-
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports,
|
|
104
|
+
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports, safeSdkOptions, satelliteEVMAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BaseWallet, SatelliteAdapter
|
|
1
|
+
import { BaseWallet, SatelliteAdapter } from '@tuwaio/satellite-core';
|
|
2
2
|
import { Connector, CreateConnectorFn, Config, CreateConfigParameters } from '@wagmi/core';
|
|
3
|
-
import { GeminiParameters, PortoParameters } from '@wagmi/connectors';
|
|
4
3
|
import { Chain } from 'viem/chains';
|
|
5
4
|
import { Transport } from 'viem';
|
|
6
5
|
|
|
@@ -42,7 +41,7 @@ interface EVMWallet extends BaseWallet {
|
|
|
42
41
|
declare function satelliteEVMAdapter(config: Config, signInWithSiwe?: () => Promise<void>): SatelliteAdapter<ConnectorEVM>;
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
|
-
* Configuration options for
|
|
44
|
+
* Configuration options for Safe SDK
|
|
46
45
|
* @remarks
|
|
47
46
|
* Defines allowed domains and debug mode for Safe integration
|
|
48
47
|
*/
|
|
@@ -52,40 +51,6 @@ declare const safeSdkOptions: {
|
|
|
52
51
|
/** Enable debug mode */
|
|
53
52
|
debug: boolean;
|
|
54
53
|
};
|
|
55
|
-
/**
|
|
56
|
-
* Initializes all supported wallet connectors based on provided configuration
|
|
57
|
-
*
|
|
58
|
-
* @remarks
|
|
59
|
-
* Creates instances of various wallet connectors including:
|
|
60
|
-
* - Injected wallets (e.g., MetaMask, Phantom, Trust Wallet, etc.)
|
|
61
|
-
* - Coinbase Wallet
|
|
62
|
-
* - Gnosis Safe
|
|
63
|
-
* - WalletConnect (if projectId provided)
|
|
64
|
-
* - Impersonated wallet (for development/testing)
|
|
65
|
-
*
|
|
66
|
-
* The order of connectors in the returned array determines their priority
|
|
67
|
-
* in the wallet connection UI.
|
|
68
|
-
*
|
|
69
|
-
* @param props - Configuration options for initializing connectors
|
|
70
|
-
* @param geminiParameters - Optional parameters for Gemini wallet connector
|
|
71
|
-
* @param portoParameters - Optional parameters for Porto wallet connector
|
|
72
|
-
* @returns Array of wallet connector instances
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const connectors = initAllConnectors({
|
|
77
|
-
* appName: "My dApp",
|
|
78
|
-
* projectId: "wallet_connect_project_id",
|
|
79
|
-
* appUrl: "https://mydapp.com",
|
|
80
|
-
* appLogoUrl: "https://mydapp.com/logo.png"
|
|
81
|
-
* });
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
declare const initAllConnectors: ({ initialParameters, geminiParameters, portoParameters, }: {
|
|
85
|
-
initialParameters: ConnectorsInitProps;
|
|
86
|
-
geminiParameters?: GeminiParameters;
|
|
87
|
-
portoParameters?: PortoParameters;
|
|
88
|
-
}) => readonly CreateConnectorFn[];
|
|
89
54
|
|
|
90
55
|
/**
|
|
91
56
|
* Checks if a given wallet address is a smart contract by examining its bytecode
|
|
@@ -136,4 +101,4 @@ declare function checkIsWalletAddressContract({ config, address, chainId, chains
|
|
|
136
101
|
*/
|
|
137
102
|
declare const createDefaultTransports: (chains: CreateConfigParameters["chains"]) => Record<number, Transport>;
|
|
138
103
|
|
|
139
|
-
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports,
|
|
104
|
+
export { type ConnectorEVM, type EVMWallet, checkIsWalletAddressContract, createDefaultTransports, 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')
|
|
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');var i=new Map;async function p({config:t,address:a,chainId:e,chains:r}){if(i.has(a))return i.get(a);if(orbitEvm.createViemClient(e,r)){let o=!!await core.getBytecode(t,{address:a});return i.set(a,o),o}else return false}function L(t,a){if(!t)throw new Error("Satellite EVM adapter requires a wagmi config object.");return {key:orbitCore.OrbitAdapter.EVM,connect:async({walletType:e,chainId:r})=>{let s=core.getConnectors(t).find(o=>orbitCore.getWalletTypeFromConnectorName(orbitCore.OrbitAdapter.EVM,orbitCore.formatWalletName(o.name))===e);if(!s)throw new Error("Cannot find connector with this wallet type");try{await core.connect(t,{connector:s,chainId:r}),a&&!orbitCore.isSafeApp&&orbitCore.formatWalletName(s.name)!=="porto"&&orbitCore.formatWalletName(s.name)!=="geminiwallet"&&await a();let o=core.getConnection(t);return {walletType:e,address:o.address??viem.zeroAddress,chainId:o.chainId??chains.mainnet.id,rpcURL:o.chain?.rpcUrls.default.http[0]??chains.mainnet.rpcUrls.default.http[0],isConnected:o.isConnected,isContractAddress:!1,walletIcon:s?.icon?.trim(),connector:s}}catch(o){throw new Error(o instanceof Error?o.message:String(o))}},disconnect:async()=>{let e=core.getConnection(t);if(e.isConnected)await core.disconnect(t,{connector:e.connector});else {let r=core.getConnectors(t);await Promise.allSettled(r.map(async n=>{await core.disconnect(t,{connector:n});}));}},getConnectors:()=>{let e=core.getConnectors(t);return {adapter:orbitCore.OrbitAdapter.EVM,connectors:e.map(r=>r)}},checkAndSwitchNetwork:async e=>await orbitEvm.checkAndSwitchChain(Number(e),t),getBalance:async(e,r)=>{let n=await core.getBalance(t,{address:e,chainId:Number(r)});return {value:viem.formatUnits(n.value,n.decimals),symbol:n.symbol}},getExplorerUrl:e=>{let{chain:r}=core.getConnection(t),n=r?.blockExplorers?.default.url;return e?`${n}/${e}`:n},getName:e=>orbitEvm.getName(e),getAvatar:e=>orbitEvm.getAvatar(e),checkIsContractWallet:async({address:e,chainId:r})=>{let n=core.getChains(t);return await p({config:t,address:e,chainId:r,chains:n})},getSafeConnectorChainId:async()=>{let r=core.getConnectors(t).find(n=>n.name==="Safe");if(r)return await r.getChainId()}}}var q={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false};var H=t=>t.reduce((a,e)=>{let r=e.id;return a[r]=viem.http(),a},{});exports.checkIsWalletAddressContract=p;exports.createDefaultTransports=H;exports.safeSdkOptions=q;exports.satelliteEVMAdapter=L;//# 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/createDefaultTransports.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","e","activeWallet","disconnect","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","initialParameters","geminiParameters","portoParameters","injectedConnector","injected","baseConnector","baseAccount","gnosisSafeConnector","safe","geminiConnector","gemini","portoConnector","porto","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http"],"mappings":"kPAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,EACA,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,CAAM,CAAA,CAE7C,CAOV,IAAME,EAAa,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,MAEE,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,sBAAAA,CAAa,GAAA,CAOlB,OAAA,CAAS,MAAO,CAAE,UAAA,CAAAC,CAAAA,CAAY,QAAAR,CAAQ,CAAA,GAAM,CAE1C,IAAMS,CAAAA,CADaC,kBAAAA,CAAcZ,CAAM,CAAA,CACV,KAC1BW,CAAAA,EACCE,wCAAAA,CAA+BJ,sBAAAA,CAAa,GAAA,CAAKK,0BAAAA,CAAiBH,CAAAA,CAAU,IAAI,CAAC,CAAA,GAAMD,CAC3F,CAAA,CACA,GAAI,CAACC,CAAAA,CAAW,MAAM,IAAI,MAAM,6CAA6C,CAAA,CAE7E,GAAI,CAKF,MAAMI,YAAAA,CAAQf,CAAAA,CAAQ,CAAE,UAAAW,CAAAA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AAa,EAAE,CACjB,CAAA,CAGM0C,EACJb,CAAAA,CAAkB,MAAA,EAAUA,CAAAA,CAAkB,QAAA,EAAYA,CAAAA,CAAkB,OAAA,EAAWA,CAAAA,CAAkB,WAAA,CACrG,CACE,IAAA,CAAMA,CAAAA,CAAkB,OAAA,CACxB,WAAA,CAAaA,CAAAA,CAAkB,WAAA,CAC/B,GAAA,CAAKA,CAAAA,CAAkB,OACvB,KAAA,CAAOA,CAAAA,CAAkB,QAC3B,CAAA,CACA,MAAA,CAEN,GAAIA,CAAAA,CAAkB,SAAA,CAAW,CAC/B,IAAMc,CAAAA,CAAyBC,wBAAAA,CAAc,CAC3C,SAAA,CAAWf,CAAAA,CAAkB,SAAA,CAC7B,QAAA,CAAUa,CACZ,CAAC,CAAA,CAEDxD,CAAAA,CAAW,IAAA,CAAKyD,CAAsB,EACxC,CAEA,OAAOzD,CACT,ECpGO,IAAM2D,EAAAA,CAA2BhF,CAAAA,EAC/BA,EAAO,MAAA,CACZ,CAACiF,CAAAA,CAAKtD,CAAAA,GAAU,CACd,IAAMuD,CAAAA,CAAMvD,CAAAA,CAAM,GAClB,OAAAsD,CAAAA,CAAIC,CAAG,CAAA,CAAIC,SAAAA,EAAK,CACTF,CACT,CAAA,CACA,EACF","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 // const isConnected = await connector.isAuthorized();\n // if (isConnected) {\n // await disconnect(config, { connector });\n // }\n await connect(config, { connector, chainId: chainId as number });\n if (\n signInWithSiwe &&\n !isSafeApp &&\n formatWalletName(connector.name) !== 'porto' &&\n formatWalletName(connector.name) !== 'geminiwallet'\n ) {\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 activeWallet = getAccount(config);\n if (activeWallet.isConnected) {\n await disconnect(config, { connector: activeWallet.connector });\n } else {\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 /**\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 {\n baseAccount,\n gemini,\n GeminiParameters,\n injected,\n porto,\n PortoParameters,\n safe,\n walletConnect,\n} 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 * - Injected wallets (e.g., MetaMask, Phantom, Trust Wallet, etc.)\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 * @param geminiParameters - Optional parameters for Gemini wallet connector\n * @param portoParameters - Optional parameters for Porto wallet connector\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 = ({\n initialParameters,\n geminiParameters,\n portoParameters,\n}: {\n initialParameters: ConnectorsInitProps;\n geminiParameters?: GeminiParameters;\n portoParameters?: PortoParameters;\n}): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const baseConnector = baseAccount({\n appName: initialParameters.appName,\n appLogoUrl: initialParameters.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n const geminiConnector = gemini({\n appMetadata: {\n appName: initialParameters?.appName,\n ...geminiParameters?.appMetadata,\n },\n });\n const portoConnector = porto(portoParameters);\n\n const connectors = [\n injectedConnector,\n baseConnector,\n gnosisSafeConnector,\n geminiConnector,\n portoConnector,\n impersonated({}),\n ];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n initialParameters.appUrl && initialParameters.appIcons && initialParameters.appName && initialParameters.description\n ? {\n name: initialParameters.appName,\n description: initialParameters.description,\n url: initialParameters.appUrl,\n icons: initialParameters.appIcons,\n }\n : undefined;\n\n if (initialParameters.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: initialParameters.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - WalletConnect has unique types for connectors and connectorsOptions\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.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","connect","isSafeApp","account","getConnection","zeroAddress","mainnet","e","activeWallet","disconnect","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","safeSdkOptions","createDefaultTransports","acc","key","http"],"mappings":"8KAUA,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,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,IAAIG,CAAO,CAAA,CAMjC,GAFeG,yBAAAA,CAAiBF,CAAAA,CAAmBC,CAAM,CAAA,CA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A,CAAE,IAAA,GAAS,MAAM,CAAA,CAC9D,GAAID,CAAAA,CACF,OAAO,MAAMA,EAAc,UAAA,EAI/B,CACF,CACF,CC/KO,IAAME,CAAAA,CAAiB,CAE5B,cAAA,CAAgB,CAAC,iBAAA,CAAmB,kBAAA,CAAoB,iBAAiB,CAAA,CAEzE,MAAO,KACT,ECCO,IAAMC,CAAAA,CAA2BpC,CAAAA,EAC/BA,CAAAA,CAAO,MAAA,CACZ,CAACqC,CAAAA,CAAKV,CAAAA,GAAU,CACd,IAAMW,CAAAA,CAAMX,CAAAA,CAAM,EAAA,CAClB,OAAAU,CAAAA,CAAIC,CAAG,CAAA,CAAIC,SAAAA,EAAK,CACTF,CACT,CAAA,CACA,EACF","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, getConnection, 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 // const isConnected = await connector.isAuthorized();\n // if (isConnected) {\n // await disconnect(config, { connector });\n // }\n await connect(config, { connector, chainId: chainId as number });\n if (\n signInWithSiwe &&\n !isSafeApp &&\n formatWalletName(connector.name) !== 'porto' &&\n formatWalletName(connector.name) !== 'geminiwallet'\n ) {\n await signInWithSiwe();\n }\n const account = getConnection(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 activeWallet = getConnection(config);\n if (activeWallet.isConnected) {\n await disconnect(config, { connector: activeWallet.connector });\n } else {\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 /**\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 } = getConnection(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","/**\n * Configuration options for 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","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
|
|
1
|
+
import {OrbitAdapter,getWalletTypeFromConnectorName,formatWalletName,isSafeApp}from'@tuwaio/orbit-core';import {createViemClient,getAvatar,getName,checkAndSwitchChain}from'@tuwaio/orbit-evm';import {getBytecode,getConnectors,getChains,getConnection,getBalance,disconnect,connect}from'@wagmi/core';import {formatUnits,zeroAddress,http}from'viem';import {mainnet}from'viem/chains';var i=new Map;async function p({config:t,address:a,chainId:e,chains:r}){if(i.has(a))return i.get(a);if(createViemClient(e,r)){let o=!!await getBytecode(t,{address:a});return i.set(a,o),o}else return false}function L(t,a){if(!t)throw new Error("Satellite EVM adapter requires a wagmi config object.");return {key:OrbitAdapter.EVM,connect:async({walletType:e,chainId:r})=>{let s=getConnectors(t).find(o=>getWalletTypeFromConnectorName(OrbitAdapter.EVM,formatWalletName(o.name))===e);if(!s)throw new Error("Cannot find connector with this wallet type");try{await connect(t,{connector:s,chainId:r}),a&&!isSafeApp&&formatWalletName(s.name)!=="porto"&&formatWalletName(s.name)!=="geminiwallet"&&await a();let o=getConnection(t);return {walletType:e,address:o.address??zeroAddress,chainId:o.chainId??mainnet.id,rpcURL:o.chain?.rpcUrls.default.http[0]??mainnet.rpcUrls.default.http[0],isConnected:o.isConnected,isContractAddress:!1,walletIcon:s?.icon?.trim(),connector:s}}catch(o){throw new Error(o instanceof Error?o.message:String(o))}},disconnect:async()=>{let e=getConnection(t);if(e.isConnected)await disconnect(t,{connector:e.connector});else {let r=getConnectors(t);await Promise.allSettled(r.map(async n=>{await disconnect(t,{connector:n});}));}},getConnectors:()=>{let e=getConnectors(t);return {adapter:OrbitAdapter.EVM,connectors:e.map(r=>r)}},checkAndSwitchNetwork:async e=>await checkAndSwitchChain(Number(e),t),getBalance:async(e,r)=>{let n=await getBalance(t,{address:e,chainId:Number(r)});return {value:formatUnits(n.value,n.decimals),symbol:n.symbol}},getExplorerUrl:e=>{let{chain:r}=getConnection(t),n=r?.blockExplorers?.default.url;return e?`${n}/${e}`:n},getName:e=>getName(e),getAvatar:e=>getAvatar(e),checkIsContractWallet:async({address:e,chainId:r})=>{let n=getChains(t);return await p({config:t,address:e,chainId:r,chains:n})},getSafeConnectorChainId:async()=>{let r=getConnectors(t).find(n=>n.name==="Safe");if(r)return await r.getChainId()}}}var q={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false};var H=t=>t.reduce((a,e)=>{let r=e.id;return a[r]=http(),a},{});export{p as checkIsWalletAddressContract,H as createDefaultTransports,q as safeSdkOptions,L 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/createDefaultTransports.ts"],"names":["walletsCache","checkIsWalletAddressContract","config","address","chainId","chains","createViemClient","isContract","getBytecode","satelliteEVMAdapter","signInWithSiwe","OrbitAdapter","walletType","connector","getConnectors","getWalletTypeFromConnectorName","formatWalletName","connect","isSafeApp","account","getAccount","zeroAddress","mainnet","e","activeWallet","disconnect","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","initialParameters","geminiParameters","portoParameters","injectedConnector","injected","baseConnector","baseAccount","gnosisSafeConnector","safe","geminiConnector","gemini","portoConnector","porto","wcMetadata","walletConnectConnector","walletConnect","createDefaultTransports","acc","key","http"],"mappings":"soBAUA,IAAMA,CAAAA,CAAe,IAAI,GAAA,CA8BzB,eAAsBC,CAAAA,CAA6B,CACjD,MAAA,CAAAC,EACA,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,CAAA,CAE7C,CAOV,IAAME,EAAa,CAAC,CALQ,MAAMC,WAAAA,CAAYN,CAAAA,CAAQ,CACpD,OAAA,CAASC,CACX,CAAC,CAAA,CAID,OAAAH,CAAAA,CAAa,GAAA,CAAIG,CAAAA,CAASI,CAAU,CAAA,CAE7BA,CACT,MAEE,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,QAAAR,CAAQ,CAAA,GAAM,CAE1C,IAAMS,CAAAA,CADaC,aAAAA,CAAcZ,CAAM,CAAA,CACV,KAC1BW,CAAAA,EACCE,8BAAAA,CAA+BJ,YAAAA,CAAa,GAAA,CAAKK,gBAAAA,CAAiBH,CAAAA,CAAU,IAAI,CAAC,CAAA,GAAMD,CAC3F,CAAA,CACA,GAAI,CAACC,CAAAA,CAAW,MAAM,IAAI,MAAM,6CAA6C,CAAA,CAE7E,GAAI,CAKF,MAAMI,OAAAA,CAAQf,CA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CAAAA,CAAa,EAAE,CACjB,CAAA,CAGM0C,EACJb,CAAAA,CAAkB,MAAA,EAAUA,CAAAA,CAAkB,QAAA,EAAYA,CAAAA,CAAkB,OAAA,EAAWA,CAAAA,CAAkB,WAAA,CACrG,CACE,IAAA,CAAMA,CAAAA,CAAkB,OAAA,CACxB,WAAA,CAAaA,CAAAA,CAAkB,WAAA,CAC/B,GAAA,CAAKA,CAAAA,CAAkB,OACvB,KAAA,CAAOA,CAAAA,CAAkB,QAC3B,CAAA,CACA,MAAA,CAEN,GAAIA,CAAAA,CAAkB,SAAA,CAAW,CAC/B,IAAMc,CAAAA,CAAyBC,aAAAA,CAAc,CAC3C,SAAA,CAAWf,CAAAA,CAAkB,SAAA,CAC7B,QAAA,CAAUa,CACZ,CAAC,CAAA,CAEDxD,CAAAA,CAAW,IAAA,CAAKyD,CAAsB,EACxC,CAEA,OAAOzD,CACT,ECpGO,IAAM2D,EAAAA,CAA2BhF,CAAAA,EAC/BA,EAAO,MAAA,CACZ,CAACiF,CAAAA,CAAKtD,CAAAA,GAAU,CACd,IAAMuD,CAAAA,CAAMvD,CAAAA,CAAM,GAClB,OAAAsD,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 // const isConnected = await connector.isAuthorized();\n // if (isConnected) {\n // await disconnect(config, { connector });\n // }\n await connect(config, { connector, chainId: chainId as number });\n if (\n signInWithSiwe &&\n !isSafeApp &&\n formatWalletName(connector.name) !== 'porto' &&\n formatWalletName(connector.name) !== 'geminiwallet'\n ) {\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 activeWallet = getAccount(config);\n if (activeWallet.isConnected) {\n await disconnect(config, { connector: activeWallet.connector });\n } else {\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 /**\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 {\n baseAccount,\n gemini,\n GeminiParameters,\n injected,\n porto,\n PortoParameters,\n safe,\n walletConnect,\n} 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 * - Injected wallets (e.g., MetaMask, Phantom, Trust Wallet, etc.)\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 * @param geminiParameters - Optional parameters for Gemini wallet connector\n * @param portoParameters - Optional parameters for Porto wallet connector\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 = ({\n initialParameters,\n geminiParameters,\n portoParameters,\n}: {\n initialParameters: ConnectorsInitProps;\n geminiParameters?: GeminiParameters;\n portoParameters?: PortoParameters;\n}): readonly CreateConnectorFn[] => {\n const injectedConnector = injected();\n const baseConnector = baseAccount({\n appName: initialParameters.appName,\n appLogoUrl: initialParameters.appLogoUrl,\n });\n const gnosisSafeConnector = safe({\n ...safeSdkOptions,\n });\n const geminiConnector = gemini({\n appMetadata: {\n appName: initialParameters?.appName,\n ...geminiParameters?.appMetadata,\n },\n });\n const portoConnector = porto(portoParameters);\n\n const connectors = [\n injectedConnector,\n baseConnector,\n gnosisSafeConnector,\n geminiConnector,\n portoConnector,\n impersonated({}),\n ];\n\n // WalletConnect metadata configuration\n const wcMetadata =\n initialParameters.appUrl && initialParameters.appIcons && initialParameters.appName && initialParameters.description\n ? {\n name: initialParameters.appName,\n description: initialParameters.description,\n url: initialParameters.appUrl,\n icons: initialParameters.appIcons,\n }\n : undefined;\n\n if (initialParameters.projectId) {\n const walletConnectConnector = walletConnect({\n projectId: initialParameters.projectId,\n metadata: wcMetadata,\n });\n // @ts-expect-error - WalletConnect has unique types for connectors and connectorsOptions\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/checkIsWalletAddressContract.ts","../src/adapters/evmAdapter.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","connect","isSafeApp","account","getConnection","zeroAddress","mainnet","e","activeWallet","disconnect","connectors","checkAndSwitchChain","balance","getBalance","formatUnits","url","chain","baseExplorerLink","getName","name","getAvatar","getChains","safeConnector","c","safeSdkOptions","createDefaultTransports","acc","key","http"],"mappings":"2XAUA,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,CAAAA,CAAa,GAAA,CAAIG,CAAO,CAAA,CAC1B,OAAOH,CAAAA,CAAa,IAAIG,CAAO,CAAA,CAMjC,GAFeG,gBAAAA,CAAiBF,CAAAA,CAAmBC,CAAM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AA,GAAS,MAAM,CAAA,CAC9D,GAAID,CAAAA,CACF,OAAO,MAAMA,EAAc,UAAA,EAI/B,CACF,CACF,CC/KO,IAAME,CAAAA,CAAiB,CAE5B,cAAA,CAAgB,CAAC,iBAAA,CAAmB,kBAAA,CAAoB,iBAAiB,CAAA,CAEzE,MAAO,KACT,ECCO,IAAMC,CAAAA,CAA2BpC,CAAAA,EAC/BA,CAAAA,CAAO,MAAA,CACZ,CAACqC,CAAAA,CAAKV,CAAAA,GAAU,CACd,IAAMW,CAAAA,CAAMX,CAAAA,CAAM,EAAA,CAClB,OAAAU,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, getConnection, 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 // const isConnected = await connector.isAuthorized();\n // if (isConnected) {\n // await disconnect(config, { connector });\n // }\n await connect(config, { connector, chainId: chainId as number });\n if (\n signInWithSiwe &&\n !isSafeApp &&\n formatWalletName(connector.name) !== 'porto' &&\n formatWalletName(connector.name) !== 'geminiwallet'\n ) {\n await signInWithSiwe();\n }\n const account = getConnection(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 activeWallet = getConnection(config);\n if (activeWallet.isConnected) {\n await disconnect(config, { connector: activeWallet.connector });\n } else {\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 /**\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 } = getConnection(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","/**\n * Configuration options for 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","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-
|
|
3
|
+
"version": "1.0.0-fix-packages-alpha.1.bd0ce80",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,32 +38,27 @@
|
|
|
38
38
|
"url": "https://github.com/Argeare5"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@react-native-async-storage/async-storage": "^2.2.0"
|
|
43
|
-
},
|
|
44
41
|
"peerDependencies": {
|
|
45
|
-
"@wagmi/core": "
|
|
46
|
-
"immer": "
|
|
42
|
+
"@wagmi/core": "3.x.x",
|
|
43
|
+
"immer": "11.x.x",
|
|
47
44
|
"zustand": "5.x.x",
|
|
48
45
|
"viem": "2.x.x",
|
|
49
|
-
"@wagmi/connectors": "6.x.x",
|
|
50
46
|
"@tuwaio/orbit-core": ">=0.1",
|
|
51
47
|
"@tuwaio/orbit-evm": ">=0.1",
|
|
52
48
|
"@tuwaio/satellite-core": ">=0.1"
|
|
53
49
|
},
|
|
54
50
|
"devDependencies": {
|
|
55
|
-
"@wagmi/core": "^
|
|
56
|
-
"@
|
|
57
|
-
"@tuwaio/orbit-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"tsup": "^8.5.0",
|
|
51
|
+
"@wagmi/core": "^3.0.0",
|
|
52
|
+
"@tuwaio/orbit-core": "1.0.0-fix-packages-alpha.2.a02ae73",
|
|
53
|
+
"@tuwaio/orbit-evm": "1.0.0-fix-packages-alpha.2.a02ae73",
|
|
54
|
+
"immer": "^11.0.0",
|
|
55
|
+
"jsdom": "^27.2.0",
|
|
56
|
+
"tsup": "^8.5.1",
|
|
62
57
|
"typescript": "^5.9.3",
|
|
63
|
-
"viem": "^2.
|
|
64
|
-
"vitest": "^4.0.
|
|
58
|
+
"viem": "^2.40.2",
|
|
59
|
+
"vitest": "^4.0.13",
|
|
65
60
|
"zustand": "^5.0.8",
|
|
66
|
-
"@tuwaio/satellite-core": "^1.0.0-fix-
|
|
61
|
+
"@tuwaio/satellite-core": "^1.0.0-fix-packages-alpha.1.bd0ce80"
|
|
67
62
|
},
|
|
68
63
|
"scripts": {
|
|
69
64
|
"start": "tsup src/index.ts --watch",
|