@lightprotocol/stateless.js 0.22.1-alpha.0 → 0.22.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/cjs/browser/constants.d.ts +41 -7
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/index.d.ts +0 -1
- package/dist/cjs/browser/programs/system/pack.d.ts +10 -79
- package/dist/cjs/browser/rpc-interface.d.ts +371 -277
- package/dist/cjs/browser/rpc.d.ts +79 -12
- package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +0 -2
- package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +12 -6
- package/dist/cjs/browser/utils/address.d.ts +7 -19
- package/dist/cjs/browser/utils/conversion.d.ts +1 -1
- package/dist/cjs/browser/utils/get-state-tree-infos.d.ts +15 -0
- package/dist/cjs/browser/utils/index.d.ts +2 -1
- package/dist/cjs/browser/utils/instruction.d.ts +35 -0
- package/dist/cjs/browser/utils/pack-decompress.d.ts +31 -0
- package/dist/cjs/node/constants.d.ts +41 -7
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/index.d.ts +0 -1
- package/dist/cjs/node/programs/system/pack.d.ts +10 -79
- package/dist/cjs/node/rpc-interface.d.ts +371 -277
- package/dist/cjs/node/rpc.d.ts +79 -12
- package/dist/cjs/node/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +0 -2
- package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +12 -6
- package/dist/cjs/node/utils/address.d.ts +7 -19
- package/dist/cjs/node/utils/conversion.d.ts +1 -1
- package/dist/cjs/node/utils/get-state-tree-infos.d.ts +15 -0
- package/dist/cjs/node/utils/index.d.ts +2 -1
- package/dist/cjs/node/utils/instruction.d.ts +35 -0
- package/dist/cjs/node/utils/pack-decompress.d.ts +31 -0
- package/dist/es/browser/actions/compress.d.ts +18 -0
- package/dist/es/browser/actions/create-account.d.ts +38 -0
- package/dist/es/browser/actions/decompress.d.ts +15 -0
- package/dist/es/browser/actions/index.d.ts +5 -0
- package/dist/es/browser/actions/transfer.d.ts +16 -0
- package/dist/es/browser/constants.d.ts +176 -0
- package/dist/es/browser/errors.d.ts +74 -0
- package/dist/es/browser/index.d.ts +9 -0
- package/dist/es/browser/index.js +2 -0
- package/dist/es/browser/index.js.map +1 -0
- package/dist/es/browser/programs/index.d.ts +1 -0
- package/dist/es/browser/programs/system/idl.d.ts +997 -0
- package/dist/es/browser/programs/system/index.d.ts +5 -0
- package/dist/es/browser/programs/system/layout.d.ts +77 -0
- package/dist/es/browser/programs/system/pack.d.ts +74 -0
- package/dist/es/browser/programs/system/program.d.ts +175 -0
- package/dist/es/browser/programs/system/select-compressed-accounts.d.ts +10 -0
- package/dist/es/browser/rpc-interface.d.ts +2873 -0
- package/dist/es/browser/rpc.d.ts +361 -0
- package/dist/es/browser/state/BN254.d.ts +13 -0
- package/dist/es/browser/state/bn.d.ts +3 -0
- package/dist/es/browser/state/compressed-account.d.ts +205 -0
- package/dist/es/browser/state/index.d.ts +4 -0
- package/dist/es/browser/state/types.d.ts +449 -0
- package/dist/es/browser/test-helpers/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/merkle-tree/index.d.ts +2 -0
- package/dist/es/browser/test-helpers/merkle-tree/indexed-array.d.ts +85 -0
- package/dist/es/browser/test-helpers/merkle-tree/merkle-tree.d.ts +92 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +7 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +38 -0
- package/dist/es/browser/test-helpers/test-rpc/get-parsed-events.d.ts +15 -0
- package/dist/es/browser/test-helpers/test-rpc/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +245 -0
- package/dist/es/browser/test-helpers/test-utils.d.ts +31 -0
- package/dist/es/browser/utils/address.d.ts +64 -0
- package/dist/es/browser/utils/airdrop.d.ts +7 -0
- package/dist/es/browser/utils/calculate-compute-unit-price.d.ts +7 -0
- package/dist/es/browser/utils/conversion.d.ts +36 -0
- package/dist/es/browser/utils/dedupe-signer.d.ts +3 -0
- package/dist/es/browser/utils/get-state-tree-infos.d.ts +63 -0
- package/dist/es/browser/utils/index.d.ts +14 -0
- package/dist/es/browser/utils/instruction.d.ts +35 -0
- package/dist/es/browser/utils/pack-decompress.d.ts +31 -0
- package/dist/es/browser/utils/parse-validity-proof.d.ts +20 -0
- package/dist/es/browser/utils/pipe.d.ts +2 -0
- package/dist/es/browser/utils/send-and-confirm.d.ts +52 -0
- package/dist/es/browser/utils/sleep.d.ts +1 -0
- package/dist/es/browser/utils/state-tree-lookup-table.d.ts +68 -0
- package/dist/es/browser/utils/validation.d.ts +8 -0
- package/dist/types/index.d.ts +340 -661
- package/package.json +18 -10
- package/dist/cjs/browser/compressible/action.d.ts +0 -77
- package/dist/cjs/browser/compressible/index.d.ts +0 -13
- package/dist/cjs/browser/compressible/instruction.d.ts +0 -177
- package/dist/cjs/browser/compressible/layout.d.ts +0 -47
- package/dist/cjs/browser/compressible/types.d.ts +0 -112
- package/dist/cjs/browser/compressible/utils.d.ts +0 -16
- package/dist/cjs/browser/utils/packed-accounts.d.ts +0 -161
- package/dist/cjs/node/compressible/action.d.ts +0 -77
- package/dist/cjs/node/compressible/index.d.ts +0 -13
- package/dist/cjs/node/compressible/instruction.d.ts +0 -177
- package/dist/cjs/node/compressible/layout.d.ts +0 -47
- package/dist/cjs/node/compressible/types.d.ts +0 -112
- package/dist/cjs/node/compressible/utils.d.ts +0 -16
- package/dist/cjs/node/utils/packed-accounts.d.ts +0 -161
|
@@ -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="",c=[],l=16383,d=0,h=n-o;d<h;d+=l)c.push(a(e,d,d+l>h?h:d+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,d=r?o-1:0,h=r?-1:1,p=e[t+d];for(d+=h,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=256*s+e[t+d],d+=h,l-=8);for(i=s&(1<<-l)-1,s>>=-l,l+=n;l>0;i=256*i+e[t+d],d+=h,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,d=l>>1,h=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+d>=1?h/u:h*Math.pow(2,1-d))*u>=2&&(i++,u/=2),i+d>=l?(a=0,i=l):i+d>=1?(a=(t*u-1)*Math.pow(2,o),i+=d):(a=t*Math.pow(2,d-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 d={}.toString,h=Array.isArray||function(e){return"[object Array]"==d.call(e)};y.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:1;var p=f();function f(){return y.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function m(e,t){if(f()<t)throw new RangeError("Invalid typed array length");return y.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=y.prototype:(null===e&&(e=new y(t)),e.length=t),e}function y(e,t,r){if(!(y.TYPED_ARRAY_SUPPORT||this instanceof y))return new y(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 g(this,e,t,r)}function g(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),y.TYPED_ARRAY_SUPPORT?(e=t).__proto__=y.prototype:e=x(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!y.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(I(t)){var r=0|b(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):x(e,t);if("Buffer"===t.type&&h(t.data))return x(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|b(t)),!y.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function x(e,t){var r=t.length<0?0:0|b(t.length);e=m(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function b(e){if(e>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|e}function I(e){return!(null==e||!e._isBuffer)}function A(e,t){if(I(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 G(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Z(e).length;default:if(n)return G(e).length;t=(""+t).toLowerCase(),n=1}}function E(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 V(this,t,r);case"utf8":case"utf-8":return N(this,t,r);case"ascii":return D(this,t,r);case"latin1":case"binary":return U(this,t,r);case"base64":return L(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=1}}function T(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function M(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=y.from(t,n)),I(t))return 0===t.length?-1:S(e,t,r,n,o);if("number"==typeof t)return t&=255,y.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 d=1,h=0;h<u;h++)if(c(e,s+h)!==c(t,h)){d=0;break}if(d)return s}return-1}function C(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 _(e,t,r,n){return J(G(t,e.length-r),e,r,n)}function k(e,t,r,n){return J(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 O(e,t,r,n){return J(Z(t),e,r,n)}function R(e,t,r,n){return J(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 L(e,t,r){return 0===t&&r===e.length?u(e):u(e.slice(t,r))}function N(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,d=c>239?4:c>223?3:c>191?2:1;if(o+d<=r)switch(d){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,d=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),o+=d}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)}y.poolSize=8192,y._augment=function(e){return e.__proto__=y.prototype,e},y.from=function(e,t,r){return g(null,e,t,r)},y.TYPED_ARRAY_SUPPORT&&(y.prototype.__proto__=Uint8Array.prototype,y.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&y[Symbol.species]),y.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)},y.allocUnsafe=function(e){return v(null,e)},y.allocUnsafeSlow=function(e){return v(null,e)},y.isBuffer=Q,y.compare=function(e,t){if(!I(e)||!I(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},y.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}},y.concat=function(e,t){if(!h(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return y.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=y.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!I(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},y.byteLength=A,y.prototype._isBuffer=1,y.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)T(this,t,t+1);return this},y.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)T(this,t,t+3),T(this,t+1,t+2);return this},y.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)T(this,t,t+7),T(this,t+1,t+6),T(this,t+2,t+5),T(this,t+3,t+4);return this},y.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?N(this,0,e):E.apply(this,arguments)},y.prototype.equals=function(e){if(!I(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===y.compare(this,e)},y.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+">"},y.prototype.compare=function(e,t,r,n,o){if(!I(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},y.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},y.prototype.indexOf=function(e,t,r){return M(this,e,t,r,1)},y.prototype.lastIndexOf=function(e,t,r){return M(this,e,t,r,0)},y.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 C(this,e,t,r);case"utf8":case"utf-8":return _(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 O(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=1}},y.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var B=4096;function D(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 U(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 V(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 F(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 q(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(!I(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 W(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 H(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),l(e,t,r,n,23,4),r+4}function j(e,t,r,n,o){return o||$(e,0,r,8),l(e,t,r,n,52,8),r+8}y.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),y.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=y.prototype;else{var o=t-e;r=new y(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},y.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||q(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n},y.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||q(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},y.prototype.readUInt8=function(e,t){return t||q(e,1,this.length),this[e]},y.prototype.readUInt16LE=function(e,t){return t||q(e,2,this.length),this[e]|this[e+1]<<8},y.prototype.readUInt16BE=function(e,t){return t||q(e,2,this.length),this[e]<<8|this[e+1]},y.prototype.readUInt32LE=function(e,t){return t||q(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},y.prototype.readUInt32BE=function(e,t){return t||q(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},y.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||q(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},y.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||q(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},y.prototype.readInt8=function(e,t){return t||q(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},y.prototype.readInt16LE=function(e,t){t||q(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt16BE=function(e,t){t||q(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt32LE=function(e,t){return t||q(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},y.prototype.readInt32BE=function(e,t){return t||q(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},y.prototype.readFloatLE=function(e,t){return t||q(e,4,this.length),c(this,e,1,23,4)},y.prototype.readFloatBE=function(e,t){return t||q(e,4,this.length),c(this,e,0,23,4)},y.prototype.readDoubleLE=function(e,t){return t||q(e,8,this.length),c(this,e,1,52,8)},y.prototype.readDoubleBE=function(e,t){return t||q(e,8,this.length),c(this,e,0,52,8)},y.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},y.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},y.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,255,0),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},y.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):W(this,e,t,1),t+2},y.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):W(this,e,t,0),t+2},y.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):H(this,e,t,1),t+4},y.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):H(this,e,t,0),t+4},y.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},y.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},y.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,127,-128),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},y.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):W(this,e,t,1),t+2},y.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):W(this,e,t,0),t+2},y.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):H(this,e,t,1),t+4},y.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),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):H(this,e,t,0),t+4},y.prototype.writeFloatLE=function(e,t,r){return z(this,e,t,1,r)},y.prototype.writeFloatBE=function(e,t,r){return z(this,e,t,0,r)},y.prototype.writeDoubleLE=function(e,t,r){return j(this,e,t,1,r)},y.prototype.writeDoubleBE=function(e,t,r){return j(this,e,t,0,r)},y.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||!y.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},y.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&&!y.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=I(e)?e:G(new y(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 G(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 Z(e){return function(e){var t,r,a,u,c,l;s||i();var d=e.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");c="="===e[d-2]?2:"="===e[d-1]?1:0,l=new o(3*d/4-c),a=c>0?d-4:d;var h=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[h++]=u>>16&255,l[h++]=u>>8&255,l[h++]=255&u;return 2===c?(u=n[e.charCodeAt(t)]<<2|n[e.charCodeAt(t+1)]>>4,l[h++]=255&u):1===c&&(u=n[e.charCodeAt(t)]<<10|n[e.charCodeAt(t+1)]<<4|n[e.charCodeAt(t+2)]>>2,l[h++]=u>>8&255,l[h++]=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 J(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 Q(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=Object.freeze({__proto__:null,Buffer:y,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),y.alloc(+e)},isBuffer:Q,kMaxLength:p}),te="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ne(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 oe={},se={};class ie{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 ae(e,t){return t.property?e+"["+t.property+"]":e}se.Layout=ie,se.nameWithProperty=ae,se.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 ie))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 ue extends ie{isCount(){throw new Error("ExternalLayout is abstract")}}class ce extends ue{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 le extends ue{constructor(e,t,r){if(!(e instanceof ie))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 de||this.layout instanceof he}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 de extends ie{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 he extends ie{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 pe extends ie{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 fe extends ie{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 me=Math.pow(2,32);function ye(e){const t=Math.floor(e/me);return{hi32:t,lo32:e-t*me}}function ge(e,t){return e*me+t}class we extends ie{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ge(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class ve extends ie{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ge(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class xe extends ie{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ge(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class be extends ie{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ge(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Ie extends ie{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 Ae extends ie{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 Ee extends ie{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 Te extends ie{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 Me extends ie{constructor(e,t,r){if(!(e instanceof ie))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof ue&&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 ue)&&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 ue&&(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 ue&&(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 ue&&this.count.encode(e.length,t,r),o}}class Se extends ie{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof ie),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 Ce{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class _e extends Ce{constructor(e,t){if(!(e instanceof ue&&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 ke extends ie{constructor(e,t,r){const n=e instanceof de||e instanceof he;if(n)e=new _e(new le(e));else if(e instanceof ue&&e.isCount())e=new _e(e);else if(!(e instanceof Ce))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof ie))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 Pe(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 Pe extends ie{constructor(e,t,r,n){if(!(e instanceof ke))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 ie))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 Oe(e){return 0>e&&(e+=4294967296),e}class Re extends ie{constructor(e,t,r){if(!(e instanceof de||e instanceof he))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=Oe(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 Le(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new Ne(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 Le{constructor(e,t,r){if(!(e instanceof Re))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=Oe(this.valueMask<<this.start),this.property=r}decode(){return Oe(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==Oe(e&this.valueMask))throw new TypeError(ae("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=Oe(e<<this.start);this.container._packedSetValue(Oe(t&~this.wordMask)|r)}}class Ne extends Le{constructor(e,t){super(e,1,t)}decode(e,t){return!!Le.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),Le.prototype.encode.call(this,e)}}class Be extends ie{constructor(e,t){if(!(e instanceof ue&&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 ue||(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 ue&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(ae("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 ue&&this.length.encode(n,t,r),n}}class De extends ie{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 Ue extends ie{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 Ve extends ie{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}se.ExternalLayout=ue,se.GreedyCount=ce,se.OffsetLayout=le,se.UInt=de,se.UIntBE=he,se.Int=pe,se.IntBE=fe,se.Float=Ie,se.FloatBE=Ae,se.Double=Ee,se.DoubleBE=Te,se.Sequence=Me,se.Structure=Se,se.UnionDiscriminator=Ce,se.UnionLayoutDiscriminator=_e,se.Union=ke,se.VariantLayout=Pe,se.BitStructure=Re,se.BitField=Le,se.Boolean=Ne,se.Blob=Be,se.CString=De,se.UTF8=Ue,se.Constant=Ve,se.greedy=(e,t)=>new ce(e,t),se.offset=(e,t,r)=>new le(e,t,r),se.u8=e=>new de(1,e),se.u16=e=>new de(2,e),se.u24=e=>new de(3,e),se.u32=e=>new de(4,e),se.u40=e=>new de(5,e),se.u48=e=>new de(6,e),se.nu64=e=>new we(e),se.u16be=e=>new he(2,e),se.u24be=e=>new he(3,e),se.u32be=e=>new he(4,e),se.u40be=e=>new he(5,e),se.u48be=e=>new he(6,e),se.nu64be=e=>new ve(e),se.s8=e=>new pe(1,e),se.s16=e=>new pe(2,e),se.s24=e=>new pe(3,e),se.s32=e=>new pe(4,e),se.s40=e=>new pe(5,e),se.s48=e=>new pe(6,e),se.ns64=e=>new xe(e),se.s16be=e=>new fe(2,e),se.s24be=e=>new fe(3,e),se.s32be=e=>new fe(4,e),se.s40be=e=>new fe(5,e),se.s48be=e=>new fe(6,e),se.ns64be=e=>new be(e),se.f32=e=>new Ie(e),se.f32be=e=>new Ae(e),se.f64=e=>new Ee(e),se.f64be=e=>new Te(e),se.struct=(e,t,r)=>new Se(e,t,r),se.bits=(e,t,r)=>new Re(e,t,r),se.seq=(e,t,r)=>new Me(e,t,r),se.union=(e,t,r)=>new ke(e,t,r),se.unionLayoutDiscriminator=(e,t)=>new _e(e,t),se.blob=(e,t)=>new Be(e,t),se.cstr=e=>new De(e),se.utf8=(e,t)=>new Ue(e,t),se.const=(e,t)=>new Ve(e,t);var Fe={exports:{}},qe=ne(ee);!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 Fe?Fe.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:qe.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 d=1;for(c=u(e,l,e.length,t),l=0;l<i;l++)d*=t;this.imuln(d),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 d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],h=[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,d=67108863&u,h=Math.min(c,t.length-1),p=Math.max(0,c-e.length+1);p<=h;p++){var f=c-p|0;l+=(i=(o=0|e.words[f])*(s=0|t.words[p])+d)/67108864|0,d=67108863&i}r.words[c]=0|d,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?d[6-u.length]+u+n:u+n}for(0!==s&&(n=s.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var c=h[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:d[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],d=8191&l,h=l>>>13,p=0|i[1],f=8191&p,m=p>>>13,y=0|i[2],g=8191&y,w=y>>>13,v=0|i[3],x=8191&v,b=v>>>13,I=0|i[4],A=8191&I,E=I>>>13,T=0|i[5],M=8191&T,S=T>>>13,C=0|i[6],_=8191&C,k=C>>>13,P=0|i[7],O=8191&P,R=P>>>13,L=0|i[8],N=8191&L,B=L>>>13,D=0|i[9],U=8191&D,V=D>>>13,F=0|a[0],q=8191&F,K=F>>>13,W=0|a[1],H=8191&W,$=W>>>13,z=0|a[2],j=8191&z,Y=z>>>13,G=0|a[3],Z=8191&G,J=G>>>13,Q=0|a[4],X=8191&Q,ee=Q>>>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],de=8191&le,he=le>>>13,pe=0|a[9],fe=8191&pe,me=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ye=(c+(n=Math.imul(d,q))|0)+((8191&(o=(o=Math.imul(d,K))+Math.imul(h,q)|0))<<13)|0;c=((s=Math.imul(h,K))+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(f,q),o=(o=Math.imul(f,K))+Math.imul(m,q)|0,s=Math.imul(m,K);var ge=(c+(n=n+Math.imul(d,H)|0)|0)+((8191&(o=(o=o+Math.imul(d,$)|0)+Math.imul(h,H)|0))<<13)|0;c=((s=s+Math.imul(h,$)|0)+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(g,q),o=(o=Math.imul(g,K))+Math.imul(w,q)|0,s=Math.imul(w,K),n=n+Math.imul(f,H)|0,o=(o=o+Math.imul(f,$)|0)+Math.imul(m,H)|0,s=s+Math.imul(m,$)|0;var we=(c+(n=n+Math.imul(d,j)|0)|0)+((8191&(o=(o=o+Math.imul(d,Y)|0)+Math.imul(h,j)|0))<<13)|0;c=((s=s+Math.imul(h,Y)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(x,q),o=(o=Math.imul(x,K))+Math.imul(b,q)|0,s=Math.imul(b,K),n=n+Math.imul(g,H)|0,o=(o=o+Math.imul(g,$)|0)+Math.imul(w,H)|0,s=s+Math.imul(w,$)|0,n=n+Math.imul(f,j)|0,o=(o=o+Math.imul(f,Y)|0)+Math.imul(m,j)|0,s=s+Math.imul(m,Y)|0;var ve=(c+(n=n+Math.imul(d,Z)|0)|0)+((8191&(o=(o=o+Math.imul(d,J)|0)+Math.imul(h,Z)|0))<<13)|0;c=((s=s+Math.imul(h,J)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(A,q),o=(o=Math.imul(A,K))+Math.imul(E,q)|0,s=Math.imul(E,K),n=n+Math.imul(x,H)|0,o=(o=o+Math.imul(x,$)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,$)|0,n=n+Math.imul(g,j)|0,o=(o=o+Math.imul(g,Y)|0)+Math.imul(w,j)|0,s=s+Math.imul(w,Y)|0,n=n+Math.imul(f,Z)|0,o=(o=o+Math.imul(f,J)|0)+Math.imul(m,Z)|0,s=s+Math.imul(m,J)|0;var xe=(c+(n=n+Math.imul(d,X)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(h,X)|0))<<13)|0;c=((s=s+Math.imul(h,ee)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(M,q),o=(o=Math.imul(M,K))+Math.imul(S,q)|0,s=Math.imul(S,K),n=n+Math.imul(A,H)|0,o=(o=o+Math.imul(A,$)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,$)|0,n=n+Math.imul(x,j)|0,o=(o=o+Math.imul(x,Y)|0)+Math.imul(b,j)|0,s=s+Math.imul(b,Y)|0,n=n+Math.imul(g,Z)|0,o=(o=o+Math.imul(g,J)|0)+Math.imul(w,Z)|0,s=s+Math.imul(w,J)|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 be=(c+(n=n+Math.imul(d,re)|0)|0)+((8191&(o=(o=o+Math.imul(d,ne)|0)+Math.imul(h,re)|0))<<13)|0;c=((s=s+Math.imul(h,ne)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(_,q),o=(o=Math.imul(_,K))+Math.imul(k,q)|0,s=Math.imul(k,K),n=n+Math.imul(M,H)|0,o=(o=o+Math.imul(M,$)|0)+Math.imul(S,H)|0,s=s+Math.imul(S,$)|0,n=n+Math.imul(A,j)|0,o=(o=o+Math.imul(A,Y)|0)+Math.imul(E,j)|0,s=s+Math.imul(E,Y)|0,n=n+Math.imul(x,Z)|0,o=(o=o+Math.imul(x,J)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,J)|0,n=n+Math.imul(g,X)|0,o=(o=o+Math.imul(g,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 Ie=(c+(n=n+Math.imul(d,se)|0)|0)+((8191&(o=(o=o+Math.imul(d,ie)|0)+Math.imul(h,se)|0))<<13)|0;c=((s=s+Math.imul(h,ie)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(O,q),o=(o=Math.imul(O,K))+Math.imul(R,q)|0,s=Math.imul(R,K),n=n+Math.imul(_,H)|0,o=(o=o+Math.imul(_,$)|0)+Math.imul(k,H)|0,s=s+Math.imul(k,$)|0,n=n+Math.imul(M,j)|0,o=(o=o+Math.imul(M,Y)|0)+Math.imul(S,j)|0,s=s+Math.imul(S,Y)|0,n=n+Math.imul(A,Z)|0,o=(o=o+Math.imul(A,J)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,J)|0,n=n+Math.imul(x,X)|0,o=(o=o+Math.imul(x,ee)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,ee)|0,n=n+Math.imul(g,re)|0,o=(o=o+Math.imul(g,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=(c+(n=n+Math.imul(d,ue)|0)|0)+((8191&(o=(o=o+Math.imul(d,ce)|0)+Math.imul(h,ue)|0))<<13)|0;c=((s=s+Math.imul(h,ce)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(N,q),o=(o=Math.imul(N,K))+Math.imul(B,q)|0,s=Math.imul(B,K),n=n+Math.imul(O,H)|0,o=(o=o+Math.imul(O,$)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,$)|0,n=n+Math.imul(_,j)|0,o=(o=o+Math.imul(_,Y)|0)+Math.imul(k,j)|0,s=s+Math.imul(k,Y)|0,n=n+Math.imul(M,Z)|0,o=(o=o+Math.imul(M,J)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,J)|0,n=n+Math.imul(A,X)|0,o=(o=o+Math.imul(A,ee)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,ee)|0,n=n+Math.imul(x,re)|0,o=(o=o+Math.imul(x,ne)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,ne)|0,n=n+Math.imul(g,se)|0,o=(o=o+Math.imul(g,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 Ee=(c+(n=n+Math.imul(d,de)|0)|0)+((8191&(o=(o=o+Math.imul(d,he)|0)+Math.imul(h,de)|0))<<13)|0;c=((s=s+Math.imul(h,he)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(U,q),o=(o=Math.imul(U,K))+Math.imul(V,q)|0,s=Math.imul(V,K),n=n+Math.imul(N,H)|0,o=(o=o+Math.imul(N,$)|0)+Math.imul(B,H)|0,s=s+Math.imul(B,$)|0,n=n+Math.imul(O,j)|0,o=(o=o+Math.imul(O,Y)|0)+Math.imul(R,j)|0,s=s+Math.imul(R,Y)|0,n=n+Math.imul(_,Z)|0,o=(o=o+Math.imul(_,J)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,J)|0,n=n+Math.imul(M,X)|0,o=(o=o+Math.imul(M,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(E,re)|0,s=s+Math.imul(E,ne)|0,n=n+Math.imul(x,se)|0,o=(o=o+Math.imul(x,ie)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ie)|0,n=n+Math.imul(g,ue)|0,o=(o=o+Math.imul(g,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(f,de)|0,o=(o=o+Math.imul(f,he)|0)+Math.imul(m,de)|0,s=s+Math.imul(m,he)|0;var Te=(c+(n=n+Math.imul(d,fe)|0)|0)+((8191&(o=(o=o+Math.imul(d,me)|0)+Math.imul(h,fe)|0))<<13)|0;c=((s=s+Math.imul(h,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(U,H),o=(o=Math.imul(U,$))+Math.imul(V,H)|0,s=Math.imul(V,$),n=n+Math.imul(N,j)|0,o=(o=o+Math.imul(N,Y)|0)+Math.imul(B,j)|0,s=s+Math.imul(B,Y)|0,n=n+Math.imul(O,Z)|0,o=(o=o+Math.imul(O,J)|0)+Math.imul(R,Z)|0,s=s+Math.imul(R,J)|0,n=n+Math.imul(_,X)|0,o=(o=o+Math.imul(_,ee)|0)+Math.imul(k,X)|0,s=s+Math.imul(k,ee)|0,n=n+Math.imul(M,re)|0,o=(o=o+Math.imul(M,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(E,se)|0,s=s+Math.imul(E,ie)|0,n=n+Math.imul(x,ue)|0,o=(o=o+Math.imul(x,ce)|0)+Math.imul(b,ue)|0,s=s+Math.imul(b,ce)|0,n=n+Math.imul(g,de)|0,o=(o=o+Math.imul(g,he)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,he)|0;var Me=(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)+(Me>>>26)|0,Me&=67108863,n=Math.imul(U,j),o=(o=Math.imul(U,Y))+Math.imul(V,j)|0,s=Math.imul(V,Y),n=n+Math.imul(N,Z)|0,o=(o=o+Math.imul(N,J)|0)+Math.imul(B,Z)|0,s=s+Math.imul(B,J)|0,n=n+Math.imul(O,X)|0,o=(o=o+Math.imul(O,ee)|0)+Math.imul(R,X)|0,s=s+Math.imul(R,ee)|0,n=n+Math.imul(_,re)|0,o=(o=o+Math.imul(_,ne)|0)+Math.imul(k,re)|0,s=s+Math.imul(k,ne)|0,n=n+Math.imul(M,se)|0,o=(o=o+Math.imul(M,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,ce)|0)+Math.imul(E,ue)|0,s=s+Math.imul(E,ce)|0,n=n+Math.imul(x,de)|0,o=(o=o+Math.imul(x,he)|0)+Math.imul(b,de)|0,s=s+Math.imul(b,he)|0;var Se=(c+(n=n+Math.imul(g,fe)|0)|0)+((8191&(o=(o=o+Math.imul(g,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(U,Z),o=(o=Math.imul(U,J))+Math.imul(V,Z)|0,s=Math.imul(V,J),n=n+Math.imul(N,X)|0,o=(o=o+Math.imul(N,ee)|0)+Math.imul(B,X)|0,s=s+Math.imul(B,ee)|0,n=n+Math.imul(O,re)|0,o=(o=o+Math.imul(O,ne)|0)+Math.imul(R,re)|0,s=s+Math.imul(R,ne)|0,n=n+Math.imul(_,se)|0,o=(o=o+Math.imul(_,ie)|0)+Math.imul(k,se)|0,s=s+Math.imul(k,ie)|0,n=n+Math.imul(M,ue)|0,o=(o=o+Math.imul(M,ce)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,ce)|0,n=n+Math.imul(A,de)|0,o=(o=o+Math.imul(A,he)|0)+Math.imul(E,de)|0,s=s+Math.imul(E,he)|0;var Ce=(c+(n=n+Math.imul(x,fe)|0)|0)+((8191&(o=(o=o+Math.imul(x,me)|0)+Math.imul(b,fe)|0))<<13)|0;c=((s=s+Math.imul(b,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(U,X),o=(o=Math.imul(U,ee))+Math.imul(V,X)|0,s=Math.imul(V,ee),n=n+Math.imul(N,re)|0,o=(o=o+Math.imul(N,ne)|0)+Math.imul(B,re)|0,s=s+Math.imul(B,ne)|0,n=n+Math.imul(O,se)|0,o=(o=o+Math.imul(O,ie)|0)+Math.imul(R,se)|0,s=s+Math.imul(R,ie)|0,n=n+Math.imul(_,ue)|0,o=(o=o+Math.imul(_,ce)|0)+Math.imul(k,ue)|0,s=s+Math.imul(k,ce)|0,n=n+Math.imul(M,de)|0,o=(o=o+Math.imul(M,he)|0)+Math.imul(S,de)|0,s=s+Math.imul(S,he)|0;var _e=(c+(n=n+Math.imul(A,fe)|0)|0)+((8191&(o=(o=o+Math.imul(A,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(U,re),o=(o=Math.imul(U,ne))+Math.imul(V,re)|0,s=Math.imul(V,ne),n=n+Math.imul(N,se)|0,o=(o=o+Math.imul(N,ie)|0)+Math.imul(B,se)|0,s=s+Math.imul(B,ie)|0,n=n+Math.imul(O,ue)|0,o=(o=o+Math.imul(O,ce)|0)+Math.imul(R,ue)|0,s=s+Math.imul(R,ce)|0,n=n+Math.imul(_,de)|0,o=(o=o+Math.imul(_,he)|0)+Math.imul(k,de)|0,s=s+Math.imul(k,he)|0;var ke=(c+(n=n+Math.imul(M,fe)|0)|0)+((8191&(o=(o=o+Math.imul(M,me)|0)+Math.imul(S,fe)|0))<<13)|0;c=((s=s+Math.imul(S,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(U,se),o=(o=Math.imul(U,ie))+Math.imul(V,se)|0,s=Math.imul(V,ie),n=n+Math.imul(N,ue)|0,o=(o=o+Math.imul(N,ce)|0)+Math.imul(B,ue)|0,s=s+Math.imul(B,ce)|0,n=n+Math.imul(O,de)|0,o=(o=o+Math.imul(O,he)|0)+Math.imul(R,de)|0,s=s+Math.imul(R,he)|0;var Pe=(c+(n=n+Math.imul(_,fe)|0)|0)+((8191&(o=(o=o+Math.imul(_,me)|0)+Math.imul(k,fe)|0))<<13)|0;c=((s=s+Math.imul(k,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(U,ue),o=(o=Math.imul(U,ce))+Math.imul(V,ue)|0,s=Math.imul(V,ce),n=n+Math.imul(N,de)|0,o=(o=o+Math.imul(N,he)|0)+Math.imul(B,de)|0,s=s+Math.imul(B,he)|0;var Oe=(c+(n=n+Math.imul(O,fe)|0)|0)+((8191&(o=(o=o+Math.imul(O,me)|0)+Math.imul(R,fe)|0))<<13)|0;c=((s=s+Math.imul(R,me)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,n=Math.imul(U,de),o=(o=Math.imul(U,he))+Math.imul(V,de)|0,s=Math.imul(V,he);var Re=(c+(n=n+Math.imul(N,fe)|0)|0)+((8191&(o=(o=o+Math.imul(N,me)|0)+Math.imul(B,fe)|0))<<13)|0;c=((s=s+Math.imul(B,me)|0)+(o>>>13)|0)+(Re>>>26)|0,Re&=67108863;var Le=(c+(n=Math.imul(U,fe))|0)+((8191&(o=(o=Math.imul(U,me))+Math.imul(V,fe)|0))<<13)|0;return c=((s=Math.imul(V,me))+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,u[0]=ye,u[1]=ge,u[2]=we,u[3]=ve,u[4]=xe,u[5]=be,u[6]=Ie,u[7]=Ae,u[8]=Ee,u[9]=Te,u[10]=Me,u[11]=Se,u[12]=Ce,u[13]=_e,u[14]=ke,u[15]=Pe,u[16]=Oe,u[17]=Re,u[18]=Le,0!==c&&(u[19]=c,r.length++),r};function y(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,d=(0|e.words[l])*(0|t.words[c]),h=67108863&d;a=67108863&(h=h+a|0),o+=(i=(i=i+(d/67108864|0)|0)+(h>>>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 g(e,t,r){return y(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?y(this,e,t):g(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),g(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 d=0|this.words[c];this.words[c]=l<<26-s|d>>>s,l=d&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 d=u-1;d>=0;d--){var h=67108864*(0|n.words[s.length+d])+(0|n.words[s.length+d-1]);for(h=Math.min(h/i|0,67108863),n._ishlnsubmul(s,h,d);0!==n.negative;)h--,n.negative=0,n._ishlnsubmul(s,1,d),n.isZero()||(n.negative^=1);a&&(a.words[d]=h)}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(),d=t.clone();!t.isZero();){for(var h=0,p=1;0==(t.words[0]&p)&&h<26;++h,p<<=1);if(h>0)for(t.iushrn(h);h-- >0;)(s.isOdd()||i.isOdd())&&(s.iadd(l),i.isub(d)),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(d)),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 d=0,h=1;0==(n.words[0]&h)&&d<26;++d,h<<=1);if(d>0)for(n.iushrn(d);d-- >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 E(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 x(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function I(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function E(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function T(e){E.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(x,v),x.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},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(b,v),n(I,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 x;else if("p224"===e)t=new b;else if("p192"===e)t=new I;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new A}return w[e]=t,t},E.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},E.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")},E.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},E.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},E.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)},E.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},E.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)},E.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},E.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},E.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},E.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},E.prototype.isqr=function(e){return this.imul(e,e.clone())},E.prototype.sqr=function(e){return this.mul(e,e)},E.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 d=this.pow(l,s),h=this.pow(e,s.addn(1).iushrn(1)),p=this.pow(e,s),f=i;0!==p.cmp(a);){for(var m=p,y=0;0!==m.cmp(a);y++)m=m.redSqr();r(y<f);var g=this.pow(d,new o(1).iushln(f-y-1));h=h.redMul(g),d=g.redSqr(),p=p.redMul(d),f=y}return h},E.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},E.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 d=c>>l&1;s!==r[0]&&(s=this.sqr(s)),0!==d||0!==i?(i<<=1,i|=d,(4==++a||0===n&&0===l)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},E.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},E.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new T(e)},n(T,E),T.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},T.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},T.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},T.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,te);var Ke,We,He=Fe.exports,$e=re(He);!function(t){var r=te&&te.__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=se,o=e,s=r(He);var i=se;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 d(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function h(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)(),d,h,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)}}(oe),exports.TreeType=void 0,(Ke=exports.TreeType||(exports.TreeType={}))[Ke.StateV1=1]="StateV1",Ke[Ke.AddressV1=2]="AddressV1",Ke[Ke.StateV2=3]="StateV2",Ke[Ke.AddressV2=4]="AddressV2",exports.VERSION=void 0,(We=exports.VERSION||(exports.VERSION={})).V1="V1",We.V2="V2";const ze={version:'"V1"',isV2:()=>"V2"===ze.version.replace(/['"]/g,"").toUpperCase()},je=e=>ze.isV2()?`${e}V2`:e,Ye=new $e("21888242871839275222246405745257275088548364400416034343698204186575808495617"),Ge=new $e("452312848583266388373324160190187140051835877600158453279131187530910662655"),Ze=[2,64,66,15,0],Je=y.from([26,16,169,7,21,202,242,25]),Qe=y.from([49,212,191,129,39,194,43,196]),Xe=y.from([86,47,163,166,21,223,92,8]),et=y.from([228,34,128,84,47,139,86,240]),tt=y.from([180,143,159,153,35,46,248,163]),rt="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",nt="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",ot="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",st=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),it=()=>e.PublicKey.findProgramAddressSync([y.from("cpi_authority")],new e.PublicKey(nt))[0],at=()=>({registeredProgramPda:new e.PublicKey(st()),noopProgram:new e.PublicKey(rt),accountCompressionProgram:new e.PublicKey(ot),accountCompressionAuthority:new e.PublicKey(it()),cpiSignatureAccount:null}),ut=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(ft),nullifyLookupTable:new e.PublicKey(mt)}],devnet:[{stateTreeLookupTable:new e.PublicKey(yt),nullifyLookupTable:new e.PublicKey(gt)}]}),ct=e=>e.includes("localhost")||e.includes("127.0.0.1"),lt=()=>[{tree:new e.PublicKey(xt),queue:new e.PublicKey(wt),cpiContext:new e.PublicKey(vt),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Et),queue:new e.PublicKey(Tt),cpiContext:new e.PublicKey(Mt),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(St),queue:new e.PublicKey(Ct),cpiContext:new e.PublicKey(_t),treeType:exports.TreeType.StateV2,nextTreeInfo:null}].filter((e=>ze.isV2()?e.treeType===exports.TreeType.StateV2:e.treeType===exports.TreeType.StateV1)),dt=()=>ze.isV2()?{tree:At,queue:At,cpiContext:null,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}:{tree:new e.PublicKey(bt),queue:new e.PublicKey(It),cpiContext:null,treeType:exports.TreeType.AddressV1,nextTreeInfo:null},ht=()=>({nullifierQueue:new e.PublicKey(wt),merkleTree:new e.PublicKey(xt),merkleTreeHeight:kt,addressTree:new e.PublicKey(bt),addressQueue:new e.PublicKey(It)}),pt=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),ft="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",mt="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",yt="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",gt="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",wt="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",vt="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",xt="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",bt="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",It="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",At=new e.PublicKey("EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK"),Et="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Tt="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",Mt="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",St="HLKs5NJ8FXkJg8BrzJt56adFYYuwg5etzDtBbQYTsixu",Ct="6L7SzhYB3anwEQ9cphpJ1U7Scwj57bx2xueReg7R9cKU",_t="7Hp52chxaew8bW1ApR4fck2bh6Y8qA1pu3qwH6N9zaLj",kt=26,Pt=new $e(Math.floor(2**kt*.95)),Ot=ze.isV2()?new $e(1):new $e(300),Rt=(ze.isV2(),new $e(392)),Lt=new $e(5e3),Nt=new $e(5e3);var Bt=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 d=s;for(;c!==a;)l[d++]=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 d=r.repeat(n);for(;l<u;++l)d+=e.charAt(c[l]);return d},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const Dt=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return Dt(Bt.decode(e))}return function(e){if(e.gte(Ye))throw new Error("Value is too large. Max <254 bits");return e}(new $e(e,t))};function Ut(e){const t=Dt(e).toArrayLike(y,void 0,32);return Bt.encode(new Uint8Array(t))}const Vt=(e,t,r)=>e instanceof Uint8Array&&!(e instanceof y)?new $e(y.from(e),t,r):new $e(e,t,r),Ft=(e,t,r,n)=>({owner:e,lamports:null!=t?t:new $e(0),address:null!=n?n:null,data:null!=r?r:null}),qt=(e,t,r,n,o)=>Object.assign(Object.assign({},e),{owner:t,lamports:null!=r?r:new $e(0),address:null!=o?o:null,data:null!=n?n:null,readOnly:0}),Kt=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n}),Wt=oe.struct([oe.publicKey("owner"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address"),oe.option(oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.vecU8("data"),oe.array(oe.u8(),32,"dataHash")]),"data")],"compressedAccount"),Ht=oe.struct([oe.u8("merkleTreePubkeyIndex"),oe.u8("queuePubkeyIndex"),oe.u32("leafIndex"),oe.bool("proveByIndex")],"merkleContext"),$t=oe.struct([oe.array(oe.u8(),32,"seed"),oe.u8("addressQueueAccountIndex"),oe.u8("addressMerkleTreeAccountIndex"),oe.u16("addressMerkleTreeRootIndex")],"newAddressParams"),zt=oe.struct([oe.option(oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")]),"proof"),oe.vec(oe.struct([Wt,Ht,oe.u16("rootIndex"),oe.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),oe.vec(oe.struct([Wt,oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.option(oe.u64(),"relayFee"),oe.vec($t,"newAddressParams"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.bool("isCompress")]);function jt(e){const t=y.alloc(1e3),r=zt.encode(e,t),n=y.from(new Uint8Array(t.slice(0,r))),o=y.alloc(4);return o.writeUInt32LE(r,0),y.concat([new Uint8Array(Je),new Uint8Array(o),new Uint8Array(n)])}const Yt=oe.struct([oe.option(oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")]),"proof"),oe.vec($t,"newAddressParams"),oe.vec(oe.struct([Wt,Ht,oe.u16("rootIndex"),oe.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),oe.vec(oe.struct([Wt,oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.option(oe.u64(),"relayFee"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.bool("isCompress"),oe.option(oe.struct([oe.bool("set_context"),oe.bool("first_set_context"),oe.u8("cpi_context_account_index")]),"compressedCpiContext")]),Gt=oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")],"compressedProof"),Zt=oe.struct([oe.bool("set_context"),oe.bool("first_set_context"),oe.u8("cpi_context_account_index")],"compressedCpiContext"),Jt=oe.struct([oe.array(oe.u8(),32,"seed"),oe.u8("address_queue_account_index"),oe.u8("address_merkle_tree_account_index"),oe.u16("address_merkle_tree_root_index"),oe.bool("assigned_to_account"),oe.u8("assigned_account_index")],"newAddressParamsAssignedPacked"),Qt=oe.struct([oe.u8("merkle_tree_pubkey_index"),oe.u8("queue_pubkey_index"),oe.u32("leaf_index"),oe.bool("prove_by_index")],"packedMerkleContext"),Xt=oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.array(oe.u8(),32,"data_hash"),Qt,oe.u16("root_index"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address")],"inAccount"),er=oe.struct([oe.array(oe.u8(),32,"address"),oe.u16("address_merkle_tree_root_index"),oe.u8("address_merkle_tree_account_index")],"packedReadOnlyAddress"),tr=oe.struct([oe.array(oe.u8(),32,"account_hash"),Qt,oe.u16("root_index")],"packedReadOnlyCompressedAccount"),rr=oe.struct([oe.u8("mode"),oe.u8("bump"),oe.publicKey("invoking_program_id"),oe.u64("compress_or_decompress_lamports"),oe.bool("is_compress"),oe.bool("with_cpi_context"),oe.bool("with_transaction_hash"),Zt,oe.option(Gt,"proof"),oe.vec(Jt,"new_address_params"),oe.vec(Xt,"input_compressed_accounts"),oe.vec(oe.struct([Wt,oe.u8("merkleTreeIndex")]),"output_compressed_accounts"),oe.vec(er,"read_only_addresses"),oe.vec(tr,"read_only_accounts")]);function nr(e){return rr.decode(e.slice(Xe.length))}function or(e){return zt.decode(e.slice(Je.length+4))}function sr(e){return Yt.decode(e.slice(Qe.length+4))}const ir=e=>{const t=Jn.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}]},ar=oe.struct([oe.vec(oe.array(oe.u8(),32),"inputCompressedAccountHashes"),oe.vec(oe.array(oe.u8(),32),"outputCompressedAccountHashes"),oe.vec(oe.struct([oe.struct([oe.publicKey("owner"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address"),oe.option(oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.vecU8("data"),oe.array(oe.u8(),32,"dataHash")]),"data")],"compressedAccount"),oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.vec(oe.u32(),"outputLeafIndices"),oe.vec(oe.struct([oe.publicKey("tree_pubkey"),oe.publicKey("queue_pubkey"),oe.u64("tree_type"),oe.u64("seq")]),"sequenceNumbers"),oe.option(oe.u64(),"relayFee"),oe.bool("isCompress"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.vec(oe.publicKey(),"pubkeyArray"),oe.option(oe.vecU8(),"message")]);function ur(e){return ar.decode(e)}const cr=oe.struct([oe.u8("is_invoked_by_program"),oe.u8("bump"),oe.u8("num_queues"),oe.u8("num_output_queues"),oe.u8("start_output_appends"),oe.u8("num_address_queues"),oe.array(oe.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),lr=oe.struct([oe.u8("index"),oe.array(oe.u8(),32,"leaf")],"appendLeavesInput"),dr=oe.struct([oe.array(oe.u8(),32,"account_hash"),oe.u32("leaf_index"),oe.u8("prove_by_index"),oe.u8("tree_index"),oe.u8("queue_index")],"insertNullifierInput"),hr=oe.struct([oe.array(oe.u8(),32,"address"),oe.u8("tree_index"),oe.u8("queue_index")],"insertAddressInput"),pr=oe.struct([oe.publicKey("tree_pubkey"),oe.publicKey("queue_pubkey"),oe.u64("tree_type"),oe.u64("seq")],"merkleTreeSequenceNumber");function fr(e){let t=0;const r=cr.decode(e,t);t+=cr.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=lr.decode(e,t);o.push(r),t+=lr.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=dr.decode(e,t);i.push(r),t+=dr.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=hr.decode(e,t);u.push(r),t+=hr.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=pr.decode(e,t);l.push(r),t+=pr.span}const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)pr.decode(e,t),t+=pr.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)pr.decode(e,t),t+=pr.span;const p=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<p;r++){const r=oe.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 mr(t,r,n){const o=e=>Array.from(e instanceof y?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:Vt((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(y.from(null===(u=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===u?void 0:u.discriminator)),data:null!==(c=o(y.from(new Uint8Array(n.outputCompressedAccounts[r].compressedAccount.data.data))))&&void 0!==c?c:[],dataHash:o(y.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((e=>({tree_pubkey:e.tree_pubkey,queue_pubkey:e.queue_pubkey,tree_type:e.tree_type,seq:e.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)?Vt(n.relayFee):null,compressOrDecompressLamports:(null==n?void 0:n.compressOrDecompressLamports)?Vt(n.compressOrDecompressLamports):null,message:null}}function yr(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function gr(e,t){return t<=0?[]:new Array(t).fill(e)}function wr(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function vr(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=yr(s,e.treeInfo.tree),o=yr(s,e.treeInfo.queue);i.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleContext:{merkleTreePubkeyIndex:n,queuePubkeyIndex:o,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex},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;let l=c.tree;if(c.treeType===exports.TreeType.StateV2){if(!ze.isV2())throw new Error("V2 trees are not supported yet");l=c.queue}const d=gr(l,r.length);return r.forEach(((e,t)=>{const r=yr(s,d[t]);a.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:s}}function xr(e,t){switch(e.treeType){case exports.TreeType.StateV1:return t.insertOrGet(e.tree);case exports.TreeType.StateV2:return t.insertOrGet(e.queue);default:throw new Error("Invalid tree type for packing output tree index")}}const br=e=>{if(e.lt(Vt(0)))throw new Error("Insufficient balance for transfer")},Ir=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")},Ar=(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(", ")}`);ze.isV2()?Mr(e,[1,2,3,4,8],"compressed accounts"):Mr(e,[1,2,3,4],"compressed accounts"),Tr(t)}else e>0?Er(e):Tr(t)},Er=e=>{ze.isV2()?Mr(e,[1,2,3,4,8],"compressed accounts"):Mr(e,[1,2,3,4],"compressed accounts")},Tr=e=>{ze.isV2()?Mr(e,[1,2,3,4],"new addresses"):Mr(e,[1,2],"new addresses")},Mr=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function Sr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Cr(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 _r(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 kr=BigInt(2**32-1),Pr=BigInt(32);function Or(e,t=0){return t?{h:Number(e&kr),l:Number(e>>Pr&kr)}:{h:0|Number(e>>Pr&kr),l:0|Number(e&kr)}}function Rr(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}=Or(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const Lr=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function Nr(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 Br(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)),Cr(e),e}class Dr{clone(){return this._cloneInto()}}const Ur=[],Vr=[],Fr=[],qr=BigInt(0),Kr=BigInt(1),Wr=BigInt(2),Hr=BigInt(7),$r=BigInt(256),zr=BigInt(113);for(let e=0,t=Kr,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Ur.push(2*(5*n+r)),Vr.push((e+1)*(e+2)/2%64);let o=qr;for(let e=0;e<7;e++)t=(t<<Kr^(t>>Hr)*zr)%$r,t&Wr&&(o^=Kr<<(Kr<<BigInt(e))-Kr);Fr.push(o)}const[jr,Yr]=Rr(Fr,1),Gr=(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),Zr=(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 Jr extends Dr{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,Sr(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(){Lr||Nr(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=Gr(s,i,1)^r[n],u=Zr(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=Vr[r],s=Gr(t,o,n),i=Zr(t,o,n),a=Ur[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]^=jr[n],e[1]^=Yr[n]}r.fill(0)}(this.state32,this.rounds),Lr||Nr(this.state32),this.posOut=0,this.pos=0}update(e){_r(this);const{blockLen:t,state:r}=this,n=(e=Br(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){_r(this,0),Cr(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 Sr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){Cr(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 Jr(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 Qr=(()=>function(e){const t=t=>e().update(Br(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new Jr(136,1,32))))(),Xr=e=>"object"==typeof e&&null!==e,en=e=>Xr(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),tn=Symbol("mapObjectSkip"),rn=(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=>en(e)?rn(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===tn)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&en(l)&&(l=Array.isArray(l)?s(l):rn(l,t,r,n)),o[c]=l)}return o};function nn(e,t,r){if(!Xr(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return rn(e,t,r)}const on=/[\p{Lu}]/u,sn=/[\p{Ll}]/u,an=/^[\p{Lu}](?![\p{Lu}])/gu,un=/([\p{Alpha}\p{N}_]|$)/u,cn=/[_.\- ]+/,ln=new RegExp("^"+cn.source),dn=new RegExp(cn.source+un.source,"gu"),hn=new RegExp("\\d+"+un.source,"gu");class pn 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 fn=new pn({maxSize:1e5}),mn=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),yn=(e,t={})=>{if(!mn(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&&mn(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=nn(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(fn.has(e))t=fn.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?cn.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&&on.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&sn.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(ln,""),e=t.preserveConsecutiveUppercase?((e,t)=>(an.lastIndex=0,e.replaceAll(an,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>(dn.lastIndex=0,hn.lastIndex=0,e.replaceAll(hn,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll(dn,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&fn.set(e,r),t=r}}return[t,o]};return nn(e,u(void 0))};function gn(e){return"0x"+e.toString("hex")}function wn(e){return Vt(e,void 0,"be").lt(Ye)}const vn=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>yn(t[e],r))):yn(t,r);var t,r};function xn(e){let t=255;for(;t>=0;){const r=y.concat([e,y.from([t])]),n=Qr(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,wn(y.from(n)))return[y.from(n),t];t-=1}return null}function bn(e){const t=Qr.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function In(t){const r=t.proof?{a:t.proof.a,b:t.proof.b,c:t.proof.c}:null,n=t.new_address_params.map((e=>({seed:e.seed,addressMerkleTreeRootIndex:e.address_merkle_tree_root_index,addressMerkleTreeAccountIndex:e.address_merkle_tree_account_index,addressQueueAccountIndex:e.address_queue_account_index})));return{proof:r,inputCompressedAccountsWithMerkleContext:t.input_compressed_accounts.map((t=>({compressedAccount:{owner:new e.PublicKey(y.alloc(32)),lamports:Vt(t.lamports),address:t.address,data:null},merkleContext:{merkleTreePubkeyIndex:t.packedMerkleContext.merkle_tree_pubkey_index,queuePubkeyIndex:t.packedMerkleContext.queue_pubkey_index,leafIndex:t.packedMerkleContext.leaf_index,proveByIndex:t.packedMerkleContext.prove_by_index},rootIndex:t.root_index,readOnly:0}))),outputCompressedAccounts:t.output_compressed_accounts.map((e=>({compressedAccount:{owner:e.compressedAccount.owner,lamports:e.compressedAccount.lamports,address:e.compressedAccount.address,data:e.compressedAccount.data},merkleTreeIndex:e.merkleTreeIndex}))),relayFee:null,newAddressParams:n,compressOrDecompressLamports:t.compress_or_decompress_lamports,isCompress:t.is_compress}}function An(e,t,r){return En([e,t,r])}function En(e){const t=Qr.create();for(const r of e)t.update(r);t.update(new Uint8Array([255]));const r=t.digest();return r[0]=0,r}function Tn(e,t){return bn([t.toBytes(),...e])}function Mn(t,r=ht().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=xn(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=yr(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=yr(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function Cn(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 _n(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}function kn(e){const t=On(e.ar[0]),r=On(e.ar[1]),n=new Uint8Array([...t,...r]),o=On(e.bs[0][0]),s=On(e.bs[0][1]),i=On(e.bs[1][0]),a=On(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=On(e.krs[0]),l=On(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function Pn(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=Rn(Vt(t.slice(32,64),32,"be"))?0:1;o[0]=Ln(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=Ye.div(Vt(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(Vt(a.slice(0,32),32,"be"),Vt(a.slice(32,64),32,"be"));i[0]=Ln(i[0],u);const c=n.slice(0,32),l=n.slice(32,64),d=Rn(Vt(l,32,"be"));return c[0]=Ln(c[0],d),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function On(e){const t=Vt(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function Rn(e){return e.lte(Ye.sub(e))}function Ln(e,t){return t?e:128|e}function Nn(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function Bn(e,t,r){const n=await e.sendTransaction(t,r);return await Dn(e,n,r),n}async function Dn(e,t,r){const n=(null==r?void 0:r.commitment)||e.commitment||"confirmed",o=ct(e.rpcEndpoint)?200:1e3;let s=0;await new Promise(((r,i)=>{const a=setInterval((async()=>{var u;s+=o,s>=8e4&&(clearInterval(a),i(new Error(`Transaction ${t}'s confirmation timed out`)));const c=await e.getSignatureStatuses([t]);(null===(u=null==c?void 0:c.value[0])||void 0===u?void 0:u.confirmationStatus)===n&&(clearInterval(a),r(t))}),o)}));const i=await e.getSlot();return await e.confirmTransactionIndexed(i),{context:{slot:i},value:{err:null}}}function Un(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=Nn(e,t.publicKey,r,o);return i.sign(s),i}function Vn(e,t){return Fn(e,t)}function Fn(e,t){const r=e.find((e=>e.tree.equals(t)||e.queue.equals(t)));if(!r)throw new Error(`No associated TreeInfo found for tree or queue. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: ${t.toBase58()}`);if(!r.queue)throw new Error("Queue must not be null for state tree. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: "+t.toBase58());return r}function qn(e,t=(ze.isV2()?exports.TreeType.StateV2: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 Kn({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}class Wn{constructor(){this.preAccounts=[],this.systemAccounts=[],this.nextIndex=0,this.map=new Map}static newWithSystemAccounts(e){const t=new Wn;return t.addSystemAccounts(e),t}addPreAccountsSigner(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:0})}addPreAccountsSignerMut(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:1})}addPreAccountsMeta(e){this.preAccounts.push(e)}addSystemAccounts(e){this.systemAccounts.push(...$n(e))}insertOrGet(e){return this.insertOrGetConfig(e,0,1)}insertOrGetReadOnly(e){return this.insertOrGetConfig(e,0,0)}insertOrGetConfig(e,t,r){const n=e.toString(),o=this.map.get(n);if(o)return o[0];const s=this.nextIndex++,i={pubkey:e,isSigner:t,isWritable:r};return this.map.set(n,[s,i]),s}hashSetAccountsToMetas(){const e=Array.from(this.map.entries());return e.sort(((e,t)=>e[1][0]-t[1][0])),e.map((([,[,e]])=>e))}getOffsets(){const e=this.preAccounts.length;return[e,e+this.systemAccounts.length]}toAccountMetas(){const e=this.hashSetAccountsToMetas(),[t,r]=this.getOffsets();return{remainingAccounts:[...this.preAccounts,...this.systemAccounts,...e],systemStart:t,packedStart:r}}}class Hn{constructor(e,t,r,n){this.selfProgram=e,this.cpiContext=t,this.solCompressionRecipient=r,this.solPoolPda=n}static new(e){return new Hn(e)}static newWithCpiContext(e,t){return new Hn(e,t)}}function $n(t){let r=(new TextEncoder).encode("cpi_authority");const n=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],o=Yn.default(),s=[{pubkey:o.lightSystemProgram,isSigner:0,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:o.noopProgram,isSigner:0,isWritable:0},{pubkey:o.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:o.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.selfProgram,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),s.push({pubkey:o.systemProgram,isSigner:0,isWritable:0}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}class zn{constructor(){this.preAccounts=[],this.systemAccounts=[],this.nextIndex=0,this.map=new Map}static newWithSystemAccounts(e){const t=new zn;return t.addSystemAccounts(e),t}getNamedMetas(){return this.map}addPreAccountsSigner(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:0})}addPreAccountsSignerMut(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:1})}addPreAccountsMeta(e){this.preAccounts.push(e)}addSystemAccounts(e){this.systemAccounts.push(...jn(e))}insertOrGet(e){return this.insertOrGetConfig(e,0,1)}insertOrGetReadOnly(e){return this.insertOrGetConfig(e,0,0)}insertOrGetConfig(e,t,r){const n=e.toString(),o=this.map.get(n);if(o)return o[0];const s=this.nextIndex++,i={pubkey:e,isSigner:t,isWritable:r};return this.map.set(n,[s,i]),s}hashSetAccountsToMetas(){const e=Array.from(this.map.entries());return e.sort(((e,t)=>e[1][0]-t[1][0])),e.map((([,[,e]])=>e))}getOffsets(){const e=this.preAccounts.length;return[e,e+this.systemAccounts.length]}toAccountMetas(){const e=this.hashSetAccountsToMetas(),[t,r]=this.getOffsets();return{remainingAccounts:[...this.preAccounts,...this.systemAccounts,...e],systemStart:t,packedStart:r}}}function jn(t){let r=(new TextEncoder).encode("cpi_authority");const n=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],o=Yn.default(),s=[{pubkey:o.lightSystemProgram,isSigner:0,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:o.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:o.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:o.systemProgram,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}class Yn{constructor(e,t,r,n,o,s,i){this.lightSystemProgram=e,this.systemProgram=t,this.accountCompressionProgram=r,this.accountCompressionAuthority=n,this.registeredProgramPda=o,this.noopProgram=s,this.solPoolPda=i}static default(){return new Yn(Jn.programId,e.SystemProgram.programId,at().accountCompressionProgram,at().accountCompressionAuthority,at().registeredProgramPda,at().noopProgram,e.PublicKey.default)}}const Gn=e=>e.reduce(((e,t)=>e.add(Vt(t.lamports))),Vt(0)),Zn=y.from("sol_pool_pda");class Jn{constructor(){}static deriveCompressedSolPda(){const t=[Zn],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=Vt(r);const n=Gn(e).sub(r);return br(n),n.eq(Vt(0))?[Ft(t,r)]:(Ir(e),[Ft(e[0].owner,n),Ft(t,r)])}static createDecompressOutputState(e,t){t=Vt(t);const r=Gn(e).sub(t);return br(r),r.eq(Vt(0))?[]:(Ir(e),[Ft(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=Vt(null!=r?r:0);const o=Gn(null!=n?n:[]).sub(r);return br(o),o.eq(Vt(0))||!n?[Ft(t,r,void 0,e)]:(Ir(n),[Ft(n[0].owner,o),Ft(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:d,remainingAccounts:h}=vr(null!=i?i:[],null!=a?a:[],c,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:f}=Sn([r],h),m=jt({proof:o,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:d,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),y=[...ir(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...wr(f)];return new e.TransactionInstruction({programId:this.programId,keys:y,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}=vr(r,s,a),d=jt({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),h=[...ir(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...wr(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTreeInfo:o}){n=Vt(n);const s=Ft(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=vr([],[],[s],o),c=jt({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),l=[...ir(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:Jn.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...wr(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=Vt(o);const a=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=vr(r,s,a),d=jt({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),h=[...ir(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:Jn.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),...wr(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}}function Qn(e,t){let r=Vt(0);t=Vt(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(Vt(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(Vt(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}Jn.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([Vt(this.value.toArray("be",32)).toString(),Vt(this.nextIndex).toString(),Vt(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class eo{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class to{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new to([new Xn(0,Vt(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=Ge;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([Vt(r.value.toArray("be",32)).toString(),Vt(r.nextIndex).toString(),Vt(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 eo(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 ro{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 no(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=at(),o=(await e.getSignaturesForAddress(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===Ze.length&&Ze.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=Bt.decode(t.data);o.push(e)}}const a=io(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 oo(i,so)}const oo=(e,t)=>{const{noopProgram:r}=at(),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=Bt.decode(s.data),o=t(y.from(r),e);null!=o&&n.push(o)}}}))})),n},so=e=>{const t=y.from(e.map((e=>e)));try{return ur(t)}catch(e){return console.error("Error deserializing event:",e),null}};function io(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=Bt.encode(e),s=Bt.encode(Je),i=Bt.encode(Qe),a=Bt.encode(Xe);if(o===s){n=or(y.from(t)),r=1;break}if(o==i){n=sr(y.from(t)),r=1;break}if(o==a){n=In(nr(y.from(t))),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if(Bt.encode(e)===Bt.encode(tt)){const e=t.slice(12);o=fr(y.from(e))}}return n?mr(o,t[t.length-1],n):null}async function ao(e,t){return(await uo(e)).find((e=>Vt(e.hash).eq(t)))}async function uo(e){var t,r;const n=(await no(e)).reverse(),o=[],s=[],i=await e.getStateTreeInfos();for(const e of n){for(let n=0;n<e.outputCompressedAccounts.length;n++){const s=Vn(i,e.pubkeyArray[e.outputCompressedAccounts[n].merkleTreeIndex]),a=e.outputCompressedAccounts[n],u={treeInfo:s,hash:Vt(e.outputCompressedAccountHashes[n]),leafIndex:e.outputLeafIndices[n],proveByIndex:s.treeType===exports.TreeType.StateV2},c=qt(u,a.compressedAccount.owner,a.compressedAccount.lamports,null!==(t=a.compressedAccount.data)&&void 0!==t?t:void 0,null!==(r=a.compressedAccount.address)&&void 0!==r?r:void 0);o.push(c)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];s.push(Vt(r))}}const a=o.filter((e=>!s.some((t=>t.eq(Vt(e.hash))))));return a.sort(((e,t)=>t.leafIndex-e.leafIndex)),a}const co=oe.struct([oe.publicKey("mint"),oe.publicKey("owner"),oe.u64("amount"),oe.option(oe.publicKey(),"delegate"),oe.u8("state"),oe.option(oe.vecU8(),"tlv")]);function lo(e,t=pt){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 co.decode(Buffer.from(r))}catch(e){throw console.error("Decoding error:",e),e}}async function ho(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=Vn(n,a);if(!(u.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])||ze.isV2()&&u.queue.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])))throw new Error("Invalid tree");const c={treeInfo:u,hash:Vt(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:u.treeType===exports.TreeType.StateV2};if(!t.compressedAccount.data)throw new Error("No data");const l=lo(t.compressedAccount);if(!l)throw new Error("Invalid token data");return{compressedAccount:qt(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=>Vt(t).eq(e.compressedAccount.hash)))))}async function po(e,t,r){const n=await no(e);return{items:(await ho(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 fo(e,t,r){const n=await no(e);return{items:(await ho(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 mo(e,t){const r=await no(e),n=(await ho(r,e)).filter((e=>Vt(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class yo 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 go(e){return"object"==typeof e&&null!=e}function wo(e){return go(e)&&!Array.isArray(e)}function vo(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function xo(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: \`${vo(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*bo(e,t,r,n){var o;go(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=xo(o,t,r,n);e&&(yield e)}}function*Io(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,d]of t.entries(e,a)){const t=Io(l,d,{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):go(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 Ao{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)=>bo(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>bo(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Mo(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Eo(e,this,t)}is(e){return To(e,this)}mask(e,t){return function(e,t,r){const n=Mo(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Mo(e,this,t)}}function Eo(e,t,r){const n=Mo(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function To(e,t){return!Mo(e,t)[0]}function Mo(e,t,r={}){const n=Io(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new yo(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function So(e,t){return new Ao({type:e,schema:null,validator:t})}function Co(){return So("any",(()=>1))}function _o(e){return new Ao({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: ${vo(e)}`})}function ko(){return So("boolean",(e=>"boolean"==typeof e))}function Po(e){return So("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${vo(t)}`))}function Oo(e){const t=vo(e);return new Ao({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${vo(r)}`})}function Ro(e){return new Ao({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function Lo(){return So("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${vo(e)}`))}function No(){return So("string",(e=>"string"==typeof e||`Expected a string, but received: ${vo(e)}`))}function Bo(e){const t=Object.keys(e);return new Ao({type:"type",schema:e,*entries(r){if(go(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>wo(e)||`Expected an object, but received: ${vo(e)}`,coercer:e=>wo(e)?{...e}:e})}function Do(e){const t=e.map((e=>e.type)).join(" | ");return new Ao({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]=Io(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: ${vo(r)}`,...o]}})}function Uo(){return So("unknown",(()=>1))}function Vo(e,t,r){return new Ao({...e,coercer:(n,o)=>To(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}const Fo=Vo(Po(e.PublicKey),No(),(t=>new e.PublicKey(t))),qo=Vo(Po(Array),No(),(t=>Array.from(new e.PublicKey(t).toBytes()))),Ko=Vo(Po($e),No(),(e=>Dt(e,"base58"))),Wo=Vo(Po($e),Do([No(),Lo()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return Vt(e)}return Vt(e,10)})),Ho=Vo(No(),No(),(e=>""===e?null:e));function $o(e){return Do([Bo({jsonrpc:Oo("2.0"),id:No(),result:e}),Bo({jsonrpc:Oo("2.0"),id:No(),error:Bo({code:Uo(),message:No(),data:Ro(Co())})})])}Vo(No(),No(),(e=>""===e?null:e));const zo=$o(Uo());function jo(e){return Vo($o(e),zo,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:Eo(t.result,e)})))}function Yo(e){return jo(Bo({context:Bo({slot:Lo()}),value:e}))}const Go=Bo({treeType:Lo(),tree:Fo,queue:Fo,cpiContext:Ro(Fo)}),Zo=Bo({treeType:Lo(),tree:Fo,queue:Fo,cpiContext:Ro(Fo),nextTreeContext:(Jo=Ro(Go),new Ao({...Jo,validator:(e,t)=>void 0===e||Jo.validator(e,t),refiner:(e,t)=>void 0===e||Jo.refiner(e,t)}))});var Jo;const Qo=Bo({address:Ro(qo),hash:Ko,data:Ro(Bo({data:Ho,dataHash:Ko,discriminator:Wo})),lamports:Wo,owner:Fo,leafIndex:Lo(),tree:Fo,seq:Ro(Wo),slotCreated:Wo}),Xo=Bo({address:Ro(qo),hash:Ko,data:Ro(Bo({data:Ho,dataHash:Ko,discriminator:Wo})),lamports:Wo,owner:Fo,leafIndex:Lo(),seq:Ro(Wo),slotCreated:Wo,merkleContext:Zo,proveByIndex:ko()}),es=Bo({mint:Fo,owner:Fo,amount:Wo,delegate:Ro(Fo),state:No()}),ts=Bo({tokenData:es,account:Qo}),rs=Bo({tokenData:es,account:Xo}),ns=Bo({items:_o(Qo)}),os=Bo({items:_o(Xo)}),ss=Bo({items:_o(Qo),cursor:Ro(No())}),is=Bo({items:_o(Xo),cursor:Ro(No())}),as=Bo({items:_o(ts),cursor:Ro(No())}),us=Bo({items:_o(rs),cursor:Ro(No())}),cs=Lo(),ls=No(),ds=Bo({items:_o(Bo({signature:No(),slot:Lo(),blockTime:Lo(),error:Ro(No())}))}),hs=Bo({items:_o(Bo({signature:No(),slot:Lo(),blockTime:Lo()})),cursor:Ro(No())}),ps=Bo({hash:Ko,leafIndex:Lo(),merkleTree:Fo,proof:_o(Ko),rootSeq:Lo(),root:Ko}),fs=Bo({hash:Ko,leafIndex:Lo(),proof:_o(Ko),root:Ko,rootSeq:Lo(),proveByIndex:ko(),treeContext:Zo}),ms=Bo({address:Ko,nextIndex:Lo(),merkleTree:Fo,proof:_o(Ko),rootSeq:Lo(),root:Ko,lowerRangeAddress:Ko,higherRangeAddress:Ko,lowElementLeafIndex:Lo()}),ys=Bo({a:_o(Lo()),b:_o(Lo()),c:_o(Lo())}),gs=Bo({rootIndex:Lo(),proveByIndex:ko()}),ws=Bo({compressedProof:ys,leafIndices:_o(Lo()),leaves:_o(Ko),rootIndices:_o(Lo()),roots:_o(Ko),merkleTrees:_o(Fo)}),vs=Bo({hash:Ko,root:Ko,rootIndex:gs,merkleContext:Zo,leafIndex:Lo()}),xs=Bo({address:Ko,root:Ko,rootIndex:Lo(),merkleContext:Zo}),bs=Bo({compressedProof:Ro(ys),accounts:_o(vs),addresses:_o(xs)}),Is=_o(ps),As=_o(fs),Es=Bo({amount:Wo}),Ts=Wo,Ms=Bo({balance:Wo,mint:Fo}),Ss=Bo({tokenBalances:_o(Ms),cursor:Ro(No())}),Cs=Bo({items:_o(Ms),cursor:Ro(No())}),_s=Bo({cursor:Ro(No()),items:_o(Bo({balance:Wo,owner:Fo}))}),ks=Bo({hash:_o(Lo()),root:_o(Lo()),proof:_o(_o(Lo()))}),Ps=Bo({items:_o(Bo({blockTime:Lo(),signature:No(),slot:Lo()}))}),Os=Bo({items:_o(Bo({blockTime:Lo(),signature:No(),slot:Lo()})),cursor:Ro(No())}),Rs=Bo({account:Xo,txHash:Ko,nullifier:Ko}),Ls=Bo({compressionInfo:Bo({closedAccounts:_o(Bo({account:Qo,optionalTokenData:Ro(es)})),openedAccounts:_o(Bo({account:Qo,optionalTokenData:Ro(es)}))}),transaction:Co()}),Ns=Bo({compressionInfo:Bo({closedAccounts:_o(Bo({account:Rs,optionalTokenData:Ro(es)})),openedAccounts:_o(Bo({account:Xo,optionalTokenData:Ro(es)}))}),transaction:Co()});function Bs({discriminator:e,data:t,dataHash:r}){const n=y.from(e.toArray("le",8));return{discriminator:Array.from(n),data:y.from(t,"base64"),dataHash:r.toArray("be",32)}}async function Ds(t,r,n,o=0){var s,i;const a=je(o?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner"),u=o?"delegate":"owner",c=await Vs(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});let l;if(l=ze.isV2()?Eo(c,Yo(us)):Eo(c,Yo(as)),"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 d=[],h=await t.getStateTreeInfos();return l.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=ze.isV2()?n.merkleContext.tree:n.tree,i=ze.isV2()?n.proveByIndex:0,a=Vn(h,s),c=qt(Kt(a,n.hash,n.leafIndex,i),n.owner,Vt(n.lamports),n.data?Bs(n.data):void 0,n.address||void 0),l={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=l[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);d.push({compressedAccount:c,parsed:l})})),{items:d.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:l.result.value.cursor}}function Us(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 Vs=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=Us(await i.text());return n?vn(JSON.parse(a)):JSON.parse(a)},Fs=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=Pn(kn(await i.json()));return n&&console.timeEnd(s),a};function qs(e){const t=[];for(let r=0;r<e.length;r++){const n={root:gn(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>gn(e))),leaf:gn(Vt(e[r].hash))};t.push(n)}return t}function Ks(e){const t=[];for(let r=0;r<e.length;r++){const n={root:gn(e[r].root),value:gn(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>gn(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:gn(e[r].leafLowerRangeValue),leafHigherRangeValue:gn(e[r].leafHigherRangeValue)};t.push(n)}return t}function Ws(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return Vt(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 Hs(e){const t=e.account,r=e.optionalTokenData,n=qt(Kt(t.treeInfo,t.hash.toArray("be",32),t.leafIndex,t.proveByIndex),t.owner,Vt(t.lamports),t.data?Bs(t.data):void 0,t.address||void 0);return null===r?{account:n,maybeTokenData:null}:{account:n,maybeTokenData:{mint:r.mint,owner:r.owner,amount:r.amount,delegate:r.delegate,state:["uninitialized","initialized","frozen"].indexOf(r.state),tlv:null}}}class $s 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 getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(ct(this.rpcEndpoint))return lt();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}=ut();try{return await Kn({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await Kn({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=await this.getStateTreeInfos(),o=await Vs(this.compressionApiEndpoint,je("getCompressedAccount"),{hash:r?Ut(r):void 0,address:t?Ut(t):void 0});let s;if(s=ze.isV2()?Eo(o,Yo(Ro(Xo))):Eo(o,Yo(Ro(Qo))),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===s.result.value)return null;const i=Vn(n,ze.isV2()?s.result.value.merkleContext.tree:s.result.value.tree),a=s.result.value;return qt(Kt(i,a.hash,a.leafIndex),a.owner,Vt(a.lamports),a.data?Bs(a.data):void 0,a.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=Eo(await Vs(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?Ut(r):void 0,address:t?Ut(t):void 0}),Yo(Ts));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?Vt(0):Vt(n.result.value)}async getCompressedBalanceByOwner(t){const r=Eo(await Vs(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),Yo(Ts));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?Vt(0):Vt(r.result.value)}async getCompressedAccountProof(t){const r=await Vs(this.compressionApiEndpoint,je("getCompressedAccountProof"),{hash:Ut(t)});let n;if(n=ze.isV2()?Eo(r,Yo(fs)):Eo(r,Yo(ps)),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get proof for compressed account ${t.toString()}`);if(null===n.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const o=Vn(await this.getStateTreeInfos(),ze.isV2()?n.result.value.treeContext.tree:n.result.value.tree);return{hash:Vt(n.result.value.hash.toArray("be",32)),treeInfo:o,leafIndex:n.result.value.leafIndex,merkleProof:n.result.value.proof,rootIndex:n.result.value.rootSeq%2400,root:n.result.value.root,proveByIndex:ze.isV2()?n.result.value.proveByIndex:0}}async getMultipleCompressedAccounts(t){const r=await Vs(this.compressionApiEndpoint,je("getMultipleCompressedAccounts"),{hashes:t.map((e=>Ut(e)))});let n;if(n=ze.isV2()?Eo(r,Yo(os)):Eo(r,Yo(ns)),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get info for compressed accounts ${t.map((e=>Ut(e))).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>Ut(e))).join(", ")}`);const o=await this.getStateTreeInfos(),s=[];return n.result.value.items.map((e=>{const t=ze.isV2()?e.merkleContext.tree:e.tree,r=Vn(o,t),n=qt(Kt(r,Vt(e.hash.toArray("be",32)),e.leafIndex),e.owner,Vt(e.lamports),e.data?Bs(e.data):void 0,e.address||void 0);s.push(n)})),s.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=await Vs(this.compressionApiEndpoint,je("getMultipleCompressedAccountProofs"),t.map((e=>Ut(e))));let n;if(n=ze.isV2()?Eo(r,Yo(_o(fs))):Eo(r,Yo(_o(ps))),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get proofs for compressed accounts ${t.map((e=>Ut(e))).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>Ut(e))).join(", ")}`);const o=[],s=await this.getStateTreeInfos();for(const e of n.result.value){const t=Vn(s,ze.isV2()?e.treeContext.tree:e.merkleTree),r={hash:Vt(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:ze.isV2()?e.proveByIndex:0};o.push(r)}return o}async getCompressedAccountsByOwner(t,r){var n;const o=await Vs(this.compressionApiEndpoint,je("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()});let s;if(s=ze.isV2()?Eo(o,Yo(is)):Eo(o,Yo(ss)),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===s.result.value)return{items:[],cursor:null};const i=[],a=await this.getStateTreeInfos();return s.result.value.items.map((e=>{const t=Vn(a,ze.isV2()?e.merkleContext.tree:e.tree),r=qt(Kt(t,Vt(e.hash.toArray("be",32)),e.leafIndex,ze.isV2()?e.proveByIndex:0),e.owner,Vt(e.lamports),e.data?Bs(e.data):void 0,e.address||void 0);i.push(r)})),{items:i.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:s.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Ds(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await Ds(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=Eo(await Vs(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:Ut(t)}),Yo(Es));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:Vt(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var n,o;r||(r={});const s=Eo(await Vs(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(Ss));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=Eo(await Vs(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(Cs));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=Eo(await Vs(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:Ut(t)}),Yo(Ps));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=await Vs(this.compressionApiEndpoint,je("getTransactionWithCompressionInfo"),{signature:t});let n;if(n=ze.isV2()?Eo(r,jo(Ns)):Eo(r,jo(Ls)),"error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get slot");if(null===n.result.transaction)return null;const o=[],s=[],i=await this.getStateTreeInfos();ze.isV2()?(n.result.compressionInfo.closedAccounts.map((e=>{o.push(function(e){const t={account:e.account.account,optionalTokenData:e.optionalTokenData},r={nullifier:e.account.nullifier,txHash:e.account.txHash},n=Hs(t);return{account:n.account,maybeTokenData:n.maybeTokenData,maybeNullifierMetadata:r}}(e))})),n.result.compressionInfo.openedAccounts.map((e=>{s.push(Hs(e))}))):(n.result.compressionInfo.closedAccounts.map((e=>{const t=Vn(i,e.account.tree),r=qt(Kt(t,Vt(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Vt(e.account.lamports),e.account.data?Bs(e.account.data):void 0,e.account.address||void 0);o.push({account:r,maybeTokenData:e.optionalTokenData})})),n.result.compressionInfo.openedAccounts.map((e=>{const t=Vn(i,e.account.tree),r=qt(Kt(t,Vt(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Vt(e.account.lamports),e.account.data?Bs(e.account.data):void 0,e.account.address||void 0);s.push({account:r,maybeTokenData:e.optionalTokenData})})));const a=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},u=a(o),c=a(s);return{compressionInfo:{closedAccounts:o,openedAccounts:s,preTokenBalances:u,postTokenBalances:c},transaction:n.result.transaction}}async getCompressionSignaturesForAddress(t,r){var n;const o=Eo(await Vs(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(Os));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=Eo(await Vs(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(Os));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=Eo(await Vs(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(Os));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=Eo(await Vs(this.compressionApiEndpoint,"getIndexerHealth"),jo(ls));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.result}async confirmTransactionIndexed(e){const t=ct(this.rpcEndpoint)?1e4:2e4,r=ct(this.rpcEndpoint)?100:200,n=Date.now();for(;;){if(await this.getIndexerSlot()>=e)return 1;if(Date.now()-n>t)throw new Error(`Timeout: Indexer slot did not reach the required slot within ${t/1e3}s`);await new Promise((e=>setTimeout(e,r)))}}async getIndexerSlot(){const t=Eo(await Vs(this.compressionApiEndpoint,"getIndexerSlot"),jo(cs));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=Eo(await Vs(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(_s));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=Eo(await Vs(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),Yo(hs));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=Eo(await Vs(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),Yo(ds));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=Eo(await Vs(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>Ut(e)))),Yo(_o(ms)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>Ut(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>Ut(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:Vt(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:Vt(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:ht().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};n.push(t)}return n}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=ht().addressTree,i=ht().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=[]){Ar(t.length,r.length);const n=await Vs(this.compressionApiEndpoint,je("getValidityProof"),{hashes:t.map((({hash:e})=>Ut(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:Ut(e),tree:t.toBase58()})))});let o;if(o=ze.isV2()?Eo(n,Yo(bs)):Eo(n,Yo(ws)),"error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);const s=o.result.value;if(ze.isV2())return{value:{compressedProof:s.compressedProof,leaves:s.accounts.map((e=>e.hash)).concat(s.addresses.map((e=>e.address))),roots:s.accounts.map((e=>e.root)).concat(s.addresses.map((e=>e.root))),rootIndices:s.accounts.map((e=>e.rootIndex.rootIndex)).concat(s.addresses.map((e=>e.rootIndex))),proveByIndices:s.accounts.map((e=>e.rootIndex.proveByIndex)).concat(s.addresses.map((()=>0))),treeInfos:s.accounts.map((e=>e.merkleContext)).concat(s.addresses.map((e=>e.merkleContext))),leafIndices:s.accounts.map((e=>e.leafIndex)).concat(s.addresses.map((()=>0)))},context:o.result.context};{const e=await this.getStateTreeInfos(),t=s.merkleTrees.map((t=>t.equals(ht().addressTree)?{tree:t,queue:ht().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}:Fn(e,t)));return{value:{compressedProof:s.compressedProof,roots:s.roots,rootIndices:s.rootIndices.map((e=>e)),leafIndices:s.leafIndices,leaves:s.leaves,treeInfos:t,proveByIndices:s.rootIndices.map((e=>e.proveByIndex))},context:o.result.context}}}async getCompressibleAccountInfo(e,t,r,n){const o=An(e.toBytes(),r.tree.toBytes(),t.toBytes()),[s,i]=await Promise.allSettled([n.getAccountInfo(e),n.getCompressedAccount(Vt(Array.from(o)))]),a="fulfilled"===s.status?s.value:null,u="fulfilled"===i.status?i.value:null;return a?{accountInfo:a,merkleContext:void 0}:u&&u.data&&u.data.data.length>0?{accountInfo:{executable:0,owner:u.owner,lamports:u.lamports.toNumber(),data:y.concat([y.from(u.data.discriminator),u.data.data])},merkleContext:{treeInfo:r,hash:u.hash,leafIndex:u.leafIndex,proveByIndex:u.proveByIndex}}:null}}class zs 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}=ht();this.lightWasm=t,this.depth=null!=i?i:u,this.log=null!=a?a:0}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return lt()}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 ao(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 ao(this,t);if(!r)throw new Error("Account not found");return Vt(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),Vt(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await uo(e)).filter((e=>t.some((t=>Vt(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(t){const r=await no(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=Vn(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]);n.has(s.tree.toBase58())||n.set(s.tree.toBase58(),{leaves:[],leafIndices:[],treeInfo:s});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:o,treeInfo:i}]of n.entries()){const a=new e.PublicKey(r);let u;if(i.treeType===exports.TreeType.StateV1)u=new ro(this.depth,this.lightWasm,o.map((e=>Vt(e).toString())));else{if(i.treeType!==exports.TreeType.StateV2)throw new Error(`Invalid tree type: ${i.treeType} in test-rpc.ts`);u=new ro(32,this.lightWasm,[])}for(let e=0;e<t.length;e++){const r=o.findIndex((r=>Vt(r).eq(t[e])));if(-1!==r)if(i.treeType===exports.TreeType.StateV1){const n=u.path(r).pathElements.map((e=>Vt(e))),a=Vt(u.root()),c={hash:Vt(t[e].toArray("be",32)),treeInfo:i,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:o.length,root:a};s.set(t[e].toString(),c)}else if(i.treeType===exports.TreeType.StateV2){const r=u._zeros.slice(0,-1).map((e=>Vt(e))),o=Vt(u.root()),c=n.get(a.toBase58()).leafIndices.findIndex((r=>t[e].eq(Vt(n.get(a.toBase58()).leaves[r])))),l={hash:Vt(t[e].toArray("be",32)),treeInfo:i,leafIndex:c,merkleProof:r,proveByIndex:1,rootIndex:0,root:o};s.set(t[e].toString(),l)}}}if(s.forEach(((e,t)=>{if(e.treeInfo.treeType===exports.TreeType.StateV1){const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=Vt(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)}})),new Set(t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`Proof not found for hash: ${e.toString()}`);return t.treeInfo.treeType}))).size>1)throw new Error("Requested hashes belong to different tree types (V1/V2)");return 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 uo(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 po(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await fo(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await mo(this,e);return{amount:Vt(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await po(this,e,t.mint)).items.map((e=>({balance:Vt(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await po(this,e,t.mint)).items.map((e=>({balance:Vt(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=to.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(Vt(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(Vt(r))}const o=new ro(this.depth,this.lightWasm,n.map((e=>Vt(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=>Vt(e))),u=t.get(n.nextIndex).value,c={root:Vt(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:Vt(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:Vt(n.index),treeInfo:{tree:ht().addressTree,queue:ht().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 getValidityProofAndRpcContext(e=[],t=[]){if(t.some((e=>!(e instanceof $e))))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 $e))))throw new Error("AddressWithTree is not supported in test-rpc");let r;const n=[];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){for(const t of e){const e=await this.getCompressedAccount(void 0,t);if(!e)throw new Error("Account not found");n.push(e.treeInfo)}const t=n.some((e=>e.treeType===exports.TreeType.StateV1)),o=await this.getMultipleCompressedAccountProofs(e);if(t){const e=qs(o);r={compressedProof:await Fs(this.proverEndpoint,"inclusion",e,this.log),roots:o.map((e=>e.root)),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>Vt(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else r={compressedProof:null,roots:o.map((()=>Vt(0))),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>Vt(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Ks(e);r={compressedProof:await Fs(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=>Vt(e.value))),treeInfos:e.map((e=>e.treeInfo)),proveByIndices:e.map((()=>0))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=await this.getMultipleNewAddressProofs(t),s=n.map((e=>e.treeInfo)).some((e=>e.treeType===exports.TreeType.StateV1)),i=Ks(o);let a;if(s){const e=qs(n);a=await Fs(this.proverEndpoint,"combined",[e,i],1)}else a=await Fs(this.proverEndpoint,"new-address",i,1);r={compressedProof:a,roots:n.map((e=>s?e.root:Vt(0))).concat(o.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(o.map((()=>3))),leafIndices:n.map((e=>e.leafIndex)).concat(o.map((e=>e.indexHashedIndexedElementLeaf.toNumber()))),leaves:n.map((e=>Vt(e.hash))).concat(o.map((e=>Vt(e.value)))),treeInfos:n.map((e=>e.treeInfo)).concat(o.map((e=>e.treeInfo))),proveByIndices:n.map((e=>e.proveByIndex)).concat(o.map((()=>0)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}async getCompressibleAccountInfo(e,t,r,n){throw new Error("getCompressibleAccountInfo not implemented in test-rpc")}}let js=1;const Ys=Qs(255),Gs=Qs(254),Zs=Qs(253),Js=Qs(252);function Qs(t){if(t||(t=js,js++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var Xs,ei,ti,ri,ni,oi,si,ii;exports.UtxoErrorCode=void 0,(Xs=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",Xs.NOT_U64="NOT_U64",Xs.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(ei=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",ei.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(ti=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",ti.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",ti.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(ri=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",ri.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",ri.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",ri.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(ni=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",ni.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,(oi=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",oi.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",oi.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(si=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",si.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",si.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",si.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",si.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",si.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(ii=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",ii.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",ii.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",ii.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",ii.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",ii.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",ii.INVALID_NUMBER="INVALID_NUMBER";class ai extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}const ui={INITIALIZE_COMPRESSION_CONFIG:[133,228,12,169,56,76,222,61],UPDATE_COMPRESSION_CONFIG:[135,215,243,81,163,146,33,70],DECOMPRESS_ACCOUNTS_IDEMPOTENT:[114,67,61,123,234,31,1,112]},ci=oe.struct([oe.u32("compressionDelay"),oe.publicKey("rentRecipient"),oe.vec(oe.publicKey(),"addressSpace"),oe.option(oe.u8(),"configBump")]),li=oe.struct([oe.option(oe.u32(),"newCompressionDelay"),oe.option(oe.publicKey(),"newRentRecipient"),oe.option(oe.vec(oe.publicKey()),"newAddressSpace"),oe.option(oe.publicKey(),"newUpdateAuthority")]),di=oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")]),hi=oe.struct([oe.u16("rootIndex"),oe.bool("proveByIndex"),oe.u8("merkleTreePubkeyIndex"),oe.u8("queuePubkeyIndex"),oe.u32("leafIndex")]),pi=oe.struct([hi.replicate("treeInfo"),oe.option(oe.array(oe.u8(),32),"address"),oe.option(oe.u64(),"lamports"),oe.u8("outputStateTreeIndex")]),fi=oe.struct([di.replicate("proof"),pi.replicate("compressedAccountMeta")]);function mi(e){return oe.struct([pi.replicate("meta"),e.replicate("data"),oe.vec(oe.vec(oe.u8()),"seeds")])}function yi(e,t,r){const n=Buffer.alloc(2e3),o=e.encode(t,n),s=Buffer.from(new Uint8Array(n.slice(0,o)));return Buffer.concat([Buffer.from(r),s])}function gi(e,t,r,n){const o=Buffer.from([133,228,12,169,56,76,222,61]),s={compressionDelay:e,rentRecipient:t,addressSpace:r,configBump:n},i=Buffer.alloc(1e3),a=ci.encode(s,i),u=Buffer.from(new Uint8Array(i.slice(0,a)));return Buffer.concat([new Uint8Array(o),new Uint8Array(u)])}function wi(t,r=0){const[n,o]=e.PublicKey.findProgramAddressSync([Buffer.from("compressible_config"),Buffer.from([r])],t);return[n,o]}async function vi(t,r){const n=await r.getAccountInfo(t);if(!n)throw new Error("Program account does not exist");const o=new e.PublicKey(n.data.slice(4,36)),s=await r.getAccountInfo(o);if(!s)throw new Error("Program data account does not exist");return{programDataAddress:o,programDataAccountInfo:s}}function xi(t,r){if(3!==t.data.readUInt32LE(0))throw new Error("Invalid program data discriminator");if(1!==t.data[12])throw new Error("Program has no upgrade authority");const n=t.data.slice(13,45),o=new e.PublicKey(n);if(!o.equals(r))throw new Error(`Provided authority ${r.toBase58()} does not match program's upgrade authority ${o.toBase58()}`)}function bi(t,r,n,o,s,i,a,u=null){const c=null!=u?u:0,[l]=wi(t,c),d=new e.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"),[h]=e.PublicKey.findProgramAddressSync([t.toBuffer()],d),p=[{pubkey:n,isSigner:1,isWritable:1},{pubkey:l,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}],f=yi(ci,{compressionDelay:s,rentRecipient:i,addressSpace:a,configBump:c},r);return new e.TransactionInstruction({programId:t,keys:p,data:f})}function Ii(t,r,n,o=null,s=null,i=null,a=null){const[u]=wi(t,0),c=[{pubkey:u,isSigner:0,isWritable:1},{pubkey:n,isSigner:1,isWritable:0}],l=yi(li,{newCompressionDelay:o,newRentRecipient:s,newAddressSpace:i,newUpdateAuthority:a},r);return new e.TransactionInstruction({programId:t,keys:c,data:l})}function Ai(t,r,n,o,s,i,a,u=[]){const[c]=wi(t,0),l=[{pubkey:n,isSigner:1,isWritable:1},{pubkey:o,isSigner:0,isWritable:1},{pubkey:c,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:1},...u],d=yi(fi,{proof:a,compressedAccountMeta:i},r);return new e.TransactionInstruction({programId:t,keys:l,data:d})}function Ei(t,r,n,o,s,i,a,u,c=[],l){if(s.length!==i.length)throw new Error("PDA accounts and compressed accounts must have the same length");if(s.length!==a.length)throw new Error("PDA accounts and bumps must have the same length");const[d]=wi(t,0),h=[{pubkey:n,isSigner:1,isWritable:1},{pubkey:o,isSigner:1,isWritable:1},{pubkey:d,isSigner:0,isWritable:0},...c],p=l({proof:u,compressedAccounts:i,bumps:a,systemAccountsOffset:s.length});return new e.TransactionInstruction({programId:t,keys:h,data:p})}class Ti{static initializeCompressionConfig(e,t,r,n,o,s,i,a=null){return bi(e,t,r,n,o,s,i,a)}static updateCompressionConfig(e,t,r,n=null,o=null,s=null,i=null){return Ii(e,t,r,n,o,s,i)}static compressAccount(e,t,r,n,o,s,i,a=[]){return Ai(e,t,r,n,o,s,i,a)}static decompressAccountsIdempotent(e,t,r,n,o,s,i,a,u=[],c){return Ei(e,0,r,n,o,s,i,a,u,c)}static deriveCompressionConfigAddress(e,t=0){return wi(e,t)}static async getProgramDataAccount(e,t){return await vi(e,t)}static checkProgramUpdateAuthority(e,t){xi(e,t)}static serializeInitializeCompressionConfigData(e,t,r,n){return gi(e,t,r,n)}static createCompressedAccountData(e,t,r,n){return{meta:{treeInfo:{rootIndex:0,proveByIndex:e.proveByIndex,merkleTreePubkeyIndex:0,queuePubkeyIndex:0,leafIndex:e.leafIndex},address:e.address?Array.from(e.address):null,lamports:e.lamports,outputStateTreeIndex:n},data:t,seeds:r}}}Ti.DISCRIMINATORS=ui,exports.ADDRESS_QUEUE_ROLLOVER_FEE=Rt,exports.ADDRESS_TREE_NETWORK_FEE=Nt,exports.ALICE=Ys,exports.AccountProofResult=ks,exports.AppendLeavesInputLayout=lr,exports.AppendNullifyCreateAddressInputsMetaLayout=cr,exports.BOB=Gs,exports.BalanceResult=Es,exports.CHARLIE=Zs,exports.COMPRESSED_TOKEN_PROGRAM_ID=pt,exports.COMPRESSIBLE_DISCRIMINATORS=ui,exports.COMPUTE_BUDGET_PATTERN=Ze,exports.CompressedAccountLayout=Wt,exports.CompressedAccountMetaSchema=pi,exports.CompressedAccountResult=Qo,exports.CompressedAccountResultV2=Xo,exports.CompressedAccountsByOwnerResult=ss,exports.CompressedAccountsByOwnerResultV2=is,exports.CompressedCpiContextLayout=Zt,exports.CompressedMintTokenHoldersResult=_s,exports.CompressedProofLayout=Gt,exports.CompressedTokenAccountResult=ts,exports.CompressedTokenAccountResultV2=rs,exports.CompressedTokenAccountsByOwnerOrDelegateResult=as,exports.CompressedTokenAccountsByOwnerOrDelegateResultV2=us,exports.CompressedTransactionResult=Ls,exports.CompressedTransactionResultV2=Ns,exports.CompressibleInstruction=Ti,exports.CreateUtxoError=class extends ai{},exports.DAVE=Js,exports.DEFAULT_MERKLE_TREE_HEIGHT=kt,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=Ye,exports.GenericCompressAccountInstructionSchema=fi,exports.HIGHEST_ADDRESS_PLUS_ONE=Ge,exports.HashError=class extends ai{},exports.HealthResult=ls,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:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{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=tt,exports.INVOKE_CPI_DISCRIMINATOR=Qe,exports.INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR=et,exports.INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR=Xe,exports.INVOKE_DISCRIMINATOR=Je,exports.InAccountLayout=Xt,exports.IndexedArray=to,exports.IndexedElement=Xn,exports.IndexedElementBundle=eo,exports.InsertAddressInputLayout=hr,exports.InsertNullifierInputLayout=dr,exports.InstructionDataInvokeCpiLayout=Yt,exports.InstructionDataInvokeCpiWithReadOnlyLayout=rr,exports.InstructionDataInvokeLayout=zt,exports.LatestNonVotingSignaturesResult=ds,exports.LatestNonVotingSignaturesResultPaginated=hs,exports.LightSystemProgram=Jn,exports.LookupTableError=class extends ai{},exports.MerkleContextLayout=Ht,exports.MerkleProofResult=ps,exports.MerkleProofResultV2=fs,exports.MerkleTree=ro,exports.MerkleTreeError=class extends ai{},exports.MerkleTreeSequenceNumberLayout=pr,exports.MultipleCompressedAccountsResult=ns,exports.MultipleCompressedAccountsResultV2=os,exports.MultipleMerkleProofsResult=Is,exports.MultipleMerkleProofsResultV2=As,exports.NativeBalanceResult=Ts,exports.NewAddressParamsAssignedPackedLayout=Jt,exports.NewAddressParamsLayout=$t,exports.NewAddressProofResult=ms,exports.PackedAccounts=Wn,exports.PackedAccountsSmall=zn,exports.PackedMerkleContextLayout=Qt,exports.PackedReadOnlyAddressLayout=er,exports.PackedReadOnlyCompressedAccountLayout=tr,exports.PackedStateTreeInfoSchema=hi,exports.ProofError=class extends ai{},exports.PublicTransactionEventLayout=ar,exports.RootIndexResultV2=gs,exports.Rpc=$s,exports.RpcError=class extends ai{},exports.STATE_MERKLE_TREE_NETWORK_FEE=Lt,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=Ot,exports.SelectInUtxosError=class extends ai{},exports.SignatureListResult=Ps,exports.SignatureListWithCursorResult=Os,exports.SlotResult=cs,exports.SystemAccountMetaConfig=Hn,exports.SystemAccountPubkeys=Yn,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=Pt,exports.TestRpc=zs,exports.TokenBalanceListResult=Ss,exports.TokenBalanceListResultV2=Cs,exports.TokenBalanceResult=Ms,exports.TokenDataLayout=co,exports.TokenDataResult=es,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UpdateCompressionConfigSchema=li,exports.UtilsError=class extends ai{},exports.UtxoError=class extends ai{},exports.ValidityProofResult=ws,exports.ValidityProofResultV2=bs,exports.ValidityProofSchema=di,exports.accountCompressionProgram=ot,exports.addressQueue=It,exports.addressTree=bt,exports.addressTreeV2=At,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await Cn(e,n),n},exports.batchCpiContext=_t,exports.batchMerkleTree=St,exports.batchQueue=Ct,exports.bn=Vt,exports.bufToDecStr=e=>Dt(e).toString(),exports.buildAndSignTx=Un,exports.buildTx=Nn,exports.byteArrayToKeypair=function(t){return e.Keypair.fromSecretKey(Uint8Array.from(t))},exports.calculateComputeUnitPrice=function(e,t){return Math.ceil(1e6*e/t)},exports.checkProgramUpdateAuthority=xi,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=qn(await t.getStateTreeInfos()));const u=await Jn.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTreeInfo:s}),c=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await Bn(t,c,i)},exports.compressAccount=async function(t,r,n,o,s,i,a,u,c,l){const d=Ai(n,c,r.publicKey,o,s,i,a,u),{blockhash:h}=await t.getLatestBlockhash(),p=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:3e5}),d],r,h);return await Bn(t,p,l)},exports.compressibleInstruction=Ti,exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=Cn,exports.confirmTx=Dn,exports.convertInvokeCpiWithReadOnlyToInvoke=In,exports.convertMerkleProofsWithContextToHex=qs,exports.convertNonInclusionMerkleProofInputsToHex=Ks,exports.convertToPublicTransactionEvent=mr,exports.cpiContext2Pubkey=Mt,exports.cpiContextPubkey=vt,exports.createAccount=async function(t,r,n,o,s,i,a){const{blockhash:u}=await t.getLatestBlockhash(),{tree:c,queue:l}=null!=s?s:dt(),d=Tn(n,o),h=Mn(d,c);i||(i=qn(await t.getStateTreeInfos()));const p=await t.getValidityProofV0(void 0,[{address:Vt(h.toBytes()),tree:c,queue:l}]),f={seed:d,addressMerkleTreeRootIndex:p.rootIndices[0],addressMerkleTreePubkey:p.treeInfos[0].tree,addressQueuePubkey:p.treeInfos[0].queue},m=await Jn.createAccount({payer:r.publicKey,newAddressParams:f,newAddress:Array.from(h.toBytes()),recentValidityProof:p.compressedProof,programId:o,outputStateTreeInfo:i}),y=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),m],r,u,[]);return await Bn(t,y,a)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u){o=Vt(o);const c=await t.getCompressedAccountsByOwner(r.publicKey),[l]=Qn(c.items,o),{blockhash:d}=await t.getLatestBlockhash(),{tree:h}=null!=i?i:dt(),p=Tn(n,s),f=Mn(p,h),m=await t.getValidityProof(l.map((e=>e.hash)),[Vt(f.toBytes())]),y={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},g=await Jn.createAccount({payer:r.publicKey,newAddressParams:y,newAddress:Array.from(f.toBytes()),recentValidityProof:m.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:m.rootIndices,outputStateTreeInfo:a}),w=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),g],r,d,[]);return await Bn(t,w,u)},exports.createBN254=Dt,exports.createCompressAccountInstruction=Ai,exports.createCompressedAccountData=function(e,t,r,n){return{meta:{treeInfo:{rootIndex:0,proveByIndex:e.proveByIndex,merkleTreePubkeyIndex:0,queuePubkeyIndex:0,leafIndex:e.leafIndex},address:e.address?Array.from(e.address):null,lamports:e.lamports,outputStateTreeIndex:n},data:t,seeds:r}},exports.createCompressedAccountDataSchema=mi,exports.createCompressedAccountLegacy=Ft,exports.createCompressedAccountMeta=(e,t,r,n)=>({treeInfo:e,outputStateTreeIndex:t,address:null!=r?r:null,lamports:null!=n?n:null}),exports.createCompressedAccountWithMerkleContextLegacy=qt,exports.createDecompressAccountsIdempotentInstruction=Ei,exports.createDecompressMultipleAccountsIdempotentDataSchema=function(e){return oe.struct([di.replicate("proof"),oe.vec(mi(e),"compressedAccounts"),oe.vec(oe.u8(),"bumps"),oe.u8("systemAccountsOffset")])},exports.createInitializeCompressionConfigInstruction=bi,exports.createMerkleContextLegacy=Kt,exports.createPackedAccounts=function(e){const t=Hn.new(e);return Wn.newWithSystemAccounts(t)},exports.createPackedAccountsSmall=function(e){const t=Hn.new(e);return zn.newWithSystemAccounts(t)},exports.createPackedAccountsSmallWithCpiContext=function(e,t){const r=Hn.newWithCpiContext(e,t);return zn.newWithSystemAccounts(r)},exports.createPackedAccountsWithCpiContext=function(e,t){const r=Hn.newWithCpiContext(e,t);return Wn.newWithSystemAccounts(r)},exports.createRootIndex=function(e){return{proofByIndex:0,rootIndex:e}},exports.createRootIndexByIndex=function(){return{proofByIndex:1,rootIndex:0}},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 $s(s,r,n,o)},exports.createRpcResult=$o,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=Un([s],r,(await t.getLatestBlockhash()).blockhash,_n(r,[n]));return{address:i,txId:await Bn(t,a)}},exports.createUpdateCompressionConfigInstruction=Ii,exports.decodeInstructionDataInvoke=or,exports.decodeInstructionDataInvokeCpi=sr,exports.decodeInstructionDataInvokeCpiWithReadOnly=nr,exports.decodePublicTransactionEvent=ur,exports.decompress=async function(t,r,n,o,s){const i=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=Vt(n);const a=Gn(i);if(n.gt(a))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${a}`);const u=await t.getValidityProof(i.map((e=>Vt(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),l=await Jn.decompress({payer:r.publicKey,toAddress:o,inputCompressedAccounts:i,recentValidityProof:u.compressedProof,recentInputStateRootIndices:u.rootIndices,lamports:n}),d=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,c,[]);return await Bn(t,d,s)},exports.decompressAccountsIdempotent=async function(t,r,n,o,s,i,a,u,c,l,d,h=ui.DECOMPRESS_ACCOUNTS_IDEMPOTENT,p){const f=Ei(n,0,o.publicKey,s.publicKey,i,a,u,c,l,d),{blockhash:m}=await t.getLatestBlockhash(),y=_n(r,[o,s]),g=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:4e5+5e4*a.length}),f],r,m,y);return await Bn(t,g,p)},exports.dedupeSigner=_n,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof $e&&r instanceof $e)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=ut,exports.defaultStaticAccounts=()=>[new e.PublicKey(st()),new e.PublicKey(rt),new e.PublicKey(ot),new e.PublicKey(it())],exports.defaultStaticAccountsStruct=at,exports.defaultTestStateTreeAccounts=ht,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(Tt),merkleTree2:new e.PublicKey(Et)}),exports.deriveAddress=Mn,exports.deriveAddressSeed=Tn,exports.deriveAddressV2=An,exports.deriveCompressionConfigAddress=wi,exports.deserializeAppendNullifyCreateAddressInputsIndexer=fr,exports.encodeBN254toBase58=Ut,exports.encodeInstructionDataInvoke=jt,exports.encodePublicTransactionEvent=function(e){const t=y.alloc(1e3),r=ar.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=Un([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,_n(i,[a]));return{tableAddress:r,txId:await Bn(t,c)}},exports.featureFlags=ze,exports.getAccountCompressionAuthority=it,exports.getAllStateTreeInfos=Kn,exports.getCompressedTokenAccountByHashTest=mo,exports.getCompressedTokenAccounts=ho,exports.getCompressedTokenAccountsByDelegateTest=fo,exports.getCompressedTokenAccountsByOwnerTest=po,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getDefaultAddressTreeInfo=dt,exports.getIndexOrAdd=yr,exports.getLightSystemAccountMetas=$n,exports.getLightSystemAccountMetasSmall=jn,exports.getParsedEvents=no,exports.getProgramDataAccount=vi,exports.getPublicInputHash=function(e,t,r,n){const o=Ws(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=Ws(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?Ws([o],[i],n):o:i},exports.getRegisteredProgramPda=st,exports.getStateTreeInfoByPubkey=Vn,exports.getTestKeypair=Qs,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 zs(t,e,r,n,void 0,{depth:o||ht().merkleTreeHeight,log:s})},exports.getTreeInfoByPubkey=Fn,exports.hashToBn254FieldSizeBe=xn,exports.hashVWithBumpSeed=En,exports.hashvToBn254FieldSizeBe=bn,exports.initializeCompressionConfig=async function(t,r,n,o,s,i,a,u=null,c=ui.INITIALIZE_COMPRESSION_CONFIG,l){const d=bi(n,c,r.publicKey,o.publicKey,s,i,a,u),{blockhash:h}=await t.getLatestBlockhash(),p=_n(r,[o]),f=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),d],r,h,p);return await Bn(t,f,l)},exports.invokeAccountsLayout=ir,exports.isLocalTest=ct,exports.isSmallerThanBn254FieldSizeBe=wn,exports.jsonRpcResult=jo,exports.jsonRpcResultAndContext=Yo,exports.lightSystemProgram=nt,exports.localTestActiveStateTreeInfos=lt,exports.merkleTree2Pubkey=Et,exports.merkletreePubkey=xt,exports.negateAndCompressProof=Pn,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=Qs(r),o=await e.requestAirdrop(n.publicKey,t);return await Dn(e,o),n},exports.noopProgram=rt,exports.nullifiedStateTreeLookupTableDevnet=gt,exports.nullifiedStateTreeLookupTableMainnet=mt,exports.nullifierQueue2Pubkey=Tt,exports.nullifierQueuePubkey=wt,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=Un([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:n,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash,_n(s,[i]));return{txId:await Bn(t,c)}},exports.packCompressedAccounts=vr,exports.packNewAddressParams=Sn,exports.packTreeInfos=function(e,t){const r="accounts"in e?e:function(e){const t=[],r=[];for(let n=0;n<e.treeInfos.length;n++){const o=e.treeInfos[n];o.treeType===exports.TreeType.StateV1||o.treeType===exports.TreeType.StateV2?t.push({hash:new Uint8Array(e.leaves[n].toArray("le",32)),root:new Uint8Array(e.roots[n].toArray("le",32)),rootIndex:{proofByIndex:e.proveByIndices[n],rootIndex:e.rootIndices[n]},leafIndex:e.leafIndices[n],treeInfo:o}):r.push({address:new Uint8Array(e.leaves[n].toArray("le",32)),root:new Uint8Array(e.roots[n].toArray("le",32)),rootIndex:e.rootIndices[n],treeInfo:o})}return{proof:e.compressedProof,accounts:t,addresses:r}}(e),n=[],o=[];let s=null;for(const e of r.accounts){const r=t.insertOrGet(e.treeInfo.tree),o=t.insertOrGet(e.treeInfo.queue),i={rootIndex:e.rootIndex.rootIndex,merkleTreePubkeyIndex:r,queuePubkeyIndex:o,leafIndex:e.leafIndex,proveByIndex:e.rootIndex.proofByIndex};if(n.push(i),e.treeInfo.nextTreeInfo){const r=xr(e.treeInfo.nextTreeInfo,t);null===s&&(s=r)}else{const r=xr(e.treeInfo,t);null===s&&(s=r)}}for(const e of r.addresses){const r=t.insertOrGet(e.treeInfo.tree),n=t.insertOrGet(e.treeInfo.queue);o.push({addressMerkleTreePubkeyIndex:r,addressQueuePubkeyIndex:n,rootIndex:e.rootIndex})}return{stateTrees:0===n.length?null:{packedTreeInfos:n,outputTreeIndex:s},addressTrees:o}},exports.packTreeInfosWithPubkeys=function(e,t,r){const n=e.slice(),o=[],s=[];let i=-1;if(0===t.length&&0===r.length)return{stateTrees:null,addressTrees:s};if(t.forEach((e=>{const t=yr(n,e.treeInfo.tree),r=yr(n,e.treeInfo.queue);o.push({rootIndex:e.rootIndex,merkleTreePubkeyIndex:t,queuePubkeyIndex:r,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex})})),o.length>0){const e=t[0].treeInfo.nextTreeInfo||t[0].treeInfo;let r=e.tree;if(e.treeType===exports.TreeType.StateV2){if(!ze.isV2())throw new Error("V2 trees are not supported yet");r=e.queue}i=yr(n,r)}return r.forEach((e=>{const t=yr(n,e.treeInfo.tree),r=yr(n,e.treeInfo.queue);s.push({rootIndex:e.rootIndex,addressMerkleTreePubkeyIndex:t,addressQueuePubkeyIndex:r})})),{stateTrees:o.length>0?{packedTreeInfos:o,outputTreeIndex:i}:null,addressTrees:s}},exports.padOutputStateMerkleTrees=gr,exports.parseAccountData=Bs,exports.parseEvents=oo,exports.parseLightTransaction=io,exports.parsePublicTransactionEventWithIdl=so,exports.parseTokenLayoutWithIdl=lo,exports.pickRandomTreeAndQueue=function(e){const t=e.length,r=Math.floor(Math.random()*t);let n;if(void 0!==r){if(r<0||r>=e.length)throw new Error(`Index ${r} out of bounds for infos array of length ${e.length}`);n=r}else n=Math.floor(Math.random()*e.length);return e[n]},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=kn,exports.proverRequest=Fs,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=Vs,exports.selectMinCompressedSolAccountsForTransfer=Qn,exports.selectStateTreeInfo=qn,exports.sendAndConfirmTx=Bn,exports.serializeInitializeCompressionConfigData=gi,exports.serializeInstructionData=yi,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=yt,exports.stateTreeLookupTableMainnet=ft,exports.sumUpLamports=Gn,exports.toAccountMetas=wr,exports.toArray=e=>Array.isArray(e)?e:[e],exports.toCamelCase=vn,exports.toHex=gn,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i){var a;let u=Vt(0);const c=[];let l;for(n=Vt(n);u.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:l,limit:Vt(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(Vt(0))&&(c.push(e),u=u.add(e.lamports));if(l=null!==(a=r.cursor)&&void 0!==a?a:void 0,r.items.length<1e3||u.gte(n))break}if(u.lt(n))throw new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${u.toString()}`);const[d]=Qn(c,n),h=await t.getValidityProof(d.map((e=>Vt(e.hash)))),p=await Jn.transfer({payer:r.publicKey,inputCompressedAccounts:d,toAddress:s,lamports:n,recentInputStateRootIndices:h.rootIndices,recentValidityProof:h.compressedProof}),{blockhash:f}=await t.getLatestBlockhash(),m=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),p],r,f);return await Bn(t,m,i)},exports.updateCompressionConfig=async function(t,r,n,o,s=null,i=null,a=null,u=null,c=ui.UPDATE_COMPRESSION_CONFIG,l){const d=Ii(n,c,o.publicKey,s,i,a,u),{blockhash:h}=await t.getLatestBlockhash(),p=_n(r,[o]),f=Un([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),d],r,h,p);return await Bn(t,f,l)},exports.validateNumbers=Mr,exports.validateNumbersForInclusionProof=Er,exports.validateNumbersForNonInclusionProof=Tr,exports.validateNumbersForProof=Ar,exports.validateSameOwner=Ir,exports.validateSufficientBalance=br,exports.versionedEndpoint=je,exports.wrapBigNumbersAsStrings=Us;
|
|
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,d=0,h=n-o;d<h;d+=l)c.push(a(e,d,d+l>h?h:d+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,d=r?o-1:0,h=r?-1:1,p=e[t+d];for(d+=h,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=256*s+e[t+d],d+=h,l-=8);for(i=s&(1<<-l)-1,s>>=-l,l+=n;l>0;i=256*i+e[t+d],d+=h,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,d=l>>1,h=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+d>=1?h/u:h*Math.pow(2,1-d))*u>=2&&(i++,u/=2),i+d>=l?(a=0,i=l):i+d>=1?(a=(t*u-1)*Math.pow(2,o),i+=d):(a=t*Math.pow(2,d-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 d={}.toString,h=Array.isArray||function(e){return"[object Array]"==d.call(e)};y.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:1;var p=f();function f(){return y.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function m(e,t){if(f()<t)throw new RangeError("Invalid typed array length");return y.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=y.prototype:(null===e&&(e=new y(t)),e.length=t),e}function y(e,t,r){if(!(y.TYPED_ARRAY_SUPPORT||this instanceof y))return new y(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 g(this,e,t,r)}function g(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),y.TYPED_ARRAY_SUPPORT?(e=t).__proto__=y.prototype:e=x(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!y.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|E(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(I(t)){var r=0|b(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):x(e,t);if("Buffer"===t.type&&h(t.data))return x(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|b(t)),!y.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function x(e,t){var r=t.length<0?0:0|b(t.length);e=m(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function b(e){if(e>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|e}function I(e){return!(null==e||!e._isBuffer)}function E(e,t){if(I(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 G(e).length;default:if(n)return Y(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 V(this,t,r);case"utf8":case"utf-8":return B(this,t,r);case"ascii":return D(this,t,r);case"latin1":case"binary":return U(this,t,r);case"base64":return L(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 T(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function M(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=y.from(t,n)),I(t))return 0===t.length?-1:S(e,t,r,n,o);if("number"==typeof t)return t&=255,y.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 d=1,h=0;h<u;h++)if(c(e,s+h)!==c(t,h)){d=0;break}if(d)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(Y(t,e.length-r),e,r,n)}function k(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 P(e,t,r,n){return k(e,t,r,n)}function R(e,t,r,n){return Q(G(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 L(e,t,r){return 0===t&&r===e.length?u(e):u(e.slice(t,r))}function B(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,d=c>239?4:c>223?3:c>191?2:1;if(o+d<=r)switch(d){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,d=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),o+=d}return function(e){var t=e.length;if(t<=N)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=N));return r}(n)}y.poolSize=8192,y._augment=function(e){return e.__proto__=y.prototype,e},y.from=function(e,t,r){return g(null,e,t,r)},y.TYPED_ARRAY_SUPPORT&&(y.prototype.__proto__=Uint8Array.prototype,y.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&y[Symbol.species]),y.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)},y.allocUnsafe=function(e){return v(null,e)},y.allocUnsafeSlow=function(e){return v(null,e)},y.isBuffer=J,y.compare=function(e,t){if(!I(e)||!I(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},y.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}},y.concat=function(e,t){if(!h(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return y.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=y.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!I(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},y.byteLength=E,y.prototype._isBuffer=1,y.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)T(this,t,t+1);return this},y.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)T(this,t,t+3),T(this,t+1,t+2);return this},y.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)T(this,t,t+7),T(this,t+1,t+6),T(this,t+2,t+5),T(this,t+3,t+4);return this},y.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?B(this,0,e):A.apply(this,arguments)},y.prototype.equals=function(e){if(!I(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===y.compare(this,e)},y.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+">"},y.prototype.compare=function(e,t,r,n,o){if(!I(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},y.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},y.prototype.indexOf=function(e,t,r){return M(this,e,t,r,1)},y.prototype.lastIndexOf=function(e,t,r){return M(this,e,t,r,0)},y.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 R(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}},y.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var N=4096;function D(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 U(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 V(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 F(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(!I(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 W(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 $(e,t,r,n,o){return o||j(e,0,r,4),l(e,t,r,n,23,4),r+4}function z(e,t,r,n,o){return o||j(e,0,r,8),l(e,t,r,n,52,8),r+8}y.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),y.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=y.prototype;else{var o=t-e;r=new y(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},y.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||F(e,t,this.length);for(var n=this[e],o=1,s=0;++s<t&&(o*=256);)n+=this[e+s]*o;return n},y.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||F(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},y.prototype.readUInt8=function(e,t){return t||F(e,1,this.length),this[e]},y.prototype.readUInt16LE=function(e,t){return t||F(e,2,this.length),this[e]|this[e+1]<<8},y.prototype.readUInt16BE=function(e,t){return t||F(e,2,this.length),this[e]<<8|this[e+1]},y.prototype.readUInt32LE=function(e,t){return t||F(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},y.prototype.readUInt32BE=function(e,t){return t||F(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},y.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||F(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},y.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||F(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},y.prototype.readInt8=function(e,t){return t||F(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},y.prototype.readInt16LE=function(e,t){t||F(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt16BE=function(e,t){t||F(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt32LE=function(e,t){return t||F(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},y.prototype.readInt32BE=function(e,t){return t||F(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},y.prototype.readFloatLE=function(e,t){return t||F(e,4,this.length),c(this,e,1,23,4)},y.prototype.readFloatBE=function(e,t){return t||F(e,4,this.length),c(this,e,0,23,4)},y.prototype.readDoubleLE=function(e,t){return t||F(e,8,this.length),c(this,e,1,52,8)},y.prototype.readDoubleBE=function(e,t){return t||F(e,8,this.length),c(this,e,0,52,8)},y.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},y.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},y.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,255,0),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},y.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},y.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},y.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):W(this,e,t,1),t+4},y.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):W(this,e,t,0),t+4},y.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},y.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},y.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,127,-128),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},y.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):H(this,e,t,1),t+2},y.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):H(this,e,t,0),t+2},y.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):W(this,e,t,1),t+4},y.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),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):W(this,e,t,0),t+4},y.prototype.writeFloatLE=function(e,t,r){return $(this,e,t,1,r)},y.prototype.writeFloatBE=function(e,t,r){return $(this,e,t,0,r)},y.prototype.writeDoubleLE=function(e,t,r){return z(this,e,t,1,r)},y.prototype.writeDoubleBE=function(e,t,r){return z(this,e,t,0,r)},y.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||!y.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},y.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&&!y.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=I(e)?e:Y(new y(e,n).toString()),a=i.length;for(s=0;s<r-t;++s)this[s+t]=i[s%a]}return this};var Z=/[^+\/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 G(e){return function(e){var t,r,a,u,c,l;s||i();var d=e.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");c="="===e[d-2]?2:"="===e[d-1]?1:0,l=new o(3*d/4-c),a=c>0?d-4:d;var h=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[h++]=u>>16&255,l[h++]=u>>8&255,l[h++]=255&u;return 2===c?(u=n[e.charCodeAt(t)]<<2|n[e.charCodeAt(t+1)]>>4,l[h++]=255&u):1===c&&(u=n[e.charCodeAt(t)]<<10|n[e.charCodeAt(t+1)]<<4|n[e.charCodeAt(t+2)]>>2,l[h++]=u>>8&255,l[h++]=255&u),l}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(Z,"")).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 J(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=Object.freeze({__proto__:null,Buffer:y,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),y.alloc(+e)},isBuffer:J,kMaxLength:p}),te="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ne(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 oe={},se={};class ie{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 ae(e,t){return t.property?e+"["+t.property+"]":e}se.Layout=ie,se.nameWithProperty=ae,se.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 ie))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 ue extends ie{isCount(){throw new Error("ExternalLayout is abstract")}}class ce extends ue{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 le extends ue{constructor(e,t,r){if(!(e instanceof ie))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 de||this.layout instanceof he}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 de extends ie{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 he extends ie{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 pe extends ie{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 fe extends ie{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 me=Math.pow(2,32);function ye(e){const t=Math.floor(e/me);return{hi32:t,lo32:e-t*me}}function ge(e,t){return e*me+t}class we extends ie{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ge(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class ve extends ie{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ge(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class xe extends ie{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ge(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class be extends ie{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ge(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=ye(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Ie extends ie{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 Ee extends ie{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 Ae extends ie{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 Te extends ie{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 Me extends ie{constructor(e,t,r){if(!(e instanceof ie))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof ue&&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 ue)&&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 ue&&(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 ue&&(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 ue&&this.count.encode(e.length,t,r),o}}class Se extends ie{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof ie),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 _e{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class Ce extends _e{constructor(e,t){if(!(e instanceof ue&&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 ke extends ie{constructor(e,t,r){const n=e instanceof de||e instanceof he;if(n)e=new Ce(new le(e));else if(e instanceof ue&&e.isCount())e=new Ce(e);else if(!(e instanceof _e))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof ie))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 Pe(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 Pe extends ie{constructor(e,t,r,n){if(!(e instanceof ke))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 ie))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 Re(e){return 0>e&&(e+=4294967296),e}class Oe extends ie{constructor(e,t,r){if(!(e instanceof de||e instanceof he))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=Re(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 Le(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new Be(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 Le{constructor(e,t,r){if(!(e instanceof Oe))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=Re(this.valueMask<<this.start),this.property=r}decode(){return Re(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==Re(e&this.valueMask))throw new TypeError(ae("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=Re(e<<this.start);this.container._packedSetValue(Re(t&~this.wordMask)|r)}}let Be=class extends Le{constructor(e,t){super(e,1,t)}decode(e,t){return!!Le.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),Le.prototype.encode.call(this,e)}};class Ne extends ie{constructor(e,t){if(!(e instanceof ue&&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 ue||(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 ue&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(ae("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 ue&&this.length.encode(n,t,r),n}}class De extends ie{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 Ue extends ie{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 Ve extends ie{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}se.ExternalLayout=ue,se.GreedyCount=ce,se.OffsetLayout=le,se.UInt=de,se.UIntBE=he,se.Int=pe,se.IntBE=fe,se.Float=Ie,se.FloatBE=Ee,se.Double=Ae,se.DoubleBE=Te,se.Sequence=Me,se.Structure=Se,se.UnionDiscriminator=_e,se.UnionLayoutDiscriminator=Ce,se.Union=ke,se.VariantLayout=Pe,se.BitStructure=Oe,se.BitField=Le,se.Boolean=Be,se.Blob=Ne,se.CString=De,se.UTF8=Ue,se.Constant=Ve,se.greedy=(e,t)=>new ce(e,t),se.offset=(e,t,r)=>new le(e,t,r),se.u8=e=>new de(1,e),se.u16=e=>new de(2,e),se.u24=e=>new de(3,e),se.u32=e=>new de(4,e),se.u40=e=>new de(5,e),se.u48=e=>new de(6,e),se.nu64=e=>new we(e),se.u16be=e=>new he(2,e),se.u24be=e=>new he(3,e),se.u32be=e=>new he(4,e),se.u40be=e=>new he(5,e),se.u48be=e=>new he(6,e),se.nu64be=e=>new ve(e),se.s8=e=>new pe(1,e),se.s16=e=>new pe(2,e),se.s24=e=>new pe(3,e),se.s32=e=>new pe(4,e),se.s40=e=>new pe(5,e),se.s48=e=>new pe(6,e),se.ns64=e=>new xe(e),se.s16be=e=>new fe(2,e),se.s24be=e=>new fe(3,e),se.s32be=e=>new fe(4,e),se.s40be=e=>new fe(5,e),se.s48be=e=>new fe(6,e),se.ns64be=e=>new be(e),se.f32=e=>new Ie(e),se.f32be=e=>new Ee(e),se.f64=e=>new Ae(e),se.f64be=e=>new Te(e),se.struct=(e,t,r)=>new Se(e,t,r),se.bits=(e,t,r)=>new Oe(e,t,r),se.seq=(e,t,r)=>new Me(e,t,r),se.union=(e,t,r)=>new ke(e,t,r),se.unionLayoutDiscriminator=(e,t)=>new Ce(e,t),se.blob=(e,t)=>new Ne(e,t),se.cstr=e=>new De(e),se.utf8=(e,t)=>new Ue(e,t),se.const=(e,t)=>new Ve(e,t);var qe={exports:{}},Fe=ne(ee);!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 qe?qe.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:Fe.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 d=1;for(c=u(e,l,e.length,t),l=0;l<i;l++)d*=t;this.imuln(d),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 d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],h=[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,d=67108863&u,h=Math.min(c,t.length-1),p=Math.max(0,c-e.length+1);p<=h;p++){var f=c-p|0;l+=(i=(o=0|e.words[f])*(s=0|t.words[p])+d)/67108864|0,d=67108863&i}r.words[c]=0|d,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?d[6-u.length]+u+n:u+n}for(0!==s&&(n=s.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var c=h[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:d[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],d=8191&l,h=l>>>13,p=0|i[1],f=8191&p,m=p>>>13,y=0|i[2],g=8191&y,w=y>>>13,v=0|i[3],x=8191&v,b=v>>>13,I=0|i[4],E=8191&I,A=I>>>13,T=0|i[5],M=8191&T,S=T>>>13,_=0|i[6],C=8191&_,k=_>>>13,P=0|i[7],R=8191&P,O=P>>>13,L=0|i[8],B=8191&L,N=L>>>13,D=0|i[9],U=8191&D,V=D>>>13,q=0|a[0],F=8191&q,K=q>>>13,H=0|a[1],W=8191&H,j=H>>>13,$=0|a[2],z=8191&$,Z=$>>>13,Y=0|a[3],G=8191&Y,Q=Y>>>13,J=0|a[4],X=8191&J,ee=J>>>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],de=8191&le,he=le>>>13,pe=0|a[9],fe=8191&pe,me=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ye=(c+(n=Math.imul(d,F))|0)+((8191&(o=(o=Math.imul(d,K))+Math.imul(h,F)|0))<<13)|0;c=((s=Math.imul(h,K))+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(f,F),o=(o=Math.imul(f,K))+Math.imul(m,F)|0,s=Math.imul(m,K);var ge=(c+(n=n+Math.imul(d,W)|0)|0)+((8191&(o=(o=o+Math.imul(d,j)|0)+Math.imul(h,W)|0))<<13)|0;c=((s=s+Math.imul(h,j)|0)+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(g,F),o=(o=Math.imul(g,K))+Math.imul(w,F)|0,s=Math.imul(w,K),n=n+Math.imul(f,W)|0,o=(o=o+Math.imul(f,j)|0)+Math.imul(m,W)|0,s=s+Math.imul(m,j)|0;var we=(c+(n=n+Math.imul(d,z)|0)|0)+((8191&(o=(o=o+Math.imul(d,Z)|0)+Math.imul(h,z)|0))<<13)|0;c=((s=s+Math.imul(h,Z)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(x,F),o=(o=Math.imul(x,K))+Math.imul(b,F)|0,s=Math.imul(b,K),n=n+Math.imul(g,W)|0,o=(o=o+Math.imul(g,j)|0)+Math.imul(w,W)|0,s=s+Math.imul(w,j)|0,n=n+Math.imul(f,z)|0,o=(o=o+Math.imul(f,Z)|0)+Math.imul(m,z)|0,s=s+Math.imul(m,Z)|0;var ve=(c+(n=n+Math.imul(d,G)|0)|0)+((8191&(o=(o=o+Math.imul(d,Q)|0)+Math.imul(h,G)|0))<<13)|0;c=((s=s+Math.imul(h,Q)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(E,F),o=(o=Math.imul(E,K))+Math.imul(A,F)|0,s=Math.imul(A,K),n=n+Math.imul(x,W)|0,o=(o=o+Math.imul(x,j)|0)+Math.imul(b,W)|0,s=s+Math.imul(b,j)|0,n=n+Math.imul(g,z)|0,o=(o=o+Math.imul(g,Z)|0)+Math.imul(w,z)|0,s=s+Math.imul(w,Z)|0,n=n+Math.imul(f,G)|0,o=(o=o+Math.imul(f,Q)|0)+Math.imul(m,G)|0,s=s+Math.imul(m,Q)|0;var xe=(c+(n=n+Math.imul(d,X)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(h,X)|0))<<13)|0;c=((s=s+Math.imul(h,ee)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(M,F),o=(o=Math.imul(M,K))+Math.imul(S,F)|0,s=Math.imul(S,K),n=n+Math.imul(E,W)|0,o=(o=o+Math.imul(E,j)|0)+Math.imul(A,W)|0,s=s+Math.imul(A,j)|0,n=n+Math.imul(x,z)|0,o=(o=o+Math.imul(x,Z)|0)+Math.imul(b,z)|0,s=s+Math.imul(b,Z)|0,n=n+Math.imul(g,G)|0,o=(o=o+Math.imul(g,Q)|0)+Math.imul(w,G)|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 be=(c+(n=n+Math.imul(d,re)|0)|0)+((8191&(o=(o=o+Math.imul(d,ne)|0)+Math.imul(h,re)|0))<<13)|0;c=((s=s+Math.imul(h,ne)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(C,F),o=(o=Math.imul(C,K))+Math.imul(k,F)|0,s=Math.imul(k,K),n=n+Math.imul(M,W)|0,o=(o=o+Math.imul(M,j)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,j)|0,n=n+Math.imul(E,z)|0,o=(o=o+Math.imul(E,Z)|0)+Math.imul(A,z)|0,s=s+Math.imul(A,Z)|0,n=n+Math.imul(x,G)|0,o=(o=o+Math.imul(x,Q)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,Q)|0,n=n+Math.imul(g,X)|0,o=(o=o+Math.imul(g,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 Ie=(c+(n=n+Math.imul(d,se)|0)|0)+((8191&(o=(o=o+Math.imul(d,ie)|0)+Math.imul(h,se)|0))<<13)|0;c=((s=s+Math.imul(h,ie)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(R,F),o=(o=Math.imul(R,K))+Math.imul(O,F)|0,s=Math.imul(O,K),n=n+Math.imul(C,W)|0,o=(o=o+Math.imul(C,j)|0)+Math.imul(k,W)|0,s=s+Math.imul(k,j)|0,n=n+Math.imul(M,z)|0,o=(o=o+Math.imul(M,Z)|0)+Math.imul(S,z)|0,s=s+Math.imul(S,Z)|0,n=n+Math.imul(E,G)|0,o=(o=o+Math.imul(E,Q)|0)+Math.imul(A,G)|0,s=s+Math.imul(A,Q)|0,n=n+Math.imul(x,X)|0,o=(o=o+Math.imul(x,ee)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,ee)|0,n=n+Math.imul(g,re)|0,o=(o=o+Math.imul(g,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 Ee=(c+(n=n+Math.imul(d,ue)|0)|0)+((8191&(o=(o=o+Math.imul(d,ce)|0)+Math.imul(h,ue)|0))<<13)|0;c=((s=s+Math.imul(h,ce)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(B,F),o=(o=Math.imul(B,K))+Math.imul(N,F)|0,s=Math.imul(N,K),n=n+Math.imul(R,W)|0,o=(o=o+Math.imul(R,j)|0)+Math.imul(O,W)|0,s=s+Math.imul(O,j)|0,n=n+Math.imul(C,z)|0,o=(o=o+Math.imul(C,Z)|0)+Math.imul(k,z)|0,s=s+Math.imul(k,Z)|0,n=n+Math.imul(M,G)|0,o=(o=o+Math.imul(M,Q)|0)+Math.imul(S,G)|0,s=s+Math.imul(S,Q)|0,n=n+Math.imul(E,X)|0,o=(o=o+Math.imul(E,ee)|0)+Math.imul(A,X)|0,s=s+Math.imul(A,ee)|0,n=n+Math.imul(x,re)|0,o=(o=o+Math.imul(x,ne)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,ne)|0,n=n+Math.imul(g,se)|0,o=(o=o+Math.imul(g,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(d,de)|0)|0)+((8191&(o=(o=o+Math.imul(d,he)|0)+Math.imul(h,de)|0))<<13)|0;c=((s=s+Math.imul(h,he)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(U,F),o=(o=Math.imul(U,K))+Math.imul(V,F)|0,s=Math.imul(V,K),n=n+Math.imul(B,W)|0,o=(o=o+Math.imul(B,j)|0)+Math.imul(N,W)|0,s=s+Math.imul(N,j)|0,n=n+Math.imul(R,z)|0,o=(o=o+Math.imul(R,Z)|0)+Math.imul(O,z)|0,s=s+Math.imul(O,Z)|0,n=n+Math.imul(C,G)|0,o=(o=o+Math.imul(C,Q)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,Q)|0,n=n+Math.imul(M,X)|0,o=(o=o+Math.imul(M,ee)|0)+Math.imul(S,X)|0,s=s+Math.imul(S,ee)|0,n=n+Math.imul(E,re)|0,o=(o=o+Math.imul(E,ne)|0)+Math.imul(A,re)|0,s=s+Math.imul(A,ne)|0,n=n+Math.imul(x,se)|0,o=(o=o+Math.imul(x,ie)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ie)|0,n=n+Math.imul(g,ue)|0,o=(o=o+Math.imul(g,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(f,de)|0,o=(o=o+Math.imul(f,he)|0)+Math.imul(m,de)|0,s=s+Math.imul(m,he)|0;var Te=(c+(n=n+Math.imul(d,fe)|0)|0)+((8191&(o=(o=o+Math.imul(d,me)|0)+Math.imul(h,fe)|0))<<13)|0;c=((s=s+Math.imul(h,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(U,W),o=(o=Math.imul(U,j))+Math.imul(V,W)|0,s=Math.imul(V,j),n=n+Math.imul(B,z)|0,o=(o=o+Math.imul(B,Z)|0)+Math.imul(N,z)|0,s=s+Math.imul(N,Z)|0,n=n+Math.imul(R,G)|0,o=(o=o+Math.imul(R,Q)|0)+Math.imul(O,G)|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(k,X)|0,s=s+Math.imul(k,ee)|0,n=n+Math.imul(M,re)|0,o=(o=o+Math.imul(M,ne)|0)+Math.imul(S,re)|0,s=s+Math.imul(S,ne)|0,n=n+Math.imul(E,se)|0,o=(o=o+Math.imul(E,ie)|0)+Math.imul(A,se)|0,s=s+Math.imul(A,ie)|0,n=n+Math.imul(x,ue)|0,o=(o=o+Math.imul(x,ce)|0)+Math.imul(b,ue)|0,s=s+Math.imul(b,ce)|0,n=n+Math.imul(g,de)|0,o=(o=o+Math.imul(g,he)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,he)|0;var Me=(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)+(Me>>>26)|0,Me&=67108863,n=Math.imul(U,z),o=(o=Math.imul(U,Z))+Math.imul(V,z)|0,s=Math.imul(V,Z),n=n+Math.imul(B,G)|0,o=(o=o+Math.imul(B,Q)|0)+Math.imul(N,G)|0,s=s+Math.imul(N,Q)|0,n=n+Math.imul(R,X)|0,o=(o=o+Math.imul(R,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(k,re)|0,s=s+Math.imul(k,ne)|0,n=n+Math.imul(M,se)|0,o=(o=o+Math.imul(M,ie)|0)+Math.imul(S,se)|0,s=s+Math.imul(S,ie)|0,n=n+Math.imul(E,ue)|0,o=(o=o+Math.imul(E,ce)|0)+Math.imul(A,ue)|0,s=s+Math.imul(A,ce)|0,n=n+Math.imul(x,de)|0,o=(o=o+Math.imul(x,he)|0)+Math.imul(b,de)|0,s=s+Math.imul(b,he)|0;var Se=(c+(n=n+Math.imul(g,fe)|0)|0)+((8191&(o=(o=o+Math.imul(g,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(U,G),o=(o=Math.imul(U,Q))+Math.imul(V,G)|0,s=Math.imul(V,Q),n=n+Math.imul(B,X)|0,o=(o=o+Math.imul(B,ee)|0)+Math.imul(N,X)|0,s=s+Math.imul(N,ee)|0,n=n+Math.imul(R,re)|0,o=(o=o+Math.imul(R,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(k,se)|0,s=s+Math.imul(k,ie)|0,n=n+Math.imul(M,ue)|0,o=(o=o+Math.imul(M,ce)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,ce)|0,n=n+Math.imul(E,de)|0,o=(o=o+Math.imul(E,he)|0)+Math.imul(A,de)|0,s=s+Math.imul(A,he)|0;var _e=(c+(n=n+Math.imul(x,fe)|0)|0)+((8191&(o=(o=o+Math.imul(x,me)|0)+Math.imul(b,fe)|0))<<13)|0;c=((s=s+Math.imul(b,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(U,X),o=(o=Math.imul(U,ee))+Math.imul(V,X)|0,s=Math.imul(V,ee),n=n+Math.imul(B,re)|0,o=(o=o+Math.imul(B,ne)|0)+Math.imul(N,re)|0,s=s+Math.imul(N,ne)|0,n=n+Math.imul(R,se)|0,o=(o=o+Math.imul(R,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(k,ue)|0,s=s+Math.imul(k,ce)|0,n=n+Math.imul(M,de)|0,o=(o=o+Math.imul(M,he)|0)+Math.imul(S,de)|0,s=s+Math.imul(S,he)|0;var Ce=(c+(n=n+Math.imul(E,fe)|0)|0)+((8191&(o=(o=o+Math.imul(E,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(U,re),o=(o=Math.imul(U,ne))+Math.imul(V,re)|0,s=Math.imul(V,ne),n=n+Math.imul(B,se)|0,o=(o=o+Math.imul(B,ie)|0)+Math.imul(N,se)|0,s=s+Math.imul(N,ie)|0,n=n+Math.imul(R,ue)|0,o=(o=o+Math.imul(R,ce)|0)+Math.imul(O,ue)|0,s=s+Math.imul(O,ce)|0,n=n+Math.imul(C,de)|0,o=(o=o+Math.imul(C,he)|0)+Math.imul(k,de)|0,s=s+Math.imul(k,he)|0;var ke=(c+(n=n+Math.imul(M,fe)|0)|0)+((8191&(o=(o=o+Math.imul(M,me)|0)+Math.imul(S,fe)|0))<<13)|0;c=((s=s+Math.imul(S,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(U,se),o=(o=Math.imul(U,ie))+Math.imul(V,se)|0,s=Math.imul(V,ie),n=n+Math.imul(B,ue)|0,o=(o=o+Math.imul(B,ce)|0)+Math.imul(N,ue)|0,s=s+Math.imul(N,ce)|0,n=n+Math.imul(R,de)|0,o=(o=o+Math.imul(R,he)|0)+Math.imul(O,de)|0,s=s+Math.imul(O,he)|0;var Pe=(c+(n=n+Math.imul(C,fe)|0)|0)+((8191&(o=(o=o+Math.imul(C,me)|0)+Math.imul(k,fe)|0))<<13)|0;c=((s=s+Math.imul(k,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(U,ue),o=(o=Math.imul(U,ce))+Math.imul(V,ue)|0,s=Math.imul(V,ce),n=n+Math.imul(B,de)|0,o=(o=o+Math.imul(B,he)|0)+Math.imul(N,de)|0,s=s+Math.imul(N,he)|0;var Re=(c+(n=n+Math.imul(R,fe)|0)|0)+((8191&(o=(o=o+Math.imul(R,me)|0)+Math.imul(O,fe)|0))<<13)|0;c=((s=s+Math.imul(O,me)|0)+(o>>>13)|0)+(Re>>>26)|0,Re&=67108863,n=Math.imul(U,de),o=(o=Math.imul(U,he))+Math.imul(V,de)|0,s=Math.imul(V,he);var Oe=(c+(n=n+Math.imul(B,fe)|0)|0)+((8191&(o=(o=o+Math.imul(B,me)|0)+Math.imul(N,fe)|0))<<13)|0;c=((s=s+Math.imul(N,me)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863;var Le=(c+(n=Math.imul(U,fe))|0)+((8191&(o=(o=Math.imul(U,me))+Math.imul(V,fe)|0))<<13)|0;return c=((s=Math.imul(V,me))+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,u[0]=ye,u[1]=ge,u[2]=we,u[3]=ve,u[4]=xe,u[5]=be,u[6]=Ie,u[7]=Ee,u[8]=Ae,u[9]=Te,u[10]=Me,u[11]=Se,u[12]=_e,u[13]=Ce,u[14]=ke,u[15]=Pe,u[16]=Re,u[17]=Oe,u[18]=Le,0!==c&&(u[19]=c,r.length++),r};function y(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,d=(0|e.words[l])*(0|t.words[c]),h=67108863&d;a=67108863&(h=h+a|0),o+=(i=(i=i+(d/67108864|0)|0)+(h>>>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 g(e,t,r){return y(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?y(this,e,t):g(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),g(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 d=0|this.words[c];this.words[c]=l<<26-s|d>>>s,l=d&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 d=u-1;d>=0;d--){var h=67108864*(0|n.words[s.length+d])+(0|n.words[s.length+d-1]);for(h=Math.min(h/i|0,67108863),n._ishlnsubmul(s,h,d);0!==n.negative;)h--,n.negative=0,n._ishlnsubmul(s,1,d),n.isZero()||(n.negative^=1);a&&(a.words[d]=h)}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(),d=t.clone();!t.isZero();){for(var h=0,p=1;0==(t.words[0]&p)&&h<26;++h,p<<=1);if(h>0)for(t.iushrn(h);h-- >0;)(s.isOdd()||i.isOdd())&&(s.iadd(l),i.isub(d)),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(d)),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 d=0,h=1;0==(n.words[0]&h)&&d<26;++d,h<<=1);if(d>0)for(n.iushrn(d);d-- >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 x(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function I(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){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 T(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(x,v),x.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},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(b,v),n(I,v),n(E,v),E.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 x;else if("p224"===e)t=new b;else if("p192"===e)t=new I;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new E}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 d=this.pow(l,s),h=this.pow(e,s.addn(1).iushrn(1)),p=this.pow(e,s),f=i;0!==p.cmp(a);){for(var m=p,y=0;0!==m.cmp(a);y++)m=m.redSqr();r(y<f);var g=this.pow(d,new o(1).iushln(f-y-1));h=h.redMul(g),d=g.redSqr(),p=p.redMul(d),f=y}return h},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 d=c>>l&1;s!==r[0]&&(s=this.sqr(s)),0!==d||0!==i?(i<<=1,i|=d,(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 T(e)},n(T,A),T.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},T.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},T.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},T.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,te);var Ke,He,We=qe.exports,je=re(We);!function(t){var r=te&&te.__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=se,o=e,s=r(We);var i=se;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 d(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function h(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)(),d,h,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)}}(oe),exports.TreeType=void 0,(Ke=exports.TreeType||(exports.TreeType={}))[Ke.StateV1=1]="StateV1",Ke[Ke.AddressV1=2]="AddressV1",Ke[Ke.StateV2=3]="StateV2",Ke[Ke.AddressV2=4]="AddressV2",exports.VERSION=void 0,(He=exports.VERSION||(exports.VERSION={})).V1="V1",He.V2="V2";const $e={version:'"V2"',isV2:()=>"V2"===$e.version.replace(/['"]/g,"").toUpperCase()},ze=e=>$e.isV2()?`${e}V2`:e,Ze=new je("21888242871839275222246405745257275088548364400416034343698204186575808495617"),Ye=new je("452312848583266388373324160190187140051835877600158453279131187530910662655"),Ge=[2,64,66,15,0],Qe=y.from([26,16,169,7,21,202,242,25]),Je=y.from([49,212,191,129,39,194,43,196]),Xe=y.from([86,47,163,166,21,223,92,8]),et=y.from([228,34,128,84,47,139,86,240]),tt=y.from([180,143,159,153,35,46,248,163]),rt="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",nt="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",ot="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",st=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),it=()=>e.PublicKey.findProgramAddressSync([y.from("cpi_authority")],new e.PublicKey(nt))[0],at=()=>({registeredProgramPda:new e.PublicKey(st()),noopProgram:new e.PublicKey(rt),accountCompressionProgram:new e.PublicKey(ot),accountCompressionAuthority:new e.PublicKey(it()),cpiSignatureAccount:null}),ut=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(gt),nullifyLookupTable:new e.PublicKey(wt)}],devnet:[{stateTreeLookupTable:new e.PublicKey(vt),nullifyLookupTable:new e.PublicKey(xt)}]}),ct=e=>e.includes("localhost")||e.includes("127.0.0.1"),lt=()=>[{tree:new e.PublicKey(Et),queue:new e.PublicKey(bt),cpiContext:new e.PublicKey(It),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Mt),queue:new e.PublicKey(St),cpiContext:new e.PublicKey(_t),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Ct),queue:new e.PublicKey(kt),cpiContext:new e.PublicKey(Pt),treeType:exports.TreeType.StateV2,nextTreeInfo:null},{tree:new e.PublicKey(Rt),queue:new e.PublicKey(Ot),cpiContext:new e.PublicKey(Lt),treeType:exports.TreeType.StateV2,nextTreeInfo:null},{tree:new e.PublicKey(Bt),queue:new e.PublicKey(Nt),cpiContext:new e.PublicKey(Dt),treeType:exports.TreeType.StateV2,nextTreeInfo:null},{tree:new e.PublicKey(Ut),queue:new e.PublicKey(Vt),cpiContext:new e.PublicKey(qt),treeType:exports.TreeType.StateV2,nextTreeInfo:null},{tree:new e.PublicKey(Ft),queue:new e.PublicKey(Kt),cpiContext:new e.PublicKey(Ht),treeType:exports.TreeType.StateV2,nextTreeInfo:null},{tree:new e.PublicKey(Wt),queue:new e.PublicKey(Wt),cpiContext:e.PublicKey.default,treeType:exports.TreeType.AddressV2,nextTreeInfo:null},{tree:new e.PublicKey(jt),queue:new e.PublicKey(jt),cpiContext:e.PublicKey.default,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}].filter((e=>$e.isV2()?1:e.treeType===exports.TreeType.StateV1)),dt=()=>pt(),ht=()=>$e.isV2()?pt():{tree:new e.PublicKey(At),queue:new e.PublicKey(Tt),cpiContext:void 0,treeType:exports.TreeType.AddressV1,nextTreeInfo:null},pt=()=>({tree:new e.PublicKey(Wt),queue:new e.PublicKey(Wt),cpiContext:void 0,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}),ft=()=>({nullifierQueue:new e.PublicKey(bt),merkleTree:new e.PublicKey(Et),merkleTreeHeight:Zt,addressTree:new e.PublicKey(At),addressQueue:new e.PublicKey(Tt)}),mt=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),yt=mt,gt="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",wt="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",vt="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",xt="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",bt="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",It="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",Et="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",At="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",Tt="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",Mt="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",St="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",_t="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",Ct="bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU",kt="oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto",Pt="cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y",Rt="bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi",Ot="oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg",Lt="cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B",Bt="bmt3ccLd4bqSVZVeCJnH1F6C8jNygAhaDfxDwePyyGb",Nt="oq3AxjekBWgo64gpauB6QtuZNesuv19xrhaC1ZM1THQ",Dt="cpi3mbwMpSX8FAGMZVP85AwxqCaQMfEk9Em1v8QK9Rf",Ut="bmt4d3p1a4YQgk9PeZv5s4DBUmbF5NxqYpk9HGjQsd8",Vt="oq4ypwvVGzCUMoiKKHWh4S1SgZJ9vCvKpcz6RT6A8dq",qt="cpi4yyPDc4bCgHAnsenunGA8Y77j3XEDyjgfyCKgcoc",Ft="bmt5yU97jC88YXTuSukYHa8Z5Bi2ZDUtmzfkDTA2mG2",Kt="oq5oh5ZR3yGomuQgFduNDzjtGvVWfDRGLuDVjv9a96P",Ht="cpi5ZTjdgYpZ1Xr7B1cMLLUE81oTtJbNNAyKary2nV6",Wt="amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx",jt="EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK",$t=Ct,zt=kt,Zt=26,Yt=new je(Math.floor(2**Zt*.95)),Gt=$e.isV2()?new je(1):new je(300),Qt=($e.isV2(),new je(392)),Jt=new je(5e3),Xt=new je(5e3),er=new je(1e4);var tr=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 d=s;for(;c!==a;)l[d++]=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 d=r.repeat(n);for(;l<u;++l)d+=e.charAt(c[l]);return d},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const rr=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return rr(tr.decode(e))}return function(e){if(e.gte(Ze))throw new Error("Value is too large. Max <254 bits");return e}(new je(e,t))};function nr(e){const t=rr(e).toArrayLike(y,void 0,32);return tr.encode(new Uint8Array(t))}const or=(e,t,r)=>e instanceof Uint8Array&&!(e instanceof y)?new je(y.from(e),t,r):new je(e,t,r),sr=(e,t,r,n)=>({owner:e,lamports:null!=t?t:new je(0),address:null!=n?n:null,data:null!=r?r:null}),ir=(e,t,r,n,o)=>Object.assign(Object.assign({},e),{owner:t,lamports:null!=r?r:new je(0),address:null!=o?o:null,data:null!=n?n:null,readOnly:0}),ar=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n}),ur=oe.struct([oe.publicKey("owner"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address"),oe.option(oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.vecU8("data"),oe.array(oe.u8(),32,"dataHash")]),"data")],"compressedAccount"),cr=oe.struct([oe.u8("merkleTreePubkeyIndex"),oe.u8("queuePubkeyIndex"),oe.u32("leafIndex"),oe.bool("proveByIndex")],"merkleContext"),lr=oe.struct([oe.array(oe.u8(),32,"seed"),oe.u8("addressQueueAccountIndex"),oe.u8("addressMerkleTreeAccountIndex"),oe.u16("addressMerkleTreeRootIndex")],"newAddressParams"),dr=oe.struct([oe.option(oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")]),"proof"),oe.vec(oe.struct([ur,cr,oe.u16("rootIndex"),oe.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),oe.vec(oe.struct([ur,oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.option(oe.u64(),"relayFee"),oe.vec(lr,"newAddressParams"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.bool("isCompress")]);function hr(e){const t=y.alloc(1e3),r=dr.encode(e,t),n=y.from(new Uint8Array(t.slice(0,r))),o=y.alloc(4);return o.writeUInt32LE(r,0),y.concat([new Uint8Array(Qe),new Uint8Array(o),new Uint8Array(n)])}const pr=oe.struct([oe.option(oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")]),"proof"),oe.vec(lr,"newAddressParams"),oe.vec(oe.struct([ur,cr,oe.u16("rootIndex"),oe.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),oe.vec(oe.struct([ur,oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.option(oe.u64(),"relayFee"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.bool("isCompress"),oe.option(oe.struct([oe.bool("set_context"),oe.bool("first_set_context"),oe.u8("cpi_context_account_index")]),"compressedCpiContext")]),fr=oe.struct([oe.array(oe.u8(),32,"a"),oe.array(oe.u8(),64,"b"),oe.array(oe.u8(),32,"c")],"compressedProof"),mr=oe.struct([oe.bool("set_context"),oe.bool("first_set_context"),oe.u8("cpi_context_account_index")],"compressedCpiContext"),yr=oe.struct([oe.array(oe.u8(),32,"seed"),oe.u8("address_queue_account_index"),oe.u8("address_merkle_tree_account_index"),oe.u16("address_merkle_tree_root_index"),oe.bool("assigned_to_account"),oe.u8("assigned_account_index")],"newAddressParamsAssignedPacked"),gr=oe.struct([oe.u8("merkle_tree_pubkey_index"),oe.u8("queue_pubkey_index"),oe.u32("leaf_index"),oe.bool("prove_by_index")],"packedMerkleContext"),wr=oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.array(oe.u8(),32,"data_hash"),gr,oe.u16("root_index"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address")],"inAccount"),vr=oe.struct([oe.array(oe.u8(),32,"address"),oe.u16("address_merkle_tree_root_index"),oe.u8("address_merkle_tree_account_index")],"packedReadOnlyAddress"),xr=oe.struct([oe.array(oe.u8(),32,"account_hash"),gr,oe.u16("root_index")],"packedReadOnlyCompressedAccount"),br=oe.struct([oe.u8("mode"),oe.u8("bump"),oe.publicKey("invoking_program_id"),oe.u64("compress_or_decompress_lamports"),oe.bool("is_compress"),oe.bool("with_cpi_context"),oe.bool("with_transaction_hash"),mr,oe.option(fr,"proof"),oe.vec(yr,"new_address_params"),oe.vec(wr,"input_compressed_accounts"),oe.vec(oe.struct([ur,oe.u8("merkleTreeIndex")]),"output_compressed_accounts"),oe.vec(vr,"read_only_addresses"),oe.vec(xr,"read_only_accounts")]);function Ir(e){return br.decode(e.slice(Xe.length))}function Er(e){return dr.decode(e.slice(Qe.length+4))}function Ar(e){return pr.decode(e.slice(Je.length+4))}const Tr=e=>{const t=fo.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}]},Mr=oe.struct([oe.vec(oe.array(oe.u8(),32),"inputCompressedAccountHashes"),oe.vec(oe.array(oe.u8(),32),"outputCompressedAccountHashes"),oe.vec(oe.struct([oe.struct([oe.publicKey("owner"),oe.u64("lamports"),oe.option(oe.array(oe.u8(),32),"address"),oe.option(oe.struct([oe.array(oe.u8(),8,"discriminator"),oe.vecU8("data"),oe.array(oe.u8(),32,"dataHash")]),"data")],"compressedAccount"),oe.u8("merkleTreeIndex")]),"outputCompressedAccounts"),oe.vec(oe.u32(),"outputLeafIndices"),oe.vec(oe.struct([oe.publicKey("tree_pubkey"),oe.publicKey("queue_pubkey"),oe.u64("tree_type"),oe.u64("seq")]),"sequenceNumbers"),oe.option(oe.u64(),"relayFee"),oe.bool("isCompress"),oe.option(oe.u64(),"compressOrDecompressLamports"),oe.vec(oe.publicKey(),"pubkeyArray"),oe.option(oe.vecU8(),"message")]);function Sr(e){return Mr.decode(e)}const _r=oe.struct([oe.u8("is_invoked_by_program"),oe.u8("bump"),oe.u8("num_queues"),oe.u8("num_output_queues"),oe.u8("start_output_appends"),oe.u8("num_address_queues"),oe.array(oe.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),Cr=oe.struct([oe.u8("index"),oe.array(oe.u8(),32,"leaf")],"appendLeavesInput"),kr=oe.struct([oe.array(oe.u8(),32,"account_hash"),oe.u32("leaf_index"),oe.u8("prove_by_index"),oe.u8("tree_index"),oe.u8("queue_index")],"insertNullifierInput"),Pr=oe.struct([oe.array(oe.u8(),32,"address"),oe.u8("tree_index"),oe.u8("queue_index")],"insertAddressInput"),Rr=oe.struct([oe.publicKey("tree_pubkey"),oe.publicKey("queue_pubkey"),oe.u64("tree_type"),oe.u64("seq")],"merkleTreeSequenceNumber");function Or(e){let t=0;const r=_r.decode(e,t);t+=_r.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=Cr.decode(e,t);o.push(r),t+=Cr.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=kr.decode(e,t);i.push(r),t+=kr.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=Pr.decode(e,t);u.push(r),t+=Pr.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=Rr.decode(e,t);l.push(r),t+=Rr.span}const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)Rr.decode(e,t),t+=Rr.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)Rr.decode(e,t),t+=Rr.span;const p=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<p;r++){const r=oe.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 Lr(t,r,n){const o=e=>Array.from(e instanceof y?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:or((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(y.from(null===(u=n.outputCompressedAccounts[r].compressedAccount.data)||void 0===u?void 0:u.discriminator)),data:null!==(c=o(y.from(new Uint8Array(n.outputCompressedAccounts[r].compressedAccount.data.data))))&&void 0!==c?c:[],dataHash:o(y.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((e=>({tree_pubkey:e.tree_pubkey,queue_pubkey:e.queue_pubkey,tree_type:e.tree_type,seq:e.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)?or(n.relayFee):null,compressOrDecompressLamports:(null==n?void 0:n.compressOrDecompressLamports)?or(n.compressOrDecompressLamports):null,message:null}}function Br(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function Nr(e,t){return t<=0?[]:new Array(t).fill(e)}function Dr(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function Ur(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=Br(s,e.treeInfo.tree),o=Br(s,e.treeInfo.queue);i.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleContext:{merkleTreePubkeyIndex:n,queuePubkeyIndex:o,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex},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;let l=c.tree;if(c.treeType===exports.TreeType.StateV2){if(!$e.isV2())throw new Error("V2 trees are not supported yet");l=c.queue}const d=Nr(l,r.length);return r.forEach(((e,t)=>{const r=Br(s,d[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 Vr=e=>{if(e.lt(or(0)))throw new Error("Insufficient balance for transfer")},qr=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")},Fr=(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(", ")}`);Wr(e,[1,2,3,4],"compressed accounts"),Hr(t)}else e>0?Kr(e):Hr(t)},Kr=e=>{Wr(e,[1,2,3,4,8],"compressed accounts")},Hr=e=>{Wr(e,[1,2],"new addresses")},Wr=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function jr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function $r(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 zr(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 Zr=BigInt(2**32-1),Yr=BigInt(32);function Gr(e,t=0){return t?{h:Number(e&Zr),l:Number(e>>Yr&Zr)}:{h:0|Number(e>>Yr&Zr),l:0|Number(e&Zr)}}function Qr(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}=Gr(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const Jr=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function Xr(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 en(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)),$r(e),e}class tn{clone(){return this._cloneInto()}}const rn=[],nn=[],on=[],sn=BigInt(0),an=BigInt(1),un=BigInt(2),cn=BigInt(7),ln=BigInt(256),dn=BigInt(113);for(let e=0,t=an,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],rn.push(2*(5*n+r)),nn.push((e+1)*(e+2)/2%64);let o=sn;for(let e=0;e<7;e++)t=(t<<an^(t>>cn)*dn)%ln,t&un&&(o^=an<<(an<<BigInt(e))-an);on.push(o)}const[hn,pn]=Qr(on,1),fn=(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),mn=(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 yn extends tn{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,jr(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(){Jr||Xr(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=fn(s,i,1)^r[n],u=mn(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=nn[r],s=fn(t,o,n),i=mn(t,o,n),a=rn[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]^=hn[n],e[1]^=pn[n]}r.fill(0)}(this.state32,this.rounds),Jr||Xr(this.state32),this.posOut=0,this.pos=0}update(e){zr(this);const{blockLen:t,state:r}=this,n=(e=en(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){zr(this,0),$r(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 jr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){$r(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 yn(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 gn=(()=>function(e){const t=t=>e().update(en(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new yn(136,1,32))))(),wn=e=>"object"==typeof e&&null!==e,vn=e=>wn(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),xn=Symbol("mapObjectSkip"),bn=(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=>vn(e)?bn(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===xn)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&vn(l)&&(l=Array.isArray(l)?s(l):bn(l,t,r,n)),o[c]=l)}return o};function In(e,t,r){if(!wn(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return bn(e,t,r)}const En=/[\p{Lu}]/u,An=/[\p{Ll}]/u,Tn=/^[\p{Lu}](?![\p{Lu}])/gu,Mn=/([\p{Alpha}\p{N}_]|$)/u,Sn=/[_.\- ]+/,_n=new RegExp("^"+Sn.source),Cn=new RegExp(Sn.source+Mn.source,"gu"),kn=new RegExp("\\d+"+Mn.source,"gu");class Pn 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 Rn=new Pn({maxSize:1e5}),On=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),Ln=(e,t={})=>{if(!On(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&&On(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=In(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(Rn.has(e))t=Rn.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?Sn.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&&En.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&An.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(_n,""),e=t.preserveConsecutiveUppercase?((e,t)=>(Tn.lastIndex=0,e.replaceAll(Tn,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>(Cn.lastIndex=0,kn.lastIndex=0,e.replaceAll(kn,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll(Cn,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&Rn.set(e,r),t=r}}return[t,o]};return In(e,u(void 0))};function Bn(e){return"0x"+e.toString("hex")}function Nn(e){return or(e,void 0,"be").lt(Ze)}const Dn=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>Ln(t[e],r))):Ln(t,r);var t,r};function Un(e){let t=255;for(;t>=0;){const r=y.concat([e,y.from([t])]),n=gn(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,Nn(y.from(n)))return[y.from(n),t];t-=1}return null}function Vn(e){const t=gn.create();for(const r of e)t.update(r);t.update(Uint8Array.from([255]));const r=t.digest();return r[0]=0,r}function qn(e){const t=gn.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function Fn(t){const r=t.proof?{a:t.proof.a,b:t.proof.b,c:t.proof.c}:null,n=t.new_address_params.map((e=>({seed:e.seed,addressMerkleTreeRootIndex:e.address_merkle_tree_root_index,addressMerkleTreeAccountIndex:e.address_merkle_tree_account_index,addressQueueAccountIndex:e.address_queue_account_index})));return{proof:r,inputCompressedAccountsWithMerkleContext:t.input_compressed_accounts.map((t=>({compressedAccount:{owner:new e.PublicKey(y.alloc(32)),lamports:or(t.lamports),address:t.address,data:null},merkleContext:{merkleTreePubkeyIndex:t.packedMerkleContext.merkle_tree_pubkey_index,queuePubkeyIndex:t.packedMerkleContext.queue_pubkey_index,leafIndex:t.packedMerkleContext.leaf_index,proveByIndex:t.packedMerkleContext.prove_by_index},rootIndex:t.root_index,readOnly:0}))),outputCompressedAccounts:t.output_compressed_accounts.map((e=>({compressedAccount:{owner:e.compressedAccount.owner,lamports:e.compressedAccount.lamports,address:e.compressedAccount.address,data:e.compressedAccount.data},merkleTreeIndex:e.merkleTreeIndex}))),relayFee:null,newAddressParams:n,compressOrDecompressLamports:t.compress_or_decompress_lamports,isCompress:t.is_compress}}function Kn(e,t){return qn([t.toBytes(),...e])}function Hn(t,r=ft().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=Un(Buffer.from([...n,...t]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new e.PublicKey(s)}function Wn(t,r,n){if(32!=t.length)throw new Error("Address seed length is not 32 bytes.");const o=r.toBytes(),s=n.toBytes(),i=Vn([Uint8Array.from(t),Uint8Array.from(o),Uint8Array.from(s)]);return new e.PublicKey(i)}function jn(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=Br(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=Br(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function $n(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 zn(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}class Zn{constructor(){this.preAccounts=[],this.systemAccounts=[],this.nextIndex=0,this.map=new Map}static newWithSystemAccounts(e){const t=new Zn;return t.addSystemAccounts(e),t}static newWithSystemAccountsV2(e){const t=new Zn;return t.addSystemAccountsV2(e),t}addPreAccountsSigner(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:0})}addPreAccountsSignerMut(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:1})}addPreAccountsMeta(e){this.preAccounts.push(e)}addSystemAccounts(e){this.systemAccounts.push(...Gn(e))}addSystemAccountsV2(e){this.systemAccounts.push(...Qn(e))}insertOrGet(e){return this.insertOrGetConfig(e,0,1)}insertOrGetReadOnly(e){return this.insertOrGetConfig(e,0,0)}insertOrGetConfig(e,t,r){const n=this.map.get(e);if(n)return n[0];const o=this.nextIndex++,s={pubkey:e,isSigner:t,isWritable:r};return this.map.set(e,[o,s]),o}hashSetAccountsToMetas(){const e=Array.from(this.map.entries());return e.sort(((e,t)=>e[1][0]-t[1][0])),e.map((([,[,e]])=>e))}getOffsets(){const e=this.preAccounts.length;return[e,e+this.systemAccounts.length]}toAccountMetas(){const e=this.hashSetAccountsToMetas(),[t,r]=this.getOffsets();return{remainingAccounts:[...this.preAccounts,...this.systemAccounts,...e],systemStart:t,packedStart:r}}}class Yn{constructor(e,t,r,n){this.selfProgram=e,this.cpiContext=t,this.solCompressionRecipient=r,this.solPoolPda=n}static new(e){return new Yn(e)}static newWithCpiContext(e,t){return new Yn(e,t)}}function Gn(t){let r=(new TextEncoder).encode("cpi_authority");const n=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],o=at(),s=[{pubkey:fo.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:o.noopProgram,isSigner:0,isWritable:0},{pubkey:o.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:o.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.selfProgram,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),s.push({pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}function Qn(t){let r=(new TextEncoder).encode("cpi_authority");const n=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],o=at(),s=[{pubkey:fo.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:o.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:o.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:o.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}function Jn(e){const t=eo(e.ar[0]),r=eo(e.ar[1]),n=new Uint8Array([...t,...r]),o=eo(e.bs[0][0]),s=eo(e.bs[0][1]),i=eo(e.bs[1][0]),a=eo(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=eo(e.krs[0]),l=eo(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function Xn(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=to(or(t.slice(32,64),32,"be"))?0:1;o[0]=ro(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=Ze.div(or(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(or(a.slice(0,32),32,"be"),or(a.slice(32,64),32,"be"));i[0]=ro(i[0],u);const c=n.slice(0,32),l=n.slice(32,64),d=to(or(l,32,"be"));return c[0]=ro(c[0],d),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function eo(e){const t=or(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function to(e){return e.lte(Ze.sub(e))}function ro(e,t){return t?e:128|e}function no(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function oo(e,t,r){const n=await e.sendTransaction(t,r);return await so(e,n,r),n}async function so(e,t,r){const n=(null==r?void 0:r.commitment)||e.commitment||"confirmed",o=ct(e.rpcEndpoint)?200:1e3;let s=0;await new Promise(((r,i)=>{const a=setInterval((async()=>{var u;s+=o,s>=8e4&&(clearInterval(a),i(new Error(`Transaction ${t}'s confirmation timed out`)));const c=await e.getSignatureStatuses([t]);(null===(u=null==c?void 0:c.value[0])||void 0===u?void 0:u.confirmationStatus)===n&&(clearInterval(a),r(t))}),o)}));const i=await e.getSlot();return await e.confirmTransactionIndexed(i),{context:{slot:i},value:{err:null}}}function io(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=no(e,t.publicKey,r,o);return i.sign(s),i}function ao(e,t){return uo(e,t)}function uo(e,t){const r=e.find((e=>e.tree.equals(t)||e.queue.equals(t)));if(!r)throw new Error(`No associated TreeInfo found for tree or queue. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: ${t.toBase58()}`);if(!r.queue)throw new Error("Queue must not be null for state tree. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: "+t.toBase58());return r}function co(e,t=($e.isV2()?exports.TreeType.StateV2: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 lo({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}const ho=e=>e.reduce(((e,t)=>e.add(or(t.lamports))),or(0)),po=y.from("sol_pool_pda");class fo{constructor(){}static deriveCompressedSolPda(){const t=[po],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=or(r);const n=ho(e).sub(r);return Vr(n),n.eq(or(0))?[sr(t,r)]:(qr(e),[sr(e[0].owner,n),sr(t,r)])}static createDecompressOutputState(e,t){t=or(t);const r=ho(e).sub(t);return Vr(r),r.eq(or(0))?[]:(qr(e),[sr(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=or(null!=r?r:0);const o=ho(null!=n?n:[]).sub(r);return Vr(o),o.eq(or(0))||!n?[sr(t,r,void 0,e)]:(qr(n),[sr(n[0].owner,o),sr(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:d,remainingAccounts:h}=Ur(null!=i?i:[],null!=a?a:[],c,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:f}=jn([r],h),m=hr({proof:o,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:d,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),y=[...Tr(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Dr(f)];return new e.TransactionInstruction({programId:this.programId,keys:y,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}=Ur(r,s,a),d=hr({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),h=[...Tr(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Dr(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTreeInfo:o}){n=or(n);const s=sr(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=Ur([],[],[s],o),c=hr({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),l=[...Tr(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:fo.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Dr(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=or(o);const a=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=Ur(r,s,a),d=hr({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),h=[...Tr(Object.assign(Object.assign({},at()),{feePayer:t,authority:t,solPoolPda:fo.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),...Dr(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}}function mo(e,t){let r=or(0);t=or(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(or(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(or(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}fo.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");class yo{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([or(this.value.toArray("be",32)).toString(),or(this.nextIndex).toString(),or(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class go{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class wo{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new wo([new yo(0,or(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=Ye;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([or(r.value.toArray("be",32)).toString(),or(r.nextIndex).toString(),or(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 yo(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new go(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 vo{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 xo(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=at(),o=(await e.getSignaturesForAddress(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===Ge.length&&Ge.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=tr.decode(t.data);o.push(e)}}const a=Eo(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 bo(i,Io)}const bo=(e,t)=>{const{noopProgram:r}=at(),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=tr.decode(s.data),o=t(y.from(r),e);null!=o&&n.push(o)}}}))})),n},Io=e=>{const t=y.from(e.map((e=>e)));try{return Sr(t)}catch(e){return console.error("Error deserializing event:",e),null}};function Eo(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=tr.encode(e),s=tr.encode(Qe),i=tr.encode(Je),a=tr.encode(Xe);if(o===s){n=Er(y.from(t)),r=1;break}if(o==i){n=Ar(y.from(t)),r=1;break}if(o==a){n=Fn(Ir(y.from(t))),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if(tr.encode(e)===tr.encode(tt)){const e=t.slice(12);o=Or(y.from(e))}}return n?Lr(o,t[t.length-1],n):null}async function Ao(e,t){return(await To(e)).find((e=>or(e.hash).eq(t)))}async function To(e){var t,r;const n=(await xo(e)).reverse(),o=[],s=[],i=await e.getStateTreeInfos();for(const e of n){for(let n=0;n<e.outputCompressedAccounts.length;n++){const s=ao(i,e.pubkeyArray[e.outputCompressedAccounts[n].merkleTreeIndex]),a=e.outputCompressedAccounts[n],u={treeInfo:s,hash:or(e.outputCompressedAccountHashes[n]),leafIndex:e.outputLeafIndices[n],proveByIndex:s.treeType===exports.TreeType.StateV2},c=ir(u,a.compressedAccount.owner,a.compressedAccount.lamports,null!==(t=a.compressedAccount.data)&&void 0!==t?t:void 0,null!==(r=a.compressedAccount.address)&&void 0!==r?r:void 0);o.push(c)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];s.push(or(r))}}const a=o.filter((e=>!s.some((t=>t.eq(or(e.hash))))));return a.sort(((e,t)=>t.leafIndex-e.leafIndex)),a}function Mo(t,r=mt){if(null===t.data)return null;const{data:n}=t.data;if(0===n.length)return null;if(t.owner.toBase58()!==r.toBase58())throw new Error(`Invalid owner ${t.owner.toBase58()} for token layout`);try{const t=Buffer.from(n);let r=0;const o=new e.PublicKey(t.slice(r,r+32));r+=32;const s=new e.PublicKey(t.slice(r,r+32));r+=32;const i=new je(t.slice(r,r+8),"le");r+=8;const a=t[r];r+=1;const u=a?new e.PublicKey(t.slice(r,r+32)):null;r+=32;const c=t[r];r+=1;const l=t[r];return r+=1,{mint:o,owner:s,amount:i,delegate:u,state:c,tlv:l?t.slice(r):null}}catch(e){throw console.error("Decoding error:",e),e}}async function So(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=ao(n,a);if(!(u.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])||$e.isV2()&&u.queue.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])))throw new Error("Invalid tree");const c={treeInfo:u,hash:or(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:u.treeType===exports.TreeType.StateV2};if(!t.compressedAccount.data)throw new Error("No data");const l=Mo(t.compressedAccount);if(!l)throw new Error("Invalid token data");return{compressedAccount:ir(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=>or(t).eq(e.compressedAccount.hash)))))}async function _o(e,t,r){const n=await xo(e);return{items:(await So(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 Co(e,t,r){const n=await xo(e);return{items:(await So(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 ko(e,t){const r=await xo(e),n=(await So(r,e)).filter((e=>or(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class Po 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 Ro(e){return"object"==typeof e&&null!=e}function Oo(e){return Ro(e)&&!Array.isArray(e)}function Lo(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Bo(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: \`${Lo(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*No(e,t,r,n){var o;Ro(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Bo(o,t,r,n);e&&(yield e)}}function*Do(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,d]of t.entries(e,a)){const t=Do(l,d,{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):Ro(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 Uo{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)=>No(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>No(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Fo(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Vo(e,this,t)}is(e){return qo(e,this)}mask(e,t){return function(e,t,r){const n=Fo(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Fo(e,this,t)}}function Vo(e,t,r){const n=Fo(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function qo(e,t){return!Fo(e,t)[0]}function Fo(e,t,r={}){const n=Do(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new Po(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function Ko(e,t){return new Uo({type:e,schema:null,validator:t})}function Ho(){return Ko("any",(()=>1))}function Wo(e){return new Uo({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: ${Lo(e)}`})}function jo(){return Ko("boolean",(e=>"boolean"==typeof e))}function $o(e){return Ko("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${Lo(t)}`))}function zo(e){const t=Lo(e);return new Uo({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${Lo(r)}`})}function Zo(e){return new Uo({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function Yo(){return Ko("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${Lo(e)}`))}function Go(){return Ko("string",(e=>"string"==typeof e||`Expected a string, but received: ${Lo(e)}`))}function Qo(e){const t=Object.keys(e);return new Uo({type:"type",schema:e,*entries(r){if(Ro(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>Oo(e)||`Expected an object, but received: ${Lo(e)}`,coercer:e=>Oo(e)?{...e}:e})}function Jo(e){const t=e.map((e=>e.type)).join(" | ");return new Uo({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]=Do(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: ${Lo(r)}`,...o]}})}function Xo(){return Ko("unknown",(()=>1))}function es(e,t,r){return new Uo({...e,coercer:(n,o)=>qo(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}var ts;exports.DerivationMode=void 0,(ts=exports.DerivationMode||(exports.DerivationMode={})).compressible="compressible",ts.standard="standard";const rs=es($o(e.PublicKey),Go(),(t=>new e.PublicKey(t))),ns=es($o(Array),Go(),(t=>Array.from(new e.PublicKey(t).toBytes()))),os=es($o(je),Go(),(e=>rr(e,"base58"))),ss=es(jo(),Jo([Yo(),jo()]),(e=>Boolean(e))),is=es($o(je),Jo([Go(),Yo()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return or(e)}return or(e,10)})),as=Go();function us(e){return Jo([Qo({jsonrpc:zo("2.0"),id:Go(),result:e}),Qo({jsonrpc:zo("2.0"),id:Go(),error:Qo({code:Xo(),message:Go(),data:Zo(Ho())})})])}const cs=us(Xo());function ls(e){return es(us(e),cs,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:Vo(t.result,e)})))}function ds(e){return ls(Qo({context:Qo({slot:Yo()}),value:e}))}const hs=Qo({treeType:Yo(),tree:rs,queue:rs,cpiContext:Zo(rs)}),ps=Qo({treeType:Yo(),tree:rs,queue:rs,cpiContext:Zo(rs),nextTreeContext:(fs=Zo(hs),new Uo({...fs,validator:(e,t)=>void 0===e||fs.validator(e,t),refiner:(e,t)=>void 0===e||fs.refiner(e,t)}))});var fs;const ms=Qo({address:Zo(ns),hash:os,data:Zo(Qo({data:as,dataHash:os,discriminator:is})),lamports:is,owner:rs,leafIndex:Yo(),tree:rs,seq:Zo(is),slotCreated:is}),ys=Qo({address:Zo(ns),hash:os,data:Zo(Qo({data:as,dataHash:os,discriminator:is})),lamports:is,owner:rs,leafIndex:Yo(),seq:Zo(is),slotCreated:is,merkleContext:ps,proveByIndex:ss}),gs=Qo({mint:rs,owner:rs,amount:is,delegate:Zo(rs),state:Go()}),ws=Qo({tokenData:gs,account:ms}),vs=Qo({tokenData:gs,account:ys}),xs=Qo({items:Wo(ms)}),bs=Qo({items:Wo(ys)}),Is=Qo({items:Wo(ms),cursor:Zo(Go())}),Es=Qo({items:Wo(ys),cursor:Zo(Go())}),As=Qo({items:Wo(ws),cursor:Zo(Go())}),Ts=Qo({items:Wo(vs),cursor:Zo(Go())}),Ms=Yo(),Ss=Go(),_s=Qo({items:Wo(Qo({signature:Go(),slot:Yo(),blockTime:Yo(),error:Zo(Go())}))}),Cs=Qo({items:Wo(Qo({signature:Go(),slot:Yo(),blockTime:Yo()})),cursor:Zo(Go())}),ks=Qo({hash:os,leafIndex:Yo(),merkleTree:rs,proof:Wo(os),rootSeq:Yo(),root:os}),Ps=Qo({hash:os,leafIndex:Yo(),proof:Wo(os),root:os,rootSeq:Yo(),proveByIndex:ss,treeContext:ps}),Rs=Qo({address:os,nextIndex:Yo(),merkleTree:rs,proof:Wo(os),rootSeq:Yo(),root:os,lowerRangeAddress:os,higherRangeAddress:os,lowElementLeafIndex:Yo()}),Os=Qo({a:Wo(Yo()),b:Wo(Yo()),c:Wo(Yo())}),Ls=Qo({rootIndex:Yo(),proveByIndex:ss}),Bs=Qo({compressedProof:Os,leafIndices:Wo(Yo()),leaves:Wo(os),rootIndices:Wo(Yo()),roots:Wo(os),merkleTrees:Wo(rs)}),Ns=Qo({hash:os,root:os,rootIndex:Ls,merkleContext:ps,leafIndex:Yo()}),Ds=Qo({address:os,root:os,rootIndex:Yo(),merkleContext:ps}),Us=Qo({compressedProof:Zo(Os),accounts:Wo(Ns),addresses:Wo(Ds)}),Vs=Wo(ks),qs=Wo(Ps),Fs=Qo({amount:is}),Ks=is,Hs=Qo({balance:is,mint:rs}),Ws=Qo({tokenBalances:Wo(Hs),cursor:Zo(Go())}),js=Qo({items:Wo(Hs),cursor:Zo(Go())}),$s=Qo({cursor:Zo(Go()),items:Wo(Qo({balance:is,owner:rs}))}),zs=Qo({hash:Wo(Yo()),root:Wo(Yo()),proof:Wo(Wo(Yo()))}),Zs=Qo({items:Wo(Qo({blockTime:Yo(),signature:Go(),slot:Yo()}))}),Ys=Qo({items:Wo(Qo({blockTime:Yo(),signature:Go(),slot:Yo()})),cursor:Zo(Go())}),Gs=Qo({account:ys,txHash:os,nullifier:os}),Qs=Qo({compressionInfo:Qo({closedAccounts:Wo(Qo({account:ms,optionalTokenData:Zo(gs)})),openedAccounts:Wo(Qo({account:ms,optionalTokenData:Zo(gs)}))}),transaction:Ho()}),Js=Qo({compressionInfo:Qo({closedAccounts:Wo(Qo({account:Gs,optionalTokenData:Zo(gs)})),openedAccounts:Wo(Qo({account:ys,optionalTokenData:Zo(gs)}))}),transaction:Ho()}),Xs={Solana:"solana",Compressed:"compressed"};function ei({discriminator:e,data:t,dataHash:r}){return{discriminator:e.toArray("le",8),data:y.from(t,"base64"),dataHash:r.toArray("le",32)}}async function ti(t,r,n,o=0){var s,i;const a=ze(o?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner"),u=o?"delegate":"owner",c=await ni(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});let l;if(l=$e.isV2()?Vo(c,ds(Ts)):Vo(c,ds(As)),"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 d=[],h=await t.getStateTreeInfos();return l.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=$e.isV2()?n.merkleContext.tree:n.tree,i=$e.isV2()?n.proveByIndex:0,a=ao(h,s),c=ir(ar(a,n.hash,n.leafIndex,i),n.owner,or(n.lamports),n.data?ei(n.data):void 0,n.address||void 0),l={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=l[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);d.push({compressedAccount:c,parsed:l})})),{items:d.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:l.result.value.cursor}}function ri(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 ni=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=ri(await i.text());return n?Dn(JSON.parse(a)):JSON.parse(a)},oi=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=Xn(Jn(await i.json()));return n&&console.timeEnd(s),a};function si(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Bn(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>Bn(e))),leaf:Bn(or(e[r].hash))};t.push(n)}return t}function ii(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Bn(e[r].root),value:Bn(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>Bn(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:Bn(e[r].leafLowerRangeValue),leafHigherRangeValue:Bn(e[r].leafHigherRangeValue)};t.push(n)}return t}function ai(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return or(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 ui(e){const t=e.account,r=e.optionalTokenData,n=ir(ar(t.treeInfo,t.hash.toArray("be",32),t.leafIndex,t.proveByIndex),t.owner,or(t.lamports),t.data?ei(t.data):void 0,t.address||void 0);return null===r?{account:n,maybeTokenData:null}:{account:n,maybeTokenData:{mint:r.mint,owner:r.owner,amount:r.amount,delegate:r.delegate,state:["uninitialized","initialized","frozen"].indexOf(r.state),tlv:null}}}function ci(e,t){var r,n,o,s;const i=new Map;for(const e of t)i.set(e.signature,{signature:e.signature,slot:e.slot,blockTime:e.blockTime,err:null,memo:null,confirmationStatus:void 0,sources:[Xs.Compressed]});for(const t of e)i.get(t.signature)?i.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:null!==(r=t.blockTime)&&void 0!==r?r:null,err:t.err,memo:null!==(n=t.memo)&&void 0!==n?n:null,confirmationStatus:t.confirmationStatus,sources:[Xs.Solana,Xs.Compressed]}):i.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:null!==(o=t.blockTime)&&void 0!==o?o:null,err:t.err,memo:null!==(s=t.memo)&&void 0!==s?s:null,confirmationStatus:t.confirmationStatus,sources:[Xs.Solana]});return Array.from(i.values()).sort(((e,t)=>t.slot-e.slot))}class li 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 getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(ct(this.rpcEndpoint))return lt();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}=ut();try{return await lo({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await lo({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 getAddressTreeInfoV2(){const t=new e.PublicKey(Wt);return{tree:t,queue:t,cpiContext:void 0,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}}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=await this.getStateTreeInfos(),o=await ni(this.compressionApiEndpoint,ze("getCompressedAccount"),{hash:r?nr(r):void 0,address:t?nr(t):void 0});let s;if(s=$e.isV2()?Vo(o,ds(Zo(ys))):Vo(o,ds(Zo(ms))),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===s.result.value)return null;const i=ao(n,$e.isV2()?s.result.value.merkleContext.tree:s.result.value.tree),a=s.result.value;return ir(ar(i,a.hash,a.leafIndex),a.owner,or(a.lamports),a.data?ei(a.data):void 0,a.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=Vo(await ni(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?nr(r):void 0,address:t?nr(t):void 0}),ds(Ks));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?or(0):or(n.result.value)}async getCompressedBalanceByOwner(t){const r=Vo(await ni(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),ds(Ks));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?or(0):or(r.result.value)}async getCompressedAccountProof(t){const r=await ni(this.compressionApiEndpoint,ze("getCompressedAccountProof"),{hash:nr(t)});let n;if(n=$e.isV2()?Vo(r,ds(Ps)):Vo(r,ds(ks)),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get proof for compressed account ${t.toString()}`);if(null===n.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const o=ao(await this.getStateTreeInfos(),$e.isV2()?n.result.value.treeContext.tree:n.result.value.tree);return{hash:or(n.result.value.hash.toArray("be",32)),treeInfo:o,leafIndex:n.result.value.leafIndex,merkleProof:n.result.value.proof,rootIndex:n.result.value.rootSeq%2400,root:n.result.value.root,proveByIndex:$e.isV2()?n.result.value.proveByIndex:0}}async getMultipleCompressedAccounts(t){const r=await ni(this.compressionApiEndpoint,ze("getMultipleCompressedAccounts"),{hashes:t.map((e=>nr(e)))});let n;if(n=$e.isV2()?Vo(r,ds(bs)):Vo(r,ds(xs)),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get info for compressed accounts ${t.map((e=>nr(e))).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>nr(e))).join(", ")}`);const o=await this.getStateTreeInfos(),s=[];return n.result.value.items.map((e=>{const t=$e.isV2()?e.merkleContext.tree:e.tree,r=ao(o,t),n=ir(ar(r,or(e.hash.toArray("be",32)),e.leafIndex),e.owner,or(e.lamports),e.data?ei(e.data):void 0,e.address||void 0);s.push(n)})),s.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=await ni(this.compressionApiEndpoint,ze("getMultipleCompressedAccountProofs"),t.map((e=>nr(e))));let n;if(n=$e.isV2()?Vo(r,ds(Wo(Ps))):Vo(r,ds(Wo(ks))),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get proofs for compressed accounts ${t.map((e=>nr(e))).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>nr(e))).join(", ")}`);const o=[],s=await this.getStateTreeInfos();for(const e of n.result.value){const t=ao(s,$e.isV2()?e.treeContext.tree:e.merkleTree),r={hash:or(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:$e.isV2()?e.proveByIndex:0};o.push(r)}return o}async getCompressedAccountsByOwner(t,r){var n;const o=await ni(this.compressionApiEndpoint,ze("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()});let s;if(s=$e.isV2()?Vo(o,ds(Es)):Vo(o,ds(Is)),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===s.result.value)return{items:[],cursor:null};const i=[],a=await this.getStateTreeInfos();return s.result.value.items.map((e=>{const t=ao(a,$e.isV2()?e.merkleContext.tree:e.tree),r=ir(ar(t,or(e.hash.toArray("be",32)),e.leafIndex,$e.isV2()?e.proveByIndex:0),e.owner,or(e.lamports),e.data?ei(e.data):void 0,e.address||void 0);i.push(r)})),{items:i.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:s.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await ti(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await ti(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=Vo(await ni(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:nr(t)}),ds(Fs));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:or(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var n,o;r||(r={});const s=Vo(await ni(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}),ds(Ws));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=Vo(await ni(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}),ds(js));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=Vo(await ni(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:nr(t)}),ds(Zs));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=await ni(this.compressionApiEndpoint,ze("getTransactionWithCompressionInfo"),{signature:t});let n;if(n=$e.isV2()?Vo(r,ls(Js)):Vo(r,ls(Qs)),"error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get slot");if(null===n.result.transaction)return null;const o=[],s=[],i=await this.getStateTreeInfos();$e.isV2()?(n.result.compressionInfo.closedAccounts.map((e=>{o.push(function(e){const t={account:e.account.account,optionalTokenData:e.optionalTokenData},r={nullifier:e.account.nullifier,txHash:e.account.txHash},n=ui(t);return{account:n.account,maybeTokenData:n.maybeTokenData,maybeNullifierMetadata:r}}(e))})),n.result.compressionInfo.openedAccounts.map((e=>{s.push(ui(e))}))):(n.result.compressionInfo.closedAccounts.map((e=>{const t=ao(i,e.account.tree),r=ir(ar(t,or(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,or(e.account.lamports),e.account.data?ei(e.account.data):void 0,e.account.address||void 0);o.push({account:r,maybeTokenData:e.optionalTokenData})})),n.result.compressionInfo.openedAccounts.map((e=>{const t=ao(i,e.account.tree),r=ir(ar(t,or(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,or(e.account.lamports),e.account.data?ei(e.account.data):void 0,e.account.address||void 0);s.push({account:r,maybeTokenData:e.optionalTokenData})})));const a=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},u=a(o),c=a(s);return{compressionInfo:{closedAccounts:o,openedAccounts:s,preTokenBalances:u,postTokenBalances:c},transaction:n.result.transaction}}async getCompressionSignaturesForAddress(t,r){var n;const o=Vo(await ni(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()}),ds(Ys));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=Vo(await ni(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()}),ds(Ys));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=Vo(await ni(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()}),ds(Ys));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=Vo(await ni(this.compressionApiEndpoint,"getIndexerHealth"),ls(Ss));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.result}async confirmTransactionIndexed(e){const t=ct(this.rpcEndpoint)?1e4:2e4,r=ct(this.rpcEndpoint)?100:200,n=Date.now();for(;;){if(await this.getIndexerSlot()>=e)return 1;if(Date.now()-n>t)throw new Error(`Timeout: Indexer slot did not reach the required slot within ${t/1e3}s`);await new Promise((e=>setTimeout(e,r)))}}async getIndexerSlot(){const t=Vo(await ni(this.compressionApiEndpoint,"getIndexerSlot"),ls(Ms));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=Vo(await ni(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()}),ds($s));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=Vo(await ni(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),ds(Cs));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=Vo(await ni(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),ds(_s));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=Vo(await ni(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>nr(e)))),ds(Wo(Rs)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>nr(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>nr(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:or(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:or(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:ft().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};n.push(t)}return n}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=ft().addressTree,i=ft().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 getValidityProofV2(e=[],t=[],r){const n=e.filter((e=>void 0!==e)).map((e=>({hash:e.hash,tree:e.treeInfo.tree,queue:e.treeInfo.queue}))),o=t.map((e=>{let t;if(r===exports.DerivationMode.compressible||void 0===r){const r=Wn(Uint8Array.from(e.address),e.treeInfo.tree,yt);t=or(r.toBytes())}else t=or(e.address);return{address:t,tree:e.treeInfo.tree,queue:e.treeInfo.queue}})),{value:s}=await this.getValidityProofAndRpcContext(n,o);return s}async getValidityProofAndRpcContext(t=[],r=[]){Fr(t.length,r.length);const n=await ni(this.compressionApiEndpoint,ze("getValidityProof"),{hashes:t.map((({hash:e})=>nr(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:nr(e),tree:t.toBase58()})))});let o;if(o=$e.isV2()?Vo(n,ds(Us)):Vo(n,ds(Bs)),"error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);const s=o.result.value;if($e.isV2())return{value:{compressedProof:s.compressedProof,leaves:s.accounts.map((e=>e.hash)).concat(s.addresses.map((e=>e.address))),roots:s.accounts.map((e=>e.root)).concat(s.addresses.map((e=>e.root))),rootIndices:s.accounts.map((e=>e.rootIndex.rootIndex)).concat(s.addresses.map((e=>e.rootIndex))),proveByIndices:s.accounts.map((e=>e.rootIndex.proveByIndex)).concat(s.addresses.map((()=>0))),treeInfos:s.accounts.map((e=>e.merkleContext)).concat(s.addresses.map((e=>e.merkleContext))),leafIndices:s.accounts.map((e=>e.leafIndex)).concat(s.addresses.map((()=>0)))},context:o.result.context};{const e=await this.getStateTreeInfos(),t=s.merkleTrees.map((t=>t.equals(ft().addressTree)?{tree:t,queue:ft().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}:uo(e,t)));return{value:{compressedProof:s.compressedProof,roots:s.roots,rootIndices:s.rootIndices.map((e=>e)),leafIndices:s.leafIndices,leaves:s.leaves,treeInfos:t,proveByIndices:s.rootIndices.map((e=>e.proveByIndex))},context:o.result.context}}}async getAccountInfoInterface(e,t,r,n){if(!$e.isV2())throw new Error("getAccountInfoInterface requires feature flag V2");n=null!=n?n:dt();const o=Wn(e.toBytes(),n.tree,t),[s,i]=await Promise.allSettled([this.getAccountInfo(e,r),this.getCompressedAccount(or(o.toBytes()))]),a="fulfilled"===s.status?s.value:null,u="fulfilled"===i.status?i.value:null;return a?u?{accountInfo:a,loadContext:{treeInfo:u.treeInfo,hash:u.hash,leafIndex:u.leafIndex,proveByIndex:u.proveByIndex},isCold:0}:{accountInfo:a,loadContext:void 0,isCold:0}:u&&u.data&&u.data.data.length>0?{accountInfo:{executable:0,owner:u.owner,lamports:u.lamports.toNumber(),data:y.concat([y.from(u.data.discriminator),u.data.data])},loadContext:{treeInfo:u.treeInfo,hash:u.hash,leafIndex:u.leafIndex,proveByIndex:u.proveByIndex},isCold:1}:null}async getSignaturesForAddressInterface(e,t,r){const[n,o]=await Promise.allSettled([this.getSignaturesForAddress(e,t),this.getCompressionSignaturesForAddress(e,r)]),s="fulfilled"===n.status?n.value:[],i="fulfilled"===o.status?o.value.items:[];return{signatures:ci(s,i),solana:s,compressed:i}}async getSignaturesForOwnerInterface(e,t,r){const[n,o]=await Promise.allSettled([this.getSignaturesForAddress(e,t),this.getCompressionSignaturesForOwner(e,r)]),s="fulfilled"===n.status?n.value:[],i="fulfilled"===o.status?o.value.items:[];return{signatures:ci(s,i),solana:s,compressed:i}}async getTokenAccountBalanceInterface(e,t,r,n){const[o,s]=await Promise.allSettled([this.getTokenAccountBalance(e,n),this.getCompressedTokenBalancesByOwner(t,{mint:r})]);let i=or(0),a=0,u=null;if("fulfilled"===o.status&&o.value){const e=o.value.value;i=or(e.amount),a=e.decimals,u=e}let c=or(0);if("fulfilled"===s.status){const e=s.value.items.filter((e=>e.mint.equals(r)));for(const t of e)c=c.add(t.balance)}return{amount:i.add(c),hasColdBalance:!c.isZero(),decimals:a,solana:u}}async getBalanceInterface(e,t){const[r,n]=await Promise.allSettled([this.getBalance(e,t),this.getCompressedBalanceByOwner(e)]),o="fulfilled"===r.status?or(r.value):or(0),s="fulfilled"===n.status?n.value:or(0);return{total:o.isZero()?s:o,hasColdBalance:!s.isZero()}}}class di extends e.Connection{constructor(e,t,r,n,o,s){super(e,o||{commitment:"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}=ft();this.lightWasm=t,this.depth=null!=i?i:u,this.log=null!=a?a:0}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return lt()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}async getAddressTreeInfoV2(){const t=new e.PublicKey(Wt);return{tree:t,queue:t,cpiContext:void 0,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}}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 Ao(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 Ao(this,t);if(!r)throw new Error("Account not found");return or(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),or(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await To(e)).filter((e=>t.some((t=>or(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(t){const r=await xo(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=ao(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]);n.has(s.tree.toBase58())||n.set(s.tree.toBase58(),{leaves:[],leafIndices:[],treeInfo:s});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:o,treeInfo:i}]of n.entries()){const a=new e.PublicKey(r);let u;if(i.treeType===exports.TreeType.StateV1)u=new vo(this.depth,this.lightWasm,o.map((e=>or(e).toString())));else{if(i.treeType!==exports.TreeType.StateV2)throw new Error(`Invalid tree type: ${i.treeType} in test-rpc.ts`);u=new vo(32,this.lightWasm,[])}for(let e=0;e<t.length;e++){const r=o.findIndex((r=>or(r).eq(t[e])));if(-1!==r)if(i.treeType===exports.TreeType.StateV1){const n=u.path(r).pathElements.map((e=>or(e))),a=or(u.root()),c={hash:or(t[e].toArray("be",32)),treeInfo:i,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:o.length,root:a};s.set(t[e].toString(),c)}else if(i.treeType===exports.TreeType.StateV2){const r=u._zeros.slice(0,-1).map((e=>or(e))),o=or(u.root()),c=n.get(a.toBase58()).leafIndices.findIndex((r=>t[e].eq(or(n.get(a.toBase58()).leaves[r])))),l={hash:or(t[e].toArray("be",32)),treeInfo:i,leafIndex:c,merkleProof:r,proveByIndex:1,rootIndex:0,root:o};s.set(t[e].toString(),l)}}}if(s.forEach(((e,t)=>{if(e.treeInfo.treeType===exports.TreeType.StateV1){const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=or(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)}})),new Set(t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`Proof not found for hash: ${e.toString()}`);return t.treeInfo.treeType}))).size>1)throw new Error("Requested hashes belong to different tree types (V1/V2)");return 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 To(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 _o(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await Co(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await ko(this,e);return{amount:or(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await _o(this,e,t.mint)).items.map((e=>({balance:or(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await _o(this,e,t.mint)).items.map((e=>({balance:or(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=wo.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(or(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(or(r))}const o=new vo(this.depth,this.lightWasm,n.map((e=>or(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=>or(e))),u=t.get(n.nextIndex).value,c={root:or(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:or(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:or(n.index),treeInfo:{tree:ft().addressTree,queue:ft().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 getValidityProofAndRpcContext(e=[],t=[]){if(t.some((e=>!(e instanceof je))))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 je))))throw new Error("AddressWithTree is not supported in test-rpc");let r;const n=[];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){for(const t of e){const e=await this.getCompressedAccount(void 0,t);if(!e)throw new Error("Account not found");n.push(e.treeInfo)}const t=n.some((e=>e.treeType===exports.TreeType.StateV1)),o=await this.getMultipleCompressedAccountProofs(e);if(t){const e=si(o);r={compressedProof:await oi(this.proverEndpoint,"inclusion",e,this.log),roots:o.map((e=>e.root)),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>or(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else r={compressedProof:null,roots:o.map((()=>or(0))),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>or(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=ii(e);r={compressedProof:await oi(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=>or(e.value))),treeInfos:e.map((e=>e.treeInfo)),proveByIndices:e.map((()=>0))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=await this.getMultipleNewAddressProofs(t),s=n.map((e=>e.treeInfo)).some((e=>e.treeType===exports.TreeType.StateV1)),i=ii(o);let a;if(s){const e=si(n);a=await oi(this.proverEndpoint,"combined",[e,i],1)}else a=await oi(this.proverEndpoint,"new-address",i,1);r={compressedProof:a,roots:n.map((e=>s?e.root:or(0))).concat(o.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(o.map((()=>3))),leafIndices:n.map((e=>e.leafIndex)).concat(o.map((e=>e.indexHashedIndexedElementLeaf.toNumber()))),leaves:n.map((e=>or(e.hash))).concat(o.map((e=>or(e.value)))),treeInfos:n.map((e=>e.treeInfo)).concat(o.map((e=>e.treeInfo))),proveByIndices:n.map((e=>e.proveByIndex)).concat(o.map((()=>0)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}async getValidityProofV2(e=[],t=[],r){const n=e.filter((e=>void 0!==e)).map((e=>({hash:e.hash,tree:e.treeInfo.tree,queue:e.treeInfo.queue}))),o=t.map((e=>({address:e.address,tree:e.treeInfo.tree,queue:e.treeInfo.queue})));return this.getValidityProofV0(n,o)}async getAccountInfoInterface(e,t,r){throw new Error("getAccountInfoInterface not implemented in TestRpc")}async getSignaturesForAddressInterface(e,t,r){throw new Error("getSignaturesForAddressInterface not implemented in TestRpc")}async getSignaturesForOwnerInterface(e,t,r){throw new Error("getSignaturesForOwnerInterface not implemented in TestRpc")}async getTokenAccountBalanceInterface(e,t,r,n){throw new Error("getTokenAccountBalanceInterface not implemented in TestRpc")}async getBalanceInterface(e,t){throw new Error("getBalanceInterface not implemented in TestRpc")}}let hi=1;const pi=gi(255),fi=gi(254),mi=gi(253),yi=gi(252);function gi(t){if(t||(t=hi,hi++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var wi,vi,xi,bi,Ii,Ei,Ai,Ti;exports.UtxoErrorCode=void 0,(wi=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",wi.NOT_U64="NOT_U64",wi.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(vi=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",vi.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(xi=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",xi.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",xi.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(bi=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",bi.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",bi.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",bi.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(Ii=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",Ii.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,(Ei=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",Ei.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",Ei.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(Ai=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",Ai.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",Ai.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",Ai.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",Ai.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",Ai.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(Ti=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",Ti.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",Ti.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",Ti.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",Ti.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",Ti.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",Ti.INVALID_NUMBER="INVALID_NUMBER";class Mi extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}exports.ADDRESS_QUEUE_ROLLOVER_FEE=Qt,exports.ADDRESS_TREE_NETWORK_FEE_V1=Xt,exports.ADDRESS_TREE_NETWORK_FEE_V2=er,exports.ALICE=pi,exports.AccountProofResult=zs,exports.AppendLeavesInputLayout=Cr,exports.AppendNullifyCreateAddressInputsMetaLayout=_r,exports.BOB=fi,exports.BalanceResult=Fs,exports.CHARLIE=mi,exports.COMPRESSED_TOKEN_PROGRAM_ID=mt,exports.COMPUTE_BUDGET_PATTERN=Ge,exports.CTOKEN_PROGRAM_ID=yt,exports.CompressedAccountLayout=ur,exports.CompressedAccountResult=ms,exports.CompressedAccountResultV2=ys,exports.CompressedAccountsByOwnerResult=Is,exports.CompressedAccountsByOwnerResultV2=Es,exports.CompressedCpiContextLayout=mr,exports.CompressedMintTokenHoldersResult=$s,exports.CompressedProofLayout=fr,exports.CompressedTokenAccountResult=ws,exports.CompressedTokenAccountResultV2=vs,exports.CompressedTokenAccountsByOwnerOrDelegateResult=As,exports.CompressedTokenAccountsByOwnerOrDelegateResultV2=Ts,exports.CompressedTransactionResult=Qs,exports.CompressedTransactionResultV2=Js,exports.CreateUtxoError=class extends Mi{},exports.DAVE=yi,exports.DEFAULT_MERKLE_TREE_HEIGHT=Zt,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=Ze,exports.HIGHEST_ADDRESS_PLUS_ONE=Ye,exports.HashError=class extends Mi{},exports.HealthResult=Ss,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:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{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=tt,exports.INVOKE_CPI_DISCRIMINATOR=Je,exports.INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR=et,exports.INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR=Xe,exports.INVOKE_DISCRIMINATOR=Qe,exports.InAccountLayout=wr,exports.IndexedArray=wo,exports.IndexedElement=yo,exports.IndexedElementBundle=go,exports.InsertAddressInputLayout=Pr,exports.InsertNullifierInputLayout=kr,exports.InstructionDataInvokeCpiLayout=pr,exports.InstructionDataInvokeCpiWithReadOnlyLayout=br,exports.InstructionDataInvokeLayout=dr,exports.LatestNonVotingSignaturesResult=_s,exports.LatestNonVotingSignaturesResultPaginated=Cs,exports.LightSystemProgram=fo,exports.LookupTableError=class extends Mi{},exports.MerkleContextLayout=cr,exports.MerkleProofResult=ks,exports.MerkleProofResultV2=Ps,exports.MerkleTree=vo,exports.MerkleTreeError=class extends Mi{},exports.MerkleTreeSequenceNumberLayout=Rr,exports.MultipleCompressedAccountsResult=xs,exports.MultipleCompressedAccountsResultV2=bs,exports.MultipleMerkleProofsResult=Vs,exports.MultipleMerkleProofsResultV2=qs,exports.NativeBalanceResult=Ks,exports.NewAddressParamsAssignedPackedLayout=yr,exports.NewAddressParamsLayout=lr,exports.NewAddressProofResult=Rs,exports.PackedAccounts=Zn,exports.PackedMerkleContextLayout=gr,exports.PackedReadOnlyAddressLayout=vr,exports.PackedReadOnlyCompressedAccountLayout=xr,exports.ProofError=class extends Mi{},exports.PublicTransactionEventLayout=Mr,exports.RootIndexResultV2=Ls,exports.Rpc=li,exports.RpcError=class extends Mi{},exports.STATE_MERKLE_TREE_NETWORK_FEE=Jt,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=Gt,exports.SelectInUtxosError=class extends Mi{},exports.SignatureListResult=Zs,exports.SignatureListWithCursorResult=Ys,exports.SignatureSource=Xs,exports.SlotResult=Ms,exports.SystemAccountMetaConfig=Yn,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=Yt,exports.TestRpc=di,exports.TokenBalanceListResult=Ws,exports.TokenBalanceListResultV2=js,exports.TokenBalanceResult=Hs,exports.TokenDataResult=gs,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends Mi{},exports.UtxoError=class extends Mi{},exports.ValidityProofResult=Bs,exports.ValidityProofResultV2=Us,exports.accountCompressionProgram=ot,exports.addressQueue=Tt,exports.addressTree=At,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await $n(e,n),n},exports.batchAddressTree=Wt,exports.batchCpiContext1=Pt,exports.batchCpiContext2=Lt,exports.batchCpiContext3=Dt,exports.batchCpiContext4=qt,exports.batchCpiContext5=Ht,exports.batchMerkleTree=$t,exports.batchMerkleTree1=Ct,exports.batchMerkleTree2=Rt,exports.batchMerkleTree3=Bt,exports.batchMerkleTree4=Ut,exports.batchMerkleTree5=Ft,exports.batchQueue=zt,exports.batchQueue1=kt,exports.batchQueue2=Ot,exports.batchQueue3=Nt,exports.batchQueue4=Vt,exports.batchQueue5=Kt,exports.bn=or,exports.bufToDecStr=e=>rr(e).toString(),exports.buildAndSignTx=io,exports.buildTx=no,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=co(await t.getStateTreeInfos()));const u=await fo.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTreeInfo:s}),c=io([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await oo(t,c,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=$n,exports.confirmTx=so,exports.convertInvokeCpiWithReadOnlyToInvoke=Fn,exports.convertMerkleProofsWithContextToHex=si,exports.convertNonInclusionMerkleProofInputsToHex=ii,exports.convertToPublicTransactionEvent=Lr,exports.cpiContext2Pubkey=_t,exports.cpiContextPubkey=It,exports.createAccount=async function(t,r,n,o,s,i,a){const{blockhash:u}=await t.getLatestBlockhash(),c=null!=s?s:ht(),{tree:l,queue:d}=c,h=c.treeType===exports.TreeType.AddressV2;if($e.isV2()||h)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const p=Kn(n,o),f=Hn(p,l);i||(i=co(await t.getStateTreeInfos()));const m=await t.getValidityProofV0(void 0,[{address:or(f.toBytes()),tree:l,queue:d}]),y={seed:p,addressMerkleTreeRootIndex:m.rootIndices[0],addressMerkleTreePubkey:m.treeInfos[0].tree,addressQueuePubkey:m.treeInfos[0].queue},g=await fo.createAccount({payer:r.publicKey,newAddressParams:y,newAddress:Array.from(f.toBytes()),recentValidityProof:m.compressedProof,programId:o,outputStateTreeInfo:i}),w=io([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),g],r,u,[]);return await oo(t,w,a)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u){o=or(o);const c=await t.getCompressedAccountsByOwner(r.publicKey),[l]=mo(c.items,o),{blockhash:d}=await t.getLatestBlockhash(),h=null!=i?i:ht(),{tree:p}=h,f=h.treeType===exports.TreeType.AddressV2;if($e.isV2()||f)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const m=Kn(n,s),y=Hn(m,p),g=await t.getValidityProof(l.map((e=>e.hash)),[or(y.toBytes())]),w={seed:m,addressMerkleTreeRootIndex:g.rootIndices[g.rootIndices.length-1],addressMerkleTreePubkey:g.treeInfos[g.treeInfos.length-1].tree,addressQueuePubkey:g.treeInfos[g.treeInfos.length-1].queue},v=await fo.createAccount({payer:r.publicKey,newAddressParams:w,newAddress:Array.from(y.toBytes()),recentValidityProof:g.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:g.rootIndices,outputStateTreeInfo:a}),x=io([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),v],r,d,[]);return await oo(t,x,u)},exports.createBN254=rr,exports.createCompressedAccountLegacy=sr,exports.createCompressedAccountMeta=(e,t,r,n)=>({treeInfo:e,outputStateTreeIndex:t,address:null!=r?r:null,lamports:null!=n?n:null}),exports.createCompressedAccountWithMerkleContextLegacy=ir,exports.createMerkleContextLegacy=ar,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 li(s,r,n,o)},exports.createRpcResult=us,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=io([s],r,(await t.getLatestBlockhash()).blockhash,zn(r,[n]));return{address:i,txId:await oo(t,a)}},exports.decodeInstructionDataInvoke=Er,exports.decodeInstructionDataInvokeCpi=Ar,exports.decodeInstructionDataInvokeCpiWithReadOnly=Ir,exports.decodePublicTransactionEvent=Sr,exports.decompress=async function(t,r,n,o,s){const i=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=or(n);const a=ho(i);if(n.gt(a))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${a}`);const u=await t.getValidityProof(i.map((e=>or(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),l=await fo.decompress({payer:r.publicKey,toAddress:o,inputCompressedAccounts:i,recentValidityProof:u.compressedProof,recentInputStateRootIndices:u.rootIndices,lamports:n}),d=io([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,c,[]);return await oo(t,d,s)},exports.dedupeSigner=zn,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof je&&r instanceof je)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=ut,exports.defaultStaticAccounts=()=>[new e.PublicKey(st()),new e.PublicKey(rt),new e.PublicKey(ot),new e.PublicKey(it())],exports.defaultStaticAccountsStruct=at,exports.defaultTestStateTreeAccounts=ft,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(St),merkleTree2:new e.PublicKey(Mt)}),exports.deriveAddress=Hn,exports.deriveAddressSeed=Kn,exports.deriveAddressSeedV2=function(e){return Vn(e.map((e=>Uint8Array.from(e))))},exports.deriveAddressV2=Wn,exports.deserializeAppendNullifyCreateAddressInputsIndexer=Or,exports.encodeBN254toBase58=nr,exports.encodeInstructionDataInvoke=hr,exports.encodePublicTransactionEvent=function(e){const t=y.alloc(1e3),r=Mr.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=io([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,zn(i,[a]));return{tableAddress:r,txId:await oo(t,c)}},exports.featureFlags=$e,exports.getAccountCompressionAuthority=it,exports.getAllStateTreeInfos=lo,exports.getBatchAddressTreeInfo=pt,exports.getCompressedTokenAccountByHashTest=ko,exports.getCompressedTokenAccounts=So,exports.getCompressedTokenAccountsByDelegateTest=Co,exports.getCompressedTokenAccountsByOwnerTest=_o,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getDefaultAddressSpace=dt,exports.getDefaultAddressTreeInfo=ht,exports.getIndexOrAdd=Br,exports.getLightSystemAccountMetas=Gn,exports.getLightSystemAccountMetasV2=Qn,exports.getOutputQueue=function(e){var t,r;return null!==(r=null===(t=e.treeInfo.nextTreeInfo)||void 0===t?void 0:t.queue)&&void 0!==r?r:e.treeInfo.queue},exports.getOutputTreeInfo=function(e){var t;return null!==(t=e.treeInfo.nextTreeInfo)&&void 0!==t?t:e.treeInfo},exports.getParsedEvents=xo,exports.getPublicInputHash=function(e,t,r,n){const o=ai(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=ai(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?ai([o],[i],n):o:i},exports.getRegisteredProgramPda=st,exports.getStateTreeInfoByPubkey=ao,exports.getTestKeypair=gi,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 di(t,e,r,n,void 0,{depth:o||ft().merkleTreeHeight,log:s})},exports.getTreeInfoByPubkey=uo,exports.hashToBn254FieldSizeBe=Un,exports.hashvToBn254FieldSizeBe=qn,exports.hashvToBn254FieldSizeBeU8Array=Vn,exports.invokeAccountsLayout=Tr,exports.isLocalTest=ct,exports.isSmallerThanBn254FieldSizeBe=Nn,exports.jsonRpcResult=ls,exports.jsonRpcResultAndContext=ds,exports.lightSystemProgram=nt,exports.localTestActiveStateTreeInfos=lt,exports.mergeSignatures=ci,exports.merkleTree2Pubkey=Mt,exports.merkletreePubkey=Et,exports.negateAndCompressProof=Xn,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=gi(r),o=await e.requestAirdrop(n.publicKey,t);return await so(e,o),n},exports.noopProgram=rt,exports.nullifiedStateTreeLookupTableDevnet=xt,exports.nullifiedStateTreeLookupTableMainnet=wt,exports.nullifierQueue2Pubkey=St,exports.nullifierQueuePubkey=bt,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=io([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:n,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash,zn(s,[i]));return{txId:await oo(t,c)}},exports.packCompressedAccounts=Ur,exports.packDecompressAccountsIdempotent=async function(e,t,r,n){const o=[],s=new Map,i=(e,t)=>{const r=e.toBase58();if(!s.has(r)){const n=o.length;return o.push({pubkey:e,isSigner:0,isWritable:t}),s.set(r,n),n}return s.get(r)},a=r.map((e=>{const t=i(e.treeInfo.tree,1),r=i(e.treeInfo.queue,1);return{[e.key]:e.data,merkleContext:{merkleTreePubkeyIndex:t,queuePubkeyIndex:r}}})),u=o.length;return n.forEach((e=>{i(e,1)})),{proofOption:{0:t.compressedProof},compressedAccounts:a,systemAccountsOffset:u,remainingAccounts:o}},exports.packNewAddressParams=jn,exports.packTreeInfos=function(e,t,r){const n=e.slice(),o=[],s=[];let i=-1;if(0===t.length&&0===r.length)return{stateTrees:void 0,addressTrees:s};if(t.forEach((e=>{const t=Br(n,e.treeInfo.tree),r=Br(n,e.treeInfo.queue);o.push({rootIndex:e.rootIndex,merkleTreePubkeyIndex:t,queuePubkeyIndex:r,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex})})),o.length>0){const e=t[0].treeInfo.nextTreeInfo||t[0].treeInfo;let r=e.tree;if(e.treeType===exports.TreeType.StateV2){if(!$e.isV2())throw new Error("V2 trees are not supported yet");r=e.queue}i=Br(n,r)}return r.forEach((e=>{const t=Br(n,e.treeInfo.tree),r=Br(n,e.treeInfo.queue);s.push({rootIndex:e.rootIndex,addressMerkleTreePubkeyIndex:t,addressQueuePubkeyIndex:r})})),{stateTrees:o.length>0?{packedTreeInfos:o,outputTreeIndex:i}:void 0,addressTrees:s}},exports.padOutputStateMerkleTrees=Nr,exports.parseAccountData=ei,exports.parseEvents=bo,exports.parseLightTransaction=Eo,exports.parsePublicTransactionEventWithIdl=Io,exports.parseTokenLayoutWithIdl=Mo,exports.pickRandomTreeAndQueue=function(e){const t=e.length,r=Math.floor(Math.random()*t);let n;if(void 0!==r){if(r<0||r>=e.length)throw new Error(`Index ${r} out of bounds for infos array of length ${e.length}`);n=r}else n=Math.floor(Math.random()*e.length);return e[n]},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=Jn,exports.proverRequest=oi,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=ni,exports.selectMinCompressedSolAccountsForTransfer=mo,exports.selectStateTreeInfo=co,exports.sendAndConfirmTx=oo,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=vt,exports.stateTreeLookupTableMainnet=gt,exports.sumUpLamports=ho,exports.testBatchAddressTree=jt,exports.toAccountMetas=Dr,exports.toArray=e=>Array.isArray(e)?e:[e],exports.toCamelCase=Dn,exports.toHex=Bn,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i){var a;let u=or(0);const c=[];let l;for(n=or(n);u.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:l,limit:or(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(or(0))&&(c.push(e),u=u.add(e.lamports));if(l=null!==(a=r.cursor)&&void 0!==a?a:void 0,r.items.length<1e3||u.gte(n))break}if(u.lt(n))throw new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${u.toString()}`);const[d]=mo(c,n),h=await t.getValidityProof(d.map((e=>or(e.hash)))),p=await fo.transfer({payer:r.publicKey,inputCompressedAccounts:d,toAddress:s,lamports:n,recentInputStateRootIndices:h.rootIndices,recentValidityProof:h.compressedProof}),{blockhash:f}=await t.getLatestBlockhash(),m=io([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),p],r,f);return await oo(t,m,i)},exports.validateNumbers=Wr,exports.validateNumbersForInclusionProof=Kr,exports.validateNumbersForNonInclusionProof=Hr,exports.validateNumbersForProof=Fr,exports.validateSameOwner=qr,exports.validateSufficientBalance=Vr,exports.versionedEndpoint=ze,exports.wrapBigNumbersAsStrings=ri;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|