@tuwaio/orbit-core 0.0.3 → 0.1.0
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 +5 -6
- package/dist/index.d.mts +239 -28
- package/dist/index.d.ts +239 -28
- 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 +5 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@tuwaio/orbit-core)
|
|
4
4
|
[](./LICENSE)
|
|
5
|
-
[](https://github.com/TuwaIO/orbit/actions)
|
|
6
6
|
|
|
7
7
|
A powerful, framework-agnostic library for seamless multi-chain blockchain interactions, providing a unified interface for EVM, Solana, and Starknet operations.
|
|
8
8
|
|
|
@@ -18,7 +18,7 @@ Its primary purpose is to provide a unified interface for interacting with diffe
|
|
|
18
18
|
|
|
19
19
|
## ✨ Key Features
|
|
20
20
|
|
|
21
|
-
- **Multi-Chain Architecture:** Native support for EVM, Solana, and Starknet through a unified adapter interface
|
|
21
|
+
- **Multi-Chain Architecture:** Native support for EVM, Solana, and Starknet through a unified adapter interface.
|
|
22
22
|
- **Framework Independence:** Compatible with any JavaScript framework or vanilla JS
|
|
23
23
|
- **Type-Safe Development:** Full TypeScript support with comprehensive type definitions
|
|
24
24
|
- **Flexible Adapter System:** Easily extensible for new blockchain architectures
|
|
@@ -30,11 +30,11 @@ Its primary purpose is to provide a unified interface for interacting with diffe
|
|
|
30
30
|
## 💾 Installation
|
|
31
31
|
```bash
|
|
32
32
|
# Using pnpm
|
|
33
|
-
pnpm add @tuwaio/orbit-core
|
|
33
|
+
pnpm add @tuwaio/orbit-core
|
|
34
34
|
# Using npm
|
|
35
|
-
npm install @tuwaio/orbit-core
|
|
35
|
+
npm install @tuwaio/orbit-core
|
|
36
36
|
# Using yarn
|
|
37
|
-
yarn add @tuwaio/orbit-core
|
|
37
|
+
yarn add @tuwaio/orbit-core
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
---
|
|
@@ -71,7 +71,6 @@ Orbit Core is built on these main concepts:
|
|
|
71
71
|
|
|
72
72
|
- `OrbitAdapter`: Enum defining supported blockchain types
|
|
73
73
|
- `selectAdapterByKey`: Utility for runtime adapter selection
|
|
74
|
-
- `createBoundedUseStore`: Store creation helper for state management
|
|
75
74
|
- Chain-specific helpers and utilities
|
|
76
75
|
|
|
77
76
|
---
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { StoreApi } from 'zustand';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @file
|
|
5
3
|
* Core type definitions for the Orbit blockchain adapter system.
|
|
@@ -79,7 +77,7 @@ declare enum OrbitAdapter {
|
|
|
79
77
|
* };
|
|
80
78
|
*
|
|
81
79
|
* // Multiple adapters
|
|
82
|
-
* const multiChainConfig: OrbitGenericAdapter<
|
|
80
|
+
* const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {
|
|
83
81
|
* adapter: [
|
|
84
82
|
* { key: OrbitAdapter.EVM, ... },
|
|
85
83
|
* { key: OrbitAdapter.SOLANA, ... }
|
|
@@ -92,42 +90,253 @@ type OrbitGenericAdapter<A extends {
|
|
|
92
90
|
}> = {
|
|
93
91
|
adapter: A | A[];
|
|
94
92
|
};
|
|
93
|
+
type BaseAdapter = {
|
|
94
|
+
/**
|
|
95
|
+
* Generates blockchain explorer URL
|
|
96
|
+
* @returns Explorer URL or undefined if not available
|
|
97
|
+
*/
|
|
98
|
+
getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;
|
|
99
|
+
/** Optional method to resolve ENS-like names */
|
|
100
|
+
getName?: (address: string) => Promise<string | null>;
|
|
101
|
+
/** Optional method to get avatar for resolved names */
|
|
102
|
+
getAvatar?: (name: string) => Promise<string | null>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Type representing a wallet identifier in format "OrbitAdapter:wallet"
|
|
106
|
+
* @example "evm:metamask" | "solana:phantom"
|
|
107
|
+
*/
|
|
108
|
+
type WalletType = `${OrbitAdapter}:${string}`;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @name delay
|
|
112
|
+
*
|
|
113
|
+
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
114
|
+
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
115
|
+
*
|
|
116
|
+
* This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.
|
|
117
|
+
* It asynchronously waits for the 'window' object to be defined before starting the actual timer,
|
|
118
|
+
* helping to prevent errors during the initial server render while still providing a time delay on the client.
|
|
119
|
+
*
|
|
120
|
+
* @template T - The type of the value being resolved.
|
|
121
|
+
*
|
|
122
|
+
* @param {T} value - The value to resolve the Promise with after the delay.
|
|
123
|
+
* @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.
|
|
124
|
+
*
|
|
125
|
+
* @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).
|
|
130
|
+
* async function waitForWindowAndDelay() {
|
|
131
|
+
* console.log("Start wait...");
|
|
132
|
+
* // This will wait for window, and then wait 100ms.
|
|
133
|
+
* const data = await delay("Ready to connect", 100);
|
|
134
|
+
* console.log(data);
|
|
135
|
+
* }
|
|
136
|
+
* waitForWindowAndDelay();
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Filters an array of objects to keep only the first occurrence of an object
|
|
143
|
+
* based on a unique value of a specified key.
|
|
144
|
+
*
|
|
145
|
+
* This function is generic and type-safe. It iterates through the array and uses a
|
|
146
|
+
* Set to track already encountered key values, effectively removing duplicates.
|
|
147
|
+
*
|
|
148
|
+
* @template T The type of the objects in the array.
|
|
149
|
+
* @param {T[]} array - The array of objects to be filtered.
|
|
150
|
+
* @param {keyof T} key - The object key (property name) whose values must be unique.
|
|
151
|
+
* @returns {T[]} The filtered array containing only objects with unique key values.
|
|
152
|
+
*/
|
|
153
|
+
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
154
|
+
|
|
155
|
+
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
156
|
+
|
|
157
|
+
declare const formatWalletName: (walletName: string) => string;
|
|
95
158
|
|
|
96
159
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
160
|
+
* Extracts the adapter type from a wallet type string
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Returns OrbitAdapter.EVM
|
|
165
|
+
* getAdapterFromWalletType('evm:metamask');
|
|
166
|
+
*
|
|
167
|
+
* // Returns OrbitAdapter.SOLANA
|
|
168
|
+
* getAdapterFromWalletType('solana:phantom');
|
|
169
|
+
*
|
|
170
|
+
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
+
* getAdapterFromWalletType('unknown');
|
|
172
|
+
* ```
|
|
100
173
|
*
|
|
101
|
-
* @
|
|
174
|
+
* @param walletType - Wallet type in format "chain:wallet" (e.g. "evm:metamask", "solana:phantom")
|
|
175
|
+
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* The function splits the wallet type string by ":" and takes the first part as the adapter type.
|
|
179
|
+
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
|
+
*/
|
|
181
|
+
declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
185
|
+
*
|
|
186
|
+
* @param key - The key for localStorage
|
|
187
|
+
* @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid
|
|
102
188
|
*/
|
|
189
|
+
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
103
190
|
|
|
104
191
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
192
|
+
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Returns "evm:metamask"
|
|
197
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
|
|
198
|
+
*
|
|
199
|
+
* // Returns "solana:phantom"
|
|
200
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
|
|
201
|
+
*
|
|
202
|
+
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
203
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
207
|
+
* @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
|
|
208
|
+
* @returns A formatted wallet type string in format "chain:wallet"
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* The function:
|
|
212
|
+
* 1. Combines adapter type with connector name using ":" as separator
|
|
213
|
+
* 2. Removes all whitespace from connector name
|
|
214
|
+
* 3. Converts connector name to lowercase
|
|
215
|
+
* This ensures consistent wallet type identifiers across the application
|
|
108
216
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} ? T : never;
|
|
217
|
+
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
218
|
+
|
|
112
219
|
/**
|
|
113
|
-
*
|
|
220
|
+
* Helper utilities for managing impersonated wallet addresses
|
|
114
221
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* These utilities are primarily used for development and testing purposes.
|
|
224
|
+
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
225
|
+
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
226
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
227
|
+
*/
|
|
228
|
+
declare const impersonatedHelpers: {
|
|
229
|
+
/**
|
|
230
|
+
* Currently impersonated address from localStorage
|
|
231
|
+
* Returns empty string if not set or in SSR context
|
|
232
|
+
*/
|
|
233
|
+
impersonatedAddress: string;
|
|
234
|
+
/**
|
|
235
|
+
* Stores an impersonated address in localStorage
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Set impersonated address
|
|
240
|
+
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param address - Ethereum or Solana address to impersonate
|
|
244
|
+
* @returns undefined in SSR context, void in browser
|
|
245
|
+
*/
|
|
246
|
+
setImpersonated: (address: string) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves the current impersonated address from localStorage
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Get current impersonated address
|
|
253
|
+
* const address = impersonatedHelpers.getImpersonated();
|
|
254
|
+
* if (address) {
|
|
255
|
+
* console.log('Currently impersonating:', address);
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
* @returns The impersonated address or undefined if not set or in SSR context
|
|
259
|
+
*/
|
|
260
|
+
getImpersonated: () => string | null | undefined;
|
|
261
|
+
removeImpersonated: () => void;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
declare const isSafeApp: boolean;
|
|
265
|
+
|
|
266
|
+
type LastConnectedWallet = {
|
|
267
|
+
walletType: WalletType;
|
|
268
|
+
chainId: number | string;
|
|
269
|
+
address?: string;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Helper utilities for managing the last connected wallet state
|
|
119
273
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
276
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
277
|
+
*/
|
|
278
|
+
declare const lastConnectedWalletHelpers: {
|
|
279
|
+
STORAGE_KEY: string;
|
|
280
|
+
/**
|
|
281
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
282
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
|
+
*/
|
|
284
|
+
lastConnectedWallet: LastConnectedWallet | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Stores the last connected wallet data in localStorage.
|
|
287
|
+
*
|
|
288
|
+
* @param data - Object containing the wallet type and chain ID.
|
|
289
|
+
* @returns undefined in SSR context, void in browser
|
|
290
|
+
*/
|
|
291
|
+
setLastConnectedWallet: ({ walletType, chainId, address }: LastConnectedWallet) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
294
|
+
*
|
|
295
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
296
|
+
*/
|
|
297
|
+
getLastConnectedWallet: () => LastConnectedWallet | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Removes the last connected wallet data from localStorage.
|
|
300
|
+
*
|
|
301
|
+
* @returns undefined in SSR context, void in browser
|
|
302
|
+
*/
|
|
303
|
+
removeLastConnectedWallet: () => void;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
|
+
/**
|
|
308
|
+
* Helper utilities for managing the last connected wallet state
|
|
123
309
|
*
|
|
124
|
-
* @
|
|
125
|
-
*
|
|
126
|
-
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
312
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
127
313
|
*/
|
|
128
|
-
declare const
|
|
129
|
-
|
|
130
|
-
|
|
314
|
+
declare const recentConnectedWalletHelpers: {
|
|
315
|
+
STORAGE_KEY: string;
|
|
316
|
+
/**
|
|
317
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
318
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
|
+
*/
|
|
320
|
+
recentConnectedWallet: RecentConnectedWallet | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Stores the last connected wallet data in localStorage.
|
|
323
|
+
*
|
|
324
|
+
* @param wallets - RecentConnectedWallet
|
|
325
|
+
* @returns undefined in SSR context, void in browser
|
|
326
|
+
*/
|
|
327
|
+
setRecentConnectedWallet: (wallets: RecentConnectedWallet) => void;
|
|
328
|
+
/**
|
|
329
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
330
|
+
*
|
|
331
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
332
|
+
*/
|
|
333
|
+
getRecentConnectedWallet: () => RecentConnectedWallet | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Removes the last connected wallet data from localStorage.
|
|
336
|
+
*
|
|
337
|
+
* @returns undefined in SSR context, void in browser
|
|
338
|
+
*/
|
|
339
|
+
removeRecentConnectedWallet: () => void;
|
|
131
340
|
};
|
|
132
341
|
|
|
133
342
|
/**
|
|
@@ -179,6 +388,8 @@ declare const selectAdapterByKey: <A extends {
|
|
|
179
388
|
adapterKey: OrbitAdapter;
|
|
180
389
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
181
390
|
|
|
391
|
+
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
392
|
+
|
|
182
393
|
/**
|
|
183
394
|
* Checks whether the given chain ID belongs to a Solana network.
|
|
184
395
|
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
@@ -195,4 +406,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
195
406
|
*/
|
|
196
407
|
declare function setChainId(chainId: number | string): string | number;
|
|
197
408
|
|
|
198
|
-
export { OrbitAdapter, type OrbitGenericAdapter,
|
|
409
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedWallet, type WalletType, delay, filterUniqueByKey, formatWalletChainId, formatWalletName, getAdapterFromWalletType, getParsedStorageItem, getWalletTypeFromConnectorName, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedWalletHelpers, recentConnectedWalletHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { StoreApi } from 'zustand';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @file
|
|
5
3
|
* Core type definitions for the Orbit blockchain adapter system.
|
|
@@ -79,7 +77,7 @@ declare enum OrbitAdapter {
|
|
|
79
77
|
* };
|
|
80
78
|
*
|
|
81
79
|
* // Multiple adapters
|
|
82
|
-
* const multiChainConfig: OrbitGenericAdapter<
|
|
80
|
+
* const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {
|
|
83
81
|
* adapter: [
|
|
84
82
|
* { key: OrbitAdapter.EVM, ... },
|
|
85
83
|
* { key: OrbitAdapter.SOLANA, ... }
|
|
@@ -92,42 +90,253 @@ type OrbitGenericAdapter<A extends {
|
|
|
92
90
|
}> = {
|
|
93
91
|
adapter: A | A[];
|
|
94
92
|
};
|
|
93
|
+
type BaseAdapter = {
|
|
94
|
+
/**
|
|
95
|
+
* Generates blockchain explorer URL
|
|
96
|
+
* @returns Explorer URL or undefined if not available
|
|
97
|
+
*/
|
|
98
|
+
getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;
|
|
99
|
+
/** Optional method to resolve ENS-like names */
|
|
100
|
+
getName?: (address: string) => Promise<string | null>;
|
|
101
|
+
/** Optional method to get avatar for resolved names */
|
|
102
|
+
getAvatar?: (name: string) => Promise<string | null>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Type representing a wallet identifier in format "OrbitAdapter:wallet"
|
|
106
|
+
* @example "evm:metamask" | "solana:phantom"
|
|
107
|
+
*/
|
|
108
|
+
type WalletType = `${OrbitAdapter}:${string}`;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @name delay
|
|
112
|
+
*
|
|
113
|
+
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
114
|
+
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
115
|
+
*
|
|
116
|
+
* This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.
|
|
117
|
+
* It asynchronously waits for the 'window' object to be defined before starting the actual timer,
|
|
118
|
+
* helping to prevent errors during the initial server render while still providing a time delay on the client.
|
|
119
|
+
*
|
|
120
|
+
* @template T - The type of the value being resolved.
|
|
121
|
+
*
|
|
122
|
+
* @param {T} value - The value to resolve the Promise with after the delay.
|
|
123
|
+
* @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.
|
|
124
|
+
*
|
|
125
|
+
* @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).
|
|
130
|
+
* async function waitForWindowAndDelay() {
|
|
131
|
+
* console.log("Start wait...");
|
|
132
|
+
* // This will wait for window, and then wait 100ms.
|
|
133
|
+
* const data = await delay("Ready to connect", 100);
|
|
134
|
+
* console.log(data);
|
|
135
|
+
* }
|
|
136
|
+
* waitForWindowAndDelay();
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Filters an array of objects to keep only the first occurrence of an object
|
|
143
|
+
* based on a unique value of a specified key.
|
|
144
|
+
*
|
|
145
|
+
* This function is generic and type-safe. It iterates through the array and uses a
|
|
146
|
+
* Set to track already encountered key values, effectively removing duplicates.
|
|
147
|
+
*
|
|
148
|
+
* @template T The type of the objects in the array.
|
|
149
|
+
* @param {T[]} array - The array of objects to be filtered.
|
|
150
|
+
* @param {keyof T} key - The object key (property name) whose values must be unique.
|
|
151
|
+
* @returns {T[]} The filtered array containing only objects with unique key values.
|
|
152
|
+
*/
|
|
153
|
+
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
154
|
+
|
|
155
|
+
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
156
|
+
|
|
157
|
+
declare const formatWalletName: (walletName: string) => string;
|
|
95
158
|
|
|
96
159
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
160
|
+
* Extracts the adapter type from a wallet type string
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Returns OrbitAdapter.EVM
|
|
165
|
+
* getAdapterFromWalletType('evm:metamask');
|
|
166
|
+
*
|
|
167
|
+
* // Returns OrbitAdapter.SOLANA
|
|
168
|
+
* getAdapterFromWalletType('solana:phantom');
|
|
169
|
+
*
|
|
170
|
+
* // Returns OrbitAdapter.EVM (default)
|
|
171
|
+
* getAdapterFromWalletType('unknown');
|
|
172
|
+
* ```
|
|
100
173
|
*
|
|
101
|
-
* @
|
|
174
|
+
* @param walletType - Wallet type in format "chain:wallet" (e.g. "evm:metamask", "solana:phantom")
|
|
175
|
+
* @returns The corresponding {@link OrbitAdapter} type or EVM as default
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* The function splits the wallet type string by ":" and takes the first part as the adapter type.
|
|
179
|
+
* If the split fails or the first part is empty, it defaults to EVM adapter.
|
|
180
|
+
*/
|
|
181
|
+
declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Internal function for safely retrieving and parsing data from localStorage.
|
|
185
|
+
*
|
|
186
|
+
* @param key - The key for localStorage
|
|
187
|
+
* @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid
|
|
102
188
|
*/
|
|
189
|
+
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
103
190
|
|
|
104
191
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
192
|
+
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Returns "evm:metamask"
|
|
197
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
|
|
198
|
+
*
|
|
199
|
+
* // Returns "solana:phantom"
|
|
200
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
|
|
201
|
+
*
|
|
202
|
+
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
203
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
207
|
+
* @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
|
|
208
|
+
* @returns A formatted wallet type string in format "chain:wallet"
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* The function:
|
|
212
|
+
* 1. Combines adapter type with connector name using ":" as separator
|
|
213
|
+
* 2. Removes all whitespace from connector name
|
|
214
|
+
* 3. Converts connector name to lowercase
|
|
215
|
+
* This ensures consistent wallet type identifiers across the application
|
|
108
216
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} ? T : never;
|
|
217
|
+
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
218
|
+
|
|
112
219
|
/**
|
|
113
|
-
*
|
|
220
|
+
* Helper utilities for managing impersonated wallet addresses
|
|
114
221
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* These utilities are primarily used for development and testing purposes.
|
|
224
|
+
* They provide a way to simulate different wallet addresses without actually connecting a wallet.
|
|
225
|
+
* All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.
|
|
226
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
227
|
+
*/
|
|
228
|
+
declare const impersonatedHelpers: {
|
|
229
|
+
/**
|
|
230
|
+
* Currently impersonated address from localStorage
|
|
231
|
+
* Returns empty string if not set or in SSR context
|
|
232
|
+
*/
|
|
233
|
+
impersonatedAddress: string;
|
|
234
|
+
/**
|
|
235
|
+
* Stores an impersonated address in localStorage
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Set impersonated address
|
|
240
|
+
* impersonatedHelpers.setImpersonated('0x1234...5678');
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param address - Ethereum or Solana address to impersonate
|
|
244
|
+
* @returns undefined in SSR context, void in browser
|
|
245
|
+
*/
|
|
246
|
+
setImpersonated: (address: string) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves the current impersonated address from localStorage
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Get current impersonated address
|
|
253
|
+
* const address = impersonatedHelpers.getImpersonated();
|
|
254
|
+
* if (address) {
|
|
255
|
+
* console.log('Currently impersonating:', address);
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
* @returns The impersonated address or undefined if not set or in SSR context
|
|
259
|
+
*/
|
|
260
|
+
getImpersonated: () => string | null | undefined;
|
|
261
|
+
removeImpersonated: () => void;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
declare const isSafeApp: boolean;
|
|
265
|
+
|
|
266
|
+
type LastConnectedWallet = {
|
|
267
|
+
walletType: WalletType;
|
|
268
|
+
chainId: number | string;
|
|
269
|
+
address?: string;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Helper utilities for managing the last connected wallet state
|
|
119
273
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
276
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
277
|
+
*/
|
|
278
|
+
declare const lastConnectedWalletHelpers: {
|
|
279
|
+
STORAGE_KEY: string;
|
|
280
|
+
/**
|
|
281
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
282
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
283
|
+
*/
|
|
284
|
+
lastConnectedWallet: LastConnectedWallet | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Stores the last connected wallet data in localStorage.
|
|
287
|
+
*
|
|
288
|
+
* @param data - Object containing the wallet type and chain ID.
|
|
289
|
+
* @returns undefined in SSR context, void in browser
|
|
290
|
+
*/
|
|
291
|
+
setLastConnectedWallet: ({ walletType, chainId, address }: LastConnectedWallet) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
294
|
+
*
|
|
295
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
296
|
+
*/
|
|
297
|
+
getLastConnectedWallet: () => LastConnectedWallet | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Removes the last connected wallet data from localStorage.
|
|
300
|
+
*
|
|
301
|
+
* @returns undefined in SSR context, void in browser
|
|
302
|
+
*/
|
|
303
|
+
removeLastConnectedWallet: () => void;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
type RecentConnectedWallet = Record<OrbitAdapter, Record<string, boolean>>;
|
|
307
|
+
/**
|
|
308
|
+
* Helper utilities for managing the last connected wallet state
|
|
123
309
|
*
|
|
124
|
-
* @
|
|
125
|
-
*
|
|
126
|
-
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* All data is stored in localStorage with the 'orbit-core:lastConnectedWallet' key.
|
|
312
|
+
* Functions are safe to use in both browser and SSR environments.
|
|
127
313
|
*/
|
|
128
|
-
declare const
|
|
129
|
-
|
|
130
|
-
|
|
314
|
+
declare const recentConnectedWalletHelpers: {
|
|
315
|
+
STORAGE_KEY: string;
|
|
316
|
+
/**
|
|
317
|
+
* The value of the last connected wallet, initialized when the module loads.
|
|
318
|
+
* Returns undefined if not set, invalid, or in an SSR context.
|
|
319
|
+
*/
|
|
320
|
+
recentConnectedWallet: RecentConnectedWallet | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Stores the last connected wallet data in localStorage.
|
|
323
|
+
*
|
|
324
|
+
* @param wallets - RecentConnectedWallet
|
|
325
|
+
* @returns undefined in SSR context, void in browser
|
|
326
|
+
*/
|
|
327
|
+
setRecentConnectedWallet: (wallets: RecentConnectedWallet) => void;
|
|
328
|
+
/**
|
|
329
|
+
* Retrieves the current last connected wallet data from localStorage.
|
|
330
|
+
*
|
|
331
|
+
* @returns The LastConnectedWallet object or undefined if not set or in SSR context
|
|
332
|
+
*/
|
|
333
|
+
getRecentConnectedWallet: () => RecentConnectedWallet | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Removes the last connected wallet data from localStorage.
|
|
336
|
+
*
|
|
337
|
+
* @returns undefined in SSR context, void in browser
|
|
338
|
+
*/
|
|
339
|
+
removeRecentConnectedWallet: () => void;
|
|
131
340
|
};
|
|
132
341
|
|
|
133
342
|
/**
|
|
@@ -179,6 +388,8 @@ declare const selectAdapterByKey: <A extends {
|
|
|
179
388
|
adapterKey: OrbitAdapter;
|
|
180
389
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
181
390
|
|
|
391
|
+
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
392
|
+
|
|
182
393
|
/**
|
|
183
394
|
* Checks whether the given chain ID belongs to a Solana network.
|
|
184
395
|
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
@@ -195,4 +406,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
195
406
|
*/
|
|
196
407
|
declare function setChainId(chainId: number | string): string | number;
|
|
197
408
|
|
|
198
|
-
export { OrbitAdapter, type OrbitGenericAdapter,
|
|
409
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type RecentConnectedWallet, type WalletType, delay, filterUniqueByKey, formatWalletChainId, formatWalletName, getAdapterFromWalletType, getParsedStorageItem, getWalletTypeFromConnectorName, impersonatedHelpers, isSafeApp, isSolanaChain, lastConnectedWalletHelpers, recentConnectedWalletHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=(n=>(n.EVM="evm",n.SOLANA="solana",n.Starknet="starknet",n))(l||{});var c=(e,t)=>new Promise(r=>{let n=()=>{setTimeout(()=>r(e),t);};typeof window<"u"?n():setTimeout(n,0);});function u(e,t){let r=new Set;return e.filter(n=>{let a=n[t];return r.has(a)?false:(r.add(a),true)})}function g(e,t){return typeof e=="string"?`${t}:${e}`:e}var s=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safewallet"],["Trust","trustwallet"],["Trust Wallet","trustwallet"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","bravewallet"],["Brave Wallet","bravewallet"]]),A=e=>s.get(e)??e.replace(/\s+/g,"").toLowerCase();function W(e){return e?.split(":")[0]??"evm"}function o(e){if(typeof window>"u")return;let t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from localStorage:`,r);return}}function O(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var R={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 v=typeof window<"u"&&window!==window.parent;var i={STORAGE_KEY:"orbit-core:lastConnectedWallet",lastConnectedWallet:o("orbit-core:lastConnectedWallet"),setLastConnectedWallet:({walletType:e,chainId:t,address:r})=>typeof window<"u"?window.localStorage.setItem(i.STORAGE_KEY,JSON.stringify({walletType:e,chainId:t,address:r})):void 0,getLastConnectedWallet:()=>o(i.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(i.STORAGE_KEY):void 0};var d={STORAGE_KEY:"orbit-core:recentConnectedWallet",recentConnectedWallet:o("orbit-core:recentConnectedWallets"),setRecentConnectedWallet:e=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentConnectedWallet:()=>o(d.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.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 r=t.find(n=>n.key===e);return r||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};async function N(e,t=50,r=200){for(let n=0;n<t;n++){if(e())return;await new Promise(a=>setTimeout(a,r));}throw new Error("Predicate not fulfilled in time")}function p(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function h(e){return p(e)?`solana:${e}`:e}exports.OrbitAdapter=l;exports.delay=c;exports.filterUniqueByKey=u;exports.formatWalletChainId=g;exports.formatWalletName=A;exports.getAdapterFromWalletType=W;exports.getParsedStorageItem=o;exports.getWalletTypeFromConnectorName=O;exports.impersonatedHelpers=R;exports.isSafeApp=v;exports.isSolanaChain=p;exports.lastConnectedWalletHelpers=i;exports.recentConnectedWalletHelpers=d;exports.selectAdapterByKey=$;exports.setChainId=h;exports.waitFor=N;//# 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/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"4CAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,gBAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,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<BaseAdapter> = {\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","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\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","/**\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/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,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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]);\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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var l=(n=>(n.EVM="evm",n.SOLANA="solana",n.Starknet="starknet",n))(l||{});var c=(e,t)=>new Promise(r=>{let n=()=>{setTimeout(()=>r(e),t);};typeof window<"u"?n():setTimeout(n,0);});function u(e,t){let r=new Set;return e.filter(n=>{let a=n[t];return r.has(a)?false:(r.add(a),true)})}function g(e,t){return typeof e=="string"?`${t}:${e}`:e}var s=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safewallet"],["Trust","trustwallet"],["Trust Wallet","trustwallet"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","bravewallet"],["Brave Wallet","bravewallet"]]),A=e=>s.get(e)??e.replace(/\s+/g,"").toLowerCase();function W(e){return e?.split(":")[0]??"evm"}function o(e){if(typeof window>"u")return;let t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from localStorage:`,r);return}}function O(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var R={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 v=typeof window<"u"&&window!==window.parent;var i={STORAGE_KEY:"orbit-core:lastConnectedWallet",lastConnectedWallet:o("orbit-core:lastConnectedWallet"),setLastConnectedWallet:({walletType:e,chainId:t,address:r})=>typeof window<"u"?window.localStorage.setItem(i.STORAGE_KEY,JSON.stringify({walletType:e,chainId:t,address:r})):void 0,getLastConnectedWallet:()=>o(i.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(i.STORAGE_KEY):void 0};var d={STORAGE_KEY:"orbit-core:recentConnectedWallet",recentConnectedWallet:o("orbit-core:recentConnectedWallets"),setRecentConnectedWallet:e=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentConnectedWallet:()=>o(d.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.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 r=t.find(n=>n.key===e);return r||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};async function N(e,t=50,r=200){for(let n=0;n<t;n++){if(e())return;await new Promise(a=>setTimeout(a,r));}throw new Error("Predicate not fulfilled in time")}function p(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function h(e){return p(e)?`solana:${e}`:e}export{l as OrbitAdapter,c as delay,u as filterUniqueByKey,g as formatWalletChainId,A as formatWalletName,W as getAdapterFromWalletType,o as getParsedStorageItem,O as getWalletTypeFromConnectorName,R as impersonatedHelpers,v as isSafeApp,p as isSolanaChain,i as lastConnectedWalletHelpers,d as recentConnectedWalletHelpers,$ as selectAdapterByKey,h as setChainId,N 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/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"+BAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,QAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,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<BaseAdapter> = {\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","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\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","/**\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/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,C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AAC,CAAA,CAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,ECnEA,eAAsBY,CAAAA,CACpBC,CAAAA,CACAC,CAAAA,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]);\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
],
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/TuwaIO/
|
|
25
|
+
"url": "git+https://github.com/TuwaIO/orbit.git",
|
|
26
26
|
"directory": "packages/orbit-core"
|
|
27
27
|
},
|
|
28
|
-
"homepage": "https://github.com/TuwaIO/
|
|
28
|
+
"homepage": "https://github.com/TuwaIO/orbit",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/TuwaIO/
|
|
30
|
+
"url": "https://github.com/TuwaIO/orbit/issues"
|
|
31
31
|
},
|
|
32
32
|
"contributors": [
|
|
33
33
|
{
|
|
@@ -35,13 +35,9 @@
|
|
|
35
35
|
"url": "https://github.com/Argeare5"
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"zustand": "^5.0.8"
|
|
40
|
-
},
|
|
41
38
|
"devDependencies": {
|
|
42
39
|
"tsup": "^8.5.0",
|
|
43
|
-
"typescript": "^5.9.
|
|
44
|
-
"zustand": "^5.0.8"
|
|
40
|
+
"typescript": "^5.9.3"
|
|
45
41
|
},
|
|
46
42
|
"scripts": {
|
|
47
43
|
"start": "tsup src/index.ts --watch",
|