@tuwaio/orbit-core 0.3.1 → 0.5.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 +14 -0
- package/dist/index.d.mts +203 -15
- package/dist/index.d.ts +203 -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,8 @@ 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.
|
|
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.
|
|
16
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.
|
|
17
19
|
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage` and do nothing during SSR.
|
|
18
20
|
- **Runtime utilities:** `detectSafeApp` (Safe{Wallet} iframe detection), `waitFor`, `delay`, `filterUniqueByKey`, and `impersonatedHelpers` for development and testing.
|
|
@@ -64,6 +66,18 @@ lastConnectedConnectorHelpers.setLastConnectedConnector({
|
|
|
64
66
|
const lastConnected = lastConnectedConnectorHelpers.getLastConnectedConnector();
|
|
65
67
|
```
|
|
66
68
|
|
|
69
|
+
### Identifying Solana clusters
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { getSolanaChainId, getSolanaCluster } from '@tuwaio/orbit-core';
|
|
73
|
+
|
|
74
|
+
getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
75
|
+
getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
76
|
+
getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
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`.
|
|
80
|
+
|
|
67
81
|
### Normalizing errors
|
|
68
82
|
|
|
69
83
|
```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,152 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
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
|
+
* ```
|
|
139
206
|
*
|
|
140
|
-
* @param
|
|
141
|
-
* @
|
|
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
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
269
|
+
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
270
|
+
* genesis hash. See {@link getSolanaCluster}.
|
|
271
|
+
*
|
|
272
|
+
* @param chainId - The chain ID or chain name.
|
|
273
|
+
* @returns `true` if the chain ID corresponds to a known Solana network, `false` otherwise.
|
|
142
274
|
*/
|
|
143
275
|
declare function isSolanaChain(chainId: number | string): boolean;
|
|
144
276
|
/**
|
|
145
|
-
*
|
|
277
|
+
* Turns a Solana chain, in any form accepted by {@link isSolanaChain}, into its CAIP-2 chain ID with the genesis hash
|
|
278
|
+
* (see {@link getSolanaChainId}): `devnet` and `solana:devnet` become `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`. Other
|
|
279
|
+
* chain IDs are returned unchanged.
|
|
146
280
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
281
|
+
* @param chainId - The original chain ID or name.
|
|
282
|
+
* @returns The CAIP-2 chain ID for Solana networks, otherwise the original value.
|
|
149
283
|
*/
|
|
150
284
|
declare function setChainId(chainId: number | string): string | number;
|
|
151
285
|
|
|
@@ -194,17 +328,19 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
194
328
|
|
|
195
329
|
/**
|
|
196
330
|
* Formats a chain ID for use in connector identifiers.
|
|
197
|
-
*
|
|
331
|
+
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
332
|
+
* IDs are prefixed with the adapter key unless they already have it; numeric EVM chain IDs are kept as is.
|
|
198
333
|
*
|
|
199
334
|
* @example
|
|
200
335
|
* ```typescript
|
|
201
|
-
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:
|
|
336
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
202
337
|
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
338
|
* ```
|
|
204
339
|
*
|
|
205
340
|
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
341
|
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
-
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise
|
|
342
|
+
* @returns The CAIP-2 chain ID for known Solana clusters, `"<adapter>:<chainId>"` for other string chain IDs, otherwise
|
|
343
|
+
* the numeric chain ID unchanged.
|
|
208
344
|
*/
|
|
209
345
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
210
346
|
|
|
@@ -282,8 +418,9 @@ declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string):
|
|
|
282
418
|
* "What is a wallet?" section in a connect modal.
|
|
283
419
|
*
|
|
284
420
|
* @param adapter - The adapter to describe.
|
|
285
|
-
* @returns Default chain (`chainId
|
|
286
|
-
* or `undefined` for adapters without network data (e.g.
|
|
421
|
+
* @returns Default chain (`chainId`: `1` for EVM, {@link SOLANA_CHAIN_IDS}`.mainnet` for Solana; `name`) and `links`
|
|
422
|
+
* (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana, or `undefined` for adapters without network data (e.g.
|
|
423
|
+
* Starknet).
|
|
287
424
|
*/
|
|
288
425
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
289
426
|
chain: {
|
|
@@ -297,7 +434,7 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
297
434
|
};
|
|
298
435
|
} | {
|
|
299
436
|
chain: {
|
|
300
|
-
chainId:
|
|
437
|
+
chainId: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
301
438
|
name: string;
|
|
302
439
|
};
|
|
303
440
|
links: {
|
|
@@ -746,6 +883,57 @@ declare const selectAdapterByKey: <A extends {
|
|
|
746
883
|
adapterKey: OrbitAdapter;
|
|
747
884
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
748
885
|
|
|
886
|
+
/**
|
|
887
|
+
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
888
|
+
* genesis hash of the cluster.
|
|
889
|
+
*
|
|
890
|
+
* Wallet Standard wallets name the same clusters `solana:mainnet`, `solana:devnet` and `solana:testnet`: pass those to
|
|
891
|
+
* wallet calls, and these IDs everywhere a chain is identified (sessions, transactions, APIs).
|
|
892
|
+
*/
|
|
893
|
+
declare const SOLANA_CHAIN_IDS: {
|
|
894
|
+
readonly mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
895
|
+
readonly devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
896
|
+
readonly testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* A Solana cluster moniker recognized by {@link getSolanaCluster}.
|
|
900
|
+
*/
|
|
901
|
+
type SolanaCluster = keyof typeof SOLANA_CHAIN_IDS | 'localnet';
|
|
902
|
+
/**
|
|
903
|
+
* Returns the cluster of a Solana chain identifier, in any of its forms: a cluster moniker (`devnet`, `mainnet-beta`),
|
|
904
|
+
* a Wallet Standard chain (`solana:devnet`), a CAIP-2 chain ID with the genesis hash
|
|
905
|
+
* (`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`) or its bare reference. `mainnet-beta` is reported as `mainnet`; the
|
|
906
|
+
* testnet ID from before the testnet genesis reset (`solana:4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR`) as `testnet`.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```typescript
|
|
910
|
+
* getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
911
|
+
* getSolanaCluster('solana:mainnet-beta'); // "mainnet"
|
|
912
|
+
* getSolanaCluster(1); // undefined
|
|
913
|
+
* ```
|
|
914
|
+
*
|
|
915
|
+
* @param chainId - Chain identifier to read. Monikers are case-sensitive, as in the Wallet Standard.
|
|
916
|
+
* @returns `mainnet`, `devnet`, `testnet` or `localnet`, or `undefined` when the value is not a known Solana chain
|
|
917
|
+
* (numbers, other namespaces, custom clusters).
|
|
918
|
+
*/
|
|
919
|
+
declare function getSolanaCluster(chainId: string | number): SolanaCluster | undefined;
|
|
920
|
+
/**
|
|
921
|
+
* Returns the CAIP-2 chain ID of a Solana chain identifier in any form accepted by {@link getSolanaCluster}: the
|
|
922
|
+
* genesis-hash ID from {@link SOLANA_CHAIN_IDS} for the public clusters, and `solana:localnet` for `localnet`, which
|
|
923
|
+
* has no fixed genesis hash.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```typescript
|
|
927
|
+
* getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
928
|
+
* getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
929
|
+
* getSolanaChainId('eip155:1'); // undefined
|
|
930
|
+
* ```
|
|
931
|
+
*
|
|
932
|
+
* @param chainId - Chain identifier to convert.
|
|
933
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value is not a known Solana chain.
|
|
934
|
+
*/
|
|
935
|
+
declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
936
|
+
|
|
749
937
|
/**
|
|
750
938
|
* Polls a predicate until it returns a truthy value.
|
|
751
939
|
*
|
|
@@ -763,4 +951,4 @@ declare const selectAdapterByKey: <A extends {
|
|
|
763
951
|
*/
|
|
764
952
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
765
953
|
|
|
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 };
|
|
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
|
@@ -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,152 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
134
134
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
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
|
+
* ```
|
|
139
206
|
*
|
|
140
|
-
* @param
|
|
141
|
-
* @
|
|
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
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Checks whether the given chain ID belongs to a Solana network: a cluster moniker (`mainnet`, `mainnet-beta`,
|
|
269
|
+
* `devnet`, `testnet`, `localnet`), a Wallet Standard chain such as `solana:devnet`, or a CAIP-2 chain ID with the
|
|
270
|
+
* genesis hash. See {@link getSolanaCluster}.
|
|
271
|
+
*
|
|
272
|
+
* @param chainId - The chain ID or chain name.
|
|
273
|
+
* @returns `true` if the chain ID corresponds to a known Solana network, `false` otherwise.
|
|
142
274
|
*/
|
|
143
275
|
declare function isSolanaChain(chainId: number | string): boolean;
|
|
144
276
|
/**
|
|
145
|
-
*
|
|
277
|
+
* Turns a Solana chain, in any form accepted by {@link isSolanaChain}, into its CAIP-2 chain ID with the genesis hash
|
|
278
|
+
* (see {@link getSolanaChainId}): `devnet` and `solana:devnet` become `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`. Other
|
|
279
|
+
* chain IDs are returned unchanged.
|
|
146
280
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
281
|
+
* @param chainId - The original chain ID or name.
|
|
282
|
+
* @returns The CAIP-2 chain ID for Solana networks, otherwise the original value.
|
|
149
283
|
*/
|
|
150
284
|
declare function setChainId(chainId: number | string): string | number;
|
|
151
285
|
|
|
@@ -194,17 +328,19 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
194
328
|
|
|
195
329
|
/**
|
|
196
330
|
* Formats a chain ID for use in connector identifiers.
|
|
197
|
-
*
|
|
331
|
+
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
332
|
+
* IDs are prefixed with the adapter key unless they already have it; numeric EVM chain IDs are kept as is.
|
|
198
333
|
*
|
|
199
334
|
* @example
|
|
200
335
|
* ```typescript
|
|
201
|
-
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:
|
|
336
|
+
* formatConnectorChainId('devnet', OrbitAdapter.SOLANA); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
202
337
|
* formatConnectorChainId(1, OrbitAdapter.EVM); // 1
|
|
203
338
|
* ```
|
|
204
339
|
*
|
|
205
340
|
* @param chainId - Numeric EVM chain ID or string chain identifier.
|
|
206
341
|
* @param connectedAdapter - Adapter of the connected wallet.
|
|
207
|
-
* @returns `"<adapter>:<chainId>"` for string chain IDs, otherwise
|
|
342
|
+
* @returns The CAIP-2 chain ID for known Solana clusters, `"<adapter>:<chainId>"` for other string chain IDs, otherwise
|
|
343
|
+
* the numeric chain ID unchanged.
|
|
208
344
|
*/
|
|
209
345
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
210
346
|
|
|
@@ -282,8 +418,9 @@ declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string):
|
|
|
282
418
|
* "What is a wallet?" section in a connect modal.
|
|
283
419
|
*
|
|
284
420
|
* @param adapter - The adapter to describe.
|
|
285
|
-
* @returns Default chain (`chainId
|
|
286
|
-
* or `undefined` for adapters without network data (e.g.
|
|
421
|
+
* @returns Default chain (`chainId`: `1` for EVM, {@link SOLANA_CHAIN_IDS}`.mainnet` for Solana; `name`) and `links`
|
|
422
|
+
* (`aboutNetwork`, `choseWallet`, `about`) for EVM and Solana, or `undefined` for adapters without network data (e.g.
|
|
423
|
+
* Starknet).
|
|
287
424
|
*/
|
|
288
425
|
declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
289
426
|
chain: {
|
|
@@ -297,7 +434,7 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
297
434
|
};
|
|
298
435
|
} | {
|
|
299
436
|
chain: {
|
|
300
|
-
chainId:
|
|
437
|
+
chainId: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
301
438
|
name: string;
|
|
302
439
|
};
|
|
303
440
|
links: {
|
|
@@ -746,6 +883,57 @@ declare const selectAdapterByKey: <A extends {
|
|
|
746
883
|
adapterKey: OrbitAdapter;
|
|
747
884
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
748
885
|
|
|
886
|
+
/**
|
|
887
|
+
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
888
|
+
* genesis hash of the cluster.
|
|
889
|
+
*
|
|
890
|
+
* Wallet Standard wallets name the same clusters `solana:mainnet`, `solana:devnet` and `solana:testnet`: pass those to
|
|
891
|
+
* wallet calls, and these IDs everywhere a chain is identified (sessions, transactions, APIs).
|
|
892
|
+
*/
|
|
893
|
+
declare const SOLANA_CHAIN_IDS: {
|
|
894
|
+
readonly mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
895
|
+
readonly devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
896
|
+
readonly testnet: "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* A Solana cluster moniker recognized by {@link getSolanaCluster}.
|
|
900
|
+
*/
|
|
901
|
+
type SolanaCluster = keyof typeof SOLANA_CHAIN_IDS | 'localnet';
|
|
902
|
+
/**
|
|
903
|
+
* Returns the cluster of a Solana chain identifier, in any of its forms: a cluster moniker (`devnet`, `mainnet-beta`),
|
|
904
|
+
* a Wallet Standard chain (`solana:devnet`), a CAIP-2 chain ID with the genesis hash
|
|
905
|
+
* (`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`) or its bare reference. `mainnet-beta` is reported as `mainnet`; the
|
|
906
|
+
* testnet ID from before the testnet genesis reset (`solana:4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR`) as `testnet`.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```typescript
|
|
910
|
+
* getSolanaCluster('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'); // "devnet"
|
|
911
|
+
* getSolanaCluster('solana:mainnet-beta'); // "mainnet"
|
|
912
|
+
* getSolanaCluster(1); // undefined
|
|
913
|
+
* ```
|
|
914
|
+
*
|
|
915
|
+
* @param chainId - Chain identifier to read. Monikers are case-sensitive, as in the Wallet Standard.
|
|
916
|
+
* @returns `mainnet`, `devnet`, `testnet` or `localnet`, or `undefined` when the value is not a known Solana chain
|
|
917
|
+
* (numbers, other namespaces, custom clusters).
|
|
918
|
+
*/
|
|
919
|
+
declare function getSolanaCluster(chainId: string | number): SolanaCluster | undefined;
|
|
920
|
+
/**
|
|
921
|
+
* Returns the CAIP-2 chain ID of a Solana chain identifier in any form accepted by {@link getSolanaCluster}: the
|
|
922
|
+
* genesis-hash ID from {@link SOLANA_CHAIN_IDS} for the public clusters, and `solana:localnet` for `localnet`, which
|
|
923
|
+
* has no fixed genesis hash.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```typescript
|
|
927
|
+
* getSolanaChainId('devnet'); // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
928
|
+
* getSolanaChainId('solana:mainnet-beta'); // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
929
|
+
* getSolanaChainId('eip155:1'); // undefined
|
|
930
|
+
* ```
|
|
931
|
+
*
|
|
932
|
+
* @param chainId - Chain identifier to convert.
|
|
933
|
+
* @returns The CAIP-2 chain ID, or `undefined` when the value is not a known Solana chain.
|
|
934
|
+
*/
|
|
935
|
+
declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
936
|
+
|
|
749
937
|
/**
|
|
750
938
|
* Polls a predicate until it returns a truthy value.
|
|
751
939
|
*
|
|
@@ -763,4 +951,4 @@ declare const selectAdapterByKey: <A extends {
|
|
|
763
951
|
*/
|
|
764
952
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
765
953
|
|
|
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 };
|
|
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};
|