edge-currency-accountbased 2.9.2 → 2.9.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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4843],{79014:function(W,H,u){"use strict";u.d(H,{Q:function(){return L},k:function(){return b}});var m=u(77591),U=u.n(m),x=u(24350),O=u(84564),B=u.n(O),M=u(76714),g=Object.defineProperty,z=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,A=(o,p,y)=>p in o?g(o,p,{enumerable:!0,configurable:!0,writable:!0,value:y}):o[p]=y,C=(o,p)=>{for(var y in p||(p={}))R.call(p,y)&&A(o,y,p[y]);if(z)for(var y of z(p))K.call(p,y)&&A(o,y,p[y]);return o};function b(o,p,y,w,D=[]){const d=C({},B()(p,{},!0)),T=p.startsWith(`${o.pluginId}://`);if(d.protocol!=null&&(d.protocol=d.protocol.replace(":","")),d.protocol!=null&&d.protocol!==""&&!y[d.protocol])throw new Error(`Uri protocol '${d.protocol}' is not supported for ${o.pluginId}.`);if(d.host===""&&d.pathname==="")throw new Error("Path and host not found in uri.");const k={publicAddress:d.host!==""?d.host:d.pathname.split("/")[0]},P=d.query.label,f=d.query.message,I=d.query.category;(P!=null||f!=null||I!=null||T)&&(k.metadata={},k.metadata.name=P,k.metadata.notes=f,k.metadata.category=I,k.metadata.gateway=T!=null?T:!1);const S=d.query.amount;if(S!=null&&typeof S=="string"){w==null&&(w=o.currencyCode);const v=(0,M.Qs)(w!=null?w:"",o,D);if(v==null)throw new Error("InternalErrorInvalidCurrencyCode");let E=(0,m.mul)(S,v.multiplier);E=(0,m.toFixed)(E,0,0),k.nativeAmount=E,k.currencyCode=w}return{edgeParsedUri:k,parsedUri:d}}function L(o,p,y){if(o.publicAddress==null)throw new Error("InvalidPublicAddressError");if(y==null&&o.label==null&&o.message==null)return o.publicAddress;{let w="";y!=null&&(w+="amount="+y+"&"),(o.label!=null||o.message!=null)&&(typeof o.label=="string"&&(w+="label="+o.label+"&"),typeof o.message=="string"&&(w+="message="+o.message+"&")),w=w.substr(0,w.length-1);const D={scheme:p,path:o.publicAddress,query:w};return(0,x.qC)(D)}}},80504:function(W,H,u){"use strict";u.r(H),u.d(H,{PiratechainTools:function(){return E},makeCurrencyEngine:function(){return S},makeCurrencyTools:function(){return F}});var m=u(77591),U=u(2153),x=u(48764),O=u(62177),B=u(79014),M=u(76714),g=u(82448);const z=(0,g.su)({first:g.mH,last:g.mH}),R=(0,g.su)({alias:(0,g.Vk)(g.XC),blockRange:(0,g.Vk)(z,()=>({first:0,last:0}))}),K=(0,g.su)({birthdayHeight:g.mH,publicKey:g.XC}),A=(0,O.jd)(K),C=a=>{const t=(0,g.su)({[`${a}Mnemonic`]:g.XC,[`${a}BirthdayHeight`]:g.mH});return(0,g.W1)(e=>{const n=t(e);return{mnemonic:n[`${a}Mnemonic`],birthdayHeight:n[`${a}BirthdayHeight`]}},e=>({[`${a}Mnemonic`]:e.mnemonic,[`${a}BirthdayHeight`]:e.birthdayHeight}))};var b=u(94935),L=u(84650),o=u(72681),p=Object.defineProperty,y=Object.getOwnPropertySymbols,w=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,T=Reflect.get,$=(a,t,e)=>t in a?p(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,k=(a,t)=>{for(var e in t||(t={}))D.call(t,e)&&$(a,e,t[e]);if(y)for(var e of y(t))d.call(t,e)&&$(a,e,t[e]);return a},P=(a,t,e)=>T(w(a),e,t),f=(a,t,e)=>new Promise((n,r)=>{var l=s=>{try{c(e.next(s))}catch(h){r(h)}},i=s=>{try{c(e.throw(s))}catch(h){r(h)}},c=s=>s.done?n(s.value):Promise.resolve(s.value).then(l,i);c((e=e.apply(a,t)).next())});class I extends L.P{constructor(t,e,n,r,l){super(t,e,n,r);const{networkInfo:i}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=i,this.makeSynchronizer=l,this.queryMutex=!1,this.started=!1}setOtherData(t){this.otherData=R(t)}initData(){const{birthdayHeight:t}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio=0}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>f(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>f(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})))}queryAll(){return f(this,null,function*(){if(!this.queryMutex){this.queryMutex=!0;try{yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()}catch{}this.queryMutex=!1}})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){const r=e*.99,l=e*.8;this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=r/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=l/100;const i=(r+l)/2;i!==this.progressRatio&&(Math.abs(i-this.progressRatio)>.1||i===1)&&(this.progressRatio=i,this.log.warn(`Scan and download progress: ${Math.floor(i)}%`),this.updateOnAddressesChecked())}}startEngine(){return f(this,null,function*(){this.engineOn=!0,this.started=!0,yield P(I.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return f(this,null,function*(){if(!(!this.isSynced()||this.synchronizer==null))try{const t=yield this.synchronizer.getBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return f(this,null,function*(){if(this.synchronizer!=null)try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,m.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r=t.memos.filter(i=>i!=="").map(i=>({memoName:"memo",type:"text",value:i})),l={blockHeight:t.minedHeight,currencyCode:this.currencyInfo.currencyCode,date:t.blockTimeInSeconds,isSend:e.startsWith("-"),memos:r,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,otherParams:{},ourReceiveAddresses:n,signedTx:"",txid:t.rawTransactionId,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,l)}syncNetwork(t){return f(this,null,function*(){if(!this.started)return 1e3;const e=C(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;return this.initializer=k({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:this.walletId},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return f(this,null,function*(){var t;this.started=!1,this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0),yield(t=this.synchronizer)==null?void 0:t.stop(),yield P(I.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return f(this,null,function*(){yield P(I.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return f(this,null,function*(){var t;yield P(I.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),(t=this.synchronizer)==null||t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.synchronizerStatus="SYNCING"})}getMaxSpendable(){return f(this,null,function*(){const t=(0,m.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,m.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return f(this,null,function*(){var e;if(t=(0,o.s)(t,this.currencyInfo),!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:l=[]}=n,i=n.spendTargets[0],{publicAddress:c,nativeAmount:s}=i;if(c==null)throw new Error("makeSpend Missing publicAddress");if(s==null)throw new b.$D;if((0,m.eq)(s,"0"))throw new b.$D;const h=(0,m.add)(s,this.networkInfo.defaultNetworkFee);if((0,m.gt)(h,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,m.gt)(h,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const N=(0,m.mul)(h,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:l,nativeAmount:N,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}})}signTx(t){return f(this,null,function*(){return t})}broadcastTx(t,e){return f(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,l=C(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const i=((n=r[0])==null?void 0:n.type)==="text"?r[0].value:"",c=t.spendTargets[0],s={zatoshi:(0,m.sub)((0,m.abs)(t.nativeAmount),t.networkFee),toAddress:c.publicAddress,memo:i,fromAccountIndex:0,mnemonicSeed:l.mnemonic};try{const h=yield this.synchronizer.sendToAddress(s);t.txid=h.txId,t.signedTx=h.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
-
${(0,
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4843],{79014:function(F,S,c){"use strict";c.d(S,{Q:function(){return z},k:function(){return b}});var w=c(77591),x=c.n(w),R=c(24350),T=c(84564),H=c.n(T),O=c(76714),g=Object.defineProperty,B=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,E=(o,f,p)=>f in o?g(o,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):o[f]=p,C=(o,f)=>{for(var p in f||(f={}))L.call(f,p)&&E(o,p,f[p]);if(B)for(var p of B(f))M.call(f,p)&&E(o,p,f[p]);return o};function b(o,f,p,m,A=[]){const d=C({},H()(f,{},!0)),D=f.startsWith(`${o.pluginId}://`);if(d.protocol!=null&&(d.protocol=d.protocol.replace(":","")),d.protocol!=null&&d.protocol!==""&&!p[d.protocol])throw new Error(`Uri protocol '${d.protocol}' is not supported for ${o.pluginId}.`);if(d.host===""&&d.pathname==="")throw new Error("Path and host not found in uri.");const I={publicAddress:d.host!==""?d.host:d.pathname.split("/")[0]},U=d.query.label,P=d.query.message,y=d.query.category;(U!=null||P!=null||y!=null||D)&&(I.metadata={},I.metadata.name=U,I.metadata.notes=P,I.metadata.category=y,I.metadata.gateway=D!=null?D:!1);const k=d.query.amount;if(k!=null&&typeof k=="string"){m==null&&(m=o.currencyCode);const K=(0,O.Qs)(m!=null?m:"",o,A);if(K==null)throw new Error("InternalErrorInvalidCurrencyCode");let v=(0,w.mul)(k,K.multiplier);v=(0,w.toFixed)(v,0,0),I.nativeAmount=v,I.currencyCode=m}return{edgeParsedUri:I,parsedUri:d}}function z(o,f,p){if(o.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&o.label==null&&o.message==null)return o.publicAddress;{let m="";p!=null&&(m+="amount="+p+"&"),(o.label!=null||o.message!=null)&&(typeof o.label=="string"&&(m+="label="+o.label+"&"),typeof o.message=="string"&&(m+="message="+o.message+"&")),m=m.substr(0,m.length-1);const A={scheme:f,path:o.publicAddress,query:m};return(0,R.qC)(A)}}},80504:function(F,S,c){"use strict";c.r(S),c.d(S,{PiratechainTools:function(){return W},makeCurrencyEngine:function(){return K},makeCurrencyTools:function(){return V}});var w=c(77591),x=c(2153),R=c(48764),T=c(62177),H=c(79014),O=c(76714),g=c(82448);const B=(0,g.su)({first:g.mH,last:g.mH}),L=(0,g.su)({alias:(0,g.Vk)(g.XC),blockRange:(0,g.Vk)(B,()=>({first:0,last:0}))}),M=(0,g.su)({birthdayHeight:g.mH,publicKey:g.XC}),E=(0,T.jd)(M),C=a=>{const t=(0,g.su)({[`${a}Mnemonic`]:g.XC,[`${a}BirthdayHeight`]:g.mH});return(0,g.W1)(e=>{const n=t(e);return{mnemonic:n[`${a}Mnemonic`],birthdayHeight:n[`${a}BirthdayHeight`]}},e=>({[`${a}Mnemonic`]:e.mnemonic,[`${a}BirthdayHeight`]:e.birthdayHeight}))};var b=c(94935),z=c(35620),o=c(84650),f=c(72681),p=Object.defineProperty,m=Object.getOwnPropertySymbols,A=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,$=Reflect.get,I=(a,t,e)=>t in a?p(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,U=(a,t)=>{for(var e in t||(t={}))d.call(t,e)&&I(a,e,t[e]);if(m)for(var e of m(t))D.call(t,e)&&I(a,e,t[e]);return a},P=(a,t,e)=>$(A(a),e,t),y=(a,t,e)=>new Promise((n,r)=>{var l=s=>{try{h(e.next(s))}catch(u){r(u)}},i=s=>{try{h(e.throw(s))}catch(u){r(u)}},h=s=>s.done?n(s.value):Promise.resolve(s.value).then(l,i);h((e=e.apply(a,t)).next())});class k extends o.P{constructor(t,e,n,r,l){super(t,e,n,r);const{networkInfo:i}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=i,this.makeSynchronizer=l,this.queryMutex=!1,this.started=!1}setOtherData(t){this.otherData=L(t)}initData(){const{birthdayHeight:t}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio=0}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>y(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>y(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})))}queryAll(){return y(this,null,function*(){if(!this.queryMutex){this.queryMutex=!0;try{yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()}catch{}this.queryMutex=!1}})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){const r=e*.99,l=e*.8;this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=r/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=l/100;const i=(r+l)/2;i!==this.progressRatio&&(Math.abs(i-this.progressRatio)>.1||i===1)&&(this.progressRatio=i,this.log.warn(`Scan and download progress: ${Math.floor(i)}%`),this.updateOnAddressesChecked())}}startEngine(){return y(this,null,function*(){this.engineOn=!0,this.started=!0,yield P(k.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return y(this,null,function*(){if(!(!this.isSynced()||this.synchronizer==null))try{const t=yield this.synchronizer.getBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return y(this,null,function*(){if(this.synchronizer!=null)try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,w.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r=t.memos.filter(i=>i!=="").map(i=>({memoName:"memo",type:"text",value:i})),l={blockHeight:t.minedHeight,currencyCode:this.currencyInfo.currencyCode,date:t.blockTimeInSeconds,isSend:e.startsWith("-"),memos:r,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,otherParams:{},ourReceiveAddresses:n,signedTx:"",txid:t.rawTransactionId,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,l)}syncNetwork(t){return y(this,null,function*(){if(!this.started)return 1e3;const e=C(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;return this.initializer=U({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:z.YU.stringify(z.US.parse(this.walletId))},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return y(this,null,function*(){var t;this.started=!1,this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0),yield(t=this.synchronizer)==null?void 0:t.stop(),yield P(k.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return y(this,null,function*(){yield P(k.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return y(this,null,function*(){var t;yield P(k.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),(t=this.synchronizer)==null||t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.synchronizerStatus="SYNCING"})}getMaxSpendable(){return y(this,null,function*(){const t=(0,w.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,w.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return y(this,null,function*(){var e;if(t=(0,f.s)(t,this.currencyInfo),!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:l=[]}=n,i=n.spendTargets[0],{publicAddress:h,nativeAmount:s}=i;if(h==null)throw new Error("makeSpend Missing publicAddress");if(s==null)throw new b.$D;if((0,w.eq)(s,"0"))throw new b.$D;const u=(0,w.add)(s,this.networkInfo.defaultNetworkFee);if((0,w.gt)(u,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,w.gt)(u,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const N=(0,w.mul)(u,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:l,nativeAmount:N,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}})}signTx(t){return y(this,null,function*(){return t})}broadcastTx(t,e){return y(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,l=C(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const i=((n=r[0])==null?void 0:n.type)==="text"?r[0].value:"",h=t.spendTargets[0],s={zatoshi:(0,w.sub)((0,w.abs)(t.nativeAmount),t.networkFee),toAddress:h.publicAddress,memo:i,fromAccountIndex:0,mnemonicSeed:l.mnemonic};try{const u=yield this.synchronizer.sendToAddress(s);t.txid=u.txId,t.signedTx=u.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,O.oX)(t)}`)}catch(u){throw this.warn("FAILURE broadcastTx failed: ",u),u}return t})}getFreshAddress(){return y(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");return{publicAddress:(yield this.synchronizer.deriveUnifiedAddress()).saplingAddress}})}}function K(a,t,e,n){return y(this,null,function*(){const r=E(e),{makeSynchronizer:l}=a.nativeIo["edge-currency-accountbased"].piratechain,i=new k(a,t,r,n,l);return yield i.loadEngine(),i})}var v=(a,t,e)=>new Promise((n,r)=>{var l=s=>{try{h(e.next(s))}catch(u){r(u)}},i=s=>{try{h(e.throw(s))}catch(u){r(u)}},h=s=>s.done?n(s.value):Promise.resolve(s.value).then(l,i);h((e=e.apply(a,t)).next())});class W{constructor(t){const{builtinTokens:e,currencyInfo:n,io:r,networkInfo:l}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=r,this.networkInfo=l;const i=t.nativeIo["edge-currency-accountbased"];if(i==null)throw new Error("Need opts");const{Tools:h}=i.piratechain;this.nativeTools=h}getDisplayPrivateKey(t){return v(this,null,function*(){const{pluginId:e}=this.currencyInfo;return C(e)(t.keys).mnemonic})}getDisplayPublicKey(t){return v(this,null,function*(){const{keys:e}=E(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return v(this,null,function*(){try{return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)}catch{return this.networkInfo.defaultBirthday}})}isValidAddress(t){return v(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return v(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo;if(!(0,x.validateMnemonic)(e))throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const i=yield this.getNewWalletBirthdayBlockheight();let h=i;const{birthdayHeight:s}=n;if(s!=null){(0,T.jD)(s);const u=parseInt(s);if(u>i)throw new Error("InvalidBirthdayHeight");h=u}return{[`${r}Mnemonic`]:e,[`${r}BirthdayHeight`]:h}})}createPrivateKey(t){return v(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=R.Buffer.from(this.io.random(32)).toString("hex"),n=(0,x.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return v(this,null,function*(){try{return M(t),!0}catch{return!1}})}derivePublicKey(t){return v(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=C(e)(t.keys);if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const r=n.mnemonic;if(typeof r!="string")throw new Error("InvalidMnemonic");const l=yield this.nativeTools.deriveViewingKey(r,this.networkInfo.rpcNode.networkName);return{birthdayHeight:n.birthdayHeight,publicKey:l}})}parseUri(t,e,n){return v(this,null,function*(){const{pluginId:r}=this.currencyInfo,l={[r]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:h}}=(0,H.k)(this.currencyInfo,t,l,e!=null?e:this.currencyInfo.currencyCode,n);if(h==null||!(yield this.isValidAddress(h)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t){return v(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:l,currencyCode:i,publicAddress:h}=e;if(!(yield this.isValidAddress(h)))throw new Error("InvalidPublicAddressError");let s;if(l!=null){const N=(0,O.Qs)(i!=null?i:this.currencyInfo.currencyCode,this.currencyInfo,n);if(N==null)throw new Error("InternalErrorInvalidCurrencyCode");s=(0,w.div)(l,N.multiplier,18)}return(0,H.Q)(e,`${r}`,s)})}}function V(a){return v(this,null,function*(){return new W(a)})}},52361:function(){},94616:function(){}}]);
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _types = require('edge-core-js/types');
|
|
14
|
+
var _rfc4648 = require('rfc4648');
|
|
14
15
|
|
|
15
16
|
var _CurrencyEngine = require('../common/CurrencyEngine');
|
|
16
17
|
|
|
@@ -288,7 +289,7 @@ var _piratechainTypes = require('./piratechainTypes');
|
|
|
288
289
|
this.initializer = {
|
|
289
290
|
mnemonicSeed: piratechainPrivateKeys.mnemonic,
|
|
290
291
|
birthdayHeight: piratechainPrivateKeys.birthdayHeight,
|
|
291
|
-
alias: this.walletId,
|
|
292
|
+
alias: _rfc4648.base16.stringify(_rfc4648.base64.parse(this.walletId)),
|
|
292
293
|
...rpcNode
|
|
293
294
|
}
|
|
294
295
|
|