@tuwaio/orbit-core 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/index.d.mts +36 -15
- package/dist/index.d.ts +36 -15
- 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:
|
|
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
|
@@ -445,12 +445,13 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
445
445
|
} | undefined;
|
|
446
446
|
|
|
447
447
|
/**
|
|
448
|
-
* Internal function for safely retrieving and parsing data from localStorage.
|
|
448
|
+
* Internal function for safely retrieving and parsing data from localStorage or sessionStorage.
|
|
449
449
|
*
|
|
450
|
-
* @param key - The key
|
|
451
|
-
* @
|
|
450
|
+
* @param key - The storage key
|
|
451
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
452
|
+
* @returns The parsed value or undefined if data is not found/invalid, or in an SSR context
|
|
452
453
|
*/
|
|
453
|
-
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
454
|
+
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
454
455
|
|
|
455
456
|
/**
|
|
456
457
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -534,12 +535,22 @@ type LastConnectedConnector = {
|
|
|
534
535
|
/** Connected wallet address, if known. */
|
|
535
536
|
address?: string;
|
|
536
537
|
};
|
|
538
|
+
/**
|
|
539
|
+
* Where a connection is kept: `remember: true` keeps it in localStorage until the wallet is disconnected (the default,
|
|
540
|
+
* as before), `remember: false` keeps it in sessionStorage until the tab closes, for people who did not ask to
|
|
541
|
+
* remember the wallet.
|
|
542
|
+
*/
|
|
543
|
+
type WalletMemoryOptions = {
|
|
544
|
+
/** Keep the connection after the tab closes. Defaults to `true`. */
|
|
545
|
+
remember?: boolean;
|
|
546
|
+
};
|
|
537
547
|
/**
|
|
538
548
|
* Helper utilities for managing the last connected wallet state
|
|
539
549
|
*
|
|
540
550
|
* @remarks
|
|
541
|
-
*
|
|
542
|
-
*
|
|
551
|
+
* The data is stored under the 'orbit-core:lastConnectedConnector' key: in localStorage for a remembered wallet, in
|
|
552
|
+
* sessionStorage for one that is kept only until the tab closes ({@link WalletMemoryOptions}). A value in
|
|
553
|
+
* sessionStorage takes precedence when reading. Functions are safe to use in both browser and SSR environments.
|
|
543
554
|
*/
|
|
544
555
|
declare const lastConnectedConnectorHelpers: {
|
|
545
556
|
STORAGE_KEY: string;
|
|
@@ -549,24 +560,32 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
549
560
|
*/
|
|
550
561
|
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
551
562
|
/**
|
|
552
|
-
* Stores the last connected wallet data in localStorage
|
|
563
|
+
* Stores the last connected wallet data: in localStorage when it is remembered (the default), otherwise in
|
|
564
|
+
* sessionStorage; the copy in the other storage is removed.
|
|
553
565
|
*
|
|
554
566
|
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
567
|
+
* @param options - Whether the wallet is remembered after the tab closes.
|
|
555
568
|
* @returns undefined in SSR context, void in browser
|
|
556
569
|
*/
|
|
557
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) =>
|
|
570
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => undefined;
|
|
558
571
|
/**
|
|
559
|
-
* Retrieves the current last connected wallet data from localStorage.
|
|
572
|
+
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
560
573
|
*
|
|
561
574
|
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
562
575
|
*/
|
|
563
576
|
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
564
577
|
/**
|
|
565
|
-
*
|
|
578
|
+
* Whether the last connection is remembered after the tab closes.
|
|
579
|
+
*
|
|
580
|
+
* @returns `true` when it is in localStorage, `false` when it is in sessionStorage, undefined when there is none
|
|
581
|
+
*/
|
|
582
|
+
isLastConnectedConnectorRemembered: () => boolean | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Removes the last connected wallet data from localStorage and sessionStorage.
|
|
566
585
|
*
|
|
567
586
|
* @returns undefined in SSR context, void in browser
|
|
568
587
|
*/
|
|
569
|
-
removeLastConnectedConnector: () =>
|
|
588
|
+
removeLastConnectedConnector: () => undefined;
|
|
570
589
|
};
|
|
571
590
|
|
|
572
591
|
/**
|
|
@@ -623,8 +642,9 @@ type RecentlyConnectedConnectorsList = Record<ConnectorType, RecentlyConnectedCo
|
|
|
623
642
|
* Helper utilities for managing recently connected connectors list with disconnect timestamps
|
|
624
643
|
*
|
|
625
644
|
* @remarks
|
|
626
|
-
*
|
|
627
|
-
*
|
|
645
|
+
* The list is stored under the 'orbit-core:recentlyConnectedConnectorsListHelpers' key: wallets that are remembered in
|
|
646
|
+
* localStorage, wallets kept only until the tab closes in sessionStorage ({@link WalletMemoryOptions}); reading
|
|
647
|
+
* merges both, the sessionStorage entry winning. Functions are safe to use in both browser and SSR environments.
|
|
628
648
|
*
|
|
629
649
|
* The storage contains a record where each key is a ConnectorType and value contains
|
|
630
650
|
* address, disconnectedTimestamp (Unix timestamp in milliseconds), and optional icon for that connector.
|
|
@@ -732,7 +752,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
732
752
|
* });
|
|
733
753
|
* ```
|
|
734
754
|
*/
|
|
735
|
-
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData) => undefined;
|
|
755
|
+
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData, options?: WalletMemoryOptions) => undefined;
|
|
736
756
|
/**
|
|
737
757
|
* Removes a single connector from the recently connected connectors list.
|
|
738
758
|
* Preserves all other connectors in the list.
|
|
@@ -951,4 +971,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
951
971
|
*/
|
|
952
972
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
953
973
|
|
|
954
|
-
export {
|
|
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 };
|
|
975
|
+
export type { BaseAdapter, Caip10AccountId, Caip19AssetId, Caip2ChainId, ChainIdentifierArray, ConnectorType, LastConnectedConnector, OrbitGenericAdapter, RecentlyConnectedConnectorData, RecentlyConnectedConnectorsList, SolanaCluster, TuwaErrorState, WalletMemoryOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -445,12 +445,13 @@ declare const getNetworkData: (adapter: OrbitAdapter) => {
|
|
|
445
445
|
} | undefined;
|
|
446
446
|
|
|
447
447
|
/**
|
|
448
|
-
* Internal function for safely retrieving and parsing data from localStorage.
|
|
448
|
+
* Internal function for safely retrieving and parsing data from localStorage or sessionStorage.
|
|
449
449
|
*
|
|
450
|
-
* @param key - The key
|
|
451
|
-
* @
|
|
450
|
+
* @param key - The storage key
|
|
451
|
+
* @param area - The storage to read: `localStorage` (default) or `sessionStorage`
|
|
452
|
+
* @returns The parsed value or undefined if data is not found/invalid, or in an SSR context
|
|
452
453
|
*/
|
|
453
|
-
declare function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined;
|
|
454
|
+
declare function getParsedStorageItem<ReturnType>(key: string, area?: 'localStorage' | 'sessionStorage'): ReturnType | undefined;
|
|
454
455
|
|
|
455
456
|
/**
|
|
456
457
|
* Helper utilities for managing impersonated wallet addresses
|
|
@@ -534,12 +535,22 @@ type LastConnectedConnector = {
|
|
|
534
535
|
/** Connected wallet address, if known. */
|
|
535
536
|
address?: string;
|
|
536
537
|
};
|
|
538
|
+
/**
|
|
539
|
+
* Where a connection is kept: `remember: true` keeps it in localStorage until the wallet is disconnected (the default,
|
|
540
|
+
* as before), `remember: false` keeps it in sessionStorage until the tab closes, for people who did not ask to
|
|
541
|
+
* remember the wallet.
|
|
542
|
+
*/
|
|
543
|
+
type WalletMemoryOptions = {
|
|
544
|
+
/** Keep the connection after the tab closes. Defaults to `true`. */
|
|
545
|
+
remember?: boolean;
|
|
546
|
+
};
|
|
537
547
|
/**
|
|
538
548
|
* Helper utilities for managing the last connected wallet state
|
|
539
549
|
*
|
|
540
550
|
* @remarks
|
|
541
|
-
*
|
|
542
|
-
*
|
|
551
|
+
* The data is stored under the 'orbit-core:lastConnectedConnector' key: in localStorage for a remembered wallet, in
|
|
552
|
+
* sessionStorage for one that is kept only until the tab closes ({@link WalletMemoryOptions}). A value in
|
|
553
|
+
* sessionStorage takes precedence when reading. Functions are safe to use in both browser and SSR environments.
|
|
543
554
|
*/
|
|
544
555
|
declare const lastConnectedConnectorHelpers: {
|
|
545
556
|
STORAGE_KEY: string;
|
|
@@ -549,24 +560,32 @@ declare const lastConnectedConnectorHelpers: {
|
|
|
549
560
|
*/
|
|
550
561
|
lastConnectedConnector: LastConnectedConnector | undefined;
|
|
551
562
|
/**
|
|
552
|
-
* Stores the last connected wallet data in localStorage
|
|
563
|
+
* Stores the last connected wallet data: in localStorage when it is remembered (the default), otherwise in
|
|
564
|
+
* sessionStorage; the copy in the other storage is removed.
|
|
553
565
|
*
|
|
554
566
|
* @param data - Connector type, chain ID and optional address of the connected wallet.
|
|
567
|
+
* @param options - Whether the wallet is remembered after the tab closes.
|
|
555
568
|
* @returns undefined in SSR context, void in browser
|
|
556
569
|
*/
|
|
557
|
-
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector) =>
|
|
570
|
+
setLastConnectedConnector: ({ connectorType, chainId, address }: LastConnectedConnector, options?: WalletMemoryOptions) => undefined;
|
|
558
571
|
/**
|
|
559
|
-
* Retrieves the current last connected wallet data from localStorage.
|
|
572
|
+
* Retrieves the current last connected wallet data, from sessionStorage first, then from localStorage.
|
|
560
573
|
*
|
|
561
574
|
* @returns The LastConnectedConnector object or undefined if not set or in SSR context
|
|
562
575
|
*/
|
|
563
576
|
getLastConnectedConnector: () => LastConnectedConnector | undefined;
|
|
564
577
|
/**
|
|
565
|
-
*
|
|
578
|
+
* Whether the last connection is remembered after the tab closes.
|
|
579
|
+
*
|
|
580
|
+
* @returns `true` when it is in localStorage, `false` when it is in sessionStorage, undefined when there is none
|
|
581
|
+
*/
|
|
582
|
+
isLastConnectedConnectorRemembered: () => boolean | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Removes the last connected wallet data from localStorage and sessionStorage.
|
|
566
585
|
*
|
|
567
586
|
* @returns undefined in SSR context, void in browser
|
|
568
587
|
*/
|
|
569
|
-
removeLastConnectedConnector: () =>
|
|
588
|
+
removeLastConnectedConnector: () => undefined;
|
|
570
589
|
};
|
|
571
590
|
|
|
572
591
|
/**
|
|
@@ -623,8 +642,9 @@ type RecentlyConnectedConnectorsList = Record<ConnectorType, RecentlyConnectedCo
|
|
|
623
642
|
* Helper utilities for managing recently connected connectors list with disconnect timestamps
|
|
624
643
|
*
|
|
625
644
|
* @remarks
|
|
626
|
-
*
|
|
627
|
-
*
|
|
645
|
+
* The list is stored under the 'orbit-core:recentlyConnectedConnectorsListHelpers' key: wallets that are remembered in
|
|
646
|
+
* localStorage, wallets kept only until the tab closes in sessionStorage ({@link WalletMemoryOptions}); reading
|
|
647
|
+
* merges both, the sessionStorage entry winning. Functions are safe to use in both browser and SSR environments.
|
|
628
648
|
*
|
|
629
649
|
* The storage contains a record where each key is a ConnectorType and value contains
|
|
630
650
|
* address, disconnectedTimestamp (Unix timestamp in milliseconds), and optional icon for that connector.
|
|
@@ -732,7 +752,7 @@ declare const recentlyConnectedConnectorsListHelpers: {
|
|
|
732
752
|
* });
|
|
733
753
|
* ```
|
|
734
754
|
*/
|
|
735
|
-
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData) => undefined;
|
|
755
|
+
addConnector: (connectorType: ConnectorType, connectorData: RecentlyConnectedConnectorData, options?: WalletMemoryOptions) => undefined;
|
|
736
756
|
/**
|
|
737
757
|
* Removes a single connector from the recently connected connectors list.
|
|
738
758
|
* Preserves all other connectors in the list.
|
|
@@ -951,4 +971,5 @@ declare function getSolanaChainId(chainId: string | number): string | undefined;
|
|
|
951
971
|
*/
|
|
952
972
|
declare function waitFor(predicate: () => boolean | undefined, maxChecks?: number, checkIntervalMs?: number): Promise<void>;
|
|
953
973
|
|
|
954
|
-
export {
|
|
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 };
|
|
975
|
+
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 p=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(p||{});function b(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function x(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function g(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return b(t);case "solana":return x(t);default:return b(t)||x(t)}}var w={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},C="solana:",R={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function y(e){if(typeof e!="string")return;let n=e.startsWith(C)?e.slice(C.length):e;return Object.hasOwn(R,n)?R[n]:void 0}function d(e){let n=y(e);if(n)return n==="localnet"?`${C}localnet`:w[n]}var S=/^[-a-z0-9]{3,8}$/,I=/^[-_a-zA-Z0-9]{1,32}$/,N=/^[-.%a-zA-Z0-9]{1,128}$/,h=/^[-.%a-zA-Z0-9]{1,128}$/,$=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function l(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),o=e.slice(n+1);return S.test(t)&&I.test(o)?{namespace:t,reference:o}:void 0}function T(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=d(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:l(e)?e:void 0)}function Y(e){let n=typeof e=="number"?e:Number($.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function k(e,n){return e==="eip155"?g(n,"evm"):e==="solana"?g(n,"solana"):N.test(n)}function z(e,n){let t=T(e);if(!t)return;let o=l(t),r=n.trim();if(!(!o||!k(o.namespace,r)))return `${t}:${r}`}function V(e){let n=e.lastIndexOf(":");if(n<0)return;let t=l(e.slice(0,n)),o=e.slice(n+1);if(!(!t||!k(t.namespace,o)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:o}}function W(e,n,t){let o=T(e);if(!(!o||!S.test(n)||!h.test(t)))return `${o}/${n}:${t}`}function H(e){let n=e.indexOf("/");if(n<0)return;let t=l(e.slice(0,n)),o=e.slice(n+1),r=o.indexOf(":");if(!t||r<0)return;let s=o.slice(0,r),u=o.slice(r+1);if(!(!S.test(s)||!h.test(u)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:u}}function Z(e){return y(e)!==void 0}function G(e){return d(e)??e}var X=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function ne(e,n){let t=new Set;return e.filter(o=>{let r=o[n];return t.has(r)?false:(t.add(r),true)})}function se(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=d(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var M=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),ae=e=>M.get(e)??e.replace(/\s+/g,"").toLowerCase();function ue(e){return e?.split(":")[0]??"evm"}function le(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var we=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:w.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 i(e,n="localStorage"){if(typeof window>"u"||!window[n])return;let t=window[n].getItem(e);if(t)try{return JSON.parse(t)}catch(o){console.error(`Error parsing ${e} from ${n}:`,o);return}}var Ae={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:e=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",e):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};async function xe(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(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",o),n(true));}window.addEventListener("message",o);let r=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:r,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var v=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",Re=v;var a="orbit-core:lastConnectedConnector",L=()=>i(a,"sessionStorage")??i(a),ke={STORAGE_KEY:a,lastConnectedConnector:L(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},o={})=>{if(typeof window>"u")return;let r=o.remember??true,[s,u]=r?[window.localStorage,window.sessionStorage]:[window.sessionStorage,window.localStorage];s?.setItem(a,JSON.stringify({connectorType:e,chainId:n,address:t})),u?.removeItem(a);},getLastConnectedConnector:()=>L(),isLastConnectedConnectorRemembered:()=>{if(i(a,"sessionStorage"))return false;if(i(a))return true},removeLastConnectedConnector:()=>{typeof window>"u"||(window.localStorage.removeItem(a),window.sessionStorage?.removeItem(a));}};var _=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function P(){let e=new WeakSet;return (n,t)=>{if(t===null||typeof t!="object")return typeof t=="function"||typeof t=="symbol"?void 0:typeof t=="bigint"?t.toString():t;if(e.has(t))return "[Circular]";if(e.add(t),t instanceof Error){let o={name:t.name,message:t.message};t.stack&&(o.stack=t.stack);for(let r of Object.keys(t))r in o||(o[r]=t[r]);return o}return t}}function D(e){let n={};if(e&&typeof e=="object"){for(let t of _)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function E(e){try{let n=P(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function Ee(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=D(e),o=E(e);return {message:n,raw:{...o,...t,originalType:e.name||"Error"}}}return typeof e=="object"?{message:("message"in e&&typeof e.message=="string"?e.message:"shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:"Unknown error")||"Unknown error",raw:{...E(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var c="orbit-core:recentlyConnectedConnectorsListHelpers",A=e=>i(c,e)??{},m=(e,n)=>window[e]?.setItem(c,JSON.stringify(n)),O=(e,n)=>{let{[n]:t,...o}=e;return o},f={STORAGE_KEY:c,recentlyConnectedConnectorsList:i(c),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>{let e=i(c),n=i(c,"sessionStorage");if(!(!e&&!n))return {...e,...n}},addConnector:(e,n,t={})=>{if(typeof window>"u")return;let[o,r]=t.remember??true?["localStorage","sessionStorage"]:["sessionStorage","localStorage"];m(o,{...A(o),[e]:n});let s=A(r);e in s&&m(r,O(s,e));},removeConnector:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=A(n);e in t&&m(n,O(t,e));}},hasConnector:e=>{if(typeof window>"u")return;let n=f.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:f.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=f.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=f.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=i(c,n);if(!t)continue;let o=Object.fromEntries(Object.entries(t).filter(([,r])=>r.disconnectedTimestamp>=e));m(n,o);}},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};var $e=({adapterKey:e,adapter:n})=>{if(Array.isArray(n)){if(n.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let t=n.find(o=>o.key===e);return t||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${n[0].key}".`),n[0])}return n};async function ve(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(r=>setTimeout(r,t));}throw new Error("Predicate not fulfilled in time")}
|
|
2
|
+
exports.OrbitAdapter=p;exports.SOLANA_CHAIN_IDS=w;exports.delay=X;exports.detectSafeApp=xe;exports.filterUniqueByKey=ne;exports.formatCaip10AccountId=z;exports.formatCaip19AssetId=W;exports.formatConnectorChainId=se;exports.formatConnectorName=ae;exports.getAdapterFromConnectorType=ue;exports.getConnectorTypeFromName=le;exports.getNetworkData=we;exports.getParsedStorageItem=i;exports.getSolanaChainId=d;exports.getSolanaCluster=y;exports.impersonatedHelpers=Ae;exports.isAddress=g;exports.isInSecureIframe=v;exports.isSafeApp=Re;exports.isSolanaChain=Z;exports.lastConnectedConnectorHelpers=ke;exports.normalizeError=Ee;exports.parseCaip10AccountId=V;exports.parseCaip19AssetId=H;exports.parseCaip2ChainId=l;exports.recentlyConnectedConnectorsListHelpers=f;exports.selectAdapterByKey=$e;exports.setChainId=G;exports.toCaip2ChainId=T;exports.toEvmChainId=Y;exports.waitFor=ve;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var p=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(p||{});function b(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function x(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function g(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return b(t);case "solana":return x(t);default:return b(t)||x(t)}}var w={mainnet:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",devnet:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",testnet:"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"},C="solana:",R={mainnet:"mainnet","mainnet-beta":"mainnet",devnet:"devnet",testnet:"testnet",localnet:"localnet","5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"mainnet",EtWTRABZaYq6iMfeYKouRu166VU2xqa1:"devnet","4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z":"testnet","4uhcVJyU9pJkvQyS88uRfhDSfZSm8DoR":"testnet"};function y(e){if(typeof e!="string")return;let n=e.startsWith(C)?e.slice(C.length):e;return Object.hasOwn(R,n)?R[n]:void 0}function d(e){let n=y(e);if(n)return n==="localnet"?`${C}localnet`:w[n]}var S=/^[-a-z0-9]{3,8}$/,I=/^[-_a-zA-Z0-9]{1,32}$/,N=/^[-.%a-zA-Z0-9]{1,128}$/,h=/^[-.%a-zA-Z0-9]{1,128}$/,$=/^(?:eip155:)?([1-9][0-9]{0,15})$/;function l(e){let n=e.indexOf(":");if(n<0)return;let t=e.slice(0,n),o=e.slice(n+1);return S.test(t)&&I.test(o)?{namespace:t,reference:o}:void 0}function T(e){if(typeof e=="number")return Number.isSafeInteger(e)&&e>0?`eip155:${e}`:void 0;let n=d(e);return n||(/^[1-9][0-9]{0,15}$/.test(e)?`eip155:${e}`:l(e)?e:void 0)}function Y(e){let n=typeof e=="number"?e:Number($.exec(e)?.[1]);return Number.isSafeInteger(n)&&n>0?n:void 0}function k(e,n){return e==="eip155"?g(n,"evm"):e==="solana"?g(n,"solana"):N.test(n)}function z(e,n){let t=T(e);if(!t)return;let o=l(t),r=n.trim();if(!(!o||!k(o.namespace,r)))return `${t}:${r}`}function V(e){let n=e.lastIndexOf(":");if(n<0)return;let t=l(e.slice(0,n)),o=e.slice(n+1);if(!(!t||!k(t.namespace,o)))return {chainId:`${t.namespace}:${t.reference}`,namespace:t.namespace,reference:t.reference,address:o}}function W(e,n,t){let o=T(e);if(!(!o||!S.test(n)||!h.test(t)))return `${o}/${n}:${t}`}function H(e){let n=e.indexOf("/");if(n<0)return;let t=l(e.slice(0,n)),o=e.slice(n+1),r=o.indexOf(":");if(!t||r<0)return;let s=o.slice(0,r),u=o.slice(r+1);if(!(!S.test(s)||!h.test(u)))return {chainId:`${t.namespace}:${t.reference}`,assetNamespace:s,assetReference:u}}function Z(e){return y(e)!==void 0}function G(e){return d(e)??e}var X=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function ne(e,n){let t=new Set;return e.filter(o=>{let r=o[n];return t.has(r)?false:(t.add(r),true)})}function se(e,n){if(typeof e!="string")return e;if(n==="solana"){let t=d(e);if(t)return t}return e.startsWith(`${n}:`)?e:`${n}:${e}`}var M=new Map([["Impersonated Connector","impersonatedwallet"],["Safe","safe"],["Trust","trust"],["Trust Wallet","trust"],["Brave \u041A\u043E\u0448\u0435\u043B\u0435\u043A","brave"],["Brave Wallet","brave"],["Base Account","coinbase"]]),ae=e=>M.get(e)??e.replace(/\s+/g,"").toLowerCase();function ue(e){return e?.split(":")[0]??"evm"}function le(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var we=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:w.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 i(e,n="localStorage"){if(typeof window>"u"||!window[n])return;let t=window[n].getItem(e);if(t)try{return JSON.parse(t)}catch(o){console.error(`Error parsing ${e} from ${n}:`,o);return}}var Ae={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:e=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",e):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};async function xe(e=1e3){return typeof window>"u"||window===window.parent||window.location.protocol!=="https:"?false:new Promise(n=>{let t=setTimeout(()=>{window.removeEventListener("message",o),n(false);},e);function o(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",o),n(true));}window.addEventListener("message",o);let r=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:r,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var v=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",Re=v;var a="orbit-core:lastConnectedConnector",L=()=>i(a,"sessionStorage")??i(a),ke={STORAGE_KEY:a,lastConnectedConnector:L(),setLastConnectedConnector:({connectorType:e,chainId:n,address:t},o={})=>{if(typeof window>"u")return;let r=o.remember??true,[s,u]=r?[window.localStorage,window.sessionStorage]:[window.sessionStorage,window.localStorage];s?.setItem(a,JSON.stringify({connectorType:e,chainId:n,address:t})),u?.removeItem(a);},getLastConnectedConnector:()=>L(),isLastConnectedConnectorRemembered:()=>{if(i(a,"sessionStorage"))return false;if(i(a))return true},removeLastConnectedConnector:()=>{typeof window>"u"||(window.localStorage.removeItem(a),window.sessionStorage?.removeItem(a));}};var _=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function P(){let e=new WeakSet;return (n,t)=>{if(t===null||typeof t!="object")return typeof t=="function"||typeof t=="symbol"?void 0:typeof t=="bigint"?t.toString():t;if(e.has(t))return "[Circular]";if(e.add(t),t instanceof Error){let o={name:t.name,message:t.message};t.stack&&(o.stack=t.stack);for(let r of Object.keys(t))r in o||(o[r]=t[r]);return o}return t}}function D(e){let n={};if(e&&typeof e=="object"){for(let t of _)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function E(e){try{let n=P(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function Ee(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=D(e),o=E(e);return {message:n,raw:{...o,...t,originalType:e.name||"Error"}}}return typeof e=="object"?{message:("message"in e&&typeof e.message=="string"?e.message:"shortMessage"in e&&typeof e.shortMessage=="string"?e.shortMessage:"Unknown error")||"Unknown error",raw:{...E(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}var c="orbit-core:recentlyConnectedConnectorsListHelpers",A=e=>i(c,e)??{},m=(e,n)=>window[e]?.setItem(c,JSON.stringify(n)),O=(e,n)=>{let{[n]:t,...o}=e;return o},f={STORAGE_KEY:c,recentlyConnectedConnectorsList:i(c),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>{let e=i(c),n=i(c,"sessionStorage");if(!(!e&&!n))return {...e,...n}},addConnector:(e,n,t={})=>{if(typeof window>"u")return;let[o,r]=t.remember??true?["localStorage","sessionStorage"]:["sessionStorage","localStorage"];m(o,{...A(o),[e]:n});let s=A(r);e in s&&m(r,O(s,e));},removeConnector:e=>{if(!(typeof window>"u"))for(let n of ["localStorage","sessionStorage"]){let t=A(n);e in t&&m(n,O(t,e));}},hasConnector:e=>{if(typeof window>"u")return;let n=f.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:f.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=f.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=f.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=i(c,n);if(!t)continue;let o=Object.fromEntries(Object.entries(t).filter(([,r])=>r.disconnectedTimestamp>=e));m(n,o);}},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};var $e=({adapterKey:e,adapter:n})=>{if(Array.isArray(n)){if(n.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let t=n.find(o=>o.key===e);return t||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${n[0].key}".`),n[0])}return n};async function ve(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(r=>setTimeout(r,t));}throw new Error("Predicate not fulfilled in time")}
|
|
2
|
+
export{p as OrbitAdapter,w as SOLANA_CHAIN_IDS,X as delay,xe as detectSafeApp,ne as filterUniqueByKey,z as formatCaip10AccountId,W as formatCaip19AssetId,se as formatConnectorChainId,ae as formatConnectorName,ue as getAdapterFromConnectorType,le as getConnectorTypeFromName,we as getNetworkData,i as getParsedStorageItem,d as getSolanaChainId,y as getSolanaCluster,Ae as impersonatedHelpers,g as isAddress,v as isInSecureIframe,Re as isSafeApp,Z as isSolanaChain,ke as lastConnectedConnectorHelpers,Ee as normalizeError,V as parseCaip10AccountId,H as parseCaip19AssetId,l as parseCaip2ChainId,f as recentlyConnectedConnectorsListHelpers,$e as selectAdapterByKey,G as setChainId,T as toCaip2ChainId,Y as toEvmChainId,ve 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.0",
|
|
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": {
|