edge-currency-accountbased 2.2.3 → 2.2.5
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.
- package/CHANGELOG.md +14 -0
- package/android/src/main/assets/edge-currency-accountbased/1944.chunk.js +4 -0
- package/android/src/main/assets/edge-currency-accountbased/2153.chunk.js +2 -0
- package/android/src/main/assets/edge-currency-accountbased/2821.chunk.js +2 -0
- package/android/src/main/assets/edge-currency-accountbased/2896.chunk.js +35 -0
- package/android/src/main/assets/edge-currency-accountbased/2945.chunk.js +25 -0
- package/android/src/main/assets/edge-currency-accountbased/3491.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{620.chunk.js → 3620.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/{666.chunk.js → 3666.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/3720.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{978.chunk.js → 3978.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/4251.chunk.js +4 -0
- package/android/src/main/assets/edge-currency-accountbased/4431.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/4618.chunk.js +20 -0
- package/android/src/main/assets/edge-currency-accountbased/{627.chunk.js → 4627.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/4650.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{826.chunk.js → 5179.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/{835.chunk.js → 5835.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/5836.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/6266.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/6291.chunk.js +58 -0
- package/android/src/main/assets/edge-currency-accountbased/6341.chunk.js +44 -0
- package/android/src/main/assets/edge-currency-accountbased/7221.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/7428.chunk.js +6 -0
- package/android/src/main/assets/edge-currency-accountbased/{481.chunk.js → 7481.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/7542.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/7786.chunk.js +2 -0
- package/android/src/main/assets/edge-currency-accountbased/8190.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{689.chunk.js → 8689.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/{726.chunk.js → 8726.chunk.js} +1 -1
- package/android/src/main/assets/edge-currency-accountbased/9068.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{223.chunk.js → 9223.chunk.js} +2 -2
- package/android/src/main/assets/edge-currency-accountbased/9539.chunk.js +10 -0
- package/android/src/main/assets/edge-currency-accountbased/{645.chunk.js → 9645.chunk.js} +6 -6
- package/android/src/main/assets/edge-currency-accountbased/9669.chunk.js +7 -0
- package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -18
- package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +5 -5
- package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
- package/lib/ethereum/info/avalancheInfo.js +8 -0
- package/lib/ethereum/info/ethereumInfo.js +8 -0
- package/lib/filecoin/FilecoinEngine.js +112 -79
- package/lib/filecoin/Filfox.js +68 -1
- package/lib/filecoin/filecoinInfo.js +8 -3
- package/lib/filecoin/filecoinTypes.js +1 -6
- package/lib/zcash/ZcashEngine.js +11 -9
- package/package.json +1 -1
- package/android/src/main/assets/edge-currency-accountbased/124.chunk.js +0 -35
- package/android/src/main/assets/edge-currency-accountbased/17.chunk.js +0 -58
- package/android/src/main/assets/edge-currency-accountbased/190.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/221.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/298.chunk.js +0 -44
- package/android/src/main/assets/edge-currency-accountbased/431.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/491.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/539.chunk.js +0 -10
- package/android/src/main/assets/edge-currency-accountbased/542.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/618.chunk.js +0 -20
- package/android/src/main/assets/edge-currency-accountbased/650.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/68.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/720.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/786.chunk.js +0 -2
- package/android/src/main/assets/edge-currency-accountbased/836.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/935.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/944.chunk.js +0 -4
- package/android/src/main/assets/edge-currency-accountbased/945.chunk.js +0 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[5679],{79014:function(ut,H,C){"use strict";C.d(H,{Q:function(){return tt},k:function(){return Y}});var g=C(77591),P=C.n(g),U=C(24350),X=C(84564),m=C.n(X),n=C(76714),V=Object.defineProperty,B=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,J=(p,A,I)=>A in p?V(p,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):p[A]=I,Z=(p,A)=>{for(var I in A||(A={}))Q.call(A,I)&&J(p,I,A[I]);if(B)for(var I of B(A))M.call(A,I)&&J(p,I,A[I]);return p};function Y(p,A,I,T,j=[]){const b=Z({},m()(A,{},!0)),K=A.startsWith(`${p.pluginId}://`);if(b.protocol!=null&&(b.protocol=b.protocol.replace(":","")),b.protocol!=null&&b.protocol!==""&&!I[b.protocol])throw new Error(`Uri protocol '${b.protocol}' is not supported for ${p.pluginId}.`);if(b.host===""&&b.pathname==="")throw new Error("Path and host not found in uri.");const D={publicAddress:b.host!==""?b.host:b.pathname.split("/")[0]},$=b.query.label,F=b.query.message,W=b.query.category;($!=null||F!=null||W!=null||K)&&(D.metadata={},D.metadata.name=$,D.metadata.notes=F,D.metadata.category=W,D.metadata.gateway=K!=null?K:!1);const L=b.query.amount;if(L!=null&&typeof L=="string"){T==null&&(T=p.currencyCode);const q=(0,n.Qs)(T!=null?T:"",p,j);if(q==null)throw new Error("InternalErrorInvalidCurrencyCode");let R=(0,g.mul)(L,q.multiplier);R=(0,g.toFixed)(R,0,0),D.nativeAmount=R,D.currencyCode=T}return{edgeParsedUri:D,parsedUri:b}}function tt(p,A,I){if(p.publicAddress==null)throw new Error("InvalidPublicAddressError");if(I==null&&p.label==null&&p.message==null)return p.publicAddress;{let T="";I!=null&&(T+="amount="+I+"&"),(p.label!=null||p.message!=null)&&(typeof p.label=="string"&&(T+="label="+p.label+"&"),typeof p.message=="string"&&(T+="message="+p.message+"&")),T=T.substr(0,T.length-1);const j={scheme:A,path:p.publicAddress,query:T};return(0,U.qC)(j)}}},58684:function(ut,H,C){"use strict";C.r(H),C.d(H,{EosTools:function(){return ct},checkAddress:function(){return x},getClient:function(){return N},makeCurrencyEngine:function(){return kt},makeCurrencyTools:function(){return Ct}});var g=C(15179),P=C(77591),U=C(20918),X=C(79014),m=C(76714),n=C(82448);const V=(0,n.su)({amount:n.XC,currencyCode:n.XC,expireTime:n.mH,paymentAddress:n.XC}),B=(0,n.su)({result:(0,n.su)(n.jK)}),Q=(0,n.su)({cpu:n.mH,net:n.mH,ram:n.mH}),M=(0,n.su)({trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH,act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:n.XC})})}),J=(0,n.su)({actions:(0,n._2)(M)}),Z=(0,n.su)({account_names:(0,n._2)(n.XC)}),Y=(0,n.su)({trace:(0,n.su)({block:(0,n.su)({num:n.mH,timestamp:n.XC}),id:n.XC,matchingActions:(0,n._2)((0,n.su)({json:(0,n.su)({from:n.XC,memo:n.XC,quantity:n.XC,to:n.XC})}))})}),tt=(0,n.su)({data:(0,n.su)({searchTransactionsBackward:(0,n.su)({results:(0,n._2)(Y)})})}),p=(0,n.su)({errors:(0,n._2)((0,n.su)({message:n.XC,extensions:(0,n.su)({code:n.XC,terminal:n.jK})}))}),A=`
|
|
2
2
|
query ($query: String!, $limit: Int64, $low: Int64, $high: Int64) {
|
|
3
3
|
searchTransactionsBackward(query: $query, lowBlockNum: $low, highBlockNum: $high, limit: $limit) {
|
|
4
4
|
results {
|
|
@@ -15,10 +15,10 @@ query ($query: String!, $limit: Int64, $low: Int64, $high: Int64) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`,I=(0,n.su)({act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:(0,n.Zz)(n.XC)})}),trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH}),T=(0,n.su)({account:n.XC,name:(0,n.Wf)("transfer"),authorization:(0,n.vq)((0,n.su)({actor:n.XC,permission:(0,n.Wf)("active")})),data:(0,n.su)({from:n.XC,to:n.XC,quantity:n.XC,memo:(0,n.Zz)(n.XC)})}),j=(0,n.su)({actions:(0,n._2)(T),signatures:(0,n._2)(n.XC)}),b={structs:[{base:"",name:"transfer",fields:[{name:"from",type:"name"},{name:"to",type:"name"},{name:"quantity",type:"asset"},{name:"memo",type:"string"}]}],actions:[{name:"transfer",type:"transfer",ricardian_contract:""}]},K={structs:[{base:"",name:"powerup",fields:[{name:"payer",type:"name"},{name:"receiver",type:"name"},{name:"days",type:"int32"},{name:"net_frac",type:"int64"},{name:"cpu_frac",type:"int64"},{name:"max_payment",type:"asset"}]}],actions:[{name:"powerup",type:"powerup",ricardian_contract:""}]};var O=C(83718),D=C(51124),$=C(94935),F=C(84564),W=C.n(F),L=C(84650),q=Object.defineProperty,R=Object.defineProperties,lt=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,ht=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,mt=Reflect.get,ot=(w,e,t)=>e in w?q(w,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):w[e]=t,et=(w,e)=>{for(var t in e||(e={}))dt.call(e,t)&&ot(w,t,e[t]);if(rt)for(var t of rt(e))ft.call(e,t)&&ot(w,t,e[t]);return w},nt=(w,e)=>R(w,lt(e)),st=(w,e,t)=>mt(ht(w),t,e),f=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(c){i(c)}},a=s=>{try{u(t.throw(s))}catch(c){i(c)}},u=s=>s.done?o(s.value):Promise.resolve(s.value).then(r,a);u((t=t.apply(w,e)).next())});const pt=1e4,yt=15e3,gt=1e4,wt=!0,vt=!0,it={ramdeathtest:!0,krpj4avazggi:!0,fobleos13125:!0};class G extends L.P{constructor(e,t,o,i){super(e,t,o,i);const{networkInfo:r}=e;this.fetchCors=(0,m.zR)(e.io),this.networkInfo=r,this.activatedAccountsCache={};const{currencyCode:a,denominations:u}=this.currencyInfo;this.referenceBlock={ref_block_num:0,ref_block_prefix:0},this.accountResources={cpu:0,net:0},this.accountNameChecked=!1,this.getResourcesMutex=!1,this.allTokens.push(nt(et({},u[0]),{currencyCode:a,currencyName:a,contractAddress:"eosio.token",denominations:u})),this.otherMethods={getAccountActivationQuote:s=>f(this,null,function*(){const{requestedAccountName:c,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v}=s;if(h==null||c==null)throw new Error("ErrorInvalidParams");if(l==null&&d==null)throw new Error("ErrorInvalidParams");if(!x(c)){const y=new Error("ErrorInvalidAccountName");throw y.name="ErrorInvalidAccountName",y}const k={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({requestedAccountName:c,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v})};try{const y=yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(_=>()=>f(this,null,function*(){const E=`${_}/api/v1/activateAccount`;return yield(yield this.fetchCors(E,k)).json()})),15e3);return V(y)}catch(y){throw this.error("getAccountActivationQuoteError: ",y),new Error("getAccountActivationQuoteError")}})}}setOtherData(e){this.otherData=(0,O.sr)(e)}checkBlockchainInnerLoop(){return f(this,null,function*(){try{const e=yield this.multicastServers("getInfo"),t=e.head_block_num.toNumber();this.walletLocalData.blockHeight!==t&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const o=e.getTransactionHeader();this.referenceBlock={ref_block_num:o.ref_block_num.toNumber(),ref_block_prefix:o.ref_block_prefix.toNumber()}}catch(e){this.error("Error fetching height: ",e)}})}processIncomingTransaction(e){const t=(0,n.Vk)(I)(e);if(t==null)return this.error("Invalid supernode tx"),0;const{act:o,trx_id:i,block_num:r}=t,a=t["@timestamp"],{from:u,to:s,memo:c,symbol:h}=o.data,l=o.data.amount.toString(),d=h,v=[],k=(0,m.aL)(d,this.currencyInfo,this.allTokensMap);if(k==null)return this.log(`processIncomingTransaction Received unsupported currencyCode: ${d}`),0;let y=(0,P.mul)(l,k.multiplier),_="";s===this.otherData.accountName?(_=u,v.push(s),u===this.otherData.accountName&&(y="0")):(_=s,y=`-${y}`);const E={txid:i,date:Date.parse(a)/1e3,currencyCode:d,blockHeight:r>0?r:0,nativeAmount:y,isSend:y.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:v,signedTx:"",otherParams:{},metadata:{name:_,notes:c},walletId:this.walletId};return this.addTransaction(d,E),E.blockHeight}processOutgoingTransaction(e){const t=[],o=e["@timestamp"].includes("Z")?e["@timestamp"]:e["@timestamp"]+"Z",i=Date.parse(o)/1e3,r=e.block_num>0?e.block_num:0;if(e.block_num==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No tx block_num`),0;const a=e.trx_id;if(e.act==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act`),0;if(e.act.name==="transfer"){if(e.act.data==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act.data`),0;const{from:s,to:c,memo:h,amount:l,symbol:d}=e.act.data,v=l.toString(),k=d,y=(0,m.aL)(k,this.currencyInfo,this.allTokensMap);if(y==null)return this.error(`processOutgoingTransaction Received unsupported currencyCode: ${k}`),0;let _=(0,P.mul)(v,y.multiplier);c===this.otherData.accountName?(t.push(c),s===this.otherData.accountName&&(_="0")):_=`-${_}`;const E={txid:a,date:i,currencyCode:k,blockHeight:r,nativeAmount:_,isSend:_.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:t,signedTx:"",metadata:{notes:h},otherParams:{fromAddress:s,toAddress:c},walletId:this.walletId};this.addTransaction(k,E)}return r}checkOutgoingTransactions(e,t){return f(this,null,function*(){var o,i;if(!vt)throw new Error("Dont use full node API");const r=10;let a=0,u=!1,s=(o=this.otherData.lastQueryActionSeq[t])!=null?o:0;for(;!u;){const c={direction:"outgoing",acct:e,currencyCode:t,skip:a,limit:r,low:s+1},h=yield this.multicastServers("getOutgoingTransactions",c);let l=[];if(h.actions!=null&&h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processOutgoingTransaction(v);if(k>s)s=k;else if(k===s&&d===0&&a===0){u=!0;break}}if(l==null||l.length<r)break;a+=10}s>((i=this.otherData.lastQueryActionSeq[t])!=null?i:0)&&(this.otherData.lastQueryActionSeq[t]=s,this.walletLocalDataDirty=!0)})}checkIncomingTransactions(e,t){return f(this,null,function*(){var o,i;if(!wt)throw new Error("Dont use Hyperion API");let r=(o=this.otherData.highestTxHeight[t])!=null?o:0;const a=10;let u=0,s=!1;for(;!s;){this.log("looping through checkIncomingTransactions, newHighestTxHeight: ",r);const c={direction:"incoming",acct:e,currencyCode:t,skip:u,limit:a,low:r+1},h=yield this.multicastServers("getIncomingTransactions",c);let l=[];if(h.actions.sort((d,v)=>v.block_num-d.block_num),h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processIncomingTransaction(v);if(k>r)r=k;else if(k===r&&d===0&&u===0){s=!0;break}}if(l.length===0||l.length<a)break;u+=10}r>((i=this.otherData.highestTxHeight[t])!=null?i:0)&&(this.otherData.highestTxHeight[t]=r,this.walletLocalDataDirty=!0)})}checkTransactionsInnerLoop(){return f(this,null,function*(){if(!this.accountNameChecked)return;const e=this.otherData.accountName;for(const t of this.enabledTokens){try{yield this.checkIncomingTransactions(e,t),yield this.checkOutgoingTransactions(e,t)}catch(o){if(e!==""){this.error("checkTransactionsInnerLoop fetches failed with error: ",o);return}}this.tokenCheckTransactionsStatus[t]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}})}multicastServers(e,...t){return f(this,null,function*(){const{currencyCode:o}=this.currencyInfo;let i={result:"",server:"no server"};switch(e){case"getAccount":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const u=yield N(this.fetchCors,r).v1.chain.get_account(this.otherData.accountName);return{server:r,result:u}})));break}case"getIncomingTransactions":case"getOutgoingTransactions":{const{direction:r,acct:a,currencyCode:u,skip:s,limit:c,low:h}=t[0],l=this.networkInfo.eosHyperionNodes.map(v=>()=>f(this,null,function*(){const k=v+`/v2/history/get_actions?transfer.${r==="outgoing"?"from":"to"}=${a}&transfer.symbol=${u}&skip=${s}&limit=${c}&sort=desc`,y=yield this.fetchCors(k),_=W()(k,{},!0);if(!y.ok)throw this.error(`multicast in / out tx server error: ${v}`),new Error(`The server returned error code ${y.status} for ${_.hostname}`);const E=J(yield y.json());return{server:v,result:E}})),d=this.networkInfo.eosDfuseServers.map(v=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const k=yield this.fetchCors(`${v}/graphql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:A,variables:{query:`${r==="outgoing"?"auth":"receiver"}:${a} action:transfer`,limit:c,low:h}})}),y=(0,n._C)(tt,p)(yield k.json());if("errors"in y)throw this.warn(`dfuse ${v} get transactions failed: ${JSON.stringify(y.errors[0])}`),new Error(y.errors[0].message);const _=y.data.searchTransactionsBackward.results.map(E=>M({trx_id:E.trace.id,"@timestamp":E.trace.block.timestamp,block_num:E.trace.block.num,act:{data:{from:E.trace.matchingActions[0].json.from,to:E.trace.matchingActions[0].json.to,amount:Number(E.trace.matchingActions[0].json.quantity.split(" ")[0]),symbol:E.trace.matchingActions[0].json.quantity.split(" ")[1],memo:E.trace.matchingActions[0].json.memo}}}));return{server:v,result:{actions:_}}}));i=yield(0,m.QJ)([...l,...d]);break}case"getKeyAccounts":{const r=t[0],a=this.networkInfo.eosHyperionNodes.map(s=>()=>f(this,null,function*(){const h=yield N(this.fetchCors,s).v1.history.get_key_accounts(r);if(h.account_names.length===0)throw new Error(`${s} could not find account with public key: ${r}`);return{server:s,result:h.account_names[0].toString()}})),u=this.networkInfo.eosDfuseServers.map(s=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const c=yield this.fetchCors(`${s}/v0/state/key_accounts?public_key=${r}`);if(!c.ok)throw new Error(`${s} get_account failed with ${c.status}`);const h=Z(yield c.json());if(h.account_names.length===0)throw new Error("dfuse returned empty array");return{server:s,result:h.account_names[0]}}));i=yield(0,m.QJ)([...a,...u]);break}case"getCurrencyBalance":{const r=t[0];i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(a=>()=>f(this,null,function*(){const s=yield N(this.fetchCors,a).v1.chain.get_currency_balance(r,this.otherData.accountName);return{server:a,result:s}})));break}case"getInfo":{const{eosNodes:r}=this.networkInfo,a=(0,m.sD)(r,3);i=yield(0,m.QJ)(a.map(u=>()=>f(this,null,function*(){const c=yield N(this.fetchCors,u).v1.chain.get_info();return{server:u,result:c}})));break}case"getPowerUpState":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const a=N(this.fetchCors,r),s=yield new D._B({api:a}).v1.powerup.get_state();return{server:r,result:s}})));break}case"getResourceUsage":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const a=N(this.fetchCors,r),s=yield new D._B({api:a}).getSampledUsage();return{server:r,result:s}})));break}case"transact":{const{eosNodes:r}=this.networkInfo,a=(0,m.sD)(r,30);i=yield(0,m.QJ)(a.map(u=>()=>f(this,null,function*(){const s=t[0],h=yield N(this.fetchCors,u).v1.chain.send_transaction(s);return{server:u,result:h}})));break}}return this.log(`${o} multicastServers ${e} ${i.server} won`),i.result})}checkAccountInnerLoop(){return f(this,null,function*(){var e,t,o,i;const r=this.walletLocalData.publicKey;try{if(it[(e=this.otherData.accountName)!=null?e:""]&&(this.otherData.accountName="",this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged()),this.otherData.accountName===""){const a=yield this.multicastServers("getKeyAccounts",r);a!=null&&it[a]==null&&(this.otherData.accountName=a,this.accountNameChecked=!0,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged())}}catch(a){/get_account failed with 400/.test(a==null?void 0:a.message)?this.accountNameChecked=!0:this.error("getKeyAccounts error: ",a)}try{if(this.otherData.accountName===""){for(const c of this.allTokens)this.updateBalance(c.currencyCode,"0");return}for(const c of this.allTokens)if(this.enabledTokens.includes(c.currencyCode)){const l=(i=(o=(t=(yield this.multicastServers("getCurrencyBalance",c.contractAddress))[0])==null?void 0:t.units)==null?void 0:o.toString())!=null?i:"0";this.updateBalance(c.currencyCode,l)}const a=yield this.multicastServers("getAccount"),{cpu_limit:u,net_limit:s}=a;this.accountResources={cpu:u.available.toNumber(),net:s.available.toNumber()}}catch(a){this.error("Error fetching account: ",a)}})}getResources(e){return f(this,null,function*(){if(this.getResourcesMutex)return;const{cpu:t,net:o}=this.accountResources;if(!(t>500&&o>500)){if(this.otherData.lastFreePowerUp>Date.now()-1e3*60*60*12){const i=(0,m.sD)(this.networkInfo.powerUpServers,1);try{const r=yield this.fetchCors(`${i}/${this.otherData.accountName}`);if(!r.ok)throw new Error(`getResources error ${r.status}`);this.otherData.lastFreePowerUp=Date.now(),this.walletLocalDataDirty=!0,this.log.warn("getResources freePowerUp SUCCESS");return}catch(r){this.log.warn("getResources lastFreePowerUp error",r)}}try{const i=yield this.multicastServers("getPowerUpState"),r=yield this.multicastServers("getResourceUsage"),a=i.cpu.frac(r,1e3),u=i.net.frac(r,1e3),s=[{account:"eosio",name:"powerup",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{payer:this.otherData.accountName,receiver:this.otherData.accountName,days:1,cpu_frac:a,net_frac:u,max_payment:"0.0003 EOS"}}],c={txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:"-3",isSend:!0,networkFee:"0",ourReceiveAddresses:[],signedTx:"",otherParams:{actions:s,signatures:[]},walletId:this.walletId},h=yield this.signTx(c,e);this.getResourcesMutex=!0,yield this.broadcastTx(h,{privateKeys:e}),this.log.warn("getResources purchase SUCCESS")}catch(i){this.log.warn(`getResources purchase FAILURE
|
|
19
|
-
`,i)}finally{this.getResourcesMutex=!1}}})}clearBlockchainCache(){return f(this,null,function*(){this.activatedAccountsCache={},yield st(G.prototype,this,"clearBlockchainCache").call(this),this.otherData.lastQueryActionSeq={},this.otherData.highestTxHeight={},this.otherData.accountName="",this.accountNameChecked=!1})}startEngine(){return f(this,null,function*(){this.engineOn=!0,this.accountNameChecked=this.otherData.accountName!=="",this.addToLoop("checkBlockchainInnerLoop",yt).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",pt).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",gt).catch(()=>{}),yield st(G.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return f(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return f(this,null,function*(){return this.otherData.accountName!=null?{publicAddress:this.otherData.accountName}:{publicAddress:"",publicKey:this.walletInfo.keys.publicKey,ownerPublicKey:this.walletInfo.keys.ownerPublicKey}})}makeSpend(e){return f(this,null,function*(){const{edgeSpendInfo:t,currencyCode:o,nativeBalance:i,denom:r}=this.makeSpendCheck(e),
|
|
18
|
+
`,I=(0,n.su)({act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:(0,n.Zz)(n.XC)})}),trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH}),T=(0,n.su)({account:n.XC,name:(0,n.Wf)("transfer"),authorization:(0,n.vq)((0,n.su)({actor:n.XC,permission:(0,n.Wf)("active")})),data:(0,n.su)({from:n.XC,to:n.XC,quantity:n.XC,memo:(0,n.Zz)(n.XC)})}),j=(0,n.su)({actions:(0,n._2)(T),signatures:(0,n._2)(n.XC)}),b={structs:[{base:"",name:"transfer",fields:[{name:"from",type:"name"},{name:"to",type:"name"},{name:"quantity",type:"asset"},{name:"memo",type:"string"}]}],actions:[{name:"transfer",type:"transfer",ricardian_contract:""}]},K={structs:[{base:"",name:"powerup",fields:[{name:"payer",type:"name"},{name:"receiver",type:"name"},{name:"days",type:"int32"},{name:"net_frac",type:"int64"},{name:"cpu_frac",type:"int64"},{name:"max_payment",type:"asset"}]}],actions:[{name:"powerup",type:"powerup",ricardian_contract:""}]};var O=C(83718),D=C(51124),$=C(94935),F=C(84564),W=C.n(F),L=C(84650),q=Object.defineProperty,R=Object.defineProperties,lt=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,ht=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,mt=Reflect.get,ot=(w,e,t)=>e in w?q(w,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):w[e]=t,et=(w,e)=>{for(var t in e||(e={}))dt.call(e,t)&&ot(w,t,e[t]);if(rt)for(var t of rt(e))ft.call(e,t)&&ot(w,t,e[t]);return w},nt=(w,e)=>R(w,lt(e)),st=(w,e,t)=>mt(ht(w),t,e),f=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(a){i(a)}},c=s=>{try{u(t.throw(s))}catch(a){i(a)}},u=s=>s.done?o(s.value):Promise.resolve(s.value).then(r,c);u((t=t.apply(w,e)).next())});const pt=1e4,yt=15e3,gt=1e4,wt=!0,vt=!0,it={ramdeathtest:!0,krpj4avazggi:!0,fobleos13125:!0};class G extends L.P{constructor(e,t,o,i){super(e,t,o,i);const{networkInfo:r}=e;this.fetchCors=(0,m.zR)(e.io),this.networkInfo=r,this.activatedAccountsCache={};const{currencyCode:c,denominations:u}=this.currencyInfo;this.referenceBlock={ref_block_num:0,ref_block_prefix:0},this.accountResources={cpu:0,net:0},this.accountNameChecked=!1,this.getResourcesMutex=!1,this.allTokens.push(nt(et({},u[0]),{currencyCode:c,currencyName:c,contractAddress:"eosio.token",denominations:u})),this.otherMethods={getAccountActivationQuote:s=>f(this,null,function*(){const{requestedAccountName:a,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v}=s;if(h==null||a==null)throw new Error("ErrorInvalidParams");if(l==null&&d==null)throw new Error("ErrorInvalidParams");if(!x(a)){const y=new Error("ErrorInvalidAccountName");throw y.name="ErrorInvalidAccountName",y}const k={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({requestedAccountName:a,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v})};try{const y=yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(_=>()=>f(this,null,function*(){const E=`${_}/api/v1/activateAccount`;return yield(yield this.fetchCors(E,k)).json()})),15e3);return V(y)}catch(y){throw this.error("getAccountActivationQuoteError: ",y),new Error("getAccountActivationQuoteError")}})}}setOtherData(e){this.otherData=(0,O.sr)(e)}checkBlockchainInnerLoop(){return f(this,null,function*(){try{const e=yield this.multicastServers("getInfo"),t=e.head_block_num.toNumber();this.walletLocalData.blockHeight!==t&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const o=e.getTransactionHeader();this.referenceBlock={ref_block_num:o.ref_block_num.toNumber(),ref_block_prefix:o.ref_block_prefix.toNumber()}}catch(e){this.error("Error fetching height: ",e)}})}processIncomingTransaction(e){const t=(0,n.Vk)(I)(e);if(t==null)return this.error("Invalid supernode tx"),0;const{act:o,trx_id:i,block_num:r}=t,c=t["@timestamp"],{from:u,to:s,memo:a,symbol:h}=o.data,l=o.data.amount.toString(),d=h,v=[],k=(0,m.aL)(d,this.currencyInfo,this.allTokensMap);if(k==null)return this.log(`processIncomingTransaction Received unsupported currencyCode: ${d}`),0;let y=(0,P.mul)(l,k.multiplier),_="";s===this.otherData.accountName?(_=u,v.push(s),u===this.otherData.accountName&&(y="0")):(_=s,y=`-${y}`);const E={txid:i,date:Date.parse(c)/1e3,currencyCode:d,blockHeight:r>0?r:0,nativeAmount:y,isSend:y.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:v,signedTx:"",otherParams:{},metadata:{name:_,notes:a},walletId:this.walletId};return this.addTransaction(d,E),E.blockHeight}processOutgoingTransaction(e){const t=[],o=e["@timestamp"].includes("Z")?e["@timestamp"]:e["@timestamp"]+"Z",i=Date.parse(o)/1e3,r=e.block_num>0?e.block_num:0;if(e.block_num==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No tx block_num`),0;const c=e.trx_id;if(e.act==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act`),0;if(e.act.name==="transfer"){if(e.act.data==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act.data`),0;const{from:s,to:a,memo:h,amount:l,symbol:d}=e.act.data,v=l.toString(),k=d,y=(0,m.aL)(k,this.currencyInfo,this.allTokensMap);if(y==null)return this.error(`processOutgoingTransaction Received unsupported currencyCode: ${k}`),0;let _=(0,P.mul)(v,y.multiplier);a===this.otherData.accountName?(t.push(a),s===this.otherData.accountName&&(_="0")):_=`-${_}`;const E={txid:c,date:i,currencyCode:k,blockHeight:r,nativeAmount:_,isSend:_.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:t,signedTx:"",metadata:{notes:h},otherParams:{fromAddress:s,toAddress:a},walletId:this.walletId};this.addTransaction(k,E)}return r}checkOutgoingTransactions(e,t){return f(this,null,function*(){var o,i;if(!vt)throw new Error("Dont use full node API");const r=10;let c=0,u=!1,s=(o=this.otherData.lastQueryActionSeq[t])!=null?o:0;for(;!u;){const a={direction:"outgoing",acct:e,currencyCode:t,skip:c,limit:r,low:s+1},h=yield this.multicastServers("getOutgoingTransactions",a);let l=[];if(h.actions!=null&&h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processOutgoingTransaction(v);if(k>s)s=k;else if(k===s&&d===0&&c===0){u=!0;break}}if(l==null||l.length<r)break;c+=10}s>((i=this.otherData.lastQueryActionSeq[t])!=null?i:0)&&(this.otherData.lastQueryActionSeq[t]=s,this.walletLocalDataDirty=!0)})}checkIncomingTransactions(e,t){return f(this,null,function*(){var o,i;if(!wt)throw new Error("Dont use Hyperion API");let r=(o=this.otherData.highestTxHeight[t])!=null?o:0;const c=10;let u=0,s=!1;for(;!s;){this.log("looping through checkIncomingTransactions, newHighestTxHeight: ",r);const a={direction:"incoming",acct:e,currencyCode:t,skip:u,limit:c,low:r+1},h=yield this.multicastServers("getIncomingTransactions",a);let l=[];if(h.actions.sort((d,v)=>v.block_num-d.block_num),h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processIncomingTransaction(v);if(k>r)r=k;else if(k===r&&d===0&&u===0){s=!0;break}}if(l.length===0||l.length<c)break;u+=10}r>((i=this.otherData.highestTxHeight[t])!=null?i:0)&&(this.otherData.highestTxHeight[t]=r,this.walletLocalDataDirty=!0)})}checkTransactionsInnerLoop(){return f(this,null,function*(){if(!this.accountNameChecked)return;const e=this.otherData.accountName;for(const t of this.enabledTokens){try{yield this.checkIncomingTransactions(e,t),yield this.checkOutgoingTransactions(e,t)}catch(o){if(e!==""){this.error("checkTransactionsInnerLoop fetches failed with error: ",o);return}}this.tokenCheckTransactionsStatus[t]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}})}multicastServers(e,...t){return f(this,null,function*(){const{currencyCode:o}=this.currencyInfo;let i={result:"",server:"no server"};switch(e){case"getAccount":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const u=yield N(this.fetchCors,r).v1.chain.get_account(this.otherData.accountName);return{server:r,result:u}})));break}case"getIncomingTransactions":case"getOutgoingTransactions":{const{direction:r,acct:c,currencyCode:u,skip:s,limit:a,low:h}=t[0],l=this.networkInfo.eosHyperionNodes.map(v=>()=>f(this,null,function*(){const k=v+`/v2/history/get_actions?transfer.${r==="outgoing"?"from":"to"}=${c}&transfer.symbol=${u}&skip=${s}&limit=${a}&sort=desc`,y=yield this.fetchCors(k),_=W()(k,{},!0);if(!y.ok)throw this.error(`multicast in / out tx server error: ${v}`),new Error(`The server returned error code ${y.status} for ${_.hostname}`);const E=J(yield y.json());return{server:v,result:E}})),d=this.networkInfo.eosDfuseServers.map(v=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const k=yield this.fetchCors(`${v}/graphql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:A,variables:{query:`${r==="outgoing"?"auth":"receiver"}:${c} action:transfer`,limit:a,low:h}})}),y=(0,n._C)(tt,p)(yield k.json());if("errors"in y)throw this.warn(`dfuse ${v} get transactions failed: ${JSON.stringify(y.errors[0])}`),new Error(y.errors[0].message);const _=y.data.searchTransactionsBackward.results.map(E=>M({trx_id:E.trace.id,"@timestamp":E.trace.block.timestamp,block_num:E.trace.block.num,act:{data:{from:E.trace.matchingActions[0].json.from,to:E.trace.matchingActions[0].json.to,amount:Number(E.trace.matchingActions[0].json.quantity.split(" ")[0]),symbol:E.trace.matchingActions[0].json.quantity.split(" ")[1],memo:E.trace.matchingActions[0].json.memo}}}));return{server:v,result:{actions:_}}}));i=yield(0,m.QJ)([...l,...d]);break}case"getKeyAccounts":{const r=t[0],c=this.networkInfo.eosHyperionNodes.map(s=>()=>f(this,null,function*(){const h=yield N(this.fetchCors,s).v1.history.get_key_accounts(r);if(h.account_names.length===0)throw new Error(`${s} could not find account with public key: ${r}`);return{server:s,result:h.account_names[0].toString()}})),u=this.networkInfo.eosDfuseServers.map(s=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const a=yield this.fetchCors(`${s}/v0/state/key_accounts?public_key=${r}`);if(!a.ok)throw new Error(`${s} get_account failed with ${a.status}`);const h=Z(yield a.json());if(h.account_names.length===0)throw new Error("dfuse returned empty array");return{server:s,result:h.account_names[0]}}));i=yield(0,m.QJ)([...c,...u]);break}case"getCurrencyBalance":{const r=t[0];i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(c=>()=>f(this,null,function*(){const s=yield N(this.fetchCors,c).v1.chain.get_currency_balance(r,this.otherData.accountName);return{server:c,result:s}})));break}case"getInfo":{const{eosNodes:r}=this.networkInfo,c=(0,m.sD)(r,3);i=yield(0,m.QJ)(c.map(u=>()=>f(this,null,function*(){const a=yield N(this.fetchCors,u).v1.chain.get_info();return{server:u,result:a}})));break}case"getPowerUpState":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const c=N(this.fetchCors,r),s=yield new D._B({api:c}).v1.powerup.get_state();return{server:r,result:s}})));break}case"getResourceUsage":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const c=N(this.fetchCors,r),s=yield new D._B({api:c}).getSampledUsage();return{server:r,result:s}})));break}case"transact":{const{eosNodes:r}=this.networkInfo,c=(0,m.sD)(r,30);i=yield(0,m.QJ)(c.map(u=>()=>f(this,null,function*(){const s=t[0],h=yield N(this.fetchCors,u).v1.chain.send_transaction(s);return{server:u,result:h}})));break}}return this.log(`${o} multicastServers ${e} ${i.server} won`),i.result})}checkAccountInnerLoop(){return f(this,null,function*(){var e,t,o,i;const r=this.walletLocalData.publicKey;try{if(it[(e=this.otherData.accountName)!=null?e:""]&&(this.otherData.accountName="",this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged()),this.otherData.accountName===""){const c=yield this.multicastServers("getKeyAccounts",r);c!=null&&it[c]==null&&(this.otherData.accountName=c,this.accountNameChecked=!0,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged())}}catch(c){/get_account failed with 400/.test(c==null?void 0:c.message)?this.accountNameChecked=!0:this.error("getKeyAccounts error: ",c)}try{if(this.otherData.accountName===""){for(const a of this.allTokens)this.updateBalance(a.currencyCode,"0");return}for(const a of this.allTokens)if(this.enabledTokens.includes(a.currencyCode)){const l=(i=(o=(t=(yield this.multicastServers("getCurrencyBalance",a.contractAddress))[0])==null?void 0:t.units)==null?void 0:o.toString())!=null?i:"0";this.updateBalance(a.currencyCode,l)}const c=yield this.multicastServers("getAccount"),{cpu_limit:u,net_limit:s}=c;this.accountResources={cpu:u.available.toNumber(),net:s.available.toNumber()}}catch(c){this.error("Error fetching account: ",c)}})}getResources(e){return f(this,null,function*(){if(this.getResourcesMutex)return;const{cpu:t,net:o}=this.accountResources;if(!(t>500&&o>500)){if(this.otherData.lastFreePowerUp>Date.now()-1e3*60*60*12){const i=(0,m.sD)(this.networkInfo.powerUpServers,1);try{const r=yield this.fetchCors(`${i}/${this.otherData.accountName}`);if(!r.ok)throw new Error(`getResources error ${r.status}`);this.otherData.lastFreePowerUp=Date.now(),this.walletLocalDataDirty=!0,this.log.warn("getResources freePowerUp SUCCESS");return}catch(r){this.log.warn("getResources lastFreePowerUp error",r)}}try{const i=yield this.multicastServers("getPowerUpState"),r=yield this.multicastServers("getResourceUsage"),c=i.cpu.frac(r,1e3),u=i.net.frac(r,1e3),s=[{account:"eosio",name:"powerup",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{payer:this.otherData.accountName,receiver:this.otherData.accountName,days:1,cpu_frac:c,net_frac:u,max_payment:"0.0003 EOS"}}],a={txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:"-3",isSend:!0,networkFee:"0",ourReceiveAddresses:[],signedTx:"",otherParams:{actions:s,signatures:[]},walletId:this.walletId},h=yield this.signTx(a,e);this.getResourcesMutex=!0,yield this.broadcastTx(h,{privateKeys:e}),this.log.warn("getResources purchase SUCCESS")}catch(i){this.log.warn(`getResources purchase FAILURE
|
|
19
|
+
`,i)}finally{this.getResourcesMutex=!1}}})}clearBlockchainCache(){return f(this,null,function*(){this.activatedAccountsCache={},yield st(G.prototype,this,"clearBlockchainCache").call(this),this.otherData.lastQueryActionSeq={},this.otherData.highestTxHeight={},this.otherData.accountName="",this.accountNameChecked=!1})}startEngine(){return f(this,null,function*(){this.engineOn=!0,this.accountNameChecked=this.otherData.accountName!=="",this.addToLoop("checkBlockchainInnerLoop",yt).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",pt).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",gt).catch(()=>{}),yield st(G.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return f(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return f(this,null,function*(){return this.otherData.accountName!=null?{publicAddress:this.otherData.accountName}:{publicAddress:"",publicKey:this.walletInfo.keys.publicKey,ownerPublicKey:this.walletInfo.keys.ownerPublicKey}})}makeSpend(e){return f(this,null,function*(){const{edgeSpendInfo:t,currencyCode:o,nativeBalance:i,denom:r}=this.makeSpendCheck(e),c=this.getTokenInfo(o);if(c==null)throw new Error("Unable to find token info");const{contractAddress:u="eosio.token"}=c,s=(0,m.aL)(o,this.currencyInfo,this.allTokensMap);if(s==null)throw new Error(`Error: no native denomination found for ${o}`);const a=s.multiplier.length-1;if(t.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:h}=t.spendTargets[0];let{nativeAmount:l}=t.spendTargets[0];if(h==null)throw new Error("makeSpend Missing publicAddress");if(l==null)throw new $.$D;let d=!1;const v=this.activatedAccountsCache[h];if(v!==void 0&&!v)d=!0;else if(v===void 0)try{yield this.tools.getAccSystemStats(h),this.activatedAccountsCache[h]=!0}catch(z){if(z instanceof g.Hx&&z.details[0].message.includes("unknown key"))this.activatedAccountsCache[h]=!1,d=!0;else throw this.error("makeSpend eosPlugin.getAccSystemStats Error ",z),z}if(d)throw new Error("ErrorAccountNotActivated");if((0,P.eq)(l,"0"))throw new $.$D;const k=(0,P.div)(l,r.multiplier,a),y="0";if((0,P.gt)(l,i))throw new $.C_;const _=(0,P.toFixed)(k,a)+` ${o}`;let E="";t.spendTargets[0].otherParams!=null&&typeof t.spendTargets[0].otherParams.uniqueIdentifier=="string"&&(E=t.spendTargets[0].otherParams.uniqueIdentifier);const at=[{account:u,name:"transfer",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{from:this.otherData.accountName,to:h,quantity:_,memo:E}}];l=`-${l}`;const bt={txid:"",date:0,currencyCode:o,blockHeight:0,nativeAmount:l,isSend:l.startsWith("-"),networkFee:y,ourReceiveAddresses:[],signedTx:"",otherParams:{actions:at,signatures:[]},walletId:this.walletId};return this.warn(`${this.currencyInfo.currencyCode} tx prepared: ${l} ${this.walletLocalData.publicKey} -> ${h}`),bt})}signTx(e,t){return f(this,null,function*(){const o=(0,O.Vo)(t),i=(0,m.Xp)(e),r=i.actions[0].name==="transfer"?b:K,c=g.YW.from(nt(et({},this.referenceBlock),{expiration:new Date(new Date().getTime()+3e4),actions:i.actions}),r),u=c.signingDigest(this.networkInfo.chainId),a=g._q.from(o.eosKey).signDigest(u),h=g.uQ.from(nt(et({},c),{signatures:[a]}));i.signatures.push(a.toString());const d=g.f1.fromSigned(h).packed_trx.hexString;return e.signedTx=d,e.otherParams=i,e})}broadcastTx(e,t){return f(this,null,function*(){var o,i,r;const c=(0,O.Vo)(t==null?void 0:t.privateKeys);yield this.getResources(c);const u=(0,m.Xp)(e),{signatures:s}=u,a=g.f1.from({signatures:s,packed_trx:e.signedTx});try{const h=yield this.multicastServers("transact",a);return e.date=Date.now()/1e3,e.txid=h.transaction_id,this.warn(`SUCCESS broadcastTx
|
|
20
20
|
${(0,m.oX)(e)}`),e}catch(h){this.error(`
|
|
21
|
-
Caught exception: `,h),h instanceof g.Hx&&this.error(JSON.stringify(h.error,null,2));let l=h;l.error!=null&&(this.error(`err.error= ${l.error}`),this.error(`err.error.name= ${l.error.name}`));try{l=JSON.parse(h)}catch{throw h}throw((o=l.error)==null?void 0:o.name)==="tx_net_usage_exceeded"?(l=new Error("Insufficient NET available to send EOS transaction"),l.name="ErrorEosInsufficientNet"):((i=l.error)==null?void 0:i.name)==="tx_cpu_usage_exceeded"?(l=new Error("Insufficient CPU available to send EOS transaction"),l.name="ErrorEosInsufficientCpu"):((r=l.error)==null?void 0:r.name)==="ram_usage_exceeded"&&(l=new Error("Insufficient RAM available to send EOS transaction"),l.name="ErrorEosInsufficientRam"),l}})}}function kt(w,e,t,o){return f(this,null,function*(){const i=(0,O.fz)(t),r=new G(w,e,i,o);return yield r.loadEngine(),r})}var S=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(
|
|
21
|
+
Caught exception: `,h),h instanceof g.Hx&&this.error(JSON.stringify(h.error,null,2));let l=h;l.error!=null&&(this.error(`err.error= ${l.error}`),this.error(`err.error.name= ${l.error.name}`));try{l=JSON.parse(h)}catch{throw h}throw((o=l.error)==null?void 0:o.name)==="tx_net_usage_exceeded"?(l=new Error("Insufficient NET available to send EOS transaction"),l.name="ErrorEosInsufficientNet"):((i=l.error)==null?void 0:i.name)==="tx_cpu_usage_exceeded"?(l=new Error("Insufficient CPU available to send EOS transaction"),l.name="ErrorEosInsufficientCpu"):((r=l.error)==null?void 0:r.name)==="ram_usage_exceeded"&&(l=new Error("Insufficient RAM available to send EOS transaction"),l.name="ErrorEosInsufficientRam"),l}})}}function kt(w,e,t,o){return f(this,null,function*(){const i=(0,O.fz)(t),r=new G(w,e,i,o);return yield r.loadEngine(),r})}var S=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(a){i(a)}},c=s=>{try{u(t.throw(s))}catch(a){i(a)}},u=s=>s.done?o(s.value):Promise.resolve(s.value).then(r,c);u((t=t.apply(w,e)).next())});function x(w){return g.VG.pattern.test(w)}function N(w,e){const t=new g.c6(e,{fetch:w});return new g.lP({provider:t})}class ct{constructor(e){const{builtinTokens:t,currencyInfo:o,io:i,log:r,networkInfo:c}=e;this.builtinTokens=t,this.currencyInfo=o,this.fetchCors=(0,m.zR)(e.io),this.io=i,this.log=r,this.networkInfo=c}getDisplayPrivateKey(e){return S(this,null,function*(){const t=(0,O.Vo)(e.keys);let o="";return o+=`owner key
|
|
22
22
|
`+String(t.eosOwnerKey)+`
|
|
23
23
|
|
|
24
24
|
`,o+=`active key
|
|
@@ -30,4 +30,4 @@ Caught exception: `,h),h instanceof g.Hx&&this.error(JSON.stringify(h.error,null
|
|
|
30
30
|
`),(t==null?void 0:t.publicKey)!=null&&(o+=`active publicKey
|
|
31
31
|
`+String(t.publicKey)+`
|
|
32
32
|
|
|
33
|
-
`),o})}importPrivateKey(e){return S(this,null,function*(){const t=e.replace(/ /g,"");if(t.length!==51)throw new Error("Private key wrong length");return g._q.fromString(t),{eosKey:t}})}createPrivateKey(e){return S(this,null,function*(){const t=e.replace("wallet:",""),o=this.currencyInfo.walletType.replace("wallet:","");if(t===o){const i=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif(),r=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif();return{eosOwnerKey:i,eosKey:r}}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return S(this,null,function*(){if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=g._q.from(e.keys.eosKey).toPublic().toLegacyString();let o;return e.keys.eosOwnerKey!=null&&(o=g._q.from(e.keys.eosOwnerKey).toPublic().toLegacyString()),{publicKey:t,ownerPublicKey:o}})}parseUri(e){return S(this,null,function*(){var t;const{edgeParsedUri:o}=(0,X.k)(this.currencyInfo,e,{[this.networkInfo.uriProtocol]:!0});if(!x((t=o.publicAddress)!=null?t:""))throw new Error("InvalidPublicAddressError");return o})}encodeUri(e){return S(this,arguments,function*(t,o=[]){if(!x(t.publicAddress))throw new Error("InvalidPublicAddressError");let r;if(typeof t.nativeAmount=="string"){const u=this.currencyInfo.currencyCode,s=t.nativeAmount,
|
|
33
|
+
`),o})}importPrivateKey(e){return S(this,null,function*(){const t=e.replace(/ /g,"");if(t.length!==51)throw new Error("Private key wrong length");return g._q.fromString(t),{eosKey:t}})}createPrivateKey(e){return S(this,null,function*(){const t=e.replace("wallet:",""),o=this.currencyInfo.walletType.replace("wallet:","");if(t===o){const i=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif(),r=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif();return{eosOwnerKey:i,eosKey:r}}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return S(this,null,function*(){if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=g._q.from(e.keys.eosKey).toPublic().toLegacyString();let o;return e.keys.eosOwnerKey!=null&&(o=g._q.from(e.keys.eosOwnerKey).toPublic().toLegacyString()),{publicKey:t,ownerPublicKey:o}})}parseUri(e){return S(this,null,function*(){var t;const{edgeParsedUri:o}=(0,X.k)(this.currencyInfo,e,{[this.networkInfo.uriProtocol]:!0});if(!x((t=o.publicAddress)!=null?t:""))throw new Error("InvalidPublicAddressError");return o})}encodeUri(e){return S(this,arguments,function*(t,o=[]){if(!x(t.publicAddress))throw new Error("InvalidPublicAddressError");let r;if(typeof t.nativeAmount=="string"){const u=this.currencyInfo.currencyCode,s=t.nativeAmount,a=(0,m.Qs)(u,this.currencyInfo,o);if(a==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,P.div)(s,a.multiplier,4)}return(0,X.Q)(t,this.networkInfo.uriProtocol,r)})}getTokenId(e){return S(this,null,function*(){(0,U.Rp)(e);const t=(0,U.Oj)(e.networkLocation);if(t==null||!x(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase()})}getAccSystemStats(e){return S(this,null,function*(){return yield(0,m.QJ)(this.networkInfo.eosNodes.map(t=>()=>S(this,null,function*(){return yield N(this.fetchCors,t).v1.chain.get_account(e)})))})}getActivationSupportedCurrencies(){return S(this,null,function*(){try{const e=yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(t=>()=>S(this,null,function*(){const o=`${t}/api/v1/getSupportedCurrencies`;return{result:yield(yield this.fetchCors(o)).json()}})));return B(e)}catch(e){throw this.log.error("UnableToGetSupportedCurrencies error: ",e),new Error("UnableToGetSupportedCurrencies")}})}getActivationCost(e){return S(this,null,function*(){try{return yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(o=>()=>S(this,null,function*(){const i=`${o}/api/v1/eosPrices/${e}`,r=yield this.fetchCors(i),c=Q(yield r.json()),u=`${o}/api/v1/startingResources/${e}`,s=yield this.fetchCors(u),a=Q(yield s.json()),l=(Number(c.ram)*a.ram+Number(c.net)*a.net+Number(c.cpu)*a.cpu).toString();return(0,P.toFixed)(l,0,4)})))}catch(t){throw this.log.error("ErrorUnableToGetCost: ",t),new Error("ErrorUnableToGetCost")}})}validateAccount(e){return S(this,null,function*(){const t=x(e)&&e.length===12,o={result:""};if(!t){const i=new Error("ErrorInvalidAccountName");throw i.name="ErrorInvalidAccountName",i}try{if((yield this.getAccSystemStats(e))!=null){const r=new Error("ErrorAccountUnavailable");throw r.name="ErrorAccountUnavailable",r}throw new Error("ErrorUnknownError")}catch(i){if(i instanceof g.Hx&&i.details[0].message.includes("unknown key"))o.result="AccountAvailable";else throw i}return this.log(`validateAccount: result=${o.result}`),o})}}function Ct(w){return S(this,null,function*(){return new ct(w)})}},89214:function(){}}]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[513],{86352:function(Se,oe,P){"use strict";P.d(oe,{Vn:function(){return ae},lF:function(){return A},sp:function(){return ee}});var g=P(76714),J=(j,p,D)=>new Promise((n,M)=>{var Z=S=>{try{F(D.next(S))}catch(O){M(O)}},T=S=>{try{F(D.throw(S))}catch(O){M(O)}},F=S=>S.done?n(S.value):Promise.resolve(S.value).then(Z,T);F((D=D.apply(j,p)).next())});const q=["https://info1.edge.app","https://info2.edge.app"];function ie(j,p,D){return J(this,arguments,function*(n,M,Z,T=5e3,F=fetch){const S=n.map(O=>()=>J(this,null,function*(){const Q=yield F(O+"/"+M,Z);if(typeof Q!="object"){const B=`Invalid return value ${M} in ${O}`;throw console.log(B),new Error(B)}return Q}));return yield(0,g.QJ)(S,T)})}function A(j,p,D,n,M=5e3,Z){return J(this,null,function*(){const T=yield ie((0,g.Sy)(p),D,n,M,Z);if(!T.ok){const O=yield T.text();throw console.error(O),new Error(`Error fetching ${D}: ${O}`)}const F=yield T.json();return j(F)})}function le(j,p,D,n=5e3,M){return J(this,null,function*(){return yield ie((0,g.Sy)(j),p,D,n,M)})}const ae=(j,p,D,n)=>J(void 0,null,function*(){return yield le(q,j,p,D,n)}),ee=j=>Object.keys(j).map(p=>{const D=j[p];return D==null?p:`${p}=${encodeURIComponent(D)}`}).join("&")},79014:function(Se,oe,P){"use strict";P.d(oe,{Q:function(){return Z},k:function(){return M}});var g=P(77591),J=P.n(g),q=P(24350),ie=P(84564),A=P.n(ie),le=P(76714),ae=Object.defineProperty,ee=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,D=(T,F,S)=>F in T?ae(T,F,{enumerable:!0,configurable:!0,writable:!0,value:S}):T[F]=S,n=(T,F)=>{for(var S in F||(F={}))j.call(F,S)&&D(T,S,F[S]);if(ee)for(var S of ee(F))p.call(F,S)&&D(T,S,F[S]);return T};function M(T,F,S,O,Q=[]){const B=n({},A()(F,{},!0)),he=F.startsWith(`${T.pluginId}://`);if(B.protocol!=null&&(B.protocol=B.protocol.replace(":","")),B.protocol!=null&&B.protocol!==""&&!S[B.protocol])throw new Error(`Uri protocol '${B.protocol}' is not supported for ${T.pluginId}.`);if(B.host===""&&B.pathname==="")throw new Error("Path and host not found in uri.");const W={publicAddress:B.host!==""?B.host:B.pathname.split("/")[0]},ge=B.query.label,ue=B.query.message,be=B.query.category;(ge!=null||ue!=null||be!=null||he)&&(W.metadata={},W.metadata.name=ge,W.metadata.notes=ue,W.metadata.category=be,W.metadata.gateway=he!=null?he:!1);const te=B.query.amount;if(te!=null&&typeof te=="string"){O==null&&(O=T.currencyCode);const pe=(0,le.Qs)(O!=null?O:"",T,Q);if(pe==null)throw new Error("InternalErrorInvalidCurrencyCode");let de=(0,g.mul)(te,pe.multiplier);de=(0,g.toFixed)(de,0,0),W.nativeAmount=de,W.currencyCode=O}return{edgeParsedUri:W,parsedUri:B}}function Z(T,F,S){if(T.publicAddress==null)throw new Error("InvalidPublicAddressError");if(S==null&&T.label==null&&T.message==null)return T.publicAddress;{let O="";S!=null&&(O+="amount="+S+"&"),(T.label!=null||T.message!=null)&&(typeof T.label=="string"&&(O+="label="+T.label+"&"),typeof T.message=="string"&&(O+="message="+T.message+"&")),O=O.substr(0,O.length-1);const Q={scheme:F,path:T.publicAddress,query:O};return(0,q.qC)(Q)}}},55773:function(Se,oe,P){"use strict";P.r(oe),P.d(oe,{EthereumTools:function(){return Ve},makeCurrencyEngine:function(){return Wt},makeCurrencyTools:function(){return en}});var g=P(77591),J=P(2153),q=P(48764),ie=P(21964),A=P.n(ie),le=P(48367),ae=P.n(le),ee=P(20918),j=P(79014),p=P(76714),D=P(4583),n=P(82448),M=P(62177);const Z=(0,n.su)({evmScanApiKey:(0,n.Zz)((0,n._C)(n.XC,(0,n._2)(n.XC))),blockcypherApiKey:(0,n.Zz)(n.XC),infuraProjectId:(0,n.Zz)(n.XC),blockchairApiKey:(0,n.Zz)(n.XC),alethioApiKey:(0,n.Zz)(n.XC),amberdataApiKey:(0,n.Zz)(n.XC),gasStationApiKey:(0,n.Zz)(n.XC),quiknodeApiKey:(0,n.Zz)(n.XC),alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)});function T(m){return m in Z.shape}const F=m=>{if(typeof m!="string")throw new Error("key must be a string");if(T(m))return m;throw new Error(`${m} not a key of EthereumInitOptions`)},S=(0,n.su)({minGasLimit:(0,n.Zz)(n.XC),regularTransaction:n.XC,tokenTransaction:n.XC}),O=(0,n.su)({highFee:n.XC,lowFee:n.XC,minGasPrice:(0,n.Zz)(n.XC),standardFeeLow:n.XC,standardFeeHigh:n.XC,standardFeeLowAmount:n.XC,standardFeeHighAmount:n.XC}),Q=(0,n.su)({lowFee:n.XC,standardFeeLow:n.XC,standardFeeHigh:n.XC,highFee:n.XC}),B=(0,n.su)({baseFeeMultiplier:(0,n.Zz)(Q),gasLimit:(0,n.Zz)(S),gasPrice:(0,n.Zz)(O),minPriorityFee:(0,n.Zz)(n.XC)}),he=(0,n.su)(B),Ie=(0,n.su)({blockNumber:n.XC,timeStamp:n.XC,hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),to:n.XC,from:n.XC,value:n.XC,nonce:n.XC,gasPrice:n.XC,gas:n.XC,gasUsed:n.XC,confirmations:n.XC,contractAddress:n.XC,tokenName:n.XC,tokenSymbol:n.XC,tokenDecimal:n.XC}),W=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasPrice:n.XC,gasUsed:n.XC,value:n.XC,nonce:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,confirmations:(0,n.Zz)(n.XC)}),ge=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasUsed:n.XC,value:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,contractAddress:(0,n.Zz)(n.XC)}),ue=(0,n.su)({LastBlock:n.XC,SafeGasPrice:n.XC,ProposeGasPrice:n.XC,FastGasPrice:n.XC,suggestBaseFee:(0,n.Vk)(n.XC),gasUsedRatio:(0,n.Vk)((0,n._2)(n.XC))}),be=(0,n.su)({status:n.XC,message:n.XC,result:(0,n._C)(n.XC,(0,n.su)(ue))}),te=(0,n.su)({from:(0,n._2)(n.XC),to:(0,n._2)(n.XC),gas:n.XC,gasPrice:n.XC,gasUsed:n.XC,tokenRecipientAddress:(0,n.Zz)(n.XC),nonceUsed:(0,n.Zz)(n.XC),replacedTxid:(0,n.Zz)(n.XC),data:(0,n.Zz)((0,n._C)(n.XC,n.gu)),isFromMakeSpend:(0,n.Zz)(n.jK,!1)}),pe=(0,n.su)({nextNonce:(0,n.Vk)(n.XC,"0"),unconfirmedNextNonce:(0,n.Vk)(n.XC,"0")}),de=(0,n.su)({blockbook:(0,n.su)({bestHeight:n.mH})}),Le=(0,n.su)({symbol:n.XC,contract:n.XC,balance:n.XC}),Qe=(0,n.su)({balance:n.XC,unconfirmedBalance:n.XC,unconfirmedTxs:n.mH,nonce:n.XC,tokens:(0,n.Vk)((0,n._2)(Le),()=>[])}),Ye=(0,n.su)({balance:n.XC,token_address:n.XC,token_symbol:n.XC}),qe=(0,n.su)({data:(0,n.su)((0,n.su)({address:(0,n.su)({balance:n.XC}),layer_2:(0,n.su)({erc_20:(0,n._2)((0,n.Zz)(n.XC))})}))}),et=(0,n.su)({data:(0,n.su)({blocks:n.mH})}),tn=(0,n.su)({hash:n.XC,timestamp:n.XC,blockNumber:n.XC,value:n.XC,fee:n.XC,gasLimit:n.XC,gasPrice:n.XC,gasUsed:n.XC,from:(0,n._2)((0,n.su)({address:n.XC})),to:(0,n._2)((0,n.su)({address:n.XC}))}),Y=(0,n.su)({result:n.XC}),tt=(0,n.su)({l1Fee:n.XC}),nn=(0,n.su)({id:(0,n._C)(n.XC,n.mH),method:(0,n.Wf)("personal_sign","eth_sign","eth_signTypedData","eth_signTypedData_v4","eth_sendTransaction","eth_signTransaction","eth_sendRawTransaction"),params:(0,n._2)(n.JC)}),nt=(0,n.Zz)((0,n.su)({typedData:(0,n.Zz)(n.jK,!1)}),{typedData:!1}),Fe=M.BQ,Ce=m=>{const e=m,t=(0,n.su)({[`${e}Mnemonic`]:(0,n.Zz)(n.XC),[`${e}Key`]:n.XC}),s=(0,n.su)({keys:t});return(0,n.W1)(r=>{const i=(0,n.Vk)(s)(r);if(i!=null)return{mnemonic:i.keys[`${e}Mnemonic`],privateKey:i.keys[`${e}Key`]};const u=t(r);return{mnemonic:u[`${e}Mnemonic`],privateKey:u[`${e}Key`]}},r=>({[`${e}Mnemonic`]:r.mnemonic,[`${e}Key`]:r.privateKey}))};var st=P(2832),Oe=P.n(st),xe=P(66052),ne=P(94935),rt=P(50144),ot=P(68142),Pe=P.n(ot),it=P(37217),at=P.n(it),ct=P(84650);const se=1e9,ye=1e8,ke=3e4,lt=.75,ht=60*10*1e3,ut=5*60*1e3;var dt=P(84564),U=P.n(dt);const ft=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return parseInt(e,16);throw new TypeError("Expected a hex number")},mt=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return(0,g.add)(m,"0");throw new TypeError("Expected a hex number")},gt=(0,n.su)({result:ft}),pt=(0,n.su)({result:mt}),yt=(0,n.su)({safeLow:n.mH,average:n.mH,fast:n.mH,fastest:n.mH}),kt=(0,n.su)({types:(0,n.su)((0,n._2)((0,n.su)({name:n.XC,type:n.XC}))),primaryType:n.XC,domain:n.JC,message:n.JC});var Et=P(86352),ce=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ee=(m,e)=>{const t=Object.keys(e);for(const s of t){const r=e[s];typeof r=="string"&&m(` ${s}: ${(0,g.div)(r,"1000000000",18)} gwei`)}},wt=(m,e,t,s,r)=>({infoFeeProvider:()=>ce(void 0,null,function*(){return yield Pt(m,e)}),externalFeeProviders:[bt,Ct,vt].map(u=>()=>ce(void 0,null,function*(){return yield u(m,e,t,s,r)}))}),vt=(m,e,t,s,r)=>ce(void 0,null,function*(){const{rpcServers:i,supportsEIP1559:u=!1}=r;if(u)return;const a=(0,p.sD)(i,1)[0],h={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify({method:"eth_gasPrice",params:[],id:1,jsonrpc:"2.0"})},o=yield m(a,h);if(!o.ok){const k=yield o.text();throw new Error(`fetchFeesFromRpc fetch error: ${k}`)}const l=yield o.json(),c=(0,n.Vk)(Y)(l);if(c==null)throw new Error(`fetchFeesFromRpc ${a} returned invalid json: ${l}`);const{result:d}=c,f=(0,p.Z8)(d),y={lowFee:(0,g.mul)(f,"1"),standardFeeLow:(0,g.mul)(f,"1.06"),standardFeeHigh:(0,g.mul)(f,"1.12"),highFee:(0,g.mul)(f,"1.25")};return s(`fetchFeesFromRpc: ${e.currencyCode}`),Ee(s,y),y}),bt=(m,e,t,s,r)=>ce(void 0,null,function*(){const i=r.evmScanApiServers,u=Be(t,e,s);if(i==null||u==null)return;const a=`&apikey=${Array.isArray(u)?(0,p.sD)(u,1)[0]:u!=null?u:""}`,h=`${(0,p.sD)(i,1)[0]}/api?module=gastracker&action=gasoracle${a}`,o=yield m(h);if(!o.ok)throw new Error(`EvmScan fetch error: ${JSON.stringify(o)}`);const l=yield o.json(),c=l.message.includes("NOTOK");if(!(l!=null&&!c))throw new Error(`fetchFeesFromEvmScan unrecognized response message: ${l.message}`);const{SafeGasPrice:f,ProposeGasPrice:y,FastGasPrice:k}=ue(l.result),b=parseInt(f);let v=parseInt(y),E=parseInt(k);v<=b&&(v=b+1),E<=v&&(E=v+1);const C=`${b*se}`,I=`${(b+v)/2*se}`,_=`${E*se}`,X=`${E*se/lt}`,H={lowFee:C,standardFeeLow:I,standardFeeHigh:_,highFee:X};return s(`fetchFeesFromEvmScan: ${e.currencyCode}`),Ee(s,H),H}),Ct=(m,e,t,s,r)=>ce(void 0,null,function*(){const{ethGasStationUrl:i}=r,u=Tt(t,e,s);if(i==null||u==null)return;const a=u?`?api-key=${u||""}`:"",o=yield(yield m(`${i}${a}`)).json(),l=yt(o);if(e.currencyCode==="MATIC"&&(l.safeLow*=10,l.average=(o.fast+o.safeLow)/2*10,l.fast=o.standard*10,l.fastest*=10),l.safeLow<=0||l.safeLow>ke)throw new Error("Invalid safeLow value from Gas Station");if(l.average<1||l.average>ke)throw new Error("Invalid average value from Gas Station");if(l.fast<1||l.fast>ke)throw new Error("Invalid fastest value from Gas Station");if(l.fastest<1||l.fastest>ke)throw new Error("Invalid fastest value from Gas Station");l.average<=l.safeLow&&(l.average=l.safeLow+1),l.fast<=l.average&&(l.fast=l.average+1),l.fastest<=l.fast&&(l.fastest=l.fast+1);let c=l.safeLow,d=l.fast,f=((l.fast+l.fastest)*.5+l.fastest)*.5,y=f>l.fastest?f:l.fastest;c=Math.round(c)*ye,d=Math.round(d)*ye,f=Math.round(f)*ye,y=Math.round(y)*ye;const k={lowFee:c.toString(),standardFeeLow:d.toString(),standardFeeHigh:f.toString(),highFee:y.toString()};return s(`fetchFeesFromEvmGasStation: ${e.currencyCode}`),Ee(s,k),k}),Pt=(m,e)=>ce(void 0,[m,e],function*(t,{pluginId:s}){const i=yield(yield(0,Et.Vn)(`v1/networkFees/${s}`,void 0,void 0,t)).json();return he(i)}),Be=(m,e,t)=>{const{evmScanApiKey:s,etherscanApiKey:r,ftmscanApiKey:i,bscscanApiKey:u,polygonscanApiKey:a}=m;if(s!=null)return s;const{currencyCode:h}=e;if(h==="ETH"&&r!=null)return t.warn("INIT OPTION 'etherscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),r;if(h==="FTM"&&i!=null)return t.warn("INIT OPTION 'ftmscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),i;if(h==="BNB"&&u!=null)return t.warn("INIT OPTION 'bscscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),u;if(h==="MATIC"&&a!=null)return t.warn("INIT OPTION 'polygonscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),a},Tt=(m,e,t)=>{const{gasStationApiKey:s,ethGasStationApiKey:r}=m;if(s!=null)return s;const{currencyCode:i}=e;if(i==="ETH"&&r!=null)return t.warn("INIT OPTION 'ethGasStationApiKey' IS DEPRECATED. USE 'gasStationApiKey' INSTEAD"),r};var At=Object.defineProperty,St=Object.defineProperties,It=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Lt=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable,$e=(m,e,t)=>e in m?At(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,Re=(m,e)=>{for(var t in e||(e={}))Lt.call(e,t)&&$e(m,t,e[t]);if(Ne)for(var t of Ne(e))Ft.call(e,t)&&$e(m,t,e[t]);return m},_e=(m,e)=>St(m,It(e)),w=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ot=2e4,xt=2e4,Bt=2e4,Nt=2e4,De=4*2,Xe=2*60,$t=50;function we(m,e){return w(this,null,function*(){return{result:yield m,server:e}})}const Te=(m,e,t)=>{let s={};try{s=_e(Re({gasPrice:(0,g.div)(m,se.toString(),se.toString().length-1)},t!==void 0?{gasUsed:t}:{}),{gasLimit:e})}catch(r){console.log(`Failed to construct feeRateUssed: ${r}`)}return s};class Rt{constructor(e){this.ethEngine=e,this.ethNeeds={blockHeightLastChecked:0,nonceLastChecked:0,tokenBalLastChecked:{},tokenTxsLastChecked:{}},this.fetchGetEtherscan=this.fetchGetEtherscan.bind(this),this.multicastServers=this.multicastServers.bind(this),this.checkAddressBlockbook=this.checkAddressBlockbook.bind(this),this.checkBlockHeightEthscan=this.checkBlockHeightEthscan.bind(this),this.checkBlockHeightBlockchair=this.checkBlockHeightBlockchair.bind(this),this.checkBlockHeightAmberdata=this.checkBlockHeightAmberdata.bind(this),this.checkBlockHeightBlockbook=this.checkBlockHeightBlockbook.bind(this),this.checkNonceRpc=this.checkNonceRpc.bind(this),this.checkNonceEthscan=this.checkNonceEthscan.bind(this),this.checkNonceAmberdata=this.checkNonceAmberdata.bind(this),this.checkTokenBalEthscan=this.checkTokenBalEthscan.bind(this),this.checkTokenBalBlockchair=this.checkTokenBalBlockchair.bind(this),this.checkTokenBalRpc=this.checkTokenBalRpc.bind(this),this.checkTxsEthscan=this.checkTxsEthscan.bind(this),this.processEthereumNetworkUpdate=this.processEthereumNetworkUpdate.bind(this),this.queryFuncs=this.buildQueryFuncs(this.ethEngine.networkInfo),this.walletId=e.walletInfo.id}processEvmScanTransaction(e,t){return w(this,null,function*(){var s;const r=[],i=(s=e.hash)!=null?s:e.transactionHash;if(i==null)throw new Error("Invalid transaction result format");const u=e.from.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase(),a=t!==this.ethEngine.currencyInfo.currencyCode,h="gasPrice"in e?e.gasPrice:void 0,o=h!=null?(0,g.mul)(h,e.gasUsed):"0";let l="0";if(u&&this.ethEngine.networkInfo.l1RollupParams!=null){const v=yield this.multicastServers("eth_getTransactionReceipt",[i]),E=tt(v.result.result);l=(0,g.add)(l,(0,p.X0)(E.l1Fee))}let c,d,f;u?a?(c=(0,g.sub)("0",e.value),d="0",f=(0,g.add)(o,l)):e.from.toLowerCase()===e.to.toLowerCase()?(c=(0,g.sub)((0,g.sub)("0",o),l),d=(0,g.add)(o,l)):(c=(0,g.sub)((0,g.sub)((0,g.sub)("0",e.value),o),l),d=(0,g.add)(o,l)):(c=e.value,d="0",r.push(this.ethEngine.walletLocalData.publicKey));const y={from:[e.from],to:[e.to],gas:e.gas,gasPrice:h!=null?h:"",gasUsed:e.gasUsed,isFromMakeSpend:!1};let k=parseInt(e.blockNumber);return k<0&&(k=0),{txid:i,date:parseInt(e.timeStamp),currencyCode:t,blockHeight:k,nativeAmount:c,isSend:c.startsWith("-"),networkFee:d,feeRateUsed:h!=null?Te(h,e.gas,e.gasUsed):void 0,parentNetworkFee:f,ourReceiveAddresses:r,signedTx:"",otherParams:y,walletId:this.walletId}})}processAlethioTransaction(e,t){let s;const r=[];let i;const u=t!==this.ethEngine.currencyInfo.currencyCode,a=e.attributes.value,h=e.attributes.fee?e.attributes.fee:"0",o=e.relationships.from.data.id,l=e.relationships.to.data.id;t===this.ethEngine.currencyInfo.currencyCode?i=h:i="0";const c=o.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase();if(c)o.toLowerCase()===l.toLowerCase()?s=(0,g.mul)(i,"-1"):(s=(0,g.sub)("0",a),u||(s=(0,g.sub)(s,i)));else if(l.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase())s=a,r.push(this.ethEngine.walletLocalData.publicKey.toLowerCase());else return null;const d={from:[o],to:[l],gas:"0",gasPrice:"0",gasUsed:"0",isFromMakeSpend:!1};let f=e.attributes.globalRank[0];f<0&&(f=0);let y,k="0";return u&&c?y=i:k=i,{txid:e.relationships.transaction.data.id,date:e.attributes.blockCreationTime,currencyCode:t,blockHeight:f,nativeAmount:s,isSend:s.startsWith("-"),networkFee:k,ourReceiveAddresses:r,signedTx:"",parentNetworkFee:y,otherParams:d,walletId:this.walletId}}fetchGetEtherscan(e,t){return w(this,null,function*(){const s=Be(this.ethEngine.initOptions,this.ethEngine.currencyInfo,this.ethEngine.log);e.indexOf("cors-http")===0&&(e=e.replace(/^cors-http/,"http"));const i=Array.isArray(s)?(0,p.sD)(s,1)[0]:s!=null?s:"",u=i!==""?`&apikey=${i}`:"",a=`${e}/api${t}`,h=yield this.ethEngine.fetchCors(`${a}${u}`);return h.ok||this.throwError(h,"fetchGetEtherscan",a),yield h.json()})}fetchGetBlockbook(e,t){return w(this,null,function*(){const s=e+t;return yield(e.includes("trezor")?yield this.ethEngine.fetchCors(s,{headers:{"User-Agent":"http.agent"}}):yield this.ethEngine.fetchCors(s)).json()})}fetchPostRPC(e,t,s,r){return w(this,null,function*(){const i={id:s,jsonrpc:"2.0",method:e,params:t},a=/{{(.*?)}}/g.exec(r);if(a!=null){const l=a[1],c=F(l),d=this.ethEngine.initOptions[c];if(typeof d=="string")r=r.replace(a[0],d);else throw d==null?new Error(`Missing ${c} in 'initOptions' for ${this.ethEngine.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const h=yield this.ethEngine.fetchCors(r,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(i)}),o=U()(r,{},!0);return h.ok||this.throwError(h,"fetchPostRPC",o.hostname),yield h.json()})}fetchPostBlockcypher(e,t,s){return w(this,null,function*(){const{blockcypherApiKey:r}=this.ethEngine.initOptions;let i="";r&&r.length>5&&(i="&token="+r);const u=`${s}/${e}${i}`,a=yield this.ethEngine.fetchCors(u,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(t)}),h=U()(u,{},!0);return a.ok||this.throwError(a,"fetchPostBlockcypher",h.hostname),yield a.json()})}fetchGetBlockchair(e,t=!1){return w(this,null,function*(){const{blockchairApiKey:s}=this.ethEngine.initOptions,{blockchairApiServers:r}=this.ethEngine.networkInfo,i=t&&s?`&key=${s}`:"",u=`${r[0]}${e}`,a=yield this.ethEngine.fetchCors(`${u}${i}`);return a.ok||this.throwError(a,"fetchGetBlockchair",u),yield a.json()})}fetchPostAmberdataRpc(e){return w(this,arguments,function*(t,s=[]){const{amberdataApiKey:r=""}=this.ethEngine.initOptions,{amberdataRpcServers:i}=this.ethEngine.networkInfo,u=`${i[0]}`,a={jsonrpc:"2.0",method:t,params:s,id:1},h=yield this.ethEngine.fetchCors(u,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":r,"Content-Type":"application/json"},method:"POST",body:JSON.stringify(a)}),o=U()(u,{},!0);return h.ok||this.throwError(h,"fetchPostAmberdataRpc",o),yield h.json()})}fetchGetAmberdataApi(e){return w(this,null,function*(){const{amberdataApiKey:t=""}=this.ethEngine.initOptions,{amberdataApiServers:s}=this.ethEngine.networkInfo,r=`${s[0]}${e}`,i=yield this.ethEngine.fetchCors(r,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":t}});return i.ok||this.throwError(i,"fetchGetAmberdata",r),yield i.json()})}fetchGetAlethio(e,t=!0,s){return w(this,null,function*(){const{alethioApiKey:r=""}=this.ethEngine.initOptions,{alethioApiServers:i}=this.ethEngine.networkInfo,u=t?`${i[0]}${e}`:e,a=yield this.ethEngine.fetchCors(u,r?{headers:{Authorization:`Bearer ${r}`}}:void 0);return a.ok||this.throwError(a,"fetchGetAlethio",u),yield a.json()})}broadcastEtherscan(e,t){return w(this,null,function*(){const s=`?module=proxy&action=eth_sendRawTransaction&hex=${e.signedTx}`,r=yield this.fetchGetEtherscan(t,s);return this.broadcastResponseHandler(r,t,e)})}broadcastRPC(e,t,s){return w(this,null,function*(){const r="eth_sendRawTransaction",i=[e.signedTx],u=yield this.fetchPostRPC(r,i,t,s),a=U()(s,{},!0);return this.broadcastResponseHandler(u,a,e)})}broadcastBlockCypher(e,t){return w(this,null,function*(){const s=`v1/${this.ethEngine.currencyInfo.currencyCode.toLowerCase()}/main/txs/push`,r=e.signedTx.replace("0x",""),i=yield this.fetchPostBlockcypher(s,{tx:r},t);return this.broadcastResponseHandler(i,t,e)})}broadcastBlockbook(e,t){return w(this,null,function*(){const s=yield this.fetchGetBlockbook(t,`/api/v2/sendtx/${e.signedTx}`);return this.broadcastResponseHandler(s,t,e)})}broadcastResponseHandler(e,t,s){if(typeof e.error<"u")throw this.ethEngine.error(`FAILURE ${t}
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[1513],{86352:function(Se,oe,P){"use strict";P.d(oe,{Vn:function(){return ae},lF:function(){return A},sp:function(){return ee}});var g=P(76714),J=(j,p,D)=>new Promise((n,M)=>{var Z=S=>{try{F(D.next(S))}catch(O){M(O)}},T=S=>{try{F(D.throw(S))}catch(O){M(O)}},F=S=>S.done?n(S.value):Promise.resolve(S.value).then(Z,T);F((D=D.apply(j,p)).next())});const q=["https://info1.edge.app","https://info2.edge.app"];function ie(j,p,D){return J(this,arguments,function*(n,M,Z,T=5e3,F=fetch){const S=n.map(O=>()=>J(this,null,function*(){const Q=yield F(O+"/"+M,Z);if(typeof Q!="object"){const B=`Invalid return value ${M} in ${O}`;throw console.log(B),new Error(B)}return Q}));return yield(0,g.QJ)(S,T)})}function A(j,p,D,n,M=5e3,Z){return J(this,null,function*(){const T=yield ie((0,g.Sy)(p),D,n,M,Z);if(!T.ok){const O=yield T.text();throw console.error(O),new Error(`Error fetching ${D}: ${O}`)}const F=yield T.json();return j(F)})}function le(j,p,D,n=5e3,M){return J(this,null,function*(){return yield ie((0,g.Sy)(j),p,D,n,M)})}const ae=(j,p,D,n)=>J(void 0,null,function*(){return yield le(q,j,p,D,n)}),ee=j=>Object.keys(j).map(p=>{const D=j[p];return D==null?p:`${p}=${encodeURIComponent(D)}`}).join("&")},79014:function(Se,oe,P){"use strict";P.d(oe,{Q:function(){return Z},k:function(){return M}});var g=P(77591),J=P.n(g),q=P(24350),ie=P(84564),A=P.n(ie),le=P(76714),ae=Object.defineProperty,ee=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,D=(T,F,S)=>F in T?ae(T,F,{enumerable:!0,configurable:!0,writable:!0,value:S}):T[F]=S,n=(T,F)=>{for(var S in F||(F={}))j.call(F,S)&&D(T,S,F[S]);if(ee)for(var S of ee(F))p.call(F,S)&&D(T,S,F[S]);return T};function M(T,F,S,O,Q=[]){const B=n({},A()(F,{},!0)),he=F.startsWith(`${T.pluginId}://`);if(B.protocol!=null&&(B.protocol=B.protocol.replace(":","")),B.protocol!=null&&B.protocol!==""&&!S[B.protocol])throw new Error(`Uri protocol '${B.protocol}' is not supported for ${T.pluginId}.`);if(B.host===""&&B.pathname==="")throw new Error("Path and host not found in uri.");const W={publicAddress:B.host!==""?B.host:B.pathname.split("/")[0]},ge=B.query.label,ue=B.query.message,be=B.query.category;(ge!=null||ue!=null||be!=null||he)&&(W.metadata={},W.metadata.name=ge,W.metadata.notes=ue,W.metadata.category=be,W.metadata.gateway=he!=null?he:!1);const te=B.query.amount;if(te!=null&&typeof te=="string"){O==null&&(O=T.currencyCode);const pe=(0,le.Qs)(O!=null?O:"",T,Q);if(pe==null)throw new Error("InternalErrorInvalidCurrencyCode");let de=(0,g.mul)(te,pe.multiplier);de=(0,g.toFixed)(de,0,0),W.nativeAmount=de,W.currencyCode=O}return{edgeParsedUri:W,parsedUri:B}}function Z(T,F,S){if(T.publicAddress==null)throw new Error("InvalidPublicAddressError");if(S==null&&T.label==null&&T.message==null)return T.publicAddress;{let O="";S!=null&&(O+="amount="+S+"&"),(T.label!=null||T.message!=null)&&(typeof T.label=="string"&&(O+="label="+T.label+"&"),typeof T.message=="string"&&(O+="message="+T.message+"&")),O=O.substr(0,O.length-1);const Q={scheme:F,path:T.publicAddress,query:O};return(0,q.qC)(Q)}}},55773:function(Se,oe,P){"use strict";P.r(oe),P.d(oe,{EthereumTools:function(){return Ve},makeCurrencyEngine:function(){return Wt},makeCurrencyTools:function(){return en}});var g=P(77591),J=P(2153),q=P(48764),ie=P(21964),A=P.n(ie),le=P(48367),ae=P.n(le),ee=P(20918),j=P(79014),p=P(76714),D=P(4583),n=P(82448),M=P(62177);const Z=(0,n.su)({evmScanApiKey:(0,n.Zz)((0,n._C)(n.XC,(0,n._2)(n.XC))),blockcypherApiKey:(0,n.Zz)(n.XC),infuraProjectId:(0,n.Zz)(n.XC),blockchairApiKey:(0,n.Zz)(n.XC),alethioApiKey:(0,n.Zz)(n.XC),amberdataApiKey:(0,n.Zz)(n.XC),gasStationApiKey:(0,n.Zz)(n.XC),quiknodeApiKey:(0,n.Zz)(n.XC),alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)});function T(m){return m in Z.shape}const F=m=>{if(typeof m!="string")throw new Error("key must be a string");if(T(m))return m;throw new Error(`${m} not a key of EthereumInitOptions`)},S=(0,n.su)({minGasLimit:(0,n.Zz)(n.XC),regularTransaction:n.XC,tokenTransaction:n.XC}),O=(0,n.su)({highFee:n.XC,lowFee:n.XC,minGasPrice:(0,n.Zz)(n.XC),standardFeeLow:n.XC,standardFeeHigh:n.XC,standardFeeLowAmount:n.XC,standardFeeHighAmount:n.XC}),Q=(0,n.su)({lowFee:n.XC,standardFeeLow:n.XC,standardFeeHigh:n.XC,highFee:n.XC}),B=(0,n.su)({baseFeeMultiplier:(0,n.Zz)(Q),gasLimit:(0,n.Zz)(S),gasPrice:(0,n.Zz)(O),minPriorityFee:(0,n.Zz)(n.XC)}),he=(0,n.su)(B),Ie=(0,n.su)({blockNumber:n.XC,timeStamp:n.XC,hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),to:n.XC,from:n.XC,value:n.XC,nonce:n.XC,gasPrice:n.XC,gas:n.XC,gasUsed:n.XC,confirmations:n.XC,contractAddress:n.XC,tokenName:n.XC,tokenSymbol:n.XC,tokenDecimal:n.XC}),W=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasPrice:n.XC,gasUsed:n.XC,value:n.XC,nonce:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,confirmations:(0,n.Zz)(n.XC)}),ge=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasUsed:n.XC,value:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,contractAddress:(0,n.Zz)(n.XC)}),ue=(0,n.su)({LastBlock:n.XC,SafeGasPrice:n.XC,ProposeGasPrice:n.XC,FastGasPrice:n.XC,suggestBaseFee:(0,n.Vk)(n.XC),gasUsedRatio:(0,n.Vk)((0,n._2)(n.XC))}),be=(0,n.su)({status:n.XC,message:n.XC,result:(0,n._C)(n.XC,(0,n.su)(ue))}),te=(0,n.su)({from:(0,n._2)(n.XC),to:(0,n._2)(n.XC),gas:n.XC,gasPrice:n.XC,gasUsed:n.XC,tokenRecipientAddress:(0,n.Zz)(n.XC),nonceUsed:(0,n.Zz)(n.XC),replacedTxid:(0,n.Zz)(n.XC),data:(0,n.Zz)((0,n._C)(n.XC,n.gu)),isFromMakeSpend:(0,n.Zz)(n.jK,!1)}),pe=(0,n.su)({nextNonce:(0,n.Vk)(n.XC,"0"),unconfirmedNextNonce:(0,n.Vk)(n.XC,"0")}),de=(0,n.su)({blockbook:(0,n.su)({bestHeight:n.mH})}),Le=(0,n.su)({symbol:n.XC,contract:n.XC,balance:n.XC}),Qe=(0,n.su)({balance:n.XC,unconfirmedBalance:n.XC,unconfirmedTxs:n.mH,nonce:n.XC,tokens:(0,n.Vk)((0,n._2)(Le),()=>[])}),Ye=(0,n.su)({balance:n.XC,token_address:n.XC,token_symbol:n.XC}),qe=(0,n.su)({data:(0,n.su)((0,n.su)({address:(0,n.su)({balance:n.XC}),layer_2:(0,n.su)({erc_20:(0,n._2)((0,n.Zz)(n.XC))})}))}),et=(0,n.su)({data:(0,n.su)({blocks:n.mH})}),tn=(0,n.su)({hash:n.XC,timestamp:n.XC,blockNumber:n.XC,value:n.XC,fee:n.XC,gasLimit:n.XC,gasPrice:n.XC,gasUsed:n.XC,from:(0,n._2)((0,n.su)({address:n.XC})),to:(0,n._2)((0,n.su)({address:n.XC}))}),Y=(0,n.su)({result:n.XC}),tt=(0,n.su)({l1Fee:n.XC}),nn=(0,n.su)({id:(0,n._C)(n.XC,n.mH),method:(0,n.Wf)("personal_sign","eth_sign","eth_signTypedData","eth_signTypedData_v4","eth_sendTransaction","eth_signTransaction","eth_sendRawTransaction"),params:(0,n._2)(n.JC)}),nt=(0,n.Zz)((0,n.su)({typedData:(0,n.Zz)(n.jK,!1)}),{typedData:!1}),Fe=M.BQ,Ce=m=>{const e=m,t=(0,n.su)({[`${e}Mnemonic`]:(0,n.Zz)(n.XC),[`${e}Key`]:n.XC}),s=(0,n.su)({keys:t});return(0,n.W1)(r=>{const i=(0,n.Vk)(s)(r);if(i!=null)return{mnemonic:i.keys[`${e}Mnemonic`],privateKey:i.keys[`${e}Key`]};const u=t(r);return{mnemonic:u[`${e}Mnemonic`],privateKey:u[`${e}Key`]}},r=>({[`${e}Mnemonic`]:r.mnemonic,[`${e}Key`]:r.privateKey}))};var st=P(2832),Oe=P.n(st),xe=P(66052),ne=P(94935),rt=P(50144),ot=P(68142),Pe=P.n(ot),it=P(37217),at=P.n(it),ct=P(84650);const se=1e9,ye=1e8,ke=3e4,lt=.75,ht=60*10*1e3,ut=5*60*1e3;var dt=P(84564),U=P.n(dt);const ft=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return parseInt(e,16);throw new TypeError("Expected a hex number")},mt=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return(0,g.add)(m,"0");throw new TypeError("Expected a hex number")},gt=(0,n.su)({result:ft}),pt=(0,n.su)({result:mt}),yt=(0,n.su)({safeLow:n.mH,average:n.mH,fast:n.mH,fastest:n.mH}),kt=(0,n.su)({types:(0,n.su)((0,n._2)((0,n.su)({name:n.XC,type:n.XC}))),primaryType:n.XC,domain:n.JC,message:n.JC});var Et=P(86352),ce=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ee=(m,e)=>{const t=Object.keys(e);for(const s of t){const r=e[s];typeof r=="string"&&m(` ${s}: ${(0,g.div)(r,"1000000000",18)} gwei`)}},wt=(m,e,t,s,r)=>({infoFeeProvider:()=>ce(void 0,null,function*(){return yield Pt(m,e)}),externalFeeProviders:[bt,Ct,vt].map(u=>()=>ce(void 0,null,function*(){return yield u(m,e,t,s,r)}))}),vt=(m,e,t,s,r)=>ce(void 0,null,function*(){const{rpcServers:i,supportsEIP1559:u=!1}=r;if(u)return;const a=(0,p.sD)(i,1)[0],h={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify({method:"eth_gasPrice",params:[],id:1,jsonrpc:"2.0"})},o=yield m(a,h);if(!o.ok){const k=yield o.text();throw new Error(`fetchFeesFromRpc fetch error: ${k}`)}const l=yield o.json(),c=(0,n.Vk)(Y)(l);if(c==null)throw new Error(`fetchFeesFromRpc ${a} returned invalid json: ${l}`);const{result:d}=c,f=(0,p.Z8)(d),y={lowFee:(0,g.mul)(f,"1"),standardFeeLow:(0,g.mul)(f,"1.06"),standardFeeHigh:(0,g.mul)(f,"1.12"),highFee:(0,g.mul)(f,"1.25")};return s(`fetchFeesFromRpc: ${e.currencyCode}`),Ee(s,y),y}),bt=(m,e,t,s,r)=>ce(void 0,null,function*(){const i=r.evmScanApiServers,u=Be(t,e,s);if(i==null||u==null)return;const a=`&apikey=${Array.isArray(u)?(0,p.sD)(u,1)[0]:u!=null?u:""}`,h=`${(0,p.sD)(i,1)[0]}/api?module=gastracker&action=gasoracle${a}`,o=yield m(h);if(!o.ok)throw new Error(`EvmScan fetch error: ${JSON.stringify(o)}`);const l=yield o.json(),c=l.message.includes("NOTOK");if(!(l!=null&&!c))throw new Error(`fetchFeesFromEvmScan unrecognized response message: ${l.message}`);const{SafeGasPrice:f,ProposeGasPrice:y,FastGasPrice:k}=ue(l.result),b=parseInt(f);let v=parseInt(y),E=parseInt(k);v<=b&&(v=b+1),E<=v&&(E=v+1);const C=`${b*se}`,I=`${(b+v)/2*se}`,_=`${E*se}`,X=`${E*se/lt}`,H={lowFee:C,standardFeeLow:I,standardFeeHigh:_,highFee:X};return s(`fetchFeesFromEvmScan: ${e.currencyCode}`),Ee(s,H),H}),Ct=(m,e,t,s,r)=>ce(void 0,null,function*(){const{ethGasStationUrl:i}=r,u=Tt(t,e,s);if(i==null||u==null)return;const a=u?`?api-key=${u||""}`:"",o=yield(yield m(`${i}${a}`)).json(),l=yt(o);if(e.currencyCode==="MATIC"&&(l.safeLow*=10,l.average=(o.fast+o.safeLow)/2*10,l.fast=o.standard*10,l.fastest*=10),l.safeLow<=0||l.safeLow>ke)throw new Error("Invalid safeLow value from Gas Station");if(l.average<1||l.average>ke)throw new Error("Invalid average value from Gas Station");if(l.fast<1||l.fast>ke)throw new Error("Invalid fastest value from Gas Station");if(l.fastest<1||l.fastest>ke)throw new Error("Invalid fastest value from Gas Station");l.average<=l.safeLow&&(l.average=l.safeLow+1),l.fast<=l.average&&(l.fast=l.average+1),l.fastest<=l.fast&&(l.fastest=l.fast+1);let c=l.safeLow,d=l.fast,f=((l.fast+l.fastest)*.5+l.fastest)*.5,y=f>l.fastest?f:l.fastest;c=Math.round(c)*ye,d=Math.round(d)*ye,f=Math.round(f)*ye,y=Math.round(y)*ye;const k={lowFee:c.toString(),standardFeeLow:d.toString(),standardFeeHigh:f.toString(),highFee:y.toString()};return s(`fetchFeesFromEvmGasStation: ${e.currencyCode}`),Ee(s,k),k}),Pt=(m,e)=>ce(void 0,[m,e],function*(t,{pluginId:s}){const i=yield(yield(0,Et.Vn)(`v1/networkFees/${s}`,void 0,void 0,t)).json();return he(i)}),Be=(m,e,t)=>{const{evmScanApiKey:s,etherscanApiKey:r,ftmscanApiKey:i,bscscanApiKey:u,polygonscanApiKey:a}=m;if(s!=null)return s;const{currencyCode:h}=e;if(h==="ETH"&&r!=null)return t.warn("INIT OPTION 'etherscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),r;if(h==="FTM"&&i!=null)return t.warn("INIT OPTION 'ftmscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),i;if(h==="BNB"&&u!=null)return t.warn("INIT OPTION 'bscscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),u;if(h==="MATIC"&&a!=null)return t.warn("INIT OPTION 'polygonscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),a},Tt=(m,e,t)=>{const{gasStationApiKey:s,ethGasStationApiKey:r}=m;if(s!=null)return s;const{currencyCode:i}=e;if(i==="ETH"&&r!=null)return t.warn("INIT OPTION 'ethGasStationApiKey' IS DEPRECATED. USE 'gasStationApiKey' INSTEAD"),r};var At=Object.defineProperty,St=Object.defineProperties,It=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Lt=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable,$e=(m,e,t)=>e in m?At(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,Re=(m,e)=>{for(var t in e||(e={}))Lt.call(e,t)&&$e(m,t,e[t]);if(Ne)for(var t of Ne(e))Ft.call(e,t)&&$e(m,t,e[t]);return m},_e=(m,e)=>St(m,It(e)),w=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ot=2e4,xt=2e4,Bt=2e4,Nt=2e4,De=4*2,Xe=2*60,$t=50;function we(m,e){return w(this,null,function*(){return{result:yield m,server:e}})}const Te=(m,e,t)=>{let s={};try{s=_e(Re({gasPrice:(0,g.div)(m,se.toString(),se.toString().length-1)},t!==void 0?{gasUsed:t}:{}),{gasLimit:e})}catch(r){console.log(`Failed to construct feeRateUssed: ${r}`)}return s};class Rt{constructor(e){this.ethEngine=e,this.ethNeeds={blockHeightLastChecked:0,nonceLastChecked:0,tokenBalLastChecked:{},tokenTxsLastChecked:{}},this.fetchGetEtherscan=this.fetchGetEtherscan.bind(this),this.multicastServers=this.multicastServers.bind(this),this.checkAddressBlockbook=this.checkAddressBlockbook.bind(this),this.checkBlockHeightEthscan=this.checkBlockHeightEthscan.bind(this),this.checkBlockHeightBlockchair=this.checkBlockHeightBlockchair.bind(this),this.checkBlockHeightAmberdata=this.checkBlockHeightAmberdata.bind(this),this.checkBlockHeightBlockbook=this.checkBlockHeightBlockbook.bind(this),this.checkNonceRpc=this.checkNonceRpc.bind(this),this.checkNonceEthscan=this.checkNonceEthscan.bind(this),this.checkNonceAmberdata=this.checkNonceAmberdata.bind(this),this.checkTokenBalEthscan=this.checkTokenBalEthscan.bind(this),this.checkTokenBalBlockchair=this.checkTokenBalBlockchair.bind(this),this.checkTokenBalRpc=this.checkTokenBalRpc.bind(this),this.checkTxsEthscan=this.checkTxsEthscan.bind(this),this.processEthereumNetworkUpdate=this.processEthereumNetworkUpdate.bind(this),this.queryFuncs=this.buildQueryFuncs(this.ethEngine.networkInfo),this.walletId=e.walletInfo.id}processEvmScanTransaction(e,t){return w(this,null,function*(){var s;const r=[],i=(s=e.hash)!=null?s:e.transactionHash;if(i==null)throw new Error("Invalid transaction result format");const u=e.from.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase(),a=t!==this.ethEngine.currencyInfo.currencyCode,h="gasPrice"in e?e.gasPrice:void 0,o=h!=null?(0,g.mul)(h,e.gasUsed):"0";let l="0";if(u&&this.ethEngine.networkInfo.l1RollupParams!=null){const v=yield this.multicastServers("eth_getTransactionReceipt",[i]),E=tt(v.result.result);l=(0,g.add)(l,(0,p.X0)(E.l1Fee))}let c,d,f;u?a?(c=(0,g.sub)("0",e.value),d="0",f=(0,g.add)(o,l)):e.from.toLowerCase()===e.to.toLowerCase()?(c=(0,g.sub)((0,g.sub)("0",o),l),d=(0,g.add)(o,l)):(c=(0,g.sub)((0,g.sub)((0,g.sub)("0",e.value),o),l),d=(0,g.add)(o,l)):(c=e.value,d="0",r.push(this.ethEngine.walletLocalData.publicKey));const y={from:[e.from],to:[e.to],gas:e.gas,gasPrice:h!=null?h:"",gasUsed:e.gasUsed,isFromMakeSpend:!1};let k=parseInt(e.blockNumber);return k<0&&(k=0),{txid:i,date:parseInt(e.timeStamp),currencyCode:t,blockHeight:k,nativeAmount:c,isSend:c.startsWith("-"),networkFee:d,feeRateUsed:h!=null?Te(h,e.gas,e.gasUsed):void 0,parentNetworkFee:f,ourReceiveAddresses:r,signedTx:"",otherParams:y,walletId:this.walletId}})}processAlethioTransaction(e,t){let s;const r=[];let i;const u=t!==this.ethEngine.currencyInfo.currencyCode,a=e.attributes.value,h=e.attributes.fee?e.attributes.fee:"0",o=e.relationships.from.data.id,l=e.relationships.to.data.id;t===this.ethEngine.currencyInfo.currencyCode?i=h:i="0";const c=o.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase();if(c)o.toLowerCase()===l.toLowerCase()?s=(0,g.mul)(i,"-1"):(s=(0,g.sub)("0",a),u||(s=(0,g.sub)(s,i)));else if(l.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase())s=a,r.push(this.ethEngine.walletLocalData.publicKey.toLowerCase());else return null;const d={from:[o],to:[l],gas:"0",gasPrice:"0",gasUsed:"0",isFromMakeSpend:!1};let f=e.attributes.globalRank[0];f<0&&(f=0);let y,k="0";return u&&c?y=i:k=i,{txid:e.relationships.transaction.data.id,date:e.attributes.blockCreationTime,currencyCode:t,blockHeight:f,nativeAmount:s,isSend:s.startsWith("-"),networkFee:k,ourReceiveAddresses:r,signedTx:"",parentNetworkFee:y,otherParams:d,walletId:this.walletId}}fetchGetEtherscan(e,t){return w(this,null,function*(){const s=Be(this.ethEngine.initOptions,this.ethEngine.currencyInfo,this.ethEngine.log);e.indexOf("cors-http")===0&&(e=e.replace(/^cors-http/,"http"));const i=Array.isArray(s)?(0,p.sD)(s,1)[0]:s!=null?s:"",u=i!==""?`&apikey=${i}`:"",a=`${e}/api${t}`,h=yield this.ethEngine.fetchCors(`${a}${u}`);return h.ok||this.throwError(h,"fetchGetEtherscan",a),yield h.json()})}fetchGetBlockbook(e,t){return w(this,null,function*(){const s=e+t;return yield(e.includes("trezor")?yield this.ethEngine.fetchCors(s,{headers:{"User-Agent":"http.agent"}}):yield this.ethEngine.fetchCors(s)).json()})}fetchPostRPC(e,t,s,r){return w(this,null,function*(){const i={id:s,jsonrpc:"2.0",method:e,params:t},a=/{{(.*?)}}/g.exec(r);if(a!=null){const l=a[1],c=F(l),d=this.ethEngine.initOptions[c];if(typeof d=="string")r=r.replace(a[0],d);else throw d==null?new Error(`Missing ${c} in 'initOptions' for ${this.ethEngine.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const h=yield this.ethEngine.fetchCors(r,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(i)}),o=U()(r,{},!0);return h.ok||this.throwError(h,"fetchPostRPC",o.hostname),yield h.json()})}fetchPostBlockcypher(e,t,s){return w(this,null,function*(){const{blockcypherApiKey:r}=this.ethEngine.initOptions;let i="";r&&r.length>5&&(i="&token="+r);const u=`${s}/${e}${i}`,a=yield this.ethEngine.fetchCors(u,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(t)}),h=U()(u,{},!0);return a.ok||this.throwError(a,"fetchPostBlockcypher",h.hostname),yield a.json()})}fetchGetBlockchair(e,t=!1){return w(this,null,function*(){const{blockchairApiKey:s}=this.ethEngine.initOptions,{blockchairApiServers:r}=this.ethEngine.networkInfo,i=t&&s?`&key=${s}`:"",u=`${r[0]}${e}`,a=yield this.ethEngine.fetchCors(`${u}${i}`);return a.ok||this.throwError(a,"fetchGetBlockchair",u),yield a.json()})}fetchPostAmberdataRpc(e){return w(this,arguments,function*(t,s=[]){const{amberdataApiKey:r=""}=this.ethEngine.initOptions,{amberdataRpcServers:i}=this.ethEngine.networkInfo,u=`${i[0]}`,a={jsonrpc:"2.0",method:t,params:s,id:1},h=yield this.ethEngine.fetchCors(u,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":r,"Content-Type":"application/json"},method:"POST",body:JSON.stringify(a)}),o=U()(u,{},!0);return h.ok||this.throwError(h,"fetchPostAmberdataRpc",o),yield h.json()})}fetchGetAmberdataApi(e){return w(this,null,function*(){const{amberdataApiKey:t=""}=this.ethEngine.initOptions,{amberdataApiServers:s}=this.ethEngine.networkInfo,r=`${s[0]}${e}`,i=yield this.ethEngine.fetchCors(r,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":t}});return i.ok||this.throwError(i,"fetchGetAmberdata",r),yield i.json()})}fetchGetAlethio(e,t=!0,s){return w(this,null,function*(){const{alethioApiKey:r=""}=this.ethEngine.initOptions,{alethioApiServers:i}=this.ethEngine.networkInfo,u=t?`${i[0]}${e}`:e,a=yield this.ethEngine.fetchCors(u,r?{headers:{Authorization:`Bearer ${r}`}}:void 0);return a.ok||this.throwError(a,"fetchGetAlethio",u),yield a.json()})}broadcastEtherscan(e,t){return w(this,null,function*(){const s=`?module=proxy&action=eth_sendRawTransaction&hex=${e.signedTx}`,r=yield this.fetchGetEtherscan(t,s);return this.broadcastResponseHandler(r,t,e)})}broadcastRPC(e,t,s){return w(this,null,function*(){const r="eth_sendRawTransaction",i=[e.signedTx],u=yield this.fetchPostRPC(r,i,t,s),a=U()(s,{},!0);return this.broadcastResponseHandler(u,a,e)})}broadcastBlockCypher(e,t){return w(this,null,function*(){const s=`v1/${this.ethEngine.currencyInfo.currencyCode.toLowerCase()}/main/txs/push`,r=e.signedTx.replace("0x",""),i=yield this.fetchPostBlockcypher(s,{tx:r},t);return this.broadcastResponseHandler(i,t,e)})}broadcastBlockbook(e,t){return w(this,null,function*(){const s=yield this.fetchGetBlockbook(t,`/api/v2/sendtx/${e.signedTx}`);return this.broadcastResponseHandler(s,t,e)})}broadcastResponseHandler(e,t,s){if(typeof e.error<"u")throw this.ethEngine.error(`FAILURE ${t}
|
|
2
2
|
${JSON.stringify(e.error)}
|
|
3
3
|
${(0,p.oX)(s)}`),e.error;if(typeof e.result=="string")return this.ethEngine.warn(`SUCCESS ${t}
|
|
4
4
|
${(0,p.oX)(s)}`),e;throw this.ethEngine.error(`FAILURE ${t}
|
|
@@ -8,4 +8,4 @@ ${(0,p.HY)(k)}
|
|
|
8
8
|
${JSON.stringify(f[y])}`),new Error(`getAllTxsEthscan ${s.name} is invalid`)}if(f.length===0)break;u++}return{allTransactions:a,server:h}})}checkTxsEthscan(e){return w(this,null,function*(){const{startBlock:t,currencyCode:s}=e;let r,i;if(s===this.ethEngine.currencyInfo.currencyCode){const a=yield this.getAllTxsEthscan(t,s,W,{searchRegularTxs:!0}),h=yield this.getAllTxsEthscan(t,s,ge,{searchRegularTxs:!1});r=a.server||h.server,i=[...a.allTransactions,...h.allTransactions]}else{const a=this.ethEngine.getTokenInfo(s);if(a!=null&&typeof a.contractAddress=="string"){const h=a.contractAddress,o=yield this.getAllTxsEthscan(t,s,Ie,{contractAddress:h});r=o.server,i=o.allTransactions}else return{}}const u={blockHeight:t,edgeTransactions:i};return{tokenTxs:{[s]:u},server:r}})}getTokenCurrencyCode(e){const t=this.ethEngine.walletLocalData.publicKey;if(e.toLowerCase()===t.toLowerCase())return this.ethEngine.currencyInfo.currencyCode;for(const s of this.ethEngine.enabledTokens){const r=this.ethEngine.getTokenInfo(s);if(r!=null){const i=r.contractAddress;if(e&&typeof i=="string"&&i.toLowerCase()===e.toLowerCase())return s}}}checkAddressBlockbook(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey.toLowerCase(),s={newNonce:"0",tokenBal:{},server:""},r="/api/v2/address/"+t+"?&details=tokenBalances",{result:i,server:u}=yield this.multicastServers("blockbookAddress",r);let a;try{a=Qe(i)}catch{throw this.ethEngine.error(`checkTxsBlockbook ${u} error BlockbookAddress ${JSON.stringify(i)}`),new Error(`checkTxsBlockbook ${u} returned invalid JSON for BlockbookAddress`)}const{nonce:h,tokens:o,balance:l}=a;s.newNonce=h,s.tokenBal!=null&&(s.tokenBal[this.ethEngine.currencyInfo.currencyCode]=l),s.server=u;for(const c of o)try{const{symbol:d,balance:f}=Le(c);s.tokenBal[d]=f}catch{throw this.ethEngine.error(`checkTxsBlockbook ${u} BlockbookTokenBalance ${JSON.stringify(c)}`),new Error(`checkTxsBlockbook ${u} returned invalid JSON for BlockbookTokenBalance`)}return s})}checkTokenBalEthscan(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey;let s,r,i,u;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",t),r=s.result,i=s.server;else{const a=this.ethEngine.getTokenInfo(e);if(a!=null&&typeof a.contractAddress=="string"){const h=a.contractAddress,o=yield this.multicastServers("getTokenBalance",t,h);r=o.result,i=o.server}}u=Y(r)}catch(a){throw this.ethEngine.error(`checkTokenBalEthscan token ${e} response ${s||""} `,a),new Error(`checkTokenBalEthscan invalid ${e} response ${JSON.stringify(r)}`)}if(/^\d+$/.test(u.result)){const a=u.result;return{tokenBal:{[e]:a},server:i}}else throw new Error(`checkTokenBalEthscan returned invalid JSON for ${e}`)})}checkTokenBalBlockchair(){return w(this,null,function*(){let e;const t=this.ethEngine.walletLocalData.publicKey,s=`/${this.ethEngine.currencyInfo.pluginId}/dashboards/address/${t}?erc_20=true`;try{const i=yield this.fetchGetBlockchair(s,!1);e=qe(i)}catch(i){throw this.logError("checkTokenBalBlockchair",i),new Error("checkTokenBalBlockchair response is invalid")}const r={[this.ethEngine.currencyInfo.currencyCode]:e.data[t].address.balance};for(const i of e.data[t].layer_2.erc_20)try{const u=Ye(i),a=u.balance,h=u.token_address,o=u.token_symbol,l=this.ethEngine.getTokenInfo(o);l!=null&&l.contractAddress===h&&(r[o]=a)}catch(u){throw this.ethEngine.error(`checkTokenBalBlockchair tokenData ${(0,p.HY)(u)}
|
|
9
9
|
${JSON.stringify(i)}`),new Error("checkTokenBalBlockchair tokenData is invalid")}return{tokenBal:r,server:"blockchair"}})}checkTokenBalRpc(e){return w(this,null,function*(){let t,s,r,i;const u=this.ethEngine.walletLocalData.publicKey;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",u),r=s.result,i=s.server;else{const a=this.ethEngine.getTokenInfo(e);if(a!=null&&typeof a.contractAddress=="string"){const h={data:`0x70a08231${(0,p.gc)((0,p.KT)(u),32)}`,to:a.contractAddress},o=yield this.multicastServers("eth_call",h),l=o.result.result;if(!l.startsWith("0x"))throw new Error("Invalid return value. Result not hex");o.result.result=(0,p.Z8)(l),r=o.result,i=o.server}}t=Y(r)}catch(a){throw this.ethEngine.error(`checkTokenBalRpc token ${e} response ${s||""} `,a),new Error(`checkTokenBalRpc invalid ${e} response ${JSON.stringify(r)}`)}return{tokenBal:{[e]:t.result},server:i}})}checkAndUpdate(e=0,t,s,r){return w(this,null,function*(){const i=Date.now();if(i-e>t)try{const u=yield r();this.processEthereumNetworkUpdate(i,u,s)}catch(u){this.ethEngine.error("checkAndUpdate ",u)}})}getQueryHeightWithLookback(e){return e>De?e-De:0}getQueryDateWithLookback(e){return e>Xe?e-Xe:0}needsLoop(){return w(this,null,function*(){for(;this.ethEngine.engineOn;){const e=this.ethEngine.walletLocalData.blockHeight;yield this.checkAndUpdate(this.ethNeeds.blockHeightLastChecked,Ot,e,()=>w(this,null,function*(){return yield this.check("blockheight")})),yield this.checkAndUpdate(this.ethNeeds.nonceLastChecked,xt,e,()=>w(this,null,function*(){return yield this.check("nonce")}));const{currencyCode:t}=this.ethEngine.currencyInfo,s=this.ethEngine.enabledTokens;s.includes(t)||s.push(t);for(const r of s)yield this.checkAndUpdate(this.ethNeeds.tokenBalLastChecked[r],Bt,e,()=>w(this,null,function*(){return yield this.check("tokenBal",r)})),yield this.checkAndUpdate(this.ethNeeds.tokenTxsLastChecked[r],Nt,e,()=>w(this,null,function*(){return yield this.check("txs",{startBlock:this.getQueryHeightWithLookback(this.ethEngine.walletLocalData.lastTransactionQueryHeight[r]),startDate:this.getQueryDateWithLookback(this.ethEngine.walletLocalData.lastTransactionDate[r]),currencyCode:r})}));yield(0,p.HB)(1e3)}})}processEthereumNetworkUpdate(e,t,s){if(!!t){if(t.blockHeight){this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate blockHeight ${t.server||"no server"} won`);const r=t.blockHeight;this.ethEngine.log(`Got block height ${r||"no blockheight"}`),typeof r=="number"&&this.ethEngine.walletLocalData.blockHeight!==r&&(this.ethNeeds.blockHeightLastChecked=e,this.ethEngine.checkDroppedTransactionsThrottled(),this.ethEngine.walletLocalData.blockHeight=r,this.ethEngine.walletLocalDataDirty=!0,this.ethEngine.currencyEngineCallbacks.onBlockHeightChanged(this.ethEngine.walletLocalData.blockHeight))}if(t.newNonce&&(this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate nonce ${t.server||"no server"} won`),this.ethNeeds.nonceLastChecked=e,this.ethEngine.otherData.nextNonce=t.newNonce,this.ethEngine.walletLocalDataDirty=!0),t.tokenBal!=null){const r=t.tokenBal;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenBal ${t.server||"no server"} won`);for(const i of Object.keys(r))this.ethNeeds.tokenBalLastChecked[i]=e,this.ethEngine.updateBalance(i,r[i])}if(t.tokenTxs!=null){const r=t.tokenTxs;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenTxs ${t.server||"no server"} won`);for(const i of Object.keys(r)){this.ethNeeds.tokenTxsLastChecked[i]=e,this.ethEngine.tokenCheckTransactionsStatus[i]=1;const u=r[i];if(u.edgeTransactions){for(const a of u.edgeTransactions)this.ethEngine.addTransaction(i,a);this.ethEngine.walletLocalData.lastTransactionQueryHeight[i]=s,this.ethEngine.walletLocalData.lastTransactionDate[i]=e}}this.ethEngine.updateOnAddressesChecked()}this.ethEngine.transactionsChangedArray.length>0&&(this.ethEngine.currencyEngineCallbacks.onTransactionsChanged(this.ethEngine.transactionsChangedArray),this.ethEngine.transactionsChangedArray=[])}}buildQueryFuncs(e){const{rpcServers:t,evmScanApiServers:s,blockbookServers:r,blockchairApiServers:i,amberdataRpcServers:u,amberdataApiServers:a}=e,h=[],o=[],l=[],c=[];return s.length>0&&(h.push(this.checkBlockHeightEthscan),o.push(this.checkNonceEthscan),c.push(this.checkTokenBalEthscan)),l.push(this.checkTxsEthscan),r.length>0&&(h.push(this.checkBlockHeightBlockbook),c.push(this.checkAddressBlockbook),o.push(this.checkAddressBlockbook)),i.length>0&&(h.push(this.checkBlockHeightBlockchair),c.push(this.checkTokenBalBlockchair)),u.length>0&&(h.push(this.checkBlockHeightAmberdata),o.push(this.checkNonceAmberdata)),a.length>0,t.length>0&&(o.push(this.checkNonceRpc),c.push(this.checkTokenBalRpc)),{blockheight:h,nonce:o,txs:l,tokenBal:c}}throwError(e,t,s){switch(e.status){case 402:case 429:case 432:throw new Error("rateLimited");default:throw new Error(`${t} The server returned error code ${e.status} for ${s}`)}}logError(e,t){(0,p.HY)(t).includes("rateLimited")?this.ethEngine.log(e,t):this.ethEngine.error(e,t)}}const _t="low",Dt="standard",Xt="high",Ke="custom",He="1000000000";function Ge(m,e,t,s){var r,i,u,a,h,o,l,c,d;let f=!0,y,k;const{customNetworkFee:b}=m!=null?m:{};if(m.networkFeeOption===Ke&&b!=null){const{gasLimit:x,gasPrice:N}=b;if((isNaN(x)||x==="")&&(isNaN(N)||N==="")){const $=new Error("Custom Fee must have at least gasLimit or gasPrice specified");throw $.name="ErrorBelowMinimumFee",$}if(N!=null&&N!==""){const $=(a=(i=(r=e.default)==null?void 0:r.gasPrice)==null?void 0:i.minGasPrice)!=null?a:(u=s.defaultNetworkFees.default.gasPrice)==null?void 0:u.minGasPrice;if($!=null){const G=(0,g.mul)(N,He);if((0,g.lt)(G,$)||/^\s*$/.test(N)){const ve=new Error(`Gas price ${G} wei below minimum ${$} wei`);throw ve.name="ErrorBelowMinimumFee",ve}}k=(0,g.mul)(N,He)}if(x!=null&&x!==""){const $=(c=(o=(h=e.default)==null?void 0:h.gasLimit)==null?void 0:o.minGasLimit)!=null?c:(l=s.defaultNetworkFees.default.gasLimit)==null?void 0:l.minGasLimit;if($!=null&&(0,g.lt)(x,$)||/^\s*$/.test(x)){const G=new Error(`Gas limit ${x} below minimum ${$}`);throw G.name="ErrorBelowMinimumFee",G}y=x,f=!1}}if(y!=null&&k!=null)return{gasLimit:y,gasPrice:k,useEstimatedGasLimit:!1};let v=e.default,E=e.default;if(typeof((d=m.spendTargets[0])==null?void 0:d.publicAddress)=="string"){const x=(0,p.f0)(m.spendTargets[0].publicAddress);typeof e[x]<"u"&&(E=e[x],f=!1,typeof E.gasPrice<"u"&&(v=E))}let C="regularTransaction";m.currencyCode!=null&&m.currencyCode!==t.currencyCode&&(C="tokenTransaction");let I="standard";typeof m.networkFeeOption=="string"&&m.networkFeeOption!==Ke&&(I=m.networkFeeOption);const _=E.gasLimit!=null?E.gasLimit[C]:"21000";let X="";if(m.spendTargets[0].nativeAmount==null)throw new Error("ErrorInvalidNativeAmount");let H=m.spendTargets[0].nativeAmount;if(C==="tokenTransaction"&&(H=(0,g.div)(H,"10")),v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");const L=v.gasPrice;switch(I){case _t:X=L.lowFee;break;case Dt:{if((0,g.gte)(H,v.gasPrice.standardFeeHighAmount)){X=L.standardFeeHigh;break}if((0,g.lte)(H,L.standardFeeLowAmount)){if(v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");X=v.gasPrice.standardFeeLow;break}const x=(0,g.sub)(L.standardFeeHighAmount,L.standardFeeLowAmount),N=(0,g.sub)(L.standardFeeHigh,L.standardFeeLow),$=(0,g.sub)(H,L.standardFeeLowAmount),G=(0,g.mul)($,N),ve=(0,g.div)(G,x);X=(0,g.add)(L.standardFeeLow,ve);break}case Xt:X=v.gasPrice.highFee;break;default:throw new Error("Invalid networkFeeOption")}return{gasLimit:y!=null?y:_,gasPrice:k!=null?k:X,useEstimatedGasLimit:f}}const Kt="1040",je=m=>{const{chainParams:e,data:t,dynamicOverhead:s,fixedOverhead:r,gasPriceL1Wei:i,gasLimit:u,nonce:a,to:h,value:o="0x0"}=m,l=Oe().custom(e),f=xe.Transaction.fromTxData({nonce:a!=null?(0,p.X0)(a):void 0,gasPrice:(0,p.X0)(i),gasLimit:(0,p.X0)(u),to:h,value:o,data:t},{common:l}).raw().map(E=>E.toString("hex")).join().match(/(.{1,2})/g);if(f==null)throw new Error("Invalid rawTx string");let y=0;for(let E=0;E<f.length;E++)f[E]==="00"?y+=4:y+=16;const k=(0,g.add)((0,g.add)(y.toString(),r),Kt),b=(0,g.div)(s,"1000000",18);return(0,g.mul)((0,g.mul)(i,k),b)};var V=P(48764).Buffer,Ht=Object.defineProperty,Gt=Object.defineProperties,jt=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,Mt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,Zt=Reflect.get,Ue=(m,e,t)=>e in m?Ht(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,re=(m,e)=>{for(var t in e||(e={}))Ut.call(e,t)&&Ue(m,t,e[t]);if(Me)for(var t of Me(e))Jt.call(e,t)&&Ue(m,t,e[t]);return m},fe=(m,e)=>Gt(m,jt(e)),Ae=(m,e,t)=>Zt(Mt(m),t,e),R=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});class me extends ct.P{constructor(e,t,s,r,i,u){super(e,t,s,i),this.updateNetworkFeesFromBaseFeePerGas=()=>R(this,null,function*(){var o;const{supportsEIP1559:l=!1}=this.networkInfo;if(!l)return;const{baseFeePerGas:c}=yield this.ethNetwork.getBaseFeePerGas();if(c==null)return;const d=(0,p.Z8)(c),f=this.networkFees;if(f.default==null||f.default.gasPrice==null)return;const y=this.networkInfo.defaultNetworkFees.default,k=f.default.minPriorityFee||y.minPriorityFee,b=(o=f.default.baseFeeMultiplier)!=null?o:y.baseFeeMultiplier;if(k==null||b==null)return;const v={lowFee:"",standardFeeLow:"",standardFeeHigh:"",highFee:""};for(const E of Object.keys(b)){const C=(0,g.mul)(b[E],d),I=(0,g.add)(C,k);v[E]=(0,g.div)(I,"1")}return this.log(`updateNetworkFeesFromBaseFeePerGas ${this.currencyInfo.currencyCode}`),Ee(this.log,v),v}),this.initOptions=r,this.networkInfo=e.networkInfo,this.ethNetwork=new Rt(this),this.lastEstimatedGasLimit={publicAddress:"",contractAddress:"",gasLimit:""},this.networkInfo.l1RollupParams!=null&&(this.l1RollupParams=this.networkInfo.l1RollupParams),this.networkFees=this.networkInfo.defaultNetworkFees,this.fetchCors=(0,p.zR)(e.io);const{infoFeeProvider:a,externalFeeProviders:h}=wt(this.fetchCors,this.currencyInfo,this.initOptions,this.log,this.networkInfo);this.infoFeeProvider=a,this.externalFeeProviders=[...h,this.updateNetworkFeesFromBaseFeePerGas],this.utils={signMessage:(o,l)=>{if(!(0,p.vq)(o))throw new Error("ErrorInvalidMessage");const c=V.from(l.privateKey,"hex"),d=(0,p.ah)(o),f=A().hashPersonalMessage(d),{v:y,r:k,s:b}=A().ecsign(f,c);return A().toRpcSig(y,k,b)},signTypedData:(o,l)=>{const c=kt(o),d=V.from(l.privateKey,"hex"),{types:f}=c;function y(L,K=[]){if(K.includes(L)||f[L]===void 0)return K;K.push(L);for(const x of f[L])for(const N of y(x.type,K))K.includes(N)||K.push(N);return K}function k(L){let K=y(L);K=K.filter(N=>N!==L),K=[L].concat(K.sort());let x="";for(const N of K)x+=`${N}(${f[N].map(({name:$,type:G})=>`${G} ${$}`).join(",")})`;return x}function b(L){return A().keccak256(k(L))}function v(L,K){const x=[],N=[];x.push("bytes32"),N.push(b(L));for(const $ of f[L]){let G=K[$.name];if($.type==="string"||$.type==="bytes")x.push("bytes32"),G=A().keccak256(G),N.push(G);else if(f[$.type]!==void 0)x.push("bytes32"),G=A().keccak256(v($.type,G)),N.push(G);else{if($.type.lastIndexOf("]")===$.type.length-1)throw new Error("Arrays currently unimplemented in encodeData");x.push($.type),N.push(G)}}return Pe().rawEncode(x,N)}function E(L,K){return A().keccak256(v(L,K))}function C(){return A().keccak256(V.concat([V.from("1901","hex"),E("EIP712Domain",c.domain),E(c.primaryType,c.message)]))}const I=A().ecsign(C(),d),{v:_,r:X,s:H}=I;return A().bufferToHex(V.concat([A().setLengthLeft(X,32),A().setLengthLeft(H,32),A().toBuffer(_)]))},txRpcParamsToSpendInfo:o=>{const l={otherParams:o};o.to!=null&&(l.publicAddress=o.to),o.value!=null?l.nativeAmount=(0,p.Z8)(o.value):l.nativeAmount="0";let c,d,f;return o.gas!=null&&(d=(0,p.Z8)(o.gas),c="custom"),o.gasPrice!=null&&(f=(0,g.div)((0,p.Z8)(o.gasPrice),se.toString(),18),c="custom"),{currencyCode:this.currencyInfo.currencyCode,spendTargets:[l],networkFeeOption:c,customNetworkFee:{gasLimit:d,gasPrice:f},otherParams:o}}},this.otherMethods={parseWalletConnectV2Payload:o=>R(this,null,function*(){var l,c;try{let d="0",f="0";switch(o.method){case"eth_sendTransaction":case"eth_signTransaction":{const y=(0,n.su)({from:n.XC,to:(0,n.Zz)(n.XC),data:n.XC,gas:(0,n.Zz)(n.XC),gasPrice:(0,n.Zz)(n.XC),value:(0,n.Zz)(n.XC)})(o.params[0]),{gas:k,gasPrice:b,value:v}=y,E=C=>{var I,_;k==null?y.gas=(0,p.X0)(C):C=(0,p.Z8)(k);let X=(_=(I=this.networkFees.default.gasPrice)==null?void 0:I.standardFeeHigh)!=null?_:"0";b==null?y.gasPrice=(0,p.X0)(X):X=(0,p.Z8)(b),f=(0,g.mul)(C,X)};v!=null&&(d=(0,p.Z8)(v)),((l=this.networkFees.default.gasLimit)==null?void 0:l.tokenTransaction)==null?this.ethNetwork.multicastServers("eth_estimateGas",y).then(C=>{const I=(0,g.add)(parseInt(C.result.result,16).toString(),"0");E(I)}).catch(C=>{this.warn("Wallet connect call_request failed to get gas limit",C)}):E((c=this.networkFees.default.gasLimit)==null?void 0:c.tokenTransaction);break}}return{nativeAmount:d,networkFee:f}}catch(d){throw this.warn("Wallet connect call_request ",d),d}}),txRpcParamsToSpendInfo:o=>R(this,null,function*(){return this.utils.txRpcParamsToSpendInfo(o)})}}estimateGasLimit(e){return R(this,null,function*(){var t,s;const{contractAddress:r,estimateGasParams:i,miningFees:u,publicAddress:a}=e,h=i[0].data!=null;if(this.lastEstimatedGasLimit.gasLimit!==""&&this.lastEstimatedGasLimit.publicAddress===a&&this.lastEstimatedGasLimit.contractAddress===r)return this.lastEstimatedGasLimit.gasLimit;let o=u.gasLimit;try{const c=(yield this.ethNetwork.multicastServers("eth_getCode",[i[0].to,"latest"])).result.result!=="0x",d=(f=0)=>R(this,null,function*(){const y=this.networkInfo.defaultNetworkFees.default.gasLimit;try{if(y!=null&&!c&&!h)o=y.regularTransaction;else{const k=yield this.ethNetwork.multicastServers("eth_estimateGas",i);o=(0,g.add)(parseInt(k.result.result,16).toString(),"0"),c&&(o=(0,g.mul)(o,"2"))}this.lastEstimatedGasLimit={publicAddress:a,contractAddress:r,gasLimit:o}}catch{if(y==null){if(f>5)throw new Error("Unable to estimate gas limit after 5 tries. Please try again later");return yield d(f+1)}if(h)throw new Error("Unable to estimate gas limit. Please try again later");y.tokenTransaction!=null&&(o=y.tokenTransaction)}});if(yield d(),(0,g.lt)(o,(s=(t=this.networkFees.default.gasLimit)==null?void 0:t.minGasLimit)!=null?s:"21000"))throw o=u.gasLimit,this.lastEstimatedGasLimit.gasLimit="",new Error("Calculated gasLimit less than minimum")}catch(l){this.error("makeSpend Error determining gas limit ",l)}return o})}setOtherData(e){this.otherData=pe(e)}updateNetworkFees(){return R(this,null,function*(){for(const e of this.externalFeeProviders)try{const t=yield e();if(t==null)continue;const s={};Object.keys(t).forEach(r=>{const i=r;s[i]=(0,p.Y7)(t[i])}),this.networkFees.default.gasPrice!=null&&(this.networkFees.default.gasPrice=re(re({},this.networkFees.default.gasPrice),s));break}catch(t){this.error(`Error fetching fees from ${e.name}. ${JSON.stringify(t)}`)}})}updateL1RollupParams(){return R(this,null,function*(){if(this.l1RollupParams!=null){try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.gasPricel1BaseFeeMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{gasPriceL1Wei:(0,g.ceil)((0,g.mul)((0,p.Z8)(s.result),this.l1RollupParams.maxGasPriceL1Multiplier),0)})}catch(e){this.log.warn("Failed to update l1GasPrice",e)}try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.dynamicOverheadMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{dynamicOverhead:(0,p.Z8)(s.result)})}catch(e){this.log.warn("Failed to update dynamicOverhead",e)}}})}clearBlockchainCache(){return R(this,null,function*(){yield Ae(me.prototype,this,"clearBlockchainCache").call(this),this.otherData.nextNonce="0",this.otherData.unconfirmedNextNonce="0"})}startEngine(){return R(this,null,function*(){var e;this.engineOn=!0;const t=(e=this.networkInfo.feeUpdateFrequencyMs)!=null?e:ht;this.infoFeeProvider().then(s=>{this.log.warn("infoFeeProvider:",JSON.stringify(s,null,2)),this.networkFees=(0,p.nu)(this.networkFees,s)}).catch(()=>this.warn("Error fetching fees from Info Server")).finally(()=>R(this,null,function*(){return yield this.addToLoop("updateNetworkFees",t)})),this.addToLoop("updateL1RollupParams",ut).catch(()=>{}),this.ethNetwork.needsLoop(),Ae(me.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return R(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return R(this,null,function*(){const{publicKey:e}=this.walletLocalData;return{publicAddress:/[A-F]/.test(e)?e:A().toChecksumAddress(e.replace("0x",""))}})}getMaxSpendable(e){return R(this,null,function*(){const{edgeSpendInfo:t,currencyCode:s}=this.makeSpendCheck(e),r=this.getBalance({currencyCode:e.currencyCode}),u=e.spendTargets[0].publicAddress;if(u==null)throw new Error("makeSpend Missing publicAddress");const{contractAddress:a,data:h,value:o}=this.getTxParameterInformation(t,s,this.currencyInfo);if(e.currencyCode===this.currencyInfo.currencyCode){const l=(c,d)=>R(this,null,function*(){const f=(0,g.sub)(d,c);if((0,g.lte)(f,"1"))return c;const y=(0,g.add)(c,(0,g.div)(f,"2"));e.spendTargets[0].nativeAmount=y;const k=Ge(e,this.networkFees,this.currencyInfo,this.networkInfo);k.useEstimatedGasLimit&&(k.gasLimit=yield this.estimateGasLimit({contractAddress:a,estimateGasParams:[{to:a!=null?a:u,from:this.walletLocalData.publicKey,gas:"0xffffff",value:o,data:h},"latest"],miningFees:k,publicAddress:u}));const b=(0,g.mul)(k.gasPrice,k.gasLimit);let v="0";if(this.l1RollupParams!=null){const C={nonce:this.otherData.unconfirmedNextNonce,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:k.gasLimit,to:u,value:(0,p.X0)(y),chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};v=je(C)}const E=(0,g.add)((0,g.add)(y,b),v);return(0,g.gt)(E,r)?yield l(c,y):yield l(y,d)});return yield l("0",(0,g.add)(r,"1"))}else return e.spendTargets[0].nativeAmount=r,yield this.makeSpend(e),this.getBalance({currencyCode:e.currencyCode})})}getTxParameterInformation(e,t,s){var r,i;const{spendTargets:u}=e,a=u[0],{publicAddress:h,nativeAmount:o}=a;let l=(i=a.memo)!=null?i:(r=a.otherParams)==null?void 0:r.data;if(l!=null&&l.length>0&&!(0,p.vq)(l))throw new Error("Memo/data field must be of type 'hex'");l===""&&(l=void 0);let c;if(t===s.currencyCode)return c=o==null?void 0:(0,p.X0)(o),{data:l,value:c};{let d;if(l!=null)d=h;else{const f=this.getTokenInfo(t);if(f==null||typeof f.contractAddress!="string")throw new Error("Error: Token not supported or invalid contract address");d=f.contractAddress;const y=Pe().simpleEncode("transfer(address,uint256):(uint256)",h,(0,p.X0)(o!=null?o:"0"));c="0x0",l="0x"+V.from(y).toString("hex")}return{contractAddress:d,data:l,value:c}}}makeSpend(e){return R(this,null,function*(){var t,s;const{edgeSpendInfo:r,currencyCode:i,skipChecks:u}=this.makeSpendCheck(e),{pendingTxs:a=[]}=r;if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const h=r.spendTargets[0],{publicAddress:o}=h;let{nativeAmount:l}=h;if(o==null)throw new Error("makeSpend Missing publicAddress");if(l==null)throw new ne.$D;if(!A().isValidAddress(o))throw new TypeError(`Invalid ${this.currencyInfo.pluginId} address`);let c;const d=Ge(r,this.networkFees,this.currencyInfo,this.networkInfo);let f;if(a.length>0){const H=this.walletLocalData.otherData,L=this.walletLocalData.numUnconfirmedSpendTxs>0?H.unconfirmedNextNonce:H.nextNonce;f=(0,g.add)(L,a.length.toString())}const{contractAddress:y,data:k,value:b}=this.getTxParameterInformation(r,i,this.currencyInfo);y==null?c={from:[this.walletLocalData.publicKey],to:[o],gas:d.gasLimit,gasPrice:d.gasPrice,gasUsed:"0",nonceUsed:f,data:k,isFromMakeSpend:!0}:c={from:[this.walletLocalData.publicKey],to:[y],gas:d.gasLimit,gasPrice:d.gasPrice,gasUsed:"0",tokenRecipientAddress:o,nonceUsed:f,data:k,isFromMakeSpend:!0},d.useEstimatedGasLimit&&(c.gas=yield this.estimateGasLimit({contractAddress:y,estimateGasParams:[{to:y!=null?y:o,from:this.walletLocalData.publicKey,gas:"0xffffff",value:b,data:k},"latest"],miningFees:d,publicAddress:o}));const v=(t=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?t:"0";let E=(0,g.mul)(d.gasPrice,c.gas),C="0",I=null,_="0";if(this.l1RollupParams!=null){const H={nonce:c.nonceUsed,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:c.gas,to:c.to[0],value:b,data:c.data,chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};_=je(H)}if(i===this.currencyInfo.currencyCode){if(E=(0,g.add)(E,_),C=(0,g.add)(E,l),!u&&(0,g.gt)(C,v))throw new ne.C_;l=(0,g.mul)(C,"-1")}else{if(I=(0,g.add)(E,_),!u&&(0,g.gt)(E,v))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:E});const H=(s=this.walletLocalData.totalBalances[i])!=null?s:"0";if(!u&&(0,g.gt)(l,H))throw new ne.C_;E="0",l=(0,g.mul)(l,"-1")}const X={txid:"",date:0,currencyCode:i,blockHeight:0,nativeAmount:l,isSend:l.startsWith("-"),networkFee:E,feeRateUsed:Te(d.gasPrice,c.gas),ourReceiveAddresses:[],signedTx:"",otherParams:c,walletId:this.walletId};return I&&(X.parentNetworkFee=I),X})}signMessage(e,t,s){return R(this,null,function*(){const r=Ce(this.currencyInfo.pluginId)(t);if(nt(s.otherParams).typedData){const u=JSON.parse(e);try{return this.utils.signTypedData(u,r)}catch{return(0,rt.signTypedData_v4)(V.from(r.privateKey,"hex"),{data:u})}}return this.utils.signMessage(e,r)})}signTx(e,t){return R(this,null,function*(){const s=Ce(this.currencyInfo.pluginId)(t),r=(0,p.Xp)(e),i=(0,p.NC)(r.gas),u=(0,p.NC)(r.gasPrice);let a;if(e.currencyCode===this.currencyInfo.currencyCode){const E=(0,g.add)(e.nativeAmount,e.networkFee);a=(0,g.mul)("-1",E,16)}else a=(0,g.mul)("-1",e.nativeAmount,16);(0,g.lt)(a,"0")&&(a="0x00");let h=r.nonceUsed;if(!h)if(this.walletLocalData.numUnconfirmedSpendTxs&&(0,g.gt)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce)){const E=(0,g.sub)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce);if((0,g.lte)(E,"5"))h=this.otherData.unconfirmedNextNonce,this.walletLocalDataDirty=!0;else{const C=new Error("Excessive pending spend transactions");throw C.name="ErrorExcessivePendingSpends",C}}else h=this.otherData.nextNonce;const o=(0,p.NC)(h);let l;if(r.data!=null)l=r.data,e.currencyCode!==this.currencyInfo.currencyCode&&(a="0x00");else if(e.currencyCode===this.currencyInfo.currencyCode)l="";else{const E=Pe().simpleEncode("transfer(address,uint256):(uint256)",r.tokenRecipientAddress,a);l="0x"+V.from(E).toString("hex"),a="0x00"}const{chainParams:c}=this.networkInfo,d=Oe().custom(c),f={nonce:o,gasPrice:u,gasLimit:i,to:r.to[0],value:a,data:l},y=V.from(s.privateKey,"hex"),k=at().fromPrivateKey(y);this.warn(`signTx getAddressString ${k.getAddressString()}`);const v=xe.Transaction.fromTxData(f,{common:d}).sign(y);return e.signedTx=(0,p.$9)(v.serialize()),e.txid=(0,p.$9)(v.hash()),e.date=Date.now()/1e3,e.otherParams!=null&&(e.otherParams.nonceUsed=h),this.warn(`signTx
|
|
10
10
|
${(0,p.oX)(e)}`),e})}broadcastTx(e){return R(this,null,function*(){return yield this.ethNetwork.multicastServers("broadcastTx",e),this.warn(`SUCCESS broadcastTx
|
|
11
|
-
${(0,p.oX)(e)}`),e})}accelerate(e){return R(this,null,function*(){var t,s,r;const{currencyCode:i}=e,u=(0,n.Vk)(te)(e.otherParams);let a=e.txid,h=yield this.findTransaction(i,(0,p.f0)(a));if(h===-1&&((u==null?void 0:u.replacedTxid)!=null&&u.replacedTxid!==""&&(a=u.replacedTxid,h=yield this.findTransaction(i,(0,p.f0)(a))),h===-1))return null;const o=this.transactionList[i][h],l=(0,n.Vk)(te)(o.otherParams);if(o==null||o.blockHeight!==0||l==null||l.nonceUsed==null||!l.isFromMakeSpend)return null;const c=((t=o.spendTargets)!=null?t:[])[0];if(c==null)return null;const d=(0,g.mul)(l.gasPrice,"2"),f=l.gas,y=fe(re({},l),{gas:f,gasPrice:d,replacedTxid:a});let{nativeAmount:k}=c,b=(0,g.mul)(d,f),v="0",E;const C=(s=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?s:"0";if(i===this.currencyInfo.currencyCode){if(v=(0,g.add)(b,k),(0,g.gt)(v,C))throw new ne.C_;k=(0,g.mul)(v,"-1")}else{if(E=b,(0,g.gt)(b,C))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:b});const I=(r=this.walletLocalData.totalBalances[i])!=null?r:"0";if((0,g.gt)(k,I))throw new ne.C_;b="0",k=(0,g.mul)(k,"-1")}return fe(re({},e),{txid:"",feeRateUsed:Te(d,f),nativeAmount:k,networkFee:b,otherParams:y,parentNetworkFee:E})})}saveTx(e){return R(this,null,function*(){var t;const s=(0,n.Vk)(te)(e.otherParams);if((s==null?void 0:s.replacedTxid)!=null){const{currencyCode:r}=e,i=(0,p.f0)(s.replacedTxid),u=this.findTransaction(r,i);if(u!==-1){const a=this.transactionList[r][u],h=e.metadata,o=fe(re({},a),{metadata:h,blockHeight:-1});this.addTransaction(r,o)}}if(e.blockHeight===0){const r=(t=e.otherParams)==null?void 0:t.nonceUsed;r!=null&&(this.otherData.unconfirmedNextNonce=(0,g.add)(r,"1"))}Ae(me.prototype,this,"saveTx").call(this,e)})}}function Wt(m,e,t,s){return R(this,null,function*(){const{currencyInfo:r,initOptions:i}=m,u=Fe(t),a=new me(m,e,u,Z(i),s,r);return yield a.loadEngine(),a})}var zt=Object.defineProperty,Vt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,Yt=Object.prototype.hasOwnProperty,qt=Object.prototype.propertyIsEnumerable,Ze=(m,e,t)=>e in m?zt(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,We=(m,e)=>{for(var t in e||(e={}))Yt.call(e,t)&&Ze(m,t,e[t]);if(Je)for(var t of Je(e))qt.call(e,t)&&Ze(m,t,e[t]);return m},ze=(m,e)=>Vt(m,Qt(e)),z=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});class Ve{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:i}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=i}getDisplayPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo;return Ce(t)(e.keys).privateKey})}getDisplayPublicKey(e){return z(this,null,function*(){const{keys:t}=Fe(e);return t.publicKey})}importPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{pluginMnemonicKeyName:s,pluginRegularKeyName:r}=this.networkInfo;if(/^(0x)?[0-9a-fA-F]{64}$/.test(e)){const i=q.Buffer.from(e.replace(/^0x/,""),"hex");if(!A().isValidPrivate(i))throw new Error("Invalid private key");const u=i.toString("hex"),a={[r]:u};return this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:a}),a}else{if(!(0,J.validateMnemonic)(e))throw new Error("Invalid input");const i=yield this._mnemonicToHex(e);return{[s]:e,[r]:i}}})}createPrivateKey(e){return z(this,null,function*(){const{pluginMnemonicKeyName:t,pluginRegularKeyName:s}=this.networkInfo;if(e.replace("wallet:","")!==this.currencyInfo.pluginId)throw new Error("InvalidWalletType");const i=q.Buffer.from(this.io.random(32)),u=(0,J.entropyToMnemonic)(i),a=yield this._mnemonicToHex(u);return{[t]:u,[s]:a}})}derivePublicKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{hdPathCoinType:s,pluginMnemonicKeyName:r,pluginRegularKeyName:i}=this.networkInfo;if(e.type!==`wallet:${t}`)throw new Error("Invalid wallet type");let u;if(e.keys[r]!=null){const a=(0,J.mnemonicToSeedSync)(e.keys[r]),h=ae().fromMasterSeed(a),o=`m/44'/${s}'/0'/0`,d=h.derivePath(`${o}/0`).getWallet().getPublicKey(),f=A().pubToAddress(d).toString("hex");u=A().toChecksumAddress(f)}else{const a=q.Buffer.from(e.keys[i].replace(/^0x/,""),"hex");if(!A().isValidPrivate(a))throw new Error("Invalid private key");u=`0x${A().privateToAddress(a).toString("hex")}`}if(!A().isValidAddress(u))throw new Error("Invalid address");return{publicKey:u}})}_mnemonicToHex(e){return z(this,null,function*(){const{hdPathCoinType:t}=this.networkInfo,s=ae().fromMasterSeed((0,J.mnemonicToSeedSync)(e)),r=`m/44'/${t}'/0'/0`;return s.derivePath(`${r}/0`).getWallet().getPrivateKeyString().replace(/^0x/,"")})}parseUri(e,t,s){return z(this,null,function*(){var r,i,u,a,h;const o={};this.networkInfo.uriNetworks.forEach(k=>{o[k]=!0});const{parsedUri:l,edgeParsedUri:c}=(0,j.k)(this.currencyInfo,e,o,t||this.currencyInfo.currencyCode,s);let d="";c.publicAddress&&(d=c.publicAddress,c.publicAddress=c.publicAddress.toLowerCase());let[f,y]=d.split("-");if(y||(y=f,f="pay"),d=y,/[A-F]/.test(d)&&!A().isValidChecksumAddress(d))throw new Error("InvalidPublicAddressError");if(d=d.toLowerCase(),!A().isValidAddress(d||""))throw new Error("InvalidPublicAddressError");if(f==="token"||f==="token_info"){if(!l.query)throw new Error("InvalidUriError");const k=(r=l.query.symbol)!=null?r:"SYM";if(k.length<2||k.length>5)throw new Error("Wrong Token symbol");const b=(i=l.query.name)!=null?i:k,v=(u=l.query.decimals)!=null?u:"18";let E="1000000000000000000";const C=parseInt(v);if(C<0||C>18)throw new Error("Wrong number of decimals");E="1"+"0".repeat(C);const I=(a=l.query.type)!=null?a:this.networkInfo.ercTokenStandard;return{token:{currencyCode:k,contractAddress:y.toLowerCase(),currencyName:b,multiplier:E,denominations:[{name:k,multiplier:E}],type:I.toUpperCase()}}}if(f==="pay"){const k=d,b=l.pathname.split("/")[1],v=l.query;switch(b){case"transfer":{const E=(h=v.address)!=null?h:"",C=k!=null?k:"",I=v.uint256!=null?(0,p.EE)(v.uint256):c.nativeAmount,_=this.currencyInfo.metaTokens.find(X=>X.contractAddress===C);if(t!=null&&(_==null||_.currencyCode!==t))throw new Error("InternalErrorInvalidCurrencyCode");if(!A().isValidAddress(E))throw new Error("InvalidPublicAddressError");if(!A().isValidAddress(C))throw new Error("InvalidContractAddressError");return ze(We({},c),{currencyCode:_==null?void 0:_.currencyCode,nativeAmount:I,publicAddress:E})}case void 0:{const E=k,C=v.value!=null?(0,p.EE)(v.value):c.nativeAmount;return ze(We({},c),{publicAddress:E,nativeAmount:C})}default:throw new Error("UnsupportedContractFunction")}}throw new Error("InvalidUriError")})}encodeUri(e){return z(this,arguments,function*(t,s=[]){const{publicAddress:r,nativeAmount:i,currencyCode:u}=t;if(!A().isValidAddress(r))throw new Error("InvalidPublicAddressError");let h;if(typeof i=="string"){const l=(0,p.Qs)(u!=null?u:this.currencyInfo.currencyCode,this.currencyInfo,s);if(l==null)throw new Error("InternalErrorInvalidCurrencyCode");h=(0,g.div)(i,l.multiplier,18)}return(0,j.Q)(t,this.currencyInfo.pluginId,h)})}getSplittableTypes(e){return Object.keys(D.s).map(t=>`wallet:${t}`)}getTokenId(e){return z(this,null,function*(){(0,ee.Rp)(e);const t=(0,ee.Oj)(e.networkLocation);if(t==null||!A().isValidAddress(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^0x/,"")})}}function en(m){return z(this,null,function*(){return new Ve(m)})}},88924:function(){},55024:function(){}}]);
|
|
11
|
+
${(0,p.oX)(e)}`),e})}accelerate(e){return R(this,null,function*(){var t,s,r;const{currencyCode:i}=e,u=(0,n.Vk)(te)(e.otherParams);let a=e.txid,h=yield this.findTransaction(i,(0,p.f0)(a));if(h===-1&&((u==null?void 0:u.replacedTxid)!=null&&u.replacedTxid!==""&&(a=u.replacedTxid,h=yield this.findTransaction(i,(0,p.f0)(a))),h===-1))return null;const o=this.transactionList[i][h],l=(0,n.Vk)(te)(o.otherParams);if(o==null||o.blockHeight!==0||l==null||l.nonceUsed==null||!l.isFromMakeSpend)return null;const c=((t=o.spendTargets)!=null?t:[])[0];if(c==null)return null;const d=(0,g.mul)(l.gasPrice,"2"),f=l.gas,y=fe(re({},l),{gas:f,gasPrice:d,replacedTxid:a});let{nativeAmount:k}=c,b=(0,g.mul)(d,f),v="0",E;const C=(s=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?s:"0";if(i===this.currencyInfo.currencyCode){if(v=(0,g.add)(b,k),(0,g.gt)(v,C))throw new ne.C_;k=(0,g.mul)(v,"-1")}else{if(E=b,(0,g.gt)(b,C))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:b});const I=(r=this.walletLocalData.totalBalances[i])!=null?r:"0";if((0,g.gt)(k,I))throw new ne.C_;b="0",k=(0,g.mul)(k,"-1")}return fe(re({},e),{txid:"",feeRateUsed:Te(d,f),nativeAmount:k,networkFee:b,otherParams:y,parentNetworkFee:E})})}saveTx(e){return R(this,null,function*(){var t;const s=(0,n.Vk)(te)(e.otherParams);if((s==null?void 0:s.replacedTxid)!=null){const{currencyCode:r}=e,i=(0,p.f0)(s.replacedTxid),u=this.findTransaction(r,i);if(u!==-1){const a=this.transactionList[r][u],h=e.metadata,o=fe(re({},a),{metadata:h,blockHeight:-1});this.addTransaction(r,o)}}if(e.blockHeight===0){const r=(t=e.otherParams)==null?void 0:t.nonceUsed;r!=null&&(this.otherData.unconfirmedNextNonce=(0,g.add)(r,"1"))}Ae(me.prototype,this,"saveTx").call(this,e)})}}function Wt(m,e,t,s){return R(this,null,function*(){const{currencyInfo:r,initOptions:i}=m,u=Fe(t),a=new me(m,e,u,Z(i),s,r);return yield a.loadEngine(),a})}var zt=Object.defineProperty,Vt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,Yt=Object.prototype.hasOwnProperty,qt=Object.prototype.propertyIsEnumerable,Ze=(m,e,t)=>e in m?zt(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,We=(m,e)=>{for(var t in e||(e={}))Yt.call(e,t)&&Ze(m,t,e[t]);if(Je)for(var t of Je(e))qt.call(e,t)&&Ze(m,t,e[t]);return m},ze=(m,e)=>Vt(m,Qt(e)),z=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});class Ve{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:i}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=i}getDisplayPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo;return Ce(t)(e.keys).privateKey})}getDisplayPublicKey(e){return z(this,null,function*(){const{keys:t}=Fe(e);return t.publicKey})}importPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{pluginMnemonicKeyName:s,pluginRegularKeyName:r}=this.networkInfo;if(/^(0x)?[0-9a-fA-F]{64}$/.test(e)){const i=q.Buffer.from(e.replace(/^0x/,""),"hex");if(!A().isValidPrivate(i))throw new Error("Invalid private key");const u=i.toString("hex"),a={[r]:u};return this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:a}),a}else{if(!(0,J.validateMnemonic)(e))throw new Error("Invalid input");const i=yield this._mnemonicToHex(e);return{[s]:e,[r]:i}}})}createPrivateKey(e){return z(this,null,function*(){const{pluginMnemonicKeyName:t,pluginRegularKeyName:s}=this.networkInfo;if(e.replace("wallet:","")!==this.currencyInfo.pluginId)throw new Error("InvalidWalletType");const i=q.Buffer.from(this.io.random(32)),u=(0,J.entropyToMnemonic)(i),a=yield this._mnemonicToHex(u);return{[t]:u,[s]:a}})}derivePublicKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{hdPathCoinType:s,pluginMnemonicKeyName:r,pluginRegularKeyName:i}=this.networkInfo;if(e.type!==`wallet:${t}`)throw new Error("Invalid wallet type");let u;if(e.keys[r]!=null){const a=(0,J.mnemonicToSeedSync)(e.keys[r]),h=ae().fromMasterSeed(a),o=`m/44'/${s}'/0'/0`,d=h.derivePath(`${o}/0`).getWallet().getPublicKey(),f=A().pubToAddress(d).toString("hex");u=A().toChecksumAddress(f)}else{const a=q.Buffer.from(e.keys[i].replace(/^0x/,""),"hex");if(!A().isValidPrivate(a))throw new Error("Invalid private key");u=`0x${A().privateToAddress(a).toString("hex")}`}if(!A().isValidAddress(u))throw new Error("Invalid address");return{publicKey:u}})}_mnemonicToHex(e){return z(this,null,function*(){const{hdPathCoinType:t}=this.networkInfo,s=ae().fromMasterSeed((0,J.mnemonicToSeedSync)(e)),r=`m/44'/${t}'/0'/0`;return s.derivePath(`${r}/0`).getWallet().getPrivateKeyString().replace(/^0x/,"")})}parseUri(e,t,s){return z(this,null,function*(){var r,i,u,a,h;const o={};this.networkInfo.uriNetworks.forEach(k=>{o[k]=!0});const{parsedUri:l,edgeParsedUri:c}=(0,j.k)(this.currencyInfo,e,o,t||this.currencyInfo.currencyCode,s);let d="";c.publicAddress&&(d=c.publicAddress,c.publicAddress=c.publicAddress.toLowerCase());let[f,y]=d.split("-");if(y||(y=f,f="pay"),d=y,/[A-F]/.test(d)&&!A().isValidChecksumAddress(d))throw new Error("InvalidPublicAddressError");if(d=d.toLowerCase(),!A().isValidAddress(d||""))throw new Error("InvalidPublicAddressError");if(f==="token"||f==="token_info"){if(!l.query)throw new Error("InvalidUriError");const k=(r=l.query.symbol)!=null?r:"SYM";if(k.length<2||k.length>5)throw new Error("Wrong Token symbol");const b=(i=l.query.name)!=null?i:k,v=(u=l.query.decimals)!=null?u:"18";let E="1000000000000000000";const C=parseInt(v);if(C<0||C>18)throw new Error("Wrong number of decimals");E="1"+"0".repeat(C);const I=(a=l.query.type)!=null?a:this.networkInfo.ercTokenStandard;return{token:{currencyCode:k,contractAddress:y.toLowerCase(),currencyName:b,multiplier:E,denominations:[{name:k,multiplier:E}],type:I.toUpperCase()}}}if(f==="pay"){const k=d,b=l.pathname.split("/")[1],v=l.query;switch(b){case"transfer":{const E=(h=v.address)!=null?h:"",C=k!=null?k:"",I=v.uint256!=null?(0,p.EE)(v.uint256):c.nativeAmount,_=this.currencyInfo.metaTokens.find(X=>X.contractAddress===C);if(t!=null&&(_==null||_.currencyCode!==t))throw new Error("InternalErrorInvalidCurrencyCode");if(!A().isValidAddress(E))throw new Error("InvalidPublicAddressError");if(!A().isValidAddress(C))throw new Error("InvalidContractAddressError");return ze(We({},c),{currencyCode:_==null?void 0:_.currencyCode,nativeAmount:I,publicAddress:E})}case void 0:{const E=k,C=v.value!=null?(0,p.EE)(v.value):c.nativeAmount;return ze(We({},c),{publicAddress:E,nativeAmount:C})}default:throw new Error("UnsupportedContractFunction")}}throw new Error("InvalidUriError")})}encodeUri(e){return z(this,arguments,function*(t,s=[]){const{publicAddress:r,nativeAmount:i,currencyCode:u}=t;if(!A().isValidAddress(r))throw new Error("InvalidPublicAddressError");let h;if(typeof i=="string"){const l=(0,p.Qs)(u!=null?u:this.currencyInfo.currencyCode,this.currencyInfo,s);if(l==null)throw new Error("InternalErrorInvalidCurrencyCode");h=(0,g.div)(i,l.multiplier,18)}return(0,j.Q)(t,this.currencyInfo.pluginId,h)})}getSplittableTypes(e){return Object.keys(D.s).map(t=>`wallet:${t}`)}getTokenId(e){return z(this,null,function*(){(0,ee.Rp)(e);const t=(0,ee.Oj)(e.networkLocation);if(t==null||!A().isValidAddress(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^0x/,"")})}}function en(m){return z(this,null,function*(){return new Ve(m)})}},89214:function(){},52361:function(){},94616:function(){},88924:function(){},55024:function(){}}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[518],{58355:function(U,H,u){var f=u(35717),g=u(51031),O=u(71027),_=u(89509).Buffer,e=u(78028),b=u(79785),w=u(89072),y=_.alloc(128);function x(C,h){O.call(this,"digest"),typeof h=="string"&&(h=_.from(h));var T=C==="sha512"||C==="sha384"?128:64;if(this._alg=C,this._key=h,h.length>T){var B=C==="rmd160"?new b:w(C);h=B.update(h).digest()}else h.length<T&&(h=_.concat([h,y],T));for(var X=this._ipad=_.allocUnsafe(T),p=this._opad=_.allocUnsafe(T),m=0;m<T;m++)X[m]=h[m]^54,p[m]=h[m]^92;this._hash=C==="rmd160"?new b:w(C),this._hash.update(X)}f(x,O),x.prototype._update=function(C){this._hash.update(C)},x.prototype._final=function(){var C=this._hash.digest(),h=this._alg==="rmd160"?new b:w(this._alg);return h.update(this._opad).update(C).digest()},U.exports=function(h,T){return h=h.toLowerCase(),h==="rmd160"||h==="ripemd160"?new x("rmd160",T):h==="md5"?new g(e,T):new x(h,T)}},51031:function(U,H,u){var f=u(35717),g=u(89509).Buffer,O=u(71027),_=g.alloc(128),e=64;function b(w,y){O.call(this,"digest"),typeof y=="string"&&(y=g.from(y)),this._alg=w,this._key=y,y.length>e?y=w(y):y.length<e&&(y=g.concat([y,_],e));for(var x=this._ipad=g.allocUnsafe(e),C=this._opad=g.allocUnsafe(e),h=0;h<e;h++)x[h]=y[h]^54,C[h]=y[h]^92;this._hash=[x]}f(b,O),b.prototype._update=function(w){this._hash.push(w)},b.prototype._final=function(){var w=this._alg(g.concat(this._hash));return this._alg(g.concat([this._opad,w]))},U.exports=b},79014:function(U,H,u){u.d(H,{Q:function(){return X},k:function(){return B}});var f=u(77591),g=u.n(f),O=u(24350),_=u(84564),e=u.n(_),b=u(76714),w=Object.defineProperty,y=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,h=(p,m,P)=>m in p?w(p,m,{enumerable:!0,configurable:!0,writable:!0,value:P}):p[m]=P,T=(p,m)=>{for(var P in m||(m={}))x.call(m,P)&&h(p,P,m[P]);if(y)for(var P of y(m))C.call(m,P)&&h(p,P,m[P]);return p};function B(p,m,P,I,R=[]){const v=T({},e()(m,{},!0)),$=m.startsWith(`${p.pluginId}://`);if(v.protocol!=null&&(v.protocol=v.protocol.replace(":","")),v.protocol!=null&&v.protocol!==""&&!P[v.protocol])throw new Error(`Uri protocol '${v.protocol}' is not supported for ${p.pluginId}.`);if(v.host===""&&v.pathname==="")throw new Error("Path and host not found in uri.");const A={publicAddress:v.host!==""?v.host:v.pathname.split("/")[0]},J=v.query.label,G=v.query.message,F=v.query.category;(J!=null||G!=null||F!=null||$)&&(A.metadata={},A.metadata.name=J,A.metadata.notes=G,A.metadata.category=F,A.metadata.gateway=$!=null?$:!1);const K=v.query.amount;if(K!=null&&typeof K=="string"){I==null&&(I=p.currencyCode);const j=(0,b.Qs)(I!=null?I:"",p,R);if(j==null)throw new Error("InternalErrorInvalidCurrencyCode");let L=(0,f.mul)(K,j.multiplier);L=(0,f.toFixed)(L,0,0),A.nativeAmount=L,A.currencyCode=I}return{edgeParsedUri:A,parsedUri:v}}function X(p,m,P){if(p.publicAddress==null)throw new Error("InvalidPublicAddressError");if(P==null&&p.label==null&&p.message==null)return p.publicAddress;{let I="";P!=null&&(I+="amount="+P+"&"),(p.label!=null||p.message!=null)&&(typeof p.label=="string"&&(I+="label="+p.label+"&"),typeof p.message=="string"&&(I+="message="+p.message+"&")),I=I.substr(0,I.length-1);const R={scheme:m,path:p.publicAddress,query:I};return(0,O.qC)(R)}}},12636:function(U,H,u){u.r(H),u.d(H,{FilecoinTools:function(){return Z},makeCurrencyEngine:function(){return Pe},makeCurrencyTools:function(){return we}});var f=u(23145),g=u(77591),O=u(37786),_=u(2153),e=u(82448),b=u(35620),w=u(79014),y=u(76714),x=u(62177);const C=(0,e.su)({}),h=(0,e.su)({sigJson:(0,e.Zz)((0,e.su)({Data:e.XC,Type:(0,e.Wf)(1,3)})),txJson:(0,e.su)({To:e.XC,From:e.XC,Nonce:e.mH,Value:e.XC,GasLimit:e.mH,GasFeeCap:e.XC,GasPremium:e.XC,Method:e.mH,Params:e.XC})}),T=(0,e.su)({address:e.XC,publicKey:e.XC}),B=(0,x.jd)(T),X=c=>{const t=(0,e.su)({[`${c}Mnemonic`]:e.XC,[`${c}Key`]:e.XC});return(0,e.W1)(s=>{const o=t(s);return{mnemonic:o[`${c}Mnemonic`],privateKey:o[`${c}Key`]}},s=>({[`${c}Mnemonic`]:s.mnemonic,[`${c}Key`]:s.privateKey}))};var p=u(94935),m=u(84650),P=(c,t,s)=>new Promise((o,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},i=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(a,i);l((s=s.apply(c,t)).next())});const I=(0,e.su)({statusCode:e.mH,message:e.XC,error:e.XC}),R=c=>(0,e.$e)((0,e._C)(I,c)),v=(0,e.su)({cid:e.XC,from:e.XC,height:e.mH,method:e.XC,nonce:e.mH,reciept:(0,e.su)({exitCode:e.mH}),timestamp:e.mH,to:e.XC,value:e.XC}),$=(0,e.su)({messages:(0,e._2)(v),totalCount:e.mH});class z{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountMessages(t,s,o=20){return P(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/messages`),a=new URLSearchParams({page:s.toString(),pageSize:o.toString()});n.search=a.toString();const l=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=R($)(l);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}}var A=(c,t,s)=>new Promise((o,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},i=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(a,i);l((s=s.apply(c,t)).next())});const J=c=>(0,e.su)({result:c}),G=(0,e.su)({code:e.mH,message:e.XC}),F=c=>(0,e.$e)((0,e._C)(G,J(c))),K=(0,e.su)({height:e.mH,block_time:e.mH,cid:e.XC,from:e.XC,to:e.XC,value:e.XC,exit_code:e.XC,method_name:e.XC}),j=(0,e.su)({account_type:e.XC,account_info:(0,e.su)({account_basic:(0,e.su)({account_id:e.XC,account_address:e.XC,account_type:e.XC,account_balance:e.XC,nonce:e.mH,code_cid:e.XC,create_time:e.XC,latest_transfer_time:e.XC})})}),L=(0,e.su)({messages_by_account_id_list:(0,e.Vk)((0,e._2)(K),()=>[]),total_count:e.mH}),q=(0,e.su)({MessageDetails:(0,e.su)({message_basic:(0,e.su)({height:e.mH,block_time:e.mH,cid:e.XC,from:e.XC,to:e.XC,value:e.XC,exit_code:e.XC,method_name:e.XC}),blk_cids:(0,e._2)(e.XC),consume_list:(0,e._2)((0,e.su)({from:e.XC,to:e.XC,value:e.XC,consume_type:e.XC})),version:e.mH,nonce:e.mH,gas_fee_cap:e.XC,gas_premium:e.XC,gas_limit:e.mH,gas_used:e.XC,base_fee:e.XC,all_gas_fee:e.XC,eth_message:e.XC})});class ee{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountInfo(t){return A(this,null,function*(){const o=yield(yield this.fetch(`${this.baseUrl}/AccountInfoByID`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({account_id:t})})).text(),n=F(j)(o);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}getAccountMessages(t,s,o=20){return A(this,null,function*(){const a=yield(yield this.fetch(`${this.baseUrl}/MessagesByAccountID`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({account_id:t,address:"",filters:{index:s,page:0,limit:o,method_name:""}})})).text(),i=F(L)(a);if(!("result"in i))throw new Error(`Error response code ${i.code}: ${i.message}`);return i.result})}getMessageDetails(t){return A(this,null,function*(){const o=yield(yield this.fetch(`${this.baseUrl}/MessageDetails`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({message_cid:t})})).text(),n=F(q)(o);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}}var te=Math.pow,se=(c,t,s)=>new Promise((o,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},i=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(a,i);l((s=s.apply(c,t)).next())});const ne=c=>(0,e.su)({id:e.mH,jsonrpc:e.XC,result:c}),re=(0,e.su)({id:e.mH,jsonrpc:e.XC,error:(0,e.su)({code:e.mH,message:e.XC})}),oe=c=>(0,e.$e)((0,e._C)(re,ne(c))),ie=(0,e.su)({Height:e.mH});class ae{constructor(t,s){this.baseUrl=t,this.fetch=s}getChainHead(){return se(this,null,function*(){const t=Math.floor(Math.random()*te(10,8)),o=yield(yield this.fetch(this.baseUrl,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,jsonrpc:"2.0",method:"Filecoin.ChainHead",params:null})})).text(),n=oe(ie)(o);if("error"in n)throw new Error(`Error response code ${n.error.code}: ${n.error.message}`);return n})}}var ce=Object.defineProperty,le=Object.defineProperties,ue=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertySymbols,de=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable,pe=Reflect.get,Q=(c,t,s)=>t in c?ce(c,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):c[t]=s,me=(c,t)=>{for(var s in t||(t={}))he.call(t,s)&&Q(c,s,t[s]);if(Y)for(var s of Y(t))fe.call(t,s)&&Q(c,s,t[s]);return c},ge=(c,t)=>le(c,ue(t)),N=(c,t,s)=>pe(de(c),s,t),E=(c,t,s)=>new Promise((o,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},i=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(a,i);l((s=s.apply(c,t)).next())});const ye=15e3,ve=3e4,Ce=15e3;class M extends m.P{constructor(t,s,o,n){super(t,s,o,n),this.filfoxMessageToEdgeTransaction=i=>{const l=this.address.toString();let r=i.value;const d=[],S="0";return i.to!==l?r=`-${(0,g.add)(r,S)}`:d.push(l),{txid:i.cid,date:i.timestamp,currencyCode:this.currencyInfo.currencyCode,blockHeight:i.height,nativeAmount:r,isSend:r.startsWith("-"),networkFee:S,ourReceiveAddresses:d,signedTx:"",otherParams:{},walletId:this.walletId}};const{networkInfo:a}=t;this.address=f.kL.fromString(o.keys.address),this.availableAttoFil="0",this.filRpc=new f.rP(t.networkInfo.rpcNode.networkName,{url:t.networkInfo.rpcNode.url,token:t.currencyInfo.currencyCode}),this.filfoxApi=new z(t.networkInfo.filfoxUrl,t.io.fetchCors),this.filscanApi=new ee(t.networkInfo.filscanUrl,t.io.fetchCors),this.rpcExtra=new ae(t.networkInfo.rpcNode.url,t.io.fetchCors),this.networkInfo=a,this.pluginId=this.currencyInfo.pluginId}setOtherData(t){this.otherData=C(t)}initData(){this.availableAttoFil="0"}initSubscriptions(){this.addToLoop("checkBalance",ye).catch(t=>this.log(t)),this.addToLoop("checkBlockHeight",ve).catch(t=>this.log(t)),this.addToLoop("checkTransactions",Ce).catch(t=>this.log(t))}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=[])}startEngine(){return E(this,null,function*(){this.initData(),this.initSubscriptions(),yield N(M.prototype,this,"startEngine").call(this)})}killEngine(){return E(this,null,function*(){yield N(M.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return E(this,null,function*(){yield N(M.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return E(this,null,function*(){yield N(M.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return E(this,null,function*(){const{address:t}=this.walletInfo.keys;return{publicAddress:t}})}getMaxSpendable(t){return E(this,null,function*(){const o=(yield this.makeSpend(t)).networkFee,n=(0,g.sub)(this.availableAttoFil,o);if((0,g.lte)(n,"0"))throw new p.C_;return n})}makeSpend(t){return E(this,null,function*(){const{edgeSpendInfo:s,currencyCode:o}=this.makeSpendCheck(t),n=s.spendTargets[0],{publicAddress:a,nativeAmount:i}=n;if(a==null)throw new Error("Missing publicAddress in EdgeSpendInfo");if(i==null)throw new p.$D;const l=f.kL.fromString(a),r=f.YW.getNew(l,this.address,f.WU.fromAtto(i),0);yield r.prepareToSend(this.filRpc);const d=r.toJSON(),S={sigJson:void 0,txJson:d},k=(0,g.mul)(d.GasLimit.toString(),d.GasPremium),W=(0,g.add)(i,k);return{txid:"",date:0,currencyCode:o,blockHeight:0,nativeAmount:`-${W}`,isSend:i.startsWith("-"),networkFee:k,ourReceiveAddresses:[],otherParams:S,signedTx:"",walletId:this.walletId}})}signTx(t,s){return E(this,null,function*(){const o=h(t.otherParams),n=f.YW.fromJSON(o.txJson),a=X(this.pluginId)(s),i=f.w5.deriveAccount(a.mnemonic,f.BG.SECP256K1,this.tools.derivationPath),l=yield f.w5.signTransaction(i,n);return t.otherParams=ge(me({},t.otherParams),{sigJson:l.toJSON()}),t})}broadcastTx(t,s){return E(this,null,function*(){const o=h(t.otherParams);if(o.sigJson==null)throw new Error("Cannot broadcast unsigned transaction");const n=f.Pc.fromJSON(o.sigJson),a=f.YW.fromJSON(o.txJson),i=yield this.filRpc.broadcastTransaction(a,n);if("error"in i)throw new Error(i.error.message);return t.txid=i.result["/"],t})}getDisplayPrivateSeed(t){return X(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}loadEngine(){return E(this,null,function*(){yield N(M.prototype,this,"loadEngine").call(this),this.engineOn=!0})}checkBalance(){return E(this,null,function*(){const t=yield this.filRpc.walletBalance(this.address);if("error"in t)throw new Error(t.error.message);const{result:s}=t;this.availableAttoFil=s,this.updateBalance(this.currencyInfo.currencyCode,s),this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.walletLocalDataDirty=!0})}checkBlockHeight(){return E(this,null,function*(){const s=(yield this.rpcExtra.getChainHead()).result.Height;this.onUpdateBlockHeight(s)})}checkTransactions(){return E(this,null,function*(){const t=this.address.toString(),s=a=>{const i=this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode],l=a;i<1&&(l>=1||l>i*1.1)&&(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=l,this.updateOnAddressesChecked())},o=({tx:a,progress:i})=>{this.addTransaction(this.currencyInfo.currencyCode,a),this.onUpdateTransactions(),this.walletLocalData.blockHeight<a.blockHeight&&this.onUpdateBlockHeight(a.blockHeight),s(i)},n=[this.scanTransactionsFromFilscan(t,o),this.scanTransactionsFromFilfox(t,o)];yield Promise.all(n),s(1)})}scanTransactionsFromFilfox(t,s){return E(this,null,function*(){let n=0,a=0,i=-1;do{const l=yield this.filfoxApi.getAccountMessages(t,n++,20);i=i===-1?l.totalCount:i;const r=l.messages;for(const d of r){const S=d.cid;if(this.findTransaction(this.currencyInfo.currencyCode,S)>=0)return;const W=this.filfoxMessageToEdgeTransaction(d),V=i===0?1:++a/i;s({tx:W,progress:V})}}while(a<i)})}scanTransactionsFromFilscan(t,s){return E(this,null,function*(){let n=0,a=0,i=-1;do{const l=yield this.filscanApi.getAccountMessages(t,n++,20);i=i===-1?l.total_count:i;const r=l.messages_by_account_id_list;for(const d of r){const S=d.cid;if(this.findTransaction(this.currencyInfo.currencyCode,S)>=0)return;const W=this.filscanMessageToEdgeTransaction(d),V=i===0?1:++a/i;s({tx:W,progress:V})}}while(a<i)})}filscanMessageToEdgeTransaction(t){const s=this.address.toString();let o=t.value;const n=[],a="0";return t.to!==s?o=`-${(0,g.add)(o,a)}`:n.push(s),{txid:t.cid,date:t.block_time,currencyCode:this.currencyInfo.currencyCode,blockHeight:t.height,nativeAmount:o,isSend:o.startsWith("-"),networkFee:a,ourReceiveAddresses:n,signedTx:"",otherParams:{},walletId:this.walletId}}}function Pe(c,t,s,o){return E(this,null,function*(){const n=B(s),a=new M(c,t,n,o);return yield a.loadEngine(),a})}var D=(c,t,s)=>new Promise((o,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},i=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?o(r.value):Promise.resolve(r.value).then(a,i);l((s=s.apply(c,t)).next())});class Z{constructor(t){const{builtinTokens:s,currencyInfo:o,io:n,networkInfo:a}=t;this.builtinTokens=s,this.currencyInfo=o,this.io=n,this.networkInfo=a,this.derivationPath=`m/44'/${this.networkInfo.hdPathCoinType}'/0'/0/0`}isValidAddress(t){return D(this,null,function*(){try{return f.kL.fromString(t),!0}catch{return!1}})}importPrivateKey(t){return D(this,arguments,function*(s,o={}){const{pluginId:n}=this.currencyInfo;if(!(0,_.validateMnemonic)(s))throw new Error("Invalid mnemonic");const a=(yield(0,_.mnemonicToSeed)(s)).toString("hex");return{[`${n}Key`]:a,[`${n}Mnemonic`]:s}})}createPrivateKey(t){return D(this,null,function*(){const{pluginId:s}=this.currencyInfo;if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const o=b.YU.stringify(this.io.random(32)),n=(0,_.entropyToMnemonic)(o);return{[`${s}Key`]:o,[`${s}Mnemonic`]:n}})}checkPublicKey(t){return D(this,null,function*(){return(0,e.Vk)(T)(t)!=null})}derivePublicKey(t){return D(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{pluginId:s}=this.currencyInfo,{hdPathCoinType:o}=this.networkInfo,n=X(s)(t.keys),a=yield(0,_.mnemonicToSeed)(n.mnemonic),d=(0,O.fromSeed)(a).deriveHardened(44).deriveHardened(o).deriveHardened(0).neutered().toBase58(),k=f.w5.deriveAccount(n.mnemonic,f.BG.SECP256K1,this.derivationPath).address.toString();return{publicKey:d,address:k}})}parseUri(t,s,o){return D(this,null,function*(){const{pluginId:n}=this.currencyInfo,a={[n]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:l}}=(0,w.k)(this.currencyInfo,t,a,s!=null?s:this.currencyInfo.currencyCode,o);if(l==null||!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t){return D(this,arguments,function*(s,o=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:a,currencyCode:i,publicAddress:l}=s;if(!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");let r;if(a!=null){const S=(0,y.Qs)(i!=null?i:this.currencyInfo.currencyCode,this.currencyInfo,o);if(S==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,g.div)(a,S.multiplier,18)}return(0,w.Q)(s,`${n}`,r)})}}function we(c){return D(this,null,function*(){return new Z(c)})}},35620:function(U,H,u){u.d(H,{US:function(){return e},YU:function(){return g}});var f=u(79911);const g=f.base16,O=f.base32,_=f.base32hex,e=f.base64,b=f.base64url,w=f.codec;var y=null}}]);
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8518],{79014:function(Z,F,h){"use strict";h.d(F,{Q:function(){return H},k:function(){return G}});var p=h(77591),w=h.n(p),L=h(24350),k=h(84564),e=h.n(k),N=h(76714),$=Object.defineProperty,U=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,S=(d,y,m)=>y in d?$(d,y,{enumerable:!0,configurable:!0,writable:!0,value:m}):d[y]=m,B=(d,y)=>{for(var m in y||(y={}))W.call(y,m)&&S(d,m,y[m]);if(U)for(var m of U(y))J.call(y,m)&&S(d,m,y[m]);return d};function G(d,y,m,v,X=[]){const f=B({},e()(y,{},!0)),x=y.startsWith(`${d.pluginId}://`);if(f.protocol!=null&&(f.protocol=f.protocol.replace(":","")),f.protocol!=null&&f.protocol!==""&&!m[f.protocol])throw new Error(`Uri protocol '${f.protocol}' is not supported for ${d.pluginId}.`);if(f.host===""&&f.pathname==="")throw new Error("Path and host not found in uri.");const P={publicAddress:f.host!==""?f.host:f.pathname.split("/")[0]},R=f.query.label,_=f.query.message,K=f.query.category;(R!=null||_!=null||K!=null||x)&&(P.metadata={},P.metadata.name=R,P.metadata.notes=_,P.metadata.category=K,P.metadata.gateway=x!=null?x:!1);const O=f.query.amount;if(O!=null&&typeof O=="string"){v==null&&(v=d.currencyCode);const A=(0,N.Qs)(v!=null?v:"",d,X);if(A==null)throw new Error("InternalErrorInvalidCurrencyCode");let D=(0,p.mul)(O,A.multiplier);D=(0,p.toFixed)(D,0,0),P.nativeAmount=D,P.currencyCode=v}return{edgeParsedUri:P,parsedUri:f}}function H(d,y,m){if(d.publicAddress==null)throw new Error("InvalidPublicAddressError");if(m==null&&d.label==null&&d.message==null)return d.publicAddress;{let v="";m!=null&&(v+="amount="+m+"&"),(d.label!=null||d.message!=null)&&(typeof d.label=="string"&&(v+="label="+d.label+"&"),typeof d.message=="string"&&(v+="message="+d.message+"&")),v=v.substr(0,v.length-1);const X={scheme:y,path:d.publicAddress,query:v};return(0,L.qC)(X)}}},12636:function(Z,F,h){"use strict";h.r(F),h.d(F,{FilecoinTools:function(){return Y},makeCurrencyEngine:function(){return Ee},makeCurrencyTools:function(){return be}});var p=h(23145),w=h(77591),L=h(37786),k=h(2153),e=h(82448),N=h(35620),$=h(79014),U=h(76714),W=h(62177);const J=(0,e.su)({}),S=(0,e.su)({sigJson:(0,e.Zz)((0,e.su)({Data:e.XC,Type:(0,e.Wf)(1,3)})),txJson:(0,e.su)({To:e.XC,From:e.XC,Nonce:e.mH,Value:e.XC,GasLimit:e.mH,GasFeeCap:e.XC,GasPremium:e.XC,Method:e.mH,Params:e.XC})}),B=(0,e.su)({address:e.XC,publicKey:e.XC}),G=(0,W.jd)(B),H=c=>{const t=(0,e.su)({[`${c}Mnemonic`]:e.XC,[`${c}Key`]:e.XC});return(0,e.W1)(s=>{const i=t(s);return{mnemonic:i[`${c}Mnemonic`],privateKey:i[`${c}Key`]}},s=>({[`${c}Mnemonic`]:s.mnemonic,[`${c}Key`]:s.privateKey}))};var d=h(94935),y=h(84650),m=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(u){n(u)}},o=r=>{try{l(s.throw(r))}catch(u){n(u)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const v=(0,e.su)({statusCode:e.mH,message:e.XC,error:e.XC}),X=c=>(0,e.$e)((0,e._C)(v,c)),f=(0,e.su)({cid:e.XC,from:e.XC,height:e.mH,method:e.XC,nonce:e.mH,receipt:(0,e.su)({exitCode:e.mH}),timestamp:e.mH,to:e.XC,value:e.XC}),x=(0,e.su)({cid:e.XC,height:e.mH,timestamp:e.mH,from:e.XC,to:e.XC,value:e.XC,gasLimit:e.mH,gasFeeCap:e.XC,gasPremium:e.XC,receipt:(0,e.su)({exitCode:e.mH,return:e.XC,gasUsed:e.mH}),baseFee:e.XC,fee:(0,e.su)({baseFeeBurn:e.XC,overEstimationBurn:e.XC,minerPenalty:e.XC,minerTip:e.XC,refund:e.XC}),transfers:(0,e._2)((0,e.su)({from:e.XC,fromId:e.XC,to:e.XC,toId:e.XC,value:e.XC,type:e.XC}))}),V=(0,e.su)({messages:(0,e._2)(f),totalCount:e.mH}),P=x;class R{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountMessages(t,s,i=20){return m(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/messages`),a=new URLSearchParams({page:s.toString(),pageSize:i.toString()});n.search=a.toString();const l=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=X(V)(l);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getMessageDetails(t){return m(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/message/${t}`,{method:"GET",headers:{"content-type":"application/json"}})).text(),n=X(P)(i);if("error"in n)throw new Error(`Error response code ${n.statusCode}: ${n.message} ${n.error}`);return n})}}var _=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(u){n(u)}},o=r=>{try{l(s.throw(r))}catch(u){n(u)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const K=c=>(0,e.su)({result:c}),O=(0,e.su)({code:e.mH,message:e.XC}),A=c=>(0,e.$e)((0,e._C)(O,K(c))),D=(0,e.su)({height:e.mH,block_time:e.mH,cid:e.XC,from:e.XC,to:e.XC,value:e.XC,exit_code:e.XC,method_name:e.XC}),q=(0,e.su)({account_type:e.XC,account_info:(0,e.su)({account_basic:(0,e.su)({account_id:e.XC,account_address:e.XC,account_type:e.XC,account_balance:e.XC,nonce:e.mH,code_cid:e.XC,create_time:e.XC,latest_transfer_time:e.XC})})}),ee=(0,e.su)({messages_by_account_id_list:(0,e.Vk)((0,e._2)(D),()=>[]),total_count:e.mH}),te=(0,e.su)({MessageDetails:(0,e.su)({message_basic:(0,e.su)({height:e.mH,block_time:e.mH,cid:e.XC,from:e.XC,to:e.XC,value:e.XC,exit_code:e.XC,method_name:e.XC}),blk_cids:(0,e._2)(e.XC),consume_list:(0,e._2)((0,e.su)({from:e.XC,to:e.XC,value:e.XC,consume_type:e.XC})),version:e.mH,nonce:e.mH,gas_fee_cap:e.XC,gas_premium:e.XC,gas_limit:e.mH,gas_used:e.XC,base_fee:e.XC,all_gas_fee:e.XC,eth_message:e.XC})});class se{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountInfo(t){return _(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/AccountInfoByID`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({account_id:t})})).text(),n=A(q)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}getAccountMessages(t,s,i=20){return _(this,null,function*(){const a=yield(yield this.fetch(`${this.baseUrl}/MessagesByAccountID`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({account_id:t,address:"",filters:{index:s,page:0,limit:i,method_name:""}})})).text(),o=A(ee)(a);if(!("result"in o))throw new Error(`Error response code ${o.code}: ${o.message}`);return o.result})}getMessageDetails(t){return _(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/MessageDetails`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({message_cid:t})})).text(),n=A(te)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}}var ne=Math.pow,re=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(u){n(u)}},o=r=>{try{l(s.throw(r))}catch(u){n(u)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const oe=c=>(0,e.su)({id:e.mH,jsonrpc:e.XC,result:c}),ie=(0,e.su)({id:e.mH,jsonrpc:e.XC,error:(0,e.su)({code:e.mH,message:e.XC})}),ae=c=>(0,e.$e)((0,e._C)(ie,oe(c))),ce=(0,e.su)({Height:e.mH});class le{constructor(t,s){this.baseUrl=t,this.fetch=s}getChainHead(){return re(this,null,function*(){const t=Math.floor(Math.random()*ne(10,8)),i=yield(yield this.fetch(this.baseUrl,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,jsonrpc:"2.0",method:"Filecoin.ChainHead",params:null})})).text(),n=ae(ce)(i);if("error"in n)throw new Error(`Error response code ${n.error.code}: ${n.error.message}`);return n})}}var ue=Object.defineProperty,de=Object.defineProperties,he=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,fe=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable,ye=Reflect.get,Q=(c,t,s)=>t in c?ue(c,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):c[t]=s,ge=(c,t)=>{for(var s in t||(t={}))pe.call(t,s)&&Q(c,s,t[s]);if(j)for(var s of j(t))me.call(t,s)&&Q(c,s,t[s]);return c},Ce=(c,t)=>de(c,he(t)),M=(c,t,s)=>ye(fe(c),s,t),g=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(u){n(u)}},o=r=>{try{l(s.throw(r))}catch(u){n(u)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const ve=15e3,we=3e4,Pe=15e3;class T extends y.P{constructor(t,s,i,n){super(t,s,i,n),this.filfoxMessageToEdgeTransaction=o=>{const l=this.address.toString(),r=[],u=o.transfers.filter(I=>I.type==="miner-fee"||I.type==="burner-fee").reduce((I,z)=>(0,w.add)(I,z.value),"0");let C;return o.from===l?(C=`-${u}`,o.to!==l&&(C=(0,w.sub)(C,o.value))):(C=o.value,r.push(l)),{txid:o.cid,date:o.timestamp,currencyCode:this.currencyInfo.currencyCode,blockHeight:o.height,nativeAmount:C,isSend:C.startsWith("-"),networkFee:u,ourReceiveAddresses:r,signedTx:"",otherParams:{},walletId:this.walletId}};const{networkInfo:a}=t;this.address=p.kL.fromString(i.keys.address),this.availableAttoFil="0",this.isScanning=!1,this.networkInfo=a,this.pluginId=this.currencyInfo.pluginId,this.filRpc=new p.rP(p.Zc[t.networkInfo.rpcNode.networkName],{url:t.networkInfo.rpcNode.url,token:t.currencyInfo.currencyCode}),this.filfoxApi=new R(t.networkInfo.filfoxUrl,t.io.fetchCors),this.filscanApi=new se(t.networkInfo.filscanUrl,t.io.fetchCors),this.rpcExtra=new le(t.networkInfo.rpcNode.url,t.io.fetchCors)}setOtherData(t){this.otherData=J(t)}initData(){this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=0,this.availableAttoFil="0"}initSubscriptions(){this.addToLoop("checkBalance",ve).catch(t=>this.log(t)),this.addToLoop("checkBlockHeight",we).catch(t=>this.log(t)),this.addToLoop("checkTransactions",Pe).catch(t=>this.log(t))}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=[])}startEngine(){return g(this,null,function*(){this.initData(),this.initSubscriptions(),yield M(T.prototype,this,"startEngine").call(this)})}killEngine(){return g(this,null,function*(){yield M(T.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return g(this,null,function*(){yield M(T.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return g(this,null,function*(){yield M(T.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return g(this,null,function*(){const{address:t}=this.walletInfo.keys;return{publicAddress:t}})}getMaxSpendable(t){return g(this,null,function*(){const i=(yield this.makeSpend(t)).networkFee,n=(0,w.sub)(this.availableAttoFil,i);if((0,w.lte)(n,"0"))throw new d.C_;return n})}makeSpend(t){return g(this,null,function*(){const{edgeSpendInfo:s,currencyCode:i}=this.makeSpendCheck(t),n=s.spendTargets[0],{publicAddress:a,nativeAmount:o}=n;if(a==null)throw new Error("Missing publicAddress in EdgeSpendInfo");if(o==null)throw new d.$D;const l=p.kL.fromString(a),r=p.YW.getNew(l,this.address,p.WU.fromAtto(o),0);yield r.prepareToSend(this.filRpc);const u=r.toJSON(),C={sigJson:void 0,txJson:u},E=(0,w.mul)(u.GasLimit.toString(),u.GasPremium),I=(0,w.mul)((0,w.add)(o,E),"-1");return{txid:"",date:0,currencyCode:i,blockHeight:0,nativeAmount:I,isSend:!0,networkFee:E,ourReceiveAddresses:[],otherParams:C,signedTx:"",walletId:this.walletId}})}signTx(t,s){return g(this,null,function*(){const i=S(t.otherParams),n=p.YW.fromJSON(i.txJson),a=H(this.pluginId)(s),o=p.w5.deriveAccount(a.mnemonic,p.BG.SECP256K1,this.tools.derivationPath),l=yield p.w5.signTransaction(o,n);return t.otherParams=Ce(ge({},t.otherParams),{sigJson:l.toJSON()}),t.date=Date.now()/1e3,t})}broadcastTx(t,s){return g(this,null,function*(){const i=S(t.otherParams);if(i.sigJson==null)throw new Error("Cannot broadcast unsigned transaction");const n=p.Pc.fromJSON(i.sigJson),a=p.YW.fromJSON(i.txJson),o=yield this.filRpc.broadcastTransaction(a,n);if("error"in o)throw new Error(o.error.message);return t.txid=o.result["/"],t})}getDisplayPrivateSeed(t){return H(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}loadEngine(){return g(this,null,function*(){yield M(T.prototype,this,"loadEngine").call(this),this.engineOn=!0})}checkBalance(){return g(this,null,function*(){const t=yield this.filRpc.walletBalance(this.address);if("error"in t)throw new Error(t.error.message);const{result:s}=t;this.availableAttoFil=s,this.updateBalance(this.currencyInfo.currencyCode,s),this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.walletLocalDataDirty=!0})}checkBlockHeight(){return g(this,null,function*(){const s=(yield this.rpcExtra.getChainHead()).result.Height;this.onUpdateBlockHeight(s)})}checkTransactions(){return g(this,null,function*(){if(!this.isScanning)try{this.isScanning=!0;const t=this.address.toString(),s=o=>{const l=this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode],r=o;l<1&&(r>=1||r>l*1.1)&&(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=r,this.updateOnAddressesChecked())},i=({tx:o,progress:l})=>{this.addTransaction(this.currencyInfo.currencyCode,o),this.onUpdateTransactions(),this.walletLocalData.blockHeight<o.blockHeight&&this.onUpdateBlockHeight(o.blockHeight),s(l)},n=[this.scanTransactionsFromFilfox(t,i)],a=this.walletLocalData.blockHeight;yield Promise.all(n),this.walletLocalData.lastAddressQueryHeight=a,this.walletLocalDataDirty=!0,s(1)}catch(t){throw console.error(t),t}finally{this.isScanning=!1}})}scanTransactionsFromFilfox(t,s){return g(this,null,function*(){let n=0,a=0,o=-1;do{const l=yield this.filfoxApi.getAccountMessages(t,n++,20);o=o===-1?l.totalCount:o;const r=l.messages;for(const u of r){if(u.height<this.walletLocalData.lastAddressQueryHeight)return;const C=yield this.filfoxApi.getMessageDetails(u.cid),E=this.filfoxMessageToEdgeTransaction(C),I=o===0?1:++a/o;s({tx:E,progress:I})}}while(a<o)})}scanTransactionsFromFilscan(t,s){return g(this,null,function*(){let n=0,a=0,o=-1;do{const l=yield this.filscanApi.getAccountMessages(t,n++,20);o=o===-1?l.total_count:o;const r=l.messages_by_account_id_list;for(const u of r){if(u.height<this.walletLocalData.lastAddressQueryHeight)return;const C=this.filscanMessageToEdgeTransaction(u),E=o===0?1:++a/o;s({tx:C,progress:E})}}while(a<o)})}filscanMessageToEdgeTransaction(t){const s=this.address.toString(),i=[],n="0";let a;return t.from===s?(a=`-${n}`,t.to!==s&&(a=(0,w.sub)(a,t.value))):(a=t.value,i.push(s)),{txid:t.cid,date:t.block_time,currencyCode:this.currencyInfo.currencyCode,blockHeight:t.height,nativeAmount:a,isSend:a.startsWith("-"),networkFee:n,ourReceiveAddresses:i,signedTx:"",otherParams:{},walletId:this.walletId}}}function Ee(c,t,s,i){return g(this,null,function*(){const n=G(s),a=new T(c,t,n,i);return yield a.loadEngine(),a})}var b=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(u){n(u)}},o=r=>{try{l(s.throw(r))}catch(u){n(u)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});class Y{constructor(t){const{builtinTokens:s,currencyInfo:i,io:n,networkInfo:a}=t;this.builtinTokens=s,this.currencyInfo=i,this.io=n,this.networkInfo=a,this.derivationPath=`m/44'/${this.networkInfo.hdPathCoinType}'/0'/0/0`}isValidAddress(t){return b(this,null,function*(){try{return p.kL.fromString(t),!0}catch{return!1}})}importPrivateKey(t){return b(this,arguments,function*(s,i={}){const{pluginId:n}=this.currencyInfo;if(!(0,k.validateMnemonic)(s))throw new Error("Invalid mnemonic");const a=(yield(0,k.mnemonicToSeed)(s)).toString("hex");return{[`${n}Key`]:a,[`${n}Mnemonic`]:s}})}createPrivateKey(t){return b(this,null,function*(){const{pluginId:s}=this.currencyInfo;if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const i=N.YU.stringify(this.io.random(32)),n=(0,k.entropyToMnemonic)(i);return{[`${s}Key`]:i,[`${s}Mnemonic`]:n}})}checkPublicKey(t){return b(this,null,function*(){return(0,e.Vk)(B)(t)!=null})}derivePublicKey(t){return b(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{pluginId:s}=this.currencyInfo,{hdPathCoinType:i}=this.networkInfo,n=H(s)(t.keys),a=yield(0,k.mnemonicToSeed)(n.mnemonic),u=(0,L.fromSeed)(a).deriveHardened(44).deriveHardened(i).deriveHardened(0).neutered().toBase58(),E=p.w5.deriveAccount(n.mnemonic,p.BG.SECP256K1,this.derivationPath).address.toString();return{publicKey:u,address:E}})}parseUri(t,s,i){return b(this,null,function*(){const{pluginId:n}=this.currencyInfo,a={[n]:!0},{edgeParsedUri:o,edgeParsedUri:{publicAddress:l}}=(0,$.k)(this.currencyInfo,t,a,s!=null?s:this.currencyInfo.currencyCode,i);if(l==null||!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");return o})}encodeUri(t){return b(this,arguments,function*(s,i=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:a,currencyCode:o,publicAddress:l}=s;if(!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");let r;if(a!=null){const C=(0,U.Qs)(o!=null?o:this.currencyInfo.currencyCode,this.currencyInfo,i);if(C==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,w.div)(a,C.multiplier,18)}return(0,$.Q)(s,`${n}`,r)})}}function be(c){return b(this,null,function*(){return new Y(c)})}},69159:function(){},89214:function(){},52361:function(){},94616:function(){}}]);
|