edge-currency-accountbased 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8601],{79014:function(ae,U,l){"use strict";l.d(U,{Q:function(){return ne},k:function(){return te}});var R=l(77591),y=l.n(R),I=l(24350),b=l(84564),A=l.n(b),B=l(76714),L=Object.defineProperty,$=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,J=(m,k,w)=>k in m?L(m,k,{enumerable:!0,configurable:!0,writable:!0,value:w}):m[k]=w,ee=(m,k)=>{for(var w in k||(k={}))M.call(k,w)&&J(m,w,k[w]);if($)for(var w of $(k))n.call(k,w)&&J(m,w,k[w]);return m};function te(m,k,w,v,N=[]){const g=ee({},A()(k,{},!0)),F=k.startsWith(`${m.pluginId}://`);if(g.protocol!=null&&(g.protocol=g.protocol.replace(":","")),g.protocol!=null&&g.protocol!==""&&!w[g.protocol])throw new Error(`Uri protocol '${g.protocol}' is not supported for ${m.pluginId}.`);if(g.host===""&&g.pathname==="")throw new Error("Path and host not found in uri.");const E={publicAddress:g.host!==""?g.host:g.pathname.split("/")[0]},X=g.query.label,Z=g.query.message,q=g.query.category;(X!=null||Z!=null||q!=null||F)&&(E.metadata={},E.metadata.name=X,E.metadata.notes=Z,E.metadata.category=q,E.metadata.gateway=F!=null?F:!1);const W=g.query.amount;if(W!=null&&typeof W=="string"){v==null&&(v=m.currencyCode);const G=(0,B.Qs)(v!=null?v:"",m,N);if(G==null)throw new Error("InternalErrorInvalidCurrencyCode");let D=(0,R.mul)(W,G.multiplier);D=(0,R.toFixed)(D,0,0),E.nativeAmount=D,E.currencyCode=v}return{edgeParsedUri:E,parsedUri:g}}function ne(m,k,w){if(m.publicAddress==null)throw new Error("InvalidPublicAddressError");if(w==null&&m.label==null&&m.message==null)return m.publicAddress;{let v="";w!=null&&(v+="amount="+w+"&"),(m.label!=null||m.message!=null)&&(typeof m.label=="string"&&(v+="label="+m.label+"&"),typeof m.message=="string"&&(v+="message="+m.message+"&")),v=v.substr(0,v.length-1);const N={scheme:k,path:m.publicAddress,query:v};return(0,I.qC)(N)}}},99599:function(ae,U,l){"use strict";l.d(U,{K:function(){return R}});const R={parse(y){const I=encodeURI(y),b=new Uint8Array(I.length);let A=0;for(let B=0;B<I.length;++B){const L=I.charCodeAt(B);L===37?(b[A++]=parseInt(I.slice(B+1,B+3),16),B+=2):b[A++]=L}return b.subarray(0,A)},stringify(y){let I="";for(let b=0;b<y.length;++b){const A=y[b];I+="%"+(A>>4).toString(16)+(A&15).toString(16)}return decodeURIComponent(I)}}},18226:function(ae,U,l){"use strict";l.r(U),l.d(U,{SolanaTools:function(){return de},makeCurrencyEngine:function(){return Oe},makeCurrencyTools:function(){return Me}});var R=l(78412),y=l(77591),I=l(2153),b=l(48764),A=l(62678),B=l(79325),L=l(20918),$=l(79014),M=l(76714),n=l(82448),J=l(62177);const ee=(0,n.su)({newestTxid:(0,n.Vk)(n.XC,"")}),te=(0,n.su)({value:n.mH}),ne=(0,n.su)({signature:n.XC,blocktime:(0,n.Zz)(n.mH),err:n.JC}),m=(0,n.su)({value:(0,n.su)({blockhash:n.XC,feeCalculator:(0,n.su)({lamportsPerSignature:n.mH})})}),k=J.BQ,w=f=>{const e=(0,n.su)({[`${f}Mnemonic`]:n.XC,[`${f}Key`]:n.XC});return(0,n.W1)(t=>{const s=e(t);return{mnemonic:s[`${f}Mnemonic`],privateKey:s[`${f}Key`]}},t=>({[`${f}Mnemonic`]:t.mnemonic,[`${f}Key`]:t.privateKey}))},v=f=>(0,n.su)({result:f}),N=(0,n.vq)(v((0,n._2)(ne))),g=v(te),F=(0,n.su)({value:(0,n.su)({amount:n.XC})}),ce=v(F),E=(0,n.su)({value:(0,n._C)(n.gu,(0,n.su)({}))}),X=(0,n.su)({accountIndex:n.mH,mint:n.XC,owner:n.XC,programId:n.XC,uiTokenAmount:(0,n.su)({amount:n.XC})}),Z=(0,n.su)({meta:(0,n.su)({err:(0,n.Zz)(n.JC),fee:n.mH,innerInstructions:(0,n._2)(n.JC),postBalances:(0,n._2)(n.mH),postTokenBalances:(0,n._2)((0,n.Vk)(X)),preBalances:(0,n._2)(n.mH),preTokenBalances:(0,n._2)((0,n.Vk)(X))}),slot:n.mH,transaction:(0,n.su)({message:(0,n.su)({accountKeys:(0,n._2)((0,n.su)({pubkey:n.XC})),instructions:(0,n._2)(n.JC),recentBlockhash:n.XC}),signatures:(0,n._2)(n.XC)})}),q=v(Z),W=v(n.mH),G=(0,n.su)({alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)});var D=l(20302),fe=l(77043),me=l(49687),H=l(94935),ye=l(84650),pe=l(72681),ge=l(99599),ke=l(48764).Buffer,we=Object.defineProperty,le=Object.getOwnPropertySymbols,ve=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,Ie=Reflect.get,ue=(f,e,t)=>e in f?we(f,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):f[e]=t,Pe=(f,e)=>{for(var t in e||(e={}))Ce.call(e,t)&&ue(f,t,e[t]);if(le)for(var t of le(e))Te.call(e,t)&&ue(f,t,e[t]);return f},be=(f,e,t)=>Ie(ve(f),t,e),C=(f,e,t)=>new Promise((s,r)=>{var a=o=>{try{c(t.next(o))}catch(h){r(h)}},u=o=>{try{c(t.throw(o))}catch(h){r(h)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,u);c((t=t.apply(f,e)).next())});const{PublicKey:K,Keypair:Be,SystemProgram:Se,Transaction:he,TransactionInstruction:Ae}=R,Ee=5e3,se=2e4,Ke=3e3;class re extends ye.P{constructor(e,t,s,r){super(e,t,s,r),this.networkInfo=e.networkInfo,this.initOptions=e.initOptions,this.chainCode=t.currencyInfo.currencyCode,this.fetchCors=(0,M.zR)(e.io),this.feePerSignature="5000",this.recentBlockhash="",this.base58PublicKey=s.keys.publicKey,this.progressRatio=0,this.addressCache=new Map,this.minimumAddressBalance="0"}setOtherData(e){this.otherData=ee(e)}fetchRpc(e){return C(this,arguments,function*(t,s=[]){const r={method:t,params:s};return(yield this.fetchRpcBulk([r]))[0].result})}fetchRpcBulk(e,t){return C(this,null,function*(){const s={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e.map((u,c)=>Pe({jsonrpc:"2.0",id:c+1},u)))},a=(t!=null?t:this.networkInfo.rpcNodes).map(u=>()=>C(this,null,function*(){const c=G(this.initOptions),h=/{{(.*)}}/g.exec(u);if(h!=null){const T=h[1],p=c[T];if(typeof p=="string")u=u.replace(h[0],p);else throw p==null?new Error(`Missing ${T} in 'initOptions' for ${this.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const d=yield this.fetchCors(u,s);if(!d.ok)throw new Error(`fetchRpc ${s.method} failed error: ${d.status}`);return yield d.json()}));return yield(0,M.QJ)(a)})}queryBalance(){return C(this,null,function*(){var e,t,s;try{const r=[{method:"getBalance",params:[this.base58PublicKey,{commitment:this.networkInfo.commitment}]}],a=[...Object.keys(this.allTokensMap)],u=new K(this.base58PublicKey),c=new K(this.networkInfo.tokenPublicKey),o=new K(this.networkInfo.associatedTokenPublicKey);for(const p of a){const i=yield(0,D.Am)(new K(p),u,!1,c,o);r.push({method:"getTokenAccountBalance",params:[i.toBase58(),{commitment:this.networkInfo.commitment,encoding:"jsonParsed"}]})}const h=yield this.fetchRpcBulk(r),[d,...x]=h,T=g(d);this.updateBalance(this.chainCode,T.result.value.toString());for(const[p,i]of a.entries()){const S=(0,n.Vk)(ce)(x[p]),P=(s=(t=(e=S==null?void 0:S.result)==null?void 0:e.value)==null?void 0:t.amount)!=null?s:"0";this.updateBalance(this.allTokensMap[i].currencyCode,P)}}catch(r){this.error(`Error checking ${this.chainCode} address balance`,r)}})}queryBlockheight(){return C(this,null,function*(){try{const e=(0,n.mH)(yield this.fetchRpc("getSlot"));e>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(e){this.error("queryBlockheight Error ",e)}})}queryMinimumBalance(){return C(this,null,function*(){try{const e=(0,n.mH)(yield this.fetchRpc("getMinimumBalanceForRentExemption",[50]));this.minimumAddressBalance=e.toString()}catch(e){this.error("queryMinimumBalance Error ",e)}})}queryFee(){return C(this,null,function*(){try{const e=yield this.fetchRpc("getRecentBlockhash"),{blockhash:t,feeCalculator:{lamportsPerSignature:s}}=m(e).value;this.feePerSignature=s.toString(),this.recentBlockhash=t}catch(e){this.error("queryFee Error ",e)}})}processSolanaTransaction(e,t,s){const r=[],{amount:a,networkFee:u,parentNetworkFee:c,tokenId:o}=t,h=o!=null?this.allTokensMap[o].currencyCode:this.chainCode;(0,y.gte)(a,"0")&&r.push(this.base58PublicKey);const d={blockHeight:e.slot,currencyCode:h,date:s,isSend:a.startsWith("-"),memos:[],nativeAmount:a,networkFee:u,ourReceiveAddresses:r,parentNetworkFee:c,signedTx:"",txid:e.transaction.signatures[0],walletId:this.walletId};this.addTransaction(h,d)}parseTxAmounts(e){var t;const s=[],r=e.transaction.message.accountKeys.findIndex(i=>i.pubkey===this.base58PublicKey);if(r<0||e.meta==null)return s;const{fee:a,preBalances:u,postBalances:c,preTokenBalances:o,postTokenBalances:h}=e.meta,d=a.toString(),x=(c[r]-u[r]).toString();if(x!=="0"){const i=(0,y.lt)(x,"0");s.push({amount:i?(0,y.sub)(x,d):x,networkFee:i?d:"0"})}const T=i=>i==null||i.owner!==this.base58PublicKey||i.programId!==this.networkInfo.tokenPublicKey||this.allTokensMap[i.mint]==null,p=new Map;for(const i of h)i==null||T(i)||p.set(i.mint,i.uiTokenAmount.amount);for(const i of o){if(i==null||T(i))continue;const S=(t=p.get(i.mint))!=null?t:"0";p.set(i.mint,(0,y.sub)(S,i.uiTokenAmount.amount))}return p.forEach((i,S)=>{s.push({amount:i,networkFee:"0",parentNetworkFee:(0,y.lt)(i,"0")?d:void 0,tokenId:S})}),s}queryTransactions(){return C(this,null,function*(){var e;let t=null;const s=this.otherData.newestTxid!==""?this.otherData.newestTxid:null;let r=[];try{for(;;){const o=[this.base58PublicKey,{until:s,before:t,limit:this.networkInfo.txQueryLimit,commitment:this.networkInfo.commitment}],h=yield this.fetchRpcBulk([{method:"getSignaturesForAddress",params:o}],this.networkInfo.rpcNodesArchival),d=N(h)[0].result;if(r=r.concat(d),d.length<this.networkInfo.txQueryLimit)break;t=d[this.networkInfo.txQueryLimit-1].signature}}catch(o){this.error("getTransactionSignatures failed with error: ",o);return}if(r.length===0){this.updateTxStatus(1),this.updateOnAddressesChecked();return}const a=50;let u=0;const c=r.map(o=>({method:"getTransaction",params:[o.signature,{encoding:"jsonParsed",commitment:this.networkInfo.commitment,maxSupportedTransactionVersion:0}]})).reverse();for(let o=0;o<c.length;o+=a){const h=c.slice(o,o+a>c.length-1?void 0:o+a),d=yield this.fetchRpcBulk(h,this.networkInfo.rpcNodesArchival),T=d.map(i=>q(i).result.slot).map(i=>({method:"getBlockTime",params:[i]})),p=yield this.fetchRpcBulk(T,this.networkInfo.rpcNodesArchival);for(let i=0;i<d.length;i++){if(((e=d[i].result.meta)==null?void 0:e.err)!=null)continue;this.parseTxAmounts(d[i].result).forEach(z=>{this.processSolanaTransaction(d[i].result,z,W(p[i]).result),u++}),this.otherData.newestTxid=r[i].signature;const P=1-u/r.length;P!==this.progressRatio&&(Math.abs(P-this.progressRatio)>.25||P===1)&&(this.progressRatio=P,this.updateTxStatus(this.progressRatio),this.updateOnAddressesChecked())}}this.walletLocalDataDirty=!0,this.updateTxStatus(1),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}updateTxStatus(e){[this.chainCode,...this.enabledTokenIds.map(s=>this.allTokensMap[s].currencyCode)].forEach(s=>{this.tokenCheckTransactionsStatus[s]=e}),this.updateOnAddressesChecked()}startEngine(){return C(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBlockheight",se).catch(()=>{}),this.addToLoop("queryMinimumBalance",se).catch(()=>{}),this.addToLoop("queryFee",se).catch(()=>{}),this.addToLoop("queryBalance",Ee).catch(()=>{}),this.addToLoop("queryTransactions",Ke).catch(()=>{}),yield be(re.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return C(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return C(this,null,function*(){const{currencyCode:t}=e;let s=this.getBalance({currencyCode:t});if(t===this.currencyInfo.currencyCode)s=(0,y.sub)(s,this.feePerSignature);else{const r=this.getBalance({currencyCode:this.currencyInfo.currencyCode});if((0,y.lt)((0,y.sub)(r,this.minimumAddressBalance),"0"))throw new H.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:this.feePerSignature})}if((0,y.lt)(s,"0"))throw new H.C_;return s})}makeSpend(e){return C(this,null,function*(){var t,s,r;e=(0,pe.s)(e,this.currencyInfo);const{edgeSpendInfo:a,currencyCode:u}=this.makeSpendCheck(e),{memos:c=[],tokenId:o}=a;if(a.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:h,publicAddress:d}=a.spendTargets[0];if(d==null)throw new Error("makeSpend Missing publicAddress");if(h==null)throw new H.$D;const x=o!=null;let T="0",p=this.feePerSignature,i;const S=(t=this.walletLocalData.totalBalances[u])!=null?t:"0",P=new K(this.base58PublicKey),z=new K(d),Y=new K(this.networkInfo.tokenPublicKey),oe=new K(this.networkInfo.associatedTokenPublicKey),Le={recentBlockhash:this.recentBlockhash,feePayer:P},Q=new he(Le);if(x){const V=new K(o),ie=yield(0,D.Am)(V,z,!1,Y,oe);let _=this.addressCache.get(d);if(_===void 0&&(E(yield this.fetchRpc("getAccountInfo",[ie.toBase58(),{commitment:this.networkInfo.commitment,encoding:"jsonParsed"}])).value==null?(_=!1,this.addressCache.set(d,!1)):(_=!0,this.addressCache.set(d,!0))),_||(Q.add((0,fe.Ek)(P,ie,z,V,Y,oe)),p=(0,y.add)(p,this.feePerSignature)),i=p,p="0",T=h,(0,y.gt)(h,S))throw new H.C_;const Ue=(s=this.walletLocalData.totalBalances[this.chainCode])!=null?s:"0";if((0,y.gt)((0,y.add)(i,this.minimumAddressBalance),Ue))throw new H.C_({currencyCode:this.chainCode,networkFee:i});const He=yield(0,D.Am)(V,P,!1,Y,oe);Q.add((0,me.$B)(He,ie,P,BigInt(h),[],Y))}else T=(0,y.add)(h,p),Q.add(Se.transfer({fromPubkey:P,toPubkey:z,lamports:parseInt(h)}));if(!(0,y.eq)(T,S)){if((0,y.gt)((0,y.add)(T,this.minimumAddressBalance),S))throw new H.C_}if(((r=c[0])==null?void 0:r.type)==="text"){const V=new Ae({keys:[{pubkey:P,isSigner:!0,isWritable:!0}],programId:new K(this.networkInfo.memoPublicKey),data:ke.from(ge.K.parse(c[0].value))});Q.add(V)}const De={unsignedSerializedSolTx:Q.serialize({requireAllSignatures:!1})};return{blockHeight:0,currencyCode:u,date:0,isSend:!0,memos:c,nativeAmount:(0,y.mul)(T,"-1"),networkFee:p,otherParams:De,ourReceiveAddresses:[],parentNetworkFee:i,signedTx:"",txid:"",walletId:this.walletId}})}signTx(e,t){return C(this,null,function*(){const s=w(this.currencyInfo.pluginId)(t),{unsignedSerializedSolTx:r}=(0,M.Xp)(e);if(r==null)throw new Error("Missing unsignedSerializedSolTx");const a=Be.fromSecretKey(Uint8Array.from(B.YU.parse(s.privateKey))),u=he.from(r);return u.recentBlockhash=this.recentBlockhash,u.sign({publicKey:a.publicKey,secretKey:a.secretKey}),e.signedTx=u.serialize().toString("base64"),this.warn(`signTx
2
- ${(0,M.oX)(e)}`),this.addressCache=new Map(Array.from(this.addressCache.entries()).filter(([c,o])=>o)),e})}broadcastTx(e){return C(this,null,function*(){if(e.signedTx==null)throw new Error("Missing signedTx");try{const t=[e.signedTx,{encoding:"base64"}],s=(0,n.XC)(yield this.fetchRpc("sendTransaction",t));e.txid=s,e.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
3
- ${(0,M.oX)(e)}`)}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}return e})}}function Oe(f,e,t,s){return C(this,null,function*(){const r=k(t),a=new re(f,e,r,s);return yield a.loadEngine(),a})}var O=(f,e,t)=>new Promise((s,r)=>{var a=o=>{try{c(t.next(o))}catch(h){r(h)}},u=o=>{try{c(t.throw(o))}catch(h){r(h)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,u);c((t=t.apply(f,e)).next())});const{Keypair:xe,PublicKey:j}=R,Re=(f,e)=>O(void 0,null,function*(){const t=yield(0,I.mnemonicToSeed)(f),s=A.derivePath(e,B.YU.stringify(t)).key;return xe.fromSeed(Uint8Array.from(s))});class de{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:a}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=a}getDisplayPrivateKey(e){return O(this,null,function*(){const{pluginId:t}=this.currencyInfo;return w(t)(e.keys).mnemonic})}getDisplayPublicKey(e){return O(this,null,function*(){const{keys:t}=k(e);return t.publicKey})}importPrivateKey(e){return O(this,null,function*(){const{pluginId:t}=this.currencyInfo;if(!(0,I.validateMnemonic)(e))throw new Error("Invalid mnemonic");const r=yield Re(e,this.networkInfo.derivationPath);return{[`${t}Mnemonic`]:e,[`${t}Key`]:b.Buffer.from(r.secretKey).toString("hex"),publicKey:r.publicKey.toBase58()}})}createPrivateKey(e){return O(this,null,function*(){if(e!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=b.Buffer.from(this.io.random(32)),s=(0,I.entropyToMnemonic)(t);return yield this.importPrivateKey(s)})}derivePublicKey(e){return O(this,null,function*(){const{pluginId:t}=this.currencyInfo;if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");if(e.keys[`${t}Mnemonic`]==null)throw new Error("Missing mnemonic");return{publicKey:(yield this.importPrivateKey(e.keys[`${t}Mnemonic`])).publicKey.toString()}})}parseUri(e,t,s){return O(this,null,function*(){const{pluginId:r}=this.currencyInfo,a={[r]:!0},{parsedUri:u,edgeParsedUri:c}=(0,$.k)(this.currencyInfo,e,a,t!=null?t:this.currencyInfo.currencyCode,s);let o="";if(c.publicAddress!=null&&(o=c.publicAddress),!j.isOnCurve(new j(o).toBytes()))throw new Error("InvalidPublicAddressError");return c.uniqueIdentifier=u.query.memo,c})}encodeUri(e){return O(this,arguments,function*(t,s=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:a,currencyCode:u,publicAddress:c}=t;if(!j.isOnCurve(new j(c).toBytes()))throw new Error("InvalidPublicAddressError");let o;if(typeof a=="string"){const d=(0,M.Qs)(u!=null?u:this.currencyInfo.currencyCode,this.currencyInfo,s);if(d==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,y.div)(a,d.multiplier,18)}return(0,$.Q)(t,r,o)})}getTokenId(e){return O(this,null,function*(){(0,L.Rp)(e);const t=(0,L.Oj)(e.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress})}}function Me(f){return O(this,null,function*(){return new de(f)})}},52361:function(){},94616:function(){},55024:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8601],{79014:function(he,H,h){"use strict";h.d(H,{Q:function(){return oe},k:function(){return re}});var L=h(77591),u=h.n(L),b=h(24350),B=h(84564),E=h.n(B),A=h(76714),F=Object.defineProperty,z=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,G=(y,k,g)=>k in y?F(y,k,{enumerable:!0,configurable:!0,writable:!0,value:g}):y[k]=g,se=(y,k)=>{for(var g in k||(k={}))M.call(k,g)&&G(y,g,k[g]);if(z)for(var g of z(k))n.call(k,g)&&G(y,g,k[g]);return y};function re(y,k,g,w,R=[]){const p=se({},E()(k,{},!0)),W=k.startsWith(`${y.pluginId}://`);if(p.protocol!=null&&(p.protocol=p.protocol.replace(":","")),p.protocol!=null&&p.protocol!==""&&!g[p.protocol])throw new Error(`Uri protocol '${p.protocol}' is not supported for ${y.pluginId}.`);if(p.host===""&&p.pathname==="")throw new Error("Path and host not found in uri.");const K={publicAddress:p.host!==""?p.host:p.pathname.split("/")[0]},Z=p.query.label,Q=p.query.message,j=p.query.category;(Z!=null||Q!=null||j!=null||W)&&(K.metadata={},K.metadata.name=Z,K.metadata.notes=Q,K.metadata.category=j,K.metadata.gateway=W!=null?W:!1);const V=p.query.amount;if(V!=null&&typeof V=="string"){w==null&&(w=y.currencyCode);const _=(0,A.Qs)(w!=null?w:"",y,R);if(_==null)throw new Error("InternalErrorInvalidCurrencyCode");let q=(0,L.mul)(V,_.multiplier);q=(0,L.toFixed)(q,0,0),K.nativeAmount=q,K.currencyCode=w}return{edgeParsedUri:K,parsedUri:p}}function oe(y,k,g){if(y.publicAddress==null)throw new Error("InvalidPublicAddressError");if(g==null&&y.label==null&&y.message==null)return y.publicAddress;{let w="";g!=null&&(w+="amount="+g+"&"),(y.label!=null||y.message!=null)&&(typeof y.label=="string"&&(w+="label="+y.label+"&"),typeof y.message=="string"&&(w+="message="+y.message+"&")),w=w.substr(0,w.length-1);const R={scheme:k,path:y.publicAddress,query:w};return(0,b.qC)(R)}}},99599:function(he,H,h){"use strict";h.d(H,{K:function(){return L}});const L={parse(u){const b=encodeURI(u),B=new Uint8Array(b.length);let E=0;for(let A=0;A<b.length;++A){const F=b.charCodeAt(A);F===37?(B[E++]=parseInt(b.slice(A+1,A+3),16),A+=2):B[E++]=F}return B.subarray(0,E)},stringify(u){let b="";for(let B=0;B<u.length;++B){const E=u[B];b+="%"+(E>>4).toString(16)+(E&15).toString(16)}return decodeURIComponent(b)}}},18226:function(he,H,h){"use strict";h.r(H),h.d(H,{SolanaTools:function(){return pe},makeCurrencyEngine:function(){return De},makeCurrencyTools:function(){return Ne}});var L=h(78412),u=h(77591),b=h(2153),B=h(48764),E=h(62678),A=h(79325),F=h(20918),z=h(79014),M=h(76714),n=h(82448),G=h(62177);const se=(0,n.su)({newestTxid:(0,n.Vk)(n.XC,"")}),re=(0,n.su)({value:n.mH}),oe=(0,n.su)({signature:n.XC,blocktime:(0,n.Zz)(n.mH),err:n.JC}),y=(0,n.su)({value:(0,n.su)({blockhash:n.XC})}),k=(0,n._2)((0,n.su)({prioritizationFee:n.mH,slot:n.mH})),g=G.BQ,w=d=>{const e=(0,n.su)({[`${d}Mnemonic`]:n.XC,[`${d}Key`]:n.XC});return(0,n.W1)(t=>{const s=e(t);return{mnemonic:s[`${d}Mnemonic`],privateKey:s[`${d}Key`]}},t=>({[`${d}Mnemonic`]:t.mnemonic,[`${d}Key`]:t.privateKey}))},R=d=>(0,n.su)({result:d}),p=(0,n.vq)(R((0,n._2)(oe))),W=R(re),de=(0,n.su)({value:(0,n.su)({amount:n.XC})}),K=R(de),Z=(0,n.su)({value:(0,n._C)(n.gu,(0,n.su)({}))}),Q=(0,n.su)({accountIndex:n.mH,mint:n.XC,owner:n.XC,programId:n.XC,uiTokenAmount:(0,n.su)({amount:n.XC})}),j=(0,n.su)({meta:(0,n.su)({err:(0,n.Zz)(n.JC),fee:n.mH,innerInstructions:(0,n._2)(n.JC),postBalances:(0,n._2)(n.mH),postTokenBalances:(0,n._2)((0,n.Vk)(Q)),preBalances:(0,n._2)(n.mH),preTokenBalances:(0,n._2)((0,n.Vk)(Q))}),slot:n.mH,transaction:(0,n.su)({message:(0,n.su)({accountKeys:(0,n._2)((0,n.su)({pubkey:n.XC})),instructions:(0,n._2)(n.JC),recentBlockhash:n.XC}),signatures:(0,n._2)(n.XC)})}),V=R(j),_=R(n.mH),q=(0,n.su)({alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)}),ge=(0,n.su)({microLamports:n.XC});var ie=h(20302),ke=h(77043),we=h(49687),N=h(94935),ve=h(84650),Ce=h(72681),Te=h(99599),Ie=h(48764).Buffer,Pe=Object.defineProperty,me=Object.getOwnPropertySymbols,be=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Se=Reflect.get,ye=(d,e,t)=>e in d?Pe(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,Ee=(d,e)=>{for(var t in e||(e={}))Be.call(e,t)&&ye(d,t,e[t]);if(me)for(var t of me(e))Ae.call(e,t)&&ye(d,t,e[t]);return d},Ke=(d,e,t)=>Se(be(d),t,e),v=(d,e,t)=>new Promise((s,r)=>{var a=o=>{try{l(t.next(o))}catch(f){r(f)}},c=o=>{try{l(t.throw(o))}catch(f){r(f)}},l=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,c);l((t=t.apply(d,e)).next())});const{ComputeBudgetProgram:Oe,PublicKey:O,Keypair:xe,SystemProgram:Re,Transaction:fe,TransactionInstruction:Le}=L,Me=5e3,Y=2e4,Fe=3e3;class ae extends ve.P{constructor(e,t,s,r){super(e,t,s,r),this.networkInfo=e.networkInfo,this.initOptions=e.initOptions,this.chainCode=t.currencyInfo.currencyCode,this.fetchCors=(0,M.zR)(e.io),this.feePerSignature="5000",this.priorityFee="0",this.recentBlockhash="",this.base58PublicKey=s.keys.publicKey,this.progressRatio=0,this.addressCache=new Map,this.minimumAddressBalance="0"}setOtherData(e){this.otherData=se(e)}fetchRpc(e){return v(this,arguments,function*(t,s=[]){const r={method:t,params:s};return(yield this.fetchRpcBulk([r]))[0].result})}fetchRpcBulk(e,t){return v(this,null,function*(){const s={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e.map((c,l)=>Ee({jsonrpc:"2.0",id:l+1},c)))},a=(t!=null?t:this.networkInfo.rpcNodes).map(c=>()=>v(this,null,function*(){const l=q(this.initOptions),f=/{{(.*)}}/g.exec(c);if(f!=null){const P=f[1],C=l[P];if(typeof C=="string")c=c.replace(f[0],C);else throw C==null?new Error(`Missing ${P} in 'initOptions' for ${this.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const m=yield this.fetchCors(c,s);if(!m.ok)throw new Error(`fetchRpc ${s.method} failed error: ${m.status}`);return yield m.json()}));return yield(0,M.QJ)(a)})}queryBalance(){return v(this,null,function*(){var e,t,s;try{const r=[{method:"getBalance",params:[this.base58PublicKey,{commitment:this.networkInfo.commitment}]}],a=[...Object.keys(this.allTokensMap)],c=new O(this.base58PublicKey),l=new O(this.networkInfo.tokenPublicKey),o=new O(this.networkInfo.associatedTokenPublicKey);for(const C of a){const i=yield(0,ie.Am)(new O(C),c,!1,l,o);r.push({method:"getTokenAccountBalance",params:[i.toBase58(),{commitment:this.networkInfo.commitment,encoding:"jsonParsed"}]})}const f=yield this.fetchRpcBulk(r),[m,...I]=f,P=W(m);this.updateBalance(this.chainCode,P.result.value.toString());for(const[C,i]of a.entries()){const T=(0,n.Vk)(K)(I[C]),S=(s=(t=(e=T==null?void 0:T.result)==null?void 0:e.value)==null?void 0:t.amount)!=null?s:"0";this.updateBalance(this.allTokensMap[i].currencyCode,S)}}catch(r){this.error(`Error checking ${this.chainCode} address balance`,r)}})}queryBlockheight(){return v(this,null,function*(){try{const e=(0,n.mH)(yield this.fetchRpc("getSlot"));e>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(e){this.error("queryBlockheight Error ",e)}})}queryMinimumBalance(){return v(this,null,function*(){try{const e=(0,n.mH)(yield this.fetchRpc("getMinimumBalanceForRentExemption",[50]));this.minimumAddressBalance=e.toString()}catch(e){this.error("queryMinimumBalance Error ",e)}})}queryFee(){return v(this,null,function*(){try{const e=yield this.fetchRpc("getRecentPrioritizationFees"),s=k(e).sort((r,a)=>r.slot-a.slot)[0];this.priorityFee=s.prioritizationFee.toString()}catch(e){this.error("queryFee Error ",e)}})}queryBlockhash(){return v(this,null,function*(){try{const e=yield this.fetchRpc("getLatestBlockhash"),{blockhash:t}=y(e).value;this.recentBlockhash=t}catch(e){this.error("queryBlockhash Error ",e)}})}processSolanaTransaction(e,t,s){const r=[],{amount:a,networkFee:c,parentNetworkFee:l,tokenId:o}=t,f=o!=null?this.allTokensMap[o].currencyCode:this.chainCode;(0,u.gte)(a,"0")&&r.push(this.base58PublicKey);const m={blockHeight:e.slot,currencyCode:f,date:s,isSend:a.startsWith("-"),memos:[],nativeAmount:a,networkFee:c,ourReceiveAddresses:r,parentNetworkFee:l,signedTx:"",txid:e.transaction.signatures[0],walletId:this.walletId};this.addTransaction(f,m)}parseTxAmounts(e){var t;const s=[],r=e.transaction.message.accountKeys.findIndex(i=>i.pubkey===this.base58PublicKey);if(r<0||e.meta==null)return s;const{fee:a,preBalances:c,postBalances:l,preTokenBalances:o,postTokenBalances:f}=e.meta,m=a.toString(),I=(l[r]-c[r]).toString();if(I!=="0"){const i=(0,u.lt)(I,"0");s.push({amount:i?(0,u.sub)(I,m):I,networkFee:i?m:"0"})}const P=i=>i==null||i.owner!==this.base58PublicKey||i.programId!==this.networkInfo.tokenPublicKey||this.allTokensMap[i.mint]==null,C=new Map;for(const i of f)i==null||P(i)||C.set(i.mint,i.uiTokenAmount.amount);for(const i of o){if(i==null||P(i))continue;const T=(t=C.get(i.mint))!=null?t:"0";C.set(i.mint,(0,u.sub)(T,i.uiTokenAmount.amount))}return C.forEach((i,T)=>{s.push({amount:i,networkFee:"0",parentNetworkFee:(0,u.lt)(i,"0")?m:void 0,tokenId:T})}),s}queryTransactions(){return v(this,null,function*(){var e;let t=null;const s=this.otherData.newestTxid!==""?this.otherData.newestTxid:null;let r=[];try{for(;;){const o=[this.base58PublicKey,{until:s,before:t,limit:this.networkInfo.txQueryLimit,commitment:this.networkInfo.commitment}],f=yield this.fetchRpcBulk([{method:"getSignaturesForAddress",params:o}],this.networkInfo.rpcNodesArchival),m=p(f)[0].result;if(r=r.concat(m),m.length<this.networkInfo.txQueryLimit)break;t=m[this.networkInfo.txQueryLimit-1].signature}}catch(o){this.error("getTransactionSignatures failed with error: ",o);return}if(r.length===0){this.updateTxStatus(1),this.updateOnAddressesChecked();return}const a=50;let c=0;const l=r.map(o=>({method:"getTransaction",params:[o.signature,{encoding:"jsonParsed",commitment:this.networkInfo.commitment,maxSupportedTransactionVersion:0}]})).reverse();for(let o=0;o<l.length;o+=a){const f=l.slice(o,o+a>l.length-1?void 0:o+a),m=yield this.fetchRpcBulk(f,this.networkInfo.rpcNodesArchival),P=m.map(i=>V(i).result.slot).map(i=>({method:"getBlockTime",params:[i]})),C=yield this.fetchRpcBulk(P,this.networkInfo.rpcNodesArchival);for(let i=0;i<m.length;i++){if(((e=m[i].result.meta)==null?void 0:e.err)!=null)continue;this.parseTxAmounts(m[i].result).forEach(J=>{this.processSolanaTransaction(m[i].result,J,_(C[i]).result),c++}),this.otherData.newestTxid=r[i].signature;const S=1-c/r.length;S!==this.progressRatio&&(Math.abs(S-this.progressRatio)>.25||S===1)&&(this.progressRatio=S,this.updateTxStatus(this.progressRatio),this.updateOnAddressesChecked())}}this.walletLocalDataDirty=!0,this.updateTxStatus(1),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}updateTxStatus(e){[this.chainCode,...this.enabledTokenIds.map(s=>this.allTokensMap[s].currencyCode)].forEach(s=>{this.tokenCheckTransactionsStatus[s]=e}),this.updateOnAddressesChecked()}startEngine(){return v(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBlockheight",Y).catch(()=>{}),this.addToLoop("queryMinimumBalance",Y).catch(()=>{}),this.addToLoop("queryFee",Y).catch(()=>{}),this.addToLoop("queryBlockhash",Y).catch(()=>{}),this.addToLoop("queryBalance",Me).catch(()=>{}),this.addToLoop("queryTransactions",Fe).catch(()=>{}),yield Ke(ae.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return v(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return v(this,null,function*(){const{currencyCode:t}=e,s=this.getBalance({currencyCode:t});e.spendTargets[0].nativeAmount="1";const r=yield this.makeSpend(e);let a;if(t===this.currencyInfo.currencyCode)a=(0,u.sub)(s,r.networkFee);else{const c=this.getBalance({currencyCode:this.currencyInfo.currencyCode}),l=(0,u.sub)(c,r.networkFee);if((0,u.lt)((0,u.sub)(l,this.minimumAddressBalance),"0"))throw new N.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:this.feePerSignature});a=s}if((0,u.lt)(a,"0"))throw new N.C_;return a})}makeSpend(e){return v(this,null,function*(){var t,s,r;e=(0,Ce.s)(e,this.currencyInfo);const{edgeSpendInfo:a,currencyCode:c}=this.makeSpendCheck(e),{customNetworkFee:l,memos:o=[],networkFeeOption:f,tokenId:m}=a;if(a.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:I,publicAddress:P}=a.spendTargets[0];if(P==null)throw new Error("makeSpend Missing publicAddress");if(I==null)throw new N.$D;const C=m!=null;let i="0",T=this.feePerSignature,S;const J=(t=this.walletLocalData.totalBalances[c])!=null?t:"0",$=new O(this.base58PublicKey),ce=new O(P),te=new O(this.networkInfo.tokenPublicKey),le=new O(this.networkInfo.associatedTokenPublicKey),$e={recentBlockhash:this.recentBlockhash,feePayer:$},X=new fe($e);let D="0";switch(f){case"low":D=(0,u.max)("0",(0,u.mul)(this.priorityFee,"0.75"));break;case"standard":D=this.priorityFee;break;case"high":D=(0,u.max)("1",(0,u.mul)(this.priorityFee,"1.25"));break;case"custom":{D=ge(l).microLamports;break}}if((0,u.gt)(D,"0")){const U=Oe.setComputeUnitPrice({microLamports:parseInt(D)});X.add(U),T=(0,u.add)(T,D)}if(C){const U=new O(m),ue=yield(0,ie.Am)(U,ce,!1,te,le);let ne=this.addressCache.get(P);if(ne===void 0&&(Z(yield this.fetchRpc("getAccountInfo",[ue.toBase58(),{commitment:this.networkInfo.commitment,encoding:"jsonParsed"}])).value==null?(ne=!1,this.addressCache.set(P,!1)):(ne=!0,this.addressCache.set(P,!0))),ne||(X.add((0,ke.Ek)($,ue,ce,U,te,le)),T=(0,u.add)(T,this.feePerSignature)),S=T,T="0",i=I,(0,u.gt)(I,J))throw new N.C_;const ze=(s=this.walletLocalData.totalBalances[this.chainCode])!=null?s:"0";if((0,u.gt)((0,u.add)(S,this.minimumAddressBalance),ze))throw new N.C_({currencyCode:this.chainCode,networkFee:S});const We=yield(0,ie.Am)(U,$,!1,te,le);X.add((0,we.$B)(We,ue,$,BigInt(I),[],te))}else i=(0,u.add)(I,T),X.add(Re.transfer({fromPubkey:$,toPubkey:ce,lamports:parseInt(I)}));if(!(0,u.eq)(i,J)){if((0,u.gt)((0,u.add)(i,this.minimumAddressBalance),J))throw new N.C_}if(((r=o[0])==null?void 0:r.type)==="text"){const U=new Le({keys:[{pubkey:$,isSigner:!0,isWritable:!0}],programId:new O(this.networkInfo.memoPublicKey),data:Ie.from(Te.K.parse(o[0].value))});X.add(U)}const Xe={unsignedSerializedSolTx:X.serialize({requireAllSignatures:!1})};return{blockHeight:0,currencyCode:c,date:0,isSend:!0,memos:o,nativeAmount:(0,u.mul)(i,"-1"),networkFee:T,otherParams:Xe,ourReceiveAddresses:[],parentNetworkFee:S,signedTx:"",txid:"",walletId:this.walletId}})}signTx(e,t){return v(this,null,function*(){const s=w(this.currencyInfo.pluginId)(t),{unsignedSerializedSolTx:r}=(0,M.Xp)(e);if(r==null)throw new Error("Missing unsignedSerializedSolTx");const a=xe.fromSecretKey(Uint8Array.from(A.YU.parse(s.privateKey))),c=fe.from(r);return c.recentBlockhash=this.recentBlockhash,c.sign({publicKey:a.publicKey,secretKey:a.secretKey}),e.signedTx=c.serialize().toString("base64"),this.warn(`signTx
2
+ ${(0,M.oX)(e)}`),this.addressCache=new Map(Array.from(this.addressCache.entries()).filter(([l,o])=>o)),e})}broadcastTx(e){return v(this,null,function*(){if(e.signedTx==null)throw new Error("Missing signedTx");try{const t=[e.signedTx,{encoding:"base64"}],s=(0,n.XC)(yield this.fetchRpc("sendTransaction",t));e.txid=s,e.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
3
+ ${(0,M.oX)(e)}`)}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}return e})}}function De(d,e,t,s){return v(this,null,function*(){const r=g(t),a=new ae(d,e,r,s);return yield a.loadEngine(),a})}var x=(d,e,t)=>new Promise((s,r)=>{var a=o=>{try{l(t.next(o))}catch(f){r(f)}},c=o=>{try{l(t.throw(o))}catch(f){r(f)}},l=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,c);l((t=t.apply(d,e)).next())});const{Keypair:Ue,PublicKey:ee}=L,He=(d,e)=>x(void 0,null,function*(){const t=yield(0,b.mnemonicToSeed)(d),s=E.derivePath(e,A.YU.stringify(t)).key;return Ue.fromSeed(Uint8Array.from(s))});class pe{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:a}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=a}getDisplayPrivateKey(e){return x(this,null,function*(){const{pluginId:t}=this.currencyInfo;return w(t)(e.keys).mnemonic})}getDisplayPublicKey(e){return x(this,null,function*(){const{keys:t}=g(e);return t.publicKey})}importPrivateKey(e){return x(this,null,function*(){const{pluginId:t}=this.currencyInfo;if(!(0,b.validateMnemonic)(e))throw new Error("Invalid mnemonic");const r=yield He(e,this.networkInfo.derivationPath);return{[`${t}Mnemonic`]:e,[`${t}Key`]:B.Buffer.from(r.secretKey).toString("hex"),publicKey:r.publicKey.toBase58()}})}createPrivateKey(e){return x(this,null,function*(){if(e!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=B.Buffer.from(this.io.random(32)),s=(0,b.entropyToMnemonic)(t);return yield this.importPrivateKey(s)})}derivePublicKey(e){return x(this,null,function*(){const{pluginId:t}=this.currencyInfo;if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");if(e.keys[`${t}Mnemonic`]==null)throw new Error("Missing mnemonic");return{publicKey:(yield this.importPrivateKey(e.keys[`${t}Mnemonic`])).publicKey.toString()}})}parseUri(e,t,s){return x(this,null,function*(){const{pluginId:r}=this.currencyInfo,a={[r]:!0},{parsedUri:c,edgeParsedUri:l}=(0,z.k)(this.currencyInfo,e,a,t!=null?t:this.currencyInfo.currencyCode,s);let o="";if(l.publicAddress!=null&&(o=l.publicAddress),!ee.isOnCurve(new ee(o).toBytes()))throw new Error("InvalidPublicAddressError");return l.uniqueIdentifier=c.query.memo,l})}encodeUri(e){return x(this,arguments,function*(t,s=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:a,currencyCode:c,publicAddress:l}=t;if(!ee.isOnCurve(new ee(l).toBytes()))throw new Error("InvalidPublicAddressError");let o;if(typeof a=="string"){const m=(0,M.Qs)(c!=null?c:this.currencyInfo.currencyCode,this.currencyInfo,s);if(m==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,u.div)(a,m.multiplier,18)}return(0,z.Q)(t,r,o)})}getTokenId(e){return x(this,null,function*(){(0,F.Rp)(e);const t=(0,F.Oj)(e.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress})}}function Ne(d){return x(this,null,function*(){return new pe(d)})}},52361:function(){},94616:function(){},55024:function(){}}]);
@@ -1068,7 +1068,7 @@ const networkInfo = {
1068
1068
  'https://eth-mainnet.alchemyapi.io/v2/-{{alchemyApiKey}}',
1069
1069
  'https://mainnet.infura.io/v3/{{infuraProjectId}}',
1070
1070
  'https://rpc.ankr.com/eth',
1071
- 'https://eth-mainnet.gateway.pokt.network/v1/lb/{{poktPortalApiKey}}',
1071
+ 'https://eth-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}',
1072
1072
  'https://cloudflare-eth.com'
1073
1073
  ],
1074
1074
  ethBalCheckerContract: '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39'
@@ -277,7 +277,7 @@ const networkInfo = {
277
277
  {
278
278
  type: 'rpc',
279
279
  servers: [
280
- 'https://fantom-mainnet.gateway.pokt.network/v1/lb/{{poktPortalApiKey}}',
280
+ 'https://fantom-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}',
281
281
  'https://polished-empty-cloud.fantom.quiknode.pro/{{quiknodeApiKey}}/',
282
282
  'https://rpc.ankr.com/fantom',
283
283
  'https://rpc.ftm.tools'
@@ -96,7 +96,7 @@ const networkInfo = {
96
96
  {
97
97
  type: 'rpc',
98
98
  servers: [
99
- 'https://eth-goerli.gateway.pokt.network/v1/lb/{{poktPortalApiKey}}',
99
+ 'https://eth-goerli.rpc.grove.city/v1/{{poktPortalApiKey}}',
100
100
  'https://eth-goerli.alchemyapi.io/v2/-{{alchemyApiKey}}',
101
101
  'https://goerli.infura.io/v3/{{infuraProjectId}}'
102
102
  ]
@@ -170,7 +170,7 @@ const networkInfo = {
170
170
  'https://rpc-mainnet.maticvigil.com',
171
171
  'https://matic-mainnet.chainstacklabs.com',
172
172
  'https://rpc.ankr.com/polygon',
173
- 'https://poly-mainnet.gateway.pokt.network/v1/lb/{{poktPortalApiKey}}',
173
+ 'https://poly-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}',
174
174
  'https://rpc-mainnet.matic.quiknode.pro/{{quiknodeApiKey}}/'
175
175
  ],
176
176
  ethBalCheckerContract: '0x2352c63A83f9Fd126af8676146721Fa00924d7e4'
@@ -49,12 +49,15 @@ var _utils = require('../common/utils');
49
49
 
50
50
 
51
51
 
52
+
53
+
52
54
 
53
55
 
54
56
 
55
57
  var _solanaTypes = require('./solanaTypes');
56
58
 
57
59
  const {
60
+ ComputeBudgetProgram,
58
61
  PublicKey,
59
62
  Keypair,
60
63
  SystemProgram,
@@ -81,6 +84,7 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
81
84
 
82
85
 
83
86
 
87
+
84
88
 
85
89
  constructor(
86
90
  env,
@@ -94,6 +98,7 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
94
98
  this.chainCode = tools.currencyInfo.currencyCode
95
99
  this.fetchCors = _utils.getFetchCors.call(void 0, env.io)
96
100
  this.feePerSignature = '5000'
101
+ this.priorityFee = '0'
97
102
  this.recentBlockhash = '' // must be < ~2min old to send tx
98
103
  this.base58PublicKey = walletInfo.keys.publicKey
99
104
  this.progressRatio = 0
@@ -251,18 +256,28 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
251
256
 
252
257
  async queryFee() {
253
258
  try {
254
- const response = await this.fetchRpc('getRecentBlockhash')
255
- const {
256
- blockhash,
257
- feeCalculator: { lamportsPerSignature }
258
- } = _solanaTypes.asRecentBlockHash.call(void 0, response).value
259
- this.feePerSignature = lamportsPerSignature.toString()
260
- this.recentBlockhash = blockhash
259
+ const response = await this.fetchRpc('getRecentPrioritizationFees')
260
+ const recentPriorityFees = _solanaTypes.asGetRecentPrioritizationFees.call(void 0, response)
261
+ // if the array is empty, or request otherwise fails, it's ok to just use the default
262
+ const latestPriorityFee = recentPriorityFees.sort(
263
+ (a, b) => a.slot - b.slot
264
+ )[0]
265
+ this.priorityFee = latestPriorityFee.prioritizationFee.toString()
261
266
  } catch (e) {
262
267
  this.error(`queryFee Error `, e)
263
268
  }
264
269
  }
265
270
 
271
+ async queryBlockhash() {
272
+ try {
273
+ const response = await this.fetchRpc('getLatestBlockhash')
274
+ const { blockhash } = _solanaTypes.asLatestBlockhash.call(void 0, response).value
275
+ this.recentBlockhash = blockhash
276
+ } catch (e) {
277
+ this.error(`queryBlockhash Error `, e)
278
+ }
279
+ }
280
+
266
281
  processSolanaTransaction(
267
282
  tx,
268
283
  amounts,
@@ -498,6 +513,9 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
498
513
  () => {}
499
514
  )
500
515
  this.addToLoop('queryFee', BLOCKCHAIN_POLL_MILLISECONDS).catch(() => {})
516
+ this.addToLoop('queryBlockhash', BLOCKCHAIN_POLL_MILLISECONDS).catch(
517
+ () => {}
518
+ )
501
519
  this.addToLoop('queryBalance', ACCOUNT_POLL_MILLISECONDS).catch(() => {})
502
520
  this.addToLoop('queryTransactions', TRANSACTION_POLL_MILLISECONDS).catch(
503
521
  () => {}
@@ -514,22 +532,28 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
514
532
  async getMaxSpendable(spendInfo) {
515
533
  // todo: Stop using deprecated currencyCode
516
534
  const { currencyCode } = spendInfo
517
- let spendableBalance = this.getBalance({
535
+ const balance = this.getBalance({
518
536
  currencyCode
519
537
  })
520
538
 
539
+ spendInfo.spendTargets[0].nativeAmount = '1'
540
+ const edgeTx = await this.makeSpend(spendInfo)
541
+
542
+ let spendableBalance
521
543
  if (currencyCode === this.currencyInfo.currencyCode) {
522
- spendableBalance = _biggystring.sub.call(void 0, spendableBalance, this.feePerSignature)
544
+ spendableBalance = _biggystring.sub.call(void 0, balance, edgeTx.networkFee)
523
545
  } else {
524
546
  const solBalance = this.getBalance({
525
547
  currencyCode: this.currencyInfo.currencyCode
526
548
  })
527
- if (_biggystring.lt.call(void 0, _biggystring.sub.call(void 0, solBalance, this.minimumAddressBalance), '0')) {
549
+ const solRequired = _biggystring.sub.call(void 0, solBalance, edgeTx.networkFee)
550
+ if (_biggystring.lt.call(void 0, _biggystring.sub.call(void 0, solRequired, this.minimumAddressBalance), '0')) {
528
551
  throw new (0, _types.InsufficientFundsError)({
529
552
  currencyCode: this.currencyInfo.currencyCode,
530
553
  networkFee: this.feePerSignature
531
554
  })
532
555
  }
556
+ spendableBalance = balance
533
557
  }
534
558
  if (_biggystring.lt.call(void 0, spendableBalance, '0')) throw new (0, _types.InsufficientFundsError)()
535
559
 
@@ -539,7 +563,12 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
539
563
  async makeSpend(edgeSpendInfoIn) {
540
564
  edgeSpendInfoIn = _upgradeMemos.upgradeMemos.call(void 0, edgeSpendInfoIn, this.currencyInfo)
541
565
  const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn)
542
- const { memos = [], tokenId } = edgeSpendInfo
566
+ const {
567
+ customNetworkFee,
568
+ memos = [],
569
+ networkFeeOption,
570
+ tokenId
571
+ } = edgeSpendInfo
543
572
 
544
573
  if (edgeSpendInfo.spendTargets.length !== 1) {
545
574
  throw new Error('Error: only one output allowed')
@@ -571,6 +600,33 @@ const TRANSACTION_POLL_MILLISECONDS = 3000
571
600
  feePayer: payer
572
601
  }
573
602
  const solTx = new Transaction(txOpts)
603
+
604
+ // calculate priority fee. Multipliers are arbitrary just to establish some ranges
605
+ let microLamports = '0'
606
+ switch (networkFeeOption) {
607
+ case 'low':
608
+ microLamports = _biggystring.max.call(void 0, '0', _biggystring.mul.call(void 0, this.priorityFee, '0.75'))
609
+ break
610
+ case 'standard':
611
+ microLamports = this.priorityFee
612
+ break
613
+ case 'high':
614
+ microLamports = _biggystring.max.call(void 0, '1', _biggystring.mul.call(void 0, this.priorityFee, '1.25'))
615
+ break
616
+ case 'custom': {
617
+ microLamports = _solanaTypes.asSolanaCustomFee.call(void 0, customNetworkFee).microLamports
618
+ break
619
+ }
620
+ }
621
+
622
+ if (_biggystring.gt.call(void 0, microLamports, '0')) {
623
+ const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
624
+ microLamports: parseInt(microLamports)
625
+ })
626
+ solTx.add(priorityFeeInstruction)
627
+ nativeNetworkFee = _biggystring.add.call(void 0, nativeNetworkFee, microLamports)
628
+ }
629
+
574
630
  if (isTokenTx) {
575
631
  const TOKEN = new PublicKey(tokenId)
576
632
 
@@ -67,7 +67,7 @@ const builtinTokens = {
67
67
  const networkInfo = {
68
68
  rpcNodes: [
69
69
  'https://api.mainnet-beta.solana.com',
70
- 'https://solana-mainnet.gateway.pokt.network/v1/lb/{{poktPortalApiKey}}' // fails to return some transactions
70
+ 'https://solana-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}' // fails to return some transactions
71
71
  ],
72
72
  rpcNodesArchival: [
73
73
  'https://api.mainnet-beta.solana.com',
@@ -103,7 +103,7 @@ const currencyInfo = {
103
103
  memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 32 }],
104
104
 
105
105
  // Deprecated:
106
- defaultSettings: {},
106
+ defaultSettings: { customFeeSettings: ['microLamports'] },
107
107
  memoType: 'text',
108
108
  metaTokens: _tokenHelpers.makeMetaTokens.call(void 0, builtinTokens)
109
109
  }
@@ -44,14 +44,15 @@ var _types = require('../common/types');
44
44
 
45
45
 
46
46
 
47
- const asRecentBlockHash = _cleaners.asObject.call(void 0, {
47
+ const asLatestBlockhash = _cleaners.asObject.call(void 0, {
48
48
  value: _cleaners.asObject.call(void 0, {
49
- blockhash: _cleaners.asString,
50
- feeCalculator: _cleaners.asObject.call(void 0, {
51
- lamportsPerSignature: _cleaners.asNumber
52
- })
49
+ blockhash: _cleaners.asString
53
50
  })
54
- }); exports.asRecentBlockHash = asRecentBlockHash
51
+ }); exports.asLatestBlockhash = asLatestBlockhash
52
+
53
+ const asGetRecentPrioritizationFees = _cleaners.asArray.call(void 0,
54
+ _cleaners.asObject.call(void 0, { prioritizationFee: _cleaners.asNumber, slot: _cleaners.asNumber })
55
+ ); exports.asGetRecentPrioritizationFees = asGetRecentPrioritizationFees
55
56
 
56
57
 
57
58
  const asSafeSolanaWalletInfo = _types.asSafeCommonWalletInfo; exports.asSafeSolanaWalletInfo = asSafeSolanaWalletInfo
@@ -184,3 +185,7 @@ const asTxTokenBalance = _cleaners.asObject.call(void 0, {
184
185
  alchemyApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString),
185
186
  poktPortalApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString)
186
187
  }); exports.asSolanaInitOptions = asSolanaInitOptions
188
+
189
+ const asSolanaCustomFee = _cleaners.asObject.call(void 0, {
190
+ microLamports: _cleaners.asString
191
+ }); exports.asSolanaCustomFee = asSolanaCustomFee
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[533],{57010:function(kt,Et,ft){ft.d(Et,{K:function(){return T},M:function(){return lt}});var ot=ft(55525),A=ft(27499);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const z=BigInt(0),at=BigInt(1);function lt(C,v){const K=(E,N)=>{const p=N.negate();return E?p:N},dt=E=>{const N=Math.ceil(v/E)+1,p=2**(E-1);return{windows:N,windowSize:p}};return{constTimeNegate:K,unsafeLadder(E,N){let p=C.ZERO,h=E;for(;N>z;)N&at&&(p=p.add(h)),h=h.double(),N>>=at;return p},precomputeWindow(E,N){const{windows:p,windowSize:h}=dt(N),I=[];let _=E,P=_;for(let et=0;et<p;et++){P=_,I.push(P);for(let Y=1;Y<h;Y++)P=P.add(_),I.push(P);_=P.double()}return I},wNAF(E,N,p){const{windows:h,windowSize:I}=dt(E);let _=C.ZERO,P=C.BASE;const et=BigInt(2**E-1),Y=2**E,j=BigInt(E);for(let st=0;st<h;st++){const gt=st*I;let f=Number(p&et);p>>=j,f>I&&(f-=Y,p+=at);const S=gt,G=gt+Math.abs(f)-1,tt=st%2!==0,nt=f<0;f===0?P=P.add(K(tt,N[S])):_=_.add(K(nt,N[G]))}return{p:_,f:P}},wNAFCached(E,N,p,h){const I=E._WINDOW_SIZE||1;let _=N.get(E);return _||(_=this.precomputeWindow(E,I),I!==1&&N.set(E,h(_))),this.wNAF(I,_,p)}}}function T(C){return(0,ot.OP)(C.Fp),(0,A.validateObject)(C,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,ot.kK)(C.n,C.nBitLength),...C,p:C.Fp.ORDER})}},42017:function(kt,Et,ft){var ot=ft(55525),A=ft(27499);function z(h){if(h instanceof Uint8Array)return h;if(typeof h=="string")return utf8ToBytes(h);throw new Error("DST must be Uint8Array or string")}const at=null;function lt(h,I){if(h<0||h>=1<<8*I)throw new Error(`bad I2OSP call: value=${h} length=${I}`);const _=Array.from({length:I}).fill(0);for(let P=I-1;P>=0;P--)_[P]=h&255,h>>>=8;return new Uint8Array(_)}function T(h,I){const _=new Uint8Array(h.length);for(let P=0;P<h.length;P++)_[P]=h[P]^I[P];return _}function C(h){if(!(h instanceof Uint8Array))throw new Error("Uint8Array expected")}function v(h){if(!Number.isSafeInteger(h))throw new Error("number expected")}function K(h,I,_,P){C(h),C(I),v(_),I.length>255&&(I=P(concatBytes(utf8ToBytes("H2C-OVERSIZE-DST-"),I)));const{outputLen:et,blockLen:Y}=P,j=Math.ceil(_/et);if(j>255)throw new Error("Invalid xmd length");const st=concatBytes(I,lt(I.length,1)),gt=lt(0,Y),f=lt(_,2),S=new Array(j),G=P(concatBytes(gt,h,f,lt(0,1),st));S[0]=P(concatBytes(G,lt(1,1),st));for(let nt=1;nt<=j;nt++){const o=[T(G,S[nt-1]),lt(nt+1,1),st];S[nt]=P(concatBytes(...o))}return concatBytes(...S).slice(0,_)}function dt(h,I,_,P,et){if(C(h),C(I),v(_),I.length>255){const Y=Math.ceil(2*P/8);I=et.create({dkLen:Y}).update(utf8ToBytes("H2C-OVERSIZE-DST-")).update(I).digest()}if(_>65535||I.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return et.create({dkLen:_}).update(h).update(lt(_,2)).update(I).update(lt(I.length,1)).digest()}function E(h,I,_){validateObject(_,{DST:"string",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:P,k:et,m:Y,hash:j,expand:st,DST:gt}=_;C(h),v(I);const f=z(gt),S=P.toString(2).length,G=Math.ceil((S+et)/8),tt=I*Y*G;let nt;if(st==="xmd")nt=K(h,f,tt,j);else if(st==="xof")nt=dt(h,f,tt,et,j);else if(st==="_internal_pass")nt=h;else throw new Error('expand must be "xmd" or "xof"');const o=new Array(I);for(let r=0;r<I;r++){const c=new Array(Y);for(let s=0;s<Y;s++){const u=G*(s+r*Y),R=nt.subarray(u,u+G);c[s]=mod(at(R),P)}o[r]=c}return o}function N(h,I){const _=I.map(P=>Array.from(P).reverse());return(P,et)=>{const[Y,j,st,gt]=_.map(f=>f.reduce((S,G)=>h.add(h.mul(S,P),G)));return P=h.div(Y,j),et=h.mul(et,h.div(st,gt)),{x:P,y:et}}}function p(h,I,_){if(typeof I!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(P,et){const Y=E(P,2,{..._,DST:_.DST,...et}),j=h.fromAffine(I(Y[0])),st=h.fromAffine(I(Y[1])),gt=j.add(st).clearCofactor();return gt.assertValidity(),gt},encodeToCurve(P,et){const Y=E(P,1,{..._,DST:_.encodeDST,...et}),j=h.fromAffine(I(Y[0])).clearCofactor();return j.assertValidity(),j}}}},55525:function(kt,Et,ft){ft.d(Et,{DV:function(){return nt},OP:function(){return Y},Pu:function(){return o},Tu:function(){return P},U_:function(){return h},gN:function(){return G},kK:function(){return S},oA:function(){return p},wQ:function(){return E}});var ot=ft(27499);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const A=BigInt(0),z=BigInt(1),at=BigInt(2),lt=BigInt(3),T=BigInt(4),C=BigInt(5),v=BigInt(8),K=BigInt(9),dt=BigInt(16);function E(r,c){const s=r%c;return s>=A?s:c+s}function N(r,c,s){if(s<=A||c<A)throw new Error("Expected power/modulo > 0");if(s===z)return A;let u=z;for(;c>A;)c&z&&(u=u*r%s),r=r*r%s,c>>=z;return u}function p(r,c,s){let u=r;for(;c-- >A;)u*=u,u%=s;return u}function h(r,c){if(r===A||c<=A)throw new Error(`invert: expected positive integers, got n=${r} mod=${c}`);let s=E(r,c),u=c,R=A,Q=z,rt=z,k=A;for(;s!==A;){const X=u/s,bt=u%s,Bt=R-rt*X,pt=Q-k*X;u=s,s=bt,R=rt,Q=k,rt=Bt,k=pt}if(u!==z)throw new Error("invert: does not exist");return E(R,c)}function I(r){const c=(r-z)/at;let s,u,R;for(s=r-z,u=0;s%at===A;s/=at,u++);for(R=at;R<r&&N(R,c,r)!==r-z;R++);if(u===1){const rt=(r+z)/T;return function(b,X){const bt=b.pow(X,rt);if(!b.eql(b.sqr(bt),X))throw new Error("Cannot find square root");return bt}}const Q=(s+z)/at;return function(k,b){if(k.pow(b,c)===k.neg(k.ONE))throw new Error("Cannot find square root");let X=u,bt=k.pow(k.mul(k.ONE,R),s),Bt=k.pow(b,Q),pt=k.pow(b,s);for(;!k.eql(pt,k.ONE);){if(k.eql(pt,k.ZERO))return k.ZERO;let Ot=1;for(let Rt=k.sqr(pt);Ot<X&&!k.eql(Rt,k.ONE);Ot++)Rt=k.sqr(Rt);const qt=k.pow(bt,z<<BigInt(X-Ot-1));bt=k.sqr(qt),Bt=k.mul(Bt,qt),pt=k.mul(pt,bt),X=Ot}return Bt}}function _(r){if(r%T===lt){const c=(r+z)/T;return function(u,R){const Q=u.pow(R,c);if(!u.eql(u.sqr(Q),R))throw new Error("Cannot find square root");return Q}}if(r%v===C){const c=(r-C)/v;return function(u,R){const Q=u.mul(R,at),rt=u.pow(Q,c),k=u.mul(R,rt),b=u.mul(u.mul(k,at),rt),X=u.mul(k,u.sub(b,u.ONE));if(!u.eql(u.sqr(X),R))throw new Error("Cannot find square root");return X}}return r%dt,I(r)}const P=(r,c)=>(E(r,c)&z)===z,et=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Y(r){const c={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},s=et.reduce((u,R)=>(u[R]="function",u),c);return(0,ot.validateObject)(r,s)}function j(r,c,s){if(s<A)throw new Error("Expected power > 0");if(s===A)return r.ONE;if(s===z)return c;let u=r.ONE,R=c;for(;s>A;)s&z&&(u=r.mul(u,R)),R=r.sqr(R),s>>=z;return u}function st(r,c){const s=new Array(c.length),u=c.reduce((Q,rt,k)=>r.is0(rt)?Q:(s[k]=Q,r.mul(Q,rt)),r.ONE),R=r.inv(u);return c.reduceRight((Q,rt,k)=>r.is0(rt)?Q:(s[k]=r.mul(Q,s[k]),r.mul(Q,rt)),R),s}function gt(r,c,s){return r.mul(c,typeof s=="bigint"?h(s,r.ORDER):r.inv(s))}function f(r){const c=(r.ORDER-z)/at;return s=>{const u=r.pow(s,c);return r.eql(u,r.ZERO)||r.eql(u,r.ONE)}}function S(r,c){const s=c!==void 0?c:r.toString(2).length,u=Math.ceil(s/8);return{nBitLength:s,nByteLength:u}}function G(r,c,s=!1,u={}){if(r<=A)throw new Error(`Expected Fp ORDER > 0, got ${r}`);const{nBitLength:R,nByteLength:Q}=S(r,c);if(Q>2048)throw new Error("Field lengths over 2048 bytes are not supported");const rt=_(r),k=Object.freeze({ORDER:r,BITS:R,BYTES:Q,MASK:(0,ot.bitMask)(R),ZERO:A,ONE:z,create:b=>E(b,r),isValid:b=>{if(typeof b!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof b}`);return A<=b&&b<r},is0:b=>b===A,isOdd:b=>(b&z)===z,neg:b=>E(-b,r),eql:(b,X)=>b===X,sqr:b=>E(b*b,r),add:(b,X)=>E(b+X,r),sub:(b,X)=>E(b-X,r),mul:(b,X)=>E(b*X,r),pow:(b,X)=>j(k,b,X),div:(b,X)=>E(b*h(X,r),r),sqrN:b=>b*b,addN:(b,X)=>b+X,subN:(b,X)=>b-X,mulN:(b,X)=>b*X,inv:b=>h(b,r),sqrt:u.sqrt||(b=>rt(k,b)),invertBatch:b=>st(k,b),cmov:(b,X,bt)=>bt?X:b,toBytes:b=>s?(0,ot.numberToBytesLE)(b,Q):(0,ot.numberToBytesBE)(b,Q),fromBytes:b=>{if(b.length!==Q)throw new Error(`Fp.fromBytes: expected ${Q}, got ${b.length}`);return s?(0,ot.bytesToNumberLE)(b):(0,ot.bytesToNumberBE)(b)}});return Object.freeze(k)}function tt(r,c){if(!r.isOdd)throw new Error("Field doesn't have isOdd");const s=r.sqrt(c);return r.isOdd(s)?s:r.neg(s)}function nt(r,c){if(!r.isOdd)throw new Error("Field doesn't have isOdd");const s=r.sqrt(c);return r.isOdd(s)?r.neg(s):s}function o(r,c,s=!1){r=(0,ot.ensureBytes)("privateHash",r);const u=r.length,R=S(c).nByteLength+8;if(R<24||u<R||u>1024)throw new Error(`hashToPrivateScalar: expected ${R}-1024 bytes of input, got ${u}`);const Q=s?(0,ot.bytesToNumberLE)(r):(0,ot.bytesToNumberBE)(r);return E(Q,c-z)+z}},27499:function(kt,Et,ft){ft.r(Et),ft.d(Et,{bitGet:function(){return j},bitLen:function(){return Y},bitMask:function(){return gt},bitSet:function(){return st},bytesToHex:function(){return T},bytesToNumberBE:function(){return dt},bytesToNumberLE:function(){return E},concatBytes:function(){return _},createHmacDrbg:function(){return G},ensureBytes:function(){return I},equalBytes:function(){return P},hexToBytes:function(){return K},hexToNumber:function(){return v},numberToBytesBE:function(){return N},numberToBytesLE:function(){return p},numberToHexUnpadded:function(){return C},numberToVarBytesBE:function(){return h},utf8ToBytes:function(){return et},validateObject:function(){return nt}});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ot=BigInt(0),A=BigInt(1),z=BigInt(2),at=o=>o instanceof Uint8Array,lt=Array.from({length:256},(o,r)=>r.toString(16).padStart(2,"0"));function T(o){if(!at(o))throw new Error("Uint8Array expected");let r="";for(let c=0;c<o.length;c++)r+=lt[o[c]];return r}function C(o){const r=o.toString(16);return r.length&1?`0${r}`:r}function v(o){if(typeof o!="string")throw new Error("hex string expected, got "+typeof o);return BigInt(o===""?"0":`0x${o}`)}function K(o){if(typeof o!="string")throw new Error("hex string expected, got "+typeof o);const r=o.length;if(r%2)throw new Error("padded hex string expected, got unpadded hex of length "+r);const c=new Uint8Array(r/2);for(let s=0;s<c.length;s++){const u=s*2,R=o.slice(u,u+2),Q=Number.parseInt(R,16);if(Number.isNaN(Q)||Q<0)throw new Error("Invalid byte sequence");c[s]=Q}return c}function dt(o){return v(T(o))}function E(o){if(!at(o))throw new Error("Uint8Array expected");return v(T(Uint8Array.from(o).reverse()))}function N(o,r){return K(o.toString(16).padStart(r*2,"0"))}function p(o,r){return N(o,r).reverse()}function h(o){return K(C(o))}function I(o,r,c){let s;if(typeof r=="string")try{s=K(r)}catch(R){throw new Error(`${o} must be valid hex string, got "${r}". Cause: ${R}`)}else if(at(r))s=Uint8Array.from(r);else throw new Error(`${o} must be hex string or Uint8Array`);const u=s.length;if(typeof c=="number"&&u!==c)throw new Error(`${o} expected ${c} bytes, got ${u}`);return s}function _(...o){const r=new Uint8Array(o.reduce((s,u)=>s+u.length,0));let c=0;return o.forEach(s=>{if(!at(s))throw new Error("Uint8Array expected");r.set(s,c),c+=s.length}),r}function P(o,r){if(o.length!==r.length)return!1;for(let c=0;c<o.length;c++)if(o[c]!==r[c])return!1;return!0}function et(o){if(typeof o!="string")throw new Error(`utf8ToBytes expected string, got ${typeof o}`);return new Uint8Array(new TextEncoder().encode(o))}function Y(o){let r;for(r=0;o>ot;o>>=A,r+=1);return r}function j(o,r){return o>>BigInt(r)&A}const st=(o,r,c)=>o|(c?A:ot)<<BigInt(r),gt=o=>(z<<BigInt(o-1))-A,f=o=>new Uint8Array(o),S=o=>Uint8Array.from(o);function G(o,r,c){if(typeof o!="number"||o<2)throw new Error("hashLen must be a number");if(typeof r!="number"||r<2)throw new Error("qByteLen must be a number");if(typeof c!="function")throw new Error("hmacFn must be a function");let s=f(o),u=f(o),R=0;const Q=()=>{s.fill(1),u.fill(0),R=0},rt=(...bt)=>c(u,s,...bt),k=(bt=f())=>{u=rt(S([0]),bt),s=rt(),bt.length!==0&&(u=rt(S([1]),bt),s=rt())},b=()=>{if(R++>=1e3)throw new Error("drbg: tried 1000 values");let bt=0;const Bt=[];for(;bt<r;){s=rt();const pt=s.slice();Bt.push(pt),bt+=s.length}return _(...Bt)};return(bt,Bt)=>{Q(),k(bt);let pt;for(;!(pt=Bt(b()));)k();return Q(),pt}}const tt={bigint:o=>typeof o=="bigint",function:o=>typeof o=="function",boolean:o=>typeof o=="boolean",string:o=>typeof o=="string",isSafeInteger:o=>Number.isSafeInteger(o),array:o=>Array.isArray(o),field:(o,r)=>r.Fp.isValid(o),hash:o=>typeof o=="function"&&Number.isSafeInteger(o.outputLen)};function nt(o,r,c={}){const s=(u,R,Q)=>{const rt=tt[R];if(typeof rt!="function")throw new Error(`Invalid validator "${R}", expected function`);const k=o[u];if(!(Q&&k===void 0)&&!rt(k,o))throw new Error(`Invalid param ${String(u)}=${k} (${typeof k}), expected ${R}`)};for(const[u,R]of Object.entries(r))s(u,R,!1);for(const[u,R]of Object.entries(c))s(u,R,!0);return o}},60533:function(kt,Et,ft){ft.d(Et,{kA:function(){return Ot}});var ot=ft(38235),A=ft(63321);const z=(n,e,t)=>n&e^~n&t,at=(n,e,t)=>n&e^n&t^e&t,lt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),T=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),C=new Uint32Array(64);class v extends ot.N{constructor(){super(64,32,8,!1),this.A=T[0]|0,this.B=T[1]|0,this.C=T[2]|0,this.D=T[3]|0,this.E=T[4]|0,this.F=T[5]|0,this.G=T[6]|0,this.H=T[7]|0}get(){const{A:e,B:t,C:l,D:O,E:g,F:U,G:x,H:F}=this;return[e,t,l,O,g,U,x,F]}set(e,t,l,O,g,U,x,F){this.A=e|0,this.B=t|0,this.C=l|0,this.D=O|0,this.E=g|0,this.F=U|0,this.G=x|0,this.H=F|0}process(e,t){for(let w=0;w<16;w++,t+=4)C[w]=e.getUint32(t,!1);for(let w=16;w<64;w++){const yt=C[w-15],it=C[w-2],Z=(0,A.np)(yt,7)^(0,A.np)(yt,18)^yt>>>3,i=(0,A.np)(it,17)^(0,A.np)(it,19)^it>>>10;C[w]=i+C[w-7]+Z+C[w-16]|0}let{A:l,B:O,C:g,D:U,E:x,F,G:q,H:D}=this;for(let w=0;w<64;w++){const yt=(0,A.np)(x,6)^(0,A.np)(x,11)^(0,A.np)(x,25),it=D+yt+z(x,F,q)+lt[w]+C[w]|0,i=((0,A.np)(l,2)^(0,A.np)(l,13)^(0,A.np)(l,22))+at(l,O,g)|0;D=q,q=F,F=x,x=U+it|0,U=g,g=O,O=l,l=it+i|0}l=l+this.A|0,O=O+this.B|0,g=g+this.C|0,U=U+this.D|0,x=x+this.E|0,F=F+this.F|0,q=q+this.G|0,D=D+this.H|0,this.set(l,O,g,U,x,F,q,D)}roundClean(){C.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class K extends v{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const dt=(0,A.hE)(()=>new v),E=(0,A.hE)(()=>new K);var N=ft(55525),p=ft(27499),h=ft(57010);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function I(n){const e=(0,h.K)(n);p.validateObject(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:t,Fp:l,a:O}=e;if(t){if(!l.eql(O,l.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:_,hexToBytes:P}=p,et={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(n){const{Err:e}=et;if(n.length<2||n[0]!==2)throw new e("Invalid signature integer tag");const t=n[1],l=n.subarray(2,t+2);if(!t||l.length!==t)throw new e("Invalid signature integer: wrong length");if(l[0]&128)throw new e("Invalid signature integer: negative");if(l[0]===0&&!(l[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:_(l),l:n.subarray(t+2)}},toSig(n){const{Err:e}=et,t=typeof n=="string"?P(n):n;if(!(t instanceof Uint8Array))throw new Error("ui8a expected");let l=t.length;if(l<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==l-2)throw new e("Invalid signature: incorrect length");const{d:O,l:g}=et._parseInt(t.subarray(2)),{d:U,l:x}=et._parseInt(g);if(x.length)throw new e("Invalid signature: left bytes after parsing");return{r:O,s:U}},hexFromSig(n){const e=q=>Number.parseInt(q[0],16)&8?"00"+q:q,t=q=>{const D=q.toString(16);return D.length&1?`0${D}`:D},l=e(t(n.s)),O=e(t(n.r)),g=l.length/2,U=O.length/2,x=t(g),F=t(U);return`30${t(U+g+4)}02${F}${O}02${x}${l}`}},Y=BigInt(0),j=BigInt(1),st=BigInt(2),gt=BigInt(3),f=BigInt(4);function S(n){const e=I(n),{Fp:t}=e,l=e.toBytes||((Z,i,y)=>{const d=i.toAffine();return p.concatBytes(Uint8Array.from([4]),t.toBytes(d.x),t.toBytes(d.y))}),O=e.fromBytes||(Z=>{const i=Z.subarray(1),y=t.fromBytes(i.subarray(0,t.BYTES)),d=t.fromBytes(i.subarray(t.BYTES,2*t.BYTES));return{x:y,y:d}});function g(Z){const{a:i,b:y}=e,d=t.sqr(Z),B=t.mul(d,Z);return t.add(t.add(B,t.mul(Z,i)),y)}if(!t.eql(t.sqr(e.Gy),g(e.Gx)))throw new Error("bad generator point: equation left != right");function U(Z){return typeof Z=="bigint"&&Y<Z&&Z<e.n}function x(Z){if(!U(Z))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function F(Z){const{allowedPrivateKeyLengths:i,nByteLength:y,wrapPrivateKey:d,n:B}=e;if(i&&typeof Z!="bigint"){if(Z instanceof Uint8Array&&(Z=p.bytesToHex(Z)),typeof Z!="string"||!i.includes(Z.length))throw new Error("Invalid key");Z=Z.padStart(y*2,"0")}let H;try{H=typeof Z=="bigint"?Z:p.bytesToNumberBE((0,p.ensureBytes)("private key",Z,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof Z}`)}return d&&(H=N.wQ(H,B)),x(H),H}const q=new Map;function D(Z){if(!(Z instanceof w))throw new Error("ProjectivePoint expected")}class w{constructor(i,y,d){if(this.px=i,this.py=y,this.pz=d,i==null||!t.isValid(i))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(d==null||!t.isValid(d))throw new Error("z required")}static fromAffine(i){const{x:y,y:d}=i||{};if(!i||!t.isValid(y)||!t.isValid(d))throw new Error("invalid affine point");if(i instanceof w)throw new Error("projective point not allowed");const B=H=>t.eql(H,t.ZERO);return B(y)&&B(d)?w.ZERO:new w(y,d,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(i){const y=t.invertBatch(i.map(d=>d.pz));return i.map((d,B)=>d.toAffine(y[B])).map(w.fromAffine)}static fromHex(i){const y=w.fromAffine(O((0,p.ensureBytes)("pointHex",i)));return y.assertValidity(),y}static fromPrivateKey(i){return w.BASE.multiply(F(i))}_setWindowSize(i){this._WINDOW_SIZE=i,q.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:i,y}=this.toAffine();if(!t.isValid(i)||!t.isValid(y))throw new Error("bad point: x or y not FE");const d=t.sqr(y),B=g(i);if(!t.eql(d,B))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:i}=this.toAffine();if(t.isOdd)return!t.isOdd(i);throw new Error("Field doesn't support isOdd")}equals(i){D(i);const{px:y,py:d,pz:B}=this,{px:H,py:$,pz:W}=i,L=t.eql(t.mul(y,W),t.mul(H,B)),V=t.eql(t.mul(d,W),t.mul($,B));return L&&V}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){const{a:i,b:y}=e,d=t.mul(y,gt),{px:B,py:H,pz:$}=this;let W=t.ZERO,L=t.ZERO,V=t.ZERO,M=t.mul(B,B),xt=t.mul(H,H),wt=t.mul($,$),ct=t.mul(B,H);return ct=t.add(ct,ct),V=t.mul(B,$),V=t.add(V,V),W=t.mul(i,V),L=t.mul(d,wt),L=t.add(W,L),W=t.sub(xt,L),L=t.add(xt,L),L=t.mul(W,L),W=t.mul(ct,W),V=t.mul(d,V),wt=t.mul(i,wt),ct=t.sub(M,wt),ct=t.mul(i,ct),ct=t.add(ct,V),V=t.add(M,M),M=t.add(V,M),M=t.add(M,wt),M=t.mul(M,ct),L=t.add(L,M),wt=t.mul(H,$),wt=t.add(wt,wt),M=t.mul(wt,ct),W=t.sub(W,M),V=t.mul(wt,xt),V=t.add(V,V),V=t.add(V,V),new w(W,L,V)}add(i){D(i);const{px:y,py:d,pz:B}=this,{px:H,py:$,pz:W}=i;let L=t.ZERO,V=t.ZERO,M=t.ZERO;const xt=e.a,wt=t.mul(e.b,gt);let ct=t.mul(y,H),vt=t.mul(d,$),_t=t.mul(B,W),Tt=t.add(y,d),a=t.add(H,$);Tt=t.mul(Tt,a),a=t.add(ct,vt),Tt=t.sub(Tt,a),a=t.add(y,B);let m=t.add(H,W);return a=t.mul(a,m),m=t.add(ct,_t),a=t.sub(a,m),m=t.add(d,B),L=t.add($,W),m=t.mul(m,L),L=t.add(vt,_t),m=t.sub(m,L),M=t.mul(xt,a),L=t.mul(wt,_t),M=t.add(L,M),L=t.sub(vt,M),M=t.add(vt,M),V=t.mul(L,M),vt=t.add(ct,ct),vt=t.add(vt,ct),_t=t.mul(xt,_t),a=t.mul(wt,a),vt=t.add(vt,_t),_t=t.sub(ct,_t),_t=t.mul(xt,_t),a=t.add(a,_t),ct=t.mul(vt,a),V=t.add(V,ct),ct=t.mul(m,a),L=t.mul(Tt,L),L=t.sub(L,ct),ct=t.mul(Tt,vt),M=t.mul(m,M),M=t.add(M,ct),new w(L,V,M)}subtract(i){return this.add(i.negate())}is0(){return this.equals(w.ZERO)}wNAF(i){return it.wNAFCached(this,q,i,y=>{const d=t.invertBatch(y.map(B=>B.pz));return y.map((B,H)=>B.toAffine(d[H])).map(w.fromAffine)})}multiplyUnsafe(i){const y=w.ZERO;if(i===Y)return y;if(x(i),i===j)return this;const{endo:d}=e;if(!d)return it.unsafeLadder(this,i);let{k1neg:B,k1:H,k2neg:$,k2:W}=d.splitScalar(i),L=y,V=y,M=this;for(;H>Y||W>Y;)H&j&&(L=L.add(M)),W&j&&(V=V.add(M)),M=M.double(),H>>=j,W>>=j;return B&&(L=L.negate()),$&&(V=V.negate()),V=new w(t.mul(V.px,d.beta),V.py,V.pz),L.add(V)}multiply(i){x(i);let y=i,d,B;const{endo:H}=e;if(H){const{k1neg:$,k1:W,k2neg:L,k2:V}=H.splitScalar(y);let{p:M,f:xt}=this.wNAF(W),{p:wt,f:ct}=this.wNAF(V);M=it.constTimeNegate($,M),wt=it.constTimeNegate(L,wt),wt=new w(t.mul(wt.px,H.beta),wt.py,wt.pz),d=M.add(wt),B=xt.add(ct)}else{const{p:$,f:W}=this.wNAF(y);d=$,B=W}return w.normalizeZ([d,B])[0]}multiplyAndAddUnsafe(i,y,d){const B=w.BASE,H=(W,L)=>L===Y||L===j||!W.equals(B)?W.multiplyUnsafe(L):W.multiply(L),$=H(this,y).add(H(i,d));return $.is0()?void 0:$}toAffine(i){const{px:y,py:d,pz:B}=this,H=this.is0();i==null&&(i=H?t.ONE:t.inv(B));const $=t.mul(y,i),W=t.mul(d,i),L=t.mul(B,i);if(H)return{x:t.ZERO,y:t.ZERO};if(!t.eql(L,t.ONE))throw new Error("invZ was invalid");return{x:$,y:W}}isTorsionFree(){const{h:i,isTorsionFree:y}=e;if(i===j)return!0;if(y)return y(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:i,clearCofactor:y}=e;return i===j?this:y?y(w,this):this.multiplyUnsafe(e.h)}toRawBytes(i=!0){return this.assertValidity(),l(w,this,i)}toHex(i=!0){return p.bytesToHex(this.toRawBytes(i))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);const yt=e.nBitLength,it=(0,h.M)(w,e.endo?Math.ceil(yt/2):yt);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:F,weierstrassEquation:g,isWithinCurveOrder:U}}function G(n){const e=(0,h.K)(n);return p.validateObject(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function tt(n){const e=G(n),{Fp:t,n:l}=e,O=t.BYTES+1,g=2*t.BYTES+1;function U(a){return Y<a&&a<t.ORDER}function x(a){return N.wQ(a,l)}function F(a){return N.U_(a,l)}const{ProjectivePoint:q,normPrivateKeyToScalar:D,weierstrassEquation:w,isWithinCurveOrder:yt}=S({...e,toBytes(a,m,J){const ht=m.toAffine(),ut=t.toBytes(ht.x),mt=p.concatBytes;return J?mt(Uint8Array.from([m.hasEvenY()?2:3]),ut):mt(Uint8Array.from([4]),ut,t.toBytes(ht.y))},fromBytes(a){const m=a.length,J=a[0],ht=a.subarray(1);if(m===O&&(J===2||J===3)){const ut=p.bytesToNumberBE(ht);if(!U(ut))throw new Error("Point is not on curve");const mt=w(ut);let At=t.sqrt(mt);const St=(At&j)===j;return(J&1)===1!==St&&(At=t.neg(At)),{x:ut,y:At}}else if(m===g&&J===4){const ut=t.fromBytes(ht.subarray(0,t.BYTES)),mt=t.fromBytes(ht.subarray(t.BYTES,2*t.BYTES));return{x:ut,y:mt}}else throw new Error(`Point of length ${m} was invalid. Expected ${O} compressed bytes or ${g} uncompressed bytes`)}}),it=a=>p.bytesToHex(p.numberToBytesBE(a,e.nByteLength));function Z(a){const m=l>>j;return a>m}function i(a){return Z(a)?x(-a):a}const y=(a,m,J)=>p.bytesToNumberBE(a.slice(m,J));class d{constructor(m,J,ht){this.r=m,this.s=J,this.recovery=ht,this.assertValidity()}static fromCompact(m){const J=e.nByteLength;return m=(0,p.ensureBytes)("compactSignature",m,J*2),new d(y(m,0,J),y(m,J,2*J))}static fromDER(m){const{r:J,s:ht}=et.toSig((0,p.ensureBytes)("DER",m));return new d(J,ht)}assertValidity(){if(!yt(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!yt(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(m){return new d(this.r,this.s,m)}recoverPublicKey(m){const{r:J,s:ht,recovery:ut}=this,mt=V((0,p.ensureBytes)("msgHash",m));if(ut==null||![0,1,2,3].includes(ut))throw new Error("recovery id invalid");const At=ut===2||ut===3?J+e.n:J;if(At>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const St=(ut&1)===0?"02":"03",Nt=q.fromHex(St+it(At)),Lt=F(At),Ct=x(-mt*Lt),jt=x(ht*Lt),Ut=q.BASE.multiplyAndAddUnsafe(Nt,Ct,jt);if(!Ut)throw new Error("point at infinify");return Ut.assertValidity(),Ut}hasHighS(){return Z(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return p.hexToBytes(this.toDERHex())}toDERHex(){return et.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return p.hexToBytes(this.toCompactHex())}toCompactHex(){return it(this.r)+it(this.s)}}const B={isValidPrivateKey(a){try{return D(a),!0}catch{return!1}},normPrivateKeyToScalar:D,randomPrivateKey:()=>{const a=e.randomBytes(t.BYTES+8),m=N.Pu(a,l);return p.numberToBytesBE(m,e.nByteLength)},precompute(a=8,m=q.BASE){return m._setWindowSize(a),m.multiply(BigInt(3)),m}};function H(a,m=!0){return q.fromPrivateKey(a).toRawBytes(m)}function $(a){const m=a instanceof Uint8Array,J=typeof a=="string",ht=(m||J)&&a.length;return m?ht===O||ht===g:J?ht===2*O||ht===2*g:a instanceof q}function W(a,m,J=!0){if($(a))throw new Error("first arg must be private key");if(!$(m))throw new Error("second arg must be public key");return q.fromHex(m).multiply(D(a)).toRawBytes(J)}const L=e.bits2int||function(a){const m=p.bytesToNumberBE(a),J=a.length*8-e.nBitLength;return J>0?m>>BigInt(J):m},V=e.bits2int_modN||function(a){return x(L(a))},M=p.bitMask(e.nBitLength);function xt(a){if(typeof a!="bigint")throw new Error("bigint expected");if(!(Y<=a&&a<M))throw new Error(`bigint expected < 2^${e.nBitLength}`);return p.numberToBytesBE(a,e.nByteLength)}function wt(a,m,J=ct){if(["recovered","canonical"].some(Ht=>Ht in J))throw new Error("sign() legacy options not supported");const{hash:ht,randomBytes:ut}=e;let{lowS:mt,prehash:At,extraEntropy:St}=J;mt==null&&(mt=!0),a=(0,p.ensureBytes)("msgHash",a),At&&(a=(0,p.ensureBytes)("prehashed msgHash",ht(a)));const Nt=V(a),Lt=D(m),Ct=[xt(Lt),xt(Nt)];if(St!=null){const Ht=St===!0?ut(t.BYTES):St;Ct.push((0,p.ensureBytes)("extraEntropy",Ht,t.BYTES))}const jt=p.concatBytes(...Ct),Ut=Nt;function Gt(Ht){const Pt=L(Ht);if(!yt(Pt))return;const Jt=F(Pt),Zt=q.BASE.multiply(Pt).toAffine(),It=x(Zt.x);if(It===Y)return;const Vt=x(Jt*x(Ut+It*Lt));if(Vt===Y)return;let Ft=(Zt.x===It?0:2)|Number(Zt.y&j),te=Vt;return mt&&Z(Vt)&&(te=i(Vt),Ft^=1),new d(It,te,Ft)}return{seed:jt,k2sig:Gt}}const ct={lowS:e.lowS,prehash:!1},vt={lowS:e.lowS,prehash:!1};function _t(a,m,J=ct){const{seed:ht,k2sig:ut}=wt(a,m,J),mt=e;return p.createHmacDrbg(mt.hash.outputLen,mt.nByteLength,mt.hmac)(ht,ut)}q.BASE._setWindowSize(8);function Tt(a,m,J,ht=vt){var Zt;const ut=a;if(m=(0,p.ensureBytes)("msgHash",m),J=(0,p.ensureBytes)("publicKey",J),"strict"in ht)throw new Error("options.strict was renamed to lowS");const{lowS:mt,prehash:At}=ht;let St,Nt;try{if(typeof ut=="string"||ut instanceof Uint8Array)try{St=d.fromDER(ut)}catch(It){if(!(It instanceof et.Err))throw It;St=d.fromCompact(ut)}else if(typeof ut=="object"&&typeof ut.r=="bigint"&&typeof ut.s=="bigint"){const{r:It,s:Vt}=ut;St=new d(It,Vt)}else throw new Error("PARSE");Nt=q.fromHex(J)}catch(It){if(It.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(mt&&St.hasHighS())return!1;At&&(m=e.hash(m));const{r:Lt,s:Ct}=St,jt=V(m),Ut=F(Ct),Gt=x(jt*Ut),Ht=x(Lt*Ut),Pt=(Zt=q.BASE.multiplyAndAddUnsafe(Nt,Gt,Ht))==null?void 0:Zt.toAffine();return Pt?x(Pt.x)===Lt:!1}return{CURVE:e,getPublicKey:H,getSharedSecret:W,sign:_t,verify:Tt,ProjectivePoint:q,Signature:d,utils:B}}function nt(n,e){const t=n.ORDER;let l=Y;for(let Z=t-j;Z%st===Y;Z/=st)l+=j;const O=l,g=st<<O-j-j,U=g*st,x=(t-j)/U,F=(x-j)/st,q=U-j,D=g,w=n.pow(e,x),yt=n.pow(e,(x+j)/st);let it=(Z,i)=>{let y=w,d=n.pow(i,q),B=n.sqr(d);B=n.mul(B,i);let H=n.mul(Z,B);H=n.pow(H,F),H=n.mul(H,d),d=n.mul(H,i),B=n.mul(H,Z);let $=n.mul(B,d);H=n.pow($,D);let W=n.eql(H,n.ONE);d=n.mul(B,yt),H=n.mul($,y),B=n.cmov(d,B,W),$=n.cmov(H,$,W);for(let L=O;L>j;L--){let V=L-st;V=st<<V-j;let M=n.pow($,V);const xt=n.eql(M,n.ONE);d=n.mul(B,y),y=n.mul(y,y),M=n.mul($,y),B=n.cmov(d,B,xt),$=n.cmov(M,$,xt)}return{isValid:W,value:B}};if(n.ORDER%f===gt){const Z=(n.ORDER-gt)/f,i=n.sqrt(n.neg(e));it=(y,d)=>{let B=n.sqr(d);const H=n.mul(y,d);B=n.mul(B,H);let $=n.pow(B,Z);$=n.mul($,H);const W=n.mul($,i),L=n.mul(n.sqr($),d),V=n.eql(L,y);let M=n.cmov(W,$,V);return{isValid:V,value:M}}}return it}function o(n,e){if(mod.validateField(n),!n.isValid(e.A)||!n.isValid(e.B)||!n.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const t=nt(n,e.Z);if(!n.isOdd)throw new Error("Fp.isOdd is not implemented!");return l=>{let O,g,U,x,F,q,D,w;O=n.sqr(l),O=n.mul(O,e.Z),g=n.sqr(O),g=n.add(g,O),U=n.add(g,n.ONE),U=n.mul(U,e.B),x=n.cmov(e.Z,n.neg(g),!n.eql(g,n.ZERO)),x=n.mul(x,e.A),g=n.sqr(U),q=n.sqr(x),F=n.mul(q,e.A),g=n.add(g,F),g=n.mul(g,U),q=n.mul(q,x),F=n.mul(q,e.B),g=n.add(g,F),D=n.mul(O,U);const{isValid:yt,value:it}=t(g,q);w=n.mul(O,l),w=n.mul(w,it),D=n.cmov(D,U,yt),w=n.cmov(w,it,yt);const Z=n.isOdd(l)===n.isOdd(w);return w=n.cmov(n.neg(w),w,Z),D=n.div(D,x),{x:D,y:w}}}var r=ft(42017),c=ft(26032);class s extends A.kb{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,c.ZP.hash(e);const l=(0,A.O0)(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const O=this.blockLen,g=new Uint8Array(O);g.set(l.length>O?e.create().update(l).digest():l);for(let U=0;U<g.length;U++)g[U]^=54;this.iHash.update(g),this.oHash=e.create();for(let U=0;U<g.length;U++)g[U]^=106;this.oHash.update(g),g.fill(0)}update(e){return c.ZP.exists(this),this.iHash.update(e),this}digestInto(e){c.ZP.exists(this),c.ZP.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:l,finished:O,destroyed:g,blockLen:U,outputLen:x}=this;return e=e,e.finished=O,e.destroyed=g,e.blockLen=U,e.outputLen=x,e.oHash=t._cloneInto(e.oHash),e.iHash=l._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const u=(n,e,t)=>new s(n,e).update(t).digest();u.create=(n,e)=>new s(n,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function R(n){return{hash:n,hmac:(e,...t)=>u(n,e,(0,A.eV)(...t)),randomBytes:A.O6}}function Q(n,e){const t=l=>tt({...n,...R(l)});return Object.freeze({...t(e),create:t})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rt=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),k=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),b=BigInt(1),X=BigInt(2),bt=(n,e)=>(n+e/X)/e;function Bt(n){const e=rt,t=BigInt(3),l=BigInt(6),O=BigInt(11),g=BigInt(22),U=BigInt(23),x=BigInt(44),F=BigInt(88),q=n*n*n%e,D=q*q*n%e,w=(0,N.oA)(D,t,e)*D%e,yt=(0,N.oA)(w,t,e)*D%e,it=(0,N.oA)(yt,X,e)*q%e,Z=(0,N.oA)(it,O,e)*it%e,i=(0,N.oA)(Z,g,e)*Z%e,y=(0,N.oA)(i,x,e)*i%e,d=(0,N.oA)(y,F,e)*y%e,B=(0,N.oA)(d,x,e)*i%e,H=(0,N.oA)(B,t,e)*D%e,$=(0,N.oA)(H,U,e)*Z%e,W=(0,N.oA)($,l,e)*q%e,L=(0,N.oA)(W,X,e);if(!pt.eql(pt.sqr(L),n))throw new Error("Cannot find square root");return L}const pt=(0,N.gN)(rt,void 0,void 0,{sqrt:Bt}),Ot=Q({a:BigInt(0),b:BigInt(7),Fp:pt,n:k,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:n=>{const e=k,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),l=-b*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),O=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),g=t,U=BigInt("0x100000000000000000000000000000000"),x=bt(g*n,e),F=bt(-l*n,e);let q=(0,N.wQ)(n-x*t-F*O,e),D=(0,N.wQ)(-x*l-F*g,e);const w=q>U,yt=D>U;if(w&&(q=e-q),yt&&(D=e-D),q>U||D>U)throw new Error("splitScalar: Endomorphism failed, k="+n);return{k1neg:w,k1:q,k2neg:yt,k2:D}}}},dt),qt=BigInt(0),Rt=n=>typeof n=="bigint"&&qt<n&&n<rt,ee=n=>typeof n=="bigint"&&qt<n&&n<k,Yt={};function $t(n,...e){let t=Yt[n];if(t===void 0){const l=sha256(Uint8Array.from(n,O=>O.charCodeAt(0)));t=concatBytes(l,l),Yt[n]=t}return sha256(concatBytes(t,...e))}const Xt=n=>n.toRawBytes(!0).slice(1),Mt=n=>numberToBytesBE(n,32),Kt=n=>mod(n,rt),Dt=n=>mod(n,k),Wt=Ot.ProjectivePoint,ne=(n,e,t)=>Wt.BASE.multiplyAndAddUnsafe(n,e,t);function zt(n){let e=Ot.utils.normPrivateKeyToScalar(n),t=Wt.fromPrivateKey(e);return{scalar:t.hasEvenY()?e:Dt(-e),bytes:Xt(t)}}function re(n){if(!Rt(n))throw new Error("bad x: need 0 < x < p");const e=Kt(n*n),t=Kt(e*n+BigInt(7));let l=Bt(t);l%X!==qt&&(l=Kt(-l));const O=new Wt(n,l,b);return O.assertValidity(),O}function Qt(...n){return Dt(bytesToNumberBE($t("BIP0340/challenge",...n)))}function se(n){return zt(n).bytes}function ie(n,e,t=randomBytes(32)){const l=ensureBytes("message",n),{bytes:O,scalar:g}=zt(e),U=ensureBytes("auxRand",t,32),x=Mt(g^bytesToNumberBE($t("BIP0340/aux",U))),F=$t("BIP0340/nonce",x,O,l),q=Dt(bytesToNumberBE(F));if(q===qt)throw new Error("sign failed: k is zero");const{bytes:D,scalar:w}=zt(q),yt=Qt(D,O,l),it=new Uint8Array(64);if(it.set(D,0),it.set(Mt(Dt(w+yt*g)),32),!oe(it,l,O))throw new Error("sign: Invalid signature produced");return it}function oe(n,e,t){const l=ensureBytes("signature",n,64),O=ensureBytes("message",e),g=ensureBytes("publicKey",t,32);try{const U=re(bytesToNumberBE(g)),x=bytesToNumberBE(l.subarray(0,32));if(!Rt(x))return!1;const F=bytesToNumberBE(l.subarray(32,64));if(!ee(F))return!1;const q=Qt(Mt(x),Xt(U),O),D=ne(U,F,Dt(-q));return!(!D||!D.hasEvenY()||D.toAffine().x!==x)}catch{return!1}}const ce=null,fe=null,ue=null,ae=null,le=null,de=null},26032:function(kt,Et,ft){function ot(v){if(!Number.isSafeInteger(v)||v<0)throw new Error(`Wrong positive integer: ${v}`)}function A(v){if(typeof v!="boolean")throw new Error(`Expected boolean, not ${v}`)}function z(v,...K){if(!(v instanceof Uint8Array))throw new Error("Expected Uint8Array");if(K.length>0&&!K.includes(v.length))throw new Error(`Expected Uint8Array of length ${K}, not of length=${v.length}`)}function at(v){if(typeof v!="function"||typeof v.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ot(v.outputLen),ot(v.blockLen)}function lt(v,K=!0){if(v.destroyed)throw new Error("Hash instance has been destroyed");if(K&&v.finished)throw new Error("Hash#digest() has already been called")}function T(v,K){z(v);const dt=K.outputLen;if(v.length<dt)throw new Error(`digestInto() expects output buffer of length at least ${dt}`)}const C={number:ot,bool:A,bytes:z,hash:at,exists:lt,output:T};Et.ZP=C},38235:function(kt,Et,ft){ft.d(Et,{N:function(){return at}});var ot=ft(26032),A=ft(63321);function z(lt,T,C,v){if(typeof lt.setBigUint64=="function")return lt.setBigUint64(T,C,v);const K=BigInt(32),dt=BigInt(4294967295),E=Number(C>>K&dt),N=Number(C&dt),p=v?4:0,h=v?0:4;lt.setUint32(T+p,E,v),lt.setUint32(T+h,N,v)}class at extends A.kb{constructor(T,C,v,K){super(),this.blockLen=T,this.outputLen=C,this.padOffset=v,this.isLE=K,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(T),this.view=(0,A.GL)(this.buffer)}update(T){ot.ZP.exists(this);const{view:C,buffer:v,blockLen:K}=this;T=(0,A.O0)(T);const dt=T.length;for(let E=0;E<dt;){const N=Math.min(K-this.pos,dt-E);if(N===K){const p=(0,A.GL)(T);for(;K<=dt-E;E+=K)this.process(p,E);continue}v.set(T.subarray(E,E+N),this.pos),this.pos+=N,E+=N,this.pos===K&&(this.process(C,0),this.pos=0)}return this.length+=T.length,this.roundClean(),this}digestInto(T){ot.ZP.exists(this),ot.ZP.output(T,this),this.finished=!0;const{buffer:C,view:v,blockLen:K,isLE:dt}=this;let{pos:E}=this;C[E++]=128,this.buffer.subarray(E).fill(0),this.padOffset>K-E&&(this.process(v,0),E=0);for(let _=E;_<K;_++)C[_]=0;z(v,K-8,BigInt(this.length*8),dt),this.process(v,0);const N=(0,A.GL)(T),p=this.outputLen;if(p%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=p/4,I=this.get();if(h>I.length)throw new Error("_sha2: outputLen bigger than state");for(let _=0;_<h;_++)N.setUint32(4*_,I[_],dt)}digest(){const{buffer:T,outputLen:C}=this;this.digestInto(T);const v=T.slice(0,C);return this.destroy(),v}_cloneInto(T){T||(T=new this.constructor),T.set(...this.get());const{blockLen:C,buffer:v,length:K,finished:dt,destroyed:E,pos:N}=this;return T.length=K,T.pos=N,T.finished=dt,T.destroyed=E,K%C&&T.buffer.set(v),T}}},63321:function(kt,Et,ft){ft.d(Et,{kb:function(){return _},eV:function(){return I},GL:function(){return lt},O6:function(){return gt},np:function(){return T},O0:function(){return h},iY:function(){return p},hE:function(){return Y}});const ot=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const A=f=>f instanceof Uint8Array,z=f=>new Uint8Array(f.buffer,f.byteOffset,f.byteLength),at=f=>new Uint32Array(f.buffer,f.byteOffset,Math.floor(f.byteLength/4)),lt=f=>new DataView(f.buffer,f.byteOffset,f.byteLength),T=(f,S)=>f<<32-S|f>>>S;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");const v=Array.from({length:256},(f,S)=>S.toString(16).padStart(2,"0"));function K(f){if(!A(f))throw new Error("Uint8Array expected");let S="";for(let G=0;G<f.length;G++)S+=v[f[G]];return S}function dt(f){if(typeof f!="string")throw new Error("hex string expected, got "+typeof f);const S=f.length;if(S%2)throw new Error("padded hex string expected, got unpadded hex of length "+S);const G=new Uint8Array(S/2);for(let tt=0;tt<G.length;tt++){const nt=tt*2,o=f.slice(nt,nt+2),r=Number.parseInt(o,16);if(Number.isNaN(r)||r<0)throw new Error("Invalid byte sequence");G[tt]=r}return G}const E=async()=>{};async function N(f,S,G){let tt=Date.now();for(let nt=0;nt<f;nt++){G(nt);const o=Date.now()-tt;o>=0&&o<S||(await E(),tt+=o)}}function p(f){if(typeof f!="string")throw new Error(`utf8ToBytes expected string, got ${typeof f}`);return new Uint8Array(new TextEncoder().encode(f))}function h(f){if(typeof f=="string"&&(f=p(f)),!A(f))throw new Error(`expected Uint8Array, got ${typeof f}`);return f}function I(...f){const S=new Uint8Array(f.reduce((tt,nt)=>tt+nt.length,0));let G=0;return f.forEach(tt=>{if(!A(tt))throw new Error("Uint8Array expected");S.set(tt,G),G+=tt.length}),S}class _{clone(){return this._cloneInto()}}const P=f=>Object.prototype.toString.call(f)==="[object Object]"&&f.constructor===Object;function et(f,S){if(S!==void 0&&(typeof S!="object"||!P(S)))throw new Error("Options should be object or undefined");return Object.assign(f,S)}function Y(f){const S=tt=>f().update(h(tt)).digest(),G=f();return S.outputLen=G.outputLen,S.blockLen=G.blockLen,S.create=()=>f(),S}function j(f){const S=(tt,nt)=>f(nt).update(h(tt)).digest(),G=f({});return S.outputLen=G.outputLen,S.blockLen=G.blockLen,S.create=tt=>f(tt),S}function st(f){const S=(tt,nt)=>f(nt).update(h(tt)).digest(),G=f({});return S.outputLen=G.outputLen,S.blockLen=G.blockLen,S.create=tt=>f(tt),S}function gt(f=32){if(ot&&typeof ot.getRandomValues=="function")return ot.getRandomValues(new Uint8Array(f));throw new Error("crypto.getRandomValues must be defined")}}}]);