@tuwaio/orbit-core 0.5.1 → 0.6.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 +7 -7
- package/dist/index.d.mts +183 -27
- package/dist/index.d.ts +183 -27
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The package has **zero runtime dependencies** and imports no Web3 SDK, so it run
|
|
|
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
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.
|
|
18
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.
|
|
19
|
-
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage` and do nothing during SSR.
|
|
19
|
+
- **Connection persistence:** `lastConnectedConnectorHelpers` and `recentlyConnectedConnectorsListHelpers` keep connection history in `localStorage`, or in `sessionStorage` until the tab closes for a wallet the user did not ask to remember (`{ remember: false }`), and do nothing during SSR.
|
|
20
20
|
- **Runtime utilities:** `detectSafeApp` (Safe{Wallet} iframe detection), `waitFor`, `delay`, `filterUniqueByKey`, and `impersonatedHelpers` for development and testing.
|
|
21
21
|
|
|
22
22
|
---
|
|
@@ -108,13 +108,13 @@ isAddress('So11111111111111111111111111111111111111112', 'solana'); // true
|
|
|
108
108
|
|
|
109
109
|
## 🗄️ Browser Storage
|
|
110
110
|
|
|
111
|
-
The storage helpers write the following
|
|
111
|
+
The storage helpers write the following keys. Clear them to reset the connection state of a user. In a browser that blocks site data they find nothing saved and write nothing, and a full storage still throws from a write:
|
|
112
112
|
|
|
113
|
-
| Key | Written by |
|
|
114
|
-
| --------------------------------------------------- | ---------------------------------------- |
|
|
115
|
-
| `orbit-core:lastConnectedConnector` | `lastConnectedConnectorHelpers` |
|
|
116
|
-
| `orbit-core:recentlyConnectedConnectorsListHelpers` | `recentlyConnectedConnectorsListHelpers` |
|
|
117
|
-
| `satellite-connect:impersonatedAddress` | `impersonatedHelpers` |
|
|
113
|
+
| Key | Written by | Where |
|
|
114
|
+
| --------------------------------------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `orbit-core:lastConnectedConnector` | `lastConnectedConnectorHelpers` | `localStorage` for a remembered wallet (the default); `sessionStorage` until the tab closes with `{ remember: false }` |
|
|
116
|
+
| `orbit-core:recentlyConnectedConnectorsListHelpers` | `recentlyConnectedConnectorsListHelpers` | `localStorage` for remembered wallets; `sessionStorage` for the others; reading merges both |
|
|
117
|
+
| `satellite-connect:impersonatedAddress` | `impersonatedHelpers` | `localStorage` |
|
|
118
118
|
|
|
119
119
|
---
|
|
120
120
|
|
package/dist/index.d.mts
CHANGED
|
@@ -125,6 +125,25 @@ type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
|
125
125
|
*/
|
|
126
126
|
type ChainIdentifierArray = readonly (string | number)[];
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* An account address in the form to compare it in: an EVM address in any case, as its case is only a checksum; any
|
|
130
|
+
* other exactly, as a base58 address in another case is another account.
|
|
131
|
+
*
|
|
132
|
+
* @param namespace - The CAIP-2 namespace of the account, e.g. `eip155` or `solana`.
|
|
133
|
+
* @param address - The address.
|
|
134
|
+
* @returns The address to compare.
|
|
135
|
+
*/
|
|
136
|
+
declare function normalizeAccountAddress(namespace: string, address: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Whether two addresses of one namespace are the same account, by {@link normalizeAccountAddress}.
|
|
139
|
+
*
|
|
140
|
+
* @param namespace - The CAIP-2 namespace of both addresses, e.g. `eip155` or `solana`.
|
|
141
|
+
* @param left - One address.
|
|
142
|
+
* @param right - The other address.
|
|
143
|
+
* @returns `true` when they are the same account.
|
|
144
|
+
*/
|
|
145
|
+
declare function isSameAddress(namespace: string, left: string, right: string): boolean;
|
|
146
|
+
|
|
128
147
|
/**
|
|
129
148
|
* Universal address validation function that supports multiple blockchain formats
|
|
130
149
|
* @param value - Address string to validate
|
|
@@ -133,6 +152,23 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
152
|
*/
|
|
134
153
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
154
|
|
|
155
|
+
/**
|
|
156
|
+
* The storage of the browser, reached safely. A browser that blocks site data throws on reaching `window.localStorage`,
|
|
157
|
+
* not on what is called on it, so a guard on `typeof window` is not enough.
|
|
158
|
+
*
|
|
159
|
+
* @param area - The storage to reach: `localStorage` (default) or `sessionStorage`.
|
|
160
|
+
* @returns The storage, or `null` without a browser or when the browser refuses it.
|
|
161
|
+
*/
|
|
162
|
+
declare function getBrowserStorage(area?: 'localStorage' | 'sessionStorage'): Storage | null;
|
|
163
|
+
/**
|
|
164
|
+
* Reads a value of the browser's storage. Never throws.
|
|
165
|
+
*
|
|
166
|
+
* @param key - The storage key.
|
|
167
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`.
|
|
168
|
+
* @returns The value, or `null` when it is not set, without a browser, or when the browser refuses it.
|
|
169
|
+
*/
|
|
170
|
+
declare function readBrowserStorage(key: string, area?: 'localStorage' | 'sessionStorage'): string | null;
|
|
171
|
+
|
|
136
172
|
/**
|
|
137
173
|
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
174
|
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
@@ -312,6 +348,15 @@ declare function setChainId(chainId: number | string): string | number;
|
|
|
312
348
|
*/
|
|
313
349
|
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
314
350
|
|
|
351
|
+
/**
|
|
352
|
+
* An error and the causes it wraps, of any kind, as wallet libraries wrap what the wallet answered several levels down.
|
|
353
|
+
* A cause that loops ends the list.
|
|
354
|
+
*
|
|
355
|
+
* @param error - What was thrown.
|
|
356
|
+
* @returns The error first, then each `cause` in turn; empty for `null` or `undefined`.
|
|
357
|
+
*/
|
|
358
|
+
declare function errorChain(error: unknown): unknown[];
|
|
359
|
+
|
|
315
360
|
/**
|
|
316
361
|
* Filters an array of objects to keep only the first occurrence of an object
|
|
317
362
|
* based on a unique value of a specified key.
|
|
@@ -326,6 +371,22 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
326
371
|
*/
|
|
327
372
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
328
373
|
|
|
374
|
+
/**
|
|
375
|
+
* An integer amount in the smallest unit of a currency as a decimal number, for example wei as gwei (`decimals` 9) or
|
|
376
|
+
* lamports as SOL (`decimals` 9): exact, with a dot, without grouping, trailing zeros or rounding.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* formatBaseUnits('89540000', 6); // "89.54"
|
|
381
|
+
* formatBaseUnits(1500000000n, 9); // "1.5"
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @param value - The amount, as a number, a decimal string or a bigint.
|
|
385
|
+
* @param decimals - The number of decimals of the displayed unit.
|
|
386
|
+
* @returns The decimal string, or `undefined` when `value` is missing, negative or not an integer.
|
|
387
|
+
*/
|
|
388
|
+
declare function formatBaseUnits(value: string | number | bigint | null | undefined, decimals: number): string | undefined;
|
|
389
|
+
|
|
329
390
|
/**
|
|
330
391
|
* Formats a chain ID for use in connector identifiers.
|
|
331
392
|
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
@@ -344,6 +405,10 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
344
405
|
*/
|
|
345
406
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
346
407
|
|
|
408
|
+
/** The connector ID of the impersonated wallet. It is saved in the last connection, so it can never change. */
|
|
409
|
+
declare const IMPERSONATED_CONNECTOR_ID = "impersonatedwallet";
|
|
410
|
+
/** The connector ID of Safe{Wallet}. It is saved in the last connection, so it can never change. */
|
|
411
|
+
declare const SAFE_CONNECTOR_ID = "safe";
|
|
347
412
|
/**
|
|
348
413
|
* Normalizes a wallet connector display name into a stable identifier.
|
|
349
414
|
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
@@ -397,21 +462,21 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
397
462
|
*
|
|
398
463
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
399
464
|
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
465
|
+
*
|
|
466
|
+
* // Returns "evm:coinbase" (a known name, by formatConnectorName)
|
|
467
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Base Account");
|
|
400
468
|
* ```
|
|
401
469
|
*
|
|
402
470
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
403
|
-
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
471
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom"), as the wallet reports it or as {@link formatConnectorName} gave it
|
|
404
472
|
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
405
473
|
*
|
|
406
474
|
* @remarks
|
|
407
|
-
* The function:
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
* and normalizes connector names for better UX/consistency.
|
|
413
|
-
*/
|
|
414
|
-
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
475
|
+
* The function goes through {@link formatConnectorName}: known names are mapped, any other has its whitespace removed
|
|
476
|
+
* and is lowercased. So one wallet has one type wherever it is read, on its connection and on its transactions, and a
|
|
477
|
+
* value that already went through the mapping stays as it is.
|
|
478
|
+
*/
|
|
479
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): ConnectorType;
|
|
415
480
|
|
|
416
481
|
/**
|
|
417
482
|
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
@@ -445,12 +510,39 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
445
510
|
} | undefined;
|
|
446
511
|
|
|
447
512
|
/**
|
|
448
|
-
* Internal function for safely retrieving and parsing data from localStorage.
|
|
513
|
+
* Internal function for safely retrieving and parsing data from localStorage or sessionStorage.
|
|
514
|
+
*
|
|
515
|
+
* @param key - The storage key
|
|
516
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
517
|
+
* @returns The parsed value or undefined if data is not found/invalid, in an SSR context, or when the browser refuses
|
|
518
|
+
* the storage
|
|
519
|
+
*/
|
|
520
|
+
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* The wallet part of a connector type.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* getWalletFromConnectorType('evm:metamask'); // "metamask"
|
|
528
|
+
* getWalletFromConnectorType('metamask'); // undefined
|
|
529
|
+
* ```
|
|
449
530
|
*
|
|
450
|
-
* @param
|
|
451
|
-
* @returns The
|
|
531
|
+
* @param connectorType - A connector type, in the format "orbit-adapter:connector".
|
|
532
|
+
* @returns The part after the adapter, or `undefined` when there is no adapter or no value.
|
|
452
533
|
*/
|
|
453
|
-
declare function
|
|
534
|
+
declare function getWalletFromConnectorType(connectorType: string | null | undefined): string | undefined;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* One object for all copies of a package on a page, kept on `globalThis` under `Symbol.for(key)`. A bundler can load a
|
|
538
|
+
* package twice, and two copies of a React context or a registry do not see each other.
|
|
539
|
+
*
|
|
540
|
+
* @template T - The type of the object.
|
|
541
|
+
* @param key - The name of the symbol. It must never change: published copies find each other through it.
|
|
542
|
+
* @param create - Makes the object, called only when no copy has made it yet.
|
|
543
|
+
* @returns The object.
|
|
544
|
+
*/
|
|
545
|
+
declare function globalSingleton<T>(key: string, create: () => T): T;
|
|
454
546
|
|
|
455
547
|
/**
|
|
456
548
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -479,7 +571,7 @@ declare const impersonatedHelpers: {
|
|
|
479
571
|
* @param address - Ethereum or Solana address to impersonate
|
|
480
572
|
* @returns undefined in SSR context, void in browser
|
|
481
573
|
*/
|
|
482
|
-
setImpersonated: (address: string) => void;
|
|
574
|
+
setImpersonated: (address: string) => void | undefined;
|
|
483
575
|
/**
|
|
484
576
|
* Retrieves the current impersonated address from localStorage
|
|
485
577
|
*
|
|
@@ -499,9 +591,17 @@ declare const impersonatedHelpers: {
|
|
|
499
591
|
*
|
|
500
592
|
* @returns undefined in SSR context, void in browser
|
|
501
593
|
*/
|
|
502
|
-
removeImpersonated: () => void;
|
|
594
|
+
removeImpersonated: () => void | undefined;
|
|
503
595
|
};
|
|
504
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Whether a value is an object with fields to read: anything but `null` and an array, class instances included.
|
|
599
|
+
*
|
|
600
|
+
* @param value - The value.
|
|
601
|
+
* @returns `true` for an object.
|
|
602
|
+
*/
|
|
603
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
604
|
+
|
|
505
605
|
/**
|
|
506
606
|
* Checks if the current window is running inside a Safe App iframe
|
|
507
607
|
* by attempting postMessage communication with the parent window.
|
|
@@ -523,6 +623,27 @@ declare const isInSecureIframe: boolean;
|
|
|
523
623
|
*/
|
|
524
624
|
declare const isSafeApp: boolean;
|
|
525
625
|
|
|
626
|
+
/**
|
|
627
|
+
* A URL without the slashes at its end.
|
|
628
|
+
*
|
|
629
|
+
* @param url - The URL.
|
|
630
|
+
* @returns The URL without them.
|
|
631
|
+
*/
|
|
632
|
+
declare function trimTrailingSlashes(url: string): string;
|
|
633
|
+
/**
|
|
634
|
+
* Joins a base URL and a path with one slash, as an explorer URL may end in a slash and a path may start with one.
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* joinUrlPath('https://etherscan.io/', '/tx/0x1'); // "https://etherscan.io/tx/0x1"
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @param base - The base URL.
|
|
642
|
+
* @param path - The path. Without it the base comes back as it is.
|
|
643
|
+
* @returns The joined URL.
|
|
644
|
+
*/
|
|
645
|
+
declare function joinUrlPath(base: string, path?: string): string;
|
|
646
|
+
|
|
526
647
|
/**
|
|
527
648
|
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
528
649
|
*/
|
|
@@ -534,12 +655,22 @@ type LastConnectedConnector = {
|
|
|
534
655
|
/** Connected wallet address, if known. */
|
|
535
656
|
address?: string;
|
|
536
657
|
};
|
|
658
|
+
/**
|
|
659
|
+
* Where a connection is kept: `remember: true` keeps it in localStorage until the wallet is disconnected (the default,
|
|
660
|
+
* as before), `remember: false` keeps it in sessionStorage until the tab closes, for people who did not ask to
|
|
661
|
+
* remember the wallet.
|
|
662
|
+
*/
|
|
663
|
+
type WalletMemoryOptions = {
|
|
664
|
+
/** Keep the connection after the tab closes. Defaults to `true`. */
|
|
665
|
+
remember?: boolean;
|
|
666
|
+
};
|
|
537
667
|
/**
|
|
538
668
|
* Helper utilities for managing the last connected wallet state
|
|
539
669
|
*
|
|
540
670
|
* @remarks
|
|
541
|
-
*
|
|
542
|
-
*
|
|
671
|
+
* The data is stored under the 'orbit-core:lastConnectedConnector' key: in localStorage for a remembered wallet, in
|
|
672
|
+
* sessionStorage for one that is kept only until the tab closes ({@link WalletMemoryOptions}). A value in
|
|
673
|
+
* sessionStorage takes precedence when reading. Functions are safe to use in both browser and SSR environments.
|
|
543
674
|
*/
|
|
544
675
|
declare const lastConnectedConnectorHelpers: {
|
|
545
676
|
STORAGE_KEY: string;
|
|
@@ -549,20 +680,28 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
549
680
|
*/
|
|
550
681
|
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
551
682
|
/**
|
|
552
|
-
* Stores the last connected wallet data in localStorage
|
|
683
|
+
* Stores the last connected wallet data: in localStorage when it is remembered (the default), otherwise in
|
|
684
|
+
* sessionStorage; the copy in the other storage is removed.
|
|
553
685
|
*
|
|
554
686
|
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
687
|
+
* @param options - Whether the wallet is remembered after the tab closes.
|
|
555
688
|
* @returns undefined in SSR context, void in browser
|
|
556
689
|
*/
|
|
557
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
690
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => void;
|
|
558
691
|
/**
|
|
559
|
-
* Retrieves the current last connected wallet data from localStorage.
|
|
692
|
+
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
560
693
|
*
|
|
561
694
|
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
562
695
|
*/
|
|
563
696
|
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
564
697
|
/**
|
|
565
|
-
*
|
|
698
|
+
* Whether the last connection is remembered after the tab closes.
|
|
699
|
+
*
|
|
700
|
+
* @returns `true` when it is in localStorage, `false` when it is in sessionStorage, undefined when there is none
|
|
701
|
+
*/
|
|
702
|
+
isLastConnectedConnectorRemembered: () => boolean | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* Removes the last connected wallet data from localStorage and sessionStorage.
|
|
566
705
|
*
|
|
567
706
|
* @returns undefined in SSR context, void in browser
|
|
568
707
|
*/
|
|
@@ -623,8 +762,9 @@ type RecentlyConnectedConnectorsList = Record<ConnectorType, RecentlyConnectedCo
|
|
|
623
762
|
* Helper utilities for managing recently connected connectors list with disconnect timestamps
|
|
624
763
|
*
|
|
625
764
|
* @remarks
|
|
626
|
-
*
|
|
627
|
-
*
|
|
765
|
+
* The list is stored under the 'orbit-core:recentlyConnectedConnectorsListHelpers' key: wallets that are remembered in
|
|
766
|
+
* localStorage, wallets kept only until the tab closes in sessionStorage ({@link WalletMemoryOptions}); reading
|
|
767
|
+
* merges both, the sessionStorage entry winning. Functions are safe to use in both browser and SSR environments.
|
|
628
768
|
*
|
|
629
769
|
* The storage contains a record where each key is a ConnectorType and value contains
|
|
630
770
|
* address, disconnectedTimestamp (Unix timestamp in milliseconds), and optional icon for that connector.
|
|
@@ -689,7 +829,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
689
829
|
* });
|
|
690
830
|
* ```
|
|
691
831
|
*/
|
|
692
|
-
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void;
|
|
832
|
+
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void | undefined;
|
|
693
833
|
/**
|
|
694
834
|
* Retrieves the current recently connected connectors list from localStorage.
|
|
695
835
|
*
|
|
@@ -732,7 +872,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
732
872
|
* });
|
|
733
873
|
* ```
|
|
734
874
|
*/
|
|
735
|
-
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData) => undefined;
|
|
875
|
+
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData, options?: WalletMemoryOptions) => undefined;
|
|
736
876
|
/**
|
|
737
877
|
* Removes a single connector from the recently connected connectors list.
|
|
738
878
|
* Preserves all other connectors in the list.
|
|
@@ -831,7 +971,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
831
971
|
* recentlyConnectedConnectorsListHelpers.removeRecentlyConnectedConnectorsList();
|
|
832
972
|
* ```
|
|
833
973
|
*/
|
|
834
|
-
removeRecentlyConnectedConnectorsList: () => void;
|
|
974
|
+
removeRecentlyConnectedConnectorsList: () => void | undefined;
|
|
835
975
|
};
|
|
836
976
|
|
|
837
977
|
/**
|
|
@@ -883,6 +1023,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
883
1023
|
adapterKey: OrbitAdapter;
|
|
884
1024
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
885
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* An address or a hash shortened to its start and end, as wallets show it.
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* shortAddress('0x1111111111111111111111111111111111112222'); // "0x1111…2222"
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* @param address - The address or hash (`0x…` or base58).
|
|
1035
|
+
* @param head - Characters kept at the start; `0x` counts toward it (default `6` for `0x`, `4` otherwise).
|
|
1036
|
+
* @param tail - Characters kept at the end (default `4`).
|
|
1037
|
+
* @returns The shortened value; a value that nothing would be saved on stays unchanged.
|
|
1038
|
+
*/
|
|
1039
|
+
declare function shortAddress(address: string, head?: number, tail?: number): string;
|
|
1040
|
+
|
|
886
1041
|
/**
|
|
887
1042
|
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
888
1043
|
* genesis hash of the cluster.
|
|
@@ -951,4 +1106,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
951
1106
|
*/
|
|
952
1107
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
953
1108
|
|
|
954
|
-
export {
|
|
1109
|
+
export { IMPERSONATED_CONNECTOR_ID, OrbitAdapter, SAFE_CONNECTOR_ID, SOLANA_CHAIN_IDS, delay, detectSafeApp, errorChain, filterUniqueByKey, formatBaseUnits, formatCaip10AccountId, formatCaip19AssetId, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getBrowserStorage, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, getWalletFromConnectorType, globalSingleton, impersonatedHelpers, isAddress, isInSecureIframe, isRecord, isSafeApp, isSameAddress, isSolanaChain, joinUrlPath, lastConnectedConnectorHelpers, normalizeAccountAddress, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, readBrowserStorage, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, shortAddress, toCaip2ChainId, toEvmChainId, trimTrailingSlashes, waitFor };
|
|
1110
|
+
export type { BaseAdapter, Caip10AccountId, Caip19AssetId, Caip2ChainId, ChainIdentifierArray, ConnectorType, LastConnectedConnector, OrbitGenericAdapter, RecentlyConnectedConnectorData, RecentlyConnectedConnectorsList, SolanaCluster, TuwaErrorState, WalletMemoryOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,25 @@ type ConnectorType = `${OrbitAdapter}:${string}`;
|
|
|
125
125
|
*/
|
|
126
126
|
type ChainIdentifierArray = readonly (string | number)[];
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* An account address in the form to compare it in: an EVM address in any case, as its case is only a checksum; any
|
|
130
|
+
* other exactly, as a base58 address in another case is another account.
|
|
131
|
+
*
|
|
132
|
+
* @param namespace - The CAIP-2 namespace of the account, e.g. `eip155` or `solana`.
|
|
133
|
+
* @param address - The address.
|
|
134
|
+
* @returns The address to compare.
|
|
135
|
+
*/
|
|
136
|
+
declare function normalizeAccountAddress(namespace: string, address: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Whether two addresses of one namespace are the same account, by {@link normalizeAccountAddress}.
|
|
139
|
+
*
|
|
140
|
+
* @param namespace - The CAIP-2 namespace of both addresses, e.g. `eip155` or `solana`.
|
|
141
|
+
* @param left - One address.
|
|
142
|
+
* @param right - The other address.
|
|
143
|
+
* @returns `true` when they are the same account.
|
|
144
|
+
*/
|
|
145
|
+
declare function isSameAddress(namespace: string, left: string, right: string): boolean;
|
|
146
|
+
|
|
128
147
|
/**
|
|
129
148
|
* Universal address validation function that supports multiple blockchain formats
|
|
130
149
|
* @param value - Address string to validate
|
|
@@ -133,6 +152,23 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
152
|
*/
|
|
134
153
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
154
|
|
|
155
|
+
/**
|
|
156
|
+
* The storage of the browser, reached safely. A browser that blocks site data throws on reaching `window.localStorage`,
|
|
157
|
+
* not on what is called on it, so a guard on `typeof window` is not enough.
|
|
158
|
+
*
|
|
159
|
+
* @param area - The storage to reach: `localStorage` (default) or `sessionStorage`.
|
|
160
|
+
* @returns The storage, or `null` without a browser or when the browser refuses it.
|
|
161
|
+
*/
|
|
162
|
+
declare function getBrowserStorage(area?: 'localStorage' | 'sessionStorage'): Storage | null;
|
|
163
|
+
/**
|
|
164
|
+
* Reads a value of the browser's storage. Never throws.
|
|
165
|
+
*
|
|
166
|
+
* @param key - The storage key.
|
|
167
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`.
|
|
168
|
+
* @returns The value, or `null` when it is not set, without a browser, or when the browser refuses it.
|
|
169
|
+
*/
|
|
170
|
+
declare function readBrowserStorage(key: string, area?: 'localStorage' | 'sessionStorage'): string | null;
|
|
171
|
+
|
|
136
172
|
/**
|
|
137
173
|
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
174
|
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
@@ -312,6 +348,15 @@ declare function setChainId(chainId: number | string): string | number;
|
|
|
312
348
|
*/
|
|
313
349
|
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
314
350
|
|
|
351
|
+
/**
|
|
352
|
+
* An error and the causes it wraps, of any kind, as wallet libraries wrap what the wallet answered several levels down.
|
|
353
|
+
* A cause that loops ends the list.
|
|
354
|
+
*
|
|
355
|
+
* @param error - What was thrown.
|
|
356
|
+
* @returns The error first, then each `cause` in turn; empty for `null` or `undefined`.
|
|
357
|
+
*/
|
|
358
|
+
declare function errorChain(error: unknown): unknown[];
|
|
359
|
+
|
|
315
360
|
/**
|
|
316
361
|
* Filters an array of objects to keep only the first occurrence of an object
|
|
317
362
|
* based on a unique value of a specified key.
|
|
@@ -326,6 +371,22 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
326
371
|
*/
|
|
327
372
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
328
373
|
|
|
374
|
+
/**
|
|
375
|
+
* An integer amount in the smallest unit of a currency as a decimal number, for example wei as gwei (`decimals` 9) or
|
|
376
|
+
* lamports as SOL (`decimals` 9): exact, with a dot, without grouping, trailing zeros or rounding.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* formatBaseUnits('89540000', 6); // "89.54"
|
|
381
|
+
* formatBaseUnits(1500000000n, 9); // "1.5"
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @param value - The amount, as a number, a decimal string or a bigint.
|
|
385
|
+
* @param decimals - The number of decimals of the displayed unit.
|
|
386
|
+
* @returns The decimal string, or `undefined` when `value` is missing, negative or not an integer.
|
|
387
|
+
*/
|
|
388
|
+
declare function formatBaseUnits(value: string | number | bigint | null | undefined, decimals: number): string | undefined;
|
|
389
|
+
|
|
329
390
|
/**
|
|
330
391
|
* Formats a chain ID for use in connector identifiers.
|
|
331
392
|
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
@@ -344,6 +405,10 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
344
405
|
*/
|
|
345
406
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
346
407
|
|
|
408
|
+
/** The connector ID of the impersonated wallet. It is saved in the last connection, so it can never change. */
|
|
409
|
+
declare const IMPERSONATED_CONNECTOR_ID = "impersonatedwallet";
|
|
410
|
+
/** The connector ID of Safe{Wallet}. It is saved in the last connection, so it can never change. */
|
|
411
|
+
declare const SAFE_CONNECTOR_ID = "safe";
|
|
347
412
|
/**
|
|
348
413
|
* Normalizes a wallet connector display name into a stable identifier.
|
|
349
414
|
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
@@ -397,21 +462,21 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
397
462
|
*
|
|
398
463
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
399
464
|
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
465
|
+
*
|
|
466
|
+
* // Returns "evm:coinbase" (a known name, by formatConnectorName)
|
|
467
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Base Account");
|
|
400
468
|
* ```
|
|
401
469
|
*
|
|
402
470
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
403
|
-
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
471
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom"), as the wallet reports it or as {@link formatConnectorName} gave it
|
|
404
472
|
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
405
473
|
*
|
|
406
474
|
* @remarks
|
|
407
|
-
* The function:
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
* and normalizes connector names for better UX/consistency.
|
|
413
|
-
*/
|
|
414
|
-
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): string;
|
|
475
|
+
* The function goes through {@link formatConnectorName}: known names are mapped, any other has its whitespace removed
|
|
476
|
+
* and is lowercased. So one wallet has one type wherever it is read, on its connection and on its transactions, and a
|
|
477
|
+
* value that already went through the mapping stays as it is.
|
|
478
|
+
*/
|
|
479
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): ConnectorType;
|
|
415
480
|
|
|
416
481
|
/**
|
|
417
482
|
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
@@ -445,12 +510,39 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
445
510
|
} | undefined;
|
|
446
511
|
|
|
447
512
|
/**
|
|
448
|
-
* Internal function for safely retrieving and parsing data from localStorage.
|
|
513
|
+
* Internal function for safely retrieving and parsing data from localStorage or sessionStorage.
|
|
514
|
+
*
|
|
515
|
+
* @param key - The storage key
|
|
516
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
517
|
+
* @returns The parsed value or undefined if data is not found/invalid, in an SSR context, or when the browser refuses
|
|
518
|
+
* the storage
|
|
519
|
+
*/
|
|
520
|
+
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* The wallet part of a connector type.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* getWalletFromConnectorType('evm:metamask'); // "metamask"
|
|
528
|
+
* getWalletFromConnectorType('metamask'); // undefined
|
|
529
|
+
* ```
|
|
449
530
|
*
|
|
450
|
-
* @param
|
|
451
|
-
* @returns The
|
|
531
|
+
* @param connectorType - A connector type, in the format "orbit-adapter:connector".
|
|
532
|
+
* @returns The part after the adapter, or `undefined` when there is no adapter or no value.
|
|
452
533
|
*/
|
|
453
|
-
declare function
|
|
534
|
+
declare function getWalletFromConnectorType(connectorType: string | null | undefined): string | undefined;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* One object for all copies of a package on a page, kept on `globalThis` under `Symbol.for(key)`. A bundler can load a
|
|
538
|
+
* package twice, and two copies of a React context or a registry do not see each other.
|
|
539
|
+
*
|
|
540
|
+
* @template T - The type of the object.
|
|
541
|
+
* @param key - The name of the symbol. It must never change: published copies find each other through it.
|
|
542
|
+
* @param create - Makes the object, called only when no copy has made it yet.
|
|
543
|
+
* @returns The object.
|
|
544
|
+
*/
|
|
545
|
+
declare function globalSingleton<T>(key: string, create: () => T): T;
|
|
454
546
|
|
|
455
547
|
/**
|
|
456
548
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -479,7 +571,7 @@ declare const impersonatedHelpers: {
|
|
|
479
571
|
* @param address - Ethereum or Solana address to impersonate
|
|
480
572
|
* @returns undefined in SSR context, void in browser
|
|
481
573
|
*/
|
|
482
|
-
setImpersonated: (address: string) => void;
|
|
574
|
+
setImpersonated: (address: string) => void | undefined;
|
|
483
575
|
/**
|
|
484
576
|
* Retrieves the current impersonated address from localStorage
|
|
485
577
|
*
|
|
@@ -499,9 +591,17 @@ declare const impersonatedHelpers: {
|
|
|
499
591
|
*
|
|
500
592
|
* @returns undefined in SSR context, void in browser
|
|
501
593
|
*/
|
|
502
|
-
removeImpersonated: () => void;
|
|
594
|
+
removeImpersonated: () => void | undefined;
|
|
503
595
|
};
|
|
504
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Whether a value is an object with fields to read: anything but `null` and an array, class instances included.
|
|
599
|
+
*
|
|
600
|
+
* @param value - The value.
|
|
601
|
+
* @returns `true` for an object.
|
|
602
|
+
*/
|
|
603
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
604
|
+
|
|
505
605
|
/**
|
|
506
606
|
* Checks if the current window is running inside a Safe App iframe
|
|
507
607
|
* by attempting postMessage communication with the parent window.
|
|
@@ -523,6 +623,27 @@ declare const isInSecureIframe: boolean;
|
|
|
523
623
|
*/
|
|
524
624
|
declare const isSafeApp: boolean;
|
|
525
625
|
|
|
626
|
+
/**
|
|
627
|
+
* A URL without the slashes at its end.
|
|
628
|
+
*
|
|
629
|
+
* @param url - The URL.
|
|
630
|
+
* @returns The URL without them.
|
|
631
|
+
*/
|
|
632
|
+
declare function trimTrailingSlashes(url: string): string;
|
|
633
|
+
/**
|
|
634
|
+
* Joins a base URL and a path with one slash, as an explorer URL may end in a slash and a path may start with one.
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* joinUrlPath('https://etherscan.io/', '/tx/0x1'); // "https://etherscan.io/tx/0x1"
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @param base - The base URL.
|
|
642
|
+
* @param path - The path. Without it the base comes back as it is.
|
|
643
|
+
* @returns The joined URL.
|
|
644
|
+
*/
|
|
645
|
+
declare function joinUrlPath(base: string, path?: string): string;
|
|
646
|
+
|
|
526
647
|
/**
|
|
527
648
|
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
528
649
|
*/
|
|
@@ -534,12 +655,22 @@ type LastConnectedConnector = {
|
|
|
534
655
|
/** Connected wallet address, if known. */
|
|
535
656
|
address?: string;
|
|
536
657
|
};
|
|
658
|
+
/**
|
|
659
|
+
* Where a connection is kept: `remember: true` keeps it in localStorage until the wallet is disconnected (the default,
|
|
660
|
+
* as before), `remember: false` keeps it in sessionStorage until the tab closes, for people who did not ask to
|
|
661
|
+
* remember the wallet.
|
|
662
|
+
*/
|
|
663
|
+
type WalletMemoryOptions = {
|
|
664
|
+
/** Keep the connection after the tab closes. Defaults to `true`. */
|
|
665
|
+
remember?: boolean;
|
|
666
|
+
};
|
|
537
667
|
/**
|
|
538
668
|
* Helper utilities for managing the last connected wallet state
|
|
539
669
|
*
|
|
540
670
|
* @remarks
|
|
541
|
-
*
|
|
542
|
-
*
|
|
671
|
+
* The data is stored under the 'orbit-core:lastConnectedConnector' key: in localStorage for a remembered wallet, in
|
|
672
|
+
* sessionStorage for one that is kept only until the tab closes ({@link WalletMemoryOptions}). A value in
|
|
673
|
+
* sessionStorage takes precedence when reading. Functions are safe to use in both browser and SSR environments.
|
|
543
674
|
*/
|
|
544
675
|
declare const lastConnectedConnectorHelpers: {
|
|
545
676
|
STORAGE_KEY: string;
|
|
@@ -549,20 +680,28 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
549
680
|
*/
|
|
550
681
|
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
551
682
|
/**
|
|
552
|
-
* Stores the last connected wallet data in localStorage
|
|
683
|
+
* Stores the last connected wallet data: in localStorage when it is remembered (the default), otherwise in
|
|
684
|
+
* sessionStorage; the copy in the other storage is removed.
|
|
553
685
|
*
|
|
554
686
|
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
687
|
+
* @param options - Whether the wallet is remembered after the tab closes.
|
|
555
688
|
* @returns undefined in SSR context, void in browser
|
|
556
689
|
*/
|
|
557
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) => void;
|
|
690
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => void;
|
|
558
691
|
/**
|
|
559
|
-
* Retrieves the current last connected wallet data from localStorage.
|
|
692
|
+
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
560
693
|
*
|
|
561
694
|
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
562
695
|
*/
|
|
563
696
|
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
564
697
|
/**
|
|
565
|
-
*
|
|
698
|
+
* Whether the last connection is remembered after the tab closes.
|
|
699
|
+
*
|
|
700
|
+
* @returns `true` when it is in localStorage, `false` when it is in sessionStorage, undefined when there is none
|
|
701
|
+
*/
|
|
702
|
+
isLastConnectedConnectorRemembered: () => boolean | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* Removes the last connected wallet data from localStorage and sessionStorage.
|
|
566
705
|
*
|
|
567
706
|
* @returns undefined in SSR context, void in browser
|
|
568
707
|
*/
|
|
@@ -623,8 +762,9 @@ type RecentlyConnectedConnectorsList = Record<ConnectorType, RecentlyConnectedCo
|
|
|
623
762
|
* Helper utilities for managing recently connected connectors list with disconnect timestamps
|
|
624
763
|
*
|
|
625
764
|
* @remarks
|
|
626
|
-
*
|
|
627
|
-
*
|
|
765
|
+
* The list is stored under the 'orbit-core:recentlyConnectedConnectorsListHelpers' key: wallets that are remembered in
|
|
766
|
+
* localStorage, wallets kept only until the tab closes in sessionStorage ({@link WalletMemoryOptions}); reading
|
|
767
|
+
* merges both, the sessionStorage entry winning. Functions are safe to use in both browser and SSR environments.
|
|
628
768
|
*
|
|
629
769
|
* The storage contains a record where each key is a ConnectorType and value contains
|
|
630
770
|
* address, disconnectedTimestamp (Unix timestamp in milliseconds), and optional icon for that connector.
|
|
@@ -689,7 +829,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
689
829
|
* });
|
|
690
830
|
* ```
|
|
691
831
|
*/
|
|
692
|
-
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void;
|
|
832
|
+
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void | undefined;
|
|
693
833
|
/**
|
|
694
834
|
* Retrieves the current recently connected connectors list from localStorage.
|
|
695
835
|
*
|
|
@@ -732,7 +872,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
732
872
|
* });
|
|
733
873
|
* ```
|
|
734
874
|
*/
|
|
735
|
-
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData) => undefined;
|
|
875
|
+
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData, options?: WalletMemoryOptions) => undefined;
|
|
736
876
|
/**
|
|
737
877
|
* Removes a single connector from the recently connected connectors list.
|
|
738
878
|
* Preserves all other connectors in the list.
|
|
@@ -831,7 +971,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
831
971
|
* recentlyConnectedConnectorsListHelpers.removeRecentlyConnectedConnectorsList();
|
|
832
972
|
* ```
|
|
833
973
|
*/
|
|
834
|
-
removeRecentlyConnectedConnectorsList: () => void;
|
|
974
|
+
removeRecentlyConnectedConnectorsList: () => void | undefined;
|
|
835
975
|
};
|
|
836
976
|
|
|
837
977
|
/**
|
|
@@ -883,6 +1023,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
883
1023
|
adapterKey: OrbitAdapter;
|
|
884
1024
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
885
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* An address or a hash shortened to its start and end, as wallets show it.
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* shortAddress('0x1111111111111111111111111111111111112222'); // "0x1111…2222"
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* @param address - The address or hash (`0x…` or base58).
|
|
1035
|
+
* @param head - Characters kept at the start; `0x` counts toward it (default `6` for `0x`, `4` otherwise).
|
|
1036
|
+
* @param tail - Characters kept at the end (default `4`).
|
|
1037
|
+
* @returns The shortened value; a value that nothing would be saved on stays unchanged.
|
|
1038
|
+
*/
|
|
1039
|
+
declare function shortAddress(address: string, head?: number, tail?: number): string;
|
|
1040
|
+
|
|
886
1041
|
/**
|
|
887
1042
|
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
888
1043
|
* genesis hash of the cluster.
|
|
@@ -951,4 +1106,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
951
1106
|
*/
|
|
952
1107
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
953
1108
|
|
|
954
|
-
export {
|
|
1109
|
+
export { IMPERSONATED_CONNECTOR_ID, OrbitAdapter, SAFE_CONNECTOR_ID, SOLANA_CHAIN_IDS, delay, detectSafeApp, errorChain, filterUniqueByKey, formatBaseUnits, formatCaip10AccountId, formatCaip19AssetId, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getBrowserStorage, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, getSolanaChainId, getSolanaCluster, getWalletFromConnectorType, globalSingleton, impersonatedHelpers, isAddress, isInSecureIframe, isRecord, isSafeApp, isSameAddress, isSolanaChain, joinUrlPath, lastConnectedConnectorHelpers, normalizeAccountAddress, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, readBrowserStorage, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, shortAddress, toCaip2ChainId, toEvmChainId, trimTrailingSlashes, waitFor };
|
|
1110
|
+
export type { BaseAdapter, Caip10AccountId, Caip19AssetId, Caip2ChainId, ChainIdentifierArray, ConnectorType, LastConnectedConnector, OrbitGenericAdapter, RecentlyConnectedConnectorData, RecentlyConnectedConnectorsList, SolanaCluster, TuwaErrorState, WalletMemoryOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
exports.OrbitAdapter=
|
|
1
|
+
'use strict';var l=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(l||{});function R(e,n){return e==="eip155"?n.toLowerCase():n}function Y(e,n,t){return R(e,n)===R(e,t)}function T(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function k(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function w(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return T(t);case "solana":return k(t);default:return T(t)||k(t)}}function i(e="localStorage"){if(typeof window>"u")return null;try{return window[e]??null}catch{return null}}function f(e,n="localStorage"){try{return i(n)?.getItem(e)??null}catch{return null}}var x={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},S="solana:",E={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function b(e){if(typeof e!="string")return;let n=e.startsWith(S)?e.slice(S.length):e;return Object.hasOwn(E,n)?E[n]:void 0}function u(e){let n=b(e);if(n)return n==="localnet"?`${S}localnet`:x[n]}var A=/^[-a-z0-9]{3,8}$/,v=/^[-_a-zA-Z0-9]{1,32}$/,D=/^[-.%a-zA-Z0-9]{1,128}$/,L=/^[-.%a-zA-Z0-9]{1,128}$/,P=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function m(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),r=e.slice(n+1);return A.test(t)&&v.test(r)?{namespace:t,reference:r}:void 0}function O(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=u(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:m(e)?e:void 0)}function ee(e){let n=typeof e=="number"?e:Number(P.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function I(e,n){return e==="eip155"?w(n,"evm"):e==="solana"?w(n,"solana"):D.test(n)}function ne(e,n){let t=O(e);if(!t)return;let r=m(t),o=n.trim();if(!(!r||!I(r.namespace,o)))return `${t}:${o}`}function te(e){let n=e.lastIndexOf(":");if(n<0)return;let t=m(e.slice(0,n)),r=e.slice(n+1);if(!(!t||!I(t.namespace,r)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:r}}function re(e,n,t){let r=O(e);if(!(!r||!A.test(n)||!L.test(t)))return `${r}/${n}:${t}`}function oe(e){let n=e.indexOf("/");if(n<0)return;let t=m(e.slice(0,n)),r=e.slice(n+1),o=r.indexOf(":");if(!t||o<0)return;let s=r.slice(0,o),p=r.slice(o+1);if(!(!A.test(s)||!L.test(p)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:p}}function ae(e){return b(e)!==void 0}function ce(e){return u(e)??e}var ue=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function pe(e){let n=[];for(let t=e;t!=null&&!n.includes(t);)n.push(t),t=typeof t=="object"?t.cause:void 0;return n}function me(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function Ce(e,n){if(e==null)return;let t=String(e);if(!/^\d+$/.test(t))return;let r=t.padStart(n+1,"0"),o=r.slice(0,r.length-n).replace(/^0+(?=\d)/,""),s=r.slice(r.length-n).replace(/0+$/,"");return s?`${o}.${s}`:o}function xe(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=u(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var j="impersonatedwallet",B="safe",F=new Map([["Impersonated Connector",j],["Safe",B],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),$=e=>F.get(e)??e.replace(/\s+/g,"").toLowerCase();function Te(e){return e?.split(":")[0]??"evm"}function Le(e,n){return `${e}:${$(n)}`}var Ne=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:x.mainnet,name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e,n="localStorage"){let t=f(e,n);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from ${n}:`,r);return}}function De(e){return e?.split(":")[1]}function je(e,n){let t=globalThis,r=Symbol.for(e);return t[r]??=n()}var g="satellite-connect:impersonatedAddress",Ue={impersonatedAddress:f(g)??"",setImpersonated:e=>i()?.setItem(g,e),getImpersonated:()=>typeof window<"u"?f(g):void 0,removeImpersonated:()=>i()?.removeItem(g)};function ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Ke(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(s){s.data&&typeof s.data=="object"&&("safeAddress"in s.data||s.data.data&&"safeAddress"in s.data.data||s.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 U=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",Ve=U;function W(e){return e.replace(/\/+$/,"")}function He(e,n){return n?`${W(e)}/${n.replace(/^\/+/,"")}`:e}var c="orbit-core:lastConnectedConnector",N=()=>a(c,"sessionStorage")??a(c),Qe={STORAGE_KEY:c,lastConnectedConnector:N(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},r={})=>{let o=r.remember??true,[s,p]=o?[i("localStorage"),i("sessionStorage")]:[i("sessionStorage"),i("localStorage")];s?.setItem(c,JSON.stringify({connectorType:e,chainId:n,address:t})),p?.removeItem(c);},getLastConnectedConnector:()=>N(),isLastConnectedConnectorRemembered:()=>{if(a(c,"sessionStorage"))return false;if(a(c))return true},removeLastConnectedConnector:()=>{i("localStorage")?.removeItem(c),i("sessionStorage")?.removeItem(c);}};var z=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function J(){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 K(e){let n={};if(e&&typeof e=="object"){for(let t of z)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function M(e){try{let n=J(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function en(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=K(e),r=M(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:{...M(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var d="orbit-core:recentlyConnectedConnectorsListHelpers",h=e=>a(d,e)??{},C=(e,n)=>i(e)?.setItem(d,JSON.stringify(n)),_=(e,n)=>{let{[n]:t,...r}=e;return r},y={STORAGE_KEY:d,recentlyConnectedConnectorsList:a(d),setRecentlyConnectedConnectorsList:e=>i()?.setItem(d,JSON.stringify(e)),getRecentlyConnectedConnectorsList:()=>{let e=a(d),n=a(d,"sessionStorage");if(!(!e&&!n))return {...e,...n}},addConnector:(e,n,t={})=>{if(typeof window>"u")return;let[r,o]=t.remember??true?["localStorage","sessionStorage"]:["sessionStorage","localStorage"];C(r,{...h(r),[e]:n});let s=h(o);e in s&&C(o,_(s,e));},removeConnector:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=h(n);e in t&&C(n,_(t,e));}},hasConnector:e=>{if(typeof window>"u")return;let n=y.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:y.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=y.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=y.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=a(d,n);if(!t)continue;let r=Object.fromEntries(Object.entries(t).filter(([,o])=>o.disconnectedTimestamp>=e));C(n,r);}},removeRecentlyConnectedConnectorsList:()=>i()?.removeItem(d)};var sn=({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};function cn(e,n=e.startsWith("0x")?6:4,t=4){return e.length<=n+t+1?e:`${e.slice(0,n)}\u2026${e.slice(-t)}`}async function un(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.IMPERSONATED_CONNECTOR_ID=j;exports.OrbitAdapter=l;exports.SAFE_CONNECTOR_ID=B;exports.SOLANA_CHAIN_IDS=x;exports.delay=ue;exports.detectSafeApp=Ke;exports.errorChain=pe;exports.filterUniqueByKey=me;exports.formatBaseUnits=Ce;exports.formatCaip10AccountId=ne;exports.formatCaip19AssetId=re;exports.formatConnectorChainId=xe;exports.formatConnectorName=$;exports.getAdapterFromConnectorType=Te;exports.getBrowserStorage=i;exports.getConnectorTypeFromName=Le;exports.getNetworkData=Ne;exports.getParsedStorageItem=a;exports.getSolanaChainId=u;exports.getSolanaCluster=b;exports.getWalletFromConnectorType=De;exports.globalSingleton=je;exports.impersonatedHelpers=Ue;exports.isAddress=w;exports.isInSecureIframe=U;exports.isRecord=ze;exports.isSafeApp=Ve;exports.isSameAddress=Y;exports.isSolanaChain=ae;exports.joinUrlPath=He;exports.lastConnectedConnectorHelpers=Qe;exports.normalizeAccountAddress=R;exports.normalizeError=en;exports.parseCaip10AccountId=te;exports.parseCaip19AssetId=oe;exports.parseCaip2ChainId=m;exports.readBrowserStorage=f;exports.recentlyConnectedConnectorsListHelpers=y;exports.selectAdapterByKey=sn;exports.setChainId=ce;exports.shortAddress=cn;exports.toCaip2ChainId=O;exports.toEvmChainId=ee;exports.trimTrailingSlashes=W;exports.waitFor=un;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var l=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(l||{});function R(e,n){return e==="eip155"?n.toLowerCase():n}function Y(e,n,t){return R(e,n)===R(e,t)}function T(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function k(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function w(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return T(t);case "solana":return k(t);default:return T(t)||k(t)}}function i(e="localStorage"){if(typeof window>"u")return null;try{return window[e]??null}catch{return null}}function f(e,n="localStorage"){try{return i(n)?.getItem(e)??null}catch{return null}}var x={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},S="solana:",E={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function b(e){if(typeof e!="string")return;let n=e.startsWith(S)?e.slice(S.length):e;return Object.hasOwn(E,n)?E[n]:void 0}function u(e){let n=b(e);if(n)return n==="localnet"?`${S}localnet`:x[n]}var A=/^[-a-z0-9]{3,8}$/,v=/^[-_a-zA-Z0-9]{1,32}$/,D=/^[-.%a-zA-Z0-9]{1,128}$/,L=/^[-.%a-zA-Z0-9]{1,128}$/,P=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function m(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),r=e.slice(n+1);return A.test(t)&&v.test(r)?{namespace:t,reference:r}:void 0}function O(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=u(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:m(e)?e:void 0)}function ee(e){let n=typeof e=="number"?e:Number(P.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function I(e,n){return e==="eip155"?w(n,"evm"):e==="solana"?w(n,"solana"):D.test(n)}function ne(e,n){let t=O(e);if(!t)return;let r=m(t),o=n.trim();if(!(!r||!I(r.namespace,o)))return `${t}:${o}`}function te(e){let n=e.lastIndexOf(":");if(n<0)return;let t=m(e.slice(0,n)),r=e.slice(n+1);if(!(!t||!I(t.namespace,r)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:r}}function re(e,n,t){let r=O(e);if(!(!r||!A.test(n)||!L.test(t)))return `${r}/${n}:${t}`}function oe(e){let n=e.indexOf("/");if(n<0)return;let t=m(e.slice(0,n)),r=e.slice(n+1),o=r.indexOf(":");if(!t||o<0)return;let s=r.slice(0,o),p=r.slice(o+1);if(!(!A.test(s)||!L.test(p)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:p}}function ae(e){return b(e)!==void 0}function ce(e){return u(e)??e}var ue=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function pe(e){let n=[];for(let t=e;t!=null&&!n.includes(t);)n.push(t),t=typeof t=="object"?t.cause:void 0;return n}function me(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function Ce(e,n){if(e==null)return;let t=String(e);if(!/^\d+$/.test(t))return;let r=t.padStart(n+1,"0"),o=r.slice(0,r.length-n).replace(/^0+(?=\d)/,""),s=r.slice(r.length-n).replace(/0+$/,"");return s?`${o}.${s}`:o}function xe(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=u(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var j="impersonatedwallet",B="safe",F=new Map([["Impersonated Connector",j],["Safe",B],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),$=e=>F.get(e)??e.replace(/\s+/g,"").toLowerCase();function Te(e){return e?.split(":")[0]??"evm"}function Le(e,n){return `${e}:${$(n)}`}var Ne=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:x.mainnet,name:"Solana"},links:{aboutNetwork:"https://solana.com/en/learn/what-is-solana",choseWallet:"https://solana.com/en/solana-wallets",about:"https://solana.com/en/learn/what-is-a-wallet"}}}};function a(e,n="localStorage"){let t=f(e,n);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from ${n}:`,r);return}}function De(e){return e?.split(":")[1]}function je(e,n){let t=globalThis,r=Symbol.for(e);return t[r]??=n()}var g="satellite-connect:impersonatedAddress",Ue={impersonatedAddress:f(g)??"",setImpersonated:e=>i()?.setItem(g,e),getImpersonated:()=>typeof window<"u"?f(g):void 0,removeImpersonated:()=>i()?.removeItem(g)};function ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Ke(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(s){s.data&&typeof s.data=="object"&&("safeAddress"in s.data||s.data.data&&"safeAddress"in s.data.data||s.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 U=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",Ve=U;function W(e){return e.replace(/\/+$/,"")}function He(e,n){return n?`${W(e)}/${n.replace(/^\/+/,"")}`:e}var c="orbit-core:lastConnectedConnector",N=()=>a(c,"sessionStorage")??a(c),Qe={STORAGE_KEY:c,lastConnectedConnector:N(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},r={})=>{let o=r.remember??true,[s,p]=o?[i("localStorage"),i("sessionStorage")]:[i("sessionStorage"),i("localStorage")];s?.setItem(c,JSON.stringify({connectorType:e,chainId:n,address:t})),p?.removeItem(c);},getLastConnectedConnector:()=>N(),isLastConnectedConnectorRemembered:()=>{if(a(c,"sessionStorage"))return false;if(a(c))return true},removeLastConnectedConnector:()=>{i("localStorage")?.removeItem(c),i("sessionStorage")?.removeItem(c);}};var z=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function J(){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 K(e){let n={};if(e&&typeof e=="object"){for(let t of z)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function M(e){try{let n=J(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function en(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=K(e),r=M(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:{...M(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var d="orbit-core:recentlyConnectedConnectorsListHelpers",h=e=>a(d,e)??{},C=(e,n)=>i(e)?.setItem(d,JSON.stringify(n)),_=(e,n)=>{let{[n]:t,...r}=e;return r},y={STORAGE_KEY:d,recentlyConnectedConnectorsList:a(d),setRecentlyConnectedConnectorsList:e=>i()?.setItem(d,JSON.stringify(e)),getRecentlyConnectedConnectorsList:()=>{let e=a(d),n=a(d,"sessionStorage");if(!(!e&&!n))return {...e,...n}},addConnector:(e,n,t={})=>{if(typeof window>"u")return;let[r,o]=t.remember??true?["localStorage","sessionStorage"]:["sessionStorage","localStorage"];C(r,{...h(r),[e]:n});let s=h(o);e in s&&C(o,_(s,e));},removeConnector:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=h(n);e in t&&C(n,_(t,e));}},hasConnector:e=>{if(typeof window>"u")return;let n=y.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:y.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=y.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=y.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=a(d,n);if(!t)continue;let r=Object.fromEntries(Object.entries(t).filter(([,o])=>o.disconnectedTimestamp>=e));C(n,r);}},removeRecentlyConnectedConnectorsList:()=>i()?.removeItem(d)};var sn=({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};function cn(e,n=e.startsWith("0x")?6:4,t=4){return e.length<=n+t+1?e:`${e.slice(0,n)}\u2026${e.slice(-t)}`}async function un(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{j as IMPERSONATED_CONNECTOR_ID,l as OrbitAdapter,B as SAFE_CONNECTOR_ID,x as SOLANA_CHAIN_IDS,ue as delay,Ke as detectSafeApp,pe as errorChain,me as filterUniqueByKey,Ce as formatBaseUnits,ne as formatCaip10AccountId,re as formatCaip19AssetId,xe as formatConnectorChainId,$ as formatConnectorName,Te as getAdapterFromConnectorType,i as getBrowserStorage,Le as getConnectorTypeFromName,Ne as getNetworkData,a as getParsedStorageItem,u as getSolanaChainId,b as getSolanaCluster,De as getWalletFromConnectorType,je as globalSingleton,Ue as impersonatedHelpers,w as isAddress,U as isInSecureIframe,ze as isRecord,Ve as isSafeApp,Y as isSameAddress,ae as isSolanaChain,He as joinUrlPath,Qe as lastConnectedConnectorHelpers,R as normalizeAccountAddress,en as normalizeError,te as parseCaip10AccountId,oe as parseCaip19AssetId,m as parseCaip2ChainId,f as readBrowserStorage,y as recentlyConnectedConnectorsListHelpers,sn as selectAdapterByKey,ce as setChainId,cn as shortAddress,O as toCaip2ChainId,ee as toEvmChainId,W as trimTrailingSlashes,un as waitFor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/orbit-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"tsup": "^
|
|
45
|
+
"tsup": "^9.0.0",
|
|
46
46
|
"typescript": "6.0.3"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|