@tuwaio/orbit-core 0.3.1 → 0.4.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 +13 -0
- package/dist/index.d.mts +72 -15
- package/dist/index.d.ts +72 -15
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ The package has **zero runtime dependencies** and imports no Web3 SDK, so it run
|
|
|
13
13
|
|
|
14
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
15
|
- **Connector helpers:** `getConnectorTypeFromName`, `getAdapterFromConnectorType`, `formatConnectorName`, `formatConnectorChainId`, `isSolanaChain`, `setChainId` and `getNetworkData`.
|
|
16
|
+
- **Solana chain IDs:** `SOLANA_CHAIN_IDS` holds the CAIP-2 chain IDs of mainnet, devnet and testnet, made of the genesis hash as CAIP-30 requires. `getSolanaChainId` and `getSolanaCluster` convert between these IDs and cluster monikers and read every form in use (`devnet`, `solana:devnet`, `solana:mainnet-beta`, the testnet ID from before the testnet genesis reset). `setChainId` and `formatConnectorChainId` return these IDs for Solana.
|
|
16
17
|
- **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
18
|
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage` and do nothing during SSR.
|
|
18
19
|
- **Runtime utilities:** `detectSafeApp` (Safe{Wallet} iframe detection), `waitFor`, `delay`, `filterUniqueByKey`, and `impersonatedHelpers` for development and testing.
|
|
@@ -64,6 +65,18 @@ lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
|
64
65
|
const lastConnected = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
65
66
|
```
|
|
66
67
|
|
|
68
|
+
### Identifying Solana clusters
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { getSolanaChainId, getSolanaCluster } from '@tuwaio/orbit-core';
|
|
72
|
+
|
|
73
|
+
getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
74
|
+
getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
75
|
+
getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Use the CAIP-2 ID wherever a chain is identified: SIWX messages, transaction records, APIs. Use the cluster moniker for RPC URLs and for Wallet Standard calls, which name the cluster `solana:devnet`.
|
|
79
|
+
|
|
67
80
|
### Normalizing errors
|
|
68
81
|
|
|
69
82
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -120,7 +120,7 @@ type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
122
122
|
* ```typescript
|
|
123
|
-
* const chainIds: ChainIdentifierArray = ['ethereum', 1, 'solana:
|
|
123
|
+
* const chainIds: ChainIdentifierArray = ['ethereum', 1, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'];
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
126
126
|
type ChainIdentifierArray = readonly (string | number)[];
|
|
@@ -134,18 +134,21 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* Checks whether the given chain ID belongs to a Solana network
|
|
138
|
-
*
|
|
137
|
+
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
138
|
+
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
139
|
+
* genesis hash. See {@link getSolanaCluster}.
|
|
139
140
|
*
|
|
140
|
-
* @param
|
|
141
|
-
* @returns
|
|
141
|
+
* @param chainId - The chain ID or chain name.
|
|
142
|
+
* @returns `true` if the chain ID corresponds to a known Solana network, `false` otherwise.
|
|
142
143
|
*/
|
|
143
144
|
declare function isSolanaChain(chainId: number | string): boolean;
|
|
144
145
|
/**
|
|
145
|
-
*
|
|
146
|
+
* Turns a Solana chain, in any form accepted by {@link isSolanaChain}, into its CAIP-2 chain ID with the genesis hash
|
|
147
|
+
* (see {@link getSolanaChainId}): `devnet` and `solana:devnet` become `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`. Other
|
|
148
|
+
* chain IDs are returned unchanged.
|
|
146
149
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
150
|
+
* @param chainId - The original chain ID or name.
|
|
151
|
+
* @returns The CAIP-2 chain ID for Solana networks, otherwise the original value.
|
|
149
152
|
*/
|
|
150
153
|
declare function setChainId(chainId: number | string): string | number;
|
|
151
154
|
|
|
@@ -194,17 +197,19 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
194
197
|
|
|
195
198
|
/**
|
|
196
199
|
* Formats a chain ID for use in connector identifiers.
|
|
197
|
-
*
|
|
200
|
+
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
201
|
+
* IDs are prefixed with the adapter key unless they already have it; numeric EVM chain IDs are kept as is.
|
|
198
202
|
*
|
|
199
203
|
* @example
|
|
200
204
|
* ```typescript
|
|
201
|
-
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:
|
|
205
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
202
206
|
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
207
|
* ```
|
|
204
208
|
*
|
|
205
209
|
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
210
|
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
-
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise
|
|
211
|
+
* @returns The CAIP-2 chain ID for known Solana clusters, `"<adapter>:<chainId>"` for other string chain IDs, otherwise
|
|
212
|
+
* the numeric chain ID unchanged.
|
|
208
213
|
*/
|
|
209
214
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
210
215
|
|
|
@@ -282,8 +287,9 @@ declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string):
|
|
|
282
287
|
* "What is a wallet?" section in a connect modal.
|
|
283
288
|
*
|
|
284
289
|
* @param adapter - The adapter to describe.
|
|
285
|
-
* @returns Default chain (`chainId
|
|
286
|
-
* or `undefined` for adapters without network data (e.g.
|
|
290
|
+
* @returns Default chain (`chainId`: `1` for EVM, {@link SOLANA_CHAIN_IDS}`.mainnet` for Solana; `name`) and `links`
|
|
291
|
+
* (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana, or `undefined` for adapters without network data (e.g.
|
|
292
|
+
* Starknet).
|
|
287
293
|
*/
|
|
288
294
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
289
295
|
chain: {
|
|
@@ -297,7 +303,7 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
297
303
|
};
|
|
298
304
|
} | {
|
|
299
305
|
chain: {
|
|
300
|
-
chainId:
|
|
306
|
+
chainId: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
301
307
|
name: string;
|
|
302
308
|
};
|
|
303
309
|
links: {
|
|
@@ -746,6 +752,57 @@ declare const selectAdapterByKey: <A extends {
|
|
|
746
752
|
adapterKey: OrbitAdapter;
|
|
747
753
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
748
754
|
|
|
755
|
+
/**
|
|
756
|
+
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
757
|
+
* genesis hash of the cluster.
|
|
758
|
+
*
|
|
759
|
+
* Wallet Standard wallets name the same clusters `solana:mainnet`, `solana:devnet` and `solana:testnet`: pass those to
|
|
760
|
+
* wallet calls, and these IDs everywhere a chain is identified (sessions, transactions, APIs).
|
|
761
|
+
*/
|
|
762
|
+
declare const SOLANA_CHAIN_IDS: {
|
|
763
|
+
readonly mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
764
|
+
readonly devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
765
|
+
readonly testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
766
|
+
};
|
|
767
|
+
/**
|
|
768
|
+
* A Solana cluster moniker recognized by {@link getSolanaCluster}.
|
|
769
|
+
*/
|
|
770
|
+
type SolanaCluster = keyof typeof SOLANA_CHAIN_IDS | 'localnet';
|
|
771
|
+
/**
|
|
772
|
+
* Returns the cluster of a Solana chain identifier, in any of its forms: a cluster moniker (`devnet`, `mainnet-beta`),
|
|
773
|
+
* a Wallet Standard chain (`solana:devnet`), a CAIP-2 chain ID with the genesis hash
|
|
774
|
+
* (`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`) or its bare reference. `mainnet-beta` is reported as `mainnet`; the
|
|
775
|
+
* testnet ID from before the testnet genesis reset (`solana:4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR`) as `testnet`.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```typescript
|
|
779
|
+
* getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
780
|
+
* getSolanaCluster('solana:mainnet-beta'); // "mainnet"
|
|
781
|
+
* getSolanaCluster(1); // undefined
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* @param chainId - Chain identifier to read. Monikers are case-sensitive, as in the Wallet Standard.
|
|
785
|
+
* @returns `mainnet`, `devnet`, `testnet` or `localnet`, or `undefined` when the value is not a known Solana chain
|
|
786
|
+
* (numbers, other namespaces, custom clusters).
|
|
787
|
+
*/
|
|
788
|
+
declare function getSolanaCluster(chainId: string | number): SolanaCluster | undefined;
|
|
789
|
+
/**
|
|
790
|
+
* Returns the CAIP-2 chain ID of a Solana chain identifier in any form accepted by {@link getSolanaCluster}: the
|
|
791
|
+
* genesis-hash ID from {@link SOLANA_CHAIN_IDS} for the public clusters, and `solana:localnet` for `localnet`, which
|
|
792
|
+
* has no fixed genesis hash.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
797
|
+
* getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
798
|
+
* getSolanaChainId('eip155:1'); // undefined
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @param chainId - Chain identifier to convert.
|
|
802
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value is not a known Solana chain.
|
|
803
|
+
*/
|
|
804
|
+
declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
805
|
+
|
|
749
806
|
/**
|
|
750
807
|
* Polls a predicate until it returns a truthy value.
|
|
751
808
|
*
|
|
@@ -763,4 +820,4 @@ declare const selectAdapterByKey: <A extends {
|
|
|
763
820
|
*/
|
|
764
821
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
765
822
|
|
|
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 };
|
|
823
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, SOLANA_CHAIN_IDS, type SolanaCluster, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
122
122
|
* ```typescript
|
|
123
|
-
* const chainIds: ChainIdentifierArray = ['ethereum', 1, 'solana:
|
|
123
|
+
* const chainIds: ChainIdentifierArray = ['ethereum', 1, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'];
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
126
126
|
type ChainIdentifierArray = readonly (string | number)[];
|
|
@@ -134,18 +134,21 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* Checks whether the given chain ID belongs to a Solana network
|
|
138
|
-
*
|
|
137
|
+
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
138
|
+
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
139
|
+
* genesis hash. See {@link getSolanaCluster}.
|
|
139
140
|
*
|
|
140
|
-
* @param
|
|
141
|
-
* @returns
|
|
141
|
+
* @param chainId - The chain ID or chain name.
|
|
142
|
+
* @returns `true` if the chain ID corresponds to a known Solana network, `false` otherwise.
|
|
142
143
|
*/
|
|
143
144
|
declare function isSolanaChain(chainId: number | string): boolean;
|
|
144
145
|
/**
|
|
145
|
-
*
|
|
146
|
+
* Turns a Solana chain, in any form accepted by {@link isSolanaChain}, into its CAIP-2 chain ID with the genesis hash
|
|
147
|
+
* (see {@link getSolanaChainId}): `devnet` and `solana:devnet` become `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`. Other
|
|
148
|
+
* chain IDs are returned unchanged.
|
|
146
149
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
150
|
+
* @param chainId - The original chain ID or name.
|
|
151
|
+
* @returns The CAIP-2 chain ID for Solana networks, otherwise the original value.
|
|
149
152
|
*/
|
|
150
153
|
declare function setChainId(chainId: number | string): string | number;
|
|
151
154
|
|
|
@@ -194,17 +197,19 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
194
197
|
|
|
195
198
|
/**
|
|
196
199
|
* Formats a chain ID for use in connector identifiers.
|
|
197
|
-
*
|
|
200
|
+
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
201
|
+
* IDs are prefixed with the adapter key unless they already have it; numeric EVM chain IDs are kept as is.
|
|
198
202
|
*
|
|
199
203
|
* @example
|
|
200
204
|
* ```typescript
|
|
201
|
-
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:
|
|
205
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
202
206
|
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
207
|
* ```
|
|
204
208
|
*
|
|
205
209
|
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
210
|
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
-
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise
|
|
211
|
+
* @returns The CAIP-2 chain ID for known Solana clusters, `"<adapter>:<chainId>"` for other string chain IDs, otherwise
|
|
212
|
+
* the numeric chain ID unchanged.
|
|
208
213
|
*/
|
|
209
214
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
210
215
|
|
|
@@ -282,8 +287,9 @@ declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string):
|
|
|
282
287
|
* "What is a wallet?" section in a connect modal.
|
|
283
288
|
*
|
|
284
289
|
* @param adapter - The adapter to describe.
|
|
285
|
-
* @returns Default chain (`chainId
|
|
286
|
-
* or `undefined` for adapters without network data (e.g.
|
|
290
|
+
* @returns Default chain (`chainId`: `1` for EVM, {@link SOLANA_CHAIN_IDS}`.mainnet` for Solana; `name`) and `links`
|
|
291
|
+
* (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana, or `undefined` for adapters without network data (e.g.
|
|
292
|
+
* Starknet).
|
|
287
293
|
*/
|
|
288
294
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
289
295
|
chain: {
|
|
@@ -297,7 +303,7 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
297
303
|
};
|
|
298
304
|
} | {
|
|
299
305
|
chain: {
|
|
300
|
-
chainId:
|
|
306
|
+
chainId: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
301
307
|
name: string;
|
|
302
308
|
};
|
|
303
309
|
links: {
|
|
@@ -746,6 +752,57 @@ declare const selectAdapterByKey: <A extends {
|
|
|
746
752
|
adapterKey: OrbitAdapter;
|
|
747
753
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
748
754
|
|
|
755
|
+
/**
|
|
756
|
+
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
757
|
+
* genesis hash of the cluster.
|
|
758
|
+
*
|
|
759
|
+
* Wallet Standard wallets name the same clusters `solana:mainnet`, `solana:devnet` and `solana:testnet`: pass those to
|
|
760
|
+
* wallet calls, and these IDs everywhere a chain is identified (sessions, transactions, APIs).
|
|
761
|
+
*/
|
|
762
|
+
declare const SOLANA_CHAIN_IDS: {
|
|
763
|
+
readonly mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
764
|
+
readonly devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
765
|
+
readonly testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
766
|
+
};
|
|
767
|
+
/**
|
|
768
|
+
* A Solana cluster moniker recognized by {@link getSolanaCluster}.
|
|
769
|
+
*/
|
|
770
|
+
type SolanaCluster = keyof typeof SOLANA_CHAIN_IDS | 'localnet';
|
|
771
|
+
/**
|
|
772
|
+
* Returns the cluster of a Solana chain identifier, in any of its forms: a cluster moniker (`devnet`, `mainnet-beta`),
|
|
773
|
+
* a Wallet Standard chain (`solana:devnet`), a CAIP-2 chain ID with the genesis hash
|
|
774
|
+
* (`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`) or its bare reference. `mainnet-beta` is reported as `mainnet`; the
|
|
775
|
+
* testnet ID from before the testnet genesis reset (`solana:4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR`) as `testnet`.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```typescript
|
|
779
|
+
* getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
780
|
+
* getSolanaCluster('solana:mainnet-beta'); // "mainnet"
|
|
781
|
+
* getSolanaCluster(1); // undefined
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* @param chainId - Chain identifier to read. Monikers are case-sensitive, as in the Wallet Standard.
|
|
785
|
+
* @returns `mainnet`, `devnet`, `testnet` or `localnet`, or `undefined` when the value is not a known Solana chain
|
|
786
|
+
* (numbers, other namespaces, custom clusters).
|
|
787
|
+
*/
|
|
788
|
+
declare function getSolanaCluster(chainId: string | number): SolanaCluster | undefined;
|
|
789
|
+
/**
|
|
790
|
+
* Returns the CAIP-2 chain ID of a Solana chain identifier in any form accepted by {@link getSolanaCluster}: the
|
|
791
|
+
* genesis-hash ID from {@link SOLANA_CHAIN_IDS} for the public clusters, and `solana:localnet` for `localnet`, which
|
|
792
|
+
* has no fixed genesis hash.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
797
|
+
* getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
798
|
+
* getSolanaChainId('eip155:1'); // undefined
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @param chainId - Chain identifier to convert.
|
|
802
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value is not a known Solana chain.
|
|
803
|
+
*/
|
|
804
|
+
declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
805
|
+
|
|
749
806
|
/**
|
|
750
807
|
* Polls a predicate until it returns a truthy value.
|
|
751
808
|
*
|
|
@@ -763,4 +820,4 @@ declare const selectAdapterByKey: <A extends {
|
|
|
763
820
|
*/
|
|
764
821
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
765
822
|
|
|
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 };
|
|
823
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, SOLANA_CHAIN_IDS, type SolanaCluster, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, 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
|
|
2
|
-
exports.OrbitAdapter=c;exports.delay=
|
|
1
|
+
'use strict';var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function m(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function g(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function x(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return m(t);case "solana":return g(t);default:return m(t)||g(t)}}var u={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},f="solana:",w={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function l(e){if(typeof e!="string")return;let n=e.startsWith(f)?e.slice(f.length):e;return Object.hasOwn(w,n)?w[n]:void 0}function d(e){let n=l(e);if(n)return n==="localnet"?`${f}localnet`:u[n]}function O(e){return l(e)!==void 0}function L(e){return d(e)??e}var N=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function K(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function P(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=d(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var C=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"]]),j=e=>C.get(e)??e.replace(/\s+/g,"").toLowerCase();function F(e){return e?.split(":")[0]??"evm"}function $(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var B=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:u.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 Q={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 ee(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 S=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",ne=S;var p={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(p.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(p.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(p.STORAGE_KEY):void 0};var A=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function R(){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 b(e){let n={};if(e&&typeof e=="object"){for(let t of A)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function y(e){try{let n=R(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function se(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=b(e),o=y(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:{...y(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 de=({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 ue(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")}
|
|
2
|
+
exports.OrbitAdapter=c;exports.SOLANA_CHAIN_IDS=u;exports.delay=N;exports.detectSafeApp=ee;exports.filterUniqueByKey=K;exports.formatConnectorChainId=P;exports.formatConnectorName=j;exports.getAdapterFromConnectorType=F;exports.getConnectorTypeFromName=$;exports.getNetworkData=B;exports.getParsedStorageItem=a;exports.getSolanaChainId=d;exports.getSolanaCluster=l;exports.impersonatedHelpers=Q;exports.isAddress=x;exports.isInSecureIframe=S;exports.isSafeApp=ne;exports.isSolanaChain=O;exports.lastConnectedConnectorHelpers=p;exports.normalizeError=se;exports.recentlyConnectedConnectorsListHelpers=r;exports.selectAdapterByKey=de;exports.setChainId=L;exports.waitFor=ue;
|
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
|
|
2
|
-
export{c as OrbitAdapter,
|
|
1
|
+
var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function m(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function g(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function x(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return m(t);case "solana":return g(t);default:return m(t)||g(t)}}var u={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},f="solana:",w={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function l(e){if(typeof e!="string")return;let n=e.startsWith(f)?e.slice(f.length):e;return Object.hasOwn(w,n)?w[n]:void 0}function d(e){let n=l(e);if(n)return n==="localnet"?`${f}localnet`:u[n]}function O(e){return l(e)!==void 0}function L(e){return d(e)??e}var N=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function K(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function P(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=d(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var C=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"]]),j=e=>C.get(e)??e.replace(/\s+/g,"").toLowerCase();function F(e){return e?.split(":")[0]??"evm"}function $(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var B=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:u.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 Q={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 ee(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 S=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",ne=S;var p={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(p.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(p.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(p.STORAGE_KEY):void 0};var A=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function R(){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 b(e){let n={};if(e&&typeof e=="object"){for(let t of A)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function y(e){try{let n=R(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function se(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=b(e),o=y(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:{...y(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 de=({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 ue(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")}
|
|
2
|
+
export{c as OrbitAdapter,u as SOLANA_CHAIN_IDS,N as delay,ee as detectSafeApp,K as filterUniqueByKey,P as formatConnectorChainId,j as formatConnectorName,F as getAdapterFromConnectorType,$ as getConnectorTypeFromName,B as getNetworkData,a as getParsedStorageItem,d as getSolanaChainId,l as getSolanaCluster,Q as impersonatedHelpers,x as isAddress,S as isInSecureIframe,ne as isSafeApp,O as isSolanaChain,p as lastConnectedConnectorHelpers,se as normalizeError,r as recentlyConnectedConnectorsListHelpers,de as selectAdapterByKey,L as setChainId,ue as waitFor};
|