edge-currency-accountbased 1.2.0 → 1.2.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 +10 -0
- package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
- package/android/src/main/assets/piratesaplingtree/mainnet/2370000.json +7 -0
- package/android/src/main/assets/saplingtree/mainnet/2070000.json +7 -0
- package/lib/algorand/AlgorandEngine.js +4 -2
- package/lib/ethereum/ethEngine.js +6 -4
- package/lib/fio/fioInfo.js +3 -3
- package/lib/zcash/zecEngine.js +10 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# edge-currency-accountbased
|
|
2
2
|
|
|
3
|
+
## 1.2.2 (2023-05-01)
|
|
4
|
+
|
|
5
|
+
- FIO: Update node list
|
|
6
|
+
|
|
7
|
+
## 1.2.1 (2023-05-01)
|
|
8
|
+
|
|
9
|
+
- ZEC/ARRR: Prevent sending overlapping queries to synchronizer
|
|
10
|
+
- Fix accessing already deleted wallet connector
|
|
11
|
+
- ZEC/ARRR: Update checkpoints
|
|
12
|
+
|
|
3
13
|
## 1.2.0 (2023-04-24)
|
|
4
14
|
|
|
5
15
|
- Add WalletConnect v1 support to Algorand
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[741],{37011:function(de,_,m){"use strict";m.r(_),m.d(_,{AlgorandTools:function(){return ie},makeCurrencyEngine:function(){return Ae},makeCurrencyTools:function(){return be}});var v=m(88814),w=m(77591),Z=m(20918),X=m(79014),S=m(76714),t=m(82448),F=m(62177);const j=(0,t.su)({latestRound:(0,t.Vk)(t.mH,0),latestTxid:(0,t.Vk)(t.XC,"")}),z=(0,t.su)({amount:t.mH,assets:(0,t._2)((0,t.su)({amount:t.mH,"asset-id":t.mH})),"min-balance":t.mH,round:t.mH}),Q=(0,t.su)({"confirmed-round":t.mH,fee:t.mH,"first-valid":t.mH,id:t.XC,note:(0,t.Zz)(t.XC),"round-time":t.mH,sender:t.XC,"tx-type":t.XC}).withRest,K=(0,t.Wf)("pay"),V=(0,t.su)({"payment-transaction":(0,t.su)({amount:t.mH,"close-amount":t.mH,receiver:t.XC}),"tx-type":K}),G=(0,t.Wf)("axfer"),J=(0,t.su)({"asset-transfer-transaction":(0,t.su)({amount:t.mH,"asset-id":t.mH}),"tx-type":G}),f=(0,t.su)({"current-round":t.mH,"next-token":(0,t.Zz)(t.XC),transactions:(0,t._2)(Q)}),T=(0,t.su)({flatFee:t.jK,fee:t.mH,firstRound:t.mH,lastRound:t.mH,genesisID:t.XC,genesisHash:t.XC}),I=(0,t.su)({type:t.XC}).withRest,x=(0,t.su)({encodedTx:t.XC,recipient:(0,t.Zz)(t.XC)}),q=(0,t.su)({type:K,to:t.XC,amount:t.mH}).withRest,p=(0,t.Vk)((0,t.su)({fee:(0,t.Zz)(t.XC)}),{fee:void 0}),H=(0,t.Vk)((0,t.su)({contractAddress:F.jD})),ne=F.BQ,E=y=>{const e=(0,t.su)({[`${y}Mnemonic`]:t.XC});return(0,t.W1)(n=>({mnemonic:e(n)[`${y}Mnemonic`]}),n=>({[`${y}Mnemonic`]:n.mnemonic}))},Y=(0,t.su)({id:(0,t._C)(t.XC,t.mH),method:(0,t.Wf)("algo_signTxn"),params:(0,t.vq)((0,t.vq)((0,t.su)({txn:t.XC,message:(0,t.Zz)(t.XC)})))}),N=(0,t.su)({id:t.mH,jsonrpc:(0,t.Wf)("2.0"),method:(0,t.Wf)("algo_signTxn"),params:(0,t.vq)((0,t.vq)((0,t.su)({txn:t.XC,message:(0,t.Zz)(t.XC)})))}).withRest;var $=m(12614),R=m(94935),D=m(35620),W=m(50244),he=m(48764).Buffer,fe=Object.defineProperty,ye=Object.defineProperties,me=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertySymbols,pe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,Te=Reflect.get,re=(y,e,n)=>e in y?fe(y,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):y[e]=n,L=(y,e)=>{for(var n in e||(e={}))ge.call(e,n)&&re(y,n,e[n]);if(se)for(var n of se(e))we.call(e,n)&&re(y,n,e[n]);return y},Ie=(y,e)=>ye(y,me(e)),ve=(y,e,n)=>Te(pe(y),n,e),h=(y,e,n)=>new Promise((o,l)=>{var s=a=>{try{i(n.next(a))}catch(c){l(c)}},r=a=>{try{i(n.throw(a))}catch(c){l(c)}},i=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,r);i((n=n.apply(y,e)).next())});const{Algodv2:ee,Indexer:ke}=v.ZP,oe=5e3,Ce=3e3;class te extends W.P{constructor(e,n,o,l){super(e,n,o,l),this.getRecipientBalance=s=>h(this,null,function*(){try{return(yield this.fetchAccountInfo(s)).amount.toString()}catch{return this.minimumAddressBalance}}),this.engineGetActivationAssets=s=>h(this,null,function*(){return{assetOptions:[{paymentWalletId:this.walletId,currencyPluginId:this.currencyInfo.pluginId}]}}),this.engineActivateWallet=s=>h(this,[s],function*({activateTokenIds:r,paymentTokenId:i,paymentWallet:a}){var c;if(r==null)throw new Error(`Must specify activateTokenIds for ${this.currencyInfo.currencyCode}`);if(i!=null)throw new Error(`Must activate with ${this.currencyInfo.currencyCode}`);if((a==null?void 0:a.id)!==this.walletId)throw new Error("Must pay with same wallet you are activating token with");const d=this.networkInfo.minimumTxFee.toFixed();let u="0";const g=[];for(const k of r){if(this.allTokensMap[k]==null)throw new Error(`Invalid tokenId to activate ${k}`);const b={currencyCode:this.allTokensMap[k].currencyCode,skipChecks:!0,spendTargets:[{publicAddress:this.walletInfo.keys.publicKey,nativeAmount:"0"}]};try{const C=yield this.makeSpend(b);u=(0,w.add)(u,(c=C.parentNetworkFee)!=null?c:d)}catch{u=(0,w.add)(u,d)}g.push(b)}return{paymentWalletId:this.walletId,fromNativeAmount:"0",networkFee:{nativeAmount:u,currencyPluginId:this.currencyInfo.pluginId},approve:(...k)=>h(this,[...k],function*(b={}){const{metadata:C}=b,A=[];for(const U of g){const M=yield this.makeSpend(U);M.metadata=L({},C);let O=yield a.signTx(M);O=yield a.broadcastTx(O),A.push(O),yield a.saveTx(O)}return{transactions:A}}),close:()=>h(this,null,function*(){})}}),this.networkInfo=e.networkInfo,this.queryTxMutex=(0,S.jT)(),this.suggestedTransactionParams={flatFee:!1,fee:0,firstRound:0,lastRound:0,genesisID:this.networkInfo.genesisID,genesisHash:this.networkInfo.genesisHash},this.minimumAddressBalance=this.networkInfo.minimumAddressBalance,this.totalReserve=this.minimumAddressBalance,this.otherMethods={wcInit:(s,r="Edge")=>h(this,null,function*(){return yield(0,S.Vs)(new Promise((i,a)=>{const c=new $.Z({uri:s.uri,storageId:s.uri,clientMeta:{description:"Edge Wallet",url:"https://www.edge.app",icons:["https://content.edge.app/Edge_logo_Icon.png"],name:r}});c.on("session_request",(d,u)=>{if(d!=null)throw this.error("Wallet connect session_request",d),d;const g=(0,F.ff)(u).params[0],P=Ie(L({},g),{timeConnected:Date.now()/1e3});this.tools.walletConnectors[s.uri]={connector:c,wcProps:s,dApp:P},i(P)}),c.on("call_request",(d,u)=>{try{if(d!=null)throw d;const g=N(u),P=g.params[0][0],k=(0,v.wj)(D.US.parse(P.txn)),b=k.amount!=null?k.amount.toString():"0",C=k.fee.toFixed();let A;if(k.type==="axfer"){const M=k.assetIndex.toString();if(this.allTokensMap[M]==null)throw new Error("Unrecognized token");A=M}const U={uri:s.uri,dApp:this.tools.walletConnectors[s.uri].dApp,payload:g,walletId:this.tools.walletConnectors[s.uri].walletId,nativeAmount:b,networkFee:C,tokenId:A};this.currencyEngineCallbacks.onWcNewContractCall(U)}catch(g){throw this.warn("Wallet connect call_request ",g),g}}),c.on("disconnect",(d,u)=>{if(d!=null)throw d;delete this.tools.walletConnectors[s.uri]})}),5e3)}),wcConnect:(s,r,i)=>{this.tools.walletConnectors[s].connector.approveSession({accounts:[r],chainId:416001}),this.tools.walletConnectors[s].walletId=i},wcDisconnect:s=>{this.tools.walletConnectors[s].connector.killSession().catch(()=>{}),delete this.tools.walletConnectors[s]},wcApproveRequest:(s,r,i)=>h(this,null,function*(){this.tools.walletConnectors[s].connector.approveRequest({id:Number(r.id),jsonrpc:"2.0",result:[i]})}),wcRejectRequest:(s,r)=>h(this,null,function*(){this.tools.walletConnectors[s].connector.rejectRequest({id:Number(r.id),jsonrpc:"2.0",error:{message:"rejected"}})}),wcGetConnections:()=>Object.keys(this.tools.walletConnectors).filter(s=>this.tools.walletConnectors[s].walletId===this.walletInfo.id).map(s=>L(L({},this.tools.walletConnectors[s].dApp),this.tools.walletConnectors[s].wcProps))}}setOtherData(e){this.otherData=j(e)}fetchAccountInfo(e){return h(this,null,function*(){return yield(0,S.QJ)(this.networkInfo.algodServers.map(n=>()=>h(this,null,function*(){const l=yield new ee("",n,"").accountInformation(e).do();return z(l)})))})}queryBalance(){return h(this,null,function*(){try{const e=yield this.fetchAccountInfo(this.walletLocalData.publicKey),{assets:n,amount:o,"min-balance":l,round:s}=e;this.totalReserve=l.toString();const r=[];for(const i of this.enabledTokens)if(i===this.currencyInfo.currencyCode)this.updateBalance(this.currencyInfo.currencyCode,o.toString());else{const a=Object.keys(this.allTokensMap).find(d=>this.allTokensMap[d].currencyCode===i);if(a==null){this.updateBalance(i,"0");continue}const c=n.find(d=>d["asset-id"].toFixed()===a);if(c==null){r.push(a),this.updateBalance(i,"0");continue}this.updateBalance(i,c.amount.toString())}s>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=s,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),(0,S.dQ)(r,this.walletLocalData.unactivatedTokenIds)||(this.walletLocalData.unactivatedTokenIds=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds))}catch(e){this.log.warn("queryBalance Error ",e)}})}queryTransactionParams(){return h(this,null,function*(){try{const e=yield(0,S.QJ)(this.networkInfo.algodServers.map(n=>()=>h(this,null,function*(){const l=yield new ee("",n,"").getTransactionParams().do(),s=T(l);if(s.genesisHash!==this.networkInfo.genesisHash)throw new Error("Server genesisHash mismatch");return s})));this.suggestedTransactionParams=e}catch(e){this.log.warn("queryTransactionParams error:",e)}})}processAlgorandTransaction(e){const{fee:n,"confirmed-round":o,id:l,"round-time":s,sender:r,"tx-type":i}=e;let a,c,d,u,g=!1;const P=[];switch(i){case"pay":{const{amount:b}=V(e)["payment-transaction"];c=b.toString(),d=n.toString(),r===this.walletInfo.keys.publicKey?(c=`-${(0,w.add)(c,d)}`,g=!0):(d="0",P.push(this.walletInfo.keys.publicKey)),a=this.currencyInfo.currencyCode;break}case"axfer":{const{amount:b,"asset-id":C}=J(e)["asset-transfer-transaction"];c=b.toString(),d="0",r===this.walletInfo.keys.publicKey?(c=`-${c}`,u=n.toString(),g=!0):P.push(this.walletInfo.keys.publicKey);const A=this.allTokensMap[C];if(A==null)return;a=A.currencyCode;break}default:return}const k={txid:l,date:s,currencyCode:a,blockHeight:o,nativeAmount:c,isSend:g,networkFee:d,ourReceiveAddresses:P,parentNetworkFee:u,signedTx:"",walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,k)}queryTransactions(){return h(this,null,function*(){return yield this.queryTxMutex(()=>h(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return h(this,null,function*(){const e=this.otherData.latestRound;let n,o=this.otherData.latestRound,l=0,s,r=!0;do{const i=yield(0,S.QJ)(this.networkInfo.indexerServers.map(u=>()=>h(this,null,function*(){const P=yield new ke({},u,"").lookupAccountTransactions(this.walletLocalData.publicKey).minRound(e).nextToken(s!=null?s:"").do();return f(P)}))),{"next-token":a,transactions:c}=i;if(c.length===0)break;for(const u of c){if(n==null&&(n=u.id,o=u["confirmed-round"]),l=u["confirmed-round"],u.id===this.otherData.latestTxid){r=!1;break}try{this.processAlgorandTransaction(u)}catch(g){this.log.warn("processAlgorandTransaction error:",g)}}o=o!=null?o:this.walletLocalData.blockHeight;const d=(o-l)/(o-e);this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=d,this.updateOnAddressesChecked(),s=a}while(s!=null&&r);n!=null&&this.otherData.latestTxid!==n&&(this.otherData.latestTxid=n,this.otherData.latestRound=o,this.walletLocalDataDirty=!0);for(const i of this.enabledTokens)this.tokenCheckTransactionsStatus[i]=1;this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return h(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBalance",oe).catch(()=>{}),this.addToLoop("queryTransactionParams",oe).catch(()=>{}),this.addToLoop("queryTransactions",Ce).catch(()=>{}),yield ve(te.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return h(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}calcFee(e){const n=e.estimateSize();return Math.max(this.suggestedTransactionParams.fee*n,this.networkInfo.minimumTxFee).toString()}getMaxSpendable(e){return h(this,null,function*(){let n=this.getBalance({currencyCode:e.currencyCode});if(e.currencyCode===this.currencyInfo.currencyCode&&(n=(0,w.sub)(n,this.totalReserve)),e.spendTargets[0].publicAddress==null)throw new Error("makeSpend Missing publicAddress");const{customNetworkFee:l}=e;let r=p(l).fee;r==null&&(e.spendTargets[0].nativeAmount="1",r=(yield this.makeSpend(e)).networkFee);const i=(a,c)=>h(this,null,function*(){const d=(0,w.sub)(c,a);if((0,w.lte)(d,"1"))return a;const u=(0,w.add)(a,(0,w.div)(d,"2"));e.spendTargets[0].nativeAmount=u;const g=(0,w.add)(u,r!=null?r:this.networkInfo.minimumTxFee.toString());return(0,w.gt)(g,n)?yield i(a,u):yield i(u,c)});return yield i("0",(0,w.add)(n,"1"))})}makeSpend(e){return h(this,null,function*(){var n,o,l;const{edgeSpendInfo:s,currencyCode:r,nativeBalance:i}=this.makeSpendCheck(e),a=(0,w.sub)(this.getBalance({currencyCode:this.currencyInfo.currencyCode}),this.totalReserve);if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:c,memo:d,publicAddress:u}=s.spendTargets[0];if(u==null)throw new Error("makeSpend Missing publicAddress");if(c==null)throw new R.$D;const{type:g}=(n=(0,t.Vk)(I)(s.otherParams))!=null?n:{type:r===this.currencyInfo.currencyCode?"pay":"axfer"};let P;d!=null&&(P=Uint8Array.from(he.from(d,"ascii")));const{customNetworkFee:k}=s,b=p(k).fee;let C,A=c,U="0",M,O,ce;switch(g){case"pay":{if(C=v.ZP.makePaymentTxnWithSuggestedParamsFromObject({to:u,from:this.walletInfo.keys.publicKey,amount:BigInt(c),note:P,suggestedParams:L({},this.suggestedTransactionParams)}),O=b!=null?b:this.calcFee(C),U=O,A=`-${(0,w.add)(A,U)}`,ce=u,(0,w.gt)((0,w.abs)(A),a))throw new R.C_;break}case"axfer":{const le=Object.keys(this.allTokensMap).find(Se=>this.allTokensMap[Se].currencyCode===r);if(le==null)throw new Error("Unrecognized asset");const ue=H((l=(o=this.allTokensMap)==null?void 0:o[le])==null?void 0:l.networkLocation);if(ue==null)throw new Error("Unrecognized asset");if(C=v.ZP.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:parseInt(ue.contractAddress),to:u,from:this.walletInfo.keys.publicKey,amount:BigInt(c),note:P,suggestedParams:L({},this.suggestedTransactionParams)}),O=b!=null?b:this.calcFee(C),A=`-${A}`,M=O,(0,w.gt)(M,a))throw new R.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:O});if((0,w.gt)((0,w.abs)(A),i))throw new R.C_;break}default:throw new Error("Unrecognized transaction type")}C.flatFee=!0,C.fee=parseInt(O);const Ee={encodedTx:D.YU.stringify((0,v.nJ)(C)),recipient:ce};return{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:A,isSend:!0,networkFee:U,ourReceiveAddresses:[],parentNetworkFee:M,signedTx:"",otherParams:Ee,walletId:this.walletId}})}signMessage(e,n){return h(this,null,function*(){const o=E(this.currencyInfo.pluginId)(n),l=(0,v.wj)(D.US.parse(e)),s=v.ZP.mnemonicToSecretKey(o.mnemonic),r=l.signTxn(s.sk);return D.US.stringify(r)})}signTx(e,n){return h(this,null,function*(){const{encodedTx:o,recipient:l}=x((0,S.Xp)(e)),s=(0,v.wj)(Uint8Array.from(D.YU.parse(o)));l!=null&&(yield this.checkRecipientMinimumBalance(this.getRecipientBalance,s.amount.toString(),l));const r=E(this.currencyInfo.pluginId)(n),i=v.ZP.mnemonicToSecretKey(r.mnemonic),a=s.signTxn(i.sk),c=D.YU.stringify(a);return e.signedTx=c,e})}broadcastTx(e){return h(this,null,function*(){const n=Uint8Array.from(D.YU.parse(e.signedTx));try{const{txId:o}=yield(0,S.QJ)(this.networkInfo.algodServers.map(l=>()=>h(this,null,function*(){return yield new ee("",l,"").sendRawTransaction(n).do()})));e.txid=o,e.date=Date.now()/1e3}catch(o){throw this.warn("FAILURE broadcastTx failed: ",o),o}return this.warn(`SUCCESS broadcastTx
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[741],{37011:function(de,_,m){"use strict";m.r(_),m.d(_,{AlgorandTools:function(){return ie},makeCurrencyEngine:function(){return Ae},makeCurrencyTools:function(){return be}});var v=m(88814),w=m(77591),Z=m(20918),X=m(79014),S=m(76714),t=m(82448),F=m(62177);const j=(0,t.su)({latestRound:(0,t.Vk)(t.mH,0),latestTxid:(0,t.Vk)(t.XC,"")}),z=(0,t.su)({amount:t.mH,assets:(0,t._2)((0,t.su)({amount:t.mH,"asset-id":t.mH})),"min-balance":t.mH,round:t.mH}),Q=(0,t.su)({"confirmed-round":t.mH,fee:t.mH,"first-valid":t.mH,id:t.XC,note:(0,t.Zz)(t.XC),"round-time":t.mH,sender:t.XC,"tx-type":t.XC}).withRest,K=(0,t.Wf)("pay"),V=(0,t.su)({"payment-transaction":(0,t.su)({amount:t.mH,"close-amount":t.mH,receiver:t.XC}),"tx-type":K}),G=(0,t.Wf)("axfer"),J=(0,t.su)({"asset-transfer-transaction":(0,t.su)({amount:t.mH,"asset-id":t.mH}),"tx-type":G}),f=(0,t.su)({"current-round":t.mH,"next-token":(0,t.Zz)(t.XC),transactions:(0,t._2)(Q)}),T=(0,t.su)({flatFee:t.jK,fee:t.mH,firstRound:t.mH,lastRound:t.mH,genesisID:t.XC,genesisHash:t.XC}),I=(0,t.su)({type:t.XC}).withRest,x=(0,t.su)({encodedTx:t.XC,recipient:(0,t.Zz)(t.XC)}),q=(0,t.su)({type:K,to:t.XC,amount:t.mH}).withRest,p=(0,t.Vk)((0,t.su)({fee:(0,t.Zz)(t.XC)}),{fee:void 0}),H=(0,t.Vk)((0,t.su)({contractAddress:F.jD})),ne=F.BQ,E=y=>{const e=(0,t.su)({[`${y}Mnemonic`]:t.XC});return(0,t.W1)(n=>({mnemonic:e(n)[`${y}Mnemonic`]}),n=>({[`${y}Mnemonic`]:n.mnemonic}))},Y=(0,t.su)({id:(0,t._C)(t.XC,t.mH),method:(0,t.Wf)("algo_signTxn"),params:(0,t.vq)((0,t.vq)((0,t.su)({txn:t.XC,message:(0,t.Zz)(t.XC)})))}),N=(0,t.su)({id:t.mH,jsonrpc:(0,t.Wf)("2.0"),method:(0,t.Wf)("algo_signTxn"),params:(0,t.vq)((0,t.vq)((0,t.su)({txn:t.XC,message:(0,t.Zz)(t.XC)})))}).withRest;var $=m(12614),R=m(94935),D=m(35620),W=m(50244),he=m(48764).Buffer,fe=Object.defineProperty,ye=Object.defineProperties,me=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertySymbols,pe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,Te=Reflect.get,re=(y,e,n)=>e in y?fe(y,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):y[e]=n,L=(y,e)=>{for(var n in e||(e={}))ge.call(e,n)&&re(y,n,e[n]);if(se)for(var n of se(e))we.call(e,n)&&re(y,n,e[n]);return y},Ie=(y,e)=>ye(y,me(e)),ve=(y,e,n)=>Te(pe(y),n,e),h=(y,e,n)=>new Promise((o,l)=>{var s=a=>{try{i(n.next(a))}catch(c){l(c)}},r=a=>{try{i(n.throw(a))}catch(c){l(c)}},i=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,r);i((n=n.apply(y,e)).next())});const{Algodv2:ee,Indexer:Ce}=v.ZP,oe=5e3,ke=3e3;class te extends W.P{constructor(e,n,o,l){super(e,n,o,l),this.getRecipientBalance=s=>h(this,null,function*(){try{return(yield this.fetchAccountInfo(s)).amount.toString()}catch{return this.minimumAddressBalance}}),this.engineGetActivationAssets=s=>h(this,null,function*(){return{assetOptions:[{paymentWalletId:this.walletId,currencyPluginId:this.currencyInfo.pluginId}]}}),this.engineActivateWallet=s=>h(this,[s],function*({activateTokenIds:r,paymentTokenId:i,paymentWallet:a}){var c;if(r==null)throw new Error(`Must specify activateTokenIds for ${this.currencyInfo.currencyCode}`);if(i!=null)throw new Error(`Must activate with ${this.currencyInfo.currencyCode}`);if((a==null?void 0:a.id)!==this.walletId)throw new Error("Must pay with same wallet you are activating token with");const d=this.networkInfo.minimumTxFee.toFixed();let u="0";const g=[];for(const C of r){if(this.allTokensMap[C]==null)throw new Error(`Invalid tokenId to activate ${C}`);const b={currencyCode:this.allTokensMap[C].currencyCode,skipChecks:!0,spendTargets:[{publicAddress:this.walletInfo.keys.publicKey,nativeAmount:"0"}]};try{const k=yield this.makeSpend(b);u=(0,w.add)(u,(c=k.parentNetworkFee)!=null?c:d)}catch{u=(0,w.add)(u,d)}g.push(b)}return{paymentWalletId:this.walletId,fromNativeAmount:"0",networkFee:{nativeAmount:u,currencyPluginId:this.currencyInfo.pluginId},approve:(...C)=>h(this,[...C],function*(b={}){const{metadata:k}=b,A=[];for(const U of g){const M=yield this.makeSpend(U);M.metadata=L({},k);let O=yield a.signTx(M);O=yield a.broadcastTx(O),A.push(O),yield a.saveTx(O)}return{transactions:A}}),close:()=>h(this,null,function*(){})}}),this.networkInfo=e.networkInfo,this.queryTxMutex=(0,S.jT)(),this.suggestedTransactionParams={flatFee:!1,fee:0,firstRound:0,lastRound:0,genesisID:this.networkInfo.genesisID,genesisHash:this.networkInfo.genesisHash},this.minimumAddressBalance=this.networkInfo.minimumAddressBalance,this.totalReserve=this.minimumAddressBalance,this.otherMethods={wcInit:(s,r="Edge")=>h(this,null,function*(){return yield(0,S.Vs)(new Promise((i,a)=>{const c=new $.Z({uri:s.uri,storageId:s.uri,clientMeta:{description:"Edge Wallet",url:"https://www.edge.app",icons:["https://content.edge.app/Edge_logo_Icon.png"],name:r}});c.on("session_request",(d,u)=>{if(d!=null)throw this.error("Wallet connect session_request",d),d;const g=(0,F.ff)(u).params[0],P=Ie(L({},g),{timeConnected:Date.now()/1e3});this.tools.walletConnectors[s.uri]={connector:c,wcProps:s,dApp:P},i(P)}),c.on("call_request",(d,u)=>{try{if(d!=null)throw d;const g=N(u),P=g.params[0][0],C=(0,v.wj)(D.US.parse(P.txn)),b=C.amount!=null?C.amount.toString():"0",k=C.fee.toFixed();let A;if(C.type==="axfer"){const M=C.assetIndex.toString();if(this.allTokensMap[M]==null)throw new Error("Unrecognized token");A=M}const U={uri:s.uri,dApp:this.tools.walletConnectors[s.uri].dApp,payload:g,walletId:this.tools.walletConnectors[s.uri].walletId,nativeAmount:b,networkFee:k,tokenId:A};this.currencyEngineCallbacks.onWcNewContractCall(U)}catch(g){throw this.warn("Wallet connect call_request ",g),g}}),c.on("disconnect",(d,u)=>{if(d!=null)throw d;delete this.tools.walletConnectors[s.uri]})}),5e3)}),wcConnect:(s,r,i)=>{this.tools.walletConnectors[s].connector.approveSession({accounts:[r],chainId:416001}),this.tools.walletConnectors[s].walletId=i},wcDisconnect:s=>{var r;((r=this.tools.walletConnectors[s])==null?void 0:r.connector)!=null&&(this.tools.walletConnectors[s].connector.killSession().catch(()=>{}),delete this.tools.walletConnectors[s])},wcApproveRequest:(s,r,i)=>h(this,null,function*(){this.tools.walletConnectors[s].connector.approveRequest({id:Number(r.id),jsonrpc:"2.0",result:[i]})}),wcRejectRequest:(s,r)=>h(this,null,function*(){this.tools.walletConnectors[s].connector.rejectRequest({id:Number(r.id),jsonrpc:"2.0",error:{message:"rejected"}})}),wcGetConnections:()=>Object.keys(this.tools.walletConnectors).filter(s=>this.tools.walletConnectors[s].walletId===this.walletInfo.id).map(s=>L(L({},this.tools.walletConnectors[s].dApp),this.tools.walletConnectors[s].wcProps))}}setOtherData(e){this.otherData=j(e)}fetchAccountInfo(e){return h(this,null,function*(){return yield(0,S.QJ)(this.networkInfo.algodServers.map(n=>()=>h(this,null,function*(){const l=yield new ee("",n,"").accountInformation(e).do();return z(l)})))})}queryBalance(){return h(this,null,function*(){try{const e=yield this.fetchAccountInfo(this.walletLocalData.publicKey),{assets:n,amount:o,"min-balance":l,round:s}=e;this.totalReserve=l.toString();const r=[];for(const i of this.enabledTokens)if(i===this.currencyInfo.currencyCode)this.updateBalance(this.currencyInfo.currencyCode,o.toString());else{const a=Object.keys(this.allTokensMap).find(d=>this.allTokensMap[d].currencyCode===i);if(a==null){this.updateBalance(i,"0");continue}const c=n.find(d=>d["asset-id"].toFixed()===a);if(c==null){r.push(a),this.updateBalance(i,"0");continue}this.updateBalance(i,c.amount.toString())}s>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=s,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),(0,S.dQ)(r,this.walletLocalData.unactivatedTokenIds)||(this.walletLocalData.unactivatedTokenIds=r,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds))}catch(e){this.log.warn("queryBalance Error ",e)}})}queryTransactionParams(){return h(this,null,function*(){try{const e=yield(0,S.QJ)(this.networkInfo.algodServers.map(n=>()=>h(this,null,function*(){const l=yield new ee("",n,"").getTransactionParams().do(),s=T(l);if(s.genesisHash!==this.networkInfo.genesisHash)throw new Error("Server genesisHash mismatch");return s})));this.suggestedTransactionParams=e}catch(e){this.log.warn("queryTransactionParams error:",e)}})}processAlgorandTransaction(e){const{fee:n,"confirmed-round":o,id:l,"round-time":s,sender:r,"tx-type":i}=e;let a,c,d,u,g=!1;const P=[];switch(i){case"pay":{const{amount:b}=V(e)["payment-transaction"];c=b.toString(),d=n.toString(),r===this.walletInfo.keys.publicKey?(c=`-${(0,w.add)(c,d)}`,g=!0):(d="0",P.push(this.walletInfo.keys.publicKey)),a=this.currencyInfo.currencyCode;break}case"axfer":{const{amount:b,"asset-id":k}=J(e)["asset-transfer-transaction"];c=b.toString(),d="0",r===this.walletInfo.keys.publicKey?(c=`-${c}`,u=n.toString(),g=!0):P.push(this.walletInfo.keys.publicKey);const A=this.allTokensMap[k];if(A==null)return;a=A.currencyCode;break}default:return}const C={txid:l,date:s,currencyCode:a,blockHeight:o,nativeAmount:c,isSend:g,networkFee:d,ourReceiveAddresses:P,parentNetworkFee:u,signedTx:"",walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,C)}queryTransactions(){return h(this,null,function*(){return yield this.queryTxMutex(()=>h(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return h(this,null,function*(){const e=this.otherData.latestRound;let n,o=this.otherData.latestRound,l=0,s,r=!0;do{const i=yield(0,S.QJ)(this.networkInfo.indexerServers.map(u=>()=>h(this,null,function*(){const P=yield new Ce({},u,"").lookupAccountTransactions(this.walletLocalData.publicKey).minRound(e).nextToken(s!=null?s:"").do();return f(P)}))),{"next-token":a,transactions:c}=i;if(c.length===0)break;for(const u of c){if(n==null&&(n=u.id,o=u["confirmed-round"]),l=u["confirmed-round"],u.id===this.otherData.latestTxid){r=!1;break}try{this.processAlgorandTransaction(u)}catch(g){this.log.warn("processAlgorandTransaction error:",g)}}o=o!=null?o:this.walletLocalData.blockHeight;const d=(o-l)/(o-e);this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=d,this.updateOnAddressesChecked(),s=a}while(s!=null&&r);n!=null&&this.otherData.latestTxid!==n&&(this.otherData.latestTxid=n,this.otherData.latestRound=o,this.walletLocalDataDirty=!0);for(const i of this.enabledTokens)this.tokenCheckTransactionsStatus[i]=1;this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return h(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBalance",oe).catch(()=>{}),this.addToLoop("queryTransactionParams",oe).catch(()=>{}),this.addToLoop("queryTransactions",ke).catch(()=>{}),yield ve(te.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return h(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}calcFee(e){const n=e.estimateSize();return Math.max(this.suggestedTransactionParams.fee*n,this.networkInfo.minimumTxFee).toString()}getMaxSpendable(e){return h(this,null,function*(){let n=this.getBalance({currencyCode:e.currencyCode});if(e.currencyCode===this.currencyInfo.currencyCode&&(n=(0,w.sub)(n,this.totalReserve)),e.spendTargets[0].publicAddress==null)throw new Error("makeSpend Missing publicAddress");const{customNetworkFee:l}=e;let r=p(l).fee;r==null&&(e.spendTargets[0].nativeAmount="1",r=(yield this.makeSpend(e)).networkFee);const i=(a,c)=>h(this,null,function*(){const d=(0,w.sub)(c,a);if((0,w.lte)(d,"1"))return a;const u=(0,w.add)(a,(0,w.div)(d,"2"));e.spendTargets[0].nativeAmount=u;const g=(0,w.add)(u,r!=null?r:this.networkInfo.minimumTxFee.toString());return(0,w.gt)(g,n)?yield i(a,u):yield i(u,c)});return yield i("0",(0,w.add)(n,"1"))})}makeSpend(e){return h(this,null,function*(){var n,o,l;const{edgeSpendInfo:s,currencyCode:r,nativeBalance:i}=this.makeSpendCheck(e),a=(0,w.sub)(this.getBalance({currencyCode:this.currencyInfo.currencyCode}),this.totalReserve);if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:c,memo:d,publicAddress:u}=s.spendTargets[0];if(u==null)throw new Error("makeSpend Missing publicAddress");if(c==null)throw new R.$D;const{type:g}=(n=(0,t.Vk)(I)(s.otherParams))!=null?n:{type:r===this.currencyInfo.currencyCode?"pay":"axfer"};let P;d!=null&&(P=Uint8Array.from(he.from(d,"ascii")));const{customNetworkFee:C}=s,b=p(C).fee;let k,A=c,U="0",M,O,ce;switch(g){case"pay":{if(k=v.ZP.makePaymentTxnWithSuggestedParamsFromObject({to:u,from:this.walletInfo.keys.publicKey,amount:BigInt(c),note:P,suggestedParams:L({},this.suggestedTransactionParams)}),O=b!=null?b:this.calcFee(k),U=O,A=`-${(0,w.add)(A,U)}`,ce=u,(0,w.gt)((0,w.abs)(A),a))throw new R.C_;break}case"axfer":{const le=Object.keys(this.allTokensMap).find(Se=>this.allTokensMap[Se].currencyCode===r);if(le==null)throw new Error("Unrecognized asset");const ue=H((l=(o=this.allTokensMap)==null?void 0:o[le])==null?void 0:l.networkLocation);if(ue==null)throw new Error("Unrecognized asset");if(k=v.ZP.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:parseInt(ue.contractAddress),to:u,from:this.walletInfo.keys.publicKey,amount:BigInt(c),note:P,suggestedParams:L({},this.suggestedTransactionParams)}),O=b!=null?b:this.calcFee(k),A=`-${A}`,M=O,(0,w.gt)(M,a))throw new R.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:O});if((0,w.gt)((0,w.abs)(A),i))throw new R.C_;break}default:throw new Error("Unrecognized transaction type")}k.flatFee=!0,k.fee=parseInt(O);const Ee={encodedTx:D.YU.stringify((0,v.nJ)(k)),recipient:ce};return{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:A,isSend:!0,networkFee:U,ourReceiveAddresses:[],parentNetworkFee:M,signedTx:"",otherParams:Ee,walletId:this.walletId}})}signMessage(e,n){return h(this,null,function*(){const o=E(this.currencyInfo.pluginId)(n),l=(0,v.wj)(D.US.parse(e)),s=v.ZP.mnemonicToSecretKey(o.mnemonic),r=l.signTxn(s.sk);return D.US.stringify(r)})}signTx(e,n){return h(this,null,function*(){const{encodedTx:o,recipient:l}=x((0,S.Xp)(e)),s=(0,v.wj)(Uint8Array.from(D.YU.parse(o)));l!=null&&(yield this.checkRecipientMinimumBalance(this.getRecipientBalance,s.amount.toString(),l));const r=E(this.currencyInfo.pluginId)(n),i=v.ZP.mnemonicToSecretKey(r.mnemonic),a=s.signTxn(i.sk),c=D.YU.stringify(a);return e.signedTx=c,e})}broadcastTx(e){return h(this,null,function*(){const n=Uint8Array.from(D.YU.parse(e.signedTx));try{const{txId:o}=yield(0,S.QJ)(this.networkInfo.algodServers.map(l=>()=>h(this,null,function*(){return yield new ee("",l,"").sendRawTransaction(n).do()})));e.txid=o,e.date=Date.now()/1e3}catch(o){throw this.warn("FAILURE broadcastTx failed: ",o),o}return this.warn(`SUCCESS broadcastTx
|
|
2
2
|
${(0,S.oX)(e)}`),e})}getDisplayPrivateSeed(e){return E(this.currencyInfo.pluginId)(e).mnemonic}getDisplayPublicSeed(){var e;return(e=this.walletInfo.keys.publicKey)!=null?e:""}}function Ae(y,e,n,o){return h(this,null,function*(){const l=ne(n),s=new te(y,e,l,o);return yield s.loadEngine(e,l,o),s})}var xe=m(48764).Buffer,B=(y,e,n)=>new Promise((o,l)=>{var s=a=>{try{i(n.next(a))}catch(c){l(c)}},r=a=>{try{i(n.throw(a))}catch(c){l(c)}},i=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,r);i((n=n.apply(y,e)).next())});const{isValidAddress:ae,mnemonicFromSeed:Pe}=v.ZP;class ie{constructor(e){const{builtinTokens:n,currencyInfo:o,io:l}=e;this.io=l,this.currencyInfo=o,this.builtinTokens=n,this.walletConnectors={}}importPrivateKey(e){return B(this,null,function*(){const{pluginId:n}=this.currencyInfo;return v.ZP.mnemonicToSecretKey(e),{[`${n}Mnemonic`]:e}})}createPrivateKey(e){return B(this,null,function*(){if(e!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const n=xe.from(this.io.random(32)),o=Pe(n);return yield this.importPrivateKey(o)})}derivePublicKey(e){return B(this,null,function*(){const{pluginId:n}=this.currencyInfo;if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const o=E(n)(e.keys);return{publicKey:v.ZP.mnemonicToSecretKey(o.mnemonic).addr}})}parseUri(e,n,o){return B(this,null,function*(){const{pluginId:l}=this.currencyInfo,s={[l]:!0,wc:!0},{parsedUri:r,edgeParsedUri:i}=(0,X.k)(this.currencyInfo,e,s,n!=null?n:this.currencyInfo.currencyCode,o);if(r.protocol==="wc"){if(r.query.bridge!=null&&r.query.key!=null)return i.walletConnect={uri:e,topic:r.pathname.split("@")[0],version:r.pathname.split("@")[1],bridge:r.query.bridge,key:r.query.key},i;throw new Error("MissingWcBridgeKey")}let a="";if(i.publicAddress!=null&&(a=i.publicAddress),!ae(a))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=r.query.memo,i})}encodeUri(e,n){return B(this,null,function*(){const{pluginId:o}=this.currencyInfo,{nativeAmount:l,currencyCode:s,publicAddress:r}=e;if(!ae(r))throw new Error("InvalidPublicAddressError");let i;if(typeof l=="string"){const c=(0,S.cp)(this.currencyInfo,s!=null?s:this.currencyInfo.currencyCode,n);if(c==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,w.div)(l,c.multiplier,18)}return(0,X.Q)(e,o,i)})}getTokenId(e){return B(this,null,function*(){(0,Z.Rp)(e);const n=H(e.networkLocation);if(n==null)throw new Error("ErrorInvalidContractAddress");return n.contractAddress})}}function be(y){return B(this,null,function*(){return new ie(y)})}},79014:function(de,_,m){"use strict";m.d(_,{Q:function(){return J},k:function(){return G}});var v=m(77591),w=m.n(v),Z=m(24350),X=m(84564),S=m.n(X),t=m(76714),F=Object.defineProperty,j=Object.getOwnPropertySymbols,z=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,K=(f,T,I)=>T in f?F(f,T,{enumerable:!0,configurable:!0,writable:!0,value:I}):f[T]=I,V=(f,T)=>{for(var I in T||(T={}))z.call(T,I)&&K(f,I,T[I]);if(j)for(var I of j(T))Q.call(T,I)&&K(f,I,T[I]);return f};function G(f,T,I,x,q){const p=V({},S()(T,{},!0)),H=T.startsWith(`${f.pluginId}://`);if(p.protocol!=null&&(p.protocol=p.protocol.replace(":","")),p.protocol!=null&&p.protocol!==""&&!I[p.protocol])throw new Error(`Uri protocol '${p.protocol}' is not supported for ${f.pluginId}.`);if(p.host===""&&p.pathname==="")throw new Error("Path and host not found in uri.");const E={publicAddress:p.host!==""?p.host:p.pathname.split("/")[0]},Y=p.query.label,N=p.query.message,$=p.query.category;(Y!=null||N!=null||$!=null||H)&&(E.metadata={},E.metadata.name=Y,E.metadata.notes=N,E.metadata.category=$,E.metadata.gateway=H!=null?H:!1);const R=p.query.amount;if(R!=null&&typeof R=="string"){x==null&&(x=f.currencyCode);const D=(0,t.cp)(f,x!=null?x:"",q);if(D==null)throw new Error("InternalErrorInvalidCurrencyCode");let W=(0,v.mul)(R,D.multiplier);W=(0,v.toFixed)(W,0,0),E.nativeAmount=W,E.currencyCode=x}return{edgeParsedUri:E,parsedUri:p}}function J(f,T,I){if(f.publicAddress==null)throw new Error("InvalidPublicAddressError");if(I==null&&f.label==null&&f.message==null)return f.publicAddress;{let x="";I!=null&&(x+="amount="+I+"&"),(f.label!=null||f.message!=null)&&(typeof f.label=="string"&&(x+="label="+f.label+"&"),typeof f.message=="string"&&(x+="message="+f.message+"&")),x=x.substr(0,x.length-1);const q={scheme:T,path:f.publicAddress,query:x};return(0,Z.qC)(q)}}},55024:function(){}}]);
|