edge-currency-accountbased 0.22.21 → 0.23.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/android/src/main/assets/edge-currency-accountbased/{645.chunk.js → 216.chunk.js} +6 -6
  3. package/android/src/main/assets/edge-currency-accountbased/244.chunk.js +1 -1
  4. package/android/src/main/assets/edge-currency-accountbased/387.chunk.js +9 -0
  5. package/android/src/main/assets/edge-currency-accountbased/491.chunk.js +1 -1
  6. package/android/src/main/assets/edge-currency-accountbased/549.chunk.js +1 -1
  7. package/android/src/main/assets/edge-currency-accountbased/94.chunk.js +8 -9
  8. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +3 -3
  9. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -2
  10. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +11 -11
  11. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +9 -9
  12. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  13. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
  14. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  15. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -4
  16. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
  17. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +6 -6
  18. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +3 -3
  19. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  20. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
  21. package/lib/binance/bnbEngine.js +28 -16
  22. package/lib/binance/bnbTypes.js +11 -0
  23. package/lib/common/engine.js +47 -3
  24. package/lib/common/types.js +20 -0
  25. package/lib/declare-modules.d.js +0 -22
  26. package/lib/eos/eosEngine.js +32 -21
  27. package/lib/eos/eosTypes.js +16 -0
  28. package/lib/eos/info/eosInfo.js +3 -1
  29. package/lib/ethereum/ethEngine.js +90 -140
  30. package/lib/ethereum/ethTypes.js +64 -0
  31. package/lib/fio/fioConst.js +26 -55
  32. package/lib/fio/fioEngine.js +830 -609
  33. package/lib/fio/fioError.js +15 -22
  34. package/lib/fio/fioInfo.js +13 -23
  35. package/lib/fio/fioPlugin.js +85 -94
  36. package/lib/fio/fioTypes.js +180 -1
  37. package/lib/hedera/hederaEngine.js +24 -12
  38. package/lib/hedera/hederaTypes.js +37 -0
  39. package/lib/polkadot/polkadotEngine.js +30 -10
  40. package/lib/polkadot/polkadotTypes.js +37 -0
  41. package/lib/solana/solanaEngine.js +25 -27
  42. package/lib/solana/solanaTypes.js +37 -0
  43. package/lib/stellar/stellarEngine.js +21 -19
  44. package/lib/stellar/stellarTypes.js +10 -0
  45. package/lib/tezos/tezosEngine.js +23 -18
  46. package/lib/tezos/tezosTypes.js +16 -0
  47. package/lib/tron/tronEngine.js +14 -7
  48. package/lib/tron/tronPlugin.js +1 -1
  49. package/lib/tron/tronTypes.js +15 -11
  50. package/lib/xrp/xrpEngine.js +86 -59
  51. package/lib/xrp/xrpTypes.js +16 -0
  52. package/lib/zcash/zecEngine.js +33 -27
  53. package/lib/zcash/zecInfo.js +4 -1
  54. package/lib/zcash/zecPlugin.js +20 -6
  55. package/lib/zcash/zecTypes.js +57 -1
  56. package/package.json +3 -3
  57. package/android/src/main/assets/edge-currency-accountbased/206.chunk.js +0 -8
