edge-currency-accountbased 4.24.6 → 4.25.0

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.25.0 (2024-09-25)
6
+
7
+ - changed: (Zcash) Replace `sendToAddress` with `createTransfer`
8
+ - changed: Upgrade react-native-zcash to v0.9.0
9
+
5
10
  ## 4.24.6 (2024-09-20)
6
11
 
7
12
  - fixed: Update some MATIC special cases to POL
@@ -1,6 +1,6 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[6478],{36823:function(X,z,u){"use strict";u.r(z),u.d(z,{ZcashTools:function(){return B},makeCurrencyEngine:function(){return V},makeCurrencyTools:function(){return Q},updateInfoPayload:function(){return J}});var d=u(66001),D=u(90749),N=u(48287),U=u(36856),C=u(96542),A=u(44276),p=u(175),I=u(82671),P=u(65828),Z=u(26277),K=Object.defineProperty,x=Object.getOwnPropertySymbols,F=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,R=Reflect.get,O=(o,t,e)=>t in o?K(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,$=(o,t)=>{for(var e in t||(t={}))L.call(t,e)&&O(o,e,t[e]);if(x)for(var e of x(t))M.call(t,e)&&O(o,e,t[e]);return o},b=(o,t,e)=>R(F(o),e,t),c=(o,t,e)=>new Promise((n,i)=>{var r=s=>{try{l(e.next(s))}catch(h){i(h)}},a=s=>{try{l(e.throw(s))}catch(h){i(h)}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,a);l((e=e.apply(o,t)).next())});const S="autoshield";class m extends Z.k{constructor(t,e,n,i,r){super(t,e,n,i);const{networkInfo:a}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=a,this.makeSynchronizer=r,this.balances={transparentAvailableZatoshi:"0",transparentTotalZatoshi:"0",saplingAvailableZatoshi:"0",saplingTotalZatoshi:"0",orchardAvailableZatoshi:"0",orchardTotalZatoshi:"0"},this.autoshielding={createAutoshieldTx:!1,threshold:(0,d.mul)(this.networkInfo.defaultNetworkFee,"2")}}setOtherData(t){this.otherData=(0,p.fS)(t)}initData(){this.otherData.isSdkInitializedOnDisk=!0,this.walletLocalDataDirty=!0,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio={seenFirstUpdate:!1,percent:0,lastUpdate:0}}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>c(this,null,function*(){const{scanProgress:e,networkBlockHeight:n}=t;this.onUpdateBlockHeight(n),this.onUpdateProgress(e),yield this.checkAutoshielding()})),this.synchronizer.on("statusChanged",t=>c(this,null,function*(){this.synchronizerStatus=t.name})),this.synchronizer.on("balanceChanged",t=>c(this,null,function*(){const{transparentAvailableZatoshi:e,transparentTotalZatoshi:n,saplingAvailableZatoshi:i,saplingTotalZatoshi:r,orchardAvailableZatoshi:a,orchardTotalZatoshi:l}=t;this.availableZatoshi=(0,d.add)(i,a),this.balances={transparentAvailableZatoshi:e,transparentTotalZatoshi:n,saplingAvailableZatoshi:i,saplingTotalZatoshi:r,orchardAvailableZatoshi:a,orchardTotalZatoshi:l};const s=(0,d.add)((0,d.add)(n,r),l);this.updateBalance(this.currencyInfo.currencyCode,s),yield this.checkAutoshielding()})),this.synchronizer.on("transactionsChanged",t=>c(this,null,function*(){const{transactions:e}=t;e.forEach(n=>{n.rawTransactionId===this.autoshielding.txid&&n.minedHeight>0&&(this.autoshielding.txid=void 0,this.autoshielding.createAutoshieldTx=!1),this.processTransaction(n)}),this.onUpdateTransactions()})),this.synchronizer.on("error",t=>c(this,null,function*(){this.log.warn(`Synchronizer error: ${t.message}`),t.level==="critical"&&(yield this.killEngine(),yield this.startEngine())})))}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){!this.progressRatio.seenFirstUpdate&&(this.progressRatio.seenFirstUpdate=!0,t!==100)||(this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=t/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=t/100,t>this.progressRatio.percent&&(t===100||Date.now()-this.progressRatio.lastUpdate>1e3)&&(this.progressRatio.percent=t,this.progressRatio.lastUpdate=Date.now(),this.log.warn(`Scan and download progress: ${Math.floor(t)}%`),this.updateOnAddressesChecked()))}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),(n==null||!(0,d.eq)(e,n))&&(this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`),this.currencyEngineCallbacks.onBalanceChanged(t,e))}startEngine(){return c(this,null,function*(){this.engineOn=!0,yield b(m.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}processTransaction(t){var e;const{rawTransactionId:n,raw:i,blockTimeInSeconds:r,minedHeight:a,value:l,fee:s,toAddress:h,memos:g}=t;let f=l;const v=s!=null?s:this.networkInfo.defaultNetworkFee;h!=null&&(f=`-${(0,d.add)(f,v)}`);const w=g.filter(T=>T!=="").map(T=>({memoName:"memo",type:"text",value:T}));this.otherData.missingAndroidShieldedMemosHack.includes(n)&&w.length===0&&w.push({memoName:"memo",type:"text",value:S}),((e=w[0])==null?void 0:e.value)===S&&(f=`-${v}`);const k=a===0?Math.max(r,Date.now()/1e3):r,E={blockHeight:a,currencyCode:this.currencyInfo.currencyCode,date:k,isSend:f.startsWith("-"),memos:w,nativeAmount:f,networkFee:v,otherParams:{},ourReceiveAddresses:[],signedTx:i!=null?i:"",tokenId:null,txid:n,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,E)}checkAutoshielding(){return c(this,null,function*(){this.isSynced()&&!this.autoshielding.createAutoshieldTx&&(0,d.gt)(this.balances.transparentAvailableZatoshi,this.autoshielding.threshold)&&(this.autoshielding.createAutoshieldTx=!0,yield this.restartSyncNetwork())})}syncNetwork(t){return c(this,null,function*(){if(!this.engineOn)return 1e3;const e=(0,p.f9)(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys);if(this.synchronizer==null){const{rpcNode:n}=this.networkInfo;this.initializer=$({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:P.xn.stringify(P.K3.parse(this.walletId)),newWallet:!this.otherData.isSdkInitializedOnDisk},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions()}return this.synchronizer!=null&&this.autoshielding.createAutoshieldTx?yield new Promise(n=>{var i;this.log.warn("Autoshield transaction broadcasting..."),(i=this.synchronizer)==null||i.shieldFunds({seed:e.mnemonic,memo:S,threshold:this.autoshielding.threshold}).then(r=>{this.log.warn("Autoshield success",r.rawTransactionId),r.blockTimeInSeconds=Date.now()/1e3,this.autoshielding.txid=r.rawTransactionId,this.otherData.missingAndroidShieldedMemosHack.push(r.rawTransactionId),this.walletLocalDataDirty=!0,this.processTransaction(r),this.onUpdateTransactions()}).catch(r=>{this.autoshielding.createAutoshieldTx=!1,this.log.error("Autoshield failed: ",r)}).finally(()=>{this.stopSyncing=n})}):yield new Promise(n=>{this.stopSyncing=n})})}killEngine(){return c(this,null,function*(){var t;yield b(m.prototype,this,"killEngine").call(this),yield this.restartSyncNetwork(),yield(t=this.synchronizer)==null?void 0:t.stop(),this.synchronizer=void 0})}restartSyncNetwork(){return c(this,null,function*(){this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0)})}clearBlockchainCache(){return c(this,null,function*(){yield b(m.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return c(this,null,function*(){var t;yield b(m.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),yield(t=this.synchronizer)==null?void 0:t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.synchronizerStatus="SYNCING"})}getMaxSpendable(t){return c(this,null,function*(){var e,n;const{memos:i=[],spendTargets:r}=t,{publicAddress:a}=r[0];if(a==null)throw new Error("makeSpend Missing publicAddress");if(this.synchronizer==null)throw new Error("Synchronizer undefined");try{yield this.synchronizer.proposeTransfer({toAddress:a,zatoshi:this.availableZatoshi,memo:(n=(e=i[0])==null?void 0:e.value)!=null?n:""})}catch(l){const s=j(String(l));return(0,d.sub)(this.availableZatoshi,s)}return this.availableZatoshi})}makeSpend(t){return c(this,null,function*(){var e,n,i;const{edgeSpendInfo:r,currencyCode:a}=this.makeSpendCheck(t),{memos:l=[],tokenId:s}=r,h=r.spendTargets[0],{publicAddress:g,nativeAmount:f}=h;if(g==null)throw new Error("makeSpend Missing publicAddress");if(f==null)throw new I.ef;if((0,d.eq)(f,"0"))throw new I.ef;if((0,d.gt)(f,this.availableZatoshi))throw new I.k5({tokenId:s});if(this.synchronizer==null)throw new Error("Synchronizer undefined");const v=yield this.synchronizer.proposeTransfer({toAddress:g,zatoshi:f,memo:(n=(e=l[0])==null?void 0:e.value)!=null?n:""});if(v.transactionCount>1)throw new Error("Unable to handle multiple transactions");const w=v.totalFee,k=(0,d.add)(f,w);if((0,d.gt)(k,(i=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?i:"0"))throw new I.k5({tokenId:s});if((0,d.gt)(k,this.availableZatoshi))throw new I.k5({tokenId:s});const E=(0,d.mul)(k,"-1");return{blockHeight:0,currencyCode:a,date:0,isSend:!0,memos:l,nativeAmount:E,networkFee:w,ourReceiveAddresses:[],signedTx:"",tokenId:s,txid:"",walletId:this.walletId}})}signTx(t){return c(this,null,function*(){return t})}broadcastTx(t,e){return c(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:i}=t,r=(0,p.f9)(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const a=((n=i[0])==null?void 0:n.type)==="text"?i[0].value:"",l=t.spendTargets[0],s={zatoshi:(0,d.sub)((0,d.abs)(t.nativeAmount),t.networkFee),toAddress:l.publicAddress,memo:a,mnemonicSeed:r.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,A.T5)(t)}`)}catch(h){throw this.warn("FAILURE broadcastTx failed: ",h),h}return t})}getFreshAddress(){return c(this,null,function*(){const t=()=>c(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{unifiedAddress:e}=yield this.synchronizer.deriveUnifiedAddress();return this.otherData.cachedAddress=e,this.walletLocalDataDirty=!0,{publicAddress:e}});return this.otherData.cachedAddress==null?yield t():(t().catch(e=>{throw e}),{publicAddress:this.otherData.cachedAddress})})}}function V(o,t,e,n){return c(this,null,function*(){const i=(0,p.mS)(e),{makeSynchronizer:r}=o.nativeIo["edge-currency-accountbased"].zcash,a=new m(o,t,i,n,r);return yield a.loadEngine(),a})}const j=o=>{const t=/(\d+)/g,e=o.match(t);if(e==null||e.length!==2)throw new Error("Error parsing proposeTransfer error string");const n=parseInt(e[0]).toString();return(0,d.sub)(parseInt(e[1]).toString(),n)};var H=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,Y=(o,t)=>{var e={};for(var n in o)W.call(o,n)&&t.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&H)for(var n of H(o))t.indexOf(n)<0&&G.call(o,n)&&(e[n]=o[n]);return e},y=(o,t,e)=>new Promise((n,i)=>{var r=s=>{try{l(e.next(s))}catch(h){i(h)}},a=s=>{try{l(e.throw(s))}catch(h){i(h)}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,a);l((e=e.apply(o,t)).next())});class B{constructor(t){const{builtinTokens:e,currencyInfo:n,io:i,networkInfo:r}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=i,this.networkInfo=r;const a=t.nativeIo["edge-currency-accountbased"];if(a==null)throw new Error("Need opts");const{Tools:l}=a.zcash;this.nativeTools=l}getDisplayPrivateKey(t){return y(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,p.f9)(e)(t.keys);return`Seed Phrase:
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[6478],{36823:function(X,z,u){"use strict";u.r(z),u.d(z,{ZcashTools:function(){return x},makeCurrencyEngine:function(){return V},makeCurrencyTools:function(){return J},updateInfoPayload:function(){return Q}});var h=u(66001),D=u(90749),N=u(48287),U=u(36856),C=u(96542),b=u(44276),p=u(175),I=u(82671),P=u(65828),Z=u(26277),K=Object.defineProperty,B=Object.getOwnPropertySymbols,M=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,R=Reflect.get,O=(a,t,e)=>t in a?K(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,$=(a,t)=>{for(var e in t||(t={}))F.call(t,e)&&O(a,e,t[e]);if(B)for(var e of B(t))L.call(t,e)&&O(a,e,t[e]);return a},T=(a,t,e)=>R(M(a),e,t),c=(a,t,e)=>new Promise((n,r)=>{var i=o=>{try{l(e.next(o))}catch(d){r(d)}},s=o=>{try{l(e.throw(o))}catch(d){r(d)}},l=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,s);l((e=e.apply(a,t)).next())});const A="autoshield";class m extends Z.k{constructor(t,e,n,r,i){super(t,e,n,r);const{networkInfo:s}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=s,this.makeSynchronizer=i,this.balances={transparentAvailableZatoshi:"0",transparentTotalZatoshi:"0",saplingAvailableZatoshi:"0",saplingTotalZatoshi:"0",orchardAvailableZatoshi:"0",orchardTotalZatoshi:"0"},this.autoshielding={createAutoshieldTx:!1,threshold:(0,h.mul)(this.networkInfo.defaultNetworkFee,"2")}}setOtherData(t){this.otherData=(0,p.fS)(t)}initData(){this.otherData.isSdkInitializedOnDisk=!0,this.walletLocalDataDirty=!0,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0",this.progressRatio={seenFirstUpdate:!1,percent:0,lastUpdate:0}}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>c(this,null,function*(){const{scanProgress:e,networkBlockHeight:n}=t;this.onUpdateBlockHeight(n),this.onUpdateProgress(e),yield this.checkAutoshielding()})),this.synchronizer.on("statusChanged",t=>c(this,null,function*(){this.synchronizerStatus=t.name})),this.synchronizer.on("balanceChanged",t=>c(this,null,function*(){const{transparentAvailableZatoshi:e,transparentTotalZatoshi:n,saplingAvailableZatoshi:r,saplingTotalZatoshi:i,orchardAvailableZatoshi:s,orchardTotalZatoshi:l}=t;this.availableZatoshi=(0,h.add)(r,s),this.balances={transparentAvailableZatoshi:e,transparentTotalZatoshi:n,saplingAvailableZatoshi:r,saplingTotalZatoshi:i,orchardAvailableZatoshi:s,orchardTotalZatoshi:l};const o=(0,h.add)((0,h.add)(n,i),l);this.updateBalance(this.currencyInfo.currencyCode,o),yield this.checkAutoshielding()})),this.synchronizer.on("transactionsChanged",t=>c(this,null,function*(){const{transactions:e}=t;e.forEach(n=>{n.rawTransactionId===this.autoshielding.txid&&n.minedHeight>0&&(this.autoshielding.txid=void 0,this.autoshielding.createAutoshieldTx=!1),this.processTransaction(n)}),this.onUpdateTransactions()})),this.synchronizer.on("error",t=>c(this,null,function*(){this.log.warn(`Synchronizer error: ${t.message}`),t.level==="critical"&&(yield this.killEngine(),yield this.startEngine())})))}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){!this.progressRatio.seenFirstUpdate&&(this.progressRatio.seenFirstUpdate=!0,t!==100)||(this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=t/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=t/100,t>this.progressRatio.percent&&(t===100||Date.now()-this.progressRatio.lastUpdate>1e3)&&(this.progressRatio.percent=t,this.progressRatio.lastUpdate=Date.now(),this.log.warn(`Scan and download progress: ${Math.floor(t)}%`),this.updateOnAddressesChecked()))}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),(n==null||!(0,h.eq)(e,n))&&(this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`),this.currencyEngineCallbacks.onBalanceChanged(t,e))}startEngine(){return c(this,null,function*(){this.engineOn=!0,yield T(m.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}processTransaction(t){var e;const{rawTransactionId:n,raw:r,blockTimeInSeconds:i,minedHeight:s,value:l,fee:o,toAddress:d,memos:g}=t;let f=l;const v=o!=null?o:this.networkInfo.defaultNetworkFee;d!=null&&(f=`-${(0,h.add)(f,v)}`);const w=g.filter(S=>S!=="").map(S=>({memoName:"memo",type:"text",value:S}));this.otherData.missingAndroidShieldedMemosHack.includes(n)&&w.length===0&&w.push({memoName:"memo",type:"text",value:A}),((e=w[0])==null?void 0:e.value)===A&&(f=`-${v}`);const k=s===0?Math.max(i,Date.now()/1e3):i,E={blockHeight:s,currencyCode:this.currencyInfo.currencyCode,date:k,isSend:f.startsWith("-"),memos:w,nativeAmount:f,networkFee:v,otherParams:{},ourReceiveAddresses:[],signedTx:r!=null?r:"",tokenId:null,txid:n,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,E)}checkAutoshielding(){return c(this,null,function*(){this.isSynced()&&!this.autoshielding.createAutoshieldTx&&(0,h.gt)(this.balances.transparentAvailableZatoshi,this.autoshielding.threshold)&&(this.autoshielding.createAutoshieldTx=!0,yield this.restartSyncNetwork())})}syncNetwork(t){return c(this,null,function*(){if(!this.engineOn)return 1e3;const e=(0,p.f9)(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys);if(this.synchronizer==null){const{rpcNode:n}=this.networkInfo;this.initializer=$({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:P.xn.stringify(P.K3.parse(this.walletId)),newWallet:!this.otherData.isSdkInitializedOnDisk},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions()}return this.synchronizer!=null&&this.autoshielding.createAutoshieldTx?yield new Promise(n=>{var r;this.log.warn("Autoshield transaction broadcasting..."),(r=this.synchronizer)==null||r.shieldFunds({seed:e.mnemonic,memo:A,threshold:this.autoshielding.threshold}).then(i=>{this.log.warn("Autoshield success",i.rawTransactionId),i.blockTimeInSeconds=Date.now()/1e3,this.autoshielding.txid=i.rawTransactionId,this.otherData.missingAndroidShieldedMemosHack.push(i.rawTransactionId),this.walletLocalDataDirty=!0,this.processTransaction(i),this.onUpdateTransactions()}).catch(i=>{this.autoshielding.createAutoshieldTx=!1,this.log.error("Autoshield failed: ",i)}).finally(()=>{this.stopSyncing=n})}):yield new Promise(n=>{this.stopSyncing=n})})}killEngine(){return c(this,null,function*(){var t;yield T(m.prototype,this,"killEngine").call(this),yield this.restartSyncNetwork(),yield(t=this.synchronizer)==null?void 0:t.stop(),this.synchronizer=void 0})}restartSyncNetwork(){return c(this,null,function*(){this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0)})}clearBlockchainCache(){return c(this,null,function*(){yield T(m.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return c(this,null,function*(){var t;yield T(m.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),yield(t=this.synchronizer)==null?void 0:t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.synchronizerStatus="SYNCING"})}getMaxSpendable(t){return c(this,null,function*(){var e,n;const{memos:r=[],spendTargets:i}=t,{publicAddress:s}=i[0];if(s==null)throw new Error("makeSpend Missing publicAddress");if(this.synchronizer==null)throw new Error("Synchronizer undefined");try{yield this.synchronizer.proposeTransfer({toAddress:s,zatoshi:this.availableZatoshi,memo:(n=(e=r[0])==null?void 0:e.value)!=null?n:""})}catch(l){const o=j(String(l));return(0,h.sub)(this.availableZatoshi,o)}return this.availableZatoshi})}makeSpend(t){return c(this,null,function*(){var e,n,r;const{edgeSpendInfo:i,currencyCode:s}=this.makeSpendCheck(t),{memos:l=[],tokenId:o}=i,d=i.spendTargets[0],{publicAddress:g,nativeAmount:f}=d;if(g==null)throw new Error("makeSpend Missing publicAddress");if(f==null)throw new I.ef;if((0,h.eq)(f,"0"))throw new I.ef;if((0,h.gt)(f,this.availableZatoshi))throw new I.k5({tokenId:o});if(this.synchronizer==null)throw new Error("Synchronizer undefined");const v=yield this.synchronizer.proposeTransfer({toAddress:g,zatoshi:f,memo:(n=(e=l[0])==null?void 0:e.value)!=null?n:""}),w=v.totalFee,k=(0,h.add)(f,w);if((0,h.gt)(k,(r=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?r:"0"))throw new I.k5({tokenId:o});if((0,h.gt)(k,this.availableZatoshi))throw new I.k5({tokenId:o});const E=(0,h.mul)(k,"-1");return{blockHeight:0,currencyCode:s,date:0,isSend:!0,memos:l,nativeAmount:E,networkFee:w,otherParams:{proposalBase64:v.proposalBase64},ourReceiveAddresses:[],signedTx:"",tokenId:o,txid:"",walletId:this.walletId}})}signTx(t){return c(this,null,function*(){return t})}broadcastTx(t,e){return c(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{proposalBase64:n}=(0,b.Je)(t);if(n==null)throw new Error("Missing proposalBase64 from makeSpend");const r=(0,p.f9)(this.pluginId)(e==null?void 0:e.privateKeys),i={proposalBase64:n,mnemonicSeed:r.mnemonic};try{const s=yield this.synchronizer.createTransfer(i);t.txid=s,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
+ ${(0,b.T5)(t)}`)}catch(s){throw this.warn("FAILURE broadcastTx failed: ",s),s}return t})}getFreshAddress(){return c(this,null,function*(){const t=()=>c(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{unifiedAddress:e}=yield this.synchronizer.deriveUnifiedAddress();return this.otherData.cachedAddress=e,this.walletLocalDataDirty=!0,{publicAddress:e}});return this.otherData.cachedAddress==null?yield t():(t().catch(e=>{throw e}),{publicAddress:this.otherData.cachedAddress})})}}function V(a,t,e,n){return c(this,null,function*(){const r=(0,p.mS)(e),{makeSynchronizer:i}=a.nativeIo["edge-currency-accountbased"].zcash,s=new m(a,t,r,n,i);return yield s.loadEngine(),s})}const j=a=>{const t=/(\d+)/g,e=a.match(t);if(e==null||e.length!==2)throw new Error("Error parsing proposeTransfer error string");const n=parseInt(e[0]).toString();return(0,h.sub)(parseInt(e[1]).toString(),n)};var H=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,Y=(a,t)=>{var e={};for(var n in a)W.call(a,n)&&t.indexOf(n)<0&&(e[n]=a[n]);if(a!=null&&H)for(var n of H(a))t.indexOf(n)<0&&G.call(a,n)&&(e[n]=a[n]);return e},y=(a,t,e)=>new Promise((n,r)=>{var i=o=>{try{l(e.next(o))}catch(d){r(d)}},s=o=>{try{l(e.throw(o))}catch(d){r(d)}},l=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,s);l((e=e.apply(a,t)).next())});class x{constructor(t){const{builtinTokens:e,currencyInfo:n,io:r,networkInfo:i}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=r,this.networkInfo=i;const s=t.nativeIo["edge-currency-accountbased"];if(s==null)throw new Error("Need opts");const{Tools:l}=s.zcash;this.nativeTools=l}getDisplayPrivateKey(t){return y(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,p.f9)(e)(t.keys);return`Seed Phrase:
3
3
  ${n.mnemonic}
4
4
 
5
5
  Birthday Height:
6
- ${n.birthdayHeight}`})}getDisplayPublicKey(t){return y(this,null,function*(){const{keys:e}=(0,p.mS)(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return y(this,null,function*(){return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)})}isValidAddress(t){return y(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return y(this,arguments,function*(e,n={}){const{pluginId:i}=this.currencyInfo,r=(0,D.validateMnemonic)(e);if(e.split(" ").length!==24)throw new Error("Mnemonic must be 24 words");if(!r)throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const a=yield this.getNewWalletBirthdayBlockheight();let l=a;const{birthdayHeight:s}=n;if(s!=null){(0,U.ym)(s);const h=parseInt(s);if(h>a)throw new Error("InvalidBirthdayHeight");l=h}return{[`${i}Mnemonic`]:e,[`${i}BirthdayHeight`]:l}})}createPrivateKey(t){return y(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=N.Buffer.from(this.io.random(32)).toString("hex"),n=(0,D.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return y(this,null,function*(){try{return(0,p.tH)(t),!0}catch{return!1}})}derivePublicKey(t){return y(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,p.f9)(e)(t.keys);if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const i=n.mnemonic;if(typeof i!="string")throw new Error("InvalidMnemonic");const r=yield this.nativeTools.deriveViewingKey(i,this.networkInfo.rpcNode.networkName);return{birthdayHeight:n.birthdayHeight,publicKey:r}})}parseUri(t,e,n){return y(this,null,function*(){const{pluginId:i}=this.currencyInfo,r={[i]:!0},{edgeParsedUri:a,edgeParsedUri:{publicAddress:l}}=yield(0,C.x)({currencyInfo:this.currencyInfo,uri:t,networks:r,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:this.currencyInfo.currencyCode,customTokens:n});if(l==null||!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");return a})}encodeUri(t){return y(this,arguments,function*(e,n=[]){const{pluginId:i}=this.currencyInfo,{nativeAmount:r,currencyCode:a,publicAddress:l}=e;if(!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");let s;if(r!=null){const g=(0,A.FQ)(a!=null?a:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(g==null)throw new Error("InternalErrorInvalidCurrencyCode");s=(0,d.div)(r,g.multiplier,18)}return(0,C.m)(e,`${i}`,s)})}}function Q(o){return y(this,null,function*(){return new B(o)})}function J(o,t){return y(this,null,function*(){const e=Y(t,[]);o.networkInfo=(0,A.wy)(o.networkInfo,e)})}},15340:function(){},79838:function(){}}]);
6
+ ${n.birthdayHeight}`})}getDisplayPublicKey(t){return y(this,null,function*(){const{keys:e}=(0,p.mS)(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return y(this,null,function*(){return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)})}isValidAddress(t){return y(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return y(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo,i=(0,D.validateMnemonic)(e);if(e.split(" ").length!==24)throw new Error("Mnemonic must be 24 words");if(!i)throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const s=yield this.getNewWalletBirthdayBlockheight();let l=s;const{birthdayHeight:o}=n;if(o!=null){(0,U.ym)(o);const d=parseInt(o);if(d>s)throw new Error("InvalidBirthdayHeight");l=d}return{[`${r}Mnemonic`]:e,[`${r}BirthdayHeight`]:l}})}createPrivateKey(t){return y(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=N.Buffer.from(this.io.random(32)).toString("hex"),n=(0,D.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return y(this,null,function*(){try{return(0,p.tH)(t),!0}catch{return!1}})}derivePublicKey(t){return y(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,p.f9)(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 i=yield this.nativeTools.deriveViewingKey(r,this.networkInfo.rpcNode.networkName);return{birthdayHeight:n.birthdayHeight,publicKey:i}})}parseUri(t,e,n){return y(this,null,function*(){const{pluginId:r}=this.currencyInfo,i={[r]:!0},{edgeParsedUri:s,edgeParsedUri:{publicAddress:l}}=yield(0,C.x)({currencyInfo:this.currencyInfo,uri:t,networks:i,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:this.currencyInfo.currencyCode,customTokens:n});if(l==null||!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");return s})}encodeUri(t){return y(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:i,currencyCode:s,publicAddress:l}=e;if(!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");let o;if(i!=null){const g=(0,b.FQ)(s!=null?s:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(g==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,h.div)(i,g.multiplier,18)}return(0,C.m)(e,`${r}`,o)})}}function J(a){return y(this,null,function*(){return new x(a)})}function Q(a,t){return y(this,null,function*(){const e=Y(t,[]);a.networkInfo=(0,b.wy)(a.networkInfo,e)})}},15340:function(){},79838:function(){}}]);
@@ -94,11 +94,11 @@ const makeZcashSynchronizer = async (
94
94
  rescan: async () => {
95
95
  return await realSynchronizer.rescan()
96
96
  },
97
- proposeTransfer: async spendInfo => {
98
- return await realSynchronizer.proposeTransfer(spendInfo)
97
+ proposeTransfer: async proposeTransferOpts => {
98
+ return await realSynchronizer.proposeTransfer(proposeTransferOpts)
99
99
  },
100
- sendToAddress: async spendInfo => {
101
- return await realSynchronizer.sendToAddress(spendInfo)
100
+ createTransfer: async transferOpts => {
101
+ return await realSynchronizer.createTransfer(transferOpts)
102
102
  },
103
103
  shieldFunds: async shieldFundsInfo => {
104
104
  return await realSynchronizer.shieldFunds(shieldFundsInfo)
@@ -465,9 +465,6 @@ const AUTOSHIELD_MEMO = 'autoshield'
465
465
  zatoshi: nativeAmount,
466
466
  memo: _nullishCoalesce(_optionalChain([memos, 'access', _23 => _23[0], 'optionalAccess', _24 => _24.value]), () => ( ''))
467
467
  })
468
- if (proposal.transactionCount > 1) {
469
- throw new Error('Unable to handle multiple transactions')
470
- }
471
468
 
472
469
  const networkFee = proposal.totalFee
473
470
 
@@ -500,6 +497,9 @@ const AUTOSHIELD_MEMO = 'autoshield'
500
497
  memos,
501
498
  nativeAmount: txNativeAmount,
502
499
  networkFee,
500
+ otherParams: {
501
+ proposalBase64: proposal.proposalBase64
502
+ },
503
503
  ourReceiveAddresses: [],
504
504
  signedTx: '',
505
505
  tokenId,
@@ -520,32 +520,22 @@ const AUTOSHIELD_MEMO = 'autoshield'
520
520
  opts
521
521
  ) {
522
522
  if (this.synchronizer == null) throw new Error('Synchronizer undefined')
523
- const { memos } = edgeTransaction
523
+ const { proposalBase64 } = _utils.getOtherParams.call(void 0, edgeTransaction)
524
+ if (proposalBase64 == null) {
525
+ throw new Error('Missing proposalBase64 from makeSpend')
526
+ }
524
527
  const zcashPrivateKeys = _zcashTypes.asZcashPrivateKeys.call(void 0, this.pluginId)(
525
528
  _optionalChain([opts, 'optionalAccess', _25 => _25.privateKeys])
526
529
  )
527
- if (
528
- edgeTransaction.spendTargets == null ||
529
- edgeTransaction.spendTargets.length !== 1
530
- )
531
- throw new Error('Invalid spend targets')
532
530
 
533
- const memo = _optionalChain([memos, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.type]) === 'text' ? memos[0].value : ''
534
- const spendTarget = edgeTransaction.spendTargets[0]
535
531
  const txParams = {
536
- zatoshi: _biggystring.sub.call(void 0,
537
- _biggystring.abs.call(void 0, edgeTransaction.nativeAmount),
538
- edgeTransaction.networkFee
539
- ),
540
- toAddress: spendTarget.publicAddress,
541
- memo,
532
+ proposalBase64,
542
533
  mnemonicSeed: zcashPrivateKeys.mnemonic
543
534
  }
544
535
 
545
536
  try {
546
- const signedTx = await this.synchronizer.sendToAddress(txParams)
547
- edgeTransaction.txid = signedTx.txId
548
- edgeTransaction.signedTx = signedTx.raw
537
+ const txid = await this.synchronizer.createTransfer(txParams)
538
+ edgeTransaction.txid = txid
549
539
  edgeTransaction.date = Date.now() / 1000
550
540
  this.warn(`SUCCESS broadcastTx\n${_utils.cleanTxLogs.call(void 0, edgeTransaction)}`)
551
541
  } catch (e) {
@@ -26,7 +26,6 @@ var _cleaners = require('cleaners');
26
26
 
27
27
 
28
28
 
29
-
30
29
  var _types = require('../common/types');
31
30
 
32
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "4.24.6",
3
+ "version": "4.25.0",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {
@@ -160,7 +160,7 @@
160
160
  "prettier": "^2.2.0",
161
161
  "process": "^0.11.10",
162
162
  "react-native-piratechain": "0.5.0",
163
- "react-native-zcash": "0.8.0",
163
+ "react-native-zcash": "0.9.0",
164
164
  "rimraf": "^3.0.2",
165
165
  "shell-quote": "^1.8.1",
166
166
  "stream-browserify": "^2.0.2",
@@ -175,6 +175,6 @@
175
175
  },
176
176
  "peerDependencies": {
177
177
  "react-native-piratechain": "v0.5.0",
178
- "react-native-zcash": "^0.8.0"
178
+ "react-native-zcash": "^0.9.0"
179
179
  }
180
180
  }