@tuwaio/orbit-core 1.0.0-fix-packages-alpha.1.bb47310 → 1.0.0-fix-packages-alpha.3.dc7f910
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 +31 -31
- package/dist/index.d.mts +52 -51
- package/dist/index.d.ts +52 -51
- 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 +1 -1
package/README.md
CHANGED
|
@@ -18,17 +18,17 @@ Its primary goal is to establish a **unified interface** for interacting with di
|
|
|
18
18
|
|
|
19
19
|
## ✨ Key Features
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
21
|
+
- **Multi-Chain Foundation:** Defines the core `OrbitAdapter` enum (supporting EVM, Solana, Starknet) and types for building consistent multi-chain support.
|
|
22
|
+
- **Framework Agnostic & Headless:** Contains only logic, no UI components, ensuring compatibility with any frontend setup.
|
|
23
|
+
- **Type-Safe Development:** Fully written in TypeScript 5.9+ for a robust developer experience.
|
|
24
|
+
- **Flexible Adapter System:** Provides utilities like `selectAdapterByKey` to easily manage and switch between different blockchain adapter implementations.
|
|
25
|
+
- **Essential Utilities:** Includes common helpers for tasks such as:
|
|
26
|
+
- Formatting connector names and chain IDs (`formatConnectorName`, `formatConnectorChainId`).
|
|
27
|
+
- Identifying chain types (`isSolanaChain`, `getAdapterFromConnectorType`).
|
|
28
|
+
- Managing connector connection state in localStorage (`lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`).
|
|
29
|
+
- Handling impersonation for development/testing (`impersonatedHelpers`).
|
|
30
|
+
- Basic async operations (`delay`, `waitFor`).
|
|
31
|
+
- **SSR Safe:** Utilities are designed to work safely in both browser and Server-Side Rendering environments.
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
@@ -117,33 +117,33 @@ if (selectedSolanaAdapter && selectedSolanaAdapter.key === OrbitAdapter.SOLANA)
|
|
|
117
117
|
```typescript
|
|
118
118
|
import {
|
|
119
119
|
OrbitAdapter,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
formatConnectorName,
|
|
121
|
+
getAdapterFromConnectorType,
|
|
122
|
+
getConnectorTypeFromName,
|
|
123
123
|
isSolanaChain,
|
|
124
|
-
|
|
124
|
+
lastConnectedConnectorHelpers
|
|
125
125
|
} from '@tuwaio/orbit-core';
|
|
126
126
|
|
|
127
127
|
// Formatting
|
|
128
|
-
const formattedName =
|
|
128
|
+
const formattedName = formatConnectorName('MetaMask'); // "metamask"
|
|
129
129
|
console.log(formattedName);
|
|
130
|
-
const
|
|
131
|
-
console.log(
|
|
130
|
+
const connectorType = getConnectorTypeFromName(OrbitAdapter.EVM, 'Brave Wallet'); // "evm:bravewallet"
|
|
131
|
+
console.log(connectorType);
|
|
132
132
|
|
|
133
133
|
// Identification
|
|
134
|
-
const adapterType =
|
|
134
|
+
const adapterType = getAdapterFromConnectorType(connectorType); // OrbitAdapter.EVM
|
|
135
135
|
console.log(adapterType);
|
|
136
136
|
console.log(isSolanaChain('devnet')); // true
|
|
137
137
|
console.log(isSolanaChain(1)); // false
|
|
138
138
|
|
|
139
|
-
// Local Storage Management for Last Connected
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
// Local Storage Management for Last Connected Connector
|
|
140
|
+
lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
141
|
+
connectorType: 'evm:metamask',
|
|
142
142
|
chainId: 1,
|
|
143
143
|
address: '0x123...'
|
|
144
144
|
});
|
|
145
|
-
const lastWallet =
|
|
146
|
-
console.log(lastWallet); // {
|
|
145
|
+
const lastWallet = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
146
|
+
console.log(lastWallet); // { connectorType: 'evm:metamask', chainId: 1, address: '0x123...' }
|
|
147
147
|
|
|
148
148
|
// lastConnectedWalletHelpers.removeLastConnectedWallet();
|
|
149
149
|
```
|
|
@@ -154,17 +154,17 @@ console.log(lastWallet); // { walletType: 'evm:metamask', chainId: 1, address: '
|
|
|
154
154
|
|
|
155
155
|
Orbit Core is designed around modularity and abstraction:
|
|
156
156
|
|
|
157
|
-
1.
|
|
158
|
-
2.
|
|
159
|
-
3.
|
|
157
|
+
1. **Core Types (`types.ts`):** Defines fundamental structures like `OrbitAdapter` (enum for EVM, Solana, Starknet), `BaseAdapter` (common interface), and `ConnectorType`.
|
|
158
|
+
2. **Adapter System:** Enables handling multiple blockchain types via a common interface. The `selectAdapterByKey` utility allows runtime selection of the correct adapter implementation based on the `OrbitAdapter` key. Chain-specific logic resides in separate packages (e.g., `@tuwaio/orbit-evm`).
|
|
159
|
+
3. **Utilities (`utils/`):** A collection of framework-agnostic helper functions covering formatting, chain identification, localStorage management (for connection state persistence), async operations, and other common tasks needed when building multi-chain UIs.
|
|
160
160
|
|
|
161
161
|
### Key Exports (`index.ts`)
|
|
162
162
|
|
|
163
|
-
- **Types:** `OrbitAdapter`, `BaseAdapter`, `
|
|
164
|
-
- **Adapter Utilities:** `selectAdapterByKey`, `
|
|
165
|
-
- **Formatting Utilities:** `
|
|
163
|
+
- **Types:** `OrbitAdapter`, `BaseAdapter`, `ConnectorType`, `OrbitGenericAdapter`, `RecentConnectedConnector`.
|
|
164
|
+
- **Adapter Utilities:** `selectAdapterByKey`, `getAdapterFromConnectorType`.
|
|
165
|
+
- **Formatting Utilities:** `formatConnectorChainId`, `formatConnectorName`, `getConnectorTypeFromName`.
|
|
166
166
|
- **Chain Helpers:** `isSolanaChain`, `setChainId`.
|
|
167
|
-
- **Storage Helpers:** `
|
|
167
|
+
- **Storage Helpers:** `lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`, `impersonatedHelpers`, `getParsedStorageItem`.
|
|
168
168
|
- **General Utilities:** `delay`, `filterUniqueByKey`, `waitFor`, `isSafeApp`.
|
|
169
169
|
|
|
170
170
|
-----
|
package/dist/index.d.mts
CHANGED
|
@@ -102,10 +102,10 @@ type BaseAdapter = {
|
|
|
102
102
|
getAvatar?: (name: string) => Promise<string | null>;
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
|
-
* Type representing a
|
|
105
|
+
* Type representing a connector identifier in format "OrbitAdapter:connector"
|
|
106
106
|
* @example "evm:metamask" | "solana:phantom"
|
|
107
107
|
*/
|
|
108
|
-
type
|
|
108
|
+
type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* @name delay
|
|
@@ -152,69 +152,70 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
152
152
|
*/
|
|
153
153
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
154
154
|
|
|
155
|
-
declare function
|
|
155
|
+
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
156
156
|
|
|
157
|
-
declare const
|
|
157
|
+
declare const formatConnectorName: (connectorName: string) => string;
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
* Extracts the adapter type from a
|
|
160
|
+
* Extracts the adapter type from a connector type string
|
|
161
161
|
*
|
|
162
162
|
* @example
|
|
163
163
|
* ```typescript
|
|
164
164
|
* // Returns OrbitAdapter.EVM
|
|
165
|
-
*
|
|
165
|
+
* getAdapterFromConnectorType('evm:metamask');
|
|
166
166
|
*
|
|
167
167
|
* // Returns OrbitAdapter.SOLANA
|
|
168
|
-
*
|
|
168
|
+
* getAdapterFromConnectorType('solana:phantom');
|
|
169
169
|
*
|
|
170
170
|
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
-
*
|
|
171
|
+
* getAdapterFromConnectorType('unknown');
|
|
172
172
|
* ```
|
|
173
173
|
*
|
|
174
|
-
* @param
|
|
174
|
+
* @param connectorType - Connector type in format "orbit-adapter:connector" (e.g. "evm:metamask", "solana:phantom")
|
|
175
175
|
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
176
|
*
|
|
177
177
|
* @remarks
|
|
178
|
-
* The function splits the
|
|
178
|
+
* The function splits the connector type string by ":" and takes the first part as the adapter type.
|
|
179
179
|
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
180
|
*/
|
|
181
|
-
declare function
|
|
181
|
+
declare function getAdapterFromConnectorType(connectorType: ConnectorType): OrbitAdapter;
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @param key - The key for localStorage
|
|
187
|
-
* @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid
|
|
188
|
-
*/
|
|
189
|
-
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
184
|
+
* Generates a standardized connector type identifier from adapter type and connector name
|
|
193
185
|
*
|
|
194
186
|
* @example
|
|
195
187
|
* ```typescript
|
|
196
188
|
* // Returns "evm:metamask"
|
|
197
|
-
*
|
|
189
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "MetaMask");
|
|
198
190
|
*
|
|
199
191
|
* // Returns "solana:phantom"
|
|
200
|
-
*
|
|
192
|
+
* getConnectorTypeFromName(OrbitAdapter.SOLANA, "Phantom");
|
|
201
193
|
*
|
|
202
194
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
203
|
-
*
|
|
195
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
204
196
|
* ```
|
|
205
197
|
*
|
|
206
198
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
207
|
-
* @param name - The
|
|
208
|
-
* @returns A formatted
|
|
199
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
200
|
+
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
209
201
|
*
|
|
210
202
|
* @remarks
|
|
211
203
|
* The function:
|
|
212
204
|
* 1. Combines adapter type with connector name using ":" as separator
|
|
213
205
|
* 2. Removes all whitespace from connector name
|
|
214
206
|
* 3. Converts connector name to lowercase
|
|
215
|
-
* This ensures consistent
|
|
207
|
+
* This ensures consistent connector type identifiers across the application
|
|
208
|
+
* and normalizes connector names for better UX/consistency.
|
|
216
209
|
*/
|
|
217
|
-
declare function
|
|
210
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
214
|
+
*
|
|
215
|
+
* @param key - The key for localStorage
|
|
216
|
+
* @returns The parsed LastConnectedConnector object or undefined if data is not found/invalid
|
|
217
|
+
*/
|
|
218
|
+
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
218
219
|
|
|
219
220
|
/**
|
|
220
221
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -263,8 +264,8 @@ declare const impersonatedHelpers: {
|
|
|
263
264
|
|
|
264
265
|
declare const isSafeApp: boolean;
|
|
265
266
|
|
|
266
|
-
type
|
|
267
|
-
|
|
267
|
+
type LastConnectedConnector = {
|
|
268
|
+
connectorType: ConnectorType;
|
|
268
269
|
chainId: number | string;
|
|
269
270
|
address?: string;
|
|
270
271
|
};
|
|
@@ -272,71 +273,71 @@ type LastConnectedWallet = {
|
|
|
272
273
|
* Helper utilities for managing the last connected wallet state
|
|
273
274
|
*
|
|
274
275
|
* @remarks
|
|
275
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
276
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.
|
|
276
277
|
* Functions are safe to use in both browser and SSR environments.
|
|
277
278
|
*/
|
|
278
|
-
declare const
|
|
279
|
+
declare const lastConnectedConnectorHelpers: {
|
|
279
280
|
STORAGE_KEY: string;
|
|
280
281
|
/**
|
|
281
282
|
* The value of the last connected wallet, initialized when the module loads.
|
|
282
283
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
284
|
*/
|
|
284
|
-
|
|
285
|
+
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
285
286
|
/**
|
|
286
287
|
* Stores the last connected wallet data in localStorage.
|
|
287
288
|
*
|
|
288
289
|
* @param data - Object containing the wallet type and chain ID.
|
|
289
290
|
* @returns undefined in SSR context, void in browser
|
|
290
291
|
*/
|
|
291
|
-
|
|
292
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
292
293
|
/**
|
|
293
294
|
* Retrieves the current last connected wallet data from localStorage.
|
|
294
295
|
*
|
|
295
|
-
* @returns The
|
|
296
|
+
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
296
297
|
*/
|
|
297
|
-
|
|
298
|
+
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
298
299
|
/**
|
|
299
300
|
* Removes the last connected wallet data from localStorage.
|
|
300
301
|
*
|
|
301
302
|
* @returns undefined in SSR context, void in browser
|
|
302
303
|
*/
|
|
303
|
-
|
|
304
|
+
removeLastConnectedConnector: () => void;
|
|
304
305
|
};
|
|
305
306
|
|
|
306
|
-
type
|
|
307
|
+
type RecentConnectedConnector = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
308
|
/**
|
|
308
|
-
* Helper utilities for managing the last connected
|
|
309
|
+
* Helper utilities for managing the last connected connector state
|
|
309
310
|
*
|
|
310
311
|
* @remarks
|
|
311
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
312
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.
|
|
312
313
|
* Functions are safe to use in both browser and SSR environments.
|
|
313
314
|
*/
|
|
314
|
-
declare const
|
|
315
|
+
declare const recentConnectedConnectorHelpers: {
|
|
315
316
|
STORAGE_KEY: string;
|
|
316
317
|
/**
|
|
317
|
-
* The value of the last connected
|
|
318
|
+
* The value of the last connected connector, initialized when the module loads.
|
|
318
319
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
320
|
*/
|
|
320
|
-
|
|
321
|
+
recentConnectedConnector: RecentConnectedConnector | undefined;
|
|
321
322
|
/**
|
|
322
|
-
* Stores the last connected
|
|
323
|
+
* Stores the last connected connector data in localStorage.
|
|
323
324
|
*
|
|
324
|
-
* @param
|
|
325
|
+
* @param connectors - RecentConnectedConnector
|
|
325
326
|
* @returns undefined in SSR context, void in browser
|
|
326
327
|
*/
|
|
327
|
-
|
|
328
|
+
setRecentConnectedConnector: (connectors: RecentConnectedConnector) => void;
|
|
328
329
|
/**
|
|
329
|
-
* Retrieves the current last connected
|
|
330
|
+
* Retrieves the current last connected connector data from localStorage.
|
|
330
331
|
*
|
|
331
|
-
* @returns The
|
|
332
|
+
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
332
333
|
*/
|
|
333
|
-
|
|
334
|
+
getRecentConnectedConnector: () => RecentConnectedConnector | undefined;
|
|
334
335
|
/**
|
|
335
|
-
* Removes the last connected
|
|
336
|
+
* Removes the last connected connector data from localStorage.
|
|
336
337
|
*
|
|
337
338
|
* @returns undefined in SSR context, void in browser
|
|
338
339
|
*/
|
|
339
|
-
|
|
340
|
+
removeRecentConnectedConnector: () => void;
|
|
340
341
|
};
|
|
341
342
|
|
|
342
343
|
/**
|
|
@@ -406,4 +407,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
406
407
|
*/
|
|
407
408
|
declare function setChainId(chainId: number | string): string | number;
|
|
408
409
|
|
|
409
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type
|
|
410
|
+
export { type BaseAdapter, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedConnector, delay, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getParsedStorageItem, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, recentConnectedConnectorHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,10 +102,10 @@ type BaseAdapter = {
|
|
|
102
102
|
getAvatar?: (name: string) => Promise<string | null>;
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
|
-
* Type representing a
|
|
105
|
+
* Type representing a connector identifier in format "OrbitAdapter:connector"
|
|
106
106
|
* @example "evm:metamask" | "solana:phantom"
|
|
107
107
|
*/
|
|
108
|
-
type
|
|
108
|
+
type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* @name delay
|
|
@@ -152,69 +152,70 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
152
152
|
*/
|
|
153
153
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
154
154
|
|
|
155
|
-
declare function
|
|
155
|
+
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
156
156
|
|
|
157
|
-
declare const
|
|
157
|
+
declare const formatConnectorName: (connectorName: string) => string;
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
* Extracts the adapter type from a
|
|
160
|
+
* Extracts the adapter type from a connector type string
|
|
161
161
|
*
|
|
162
162
|
* @example
|
|
163
163
|
* ```typescript
|
|
164
164
|
* // Returns OrbitAdapter.EVM
|
|
165
|
-
*
|
|
165
|
+
* getAdapterFromConnectorType('evm:metamask');
|
|
166
166
|
*
|
|
167
167
|
* // Returns OrbitAdapter.SOLANA
|
|
168
|
-
*
|
|
168
|
+
* getAdapterFromConnectorType('solana:phantom');
|
|
169
169
|
*
|
|
170
170
|
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
-
*
|
|
171
|
+
* getAdapterFromConnectorType('unknown');
|
|
172
172
|
* ```
|
|
173
173
|
*
|
|
174
|
-
* @param
|
|
174
|
+
* @param connectorType - Connector type in format "orbit-adapter:connector" (e.g. "evm:metamask", "solana:phantom")
|
|
175
175
|
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
176
|
*
|
|
177
177
|
* @remarks
|
|
178
|
-
* The function splits the
|
|
178
|
+
* The function splits the connector type string by ":" and takes the first part as the adapter type.
|
|
179
179
|
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
180
|
*/
|
|
181
|
-
declare function
|
|
181
|
+
declare function getAdapterFromConnectorType(connectorType: ConnectorType): OrbitAdapter;
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @param key - The key for localStorage
|
|
187
|
-
* @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid
|
|
188
|
-
*/
|
|
189
|
-
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
184
|
+
* Generates a standardized connector type identifier from adapter type and connector name
|
|
193
185
|
*
|
|
194
186
|
* @example
|
|
195
187
|
* ```typescript
|
|
196
188
|
* // Returns "evm:metamask"
|
|
197
|
-
*
|
|
189
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "MetaMask");
|
|
198
190
|
*
|
|
199
191
|
* // Returns "solana:phantom"
|
|
200
|
-
*
|
|
192
|
+
* getConnectorTypeFromName(OrbitAdapter.SOLANA, "Phantom");
|
|
201
193
|
*
|
|
202
194
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
203
|
-
*
|
|
195
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
204
196
|
* ```
|
|
205
197
|
*
|
|
206
198
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
207
|
-
* @param name - The
|
|
208
|
-
* @returns A formatted
|
|
199
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
200
|
+
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
209
201
|
*
|
|
210
202
|
* @remarks
|
|
211
203
|
* The function:
|
|
212
204
|
* 1. Combines adapter type with connector name using ":" as separator
|
|
213
205
|
* 2. Removes all whitespace from connector name
|
|
214
206
|
* 3. Converts connector name to lowercase
|
|
215
|
-
* This ensures consistent
|
|
207
|
+
* This ensures consistent connector type identifiers across the application
|
|
208
|
+
* and normalizes connector names for better UX/consistency.
|
|
216
209
|
*/
|
|
217
|
-
declare function
|
|
210
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
214
|
+
*
|
|
215
|
+
* @param key - The key for localStorage
|
|
216
|
+
* @returns The parsed LastConnectedConnector object or undefined if data is not found/invalid
|
|
217
|
+
*/
|
|
218
|
+
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
218
219
|
|
|
219
220
|
/**
|
|
220
221
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -263,8 +264,8 @@ declare const impersonatedHelpers: {
|
|
|
263
264
|
|
|
264
265
|
declare const isSafeApp: boolean;
|
|
265
266
|
|
|
266
|
-
type
|
|
267
|
-
|
|
267
|
+
type LastConnectedConnector = {
|
|
268
|
+
connectorType: ConnectorType;
|
|
268
269
|
chainId: number | string;
|
|
269
270
|
address?: string;
|
|
270
271
|
};
|
|
@@ -272,71 +273,71 @@ type LastConnectedWallet = {
|
|
|
272
273
|
* Helper utilities for managing the last connected wallet state
|
|
273
274
|
*
|
|
274
275
|
* @remarks
|
|
275
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
276
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.
|
|
276
277
|
* Functions are safe to use in both browser and SSR environments.
|
|
277
278
|
*/
|
|
278
|
-
declare const
|
|
279
|
+
declare const lastConnectedConnectorHelpers: {
|
|
279
280
|
STORAGE_KEY: string;
|
|
280
281
|
/**
|
|
281
282
|
* The value of the last connected wallet, initialized when the module loads.
|
|
282
283
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
284
|
*/
|
|
284
|
-
|
|
285
|
+
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
285
286
|
/**
|
|
286
287
|
* Stores the last connected wallet data in localStorage.
|
|
287
288
|
*
|
|
288
289
|
* @param data - Object containing the wallet type and chain ID.
|
|
289
290
|
* @returns undefined in SSR context, void in browser
|
|
290
291
|
*/
|
|
291
|
-
|
|
292
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
292
293
|
/**
|
|
293
294
|
* Retrieves the current last connected wallet data from localStorage.
|
|
294
295
|
*
|
|
295
|
-
* @returns The
|
|
296
|
+
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
296
297
|
*/
|
|
297
|
-
|
|
298
|
+
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
298
299
|
/**
|
|
299
300
|
* Removes the last connected wallet data from localStorage.
|
|
300
301
|
*
|
|
301
302
|
* @returns undefined in SSR context, void in browser
|
|
302
303
|
*/
|
|
303
|
-
|
|
304
|
+
removeLastConnectedConnector: () => void;
|
|
304
305
|
};
|
|
305
306
|
|
|
306
|
-
type
|
|
307
|
+
type RecentConnectedConnector = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
308
|
/**
|
|
308
|
-
* Helper utilities for managing the last connected
|
|
309
|
+
* Helper utilities for managing the last connected connector state
|
|
309
310
|
*
|
|
310
311
|
* @remarks
|
|
311
|
-
* All data is stored in localStorage with the 'orbit-core:
|
|
312
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.
|
|
312
313
|
* Functions are safe to use in both browser and SSR environments.
|
|
313
314
|
*/
|
|
314
|
-
declare const
|
|
315
|
+
declare const recentConnectedConnectorHelpers: {
|
|
315
316
|
STORAGE_KEY: string;
|
|
316
317
|
/**
|
|
317
|
-
* The value of the last connected
|
|
318
|
+
* The value of the last connected connector, initialized when the module loads.
|
|
318
319
|
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
320
|
*/
|
|
320
|
-
|
|
321
|
+
recentConnectedConnector: RecentConnectedConnector | undefined;
|
|
321
322
|
/**
|
|
322
|
-
* Stores the last connected
|
|
323
|
+
* Stores the last connected connector data in localStorage.
|
|
323
324
|
*
|
|
324
|
-
* @param
|
|
325
|
+
* @param connectors - RecentConnectedConnector
|
|
325
326
|
* @returns undefined in SSR context, void in browser
|
|
326
327
|
*/
|
|
327
|
-
|
|
328
|
+
setRecentConnectedConnector: (connectors: RecentConnectedConnector) => void;
|
|
328
329
|
/**
|
|
329
|
-
* Retrieves the current last connected
|
|
330
|
+
* Retrieves the current last connected connector data from localStorage.
|
|
330
331
|
*
|
|
331
|
-
* @returns The
|
|
332
|
+
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
332
333
|
*/
|
|
333
|
-
|
|
334
|
+
getRecentConnectedConnector: () => RecentConnectedConnector | undefined;
|
|
334
335
|
/**
|
|
335
|
-
* Removes the last connected
|
|
336
|
+
* Removes the last connected connector data from localStorage.
|
|
336
337
|
*
|
|
337
338
|
* @returns undefined in SSR context, void in browser
|
|
338
339
|
*/
|
|
339
|
-
|
|
340
|
+
removeRecentConnectedConnector: () => void;
|
|
340
341
|
};
|
|
341
342
|
|
|
342
343
|
/**
|
|
@@ -406,4 +407,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
406
407
|
*/
|
|
407
408
|
declare function setChainId(chainId: number | string): string | number;
|
|
408
409
|
|
|
409
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type
|
|
410
|
+
export { type BaseAdapter, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedConnector, delay, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getParsedStorageItem, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, recentConnectedConnectorHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var a=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(a||{});var l=(e,t)=>new Promise(n=>{let r=()=>{setTimeout(()=>n(e),t);};typeof window<"u"?r():setTimeout(r,0);});function u(e,t){let n=new Set;return e.filter(r=>{let i=r[t];return n.has(i)?false:(n.add(i),true)})}function C(e,t){return typeof e=="string"?`${t}:${e}`:e}var c=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safewallet"],["Trust","trustwallet"],["Trust Wallet","trustwallet"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","bravewallet"],["Brave Wallet","bravewallet"],["Base Account","coinbasewallet"]]),y=e=>c.get(e)??e.replace(/\s+/g,"").toLowerCase();function T(e){return e?.split(":")[0]??"evm"}function O(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}function o(e){if(typeof window>"u")return;let t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(n){console.error(`Error parsing ${e} from localStorage:`,n);return}}var I={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:e=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",e):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};var G=typeof window<"u"&&window!==window.parent;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:o("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:t,address:n})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:t,address:n})):void 0,getLastConnectedConnector:()=>o(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var s={STORAGE_KEY:"orbit-core:recentConnectedConnector",recentConnectedConnector:o("orbit-core:recentConnectedConnectors"),setRecentConnectedConnector:e=>typeof window<"u"?window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentConnectedConnector:()=>o(s.STORAGE_KEY),removeRecentConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(s.STORAGE_KEY):void 0};var $=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};async function Y(e,t=50,n=200){for(let r=0;r<t;r++){if(e())return;await new Promise(i=>setTimeout(i,n));}throw new Error("Predicate not fulfilled in time")}function p(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function B(e){return p(e)?`solana:${e}`:e}exports.OrbitAdapter=a;exports.delay=l;exports.filterUniqueByKey=u;exports.formatConnectorChainId=C;exports.formatConnectorName=y;exports.getAdapterFromConnectorType=T;exports.getConnectorTypeFromName=O;exports.getParsedStorageItem=o;exports.impersonatedHelpers=I;exports.isSafeApp=G;exports.isSolanaChain=p;exports.lastConnectedConnectorHelpers=d;exports.recentConnectedConnectorHelpers=s;exports.selectAdapterByKey=$;exports.setChainId=B;exports.waitFor=Y;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/utils/delay.ts","../src/utils/filterUniqueByKey.ts","../src/utils/formatWalletChainId.ts","../src/utils/formatWalletName.ts","../src/utils/getAdapterFromWalletType.ts","../src/utils/getParsedStorageItem.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/impersonatedHelpers.ts","../src/utils/isSafeApp.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/utils/selectAdapterByKey.ts","../src/utils/waitFor.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","delay","value","ms","resolve","runTimeout","filterUniqueByKey","array","key","seenValues","item","keyValue","formatWalletChainId","chainId","connectedAdapter","WALLET_MAPPINGS","formatWalletName","walletName","getAdapterFromWalletType","walletType","getParsedStorageItem","error","getWalletTypeFromConnectorName","adapter","name","impersonatedHelpers","address","isSafeApp","lastConnectedWalletHelpers","recentConnectedWalletHelpers","wallets","selectAdapterByKey","adapterKey","foundAdapter","a","waitFor","predicate","maxChecks","checkIntervalMs","i","isSolanaChain","setChainId"],"mappings":"aAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,MAAA,CAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECHL,IAAMC,EAAQ,CAAIC,CAAAA,CAAUC,CAAAA,GAC1B,IAAI,OAAA,CAASC,CAAAA,EAAY,CAC9B,IAAMC,CAAAA,CAAa,IAAM,CACvB,UAAA,CAAW,IAAMD,CAAAA,CAAQF,CAAK,CAAA,CAAGC,CAAE,EACrC,CAAA,CAEI,OAAO,MAAA,CAAW,GAAA,CACpBE,CAAAA,EAAW,CAEX,UAAA,CAAWA,CAAAA,CAAY,CAAC,EAE5B,CAAC,EC5BI,SAASC,CAAAA,CAAqBC,CAAAA,CAAYC,CAAAA,CAAmB,CAGlE,IAAMC,CAAAA,CAAa,IAAI,GAAA,CAGvB,OAAOF,CAAAA,CAAM,MAAA,CAAQG,CAAAA,EAAS,CAE5B,IAAMC,EAAWD,CAAAA,CAAKF,CAAG,CAAA,CAGzB,OAAIC,CAAAA,CAAW,GAAA,CAAIE,CAAQ,CAAA,CAGlB,KAAA,EAGPF,CAAAA,CAAW,GAAA,CAAIE,CAAQ,CAAA,CAEhB,IAAA,CAEX,CAAC,CACH,CChCO,SAASC,CAAAA,CAAoBC,CAAAA,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A0B,GAAA,CAC1B,CACA,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,CAAAA,CAAWE,CAAAA,EAAAA,CAAK,CAClC,GAAIH,CAAAA,EAAU,CACZ,OAEF,MAAM,IAAI,OAAA,CAAShC,CAAAA,EAAY,UAAA,CAAWA,CAAAA,CAASkC,CAAe,CAAC,EACrE,CACA,MAAM,IAAI,KAAA,CAAM,iCAAiC,CACnD,CCLO,SAASE,EAAc3B,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,SAAA,CAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAAS4B,CAAAA,CAAW5B,CAAAA,CAA2C,CACpE,OAAI2B,CAAAA,CAAc3B,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.js","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n\n/**\n * Type representing a wallet identifier in format \"OrbitAdapter:wallet\"\n * @example \"evm:metamask\" | \"solana:phantom\"\n */\nexport type WalletType = `${OrbitAdapter}:${string}`;\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","/**\n * Filters an array of objects to keep only the first occurrence of an object\n * based on a unique value of a specified key.\n *\n * This function is generic and type-safe. It iterates through the array and uses a\n * Set to track already encountered key values, effectively removing duplicates.\n *\n * @template T The type of the objects in the array.\n * @param {T[]} array - The array of objects to be filtered.\n * @param {keyof T} key - The object key (property name) whose values must be unique.\n * @returns {T[]} The filtered array containing only objects with unique key values.\n */\nexport function filterUniqueByKey<T>(array: T[], key: keyof T): T[] {\n // 1. Create a Set to store the unique values of the key encountered so far.\n // Set is a collection of unique values, which is perfect for fast duplicate checks.\n const seenValues = new Set<T[keyof T]>();\n\n // 2. Use the native Array.prototype.filter() method to create a new, filtered array.\n return array.filter((item) => {\n // Access the value of the specified key from the current object.\n const keyValue = item[key];\n\n // 3. Check if this key value has been seen before.\n if (seenValues.has(keyValue)) {\n // If the value is already in the Set, return false.\n // This object is a duplicate and will be excluded from the result.\n return false;\n } else {\n // If the value is encountered for the first time, add it to the Set.\n seenValues.add(keyValue);\n // Return true to include the object in the resulting unique array.\n return true;\n }\n });\n}\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","const WALLET_MAPPINGS = new Map([\n ['Impersonated Connector', 'impersonatedwallet'],\n ['Safe', 'safewallet'],\n ['Trust', 'trustwallet'],\n ['Trust Wallet', 'trustwallet'],\n ['Brave Кошелек', 'bravewallet'],\n ['Brave Wallet', 'bravewallet'],\n ['Base Account', 'coinbasewallet'], // TODO: need fix\n]);\n\nexport const formatWalletName = (walletName: string): string => {\n return WALLET_MAPPINGS.get(walletName) ?? walletName.replace(/\\s+/g, '').toLowerCase();\n};\n","import { OrbitAdapter, WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType?.split(':')[0] as OrbitAdapter.EVM) ?? OrbitAdapter.EVM;\n}\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n\n removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","export const isSafeApp = typeof window !== 'undefined' && window !== window.parent;\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string; address?: string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('orbit-core:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId, address }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(\n lastConnectedWalletHelpers.STORAGE_KEY,\n JSON.stringify({ walletType, chainId, address }),\n )\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('orbit-core:recentConnectedWallets'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param wallets - RecentConnectedWallet\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: (wallets: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify(wallets))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","export async function waitFor(\n predicate: () => boolean | undefined,\n maxChecks: number = 50,\n checkIntervalMs: number = 200,\n) {\n for (let i = 0; i < maxChecks; i++) {\n if (predicate()) {\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, checkIntervalMs));\n }\n throw new Error('Predicate not fulfilled in time');\n}\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/delay.ts","../src/utils/filterUniqueByKey.ts","../src/utils/formatConnectorChainId.ts","../src/utils/formatConnectorName.ts","../src/utils/getAdapterFromConnectorType.ts","../src/utils/getConnectorTypeFromName.ts","../src/utils/getParsedStorageItem.ts","../src/utils/impersonatedHelpers.ts","../src/utils/isSafeApp.ts","../src/utils/lastConnectedConnectorHelpers.ts","../src/utils/recentConnectedConnectorHelpers.ts","../src/utils/selectAdapterByKey.ts","../src/utils/waitFor.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","delay","value","ms","resolve","runTimeout","filterUniqueByKey","array","key","seenValues","item","keyValue","formatConnectorChainId","chainId","connectedAdapter","CONNECTOR_MAPPINGS","formatConnectorName","connectorName","getAdapterFromConnectorType","connectorType","getConnectorTypeFromName","adapter","name","getParsedStorageItem","error","impersonatedHelpers","address","isSafeApp","lastConnectedConnectorHelpers","recentConnectedConnectorHelpers","connectors","selectAdapterByKey","adapterKey","foundAdapter","a","waitFor","predicate","maxChecks","checkIntervalMs","i","isSolanaChain","setChainId"],"mappings":"aAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,MAAA,CAAS,QAAA,CASTA,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CAAAA,CAAW5B,CAAAA,CAA2C,CACpE,OAAI2B,CAAAA,CAAc3B,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.js","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n\n/**\n * Type representing a connector identifier in format \"OrbitAdapter:connector\"\n * @example \"evm:metamask\" | \"solana:phantom\"\n */\nexport type ConnectorType = `${OrbitAdapter}:${string}`;\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","/**\n * Filters an array of objects to keep only the first occurrence of an object\n * based on a unique value of a specified key.\n *\n * This function is generic and type-safe. It iterates through the array and uses a\n * Set to track already encountered key values, effectively removing duplicates.\n *\n * @template T The type of the objects in the array.\n * @param {T[]} array - The array of objects to be filtered.\n * @param {keyof T} key - The object key (property name) whose values must be unique.\n * @returns {T[]} The filtered array containing only objects with unique key values.\n */\nexport function filterUniqueByKey<T>(array: T[], key: keyof T): T[] {\n // 1. Create a Set to store the unique values of the key encountered so far.\n // Set is a collection of unique values, which is perfect for fast duplicate checks.\n const seenValues = new Set<T[keyof T]>();\n\n // 2. Use the native Array.prototype.filter() method to create a new, filtered array.\n return array.filter((item) => {\n // Access the value of the specified key from the current object.\n const keyValue = item[key];\n\n // 3. Check if this key value has been seen before.\n if (seenValues.has(keyValue)) {\n // If the value is already in the Set, return false.\n // This object is a duplicate and will be excluded from the result.\n return false;\n } else {\n // If the value is encountered for the first time, add it to the Set.\n seenValues.add(keyValue);\n // Return true to include the object in the resulting unique array.\n return true;\n }\n });\n}\n","import { OrbitAdapter } from '../types';\n\nexport function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","const CONNECTOR_MAPPINGS = new Map([\n ['Impersonated Connector', 'impersonatedwallet'],\n ['Safe', 'safewallet'],\n ['Trust', 'trustwallet'],\n ['Trust Wallet', 'trustwallet'],\n ['Brave Кошелек', 'bravewallet'],\n ['Brave Wallet', 'bravewallet'],\n ['Base Account', 'coinbasewallet'], // TODO: need fix\n]);\n\nexport const formatConnectorName = (connectorName: string): string => {\n return CONNECTOR_MAPPINGS.get(connectorName) ?? connectorName.replace(/\\s+/g, '').toLowerCase();\n};\n","import { ConnectorType, OrbitAdapter } from '../types';\n\n/**\n * Extracts the adapter type from a connector type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromConnectorType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromConnectorType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromConnectorType('unknown');\n * ```\n *\n * @param connectorType - Connector type in format \"orbit-adapter:connector\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the connector type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromConnectorType(connectorType: ConnectorType): OrbitAdapter {\n return (connectorType?.split(':')[0] as OrbitAdapter.EVM) ?? OrbitAdapter.EVM;\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized connector type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getConnectorTypeFromName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getConnectorTypeFromName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getConnectorTypeFromName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted connector type string in format \"orbit-adapter:connector\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent connector type identifiers across the application\n * and normalizes connector names for better UX/consistency.\n */\nexport function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedConnector object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n\n removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","export const isSafeApp = typeof window !== 'undefined' && window !== window.parent;\n","import { ConnectorType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedConnector = { connectorType: ConnectorType; chainId: number | string; address?: string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedConnectorHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:lastConnectedConnector',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedConnector: getParsedStorageItem<LastConnectedConnector>('orbit-core:lastConnectedConnector'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(\n lastConnectedConnectorHelpers.STORAGE_KEY,\n JSON.stringify({ connectorType, chainId, address }),\n )\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedConnector object or undefined if not set or in SSR context\n */\n getLastConnectedConnector: () =>\n getParsedStorageItem<LastConnectedConnector>(lastConnectedConnectorHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedConnector: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(lastConnectedConnectorHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { OrbitAdapter } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedConnector = Record<OrbitAdapter, Record<string, boolean>>;\n\n/**\n * Helper utilities for managing the last connected connector state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedConnectorHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:recentConnectedConnector',\n\n /**\n * The value of the last connected connector, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedConnector: getParsedStorageItem<RecentConnectedConnector>('orbit-core:recentConnectedConnectors'),\n\n /**\n * Stores the last connected connector data in localStorage.\n *\n * @param connectors - RecentConnectedConnector\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedConnector: (connectors: RecentConnectedConnector) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedConnectorHelpers.STORAGE_KEY, JSON.stringify(connectors))\n : undefined,\n\n /**\n * Retrieves the current last connected connector data from localStorage.\n *\n * @returns The LastConnectedConnector object or undefined if not set or in SSR context\n */\n getRecentConnectedConnector: () =>\n getParsedStorageItem<RecentConnectedConnector>(recentConnectedConnectorHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected connector data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedConnector: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedConnectorHelpers.STORAGE_KEY)\n : undefined,\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","export async function waitFor(\n predicate: () => boolean | undefined,\n maxChecks: number = 50,\n checkIntervalMs: number = 200,\n) {\n for (let i = 0; i < maxChecks; i++) {\n if (predicate()) {\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, checkIntervalMs));\n }\n throw new Error('Predicate not fulfilled in time');\n}\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(a||{});var l=(e,t)=>new Promise(n=>{let r=()=>{setTimeout(()=>n(e),t);};typeof window<"u"?r():setTimeout(r,0);});function u(e,t){let n=new Set;return e.filter(r=>{let i=r[t];return n.has(i)?false:(n.add(i),true)})}function C(e,t){return typeof e=="string"?`${t}:${e}`:e}var c=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safewallet"],["Trust","trustwallet"],["Trust Wallet","trustwallet"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","bravewallet"],["Brave Wallet","bravewallet"],["Base Account","coinbasewallet"]]),y=e=>c.get(e)??e.replace(/\s+/g,"").toLowerCase();function T(e){return e?.split(":")[0]??"evm"}function O(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}function o(e){if(typeof window>"u")return;let t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(n){console.error(`Error parsing ${e} from localStorage:`,n);return}}var I={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:e=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",e):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};var G=typeof window<"u"&&window!==window.parent;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:o("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:t,address:n})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:t,address:n})):void 0,getLastConnectedConnector:()=>o(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var s={STORAGE_KEY:"orbit-core:recentConnectedConnector",recentConnectedConnector:o("orbit-core:recentConnectedConnectors"),setRecentConnectedConnector:e=>typeof window<"u"?window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentConnectedConnector:()=>o(s.STORAGE_KEY),removeRecentConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(s.STORAGE_KEY):void 0};var $=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};async function Y(e,t=50,n=200){for(let r=0;r<t;r++){if(e())return;await new Promise(i=>setTimeout(i,n));}throw new Error("Predicate not fulfilled in time")}function p(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function B(e){return p(e)?`solana:${e}`:e}export{a as OrbitAdapter,l as delay,u as filterUniqueByKey,C as formatConnectorChainId,y as formatConnectorName,T as getAdapterFromConnectorType,O as getConnectorTypeFromName,o as getParsedStorageItem,I as impersonatedHelpers,G as isSafeApp,p as isSolanaChain,d as lastConnectedConnectorHelpers,s as recentConnectedConnectorHelpers,$ as selectAdapterByKey,B as setChainId,Y as waitFor};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/utils/delay.ts","../src/utils/filterUniqueByKey.ts","../src/utils/formatWalletChainId.ts","../src/utils/formatWalletName.ts","../src/utils/getAdapterFromWalletType.ts","../src/utils/getParsedStorageItem.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/impersonatedHelpers.ts","../src/utils/isSafeApp.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/utils/selectAdapterByKey.ts","../src/utils/waitFor.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","delay","value","ms","resolve","runTimeout","filterUniqueByKey","array","key","seenValues","item","keyValue","formatWalletChainId","chainId","connectedAdapter","WALLET_MAPPINGS","formatWalletName","walletName","getAdapterFromWalletType","walletType","getParsedStorageItem","error","getWalletTypeFromConnectorName","adapter","name","impersonatedHelpers","address","isSafeApp","lastConnectedWalletHelpers","recentConnectedWalletHelpers","wallets","selectAdapterByKey","adapterKey","foundAdapter","a","waitFor","predicate","maxChecks","checkIntervalMs","i","isSolanaChain","setChainId"],"mappings":"AAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,MAAA,CAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECHL,IAAMC,EAAQ,CAAIC,CAAAA,CAAUC,CAAAA,GAC1B,IAAI,OAAA,CAASC,CAAAA,EAAY,CAC9B,IAAMC,CAAAA,CAAa,IAAM,CACvB,UAAA,CAAW,IAAMD,CAAAA,CAAQF,CAAK,CAAA,CAAGC,CAAE,EACrC,CAAA,CAEI,OAAO,MAAA,CAAW,GAAA,CACpBE,CAAAA,EAAW,CAEX,UAAA,CAAWA,CAAAA,CAAY,CAAC,EAE5B,CAAC,EC5BI,SAASC,CAAAA,CAAqBC,CAAAA,CAAYC,CAAAA,CAAmB,CAGlE,IAAMC,CAAAA,CAAa,IAAI,GAAA,CAGvB,OAAOF,CAAAA,CAAM,MAAA,CAAQG,CAAAA,EAAS,CAE5B,IAAMC,EAAWD,CAAAA,CAAKF,CAAG,CAAA,CAGzB,OAAIC,CAAAA,CAAW,GAAA,CAAIE,CAAQ,CAAA,CAGlB,KAAA,EAGPF,CAAAA,CAAW,GAAA,CAAIE,CAAQ,CAAA,CAEhB,IAAA,CAEX,CAAC,CACH,CChCO,SAASC,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CAAoB,EAAA,CACpBC,EAA0B,GAAA,CAC1B,CACA,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,CAAAA,CAAWE,CAAAA,EAAAA,CAAK,CAClC,GAAIH,CAAAA,EAAU,CACZ,OAEF,MAAM,IAAI,OAAA,CAAShC,CAAAA,EAAY,UAAA,CAAWA,CAAAA,CAASkC,CAAe,CAAC,EACrE,CACA,MAAM,IAAI,KAAA,CAAM,iCAAiC,CACnD,CCLO,SAASE,EAAc3B,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,SAAA,CAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAAS4B,CAAAA,CAAW5B,CAAAA,CAA2C,CACpE,OAAI2B,CAAAA,CAAc3B,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.mjs","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n\n/**\n * Type representing a wallet identifier in format \"OrbitAdapter:wallet\"\n * @example \"evm:metamask\" | \"solana:phantom\"\n */\nexport type WalletType = `${OrbitAdapter}:${string}`;\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","/**\n * Filters an array of objects to keep only the first occurrence of an object\n * based on a unique value of a specified key.\n *\n * This function is generic and type-safe. It iterates through the array and uses a\n * Set to track already encountered key values, effectively removing duplicates.\n *\n * @template T The type of the objects in the array.\n * @param {T[]} array - The array of objects to be filtered.\n * @param {keyof T} key - The object key (property name) whose values must be unique.\n * @returns {T[]} The filtered array containing only objects with unique key values.\n */\nexport function filterUniqueByKey<T>(array: T[], key: keyof T): T[] {\n // 1. Create a Set to store the unique values of the key encountered so far.\n // Set is a collection of unique values, which is perfect for fast duplicate checks.\n const seenValues = new Set<T[keyof T]>();\n\n // 2. Use the native Array.prototype.filter() method to create a new, filtered array.\n return array.filter((item) => {\n // Access the value of the specified key from the current object.\n const keyValue = item[key];\n\n // 3. Check if this key value has been seen before.\n if (seenValues.has(keyValue)) {\n // If the value is already in the Set, return false.\n // This object is a duplicate and will be excluded from the result.\n return false;\n } else {\n // If the value is encountered for the first time, add it to the Set.\n seenValues.add(keyValue);\n // Return true to include the object in the resulting unique array.\n return true;\n }\n });\n}\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","const WALLET_MAPPINGS = new Map([\n ['Impersonated Connector', 'impersonatedwallet'],\n ['Safe', 'safewallet'],\n ['Trust', 'trustwallet'],\n ['Trust Wallet', 'trustwallet'],\n ['Brave Кошелек', 'bravewallet'],\n ['Brave Wallet', 'bravewallet'],\n ['Base Account', 'coinbasewallet'], // TODO: need fix\n]);\n\nexport const formatWalletName = (walletName: string): string => {\n return WALLET_MAPPINGS.get(walletName) ?? walletName.replace(/\\s+/g, '').toLowerCase();\n};\n","import { OrbitAdapter, WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType?.split(':')[0] as OrbitAdapter.EVM) ?? OrbitAdapter.EVM;\n}\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n\n removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","export const isSafeApp = typeof window !== 'undefined' && window !== window.parent;\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string; address?: string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('orbit-core:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId, address }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(\n lastConnectedWalletHelpers.STORAGE_KEY,\n JSON.stringify({ walletType, chainId, address }),\n )\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('orbit-core:recentConnectedWallets'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param wallets - RecentConnectedWallet\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: (wallets: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify(wallets))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","export async function waitFor(\n predicate: () => boolean | undefined,\n maxChecks: number = 50,\n checkIntervalMs: number = 200,\n) {\n for (let i = 0; i < maxChecks; i++) {\n if (predicate()) {\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, checkIntervalMs));\n }\n throw new Error('Predicate not fulfilled in time');\n}\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/delay.ts","../src/utils/filterUniqueByKey.ts","../src/utils/formatConnectorChainId.ts","../src/utils/formatConnectorName.ts","../src/utils/getAdapterFromConnectorType.ts","../src/utils/getConnectorTypeFromName.ts","../src/utils/getParsedStorageItem.ts","../src/utils/impersonatedHelpers.ts","../src/utils/isSafeApp.ts","../src/utils/lastConnectedConnectorHelpers.ts","../src/utils/recentConnectedConnectorHelpers.ts","../src/utils/selectAdapterByKey.ts","../src/utils/waitFor.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","delay","value","ms","resolve","runTimeout","filterUniqueByKey","array","key","seenValues","item","keyValue","formatConnectorChainId","chainId","connectedAdapter","CONNECTOR_MAPPINGS","formatConnectorName","connectorName","getAdapterFromConnectorType","connectorType","getConnectorTypeFromName","adapter","name","getParsedStorageItem","error","impersonatedHelpers","address","isSafeApp","lastConnectedConnectorHelpers","recentConnectedConnectorHelpers","connectors","selectAdapterByKey","adapterKey","foundAdapter","a","waitFor","predicate","maxChecks","checkIntervalMs","i","isSolanaChain","setChainId"],"mappings":"AAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA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AEnE,KACT,CAQO,SAAS4B,CAAAA,CAAW5B,CAAAA,CAA2C,CACpE,OAAI2B,CAAAA,CAAc3B,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.mjs","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n\n/**\n * Type representing a connector identifier in format \"OrbitAdapter:connector\"\n * @example \"evm:metamask\" | \"solana:phantom\"\n */\nexport type ConnectorType = `${OrbitAdapter}:${string}`;\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","/**\n * Filters an array of objects to keep only the first occurrence of an object\n * based on a unique value of a specified key.\n *\n * This function is generic and type-safe. It iterates through the array and uses a\n * Set to track already encountered key values, effectively removing duplicates.\n *\n * @template T The type of the objects in the array.\n * @param {T[]} array - The array of objects to be filtered.\n * @param {keyof T} key - The object key (property name) whose values must be unique.\n * @returns {T[]} The filtered array containing only objects with unique key values.\n */\nexport function filterUniqueByKey<T>(array: T[], key: keyof T): T[] {\n // 1. Create a Set to store the unique values of the key encountered so far.\n // Set is a collection of unique values, which is perfect for fast duplicate checks.\n const seenValues = new Set<T[keyof T]>();\n\n // 2. Use the native Array.prototype.filter() method to create a new, filtered array.\n return array.filter((item) => {\n // Access the value of the specified key from the current object.\n const keyValue = item[key];\n\n // 3. Check if this key value has been seen before.\n if (seenValues.has(keyValue)) {\n // If the value is already in the Set, return false.\n // This object is a duplicate and will be excluded from the result.\n return false;\n } else {\n // If the value is encountered for the first time, add it to the Set.\n seenValues.add(keyValue);\n // Return true to include the object in the resulting unique array.\n return true;\n }\n });\n}\n","import { OrbitAdapter } from '../types';\n\nexport function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","const CONNECTOR_MAPPINGS = new Map([\n ['Impersonated Connector', 'impersonatedwallet'],\n ['Safe', 'safewallet'],\n ['Trust', 'trustwallet'],\n ['Trust Wallet', 'trustwallet'],\n ['Brave Кошелек', 'bravewallet'],\n ['Brave Wallet', 'bravewallet'],\n ['Base Account', 'coinbasewallet'], // TODO: need fix\n]);\n\nexport const formatConnectorName = (connectorName: string): string => {\n return CONNECTOR_MAPPINGS.get(connectorName) ?? connectorName.replace(/\\s+/g, '').toLowerCase();\n};\n","import { ConnectorType, OrbitAdapter } from '../types';\n\n/**\n * Extracts the adapter type from a connector type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromConnectorType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromConnectorType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromConnectorType('unknown');\n * ```\n *\n * @param connectorType - Connector type in format \"orbit-adapter:connector\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the connector type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromConnectorType(connectorType: ConnectorType): OrbitAdapter {\n return (connectorType?.split(':')[0] as OrbitAdapter.EVM) ?? OrbitAdapter.EVM;\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized connector type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getConnectorTypeFromName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getConnectorTypeFromName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getConnectorTypeFromName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted connector type string in format \"orbit-adapter:connector\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent connector type identifiers across the application\n * and normalizes connector names for better UX/consistency.\n */\nexport function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedConnector object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n\n removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","export const isSafeApp = typeof window !== 'undefined' && window !== window.parent;\n","import { ConnectorType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedConnector = { connectorType: ConnectorType; chainId: number | string; address?: string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedConnectorHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:lastConnectedConnector',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedConnector: getParsedStorageItem<LastConnectedConnector>('orbit-core:lastConnectedConnector'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(\n lastConnectedConnectorHelpers.STORAGE_KEY,\n JSON.stringify({ connectorType, chainId, address }),\n )\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedConnector object or undefined if not set or in SSR context\n */\n getLastConnectedConnector: () =>\n getParsedStorageItem<LastConnectedConnector>(lastConnectedConnectorHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedConnector: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(lastConnectedConnectorHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { OrbitAdapter } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedConnector = Record<OrbitAdapter, Record<string, boolean>>;\n\n/**\n * Helper utilities for managing the last connected connector state\n *\n * @remarks\n * All data is stored in localStorage with the 'orbit-core:lastConnectedConnector' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedConnectorHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'orbit-core:recentConnectedConnector',\n\n /**\n * The value of the last connected connector, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedConnector: getParsedStorageItem<RecentConnectedConnector>('orbit-core:recentConnectedConnectors'),\n\n /**\n * Stores the last connected connector data in localStorage.\n *\n * @param connectors - RecentConnectedConnector\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedConnector: (connectors: RecentConnectedConnector) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedConnectorHelpers.STORAGE_KEY, JSON.stringify(connectors))\n : undefined,\n\n /**\n * Retrieves the current last connected connector data from localStorage.\n *\n * @returns The LastConnectedConnector object or undefined if not set or in SSR context\n */\n getRecentConnectedConnector: () =>\n getParsedStorageItem<RecentConnectedConnector>(recentConnectedConnectorHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected connector data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedConnector: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedConnectorHelpers.STORAGE_KEY)\n : undefined,\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","export async function waitFor(\n predicate: () => boolean | undefined,\n maxChecks: number = 50,\n checkIntervalMs: number = 200,\n) {\n for (let i = 0; i < maxChecks; i++) {\n if (predicate()) {\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, checkIntervalMs));\n }\n throw new Error('Predicate not fulfilled in time');\n}\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|