@tuwaio/orbit-core 0.3.0 → 0.3.1
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 +63 -44
- package/dist/index.d.mts +75 -6
- package/dist/index.d.ts +75 -6
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
# @tuwaio/orbit-core
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@tuwaio/orbit-core)
|
|
4
|
-
[](
|
|
4
|
+
[](https://github.com/TuwaIO/orbit/blob/main/packages/orbit-core/LICENSE)
|
|
5
5
|
|
|
6
|
-
`@tuwaio/orbit-core` is the Layer 1 (L1)
|
|
6
|
+
`@tuwaio/orbit-core` is the Layer 1 (L1) package of **Orbit Utils**, the Stage 1 primitives layer of the TUWA ecosystem. It defines the chain-agnostic types that the Orbit chain packages and the higher TUWA layers (Satellite Connect, Pulsar) share, and ships small helpers for connector naming, address validation, error normalization and SSR-safe connection persistence.
|
|
7
|
+
|
|
8
|
+
The package has **zero runtime dependencies** and imports no Web3 SDK, so it runs in any framework, in the browser and on the server.
|
|
7
9
|
|
|
8
10
|
---
|
|
9
11
|
|
|
10
12
|
## 🏛️ Core Capabilities
|
|
11
13
|
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
14
|
+
- **Multi-chain primitives:** the `OrbitAdapter` enum (`evm`, `solana`, `starknet`), the `BaseAdapter` contract, `ConnectorType` identifiers such as `"evm:metamask"` or `"solana:phantom"`, and `selectAdapterByKey` to pick the adapter of the active chain.
|
|
15
|
+
- **Connector helpers:** `getConnectorTypeFromName`, `getAdapterFromConnectorType`, `formatConnectorName`, `formatConnectorChainId`, `isSolanaChain`, `setChainId` and `getNetworkData`.
|
|
16
|
+
- **Validation and errors:** `isAddress` validates EVM (hex) and Solana (Base58) addresses. `normalizeError` turns any wallet, viem or RPC error into a JSON-serializable `TuwaErrorState` that is safe to persist.
|
|
17
|
+
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage` and do nothing during SSR.
|
|
18
|
+
- **Runtime utilities:** `detectSafeApp` (Safe{Wallet} iframe detection), `waitFor`, `delay`, `filterUniqueByKey`, and `impersonatedHelpers` for development and testing.
|
|
16
19
|
|
|
17
20
|
---
|
|
18
21
|
|
|
@@ -24,71 +27,87 @@ pnpm add @tuwaio/orbit-core
|
|
|
24
27
|
|
|
25
28
|
---
|
|
26
29
|
|
|
27
|
-
## 🚀
|
|
30
|
+
## 🚀 Usage
|
|
28
31
|
|
|
29
|
-
###
|
|
32
|
+
### Resolving the active adapter
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
`BaseAdapter` describes what an adapter can do; add a `key` to register it for a chain family:
|
|
32
35
|
|
|
33
36
|
```typescript
|
|
34
|
-
import { OrbitAdapter, selectAdapterByKey
|
|
35
|
-
|
|
36
|
-
// Configure primitive adapter mapping
|
|
37
|
-
const adapters: BaseAdapter[] = [
|
|
38
|
-
{
|
|
39
|
-
key: OrbitAdapter.EVM,
|
|
40
|
-
getExplorerUrl: (url) => `https://etherscan.io/${url}`,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
key: OrbitAdapter.SOLANA,
|
|
44
|
-
getExplorerUrl: (url, cluster) => `https://solscan.io/${url}?cluster=${cluster}`,
|
|
45
|
-
},
|
|
46
|
-
];
|
|
37
|
+
import { type BaseAdapter, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';
|
|
47
38
|
|
|
48
|
-
|
|
49
|
-
const activeAdapter = selectAdapterByKey({
|
|
50
|
-
adapterKey: OrbitAdapter.SOLANA,
|
|
51
|
-
adapter: adapters,
|
|
52
|
-
});
|
|
39
|
+
type ExplorerAdapter = BaseAdapter & { key: OrbitAdapter };
|
|
53
40
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
41
|
+
const adapters: ExplorerAdapter[] = [
|
|
42
|
+
{ key: OrbitAdapter.EVM, getExplorerUrl: (path) => `https://etherscan.io/${path ?? ''}` },
|
|
43
|
+
{ key: OrbitAdapter.SOLANA, getExplorerUrl: (path) => `https://explorer.solana.com/${path ?? ''}` },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const solanaAdapter = selectAdapterByKey({ adapterKey: OrbitAdapter.SOLANA, adapter: adapters });
|
|
47
|
+
solanaAdapter?.getExplorerUrl('tx/<signature>'); // "https://explorer.solana.com/tx/<signature>"
|
|
57
48
|
```
|
|
58
49
|
|
|
59
|
-
|
|
50
|
+
If no adapter matches the key, `selectAdapterByKey` falls back to the first adapter in the array and logs a warning.
|
|
60
51
|
|
|
61
|
-
|
|
52
|
+
### Persisting the last connection
|
|
62
53
|
|
|
63
54
|
```typescript
|
|
64
55
|
import { lastConnectedConnectorHelpers } from '@tuwaio/orbit-core';
|
|
65
56
|
|
|
66
|
-
// Persist metadata
|
|
67
57
|
lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
68
58
|
connectorType: 'evm:metamask',
|
|
69
59
|
chainId: 1,
|
|
70
|
-
address: '
|
|
60
|
+
address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
71
61
|
});
|
|
72
62
|
|
|
73
|
-
//
|
|
63
|
+
// Returns undefined on the server and when nothing is stored.
|
|
74
64
|
const lastConnected = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
75
|
-
console.log(lastConnected?.address); // "0x123..."
|
|
76
65
|
```
|
|
77
66
|
|
|
67
|
+
### Normalizing errors
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { normalizeError } from '@tuwaio/orbit-core';
|
|
71
|
+
|
|
72
|
+
declare function sendTransaction(): Promise<void>;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await sendTransaction();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// `message` prefers viem's `shortMessage`; `raw` is a JSON-safe copy of the error details.
|
|
78
|
+
const { message, raw } = normalizeError(error);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Validating addresses
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { isAddress } from '@tuwaio/orbit-core';
|
|
86
|
+
|
|
87
|
+
isAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'); // true (auto-detected as EVM)
|
|
88
|
+
isAddress('So11111111111111111111111111111111111111112', 'solana'); // true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`isAddress` checks the address format only (hex length or Base58 alphabet); it does not verify EVM checksums.
|
|
92
|
+
|
|
78
93
|
---
|
|
79
94
|
|
|
80
|
-
##
|
|
95
|
+
## 🗄️ Browser Storage
|
|
81
96
|
|
|
82
|
-
|
|
97
|
+
The storage helpers write the following `localStorage` keys. Clear them to reset the connection state of a user:
|
|
83
98
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
-
|
|
88
|
-
|
|
99
|
+
| Key | Written by |
|
|
100
|
+
| --------------------------------------------------- | ---------------------------------------- |
|
|
101
|
+
| `orbit-core:lastConnectedConnector` | `lastConnectedConnectorHelpers` |
|
|
102
|
+
| `orbit-core:recentlyConnectedConnectorsListHelpers` | `recentlyConnectedConnectorsListHelpers` |
|
|
103
|
+
| `satellite-connect:impersonatedAddress` | `impersonatedHelpers` |
|
|
89
104
|
|
|
90
105
|
---
|
|
91
106
|
|
|
107
|
+
## 📚 API Reference
|
|
108
|
+
|
|
109
|
+
Every export, with signatures and types generated from the source, is documented at **[orbit.docs.tuwa.io/packages/orbit-core](https://orbit.docs.tuwa.io/packages/orbit-core)**.
|
|
110
|
+
|
|
92
111
|
## 📄 License
|
|
93
112
|
|
|
94
|
-
Licensed under the **Apache-2.0 License**. See the [LICENSE](
|
|
113
|
+
Licensed under the **Apache-2.0 License**. See the [LICENSE](https://github.com/TuwaIO/orbit/blob/main/packages/orbit-core/LICENSE) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -48,8 +48,10 @@ declare enum OrbitAdapter {
|
|
|
48
48
|
* For the Starknet L2 network.
|
|
49
49
|
* Supports:
|
|
50
50
|
* - Starknet Mainnet
|
|
51
|
-
* -
|
|
51
|
+
* - Starknet Sepolia testnet
|
|
52
52
|
* - Other Starknet deployments
|
|
53
|
+
*
|
|
54
|
+
* Reserved for future use: no Orbit chain package implements Starknet yet.
|
|
53
55
|
*/
|
|
54
56
|
Starknet = "starknet"
|
|
55
57
|
}
|
|
@@ -90,6 +92,10 @@ type OrbitGenericAdapter<A extends {
|
|
|
90
92
|
}> = {
|
|
91
93
|
adapter: A | A[];
|
|
92
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Minimal contract shared by chain adapters: explorer links plus optional name-service lookups.
|
|
97
|
+
* Combine it with a `key: OrbitAdapter` property to register an adapter for {@link selectAdapterByKey}.
|
|
98
|
+
*/
|
|
93
99
|
type BaseAdapter = {
|
|
94
100
|
/**
|
|
95
101
|
* Generates blockchain explorer URL
|
|
@@ -144,8 +150,6 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
144
150
|
declare function setChainId(chainId: number | string): string | number;
|
|
145
151
|
|
|
146
152
|
/**
|
|
147
|
-
* @name delay
|
|
148
|
-
*
|
|
149
153
|
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
150
154
|
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
151
155
|
*
|
|
@@ -188,8 +192,36 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
188
192
|
*/
|
|
189
193
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
190
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Formats a chain ID for use in connector identifiers.
|
|
197
|
+
* String chain IDs (e.g. Solana cluster names) are prefixed with the adapter key; numeric EVM chain IDs are kept as is.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:devnet"
|
|
202
|
+
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
|
+
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
+
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise the numeric chain ID unchanged.
|
|
208
|
+
*/
|
|
191
209
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
192
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Normalizes a wallet connector display name into a stable identifier.
|
|
213
|
+
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
214
|
+
* any other name has its whitespace removed and is lowercased.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* formatConnectorName('Trust Wallet'); // "trust"
|
|
219
|
+
* formatConnectorName('Rabby Wallet'); // "rabbywallet"
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @param connectorName - Display name reported by the wallet connector.
|
|
223
|
+
* @returns The normalized connector identifier.
|
|
224
|
+
*/
|
|
193
225
|
declare const formatConnectorName: (connectorName: string) => string;
|
|
194
226
|
|
|
195
227
|
/**
|
|
@@ -245,6 +277,14 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
245
277
|
*/
|
|
246
278
|
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
247
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
282
|
+
* "What is a wallet?" section in a connect modal.
|
|
283
|
+
*
|
|
284
|
+
* @param adapter - The adapter to describe.
|
|
285
|
+
* @returns Default chain (`chainId`, `name`) and `links` (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana,
|
|
286
|
+
* or `undefined` for adapters without network data (e.g. Starknet).
|
|
287
|
+
*/
|
|
248
288
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
249
289
|
chain: {
|
|
250
290
|
chainId: number;
|
|
@@ -317,14 +357,22 @@ declare const impersonatedHelpers: {
|
|
|
317
357
|
* @returns The impersonated address or undefined if not set or in SSR context
|
|
318
358
|
*/
|
|
319
359
|
getImpersonated: () => string | null | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Removes the impersonated address from localStorage.
|
|
362
|
+
*
|
|
363
|
+
* @returns undefined in SSR context, void in browser
|
|
364
|
+
*/
|
|
320
365
|
removeImpersonated: () => void;
|
|
321
366
|
};
|
|
322
367
|
|
|
323
368
|
/**
|
|
324
369
|
* Checks if the current window is running inside a Safe App iframe
|
|
325
370
|
* by attempting postMessage communication with the parent window.
|
|
371
|
+
* Side effect: posts a `getSafeInfo` message to `window.parent` and listens for the reply until `timeout`.
|
|
326
372
|
*
|
|
327
|
-
* @
|
|
373
|
+
* @param timeout - How long to wait for the Safe response, in milliseconds. Defaults to 1000.
|
|
374
|
+
* @returns Promise that resolves to true if running inside Safe Wallet, false otherwise (also on the server,
|
|
375
|
+
* outside an iframe, or when not served over HTTPS)
|
|
328
376
|
*/
|
|
329
377
|
declare function detectSafeApp(timeout?: number): Promise<boolean>;
|
|
330
378
|
/**
|
|
@@ -338,9 +386,15 @@ declare const isInSecureIframe: boolean;
|
|
|
338
386
|
*/
|
|
339
387
|
declare const isSafeApp: boolean;
|
|
340
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
391
|
+
*/
|
|
341
392
|
type LastConnectedConnector = {
|
|
393
|
+
/** Connector identifier, e.g. "evm:metamask". */
|
|
342
394
|
connectorType: ConnectorType;
|
|
395
|
+
/** Chain the wallet was connected to (numeric EVM chain ID or Solana chain identifier). */
|
|
343
396
|
chainId: number | string;
|
|
397
|
+
/** Connected wallet address, if known. */
|
|
344
398
|
address?: string;
|
|
345
399
|
};
|
|
346
400
|
/**
|
|
@@ -360,7 +414,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
360
414
|
/**
|
|
361
415
|
* Stores the last connected wallet data in localStorage.
|
|
362
416
|
*
|
|
363
|
-
* @param data -
|
|
417
|
+
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
364
418
|
* @returns undefined in SSR context, void in browser
|
|
365
419
|
*/
|
|
366
420
|
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
@@ -692,6 +746,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
692
746
|
adapterKey: OrbitAdapter;
|
|
693
747
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
694
748
|
|
|
749
|
+
/**
|
|
750
|
+
* Polls a predicate until it returns a truthy value.
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* ```typescript
|
|
754
|
+
* // Wait up to 10 seconds (50 × 200 ms) for an injected provider.
|
|
755
|
+
* await waitFor(() => typeof window !== 'undefined' && 'ethereum' in window);
|
|
756
|
+
* ```
|
|
757
|
+
*
|
|
758
|
+
* @param predicate - Condition to check on every attempt.
|
|
759
|
+
* @param maxChecks - Maximum number of attempts. Defaults to 50.
|
|
760
|
+
* @param checkIntervalMs - Delay between attempts in milliseconds. Defaults to 200.
|
|
761
|
+
* @returns A promise that resolves as soon as the predicate is truthy.
|
|
762
|
+
* @throws {Error} "Predicate not fulfilled in time" if the predicate is still falsy after `maxChecks` attempts.
|
|
763
|
+
*/
|
|
695
764
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
696
765
|
|
|
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 };
|
|
766
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, 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
|
@@ -48,8 +48,10 @@ declare enum OrbitAdapter {
|
|
|
48
48
|
* For the Starknet L2 network.
|
|
49
49
|
* Supports:
|
|
50
50
|
* - Starknet Mainnet
|
|
51
|
-
* -
|
|
51
|
+
* - Starknet Sepolia testnet
|
|
52
52
|
* - Other Starknet deployments
|
|
53
|
+
*
|
|
54
|
+
* Reserved for future use: no Orbit chain package implements Starknet yet.
|
|
53
55
|
*/
|
|
54
56
|
Starknet = "starknet"
|
|
55
57
|
}
|
|
@@ -90,6 +92,10 @@ type OrbitGenericAdapter<A extends {
|
|
|
90
92
|
}> = {
|
|
91
93
|
adapter: A | A[];
|
|
92
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Minimal contract shared by chain adapters: explorer links plus optional name-service lookups.
|
|
97
|
+
* Combine it with a `key: OrbitAdapter` property to register an adapter for {@link selectAdapterByKey}.
|
|
98
|
+
*/
|
|
93
99
|
type BaseAdapter = {
|
|
94
100
|
/**
|
|
95
101
|
* Generates blockchain explorer URL
|
|
@@ -144,8 +150,6 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
144
150
|
declare function setChainId(chainId: number | string): string | number;
|
|
145
151
|
|
|
146
152
|
/**
|
|
147
|
-
* @name delay
|
|
148
|
-
*
|
|
149
153
|
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
150
154
|
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
151
155
|
*
|
|
@@ -188,8 +192,36 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
188
192
|
*/
|
|
189
193
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
190
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Formats a chain ID for use in connector identifiers.
|
|
197
|
+
* String chain IDs (e.g. Solana cluster names) are prefixed with the adapter key; numeric EVM chain IDs are kept as is.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:devnet"
|
|
202
|
+
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
|
+
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
+
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise the numeric chain ID unchanged.
|
|
208
|
+
*/
|
|
191
209
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
192
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Normalizes a wallet connector display name into a stable identifier.
|
|
213
|
+
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
214
|
+
* any other name has its whitespace removed and is lowercased.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* formatConnectorName('Trust Wallet'); // "trust"
|
|
219
|
+
* formatConnectorName('Rabby Wallet'); // "rabbywallet"
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @param connectorName - Display name reported by the wallet connector.
|
|
223
|
+
* @returns The normalized connector identifier.
|
|
224
|
+
*/
|
|
193
225
|
declare const formatConnectorName: (connectorName: string) => string;
|
|
194
226
|
|
|
195
227
|
/**
|
|
@@ -245,6 +277,14 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
245
277
|
*/
|
|
246
278
|
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
247
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
282
|
+
* "What is a wallet?" section in a connect modal.
|
|
283
|
+
*
|
|
284
|
+
* @param adapter - The adapter to describe.
|
|
285
|
+
* @returns Default chain (`chainId`, `name`) and `links` (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana,
|
|
286
|
+
* or `undefined` for adapters without network data (e.g. Starknet).
|
|
287
|
+
*/
|
|
248
288
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
249
289
|
chain: {
|
|
250
290
|
chainId: number;
|
|
@@ -317,14 +357,22 @@ declare const impersonatedHelpers: {
|
|
|
317
357
|
* @returns The impersonated address or undefined if not set or in SSR context
|
|
318
358
|
*/
|
|
319
359
|
getImpersonated: () => string | null | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Removes the impersonated address from localStorage.
|
|
362
|
+
*
|
|
363
|
+
* @returns undefined in SSR context, void in browser
|
|
364
|
+
*/
|
|
320
365
|
removeImpersonated: () => void;
|
|
321
366
|
};
|
|
322
367
|
|
|
323
368
|
/**
|
|
324
369
|
* Checks if the current window is running inside a Safe App iframe
|
|
325
370
|
* by attempting postMessage communication with the parent window.
|
|
371
|
+
* Side effect: posts a `getSafeInfo` message to `window.parent` and listens for the reply until `timeout`.
|
|
326
372
|
*
|
|
327
|
-
* @
|
|
373
|
+
* @param timeout - How long to wait for the Safe response, in milliseconds. Defaults to 1000.
|
|
374
|
+
* @returns Promise that resolves to true if running inside Safe Wallet, false otherwise (also on the server,
|
|
375
|
+
* outside an iframe, or when not served over HTTPS)
|
|
328
376
|
*/
|
|
329
377
|
declare function detectSafeApp(timeout?: number): Promise<boolean>;
|
|
330
378
|
/**
|
|
@@ -338,9 +386,15 @@ declare const isInSecureIframe: boolean;
|
|
|
338
386
|
*/
|
|
339
387
|
declare const isSafeApp: boolean;
|
|
340
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
391
|
+
*/
|
|
341
392
|
type LastConnectedConnector = {
|
|
393
|
+
/** Connector identifier, e.g. "evm:metamask". */
|
|
342
394
|
connectorType: ConnectorType;
|
|
395
|
+
/** Chain the wallet was connected to (numeric EVM chain ID or Solana chain identifier). */
|
|
343
396
|
chainId: number | string;
|
|
397
|
+
/** Connected wallet address, if known. */
|
|
344
398
|
address?: string;
|
|
345
399
|
};
|
|
346
400
|
/**
|
|
@@ -360,7 +414,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
360
414
|
/**
|
|
361
415
|
* Stores the last connected wallet data in localStorage.
|
|
362
416
|
*
|
|
363
|
-
* @param data -
|
|
417
|
+
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
364
418
|
* @returns undefined in SSR context, void in browser
|
|
365
419
|
*/
|
|
366
420
|
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
@@ -692,6 +746,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
692
746
|
adapterKey: OrbitAdapter;
|
|
693
747
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
694
748
|
|
|
749
|
+
/**
|
|
750
|
+
* Polls a predicate until it returns a truthy value.
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* ```typescript
|
|
754
|
+
* // Wait up to 10 seconds (50 × 200 ms) for an injected provider.
|
|
755
|
+
* await waitFor(() => typeof window !== 'undefined' && 'ethereum' in window);
|
|
756
|
+
* ```
|
|
757
|
+
*
|
|
758
|
+
* @param predicate - Condition to check on every attempt.
|
|
759
|
+
* @param maxChecks - Maximum number of attempts. Defaults to 50.
|
|
760
|
+
* @param checkIntervalMs - Delay between attempts in milliseconds. Defaults to 200.
|
|
761
|
+
* @returns A promise that resolves as soon as the predicate is truthy.
|
|
762
|
+
* @throws {Error} "Predicate not fulfilled in time" if the predicate is still falsy after `maxChecks` attempts.
|
|
763
|
+
*/
|
|
695
764
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
696
765
|
|
|
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 };
|
|
766
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, 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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "L1 core of Orbit Utils (TUWA): zero-dependency, framework-agnostic multi-chain types, connector and address helpers, error normalization and SSR-safe connection persistence.",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -16,9 +16,14 @@
|
|
|
16
16
|
"socket.json"
|
|
17
17
|
],
|
|
18
18
|
"keywords": [
|
|
19
|
+
"tuwa",
|
|
20
|
+
"orbit",
|
|
19
21
|
"web3",
|
|
22
|
+
"multi-chain",
|
|
23
|
+
"evm",
|
|
24
|
+
"solana",
|
|
20
25
|
"typescript",
|
|
21
|
-
"
|
|
26
|
+
"framework-agnostic",
|
|
22
27
|
"headless"
|
|
23
28
|
],
|
|
24
29
|
"repository": {
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
],
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"tsup": "^8.5.1",
|
|
41
|
-
"typescript": "
|
|
46
|
+
"typescript": "6.0.3"
|
|
42
47
|
},
|
|
43
48
|
"scripts": {
|
|
44
49
|
"start": "tsup src/index.ts --watch",
|