@tuwaio/orbit-core 0.4.0 → 0.5.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 +1 -0
- package/dist/index.d.mts +132 -1
- package/dist/index.d.ts +132 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ The package has **zero runtime dependencies** and imports no Web3 SDK, so it run
|
|
|
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
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.
|
|
17
|
+
- **CAIP identifiers:** `toCaip2ChainId` turns EVM chain numbers into `eip155:<number>` and every Solana form into its genesis-hash ID, and `toEvmChainId` reads the number back; `formatCaip10AccountId` and `formatCaip19AssetId` build account and asset IDs (`eip155:8453/erc20:0x…`, `solana:…/token:…`, `…/slip44:501`), and the `parse…` functions read and validate them.
|
|
17
18
|
- **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.
|
|
18
19
|
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage` and do nothing during SSR.
|
|
19
20
|
- **Runtime utilities:** `detectSafeApp` (Safe{Wallet} iframe detection), `waitFor`, `delay`, `filterUniqueByKey`, and `impersonatedHelpers` for development and testing.
|
package/dist/index.d.mts
CHANGED
|
@@ -133,6 +133,137 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
133
|
*/
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
|
+
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
139
|
+
*/
|
|
140
|
+
type Caip2ChainId = `${string}:${string}`;
|
|
141
|
+
/** A CAIP-10 account ID: `<CAIP-2 chain ID>:<address>`, for example `eip155:1:0xab16…`. */
|
|
142
|
+
type Caip10AccountId = `${string}:${string}:${string}`;
|
|
143
|
+
/**
|
|
144
|
+
* A CAIP-19 asset type ID: `<CAIP-2 chain ID>/<asset namespace>:<asset reference>`, for example
|
|
145
|
+
* `eip155:8453/erc20:0x8335…` (an ERC-20 token), `solana:5eykt…/token:EPjF…` (an SPL token) or `eip155:1/slip44:60`
|
|
146
|
+
* (the native coin).
|
|
147
|
+
*/
|
|
148
|
+
type Caip19AssetId = `${string}:${string}/${string}:${string}`;
|
|
149
|
+
/**
|
|
150
|
+
* Splits a CAIP-2 chain ID into its namespace and reference, validating both against the CAIP-2 grammar.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* parseCaip2ChainId('eip155:8453'); // { namespace: 'eip155', reference: '8453' }
|
|
155
|
+
* parseCaip2ChainId('8453'); // undefined
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param chainId - The chain ID to parse.
|
|
159
|
+
* @returns The namespace and reference, or `undefined` when the value is not a CAIP-2 chain ID.
|
|
160
|
+
*/
|
|
161
|
+
declare function parseCaip2ChainId(chainId: string): {
|
|
162
|
+
namespace: string;
|
|
163
|
+
reference: string;
|
|
164
|
+
} | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Turns a chain identifier into a CAIP-2 chain ID: EVM chain numbers and their decimal strings become
|
|
167
|
+
* `eip155:<number>`, every Solana form accepted by {@link getSolanaChainId} becomes its genesis-hash ID, and a valid
|
|
168
|
+
* CAIP-2 chain ID is returned as it is.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* toCaip2ChainId(8453); // "eip155:8453"
|
|
173
|
+
* toCaip2ChainId('solana:devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
174
|
+
* toCaip2ChainId('base'); // undefined
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @param chainId - An EVM chain number, a Solana chain in any form, or a CAIP-2 chain ID.
|
|
178
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value cannot be read as one.
|
|
179
|
+
*/
|
|
180
|
+
declare function toCaip2ChainId(chainId: string | number): Caip2ChainId | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Reads the EVM chain number from an `eip155` CAIP-2 chain ID, a decimal string or a number: the reverse of
|
|
183
|
+
* {@link toCaip2ChainId} for EVM chains.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* toEvmChainId('eip155:8453'); // 8453
|
|
188
|
+
* toEvmChainId('8453'); // 8453
|
|
189
|
+
* toEvmChainId('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); // undefined
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @param chainId - An `eip155` CAIP-2 chain ID, an EVM chain number or its decimal string.
|
|
193
|
+
* @returns The chain number, or `undefined` when the value names no EVM chain or the number is not a safe integer.
|
|
194
|
+
*/
|
|
195
|
+
declare function toEvmChainId(chainId: string | number): number | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Builds a CAIP-10 account ID. The chain is normalized with {@link toCaip2ChainId}; the address is trimmed, checked
|
|
198
|
+
* against its chain (`0x` and 40 hex characters for EVM, base58 for Solana) and keeps its case.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* formatCaip10AccountId(8453, '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
203
|
+
* // "eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
204
|
+
* formatCaip10AccountId('devnet', '0x1234'); // undefined
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @param chainId - The chain, in any form accepted by {@link toCaip2ChainId}.
|
|
208
|
+
* @param address - The account address.
|
|
209
|
+
* @returns The CAIP-10 account ID, or `undefined` when the chain or the address is invalid.
|
|
210
|
+
*/
|
|
211
|
+
declare function formatCaip10AccountId(chainId: string | number, address: string): Caip10AccountId | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Splits a CAIP-10 account ID into its chain and address, validating both.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* parseCaip10AccountId('eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
218
|
+
* // { chainId: 'eip155:8453', namespace: 'eip155', reference: '8453', address: '0x8335…' }
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @param accountId - The CAIP-10 account ID to parse.
|
|
222
|
+
* @returns The chain ID, its namespace and reference, and the address, or `undefined` when the value is not a valid
|
|
223
|
+
* CAIP-10 account ID.
|
|
224
|
+
*/
|
|
225
|
+
declare function parseCaip10AccountId(accountId: string): {
|
|
226
|
+
chainId: Caip2ChainId;
|
|
227
|
+
namespace: string;
|
|
228
|
+
reference: string;
|
|
229
|
+
address: string;
|
|
230
|
+
} | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Builds a CAIP-19 asset type ID from a chain, an asset namespace (`erc20`, `token`, `slip44`, …) and an asset
|
|
233
|
+
* reference (a token contract, an SPL mint, a SLIP-44 coin type).
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* formatCaip19AssetId(8453, 'erc20', '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
238
|
+
* // "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
239
|
+
* formatCaip19AssetId('mainnet', 'slip44', '501'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @param chainId - The chain, in any form accepted by {@link toCaip2ChainId}.
|
|
243
|
+
* @param assetNamespace - The CAIP-19 asset namespace: 3–8 lowercase letters, digits or `-`.
|
|
244
|
+
* @param assetReference - The asset reference within that namespace.
|
|
245
|
+
* @returns The CAIP-19 asset type ID, or `undefined` when any part is invalid.
|
|
246
|
+
*/
|
|
247
|
+
declare function formatCaip19AssetId(chainId: string | number, assetNamespace: string, assetReference: string): Caip19AssetId | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Splits a CAIP-19 asset type ID into its chain, asset namespace and asset reference. IDs of single tokens
|
|
250
|
+
* (`eip155:1/erc721:0x…/1`) are not asset types and are rejected.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* parseCaip19AssetId('eip155:1/slip44:60'); // { chainId: 'eip155:1', assetNamespace: 'slip44', assetReference: '60' }
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @param assetId - The CAIP-19 asset type ID to parse.
|
|
258
|
+
* @returns The chain ID, asset namespace and asset reference, or `undefined` when the value is not a valid CAIP-19
|
|
259
|
+
* asset type ID.
|
|
260
|
+
*/
|
|
261
|
+
declare function parseCaip19AssetId(assetId: string): {
|
|
262
|
+
chainId: Caip2ChainId;
|
|
263
|
+
assetNamespace: string;
|
|
264
|
+
assetReference: string;
|
|
265
|
+
} | undefined;
|
|
266
|
+
|
|
136
267
|
/**
|
|
137
268
|
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
138
269
|
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
@@ -820,4 +951,4 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
820
951
|
*/
|
|
821
952
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
822
953
|
|
|
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 };
|
|
954
|
+
export { type BaseAdapter, type Caip10AccountId, type Caip19AssetId, type Caip2ChainId, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, SOLANA_CHAIN_IDS, type SolanaCluster, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatCaip10AccountId, formatCaip19AssetId, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, toCaip2ChainId, toEvmChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,137 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
133
|
*/
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
|
+
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
139
|
+
*/
|
|
140
|
+
type Caip2ChainId = `${string}:${string}`;
|
|
141
|
+
/** A CAIP-10 account ID: `<CAIP-2 chain ID>:<address>`, for example `eip155:1:0xab16…`. */
|
|
142
|
+
type Caip10AccountId = `${string}:${string}:${string}`;
|
|
143
|
+
/**
|
|
144
|
+
* A CAIP-19 asset type ID: `<CAIP-2 chain ID>/<asset namespace>:<asset reference>`, for example
|
|
145
|
+
* `eip155:8453/erc20:0x8335…` (an ERC-20 token), `solana:5eykt…/token:EPjF…` (an SPL token) or `eip155:1/slip44:60`
|
|
146
|
+
* (the native coin).
|
|
147
|
+
*/
|
|
148
|
+
type Caip19AssetId = `${string}:${string}/${string}:${string}`;
|
|
149
|
+
/**
|
|
150
|
+
* Splits a CAIP-2 chain ID into its namespace and reference, validating both against the CAIP-2 grammar.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* parseCaip2ChainId('eip155:8453'); // { namespace: 'eip155', reference: '8453' }
|
|
155
|
+
* parseCaip2ChainId('8453'); // undefined
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param chainId - The chain ID to parse.
|
|
159
|
+
* @returns The namespace and reference, or `undefined` when the value is not a CAIP-2 chain ID.
|
|
160
|
+
*/
|
|
161
|
+
declare function parseCaip2ChainId(chainId: string): {
|
|
162
|
+
namespace: string;
|
|
163
|
+
reference: string;
|
|
164
|
+
} | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Turns a chain identifier into a CAIP-2 chain ID: EVM chain numbers and their decimal strings become
|
|
167
|
+
* `eip155:<number>`, every Solana form accepted by {@link getSolanaChainId} becomes its genesis-hash ID, and a valid
|
|
168
|
+
* CAIP-2 chain ID is returned as it is.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* toCaip2ChainId(8453); // "eip155:8453"
|
|
173
|
+
* toCaip2ChainId('solana:devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
174
|
+
* toCaip2ChainId('base'); // undefined
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @param chainId - An EVM chain number, a Solana chain in any form, or a CAIP-2 chain ID.
|
|
178
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value cannot be read as one.
|
|
179
|
+
*/
|
|
180
|
+
declare function toCaip2ChainId(chainId: string | number): Caip2ChainId | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Reads the EVM chain number from an `eip155` CAIP-2 chain ID, a decimal string or a number: the reverse of
|
|
183
|
+
* {@link toCaip2ChainId} for EVM chains.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* toEvmChainId('eip155:8453'); // 8453
|
|
188
|
+
* toEvmChainId('8453'); // 8453
|
|
189
|
+
* toEvmChainId('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); // undefined
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @param chainId - An `eip155` CAIP-2 chain ID, an EVM chain number or its decimal string.
|
|
193
|
+
* @returns The chain number, or `undefined` when the value names no EVM chain or the number is not a safe integer.
|
|
194
|
+
*/
|
|
195
|
+
declare function toEvmChainId(chainId: string | number): number | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Builds a CAIP-10 account ID. The chain is normalized with {@link toCaip2ChainId}; the address is trimmed, checked
|
|
198
|
+
* against its chain (`0x` and 40 hex characters for EVM, base58 for Solana) and keeps its case.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* formatCaip10AccountId(8453, '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
203
|
+
* // "eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
204
|
+
* formatCaip10AccountId('devnet', '0x1234'); // undefined
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @param chainId - The chain, in any form accepted by {@link toCaip2ChainId}.
|
|
208
|
+
* @param address - The account address.
|
|
209
|
+
* @returns The CAIP-10 account ID, or `undefined` when the chain or the address is invalid.
|
|
210
|
+
*/
|
|
211
|
+
declare function formatCaip10AccountId(chainId: string | number, address: string): Caip10AccountId | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Splits a CAIP-10 account ID into its chain and address, validating both.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* parseCaip10AccountId('eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
218
|
+
* // { chainId: 'eip155:8453', namespace: 'eip155', reference: '8453', address: '0x8335…' }
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @param accountId - The CAIP-10 account ID to parse.
|
|
222
|
+
* @returns The chain ID, its namespace and reference, and the address, or `undefined` when the value is not a valid
|
|
223
|
+
* CAIP-10 account ID.
|
|
224
|
+
*/
|
|
225
|
+
declare function parseCaip10AccountId(accountId: string): {
|
|
226
|
+
chainId: Caip2ChainId;
|
|
227
|
+
namespace: string;
|
|
228
|
+
reference: string;
|
|
229
|
+
address: string;
|
|
230
|
+
} | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Builds a CAIP-19 asset type ID from a chain, an asset namespace (`erc20`, `token`, `slip44`, …) and an asset
|
|
233
|
+
* reference (a token contract, an SPL mint, a SLIP-44 coin type).
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* formatCaip19AssetId(8453, 'erc20', '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
238
|
+
* // "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
239
|
+
* formatCaip19AssetId('mainnet', 'slip44', '501'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @param chainId - The chain, in any form accepted by {@link toCaip2ChainId}.
|
|
243
|
+
* @param assetNamespace - The CAIP-19 asset namespace: 3–8 lowercase letters, digits or `-`.
|
|
244
|
+
* @param assetReference - The asset reference within that namespace.
|
|
245
|
+
* @returns The CAIP-19 asset type ID, or `undefined` when any part is invalid.
|
|
246
|
+
*/
|
|
247
|
+
declare function formatCaip19AssetId(chainId: string | number, assetNamespace: string, assetReference: string): Caip19AssetId | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Splits a CAIP-19 asset type ID into its chain, asset namespace and asset reference. IDs of single tokens
|
|
250
|
+
* (`eip155:1/erc721:0x…/1`) are not asset types and are rejected.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* parseCaip19AssetId('eip155:1/slip44:60'); // { chainId: 'eip155:1', assetNamespace: 'slip44', assetReference: '60' }
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @param assetId - The CAIP-19 asset type ID to parse.
|
|
258
|
+
* @returns The chain ID, asset namespace and asset reference, or `undefined` when the value is not a valid CAIP-19
|
|
259
|
+
* asset type ID.
|
|
260
|
+
*/
|
|
261
|
+
declare function parseCaip19AssetId(assetId: string): {
|
|
262
|
+
chainId: Caip2ChainId;
|
|
263
|
+
assetNamespace: string;
|
|
264
|
+
assetReference: string;
|
|
265
|
+
} | undefined;
|
|
266
|
+
|
|
136
267
|
/**
|
|
137
268
|
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
138
269
|
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
@@ -820,4 +951,4 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
820
951
|
*/
|
|
821
952
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
822
953
|
|
|
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 };
|
|
954
|
+
export { type BaseAdapter, type Caip10AccountId, type Caip19AssetId, type Caip2ChainId, type ChainIdentifierArray, type ConnectorType, type LastConnectedConnector, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, SOLANA_CHAIN_IDS, type SolanaCluster, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatCaip10AccountId, formatCaip19AssetId, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, toCaip2ChainId, toEvmChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
exports.OrbitAdapter=
|
|
1
|
+
'use strict';var d=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(d||{});function y(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function A(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function u(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return y(t);case "solana":return A(t);default:return y(t)||A(t)}}var l={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},p="solana:",S={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function m(e){if(typeof e!="string")return;let n=e.startsWith(p)?e.slice(p.length):e;return Object.hasOwn(S,n)?S[n]:void 0}function a(e){let n=m(e);if(n)return n==="localnet"?`${p}localnet`:l[n]}var g=/^[-a-z0-9]{3,8}$/,T=/^[-_a-zA-Z0-9]{1,32}$/,h=/^[-.%a-zA-Z0-9]{1,128}$/,b=/^[-.%a-zA-Z0-9]{1,128}$/,k=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function f(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),r=e.slice(n+1);return g.test(t)&&T.test(r)?{namespace:t,reference:r}:void 0}function x(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=a(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:f(e)?e:void 0)}function P(e){let n=typeof e=="number"?e:Number(k.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function R(e,n){return e==="eip155"?u(n,"evm"):e==="solana"?u(n,"solana"):h.test(n)}function D(e,n){let t=x(e);if(!t)return;let r=f(t),o=n.trim();if(!(!r||!R(r.namespace,o)))return `${t}:${o}`}function J(e){let n=e.lastIndexOf(":");if(n<0)return;let t=f(e.slice(0,n)),r=e.slice(n+1);if(!(!t||!R(t.namespace,r)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:r}}function j(e,n,t){let r=x(e);if(!(!r||!g.test(n)||!b.test(t)))return `${r}/${n}:${t}`}function F(e){let n=e.indexOf("/");if(n<0)return;let t=f(e.slice(0,n)),r=e.slice(n+1),o=r.indexOf(":");if(!t||o<0)return;let i=r.slice(0,o),w=r.slice(o+1);if(!(!g.test(i)||!b.test(w)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:i,assetReference:w}}function z(e){return m(e)!==void 0}function V(e){return a(e)??e}var q=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function W(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function ee(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=a(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var O=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"]]),te=e=>O.get(e)??e.replace(/\s+/g,"").toLowerCase();function ie(e){return e?.split(":")[0]??"evm"}function ce(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var pe=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:l.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 c(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 ge={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 we(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",r),n(false);},e);function r(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",r),n(true));}window.addEventListener("message",r);let o=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:o,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var L=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",ye=L;var C={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:c("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(C.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>c(C.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(C.STORAGE_KEY):void 0};var I=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function N(){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 r={name:t.name,message:t.message};t.stack&&(r.stack=t.stack);for(let o of Object.keys(t))o in r||(r[o]=t[o]);return r}return t}}function $(e){let n={};if(e&&typeof e=="object"){for(let t of I)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function E(e){try{let n=N(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function xe(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=$(e),r=E(e);return {message:n,raw:{...r,...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:{...E(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var s={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:c("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>c(s.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let r={...s.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(r));},removeConnector:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...r}=n;window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(r));},hasConnector:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:s.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=s.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=s.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,r])=>r.disconnectedTimestamp>=e));window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(s.STORAGE_KEY):void 0};var he=({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(r=>r.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 Oe(e,n=50,t=200){for(let r=0;r<n;r++){if(e())return;await new Promise(o=>setTimeout(o,t));}throw new Error("Predicate not fulfilled in time")}
|
|
2
|
+
exports.OrbitAdapter=d;exports.SOLANA_CHAIN_IDS=l;exports.delay=q;exports.detectSafeApp=we;exports.filterUniqueByKey=W;exports.formatCaip10AccountId=D;exports.formatCaip19AssetId=j;exports.formatConnectorChainId=ee;exports.formatConnectorName=te;exports.getAdapterFromConnectorType=ie;exports.getConnectorTypeFromName=ce;exports.getNetworkData=pe;exports.getParsedStorageItem=c;exports.getSolanaChainId=a;exports.getSolanaCluster=m;exports.impersonatedHelpers=ge;exports.isAddress=u;exports.isInSecureIframe=L;exports.isSafeApp=ye;exports.isSolanaChain=z;exports.lastConnectedConnectorHelpers=C;exports.normalizeError=xe;exports.parseCaip10AccountId=J;exports.parseCaip19AssetId=F;exports.parseCaip2ChainId=f;exports.recentlyConnectedConnectorsListHelpers=s;exports.selectAdapterByKey=he;exports.setChainId=V;exports.toCaip2ChainId=x;exports.toEvmChainId=P;exports.waitFor=Oe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var d=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(d||{});function y(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function A(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function u(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return y(t);case "solana":return A(t);default:return y(t)||A(t)}}var l={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},p="solana:",S={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function m(e){if(typeof e!="string")return;let n=e.startsWith(p)?e.slice(p.length):e;return Object.hasOwn(S,n)?S[n]:void 0}function a(e){let n=m(e);if(n)return n==="localnet"?`${p}localnet`:l[n]}var g=/^[-a-z0-9]{3,8}$/,T=/^[-_a-zA-Z0-9]{1,32}$/,h=/^[-.%a-zA-Z0-9]{1,128}$/,b=/^[-.%a-zA-Z0-9]{1,128}$/,k=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function f(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),r=e.slice(n+1);return g.test(t)&&T.test(r)?{namespace:t,reference:r}:void 0}function x(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=a(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:f(e)?e:void 0)}function P(e){let n=typeof e=="number"?e:Number(k.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function R(e,n){return e==="eip155"?u(n,"evm"):e==="solana"?u(n,"solana"):h.test(n)}function D(e,n){let t=x(e);if(!t)return;let r=f(t),o=n.trim();if(!(!r||!R(r.namespace,o)))return `${t}:${o}`}function J(e){let n=e.lastIndexOf(":");if(n<0)return;let t=f(e.slice(0,n)),r=e.slice(n+1);if(!(!t||!R(t.namespace,r)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:r}}function j(e,n,t){let r=x(e);if(!(!r||!g.test(n)||!b.test(t)))return `${r}/${n}:${t}`}function F(e){let n=e.indexOf("/");if(n<0)return;let t=f(e.slice(0,n)),r=e.slice(n+1),o=r.indexOf(":");if(!t||o<0)return;let i=r.slice(0,o),w=r.slice(o+1);if(!(!g.test(i)||!b.test(w)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:i,assetReference:w}}function z(e){return m(e)!==void 0}function V(e){return a(e)??e}var q=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function W(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function ee(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=a(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var O=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"]]),te=e=>O.get(e)??e.replace(/\s+/g,"").toLowerCase();function ie(e){return e?.split(":")[0]??"evm"}function ce(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var pe=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:l.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 c(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 ge={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 we(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",r),n(false);},e);function r(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",r),n(true));}window.addEventListener("message",r);let o=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:o,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var L=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",ye=L;var C={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:c("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(C.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>c(C.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(C.STORAGE_KEY):void 0};var I=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function N(){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 r={name:t.name,message:t.message};t.stack&&(r.stack=t.stack);for(let o of Object.keys(t))o in r||(r[o]=t[o]);return r}return t}}function $(e){let n={};if(e&&typeof e=="object"){for(let t of I)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function E(e){try{let n=N(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function xe(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=$(e),r=E(e);return {message:n,raw:{...r,...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:{...E(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var s={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:c("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>c(s.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let r={...s.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(r));},removeConnector:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...r}=n;window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(r));},hasConnector:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:s.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=s.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=s.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=s.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,r])=>r.disconnectedTimestamp>=e));window.localStorage.setItem(s.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(s.STORAGE_KEY):void 0};var he=({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(r=>r.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 Oe(e,n=50,t=200){for(let r=0;r<n;r++){if(e())return;await new Promise(o=>setTimeout(o,t));}throw new Error("Predicate not fulfilled in time")}
|
|
2
|
+
export{d as OrbitAdapter,l as SOLANA_CHAIN_IDS,q as delay,we as detectSafeApp,W as filterUniqueByKey,D as formatCaip10AccountId,j as formatCaip19AssetId,ee as formatConnectorChainId,te as formatConnectorName,ie as getAdapterFromConnectorType,ce as getConnectorTypeFromName,pe as getNetworkData,c as getParsedStorageItem,a as getSolanaChainId,m as getSolanaCluster,ge as impersonatedHelpers,u as isAddress,L as isInSecureIframe,ye as isSafeApp,z as isSolanaChain,C as lastConnectedConnectorHelpers,xe as normalizeError,J as parseCaip10AccountId,F as parseCaip19AssetId,f as parseCaip2ChainId,s as recentlyConnectedConnectorsListHelpers,he as selectAdapterByKey,V as setChainId,x as toCaip2ChainId,P as toEvmChainId,Oe as waitFor};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
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.",
|
|
7
|
+
"description": "L1 core of Orbit Utils (TUWA): zero-dependency, framework-agnostic multi-chain types, CAIP-2, CAIP-10 and CAIP-19 helpers, 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",
|