@tuwaio/orbit-core 0.2.6 → 0.2.7
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/dist/index.d.mts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -663,4 +663,35 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
663
663
|
*/
|
|
664
664
|
declare function setChainId(chainId: number | string): string | number;
|
|
665
665
|
|
|
666
|
-
|
|
666
|
+
/**
|
|
667
|
+
* Persistence-safe error normalization for Web3 errors.
|
|
668
|
+
* Handles circular references, functions, and non-serializable properties.
|
|
669
|
+
*/
|
|
670
|
+
/**
|
|
671
|
+
* Normalized error state that is safe for Zustand persistence.
|
|
672
|
+
* - `message`: User-friendly error message for display
|
|
673
|
+
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
674
|
+
*/
|
|
675
|
+
interface TuwaErrorState {
|
|
676
|
+
message: string;
|
|
677
|
+
raw: Record<string, unknown>;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
681
|
+
*
|
|
682
|
+
* @param error - Any error value (Error, string, object, etc.)
|
|
683
|
+
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* ```typescript
|
|
687
|
+
* try {
|
|
688
|
+
* await sendTransaction();
|
|
689
|
+
* } catch (e) {
|
|
690
|
+
* const normalized = normalizeError(e);
|
|
691
|
+
* set({ error: normalized });
|
|
692
|
+
* }
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
696
|
+
|
|
697
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -663,4 +663,35 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
663
663
|
*/
|
|
664
664
|
declare function setChainId(chainId: number | string): string | number;
|
|
665
665
|
|
|
666
|
-
|
|
666
|
+
/**
|
|
667
|
+
* Persistence-safe error normalization for Web3 errors.
|
|
668
|
+
* Handles circular references, functions, and non-serializable properties.
|
|
669
|
+
*/
|
|
670
|
+
/**
|
|
671
|
+
* Normalized error state that is safe for Zustand persistence.
|
|
672
|
+
* - `message`: User-friendly error message for display
|
|
673
|
+
* - `raw`: Full error details as JSON-serializable object for debugging/copying
|
|
674
|
+
*/
|
|
675
|
+
interface TuwaErrorState {
|
|
676
|
+
message: string;
|
|
677
|
+
raw: Record<string, unknown>;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Normalizes any error into a persistence-safe TuwaErrorState.
|
|
681
|
+
*
|
|
682
|
+
* @param error - Any error value (Error, string, object, etc.)
|
|
683
|
+
* @returns TuwaErrorState with user-friendly message and full raw details
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* ```typescript
|
|
687
|
+
* try {
|
|
688
|
+
* await sendTransaction();
|
|
689
|
+
* } catch (e) {
|
|
690
|
+
* const normalized = normalizeError(e);
|
|
691
|
+
* set({ error: normalized });
|
|
692
|
+
* }
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
declare function normalizeError(error: unknown): TuwaErrorState;
|
|
696
|
+
|
|
697
|
+
export { type BaseAdapter, type ChainIdentifierArray, type ConnectorType, OrbitAdapter, type OrbitGenericAdapter, type RecentlyConnectedConnectorData, type RecentlyConnectedConnectorsList, type TuwaErrorState, delay, detectSafeApp, filterUniqueByKey, formatConnectorChainId, formatConnectorName, getAdapterFromConnectorType, getConnectorTypeFromName, getNetworkData, getParsedStorageItem, impersonatedHelpers, isAddress, isInSecureIframe, isSafeApp, isSolanaChain, lastConnectedConnectorHelpers, normalizeError, recentlyConnectedConnectorsListHelpers, selectAdapterByKey, setChainId, waitFor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
exports.OrbitAdapter=
|
|
1
|
+
'use strict';var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=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"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=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:"solana: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){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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 v(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(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var W=({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 Z(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(s=>setTimeout(s,t));}throw new Error("Predicate not fulfilled in time")}function g(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function X(e){return g(e)?`solana:${e}`:e}var w=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function y(){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 s of Object.keys(t))s in o||(o[s]=t[s]);return o}return t}}function C(e){let n={};if(e&&typeof e=="object"){for(let t of w)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function p(e){try{let n=y(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function ne(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=C(e),o=p(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:{...p(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}
|
|
2
|
+
exports.OrbitAdapter=c;exports.delay=S;exports.detectSafeApp=v;exports.filterUniqueByKey=R;exports.formatConnectorChainId=h;exports.formatConnectorName=O;exports.getAdapterFromConnectorType=M;exports.getConnectorTypeFromName=G;exports.getNetworkData=j;exports.getParsedStorageItem=a;exports.impersonatedHelpers=F;exports.isAddress=A;exports.isInSecureIframe=m;exports.isSafeApp=D;exports.isSolanaChain=g;exports.lastConnectedConnectorHelpers=d;exports.normalizeError=ne;exports.recentlyConnectedConnectorsListHelpers=r;exports.selectAdapterByKey=W;exports.setChainId=X;exports.waitFor=Z;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var c=(o=>(o.EVM="evm",o.SOLANA="solana",o.Starknet="starknet",o))(c||{});function f(e){return /^0x[a-fA-F0-9]{40}$/.test(e.trim())}function u(e){return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e.trim())}function A(e,n="auto"){if(!e)return false;let t=e.trim();switch(n){case "evm":return f(t);case "solana":return u(t);default:return f(t)||u(t)}}var S=(e,n)=>new Promise(t=>{let o=()=>{setTimeout(()=>t(e),n);};typeof window<"u"?o():setTimeout(o,0);});function R(e,n){let t=new Set;return e.filter(o=>{let s=o[n];return t.has(s)?false:(t.add(s),true)})}function h(e,n){return typeof e=="string"?`${n}:${e}`:e}var l=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"]]),O=e=>l.get(e)??e.replace(/\s+/g,"").toLowerCase();function M(e){return e?.split(":")[0]??"evm"}function G(e,n){return `${e}:${n.replace(/\s+/g,"").toLowerCase()}`}var j=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:"solana: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){if(typeof window>"u")return;let n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error(`Error parsing ${e} from localStorage:`,t);return}}var F={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 v(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(i){i.data&&typeof i.data=="object"&&("safeAddress"in i.data||i.data.data&&"safeAddress"in i.data.data||i.data.method==="getInfo")&&(clearTimeout(t),window.removeEventListener("message",o),n(true));}window.addEventListener("message",o);let s=Math.trunc(Math.random()*1e6);window.parent.postMessage({id:s,method:"getSafeInfo",env:{sdkVersion:"1.0.0"}},"*");})}var m=typeof window<"u"&&window!==window.parent&&window.location.protocol==="https:",D=m;var d={STORAGE_KEY:"orbit-core:lastConnectedConnector",lastConnectedConnector:a("orbit-core:lastConnectedConnector"),setLastConnectedConnector:({connectorType:e,chainId:n,address:t})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({connectorType:e,chainId:n,address:t})):void 0,getLastConnectedConnector:()=>a(d.STORAGE_KEY),removeLastConnectedConnector:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var r={STORAGE_KEY:"orbit-core:recentlyConnectedConnectorsListHelpers",recentlyConnectedConnectorsList:a("orbit-core:recentlyConnectedConnectorsListHelpers"),setRecentlyConnectedConnectorsList:e=>typeof window<"u"?window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(e)):void 0,getRecentlyConnectedConnectorsList:()=>a(r.STORAGE_KEY),addConnector:(e,n)=>{if(typeof window>"u")return;let o={...r.getRecentlyConnectedConnectorsList()||{},[e]:n};window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},removeConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n||!(e in n))return;let{[e]:t,...o}=n;window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(o));},hasConnector:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();return n?e in n:false},getConnector:e=>typeof window>"u"?void 0:r.getRecentlyConnectedConnectorsList()?.[e],getConnectorCount:()=>{if(typeof window>"u")return 0;let e=r.getRecentlyConnectedConnectorsList();return e?Object.keys(e).length:0},getConnectorsSortedByTime:()=>{if(typeof window>"u")return [];let e=r.getRecentlyConnectedConnectorsList();return e?Object.entries(e).sort(([,n],[,t])=>t.disconnectedTimestamp-n.disconnectedTimestamp):[]},removeConnectorsOlderThan:e=>{if(typeof window>"u")return;let n=r.getRecentlyConnectedConnectorsList();if(!n)return;let t=Object.fromEntries(Object.entries(n).filter(([,o])=>o.disconnectedTimestamp>=e));window.localStorage.setItem(r.STORAGE_KEY,JSON.stringify(t));},removeRecentlyConnectedConnectorsList:()=>typeof window<"u"?window.localStorage.removeItem(r.STORAGE_KEY):void 0};var W=({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 Z(e,n=50,t=200){for(let o=0;o<n;o++){if(e())return;await new Promise(s=>setTimeout(s,t));}throw new Error("Predicate not fulfilled in time")}function g(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function X(e){return g(e)?`solana:${e}`:e}var w=["code","name","shortMessage","details","cause","metaMessages","data","reason","method","transaction","receipt","action","version"];function y(){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 s of Object.keys(t))s in o||(o[s]=t[s]);return o}return t}}function C(e){let n={};if(e&&typeof e=="object"){for(let t of w)t in e&&(n[t]=e[t]);"message"in e&&(n.message=e.message),"stack"in e&&(n.stack=e.stack);}return n}function p(e){try{let n=y(),t=JSON.stringify(e,n);return JSON.parse(t)}catch{return {_serializationError:"Failed to serialize error object"}}}function ne(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=C(e),o=p(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:{...p(e),originalType:"object"}}:{message:String(e),raw:{value:String(e),originalType:typeof e}}}
|
|
2
|
+
export{c as OrbitAdapter,S as delay,v as detectSafeApp,R as filterUniqueByKey,h as formatConnectorChainId,O as formatConnectorName,M as getAdapterFromConnectorType,G as getConnectorTypeFromName,j as getNetworkData,a as getParsedStorageItem,F as impersonatedHelpers,A as isAddress,m as isInSecureIframe,D as isSafeApp,g as isSolanaChain,d as lastConnectedConnectorHelpers,ne as normalizeError,r as recentlyConnectedConnectorsListHelpers,W as selectAdapterByKey,X as setChainId,Z as waitFor};
|