edge-currency-accountbased 2.2.3 → 2.2.4
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 +9 -0
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +9 -9
- package/android/src/main/assets/edge-currency-accountbased/filecoin.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 +110 -78
- package/lib/filecoin/Filfox.js +68 -1
- package/lib/zcash/ZcashEngine.js +11 -9
- package/package.json +1 -1
|
@@ -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
|
+
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[518],{58355:function(F,O,u){var f=u(35717),g=u(51031),X=u(71027),_=u(89509).Buffer,e=u(78028),x=u(79785),P=u(89072),y=_.alloc(128);function A(w,h){X.call(this,"digest"),typeof h=="string"&&(h=_.from(h));var T=w==="sha512"||w==="sha384"?128:64;if(this._alg=w,this._key=h,h.length>T){var L=w==="rmd160"?new x:P(w);h=L.update(h).digest()}else h.length<T&&(h=_.concat([h,y],T));for(var D=this._ipad=_.allocUnsafe(T),p=this._opad=_.allocUnsafe(T),m=0;m<T;m++)D[m]=h[m]^54,p[m]=h[m]^92;this._hash=w==="rmd160"?new x:P(w),this._hash.update(D)}f(A,X),A.prototype._update=function(w){this._hash.update(w)},A.prototype._final=function(){var w=this._hash.digest(),h=this._alg==="rmd160"?new x:P(this._alg);return h.update(this._opad).update(w).digest()},F.exports=function(h,T){return h=h.toLowerCase(),h==="rmd160"||h==="ripemd160"?new A("rmd160",T):h==="md5"?new g(e,T):new A(h,T)}},51031:function(F,O,u){var f=u(35717),g=u(89509).Buffer,X=u(71027),_=g.alloc(128),e=64;function x(P,y){X.call(this,"digest"),typeof y=="string"&&(y=g.from(y)),this._alg=P,this._key=y,y.length>e?y=P(y):y.length<e&&(y=g.concat([y,_],e));for(var A=this._ipad=g.allocUnsafe(e),w=this._opad=g.allocUnsafe(e),h=0;h<e;h++)A[h]=y[h]^54,w[h]=y[h]^92;this._hash=[A]}f(x,X),x.prototype._update=function(P){this._hash.push(P)},x.prototype._final=function(){var P=this._alg(g.concat(this._hash));return this._alg(g.concat([this._opad,P]))},F.exports=x},79014:function(F,O,u){u.d(O,{Q:function(){return D},k:function(){return L}});var f=u(77591),g=u.n(f),X=u(24350),_=u(84564),e=u.n(_),x=u(76714),P=Object.defineProperty,y=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,h=(p,m,v)=>m in p?P(p,m,{enumerable:!0,configurable:!0,writable:!0,value:v}):p[m]=v,T=(p,m)=>{for(var v in m||(m={}))A.call(m,v)&&h(p,v,m[v]);if(y)for(var v of y(m))w.call(m,v)&&h(p,v,m[v]);return p};function L(p,m,v,I,B=[]){const C=T({},e()(m,{},!0)),K=m.startsWith(`${p.pluginId}://`);if(C.protocol!=null&&(C.protocol=C.protocol.replace(":","")),C.protocol!=null&&C.protocol!==""&&!v[C.protocol])throw new Error(`Uri protocol '${C.protocol}' is not supported for ${p.pluginId}.`);if(C.host===""&&C.pathname==="")throw new Error("Path and host not found in uri.");const S={publicAddress:C.host!==""?C.host:C.pathname.split("/")[0]},G=C.query.label,$=C.query.message,j=C.query.category;(G!=null||$!=null||j!=null||K)&&(S.metadata={},S.metadata.name=G,S.metadata.notes=$,S.metadata.category=j,S.metadata.gateway=K!=null?K:!1);const N=C.query.amount;if(N!=null&&typeof N=="string"){I==null&&(I=p.currencyCode);const R=(0,x.Qs)(I!=null?I:"",p,B);if(R==null)throw new Error("InternalErrorInvalidCurrencyCode");let W=(0,f.mul)(N,R.multiplier);W=(0,f.toFixed)(W,0,0),S.nativeAmount=W,S.currencyCode=I}return{edgeParsedUri:S,parsedUri:C}}function D(p,m,v){if(p.publicAddress==null)throw new Error("InvalidPublicAddressError");if(v==null&&p.label==null&&p.message==null)return p.publicAddress;{let I="";v!=null&&(I+="amount="+v+"&"),(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 B={scheme:m,path:p.publicAddress,query:I};return(0,X.qC)(B)}}},12636:function(F,O,u){u.r(O),u.d(O,{FilecoinTools:function(){return Y},makeCurrencyEngine:function(){return Ee},makeCurrencyTools:function(){return be}});var f=u(23145),g=u(77591),X=u(37786),_=u(2153),e=u(82448),x=u(35620),P=u(79014),y=u(76714),A=u(62177);const w=(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}),L=(0,A.jd)(T),D=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 p=u(94935),m=u(84650),v=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},o=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const I=(0,e.su)({statusCode:e.mH,message:e.XC,error:e.XC}),B=c=>(0,e.$e)((0,e._C)(I,c)),C=(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}),K=(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)(C),totalCount:e.mH}),S=K;class G{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountMessages(t,s,i=20){return v(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=B(V)(l);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getMessageDetails(t){return v(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/message/${t}`,{method:"GET",headers:{"content-type":"application/json"}})).text(),n=B(S)(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(d){n(d)}},o=r=>{try{l(s.throw(r))}catch(d){n(d)}},l=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,o);l((s=s.apply(c,t)).next())});const j=c=>(0,e.su)({result:c}),N=(0,e.su)({code:e.mH,message:e.XC}),R=c=>(0,e.$e)((0,e._C)(N,j(c))),W=(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)(W),()=>[]),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=R(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=R(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=R(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(d){n(d)}},o=r=>{try{l(s.throw(r))}catch(d){n(d)}},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,Q=Object.getOwnPropertySymbols,fe=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable,ge=Reflect.get,z=(c,t,s)=>t in c?ue(c,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):c[t]=s,ye=(c,t)=>{for(var s in t||(t={}))pe.call(t,s)&&z(c,s,t[s]);if(Q)for(var s of Q(t))me.call(t,s)&&z(c,s,t[s]);return c},Ce=(c,t)=>de(c,he(t)),J=(c,t,s)=>ge(fe(c),s,t),E=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},o=r=>{try{l(s.throw(r))}catch(d){n(d)}},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 U extends m.P{constructor(t,s,i,n){super(t,s,i,n),this.filfoxMessageToEdgeTransaction=o=>{const l=this.address.toString(),r=[],d=o.transfers.filter(k=>k.type==="miner-fee"||k.type==="burner-fee").reduce((k,Z)=>(0,g.add)(k,Z.value),"0");let b;return o.from===l?(b=`-${d}`,o.to!==l&&(b=(0,g.sub)(b,o.value))):(b=o.value,r.push(l)),{txid:o.cid,date:o.timestamp,currencyCode:this.currencyInfo.currencyCode,blockHeight:o.height,nativeAmount:b,isSend:b.startsWith("-"),networkFee:d,ourReceiveAddresses:r,signedTx:"",otherParams:{},walletId:this.walletId}};const{networkInfo:a}=t;this.address=f.kL.fromString(i.keys.address),this.availableAttoFil="0",this.isScanning=!1,this.networkInfo=a,this.pluginId=this.currencyInfo.pluginId,this.filRpc=new f.rP(t.networkInfo.rpcNode.networkName,{url:t.networkInfo.rpcNode.url,token:t.currencyInfo.currencyCode}),this.filfoxApi=new G(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=w(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 E(this,null,function*(){this.initData(),this.initSubscriptions(),yield J(U.prototype,this,"startEngine").call(this)})}killEngine(){return E(this,null,function*(){yield J(U.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return E(this,null,function*(){yield J(U.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return E(this,null,function*(){yield J(U.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 i=(yield this.makeSpend(t)).networkFee,n=(0,g.sub)(this.availableAttoFil,i);if((0,g.lte)(n,"0"))throw new p.C_;return n})}makeSpend(t){return E(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 p.$D;const l=f.kL.fromString(a),r=f.YW.getNew(l,this.address,f.WU.fromAtto(o),0);yield r.prepareToSend(this.filRpc);const d=r.toJSON(),b={sigJson:void 0,txJson:d},H=(0,g.mul)(d.GasLimit.toString(),d.GasPremium),k=(0,g.mul)((0,g.add)(o,H),"-1");return{txid:"",date:0,currencyCode:i,blockHeight:0,nativeAmount:k,isSend:!0,networkFee:H,ourReceiveAddresses:[],otherParams:b,signedTx:"",walletId:this.walletId}})}signTx(t,s){return E(this,null,function*(){const i=h(t.otherParams),n=f.YW.fromJSON(i.txJson),a=D(this.pluginId)(s),o=f.w5.deriveAccount(a.mnemonic,f.BG.SECP256K1,this.tools.derivationPath),l=yield f.w5.signTransaction(o,n);return t.otherParams=Ce(ye({},t.otherParams),{sigJson:l.toJSON()}),t.date=Date.now()/1e3,t})}broadcastTx(t,s){return E(this,null,function*(){const i=h(t.otherParams);if(i.sigJson==null)throw new Error("Cannot broadcast unsigned transaction");const n=f.Pc.fromJSON(i.sigJson),a=f.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 D(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}loadEngine(){return E(this,null,function*(){yield J(U.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*(){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 E(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 d of r){if(d.height<this.walletLocalData.lastAddressQueryHeight)return;const b=yield this.filfoxApi.getMessageDetails(d.cid),H=this.filfoxMessageToEdgeTransaction(b),k=o===0?1:++a/o;s({tx:H,progress:k})}}while(a<o)})}scanTransactionsFromFilscan(t,s){return E(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 d of r){if(d.height<this.walletLocalData.lastAddressQueryHeight)return;const b=this.filscanMessageToEdgeTransaction(d),H=o===0?1:++a/o;s({tx:b,progress:H})}}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,g.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 E(this,null,function*(){const n=L(s),a=new U(c,t,n,i);return yield a.loadEngine(),a})}var M=(c,t,s)=>new Promise((i,n)=>{var a=r=>{try{l(s.next(r))}catch(d){n(d)}},o=r=>{try{l(s.throw(r))}catch(d){n(d)}},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 M(this,null,function*(){try{return f.kL.fromString(t),!0}catch{return!1}})}importPrivateKey(t){return M(this,arguments,function*(s,i={}){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 M(this,null,function*(){const{pluginId:s}=this.currencyInfo;if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const i=x.YU.stringify(this.io.random(32)),n=(0,_.entropyToMnemonic)(i);return{[`${s}Key`]:i,[`${s}Mnemonic`]:n}})}checkPublicKey(t){return M(this,null,function*(){return(0,e.Vk)(T)(t)!=null})}derivePublicKey(t){return M(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{pluginId:s}=this.currencyInfo,{hdPathCoinType:i}=this.networkInfo,n=D(s)(t.keys),a=yield(0,_.mnemonicToSeed)(n.mnemonic),d=(0,X.fromSeed)(a).deriveHardened(44).deriveHardened(i).deriveHardened(0).neutered().toBase58(),H=f.w5.deriveAccount(n.mnemonic,f.BG.SECP256K1,this.derivationPath).address.toString();return{publicKey:d,address:H}})}parseUri(t,s,i){return M(this,null,function*(){const{pluginId:n}=this.currencyInfo,a={[n]:!0},{edgeParsedUri:o,edgeParsedUri:{publicAddress:l}}=(0,P.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 M(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 b=(0,y.Qs)(o!=null?o:this.currencyInfo.currencyCode,this.currencyInfo,i);if(b==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,g.div)(a,b.multiplier,18)}return(0,P.Q)(s,`${n}`,r)})}}function be(c){return M(this,null,function*(){return new Y(c)})}},35620:function(F,O,u){u.d(O,{US:function(){return e},YU:function(){return g}});var f=u(79911);const g=f.base16,X=f.base32,_=f.base32hex,e=f.base64,x=f.base64url,P=f.codec;var y=null}}]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[159],{79014:function(
|
|
2
|
-
${(0,
|
|
1
|
+
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[159],{79014:function(F,H,d){d.d(H,{Q:function(){return V},k:function(){return b}});var g=d(77591),A=d.n(g),$=d(24350),O=d(84564),x=d.n(O),N=d(76714),h=Object.defineProperty,M=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,P=(a,y,f)=>y in a?h(a,y,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[y]=f,S=(a,y)=>{for(var f in y||(y={}))L.call(y,f)&&P(a,f,y[f]);if(M)for(var f of M(y))U.call(y,f)&&P(a,f,y[f]);return a};function b(a,y,f,m,D=[]){const u=S({},x()(y,{},!0)),T=y.startsWith(`${a.pluginId}://`);if(u.protocol!=null&&(u.protocol=u.protocol.replace(":","")),u.protocol!=null&&u.protocol!==""&&!f[u.protocol])throw new Error(`Uri protocol '${u.protocol}' is not supported for ${a.pluginId}.`);if(u.host===""&&u.pathname==="")throw new Error("Path and host not found in uri.");const k={publicAddress:u.host!==""?u.host:u.pathname.split("/")[0]},p=u.query.label,I=u.query.message,z=u.query.category;(p!=null||I!=null||z!=null||T)&&(k.metadata={},k.metadata.name=p,k.metadata.notes=I,k.metadata.category=z,k.metadata.gateway=T!=null?T:!1);const w=u.query.amount;if(w!=null&&typeof w=="string"){m==null&&(m=a.currencyCode);const B=(0,N.Qs)(m!=null?m:"",a,D);if(B==null)throw new Error("InternalErrorInvalidCurrencyCode");let K=(0,g.mul)(w,B.multiplier);K=(0,g.toFixed)(K,0,0),k.nativeAmount=K,k.currencyCode=m}return{edgeParsedUri:k,parsedUri:u}}function V(a,y,f){if(a.publicAddress==null)throw new Error("InvalidPublicAddressError");if(f==null&&a.label==null&&a.message==null)return a.publicAddress;{let m="";f!=null&&(m+="amount="+f+"&"),(a.label!=null||a.message!=null)&&(typeof a.label=="string"&&(m+="label="+a.label+"&"),typeof a.message=="string"&&(m+="message="+a.message+"&")),m=m.substr(0,m.length-1);const D={scheme:y,path:a.publicAddress,query:m};return(0,$.qC)(D)}}},62560:function(F,H,d){d.r(H),d.d(H,{ZcashTools:function(){return B},makeCurrencyEngine:function(){return z},makeCurrencyTools:function(){return K}});var g=d(77591),A=d(2153),$=d(48764),O=d(62177),x=d(79014),N=d(76714),h=d(82448);const M=(0,h.su)({first:h.mH,last:h.mH}),L=(0,h.su)({alias:(0,h.Vk)(h.XC),blockRange:(0,h.Vk)(M,()=>({first:0,last:0}))}),U=(0,h.su)({birthdayHeight:h.mH,publicKey:h.XC,unifiedViewingKeys:(0,h.su)({extfvk:h.XC,extpub:h.XC})}),P=(0,O.jd)(U),S=s=>{const t=(0,h.su)({[`${s}Mnemonic`]:h.XC,[`${s}SpendKey`]:h.XC,[`${s}BirthdayHeight`]:h.mH});return(0,h.W1)(e=>{const n=t(e);return{mnemonic:n[`${s}Mnemonic`],spendKey:n[`${s}SpendKey`],birthdayHeight:n[`${s}BirthdayHeight`]}},e=>({[`${s}Mnemonic`]:e.mnemonic,[`${s}SpendKey`]:e.spendKey,[`${s}BirthdayHeight`]:e.birthdayHeight}))};var b=d(94935),V=d(84650),a=Object.defineProperty,y=Object.getOwnPropertySymbols,f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,u=Reflect.get,T=(s,t,e)=>t in s?a(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,_=(s,t)=>{for(var e in t||(t={}))m.call(t,e)&&T(s,e,t[e]);if(y)for(var e of y(t))D.call(t,e)&&T(s,e,t[e]);return s},k=(s,t,e)=>u(f(s),e,t),p=(s,t,e)=>new Promise((n,r)=>{var l=i=>{try{c(e.next(i))}catch(v){r(v)}},o=i=>{try{c(e.throw(i))}catch(v){r(v)}},c=i=>i.done?n(i.value):Promise.resolve(i.value).then(l,o);c((e=e.apply(s,t)).next())});class I extends V.P{constructor(t,e,n,r,l){super(t,e,n,r);const{networkInfo:o}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=o,this.makeSynchronizer=l,this.queryMutex=!1}setOtherData(t){this.otherData=L(t)}initData(){const{birthdayHeight:t,alias:e}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.alias=e,this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio=0}initSubscriptions(){this.synchronizer.on("update",t=>p(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>p(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()}))}queryAll(){return p(this,null,function*(){if(!this.queryMutex){this.queryMutex=!0;try{yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()}catch{}this.queryMutex=!1}})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=e*.99/100;let r=0;if(t>0){const o=n-t;this.initialNumBlocksToDownload<0&&(this.initialNumBlocksToDownload=o),r=o===0||this.initialNumBlocksToDownload===0?1:1-o/this.initialNumBlocksToDownload}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=r*.8;const l=(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]+this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode])/2;l!==this.progressRatio&&(Math.abs(l-this.progressRatio)>.1||l===1)&&(this.progressRatio=l,this.updateOnAddressesChecked())}}startEngine(){return p(this,null,function*(){this.initData(),this.synchronizer=yield this.makeSynchronizer(this.initializer),yield this.synchronizer.start(),this.initSubscriptions(),yield k(I.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return p(this,null,function*(){if(!!this.isSynced())try{const t=yield this.synchronizer.getShieldedBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return p(this,null,function*(){try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,g.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r={txid:t.rawTransactionId,date:t.blockTimeInSeconds,currencyCode:this.currencyInfo.currencyCode,blockHeight:t.minedHeight,nativeAmount:e,isSend:e.startsWith("-"),networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:n,signedTx:"",otherParams:{},walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,r)}killEngine(){return p(this,null,function*(){yield this.synchronizer.stop(),yield k(I.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return p(this,null,function*(){yield k(I.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield k(I.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),this.synchronizer.rescan(this.walletInfo.keys.birthdayHeight).catch(t=>this.warn("resyncBlockchain failed: ",t))})}getMaxSpendable(){return p(this,null,function*(){const t=(0,g.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,g.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return p(this,null,function*(){var e;if(!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),l=n.spendTargets[0],{publicAddress:o,nativeAmount:c}=l;if(o==null)throw new Error("makeSpend Missing publicAddress");if(c==null)throw new b.$D;if((0,g.eq)(c,"0"))throw new b.$D;const i=(0,g.add)(c,this.networkInfo.defaultNetworkFee);if((0,g.gt)(i,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,g.gt)(i,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const v=n.spendTargets.map(E=>{var W;return{uniqueIdentifier:E.uniqueIdentifier,memo:E.memo,nativeAmount:(W=E.nativeAmount)!=null?W:"0",currencyCode:r,publicAddress:o}}),C=(0,g.mul)(i,"-1");return{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:C,isSend:!0,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",spendTargets:v,walletId:this.walletId}})}signTx(t){return p(this,null,function*(){return t})}broadcastTx(t,e){return p(this,null,function*(){var n,r;const l=S(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const o=t.spendTargets[0],c={zatoshi:(0,g.sub)((0,g.abs)(t.nativeAmount),t.networkFee),toAddress:o.publicAddress,memo:(r=(n=o.memo)!=null?n:o.uniqueIdentifier)!=null?r:"",fromAccountIndex:0,spendingKey:l.spendKey};try{const i=yield this.synchronizer.sendToAddress(c);t.txid=i.txId,t.signedTx=i.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,N.oX)(t)}`)}catch(i){throw this.warn("FAILURE broadcastTx failed: ",i),i}return t})}loadEngine(){return p(this,null,function*(){const{walletInfo:t}=this;yield k(I.prototype,this,"loadEngine").call(this),this.engineOn=!0;const{rpcNode:e}=this.networkInfo;this.initializer=_({fullViewingKey:t.keys.unifiedViewingKeys,birthdayHeight:t.keys.birthdayHeight,alias:t.keys.publicKey},e)})}}function z(s,t,e,n){return p(this,null,function*(){const r=P(e),{makeSynchronizer:l}=s.nativeIo["edge-currency-accountbased"][s.networkInfo.nativeSdk],o=new I(s,t,r,n,l);return yield o.loadEngine(),o})}var w=(s,t,e)=>new Promise((n,r)=>{var l=i=>{try{c(e.next(i))}catch(v){r(v)}},o=i=>{try{c(e.throw(i))}catch(v){r(v)}},c=i=>i.done?n(i.value):Promise.resolve(i.value).then(l,o);c((e=e.apply(s,t)).next())});class B{constructor(t){const{builtinTokens:e,currencyInfo:n,io:r,networkInfo:l}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=r,this.networkInfo=l;const o=t.nativeIo["edge-currency-accountbased"];if(o==null)throw new Error("Need opts");const{KeyTool:c,AddressTool:i}=o[this.networkInfo.nativeSdk];this.KeyTool=c,this.AddressTool=i}getDisplayPrivateKey(t){return w(this,null,function*(){const{pluginId:e}=this.currencyInfo;return S(e)(t.keys).mnemonic})}getDisplayPublicKey(t){return w(this,null,function*(){var e;const{keys:n}=P(t);return(e=n.unifiedViewingKeys)==null?void 0:e.extfvk})}getNewWalletBirthdayBlockheight(){return w(this,null,function*(){try{return yield this.KeyTool.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)}catch{return this.networkInfo.defaultBirthday}})}isValidAddress(t){return w(this,null,function*(){return(yield this.AddressTool.isValidShieldedAddress(t))||(yield this.AddressTool.isValidTransparentAddress(t))})}importPrivateKey(t){return w(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo;if(!(0,A.validateMnemonic)(e))throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const c=(yield(0,A.mnemonicToSeed)(e)).toString("hex"),i=yield this.KeyTool.deriveSpendingKey(c,this.networkInfo.rpcNode.networkName);if(typeof i!="string")throw new Error("Invalid spendKey type");const v=yield this.getNewWalletBirthdayBlockheight();let C=v;const{birthdayHeight:R}=n;if(R!=null){(0,O.jD)(R);const E=parseInt(R);if(E>v)throw new Error("InvalidBirthdayHeight");C=E}return{[`${r}Mnemonic`]:e,[`${r}SpendKey`]:i,[`${r}BirthdayHeight`]:C}})}createPrivateKey(t){return w(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=$.Buffer.from(this.io.random(32)).toString("hex"),n=(0,A.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return w(this,null,function*(){try{return U(t),!0}catch{return!1}})}derivePublicKey(t){return w(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=S(e)(t.keys);if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const r=n.mnemonic;if(typeof r!="string")throw new Error("InvalidMnemonic");const o=(yield(0,A.mnemonicToSeed)(r)).toString("hex"),c=yield this.KeyTool.deriveViewingKey(o,this.networkInfo.rpcNode.networkName),i=yield this.AddressTool.deriveShieldedAddress(c.extfvk,this.networkInfo.rpcNode.networkName);return{birthdayHeight:n.birthdayHeight,publicKey:i,unifiedViewingKeys:c}})}parseUri(t,e,n){return w(this,null,function*(){const{pluginId:r}=this.currencyInfo,l={[r]:!0},{edgeParsedUri:o,edgeParsedUri:{publicAddress:c}}=(0,x.k)(this.currencyInfo,t,l,e!=null?e:this.currencyInfo.currencyCode,n);if(c==null||!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");return o})}encodeUri(t){return w(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:l,currencyCode:o,publicAddress:c}=e;if(!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");let i;if(l!=null){const C=(0,N.Qs)(o!=null?o:this.currencyInfo.currencyCode,this.currencyInfo,n);if(C==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,g.div)(l,C.multiplier,18)}return(0,x.Q)(e,`${r}`,i)})}}function K(s){return w(this,null,function*(){return new B(s)})}}}]);
|
|
@@ -118,6 +118,14 @@ const builtinTokens = {
|
|
|
118
118
|
contractAddress: '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664'
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
|
+
'9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7': {
|
|
122
|
+
currencyCode: 'USDT',
|
|
123
|
+
displayName: 'Tether USD',
|
|
124
|
+
denominations: [{ name: 'USDT', multiplier: '1000000' }],
|
|
125
|
+
networkLocation: {
|
|
126
|
+
contractAddress: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7'
|
|
127
|
+
}
|
|
128
|
+
},
|
|
121
129
|
c7198437980c041c805a1edcba50c1ce5db95118: {
|
|
122
130
|
currencyCode: 'USDT.e',
|
|
123
131
|
displayName: 'Tether USD',
|
|
@@ -934,6 +934,14 @@ const builtinTokens = {
|
|
|
934
934
|
contractAddress: '0x3a4f40631a4f906c2BaD353Ed06De7A5D3fCb430'
|
|
935
935
|
}
|
|
936
936
|
},
|
|
937
|
+
e17b8adf8e46b15f3f9ab4bb9e3b6e31db09126e: {
|
|
938
|
+
currencyCode: 'PYUSD',
|
|
939
|
+
displayName: 'PayPal USD',
|
|
940
|
+
denominations: [{ name: 'PYUSD', multiplier: '1000000' }],
|
|
941
|
+
networkLocation: {
|
|
942
|
+
contractAddress: '0xe17b8aDF8E46b15f3F9aB4Bb9E3b6e31Db09126E'
|
|
943
|
+
}
|
|
944
|
+
},
|
|
937
945
|
'4a220e6096b25eadb88358cb44068a3248254675': {
|
|
938
946
|
currencyCode: 'QNT',
|
|
939
947
|
displayName: 'Quant',
|
|
@@ -51,6 +51,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
|
|
54
55
|
|
|
55
56
|
// Backends:
|
|
56
57
|
|
|
@@ -68,6 +69,10 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
68
69
|
const { networkInfo } = env
|
|
69
70
|
this.address = _izarifilecoin.Address.fromString(walletInfo.keys.address)
|
|
70
71
|
this.availableAttoFil = '0'
|
|
72
|
+
this.isScanning = false
|
|
73
|
+
this.networkInfo = networkInfo
|
|
74
|
+
this.pluginId = this.currencyInfo.pluginId
|
|
75
|
+
|
|
71
76
|
this.filRpc = new (0, _izarifilecoin.RPC)(env.networkInfo.rpcNode.networkName, {
|
|
72
77
|
url: env.networkInfo.rpcNode.url,
|
|
73
78
|
token: env.currencyInfo.currencyCode
|
|
@@ -75,9 +80,6 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
75
80
|
this.filfoxApi = new (0, _Filfox.Filfox)(env.networkInfo.filfoxUrl, env.io.fetchCors)
|
|
76
81
|
this.filscanApi = new (0, _Filscan.Filscan)(env.networkInfo.filscanUrl, env.io.fetchCors)
|
|
77
82
|
this.rpcExtra = new (0, _RpcExtra.RpcExtra)(env.networkInfo.rpcNode.url, env.io.fetchCors)
|
|
78
|
-
|
|
79
|
-
this.networkInfo = networkInfo
|
|
80
|
-
this.pluginId = this.currencyInfo.pluginId
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
setOtherData(raw) {
|
|
@@ -85,9 +87,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
initData() {
|
|
88
|
-
|
|
89
|
-
// ...
|
|
90
|
-
|
|
90
|
+
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] = 0
|
|
91
91
|
// Engine variables
|
|
92
92
|
this.availableAttoFil = '0'
|
|
93
93
|
}
|
|
@@ -189,15 +189,15 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
const networkFee = _biggystring.mul.call(void 0, txJson.GasLimit.toString(), txJson.GasPremium) // TODO: Include base fee and burn fee somehow?
|
|
192
|
-
const
|
|
192
|
+
const txNativeAmount = _biggystring.mul.call(void 0, _biggystring.add.call(void 0, nativeAmount, networkFee), '-1')
|
|
193
193
|
|
|
194
194
|
const edgeTransaction = {
|
|
195
195
|
txid: '',
|
|
196
196
|
date: 0,
|
|
197
197
|
currencyCode,
|
|
198
198
|
blockHeight: 0,
|
|
199
|
-
nativeAmount:
|
|
200
|
-
isSend:
|
|
199
|
+
nativeAmount: txNativeAmount,
|
|
200
|
+
isSend: true,
|
|
201
201
|
networkFee,
|
|
202
202
|
ourReceiveAddresses: [],
|
|
203
203
|
otherParams,
|
|
@@ -230,6 +230,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
230
230
|
sigJson: signature.toJSON()
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
edgeTransaction.date = Date.now() / 1000
|
|
234
|
+
|
|
233
235
|
return edgeTransaction
|
|
234
236
|
}
|
|
235
237
|
|
|
@@ -297,52 +299,71 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
297
299
|
}
|
|
298
300
|
|
|
299
301
|
async checkTransactions() {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
302
|
+
// We shouldn't start scanning if scanning is already happening:
|
|
303
|
+
if (this.isScanning) return
|
|
304
|
+
try {
|
|
305
|
+
this.isScanning = true
|
|
306
|
+
|
|
307
|
+
const addressString = this.address.toString()
|
|
308
|
+
|
|
309
|
+
const handleScanProgress = (progress) => {
|
|
310
|
+
const currentProgress =
|
|
311
|
+
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]
|
|
312
|
+
const newProgress = progress
|
|
313
|
+
|
|
314
|
+
if (
|
|
315
|
+
// Only send event if we haven't completed sync
|
|
316
|
+
currentProgress < 1 &&
|
|
317
|
+
// Avoid thrashing
|
|
318
|
+
(newProgress >= 1 || newProgress > currentProgress * 1.1)
|
|
319
|
+
) {
|
|
320
|
+
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] =
|
|
321
|
+
newProgress
|
|
322
|
+
this.updateOnAddressesChecked()
|
|
323
|
+
}
|
|
316
324
|
}
|
|
317
|
-
}
|
|
318
325
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
326
|
+
const handleScan = ({
|
|
327
|
+
tx,
|
|
328
|
+
progress
|
|
329
|
+
}
|
|
323
330
|
|
|
324
331
|
|
|
325
332
|
) => {
|
|
326
|
-
|
|
327
|
-
|
|
333
|
+
this.addTransaction(this.currencyInfo.currencyCode, tx)
|
|
334
|
+
this.onUpdateTransactions()
|
|
335
|
+
|
|
336
|
+
// Progress the block-height if the message's height is greater than
|
|
337
|
+
// last poll for block-height.
|
|
338
|
+
if (this.walletLocalData.blockHeight < tx.blockHeight) {
|
|
339
|
+
this.onUpdateBlockHeight(tx.blockHeight)
|
|
340
|
+
}
|
|
328
341
|
|
|
329
|
-
|
|
330
|
-
// last poll for block-height.
|
|
331
|
-
if (this.walletLocalData.blockHeight < tx.blockHeight) {
|
|
332
|
-
this.onUpdateBlockHeight(tx.blockHeight)
|
|
342
|
+
handleScanProgress(progress)
|
|
333
343
|
}
|
|
334
344
|
|
|
335
|
-
|
|
336
|
-
|
|
345
|
+
const scanners = [
|
|
346
|
+
// this.scanTransactionsFromFilscan(addressString, handleScan),
|
|
347
|
+
this.scanTransactionsFromFilfox(addressString, handleScan)
|
|
348
|
+
]
|
|
337
349
|
|
|
338
|
-
|
|
339
|
-
this.scanTransactionsFromFilscan(addressString, handleScan),
|
|
340
|
-
this.scanTransactionsFromFilfox(addressString, handleScan)
|
|
341
|
-
]
|
|
350
|
+
const startingNetworkHeight = this.walletLocalData.blockHeight
|
|
342
351
|
|
|
343
|
-
|
|
352
|
+
// Run scanners:
|
|
353
|
+
await Promise.all(scanners)
|
|
344
354
|
|
|
345
|
-
|
|
355
|
+
// Save the network height at the start of the scanning
|
|
356
|
+
this.walletLocalData.lastAddressQueryHeight = startingNetworkHeight
|
|
357
|
+
this.walletLocalDataDirty = true
|
|
358
|
+
|
|
359
|
+
// Make sure the sync progress is 100%
|
|
360
|
+
handleScanProgress(1)
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error(error)
|
|
363
|
+
throw error
|
|
364
|
+
} finally {
|
|
365
|
+
this.isScanning = false
|
|
366
|
+
}
|
|
346
367
|
}
|
|
347
368
|
|
|
348
369
|
async scanTransactionsFromFilfox(
|
|
@@ -367,17 +388,14 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
367
388
|
|
|
368
389
|
const messages = messagesResponse.messages
|
|
369
390
|
for (const message of messages) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (idx >= 0) {
|
|
374
|
-
// Exit early because we reached transaction history from previous
|
|
375
|
-
// check
|
|
376
|
-
return
|
|
377
|
-
}
|
|
391
|
+
// Exit when we reach a transaction we may already have saved
|
|
392
|
+
if (message.height < this.walletLocalData.lastAddressQueryHeight) return
|
|
378
393
|
|
|
379
394
|
// Process message into a transaction
|
|
380
|
-
const
|
|
395
|
+
const messageDetails = await this.filfoxApi.getMessageDetails(
|
|
396
|
+
message.cid
|
|
397
|
+
)
|
|
398
|
+
const tx = this.filfoxMessageToEdgeTransaction(messageDetails)
|
|
381
399
|
|
|
382
400
|
// Calculate the progress
|
|
383
401
|
const progress =
|
|
@@ -410,14 +428,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
410
428
|
|
|
411
429
|
const messages = messagesResponse.messages_by_account_id_list
|
|
412
430
|
for (const message of messages) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (idx >= 0) {
|
|
417
|
-
// Exit early because we reached transaction history from previous
|
|
418
|
-
// check
|
|
419
|
-
return
|
|
420
|
-
}
|
|
431
|
+
// Exit when we reach a transaction we may already have saved
|
|
432
|
+
if (message.height < this.walletLocalData.lastAddressQueryHeight) return
|
|
421
433
|
|
|
422
434
|
// Process message into a transaction
|
|
423
435
|
const tx = this.filscanMessageToEdgeTransaction(message)
|
|
@@ -432,27 +444,41 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
432
444
|
}
|
|
433
445
|
|
|
434
446
|
__init() {this.filfoxMessageToEdgeTransaction = (
|
|
435
|
-
|
|
447
|
+
messageDetails
|
|
436
448
|
) => {
|
|
437
449
|
const addressString = this.address.toString()
|
|
438
|
-
let netNativeAmount = message.value
|
|
439
450
|
const ourReceiveAddresses = []
|
|
440
451
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
452
|
+
// Handle network fees:
|
|
453
|
+
const networkFee = messageDetails.transfers
|
|
454
|
+
.filter(
|
|
455
|
+
transfer =>
|
|
456
|
+
transfer.type === 'miner-fee' || transfer.type === 'burner-fee'
|
|
457
|
+
)
|
|
458
|
+
.reduce((sum, transfer) => _biggystring.add.call(void 0, sum, transfer.value), '0')
|
|
459
|
+
|
|
460
|
+
// Handle native amount:
|
|
461
|
+
let nativeAmount
|
|
462
|
+
if (messageDetails.from === addressString) {
|
|
463
|
+
// For spends, always include network fee
|
|
464
|
+
nativeAmount = `-${networkFee}`
|
|
465
|
+
if (messageDetails.to !== addressString) {
|
|
466
|
+
// For spends not to self, subtract tx value
|
|
467
|
+
nativeAmount = _biggystring.sub.call(void 0, nativeAmount, messageDetails.value)
|
|
468
|
+
}
|
|
445
469
|
} else {
|
|
470
|
+
// For receives nativeAMount is always positively the value
|
|
471
|
+
nativeAmount = messageDetails.value
|
|
446
472
|
ourReceiveAddresses.push(addressString)
|
|
447
473
|
}
|
|
448
474
|
|
|
449
475
|
const edgeTransaction = {
|
|
450
|
-
txid:
|
|
451
|
-
date:
|
|
476
|
+
txid: messageDetails.cid,
|
|
477
|
+
date: messageDetails.timestamp,
|
|
452
478
|
currencyCode: this.currencyInfo.currencyCode,
|
|
453
|
-
blockHeight:
|
|
454
|
-
nativeAmount
|
|
455
|
-
isSend:
|
|
479
|
+
blockHeight: messageDetails.height,
|
|
480
|
+
nativeAmount,
|
|
481
|
+
isSend: nativeAmount.startsWith('-'),
|
|
456
482
|
networkFee,
|
|
457
483
|
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
|
|
458
484
|
signedTx: '',
|
|
@@ -465,14 +491,20 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
465
491
|
|
|
466
492
|
filscanMessageToEdgeTransaction(message) {
|
|
467
493
|
const addressString = this.address.toString()
|
|
468
|
-
let netNativeAmount = message.value
|
|
469
494
|
const ourReceiveAddresses = []
|
|
470
495
|
|
|
471
496
|
const networkFee = '0' // TODO: calculate transaction fee from onchain gas fields
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
497
|
+
let nativeAmount
|
|
498
|
+
if (message.from === addressString) {
|
|
499
|
+
// For spends, always include network fee
|
|
500
|
+
nativeAmount = `-${networkFee}`
|
|
501
|
+
if (message.to !== addressString) {
|
|
502
|
+
// For spends not to self, subtract tx value
|
|
503
|
+
nativeAmount = _biggystring.sub.call(void 0, nativeAmount, message.value)
|
|
504
|
+
}
|
|
475
505
|
} else {
|
|
506
|
+
// For receives nativeAMount is always positively the value
|
|
507
|
+
nativeAmount = message.value
|
|
476
508
|
ourReceiveAddresses.push(addressString)
|
|
477
509
|
}
|
|
478
510
|
|
|
@@ -481,8 +513,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
481
513
|
date: message.block_time,
|
|
482
514
|
currencyCode: this.currencyInfo.currencyCode,
|
|
483
515
|
blockHeight: message.height,
|
|
484
|
-
nativeAmount
|
|
485
|
-
isSend:
|
|
516
|
+
nativeAmount,
|
|
517
|
+
isSend: nativeAmount.startsWith('-'),
|
|
486
518
|
networkFee,
|
|
487
519
|
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
|
|
488
520
|
signedTx: '',
|
package/lib/filecoin/Filfox.js
CHANGED
|
@@ -40,7 +40,7 @@ var _cleaners = require('cleaners');
|
|
|
40
40
|
height: _cleaners.asNumber,
|
|
41
41
|
method: _cleaners.asString,
|
|
42
42
|
nonce: _cleaners.asNumber,
|
|
43
|
-
|
|
43
|
+
receipt: _cleaners.asObject.call(void 0, {
|
|
44
44
|
exitCode: _cleaners.asNumber
|
|
45
45
|
}),
|
|
46
46
|
timestamp: _cleaners.asNumber,
|
|
@@ -48,6 +48,42 @@ var _cleaners = require('cleaners');
|
|
|
48
48
|
value: _cleaners.asString
|
|
49
49
|
}); exports.asFilfoxMessage = asFilfoxMessage
|
|
50
50
|
|
|
51
|
+
|
|
52
|
+
const asFilfoxMessageDetailed = _cleaners.asObject.call(void 0, {
|
|
53
|
+
cid: _cleaners.asString,
|
|
54
|
+
height: _cleaners.asNumber,
|
|
55
|
+
timestamp: _cleaners.asNumber,
|
|
56
|
+
from: _cleaners.asString,
|
|
57
|
+
to: _cleaners.asString,
|
|
58
|
+
value: _cleaners.asString,
|
|
59
|
+
gasLimit: _cleaners.asNumber,
|
|
60
|
+
gasFeeCap: _cleaners.asString,
|
|
61
|
+
gasPremium: _cleaners.asString,
|
|
62
|
+
receipt: _cleaners.asObject.call(void 0, {
|
|
63
|
+
exitCode: _cleaners.asNumber,
|
|
64
|
+
return: _cleaners.asString,
|
|
65
|
+
gasUsed: _cleaners.asNumber
|
|
66
|
+
}),
|
|
67
|
+
baseFee: _cleaners.asString,
|
|
68
|
+
fee: _cleaners.asObject.call(void 0, {
|
|
69
|
+
baseFeeBurn: _cleaners.asString,
|
|
70
|
+
overEstimationBurn: _cleaners.asString,
|
|
71
|
+
minerPenalty: _cleaners.asString,
|
|
72
|
+
minerTip: _cleaners.asString,
|
|
73
|
+
refund: _cleaners.asString
|
|
74
|
+
}),
|
|
75
|
+
transfers: _cleaners.asArray.call(void 0,
|
|
76
|
+
_cleaners.asObject.call(void 0, {
|
|
77
|
+
from: _cleaners.asString,
|
|
78
|
+
fromId: _cleaners.asString,
|
|
79
|
+
to: _cleaners.asString,
|
|
80
|
+
toId: _cleaners.asString,
|
|
81
|
+
value: _cleaners.asString,
|
|
82
|
+
type: _cleaners.asString
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
}); exports.asFilfoxMessageDetailed = asFilfoxMessageDetailed
|
|
86
|
+
|
|
51
87
|
//
|
|
52
88
|
// Messages
|
|
53
89
|
//
|
|
@@ -58,6 +94,15 @@ var _cleaners = require('cleaners');
|
|
|
58
94
|
totalCount: _cleaners.asNumber
|
|
59
95
|
}); exports.asFilfoxMessagesResult = asFilfoxMessagesResult
|
|
60
96
|
|
|
97
|
+
//
|
|
98
|
+
// Message Details
|
|
99
|
+
//
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
const asFilfoxMessageDetailsResult = exports.asFilfoxMessageDetailed; exports.asFilfoxMessageDetailsResult = asFilfoxMessageDetailsResult
|
|
105
|
+
|
|
61
106
|
// -----------------------------------------------------------------------------
|
|
62
107
|
// Implementation
|
|
63
108
|
// -----------------------------------------------------------------------------
|
|
@@ -98,4 +143,26 @@ var _cleaners = require('cleaners');
|
|
|
98
143
|
|
|
99
144
|
return responseBody
|
|
100
145
|
}
|
|
146
|
+
|
|
147
|
+
async getMessageDetails(
|
|
148
|
+
messageCid
|
|
149
|
+
) {
|
|
150
|
+
const response = await this.fetch(`${this.baseUrl}/message/${messageCid}`, {
|
|
151
|
+
method: 'GET',
|
|
152
|
+
headers: {
|
|
153
|
+
'content-type': 'application/json'
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
const responseText = await response.text()
|
|
157
|
+
const responseBody = exports.asFilfoxEnvelope.call(void 0, (0, exports.asFilfoxMessageDetailsResult))(
|
|
158
|
+
responseText
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if ('error' in responseBody)
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Error response code ${responseBody.statusCode}: ${responseBody.message} ${responseBody.error}`
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
return responseBody
|
|
167
|
+
}
|
|
101
168
|
} exports.Filfox = Filfox;
|
package/lib/zcash/ZcashEngine.js
CHANGED
|
@@ -338,16 +338,18 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
338
338
|
publicAddress
|
|
339
339
|
}))
|
|
340
340
|
|
|
341
|
+
const txNativeAmount = _biggystring.mul.call(void 0, totalTxAmount, '-1')
|
|
342
|
+
|
|
341
343
|
const edgeTransaction = {
|
|
342
|
-
txid: '',
|
|
343
|
-
date: 0,
|
|
344
|
-
currencyCode,
|
|
345
|
-
blockHeight: 0,
|
|
346
|
-
nativeAmount:
|
|
347
|
-
isSend:
|
|
348
|
-
networkFee: this.networkInfo.defaultNetworkFee,
|
|
349
|
-
ourReceiveAddresses: [],
|
|
350
|
-
signedTx: '',
|
|
344
|
+
txid: '',
|
|
345
|
+
date: 0,
|
|
346
|
+
currencyCode,
|
|
347
|
+
blockHeight: 0,
|
|
348
|
+
nativeAmount: txNativeAmount,
|
|
349
|
+
isSend: true,
|
|
350
|
+
networkFee: this.networkInfo.defaultNetworkFee,
|
|
351
|
+
ourReceiveAddresses: [],
|
|
352
|
+
signedTx: '',
|
|
351
353
|
spendTargets,
|
|
352
354
|
walletId: this.walletId
|
|
353
355
|
}
|