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,3 +1,3 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[26],{36048:function($){function g(h){var E=new Error("Cannot find module '"+h+"'");throw E.code="MODULE_NOT_FOUND",E}g.keys=function(){return[]},g.resolve=g,g.id=36048,$.exports=g},59439:function($,g,h){"use strict";h.r(g),h.d(g,{BinanceTools:function(){return j},makeCurrencyEngine:function(){return O},makeCurrencyTools:function(){return Z}});var E=h(58298),b=h(77591),U=h(2153),R=h(48764),S=h(79014),m=h(76714),D=h(94935),_=h(50244),H=h(62177),a=h(82448);const N=(0,a.su)({sync_info:(0,a.su)({latest_block_height:a.mH})}),F=(0,a.su)({balances:(0,a._2)((0,a.su)({free:a.XC,frozen:a.XC,locked:a.XC,symbol:a.XC}))}),X=(0,a.su)({hash:a.XC,blockHeight:a.mH,blockTime:a.mH,type:a.XC,fee:a.mH,memo:a.XC,asset:a.XC,amount:a.mH,fromAddr:a.XC,toAddr:a.XC}),x=(0,a.su)({txs:(0,a._2)(X)}),u=(0,a.su)({binanceMnemonic:(0,a.Zz)(a.XC),publicKey:(0,a.Zz)(a.XC)}),f=(0,a.su)({result:(0,a._2)((0,a.su)({ok:a.jK,hash:(0,a.Zz)(a.XC)}))});var p=Object.getPrototypeOf,y=Reflect.get,B=(v,e,t)=>y(p(v),t,e),l=(v,e,t)=>new Promise((n,r)=>{var s=o=>{try{i(t.next(o))}catch(d){r(d)}},c=o=>{try{i(t.throw(o))}catch(d){r(d)}},i=o=>o.done?n(o.value):Promise.resolve(o.value).then(s,c);i((t=t.apply(v,e)).next())});const P=2e4,Q=2e4,w=3e3,L=1e3*60*60*24,K=15555e8,M=1e3*60*60*24*5,A="37500";class C extends _.P{constructor(e,t,n,r,s){super(e,t,n,s),this.networkInfo=e.networkInfo}setOtherData(e){this.otherData={}}fetchGet(e){return l(this,null,function*(){const t=yield this.io.fetch(e,{method:"GET"});if(!t.ok)throw new Error(`The server returned error code ${t.status} for ${e}`);return yield t.json()})}fetchCorsGet(e){return l(this,null,function*(){var t;const r=yield((t=this.io.fetchCors)!=null?t:this.io.fetch)(e,{method:"GET"});if(!r.ok)throw new Error(`The server returned error code ${r.status} for ${e}`);return yield r.json()})}checkBlockchainInnerLoop(){return l(this,null,function*(){try{const e=yield this.multicastServers("bnb_blockNumber","/api/v1/node-info"),n=N(e).sync_info.latest_block_height;this.log(`Got block height ${n}`),this.walletLocalData.blockHeight!==n&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=n,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(e){this.error("Error fetching height: ",e.message)}})}checkAccountInnerLoop(){return l(this,null,function*(){const e=this.walletLocalData.publicKey;try{const t=yield this.multicastServers("bnb_getBalance",`/api/v1/account/${e}`),n=F(t);n.balances.length===0&&this.updateBalance("BNB","0");for(const r of this.enabledTokens)for(const s of n.balances)if(s.symbol===r){const c=(0,m.cp)(this.currencyInfo,r);if(c==null){this.error(`checkAccountInnerLoop Received unsupported currencyCode: ${r}`);break}const i=(0,b.mul)(s.free,c.multiplier);this.updateBalance(r,i)}}catch{this.tokenCheckTransactionsStatus.BNB===1&&this.transactionList.BNB.length===0&&this.updateBalance("BNB","0"),this.error("Error checking BNB address balance")}})}processBinanceApiTransaction(e,t){if(t!==e.asset||e.type!=="TRANSFER")return;let n;const r=[],s=String(e.fee),c=String(e.amount);e.fromAddr.toLowerCase()===this.walletLocalData.publicKey.toLowerCase()?e.fromAddr.toLowerCase()===e.toAddr.toLowerCase()?n=(0,b.mul)(s,"-1"):(n=(0,b.sub)("0",c),n=(0,b.sub)(n,s)):(n=(0,b.add)("0",c),r.push(this.walletLocalData.publicKey.toLowerCase()));let i=e.blockHeight;i<0&&(i=0);const o=new Date(e.blockTime),d={txid:e.hash,date:o.getTime(),currencyCode:t,blockHeight:i,nativeAmount:n,networkFee:s,ourReceiveAddresses:r,signedTx:"",metadata:{notes:e.memo},walletId:this.walletId};this.addTransaction(t,d)}checkTransactionsFetch(e,t){return l(this,null,function*(){const n=this.walletLocalData.publicKey;let r=e,s=0;const c=Date.now();try{for(;s!==c;){s=r+M,s>c&&(s=c);const o=`/bc/api/v1/txs?address=${n}`+`&startTime=${r}&endTime=${s}`,d=yield this.multicastServers("bnb_getTransactions",o),T=x(d);for(const I of T.txs)this.processBinanceApiTransaction(I,t);r=s}}catch(i){if(!(0,H.Tt)(i).message.includes("404"))return this.error(`Error checkTransactionsFetch ${t}: ${this.walletLocalData.publicKey}`,i),!1}return this.tokenCheckTransactionsStatus[t]=1,this.updateOnAddressesChecked(),!0})}checkTransactionsInnerLoop(){return l(this,null,function*(){const e=Date.now();let t=K;const n=[];this.walletLocalData.lastAddressQueryHeight>L&&(t=this.walletLocalData.lastAddressQueryHeight-L);for(const c of this.enabledTokens)n.push(this.checkTransactionsFetch(t,c));let r=[];try{r=yield Promise.all(n)}catch(c){this.error("Failed to query transactions ",c)}let s=0;for(const c of r)c&&s++;s===n.length&&(this.walletLocalData.lastAddressQueryHeight=e),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}multicastServers(e,...t){return l(this,null,function*(){let n={result:"",server:"no server"},r;switch(e){case"bnb_broadcastTx":{const s=[],c=this.networkInfo.binanceApiServers;for(const d of c){const T=`${d}/api/v1/broadcast?sync=true`;s.push(this.io.fetch(T,{method:"POST",body:t[0],headers:{"content-type":"text/plain"}}))}const o=yield(yield(0,m.Wp)(s)).json();if(o[0]&&o[0].ok&&o[0].code===0)return this.log(`multicastServers ${e} ${JSON.stringify(n)} won`),{result:o,server:"irrelevant"};throw new Error(`send fail with error: ${o.message}`)}case"bnb_blockNumber":case"bnb_getBalance":r=this.networkInfo.binanceApiServers.map(s=>()=>l(this,null,function*(){const c=t[0],i=yield this.fetchGet(s+c);if(typeof i!="object"){const o=`Invalid return value ${e} in ${s}`;throw this.error(o),new Error(o)}return{server:s,result:i}})),r=(0,m.Sy)(r),n=yield(0,m.QJ)(r);break;case"bnb_getTransactions":r=this.networkInfo.beaconChainApiServers.map(s=>()=>l(this,null,function*(){const c=t[0],i=yield this.fetchCorsGet(s+c);if(typeof i!="object"){const o=`Invalid return value ${e} in ${s}`;throw this.error(o),new Error(o)}return{server:s,result:i}})),r=(0,m.Sy)(r),n=yield(0,m.QJ)(r);break}return this.log(`multicastServers ${e} ${n.server} won`),n.result})}startEngine(){return l(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",Q).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",P).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",w).catch(()=>{}),yield B(C.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return l(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(e){return l(this,null,function*(){var t,n;const{edgeSpendInfo:r,currencyCode:s}=this.makeSpendCheck(e),c=r.spendTargets[0],{publicAddress:i}=c;let{nativeAmount:o}=c;if(i==null)throw new Error("makeSpend Missing publicAddress");if(o==null)throw new D.$D;const d=c.otherParams!=null?c.otherParams.data:void 0,T={from:[this.walletLocalData.publicKey],to:[i],errorVal:0,tokenRecipientAddress:null,data:d};if(s!==this.currencyInfo.currencyCode)throw new Error("Binance Beacon Chain token transfers not supported");((t=r.spendTargets[0].otherParams)==null?void 0:t.uniqueIdentifier)!=null&&(T.memo=r.spendTargets[0].otherParams.uniqueIdentifier);const I=A,Y=new Error("Insufficient BNB for transaction fee");Y.name="ErrorInsufficientFundsMoreBnb";const q=(n=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?n:"0";let G="0";if(G=(0,b.add)(o,I),(0,b.gt)(G,q))throw new D.C_;return o=(0,b.mul)(G,"-1"),{txid:"",date:0,currencyCode:s,blockHeight:0,nativeAmount:o,networkFee:I,ourReceiveAddresses:[],signedTx:"",otherParams:T,walletId:this.walletId}})}signTx(e){return l(this,null,function*(){const t=(0,m.Xp)(e),n=new E.TR(this.networkInfo.binanceApiServers[0]);n.chooseNetwork("mainnet");const r=this.walletInfo.keys.binanceKey;yield n.setPrivateKey(r),yield n.initChain();const s=e.currencyCode,i=(0,b.add)(e.nativeAmount,A).replace("-",""),o=(0,m.cp)(this.currencyInfo,s);if(o==null)throw this.error(`signTx Received unsupported currencyCode: ${s}`),new Error(`Received unsupported currencyCode: ${s}`);const d=parseInt(i)/parseInt(o.multiplier);n._broadcastDelegate=I=>I;const T=yield n.transfer(t.from[0],t.to[0],d,s,t.memo);return t.serializedTx=T.serialize(),this.warn(`signTx
2
- ${(0,m.oX)(e)}`),e})}broadcastTx(e){return l(this,null,function*(){var t,n;const s=(0,m.Xp)(e).serializedTx,c=yield this.multicastServers("bnb_broadcastTx",s),i=f(c);return(t=i.result[0])!=null&&t.ok&&(this.warn(`SUCCESS broadcastTx
3
- ${(0,m.oX)(e)}`),e.txid=(n=i.result[0].hash)!=null?n:""),e})}getDisplayPrivateSeed(){const{keys:e}=this.walletInfo;return e.binanceMnemonic!=null?e.binanceMnemonic:""}getDisplayPublicSeed(){const{keys:e}=this.walletInfo;return e.publicKey!=null?e.publicKey:""}}function O(v,e,t,n){return l(this,null,function*(){const{initOptions:r}=v,s=new C(v,e,t,r,n);return yield s.loadEngine(e,t,n),s})}var k=(v,e,t)=>new Promise((n,r)=>{var s=o=>{try{i(t.next(o))}catch(d){r(d)}},c=o=>{try{i(t.throw(o))}catch(d){r(d)}},i=o=>o.done?n(o.value):Promise.resolve(o.value).then(s,c);i((t=t.apply(v,e)).next())});const{checkAddress:z,getAddressFromPrivateKey:V,getPrivateKeyFromMnemonic:W,validateMnemonic:J}=E.eL;class j{constructor(e){const{builtinTokens:t,currencyInfo:n,io:r,networkInfo:s}=e;this.builtinTokens=t,this.currencyInfo=n,this.io=r,this.networkInfo=s}importPrivateKey(e){return k(this,null,function*(){if(!J(e))throw new Error("Invalid BNB mnemonic");const n=W(e);return{binanceMnemonic:e,binanceKey:n}})}createPrivateKey(e){return k(this,null,function*(){if(e.replace("wallet:","")==="binance"){const n=R.Buffer.from(this.io.random(32)).toString("hex"),r=(0,U.entropyToMnemonic)(n),s=W(r);return{binanceMnemonic:r,binanceKey:s}}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return k(this,null,function*(){if(e.type.replace("wallet:","")==="binance"){let n="",r=e.keys.binanceKey;return typeof r!="string"&&(r=W(e.keys.binanceMnemonic)),n=V(r,"bnb"),{publicKey:n}}else throw new Error("InvalidWalletType")})}parseUri(e,t,n){return k(this,null,function*(){var r;const s={binance:!0},{parsedUri:c,edgeParsedUri:i}=(0,S.k)(this.currencyInfo,e,s,t!=null?t:"BNB",n),o=(r=i.publicAddress)!=null?r:"";if(!z(o,"bnb"))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=c.query.memo,i})}encodeUri(e,t){return k(this,null,function*(){const{publicAddress:n,nativeAmount:r,currencyCode:s}=e;if(!z(n,"bnb"))throw new Error("InvalidPublicAddressError");let i;if(typeof r=="string"){const d=(0,m.cp)(this.currencyInfo,s!=null?s:"BNB",t);if(d==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,b.div)(r,d.multiplier,18)}return(0,S.Q)(e,"binance",i)})}}function Z(v){return k(this,null,function*(){return new j(v)})}},79014:function($,g,h){"use strict";h.d(g,{Q:function(){return x},k:function(){return X}});var E=h(77591),b=h.n(E),U=h(24350),R=h(84564),S=h.n(R),m=h(76714),D=Object.defineProperty,_=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,N=(u,f,p)=>f in u?D(u,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):u[f]=p,F=(u,f)=>{for(var p in f||(f={}))H.call(f,p)&&N(u,p,f[p]);if(_)for(var p of _(f))a.call(f,p)&&N(u,p,f[p]);return u};function X(u,f,p,y,B){const l=F({},S()(f,{},!0)),P=f.startsWith(`${u.pluginId}://`);if(l.protocol!=null&&(l.protocol=l.protocol.replace(":","")),l.protocol!=null&&l.protocol!==""&&!p[l.protocol])throw new Error(`Uri protocol '${l.protocol}' is not supported for ${u.pluginId}.`);if(l.host===""&&l.pathname==="")throw new Error("Path and host not found in uri.");const w={publicAddress:l.host!==""?l.host:l.pathname.split("/")[0]},L=l.query.label,K=l.query.message,M=l.query.category;(L!=null||K!=null||M!=null||P)&&(w.metadata={},w.metadata.name=L,w.metadata.notes=K,w.metadata.category=M,w.metadata.gateway=P!=null?P:!1);const A=l.query.amount;if(A!=null&&typeof A=="string"){y==null&&(y=u.currencyCode);const C=(0,m.cp)(u,y!=null?y:"",B);if(C==null)throw new Error("InternalErrorInvalidCurrencyCode");let O=(0,E.mul)(A,C.multiplier);O=(0,E.toFixed)(O,0,0),w.nativeAmount=O,w.currencyCode=y}return{edgeParsedUri:w,parsedUri:l}}function x(u,f,p){if(u.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&u.label==null&&u.message==null)return u.publicAddress;{let y="";p!=null&&(y+="amount="+p+"&"),(u.label!=null||u.message!=null)&&(typeof u.label=="string"&&(y+="label="+u.label+"&"),typeof u.message=="string"&&(y+="message="+u.message+"&")),y=y.substr(0,y.length-1);const B={scheme:f,path:u.publicAddress,query:y};return(0,U.qC)(B)}}},89214:function(){},71156:function(){},52361:function(){},94616:function(){},83954:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[26],{36048:function(R){function w(u){var T=new Error("Cannot find module '"+u+"'");throw T.code="MODULE_NOT_FOUND",T}w.keys=function(){return[]},w.resolve=w,w.id=36048,R.exports=w},59439:function(R,w,u){"use strict";u.r(w),u.d(w,{BinanceTools:function(){return Z},makeCurrencyEngine:function(){return Y},makeCurrencyTools:function(){return te}});var T=u(58298),v=u(77591),H=u(2153),X=u(48764),S=u(79014),b=u(76714),D=u(94935),_=u(50244),K=u(62177),c=u(82448);const N=(0,c.su)({sync_info:(0,c.su)({latest_block_height:c.mH})}),F=(0,c.su)({balances:(0,c._2)((0,c.su)({free:c.XC,frozen:c.XC,locked:c.XC,symbol:c.XC}))}),x=(0,c.su)({hash:c.XC,blockHeight:c.mH,blockTime:c.mH,type:c.XC,fee:c.mH,memo:c.XC,asset:c.XC,amount:c.mH,fromAddr:c.XC,toAddr:c.XC}),W=(0,c.su)({txs:(0,c._2)(x)}),l=(0,c.su)({binanceMnemonic:(0,c.Zz)(c.XC),publicKey:(0,c.Zz)(c.XC)}),f=(0,c.su)({result:(0,c._2)((0,c.su)({ok:c.jK,hash:(0,c.Zz)(c.XC)}))}),p=K.BQ,y=(0,c.su)({binanceKey:c.XC,binanceMnemonic:c.XC});var B=Object.getPrototypeOf,h=Reflect.get,P=(g,e,n)=>h(B(g),n,e),m=(g,e,n)=>new Promise((r,t)=>{var s=i=>{try{o(n.next(i))}catch(d){t(d)}},a=i=>{try{o(n.throw(i))}catch(d){t(d)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,a);o((n=n.apply(g,e)).next())});const E=2e4,M=2e4,$=3e3,L=1e3*60*60*24,O=15555e8,U=1e3*60*60*24*5,A="37500";class G extends _.P{constructor(e,n,r,t,s){super(e,n,r,s),this.networkInfo=e.networkInfo}setOtherData(e){this.otherData={}}fetchGet(e){return m(this,null,function*(){const n=yield this.io.fetch(e,{method:"GET"});if(!n.ok)throw new Error(`The server returned error code ${n.status} for ${e}`);return yield n.json()})}fetchCorsGet(e){return m(this,null,function*(){var n;const t=yield((n=this.io.fetchCors)!=null?n:this.io.fetch)(e,{method:"GET"});if(!t.ok)throw new Error(`The server returned error code ${t.status} for ${e}`);return yield t.json()})}checkBlockchainInnerLoop(){return m(this,null,function*(){try{const e=yield this.multicastServers("bnb_blockNumber","/api/v1/node-info"),r=N(e).sync_info.latest_block_height;this.log(`Got block height ${r}`),this.walletLocalData.blockHeight!==r&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(e){this.error("Error fetching height: ",e.message)}})}checkAccountInnerLoop(){return m(this,null,function*(){const e=this.walletLocalData.publicKey;try{const n=yield this.multicastServers("bnb_getBalance",`/api/v1/account/${e}`),r=F(n);r.balances.length===0&&this.updateBalance("BNB","0");for(const t of this.enabledTokens)for(const s of r.balances)if(s.symbol===t){const a=(0,b.cp)(this.currencyInfo,t);if(a==null){this.error(`checkAccountInnerLoop Received unsupported currencyCode: ${t}`);break}const o=(0,v.mul)(s.free,a.multiplier);this.updateBalance(t,o)}}catch{this.tokenCheckTransactionsStatus.BNB===1&&this.transactionList.BNB.length===0&&this.updateBalance("BNB","0"),this.error("Error checking BNB address balance")}})}processBinanceApiTransaction(e,n){if(n!==e.asset||e.type!=="TRANSFER")return;let r;const t=[],s=String(e.fee),a=String(e.amount);e.fromAddr.toLowerCase()===this.walletLocalData.publicKey.toLowerCase()?e.fromAddr.toLowerCase()===e.toAddr.toLowerCase()?r=(0,v.mul)(s,"-1"):(r=(0,v.sub)("0",a),r=(0,v.sub)(r,s)):(r=(0,v.add)("0",a),t.push(this.walletLocalData.publicKey.toLowerCase()));let o=e.blockHeight;o<0&&(o=0);const i=new Date(e.blockTime),d={txid:e.hash,date:i.getTime(),currencyCode:n,blockHeight:o,nativeAmount:r,networkFee:s,ourReceiveAddresses:t,signedTx:"",metadata:{notes:e.memo},walletId:this.walletId};this.addTransaction(n,d)}checkTransactionsFetch(e,n){return m(this,null,function*(){const r=this.walletLocalData.publicKey;let t=e,s=0;const a=Date.now();try{for(;s!==a;){s=t+U,s>a&&(s=a);const i=`/bc/api/v1/txs?address=${r}`+`&startTime=${t}&endTime=${s}`,d=yield this.multicastServers("bnb_getTransactions",i),C=W(d);for(const I of C.txs)this.processBinanceApiTransaction(I,n);t=s}}catch(o){if(!(0,K.Tt)(o).message.includes("404"))return this.error(`Error checkTransactionsFetch ${n}: ${this.walletLocalData.publicKey}`,o),!1}return this.tokenCheckTransactionsStatus[n]=1,this.updateOnAddressesChecked(),!0})}checkTransactionsInnerLoop(){return m(this,null,function*(){const e=Date.now();let n=O;const r=[];this.walletLocalData.lastAddressQueryHeight>L&&(n=this.walletLocalData.lastAddressQueryHeight-L);for(const a of this.enabledTokens)r.push(this.checkTransactionsFetch(n,a));let t=[];try{t=yield Promise.all(r)}catch(a){this.error("Failed to query transactions ",a)}let s=0;for(const a of t)a&&s++;s===r.length&&(this.walletLocalData.lastAddressQueryHeight=e),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}multicastServers(e,...n){return m(this,null,function*(){let r={result:"",server:"no server"},t;switch(e){case"bnb_broadcastTx":{const s=[],a=this.networkInfo.binanceApiServers;for(const d of a){const C=`${d}/api/v1/broadcast?sync=true`;s.push(this.io.fetch(C,{method:"POST",body:n[0],headers:{"content-type":"text/plain"}}))}const i=yield(yield(0,b.Wp)(s)).json();if(i[0]&&i[0].ok&&i[0].code===0)return this.log(`multicastServers ${e} ${JSON.stringify(r)} won`),{result:i,server:"irrelevant"};throw new Error(`send fail with error: ${i.message}`)}case"bnb_blockNumber":case"bnb_getBalance":t=this.networkInfo.binanceApiServers.map(s=>()=>m(this,null,function*(){const a=n[0],o=yield this.fetchGet(s+a);if(typeof o!="object"){const i=`Invalid return value ${e} in ${s}`;throw this.error(i),new Error(i)}return{server:s,result:o}})),t=(0,b.Sy)(t),r=yield(0,b.QJ)(t);break;case"bnb_getTransactions":t=this.networkInfo.beaconChainApiServers.map(s=>()=>m(this,null,function*(){const a=n[0],o=yield this.fetchCorsGet(s+a);if(typeof o!="object"){const i=`Invalid return value ${e} in ${s}`;throw this.error(i),new Error(i)}return{server:s,result:o}})),t=(0,b.Sy)(t),r=yield(0,b.QJ)(t);break}return this.log(`multicastServers ${e} ${r.server} won`),r.result})}startEngine(){return m(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",M).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",E).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",$).catch(()=>{}),yield P(G.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return m(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(e){return m(this,null,function*(){var n,r;const{edgeSpendInfo:t,currencyCode:s}=this.makeSpendCheck(e),a=t.spendTargets[0],{publicAddress:o}=a;let{nativeAmount:i}=a;if(o==null)throw new Error("makeSpend Missing publicAddress");if(i==null)throw new D.$D;const d=a.otherParams!=null?a.otherParams.data:void 0,C={from:[this.walletLocalData.publicKey],to:[o],errorVal:0,tokenRecipientAddress:null,data:d};if(s!==this.currencyInfo.currencyCode)throw new Error("Binance Beacon Chain token transfers not supported");((n=t.spendTargets[0].otherParams)==null?void 0:n.uniqueIdentifier)!=null&&(C.memo=t.spendTargets[0].otherParams.uniqueIdentifier);const I=A,z=new Error("Insufficient BNB for transaction fee");z.name="ErrorInsufficientFundsMoreBnb";const j=(r=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?r:"0";let V="0";if(V=(0,v.add)(i,I),(0,v.gt)(V,j))throw new D.C_;return i=(0,v.mul)(V,"-1"),{txid:"",date:0,currencyCode:s,blockHeight:0,nativeAmount:i,networkFee:I,ourReceiveAddresses:[],signedTx:"",otherParams:C,walletId:this.walletId}})}signTx(e,n){return m(this,null,function*(){const r=y(n),t=(0,b.Xp)(e),s=new T.TR(this.networkInfo.binanceApiServers[0]);s.chooseNetwork("mainnet");const{binanceKey:a}=r;yield s.setPrivateKey(a),yield s.initChain();const o=e.currencyCode,d=(0,v.add)(e.nativeAmount,A).replace("-",""),C=(0,b.cp)(this.currencyInfo,o);if(C==null)throw this.error(`signTx Received unsupported currencyCode: ${o}`),new Error(`Received unsupported currencyCode: ${o}`);const I=parseInt(d)/parseInt(C.multiplier);s._broadcastDelegate=j=>j;const z=yield s.transfer(t.from[0],t.to[0],I,o,t.memo);return t.serializedTx=z.serialize(),this.warn(`signTx
2
+ ${(0,b.oX)(e)}`),e})}broadcastTx(e){return m(this,null,function*(){var n,r;const s=(0,b.Xp)(e).serializedTx,a=yield this.multicastServers("bnb_broadcastTx",s),o=f(a);return(n=o.result[0])!=null&&n.ok&&(this.warn(`SUCCESS broadcastTx
3
+ ${(0,b.oX)(e)}`),e.txid=(r=o.result[0].hash)!=null?r:""),e})}getDisplayPrivateSeed(e){return y(e).binanceMnemonic}getDisplayPublicSeed(){const{keys:e}=this.walletInfo;return e.publicKey}}function Y(g,e,n,r){return m(this,null,function*(){const{initOptions:t}=g,s=p(n),a=new G(g,e,s,t,r);return yield a.loadEngine(e,s,r),a})}var k=(g,e,n)=>new Promise((r,t)=>{var s=i=>{try{o(n.next(i))}catch(d){t(d)}},a=i=>{try{o(n.throw(i))}catch(d){t(d)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,a);o((n=n.apply(g,e)).next())});const{checkAddress:J,getAddressFromPrivateKey:q,getPrivateKeyFromMnemonic:Q,validateMnemonic:ee}=T.eL;class Z{constructor(e){const{builtinTokens:n,currencyInfo:r,io:t,networkInfo:s}=e;this.builtinTokens=n,this.currencyInfo=r,this.io=t,this.networkInfo=s}importPrivateKey(e){return k(this,null,function*(){if(!ee(e))throw new Error("Invalid BNB mnemonic");const r=Q(e);return{binanceMnemonic:e,binanceKey:r}})}createPrivateKey(e){return k(this,null,function*(){if(e.replace("wallet:","")==="binance"){const r=X.Buffer.from(this.io.random(32)).toString("hex"),t=(0,H.entropyToMnemonic)(r),s=Q(t);return{binanceMnemonic:t,binanceKey:s}}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return k(this,null,function*(){if(e.type.replace("wallet:","")==="binance"){let r="",t=e.keys.binanceKey;return typeof t!="string"&&(t=Q(e.keys.binanceMnemonic)),r=q(t,"bnb"),{publicKey:r}}else throw new Error("InvalidWalletType")})}parseUri(e,n,r){return k(this,null,function*(){var t;const s={binance:!0},{parsedUri:a,edgeParsedUri:o}=(0,S.k)(this.currencyInfo,e,s,n!=null?n:"BNB",r),i=(t=o.publicAddress)!=null?t:"";if(!J(i,"bnb"))throw new Error("InvalidPublicAddressError");return o.uniqueIdentifier=a.query.memo,o})}encodeUri(e,n){return k(this,null,function*(){const{publicAddress:r,nativeAmount:t,currencyCode:s}=e;if(!J(r,"bnb"))throw new Error("InvalidPublicAddressError");let o;if(typeof t=="string"){const d=(0,b.cp)(this.currencyInfo,s!=null?s:"BNB",n);if(d==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,v.div)(t,d.multiplier,18)}return(0,S.Q)(e,"binance",o)})}}function te(g){return k(this,null,function*(){return new Z(g)})}},79014:function(R,w,u){"use strict";u.d(w,{Q:function(){return W},k:function(){return x}});var T=u(77591),v=u.n(T),H=u(24350),X=u(84564),S=u.n(X),b=u(76714),D=Object.defineProperty,_=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable,N=(l,f,p)=>f in l?D(l,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[f]=p,F=(l,f)=>{for(var p in f||(f={}))K.call(f,p)&&N(l,p,f[p]);if(_)for(var p of _(f))c.call(f,p)&&N(l,p,f[p]);return l};function x(l,f,p,y,B){const h=F({},S()(f,{},!0)),P=f.startsWith(`${l.pluginId}://`);if(h.protocol!=null&&(h.protocol=h.protocol.replace(":","")),h.protocol!=null&&h.protocol!==""&&!p[h.protocol])throw new Error(`Uri protocol '${h.protocol}' is not supported for ${l.pluginId}.`);if(h.host===""&&h.pathname==="")throw new Error("Path and host not found in uri.");const E={publicAddress:h.host!==""?h.host:h.pathname.split("/")[0]},M=h.query.label,$=h.query.message,L=h.query.category;(M!=null||$!=null||L!=null||P)&&(E.metadata={},E.metadata.name=M,E.metadata.notes=$,E.metadata.category=L,E.metadata.gateway=P!=null?P:!1);const O=h.query.amount;if(O!=null&&typeof O=="string"){y==null&&(y=l.currencyCode);const U=(0,b.cp)(l,y!=null?y:"",B);if(U==null)throw new Error("InternalErrorInvalidCurrencyCode");let A=(0,T.mul)(O,U.multiplier);A=(0,T.toFixed)(A,0,0),E.nativeAmount=A,E.currencyCode=y}return{edgeParsedUri:E,parsedUri:h}}function W(l,f,p){if(l.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&l.label==null&&l.message==null)return l.publicAddress;{let y="";p!=null&&(y+="amount="+p+"&"),(l.label!=null||l.message!=null)&&(typeof l.label=="string"&&(y+="label="+l.label+"&"),typeof l.message=="string"&&(y+="message="+l.message+"&")),y=y.substr(0,y.length-1);const B={scheme:f,path:l.publicAddress,query:y};return(0,H.qC)(B)}}},89214:function(){},71156:function(){},52361:function(){},94616:function(){},83954:function(){}}]);