@lightprotocol/stateless.js 0.17.2-alpha.0 → 0.17.2-alpha.1
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/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/rpc-interface.d.ts +3 -3
- package/dist/cjs/browser/rpc.d.ts +2 -57
- package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +2 -3
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/rpc-interface.d.ts +3 -3
- package/dist/cjs/node/rpc.d.ts +2 -57
- package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +2 -3
- package/dist/es/browser/index.js +1 -1
- package/dist/es/browser/index.js.map +1 -1
- package/dist/es/browser/rpc-interface.d.ts +3 -3
- package/dist/es/browser/rpc.d.ts +2 -57
- package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +2 -3
- package/dist/types/index.d.ts +5 -185
- package/package.json +4 -4
- package/dist/cjs/browser/connection-interface.d.ts +0 -125
- package/dist/cjs/node/connection-interface.d.ts +0 -125
- package/dist/es/browser/connection-interface.d.ts +0 -125
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@solana/web3.js"),e=require("buffer"),r=require("buffer-layout"),n=require("superstruct"),o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};!function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t,e,r){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof i?i.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(t){}function a(t,e){var n=t.charCodeAt(e);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(0,"Invalid character in "+t)}function u(t,e,r){var n=a(t,r);return r-1>=e&&(n|=a(t,r-1)<<4),n}function l(t,e,n,o){for(var s=0,i=0,a=Math.min(t.length,n),u=e;u<a;u++){var l=t.charCodeAt(u)-48;s*=o,i=l>=49?l-49+10:l>=17?l-17+10:l,r(l>=0&&i<o,"Invalid character"),s+=i}return s}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(o.isBN=function(t){return t instanceof o?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var o=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<t.length&&(16===e?this._parseHex(t,o,n):(this._parseBase(t,e,o),"le"===n&&this._initArray(this.toArray(),e,n)))},o.prototype._initNumber=function(t,e,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},o.prototype._initArray=function(t,e,n){if(r("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var s,i,a=0;if("be"===n)for(o=t.length-1,s=0;o>=0;o-=3)i=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===n)for(o=0,s=0;o<t.length;o+=3)i=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,s=0,i=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)o=u(t,e,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)o=u(t,e,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,o=1;o<=67108863;o*=e)n++;n--,o=o/e|0;for(var s=t.length-r,i=s%n,a=Math.min(s,s-i)+r,u=0,h=r;h<a;h+=n)u=l(t,h,h+n,e),this.imuln(o),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==i){var c=1;for(u=l(t,h,t.length,e),h=0;h<i;h++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype._move=function(t){h(t,this)},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=c}catch(t){o.prototype.inspect=c}else o.prototype.inspect=c;function c(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],p=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function f(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var o=0|t.words[0],s=0|e.words[0],i=o*s,a=67108863&i,u=i/67108864|0;r.words[0]=a;for(var l=1;l<n;l++){for(var h=u>>>26,c=67108863&u,d=Math.min(l,e.length-1),p=Math.max(0,l-t.length+1);p<=d;p++){var m=l-p|0;h+=(i=(o=0|t.words[m])*(s=0|e.words[p])+c)/67108864|0,c=67108863&i}r.words[l]=0|c,u=0|h}return 0!==u?r.words[l]=0|u:r.length--,r._strip()}o.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var o=0,s=0,i=0;i<this.length;i++){var a=this.words[i],u=(16777215&(a<<o|s)).toString(16);s=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,i--),n=0!==s||i!==this.length-1?d[6-u.length]+u+n:u+n}for(0!==s&&(n=s.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var l=p[t],h=m[t];n="";var c=this.clone();for(c.negative=0;!c.isZero();){var f=c.modrn(h).toString(t);n=(c=c.idivn(h)).isZero()?f+n:d[l-f.length]+f+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,n){this._strip();var o=this.byteLength(),s=n||Math.max(1,o);r(o<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var i=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](i,o),i},o.prototype._toArrayLikeLE=function(t){for(var e=0,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;t[e++]=255&s,e<t.length&&(t[e++]=s>>8&255),e<t.length&&(t[e++]=s>>16&255),6===o?(e<t.length&&(t[e++]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(e<t.length)for(t[e++]=r;e<t.length;)t[e++]=0},o.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;t[e--]=255&s,e>=0&&(t[e--]=s>>8&255),e>=0&&(t[e--]=s>>16&255),6===o?(e>=0&&(t[e--]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(e>=0)for(t[e--]=r;e>=0;)t[e--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return r(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return r(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return r(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var o=0;o<e;o++)this.words[o]=67108863&~this.words[o];return n>0&&(this.words[o]=~this.words[o]&67108863>>26-n),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){r("number"==typeof t&&t>=0);var n=t/26|0,o=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<o:this.words[n]&~(1<<o),this._strip()},o.prototype.iadd=function(t){var e,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)e=(0|r.words[s])+(0|n.words[s])+o,this.words[s]=67108863&e,o=e>>>26;for(;0!==o&&s<r.length;s++)e=(0|r.words[s])+o,this.words[s]=67108863&e,o=e>>>26;if(this.length=r.length,0!==o)this.words[this.length]=o,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},o.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,o=this.cmp(t);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(r=this,n=t):(r=t,n=this);for(var s=0,i=0;i<n.length;i++)s=(e=(0|r.words[i])-(0|n.words[i])+s)>>26,this.words[i]=67108863&e;for(;0!==s&&i<r.length;i++)s=(e=(0|r.words[i])+s)>>26,this.words[i]=67108863&e;if(0===s&&i<r.length&&r!==this)for(;i<r.length;i++)this.words[i]=r.words[i];return this.length=Math.max(this.length,i),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,o,s,i=t.words,a=e.words,u=r.words,l=0,h=0|i[0],c=8191&h,d=h>>>13,p=0|i[1],m=8191&p,f=p>>>13,g=0|i[2],w=8191&g,y=g>>>13,v=0|i[3],M=8191&v,E=v>>>13,b=0|i[4],A=8191&b,x=b>>>13,I=0|i[5],T=8191&I,k=I>>>13,_=0|i[6],S=8191&_,C=_>>>13,P=0|i[7],N=8191&P,O=P>>>13,B=0|i[8],L=8191&B,R=B>>>13,U=0|i[9],D=8191&U,F=U>>>13,V=0|a[0],H=8191&V,K=V>>>13,q=0|a[1],Q=8191&q,j=q>>>13,W=0|a[2],z=8191&W,$=W>>>13,Z=0|a[3],J=8191&Z,X=Z>>>13,G=0|a[4],Y=8191&G,tt=G>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,ot=0|a[6],st=8191&ot,it=ot>>>13,at=0|a[7],ut=8191&at,lt=at>>>13,ht=0|a[8],ct=8191&ht,dt=ht>>>13,pt=0|a[9],mt=8191&pt,ft=pt>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(l+(n=Math.imul(c,H))|0)+((8191&(o=(o=Math.imul(c,K))+Math.imul(d,H)|0))<<13)|0;l=((s=Math.imul(d,K))+(o>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(m,H),o=(o=Math.imul(m,K))+Math.imul(f,H)|0,s=Math.imul(f,K);var wt=(l+(n=n+Math.imul(c,Q)|0)|0)+((8191&(o=(o=o+Math.imul(c,j)|0)+Math.imul(d,Q)|0))<<13)|0;l=((s=s+Math.imul(d,j)|0)+(o>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(w,H),o=(o=Math.imul(w,K))+Math.imul(y,H)|0,s=Math.imul(y,K),n=n+Math.imul(m,Q)|0,o=(o=o+Math.imul(m,j)|0)+Math.imul(f,Q)|0,s=s+Math.imul(f,j)|0;var yt=(l+(n=n+Math.imul(c,z)|0)|0)+((8191&(o=(o=o+Math.imul(c,$)|0)+Math.imul(d,z)|0))<<13)|0;l=((s=s+Math.imul(d,$)|0)+(o>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(M,H),o=(o=Math.imul(M,K))+Math.imul(E,H)|0,s=Math.imul(E,K),n=n+Math.imul(w,Q)|0,o=(o=o+Math.imul(w,j)|0)+Math.imul(y,Q)|0,s=s+Math.imul(y,j)|0,n=n+Math.imul(m,z)|0,o=(o=o+Math.imul(m,$)|0)+Math.imul(f,z)|0,s=s+Math.imul(f,$)|0;var vt=(l+(n=n+Math.imul(c,J)|0)|0)+((8191&(o=(o=o+Math.imul(c,X)|0)+Math.imul(d,J)|0))<<13)|0;l=((s=s+Math.imul(d,X)|0)+(o>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(A,H),o=(o=Math.imul(A,K))+Math.imul(x,H)|0,s=Math.imul(x,K),n=n+Math.imul(M,Q)|0,o=(o=o+Math.imul(M,j)|0)+Math.imul(E,Q)|0,s=s+Math.imul(E,j)|0,n=n+Math.imul(w,z)|0,o=(o=o+Math.imul(w,$)|0)+Math.imul(y,z)|0,s=s+Math.imul(y,$)|0,n=n+Math.imul(m,J)|0,o=(o=o+Math.imul(m,X)|0)+Math.imul(f,J)|0,s=s+Math.imul(f,X)|0;var Mt=(l+(n=n+Math.imul(c,Y)|0)|0)+((8191&(o=(o=o+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;l=((s=s+Math.imul(d,tt)|0)+(o>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(T,H),o=(o=Math.imul(T,K))+Math.imul(k,H)|0,s=Math.imul(k,K),n=n+Math.imul(A,Q)|0,o=(o=o+Math.imul(A,j)|0)+Math.imul(x,Q)|0,s=s+Math.imul(x,j)|0,n=n+Math.imul(M,z)|0,o=(o=o+Math.imul(M,$)|0)+Math.imul(E,z)|0,s=s+Math.imul(E,$)|0,n=n+Math.imul(w,J)|0,o=(o=o+Math.imul(w,X)|0)+Math.imul(y,J)|0,s=s+Math.imul(y,X)|0,n=n+Math.imul(m,Y)|0,o=(o=o+Math.imul(m,tt)|0)+Math.imul(f,Y)|0,s=s+Math.imul(f,tt)|0;var Et=(l+(n=n+Math.imul(c,rt)|0)|0)+((8191&(o=(o=o+Math.imul(c,nt)|0)+Math.imul(d,rt)|0))<<13)|0;l=((s=s+Math.imul(d,nt)|0)+(o>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(S,H),o=(o=Math.imul(S,K))+Math.imul(C,H)|0,s=Math.imul(C,K),n=n+Math.imul(T,Q)|0,o=(o=o+Math.imul(T,j)|0)+Math.imul(k,Q)|0,s=s+Math.imul(k,j)|0,n=n+Math.imul(A,z)|0,o=(o=o+Math.imul(A,$)|0)+Math.imul(x,z)|0,s=s+Math.imul(x,$)|0,n=n+Math.imul(M,J)|0,o=(o=o+Math.imul(M,X)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,X)|0,n=n+Math.imul(w,Y)|0,o=(o=o+Math.imul(w,tt)|0)+Math.imul(y,Y)|0,s=s+Math.imul(y,tt)|0,n=n+Math.imul(m,rt)|0,o=(o=o+Math.imul(m,nt)|0)+Math.imul(f,rt)|0,s=s+Math.imul(f,nt)|0;var bt=(l+(n=n+Math.imul(c,st)|0)|0)+((8191&(o=(o=o+Math.imul(c,it)|0)+Math.imul(d,st)|0))<<13)|0;l=((s=s+Math.imul(d,it)|0)+(o>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(N,H),o=(o=Math.imul(N,K))+Math.imul(O,H)|0,s=Math.imul(O,K),n=n+Math.imul(S,Q)|0,o=(o=o+Math.imul(S,j)|0)+Math.imul(C,Q)|0,s=s+Math.imul(C,j)|0,n=n+Math.imul(T,z)|0,o=(o=o+Math.imul(T,$)|0)+Math.imul(k,z)|0,s=s+Math.imul(k,$)|0,n=n+Math.imul(A,J)|0,o=(o=o+Math.imul(A,X)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,X)|0,n=n+Math.imul(M,Y)|0,o=(o=o+Math.imul(M,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,n=n+Math.imul(w,rt)|0,o=(o=o+Math.imul(w,nt)|0)+Math.imul(y,rt)|0,s=s+Math.imul(y,nt)|0,n=n+Math.imul(m,st)|0,o=(o=o+Math.imul(m,it)|0)+Math.imul(f,st)|0,s=s+Math.imul(f,it)|0;var At=(l+(n=n+Math.imul(c,ut)|0)|0)+((8191&(o=(o=o+Math.imul(c,lt)|0)+Math.imul(d,ut)|0))<<13)|0;l=((s=s+Math.imul(d,lt)|0)+(o>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(L,H),o=(o=Math.imul(L,K))+Math.imul(R,H)|0,s=Math.imul(R,K),n=n+Math.imul(N,Q)|0,o=(o=o+Math.imul(N,j)|0)+Math.imul(O,Q)|0,s=s+Math.imul(O,j)|0,n=n+Math.imul(S,z)|0,o=(o=o+Math.imul(S,$)|0)+Math.imul(C,z)|0,s=s+Math.imul(C,$)|0,n=n+Math.imul(T,J)|0,o=(o=o+Math.imul(T,X)|0)+Math.imul(k,J)|0,s=s+Math.imul(k,X)|0,n=n+Math.imul(A,Y)|0,o=(o=o+Math.imul(A,tt)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,tt)|0,n=n+Math.imul(M,rt)|0,o=(o=o+Math.imul(M,nt)|0)+Math.imul(E,rt)|0,s=s+Math.imul(E,nt)|0,n=n+Math.imul(w,st)|0,o=(o=o+Math.imul(w,it)|0)+Math.imul(y,st)|0,s=s+Math.imul(y,it)|0,n=n+Math.imul(m,ut)|0,o=(o=o+Math.imul(m,lt)|0)+Math.imul(f,ut)|0,s=s+Math.imul(f,lt)|0;var xt=(l+(n=n+Math.imul(c,ct)|0)|0)+((8191&(o=(o=o+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;l=((s=s+Math.imul(d,dt)|0)+(o>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(D,H),o=(o=Math.imul(D,K))+Math.imul(F,H)|0,s=Math.imul(F,K),n=n+Math.imul(L,Q)|0,o=(o=o+Math.imul(L,j)|0)+Math.imul(R,Q)|0,s=s+Math.imul(R,j)|0,n=n+Math.imul(N,z)|0,o=(o=o+Math.imul(N,$)|0)+Math.imul(O,z)|0,s=s+Math.imul(O,$)|0,n=n+Math.imul(S,J)|0,o=(o=o+Math.imul(S,X)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,X)|0,n=n+Math.imul(T,Y)|0,o=(o=o+Math.imul(T,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,n=n+Math.imul(A,rt)|0,o=(o=o+Math.imul(A,nt)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,nt)|0,n=n+Math.imul(M,st)|0,o=(o=o+Math.imul(M,it)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,it)|0,n=n+Math.imul(w,ut)|0,o=(o=o+Math.imul(w,lt)|0)+Math.imul(y,ut)|0,s=s+Math.imul(y,lt)|0,n=n+Math.imul(m,ct)|0,o=(o=o+Math.imul(m,dt)|0)+Math.imul(f,ct)|0,s=s+Math.imul(f,dt)|0;var It=(l+(n=n+Math.imul(c,mt)|0)|0)+((8191&(o=(o=o+Math.imul(c,ft)|0)+Math.imul(d,mt)|0))<<13)|0;l=((s=s+Math.imul(d,ft)|0)+(o>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(D,Q),o=(o=Math.imul(D,j))+Math.imul(F,Q)|0,s=Math.imul(F,j),n=n+Math.imul(L,z)|0,o=(o=o+Math.imul(L,$)|0)+Math.imul(R,z)|0,s=s+Math.imul(R,$)|0,n=n+Math.imul(N,J)|0,o=(o=o+Math.imul(N,X)|0)+Math.imul(O,J)|0,s=s+Math.imul(O,X)|0,n=n+Math.imul(S,Y)|0,o=(o=o+Math.imul(S,tt)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,tt)|0,n=n+Math.imul(T,rt)|0,o=(o=o+Math.imul(T,nt)|0)+Math.imul(k,rt)|0,s=s+Math.imul(k,nt)|0,n=n+Math.imul(A,st)|0,o=(o=o+Math.imul(A,it)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,it)|0,n=n+Math.imul(M,ut)|0,o=(o=o+Math.imul(M,lt)|0)+Math.imul(E,ut)|0,s=s+Math.imul(E,lt)|0,n=n+Math.imul(w,ct)|0,o=(o=o+Math.imul(w,dt)|0)+Math.imul(y,ct)|0,s=s+Math.imul(y,dt)|0;var Tt=(l+(n=n+Math.imul(m,mt)|0)|0)+((8191&(o=(o=o+Math.imul(m,ft)|0)+Math.imul(f,mt)|0))<<13)|0;l=((s=s+Math.imul(f,ft)|0)+(o>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(D,z),o=(o=Math.imul(D,$))+Math.imul(F,z)|0,s=Math.imul(F,$),n=n+Math.imul(L,J)|0,o=(o=o+Math.imul(L,X)|0)+Math.imul(R,J)|0,s=s+Math.imul(R,X)|0,n=n+Math.imul(N,Y)|0,o=(o=o+Math.imul(N,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,n=n+Math.imul(S,rt)|0,o=(o=o+Math.imul(S,nt)|0)+Math.imul(C,rt)|0,s=s+Math.imul(C,nt)|0,n=n+Math.imul(T,st)|0,o=(o=o+Math.imul(T,it)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,it)|0,n=n+Math.imul(A,ut)|0,o=(o=o+Math.imul(A,lt)|0)+Math.imul(x,ut)|0,s=s+Math.imul(x,lt)|0,n=n+Math.imul(M,ct)|0,o=(o=o+Math.imul(M,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var kt=(l+(n=n+Math.imul(w,mt)|0)|0)+((8191&(o=(o=o+Math.imul(w,ft)|0)+Math.imul(y,mt)|0))<<13)|0;l=((s=s+Math.imul(y,ft)|0)+(o>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,X))+Math.imul(F,J)|0,s=Math.imul(F,X),n=n+Math.imul(L,Y)|0,o=(o=o+Math.imul(L,tt)|0)+Math.imul(R,Y)|0,s=s+Math.imul(R,tt)|0,n=n+Math.imul(N,rt)|0,o=(o=o+Math.imul(N,nt)|0)+Math.imul(O,rt)|0,s=s+Math.imul(O,nt)|0,n=n+Math.imul(S,st)|0,o=(o=o+Math.imul(S,it)|0)+Math.imul(C,st)|0,s=s+Math.imul(C,it)|0,n=n+Math.imul(T,ut)|0,o=(o=o+Math.imul(T,lt)|0)+Math.imul(k,ut)|0,s=s+Math.imul(k,lt)|0,n=n+Math.imul(A,ct)|0,o=(o=o+Math.imul(A,dt)|0)+Math.imul(x,ct)|0,s=s+Math.imul(x,dt)|0;var _t=(l+(n=n+Math.imul(M,mt)|0)|0)+((8191&(o=(o=o+Math.imul(M,ft)|0)+Math.imul(E,mt)|0))<<13)|0;l=((s=s+Math.imul(E,ft)|0)+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(D,Y),o=(o=Math.imul(D,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),n=n+Math.imul(L,rt)|0,o=(o=o+Math.imul(L,nt)|0)+Math.imul(R,rt)|0,s=s+Math.imul(R,nt)|0,n=n+Math.imul(N,st)|0,o=(o=o+Math.imul(N,it)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,it)|0,n=n+Math.imul(S,ut)|0,o=(o=o+Math.imul(S,lt)|0)+Math.imul(C,ut)|0,s=s+Math.imul(C,lt)|0,n=n+Math.imul(T,ct)|0,o=(o=o+Math.imul(T,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var St=(l+(n=n+Math.imul(A,mt)|0)|0)+((8191&(o=(o=o+Math.imul(A,ft)|0)+Math.imul(x,mt)|0))<<13)|0;l=((s=s+Math.imul(x,ft)|0)+(o>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(D,rt),o=(o=Math.imul(D,nt))+Math.imul(F,rt)|0,s=Math.imul(F,nt),n=n+Math.imul(L,st)|0,o=(o=o+Math.imul(L,it)|0)+Math.imul(R,st)|0,s=s+Math.imul(R,it)|0,n=n+Math.imul(N,ut)|0,o=(o=o+Math.imul(N,lt)|0)+Math.imul(O,ut)|0,s=s+Math.imul(O,lt)|0,n=n+Math.imul(S,ct)|0,o=(o=o+Math.imul(S,dt)|0)+Math.imul(C,ct)|0,s=s+Math.imul(C,dt)|0;var Ct=(l+(n=n+Math.imul(T,mt)|0)|0)+((8191&(o=(o=o+Math.imul(T,ft)|0)+Math.imul(k,mt)|0))<<13)|0;l=((s=s+Math.imul(k,ft)|0)+(o>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,n=Math.imul(D,st),o=(o=Math.imul(D,it))+Math.imul(F,st)|0,s=Math.imul(F,it),n=n+Math.imul(L,ut)|0,o=(o=o+Math.imul(L,lt)|0)+Math.imul(R,ut)|0,s=s+Math.imul(R,lt)|0,n=n+Math.imul(N,ct)|0,o=(o=o+Math.imul(N,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Pt=(l+(n=n+Math.imul(S,mt)|0)|0)+((8191&(o=(o=o+Math.imul(S,ft)|0)+Math.imul(C,mt)|0))<<13)|0;l=((s=s+Math.imul(C,ft)|0)+(o>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(D,ut),o=(o=Math.imul(D,lt))+Math.imul(F,ut)|0,s=Math.imul(F,lt),n=n+Math.imul(L,ct)|0,o=(o=o+Math.imul(L,dt)|0)+Math.imul(R,ct)|0,s=s+Math.imul(R,dt)|0;var Nt=(l+(n=n+Math.imul(N,mt)|0)|0)+((8191&(o=(o=o+Math.imul(N,ft)|0)+Math.imul(O,mt)|0))<<13)|0;l=((s=s+Math.imul(O,ft)|0)+(o>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,n=Math.imul(D,ct),o=(o=Math.imul(D,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var Ot=(l+(n=n+Math.imul(L,mt)|0)|0)+((8191&(o=(o=o+Math.imul(L,ft)|0)+Math.imul(R,mt)|0))<<13)|0;l=((s=s+Math.imul(R,ft)|0)+(o>>>13)|0)+(Ot>>>26)|0,Ot&=67108863;var Bt=(l+(n=Math.imul(D,mt))|0)+((8191&(o=(o=Math.imul(D,ft))+Math.imul(F,mt)|0))<<13)|0;return l=((s=Math.imul(F,ft))+(o>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,u[0]=gt,u[1]=wt,u[2]=yt,u[3]=vt,u[4]=Mt,u[5]=Et,u[6]=bt,u[7]=At,u[8]=xt,u[9]=It,u[10]=Tt,u[11]=kt,u[12]=_t,u[13]=St,u[14]=Ct,u[15]=Pt,u[16]=Nt,u[17]=Ot,u[18]=Bt,0!==l&&(u[19]=l,r.length++),r};function w(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,o=0,s=0;s<r.length-1;s++){var i=o;o=0;for(var a=67108863&n,u=Math.min(s,e.length-1),l=Math.max(0,s-t.length+1);l<=u;l++){var h=s-l,c=(0|t.words[h])*(0|e.words[l]),d=67108863&c;a=67108863&(d=d+a|0),o+=(i=(i=i+(c/67108864|0)|0)+(d>>>26)|0)>>>26,i&=67108863}r.words[s]=a,n=i,i=o}return 0!==n?r.words[s]=n:r.length--,r._strip()}function y(t,e,r){return w(t,e,r)}Math.imul||(g=f),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?f(this,t,e):r<1024?w(this,t,e):y(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),y(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),r("number"==typeof t),r(t<67108864);for(var n=0,o=0;o<this.length;o++){var s=(0|this.words[o])*t,i=(67108863&s)+(67108863&n);n>>=26,n+=s/67108864|0,n+=i>>>26,this.words[o]=67108863&i}return 0!==n&&(this.words[o]=n,this.length++),e?this.ineg():this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,o=r%26;e[r]=t.words[n]>>>o&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var s=r.sqr();n<e.length;n++,s=s.sqr())0!==e[n]&&(r=r.mul(s));return r},o.prototype.iushln=function(t){r("number"==typeof t&&t>=0);var e,n=t%26,o=(t-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var i=0;for(e=0;e<this.length;e++){var a=this.words[e]&s,u=(0|this.words[e])-a<<n;this.words[e]=u|i,i=a>>>26-n}i&&(this.words[e]=i,this.length++)}if(0!==o){for(e=this.length-1;e>=0;e--)this.words[e+o]=this.words[e];for(e=0;e<o;e++)this.words[e]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(t){return r(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,n){var o;r("number"==typeof t&&t>=0),o=e?(e-e%26)/26:0;var s=t%26,i=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,u=n;if(o-=i,o=Math.max(0,o),u){for(var l=0;l<i;l++)u.words[l]=this.words[l];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,l=0;l<this.length;l++)this.words[l]=this.words[l+i];else this.words[0]=0,this.length=1;var h=0;for(l=this.length-1;l>=0&&(0!==h||l>=o);l--){var c=0|this.words[l];this.words[l]=h<<26-s|c>>>s,h=c&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,n){return r(0===this.negative),this.iushrn(t,e,n)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,o=1<<e;return this.length<=n?0:!!(this.words[n]&o)},o.prototype.imaskn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var o=67108863^67108863>>>e<<e;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return r("number"==typeof t),r(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<=t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},o.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,e,n){var o,s,i=t.length+n;this._expand(i);var a=0;for(o=0;o<t.length;o++){s=(0|this.words[o+n])+a;var u=(0|t.words[o])*e;a=((s-=67108863&u)>>26)-(u/67108864|0),this.words[o+n]=67108863&s}for(;o<this.length-n;o++)a=(s=(0|this.words[o+n])+a)>>26,this.words[o+n]=67108863&s;if(0===a)return this._strip();for(r(-1===a),a=0,o=0;o<this.length;o++)a=(s=-(0|this.words[o])+a)>>26,this.words[o]=67108863&s;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),s=t,i=0|s.words[s.length-1];0!=(r=26-this._countBits(i))&&(s=s.ushln(r),n.iushln(r),i=0|s.words[s.length-1]);var a,u=n.length-s.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var l=0;l<a.length;l++)a.words[l]=0}var h=n.clone()._ishlnsubmul(s,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var c=u-1;c>=0;c--){var d=67108864*(0|n.words[s.length+c])+(0|n.words[s.length+c-1]);for(d=Math.min(d/i|0,67108863),n._ishlnsubmul(s,d,c);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(s,1,c),n.isZero()||(n.negative^=1);a&&(a.words[c]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(t,e,n){return r(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(i=a.mod.neg(),n&&0!==i.negative&&i.iadd(t)),{div:s,mod:i}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(i=a.mod.neg(),n&&0!==i.negative&&i.isub(t)),{div:a.div,mod:i}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var s,i,a},o.prototype.div=function(t){return this.divmod(t,"div",0).div},o.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},o.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),o=t.andln(1),s=r.cmp(n);return s<0||1===o&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=(1<<26)%t,o=0,s=this.length-1;s>=0;s--)o=(n*o+(0|this.words[s]))%t;return e?-o:o},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=0,o=this.length-1;o>=0;o--){var s=(0|this.words[o])+67108864*n;this.words[o]=s/t|0,n=s%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new o(1),i=new o(0),a=new o(0),u=new o(1),l=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++l;for(var h=n.clone(),c=e.clone();!e.isZero();){for(var d=0,p=1;0==(e.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||i.isOdd())&&(s.iadd(h),i.isub(c)),s.iushrn(1),i.iushrn(1);for(var m=0,f=1;0==(n.words[0]&f)&&m<26;++m,f<<=1);if(m>0)for(n.iushrn(m);m-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(c)),a.iushrn(1),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(a),i.isub(u)):(n.isub(e),a.isub(s),u.isub(i))}return{a:a,b:u,gcd:n.iushln(l)}},o.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,i=new o(1),a=new o(0),u=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var l=0,h=1;0==(e.words[0]&h)&&l<26;++l,h<<=1);if(l>0)for(e.iushrn(l);l-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var c=0,d=1;0==(n.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(n.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(n)>=0?(e.isub(n),i.isub(a)):(n.isub(e),a.isub(i))}return(s=0===e.cmpn(1)?i:a).cmpn(0)<0&&s.iadd(t),s},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var o=e.cmp(r);if(o<0){var s=e;e=r,r=s}else if(0===o||0===r.cmpn(1))break;e.isub(r)}return r.iushln(n)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){r("number"==typeof t);var e=t%26,n=(t-e)/26,o=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=o,this;for(var s=o,i=n;0!==s&&i<this.length;i++){var a=0|this.words[i];s=(a+=s)>>>26,a&=67108863,this.words[i]=a}return 0!==s&&(this.words[i]=s,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)e=1;else{n&&(t=-t),r(t<=67108863,"Number is too big");var o=0|this.words[0];e=o===t?0:o<t?-1:1}return 0!==this.negative?0|-e:e},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],o=0|t.words[r];if(n!==o){n<o?e=-1:n>o&&(e=1);break}}return e},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new I(t)},o.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var v={k256:null,p224:null,p192:null,p25519:null};function M(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function E(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function x(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function I(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function T(t){I.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}M.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},M.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},M.prototype.split=function(t,e){t.iushrn(this.n,0,e)},M.prototype.imulK=function(t){return t.imul(this.k)},n(E,M),E.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),o=0;o<n;o++)e.words[o]=t.words[o];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&r,o=10;o<t.length;o++){var i=0|t.words[o];t.words[o-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,t.words[o-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},E.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(b,M),n(A,M),n(x,M),x.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,o=67108863&n;n>>>=26,t.words[r]=o,e=n}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(v[t])return v[t];var e;if("k256"===t)e=new E;else if("p224"===t)e=new b;else if("p192"===t)e=new A;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new x}return v[t]=e,e},I.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},I.prototype._verify2=function(t,e){r(0==(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},I.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},I.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},I.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},I.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},I.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},I.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},I.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},I.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},I.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},I.prototype.isqr=function(t){return this.imul(t,t.clone())},I.prototype.sqr=function(t){return this.mul(t,t)},I.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new o(1)).iushrn(2);return this.pow(t,n)}for(var s=this.m.subn(1),i=0;!s.isZero()&&0===s.andln(1);)i++,s.iushrn(1);r(!s.isZero());var a=new o(1).toRed(this),u=a.redNeg(),l=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,l).cmp(u);)h.redIAdd(u);for(var c=this.pow(h,s),d=this.pow(t,s.addn(1).iushrn(1)),p=this.pow(t,s),m=i;0!==p.cmp(a);){for(var f=p,g=0;0!==f.cmp(a);g++)f=f.redSqr();r(g<m);var w=this.pow(c,new o(1).iushln(m-g-1));d=d.redMul(w),c=w.redSqr(),p=p.redMul(c),m=g}return d},I.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},I.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var s=r[0],i=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var l=e.words[n],h=u-1;h>=0;h--){var c=l>>h&1;s!==r[0]&&(s=this.sqr(s)),0!==c||0!==i?(i<<=1,i|=c,(4==++a||0===n&&0===h)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},I.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},I.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new T(t)},n(T,I),T.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},T.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},T.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},T.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,o);var a=i.exports,u=s(a);const l=new u("21888242871839275222246405745257275088548364400416034343698204186575808495617"),h=new u("452312848583266388373324160190187140051835877600158453279131187530910662655"),c="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",d="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",p="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",m=()=>new t.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),f=()=>t.PublicKey.findProgramAddressSync([e.Buffer.from("cpi_authority")],new t.PublicKey(d))[0],g=()=>({registeredProgramPda:new t.PublicKey(m()),noopProgram:new t.PublicKey(c),accountCompressionProgram:new t.PublicKey(p),accountCompressionAuthority:new t.PublicKey(f()),cpiSignatureAccount:null}),w=()=>({nullifierQueue:new t.PublicKey(y),merkleTree:new t.PublicKey(v),merkleTreeHeight:b,addressTree:new t.PublicKey(M),addressQueue:new t.PublicKey(E)}),y="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",v="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",M="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",E="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",b=26,A=new u(Math.floor(2**b*.95)),x=new u(300),I=new u(392),T=new u(5e3),k=new u(5e3);var _=function(t){const e=new Uint8Array(256);for(let t=0;t<e.length;t++)e[t]=255;for(let r=0;r<58;r++){const n=t.charAt(r),o=n.charCodeAt(0);if(255!==e[o])throw new TypeError(n+" is ambiguous");e[o]=r}const r=t.charAt(0),n=Math.log(58)/Math.log(256),o=Math.log(256)/Math.log(58);function s(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;let o=0,s=0,i=0;for(;t[o]===r;)s++,o++;const a=(t.length-o)*n+1>>>0,u=new Uint8Array(a);for(;t[o];){let r=e[t.charCodeAt(o)];if(255===r)return;let n=0;for(let t=a-1;(0!==r||n<i)&&-1!==t;t--,n++)r+=58*u[t]>>>0,u[t]=r%256>>>0,r=r/256>>>0;if(0!==r)throw new Error("Non-zero carry");i=n,o++}let l=a-i;for(;l!==a&&0===u[l];)l++;const h=new Uint8Array(s+(a-l));let c=s;for(;l!==a;)h[c++]=u[l++];return h}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";let n=0,s=0,i=0;const a=e.length;for(;i!==a&&0===e[i];)i++,n++;const u=(a-i)*o+1>>>0,l=new Uint8Array(u);for(;i!==a;){let t=e[i],r=0;for(let e=u-1;(0!==t||r<s)&&-1!==e;e--,r++)t+=256*l[e]>>>0,l[e]=t%58>>>0,t=t/58>>>0;if(0!==t)throw new Error("Non-zero carry");s=r,i++}let h=u-s;for(;h!==u&&0===l[h];)h++;let c=r.repeat(n);for(;h<u;++h)c+=t.charAt(l[h]);return c},decodeUnsafe:s,decode:function(t){const e=s(t);if(e)return e;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const S=(t,e,r)=>new u(t,e,r),C=(t,e)=>{if("base58"===e){if("string"!=typeof t)throw new Error("Must be a base58 string");return C(_.decode(t))}return function(t){if(t.gte(l))throw new Error("Value is too large. Max <254 bits");return t}(new u(t,e))};function P(t){const r=C(t).toArrayLike(e.Buffer,void 0,32);return _.encode(r)}const N=(t,e,r,n)=>({owner:t,lamports:null!=e?e:S(0),address:null!=n?n:null,data:null!=r?r:null}),O=(t,e,r,n,o)=>Object.assign(Object.assign(Object.assign({},N(e,r,n,o)),t),{readOnly:0}),B=(t,e,r,n)=>({merkleTree:t,nullifierQueue:e,hash:r,leafIndex:n});function L(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function R(t,...e){if(!((r=t)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function U(t,e=1){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}const D=BigInt(2**32-1),F=BigInt(32);function V(t,e=0){return e?{h:Number(t&D),l:Number(t>>F&D)}:{h:0|Number(t>>F&D),l:0|Number(t&D)}}function H(t,e=0){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let o=0;o<t.length;o++){const{h:s,l:i}=V(t[o],e);[r[o],n[o]]=[s,i]}return[r,n]}const K=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function q(t){for(let r=0;r<t.length;r++)t[r]=(e=t[r])<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;var e}function Q(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),R(t),t}class j{clone(){return this._cloneInto()}}const W=[],z=[],$=[],Z=BigInt(0),J=BigInt(1),X=BigInt(2),G=BigInt(7),Y=BigInt(256),tt=BigInt(113);for(let t=0,e=J,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],W.push(2*(5*n+r)),z.push((t+1)*(t+2)/2%64);let o=Z;for(let t=0;t<7;t++)e=(e<<J^(e>>G)*tt)%Y,e&X&&(o^=J<<(J<<BigInt(t))-J);$.push(o)}const[et,rt]=H($,1),nt=(t,e,r)=>r>32?((t,e,r)=>e<<r-32|t>>>64-r)(t,e,r):((t,e,r)=>t<<r|e>>>32-r)(t,e,r),ot=(t,e,r)=>r>32?((t,e,r)=>t<<r-32|e>>>64-r)(t,e,r):((t,e,r)=>e<<r|t>>>32-r)(t,e,r);class st extends j{constructor(t,e,r,n=0,o=24){if(super(),this.blockLen=t,this.suffix=e,this.outputLen=r,this.enableXOF=n,this.rounds=o,this.pos=0,this.posOut=0,this.finished=0,this.destroyed=0,L(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){K||q(this.state32),function(t,e=24){const r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let e=0;e<10;e++)r[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const n=(e+8)%10,o=(e+2)%10,s=r[o],i=r[o+1],a=nt(s,i,1)^r[n],u=ot(s,i,1)^r[n+1];for(let r=0;r<50;r+=10)t[e+r]^=a,t[e+r+1]^=u}let e=t[2],o=t[3];for(let r=0;r<24;r++){const n=z[r],s=nt(e,o,n),i=ot(e,o,n),a=W[r];e=t[a],o=t[a+1],t[a]=s,t[a+1]=i}for(let e=0;e<50;e+=10){for(let n=0;n<10;n++)r[n]=t[e+n];for(let n=0;n<10;n++)t[e+n]^=~r[(n+2)%10]&r[(n+4)%10]}t[0]^=et[n],t[1]^=rt[n]}r.fill(0)}(this.state32,this.rounds),K||q(this.state32),this.posOut=0,this.pos=0}update(t){U(this);const{blockLen:e,state:r}=this,n=(t=Q(t)).length;for(let o=0;o<n;){const s=Math.min(e-this.pos,n-o);for(let e=0;e<s;e++)r[this.pos++]^=t[o++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=1;const{state:t,suffix:e,pos:r,blockLen:n}=this;t[r]^=e,0!=(128&e)&&r===n-1&&this.keccak(),t[n-1]^=128,this.keccak()}writeInto(t){U(this,0),R(t),this.finish();const e=this.state,{blockLen:r}=this;for(let n=0,o=t.length;n<o;){this.posOut>=r&&this.keccak();const s=Math.min(r-this.posOut,o-n);t.set(e.subarray(this.posOut,this.posOut+s),n),this.posOut+=s,n+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return L(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(function(t,e){R(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=1,this.state.fill(0)}_cloneInto(t){const{blockLen:e,suffix:r,outputLen:n,rounds:o,enableXOF:s}=this;return t||(t=new st(e,r,n,s,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=n,t.enableXOF=s,t.destroyed=this.destroyed,t}}const it=(()=>function(t){const e=e=>t().update(Q(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}((()=>new st(136,1,32))))();function at(t){return"0x"+t.toString("hex")}const ut=t=>Array.isArray(t)?t:[t];function lt(t){return S(t,void 0,"be").lt(l)}function ht(t){let r=255;for(;r>=0;){const n=e.Buffer.concat([t,e.Buffer.from([r])]),o=it(n);if(32!==o.length)throw new Error("Invalid hash length");if(o[0]=0,lt(e.Buffer.from(o)))return[e.Buffer.from(o),r];r-=1}return null}function ct(t){const e=it.create();for(const r of t)e.update(r);const r=e.digest();return r[0]=0,r}function dt(t){return Array.isArray(t)?t.map((t=>dt(t))):null!==t&&t.constructor===Object?Object.keys(t).reduce(((e,r)=>(e[r.replace(/([-_][a-z])/gi,(t=>t.toUpperCase().replace("-","").replace("_","")))]=dt(t[r]),e)),{}):t}function pt(t,e){const r=t.findIndex((t=>t.equals(e)));return-1===r?(t.push(e),t.length-1):r}function mt(t,e,r){if(e<=0)return[];if(void 0===t)return 0===r.length?new Array(e).fill(w().merkleTree):new Array(e).fill(r[0].merkleTree);{const r=ut(t);return r.length>=e?r.slice(0,e):r.concat(new Array(e-r.length).fill(r[0]))}}function ft(t){return t.map((t=>({pubkey:t,isWritable:1,isSigner:0})))}function gt(t,e,r,n,o=[]){const s=o.slice(),i=[],a=[];t.forEach(((t,r)=>{const n=pt(s,t.merkleTree),o=pt(s,t.nullifierQueue);i.push({compressedAccount:{owner:t.owner,lamports:t.lamports,address:t.address,data:t.data},merkleContext:{merkleTreePubkeyIndex:n,nullifierQueuePubkeyIndex:o,leafIndex:t.leafIndex,queueIndex:null},rootIndex:e[r],readOnly:0})}));const u=mt(n,r.length,t);return r.forEach(((t,e)=>{const r=pt(s,u[e]);a.push({compressedAccount:{owner:t.owner,lamports:t.lamports,address:t.address,data:t.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:s}}const wt=t=>{if(t.lt(S(0)))throw new Error("Not enough balance for transfer")},yt=t=>{if(0===t.length)throw new Error("No accounts provided for validation");const e=t[0].owner;if(!t.every((t=>t.owner.equals(e))))throw new Error("All input accounts must have the same owner")};function vt(t,e){return ct([e.toBytes(),...t])}function Mt(e,r=w().addressTree){if(32!=e.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=ht(Buffer.from([...n,...e]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new t.PublicKey(s)}function Et(t,e){const r=e.slice(),n=t.map((t=>({seed:Array.from(t.seed),addressMerkleTreeRootIndex:t.addressMerkleTreeRootIndex,addressMerkleTreeAccountIndex:0,addressQueueAccountIndex:0})));return t.forEach(((t,e)=>{n[e].addressMerkleTreeAccountIndex=pt(r,t.addressMerkleTreePubkey)})),t.forEach(((t,e)=>{n[e].addressQueueAccountIndex=pt(r,t.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function bt(t,e,r="confirmed"){const n=await t.getLatestBlockhash(r),o={signature:e.toString(),lastValidBlockHeight:n.lastValidBlockHeight,blockhash:n.blockhash};return await t.confirmTransaction(o,r)}function At(t){const e=It(t.ar[0]),r=It(t.ar[1]),n=new Uint8Array([...e,...r]),o=It(t.bs[0][0]),s=It(t.bs[0][1]),i=It(t.bs[1][0]),a=It(t.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),l=It(t.krs[0]),h=It(t.krs[1]);return{a:n,b:u,c:new Uint8Array([...l,...h])}}function xt(t){const e=t.a,r=t.b,n=t.c,o=e.slice(0,32),s=Tt(new u(e.slice(32,64),32,"be"))?0:1;o[0]=kt(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),h=function(t,e){const r=l.div(new u(2));return t.lt(r)?1:t.gt(r)?0:e.lt(r)}(new u(a.slice(0,32),32,"be"),new u(a.slice(32,64),32,"be"));i[0]=kt(i[0],h);const c=n.slice(0,32),d=n.slice(32,64),p=Tt(new u(d,32,"be"));return c[0]=kt(c[0],p),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function It(t){const e=new u(t.startsWith("0x")?t.substring(2):t,"hex");return new Uint8Array(e.toArray("be",32))}function Tt(t){return t.lte(l.sub(t))}function kt(t,e){return e?t:128|t}function _t(e,r,n,o){const s=new t.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:e}).compileToV0Message(o);return new t.VersionedTransaction(s)}async function St(t,e,r,n){const o=await t.sendTransaction(e,r);n||(n=await t.getLatestBlockhash());const s={signature:o,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},i=(await t.confirmTransaction(s,(null==r?void 0:r.commitment)||t.commitment||"confirmed")).context.slot;return await t.confirmTransactionIndexed(i),o}async function Ct(t,e,r,n){n||(n=await t.getLatestBlockhash());const o={signature:e,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},s=await t.confirmTransaction(o,(null==r?void 0:r.commitment)||t.commitment||"confirmed"),i=s.context.slot;return await t.confirmTransactionIndexed(i),s}function Pt(t,e,r,n=[],o){if(n.includes(e))throw new Error("payer must not be in additionalSigners");const s=[e,...n],i=_t(t,e.publicKey,r,o);return i.sign(s),i}let Nt=1;const Ot=Ut(255),Bt=Ut(254),Lt=Ut(253),Rt=Ut(252);function Ut(e){if(e||(e=Nt,Nt++),e>255)return t.Keypair.generate();const r=new Uint8Array(32);return r[31]=e,t.Keypair.fromSeed(r)}var Dt={};!function(e){var n=o&&o.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:1}),e.map=e.array=e.rustEnum=e.str=e.vecU8=e.tagged=e.vec=e.bool=e.option=e.publicKey=e.i256=e.u256=e.i128=e.u128=e.i64=e.u64=e.struct=e.f64=e.f32=e.i32=e.u32=e.i16=e.u16=e.i8=e.u8=void 0;const s=r,i=t,u=n(a);var l=r;Object.defineProperty(e,"u8",{enumerable:1,get:function(){return l.u8}}),Object.defineProperty(e,"i8",{enumerable:1,get:function(){return l.s8}}),Object.defineProperty(e,"u16",{enumerable:1,get:function(){return l.u16}}),Object.defineProperty(e,"i16",{enumerable:1,get:function(){return l.s16}}),Object.defineProperty(e,"u32",{enumerable:1,get:function(){return l.u32}}),Object.defineProperty(e,"i32",{enumerable:1,get:function(){return l.s32}}),Object.defineProperty(e,"f32",{enumerable:1,get:function(){return l.f32}}),Object.defineProperty(e,"f64",{enumerable:1,get:function(){return l.f64}}),Object.defineProperty(e,"struct",{enumerable:1,get:function(){return l.struct}});class h extends s.Layout{constructor(t,e,r){super(t,r),this.blob=(0,s.blob)(t),this.signed=e}decode(t,e=0){const r=new u.default(this.blob.decode(t,e),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(t,e,r=0){return this.signed&&(t=t.toTwos(8*this.span)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),e,r)}}function c(t){return new h(8,0,t)}e.u64=c,e.i64=function(t){return new h(8,1,t)},e.u128=function(t){return new h(16,0,t)},e.i128=function(t){return new h(16,1,t)},e.u256=function(t){return new h(32,0,t)},e.i256=function(t){return new h(32,1,t)};class d extends s.Layout{constructor(t,e,r,n){super(t.span,n),this.layout=t,this.decoder=e,this.encoder=r}decode(t,e){return this.decoder(this.layout.decode(t,e))}encode(t,e,r){return this.layout.encode(this.encoder(t),e,r)}getSpan(t,e){return this.layout.getSpan(t,e)}}e.publicKey=function(t){return new d((0,s.blob)(32),(t=>new i.PublicKey(t)),(t=>t.toBuffer()),t)};class p extends s.Layout{constructor(t,e){super(-1,e),this.layout=t,this.discriminator=(0,s.u8)()}encode(t,e,r=0){return null==t?this.discriminator.encode(0,e,r):(this.discriminator.encode(1,e,r),this.layout.encode(t,e,r+1)+1)}decode(t,e=0){const r=this.discriminator.decode(t,e);if(0===r)return null;if(1===r)return this.layout.decode(t,e+1);throw new Error("Invalid option "+this.property)}getSpan(t,e=0){const r=this.discriminator.decode(t,e);if(0===r)return 1;if(1===r)return this.layout.getSpan(t,e+1)+1;throw new Error("Invalid option "+this.property)}}function m(t){if(0===t)return 0;if(1===t)return 1;throw new Error("Invalid bool: "+t)}function f(t){return t?1:0}function g(t){const e=(0,s.u32)("length"),r=(0,s.struct)([e,(0,s.blob)((0,s.offset)(e,-e.span),"data")]);return new d(r,(({data:t})=>t),(t=>({data:t})),t)}e.option=function(t,e){return new p(t,e)},e.bool=function(t){return new d((0,s.u8)(),m,f,t)},e.vec=function(t,e){const r=(0,s.u32)("length"),n=(0,s.struct)([r,(0,s.seq)(t,(0,s.offset)(r,-r.span),"values")]);return new d(n,(({values:t})=>t),(t=>({values:t})),e)},e.tagged=function(t,e,r){const n=(0,s.struct)([c("tag"),e.replicate("data")]);return new d(n,(function({tag:e,data:r}){if(!e.eq(t))throw new Error("Invalid tag, expected: "+t.toString("hex")+", got: "+e.toString("hex"));return r}),(e=>({tag:t,data:e})),r)},e.vecU8=g,e.str=function(t){return new d(g(),(t=>t.toString("utf-8")),(t=>Buffer.from(t,"utf-8")),t)},e.rustEnum=function(t,e,r){const n=(0,s.union)(null!=r?r:(0,s.u8)(),e);return t.forEach(((t,e)=>n.addVariant(e,t,t.property))),n},e.array=function(t,e,r){const n=(0,s.struct)([(0,s.seq)(t,e,"values")]);return new d(n,(({values:t})=>t),(t=>({values:t})),r)};class w extends s.Layout{constructor(t,e,r){super(t.span+e.span,r),this.keyLayout=t,this.valueLayout=e}decode(t,e){return e=e||0,[this.keyLayout.decode(t,e),this.valueLayout.decode(t,e+this.keyLayout.getSpan(t,e))]}encode(t,e,r){r=r||0;const n=this.keyLayout.encode(t[0],e,r);return n+this.valueLayout.encode(t[1],e,r+n)}getSpan(t,e){return this.keyLayout.getSpan(t,e)+this.valueLayout.getSpan(t,e)}}e.map=function(t,e,r){const n=(0,s.u32)("length"),o=(0,s.struct)([n,(0,s.seq)(new w(t,e),(0,s.offset)(n,-n.span),"values")]);return new d(o,(({values:t})=>new Map(t)),(t=>({values:Array.from(t.entries())})),r)}}(Dt);const Ft=Dt.struct([Dt.publicKey("owner"),Dt.u64("lamports"),Dt.option(Dt.array(Dt.u8(),32),"address"),Dt.option(Dt.struct([Dt.array(Dt.u8(),8,"discriminator"),Dt.vecU8("data"),Dt.array(Dt.u8(),32,"dataHash")]),"data")],"compressedAccount"),Vt=Dt.struct([Dt.u8("merkleTreePubkeyIndex"),Dt.u8("nullifierQueuePubkeyIndex"),Dt.u32("leafIndex"),Dt.option(Dt.struct([Dt.u8("queueId"),Dt.u16("index")]),"queueIndex")],"merkleContext"),Ht=Dt.struct([Dt.array(Dt.u8(),32,"seed"),Dt.u8("addressQueueAccountIndex"),Dt.u8("addressMerkleTreeAccountIndex"),Dt.u16("addressMerkleTreeRootIndex")],"newAddressParams"),Kt=Dt.struct([Dt.option(Dt.struct([Dt.array(Dt.u8(),32,"a"),Dt.array(Dt.u8(),64,"b"),Dt.array(Dt.u8(),32,"c")]),"proof"),Dt.vec(Dt.struct([Ft,Vt,Dt.u16("rootIndex"),Dt.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),Dt.vec(Dt.struct([Ft,Dt.u8("merkleTreeIndex")]),"outputCompressedAccounts"),Dt.option(Dt.u64(),"relayFee"),Dt.vec(Ht,"newAddressParams"),Dt.option(Dt.u64(),"compressOrDecompressLamports"),Dt.bool("isCompress")]);function qt(t){const r=e.Buffer.alloc(1e3),n=Kt.encode(t,r),o=e.Buffer.from(r.slice(0,n)),s=e.Buffer.alloc(4);return s.writeUInt32LE(n,0),e.Buffer.concat([e.Buffer.from([26,16,169,7,21,202,242,25]),s,o])}const Qt=t=>{const e=Zt.programId,{feePayer:r,authority:n,registeredProgramPda:o,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:l,systemProgram:h}=t;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:null!=u?u:e,isSigner:0,isWritable:null!==u},{pubkey:null!=l?l:e,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0}]},jt=Dt.struct([Dt.vec(Dt.array(Dt.u8(),32),"inputCompressedAccountHashes"),Dt.vec(Dt.array(Dt.u8(),32),"outputCompressedAccountHashes"),Dt.vec(Dt.struct([Dt.struct([Dt.publicKey("owner"),Dt.u64("lamports"),Dt.option(Dt.array(Dt.u8(),32),"address"),Dt.option(Dt.struct([Dt.array(Dt.u8(),8,"discriminator"),Dt.vecU8("data"),Dt.array(Dt.u8(),32,"dataHash")]),"data")],"compressedAccount"),Dt.u8("merkleTreeIndex")]),"outputCompressedAccounts"),Dt.vec(Dt.u32(),"outputLeafIndices"),Dt.vec(Dt.struct([Dt.publicKey("pubkey"),Dt.u64("seq")]),"sequenceNumbers"),Dt.option(Dt.u64(),"relayFee"),Dt.bool("isCompress"),Dt.option(Dt.u64(),"compressOrDecompressLamports"),Dt.vec(Dt.publicKey(),"pubkeyArray"),Dt.option(Dt.vecU8(),"message")]);function Wt(t){return jt.decode(t)}const zt=t=>t.reduce(((t,e)=>t.add(S(e.lamports))),S(0)),$t=e.Buffer.from("sol_pool_pda");class Zt{constructor(){}static deriveCompressedSolPda(){const e=[$t],[r,n]=t.PublicKey.findProgramAddressSync(e,this.programId);return r}static createTransferOutputState(t,e,r){r=S(r);const n=zt(t).sub(r);return wt(n),n.eq(S(0))?[N(e,r)]:(yt(t),[N(t[0].owner,n),N(e,r)])}static createDecompressOutputState(t,e){e=S(e);const r=zt(t).sub(e);return wt(r),r.eq(S(0))?[]:(yt(t),[N(t[0].owner,r)])}static createNewAddressOutputState(t,e,r,n){r=S(null!=r?r:0);const o=zt(null!=n?n:[]).sub(r);return wt(o),o.eq(S(0))||!n?[N(e,r,void 0,t)]:(yt(n),[N(n[0].owner,o),N(e,r,void 0,t)])}static async createAccount({payer:e,newAddressParams:r,newAddress:n,recentValidityProof:o,outputStateTree:s,inputCompressedAccounts:i,inputStateRootIndices:a,lamports:u}){const l=this.createNewAddressOutputState(n,e,u,i),{packedInputCompressedAccounts:h,packedOutputCompressedAccounts:c,remainingAccounts:d}=gt(null!=i?i:[],null!=a?a:[],l,s),{newAddressParamsPacked:p,remainingAccounts:m}=Et([r],d),f=qt({proof:o,inputCompressedAccountsWithMerkleContext:h,outputCompressedAccounts:c,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),w=[...Qt(Object.assign(Object.assign({},g()),{feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:t.SystemProgram.programId})),...ft(m)];return new t.TransactionInstruction({programId:this.programId,keys:w,data:f})}static async transfer({payer:e,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i,outputStateTrees:a}){const u=this.createTransferOutputState(r,n,o),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:h,remainingAccounts:c}=gt(r,s,u,a),d=qt({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:h,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),p=[...Qt(Object.assign(Object.assign({},g()),{feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:t.SystemProgram.programId})),...ft(c)];return new t.TransactionInstruction({programId:this.programId,keys:p,data:d})}static async compress({payer:e,toAddress:r,lamports:n,outputStateTree:o}){n=S(n);const s=N(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=gt([],[],[s],o),l=qt({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),h=[...Qt(Object.assign(Object.assign({},g()),{feePayer:e,authority:e,solPoolPda:this.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:t.SystemProgram.programId})),...ft(u)];return new t.TransactionInstruction({programId:this.programId,keys:h,data:l})}static async decompress({payer:e,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i,outputStateTree:a}){o=S(o);const u=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:h,remainingAccounts:c}=gt(r,s,u,a),d=qt({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:h,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),p=[...Qt(Object.assign(Object.assign({},g()),{feePayer:e,authority:e,solPoolPda:this.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:t.SystemProgram.programId})),...ft(c)];return new t.TransactionInstruction({programId:this.programId,keys:p,data:d})}}function Jt(t,e){let r=S(0);e=S(e);const n=[];t.sort(((t,e)=>e.lamports.cmp(t.lamports)));for(const o of t){if(r.gte(S(e)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(S(e)))throw new Error(`Not enough balance for transfer. Required: ${e.toString()}, available: ${r.toString()}`);return[n,r]}var Xt,Gt,Yt,te,ee,re,ne,oe;Zt.programId=new t.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"),exports.UtxoErrorCode=void 0,(Xt=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",Xt.NOT_U64="NOT_U64",Xt.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(Gt=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",Gt.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(Yt=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",Yt.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",Yt.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(te=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",te.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",te.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",te.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(ee=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",ee.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED",exports.HashErrorCode=void 0,(exports.HashErrorCode||(exports.HashErrorCode={})).NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED",exports.ProofErrorCode=void 0,(re=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",re.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",re.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(ne=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",ne.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",ne.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",ne.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",ne.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",ne.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(oe=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",oe.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",oe.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",oe.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",oe.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",oe.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",oe.INVALID_NUMBER="INVALID_NUMBER";class se extends Error{constructor(t,e,r){super(`${t}: ${r}`),this.code=t,this.functionName=e,this.codeMessage=r}}const ie=n.coerce(n.instance(t.PublicKey),n.string(),(e=>new t.PublicKey(e))),ae=n.coerce(n.instance(Array),n.string(),(e=>Array.from(new t.PublicKey(e).toBytes()))),ue=n.coerce(n.instance(u),n.string(),(t=>C(t,"base58"))),le=n.coerce(n.instance(u),n.number(),(t=>Number.isSafeInteger(t)?S(t):S(t.toString(),10))),he=n.coerce(n.string(),n.string(),(t=>""===t?null:t));function ce(t){return n.union([n.type({jsonrpc:n.literal("2.0"),id:n.string(),result:t}),n.type({jsonrpc:n.literal("2.0"),id:n.string(),error:n.type({code:n.unknown(),message:n.string(),data:n.nullable(n.any())})})])}const de=ce(n.unknown());function pe(t){return n.coerce(ce(t),de,(e=>"error"in e?e:Object.assign(Object.assign({},e),{result:n.create(e.result,t)})))}function me(t){return pe(n.type({context:n.type({slot:n.number()}),value:t}))}const fe=n.type({address:n.nullable(ae),hash:ue,data:n.nullable(n.type({data:he,dataHash:ue,discriminator:le})),lamports:le,owner:ie,leafIndex:n.number(),tree:ie,seq:n.nullable(le),slotCreated:le}),ge=n.type({mint:ie,owner:ie,amount:le,delegate:n.nullable(ie),state:n.string()}),we=n.type({tokenData:ge,account:fe}),ye=n.type({items:n.array(fe)}),ve=n.type({items:n.array(fe),cursor:n.nullable(n.string())}),Me=n.type({items:n.array(we),cursor:n.nullable(n.string())}),Ee=n.number(),be=n.string(),Ae=n.type({items:n.array(n.type({signature:n.string(),slot:n.number(),blockTime:n.number(),error:n.nullable(n.string())}))}),xe=n.type({items:n.array(n.type({signature:n.string(),slot:n.number(),blockTime:n.number()})),cursor:n.nullable(n.string())}),Ie=n.type({hash:ue,leafIndex:n.number(),merkleTree:ie,proof:n.array(ue),rootSeq:n.number(),root:ue}),Te=n.type({address:ue,nextIndex:n.number(),merkleTree:ie,proof:n.array(ue),rootSeq:n.number(),root:ue,lowerRangeAddress:ue,higherRangeAddress:ue,lowElementLeafIndex:n.number()}),ke=n.type({a:n.array(n.number()),b:n.array(n.number()),c:n.array(n.number())}),_e=n.type({compressedProof:ke,leafIndices:n.array(n.number()),leaves:n.array(ue),rootIndices:n.array(n.number()),roots:n.array(ue),merkleTrees:n.array(ie)}),Se=n.array(Ie),Ce=n.type({amount:le}),Pe=le,Ne=n.type({balance:le,mint:ie}),Oe=n.type({tokenBalances:n.array(Ne),cursor:n.nullable(n.string())}),Be=n.type({items:n.array(Ne),cursor:n.nullable(n.string())}),Le=n.type({cursor:n.nullable(n.string()),items:n.array(n.type({balance:le,owner:ie}))}),Re=n.type({hash:n.array(n.number()),root:n.array(n.number()),proof:n.array(n.array(n.number()))}),Ue=n.type({items:n.array(n.type({blockTime:n.number(),signature:n.string(),slot:n.number()}))}),De=n.type({items:n.array(n.type({blockTime:n.number(),signature:n.string(),slot:n.number()})),cursor:n.nullable(n.string())}),Fe=n.type({compressionInfo:n.type({closedAccounts:n.array(n.type({account:fe,optionalTokenData:n.nullable(ge)})),openedAccounts:n.array(n.type({account:fe,optionalTokenData:n.nullable(ge)}))}),transaction:n.any()});function Ve({discriminator:t,data:r,dataHash:n}){return{discriminator:t.toArray("le",8),data:e.Buffer.from(r,"base64"),dataHash:n.toArray("le",32)}}async function He(e,r,o,s=0){var i,a;const u=s?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner",l=s?"delegate":"owner",h=await qe(e.compressionApiEndpoint,u,{[l]:r.toBase58(),mint:null===(i=o.mint)||void 0===i?void 0:i.toBase58(),limit:null===(a=o.limit)||void 0===a?void 0:a.toNumber(),cursor:o.cursor}),c=n.create(h,me(Me));if("error"in c)throw new t.SolanaJSONRPCError(c.error,`failed to get info for compressed accounts by ${l} ${r.toBase58()}`);if(null===c.result.value)throw new Error("not implemented: NULL result");const d=[];return c.result.value.items.map((t=>{var e;const n=t.account,o=t.tokenData,s=O(B(n.tree,$e,n.hash.toArray("be",32),n.leafIndex),n.owner,S(n.lamports),n.data?Ve(n.data):void 0,n.address||void 0),i={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(e=i[l])||void 0===e?void 0:e.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${l} different from requested ${l}`);d.push({compressedAccount:s,parsed:i})})),{items:d.sort(((t,e)=>e.compressedAccount.leafIndex-t.compressedAccount.leafIndex)),cursor:c.result.value.cursor}}function Ke(t){const e=t.account,r=t.optionalTokenData,n=O(B(e.merkleTree,$e,e.hash.toArray("be",32),e.leafIndex),e.owner,S(e.lamports),e.data?Ve(e.data):void 0,e.address||void 0);return null===r?{account:n,maybeTokenData:null}:{account:n,maybeTokenData:{mint:r.mint,owner:r.owner,amount:r.amount,delegate:r.delegate,state:["uninitialized","initialized","frozen"].indexOf(r.state),tlv:null}}}const qe=async(t,e,r=[],n=1)=>{const o=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:e,params:r}),s=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:o});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return n?dt(await s.json()):await s.json()},Qe=async(t,e,r=[])=>{let n;"inclusion"===e?n=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===e?n=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===e&&(n=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const o=await fetch(`${t}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:n});if(!o.ok)throw new Error(`Error fetching proof: ${o.statusText}`);return xt(At(await o.json()))};function je(t){const e=[];for(let r=0;r<t.length;r++){const n={root:at(t[r].root),pathIndex:t[r].leafIndex,pathElements:t[r].merkleProof.map((t=>at(t))),leaf:at(S(t[r].hash))};e.push(n)}return e}function We(t){const e=[];for(let r=0;r<t.length;r++){const n={root:at(t[r].root),value:at(t[r].value),pathIndex:t[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:t[r].merkleProofHashedIndexedElementLeaf.map((t=>at(t))),nextIndex:t[r].nextIndex.toNumber(),leafLowerRangeValue:at(t[r].leafLowerRangeValue),leafHigherRangeValue:at(t[r].leafHigherRangeValue)};e.push(n)}return e}function ze(t,e,r){if(t.length!==e.length)throw new Error("Input lengths must match.");if(0===t.length)return new u(0);let n=r.poseidonHashBN([t[0].toString(),e[0].toString()]);for(let o=1;o<t.length;o++)n=r.poseidonHashBN([n.toString(),t[o].toString(),e[o].toString()]);return n}const $e=w().nullifierQueue,Ze=w().addressQueue;class Je extends t.Connection{constructor(e,r,n,o){super(e,o||"confirmed"),this.connection=new t.Connection(e,o||"confirmed"),this.compressionApiEndpoint=r,this.proverEndpoint=n}get commitment(){return this.connection.commitment}get rpcEndpoint(){return this.connection.rpcEndpoint}async getBalanceAndContext(t,e){return this.connection.getBalanceAndContext(t,e)}async getBalance(t,e){return this.connection.getBalance(t,e)}async getBlockTime(t){return this.connection.getBlockTime(t)}async getMinimumLedgerSlot(){return this.connection.getMinimumLedgerSlot()}async getFirstAvailableBlock(){return this.connection.getFirstAvailableBlock()}async getSupply(t){return this.connection.getSupply(t)}async getTokenSupply(t,e){return this.connection.getTokenSupply(t,e)}async getTokenAccountBalance(t,e){return this.connection.getTokenAccountBalance(t,e)}async getTokenAccountsByOwner(t,e,r){return this.connection.getTokenAccountsByOwner(t,e,r)}async getParsedTokenAccountsByOwner(t,e,r){return this.connection.getParsedTokenAccountsByOwner(t,e,r)}async getLargestAccounts(t){return this.connection.getLargestAccounts(t)}async getTokenLargestAccounts(t,e){return this.connection.getTokenLargestAccounts(t,e)}async getAccountInfoAndContext(t,e){return this.connection.getAccountInfoAndContext(t,e)}async getParsedAccountInfo(t,e){return this.connection.getParsedAccountInfo(t,e)}async getAccountInfo(t,e){return this.connection.getAccountInfo(t,e)}async getMultipleParsedAccounts(t,e){return this.connection.getMultipleParsedAccounts(t,e)}async getMultipleAccountsInfoAndContext(t,e){return this.connection.getMultipleAccountsInfoAndContext(t,e)}async getMultipleAccountsInfo(t,e){return this.connection.getMultipleAccountsInfo(t,e)}async getStakeActivation(t,e,r){return this.connection.getStakeActivation(t,e,r)}async getProgramAccounts(t,e){return this.connection.getProgramAccounts(t,e)}async getParsedProgramAccounts(t,e){return this.connection.getParsedProgramAccounts(t,e)}async getParsedBlock(t,e){return this.connection.getParsedBlock(t,e)}async getConfirmedTransaction(t,e){return this.connection.getConfirmedTransaction(t,e)}async getParsedConfirmedTransaction(t,e){return this.connection.getParsedConfirmedTransaction(t,e)}async getParsedConfirmedTransactions(t,e){return this.connection.getParsedConfirmedTransactions(t,e)}async getConfirmedSignaturesForAddress(t,e,r){return this.connection.getConfirmedSignaturesForAddress(t,e,r)}async getConfirmedSignaturesForAddress2(t,e,r){return this.connection.getConfirmedSignaturesForAddress2(t,e,r)}async getSignaturesForAddress(t,e,r){return this.connection.getSignaturesForAddress(t,e,r)}async getRecentPrioritizationFees(t){return this.connection.getRecentPrioritizationFees(t)}async getLatestBlockhash(t){return this.connection.getLatestBlockhash(t)}async getLatestBlockhashAndContext(t){return this.connection.getLatestBlockhashAndContext(t)}async isBlockhashValid(t,e){return this.connection.isBlockhashValid(t,e)}async getVersion(){return this.connection.getVersion()}async getAddressLookupTable(t,e){return this.connection.getAddressLookupTable(t,e)}async getNonceAndContext(t,e){return this.connection.getNonceAndContext(t,e)}async getNonce(t,e){return this.connection.getNonce(t,e)}async getCompressedAccount(e,r){if(!r&&!e)throw new Error("Either hash or address must be provided");if(r&&e)throw new Error("Only one of hash or address must be provided");const o=await qe(this.compressionApiEndpoint,"getCompressedAccount",{hash:r?P(r):void 0,address:e?P(e):void 0}),s=n.create(o,me(n.nullable(fe)));if("error"in s)throw new t.SolanaJSONRPCError(s.error,`failed to get info for compressed account ${r?r.toString():e?e.toString():""}`);if(null===s.result.value)return null;const i=s.result.value;return O(B(i.tree,$e,i.hash.toArray("be",32),i.leafIndex),i.owner,S(i.lamports),i.data?Ve(i.data):void 0,i.address||void 0)}async getCompressedBalance(e,r){if(!r&&!e)throw new Error("Either hash or address must be provided");if(r&&e)throw new Error("Only one of hash or address must be provided");const o=await qe(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?P(r):void 0,address:e?P(e):void 0}),s=n.create(o,me(Pe));if("error"in s)throw new t.SolanaJSONRPCError(s.error,`failed to get balance for compressed account ${r?r.toString():e?e.toString():""}`);return null===s.result.value?S(0):S(s.result.value)}async getCompressedBalanceByOwner(e){const r=await qe(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:e.toBase58()}),o=n.create(r,me(Pe));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get balance for compressed account ${e.toBase58()}`);return null===o.result.value?S(0):S(o.result.value)}async getCompressedAccountProof(e){const r=await qe(this.compressionApiEndpoint,"getCompressedAccountProof",{hash:P(e)}),o=n.create(r,me(Ie));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get proof for compressed account ${e.toString()}`);if(null===o.result.value)throw new Error(`failed to get proof for compressed account ${e.toString()}`);return{hash:o.result.value.hash.toArray("be",32),merkleTree:o.result.value.merkleTree,leafIndex:o.result.value.leafIndex,merkleProof:o.result.value.proof,nullifierQueue:$e,rootIndex:o.result.value.rootSeq%2400,root:o.result.value.root}}async getMultipleCompressedAccounts(e){const r=await qe(this.compressionApiEndpoint,"getMultipleCompressedAccounts",{hashes:e.map((t=>P(t)))}),o=n.create(r,me(ye));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts ${e.map((t=>P(t))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get info for compressed accounts ${e.map((t=>P(t))).join(", ")}`);const s=[];return o.result.value.items.map((t=>{const e=O(B(t.tree,$e,t.hash.toArray("be",32),t.leafIndex),t.owner,S(t.lamports),t.data?Ve(t.data):void 0,t.address||void 0);s.push(e)})),s.sort(((t,e)=>e.leafIndex-t.leafIndex))}async getMultipleCompressedAccountProofs(e){const r=await qe(this.compressionApiEndpoint,"getMultipleCompressedAccountProofs",e.map((t=>P(t)))),o=n.create(r,me(n.array(Ie)));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get proofs for compressed accounts ${e.map((t=>P(t))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get proofs for compressed accounts ${e.map((t=>P(t))).join(", ")}`);const s=[];for(const t of o.result.value){const e={hash:t.hash.toArray("be",32),merkleTree:t.merkleTree,leafIndex:t.leafIndex,merkleProof:t.proof,nullifierQueue:Ze,rootIndex:t.rootSeq%2400,root:t.root};s.push(e)}return s}async getCompressedAccountsByOwner(e,r){var o;const s=await qe(this.compressionApiEndpoint,"getCompressedAccountsByOwner",{owner:e.toBase58(),filters:(null==r?void 0:r.filters)||[],dataSlice:null==r?void 0:r.dataSlice,cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,me(ve));if("error"in i)throw new t.SolanaJSONRPCError(i.error,`failed to get info for compressed accounts owned by ${e.toBase58()}`);if(null===i.result.value)return{items:[],cursor:null};const a=[];return i.result.value.items.map((t=>{const e=O(B(t.tree,$e,t.hash.toArray("be",32),t.leafIndex),t.owner,S(t.lamports),t.data?Ve(t.data):void 0,t.address||void 0);a.push(e)})),{items:a.sort(((t,e)=>e.leafIndex-t.leafIndex)),cursor:i.result.value.cursor}}async getCompressedTokenAccountsByOwner(t,e){return e||(e={}),await He(this,t,e,0)}async getCompressedTokenAccountsByDelegate(t,e){return e||(e={}),He(this,t,e,1)}async getCompressedTokenAccountBalance(e){const r=await qe(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:P(e)}),o=n.create(r,me(Ce));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get balance for compressed token account ${e.toString()}`);if(null===o.result.value)throw new Error(`failed to get balance for compressed token account ${e.toString()}`);return{amount:S(o.result.value.amount)}}async getCompressedTokenBalancesByOwner(e,r){var o,s;r||(r={});const i=await qe(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:e.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(s=r.limit)||void 0===s?void 0:s.toNumber(),cursor:r.cursor}),a=n.create(i,me(Oe));if("error"in a)throw new t.SolanaJSONRPCError(a.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===a.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);return{items:r.mint?a.result.value.tokenBalances.filter((t=>t.mint.toBase58()===r.mint.toBase58())):a.result.value.tokenBalances,cursor:a.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(e,r){var o,s;r||(r={});const i=await qe(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:e.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(s=r.limit)||void 0===s?void 0:s.toNumber(),cursor:r.cursor}),a=n.create(i,me(Be));if("error"in a)throw new t.SolanaJSONRPCError(a.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===a.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);const u=r.mint?a.result.value.items.filter((t=>t.mint.toBase58()===r.mint.toBase58())):a.result.value.items;return{context:a.result.context,value:{items:u,cursor:a.result.value.cursor}}}async getCompressionSignaturesForAccount(e){const r=await qe(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:P(e)}),o=n.create(r,me(Ue));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get signatures for compressed account ${e.toString()}`);return o.result.value.items}async getTransactionWithCompressionInfo(e){const r=await qe(this.compressionApiEndpoint,"getTransactionWithCompressionInfo",{signature:e}),o=n.create(r,pe(Fe));if("error"in o)throw new t.SolanaJSONRPCError(o.error,"failed to get slot");if(null===o.result.transaction)return null;const s=[],i=[];o.result.compressionInfo.closedAccounts.map((t=>{s.push(Ke(t))})),o.result.compressionInfo.openedAccounts.map((t=>{i.push(Ke(t))}));const a=t=>{const e=Object.values(t.reduce(((t,{maybeTokenData:e})=>{if(e){const{owner:r,mint:n,amount:o}=e,s=`${r.toBase58()}_${n.toBase58()}`;s in t?t[s].amount=t[s].amount.add(o):t[s]={owner:r,mint:n,amount:o}}return t}),{}));return e.length>0?e:void 0},u=a(s),l=a(i);return{compressionInfo:{closedAccounts:s,openedAccounts:i,preTokenBalances:u,postTokenBalances:l},transaction:o.result.transaction}}async getCompressionSignaturesForAddress(e,r){var o;const s=await qe(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:e.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,me(De));if("error"in i)throw new t.SolanaJSONRPCError(i.error,`failed to get signatures for address ${e.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for address ${e.toBase58()}`);return i.result.value}async getCompressionSignaturesForOwner(e,r){var o;const s=await qe(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:e.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,me(De));if("error"in i)throw new t.SolanaJSONRPCError(i.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return i.result.value}async getCompressionSignaturesForTokenOwner(e,r){var o;const s=await qe(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:e.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,me(De));if("error"in i)throw new t.SolanaJSONRPCError(i.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return i.result.value}async getIndexerHealth(){const e=await qe(this.compressionApiEndpoint,"getIndexerHealth"),r=n.create(e,pe(be));if("error"in r)throw new t.SolanaJSONRPCError(r.error,"failed to get health");return r.result}async confirmTransactionIndexed(t){const e=Date.now();for(;;){if(await this.getIndexerSlot()>=t)return 1;if(Date.now()-e>2e4)throw new Error("Timeout: Indexer slot did not reach the required slot within 20 seconds");await new Promise((t=>setTimeout(t,200)))}}async getIndexerSlot(){const e=await qe(this.compressionApiEndpoint,"getIndexerSlot"),r=n.create(e,pe(Ee));if("error"in r)throw new t.SolanaJSONRPCError(r.error,"failed to get slot");return r.result}async getCompressedMintTokenHolders(e,r){var o;const s=await qe(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:e.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,me(Le));if("error"in i)throw new t.SolanaJSONRPCError(i.error,"failed to get mint token holders");return i.result}async getLatestCompressionSignatures(e,r){const o=await qe(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:e}),s=n.create(o,me(xe));if("error"in s)throw new t.SolanaJSONRPCError(s.error,"failed to get latest non-voting signatures");return s.result}async getLatestNonVotingSignatures(e,r){const o=await qe(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:e,cursor:r}),s=n.create(o,me(Ae));if("error"in s)throw new t.SolanaJSONRPCError(s.error,"failed to get latest non-voting signatures");return s.result}async getMultipleNewAddressProofs(e){const r=await qe(this.compressionApiEndpoint,"getMultipleNewAddressProofs",e.map((t=>P(t)))),o=n.create(r,me(n.array(Te)));if("error"in o)throw new t.SolanaJSONRPCError(o.error,`failed to get proofs for new addresses ${e.map((t=>P(t))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get proofs for new addresses ${e.map((t=>P(t))).join(", ")}`);const s=[];for(const t of o.result.value){const e={root:t.root,rootIndex:t.rootSeq%2400,value:t.address,leafLowerRangeValue:t.lowerRangeAddress,leafHigherRangeValue:t.higherRangeAddress,nextIndex:S(t.nextIndex),merkleProofHashedIndexedElementLeaf:t.proof,indexHashedIndexedElementLeaf:S(t.lowElementLeafIndex),merkleTree:t.merkleTree,nullifierQueue:Ze};s.push(e)}return s}async getValidityProofDirect(t=[],e=[]){let r;if(0===t.length&&0===e.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(t.length>0&&0===e.length){const e=await this.getMultipleCompressedAccountProofs(t),n=je(e);r={compressedProof:await Qe(this.proverEndpoint,"inclusion",n),roots:e.map((t=>t.root)),rootIndices:e.map((t=>t.rootIndex)),leafIndices:e.map((t=>t.leafIndex)),leaves:e.map((t=>S(t.hash))),merkleTrees:e.map((t=>t.merkleTree)),nullifierQueues:e.map((t=>t.nullifierQueue))}}else if(0===t.length&&e.length>0){const t=await this.getMultipleNewAddressProofs(e),n=We(t);r={compressedProof:await Qe(this.proverEndpoint,"new-address",n),roots:t.map((t=>t.root)),rootIndices:t.map((t=>t.rootIndex)),leafIndices:t.map((t=>t.nextIndex.toNumber())),leaves:t.map((t=>S(t.value))),merkleTrees:t.map((t=>t.merkleTree)),nullifierQueues:t.map((t=>t.nullifierQueue))}}else{if(!(t.length>0&&e.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(t),o=je(n),s=await this.getMultipleNewAddressProofs(e),i=We(s);r={compressedProof:await Qe(this.proverEndpoint,"combined",[o,i]),roots:n.map((t=>t.root)).concat(s.map((t=>t.root))),rootIndices:n.map((t=>t.rootIndex)).concat(s.map((t=>t.rootIndex))),leafIndices:n.map((t=>t.leafIndex)).concat(s.map((t=>t.nextIndex.toNumber()))),leaves:n.map((t=>S(t.hash))).concat(s.map((t=>S(t.value)))),merkleTrees:n.map((t=>t.merkleTree)).concat(s.map((t=>t.merkleTree))),nullifierQueues:n.map((t=>t.nullifierQueue)).concat(s.map((t=>t.nullifierQueue)))}}}return r}async getValidityProof(t=[],e=[]){const r=w().addressTree,n=w().addressQueue,o=w().merkleTree,s=w().nullifierQueue,i=t.map((t=>({hash:t,tree:o,queue:s}))),a=e.map((t=>({address:t,tree:r,queue:n})));return this.getValidityProofV0(i,a)}async getValidityProofV0(t=[],e=[]){const{value:r}=await this.getValidityProofAndRpcContext(t,e);return r}async getValidityProofAndRpcContext(e=[],r=[]){const o=await qe(this.compressionApiEndpoint,"getValidityProof",{hashes:e.map((({hash:t})=>P(t))),newAddressesWithTrees:r.map((({address:t,tree:e})=>({address:P(t),tree:e.toBase58()})))}),s=n.create(o,me(_e));if("error"in s)throw new t.SolanaJSONRPCError(s.error,`failed to get ValidityProof for compressed accounts ${e.map((t=>t.toString()))}`);const i=s.result.value;if(null===i)throw new Error(`failed to get ValidityProof for compressed accounts ${e.map((t=>t.toString()))}`);return{value:{compressedProof:i.compressedProof,merkleTrees:i.merkleTrees,leafIndices:i.leafIndices,nullifierQueues:[...e.map((({queue:t})=>t)),...r.map((({queue:t})=>t))],rootIndices:i.rootIndices,roots:i.roots,leaves:i.leaves},context:s.result.context}}}class Xe{constructor(t,e,r){this.index=t,this.value=e,this.nextIndex=r}equals(t){return this.value.eq(t.value)}compareTo(t){return this.value.cmp(t.value)}hash(t,e){try{return t.poseidonHash([S(this.value.toArray("be",32)).toString(),S(this.nextIndex).toString(),S(e.toArray("be",32)).toString()])}catch(t){throw new Error("Hashing failed")}}}class Ge{constructor(t,e,r){this.newLowElement=t,this.newElement=e,this.newElementNextValue=r}}class Ye{constructor(t,e,r){this.elements=t,this.currentNodeIndex=e,this.highestElementIndex=r}static default(){return new Ye([new Xe(0,S(0),0)],0,0)}get(t){return this.elements[t]}length(){return Number(this.currentNodeIndex)}isEmpty(){return 0===this.currentNodeIndex}findElement(t){return this.elements.slice(0,this.length()+1).find((e=>e.value===t))}init(){try{const t=h;return this.append(t)}catch(t){throw new Error(`Failed to initialize IndexedArray: ${t}`)}}findLowElementIndex(t){for(let e=0;e<=this.length();e++){const r=this.elements[e];if(this.elements[r.nextIndex].value.gt(t)&&r.value.lt(t))return e;if(r.value.eq(t))throw new Error("Element already exists in the array")}return this.highestElementIndex}findLowElement(t){const e=this.findLowElementIndex(t);if(void 0===e)return[void 0,void 0];const r=this.elements[e];return[r,this.elements[r.nextIndex].value]}hashElement(t,e){const r=this.elements[e];if(!r)return;const n=this.elements[r.nextIndex];return n?t.poseidonHash([S(r.value.toArray("be",32)).toString(),S(r.nextIndex).toString(),S(n.value.toArray("be",32)).toString()]):void 0}append(t){const e=this.findLowElementIndex(t);if(void 0===e)throw new Error("Low element index not found.");return this.appendWithLowElementIndex(e,t)}appendWithLowElementIndex(t,e){const r=this.elements[t];if(0===r.nextIndex){if(e.lte(r.value))throw new Error("New element value must be greater than the low element value.")}else{const t=this.elements[r.nextIndex];if(e.lte(r.value))throw new Error("New element value must be greater than the low element value.");if(e.gte(t.value))throw new Error("New element value must be less than the next element value.")}const n=this.newElementWithLowElementIndex(t,e);return 0===r.nextIndex&&(this.highestElementIndex=n.newElement.index),this.currentNodeIndex=n.newElement.index,this.elements[this.length()]=n.newElement,this.elements[t]=n.newLowElement,n}lowest(){return this.elements.length>0?this.elements[0]:void 0}newElementWithLowElementIndex(t,e){const r=this.elements[t],n=this.currentNodeIndex+1,o=new Xe(n,e,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new Ge(r,o,s)}newElement(t){const e=this.findLowElementIndex(t);if(void 0===e)throw new Error("Low element index not found.");return this.newElementWithLowElementIndex(e,t)}}class tr{constructor(t,e,r=[],{zeroElement:n="0"}={}){if(this.levels=t,this.capacity=2**t,this.zeroElement=n,this._lightWasm=e,r.length>this.capacity)throw new Error("Tree is full");this._zeros=[],this._layers=[],this._layers[0]=r,this._zeros[0]=this.zeroElement;for(let e=1;e<=t;e++)this._zeros[e]=this._lightWasm.poseidonHashString([this._zeros[e-1],this._zeros[e-1]]);this._rebuild()}_rebuild(){for(let t=1;t<=this.levels;t++){this._layers[t]=[];for(let e=0;e<Math.ceil(this._layers[t-1].length/2);e++)this._layers[t][e]=this._lightWasm.poseidonHashString([this._layers[t-1][2*e],2*e+1<this._layers[t-1].length?this._layers[t-1][2*e+1]:this._zeros[t-1]])}}root(){return this._layers[this.levels].length>0?this._layers[this.levels][0]:this._zeros[this.levels]}insert(t){if(this._layers[0].length>=this.capacity)throw new Error("Tree is full");this.update(this._layers[0].length,t)}bulkInsert(t){if(this._layers[0].length+t.length>this.capacity)throw new Error("Tree is full");this._layers[0].push(...t),this._rebuild()}update(t,e){if(isNaN(Number(t))||t<0||t>this._layers[0].length||t>=this.capacity)throw new Error("Insert index out of bounds: "+t);this._layers[0][t]=e;for(let e=1;e<=this.levels;e++)t>>=1,this._layers[e][t]=this._lightWasm.poseidonHashString([this._layers[e-1][2*t],2*t+1<this._layers[e-1].length?this._layers[e-1][2*t+1]:this._zeros[e-1]])}path(t){if(isNaN(Number(t))||t<0||t>=this._layers[0].length)throw new Error("Index out of bounds: "+t);const e=[],r=[];for(let n=0;n<this.levels;n++)r[n]=t%2,e[n]=(1^t)<this._layers[n].length?this._layers[n][1^t]:this._zeros[n],t>>=1;return{pathElements:e,pathIndices:r}}indexOf(t,e=null){return e?this._layers[0].findIndex((r=>e(t,r))):this._layers[0].indexOf(t)}elements(){return this._layers[0].slice()}serialize(){return{levels:this.levels,_zeros:this._zeros,_layers:this._layers}}static deserialize(t,e){const r=Object.assign(Object.create(this.prototype),t);return r._hash=e,r.capacity=2**r.levels,r.zeroElement=r._zeros[0],r}}async function er(t){const{noopProgram:e,accountCompressionProgram:r}=g(),n=(await t.getConfirmedSignaturesForAddress2(r,void 0,"confirmed")).map((t=>t.signature)),o=(await t.getParsedTransactions(n,{maxSupportedTransactionVersion:0,commitment:"confirmed"})).filter((t=>t?t.transaction.message.accountKeys.some((t=>("string"==typeof t?t:t.pubkey.toBase58())===e.toBase58())):0));return rr(o,nr)}const rr=(t,e)=>{const{noopProgram:r}=g(),n=[];return t.forEach((t=>{!t||!t.meta||t.meta.err||!t.meta.innerInstructions||t.meta.innerInstructions.length<=0||t.meta.innerInstructions.forEach((o=>{if(o.instructions.length>0){const s=o.instructions[o.instructions.length-1];if("data"in s&&s.data&&s.programId.toBase58()===r.toBase58()){const r=_.decode(s.data),o=e(Buffer.from(r),t);null!=o&&n.push(o)}}}))})),n},nr=t=>{const e=Buffer.from(t.map((t=>t)));try{return Wt(e)}catch(t){return null}};async function or(t,e){return(await sr(t)).find((t=>S(t.hash).eq(e)))}async function sr(t){var e,r;const n=(await er(t)).reverse(),o=[],s=[];for(const t of n){for(let n=0;n<t.outputCompressedAccounts.length;n++){const s=t.outputCompressedAccounts[n],i={merkleTree:w().merkleTree,nullifierQueue:w().nullifierQueue,hash:t.outputCompressedAccountHashes[n],leafIndex:t.outputLeafIndices[n]},a=O(i,s.compressedAccount.owner,s.compressedAccount.lamports,null!==(e=s.compressedAccount.data)&&void 0!==e?e:void 0,null!==(r=s.compressedAccount.address)&&void 0!==r?r:void 0);o.push(a)}for(let e=0;e<t.inputCompressedAccountHashes.length;e++){const r=t.inputCompressedAccountHashes[e];s.push(S(r))}}const i=o.filter((t=>!s.some((e=>e.eq(S(t.hash))))));return i.sort(((t,e)=>e.leafIndex-t.leafIndex)),i}const ir=new t.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),ar=Dt.struct([Dt.publicKey("mint"),Dt.publicKey("owner"),Dt.u64("amount"),Dt.option(Dt.publicKey(),"delegate"),Dt.u8("state"),Dt.option(Dt.vecU8(),"tlv")]);function ur(t,e=ir){if(null===t.data)return null;const{data:r}=t.data;if(0===r.length)return null;if(t.owner.toBase58()!==e.toBase58())throw new Error(`Invalid owner ${t.owner.toBase58()} for token layout`);return ar.decode(Buffer.from(r))}async function lr(t){const e=await Promise.all(t.map((t=>async function(t){const e=t.pubkeyArray,r=t.outputCompressedAccountHashes,n=t.outputCompressedAccounts.map(((n,o)=>{var s;const i={merkleTree:e[t.outputCompressedAccounts[o].merkleTreeIndex],nullifierQueue:w().nullifierQueue,hash:r[o],leafIndex:t.outputLeafIndices[o]};if(!n.compressedAccount.data)throw new Error("No data");const a=ur(n.compressedAccount);if(!a)throw new Error("Invalid token data");return{compressedAccount:O(i,n.compressedAccount.owner,n.compressedAccount.lamports,n.compressedAccount.data,null!==(s=n.compressedAccount.address)&&void 0!==s?s:void 0),parsed:a}}));return{inputCompressedAccountHashes:t.inputCompressedAccountHashes,outputCompressedAccounts:n}}(t)))),r=e.flatMap((t=>t.outputCompressedAccounts)),n=e.flatMap((t=>t.inputCompressedAccountHashes));return r.filter((t=>!n.some((e=>JSON.stringify(e)===JSON.stringify(t.compressedAccount.hash)))))}async function hr(t,e,r){const n=await er(t);return{items:(await lr(n)).filter((t=>t.parsed.owner.equals(e)&&t.parsed.mint.equals(r))).sort(((t,e)=>e.compressedAccount.leafIndex-t.compressedAccount.leafIndex)),cursor:null}}async function cr(t,e,r){const n=await er(t);return{items:(await lr(n)).filter((t=>{var n;return(null===(n=t.parsed.delegate)||void 0===n?void 0:n.equals(e))&&t.parsed.mint.equals(r)})),cursor:null}}async function dr(t,e){const r=await er(t),n=(await lr(r)).filter((t=>S(t.compressedAccount.hash).eq(e)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class pr extends t.Connection{constructor(e,r,n,o,s,i){super(e,s||"confirmed"),this.log=0,this.connection=new t.Connection(e,s||"confirmed"),this.compressionApiEndpoint=n,this.proverEndpoint=o;const{merkleTreeAddress:a,nullifierQueueAddress:u,depth:l,log:h,addressTreeAddress:c,addressQueueAddress:d}=null!=i?i:{},{merkleTree:p,nullifierQueue:m,merkleTreeHeight:f,addressQueue:g,addressTree:y}=w();this.lightWasm=r,this.merkleTreeAddress=null!=a?a:p,this.nullifierQueueAddress=null!=u?u:m,this.addressTreeAddress=null!=c?c:y,this.addressQueueAddress=null!=d?d:g,this.depth=null!=l?l:f,this.log=null!=h?h:0}async getCompressedAccount(t,e){if(t)throw new Error("address is not supported in test-rpc");if(!e)throw new Error("hash is required");const r=await or(this,e);return null!=r?r:null}async getCompressedBalance(t,e){if(t)throw new Error("address is not supported in test-rpc");if(!e)throw new Error("hash is required");const r=await or(this,e);if(!r)throw new Error("Account not found");return S(r.lamports)}async getCompressedBalanceByOwner(t){return(await this.getCompressedAccountsByOwner(t)).items.reduce(((t,e)=>t.add(e.lamports)),S(0))}async getCompressedAccountProof(t){return(await this.getMultipleCompressedAccountProofs([t]))[0]}async getMultipleCompressedAccounts(t){return await async function(t,e){return(await sr(t)).filter((t=>e.some((e=>S(t.hash).eq(e))))).sort(((t,e)=>e.leafIndex-t.leafIndex))}(this,t)}async confirmTransactionIndexed(t){return 1}async getMultipleCompressedAccountProofs(t){const e=await er(this).then((t=>t.reverse())),r=[],n=[];for(const t of e)for(let e=0;e<t.outputCompressedAccounts.length;e++){const o=t.outputCompressedAccountHashes[e];r.push(o),n.push(t.outputLeafIndices[e])}const o=new tr(this.depth,this.lightWasm,r.map((t=>S(t).toString()))),s=[];for(let e=0;e<t.length;e++){const n=o.indexOf(t[e].toString()),i=o.path(n).pathElements.map((t=>S(t))),a=S(o.root()),u={hash:t[e].toArray("be",32),merkleTree:this.merkleTreeAddress,leafIndex:n,merkleProof:i,nullifierQueue:this.nullifierQueueAddress,rootIndex:r.length,root:a};s.push(u)}return s.forEach(((t,e)=>{const r=t.leafIndex,n=o.elements()[r],s=S(n).toArray("be",32);if(!s.every(((e,r)=>e===t.hash[r])))throw new Error(`Mismatch at index ${e}: expected ${t.hash.toString()}, got ${s.toString()}`)})),s}async getCompressedAccountsByOwner(t,e){const r=await async function(t,e){return(await sr(t)).filter((t=>t.owner.equals(e)))}(this,t);return{items:r,cursor:null}}async getLatestCompressionSignatures(t,e){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getLatestNonVotingSignatures(t){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getCompressedTokenAccountsByOwner(t,e){return await hr(this,t,e.mint)}async getCompressedTokenAccountsByDelegate(t,e){return await cr(this,t,e.mint)}async getCompressedTokenAccountBalance(t){const e=await dr(this,t);return{amount:S(e.parsed.amount)}}async getCompressedTokenBalancesByOwner(t,e){return{items:(await hr(this,t,e.mint)).items.map((t=>({balance:S(t.parsed.amount),mint:t.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(t,e){return{context:{slot:1},value:{items:(await hr(this,t,e.mint)).items.map((t=>({balance:S(t.parsed.amount),mint:t.parsed.mint}))),cursor:null}}}async getCompressionSignaturesForAccount(t){throw new Error("getCompressionSignaturesForAccount not implemented in test-rpc")}async getTransactionWithCompressionInfo(t){throw new Error("getCompressedTransaction not implemented in test-rpc")}async getCompressionSignaturesForAddress(t,e){throw new Error("getSignaturesForAddress3 not implemented")}async getCompressionSignaturesForOwner(t,e){throw new Error("getSignaturesForOwner not implemented")}async getCompressionSignaturesForTokenOwner(t,e){throw new Error("getSignaturesForTokenOwner not implemented")}async getIndexerHealth(){return"ok"}async getIndexerSlot(){return 1}async getMultipleNewAddressProofs(t){const e=Ye.default(),r=[];e.init();const n=[];for(let t=0;t<r.length;t++)e.append(S(r[t]));for(let t=0;t<e.elements.length;t++){const r=e.hashElement(this.lightWasm,t);n.push(S(r))}const o=new tr(this.depth,this.lightWasm,n.map((t=>S(t).toString()))),s=[];for(let r=0;r<t.length;r++){const[n]=e.findLowElement(t[r]);if(!n)throw new Error("Address not found");const i=n.index,a=o.path(i).pathElements.map((t=>S(t))),u=e.get(n.nextIndex).value,l={root:S(o.root()),rootIndex:3,value:t[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:S(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:S(n.index),merkleTree:this.addressTreeAddress,nullifierQueue:this.addressQueueAddress};s.push(l)}return s}async getCompressedMintTokenHolders(t,e){throw new Error("getCompressedMintTokenHolders not implemented in test-rpc")}async getValidityProofDirect(t=[],e=[]){return this.getValidityProof(t,e)}async getValidityProofAndRpcContext(t=[],e=[]){if(e.some((t=>!(t instanceof u))))throw new Error("AddressWithTree is not supported in test-rpc");return{value:await this.getValidityProofV0(t,e),context:{slot:1}}}async getValidityProof(t=[],e=[]){if(e.some((t=>!(t instanceof u))))throw new Error("AddressWithTree is not supported in test-rpc");let r;if(0===t.length&&0===e.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(t.length>0&&0===e.length){const e=await this.getMultipleCompressedAccountProofs(t),n=je(e);r={compressedProof:await Qe(this.proverEndpoint,"inclusion",n,this.log),roots:e.map((t=>t.root)),rootIndices:e.map((t=>t.rootIndex)),leafIndices:e.map((t=>t.leafIndex)),leaves:e.map((t=>S(t.hash))),merkleTrees:e.map((t=>t.merkleTree)),nullifierQueues:e.map((t=>t.nullifierQueue))}}else if(0===t.length&&e.length>0){const t=await this.getMultipleNewAddressProofs(e),n=We(t);r={compressedProof:await Qe(this.proverEndpoint,"new-address",n,this.log),roots:t.map((t=>t.root)),rootIndices:t.map((()=>3)),leafIndices:t.map((t=>t.indexHashedIndexedElementLeaf.toNumber())),leaves:t.map((t=>S(t.value))),merkleTrees:t.map((t=>t.merkleTree)),nullifierQueues:t.map((t=>t.nullifierQueue))}}else{if(!(t.length>0&&e.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(t),o=je(n),s=await this.getMultipleNewAddressProofs(e),i=We(s);r={compressedProof:await Qe(this.proverEndpoint,"combined",[o,i],this.log),roots:n.map((t=>t.root)).concat(s.map((t=>t.root))),rootIndices:n.map((t=>t.rootIndex)).concat(s.map((()=>3))),leafIndices:n.map((t=>t.leafIndex)).concat(s.map((t=>t.indexHashedIndexedElementLeaf.toNumber()))),leaves:n.map((t=>S(t.hash))).concat(s.map((t=>S(t.value)))),merkleTrees:n.map((t=>t.merkleTree)).concat(s.map((t=>t.merkleTree))),nullifierQueues:n.map((t=>t.nullifierQueue)).concat(s.map((t=>t.nullifierQueue)))}}}return r}async getValidityProofV0(t=[],e=[]){return this.getValidityProof(t.map((t=>t.hash)),e.map((t=>t.address)))}}exports.ADDRESS_QUEUE_ROLLOVER_FEE=I,exports.ADDRESS_TREE_NETWORK_FEE=k,exports.ALICE=Ot,exports.AccountProofResult=Re,exports.BOB=Bt,exports.BalanceResult=Ce,exports.BaseRpc=class{async getCancellationPromise(){throw new Error("getCancellationPromise not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async getTransactionConfirmationPromise(){throw new Error("getTransactionConfirmationPromise not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingBlockHeightExceedanceStrategy(){throw new Error("confirmTransactionUsingBlockHeightExceedanceStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingDurableNonceStrategy(){throw new Error("confirmTransactionUsingDurableNonceStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:t,signature:e}){throw new Error("confirmTransactionUsingLegacyTimeoutStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}},exports.CHARLIE=Lt,exports.CompressedAccountLayout=Ft,exports.CompressedAccountResult=fe,exports.CompressedAccountsByOwnerResult=ve,exports.CompressedMintTokenHoldersResult=Le,exports.CompressedTokenAccountResult=we,exports.CompressedTokenAccountsByOwnerOrDelegateResult=Me,exports.CompressedTransactionResult=Fe,exports.CreateUtxoError=class extends se{},exports.DAVE=Rt,exports.DEFAULT_MERKLE_TREE_HEIGHT=b,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=l,exports.HIGHEST_ADDRESS_PLUS_ONE=h,exports.HashError=class extends se{},exports.HealthResult=be,exports.IndexedArray=Ye,exports.IndexedElement=Xe,exports.IndexedElementBundle=Ge,exports.InstructionDataInvokeLayout=Kt,exports.LatestNonVotingSignaturesResult=Ae,exports.LatestNonVotingSignaturesResultPaginated=xe,exports.LightSystemProgram=Zt,exports.LookupTableError=class extends se{},exports.MerkeProofResult=Ie,exports.MerkleContextLayout=Vt,exports.MerkleTree=tr,exports.MerkleTreeError=class extends se{},exports.MultipleCompressedAccountsResult=ye,exports.MultipleMerkleProofsResult=Se,exports.NativeBalanceResult=Pe,exports.NewAddressParamsLayout=Ht,exports.NewAddressProofResult=Te,exports.ProofError=class extends se{},exports.PublicTransactionEventLayout=jt,exports.Rpc=Je,exports.RpcError=class extends se{},exports.STATE_MERKLE_TREE_NETWORK_FEE=T,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=x,exports.SelectInUtxosError=class extends se{},exports.SignatureListResult=Ue,exports.SignatureListWithCursorResult=De,exports.SlotResult=Ee,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=A,exports.TestRpc=pr,exports.TokenBalanceListResult=Oe,exports.TokenBalanceListResultV2=Be,exports.TokenBalanceResult=Ne,exports.TokenDataLayout=ar,exports.TokenDataResult=ge,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends se{},exports.UtxoError=class extends se{},exports.ValidityProofResult=_e,exports.accountCompressionProgram=p,exports.addressQueue=E,exports.addressTree=M,exports.airdropSol=async function({connection:t,lamports:e,recipientPublicKey:r}){const n=await t.requestAirdrop(r,e);return await bt(t,n),n},exports.bn=S,exports.bufToDecStr=t=>C(t).toString(),exports.buildAndSignTx=Pt,exports.buildTx=_t,exports.byteArrayToKeypair=function(e){return t.Keypair.fromSecretKey(Uint8Array.from(e))},exports.calculateComputeUnitPrice=function(t,e){return Math.ceil(1e6*t/e)},exports.checkValidityProofShape=t=>{if(32!==t.a.length||64!==t.b.length||32!==t.c.length)throw new Error("ValidityProof has invalid shape")},exports.compress=async function(e,r,n,o,s,i){const{blockhash:a}=await e.getLatestBlockhash(),u=await Zt.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTree:s}),l=Pt([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await St(e,l,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=bt,exports.confirmTx=Ct,exports.convertMerkleProofsWithContextToHex=je,exports.convertNonInclusionMerkleProofInputsToHex=We,exports.createAccount=async function(e,r,n,o,s,i,a,u){const{blockhash:l}=await e.getLatestBlockhash();s=null!=s?s:w().addressTree,i=null!=i?i:w().addressQueue;const h=vt(n,o),c=Mt(h,s),d=await e.getValidityProofV0(void 0,[{address:S(c.toBytes()),tree:s,queue:i}]),p={seed:h,addressMerkleTreeRootIndex:d.rootIndices[0],addressMerkleTreePubkey:d.merkleTrees[0],addressQueuePubkey:d.nullifierQueues[0]},m=await Zt.createAccount({payer:r.publicKey,newAddressParams:p,newAddress:Array.from(c.toBytes()),recentValidityProof:d.compressedProof,programId:o,outputStateTree:a}),f=Pt([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),m],r,l,[]);return await St(e,f,u)},exports.createAccountWithLamports=async function(e,r,n,o,s,i,a,u,l){o=S(o);const h=await e.getCompressedAccountsByOwner(r.publicKey),[c]=Jt(h.items,o),{blockhash:d}=await e.getLatestBlockhash();i=null!=i?i:w().addressTree,a=null!=a?a:w().addressQueue;const p=vt(n,s),m=Mt(p,i),f=await e.getValidityProof(c.map((t=>S(t.hash))),[S(m.toBytes())]),g={seed:p,addressMerkleTreeRootIndex:f.rootIndices[f.rootIndices.length-1],addressMerkleTreePubkey:f.merkleTrees[f.merkleTrees.length-1],addressQueuePubkey:f.nullifierQueues[f.nullifierQueues.length-1]},y=await Zt.createAccount({payer:r.publicKey,newAddressParams:g,newAddress:Array.from(m.toBytes()),recentValidityProof:f.compressedProof,inputCompressedAccounts:c,inputStateRootIndices:f.rootIndices,programId:s,outputStateTree:u}),v=Pt([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),y],r,d,[]);return await St(e,v,l)},exports.createBN254=C,exports.createCompressedAccount=N,exports.createCompressedAccountWithMerkleContext=O,exports.createMerkleContext=B,exports.createRpc=function(t="http://127.0.0.1:8899",e="http://127.0.0.1:8784",r="http://127.0.0.1:3001",n){const o="string"==typeof t?t:t.rpcEndpoint;return new Je(o,e,r,n)},exports.createRpcResult=ce,exports.decodeInstructionDataInvoke=function(t){return Kt.decode(t)},exports.decodePublicTransactionEvent=Wt,exports.decompress=async function(e,r,n,o,s,i){const a=(await e.getCompressedAccountsByOwner(r.publicKey)).items;n=S(n);const u=zt(a);if(n.gt(u))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${u}`);const l=await e.getValidityProof(a.map((t=>S(t.hash)))),{blockhash:h}=await e.getLatestBlockhash(),c=await Zt.decompress({payer:r.publicKey,toAddress:o,outputStateTree:s,inputCompressedAccounts:a,recentValidityProof:l.compressedProof,recentInputStateRootIndices:l.rootIndices,lamports:n}),d=Pt([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),c],r,h,[]);return await St(e,d,i)},exports.dedupeSigner=function(t,e){return e.includes(t)?e.filter((e=>e.publicKey.toString()!==t.publicKey.toString())):e},exports.defaultStaticAccounts=()=>[new t.PublicKey(m()),new t.PublicKey(c),new t.PublicKey(p),new t.PublicKey(f())],exports.defaultStaticAccountsStruct=g,exports.defaultTestStateTreeAccounts=w,exports.deriveAddress=Mt,exports.deriveAddressSeed=vt,exports.encodeBN254toBase58=P,exports.encodeInstructionDataInvoke=qt,exports.encodePublicTransactionEvent=function(t){const r=e.Buffer.alloc(1e3),n=jt.encode(t,r);return r.slice(0,n)},exports.getAccountCompressionAuthority=f,exports.getCompressedTokenAccountByHashTest=dr,exports.getCompressedTokenAccounts=lr,exports.getCompressedTokenAccountsByDelegateTest=cr,exports.getCompressedTokenAccountsByOwnerTest=hr,exports.getConnection=function(){return new t.Connection("http://127.0.0.1:8899","confirmed")},exports.getIndexOrAdd=pt,exports.getParsedEvents=er,exports.getPublicInputHash=function(t,e,r,n){const o=ze(t.map((t=>t.root)),e,n),s=r.map((t=>t.value)),i=ze(r.map((t=>t.root)),s,n);return i.isZero()?o.isZero()?ze([o],[i],n):o:i},exports.getRegisteredProgramPda=m,exports.getTestKeypair=Ut,exports.getTestRpc=async function(t,e="http://127.0.0.1:8899",r="http://127.0.0.1:8784",n="http://127.0.0.1:3001",o,s,i,a=0){const u=w();return new pr(e,t,r,n,void 0,{merkleTreeAddress:o||u.merkleTree,nullifierQueueAddress:s||u.nullifierQueue,depth:i||u.merkleTreeHeight,log:a})},exports.hashToBn254FieldSizeBe=ht,exports.hashvToBn254FieldSizeBe=ct,exports.invokeAccountsLayout=Qt,exports.jsonRpcResult=pe,exports.jsonRpcResultAndContext=me,exports.lightProgram=d,exports.merkletreePubkey=v,exports.negateAndCompressProof=xt,exports.newAccountWithLamports=async function(t,e=1e9,r){(void 0===r||r>255)&&(r=256);const n=Ut(r),o=await t.requestAirdrop(n.publicKey,e);return await Ct(t,o),n},exports.noopProgram=c,exports.nullifierQueuePubkey=y,exports.packCompressedAccounts=gt,exports.packNewAddressParams=Et,exports.padOutputStateMerkleTrees=mt,exports.parseAccountData=Ve,exports.parseEvents=rr,exports.parsePublicTransactionEventWithIdl=nr,exports.parseTokenLayoutWithIdl=ur,exports.pipe=function(t,...e){return r=>e.reduce(((t,e)=>e(t)),t(r))},exports.placeholderValidityProof=()=>({a:Array.from({length:32},((t,e)=>e+1)),b:Array.from({length:64},((t,e)=>e+1)),c:Array.from({length:32},((t,e)=>e+1))}),exports.proofFromJsonStruct=At,exports.proverRequest=Qe,exports.pushUniqueItems=function(t,e){t.forEach((t=>{e.includes(t)||e.push(t)}))},exports.rpcRequest=qe,exports.selectMinCompressedSolAccountsForTransfer=Jt,exports.sendAndConfirmTx=St,exports.sleep=function(t){return new Promise((e=>setTimeout(e,t)))},exports.sumUpLamports=zt,exports.toAccountMetas=ft,exports.toArray=ut,exports.toCamelCase=dt,exports.toHex=at,exports.toUnixTimestamp=t=>new Date(t).getTime(),exports.transfer=async function(e,r,n,o,s,i,a){var l;let h=S(0);const c=[];let d;for(n=S(n);h.lt(n);){const t={filters:void 0,dataSlice:void 0,cursor:d,limit:new u(1e3)},r=await e.getCompressedAccountsByOwner(o.publicKey,t);for(const t of r.items)t.lamports.gt(new u(0))&&(c.push(t),h=h.add(t.lamports));if(d=null!==(l=r.cursor)&&void 0!==l?l:void 0,r.items.length<1e3||h.gte(n))break}if(h.lt(n))throw new Error(`Not enough balance for transfer. Required: ${n.toString()}, available: ${h.toString()}`);const[p]=Jt(c,n),m=await e.getValidityProof(p.map((t=>S(t.hash)))),f=await Zt.transfer({payer:r.publicKey,inputCompressedAccounts:p,toAddress:s,lamports:n,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,outputStateTrees:i}),{blockhash:g}=await e.getLatestBlockhash(),w=Pt([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,g);return await St(e,w,a)},exports.validateSameOwner=yt,exports.validateSufficientBalance=wt;
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t=require("buffer"),r=require("buffer-layout"),n=require("superstruct"),o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i={exports:{}};!function(e,t){function r(e,t){if(!e)throw new Error(t||"Assertion failed")}function n(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function o(e,t,r){if(o.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var s;"object"==typeof i?i.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(e){}function a(e,t){var n=e.charCodeAt(t);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(0,"Invalid character in "+e)}function u(e,t,r){var n=a(e,r);return r-1>=t&&(n|=a(e,r-1)<<4),n}function l(e,t,n,o){for(var s=0,i=0,a=Math.min(e.length,n),u=t;u<a;u++){var l=e.charCodeAt(u)-48;s*=o,i=l>=49?l-49+10:l>=17?l-17+10:l,r(l>=0&&i<o,"Invalid character"),s+=i}return s}function h(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(o.isBN=function(e){return e instanceof o?1:null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,n){if("number"==typeof e)return this._initNumber(e,t,n);if("object"==typeof e)return this._initArray(e,t,n);"hex"===t&&(t=16),r(t===(0|t)&&t>=2&&t<=36);var o=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<e.length&&(16===t?this._parseHex(e,o,n):(this._parseBase(e,t,o),"le"===n&&this._initArray(this.toArray(),t,n)))},o.prototype._initNumber=function(e,t,n){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),t,n)},o.prototype._initArray=function(e,t,n){if(r("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var s,i,a=0;if("be"===n)for(o=e.length-1,s=0;o>=0;o-=3)i=e[o]|e[o-1]<<8|e[o-2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===n)for(o=0,s=0;o<e.length;o+=3)i=e[o]|e[o+1]<<8|e[o+2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},o.prototype._parseHex=function(e,t,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,s=0,i=0;if("be"===r)for(n=e.length-1;n>=t;n-=2)o=u(e,t,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;else for(n=(e.length-t)%2==0?t+1:t;n<e.length;n+=2)o=u(e,t,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;this._strip()},o.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,o=1;o<=67108863;o*=t)n++;n--,o=o/t|0;for(var s=e.length-r,i=s%n,a=Math.min(s,s-i)+r,u=0,h=r;h<a;h+=n)u=l(e,h,h+n,t),this.imuln(o),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==i){var c=1;for(u=l(e,h,e.length,t),h=0;h<i;h++)c*=t;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},o.prototype._move=function(e){h(e,this)},o.prototype.clone=function(){var e=new o(null);return this.copy(e),e},o.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=c}catch(e){o.prototype.inspect=c}else o.prototype.inspect=c;function c(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],p=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function f(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var o=0|e.words[0],s=0|t.words[0],i=o*s,a=67108863&i,u=i/67108864|0;r.words[0]=a;for(var l=1;l<n;l++){for(var h=u>>>26,c=67108863&u,d=Math.min(l,t.length-1),p=Math.max(0,l-e.length+1);p<=d;p++){var m=l-p|0;h+=(i=(o=0|e.words[m])*(s=0|t.words[p])+c)/67108864|0,c=67108863&i}r.words[l]=0|c,u=0|h}return 0!==u?r.words[l]=0|u:r.length--,r._strip()}o.prototype.toString=function(e,t){var n;if(t=0|t||1,16===(e=e||10)||"hex"===e){n="";for(var o=0,s=0,i=0;i<this.length;i++){var a=this.words[i],u=(16777215&(a<<o|s)).toString(16);s=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,i--),n=0!==s||i!==this.length-1?d[6-u.length]+u+n:u+n}for(0!==s&&(n=s.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var l=p[e],h=m[e];n="";var c=this.clone();for(c.negative=0;!c.isZero();){var f=c.modrn(h).toString(e);n=(c=c.idivn(h)).isZero()?f+n:d[l-f.length]+f+n}for(this.isZero()&&(n="0"+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&r(0,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(e,t){return this.toArrayLike(s,e,t)}),o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,n){this._strip();var o=this.byteLength(),s=n||Math.max(1,o);r(o<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var i=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)}(e,s);return this["_toArrayLike"+("le"===t?"LE":"BE")](i,o),i},o.prototype._toArrayLikeLE=function(e){for(var t=0,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;e[t++]=255&s,t<e.length&&(e[t++]=s>>8&255),t<e.length&&(e[t++]=s>>16&255),6===o?(t<e.length&&(e[t++]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(t<e.length)for(e[t++]=r;t<e.length;)e[t++]=0},o.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;e[t--]=255&s,t>=0&&(e[t--]=s>>8&255),t>=0&&(e[t--]=s>>16&255),6===o?(t>=0&&(e[t--]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(t>=0)for(e[t--]=r;t>=0;)e[t--]=0},Math.clz32?o.prototype._countBits=function(e){return 32-Math.clz32(e)}:o.prototype._countBits=function(e){var t=e,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var r=this._zeroBits(this.words[t]);if(e+=r,26!==r)break}return e},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},o.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},o.prototype.ior=function(e){return r(0==(this.negative|e.negative)),this.iuor(e)},o.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this._strip()},o.prototype.iand=function(e){return r(0==(this.negative|e.negative)),this.iuand(e)},o.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;n<r.length;n++)this.words[n]=t.words[n]^r.words[n];if(this!==t)for(;n<t.length;n++)this.words[n]=t.words[n];return this.length=t.length,this._strip()},o.prototype.ixor=function(e){return r(0==(this.negative|e.negative)),this.iuxor(e)},o.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){r("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),n=e%26;this._expand(t),n>0&&t--;for(var o=0;o<t;o++)this.words[o]=67108863&~this.words[o];return n>0&&(this.words[o]=~this.words[o]&67108863>>26-n),this._strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){r("number"==typeof e&&e>=0);var n=e/26|0,o=e%26;return this._expand(n+1),this.words[n]=t?this.words[n]|1<<o:this.words[n]&~(1<<o),this._strip()},o.prototype.iadd=function(e){var t,r,n;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(r=this,n=e):(r=e,n=this);for(var o=0,s=0;s<n.length;s++)t=(0|r.words[s])+(0|n.words[s])+o,this.words[s]=67108863&t,o=t>>>26;for(;0!==o&&s<r.length;s++)t=(0|r.words[s])+o,this.words[s]=67108863&t,o=t>>>26;if(this.length=r.length,0!==o)this.words[this.length]=o,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},o.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r,n,o=this.cmp(e);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(r=this,n=e):(r=e,n=this);for(var s=0,i=0;i<n.length;i++)s=(t=(0|r.words[i])-(0|n.words[i])+s)>>26,this.words[i]=67108863&t;for(;0!==s&&i<r.length;i++)s=(t=(0|r.words[i])+s)>>26,this.words[i]=67108863&t;if(0===s&&i<r.length&&r!==this)for(;i<r.length;i++)this.words[i]=r.words[i];return this.length=Math.max(this.length,i),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var g=function(e,t,r){var n,o,s,i=e.words,a=t.words,u=r.words,l=0,h=0|i[0],c=8191&h,d=h>>>13,p=0|i[1],m=8191&p,f=p>>>13,g=0|i[2],w=8191&g,y=g>>>13,v=0|i[3],M=8191&v,E=v>>>13,b=0|i[4],x=8191&b,A=b>>>13,I=0|i[5],T=8191&I,_=I>>>13,k=0|i[6],S=8191&k,C=k>>>13,P=0|i[7],N=8191&P,O=P>>>13,R=0|i[8],L=8191&R,B=R>>>13,U=0|i[9],D=8191&U,F=U>>>13,H=0|a[0],V=8191&H,K=H>>>13,q=0|a[1],Q=8191&q,j=q>>>13,W=0|a[2],$=8191&W,z=W>>>13,Z=0|a[3],J=8191&Z,X=Z>>>13,G=0|a[4],Y=8191&G,ee=G>>>13,te=0|a[5],re=8191&te,ne=te>>>13,oe=0|a[6],se=8191&oe,ie=oe>>>13,ae=0|a[7],ue=8191&ae,le=ae>>>13,he=0|a[8],ce=8191&he,de=he>>>13,pe=0|a[9],me=8191&pe,fe=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(l+(n=Math.imul(c,V))|0)+((8191&(o=(o=Math.imul(c,K))+Math.imul(d,V)|0))<<13)|0;l=((s=Math.imul(d,K))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(m,V),o=(o=Math.imul(m,K))+Math.imul(f,V)|0,s=Math.imul(f,K);var we=(l+(n=n+Math.imul(c,Q)|0)|0)+((8191&(o=(o=o+Math.imul(c,j)|0)+Math.imul(d,Q)|0))<<13)|0;l=((s=s+Math.imul(d,j)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(w,V),o=(o=Math.imul(w,K))+Math.imul(y,V)|0,s=Math.imul(y,K),n=n+Math.imul(m,Q)|0,o=(o=o+Math.imul(m,j)|0)+Math.imul(f,Q)|0,s=s+Math.imul(f,j)|0;var ye=(l+(n=n+Math.imul(c,$)|0)|0)+((8191&(o=(o=o+Math.imul(c,z)|0)+Math.imul(d,$)|0))<<13)|0;l=((s=s+Math.imul(d,z)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(M,V),o=(o=Math.imul(M,K))+Math.imul(E,V)|0,s=Math.imul(E,K),n=n+Math.imul(w,Q)|0,o=(o=o+Math.imul(w,j)|0)+Math.imul(y,Q)|0,s=s+Math.imul(y,j)|0,n=n+Math.imul(m,$)|0,o=(o=o+Math.imul(m,z)|0)+Math.imul(f,$)|0,s=s+Math.imul(f,z)|0;var ve=(l+(n=n+Math.imul(c,J)|0)|0)+((8191&(o=(o=o+Math.imul(c,X)|0)+Math.imul(d,J)|0))<<13)|0;l=((s=s+Math.imul(d,X)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(x,V),o=(o=Math.imul(x,K))+Math.imul(A,V)|0,s=Math.imul(A,K),n=n+Math.imul(M,Q)|0,o=(o=o+Math.imul(M,j)|0)+Math.imul(E,Q)|0,s=s+Math.imul(E,j)|0,n=n+Math.imul(w,$)|0,o=(o=o+Math.imul(w,z)|0)+Math.imul(y,$)|0,s=s+Math.imul(y,z)|0,n=n+Math.imul(m,J)|0,o=(o=o+Math.imul(m,X)|0)+Math.imul(f,J)|0,s=s+Math.imul(f,X)|0;var Me=(l+(n=n+Math.imul(c,Y)|0)|0)+((8191&(o=(o=o+Math.imul(c,ee)|0)+Math.imul(d,Y)|0))<<13)|0;l=((s=s+Math.imul(d,ee)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(T,V),o=(o=Math.imul(T,K))+Math.imul(_,V)|0,s=Math.imul(_,K),n=n+Math.imul(x,Q)|0,o=(o=o+Math.imul(x,j)|0)+Math.imul(A,Q)|0,s=s+Math.imul(A,j)|0,n=n+Math.imul(M,$)|0,o=(o=o+Math.imul(M,z)|0)+Math.imul(E,$)|0,s=s+Math.imul(E,z)|0,n=n+Math.imul(w,J)|0,o=(o=o+Math.imul(w,X)|0)+Math.imul(y,J)|0,s=s+Math.imul(y,X)|0,n=n+Math.imul(m,Y)|0,o=(o=o+Math.imul(m,ee)|0)+Math.imul(f,Y)|0,s=s+Math.imul(f,ee)|0;var Ee=(l+(n=n+Math.imul(c,re)|0)|0)+((8191&(o=(o=o+Math.imul(c,ne)|0)+Math.imul(d,re)|0))<<13)|0;l=((s=s+Math.imul(d,ne)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(S,V),o=(o=Math.imul(S,K))+Math.imul(C,V)|0,s=Math.imul(C,K),n=n+Math.imul(T,Q)|0,o=(o=o+Math.imul(T,j)|0)+Math.imul(_,Q)|0,s=s+Math.imul(_,j)|0,n=n+Math.imul(x,$)|0,o=(o=o+Math.imul(x,z)|0)+Math.imul(A,$)|0,s=s+Math.imul(A,z)|0,n=n+Math.imul(M,J)|0,o=(o=o+Math.imul(M,X)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,X)|0,n=n+Math.imul(w,Y)|0,o=(o=o+Math.imul(w,ee)|0)+Math.imul(y,Y)|0,s=s+Math.imul(y,ee)|0,n=n+Math.imul(m,re)|0,o=(o=o+Math.imul(m,ne)|0)+Math.imul(f,re)|0,s=s+Math.imul(f,ne)|0;var be=(l+(n=n+Math.imul(c,se)|0)|0)+((8191&(o=(o=o+Math.imul(c,ie)|0)+Math.imul(d,se)|0))<<13)|0;l=((s=s+Math.imul(d,ie)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(N,V),o=(o=Math.imul(N,K))+Math.imul(O,V)|0,s=Math.imul(O,K),n=n+Math.imul(S,Q)|0,o=(o=o+Math.imul(S,j)|0)+Math.imul(C,Q)|0,s=s+Math.imul(C,j)|0,n=n+Math.imul(T,$)|0,o=(o=o+Math.imul(T,z)|0)+Math.imul(_,$)|0,s=s+Math.imul(_,z)|0,n=n+Math.imul(x,J)|0,o=(o=o+Math.imul(x,X)|0)+Math.imul(A,J)|0,s=s+Math.imul(A,X)|0,n=n+Math.imul(M,Y)|0,o=(o=o+Math.imul(M,ee)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,ee)|0,n=n+Math.imul(w,re)|0,o=(o=o+Math.imul(w,ne)|0)+Math.imul(y,re)|0,s=s+Math.imul(y,ne)|0,n=n+Math.imul(m,se)|0,o=(o=o+Math.imul(m,ie)|0)+Math.imul(f,se)|0,s=s+Math.imul(f,ie)|0;var xe=(l+(n=n+Math.imul(c,ue)|0)|0)+((8191&(o=(o=o+Math.imul(c,le)|0)+Math.imul(d,ue)|0))<<13)|0;l=((s=s+Math.imul(d,le)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(L,V),o=(o=Math.imul(L,K))+Math.imul(B,V)|0,s=Math.imul(B,K),n=n+Math.imul(N,Q)|0,o=(o=o+Math.imul(N,j)|0)+Math.imul(O,Q)|0,s=s+Math.imul(O,j)|0,n=n+Math.imul(S,$)|0,o=(o=o+Math.imul(S,z)|0)+Math.imul(C,$)|0,s=s+Math.imul(C,z)|0,n=n+Math.imul(T,J)|0,o=(o=o+Math.imul(T,X)|0)+Math.imul(_,J)|0,s=s+Math.imul(_,X)|0,n=n+Math.imul(x,Y)|0,o=(o=o+Math.imul(x,ee)|0)+Math.imul(A,Y)|0,s=s+Math.imul(A,ee)|0,n=n+Math.imul(M,re)|0,o=(o=o+Math.imul(M,ne)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,ne)|0,n=n+Math.imul(w,se)|0,o=(o=o+Math.imul(w,ie)|0)+Math.imul(y,se)|0,s=s+Math.imul(y,ie)|0,n=n+Math.imul(m,ue)|0,o=(o=o+Math.imul(m,le)|0)+Math.imul(f,ue)|0,s=s+Math.imul(f,le)|0;var Ae=(l+(n=n+Math.imul(c,ce)|0)|0)+((8191&(o=(o=o+Math.imul(c,de)|0)+Math.imul(d,ce)|0))<<13)|0;l=((s=s+Math.imul(d,de)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(D,V),o=(o=Math.imul(D,K))+Math.imul(F,V)|0,s=Math.imul(F,K),n=n+Math.imul(L,Q)|0,o=(o=o+Math.imul(L,j)|0)+Math.imul(B,Q)|0,s=s+Math.imul(B,j)|0,n=n+Math.imul(N,$)|0,o=(o=o+Math.imul(N,z)|0)+Math.imul(O,$)|0,s=s+Math.imul(O,z)|0,n=n+Math.imul(S,J)|0,o=(o=o+Math.imul(S,X)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,X)|0,n=n+Math.imul(T,Y)|0,o=(o=o+Math.imul(T,ee)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,ee)|0,n=n+Math.imul(x,re)|0,o=(o=o+Math.imul(x,ne)|0)+Math.imul(A,re)|0,s=s+Math.imul(A,ne)|0,n=n+Math.imul(M,se)|0,o=(o=o+Math.imul(M,ie)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ie)|0,n=n+Math.imul(w,ue)|0,o=(o=o+Math.imul(w,le)|0)+Math.imul(y,ue)|0,s=s+Math.imul(y,le)|0,n=n+Math.imul(m,ce)|0,o=(o=o+Math.imul(m,de)|0)+Math.imul(f,ce)|0,s=s+Math.imul(f,de)|0;var Ie=(l+(n=n+Math.imul(c,me)|0)|0)+((8191&(o=(o=o+Math.imul(c,fe)|0)+Math.imul(d,me)|0))<<13)|0;l=((s=s+Math.imul(d,fe)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(D,Q),o=(o=Math.imul(D,j))+Math.imul(F,Q)|0,s=Math.imul(F,j),n=n+Math.imul(L,$)|0,o=(o=o+Math.imul(L,z)|0)+Math.imul(B,$)|0,s=s+Math.imul(B,z)|0,n=n+Math.imul(N,J)|0,o=(o=o+Math.imul(N,X)|0)+Math.imul(O,J)|0,s=s+Math.imul(O,X)|0,n=n+Math.imul(S,Y)|0,o=(o=o+Math.imul(S,ee)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,ee)|0,n=n+Math.imul(T,re)|0,o=(o=o+Math.imul(T,ne)|0)+Math.imul(_,re)|0,s=s+Math.imul(_,ne)|0,n=n+Math.imul(x,se)|0,o=(o=o+Math.imul(x,ie)|0)+Math.imul(A,se)|0,s=s+Math.imul(A,ie)|0,n=n+Math.imul(M,ue)|0,o=(o=o+Math.imul(M,le)|0)+Math.imul(E,ue)|0,s=s+Math.imul(E,le)|0,n=n+Math.imul(w,ce)|0,o=(o=o+Math.imul(w,de)|0)+Math.imul(y,ce)|0,s=s+Math.imul(y,de)|0;var Te=(l+(n=n+Math.imul(m,me)|0)|0)+((8191&(o=(o=o+Math.imul(m,fe)|0)+Math.imul(f,me)|0))<<13)|0;l=((s=s+Math.imul(f,fe)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(D,$),o=(o=Math.imul(D,z))+Math.imul(F,$)|0,s=Math.imul(F,z),n=n+Math.imul(L,J)|0,o=(o=o+Math.imul(L,X)|0)+Math.imul(B,J)|0,s=s+Math.imul(B,X)|0,n=n+Math.imul(N,Y)|0,o=(o=o+Math.imul(N,ee)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,ee)|0,n=n+Math.imul(S,re)|0,o=(o=o+Math.imul(S,ne)|0)+Math.imul(C,re)|0,s=s+Math.imul(C,ne)|0,n=n+Math.imul(T,se)|0,o=(o=o+Math.imul(T,ie)|0)+Math.imul(_,se)|0,s=s+Math.imul(_,ie)|0,n=n+Math.imul(x,ue)|0,o=(o=o+Math.imul(x,le)|0)+Math.imul(A,ue)|0,s=s+Math.imul(A,le)|0,n=n+Math.imul(M,ce)|0,o=(o=o+Math.imul(M,de)|0)+Math.imul(E,ce)|0,s=s+Math.imul(E,de)|0;var _e=(l+(n=n+Math.imul(w,me)|0)|0)+((8191&(o=(o=o+Math.imul(w,fe)|0)+Math.imul(y,me)|0))<<13)|0;l=((s=s+Math.imul(y,fe)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,X))+Math.imul(F,J)|0,s=Math.imul(F,X),n=n+Math.imul(L,Y)|0,o=(o=o+Math.imul(L,ee)|0)+Math.imul(B,Y)|0,s=s+Math.imul(B,ee)|0,n=n+Math.imul(N,re)|0,o=(o=o+Math.imul(N,ne)|0)+Math.imul(O,re)|0,s=s+Math.imul(O,ne)|0,n=n+Math.imul(S,se)|0,o=(o=o+Math.imul(S,ie)|0)+Math.imul(C,se)|0,s=s+Math.imul(C,ie)|0,n=n+Math.imul(T,ue)|0,o=(o=o+Math.imul(T,le)|0)+Math.imul(_,ue)|0,s=s+Math.imul(_,le)|0,n=n+Math.imul(x,ce)|0,o=(o=o+Math.imul(x,de)|0)+Math.imul(A,ce)|0,s=s+Math.imul(A,de)|0;var ke=(l+(n=n+Math.imul(M,me)|0)|0)+((8191&(o=(o=o+Math.imul(M,fe)|0)+Math.imul(E,me)|0))<<13)|0;l=((s=s+Math.imul(E,fe)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(D,Y),o=(o=Math.imul(D,ee))+Math.imul(F,Y)|0,s=Math.imul(F,ee),n=n+Math.imul(L,re)|0,o=(o=o+Math.imul(L,ne)|0)+Math.imul(B,re)|0,s=s+Math.imul(B,ne)|0,n=n+Math.imul(N,se)|0,o=(o=o+Math.imul(N,ie)|0)+Math.imul(O,se)|0,s=s+Math.imul(O,ie)|0,n=n+Math.imul(S,ue)|0,o=(o=o+Math.imul(S,le)|0)+Math.imul(C,ue)|0,s=s+Math.imul(C,le)|0,n=n+Math.imul(T,ce)|0,o=(o=o+Math.imul(T,de)|0)+Math.imul(_,ce)|0,s=s+Math.imul(_,de)|0;var Se=(l+(n=n+Math.imul(x,me)|0)|0)+((8191&(o=(o=o+Math.imul(x,fe)|0)+Math.imul(A,me)|0))<<13)|0;l=((s=s+Math.imul(A,fe)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(D,re),o=(o=Math.imul(D,ne))+Math.imul(F,re)|0,s=Math.imul(F,ne),n=n+Math.imul(L,se)|0,o=(o=o+Math.imul(L,ie)|0)+Math.imul(B,se)|0,s=s+Math.imul(B,ie)|0,n=n+Math.imul(N,ue)|0,o=(o=o+Math.imul(N,le)|0)+Math.imul(O,ue)|0,s=s+Math.imul(O,le)|0,n=n+Math.imul(S,ce)|0,o=(o=o+Math.imul(S,de)|0)+Math.imul(C,ce)|0,s=s+Math.imul(C,de)|0;var Ce=(l+(n=n+Math.imul(T,me)|0)|0)+((8191&(o=(o=o+Math.imul(T,fe)|0)+Math.imul(_,me)|0))<<13)|0;l=((s=s+Math.imul(_,fe)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(D,se),o=(o=Math.imul(D,ie))+Math.imul(F,se)|0,s=Math.imul(F,ie),n=n+Math.imul(L,ue)|0,o=(o=o+Math.imul(L,le)|0)+Math.imul(B,ue)|0,s=s+Math.imul(B,le)|0,n=n+Math.imul(N,ce)|0,o=(o=o+Math.imul(N,de)|0)+Math.imul(O,ce)|0,s=s+Math.imul(O,de)|0;var Pe=(l+(n=n+Math.imul(S,me)|0)|0)+((8191&(o=(o=o+Math.imul(S,fe)|0)+Math.imul(C,me)|0))<<13)|0;l=((s=s+Math.imul(C,fe)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(D,ue),o=(o=Math.imul(D,le))+Math.imul(F,ue)|0,s=Math.imul(F,le),n=n+Math.imul(L,ce)|0,o=(o=o+Math.imul(L,de)|0)+Math.imul(B,ce)|0,s=s+Math.imul(B,de)|0;var Ne=(l+(n=n+Math.imul(N,me)|0)|0)+((8191&(o=(o=o+Math.imul(N,fe)|0)+Math.imul(O,me)|0))<<13)|0;l=((s=s+Math.imul(O,fe)|0)+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,n=Math.imul(D,ce),o=(o=Math.imul(D,de))+Math.imul(F,ce)|0,s=Math.imul(F,de);var Oe=(l+(n=n+Math.imul(L,me)|0)|0)+((8191&(o=(o=o+Math.imul(L,fe)|0)+Math.imul(B,me)|0))<<13)|0;l=((s=s+Math.imul(B,fe)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863;var Re=(l+(n=Math.imul(D,me))|0)+((8191&(o=(o=Math.imul(D,fe))+Math.imul(F,me)|0))<<13)|0;return l=((s=Math.imul(F,fe))+(o>>>13)|0)+(Re>>>26)|0,Re&=67108863,u[0]=ge,u[1]=we,u[2]=ye,u[3]=ve,u[4]=Me,u[5]=Ee,u[6]=be,u[7]=xe,u[8]=Ae,u[9]=Ie,u[10]=Te,u[11]=_e,u[12]=ke,u[13]=Se,u[14]=Ce,u[15]=Pe,u[16]=Ne,u[17]=Oe,u[18]=Re,0!==l&&(u[19]=l,r.length++),r};function w(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,o=0,s=0;s<r.length-1;s++){var i=o;o=0;for(var a=67108863&n,u=Math.min(s,t.length-1),l=Math.max(0,s-e.length+1);l<=u;l++){var h=s-l,c=(0|e.words[h])*(0|t.words[l]),d=67108863&c;a=67108863&(d=d+a|0),o+=(i=(i=i+(c/67108864|0)|0)+(d>>>26)|0)>>>26,i&=67108863}r.words[s]=a,n=i,i=o}return 0!==n?r.words[s]=n:r.length--,r._strip()}function y(e,t,r){return w(e,t,r)}Math.imul||(g=f),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?g(this,e,t):r<63?f(this,e,t):r<1024?w(this,e,t):y(this,e,t)},o.prototype.mul=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),y(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){var t=e<0;t&&(e=-e),r("number"==typeof e),r(e<67108864);for(var n=0,o=0;o<this.length;o++){var s=(0|this.words[o])*e,i=(67108863&s)+(67108863&n);n>>=26,n+=s/67108864|0,n+=i>>>26,this.words[o]=67108863&i}return 0!==n&&(this.words[o]=n,this.length++),t?this.ineg():this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=e.words[n]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n<t.length&&0===t[n];n++,r=r.sqr());if(++n<t.length)for(var s=r.sqr();n<t.length;n++,s=s.sqr())0!==t[n]&&(r=r.mul(s));return r},o.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,n=e%26,o=(e-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var i=0;for(t=0;t<this.length;t++){var a=this.words[t]&s,u=(0|this.words[t])-a<<n;this.words[t]=u|i,i=a>>>26-n}i&&(this.words[t]=i,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(e){return r(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,n){var o;r("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var s=e%26,i=Math.min((e-s)/26,this.length),a=67108863^67108863>>>s<<s,u=n;if(o-=i,o=Math.max(0,o),u){for(var l=0;l<i;l++)u.words[l]=this.words[l];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,l=0;l<this.length;l++)this.words[l]=this.words[l+i];else this.words[0]=0,this.length=1;var h=0;for(l=this.length-1;l>=0&&(0!==h||l>=o);l--){var c=0|this.words[l];this.words[l]=h<<26-s|c>>>s,h=c&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(e,t,n){return r(0===this.negative),this.iushrn(e,t,n)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26,o=1<<t;return this.length<=n?0:!!(this.words[n]&o)},o.prototype.imaskn=function(e){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==t&&n++,this.length=Math.min(n,this.length),0!==t){var o=67108863^67108863>>>t<<t;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(e){return this.clone().imaskn(e)},o.prototype.iaddn=function(e){return r("number"==typeof e),r(e<67108864),e<0?this.isubn(-e):0!==this.negative?1===this.length&&(0|this.words[0])<=e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},o.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},o.prototype.isubn=function(e){if(r("number"==typeof e),r(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,this.words[t+1]-=1;return this._strip()},o.prototype.addn=function(e){return this.clone().iaddn(e)},o.prototype.subn=function(e){return this.clone().isubn(e)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(e,t,n){var o,s,i=e.length+n;this._expand(i);var a=0;for(o=0;o<e.length;o++){s=(0|this.words[o+n])+a;var u=(0|e.words[o])*t;a=((s-=67108863&u)>>26)-(u/67108864|0),this.words[o+n]=67108863&s}for(;o<this.length-n;o++)a=(s=(0|this.words[o+n])+a)>>26,this.words[o+n]=67108863&s;if(0===a)return this._strip();for(r(-1===a),a=0,o=0;o<this.length;o++)a=(s=-(0|this.words[o])+a)>>26,this.words[o]=67108863&s;return this.negative=1,this._strip()},o.prototype._wordDiv=function(e,t){var r=(this.length,e.length),n=this.clone(),s=e,i=0|s.words[s.length-1];0!=(r=26-this._countBits(i))&&(s=s.ushln(r),n.iushln(r),i=0|s.words[s.length-1]);var a,u=n.length-s.length;if("mod"!==t){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var l=0;l<a.length;l++)a.words[l]=0}var h=n.clone()._ishlnsubmul(s,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var c=u-1;c>=0;c--){var d=67108864*(0|n.words[s.length+c])+(0|n.words[s.length+c-1]);for(d=Math.min(d/i|0,67108863),n._ishlnsubmul(s,d,c);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(s,1,c),n.isZero()||(n.negative^=1);a&&(a.words[c]=d)}return a&&a._strip(),n._strip(),"div"!==t&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(e,t,n){return r(!e.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(s=a.div.neg()),"div"!==t&&(i=a.mod.neg(),n&&0!==i.negative&&i.iadd(e)),{div:s,mod:i}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(i=a.mod.neg(),n&&0!==i.negative&&i.isub(e)),{div:a.div,mod:i}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modrn(e.words[0]))}:this._wordDiv(e,t);var s,i,a},o.prototype.div=function(e){return this.divmod(e,"div",0).div},o.prototype.mod=function(e){return this.divmod(e,"mod",0).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",1).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var r=0!==t.div.negative?t.mod.isub(e):t.mod,n=e.ushrn(1),o=e.andln(1),s=r.cmp(n);return s<0||1===o&&0===s?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modrn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var n=(1<<26)%e,o=0,s=this.length-1;s>=0;s--)o=(n*o+(0|this.words[s]))%e;return t?-o:o},o.prototype.modn=function(e){return this.modrn(e)},o.prototype.idivn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var n=0,o=this.length-1;o>=0;o--){var s=(0|this.words[o])+67108864*n;this.words[o]=s/e|0,n=s%e}return this._strip(),t?this.ineg():this},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var s=new o(1),i=new o(0),a=new o(0),u=new o(1),l=0;t.isEven()&&n.isEven();)t.iushrn(1),n.iushrn(1),++l;for(var h=n.clone(),c=t.clone();!t.isZero();){for(var d=0,p=1;0==(t.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(t.iushrn(d);d-- >0;)(s.isOdd()||i.isOdd())&&(s.iadd(h),i.isub(c)),s.iushrn(1),i.iushrn(1);for(var m=0,f=1;0==(n.words[0]&f)&&m<26;++m,f<<=1);if(m>0)for(n.iushrn(m);m-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(c)),a.iushrn(1),u.iushrn(1);t.cmp(n)>=0?(t.isub(n),s.isub(a),i.isub(u)):(n.isub(t),a.isub(s),u.isub(i))}return{a:a,b:u,gcd:n.iushln(l)}},o.prototype._invmp=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var s,i=new o(1),a=new o(0),u=n.clone();t.cmpn(1)>0&&n.cmpn(1)>0;){for(var l=0,h=1;0==(t.words[0]&h)&&l<26;++l,h<<=1);if(l>0)for(t.iushrn(l);l-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var c=0,d=1;0==(n.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(n.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(n)>=0?(t.isub(n),i.isub(a)):(n.isub(t),a.isub(i))}return(s=0===t.cmpn(1)?i:a).cmpn(0)<0&&s.iadd(e),s},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),r=e.clone();t.negative=0,r.negative=0;for(var n=0;t.isEven()&&r.isEven();n++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var o=t.cmp(r);if(o<0){var s=t;t=r,r=s}else if(0===o||0===r.cmpn(1))break;t.isub(r)}return r.iushln(n)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){r("number"==typeof e);var t=e%26,n=(e-t)/26,o=1<<t;if(this.length<=n)return this._expand(n+1),this.words[n]|=o,this;for(var s=o,i=n;0!==s&&i<this.length;i++){var a=0|this.words[i];s=(a+=s)>>>26,a&=67108863,this.words[i]=a}return 0!==s&&(this.words[i]=s,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(e){var t,n=e<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)t=1;else{n&&(e=-e),r(e<=67108863,"Number is too big");var o=0|this.words[0];t=o===e?0:o<e?-1:1}return 0!==this.negative?0|-t:t},o.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0!==this.negative?0|-t:t},o.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],o=0|e.words[r];if(n!==o){n<o?t=-1:n>o&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new I(e)},o.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var v={k256:null,p224:null,p192:null,p25519:null};function M(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function E(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function x(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function I(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function T(e){I.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}M.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},M.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},M.prototype.split=function(e,t){e.iushrn(this.n,0,t)},M.prototype.imulK=function(e){return e.imul(this.k)},n(E,M),E.prototype.split=function(e,t){for(var r=4194303,n=Math.min(e.length,9),o=0;o<n;o++)t.words[o]=e.words[o];if(t.length=n,e.length<=9)return e.words[0]=0,void(e.length=1);var s=e.words[9];for(t.words[t.length++]=s&r,o=10;o<e.length;o++){var i=0|e.words[o];e.words[o-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,e.words[o-10]=s,0===s&&e.length>10?e.length-=10:e.length-=9},E.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(b,M),n(x,M),n(A,M),A.prototype.imulK=function(e){for(var t=0,r=0;r<e.length;r++){var n=19*(0|e.words[r])+t,o=67108863&n;n>>>=26,e.words[r]=o,t=n}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(v[e])return v[e];var t;if("k256"===e)t=new E;else if("p224"===e)t=new b;else if("p192"===e)t=new x;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new A}return v[e]=t,t},I.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},I.prototype._verify2=function(e,t){r(0==(e.negative|t.negative),"red works only with positives"),r(e.red&&e.red===t.red,"red works only with red numbers")},I.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(h(e,e.umod(this.m)._forceRed(this)),e)},I.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},I.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},I.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},I.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},I.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},I.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},I.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},I.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},I.prototype.isqr=function(e){return this.imul(e,e.clone())},I.prototype.sqr=function(e){return this.mul(e,e)},I.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(r(t%2==1),3===t){var n=this.m.add(new o(1)).iushrn(2);return this.pow(e,n)}for(var s=this.m.subn(1),i=0;!s.isZero()&&0===s.andln(1);)i++,s.iushrn(1);r(!s.isZero());var a=new o(1).toRed(this),u=a.redNeg(),l=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,l).cmp(u);)h.redIAdd(u);for(var c=this.pow(h,s),d=this.pow(e,s.addn(1).iushrn(1)),p=this.pow(e,s),m=i;0!==p.cmp(a);){for(var f=p,g=0;0!==f.cmp(a);g++)f=f.redSqr();r(g<m);var w=this.pow(c,new o(1).iushln(m-g-1));d=d.redMul(w),c=w.redSqr(),p=p.redMul(c),m=g}return d},I.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},I.prototype.pow=function(e,t){if(t.isZero())return new o(1).toRed(this);if(0===t.cmpn(1))return e.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=e;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],e);var s=r[0],i=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),n=t.length-1;n>=0;n--){for(var l=t.words[n],h=u-1;h>=0;h--){var c=l>>h&1;s!==r[0]&&(s=this.sqr(s)),0!==c||0!==i?(i<<=1,i|=c,(4==++a||0===n&&0===h)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},I.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},I.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new T(e)},n(T,I),T.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},T.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},T.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},T.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,o);var a=i.exports,u=s(a);const l=new u("21888242871839275222246405745257275088548364400416034343698204186575808495617"),h=new u("452312848583266388373324160190187140051835877600158453279131187530910662655"),c="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",d="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",p="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",m=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),f=()=>e.PublicKey.findProgramAddressSync([t.Buffer.from("cpi_authority")],new e.PublicKey(d))[0],g=()=>({registeredProgramPda:new e.PublicKey(m()),noopProgram:new e.PublicKey(c),accountCompressionProgram:new e.PublicKey(p),accountCompressionAuthority:new e.PublicKey(f()),cpiSignatureAccount:null}),w=()=>({nullifierQueue:new e.PublicKey(y),merkleTree:new e.PublicKey(v),merkleTreeHeight:b,addressTree:new e.PublicKey(M),addressQueue:new e.PublicKey(E)}),y="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",v="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",M="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",E="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",b=26,x=new u(Math.floor(2**b*.95)),A=new u(300),I=new u(392),T=new u(5e3),_=new u(5e3);var k=function(e){const t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let r=0;r<58;r++){const n=e.charAt(r),o=n.charCodeAt(0);if(255!==t[o])throw new TypeError(n+" is ambiguous");t[o]=r}const r=e.charAt(0),n=Math.log(58)/Math.log(256),o=Math.log(256)/Math.log(58);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,i=0;for(;e[o]===r;)s++,o++;const a=(e.length-o)*n+1>>>0,u=new Uint8Array(a);for(;e[o];){let r=t[e.charCodeAt(o)];if(255===r)return;let n=0;for(let e=a-1;(0!==r||n<i)&&-1!==e;e--,n++)r+=58*u[e]>>>0,u[e]=r%256>>>0,r=r/256>>>0;if(0!==r)throw new Error("Non-zero carry");i=n,o++}let l=a-i;for(;l!==a&&0===u[l];)l++;const h=new Uint8Array(s+(a-l));let c=s;for(;l!==a;)h[c++]=u[l++];return h}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let n=0,s=0,i=0;const a=t.length;for(;i!==a&&0===t[i];)i++,n++;const u=(a-i)*o+1>>>0,l=new Uint8Array(u);for(;i!==a;){let e=t[i],r=0;for(let t=u-1;(0!==e||r<s)&&-1!==t;t--,r++)e+=256*l[t]>>>0,l[t]=e%58>>>0,e=e/58>>>0;if(0!==e)throw new Error("Non-zero carry");s=r,i++}let h=u-s;for(;h!==u&&0===l[h];)h++;let c=r.repeat(n);for(;h<u;++h)c+=e.charAt(l[h]);return c},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const S=(e,t,r)=>new u(e,t,r),C=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return C(k.decode(e))}return function(e){if(e.gte(l))throw new Error("Value is too large. Max <254 bits");return e}(new u(e,t))};function P(e){const r=C(e).toArrayLike(t.Buffer,void 0,32);return k.encode(r)}const N=(e,t,r,n)=>({owner:e,lamports:null!=t?t:S(0),address:null!=n?n:null,data:null!=r?r:null}),O=(e,t,r,n,o)=>Object.assign(Object.assign(Object.assign({},N(t,r,n,o)),e),{readOnly:0}),R=(e,t,r,n)=>({merkleTree:e,nullifierQueue:t,hash:r,leafIndex:n});function L(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function B(e,...t){if(!((r=e)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function U(e,t=1){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const D=BigInt(2**32-1),F=BigInt(32);function H(e,t=0){return t?{h:Number(e&D),l:Number(e>>F&D)}:{h:0|Number(e>>F&D),l:0|Number(e&D)}}function V(e,t=0){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:s,l:i}=H(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const K=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function q(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t}function Q(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),B(e),e}class j{clone(){return this._cloneInto()}}const W=[],$=[],z=[],Z=BigInt(0),J=BigInt(1),X=BigInt(2),G=BigInt(7),Y=BigInt(256),ee=BigInt(113);for(let e=0,t=J,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],W.push(2*(5*n+r)),$.push((e+1)*(e+2)/2%64);let o=Z;for(let e=0;e<7;e++)t=(t<<J^(t>>G)*ee)%Y,t&X&&(o^=J<<(J<<BigInt(e))-J);z.push(o)}const[te,re]=V(z,1),ne=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),oe=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class se extends j{constructor(e,t,r,n=0,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=o,this.pos=0,this.posOut=0,this.finished=0,this.destroyed=0,L(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){K||q(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,o=(t+2)%10,s=r[o],i=r[o+1],a=ne(s,i,1)^r[n],u=oe(s,i,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=u}let t=e[2],o=e[3];for(let r=0;r<24;r++){const n=$[r],s=ne(t,o,n),i=oe(t,o,n),a=W[r];t=e[a],o=e[a+1],e[a]=s,e[a+1]=i}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=te[n],e[1]^=re[n]}r.fill(0)}(this.state32,this.rounds),K||q(this.state32),this.posOut=0,this.pos=0}update(e){U(this);const{blockLen:t,state:r}=this,n=(e=Q(e)).length;for(let o=0;o<n;){const s=Math.min(t-this.pos,n-o);for(let t=0;t<s;t++)r[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=1;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,0!=(128&t)&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){U(this,0),B(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,o=e.length;n<o;){this.posOut>=r&&this.keccak();const s=Math.min(r-this.posOut,o-n);e.set(t.subarray(this.posOut,this.posOut+s),n),this.posOut+=s,n+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return L(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){B(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=1,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:o,enableXOF:s}=this;return e||(e=new se(t,r,n,s,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=n,e.enableXOF=s,e.destroyed=this.destroyed,e}}const ie=(()=>function(e){const t=t=>e().update(Q(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new se(136,1,32))))();function ae(e){return"0x"+e.toString("hex")}const ue=e=>Array.isArray(e)?e:[e];function le(e){return S(e,void 0,"be").lt(l)}function he(e){let r=255;for(;r>=0;){const n=t.Buffer.concat([e,t.Buffer.from([r])]),o=ie(n);if(32!==o.length)throw new Error("Invalid hash length");if(o[0]=0,le(t.Buffer.from(o)))return[t.Buffer.from(o),r];r-=1}return null}function ce(e){const t=ie.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function de(e){return Array.isArray(e)?e.map((e=>de(e))):null!==e&&e.constructor===Object?Object.keys(e).reduce(((t,r)=>(t[r.replace(/([-_][a-z])/gi,(e=>e.toUpperCase().replace("-","").replace("_","")))]=de(e[r]),t)),{}):e}function pe(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function me(e,t,r){if(t<=0)return[];if(void 0===e)return 0===r.length?new Array(t).fill(w().merkleTree):new Array(t).fill(r[0].merkleTree);{const r=ue(e);return r.length>=t?r.slice(0,t):r.concat(new Array(t-r.length).fill(r[0]))}}function fe(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function ge(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];e.forEach(((e,r)=>{const n=pe(s,e.merkleTree),o=pe(s,e.nullifierQueue);i.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleContext:{merkleTreePubkeyIndex:n,nullifierQueuePubkeyIndex:o,leafIndex:e.leafIndex,queueIndex:null},rootIndex:t[r],readOnly:0})}));const u=me(n,r.length,e);return r.forEach(((e,t)=>{const r=pe(s,u[t]);a.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:s}}const we=e=>{if(e.lt(S(0)))throw new Error("Not enough balance for transfer")},ye=e=>{if(0===e.length)throw new Error("No accounts provided for validation");const t=e[0].owner;if(!e.every((e=>e.owner.equals(t))))throw new Error("All input accounts must have the same owner")};function ve(e,t){return ce([t.toBytes(),...e])}function Me(t,r=w().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=he(Buffer.from([...n,...t]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new e.PublicKey(s)}function Ee(e,t){const r=t.slice(),n=e.map((e=>({seed:Array.from(e.seed),addressMerkleTreeRootIndex:e.addressMerkleTreeRootIndex,addressMerkleTreeAccountIndex:0,addressQueueAccountIndex:0})));return e.forEach(((e,t)=>{n[t].addressMerkleTreeAccountIndex=pe(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=pe(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function be(e,t,r="confirmed"){const n=await e.getLatestBlockhash(r),o={signature:t.toString(),lastValidBlockHeight:n.lastValidBlockHeight,blockhash:n.blockhash};return await e.confirmTransaction(o,r)}function xe(e){const t=Ie(e.ar[0]),r=Ie(e.ar[1]),n=new Uint8Array([...t,...r]),o=Ie(e.bs[0][0]),s=Ie(e.bs[0][1]),i=Ie(e.bs[1][0]),a=Ie(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),l=Ie(e.krs[0]),h=Ie(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...l,...h])}}function Ae(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=Te(new u(t.slice(32,64),32,"be"))?0:1;o[0]=_e(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),h=function(e,t){const r=l.div(new u(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(new u(a.slice(0,32),32,"be"),new u(a.slice(32,64),32,"be"));i[0]=_e(i[0],h);const c=n.slice(0,32),d=n.slice(32,64),p=Te(new u(d,32,"be"));return c[0]=_e(c[0],p),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function Ie(e){const t=new u(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function Te(e){return e.lte(l.sub(e))}function _e(e,t){return t?e:128|e}function ke(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function Se(e,t,r,n){const o=await e.sendTransaction(t,r);n||(n=await e.getLatestBlockhash());const s={signature:o,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},i=(await e.confirmTransaction(s,(null==r?void 0:r.commitment)||e.commitment||"confirmed")).context.slot;return await e.confirmTransactionIndexed(i),o}async function Ce(e,t,r,n){n||(n=await e.getLatestBlockhash());const o={signature:t,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},s=await e.confirmTransaction(o,(null==r?void 0:r.commitment)||e.commitment||"confirmed"),i=s.context.slot;return await e.confirmTransactionIndexed(i),s}function Pe(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=ke(e,t.publicKey,r,o);return i.sign(s),i}let Ne=1;const Oe=Ue(255),Re=Ue(254),Le=Ue(253),Be=Ue(252);function Ue(t){if(t||(t=Ne,Ne++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var De={};!function(t){var n=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:1}),t.map=t.array=t.rustEnum=t.str=t.vecU8=t.tagged=t.vec=t.bool=t.option=t.publicKey=t.i256=t.u256=t.i128=t.u128=t.i64=t.u64=t.struct=t.f64=t.f32=t.i32=t.u32=t.i16=t.u16=t.i8=t.u8=void 0;const s=r,i=e,u=n(a);var l=r;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return l.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return l.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return l.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return l.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return l.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return l.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return l.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return l.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return l.struct}});class h extends s.Layout{constructor(e,t,r){super(e,r),this.blob=(0,s.blob)(e),this.signed=t}decode(e,t=0){const r=new u.default(this.blob.decode(e,t),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(e,t,r=0){return this.signed&&(e=e.toTwos(8*this.span)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),t,r)}}function c(e){return new h(8,0,e)}t.u64=c,t.i64=function(e){return new h(8,1,e)},t.u128=function(e){return new h(16,0,e)},t.i128=function(e){return new h(16,1,e)},t.u256=function(e){return new h(32,0,e)},t.i256=function(e){return new h(32,1,e)};class d extends s.Layout{constructor(e,t,r,n){super(e.span,n),this.layout=e,this.decoder=t,this.encoder=r}decode(e,t){return this.decoder(this.layout.decode(e,t))}encode(e,t,r){return this.layout.encode(this.encoder(e),t,r)}getSpan(e,t){return this.layout.getSpan(e,t)}}t.publicKey=function(e){return new d((0,s.blob)(32),(e=>new i.PublicKey(e)),(e=>e.toBuffer()),e)};class p extends s.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,s.u8)()}encode(e,t,r=0){return null==e?this.discriminator.encode(0,t,r):(this.discriminator.encode(1,t,r),this.layout.encode(e,t,r+1)+1)}decode(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return null;if(1===r)return this.layout.decode(e,t+1);throw new Error("Invalid option "+this.property)}getSpan(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return 1;if(1===r)return this.layout.getSpan(e,t+1)+1;throw new Error("Invalid option "+this.property)}}function m(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function f(e){return e?1:0}function g(e){const t=(0,s.u32)("length"),r=(0,s.struct)([t,(0,s.blob)((0,s.offset)(t,-t.span),"data")]);return new d(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new p(e,t)},t.bool=function(e){return new d((0,s.u8)(),m,f,e)},t.vec=function(e,t){const r=(0,s.u32)("length"),n=(0,s.struct)([r,(0,s.seq)(e,(0,s.offset)(r,-r.span),"values")]);return new d(n,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const n=(0,s.struct)([c("tag"),t.replicate("data")]);return new d(n,(function({tag:t,data:r}){if(!t.eq(e))throw new Error("Invalid tag, expected: "+e.toString("hex")+", got: "+t.toString("hex"));return r}),(t=>({tag:e,data:t})),r)},t.vecU8=g,t.str=function(e){return new d(g(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const n=(0,s.union)(null!=r?r:(0,s.u8)(),t);return e.forEach(((e,t)=>n.addVariant(t,e,e.property))),n},t.array=function(e,t,r){const n=(0,s.struct)([(0,s.seq)(e,t,"values")]);return new d(n,(({values:e})=>e),(e=>({values:e})),r)};class w extends s.Layout{constructor(e,t,r){super(e.span+t.span,r),this.keyLayout=e,this.valueLayout=t}decode(e,t){return t=t||0,[this.keyLayout.decode(e,t),this.valueLayout.decode(e,t+this.keyLayout.getSpan(e,t))]}encode(e,t,r){r=r||0;const n=this.keyLayout.encode(e[0],t,r);return n+this.valueLayout.encode(e[1],t,r+n)}getSpan(e,t){return this.keyLayout.getSpan(e,t)+this.valueLayout.getSpan(e,t)}}t.map=function(e,t,r){const n=(0,s.u32)("length"),o=(0,s.struct)([n,(0,s.seq)(new w(e,t),(0,s.offset)(n,-n.span),"values")]);return new d(o,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(De);const Fe=De.struct([De.publicKey("owner"),De.u64("lamports"),De.option(De.array(De.u8(),32),"address"),De.option(De.struct([De.array(De.u8(),8,"discriminator"),De.vecU8("data"),De.array(De.u8(),32,"dataHash")]),"data")],"compressedAccount"),He=De.struct([De.u8("merkleTreePubkeyIndex"),De.u8("nullifierQueuePubkeyIndex"),De.u32("leafIndex"),De.option(De.struct([De.u8("queueId"),De.u16("index")]),"queueIndex")],"merkleContext"),Ve=De.struct([De.array(De.u8(),32,"seed"),De.u8("addressQueueAccountIndex"),De.u8("addressMerkleTreeAccountIndex"),De.u16("addressMerkleTreeRootIndex")],"newAddressParams"),Ke=De.struct([De.option(De.struct([De.array(De.u8(),32,"a"),De.array(De.u8(),64,"b"),De.array(De.u8(),32,"c")]),"proof"),De.vec(De.struct([Fe,He,De.u16("rootIndex"),De.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),De.vec(De.struct([Fe,De.u8("merkleTreeIndex")]),"outputCompressedAccounts"),De.option(De.u64(),"relayFee"),De.vec(Ve,"newAddressParams"),De.option(De.u64(),"compressOrDecompressLamports"),De.bool("isCompress")]);function qe(e){const r=t.Buffer.alloc(1e3),n=Ke.encode(e,r),o=t.Buffer.from(r.slice(0,n)),s=t.Buffer.alloc(4);return s.writeUInt32LE(n,0),t.Buffer.concat([t.Buffer.from([26,16,169,7,21,202,242,25]),s,o])}const Qe=e=>{const t=Ze.programId,{feePayer:r,authority:n,registeredProgramPda:o,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:l,systemProgram:h}=e;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:null!=u?u:t,isSigner:0,isWritable:null!==u},{pubkey:null!=l?l:t,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0}]},je=De.struct([De.vec(De.array(De.u8(),32),"inputCompressedAccountHashes"),De.vec(De.array(De.u8(),32),"outputCompressedAccountHashes"),De.vec(De.struct([De.struct([De.publicKey("owner"),De.u64("lamports"),De.option(De.array(De.u8(),32),"address"),De.option(De.struct([De.array(De.u8(),8,"discriminator"),De.vecU8("data"),De.array(De.u8(),32,"dataHash")]),"data")],"compressedAccount"),De.u8("merkleTreeIndex")]),"outputCompressedAccounts"),De.vec(De.u32(),"outputLeafIndices"),De.vec(De.struct([De.publicKey("pubkey"),De.u64("seq")]),"sequenceNumbers"),De.option(De.u64(),"relayFee"),De.bool("isCompress"),De.option(De.u64(),"compressOrDecompressLamports"),De.vec(De.publicKey(),"pubkeyArray"),De.option(De.vecU8(),"message")]);function We(e){return je.decode(e)}const $e=e=>e.reduce(((e,t)=>e.add(S(t.lamports))),S(0)),ze=t.Buffer.from("sol_pool_pda");class Ze{constructor(){}static deriveCompressedSolPda(){const t=[ze],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=S(r);const n=$e(e).sub(r);return we(n),n.eq(S(0))?[N(t,r)]:(ye(e),[N(e[0].owner,n),N(t,r)])}static createDecompressOutputState(e,t){t=S(t);const r=$e(e).sub(t);return we(r),r.eq(S(0))?[]:(ye(e),[N(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=S(null!=r?r:0);const o=$e(null!=n?n:[]).sub(r);return we(o),o.eq(S(0))||!n?[N(t,r,void 0,e)]:(ye(n),[N(n[0].owner,o),N(t,r,void 0,e)])}static async createAccount({payer:t,newAddressParams:r,newAddress:n,recentValidityProof:o,outputStateTree:s,inputCompressedAccounts:i,inputStateRootIndices:a,lamports:u}){const l=this.createNewAddressOutputState(n,t,u,i),{packedInputCompressedAccounts:h,packedOutputCompressedAccounts:c,remainingAccounts:d}=ge(null!=i?i:[],null!=a?a:[],l,s),{newAddressParamsPacked:p,remainingAccounts:m}=Ee([r],d),f=qe({proof:o,inputCompressedAccountsWithMerkleContext:h,outputCompressedAccounts:c,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),w=[...Qe(Object.assign(Object.assign({},g()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...fe(m)];return new e.TransactionInstruction({programId:this.programId,keys:w,data:f})}static async transfer({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i,outputStateTrees:a}){const u=this.createTransferOutputState(r,n,o),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:h,remainingAccounts:c}=ge(r,s,u,a),d=qe({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:h,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),p=[...Qe(Object.assign(Object.assign({},g()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...fe(c)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTree:o}){n=S(n);const s=N(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=ge([],[],[s],o),l=qe({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),h=[...Qe(Object.assign(Object.assign({},g()),{feePayer:t,authority:t,solPoolPda:this.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...fe(u)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:l})}static async decompress({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i,outputStateTree:a}){o=S(o);const u=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:h,remainingAccounts:c}=ge(r,s,u,a),d=qe({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:h,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),p=[...Qe(Object.assign(Object.assign({},g()),{feePayer:t,authority:t,solPoolPda:this.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),...fe(c)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}}function Je(e,t){let r=S(0);t=S(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(S(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(S(t)))throw new Error(`Not enough balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}var Xe,Ge,Ye,et,tt,rt,nt,ot;Ze.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"),exports.UtxoErrorCode=void 0,(Xe=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",Xe.NOT_U64="NOT_U64",Xe.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(Ge=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",Ge.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(Ye=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",Ye.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",Ye.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(et=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",et.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",et.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",et.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(tt=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",tt.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED",exports.HashErrorCode=void 0,(exports.HashErrorCode||(exports.HashErrorCode={})).NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED",exports.ProofErrorCode=void 0,(rt=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",rt.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",rt.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(nt=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",nt.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",nt.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",nt.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",nt.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",nt.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(ot=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",ot.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",ot.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",ot.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",ot.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",ot.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",ot.INVALID_NUMBER="INVALID_NUMBER";class st extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}const it=n.coerce(n.instance(e.PublicKey),n.string(),(t=>new e.PublicKey(t))),at=n.coerce(n.instance(Array),n.string(),(t=>Array.from(new e.PublicKey(t).toBytes()))),ut=n.coerce(n.instance(u),n.string(),(e=>C(e,"base58"))),lt=n.coerce(n.instance(u),n.number(),(e=>Number.isSafeInteger(e)?S(e):S(e.toString(),10))),ht=n.coerce(n.string(),n.string(),(e=>""===e?null:e));function ct(e){return n.union([n.type({jsonrpc:n.literal("2.0"),id:n.string(),result:e}),n.type({jsonrpc:n.literal("2.0"),id:n.string(),error:n.type({code:n.unknown(),message:n.string(),data:n.nullable(n.any())})})])}const dt=ct(n.unknown());function pt(e){return n.coerce(ct(e),dt,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:n.create(t.result,e)})))}function mt(e){return pt(n.type({context:n.type({slot:n.number()}),value:e}))}const ft=n.type({address:n.nullable(at),hash:ut,data:n.nullable(n.type({data:ht,dataHash:ut,discriminator:lt})),lamports:lt,owner:it,leafIndex:n.number(),tree:it,seq:n.nullable(lt),slotCreated:lt}),gt=n.type({mint:it,owner:it,amount:lt,delegate:n.nullable(it),state:n.string()}),wt=n.type({tokenData:gt,account:ft}),yt=n.type({items:n.array(ft)}),vt=n.type({items:n.array(ft),cursor:n.nullable(n.string())}),Mt=n.type({items:n.array(wt),cursor:n.nullable(n.string())}),Et=n.number(),bt=n.string(),xt=n.type({items:n.array(n.type({signature:n.string(),slot:n.number(),blockTime:n.number(),error:n.nullable(n.string())}))}),At=n.type({items:n.array(n.type({signature:n.string(),slot:n.number(),blockTime:n.number()})),cursor:n.nullable(n.string())}),It=n.type({hash:ut,leafIndex:n.number(),merkleTree:it,proof:n.array(ut),rootSeq:n.number(),root:ut}),Tt=n.type({address:ut,nextIndex:n.number(),merkleTree:it,proof:n.array(ut),rootSeq:n.number(),root:ut,lowerRangeAddress:ut,higherRangeAddress:ut,lowElementLeafIndex:n.number()}),_t=n.type({a:n.array(n.number()),b:n.array(n.number()),c:n.array(n.number())}),kt=n.type({compressedProof:_t,leafIndices:n.array(n.number()),leaves:n.array(ut),rootIndices:n.array(n.number()),roots:n.array(ut),merkleTrees:n.array(it)}),St=n.array(It),Ct=n.type({amount:lt}),Pt=lt,Nt=n.type({balance:lt,mint:it}),Ot=n.type({tokenBalances:n.array(Nt),cursor:n.nullable(n.string())}),Rt=n.type({items:n.array(Nt),cursor:n.nullable(n.string())}),Lt=n.type({cursor:n.nullable(n.string()),items:n.array(n.type({balance:lt,owner:it}))}),Bt=n.type({hash:n.array(n.number()),root:n.array(n.number()),proof:n.array(n.array(n.number()))}),Ut=n.type({items:n.array(n.type({blockTime:n.number(),signature:n.string(),slot:n.number()}))}),Dt=n.type({items:n.array(n.type({blockTime:n.number(),signature:n.string(),slot:n.number()})),cursor:n.nullable(n.string())}),Ft=n.type({compressionInfo:n.type({closedAccounts:n.array(n.type({account:ft,optionalTokenData:n.nullable(gt)})),openedAccounts:n.array(n.type({account:ft,optionalTokenData:n.nullable(gt)}))}),transaction:n.any()});function Ht({discriminator:e,data:r,dataHash:n}){return{discriminator:e.toArray("le",8),data:t.Buffer.from(r,"base64"),dataHash:n.toArray("le",32)}}async function Vt(t,r,o,s=0){var i,a;const u=s?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner",l=s?"delegate":"owner",h=await qt(t.compressionApiEndpoint,u,{[l]:r.toBase58(),mint:null===(i=o.mint)||void 0===i?void 0:i.toBase58(),limit:null===(a=o.limit)||void 0===a?void 0:a.toNumber(),cursor:o.cursor}),c=n.create(h,mt(Mt));if("error"in c)throw new e.SolanaJSONRPCError(c.error,`failed to get info for compressed accounts by ${l} ${r.toBase58()}`);if(null===c.result.value)throw new Error("not implemented: NULL result");const d=[];return c.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=O(R(n.tree,zt,n.hash.toArray("be",32),n.leafIndex),n.owner,S(n.lamports),n.data?Ht(n.data):void 0,n.address||void 0),i={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=i[l])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${l} different from requested ${l}`);d.push({compressedAccount:s,parsed:i})})),{items:d.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:c.result.value.cursor}}function Kt(e){const t=e.account,r=e.optionalTokenData,n=O(R(t.merkleTree,zt,t.hash.toArray("be",32),t.leafIndex),t.owner,S(t.lamports),t.data?Ht(t.data):void 0,t.address||void 0);return null===r?{account:n,maybeTokenData:null}:{account:n,maybeTokenData:{mint:r.mint,owner:r.owner,amount:r.amount,delegate:r.delegate,state:["uninitialized","initialized","frozen"].indexOf(r.state),tlv:null}}}const qt=async(e,t,r=[],n=1)=>{const o=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:t,params:r}),s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:o});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return n?de(await s.json()):await s.json()},Qt=async(e,t,r=[])=>{let n;"inclusion"===t?n=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===t?n=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===t&&(n=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const o=await fetch(`${e}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:n});if(!o.ok)throw new Error(`Error fetching proof: ${o.statusText}`);return Ae(xe(await o.json()))};function jt(e){const t=[];for(let r=0;r<e.length;r++){const n={root:ae(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>ae(e))),leaf:ae(S(e[r].hash))};t.push(n)}return t}function Wt(e){const t=[];for(let r=0;r<e.length;r++){const n={root:ae(e[r].root),value:ae(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>ae(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:ae(e[r].leafLowerRangeValue),leafHigherRangeValue:ae(e[r].leafHigherRangeValue)};t.push(n)}return t}function $t(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return new u(0);let n=r.poseidonHashBN([e[0].toString(),t[0].toString()]);for(let o=1;o<e.length;o++)n=r.poseidonHashBN([n.toString(),e[o].toString(),t[o].toString()]);return n}const zt=w().nullifierQueue,Zt=w().addressQueue;class Jt extends e.Connection{constructor(e,t,r,n){super(e,n||"confirmed"),this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCompressedAccount(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const o=await qt(this.compressionApiEndpoint,"getCompressedAccount",{hash:r?P(r):void 0,address:t?P(t):void 0}),s=n.create(o,mt(n.nullable(ft)));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===s.result.value)return null;const i=s.result.value;return O(R(i.tree,zt,i.hash.toArray("be",32),i.leafIndex),i.owner,S(i.lamports),i.data?Ht(i.data):void 0,i.address||void 0)}async getCompressedBalance(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const o=await qt(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?P(r):void 0,address:t?P(t):void 0}),s=n.create(o,mt(Pt));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get balance for compressed account ${r?r.toString():t?t.toString():""}`);return null===s.result.value?S(0):S(s.result.value)}async getCompressedBalanceByOwner(t){const r=await qt(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),o=n.create(r,mt(Pt));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===o.result.value?S(0):S(o.result.value)}async getCompressedAccountProof(t){const r=await qt(this.compressionApiEndpoint,"getCompressedAccountProof",{hash:P(t)}),o=n.create(r,mt(It));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get proof for compressed account ${t.toString()}`);if(null===o.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);return{hash:o.result.value.hash.toArray("be",32),merkleTree:o.result.value.merkleTree,leafIndex:o.result.value.leafIndex,merkleProof:o.result.value.proof,nullifierQueue:zt,rootIndex:o.result.value.rootSeq%2400,root:o.result.value.root}}async getMultipleCompressedAccounts(t){const r=await qt(this.compressionApiEndpoint,"getMultipleCompressedAccounts",{hashes:t.map((e=>P(e)))}),o=n.create(r,mt(yt));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts ${t.map((e=>P(e))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>P(e))).join(", ")}`);const s=[];return o.result.value.items.map((e=>{const t=O(R(e.tree,zt,e.hash.toArray("be",32),e.leafIndex),e.owner,S(e.lamports),e.data?Ht(e.data):void 0,e.address||void 0);s.push(t)})),s.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=await qt(this.compressionApiEndpoint,"getMultipleCompressedAccountProofs",t.map((e=>P(e)))),o=n.create(r,mt(n.array(It)));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get proofs for compressed accounts ${t.map((e=>P(e))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>P(e))).join(", ")}`);const s=[];for(const e of o.result.value){const t={hash:e.hash.toArray("be",32),merkleTree:e.merkleTree,leafIndex:e.leafIndex,merkleProof:e.proof,nullifierQueue:Zt,rootIndex:e.rootSeq%2400,root:e.root};s.push(t)}return s}async getCompressedAccountsByOwner(t,r){var o;const s=await qt(this.compressionApiEndpoint,"getCompressedAccountsByOwner",{owner:t.toBase58(),filters:(null==r?void 0:r.filters)||[],dataSlice:null==r?void 0:r.dataSlice,cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,mt(vt));if("error"in i)throw new e.SolanaJSONRPCError(i.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===i.result.value)return{items:[],cursor:null};const a=[];return i.result.value.items.map((e=>{const t=O(R(e.tree,zt,e.hash.toArray("be",32),e.leafIndex),e.owner,S(e.lamports),e.data?Ht(e.data):void 0,e.address||void 0);a.push(t)})),{items:a.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:i.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Vt(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),Vt(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=await qt(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:P(t)}),o=n.create(r,mt(Ct));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get balance for compressed token account ${t.toString()}`);if(null===o.result.value)throw new Error(`failed to get balance for compressed token account ${t.toString()}`);return{amount:S(o.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var o,s;r||(r={});const i=await qt(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:t.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(s=r.limit)||void 0===s?void 0:s.toNumber(),cursor:r.cursor}),a=n.create(i,mt(Ot));if("error"in a)throw new e.SolanaJSONRPCError(a.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===a.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);return{items:r.mint?a.result.value.tokenBalances.filter((e=>e.mint.toBase58()===r.mint.toBase58())):a.result.value.tokenBalances,cursor:a.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(t,r){var o,s;r||(r={});const i=await qt(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:t.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(s=r.limit)||void 0===s?void 0:s.toNumber(),cursor:r.cursor}),a=n.create(i,mt(Rt));if("error"in a)throw new e.SolanaJSONRPCError(a.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===a.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);const u=r.mint?a.result.value.items.filter((e=>e.mint.toBase58()===r.mint.toBase58())):a.result.value.items;return{context:a.result.context,value:{items:u,cursor:a.result.value.cursor}}}async getCompressionSignaturesForAccount(t){const r=await qt(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:P(t)}),o=n.create(r,mt(Ut));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for compressed account ${t.toString()}`);return o.result.value.items}async getTransactionWithCompressionInfo(t){const r=await qt(this.compressionApiEndpoint,"getTransactionWithCompressionInfo",{signature:t}),o=n.create(r,pt(Ft));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get slot");if(null===o.result.transaction)return null;const s=[],i=[];o.result.compressionInfo.closedAccounts.map((e=>{s.push(Kt(e))})),o.result.compressionInfo.openedAccounts.map((e=>{i.push(Kt(e))}));const a=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},u=a(s),l=a(i);return{compressionInfo:{closedAccounts:s,openedAccounts:i,preTokenBalances:u,postTokenBalances:l},transaction:o.result.transaction}}async getCompressionSignaturesForAddress(t,r){var o;const s=await qt(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,mt(Dt));if("error"in i)throw new e.SolanaJSONRPCError(i.error,`failed to get signatures for address ${t.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for address ${t.toBase58()}`);return i.result.value}async getCompressionSignaturesForOwner(t,r){var o;const s=await qt(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,mt(Dt));if("error"in i)throw new e.SolanaJSONRPCError(i.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return i.result.value}async getCompressionSignaturesForTokenOwner(t,r){var o;const s=await qt(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,mt(Dt));if("error"in i)throw new e.SolanaJSONRPCError(i.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===i.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return i.result.value}async getIndexerHealth(){const t=await qt(this.compressionApiEndpoint,"getIndexerHealth"),r=n.create(t,pt(bt));if("error"in r)throw new e.SolanaJSONRPCError(r.error,"failed to get health");return r.result}async confirmTransactionIndexed(e){const t=Date.now();for(;;){if(await this.getIndexerSlot()>=e)return 1;if(Date.now()-t>2e4)throw new Error("Timeout: Indexer slot did not reach the required slot within 20 seconds");await new Promise((e=>setTimeout(e,200)))}}async getIndexerSlot(){const t=await qt(this.compressionApiEndpoint,"getIndexerSlot"),r=n.create(t,pt(Et));if("error"in r)throw new e.SolanaJSONRPCError(r.error,"failed to get slot");return r.result}async getCompressedMintTokenHolders(t,r){var o;const s=await qt(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),i=n.create(s,mt(Lt));if("error"in i)throw new e.SolanaJSONRPCError(i.error,"failed to get mint token holders");return i.result}async getLatestCompressionSignatures(t,r){const o=await qt(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),s=n.create(o,mt(At));if("error"in s)throw new e.SolanaJSONRPCError(s.error,"failed to get latest non-voting signatures");return s.result}async getLatestNonVotingSignatures(t,r){const o=await qt(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),s=n.create(o,mt(xt));if("error"in s)throw new e.SolanaJSONRPCError(s.error,"failed to get latest non-voting signatures");return s.result}async getMultipleNewAddressProofs(t){const r=await qt(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>P(e)))),o=n.create(r,mt(n.array(Tt)));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get proofs for new addresses ${t.map((e=>P(e))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>P(e))).join(", ")}`);const s=[];for(const e of o.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:S(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:S(e.lowElementLeafIndex),merkleTree:e.merkleTree,nullifierQueue:Zt};s.push(t)}return s}async getValidityProofDirect(e=[],t=[]){let r;if(0===e.length&&0===t.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(e.length>0&&0===t.length){const t=await this.getMultipleCompressedAccountProofs(e),n=jt(t);r={compressedProof:await Qt(this.proverEndpoint,"inclusion",n),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>S(e.hash))),merkleTrees:t.map((e=>e.merkleTree)),nullifierQueues:t.map((e=>e.nullifierQueue))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Wt(e);r={compressedProof:await Qt(this.proverEndpoint,"new-address",n),roots:e.map((e=>e.root)),rootIndices:e.map((e=>e.rootIndex)),leafIndices:e.map((e=>e.nextIndex.toNumber())),leaves:e.map((e=>S(e.value))),merkleTrees:e.map((e=>e.merkleTree)),nullifierQueues:e.map((e=>e.nullifierQueue))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=jt(n),s=await this.getMultipleNewAddressProofs(t),i=Wt(s);r={compressedProof:await Qt(this.proverEndpoint,"combined",[o,i]),roots:n.map((e=>e.root)).concat(s.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(s.map((e=>e.rootIndex))),leafIndices:n.map((e=>e.leafIndex)).concat(s.map((e=>e.nextIndex.toNumber()))),leaves:n.map((e=>S(e.hash))).concat(s.map((e=>S(e.value)))),merkleTrees:n.map((e=>e.merkleTree)).concat(s.map((e=>e.merkleTree))),nullifierQueues:n.map((e=>e.nullifierQueue)).concat(s.map((e=>e.nullifierQueue)))}}}return r}async getValidityProof(e=[],t=[]){const r=w().addressTree,n=w().addressQueue,o=w().merkleTree,s=w().nullifierQueue,i=e.map((e=>({hash:e,tree:o,queue:s}))),a=t.map((e=>({address:e,tree:r,queue:n})));return this.getValidityProofV0(i,a)}async getValidityProofV0(e=[],t=[]){const{value:r}=await this.getValidityProofAndRpcContext(e,t);return r}async getValidityProofAndRpcContext(t=[],r=[]){const o=await qt(this.compressionApiEndpoint,"getValidityProof",{hashes:t.map((({hash:e})=>P(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:P(e),tree:t.toBase58()})))}),s=n.create(o,mt(kt));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const i=s.result.value;if(null===i)throw new Error(`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);return{value:{compressedProof:i.compressedProof,merkleTrees:i.merkleTrees,leafIndices:i.leafIndices,nullifierQueues:[...t.map((({queue:e})=>e)),...r.map((({queue:e})=>e))],rootIndices:i.rootIndices,roots:i.roots,leaves:i.leaves},context:s.result.context}}}class Xt{constructor(e,t,r){this.index=e,this.value=t,this.nextIndex=r}equals(e){return this.value.eq(e.value)}compareTo(e){return this.value.cmp(e.value)}hash(e,t){try{return e.poseidonHash([S(this.value.toArray("be",32)).toString(),S(this.nextIndex).toString(),S(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class Gt{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class Yt{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new Yt([new Xt(0,S(0),0)],0,0)}get(e){return this.elements[e]}length(){return Number(this.currentNodeIndex)}isEmpty(){return 0===this.currentNodeIndex}findElement(e){return this.elements.slice(0,this.length()+1).find((t=>t.value===e))}init(){try{const e=h;return this.append(e)}catch(e){throw new Error(`Failed to initialize IndexedArray: ${e}`)}}findLowElementIndex(e){for(let t=0;t<=this.length();t++){const r=this.elements[t];if(this.elements[r.nextIndex].value.gt(e)&&r.value.lt(e))return t;if(r.value.eq(e))throw new Error("Element already exists in the array")}return this.highestElementIndex}findLowElement(e){const t=this.findLowElementIndex(e);if(void 0===t)return[void 0,void 0];const r=this.elements[t];return[r,this.elements[r.nextIndex].value]}hashElement(e,t){const r=this.elements[t];if(!r)return;const n=this.elements[r.nextIndex];return n?e.poseidonHash([S(r.value.toArray("be",32)).toString(),S(r.nextIndex).toString(),S(n.value.toArray("be",32)).toString()]):void 0}append(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.appendWithLowElementIndex(t,e)}appendWithLowElementIndex(e,t){const r=this.elements[e];if(0===r.nextIndex){if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.")}else{const e=this.elements[r.nextIndex];if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.");if(t.gte(e.value))throw new Error("New element value must be less than the next element value.")}const n=this.newElementWithLowElementIndex(e,t);return 0===r.nextIndex&&(this.highestElementIndex=n.newElement.index),this.currentNodeIndex=n.newElement.index,this.elements[this.length()]=n.newElement,this.elements[e]=n.newLowElement,n}lowest(){return this.elements.length>0?this.elements[0]:void 0}newElementWithLowElementIndex(e,t){const r=this.elements[e],n=this.currentNodeIndex+1,o=new Xt(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new Gt(r,o,s)}newElement(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.newElementWithLowElementIndex(t,e)}}class er{constructor(e,t,r=[],{zeroElement:n="0"}={}){if(this.levels=e,this.capacity=2**e,this.zeroElement=n,this._lightWasm=t,r.length>this.capacity)throw new Error("Tree is full");this._zeros=[],this._layers=[],this._layers[0]=r,this._zeros[0]=this.zeroElement;for(let t=1;t<=e;t++)this._zeros[t]=this._lightWasm.poseidonHashString([this._zeros[t-1],this._zeros[t-1]]);this._rebuild()}_rebuild(){for(let e=1;e<=this.levels;e++){this._layers[e]=[];for(let t=0;t<Math.ceil(this._layers[e-1].length/2);t++)this._layers[e][t]=this._lightWasm.poseidonHashString([this._layers[e-1][2*t],2*t+1<this._layers[e-1].length?this._layers[e-1][2*t+1]:this._zeros[e-1]])}}root(){return this._layers[this.levels].length>0?this._layers[this.levels][0]:this._zeros[this.levels]}insert(e){if(this._layers[0].length>=this.capacity)throw new Error("Tree is full");this.update(this._layers[0].length,e)}bulkInsert(e){if(this._layers[0].length+e.length>this.capacity)throw new Error("Tree is full");this._layers[0].push(...e),this._rebuild()}update(e,t){if(isNaN(Number(e))||e<0||e>this._layers[0].length||e>=this.capacity)throw new Error("Insert index out of bounds: "+e);this._layers[0][e]=t;for(let t=1;t<=this.levels;t++)e>>=1,this._layers[t][e]=this._lightWasm.poseidonHashString([this._layers[t-1][2*e],2*e+1<this._layers[t-1].length?this._layers[t-1][2*e+1]:this._zeros[t-1]])}path(e){if(isNaN(Number(e))||e<0||e>=this._layers[0].length)throw new Error("Index out of bounds: "+e);const t=[],r=[];for(let n=0;n<this.levels;n++)r[n]=e%2,t[n]=(1^e)<this._layers[n].length?this._layers[n][1^e]:this._zeros[n],e>>=1;return{pathElements:t,pathIndices:r}}indexOf(e,t=null){return t?this._layers[0].findIndex((r=>t(e,r))):this._layers[0].indexOf(e)}elements(){return this._layers[0].slice()}serialize(){return{levels:this.levels,_zeros:this._zeros,_layers:this._layers}}static deserialize(e,t){const r=Object.assign(Object.create(this.prototype),e);return r._hash=t,r.capacity=2**r.levels,r.zeroElement=r._zeros[0],r}}async function tr(e){const{noopProgram:t,accountCompressionProgram:r}=g(),n=(await e.getConfirmedSignaturesForAddress2(r,void 0,"confirmed")).map((e=>e.signature)),o=(await e.getParsedTransactions(n,{maxSupportedTransactionVersion:0,commitment:"confirmed"})).filter((e=>e?e.transaction.message.accountKeys.some((e=>("string"==typeof e?e:e.pubkey.toBase58())===t.toBase58())):0));return rr(o,nr)}const rr=(e,t)=>{const{noopProgram:r}=g(),n=[];return e.forEach((e=>{!e||!e.meta||e.meta.err||!e.meta.innerInstructions||e.meta.innerInstructions.length<=0||e.meta.innerInstructions.forEach((o=>{if(o.instructions.length>0){const s=o.instructions[o.instructions.length-1];if("data"in s&&s.data&&s.programId.toBase58()===r.toBase58()){const r=k.decode(s.data),o=t(Buffer.from(r),e);null!=o&&n.push(o)}}}))})),n},nr=e=>{const t=Buffer.from(e.map((e=>e)));try{return We(t)}catch(e){return null}};async function or(e,t){return(await sr(e)).find((e=>S(e.hash).eq(t)))}async function sr(e){var t,r;const n=(await tr(e)).reverse(),o=[],s=[];for(const e of n){for(let n=0;n<e.outputCompressedAccounts.length;n++){const s=e.outputCompressedAccounts[n],i={merkleTree:w().merkleTree,nullifierQueue:w().nullifierQueue,hash:e.outputCompressedAccountHashes[n],leafIndex:e.outputLeafIndices[n]},a=O(i,s.compressedAccount.owner,s.compressedAccount.lamports,null!==(t=s.compressedAccount.data)&&void 0!==t?t:void 0,null!==(r=s.compressedAccount.address)&&void 0!==r?r:void 0);o.push(a)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];s.push(S(r))}}const i=o.filter((e=>!s.some((t=>t.eq(S(e.hash))))));return i.sort(((e,t)=>t.leafIndex-e.leafIndex)),i}const ir=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),ar=De.struct([De.publicKey("mint"),De.publicKey("owner"),De.u64("amount"),De.option(De.publicKey(),"delegate"),De.u8("state"),De.option(De.vecU8(),"tlv")]);function ur(e,t=ir){if(null===e.data)return null;const{data:r}=e.data;if(0===r.length)return null;if(e.owner.toBase58()!==t.toBase58())throw new Error(`Invalid owner ${e.owner.toBase58()} for token layout`);return ar.decode(Buffer.from(r))}async function lr(e){const t=await Promise.all(e.map((e=>async function(e){const t=e.pubkeyArray,r=e.outputCompressedAccountHashes,n=e.outputCompressedAccounts.map(((n,o)=>{var s;const i={merkleTree:t[e.outputCompressedAccounts[o].merkleTreeIndex],nullifierQueue:w().nullifierQueue,hash:r[o],leafIndex:e.outputLeafIndices[o]};if(!n.compressedAccount.data)throw new Error("No data");const a=ur(n.compressedAccount);if(!a)throw new Error("Invalid token data");return{compressedAccount:O(i,n.compressedAccount.owner,n.compressedAccount.lamports,n.compressedAccount.data,null!==(s=n.compressedAccount.address)&&void 0!==s?s:void 0),parsed:a}}));return{inputCompressedAccountHashes:e.inputCompressedAccountHashes,outputCompressedAccounts:n}}(e)))),r=t.flatMap((e=>e.outputCompressedAccounts)),n=t.flatMap((e=>e.inputCompressedAccountHashes));return r.filter((e=>!n.some((t=>JSON.stringify(t)===JSON.stringify(e.compressedAccount.hash)))))}async function hr(e,t,r){const n=await tr(e);return{items:(await lr(n)).filter((e=>e.parsed.owner.equals(t)&&e.parsed.mint.equals(r))).sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:null}}async function cr(e,t,r){const n=await tr(e);return{items:(await lr(n)).filter((e=>{var n;return(null===(n=e.parsed.delegate)||void 0===n?void 0:n.equals(t))&&e.parsed.mint.equals(r)})),cursor:null}}async function dr(e,t){const r=await tr(e),n=(await lr(r)).filter((e=>S(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class pr extends e.Connection{constructor(e,t,r,n,o,s){super(e,o||"confirmed"),this.log=0,this.compressionApiEndpoint=r,this.proverEndpoint=n;const{merkleTreeAddress:i,nullifierQueueAddress:a,depth:u,log:l,addressTreeAddress:h,addressQueueAddress:c}=null!=s?s:{},{merkleTree:d,nullifierQueue:p,merkleTreeHeight:m,addressQueue:f,addressTree:g}=w();this.lightWasm=t,this.merkleTreeAddress=null!=i?i:d,this.nullifierQueueAddress=null!=a?a:p,this.addressTreeAddress=null!=h?h:g,this.addressQueueAddress=null!=c?c:f,this.depth=null!=u?u:m,this.log=null!=l?l:0}async getCompressedAccount(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await or(this,t);return null!=r?r:null}async getCompressedBalance(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await or(this,t);if(!r)throw new Error("Account not found");return S(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),S(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await sr(e)).filter((e=>t.some((t=>S(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(e){const t=await tr(this).then((e=>e.reverse())),r=[],n=[];for(const e of t)for(let t=0;t<e.outputCompressedAccounts.length;t++){const o=e.outputCompressedAccountHashes[t];r.push(o),n.push(e.outputLeafIndices[t])}const o=new er(this.depth,this.lightWasm,r.map((e=>S(e).toString()))),s=[];for(let t=0;t<e.length;t++){const n=o.indexOf(e[t].toString()),i=o.path(n).pathElements.map((e=>S(e))),a=S(o.root()),u={hash:e[t].toArray("be",32),merkleTree:this.merkleTreeAddress,leafIndex:n,merkleProof:i,nullifierQueue:this.nullifierQueueAddress,rootIndex:r.length,root:a};s.push(u)}return s.forEach(((e,t)=>{const r=e.leafIndex,n=o.elements()[r],s=S(n).toArray("be",32);if(!s.every(((t,r)=>t===e.hash[r])))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)})),s}async getCompressedAccountsByOwner(e,t){const r=await async function(e,t){return(await sr(e)).filter((e=>e.owner.equals(t)))}(this,e);return{items:r,cursor:null}}async getLatestCompressionSignatures(e,t){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getLatestNonVotingSignatures(e){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getCompressedTokenAccountsByOwner(e,t){return await hr(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await cr(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await dr(this,e);return{amount:S(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await hr(this,e,t.mint)).items.map((e=>({balance:S(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await hr(this,e,t.mint)).items.map((e=>({balance:S(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}}async getCompressionSignaturesForAccount(e){throw new Error("getCompressionSignaturesForAccount not implemented in test-rpc")}async getTransactionWithCompressionInfo(e){throw new Error("getCompressedTransaction not implemented in test-rpc")}async getCompressionSignaturesForAddress(e,t){throw new Error("getSignaturesForAddress3 not implemented")}async getCompressionSignaturesForOwner(e,t){throw new Error("getSignaturesForOwner not implemented")}async getCompressionSignaturesForTokenOwner(e,t){throw new Error("getSignaturesForTokenOwner not implemented")}async getIndexerHealth(){return"ok"}async getIndexerSlot(){return 1}async getMultipleNewAddressProofs(e){const t=Yt.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(S(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(S(r))}const o=new er(this.depth,this.lightWasm,n.map((e=>S(e).toString()))),s=[];for(let r=0;r<e.length;r++){const[n]=t.findLowElement(e[r]);if(!n)throw new Error("Address not found");const i=n.index,a=o.path(i).pathElements.map((e=>S(e))),u=t.get(n.nextIndex).value,l={root:S(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:S(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:S(n.index),merkleTree:this.addressTreeAddress,nullifierQueue:this.addressQueueAddress};s.push(l)}return s}async getCompressedMintTokenHolders(e,t){throw new Error("getCompressedMintTokenHolders not implemented in test-rpc")}async getValidityProofDirect(e=[],t=[]){return this.getValidityProof(e,t)}async getValidityProofAndRpcContext(e=[],t=[]){if(t.some((e=>!(e instanceof u))))throw new Error("AddressWithTree is not supported in test-rpc");return{value:await this.getValidityProofV0(e,t),context:{slot:1}}}async getValidityProof(e=[],t=[]){if(t.some((e=>!(e instanceof u))))throw new Error("AddressWithTree is not supported in test-rpc");let r;if(0===e.length&&0===t.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(e.length>0&&0===t.length){const t=await this.getMultipleCompressedAccountProofs(e),n=jt(t);r={compressedProof:await Qt(this.proverEndpoint,"inclusion",n,this.log),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>S(e.hash))),merkleTrees:t.map((e=>e.merkleTree)),nullifierQueues:t.map((e=>e.nullifierQueue))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Wt(e);r={compressedProof:await Qt(this.proverEndpoint,"new-address",n,this.log),roots:e.map((e=>e.root)),rootIndices:e.map((()=>3)),leafIndices:e.map((e=>e.indexHashedIndexedElementLeaf.toNumber())),leaves:e.map((e=>S(e.value))),merkleTrees:e.map((e=>e.merkleTree)),nullifierQueues:e.map((e=>e.nullifierQueue))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=jt(n),s=await this.getMultipleNewAddressProofs(t),i=Wt(s);r={compressedProof:await Qt(this.proverEndpoint,"combined",[o,i],this.log),roots:n.map((e=>e.root)).concat(s.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(s.map((()=>3))),leafIndices:n.map((e=>e.leafIndex)).concat(s.map((e=>e.indexHashedIndexedElementLeaf.toNumber()))),leaves:n.map((e=>S(e.hash))).concat(s.map((e=>S(e.value)))),merkleTrees:n.map((e=>e.merkleTree)).concat(s.map((e=>e.merkleTree))),nullifierQueues:n.map((e=>e.nullifierQueue)).concat(s.map((e=>e.nullifierQueue)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}}exports.ADDRESS_QUEUE_ROLLOVER_FEE=I,exports.ADDRESS_TREE_NETWORK_FEE=_,exports.ALICE=Oe,exports.AccountProofResult=Bt,exports.BOB=Re,exports.BalanceResult=Ct,exports.BaseRpc=class{async getCancellationPromise(){throw new Error("getCancellationPromise not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async getTransactionConfirmationPromise(){throw new Error("getTransactionConfirmationPromise not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingBlockHeightExceedanceStrategy(){throw new Error("confirmTransactionUsingBlockHeightExceedanceStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingDurableNonceStrategy(){throw new Error("confirmTransactionUsingDurableNonceStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:e,signature:t}){throw new Error("confirmTransactionUsingLegacyTimeoutStrategy not supported in rpc. it is a stub that is marked as private in web3.js Connection")}},exports.CHARLIE=Le,exports.CompressedAccountLayout=Fe,exports.CompressedAccountResult=ft,exports.CompressedAccountsByOwnerResult=vt,exports.CompressedMintTokenHoldersResult=Lt,exports.CompressedTokenAccountResult=wt,exports.CompressedTokenAccountsByOwnerOrDelegateResult=Mt,exports.CompressedTransactionResult=Ft,exports.CreateUtxoError=class extends st{},exports.DAVE=Be,exports.DEFAULT_MERKLE_TREE_HEIGHT=b,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=l,exports.HIGHEST_ADDRESS_PLUS_ONE=h,exports.HashError=class extends st{},exports.HealthResult=bt,exports.IndexedArray=Yt,exports.IndexedElement=Xt,exports.IndexedElementBundle=Gt,exports.InstructionDataInvokeLayout=Ke,exports.LatestNonVotingSignaturesResult=xt,exports.LatestNonVotingSignaturesResultPaginated=At,exports.LightSystemProgram=Ze,exports.LookupTableError=class extends st{},exports.MerkeProofResult=It,exports.MerkleContextLayout=He,exports.MerkleTree=er,exports.MerkleTreeError=class extends st{},exports.MultipleCompressedAccountsResult=yt,exports.MultipleMerkleProofsResult=St,exports.NativeBalanceResult=Pt,exports.NewAddressParamsLayout=Ve,exports.NewAddressProofResult=Tt,exports.ProofError=class extends st{},exports.PublicTransactionEventLayout=je,exports.Rpc=Jt,exports.RpcError=class extends st{},exports.STATE_MERKLE_TREE_NETWORK_FEE=T,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=A,exports.SelectInUtxosError=class extends st{},exports.SignatureListResult=Ut,exports.SignatureListWithCursorResult=Dt,exports.SlotResult=Et,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=x,exports.TestRpc=pr,exports.TokenBalanceListResult=Ot,exports.TokenBalanceListResultV2=Rt,exports.TokenBalanceResult=Nt,exports.TokenDataLayout=ar,exports.TokenDataResult=gt,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends st{},exports.UtxoError=class extends st{},exports.ValidityProofResult=kt,exports.accountCompressionProgram=p,exports.addressQueue=E,exports.addressTree=M,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await be(e,n),n},exports.bn=S,exports.bufToDecStr=e=>C(e).toString(),exports.buildAndSignTx=Pe,exports.buildTx=ke,exports.byteArrayToKeypair=function(t){return e.Keypair.fromSecretKey(Uint8Array.from(t))},exports.calculateComputeUnitPrice=function(e,t){return Math.ceil(1e6*e/t)},exports.checkValidityProofShape=e=>{if(32!==e.a.length||64!==e.b.length||32!==e.c.length)throw new Error("ValidityProof has invalid shape")},exports.compress=async function(t,r,n,o,s,i){const{blockhash:a}=await t.getLatestBlockhash(),u=await Ze.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTree:s}),l=Pe([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await Se(t,l,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=be,exports.confirmTx=Ce,exports.convertMerkleProofsWithContextToHex=jt,exports.convertNonInclusionMerkleProofInputsToHex=Wt,exports.createAccount=async function(t,r,n,o,s,i,a,u){const{blockhash:l}=await t.getLatestBlockhash();s=null!=s?s:w().addressTree,i=null!=i?i:w().addressQueue;const h=ve(n,o),c=Me(h,s),d=await t.getValidityProofV0(void 0,[{address:S(c.toBytes()),tree:s,queue:i}]),p={seed:h,addressMerkleTreeRootIndex:d.rootIndices[0],addressMerkleTreePubkey:d.merkleTrees[0],addressQueuePubkey:d.nullifierQueues[0]},m=await Ze.createAccount({payer:r.publicKey,newAddressParams:p,newAddress:Array.from(c.toBytes()),recentValidityProof:d.compressedProof,programId:o,outputStateTree:a}),f=Pe([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),m],r,l,[]);return await Se(t,f,u)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u,l){o=S(o);const h=await t.getCompressedAccountsByOwner(r.publicKey),[c]=Je(h.items,o),{blockhash:d}=await t.getLatestBlockhash();i=null!=i?i:w().addressTree,a=null!=a?a:w().addressQueue;const p=ve(n,s),m=Me(p,i),f=await t.getValidityProof(c.map((e=>S(e.hash))),[S(m.toBytes())]),g={seed:p,addressMerkleTreeRootIndex:f.rootIndices[f.rootIndices.length-1],addressMerkleTreePubkey:f.merkleTrees[f.merkleTrees.length-1],addressQueuePubkey:f.nullifierQueues[f.nullifierQueues.length-1]},y=await Ze.createAccount({payer:r.publicKey,newAddressParams:g,newAddress:Array.from(m.toBytes()),recentValidityProof:f.compressedProof,inputCompressedAccounts:c,inputStateRootIndices:f.rootIndices,programId:s,outputStateTree:u}),v=Pe([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),y],r,d,[]);return await Se(t,v,l)},exports.createBN254=C,exports.createCompressedAccount=N,exports.createCompressedAccountWithMerkleContext=O,exports.createMerkleContext=R,exports.createRpc=function(e="http://127.0.0.1:8899",t="http://127.0.0.1:8784",r="http://127.0.0.1:3001",n){const o="string"==typeof e?e:e.rpcEndpoint;return new Jt(o,t,r,n)},exports.createRpcResult=ct,exports.decodeInstructionDataInvoke=function(e){return Ke.decode(e)},exports.decodePublicTransactionEvent=We,exports.decompress=async function(t,r,n,o,s,i){const a=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=S(n);const u=$e(a);if(n.gt(u))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${u}`);const l=await t.getValidityProof(a.map((e=>S(e.hash)))),{blockhash:h}=await t.getLatestBlockhash(),c=await Ze.decompress({payer:r.publicKey,toAddress:o,outputStateTree:s,inputCompressedAccounts:a,recentValidityProof:l.compressedProof,recentInputStateRootIndices:l.rootIndices,lamports:n}),d=Pe([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),c],r,h,[]);return await Se(t,d,i)},exports.dedupeSigner=function(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t},exports.defaultStaticAccounts=()=>[new e.PublicKey(m()),new e.PublicKey(c),new e.PublicKey(p),new e.PublicKey(f())],exports.defaultStaticAccountsStruct=g,exports.defaultTestStateTreeAccounts=w,exports.deriveAddress=Me,exports.deriveAddressSeed=ve,exports.encodeBN254toBase58=P,exports.encodeInstructionDataInvoke=qe,exports.encodePublicTransactionEvent=function(e){const r=t.Buffer.alloc(1e3),n=je.encode(e,r);return r.slice(0,n)},exports.getAccountCompressionAuthority=f,exports.getCompressedTokenAccountByHashTest=dr,exports.getCompressedTokenAccounts=lr,exports.getCompressedTokenAccountsByDelegateTest=cr,exports.getCompressedTokenAccountsByOwnerTest=hr,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getIndexOrAdd=pe,exports.getParsedEvents=tr,exports.getPublicInputHash=function(e,t,r,n){const o=$t(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=$t(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?$t([o],[i],n):o:i},exports.getRegisteredProgramPda=m,exports.getTestKeypair=Ue,exports.getTestRpc=async function(e,t="http://127.0.0.1:8899",r="http://127.0.0.1:8784",n="http://127.0.0.1:3001",o,s,i,a=0){const u=w();return new pr(t,e,r,n,void 0,{merkleTreeAddress:o||u.merkleTree,nullifierQueueAddress:s||u.nullifierQueue,depth:i||u.merkleTreeHeight,log:a})},exports.hashToBn254FieldSizeBe=he,exports.hashvToBn254FieldSizeBe=ce,exports.invokeAccountsLayout=Qe,exports.jsonRpcResult=pt,exports.jsonRpcResultAndContext=mt,exports.lightProgram=d,exports.merkletreePubkey=v,exports.negateAndCompressProof=Ae,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=Ue(r),o=await e.requestAirdrop(n.publicKey,t);return await Ce(e,o),n},exports.noopProgram=c,exports.nullifierQueuePubkey=y,exports.packCompressedAccounts=ge,exports.packNewAddressParams=Ee,exports.padOutputStateMerkleTrees=me,exports.parseAccountData=Ht,exports.parseEvents=rr,exports.parsePublicTransactionEventWithIdl=nr,exports.parseTokenLayoutWithIdl=ur,exports.pipe=function(e,...t){return r=>t.reduce(((e,t)=>t(e)),e(r))},exports.placeholderValidityProof=()=>({a:Array.from({length:32},((e,t)=>t+1)),b:Array.from({length:64},((e,t)=>t+1)),c:Array.from({length:32},((e,t)=>t+1))}),exports.proofFromJsonStruct=xe,exports.proverRequest=Qt,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=qt,exports.selectMinCompressedSolAccountsForTransfer=Je,exports.sendAndConfirmTx=Se,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.sumUpLamports=$e,exports.toAccountMetas=fe,exports.toArray=ue,exports.toCamelCase=de,exports.toHex=ae,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i,a){var l;let h=S(0);const c=[];let d;for(n=S(n);h.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:d,limit:new u(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(new u(0))&&(c.push(e),h=h.add(e.lamports));if(d=null!==(l=r.cursor)&&void 0!==l?l:void 0,r.items.length<1e3||h.gte(n))break}if(h.lt(n))throw new Error(`Not enough balance for transfer. Required: ${n.toString()}, available: ${h.toString()}`);const[p]=Je(c,n),m=await t.getValidityProof(p.map((e=>S(e.hash)))),f=await Ze.transfer({payer:r.publicKey,inputCompressedAccounts:p,toAddress:s,lamports:n,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,outputStateTrees:i}),{blockhash:g}=await t.getLatestBlockhash(),w=Pe([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,g);return await Se(t,w,a)},exports.validateSameOwner=ye,exports.validateSufficientBalance=we;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|