@@ -1,6 +1,6 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[870],{79014:function(V,M,u){"use strict";u.d(M,{Q:function(){return N},k:function(){return F}});var f=u(77591),W=u.n(f),I=u(24350),_=u(84564),U=u.n(_),H=u(76714),$=Object.defineProperty,d=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,v=(c,p,o)=>p in c?$(c,p,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[p]=o,q=(c,p)=>{for(var o in p||(p={}))P.call(p,o)&&v(c,o,p[o]);if(d)for(var o of d(p))X.call(p,o)&&v(c,o,p[o]);return c};function F(c,p,o,y,L){const h=q({},U()(p,{},!0)),D=p.startsWith(`${c.pluginId}://`);if(h.protocol!=null&&(h.protocol=h.protocol.replace(":","")),h.protocol!=null&&h.protocol!==""&&!o[h.protocol])throw new Error(`Uri protocol '${h.protocol}' is not supported for ${c.pluginId}.`);if(h.host===""&&h.pathname==="")throw new Error("Path and host not found in uri.");const w={publicAddress:h.host!==""?h.host:h.pathname.split("/")[0]},K=h.query.label,A=h.query.message,T=h.query.category;(K!=null||A!=null||T!=null||D)&&(w.metadata={},w.metadata.name=K,w.metadata.notes=A,w.metadata.category=T,w.metadata.gateway=D!=null?D:!1);const C=h.query.amount;if(C!=null&&typeof C=="string"){y==null&&(y=c.currencyCode);const B=(0,H.cp)(c,y!=null?y:"",L);if(B==null)throw new Error("InternalErrorInvalidCurrencyCode");let g=(0,f.mul)(C,B.multiplier);g=(0,f.toFixed)(g,0,0),w.nativeAmount=g,w.currencyCode=y}return{edgeParsedUri:w,parsedUri:h}}function N(c,p,o){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(o==null&&c.label==null&&c.message==null)return c.publicAddress;{let y="";o!=null&&(y+="amount="+o+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(y+="label="+c.label+"&"),typeof c.message=="string"&&(y+="message="+c.message+"&")),y=y.substr(0,y.length-1);const L={scheme:p,path:c.publicAddress,query:y};return(0,I.qC)(L)}}},31188:function(V,M,u){"use strict";u.r(M),u.d(M,{StellarTools:function(){return C},makeCurrencyEngine:function(){return K},makeCurrencyTools:function(){return B}});var f=u(77591),W=u(13620),I=u.n(W),_=u(24350),U=u(84564),H=u.n(U),$=u(79014),d=u(76714),P=u(94935),X=u(50244),v=u(82448);const q=(0,v.su)({lastPagingToken:(0,v.Vk)(v.XC,"0"),accountSequence:(0,v.Vk)(v.mH,0)}),F=(0,v.su)({fee_charged:(0,v.su)({p50:v.XC,p70:v.XC,p95:v.XC})});var N=Object.getPrototypeOf,c=Reflect.get,p=(g,e,r)=>c(N(g),r,e),o=(g,e,r)=>new Promise((n,t)=>{var s=l=>{try{a(r.next(l))}catch(m){t(m)}},i=l=>{try{a(r.throw(l))}catch(m){t(m)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,i);a((r=r.apply(g,e)).next())});const y=2,L=15e3,h=3e4,D=5e3,O=100;class w extends X.P{constructor(e,r,n,t){super(e,r,n,t),this.getRecipientBalance=s=>o(this,null,function*(){var i;try{const l=(yield this.multicastServers("loadAccount",s)).balances.find(k=>k.asset_type==="native");if(l==null)return"0";const m=(0,d.cp)(this.currencyInfo,this.currencyInfo.currencyCode);if(m==null)throw new Error("Unknown denom");return(0,f.mul)(l.balance,m.multiplier)}catch(a){return((i=a.response)==null?void 0:i.title)==="Resource Missing"?"0":this.minimumAddressBalance}}),this.networkInfo=e.networkInfo,this.stellarApi={},this.activatedAccountsCache={},this.pendingTransactionsIndex=0,this.pendingTransactionsMap={},this.fees={low:O,standard:O,high:O},this.minimumAddressBalance=this.networkInfo.baseReserve}setOtherData(e){this.otherData=q(e)}multicastServers(e,...r){return o(this,null,function*(){let n={result:"",server:""},t;switch(e){case"feeStats":t=this.networkInfo.stellarServers.map(s=>()=>o(this,null,function*(){const i=yield fetch(`${s}/fee_stats`),a=F(yield i.json());return{server:s,result:a}})),n=yield(0,d.QJ)(t);break;case"loadAccount":t=this.tools.stellarApiServers.map(s=>()=>o(this,null,function*(){const i=yield s[e](...r);return{server:s.serverName,result:i}})),n=yield(0,d.QJ)(t);break;case"ledgers":t=this.tools.stellarApiServers.map(s=>()=>o(this,null,function*(){const i=yield s.ledgers().order("desc").limit(1).call(),a=i.records[0].sequence;if(this.walletLocalData.blockHeight<=a&&this.tools.highestTxHeight<=a)return{server:s.serverName,result:i};throw new Error("Height out of date")})),n=yield(0,d.QJ)(t);break;case"payments":t=this.tools.stellarApiServers.map(s=>()=>o(this,null,function*(){const i=yield s.payments().limit(y).cursor(this.otherData.lastPagingToken).forAccount(...r).call();return{server:s.serverName,result:i}})),n=yield(0,d.QJ)(t);break;case"submitTransaction":n=yield(0,d.Wp)(this.tools.stellarApiServers.map(s=>o(this,null,function*(){const i=yield s[e](...r);return{server:s.serverName,result:i}})));break}return this.log(`multicastServers ${e} ${n.server} won`),n.result})}processTransaction(e){return o(this,null,function*(){const r=[];let n="",t="",s="",i,a,l;e.type==="create_account"?(s=e.source_account,i=e.account,t=e.starting_balance,n=this.currencyInfo.currencyCode):e.type==="payment"&&(s=e.from,i=e.to,t=e.amount,e.asset_type==="native"?n=this.currencyInfo.currencyCode:n=e.asset_type);const m=Date.parse(e.created_at)/1e3,k=(0,d.cp)(this.currencyInfo,n);if(k!=null&&k.multiplier)a=(0,f.mul)(t,k.multiplier);else throw new Error("ErrorDenomNotFound");let b;try{b=yield e.transaction(),l=b.fee_charged.toString()}catch(R){throw this.error("processTransaction rawTx Error ",R),R}i===this.walletLocalData.publicKey?(r.push(s),s===this.walletLocalData.publicKey&&(a="-"+l)):(a=(0,f.add)(a,l),a="-"+a);const S={txid:e.transaction_hash,date:m,currencyCode:n,blockHeight:b.ledger_attr>0?b.ledger_attr:0,nativeAmount:a,networkFee:l,parentNetworkFee:"0",ourReceiveAddresses:r,signedTx:"",otherParams:{fromAddress:s,toAddress:i},walletId:this.walletId};return S.blockHeight>this.tools.highestTxHeight&&(this.tools.highestTxHeight=S.blockHeight),this.addTransaction(n,S),e.paging_token})}checkTransactionsInnerLoop(){return o(this,null,function*(){const e=this.walletLocalData.blockHeight,r=this.walletLocalData.publicKey;let n,t;for(;;)try{if(n?n=yield n.next():n=yield this.multicastServers("payments",r),n.records.length===0)break;for(const s of n.records)t=yield this.processTransaction(s)}catch(s){s.response&&s.response.title==="Resource Missing"?(this.log("Account not found. Probably not activated w/minimum XLM"),this.tokenCheckTransactionsStatus.XLM=1,this.updateOnAddressesChecked()):this.error("checkTransactionsInnerLoop Error fetching transaction info: ",s);return}this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]),t&&(this.otherData.lastPagingToken=t,this.walletLocalDataDirty=!0),this.walletLocalData.lastAddressQueryHeight=e,this.tokenCheckTransactionsStatus.XLM=1,this.updateOnAddressesChecked()})}checkUnconfirmedTransactionsFetch(){return o(this,null,function*(){})}checkAccountInnerLoop(){return o(this,null,function*(){const e=this.walletLocalData.publicKey;try{const r=yield this.multicastServers("loadAccount",e);r.sequence!==this.otherData.accountSequence&&(this.otherData.accountSequence=r.sequence);for(const n of r.balances){let t;n.asset_type==="native"?(t=this.currencyInfo.currencyCode,this.log("--Got balances--")):t=n.asset_type;const s=(0,d.cp)(this.currencyInfo,t);if(s!=null&&s.multiplier){const i=(0,f.mul)(n.balance,s.multiplier);this.updateBalance(t,i)}}}catch(r){r.response&&r.response.title==="Resource Missing"?(this.log("Account not found. Probably not activated w/minimum XLM"),this.tokenCheckBalanceStatus.XLM=1,this.updateOnAddressesChecked()):this.error("checkAccountInnerLoop Error fetching address info: ",r)}})}checkBlockchainInnerLoop(){this.multicastServers("ledgers").then(e=>{const r=e.records[0].sequence;this.walletLocalData.blockHeight!==r&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}).catch(e=>{this.error("checkBlockchainInnerLoop Error ",e)})}queryFee(){return o(this,null,function*(){try{const e=yield this.multicastServers("feeStats"),{p50:r,p70:n,p95:t}=e.fee_charged;this.fees={low:parseInt(r),standard:parseInt(n),high:parseInt(t)}}catch(e){this.error("queryFee Error ",e)}})}clearBlockchainCache(){return o(this,null,function*(){this.activatedAccountsCache={},this.pendingTransactionsIndex=0,this.pendingTransactionsMap={},yield p(w.prototype,this,"clearBlockchainCache").call(this),this.otherData.accountSequence=0})}startEngine(){return o(this,null,function*(){this.engineOn=!0,this.addToLoop("queryFee",h).catch(()=>{}),this.addToLoop("checkBlockchainInnerLoop",h).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",L).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",D).catch(()=>{}),yield p(w.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return o(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(e){return o(this,null,function*(){const{edgeSpendInfo:r,currencyCode:n,nativeBalance:t,denom:s}=this.makeSpendCheck(e);if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:i}=r.spendTargets[0];let{nativeAmount:a}=r.spendTargets[0];if(i==null)throw new Error("makeSpend Missing publicAddress");if(a==null)throw new P.$D;let l=!1;const m=this.activatedAccountsCache[i];if(m===void 0)try{yield this.multicastServers("loadAccount",i),this.activatedAccountsCache[i]=!0}catch{this.activatedAccountsCache[i]=!1,l=!0}else m||(l=!0);if((0,f.eq)(a,"0"))throw new P.$D;const k=(0,f.div)(a,s.multiplier,7),b=new this.stellarApi.Account(this.walletLocalData.publicKey,this.otherData.accountSequence);let S;r.spendTargets[0].otherParams!=null&&r.spendTargets[0].otherParams.uniqueIdentifier&&(S=r.spendTargets[0].otherParams.uniqueIdentifier);const R=r.networkFeeOption!==void 0&&r.networkFeeOption!=="custom"?this.fees[r.networkFeeOption]:O,Q=new this.stellarApi.TransactionBuilder(b,{fee:R});let E;if(l?E=Q.addOperation(this.stellarApi.Operation.createAccount({destination:i,startingBalance:k})):E=Q.addOperation(this.stellarApi.Operation.payment({destination:i,asset:this.stellarApi.Asset.native(),amount:k})),S){const J=this.stellarApi.Memo.id(S);E=E.addMemo(J)}E=E.build();const G=E.fee.toString();a=(0,f.add)(G,a);const z=(0,f.sub)(t,this.networkInfo.baseReserve);if((0,f.gt)(a,z))throw new P.C_;a=`-${a}`;const x=this.pendingTransactionsIndex,Y={txid:"",date:0,currencyCode:n,blockHeight:0,nativeAmount:a,networkFee:G,ourReceiveAddresses:[],signedTx:"",otherParams:{idInternal:x,fromAddress:this.walletLocalData.publicKey,toAddress:i},walletId:this.walletId};return this.pendingTransactionsMap[x]=E,this.pendingTransactionsIndex++,this.pendingTransactionsMap[this.pendingTransactionsIndex-20]&&delete this.pendingTransactionsMap[this.pendingTransactionsIndex-20],this.warn("Stellar transaction prepared"),this.warn(`idInternal: ${x}`),this.warn(`${a} ${this.walletLocalData.publicKey} -> ${i}`),Y})}signTx(e){return o(this,null,function*(){const r=(0,d.Xp)(e),n=(0,f.abs)((0,f.add)(e.nativeAmount,e.networkFee));yield this.checkRecipientMinimumBalance(this.getRecipientBalance,n,r.toAddress);try{const{idInternal:t}=r,s=this.pendingTransactionsMap[t];if(!s)throw new Error("ErrorInvalidTransaction");this.warn("Signing...");const i=this.stellarApi.Keypair.fromSecret(this.walletInfo.keys.stellarKey);yield s.sign(i)}catch(t){throw this.error(`FAILURE signTx
2
- ${JSON.stringify((0,d.oX)(e))} `,t),t}return this.warn(`signTx
3
- ${(0,d.oX)(e)}`),e})}broadcastTx(e){return o(this,null,function*(){const r=(0,d.Xp)(e);try{const{idInternal:n}=r,t=this.pendingTransactionsMap[n];if(!t)throw new Error("ErrorInvalidTransaction");this.warn(`Broadcasting...
4
- ${(0,d.oX)(e)}`);const s=yield this.multicastServers("submitTransaction",t);e.txid=s.hash,e.date=Date.now()/1e3,this.activatedAccountsCache[r.toAddress]=!0,this.otherData.accountSequence++,this.walletLocalDataDirty=!0,this.warn(`SUCCESS broadcastTx
5
- ${(0,d.oX)(e)}`)}catch(n){throw this.error(`FAILURE broadcastTx
6
- ${JSON.stringify((0,d.oX)(e))} `,n),n}return e})}getDisplayPrivateSeed(){return this.walletInfo.keys&&this.walletInfo.keys.stellarKey?this.walletInfo.keys.stellarKey:""}getDisplayPublicSeed(){return this.walletInfo.keys&&this.walletInfo.keys.publicKey?this.walletInfo.keys.publicKey:""}}function K(g,e,r,n){return o(this,null,function*(){const t=new w(g,e,r,n);return t.stellarApi=I(),yield t.loadEngine(e,r,n),t})}var A=(g,e,r)=>new Promise((n,t)=>{var s=l=>{try{a(r.next(l))}catch(m){t(m)}},i=l=>{try{a(r.throw(l))}catch(m){t(m)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,i);a((r=r.apply(g,e)).next())});const T="web+stellar";class C{constructor(e){this.highestTxHeight=0;const{builtinTokens:r,currencyInfo:n,io:t,networkInfo:s}=e;this.builtinTokens=r,this.currencyInfo=n,this.io=t,this.networkInfo=s,I().Network.usePublicNetwork(),this.stellarApiServers=[];for(const i of this.networkInfo.stellarServers){const a=new(I()).Server(i);a.serverName=i,this.stellarApiServers.push(a)}}checkAddress(e){try{return I().Keypair.fromPublicKey(e),!0}catch{return!1}}createPrivateKey(e){return A(this,null,function*(){if(e!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const r=Array.from(this.io.random(32));return{stellarKey:I().Keypair.fromRawEd25519Seed(r).secret()}})}importPrivateKey(e){return A(this,null,function*(){if(e.replace(/ /g,""),I().Keypair.fromSecret(e),e.length!==56)throw new Error("Private key wrong length");return yield Promise.resolve({stellarKey:e})})}derivePublicKey(e){return A(this,null,function*(){if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");return{publicKey:I().Keypair.fromSecret(e.keys.stellarKey).publicKey()}})}parseUri(e){return A(this,null,function*(){const r={};r[T]=!0;const n=`${T}:pay`;if(e.includes(n)){const l=H()(e,{},!0).query.destination;l&&(e=e.replace(n,`${T}:${l}`))}const{parsedUri:t,edgeParsedUri:s}=(0,$.k)(this.currencyInfo,e,r);if(!this.checkAddress(s.publicAddress||""))throw new Error("InvalidPublicAddressError");if(t.query.msg&&(s.metadata={notes:t.query.msg}),t.query.asset_code&&t.query.asset_code.toUpperCase()!=="XLM")throw new Error("ErrorInvalidCurrencyCode");if(t.query.memo_type&&t.query.memo_type!=="MEMO_ID")throw new Error("ErrorInvalidMemoType");if(t.query.memo){if((0,f.add)(t.query.memo,"0")!==t.query.memo)throw new Error("ErrorInvalidMemoId");s.uniqueIdentifier=t.query.memo}return s})}encodeUri(e){return A(this,null,function*(){if(!this.checkAddress(e.publicAddress))throw new Error("InvalidPublicAddressError");let n;if(typeof e.nativeAmount=="string"){const t="XLM",s=e.nativeAmount,i=(0,d.cp)(this.currencyInfo,t);if(i==null)throw new Error("InternalErrorInvalidCurrencyCode");n=(0,f.div)(s,i.multiplier,7)}if(!n&&!e.label&&!e.message)return e.publicAddress;{let t=`destination=${e.publicAddress}&`;n&&(t+="amount="+n+"&"),(e.label||e.message)&&(typeof e.label=="string"&&(t+="label="+e.label+"&"),typeof e.message=="string"&&(t+="msg="+e.message+"&")),t=t.substr(0,t.length-1);const s={scheme:T,path:"pay",query:t};return(0,_.qC)(s)}})}}function B(g){return A(this,null,function*(){return new C(g)})}},89214:function(){},52361:function(){},94616:function(){},17002:function(){},55024:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[870],{79014:function(Y,K,u){"use strict";u.d(K,{Q:function(){return N},k:function(){return F}});var f=u(77591),W=u.n(f),A=u(24350),U=u(84564),_=u.n(U),H=u(76714),X=Object.defineProperty,h=Object.getOwnPropertySymbols,D=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,y=(c,d,p)=>d in c?X(c,d,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[d]=p,q=(c,d)=>{for(var p in d||(d={}))D.call(d,p)&&y(c,p,d[p]);if(h)for(var p of h(d))$.call(d,p)&&y(c,p,d[p]);return c};function F(c,d,p,m,b){const o=q({},_()(d,{},!0)),O=d.startsWith(`${c.pluginId}://`);if(o.protocol!=null&&(o.protocol=o.protocol.replace(":","")),o.protocol!=null&&o.protocol!==""&&!p[o.protocol])throw new Error(`Uri protocol '${o.protocol}' is not supported for ${c.pluginId}.`);if(o.host===""&&o.pathname==="")throw new Error("Path and host not found in uri.");const v={publicAddress:o.host!==""?o.host:o.pathname.split("/")[0]},B=o.query.label,T=o.query.message,C=o.query.category;(B!=null||T!=null||C!=null||O)&&(v.metadata={},v.metadata.name=B,v.metadata.notes=T,v.metadata.category=C,v.metadata.gateway=O!=null?O:!1);const M=o.query.amount;if(M!=null&&typeof M=="string"){m==null&&(m=c.currencyCode);const I=(0,H.cp)(c,m!=null?m:"",b);if(I==null)throw new Error("InternalErrorInvalidCurrencyCode");let k=(0,f.mul)(M,I.multiplier);k=(0,f.toFixed)(k,0,0),v.nativeAmount=k,v.currencyCode=m}return{edgeParsedUri:v,parsedUri:o}}function N(c,d,p){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&c.label==null&&c.message==null)return c.publicAddress;{let m="";p!=null&&(m+="amount="+p+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(m+="label="+c.label+"&"),typeof c.message=="string"&&(m+="message="+c.message+"&")),m=m.substr(0,m.length-1);const b={scheme:d,path:c.publicAddress,query:m};return(0,A.qC)(b)}}},31188:function(Y,K,u){"use strict";u.r(K),u.d(K,{StellarTools:function(){return G},makeCurrencyEngine:function(){return M},makeCurrencyTools:function(){return Z}});var f=u(77591),W=u(13620),A=u.n(W),U=u(24350),_=u(84564),H=u.n(_),X=u(79014),h=u(76714),D=u(94935),$=u(50244),y=u(82448),q=u(62177);const F=(0,y.su)({lastPagingToken:(0,y.Vk)(y.XC,"0"),accountSequence:(0,y.Vk)(y.mH,0)}),N=(0,y.su)({fee_charged:(0,y.su)({p50:y.XC,p70:y.XC,p95:y.XC})}),c=q.BQ,d=(0,y.su)({stellarKey:y.XC});var p=Object.getPrototypeOf,m=Reflect.get,b=(w,e,r)=>m(p(w),r,e),o=(w,e,r)=>new Promise((s,t)=>{var n=l=>{try{i(r.next(l))}catch(g){t(g)}},a=l=>{try{i(r.throw(l))}catch(g){t(g)}},i=l=>l.done?s(l.value):Promise.resolve(l.value).then(n,a);i((r=r.apply(w,e)).next())});const O=2,Q=15e3,v=3e4,B=5e3,T=100;class C extends $.P{constructor(e,r,s,t){super(e,r,s,t),this.getRecipientBalance=n=>o(this,null,function*(){var a;try{const l=(yield this.multicastServers("loadAccount",n)).balances.find(E=>E.asset_type==="native");if(l==null)return"0";const g=(0,h.cp)(this.currencyInfo,this.currencyInfo.currencyCode);if(g==null)throw new Error("Unknown denom");return(0,f.mul)(l.balance,g.multiplier)}catch(i){return((a=i.response)==null?void 0:a.title)==="Resource Missing"?"0":this.minimumAddressBalance}}),this.networkInfo=e.networkInfo,this.stellarApi={},this.activatedAccountsCache={},this.pendingTransactionsIndex=0,this.pendingTransactionsMap={},this.fees={low:T,standard:T,high:T},this.minimumAddressBalance=this.networkInfo.baseReserve}setOtherData(e){this.otherData=F(e)}multicastServers(e,...r){return o(this,null,function*(){let s={result:"",server:""},t;switch(e){case"feeStats":t=this.networkInfo.stellarServers.map(n=>()=>o(this,null,function*(){const a=yield fetch(`${n}/fee_stats`),i=N(yield a.json());return{server:n,result:i}})),s=yield(0,h.QJ)(t);break;case"loadAccount":t=this.tools.stellarApiServers.map(n=>()=>o(this,null,function*(){const a=yield n[e](...r);return{server:n.serverName,result:a}})),s=yield(0,h.QJ)(t);break;case"ledgers":t=this.tools.stellarApiServers.map(n=>()=>o(this,null,function*(){const a=yield n.ledgers().order("desc").limit(1).call(),i=a.records[0].sequence;if(this.walletLocalData.blockHeight<=i&&this.tools.highestTxHeight<=i)return{server:n.serverName,result:a};throw new Error("Height out of date")})),s=yield(0,h.QJ)(t);break;case"payments":t=this.tools.stellarApiServers.map(n=>()=>o(this,null,function*(){const a=yield n.payments().limit(O).cursor(this.otherData.lastPagingToken).forAccount(...r).call();return{server:n.serverName,result:a}})),s=yield(0,h.QJ)(t);break;case"submitTransaction":s=yield(0,h.Wp)(this.tools.stellarApiServers.map(n=>o(this,null,function*(){const a=yield n[e](...r);return{server:n.serverName,result:a}})));break}return this.log(`multicastServers ${e} ${s.server} won`),s.result})}processTransaction(e){return o(this,null,function*(){const r=[];let s="",t="",n="",a,i,l;e.type==="create_account"?(n=e.source_account,a=e.account,t=e.starting_balance,s=this.currencyInfo.currencyCode):e.type==="payment"&&(n=e.from,a=e.to,t=e.amount,e.asset_type==="native"?s=this.currencyInfo.currencyCode:s=e.asset_type);const g=Date.parse(e.created_at)/1e3,E=(0,h.cp)(this.currencyInfo,s);if(E!=null&&E.multiplier)i=(0,f.mul)(t,E.multiplier);else throw new Error("ErrorDenomNotFound");let L;try{L=yield e.transaction(),l=L.fee_charged.toString()}catch(R){throw this.error("processTransaction rawTx Error ",R),R}a===this.walletLocalData.publicKey?(r.push(n),n===this.walletLocalData.publicKey&&(i="-"+l)):(i=(0,f.add)(i,l),i="-"+i);const P={txid:e.transaction_hash,date:g,currencyCode:s,blockHeight:L.ledger_attr>0?L.ledger_attr:0,nativeAmount:i,networkFee:l,parentNetworkFee:"0",ourReceiveAddresses:r,signedTx:"",otherParams:{fromAddress:n,toAddress:a},walletId:this.walletId};return P.blockHeight>this.tools.highestTxHeight&&(this.tools.highestTxHeight=P.blockHeight),this.addTransaction(s,P),e.paging_token})}checkTransactionsInnerLoop(){return o(this,null,function*(){const e=this.walletLocalData.blockHeight,r=this.walletLocalData.publicKey;let s,t;for(;;)try{if(s?s=yield s.next():s=yield this.multicastServers("payments",r),s.records.length===0)break;for(const n of s.records)t=yield this.processTransaction(n)}catch(n){n.response&&n.response.title==="Resource Missing"?(this.log("Account not found. Probably not activated w/minimum XLM"),this.tokenCheckTransactionsStatus.XLM=1,this.updateOnAddressesChecked()):this.error("checkTransactionsInnerLoop Error fetching transaction info: ",n);return}this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]),t&&(this.otherData.lastPagingToken=t,this.walletLocalDataDirty=!0),this.walletLocalData.lastAddressQueryHeight=e,this.tokenCheckTransactionsStatus.XLM=1,this.updateOnAddressesChecked()})}checkUnconfirmedTransactionsFetch(){return o(this,null,function*(){})}checkAccountInnerLoop(){return o(this,null,function*(){const e=this.walletLocalData.publicKey;try{const r=yield this.multicastServers("loadAccount",e);r.sequence!==this.otherData.accountSequence&&(this.otherData.accountSequence=r.sequence);for(const s of r.balances){let t;s.asset_type==="native"?(t=this.currencyInfo.currencyCode,this.log("--Got balances--")):t=s.asset_type;const n=(0,h.cp)(this.currencyInfo,t);if(n!=null&&n.multiplier){const a=(0,f.mul)(s.balance,n.multiplier);this.updateBalance(t,a)}}}catch(r){r.response&&r.response.title==="Resource Missing"?(this.log("Account not found. Probably not activated w/minimum XLM"),this.tokenCheckBalanceStatus.XLM=1,this.updateOnAddressesChecked()):this.error("checkAccountInnerLoop Error fetching address info: ",r)}})}checkBlockchainInnerLoop(){this.multicastServers("ledgers").then(e=>{const r=e.records[0].sequence;this.walletLocalData.blockHeight!==r&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}).catch(e=>{this.error("checkBlockchainInnerLoop Error ",e)})}queryFee(){return o(this,null,function*(){try{const e=yield this.multicastServers("feeStats"),{p50:r,p70:s,p95:t}=e.fee_charged;this.fees={low:parseInt(r),standard:parseInt(s),high:parseInt(t)}}catch(e){this.error("queryFee Error ",e)}})}clearBlockchainCache(){return o(this,null,function*(){this.activatedAccountsCache={},this.pendingTransactionsIndex=0,this.pendingTransactionsMap={},yield b(C.prototype,this,"clearBlockchainCache").call(this),this.otherData.accountSequence=0})}startEngine(){return o(this,null,function*(){this.engineOn=!0,this.addToLoop("queryFee",v).catch(()=>{}),this.addToLoop("checkBlockchainInnerLoop",v).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",Q).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",B).catch(()=>{}),yield b(C.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return o(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(e){return o(this,null,function*(){const{edgeSpendInfo:r,currencyCode:s,nativeBalance:t,denom:n}=this.makeSpendCheck(e);if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:a}=r.spendTargets[0];let{nativeAmount:i}=r.spendTargets[0];if(a==null)throw new Error("makeSpend Missing publicAddress");if(i==null)throw new D.$D;let l=!1;const g=this.activatedAccountsCache[a];if(g===void 0)try{yield this.multicastServers("loadAccount",a),this.activatedAccountsCache[a]=!0}catch{this.activatedAccountsCache[a]=!1,l=!0}else g||(l=!0);if((0,f.eq)(i,"0"))throw new D.$D;const E=(0,f.div)(i,n.multiplier,7),L=new this.stellarApi.Account(this.walletLocalData.publicKey,this.otherData.accountSequence);let P;r.spendTargets[0].otherParams!=null&&r.spendTargets[0].otherParams.uniqueIdentifier&&(P=r.spendTargets[0].otherParams.uniqueIdentifier);const R=r.networkFeeOption!==void 0&&r.networkFeeOption!=="custom"?this.fees[r.networkFeeOption]:T,J=new this.stellarApi.TransactionBuilder(L,{fee:R});let S;if(l?S=J.addOperation(this.stellarApi.Operation.createAccount({destination:a,startingBalance:E})):S=J.addOperation(this.stellarApi.Operation.payment({destination:a,asset:this.stellarApi.Asset.native(),amount:E})),P){const z=this.stellarApi.Memo.id(P);S=S.addMemo(z)}S=S.build();const V=S.fee.toString();i=(0,f.add)(V,i);const j=(0,f.sub)(t,this.networkInfo.baseReserve);if((0,f.gt)(i,j))throw new D.C_;i=`-${i}`;const x=this.pendingTransactionsIndex,ee={txid:"",date:0,currencyCode:s,blockHeight:0,nativeAmount:i,networkFee:V,ourReceiveAddresses:[],signedTx:"",otherParams:{idInternal:x,fromAddress:this.walletLocalData.publicKey,toAddress:a},walletId:this.walletId};return this.pendingTransactionsMap[x]=S,this.pendingTransactionsIndex++,this.pendingTransactionsMap[this.pendingTransactionsIndex-20]&&delete this.pendingTransactionsMap[this.pendingTransactionsIndex-20],this.warn("Stellar transaction prepared"),this.warn(`idInternal: ${x}`),this.warn(`${i} ${this.walletLocalData.publicKey} -> ${a}`),ee})}signTx(e,r){return o(this,null,function*(){const s=d(r),t=(0,h.Xp)(e),n=(0,f.abs)((0,f.add)(e.nativeAmount,e.networkFee));yield this.checkRecipientMinimumBalance(this.getRecipientBalance,n,t.toAddress);try{const{idInternal:a}=t,i=this.pendingTransactionsMap[a];if(!i)throw new Error("ErrorInvalidTransaction");this.warn("Signing...");const l=this.stellarApi.Keypair.fromSecret(s.stellarKey);yield i.sign(l)}catch(a){throw this.error(`FAILURE signTx
2
+ ${JSON.stringify((0,h.oX)(e))} `,a),a}return this.warn(`signTx
3
+ ${(0,h.oX)(e)}`),e})}broadcastTx(e){return o(this,null,function*(){const r=(0,h.Xp)(e);try{const{idInternal:s}=r,t=this.pendingTransactionsMap[s];if(!t)throw new Error("ErrorInvalidTransaction");this.warn(`Broadcasting...
4
+ ${(0,h.oX)(e)}`);const n=yield this.multicastServers("submitTransaction",t);e.txid=n.hash,e.date=Date.now()/1e3,this.activatedAccountsCache[r.toAddress]=!0,this.otherData.accountSequence++,this.walletLocalDataDirty=!0,this.warn(`SUCCESS broadcastTx
5
+ ${(0,h.oX)(e)}`)}catch(s){throw this.error(`FAILURE broadcastTx
6
+ ${JSON.stringify((0,h.oX)(e))} `,s),s}return e})}getDisplayPrivateSeed(e){return d(e).stellarKey}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}}function M(w,e,r,s){return o(this,null,function*(){const t=c(r),n=new C(w,e,t,s);return n.stellarApi=A(),yield n.loadEngine(e,t,s),n})}var I=(w,e,r)=>new Promise((s,t)=>{var n=l=>{try{i(r.next(l))}catch(g){t(g)}},a=l=>{try{i(r.throw(l))}catch(g){t(g)}},i=l=>l.done?s(l.value):Promise.resolve(l.value).then(n,a);i((r=r.apply(w,e)).next())});const k="web+stellar";class G{constructor(e){this.highestTxHeight=0;const{builtinTokens:r,currencyInfo:s,io:t,networkInfo:n}=e;this.builtinTokens=r,this.currencyInfo=s,this.io=t,this.networkInfo=n,A().Network.usePublicNetwork(),this.stellarApiServers=[];for(const a of this.networkInfo.stellarServers){const i=new(A()).Server(a);i.serverName=a,this.stellarApiServers.push(i)}}checkAddress(e){try{return A().Keypair.fromPublicKey(e),!0}catch{return!1}}createPrivateKey(e){return I(this,null,function*(){if(e!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const r=Array.from(this.io.random(32));return{stellarKey:A().Keypair.fromRawEd25519Seed(r).secret()}})}importPrivateKey(e){return I(this,null,function*(){if(e.replace(/ /g,""),A().Keypair.fromSecret(e),e.length!==56)throw new Error("Private key wrong length");return yield Promise.resolve({stellarKey:e})})}derivePublicKey(e){return I(this,null,function*(){if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");return{publicKey:A().Keypair.fromSecret(e.keys.stellarKey).publicKey()}})}parseUri(e){return I(this,null,function*(){const r={};r[k]=!0;const s=`${k}:pay`;if(e.includes(s)){const l=H()(e,{},!0).query.destination;l&&(e=e.replace(s,`${k}:${l}`))}const{parsedUri:t,edgeParsedUri:n}=(0,X.k)(this.currencyInfo,e,r);if(!this.checkAddress(n.publicAddress||""))throw new Error("InvalidPublicAddressError");if(t.query.msg&&(n.metadata={notes:t.query.msg}),t.query.asset_code&&t.query.asset_code.toUpperCase()!=="XLM")throw new Error("ErrorInvalidCurrencyCode");if(t.query.memo_type&&t.query.memo_type!=="MEMO_ID")throw new Error("ErrorInvalidMemoType");if(t.query.memo){if((0,f.add)(t.query.memo,"0")!==t.query.memo)throw new Error("ErrorInvalidMemoId");n.uniqueIdentifier=t.query.memo}return n})}encodeUri(e){return I(this,null,function*(){if(!this.checkAddress(e.publicAddress))throw new Error("InvalidPublicAddressError");let s;if(typeof e.nativeAmount=="string"){const t="XLM",n=e.nativeAmount,a=(0,h.cp)(this.currencyInfo,t);if(a==null)throw new Error("InternalErrorInvalidCurrencyCode");s=(0,f.div)(n,a.multiplier,7)}if(!s&&!e.label&&!e.message)return e.publicAddress;{let t=`destination=${e.publicAddress}&`;s&&(t+="amount="+s+"&"),(e.label||e.message)&&(typeof e.label=="string"&&(t+="label="+e.label+"&"),typeof e.message=="string"&&(t+="msg="+e.message+"&")),t=t.substr(0,t.length-1);const n={scheme:k,path:"pay",query:t};return(0,U.qC)(n)}})}}function Z(w){return I(this,null,function*(){return new G(w)})}},89214:function(){},52361:function(){},94616:function(){},17002:function(){},55024:function(){}}]);
@@ -1,3 +1,3 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[92],{12170:function(j,I,f){"use strict";f.r(I),f.d(I,{TezosTools:function(){return E},makeCurrencyEngine:function(){return H},makeCurrencyTools:function(){return $}});var u=f(19971),C=f(39143),y=f(77591),b=f(94935),A=f(50244),d=f(76714),L=f(81649),h=f(82448);const O=(0,h.su)({numberTransactions:(0,h.Vk)(h.mH,0)}),D=(0,h.su)({level:h.mH,timestamp:h.XC,hash:h.XC,sender:(0,h.su)({address:h.XC}),bakerFee:h.mH,allocationFee:h.mH,target:(0,h.su)({address:h.XC}),amount:h.mH,status:h.XC});var P=Object.getPrototypeOf,N=Reflect.get,T=(p,t,e)=>N(P(p),e,t),l=(p,t,e)=>new Promise((r,n)=>{var s=i=>{try{o(e.next(i))}catch(a){n(a)}},c=i=>{try{o(e.throw(i))}catch(a){n(a)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((e=e.apply(p,t)).next())});const B=15e3,K=3e4,R=5e3,x=(0,d.jT)(),S=L.j.currencyCode;class m extends A.P{constructor(t,e,r,n){super(t,e,r,n),this.networkInfo=t.networkInfo;const s=(0,d.zR)(t);this.fetchCors=s}setOtherData(t){this.otherData=O(t)}multicastServers(t,...e){return l(this,null,function*(){let r={result:"",server:"no server"},n;switch(t){case"getHead":{n=this.tools.tezosRpcNodes.map(c=>()=>l(this,null,function*(){const o=yield this.io.fetch(c+"/chains/main/blocks/head/header").then(function(i){return l(this,null,function*(){return yield i.json()})}).then(function(i){return i});return{server:c,result:o}})),r=yield(0,d.QJ)(n);break}case"getBalance":{n=this.tools.tezosRpcNodes.map(c=>()=>l(this,null,function*(){u.eztz.node.setProvider(c);const o=yield u.eztz.rpc.getBalance(e[0]);return{server:c,result:o}})),r=yield(0,d.QJ)(n);break}case"getNumberOfOperations":n=this.tools.tezosApiServers.map(s=>()=>l(this,null,function*(){const c=yield this.fetchCors(`${s}/v1/accounts/${e[0]}`).then(function(o){return l(this,null,function*(){return yield o.json()})}).then(function(o){return o.numTransactions});return{server:s,result:c}})),r=yield(0,d.QJ)(n);break;case"getTransactions":n=this.tools.tezosApiServers.map(s=>()=>l(this,null,function*(){const c=s.includes("tzkt")?"":`&p='${e[1]}&number=50`,o=yield this.fetchCors(`${s}/v1/accounts/${e[0]}/operations?type=transaction`+c).then(function(i){return l(this,null,function*(){return yield i.json()})});return{server:s,result:o}})),r=yield(0,d.QJ)(n);break;case"createTransaction":n=this.tools.tezosRpcNodes.map(s=>()=>l(this,null,function*(){u.eztz.node.setProvider(s);const c=yield u.eztz.rpc.transfer(e[0],e[1],e[2],e[3],e[4],null,this.networkInfo.limit.gas,this.networkInfo.limit.storage,this.networkInfo.fee.reveal).then(function(o){return o});return{server:s,result:c}})),r=yield(0,d.QJ)(n);break;case"injectOperation":{let s="";n=this.tools.tezosRpcNodes.map(c=>()=>l(this,null,function*(){u.eztz.node.setProvider(c);const o=yield u.eztz.rpc.inject(e[0],e[1]).catch(i=>{this.error("Error when injection operation: ",i);const a=this.formatError(i);throw!s&&a!==""&&(s=a),i});return this.multicastServers("silentInjection",c,e[1]),{server:c,result:o}})),r=yield(0,d.QJ)(n).catch(c=>{throw this.error("Error from waterfall: ",c),s!==""?new Error(s):c});break}case"silentInjection":{const s=this.tools.tezosRpcNodes.indexOf(e[0]),c=this.tools.tezosRpcNodes.slice(s+1);r=yield(0,d.Wp)(c.map(o=>l(this,null,function*(){u.eztz.node.setProvider(o);const i=yield u.eztz.rpc.silentInject(e[1]);return this.warn(`Injected silently to: ${o}`),{server:o,result:i}})));break}}return this.log(`XTZ multicastServers ${t} ${r.server} won with result ${r.result}`),r.result})}formatError(t){if(typeof t=="string")return t;try{if(t.error&&t.error==="Operation Failed"&&t.errors&&t.errors[0].id)return"Failed in preapply with an error code ("+t.errors[0].id+")";if(t[0]&&t[0].kind&&t[0].kind==="branch"&&t[0].id)return"Failed in preapply with an error code ("+t[0].id+")"}catch{}return""}processTezosTransaction(t){const e=D(t),r=this.walletLocalData.publicKey,n=[],s=S,c=new Date(e.timestamp).getTime()/1e3,o=e.level;let i=e.amount.toString();const a=(e.bakerFee+e.allocationFee).toString(),z=e.status==="failed";r===e.target.address?(n.push(r),e.sender.address===r&&(i="-"+a)):i="-"+(0,y.add)(i,a);const g={txid:t.hash,date:c,currencyCode:s,blockHeight:o,nativeAmount:i,networkFee:a,ourReceiveAddresses:n,signedTx:"",otherParams:{},walletId:this.walletId};z||this.addTransaction(s,g)}checkTransactionsInnerLoop(){return l(this,null,function*(){const t=this.walletLocalData.publicKey;this.otherData.numberTransactions||(this.otherData.numberTransactions=0);const e=yield this.multicastServers("getNumberOfOperations",t);if(e!==this.otherData.numberTransactions){let r=[],n=0,s;this.tokenCheckTransactionsStatus.XTZ=.5;do s=yield this.multicastServers("getTransactions",t,n++),r=r.concat(s);while(s.length>0&&n<10);for(const c of r)this.processTezosTransaction(c);this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]),this.otherData.numberTransactions=e,this.walletLocalDataDirty=!0}this.tokenCheckTransactionsStatus.XTZ=1,this.updateOnAddressesChecked()})}checkUnconfirmedTransactionsFetch(){return l(this,null,function*(){})}checkAccountInnerLoop(){return l(this,null,function*(){const t=S,e=this.walletLocalData.publicKey;typeof this.walletLocalData.totalBalances[t]>"u"&&(this.walletLocalData.totalBalances[t]="0");const r=yield this.multicastServers("getBalance",e);this.updateBalance(t,r)})}checkBlockchainInnerLoop(){return l(this,null,function*(){const e=(yield this.multicastServers("getHead")).level;this.walletLocalData.blockHeight!==e&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))})}clearBlockchainCache(){return l(this,null,function*(){yield T(m.prototype,this,"clearBlockchainCache").call(this)})}isBurn(t){return l(this,null,function*(){return t.kind==="origination"||t.kind==="transaction"&&t.destination.slice(0,2)==="tz"&&(yield this.multicastServers("getBalance",t.destination))==="0"})}startEngine(){return l(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",K),this.addToLoop("checkAccountInnerLoop",B),this.addToLoop("checkTransactionsInnerLoop",R),T(m.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return l(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(t){return l(this,null,function*(){return yield x(()=>l(this,null,function*(){return yield this.makeSpendInner(t)}))})}makeSpendInner(t){return l(this,null,function*(){const{edgeSpendInfo:e,currencyCode:r,nativeBalance:n,denom:s}=this.makeSpendCheck(t);if(e.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:c}=e.spendTargets[0];let{nativeAmount:o}=e.spendTargets[0];if(c==null)throw new Error("makeSpend Missing publicAddress");if(o==null)throw new b.$D;if((0,y.eq)(o,"0"))throw new b.$D;const i={pk:this.walletInfo.keys.publicKeyEd,pkh:this.walletInfo.keys.publicKey,sk:!1};let a,z=0,g;do try{a=yield this.multicastServers("createTransaction",i.pkh,i,c,(0,y.div)(o,s.multiplier,6),this.networkInfo.fee.transaction)}catch(v){g=v}while((typeof a>"u"||a.opOb.contents.length>2)&&z++<5);if(typeof a>"u")throw g;let w="0";for(const v of a.opOb.contents)w=(0,y.add)(w,v.fee),(yield this.isBurn(v))&&(w=(0,y.add)(w,this.networkInfo.fee.burn));if(o=(0,y.add)(o,w),(0,y.gt)(o,n))throw new b.C_;return o="-"+o,{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:o,networkFee:w,ourReceiveAddresses:[],signedTx:"",otherParams:{idInternal:0,fromAddress:this.walletLocalData.publicKey,toAddress:c,fullOp:a},walletId:this.walletId}})}signTx(t){return l(this,null,function*(){const e=(0,d.Xp)(t);if(t.signedTx===""){const r=this.walletInfo.keys.privateKey,n=u.eztz.crypto.sign(e.fullOp.opbytes,r,u.eztz.watermark.generic);e.fullOp.opbytes=n.sbytes,e.fullOp.opOb.signature=n.edsig,t.signedTx=n.sbytes}return this.warn(`signTx
2
- ${(0,d.oX)(t)}`),t})}broadcastTx(t){return l(this,null,function*(){const e=(0,d.Xp)(t),r=e.fullOp.opbytes,n=e.fullOp.opOb,s=yield this.multicastServers("injectOperation",n,r);return t.txid=s.hash,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
3
- ${(0,d.oX)(t)}`),t})}getDisplayPrivateSeed(){return this.walletInfo.keys&&this.walletInfo.keys.mnemonic?this.walletInfo.keys.mnemonic:""}getDisplayPublicSeed(){return this.walletInfo.keys&&this.walletInfo.keys.publicKey?this.walletInfo.keys.publicKey:""}}function H(p,t,e,r){return l(this,null,function*(){const n=new m(p,t,e,r);return yield n.loadEngine(t,e,r),n})}var X=f(48764).Buffer,k=(p,t,e)=>new Promise((r,n)=>{var s=i=>{try{o(e.next(i))}catch(a){n(a)}},c=i=>{try{o(e.throw(i))}catch(a){n(a)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((e=e.apply(p,t)).next())});class E{constructor(t){const{builtinTokens:e,currencyInfo:r,io:n,networkInfo:s}=t;this.builtinTokens=e,this.currencyInfo=r,this.io=n,this.networkInfo=s,this.tezosRpcNodes=[...this.networkInfo.tezosRpcNodes],this.tezosApiServers=[...this.networkInfo.tezosApiServers]}checkAddress(t){try{return u.eztz.crypto.checkAddress(t)}catch{return!1}}importPrivateKey(t){return k(this,null,function*(){if(/\d/.test(t))throw new Error("Input must be mnemonic phrase");if(t.split(" ").length!==24)throw new Error("Mnemonic phrase must be 24 words long");const n=u.eztz.crypto.generateKeys(t,"");return this.derivePublicKey({type:"wallet:tezos",id:"fake",keys:n}),{mnemonic:n.mnemonic,privateKey:n.sk}})}createPrivateKey(t){return k(this,null,function*(){if(t.replace("wallet:","")==="tezos"){const r=X.from(this.io.random(32)).toString("hex"),n=u.eztz.library.bip39.entropyToMnemonic(r),s=u.eztz.crypto.generateKeys(n,"").sk;return{mnemonic:n,privateKey:s}}else throw new Error("InvalidWalletType")})}derivePublicKey(t){return k(this,null,function*(){if(t.type.replace("wallet:","")==="tezos"){const r=u.eztz.crypto.generateKeys(t.keys.mnemonic,"");return{publicKey:r.pkh,publicKeyEd:r.pk}}else throw new Error("InvalidWalletType")})}parseUri(t){return k(this,null,function*(){let e,r,n;if(this.checkAddress(t))e=t;else if(t.slice(0,10)==="web+tezos:"){if(r=(0,C.decodeMainnet)(t),!r[0]||!r[0].content)throw new Error("InvalidUriError");if(n=r[0].content,e=n.destination,!this.checkAddress(e))throw new Error("InvalidPublicAddressError")}else throw new Error("InvalidUriError");const s={publicAddress:e};return s.nativeAmount=n!=null&&n.amount!=="0"?n.amount:void 0,s.currencyCode="XTZ",s})}encodeUri(t){return k(this,null,function*(){if(!this.checkAddress(t.publicAddress))throw new Error("InvalidPublicAddressError");if(t.currencyCode!=="XTZ")throw new Error("InvalidCurrencyCodeError");const n={kind:"transaction",amount:typeof t.nativeAmount=="string"?t.nativeAmount:"0",destination:t.publicAddress};return(0,C.encodeMainnet)([{content:n}])})}}function $(p){return k(this,null,function*(){return new E(p)})}},89214:function(){},75992:function(){},52361:function(){},94616:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[92],{12170:function(U,C,f){"use strict";f.r(C),f.d(C,{TezosTools:function(){return L},makeCurrencyEngine:function(){return j},makeCurrencyTools:function(){return F}});var h=f(19971),T=f(39143),y=f(77591),b=f(94935),O=f(50244),d=f(76714),P=f(81649),l=f(82448),D=f(62177);const K=(0,l.su)({numberTransactions:(0,l.Vk)(l.mH,0)}),N=(0,l.su)({level:l.mH,timestamp:l.XC,hash:l.XC,sender:(0,l.su)({address:l.XC}),bakerFee:l.mH,allocationFee:l.mH,target:(0,l.su)({address:l.XC}),amount:l.mH,status:l.XC}),I=(0,D.jd)((0,l.su)({publicKey:l.XC,publicKeyEd:l.XC})),S=(0,l.su)({mnemonic:l.XC,privateKey:l.XC});var B=Object.getPrototypeOf,R=Reflect.get,E=(p,t,e)=>R(B(p),e,t),a=(p,t,e)=>new Promise((r,n)=>{var s=c=>{try{o(e.next(c))}catch(u){n(u)}},i=c=>{try{o(e.throw(c))}catch(u){n(u)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(s,i);o((e=e.apply(p,t)).next())});const X=15e3,x=3e4,H=5e3,$=(0,d.jT)(),A=P.j.currencyCode;class w extends O.P{constructor(t,e,r,n){super(t,e,r,n),this.walletInfo=I(r),this.networkInfo=t.networkInfo;const s=(0,d.zR)(t);this.fetchCors=s}setOtherData(t){this.otherData=K(t)}multicastServers(t,...e){return a(this,null,function*(){let r={result:"",server:"no server"},n;switch(t){case"getHead":{n=this.tools.tezosRpcNodes.map(i=>()=>a(this,null,function*(){const o=yield this.io.fetch(i+"/chains/main/blocks/head/header").then(function(c){return a(this,null,function*(){return yield c.json()})}).then(function(c){return c});return{server:i,result:o}})),r=yield(0,d.QJ)(n);break}case"getBalance":{n=this.tools.tezosRpcNodes.map(i=>()=>a(this,null,function*(){h.eztz.node.setProvider(i);const o=yield h.eztz.rpc.getBalance(e[0]);return{server:i,result:o}})),r=yield(0,d.QJ)(n);break}case"getNumberOfOperations":n=this.tools.tezosApiServers.map(s=>()=>a(this,null,function*(){const i=yield this.fetchCors(`${s}/v1/accounts/${e[0]}`).then(function(o){return a(this,null,function*(){return yield o.json()})}).then(function(o){return o.numTransactions});return{server:s,result:i}})),r=yield(0,d.QJ)(n);break;case"getTransactions":n=this.tools.tezosApiServers.map(s=>()=>a(this,null,function*(){const i=s.includes("tzkt")?"":`&p='${e[1]}&number=50`,o=yield this.fetchCors(`${s}/v1/accounts/${e[0]}/operations?type=transaction`+i).then(function(c){return a(this,null,function*(){return yield c.json()})});return{server:s,result:o}})),r=yield(0,d.QJ)(n);break;case"createTransaction":n=this.tools.tezosRpcNodes.map(s=>()=>a(this,null,function*(){h.eztz.node.setProvider(s);const i=yield h.eztz.rpc.transfer(e[0],e[1],e[2],e[3],e[4],null,this.networkInfo.limit.gas,this.networkInfo.limit.storage,this.networkInfo.fee.reveal).then(function(o){return o});return{server:s,result:i}})),r=yield(0,d.QJ)(n);break;case"injectOperation":{let s="";n=this.tools.tezosRpcNodes.map(i=>()=>a(this,null,function*(){h.eztz.node.setProvider(i);const o=yield h.eztz.rpc.inject(e[0],e[1]).catch(c=>{this.error("Error when injection operation: ",c);const u=this.formatError(c);throw!s&&u!==""&&(s=u),c});return this.multicastServers("silentInjection",i,e[1]),{server:i,result:o}})),r=yield(0,d.QJ)(n).catch(i=>{throw this.error("Error from waterfall: ",i),s!==""?new Error(s):i});break}case"silentInjection":{const s=this.tools.tezosRpcNodes.indexOf(e[0]),i=this.tools.tezosRpcNodes.slice(s+1);r=yield(0,d.Wp)(i.map(o=>a(this,null,function*(){h.eztz.node.setProvider(o);const c=yield h.eztz.rpc.silentInject(e[1]);return this.warn(`Injected silently to: ${o}`),{server:o,result:c}})));break}}return this.log(`XTZ multicastServers ${t} ${r.server} won with result ${r.result}`),r.result})}formatError(t){if(typeof t=="string")return t;try{if(t.error&&t.error==="Operation Failed"&&t.errors&&t.errors[0].id)return"Failed in preapply with an error code ("+t.errors[0].id+")";if(t[0]&&t[0].kind&&t[0].kind==="branch"&&t[0].id)return"Failed in preapply with an error code ("+t[0].id+")"}catch{}return""}processTezosTransaction(t){const e=N(t),r=this.walletLocalData.publicKey,n=[],s=A,i=new Date(e.timestamp).getTime()/1e3,o=e.level;let c=e.amount.toString();const u=(e.bakerFee+e.allocationFee).toString(),z=e.status==="failed";r===e.target.address?(n.push(r),e.sender.address===r&&(c="-"+u)):c="-"+(0,y.add)(c,u);const v={txid:t.hash,date:i,currencyCode:s,blockHeight:o,nativeAmount:c,networkFee:u,ourReceiveAddresses:n,signedTx:"",otherParams:{},walletId:this.walletId};z||this.addTransaction(s,v)}checkTransactionsInnerLoop(){return a(this,null,function*(){const t=this.walletLocalData.publicKey;this.otherData.numberTransactions||(this.otherData.numberTransactions=0);const e=yield this.multicastServers("getNumberOfOperations",t);if(e!==this.otherData.numberTransactions){let r=[],n=0,s;this.tokenCheckTransactionsStatus.XTZ=.5;do s=yield this.multicastServers("getTransactions",t,n++),r=r.concat(s);while(s.length>0&&n<10);for(const i of r)this.processTezosTransaction(i);this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]),this.otherData.numberTransactions=e,this.walletLocalDataDirty=!0}this.tokenCheckTransactionsStatus.XTZ=1,this.updateOnAddressesChecked()})}checkUnconfirmedTransactionsFetch(){return a(this,null,function*(){})}checkAccountInnerLoop(){return a(this,null,function*(){const t=A,e=this.walletLocalData.publicKey;typeof this.walletLocalData.totalBalances[t]>"u"&&(this.walletLocalData.totalBalances[t]="0");const r=yield this.multicastServers("getBalance",e);this.updateBalance(t,r)})}checkBlockchainInnerLoop(){return a(this,null,function*(){const e=(yield this.multicastServers("getHead")).level;this.walletLocalData.blockHeight!==e&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))})}clearBlockchainCache(){return a(this,null,function*(){yield E(w.prototype,this,"clearBlockchainCache").call(this)})}isBurn(t){return a(this,null,function*(){return t.kind==="origination"||t.kind==="transaction"&&t.destination.slice(0,2)==="tz"&&(yield this.multicastServers("getBalance",t.destination))==="0"})}startEngine(){return a(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",x),this.addToLoop("checkAccountInnerLoop",X),this.addToLoop("checkTransactionsInnerLoop",H),E(w.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return a(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(t){return a(this,null,function*(){return yield $(()=>a(this,null,function*(){return yield this.makeSpendInner(t)}))})}makeSpendInner(t){return a(this,null,function*(){const{edgeSpendInfo:e,currencyCode:r,nativeBalance:n,denom:s}=this.makeSpendCheck(t);if(e.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:i}=e.spendTargets[0];let{nativeAmount:o}=e.spendTargets[0];if(i==null)throw new Error("makeSpend Missing publicAddress");if(o==null)throw new b.$D;if((0,y.eq)(o,"0"))throw new b.$D;const c={pk:this.walletInfo.keys.publicKeyEd,pkh:this.walletInfo.keys.publicKey,sk:!1};let u,z=0,v;do try{u=yield this.multicastServers("createTransaction",c.pkh,c,i,(0,y.div)(o,s.multiplier,6),this.networkInfo.fee.transaction)}catch(g){v=g}while((typeof u>"u"||u.opOb.contents.length>2)&&z++<5);if(typeof u>"u")throw v;let m="0";for(const g of u.opOb.contents)m=(0,y.add)(m,g.fee),(yield this.isBurn(g))&&(m=(0,y.add)(m,this.networkInfo.fee.burn));if(o=(0,y.add)(o,m),(0,y.gt)(o,n))throw new b.C_;return o="-"+o,{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:o,networkFee:m,ourReceiveAddresses:[],signedTx:"",otherParams:{idInternal:0,fromAddress:this.walletLocalData.publicKey,toAddress:i,fullOp:u},walletId:this.walletId}})}signTx(t,e){return a(this,null,function*(){const r=S(e),n=(0,d.Xp)(t);if(t.signedTx===""){const s=r.privateKey,i=h.eztz.crypto.sign(n.fullOp.opbytes,s,h.eztz.watermark.generic);n.fullOp.opbytes=i.sbytes,n.fullOp.opOb.signature=i.edsig,t.signedTx=i.sbytes}return this.warn(`signTx
2
+ ${(0,d.oX)(t)}`),t})}broadcastTx(t){return a(this,null,function*(){const e=(0,d.Xp)(t),r=e.fullOp.opbytes,n=e.fullOp.opOb,s=yield this.multicastServers("injectOperation",n,r);return t.txid=s.hash,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
3
+ ${(0,d.oX)(t)}`),t})}getDisplayPrivateSeed(t){return S(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}}function j(p,t,e,r){return a(this,null,function*(){const n=I(e),s=new w(p,t,n,r);return yield s.loadEngine(t,n,r),s})}var M=f(48764).Buffer,k=(p,t,e)=>new Promise((r,n)=>{var s=c=>{try{o(e.next(c))}catch(u){n(u)}},i=c=>{try{o(e.throw(c))}catch(u){n(u)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(s,i);o((e=e.apply(p,t)).next())});class L{constructor(t){const{builtinTokens:e,currencyInfo:r,io:n,networkInfo:s}=t;this.builtinTokens=e,this.currencyInfo=r,this.io=n,this.networkInfo=s,this.tezosRpcNodes=[...this.networkInfo.tezosRpcNodes],this.tezosApiServers=[...this.networkInfo.tezosApiServers]}checkAddress(t){try{return h.eztz.crypto.checkAddress(t)}catch{return!1}}importPrivateKey(t){return k(this,null,function*(){if(/\d/.test(t))throw new Error("Input must be mnemonic phrase");if(t.split(" ").length!==24)throw new Error("Mnemonic phrase must be 24 words long");const n=h.eztz.crypto.generateKeys(t,"");return this.derivePublicKey({type:"wallet:tezos",id:"fake",keys:n}),{mnemonic:n.mnemonic,privateKey:n.sk}})}createPrivateKey(t){return k(this,null,function*(){if(t.replace("wallet:","")==="tezos"){const r=M.from(this.io.random(32)).toString("hex"),n=h.eztz.library.bip39.entropyToMnemonic(r),s=h.eztz.crypto.generateKeys(n,"").sk;return{mnemonic:n,privateKey:s}}else throw new Error("InvalidWalletType")})}derivePublicKey(t){return k(this,null,function*(){if(t.type.replace("wallet:","")==="tezos"){const r=h.eztz.crypto.generateKeys(t.keys.mnemonic,"");return{publicKey:r.pkh,publicKeyEd:r.pk}}else throw new Error("InvalidWalletType")})}parseUri(t){return k(this,null,function*(){let e,r,n;if(this.checkAddress(t))e=t;else if(t.slice(0,10)==="web+tezos:"){if(r=(0,T.decodeMainnet)(t),!r[0]||!r[0].content)throw new Error("InvalidUriError");if(n=r[0].content,e=n.destination,!this.checkAddress(e))throw new Error("InvalidPublicAddressError")}else throw new Error("InvalidUriError");const s={publicAddress:e};return s.nativeAmount=n!=null&&n.amount!=="0"?n.amount:void 0,s.currencyCode="XTZ",s})}encodeUri(t){return k(this,null,function*(){if(!this.checkAddress(t.publicAddress))throw new Error("InvalidPublicAddressError");if(t.currencyCode!=="XTZ")throw new Error("InvalidCurrencyCodeError");const n={kind:"transaction",amount:typeof t.nativeAmount=="string"?t.nativeAmount:"0",destination:t.publicAddress};return(0,T.encodeMainnet)([{content:n}])})}}function F(p){return k(this,null,function*(){return new L(p)})}},89214:function(){},75992:function(){},52361:function(){},94616:function(){}}]);
@@ -1 +1 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[5],{86352:function(ht,Z,h){"use strict";h.d(Z,{Vn:function(){return et},lF:function(){return q},sp:function(){return n}});var O=h(76714),m=(P,D,E)=>new Promise((S,B)=>{var z=g=>{try{p(E.next(g))}catch(v){B(v)}},f=g=>{try{p(E.throw(g))}catch(v){B(v)}},p=g=>g.done?S(g.value):Promise.resolve(g.value).then(z,f);p((E=E.apply(P,D)).next())});const J=["https://info1.edge.app","https://info2.edge.app"];function Q(P,D,E){return m(this,arguments,function*(S,B,z,f=5e3,p=fetch){const g=S.map(v=>()=>m(this,null,function*(){const K=yield p(v+"/"+B,z);if(typeof K!="object"){const w=`Invalid return value ${B} in ${v}`;throw console.log(w),new Error(w)}return K}));return yield(0,O.QJ)(g,f)})}function q(P,D,E,S,B=5e3,z){return m(this,null,function*(){const f=yield Q((0,O.Sy)(D),E,S,B,z);if(!f.ok){const v=yield f.text();throw console.error(v),new Error(`Error fetching ${E}: ${v}`)}const p=yield f.json();return P(p)})}function tt(P,D,E,S=5e3,B){return m(this,null,function*(){return yield Q((0,O.Sy)(P),D,E,S,B)})}const et=(P,D,E,S)=>m(void 0,null,function*(){return yield tt(J,P,D,E,S)}),n=P=>Object.keys(P).map(D=>{const E=P[D];return E==null?D:`${D}=${encodeURIComponent(E)}`}).join("&")},79014:function(ht,Z,h){"use strict";h.d(Z,{Q:function(){return z},k:function(){return B}});var O=h(77591),m=h.n(O),J=h(24350),Q=h(84564),q=h.n(Q),tt=h(76714),et=Object.defineProperty,n=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,E=(f,p,g)=>p in f?et(f,p,{enumerable:!0,configurable:!0,writable:!0,value:g}):f[p]=g,S=(f,p)=>{for(var g in p||(p={}))P.call(p,g)&&E(f,g,p[g]);if(n)for(var g of n(p))D.call(p,g)&&E(f,g,p[g]);return f};function B(f,p,g,v,K){const w=S({},q()(p,{},!0)),nt=p.startsWith(`${f.pluginId}://`);if(w.protocol!=null&&(w.protocol=w.protocol.replace(":","")),w.protocol!=null&&w.protocol!==""&&!g[w.protocol])throw new Error(`Uri protocol '${w.protocol}' is not supported for ${f.pluginId}.`);if(w.host===""&&w.pathname==="")throw new Error("Path and host not found in uri.");const X={publicAddress:w.host!==""?w.host:w.pathname.split("/")[0]},L=w.query.label,rt=w.query.message,ot=w.query.category;(L!=null||rt!=null||ot!=null||nt)&&(X.metadata={},X.metadata.name=L,X.metadata.notes=rt,X.metadata.category=ot,X.metadata.gateway=nt!=null?nt:!1);const j=w.query.amount;if(j!=null&&typeof j=="string"){v==null&&(v=f.currencyCode);const at=(0,tt.cp)(f,v!=null?v:"",K);if(at==null)throw new Error("InternalErrorInvalidCurrencyCode");let M=(0,O.mul)(j,at.multiplier);M=(0,O.toFixed)(M,0,0),X.nativeAmount=M,X.currencyCode=v}return{edgeParsedUri:X,parsedUri:w}}function z(f,p,g){if(f.publicAddress==null)throw new Error("InvalidPublicAddressError");if(g==null&&f.label==null&&f.message==null)return f.publicAddress;{let v="";g!=null&&(v+="amount="+g+"&"),(f.label!=null||f.message!=null)&&(typeof f.label=="string"&&(v+="label="+f.label+"&"),typeof f.message=="string"&&(v+="message="+f.message+"&")),v=v.substr(0,v.length-1);const K={scheme:p,path:f.publicAddress,query:v};return(0,J.qC)(K)}}},9127:function(ht,Z,h){"use strict";h.r(Z),h.d(Z,{TronTools:function(){return kt},makeCurrencyEngine:function(){return le},makeCurrencyTools:function(){return ue}});var O=h(77960),m=h(77591),J=h(2153),Q=h(21964),q=h.n(Q),tt=h(48367),et=h.n(tt),n=h(82448),P=h(86352);const D=s=>{if(s.includes("@"))return E(s)?[!0,s.toLowerCase()]:[!1,"Invalid Email"];if(s.includes("+"))return s="+"+s.replace(/[^\d]+/g,""),s.length!==14?[!1,"Invalid Phone number"]:s.substring(0,3)!=="+55"?[!1,"Not brasilian number"]:[!0,s];if(s.length===36)return[!0,s];if(s.length===18)return/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/.test(s)?B(s)?(s=s.replace(/[^\d]+/g,""),[!0,s]):[!1,"invalid cnpj"]:[!1,"invalid pixkey"];if(s.length===13&&/^\d+$/.test(s))return s.substr(0,2)!=="55"?[!1,"invalid pixkey"]:[!0,"+"+s];if(s.length<11)return[!1,"invalid pixkey"];if(s.length===14){if(/^\d+$/.test(s))return B(s)?[!0,s]:[!1,"invalid pixkey"];if(/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(s))return S(s)?[!0,s.replace(/[^\d]+/g,"")]:[!1,"invalid cpf"]}return s.length===11?/^\d+$/.test(s)?S(s)?[!0,s.replace(/[^\d]+/g,"")]:s.charAt(0)==="0"?[!1,"invalid pixkey"]:[!0,"+55"+s]:[!1,"invalid pixkey"]:(s=s.replace(/[^\d]+/g,""),s.length===12?s.charAt(0)!=="0"?[!1,"invalid pixkey"]:[!0,"+55"+s.substr(1)]:s.length===11?S(s)?[!0,s]:[!0,"+55"+s]:[!1,"invalid pixkey"])};function E(s){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(s).toLowerCase())}function S(s){if(s=s.replace(/[^\d]+/g,""),s===""||s.length!==11||s==="00000000000"||s==="11111111111"||s==="22222222222"||s==="33333333333"||s==="44444444444"||s==="55555555555"||s==="66666666666"||s==="77777777777"||s==="88888888888"||s==="99999999999")return!1;let t,e;t=0;for(let r=1;r<=9;r++)t=t+parseInt(s.substring(r-1,r))*(11-r);if(e=t*10%11,(e===10||e===11)&&(e=0),e!==parseInt(s.substring(9,10)))return!1;t=0;for(let r=1;r<=10;r++)t=t+parseInt(s.substring(r-1,r))*(12-r);return e=t*10%11,(e===10||e===11)&&(e=0),e===parseInt(s.substring(10,11))}function B(s){if(s=s.replace(/[^\d]+/g,""),s===""||s.length!==14||s==="00000000000000"||s==="11111111111111"||s==="22222222222222"||s==="33333333333333"||s==="44444444444444"||s==="55555555555555"||s==="66666666666666"||s==="77777777777777"||s==="88888888888888"||s==="99999999999999")return!1;let t=s.length-2,e=s.substring(0,t);const r=s.substring(t);let a=0,o=t-7;for(let i=t;i>=1;i--)a+=Number(e.charAt(t-i))*o--,o<2&&(o=9);let c=a%11<2?0:11-a%11;if(c!==Number(r.charAt(0)))return!1;t=t+1,e=s.substring(0,t),a=0,o=t-7;for(let i=t;i>=1;i--)a+=Number(e.charAt(t-i))*o--,o<2&&(o=9);return c=a%11<2?0:11-a%11,c===Number(r.charAt(1))}function z(s,t=!1){const e=p(s),r=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];let a=65535;for(let i=0;i<e.length;i++){const u=(e[i]^a>>8)&255;a=r[u]^a<<8}const o=(a^0)&65535,c=f(o,4);return t?c.slice(2)+c.slice(0,2):c}function f(s,t){const e=s.toString(16).toUpperCase();return t>0?("0".repeat(t)+e).slice(-t):e.length%2===0?e:"0"+e}function p(s){let t=0;const e=s.length;let r=0,a=Math.max(32,e+(e>>>1)+7),o=new Uint8Array(a>>>3<<3);for(;t<e;){let c=s.charCodeAt(t++);if(c>=55296&&c<=56319){if(t<e){const i=s.charCodeAt(t);(i&64512)===56320&&(++t,c=((c&1023)<<10)+(i&1023)+65536)}if(c>=55296&&c<=56319)continue}if(r+4>o.length){a+=8,a*=1+t/s.length*2,a=a>>>3<<3;const i=new Uint8Array(a);i.set(o),o=i}if((c&4294967168)===0){o[r++]=c;continue}else if((c&4294965248)===0)o[r++]=c>>>6&31|192;else if((c&4294901760)===0)o[r++]=c>>>12&15|224,o[r++]=c>>>6&63|128;else if((c&4292870144)===0)o[r++]=c>>>18&7|240,o[r++]=c>>>12&63|128,o[r++]=c>>>6&63|128;else continue;o[r++]=c&63|128}return o.slice!=null?o.slice(0,r):o.subarray(0,r)}var g=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const v=60*60*24*7,K=(0,n._C)((0,n.su)({status:(0,n.Wf)("ok"),msg:n.XC,data:(0,n.su)({amount:n.mH,name:n.XC,key:n.XC,timeout:n.mH})}),(0,n.su)({status:(0,n.Wf)("failed"),msg:n.XC})),w=(0,n.su)({status:(0,n.Wf)("ok"),msg:n.XC,data:(0,n.su)({amount_usd:n.XC,price_brl:n.XC,total_brl:n.XC,fee_brl:n.XC,send_brl:n.XC,timeout:n.mH,amount_txusdt:n.XC,price_txusdt:n.mH,value_usd:n.XC,total_txusdt:n.XC})}),nt=(s,t,e,r,a)=>g(void 0,null,function*(){const o=new Date;if(e.length>36){const c=z(e.slice(0,-4));if(!e.endsWith(c))return;try{const i=encodeURIComponent(e),l=yield(0,P.lF)(K,["https://connect.smartpay.com.vc"],`api/pix/qrdecode?qrcode=${i}`,void 0,void 0,s.fetch);if(l.status!=="ok")throw new Error(l.msg);const{data:u}=l,{amount:d,key:k,name:x,timeout:T}=u;if(T>0&&T<120)throw new Error("ErrorPixExpired");let C,b;if(d!==0){const A={type:"buy",profile:"transfer",currency:"brl",conv:"txusdt",target:"amount",user:a,amount:d===0?100:d},_=(0,P.sp)(A),R=yield(0,P.lF)(w,["https://connect.smartpay.com.vc"],`api/swapix/swapquote?${_}`,void 0,void 0,s.fetch),{data:H}=R,{amount_txusdt:W,timeout:U}=H;if(U>0&&U<120)throw new Error("ErrorPixExpired");const N=Object.keys(t).find(lt=>t[lt].currencyCode==="USDT");if(N==null)return;const Y=t[N];C=(0,m.mul)(W,Y.denominations[0].multiplier);const st=Math.min(T>0?T:v,U>0?U:v);b=new Date(o.getTime()+st*1e3)}return{currencyCode:"USDT",metadata:{name:x,notes:`To PIX: ${k}`},expireDate:b,nativeAmount:C,publicAddress:r,uniqueIdentifier:e}}catch(i){console.log(`Could not query PIX address ${e}: ${i.message}`)}}else{const[c,i]=D(e);return c?{currencyCode:"USDT",metadata:{name:`PIX: ${i}`,notes:`To PIX: ${i}`},publicAddress:"TUmgPbM5J6om7Z2PJjzrbSEbXit84ZhVCj",uniqueIdentifier:i}:void 0}});var ut=h(20918),X=h(79014),L=h(76714);const rt=(0,n.su)({tronMnemonic:(0,n.Zz)(n.XC),tronKey:n.XC,derivationPath:(0,n.Zz)(n.XC)}),ot=(0,n.su)({smartPayPublicAddress:(0,n.Zz)(n.XC,"TUmgPbM5J6om7Z2PJjzrbSEbXit84ZhVCj"),smartPayUserId:(0,n.Zz)(n.XC,"edge")}),j=(0,n.su)({txid:n.XC,timestamp:n.mH}),at=(0,n.su)({txQueryCache:(0,n.Vk)((0,n.su)({mainnet:j,trc20:j}),{mainnet:{txid:"",timestamp:0},trc20:{txid:"",timestamp:0}})}),M=(0,n.Wf)("BANDWIDTH","ENERGY"),xt=(0,n.su)({type:(0,n.Wf)("add"),params:(0,n.su)({nativeAmount:n.XC,resource:M})}),It=(0,n.su)({type:(0,n.Wf)("remove"),params:(0,n.su)({resource:M})}),Pt=(0,n.su)({chainParameter:(0,n._2)((0,n.su)({key:n.XC,value:(0,n.Zz)(n.mH)}))}),_t=(0,n.su)({blockID:n.XC,block_header:(0,n.su)({raw_data:(0,n.su)({number:n.mH,timestamp:n.mH})})}),ft=(0,n.su)({freeNetUsed:(0,n.Vk)(n.mH,0),freeNetLimit:n.mH,EnergyUsed:(0,n.Vk)(n.mH,0),EnergyLimit:(0,n.Vk)(n.mH,0)}),Dt=(0,n.su)({frozen:(0,n.Zz)((0,n.vq)((0,n.su)({frozen_balance:n.mH,expire_time:n.mH}))),account_resource:(0,n.su)({frozen_balance_for_energy:(0,n.Zz)((0,n.su)({frozen_balance:n.mH,expire_time:n.mH}))}),balance:(0,n.Vk)(n.mH,0)}),St=(0,n.su)({constant_result:(0,n.vq)(n.XC)}),Ot=(0,n.su)({ret:(0,n._2)((0,n.su)({contractRet:n.XC,fee:n.mH})),txID:n.XC,unfreeze_amount:(0,n.Zz)(n.mH),blockNumber:n.mH,block_timestamp:n.mH,raw_data:(0,n.su)({contract:(0,n._2)(n.JC)})}),Bt=(0,n.su)({transaction_id:n.XC,token_info:(0,n.su)({address:n.XC}),block_timestamp:n.mH,from:n.XC,to:n.XC,type:n.XC,value:n.XC}),Rt=(0,n.su)({fee:n.mH,blockNumber:n.mH}),Lt=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({amount:n.mH,owner_address:n.XC,to_address:n.XC})}),type:(0,n.Wf)("TransferContract")}),Ft=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({data:n.XC,owner_address:n.XC,contract_address:n.XC})}),type:(0,n.Wf)("TriggerSmartContract")}),Ht=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({frozen_balance:n.mH,resource_type:M,owner_address:n.XC})}),type:(0,n.Wf)("FreezeBalanceContract")}),Nt=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({resource_type:M,owner_address:n.XC})}),type:(0,n.Wf)("UnfreezeBalanceContract")}),Xt=s=>(0,n.su)({data:(0,n._2)(s),success:n.jK,meta:(0,n.su)({links:(0,n.Zz)((0,n.su)({next:n.XC})),page_size:n.mH})}),Ut=(0,n.su)({energy_used:n.mH,transaction:(0,n.su)({ret:(0,n._2)((0,n.su)({ret:(0,n.Zz)(n.XC)}))})}),zt=(0,n.su)({result:n.jK,txid:n.XC,message:n.XC});var mt=h(85632),Kt=h(13185),yt=h(94935),Mt=h(50244),$t=h(56475),Wt=h(85021),Vt=h(68142),Jt=h.n(Vt),gt=h(48764).Buffer,Zt=Object.getPrototypeOf,Qt=Reflect.get,pt=(s,t,e)=>Qt(Zt(s),e,t),vt=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const F=s=>{const t=(0,O.decode58Check)(s);return(0,mt.byteArray2hexStr)(t)},G=s=>{const t=(0,Wt.hexStr2byteArray)(s);return(0,O.getBase58CheckAddress)(t)},wt="a9059cbb",de=s=>{if(!s.startsWith(wt))throw new Error("Not a TRC20 data payload");const t=s.replace(wt,""),e=`41${t.substring(24,64)}`,r=G(e),a=t.substring(64,128),o=hexToDecimal(a);return[r,o]},jt=(s,t)=>{const e=F(s).replace(/^(41)/,"0x"),r=Jt().simpleEncode("transfer(address,uint256):(uint256)",e,parseInt(t));return gt.from(r).toString("hex")};class ct extends $t.Client{constructor(t){super(""),this.recentBlock=t}getLatestBlock(){return this.recentBlock}addData(t,e){return vt(this,null,function*(){const r=yield pt(ct.prototype,this,"addRef").call(this,t),a=r.getRawData();return a.setData(Uint8Array.from(gt.from(e,"ascii"))),r.setRawData(a),r})}addRef(t,e){return vt(this,null,function*(){const r=yield pt(ct.prototype,this,"addRef").call(this,t);if(e!=null){const a=r.getRawData();a.setFeeLimit(e),r.setRawData(a)}return r})}}var Gt=Object.defineProperty,Yt=Object.defineProperties,qt=Object.getOwnPropertyDescriptors,Tt=Object.getOwnPropertySymbols,te=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,re=Reflect.get,Ct=(s,t,e)=>t in s?Gt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,dt=(s,t)=>{for(var e in t||(t={}))ee.call(t,e)&&Ct(s,e,t[e]);if(Tt)for(var e of Tt(t))ne.call(t,e)&&Ct(s,e,t[e]);return s},se=(s,t)=>Yt(s,qt(t)),bt=(s,t,e)=>re(te(s),e,t),y=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const oe=(0,L.jT)(),At=2e4,ae=2e4,ce=3e3,ie=60*10*1e3;class it extends Mt.P{constructor(t,e,r,a){super(t,e,r,a);const o=(0,L.zR)(t),{networkInfo:c}=t;this.fetchCors=o,this.log=a.log,this.networkInfo=c,this.recentBlock={hash:"0",number:0,timestamp:0},this.accountResources={BANDWIDTH:0,ENERGY:0},this.networkFees={getCreateAccountFee:1e5,getTransactionFee:1e3,getEnergyFee:280,getMemoFee:1e6},this.tronscan=new ct(this.recentBlock),this.accountExistsCache={},this.energyEstimateCache={},this.processTRXTransaction=this.processTRXTransaction.bind(this),this.processTRC20Transaction=this.processTRC20Transaction.bind(this),this.stakingStatus={stakedAmounts:[{nativeAmount:"0",otherParams:{type:"BANDWIDTH"}},{nativeAmount:"0",otherParams:{type:"ENERGY"}}]}}setOtherData(t){this.otherData=at(t)}fetch(t,e){return y(this,arguments,function*(r,a,o={}){const c=r+a,i=yield this.fetchCors(c,o);if(!i.ok||i.status!==200)throw this.log(`The server returned error code ${i.status} for ${c}`),new Error(`The server returned error code ${i.status} for ${c}`);const l=yield i.json();if(typeof l!="object"){const u=`Invalid return value ${a} in ${r}`;throw this.log(u),new Error(u)}return{server:r,result:l}})}checkBlockchainInnerLoop(){return y(this,null,function*(){try{const t=yield this.multicastServers("trx_blockNumber","/wallet/getnowblock"),e=_t(t),r=e.block_header.raw_data.number;Object.assign(this.recentBlock,{hash:e.blockID,number:r,timestamp:e.block_header.raw_data.timestamp}),this.walletLocalData.blockHeight!==r&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(t){this.log.error("Error fetching height: ",t)}})}updateBalance(t,e){const r=this.walletLocalData.totalBalances[t];typeof this.walletLocalData.totalBalances[t]>"u"&&(this.walletLocalData.totalBalances[t]="0"),(r==null||!(0,m.eq)(e,r))&&(this.walletLocalData.totalBalances[t]=e,this.log(t+": token Address balance: "+e),this.currencyEngineCallbacks.onBalanceChanged(t,e)),this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}checkTokenBalances(){return y(this,null,function*(){const t=F(this.walletLocalData.publicKey);for(const e of this.enabledTokens){const r=this.allTokens.find(c=>c.currencyCode===e);if((r==null?void 0:r.contractAddress)==null)continue;const o={contract_address:F(r.contractAddress),function_selector:"balanceOf(address)",parameter:(0,L.gc)(t,32),owner_address:t};try{const c=yield this.multicastServers("trx_getBalance","/wallet/triggerconstantcontract",o),i=St(c);r!=null&&this.updateBalance(r.currencyCode,(0,L.Z8)(i.constant_result[0]))}catch(c){this.log.error(`Failed to get balance of ${e}`,c)}}})}checkAccountInnerLoop(){return y(this,null,function*(){const t={address:F(this.walletLocalData.publicKey)};try{const e=yield this.multicastServers("trx_getBalance","/wallet/getaccount",t),r=(0,n.Vk)(Dt)(e);if(r==null){this.updateBalance(this.currencyInfo.currencyCode,"0");return}this.updateBalance(this.currencyInfo.currencyCode,r.balance.toString());const{frozen:a,account_resource:{frozen_balance_for_energy:o}}=r,c=[];if(a!=null){const i=a[0].frozen_balance.toString(),l=new Date(a[0].expire_time);c.push({nativeAmount:i,unlockDate:l,otherParams:{type:"BANDWIDTH"}})}if(o!=null){const i=o.frozen_balance.toString(),l=new Date(o.expire_time);c.push({nativeAmount:i,unlockDate:l,otherParams:{type:"ENERGY"}})}this.stakingStatus={stakedAmounts:c},this.currencyEngineCallbacks.onStakingStatusChanged(dt({},this.stakingStatus))}catch(e){this.log.error("Error checking TRX address balance: ",e)}try{const e=yield this.multicastServers("trx_getAccountResource","/wallet/getaccountresource",t),r=ft(e);this.accountResources={BANDWIDTH:r.freeNetLimit-r.freeNetUsed,ENERGY:r.EnergyLimit-r.EnergyUsed}}catch(e){this.log.error("Error checking TRX address resources: ",e)}})}queryTransactions(){return y(this,null,function*(){return yield oe(()=>y(this,null,function*(){return yield this.queryTransactionsInnerLoop()}))})}queryTransactionsInnerLoop(){return y(this,null,function*(){try{yield this.fetchTrxTransactions(),yield this.fetchTrc20Transactions()}catch(t){throw this.log.error("Error checkTransactionsFetch fetchTrxTransactions: ",t),t}this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]);for(const t of this.enabledTokens)this.tokenCheckTransactionsStatus[t]=1;this.updateOnAddressesChecked()})}fetchTrxTransactions(){return y(this,null,function*(){let t=!1;for(;!t;)t=yield this.fetchTransactions("mainnet",Ot,this.processTRXTransaction)})}fetchTrc20Transactions(){return y(this,null,function*(){let t=!1;for(;!t;)t=yield this.fetchTransactions("trc20",Bt,this.processTRC20Transaction)})}fetchTransactions(t,e,r){return y(this,null,function*(){var a;const o=t==="trc20"?t:"",c=this.otherData.txQueryCache[t].timestamp,i=`/v1/accounts/${this.walletLocalData.publicKey}/transactions/${o}?limit=200&order_by=block_timestamp,asc&min_timestamp=${c}`,l=yield this.multicastServers("trx_getTransactions",i),{data:u,meta:d,success:k}=Xt(e)(l),x=((a=d==null?void 0:d.links)==null?void 0:a.next)==null;if(!k)throw new Error("Failed to query TRX transactions");for(const T of u){const{timestamp:C,txid:b}=yield r(T);this.otherData.txQueryCache[t].txid=b,this.otherData.txQueryCache[t].timestamp=C,this.walletLocalDataDirty=!0}return x})}processTRXTransaction(t){const{txID:e,block_timestamp:r,blockNumber:a,ret:o,unfreeze_amount:c,raw_data:{contract:i}}=t,l={txid:e,timestamp:r};if(e===this.otherData.txQueryCache.mainnet.txid||o.length<1)return l;const u=[];for(const d of i){const k=(0,n.Vk)(Lt)(d);if(k!=null){const{parameter:{value:{amount:b,owner_address:I,to_address:A}}}=k,{contractRet:_,fee:R}=o[0];let H=R.toString();const W=G(I),U=G(A);let N=b.toString();if(W===this.walletLocalData.publicKey)W===U?N=(0,m.mul)(H,"-1"):N=(0,m.mul)((0,m.add)(N,H),"-1"),_!=="SUCCESS"&&(N="0");else{if(_!=="SUCCESS")return l;u.push(this.walletLocalData.publicKey),H="0"}const{currencyCode:Y}=this.currencyInfo,st={txid:e,date:Math.floor(r/1e3),currencyCode:Y,blockHeight:a,nativeAmount:N,networkFee:H,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(Y,st),l}const x=(0,n.Vk)(Ft)(d);if(x!=null){const{parameter:{value:{owner_address:b}}}=x;if(G(b)!==this.walletLocalData.publicKey)break;const I=o[0].fee.toString(),{currencyCode:A}=this.currencyInfo,_={txid:e,date:Math.floor(r/1e3),currencyCode:A,blockHeight:a,nativeAmount:(0,m.mul)(I,"-1"),networkFee:I,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(A,_),l}const T=(0,n.Vk)(Ht)(d);if(T!=null){const{parameter:{value:{owner_address:b,frozen_balance:I}}}=T;if(G(b)!==this.walletLocalData.publicKey)break;const A=o[0].fee.toString(),_=(0,m.add)(I.toString(),A),{currencyCode:R}=this.currencyInfo,H={txid:e,date:Math.floor(r/1e3),currencyCode:R,blockHeight:a,nativeAmount:(0,m.mul)(_,"-1"),networkFee:A,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(R,H),l}const C=(0,n.Vk)(Nt)(d);if(C!=null){if(c==null)return l;const{parameter:{value:{owner_address:b}}}=C;if(G(b)!==this.walletLocalData.publicKey)break;const I=o[0].fee.toString(),{currencyCode:A}=this.currencyInfo,_={txid:e,date:Math.floor(r/1e3),currencyCode:A,blockHeight:a,nativeAmount:(0,m.sub)(c.toString(),I),networkFee:I,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(A,_),l}}return l}processTRC20Transaction(t){return y(this,null,function*(){const{transaction_id:e,token_info:{address:r},block_timestamp:a,from:o,to:c,type:i,value:l}=t,u={txid:e,timestamp:a};if(e===this.otherData.txQueryCache.trc20.txid)return u;const d=yield this.multicastServers("trx_getTransactionInfo","/wallet/gettransactioninfobyid",{value:e}),{blockNumber:k,fee:x}=Rt(d),T=this.allTokens.find(_=>_.contractAddress===r);if(i!=="Transfer"||T==null)return u;const C=[];let b=l;const I=x;if(o===this.walletLocalData.publicKey)b=(0,m.mul)(l,"-1");else if(c===this.walletLocalData.publicKey)C.push(this.walletLocalData.publicKey);else return u;const A={txid:e,date:Math.floor(a/1e3),currencyCode:T.currencyCode,blockHeight:k,nativeAmount:b,networkFee:"0",ourReceiveAddresses:C,signedTx:"",walletId:this.walletId};return(0,m.lt)(b,"0")&&(A.parentNetworkFee=I.toString()),this.addTransaction(T.currencyCode,A),u})}checkUpdateNetworkFees(){return y(this,null,function*(){try{const t=yield this.multicastServers("trx_chainParams","/wallet/getchainparameters"),e=Pt(t).chainParameter;for(const r of Object.keys(this.networkFees)){const a=e.find(o=>o.key===r);a!=null&&(this.networkFees=se(dt({},this.networkFees),{[r]:a.value}))}}catch(t){this.log.error("checkUpdateNetworkFees error: ",t)}})}multicastServers(t,e){return y(this,arguments,function*(r,a,o={}){let c={result:"",server:"no server"},i=[];switch(r){case"trx_chainParams":i=this.networkInfo.tronNodeServers.map(l=>()=>y(this,null,function*(){return yield this.fetch(l,a)}));break;case"trx_blockNumber":case"trx_broadcastTx":case"trx_estimateEnergy":case"trx_getAccountResource":case"trx_getBalance":case"trx_getTransactionInfo":i=this.networkInfo.tronNodeServers.map(l=>()=>y(this,null,function*(){const u={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(o)};return yield this.fetch(l,a,u)}));break;case"trx_getTransactions":i=this.networkInfo.tronApiServers.map(l=>()=>y(this,null,function*(){const u={headers:{Accept:"application/json","Content-Type":"application/json"}};return yield this.fetch(l,a,u)}));break}return i=(0,L.Sy)(i),c=yield(0,L.QJ)(i),this.log(`TRX multicastServers ${r} ${c.server} won`),c.result})}calcTxFee(t){return y(this,null,function*(){var e,r;const{note:a,receiverAddress:o,tokenOpts:c,unsignedTxHex:i}=t,l=(0,L.cp)(this.currencyInfo,this.currencyInfo.currencyCode);if(l==null)throw new Error("calcTxFee unknown denom");let u=0;if(c!=null&&o!=null){const{contractAddress:C,data:b}=c;if(this.energyEstimateCache[`${o}:${C}`]==null){const I={owner_address:F(this.walletLocalData.publicKey),contract_address:F(C),function_selector:"transfer(address,uint256)",parameter:b.slice(8)};try{const A=yield this.multicastServers("trx_estimateEnergy","/wallet/triggerconstantcontract",I),_=Ut(A),R=(e=_.transaction.ret[0])==null?void 0:e.ret;if(R!=null&&R!=="SUCCESS")throw new Error("calcTxFee Failed to estimate fee");this.energyEstimateCache[`${o}:${C}`]=_.energy_used}catch(A){this.log.warn("trx_estimateEnergy error. Using a high default.",A)}}u=Math.max(((r=this.energyEstimateCache[`${o}:${C}`])!=null?r:1e5)-this.accountResources.ENERGY,0)}this.log("Account energy: ",this.accountResources.ENERGY),this.log("Energy needed: ",u);let d=i.length/2+65+64+5;if(i.length/2<128&&d--,o!=null&&this.accountExistsCache[o]===void 0)try{const C=yield this.multicastServers("trx_getAccountResource","/wallet/getaccountresource",{address:F(o)});this.accountExistsCache[o]=(0,n.Vk)(ft)(C)!=null}catch(C){this.log.error("calcTxFee error: Failed to call trx_getAccountResource. Allowing the user to proceed assuming high fee.",C)}c==null&&o!=null&&!this.accountExistsCache[o]&&(d=100),d<this.accountResources.BANDWIDTH&&(d=0),this.log("Account bandwidth: ",this.accountResources.BANDWIDTH),this.log("Bandwidth needed: ",d);let k=0;c==null&&o!=null&&!this.accountExistsCache[o]&&(k=this.networkFees.getCreateAccountFee+parseInt(l.multiplier)),this.log("Create account fee: ",k);const x=a!=null?this.networkFees.getMemoFee:0;this.log("Transaction note fee: ",x);const T=u*this.networkFees.getEnergyFee+d*this.networkFees.getTransactionFee+k+x;return this.log("Total fee in SUN: ",T),T.toString()})}txBuilder(t){return y(this,null,function*(){const{contractJson:e,feeLimit:r,note:a}=t,o=(0,Kt.contractJsonToProtobuf)(e);yield this.tronscan.addRef(o,r),a!=null&&(yield this.tronscan.addData(o,a));const c=(0,mt.byteArray2hexStr)(o.getRawData().serializeBinary());return{transaction:o,transactionHex:c}})}makeTransferJson(t){return y(this,null,function*(){const{currencyCode:e,toAddress:r,nativeAmount:a,data:o,note:c}=t;let i,l;if(e===this.currencyInfo.currencyCode)l={parameter:{value:{to_address:F(r),owner_address:F(this.walletLocalData.publicKey),amount:parseInt(a)}},type:"TransferContract"};else{const u=this.allTokens.find(d=>d.currencyCode===e);if((u==null?void 0:u.contractAddress)==null)throw new Error(`txBuilder unknown currency code ${e}`);l={parameter:{value:{owner_address:F(this.walletLocalData.publicKey),contract_address:F(u.contractAddress),data:o,call_value:0}},type:"TriggerSmartContract"},i=this.networkInfo.defaultFeeLimit}return{contractJson:l,feeLimit:i,note:c}})}makeFreezeTransaction(t){return y(this,null,function*(){const{params:{nativeAmount:e,resource:r}}=t,o={contractJson:{parameter:{value:{owner_address:F(this.walletLocalData.publicKey),frozen_balance:parseInt(e),frozen_duration:this.networkInfo.defaultFreezeDurationInDays,resource:r}},type:"FreezeBalanceContract"}},{transactionHex:c}=yield this.txBuilder(o),i=yield this.calcTxFee({unsignedTxHex:c});return{txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:(0,m.mul)(e,"-1"),networkFee:i,ourReceiveAddresses:[],signedTx:"",otherParams:o,walletId:this.walletId,metadata:{notes:r}}})}makeUnfreezeTransaction(t){return y(this,null,function*(){const{params:{resource:e}}=t,r=this.stakingStatus.stakedAmounts.find(u=>{var d;return((d=u.otherParams)==null?void 0:d.type)===e});if(r==null)throw new Error("Nothing to unfreeze");const o={contractJson:{parameter:{value:{owner_address:F(this.walletLocalData.publicKey),resource:e}},type:"UnfreezeBalanceContract"}},{transactionHex:c}=yield this.txBuilder(o),i=yield this.calcTxFee({unsignedTxHex:c});return{txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:r.nativeAmount,networkFee:i,ourReceiveAddresses:[],signedTx:"",otherParams:o,walletId:this.walletId,metadata:{notes:e}}})}startEngine(){return y(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",ae).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",At).catch(()=>{}),this.addToLoop("checkTokenBalances",At).catch(()=>{}),this.addToLoop("checkUpdateNetworkFees",ie).catch(()=>{}),this.addToLoop("queryTransactions",ce).catch(()=>{}),yield bt(it.prototype,this,"startEngine").call(this)})}getStakingStatus(){return y(this,null,function*(){return dt({},this.stakingStatus)})}resyncBlockchain(){return y(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return y(this,null,function*(){const e=this.getBalance({currencyCode:t.currencyCode});if(t.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:r,memo:a}=t.spendTargets[0],o=a===""?void 0:a;if(r==null||t.currencyCode==null)throw new Error("Error: need recipient address and/or currencyCode");if(t.currencyCode===this.currencyInfo.currencyCode){const c=(i,l)=>y(this,null,function*(){const u=(0,m.sub)(l,i);if((0,m.lte)(u,"1"))return i;const d=(0,m.add)(i,(0,m.div)(u,"2")),k={toAddress:r,currencyCode:this.currencyInfo.currencyCode,nativeAmount:d},{contractJson:x,feeLimit:T}=yield this.makeTransferJson(k),{transactionHex:C}=yield this.txBuilder({contractJson:x,feeLimit:T,note:o});t.spendTargets[0].nativeAmount=d;const b=yield this.calcTxFee({receiverAddress:r,unsignedTxHex:C,note:o}),I=(0,m.add)(d,b);return(0,m.gt)(I,e)?yield c(i,d):yield c(d,l)});return yield c("0",(0,m.add)(e,"1"))}else return t.spendTargets[0].nativeAmount=e,yield this.makeSpend(t),e})}makeSpend(t){return y(this,null,function*(){var e,r;if(t.otherParams!=null){let V;if(V=(0,n.Vk)(xt)(t.otherParams),V!=null)return yield this.makeFreezeTransaction(V);if(V=(0,n.Vk)(It)(t.otherParams),V!=null)return yield this.makeUnfreezeTransaction(V)}const{edgeSpendInfo:a,currencyCode:o}=bt(it.prototype,this,"makeSpendCheck").call(this,t),c=o!==this.currencyInfo.currencyCode;if(a.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:i,publicAddress:l,otherParams:u,memo:d}=a.spendTargets[0];if(l==null)throw new Error("makeSpend Missing publicAddress");if(i==null)throw new yt.$D;const k=(e=u==null?void 0:u.data)!=null?e:o!==this.currencyInfo.currencyCode?jt(l,i):void 0,x=c?this.allTokens.find(V=>V.currencyCode===o):void 0,T=d===""?void 0:d,C={currencyCode:o,toAddress:l,nativeAmount:i,contractAddress:x==null?void 0:x.contractAddress,data:k,note:T},{contractJson:b,feeLimit:I}=yield this.makeTransferJson(C),{transactionHex:A}=yield this.txBuilder({contractJson:b,feeLimit:I,note:T}),_=(x==null?void 0:x.contractAddress)!=null&&k!=null?{contractAddress:x==null?void 0:x.contractAddress,data:k}:void 0,R=yield this.calcTxFee({receiverAddress:l,unsignedTxHex:A,tokenOpts:_,note:T});let H,W,U,N;c?(H=i,W="0",U=R,N=U):(H=(0,m.add)(i,R),W=R,N=H);const Y=(r=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?r:"0";if((0,m.gt)(N,Y))throw new yt.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:R});const st={contractJson:b,feeLimit:I,note:T},lt={txid:"",date:0,currencyCode:o,blockHeight:0,nativeAmount:(0,m.mul)(H,"-1"),networkFee:W,ourReceiveAddresses:[],signedTx:"",otherParams:st,walletId:this.walletId};return U!=null&&(lt.parentNetworkFee=U),lt})}signTx(t){return y(this,null,function*(){const e=(0,L.Xp)(t),r=yield this.txBuilder(e),{tronKey:a}=rt(this.walletInfo.keys),o=this.tronscan.getSigner(a),{hex:c}=yield o.signTransaction(r.transaction);return t.signedTx=c,t})}broadcastTx(t){return y(this,null,function*(){const e={transaction:t.signedTx},r=yield this.multicastServers("trx_broadcastTx","/wallet/broadcasthex",e),a=zt(r);if(!a.result)throw new Error(a.message);const{toAddress:o,contractAddress:c}=(0,L.Xp)(t);return t.currencyCode===this.currencyInfo.currencyCode&&o!=null&&(this.accountExistsCache[o]=!0),c!=null&&delete this.energyEstimateCache[`${o}:${c}`],t.txid=a.txid,t.date=Date.now()/1e3,t})}getDisplayPrivateSeed(){var t,e,r;return(r=(t=this.walletInfo.keys)==null?void 0:t.tronMnemonic)!=null?r:(e=this.walletInfo.keys)==null?void 0:e.tronKey}getDisplayPublicSeed(){var t,e;return(e=(t=this.walletInfo.keys)==null?void 0:t.publicKey)!=null?e:""}}function le(s,t,e,r){return y(this,null,function*(){const a=new it(s,t,e,r);return yield a.loadEngine(t,e,r),a})}var Et=h(48764).Buffer,$=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});class kt{constructor(t){const{builtinTokens:e,currencyInfo:r,initOptions:a,io:o,log:c,networkInfo:i}=t;this.builtinTokens=e,this.currencyInfo=r,this.initOptions=ot(a),this.io=o,this.log=c,this.networkInfo=i}importPrivateKey(t,e){return $(this,null,function*(){var r;if(/^(0x)?[0-9a-fA-F]{64}$/.test(t)){const a=Et.from(t.replace(/^0x/,""),"hex");if(q().isValidPrivate(a)===!0)throw new Error("Invalid private key");return{tronKey:a.toString("hex")}}else{if(!(0,J.validateMnemonic)(t))throw new Error("Invalid input");const a=(r=e==null?void 0:e.derivationPath)!=null?r:this.networkInfo.defaultDerivationPath,o=yield this._mnemonicToTronKey(t,a);return{tronMnemonic:t,tronKey:o,derivationPath:a}}})}createPrivateKey(t){return $(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=Et.from(this.io.random(32)).toString("hex"),r=(0,J.entropyToMnemonic)(e);return yield this.importPrivateKey(r)})}_mnemonicToTronKey(t,e){return $(this,null,function*(){const r=yield(0,J.mnemonicToSeed)(t);return et().fromMasterSeed(r).derivePath(e).getWallet().getPrivateKeyString().replace("0x","")})}derivePublicKey(t){return $(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{tronKey:e}=rt(t.keys);return{publicKey:(0,O.pkToAddress)(e)}})}parseUri(t,e,r){return $(this,null,function*(){var a;const o={[this.currencyInfo.pluginId]:!0},{smartPayPublicAddress:c,smartPayUserId:i}=this.initOptions,l=yield nt(this.io,this.builtinTokens,t,c,i);if(l!=null)return l;const{parsedUri:u,edgeParsedUri:d}=(0,X.k)(this.currencyInfo,t,o,e!=null?e:this.currencyInfo.currencyCode,r),k=(a=d.publicAddress)!=null?a:"";if(!(0,O.isAddressValid)(k))throw new Error("InvalidPublicAddressError");return d.uniqueIdentifier=u.query.memo,d})}encodeUri(t,e){return $(this,null,function*(){const{publicAddress:r,nativeAmount:a,currencyCode:o}=t;if(!(0,O.isAddressValid)(r))throw new Error("InvalidPublicAddressError");let c;if(typeof a=="string"){const l=(0,L.cp)(this.currencyInfo,o!=null?o:this.currencyInfo.currencyCode,e);if(l==null)throw new Error("InternalErrorInvalidCurrencyCode");c=(0,m.div)(a,l.multiplier,18)}return(0,X.Q)(t,this.currencyInfo.pluginId,c)})}getTokenId(t){return $(this,null,function*(){(0,ut.Rp)(t);const e=(0,ut.Oj)(t.networkLocation);if(e==null||!(0,O.isAddressValid)(e.contractAddress))throw new Error("ErrorInvalidContractAddress");return e.contractAddress})}}function ue(s){return $(this,null,function*(){return new kt(s)})}},89214:function(){},52361:function(){},94616:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[5],{86352:function(ft,Z,h){"use strict";h.d(Z,{Vn:function(){return et},lF:function(){return q},sp:function(){return n}});var O=h(76714),m=(P,S,E)=>new Promise((_,B)=>{var z=g=>{try{p(E.next(g))}catch(v){B(v)}},f=g=>{try{p(E.throw(g))}catch(v){B(v)}},p=g=>g.done?_(g.value):Promise.resolve(g.value).then(z,f);p((E=E.apply(P,S)).next())});const J=["https://info1.edge.app","https://info2.edge.app"];function Q(P,S,E){return m(this,arguments,function*(_,B,z,f=5e3,p=fetch){const g=_.map(v=>()=>m(this,null,function*(){const K=yield p(v+"/"+B,z);if(typeof K!="object"){const T=`Invalid return value ${B} in ${v}`;throw console.log(T),new Error(T)}return K}));return yield(0,O.QJ)(g,f)})}function q(P,S,E,_,B=5e3,z){return m(this,null,function*(){const f=yield Q((0,O.Sy)(S),E,_,B,z);if(!f.ok){const v=yield f.text();throw console.error(v),new Error(`Error fetching ${E}: ${v}`)}const p=yield f.json();return P(p)})}function tt(P,S,E,_=5e3,B){return m(this,null,function*(){return yield Q((0,O.Sy)(P),S,E,_,B)})}const et=(P,S,E,_)=>m(void 0,null,function*(){return yield tt(J,P,S,E,_)}),n=P=>Object.keys(P).map(S=>{const E=P[S];return E==null?S:`${S}=${encodeURIComponent(E)}`}).join("&")},79014:function(ft,Z,h){"use strict";h.d(Z,{Q:function(){return z},k:function(){return B}});var O=h(77591),m=h.n(O),J=h(24350),Q=h(84564),q=h.n(Q),tt=h(76714),et=Object.defineProperty,n=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,E=(f,p,g)=>p in f?et(f,p,{enumerable:!0,configurable:!0,writable:!0,value:g}):f[p]=g,_=(f,p)=>{for(var g in p||(p={}))P.call(p,g)&&E(f,g,p[g]);if(n)for(var g of n(p))S.call(p,g)&&E(f,g,p[g]);return f};function B(f,p,g,v,K){const T=_({},q()(p,{},!0)),nt=p.startsWith(`${f.pluginId}://`);if(T.protocol!=null&&(T.protocol=T.protocol.replace(":","")),T.protocol!=null&&T.protocol!==""&&!g[T.protocol])throw new Error(`Uri protocol '${T.protocol}' is not supported for ${f.pluginId}.`);if(T.host===""&&T.pathname==="")throw new Error("Path and host not found in uri.");const X={publicAddress:T.host!==""?T.host:T.pathname.split("/")[0]},L=T.query.label,st=T.query.message,ot=T.query.category;(L!=null||st!=null||ot!=null||nt)&&(X.metadata={},X.metadata.name=L,X.metadata.notes=st,X.metadata.category=ot,X.metadata.gateway=nt!=null?nt:!1);const j=T.query.amount;if(j!=null&&typeof j=="string"){v==null&&(v=f.currencyCode);const at=(0,tt.cp)(f,v!=null?v:"",K);if(at==null)throw new Error("InternalErrorInvalidCurrencyCode");let M=(0,O.mul)(j,at.multiplier);M=(0,O.toFixed)(M,0,0),X.nativeAmount=M,X.currencyCode=v}return{edgeParsedUri:X,parsedUri:T}}function z(f,p,g){if(f.publicAddress==null)throw new Error("InvalidPublicAddressError");if(g==null&&f.label==null&&f.message==null)return f.publicAddress;{let v="";g!=null&&(v+="amount="+g+"&"),(f.label!=null||f.message!=null)&&(typeof f.label=="string"&&(v+="label="+f.label+"&"),typeof f.message=="string"&&(v+="message="+f.message+"&")),v=v.substr(0,v.length-1);const K={scheme:p,path:f.publicAddress,query:v};return(0,J.qC)(K)}}},9127:function(ft,Z,h){"use strict";h.r(Z),h.d(Z,{TronTools:function(){return kt},makeCurrencyEngine:function(){return de},makeCurrencyTools:function(){return he}});var O=h(77960),m=h(77591),J=h(2153),Q=h(21964),q=h.n(Q),tt=h(48367),et=h.n(tt),n=h(82448),P=h(86352);const S=s=>{if(s.includes("@"))return E(s)?[!0,s.toLowerCase()]:[!1,"Invalid Email"];if(s.includes("+"))return s="+"+s.replace(/[^\d]+/g,""),s.length!==14?[!1,"Invalid Phone number"]:s.substring(0,3)!=="+55"?[!1,"Not brasilian number"]:[!0,s];if(s.length===36)return[!0,s];if(s.length===18)return/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/.test(s)?B(s)?(s=s.replace(/[^\d]+/g,""),[!0,s]):[!1,"invalid cnpj"]:[!1,"invalid pixkey"];if(s.length===13&&/^\d+$/.test(s))return s.substr(0,2)!=="55"?[!1,"invalid pixkey"]:[!0,"+"+s];if(s.length<11)return[!1,"invalid pixkey"];if(s.length===14){if(/^\d+$/.test(s))return B(s)?[!0,s]:[!1,"invalid pixkey"];if(/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(s))return _(s)?[!0,s.replace(/[^\d]+/g,"")]:[!1,"invalid cpf"]}return s.length===11?/^\d+$/.test(s)?_(s)?[!0,s.replace(/[^\d]+/g,"")]:s.charAt(0)==="0"?[!1,"invalid pixkey"]:[!0,"+55"+s]:[!1,"invalid pixkey"]:(s=s.replace(/[^\d]+/g,""),s.length===12?s.charAt(0)!=="0"?[!1,"invalid pixkey"]:[!0,"+55"+s.substr(1)]:s.length===11?_(s)?[!0,s]:[!0,"+55"+s]:[!1,"invalid pixkey"])};function E(s){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(s).toLowerCase())}function _(s){if(s=s.replace(/[^\d]+/g,""),s===""||s.length!==11||s==="00000000000"||s==="11111111111"||s==="22222222222"||s==="33333333333"||s==="44444444444"||s==="55555555555"||s==="66666666666"||s==="77777777777"||s==="88888888888"||s==="99999999999")return!1;let t,e;t=0;for(let r=1;r<=9;r++)t=t+parseInt(s.substring(r-1,r))*(11-r);if(e=t*10%11,(e===10||e===11)&&(e=0),e!==parseInt(s.substring(9,10)))return!1;t=0;for(let r=1;r<=10;r++)t=t+parseInt(s.substring(r-1,r))*(12-r);return e=t*10%11,(e===10||e===11)&&(e=0),e===parseInt(s.substring(10,11))}function B(s){if(s=s.replace(/[^\d]+/g,""),s===""||s.length!==14||s==="00000000000000"||s==="11111111111111"||s==="22222222222222"||s==="33333333333333"||s==="44444444444444"||s==="55555555555555"||s==="66666666666666"||s==="77777777777777"||s==="88888888888888"||s==="99999999999999")return!1;let t=s.length-2,e=s.substring(0,t);const r=s.substring(t);let a=0,o=t-7;for(let i=t;i>=1;i--)a+=Number(e.charAt(t-i))*o--,o<2&&(o=9);let c=a%11<2?0:11-a%11;if(c!==Number(r.charAt(0)))return!1;t=t+1,e=s.substring(0,t),a=0,o=t-7;for(let i=t;i>=1;i--)a+=Number(e.charAt(t-i))*o--,o<2&&(o=9);return c=a%11<2?0:11-a%11,c===Number(r.charAt(1))}function z(s,t=!1){const e=p(s),r=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];let a=65535;for(let i=0;i<e.length;i++){const u=(e[i]^a>>8)&255;a=r[u]^a<<8}const o=(a^0)&65535,c=f(o,4);return t?c.slice(2)+c.slice(0,2):c}function f(s,t){const e=s.toString(16).toUpperCase();return t>0?("0".repeat(t)+e).slice(-t):e.length%2===0?e:"0"+e}function p(s){let t=0;const e=s.length;let r=0,a=Math.max(32,e+(e>>>1)+7),o=new Uint8Array(a>>>3<<3);for(;t<e;){let c=s.charCodeAt(t++);if(c>=55296&&c<=56319){if(t<e){const i=s.charCodeAt(t);(i&64512)===56320&&(++t,c=((c&1023)<<10)+(i&1023)+65536)}if(c>=55296&&c<=56319)continue}if(r+4>o.length){a+=8,a*=1+t/s.length*2,a=a>>>3<<3;const i=new Uint8Array(a);i.set(o),o=i}if((c&4294967168)===0){o[r++]=c;continue}else if((c&4294965248)===0)o[r++]=c>>>6&31|192;else if((c&4294901760)===0)o[r++]=c>>>12&15|224,o[r++]=c>>>6&63|128;else if((c&4292870144)===0)o[r++]=c>>>18&7|240,o[r++]=c>>>12&63|128,o[r++]=c>>>6&63|128;else continue;o[r++]=c&63|128}return o.slice!=null?o.slice(0,r):o.subarray(0,r)}var g=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const v=60*60*24*7,K=(0,n._C)((0,n.su)({status:(0,n.Wf)("ok"),msg:n.XC,data:(0,n.su)({amount:n.mH,name:n.XC,key:n.XC,timeout:n.mH})}),(0,n.su)({status:(0,n.Wf)("failed"),msg:n.XC})),T=(0,n.su)({status:(0,n.Wf)("ok"),msg:n.XC,data:(0,n.su)({amount_usd:n.XC,price_brl:n.XC,total_brl:n.XC,fee_brl:n.XC,send_brl:n.XC,timeout:n.mH,amount_txusdt:n.XC,price_txusdt:n.mH,value_usd:n.XC,total_txusdt:n.XC})}),nt=(s,t,e,r,a)=>g(void 0,null,function*(){const o=new Date;if(e.length>36){const c=z(e.slice(0,-4));if(!e.endsWith(c))return;try{const i=encodeURIComponent(e),l=yield(0,P.lF)(K,["https://connect.smartpay.com.vc"],`api/pix/qrdecode?qrcode=${i}`,void 0,void 0,s.fetch);if(l.status!=="ok")throw new Error(l.msg);const{data:u}=l,{amount:d,key:x,name:k,timeout:w}=u;if(w>0&&w<120)throw new Error("ErrorPixExpired");let C,b;if(d!==0){const A={type:"buy",profile:"transfer",currency:"brl",conv:"txusdt",target:"amount",user:a,amount:d===0?100:d},D=(0,P.sp)(A),R=yield(0,P.lF)(T,["https://connect.smartpay.com.vc"],`api/swapix/swapquote?${D}`,void 0,void 0,s.fetch),{data:H}=R,{amount_txusdt:W,timeout:U}=H;if(U>0&&U<120)throw new Error("ErrorPixExpired");const N=Object.keys(t).find(lt=>t[lt].currencyCode==="USDT");if(N==null)return;const Y=t[N];C=(0,m.mul)(W,Y.denominations[0].multiplier);const rt=Math.min(w>0?w:v,U>0?U:v);b=new Date(o.getTime()+rt*1e3)}return{currencyCode:"USDT",metadata:{name:k,notes:`To PIX: ${x}`},expireDate:b,nativeAmount:C,publicAddress:r,uniqueIdentifier:e}}catch(i){console.log(`Could not query PIX address ${e}: ${i.message}`)}}else{const[c,i]=S(e);return c?{currencyCode:"USDT",metadata:{name:`PIX: ${i}`,notes:`To PIX: ${i}`},publicAddress:"TUmgPbM5J6om7Z2PJjzrbSEbXit84ZhVCj",uniqueIdentifier:i}:void 0}});var ut=h(20918),X=h(79014),L=h(76714),st=h(62177);const ot=(0,n.su)({smartPayPublicAddress:(0,n.Zz)(n.XC,"TUmgPbM5J6om7Z2PJjzrbSEbXit84ZhVCj"),smartPayUserId:(0,n.Zz)(n.XC,"edge")}),j=(0,n.su)({txid:n.XC,timestamp:n.mH}),at=(0,n.su)({txQueryCache:(0,n.Vk)((0,n.su)({mainnet:j,trc20:j}),{mainnet:{txid:"",timestamp:0},trc20:{txid:"",timestamp:0}})}),M=(0,n.Wf)("BANDWIDTH","ENERGY"),It=(0,n.su)({type:(0,n.Wf)("add"),params:(0,n.su)({nativeAmount:n.XC,resource:M})}),Pt=(0,n.su)({type:(0,n.Wf)("remove"),params:(0,n.su)({resource:M})}),Dt=(0,n.su)({chainParameter:(0,n._2)((0,n.su)({key:n.XC,value:(0,n.Zz)(n.mH)}))}),St=(0,n.su)({blockID:n.XC,block_header:(0,n.su)({raw_data:(0,n.su)({number:n.mH,timestamp:n.mH})})}),mt=(0,n.su)({freeNetUsed:(0,n.Vk)(n.mH,0),freeNetLimit:n.mH,EnergyUsed:(0,n.Vk)(n.mH,0),EnergyLimit:(0,n.Vk)(n.mH,0)}),_t=(0,n.su)({frozen:(0,n.Zz)((0,n.vq)((0,n.su)({frozen_balance:n.mH,expire_time:n.mH}))),account_resource:(0,n.su)({frozen_balance_for_energy:(0,n.Zz)((0,n.su)({frozen_balance:n.mH,expire_time:n.mH}))}),balance:(0,n.Vk)(n.mH,0)}),Ot=(0,n.su)({constant_result:(0,n.vq)(n.XC)}),Bt=(0,n.su)({ret:(0,n._2)((0,n.su)({contractRet:n.XC,fee:n.mH})),txID:n.XC,unfreeze_amount:(0,n.Zz)(n.mH),blockNumber:n.mH,block_timestamp:n.mH,raw_data:(0,n.su)({contract:(0,n._2)(n.JC)})}),Rt=(0,n.su)({transaction_id:n.XC,token_info:(0,n.su)({address:n.XC}),block_timestamp:n.mH,from:n.XC,to:n.XC,type:n.XC,value:n.XC}),Lt=(0,n.su)({fee:n.mH,blockNumber:n.mH}),Ft=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({amount:n.mH,owner_address:n.XC,to_address:n.XC})}),type:(0,n.Wf)("TransferContract")}),Ht=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({data:n.XC,owner_address:n.XC,contract_address:n.XC})}),type:(0,n.Wf)("TriggerSmartContract")}),Nt=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({frozen_balance:n.mH,resource_type:M,owner_address:n.XC})}),type:(0,n.Wf)("FreezeBalanceContract")}),Xt=(0,n.su)({parameter:(0,n.su)({value:(0,n.su)({resource_type:M,owner_address:n.XC})}),type:(0,n.Wf)("UnfreezeBalanceContract")}),Ut=s=>(0,n.su)({data:(0,n._2)(s),success:n.jK,meta:(0,n.su)({links:(0,n.Zz)((0,n.su)({next:n.XC})),page_size:n.mH})}),zt=(0,n.su)({energy_used:n.mH,transaction:(0,n.su)({ret:(0,n._2)((0,n.su)({ret:(0,n.Zz)(n.XC)}))})}),Kt=(0,n.su)({result:n.jK,txid:n.XC,message:n.XC}),Mt=st.BQ,dt=(0,n.su)({tronMnemonic:(0,n.Zz)(n.XC),tronKey:n.XC,derivationPath:(0,n.Zz)(n.XC)});var yt=h(85632),$t=h(13185),gt=h(94935),Wt=h(50244),Vt=h(56475),Jt=h(85021),Zt=h(68142),Qt=h.n(Zt),pt=h(48764).Buffer,jt=Object.getPrototypeOf,Gt=Reflect.get,vt=(s,t,e)=>Gt(jt(s),e,t),Tt=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const F=s=>{const t=(0,O.decode58Check)(s);return(0,yt.byteArray2hexStr)(t)},G=s=>{const t=(0,Jt.hexStr2byteArray)(s);return(0,O.getBase58CheckAddress)(t)},wt="a9059cbb",fe=s=>{if(!s.startsWith(wt))throw new Error("Not a TRC20 data payload");const t=s.replace(wt,""),e=`41${t.substring(24,64)}`,r=G(e),a=t.substring(64,128),o=hexToDecimal(a);return[r,o]},Yt=(s,t)=>{const e=F(s).replace(/^(41)/,"0x"),r=Qt().simpleEncode("transfer(address,uint256):(uint256)",e,parseInt(t));return pt.from(r).toString("hex")};class ct extends Vt.Client{constructor(t){super(""),this.recentBlock=t}getLatestBlock(){return this.recentBlock}addData(t,e){return Tt(this,null,function*(){const r=yield vt(ct.prototype,this,"addRef").call(this,t),a=r.getRawData();return a.setData(Uint8Array.from(pt.from(e,"ascii"))),r.setRawData(a),r})}addRef(t,e){return Tt(this,null,function*(){const r=yield vt(ct.prototype,this,"addRef").call(this,t);if(e!=null){const a=r.getRawData();a.setFeeLimit(e),r.setRawData(a)}return r})}}var qt=Object.defineProperty,te=Object.defineProperties,ee=Object.getOwnPropertyDescriptors,Ct=Object.getOwnPropertySymbols,ne=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,oe=Reflect.get,bt=(s,t,e)=>t in s?qt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ht=(s,t)=>{for(var e in t||(t={}))re.call(t,e)&&bt(s,e,t[e]);if(Ct)for(var e of Ct(t))se.call(t,e)&&bt(s,e,t[e]);return s},ae=(s,t)=>te(s,ee(t)),At=(s,t,e)=>oe(ne(s),e,t),y=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});const ce=(0,L.jT)(),Et=2e4,ie=2e4,le=3e3,ue=60*10*1e3;class it extends Wt.P{constructor(t,e,r,a){super(t,e,r,a);const o=(0,L.zR)(t),{networkInfo:c}=t;this.fetchCors=o,this.log=a.log,this.networkInfo=c,this.recentBlock={hash:"0",number:0,timestamp:0},this.accountResources={BANDWIDTH:0,ENERGY:0},this.networkFees={getCreateAccountFee:1e5,getTransactionFee:1e3,getEnergyFee:280,getMemoFee:1e6},this.tronscan=new ct(this.recentBlock),this.accountExistsCache={},this.energyEstimateCache={},this.processTRXTransaction=this.processTRXTransaction.bind(this),this.processTRC20Transaction=this.processTRC20Transaction.bind(this),this.stakingStatus={stakedAmounts:[{nativeAmount:"0",otherParams:{type:"BANDWIDTH"}},{nativeAmount:"0",otherParams:{type:"ENERGY"}}]}}setOtherData(t){this.otherData=at(t)}fetch(t,e){return y(this,arguments,function*(r,a,o={}){const c=r+a,i=yield this.fetchCors(c,o);if(!i.ok||i.status!==200)throw this.log(`The server returned error code ${i.status} for ${c}`),new Error(`The server returned error code ${i.status} for ${c}`);const l=yield i.json();if(typeof l!="object"){const u=`Invalid return value ${a} in ${r}`;throw this.log(u),new Error(u)}return{server:r,result:l}})}checkBlockchainInnerLoop(){return y(this,null,function*(){try{const t=yield this.multicastServers("trx_blockNumber","/wallet/getnowblock"),e=St(t),r=e.block_header.raw_data.number;Object.assign(this.recentBlock,{hash:e.blockID,number:r,timestamp:e.block_header.raw_data.timestamp}),this.walletLocalData.blockHeight!==r&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(t){this.log.error("Error fetching height: ",t)}})}updateBalance(t,e){const r=this.walletLocalData.totalBalances[t];typeof this.walletLocalData.totalBalances[t]>"u"&&(this.walletLocalData.totalBalances[t]="0"),(r==null||!(0,m.eq)(e,r))&&(this.walletLocalData.totalBalances[t]=e,this.log(t+": token Address balance: "+e),this.currencyEngineCallbacks.onBalanceChanged(t,e)),this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}checkTokenBalances(){return y(this,null,function*(){const t=F(this.walletLocalData.publicKey);for(const e of this.enabledTokens){const r=this.allTokens.find(c=>c.currencyCode===e);if((r==null?void 0:r.contractAddress)==null)continue;const o={contract_address:F(r.contractAddress),function_selector:"balanceOf(address)",parameter:(0,L.gc)(t,32),owner_address:t};try{const c=yield this.multicastServers("trx_getBalance","/wallet/triggerconstantcontract",o),i=Ot(c);r!=null&&this.updateBalance(r.currencyCode,(0,L.Z8)(i.constant_result[0]))}catch(c){this.log.error(`Failed to get balance of ${e}`,c)}}})}checkAccountInnerLoop(){return y(this,null,function*(){const t={address:F(this.walletLocalData.publicKey)};try{const e=yield this.multicastServers("trx_getBalance","/wallet/getaccount",t),r=(0,n.Vk)(_t)(e);if(r==null){this.updateBalance(this.currencyInfo.currencyCode,"0");return}this.updateBalance(this.currencyInfo.currencyCode,r.balance.toString());const{frozen:a,account_resource:{frozen_balance_for_energy:o}}=r,c=[];if(a!=null){const i=a[0].frozen_balance.toString(),l=new Date(a[0].expire_time);c.push({nativeAmount:i,unlockDate:l,otherParams:{type:"BANDWIDTH"}})}if(o!=null){const i=o.frozen_balance.toString(),l=new Date(o.expire_time);c.push({nativeAmount:i,unlockDate:l,otherParams:{type:"ENERGY"}})}this.stakingStatus={stakedAmounts:c},this.currencyEngineCallbacks.onStakingStatusChanged(ht({},this.stakingStatus))}catch(e){this.log.error("Error checking TRX address balance: ",e)}try{const e=yield this.multicastServers("trx_getAccountResource","/wallet/getaccountresource",t),r=mt(e);this.accountResources={BANDWIDTH:r.freeNetLimit-r.freeNetUsed,ENERGY:r.EnergyLimit-r.EnergyUsed}}catch(e){this.log.error("Error checking TRX address resources: ",e)}})}queryTransactions(){return y(this,null,function*(){return yield ce(()=>y(this,null,function*(){return yield this.queryTransactionsInnerLoop()}))})}queryTransactionsInnerLoop(){return y(this,null,function*(){try{yield this.fetchTrxTransactions(),yield this.fetchTrc20Transactions()}catch(t){throw this.log.error("Error checkTransactionsFetch fetchTrxTransactions: ",t),t}this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]);for(const t of this.enabledTokens)this.tokenCheckTransactionsStatus[t]=1;this.updateOnAddressesChecked()})}fetchTrxTransactions(){return y(this,null,function*(){let t=!1;for(;!t;)t=yield this.fetchTransactions("mainnet",Bt,this.processTRXTransaction)})}fetchTrc20Transactions(){return y(this,null,function*(){let t=!1;for(;!t;)t=yield this.fetchTransactions("trc20",Rt,this.processTRC20Transaction)})}fetchTransactions(t,e,r){return y(this,null,function*(){var a;const o=t==="trc20"?t:"",c=this.otherData.txQueryCache[t].timestamp,i=`/v1/accounts/${this.walletLocalData.publicKey}/transactions/${o}?limit=200&order_by=block_timestamp,asc&min_timestamp=${c}`,l=yield this.multicastServers("trx_getTransactions",i),{data:u,meta:d,success:x}=Ut(e)(l),k=((a=d==null?void 0:d.links)==null?void 0:a.next)==null;if(!x)throw new Error("Failed to query TRX transactions");for(const w of u){const{timestamp:C,txid:b}=yield r(w);this.otherData.txQueryCache[t].txid=b,this.otherData.txQueryCache[t].timestamp=C,this.walletLocalDataDirty=!0}return k})}processTRXTransaction(t){const{txID:e,block_timestamp:r,blockNumber:a,ret:o,unfreeze_amount:c,raw_data:{contract:i}}=t,l={txid:e,timestamp:r};if(e===this.otherData.txQueryCache.mainnet.txid||o.length<1)return l;const u=[];for(const d of i){const x=(0,n.Vk)(Ft)(d);if(x!=null){const{parameter:{value:{amount:b,owner_address:I,to_address:A}}}=x,{contractRet:D,fee:R}=o[0];let H=R.toString();const W=G(I),U=G(A);let N=b.toString();if(W===this.walletLocalData.publicKey)W===U?N=(0,m.mul)(H,"-1"):N=(0,m.mul)((0,m.add)(N,H),"-1"),D!=="SUCCESS"&&(N="0");else{if(D!=="SUCCESS")return l;u.push(this.walletLocalData.publicKey),H="0"}const{currencyCode:Y}=this.currencyInfo,rt={txid:e,date:Math.floor(r/1e3),currencyCode:Y,blockHeight:a,nativeAmount:N,networkFee:H,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(Y,rt),l}const k=(0,n.Vk)(Ht)(d);if(k!=null){const{parameter:{value:{owner_address:b}}}=k;if(G(b)!==this.walletLocalData.publicKey)break;const I=o[0].fee.toString(),{currencyCode:A}=this.currencyInfo,D={txid:e,date:Math.floor(r/1e3),currencyCode:A,blockHeight:a,nativeAmount:(0,m.mul)(I,"-1"),networkFee:I,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(A,D),l}const w=(0,n.Vk)(Nt)(d);if(w!=null){const{parameter:{value:{owner_address:b,frozen_balance:I}}}=w;if(G(b)!==this.walletLocalData.publicKey)break;const A=o[0].fee.toString(),D=(0,m.add)(I.toString(),A),{currencyCode:R}=this.currencyInfo,H={txid:e,date:Math.floor(r/1e3),currencyCode:R,blockHeight:a,nativeAmount:(0,m.mul)(D,"-1"),networkFee:A,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(R,H),l}const C=(0,n.Vk)(Xt)(d);if(C!=null){if(c==null)return l;const{parameter:{value:{owner_address:b}}}=C;if(G(b)!==this.walletLocalData.publicKey)break;const I=o[0].fee.toString(),{currencyCode:A}=this.currencyInfo,D={txid:e,date:Math.floor(r/1e3),currencyCode:A,blockHeight:a,nativeAmount:(0,m.sub)(c.toString(),I),networkFee:I,ourReceiveAddresses:u,signedTx:"",walletId:this.walletId};return this.addTransaction(A,D),l}}return l}processTRC20Transaction(t){return y(this,null,function*(){const{transaction_id:e,token_info:{address:r},block_timestamp:a,from:o,to:c,type:i,value:l}=t,u={txid:e,timestamp:a};if(e===this.otherData.txQueryCache.trc20.txid)return u;const d=yield this.multicastServers("trx_getTransactionInfo","/wallet/gettransactioninfobyid",{value:e}),{blockNumber:x,fee:k}=Lt(d),w=this.allTokens.find(D=>D.contractAddress===r);if(i!=="Transfer"||w==null)return u;const C=[];let b=l;const I=k;if(o===this.walletLocalData.publicKey)b=(0,m.mul)(l,"-1");else if(c===this.walletLocalData.publicKey)C.push(this.walletLocalData.publicKey);else return u;const A={txid:e,date:Math.floor(a/1e3),currencyCode:w.currencyCode,blockHeight:x,nativeAmount:b,networkFee:"0",ourReceiveAddresses:C,signedTx:"",walletId:this.walletId};return(0,m.lt)(b,"0")&&(A.parentNetworkFee=I.toString()),this.addTransaction(w.currencyCode,A),u})}checkUpdateNetworkFees(){return y(this,null,function*(){try{const t=yield this.multicastServers("trx_chainParams","/wallet/getchainparameters"),e=Dt(t).chainParameter;for(const r of Object.keys(this.networkFees)){const a=e.find(o=>o.key===r);a!=null&&(this.networkFees=ae(ht({},this.networkFees),{[r]:a.value}))}}catch(t){this.log.error("checkUpdateNetworkFees error: ",t)}})}multicastServers(t,e){return y(this,arguments,function*(r,a,o={}){let c={result:"",server:"no server"},i=[];switch(r){case"trx_chainParams":i=this.networkInfo.tronNodeServers.map(l=>()=>y(this,null,function*(){return yield this.fetch(l,a)}));break;case"trx_blockNumber":case"trx_broadcastTx":case"trx_estimateEnergy":case"trx_getAccountResource":case"trx_getBalance":case"trx_getTransactionInfo":i=this.networkInfo.tronNodeServers.map(l=>()=>y(this,null,function*(){const u={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(o)};return yield this.fetch(l,a,u)}));break;case"trx_getTransactions":i=this.networkInfo.tronApiServers.map(l=>()=>y(this,null,function*(){const u={headers:{Accept:"application/json","Content-Type":"application/json"}};return yield this.fetch(l,a,u)}));break}return i=(0,L.Sy)(i),c=yield(0,L.QJ)(i),this.log(`TRX multicastServers ${r} ${c.server} won`),c.result})}calcTxFee(t){return y(this,null,function*(){var e,r;const{note:a,receiverAddress:o,tokenOpts:c,unsignedTxHex:i}=t,l=(0,L.cp)(this.currencyInfo,this.currencyInfo.currencyCode);if(l==null)throw new Error("calcTxFee unknown denom");let u=0;if(c!=null&&o!=null){const{contractAddress:C,data:b}=c;if(this.energyEstimateCache[`${o}:${C}`]==null){const I={owner_address:F(this.walletLocalData.publicKey),contract_address:F(C),function_selector:"transfer(address,uint256)",parameter:b.slice(8)};try{const A=yield this.multicastServers("trx_estimateEnergy","/wallet/triggerconstantcontract",I),D=zt(A),R=(e=D.transaction.ret[0])==null?void 0:e.ret;if(R!=null&&R!=="SUCCESS")throw new Error("calcTxFee Failed to estimate fee");this.energyEstimateCache[`${o}:${C}`]=D.energy_used}catch(A){this.log.warn("trx_estimateEnergy error. Using a high default.",A)}}u=Math.max(((r=this.energyEstimateCache[`${o}:${C}`])!=null?r:1e5)-this.accountResources.ENERGY,0)}this.log("Account energy: ",this.accountResources.ENERGY),this.log("Energy needed: ",u);let d=i.length/2+65+64+5;if(i.length/2<128&&d--,o!=null&&this.accountExistsCache[o]===void 0)try{const C=yield this.multicastServers("trx_getAccountResource","/wallet/getaccountresource",{address:F(o)});this.accountExistsCache[o]=(0,n.Vk)(mt)(C)!=null}catch(C){this.log.error("calcTxFee error: Failed to call trx_getAccountResource. Allowing the user to proceed assuming high fee.",C)}c==null&&o!=null&&!this.accountExistsCache[o]&&(d=100),d<this.accountResources.BANDWIDTH&&(d=0),this.log("Account bandwidth: ",this.accountResources.BANDWIDTH),this.log("Bandwidth needed: ",d);let x=0;c==null&&o!=null&&!this.accountExistsCache[o]&&(x=this.networkFees.getCreateAccountFee+parseInt(l.multiplier)),this.log("Create account fee: ",x);const k=a!=null?this.networkFees.getMemoFee:0;this.log("Transaction note fee: ",k);const w=u*this.networkFees.getEnergyFee+d*this.networkFees.getTransactionFee+x+k;return this.log("Total fee in SUN: ",w),w.toString()})}txBuilder(t){return y(this,null,function*(){const{contractJson:e,feeLimit:r,note:a}=t,o=(0,$t.contractJsonToProtobuf)(e);yield this.tronscan.addRef(o,r),a!=null&&(yield this.tronscan.addData(o,a));const c=(0,yt.byteArray2hexStr)(o.getRawData().serializeBinary());return{transaction:o,transactionHex:c}})}makeTransferJson(t){return y(this,null,function*(){const{currencyCode:e,toAddress:r,nativeAmount:a,data:o,note:c}=t;let i,l;if(e===this.currencyInfo.currencyCode)l={parameter:{value:{to_address:F(r),owner_address:F(this.walletLocalData.publicKey),amount:parseInt(a)}},type:"TransferContract"};else{const u=this.allTokens.find(d=>d.currencyCode===e);if((u==null?void 0:u.contractAddress)==null)throw new Error(`txBuilder unknown currency code ${e}`);l={parameter:{value:{owner_address:F(this.walletLocalData.publicKey),contract_address:F(u.contractAddress),data:o,call_value:0}},type:"TriggerSmartContract"},i=this.networkInfo.defaultFeeLimit}return{contractJson:l,feeLimit:i,note:c}})}makeFreezeTransaction(t){return y(this,null,function*(){const{params:{nativeAmount:e,resource:r}}=t,o={contractJson:{parameter:{value:{owner_address:F(this.walletLocalData.publicKey),frozen_balance:parseInt(e),frozen_duration:this.networkInfo.defaultFreezeDurationInDays,resource:r}},type:"FreezeBalanceContract"}},{transactionHex:c}=yield this.txBuilder(o),i=yield this.calcTxFee({unsignedTxHex:c});return{txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:(0,m.mul)(e,"-1"),networkFee:i,ourReceiveAddresses:[],signedTx:"",otherParams:o,walletId:this.walletId,metadata:{notes:r}}})}makeUnfreezeTransaction(t){return y(this,null,function*(){const{params:{resource:e}}=t,r=this.stakingStatus.stakedAmounts.find(u=>{var d;return((d=u.otherParams)==null?void 0:d.type)===e});if(r==null)throw new Error("Nothing to unfreeze");const o={contractJson:{parameter:{value:{owner_address:F(this.walletLocalData.publicKey),resource:e}},type:"UnfreezeBalanceContract"}},{transactionHex:c}=yield this.txBuilder(o),i=yield this.calcTxFee({unsignedTxHex:c});return{txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:r.nativeAmount,networkFee:i,ourReceiveAddresses:[],signedTx:"",otherParams:o,walletId:this.walletId,metadata:{notes:e}}})}startEngine(){return y(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",ie).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",Et).catch(()=>{}),this.addToLoop("checkTokenBalances",Et).catch(()=>{}),this.addToLoop("checkUpdateNetworkFees",ue).catch(()=>{}),this.addToLoop("queryTransactions",le).catch(()=>{}),yield At(it.prototype,this,"startEngine").call(this)})}getStakingStatus(){return y(this,null,function*(){return ht({},this.stakingStatus)})}resyncBlockchain(){return y(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return y(this,null,function*(){const e=this.getBalance({currencyCode:t.currencyCode});if(t.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:r,memo:a}=t.spendTargets[0],o=a===""?void 0:a;if(r==null||t.currencyCode==null)throw new Error("Error: need recipient address and/or currencyCode");if(t.currencyCode===this.currencyInfo.currencyCode){const c=(i,l)=>y(this,null,function*(){const u=(0,m.sub)(l,i);if((0,m.lte)(u,"1"))return i;const d=(0,m.add)(i,(0,m.div)(u,"2")),x={toAddress:r,currencyCode:this.currencyInfo.currencyCode,nativeAmount:d},{contractJson:k,feeLimit:w}=yield this.makeTransferJson(x),{transactionHex:C}=yield this.txBuilder({contractJson:k,feeLimit:w,note:o});t.spendTargets[0].nativeAmount=d;const b=yield this.calcTxFee({receiverAddress:r,unsignedTxHex:C,note:o}),I=(0,m.add)(d,b);return(0,m.gt)(I,e)?yield c(i,d):yield c(d,l)});return yield c("0",(0,m.add)(e,"1"))}else return t.spendTargets[0].nativeAmount=e,yield this.makeSpend(t),e})}makeSpend(t){return y(this,null,function*(){var e,r;if(t.otherParams!=null){let V;if(V=(0,n.Vk)(It)(t.otherParams),V!=null)return yield this.makeFreezeTransaction(V);if(V=(0,n.Vk)(Pt)(t.otherParams),V!=null)return yield this.makeUnfreezeTransaction(V)}const{edgeSpendInfo:a,currencyCode:o}=At(it.prototype,this,"makeSpendCheck").call(this,t),c=o!==this.currencyInfo.currencyCode;if(a.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:i,publicAddress:l,otherParams:u,memo:d}=a.spendTargets[0];if(l==null)throw new Error("makeSpend Missing publicAddress");if(i==null)throw new gt.$D;const x=(e=u==null?void 0:u.data)!=null?e:o!==this.currencyInfo.currencyCode?Yt(l,i):void 0,k=c?this.allTokens.find(V=>V.currencyCode===o):void 0,w=d===""?void 0:d,C={currencyCode:o,toAddress:l,nativeAmount:i,contractAddress:k==null?void 0:k.contractAddress,data:x,note:w},{contractJson:b,feeLimit:I}=yield this.makeTransferJson(C),{transactionHex:A}=yield this.txBuilder({contractJson:b,feeLimit:I,note:w}),D=(k==null?void 0:k.contractAddress)!=null&&x!=null?{contractAddress:k==null?void 0:k.contractAddress,data:x}:void 0,R=yield this.calcTxFee({receiverAddress:l,unsignedTxHex:A,tokenOpts:D,note:w});let H,W,U,N;c?(H=i,W="0",U=R,N=U):(H=(0,m.add)(i,R),W=R,N=H);const Y=(r=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?r:"0";if((0,m.gt)(N,Y))throw new gt.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:R});const rt={contractJson:b,feeLimit:I,note:w},lt={txid:"",date:0,currencyCode:o,blockHeight:0,nativeAmount:(0,m.mul)(H,"-1"),networkFee:W,ourReceiveAddresses:[],signedTx:"",otherParams:rt,walletId:this.walletId};return U!=null&&(lt.parentNetworkFee=U),lt})}signTx(t,e){return y(this,null,function*(){const r=(0,L.Xp)(t),a=yield this.txBuilder(r),{tronKey:o}=dt(e),c=this.tronscan.getSigner(o),{hex:i}=yield c.signTransaction(a.transaction);return t.signedTx=i,t})}broadcastTx(t){return y(this,null,function*(){const e={transaction:t.signedTx},r=yield this.multicastServers("trx_broadcastTx","/wallet/broadcasthex",e),a=Kt(r);if(!a.result)throw new Error(a.message);const{toAddress:o,contractAddress:c}=(0,L.Xp)(t);return t.currencyCode===this.currencyInfo.currencyCode&&o!=null&&(this.accountExistsCache[o]=!0),c!=null&&delete this.energyEstimateCache[`${o}:${c}`],t.txid=a.txid,t.date=Date.now()/1e3,t})}getDisplayPrivateSeed(t){var e;const r=dt(t);return(e=r.tronMnemonic)!=null?e:r.tronKey}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}}function de(s,t,e,r){return y(this,null,function*(){const a=Mt(e),o=new it(s,t,a,r);return yield o.loadEngine(t,a,r),o})}var xt=h(48764).Buffer,$=(s,t,e)=>new Promise((r,a)=>{var o=l=>{try{i(e.next(l))}catch(u){a(u)}},c=l=>{try{i(e.throw(l))}catch(u){a(u)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,c);i((e=e.apply(s,t)).next())});class kt{constructor(t){const{builtinTokens:e,currencyInfo:r,initOptions:a,io:o,log:c,networkInfo:i}=t;this.builtinTokens=e,this.currencyInfo=r,this.initOptions=ot(a),this.io=o,this.log=c,this.networkInfo=i}importPrivateKey(t,e){return $(this,null,function*(){var r;if(/^(0x)?[0-9a-fA-F]{64}$/.test(t)){const a=xt.from(t.replace(/^0x/,""),"hex");if(q().isValidPrivate(a)===!0)throw new Error("Invalid private key");return{tronKey:a.toString("hex")}}else{if(!(0,J.validateMnemonic)(t))throw new Error("Invalid input");const a=(r=e==null?void 0:e.derivationPath)!=null?r:this.networkInfo.defaultDerivationPath,o=yield this._mnemonicToTronKey(t,a);return{tronMnemonic:t,tronKey:o,derivationPath:a}}})}createPrivateKey(t){return $(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=xt.from(this.io.random(32)).toString("hex"),r=(0,J.entropyToMnemonic)(e);return yield this.importPrivateKey(r)})}_mnemonicToTronKey(t,e){return $(this,null,function*(){const r=yield(0,J.mnemonicToSeed)(t);return et().fromMasterSeed(r).derivePath(e).getWallet().getPrivateKeyString().replace("0x","")})}derivePublicKey(t){return $(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{tronKey:e}=dt(t.keys);return{publicKey:(0,O.pkToAddress)(e)}})}parseUri(t,e,r){return $(this,null,function*(){var a;const o={[this.currencyInfo.pluginId]:!0},{smartPayPublicAddress:c,smartPayUserId:i}=this.initOptions,l=yield nt(this.io,this.builtinTokens,t,c,i);if(l!=null)return l;const{parsedUri:u,edgeParsedUri:d}=(0,X.k)(this.currencyInfo,t,o,e!=null?e:this.currencyInfo.currencyCode,r),x=(a=d.publicAddress)!=null?a:"";if(!(0,O.isAddressValid)(x))throw new Error("InvalidPublicAddressError");return d.uniqueIdentifier=u.query.memo,d})}encodeUri(t,e){return $(this,null,function*(){const{publicAddress:r,nativeAmount:a,currencyCode:o}=t;if(!(0,O.isAddressValid)(r))throw new Error("InvalidPublicAddressError");let c;if(typeof a=="string"){const l=(0,L.cp)(this.currencyInfo,o!=null?o:this.currencyInfo.currencyCode,e);if(l==null)throw new Error("InternalErrorInvalidCurrencyCode");c=(0,m.div)(a,l.multiplier,18)}return(0,X.Q)(t,this.currencyInfo.pluginId,c)})}getTokenId(t){return $(this,null,function*(){(0,ut.Rp)(t);const e=(0,ut.Oj)(t.networkLocation);if(e==null||!(0,O.isAddressValid)(e.contractAddress))throw new Error("ErrorInvalidContractAddress");return e.contractAddress})}}function he(s){return $(this,null,function*(){return new kt(s)})}},89214:function(){},52361:function(){},94616:function(){}}]);
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[159],{79014:function(z,T,d){"use strict";d.d(T,{Q:function(){return x},k:function(){return H}});var g=d(77591),b=d.n(g),B=d(24350),A=d(84564),E=d.n(A),v=d(76714),O=Object.defineProperty,k=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,P=(l,y,h)=>y in l?O(l,y,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[y]=h,D=(l,y)=>{for(var h in y||(y={}))K.call(y,h)&&P(l,h,y[h]);if(k)for(var h of k(y))N.call(y,h)&&P(l,h,y[h]);return l};function H(l,y,h,p,I){const i=D({},E()(y,{},!0)),m=y.startsWith(`${l.pluginId}://`);if(i.protocol!=null&&(i.protocol=i.protocol.replace(":","")),i.protocol!=null&&i.protocol!==""&&!h[i.protocol])throw new Error(`Uri protocol '${i.protocol}' is not supported for ${l.pluginId}.`);if(i.host===""&&i.pathname==="")throw new Error("Path and host not found in uri.");const f={publicAddress:i.host!==""?i.host:i.pathname.split("/")[0]},C=i.query.label,S=i.query.message,c=i.query.category;(C!=null||S!=null||c!=null||m)&&(f.metadata={},f.metadata.name=C,f.metadata.notes=S,f.metadata.category=c,f.metadata.gateway=m!=null?m:!1);const t=i.query.amount;if(t!=null&&typeof t=="string"){p==null&&(p=l.currencyCode);const e=(0,v.cp)(l,p!=null?p:"",I);if(e==null)throw new Error("InternalErrorInvalidCurrencyCode");let n=(0,g.mul)(t,e.multiplier);n=(0,g.toFixed)(n,0,0),f.nativeAmount=n,f.currencyCode=p}return{edgeParsedUri:f,parsedUri:i}}function x(l,y,h){if(l.publicAddress==null)throw new Error("InvalidPublicAddressError");if(h==null&&l.label==null&&l.message==null)return l.publicAddress;{let p="";h!=null&&(p+="amount="+h+"&"),(l.label!=null||l.message!=null)&&(typeof l.label=="string"&&(p+="label="+l.label+"&"),typeof l.message=="string"&&(p+="message="+l.message+"&")),p=p.substr(0,p.length-1);const I={scheme:y,path:l.publicAddress,query:p};return(0,B.qC)(I)}}},940:function(z,T,d){"use strict";d.r(T),d.d(T,{ZcashTools:function(){return C},makeCurrencyEngine:function(){return R},makeCurrencyTools:function(){return S}});var g=d(77591),b=d(2153),B=d(48764),A=d(79014),E=d(76714),v=d(94935),O=d(50244),k=d(82448);const K=(0,k.su)({first:k.mH,last:k.mH}),N=(0,k.su)({alias:(0,k.Vk)(k.XC),blockRange:(0,k.Vk)(K,{first:0,last:0})});var P=Object.defineProperty,D=Object.getOwnPropertySymbols,H=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,y=Reflect.get,h=(c,t,e)=>t in c?P(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,p=(c,t)=>{for(var e in t||(t={}))x.call(t,e)&&h(c,e,t[e]);if(D)for(var e of D(t))l.call(t,e)&&h(c,e,t[e]);return c},I=(c,t,e)=>y(H(c),e,t),i=(c,t,e)=>new Promise((n,r)=>{var o=u=>{try{a(e.next(u))}catch(w){r(w)}},s=u=>{try{a(e.throw(u))}catch(w){r(w)}},a=u=>u.done?n(u.value):Promise.resolve(u.value).then(o,s);a((e=e.apply(c,t)).next())});class m extends O.P{constructor(t,e,n,r,o){super(t,e,n,r);const{networkInfo:s}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=s,this.makeSynchronizer=o}setOtherData(t){this.otherData=N(t)}initData(){const{birthdayHeight:t,alias:e}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.alias=e,this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio=0}initSubscriptions(){this.synchronizer.on("update",t=>i(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>i(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()}))}queryAll(){return i(this,null,function*(){yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=e*.99/100;let r=0;if(t>0){const s=n-t;this.initialNumBlocksToDownload<0&&(this.initialNumBlocksToDownload=s),r=s===0||this.initialNumBlocksToDownload===0?1:1-s/this.initialNumBlocksToDownload}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=r*.8;const o=(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]+this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode])/2;o!==this.progressRatio&&(Math.abs(o-this.progressRatio)>.1||o===1)&&(this.progressRatio=o,this.updateOnAddressesChecked())}}startEngine(){return i(this,null,function*(){this.initData(),this.synchronizer=yield this.makeSynchronizer(this.initializer),yield this.synchronizer.start(),this.initSubscriptions(),yield I(m.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return i(this,null,function*(){if(!!this.isSynced())try{const t=yield this.synchronizer.getShieldedBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return i(this,null,function*(){try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,g.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r={txid:t.rawTransactionId,date:t.blockTimeInSeconds,currencyCode:this.currencyInfo.currencyCode,blockHeight:t.minedHeight,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:n,signedTx:"",otherParams:{},walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,r)}killEngine(){return i(this,null,function*(){yield this.synchronizer.stop(),yield I(m.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return i(this,null,function*(){yield I(m.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return i(this,null,function*(){var t;yield I(m.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),this.synchronizer.rescan((t=this.walletInfo.keys[`${this.pluginId}BirthdayHeight`])!=null?t:this.networkInfo.defaultBirthday).catch(e=>this.warn("resyncBlockchain failed: ",e))})}getMaxSpendable(){return i(this,null,function*(){const t=(0,g.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,g.lte)(t,"0"))throw new v.C_;return t})}makeSpend(t){return i(this,null,function*(){var e;if(!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),o=n.spendTargets[0],{publicAddress:s,nativeAmount:a}=o;if(s==null)throw new Error("makeSpend Missing publicAddress");if(a==null)throw new v.$D;if((0,g.eq)(a,"0"))throw new v.$D;const u=(0,g.add)(a,this.networkInfo.defaultNetworkFee);if((0,g.gt)(u,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new v.C_;if((0,g.gt)(u,this.availableZatoshi))throw new v.C_("Amount exceeds available balance");const w=n.spendTargets.map(U=>{var _;return{uniqueIdentifier:U.uniqueIdentifier,memo:U.memo,nativeAmount:(_=U.nativeAmount)!=null?_:"0",currencyCode:r,publicAddress:s}});return{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:`-${u}`,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",spendTargets:w,walletId:this.walletId}})}signTx(t){return i(this,null,function*(){return t})}broadcastTx(t){return i(this,null,function*(){var e,n;if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const r=t.spendTargets[0],o={zatoshi:(0,g.sub)((0,g.abs)(t.nativeAmount),t.networkFee),toAddress:r.publicAddress,memo:(n=(e=r.memo)!=null?e:r.uniqueIdentifier)!=null?n:"",fromAccountIndex:0,spendingKey:this.walletInfo.keys[`${this.pluginId}SpendKey`]};try{const s=yield this.synchronizer.sendToAddress(o);t.txid=s.txId,t.signedTx=s.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
- ${(0,E.oX)(t)}`)}catch(s){throw this.warn("FAILURE broadcastTx failed: ",s),s}return t})}getDisplayPrivateSeed(){var t;return(t=this.walletInfo.keys[`${this.pluginId}Mnemonic`])!=null?t:""}getDisplayPublicSeed(){var t,e;return(e=(t=this.walletInfo.keys.unifiedViewingKeys)==null?void 0:t.extfvk)!=null?e:""}loadEngine(t,e,n){return i(this,null,function*(){var r;if(yield I(m.prototype,this,"loadEngine").call(this,t,e,n),this.engineOn=!0,this.walletInfo.keys.publicKey!=null||this.walletInfo.keys.unifiedViewingKeys!=null){const a=yield t.derivePublicKey(this.walletInfo);this.walletInfo.keys.publicKey=a.publicKey,this.walletInfo.keys[`${this.pluginId}ViewKeys`]=a.unifiedViewingKeys}const{rpcNode:o,defaultBirthday:s}=this.networkInfo;this.initializer=p({fullViewingKey:this.walletInfo.keys[`${this.pluginId}ViewKeys`],birthdayHeight:(r=this.walletInfo.keys[`${this.pluginId}BirthdayHeight`])!=null?r:s,alias:this.walletInfo.keys.publicKey},o)})}}function R(c,t,e,n){return i(this,null,function*(){const{makeSynchronizer:r}=c.nativeIo["edge-currency-accountbased"][c.networkInfo.nativeSdk],o=new m(c,t,e,n,r);return yield o.loadEngine(t,e,n),o})}var f=(c,t,e)=>new Promise((n,r)=>{var o=u=>{try{a(e.next(u))}catch(w){r(w)}},s=u=>{try{a(e.throw(u))}catch(w){r(w)}},a=u=>u.done?n(u.value):Promise.resolve(u.value).then(o,s);a((e=e.apply(c,t)).next())});class C{constructor(t){const{builtinTokens:e,currencyInfo:n,io:r,networkInfo:o}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=r,this.networkInfo=o;const s=t.nativeIo["edge-currency-accountbased"];if(s==null)throw new Error("Need opts");const{KeyTool:a,AddressTool:u}=s[this.networkInfo.nativeSdk];this.KeyTool=a,this.AddressTool=u}getNewWalletBirthdayBlockheight(){return f(this,null,function*(){let t=this.networkInfo.defaultBirthday;try{t=yield this.KeyTool.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)}catch{}return t})}isValidAddress(t){return f(this,null,function*(){return(yield this.AddressTool.isValidShieldedAddress(t))||(yield this.AddressTool.isValidTransparentAddress(t))})}importPrivateKey(t){return f(this,null,function*(){const{pluginId:e}=this.currencyInfo;if(!(0,b.validateMnemonic)(t))throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const o=(yield(0,b.mnemonicToSeed)(t)).toString("hex"),s=yield this.KeyTool.deriveSpendingKey(o,this.networkInfo.rpcNode.networkName);if(typeof s!="string")throw new Error("Invalid spendKey type");const a=yield this.getNewWalletBirthdayBlockheight();return{[`${e}Mnemonic`]:t,[`${e}SpendKey`]:s,[`${e}BirthdayHeight`]:a}})}createPrivateKey(t){return f(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=B.Buffer.from(this.io.random(32)).toString("hex"),n=(0,b.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}derivePublicKey(t){return f(this,null,function*(){const{pluginId:e}=this.currencyInfo;if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const n=t.keys[`${e}Mnemonic`];if(typeof n!="string")throw new Error("InvalidMnemonic");const o=(yield(0,b.mnemonicToSeed)(n)).toString("hex"),s=yield this.KeyTool.deriveViewingKey(o,this.networkInfo.rpcNode.networkName);return{publicKey:yield this.AddressTool.deriveShieldedAddress(s.extfvk,this.networkInfo.rpcNode.networkName),unifiedViewingKeys:s}})}parseUri(t,e,n){return f(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{edgeParsedUri:s,edgeParsedUri:{publicAddress:a}}=(0,A.k)(this.currencyInfo,t,o,e!=null?e:this.currencyInfo.currencyCode,n);if(a==null||!(yield this.isValidAddress(a)))throw new Error("InvalidPublicAddressError");return s})}encodeUri(t,e){return f(this,null,function*(){const{pluginId:n}=this.currencyInfo,{nativeAmount:r,currencyCode:o,publicAddress:s}=t;if(!(yield this.isValidAddress(s)))throw new Error("InvalidPublicAddressError");let a;if(r!=null){const w=(0,E.cp)(this.currencyInfo,o!=null?o:this.currencyInfo.currencyCode,e);if(w==null)throw new Error("InternalErrorInvalidCurrencyCode");a=(0,g.div)(r,w.multiplier,18)}return(0,A.Q)(t,`${n}`,a)})}}function S(c){return f(this,null,function*(){return new C(c)})}},52361:function(){},94616:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[159],{79014:function(_,D,d){"use strict";d.d(D,{Q:function(){return M},k:function(){return b}});var m=d(77591),T=d.n(m),U=d(24350),B=d(84564),K=d.n(B),h=d(76714),z=Object.defineProperty,O=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,N=(a,y,f)=>y in a?z(a,y,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[y]=f,A=(a,y)=>{for(var f in y||(y={}))$.call(y,f)&&N(a,f,y[f]);if(O)for(var f of O(y))H.call(y,f)&&N(a,f,y[f]);return a};function b(a,y,f,g,E){const u=A({},K()(y,{},!0)),C=y.startsWith(`${a.pluginId}://`);if(u.protocol!=null&&(u.protocol=u.protocol.replace(":","")),u.protocol!=null&&u.protocol!==""&&!f[u.protocol])throw new Error(`Uri protocol '${u.protocol}' is not supported for ${a.pluginId}.`);if(u.host===""&&u.pathname==="")throw new Error("Path and host not found in uri.");const w={publicAddress:u.host!==""?u.host:u.pathname.split("/")[0]},p=u.query.label,I=u.query.message,x=u.query.category;(p!=null||I!=null||x!=null||C)&&(w.metadata={},w.metadata.name=p,w.metadata.notes=I,w.metadata.category=x,w.metadata.gateway=C!=null?C:!1);const k=u.query.amount;if(k!=null&&typeof k=="string"){g==null&&(g=a.currencyCode);const P=(0,h.cp)(a,g!=null?g:"",E);if(P==null)throw new Error("InternalErrorInvalidCurrencyCode");let S=(0,m.mul)(k,P.multiplier);S=(0,m.toFixed)(S,0,0),w.nativeAmount=S,w.currencyCode=g}return{edgeParsedUri:w,parsedUri:u}}function M(a,y,f){if(a.publicAddress==null)throw new Error("InvalidPublicAddressError");if(f==null&&a.label==null&&a.message==null)return a.publicAddress;{let g="";f!=null&&(g+="amount="+f+"&"),(a.label!=null||a.message!=null)&&(typeof a.label=="string"&&(g+="label="+a.label+"&"),typeof a.message=="string"&&(g+="message="+a.message+"&")),g=g.substr(0,g.length-1);const E={scheme:y,path:a.publicAddress,query:g};return(0,U.qC)(E)}}},940:function(_,D,d){"use strict";d.r(D),d.d(D,{ZcashTools:function(){return P},makeCurrencyEngine:function(){return x},makeCurrencyTools:function(){return S}});var m=d(77591),T=d(2153),U=d(48764),B=d(79014),K=d(76714),h=d(82448),z=d(62177);const O=(0,h.su)({first:h.mH,last:h.mH}),$=(0,h.su)({alias:(0,h.Vk)(h.XC),blockRange:(0,h.Vk)(O,{first:0,last:0})}),H=(0,h.su)({birthdayHeight:h.mH,publicKey:h.XC,unifiedViewingKeys:(0,h.su)({extfvk:h.XC,extpub:h.XC})}),N=(0,z.jd)(H),A=s=>(0,h.W1)(t=>{const e=(0,h.su)({[`${s}Mnemonic`]:h.XC,[`${s}SpendKey`]:h.XC,[`${s}BirthdayHeight`]:h.mH})(t),r={mnemonic:e[`${s}Mnemonic`],spendKey:e[`${s}SpendKey`],birthdayHeight:e[`${s}BirthdayHeight`]};return(0,h.su)({mnemonic:h.XC,spendKey:h.XC,birthdayHeight:h.mH})(r)},t=>({[`${s}Mnemonic`]:t.mnemonic,[`${s}SpendKey`]:t.spendKey,[`${s}BirthdayHeight`]:t.birthdayHeight}));var b=d(94935),M=d(50244),a=Object.defineProperty,y=Object.getOwnPropertySymbols,f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,u=Reflect.get,C=(s,t,e)=>t in s?a(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,L=(s,t)=>{for(var e in t||(t={}))g.call(t,e)&&C(s,e,t[e]);if(y)for(var e of y(t))E.call(t,e)&&C(s,e,t[e]);return s},w=(s,t,e)=>u(f(s),e,t),p=(s,t,e)=>new Promise((r,n)=>{var l=o=>{try{c(e.next(o))}catch(v){n(v)}},i=o=>{try{c(e.throw(o))}catch(v){n(v)}},c=o=>o.done?r(o.value):Promise.resolve(o.value).then(l,i);c((e=e.apply(s,t)).next())});class I extends M.P{constructor(t,e,r,n,l){super(t,e,r,n);const{networkInfo:i}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=i,this.makeSynchronizer=l}setOtherData(t){this.otherData=$(t)}initData(){const{birthdayHeight:t,alias:e}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.alias=e,this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio=0}initSubscriptions(){this.synchronizer.on("update",t=>p(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:r,networkBlockHeight:n}=t;this.onUpdateBlockHeight(n),this.onUpdateProgress(e,r,n),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>p(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()}))}queryAll(){return p(this,null,function*(){yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,r){if(!this.addressesChecked&&!this.isSynced()){this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=e*.99/100;let n=0;if(t>0){const i=r-t;this.initialNumBlocksToDownload<0&&(this.initialNumBlocksToDownload=i),n=i===0||this.initialNumBlocksToDownload===0?1:1-i/this.initialNumBlocksToDownload}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=n*.8;const l=(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]+this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode])/2;l!==this.progressRatio&&(Math.abs(l-this.progressRatio)>.1||l===1)&&(this.progressRatio=l,this.updateOnAddressesChecked())}}startEngine(){return p(this,null,function*(){this.initData(),this.synchronizer=yield this.makeSynchronizer(this.initializer),yield this.synchronizer.start(),this.initSubscriptions(),yield w(I.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return p(this,null,function*(){if(!!this.isSynced())try{const t=yield this.synchronizer.getShieldedBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return p(this,null,function*(){try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(n=>this.processTransaction(n)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const r=[];t.toAddress!=null?e=`-${(0,m.add)(e,this.networkInfo.defaultNetworkFee)}`:r.push(this.walletInfo.keys.publicKey);const n={txid:t.rawTransactionId,date:t.blockTimeInSeconds,currencyCode:this.currencyInfo.currencyCode,blockHeight:t.minedHeight,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:r,signedTx:"",otherParams:{},walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,n)}killEngine(){return p(this,null,function*(){yield this.synchronizer.stop(),yield w(I.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return p(this,null,function*(){yield w(I.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield w(I.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),this.synchronizer.rescan(this.walletInfo.keys.birthdayHeight).catch(t=>this.warn("resyncBlockchain failed: ",t))})}getMaxSpendable(){return p(this,null,function*(){const t=(0,m.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,m.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return p(this,null,function*(){var e;if(!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:r,currencyCode:n}=this.makeSpendCheck(t),l=r.spendTargets[0],{publicAddress:i,nativeAmount:c}=l;if(i==null)throw new Error("makeSpend Missing publicAddress");if(c==null)throw new b.$D;if((0,m.eq)(c,"0"))throw new b.$D;const o=(0,m.add)(c,this.networkInfo.defaultNetworkFee);if((0,m.gt)(o,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,m.gt)(o,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const v=r.spendTargets.map(R=>{var V;return{uniqueIdentifier:R.uniqueIdentifier,memo:R.memo,nativeAmount:(V=R.nativeAmount)!=null?V:"0",currencyCode:n,publicAddress:i}});return{txid:"",date:0,currencyCode:n,blockHeight:0,nativeAmount:`-${o}`,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",spendTargets:v,walletId:this.walletId}})}signTx(t){return p(this,null,function*(){return t})}broadcastTx(t,e){return p(this,null,function*(){var r,n;const l=A(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const i=t.spendTargets[0],c={zatoshi:(0,m.sub)((0,m.abs)(t.nativeAmount),t.networkFee),toAddress:i.publicAddress,memo:(n=(r=i.memo)!=null?r:i.uniqueIdentifier)!=null?n:"",fromAccountIndex:0,spendingKey:l.spendKey};try{const o=yield this.synchronizer.sendToAddress(c);t.txid=o.txId,t.signedTx=o.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
+ ${(0,K.oX)(t)}`)}catch(o){throw this.warn("FAILURE broadcastTx failed: ",o),o}return t})}getDisplayPrivateSeed(t){return A(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){var t,e;return(e=(t=this.walletInfo.keys.unifiedViewingKeys)==null?void 0:t.extfvk)!=null?e:""}loadEngine(t,e,r){return p(this,null,function*(){yield w(I.prototype,this,"loadEngine").call(this,t,e,r),this.engineOn=!0;const{rpcNode:n}=this.networkInfo;this.initializer=L({fullViewingKey:e.keys.unifiedViewingKeys,birthdayHeight:e.keys.birthdayHeight,alias:e.keys.publicKey},n)})}}function x(s,t,e,r){return p(this,null,function*(){const n=N(e),{makeSynchronizer:l}=s.nativeIo["edge-currency-accountbased"][s.networkInfo.nativeSdk],i=new I(s,t,n,r,l);return yield i.loadEngine(t,n,r),i})}var k=(s,t,e)=>new Promise((r,n)=>{var l=o=>{try{c(e.next(o))}catch(v){n(v)}},i=o=>{try{c(e.throw(o))}catch(v){n(v)}},c=o=>o.done?r(o.value):Promise.resolve(o.value).then(l,i);c((e=e.apply(s,t)).next())});class P{constructor(t){const{builtinTokens:e,currencyInfo:r,io:n,networkInfo:l}=t;this.builtinTokens=e,this.currencyInfo=r,this.io=n,this.networkInfo=l;const i=t.nativeIo["edge-currency-accountbased"];if(i==null)throw new Error("Need opts");const{KeyTool:c,AddressTool:o}=i[this.networkInfo.nativeSdk];this.KeyTool=c,this.AddressTool=o}getNewWalletBirthdayBlockheight(){return k(this,null,function*(){try{return yield this.KeyTool.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)}catch{return this.networkInfo.defaultBirthday}})}isValidAddress(t){return k(this,null,function*(){return(yield this.AddressTool.isValidShieldedAddress(t))||(yield this.AddressTool.isValidTransparentAddress(t))})}importPrivateKey(t){return k(this,null,function*(){const{pluginId:e}=this.currencyInfo;if(!(0,T.validateMnemonic)(t))throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const l=(yield(0,T.mnemonicToSeed)(t)).toString("hex"),i=yield this.KeyTool.deriveSpendingKey(l,this.networkInfo.rpcNode.networkName);if(typeof i!="string")throw new Error("Invalid spendKey type");const c=yield this.getNewWalletBirthdayBlockheight();return{[`${e}Mnemonic`]:t,[`${e}SpendKey`]:i,[`${e}BirthdayHeight`]:c}})}createPrivateKey(t){return k(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=U.Buffer.from(this.io.random(32)).toString("hex"),r=(0,T.entropyToMnemonic)(e);return yield this.importPrivateKey(r)})}checkPublicKey(t){return k(this,null,function*(){try{return H(t),!0}catch{return!1}})}derivePublicKey(t){return k(this,null,function*(){const{pluginId:e}=this.currencyInfo,r=A(e)(t.keys);if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const n=r.mnemonic;if(typeof n!="string")throw new Error("InvalidMnemonic");const i=(yield(0,T.mnemonicToSeed)(n)).toString("hex"),c=yield this.KeyTool.deriveViewingKey(i,this.networkInfo.rpcNode.networkName),o=yield this.AddressTool.deriveShieldedAddress(c.extfvk,this.networkInfo.rpcNode.networkName);return{birthdayHeight:r.birthdayHeight,publicKey:o,unifiedViewingKeys:c}})}parseUri(t,e,r){return k(this,null,function*(){const{pluginId:n}=this.currencyInfo,l={[n]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:c}}=(0,B.k)(this.currencyInfo,t,l,e!=null?e:this.currencyInfo.currencyCode,r);if(c==null||!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t,e){return k(this,null,function*(){const{pluginId:r}=this.currencyInfo,{nativeAmount:n,currencyCode:l,publicAddress:i}=t;if(!(yield this.isValidAddress(i)))throw new Error("InvalidPublicAddressError");let c;if(n!=null){const v=(0,K.cp)(this.currencyInfo,l!=null?l:this.currencyInfo.currencyCode,e);if(v==null)throw new Error("InternalErrorInvalidCurrencyCode");c=(0,m.div)(n,v.multiplier,18)}return(0,B.Q)(t,`${r}`,c)})}}function S(s){return k(this,null,function*(){return new P(s)})}},52361:function(){},94616:function(){}}]);
@@ -8,6 +8,7 @@ var _biggystring = require('biggystring');
8
8
 
9
9
 
10
10
 
11
+
11
12
  var _types = require('edge-core-js/types');
12
13
 
13
14
  var _engine = require('../common/engine');
@@ -30,6 +31,9 @@ var _utils = require('../common/utils');
30
31
 
31
32
 
32
33
 
34
+
35
+
36
+
33
37
  var _bnbTypes = require('./bnbTypes');
34
38
 
35
39
  const ACCOUNT_POLL_MILLISECONDS = 20000
@@ -46,7 +50,10 @@ const NETWORK_FEE_NATIVE_AMOUNT = '37500' // fixed amount for BNB
46
50
 
47
51
 
48
52
 
49
- class BinanceEngine extends _engine.CurrencyEngine {
53
+ class BinanceEngine extends _engine.CurrencyEngine
54
+
55
+
56
+ {
50
57
 
51
58
 
52
59
  constructor(
@@ -446,13 +453,17 @@ const NETWORK_FEE_NATIVE_AMOUNT = '37500' // fixed amount for BNB
446
453
  return edgeTransaction
447
454
  }
448
455
 
449
- async signTx(edgeTransaction) {
456
+ async signTx(
457
+ edgeTransaction,
458
+ privateKeys
459
+ ) {
460
+ const bnbPrivateKeys = _bnbTypes.asBnbPrivateKey.call(void 0, privateKeys)
450
461
  const otherParams = _utils.getOtherParams.call(void 0, edgeTransaction)
451
462
 
452
463
  const bnbClient = new (0, _javascriptsdk.BncClient)(this.networkInfo.binanceApiServers[0])
453
464
  bnbClient.chooseNetwork('mainnet')
454
- const privKey = this.walletInfo.keys.binanceKey
455
- await bnbClient.setPrivateKey(privKey)
465
+ const { binanceKey } = bnbPrivateKeys
466
+ await bnbClient.setPrivateKey(binanceKey)
456
467
  await bnbClient.initChain()
457
468
  const currencyCode = edgeTransaction.currencyCode
458
469
  const spendAmount = _biggystring.add.call(void 0,
@@ -505,20 +516,14 @@ const NETWORK_FEE_NATIVE_AMOUNT = '37500' // fixed amount for BNB
505
516
  return edgeTransaction
506
517
  }
507
518
 
508
- getDisplayPrivateSeed() {
509
- const { keys } = this.walletInfo
510
- if (keys.binanceMnemonic != null) {
511
- return keys.binanceMnemonic
512
- }
513
- return ''
519
+ getDisplayPrivateSeed(privateKeys) {
520
+ const bnbPrivateKey = _bnbTypes.asBnbPrivateKey.call(void 0, privateKeys)
521
+ return bnbPrivateKey.binanceMnemonic
514
522
  }
515
523
 
516
524
  getDisplayPublicSeed() {
517
525
  const { keys } = this.walletInfo
518
- if (keys.publicKey != null) {
519
- return keys.publicKey
520
- }
521
- return ''
526
+ return keys.publicKey
522
527
  }
523
528
  } exports.BinanceEngine = BinanceEngine;
524
529
 
@@ -530,10 +535,17 @@ const NETWORK_FEE_NATIVE_AMOUNT = '37500' // fixed amount for BNB
530
535
  ) {
531
536
  const { initOptions } = env
532
537
 
533
- const engine = new BinanceEngine(env, tools, walletInfo, initOptions, opts)
538
+ const safeWalletInfo = _bnbTypes.asSafeBnbWalletInfo.call(void 0, walletInfo)
539
+ const engine = new BinanceEngine(
540
+ env,
541
+ tools,
542
+ safeWalletInfo,
543
+ initOptions,
544
+ opts
545
+ )
534
546
 
535
547
  // Do any async initialization necessary for the engine
536
- await engine.loadEngine(tools, walletInfo, opts)
548
+ await engine.loadEngine(tools, safeWalletInfo, opts)
537
549
 
538
550
  return engine
539
551
  } exports.makeCurrencyEngine = makeCurrencyEngine;
@@ -7,6 +7,8 @@
7
7
 
8
8
  var _cleaners = require('cleaners');
9
9
 
10
+ var _types = require('../common/types');
11
+
10
12
 
11
13
 
12
14
 
@@ -73,3 +75,12 @@ var _cleaners = require('cleaners');
73
75
 
74
76
 
75
77
 
78
+
79
+
80
+ const asSafeBnbWalletInfo = _types.asSafeCommonWalletInfo; exports.asSafeBnbWalletInfo = asSafeBnbWalletInfo
81
+
82
+
83
+ const asBnbPrivateKey = _cleaners.asObject.call(void 0, {
84
+ binanceKey: _cleaners.asString,
85
+ binanceMnemonic: _cleaners.asString
86
+ }); exports.asBnbPrivateKey = asBnbPrivateKey