1
2
|
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.freighterApi=e():r.freighterApi=e()}(this,(()=>(()=>{"use strict";var r,e,s={d:(r,e)=>{for(var t in e)s.o(e,t)&&!s.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},o:(r,e)=>Object.prototype.hasOwnProperty.call(r,e),r:r=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},t={};s.r(t),s.d(t,{WatchWalletChanges:()=>w,addToken:()=>i,default:()=>u,getAddress:()=>a,getNetwork:()=>N,getNetworkDetails:()=>l,isAllowed:()=>C,isBrowser:()=>I,isConnected:()=>c,requestAccess:()=>R,setAllowed:()=>O,signAuthEntry:()=>d,signMessage:()=>S,signTransaction:()=>_}),function(r){r.CREATE_ACCOUNT="CREATE_ACCOUNT",r.FUND_ACCOUNT="FUND_ACCOUNT",r.ADD_ACCOUNT="ADD_ACCOUNT",r.IMPORT_ACCOUNT="IMPORT_ACCOUNT",r.IMPORT_HARDWARE_WALLET="IMPORT_HARDWARE_WALLET",r.LOAD_ACCOUNT="LOAD_ACCOUNT",r.MAKE_ACCOUNT_ACTIVE="MAKE_ACCOUNT_ACTIVE",r.UPDATE_ACCOUNT_NAME="UPDATE_ACCOUNT_NAME",r.GET_MNEMONIC_PHRASE="GET_MNEMONIC_PHRASE",r.CONFIRM_MNEMONIC_PHRASE="CONFIRM_MNEMONIC_PHRASE",r.CONFIRM_MIGRATED_MNEMONIC_PHRASE="CONFIRM_MIGRATED_MNEMONIC_PHRASE",r.RECOVER_ACCOUNT="RECOVER_ACCOUNT",r.CONFIRM_PASSWORD="CONFIRM_PASSWORD",r.REJECT_ACCESS="REJECT_ACCESS",r.GRANT_ACCESS="GRANT_ACCESS",r.ADD_TOKEN="ADD_TOKEN",r.SIGN_TRANSACTION="SIGN_TRANSACTION",r.SIGN_BLOB="SIGN_BLOB",r.SIGN_AUTH_ENTRY="SIGN_AUTH_ENTRY",r.HANDLE_SIGNED_HW_PAYLOAD="HANDLE_SIGNED_HW_PAYLOAD",r.REJECT_TRANSACTION="REJECT_TRANSACTION",r.SIGN_FREIGHTER_TRANSACTION="SIGN_FREIGHTER_TRANSACTION",r.SIGN_FREIGHTER_SOROBAN_TRANSACTION="SIGN_FREIGHTER_SOROBAN_TRANSACTION",r.ADD_RECENT_ADDRESS="ADD_RECENT_ADDRESS",r.LOAD_RECENT_ADDRESSES="LOAD_RECENT_ADDRESSES",r.LOAD_LAST_USED_ACCOUNT="LOAD_LAST_USED_ACCOUNT",r.SIGN_OUT="SIGN_OUT",r.SHOW_BACKUP_PHRASE="SHOW_BACKUP_PHRASE",r.SAVE_ALLOWLIST="SAVE_ALLOWLIST",r.SAVE_SETTINGS="SAVE_SETTINGS",r.SAVE_EXPERIMENTAL_FEATURES="SAVE_EXPERIMENTAL_FEATURES",r.LOAD_SETTINGS="LOAD_SETTINGS",r.GET_CACHED_ASSET_ICON="GET_CACHED_ASSET_ICON",r.CACHE_ASSET_ICON="CACHE_ASSET_ICON",r.GET_CACHED_ASSET_DOMAIN="GET_CACHED_ASSET_DOMAIN",r.CACHE_ASSET_DOMAIN="CACHE_ASSET_DOMAIN",r.GET_MEMO_REQUIRED_ACCOUNTS="GET_MEMO_REQUIRED_ACCOUNTS",r.ADD_CUSTOM_NETWORK="ADD_CUSTOM_NETWORK",r.CHANGE_NETWORK="CHANGE_NETWORK",r.REMOVE_CUSTOM_NETWORK="REMOVE_CUSTOM_NETWORK",r.EDIT_CUSTOM_NETWORK="EDIT_CUSTOM_NETWORK",r.RESET_EXP_DATA="RESET_EXP_DATA",r.ADD_TOKEN_ID="ADD_TOKEN_ID",r.GET_TOKEN_IDS="GET_TOKEN_IDS",r.REMOVE_TOKEN_ID="REMOVE_TOKEN_ID",r.GET_MIGRATABLE_ACCOUNTS="GET_MIGRATABLE_ACCOUNTS",r.GET_MIGRATED_MNEMONIC_PHRASE="GET_MIGRATED_MNEMONIC_PHRASE",r.MIGRATE_ACCOUNTS="MIGRATE_ACCOUNTS",r.ADD_ASSETS_LIST="ADD_ASSETS_LIST",r.MODIFY_ASSETS_LIST="MODIFY_ASSETS_LIST"}(r||(r={})),function(r){r.REQUEST_ACCESS="REQUEST_ACCESS",r.REQUEST_PUBLIC_KEY="REQUEST_PUBLIC_KEY",r.SUBMIT_TOKEN="SUBMIT_TOKEN",r.SUBMIT_TRANSACTION="SUBMIT_TRANSACTION",r.SUBMIT_BLOB="SUBMIT_BLOB",r.SUBMIT_AUTH_ENTRY="SUBMIT_AUTH_ENTRY",r.REQUEST_NETWORK="REQUEST_NETWORK",r.REQUEST_NETWORK_DETAILS="REQUEST_NETWORK_DETAILS",r.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS",r.REQUEST_ALLOWED_STATUS="REQUEST_ALLOWED_STATUS",r.SET_ALLOWED_STATUS="SET_ALLOWED_STATUS",r.REQUEST_USER_INFO="REQUEST_USER_INFO"}(e||(e={}));const n=r=>{const s=Date.now()+Math.random();return window.postMessage({source:"FREIGHTER_EXTERNAL_MSG_REQUEST",messageId:s,...r},window.location.origin),new Promise((t=>{let n=0;r.type!==e.REQUEST_CONNECTION_STATUS&&r.type!==e.REQUEST_PUBLIC_KEY||(n=setTimeout((()=>{t({isConnected:!1,publicKey:""}),window.removeEventListener("message",o)}),2e3));const o=r=>{var e,E;r.source===window&&"FREIGHTER_EXTERNAL_MSG_RESPONSE"===(null===(e=null==r?void 0:r.data)||void 0===e?void 0:e.source)&&(null===(E=null==r?void 0:r.data)||void 0===E?void 0:E.messagedId)===s&&(t(r.data),window.removeEventListener("message",o),clearTimeout(n))};window.addEventListener("message",o,!1)}))},o={code:-1,message:"Node environment is not supported"},E={code:-1,message:"The wallet encountered an internal error. Please try again or contact the wallet if the problem persists."},T=async()=>{let r;try{r=await n({type:e.REQUEST_PUBLIC_KEY})}catch(r){console.error(r)}return{publicKey:(null==r?void 0:r.publicKey)||"",error:null==r?void 0:r.apiError}},A=async()=>{let r;try{r=await n({type:e.REQUEST_NETWORK_DETAILS})}catch(r){console.error(r)}const{networkDetails:s,apiError:t}=r||{networkDetails:{network:"",networkName:"",networkUrl:"",networkPassphrase:"",sorobanRpcUrl:void 0,apiError:""}},{network:o,networkUrl:E,networkPassphrase:T,sorobanRpcUrl:A}=s;return{network:o,networkUrl:E,networkPassphrase:T,sorobanRpcUrl:A,error:t}},a=async()=>{let r="";if(I){const e=await T();return r=e.publicKey,e.error?{address:r,error:e.error}:{address:r}}return{address:r,error:o}},i=async r=>{if(I){const s=await(async r=>{let s;try{s=await n({contractId:r.contractId,networkPassphrase:r.networkPassphrase,type:e.SUBMIT_TOKEN})}catch(r){return{error:E}}return{contractId:s.contractId,error:null==s?void 0:s.apiError}})(r);return s.error?{contractId:"",error:s.error}:{contractId:s.contractId||""}}return{contractId:"",error:o}},_=async(r,s)=>{if(I){const t=await(async(r,s)=>{let t,o,T,A;"object"==typeof s?(o=s.accountToSign,T=s.networkPassphrase):(t=s,o=void 0);try{A=await n({transactionXdr:r,network:t,networkPassphrase:T,accountToSign:o,type:e.SUBMIT_TRANSACTION})}catch(r){return{signedTransaction:"",signerAddress:"",error:E}}const{signedTransaction:a,signerAddress:i}=A;return{signedTransaction:a,signerAddress:i,error:null==A?void 0:A.apiError}})(r,s);return t.error?{signedTxXdr:"",signerAddress:"",error:t.error}:{signedTxXdr:t.signedTransaction,signerAddress:t.signerAddress}}return{signedTxXdr:"",signerAddress:"",error:o}},S=async(r,s)=>{if(I){const t=await(async(r,s,t)=>{let o;const T=(t||{}).address;try{o=await n({blob:r,accountToSign:T,apiVersion:s,type:e.SUBMIT_BLOB})}catch(r){return{signedMessage:null,signerAddress:"",error:E}}const{signedBlob:A,signerAddress:a}=o;return{signedMessage:A||null,signerAddress:a,error:null==o?void 0:o.apiError}})(r,"3.1.0",s);return t.error?{signedMessage:null,signerAddress:"",error:t.error}:{signedMessage:t.signedMessage,signerAddress:t.signerAddress}}return{signedMessage:null,signerAddress:"",error:o}},d=async(r,s)=>{if(I){const t=await(async(r,s)=>{const t=(s||{}).address;let o;try{o=await n({entryXdr:r,accountToSign:t,networkPassphrase:null==s?void 0:s.networkPassphrase,type:e.SUBMIT_AUTH_ENTRY})}catch(r){return console.error(r),{signedAuthEntry:null,signerAddress:"",error:E}}const{signedAuthEntry:T,signerAddress:A}=o;return{signedAuthEntry:T||null,signerAddress:A,error:null==o?void 0:o.apiError}})(r,s);return t.error?{signedAuthEntry:null,signerAddress:"",error:t.error}:{signedAuthEntry:t.signedAuthEntry,signerAddress:t.signerAddress}}return{signedAuthEntry:null,signerAddress:"",error:o}},c=async()=>I?window.freighter?Promise.resolve({isConnected:window.freighter}):(async()=>{let r={isConnected:!1};try{r=await n({type:e.REQUEST_CONNECTION_STATUS})}catch(r){console.error(r)}return{isConnected:r.isConnected}})():{isConnected:!1,error:o},N=async()=>{if(I){const r=await(async()=>{let r;try{r=await n({type:e.REQUEST_NETWORK_DETAILS})}catch(r){console.error(r)}const{networkDetails:s}=r||{networkDetails:{network:"",networkPassphrase:""}};return{network:null==s?void 0:s.network,networkPassphrase:null==s?void 0:s.networkPassphrase,error:null==r?void 0:r.apiError}})();return r.error?{network:"",networkPassphrase:"",error:r.error}:{network:r.network,networkPassphrase:r.networkPassphrase}}return{network:"",networkPassphrase:"",error:o}},l=async()=>{if(I){const r=await A();return r.error?{network:"",networkUrl:"",networkPassphrase:"",error:r.error}:{network:r.network,networkUrl:r.networkUrl,networkPassphrase:r.networkPassphrase,sorobanRpcUrl:r.sorobanRpcUrl}}return{network:"",networkUrl:"",networkPassphrase:"",error:o}},C=async()=>{let r=!1;if(I){const s=await(async()=>{let r;try{r=await n({type:e.REQUEST_ALLOWED_STATUS})}catch(r){console.error(r)}const{isAllowed:s}=r||{isAllowed:!1};return{isAllowed:s,error:null==r?void 0:r.apiError}})();return r=s.isAllowed,s.error?{isAllowed:r,error:s.error}:{isAllowed:r}}return{isAllowed:r,error:o}},O=async()=>{let r=!1;if(I){const s=await(async()=>{let r;try{r=await n({type:e.SET_ALLOWED_STATUS})}catch(r
|