@tuwaio/orbit-core 0.2.7 → 0.2.11
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 +47 -137
- package/dist/index.d.mts +31 -31
- package/dist/index.d.ts +31 -31
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,188 +1,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tuwaio/orbit-core
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@tuwaio/orbit-core)
|
|
4
4
|
[](./LICENSE)
|
|
5
|
-
[](https://github.com/TuwaIO/orbit/actions)
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
`@tuwaio/orbit-core` serves as the core logic and connector layer for the Orbit Utils ecosystem. It is completely **headless** and **framework-agnostic**, ensuring compatibility across React, Vue, Svelte, or vanilla JS applications. It abstracts the underlying blockchain architectures into a unified interface, simplifying state handling in complex multi-chain UIs.
|
|
8
7
|
|
|
9
8
|
---
|
|
10
9
|
|
|
11
|
-
## 🏛️
|
|
10
|
+
## 🏛️ Core Capabilities
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## ✨ Key Features
|
|
20
|
-
|
|
21
|
-
- **Multi-Chain Foundation:** Defines the core `OrbitAdapter` enum (supporting EVM, Solana, Starknet) and types for building consistent multi-chain support.
|
|
22
|
-
- **Framework Agnostic & Headless:** Contains only logic, no UI components, ensuring compatibility with any frontend setup.
|
|
23
|
-
- **Type-Safe Development:** Fully written in TypeScript 5.9+ for a robust developer experience.
|
|
24
|
-
- **Flexible Adapter System:** Provides utilities like `selectAdapterByKey` to easily manage and switch between different blockchain adapter implementations.
|
|
25
|
-
- **Essential Utilities:** Includes common helpers for tasks such as:
|
|
26
|
-
- Formatting connector names and chain IDs (`formatConnectorName`, `formatConnectorChainId`).
|
|
27
|
-
- Identifying chain types (`isSolanaChain`, `getAdapterFromConnectorType`).
|
|
28
|
-
- Managing connector connection state in localStorage (`lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`).
|
|
29
|
-
- Handling impersonation for development/testing (`impersonatedHelpers`).
|
|
30
|
-
- Basic async operations (`delay`, `waitFor`).
|
|
31
|
-
- **SSR Safe:** Utilities are designed to work safely in both browser and Server-Side Rendering environments.
|
|
12
|
+
- **Unified Multi-Chain Adapters:** Establishes the standard `BaseAdapter` interface and the `OrbitAdapter` enum (EVM, Solana, Starknet) to enable cross-chain UI layers.
|
|
13
|
+
- **Connection State Persistence:** Includes SSR-safe storage helpers (`lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`) to track and resume wallet connection history.
|
|
14
|
+
- **autonomy-focused Utilities:** Native handlers for formatting chain IDs, parsing connector names, and managing async task execution (`waitFor`, `delay`).
|
|
15
|
+
- **Impersonation Engine:** Built-in `impersonatedHelpers` to support testing and debugging in different account contexts.
|
|
32
16
|
|
|
33
17
|
---
|
|
34
18
|
|
|
35
19
|
## 💾 Installation
|
|
36
20
|
|
|
37
21
|
```bash
|
|
38
|
-
# Using pnpm (recommended), but you can use npm, yarn or bun as well
|
|
39
22
|
pnpm add @tuwaio/orbit-core
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*Note: `@tuwaio/orbit-core` provides the core logic. You will typically install chain-specific packages like `@tuwaio/orbit-evm` or `@tuwaio/orbit-solana` alongside it.*
|
|
23
|
+
```
|
|
43
24
|
|
|
44
|
-
|
|
25
|
+
---
|
|
45
26
|
|
|
46
27
|
## 🚀 Quick Start
|
|
47
28
|
|
|
48
|
-
###
|
|
29
|
+
### Runtime Adapter Selection
|
|
49
30
|
|
|
50
|
-
|
|
31
|
+
Configure chain adapters dynamically and retrieve them at runtime using standard selectors:
|
|
51
32
|
|
|
52
33
|
```typescript
|
|
53
34
|
import { OrbitAdapter, selectAdapterByKey, BaseAdapter } from '@tuwaio/orbit-core';
|
|
54
35
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
key: OrbitAdapter.EVM;
|
|
59
|
-
}
|
|
60
|
-
interface SolanaAdapter extends BaseAdapter {
|
|
61
|
-
key: OrbitAdapter.SOLANA;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const evmAdapterImpl: EvmAdapter = {
|
|
36
|
+
// Configure adapters (mocked here, use @tuwaio/orbit-evm / @tuwaio/orbit-solana in production)
|
|
37
|
+
const adapters: BaseAdapter[] = [
|
|
38
|
+
{
|
|
65
39
|
key: OrbitAdapter.EVM,
|
|
66
|
-
getExplorerUrl: (url
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const solanaAdapterImpl: SolanaAdapter = {
|
|
40
|
+
getExplorerUrl: (url) => `https://etherscan.io/${url}`,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
72
43
|
key: OrbitAdapter.SOLANA,
|
|
73
|
-
getExplorerUrl: (url,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const configuredAdapters = [evmAdapterImpl, solanaAdapterImpl];
|
|
80
|
-
|
|
81
|
-
// --- Selecting an Adapter ---
|
|
82
|
-
|
|
83
|
-
// Select the EVM adapter based on its key
|
|
84
|
-
const selectedEvmAdapter = selectAdapterByKey({
|
|
85
|
-
adapterKey: OrbitAdapter.EVM,
|
|
86
|
-
adapter: configuredAdapters,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (selectedEvmAdapter && selectedEvmAdapter.key === OrbitAdapter.EVM) {
|
|
90
|
-
console.log('Selected EVM Adapter Chain:', selectedEvmAdapter.getChainName()); // Output: Ethereum
|
|
91
|
-
} else {
|
|
92
|
-
console.error('EVM Adapter not found or configured.');
|
|
93
|
-
}
|
|
44
|
+
getExplorerUrl: (url, cluster) => `https://solscan.io/${url}?cluster=${cluster}`,
|
|
45
|
+
},
|
|
46
|
+
];
|
|
94
47
|
|
|
95
|
-
// Select
|
|
96
|
-
const
|
|
48
|
+
// Select adapter dynamically
|
|
49
|
+
const activeAdapter = selectAdapterByKey({
|
|
97
50
|
adapterKey: OrbitAdapter.SOLANA,
|
|
98
|
-
adapter:
|
|
51
|
+
adapter: adapters,
|
|
99
52
|
});
|
|
100
53
|
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
console.log('Explorer URL:', selectedSolanaAdapter.getExplorerUrl('tx/abc...', 'mainnet-beta')); // Output: [https://solscan.io/tx/abc...?cluster=mainnet-beta](https://solscan.io/tx/abc...?cluster=mainnet-beta)
|
|
104
|
-
} else {
|
|
105
|
-
console.error('Solana Adapter not found or configured.');
|
|
54
|
+
if (activeAdapter) {
|
|
55
|
+
console.log('Selected:', activeAdapter.getExplorerUrl('tx/0x...', 'mainnet-beta'));
|
|
106
56
|
}
|
|
107
57
|
```
|
|
108
58
|
|
|
109
|
-
###
|
|
59
|
+
### Connection State Persistence
|
|
60
|
+
|
|
61
|
+
Persist last connected connector state in localStorage safely:
|
|
110
62
|
|
|
111
63
|
```typescript
|
|
112
|
-
import {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
getAdapterFromConnectorType,
|
|
116
|
-
getConnectorTypeFromName,
|
|
117
|
-
isSolanaChain,
|
|
118
|
-
lastConnectedConnectorHelpers
|
|
119
|
-
} from '@tuwaio/orbit-core';
|
|
120
|
-
|
|
121
|
-
// Formatting
|
|
122
|
-
const formattedName = formatConnectorName('MetaMask'); // "metamask"
|
|
123
|
-
console.log(formattedName);
|
|
124
|
-
const connectorType = getConnectorTypeFromName(OrbitAdapter.EVM, 'Brave Wallet'); // "evm:bravewallet"
|
|
125
|
-
console.log(connectorType);
|
|
126
|
-
|
|
127
|
-
// Identification
|
|
128
|
-
const adapterType = getAdapterFromConnectorType(connectorType); // OrbitAdapter.EVM
|
|
129
|
-
console.log(adapterType);
|
|
130
|
-
console.log(isSolanaChain('devnet')); // true
|
|
131
|
-
console.log(isSolanaChain(1)); // false
|
|
132
|
-
|
|
133
|
-
// Local Storage Management for Last Connected Connector
|
|
64
|
+
import { lastConnectedConnectorHelpers } from '@tuwaio/orbit-core';
|
|
65
|
+
|
|
66
|
+
// Save connection metadata
|
|
134
67
|
lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
135
68
|
connectorType: 'evm:metamask',
|
|
136
69
|
chainId: 1,
|
|
137
|
-
address: '0x123...'
|
|
70
|
+
address: '0x123...',
|
|
138
71
|
});
|
|
139
|
-
const lastWallet = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
140
|
-
console.log(lastWallet); // { connectorType: 'evm:metamask', chainId: 1, address: '0x123...' }
|
|
141
72
|
|
|
142
|
-
//
|
|
73
|
+
// Retrieve connection metadata (returns null in SSR environment)
|
|
74
|
+
const lastConnected = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
75
|
+
console.log(lastConnected?.address); // "0x123..."
|
|
143
76
|
```
|
|
144
77
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## 🔧 Architecture
|
|
148
|
-
|
|
149
|
-
Orbit Core is designed around modularity and abstraction:
|
|
150
|
-
|
|
151
|
-
1. **Core Types (`types.ts`):** Defines fundamental structures like `OrbitAdapter` (enum for EVM, Solana, Starknet), `BaseAdapter` (common interface), and `ConnectorType`.
|
|
152
|
-
2. **Adapter System:** Enables handling multiple blockchain types via a common interface. The `selectAdapterByKey` utility allows runtime selection of the correct adapter implementation based on the `OrbitAdapter` key. Chain-specific logic resides in separate packages (e.g., `@tuwaio/orbit-evm`).
|
|
153
|
-
3. **Utilities (`utils/`):** A collection of framework-agnostic helper functions covering formatting, chain identification, localStorage management (for connection state persistence), async operations, and other common tasks needed when building multi-chain UIs.
|
|
154
|
-
|
|
155
|
-
### Key Exports (`index.ts`)
|
|
156
|
-
|
|
157
|
-
- **Types:** `OrbitAdapter`, `BaseAdapter`, `ConnectorType`, `OrbitGenericAdapter`, `RecentConnectedConnector`.
|
|
158
|
-
- **Adapter Utilities:** `selectAdapterByKey`, `getAdapterFromConnectorType`.
|
|
159
|
-
- **Formatting Utilities:** `formatConnectorChainId`, `formatConnectorName`, `getConnectorTypeFromName`.
|
|
160
|
-
- **Chain Helpers:** `isSolanaChain`, `setChainId`.
|
|
161
|
-
- **Storage Helpers:** `lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`, `impersonatedHelpers`, `getParsedStorageItem`.
|
|
162
|
-
- **General Utilities:** `delay`, `filterUniqueByKey`, `waitFor`, `isSafeApp`.
|
|
163
|
-
|
|
164
|
-
-----
|
|
165
|
-
|
|
166
|
-
## ✨ How It Connects to the Ecosystem
|
|
167
|
-
|
|
168
|
-
The Orbit Utils ecosystem is designed for modularity:
|
|
169
|
-
|
|
170
|
-
- **`@tuwaio/orbit-core`:** (This package) Provides the core, non-chain-specific types, utilities, and adapter structure.
|
|
171
|
-
- **`@tuwaio/orbit-evm`:** Contains the specific adapter implementation and helper functions for EVM-compatible chains (using libraries like `viem` and `@wagmi/core`).
|
|
172
|
-
- **`@tuwaio/orbit-solana`:** Contains the specific adapter implementation and helpers for the Solana blockchain (using libraries like `gill`).
|
|
78
|
+
---
|
|
173
79
|
|
|
174
|
-
|
|
80
|
+
## 🔧 API & Module Architecture
|
|
175
81
|
|
|
176
|
-
|
|
82
|
+
`@tuwaio/orbit-core` exports the following structures:
|
|
177
83
|
|
|
178
|
-
|
|
84
|
+
- **Core Types:** `OrbitAdapter`, `BaseAdapter`, `ConnectorType`, `RecentlyConnectedConnectorData`.
|
|
85
|
+
- **Registry Utilities:** `selectAdapterByKey`, `getAdapterFromConnectorType`, `getConnectorTypeFromName`.
|
|
86
|
+
- **Formatters:** `formatConnectorName`, `formatConnectorChainId`.
|
|
87
|
+
- **Storage Persisters:** `lastConnectedConnectorHelpers`, `recentConnectedConnectorHelpers`, `impersonatedHelpers`.
|
|
88
|
+
- **General Utilities:** `isSafeApp`, `delay`, `waitFor`, `filterUniqueByKey`.
|
|
179
89
|
|
|
180
|
-
|
|
90
|
+
---
|
|
181
91
|
|
|
182
|
-
|
|
92
|
+
## 🤝 Contributing
|
|
183
93
|
|
|
184
|
-
|
|
94
|
+
Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)** before submitting pull requests.
|
|
185
95
|
|
|
186
96
|
## 📄 License
|
|
187
97
|
|
|
188
|
-
|
|
98
|
+
Licensed under the **Apache-2.0 License**. See the [LICENSE](./LICENSE) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -362,6 +362,37 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
362
362
|
removeLastConnectedConnector: () => void;
|
|
363
363
|
};
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Persistence-safe error normalization for Web3 errors.
|
|
367
|
+
* Handles circular references, functions, and non-serializable properties.
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* Normalized error state that is safe for Zustand persistence.
|
|
371
|
+
* - `message`: User-friendly error message for display
|
|
372
|
+
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
373
|
+
*/
|
|
374
|
+
interface TuwaErrorState {
|
|
375
|
+
message: string;
|
|
376
|
+
raw: Record<string, unknown>;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
380
|
+
*
|
|
381
|
+
* @param error - Any error value (Error, string, object, etc.)
|
|
382
|
+
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* try {
|
|
387
|
+
* await sendTransaction();
|
|
388
|
+
* } catch (e) {
|
|
389
|
+
* const normalized = normalizeError(e);
|
|
390
|
+
* set({ error: normalized });
|
|
391
|
+
* }
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
395
|
+
|
|
365
396
|
/**
|
|
366
397
|
* Data structure for a recently connected connector
|
|
367
398
|
*
|
|
@@ -663,35 +694,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
663
694
|
*/
|
|
664
695
|
declare function setChainId(chainId: number | string): string | number;
|
|
665
696
|
|
|
666
|
-
/**
|
|
667
|
-
* Persistence-safe error normalization for Web3 errors.
|
|
668
|
-
* Handles circular references, functions, and non-serializable properties.
|
|
669
|
-
*/
|
|
670
|
-
/**
|
|
671
|
-
* Normalized error state that is safe for Zustand persistence.
|
|
672
|
-
* - `message`: User-friendly error message for display
|
|
673
|
-
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
674
|
-
*/
|
|
675
|
-
interface TuwaErrorState {
|
|
676
|
-
message: string;
|
|
677
|
-
raw: Record<string, unknown>;
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
681
|
-
*
|
|
682
|
-
* @param error - Any error value (Error, string, object, etc.)
|
|
683
|
-
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
684
|
-
*
|
|
685
|
-
* @example
|
|
686
|
-
* ```typescript
|
|
687
|
-
* try {
|
|
688
|
-
* await sendTransaction();
|
|
689
|
-
* } catch (e) {
|
|
690
|
-
* const normalized = normalizeError(e);
|
|
691
|
-
* set({ error: normalized });
|
|
692
|
-
* }
|
|
693
|
-
* ```
|
|
694
|
-
*/
|
|
695
|
-
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
696
|
-
|
|
697
697
|
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -362,6 +362,37 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
362
362
|
removeLastConnectedConnector: () => void;
|
|
363
363
|
};
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Persistence-safe error normalization for Web3 errors.
|
|
367
|
+
* Handles circular references, functions, and non-serializable properties.
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* Normalized error state that is safe for Zustand persistence.
|
|
371
|
+
* - `message`: User-friendly error message for display
|
|
372
|
+
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
373
|
+
*/
|
|
374
|
+
interface TuwaErrorState {
|
|
375
|
+
message: string;
|
|
376
|
+
raw: Record<string, unknown>;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
380
|
+
*
|
|
381
|
+
* @param error - Any error value (Error, string, object, etc.)
|
|
382
|
+
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* try {
|
|
387
|
+
* await sendTransaction();
|
|
388
|
+
* } catch (e) {
|
|
389
|
+
* const normalized = normalizeError(e);
|
|
390
|
+
* set({ error: normalized });
|
|
391
|
+
* }
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
395
|
+
|
|
365
396
|
/**
|
|
366
397
|
* Data structure for a recently connected connector
|
|
367
398
|
*
|
|
@@ -663,35 +694,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
663
694
|
*/
|
|
664
695
|
declare function setChainId(chainId: number | string): string | number;
|
|
665
696
|
|
|
666
|
-
/**
|
|
667
|
-
* Persistence-safe error normalization for Web3 errors.
|
|
668
|
-
* Handles circular references, functions, and non-serializable properties.
|
|
669
|
-
*/
|
|
670
|
-
/**
|
|
671
|
-
* Normalized error state that is safe for Zustand persistence.
|
|
672
|
-
* - `message`: User-friendly error message for display
|
|
673
|
-
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
674
|
-
*/
|
|
675
|
-
interface TuwaErrorState {
|
|
676
|
-
message: string;
|
|
677
|
-
raw: Record<string, unknown>;
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
681
|
-
*
|
|
682
|
-
* @param error - Any error value (Error, string, object, etc.)
|
|
683
|
-
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
684
|
-
*
|
|
685
|
-
* @example
|
|
686
|
-
* ```typescript
|
|
687
|
-
* try {
|
|
688
|
-
* await sendTransaction();
|
|
689
|
-
* } catch (e) {
|
|
690
|
-
* const normalized = normalizeError(e);
|
|
691
|
-
* set({ error: normalized });
|
|
692
|
-
* }
|
|
693
|
-
* ```
|
|
694
|
-
*/
|
|
695
|
-
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
696
|
-
|
|
697
697
|
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=e=>{switch(e){case "evm":return {chain:{chainId:1,name:"Ethereum"},links:{aboutNetwork:"https://ethereum.org/developers/docs/intro-to-ethereum/",choseWallet:"https://ethereum.org/wallets/find-wallet/",about:"https://ethereum.org/wallets/"}};case "solana":return {chain:{chainId:"solana:mainnet",name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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};async function v(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var
|
|
2
|
-
exports.OrbitAdapter=c;exports.delay=S;exports.detectSafeApp=v;exports.filterUniqueByKey=R;exports.formatConnectorChainId=h;exports.formatConnectorName=O;exports.getAdapterFromConnectorType=M;exports.getConnectorTypeFromName=G;exports.getNetworkData=j;exports.getParsedStorageItem=a;exports.impersonatedHelpers=F;exports.isAddress=A;exports.isInSecureIframe=m;exports.isSafeApp=D;exports.isSolanaChain=
|
|
1
|
+
'use strict';var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=e=>{switch(e){case "evm":return {chain:{chainId:1,name:"Ethereum"},links:{aboutNetwork:"https://ethereum.org/developers/docs/intro-to-ethereum/",choseWallet:"https://ethereum.org/wallets/find-wallet/",about:"https://ethereum.org/wallets/"}};case "solana":return {chain:{chainId:"solana:mainnet",name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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};async function v(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var g=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function w(){let e=new WeakSet;return (n,t)=>{if(t===null||typeof t!="object")return typeof t=="function"||typeof t=="symbol"?void 0:typeof t=="bigint"?t.toString():t;if(e.has(t))return "[Circular]";if(e.add(t),t instanceof Error){let o={name:t.name,message:t.message};t.stack&&(o.stack=t.stack);for(let s of Object.keys(t))s in o||(o[s]=t[s]);return o}return t}}function y(e){let n={};if(e&&typeof e=="object"){for(let t of g)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function p(e){try{let n=w(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function H(e){if(e==null)return {message:"Unknown error",raw:{originalType:"null"}};if(typeof e=="string")return {message:e,raw:{message:e,originalType:"string"}};if(e instanceof Error){let n=("shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:e.message)||"Unknown error",t=y(e),o=p(e);return {message:n,raw:{...o,...t,originalType:e.name||"Error"}}}return typeof e=="object"?{message:("message"in e&&typeof e.message=="string"?e.message:"shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:"Unknown error")||"Unknown error",raw:{...p(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var Z=({adapterKey:e,adapter:n})=>{if(Array.isArray(n)){if(n.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let t=n.find(o=>o.key===e);return t||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${n[0].key}".`),n[0])}return n};async function X(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(s=>setTimeout(s,t));}throw new Error("Predicate not fulfilled in time")}function C(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function ne(e){return C(e)?`solana:${e}`:e}
|
|
2
|
+
exports.OrbitAdapter=c;exports.delay=S;exports.detectSafeApp=v;exports.filterUniqueByKey=R;exports.formatConnectorChainId=h;exports.formatConnectorName=O;exports.getAdapterFromConnectorType=M;exports.getConnectorTypeFromName=G;exports.getNetworkData=j;exports.getParsedStorageItem=a;exports.impersonatedHelpers=F;exports.isAddress=A;exports.isInSecureIframe=m;exports.isSafeApp=D;exports.isSolanaChain=C;exports.lastConnectedConnectorHelpers=d;exports.normalizeError=H;exports.recentlyConnectedConnectorsListHelpers=r;exports.selectAdapterByKey=Z;exports.setChainId=ne;exports.waitFor=X;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=e=>{switch(e){case "evm":return {chain:{chainId:1,name:"Ethereum"},links:{aboutNetwork:"https://ethereum.org/developers/docs/intro-to-ethereum/",choseWallet:"https://ethereum.org/wallets/find-wallet/",about:"https://ethereum.org/wallets/"}};case "solana":return {chain:{chainId:"solana:mainnet",name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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};async function v(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var
|
|
2
|
-
export{c as OrbitAdapter,S as delay,v as detectSafeApp,R as filterUniqueByKey,h as formatConnectorChainId,O as formatConnectorName,M as getAdapterFromConnectorType,G as getConnectorTypeFromName,j as getNetworkData,a as getParsedStorageItem,F as impersonatedHelpers,A as isAddress,m as isInSecureIframe,D as isSafeApp,
|
|
1
|
+
var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=e=>{switch(e){case "evm":return {chain:{chainId:1,name:"Ethereum"},links:{aboutNetwork:"https://ethereum.org/developers/docs/intro-to-ethereum/",choseWallet:"https://ethereum.org/wallets/find-wallet/",about:"https://ethereum.org/wallets/"}};case "solana":return {chain:{chainId:"solana:mainnet",name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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};async function v(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var g=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function w(){let e=new WeakSet;return (n,t)=>{if(t===null||typeof t!="object")return typeof t=="function"||typeof t=="symbol"?void 0:typeof t=="bigint"?t.toString():t;if(e.has(t))return "[Circular]";if(e.add(t),t instanceof Error){let o={name:t.name,message:t.message};t.stack&&(o.stack=t.stack);for(let s of Object.keys(t))s in o||(o[s]=t[s]);return o}return t}}function y(e){let n={};if(e&&typeof e=="object"){for(let t of g)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function p(e){try{let n=w(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function H(e){if(e==null)return {message:"Unknown error",raw:{originalType:"null"}};if(typeof e=="string")return {message:e,raw:{message:e,originalType:"string"}};if(e instanceof Error){let n=("shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:e.message)||"Unknown error",t=y(e),o=p(e);return {message:n,raw:{...o,...t,originalType:e.name||"Error"}}}return typeof e=="object"?{message:("message"in e&&typeof e.message=="string"?e.message:"shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:"Unknown error")||"Unknown error",raw:{...p(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var Z=({adapterKey:e,adapter:n})=>{if(Array.isArray(n)){if(n.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let t=n.find(o=>o.key===e);return t||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${n[0].key}".`),n[0])}return n};async function X(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(s=>setTimeout(s,t));}throw new Error("Predicate not fulfilled in time")}function C(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function ne(e){return C(e)?`solana:${e}`:e}
|
|
2
|
+
export{c as OrbitAdapter,S as delay,v as detectSafeApp,R as filterUniqueByKey,h as formatConnectorChainId,O as formatConnectorName,M as getAdapterFromConnectorType,G as getConnectorTypeFromName,j as getNetworkData,a as getParsedStorageItem,F as impersonatedHelpers,A as isAddress,m as isInSecureIframe,D as isSafeApp,C as isSolanaChain,d as lastConnectedConnectorHelpers,H as normalizeError,r as recentlyConnectedConnectorsListHelpers,Z as selectAdapterByKey,ne as setChainId,X as waitFor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.5.1",
|
|
40
|
-
"typescript": "^
|
|
40
|
+
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"start": "tsup src/index.ts --watch",
|