edge-currency-accountbased 4.48.2 → 4.48.3

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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.48.3 (2025-06-06)
6
+
7
+ - changed: Improved change-server integration by usage of checkpoints.
8
+ - fixed: Remove gas station multiplier to fix gas-station calculations.
9
+
5
10
  ## 4.48.2 (2025-06-05)
6
11
 
7
12
  - changed: (Hedera) Save memo to queried transactions
@@ -1 +1 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8330],{26277:function(F,M,k){k.d(M,{k:function(){return b}});var p=k(66001),S=k(82671),A=k(89089),C=k(14483),d=k(36856),m=k(44276),L=k(42704);function E(f,t){var e;const{memos:n=[]}=f,{displayName:s,memoOptions:i=[],multipleMemos:r=!1}=t,{memoName:a="memo"}=(e=i[0])!=null?e:{};for(const o of n){const u=i.filter(y=>o.type===y.type);if(u.length<1)throw new Error(`${s} ${a}: cannot be type ${o.type}`);const g=u.map(y=>O(o,y)).find(y=>y!=null);if(g!=null)throw new Error(`${s} ${a}: ${g}`)}if(!r&&n.length>1)throw new Error(`${s} only supports one ${a}`)}function O(f,t){if(t.type==="text"&&t.maxLength!=null&&f.value.length>t.maxLength)return`cannot be longer than ${t.maxLength} characters`;if(t.type==="number"){const e=(0,L.HS)(d.ym)(f.value);if(e==null)return"is not a valid number";if(t.maxValue!=null&&(0,p.gt)(e,t.maxValue))return`cannot be greater than ${t.maxValue}`}if(t.type==="hex"){const e=(0,L.HS)(d.zU)(f.value);if(e==null)return"is not valid hexadecimal";if(t.maxBytes!=null&&e.length>t.maxBytes)return`cannot be longer than ${t.maxBytes} bytes`;if(t.minBytes!=null&&e.length<t.minBytes)return`cannot be shorter than ${t.minBytes} bytes`}}var v=Object.defineProperty,D=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,$=(f,t,e)=>t in f?v(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,K=(f,t)=>{for(var e in t||(t={}))N.call(t,e)&&$(f,e,t[e]);if(D)for(var e of D(t))H.call(t,e)&&$(f,e,t[e]);return f},l=(f,t,e)=>new Promise((n,s)=>{var i=o=>{try{a(e.next(o))}catch(u){s(u)}},r=o=>{try{a(e.throw(o))}catch(u){s(u)}},a=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,r);a((e=e.apply(f,t)).next())});const h=1e4,c=2500,w=3600*24;class b{constructor(t,e,n,s){this.tasks=new Map,this.allTokens=[],this.allTokensMap={},this.builtinTokens={},this.customTokens={},this.enabledTokenIds=[],this.enabledTokens=[];const{builtinTokens:i,currencyInfo:r}=t,{callbacks:a,customTokens:o,enabledTokenIds:u,log:g,walletLocalDisklet:y}=s;this.tools=e,this.log=g,this.warn=(I,x)=>this.log.warn(I+(0,m.Jo)(x)),this.error=(I,x)=>this.log.error(I+(0,m.Jo)(x)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.seenTxCheckpoint=s.seenTxCheckpoint,this.transactionEvents=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=n,this.walletId=n.id,this.currencyInfo=r,this.otherData=void 0,this.minimumAddressBalance="0";const{currencyCode:T}=r;this.transactionList[T]=[],this.txIdMap[T]={},this.txIdList[T]=[],this.builtinTokens=i,this.changeCustomTokensSync(o),this.changeEnabledTokenIdsSync(u),s.userSettings!=null?this.currentSettings=s.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=a,this.walletLocalDisklet=y,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=n.keys.publicKey),this.walletLocalData={blockHeight:0,lastAddressQueryHeight:0,lastTransactionQueryHeight:{},lastTransactionDate:{},publicKey:"",totalBalances:{},lastCheckedTxsDropped:0,numUnconfirmedSpendTxs:0,numTransactions:{},unactivatedTokenIds:[],otherData:void 0},this.log(`Created Wallet Type ${this.walletInfo.type} for Currency Plugin ${this.currencyInfo.pluginId}`),this.checkBalances=(I,x)=>{var U,_;const{nativeAmount:P,parentNetworkFee:B}=I,R=this.currencyInfo.currencyCode,J=x!=null?this.allTokensMap[x].currencyCode:R,W=(U=this.walletLocalData.totalBalances[J])!=null?U:"0",V=R,Q=(_=this.walletLocalData.totalBalances[V])!=null?_:"0";if((0,p.gt)((0,p.abs)(P),W))throw new S.k5({tokenId:x});if(B!=null&&(0,p.gt)(B,Q))throw new S.k5({networkFee:B,tokenId:null})},this.makeEdgeTransactionAmounts=(I,x,U)=>{let _=`-${I}`,P=x,B;return U!=null?(B=P,P="0"):_=(0,p.sub)(_,P),{nativeAmount:_,networkFee:P,parentNetworkFee:B}}}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,p.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const n of t.ourReceiveAddresses)n===this.walletLocalData.publicKey&&(e=!1);return e}isTransactionNew(t){const e=this.getTxCheckpoint(t);return this.seenTxCheckpoint!=null&&e!==this.seenTxCheckpoint?this.selectSeenTxCheckpoint(e,this.seenTxCheckpoint)===e:!1}setOtherData(t){}loadTransactions(){return l(this,null,function*(){var t;if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const e=this.walletLocalDisklet;let n;try{const a=yield e.getText(d._6);n=JSON.parse(a)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield e.setText(d._6,JSON.stringify(this.txIdList))}let s;try{const a=yield e.getText(d.wV);s=JSON.parse(a)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield e.setText(d.wV,JSON.stringify(this.txIdMap))}let i;try{const a=yield e.getText(d.Kw);i=JSON.parse(a)}catch(a){a.code==="ENOENT"||((t=a.message)==null?void 0:t.includes("No such file"))===!0?(this.log("Could not load transactionList file. Failure is ok on new device"),yield e.setText(d.Kw,JSON.stringify(this.transactionList))):this.log.crash(a,{currencyPluginId:this.currencyInfo.pluginId})}let r=!0;for(const a of Object.keys(this.transactionList))if(this.transactionList[a]!=null&&this.transactionList[a].length>0){r=!1;break}if(r){this.transactionList=i!=null?i:this.transactionList,this.txIdList=n!=null?n:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;for(const a of Object.keys(this.transactionList))for(const o of this.transactionList[a])this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.highestSeenCheckpoint,this.getTxCheckpoint(o))}else if(i!=null)for(const a of Object.keys(i))for(const o of i[a])this.addTransaction(a,o);for(const a in this.transactionList)this.walletLocalData.numTransactions[a]=this.transactionList[a].length})}loadEngine(){return l(this,null,function*(){var t;const{walletInfo:e}=this,{currencyCode:n}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const s=this.walletLocalDisklet;try{const i=yield s.getText(d.e1);this.walletLocalData=(0,d.TS)(JSON.parse(i)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,d.TS)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield s.setText(d.e1,JSON.stringify(this.walletLocalData))}catch(r){throw this.error("Error writing to localDataStore. Engine not started: ",r),r}}this.setOtherData((t=this.walletLocalData.otherData)!=null?t:{}),this.walletLocalDataDirty=!(0,m.AP)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[n]=0,this.tokenCheckTransactionsStatus[n]=0,this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback(),this.seenTxCheckpoint==null&&(yield this.loadTransactions(),this.highestSeenCheckpoint==null&&(this.highestSeenCheckpoint="0"))})}findTransaction(t,e){if(this.txIdMap[t]!=null){const n=this.txIdMap[t][e];if(typeof n=="number")return n}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,n){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=n!=null?n:Math.round(Date.now()/1e3));const s=(0,m.Qh)(e.txid),i=this.findTransaction(t,s);let r=!1;if(i===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),r=!0,typeof this.transactionList[t]>"u")this.transactionList[t]=[];else if(this.transactionList[t].length>=c)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0;const a=this.isTransactionNew(e);this.transactionEvents.push({isNew:a,transaction:e}),this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.getTxCheckpoint(e),this.highestSeenCheckpoint),this.warn(`addTransaction new tx: ${e.txid}`)}else{const o=this.transactionList[t][i],{otherParams:u={}}=o,{otherParams:g={}}=e;(o.blockHeight<e.blockHeight||o.blockHeight===0&&e.blockHeight<0||o.blockHeight===e.blockHeight&&(o.networkFee!==e.networkFee||o.nativeAmount!==e.nativeAmount||u.lastSeenTime!==g.lastSeenTime||o.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&o.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,o.date!==e.date&&(r=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,i))}r&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let n=0;for(const s of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,m.Qh)(s.txid)]=n,e.push((0,m.Qh)(s.txid)),n++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>w&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.sendTransactionEvents())}checkDroppedTransactions(t){let e=0;for(const n in this.transactionList)for(let s=0;s<this.transactionList[n].length;s++){const i=this.transactionList[n][s];if(i.blockHeight===0){const{otherParams:r={}}=i,a=r.lastSeenTime;t-a>w?(i.blockHeight=-1,i.nativeAmount="0",this.transactionEvents.push({isNew:!1,transaction:i})):this.isSpendTx(i)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];if(this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),n==null||!(0,p.eq)(e,n)){this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`);const s=(0,C.jE)(t,this.currencyInfo.currencyCode,this.allTokensMap);if(s===void 0)return;this.currencyEngineCallbacks.onTokenBalanceChanged(s,e)}this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,n){this.transactionList[t][n]=e,this.transactionListDirty=!0,this.transactionEvents.push({isNew:!1,transaction:e}),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return l(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let n=JSON.stringify(this.transactionList);e.push(t.setText(d.Kw,n).catch(s=>{this.error("Error saving transactionList ",s)})),n=JSON.stringify(this.txIdList),e.push(t.setText(d._6,n).catch(s=>{this.error("Error saving txIdList ",s)})),n=JSON.stringify(this.txIdMap),e.push(t.setText(d.wV,n).catch(s=>{this.error("Error saving txIdMap ",s)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const n=JSON.stringify(this.walletLocalData);yield t.setText(d.e1,n).then(()=>{this.walletLocalDataDirty=!1}).catch(s=>{this.error("Error saving walletLocalData ",s)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{const n=(0,C.jE)(e,this.currencyInfo.currencyCode,this.allTokensMap);if(n===void 0)continue;this.currencyEngineCallbacks.onTokenBalanceChanged(n,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(n){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,n)}}doInitialUnactivatedTokenIdsCallback(){try{this.walletLocalData.unactivatedTokenIds!=null&&this.walletLocalData.unactivatedTokenIds.length>0&&this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds)}catch(t){this.error("doInitialUnactivatedTokenIdsCallback Error",t)}}addToLoop(t,e,n=()=>l(this,null,function*(){yield this[t]()})){if(this.tasks.get(t)!=null)return;const s=r=>{this.log(t+": "+String(r))},i=(0,A.Z)(n,e,{onError:s});this.tasks.set(t,i),this.engineOn&&i.start()}removeFromLoop(t){var e;(e=this.tasks.get(t))==null||e.stop(),this.tasks.delete(t)}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}getTxCheckpoint(t){return t.blockHeight.toString()}selectSeenTxCheckpoint(t,e){return t==null?e:e==null||parseInt(t)>parseInt(e)?t:e}sendTransactionEvents(){this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[],this.updateSeenTxCheckpoint())}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const n=this.enabledTokens,s=1/n.length;let i=0,r=0;for(const a of n){const o=(t=this.tokenCheckBalanceStatus[a])!=null?t:0,u=(e=this.tokenCheckTransactionsStatus[a])!=null?e:0;i+=(o+u)/2*s,o===1&&u===1&&r++}r===n.length&&(i=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${i}`),this.currencyEngineCallbacks.onAddressesChecked(i),this.addressesChecked&&this.updateSeenTxCheckpoint()}updateSeenTxCheckpoint(){const t=this.selectSeenTxCheckpoint(this.highestSeenCheckpoint,this.seenTxCheckpoint);t!=null&&t!==this.seenTxCheckpoint&&(this.seenTxCheckpoint=t,this.currencyEngineCallbacks.onSeenTxCheckpoint(this.seenTxCheckpoint))}clearBlockchainCache(){return l(this,null,function*(){this.walletLocalData=(0,d.TS)({publicKey:this.walletLocalData.publicKey}),this.walletLocalDataDirty=!0,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.transactionList={},this.txIdList={},this.txIdMap={},this.transactionListDirty=!0,this.setOtherData({}),yield this.saveWalletLoop()})}startEngine(){return l(this,null,function*(){this.addToLoop("saveWalletLoop",h),this.engineOn=!0;for(const[,t]of this.tasks)t.start()})}killEngine(){return l(this,null,function*(){this.engineOn=!1;for(const[,t]of this.tasks)t.stop()})}changeUserSettings(t){return l(this,null,function*(){this.currentSettings=t})}getBlockHeight(){return this.walletLocalData.blockHeight}changeCustomTokensSync(t){this.customTokens={};for(const e of Object.keys(t)){const n=t[e];try{(0,C.k9)(n)}catch{this.log.warn(`Dropping custom token "${n.currencyCode}" / ${e}`);continue}this.customTokens[e]=n}this.allTokensMap=K(K({},this.customTokens),this.builtinTokens),this.allTokens=(0,C.yQ)(this.allTokensMap)}changeCustomTokens(t){return l(this,null,function*(){this.changeCustomTokensSync(t)})}changeEnabledTokenIdsSync(t){const{currencyCode:e}=this.currencyInfo,n=new Set,s=new Set;for(const i of t){const r=this.allTokensMap[i];r!=null&&(n.add(r.currencyCode),s.add(i))}this.enabledTokens=[...n,e],this.enabledTokenIds=[...s]}changeEnabledTokenIds(t){return l(this,null,function*(){this.changeEnabledTokenIdsSync(t)})}getBalance(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e],s=this.walletLocalData.totalBalances[n];return s==null?"0":s}getNumTransactions(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e];return this.walletLocalData.numTransactions[n]==null?0:this.walletLocalData.numTransactions[n]}getTransactions(t){return l(this,null,function*(){const{startDate:e,endDate:n,tokenId:s}=t,{currencyCode:i}=s==null?this.currencyInfo:this.allTokensMap[s];return yield this.loadTransactions(),this.transactionList[i]==null?[]:this.transactionList[i].filter(a=>new Date(a.date)>=(e!=null?e:new Date(0))&&new Date(a.date)<=(n!=null?n:new Date))})}getFreshAddress(t){return l(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return l(this,null,function*(){})}isAddressUsed(t){return l(this,null,function*(){return!1})}dumpData(){return l(this,null,function*(){return{walletId:this.walletId.split(" - ")[0],walletType:this.walletInfo.type,data:{pluginType:{pluginId:this.currencyInfo.pluginId},walletLocalData:this.walletLocalData}}})}makeSpendCheck(t){var e,n,s;const{skipChecks:i=!1,tokenId:r}=t;E(t,this.currencyInfo);for(const y of t.spendTargets)if(!i&&y.publicAddress===this.walletLocalData.publicKey)throw new S.gw;if(r!=null&&!this.enabledTokenIds.includes(r))throw new Error("Error: Token not enabled");const{currencyCode:a}=r==null?this.currencyInfo:this.allTokensMap[r],o=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",u={};for(const y of t.spendTargets){const{nativeAmount:T}=y;T!=null&&(u[a]=(n=u[a])!=null?n:"0",u[a]=(0,p.add)(u[a],T))}for(const[y,T]of Object.entries(u)){const I=(s=this.walletLocalData.totalBalances[y])!=null?s:"0";if(!i&&(0,p.lt)(I,T))throw new S.k5({tokenId:r})}const g=(0,m._r)(a,this.currencyInfo,this.allTokensMap);if(g==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:o,currencyCode:a,denom:g,skipChecks:i}}checkRecipientMinimumBalance(t,e,n){return l(this,null,function*(){if((0,p.gte)(e,this.minimumAddressBalance))return;const s=yield t(n);if((0,p.lt)((0,p.add)(e,s),this.minimumAddressBalance)){const i=this.currencyInfo.denominations.find(a=>a.name===this.currencyInfo.currencyCode);if(i==null)throw new Error("Unknown denom");const r=(0,p.div)(this.minimumAddressBalance,i.multiplier);throw new Error(`Recipient address not activated. A minimum ${r} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return l(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionEvents.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,m.T5)(e.transaction)}`)),this.sendTransactionEvents()})}resyncBlockchain(){return l(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return l(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return l(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return l(this,null,function*(){throw new Error("not implemented")})}}},89089:function(F,M,k){k.d(M,{Z:function(){return p}});function p(S,A,C={}){const{onError:d=()=>{}}=C;let m=!1,L;function E(){L=void 0,v.started&&(m=!0,new Promise(D=>D(S())).catch(d).then(O,O))}function O(){m=!1,v.started&&(L=setTimeout(E,A))}const v={started:!1,setDelay(D){A=D},start(D={}){const{wait:N=!1}=D;v.started=!0,!m&&L==null&&(N?O():E())},stop(){v.started=!1,L!=null&&(clearTimeout(L),L=void 0)}};return v}},96542:function(F,M,k){k.d(M,{m:function(){return K},x:function(){return $}});var p=k(66001),S=k.n(p),A=k(63054),C=k(61160),d=k.n(C),m=k(44276),L=Object.defineProperty,E=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,D=(l,h,c)=>h in l?L(l,h,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[h]=c,N=(l,h)=>{for(var c in h||(h={}))O.call(h,c)&&D(l,c,h[c]);if(E)for(var c of E(h))v.call(h,c)&&D(l,c,h[c]);return l},H=(l,h,c)=>new Promise((w,b)=>{var f=n=>{try{e(c.next(n))}catch(s){b(s)}},t=n=>{try{e(c.throw(n))}catch(s){b(s)}},e=n=>n.done?w(n.value):Promise.resolve(n.value).then(f,t);e((c=c.apply(l,h)).next())});function $(l){return H(this,null,function*(){const{currencyInfo:h,uri:c,networks:w,builtinTokens:b,customTokens:f=[],testPrivateKeys:t}=l;let{currencyCode:e}=l;const n=N({},d()(c,{},!0)),s=c.startsWith(`${h.pluginId}://`);if(n.protocol!=null&&(n.protocol=n.protocol.replace(":","")),n.protocol!=null&&n.protocol!==""&&!w[n.protocol])throw new Error(`Uri protocol '${n.protocol}' is not supported for ${h.pluginId}.`);if(n.host===""&&n.pathname==="")throw new Error("Path and host not found in uri.");const r={publicAddress:n.host!==""?n.host:n.pathname.split("/")[0]},a=n.query.label,o=n.query.message,u=n.query.category;(a!=null||o!=null||u!=null||s)&&(r.metadata={},r.metadata.name=a,r.metadata.notes=o,r.metadata.category=u,r.metadata.gateway=s!=null?s:!1);const g=n.query.amount;if(g!=null&&typeof g=="string"){e==null&&(e=h.currencyCode);const y=(0,m.FQ)(e!=null?e:"",h,f,b);if(y==null)throw new Error("InternalErrorInvalidCurrencyCode");let T=(0,p.mul)(g,y.multiplier);T=(0,p.toFixed)(T,0,0),r.nativeAmount=T,r.currencyCode=e}if(t!=null)try{yield t(c),r.privateKeys=[c],r.publicAddress=void 0}catch{}return{edgeParsedUri:r,parsedUri:n}})}function K(l,h,c){if(l.publicAddress==null)throw new Error("InvalidPublicAddressError");if(c==null&&l.label==null&&l.message==null)return l.publicAddress;{let w="";c!=null&&(w+="amount="+c+"&"),(l.label!=null||l.message!=null)&&(typeof l.label=="string"&&(w+="label="+l.label+"&"),typeof l.message=="string"&&(w+="message="+l.message+"&")),w=w.substr(0,w.length-1);const b={scheme:h,path:l.publicAddress,query:w};return(0,A.lK)(b)}}}}]);
1
+ "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8330],{26277:function(F,M,k){k.d(M,{k:function(){return b}});var p=k(66001),S=k(82671),A=k(89089),C=k(14483),d=k(36856),m=k(44276),L=k(42704);function E(f,t){var e;const{memos:n=[]}=f,{displayName:s,memoOptions:i=[],multipleMemos:r=!1}=t,{memoName:a="memo"}=(e=i[0])!=null?e:{};for(const o of n){const u=i.filter(y=>o.type===y.type);if(u.length<1)throw new Error(`${s} ${a}: cannot be type ${o.type}`);const g=u.map(y=>O(o,y)).find(y=>y!=null);if(g!=null)throw new Error(`${s} ${a}: ${g}`)}if(!r&&n.length>1)throw new Error(`${s} only supports one ${a}`)}function O(f,t){if(t.type==="text"&&t.maxLength!=null&&f.value.length>t.maxLength)return`cannot be longer than ${t.maxLength} characters`;if(t.type==="number"){const e=(0,L.HS)(d.ym)(f.value);if(e==null)return"is not a valid number";if(t.maxValue!=null&&(0,p.gt)(e,t.maxValue))return`cannot be greater than ${t.maxValue}`}if(t.type==="hex"){const e=(0,L.HS)(d.zU)(f.value);if(e==null)return"is not valid hexadecimal";if(t.maxBytes!=null&&e.length>t.maxBytes)return`cannot be longer than ${t.maxBytes} bytes`;if(t.minBytes!=null&&e.length<t.minBytes)return`cannot be shorter than ${t.minBytes} bytes`}}var v=Object.defineProperty,D=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,$=(f,t,e)=>t in f?v(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,K=(f,t)=>{for(var e in t||(t={}))N.call(t,e)&&$(f,e,t[e]);if(D)for(var e of D(t))H.call(t,e)&&$(f,e,t[e]);return f},l=(f,t,e)=>new Promise((n,s)=>{var i=o=>{try{a(e.next(o))}catch(u){s(u)}},r=o=>{try{a(e.throw(o))}catch(u){s(u)}},a=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,r);a((e=e.apply(f,t)).next())});const h=1e4,c=2500,w=3600*24;class b{constructor(t,e,n,s){this.tasks=new Map,this.allTokens=[],this.allTokensMap={},this.builtinTokens={},this.customTokens={},this.enabledTokenIds=[],this.enabledTokens=[];const{builtinTokens:i,currencyInfo:r}=t,{callbacks:a,customTokens:o,enabledTokenIds:u,log:g,walletLocalDisklet:y}=s;this.tools=e,this.log=g,this.warn=(I,x)=>this.log.warn(I+(0,m.Jo)(x)),this.error=(I,x)=>this.log.error(I+(0,m.Jo)(x)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.seenTxCheckpoint=s.seenTxCheckpoint,this.transactionEvents=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=n,this.walletId=n.id,this.currencyInfo=r,this.otherData=void 0,this.minimumAddressBalance="0";const{currencyCode:T}=r;this.transactionList[T]=[],this.txIdMap[T]={},this.txIdList[T]=[],this.builtinTokens=i,this.changeCustomTokensSync(o),this.changeEnabledTokenIdsSync(u),s.userSettings!=null?this.currentSettings=s.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=a,this.walletLocalDisklet=y,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=n.keys.publicKey),this.walletLocalData={blockHeight:0,lastAddressQueryHeight:0,lastTransactionQueryHeight:{},lastTransactionDate:{},publicKey:"",totalBalances:{},lastCheckedTxsDropped:0,numUnconfirmedSpendTxs:0,numTransactions:{},unactivatedTokenIds:[],otherData:void 0},this.log(`Created Wallet Type ${this.walletInfo.type} for Currency Plugin ${this.currencyInfo.pluginId}`),this.checkBalances=(I,x)=>{var U,_;const{nativeAmount:P,parentNetworkFee:B}=I,R=this.currencyInfo.currencyCode,J=x!=null?this.allTokensMap[x].currencyCode:R,W=(U=this.walletLocalData.totalBalances[J])!=null?U:"0",V=R,Q=(_=this.walletLocalData.totalBalances[V])!=null?_:"0";if((0,p.gt)((0,p.abs)(P),W))throw new S.k5({tokenId:x});if(B!=null&&(0,p.gt)(B,Q))throw new S.k5({networkFee:B,tokenId:null})},this.makeEdgeTransactionAmounts=(I,x,U)=>{let _=`-${I}`,P=x,B;return U!=null?(B=P,P="0"):_=(0,p.sub)(_,P),{nativeAmount:_,networkFee:P,parentNetworkFee:B}}}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,p.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const n of t.ourReceiveAddresses)n===this.walletLocalData.publicKey&&(e=!1);return e}isTransactionNew(t){const e=this.getTxCheckpoint(t);return this.seenTxCheckpoint!=null&&e!==this.seenTxCheckpoint?this.selectSeenTxCheckpoint(e,this.seenTxCheckpoint)===e:!1}setOtherData(t){}loadTransactions(){return l(this,null,function*(){var t;if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const e=this.walletLocalDisklet;let n;try{const a=yield e.getText(d._6);n=JSON.parse(a)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield e.setText(d._6,JSON.stringify(this.txIdList))}let s;try{const a=yield e.getText(d.wV);s=JSON.parse(a)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield e.setText(d.wV,JSON.stringify(this.txIdMap))}let i;try{const a=yield e.getText(d.Kw);i=JSON.parse(a)}catch(a){a.code==="ENOENT"||((t=a.message)==null?void 0:t.includes("No such file"))===!0?(this.log("Could not load transactionList file. Failure is ok on new device"),yield e.setText(d.Kw,JSON.stringify(this.transactionList))):this.log.crash(a,{currencyPluginId:this.currencyInfo.pluginId})}let r=!0;for(const a of Object.keys(this.transactionList))if(this.transactionList[a]!=null&&this.transactionList[a].length>0){r=!1;break}if(r){this.transactionList=i!=null?i:this.transactionList,this.txIdList=n!=null?n:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;for(const a of Object.keys(this.transactionList))for(const o of this.transactionList[a])this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.highestSeenCheckpoint,this.getTxCheckpoint(o))}else if(i!=null)for(const a of Object.keys(i))for(const o of i[a])this.addTransaction(a,o);for(const a in this.transactionList)this.walletLocalData.numTransactions[a]=this.transactionList[a].length})}loadEngine(){return l(this,null,function*(){var t;const{walletInfo:e}=this,{currencyCode:n}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const s=this.walletLocalDisklet;try{const i=yield s.getText(d.e1);this.walletLocalData=(0,d.TS)(JSON.parse(i)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,d.TS)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield s.setText(d.e1,JSON.stringify(this.walletLocalData))}catch(r){throw this.error("Error writing to localDataStore. Engine not started: ",r),r}}this.setOtherData((t=this.walletLocalData.otherData)!=null?t:{}),this.walletLocalDataDirty=!(0,m.AP)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[n]=0,this.tokenCheckTransactionsStatus[n]=0,this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback(),this.seenTxCheckpoint==null&&(yield this.loadTransactions(),this.highestSeenCheckpoint==null&&(this.highestSeenCheckpoint="0"))})}findTransaction(t,e){if(this.txIdMap[t]!=null){const n=this.txIdMap[t][e];if(typeof n=="number")return n}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,n){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=n!=null?n:Math.round(Date.now()/1e3));const s=(0,m.Qh)(e.txid),i=this.findTransaction(t,s);let r=!1;if(i===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),r=!0,typeof this.transactionList[t]>"u")this.transactionList[t]=[];else if(this.transactionList[t].length>=c)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0;const a=this.isTransactionNew(e);this.transactionEvents.push({isNew:a,transaction:e}),this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.getTxCheckpoint(e),this.highestSeenCheckpoint),this.warn(`addTransaction new tx: ${e.txid}`)}else{const o=this.transactionList[t][i],{otherParams:u={}}=o,{otherParams:g={}}=e;(o.blockHeight<e.blockHeight||o.blockHeight===0&&e.blockHeight<0||o.blockHeight===e.blockHeight&&(o.networkFee!==e.networkFee||o.nativeAmount!==e.nativeAmount||u.lastSeenTime!==g.lastSeenTime||o.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&o.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,o.date!==e.date&&(r=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,i))}r&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let n=0;for(const s of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,m.Qh)(s.txid)]=n,e.push((0,m.Qh)(s.txid)),n++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>w&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.sendTransactionEvents())}checkDroppedTransactions(t){let e=0;for(const n in this.transactionList)for(let s=0;s<this.transactionList[n].length;s++){const i=this.transactionList[n][s];if(i.blockHeight===0){const{otherParams:r={}}=i,a=r.lastSeenTime;t-a>w?(i.blockHeight=-1,i.nativeAmount="0",this.transactionEvents.push({isNew:!1,transaction:i})):this.isSpendTx(i)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];if(this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),n==null||!(0,p.eq)(e,n)){this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`);const s=(0,C.jE)(t,this.currencyInfo.currencyCode,this.allTokensMap);if(s===void 0)return;this.currencyEngineCallbacks.onTokenBalanceChanged(s,e)}this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,n){this.transactionList[t][n]=e,this.transactionListDirty=!0,this.transactionEvents.push({isNew:!1,transaction:e}),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return l(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let n=JSON.stringify(this.transactionList);e.push(t.setText(d.Kw,n).catch(s=>{this.error("Error saving transactionList ",s)})),n=JSON.stringify(this.txIdList),e.push(t.setText(d._6,n).catch(s=>{this.error("Error saving txIdList ",s)})),n=JSON.stringify(this.txIdMap),e.push(t.setText(d.wV,n).catch(s=>{this.error("Error saving txIdMap ",s)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const n=JSON.stringify(this.walletLocalData);yield t.setText(d.e1,n).then(()=>{this.walletLocalDataDirty=!1}).catch(s=>{this.error("Error saving walletLocalData ",s)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{const n=(0,C.jE)(e,this.currencyInfo.currencyCode,this.allTokensMap);if(n===void 0)continue;this.currencyEngineCallbacks.onTokenBalanceChanged(n,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(n){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,n)}}doInitialUnactivatedTokenIdsCallback(){try{this.walletLocalData.unactivatedTokenIds!=null&&this.walletLocalData.unactivatedTokenIds.length>0&&this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds)}catch(t){this.error("doInitialUnactivatedTokenIdsCallback Error",t)}}addToLoop(t,e,n=()=>l(this,null,function*(){yield this[t]()})){if(this.tasks.get(t)!=null)return;const s=r=>{this.log(t+": "+String(r))},i=(0,A.Z)(n,e,{onError:s});this.tasks.set(t,i),this.engineOn&&i.start()}removeFromLoop(t){var e;(e=this.tasks.get(t))==null||e.stop(),this.tasks.delete(t)}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}getTxCheckpoint(t){return t.blockHeight.toString()}selectSeenTxCheckpoint(t,e){return t==null?e:e==null||parseInt(t)>parseInt(e)?t:e}sendTransactionEvents(){this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[],this.updateSeenTxCheckpoint())}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const n=this.enabledTokens,s=1/n.length;let i=0,r=0;for(const a of n){const o=(t=this.tokenCheckBalanceStatus[a])!=null?t:0,u=(e=this.tokenCheckTransactionsStatus[a])!=null?e:0;i+=(o+u)/2*s,o===1&&u===1&&r++}r===n.length&&(i=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${i}`),this.currencyEngineCallbacks.onAddressesChecked(i),this.addressesChecked&&this.updateSeenTxCheckpoint()}syncTheWalletLikeLifeDependsOnIt(){this.addressesChecked=!0,this.currencyEngineCallbacks.onAddressesChecked(1)}updateSeenTxCheckpoint(){const t=this.selectSeenTxCheckpoint(this.highestSeenCheckpoint,this.seenTxCheckpoint);t!=null&&t!==this.seenTxCheckpoint&&(this.seenTxCheckpoint=t,this.currencyEngineCallbacks.onSeenTxCheckpoint(this.seenTxCheckpoint))}clearBlockchainCache(){return l(this,null,function*(){this.walletLocalData=(0,d.TS)({publicKey:this.walletLocalData.publicKey}),this.walletLocalDataDirty=!0,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.transactionList={},this.txIdList={},this.txIdMap={},this.transactionListDirty=!0,this.setOtherData({}),yield this.saveWalletLoop()})}startEngine(){return l(this,null,function*(){this.addToLoop("saveWalletLoop",h),this.engineOn=!0;for(const[,t]of this.tasks)t.start()})}killEngine(){return l(this,null,function*(){this.engineOn=!1;for(const[,t]of this.tasks)t.stop()})}changeUserSettings(t){return l(this,null,function*(){this.currentSettings=t})}getBlockHeight(){return this.walletLocalData.blockHeight}changeCustomTokensSync(t){this.customTokens={};for(const e of Object.keys(t)){const n=t[e];try{(0,C.k9)(n)}catch{this.log.warn(`Dropping custom token "${n.currencyCode}" / ${e}`);continue}this.customTokens[e]=n}this.allTokensMap=K(K({},this.customTokens),this.builtinTokens),this.allTokens=(0,C.yQ)(this.allTokensMap)}changeCustomTokens(t){return l(this,null,function*(){this.changeCustomTokensSync(t)})}changeEnabledTokenIdsSync(t){const{currencyCode:e}=this.currencyInfo,n=new Set,s=new Set;for(const i of t){const r=this.allTokensMap[i];r!=null&&(n.add(r.currencyCode),s.add(i))}this.enabledTokens=[...n,e],this.enabledTokenIds=[...s]}changeEnabledTokenIds(t){return l(this,null,function*(){this.changeEnabledTokenIdsSync(t)})}getBalance(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e],s=this.walletLocalData.totalBalances[n];return s==null?"0":s}getNumTransactions(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e];return this.walletLocalData.numTransactions[n]==null?0:this.walletLocalData.numTransactions[n]}getTransactions(t){return l(this,null,function*(){const{startDate:e,endDate:n,tokenId:s}=t,{currencyCode:i}=s==null?this.currencyInfo:this.allTokensMap[s];return yield this.loadTransactions(),this.transactionList[i]==null?[]:this.transactionList[i].filter(a=>new Date(a.date)>=(e!=null?e:new Date(0))&&new Date(a.date)<=(n!=null?n:new Date))})}getFreshAddress(t){return l(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return l(this,null,function*(){})}isAddressUsed(t){return l(this,null,function*(){return!1})}dumpData(){return l(this,null,function*(){return{walletId:this.walletId.split(" - ")[0],walletType:this.walletInfo.type,data:{pluginType:{pluginId:this.currencyInfo.pluginId},walletLocalData:this.walletLocalData}}})}makeSpendCheck(t){var e,n,s;const{skipChecks:i=!1,tokenId:r}=t;E(t,this.currencyInfo);for(const y of t.spendTargets)if(!i&&y.publicAddress===this.walletLocalData.publicKey)throw new S.gw;if(r!=null&&!this.enabledTokenIds.includes(r))throw new Error("Error: Token not enabled");const{currencyCode:a}=r==null?this.currencyInfo:this.allTokensMap[r],o=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",u={};for(const y of t.spendTargets){const{nativeAmount:T}=y;T!=null&&(u[a]=(n=u[a])!=null?n:"0",u[a]=(0,p.add)(u[a],T))}for(const[y,T]of Object.entries(u)){const I=(s=this.walletLocalData.totalBalances[y])!=null?s:"0";if(!i&&(0,p.lt)(I,T))throw new S.k5({tokenId:r})}const g=(0,m._r)(a,this.currencyInfo,this.allTokensMap);if(g==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:o,currencyCode:a,denom:g,skipChecks:i}}checkRecipientMinimumBalance(t,e,n){return l(this,null,function*(){if((0,p.gte)(e,this.minimumAddressBalance))return;const s=yield t(n);if((0,p.lt)((0,p.add)(e,s),this.minimumAddressBalance)){const i=this.currencyInfo.denominations.find(a=>a.name===this.currencyInfo.currencyCode);if(i==null)throw new Error("Unknown denom");const r=(0,p.div)(this.minimumAddressBalance,i.multiplier);throw new Error(`Recipient address not activated. A minimum ${r} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return l(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionEvents.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,m.T5)(e.transaction)}`)),this.sendTransactionEvents()})}resyncBlockchain(){return l(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return l(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return l(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return l(this,null,function*(){throw new Error("not implemented")})}}},89089:function(F,M,k){k.d(M,{Z:function(){return p}});function p(S,A,C={}){const{onError:d=()=>{}}=C;let m=!1,L;function E(){L=void 0,v.started&&(m=!0,new Promise(D=>D(S())).catch(d).then(O,O))}function O(){m=!1,v.started&&(L=setTimeout(E,A))}const v={started:!1,setDelay(D){A=D},start(D={}){const{wait:N=!1}=D;v.started=!0,!m&&L==null&&(N?O():E())},stop(){v.started=!1,L!=null&&(clearTimeout(L),L=void 0)}};return v}},96542:function(F,M,k){k.d(M,{m:function(){return K},x:function(){return $}});var p=k(66001),S=k.n(p),A=k(63054),C=k(61160),d=k.n(C),m=k(44276),L=Object.defineProperty,E=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,D=(l,h,c)=>h in l?L(l,h,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[h]=c,N=(l,h)=>{for(var c in h||(h={}))O.call(h,c)&&D(l,c,h[c]);if(E)for(var c of E(h))v.call(h,c)&&D(l,c,h[c]);return l},H=(l,h,c)=>new Promise((w,b)=>{var f=n=>{try{e(c.next(n))}catch(s){b(s)}},t=n=>{try{e(c.throw(n))}catch(s){b(s)}},e=n=>n.done?w(n.value):Promise.resolve(n.value).then(f,t);e((c=c.apply(l,h)).next())});function $(l){return H(this,null,function*(){const{currencyInfo:h,uri:c,networks:w,builtinTokens:b,customTokens:f=[],testPrivateKeys:t}=l;let{currencyCode:e}=l;const n=N({},d()(c,{},!0)),s=c.startsWith(`${h.pluginId}://`);if(n.protocol!=null&&(n.protocol=n.protocol.replace(":","")),n.protocol!=null&&n.protocol!==""&&!w[n.protocol])throw new Error(`Uri protocol '${n.protocol}' is not supported for ${h.pluginId}.`);if(n.host===""&&n.pathname==="")throw new Error("Path and host not found in uri.");const r={publicAddress:n.host!==""?n.host:n.pathname.split("/")[0]},a=n.query.label,o=n.query.message,u=n.query.category;(a!=null||o!=null||u!=null||s)&&(r.metadata={},r.metadata.name=a,r.metadata.notes=o,r.metadata.category=u,r.metadata.gateway=s!=null?s:!1);const g=n.query.amount;if(g!=null&&typeof g=="string"){e==null&&(e=h.currencyCode);const y=(0,m.FQ)(e!=null?e:"",h,f,b);if(y==null)throw new Error("InternalErrorInvalidCurrencyCode");let T=(0,p.mul)(g,y.multiplier);T=(0,p.toFixed)(T,0,0),r.nativeAmount=T,r.currencyCode=e}if(t!=null)try{yield t(c),r.privateKeys=[c],r.publicAddress=void 0}catch{}return{edgeParsedUri:r,parsedUri:n}})}function K(l,h,c){if(l.publicAddress==null)throw new Error("InvalidPublicAddressError");if(c==null&&l.label==null&&l.message==null)return l.publicAddress;{let w="";c!=null&&(w+="amount="+c+"&"),(l.label!=null||l.message!=null)&&(typeof l.label=="string"&&(w+="label="+l.label+"&"),typeof l.message=="string"&&(w+="message="+l.message+"&")),w=w.substr(0,w.length-1);const b={scheme:h,path:l.publicAddress,query:w};return(0,A.lK)(b)}}}}]);