UNPKG

@bajetech/astrax-api

Version:

Utility functions to interact with AstraX web extension

2 lines 3.83 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.astraxApi=t():e.astraxApi=t()}(this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";var n,o;r.r(t),function(e){e.CREATE_ACCOUNT="CREATE_ACCOUNT",e.FUND_ACCOUNT="FUND_ACCOUNT",e.ADD_ACCOUNT="ADD_ACCOUNT",e.IMPORT_ACCOUNT="IMPORT_ACCOUNT",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.REJECT_TRANSACTION="REJECT_TRANSACTION",e.SIGN_OUT="SIGN_OUT",e.SHOW_BACKUP_PHRASE="SHOW_BACKUP_PHRASE",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"}(n||(n={})),function(e){e.REQUEST_ACCESS="REQUEST_ACCESS",e.SUBMIT_TRANSACTION="SUBMIT_TRANSACTION",e.REQUEST_NETWORK="REQUEST_NETWORK"}(o||(o={}));var T,E;!function(e){e.TESTNET="Test network",e.PUBNET="Public network"}(T||(T={})),function(e){e.PUBLIC="PUBLIC",e.TESTNET="TESTNET"}(E||(E={}));class C extends Error{constructor(){super(...arguments),this.message="AstraX does not appear to be installed."}}const i=e=>{const t=Date.now()+Math.random();return window.postMessage({source:"ASTRAX_EXTERNAL_MSG_REQUEST",messageId:t,...e},window.location.origin),new Promise((e,r)=>{window.astrax||r(new C);const n=r=>{var o,T;r.source===window&&"ASTRAX_EXTERNAL_MSG_RESPONSE"===(null===(o=null==r?void 0:r.data)||void 0===o?void 0:o.source)&&(null===(T=null==r?void 0:r.data)||void 0===T?void 0:T.messagedId)===t&&(e(r.data),window.removeEventListener("message",n))};window.addEventListener("message",n,!1)})},A=()=>(async()=>{let e={publicKey:"",error:""};try{e=await i({type:o.REQUEST_ACCESS})}catch(e){console.error(e)}const{publicKey:t,error:r}=e;if(r)throw r;return t})(),S=(e,t)=>(async(e,t)=>{let r={signedTransaction:"",error:""};if(t&&t!==E.PUBLIC&&t!==E.TESTNET){throw`Network must be ${E.PUBLIC} or ${E.TESTNET}`}try{r=await i({transactionXdr:e,network:t,type:o.SUBMIT_TRANSACTION})}catch(e){console.error(e)}const{signedTransaction:n,error:T}=r;if(T)throw T;return n})(e,t),_=()=>!!window.astrax,a=()=>(async()=>{let e={network:"",error:""};try{e=await i({type:o.REQUEST_NETWORK})}catch(e){console.error(e)}const{network:t,error:r}=e;if(r)throw r;return t})();r.d(t,"getPublicKey",(function(){return A})),r.d(t,"signTransaction",(function(){return S})),r.d(t,"isConnected",(function(){return _})),r.d(t,"getNetwork",(function(){return a}));t.default={getPublicKey:A,signTransaction:S,isConnected:_,getNetwork:a}}])})); //# sourceMappingURL=index.min.js.map