@tuwaio/orbit-core 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +162 -17
- package/dist/index.d.ts +162 -17
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ isAddress('So11111111111111111111111111111111111111112', 'solana'); // true
|
|
|
108
108
|
|
|
109
109
|
## 🗄️ Browser Storage
|
|
110
110
|
|
|
111
|
-
The storage helpers write the following keys. Clear them to reset the connection state of a user:
|
|
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
113
|
| Key | Written by | Where |
|
|
114
114
|
| --------------------------------------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
package/dist/index.d.mts
CHANGED
|
@@ -125,6 +125,35 @@ 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
|
+
/**
|
|
147
|
+
* Whether two addresses of one adapter are the same account: {@link isSameAddress} for what knows its adapter and not its
|
|
148
|
+
* CAIP-2 namespace, such as a transaction.
|
|
149
|
+
*
|
|
150
|
+
* @param adapter - The adapter of both addresses.
|
|
151
|
+
* @param left - One address.
|
|
152
|
+
* @param right - The other address.
|
|
153
|
+
* @returns `true` when they are the same account.
|
|
154
|
+
*/
|
|
155
|
+
declare function isSameAdapterAddress(adapter: OrbitAdapter, left: string, right: string): boolean;
|
|
156
|
+
|
|
128
157
|
/**
|
|
129
158
|
* Universal address validation function that supports multiple blockchain formats
|
|
130
159
|
* @param value - Address string to validate
|
|
@@ -133,6 +162,23 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
162
|
*/
|
|
134
163
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
164
|
|
|
165
|
+
/**
|
|
166
|
+
* The storage of the browser, reached safely. A browser that blocks site data throws on reaching `window.localStorage`,
|
|
167
|
+
* not on what is called on it, so a guard on `typeof window` is not enough.
|
|
168
|
+
*
|
|
169
|
+
* @param area - The storage to reach: `localStorage` (default) or `sessionStorage`.
|
|
170
|
+
* @returns The storage, or `null` without a browser or when the browser refuses it.
|
|
171
|
+
*/
|
|
172
|
+
declare function getBrowserStorage(area?: 'localStorage' | 'sessionStorage'): Storage | null;
|
|
173
|
+
/**
|
|
174
|
+
* Reads a value of the browser's storage. Never throws.
|
|
175
|
+
*
|
|
176
|
+
* @param key - The storage key.
|
|
177
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`.
|
|
178
|
+
* @returns The value, or `null` when it is not set, without a browser, or when the browser refuses it.
|
|
179
|
+
*/
|
|
180
|
+
declare function readBrowserStorage(key: string, area?: 'localStorage' | 'sessionStorage'): string | null;
|
|
181
|
+
|
|
136
182
|
/**
|
|
137
183
|
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
184
|
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
@@ -312,6 +358,15 @@ declare function setChainId(chainId: number | string): string | number;
|
|
|
312
358
|
*/
|
|
313
359
|
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
314
360
|
|
|
361
|
+
/**
|
|
362
|
+
* An error and the causes it wraps, of any kind, as wallet libraries wrap what the wallet answered several levels down.
|
|
363
|
+
* A cause that loops ends the list.
|
|
364
|
+
*
|
|
365
|
+
* @param error - What was thrown.
|
|
366
|
+
* @returns The error first, then each `cause` in turn; empty for `null` or `undefined`.
|
|
367
|
+
*/
|
|
368
|
+
declare function errorChain(error: unknown): unknown[];
|
|
369
|
+
|
|
315
370
|
/**
|
|
316
371
|
* Filters an array of objects to keep only the first occurrence of an object
|
|
317
372
|
* based on a unique value of a specified key.
|
|
@@ -326,6 +381,22 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
326
381
|
*/
|
|
327
382
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
328
383
|
|
|
384
|
+
/**
|
|
385
|
+
* An integer amount in the smallest unit of a currency as a decimal number, for example wei as gwei (`decimals` 9) or
|
|
386
|
+
* lamports as SOL (`decimals` 9): exact, with a dot, without grouping, trailing zeros or rounding.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* formatBaseUnits('89540000', 6); // "89.54"
|
|
391
|
+
* formatBaseUnits(1500000000n, 9); // "1.5"
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @param value - The amount, as a number, a decimal string or a bigint.
|
|
395
|
+
* @param decimals - The number of decimals of the displayed unit.
|
|
396
|
+
* @returns The decimal string, or `undefined` when `value` is missing, negative or not an integer.
|
|
397
|
+
*/
|
|
398
|
+
declare function formatBaseUnits(value: string | number | bigint | null | undefined, decimals: number): string | undefined;
|
|
399
|
+
|
|
329
400
|
/**
|
|
330
401
|
* Formats a chain ID for use in connector identifiers.
|
|
331
402
|
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
@@ -344,6 +415,10 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
344
415
|
*/
|
|
345
416
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
346
417
|
|
|
418
|
+
/** The connector ID of the impersonated wallet. It is saved in the last connection, so it can never change. */
|
|
419
|
+
declare const IMPERSONATED_CONNECTOR_ID = "impersonatedwallet";
|
|
420
|
+
/** The connector ID of Safe{Wallet}. It is saved in the last connection, so it can never change. */
|
|
421
|
+
declare const SAFE_CONNECTOR_ID = "safe";
|
|
347
422
|
/**
|
|
348
423
|
* Normalizes a wallet connector display name into a stable identifier.
|
|
349
424
|
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
@@ -397,21 +472,21 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
397
472
|
*
|
|
398
473
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
399
474
|
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
475
|
+
*
|
|
476
|
+
* // Returns "evm:coinbase" (a known name, by formatConnectorName)
|
|
477
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Base Account");
|
|
400
478
|
* ```
|
|
401
479
|
*
|
|
402
480
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
403
|
-
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
481
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom"), as the wallet reports it or as {@link formatConnectorName} gave it
|
|
404
482
|
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
405
483
|
*
|
|
406
484
|
* @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;
|
|
485
|
+
* The function goes through {@link formatConnectorName}: known names are mapped, any other has its whitespace removed
|
|
486
|
+
* and is lowercased. So one wallet has one type wherever it is read, on its connection and on its transactions, and a
|
|
487
|
+
* value that already went through the mapping stays as it is.
|
|
488
|
+
*/
|
|
489
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): ConnectorType;
|
|
415
490
|
|
|
416
491
|
/**
|
|
417
492
|
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
@@ -449,10 +524,36 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
449
524
|
*
|
|
450
525
|
* @param key - The storage key
|
|
451
526
|
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
452
|
-
* @returns The parsed value or undefined if data is not found/invalid,
|
|
527
|
+
* @returns The parsed value or undefined if data is not found/invalid, in an SSR context, or when the browser refuses
|
|
528
|
+
* the storage
|
|
453
529
|
*/
|
|
454
530
|
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
455
531
|
|
|
532
|
+
/**
|
|
533
|
+
* The wallet part of a connector type.
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* ```typescript
|
|
537
|
+
* getWalletFromConnectorType('evm:metamask'); // "metamask"
|
|
538
|
+
* getWalletFromConnectorType('metamask'); // undefined
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* @param connectorType - A connector type, in the format "orbit-adapter:connector".
|
|
542
|
+
* @returns The part after the adapter, or `undefined` when there is no adapter or no value.
|
|
543
|
+
*/
|
|
544
|
+
declare function getWalletFromConnectorType(connectorType: string | null | undefined): string | undefined;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* One object for all copies of a package on a page, kept on `globalThis` under `Symbol.for(key)`. A bundler can load a
|
|
548
|
+
* package twice, and two copies of a React context or a registry do not see each other.
|
|
549
|
+
*
|
|
550
|
+
* @template T - The type of the object.
|
|
551
|
+
* @param key - The name of the symbol. It must never change: published copies find each other through it.
|
|
552
|
+
* @param create - Makes the object, called only when no copy has made it yet.
|
|
553
|
+
* @returns The object.
|
|
554
|
+
*/
|
|
555
|
+
declare function globalSingleton<T>(key: string, create: () => T): T;
|
|
556
|
+
|
|
456
557
|
/**
|
|
457
558
|
* Helper utilities for managing impersonated wallet addresses
|
|
458
559
|
*
|
|
@@ -480,7 +581,7 @@ declare const impersonatedHelpers: {
|
|
|
480
581
|
* @param address - Ethereum or Solana address to impersonate
|
|
481
582
|
* @returns undefined in SSR context, void in browser
|
|
482
583
|
*/
|
|
483
|
-
setImpersonated: (address: string) => void;
|
|
584
|
+
setImpersonated: (address: string) => void | undefined;
|
|
484
585
|
/**
|
|
485
586
|
* Retrieves the current impersonated address from localStorage
|
|
486
587
|
*
|
|
@@ -500,9 +601,17 @@ declare const impersonatedHelpers: {
|
|
|
500
601
|
*
|
|
501
602
|
* @returns undefined in SSR context, void in browser
|
|
502
603
|
*/
|
|
503
|
-
removeImpersonated: () => void;
|
|
604
|
+
removeImpersonated: () => void | undefined;
|
|
504
605
|
};
|
|
505
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Whether a value is an object with fields to read: anything but `null` and an array, class instances included.
|
|
609
|
+
*
|
|
610
|
+
* @param value - The value.
|
|
611
|
+
* @returns `true` for an object.
|
|
612
|
+
*/
|
|
613
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
614
|
+
|
|
506
615
|
/**
|
|
507
616
|
* Checks if the current window is running inside a Safe App iframe
|
|
508
617
|
* by attempting postMessage communication with the parent window.
|
|
@@ -524,6 +633,27 @@ declare const isInSecureIframe: boolean;
|
|
|
524
633
|
*/
|
|
525
634
|
declare const isSafeApp: boolean;
|
|
526
635
|
|
|
636
|
+
/**
|
|
637
|
+
* A URL without the slashes at its end.
|
|
638
|
+
*
|
|
639
|
+
* @param url - The URL.
|
|
640
|
+
* @returns The URL without them.
|
|
641
|
+
*/
|
|
642
|
+
declare function trimTrailingSlashes(url: string): string;
|
|
643
|
+
/**
|
|
644
|
+
* 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.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* joinUrlPath('https://etherscan.io/', '/tx/0x1'); // "https://etherscan.io/tx/0x1"
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @param base - The base URL.
|
|
652
|
+
* @param path - The path. Without it the base comes back as it is.
|
|
653
|
+
* @returns The joined URL.
|
|
654
|
+
*/
|
|
655
|
+
declare function joinUrlPath(base: string, path?: string): string;
|
|
656
|
+
|
|
527
657
|
/**
|
|
528
658
|
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
529
659
|
*/
|
|
@@ -567,7 +697,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
567
697
|
* @param options - Whether the wallet is remembered after the tab closes.
|
|
568
698
|
* @returns undefined in SSR context, void in browser
|
|
569
699
|
*/
|
|
570
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) =>
|
|
700
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => void;
|
|
571
701
|
/**
|
|
572
702
|
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
573
703
|
*
|
|
@@ -585,7 +715,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
585
715
|
*
|
|
586
716
|
* @returns undefined in SSR context, void in browser
|
|
587
717
|
*/
|
|
588
|
-
removeLastConnectedConnector: () =>
|
|
718
|
+
removeLastConnectedConnector: () => void;
|
|
589
719
|
};
|
|
590
720
|
|
|
591
721
|
/**
|
|
@@ -709,7 +839,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
709
839
|
* });
|
|
710
840
|
* ```
|
|
711
841
|
*/
|
|
712
|
-
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void;
|
|
842
|
+
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void | undefined;
|
|
713
843
|
/**
|
|
714
844
|
* Retrieves the current recently connected connectors list from localStorage.
|
|
715
845
|
*
|
|
@@ -851,7 +981,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
851
981
|
* recentlyConnectedConnectorsListHelpers.removeRecentlyConnectedConnectorsList();
|
|
852
982
|
* ```
|
|
853
983
|
*/
|
|
854
|
-
removeRecentlyConnectedConnectorsList: () => void;
|
|
984
|
+
removeRecentlyConnectedConnectorsList: () => void | undefined;
|
|
855
985
|
};
|
|
856
986
|
|
|
857
987
|
/**
|
|
@@ -903,6 +1033,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
903
1033
|
adapterKey: OrbitAdapter;
|
|
904
1034
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
905
1035
|
|
|
1036
|
+
/**
|
|
1037
|
+
* An address or a hash shortened to its start and end, as wallets show it.
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* shortAddress('0x1111111111111111111111111111111111112222'); // "0x1111…2222"
|
|
1042
|
+
* ```
|
|
1043
|
+
*
|
|
1044
|
+
* @param address - The address or hash (`0x…` or base58).
|
|
1045
|
+
* @param head - Characters kept at the start; `0x` counts toward it (default `6` for `0x`, `4` otherwise).
|
|
1046
|
+
* @param tail - Characters kept at the end (default `4`).
|
|
1047
|
+
* @returns The shortened value; a value that nothing would be saved on stays unchanged.
|
|
1048
|
+
*/
|
|
1049
|
+
declare function shortAddress(address: string, head?: number, tail?: number): string;
|
|
1050
|
+
|
|
906
1051
|
/**
|
|
907
1052
|
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
908
1053
|
* genesis hash of the cluster.
|
|
@@ -971,5 +1116,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
971
1116
|
*/
|
|
972
1117
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
973
1118
|
|
|
974
|
-
export { OrbitAdapter, SOLANA_CHAIN_IDS, 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 };
|
|
1119
|
+
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, isSameAdapterAddress, isSameAddress, isSolanaChain, joinUrlPath, lastConnectedConnectorHelpers, normalizeAccountAddress, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, readBrowserStorage, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, shortAddress, toCaip2ChainId, toEvmChainId, trimTrailingSlashes, waitFor };
|
|
975
1120
|
export type { BaseAdapter, Caip10AccountId, Caip19AssetId, Caip2ChainId, ChainIdentifierArray, ConnectorType, LastConnectedConnector, OrbitGenericAdapter, RecentlyConnectedConnectorData, RecentlyConnectedConnectorsList, SolanaCluster, TuwaErrorState, WalletMemoryOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,35 @@ 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
|
+
/**
|
|
147
|
+
* Whether two addresses of one adapter are the same account: {@link isSameAddress} for what knows its adapter and not its
|
|
148
|
+
* CAIP-2 namespace, such as a transaction.
|
|
149
|
+
*
|
|
150
|
+
* @param adapter - The adapter of both addresses.
|
|
151
|
+
* @param left - One address.
|
|
152
|
+
* @param right - The other address.
|
|
153
|
+
* @returns `true` when they are the same account.
|
|
154
|
+
*/
|
|
155
|
+
declare function isSameAdapterAddress(adapter: OrbitAdapter, left: string, right: string): boolean;
|
|
156
|
+
|
|
128
157
|
/**
|
|
129
158
|
* Universal address validation function that supports multiple blockchain formats
|
|
130
159
|
* @param value - Address string to validate
|
|
@@ -133,6 +162,23 @@ type ChainIdentifierArray = readonly (string | number)[];
|
|
|
133
162
|
*/
|
|
134
163
|
declare function isAddress(value: string, type?: 'evm' | 'solana' | 'auto'): boolean;
|
|
135
164
|
|
|
165
|
+
/**
|
|
166
|
+
* The storage of the browser, reached safely. A browser that blocks site data throws on reaching `window.localStorage`,
|
|
167
|
+
* not on what is called on it, so a guard on `typeof window` is not enough.
|
|
168
|
+
*
|
|
169
|
+
* @param area - The storage to reach: `localStorage` (default) or `sessionStorage`.
|
|
170
|
+
* @returns The storage, or `null` without a browser or when the browser refuses it.
|
|
171
|
+
*/
|
|
172
|
+
declare function getBrowserStorage(area?: 'localStorage' | 'sessionStorage'): Storage | null;
|
|
173
|
+
/**
|
|
174
|
+
* Reads a value of the browser's storage. Never throws.
|
|
175
|
+
*
|
|
176
|
+
* @param key - The storage key.
|
|
177
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`.
|
|
178
|
+
* @returns The value, or `null` when it is not set, without a browser, or when the browser refuses it.
|
|
179
|
+
*/
|
|
180
|
+
declare function readBrowserStorage(key: string, area?: 'localStorage' | 'sessionStorage'): string | null;
|
|
181
|
+
|
|
136
182
|
/**
|
|
137
183
|
* A CAIP-2 chain ID: `<namespace>:<reference>`, for example `eip155:8453` or
|
|
138
184
|
* `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
@@ -312,6 +358,15 @@ declare function setChainId(chainId: number | string): string | number;
|
|
|
312
358
|
*/
|
|
313
359
|
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
314
360
|
|
|
361
|
+
/**
|
|
362
|
+
* An error and the causes it wraps, of any kind, as wallet libraries wrap what the wallet answered several levels down.
|
|
363
|
+
* A cause that loops ends the list.
|
|
364
|
+
*
|
|
365
|
+
* @param error - What was thrown.
|
|
366
|
+
* @returns The error first, then each `cause` in turn; empty for `null` or `undefined`.
|
|
367
|
+
*/
|
|
368
|
+
declare function errorChain(error: unknown): unknown[];
|
|
369
|
+
|
|
315
370
|
/**
|
|
316
371
|
* Filters an array of objects to keep only the first occurrence of an object
|
|
317
372
|
* based on a unique value of a specified key.
|
|
@@ -326,6 +381,22 @@ declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
|
326
381
|
*/
|
|
327
382
|
declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
328
383
|
|
|
384
|
+
/**
|
|
385
|
+
* An integer amount in the smallest unit of a currency as a decimal number, for example wei as gwei (`decimals` 9) or
|
|
386
|
+
* lamports as SOL (`decimals` 9): exact, with a dot, without grouping, trailing zeros or rounding.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* formatBaseUnits('89540000', 6); // "89.54"
|
|
391
|
+
* formatBaseUnits(1500000000n, 9); // "1.5"
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @param value - The amount, as a number, a decimal string or a bigint.
|
|
395
|
+
* @param decimals - The number of decimals of the displayed unit.
|
|
396
|
+
* @returns The decimal string, or `undefined` when `value` is missing, negative or not an integer.
|
|
397
|
+
*/
|
|
398
|
+
declare function formatBaseUnits(value: string | number | bigint | null | undefined, decimals: number): string | undefined;
|
|
399
|
+
|
|
329
400
|
/**
|
|
330
401
|
* Formats a chain ID for use in connector identifiers.
|
|
331
402
|
* Solana clusters become CAIP-2 chain IDs with the genesis hash (see {@link getSolanaChainId}); other string chain
|
|
@@ -344,6 +415,10 @@ declare function filterUniqueByKey<T>(array: T[], key: keyof T): T[];
|
|
|
344
415
|
*/
|
|
345
416
|
declare function formatConnectorChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
346
417
|
|
|
418
|
+
/** The connector ID of the impersonated wallet. It is saved in the last connection, so it can never change. */
|
|
419
|
+
declare const IMPERSONATED_CONNECTOR_ID = "impersonatedwallet";
|
|
420
|
+
/** The connector ID of Safe{Wallet}. It is saved in the last connection, so it can never change. */
|
|
421
|
+
declare const SAFE_CONNECTOR_ID = "safe";
|
|
347
422
|
/**
|
|
348
423
|
* Normalizes a wallet connector display name into a stable identifier.
|
|
349
424
|
* Known names are mapped explicitly (e.g. "Trust Wallet" → "trust", "Base Account" → "coinbase");
|
|
@@ -397,21 +472,21 @@ declare function getAdapterFromConnectorType(connectorType: ConnectorType): Orbi
|
|
|
397
472
|
*
|
|
398
473
|
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
399
474
|
* getConnectorTypeFromName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
475
|
+
*
|
|
476
|
+
* // Returns "evm:coinbase" (a known name, by formatConnectorName)
|
|
477
|
+
* getConnectorTypeFromName(OrbitAdapter.EVM, "Base Account");
|
|
400
478
|
* ```
|
|
401
479
|
*
|
|
402
480
|
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
403
|
-
* @param name - The connector name (e.g. "MetaMask", "Phantom")
|
|
481
|
+
* @param name - The connector name (e.g. "MetaMask", "Phantom"), as the wallet reports it or as {@link formatConnectorName} gave it
|
|
404
482
|
* @returns A formatted connector type string in format "orbit-adapter:connector"
|
|
405
483
|
*
|
|
406
484
|
* @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;
|
|
485
|
+
* The function goes through {@link formatConnectorName}: known names are mapped, any other has its whitespace removed
|
|
486
|
+
* and is lowercased. So one wallet has one type wherever it is read, on its connection and on its transactions, and a
|
|
487
|
+
* value that already went through the mapping stays as it is.
|
|
488
|
+
*/
|
|
489
|
+
declare function getConnectorTypeFromName(adapter: OrbitAdapter, name: string): ConnectorType;
|
|
415
490
|
|
|
416
491
|
/**
|
|
417
492
|
* Returns the default network and educational links for an adapter, e.g. to render a
|
|
@@ -449,10 +524,36 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
449
524
|
*
|
|
450
525
|
* @param key - The storage key
|
|
451
526
|
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
452
|
-
* @returns The parsed value or undefined if data is not found/invalid,
|
|
527
|
+
* @returns The parsed value or undefined if data is not found/invalid, in an SSR context, or when the browser refuses
|
|
528
|
+
* the storage
|
|
453
529
|
*/
|
|
454
530
|
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
455
531
|
|
|
532
|
+
/**
|
|
533
|
+
* The wallet part of a connector type.
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* ```typescript
|
|
537
|
+
* getWalletFromConnectorType('evm:metamask'); // "metamask"
|
|
538
|
+
* getWalletFromConnectorType('metamask'); // undefined
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* @param connectorType - A connector type, in the format "orbit-adapter:connector".
|
|
542
|
+
* @returns The part after the adapter, or `undefined` when there is no adapter or no value.
|
|
543
|
+
*/
|
|
544
|
+
declare function getWalletFromConnectorType(connectorType: string | null | undefined): string | undefined;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* One object for all copies of a package on a page, kept on `globalThis` under `Symbol.for(key)`. A bundler can load a
|
|
548
|
+
* package twice, and two copies of a React context or a registry do not see each other.
|
|
549
|
+
*
|
|
550
|
+
* @template T - The type of the object.
|
|
551
|
+
* @param key - The name of the symbol. It must never change: published copies find each other through it.
|
|
552
|
+
* @param create - Makes the object, called only when no copy has made it yet.
|
|
553
|
+
* @returns The object.
|
|
554
|
+
*/
|
|
555
|
+
declare function globalSingleton<T>(key: string, create: () => T): T;
|
|
556
|
+
|
|
456
557
|
/**
|
|
457
558
|
* Helper utilities for managing impersonated wallet addresses
|
|
458
559
|
*
|
|
@@ -480,7 +581,7 @@ declare const impersonatedHelpers: {
|
|
|
480
581
|
* @param address - Ethereum or Solana address to impersonate
|
|
481
582
|
* @returns undefined in SSR context, void in browser
|
|
482
583
|
*/
|
|
483
|
-
setImpersonated: (address: string) => void;
|
|
584
|
+
setImpersonated: (address: string) => void | undefined;
|
|
484
585
|
/**
|
|
485
586
|
* Retrieves the current impersonated address from localStorage
|
|
486
587
|
*
|
|
@@ -500,9 +601,17 @@ declare const impersonatedHelpers: {
|
|
|
500
601
|
*
|
|
501
602
|
* @returns undefined in SSR context, void in browser
|
|
502
603
|
*/
|
|
503
|
-
removeImpersonated: () => void;
|
|
604
|
+
removeImpersonated: () => void | undefined;
|
|
504
605
|
};
|
|
505
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Whether a value is an object with fields to read: anything but `null` and an array, class instances included.
|
|
609
|
+
*
|
|
610
|
+
* @param value - The value.
|
|
611
|
+
* @returns `true` for an object.
|
|
612
|
+
*/
|
|
613
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
614
|
+
|
|
506
615
|
/**
|
|
507
616
|
* Checks if the current window is running inside a Safe App iframe
|
|
508
617
|
* by attempting postMessage communication with the parent window.
|
|
@@ -524,6 +633,27 @@ declare const isInSecureIframe: boolean;
|
|
|
524
633
|
*/
|
|
525
634
|
declare const isSafeApp: boolean;
|
|
526
635
|
|
|
636
|
+
/**
|
|
637
|
+
* A URL without the slashes at its end.
|
|
638
|
+
*
|
|
639
|
+
* @param url - The URL.
|
|
640
|
+
* @returns The URL without them.
|
|
641
|
+
*/
|
|
642
|
+
declare function trimTrailingSlashes(url: string): string;
|
|
643
|
+
/**
|
|
644
|
+
* 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.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* joinUrlPath('https://etherscan.io/', '/tx/0x1'); // "https://etherscan.io/tx/0x1"
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @param base - The base URL.
|
|
652
|
+
* @param path - The path. Without it the base comes back as it is.
|
|
653
|
+
* @returns The joined URL.
|
|
654
|
+
*/
|
|
655
|
+
declare function joinUrlPath(base: string, path?: string): string;
|
|
656
|
+
|
|
527
657
|
/**
|
|
528
658
|
* Connection data persisted by {@link lastConnectedConnectorHelpers}.
|
|
529
659
|
*/
|
|
@@ -567,7 +697,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
567
697
|
* @param options - Whether the wallet is remembered after the tab closes.
|
|
568
698
|
* @returns undefined in SSR context, void in browser
|
|
569
699
|
*/
|
|
570
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) =>
|
|
700
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => void;
|
|
571
701
|
/**
|
|
572
702
|
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
573
703
|
*
|
|
@@ -585,7 +715,7 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
585
715
|
*
|
|
586
716
|
* @returns undefined in SSR context, void in browser
|
|
587
717
|
*/
|
|
588
|
-
removeLastConnectedConnector: () =>
|
|
718
|
+
removeLastConnectedConnector: () => void;
|
|
589
719
|
};
|
|
590
720
|
|
|
591
721
|
/**
|
|
@@ -709,7 +839,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
709
839
|
* });
|
|
710
840
|
* ```
|
|
711
841
|
*/
|
|
712
|
-
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void;
|
|
842
|
+
setRecentlyConnectedConnectorsList: (connectors: RecentlyConnectedConnectorsList) => void | undefined;
|
|
713
843
|
/**
|
|
714
844
|
* Retrieves the current recently connected connectors list from localStorage.
|
|
715
845
|
*
|
|
@@ -851,7 +981,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
851
981
|
* recentlyConnectedConnectorsListHelpers.removeRecentlyConnectedConnectorsList();
|
|
852
982
|
* ```
|
|
853
983
|
*/
|
|
854
|
-
removeRecentlyConnectedConnectorsList: () => void;
|
|
984
|
+
removeRecentlyConnectedConnectorsList: () => void | undefined;
|
|
855
985
|
};
|
|
856
986
|
|
|
857
987
|
/**
|
|
@@ -903,6 +1033,21 @@ declare const selectAdapterByKey: <A extends {
|
|
|
903
1033
|
adapterKey: OrbitAdapter;
|
|
904
1034
|
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
905
1035
|
|
|
1036
|
+
/**
|
|
1037
|
+
* An address or a hash shortened to its start and end, as wallets show it.
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* shortAddress('0x1111111111111111111111111111111111112222'); // "0x1111…2222"
|
|
1042
|
+
* ```
|
|
1043
|
+
*
|
|
1044
|
+
* @param address - The address or hash (`0x…` or base58).
|
|
1045
|
+
* @param head - Characters kept at the start; `0x` counts toward it (default `6` for `0x`, `4` otherwise).
|
|
1046
|
+
* @param tail - Characters kept at the end (default `4`).
|
|
1047
|
+
* @returns The shortened value; a value that nothing would be saved on stays unchanged.
|
|
1048
|
+
*/
|
|
1049
|
+
declare function shortAddress(address: string, head?: number, tail?: number): string;
|
|
1050
|
+
|
|
906
1051
|
/**
|
|
907
1052
|
* CAIP-2 chain IDs of the public Solana clusters. By CAIP-30, the reference is the first 32 characters of the base58
|
|
908
1053
|
* genesis hash of the cluster.
|
|
@@ -971,5 +1116,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
971
1116
|
*/
|
|
972
1117
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
973
1118
|
|
|
974
|
-
export { OrbitAdapter, SOLANA_CHAIN_IDS, 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 };
|
|
1119
|
+
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, isSameAdapterAddress, isSameAddress, isSolanaChain, joinUrlPath, lastConnectedConnectorHelpers, normalizeAccountAddress, normalizeError, parseCaip10AccountId, parseCaip19AssetId, parseCaip2ChainId, readBrowserStorage, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, shortAddress, toCaip2ChainId, toEvmChainId, trimTrailingSlashes, waitFor };
|
|
975
1120
|
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 f=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(f||{});function R(e,n){return e==="eip155"?n.toLowerCase():n}function v(e,n,t){return R(e,n)===R(e,t)}function q(e,n,t){return v(e==="evm"?"eip155":e,n,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 p(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}$/,D=/^[-_a-zA-Z0-9]{1,32}$/,P=/^[-.%a-zA-Z0-9]{1,128}$/,L=/^[-.%a-zA-Z0-9]{1,128}$/,j=/^(?: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)&&D.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 te(e){let n=typeof e=="number"?e:Number(j.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"):P.test(n)}function re(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 oe(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 se(e,n,t){let r=O(e);if(!(!r||!A.test(n)||!L.test(t)))return `${r}/${n}:${t}`}function ie(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),l=r.slice(o+1);if(!(!A.test(s)||!L.test(l)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:l}}function de(e){return b(e)!==void 0}function ue(e){return u(e)??e}var pe=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function me(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 Ce(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function we(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 Ae(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 B="impersonatedwallet",F="safe",U=new Map([["Impersonated Connector",B],["Safe",F],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),$=e=>U.get(e)??e.replace(/\s+/g,"").toLowerCase();function Ee(e){return e?.split(":")[0]??"evm"}function Ie(e,n){return `${e}:${$(n)}`}var _e=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=p(e,n);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from ${n}:`,r);return}}function je(e){return e?.split(":")[1]}function Fe(e,n){let t=globalThis,r=Symbol.for(e);return t[r]??=n()}var g="satellite-connect:impersonatedAddress",ze={impersonatedAddress:p(g)??"",setImpersonated:e=>i()?.setItem(g,e),getImpersonated:()=>typeof window<"u"?p(g):void 0,removeImpersonated:()=>i()?.removeItem(g)};function Ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Ye(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 W=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",He=W;function z(e){return e.replace(/\/+$/,"")}function Ze(e,n){return n?`${z(e)}/${n.replace(/^\/+/,"")}`:e}var c="orbit-core:lastConnectedConnector",N=()=>a(c,"sessionStorage")??a(c),en={STORAGE_KEY:c,lastConnectedConnector:N(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},r={})=>{let o=r.remember??true,[s,l]=o?[i("localStorage"),i("sessionStorage")]:[i("sessionStorage"),i("localStorage")];s?.setItem(c,JSON.stringify({connectorType:e,chainId:n,address:t})),l?.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 J=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function K(){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 V(e){let n={};if(e&&typeof e=="object"){for(let t of J)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=K(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function tn(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=V(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 cn=({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 un(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 pn(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=B;exports.OrbitAdapter=f;exports.SAFE_CONNECTOR_ID=F;exports.SOLANA_CHAIN_IDS=x;exports.delay=pe;exports.detectSafeApp=Ye;exports.errorChain=me;exports.filterUniqueByKey=Ce;exports.formatBaseUnits=we;exports.formatCaip10AccountId=re;exports.formatCaip19AssetId=se;exports.formatConnectorChainId=Ae;exports.formatConnectorName=$;exports.getAdapterFromConnectorType=Ee;exports.getBrowserStorage=i;exports.getConnectorTypeFromName=Ie;exports.getNetworkData=_e;exports.getParsedStorageItem=a;exports.getSolanaChainId=u;exports.getSolanaCluster=b;exports.getWalletFromConnectorType=je;exports.globalSingleton=Fe;exports.impersonatedHelpers=ze;exports.isAddress=w;exports.isInSecureIframe=W;exports.isRecord=Ke;exports.isSafeApp=He;exports.isSameAdapterAddress=q;exports.isSameAddress=v;exports.isSolanaChain=de;exports.joinUrlPath=Ze;exports.lastConnectedConnectorHelpers=en;exports.normalizeAccountAddress=R;exports.normalizeError=tn;exports.parseCaip10AccountId=oe;exports.parseCaip19AssetId=ie;exports.parseCaip2ChainId=m;exports.readBrowserStorage=p;exports.recentlyConnectedConnectorsListHelpers=y;exports.selectAdapterByKey=cn;exports.setChainId=ue;exports.shortAddress=un;exports.toCaip2ChainId=O;exports.toEvmChainId=te;exports.trimTrailingSlashes=z;exports.waitFor=pn;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var f=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(f||{});function R(e,n){return e==="eip155"?n.toLowerCase():n}function v(e,n,t){return R(e,n)===R(e,t)}function q(e,n,t){return v(e==="evm"?"eip155":e,n,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 p(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}$/,D=/^[-_a-zA-Z0-9]{1,32}$/,P=/^[-.%a-zA-Z0-9]{1,128}$/,L=/^[-.%a-zA-Z0-9]{1,128}$/,j=/^(?: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)&&D.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 te(e){let n=typeof e=="number"?e:Number(j.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"):P.test(n)}function re(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 oe(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 se(e,n,t){let r=O(e);if(!(!r||!A.test(n)||!L.test(t)))return `${r}/${n}:${t}`}function ie(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),l=r.slice(o+1);if(!(!A.test(s)||!L.test(l)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:l}}function de(e){return b(e)!==void 0}function ue(e){return u(e)??e}var pe=(e,n)=>new Promise(t=>{let r=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?r():setTimeout(r,0);});function me(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 Ce(e,n){let t=new Set;return e.filter(r=>{let o=r[n];return t.has(o)?false:(t.add(o),true)})}function we(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 Ae(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 B="impersonatedwallet",F="safe",U=new Map([["Impersonated Connector",B],["Safe",F],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),$=e=>U.get(e)??e.replace(/\s+/g,"").toLowerCase();function Ee(e){return e?.split(":")[0]??"evm"}function Ie(e,n){return `${e}:${$(n)}`}var _e=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=p(e,n);if(t)try{return JSON.parse(t)}catch(r){console.error(`Error parsing ${e} from ${n}:`,r);return}}function je(e){return e?.split(":")[1]}function Fe(e,n){let t=globalThis,r=Symbol.for(e);return t[r]??=n()}var g="satellite-connect:impersonatedAddress",ze={impersonatedAddress:p(g)??"",setImpersonated:e=>i()?.setItem(g,e),getImpersonated:()=>typeof window<"u"?p(g):void 0,removeImpersonated:()=>i()?.removeItem(g)};function Ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Ye(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 W=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",He=W;function z(e){return e.replace(/\/+$/,"")}function Ze(e,n){return n?`${z(e)}/${n.replace(/^\/+/,"")}`:e}var c="orbit-core:lastConnectedConnector",N=()=>a(c,"sessionStorage")??a(c),en={STORAGE_KEY:c,lastConnectedConnector:N(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},r={})=>{let o=r.remember??true,[s,l]=o?[i("localStorage"),i("sessionStorage")]:[i("sessionStorage"),i("localStorage")];s?.setItem(c,JSON.stringify({connectorType:e,chainId:n,address:t})),l?.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 J=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function K(){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 V(e){let n={};if(e&&typeof e=="object"){for(let t of J)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=K(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function tn(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=V(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 cn=({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 un(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 pn(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{B as IMPERSONATED_CONNECTOR_ID,f as OrbitAdapter,F as SAFE_CONNECTOR_ID,x as SOLANA_CHAIN_IDS,pe as delay,Ye as detectSafeApp,me as errorChain,Ce as filterUniqueByKey,we as formatBaseUnits,re as formatCaip10AccountId,se as formatCaip19AssetId,Ae as formatConnectorChainId,$ as formatConnectorName,Ee as getAdapterFromConnectorType,i as getBrowserStorage,Ie as getConnectorTypeFromName,_e as getNetworkData,a as getParsedStorageItem,u as getSolanaChainId,b as getSolanaCluster,je as getWalletFromConnectorType,Fe as globalSingleton,ze as impersonatedHelpers,w as isAddress,W as isInSecureIframe,Ke as isRecord,He as isSafeApp,q as isSameAdapterAddress,v as isSameAddress,de as isSolanaChain,Ze as joinUrlPath,en as lastConnectedConnectorHelpers,R as normalizeAccountAddress,tn as normalizeError,oe as parseCaip10AccountId,ie as parseCaip19AssetId,m as parseCaip2ChainId,p as readBrowserStorage,y as recentlyConnectedConnectorsListHelpers,cn as selectAdapterByKey,ue as setChainId,un as shortAddress,O as toCaip2ChainId,te as toEvmChainId,z as trimTrailingSlashes,pn as waitFor};
|