edge-currency-accountbased 2.8.0 → 2.8.2
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/filecoin.chunk.js +1 -1
- package/edge-currency-accountbased.d.ts +31 -0
- package/lib/declare-modules.d.js +0 -2
- package/lib/filecoin/FilecoinEngine.js +61 -16
- package/lib/index.js +8 -0
- package/package.json +3 -2
- package/lib/globals.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.8.2 (2023-10-25)
|
|
6
|
+
|
|
7
|
+
- fixed: Filecoin `getMaxSpendable` fee race conditions are resolved by caching the max-spend parameters.
|
|
8
|
+
- fixed: Filecoin resync bugs
|
|
9
|
+
|
|
10
|
+
## 2.8.1 (2023-10-24)
|
|
11
|
+
|
|
12
|
+
- fixed: Provide working type definitions for this library.
|
|
13
|
+
|
|
5
14
|
## 2.8.0 (2023-10-23)
|
|
6
15
|
|
|
7
16
|
- added: Filecoin Testnet (Calibration)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8518],{79014:function(se,R,h){"use strict";h.d(R,{Q:function(){return _},k:function(){return Q}});var p=h(77591),E=h.n(p),J=h(24350),I=h(84564),e=h.n(I),G=h(76714),U=Object.defineProperty,B=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,x=(d,g,y)=>g in d?U(d,g,{enumerable:!0,configurable:!0,writable:!0,value:y}):d[g]=y,L=(d,g)=>{for(var y in g||(g={}))j.call(g,y)&&x(d,y,g[y]);if(B)for(var y of B(g))V.call(g,y)&&x(d,y,g[y]);return d};function Q(d,g,y,C,H=[]){const f=L({},e()(g,{},!0)),O=g.startsWith(`${d.pluginId}://`);if(f.protocol!=null&&(f.protocol=f.protocol.replace(":","")),f.protocol!=null&&f.protocol!==""&&!y[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 A={publicAddress:f.host!==""?f.host:f.pathname.split("/")[0]},K=f.query.label,N=f.query.message,W=f.query.category;(K!=null||N!=null||W!=null||O)&&(A.metadata={},A.metadata.name=K,A.metadata.notes=N,A.metadata.category=W,A.metadata.gateway=O!=null?O:!1);const D=f.query.amount;if(D!=null&&typeof D=="string"){C==null&&(C=d.currencyCode);const S=(0,G.Qs)(C!=null?C:"",d,H);if(S==null)throw new Error("InternalErrorInvalidCurrencyCode");let F=(0,p.mul)(D,S.multiplier);F=(0,p.toFixed)(F,0,0),A.nativeAmount=F,A.currencyCode=C}return{edgeParsedUri:A,parsedUri:f}}function _(d,g,y){if(d.publicAddress==null)throw new Error("InvalidPublicAddressError");if(y==null&&d.label==null&&d.message==null)return d.publicAddress;{let C="";y!=null&&(C+="amount="+y+"&"),(d.label!=null||d.message!=null)&&(typeof d.label=="string"&&(C+="label="+d.label+"&"),typeof d.message=="string"&&(C+="message="+d.message+"&")),C=C.substr(0,C.length-1);const H={scheme:g,path:d.publicAddress,query:C};return(0,J.qC)(H)}}},12636:function(se,R,h){"use strict";h.r(R),h.d(R,{FilecoinTools:function(){return te},makeCurrencyEngine:function(){return Ie},makeCurrencyTools:function(){return Se}});var p=h(23145),E=h(77591),J=h(37786),I=h(2153),e=h(82448),G=h(35620),U=h(79014),B=h(76714),j=h(62177);const V=(0,e.su)({}),x=(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})}),L=(0,e.su)({address:e.XC,publicKey:e.XC}),Q=(0,j.jd)(L),_=l=>{const t=(0,e.su)({[`${l}Mnemonic`]:e.XC,[`${l}Key`]:e.XC});return(0,e.W1)(s=>{const i=t(s);return{mnemonic:i[`${l}Mnemonic`],privateKey:i[`${l}Key`]}},s=>({[`${l}Mnemonic`]:s.mnemonic,[`${l}Key`]:s.privateKey}))};var d=h(94935),g=h(84650),y=h(72681),C=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const H=(0,e.su)({statusCode:e.mH,message:e.XC,error:e.XC}),f=l=>(0,e.$e)((0,e._C)(H,l)),O=(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}),Z=(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}))}),A=(0,e.su)({from:e.XC,height:e.mH,message:e.XC,timestamp:e.mH,to:e.XC,type:e.XC,value:e.XC}),K=(0,e.su)({messages:(0,e._2)(O),totalCount:e.mH}),N=Z,W=(0,e.su)({transfers:(0,e._2)(A),totalCount:e.mH});class D{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountMessages(t,s,i=20){return C(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/messages`),o=new URLSearchParams({page:s.toString(),pageSize:i.toString()});n.search=o.toString();const c=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=f(K)(c);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getAccountTransfers(t,s,i=20){return C(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/transfers`),o=new URLSearchParams({page:s.toString(),pageSize:i.toString()});n.search=o.toString();const c=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=f(W)(c);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getMessageDetails(t){return C(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/message/${t}`,{method:"GET",headers:{"content-type":"application/json"}})).text(),n=f(N)(i);if("error"in n)throw new Error(`Error response code ${n.statusCode}: ${n.message} ${n.error}`);return n})}}var S=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const F=l=>(0,e.su)({result:l}),ne=(0,e.su)({code:e.mH,message:e.XC}),Y=l=>(0,e.$e)((0,e._C)(ne,F(l))),re=(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}),oe=(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})})}),ie=(0,e.su)({messages_by_account_id_list:(0,e.Vk)((0,e._2)(re),()=>[]),total_count:e.mH}),ae=(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 ce{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountInfo(t){return S(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=Y(oe)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}getAccountMessages(t,s,i=20){return S(this,null,function*(){const o=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(),a=Y(ie)(o);if(!("result"in a))throw new Error(`Error response code ${a.code}: ${a.message}`);return a.result})}getMessageDetails(t){return S(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=Y(ae)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}}var le=Math.pow,ue=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const de=l=>(0,e.su)({id:e.mH,jsonrpc:e.XC,result:l}),he=(0,e.su)({id:e.mH,jsonrpc:e.XC,error:(0,e.su)({code:e.mH,message:e.XC})}),fe=l=>(0,e.$e)((0,e._C)(he,de(l))),pe=(0,e.su)({Height:e.mH});class me{constructor(t,s){this.baseUrl=t,this.fetch=s}getChainHead(){return ue(this,null,function*(){const t=Math.floor(Math.random()*le(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=fe(pe)(i);if("error"in n)throw new Error(`Error response code ${n.error.code}: ${n.error.message}`);return n})}}var ge=Object.defineProperty,ye=Object.defineProperties,Ce=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,ve=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,Ee=Reflect.get,ee=(l,t,s)=>t in l?ge(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,Te=(l,t)=>{for(var s in t||(t={}))we.call(t,s)&&ee(l,s,t[s]);if(q)for(var s of q(t))Pe.call(t,s)&&ee(l,s,t[s]);return l},Ae=(l,t)=>ye(l,Ce(t)),M=(l,t,s)=>Ee(ve(l),s,t),v=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const ke=15e3,be=3e4,Xe=15e3;class b extends g.P{constructor(t,s,i,n){super(t,s,i,n),this.filfoxMessageToEdgeTransaction=a=>{const c=this.address.toString(),r=[],u=a.transfers.filter(P=>P.type==="miner-fee"||P.type==="burner-fee").reduce((P,T)=>(0,E.add)(P,T.value),"0");let m;return a.from===c?(m=`-${u}`,a.to!==c&&(m=(0,E.sub)(m,a.value))):(m=a.value,r.push(c)),{blockHeight:a.height,currencyCode:this.currencyInfo.currencyCode,date:a.timestamp,isSend:m.startsWith("-"),memos:[],nativeAmount:m,networkFee:u,otherParams:{},ourReceiveAddresses:r,signedTx:"",txid:a.cid,walletId:this.walletId}};const{networkInfo:o}=t;this.address=p.kL.fromString(i.keys.address),this.availableAttoFil="0",this.isScanning=!1,this.networkInfo=o,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 D(t.networkInfo.filfoxUrl,t.io.fetchCors),this.filscanApi=new ce(t.networkInfo.filscanUrl,t.io.fetchCors),this.rpcExtra=new me(t.networkInfo.rpcNode.url,t.io.fetchCors)}setOtherData(t){this.otherData=V(t)}initData(){this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=0,this.availableAttoFil="0"}initSubscriptions(){this.addToLoop("checkBalance",ke).catch(t=>this.log(t)),this.addToLoop("checkBlockHeight",be).catch(t=>this.log(t)),this.addToLoop("checkTransactions",Xe).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 v(this,null,function*(){this.initData(),this.initSubscriptions(),yield M(b.prototype,this,"startEngine").call(this)})}killEngine(){return v(this,null,function*(){yield M(b.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return v(this,null,function*(){yield M(b.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return v(this,null,function*(){yield M(b.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return v(this,null,function*(){const{address:t}=this.walletInfo.keys;return{publicAddress:t}})}getMaxSpendable(t){return v(this,null,function*(){var s;let i="0",n=(s=t.spendTargets[0].nativeAmount)!=null?s:"0",o=10;for(t.skipChecks=!0;o-- >0;){t.spendTargets[0].nativeAmount=n;const a=yield this.makeSpend(t);if(n=(0,E.sub)(this.availableAttoFil,a.networkFee),(0,E.lte)(n,"0"))throw new d.C_;if((0,E.gte)(i,a.networkFee))break;i=a.networkFee}return n})}makeSpend(t){return v(this,null,function*(){t=(0,y.s)(t,this.currencyInfo);const{edgeSpendInfo:s,currencyCode:i,skipChecks:n}=this.makeSpendCheck(t),{memos:o=[]}=s,a=s.spendTargets[0],{publicAddress:c,nativeAmount:r}=a;if(c==null)throw new Error("Missing publicAddress in EdgeSpendInfo");if(r==null)throw new d.$D;const u=p.kL.fromString(c),m=p.YW.getNew(u,this.address,p.WU.fromAtto(r),0);yield m.prepareToSend(this.filRpc);const w=m.toJSON(),P={sigJson:void 0,txJson:w},T=(0,E.mul)(w.GasLimit.toString(),w.GasFeeCap),X=(0,E.add)(r,T),$=(0,E.mul)(X,"-1"),z=this.availableAttoFil;if(!n&&(0,E.gt)(X,z))throw new d.C_;return{blockHeight:0,currencyCode:i,date:0,isSend:!0,memos:o,nativeAmount:$,networkFee:T,otherParams:P,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}})}signTx(t,s){return v(this,null,function*(){const i=x(t.otherParams),n=p.YW.fromJSON(i.txJson),o=_(this.pluginId)(s),a=p.w5.deriveAccount(o.mnemonic,p.BG.SECP256K1,this.tools.derivationPath),c=yield p.w5.signTransaction(a,n);return t.otherParams=Ae(Te({},t.otherParams),{sigJson:c.toJSON()}),t.date=Date.now()/1e3,t})}broadcastTx(t,s){return v(this,null,function*(){const i=x(t.otherParams);if(i.sigJson==null)throw new Error("Cannot broadcast unsigned transaction");const n=p.Pc.fromJSON(i.sigJson),o=p.YW.fromJSON(i.txJson),a=yield this.filRpc.broadcastTransaction(o,n);if("error"in a)throw new Error(a.error.message);return t.txid=a.result["/"],t})}getDisplayPrivateSeed(t){return _(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}loadEngine(){return v(this,null,function*(){yield M(b.prototype,this,"loadEngine").call(this),this.engineOn=!0})}checkBalance(){return v(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 v(this,null,function*(){const s=(yield this.rpcExtra.getChainHead()).result.Height;this.onUpdateBlockHeight(s)})}checkTransactions(){return v(this,null,function*(){if(!this.isScanning)try{this.isScanning=!0;const t=this.address.toString(),s=o=>{const a=this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode],c=o;a<1&&(c>=1||c>a*1.1)&&(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=c,this.updateOnAddressesChecked())},i=({tx:o,progress:a})=>{o!=null&&(this.addTransaction(this.currencyInfo.currencyCode,o),this.onUpdateTransactions(),this.walletLocalData.blockHeight<o.blockHeight&&this.onUpdateBlockHeight(o.blockHeight)),s(a)},n=[this.scanTransactionsFromFilfox(t,i)];yield Promise.all(n),this.walletLocalData.lastAddressQueryHeight=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,s(1)}catch(t){throw console.error(t),t}finally{this.isScanning=!1}})}scanTransactionsFromFilfox(t,s){return v(this,null,function*(){const i=new Set;let o=(yield this.filfoxApi.getAccountTransfers(t,0,1)).totalCount;const a=20;let c=Math.ceil(o/a),r=0;for(let u=c-1;u>=0;u--){const m=yield this.filfoxApi.getAccountTransfers(t,u,a);let w=m.transfers;if(m.totalCount!==o){const P=m.totalCount-o,X=(u+1)*(a/P),$=yield this.filfoxApi.getAccountTransfers(t,X,P);w=[...w,...$.transfers],o=m.totalCount,c=Math.ceil(o/a)}for(let P=w.length-1;P>=0;P--){if(!this.engineOn)return;const T=w[P];let X;if(T.height>=this.walletLocalData.lastAddressQueryHeight&&!i.has(T.message)){T.height>this.walletLocalData.lastAddressQueryHeight&&(this.walletLocalData.lastAddressQueryHeight=T.height,this.walletLocalDataDirty=!0);const z=yield this.filfoxApi.getMessageDetails(T.message);X=this.filfoxMessageToEdgeTransaction(z)}const $=o===0?1:++r/o;s({tx:X,progress:$}),i.add(T.message)}}})}scanTransactionsFromFilscan(t,s){return v(this,null,function*(){let n=0,o=0,a=-1;do{const c=yield this.filscanApi.getAccountMessages(t,n++,20);a=a===-1?c.total_count:a;const r=c.messages_by_account_id_list;for(const u of r){if(u.height<this.walletLocalData.lastAddressQueryHeight)return;const m=this.filscanMessageToEdgeTransaction(u),w=a===0?1:++o/a;s({tx:m,progress:w})}}while(o<a)})}filscanMessageToEdgeTransaction(t){const s=this.address.toString(),i=[],n="0";let o;return t.from===s?(o=`-${n}`,t.to!==s&&(o=(0,E.sub)(o,t.value))):(o=t.value,i.push(s)),{blockHeight:t.height,currencyCode:this.currencyInfo.currencyCode,date:t.block_time,isSend:o.startsWith("-"),memos:[],nativeAmount:o,networkFee:n,otherParams:{},ourReceiveAddresses:i,signedTx:"",txid:t.cid,walletId:this.walletId}}}function Ie(l,t,s,i){return v(this,null,function*(){const n=Q(s),o=new b(l,t,n,i);return yield o.loadEngine(),o})}var k=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});class te{constructor(t){const{builtinTokens:s,currencyInfo:i,io:n,networkInfo:o}=t;this.builtinTokens=s,this.currencyInfo=i,this.io=n,this.networkInfo=o,this.derivationPath=`m/44'/${this.networkInfo.hdPathCoinType}'/0'/0/0`}isValidAddress(t){return k(this,null,function*(){try{return p.kL.fromString(t),!0}catch{return!1}})}importPrivateKey(t){return k(this,arguments,function*(s,i={}){const{pluginId:n}=this.currencyInfo;if(!(0,I.validateMnemonic)(s))throw new Error("Invalid mnemonic");const o=(yield(0,I.mnemonicToSeed)(s)).toString("hex");return{[`${n}Key`]:o,[`${n}Mnemonic`]:s}})}createPrivateKey(t){return k(this,null,function*(){const{pluginId:s}=this.currencyInfo;if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const i=G.YU.stringify(this.io.random(32)),n=(0,I.entropyToMnemonic)(i);return{[`${s}Key`]:i,[`${s}Mnemonic`]:n}})}checkPublicKey(t){return k(this,null,function*(){return(0,e.Vk)(L)(t)!=null})}derivePublicKey(t){return k(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{pluginId:s}=this.currencyInfo,{hdPathCoinType:i}=this.networkInfo,n=_(s)(t.keys),o=yield(0,I.mnemonicToSeed)(n.mnemonic),u=(0,J.fromSeed)(o).deriveHardened(44).deriveHardened(i).deriveHardened(0).neutered().toBase58(),w=p.w5.deriveAccount(n.mnemonic,p.BG.SECP256K1,this.derivationPath,void 0,p.PY[this.networkInfo.networkPrefix]).address.toString();return{publicKey:u,address:w}})}parseUri(t,s,i){return k(this,null,function*(){const{pluginId:n}=this.currencyInfo,o={[n]:!0},{edgeParsedUri:a,edgeParsedUri:{publicAddress:c}}=(0,U.k)(this.currencyInfo,t,o,s!=null?s:this.currencyInfo.currencyCode,i);if(c==null||!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");return a})}encodeUri(t){return k(this,arguments,function*(s,i=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:o,currencyCode:a,publicAddress:c}=s;if(!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");let r;if(o!=null){const m=(0,B.Qs)(a!=null?a:this.currencyInfo.currencyCode,this.currencyInfo,i);if(m==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,E.div)(o,m.multiplier,18)}return(0,U.Q)(s,`${n}`,r)})}}function Se(l){return k(this,null,function*(){return new te(l)})}},69159:function(){},89214:function(){},52361:function(){},94616:function(){}}]);
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8518],{79014:function(ne,$,p){"use strict";p.d($,{Q:function(){return _},k:function(){return Q}});var h=p(77591),E=p.n(h),J=p(24350),k=p(84564),e=p.n(k),G=p(76714),R=Object.defineProperty,U=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,x=(d,g,y)=>g in d?R(d,g,{enumerable:!0,configurable:!0,writable:!0,value:y}):d[g]=y,L=(d,g)=>{for(var y in g||(g={}))j.call(g,y)&&x(d,y,g[y]);if(U)for(var y of U(g))V.call(g,y)&&x(d,y,g[y]);return d};function Q(d,g,y,C,H=[]){const m=L({},e()(g,{},!0)),O=g.startsWith(`${d.pluginId}://`);if(m.protocol!=null&&(m.protocol=m.protocol.replace(":","")),m.protocol!=null&&m.protocol!==""&&!y[m.protocol])throw new Error(`Uri protocol '${m.protocol}' is not supported for ${d.pluginId}.`);if(m.host===""&&m.pathname==="")throw new Error("Path and host not found in uri.");const A={publicAddress:m.host!==""?m.host:m.pathname.split("/")[0]},B=m.query.label,K=m.query.message,N=m.query.category;(B!=null||K!=null||N!=null||O)&&(A.metadata={},A.metadata.name=B,A.metadata.notes=K,A.metadata.category=N,A.metadata.gateway=O!=null?O:!1);const M=m.query.amount;if(M!=null&&typeof M=="string"){C==null&&(C=d.currencyCode);const I=(0,G.Qs)(C!=null?C:"",d,H);if(I==null)throw new Error("InternalErrorInvalidCurrencyCode");let D=(0,h.mul)(M,I.multiplier);D=(0,h.toFixed)(D,0,0),A.nativeAmount=D,A.currencyCode=C}return{edgeParsedUri:A,parsedUri:m}}function _(d,g,y){if(d.publicAddress==null)throw new Error("InvalidPublicAddressError");if(y==null&&d.label==null&&d.message==null)return d.publicAddress;{let C="";y!=null&&(C+="amount="+y+"&"),(d.label!=null||d.message!=null)&&(typeof d.label=="string"&&(C+="label="+d.label+"&"),typeof d.message=="string"&&(C+="message="+d.message+"&")),C=C.substr(0,C.length-1);const H={scheme:g,path:d.publicAddress,query:C};return(0,J.qC)(H)}}},12636:function(ne,$,p){"use strict";p.r($),p.d($,{FilecoinTools:function(){return te},makeCurrencyEngine:function(){return Xe},makeCurrencyTools:function(){return xe}});var h=p(23145),E=p(77591),J=p(37786),k=p(2153),e=p(82448),G=p(35620),R=p(79014),U=p(76714),j=p(62177);const V=(0,e.su)({}),x=(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})}),L=(0,e.su)({address:e.XC,publicKey:e.XC}),Q=(0,j.jd)(L),_=l=>{const t=(0,e.su)({[`${l}Mnemonic`]:e.XC,[`${l}Key`]:e.XC});return(0,e.W1)(s=>{const i=t(s);return{mnemonic:i[`${l}Mnemonic`],privateKey:i[`${l}Key`]}},s=>({[`${l}Mnemonic`]:s.mnemonic,[`${l}Key`]:s.privateKey}))};var d=p(94935),g=p(84650),y=p(72681),C=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const H=(0,e.su)({statusCode:e.mH,message:e.XC,error:e.XC}),m=l=>(0,e.$e)((0,e._C)(H,l)),O=(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}),Z=(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}))}),A=(0,e.su)({from:e.XC,height:e.mH,message:e.XC,timestamp:e.mH,to:e.XC,type:e.XC,value:e.XC}),B=(0,e.su)({messages:(0,e._2)(O),totalCount:e.mH}),K=Z,N=(0,e.su)({transfers:(0,e._2)(A),totalCount:e.mH});class M{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountMessages(t,s,i=20){return C(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/messages`),o=new URLSearchParams({page:s.toString(),pageSize:i.toString()});n.search=o.toString();const c=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=m(B)(c);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getAccountTransfers(t,s,i=20){return C(this,null,function*(){const n=new URL(`${this.baseUrl}/address/${t}/transfers`),o=new URLSearchParams({page:s.toString(),pageSize:i.toString()});n.search=o.toString();const c=yield(yield this.fetch(n.toString(),{method:"GET",headers:{"content-type":"application/json"}})).text(),r=m(N)(c);if("error"in r)throw new Error(`Error response code ${r.statusCode}: ${r.message} ${r.error}`);return r})}getMessageDetails(t){return C(this,null,function*(){const i=yield(yield this.fetch(`${this.baseUrl}/message/${t}`,{method:"GET",headers:{"content-type":"application/json"}})).text(),n=m(K)(i);if("error"in n)throw new Error(`Error response code ${n.statusCode}: ${n.message} ${n.error}`);return n})}}var I=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const D=l=>(0,e.su)({result:l}),re=(0,e.su)({code:e.mH,message:e.XC}),Y=l=>(0,e.$e)((0,e._C)(re,D(l))),oe=(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}),ie=(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})})}),ae=(0,e.su)({messages_by_account_id_list:(0,e.Vk)((0,e._2)(oe),()=>[]),total_count:e.mH}),ce=(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 le{constructor(t,s){this.baseUrl=t,this.fetch=s}getAccountInfo(t){return I(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=Y(ie)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}getAccountMessages(t,s,i=20){return I(this,null,function*(){const o=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(),a=Y(ae)(o);if(!("result"in a))throw new Error(`Error response code ${a.code}: ${a.message}`);return a.result})}getMessageDetails(t){return I(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=Y(ce)(i);if(!("result"in n))throw new Error(`Error response code ${n.code}: ${n.message}`);return n.result})}}var ue=Math.pow,de=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const he=l=>(0,e.su)({id:e.mH,jsonrpc:e.XC,result:l}),fe=(0,e.su)({id:e.mH,jsonrpc:e.XC,error:(0,e.su)({code:e.mH,message:e.XC})}),pe=l=>(0,e.$e)((0,e._C)(fe,he(l))),me=(0,e.su)({Height:e.mH});class ge{constructor(t,s){this.baseUrl=t,this.fetch=s}getChainHead(){return de(this,null,function*(){const t=Math.floor(Math.random()*ue(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=pe(me)(i);if("error"in n)throw new Error(`Error response code ${n.error.code}: ${n.error.message}`);return n})}}var ye=Object.defineProperty,Ce=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,we=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable,Te=Reflect.get,ee=(l,t,s)=>t in l?ye(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,Ae=(l,t)=>{for(var s in t||(t={}))Pe.call(t,s)&&ee(l,s,t[s]);if(q)for(var s of q(t))Ee.call(t,s)&&ee(l,s,t[s]);return l},be=(l,t)=>Ce(l,ve(t)),W=(l,t,s)=>Te(we(l),s,t),v=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});const Se=15e3,ke=3e4,Ie=15e3;class X extends g.P{constructor(t,s,i,n){super(t,s,i,n),this.filfoxMessageToEdgeTransaction=a=>{const c=this.address.toString(),r=[],u=a.transfers.filter(P=>P.type==="miner-fee"||P.type==="burner-fee").reduce((P,T)=>(0,E.add)(P,T.value),"0");let f;return a.from===c?(f=`-${u}`,a.to!==c&&(f=(0,E.sub)(f,a.value))):(f=a.value,r.push(c)),{blockHeight:a.height,currencyCode:this.currencyInfo.currencyCode,date:a.timestamp,isSend:f.startsWith("-"),memos:[],nativeAmount:f,networkFee:u,otherParams:{},ourReceiveAddresses:r,signedTx:"",txid:a.cid,walletId:this.walletId}};const{networkInfo:o}=t;this.address=h.kL.fromString(i.keys.address),this.availableAttoFil="0",this.isScanning=!1,this.networkInfo=o,this.pluginId=this.currencyInfo.pluginId,this.filRpc=new h.rP(h.Zc[t.networkInfo.rpcNode.networkName],{url:t.networkInfo.rpcNode.url,token:t.currencyInfo.currencyCode}),this.filfoxApi=new M(t.networkInfo.filfoxUrl,t.io.fetchCors),this.filscanApi=new le(t.networkInfo.filscanUrl,t.io.fetchCors),this.rpcExtra=new ge(t.networkInfo.rpcNode.url,t.io.fetchCors)}setOtherData(t){this.otherData=V(t)}initData(){this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=0,this.availableAttoFil="0"}initSubscriptions(){this.addToLoop("checkBalance",Se).catch(t=>this.log(t)),this.addToLoop("checkBlockHeight",ke).catch(t=>this.log(t)),this.addToLoop("checkTransactions",Ie).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 v(this,null,function*(){this.engineOn=!0,this.initData(),this.initSubscriptions(),yield W(X.prototype,this,"startEngine").call(this)})}killEngine(){return v(this,null,function*(){yield W(X.prototype,this,"killEngine").call(this),yield new Promise(t=>{const s=setInterval(()=>{this.isScanning||(clearInterval(s),t())},300)})})}clearBlockchainCache(){return v(this,null,function*(){yield W(X.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return v(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return v(this,null,function*(){const{address:t}=this.walletInfo.keys;return{publicAddress:t}})}getMaxSpendable(t){return v(this,null,function*(){var s;const i=t.spendTargets[0].publicAddress;if(i==null)throw new Error("Missing publicAddress");t.skipChecks=!0;const n=t.spendTargets[0];if(n==null)throw new Error("missing spendTargets");n.nativeAmount=(s=n.nativeAmount)!=null?s:"0";const o=yield this.makeSpend(t),a=(0,E.sub)(this.availableAttoFil,o.networkFee),c=h.YW.getNew(h.kL.fromString(i),this.address,h.WU.fromAtto(a),0);yield c.prepareToSend(this.filRpc);const{GasLimit:r,GasPremium:u,GasFeeCap:f}=c.toJSON(),w=(0,E.mul)(r.toString(),f),P=(0,E.sub)(this.availableAttoFil,w);return this.lastMaxSpendable={nativeAmount:P,params:{GasLimit:r,GasPremium:u,GasFeeCap:f}},P})}makeSpend(t){return v(this,null,function*(){t=(0,y.s)(t,this.currencyInfo);const{edgeSpendInfo:s,currencyCode:i,skipChecks:n}=this.makeSpendCheck(t),{memos:o=[]}=s,a=s.spendTargets[0];if(a==null)throw new Error("missing spendTargets");const{publicAddress:c,nativeAmount:r}=a;if(c==null)throw new Error("Missing publicAddress in EdgeSpendInfo");if(r==null)throw new d.$D;const u=h.kL.fromString(c),f=h.YW.getNew(u,this.address,h.WU.fromAtto(r),0);yield f.prepareToSend(this.filRpc);const w=f.toJSON();if(this.lastMaxSpendable!=null){const{nativeAmount:se,params:_e}=this.lastMaxSpendable;(0,E.eq)(se,se)&&(Object.assign(w,_e),delete this.lastMaxSpendable)}const P={sigJson:void 0,txJson:w},T=(0,E.mul)(w.GasLimit.toString(),w.GasFeeCap),S=(0,E.add)(r,T),F=(0,E.mul)(S,"-1"),z=this.availableAttoFil;if(!n&&(0,E.gt)(S,z))throw new d.C_;return{blockHeight:0,currencyCode:i,date:0,isSend:!0,memos:o,nativeAmount:F,networkFee:T,otherParams:P,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}})}signTx(t,s){return v(this,null,function*(){const i=x(t.otherParams),n=h.YW.fromJSON(i.txJson),o=_(this.pluginId)(s),a=h.w5.deriveAccount(o.mnemonic,h.BG.SECP256K1,this.tools.derivationPath),c=yield h.w5.signTransaction(a,n);return t.otherParams=be(Ae({},t.otherParams),{sigJson:c.toJSON()}),t.date=Date.now()/1e3,t})}broadcastTx(t,s){return v(this,null,function*(){const i=x(t.otherParams);if(i.sigJson==null)throw new Error("Cannot broadcast unsigned transaction");const n=h.Pc.fromJSON(i.sigJson),o=h.YW.fromJSON(i.txJson),a=yield this.filRpc.broadcastTransaction(o,n);if("error"in a)throw new Error(a.error.message);return t.txid=a.result["/"],t})}getDisplayPrivateSeed(t){return _(this.pluginId)(t).mnemonic}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}loadEngine(){return v(this,null,function*(){yield W(X.prototype,this,"loadEngine").call(this),this.engineOn=!0})}checkBalance(){return v(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 v(this,null,function*(){const s=(yield this.rpcExtra.getChainHead()).result.Height;this.onUpdateBlockHeight(s)})}checkTransactions(){return v(this,null,function*(){if(!this.isScanning)try{this.isScanning=!0;const t=this.address.toString(),s=o=>{const a=this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode],c=o;a<1&&(c>=1||c>a*1.1)&&(this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=c,this.updateOnAddressesChecked())},i=({tx:o,progress:a})=>{o!=null&&(this.addTransaction(this.currencyInfo.currencyCode,o),this.onUpdateTransactions(),this.walletLocalData.blockHeight<o.blockHeight&&this.onUpdateBlockHeight(o.blockHeight)),s(a)},n=[this.scanTransactionsFromFilfox(t,i)];yield Promise.all(n),this.walletLocalData.lastAddressQueryHeight=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,s(1)}catch(t){throw console.error(t),t}finally{this.isScanning=!1}})}scanTransactionsFromFilfox(t,s){return v(this,null,function*(){const i=new Set;let o=(yield this.filfoxApi.getAccountTransfers(t,0,1)).totalCount;const a=20;let c=Math.ceil(o/a),r=0;for(let u=c-1;u>=0;u--){const f=yield this.filfoxApi.getAccountTransfers(t,u,a);let w=f.transfers;if(f.totalCount!==o){const P=f.totalCount-o,S=(u+1)*(a/P),F=yield this.filfoxApi.getAccountTransfers(t,S,P);w=[...w,...F.transfers],o=f.totalCount,c=Math.ceil(o/a)}for(let P=w.length-1;P>=0;P--){if(!this.engineOn)return;const T=w[P];let S;if(T.height>=this.walletLocalData.lastAddressQueryHeight&&!i.has(T.message)){T.height>this.walletLocalData.lastAddressQueryHeight&&(this.walletLocalData.lastAddressQueryHeight=T.height,this.walletLocalDataDirty=!0);const z=yield this.filfoxApi.getMessageDetails(T.message);S=this.filfoxMessageToEdgeTransaction(z)}const F=o===0?1:++r/o;s({tx:S,progress:F}),i.add(T.message)}}})}scanTransactionsFromFilscan(t,s){return v(this,null,function*(){let n=0,o=0,a=-1;do{const c=yield this.filscanApi.getAccountMessages(t,n++,20);a=a===-1?c.total_count:a;const r=c.messages_by_account_id_list;for(const u of r){if(u.height<this.walletLocalData.lastAddressQueryHeight)return;const f=this.filscanMessageToEdgeTransaction(u),w=a===0?1:++o/a;s({tx:f,progress:w})}}while(o<a)})}filscanMessageToEdgeTransaction(t){const s=this.address.toString(),i=[],n="0";let o;return t.from===s?(o=`-${n}`,t.to!==s&&(o=(0,E.sub)(o,t.value))):(o=t.value,i.push(s)),{blockHeight:t.height,currencyCode:this.currencyInfo.currencyCode,date:t.block_time,isSend:o.startsWith("-"),memos:[],nativeAmount:o,networkFee:n,otherParams:{},ourReceiveAddresses:i,signedTx:"",txid:t.cid,walletId:this.walletId}}}function Xe(l,t,s,i){return v(this,null,function*(){const n=Q(s),o=new X(l,t,n,i);return yield o.loadEngine(),o})}var b=(l,t,s)=>new Promise((i,n)=>{var o=r=>{try{c(s.next(r))}catch(u){n(u)}},a=r=>{try{c(s.throw(r))}catch(u){n(u)}},c=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,a);c((s=s.apply(l,t)).next())});class te{constructor(t){const{builtinTokens:s,currencyInfo:i,io:n,networkInfo:o}=t;this.builtinTokens=s,this.currencyInfo=i,this.io=n,this.networkInfo=o,this.derivationPath=`m/44'/${this.networkInfo.hdPathCoinType}'/0'/0/0`}isValidAddress(t){return b(this,null,function*(){try{return h.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 o=(yield(0,k.mnemonicToSeed)(s)).toString("hex");return{[`${n}Key`]:o,[`${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=G.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)(L)(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=_(s)(t.keys),o=yield(0,k.mnemonicToSeed)(n.mnemonic),u=(0,J.fromSeed)(o).deriveHardened(44).deriveHardened(i).deriveHardened(0).neutered().toBase58(),w=h.w5.deriveAccount(n.mnemonic,h.BG.SECP256K1,this.derivationPath,void 0,h.PY[this.networkInfo.networkPrefix]).address.toString();return{publicKey:u,address:w}})}parseUri(t,s,i){return b(this,null,function*(){const{pluginId:n}=this.currencyInfo,o={[n]:!0},{edgeParsedUri:a,edgeParsedUri:{publicAddress:c}}=(0,R.k)(this.currencyInfo,t,o,s!=null?s:this.currencyInfo.currencyCode,i);if(c==null||!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");return a})}encodeUri(t){return b(this,arguments,function*(s,i=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:o,currencyCode:a,publicAddress:c}=s;if(!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");let r;if(o!=null){const f=(0,U.Qs)(a!=null?a:this.currencyInfo.currencyCode,this.currencyInfo,i);if(f==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,E.div)(o,f.multiplier,18)}return(0,R.Q)(s,`${n}`,r)})}}function xe(l){return b(this,null,function*(){return new te(l)})}},69159:function(){},89214:function(){},52361:function(){},94616:function(){}}]);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EdgeCorePluginOptions,
|
|
3
|
+
EdgeCurrencyPlugin,
|
|
4
|
+
EdgeOtherMethods
|
|
5
|
+
} from 'edge-core-js/types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add this to your `nativeIo` object on React Native,
|
|
9
|
+
* as `{ 'edge-currency-accountbased': makePluginIo() }`
|
|
10
|
+
*/
|
|
11
|
+
export function makePluginIo(): EdgeOtherMethods
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Debugging-URI to use on React Native,
|
|
15
|
+
* along with running `yarn start` in this repo.
|
|
16
|
+
*/
|
|
17
|
+
export const debugUri: string
|
|
18
|
+
|
|
19
|
+
/* Regular URI to use on React Native. */
|
|
20
|
+
export const pluginUri: string
|
|
21
|
+
|
|
22
|
+
type EdgeCorePluginFactory = (env: EdgeCorePluginOptions) => EdgeCurrencyPlugin
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The Node.js default export.
|
|
26
|
+
*/
|
|
27
|
+
declare const plugins: {
|
|
28
|
+
[pluginId: string]: EdgeCorePluginFactory
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default plugins
|
package/lib/declare-modules.d.js
CHANGED
|
@@ -61,6 +61,16 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
// Engine State:
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
64
74
|
constructor(
|
|
65
75
|
env,
|
|
66
76
|
tools,
|
|
@@ -126,6 +136,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
async startEngine() {
|
|
139
|
+
this.engineOn = true
|
|
129
140
|
this.initData()
|
|
130
141
|
this.initSubscriptions()
|
|
131
142
|
await super.startEngine()
|
|
@@ -133,6 +144,16 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
133
144
|
|
|
134
145
|
async killEngine() {
|
|
135
146
|
await super.killEngine()
|
|
147
|
+
|
|
148
|
+
// Wait for any transaction scanning to finish before killing engine
|
|
149
|
+
await new Promise(resolve => {
|
|
150
|
+
const id = setInterval(() => {
|
|
151
|
+
if (!this.isScanning) {
|
|
152
|
+
clearInterval(id)
|
|
153
|
+
resolve()
|
|
154
|
+
}
|
|
155
|
+
}, 300)
|
|
156
|
+
})
|
|
136
157
|
}
|
|
137
158
|
|
|
138
159
|
async clearBlockchainCache() {
|
|
@@ -140,7 +161,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
async resyncBlockchain() {
|
|
143
|
-
await
|
|
164
|
+
await this.killEngine()
|
|
144
165
|
await this.clearBlockchainCache()
|
|
145
166
|
await this.startEngine()
|
|
146
167
|
}
|
|
@@ -153,29 +174,43 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
153
174
|
}
|
|
154
175
|
|
|
155
176
|
async getMaxSpendable(spendInfo) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
177
|
+
const publicAddress = spendInfo.spendTargets[0].publicAddress
|
|
178
|
+
|
|
179
|
+
if (publicAddress == null) throw new Error('Missing publicAddress')
|
|
159
180
|
|
|
160
181
|
// Enable skip checks because we don't want insufficient funds errors
|
|
161
182
|
spendInfo.skipChecks = true
|
|
183
|
+
const spendTarget = spendInfo.spendTargets[0]
|
|
184
|
+
if (spendTarget == null) throw new Error('missing spendTargets')
|
|
185
|
+
spendTarget.nativeAmount = _nullishCoalesce(spendTarget.nativeAmount, () => ( '0'))
|
|
162
186
|
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
while (maxTries-- > 0) {
|
|
167
|
-
spendInfo.spendTargets[0].nativeAmount = spendableBalance
|
|
168
|
-
const tx = await this.makeSpend(spendInfo)
|
|
187
|
+
// Probe for an amount to use in our transaction:
|
|
188
|
+
const txForAmount = await this.makeSpend(spendInfo)
|
|
189
|
+
const probeAmount = _biggystring.sub.call(void 0, this.availableAttoFil, txForAmount.networkFee)
|
|
169
190
|
|
|
170
|
-
|
|
171
|
-
|
|
191
|
+
// Probe for fee params:
|
|
192
|
+
const transaction = _izarifilecoin.Transaction.getNew(
|
|
193
|
+
_izarifilecoin.Address.fromString(publicAddress),
|
|
194
|
+
this.address,
|
|
195
|
+
_izarifilecoin.Token.fromAtto(probeAmount),
|
|
196
|
+
0
|
|
197
|
+
)
|
|
198
|
+
await transaction.prepareToSend(this.filRpc)
|
|
199
|
+
const { GasLimit, GasPremium, GasFeeCap } = transaction.toJSON()
|
|
172
200
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
201
|
+
// Calculate actual values:
|
|
202
|
+
const networkFee = _biggystring.mul.call(void 0, GasLimit.toString(), GasFeeCap)
|
|
203
|
+
const nativeAmount = _biggystring.sub.call(void 0, this.availableAttoFil, networkFee)
|
|
204
|
+
this.lastMaxSpendable = {
|
|
205
|
+
nativeAmount,
|
|
206
|
+
params: {
|
|
207
|
+
GasLimit,
|
|
208
|
+
GasPremium,
|
|
209
|
+
GasFeeCap
|
|
210
|
+
}
|
|
176
211
|
}
|
|
177
212
|
|
|
178
|
-
return
|
|
213
|
+
return nativeAmount
|
|
179
214
|
}
|
|
180
215
|
|
|
181
216
|
async makeSpend(edgeSpendInfoIn) {
|
|
@@ -184,6 +219,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
184
219
|
this.makeSpendCheck(edgeSpendInfoIn)
|
|
185
220
|
const { memos = [] } = edgeSpendInfo
|
|
186
221
|
const spendTarget = edgeSpendInfo.spendTargets[0]
|
|
222
|
+
if (spendTarget == null) throw new Error('missing spendTargets')
|
|
187
223
|
const { publicAddress, nativeAmount } = spendTarget
|
|
188
224
|
|
|
189
225
|
if (publicAddress == null)
|
|
@@ -204,6 +240,15 @@ const CHECK_TRANSACTION_INTERVAL = 15000
|
|
|
204
240
|
|
|
205
241
|
const txJson = transaction.toJSON()
|
|
206
242
|
|
|
243
|
+
// Override fee parameters if this is a max-spend:
|
|
244
|
+
if (this.lastMaxSpendable != null) {
|
|
245
|
+
const { nativeAmount, params } = this.lastMaxSpendable
|
|
246
|
+
if (_biggystring.eq.call(void 0, nativeAmount, nativeAmount)) {
|
|
247
|
+
Object.assign(txJson, params)
|
|
248
|
+
delete this.lastMaxSpendable
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
207
252
|
const otherParams = {
|
|
208
253
|
sigJson: undefined,
|
|
209
254
|
txJson
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('regenerator-runtime/runtime');
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
|
|
3
5
|
var _algorandInfo = require('./algorand/algorandInfo');
|
|
4
6
|
var _binanceInfo = require('./binance/binanceInfo');
|
|
5
7
|
var _eosInfos = require('./eos/eosInfos');
|
|
@@ -40,6 +42,12 @@ const plugins = {
|
|
|
40
42
|
zcash: _zcashInfo.zcash
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
43
51
|
if (
|
|
44
52
|
typeof window !== 'undefined' &&
|
|
45
53
|
typeof window.addEdgeCorePlugins === 'function'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-accountbased",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Edge currency plugin for account based currencies",
|
|
5
5
|
"homepage": "https://edge.app/",
|
|
6
6
|
"repository": {
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
],
|
|
21
21
|
"main": "./lib/index.js",
|
|
22
22
|
"react-native": "./lib/react-native.js",
|
|
23
|
-
"types": "./
|
|
23
|
+
"types": "./edge-currency-accountbased.d.ts",
|
|
24
24
|
"files": [
|
|
25
25
|
"/android/build.gradle",
|
|
26
26
|
"/android/src/",
|
|
27
27
|
"/CHANGELOG.md",
|
|
28
|
+
"/edge-currency-accountbased.d.ts",
|
|
28
29
|
"/edge-currency-accountbased.podspec",
|
|
29
30
|
"/ios/",
|
|
30
31
|
"/lib/",
|