!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.freighterApi=r():e.freighterApi=r()}(this,()=>(()=>{"use strict";var e,r,o={d:(e,r)=>{for(var E in r)o.o(r,E)&&!o.o(e,E)&&Object.defineProperty(e,E,{enumerable:!0,get:r[E]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},E={};o.r(E),o.d(E,{default:()=>a,getNetwork:()=>N,getNetworkDetails:()=>s,getPublicKey:()=>t,getUserInfo:()=>i,isAllowed:()=>O,isBrowser:()=>R,isConnected:()=>n,setAllowed:()=>C,signAuthEntry:()=>A,signBlob:()=>S,signTransaction:()=>_}),function(e){e.CREATE_ACCOUNT="CREATE_ACCOUNT",e.FUND_ACCOUNT="FUND_ACCOUNT",e.ADD_ACCOUNT="ADD_ACCOUNT",e.IMPORT_ACCOUNT="IMPORT_ACCOUNT",e.IMPORT_HARDWARE_WALLET="IMPORT_HARDWARE_WALLET",e.LOAD_ACCOUNT="LOAD_ACCOUNT",e.MAKE_ACCOUNT_ACTIVE="MAKE_ACCOUNT_ACTIVE",e.UPDATE_ACCOUNT_NAME="UPDATE_ACCOUNT_NAME",e.GET_MNEMONIC_PHRASE="GET_MNEMONIC_PHRASE",e.CONFIRM_MNEMONIC_PHRASE="CONFIRM_MNEMONIC_PHRASE",e.RECOVER_ACCOUNT="RECOVER_ACCOUNT",e.CONFIRM_PASSWORD="CONFIRM_PASSWORD",e.REJECT_ACCESS="REJECT_ACCESS",e.GRANT_ACCESS="GRANT_ACCESS",e.SIGN_TRANSACTION="SIGN_TRANSACTION",e.SIGN_BLOB="SIGN_BLOB",e.SIGN_AUTH_ENTRY="SIGN_AUTH_ENTRY",e.HANDLE_SIGNED_HW_TRANSACTION="HANDLE_SIGNED_HW_TRANSACTION",e.REJECT_TRANSACTION="REJECT_TRANSACTION",e.SIGN_FREIGHTER_TRANSACTION="SIGN_FREIGHTER_TRANSACTION",e.SIGN_FREIGHTER_SOROBAN_TRANSACTION="SIGN_FREIGHTER_SOROBAN_TRANSACTION",e.ADD_RECENT_ADDRESS="ADD_RECENT_ADDRESS",e.LOAD_RECENT_ADDRESSES="LOAD_RECENT_ADDRESSES",e.SIGN_OUT="SIGN_OUT",e.SHOW_BACKUP_PHRASE="SHOW_BACKUP_PHRASE",e.SAVE_ALLOWLIST="SAVE_ALLOWLIST",e.SAVE_SETTINGS="SAVE_SETTINGS",e.LOAD_SETTINGS="LOAD_SETTINGS",e.GET_CACHED_ASSET_ICON="GET_CACHED_ASSET_ICON",e.CACHE_ASSET_ICON="CACHE_ASSET_ICON",e.GET_CACHED_ASSET_DOMAIN="GET_CACHED_ASSET_DOMAIN",e.CACHE_ASSET_DOMAIN="CACHE_ASSET_DOMAIN",e.GET_BLOCKED_ACCOUNTS="GET_BLOCKED_ACCOUNTS",e.GET_BLOCKED_DOMAINS="GET_BLOCKED_DOMAINS",e.ADD_CUSTOM_NETWORK="ADD_CUSTOM_NETWORK",e.CHANGE_NETWORK="CHANGE_NETWORK",e.REMOVE_CUSTOM_NETWORK="REMOVE_CUSTOM_NETWORK",e.EDIT_CUSTOM_NETWORK="EDIT_CUSTOM_NETWORK",e.RESET_EXP_DATA="RESET_EXP_DATA",e.ADD_TOKEN_ID="ADD_TOKEN_ID",e.GET_TOKEN_IDS="GET_TOKEN_IDS",e.REMOVE_TOKEN_ID="REMOVE_TOKEN_ID"}(e||(e={})),function(e){e.REQUEST_ACCESS="REQUEST_ACCESS",e.SUBMIT_TRANSACTION="SUBMIT_TRANSACTION",e.SUBMIT_BLOB="SUBMIT_BLOB",e.SUBMIT_AUTH_ENTRY="SUBMIT_AUTH_ENTRY",e.REQUEST_NETWORK="REQUEST_NETWORK",e.REQUEST_NETWORK_DETAILS="REQUEST_NETWORK_DETAILS",e.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS",e.REQUEST_ALLOWED_STATUS="REQUEST_ALLOWED_STATUS",e.SET_ALLOWED_STATUS="SET_ALLOWED_STATUS",e.REQUEST_USER_INFO="REQUEST_USER_INFO"}(r||(r={}));const T=e=>{const o=Date.now()+Math.random();return window.postMessage({source:"FREIGHTER_EXTERNAL_MSG_REQUEST",messageId:o,...e},window.location.origin),new Promise(E=>{let T=0;e.type===r.REQUEST_CONNECTION_STATUS&&(T=setTimeout(()=>{E({isConnected:!1}),window.removeEventListener("message",t)},2e3));const t=e=>{var r,_;e.source===window&&"FREIGHTER_EXTERNAL_MSG_RESPONSE"===(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.source)&&(null===(_=null==e?void 0:e.data)||void 0===_?void 0:_.messagedId)===o&&(E(e.data),window.removeEventListener("message",t),clearTimeout(T))};window.addEventListener("message",t,!1)})},t=()=>R?(async()=>{let e={publicKey:"",error:""};try{e=await T({type:r.REQUEST_ACCESS})}catch(e){console.error(e)}const{publicKey:o,error:E}=e;if(E)throw E;return o})():Promise.resolve(""),_=(e,o)=>R?(async(e,o,E)=>{let t="",_="",S="";"object"==typeof o?(t=o.network||"",_=o.accountToSign||"",S=o.networkPassphrase||""):(t=o||"",_="");let A={signedTransaction:"",error:""};try{A=await T({transactionXdr:e,network:t,networkPassphrase:S,accountToSign:_,type:r.SUBMIT_TRANSACTION})}catch(e){throw console.error(e),e}const{signedTransaction:n,error:N}=A;if(N)throw N;return n})(e,o):Promise.resolve(""),S=(e,o)=>R?(async(e,o)=>{let E={signedBlob:"",error:""};const t=(o||{}).accountToSign||"";try{E=await T({blob:e,accountToSign:t,type:r.SUBMIT_BLOB})}catch(e){throw console.error(e),e}const{signedBlob:_,error:S}=E;if(S)throw S;return _})(e,o):Promise.resolve(""),A=(e,o)=>R?(async(e,o)=>{let E={signedAuthEntry:"",error:""};const t=(o||{}).accountToSign||"";try{E=await T({entryXdr:e,accountToSign:t,type:r.SUBMIT_AUTH_ENTRY})}catch(e){console.error(e)}const{signedAuthEntry:_,error:S}=E;if(S)throw S;return _})(e,o):Promise.resolve(""),n=()=>R?window.freighter?Promise.resolve(window.freighter):(async()=>{let e={isConnected:!1};try{e=await T({type:r.REQUEST_CONNECTION_STATUS})}catch(e){console.error(e)}return e.isConnected})():Promise.resolve(!1),N=()=>R?(async()=>{let e={network:"",error:""};try{e=await T({type:r.REQUEST_NETWORK})}catch(e){console.error(e)}const{network:o,error:E}=e;if(E)throw E;return o})():Promise.resolve(""),s=()=>R?(async()=>{let e={networkDetails:{network:"",networkName:"",networkUrl:"",networkPassphrase:"",sorobanRpcUrl:void 0},error:""};try{e=await T({type:r.REQUEST_NETWORK_DETAILS})}catch(e){console.error(e)}const{networkDetails:o,error:E}=e,{network:t,networkUrl:_,networkPassphrase:S,sorobanRpcUrl:A}=o;if(E)throw E;return{network:t,networkUrl:_,networkPassphrase:S,sorobanRpcUrl:A}})():Promise.resolve({network:"",networkUrl:"",networkPassphrase:"",sorobanRpcUrl:""}),O=()=>R?(async()=>{let e={isAllowed:!1};try{e=await T({type:r.REQUEST_ALLOWED_STATUS})}catch(e){console.error(e)}return e.isAllowed})():Promise.resolve(!1),C=()=>R?(async()=>{let e={isAllowed:!1,error:""};try{e=await T({type:r.SET_ALLOWED_STATUS})}catch(e){console.error(e)}const{isAllowed:o,error:E}=e;if(E)throw E;return o})():Promise.resolve(!1),i=()=>R?(async()=>{let e={userInfo:{publicKey:""},error:""};try{e=await T({type:r.REQUEST_USER_INFO})}catch(e){console.error(e)}const{userInfo:o,error:E}=e;if(E)throw E;return o})():Promise.resolve({publicKey:""}),R="undefined"!=typeof window,a={getPublicKey:t,signTransaction:_,signBlob:S,signAuthEntry:A,isConnected:n,getNetwork:N,getNetworkDetails:s,isAllowed:O,setAllowed:C,getUserInfo:i};return E})());