@lightprotocol/stateless.js 0.20.8 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser/actions/compress.d.ts +9 -7
- package/dist/cjs/browser/actions/create-account.d.ts +25 -28
- package/dist/cjs/browser/actions/decompress.d.ts +6 -7
- package/dist/cjs/browser/actions/index.d.ts +1 -1
- package/dist/cjs/browser/actions/transfer.d.ts +8 -11
- package/dist/cjs/browser/constants.d.ts +16 -6
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/index.d.ts +2 -2
- package/dist/cjs/browser/instruction/pack-compressed-accounts.d.ts +6 -24
- package/dist/cjs/browser/programs/layout.d.ts +27 -0
- package/dist/cjs/browser/programs/system.d.ts +18 -27
- package/dist/cjs/browser/rpc-interface.d.ts +115 -50
- package/dist/cjs/browser/rpc.d.ts +21 -41
- package/dist/cjs/browser/state/BN254.d.ts +0 -1
- package/dist/cjs/browser/state/bn.d.ts +3 -0
- package/dist/cjs/browser/state/compressed-account.d.ts +53 -13
- package/dist/cjs/browser/state/index.d.ts +1 -0
- package/dist/cjs/browser/state/types.d.ts +87 -12
- package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +10 -1
- package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +1 -1
- package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +15 -19
- package/dist/cjs/browser/utils/get-state-tree-infos.d.ts +41 -0
- package/dist/cjs/browser/utils/index.d.ts +5 -2
- package/dist/cjs/browser/utils/parse-validity-proof.d.ts +3 -3
- package/dist/cjs/browser/utils/state-tree-lookup-table.d.ts +68 -0
- package/dist/cjs/node/actions/compress.d.ts +9 -7
- package/dist/cjs/node/actions/create-account.d.ts +25 -28
- package/dist/cjs/node/actions/decompress.d.ts +6 -7
- package/dist/cjs/node/actions/index.d.ts +1 -1
- package/dist/cjs/node/actions/transfer.d.ts +8 -11
- package/dist/cjs/node/constants.d.ts +16 -6
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/index.d.ts +2 -2
- package/dist/cjs/node/instruction/pack-compressed-accounts.d.ts +6 -24
- package/dist/cjs/node/programs/layout.d.ts +27 -0
- package/dist/cjs/node/programs/system.d.ts +18 -27
- package/dist/cjs/node/rpc-interface.d.ts +115 -50
- package/dist/cjs/node/rpc.d.ts +21 -41
- package/dist/cjs/node/state/BN254.d.ts +0 -1
- package/dist/cjs/node/state/bn.d.ts +3 -0
- package/dist/cjs/node/state/compressed-account.d.ts +53 -13
- package/dist/cjs/node/state/index.d.ts +1 -0
- package/dist/cjs/node/state/types.d.ts +87 -12
- package/dist/cjs/node/test-helpers/test-rpc/get-compressed-accounts.d.ts +10 -1
- package/dist/cjs/node/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +1 -1
- package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +15 -19
- package/dist/cjs/node/utils/get-state-tree-infos.d.ts +41 -0
- package/dist/cjs/node/utils/index.d.ts +5 -2
- package/dist/cjs/node/utils/parse-validity-proof.d.ts +3 -3
- package/dist/cjs/node/utils/state-tree-lookup-table.d.ts +68 -0
- package/dist/types/index.d.ts +596 -405
- package/package.json +4 -3
- package/dist/cjs/browser/utils/get-light-state-tree-info.d.ts +0 -76
- package/dist/cjs/node/utils/get-light-state-tree-info.d.ts +0 -76
- /package/dist/cjs/browser/{actions/common.d.ts → utils/dedupe-signer.d.ts} +0 -0
- /package/dist/cjs/node/{actions/common.d.ts → utils/dedupe-signer.d.ts} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("@solana/web3.js"),t="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s=0;function i(){s=1;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)r[t]=e[t],n[e.charCodeAt(t)]=t;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63}function a(e,t,n){for(var o,s,i=[],a=t;a<n;a+=3)o=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(r[(s=o)>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return i.join("")}function u(e){var t;s||i();for(var n=e.length,o=n%3,u="",l=[],c=16383,h=0,d=n-o;h<d;h+=c)l.push(a(e,h,h+c>d?d:h+c));return 1===o?(t=e[n-1],u+=r[t>>2],u+=r[t<<4&63],u+="=="):2===o&&(t=(e[n-2]<<8)+e[n-1],u+=r[t>>10],u+=r[t>>4&63],u+=r[t<<2&63],u+="="),l.push(u),l.join("")}function l(e,t,r,n,o){var s,i,a=8*o-n-1,u=(1<<a)-1,l=u>>1,c=-7,h=r?o-1:0,d=r?-1:1,p=e[t+h];for(h+=d,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+h],h+=d,c-=8);for(i=s&(1<<-c)-1,s>>=-c,c+=n;c>0;i=256*i+e[t+h],h+=d,c-=8);if(0===s)s=1-l;else{if(s===u)return i?NaN:Infinity*(p?-1:1);i+=Math.pow(2,n),s-=l}return(p?-1:1)*i*Math.pow(2,s-n)}function c(e,t,r,n,o,s){var i,a,u,l=8*s-o-1,c=(1<<l)-1,h=c>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,f=n?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||Infinity===t?(a=isNaN(t)?1:0,i=c):(i=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-i))<1&&(i--,u*=2),(t+=i+h>=1?d/u:d*Math.pow(2,1-h))*u>=2&&(i++,u/=2),i+h>=c?(a=0,i=c):i+h>=1?(a=(t*u-1)*Math.pow(2,o),i+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,o),i=0));o>=8;e[r+p]=255&a,p+=f,a/=256,o-=8);for(i=i<<o|a,l+=o;l>0;e[r+p]=255&i,p+=f,i/=256,l-=8);e[r+p-f]|=128*m}var h={}.toString,d=Array.isArray||function(e){return"[object Array]"==h.call(e)};g.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:1;var p=f();function f(){return g.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function m(e,t){if(f()<t)throw new RangeError("Invalid typed array length");return g.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=g.prototype:(null===e&&(e=new g(t)),e.length=t),e}function g(e,t,r){if(!(g.TYPED_ARRAY_SUPPORT||this instanceof g))return new g(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return v(this,e)}return y(this,e,t,r)}function y(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),g.TYPED_ARRAY_SUPPORT?(e=t).__proto__=g.prototype:e=b(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!g.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|A(t,r),o=(e=m(e,n)).write(t,r);return o!==n&&(e=e.slice(0,o)),e}(e,t,r):function(e,t){if(x(t)){var r=0|E(t.length);return 0===(e=m(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?m(e,0):b(e,t);if("Buffer"===t.type&&d(t.data))return b(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function w(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function v(e,t){if(w(t),e=m(e,t<0?0:0|E(t)),!g.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function b(e,t){var r=t.length<0?0:0|E(t.length);e=m(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function E(e){if(e>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|e}function x(e){return!(null==e||!e._isBuffer)}function A(e,t){if(x(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=0;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return J(e).length;default:if(n)return Y(e).length;t=(""+t).toLowerCase(),n=1}}function M(e,t,r){var n=0;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return F(this,t,r);case"utf8":case"utf-8":return R(this,t,r);case"ascii":return U(this,t,r);case"latin1":case"binary":return D(this,t,r);case"base64":return O(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=1}}function I(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function T(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=g.from(t,n)),x(t))return 0===t.length?-1:S(e,t,r,n,o);if("number"==typeof t)return t&=255,g.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):S(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function S(e,t,r,n,o){var s,i=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;i=2,a/=2,u/=2,r/=2}function l(e,t){return 1===i?e[t]:e.readUInt16BE(t*i)}if(o){var c=-1;for(s=r;s<a;s++)if(l(e,s)===l(t,-1===c?0:s-c)){if(-1===c&&(c=s),s-c+1===u)return c*i}else-1!==c&&(s-=s-c),c=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){for(var h=1,d=0;d<u;d++)if(l(e,s+d)!==l(t,d)){h=0;break}if(h)return s}return-1}function _(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var i=0;i<n;++i){var a=parseInt(t.substr(2*i,2),16);if(isNaN(a))return i;e[r+i]=a}return i}function C(e,t,r,n){return Z(Y(t,e.length-r),e,r,n)}function k(e,t,r,n){return Z(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function P(e,t,r,n){return k(e,t,r,n)}function L(e,t,r,n){return Z(J(t),e,r,n)}function N(e,t,r,n){return Z(function(e,t){for(var r,n,o,s=[],i=0;i<e.length&&!((t-=2)<0);++i)n=(r=e.charCodeAt(i))>>8,o=r%256,s.push(o),s.push(n);return s}(t,e.length-r),e,r,n)}function O(e,t,r){return 0===t&&r===e.length?u(e):u(e.slice(t,r))}function R(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var s,i,a,u,l=e[o],c=null,h=l>239?4:l>223?3:l>191?2:1;if(o+h<=r)switch(h){case 1:l<128&&(c=l);break;case 2:128==(192&(s=e[o+1]))&&(u=(31&l)<<6|63&s)>127&&(c=u);break;case 3:s=e[o+1],i=e[o+2],128==(192&s)&&128==(192&i)&&(u=(15&l)<<12|(63&s)<<6|63&i)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:s=e[o+1],i=e[o+2],a=e[o+3],128==(192&s)&&128==(192&i)&&128==(192&a)&&(u=(15&l)<<18|(63&s)<<12|(63&i)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=h}return function(e){var t=e.length;if(t<=B)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=B));return r}(n)}g.poolSize=8192,g._augment=function(e){return e.__proto__=g.prototype,e},g.from=function(e,t,r){return y(null,e,t,r)},g.TYPED_ARRAY_SUPPORT&&(g.prototype.__proto__=Uint8Array.prototype,g.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&g[Symbol.species]),g.alloc=function(e,t,r){return function(e,t,r,n){return w(t),t<=0?m(e,t):void 0!==r?"string"==typeof n?m(e,t).fill(r,n):m(e,t).fill(r):m(e,t)}(null,e,t,r)},g.allocUnsafe=function(e){return v(null,e)},g.allocUnsafeSlow=function(e){return v(null,e)},g.isBuffer=G,g.compare=function(e,t){if(!x(e)||!x(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,o=0,s=Math.min(r,n);o<s;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},g.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 1;default:return 0}},g.concat=function(e,t){if(!d(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return g.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=g.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!x(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},g.byteLength=A,g.prototype._isBuffer=1,g.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)I(this,t,t+1);return this},g.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)I(this,t,t+3),I(this,t+1,t+2);return this},g.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)I(this,t,t+7),I(this,t+1,t+6),I(this,t+2,t+5),I(this,t+3,t+4);return this},g.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?R(this,0,e):M.apply(this,arguments)},g.prototype.equals=function(e){if(!x(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===g.compare(this,e)},g.prototype.inspect=function(){var e="";return this.length>0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),"<Buffer "+e+">"},g.prototype.compare=function(e,t,r,n,o){if(!x(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;for(var s=(o>>>=0)-(n>>>=0),i=(r>>>=0)-(t>>>=0),a=Math.min(s,i),u=this.slice(n,o),l=e.slice(t,r),c=0;c<a;++c)if(u[c]!==l[c]){s=u[c],i=l[c];break}return s<i?-1:i<s?1:0},g.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},g.prototype.indexOf=function(e,t,r){return T(this,e,t,r,1)},g.prototype.lastIndexOf=function(e,t,r){return T(this,e,t,r,0)},g.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=0;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return C(this,e,t,r);case"ascii":return k(this,e,t,r);case"latin1":case"binary":return P(this,e,t,r);case"base64":return L(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=1}},g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var B=4096;function U(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function D(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function F(e,t,r){var n,o=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>o)&&(r=o);for(var s="",i=t;i<r;++i)s+=(n=e[i])<16?"0"+n.toString(16):n.toString(16);return s}function q(e,t,r){for(var n=e.slice(t,r),o="",s=0;s<n.length;s+=2)o+=String.fromCharCode(n[s]+256*n[s+1]);return o}function K(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function V(e,t,r,n,o,s){if(!x(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function H(e,t,r,n){t<0&&(t=65535+t+1);for(var o=0,s=Math.min(e.length-r,2);o<s;++o)e[r+o]=(t&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function j(e,t,r,n){t<0&&(t=4294967295+t+1);for(var o=0,s=Math.min(e.length-r,4);o<s;++o)e[r+o]=t>>>8*(n?o:3-o)&255}function $(e,t,r,n){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function z(e,t,r,n,o){return o||$(e,0,r,4),c(e,t,r,n,23,4),r+4}function Q(e,t,r,n,o){return o||$(e,0,r,8),c(e,t,r,n,52,8),r+8}g.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),g.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=g.prototype;else{var o=t-e;r=new g(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},g.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||K(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n},g.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||K(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},g.prototype.readUInt8=function(e,t){return t||K(e,1,this.length),this[e]},g.prototype.readUInt16LE=function(e,t){return t||K(e,2,this.length),this[e]|this[e+1]<<8},g.prototype.readUInt16BE=function(e,t){return t||K(e,2,this.length),this[e]<<8|this[e+1]},g.prototype.readUInt32LE=function(e,t){return t||K(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},g.prototype.readUInt32BE=function(e,t){return t||K(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},g.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||K(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},g.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||K(e,t,this.length);for(var n=t,o=1,s=this[e+--n];n>0&&(o*=256);)s+=this[e+--n]*o;return s>=(o*=128)&&(s-=Math.pow(2,8*t)),s},g.prototype.readInt8=function(e,t){return t||K(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},g.prototype.readInt16LE=function(e,t){t||K(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},g.prototype.readInt16BE=function(e,t){t||K(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},g.prototype.readInt32LE=function(e,t){return t||K(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},g.prototype.readInt32BE=function(e,t){return t||K(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},g.prototype.readFloatLE=function(e,t){return t||K(e,4,this.length),l(this,e,1,23,4)},g.prototype.readFloatBE=function(e,t){return t||K(e,4,this.length),l(this,e,0,23,4)},g.prototype.readDoubleLE=function(e,t){return t||K(e,8,this.length),l(this,e,1,52,8)},g.prototype.readDoubleBE=function(e,t){return t||K(e,8,this.length),l(this,e,0,52,8)},g.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||V(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,s=0;for(this[t]=255&e;++s<r&&(o*=256);)this[t+s]=e/o&255;return t+r},g.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||V(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,s=1;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+r},g.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,1,255,0),g.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},g.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},g.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},g.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):j(this,e,t,1),t+4},g.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):j(this,e,t,0),t+4},g.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);V(this,e,t,r,o-1,-o)}var s=0,i=1,a=0;for(this[t]=255&e;++s<r&&(i*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+r},g.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);V(this,e,t,r,o-1,-o)}var s=r-1,i=1,a=0;for(this[t+s]=255&e;--s>=0&&(i*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+r},g.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,1,127,-128),g.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},g.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},g.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},g.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,4,2147483647,-2147483648),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):j(this,e,t,1),t+4},g.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||V(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):j(this,e,t,0),t+4},g.prototype.writeFloatLE=function(e,t,r){return z(this,e,t,1,r)},g.prototype.writeFloatBE=function(e,t,r){return z(this,e,t,0,r)},g.prototype.writeDoubleLE=function(e,t,r){return Q(this,e,t,1,r)},g.prototype.writeDoubleBE=function(e,t,r){return Q(this,e,t,0,r)},g.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o,s=n-r;if(this===e&&r<t&&t<n)for(o=s-1;o>=0;--o)e[o+t]=this[o+r];else if(s<1e3||!g.TYPED_ARRAY_SUPPORT)for(o=0;o<s;++o)e[o+t]=this[o+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s},g.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var o=e.charCodeAt(0);o<256&&(e=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!g.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var s;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var i=x(e)?e:Y(new g(e,n).toString()),a=i.length;for(s=0;s<r-t;++s)this[s+t]=i[s%a]}return this};var W=/[^+\/0-9A-Za-z-_]/g;function Y(e,t){var r;t=t||Infinity;for(var n=e.length,o=null,s=[],i=0;i<n;++i){if((r=e.charCodeAt(i))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(i+1===n){(t-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function J(e){return function(e){var t,r,a,u,l,c;s||i();var h=e.length;if(h%4>0)throw new Error("Invalid string. Length must be a multiple of 4");l="="===e[h-2]?2:"="===e[h-1]?1:0,c=new o(3*h/4-l),a=l>0?h-4:h;var d=0;for(t=0,r=0;t<a;t+=4,r+=3)u=n[e.charCodeAt(t)]<<18|n[e.charCodeAt(t+1)]<<12|n[e.charCodeAt(t+2)]<<6|n[e.charCodeAt(t+3)],c[d++]=u>>16&255,c[d++]=u>>8&255,c[d++]=255&u;return 2===l?(u=n[e.charCodeAt(t)]<<2|n[e.charCodeAt(t+1)]>>4,c[d++]=255&u):1===l&&(u=n[e.charCodeAt(t)]<<10|n[e.charCodeAt(t+1)]<<4|n[e.charCodeAt(t+2)]>>2,c[d++]=u>>8&255,c[d++]=255&u),c}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(W,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Z(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function G(e){return null!=e&&(!!e._isBuffer||X(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&X(e.slice(0,0))}(e))}function X(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var ee="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function te(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function re(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:1}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:1,get:function(){return e[t]}})})),r}var ne={exports:{}},oe=re(Object.freeze({__proto__:null,Buffer:g,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),g.alloc(+e)},isBuffer:G,kMaxLength:p}));!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 ne?ne.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:oe.Buffer}catch(e){}function i(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 a(e,t,r){var n=i(e,r);return r-1>=t&&(n|=i(e,r-1)<<4),n}function u(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 l(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=a(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=a(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,l=0,c=r;c<a;c+=n)l=u(e,c,c+n,t),this.imuln(o),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(0!==i){var h=1;for(l=u(e,c,e.length,t),c=0;c<i;c++)h*=t;this.imuln(h),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}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){l(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 h=["","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"],d=[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],p=[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 c=u>>>26,h=67108863&u,d=Math.min(l,t.length-1),p=Math.max(0,l-e.length+1);p<=d;p++){var f=l-p|0;c+=(i=(o=0|e.words[f])*(s=0|t.words[p])+h)/67108864|0,h=67108863&i}r.words[l]=0|h,u=0|c}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?h[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=d[e],c=p[e];n="";var f=this.clone();for(f.negative=0;!f.isZero();){var m=f.modrn(c).toString(e);n=(f=f.idivn(c)).isZero()?m+n:h[l-m.length]+m+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 m=function(e,t,r){var n,o,s,i=e.words,a=t.words,u=r.words,l=0,c=0|i[0],h=8191&c,d=c>>>13,p=0|i[1],f=8191&p,m=p>>>13,g=0|i[2],y=8191&g,w=g>>>13,v=0|i[3],b=8191&v,E=v>>>13,x=0|i[4],A=8191&x,M=x>>>13,I=0|i[5],T=8191&I,S=I>>>13,_=0|i[6],C=8191&_,k=_>>>13,P=0|i[7],L=8191&P,N=P>>>13,O=0|i[8],R=8191&O,B=O>>>13,U=0|i[9],D=8191&U,F=U>>>13,q=0|a[0],K=8191&q,V=q>>>13,H=0|a[1],j=8191&H,$=H>>>13,z=0|a[2],Q=8191&z,W=z>>>13,Y=0|a[3],J=8191&Y,Z=Y>>>13,G=0|a[4],X=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,ce=0|a[8],he=8191&ce,de=ce>>>13,pe=0|a[9],fe=8191&pe,me=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(l+(n=Math.imul(h,K))|0)+((8191&(o=(o=Math.imul(h,V))+Math.imul(d,K)|0))<<13)|0;l=((s=Math.imul(d,V))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(f,K),o=(o=Math.imul(f,V))+Math.imul(m,K)|0,s=Math.imul(m,V);var ye=(l+(n=n+Math.imul(h,j)|0)|0)+((8191&(o=(o=o+Math.imul(h,$)|0)+Math.imul(d,j)|0))<<13)|0;l=((s=s+Math.imul(d,$)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,K),o=(o=Math.imul(y,V))+Math.imul(w,K)|0,s=Math.imul(w,V),n=n+Math.imul(f,j)|0,o=(o=o+Math.imul(f,$)|0)+Math.imul(m,j)|0,s=s+Math.imul(m,$)|0;var we=(l+(n=n+Math.imul(h,Q)|0)|0)+((8191&(o=(o=o+Math.imul(h,W)|0)+Math.imul(d,Q)|0))<<13)|0;l=((s=s+Math.imul(d,W)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(b,K),o=(o=Math.imul(b,V))+Math.imul(E,K)|0,s=Math.imul(E,V),n=n+Math.imul(y,j)|0,o=(o=o+Math.imul(y,$)|0)+Math.imul(w,j)|0,s=s+Math.imul(w,$)|0,n=n+Math.imul(f,Q)|0,o=(o=o+Math.imul(f,W)|0)+Math.imul(m,Q)|0,s=s+Math.imul(m,W)|0;var ve=(l+(n=n+Math.imul(h,J)|0)|0)+((8191&(o=(o=o+Math.imul(h,Z)|0)+Math.imul(d,J)|0))<<13)|0;l=((s=s+Math.imul(d,Z)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(A,K),o=(o=Math.imul(A,V))+Math.imul(M,K)|0,s=Math.imul(M,V),n=n+Math.imul(b,j)|0,o=(o=o+Math.imul(b,$)|0)+Math.imul(E,j)|0,s=s+Math.imul(E,$)|0,n=n+Math.imul(y,Q)|0,o=(o=o+Math.imul(y,W)|0)+Math.imul(w,Q)|0,s=s+Math.imul(w,W)|0,n=n+Math.imul(f,J)|0,o=(o=o+Math.imul(f,Z)|0)+Math.imul(m,J)|0,s=s+Math.imul(m,Z)|0;var be=(l+(n=n+Math.imul(h,X)|0)|0)+((8191&(o=(o=o+Math.imul(h,ee)|0)+Math.imul(d,X)|0))<<13)|0;l=((s=s+Math.imul(d,ee)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(T,K),o=(o=Math.imul(T,V))+Math.imul(S,K)|0,s=Math.imul(S,V),n=n+Math.imul(A,j)|0,o=(o=o+Math.imul(A,$)|0)+Math.imul(M,j)|0,s=s+Math.imul(M,$)|0,n=n+Math.imul(b,Q)|0,o=(o=o+Math.imul(b,W)|0)+Math.imul(E,Q)|0,s=s+Math.imul(E,W)|0,n=n+Math.imul(y,J)|0,o=(o=o+Math.imul(y,Z)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,Z)|0,n=n+Math.imul(f,X)|0,o=(o=o+Math.imul(f,ee)|0)+Math.imul(m,X)|0,s=s+Math.imul(m,ee)|0;var Ee=(l+(n=n+Math.imul(h,re)|0)|0)+((8191&(o=(o=o+Math.imul(h,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(C,K),o=(o=Math.imul(C,V))+Math.imul(k,K)|0,s=Math.imul(k,V),n=n+Math.imul(T,j)|0,o=(o=o+Math.imul(T,$)|0)+Math.imul(S,j)|0,s=s+Math.imul(S,$)|0,n=n+Math.imul(A,Q)|0,o=(o=o+Math.imul(A,W)|0)+Math.imul(M,Q)|0,s=s+Math.imul(M,W)|0,n=n+Math.imul(b,J)|0,o=(o=o+Math.imul(b,Z)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,Z)|0,n=n+Math.imul(y,X)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,X)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(f,re)|0,o=(o=o+Math.imul(f,ne)|0)+Math.imul(m,re)|0,s=s+Math.imul(m,ne)|0;var xe=(l+(n=n+Math.imul(h,se)|0)|0)+((8191&(o=(o=o+Math.imul(h,ie)|0)+Math.imul(d,se)|0))<<13)|0;l=((s=s+Math.imul(d,ie)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(L,K),o=(o=Math.imul(L,V))+Math.imul(N,K)|0,s=Math.imul(N,V),n=n+Math.imul(C,j)|0,o=(o=o+Math.imul(C,$)|0)+Math.imul(k,j)|0,s=s+Math.imul(k,$)|0,n=n+Math.imul(T,Q)|0,o=(o=o+Math.imul(T,W)|0)+Math.imul(S,Q)|0,s=s+Math.imul(S,W)|0,n=n+Math.imul(A,J)|0,o=(o=o+Math.imul(A,Z)|0)+Math.imul(M,J)|0,s=s+Math.imul(M,Z)|0,n=n+Math.imul(b,X)|0,o=(o=o+Math.imul(b,ee)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(f,se)|0,o=(o=o+Math.imul(f,ie)|0)+Math.imul(m,se)|0,s=s+Math.imul(m,ie)|0;var Ae=(l+(n=n+Math.imul(h,ue)|0)|0)+((8191&(o=(o=o+Math.imul(h,le)|0)+Math.imul(d,ue)|0))<<13)|0;l=((s=s+Math.imul(d,le)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(R,K),o=(o=Math.imul(R,V))+Math.imul(B,K)|0,s=Math.imul(B,V),n=n+Math.imul(L,j)|0,o=(o=o+Math.imul(L,$)|0)+Math.imul(N,j)|0,s=s+Math.imul(N,$)|0,n=n+Math.imul(C,Q)|0,o=(o=o+Math.imul(C,W)|0)+Math.imul(k,Q)|0,s=s+Math.imul(k,W)|0,n=n+Math.imul(T,J)|0,o=(o=o+Math.imul(T,Z)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,Z)|0,n=n+Math.imul(A,X)|0,o=(o=o+Math.imul(A,ee)|0)+Math.imul(M,X)|0,s=s+Math.imul(M,ee)|0,n=n+Math.imul(b,re)|0,o=(o=o+Math.imul(b,ne)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,ne)|0,n=n+Math.imul(y,se)|0,o=(o=o+Math.imul(y,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,n=n+Math.imul(f,ue)|0,o=(o=o+Math.imul(f,le)|0)+Math.imul(m,ue)|0,s=s+Math.imul(m,le)|0;var Me=(l+(n=n+Math.imul(h,he)|0)|0)+((8191&(o=(o=o+Math.imul(h,de)|0)+Math.imul(d,he)|0))<<13)|0;l=((s=s+Math.imul(d,de)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,K),o=(o=Math.imul(D,V))+Math.imul(F,K)|0,s=Math.imul(F,V),n=n+Math.imul(R,j)|0,o=(o=o+Math.imul(R,$)|0)+Math.imul(B,j)|0,s=s+Math.imul(B,$)|0,n=n+Math.imul(L,Q)|0,o=(o=o+Math.imul(L,W)|0)+Math.imul(N,Q)|0,s=s+Math.imul(N,W)|0,n=n+Math.imul(C,J)|0,o=(o=o+Math.imul(C,Z)|0)+Math.imul(k,J)|0,s=s+Math.imul(k,Z)|0,n=n+Math.imul(T,X)|0,o=(o=o+Math.imul(T,ee)|0)+Math.imul(S,X)|0,s=s+Math.imul(S,ee)|0,n=n+Math.imul(A,re)|0,o=(o=o+Math.imul(A,ne)|0)+Math.imul(M,re)|0,s=s+Math.imul(M,ne)|0,n=n+Math.imul(b,se)|0,o=(o=o+Math.imul(b,ie)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ie)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,le)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,le)|0,n=n+Math.imul(f,he)|0,o=(o=o+Math.imul(f,de)|0)+Math.imul(m,he)|0,s=s+Math.imul(m,de)|0;var Ie=(l+(n=n+Math.imul(h,fe)|0)|0)+((8191&(o=(o=o+Math.imul(h,me)|0)+Math.imul(d,fe)|0))<<13)|0;l=((s=s+Math.imul(d,me)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(D,j),o=(o=Math.imul(D,$))+Math.imul(F,j)|0,s=Math.imul(F,$),n=n+Math.imul(R,Q)|0,o=(o=o+Math.imul(R,W)|0)+Math.imul(B,Q)|0,s=s+Math.imul(B,W)|0,n=n+Math.imul(L,J)|0,o=(o=o+Math.imul(L,Z)|0)+Math.imul(N,J)|0,s=s+Math.imul(N,Z)|0,n=n+Math.imul(C,X)|0,o=(o=o+Math.imul(C,ee)|0)+Math.imul(k,X)|0,s=s+Math.imul(k,ee)|0,n=n+Math.imul(T,re)|0,o=(o=o+Math.imul(T,ne)|0)+Math.imul(S,re)|0,s=s+Math.imul(S,ne)|0,n=n+Math.imul(A,se)|0,o=(o=o+Math.imul(A,ie)|0)+Math.imul(M,se)|0,s=s+Math.imul(M,ie)|0,n=n+Math.imul(b,ue)|0,o=(o=o+Math.imul(b,le)|0)+Math.imul(E,ue)|0,s=s+Math.imul(E,le)|0,n=n+Math.imul(y,he)|0,o=(o=o+Math.imul(y,de)|0)+Math.imul(w,he)|0,s=s+Math.imul(w,de)|0;var Te=(l+(n=n+Math.imul(f,fe)|0)|0)+((8191&(o=(o=o+Math.imul(f,me)|0)+Math.imul(m,fe)|0))<<13)|0;l=((s=s+Math.imul(m,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(D,Q),o=(o=Math.imul(D,W))+Math.imul(F,Q)|0,s=Math.imul(F,W),n=n+Math.imul(R,J)|0,o=(o=o+Math.imul(R,Z)|0)+Math.imul(B,J)|0,s=s+Math.imul(B,Z)|0,n=n+Math.imul(L,X)|0,o=(o=o+Math.imul(L,ee)|0)+Math.imul(N,X)|0,s=s+Math.imul(N,ee)|0,n=n+Math.imul(C,re)|0,o=(o=o+Math.imul(C,ne)|0)+Math.imul(k,re)|0,s=s+Math.imul(k,ne)|0,n=n+Math.imul(T,se)|0,o=(o=o+Math.imul(T,ie)|0)+Math.imul(S,se)|0,s=s+Math.imul(S,ie)|0,n=n+Math.imul(A,ue)|0,o=(o=o+Math.imul(A,le)|0)+Math.imul(M,ue)|0,s=s+Math.imul(M,le)|0,n=n+Math.imul(b,he)|0,o=(o=o+Math.imul(b,de)|0)+Math.imul(E,he)|0,s=s+Math.imul(E,de)|0;var Se=(l+(n=n+Math.imul(y,fe)|0)|0)+((8191&(o=(o=o+Math.imul(y,me)|0)+Math.imul(w,fe)|0))<<13)|0;l=((s=s+Math.imul(w,me)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,Z))+Math.imul(F,J)|0,s=Math.imul(F,Z),n=n+Math.imul(R,X)|0,o=(o=o+Math.imul(R,ee)|0)+Math.imul(B,X)|0,s=s+Math.imul(B,ee)|0,n=n+Math.imul(L,re)|0,o=(o=o+Math.imul(L,ne)|0)+Math.imul(N,re)|0,s=s+Math.imul(N,ne)|0,n=n+Math.imul(C,se)|0,o=(o=o+Math.imul(C,ie)|0)+Math.imul(k,se)|0,s=s+Math.imul(k,ie)|0,n=n+Math.imul(T,ue)|0,o=(o=o+Math.imul(T,le)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,le)|0,n=n+Math.imul(A,he)|0,o=(o=o+Math.imul(A,de)|0)+Math.imul(M,he)|0,s=s+Math.imul(M,de)|0;var _e=(l+(n=n+Math.imul(b,fe)|0)|0)+((8191&(o=(o=o+Math.imul(b,me)|0)+Math.imul(E,fe)|0))<<13)|0;l=((s=s+Math.imul(E,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(D,X),o=(o=Math.imul(D,ee))+Math.imul(F,X)|0,s=Math.imul(F,ee),n=n+Math.imul(R,re)|0,o=(o=o+Math.imul(R,ne)|0)+Math.imul(B,re)|0,s=s+Math.imul(B,ne)|0,n=n+Math.imul(L,se)|0,o=(o=o+Math.imul(L,ie)|0)+Math.imul(N,se)|0,s=s+Math.imul(N,ie)|0,n=n+Math.imul(C,ue)|0,o=(o=o+Math.imul(C,le)|0)+Math.imul(k,ue)|0,s=s+Math.imul(k,le)|0,n=n+Math.imul(T,he)|0,o=(o=o+Math.imul(T,de)|0)+Math.imul(S,he)|0,s=s+Math.imul(S,de)|0;var Ce=(l+(n=n+Math.imul(A,fe)|0)|0)+((8191&(o=(o=o+Math.imul(A,me)|0)+Math.imul(M,fe)|0))<<13)|0;l=((s=s+Math.imul(M,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=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(R,se)|0,o=(o=o+Math.imul(R,ie)|0)+Math.imul(B,se)|0,s=s+Math.imul(B,ie)|0,n=n+Math.imul(L,ue)|0,o=(o=o+Math.imul(L,le)|0)+Math.imul(N,ue)|0,s=s+Math.imul(N,le)|0,n=n+Math.imul(C,he)|0,o=(o=o+Math.imul(C,de)|0)+Math.imul(k,he)|0,s=s+Math.imul(k,de)|0;var ke=(l+(n=n+Math.imul(T,fe)|0)|0)+((8191&(o=(o=o+Math.imul(T,me)|0)+Math.imul(S,fe)|0))<<13)|0;l=((s=s+Math.imul(S,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=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(R,ue)|0,o=(o=o+Math.imul(R,le)|0)+Math.imul(B,ue)|0,s=s+Math.imul(B,le)|0,n=n+Math.imul(L,he)|0,o=(o=o+Math.imul(L,de)|0)+Math.imul(N,he)|0,s=s+Math.imul(N,de)|0;var Pe=(l+(n=n+Math.imul(C,fe)|0)|0)+((8191&(o=(o=o+Math.imul(C,me)|0)+Math.imul(k,fe)|0))<<13)|0;l=((s=s+Math.imul(k,me)|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(R,he)|0,o=(o=o+Math.imul(R,de)|0)+Math.imul(B,he)|0,s=s+Math.imul(B,de)|0;var Le=(l+(n=n+Math.imul(L,fe)|0)|0)+((8191&(o=(o=o+Math.imul(L,me)|0)+Math.imul(N,fe)|0))<<13)|0;l=((s=s+Math.imul(N,me)|0)+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,n=Math.imul(D,he),o=(o=Math.imul(D,de))+Math.imul(F,he)|0,s=Math.imul(F,de);var Ne=(l+(n=n+Math.imul(R,fe)|0)|0)+((8191&(o=(o=o+Math.imul(R,me)|0)+Math.imul(B,fe)|0))<<13)|0;l=((s=s+Math.imul(B,me)|0)+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863;var Oe=(l+(n=Math.imul(D,fe))|0)+((8191&(o=(o=Math.imul(D,me))+Math.imul(F,fe)|0))<<13)|0;return l=((s=Math.imul(F,me))+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=ve,u[4]=be,u[5]=Ee,u[6]=xe,u[7]=Ae,u[8]=Me,u[9]=Ie,u[10]=Te,u[11]=Se,u[12]=_e,u[13]=Ce,u[14]=ke,u[15]=Pe,u[16]=Le,u[17]=Ne,u[18]=Oe,0!==l&&(u[19]=l,r.length++),r};function g(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 c=s-l,h=(0|e.words[c])*(0|t.words[l]),d=67108863&h;a=67108863&(d=d+a|0),o+=(i=(i=i+(h/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 g(e,t,r)}Math.imul||(m=f),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?m(this,e,t):r<63?f(this,e,t):r<1024?g(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 c=0;for(l=this.length-1;l>=0&&(0!==c||l>=o);l--){var h=0|this.words[l];this.words[l]=c<<26-s|h>>>s,c=h&a}return u&&0!==c&&(u.words[u.length++]=c),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 c=n.clone()._ishlnsubmul(s,1,u);0===c.negative&&(n=c,a&&(a.words[u]=1));for(var h=u-1;h>=0;h--){var d=67108864*(0|n.words[s.length+h])+(0|n.words[s.length+h-1]);for(d=Math.min(d/i|0,67108863),n._ishlnsubmul(s,d,h);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(s,1,h),n.isZero()||(n.negative^=1);a&&(a.words[h]=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 c=n.clone(),h=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(c),i.isub(h)),s.iushrn(1),i.iushrn(1);for(var f=0,m=1;0==(n.words[0]&m)&&f<26;++f,m<<=1);if(f>0)for(n.iushrn(f);f-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(c),u.isub(h)),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,c=1;0==(t.words[0]&c)&&l<26;++l,c<<=1);if(l>0)for(t.iushrn(l);l-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var h=0,d=1;0==(n.words[0]&d)&&h<26;++h,d<<=1);if(h>0)for(n.iushrn(h);h-- >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 M(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 w={k256:null,p224:null,p192:null,p25519:null};function v(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 b(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function E(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function x(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(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 I(e){M.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)}v.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},v.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},v.prototype.split=function(e,t){e.iushrn(this.n,0,t)},v.prototype.imulK=function(e){return e.imul(this.k)},n(b,v),b.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},b.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(E,v),n(x,v),n(A,v),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(w[e])return w[e];var t;if("k256"===e)t=new b;else if("p224"===e)t=new E;else if("p192"===e)t=new x;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new A}return w[e]=t,t},M.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},M.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")},M.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(l(e,e.umod(this.m)._forceRed(this)),e)},M.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},M.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)},M.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},M.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)},M.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},M.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},M.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},M.prototype.isqr=function(e){return this.imul(e,e.clone())},M.prototype.sqr=function(e){return this.mul(e,e)},M.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),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);0!==this.pow(c,l).cmp(u);)c.redIAdd(u);for(var h=this.pow(c,s),d=this.pow(e,s.addn(1).iushrn(1)),p=this.pow(e,s),f=i;0!==p.cmp(a);){for(var m=p,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<f);var y=this.pow(h,new o(1).iushln(f-g-1));d=d.redMul(y),h=y.redSqr(),p=p.redMul(h),f=g}return d},M.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},M.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],c=u-1;c>=0;c--){var h=l>>c&1;s!==r[0]&&(s=this.sqr(s)),0!==h||0!==i?(i<<=1,i|=h,(4==++a||0===n&&0===c)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},M.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},M.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new I(e)},n(I,M),I.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},I.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},I.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)},I.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)},I.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,ee);var se,ie=ne.exports,ae=te(ie);exports.TreeType=void 0,(se=exports.TreeType||(exports.TreeType={}))[se.State=0]="State",se[se.Address=1]="Address",se[se.BatchedState=2]="BatchedState",se[se.BatchedAddress=3]="BatchedAddress";const ue=new ae("21888242871839275222246405745257275088548364400416034343698204186575808495617"),le=new ae("452312848583266388373324160190187140051835877600158453279131187530910662655"),ce=[2,64,66,15,0],he=g.from([26,16,169,7,21,202,242,25]),de=g.from([49,212,191,129,39,194,43,196]),pe=g.from([180,143,159,153,35,46,248,163]),fe="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",me="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",ge="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",ye=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),we=()=>e.PublicKey.findProgramAddressSync([g.from("cpi_authority")],new e.PublicKey(me))[0],ve=()=>({registeredProgramPda:new e.PublicKey(ye()),noopProgram:new e.PublicKey(fe),accountCompressionProgram:new e.PublicKey(ge),accountCompressionAuthority:new e.PublicKey(we()),cpiSignatureAccount:null}),be=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(Me),nullifyTable:new e.PublicKey(Ie)}],devnet:[{stateTreeLookupTable:new e.PublicKey(Te),nullifyTable:new e.PublicKey(Se)}]}),Ee=e=>e.includes("localhost")||e.includes("127.0.0.1"),xe=()=>[{tree:new e.PublicKey(ke),queue:new e.PublicKey(_e),cpiContext:new e.PublicKey(Ce),treeType:exports.TreeType.State},{tree:new e.PublicKey(Ne),queue:new e.PublicKey(Oe),cpiContext:new e.PublicKey(Re),treeType:exports.TreeType.State}],Ae=()=>({nullifierQueue:new e.PublicKey(_e),merkleTree:new e.PublicKey(ke),merkleTreeHeight:Be,addressTree:new e.PublicKey(Pe),addressQueue:new e.PublicKey(Le)}),Me="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",Ie="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",Te="8n8rH2bFRVA6cSGNDpgqcKHCndbFCT1bXxAQG89ejVsh",Se="5dhaJLBjnVBQFErr8oiCJmcVsx3Zj6xDekGB2zULPsnP",_e="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",Ce="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",ke="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",Pe="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",Le="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",Ne="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Oe="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",Re="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",Be=26,Ue=new ae(Math.floor(2**Be*.95)),De=new ae(300),Fe=new ae(392),qe=new ae(5e3),Ke=new ae(5e3);var Ve=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 c=new Uint8Array(s+(a-l));let h=s;for(;l!==a;)c[h++]=u[l++];return c}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 c=u-s;for(;c!==u&&0===l[c];)c++;let h=r.repeat(n);for(;c<u;++c)h+=e.charAt(l[c]);return h},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const He=(e,t,r)=>new ae(e,t,r),je=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return je(Ve.decode(e))}return function(e){if(e.gte(ue))throw new Error("Value is too large. Max <254 bits");return e}(new ae(e,t))};function $e(e){const t=je(e).toArrayLike(g,void 0,32);return Ve.encode(t)}const ze=(e,t,r,n)=>({owner:e,lamports:null!=t?t:He(0),address:null!=n?n:null,data:null!=r?r:null}),Qe=(e,t,r,n,o)=>Object.assign(Object.assign(Object.assign({},ze(t,r,n,o)),e),{readOnly:0}),We=(e,t,r,n)=>({merkleTree:e,nullifierQueue:t,hash:r,leafIndex:n});function Ye(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Je(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 Ze(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 Ge=BigInt(2**32-1),Xe=BigInt(32);function et(e,t=0){return t?{h:Number(e&Ge),l:Number(e>>Xe&Ge)}:{h:0|Number(e>>Xe&Ge),l:0|Number(e&Ge)}}function tt(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}=et(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const rt=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function nt(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 ot(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)),Je(e),e}class st{clone(){return this._cloneInto()}}const it=[],at=[],ut=[],lt=BigInt(0),ct=BigInt(1),ht=BigInt(2),dt=BigInt(7),pt=BigInt(256),ft=BigInt(113);for(let e=0,t=ct,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],it.push(2*(5*n+r)),at.push((e+1)*(e+2)/2%64);let o=lt;for(let e=0;e<7;e++)t=(t<<ct^(t>>dt)*ft)%pt,t&ht&&(o^=ct<<(ct<<BigInt(e))-ct);ut.push(o)}const[mt,gt]=tt(ut,1),yt=(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),wt=(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 vt extends st{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,Ye(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(){rt||nt(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=yt(s,i,1)^r[n],u=wt(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=at[r],s=yt(t,o,n),i=wt(t,o,n),a=it[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]^=mt[n],e[1]^=gt[n]}r.fill(0)}(this.state32,this.rounds),rt||nt(this.state32),this.posOut=0,this.pos=0}update(e){Ze(this);const{blockLen:t,state:r}=this,n=(e=ot(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){Ze(this,0),Je(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 Ye(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){Je(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 vt(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 bt=(()=>function(e){const t=t=>e().update(ot(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new vt(136,1,32))))(),Et=e=>"object"==typeof e&&null!==e,xt=e=>Et(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),At=Symbol("mapObjectSkip"),Mt=(e,t,r,n=new WeakMap)=>{if(r={deep:0,target:{},...r},n.has(e))return n.get(e);n.set(e,r.target);const{target:o}=r;delete r.target;const s=e=>e.map((e=>xt(e)?Mt(e,t,r,n):e));if(Array.isArray(e))return s(e);for(const[i,a]of Object.entries(e)){const u=t(i,a,e);if(u===At)continue;let[l,c,{shouldRecurse:h=1}={}]=u;"__proto__"!==l&&(r.deep&&h&&xt(c)&&(c=Array.isArray(c)?s(c):Mt(c,t,r,n)),o[l]=c)}return o};function It(e,t,r){if(!Et(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return Mt(e,t,r)}const Tt=/[\p{Lu}]/u,St=/[\p{Ll}]/u,_t=/^[\p{Lu}](?![\p{Lu}])/gu,Ct=/([\p{Alpha}\p{N}_]|$)/u,kt=/[_.\- ]+/,Pt=new RegExp("^"+kt.source),Lt=new RegExp(kt.source+Ct.source,"gu"),Nt=new RegExp("\\d+"+Ct.source,"gu");class Ot extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,r]of e)this.onEviction(t,r.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()?("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e)):0}_getOrDeleteIfExpired(e,t){if(0==this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const r=t.get(e);return this._getItemValue(e,r)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield e)}for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(0==this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:r=this.maxAge}={}){const n="number"==typeof r&&r!==Number.POSITIVE_INFINITY?Date.now()+r:void 0;return this.cache.has(e)?this.cache.set(e,{value:t,expiry:n}):this._set(e,{value:t,expiry:n}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):this.oldCache.has(e)?!this._deleteIfExpired(e,this.oldCache.get(e)):0}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],r=t.length-e;r<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(r>0&&this._emitEvictions(t.slice(0,r)),this.oldCache=new Map(t.slice(r)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;this.cache.has(n)||0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[r,n]of this.entriesAscending())e.call(t,n,r,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}const Rt=new Ot({maxSize:1e5}),Bt=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),Ut=(e,t={})=>{if(!Bt(e))return e;const{exclude:r,pascalCase:n=0,stopPaths:o,deep:s=0,preserveConsecutiveUppercase:i=0}=t,a=new Set(o),u=e=>(t,o)=>{if(s&&Bt(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=It(o,u(r)))}if(!r||!((e,t)=>e.some((e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t)))))(r,t)){const e=n?`${t}_`:t;if(Rt.has(e))t=Rt.get(e);else{const r=function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:0,preserveConsecutiveUppercase:0,...t},0===(e=Array.isArray(e)?e.map((e=>e.trim())).filter((e=>e.length)).join("-"):e.trim()).length)return"";const r=0==t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),n=0==t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);return 1===e.length?kt.test(e)?"":t.pascalCase?n(e):r(e):(e!==r(e)&&(e=((e,t,r,n)=>{let o=0,s=0,i=0,a=0;for(let u=0;u<e.length;u++){const l=e[u];a=u>2?"-"===e[u-3]:1,o&&Tt.test(l)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&St.test(l)&&(!a||n)?(e=e.slice(0,u-1)+"-"+e.slice(u-1),i=s,s=0,o=1):(o=t(l)===l&&r(l)!==l,i=s,s=r(l)===l&&t(l)!==l)}return e})(e,r,n,t.preserveConsecutiveUppercase)),e=e.replace(Pt,""),e=t.preserveConsecutiveUppercase?((e,t)=>(_t.lastIndex=0,e.replaceAll(_t,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>(Lt.lastIndex=0,Nt.lastIndex=0,e.replaceAll(Nt,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll(Lt,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&Rt.set(e,r),t=r}}return[t,o]};return It(e,u(void 0))};function Dt(e){return"0x"+e.toString("hex")}const Ft=e=>Array.isArray(e)?e:[e];function qt(e){return He(e,void 0,"be").lt(ue)}const Kt=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>Ut(t[e],r))):Ut(t,r);var t,r};function Vt(e){let t=255;for(;t>=0;){const r=g.concat([e,g.from([t])]),n=bt(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,qt(g.from(n)))return[g.from(n),t];t-=1}return null}function Ht(e){const t=bt.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}class jt extends TypeError{constructor(e,t){let r;const{message:n,explanation:o,...s}=e,{path:i}=e,a=0===i.length?n:`At path: ${i.join(".")} -- ${n}`;super(o??a),null!=o&&(this.cause=a),Object.assign(this,s),this.name=this.constructor.name,this.failures=()=>r??(r=[e,...t()])}}function $t(e){return"object"==typeof e&&null!=e}function zt(e){return $t(e)&&!Array.isArray(e)}function Qt(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Wt(e,t,r,n){if(1==e)return;0==e?e={}:"string"==typeof e&&(e={message:e});const{path:o,branch:s}=t,{type:i}=r,{refinement:a,message:u=`Expected a value of type \`${i}\`${a?` with refinement \`${a}\``:""}, but received: \`${Qt(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*Yt(e,t,r,n){var o;$t(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Wt(o,t,r,n);e&&(yield e)}}function*Jt(e,t,r={}){const{path:n=[],branch:o=[e],coerce:s=0,mask:i=0}=r,a={path:n,branch:o,mask:i};s&&(e=t.coercer(e,a));let u="valid";for(const n of t.validator(e,a))n.explanation=r.message,u="not_valid",yield[n,void 0];for(let[l,c,h]of t.entries(e,a)){const t=Jt(c,h,{path:void 0===l?n:[...n,l],branch:void 0===l?o:[...o,c],coerce:s,mask:i,message:r.message});for(const r of t)r[0]?(u=null!=r[0].refinement?"not_refined":"not_valid",yield[r[0],void 0]):s&&(c=r[1],void 0===l?e=c:e instanceof Map?e.set(l,c):e instanceof Set?e.add(c):$t(e)&&(void 0!==c||l in e)&&(e[l]=c))}if("not_valid"!==u)for(const n of t.refiner(e,a))n.explanation=r.message,u="not_refined",yield[n,void 0];"valid"===u&&(yield[void 0,e])}class Zt{constructor(e){const{type:t,schema:r,validator:n,refiner:o,coercer:s=(e=>e),entries:i=function*(){}}=e;this.type=t,this.schema=r,this.entries=i,this.coercer=s,this.validator=n?(e,t)=>Yt(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>Yt(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=er(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Gt(e,this,t)}is(e){return Xt(e,this)}mask(e,t){return function(e,t,r){const n=er(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return er(e,this,t)}}function Gt(e,t,r){const n=er(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function Xt(e,t){return!er(e,t)[0]}function er(e,t,r={}){const n=Jt(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new jt(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function tr(e,t){return new Zt({type:e,schema:null,validator:t})}function rr(){return tr("any",(()=>1))}function nr(e){return new Zt({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[r,n]of t.entries())yield[r,n,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||`Expected an array value, but received: ${Qt(e)}`})}function or(e){return tr("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${Qt(t)}`))}function sr(e){const t=Qt(e);return new Zt({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${Qt(r)}`})}function ir(e){return new Zt({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function ar(){return tr("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${Qt(e)}`))}function ur(){return tr("string",(e=>"string"==typeof e||`Expected a string, but received: ${Qt(e)}`))}function lr(e){const t=Object.keys(e);return new Zt({type:"type",schema:e,*entries(r){if($t(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>zt(e)||`Expected an object, but received: ${Qt(e)}`,coercer:e=>zt(e)?{...e}:e})}function cr(e){const t=e.map((e=>e.type)).join(" | ");return new Zt({type:"union",schema:null,coercer(t,r){for(const n of e){const[e,o]=n.validate(t,{coerce:1,mask:r.mask});if(!e)return o}return t},validator(r,n){const o=[];for(const t of e){const[...e]=Jt(r,t,n),[s]=e;if(!s[0])return[];for(const[t]of e)t&&o.push(t)}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${Qt(r)}`,...o]}})}function hr(){return tr("unknown",(()=>1))}function dr(e,t,r){return new Zt({...e,coercer:(n,o)=>Xt(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}const pr=dr(or(e.PublicKey),ur(),(t=>new e.PublicKey(t))),fr=dr(or(Array),ur(),(t=>Array.from(new e.PublicKey(t).toBytes()))),mr=dr(or(ae),ur(),(e=>je(e,"base58"))),gr=dr(or(ae),cr([ur(),ar()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return new ae(e)}return new ae(e,10)})),yr=dr(ur(),ur(),(e=>""===e?null:e));function wr(e){return cr([lr({jsonrpc:sr("2.0"),id:ur(),result:e}),lr({jsonrpc:sr("2.0"),id:ur(),error:lr({code:hr(),message:ur(),data:ir(rr())})})])}const vr=wr(hr());function br(e){return dr(wr(e),vr,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:Gt(t.result,e)})))}function Er(e){return br(lr({context:lr({slot:ar()}),value:e}))}const xr=lr({address:ir(fr),hash:mr,data:ir(lr({data:yr,dataHash:mr,discriminator:gr})),lamports:gr,owner:pr,leafIndex:ar(),tree:pr,seq:ir(gr),slotCreated:gr}),Ar=lr({mint:pr,owner:pr,amount:gr,delegate:ir(pr),state:ur()}),Mr=lr({tokenData:Ar,account:xr}),Ir=lr({items:nr(xr)}),Tr=lr({items:nr(xr),cursor:ir(ur())}),Sr=lr({items:nr(Mr),cursor:ir(ur())}),_r=ar(),Cr=ur(),kr=lr({items:nr(lr({signature:ur(),slot:ar(),blockTime:ar(),error:ir(ur())}))}),Pr=lr({items:nr(lr({signature:ur(),slot:ar(),blockTime:ar()})),cursor:ir(ur())}),Lr=lr({hash:mr,leafIndex:ar(),merkleTree:pr,proof:nr(mr),rootSeq:ar(),root:mr}),Nr=lr({address:mr,nextIndex:ar(),merkleTree:pr,proof:nr(mr),rootSeq:ar(),root:mr,lowerRangeAddress:mr,higherRangeAddress:mr,lowElementLeafIndex:ar()}),Or=lr({a:nr(ar()),b:nr(ar()),c:nr(ar())}),Rr=lr({compressedProof:Or,leafIndices:nr(ar()),leaves:nr(mr),rootIndices:nr(ar()),roots:nr(mr),merkleTrees:nr(pr)}),Br=nr(Lr),Ur=lr({amount:gr}),Dr=gr,Fr=lr({balance:gr,mint:pr}),qr=lr({tokenBalances:nr(Fr),cursor:ir(ur())}),Kr=lr({items:nr(Fr),cursor:ir(ur())}),Vr=lr({cursor:ir(ur()),items:nr(lr({balance:gr,owner:pr}))}),Hr=lr({hash:nr(ar()),root:nr(ar()),proof:nr(nr(ar()))}),jr=lr({items:nr(lr({blockTime:ar(),signature:ur(),slot:ar()}))}),$r=lr({items:nr(lr({blockTime:ar(),signature:ur(),slot:ar()})),cursor:ir(ur())}),zr=lr({compressionInfo:lr({closedAccounts:nr(lr({account:xr,optionalTokenData:ir(Ar)})),openedAccounts:nr(lr({account:xr,optionalTokenData:ir(Ar)}))}),transaction:rr()});function Qr(e){const t=Yr(e.ar[0]),r=Yr(e.ar[1]),n=new Uint8Array([...t,...r]),o=Yr(e.bs[0][0]),s=Yr(e.bs[0][1]),i=Yr(e.bs[1][0]),a=Yr(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),l=Yr(e.krs[0]),c=Yr(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...l,...c])}}function Wr(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=Jr(new ae(t.slice(32,64),32,"be"))?0:1;o[0]=Zr(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=ue.div(new ae(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(new ae(a.slice(0,32),32,"be"),new ae(a.slice(32,64),32,"be"));i[0]=Zr(i[0],u);const l=n.slice(0,32),c=n.slice(32,64),h=Jr(new ae(c,32,"be"));return l[0]=Zr(l[0],h),{a:Array.from(o),b:Array.from(i),c:Array.from(l)}}function Yr(e){const t=new ae(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function Jr(e){return e.lte(ue.sub(e))}function Zr(e,t){return t?e:128|e}function Gr(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function Xr(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 en(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 tn(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=Gr(e,t.publicKey,r,o);return i.sign(s),i}async function rn({connection:e,stateTreeLookupTableAddress:t,nullifyTableAddress:r}){const n=await e.getAddressLookupTable(t);if(!n.value)throw new Error("State tree lookup table not found");if(n.value.state.addresses.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");const o=await e.getAddressLookupTable(r);if(!o.value)throw new Error("Nullify table not found");const s=n.value.state.addresses,i=o.value.state.addresses,a=[];for(let e=0;e<s.length;e+=3){const t=s[e];i.includes(t)||a.push({tree:t,queue:s[e+1],cpiContext:s[e+2],treeType:exports.TreeType.State})}return a}function nn(e,t){return Ht([t.toBytes(),...e])}function on(t,r=Ae().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=Vt(Buffer.from([...n,...t]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new e.PublicKey(s)}function sn(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=Tn(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=Tn(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function an(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)}const un=e=>{if(e.lt(He(0)))throw new Error("Insufficient balance for transfer")},ln=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")},cn=(e,t)=>{if(e>0&&t>0){if(8===e)throw new Error(`Invalid number of compressed accounts for proof: ${e}. Allowed numbers: ${[1,2,3,4].join(", ")}`);pn(e,[1,2,3,4],"compressed accounts"),dn(t)}else e>0?hn(e):dn(t)},hn=e=>{pn(e,[1,2,3,4,8],"compressed accounts")},dn=e=>{pn(e,[1,2],"new addresses")},pn=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function fn({discriminator:e,data:t,dataHash:r}){return{discriminator:e.toArray("le",8),data:g.from(t,"base64"),dataHash:r.toArray("le",32)}}async function mn(t,r,n,o=0){var s,i;const a=o?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner",u=o?"delegate":"owner",l=Gt(await wn(t.compressionApiEndpoint,a,{[u]:r.toBase58(),mint:null===(s=n.mint)||void 0===s?void 0:s.toBase58(),limit:null===(i=n.limit)||void 0===i?void 0:i.toNumber(),cursor:n.cursor}),Er(Sr));if("error"in l)throw new e.SolanaJSONRPCError(l.error,`failed to get info for compressed accounts by ${u} ${r.toBase58()}`);if(null===l.result.value)throw new Error("not implemented: NULL result");const c=[],h=await t.getCachedActiveStateTreeInfo();return l.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=An(h,n.tree),i=Qe(We(n.tree,s,n.hash.toArray("be",32),n.leafIndex),n.owner,He(n.lamports),n.data?fn(n.data):void 0,n.address||void 0),a={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=a[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);c.push({compressedAccount:i,parsed:a})})),{items:c.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:l.result.value.cursor}}function gn(e,t){const r=e.account,n=e.optionalTokenData,o=An(t,r.tree),s=Qe(We(r.merkleTree,o,r.hash.toArray("be",32),r.leafIndex),r.owner,He(r.lamports),r.data?fn(r.data):void 0,r.address||void 0);return null===n?{account:s,maybeTokenData:null}:{account:s,maybeTokenData:{mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null}}}function yn(e){return e.replace(/(":\s*)(-?\d+)(\s*[},])/g,((e,t,r,n)=>{const o=Number(r);return!Number.isNaN(o)&&(o>Number.MAX_SAFE_INTEGER||o<Number.MIN_SAFE_INTEGER)?`${t}"${r}"${n}`:e}))}const wn=async(e,t,r=[],n=1,o=0)=>{const s=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:t,params:r});if(o){const t=()=>{const t=s.replace(/"/g,'\\"');return`curl -X POST ${e} \\\n -H "Content-Type: application/json" \\\n -d "${t}"`};console.log("Debug: Stack trace:"),console.log((new Error).stack),console.log("\nDebug: curl:"),console.log(t()),console.log("\n")}const i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:s});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const a=yn(await i.text());return n?Kt(JSON.parse(a)):JSON.parse(a)},vn=async(e,t,r=[],n=0)=>{let o,s="";n&&(s=`Proof generation for method:${t}`,console.time(s)),"inclusion"===t?o=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===t?o=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===t&&(o=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const i=await fetch(`${e}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:o});if(!i.ok)throw new Error(`Error fetching proof: ${i.statusText}`);const a=Wr(Qr(await i.json()));return n&&console.timeEnd(s),a};function bn(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Dt(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>Dt(e))),leaf:Dt(He(e[r].hash))};t.push(n)}return t}function En(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Dt(e[r].root),value:Dt(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>Dt(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:Dt(e[r].leafLowerRangeValue),leafHigherRangeValue:Dt(e[r].leafHigherRangeValue)};t.push(n)}return t}function xn(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return new ae(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}function An(e,t){const r=e.findIndex((e=>e.tree.equals(t)));if(-1===r)throw new Error("No associated queue found for tree. Please set activeStateTreeInfo with latest Tree accounts. If you use custom state trees, set manually.");if(!e[r].queue)throw new Error("Queue must not be null for state tree");return e[r].queue}function Mn(e){const t=e.length,r=Math.floor(Math.random()*t);if(!e[r].queue)throw new Error("Queue must not be null for state tree");return{tree:e[r].tree,queue:e[r].queue}}class In extends e.Connection{constructor(e,t,r,n){super(e,n||"confirmed"),this.activeStateTreeInfo=null,this.compressionApiEndpoint=t,this.proverEndpoint=r}setStateTreeInfo(e){this.activeStateTreeInfo=e}async getCachedActiveStateTreeInfo(){if(Ee(this.rpcEndpoint))return xe();let e=null;if(!this.activeStateTreeInfo){const{mainnet:t,devnet:r}=be();try{e=await rn({connection:this,stateTreeLookupTableAddress:t[0].stateTreeLookupTable,nullifyTableAddress:t[0].nullifyTable}),this.activeStateTreeInfo=e}catch(t){e=await rn({connection:this,stateTreeLookupTableAddress:r[0].stateTreeLookupTable,nullifyTableAddress:r[0].nullifyTable}),this.activeStateTreeInfo=e}}if(!this.activeStateTreeInfo)throw new Error(`activeStateTreeInfo should not be null ${JSON.stringify(this.activeStateTreeInfo)}`);return this.activeStateTreeInfo}async getLatestActiveStateTreeInfo(){return this.activeStateTreeInfo=null,await this.getCachedActiveStateTreeInfo()}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 n=Gt(await wn(this.compressionApiEndpoint,"getCompressedAccount",{hash:r?$e(r):void 0,address:t?$e(t):void 0}),Er(ir(xr)));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===n.result.value)return null;const o=An(await this.getCachedActiveStateTreeInfo(),n.result.value.tree),s=n.result.value;return Qe(We(s.tree,o,s.hash.toArray("be",32),s.leafIndex),s.owner,He(s.lamports),s.data?fn(s.data):void 0,s.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 n=Gt(await wn(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?$e(r):void 0,address:t?$e(t):void 0}),Er(Dr));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get balance for compressed account ${r?r.toString():t?t.toString():""}`);return null===n.result.value?He(0):He(n.result.value)}async getCompressedBalanceByOwner(t){const r=Gt(await wn(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),Er(Dr));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?He(0):He(r.result.value)}async getCompressedAccountProof(t){const r=Gt(await wn(this.compressionApiEndpoint,"getCompressedAccountProof",{hash:$e(t)}),Er(Lr));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proof for compressed account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const n=An(await this.getCachedActiveStateTreeInfo(),r.result.value.merkleTree);return{hash:r.result.value.hash.toArray("be",32),merkleTree:r.result.value.merkleTree,leafIndex:r.result.value.leafIndex,merkleProof:r.result.value.proof,nullifierQueue:n,rootIndex:r.result.value.rootSeq%2400,root:r.result.value.root}}async getMultipleCompressedAccounts(t){const r=Gt(await wn(this.compressionApiEndpoint,"getMultipleCompressedAccounts",{hashes:t.map((e=>$e(e)))}),Er(Ir));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get info for compressed accounts ${t.map((e=>$e(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>$e(e))).join(", ")}`);const n=await this.getCachedActiveStateTreeInfo(),o=[];return r.result.value.items.map((e=>{const t=An(n,e.tree),r=Qe(We(e.tree,t,e.hash.toArray("be",32),e.leafIndex),e.owner,He(e.lamports),e.data?fn(e.data):void 0,e.address||void 0);o.push(r)})),o.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=Gt(await wn(this.compressionApiEndpoint,"getMultipleCompressedAccountProofs",t.map((e=>$e(e)))),Er(nr(Lr)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for compressed accounts ${t.map((e=>$e(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>$e(e))).join(", ")}`);const n=[],o=await this.getCachedActiveStateTreeInfo();for(const e of r.result.value){const t=An(o,e.merkleTree),r={hash:e.hash.toArray("be",32),merkleTree:e.merkleTree,leafIndex:e.leafIndex,merkleProof:e.proof,nullifierQueue:t,rootIndex:e.rootSeq%2400,root:e.root};n.push(r)}return n}async getCompressedAccountsByOwner(t,r){var n;const o=Gt(await wn(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===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),Er(Tr));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===o.result.value)return{items:[],cursor:null};const s=[],i=await this.getCachedActiveStateTreeInfo();return o.result.value.items.map((e=>{const t=An(i,e.tree),r=Qe(We(e.tree,t,e.hash.toArray("be",32),e.leafIndex),e.owner,He(e.lamports),e.data?fn(e.data):void 0,e.address||void 0);s.push(r)})),{items:s.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:o.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await mn(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await mn(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=Gt(await wn(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:$e(t)}),Er(Ur));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed token account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get balance for compressed token account ${t.toString()}`);return{amount:He(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var n,o;r||(r={});const s=Gt(await wn(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),Er(qr));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);return{items:r.mint?s.result.value.tokenBalances.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.tokenBalances,cursor:s.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(t,r){var n,o;r||(r={});const s=Gt(await wn(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),Er(Kr));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);const i=r.mint?s.result.value.items.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.items;return{context:s.result.context,value:{items:i,cursor:s.result.value.cursor}}}async getCompressionSignaturesForAccount(t){const r=Gt(await wn(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:$e(t)}),Er(jr));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get signatures for compressed account ${t.toString()}`);return r.result.value.items}async getTransactionWithCompressionInfo(t){const r=Gt(await wn(this.compressionApiEndpoint,"getTransactionWithCompressionInfo",{signature:t}),br(zr));if("error"in r)throw new e.SolanaJSONRPCError(r.error,"failed to get slot");if(null===r.result.transaction)return null;const n=[],o=[],s=await this.getCachedActiveStateTreeInfo();r.result.compressionInfo.closedAccounts.map((e=>{n.push(gn(e,s))})),r.result.compressionInfo.openedAccounts.map((e=>{o.push(gn(e,s))}));const i=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},a=i(n),u=i(o);return{compressionInfo:{closedAccounts:n,openedAccounts:o,preTokenBalances:a,postTokenBalances:u},transaction:r.result.transaction}}async getCompressionSignaturesForAddress(t,r){var n;const o=Gt(await wn(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),Er($r));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for address ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for address ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForOwner(t,r){var n;const o=Gt(await wn(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),Er($r));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForTokenOwner(t,r){var n;const o=Gt(await wn(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),Er($r));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getIndexerHealth(){const t=Gt(await wn(this.compressionApiEndpoint,"getIndexerHealth"),br(Cr));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.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=Gt(await wn(this.compressionApiEndpoint,"getIndexerSlot"),br(_r));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get slot");return t.result}async getCompressedMintTokenHolders(t,r){var n;const o=Gt(await wn(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),Er(Vr));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get mint token holders");return o.result}async getLatestCompressionSignatures(t,r){const n=Gt(await wn(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),Er(Pr));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getLatestNonVotingSignatures(t,r){const n=Gt(await wn(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),Er(kr));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getMultipleNewAddressProofs(t){const r=Gt(await wn(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>$e(e)))),Er(nr(Nr)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>$e(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>$e(e))).join(", ")}`);const n=[];for(const e of r.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:He(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:He(e.lowElementLeafIndex),merkleTree:e.merkleTree,nullifierQueue:Ae().addressQueue};n.push(t)}return n}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=bn(t);r={compressedProof:await vn(this.proverEndpoint,"inclusion",n,0),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>He(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=En(e);r={compressedProof:await vn(this.proverEndpoint,"new-address",n,0),roots:e.map((e=>e.root)),rootIndices:e.map((e=>e.rootIndex)),leafIndices:e.map((e=>e.nextIndex.toNumber())),leaves:e.map((e=>He(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=bn(n),s=await this.getMultipleNewAddressProofs(t),i=En(s);r={compressedProof:await vn(this.proverEndpoint,"combined",[o,i],0),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=>He(e.hash))).concat(s.map((e=>He(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=await this.getMultipleCompressedAccounts(e),n=r.map((e=>e.merkleTree)),o=r.map((e=>e.nullifierQueue)),s=Ae().addressTree,i=Ae().addressQueue,a=e.map(((e,t)=>({hash:e,tree:n[t],queue:o[t]}))),u=t.map((e=>({address:e,tree:s,queue:i})));return this.getValidityProofV0(a,u)}async getValidityProofV0(e=[],t=[]){const{value:r}=await this.getValidityProofAndRpcContext(e,t);return r}async getValidityProofAndRpcContext(t=[],r=[]){cn(t.length,r.length);const n=Gt(await wn(this.compressionApiEndpoint,"getValidityProof",{hashes:t.map((({hash:e})=>$e(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:$e(e),tree:t.toBase58()})))}),Er(Rr));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const o=n.result.value;if(null===o)throw new Error(`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);return{value:{compressedProof:o.compressedProof,merkleTrees:o.merkleTrees,leafIndices:o.leafIndices,nullifierQueues:[...t.map((({queue:e})=>e)),...r.map((({queue:e})=>e))],rootIndices:o.rootIndices,roots:o.roots,leaves:o.leaves},context:n.result.context}}}function Tn(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function Sn(e,t,r,n=[]){if(t<=0)return[];if(void 0===e){if(0===r.length){if(n.length>0)return new Array(t).fill(Mn(n).tree);throw new Error("No input compressed accounts, output state trees, or active tree bundles passed. Please pass a valid outputStateMerkleTree pubkey into the instruction builder.")}const e=r[0].merkleTree;return n.length>0&&!n.some((t=>t.tree.equals(e)))?new Array(t).fill(Mn(n).tree):new Array(t).fill(e)}{const r=Ft(e);return r.length>=t?r.slice(0,t):r.concat(new Array(t-r.length).fill(r[0]))}}function _n(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function Cn(e,t,r,n,o=[],s){const i=o.slice(),a=[],u=[];if(e.forEach(((e,r)=>{const n=Tn(i,e.merkleTree),o=Tn(i,e.nullifierQueue);a.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})})),void 0===n&&0===e.length)throw new Error("No input compressed accounts nor output state trees provided. Please pass in at least one of the following: outputStateMerkleTree or inputCompressedAccount");const l=Sn(n,r.length,e,s);return r.forEach(((e,t)=>{const r=Tn(i,l[t]);u.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:a,packedOutputCompressedAccounts:u,remainingAccounts:i}}var kn={},Pn={};class Ln{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}decode(e,t){throw new Error("Layout is abstract")}encode(e,t,r){throw new Error("Layout is abstract")}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function Nn(e,t){return t.property?e+"["+t.property+"]":e}Pn.Layout=Ln,Pn.nameWithProperty=Nn,Pn.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(e.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof Ln))throw new TypeError("layout must be a Layout");if(t.hasOwnProperty("boundConstructor_"))throw new Error("layout is already bound to a constructor");e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=()=>new e,Object.defineProperty(e.prototype,"encode",{value:function(e,r){return t.encode(this,e,r)},writable:1}),Object.defineProperty(e,"decode",{value:function(e,r){return t.decode(e,r)},writable:1})};class On extends Ln{isCount(){throw new Error("ExternalLayout is abstract")}}class Rn extends On{constructor(e,t){if(void 0===e&&(e=1),!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t){void 0===t&&(t=0);const r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}}class Bn extends On{constructor(e,t,r){if(!(e instanceof Ln))throw new TypeError("layout must be a Layout");if(void 0===t)t=0;else if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof Un||this.layout instanceof Dn}decode(e,t){return void 0===t&&(t=0),this.layout.decode(e,t+this.offset)}encode(e,t,r){return void 0===r&&(r=0),this.layout.encode(e,t,r+this.offset)}}class Un extends Ln{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntLE(e,r,this.span),this.span}}class Dn extends Ln{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntBE(e,r,this.span),this.span}}class Fn extends Ln{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntLE(e,r,this.span),this.span}}class qn extends Ln{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntBE(e,r,this.span),this.span}}const Kn=Math.pow(2,32);function Vn(e){const t=Math.floor(e/Kn);return{hi32:t,lo32:e-t*Kn}}function Hn(e,t){return e*Kn+t}class jn extends Ln{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Hn(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Vn(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class $n extends Ln{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Hn(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Vn(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class zn extends Ln{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Hn(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Vn(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Qn extends Ln{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Hn(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Vn(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Wn extends Ln{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatLE(e,r),4}}class Yn extends Ln{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatBE(e,r),4}}class Jn extends Ln{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleLE(e,r),8}}class Zn extends Ln{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleBE(e,r),8}}class Gn extends Ln{constructor(e,t,r){if(!(e instanceof Ln))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof On&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(t instanceof On)&&0<e.span&&(n=t*e.span),super(n,r),this.elementLayout=e,this.count=t}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0,n=this.count;if(n instanceof On&&(n=n.decode(e,t)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let o=0;for(;o<n;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t){void 0===t&&(t=0);const r=[];let n=0,o=this.count;for(o instanceof On&&(o=o.decode(e,t));n<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),n+=1;return r}encode(e,t,r){void 0===r&&(r=0);const n=this.elementLayout,o=e.reduce(((e,o)=>e+n.encode(o,t,r+e)),0);return this.count instanceof On&&this.count.encode(e.length,t,r),o}}class Xn extends Ln{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof Ln),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===r&&(r=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(n,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;try{r=this.fields.reduce(((r,n)=>{const o=n.getSpan(e,t);return t+=o,r+o}),0)}catch(e){throw new RangeError("indeterminate span")}return r}decode(e,t){void 0===t&&(t=0);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(e,t)),t+=n.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r){void 0===r&&(r=0);const n=r;let o=0,s=0;for(const n of this.fields){let i=n.span;if(s=0<i?i:0,void 0!==n.property){const o=e[n.property];void 0!==o&&(s=n.encode(o,t,r),0>i&&(i=n.getSpan(t,r)))}o=r,r+=i}return o+s-n}fromArray(e){const t=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}}class eo{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class to extends eo{constructor(e,t){if(!(e instanceof On&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}}class ro extends Ln{constructor(e,t,r){const n=e instanceof Un||e instanceof Dn;if(n)e=new to(new Bn(e));else if(e instanceof On&&e.isCount())e=new to(e);else if(!(e instanceof eo))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof Ln))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&n&&(o+=e.layout.span)),super(o,r),this.discriminator=e,this.usesPrefixDiscriminator=n,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return s(e)},this.configGetSourceVariant=function(e){s=e.bind(this)}}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);const r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(e.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&e.hasOwnProperty(this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||e.hasOwnProperty(t.property)))return t}else for(const t in this.registry){const r=this.registry[t];if(e.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(e,t){let r;void 0===t&&(t=0);const n=this.discriminator,o=n.decode(e,t);let s=this.registry[o];if(void 0===s){let i=0;s=this.defaultLayout,this.usesPrefixDiscriminator&&(i=n.layout.span),r=this.makeDestinationObject(),r[n.property]=o,r[s.property]=this.defaultLayout.decode(e,t+i)}else r=s.decode(e,t);return r}encode(e,t,r){void 0===r&&(r=0);const n=this.getSourceVariant(e);if(void 0===n){const n=this.discriminator,o=this.defaultLayout;let s=0;return this.usesPrefixDiscriminator&&(s=n.layout.span),n.encode(e[n.property],t,r),s+o.encode(e[o.property],t,r+s)}return n.encode(e,t,r)}addVariant(e,t,r){const n=new no(this,e,t,r);return this.registry[e]=n,n}getVariant(e,t){let r=e;return Buffer.isBuffer(e)&&(void 0===t&&(t=0),r=this.discriminator.decode(e,t)),this.registry[r]}}class no extends Ln{constructor(e,t,r,n){if(!(e instanceof ro))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof Ln))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,n),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(e,t+r)}decode(e,t){const r=this.makeDestinationObject();if(void 0===t&&(t=0),this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+n):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!e.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=n;if(this.layout&&(this.layout.encode(e[this.property],t,r+n),o+=this.layout.getSpan(t,r+n),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function oo(e){return 0>e&&(e+=4294967296),e}class so extends Ln{constructor(e,t,r){if(!(e instanceof Un||e instanceof Dn))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===r&&(r=t,t=void 0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let n=0;this._packedSetValue=function(e){return n=oo(e),this},this._packedGetValue=function(){return n}}decode(e,t){const r=this.makeDestinationObject();void 0===t&&(t=0);const n=this.word.decode(e,t);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(n));return r}encode(e,t,r){void 0===r&&(r=0);const n=this.word.decode(t,r);this._packedSetValue(n);for(const t of this.fields)if(void 0!==t.property){const r=e[t.property];void 0!==r&&t.encode(r)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){const r=new io(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new ao(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}class io{constructor(e,t,r){if(!(e instanceof so))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const n=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>n)throw new Error("bits too long for span remainder ("+(n-o)+" of "+n+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=n-o-t),this.wordMask=oo(this.valueMask<<this.start),this.property=r}decode(){return oo(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==oo(e&this.valueMask))throw new TypeError(Nn("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=oo(e<<this.start);this.container._packedSetValue(oo(t&~this.wordMask)|r)}}class ao extends io{constructor(e,t){super(e,1,t)}decode(e,t){return!!io.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),io.prototype.encode.call(this,e)}}class uo extends Ln{constructor(e,t){if(!(e instanceof On&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof On||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t){void 0===t&&(t=0);let r=this.span;return 0>r&&(r=this.length.decode(e,t)),e.slice(t,t+r)}encode(e,t,r){let n=this.length;if(this.length instanceof On&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(Nn("Blob.encode",this)+" requires (length "+n+") Buffer as src");if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return t.write(e.toString("hex"),r,n,"hex"),this.length instanceof On&&this.length.encode(n,t,r),n}}class lo extends Ln{constructor(e){super(-1,e)}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");void 0===t&&(t=0);let r=t;for(;r<e.length&&0!==e[r];)r+=1;return 1+r-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);return e.slice(t,t+n-1).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),t[r+o]=0,o+1}}class co extends Ln{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");return void 0===t&&(t=0),e.length-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return e.slice(t,t+n).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),o}}class ho extends Ln{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}Pn.ExternalLayout=On,Pn.GreedyCount=Rn,Pn.OffsetLayout=Bn,Pn.UInt=Un,Pn.UIntBE=Dn,Pn.Int=Fn,Pn.IntBE=qn,Pn.Float=Wn,Pn.FloatBE=Yn,Pn.Double=Jn,Pn.DoubleBE=Zn,Pn.Sequence=Gn,Pn.Structure=Xn,Pn.UnionDiscriminator=eo,Pn.UnionLayoutDiscriminator=to,Pn.Union=ro,Pn.VariantLayout=no,Pn.BitStructure=so,Pn.BitField=io,Pn.Boolean=ao,Pn.Blob=uo,Pn.CString=lo,Pn.UTF8=co,Pn.Constant=ho,Pn.greedy=(e,t)=>new Rn(e,t),Pn.offset=(e,t,r)=>new Bn(e,t,r),Pn.u8=e=>new Un(1,e),Pn.u16=e=>new Un(2,e),Pn.u24=e=>new Un(3,e),Pn.u32=e=>new Un(4,e),Pn.u40=e=>new Un(5,e),Pn.u48=e=>new Un(6,e),Pn.nu64=e=>new jn(e),Pn.u16be=e=>new Dn(2,e),Pn.u24be=e=>new Dn(3,e),Pn.u32be=e=>new Dn(4,e),Pn.u40be=e=>new Dn(5,e),Pn.u48be=e=>new Dn(6,e),Pn.nu64be=e=>new $n(e),Pn.s8=e=>new Fn(1,e),Pn.s16=e=>new Fn(2,e),Pn.s24=e=>new Fn(3,e),Pn.s32=e=>new Fn(4,e),Pn.s40=e=>new Fn(5,e),Pn.s48=e=>new Fn(6,e),Pn.ns64=e=>new zn(e),Pn.s16be=e=>new qn(2,e),Pn.s24be=e=>new qn(3,e),Pn.s32be=e=>new qn(4,e),Pn.s40be=e=>new qn(5,e),Pn.s48be=e=>new qn(6,e),Pn.ns64be=e=>new Qn(e),Pn.f32=e=>new Wn(e),Pn.f32be=e=>new Yn(e),Pn.f64=e=>new Jn(e),Pn.f64be=e=>new Zn(e),Pn.struct=(e,t,r)=>new Xn(e,t,r),Pn.bits=(e,t,r)=>new so(e,t,r),Pn.seq=(e,t,r)=>new Gn(e,t,r),Pn.union=(e,t,r)=>new ro(e,t,r),Pn.unionLayoutDiscriminator=(e,t)=>new to(e,t),Pn.blob=(e,t)=>new uo(e,t),Pn.cstr=e=>new lo(e),Pn.utf8=(e,t)=>new co(e,t),Pn.const=(e,t)=>new ho(e,t),function(t){var r=ee&&ee.__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 n=Pn,o=e,s=r(ie);var i=Pn;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return i.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return i.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return i.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return i.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return i.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return i.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return i.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return i.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return i.struct}});class a extends n.Layout{constructor(e,t,r){super(e,r),this.blob=(0,n.blob)(e),this.signed=t}decode(e,t=0){const r=new s.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 u(e){return new a(8,0,e)}t.u64=u,t.i64=function(e){return new a(8,1,e)},t.u128=function(e){return new a(16,0,e)},t.i128=function(e){return new a(16,1,e)},t.u256=function(e){return new a(32,0,e)},t.i256=function(e){return new a(32,1,e)};class l extends n.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 l((0,n.blob)(32),(e=>new o.PublicKey(e)),(e=>e.toBuffer()),e)};class c extends n.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,n.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 h(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function d(e){return e?1:0}function p(e){const t=(0,n.u32)("length"),r=(0,n.struct)([t,(0,n.blob)((0,n.offset)(t,-t.span),"data")]);return new l(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new c(e,t)},t.bool=function(e){return new l((0,n.u8)(),h,d,e)},t.vec=function(e,t){const r=(0,n.u32)("length"),o=(0,n.struct)([r,(0,n.seq)(e,(0,n.offset)(r,-r.span),"values")]);return new l(o,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const o=(0,n.struct)([u("tag"),t.replicate("data")]);return new l(o,(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=p,t.str=function(e){return new l(p(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const o=(0,n.union)(null!=r?r:(0,n.u8)(),t);return e.forEach(((e,t)=>o.addVariant(t,e,e.property))),o},t.array=function(e,t,r){const o=(0,n.struct)([(0,n.seq)(e,t,"values")]);return new l(o,(({values:e})=>e),(e=>({values:e})),r)};class f extends n.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 o=(0,n.u32)("length"),s=(0,n.struct)([o,(0,n.seq)(new f(e,t),(0,n.offset)(o,-o.span),"values")]);return new l(s,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(kn);const po=kn.struct([kn.publicKey("owner"),kn.u64("lamports"),kn.option(kn.array(kn.u8(),32),"address"),kn.option(kn.struct([kn.array(kn.u8(),8,"discriminator"),kn.vecU8("data"),kn.array(kn.u8(),32,"dataHash")]),"data")],"compressedAccount"),fo=kn.struct([kn.u8("merkleTreePubkeyIndex"),kn.u8("nullifierQueuePubkeyIndex"),kn.u32("leafIndex"),kn.option(kn.struct([kn.u8("queueId"),kn.u16("index")]),"queueIndex")],"merkleContext"),mo=kn.struct([kn.array(kn.u8(),32,"seed"),kn.u8("addressQueueAccountIndex"),kn.u8("addressMerkleTreeAccountIndex"),kn.u16("addressMerkleTreeRootIndex")],"newAddressParams"),go=kn.struct([kn.option(kn.struct([kn.array(kn.u8(),32,"a"),kn.array(kn.u8(),64,"b"),kn.array(kn.u8(),32,"c")]),"proof"),kn.vec(kn.struct([po,fo,kn.u16("rootIndex"),kn.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),kn.vec(kn.struct([po,kn.u8("merkleTreeIndex")]),"outputCompressedAccounts"),kn.option(kn.u64(),"relayFee"),kn.vec(mo,"newAddressParams"),kn.option(kn.u64(),"compressOrDecompressLamports"),kn.bool("isCompress")]);function yo(e){const t=g.alloc(1e3),r=go.encode(e,t),n=g.from(t.slice(0,r)),o=g.alloc(4);return o.writeUInt32LE(r,0),g.concat([he,o,n])}const wo=kn.struct([kn.option(kn.struct([kn.array(kn.u8(),32,"a"),kn.array(kn.u8(),64,"b"),kn.array(kn.u8(),32,"c")]),"proof"),kn.vec(mo,"newAddressParams"),kn.vec(kn.struct([po,fo,kn.u16("rootIndex"),kn.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),kn.vec(kn.struct([po,kn.u8("merkleTreeIndex")]),"outputCompressedAccounts"),kn.option(kn.u64(),"relayFee"),kn.option(kn.u64(),"compressOrDecompressLamports"),kn.bool("isCompress"),kn.option(kn.struct([kn.bool("set_context"),kn.bool("first_set_context"),kn.u8("cpi_context_account_index")]),"compressedCpiContext")]);function vo(e){return go.decode(e.slice(he.length+4))}function bo(e){return wo.decode(e.slice(de.length+4))}const Eo=e=>{const t=No.programId,{feePayer:r,authority:n,registeredProgramPda:o,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:l,systemProgram:c}=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:c,isSigner:0,isWritable:0}]},xo=kn.struct([kn.vec(kn.array(kn.u8(),32),"inputCompressedAccountHashes"),kn.vec(kn.array(kn.u8(),32),"outputCompressedAccountHashes"),kn.vec(kn.struct([kn.struct([kn.publicKey("owner"),kn.u64("lamports"),kn.option(kn.array(kn.u8(),32),"address"),kn.option(kn.struct([kn.array(kn.u8(),8,"discriminator"),kn.vecU8("data"),kn.array(kn.u8(),32,"dataHash")]),"data")],"compressedAccount"),kn.u8("merkleTreeIndex")]),"outputCompressedAccounts"),kn.vec(kn.u32(),"outputLeafIndices"),kn.vec(kn.struct([kn.publicKey("pubkey"),kn.u64("seq")]),"sequenceNumbers"),kn.option(kn.u64(),"relayFee"),kn.bool("isCompress"),kn.option(kn.u64(),"compressOrDecompressLamports"),kn.vec(kn.publicKey(),"pubkeyArray"),kn.option(kn.vecU8(),"message")]);function Ao(e){return xo.decode(e)}const Mo=kn.struct([kn.u8("is_invoked_by_program"),kn.u8("bump"),kn.u8("num_queues"),kn.u8("num_output_queues"),kn.u8("start_output_appends"),kn.u8("num_address_queues"),kn.array(kn.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),Io=kn.struct([kn.u8("index"),kn.array(kn.u8(),32,"leaf")],"appendLeavesInput"),To=kn.struct([kn.array(kn.u8(),32,"account_hash"),kn.u32("leaf_index"),kn.u8("prove_by_index"),kn.u8("tree_index"),kn.u8("queue_index")],"insertNullifierInput"),So=kn.struct([kn.array(kn.u8(),32,"address"),kn.u8("tree_index"),kn.u8("queue_index")],"insertAddressInput"),_o=kn.struct([kn.publicKey("pubkey"),kn.u64("seq")],"merkleTreeSequenceNumber");function Co(e){let t=0;const r=Mo.decode(e,t);t+=Mo.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=Io.decode(e,t);o.push(r),t+=Io.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=To.decode(e,t);i.push(r),t+=To.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=So.decode(e,t);u.push(r),t+=So.span}const l=e.readUInt8(t);t+=1;const c=[];for(let r=0;r<l;r++){const r=_o.decode(e,t);c.push(r),t+=_o.span}const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)_o.decode(e,t),t+=_o.span;const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)_o.decode(e,t),t+=_o.span;const p=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<p;r++){const r=kn.u32().decode(e,t);f.push(r),t+=4}return{meta:r,leaves:o,nullifiers:i,addresses:u,sequence_numbers:c,output_leaf_indices:f}}function ko(t,r,n){const o=e=>Array.from(e instanceof g?new Uint8Array(e):e);return{inputCompressedAccountHashes:t.nullifiers.map((e=>o(e.account_hash))),outputCompressedAccountHashes:t.leaves.map((e=>o(e.leaf))),outputCompressedAccounts:t.leaves.map(((t,r)=>{var s,i,a,u,l,c;return{compressedAccount:{owner:new e.PublicKey((null===(s=null==n?void 0:n.outputCompressedAccounts[r])||void 0===s?void 0:s.compressedAccount.owner)||e.PublicKey.default),lamports:new ie.BN((null===(i=null==n?void 0:n.outputCompressedAccounts[r])||void 0===i?void 0:i.compressedAccount.lamports)||0),address:null==n?void 0:n.outputCompressedAccounts[r].compressedAccount.address,data:(null===(a=null==n?void 0:n.outputCompressedAccounts[r])||void 0===a?void 0:a.compressedAccount.data)?{discriminator:o(g.from(null===(u=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===u?void 0:u.discriminator)),data:null!==(l=o(g.from(n.outputCompressedAccounts[r].compressedAccount.data.data)))&&void 0!==l?l:[],dataHash:o(g.from(null===(c=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===c?void 0:c.dataHash))}:null},merkleTreeIndex:t.index}})),outputLeafIndices:t.output_leaf_indices,sequenceNumbers:t.sequence_numbers.map((t=>({pubkey:new e.PublicKey(t.pubkey),seq:new ie.BN(t.seq)}))),pubkeyArray:r.slice(2).filter((t=>!t.equals(e.PublicKey.default))),isCompress:(null==n?void 0:n.isCompress)||0,relayFee:(null==n?void 0:n.relayFee)?new ie.BN(n.relayFee):null,compressOrDecompressLamports:(null==n?void 0:n.compressOrDecompressLamports)?new ie.BN(n.compressOrDecompressLamports):null,message:null}}const Po=e=>e.reduce(((e,t)=>e.add(He(t.lamports))),He(0)),Lo=g.from("sol_pool_pda");class No{constructor(){}static deriveCompressedSolPda(){const t=[Lo],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=He(r);const n=Po(e).sub(r);return un(n),n.eq(He(0))?[ze(t,r)]:(ln(e),[ze(e[0].owner,n),ze(t,r)])}static createDecompressOutputState(e,t){t=He(t);const r=Po(e).sub(t);return un(r),r.eq(He(0))?[]:(ln(e),[ze(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=He(null!=r?r:0);const o=Po(null!=n?n:[]).sub(r);return un(o),o.eq(He(0))||!n?[ze(t,r,void 0,e)]:(ln(n),[ze(n[0].owner,o),ze(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:c,packedOutputCompressedAccounts:h,remainingAccounts:d}=Cn(null!=i?i:[],null!=a?a:[],l,s),{newAddressParamsPacked:p,remainingAccounts:f}=sn([r],d),m=yo({proof:o,inputCompressedAccountsWithMerkleContext:c,outputCompressedAccounts:h,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),g=[...Eo(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),..._n(f)];return new e.TransactionInstruction({programId:this.programId,keys:g,data:m})}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:c,remainingAccounts:h}=Cn(r,s,u,a),d=yo({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),p=[...Eo(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),..._n(h)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTree:o}){n=He(n);const s=ze(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=Cn([],[],[s],o),l=yo({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),c=[...Eo(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:No.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),..._n(u)];return new e.TransactionInstruction({programId:this.programId,keys:c,data:l})}static async decompress({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i,outputStateTree:a}){o=He(o);const u=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:c,remainingAccounts:h}=Cn(r,s,u,a),d=yo({proof:i,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),p=[...Eo(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:No.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),..._n(h)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}}function Oo(e,t){let r=He(0);t=He(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(He(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(He(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}function Ro(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}var Bo,Uo,Do,Fo,qo,Ko,Vo,Ho;No.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"),exports.UtxoErrorCode=void 0,(Bo=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",Bo.NOT_U64="NOT_U64",Bo.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(Uo=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",Uo.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(Do=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",Do.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",Do.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(Fo=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",Fo.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",Fo.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",Fo.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(qo=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",qo.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,(Ko=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",Ko.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",Ko.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(Vo=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",Vo.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",Vo.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",Vo.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",Vo.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",Vo.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(Ho=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",Ho.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",Ho.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",Ho.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",Ho.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",Ho.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",Ho.INVALID_NUMBER="INVALID_NUMBER";class jo extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}class $o{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([He(this.value.toArray("be",32)).toString(),He(this.nextIndex).toString(),He(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class zo{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class Qo{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new Qo([new $o(0,He(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=le;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([He(r.value.toArray("be",32)).toString(),He(r.nextIndex).toString(),He(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 $o(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new zo(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 Wo{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 Yo(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=ve(),o=(await e.getConfirmedSignaturesForAddress2(n,void 0,"confirmed")).map((e=>e.signature)),s=await e.getParsedTransactions(o,{maxSupportedTransactionVersion:0,commitment:"confirmed"});for(const r of s){if(!r||!r.transaction||!r.meta)continue;if(!r.meta.innerInstructions||0==r.meta.innerInstructions.length)continue;const n=r.transaction.message.accountKeys.map((e=>e.pubkey)),o=[],s=await e.getTransaction(r.transaction.signatures[0],{commitment:"confirmed",maxSupportedTransactionVersion:0});for(const e of(null==s?void 0:s.transaction.message.compiledInstructions)||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===ce.length&&ce.every(((e,r)=>e===t[r])))continue;o.push(t)}const i=[];if(s.meta.innerInstructions&&s.meta.innerInstructions.length>0)for(const e of s.meta.innerInstructions)for(const t of e.instructions){const e=t.accounts.map((e=>n[e]));if(i.push(e),t.data&&t.data.length>0){const e=Ve.decode(t.data);o.push(e)}}const a=Go(o,i);a&&t.push(a)}if(t.length>0)return t;const i=s.filter((e=>e?e.transaction.message.accountKeys.some((e=>("string"==typeof e?e:e.pubkey.toBase58())===r.toBase58())):0));return Jo(i,Zo)}const Jo=(e,t)=>{const{noopProgram:r}=ve(),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=Ve.decode(s.data),o=t(g.from(r),e);null!=o&&n.push(o)}}}))})),n},Zo=e=>{const t=g.from(e.map((e=>e)));try{return Ao(t)}catch(e){return console.error("Error deserializing event:",e),null}};function Go(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=Ve.encode(e),s=Ve.encode(he),i=Ve.encode(de);if(o===s){n=vo(g.from(t)),r=1;break}if(o==i){n=bo(g.from(t)),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if(Ve.encode(e)!==Ve.encode(pe))console.log("discriminator does not match");else{const e=t.slice(12);o=Co(g.from(e))}}return n?ko(o,t[t.length-1],n):null}async function Xo(e,t){return(await es(e)).find((e=>He(e.hash).eq(t)))}async function es(e){var t,r;const n=(await Yo(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:Ae().merkleTree,nullifierQueue:Ae().nullifierQueue,hash:e.outputCompressedAccountHashes[n],leafIndex:e.outputLeafIndices[n]},a=Qe(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(He(r))}}const i=o.filter((e=>!s.some((t=>t.eq(He(e.hash))))));return i.sort(((e,t)=>t.leafIndex-e.leafIndex)),i}const ts=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),rs=kn.struct([kn.publicKey("mint"),kn.publicKey("owner"),kn.u64("amount"),kn.option(kn.publicKey(),"delegate"),kn.u8("state"),kn.option(kn.vecU8(),"tlv")]);function ns(e,t=ts){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 rs.decode(Buffer.from(r))}async function os(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:Ae().nullifierQueue,hash:r[o],leafIndex:e.outputLeafIndices[o]};if(!n.compressedAccount.data)throw new Error("No data");const a=ns(n.compressedAccount);if(!a)throw new Error("Invalid token data");return{compressedAccount:Qe(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 ss(e,t,r){const n=await Yo(e);return{items:(await os(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 is(e,t,r){const n=await Yo(e);return{items:(await os(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 as(e,t){const r=await Yo(e),n=(await os(r)).filter((e=>He(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class us extends e.Connection{constructor(e,t,r,n,o,s){super(e,o||"confirmed"),this.log=0,this.activeStateTreeInfo=null,this.compressionApiEndpoint=r,this.proverEndpoint=n;const{merkleTreeAddress:i,nullifierQueueAddress:a,depth:u,log:l,addressTreeAddress:c,addressQueueAddress:h}=null!=s?s:{},{merkleTree:d,nullifierQueue:p,merkleTreeHeight:f,addressQueue:m,addressTree:g}=Ae();this.lightWasm=t,this.merkleTreeAddress=null!=i?i:d,this.nullifierQueueAddress=null!=a?a:p,this.addressTreeAddress=null!=c?c:g,this.addressQueueAddress=null!=h?h:m,this.depth=null!=u?u:f,this.log=null!=l?l:0}setStateTreeInfo(e){this.activeStateTreeInfo=e}async getCachedActiveStateTreeInfo(){return xe()}async getLatestActiveStateTreeInfo(){return xe()}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 Xo(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 Xo(this,t);if(!r)throw new Error("Account not found");return He(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),He(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await es(e)).filter((e=>t.some((t=>He(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(e){const t=await Yo(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 Wo(this.depth,this.lightWasm,r.map((e=>He(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=>He(e))),a=He(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=He(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 es(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 ss(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await is(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await as(this,e);return{amount:He(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await ss(this,e,t.mint)).items.map((e=>({balance:He(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await ss(this,e,t.mint)).items.map((e=>({balance:He(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=Qo.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(He(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(He(r))}const o=new Wo(this.depth,this.lightWasm,n.map((e=>He(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=>He(e))),u=t.get(n.nextIndex).value,l={root:He(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:He(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:He(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 ae))))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 ae))))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=bn(t);r={compressedProof:await vn(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=>He(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=En(e);r={compressedProof:await vn(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=>He(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=bn(n),s=await this.getMultipleNewAddressProofs(t),i=En(s);r={compressedProof:await vn(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=>He(e.hash))).concat(s.map((e=>He(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)))}}let ls=1;const cs=fs(255),hs=fs(254),ds=fs(253),ps=fs(252);function fs(t){if(t||(t=ls,ls++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}exports.ADDRESS_QUEUE_ROLLOVER_FEE=Fe,exports.ADDRESS_TREE_NETWORK_FEE=Ke,exports.ALICE=cs,exports.AccountProofResult=Hr,exports.AppendLeavesInputLayout=Io,exports.AppendNullifyCreateAddressInputsMetaLayout=Mo,exports.BOB=hs,exports.BalanceResult=Ur,exports.CHARLIE=ds,exports.COMPUTE_BUDGET_PATTERN=ce,exports.CompressedAccountLayout=po,exports.CompressedAccountResult=xr,exports.CompressedAccountsByOwnerResult=Tr,exports.CompressedMintTokenHoldersResult=Vr,exports.CompressedTokenAccountResult=Mr,exports.CompressedTokenAccountsByOwnerOrDelegateResult=Sr,exports.CompressedTransactionResult=zr,exports.CreateUtxoError=class extends jo{},exports.DAVE=ps,exports.DEFAULT_MERKLE_TREE_HEIGHT=Be,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=ue,exports.HIGHEST_ADDRESS_PLUS_ONE=le,exports.HashError=class extends jo{},exports.HealthResult=Cr,exports.IDL={version:"1.2.0",name:"light_system_program",constants:[{name:"SOL_POOL_PDA_SEED",type:"bytes",value:"[115, 111, 108, 95, 112, 111, 111, 108, 95, 112, 100, 97]"}],instructions:[{name:"initCpiContextAccount",accounts:[{name:"feePayer",isMut:1,isSigner:1},{name:"cpiContextAccount",isMut:1,isSigner:0},{name:"associatedMerkleTree",isMut:0,isSigner:0}],args:[]},{name:"invoke",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpi",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpiWithReadOnly",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"InstructionDataInvoke"}},{name:"inputs2",type:{defined:"InstructionDataInvokeCpi"}},{name:"inputs3",type:{defined:"PublicTransactionEvent"}}]}],accounts:[{name:"cpiContextAccount",docs:["Collects instruction data without executing a compressed transaction.","Signer checks are performed on instruction data.","Collected instruction data is combined with the instruction data of the executing cpi,","and executed as a single transaction.","This enables to use input compressed accounts that are owned by multiple programs,","with one zero-knowledge proof."],type:{kind:"struct",fields:[{name:"feePayer",type:"publicKey"},{name:"associatedMerkleTree",type:"publicKey"},{name:"context",type:{vec:{defined:"InstructionDataInvokeCpi"}}}]}}],types:[{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"nullifierQueuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"queueIndex",type:{option:{defined:"QueueIndex"}}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"SumCheckFailed",msg:"Sum check failed"},{code:6001,name:"SignerCheckFailed",msg:"Signer check failed"},{code:6002,name:"CpiSignerCheckFailed",msg:"Cpi signer check failed"},{code:6003,name:"ComputeInputSumFailed",msg:"Computing input sum failed."},{code:6004,name:"ComputeOutputSumFailed",msg:"Computing output sum failed."},{code:6005,name:"ComputeRpcSumFailed",msg:"Computing rpc sum failed."},{code:6006,name:"InvalidAddress",msg:"InvalidAddress"},{code:6007,name:"DeriveAddressError",msg:"DeriveAddressError"},{code:6008,name:"CompressedSolPdaUndefinedForCompressSol",msg:"CompressedSolPdaUndefinedForCompressSol"},{code:6009,name:"DeCompressLamportsUndefinedForCompressSol",msg:"DeCompressLamportsUndefinedForCompressSol"},{code:6010,name:"CompressedSolPdaUndefinedForDecompressSol",msg:"CompressedSolPdaUndefinedForDecompressSol"},{code:6011,name:"DeCompressLamportsUndefinedForDecompressSol",msg:"DeCompressLamportsUndefinedForDecompressSol"},{code:6012,name:"DecompressRecipientUndefinedForDecompressSol",msg:"DecompressRecipientUndefinedForDecompressSol"},{code:6013,name:"WriteAccessCheckFailed",msg:"WriteAccessCheckFailed"},{code:6014,name:"InvokingProgramNotProvided",msg:"InvokingProgramNotProvided"},{code:6015,name:"InvalidCapacity",msg:"InvalidCapacity"},{code:6016,name:"InvalidMerkleTreeOwner",msg:"InvalidMerkleTreeOwner"},{code:6017,name:"ProofIsNone",msg:"ProofIsNone"},{code:6018,name:"ProofIsSome",msg:"Proof is some but no input compressed accounts or new addresses provided."},{code:6019,name:"EmptyInputs",msg:"EmptyInputs"},{code:6020,name:"CpiContextAccountUndefined",msg:"CpiContextAccountUndefined"},{code:6021,name:"CpiContextEmpty",msg:"CpiContextEmpty"},{code:6022,name:"CpiContextMissing",msg:"CpiContextMissing"},{code:6023,name:"DecompressionRecipientDefined",msg:"DecompressionRecipientDefined"},{code:6024,name:"SolPoolPdaDefined",msg:"SolPoolPdaDefined"},{code:6025,name:"AppendStateFailed",msg:"AppendStateFailed"},{code:6026,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6027,name:"CpiContextFeePayerMismatch",msg:"CpiContextFeePayerMismatch"},{code:6028,name:"CpiContextAssociatedMerkleTreeMismatch",msg:"CpiContextAssociatedMerkleTreeMismatch"},{code:6029,name:"NoInputs",msg:"NoInputs"},{code:6030,name:"InputMerkleTreeIndicesNotInOrder",msg:"Input merkle tree indices are not in ascending order."},{code:6031,name:"OutputMerkleTreeIndicesNotInOrder",msg:"Output merkle tree indices are not in ascending order."},{code:6032,name:"OutputMerkleTreeNotUnique"},{code:6033,name:"DataFieldUndefined"},{code:6034,name:"ReadOnlyAddressAlreadyExists"},{code:6035,name:"ReadOnlyAccountDoesNotExist"},{code:6036,name:"HashChainInputsLenghtInconsistent"},{code:6037,name:"InvalidAddressTreeHeight"},{code:6038,name:"InvalidStateTreeHeight"}]},exports.INSERT_INTO_QUEUES_DISCRIMINATOR=pe,exports.INVOKE_CPI_DISCRIMINATOR=de,exports.INVOKE_DISCRIMINATOR=he,exports.IndexedArray=Qo,exports.IndexedElement=$o,exports.IndexedElementBundle=zo,exports.InsertAddressInputLayout=So,exports.InsertNullifierInputLayout=To,exports.InstructionDataInvokeCpiLayout=wo,exports.InstructionDataInvokeLayout=go,exports.LatestNonVotingSignaturesResult=kr,exports.LatestNonVotingSignaturesResultPaginated=Pr,exports.LightSystemProgram=No,exports.LookupTableError=class extends jo{},exports.MerkeProofResult=Lr,exports.MerkleContextLayout=fo,exports.MerkleTree=Wo,exports.MerkleTreeError=class extends jo{},exports.MerkleTreeSequenceNumberLayout=_o,exports.MultipleCompressedAccountsResult=Ir,exports.MultipleMerkleProofsResult=Br,exports.NativeBalanceResult=Dr,exports.NewAddressParamsLayout=mo,exports.NewAddressProofResult=Nr,exports.ProofError=class extends jo{},exports.PublicTransactionEventLayout=xo,exports.Rpc=In,exports.RpcError=class extends jo{},exports.STATE_MERKLE_TREE_NETWORK_FEE=qe,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=De,exports.SelectInUtxosError=class extends jo{},exports.SignatureListResult=jr,exports.SignatureListWithCursorResult=$r,exports.SlotResult=_r,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=Ue,exports.TestRpc=us,exports.TokenBalanceListResult=qr,exports.TokenBalanceListResultV2=Kr,exports.TokenBalanceResult=Fr,exports.TokenDataLayout=rs,exports.TokenDataResult=Ar,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends jo{},exports.UtxoError=class extends jo{},exports.ValidityProofResult=Rr,exports.accountCompressionProgram=ge,exports.addressQueue=Le,exports.addressTree=Pe,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await an(e,n),n},exports.bn=He,exports.bufToDecStr=e=>je(e).toString(),exports.buildAndSignTx=tn,exports.buildTx=Gr,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();if(!s){const e=await t.getCachedActiveStateTreeInfo(),{tree:r}=Mn(e);s=r}const u=await No.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTree:s}),l=tn([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await Xr(t,l,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=an,exports.confirmTx=en,exports.convertMerkleProofsWithContextToHex=bn,exports.convertNonInclusionMerkleProofInputsToHex=En,exports.convertToPublicTransactionEvent=ko,exports.cpiContext2Pubkey=Re,exports.cpiContextPubkey=Ce,exports.createAccount=async function(t,r,n,o,s,i,a,u){const{blockhash:l}=await t.getLatestBlockhash();s=null!=s?s:Ae().addressTree,i=null!=i?i:Ae().addressQueue;const c=nn(n,o),h=on(c,s);if(!a){const e=await t.getCachedActiveStateTreeInfo(),{tree:r}=Mn(e);a=r}const d=await t.getValidityProofV0(void 0,[{address:He(h.toBytes()),tree:s,queue:i}]),p={seed:c,addressMerkleTreeRootIndex:d.rootIndices[0],addressMerkleTreePubkey:d.merkleTrees[0],addressQueuePubkey:d.nullifierQueues[0]},f=await No.createAccount({payer:r.publicKey,newAddressParams:p,newAddress:Array.from(h.toBytes()),recentValidityProof:d.compressedProof,programId:o,outputStateTree:a}),m=tn([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,l,[]);return await Xr(t,m,u)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u,l){o=He(o);const c=await t.getCompressedAccountsByOwner(r.publicKey),[h]=Oo(c.items,o);if(!u){const e=await t.getCachedActiveStateTreeInfo(),{tree:r}=Mn(e);u=r}const{blockhash:d}=await t.getLatestBlockhash();i=null!=i?i:Ae().addressTree,a=null!=a?a:Ae().addressQueue;const p=nn(n,s),f=on(p,i),m=await t.getValidityProof(h.map((e=>He(e.hash))),[He(f.toBytes())]),g={seed:p,addressMerkleTreeRootIndex:m.rootIndices[m.rootIndices.length-1],addressMerkleTreePubkey:m.merkleTrees[m.merkleTrees.length-1],addressQueuePubkey:m.nullifierQueues[m.nullifierQueues.length-1]},y=await No.createAccount({payer:r.publicKey,newAddressParams:g,newAddress:Array.from(f.toBytes()),recentValidityProof:m.compressedProof,inputCompressedAccounts:h,inputStateRootIndices:m.rootIndices,programId:s,outputStateTree:u}),w=tn([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),y],r,d,[]);return await Xr(t,w,l)},exports.createBN254=je,exports.createCompressedAccount=ze,exports.createCompressedAccountWithMerkleContext=Qe,exports.createMerkleContext=We,exports.createRpc=function(t,r,n,o){let s;if(t)if("string"==typeof t)s=t,r=r||s,n=n||s;else{if(!(t instanceof e.Connection))throw new Error("Invalid endpoint or connection type");s=t.rpcEndpoint,r=r||s,n=n||s}else s="http://127.0.0.1:8899",r=r||"http://127.0.0.1:8784",n=n||"http://127.0.0.1:3001";return new In(s,r,n,o)},exports.createRpcResult=wr,exports.createStateTreeLookupTable=async function({connection:t,payer:r,authority:n,recentSlot:o}){const[s,i]=e.AddressLookupTableProgram.createLookupTable({payer:r.publicKey,authority:n.publicKey,recentSlot:o}),a=tn([s],r,(await t.getLatestBlockhash()).blockhash,Ro(r,[n]));return{address:i,txId:await Xr(t,a)}},exports.decodeInstructionDataInvoke=vo,exports.decodeInstructionDataInvokeCpi=bo,exports.decodePublicTransactionEvent=Ao,exports.decompress=async function(t,r,n,o,s,i){const a=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=He(n);const u=Po(a);if(n.gt(u))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${u}`);const l=await t.getValidityProof(a.map((e=>He(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),h=await No.decompress({payer:r.publicKey,toAddress:o,outputStateTree:s,inputCompressedAccounts:a,recentValidityProof:l.compressedProof,recentInputStateRootIndices:l.rootIndices,lamports:n}),d=tn([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),h],r,c,[]);return await Xr(t,d,i)},exports.dedupeSigner=Ro,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof ae&&r instanceof ae)return t.eq(r);if("object"==typeof t&&null!==t&&null!==r){const n=Object.keys(t),o=Object.keys(r);if(n.length!==o.length)return console.log(`Key length mismatch: ${n.length} !== ${o.length}`),0;for(const s of n){if(!o.includes(s))return console.log(`Key ${s} not found in value`),0;if(!e(t[s],r[s]))return console.log(`Value mismatch at key ${s}`),0}return 1}return t!==r&&console.log(`Value mismatch: ${t} !== ${r}`),t===r},exports.defaultStateTreeLookupTables=be,exports.defaultStaticAccounts=()=>[new e.PublicKey(ye()),new e.PublicKey(fe),new e.PublicKey(ge),new e.PublicKey(we())],exports.defaultStaticAccountsStruct=ve,exports.defaultTestStateTreeAccounts=Ae,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(Oe),merkleTree2:new e.PublicKey(Ne)}),exports.deriveAddress=on,exports.deriveAddressSeed=nn,exports.deserializeAppendNullifyCreateAddressInputsIndexer=Co,exports.encodeBN254toBase58=$e,exports.encodeInstructionDataInvoke=yo,exports.encodePublicTransactionEvent=function(e){const t=g.alloc(1e3),r=xo.encode(e,t);return t.slice(0,r)},exports.extendStateTreeLookupTable=async function({connection:t,tableAddress:r,newStateTreeAddresses:n,newQueueAddresses:o,newCpiContextAddresses:s,payer:i,authority:a}){const u=await t.getAddressLookupTable(r);if(!u.value)throw new Error("Lookup table not found");if(u.value.state.addresses.length%3!=0)throw new Error("Lookup table must have a multiple of 3 addresses");if(n.length!==o.length||n.length!==s.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const l=tn([e.AddressLookupTableProgram.extendLookupTable({payer:i.publicKey,authority:a.publicKey,lookupTable:r,addresses:n.flatMap(((e,t)=>[e,o[t],s[t]]))})],i,(await t.getLatestBlockhash()).blockhash,Ro(i,[a]));return{tableAddress:r,txId:await Xr(t,l)}},exports.getAccountCompressionAuthority=we,exports.getCompressedTokenAccountByHashTest=as,exports.getCompressedTokenAccounts=os,exports.getCompressedTokenAccountsByDelegateTest=is,exports.getCompressedTokenAccountsByOwnerTest=ss,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getIndexOrAdd=Tn,exports.getLightStateTreeInfo=rn,exports.getParsedEvents=Yo,exports.getPublicInputHash=function(e,t,r,n){const o=xn(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=xn(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?xn([o],[i],n):o:i},exports.getQueueForTree=An,exports.getRegisteredProgramPda=ye,exports.getTestKeypair=fs,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=Ae();return new us(t,e,r,n,void 0,{merkleTreeAddress:o||u.merkleTree,nullifierQueueAddress:s||u.nullifierQueue,depth:i||u.merkleTreeHeight,log:a})},exports.getTreeForQueue=function(e,t){const r=e.findIndex((e=>{var r;return null===(r=e.queue)||void 0===r?void 0:r.equals(t)}));if(-1===r)throw new Error("No associated tree found for queue. Please set activeStateTreeInfo with latest Tree accounts. If you use custom state trees, set manually.");if(!e[r].tree)throw new Error("Tree must not be null for state tree");return e[r].tree},exports.hashToBn254FieldSizeBe=Vt,exports.hashvToBn254FieldSizeBe=Ht,exports.invokeAccountsLayout=Eo,exports.isLocalTest=Ee,exports.isSmallerThanBn254FieldSizeBe=qt,exports.jsonRpcResult=br,exports.jsonRpcResultAndContext=Er,exports.lightProgram=me,exports.localTestActiveStateTreeInfo=xe,exports.merkleTree2Pubkey=Ne,exports.merkletreePubkey=ke,exports.negateAndCompressProof=Wr,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=fs(r),o=await e.requestAirdrop(n.publicKey,t);return await en(e,o),n},exports.noopProgram=fe,exports.nullifiedStateTreeLookupTableDevnet=Se,exports.nullifiedStateTreeLookupTableMainnet=Ie,exports.nullifierQueue2Pubkey=Oe,exports.nullifierQueuePubkey=_e,exports.nullifyLookupTable=async function({connection:t,fullStateTreeAddress:r,nullifyTableAddress:n,stateTreeLookupTableAddress:o,payer:s,authority:i}){const a=await t.getAddressLookupTable(o);if(!a.value)throw new Error("State tree lookup table not found");if(!a.value.state.addresses.includes(r))throw new Error("State tree address not found in lookup table. Pass correct address or stateTreeLookupTable");const u=await t.getAddressLookupTable(n);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.includes(r))throw new Error("Address already exists in nullify lookup table");const l=tn([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:n,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash);return{txId:await Xr(t,l)}},exports.packCompressedAccounts=Cn,exports.packNewAddressParams=sn,exports.padOutputStateMerkleTrees=Sn,exports.parseAccountData=fn,exports.parseEvents=Jo,exports.parseLightTransaction=Go,exports.parsePublicTransactionEventWithIdl=Zo,exports.parseTokenLayoutWithIdl=ns,exports.pickRandomTreeAndQueue=Mn,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=Qr,exports.proverRequest=vn,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=wn,exports.selectMinCompressedSolAccountsForTransfer=Oo,exports.sendAndConfirmTx=Xr,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=Te,exports.stateTreeLookupTableMainnet=Me,exports.sumUpLamports=Po,exports.toAccountMetas=_n,exports.toArray=Ft,exports.toCamelCase=Kt,exports.toHex=Dt,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i,a){var u;let l=He(0);const c=[];let h;for(n=He(n);l.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:h,limit:new ae(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(new ae(0))&&(c.push(e),l=l.add(e.lamports));if(h=null!==(u=r.cursor)&&void 0!==u?u:void 0,r.items.length<1e3||l.gte(n))break}if(l.lt(n))throw new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${l.toString()}`);const[d]=Oo(c,n),p=await t.getValidityProof(d.map((e=>He(e.hash)))),f=await No.transfer({payer:r.publicKey,inputCompressedAccounts:d,toAddress:s,lamports:n,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof,outputStateTrees:i}),{blockhash:m}=await t.getLatestBlockhash(),g=tn([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,m);return await Xr(t,g,a)},exports.validateNumbers=pn,exports.validateNumbersForInclusionProof=hn,exports.validateNumbersForNonInclusionProof=dn,exports.validateNumbersForProof=cn,exports.validateSameOwner=ln,exports.validateSufficientBalance=un,exports.wrapBigNumbersAsStrings=yn;
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s=0;function i(){s=1;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)r[t]=e[t],n[e.charCodeAt(t)]=t;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63}function a(e,t,n){for(var o,s,i=[],a=t;a<n;a+=3)o=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(r[(s=o)>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return i.join("")}function u(e){var t;s||i();for(var n=e.length,o=n%3,u="",c=[],l=16383,h=0,d=n-o;h<d;h+=l)c.push(a(e,h,h+l>d?d:h+l));return 1===o?(t=e[n-1],u+=r[t>>2],u+=r[t<<4&63],u+="=="):2===o&&(t=(e[n-2]<<8)+e[n-1],u+=r[t>>10],u+=r[t>>4&63],u+=r[t<<2&63],u+="="),c.push(u),c.join("")}function c(e,t,r,n,o){var s,i,a=8*o-n-1,u=(1<<a)-1,c=u>>1,l=-7,h=r?o-1:0,d=r?-1:1,p=e[t+h];for(h+=d,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=256*s+e[t+h],h+=d,l-=8);for(i=s&(1<<-l)-1,s>>=-l,l+=n;l>0;i=256*i+e[t+h],h+=d,l-=8);if(0===s)s=1-c;else{if(s===u)return i?NaN:Infinity*(p?-1:1);i+=Math.pow(2,n),s-=c}return(p?-1:1)*i*Math.pow(2,s-n)}function l(e,t,r,n,o,s){var i,a,u,c=8*s-o-1,l=(1<<c)-1,h=l>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,f=n?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||Infinity===t?(a=isNaN(t)?1:0,i=l):(i=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-i))<1&&(i--,u*=2),(t+=i+h>=1?d/u:d*Math.pow(2,1-h))*u>=2&&(i++,u/=2),i+h>=l?(a=0,i=l):i+h>=1?(a=(t*u-1)*Math.pow(2,o),i+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,o),i=0));o>=8;e[r+p]=255&a,p+=f,a/=256,o-=8);for(i=i<<o|a,c+=o;c>0;e[r+p]=255&i,p+=f,i/=256,c-=8);e[r+p-f]|=128*m}var h={}.toString,d=Array.isArray||function(e){return"[object Array]"==h.call(e)};g.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:1;var p=f();function f(){return g.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function m(e,t){if(f()<t)throw new RangeError("Invalid typed array length");return g.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=g.prototype:(null===e&&(e=new g(t)),e.length=t),e}function g(e,t,r){if(!(g.TYPED_ARRAY_SUPPORT||this instanceof g))return new g(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return v(this,e)}return y(this,e,t,r)}function y(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),g.TYPED_ARRAY_SUPPORT?(e=t).__proto__=g.prototype:e=b(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!g.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|I(t,r),o=(e=m(e,n)).write(t,r);return o!==n&&(e=e.slice(0,o)),e}(e,t,r):function(e,t){if(x(t)){var r=0|E(t.length);return 0===(e=m(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?m(e,0):b(e,t);if("Buffer"===t.type&&d(t.data))return b(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function w(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function v(e,t){if(w(t),e=m(e,t<0?0:0|E(t)),!g.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function b(e,t){var r=t.length<0?0:0|E(t.length);e=m(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function E(e){if(e>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|e}function x(e){return!(null==e||!e._isBuffer)}function I(e,t){if(x(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=0;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return J(e).length;default:if(n)return Z(e).length;t=(""+t).toLowerCase(),n=1}}function A(e,t,r){var n=0;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return F(this,t,r);case"utf8":case"utf-8":return R(this,t,r);case"ascii":return U(this,t,r);case"latin1":case"binary":return D(this,t,r);case"base64":return N(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=1}}function M(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function T(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=g.from(t,n)),x(t))return 0===t.length?-1:S(e,t,r,n,o);if("number"==typeof t)return t&=255,g.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):S(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function S(e,t,r,n,o){var s,i=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;i=2,a/=2,u/=2,r/=2}function c(e,t){return 1===i?e[t]:e.readUInt16BE(t*i)}if(o){var l=-1;for(s=r;s<a;s++)if(c(e,s)===c(t,-1===l?0:s-l)){if(-1===l&&(l=s),s-l+1===u)return l*i}else-1!==l&&(s-=s-l),l=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){for(var h=1,d=0;d<u;d++)if(c(e,s+d)!==c(t,d)){h=0;break}if(h)return s}return-1}function _(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var i=0;i<n;++i){var a=parseInt(t.substr(2*i,2),16);if(isNaN(a))return i;e[r+i]=a}return i}function C(e,t,r,n){return Q(Z(t,e.length-r),e,r,n)}function P(e,t,r,n){return Q(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function k(e,t,r,n){return P(e,t,r,n)}function L(e,t,r,n){return Q(J(t),e,r,n)}function O(e,t,r,n){return Q(function(e,t){for(var r,n,o,s=[],i=0;i<e.length&&!((t-=2)<0);++i)n=(r=e.charCodeAt(i))>>8,o=r%256,s.push(o),s.push(n);return s}(t,e.length-r),e,r,n)}function N(e,t,r){return 0===t&&r===e.length?u(e):u(e.slice(t,r))}function R(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var s,i,a,u,c=e[o],l=null,h=c>239?4:c>223?3:c>191?2:1;if(o+h<=r)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(s=e[o+1]))&&(u=(31&c)<<6|63&s)>127&&(l=u);break;case 3:s=e[o+1],i=e[o+2],128==(192&s)&&128==(192&i)&&(u=(15&c)<<12|(63&s)<<6|63&i)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:s=e[o+1],i=e[o+2],a=e[o+3],128==(192&s)&&128==(192&i)&&128==(192&a)&&(u=(15&c)<<18|(63&s)<<12|(63&i)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),o+=h}return function(e){var t=e.length;if(t<=B)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=B));return r}(n)}g.poolSize=8192,g._augment=function(e){return e.__proto__=g.prototype,e},g.from=function(e,t,r){return y(null,e,t,r)},g.TYPED_ARRAY_SUPPORT&&(g.prototype.__proto__=Uint8Array.prototype,g.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&g[Symbol.species]),g.alloc=function(e,t,r){return function(e,t,r,n){return w(t),t<=0?m(e,t):void 0!==r?"string"==typeof n?m(e,t).fill(r,n):m(e,t).fill(r):m(e,t)}(null,e,t,r)},g.allocUnsafe=function(e){return v(null,e)},g.allocUnsafeSlow=function(e){return v(null,e)},g.isBuffer=G,g.compare=function(e,t){if(!x(e)||!x(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,o=0,s=Math.min(r,n);o<s;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},g.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 1;default:return 0}},g.concat=function(e,t){if(!d(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return g.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=g.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!x(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},g.byteLength=I,g.prototype._isBuffer=1,g.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)M(this,t,t+1);return this},g.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},g.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},g.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?R(this,0,e):A.apply(this,arguments)},g.prototype.equals=function(e){if(!x(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===g.compare(this,e)},g.prototype.inspect=function(){var e="";return this.length>0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),"<Buffer "+e+">"},g.prototype.compare=function(e,t,r,n,o){if(!x(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;for(var s=(o>>>=0)-(n>>>=0),i=(r>>>=0)-(t>>>=0),a=Math.min(s,i),u=this.slice(n,o),c=e.slice(t,r),l=0;l<a;++l)if(u[l]!==c[l]){s=u[l],i=c[l];break}return s<i?-1:i<s?1:0},g.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},g.prototype.indexOf=function(e,t,r){return T(this,e,t,r,1)},g.prototype.lastIndexOf=function(e,t,r){return T(this,e,t,r,0)},g.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=0;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return C(this,e,t,r);case"ascii":return P(this,e,t,r);case"latin1":case"binary":return k(this,e,t,r);case"base64":return L(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=1}},g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var B=4096;function U(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function D(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function F(e,t,r){var n,o=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>o)&&(r=o);for(var s="",i=t;i<r;++i)s+=(n=e[i])<16?"0"+n.toString(16):n.toString(16);return s}function q(e,t,r){for(var n=e.slice(t,r),o="",s=0;s<n.length;s+=2)o+=String.fromCharCode(n[s]+256*n[s+1]);return o}function V(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function K(e,t,r,n,o,s){if(!x(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function H(e,t,r,n){t<0&&(t=65535+t+1);for(var o=0,s=Math.min(e.length-r,2);o<s;++o)e[r+o]=(t&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function $(e,t,r,n){t<0&&(t=4294967295+t+1);for(var o=0,s=Math.min(e.length-r,4);o<s;++o)e[r+o]=t>>>8*(n?o:3-o)&255}function j(e,t,r,n){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function z(e,t,r,n,o){return o||j(e,0,r,4),l(e,t,r,n,23,4),r+4}function W(e,t,r,n,o){return o||j(e,0,r,8),l(e,t,r,n,52,8),r+8}g.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),g.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=g.prototype;else{var o=t-e;r=new g(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},g.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||V(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n},g.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||V(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},g.prototype.readUInt8=function(e,t){return t||V(e,1,this.length),this[e]},g.prototype.readUInt16LE=function(e,t){return t||V(e,2,this.length),this[e]|this[e+1]<<8},g.prototype.readUInt16BE=function(e,t){return t||V(e,2,this.length),this[e]<<8|this[e+1]},g.prototype.readUInt32LE=function(e,t){return t||V(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},g.prototype.readUInt32BE=function(e,t){return t||V(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},g.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||V(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},g.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||V(e,t,this.length);for(var n=t,o=1,s=this[e+--n];n>0&&(o*=256);)s+=this[e+--n]*o;return s>=(o*=128)&&(s-=Math.pow(2,8*t)),s},g.prototype.readInt8=function(e,t){return t||V(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},g.prototype.readInt16LE=function(e,t){t||V(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},g.prototype.readInt16BE=function(e,t){t||V(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},g.prototype.readInt32LE=function(e,t){return t||V(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},g.prototype.readInt32BE=function(e,t){return t||V(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},g.prototype.readFloatLE=function(e,t){return t||V(e,4,this.length),c(this,e,1,23,4)},g.prototype.readFloatBE=function(e,t){return t||V(e,4,this.length),c(this,e,0,23,4)},g.prototype.readDoubleLE=function(e,t){return t||V(e,8,this.length),c(this,e,1,52,8)},g.prototype.readDoubleBE=function(e,t){return t||V(e,8,this.length),c(this,e,0,52,8)},g.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||K(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,s=0;for(this[t]=255&e;++s<r&&(o*=256);)this[t+s]=e/o&255;return t+r},g.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||K(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,s=1;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+r},g.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,255,0),g.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},g.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},g.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},g.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):$(this,e,t,1),t+4},g.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):$(this,e,t,0),t+4},g.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);K(this,e,t,r,o-1,-o)}var s=0,i=1,a=0;for(this[t]=255&e;++s<r&&(i*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+r},g.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);K(this,e,t,r,o-1,-o)}var s=r-1,i=1,a=0;for(this[t+s]=255&e;--s>=0&&(i*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+r},g.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,127,-128),g.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},g.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},g.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},g.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),g.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):$(this,e,t,1),t+4},g.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),g.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):$(this,e,t,0),t+4},g.prototype.writeFloatLE=function(e,t,r){return z(this,e,t,1,r)},g.prototype.writeFloatBE=function(e,t,r){return z(this,e,t,0,r)},g.prototype.writeDoubleLE=function(e,t,r){return W(this,e,t,1,r)},g.prototype.writeDoubleBE=function(e,t,r){return W(this,e,t,0,r)},g.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o,s=n-r;if(this===e&&r<t&&t<n)for(o=s-1;o>=0;--o)e[o+t]=this[o+r];else if(s<1e3||!g.TYPED_ARRAY_SUPPORT)for(o=0;o<s;++o)e[o+t]=this[o+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s},g.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var o=e.charCodeAt(0);o<256&&(e=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!g.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var s;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var i=x(e)?e:Z(new g(e,n).toString()),a=i.length;for(s=0;s<r-t;++s)this[s+t]=i[s%a]}return this};var Y=/[^+\/0-9A-Za-z-_]/g;function Z(e,t){var r;t=t||Infinity;for(var n=e.length,o=null,s=[],i=0;i<n;++i){if((r=e.charCodeAt(i))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(i+1===n){(t-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function J(e){return function(e){var t,r,a,u,c,l;s||i();var h=e.length;if(h%4>0)throw new Error("Invalid string. Length must be a multiple of 4");c="="===e[h-2]?2:"="===e[h-1]?1:0,l=new o(3*h/4-c),a=c>0?h-4:h;var d=0;for(t=0,r=0;t<a;t+=4,r+=3)u=n[e.charCodeAt(t)]<<18|n[e.charCodeAt(t+1)]<<12|n[e.charCodeAt(t+2)]<<6|n[e.charCodeAt(t+3)],l[d++]=u>>16&255,l[d++]=u>>8&255,l[d++]=255&u;return 2===c?(u=n[e.charCodeAt(t)]<<2|n[e.charCodeAt(t+1)]>>4,l[d++]=255&u):1===c&&(u=n[e.charCodeAt(t)]<<10|n[e.charCodeAt(t+1)]<<4|n[e.charCodeAt(t+2)]>>2,l[d++]=u>>8&255,l[d++]=255&u),l}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Y,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Q(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function G(e){return null!=e&&(!!e._isBuffer||X(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&X(e.slice(0,0))}(e))}function X(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var ee="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function te(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function re(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:1}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:1,get:function(){return e[t]}})})),r}var ne={exports:{}},oe=re(Object.freeze({__proto__:null,Buffer:g,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),g.alloc(+e)},isBuffer:G,kMaxLength:p}));!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 ne?ne.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:oe.Buffer}catch(e){}function i(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 a(e,t,r){var n=i(e,r);return r-1>=t&&(n|=i(e,r-1)<<4),n}function u(e,t,n,o){for(var s=0,i=0,a=Math.min(e.length,n),u=t;u<a;u++){var c=e.charCodeAt(u)-48;s*=o,i=c>=49?c-49+10:c>=17?c-17+10:c,r(c>=0&&i<o,"Invalid character"),s+=i}return s}function c(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=a(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=a(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,c=0,l=r;l<a;l+=n)c=u(e,l,l+n,t),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==i){var h=1;for(c=u(e,l,e.length,t),l=0;l<i;l++)h*=t;this.imuln(h),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}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){c(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")]=l}catch(e){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var h=["","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"],d=[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],p=[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 c=1;c<n;c++){for(var l=u>>>26,h=67108863&u,d=Math.min(c,t.length-1),p=Math.max(0,c-e.length+1);p<=d;p++){var f=c-p|0;l+=(i=(o=0|e.words[f])*(s=0|t.words[p])+h)/67108864|0,h=67108863&i}r.words[c]=0|h,u=0|l}return 0!==u?r.words[c]=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?h[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 c=d[e],l=p[e];n="";var f=this.clone();for(f.negative=0;!f.isZero();){var m=f.modrn(l).toString(e);n=(f=f.idivn(l)).isZero()?m+n:h[c-m.length]+m+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 m=function(e,t,r){var n,o,s,i=e.words,a=t.words,u=r.words,c=0,l=0|i[0],h=8191&l,d=l>>>13,p=0|i[1],f=8191&p,m=p>>>13,g=0|i[2],y=8191&g,w=g>>>13,v=0|i[3],b=8191&v,E=v>>>13,x=0|i[4],I=8191&x,A=x>>>13,M=0|i[5],T=8191&M,S=M>>>13,_=0|i[6],C=8191&_,P=_>>>13,k=0|i[7],L=8191&k,O=k>>>13,N=0|i[8],R=8191&N,B=N>>>13,U=0|i[9],D=8191&U,F=U>>>13,q=0|a[0],V=8191&q,K=q>>>13,H=0|a[1],$=8191&H,j=H>>>13,z=0|a[2],W=8191&z,Y=z>>>13,Z=0|a[3],J=8191&Z,Q=Z>>>13,G=0|a[4],X=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,ce=ae>>>13,le=0|a[8],he=8191&le,de=le>>>13,pe=0|a[9],fe=8191&pe,me=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(c+(n=Math.imul(h,V))|0)+((8191&(o=(o=Math.imul(h,K))+Math.imul(d,V)|0))<<13)|0;c=((s=Math.imul(d,K))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(f,V),o=(o=Math.imul(f,K))+Math.imul(m,V)|0,s=Math.imul(m,K);var ye=(c+(n=n+Math.imul(h,$)|0)|0)+((8191&(o=(o=o+Math.imul(h,j)|0)+Math.imul(d,$)|0))<<13)|0;c=((s=s+Math.imul(d,j)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,V),o=(o=Math.imul(y,K))+Math.imul(w,V)|0,s=Math.imul(w,K),n=n+Math.imul(f,$)|0,o=(o=o+Math.imul(f,j)|0)+Math.imul(m,$)|0,s=s+Math.imul(m,j)|0;var we=(c+(n=n+Math.imul(h,W)|0)|0)+((8191&(o=(o=o+Math.imul(h,Y)|0)+Math.imul(d,W)|0))<<13)|0;c=((s=s+Math.imul(d,Y)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(b,V),o=(o=Math.imul(b,K))+Math.imul(E,V)|0,s=Math.imul(E,K),n=n+Math.imul(y,$)|0,o=(o=o+Math.imul(y,j)|0)+Math.imul(w,$)|0,s=s+Math.imul(w,j)|0,n=n+Math.imul(f,W)|0,o=(o=o+Math.imul(f,Y)|0)+Math.imul(m,W)|0,s=s+Math.imul(m,Y)|0;var ve=(c+(n=n+Math.imul(h,J)|0)|0)+((8191&(o=(o=o+Math.imul(h,Q)|0)+Math.imul(d,J)|0))<<13)|0;c=((s=s+Math.imul(d,Q)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(I,V),o=(o=Math.imul(I,K))+Math.imul(A,V)|0,s=Math.imul(A,K),n=n+Math.imul(b,$)|0,o=(o=o+Math.imul(b,j)|0)+Math.imul(E,$)|0,s=s+Math.imul(E,j)|0,n=n+Math.imul(y,W)|0,o=(o=o+Math.imul(y,Y)|0)+Math.imul(w,W)|0,s=s+Math.imul(w,Y)|0,n=n+Math.imul(f,J)|0,o=(o=o+Math.imul(f,Q)|0)+Math.imul(m,J)|0,s=s+Math.imul(m,Q)|0;var be=(c+(n=n+Math.imul(h,X)|0)|0)+((8191&(o=(o=o+Math.imul(h,ee)|0)+Math.imul(d,X)|0))<<13)|0;c=((s=s+Math.imul(d,ee)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(T,V),o=(o=Math.imul(T,K))+Math.imul(S,V)|0,s=Math.imul(S,K),n=n+Math.imul(I,$)|0,o=(o=o+Math.imul(I,j)|0)+Math.imul(A,$)|0,s=s+Math.imul(A,j)|0,n=n+Math.imul(b,W)|0,o=(o=o+Math.imul(b,Y)|0)+Math.imul(E,W)|0,s=s+Math.imul(E,Y)|0,n=n+Math.imul(y,J)|0,o=(o=o+Math.imul(y,Q)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,Q)|0,n=n+Math.imul(f,X)|0,o=(o=o+Math.imul(f,ee)|0)+Math.imul(m,X)|0,s=s+Math.imul(m,ee)|0;var Ee=(c+(n=n+Math.imul(h,re)|0)|0)+((8191&(o=(o=o+Math.imul(h,ne)|0)+Math.imul(d,re)|0))<<13)|0;c=((s=s+Math.imul(d,ne)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(C,V),o=(o=Math.imul(C,K))+Math.imul(P,V)|0,s=Math.imul(P,K),n=n+Math.imul(T,$)|0,o=(o=o+Math.imul(T,j)|0)+Math.imul(S,$)|0,s=s+Math.imul(S,j)|0,n=n+Math.imul(I,W)|0,o=(o=o+Math.imul(I,Y)|0)+Math.imul(A,W)|0,s=s+Math.imul(A,Y)|0,n=n+Math.imul(b,J)|0,o=(o=o+Math.imul(b,Q)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,Q)|0,n=n+Math.imul(y,X)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,X)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(f,re)|0,o=(o=o+Math.imul(f,ne)|0)+Math.imul(m,re)|0,s=s+Math.imul(m,ne)|0;var xe=(c+(n=n+Math.imul(h,se)|0)|0)+((8191&(o=(o=o+Math.imul(h,ie)|0)+Math.imul(d,se)|0))<<13)|0;c=((s=s+Math.imul(d,ie)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(L,V),o=(o=Math.imul(L,K))+Math.imul(O,V)|0,s=Math.imul(O,K),n=n+Math.imul(C,$)|0,o=(o=o+Math.imul(C,j)|0)+Math.imul(P,$)|0,s=s+Math.imul(P,j)|0,n=n+Math.imul(T,W)|0,o=(o=o+Math.imul(T,Y)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,Y)|0,n=n+Math.imul(I,J)|0,o=(o=o+Math.imul(I,Q)|0)+Math.imul(A,J)|0,s=s+Math.imul(A,Q)|0,n=n+Math.imul(b,X)|0,o=(o=o+Math.imul(b,ee)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(f,se)|0,o=(o=o+Math.imul(f,ie)|0)+Math.imul(m,se)|0,s=s+Math.imul(m,ie)|0;var Ie=(c+(n=n+Math.imul(h,ue)|0)|0)+((8191&(o=(o=o+Math.imul(h,ce)|0)+Math.imul(d,ue)|0))<<13)|0;c=((s=s+Math.imul(d,ce)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(R,V),o=(o=Math.imul(R,K))+Math.imul(B,V)|0,s=Math.imul(B,K),n=n+Math.imul(L,$)|0,o=(o=o+Math.imul(L,j)|0)+Math.imul(O,$)|0,s=s+Math.imul(O,j)|0,n=n+Math.imul(C,W)|0,o=(o=o+Math.imul(C,Y)|0)+Math.imul(P,W)|0,s=s+Math.imul(P,Y)|0,n=n+Math.imul(T,J)|0,o=(o=o+Math.imul(T,Q)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,Q)|0,n=n+Math.imul(I,X)|0,o=(o=o+Math.imul(I,ee)|0)+Math.imul(A,X)|0,s=s+Math.imul(A,ee)|0,n=n+Math.imul(b,re)|0,o=(o=o+Math.imul(b,ne)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,ne)|0,n=n+Math.imul(y,se)|0,o=(o=o+Math.imul(y,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,n=n+Math.imul(f,ue)|0,o=(o=o+Math.imul(f,ce)|0)+Math.imul(m,ue)|0,s=s+Math.imul(m,ce)|0;var Ae=(c+(n=n+Math.imul(h,he)|0)|0)+((8191&(o=(o=o+Math.imul(h,de)|0)+Math.imul(d,he)|0))<<13)|0;c=((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(R,$)|0,o=(o=o+Math.imul(R,j)|0)+Math.imul(B,$)|0,s=s+Math.imul(B,j)|0,n=n+Math.imul(L,W)|0,o=(o=o+Math.imul(L,Y)|0)+Math.imul(O,W)|0,s=s+Math.imul(O,Y)|0,n=n+Math.imul(C,J)|0,o=(o=o+Math.imul(C,Q)|0)+Math.imul(P,J)|0,s=s+Math.imul(P,Q)|0,n=n+Math.imul(T,X)|0,o=(o=o+Math.imul(T,ee)|0)+Math.imul(S,X)|0,s=s+Math.imul(S,ee)|0,n=n+Math.imul(I,re)|0,o=(o=o+Math.imul(I,ne)|0)+Math.imul(A,re)|0,s=s+Math.imul(A,ne)|0,n=n+Math.imul(b,se)|0,o=(o=o+Math.imul(b,ie)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ie)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(f,he)|0,o=(o=o+Math.imul(f,de)|0)+Math.imul(m,he)|0,s=s+Math.imul(m,de)|0;var Me=(c+(n=n+Math.imul(h,fe)|0)|0)+((8191&(o=(o=o+Math.imul(h,me)|0)+Math.imul(d,fe)|0))<<13)|0;c=((s=s+Math.imul(d,me)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,$),o=(o=Math.imul(D,j))+Math.imul(F,$)|0,s=Math.imul(F,j),n=n+Math.imul(R,W)|0,o=(o=o+Math.imul(R,Y)|0)+Math.imul(B,W)|0,s=s+Math.imul(B,Y)|0,n=n+Math.imul(L,J)|0,o=(o=o+Math.imul(L,Q)|0)+Math.imul(O,J)|0,s=s+Math.imul(O,Q)|0,n=n+Math.imul(C,X)|0,o=(o=o+Math.imul(C,ee)|0)+Math.imul(P,X)|0,s=s+Math.imul(P,ee)|0,n=n+Math.imul(T,re)|0,o=(o=o+Math.imul(T,ne)|0)+Math.imul(S,re)|0,s=s+Math.imul(S,ne)|0,n=n+Math.imul(I,se)|0,o=(o=o+Math.imul(I,ie)|0)+Math.imul(A,se)|0,s=s+Math.imul(A,ie)|0,n=n+Math.imul(b,ue)|0,o=(o=o+Math.imul(b,ce)|0)+Math.imul(E,ue)|0,s=s+Math.imul(E,ce)|0,n=n+Math.imul(y,he)|0,o=(o=o+Math.imul(y,de)|0)+Math.imul(w,he)|0,s=s+Math.imul(w,de)|0;var Te=(c+(n=n+Math.imul(f,fe)|0)|0)+((8191&(o=(o=o+Math.imul(f,me)|0)+Math.imul(m,fe)|0))<<13)|0;c=((s=s+Math.imul(m,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(D,W),o=(o=Math.imul(D,Y))+Math.imul(F,W)|0,s=Math.imul(F,Y),n=n+Math.imul(R,J)|0,o=(o=o+Math.imul(R,Q)|0)+Math.imul(B,J)|0,s=s+Math.imul(B,Q)|0,n=n+Math.imul(L,X)|0,o=(o=o+Math.imul(L,ee)|0)+Math.imul(O,X)|0,s=s+Math.imul(O,ee)|0,n=n+Math.imul(C,re)|0,o=(o=o+Math.imul(C,ne)|0)+Math.imul(P,re)|0,s=s+Math.imul(P,ne)|0,n=n+Math.imul(T,se)|0,o=(o=o+Math.imul(T,ie)|0)+Math.imul(S,se)|0,s=s+Math.imul(S,ie)|0,n=n+Math.imul(I,ue)|0,o=(o=o+Math.imul(I,ce)|0)+Math.imul(A,ue)|0,s=s+Math.imul(A,ce)|0,n=n+Math.imul(b,he)|0,o=(o=o+Math.imul(b,de)|0)+Math.imul(E,he)|0,s=s+Math.imul(E,de)|0;var Se=(c+(n=n+Math.imul(y,fe)|0)|0)+((8191&(o=(o=o+Math.imul(y,me)|0)+Math.imul(w,fe)|0))<<13)|0;c=((s=s+Math.imul(w,me)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,Q))+Math.imul(F,J)|0,s=Math.imul(F,Q),n=n+Math.imul(R,X)|0,o=(o=o+Math.imul(R,ee)|0)+Math.imul(B,X)|0,s=s+Math.imul(B,ee)|0,n=n+Math.imul(L,re)|0,o=(o=o+Math.imul(L,ne)|0)+Math.imul(O,re)|0,s=s+Math.imul(O,ne)|0,n=n+Math.imul(C,se)|0,o=(o=o+Math.imul(C,ie)|0)+Math.imul(P,se)|0,s=s+Math.imul(P,ie)|0,n=n+Math.imul(T,ue)|0,o=(o=o+Math.imul(T,ce)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,ce)|0,n=n+Math.imul(I,he)|0,o=(o=o+Math.imul(I,de)|0)+Math.imul(A,he)|0,s=s+Math.imul(A,de)|0;var _e=(c+(n=n+Math.imul(b,fe)|0)|0)+((8191&(o=(o=o+Math.imul(b,me)|0)+Math.imul(E,fe)|0))<<13)|0;c=((s=s+Math.imul(E,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(D,X),o=(o=Math.imul(D,ee))+Math.imul(F,X)|0,s=Math.imul(F,ee),n=n+Math.imul(R,re)|0,o=(o=o+Math.imul(R,ne)|0)+Math.imul(B,re)|0,s=s+Math.imul(B,ne)|0,n=n+Math.imul(L,se)|0,o=(o=o+Math.imul(L,ie)|0)+Math.imul(O,se)|0,s=s+Math.imul(O,ie)|0,n=n+Math.imul(C,ue)|0,o=(o=o+Math.imul(C,ce)|0)+Math.imul(P,ue)|0,s=s+Math.imul(P,ce)|0,n=n+Math.imul(T,he)|0,o=(o=o+Math.imul(T,de)|0)+Math.imul(S,he)|0,s=s+Math.imul(S,de)|0;var Ce=(c+(n=n+Math.imul(I,fe)|0)|0)+((8191&(o=(o=o+Math.imul(I,me)|0)+Math.imul(A,fe)|0))<<13)|0;c=((s=s+Math.imul(A,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=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(R,se)|0,o=(o=o+Math.imul(R,ie)|0)+Math.imul(B,se)|0,s=s+Math.imul(B,ie)|0,n=n+Math.imul(L,ue)|0,o=(o=o+Math.imul(L,ce)|0)+Math.imul(O,ue)|0,s=s+Math.imul(O,ce)|0,n=n+Math.imul(C,he)|0,o=(o=o+Math.imul(C,de)|0)+Math.imul(P,he)|0,s=s+Math.imul(P,de)|0;var Pe=(c+(n=n+Math.imul(T,fe)|0)|0)+((8191&(o=(o=o+Math.imul(T,me)|0)+Math.imul(S,fe)|0))<<13)|0;c=((s=s+Math.imul(S,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=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(R,ue)|0,o=(o=o+Math.imul(R,ce)|0)+Math.imul(B,ue)|0,s=s+Math.imul(B,ce)|0,n=n+Math.imul(L,he)|0,o=(o=o+Math.imul(L,de)|0)+Math.imul(O,he)|0,s=s+Math.imul(O,de)|0;var ke=(c+(n=n+Math.imul(C,fe)|0)|0)+((8191&(o=(o=o+Math.imul(C,me)|0)+Math.imul(P,fe)|0))<<13)|0;c=((s=s+Math.imul(P,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(D,ue),o=(o=Math.imul(D,ce))+Math.imul(F,ue)|0,s=Math.imul(F,ce),n=n+Math.imul(R,he)|0,o=(o=o+Math.imul(R,de)|0)+Math.imul(B,he)|0,s=s+Math.imul(B,de)|0;var Le=(c+(n=n+Math.imul(L,fe)|0)|0)+((8191&(o=(o=o+Math.imul(L,me)|0)+Math.imul(O,fe)|0))<<13)|0;c=((s=s+Math.imul(O,me)|0)+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,n=Math.imul(D,he),o=(o=Math.imul(D,de))+Math.imul(F,he)|0,s=Math.imul(F,de);var Oe=(c+(n=n+Math.imul(R,fe)|0)|0)+((8191&(o=(o=o+Math.imul(R,me)|0)+Math.imul(B,fe)|0))<<13)|0;c=((s=s+Math.imul(B,me)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863;var Ne=(c+(n=Math.imul(D,fe))|0)+((8191&(o=(o=Math.imul(D,me))+Math.imul(F,fe)|0))<<13)|0;return c=((s=Math.imul(F,me))+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=ve,u[4]=be,u[5]=Ee,u[6]=xe,u[7]=Ie,u[8]=Ae,u[9]=Me,u[10]=Te,u[11]=Se,u[12]=_e,u[13]=Ce,u[14]=Pe,u[15]=ke,u[16]=Le,u[17]=Oe,u[18]=Ne,0!==c&&(u[19]=c,r.length++),r};function g(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),c=Math.max(0,s-e.length+1);c<=u;c++){var l=s-c,h=(0|e.words[l])*(0|t.words[c]),d=67108863&h;a=67108863&(d=d+a|0),o+=(i=(i=i+(h/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 g(e,t,r)}Math.imul||(m=f),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?m(this,e,t):r<63?f(this,e,t):r<1024?g(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 c=0;c<i;c++)u.words[c]=this.words[c];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,c=0;c<this.length;c++)this.words[c]=this.words[c+i];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var h=0|this.words[c];this.words[c]=l<<26-s|h>>>s,l=h&a}return u&&0!==l&&(u.words[u.length++]=l),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 c=0;c<a.length;c++)a.words[c]=0}var l=n.clone()._ishlnsubmul(s,1,u);0===l.negative&&(n=l,a&&(a.words[u]=1));for(var h=u-1;h>=0;h--){var d=67108864*(0|n.words[s.length+h])+(0|n.words[s.length+h-1]);for(d=Math.min(d/i|0,67108863),n._ishlnsubmul(s,d,h);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(s,1,h),n.isZero()||(n.negative^=1);a&&(a.words[h]=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),c=0;t.isEven()&&n.isEven();)t.iushrn(1),n.iushrn(1),++c;for(var l=n.clone(),h=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(l),i.isub(h)),s.iushrn(1),i.iushrn(1);for(var f=0,m=1;0==(n.words[0]&m)&&f<26;++f,m<<=1);if(f>0)for(n.iushrn(f);f-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(h)),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(c)}},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 c=0,l=1;0==(t.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var h=0,d=1;0==(n.words[0]&d)&&h<26;++h,d<<=1);if(h>0)for(n.iushrn(h);h-- >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 A(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 w={k256:null,p224:null,p192:null,p25519:null};function v(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 b(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function E(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function x(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function I(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function A(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 M(e){A.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)}v.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},v.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},v.prototype.split=function(e,t){e.iushrn(this.n,0,t)},v.prototype.imulK=function(e){return e.imul(this.k)},n(b,v),b.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},b.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(E,v),n(x,v),n(I,v),I.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(w[e])return w[e];var t;if("k256"===e)t=new b;else if("p224"===e)t=new E;else if("p192"===e)t=new x;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new I}return w[e]=t,t},A.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},A.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")},A.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},A.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},A.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)},A.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},A.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)},A.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},A.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},A.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},A.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},A.prototype.isqr=function(e){return this.imul(e,e.clone())},A.prototype.sqr=function(e){return this.mul(e,e)},A.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(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var h=this.pow(l,s),d=this.pow(e,s.addn(1).iushrn(1)),p=this.pow(e,s),f=i;0!==p.cmp(a);){for(var m=p,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<f);var y=this.pow(h,new o(1).iushln(f-g-1));d=d.redMul(y),h=y.redSqr(),p=p.redMul(h),f=g}return d},A.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},A.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 c=t.words[n],l=u-1;l>=0;l--){var h=c>>l&1;s!==r[0]&&(s=this.sqr(s)),0!==h||0!==i?(i<<=1,i|=h,(4==++a||0===n&&0===l)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},A.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},A.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new M(e)},n(M,A),M.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},M.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},M.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)},M.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)},M.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,ee);var se,ie=ne.exports,ae=te(ie);exports.TreeType=void 0,(se=exports.TreeType||(exports.TreeType={}))[se.StateV1=1]="StateV1",se[se.AddressV1=2]="AddressV1",se[se.StateV2=3]="StateV2",se[se.AddressV2=4]="AddressV2";const ue=new ae("21888242871839275222246405745257275088548364400416034343698204186575808495617"),ce=new ae("452312848583266388373324160190187140051835877600158453279131187530910662655"),le=[2,64,66,15,0],he=g.from([26,16,169,7,21,202,242,25]),de=g.from([49,212,191,129,39,194,43,196]),pe=g.from([180,143,159,153,35,46,248,163]),fe="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",me="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",ge="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",ye=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),we=()=>e.PublicKey.findProgramAddressSync([g.from("cpi_authority")],new e.PublicKey(me))[0],ve=()=>({registeredProgramPda:new e.PublicKey(ye()),noopProgram:new e.PublicKey(fe),accountCompressionProgram:new e.PublicKey(ge),accountCompressionAuthority:new e.PublicKey(we()),cpiSignatureAccount:null}),be=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(Te),nullifyLookupTable:new e.PublicKey(Se)}],devnet:[{stateTreeLookupTable:new e.PublicKey(_e),nullifyLookupTable:new e.PublicKey(Ce)}]}),Ee=e=>e.includes("localhost")||e.includes("127.0.0.1"),xe=()=>[{tree:new e.PublicKey(Le),queue:new e.PublicKey(Pe),cpiContext:new e.PublicKey(ke),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Re),queue:new e.PublicKey(Be),cpiContext:new e.PublicKey(Ue),treeType:exports.TreeType.StateV1,nextTreeInfo:null}],Ie=()=>({tree:new e.PublicKey(Oe),queue:new e.PublicKey(Ne),cpiContext:null,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}),Ae=()=>({nullifierQueue:new e.PublicKey(Pe),merkleTree:new e.PublicKey(Le),merkleTreeHeight:De,addressTree:new e.PublicKey(Oe),addressQueue:new e.PublicKey(Ne)}),Me=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),Te="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",Se="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",_e="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",Ce="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",Pe="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",ke="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",Le="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",Oe="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",Ne="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",Re="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Be="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",Ue="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",De=26,Fe=new ae(Math.floor(2**De*.95)),qe=new ae(300),Ve=new ae(392),Ke=new ae(5e3),He=new ae(5e3);var $e=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 c=a-i;for(;c!==a&&0===u[c];)c++;const l=new Uint8Array(s+(a-c));let h=s;for(;c!==a;)l[h++]=u[c++];return l}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,c=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*c[t]>>>0,c[t]=e%58>>>0,e=e/58>>>0;if(0!==e)throw new Error("Non-zero carry");s=r,i++}let l=u-s;for(;l!==u&&0===c[l];)l++;let h=r.repeat(n);for(;l<u;++l)h+=e.charAt(c[l]);return h},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const je=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return je($e.decode(e))}return function(e){if(e.gte(ue))throw new Error("Value is too large. Max <254 bits");return e}(new ae(e,t))};function ze(e){const t=je(e).toArrayLike(g,void 0,32);return $e.encode(new Uint8Array(t))}const We=(e,t,r)=>e instanceof Uint8Array&&!(e instanceof g)?new ae(g.from(e),t,r):new ae(e,t,r),Ye=(e,t,r,n)=>({owner:e,lamports:null!=t?t:We(0),address:null!=n?n:null,data:null!=r?r:null}),Ze=(e,t,r,n,o)=>Object.assign(Object.assign(Object.assign({},Ye(t,r,n,o)),e),{readOnly:0}),Je=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n});function Qe(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function Ge(e,t){return t<=0?[]:new Array(t).fill(e)}function Xe(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function et(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=Qe(s,e.treeInfo.tree),o=Qe(s,e.treeInfo.queue);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})})),e.length>0&&n)throw new Error("Cannot specify both input accounts and outputStateTreeInfo");let u;if(e.length>0)u=e[0].treeInfo;else{if(!n)throw new Error("Neither input accounts nor outputStateTreeInfo are available");u=n}const c=u.nextTreeInfo||u,l=c.tree;if(c.treeType===exports.TreeType.StateV2)throw new Error("V2 trees are not supported yet");const h=Ge(l,r.length);return r.forEach(((e,t)=>{const r=Qe(s,h[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 tt=e=>{if(e.lt(We(0)))throw new Error("Insufficient balance for transfer")},rt=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")},nt=(e,t)=>{if(e>0&&t>0){if(8===e)throw new Error(`Invalid number of compressed accounts for proof: ${e}. Allowed numbers: ${[1,2,3,4].join(", ")}`);it(e,[1,2,3,4],"compressed accounts"),st(t)}else e>0?ot(e):st(t)},ot=e=>{it(e,[1,2,3,4,8],"compressed accounts")},st=e=>{it(e,[1,2],"new addresses")},it=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function at(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ut(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 ct(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 lt=BigInt(2**32-1),ht=BigInt(32);function dt(e,t=0){return t?{h:Number(e<),l:Number(e>>ht<)}:{h:0|Number(e>>ht<),l:0|Number(e<)}}function pt(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}=dt(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const ft=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function mt(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 gt(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)),ut(e),e}class yt{clone(){return this._cloneInto()}}const wt=[],vt=[],bt=[],Et=BigInt(0),xt=BigInt(1),It=BigInt(2),At=BigInt(7),Mt=BigInt(256),Tt=BigInt(113);for(let e=0,t=xt,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],wt.push(2*(5*n+r)),vt.push((e+1)*(e+2)/2%64);let o=Et;for(let e=0;e<7;e++)t=(t<<xt^(t>>At)*Tt)%Mt,t&It&&(o^=xt<<(xt<<BigInt(e))-xt);bt.push(o)}const[St,_t]=pt(bt,1),Ct=(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),Pt=(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 kt extends yt{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,at(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(){ft||mt(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=Ct(s,i,1)^r[n],u=Pt(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=vt[r],s=Ct(t,o,n),i=Pt(t,o,n),a=wt[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]^=St[n],e[1]^=_t[n]}r.fill(0)}(this.state32,this.rounds),ft||mt(this.state32),this.posOut=0,this.pos=0}update(e){ct(this);const{blockLen:t,state:r}=this,n=(e=gt(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){ct(this,0),ut(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 at(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){ut(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 kt(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 Lt=(()=>function(e){const t=t=>e().update(gt(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new kt(136,1,32))))(),Ot=e=>"object"==typeof e&&null!==e,Nt=e=>Ot(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),Rt=Symbol("mapObjectSkip"),Bt=(e,t,r,n=new WeakMap)=>{if(r={deep:0,target:{},...r},n.has(e))return n.get(e);n.set(e,r.target);const{target:o}=r;delete r.target;const s=e=>e.map((e=>Nt(e)?Bt(e,t,r,n):e));if(Array.isArray(e))return s(e);for(const[i,a]of Object.entries(e)){const u=t(i,a,e);if(u===Rt)continue;let[c,l,{shouldRecurse:h=1}={}]=u;"__proto__"!==c&&(r.deep&&h&&Nt(l)&&(l=Array.isArray(l)?s(l):Bt(l,t,r,n)),o[c]=l)}return o};function Ut(e,t,r){if(!Ot(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return Bt(e,t,r)}const Dt=/[\p{Lu}]/u,Ft=/[\p{Ll}]/u,qt=/^[\p{Lu}](?![\p{Lu}])/gu,Vt=/([\p{Alpha}\p{N}_]|$)/u,Kt=/[_.\- ]+/,Ht=new RegExp("^"+Kt.source),$t=new RegExp(Kt.source+Vt.source,"gu"),jt=new RegExp("\\d+"+Vt.source,"gu");class zt extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,r]of e)this.onEviction(t,r.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()?("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e)):0}_getOrDeleteIfExpired(e,t){if(0==this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const r=t.get(e);return this._getItemValue(e,r)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield e)}for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(0==this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:r=this.maxAge}={}){const n="number"==typeof r&&r!==Number.POSITIVE_INFINITY?Date.now()+r:void 0;return this.cache.has(e)?this.cache.set(e,{value:t,expiry:n}):this._set(e,{value:t,expiry:n}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):this.oldCache.has(e)?!this._deleteIfExpired(e,this.oldCache.get(e)):0}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],r=t.length-e;r<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(r>0&&this._emitEvictions(t.slice(0,r)),this.oldCache=new Map(t.slice(r)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;this.cache.has(n)||0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[r,n]of this.entriesAscending())e.call(t,n,r,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}const Wt=new zt({maxSize:1e5}),Yt=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),Zt=(e,t={})=>{if(!Yt(e))return e;const{exclude:r,pascalCase:n=0,stopPaths:o,deep:s=0,preserveConsecutiveUppercase:i=0}=t,a=new Set(o),u=e=>(t,o)=>{if(s&&Yt(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=Ut(o,u(r)))}if(!r||!((e,t)=>e.some((e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t)))))(r,t)){const e=n?`${t}_`:t;if(Wt.has(e))t=Wt.get(e);else{const r=function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:0,preserveConsecutiveUppercase:0,...t},0===(e=Array.isArray(e)?e.map((e=>e.trim())).filter((e=>e.length)).join("-"):e.trim()).length)return"";const r=0==t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),n=0==t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);return 1===e.length?Kt.test(e)?"":t.pascalCase?n(e):r(e):(e!==r(e)&&(e=((e,t,r,n)=>{let o=0,s=0,i=0,a=0;for(let u=0;u<e.length;u++){const c=e[u];a=u>2?"-"===e[u-3]:1,o&&Dt.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&Ft.test(c)&&(!a||n)?(e=e.slice(0,u-1)+"-"+e.slice(u-1),i=s,s=0,o=1):(o=t(c)===c&&r(c)!==c,i=s,s=r(c)===c&&t(c)!==c)}return e})(e,r,n,t.preserveConsecutiveUppercase)),e=e.replace(Ht,""),e=t.preserveConsecutiveUppercase?((e,t)=>(qt.lastIndex=0,e.replaceAll(qt,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>($t.lastIndex=0,jt.lastIndex=0,e.replaceAll(jt,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll($t,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&Wt.set(e,r),t=r}}return[t,o]};return Ut(e,u(void 0))};function Jt(e){return"0x"+e.toString("hex")}function Qt(e){return We(e,void 0,"be").lt(ue)}const Gt=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>Zt(t[e],r))):Zt(t,r);var t,r};function Xt(e){let t=255;for(;t>=0;){const r=g.concat([e,g.from([t])]),n=Lt(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,Qt(g.from(n)))return[g.from(n),t];t-=1}return null}function er(e){const t=Lt.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function tr(e,t){return er([t.toBytes(),...e])}function rr(t,r=Ae().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=Xt(Buffer.from([...n,...t]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new e.PublicKey(s)}function nr(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=Qe(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=Qe(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function or(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 sr(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}function ir(e,t=exports.TreeType.StateV1,r=0){const n=e.filter((e=>!e.nextTreeInfo)).filter((e=>e.treeType===t));if(0===n.length)throw new Error("No active state tree infos found for the specified tree type");const o=r?n.length:Math.min(5,n.length),s=Math.floor(Math.random()*o);if(!n[s].queue)throw new Error("Queue must not be null for state tree");return n[s]}async function ar({connection:t,stateTreeLUTPairs:r}){var n;const o=await Promise.all(r.map((async e=>({stateTreeLookupTable:await t.getAddressLookupTable(e.stateTreeLookupTable),nullifyLookupTable:await t.getAddressLookupTable(e.nullifyLookupTable)})))),s=[];for(const{stateTreeLookupTable:t,nullifyLookupTable:r}of o){if(!t.value)throw new Error("State tree lookup table not found");if(!r.value)throw new Error("Nullify table not found");const o=t.value.state.addresses,i=r.value.state.addresses;if(o.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");for(let t=0;t<o.length;t+=3){const r=o[t],n=o[t+1],a=o[t+2];let u=null;if(!r||!n||!a)throw new Error("Invalid state tree pubkeys structure");i.map((e=>e.toBase58())).includes(r.toBase58())&&(u={tree:e.PublicKey.default,queue:e.PublicKey.default,cpiContext:e.PublicKey.default,treeType:exports.TreeType.StateV1,nextTreeInfo:null}),s.push({tree:r,queue:n,cpiContext:a,treeType:exports.TreeType.StateV1,nextTreeInfo:u})}for(const t of s)if(null===(n=t.nextTreeInfo)||void 0===n?void 0:n.tree.equals(e.PublicKey.default)){const e=s.find((e=>!e.nextTreeInfo));if(!e)throw new Error("No available tree info found to assign as next tree");t.nextTreeInfo=e}}return s}function ur(e){const t=lr(e.ar[0]),r=lr(e.ar[1]),n=new Uint8Array([...t,...r]),o=lr(e.bs[0][0]),s=lr(e.bs[0][1]),i=lr(e.bs[1][0]),a=lr(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=lr(e.krs[0]),l=lr(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function cr(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=hr(We(t.slice(32,64),32,"be"))?0:1;o[0]=dr(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=ue.div(We(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(We(a.slice(0,32),32,"be"),We(a.slice(32,64),32,"be"));i[0]=dr(i[0],u);const c=n.slice(0,32),l=n.slice(32,64),h=hr(We(l,32,"be"));return c[0]=dr(c[0],h),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function lr(e){const t=We(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function hr(e){return e.lte(ue.sub(e))}function dr(e,t){return t?e:128|e}function pr(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function fr(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 mr(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 gr(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=pr(e,t.publicKey,r,o);return i.sign(s),i}var yr={},wr={};class vr{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}decode(e,t){throw new Error("Layout is abstract")}encode(e,t,r){throw new Error("Layout is abstract")}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function br(e,t){return t.property?e+"["+t.property+"]":e}wr.Layout=vr,wr.nameWithProperty=br,wr.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(e.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof vr))throw new TypeError("layout must be a Layout");if(t.hasOwnProperty("boundConstructor_"))throw new Error("layout is already bound to a constructor");e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=()=>new e,Object.defineProperty(e.prototype,"encode",{value:function(e,r){return t.encode(this,e,r)},writable:1}),Object.defineProperty(e,"decode",{value:function(e,r){return t.decode(e,r)},writable:1})};class Er extends vr{isCount(){throw new Error("ExternalLayout is abstract")}}class xr extends Er{constructor(e,t){if(void 0===e&&(e=1),!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t){void 0===t&&(t=0);const r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}}class Ir extends Er{constructor(e,t,r){if(!(e instanceof vr))throw new TypeError("layout must be a Layout");if(void 0===t)t=0;else if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof Ar||this.layout instanceof Mr}decode(e,t){return void 0===t&&(t=0),this.layout.decode(e,t+this.offset)}encode(e,t,r){return void 0===r&&(r=0),this.layout.encode(e,t,r+this.offset)}}class Ar extends vr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntLE(e,r,this.span),this.span}}class Mr extends vr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntBE(e,r,this.span),this.span}}class Tr extends vr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntLE(e,r,this.span),this.span}}class Sr extends vr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntBE(e,r,this.span),this.span}}const _r=Math.pow(2,32);function Cr(e){const t=Math.floor(e/_r);return{hi32:t,lo32:e-t*_r}}function Pr(e,t){return e*_r+t}class kr extends vr{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Pr(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Cr(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class Lr extends vr{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Pr(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Cr(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Or extends vr{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Pr(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Cr(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Nr extends vr{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Pr(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Cr(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Rr extends vr{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatLE(e,r),4}}class Br extends vr{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatBE(e,r),4}}class Ur extends vr{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleLE(e,r),8}}class Dr extends vr{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleBE(e,r),8}}class Fr extends vr{constructor(e,t,r){if(!(e instanceof vr))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof Er&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(t instanceof Er)&&0<e.span&&(n=t*e.span),super(n,r),this.elementLayout=e,this.count=t}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0,n=this.count;if(n instanceof Er&&(n=n.decode(e,t)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let o=0;for(;o<n;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t){void 0===t&&(t=0);const r=[];let n=0,o=this.count;for(o instanceof Er&&(o=o.decode(e,t));n<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),n+=1;return r}encode(e,t,r){void 0===r&&(r=0);const n=this.elementLayout,o=e.reduce(((e,o)=>e+n.encode(o,t,r+e)),0);return this.count instanceof Er&&this.count.encode(e.length,t,r),o}}class qr extends vr{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof vr),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===r&&(r=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(n,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;try{r=this.fields.reduce(((r,n)=>{const o=n.getSpan(e,t);return t+=o,r+o}),0)}catch(e){throw new RangeError("indeterminate span")}return r}decode(e,t){void 0===t&&(t=0);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(e,t)),t+=n.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r){void 0===r&&(r=0);const n=r;let o=0,s=0;for(const n of this.fields){let i=n.span;if(s=0<i?i:0,void 0!==n.property){const o=e[n.property];void 0!==o&&(s=n.encode(o,t,r),0>i&&(i=n.getSpan(t,r)))}o=r,r+=i}return o+s-n}fromArray(e){const t=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}}class Vr{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class Kr extends Vr{constructor(e,t){if(!(e instanceof Er&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}}class Hr extends vr{constructor(e,t,r){const n=e instanceof Ar||e instanceof Mr;if(n)e=new Kr(new Ir(e));else if(e instanceof Er&&e.isCount())e=new Kr(e);else if(!(e instanceof Vr))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof vr))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&n&&(o+=e.layout.span)),super(o,r),this.discriminator=e,this.usesPrefixDiscriminator=n,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return s(e)},this.configGetSourceVariant=function(e){s=e.bind(this)}}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);const r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(e.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&e.hasOwnProperty(this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||e.hasOwnProperty(t.property)))return t}else for(const t in this.registry){const r=this.registry[t];if(e.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(e,t){let r;void 0===t&&(t=0);const n=this.discriminator,o=n.decode(e,t);let s=this.registry[o];if(void 0===s){let i=0;s=this.defaultLayout,this.usesPrefixDiscriminator&&(i=n.layout.span),r=this.makeDestinationObject(),r[n.property]=o,r[s.property]=this.defaultLayout.decode(e,t+i)}else r=s.decode(e,t);return r}encode(e,t,r){void 0===r&&(r=0);const n=this.getSourceVariant(e);if(void 0===n){const n=this.discriminator,o=this.defaultLayout;let s=0;return this.usesPrefixDiscriminator&&(s=n.layout.span),n.encode(e[n.property],t,r),s+o.encode(e[o.property],t,r+s)}return n.encode(e,t,r)}addVariant(e,t,r){const n=new $r(this,e,t,r);return this.registry[e]=n,n}getVariant(e,t){let r=e;return Buffer.isBuffer(e)&&(void 0===t&&(t=0),r=this.discriminator.decode(e,t)),this.registry[r]}}class $r extends vr{constructor(e,t,r,n){if(!(e instanceof Hr))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof vr))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,n),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(e,t+r)}decode(e,t){const r=this.makeDestinationObject();if(void 0===t&&(t=0),this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+n):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!e.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=n;if(this.layout&&(this.layout.encode(e[this.property],t,r+n),o+=this.layout.getSpan(t,r+n),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function jr(e){return 0>e&&(e+=4294967296),e}class zr extends vr{constructor(e,t,r){if(!(e instanceof Ar||e instanceof Mr))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===r&&(r=t,t=void 0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let n=0;this._packedSetValue=function(e){return n=jr(e),this},this._packedGetValue=function(){return n}}decode(e,t){const r=this.makeDestinationObject();void 0===t&&(t=0);const n=this.word.decode(e,t);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(n));return r}encode(e,t,r){void 0===r&&(r=0);const n=this.word.decode(t,r);this._packedSetValue(n);for(const t of this.fields)if(void 0!==t.property){const r=e[t.property];void 0!==r&&t.encode(r)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){const r=new Wr(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new Yr(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}class Wr{constructor(e,t,r){if(!(e instanceof zr))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const n=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>n)throw new Error("bits too long for span remainder ("+(n-o)+" of "+n+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=n-o-t),this.wordMask=jr(this.valueMask<<this.start),this.property=r}decode(){return jr(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==jr(e&this.valueMask))throw new TypeError(br("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=jr(e<<this.start);this.container._packedSetValue(jr(t&~this.wordMask)|r)}}class Yr extends Wr{constructor(e,t){super(e,1,t)}decode(e,t){return!!Wr.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),Wr.prototype.encode.call(this,e)}}class Zr extends vr{constructor(e,t){if(!(e instanceof Er&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof Er||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t){void 0===t&&(t=0);let r=this.span;return 0>r&&(r=this.length.decode(e,t)),e.slice(t,t+r)}encode(e,t,r){let n=this.length;if(this.length instanceof Er&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(br("Blob.encode",this)+" requires (length "+n+") Buffer as src");if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return t.write(e.toString("hex"),r,n,"hex"),this.length instanceof Er&&this.length.encode(n,t,r),n}}class Jr extends vr{constructor(e){super(-1,e)}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");void 0===t&&(t=0);let r=t;for(;r<e.length&&0!==e[r];)r+=1;return 1+r-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);return e.slice(t,t+n-1).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),t[r+o]=0,o+1}}class Qr extends vr{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");return void 0===t&&(t=0),e.length-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return e.slice(t,t+n).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),o}}class Gr extends vr{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}wr.ExternalLayout=Er,wr.GreedyCount=xr,wr.OffsetLayout=Ir,wr.UInt=Ar,wr.UIntBE=Mr,wr.Int=Tr,wr.IntBE=Sr,wr.Float=Rr,wr.FloatBE=Br,wr.Double=Ur,wr.DoubleBE=Dr,wr.Sequence=Fr,wr.Structure=qr,wr.UnionDiscriminator=Vr,wr.UnionLayoutDiscriminator=Kr,wr.Union=Hr,wr.VariantLayout=$r,wr.BitStructure=zr,wr.BitField=Wr,wr.Boolean=Yr,wr.Blob=Zr,wr.CString=Jr,wr.UTF8=Qr,wr.Constant=Gr,wr.greedy=(e,t)=>new xr(e,t),wr.offset=(e,t,r)=>new Ir(e,t,r),wr.u8=e=>new Ar(1,e),wr.u16=e=>new Ar(2,e),wr.u24=e=>new Ar(3,e),wr.u32=e=>new Ar(4,e),wr.u40=e=>new Ar(5,e),wr.u48=e=>new Ar(6,e),wr.nu64=e=>new kr(e),wr.u16be=e=>new Mr(2,e),wr.u24be=e=>new Mr(3,e),wr.u32be=e=>new Mr(4,e),wr.u40be=e=>new Mr(5,e),wr.u48be=e=>new Mr(6,e),wr.nu64be=e=>new Lr(e),wr.s8=e=>new Tr(1,e),wr.s16=e=>new Tr(2,e),wr.s24=e=>new Tr(3,e),wr.s32=e=>new Tr(4,e),wr.s40=e=>new Tr(5,e),wr.s48=e=>new Tr(6,e),wr.ns64=e=>new Or(e),wr.s16be=e=>new Sr(2,e),wr.s24be=e=>new Sr(3,e),wr.s32be=e=>new Sr(4,e),wr.s40be=e=>new Sr(5,e),wr.s48be=e=>new Sr(6,e),wr.ns64be=e=>new Nr(e),wr.f32=e=>new Rr(e),wr.f32be=e=>new Br(e),wr.f64=e=>new Ur(e),wr.f64be=e=>new Dr(e),wr.struct=(e,t,r)=>new qr(e,t,r),wr.bits=(e,t,r)=>new zr(e,t,r),wr.seq=(e,t,r)=>new Fr(e,t,r),wr.union=(e,t,r)=>new Hr(e,t,r),wr.unionLayoutDiscriminator=(e,t)=>new Kr(e,t),wr.blob=(e,t)=>new Zr(e,t),wr.cstr=e=>new Jr(e),wr.utf8=(e,t)=>new Qr(e,t),wr.const=(e,t)=>new Gr(e,t),function(t){var r=ee&&ee.__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 n=wr,o=e,s=r(ie);var i=wr;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return i.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return i.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return i.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return i.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return i.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return i.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return i.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return i.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return i.struct}});class a extends n.Layout{constructor(e,t,r){super(e,r),this.blob=(0,n.blob)(e),this.signed=t}decode(e,t=0){const r=new s.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 u(e){return new a(8,0,e)}t.u64=u,t.i64=function(e){return new a(8,1,e)},t.u128=function(e){return new a(16,0,e)},t.i128=function(e){return new a(16,1,e)},t.u256=function(e){return new a(32,0,e)},t.i256=function(e){return new a(32,1,e)};class c extends n.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 c((0,n.blob)(32),(e=>new o.PublicKey(e)),(e=>e.toBuffer()),e)};class l extends n.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,n.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 h(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function d(e){return e?1:0}function p(e){const t=(0,n.u32)("length"),r=(0,n.struct)([t,(0,n.blob)((0,n.offset)(t,-t.span),"data")]);return new c(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new l(e,t)},t.bool=function(e){return new c((0,n.u8)(),h,d,e)},t.vec=function(e,t){const r=(0,n.u32)("length"),o=(0,n.struct)([r,(0,n.seq)(e,(0,n.offset)(r,-r.span),"values")]);return new c(o,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const o=(0,n.struct)([u("tag"),t.replicate("data")]);return new c(o,(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=p,t.str=function(e){return new c(p(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const o=(0,n.union)(null!=r?r:(0,n.u8)(),t);return e.forEach(((e,t)=>o.addVariant(t,e,e.property))),o},t.array=function(e,t,r){const o=(0,n.struct)([(0,n.seq)(e,t,"values")]);return new c(o,(({values:e})=>e),(e=>({values:e})),r)};class f extends n.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 o=(0,n.u32)("length"),s=(0,n.struct)([o,(0,n.seq)(new f(e,t),(0,n.offset)(o,-o.span),"values")]);return new c(s,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(yr);const Xr=yr.struct([yr.publicKey("owner"),yr.u64("lamports"),yr.option(yr.array(yr.u8(),32),"address"),yr.option(yr.struct([yr.array(yr.u8(),8,"discriminator"),yr.vecU8("data"),yr.array(yr.u8(),32,"dataHash")]),"data")],"compressedAccount"),en=yr.struct([yr.u8("merkleTreePubkeyIndex"),yr.u8("nullifierQueuePubkeyIndex"),yr.u32("leafIndex"),yr.option(yr.struct([yr.u8("queueId"),yr.u16("index")]),"queueIndex")],"merkleContext"),tn=yr.struct([yr.array(yr.u8(),32,"seed"),yr.u8("addressQueueAccountIndex"),yr.u8("addressMerkleTreeAccountIndex"),yr.u16("addressMerkleTreeRootIndex")],"newAddressParams"),rn=yr.struct([yr.option(yr.struct([yr.array(yr.u8(),32,"a"),yr.array(yr.u8(),64,"b"),yr.array(yr.u8(),32,"c")]),"proof"),yr.vec(yr.struct([Xr,en,yr.u16("rootIndex"),yr.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),yr.vec(yr.struct([Xr,yr.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yr.option(yr.u64(),"relayFee"),yr.vec(tn,"newAddressParams"),yr.option(yr.u64(),"compressOrDecompressLamports"),yr.bool("isCompress")]);function nn(e){const t=g.alloc(1e3),r=rn.encode(e,t),n=g.from(new Uint8Array(t.slice(0,r))),o=g.alloc(4);return o.writeUInt32LE(r,0),g.concat([new Uint8Array(he),new Uint8Array(o),new Uint8Array(n)])}const on=yr.struct([yr.option(yr.struct([yr.array(yr.u8(),32,"a"),yr.array(yr.u8(),64,"b"),yr.array(yr.u8(),32,"c")]),"proof"),yr.vec(tn,"newAddressParams"),yr.vec(yr.struct([Xr,en,yr.u16("rootIndex"),yr.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),yr.vec(yr.struct([Xr,yr.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yr.option(yr.u64(),"relayFee"),yr.option(yr.u64(),"compressOrDecompressLamports"),yr.bool("isCompress"),yr.option(yr.struct([yr.bool("set_context"),yr.bool("first_set_context"),yr.u8("cpi_context_account_index")]),"compressedCpiContext")]);function sn(e){return rn.decode(e.slice(he.length+4))}function an(e){return on.decode(e.slice(de.length+4))}const un=e=>{const t=bn.programId,{feePayer:r,authority:n,registeredProgramPda:o,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:c,systemProgram:l}=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!=c?c:t,isSigner:0,isWritable:1},{pubkey:l,isSigner:0,isWritable:0}]},cn=yr.struct([yr.vec(yr.array(yr.u8(),32),"inputCompressedAccountHashes"),yr.vec(yr.array(yr.u8(),32),"outputCompressedAccountHashes"),yr.vec(yr.struct([yr.struct([yr.publicKey("owner"),yr.u64("lamports"),yr.option(yr.array(yr.u8(),32),"address"),yr.option(yr.struct([yr.array(yr.u8(),8,"discriminator"),yr.vecU8("data"),yr.array(yr.u8(),32,"dataHash")]),"data")],"compressedAccount"),yr.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yr.vec(yr.u32(),"outputLeafIndices"),yr.vec(yr.struct([yr.publicKey("pubkey"),yr.u64("seq")]),"sequenceNumbers"),yr.option(yr.u64(),"relayFee"),yr.bool("isCompress"),yr.option(yr.u64(),"compressOrDecompressLamports"),yr.vec(yr.publicKey(),"pubkeyArray"),yr.option(yr.vecU8(),"message")]);function ln(e){return cn.decode(e)}const hn=yr.struct([yr.u8("is_invoked_by_program"),yr.u8("bump"),yr.u8("num_queues"),yr.u8("num_output_queues"),yr.u8("start_output_appends"),yr.u8("num_address_queues"),yr.array(yr.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),dn=yr.struct([yr.u8("index"),yr.array(yr.u8(),32,"leaf")],"appendLeavesInput"),pn=yr.struct([yr.array(yr.u8(),32,"account_hash"),yr.u32("leaf_index"),yr.u8("prove_by_index"),yr.u8("tree_index"),yr.u8("queue_index")],"insertNullifierInput"),fn=yr.struct([yr.array(yr.u8(),32,"address"),yr.u8("tree_index"),yr.u8("queue_index")],"insertAddressInput"),mn=yr.struct([yr.publicKey("pubkey"),yr.u64("seq")],"merkleTreeSequenceNumber");function gn(e){let t=0;const r=hn.decode(e,t);t+=hn.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=dn.decode(e,t);o.push(r),t+=dn.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=pn.decode(e,t);i.push(r),t+=pn.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=fn.decode(e,t);u.push(r),t+=fn.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=mn.decode(e,t);l.push(r),t+=mn.span}const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)mn.decode(e,t),t+=mn.span;const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)mn.decode(e,t),t+=mn.span;const p=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<p;r++){const r=yr.u32().decode(e,t);f.push(r),t+=4}return{meta:r,leaves:o,nullifiers:i,addresses:u,sequence_numbers:l,output_leaf_indices:f}}function yn(t,r,n){const o=e=>Array.from(e instanceof g?new Uint8Array(e):e);return{inputCompressedAccountHashes:t.nullifiers.map((e=>o(e.account_hash))),outputCompressedAccountHashes:t.leaves.map((e=>o(e.leaf))),outputCompressedAccounts:t.leaves.map(((t,r)=>{var s,i,a,u,c,l;return{compressedAccount:{owner:new e.PublicKey((null===(s=null==n?void 0:n.outputCompressedAccounts[r])||void 0===s?void 0:s.compressedAccount.owner)||e.PublicKey.default),lamports:We((null===(i=null==n?void 0:n.outputCompressedAccounts[r])||void 0===i?void 0:i.compressedAccount.lamports)||0),address:null==n?void 0:n.outputCompressedAccounts[r].compressedAccount.address,data:(null===(a=null==n?void 0:n.outputCompressedAccounts[r])||void 0===a?void 0:a.compressedAccount.data)?{discriminator:o(g.from(null===(u=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===u?void 0:u.discriminator)),data:null!==(c=o(g.from(new Uint8Array(n.outputCompressedAccounts[r].compressedAccount.data.data))))&&void 0!==c?c:[],dataHash:o(g.from(null===(l=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===l?void 0:l.dataHash))}:null},merkleTreeIndex:t.index}})),outputLeafIndices:t.output_leaf_indices,sequenceNumbers:t.sequence_numbers.map((t=>({pubkey:new e.PublicKey(t.pubkey),seq:We(t.seq)}))),pubkeyArray:r.slice(2).filter((t=>!t.equals(e.PublicKey.default))),isCompress:(null==n?void 0:n.isCompress)||0,relayFee:(null==n?void 0:n.relayFee)?We(n.relayFee):null,compressOrDecompressLamports:(null==n?void 0:n.compressOrDecompressLamports)?We(n.compressOrDecompressLamports):null,message:null}}const wn=e=>e.reduce(((e,t)=>e.add(We(t.lamports))),We(0)),vn=g.from("sol_pool_pda");class bn{constructor(){}static deriveCompressedSolPda(){const t=[vn],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=We(r);const n=wn(e).sub(r);return tt(n),n.eq(We(0))?[Ye(t,r)]:(rt(e),[Ye(e[0].owner,n),Ye(t,r)])}static createDecompressOutputState(e,t){t=We(t);const r=wn(e).sub(t);return tt(r),r.eq(We(0))?[]:(rt(e),[Ye(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=We(null!=r?r:0);const o=wn(null!=n?n:[]).sub(r);return tt(o),o.eq(We(0))||!n?[Ye(t,r,void 0,e)]:(rt(n),[Ye(n[0].owner,o),Ye(t,r,void 0,e)])}static async createAccount({payer:t,newAddressParams:r,newAddress:n,recentValidityProof:o,outputStateTreeInfo:s,inputCompressedAccounts:i,inputStateRootIndices:a,lamports:u}){const c=this.createNewAddressOutputState(n,t,u,i),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:h,remainingAccounts:d}=et(null!=i?i:[],null!=a?a:[],c,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:f}=nr([r],d),m=nn({proof:o,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:h,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),g=[...un(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Xe(f)];return new e.TransactionInstruction({programId:this.programId,keys:g,data:m})}static async transfer({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){const a=this.createTransferOutputState(r,n,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=et(r,s,a),h=nn({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),d=[...un(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Xe(l)];return new e.TransactionInstruction({programId:this.programId,keys:d,data:h})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTreeInfo:o}){n=We(n);const s=Ye(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=et([],[],[s],o),c=nn({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),l=[...un(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:bn.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Xe(u)];return new e.TransactionInstruction({programId:this.programId,keys:l,data:c})}static async decompress({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){o=We(o);const a=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=et(r,s,a),h=nn({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),d=[...un(Object.assign(Object.assign({},ve()),{feePayer:t,authority:t,solPoolPda:bn.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),...Xe(l)];return new e.TransactionInstruction({programId:this.programId,keys:d,data:h})}}function En(e,t){let r=We(0);t=We(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(We(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(We(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}bn.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");class xn{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([We(this.value.toArray("be",32)).toString(),We(this.nextIndex).toString(),We(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class In{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class An{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new An([new xn(0,We(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=ce;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([We(r.value.toArray("be",32)).toString(),We(r.nextIndex).toString(),We(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 xn(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new In(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 Mn{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 Tn(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=ve(),o=(await e.getConfirmedSignaturesForAddress2(n,void 0,"confirmed")).map((e=>e.signature)),s=await e.getParsedTransactions(o,{maxSupportedTransactionVersion:0,commitment:"confirmed"});for(const r of s){if(!r||!r.transaction||!r.meta)continue;if(!r.meta.innerInstructions||0==r.meta.innerInstructions.length)continue;const n=r.transaction.message.accountKeys.map((e=>e.pubkey)),o=[],s=await e.getTransaction(r.transaction.signatures[0],{commitment:"confirmed",maxSupportedTransactionVersion:0});for(const e of(null==s?void 0:s.transaction.message.compiledInstructions)||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===le.length&&le.every(((e,r)=>e===t[r])))continue;o.push(t)}const i=[];if(s.meta.innerInstructions&&s.meta.innerInstructions.length>0)for(const e of s.meta.innerInstructions)for(const t of e.instructions){const e=t.accounts.map((e=>n[e]));if(i.push(e),t.data&&t.data.length>0){const e=$e.decode(t.data);o.push(e)}}const a=Cn(o,i);a&&t.push(a)}if(t.length>0)return t;const i=s.filter((e=>e?e.transaction.message.accountKeys.some((e=>("string"==typeof e?e:e.pubkey.toBase58())===r.toBase58())):0));return Sn(i,_n)}const Sn=(e,t)=>{const{noopProgram:r}=ve(),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=$e.decode(s.data),o=t(g.from(r),e);null!=o&&n.push(o)}}}))})),n},_n=e=>{const t=g.from(e.map((e=>e)));try{return ln(t)}catch(e){return console.error("Error deserializing event:",e),null}};function Cn(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=$e.encode(e),s=$e.encode(he),i=$e.encode(de);if(o===s){n=sn(g.from(t)),r=1;break}if(o==i){n=an(g.from(t)),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if($e.encode(e)===$e.encode(pe)){const e=t.slice(12);o=gn(g.from(e))}}return n?yn(o,t[t.length-1],n):null}function Pn(e,t){if(e.some((e=>e.queue.equals(t))))throw new Error("Checking by queue not supported yet");const r=e.findIndex((e=>e.tree.equals(t)));if(-1!==r){const{queue:t,treeType:n}=e[r];if(!t)throw new Error("Queue must not be null for state tree");return{queue:t,treeType:n,tree:e[r].tree,cpiContext:e[r].cpiContext,nextTreeInfo:e[r].nextTreeInfo}}throw new Error(`No associated StateTreeInfo found for tree or queue. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: ${t.toBase58()}`)}async function kn(e,t){return(await Ln(e)).find((e=>We(e.hash).eq(t)))}async function Ln(t){var r,n;const o=(await Tn(t)).reverse(),s=[],i=[],a=await t.getStateTreeInfos();for(const t of o){for(let o=0;o<t.outputCompressedAccounts.length;o++){const i=t.pubkeyArray[t.outputCompressedAccounts[o].merkleTreeIndex],u=Pn(a,new e.PublicKey(i)),c=t.outputCompressedAccounts[o],l={treeInfo:u,hash:We(t.outputCompressedAccountHashes[o]),leafIndex:t.outputLeafIndices[o],proveByIndex:0},h=Ze(l,c.compressedAccount.owner,c.compressedAccount.lamports,null!==(r=c.compressedAccount.data)&&void 0!==r?r:void 0,null!==(n=c.compressedAccount.address)&&void 0!==n?n:void 0);s.push(h)}for(let e=0;e<t.inputCompressedAccountHashes.length;e++){const r=t.inputCompressedAccountHashes[e];i.push(We(r))}}const u=s.filter((e=>!i.some((t=>t.eq(We(e.hash))))));return u.sort(((e,t)=>t.leafIndex-e.leafIndex)),u}const On=yr.struct([yr.publicKey("mint"),yr.publicKey("owner"),yr.u64("amount"),yr.option(yr.publicKey(),"delegate"),yr.u8("state"),yr.option(yr.vecU8(),"tlv")]);function Nn(e,t=Me){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`);try{return On.decode(Buffer.from(r))}catch(e){throw console.error("Decoding error:",e),e}}async function Rn(e,t){const r=await Promise.all(e.map((e=>async function(e,t){const r=e.pubkeyArray,n=await t.getStateTreeInfos(),o=e.outputCompressedAccountHashes,s=e.outputCompressedAccounts.map(((t,s)=>{var i;const a=r[e.outputCompressedAccounts[s].merkleTreeIndex],u=Pn(n,a);if(!u.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex]))throw new Error("Invalid tree");const c={treeInfo:u,hash:We(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:0};if(!t.compressedAccount.data)throw new Error("No data");const l=Nn(t.compressedAccount);if(!l)throw new Error("Invalid token data");return{compressedAccount:Ze(c,t.compressedAccount.owner,t.compressedAccount.lamports,t.compressedAccount.data,null!==(i=t.compressedAccount.address)&&void 0!==i?i:void 0),parsed:l}}));return{inputCompressedAccountHashes:e.inputCompressedAccountHashes,outputCompressedAccounts:s}}(e,t)))),n=r.flatMap((e=>e.outputCompressedAccounts)),o=r.flatMap((e=>e.inputCompressedAccountHashes));return n.filter((e=>!o.some((t=>We(t).eq(e.compressedAccount.hash)))))}async function Bn(e,t,r){const n=await Tn(e);return{items:(await Rn(n,e)).filter((e=>e.parsed.owner.equals(t)&&e.parsed.mint.equals(r))).sort(((e,t)=>e.compressedAccount.leafIndex-t.compressedAccount.leafIndex)),cursor:null}}async function Un(e,t,r){const n=await Tn(e);return{items:(await Rn(n,e)).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 Dn(e,t){const r=await Tn(e),n=(await Rn(r,e)).filter((e=>We(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class Fn extends TypeError{constructor(e,t){let r;const{message:n,explanation:o,...s}=e,{path:i}=e,a=0===i.length?n:`At path: ${i.join(".")} -- ${n}`;super(o??a),null!=o&&(this.cause=a),Object.assign(this,s),this.name=this.constructor.name,this.failures=()=>r??(r=[e,...t()])}}function qn(e){return"object"==typeof e&&null!=e}function Vn(e){return qn(e)&&!Array.isArray(e)}function Kn(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Hn(e,t,r,n){if(1==e)return;0==e?e={}:"string"==typeof e&&(e={message:e});const{path:o,branch:s}=t,{type:i}=r,{refinement:a,message:u=`Expected a value of type \`${i}\`${a?` with refinement \`${a}\``:""}, but received: \`${Kn(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*$n(e,t,r,n){var o;qn(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Hn(o,t,r,n);e&&(yield e)}}function*jn(e,t,r={}){const{path:n=[],branch:o=[e],coerce:s=0,mask:i=0}=r,a={path:n,branch:o,mask:i};s&&(e=t.coercer(e,a));let u="valid";for(const n of t.validator(e,a))n.explanation=r.message,u="not_valid",yield[n,void 0];for(let[c,l,h]of t.entries(e,a)){const t=jn(l,h,{path:void 0===c?n:[...n,c],branch:void 0===c?o:[...o,l],coerce:s,mask:i,message:r.message});for(const r of t)r[0]?(u=null!=r[0].refinement?"not_refined":"not_valid",yield[r[0],void 0]):s&&(l=r[1],void 0===c?e=l:e instanceof Map?e.set(c,l):e instanceof Set?e.add(l):qn(e)&&(void 0!==l||c in e)&&(e[c]=l))}if("not_valid"!==u)for(const n of t.refiner(e,a))n.explanation=r.message,u="not_refined",yield[n,void 0];"valid"===u&&(yield[void 0,e])}class zn{constructor(e){const{type:t,schema:r,validator:n,refiner:o,coercer:s=(e=>e),entries:i=function*(){}}=e;this.type=t,this.schema=r,this.entries=i,this.coercer=s,this.validator=n?(e,t)=>$n(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>$n(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Zn(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Wn(e,this,t)}is(e){return Yn(e,this)}mask(e,t){return function(e,t,r){const n=Zn(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Zn(e,this,t)}}function Wn(e,t,r){const n=Zn(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function Yn(e,t){return!Zn(e,t)[0]}function Zn(e,t,r={}){const n=jn(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new Fn(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function Jn(e,t){return new zn({type:e,schema:null,validator:t})}function Qn(){return Jn("any",(()=>1))}function Gn(e){return new zn({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[r,n]of t.entries())yield[r,n,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||`Expected an array value, but received: ${Kn(e)}`})}function Xn(e){return Jn("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${Kn(t)}`))}function eo(e){const t=Kn(e);return new zn({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${Kn(r)}`})}function to(e){return new zn({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function ro(){return Jn("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${Kn(e)}`))}function no(){return Jn("string",(e=>"string"==typeof e||`Expected a string, but received: ${Kn(e)}`))}function oo(e){const t=Object.keys(e);return new zn({type:"type",schema:e,*entries(r){if(qn(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>Vn(e)||`Expected an object, but received: ${Kn(e)}`,coercer:e=>Vn(e)?{...e}:e})}function so(e){const t=e.map((e=>e.type)).join(" | ");return new zn({type:"union",schema:null,coercer(t,r){for(const n of e){const[e,o]=n.validate(t,{coerce:1,mask:r.mask});if(!e)return o}return t},validator(r,n){const o=[];for(const t of e){const[...e]=jn(r,t,n),[s]=e;if(!s[0])return[];for(const[t]of e)t&&o.push(t)}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${Kn(r)}`,...o]}})}function io(){return Jn("unknown",(()=>1))}function ao(e,t,r){return new zn({...e,coercer:(n,o)=>Yn(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}const uo=ao(Xn(e.PublicKey),no(),(t=>new e.PublicKey(t))),co=ao(Xn(Array),no(),(t=>Array.from(new e.PublicKey(t).toBytes()))),lo=ao(Xn(ae),no(),(e=>je(e,"base58"))),ho=ao(Xn(ae),so([no(),ro()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return We(e)}return We(e,10)})),po=ao(no(),no(),(e=>""===e?null:e));function fo(e){return so([oo({jsonrpc:eo("2.0"),id:no(),result:e}),oo({jsonrpc:eo("2.0"),id:no(),error:oo({code:io(),message:no(),data:to(Qn())})})])}const mo=fo(io());function go(e){return ao(fo(e),mo,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:Wn(t.result,e)})))}function yo(e){return go(oo({context:oo({slot:ro()}),value:e}))}const wo=oo({address:to(co),hash:lo,data:to(oo({data:po,dataHash:lo,discriminator:ho})),lamports:ho,owner:uo,leafIndex:ro(),tree:uo,seq:to(ho),slotCreated:ho}),vo=oo({mint:uo,owner:uo,amount:ho,delegate:to(uo),state:no()}),bo=oo({tokenData:vo,account:wo}),Eo=oo({items:Gn(wo)}),xo=oo({items:Gn(wo),cursor:to(no())}),Io=oo({items:Gn(bo),cursor:to(no())}),Ao=ro(),Mo=no(),To=oo({items:Gn(oo({signature:no(),slot:ro(),blockTime:ro(),error:to(no())}))}),So=oo({items:Gn(oo({signature:no(),slot:ro(),blockTime:ro()})),cursor:to(no())}),_o=oo({hash:lo,leafIndex:ro(),merkleTree:uo,proof:Gn(lo),rootSeq:ro(),root:lo}),Co=oo({address:lo,nextIndex:ro(),merkleTree:uo,proof:Gn(lo),rootSeq:ro(),root:lo,lowerRangeAddress:lo,higherRangeAddress:lo,lowElementLeafIndex:ro()}),Po=oo({a:Gn(ro()),b:Gn(ro()),c:Gn(ro())}),ko=oo({compressedProof:Po,leafIndices:Gn(ro()),leaves:Gn(lo),rootIndices:Gn(ro()),roots:Gn(lo),merkleTrees:Gn(uo)}),Lo=Gn(_o),Oo=oo({amount:ho}),No=ho,Ro=oo({balance:ho,mint:uo}),Bo=oo({tokenBalances:Gn(Ro),cursor:to(no())}),Uo=oo({items:Gn(Ro),cursor:to(no())}),Do=oo({cursor:to(no()),items:Gn(oo({balance:ho,owner:uo}))}),Fo=oo({hash:Gn(ro()),root:Gn(ro()),proof:Gn(Gn(ro()))}),qo=oo({items:Gn(oo({blockTime:ro(),signature:no(),slot:ro()}))}),Vo=oo({items:Gn(oo({blockTime:ro(),signature:no(),slot:ro()})),cursor:to(no())}),Ko=oo({compressionInfo:oo({closedAccounts:Gn(oo({account:wo,optionalTokenData:to(vo)})),openedAccounts:Gn(oo({account:wo,optionalTokenData:to(vo)}))}),transaction:Qn()});function Ho({discriminator:e,data:t,dataHash:r}){return{discriminator:e.toArray("le",8),data:g.from(t,"base64"),dataHash:r.toArray("le",32)}}async function $o(t,r,n,o=0){var s,i;const a=o?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner",u=o?"delegate":"owner",c=Wn(await Wo(t.compressionApiEndpoint,a,{[u]:r.toBase58(),mint:null===(s=n.mint)||void 0===s?void 0:s.toBase58(),limit:null===(i=n.limit)||void 0===i?void 0:i.toNumber(),cursor:n.cursor}),yo(Io));if("error"in c)throw new e.SolanaJSONRPCError(c.error,`failed to get info for compressed accounts by ${u} ${r.toBase58()}`);if(null===c.result.value)throw new Error("not implemented: NULL result");const l=[],h=await t.getStateTreeInfos();return c.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=Pn(h,n.tree),i=Ze(Je(s,n.hash,n.leafIndex),n.owner,We(n.lamports),n.data?Ho(n.data):void 0,n.address||void 0),a={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=a[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);l.push({compressedAccount:i,parsed:a})})),{items:l.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:c.result.value.cursor}}function jo(e,t){const r=e.account,n=e.optionalTokenData,o=Pn(t,r.tree),s=Ze(Je(o,r.hash,r.leafIndex),r.owner,We(r.lamports),r.data?Ho(r.data):void 0,r.address||void 0);return null===n?{account:s,maybeTokenData:null}:{account:s,maybeTokenData:{mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null}}}function zo(e){return e.replace(/(":\s*)(-?\d+)(\s*[},])/g,((e,t,r,n)=>{const o=Number(r);return!Number.isNaN(o)&&(o>Number.MAX_SAFE_INTEGER||o<Number.MIN_SAFE_INTEGER)?`${t}"${r}"${n}`:e}))}const Wo=async(e,t,r=[],n=1,o=0)=>{const s=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:t,params:r});if(o){const t=()=>{const t=s.replace(/"/g,'\\"');return`curl -X POST ${e} \\\n -H "Content-Type: application/json" \\\n -d "${t}"`};console.log("Debug: Stack trace:"),console.log((new Error).stack),console.log("\nDebug: curl:"),console.log(t()),console.log("\n")}const i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:s});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const a=zo(await i.text());return n?Gt(JSON.parse(a)):JSON.parse(a)},Yo=async(e,t,r=[],n=0)=>{let o,s="";n&&(s=`Proof generation for method:${t}`,console.time(s)),"inclusion"===t?o=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===t?o=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===t&&(o=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const i=await fetch(`${e}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:o});if(!i.ok)throw new Error(`Error fetching proof: ${i.statusText}`);const a=cr(ur(await i.json()));return n&&console.timeEnd(s),a};function Zo(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Jt(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>Jt(e))),leaf:Jt(We(e[r].hash))};t.push(n)}return t}function Jo(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Jt(e[r].root),value:Jt(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>Jt(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:Jt(e[r].leafLowerRangeValue),leafHigherRangeValue:Jt(e[r].leafHigherRangeValue)};t.push(n)}return t}function Qo(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return We(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}class Go extends e.Connection{constructor(e,t,r,n){super(e,n||"confirmed"),this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.CACHE_TTL=36e5,this.fetchPromise=null,this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(Ee(this.rpcEndpoint))return xe();if(this.allStateTreeInfos&&this.lastStateTreeFetchTime&&Date.now()-this.lastStateTreeFetchTime<=this.CACHE_TTL)return this.allStateTreeInfos;if(this.fetchPromise)return this.fetchPromise;let e;try{return this.fetchPromise=this.doFetch(),e=await this.fetchPromise,this.allStateTreeInfos=e,this.lastStateTreeFetchTime=Date.now(),e}finally{this.fetchPromise=null}}async doFetch(){const{mainnet:e,devnet:t}=be();try{return await ar({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await ar({connection:this,stateTreeLUTPairs:[t[0]]})}catch(t){throw new Error(`Failed to fetch state tree infos from both mainnet and devnet. Mainnet error: ${e}. Devnet error: ${t}`)}}}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 n=Wn(await Wo(this.compressionApiEndpoint,"getCompressedAccount",{hash:r?ze(r):void 0,address:t?ze(t):void 0}),yo(to(wo)));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===n.result.value)return null;const o=Pn(await this.getStateTreeInfos(),n.result.value.tree),s=n.result.value;return Ze(Je(o,s.hash,s.leafIndex),s.owner,We(s.lamports),s.data?Ho(s.data):void 0,s.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 n=Wn(await Wo(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?ze(r):void 0,address:t?ze(t):void 0}),yo(No));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get balance for compressed account ${r?r.toString():t?t.toString():""}`);return null===n.result.value?We(0):We(n.result.value)}async getCompressedBalanceByOwner(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),yo(No));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?We(0):We(r.result.value)}async getCompressedAccountProof(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getCompressedAccountProof",{hash:ze(t)}),yo(_o));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proof for compressed account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const n=Pn(await this.getStateTreeInfos(),r.result.value.merkleTree);return{hash:We(r.result.value.hash.toArray("be",32)),treeInfo:n,leafIndex:r.result.value.leafIndex,merkleProof:r.result.value.proof,rootIndex:r.result.value.rootSeq%2400,root:r.result.value.root,proveByIndex:0}}async getMultipleCompressedAccounts(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getMultipleCompressedAccounts",{hashes:t.map((e=>ze(e)))}),yo(Eo));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get info for compressed accounts ${t.map((e=>ze(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>ze(e))).join(", ")}`);const n=await this.getStateTreeInfos(),o=[];return r.result.value.items.map((e=>{const t=Pn(n,e.tree),r=Ze(Je(t,We(e.hash.toArray("be",32)),e.leafIndex),e.owner,We(e.lamports),e.data?Ho(e.data):void 0,e.address||void 0);o.push(r)})),o.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getMultipleCompressedAccountProofs",t.map((e=>ze(e)))),yo(Gn(_o)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for compressed accounts ${t.map((e=>ze(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>ze(e))).join(", ")}`);const n=[],o=await this.getStateTreeInfos();for(const e of r.result.value){const t=Pn(o,e.merkleTree),r={hash:We(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:0};n.push(r)}return n}async getCompressedAccountsByOwner(t,r){var n;const o=Wn(await Wo(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===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),yo(xo));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===o.result.value)return{items:[],cursor:null};const s=[],i=await this.getStateTreeInfos();return o.result.value.items.map((e=>{const t=Pn(i,e.tree),r=Ze(Je(t,We(e.hash.toArray("be",32)),e.leafIndex),e.owner,We(e.lamports),e.data?Ho(e.data):void 0,e.address||void 0);s.push(r)})),{items:s.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:o.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await $o(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await $o(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:ze(t)}),yo(Oo));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed token account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get balance for compressed token account ${t.toString()}`);return{amount:We(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var n,o;r||(r={});const s=Wn(await Wo(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),yo(Bo));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);return{items:r.mint?s.result.value.tokenBalances.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.tokenBalances,cursor:s.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(t,r){var n,o;r||(r={});const s=Wn(await Wo(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),yo(Uo));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);const i=r.mint?s.result.value.items.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.items;return{context:s.result.context,value:{items:i,cursor:s.result.value.cursor}}}async getCompressionSignaturesForAccount(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:ze(t)}),yo(qo));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get signatures for compressed account ${t.toString()}`);return r.result.value.items}async getTransactionWithCompressionInfo(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getTransactionWithCompressionInfo",{signature:t}),go(Ko));if("error"in r)throw new e.SolanaJSONRPCError(r.error,"failed to get slot");if(null===r.result.transaction)return null;const n=[],o=[],s=await this.getStateTreeInfos();r.result.compressionInfo.closedAccounts.map((e=>{n.push(jo(e,s))})),r.result.compressionInfo.openedAccounts.map((e=>{o.push(jo(e,s))}));const i=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},a=i(n),u=i(o);return{compressionInfo:{closedAccounts:n,openedAccounts:o,preTokenBalances:a,postTokenBalances:u},transaction:r.result.transaction}}async getCompressionSignaturesForAddress(t,r){var n;const o=Wn(await Wo(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),yo(Vo));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for address ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for address ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForOwner(t,r){var n;const o=Wn(await Wo(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),yo(Vo));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForTokenOwner(t,r){var n;const o=Wn(await Wo(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),yo(Vo));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getIndexerHealth(){const t=Wn(await Wo(this.compressionApiEndpoint,"getIndexerHealth"),go(Mo));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.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=Wn(await Wo(this.compressionApiEndpoint,"getIndexerSlot"),go(Ao));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get slot");return t.result}async getCompressedMintTokenHolders(t,r){var n;const o=Wn(await Wo(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),yo(Do));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get mint token holders");return o.result}async getLatestCompressionSignatures(t,r){const n=Wn(await Wo(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),yo(So));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getLatestNonVotingSignatures(t,r){const n=Wn(await Wo(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),yo(To));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getMultipleNewAddressProofs(t){const r=Wn(await Wo(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>ze(e)))),yo(Gn(Co)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>ze(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>ze(e))).join(", ")}`);const n=[];for(const e of r.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:We(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:We(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:Ae().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};n.push(t)}return n}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=Zo(t);r={compressedProof:await Yo(this.proverEndpoint,"inclusion",n,0),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>We(e.hash))),treeInfos:t.map((e=>e.treeInfo))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Jo(e);r={compressedProof:await Yo(this.proverEndpoint,"new-address",n,0),roots:e.map((e=>e.root)),rootIndices:e.map((e=>e.rootIndex)),leafIndices:e.map((e=>e.nextIndex.toNumber())),leaves:e.map((e=>We(e.value))),treeInfos:e.map((e=>e.treeInfo))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=Zo(n),s=await this.getMultipleNewAddressProofs(t),i=Jo(s),a=await Yo(this.proverEndpoint,"combined",[o,i],0),u=[...n.map((e=>e.treeInfo)),...s.map((e=>e.treeInfo))];r={compressedProof:a,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=>We(e.hash))).concat(s.map((e=>We(e.value)))),treeInfos:u}}}return r}async getValidityProof(e=[],t=[]){const r=await this.getMultipleCompressedAccounts(e),n=r.map((e=>e.treeInfo.tree)),o=r.map((e=>e.treeInfo.queue)),s=Ae().addressTree,i=Ae().addressQueue,a=e.map(((e,t)=>({hash:e,tree:n[t],queue:o[t]}))),u=t.map((e=>({address:e,tree:s,queue:i})));return this.getValidityProofV0(a,u)}async getValidityProofV0(e=[],t=[]){const{value:r}=await this.getValidityProofAndRpcContext(e,t);return r}async getValidityProofAndRpcContext(t=[],r=[]){nt(t.length,r.length);const n=await this.getStateTreeInfos(),o=Wn(await Wo(this.compressionApiEndpoint,"getValidityProof",{hashes:t.map((({hash:e})=>ze(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:ze(e),tree:t.toBase58()})))}),yo(ko));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const s=o.result.value;if(null===s)throw new Error(`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const i=[...t.map((({tree:e})=>{const t=Pn(n,e);return{tree:e,queue:t.queue,treeType:t.treeType,nextTreeInfo:t.nextTreeInfo}})),...r.map((({tree:e,queue:t})=>({tree:e,queue:t,treeType:exports.TreeType.AddressV1,nextTreeInfo:null})))];return{value:{compressedProof:s.compressedProof,treeInfos:i,leafIndices:s.leafIndices,rootIndices:s.rootIndices,roots:s.roots,leaves:s.leaves},context:o.result.context}}}class Xo extends e.Connection{constructor(e,t,r,n,o,s){super(e,o||"confirmed"),this.log=0,this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.fetchPromise=null,this.CACHE_TTL=36e5,this.compressionApiEndpoint=r,this.proverEndpoint=n;const{depth:i,log:a}=null!=s?s:{},{merkleTreeHeight:u}=Ae();this.lightWasm=t,this.depth=null!=i?i:u,this.log=null!=a?a:0}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return xe()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}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 kn(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 kn(this,t);if(!r)throw new Error("Account not found");return We(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),We(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await Ln(e)).filter((e=>t.some((t=>We(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(t){const r=await Tn(this).then((e=>e.reverse())),n=new Map,o=await this.getStateTreeInfos();for(const e of r)for(let t=0;t<e.outputCompressedAccounts.length;t++){const r=e.outputCompressedAccountHashes[t],s=Pn(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]);n.has(s.tree.toBase58())||n.set(s.tree.toBase58(),{leaves:[],leafIndices:[],treeType:s.treeType,queue:s.queue});const i=n.get(s.tree.toBase58());if(!i)throw new Error(`Tree not found: ${s.tree.toBase58()}`);i.leaves.push(r),i.leafIndices.push(e.outputLeafIndices[t])}const s=new Map;for(const[r,{leaves:i,treeType:a,queue:u}]of n.entries()){const n=new e.PublicKey(r);let u;if(a!==exports.TreeType.StateV1)throw new Error(`Unsupported tree type: ${a} in test-rpc.ts`);u=new Mn(this.depth,this.lightWasm,i.map((e=>We(e).toString())));for(let e=0;e<t.length;e++){const r=i.findIndex((r=>We(r).eq(t[e]))),c=Pn(o,n);if(-1!==r&&a===exports.TreeType.StateV1){const n=u.path(r).pathElements.map((e=>We(e))),o=We(u.root()),a={hash:We(t[e].toArray("be",32)),treeInfo:c,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:i.length,root:o};s.set(t[e].toString(),a)}}}return s.forEach(((e,t)=>{const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=We(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)})),t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`No proof found for hash: ${e.toString()}`);return t}))}async getCompressedAccountsByOwner(e,t){const r=await async function(e,t){return(await Ln(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 Bn(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await Un(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await Dn(this,e);return{amount:We(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await Bn(this,e,t.mint)).items.map((e=>({balance:We(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await Bn(this,e,t.mint)).items.map((e=>({balance:We(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=An.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(We(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(We(r))}const o=new Mn(this.depth,this.lightWasm,n.map((e=>We(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=>We(e))),u=t.get(n.nextIndex).value,c={root:We(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:We(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:We(n.index),treeInfo:{tree:Ae().addressTree,queue:Ae().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};s.push(c)}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 ae))))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 ae))))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=Zo(t);r={compressedProof:await Yo(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=>We(e.hash))),treeInfos:t.map((e=>e.treeInfo))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Jo(e);r={compressedProof:await Yo(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=>We(e.value))),treeInfos:e.map((e=>e.treeInfo))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=Zo(n),s=await this.getMultipleNewAddressProofs(t),i=Jo(s);r={compressedProof:await Yo(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=>We(e.hash))).concat(s.map((e=>We(e.value)))),treeInfos:n.map((e=>e.treeInfo)).concat(s.map((e=>e.treeInfo)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}}let es=1;const ts=ss(255),rs=ss(254),ns=ss(253),os=ss(252);function ss(t){if(t||(t=es,es++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var is,as,us,cs,ls,hs,ds,ps;exports.UtxoErrorCode=void 0,(is=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",is.NOT_U64="NOT_U64",is.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(as=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",as.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(us=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",us.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",us.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(cs=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",cs.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",cs.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",cs.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(ls=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",ls.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,(hs=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",hs.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",hs.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(ds=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",ds.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",ds.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",ds.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",ds.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",ds.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(ps=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",ps.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",ps.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",ps.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",ps.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",ps.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",ps.INVALID_NUMBER="INVALID_NUMBER";class fs extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}exports.ADDRESS_QUEUE_ROLLOVER_FEE=Ve,exports.ADDRESS_TREE_NETWORK_FEE=He,exports.ALICE=ts,exports.AccountProofResult=Fo,exports.AppendLeavesInputLayout=dn,exports.AppendNullifyCreateAddressInputsMetaLayout=hn,exports.BOB=rs,exports.BalanceResult=Oo,exports.CHARLIE=ns,exports.COMPRESSED_TOKEN_PROGRAM_ID=Me,exports.COMPUTE_BUDGET_PATTERN=le,exports.CompressedAccountLayout=Xr,exports.CompressedAccountResult=wo,exports.CompressedAccountsByOwnerResult=xo,exports.CompressedMintTokenHoldersResult=Do,exports.CompressedTokenAccountResult=bo,exports.CompressedTokenAccountsByOwnerOrDelegateResult=Io,exports.CompressedTransactionResult=Ko,exports.CreateUtxoError=class extends fs{},exports.DAVE=os,exports.DEFAULT_MERKLE_TREE_HEIGHT=De,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=ue,exports.HIGHEST_ADDRESS_PLUS_ONE=ce,exports.HashError=class extends fs{},exports.HealthResult=Mo,exports.IDL={version:"1.2.0",name:"light_system_program",constants:[{name:"SOL_POOL_PDA_SEED",type:"bytes",value:"[115, 111, 108, 95, 112, 111, 111, 108, 95, 112, 100, 97]"}],instructions:[{name:"initCpiContextAccount",accounts:[{name:"feePayer",isMut:1,isSigner:1},{name:"cpiContextAccount",isMut:1,isSigner:0},{name:"associatedMerkleTree",isMut:0,isSigner:0}],args:[]},{name:"invoke",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpi",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpiWithReadOnly",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"InstructionDataInvoke"}},{name:"inputs2",type:{defined:"InstructionDataInvokeCpi"}},{name:"inputs3",type:{defined:"PublicTransactionEvent"}}]}],accounts:[{name:"cpiContextAccount",docs:["Collects instruction data without executing a compressed transaction.","Signer checks are performed on instruction data.","Collected instruction data is combined with the instruction data of the executing cpi,","and executed as a single transaction.","This enables to use input compressed accounts that are owned by multiple programs,","with one zero-knowledge proof."],type:{kind:"struct",fields:[{name:"feePayer",type:"publicKey"},{name:"associatedMerkleTree",type:"publicKey"},{name:"context",type:{vec:{defined:"InstructionDataInvokeCpi"}}}]}}],types:[{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"nullifierQueuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"queueIndex",type:{option:{defined:"QueueIndex"}}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"SumCheckFailed",msg:"Sum check failed"},{code:6001,name:"SignerCheckFailed",msg:"Signer check failed"},{code:6002,name:"CpiSignerCheckFailed",msg:"Cpi signer check failed"},{code:6003,name:"ComputeInputSumFailed",msg:"Computing input sum failed."},{code:6004,name:"ComputeOutputSumFailed",msg:"Computing output sum failed."},{code:6005,name:"ComputeRpcSumFailed",msg:"Computing rpc sum failed."},{code:6006,name:"InvalidAddress",msg:"InvalidAddress"},{code:6007,name:"DeriveAddressError",msg:"DeriveAddressError"},{code:6008,name:"CompressedSolPdaUndefinedForCompressSol",msg:"CompressedSolPdaUndefinedForCompressSol"},{code:6009,name:"DeCompressLamportsUndefinedForCompressSol",msg:"DeCompressLamportsUndefinedForCompressSol"},{code:6010,name:"CompressedSolPdaUndefinedForDecompressSol",msg:"CompressedSolPdaUndefinedForDecompressSol"},{code:6011,name:"DeCompressLamportsUndefinedForDecompressSol",msg:"DeCompressLamportsUndefinedForDecompressSol"},{code:6012,name:"DecompressRecipientUndefinedForDecompressSol",msg:"DecompressRecipientUndefinedForDecompressSol"},{code:6013,name:"WriteAccessCheckFailed",msg:"WriteAccessCheckFailed"},{code:6014,name:"InvokingProgramNotProvided",msg:"InvokingProgramNotProvided"},{code:6015,name:"InvalidCapacity",msg:"InvalidCapacity"},{code:6016,name:"InvalidMerkleTreeOwner",msg:"InvalidMerkleTreeOwner"},{code:6017,name:"ProofIsNone",msg:"ProofIsNone"},{code:6018,name:"ProofIsSome",msg:"Proof is some but no input compressed accounts or new addresses provided."},{code:6019,name:"EmptyInputs",msg:"EmptyInputs"},{code:6020,name:"CpiContextAccountUndefined",msg:"CpiContextAccountUndefined"},{code:6021,name:"CpiContextEmpty",msg:"CpiContextEmpty"},{code:6022,name:"CpiContextMissing",msg:"CpiContextMissing"},{code:6023,name:"DecompressionRecipientDefined",msg:"DecompressionRecipientDefined"},{code:6024,name:"SolPoolPdaDefined",msg:"SolPoolPdaDefined"},{code:6025,name:"AppendStateFailed",msg:"AppendStateFailed"},{code:6026,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6027,name:"CpiContextFeePayerMismatch",msg:"CpiContextFeePayerMismatch"},{code:6028,name:"CpiContextAssociatedMerkleTreeMismatch",msg:"CpiContextAssociatedMerkleTreeMismatch"},{code:6029,name:"NoInputs",msg:"NoInputs"},{code:6030,name:"InputMerkleTreeIndicesNotInOrder",msg:"Input merkle tree indices are not in ascending order."},{code:6031,name:"OutputMerkleTreeIndicesNotInOrder",msg:"Output merkle tree indices are not in ascending order."},{code:6032,name:"OutputMerkleTreeNotUnique"},{code:6033,name:"DataFieldUndefined"},{code:6034,name:"ReadOnlyAddressAlreadyExists"},{code:6035,name:"ReadOnlyAccountDoesNotExist"},{code:6036,name:"HashChainInputsLenghtInconsistent"},{code:6037,name:"InvalidAddressTreeHeight"},{code:6038,name:"InvalidStateTreeHeight"}]},exports.INSERT_INTO_QUEUES_DISCRIMINATOR=pe,exports.INVOKE_CPI_DISCRIMINATOR=de,exports.INVOKE_DISCRIMINATOR=he,exports.IndexedArray=An,exports.IndexedElement=xn,exports.IndexedElementBundle=In,exports.InsertAddressInputLayout=fn,exports.InsertNullifierInputLayout=pn,exports.InstructionDataInvokeCpiLayout=on,exports.InstructionDataInvokeLayout=rn,exports.LatestNonVotingSignaturesResult=To,exports.LatestNonVotingSignaturesResultPaginated=So,exports.LightSystemProgram=bn,exports.LookupTableError=class extends fs{},exports.MerkeProofResult=_o,exports.MerkleContextLayout=en,exports.MerkleTree=Mn,exports.MerkleTreeError=class extends fs{},exports.MerkleTreeSequenceNumberLayout=mn,exports.MultipleCompressedAccountsResult=Eo,exports.MultipleMerkleProofsResult=Lo,exports.NativeBalanceResult=No,exports.NewAddressParamsLayout=tn,exports.NewAddressProofResult=Co,exports.ProofError=class extends fs{},exports.PublicTransactionEventLayout=cn,exports.Rpc=Go,exports.RpcError=class extends fs{},exports.STATE_MERKLE_TREE_NETWORK_FEE=Ke,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=qe,exports.SelectInUtxosError=class extends fs{},exports.SignatureListResult=qo,exports.SignatureListWithCursorResult=Vo,exports.SlotResult=Ao,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=Fe,exports.TestRpc=Xo,exports.TokenBalanceListResult=Bo,exports.TokenBalanceListResultV2=Uo,exports.TokenBalanceResult=Ro,exports.TokenDataLayout=On,exports.TokenDataResult=vo,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends fs{},exports.UtxoError=class extends fs{},exports.ValidityProofResult=ko,exports.accountCompressionProgram=ge,exports.addressQueue=Ne,exports.addressTree=Oe,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await or(e,n),n},exports.bn=We,exports.bufToDecStr=e=>je(e).toString(),exports.buildAndSignTx=gr,exports.buildTx=pr,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();s||(s=ir(await t.getStateTreeInfos()));const u=await bn.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTreeInfo:s}),c=gr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await fr(t,c,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=or,exports.confirmTx=mr,exports.convertMerkleProofsWithContextToHex=Zo,exports.convertNonInclusionMerkleProofInputsToHex=Jo,exports.convertToPublicTransactionEvent=yn,exports.cpiContext2Pubkey=Ue,exports.cpiContextPubkey=ke,exports.createAccount=async function(t,r,n,o,s,i,a){const{blockhash:u}=await t.getLatestBlockhash(),{tree:c,queue:l}=null!=s?s:Ie(),h=tr(n,o),d=rr(h,c);i||(i=ir(await t.getStateTreeInfos()));const p=await t.getValidityProofV0(void 0,[{address:We(d.toBytes()),tree:c,queue:l}]),f={seed:h,addressMerkleTreeRootIndex:p.rootIndices[0],addressMerkleTreePubkey:p.treeInfos[0].tree,addressQueuePubkey:p.treeInfos[0].queue},m=await bn.createAccount({payer:r.publicKey,newAddressParams:f,newAddress:Array.from(d.toBytes()),recentValidityProof:p.compressedProof,programId:o,outputStateTreeInfo:i}),g=gr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),m],r,u,[]);return await fr(t,g,a)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u){o=We(o);const c=await t.getCompressedAccountsByOwner(r.publicKey),[l]=En(c.items,o),{blockhash:h}=await t.getLatestBlockhash(),{tree:d}=null!=i?i:Ie(),p=tr(n,s),f=rr(p,d),m=await t.getValidityProof(l.map((e=>e.hash)),[We(f.toBytes())]),g={seed:p,addressMerkleTreeRootIndex:m.rootIndices[m.rootIndices.length-1],addressMerkleTreePubkey:m.treeInfos[m.treeInfos.length-1].tree,addressQueuePubkey:m.treeInfos[m.treeInfos.length-1].queue},y=await bn.createAccount({payer:r.publicKey,newAddressParams:g,newAddress:Array.from(f.toBytes()),recentValidityProof:m.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:m.rootIndices,outputStateTreeInfo:a}),w=gr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),y],r,h,[]);return await fr(t,w,u)},exports.createBN254=je,exports.createCompressedAccount=Ye,exports.createCompressedAccountWithMerkleContext=Ze,exports.createMerkleContext=Je,exports.createRpc=function(t,r,n,o){let s;if(t)if("string"==typeof t)s=t,r=r||s,n=n||s;else{if(!(t instanceof e.Connection))throw new Error("Invalid endpoint or connection type");s=t.rpcEndpoint,r=r||s,n=n||s}else s="http://127.0.0.1:8899",r=r||"http://127.0.0.1:8784",n=n||"http://127.0.0.1:3001";return new Go(s,r,n,o)},exports.createRpcResult=fo,exports.createStateTreeLookupTable=async function({connection:t,payer:r,authority:n,recentSlot:o}){const[s,i]=e.AddressLookupTableProgram.createLookupTable({payer:r.publicKey,authority:n.publicKey,recentSlot:o}),a=gr([s],r,(await t.getLatestBlockhash()).blockhash,sr(r,[n]));return{address:i,txId:await fr(t,a)}},exports.decodeInstructionDataInvoke=sn,exports.decodeInstructionDataInvokeCpi=an,exports.decodePublicTransactionEvent=ln,exports.decompress=async function(t,r,n,o,s){const i=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=We(n);const a=wn(i);if(n.gt(a))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${a}`);const u=await t.getValidityProof(i.map((e=>We(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),l=await bn.decompress({payer:r.publicKey,toAddress:o,inputCompressedAccounts:i,recentValidityProof:u.compressedProof,recentInputStateRootIndices:u.rootIndices,lamports:n}),h=gr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,c,[]);return await fr(t,h,s)},exports.dedupeSigner=sr,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof ae&&r instanceof ae)return t.eq(r);if("object"==typeof t&&null!==t&&null!==r){const n=Object.keys(t),o=Object.keys(r);if(n.length!==o.length)return console.log(`Key length mismatch: ${n.length} !== ${o.length}`),0;for(const s of n){if(!o.includes(s))return console.log(`Key ${s} not found in value`),0;if(!e(t[s],r[s]))return console.log(`Value mismatch at key ${s}`),0}return 1}return t!==r&&console.log(`Value mismatch: ${t} !== ${r}`),t===r},exports.defaultStateTreeLookupTables=be,exports.defaultStaticAccounts=()=>[new e.PublicKey(ye()),new e.PublicKey(fe),new e.PublicKey(ge),new e.PublicKey(we())],exports.defaultStaticAccountsStruct=ve,exports.defaultTestStateTreeAccounts=Ae,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(Be),merkleTree2:new e.PublicKey(Re)}),exports.deriveAddress=rr,exports.deriveAddressSeed=tr,exports.deserializeAppendNullifyCreateAddressInputsIndexer=gn,exports.encodeBN254toBase58=ze,exports.encodeInstructionDataInvoke=nn,exports.encodePublicTransactionEvent=function(e){const t=g.alloc(1e3),r=cn.encode(e,t);return t.slice(0,r)},exports.extendStateTreeLookupTable=async function({connection:t,tableAddress:r,newStateTreeAddresses:n,newQueueAddresses:o,newCpiContextAddresses:s,payer:i,authority:a}){const u=await t.getAddressLookupTable(r);if(!u.value)throw new Error("Lookup table not found");if(u.value.state.addresses.length%3!=0)throw new Error("Lookup table must have a multiple of 3 addresses");if(n.length!==o.length||n.length!==s.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const c=gr([e.AddressLookupTableProgram.extendLookupTable({payer:i.publicKey,authority:a.publicKey,lookupTable:r,addresses:n.flatMap(((e,t)=>[e,o[t],s[t]]))})],i,(await t.getLatestBlockhash()).blockhash,sr(i,[a]));return{tableAddress:r,txId:await fr(t,c)}},exports.getAccountCompressionAuthority=we,exports.getAllStateTreeInfos=ar,exports.getCompressedTokenAccountByHashTest=Dn,exports.getCompressedTokenAccounts=Rn,exports.getCompressedTokenAccountsByDelegateTest=Un,exports.getCompressedTokenAccountsByOwnerTest=Bn,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getDefaultAddressTreeInfo=Ie,exports.getIndexOrAdd=Qe,exports.getParsedEvents=Tn,exports.getPublicInputHash=function(e,t,r,n){const o=Qo(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=Qo(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?Qo([o],[i],n):o:i},exports.getRegisteredProgramPda=ye,exports.getTestKeypair=ss,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=0){return new Xo(t,e,r,n,void 0,{depth:o||Ae().merkleTreeHeight,log:s})},exports.getTreeForQueue=function(e,t){const r=e.findIndex((e=>{var r;return null===(r=e.queue)||void 0===r?void 0:r.equals(t)}));if(-1===r)throw new Error("No associated tree found for queue. Please set activeStateTreeInfo with latest Tree accounts. If you use custom state trees, set manually.");if(!e[r].tree)throw new Error("Tree must not be null for state tree");return e[r].tree},exports.hashToBn254FieldSizeBe=Xt,exports.hashvToBn254FieldSizeBe=er,exports.invokeAccountsLayout=un,exports.isLocalTest=Ee,exports.isSmallerThanBn254FieldSizeBe=Qt,exports.jsonRpcResult=go,exports.jsonRpcResultAndContext=yo,exports.lightProgram=me,exports.localTestActiveStateTreeInfo=xe,exports.merkleTree2Pubkey=Re,exports.merkletreePubkey=Le,exports.negateAndCompressProof=cr,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=ss(r),o=await e.requestAirdrop(n.publicKey,t);return await mr(e,o),n},exports.noopProgram=fe,exports.nullifiedStateTreeLookupTableDevnet=Ce,exports.nullifiedStateTreeLookupTableMainnet=Se,exports.nullifierQueue2Pubkey=Be,exports.nullifierQueuePubkey=Pe,exports.nullifyLookupTable=async function({connection:t,fullStateTreeAddress:r,nullifyLookupTableAddress:n,stateTreeLookupTableAddress:o,payer:s,authority:i}){const a=await t.getAddressLookupTable(o);if(!a.value)throw console.log("stateTreeLookupTable",a),new Error("State tree lookup table not found");if(!a.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw console.log("fullStateTreeAddress",r),console.log("stateTreeLookupTable.value.state.addresses",a.value.state.addresses),new Error("State tree address not found in lookup table. Pass correct address or stateTreeLookupTable");const u=await t.getAddressLookupTable(n);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw new Error("Address already exists in nullify lookup table");const c=gr([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:n,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash,sr(s,[i]));return{txId:await fr(t,c)}},exports.packCompressedAccounts=et,exports.packNewAddressParams=nr,exports.padOutputStateMerkleTrees=Ge,exports.parseAccountData=Ho,exports.parseEvents=Sn,exports.parseLightTransaction=Cn,exports.parsePublicTransactionEventWithIdl=_n,exports.parseTokenLayoutWithIdl=Nn,exports.pickRandomTreeAndQueue=function(e){const t=e.length,r=Math.floor(Math.random()*t);if(!e[r].queue)throw new Error("Queue must not be null for state tree");return{tree:e[r].tree,queue:e[r].queue}},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=ur,exports.proverRequest=Yo,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=Wo,exports.selectMinCompressedSolAccountsForTransfer=En,exports.selectStateTreeInfo=ir,exports.sendAndConfirmTx=fr,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=_e,exports.stateTreeLookupTableMainnet=Te,exports.sumUpLamports=wn,exports.toAccountMetas=Xe,exports.toArray=e=>Array.isArray(e)?e:[e],exports.toCamelCase=Gt,exports.toHex=Jt,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i,a){var u;let c=We(0);const l=[];let h;for(n=We(n);c.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:h,limit:We(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(We(0))&&(l.push(e),c=c.add(e.lamports));if(h=null!==(u=r.cursor)&&void 0!==u?u:void 0,r.items.length<1e3||c.gte(n))break}if(c.lt(n))throw new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${c.toString()}`);const[d]=En(l,n),p=await t.getValidityProof(d.map((e=>We(e.hash)))),f=await bn.transfer({payer:r.publicKey,inputCompressedAccounts:d,toAddress:s,lamports:n,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:m}=await t.getLatestBlockhash(),g=gr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,m);return await fr(t,g,a)},exports.validateNumbers=it,exports.validateNumbersForInclusionProof=ot,exports.validateNumbersForNonInclusionProof=st,exports.validateNumbersForProof=nt,exports.validateSameOwner=rt,exports.validateSufficientBalance=tt,exports.wrapBigNumbersAsStrings=zo;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|