@lightprotocol/stateless.js 0.22.1-alpha.7 → 0.23.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import e,{PublicKey as t,Keypair as r,SystemProgram as n,TransactionMessage as o,VersionedTransaction as s,AddressLookupTableProgram as i,TransactionInstruction as a,ComputeBudgetProgram as u,Connection as c,SolanaJSONRPCError as l}from"@solana/web3.js";const d={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"}]};var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},f=[],p=[],m="undefined"!=typeof Uint8Array?Uint8Array:Array,g=0;function y(){g=1;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)f[t]=e[t],p[e.charCodeAt(t)]=t;p["-".charCodeAt(0)]=62,p["_".charCodeAt(0)]=63}function w(e,t,r){for(var n,o,s=[],i=t;i<r;i+=3)n=(e[i]<<16)+(e[i+1]<<8)+e[i+2],s.push(f[(o=n)>>18&63]+f[o>>12&63]+f[o>>6&63]+f[63&o]);return s.join("")}function v(e){var t;g||y();for(var r=e.length,n=r%3,o="",s=[],i=16383,a=0,u=r-n;a<u;a+=i)s.push(w(e,a,a+i>u?u:a+i));return 1===n?(t=e[r-1],o+=f[t>>2],o+=f[t<<4&63],o+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],o+=f[t>>10],o+=f[t>>4&63],o+=f[t<<2&63],o+="="),s.push(o),s.join("")}function b(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,f=e[t+d];for(d+=h,s=f&(1<<-l)-1,f>>=-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*(f?-1:1);i+=Math.pow(2,n),s-=c}return(f?-1:1)*i*Math.pow(2,s-n)}function I(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,f=n?0:s-1,p=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+f]=255&a,f+=p,a/=256,o-=8);for(i=i<<o|a,c+=o;c>0;e[r+f]=255&i,f+=p,i/=256,c-=8);e[r+f-p]|=128*m}var A={}.toString,E=Array.isArray||function(e){return"[object Array]"==A.call(e)};T.TYPED_ARRAY_SUPPORT=void 0!==h.TYPED_ARRAY_SUPPORT?h.TYPED_ARRAY_SUPPORT:1;var x=M();function M(){return T.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function _(e,t){if(M()<t)throw new RangeError("Invalid typed array length");return T.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=T.prototype:(null===e&&(e=new T(t)),e.length=t),e}function T(e,t,r){if(!(T.TYPED_ARRAY_SUPPORT||this instanceof T))return new T(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 C(this,e)}return k(this,e,t,r)}function k(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),T.TYPED_ARRAY_SUPPORT?(e=t).__proto__=T.prototype:e=P(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!T.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|N(t,r),o=(e=_(e,n)).write(t,r);return o!==n&&(e=e.slice(0,o)),e}(e,t,r):function(e,t){if(L(t)){var r=0|B(t.length);return 0===(e=_(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?_(e,0):P(e,t);if("Buffer"===t.type&&E(t.data))return P(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function S(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 C(e,t){if(S(t),e=_(e,t<0?0:0|B(t)),!T.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function P(e,t){var r=t.length<0?0:0|B(t.length);e=_(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function B(e){if(e>=M())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+M().toString(16)+" bytes");return 0|e}function L(e){return!(null==e||!e._isBuffer)}function N(e,t){if(L(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 ie(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return ae(e).length;default:if(n)return ie(e).length;t=(""+t).toLowerCase(),n=1}}function O(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 G(this,t,r);case"utf8":case"utf-8":return z(this,t,r);case"ascii":return Z(this,t,r);case"latin1":case"binary":return Y(this,t,r);case"base64":return j(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=1}}function U(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function R(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=T.from(t,n)),L(t))return 0===t.length?-1:D(e,t,r,n,o);if("number"==typeof t)return t&=255,T.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):D(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function D(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 V(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 q(e,t,r,n){return ue(ie(t,e.length-r),e,r,n)}function F(e,t,r,n){return ue(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function W(e,t,r,n){return F(e,t,r,n)}function H(e,t,r,n){return ue(ae(t),e,r,n)}function $(e,t,r,n){return ue(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 j(e,t,r){return 0===t&&r===e.length?v(e):v(e.slice(t,r))}function z(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<=K)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=K));return r}(n)}T.poolSize=8192,T._augment=function(e){return e.__proto__=T.prototype,e},T.from=function(e,t,r){return k(null,e,t,r)},T.TYPED_ARRAY_SUPPORT&&(T.prototype.__proto__=Uint8Array.prototype,T.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&T[Symbol.species]),T.alloc=function(e,t,r){return function(e,t,r,n){return S(t),t<=0?_(e,t):void 0!==r?"string"==typeof n?_(e,t).fill(r,n):_(e,t).fill(r):_(e,t)}(null,e,t,r)},T.allocUnsafe=function(e){return C(null,e)},T.allocUnsafeSlow=function(e){return C(null,e)},T.isBuffer=ce,T.compare=function(e,t){if(!L(e)||!L(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},T.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}},T.concat=function(e,t){if(!E(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return T.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=T.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!L(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},T.byteLength=N,T.prototype._isBuffer=1,T.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)U(this,t,t+1);return this},T.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)U(this,t,t+3),U(this,t+1,t+2);return this},T.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)U(this,t,t+7),U(this,t+1,t+6),U(this,t+2,t+5),U(this,t+3,t+4);return this},T.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?z(this,0,e):O.apply(this,arguments)},T.prototype.equals=function(e){if(!L(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===T.compare(this,e)},T.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+">"},T.prototype.compare=function(e,t,r,n,o){if(!L(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},T.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},T.prototype.indexOf=function(e,t,r){return R(this,e,t,r,1)},T.prototype.lastIndexOf=function(e,t,r){return R(this,e,t,r,0)},T.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 V(this,e,t,r);case"utf8":case"utf-8":return q(this,e,t,r);case"ascii":return F(this,e,t,r);case"latin1":case"binary":return W(this,e,t,r);case"base64":return H(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=1}},T.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;function Z(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 Y(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 G(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 X(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 J(e,t,r,n,o,s){if(!L(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 ee(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 te(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 re(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 ne(e,t,r,n,o){return o||re(e,0,r,4),I(e,t,r,n,23,4),r+4}function oe(e,t,r,n,o){return o||re(e,0,r,8),I(e,t,r,n,52,8),r+8}T.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),T.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=T.prototype;else{var o=t-e;r=new T(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},T.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},T.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},T.prototype.readUInt8=function(e,t){return t||Q(e,1,this.length),this[e]},T.prototype.readUInt16LE=function(e,t){return t||Q(e,2,this.length),this[e]|this[e+1]<<8},T.prototype.readUInt16BE=function(e,t){return t||Q(e,2,this.length),this[e]<<8|this[e+1]},T.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]},T.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])},T.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},T.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},T.prototype.readInt8=function(e,t){return t||Q(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},T.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},T.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},T.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},T.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]},T.prototype.readFloatLE=function(e,t){return t||Q(e,4,this.length),b(this,e,1,23,4)},T.prototype.readFloatBE=function(e,t){return t||Q(e,4,this.length),b(this,e,0,23,4)},T.prototype.readDoubleLE=function(e,t){return t||Q(e,8,this.length),b(this,e,1,52,8)},T.prototype.readDoubleBE=function(e,t){return t||Q(e,8,this.length),b(this,e,0,52,8)},T.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||J(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},T.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||J(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},T.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,1,255,0),T.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},T.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,65535,0),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ee(this,e,t,1),t+2},T.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,65535,0),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ee(this,e,t,0),t+2},T.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,4294967295,0),T.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):te(this,e,t,1),t+4},T.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,4294967295,0),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):te(this,e,t,0),t+4},T.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);J(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},T.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);J(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},T.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,1,127,-128),T.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},T.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,32767,-32768),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ee(this,e,t,1),t+2},T.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,32767,-32768),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ee(this,e,t,0),t+2},T.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,2147483647,-2147483648),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):te(this,e,t,1),t+4},T.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):te(this,e,t,0),t+4},T.prototype.writeFloatLE=function(e,t,r){return ne(this,e,t,1,r)},T.prototype.writeFloatBE=function(e,t,r){return ne(this,e,t,0,r)},T.prototype.writeDoubleLE=function(e,t,r){return oe(this,e,t,1,r)},T.prototype.writeDoubleBE=function(e,t,r){return oe(this,e,t,0,r)},T.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||!T.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},T.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&&!T.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=L(e)?e:ie(new T(e,n).toString()),a=i.length;for(s=0;s<r-t;++s)this[s+t]=i[s%a]}return this};var se=/[^+\/0-9A-Za-z-_]/g;function ie(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 ae(e){return function(e){var t,r,n,o,s,i;g||y();var a=e.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s="="===e[a-2]?2:"="===e[a-1]?1:0,i=new m(3*a/4-s),n=s>0?a-4:a;var u=0;for(t=0,r=0;t<n;t+=4,r+=3)o=p[e.charCodeAt(t)]<<18|p[e.charCodeAt(t+1)]<<12|p[e.charCodeAt(t+2)]<<6|p[e.charCodeAt(t+3)],i[u++]=o>>16&255,i[u++]=o>>8&255,i[u++]=255&o;return 2===s?(o=p[e.charCodeAt(t)]<<2|p[e.charCodeAt(t+1)]>>4,i[u++]=255&o):1===s&&(o=p[e.charCodeAt(t)]<<10|p[e.charCodeAt(t+1)]<<4|p[e.charCodeAt(t+2)]>>2,i[u++]=o>>8&255,i[u++]=255&o),i}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(se,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function ue(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 ce(e){return null!=e&&(!!e._isBuffer||le(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&le(e.slice(0,0))}(e))}function le(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var de=Object.freeze({__proto__:null,Buffer:T,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),T.alloc(+e)},isBuffer:ce,kMaxLength:x}),he="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function pe(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 me={},ge={};class ye{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 we(e,t){return t.property?e+"["+t.property+"]":e}ge.Layout=ye,ge.nameWithProperty=we,ge.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 ye))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 ve extends ye{isCount(){throw new Error("ExternalLayout is abstract")}}class be extends ve{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 Ie extends ve{constructor(e,t,r){if(!(e instanceof ye))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 Ae||this.layout instanceof Ee}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 Ae extends ye{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 Ee extends ye{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 xe extends ye{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 Me extends ye{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 _e=Math.pow(2,32);function Te(e){const t=Math.floor(e/_e);return{hi32:t,lo32:e-t*_e}}function ke(e,t){return e*_e+t}class Se extends ye{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ke(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class Ce extends ye{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ke(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Pe extends ye{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return ke(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Be extends ye{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),ke(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Le extends ye{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 Ne extends ye{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 Oe extends ye{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 Ue extends ye{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 Re extends ye{constructor(e,t,r){if(!(e instanceof ye))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof ve&&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 ve)&&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 ve&&(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 ve&&(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 ve&&this.count.encode(e.length,t,r),o}}class De extends ye{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof ye),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 Ve{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class qe extends Ve{constructor(e,t){if(!(e instanceof ve&&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 Fe extends ye{constructor(e,t,r){const n=e instanceof Ae||e instanceof Ee;if(n)e=new qe(new Ie(e));else if(e instanceof ve&&e.isCount())e=new qe(e);else if(!(e instanceof Ve))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof ye))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 We(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 We extends ye{constructor(e,t,r,n){if(!(e instanceof Fe))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 ye))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 He(e){return 0>e&&(e+=4294967296),e}class $e extends ye{constructor(e,t,r){if(!(e instanceof Ae||e instanceof Ee))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=He(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 je(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new ze(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 je{constructor(e,t,r){if(!(e instanceof $e))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=He(this.valueMask<<this.start),this.property=r}decode(){return He(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==He(e&this.valueMask))throw new TypeError(we("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=He(e<<this.start);this.container._packedSetValue(He(t&~this.wordMask)|r)}}let ze=class extends je{constructor(e,t){super(e,1,t)}decode(e,t){return!!je.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),je.prototype.encode.call(this,e)}};class Ke extends ye{constructor(e,t){if(!(e instanceof ve&&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 ve||(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 ve&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(we("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 ve&&this.length.encode(n,t,r),n}}class Ze extends ye{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 Ye extends ye{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 Ge extends ye{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}ge.ExternalLayout=ve,ge.GreedyCount=be,ge.OffsetLayout=Ie,ge.UInt=Ae,ge.UIntBE=Ee,ge.Int=xe,ge.IntBE=Me,ge.Float=Le,ge.FloatBE=Ne,ge.Double=Oe,ge.DoubleBE=Ue,ge.Sequence=Re,ge.Structure=De,ge.UnionDiscriminator=Ve,ge.UnionLayoutDiscriminator=qe,ge.Union=Fe,ge.VariantLayout=We,ge.BitStructure=$e,ge.BitField=je,ge.Boolean=ze,ge.Blob=Ke,ge.CString=Ze,ge.UTF8=Ye,ge.Constant=Ge,ge.greedy=(e,t)=>new be(e,t),ge.offset=(e,t,r)=>new Ie(e,t,r),ge.u8=e=>new Ae(1,e),ge.u16=e=>new Ae(2,e),ge.u24=e=>new Ae(3,e),ge.u32=e=>new Ae(4,e),ge.u40=e=>new Ae(5,e),ge.u48=e=>new Ae(6,e),ge.nu64=e=>new Se(e),ge.u16be=e=>new Ee(2,e),ge.u24be=e=>new Ee(3,e),ge.u32be=e=>new Ee(4,e),ge.u40be=e=>new Ee(5,e),ge.u48be=e=>new Ee(6,e),ge.nu64be=e=>new Ce(e),ge.s8=e=>new xe(1,e),ge.s16=e=>new xe(2,e),ge.s24=e=>new xe(3,e),ge.s32=e=>new xe(4,e),ge.s40=e=>new xe(5,e),ge.s48=e=>new xe(6,e),ge.ns64=e=>new Pe(e),ge.s16be=e=>new Me(2,e),ge.s24be=e=>new Me(3,e),ge.s32be=e=>new Me(4,e),ge.s40be=e=>new Me(5,e),ge.s48be=e=>new Me(6,e),ge.ns64be=e=>new Be(e),ge.f32=e=>new Le(e),ge.f32be=e=>new Ne(e),ge.f64=e=>new Oe(e),ge.f64be=e=>new Ue(e),ge.struct=(e,t,r)=>new De(e,t,r),ge.bits=(e,t,r)=>new $e(e,t,r),ge.seq=(e,t,r)=>new Re(e,t,r),ge.union=(e,t,r)=>new Fe(e,t,r),ge.unionLayoutDiscriminator=(e,t)=>new qe(e,t),ge.blob=(e,t)=>new Ke(e,t),ge.cstr=e=>new Ze(e),ge.utf8=(e,t)=>new Ye(e,t),ge.const=(e,t)=>new Ge(e,t);var Xe={exports:{}},Qe=pe(de);!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 Xe?Xe.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],f=[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 p(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),f=Math.max(0,c-e.length+1);f<=h;f++){var p=c-f|0;l+=(i=(o=0|e.words[p])*(s=0|t.words[f])+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=f[e];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var m=p.modrn(l).toString(e);n=(p=p.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,f=0|i[1],p=8191&f,m=f>>>13,g=0|i[2],y=8191&g,w=g>>>13,v=0|i[3],b=8191&v,I=v>>>13,A=0|i[4],E=8191&A,x=A>>>13,M=0|i[5],_=8191&M,T=M>>>13,k=0|i[6],S=8191&k,C=k>>>13,P=0|i[7],B=8191&P,L=P>>>13,N=0|i[8],O=8191&N,U=N>>>13,R=0|i[9],D=8191&R,V=R>>>13,q=0|a[0],F=8191&q,W=q>>>13,H=0|a[1],$=8191&H,j=H>>>13,z=0|a[2],K=8191&z,Z=z>>>13,Y=0|a[3],G=8191&Y,X=Y>>>13,Q=0|a[4],J=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,fe=0|a[9],pe=8191&fe,me=fe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(c+(n=Math.imul(d,F))|0)+((8191&(o=(o=Math.imul(d,W))+Math.imul(h,F)|0))<<13)|0;c=((s=Math.imul(h,W))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(p,F),o=(o=Math.imul(p,W))+Math.imul(m,F)|0,s=Math.imul(m,W);var ye=(c+(n=n+Math.imul(d,$)|0)|0)+((8191&(o=(o=o+Math.imul(d,j)|0)+Math.imul(h,$)|0))<<13)|0;c=((s=s+Math.imul(h,j)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,F),o=(o=Math.imul(y,W))+Math.imul(w,F)|0,s=Math.imul(w,W),n=n+Math.imul(p,$)|0,o=(o=o+Math.imul(p,j)|0)+Math.imul(m,$)|0,s=s+Math.imul(m,j)|0;var we=(c+(n=n+Math.imul(d,K)|0)|0)+((8191&(o=(o=o+Math.imul(d,Z)|0)+Math.imul(h,K)|0))<<13)|0;c=((s=s+Math.imul(h,Z)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(b,F),o=(o=Math.imul(b,W))+Math.imul(I,F)|0,s=Math.imul(I,W),n=n+Math.imul(y,$)|0,o=(o=o+Math.imul(y,j)|0)+Math.imul(w,$)|0,s=s+Math.imul(w,j)|0,n=n+Math.imul(p,K)|0,o=(o=o+Math.imul(p,Z)|0)+Math.imul(m,K)|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,X)|0)+Math.imul(h,G)|0))<<13)|0;c=((s=s+Math.imul(h,X)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(E,F),o=(o=Math.imul(E,W))+Math.imul(x,F)|0,s=Math.imul(x,W),n=n+Math.imul(b,$)|0,o=(o=o+Math.imul(b,j)|0)+Math.imul(I,$)|0,s=s+Math.imul(I,j)|0,n=n+Math.imul(y,K)|0,o=(o=o+Math.imul(y,Z)|0)+Math.imul(w,K)|0,s=s+Math.imul(w,Z)|0,n=n+Math.imul(p,G)|0,o=(o=o+Math.imul(p,X)|0)+Math.imul(m,G)|0,s=s+Math.imul(m,X)|0;var be=(c+(n=n+Math.imul(d,J)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(h,J)|0))<<13)|0;c=((s=s+Math.imul(h,ee)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(_,F),o=(o=Math.imul(_,W))+Math.imul(T,F)|0,s=Math.imul(T,W),n=n+Math.imul(E,$)|0,o=(o=o+Math.imul(E,j)|0)+Math.imul(x,$)|0,s=s+Math.imul(x,j)|0,n=n+Math.imul(b,K)|0,o=(o=o+Math.imul(b,Z)|0)+Math.imul(I,K)|0,s=s+Math.imul(I,Z)|0,n=n+Math.imul(y,G)|0,o=(o=o+Math.imul(y,X)|0)+Math.imul(w,G)|0,s=s+Math.imul(w,X)|0,n=n+Math.imul(p,J)|0,o=(o=o+Math.imul(p,ee)|0)+Math.imul(m,J)|0,s=s+Math.imul(m,ee)|0;var Ie=(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)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(S,F),o=(o=Math.imul(S,W))+Math.imul(C,F)|0,s=Math.imul(C,W),n=n+Math.imul(_,$)|0,o=(o=o+Math.imul(_,j)|0)+Math.imul(T,$)|0,s=s+Math.imul(T,j)|0,n=n+Math.imul(E,K)|0,o=(o=o+Math.imul(E,Z)|0)+Math.imul(x,K)|0,s=s+Math.imul(x,Z)|0,n=n+Math.imul(b,G)|0,o=(o=o+Math.imul(b,X)|0)+Math.imul(I,G)|0,s=s+Math.imul(I,X)|0,n=n+Math.imul(y,J)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(p,re)|0,o=(o=o+Math.imul(p,ne)|0)+Math.imul(m,re)|0,s=s+Math.imul(m,ne)|0;var Ae=(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)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(B,F),o=(o=Math.imul(B,W))+Math.imul(L,F)|0,s=Math.imul(L,W),n=n+Math.imul(S,$)|0,o=(o=o+Math.imul(S,j)|0)+Math.imul(C,$)|0,s=s+Math.imul(C,j)|0,n=n+Math.imul(_,K)|0,o=(o=o+Math.imul(_,Z)|0)+Math.imul(T,K)|0,s=s+Math.imul(T,Z)|0,n=n+Math.imul(E,G)|0,o=(o=o+Math.imul(E,X)|0)+Math.imul(x,G)|0,s=s+Math.imul(x,X)|0,n=n+Math.imul(b,J)|0,o=(o=o+Math.imul(b,ee)|0)+Math.imul(I,J)|0,s=s+Math.imul(I,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(p,se)|0,o=(o=o+Math.imul(p,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(O,F),o=(o=Math.imul(O,W))+Math.imul(U,F)|0,s=Math.imul(U,W),n=n+Math.imul(B,$)|0,o=(o=o+Math.imul(B,j)|0)+Math.imul(L,$)|0,s=s+Math.imul(L,j)|0,n=n+Math.imul(S,K)|0,o=(o=o+Math.imul(S,Z)|0)+Math.imul(C,K)|0,s=s+Math.imul(C,Z)|0,n=n+Math.imul(_,G)|0,o=(o=o+Math.imul(_,X)|0)+Math.imul(T,G)|0,s=s+Math.imul(T,X)|0,n=n+Math.imul(E,J)|0,o=(o=o+Math.imul(E,ee)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,ee)|0,n=n+Math.imul(b,re)|0,o=(o=o+Math.imul(b,ne)|0)+Math.imul(I,re)|0,s=s+Math.imul(I,ne)|0,n=n+Math.imul(y,se)|0,o=(o=o+Math.imul(y,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,n=n+Math.imul(p,ue)|0,o=(o=o+Math.imul(p,ce)|0)+Math.imul(m,ue)|0,s=s+Math.imul(m,ce)|0;var xe=(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)+(xe>>>26)|0,xe&=67108863,n=Math.imul(D,F),o=(o=Math.imul(D,W))+Math.imul(V,F)|0,s=Math.imul(V,W),n=n+Math.imul(O,$)|0,o=(o=o+Math.imul(O,j)|0)+Math.imul(U,$)|0,s=s+Math.imul(U,j)|0,n=n+Math.imul(B,K)|0,o=(o=o+Math.imul(B,Z)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,Z)|0,n=n+Math.imul(S,G)|0,o=(o=o+Math.imul(S,X)|0)+Math.imul(C,G)|0,s=s+Math.imul(C,X)|0,n=n+Math.imul(_,J)|0,o=(o=o+Math.imul(_,ee)|0)+Math.imul(T,J)|0,s=s+Math.imul(T,ee)|0,n=n+Math.imul(E,re)|0,o=(o=o+Math.imul(E,ne)|0)+Math.imul(x,re)|0,s=s+Math.imul(x,ne)|0,n=n+Math.imul(b,se)|0,o=(o=o+Math.imul(b,ie)|0)+Math.imul(I,se)|0,s=s+Math.imul(I,ie)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(p,de)|0,o=(o=o+Math.imul(p,he)|0)+Math.imul(m,de)|0,s=s+Math.imul(m,he)|0;var Me=(c+(n=n+Math.imul(d,pe)|0)|0)+((8191&(o=(o=o+Math.imul(d,me)|0)+Math.imul(h,pe)|0))<<13)|0;c=((s=s+Math.imul(h,me)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,$),o=(o=Math.imul(D,j))+Math.imul(V,$)|0,s=Math.imul(V,j),n=n+Math.imul(O,K)|0,o=(o=o+Math.imul(O,Z)|0)+Math.imul(U,K)|0,s=s+Math.imul(U,Z)|0,n=n+Math.imul(B,G)|0,o=(o=o+Math.imul(B,X)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,X)|0,n=n+Math.imul(S,J)|0,o=(o=o+Math.imul(S,ee)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,ee)|0,n=n+Math.imul(_,re)|0,o=(o=o+Math.imul(_,ne)|0)+Math.imul(T,re)|0,s=s+Math.imul(T,ne)|0,n=n+Math.imul(E,se)|0,o=(o=o+Math.imul(E,ie)|0)+Math.imul(x,se)|0,s=s+Math.imul(x,ie)|0,n=n+Math.imul(b,ue)|0,o=(o=o+Math.imul(b,ce)|0)+Math.imul(I,ue)|0,s=s+Math.imul(I,ce)|0,n=n+Math.imul(y,de)|0,o=(o=o+Math.imul(y,he)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,he)|0;var _e=(c+(n=n+Math.imul(p,pe)|0)|0)+((8191&(o=(o=o+Math.imul(p,me)|0)+Math.imul(m,pe)|0))<<13)|0;c=((s=s+Math.imul(m,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(D,K),o=(o=Math.imul(D,Z))+Math.imul(V,K)|0,s=Math.imul(V,Z),n=n+Math.imul(O,G)|0,o=(o=o+Math.imul(O,X)|0)+Math.imul(U,G)|0,s=s+Math.imul(U,X)|0,n=n+Math.imul(B,J)|0,o=(o=o+Math.imul(B,ee)|0)+Math.imul(L,J)|0,s=s+Math.imul(L,ee)|0,n=n+Math.imul(S,re)|0,o=(o=o+Math.imul(S,ne)|0)+Math.imul(C,re)|0,s=s+Math.imul(C,ne)|0,n=n+Math.imul(_,se)|0,o=(o=o+Math.imul(_,ie)|0)+Math.imul(T,se)|0,s=s+Math.imul(T,ie)|0,n=n+Math.imul(E,ue)|0,o=(o=o+Math.imul(E,ce)|0)+Math.imul(x,ue)|0,s=s+Math.imul(x,ce)|0,n=n+Math.imul(b,de)|0,o=(o=o+Math.imul(b,he)|0)+Math.imul(I,de)|0,s=s+Math.imul(I,he)|0;var Te=(c+(n=n+Math.imul(y,pe)|0)|0)+((8191&(o=(o=o+Math.imul(y,me)|0)+Math.imul(w,pe)|0))<<13)|0;c=((s=s+Math.imul(w,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(D,G),o=(o=Math.imul(D,X))+Math.imul(V,G)|0,s=Math.imul(V,X),n=n+Math.imul(O,J)|0,o=(o=o+Math.imul(O,ee)|0)+Math.imul(U,J)|0,s=s+Math.imul(U,ee)|0,n=n+Math.imul(B,re)|0,o=(o=o+Math.imul(B,ne)|0)+Math.imul(L,re)|0,s=s+Math.imul(L,ne)|0,n=n+Math.imul(S,se)|0,o=(o=o+Math.imul(S,ie)|0)+Math.imul(C,se)|0,s=s+Math.imul(C,ie)|0,n=n+Math.imul(_,ue)|0,o=(o=o+Math.imul(_,ce)|0)+Math.imul(T,ue)|0,s=s+Math.imul(T,ce)|0,n=n+Math.imul(E,de)|0,o=(o=o+Math.imul(E,he)|0)+Math.imul(x,de)|0,s=s+Math.imul(x,he)|0;var ke=(c+(n=n+Math.imul(b,pe)|0)|0)+((8191&(o=(o=o+Math.imul(b,me)|0)+Math.imul(I,pe)|0))<<13)|0;c=((s=s+Math.imul(I,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,ee))+Math.imul(V,J)|0,s=Math.imul(V,ee),n=n+Math.imul(O,re)|0,o=(o=o+Math.imul(O,ne)|0)+Math.imul(U,re)|0,s=s+Math.imul(U,ne)|0,n=n+Math.imul(B,se)|0,o=(o=o+Math.imul(B,ie)|0)+Math.imul(L,se)|0,s=s+Math.imul(L,ie)|0,n=n+Math.imul(S,ue)|0,o=(o=o+Math.imul(S,ce)|0)+Math.imul(C,ue)|0,s=s+Math.imul(C,ce)|0,n=n+Math.imul(_,de)|0,o=(o=o+Math.imul(_,he)|0)+Math.imul(T,de)|0,s=s+Math.imul(T,he)|0;var Se=(c+(n=n+Math.imul(E,pe)|0)|0)+((8191&(o=(o=o+Math.imul(E,me)|0)+Math.imul(x,pe)|0))<<13)|0;c=((s=s+Math.imul(x,me)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(D,re),o=(o=Math.imul(D,ne))+Math.imul(V,re)|0,s=Math.imul(V,ne),n=n+Math.imul(O,se)|0,o=(o=o+Math.imul(O,ie)|0)+Math.imul(U,se)|0,s=s+Math.imul(U,ie)|0,n=n+Math.imul(B,ue)|0,o=(o=o+Math.imul(B,ce)|0)+Math.imul(L,ue)|0,s=s+Math.imul(L,ce)|0,n=n+Math.imul(S,de)|0,o=(o=o+Math.imul(S,he)|0)+Math.imul(C,de)|0,s=s+Math.imul(C,he)|0;var Ce=(c+(n=n+Math.imul(_,pe)|0)|0)+((8191&(o=(o=o+Math.imul(_,me)|0)+Math.imul(T,pe)|0))<<13)|0;c=((s=s+Math.imul(T,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(D,se),o=(o=Math.imul(D,ie))+Math.imul(V,se)|0,s=Math.imul(V,ie),n=n+Math.imul(O,ue)|0,o=(o=o+Math.imul(O,ce)|0)+Math.imul(U,ue)|0,s=s+Math.imul(U,ce)|0,n=n+Math.imul(B,de)|0,o=(o=o+Math.imul(B,he)|0)+Math.imul(L,de)|0,s=s+Math.imul(L,he)|0;var Pe=(c+(n=n+Math.imul(S,pe)|0)|0)+((8191&(o=(o=o+Math.imul(S,me)|0)+Math.imul(C,pe)|0))<<13)|0;c=((s=s+Math.imul(C,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(D,ue),o=(o=Math.imul(D,ce))+Math.imul(V,ue)|0,s=Math.imul(V,ce),n=n+Math.imul(O,de)|0,o=(o=o+Math.imul(O,he)|0)+Math.imul(U,de)|0,s=s+Math.imul(U,he)|0;var Be=(c+(n=n+Math.imul(B,pe)|0)|0)+((8191&(o=(o=o+Math.imul(B,me)|0)+Math.imul(L,pe)|0))<<13)|0;c=((s=s+Math.imul(L,me)|0)+(o>>>13)|0)+(Be>>>26)|0,Be&=67108863,n=Math.imul(D,de),o=(o=Math.imul(D,he))+Math.imul(V,de)|0,s=Math.imul(V,he);var Le=(c+(n=n+Math.imul(O,pe)|0)|0)+((8191&(o=(o=o+Math.imul(O,me)|0)+Math.imul(U,pe)|0))<<13)|0;c=((s=s+Math.imul(U,me)|0)+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863;var Ne=(c+(n=Math.imul(D,pe))|0)+((8191&(o=(o=Math.imul(D,me))+Math.imul(V,pe)|0))<<13)|0;return c=((s=Math.imul(V,me))+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=ve,u[4]=be,u[5]=Ie,u[6]=Ae,u[7]=Ee,u[8]=xe,u[9]=Me,u[10]=_e,u[11]=Te,u[12]=ke,u[13]=Se,u[14]=Ce,u[15]=Pe,u[16]=Be,u[17]=Le,u[18]=Ne,0!==c&&(u[19]=c,r.length++),r};function g(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,o=0,s=0;s<r.length-1;s++){var i=o;o=0;for(var a=67108863&n,u=Math.min(s,t.length-1),c=Math.max(0,s-e.length+1);c<=u;c++){var l=s-c,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 y(e,t,r){return g(e,t,r)}Math.imul||(m=p),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?p(this,e,t):r<1024?g(this,e,t):y(this,e,t)},o.prototype.mul=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),y(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){var t=e<0;t&&(e=-e),r("number"==typeof e),r(e<67108864);for(var n=0,o=0;o<this.length;o++){var s=(0|this.words[o])*e,i=(67108863&s)+(67108863&n);n>>=26,n+=s/67108864|0,n+=i>>>26,this.words[o]=67108863&i}return 0!==n&&(this.words[o]=n,this.length++),t?this.ineg():this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=e.words[n]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n<t.length&&0===t[n];n++,r=r.sqr());if(++n<t.length)for(var s=r.sqr();n<t.length;n++,s=s.sqr())0!==t[n]&&(r=r.mul(s));return r},o.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,n=e%26,o=(e-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var i=0;for(t=0;t<this.length;t++){var a=this.words[t]&s,u=(0|this.words[t])-a<<n;this.words[t]=u|i,i=a>>>26-n}i&&(this.words[t]=i,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(e){return r(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,n){var o;r("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var s=e%26,i=Math.min((e-s)/26,this.length),a=67108863^67108863>>>s<<s,u=n;if(o-=i,o=Math.max(0,o),u){for(var c=0;c<i;c++)u.words[c]=this.words[c];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,c=0;c<this.length;c++)this.words[c]=this.words[c+i];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var 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,f=1;0==(t.words[0]&f)&&h<26;++h,f<<=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 p=0,m=1;0==(n.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(n.iushrn(p);p-- >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 x(e)},o.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var w={k256:null,p224:null,p192:null,p25519:null};function v(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function I(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function x(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function M(e){x.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},v.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(e,t){e.iushrn(this.n,0,t)},v.prototype.imulK=function(e){return e.imul(this.k)},n(b,v),b.prototype.split=function(e,t){for(var r=4194303,n=Math.min(e.length,9),o=0;o<n;o++)t.words[o]=e.words[o];if(t.length=n,e.length<=9)return e.words[0]=0,void(e.length=1);var s=e.words[9];for(t.words[t.length++]=s&r,o=10;o<e.length;o++){var i=0|e.words[o];e.words[o-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,e.words[o-10]=s,0===s&&e.length>10?e.length-=10:e.length-=9},b.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(I,v),n(A,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 b;else if("p224"===e)t=new I;else if("p192"===e)t=new A;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new E}return w[e]=t,t},x.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},x.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")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.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)},x.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},x.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)},x.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},x.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},x.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},x.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.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)),f=this.pow(e,s),p=i;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<p);var y=this.pow(d,new o(1).iushln(p-g-1));h=h.redMul(y),d=y.redSqr(),f=f.redMul(d),p=g}return h},x.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},x.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},x.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},x.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new M(e)},n(M,x),M.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},M.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},M.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},M.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},M.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,he);var Je,et,tt=Xe.exports,rt=fe(tt);!function(t){var r=he&&he.__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=ge,o=e,s=r(tt);var i=ge;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 f(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=f,t.str=function(e){return new c(f(),(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 p 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 p(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)}}(me),function(e){e[e.StateV1=1]="StateV1",e[e.AddressV1=2]="AddressV1",e[e.StateV2=3]="StateV2",e[e.AddressV2=4]="AddressV2"}(Je||(Je={})),function(e){e.V1="V1",e.V2="V2"}(et||(et={}));const nt={version:'"V2"',isV2:()=>"V2"===nt.version.replace(/['"]/g,"").toUpperCase()},ot=e=>nt.isV2()?`${e}V2`:e,st=new rt("21888242871839275222246405745257275088548364400416034343698204186575808495617"),it=new rt("452312848583266388373324160190187140051835877600158453279131187530910662655"),at=[2,64,66,15,0],ut=T.from([26,16,169,7,21,202,242,25]),ct=T.from([49,212,191,129,39,194,43,196]),lt=T.from([86,47,163,166,21,223,92,8]),dt=T.from([228,34,128,84,47,139,86,240]),ht=T.from([180,143,159,153,35,46,248,163]),ft="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",pt="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",mt="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",gt=()=>new t("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),yt=()=>t.findProgramAddressSync([T.from("cpi_authority")],new t(pt))[0],wt=()=>[new t(gt()),new t(ft),new t(mt),new t(yt())],vt=()=>({registeredProgramPda:new t(gt()),noopProgram:new t(ft),accountCompressionProgram:new t(mt),accountCompressionAuthority:new t(yt()),cpiSignatureAccount:null}),bt=()=>({mainnet:[{stateTreeLookupTable:new t(St),nullifyLookupTable:new t(Ct)}],devnet:[{stateTreeLookupTable:new t(Pt),nullifyLookupTable:new t(Bt)}]}),It=e=>e.includes("localhost")||e.includes("127.0.0.1"),At=()=>xt(),Et=()=>nt.isV2()?xt():{tree:new t(Ut),queue:new t(Rt),cpiContext:void 0,treeType:Je.AddressV1,nextTreeInfo:null},xt=()=>({tree:new t(rr),queue:new t(rr),cpiContext:void 0,treeType:Je.AddressV2,nextTreeInfo:null}),Mt=()=>({nullifierQueue:new t(Lt),merkleTree:new t(Ot),merkleTreeHeight:ar,addressTree:new t(Ut),addressQueue:new t(Rt)}),_t=()=>({nullifierQueue2:new t(Vt),merkleTree2:new t(Dt)}),Tt=new t("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),kt=Tt,St="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",Ct="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",Pt="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",Bt="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",Lt="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",Nt="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",Ot="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",Ut="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",Rt="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",Dt="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Vt="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",qt="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",Ft="bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU",Wt="oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto",Ht="cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y",$t="bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi",jt="oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg",zt="cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B",Kt="bmt3ccLd4bqSVZVeCJnH1F6C8jNygAhaDfxDwePyyGb",Zt="oq3AxjekBWgo64gpauB6QtuZNesuv19xrhaC1ZM1THQ",Yt="cpi3mbwMpSX8FAGMZVP85AwxqCaQMfEk9Em1v8QK9Rf",Gt="bmt4d3p1a4YQgk9PeZv5s4DBUmbF5NxqYpk9HGjQsd8",Xt="oq4ypwvVGzCUMoiKKHWh4S1SgZJ9vCvKpcz6RT6A8dq",Qt="cpi4yyPDc4bCgHAnsenunGA8Y77j3XEDyjgfyCKgcoc",Jt="bmt5yU97jC88YXTuSukYHa8Z5Bi2ZDUtmzfkDTA2mG2",er="oq5oh5ZR3yGomuQgFduNDzjtGvVWfDRGLuDVjv9a96P",tr="cpi5ZTjdgYpZ1Xr7B1cMLLUE81oTtJbNNAyKary2nV6",rr="amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx",nr=Ft,or=Wt,sr=()=>{const e=[[Ft,Wt,Ht],[$t,jt,zt],[Kt,Zt,Yt],[Gt,Xt,Qt],[Jt,er,tr]],r=rr,n=[[Ot,Lt,Nt],[Dt,Vt,qt]].map((([e,r,n])=>({tree:new t(e),queue:new t(r),cpiContext:new t(n),treeType:Je.StateV1,nextTreeInfo:null}))),o=e.map((([e,r,n])=>({tree:new t(e),queue:new t(r),cpiContext:new t(n),treeType:Je.StateV2,nextTreeInfo:null}))),s={tree:new t(r),queue:new t(r),cpiContext:t.default,treeType:Je.AddressV2,nextTreeInfo:null};return nt.isV2()?[...n,...o,s]:n},ir={commitment:"confirmed",preflightCommitment:"confirmed"},ar=26,ur=2800,cr=20,lr=10,dr=new rt(Math.floor(2**ar*.95)),hr=nt.isV2()?new rt(1):new rt(300),fr=(nt.isV2(),new rt(392)),pr=new rt(5e3),mr=new rt(5e3),gr=new rt(1e4);var yr=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 wr=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return wr(yr.decode(e))}return function(e){if(e.gte(st))throw new Error("Value is too large. Max <254 bits");return e}(new rt(e,t))};function vr(e){const t=wr(e).toArrayLike(T,void 0,32);return yr.encode(new Uint8Array(t))}const br=(e,t,r)=>e instanceof Uint8Array&&!(e instanceof T)?new rt(T.from(e),t,r):new rt(e,t,r),Ir=(e,t,r,n)=>({treeInfo:e,outputStateTreeIndex:t,address:r??null,lamports:n??null}),Ar=(e,t,r,n)=>({owner:e,lamports:t??new rt(0),address:n??null,data:r??null}),Er=(e,t,r,n,o)=>({...e,owner:t,lamports:r??new rt(0),address:o??null,data:n??null,readOnly:0}),xr=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n}),Mr=me.struct([me.publicKey("owner"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address"),me.option(me.struct([me.array(me.u8(),8,"discriminator"),me.vecU8("data"),me.array(me.u8(),32,"dataHash")]),"data")],"compressedAccount"),_r=me.struct([me.u8("merkleTreePubkeyIndex"),me.u8("queuePubkeyIndex"),me.u32("leafIndex"),me.bool("proveByIndex")],"merkleContext"),Tr=me.struct([me.array(me.u8(),32,"seed"),me.u8("addressQueueAccountIndex"),me.u8("addressMerkleTreeAccountIndex"),me.u16("addressMerkleTreeRootIndex")],"newAddressParams"),kr=me.struct([me.option(me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")]),"proof"),me.vec(me.struct([Mr,_r,me.u16("rootIndex"),me.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),me.vec(me.struct([Mr,me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.option(me.u64(),"relayFee"),me.vec(Tr,"newAddressParams"),me.option(me.u64(),"compressOrDecompressLamports"),me.bool("isCompress")]);function Sr(e){const t=T.alloc(1e3),r=kr.encode(e,t),n=T.from(new Uint8Array(t.slice(0,r))),o=T.alloc(4);return o.writeUInt32LE(r,0),T.concat([new Uint8Array(ut),new Uint8Array(o),new Uint8Array(n)])}const Cr=me.struct([me.option(me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")]),"proof"),me.vec(Tr,"newAddressParams"),me.vec(me.struct([Mr,_r,me.u16("rootIndex"),me.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),me.vec(me.struct([Mr,me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.option(me.u64(),"relayFee"),me.option(me.u64(),"compressOrDecompressLamports"),me.bool("isCompress"),me.option(me.struct([me.bool("set_context"),me.bool("first_set_context"),me.u8("cpi_context_account_index")]),"compressedCpiContext")]),Pr=me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")],"compressedProof"),Br=me.struct([me.bool("set_context"),me.bool("first_set_context"),me.u8("cpi_context_account_index")],"compressedCpiContext"),Lr=me.struct([me.array(me.u8(),32,"seed"),me.u8("address_queue_account_index"),me.u8("address_merkle_tree_account_index"),me.u16("address_merkle_tree_root_index"),me.bool("assigned_to_account"),me.u8("assigned_account_index")],"newAddressParamsAssignedPacked"),Nr=me.struct([me.u8("merkle_tree_pubkey_index"),me.u8("queue_pubkey_index"),me.u32("leaf_index"),me.bool("prove_by_index")],"packedMerkleContext"),Or=me.struct([me.array(me.u8(),8,"discriminator"),me.array(me.u8(),32,"data_hash"),Nr,me.u16("root_index"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address")],"inAccount"),Ur=me.struct([me.array(me.u8(),32,"address"),me.u16("address_merkle_tree_root_index"),me.u8("address_merkle_tree_account_index")],"packedReadOnlyAddress"),Rr=me.struct([me.array(me.u8(),32,"account_hash"),Nr,me.u16("root_index")],"packedReadOnlyCompressedAccount"),Dr=me.struct([me.u8("mode"),me.u8("bump"),me.publicKey("invoking_program_id"),me.u64("compress_or_decompress_lamports"),me.bool("is_compress"),me.bool("with_cpi_context"),me.bool("with_transaction_hash"),Br,me.option(Pr,"proof"),me.vec(Lr,"new_address_params"),me.vec(Or,"input_compressed_accounts"),me.vec(me.struct([Mr,me.u8("merkleTreeIndex")]),"output_compressed_accounts"),me.vec(Ur,"read_only_addresses"),me.vec(Rr,"read_only_accounts")]);function Vr(e){return Dr.decode(e.slice(lt.length))}function qr(e){return kr.decode(e.slice(ut.length+4))}function Fr(e){return Cr.decode(e.slice(ct.length+4))}const Wr=e=>{const t=Qo.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:u??t,isSigner:0,isWritable:null!==u},{pubkey:c??t,isSigner:0,isWritable:1},{pubkey:l,isSigner:0,isWritable:0}]},Hr=me.struct([me.vec(me.array(me.u8(),32),"inputCompressedAccountHashes"),me.vec(me.array(me.u8(),32),"outputCompressedAccountHashes"),me.vec(me.struct([me.struct([me.publicKey("owner"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address"),me.option(me.struct([me.array(me.u8(),8,"discriminator"),me.vecU8("data"),me.array(me.u8(),32,"dataHash")]),"data")],"compressedAccount"),me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.vec(me.u32(),"outputLeafIndices"),me.vec(me.struct([me.publicKey("tree_pubkey"),me.publicKey("queue_pubkey"),me.u64("tree_type"),me.u64("seq")]),"sequenceNumbers"),me.option(me.u64(),"relayFee"),me.bool("isCompress"),me.option(me.u64(),"compressOrDecompressLamports"),me.vec(me.publicKey(),"pubkeyArray"),me.option(me.vecU8(),"message")]);function $r(e){const t=T.alloc(1e3),r=Hr.encode(e,t);return t.slice(0,r)}function jr(e){return Hr.decode(e)}const zr=me.struct([me.u8("is_invoked_by_program"),me.u8("bump"),me.u8("num_queues"),me.u8("num_output_queues"),me.u8("start_output_appends"),me.u8("num_address_queues"),me.array(me.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),Kr=me.struct([me.u8("index"),me.array(me.u8(),32,"leaf")],"appendLeavesInput"),Zr=me.struct([me.array(me.u8(),32,"account_hash"),me.u32("leaf_index"),me.u8("prove_by_index"),me.u8("tree_index"),me.u8("queue_index")],"insertNullifierInput"),Yr=me.struct([me.array(me.u8(),32,"address"),me.u8("tree_index"),me.u8("queue_index")],"insertAddressInput"),Gr=me.struct([me.publicKey("tree_pubkey"),me.publicKey("queue_pubkey"),me.u64("tree_type"),me.u64("seq")],"merkleTreeSequenceNumber");function Xr(e){let t=0;const r=zr.decode(e,t);t+=zr.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=Kr.decode(e,t);o.push(r),t+=Kr.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=Zr.decode(e,t);i.push(r),t+=Zr.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=Yr.decode(e,t);u.push(r),t+=Yr.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=Gr.decode(e,t);l.push(r),t+=Gr.span}const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)Gr.decode(e,t),t+=Gr.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)Gr.decode(e,t),t+=Gr.span;const f=e.readUInt8(t);t+=1;const p=[];for(let r=0;r<f;r++){const r=me.u32().decode(e,t);p.push(r),t+=4}return{meta:r,leaves:o,nullifiers:i,addresses:u,sequence_numbers:l,output_leaf_indices:p}}function Qr(e,r,n){const o=e=>Array.from(e instanceof T?new Uint8Array(e):e);return{inputCompressedAccountHashes:e.nullifiers.map((e=>o(e.account_hash))),outputCompressedAccountHashes:e.leaves.map((e=>o(e.leaf))),outputCompressedAccounts:e.leaves.map(((e,r)=>({compressedAccount:{owner:new t(n?.outputCompressedAccounts[r]?.compressedAccount.owner||t.default),lamports:br(n?.outputCompressedAccounts[r]?.compressedAccount.lamports||0),address:n?.outputCompressedAccounts[r].compressedAccount.address,data:n?.outputCompressedAccounts[r]?.compressedAccount.data?{discriminator:o(T.from(n.outputCompressedAccounts[r].compressedAccount.data?.discriminator)),data:o(T.from(new Uint8Array(n.outputCompressedAccounts[r].compressedAccount.data.data)))??[],dataHash:o(T.from(n.outputCompressedAccounts[r].compressedAccount.data?.dataHash))}:null},merkleTreeIndex:e.index}))),outputLeafIndices:e.output_leaf_indices,sequenceNumbers:e.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((e=>!e.equals(t.default))),isCompress:n?.isCompress||0,relayFee:n?.relayFee?br(n.relayFee):null,compressOrDecompressLamports:n?.compressOrDecompressLamports?br(n.compressOrDecompressLamports):null,message:null}}function Jr(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function en(e,t){return t<=0?[]:new Array(t).fill(e)}function tn(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function rn(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=Jr(n,e.treeInfo.tree),r=Jr(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===Je.StateV2){if(!nt.isV2())throw new Error("V2 trees are not supported yet");r=e.queue}i=Jr(n,r)}return r.forEach((e=>{const t=Jr(n,e.treeInfo.tree),r=Jr(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}}function nn(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=Jr(s,e.treeInfo.tree),o=Jr(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===Je.StateV2){if(!nt.isV2())throw new Error("V2 trees are not supported yet");l=c.queue}const d=en(l,r.length);return r.forEach(((e,t)=>{const r=Jr(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 on=e=>{if(e.lt(br(0)))throw new Error("Insufficient balance for transfer")},sn=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")},an=(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(", ")}`);ln(e,[1,2,3,4],"compressed accounts"),cn(t)}else e>0?un(e):cn(t)},un=e=>{ln(e,[1,2,3,4,8],"compressed accounts")},cn=e=>{ln(e,[1,2],"new addresses")},ln=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function hn(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 fn(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 pn=BigInt(2**32-1),mn=BigInt(32);function gn(e,t=0){return t?{h:Number(e&pn),l:Number(e>>mn&pn)}:{h:0|Number(e>>mn&pn),l:0|Number(e&pn)}}function yn(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}=gn(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const wn=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function vn(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 bn(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)),hn(e),e}class In{clone(){return this._cloneInto()}}const An=[],En=[],xn=[],Mn=BigInt(0),_n=BigInt(1),Tn=BigInt(2),kn=BigInt(7),Sn=BigInt(256),Cn=BigInt(113);for(let e=0,t=_n,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],An.push(2*(5*n+r)),En.push((e+1)*(e+2)/2%64);let o=Mn;for(let e=0;e<7;e++)t=(t<<_n^(t>>kn)*Cn)%Sn,t&Tn&&(o^=_n<<(_n<<BigInt(e))-_n);xn.push(o)}const[Pn,Bn]=yn(xn,1),Ln=(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),Nn=(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 On extends In{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,dn(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(){wn||vn(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=Ln(s,i,1)^r[n],u=Nn(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=En[r],s=Ln(t,o,n),i=Nn(t,o,n),a=An[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]^=Pn[n],e[1]^=Bn[n]}r.fill(0)}(this.state32,this.rounds),wn||vn(this.state32),this.posOut=0,this.pos=0}update(e){fn(this);const{blockLen:t,state:r}=this,n=(e=bn(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){fn(this,0),hn(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 dn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){hn(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 On(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 Un=(()=>function(e){const t=t=>e().update(bn(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new On(136,1,32))))(),Rn=e=>"object"==typeof e&&null!==e,Dn=e=>Rn(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),Vn=Symbol("mapObjectSkip"),qn=(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=>Dn(e)?qn(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===Vn)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&Dn(l)&&(l=Array.isArray(l)?s(l):qn(l,t,r,n)),o[c]=l)}return o};function Fn(e,t,r){if(!Rn(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return qn(e,t,r)}const Wn=/[\p{Lu}]/u,Hn=/[\p{Ll}]/u,$n=/^[\p{Lu}](?![\p{Lu}])/gu,jn=/([\p{Alpha}\p{N}_]|$)/u,zn=/[_.\- ]+/,Kn=new RegExp("^"+zn.source),Zn=new RegExp(zn.source+jn.source,"gu"),Yn=new RegExp("\\d+"+jn.source,"gu");class Gn 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 Xn=new Gn({maxSize:1e5}),Qn=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),Jn=(e,t={})=>{if(!Qn(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&&Qn(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=Fn(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(Xn.has(e))t=Xn.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?zn.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&&Wn.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&Hn.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(Kn,""),e=t.preserveConsecutiveUppercase?((e,t)=>($n.lastIndex=0,e.replaceAll($n,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>(Zn.lastIndex=0,Yn.lastIndex=0,e.replaceAll(Yn,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll(Zn,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&Xn.set(e,r),t=r}}return[t,o]};return Fn(e,u(void 0))};function eo(e){return r.fromSecretKey(Uint8Array.from(e))}function to(e){return"0x"+e.toString("hex")}const ro=e=>Array.isArray(e)?e:[e],no=e=>wr(e).toString();function oo(e){return br(e,void 0,"be").lt(st)}const so=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>Jn(t[e],r))):Jn(t,r);var t,r};function io(e){let t=255;for(;t>=0;){const r=T.concat([e,T.from([t])]),n=Un(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,oo(T.from(n)))return[T.from(n),t];t-=1}return null}function ao(e){const t=Un.create();for(const r of e)t.update(r);t.update(Uint8Array.from([255]));const r=t.digest();return r[0]=0,r}function uo(e){const t=Un.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function co(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))}function lo(e){const r=e.proof?{a:e.proof.a,b:e.proof.b,c:e.proof.c}:null,n=e.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:e.input_compressed_accounts.map((e=>({compressedAccount:{owner:new t(T.alloc(32)),lamports:br(e.lamports),address:e.address,data:null},merkleContext:{merkleTreePubkeyIndex:e.packedMerkleContext.merkle_tree_pubkey_index,queuePubkeyIndex:e.packedMerkleContext.queue_pubkey_index,leafIndex:e.packedMerkleContext.leaf_index,proveByIndex:e.packedMerkleContext.prove_by_index},rootIndex:e.root_index,readOnly:0}))),outputCompressedAccounts:e.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:e.compress_or_decompress_lamports,isCompress:e.is_compress}}function ho(e,t){return uo([t.toBytes(),...e])}function fo(e,r=Mt().addressTree){if(32!=e.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=io(Buffer.from([...n,...e]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new t(s)}function po(e){return ao(e.map((e=>Uint8Array.from(e))))}function mo(e,r,n){if(32!=e.length)throw new Error("Address seed length is not 32 bytes.");const o=r.toBytes(),s=n.toBytes(),i=ao([Uint8Array.from(e),Uint8Array.from(o),Uint8Array.from(s)]);return new t(i)}function go(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=Jr(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=Jr(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}if(import.meta.vitest){const{it:e,expect:r,describe:n}=import.meta.vitest,o=new t("7yucc7fL3JGbyMwg4neUaenNSdySS39hbAk89Ao3t1Hz");n("derive address seed",(()=>{e("should derive a valid address seed",(()=>{const e=[(new TextEncoder).encode("foo"),(new TextEncoder).encode("bar")];r(ho(e,o)).toStrictEqual(new Uint8Array([0,246,150,3,192,95,53,123,56,139,206,179,253,133,115,103,120,155,251,72,250,47,117,217,118,59,174,207,49,101,201,110]))})),e("should derive a valid address seed",(()=>{const e=[(new TextEncoder).encode("ayy"),(new TextEncoder).encode("lmao")];r(ho(e,o)).toStrictEqual(new Uint8Array([0,202,44,25,221,74,144,92,69,168,38,19,206,208,29,162,53,27,120,214,152,116,15,107,212,168,33,121,187,10,76,233]))}))})),n("deriveAddress function",(()=>{e("should derive a valid address from a seed and a merkle tree public key",(async()=>{const e=fo(ho([(new TextEncoder).encode("foo"),(new TextEncoder).encode("bar")],o),new t("11111111111111111111111111111111"));r(e).toBeInstanceOf(t),r(e).toStrictEqual(new t("139uhyyBtEh4e1CBDJ68ooK5nCeWoncZf9HPyAfRrukA"))})),e("should derive a valid address from a seed and a merkle tree public key",(async()=>{const e=fo(ho([(new TextEncoder).encode("ayy"),(new TextEncoder).encode("lmao")],o),new t("11111111111111111111111111111111"));r(e).toBeInstanceOf(t),r(e).toStrictEqual(new t("12bhHm6PQjbNmEn3Yu1Gq9k7XwVn2rZpzYokmLwbFazN"))}))})),n("packNewAddressParams function",(()=>{e("should pack new address params correctly",(()=>{const e=go([{seed:new Uint8Array([1,2,3,4]),addressMerkleTreeRootIndex:0,addressMerkleTreePubkey:new t("11111111111111111111111111111111"),addressQueuePubkey:new t("11111111111111111111111111111112")}],[new t("11111111111111111111111111111112"),new t("11111111111111111111111111111111")]);r(e.newAddressParamsPacked[0].addressMerkleTreeAccountIndex).toBe(1),r(e.newAddressParamsPacked[0].addressQueueAccountIndex).toBe(0)}))}))}async function yo({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await wo(e,n),n}async function wo(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 vo(e,t){return Math.ceil(1e6*e/t)}function bo(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}class Io{preAccounts=[];systemAccounts=[];nextIndex=0;map=new Map;static newWithSystemAccounts(e){const t=new Io;return t.addSystemAccounts(e),t}static newWithSystemAccountsV2(e){const t=new Io;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(...Eo(e))}addSystemAccountsV2(e){this.systemAccounts.push(...xo(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 Ao{selfProgram;cpiContext;solCompressionRecipient;solPoolPda;constructor(e,t,r,n){this.selfProgram=e,this.cpiContext=t,this.solCompressionRecipient=r,this.solPoolPda=n}static new(e){return new Ao(e)}static newWithCpiContext(e,t){return new Ao(e,t)}}function Eo(e){let r=(new TextEncoder).encode("cpi_authority");const o=t.findProgramAddressSync([r],e.selfProgram)[0],s=vt(),i=[{pubkey:Qo.programId,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:s.noopProgram,isSigner:0,isWritable:0},{pubkey:s.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:s.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.selfProgram,isSigner:0,isWritable:0}];return e.solPoolPda&&i.push({pubkey:e.solPoolPda,isSigner:0,isWritable:1}),e.solCompressionRecipient&&i.push({pubkey:e.solCompressionRecipient,isSigner:0,isWritable:1}),i.push({pubkey:n.programId,isSigner:0,isWritable:0}),e.cpiContext&&i.push({pubkey:e.cpiContext,isSigner:0,isWritable:1}),i}function xo(e){let r=(new TextEncoder).encode("cpi_authority");const o=t.findProgramAddressSync([r],e.selfProgram)[0],s=vt(),i=[{pubkey:Qo.programId,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:s.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:s.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.programId,isSigner:0,isWritable:0}];return e.solPoolPda&&i.push({pubkey:e.solPoolPda,isSigner:0,isWritable:1}),e.solCompressionRecipient&&i.push({pubkey:e.solCompressionRecipient,isSigner:0,isWritable:1}),e.cpiContext&&i.push({pubkey:e.cpiContext,isSigner:0,isWritable:1}),i}const Mo=()=>({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))}),_o=e=>{if(32!==e.a.length||64!==e.b.length||32!==e.c.length)throw new Error("ValidityProof has invalid shape")};function To(e){const t=So(e.ar[0]),r=So(e.ar[1]),n=new Uint8Array([...t,...r]),o=So(e.bs[0][0]),s=So(e.bs[0][1]),i=So(e.bs[1][0]),a=So(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=So(e.krs[0]),l=So(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function ko(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=Co(br(t.slice(32,64),32,"be"))?0:1;o[0]=Po(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=st.div(br(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(br(a.slice(0,32),32,"be"),br(a.slice(32,64),32,"be"));i[0]=Po(i[0],u);const c=n.slice(0,32),l=n.slice(32,64),d=Co(br(l,32,"be"));return c[0]=Po(c[0],d),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function So(e){const t=br(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function Co(e){return e.lte(st.sub(e))}function Po(e,t){return t?e:128|e}if(import.meta.vitest){const{it:e,expect:t,describe:r}=import.meta.vitest;r("addBitmaskToByte",(()=>{e("should add a bitmask to the byte if yIsPositive is false",(()=>{const e=Po(0,0);t(e).toBe(128)})),e("should not modify the byte if yIsPositive is true",(()=>{const e=Po(0,1);t(e).toBe(0)}))})),r("test prover server",(()=>{const r={ar:["0x22bdaa3187d8fe294925a66fa0165a11bc9e07678fa2fc72402ebfd33d521c69","0x2d18ff780b69898b4cdd8d7b6ac72d077799399f0f45e52665426456f3903584"],bs:[["0x138cc0962e49f76a701d2871d2799892c9782940095eb0429e979f336d2e162d","0x2fe1bfbb15cbfb83d7e00ace23e45f890604003783eaf34affa35e0d6f4822bc"],["0x1a89264f82cc6e8ef1c696bea0b5803c28c0ba6ab61366bcb71e73a4135cae8d","0xf778d857b3df01a4100265c9d014ce02d47425f0114685356165fa5ee3f3a26"]],krs:["0x176b6ae9001f66832951e2d43a98a972667447bb1781f534b70cb010270dcdd3","0xb748d5fac1686db28d94c02250af7eb4f28dfdabc8983305c45bcbc6e163eeb"]},n=[34,189,170,49,135,216,254,41,73,37,166,111,160,22,90,17,188,158,7,103,143,162,252,114,64,46,191,211,61,82,28,105],o=[147,140,192,150,46,73,247,106,112,29,40,113,210,121,152,146,201,120,41,64,9,94,176,66,158,151,159,51,109,46,22,45,47,225,191,187,21,203,251,131,215,224,10,206,35,228,95,137,6,4,0,55,131,234,243,74,255,163,94,13,111,72,34,188],s=[23,107,106,233,0,31,102,131,41,81,226,212,58,152,169,114,102,116,71,187,23,129,245,52,183,12,176,16,39,13,205,211];e("should execute a compressed token mint",(async()=>{const e=ko(To(r));t(e.a).toEqual(n),t(e.b).toEqual(o),t(e.c).toEqual(s)}))})),r("Validity Proof Functions",(()=>{r("placeholderValidityProof",(()=>{e("should create a validity proof with correct shape",(()=>{const e=Mo();t(e.a.length).toBe(32),t(e.b.length).toBe(64),t(e.c.length).toBe(32)}))})),r("checkValidityProofShape",(()=>{e("should not throw an error for valid proof shape",(()=>{const e={a:Array.from(new Uint8Array(32)),b:Array.from(new Uint8Array(64)),c:Array.from(new Uint8Array(32))};t((()=>_o(e))).not.toThrow()})),e("should throw an error for an invalid proof",(()=>{const e={a:Array.from(new Uint8Array(31)),b:Array.from(new Uint8Array(64)),c:Array.from(new Uint8Array(32))};t((()=>_o(e))).toThrow("ValidityProof has invalid shape")}))}))}))}function Bo(e,...t){return r=>t.reduce(((e,t)=>t(e)),e(r))}if(import.meta.vitest){const{it:e,expect:t,describe:r}=import.meta.vitest;r("pipe",(()=>{e("should return the result of applying all fns to the initial value",(()=>{const e=Bo((e=>e+1),(e=>2*e),(e=>e-3));t(e(5)).toBe(9)}))}))}function Lo(e,t,r,n){const i=new o({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(n);return new s(i)}async function No(e,t,r){const n=await e.sendTransaction(t,r);return await Oo(e,n,r),n}async function Oo(e,t,r){const n=r?.commitment||e.commitment||"confirmed",o=It(e.rpcEndpoint)?200:1e3;let s=0;await new Promise(((r,i)=>{const a=setInterval((async()=>{s+=o,s>=8e4&&(clearInterval(a),i(new Error(`Transaction ${t}'s confirmation timed out`)));const u=await e.getSignatureStatuses([t]);u?.value[0]?.confirmationStatus===n&&(clearInterval(a),r(t))}),o)}));const i=await e.getSlot();return await e.confirmTransactionIndexed(i),{context:{slot:i},value:{err:null}}}function Uo(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=Lo(e,t.publicKey,r,o);return i.sign(s),i}function Ro(e){return new Promise((t=>setTimeout(t,e)))}async function Do({connection:e,payer:t,authority:r,recentSlot:n}){const[o,s]=i.createLookupTable({payer:t.publicKey,authority:r.publicKey,recentSlot:n}),a=Uo([o],t,(await e.getLatestBlockhash()).blockhash,bo(t,[r]));return{address:s,txId:await No(e,a)}}async function Vo({connection:e,tableAddress:t,newStateTreeAddresses:r,newQueueAddresses:n,newCpiContextAddresses:o,payer:s,authority:a}){const u=await e.getAddressLookupTable(t);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(r.length!==n.length||r.length!==o.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const c=Uo([i.extendLookupTable({payer:s.publicKey,authority:a.publicKey,lookupTable:t,addresses:r.flatMap(((e,t)=>[e,n[t],o[t]]))})],s,(await e.getLatestBlockhash()).blockhash,bo(s,[a]));return{tableAddress:t,txId:await No(e,c)}}async function qo({connection:e,fullStateTreeAddress:t,nullifyLookupTableAddress:r,stateTreeLookupTableAddress:n,payer:o,authority:s}){const a=await e.getAddressLookupTable(n);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(t.toBase58()))throw console.log("fullStateTreeAddress",t),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 e.getAddressLookupTable(r);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.map((e=>e.toBase58())).includes(t.toBase58()))throw new Error("Address already exists in nullify lookup table");const c=Uo([i.extendLookupTable({payer:o.publicKey,authority:s.publicKey,lookupTable:r,addresses:[t]})],o,(await e.getLatestBlockhash()).blockhash,bo(o,[s]));return{txId:await No(e,c)}}function Fo(e){return e.treeInfo.nextTreeInfo?.queue??e.treeInfo.queue}function Wo(e){return e.treeInfo.nextTreeInfo??e.treeInfo}function Ho(e,t){return $o(e,t)}function $o(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 jo(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]}const zo=5;function Ko(e,t=(nt.isV2()?Je.StateV2:Je.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(zo,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 Zo({connection:e,stateTreeLUTPairs:r}){const n=await Promise.all(r.map((async t=>({stateTreeLookupTable:await e.getAddressLookupTable(t.stateTreeLookupTable),nullifyLookupTable:await e.getAddressLookupTable(t.nullifyLookupTable)})))),o=[];for(const{stateTreeLookupTable:e,nullifyLookupTable:r}of n){if(!e.value)throw new Error("State tree lookup table not found");if(!r.value)throw new Error("Nullify table not found");const n=e.value.state.addresses,s=r.value.state.addresses;if(n.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");for(let e=0;e<n.length;e+=3){const r=n[e],i=n[e+1],a=n[e+2];let u=null;if(!r||!i||!a)throw new Error("Invalid state tree pubkeys structure");const c=r.toBase58();let l;l=c.startsWith("bmt")?Je.StateV2:c.startsWith("amt2")?Je.AddressV2:c.startsWith("amt")?Je.AddressV1:Je.StateV1,s.map((e=>e.toBase58())).includes(r.toBase58())&&(u={tree:t.default,queue:t.default,cpiContext:t.default,treeType:l,nextTreeInfo:null}),o.push({tree:r,queue:i,cpiContext:a,treeType:l,nextTreeInfo:u})}for(const e of o)if(e.nextTreeInfo?.tree.equals(t.default)){const t=o.find((e=>!e.nextTreeInfo));if(!t)throw new Error("No available tree info found to assign as next tree");e.nextTreeInfo=t}}return o}async function Yo(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}}const Go=e=>e.reduce(((e,t)=>e.add(br(t.lamports))),br(0)),Xo=T.from("sol_pool_pda");class Qo{constructor(){}static programId=new t("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");static deriveCompressedSolPda(){const e=[Xo],[r,n]=t.findProgramAddressSync(e,this.programId);return r}static createTransferOutputState(e,t,r){r=br(r);const n=Go(e).sub(r);return on(n),n.eq(br(0))?[Ar(t,r)]:(sn(e),[Ar(e[0].owner,n),Ar(t,r)])}static createDecompressOutputState(e,t){t=br(t);const r=Go(e).sub(t);return on(r),r.eq(br(0))?[]:(sn(e),[Ar(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=br(r??0);const o=Go(n??[]).sub(r);return on(o),o.eq(br(0))||!n?[Ar(t,r,void 0,e)]:(sn(n),[Ar(n[0].owner,o),Ar(t,r,void 0,e)])}static async createAccount({payer:e,newAddressParams:t,newAddress:r,recentValidityProof:o,outputStateTreeInfo:s,inputCompressedAccounts:i,inputStateRootIndices:u,lamports:c}){const l=this.createNewAddressOutputState(r,e,c,i),{packedInputCompressedAccounts:d,packedOutputCompressedAccounts:h,remainingAccounts:f}=nn(i??[],u??[],l,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:m}=go([t],f),g=Sr({proof:o,inputCompressedAccountsWithMerkleContext:d,outputCompressedAccounts:h,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),y=[...Wr({...vt(),feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:n.programId}),...tn(m)];return new a({programId:this.programId,keys:y,data:g})}static async transfer({payer:e,inputCompressedAccounts:t,toAddress:r,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){const u=this.createTransferOutputState(t,r,o),{packedInputCompressedAccounts:c,packedOutputCompressedAccounts:l,remainingAccounts:d}=nn(t,s,u),h=Sr({proof:i,inputCompressedAccountsWithMerkleContext:c,outputCompressedAccounts:l,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),f=[...Wr({...vt(),feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:n.programId}),...tn(d)];return new a({programId:this.programId,keys:f,data:h})}static async compress({payer:e,toAddress:t,lamports:r,outputStateTreeInfo:o}){r=br(r);const s=Ar(t,r),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:u,remainingAccounts:c}=nn([],[],[s],o),l=Sr({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:u,relayFee:null,newAddressParams:[],compressOrDecompressLamports:r,isCompress:1}),d=[...Wr({...vt(),feePayer:e,authority:e,solPoolPda:Qo.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:n.programId}),...tn(c)];return new a({programId:this.programId,keys:d,data:l})}static async decompress({payer:e,inputCompressedAccounts:t,toAddress:r,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){o=br(o);const u=this.createDecompressOutputState(t,o),{packedInputCompressedAccounts:c,packedOutputCompressedAccounts:l,remainingAccounts:d}=nn(t,s,u),h=Sr({proof:i,inputCompressedAccountsWithMerkleContext:c,outputCompressedAccounts:l,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),f=[...Wr({...vt(),feePayer:e,authority:e,solPoolPda:Qo.deriveCompressedSolPda(),decompressionRecipient:r,systemProgram:n.programId}),...tn(d)];return new a({programId:this.programId,keys:f,data:h})}}function Jo(e,t){let r=br(0);t=br(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(br(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(br(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}async function es(e,t,r,n,o,s){const{blockhash:i}=await e.getLatestBlockhash();o||(o=Ko(await e.getStateTreeInfos()));const a=await Qo.compress({payer:t.publicKey,toAddress:n,lamports:r,outputStateTreeInfo:o}),c=Uo([u.setComputeUnitLimit({units:1e6}),a],t,i,[]);return await No(e,c,s)}async function ts(e,t,r,n,o,s,i){const{blockhash:a}=await e.getLatestBlockhash(),c=o??Et(),{tree:l,queue:d}=c,h=c.treeType===Je.AddressV2;if(nt.isV2()||h)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const f=ho(r,n),p=fo(f,l);s||(s=Ko(await e.getStateTreeInfos()));const m=await e.getValidityProofV0(void 0,[{address:br(p.toBytes()),tree:l,queue:d}]),g={seed:f,addressMerkleTreeRootIndex:m.rootIndices[0],addressMerkleTreePubkey:m.treeInfos[0].tree,addressQueuePubkey:m.treeInfos[0].queue},y=await Qo.createAccount({payer:t.publicKey,newAddressParams:g,newAddress:Array.from(p.toBytes()),recentValidityProof:m.compressedProof,programId:n,outputStateTreeInfo:s}),w=Uo([u.setComputeUnitLimit({units:1e6}),y],t,a,[]);return await No(e,w,i)}async function rs(e,t,r,n,o,s,i,a){n=br(n);const c=await e.getCompressedAccountsByOwner(t.publicKey),[l]=Jo(c.items,n),{blockhash:d}=await e.getLatestBlockhash(),h=s??Et(),{tree:f}=h,p=h.treeType===Je.AddressV2;if(nt.isV2()||p)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const m=ho(r,o),g=fo(m,f),y=await e.getValidityProof(l.map((e=>e.hash)),[br(g.toBytes())]),w={seed:m,addressMerkleTreeRootIndex:y.rootIndices[y.rootIndices.length-1],addressMerkleTreePubkey:y.treeInfos[y.treeInfos.length-1].tree,addressQueuePubkey:y.treeInfos[y.treeInfos.length-1].queue},v=await Qo.createAccount({payer:t.publicKey,newAddressParams:w,newAddress:Array.from(g.toBytes()),recentValidityProof:y.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:y.rootIndices,outputStateTreeInfo:i}),b=Uo([u.setComputeUnitLimit({units:1e6}),v],t,d,[]);return await No(e,b,a)}async function ns(e,t,r,n,o){const s=(await e.getCompressedAccountsByOwner(t.publicKey)).items;r=br(r);const i=Go(s);if(r.gt(i))throw new Error(`Not enough compressed lamports. Expected ${r}, got ${i}`);const a=await e.getValidityProof(s.map((e=>br(e.hash)))),{blockhash:c}=await e.getLatestBlockhash(),l=await Qo.decompress({payer:t.publicKey,toAddress:n,inputCompressedAccounts:s,recentValidityProof:a.compressedProof,recentInputStateRootIndices:a.rootIndices,lamports:r}),d=Uo([u.setComputeUnitLimit({units:1e6}),l],t,c,[]);return await No(e,d,o)}async function os(e,t,r,n,o,s){let i=br(0);const a=[];let c;for(r=br(r);i.lt(r);){const t={filters:void 0,dataSlice:void 0,cursor:c,limit:br(1e3)},o=await e.getCompressedAccountsByOwner(n.publicKey,t);for(const e of o.items)e.lamports.gt(br(0))&&(a.push(e),i=i.add(e.lamports));if(c=o.cursor??void 0,o.items.length<1e3||i.gte(r))break}if(i.lt(r))throw new Error(`Insufficient balance for transfer. Required: ${r.toString()}, available: ${i.toString()}`);const[l]=Jo(a,r),d=await e.getValidityProof(l.map((e=>br(e.hash)))),h=await Qo.transfer({payer:t.publicKey,inputCompressedAccounts:l,toAddress:o,lamports:r,recentInputStateRootIndices:d.rootIndices,recentValidityProof:d.compressedProof}),{blockhash:f}=await e.getLatestBlockhash(),p=Uo([u.setComputeUnitLimit({units:35e4}),h],t,f);return await No(e,p,s)}class ss{index;value;nextIndex;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([br(this.value.toArray("be",32)).toString(),br(this.nextIndex).toString(),br(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class is{newLowElement;newElement;newElementNextValue;constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class as{elements;currentNodeIndex;highestElementIndex;constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new as([new ss(0,br(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=it;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([br(r.value.toArray("be",32)).toString(),br(r.nextIndex).toString(),br(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 ss(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new is(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)}}const us="0";class cs{levels;capacity;zeroElement;_zeros;_layers;_lightWasm;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 ls(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=vt(),o=(await e.getSignaturesForAddress(n,void 0,"confirmed")).map((e=>e.signature)),s=[];for(let t=0;t<o.length;t+=100){const r=o.slice(t,t+100),n=await e.getParsedTransactions(r,{maxSupportedTransactionVersion:0,commitment:"confirmed"});s.push(...n)}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 s?.transaction.message.compiledInstructions||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===at.length&&at.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=yr.decode(t.data);o.push(e)}}const a=fs(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 ds(i,hs)}const ds=(e,t)=>{const{noopProgram:r}=vt(),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=yr.decode(s.data),o=t(T.from(r),e);null!=o&&n.push(o)}}}))})),n},hs=e=>{const t=T.from(e.map((e=>e)));try{return jr(t)}catch(e){return console.error("Error deserializing event:",e),null}};function fs(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=yr.encode(e),s=yr.encode(ut),i=yr.encode(ct),a=yr.encode(lt);if(o===s){n=qr(T.from(t)),r=1;break}if(o==i){n=Fr(T.from(t)),r=1;break}if(o==a){n=lo(Vr(T.from(t))),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if(yr.encode(e)===yr.encode(ht)){const e=t.slice(12);o=Xr(T.from(e))}}return n?Qr(o,t[t.length-1],n):null}async function ps(e,t){return(await ms(e)).find((e=>br(e.hash).eq(t)))}async function ms(e){const t=(await ls(e)).reverse(),r=[],n=[],o=await e.getStateTreeInfos();for(const e of t){for(let t=0;t<e.outputCompressedAccounts.length;t++){const n=Ho(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]),s=e.outputCompressedAccounts[t],i={treeInfo:n,hash:br(e.outputCompressedAccountHashes[t]),leafIndex:e.outputLeafIndices[t],proveByIndex:n.treeType===Je.StateV2},a=Er(i,s.compressedAccount.owner,s.compressedAccount.lamports,s.compressedAccount.data??void 0,s.compressedAccount.address??void 0);r.push(a)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];n.push(br(r))}}const s=r.filter((e=>!n.some((t=>t.eq(br(e.hash))))));return s.sort(((e,t)=>t.leafIndex-e.leafIndex)),s}function gs(e,r=Tt){if(null===e.data)return null;const{data:n}=e.data;if(0===n.length)return null;if(e.owner.toBase58()!==r.toBase58())throw new Error(`Invalid owner ${e.owner.toBase58()} for token layout`);try{const e=Buffer.from(n);let r=0;const o=new t(e.slice(r,r+32));r+=32;const s=new t(e.slice(r,r+32));r+=32;const i=new rt(e.slice(r,r+8),"le");r+=8;const a=e[r];r+=1;const u=a?new t(e.slice(r,r+32)):null;r+=32;const c=e[r];r+=1;const l=e[r];return r+=1,{mint:o,owner:s,amount:i,delegate:u,state:c,tlv:l?e.slice(r):null}}catch(e){throw console.error("Decoding error:",e),e}}async function ys(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)=>{const i=r[e.outputCompressedAccounts[s].merkleTreeIndex],a=Ho(n,i);if(!(a.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])||nt.isV2()&&a.queue.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])))throw new Error("Invalid tree");const u={treeInfo:a,hash:br(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:a.treeType===Je.StateV2};if(!t.compressedAccount.data)throw new Error("No data");const c=gs(t.compressedAccount);if(!c)throw new Error("Invalid token data");return{compressedAccount:Er(u,t.compressedAccount.owner,t.compressedAccount.lamports,t.compressedAccount.data,t.compressedAccount.address??void 0),parsed:c}}));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=>br(t).eq(e.compressedAccount.hash)))))}async function ws(e,t,r){const n=await ls(e);return{items:(await ys(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 vs(e,t,r){const n=await ls(e);return{items:(await ys(n,e)).filter((e=>e.parsed.delegate?.equals(t)&&e.parsed.mint.equals(r))),cursor:null}}async function bs(e,t){const r=await ls(e),n=(await ys(r,e)).filter((e=>br(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class Is 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 As(e){return"object"==typeof e&&null!=e}function Es(e){return As(e)&&!Array.isArray(e)}function xs(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Ms(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: \`${xs(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*_s(e,t,r,n){var o;As(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Ms(o,t,r,n);e&&(yield e)}}function*Ts(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=Ts(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):As(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 ks{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)=>_s(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>_s(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Ps(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Ss(e,this,t)}is(e){return Cs(e,this)}mask(e,t){return function(e,t,r){const n=Ps(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Ps(e,this,t)}}function Ss(e,t,r){const n=Ps(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function Cs(e,t){return!Ps(e,t)[0]}function Ps(e,t,r={}){const n=Ts(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new Is(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function Bs(e,t){return new ks({type:e,schema:null,validator:t})}function Ls(){return Bs("any",(()=>1))}function Ns(e){return new ks({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: ${xs(e)}`})}function Os(){return Bs("boolean",(e=>"boolean"==typeof e))}function Us(e){return Bs("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${xs(t)}`))}function Rs(e){const t=xs(e);return new ks({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${xs(r)}`})}function Ds(e){return new ks({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function Vs(){return Bs("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${xs(e)}`))}function qs(){return Bs("string",(e=>"string"==typeof e||`Expected a string, but received: ${xs(e)}`))}function Fs(e){const t=Object.keys(e);return new ks({type:"type",schema:e,*entries(r){if(As(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>Es(e)||`Expected an object, but received: ${xs(e)}`,coercer:e=>Es(e)?{...e}:e})}function Ws(e){const t=e.map((e=>e.type)).join(" | ");return new ks({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]=Ts(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: ${xs(r)}`,...o]}})}function Hs(){return Bs("unknown",(()=>1))}function $s(e,t,r){return new ks({...e,coercer:(n,o)=>Cs(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}var js;!function(e){e.compressible="compressible",e.standard="standard"}(js||(js={}));const zs=$s(Us(t),qs(),(e=>new t(e))),Ks=$s(Us(Array),qs(),(e=>Array.from(new t(e).toBytes()))),Zs=$s(Us(rt),qs(),(e=>wr(e,"base58"))),Ys=$s(Os(),Ws([Vs(),Os()]),(e=>Boolean(e))),Gs=$s(Us(rt),Ws([qs(),Vs()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return br(e)}return br(e,10)})),Xs=qs();function Qs(e){return Ws([Fs({jsonrpc:Rs("2.0"),id:qs(),result:e}),Fs({jsonrpc:Rs("2.0"),id:qs(),error:Fs({code:Hs(),message:qs(),data:Ds(Ls())})})])}const Js=Qs(Hs());function ei(e){return $s(Qs(e),Js,(t=>"error"in t?t:{...t,result:Ss(t.result,e)}))}function ti(e){return ei(Fs({context:Fs({slot:Vs()}),value:e}))}const ri=Fs({treeType:Vs(),tree:zs,queue:zs,cpiContext:Ds(zs)}),ni=Fs({treeType:Vs(),tree:zs,queue:zs,cpiContext:Ds(zs),nextTreeContext:(oi=Ds(ri),new ks({...oi,validator:(e,t)=>void 0===e||oi.validator(e,t),refiner:(e,t)=>void 0===e||oi.refiner(e,t)}))});var oi;const si=Fs({address:Ds(Ks),hash:Zs,data:Ds(Fs({data:Xs,dataHash:Zs,discriminator:Gs})),lamports:Gs,owner:zs,leafIndex:Vs(),tree:zs,seq:Ds(Gs),slotCreated:Gs}),ii=Fs({address:Ds(Ks),hash:Zs,data:Ds(Fs({data:Xs,dataHash:Zs,discriminator:Gs})),lamports:Gs,owner:zs,leafIndex:Vs(),seq:Ds(Gs),slotCreated:Gs,merkleContext:ni,proveByIndex:Ys}),ai=Fs({mint:zs,owner:zs,amount:Gs,delegate:Ds(zs),state:qs()}),ui=Fs({tokenData:ai,account:si}),ci=Fs({tokenData:ai,account:ii}),li=Fs({items:Ns(si)}),di=Fs({items:Ns(ii)}),hi=Fs({items:Ns(si),cursor:Ds(qs())}),fi=Fs({items:Ns(ii),cursor:Ds(qs())}),pi=Fs({items:Ns(ui),cursor:Ds(qs())}),mi=Fs({items:Ns(ci),cursor:Ds(qs())}),gi=Vs(),yi=qs(),wi=Fs({items:Ns(Fs({signature:qs(),slot:Vs(),blockTime:Vs(),error:Ds(qs())}))}),vi=Fs({items:Ns(Fs({signature:qs(),slot:Vs(),blockTime:Vs()})),cursor:Ds(qs())}),bi=Fs({hash:Zs,leafIndex:Vs(),merkleTree:zs,proof:Ns(Zs),rootSeq:Vs(),root:Zs}),Ii=Fs({hash:Zs,leafIndex:Vs(),proof:Ns(Zs),root:Zs,rootSeq:Vs(),proveByIndex:Ys,treeContext:ni}),Ai=Fs({address:Zs,nextIndex:Vs(),merkleTree:zs,proof:Ns(Zs),rootSeq:Vs(),root:Zs,lowerRangeAddress:Zs,higherRangeAddress:Zs,lowElementLeafIndex:Vs()}),Ei=Fs({a:Ns(Vs()),b:Ns(Vs()),c:Ns(Vs())}),xi=Fs({rootIndex:Vs(),proveByIndex:Ys}),Mi=Fs({compressedProof:Ei,leafIndices:Ns(Vs()),leaves:Ns(Zs),rootIndices:Ns(Vs()),roots:Ns(Zs),merkleTrees:Ns(zs)}),_i=Fs({hash:Zs,root:Zs,rootIndex:xi,merkleContext:ni,leafIndex:Vs()}),Ti=Fs({address:Zs,root:Zs,rootIndex:Vs(),merkleContext:ni}),ki=Fs({compressedProof:Ds(Ei),accounts:Ns(_i),addresses:Ns(Ti)}),Si=Ns(bi),Ci=Ns(Ii),Pi=Fs({amount:Gs}),Bi=Gs,Li=Fs({balance:Gs,mint:zs}),Ni=Fs({tokenBalances:Ns(Li),cursor:Ds(qs())}),Oi=Fs({items:Ns(Li),cursor:Ds(qs())}),Ui=Fs({cursor:Ds(qs()),items:Ns(Fs({balance:Gs,owner:zs}))}),Ri=Fs({hash:Ns(Vs()),root:Ns(Vs()),proof:Ns(Ns(Vs()))}),Di=e=>new Date(e).getTime(),Vi=Fs({items:Ns(Fs({blockTime:Vs(),signature:qs(),slot:Vs()}))}),qi=Fs({items:Ns(Fs({blockTime:Vs(),signature:qs(),slot:Vs()})),cursor:Ds(qs())}),Fi=Fs({account:ii,txHash:Zs,nullifier:Zs}),Wi=Fs({compressionInfo:Fs({closedAccounts:Ns(Fs({account:si,optionalTokenData:Ds(ai)})),openedAccounts:Ns(Fs({account:si,optionalTokenData:Ds(ai)}))}),transaction:Ls()}),Hi=Fs({compressionInfo:Fs({closedAccounts:Ns(Fs({account:Fi,optionalTokenData:Ds(ai)})),openedAccounts:Ns(Fs({account:ii,optionalTokenData:Ds(ai)}))}),transaction:Ls()}),$i={Solana:"solana",Compressed:"compressed"};let ji=0;function zi(){return ji}function Ki({discriminator:e,data:t,dataHash:r}){return{discriminator:e.toArray("le",8),data:T.from(t,"base64"),dataHash:r.toArray("le",32)}}async function Zi(e,t,r,n=0){const o=ot(n?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner"),s=n?"delegate":"owner",i=await Xi(e.compressionApiEndpoint,o,{[s]:t.toBase58(),mint:r.mint?.toBase58(),limit:r.limit?.toNumber(),cursor:r.cursor});let a;if(a=nt.isV2()?Ss(i,ti(mi)):Ss(i,ti(pi)),"error"in a)throw new l(a.error,`failed to get info for compressed accounts by ${s} ${t.toBase58()}`);if(null===a.result.value)throw new Error("not implemented: NULL result");const u=[],c=await e.getStateTreeInfos();return a.result.value.items.map((e=>{const r=e.account,n=e.tokenData,o=nt.isV2()?r.merkleContext.tree:r.tree,i=nt.isV2()?r.proveByIndex:0,a=Ho(c,o),l=Er(xr(a,r.hash,r.leafIndex,i),r.owner,br(r.lamports),r.data?Ki(r.data):void 0,r.address||void 0),d={mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null};if(d[s]?.toBase58()!==t.toBase58())throw new Error(`RPC returned token account with ${s} different from requested ${s}`);u.push({compressedAccount:l,parsed:d})})),{items:u.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:a.result.value.cursor}}function Yi(e,t,r,n){let o;if(e)if("string"==typeof e)o=e,t=t||o,r=r||o;else{if(!(e instanceof c))throw new Error("Invalid endpoint or connection type");o=e.rpcEndpoint,t=t||o,r=r||o}else o="http://127.0.0.1:8899",t=t||"http://127.0.0.1:8784",r=r||"http://127.0.0.1:3001";var s;return s=o.toLowerCase().includes("devnet"),ji=s,new sa(o,t,r,n)}function Gi(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 Xi=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=Gi(await i.text());return n?so(JSON.parse(a)):JSON.parse(a)},Qi=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=ko(To(await i.json()));return n&&console.timeEnd(s),a};function Ji(e){const t=[];for(let r=0;r<e.length;r++){const n={root:to(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>to(e))),leaf:to(br(e[r].hash))};t.push(n)}return t}function ea(e){const t=[];for(let r=0;r<e.length;r++){const n={root:to(e[r].root),value:to(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>to(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:to(e[r].leafLowerRangeValue),leafHigherRangeValue:to(e[r].leafHigherRangeValue)};t.push(n)}return t}function ta(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return br(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 ra(e,t,r,n){const o=ta(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=ta(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?ta([o],[i],n):o:i}function na(e){const t=e.account,r=e.optionalTokenData,n=Er(xr(t.treeInfo,t.hash.toArray("be",32),t.leafIndex,t.proveByIndex),t.owner,br(t.lamports),t.data?Ki(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 oa(e,t){const r=new Map;for(const e of t)r.set(e.signature,{signature:e.signature,slot:e.slot,blockTime:e.blockTime,err:null,memo:null,confirmationStatus:void 0,sources:[$i.Compressed]});for(const t of e)r.get(t.signature)?r.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:t.blockTime??null,err:t.err,memo:t.memo??null,confirmationStatus:t.confirmationStatus,sources:[$i.Solana,$i.Compressed]}):r.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:t.blockTime??null,err:t.err,memo:t.memo??null,confirmationStatus:t.confirmationStatus,sources:[$i.Solana]});return Array.from(r.values()).sort(((e,t)=>t.slot-e.slot))}class sa extends c{compressionApiEndpoint;proverEndpoint;allStateTreeInfos=null;lastStateTreeFetchTime=null;CACHE_TTL=36e5;fetchPromise=null;constructor(e,t,r,n){super(e,n||"confirmed"),this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(It(this.rpcEndpoint))return sr();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}=bt();try{return await Zo({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await Zo({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 e=new t(rr);return{tree:e,queue:e,cpiContext:void 0,treeType:Je.AddressV2,nextTreeInfo:null}}async getCompressedAccount(e,t){if(!t&&!e)throw new Error("Either hash or address must be provided");if(t&&e)throw new Error("Only one of hash or address must be provided");const r=await this.getStateTreeInfos(),n=await Xi(this.compressionApiEndpoint,ot("getCompressedAccount"),{hash:t?vr(t):void 0,address:e?vr(e):void 0});let o;if(o=nt.isV2()?Ss(n,ti(Ds(ii))):Ss(n,ti(Ds(si))),"error"in o)throw new l(o.error,`failed to get info for compressed account ${t?t.toString():e?e.toString():""}`);if(null===o.result.value)return null;const s=Ho(r,nt.isV2()?o.result.value.merkleContext.tree:o.result.value.tree),i=o.result.value;return Er(xr(s,i.hash,i.leafIndex),i.owner,br(i.lamports),i.data?Ki(i.data):void 0,i.address||void 0)}async getCompressedBalance(e,t){if(!t&&!e)throw new Error("Either hash or address must be provided");if(t&&e)throw new Error("Only one of hash or address must be provided");const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressedBalance",{hash:t?vr(t):void 0,address:e?vr(e):void 0}),ti(Bi));if("error"in r)throw new l(r.error,`failed to get balance for compressed account ${t?t.toString():e?e.toString():""}`);return null===r.result.value?br(0):br(r.result.value)}async getCompressedBalanceByOwner(e){const t=Ss(await Xi(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:e.toBase58()}),ti(Bi));if("error"in t)throw new l(t.error,`failed to get balance for compressed account ${e.toBase58()}`);return null===t.result.value?br(0):br(t.result.value)}async getCompressedAccountProof(e){const t=await Xi(this.compressionApiEndpoint,ot("getCompressedAccountProof"),{hash:vr(e)});let r;if(r=nt.isV2()?Ss(t,ti(Ii)):Ss(t,ti(bi)),"error"in r)throw new l(r.error,`failed to get proof for compressed account ${e.toString()}`);if(null===r.result.value)throw new Error(`failed to get proof for compressed account ${e.toString()}`);const n=Ho(await this.getStateTreeInfos(),nt.isV2()?r.result.value.treeContext.tree:r.result.value.tree);return{hash:br(r.result.value.hash.toArray("be",32)),treeInfo:n,leafIndex:r.result.value.leafIndex,merkleProof:r.result.value.proof,rootIndex:r.result.value.rootSeq%2400,root:r.result.value.root,proveByIndex:nt.isV2()?r.result.value.proveByIndex:0}}async getMultipleCompressedAccounts(e){const t=await Xi(this.compressionApiEndpoint,ot("getMultipleCompressedAccounts"),{hashes:e.map((e=>vr(e)))});let r;if(r=nt.isV2()?Ss(t,ti(di)):Ss(t,ti(li)),"error"in r)throw new l(r.error,`failed to get info for compressed accounts ${e.map((e=>vr(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get info for compressed accounts ${e.map((e=>vr(e))).join(", ")}`);const n=await this.getStateTreeInfos(),o=[];return r.result.value.items.map((e=>{const t=nt.isV2()?e.merkleContext.tree:e.tree,r=Ho(n,t),s=Er(xr(r,br(e.hash.toArray("be",32)),e.leafIndex),e.owner,br(e.lamports),e.data?Ki(e.data):void 0,e.address||void 0);o.push(s)})),o.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(e){const t=await Xi(this.compressionApiEndpoint,ot("getMultipleCompressedAccountProofs"),e.map((e=>vr(e))));let r;if(r=nt.isV2()?Ss(t,ti(Ns(Ii))):Ss(t,ti(Ns(bi))),"error"in r)throw new l(r.error,`failed to get proofs for compressed accounts ${e.map((e=>vr(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for compressed accounts ${e.map((e=>vr(e))).join(", ")}`);const n=[],o=await this.getStateTreeInfos();for(const e of r.result.value){const t=Ho(o,nt.isV2()?e.treeContext.tree:e.merkleTree),r={hash:br(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:nt.isV2()?e.proveByIndex:0};n.push(r)}return n}async getCompressedAccountsByOwner(e,t){const r=await Xi(this.compressionApiEndpoint,ot("getCompressedAccountsByOwner"),{owner:e.toBase58(),filters:t?.filters||[],dataSlice:t?.dataSlice,cursor:t?.cursor,limit:t?.limit?.toNumber()});let n;if(n=nt.isV2()?Ss(r,ti(fi)):Ss(r,ti(hi)),"error"in n)throw new l(n.error,`failed to get info for compressed accounts owned by ${e.toBase58()}`);if(null===n.result.value)return{items:[],cursor:null};const o=[],s=await this.getStateTreeInfos();return n.result.value.items.map((e=>{const t=Ho(s,nt.isV2()?e.merkleContext.tree:e.tree),r=Er(xr(t,br(e.hash.toArray("be",32)),e.leafIndex,nt.isV2()?e.proveByIndex:0),e.owner,br(e.lamports),e.data?Ki(e.data):void 0,e.address||void 0);o.push(r)})),{items:o.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:n.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Zi(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await Zi(this,e,t,1)}async getCompressedTokenAccountBalance(e){const t=Ss(await Xi(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:vr(e)}),ti(Pi));if("error"in t)throw new l(t.error,`failed to get balance for compressed token account ${e.toString()}`);if(null===t.result.value)throw new Error(`failed to get balance for compressed token account ${e.toString()}`);return{amount:br(t.result.value.amount)}}async getCompressedTokenBalancesByOwner(e,t){t||(t={});const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:e.toBase58(),mint:t.mint?.toBase58(),limit:t.limit?.toNumber(),cursor:t.cursor}),ti(Ni));if("error"in r)throw new l(r.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);return{items:t.mint?r.result.value.tokenBalances.filter((e=>e.mint.toBase58()===t.mint.toBase58())):r.result.value.tokenBalances,cursor:r.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(e,t){t||(t={});const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:e.toBase58(),mint:t.mint?.toBase58(),limit:t.limit?.toNumber(),cursor:t.cursor}),ti(Oi));if("error"in r)throw new l(r.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);const n=t.mint?r.result.value.items.filter((e=>e.mint.toBase58()===t.mint.toBase58())):r.result.value.items;return{context:r.result.context,value:{items:n,cursor:r.result.value.cursor}}}async getCompressionSignaturesForAccount(e){const t=Ss(await Xi(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:vr(e)}),ti(Vi));if("error"in t)throw new l(t.error,`failed to get signatures for compressed account ${e.toString()}`);return t.result.value.items}async getTransactionWithCompressionInfo(e){const t=await Xi(this.compressionApiEndpoint,ot("getTransactionWithCompressionInfo"),{signature:e});let r;if(r=nt.isV2()?Ss(t,ei(Hi)):Ss(t,ei(Wi)),"error"in r)throw new l(r.error,"failed to get slot");if(null===r.result.transaction)return null;const n=[],o=[],s=await this.getStateTreeInfos();nt.isV2()?(r.result.compressionInfo.closedAccounts.map((e=>{n.push(function(e){const t={account:e.account.account,optionalTokenData:e.optionalTokenData},r={nullifier:e.account.nullifier,txHash:e.account.txHash},n=na(t);return{account:n.account,maybeTokenData:n.maybeTokenData,maybeNullifierMetadata:r}}(e))})),r.result.compressionInfo.openedAccounts.map((e=>{o.push(na(e))}))):(r.result.compressionInfo.closedAccounts.map((e=>{const t=Ho(s,e.account.tree),r=Er(xr(t,br(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,br(e.account.lamports),e.account.data?Ki(e.account.data):void 0,e.account.address||void 0);n.push({account:r,maybeTokenData:e.optionalTokenData})})),r.result.compressionInfo.openedAccounts.map((e=>{const t=Ho(s,e.account.tree),r=Er(xr(t,br(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,br(e.account.lamports),e.account.data?Ki(e.account.data):void 0,e.account.address||void 0);o.push({account:r,maybeTokenData:e.optionalTokenData})})));const i=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},a=i(n),u=i(o);return{compressionInfo:{closedAccounts:n,openedAccounts:o,preTokenBalances:a,postTokenBalances:u},transaction:r.result.transaction}}async getCompressionSignaturesForAddress(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ti(qi));if("error"in r)throw new l(r.error,`failed to get signatures for address ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for address ${e.toBase58()}`);return r.result.value}async getCompressionSignaturesForOwner(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ti(qi));if("error"in r)throw new l(r.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return r.result.value}async getCompressionSignaturesForTokenOwner(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ti(qi));if("error"in r)throw new l(r.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return r.result.value}async getIndexerHealth(){const e=Ss(await Xi(this.compressionApiEndpoint,"getIndexerHealth"),ei(yi));if("error"in e)throw new l(e.error,"failed to get health");return e.result}async confirmTransactionIndexed(e){const t=It(this.rpcEndpoint)?1e4:2e4,r=It(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 e=Ss(await Xi(this.compressionApiEndpoint,"getIndexerSlot"),ei(gi));if("error"in e)throw new l(e.error,"failed to get slot");return e.result}async getCompressedMintTokenHolders(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ti(Ui));if("error"in r)throw new l(r.error,"failed to get mint token holders");return r.result}async getLatestCompressionSignatures(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:t,cursor:e}),ti(vi));if("error"in r)throw new l(r.error,"failed to get latest non-voting signatures");return r.result}async getLatestNonVotingSignatures(e,t){const r=Ss(await Xi(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:e,cursor:t}),ti(wi));if("error"in r)throw new l(r.error,"failed to get latest non-voting signatures");return r.result}async getMultipleNewAddressProofs(e){const t=Ss(await Xi(this.compressionApiEndpoint,"getMultipleNewAddressProofs",e.map((e=>vr(e)))),ti(Ns(Ai)));if("error"in t)throw new l(t.error,`failed to get proofs for new addresses ${e.map((e=>vr(e))).join(", ")}`);if(null===t.result.value)throw new Error(`failed to get proofs for new addresses ${e.map((e=>vr(e))).join(", ")}`);const r=[];for(const e of t.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:br(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:br(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:Mt().addressQueue,treeType:Je.AddressV1,nextTreeInfo:null}};r.push(t)}return r}async getValidityProof(e=[],t=[]){const r=await this.getMultipleCompressedAccounts(e),n=r.map((e=>e.treeInfo.tree)),o=r.map((e=>e.treeInfo.queue)),s=Mt().addressTree,i=Mt().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===js.compressible||void 0===r){const r=mo(Uint8Array.from(e.address),e.treeInfo.tree,kt);t=br(r.toBytes())}else t=br(e.address);return{address:t,tree:e.treeInfo.tree,queue:e.treeInfo.queue}})),{value:s}=await this.getValidityProofAndRpcContext(n,o);return s}async getValidityProofAndRpcContext(e=[],t=[]){an(e.length,t.length);const r=await Xi(this.compressionApiEndpoint,ot("getValidityProof"),{hashes:e.map((({hash:e})=>vr(e))),newAddressesWithTrees:t.map((({address:e,tree:t})=>({address:vr(e),tree:t.toBase58()})))});let n;if(n=nt.isV2()?Ss(r,ti(ki)):Ss(r,ti(Mi)),"error"in n)throw new l(n.error,`failed to get validity proof for hashes ${e.map((e=>e.hash.toString())).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get validity proof for hashes ${e.map((e=>e.hash.toString())).join(", ")}`);const o=n.result.value;if(nt.isV2())return{value:{compressedProof:o.compressedProof,leaves:o.accounts.map((e=>e.hash)).concat(o.addresses.map((e=>e.address))),roots:o.accounts.map((e=>e.root)).concat(o.addresses.map((e=>e.root))),rootIndices:o.accounts.map((e=>e.rootIndex.rootIndex)).concat(o.addresses.map((e=>e.rootIndex))),proveByIndices:o.accounts.map((e=>e.rootIndex.proveByIndex)).concat(o.addresses.map((()=>0))),treeInfos:o.accounts.map((e=>e.merkleContext)).concat(o.addresses.map((e=>e.merkleContext))),leafIndices:o.accounts.map((e=>e.leafIndex)).concat(o.addresses.map((()=>0)))},context:n.result.context};{const e=await this.getStateTreeInfos(),t=o.merkleTrees.map((t=>t.equals(Mt().addressTree)?{tree:t,queue:Mt().addressQueue,treeType:Je.AddressV1,nextTreeInfo:null}:$o(e,t)));return{value:{compressedProof:o.compressedProof,roots:o.roots,rootIndices:o.rootIndices.map((e=>e)),leafIndices:o.leafIndices,leaves:o.leaves,treeInfos:t,proveByIndices:o.rootIndices.map((e=>e.proveByIndex))},context:n.result.context}}}async getAccountInfoInterface(e,t,r,n){if(!nt.isV2())throw new Error("getAccountInfoInterface requires feature flag V2");n=n??At();const o=mo(e.toBytes(),n.tree,t),[s,i]=await Promise.allSettled([this.getAccountInfo(e,r),this.getCompressedAccount(br(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:T.concat([T.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:oa(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:oa(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=br(0),a=0,u=null;if("fulfilled"===o.status&&o.value){const e=o.value.value;i=br(e.amount),a=e.decimals,u=e}let c=br(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?br(r.value):br(0),s="fulfilled"===n.status?n.value:br(0);return{total:o.isZero()?s:o,hasColdBalance:!s.isZero()}}}async function ia(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 aa(t,e,r,n,void 0,{depth:o||Mt().merkleTreeHeight,log:s})}class aa extends c{compressionApiEndpoint;proverEndpoint;lightWasm;depth;log=0;allStateTreeInfos=null;lastStateTreeFetchTime=null;fetchPromise=null;CACHE_TTL=36e5;constructor(e,t,r,n,o,s){super(e,o||{commitment:"confirmed"}),this.compressionApiEndpoint=r,this.proverEndpoint=n;const{depth:i,log:a}=s??{},{merkleTreeHeight:u}=Mt();this.lightWasm=t,this.depth=i??u,this.log=a??0}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return sr()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}async getAddressTreeInfoV2(){const e=new t(rr);return{tree:e,queue:e,cpiContext:void 0,treeType:Je.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");return await ps(this,t)??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 ps(this,t);if(!r)throw new Error("Account not found");return br(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),br(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await ms(e)).filter((e=>t.some((t=>br(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(e){const r=await ls(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=Ho(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 t(r);let u;if(i.treeType===Je.StateV1)u=new cs(this.depth,this.lightWasm,o.map((e=>br(e).toString())));else{if(i.treeType!==Je.StateV2)throw new Error(`Invalid tree type: ${i.treeType} in test-rpc.ts`);u=new cs(32,this.lightWasm,[])}for(let t=0;t<e.length;t++){const r=o.findIndex((r=>br(r).eq(e[t])));if(-1!==r)if(i.treeType===Je.StateV1){const n=u.path(r).pathElements.map((e=>br(e))),a=br(u.root()),c={hash:br(e[t].toArray("be",32)),treeInfo:i,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:o.length,root:a};s.set(e[t].toString(),c)}else if(i.treeType===Je.StateV2){const r=u._zeros.slice(0,-1).map((e=>br(e))),o=br(u.root()),c=n.get(a.toBase58()).leafIndices.findIndex((r=>e[t].eq(br(n.get(a.toBase58()).leaves[r])))),l={hash:br(e[t].toArray("be",32)),treeInfo:i,leafIndex:c,merkleProof:r,proveByIndex:1,rootIndex:0,root:o};s.set(e[t].toString(),l)}}}if(s.forEach(((e,t)=>{if(e.treeInfo.treeType===Je.StateV1){const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=br(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)}})),new Set(e.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 e.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 ms(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 ws(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await vs(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await bs(this,e);return{amount:br(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await ws(this,e,t.mint)).items.map((e=>({balance:br(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await ws(this,e,t.mint)).items.map((e=>({balance:br(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=as.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(br(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(br(r))}const o=new cs(this.depth,this.lightWasm,n.map((e=>br(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=>br(e))),u=t.get(n.nextIndex).value,c={root:br(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:br(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:br(n.index),treeInfo:{tree:Mt().addressTree,queue:Mt().addressQueue,treeType:Je.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 rt))))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 rt))))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===Je.StateV1)),o=await this.getMultipleCompressedAccountProofs(e);if(t){const e=Ji(o);r={compressedProof:await Qi(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=>br(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else r={compressedProof:null,roots:o.map((()=>br(0))),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>br(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=ea(e);r={compressedProof:await Qi(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=>br(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===Je.StateV1)),i=ea(o);let a;if(s){const e=Ji(n);a=await Qi(this.proverEndpoint,"combined",[e,i],1)}else a=await Qi(this.proverEndpoint,"new-address",i,1);r={compressedProof:a,roots:n.map((e=>s?e.root:br(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=>br(e.hash))).concat(o.map((e=>br(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 ua=1;const ca=ga(255),la=ga(254),da=ga(253),ha=ga(252);function fa(e,t){if(typeof e!=typeof t)return console.log(`Type mismatch: ${typeof e} !== ${typeof t}`),0;if(e instanceof rt&&t instanceof rt)return e.eq(t);if("object"==typeof e&&null!==e&&null!==t){const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return console.log(`Key length mismatch: ${r.length} !== ${n.length}`),0;for(const o of r){if(!n.includes(o))return console.log(`Key ${o} not found in value`),0;if(!fa(e[o],t[o]))return console.log(`Value mismatch at key ${o}`),0}return 1}return e!==t&&console.log(`Value mismatch: ${e} !== ${t}`),e===t}async function pa(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=ga(r),o=await e.requestAirdrop(n.publicKey,t);return await Oo(e,o),n}function ma(){return new c("http://127.0.0.1:8899","confirmed")}function ga(e){if(e||(e=ua,ua++),e>255)return r.generate();const t=new Uint8Array(32);return t[31]=e,r.fromSeed(t)}if(import.meta.vitest){const{describe:e,it:t,expect:n}=import.meta.vitest;e("getTestKeypair",(()=>{t("should generate a keypair with a specific counter",(()=>{const e=ga(10),t=ga(10);n(e).toEqual(t),n(e).toBeInstanceOf(r),n(e.publicKey).toBeDefined(),n(e.secretKey).toBeDefined()})),t("should generate random keypair if counter is greater than 255",(()=>{const e=()=>ga(256),t=e(),r=e();n(t).not.toEqual(r)})),t("should increment the global counter if no counter is provided",(()=>{const e=ga(),t=ga(),r=ga(),o=ga(3);n(e).not.toEqual(t),n(t).not.toEqual(r),n(r).toEqual(o)}))}))}var ya,wa,va,ba,Ia,Aa,Ea,xa,Ma;!function(e){e.NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",e.NOT_U64="NOT_U64",e.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE"}(ya||(ya={})),function(e){e.FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",e.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS"}(wa||(wa={})),function(e){e.OWNER_UNDEFINED="OWNER_UNDEFINED",e.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",e.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED"}(va||(va={})),function(e){e.CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",e.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",e.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",e.RPC_INVALID="RPC_INVALID"}(ba||(ba={})),function(e){e.LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",e.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED"}(Ia||(Ia={})),function(e){e.NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED"}(Aa||(Aa={})),function(e){e.INVALID_PROOF="INVALID_PROOF",e.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",e.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED"}(Ea||(Ea={})),function(e){e.MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",e.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",e.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",e.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",e.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",e.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED"}(xa||(xa={})),function(e){e.ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",e.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",e.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",e.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",e.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",e.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",e.INVALID_NUMBER="INVALID_NUMBER"}(Ma||(Ma={}));class _a extends Error{code;functionName;codeMessage;constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}class Ta extends _a{}class ka extends _a{}class Sa extends _a{}class Ca extends _a{}class Pa extends _a{}class Ba extends _a{}class La extends _a{}class Na extends _a{}class Oa extends _a{}export{fr as ADDRESS_QUEUE_ROLLOVER_FEE,mr as ADDRESS_TREE_NETWORK_FEE_V1,gr as ADDRESS_TREE_NETWORK_FEE_V2,ca as ALICE,Ri as AccountProofResult,Kr as AppendLeavesInputLayout,zr as AppendNullifyCreateAddressInputsMetaLayout,la as BOB,Pi as BalanceResult,da as CHARLIE,Tt as COMPRESSED_TOKEN_PROGRAM_ID,at as COMPUTE_BUDGET_PATTERN,kt as CTOKEN_PROGRAM_ID,Mr as CompressedAccountLayout,si as CompressedAccountResult,ii as CompressedAccountResultV2,hi as CompressedAccountsByOwnerResult,fi as CompressedAccountsByOwnerResultV2,Br as CompressedCpiContextLayout,Ui as CompressedMintTokenHoldersResult,Pr as CompressedProofLayout,ui as CompressedTokenAccountResult,ci as CompressedTokenAccountResultV2,pi as CompressedTokenAccountsByOwnerOrDelegateResult,mi as CompressedTokenAccountsByOwnerOrDelegateResultV2,Wi as CompressedTransactionResult,Hi as CompressedTransactionResultV2,Sa as CreateUtxoError,va as CreateUtxoErrorCode,ha as DAVE,ar as DEFAULT_MERKLE_TREE_HEIGHT,ur as DEFAULT_MERKLE_TREE_ROOTS,us as DEFAULT_ZERO,js as DerivationMode,st as FIELD_SIZE,it as HIGHEST_ADDRESS_PLUS_ONE,Ba as HashError,Aa as HashErrorCode,yi as HealthResult,d as IDL,ht as INSERT_INTO_QUEUES_DISCRIMINATOR,ct as INVOKE_CPI_DISCRIMINATOR,dt as INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR,lt as INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR,ut as INVOKE_DISCRIMINATOR,Or as InAccountLayout,as as IndexedArray,ss as IndexedElement,is as IndexedElementBundle,Yr as InsertAddressInputLayout,Zr as InsertNullifierInputLayout,Cr as InstructionDataInvokeCpiLayout,Dr as InstructionDataInvokeCpiWithReadOnlyLayout,kr as InstructionDataInvokeLayout,wi as LatestNonVotingSignaturesResult,vi as LatestNonVotingSignaturesResultPaginated,Qo as LightSystemProgram,Pa as LookupTableError,Ia as LookupTableErrorCode,_r as MerkleContextLayout,bi as MerkleProofResult,Ii as MerkleProofResultV2,cs as MerkleTree,Na as MerkleTreeError,xa as MerkleTreeErrorCode,Gr as MerkleTreeSequenceNumberLayout,li as MultipleCompressedAccountsResult,di as MultipleCompressedAccountsResultV2,Si as MultipleMerkleProofsResult,Ci as MultipleMerkleProofsResultV2,Bi as NativeBalanceResult,Lr as NewAddressParamsAssignedPackedLayout,Tr as NewAddressParamsLayout,Ai as NewAddressProofResult,Io as PackedAccounts,Nr as PackedMerkleContextLayout,Ur as PackedReadOnlyAddressLayout,Rr as PackedReadOnlyCompressedAccountLayout,La as ProofError,Ea as ProofErrorCode,Hr as PublicTransactionEventLayout,xi as RootIndexResultV2,sa as Rpc,Ca as RpcError,ba as RpcErrorCode,pr as STATE_MERKLE_TREE_NETWORK_FEE,hr as STATE_MERKLE_TREE_ROLLOVER_FEE,ka as SelectInUtxosError,wa as SelectInUtxosErrorCode,Vi as SignatureListResult,qi as SignatureListWithCursorResult,$i as SignatureSource,gi as SlotResult,Ao as SystemAccountMetaConfig,dr as TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD,aa as TestRpc,Ni as TokenBalanceListResult,Oi as TokenBalanceListResultV2,Li as TokenBalanceResult,ai as TokenDataResult,Je as TreeType,lr as UTXO_MERGE_MAXIMUM,cr as UTXO_MERGE_THRESHOLD,Oa as UtilsError,Ma as UtilsErrorCode,Ta as UtxoError,ya as UtxoErrorCode,et as VERSION,Mi as ValidityProofResult,ki as ValidityProofResultV2,mt as accountCompressionProgram,Rt as addressQueue,Ut as addressTree,yo as airdropSol,rr as batchAddressTree,Ht as batchCpiContext1,zt as batchCpiContext2,Yt as batchCpiContext3,Qt as batchCpiContext4,tr as batchCpiContext5,nr as batchMerkleTree,Ft as batchMerkleTree1,$t as batchMerkleTree2,Kt as batchMerkleTree3,Gt as batchMerkleTree4,Jt as batchMerkleTree5,or as batchQueue,Wt as batchQueue1,jt as batchQueue2,Zt as batchQueue3,Xt as batchQueue4,er as batchQueue5,br as bn,no as bufToDecStr,Uo as buildAndSignTx,Lo as buildTx,eo as byteArrayToKeypair,vo as calculateComputeUnitPrice,_o as checkValidityProofShape,es as compress,ir as confirmConfig,wo as confirmTransaction,Oo as confirmTx,lo as convertInvokeCpiWithReadOnlyToInvoke,Ji as convertMerkleProofsWithContextToHex,ea as convertNonInclusionMerkleProofInputsToHex,Qr as convertToPublicTransactionEvent,qt as cpiContext2Pubkey,Nt as cpiContextPubkey,ts as createAccount,rs as createAccountWithLamports,wr as createBN254,Ar as createCompressedAccountLegacy,Ir as createCompressedAccountMeta,Er as createCompressedAccountWithMerkleContextLegacy,xr as createMerkleContextLegacy,Yi as createRpc,Qs as createRpcResult,Do as createStateTreeLookupTable,qr as decodeInstructionDataInvoke,Fr as decodeInstructionDataInvokeCpi,Vr as decodeInstructionDataInvokeCpiWithReadOnly,jr as decodePublicTransactionEvent,ns as decompress,bo as dedupeSigner,fa as deepEqual,bt as defaultStateTreeLookupTables,wt as defaultStaticAccounts,vt as defaultStaticAccountsStruct,Mt as defaultTestStateTreeAccounts,_t as defaultTestStateTreeAccounts2,fo as deriveAddress,ho as deriveAddressSeed,po as deriveAddressSeedV2,mo as deriveAddressV2,Xr as deserializeAppendNullifyCreateAddressInputsIndexer,vr as encodeBN254toBase58,Sr as encodeInstructionDataInvoke,$r as encodePublicTransactionEvent,Vo as extendStateTreeLookupTable,nt as featureFlags,yt as getAccountCompressionAuthority,Zo as getAllStateTreeInfos,xt as getBatchAddressTreeInfo,bs as getCompressedTokenAccountByHashTest,ys as getCompressedTokenAccounts,vs as getCompressedTokenAccountsByDelegateTest,ws as getCompressedTokenAccountsByOwnerTest,ma as getConnection,At as getDefaultAddressSpace,Et as getDefaultAddressTreeInfo,Jr as getIndexOrAdd,Eo as getLightSystemAccountMetas,xo as getLightSystemAccountMetasV2,Fo as getOutputQueue,Wo as getOutputTreeInfo,ls as getParsedEvents,ra as getPublicInputHash,gt as getRegisteredProgramPda,Ho as getStateTreeInfoByPubkey,ga as getTestKeypair,ia as getTestRpc,$o as getTreeInfoByPubkey,io as hashToBn254FieldSizeBe,uo as hashvToBn254FieldSizeBe,ao as hashvToBn254FieldSizeBeU8Array,Wr as invokeAccountsLayout,zi as isDevnetCompat,It as isLocalTest,oo as isSmallerThanBn254FieldSizeBe,ei as jsonRpcResult,ti as jsonRpcResultAndContext,pt as lightSystemProgram,sr as localTestActiveStateTreeInfos,oa as mergeSignatures,Dt as merkleTree2Pubkey,Ot as merkletreePubkey,ko as negateAndCompressProof,pa as newAccountWithLamports,ft as noopProgram,Bt as nullifiedStateTreeLookupTableDevnet,Ct as nullifiedStateTreeLookupTableMainnet,Vt as nullifierQueue2Pubkey,Lt as nullifierQueuePubkey,qo as nullifyLookupTable,nn as packCompressedAccounts,Yo as packDecompressAccountsIdempotent,go as packNewAddressParams,rn as packTreeInfos,en as padOutputStateMerkleTrees,Ki as parseAccountData,ds as parseEvents,fs as parseLightTransaction,hs as parsePublicTransactionEventWithIdl,gs as parseTokenLayoutWithIdl,jo as pickRandomTreeAndQueue,Bo as pipe,Mo as placeholderValidityProof,To as proofFromJsonStruct,Qi as proverRequest,co as pushUniqueItems,Xi as rpcRequest,Jo as selectMinCompressedSolAccountsForTransfer,Ko as selectStateTreeInfo,No as sendAndConfirmTx,Ro as sleep,Pt as stateTreeLookupTableDevnet,St as stateTreeLookupTableMainnet,Go as sumUpLamports,tn as toAccountMetas,ro as toArray,so as toCamelCase,to as toHex,Di as toUnixTimestamp,os as transfer,ln as validateNumbers,un as validateNumbersForInclusionProof,cn as validateNumbersForNonInclusionProof,an as validateNumbersForProof,sn as validateSameOwner,on as validateSufficientBalance,ot as versionedEndpoint,Gi as wrapBigNumbersAsStrings};
1
+ import e,{PublicKey as t,Keypair as r,SystemProgram as n,TransactionMessage as o,VersionedTransaction as s,AddressLookupTableProgram as i,TransactionInstruction as a,ComputeBudgetProgram as u,Connection as c,SolanaJSONRPCError as l}from"@solana/web3.js";const d={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"}]};var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},f=[],p=[],m="undefined"!=typeof Uint8Array?Uint8Array:Array,g=0;function y(){g=1;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)f[t]=e[t],p[e.charCodeAt(t)]=t;p["-".charCodeAt(0)]=62,p["_".charCodeAt(0)]=63}function w(e,t,r){for(var n,o,s=[],i=t;i<r;i+=3)n=(e[i]<<16)+(e[i+1]<<8)+e[i+2],s.push(f[(o=n)>>18&63]+f[o>>12&63]+f[o>>6&63]+f[63&o]);return s.join("")}function v(e){var t;g||y();for(var r=e.length,n=r%3,o="",s=[],i=16383,a=0,u=r-n;a<u;a+=i)s.push(w(e,a,a+i>u?u:a+i));return 1===n?(t=e[r-1],o+=f[t>>2],o+=f[t<<4&63],o+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],o+=f[t>>10],o+=f[t>>4&63],o+=f[t<<2&63],o+="="),s.push(o),s.join("")}function b(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,f=e[t+d];for(d+=h,s=f&(1<<-l)-1,f>>=-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*(f?-1:1);i+=Math.pow(2,n),s-=c}return(f?-1:1)*i*Math.pow(2,s-n)}function I(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,f=n?0:s-1,p=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+f]=255&a,f+=p,a/=256,o-=8);for(i=i<<o|a,c+=o;c>0;e[r+f]=255&i,f+=p,i/=256,c-=8);e[r+f-p]|=128*m}var A={}.toString,E=Array.isArray||function(e){return"[object Array]"==A.call(e)};T.TYPED_ARRAY_SUPPORT=void 0!==h.TYPED_ARRAY_SUPPORT?h.TYPED_ARRAY_SUPPORT:1;var x=M();function M(){return T.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function _(e,t){if(M()<t)throw new RangeError("Invalid typed array length");return T.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=T.prototype:(null===e&&(e=new T(t)),e.length=t),e}function T(e,t,r){if(!(T.TYPED_ARRAY_SUPPORT||this instanceof T))return new T(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 C(this,e)}return S(this,e,t,r)}function S(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),T.TYPED_ARRAY_SUPPORT?(e=t).__proto__=T.prototype:e=P(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!T.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|O(t,r),o=(e=_(e,n)).write(t,r);return o!==n&&(e=e.slice(0,o)),e}(e,t,r):function(e,t){if(L(t)){var r=0|B(t.length);return 0===(e=_(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?_(e,0):P(e,t);if("Buffer"===t.type&&E(t.data))return P(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function k(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 C(e,t){if(k(t),e=_(e,t<0?0:0|B(t)),!T.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function P(e,t){var r=t.length<0?0:0|B(t.length);e=_(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function B(e){if(e>=M())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+M().toString(16)+" bytes");return 0|e}function L(e){return!(null==e||!e._isBuffer)}function O(e,t){if(L(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 ie(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return ae(e).length;default:if(n)return ie(e).length;t=(""+t).toLowerCase(),n=1}}function N(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 G(this,t,r);case"utf8":case"utf-8":return z(this,t,r);case"ascii":return Z(this,t,r);case"latin1":case"binary":return Y(this,t,r);case"base64":return j(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=1}}function R(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function U(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=T.from(t,n)),L(t))return 0===t.length?-1:D(e,t,r,n,o);if("number"==typeof t)return t&=255,T.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):D(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function D(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 V(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 q(e,t,r,n){return ue(ie(t,e.length-r),e,r,n)}function F(e,t,r,n){return ue(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function H(e,t,r,n){return F(e,t,r,n)}function W(e,t,r,n){return ue(ae(t),e,r,n)}function $(e,t,r,n){return ue(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 j(e,t,r){return 0===t&&r===e.length?v(e):v(e.slice(t,r))}function z(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<=K)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=K));return r}(n)}T.poolSize=8192,T._augment=function(e){return e.__proto__=T.prototype,e},T.from=function(e,t,r){return S(null,e,t,r)},T.TYPED_ARRAY_SUPPORT&&(T.prototype.__proto__=Uint8Array.prototype,T.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&T[Symbol.species]),T.alloc=function(e,t,r){return function(e,t,r,n){return k(t),t<=0?_(e,t):void 0!==r?"string"==typeof n?_(e,t).fill(r,n):_(e,t).fill(r):_(e,t)}(null,e,t,r)},T.allocUnsafe=function(e){return C(null,e)},T.allocUnsafeSlow=function(e){return C(null,e)},T.isBuffer=ce,T.compare=function(e,t){if(!L(e)||!L(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},T.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}},T.concat=function(e,t){if(!E(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return T.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=T.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(!L(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},T.byteLength=O,T.prototype._isBuffer=1,T.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)R(this,t,t+1);return this},T.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)R(this,t,t+3),R(this,t+1,t+2);return this},T.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)R(this,t,t+7),R(this,t+1,t+6),R(this,t+2,t+5),R(this,t+3,t+4);return this},T.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?z(this,0,e):N.apply(this,arguments)},T.prototype.equals=function(e){if(!L(e))throw new TypeError("Argument must be a Buffer");return this===e?1:0===T.compare(this,e)},T.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+">"},T.prototype.compare=function(e,t,r,n,o){if(!L(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},T.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},T.prototype.indexOf=function(e,t,r){return U(this,e,t,r,1)},T.prototype.lastIndexOf=function(e,t,r){return U(this,e,t,r,0)},T.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 V(this,e,t,r);case"utf8":case"utf-8":return q(this,e,t,r);case"ascii":return F(this,e,t,r);case"latin1":case"binary":return H(this,e,t,r);case"base64":return W(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=1}},T.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;function Z(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 Y(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 G(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 X(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 J(e,t,r,n,o,s){if(!L(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 ee(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 te(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 re(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 ne(e,t,r,n,o){return o||re(e,0,r,4),I(e,t,r,n,23,4),r+4}function oe(e,t,r,n,o){return o||re(e,0,r,8),I(e,t,r,n,52,8),r+8}T.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),T.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=T.prototype;else{var o=t-e;r=new T(o,void 0);for(var s=0;s<o;++s)r[s]=this[s+e]}return r},T.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},T.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},T.prototype.readUInt8=function(e,t){return t||Q(e,1,this.length),this[e]},T.prototype.readUInt16LE=function(e,t){return t||Q(e,2,this.length),this[e]|this[e+1]<<8},T.prototype.readUInt16BE=function(e,t){return t||Q(e,2,this.length),this[e]<<8|this[e+1]},T.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]},T.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])},T.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},T.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},T.prototype.readInt8=function(e,t){return t||Q(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},T.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},T.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},T.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},T.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]},T.prototype.readFloatLE=function(e,t){return t||Q(e,4,this.length),b(this,e,1,23,4)},T.prototype.readFloatBE=function(e,t){return t||Q(e,4,this.length),b(this,e,0,23,4)},T.prototype.readDoubleLE=function(e,t){return t||Q(e,8,this.length),b(this,e,1,52,8)},T.prototype.readDoubleBE=function(e,t){return t||Q(e,8,this.length),b(this,e,0,52,8)},T.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||J(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},T.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||J(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},T.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,1,255,0),T.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},T.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,65535,0),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ee(this,e,t,1),t+2},T.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,65535,0),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ee(this,e,t,0),t+2},T.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,4294967295,0),T.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):te(this,e,t,1),t+4},T.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,4294967295,0),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):te(this,e,t,0),t+4},T.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);J(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},T.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);J(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},T.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,1,127,-128),T.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},T.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,32767,-32768),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ee(this,e,t,1),t+2},T.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,2,32767,-32768),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ee(this,e,t,0),t+2},T.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,2147483647,-2147483648),T.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):te(this,e,t,1),t+4},T.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||J(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),T.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):te(this,e,t,0),t+4},T.prototype.writeFloatLE=function(e,t,r){return ne(this,e,t,1,r)},T.prototype.writeFloatBE=function(e,t,r){return ne(this,e,t,0,r)},T.prototype.writeDoubleLE=function(e,t,r){return oe(this,e,t,1,r)},T.prototype.writeDoubleBE=function(e,t,r){return oe(this,e,t,0,r)},T.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||!T.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},T.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&&!T.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=L(e)?e:ie(new T(e,n).toString()),a=i.length;for(s=0;s<r-t;++s)this[s+t]=i[s%a]}return this};var se=/[^+\/0-9A-Za-z-_]/g;function ie(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 ae(e){return function(e){var t,r,n,o,s,i;g||y();var a=e.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s="="===e[a-2]?2:"="===e[a-1]?1:0,i=new m(3*a/4-s),n=s>0?a-4:a;var u=0;for(t=0,r=0;t<n;t+=4,r+=3)o=p[e.charCodeAt(t)]<<18|p[e.charCodeAt(t+1)]<<12|p[e.charCodeAt(t+2)]<<6|p[e.charCodeAt(t+3)],i[u++]=o>>16&255,i[u++]=o>>8&255,i[u++]=255&o;return 2===s?(o=p[e.charCodeAt(t)]<<2|p[e.charCodeAt(t+1)]>>4,i[u++]=255&o):1===s&&(o=p[e.charCodeAt(t)]<<10|p[e.charCodeAt(t+1)]<<4|p[e.charCodeAt(t+2)]>>2,i[u++]=o>>8&255,i[u++]=255&o),i}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(se,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function ue(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 ce(e){return null!=e&&(!!e._isBuffer||le(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&le(e.slice(0,0))}(e))}function le(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var de=Object.freeze({__proto__:null,Buffer:T,INSPECT_MAX_BYTES:50,SlowBuffer:function(e){return+e!=e&&(e=0),T.alloc(+e)},isBuffer:ce,kMaxLength:x}),he="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function pe(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 me={},ge={};class ye{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 we(e,t){return t.property?e+"["+t.property+"]":e}ge.Layout=ye,ge.nameWithProperty=we,ge.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 ye))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 ve extends ye{isCount(){throw new Error("ExternalLayout is abstract")}}class be extends ve{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 Ie extends ve{constructor(e,t,r){if(!(e instanceof ye))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 Ae||this.layout instanceof Ee}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 Ae extends ye{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 Ee extends ye{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 xe extends ye{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 Me extends ye{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 _e=Math.pow(2,32);function Te(e){const t=Math.floor(e/_e);return{hi32:t,lo32:e-t*_e}}function Se(e,t){return e*_e+t}class ke extends ye{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Se(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class Ce extends ye{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Se(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Pe extends ye{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return Se(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Be extends ye{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),Se(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=Te(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Le extends ye{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 Oe extends ye{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 Ne extends ye{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 Re extends ye{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 Ue extends ye{constructor(e,t,r){if(!(e instanceof ye))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof ve&&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 ve)&&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 ve&&(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 ve&&(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 ve&&this.count.encode(e.length,t,r),o}}class De extends ye{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof ye),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 Ve{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class qe extends Ve{constructor(e,t){if(!(e instanceof ve&&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 Fe extends ye{constructor(e,t,r){const n=e instanceof Ae||e instanceof Ee;if(n)e=new qe(new Ie(e));else if(e instanceof ve&&e.isCount())e=new qe(e);else if(!(e instanceof Ve))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof ye))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 He(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 He extends ye{constructor(e,t,r,n){if(!(e instanceof Fe))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 ye))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 We(e){return 0>e&&(e+=4294967296),e}class $e extends ye{constructor(e,t,r){if(!(e instanceof Ae||e instanceof Ee))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=We(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 je(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new ze(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 je{constructor(e,t,r){if(!(e instanceof $e))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=We(this.valueMask<<this.start),this.property=r}decode(){return We(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==We(e&this.valueMask))throw new TypeError(we("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=We(e<<this.start);this.container._packedSetValue(We(t&~this.wordMask)|r)}}let ze=class extends je{constructor(e,t){super(e,1,t)}decode(e,t){return!!je.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),je.prototype.encode.call(this,e)}};class Ke extends ye{constructor(e,t){if(!(e instanceof ve&&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 ve||(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 ve&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(we("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 ve&&this.length.encode(n,t,r),n}}class Ze extends ye{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 Ye extends ye{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 Ge extends ye{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}ge.ExternalLayout=ve,ge.GreedyCount=be,ge.OffsetLayout=Ie,ge.UInt=Ae,ge.UIntBE=Ee,ge.Int=xe,ge.IntBE=Me,ge.Float=Le,ge.FloatBE=Oe,ge.Double=Ne,ge.DoubleBE=Re,ge.Sequence=Ue,ge.Structure=De,ge.UnionDiscriminator=Ve,ge.UnionLayoutDiscriminator=qe,ge.Union=Fe,ge.VariantLayout=He,ge.BitStructure=$e,ge.BitField=je,ge.Boolean=ze,ge.Blob=Ke,ge.CString=Ze,ge.UTF8=Ye,ge.Constant=Ge,ge.greedy=(e,t)=>new be(e,t),ge.offset=(e,t,r)=>new Ie(e,t,r),ge.u8=e=>new Ae(1,e),ge.u16=e=>new Ae(2,e),ge.u24=e=>new Ae(3,e),ge.u32=e=>new Ae(4,e),ge.u40=e=>new Ae(5,e),ge.u48=e=>new Ae(6,e),ge.nu64=e=>new ke(e),ge.u16be=e=>new Ee(2,e),ge.u24be=e=>new Ee(3,e),ge.u32be=e=>new Ee(4,e),ge.u40be=e=>new Ee(5,e),ge.u48be=e=>new Ee(6,e),ge.nu64be=e=>new Ce(e),ge.s8=e=>new xe(1,e),ge.s16=e=>new xe(2,e),ge.s24=e=>new xe(3,e),ge.s32=e=>new xe(4,e),ge.s40=e=>new xe(5,e),ge.s48=e=>new xe(6,e),ge.ns64=e=>new Pe(e),ge.s16be=e=>new Me(2,e),ge.s24be=e=>new Me(3,e),ge.s32be=e=>new Me(4,e),ge.s40be=e=>new Me(5,e),ge.s48be=e=>new Me(6,e),ge.ns64be=e=>new Be(e),ge.f32=e=>new Le(e),ge.f32be=e=>new Oe(e),ge.f64=e=>new Ne(e),ge.f64be=e=>new Re(e),ge.struct=(e,t,r)=>new De(e,t,r),ge.bits=(e,t,r)=>new $e(e,t,r),ge.seq=(e,t,r)=>new Ue(e,t,r),ge.union=(e,t,r)=>new Fe(e,t,r),ge.unionLayoutDiscriminator=(e,t)=>new qe(e,t),ge.blob=(e,t)=>new Ke(e,t),ge.cstr=e=>new Ze(e),ge.utf8=(e,t)=>new Ye(e,t),ge.const=(e,t)=>new Ge(e,t);var Xe={exports:{}},Qe=pe(de);!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 Xe?Xe.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],f=[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 p(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),f=Math.max(0,c-e.length+1);f<=h;f++){var p=c-f|0;l+=(i=(o=0|e.words[p])*(s=0|t.words[f])+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=f[e];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var m=p.modrn(l).toString(e);n=(p=p.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,f=0|i[1],p=8191&f,m=f>>>13,g=0|i[2],y=8191&g,w=g>>>13,v=0|i[3],b=8191&v,I=v>>>13,A=0|i[4],E=8191&A,x=A>>>13,M=0|i[5],_=8191&M,T=M>>>13,S=0|i[6],k=8191&S,C=S>>>13,P=0|i[7],B=8191&P,L=P>>>13,O=0|i[8],N=8191&O,R=O>>>13,U=0|i[9],D=8191&U,V=U>>>13,q=0|a[0],F=8191&q,H=q>>>13,W=0|a[1],$=8191&W,j=W>>>13,z=0|a[2],K=8191&z,Z=z>>>13,Y=0|a[3],G=8191&Y,X=Y>>>13,Q=0|a[4],J=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,fe=0|a[9],pe=8191&fe,me=fe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(c+(n=Math.imul(d,F))|0)+((8191&(o=(o=Math.imul(d,H))+Math.imul(h,F)|0))<<13)|0;c=((s=Math.imul(h,H))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(p,F),o=(o=Math.imul(p,H))+Math.imul(m,F)|0,s=Math.imul(m,H);var ye=(c+(n=n+Math.imul(d,$)|0)|0)+((8191&(o=(o=o+Math.imul(d,j)|0)+Math.imul(h,$)|0))<<13)|0;c=((s=s+Math.imul(h,j)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,F),o=(o=Math.imul(y,H))+Math.imul(w,F)|0,s=Math.imul(w,H),n=n+Math.imul(p,$)|0,o=(o=o+Math.imul(p,j)|0)+Math.imul(m,$)|0,s=s+Math.imul(m,j)|0;var we=(c+(n=n+Math.imul(d,K)|0)|0)+((8191&(o=(o=o+Math.imul(d,Z)|0)+Math.imul(h,K)|0))<<13)|0;c=((s=s+Math.imul(h,Z)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(b,F),o=(o=Math.imul(b,H))+Math.imul(I,F)|0,s=Math.imul(I,H),n=n+Math.imul(y,$)|0,o=(o=o+Math.imul(y,j)|0)+Math.imul(w,$)|0,s=s+Math.imul(w,j)|0,n=n+Math.imul(p,K)|0,o=(o=o+Math.imul(p,Z)|0)+Math.imul(m,K)|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,X)|0)+Math.imul(h,G)|0))<<13)|0;c=((s=s+Math.imul(h,X)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(E,F),o=(o=Math.imul(E,H))+Math.imul(x,F)|0,s=Math.imul(x,H),n=n+Math.imul(b,$)|0,o=(o=o+Math.imul(b,j)|0)+Math.imul(I,$)|0,s=s+Math.imul(I,j)|0,n=n+Math.imul(y,K)|0,o=(o=o+Math.imul(y,Z)|0)+Math.imul(w,K)|0,s=s+Math.imul(w,Z)|0,n=n+Math.imul(p,G)|0,o=(o=o+Math.imul(p,X)|0)+Math.imul(m,G)|0,s=s+Math.imul(m,X)|0;var be=(c+(n=n+Math.imul(d,J)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(h,J)|0))<<13)|0;c=((s=s+Math.imul(h,ee)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(_,F),o=(o=Math.imul(_,H))+Math.imul(T,F)|0,s=Math.imul(T,H),n=n+Math.imul(E,$)|0,o=(o=o+Math.imul(E,j)|0)+Math.imul(x,$)|0,s=s+Math.imul(x,j)|0,n=n+Math.imul(b,K)|0,o=(o=o+Math.imul(b,Z)|0)+Math.imul(I,K)|0,s=s+Math.imul(I,Z)|0,n=n+Math.imul(y,G)|0,o=(o=o+Math.imul(y,X)|0)+Math.imul(w,G)|0,s=s+Math.imul(w,X)|0,n=n+Math.imul(p,J)|0,o=(o=o+Math.imul(p,ee)|0)+Math.imul(m,J)|0,s=s+Math.imul(m,ee)|0;var Ie=(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)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(k,F),o=(o=Math.imul(k,H))+Math.imul(C,F)|0,s=Math.imul(C,H),n=n+Math.imul(_,$)|0,o=(o=o+Math.imul(_,j)|0)+Math.imul(T,$)|0,s=s+Math.imul(T,j)|0,n=n+Math.imul(E,K)|0,o=(o=o+Math.imul(E,Z)|0)+Math.imul(x,K)|0,s=s+Math.imul(x,Z)|0,n=n+Math.imul(b,G)|0,o=(o=o+Math.imul(b,X)|0)+Math.imul(I,G)|0,s=s+Math.imul(I,X)|0,n=n+Math.imul(y,J)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(p,re)|0,o=(o=o+Math.imul(p,ne)|0)+Math.imul(m,re)|0,s=s+Math.imul(m,ne)|0;var Ae=(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)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(B,F),o=(o=Math.imul(B,H))+Math.imul(L,F)|0,s=Math.imul(L,H),n=n+Math.imul(k,$)|0,o=(o=o+Math.imul(k,j)|0)+Math.imul(C,$)|0,s=s+Math.imul(C,j)|0,n=n+Math.imul(_,K)|0,o=(o=o+Math.imul(_,Z)|0)+Math.imul(T,K)|0,s=s+Math.imul(T,Z)|0,n=n+Math.imul(E,G)|0,o=(o=o+Math.imul(E,X)|0)+Math.imul(x,G)|0,s=s+Math.imul(x,X)|0,n=n+Math.imul(b,J)|0,o=(o=o+Math.imul(b,ee)|0)+Math.imul(I,J)|0,s=s+Math.imul(I,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(p,se)|0,o=(o=o+Math.imul(p,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(N,F),o=(o=Math.imul(N,H))+Math.imul(R,F)|0,s=Math.imul(R,H),n=n+Math.imul(B,$)|0,o=(o=o+Math.imul(B,j)|0)+Math.imul(L,$)|0,s=s+Math.imul(L,j)|0,n=n+Math.imul(k,K)|0,o=(o=o+Math.imul(k,Z)|0)+Math.imul(C,K)|0,s=s+Math.imul(C,Z)|0,n=n+Math.imul(_,G)|0,o=(o=o+Math.imul(_,X)|0)+Math.imul(T,G)|0,s=s+Math.imul(T,X)|0,n=n+Math.imul(E,J)|0,o=(o=o+Math.imul(E,ee)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,ee)|0,n=n+Math.imul(b,re)|0,o=(o=o+Math.imul(b,ne)|0)+Math.imul(I,re)|0,s=s+Math.imul(I,ne)|0,n=n+Math.imul(y,se)|0,o=(o=o+Math.imul(y,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,n=n+Math.imul(p,ue)|0,o=(o=o+Math.imul(p,ce)|0)+Math.imul(m,ue)|0,s=s+Math.imul(m,ce)|0;var xe=(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)+(xe>>>26)|0,xe&=67108863,n=Math.imul(D,F),o=(o=Math.imul(D,H))+Math.imul(V,F)|0,s=Math.imul(V,H),n=n+Math.imul(N,$)|0,o=(o=o+Math.imul(N,j)|0)+Math.imul(R,$)|0,s=s+Math.imul(R,j)|0,n=n+Math.imul(B,K)|0,o=(o=o+Math.imul(B,Z)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,Z)|0,n=n+Math.imul(k,G)|0,o=(o=o+Math.imul(k,X)|0)+Math.imul(C,G)|0,s=s+Math.imul(C,X)|0,n=n+Math.imul(_,J)|0,o=(o=o+Math.imul(_,ee)|0)+Math.imul(T,J)|0,s=s+Math.imul(T,ee)|0,n=n+Math.imul(E,re)|0,o=(o=o+Math.imul(E,ne)|0)+Math.imul(x,re)|0,s=s+Math.imul(x,ne)|0,n=n+Math.imul(b,se)|0,o=(o=o+Math.imul(b,ie)|0)+Math.imul(I,se)|0,s=s+Math.imul(I,ie)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(p,de)|0,o=(o=o+Math.imul(p,he)|0)+Math.imul(m,de)|0,s=s+Math.imul(m,he)|0;var Me=(c+(n=n+Math.imul(d,pe)|0)|0)+((8191&(o=(o=o+Math.imul(d,me)|0)+Math.imul(h,pe)|0))<<13)|0;c=((s=s+Math.imul(h,me)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,$),o=(o=Math.imul(D,j))+Math.imul(V,$)|0,s=Math.imul(V,j),n=n+Math.imul(N,K)|0,o=(o=o+Math.imul(N,Z)|0)+Math.imul(R,K)|0,s=s+Math.imul(R,Z)|0,n=n+Math.imul(B,G)|0,o=(o=o+Math.imul(B,X)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,X)|0,n=n+Math.imul(k,J)|0,o=(o=o+Math.imul(k,ee)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,ee)|0,n=n+Math.imul(_,re)|0,o=(o=o+Math.imul(_,ne)|0)+Math.imul(T,re)|0,s=s+Math.imul(T,ne)|0,n=n+Math.imul(E,se)|0,o=(o=o+Math.imul(E,ie)|0)+Math.imul(x,se)|0,s=s+Math.imul(x,ie)|0,n=n+Math.imul(b,ue)|0,o=(o=o+Math.imul(b,ce)|0)+Math.imul(I,ue)|0,s=s+Math.imul(I,ce)|0,n=n+Math.imul(y,de)|0,o=(o=o+Math.imul(y,he)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,he)|0;var _e=(c+(n=n+Math.imul(p,pe)|0)|0)+((8191&(o=(o=o+Math.imul(p,me)|0)+Math.imul(m,pe)|0))<<13)|0;c=((s=s+Math.imul(m,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(D,K),o=(o=Math.imul(D,Z))+Math.imul(V,K)|0,s=Math.imul(V,Z),n=n+Math.imul(N,G)|0,o=(o=o+Math.imul(N,X)|0)+Math.imul(R,G)|0,s=s+Math.imul(R,X)|0,n=n+Math.imul(B,J)|0,o=(o=o+Math.imul(B,ee)|0)+Math.imul(L,J)|0,s=s+Math.imul(L,ee)|0,n=n+Math.imul(k,re)|0,o=(o=o+Math.imul(k,ne)|0)+Math.imul(C,re)|0,s=s+Math.imul(C,ne)|0,n=n+Math.imul(_,se)|0,o=(o=o+Math.imul(_,ie)|0)+Math.imul(T,se)|0,s=s+Math.imul(T,ie)|0,n=n+Math.imul(E,ue)|0,o=(o=o+Math.imul(E,ce)|0)+Math.imul(x,ue)|0,s=s+Math.imul(x,ce)|0,n=n+Math.imul(b,de)|0,o=(o=o+Math.imul(b,he)|0)+Math.imul(I,de)|0,s=s+Math.imul(I,he)|0;var Te=(c+(n=n+Math.imul(y,pe)|0)|0)+((8191&(o=(o=o+Math.imul(y,me)|0)+Math.imul(w,pe)|0))<<13)|0;c=((s=s+Math.imul(w,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(D,G),o=(o=Math.imul(D,X))+Math.imul(V,G)|0,s=Math.imul(V,X),n=n+Math.imul(N,J)|0,o=(o=o+Math.imul(N,ee)|0)+Math.imul(R,J)|0,s=s+Math.imul(R,ee)|0,n=n+Math.imul(B,re)|0,o=(o=o+Math.imul(B,ne)|0)+Math.imul(L,re)|0,s=s+Math.imul(L,ne)|0,n=n+Math.imul(k,se)|0,o=(o=o+Math.imul(k,ie)|0)+Math.imul(C,se)|0,s=s+Math.imul(C,ie)|0,n=n+Math.imul(_,ue)|0,o=(o=o+Math.imul(_,ce)|0)+Math.imul(T,ue)|0,s=s+Math.imul(T,ce)|0,n=n+Math.imul(E,de)|0,o=(o=o+Math.imul(E,he)|0)+Math.imul(x,de)|0,s=s+Math.imul(x,he)|0;var Se=(c+(n=n+Math.imul(b,pe)|0)|0)+((8191&(o=(o=o+Math.imul(b,me)|0)+Math.imul(I,pe)|0))<<13)|0;c=((s=s+Math.imul(I,me)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(D,J),o=(o=Math.imul(D,ee))+Math.imul(V,J)|0,s=Math.imul(V,ee),n=n+Math.imul(N,re)|0,o=(o=o+Math.imul(N,ne)|0)+Math.imul(R,re)|0,s=s+Math.imul(R,ne)|0,n=n+Math.imul(B,se)|0,o=(o=o+Math.imul(B,ie)|0)+Math.imul(L,se)|0,s=s+Math.imul(L,ie)|0,n=n+Math.imul(k,ue)|0,o=(o=o+Math.imul(k,ce)|0)+Math.imul(C,ue)|0,s=s+Math.imul(C,ce)|0,n=n+Math.imul(_,de)|0,o=(o=o+Math.imul(_,he)|0)+Math.imul(T,de)|0,s=s+Math.imul(T,he)|0;var ke=(c+(n=n+Math.imul(E,pe)|0)|0)+((8191&(o=(o=o+Math.imul(E,me)|0)+Math.imul(x,pe)|0))<<13)|0;c=((s=s+Math.imul(x,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(D,re),o=(o=Math.imul(D,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(R,se)|0,s=s+Math.imul(R,ie)|0,n=n+Math.imul(B,ue)|0,o=(o=o+Math.imul(B,ce)|0)+Math.imul(L,ue)|0,s=s+Math.imul(L,ce)|0,n=n+Math.imul(k,de)|0,o=(o=o+Math.imul(k,he)|0)+Math.imul(C,de)|0,s=s+Math.imul(C,he)|0;var Ce=(c+(n=n+Math.imul(_,pe)|0)|0)+((8191&(o=(o=o+Math.imul(_,me)|0)+Math.imul(T,pe)|0))<<13)|0;c=((s=s+Math.imul(T,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(D,se),o=(o=Math.imul(D,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(R,ue)|0,s=s+Math.imul(R,ce)|0,n=n+Math.imul(B,de)|0,o=(o=o+Math.imul(B,he)|0)+Math.imul(L,de)|0,s=s+Math.imul(L,he)|0;var Pe=(c+(n=n+Math.imul(k,pe)|0)|0)+((8191&(o=(o=o+Math.imul(k,me)|0)+Math.imul(C,pe)|0))<<13)|0;c=((s=s+Math.imul(C,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(D,ue),o=(o=Math.imul(D,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(R,de)|0,s=s+Math.imul(R,he)|0;var Be=(c+(n=n+Math.imul(B,pe)|0)|0)+((8191&(o=(o=o+Math.imul(B,me)|0)+Math.imul(L,pe)|0))<<13)|0;c=((s=s+Math.imul(L,me)|0)+(o>>>13)|0)+(Be>>>26)|0,Be&=67108863,n=Math.imul(D,de),o=(o=Math.imul(D,he))+Math.imul(V,de)|0,s=Math.imul(V,he);var Le=(c+(n=n+Math.imul(N,pe)|0)|0)+((8191&(o=(o=o+Math.imul(N,me)|0)+Math.imul(R,pe)|0))<<13)|0;c=((s=s+Math.imul(R,me)|0)+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863;var Oe=(c+(n=Math.imul(D,pe))|0)+((8191&(o=(o=Math.imul(D,me))+Math.imul(V,pe)|0))<<13)|0;return c=((s=Math.imul(V,me))+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=ve,u[4]=be,u[5]=Ie,u[6]=Ae,u[7]=Ee,u[8]=xe,u[9]=Me,u[10]=_e,u[11]=Te,u[12]=Se,u[13]=ke,u[14]=Ce,u[15]=Pe,u[16]=Be,u[17]=Le,u[18]=Oe,0!==c&&(u[19]=c,r.length++),r};function g(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,o=0,s=0;s<r.length-1;s++){var i=o;o=0;for(var a=67108863&n,u=Math.min(s,t.length-1),c=Math.max(0,s-e.length+1);c<=u;c++){var l=s-c,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 y(e,t,r){return g(e,t,r)}Math.imul||(m=p),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?p(this,e,t):r<1024?g(this,e,t):y(this,e,t)},o.prototype.mul=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),y(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){var t=e<0;t&&(e=-e),r("number"==typeof e),r(e<67108864);for(var n=0,o=0;o<this.length;o++){var s=(0|this.words[o])*e,i=(67108863&s)+(67108863&n);n>>=26,n+=s/67108864|0,n+=i>>>26,this.words[o]=67108863&i}return 0!==n&&(this.words[o]=n,this.length++),t?this.ineg():this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=e.words[n]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n<t.length&&0===t[n];n++,r=r.sqr());if(++n<t.length)for(var s=r.sqr();n<t.length;n++,s=s.sqr())0!==t[n]&&(r=r.mul(s));return r},o.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,n=e%26,o=(e-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var i=0;for(t=0;t<this.length;t++){var a=this.words[t]&s,u=(0|this.words[t])-a<<n;this.words[t]=u|i,i=a>>>26-n}i&&(this.words[t]=i,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(e){return r(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,n){var o;r("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var s=e%26,i=Math.min((e-s)/26,this.length),a=67108863^67108863>>>s<<s,u=n;if(o-=i,o=Math.max(0,o),u){for(var c=0;c<i;c++)u.words[c]=this.words[c];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,c=0;c<this.length;c++)this.words[c]=this.words[c+i];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var 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,f=1;0==(t.words[0]&f)&&h<26;++h,f<<=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 p=0,m=1;0==(n.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(n.iushrn(p);p-- >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 x(e)},o.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var w={k256:null,p224:null,p192:null,p25519:null};function v(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function I(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function x(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function M(e){x.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},v.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(e,t){e.iushrn(this.n,0,t)},v.prototype.imulK=function(e){return e.imul(this.k)},n(b,v),b.prototype.split=function(e,t){for(var r=4194303,n=Math.min(e.length,9),o=0;o<n;o++)t.words[o]=e.words[o];if(t.length=n,e.length<=9)return e.words[0]=0,void(e.length=1);var s=e.words[9];for(t.words[t.length++]=s&r,o=10;o<e.length;o++){var i=0|e.words[o];e.words[o-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,e.words[o-10]=s,0===s&&e.length>10?e.length-=10:e.length-=9},b.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(I,v),n(A,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 b;else if("p224"===e)t=new I;else if("p192"===e)t=new A;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new E}return w[e]=t,t},x.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},x.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")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.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)},x.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},x.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)},x.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},x.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},x.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},x.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.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)),f=this.pow(e,s),p=i;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<p);var y=this.pow(d,new o(1).iushln(p-g-1));h=h.redMul(y),d=y.redSqr(),f=f.redMul(d),p=g}return h},x.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},x.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},x.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},x.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new M(e)},n(M,x),M.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},M.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},M.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},M.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(n).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},M.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,he);var Je,et,tt=Xe.exports,rt=fe(tt);!function(t){var r=he&&he.__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=ge,o=e,s=r(tt);var i=ge;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 f(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=f,t.str=function(e){return new c(f(),(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 p 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 p(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)}}(me),function(e){e[e.StateV1=1]="StateV1",e[e.AddressV1=2]="AddressV1",e[e.StateV2=3]="StateV2",e[e.AddressV2=4]="AddressV2"}(Je||(Je={})),function(e){e.V1="V1",e.V2="V2"}(et||(et={}));const nt={version:'"V2"',isV2:()=>"V2"===nt.version.replace(/['"]/g,"").toUpperCase(),isBeta:()=>{if("undefined"!=typeof process&&process.env?.LIGHT_PROTOCOL_BETA){const e=process.env.LIGHT_PROTOCOL_BETA.toLowerCase();return"true"===e||"1"===e}return 0}},ot="Interface methods require beta feature flag. These features are not yet deployed on mainnet (only localnet/devnet). Set LIGHT_PROTOCOL_BETA=true to enable.";function st(){if(!nt.isV2())throw new Error("Interface methods require V2. Set LIGHT_PROTOCOL_VERSION=V2.");if(!nt.isBeta())throw new Error(ot)}const it=e=>nt.isV2()?`${e}V2`:e,at=new rt("21888242871839275222246405745257275088548364400416034343698204186575808495617"),ut=new rt("452312848583266388373324160190187140051835877600158453279131187530910662655"),ct=[2,64,66,15,0],lt=T.from([26,16,169,7,21,202,242,25]),dt=T.from([49,212,191,129,39,194,43,196]),ht=T.from([86,47,163,166,21,223,92,8]),ft=T.from([228,34,128,84,47,139,86,240]),pt=T.from([180,143,159,153,35,46,248,163]),mt="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",gt="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",yt="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",wt=()=>new t("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),vt=()=>t.findProgramAddressSync([T.from("cpi_authority")],new t(gt))[0],bt=()=>[new t(wt()),new t(mt),new t(yt),new t(vt())],It=()=>({registeredProgramPda:new t(wt()),noopProgram:new t(mt),accountCompressionProgram:new t(yt),accountCompressionAuthority:new t(vt()),cpiSignatureAccount:null}),At=()=>({mainnet:[{stateTreeLookupTable:new t(Pt),nullifyLookupTable:new t(Bt)}],devnet:[{stateTreeLookupTable:new t(Lt),nullifyLookupTable:new t(Ot)}]}),Et=e=>e.includes("localhost")||e.includes("127.0.0.1"),xt=()=>_t(),Mt=()=>nt.isV2()?_t():{tree:new t(Dt),queue:new t(Vt),cpiContext:void 0,treeType:Je.AddressV1,nextTreeInfo:null},_t=()=>({tree:new t(or),queue:new t(or),cpiContext:void 0,treeType:Je.AddressV2,nextTreeInfo:null}),Tt=()=>({nullifierQueue:new t(Nt),merkleTree:new t(Ut),merkleTreeHeight:cr,addressTree:new t(Dt),addressQueue:new t(Vt)}),St=()=>({nullifierQueue2:new t(Ft),merkleTree2:new t(qt)}),kt=new t("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),Ct=kt,Pt="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",Bt="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",Lt="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",Ot="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",Nt="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",Rt="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",Ut="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",Dt="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",Vt="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",qt="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Ft="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",Ht="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",Wt="bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU",$t="oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto",jt="cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y",zt="bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi",Kt="oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg",Zt="cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B",Yt="bmt3ccLd4bqSVZVeCJnH1F6C8jNygAhaDfxDwePyyGb",Gt="oq3AxjekBWgo64gpauB6QtuZNesuv19xrhaC1ZM1THQ",Xt="cpi3mbwMpSX8FAGMZVP85AwxqCaQMfEk9Em1v8QK9Rf",Qt="bmt4d3p1a4YQgk9PeZv5s4DBUmbF5NxqYpk9HGjQsd8",Jt="oq4ypwvVGzCUMoiKKHWh4S1SgZJ9vCvKpcz6RT6A8dq",er="cpi4yyPDc4bCgHAnsenunGA8Y77j3XEDyjgfyCKgcoc",tr="bmt5yU97jC88YXTuSukYHa8Z5Bi2ZDUtmzfkDTA2mG2",rr="oq5oh5ZR3yGomuQgFduNDzjtGvVWfDRGLuDVjv9a96P",nr="cpi5ZTjdgYpZ1Xr7B1cMLLUE81oTtJbNNAyKary2nV6",or="amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx",sr=Wt,ir=$t,ar=()=>{const e=[[Wt,$t,jt],[zt,Kt,Zt],[Yt,Gt,Xt],[Qt,Jt,er],[tr,rr,nr]],r=or,n=[[Ut,Nt,Rt],[qt,Ft,Ht]].map((([e,r,n])=>({tree:new t(e),queue:new t(r),cpiContext:new t(n),treeType:Je.StateV1,nextTreeInfo:null}))),o=e.map((([e,r,n])=>({tree:new t(e),queue:new t(r),cpiContext:new t(n),treeType:Je.StateV2,nextTreeInfo:null}))),s={tree:new t(r),queue:new t(r),cpiContext:t.default,treeType:Je.AddressV2,nextTreeInfo:null};return nt.isV2()?[...n,...o,s]:n},ur={commitment:"confirmed",preflightCommitment:"confirmed"},cr=26,lr=2800,dr=20,hr=10,fr=new rt(Math.floor(2**cr*.95)),pr=nt.isV2()?new rt(1):new rt(300),mr=(nt.isV2(),new rt(392)),gr=new rt(5e3),yr=new rt(5e3),wr=new rt(1e4);var vr=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 br=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return br(vr.decode(e))}return function(e){if(e.gte(at))throw new Error("Value is too large. Max <254 bits");return e}(new rt(e,t))};function Ir(e){const t=br(e).toArrayLike(T,void 0,32);return vr.encode(new Uint8Array(t))}const Ar=(e,t,r)=>e instanceof Uint8Array&&!(e instanceof T)?new rt(T.from(e),t,r):new rt(e,t,r),Er=(e,t,r,n)=>({treeInfo:e,outputStateTreeIndex:t,address:r??null,lamports:n??null}),xr=(e,t,r,n)=>({owner:e,lamports:t??new rt(0),address:n??null,data:r??null}),Mr=(e,t,r,n,o)=>({...e,owner:t,lamports:r??new rt(0),address:o??null,data:n??null,readOnly:0}),_r=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n}),Tr=me.struct([me.publicKey("owner"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address"),me.option(me.struct([me.array(me.u8(),8,"discriminator"),me.vecU8("data"),me.array(me.u8(),32,"dataHash")]),"data")],"compressedAccount"),Sr=me.struct([me.u8("merkleTreePubkeyIndex"),me.u8("queuePubkeyIndex"),me.u32("leafIndex"),me.bool("proveByIndex")],"merkleContext"),kr=me.struct([me.array(me.u8(),32,"seed"),me.u8("addressQueueAccountIndex"),me.u8("addressMerkleTreeAccountIndex"),me.u16("addressMerkleTreeRootIndex")],"newAddressParams"),Cr=me.struct([me.option(me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")]),"proof"),me.vec(me.struct([Tr,Sr,me.u16("rootIndex"),me.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),me.vec(me.struct([Tr,me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.option(me.u64(),"relayFee"),me.vec(kr,"newAddressParams"),me.option(me.u64(),"compressOrDecompressLamports"),me.bool("isCompress")]);function Pr(e){const t=T.alloc(1e3),r=Cr.encode(e,t),n=T.from(new Uint8Array(t.slice(0,r))),o=T.alloc(4);return o.writeUInt32LE(r,0),T.concat([new Uint8Array(lt),new Uint8Array(o),new Uint8Array(n)])}const Br=me.struct([me.option(me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")]),"proof"),me.vec(kr,"newAddressParams"),me.vec(me.struct([Tr,Sr,me.u16("rootIndex"),me.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),me.vec(me.struct([Tr,me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.option(me.u64(),"relayFee"),me.option(me.u64(),"compressOrDecompressLamports"),me.bool("isCompress"),me.option(me.struct([me.bool("set_context"),me.bool("first_set_context"),me.u8("cpi_context_account_index")]),"compressedCpiContext")]),Lr=me.struct([me.array(me.u8(),32,"a"),me.array(me.u8(),64,"b"),me.array(me.u8(),32,"c")],"compressedProof"),Or=me.struct([me.bool("set_context"),me.bool("first_set_context"),me.u8("cpi_context_account_index")],"compressedCpiContext"),Nr=me.struct([me.array(me.u8(),32,"seed"),me.u8("address_queue_account_index"),me.u8("address_merkle_tree_account_index"),me.u16("address_merkle_tree_root_index"),me.bool("assigned_to_account"),me.u8("assigned_account_index")],"newAddressParamsAssignedPacked"),Rr=me.struct([me.u8("merkle_tree_pubkey_index"),me.u8("queue_pubkey_index"),me.u32("leaf_index"),me.bool("prove_by_index")],"packedMerkleContext"),Ur=me.struct([me.array(me.u8(),8,"discriminator"),me.array(me.u8(),32,"data_hash"),Rr,me.u16("root_index"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address")],"inAccount"),Dr=me.struct([me.array(me.u8(),32,"address"),me.u16("address_merkle_tree_root_index"),me.u8("address_merkle_tree_account_index")],"packedReadOnlyAddress"),Vr=me.struct([me.array(me.u8(),32,"account_hash"),Rr,me.u16("root_index")],"packedReadOnlyCompressedAccount"),qr=me.struct([me.u8("mode"),me.u8("bump"),me.publicKey("invoking_program_id"),me.u64("compress_or_decompress_lamports"),me.bool("is_compress"),me.bool("with_cpi_context"),me.bool("with_transaction_hash"),Or,me.option(Lr,"proof"),me.vec(Nr,"new_address_params"),me.vec(Ur,"input_compressed_accounts"),me.vec(me.struct([Tr,me.u8("merkleTreeIndex")]),"output_compressed_accounts"),me.vec(Dr,"read_only_addresses"),me.vec(Vr,"read_only_accounts")]);function Fr(e){return qr.decode(e.slice(ht.length))}function Hr(e){return Cr.decode(e.slice(lt.length+4))}function Wr(e){return Br.decode(e.slice(dt.length+4))}const $r=e=>{const t=ns.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:u??t,isSigner:0,isWritable:null!==u},{pubkey:c??t,isSigner:0,isWritable:1},{pubkey:l,isSigner:0,isWritable:0}]},jr=me.struct([me.vec(me.array(me.u8(),32),"inputCompressedAccountHashes"),me.vec(me.array(me.u8(),32),"outputCompressedAccountHashes"),me.vec(me.struct([me.struct([me.publicKey("owner"),me.u64("lamports"),me.option(me.array(me.u8(),32),"address"),me.option(me.struct([me.array(me.u8(),8,"discriminator"),me.vecU8("data"),me.array(me.u8(),32,"dataHash")]),"data")],"compressedAccount"),me.u8("merkleTreeIndex")]),"outputCompressedAccounts"),me.vec(me.u32(),"outputLeafIndices"),me.vec(me.struct([me.publicKey("tree_pubkey"),me.publicKey("queue_pubkey"),me.u64("tree_type"),me.u64("seq")]),"sequenceNumbers"),me.option(me.u64(),"relayFee"),me.bool("isCompress"),me.option(me.u64(),"compressOrDecompressLamports"),me.vec(me.publicKey(),"pubkeyArray"),me.option(me.vecU8(),"message")]);function zr(e){const t=T.alloc(1e3),r=jr.encode(e,t);return t.slice(0,r)}function Kr(e){return jr.decode(e)}const Zr=me.struct([me.u8("is_invoked_by_program"),me.u8("bump"),me.u8("num_queues"),me.u8("num_output_queues"),me.u8("start_output_appends"),me.u8("num_address_queues"),me.array(me.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),Yr=me.struct([me.u8("index"),me.array(me.u8(),32,"leaf")],"appendLeavesInput"),Gr=me.struct([me.array(me.u8(),32,"account_hash"),me.u32("leaf_index"),me.u8("prove_by_index"),me.u8("tree_index"),me.u8("queue_index")],"insertNullifierInput"),Xr=me.struct([me.array(me.u8(),32,"address"),me.u8("tree_index"),me.u8("queue_index")],"insertAddressInput"),Qr=me.struct([me.publicKey("tree_pubkey"),me.publicKey("queue_pubkey"),me.u64("tree_type"),me.u64("seq")],"merkleTreeSequenceNumber");function Jr(e){let t=0;const r=Zr.decode(e,t);t+=Zr.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=Yr.decode(e,t);o.push(r),t+=Yr.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=Gr.decode(e,t);i.push(r),t+=Gr.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=Xr.decode(e,t);u.push(r),t+=Xr.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=Qr.decode(e,t);l.push(r),t+=Qr.span}const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)Qr.decode(e,t),t+=Qr.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)Qr.decode(e,t),t+=Qr.span;const f=e.readUInt8(t);t+=1;const p=[];for(let r=0;r<f;r++){const r=me.u32().decode(e,t);p.push(r),t+=4}return{meta:r,leaves:o,nullifiers:i,addresses:u,sequence_numbers:l,output_leaf_indices:p}}function en(e,r,n){const o=e=>Array.from(e instanceof T?new Uint8Array(e):e);return{inputCompressedAccountHashes:e.nullifiers.map((e=>o(e.account_hash))),outputCompressedAccountHashes:e.leaves.map((e=>o(e.leaf))),outputCompressedAccounts:e.leaves.map(((e,r)=>({compressedAccount:{owner:new t(n?.outputCompressedAccounts[r]?.compressedAccount.owner||t.default),lamports:Ar(n?.outputCompressedAccounts[r]?.compressedAccount.lamports||0),address:n?.outputCompressedAccounts[r].compressedAccount.address,data:n?.outputCompressedAccounts[r]?.compressedAccount.data?{discriminator:o(T.from(n.outputCompressedAccounts[r].compressedAccount.data?.discriminator)),data:o(T.from(new Uint8Array(n.outputCompressedAccounts[r].compressedAccount.data.data)))??[],dataHash:o(T.from(n.outputCompressedAccounts[r].compressedAccount.data?.dataHash))}:null},merkleTreeIndex:e.index}))),outputLeafIndices:e.output_leaf_indices,sequenceNumbers:e.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((e=>!e.equals(t.default))),isCompress:n?.isCompress||0,relayFee:n?.relayFee?Ar(n.relayFee):null,compressOrDecompressLamports:n?.compressOrDecompressLamports?Ar(n.compressOrDecompressLamports):null,message:null}}function tn(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function rn(e,t){return t<=0?[]:new Array(t).fill(e)}function nn(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function on(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=tn(n,e.treeInfo.tree),r=tn(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===Je.StateV2){if(!nt.isV2())throw new Error("V2 trees are not supported yet");r=e.queue}i=tn(n,r)}return r.forEach((e=>{const t=tn(n,e.treeInfo.tree),r=tn(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}}function sn(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=tn(s,e.treeInfo.tree),o=tn(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===Je.StateV2){if(!nt.isV2())throw new Error("V2 trees are not supported yet");l=c.queue}const d=rn(l,r.length);return r.forEach(((e,t)=>{const r=tn(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 an=e=>{if(e.lt(Ar(0)))throw new Error("Insufficient balance for transfer")},un=e=>{if(0===e.length)throw new Error("No accounts provided for validation");const t=e[0].owner;if(!e.every((e=>e.owner.equals(t))))throw new Error("All input accounts must have the same owner")},cn=(e,t)=>{if(e>0&&t>0){if(8===e)throw new Error(`Invalid number of compressed accounts for proof: ${e}. Allowed numbers: ${[1,2,3,4].join(", ")}`);hn(e,[1,2,3,4],"compressed accounts"),dn(t)}else e>0?ln(e):dn(t)},ln=e=>{hn(e,[1,2,3,4,8],"compressed accounts")},dn=e=>{hn(e,[1,2],"new addresses")},hn=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function fn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function pn(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 mn(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 gn=BigInt(2**32-1),yn=BigInt(32);function wn(e,t=0){return t?{h:Number(e&gn),l:Number(e>>yn&gn)}:{h:0|Number(e>>yn&gn),l:0|Number(e&gn)}}function vn(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}=wn(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const bn=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function In(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 An(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)),pn(e),e}class En{clone(){return this._cloneInto()}}const xn=[],Mn=[],_n=[],Tn=BigInt(0),Sn=BigInt(1),kn=BigInt(2),Cn=BigInt(7),Pn=BigInt(256),Bn=BigInt(113);for(let e=0,t=Sn,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],xn.push(2*(5*n+r)),Mn.push((e+1)*(e+2)/2%64);let o=Tn;for(let e=0;e<7;e++)t=(t<<Sn^(t>>Cn)*Bn)%Pn,t&kn&&(o^=Sn<<(Sn<<BigInt(e))-Sn);_n.push(o)}const[Ln,On]=vn(_n,1),Nn=(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),Rn=(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 Un extends En{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,fn(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(){bn||In(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=Nn(s,i,1)^r[n],u=Rn(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=Mn[r],s=Nn(t,o,n),i=Rn(t,o,n),a=xn[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]^=Ln[n],e[1]^=On[n]}r.fill(0)}(this.state32,this.rounds),bn||In(this.state32),this.posOut=0,this.pos=0}update(e){mn(this);const{blockLen:t,state:r}=this,n=(e=An(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){mn(this,0),pn(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 fn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){pn(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 Un(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 Dn=(()=>function(e){const t=t=>e().update(An(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new Un(136,1,32))))(),Vn=e=>"object"==typeof e&&null!==e,qn=e=>Vn(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),Fn=Symbol("mapObjectSkip"),Hn=(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=>qn(e)?Hn(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===Fn)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&qn(l)&&(l=Array.isArray(l)?s(l):Hn(l,t,r,n)),o[c]=l)}return o};function Wn(e,t,r){if(!Vn(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return Hn(e,t,r)}const $n=/[\p{Lu}]/u,jn=/[\p{Ll}]/u,zn=/^[\p{Lu}](?![\p{Lu}])/gu,Kn=/([\p{Alpha}\p{N}_]|$)/u,Zn=/[_.\- ]+/,Yn=new RegExp("^"+Zn.source),Gn=new RegExp(Zn.source+Kn.source,"gu"),Xn=new RegExp("\\d+"+Kn.source,"gu");class Qn 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 Jn=new Qn({maxSize:1e5}),eo=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),to=(e,t={})=>{if(!eo(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&&eo(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=Wn(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(Jn.has(e))t=Jn.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?Zn.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&&$n.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&jn.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(Yn,""),e=t.preserveConsecutiveUppercase?((e,t)=>(zn.lastIndex=0,e.replaceAll(zn,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>(Gn.lastIndex=0,Xn.lastIndex=0,e.replaceAll(Xn,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll(Gn,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&Jn.set(e,r),t=r}}return[t,o]};return Wn(e,u(void 0))};function ro(e){return r.fromSecretKey(Uint8Array.from(e))}function no(e){return"0x"+e.toString("hex")}const oo=e=>Array.isArray(e)?e:[e],so=e=>br(e).toString();function io(e){return Ar(e,void 0,"be").lt(at)}const ao=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>to(t[e],r))):to(t,r);var t,r};function uo(e){let t=255;for(;t>=0;){const r=T.concat([e,T.from([t])]),n=Dn(r);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,io(T.from(n)))return[T.from(n),t];t-=1}return null}function co(e){const t=Dn.create();for(const r of e)t.update(r);t.update(Uint8Array.from([255]));const r=t.digest();return r[0]=0,r}function lo(e){const t=Dn.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function ho(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))}function fo(e){const r=e.proof?{a:e.proof.a,b:e.proof.b,c:e.proof.c}:null,n=e.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:e.input_compressed_accounts.map((e=>({compressedAccount:{owner:new t(T.alloc(32)),lamports:Ar(e.lamports),address:e.address,data:null},merkleContext:{merkleTreePubkeyIndex:e.packedMerkleContext.merkle_tree_pubkey_index,queuePubkeyIndex:e.packedMerkleContext.queue_pubkey_index,leafIndex:e.packedMerkleContext.leaf_index,proveByIndex:e.packedMerkleContext.prove_by_index},rootIndex:e.root_index,readOnly:0}))),outputCompressedAccounts:e.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:e.compress_or_decompress_lamports,isCompress:e.is_compress}}function po(e,t){return lo([t.toBytes(),...e])}function mo(e,r=Tt().addressTree){if(32!=e.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=uo(Buffer.from([...n,...e]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new t(s)}function go(e){return co(e.map((e=>Uint8Array.from(e))))}function yo(e,t){const r=nt.isV2();if(void 0!==t){if(r)throw new Error("deriveAddressSeed: programId must not be passed in V2 mode. For V2, omit programId here and pass it to deriveAddress instead. If you need V1 behavior, set LIGHT_PROTOCOL_VERSION=V1.");return po(e,t)}if(!r)throw new Error("deriveAddressSeed: programId is required in V1 mode. Pass programId as the second argument. If you need V2 behavior, set LIGHT_PROTOCOL_VERSION=V2.");return go(e)}function wo(e,r,n){if(32!=e.length)throw new Error("Address seed length is not 32 bytes.");const o=r.toBytes(),s=n.toBytes(),i=co([Uint8Array.from(e),Uint8Array.from(o),Uint8Array.from(s)]);return new t(i)}function vo(e,t,r){const n=nt.isV2();if(void 0===r){if(n)throw new Error("deriveAddress: programId is required in V2 mode. Pass programId as the third argument. If you need V1 behavior, set LIGHT_PROTOCOL_VERSION=V1.");return mo(e,t)}if(!n)throw new Error("deriveAddress: programId must not be passed in V1 mode. Omit programId from deriveAddress. If you need V2 behavior, set LIGHT_PROTOCOL_VERSION=V2.");return wo(e,t,r)}function bo(e,t){const r=t.slice(),n=e.map((e=>({seed:Array.from(e.seed),addressMerkleTreeRootIndex:e.addressMerkleTreeRootIndex,addressMerkleTreeAccountIndex:0,addressQueueAccountIndex:0})));return e.forEach(((e,t)=>{n[t].addressMerkleTreeAccountIndex=tn(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=tn(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}if(import.meta.vitest){const{it:e,expect:r,describe:n}=import.meta.vitest,o=new t("7yucc7fL3JGbyMwg4neUaenNSdySS39hbAk89Ao3t1Hz");n("derive address seed (legacy/V1)",(()=>{e("should derive a valid address seed with programId",(()=>{const e=[(new TextEncoder).encode("foo"),(new TextEncoder).encode("bar")];r(po(e,o)).toStrictEqual(new Uint8Array([0,246,150,3,192,95,53,123,56,139,206,179,253,133,115,103,120,155,251,72,250,47,117,217,118,59,174,207,49,101,201,110]))})),e("should derive a valid address seed with programId",(()=>{const e=[(new TextEncoder).encode("ayy"),(new TextEncoder).encode("lmao")];r(po(e,o)).toStrictEqual(new Uint8Array([0,202,44,25,221,74,144,92,69,168,38,19,206,208,29,162,53,27,120,214,152,116,15,107,212,168,33,121,187,10,76,233]))}))})),n("deriveAddress function (legacy/V1)",(()=>{e("should derive a valid address from a seed and a merkle tree public key",(async()=>{const e=mo(po([(new TextEncoder).encode("foo"),(new TextEncoder).encode("bar")],o),new t("11111111111111111111111111111111"));r(e).toBeInstanceOf(t),r(e).toStrictEqual(new t("139uhyyBtEh4e1CBDJ68ooK5nCeWoncZf9HPyAfRrukA"))})),e("should derive a valid address from a seed and a merkle tree public key",(async()=>{const e=mo(po([(new TextEncoder).encode("ayy"),(new TextEncoder).encode("lmao")],o),new t("11111111111111111111111111111111"));r(e).toBeInstanceOf(t),r(e).toStrictEqual(new t("12bhHm6PQjbNmEn3Yu1Gq9k7XwVn2rZpzYokmLwbFazN"))}))})),n("packNewAddressParams function",(()=>{e("should pack new address params correctly",(()=>{const e=bo([{seed:new Uint8Array([1,2,3,4]),addressMerkleTreeRootIndex:0,addressMerkleTreePubkey:new t("11111111111111111111111111111111"),addressQueuePubkey:new t("11111111111111111111111111111112")}],[new t("11111111111111111111111111111112"),new t("11111111111111111111111111111111")]);r(e.newAddressParamsPacked[0].addressMerkleTreeAccountIndex).toBe(1),r(e.newAddressParamsPacked[0].addressQueueAccountIndex).toBe(0)}))}))}async function Io({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await Ao(e,n),n}async function Ao(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 Eo(e,t){return Math.ceil(1e6*e/t)}function xo(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}class Mo{preAccounts=[];systemAccounts=[];nextIndex=0;map=new Map;static newWithSystemAccounts(e){const t=new Mo;return t.addSystemAccounts(e),t}static newWithSystemAccountsV2(e){const t=new Mo;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){nt.isV2()?this.systemAccounts.push(...ko(e)):this.systemAccounts.push(...To(e))}addSystemAccountsV2(e){this.systemAccounts.push(...ko(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 _o{selfProgram;cpiContext;solCompressionRecipient;solPoolPda;constructor(e,t,r,n){this.selfProgram=e,this.cpiContext=t,this.solCompressionRecipient=r,this.solPoolPda=n}static new(e){return new _o(e)}static newWithCpiContext(e,t){return new _o(e,t)}}function To(e){let r=(new TextEncoder).encode("cpi_authority");const o=t.findProgramAddressSync([r],e.selfProgram)[0],s=It(),i=[{pubkey:ns.programId,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:s.noopProgram,isSigner:0,isWritable:0},{pubkey:s.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:s.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.selfProgram,isSigner:0,isWritable:0}];return e.solPoolPda&&i.push({pubkey:e.solPoolPda,isSigner:0,isWritable:1}),e.solCompressionRecipient&&i.push({pubkey:e.solCompressionRecipient,isSigner:0,isWritable:1}),i.push({pubkey:n.programId,isSigner:0,isWritable:0}),e.cpiContext&&i.push({pubkey:e.cpiContext,isSigner:0,isWritable:1}),i}function So(e){return nt.isV2()?ko(e):To(e)}function ko(e){let r=(new TextEncoder).encode("cpi_authority");const o=t.findProgramAddressSync([r],e.selfProgram)[0],s=It(),i=[{pubkey:ns.programId,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:s.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:s.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.programId,isSigner:0,isWritable:0}];return e.solPoolPda&&i.push({pubkey:e.solPoolPda,isSigner:0,isWritable:1}),e.solCompressionRecipient&&i.push({pubkey:e.solCompressionRecipient,isSigner:0,isWritable:1}),e.cpiContext&&i.push({pubkey:e.cpiContext,isSigner:0,isWritable:1}),i}const Co=()=>({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))}),Po=e=>{if(32!==e.a.length||64!==e.b.length||32!==e.c.length)throw new Error("ValidityProof has invalid shape")};function Bo(e){const t=Oo(e.ar[0]),r=Oo(e.ar[1]),n=new Uint8Array([...t,...r]),o=Oo(e.bs[0][0]),s=Oo(e.bs[0][1]),i=Oo(e.bs[1][0]),a=Oo(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=Oo(e.krs[0]),l=Oo(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function Lo(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=No(Ar(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=at.div(Ar(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(Ar(a.slice(0,32),32,"be"),Ar(a.slice(32,64),32,"be"));i[0]=Ro(i[0],u);const c=n.slice(0,32),l=n.slice(32,64),d=No(Ar(l,32,"be"));return c[0]=Ro(c[0],d),{a:Array.from(o),b:Array.from(i),c:Array.from(c)}}function Oo(e){const t=Ar(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function No(e){return e.lte(at.sub(e))}function Ro(e,t){return t?e:128|e}if(import.meta.vitest){const{it:e,expect:t,describe:r}=import.meta.vitest;r("addBitmaskToByte",(()=>{e("should add a bitmask to the byte if yIsPositive is false",(()=>{const e=Ro(0,0);t(e).toBe(128)})),e("should not modify the byte if yIsPositive is true",(()=>{const e=Ro(0,1);t(e).toBe(0)}))})),r("test prover server",(()=>{const r={ar:["0x22bdaa3187d8fe294925a66fa0165a11bc9e07678fa2fc72402ebfd33d521c69","0x2d18ff780b69898b4cdd8d7b6ac72d077799399f0f45e52665426456f3903584"],bs:[["0x138cc0962e49f76a701d2871d2799892c9782940095eb0429e979f336d2e162d","0x2fe1bfbb15cbfb83d7e00ace23e45f890604003783eaf34affa35e0d6f4822bc"],["0x1a89264f82cc6e8ef1c696bea0b5803c28c0ba6ab61366bcb71e73a4135cae8d","0xf778d857b3df01a4100265c9d014ce02d47425f0114685356165fa5ee3f3a26"]],krs:["0x176b6ae9001f66832951e2d43a98a972667447bb1781f534b70cb010270dcdd3","0xb748d5fac1686db28d94c02250af7eb4f28dfdabc8983305c45bcbc6e163eeb"]},n=[34,189,170,49,135,216,254,41,73,37,166,111,160,22,90,17,188,158,7,103,143,162,252,114,64,46,191,211,61,82,28,105],o=[147,140,192,150,46,73,247,106,112,29,40,113,210,121,152,146,201,120,41,64,9,94,176,66,158,151,159,51,109,46,22,45,47,225,191,187,21,203,251,131,215,224,10,206,35,228,95,137,6,4,0,55,131,234,243,74,255,163,94,13,111,72,34,188],s=[23,107,106,233,0,31,102,131,41,81,226,212,58,152,169,114,102,116,71,187,23,129,245,52,183,12,176,16,39,13,205,211];e("should execute a compressed token mint",(async()=>{const e=Lo(Bo(r));t(e.a).toEqual(n),t(e.b).toEqual(o),t(e.c).toEqual(s)}))})),r("Validity Proof Functions",(()=>{r("placeholderValidityProof",(()=>{e("should create a validity proof with correct shape",(()=>{const e=Co();t(e.a.length).toBe(32),t(e.b.length).toBe(64),t(e.c.length).toBe(32)}))})),r("checkValidityProofShape",(()=>{e("should not throw an error for valid proof shape",(()=>{const e={a:Array.from(new Uint8Array(32)),b:Array.from(new Uint8Array(64)),c:Array.from(new Uint8Array(32))};t((()=>Po(e))).not.toThrow()})),e("should throw an error for an invalid proof",(()=>{const e={a:Array.from(new Uint8Array(31)),b:Array.from(new Uint8Array(64)),c:Array.from(new Uint8Array(32))};t((()=>Po(e))).toThrow("ValidityProof has invalid shape")}))}))}))}function Uo(e,...t){return r=>t.reduce(((e,t)=>t(e)),e(r))}if(import.meta.vitest){const{it:e,expect:t,describe:r}=import.meta.vitest;r("pipe",(()=>{e("should return the result of applying all fns to the initial value",(()=>{const e=Uo((e=>e+1),(e=>2*e),(e=>e-3));t(e(5)).toBe(9)}))}))}function Do(e,t,r,n){const i=new o({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(n);return new s(i)}async function Vo(e,t,r){const n=await e.sendTransaction(t,r);return await qo(e,n,r),n}async function qo(e,t,r){const n=r?.commitment||e.commitment||"confirmed",o=Et(e.rpcEndpoint)?200:1e3;let s=0;await new Promise(((r,i)=>{const a=setInterval((async()=>{s+=o,s>=8e4&&(clearInterval(a),i(new Error(`Transaction ${t}'s confirmation timed out`)));const u=await e.getSignatureStatuses([t]);u?.value[0]?.confirmationStatus===n&&(clearInterval(a),r(t))}),o)}));const i=await e.getSlot();return await e.confirmTransactionIndexed(i),{context:{slot:i},value:{err:null}}}function Fo(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=Do(e,t.publicKey,r,o);return i.sign(s),i}function Ho(e){return new Promise((t=>setTimeout(t,e)))}async function Wo({connection:e,payer:t,authority:r,recentSlot:n}){const[o,s]=i.createLookupTable({payer:t.publicKey,authority:r.publicKey,recentSlot:n}),a=Fo([o],t,(await e.getLatestBlockhash()).blockhash,xo(t,[r]));return{address:s,txId:await Vo(e,a)}}async function $o({connection:e,tableAddress:t,newStateTreeAddresses:r,newQueueAddresses:n,newCpiContextAddresses:o,payer:s,authority:a}){const u=await e.getAddressLookupTable(t);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(r.length!==n.length||r.length!==o.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const c=Fo([i.extendLookupTable({payer:s.publicKey,authority:a.publicKey,lookupTable:t,addresses:r.flatMap(((e,t)=>[e,n[t],o[t]]))})],s,(await e.getLatestBlockhash()).blockhash,xo(s,[a]));return{tableAddress:t,txId:await Vo(e,c)}}async function jo({connection:e,fullStateTreeAddress:t,nullifyLookupTableAddress:r,stateTreeLookupTableAddress:n,payer:o,authority:s}){const a=await e.getAddressLookupTable(n);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(t.toBase58()))throw console.log("fullStateTreeAddress",t),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 e.getAddressLookupTable(r);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.map((e=>e.toBase58())).includes(t.toBase58()))throw new Error("Address already exists in nullify lookup table");const c=Fo([i.extendLookupTable({payer:o.publicKey,authority:s.publicKey,lookupTable:r,addresses:[t]})],o,(await e.getLatestBlockhash()).blockhash,xo(o,[s]));return{txId:await Vo(e,c)}}function zo(e){return e.treeInfo.nextTreeInfo?.queue??e.treeInfo.queue}function Ko(e){return e.treeInfo.nextTreeInfo??e.treeInfo}function Zo(e,t){return Yo(e,t)}function Yo(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 Go(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]}const Xo=5;function Qo(e,t=(nt.isV2()?Je.StateV2:Je.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(Xo,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 Jo({connection:e,stateTreeLUTPairs:r}){const n=await Promise.all(r.map((async t=>({stateTreeLookupTable:await e.getAddressLookupTable(t.stateTreeLookupTable),nullifyLookupTable:await e.getAddressLookupTable(t.nullifyLookupTable)})))),o=[];for(const{stateTreeLookupTable:e,nullifyLookupTable:r}of n){if(!e.value)throw new Error("State tree lookup table not found");if(!r.value)throw new Error("Nullify table not found");const n=e.value.state.addresses,s=r.value.state.addresses;if(n.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");for(let e=0;e<n.length;e+=3){const r=n[e],i=n[e+1],a=n[e+2];let u=null;if(!r||!i||!a)throw new Error("Invalid state tree pubkeys structure");const c=r.toBase58();let l;l=c.startsWith("bmt")?Je.StateV2:c.startsWith("amt2")?Je.AddressV2:c.startsWith("amt")?Je.AddressV1:Je.StateV1,s.map((e=>e.toBase58())).includes(r.toBase58())&&(u={tree:t.default,queue:t.default,cpiContext:t.default,treeType:l,nextTreeInfo:null}),o.push({tree:r,queue:i,cpiContext:a,treeType:l,nextTreeInfo:u})}for(const e of o)if(e.nextTreeInfo?.tree.equals(t.default)){const t=o.find((e=>!e.nextTreeInfo));if(!t)throw new Error("No available tree info found to assign as next tree");e.nextTreeInfo=t}}return o}async function es(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}}const ts=e=>e.reduce(((e,t)=>e.add(Ar(t.lamports))),Ar(0)),rs=T.from("sol_pool_pda");class ns{constructor(){}static programId=new t("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");static deriveCompressedSolPda(){const e=[rs],[r,n]=t.findProgramAddressSync(e,this.programId);return r}static createTransferOutputState(e,t,r){r=Ar(r);const n=ts(e).sub(r);return an(n),n.eq(Ar(0))?[xr(t,r)]:(un(e),[xr(e[0].owner,n),xr(t,r)])}static createDecompressOutputState(e,t){t=Ar(t);const r=ts(e).sub(t);return an(r),r.eq(Ar(0))?[]:(un(e),[xr(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=Ar(r??0);const o=ts(n??[]).sub(r);return an(o),o.eq(Ar(0))||!n?[xr(t,r,void 0,e)]:(un(n),[xr(n[0].owner,o),xr(t,r,void 0,e)])}static async createAccount({payer:e,newAddressParams:t,newAddress:r,recentValidityProof:o,outputStateTreeInfo:s,inputCompressedAccounts:i,inputStateRootIndices:u,lamports:c}){const l=this.createNewAddressOutputState(r,e,c,i),{packedInputCompressedAccounts:d,packedOutputCompressedAccounts:h,remainingAccounts:f}=sn(i??[],u??[],l,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:m}=bo([t],f),g=Pr({proof:o,inputCompressedAccountsWithMerkleContext:d,outputCompressedAccounts:h,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),y=[...$r({...It(),feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:n.programId}),...nn(m)];return new a({programId:this.programId,keys:y,data:g})}static async transfer({payer:e,inputCompressedAccounts:t,toAddress:r,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){const u=this.createTransferOutputState(t,r,o),{packedInputCompressedAccounts:c,packedOutputCompressedAccounts:l,remainingAccounts:d}=sn(t,s,u),h=Pr({proof:i,inputCompressedAccountsWithMerkleContext:c,outputCompressedAccounts:l,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),f=[...$r({...It(),feePayer:e,authority:e,solPoolPda:null,decompressionRecipient:null,systemProgram:n.programId}),...nn(d)];return new a({programId:this.programId,keys:f,data:h})}static async compress({payer:e,toAddress:t,lamports:r,outputStateTreeInfo:o}){r=Ar(r);const s=xr(t,r),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:u,remainingAccounts:c}=sn([],[],[s],o),l=Pr({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:u,relayFee:null,newAddressParams:[],compressOrDecompressLamports:r,isCompress:1}),d=[...$r({...It(),feePayer:e,authority:e,solPoolPda:ns.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:n.programId}),...nn(c)];return new a({programId:this.programId,keys:d,data:l})}static async decompress({payer:e,inputCompressedAccounts:t,toAddress:r,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){o=Ar(o);const u=this.createDecompressOutputState(t,o),{packedInputCompressedAccounts:c,packedOutputCompressedAccounts:l,remainingAccounts:d}=sn(t,s,u),h=Pr({proof:i,inputCompressedAccountsWithMerkleContext:c,outputCompressedAccounts:l,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),f=[...$r({...It(),feePayer:e,authority:e,solPoolPda:ns.deriveCompressedSolPda(),decompressionRecipient:r,systemProgram:n.programId}),...nn(d)];return new a({programId:this.programId,keys:f,data:h})}}function os(e,t){let r=Ar(0);t=Ar(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(Ar(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(Ar(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}async function ss(e,t,r,n,o,s){const{blockhash:i}=await e.getLatestBlockhash();o||(o=Qo(await e.getStateTreeInfos()));const a=await ns.compress({payer:t.publicKey,toAddress:n,lamports:r,outputStateTreeInfo:o}),c=Fo([u.setComputeUnitLimit({units:1e6}),a],t,i,[]);return await Vo(e,c,s)}async function is(e,t,r,n,o,s,i){const{blockhash:a}=await e.getLatestBlockhash(),c=o??Mt(),{tree:l,queue:d}=c,h=c.treeType===Je.AddressV2;if(nt.isV2()||h)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const f=po(r,n),p=mo(f,l);s||(s=Qo(await e.getStateTreeInfos()));const m=await e.getValidityProofV0(void 0,[{address:Ar(p.toBytes()),tree:l,queue:d}]),g={seed:f,addressMerkleTreeRootIndex:m.rootIndices[0],addressMerkleTreePubkey:m.treeInfos[0].tree,addressQueuePubkey:m.treeInfos[0].queue},y=await ns.createAccount({payer:t.publicKey,newAddressParams:g,newAddress:Array.from(p.toBytes()),recentValidityProof:m.compressedProof,programId:n,outputStateTreeInfo:s}),w=Fo([u.setComputeUnitLimit({units:1e6}),y],t,a,[]);return await Vo(e,w,i)}async function as(e,t,r,n,o,s,i,a){n=Ar(n);const c=await e.getCompressedAccountsByOwner(t.publicKey),[l]=os(c.items,n),{blockhash:d}=await e.getLatestBlockhash(),h=s??Mt(),{tree:f}=h,p=h.treeType===Je.AddressV2;if(nt.isV2()||p)throw new Error("You are using V2. create-account/create-address is only supported via CPI.");const m=po(r,o),g=mo(m,f),y=await e.getValidityProof(l.map((e=>e.hash)),[Ar(g.toBytes())]),w={seed:m,addressMerkleTreeRootIndex:y.rootIndices[y.rootIndices.length-1],addressMerkleTreePubkey:y.treeInfos[y.treeInfos.length-1].tree,addressQueuePubkey:y.treeInfos[y.treeInfos.length-1].queue},v=await ns.createAccount({payer:t.publicKey,newAddressParams:w,newAddress:Array.from(g.toBytes()),recentValidityProof:y.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:y.rootIndices,outputStateTreeInfo:i}),b=Fo([u.setComputeUnitLimit({units:1e6}),v],t,d,[]);return await Vo(e,b,a)}async function us(e,t,r,n,o){const s=(await e.getCompressedAccountsByOwner(t.publicKey)).items;r=Ar(r);const i=ts(s);if(r.gt(i))throw new Error(`Not enough compressed lamports. Expected ${r}, got ${i}`);const a=await e.getValidityProof(s.map((e=>Ar(e.hash)))),{blockhash:c}=await e.getLatestBlockhash(),l=await ns.decompress({payer:t.publicKey,toAddress:n,inputCompressedAccounts:s,recentValidityProof:a.compressedProof,recentInputStateRootIndices:a.rootIndices,lamports:r}),d=Fo([u.setComputeUnitLimit({units:1e6}),l],t,c,[]);return await Vo(e,d,o)}async function cs(e,t,r,n,o,s){let i=Ar(0);const a=[];let c;for(r=Ar(r);i.lt(r);){const t={filters:void 0,dataSlice:void 0,cursor:c,limit:Ar(1e3)},o=await e.getCompressedAccountsByOwner(n.publicKey,t);for(const e of o.items)e.lamports.gt(Ar(0))&&(a.push(e),i=i.add(e.lamports));if(c=o.cursor??void 0,o.items.length<1e3||i.gte(r))break}if(i.lt(r))throw new Error(`Insufficient balance for transfer. Required: ${r.toString()}, available: ${i.toString()}`);const[l]=os(a,r),d=await e.getValidityProof(l.map((e=>Ar(e.hash)))),h=await ns.transfer({payer:t.publicKey,inputCompressedAccounts:l,toAddress:o,lamports:r,recentInputStateRootIndices:d.rootIndices,recentValidityProof:d.compressedProof}),{blockhash:f}=await e.getLatestBlockhash(),p=Fo([u.setComputeUnitLimit({units:35e4}),h],t,f);return await Vo(e,p,s)}class ls{index;value;nextIndex;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([Ar(this.value.toArray("be",32)).toString(),Ar(this.nextIndex).toString(),Ar(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class ds{newLowElement;newElement;newElementNextValue;constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class hs{elements;currentNodeIndex;highestElementIndex;constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new hs([new ls(0,Ar(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=ut;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([Ar(r.value.toArray("be",32)).toString(),Ar(r.nextIndex).toString(),Ar(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 ls(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new ds(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)}}const fs="0";class ps{levels;capacity;zeroElement;_zeros;_layers;_lightWasm;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 ms(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=It(),o=(await e.getSignaturesForAddress(n,void 0,"confirmed")).map((e=>e.signature)),s=[];for(let t=0;t<o.length;t+=100){const r=o.slice(t,t+100),n=await e.getParsedTransactions(r,{maxSupportedTransactionVersion:0,commitment:"confirmed"});s.push(...n)}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 s?.transaction.message.compiledInstructions||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===ct.length&&ct.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=vr.decode(t.data);o.push(e)}}const a=ws(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 gs(i,ys)}const gs=(e,t)=>{const{noopProgram:r}=It(),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=vr.decode(s.data),o=t(T.from(r),e);null!=o&&n.push(o)}}}))})),n},ys=e=>{const t=T.from(e.map((e=>e)));try{return Kr(t)}catch(e){return console.error("Error deserializing event:",e),null}};function ws(e,t){let r=0,n=null,o=null;for(const t of e){const e=t.slice(0,8),o=vr.encode(e),s=vr.encode(lt),i=vr.encode(dt),a=vr.encode(ht);if(o===s){n=Hr(T.from(t)),r=1;break}if(o==i){n=Wr(T.from(t)),r=1;break}if(o==a){n=fo(Fr(T.from(t))),r=1;break}}if(!r)return null;for(const t of e){const e=t.slice(0,8);if(vr.encode(e)===vr.encode(pt)){const e=t.slice(12);o=Jr(T.from(e))}}return n?en(o,t[t.length-1],n):null}async function vs(e,t){return(await bs(e)).find((e=>Ar(e.hash).eq(t)))}async function bs(e){const t=(await ms(e)).reverse(),r=[],n=[],o=await e.getStateTreeInfos();for(const e of t){for(let t=0;t<e.outputCompressedAccounts.length;t++){const n=Zo(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]),s=e.outputCompressedAccounts[t],i={treeInfo:n,hash:Ar(e.outputCompressedAccountHashes[t]),leafIndex:e.outputLeafIndices[t],proveByIndex:n.treeType===Je.StateV2},a=Mr(i,s.compressedAccount.owner,s.compressedAccount.lamports,s.compressedAccount.data??void 0,s.compressedAccount.address??void 0);r.push(a)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];n.push(Ar(r))}}const s=r.filter((e=>!n.some((t=>t.eq(Ar(e.hash))))));return s.sort(((e,t)=>t.leafIndex-e.leafIndex)),s}function Is(e,r=kt){if(null===e.data)return null;const{data:n}=e.data;if(0===n.length)return null;if(e.owner.toBase58()!==r.toBase58())throw new Error(`Invalid owner ${e.owner.toBase58()} for token layout`);try{const e=Buffer.from(n);let r=0;const o=new t(e.slice(r,r+32));r+=32;const s=new t(e.slice(r,r+32));r+=32;const i=new rt(e.slice(r,r+8),"le");r+=8;const a=e[r];r+=1;const u=a?new t(e.slice(r,r+32)):null;r+=32;const c=e[r];r+=1;const l=e[r];return r+=1,{mint:o,owner:s,amount:i,delegate:u,state:c,tlv:l?e.slice(r):null}}catch(e){throw console.error("Decoding error:",e),e}}async function As(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)=>{const i=r[e.outputCompressedAccounts[s].merkleTreeIndex],a=Zo(n,i);if(!(a.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])||nt.isV2()&&a.queue.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])))throw new Error("Invalid tree");const u={treeInfo:a,hash:Ar(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:a.treeType===Je.StateV2};if(!t.compressedAccount.data)throw new Error("No data");const c=Is(t.compressedAccount);if(!c)throw new Error("Invalid token data");return{compressedAccount:Mr(u,t.compressedAccount.owner,t.compressedAccount.lamports,t.compressedAccount.data,t.compressedAccount.address??void 0),parsed:c}}));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=>Ar(t).eq(e.compressedAccount.hash)))))}async function Es(e,t,r){const n=await ms(e);return{items:(await As(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 xs(e,t,r){const n=await ms(e);return{items:(await As(n,e)).filter((e=>e.parsed.delegate?.equals(t)&&e.parsed.mint.equals(r))),cursor:null}}async function Ms(e,t){const r=await ms(e),n=(await As(r,e)).filter((e=>Ar(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class _s 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 Ts(e){return"object"==typeof e&&null!=e}function Ss(e){return Ts(e)&&!Array.isArray(e)}function ks(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Cs(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: \`${ks(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*Ps(e,t,r,n){var o;Ts(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Cs(o,t,r,n);e&&(yield e)}}function*Bs(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=Bs(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):Ts(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 Ls{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)=>Ps(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>Ps(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Rs(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return Os(e,this,t)}is(e){return Ns(e,this)}mask(e,t){return function(e,t,r){const n=Rs(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Rs(e,this,t)}}function Os(e,t,r){const n=Rs(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function Ns(e,t){return!Rs(e,t)[0]}function Rs(e,t,r={}){const n=Bs(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new _s(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function Us(e,t){return new Ls({type:e,schema:null,validator:t})}function Ds(){return Us("any",(()=>1))}function Vs(e){return new Ls({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: ${ks(e)}`})}function qs(){return Us("boolean",(e=>"boolean"==typeof e))}function Fs(e){return Us("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${ks(t)}`))}function Hs(e){const t=ks(e);return new Ls({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${ks(r)}`})}function Ws(e){return new Ls({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function $s(){return Us("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${ks(e)}`))}function js(){return Us("string",(e=>"string"==typeof e||`Expected a string, but received: ${ks(e)}`))}function zs(e){const t=Object.keys(e);return new Ls({type:"type",schema:e,*entries(r){if(Ts(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>Ss(e)||`Expected an object, but received: ${ks(e)}`,coercer:e=>Ss(e)?{...e}:e})}function Ks(e){const t=e.map((e=>e.type)).join(" | ");return new Ls({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]=Bs(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: ${ks(r)}`,...o]}})}function Zs(){return Us("unknown",(()=>1))}function Ys(e,t,r){return new Ls({...e,coercer:(n,o)=>Ns(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}var Gs;!function(e){e.compressible="compressible",e.standard="standard"}(Gs||(Gs={}));const Xs=Ys(Fs(t),js(),(e=>new t(e))),Qs=Ys(Fs(Array),js(),(e=>Array.from(new t(e).toBytes()))),Js=Ys(Fs(rt),js(),(e=>br(e,"base58"))),ei=Ys(qs(),Ks([$s(),qs()]),(e=>Boolean(e))),ti=Ys(Fs(rt),Ks([js(),$s()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return Ar(e)}return Ar(e,10)})),ri=js();function ni(e){return Ks([zs({jsonrpc:Hs("2.0"),id:js(),result:e}),zs({jsonrpc:Hs("2.0"),id:js(),error:zs({code:Zs(),message:js(),data:Ws(Ds())})})])}const oi=ni(Zs());function si(e){return Ys(ni(e),oi,(t=>"error"in t?t:{...t,result:Os(t.result,e)}))}function ii(e){return si(zs({context:zs({slot:$s()}),value:e}))}const ai=zs({treeType:$s(),tree:Xs,queue:Xs,cpiContext:Ws(Xs)}),ui=zs({treeType:$s(),tree:Xs,queue:Xs,cpiContext:Ws(Xs),nextTreeContext:(ci=Ws(ai),new Ls({...ci,validator:(e,t)=>void 0===e||ci.validator(e,t),refiner:(e,t)=>void 0===e||ci.refiner(e,t)}))});var ci;const li=zs({address:Ws(Qs),hash:Js,data:Ws(zs({data:ri,dataHash:Js,discriminator:ti})),lamports:ti,owner:Xs,leafIndex:$s(),tree:Xs,seq:Ws(ti),slotCreated:ti}),di=zs({address:Ws(Qs),hash:Js,data:Ws(zs({data:ri,dataHash:Js,discriminator:ti})),lamports:ti,owner:Xs,leafIndex:$s(),seq:Ws(ti),slotCreated:ti,merkleContext:ui,proveByIndex:ei}),hi=zs({mint:Xs,owner:Xs,amount:ti,delegate:Ws(Xs),state:js()}),fi=zs({tokenData:hi,account:li}),pi=zs({tokenData:hi,account:di}),mi=zs({items:Vs(li)}),gi=zs({items:Vs(di)}),yi=zs({items:Vs(li),cursor:Ws(js())}),wi=zs({items:Vs(di),cursor:Ws(js())}),vi=zs({items:Vs(fi),cursor:Ws(js())}),bi=zs({items:Vs(pi),cursor:Ws(js())}),Ii=$s(),Ai=js(),Ei=zs({items:Vs(zs({signature:js(),slot:$s(),blockTime:$s(),error:Ws(js())}))}),xi=zs({items:Vs(zs({signature:js(),slot:$s(),blockTime:$s()})),cursor:Ws(js())}),Mi=zs({hash:Js,leafIndex:$s(),merkleTree:Xs,proof:Vs(Js),rootSeq:$s(),root:Js}),_i=zs({hash:Js,leafIndex:$s(),proof:Vs(Js),root:Js,rootSeq:$s(),proveByIndex:ei,treeContext:ui}),Ti=zs({address:Js,nextIndex:$s(),merkleTree:Xs,proof:Vs(Js),rootSeq:$s(),root:Js,lowerRangeAddress:Js,higherRangeAddress:Js,lowElementLeafIndex:$s()}),Si=zs({a:Vs($s()),b:Vs($s()),c:Vs($s())}),ki=zs({rootIndex:$s(),proveByIndex:ei}),Ci=zs({compressedProof:Si,leafIndices:Vs($s()),leaves:Vs(Js),rootIndices:Vs($s()),roots:Vs(Js),merkleTrees:Vs(Xs)}),Pi=zs({hash:Js,root:Js,rootIndex:ki,merkleContext:ui,leafIndex:$s()}),Bi=zs({address:Js,root:Js,rootIndex:$s(),merkleContext:ui}),Li=zs({compressedProof:Ws(Si),accounts:Vs(Pi),addresses:Vs(Bi)}),Oi=Vs(Mi),Ni=Vs(_i),Ri=zs({amount:ti}),Ui=ti,Di=zs({balance:ti,mint:Xs}),Vi=zs({tokenBalances:Vs(Di),cursor:Ws(js())}),qi=zs({items:Vs(Di),cursor:Ws(js())}),Fi=zs({cursor:Ws(js()),items:Vs(zs({balance:ti,owner:Xs}))}),Hi=zs({hash:Vs($s()),root:Vs($s()),proof:Vs(Vs($s()))}),Wi=e=>new Date(e).getTime(),$i=zs({items:Vs(zs({blockTime:$s(),signature:js(),slot:$s()}))}),ji=zs({items:Vs(zs({blockTime:$s(),signature:js(),slot:$s()})),cursor:Ws(js())}),zi=zs({account:di,txHash:Js,nullifier:Js}),Ki=zs({compressionInfo:zs({closedAccounts:Vs(zs({account:li,optionalTokenData:Ws(hi)})),openedAccounts:Vs(zs({account:li,optionalTokenData:Ws(hi)}))}),transaction:Ds()}),Zi=zs({compressionInfo:zs({closedAccounts:Vs(zs({account:zi,optionalTokenData:Ws(hi)})),openedAccounts:Vs(zs({account:di,optionalTokenData:Ws(hi)}))}),transaction:Ds()}),Yi={Solana:"solana",Compressed:"compressed"};let Gi=0;function Xi(){return Gi}function Qi({discriminator:e,data:t,dataHash:r}){return{discriminator:e.toArray("le",8),data:T.from(t,"base64"),dataHash:r.toArray("le",32)}}async function Ji(e,t,r,n=0){const o=it(n?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner"),s=n?"delegate":"owner",i=await ra(e.compressionApiEndpoint,o,{[s]:t.toBase58(),mint:r.mint?.toBase58(),limit:r.limit?.toNumber(),cursor:r.cursor});let a;if(a=nt.isV2()?Os(i,ii(bi)):Os(i,ii(vi)),"error"in a)throw new l(a.error,`failed to get info for compressed accounts by ${s} ${t.toBase58()}`);if(null===a.result.value)throw new Error("not implemented: NULL result");const u=[],c=await e.getStateTreeInfos();return a.result.value.items.map((e=>{const r=e.account,n=e.tokenData,o=nt.isV2()?r.merkleContext.tree:r.tree,i=nt.isV2()?r.proveByIndex:0,a=Zo(c,o),l=Mr(_r(a,r.hash,r.leafIndex,i),r.owner,Ar(r.lamports),r.data?Qi(r.data):void 0,r.address||void 0),d={mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null};if(d[s]?.toBase58()!==t.toBase58())throw new Error(`RPC returned token account with ${s} different from requested ${s}`);u.push({compressedAccount:l,parsed:d})})),{items:u.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:a.result.value.cursor}}function ea(e,t,r,n){let o;if(e)if("string"==typeof e)o=e,t=t||o,r=r||o;else{if(!(e instanceof c))throw new Error("Invalid endpoint or connection type");o=e.rpcEndpoint,t=t||o,r=r||o}else o="http://127.0.0.1:8899",t=t||"http://127.0.0.1:8784",r=r||"http://127.0.0.1:3001";var s;return s=o.toLowerCase().includes("devnet"),Gi=s,new la(o,t,r,n)}function ta(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 ra=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=ta(await i.text());return n?ao(JSON.parse(a)):JSON.parse(a)},na=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=Lo(Bo(await i.json()));return n&&console.timeEnd(s),a};function oa(e){const t=[];for(let r=0;r<e.length;r++){const n={root:no(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>no(e))),leaf:no(Ar(e[r].hash))};t.push(n)}return t}function sa(e){const t=[];for(let r=0;r<e.length;r++){const n={root:no(e[r].root),value:no(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>no(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:no(e[r].leafLowerRangeValue),leafHigherRangeValue:no(e[r].leafHigherRangeValue)};t.push(n)}return t}function ia(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return Ar(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 aa(e,t,r,n){const o=ia(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=ia(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?ia([o],[i],n):o:i}function ua(e){const t=e.account,r=e.optionalTokenData,n=Mr(_r(t.treeInfo,t.hash.toArray("be",32),t.leafIndex,t.proveByIndex),t.owner,Ar(t.lamports),t.data?Qi(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 ca(e,t){const r=new Map;for(const e of t)r.set(e.signature,{signature:e.signature,slot:e.slot,blockTime:e.blockTime,err:null,memo:null,confirmationStatus:void 0,sources:[Yi.Compressed]});for(const t of e)r.get(t.signature)?r.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:t.blockTime??null,err:t.err,memo:t.memo??null,confirmationStatus:t.confirmationStatus,sources:[Yi.Solana,Yi.Compressed]}):r.set(t.signature,{signature:t.signature,slot:t.slot,blockTime:t.blockTime??null,err:t.err,memo:t.memo??null,confirmationStatus:t.confirmationStatus,sources:[Yi.Solana]});return Array.from(r.values()).sort(((e,t)=>t.slot-e.slot))}class la extends c{compressionApiEndpoint;proverEndpoint;allStateTreeInfos=null;lastStateTreeFetchTime=null;CACHE_TTL=36e5;fetchPromise=null;constructor(e,t,r,n){super(e,n||"confirmed"),this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(Et(this.rpcEndpoint))return ar();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}=At();try{return await Jo({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await Jo({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 e=new t(or);return{tree:e,queue:e,cpiContext:void 0,treeType:Je.AddressV2,nextTreeInfo:null}}async getCompressedAccount(e,t){if(!t&&!e)throw new Error("Either hash or address must be provided");if(t&&e)throw new Error("Only one of hash or address must be provided");const r=await this.getStateTreeInfos(),n=await ra(this.compressionApiEndpoint,it("getCompressedAccount"),{hash:t?Ir(t):void 0,address:e?Ir(e):void 0});let o;if(o=nt.isV2()?Os(n,ii(Ws(di))):Os(n,ii(Ws(li))),"error"in o)throw new l(o.error,`failed to get info for compressed account ${t?t.toString():e?e.toString():""}`);if(null===o.result.value)return null;const s=Zo(r,nt.isV2()?o.result.value.merkleContext.tree:o.result.value.tree),i=o.result.value;return Mr(_r(s,i.hash,i.leafIndex),i.owner,Ar(i.lamports),i.data?Qi(i.data):void 0,i.address||void 0)}async getCompressedBalance(e,t){if(!t&&!e)throw new Error("Either hash or address must be provided");if(t&&e)throw new Error("Only one of hash or address must be provided");const r=Os(await ra(this.compressionApiEndpoint,"getCompressedBalance",{hash:t?Ir(t):void 0,address:e?Ir(e):void 0}),ii(Ui));if("error"in r)throw new l(r.error,`failed to get balance for compressed account ${t?t.toString():e?e.toString():""}`);return null===r.result.value?Ar(0):Ar(r.result.value)}async getCompressedBalanceByOwner(e){const t=Os(await ra(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:e.toBase58()}),ii(Ui));if("error"in t)throw new l(t.error,`failed to get balance for compressed account ${e.toBase58()}`);return null===t.result.value?Ar(0):Ar(t.result.value)}async getCompressedAccountProof(e){const t=await ra(this.compressionApiEndpoint,it("getCompressedAccountProof"),{hash:Ir(e)});let r;if(r=nt.isV2()?Os(t,ii(_i)):Os(t,ii(Mi)),"error"in r)throw new l(r.error,`failed to get proof for compressed account ${e.toString()}`);if(null===r.result.value)throw new Error(`failed to get proof for compressed account ${e.toString()}`);const n=Zo(await this.getStateTreeInfos(),nt.isV2()?r.result.value.treeContext.tree:r.result.value.tree);return{hash:Ar(r.result.value.hash.toArray("be",32)),treeInfo:n,leafIndex:r.result.value.leafIndex,merkleProof:r.result.value.proof,rootIndex:r.result.value.rootSeq%2400,root:r.result.value.root,proveByIndex:nt.isV2()?r.result.value.proveByIndex:0}}async getMultipleCompressedAccounts(e){const t=await ra(this.compressionApiEndpoint,it("getMultipleCompressedAccounts"),{hashes:e.map((e=>Ir(e)))});let r;if(r=nt.isV2()?Os(t,ii(gi)):Os(t,ii(mi)),"error"in r)throw new l(r.error,`failed to get info for compressed accounts ${e.map((e=>Ir(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get info for compressed accounts ${e.map((e=>Ir(e))).join(", ")}`);const n=await this.getStateTreeInfos(),o=[];return r.result.value.items.map((e=>{const t=nt.isV2()?e.merkleContext.tree:e.tree,r=Zo(n,t),s=Mr(_r(r,Ar(e.hash.toArray("be",32)),e.leafIndex),e.owner,Ar(e.lamports),e.data?Qi(e.data):void 0,e.address||void 0);o.push(s)})),o.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(e){const t=await ra(this.compressionApiEndpoint,it("getMultipleCompressedAccountProofs"),e.map((e=>Ir(e))));let r;if(r=nt.isV2()?Os(t,ii(Vs(_i))):Os(t,ii(Vs(Mi))),"error"in r)throw new l(r.error,`failed to get proofs for compressed accounts ${e.map((e=>Ir(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for compressed accounts ${e.map((e=>Ir(e))).join(", ")}`);const n=[],o=await this.getStateTreeInfos();for(const e of r.result.value){const t=Zo(o,nt.isV2()?e.treeContext.tree:e.merkleTree),r={hash:Ar(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:nt.isV2()?e.proveByIndex:0};n.push(r)}return n}async getCompressedAccountsByOwner(e,t){const r=await ra(this.compressionApiEndpoint,it("getCompressedAccountsByOwner"),{owner:e.toBase58(),filters:t?.filters||[],dataSlice:t?.dataSlice,cursor:t?.cursor,limit:t?.limit?.toNumber()});let n;if(n=nt.isV2()?Os(r,ii(wi)):Os(r,ii(yi)),"error"in n)throw new l(n.error,`failed to get info for compressed accounts owned by ${e.toBase58()}`);if(null===n.result.value)return{items:[],cursor:null};const o=[],s=await this.getStateTreeInfos();return n.result.value.items.map((e=>{const t=Zo(s,nt.isV2()?e.merkleContext.tree:e.tree),r=Mr(_r(t,Ar(e.hash.toArray("be",32)),e.leafIndex,nt.isV2()?e.proveByIndex:0),e.owner,Ar(e.lamports),e.data?Qi(e.data):void 0,e.address||void 0);o.push(r)})),{items:o.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:n.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Ji(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await Ji(this,e,t,1)}async getCompressedTokenAccountBalance(e){const t=Os(await ra(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:Ir(e)}),ii(Ri));if("error"in t)throw new l(t.error,`failed to get balance for compressed token account ${e.toString()}`);if(null===t.result.value)throw new Error(`failed to get balance for compressed token account ${e.toString()}`);return{amount:Ar(t.result.value.amount)}}async getCompressedTokenBalancesByOwner(e,t){t||(t={});const r=Os(await ra(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:e.toBase58(),mint:t.mint?.toBase58(),limit:t.limit?.toNumber(),cursor:t.cursor}),ii(Vi));if("error"in r)throw new l(r.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);return{items:t.mint?r.result.value.tokenBalances.filter((e=>e.mint.toBase58()===t.mint.toBase58())):r.result.value.tokenBalances,cursor:r.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(e,t){t||(t={});const r=Os(await ra(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:e.toBase58(),mint:t.mint?.toBase58(),limit:t.limit?.toNumber(),cursor:t.cursor}),ii(qi));if("error"in r)throw new l(r.error,`failed to get compressed token balances for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get compressed token balances for owner ${e.toBase58()}`);const n=t.mint?r.result.value.items.filter((e=>e.mint.toBase58()===t.mint.toBase58())):r.result.value.items;return{context:r.result.context,value:{items:n,cursor:r.result.value.cursor}}}async getCompressionSignaturesForAccount(e){const t=Os(await ra(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:Ir(e)}),ii($i));if("error"in t)throw new l(t.error,`failed to get signatures for compressed account ${e.toString()}`);return t.result.value.items}async getTransactionWithCompressionInfo(e){const t=await ra(this.compressionApiEndpoint,it("getTransactionWithCompressionInfo"),{signature:e});let r;if(r=nt.isV2()?Os(t,si(Zi)):Os(t,si(Ki)),"error"in r)throw new l(r.error,"failed to get slot");if(null===r.result.transaction)return null;const n=[],o=[],s=await this.getStateTreeInfos();nt.isV2()?(r.result.compressionInfo.closedAccounts.map((e=>{n.push(function(e){const t={account:e.account.account,optionalTokenData:e.optionalTokenData},r={nullifier:e.account.nullifier,txHash:e.account.txHash},n=ua(t);return{account:n.account,maybeTokenData:n.maybeTokenData,maybeNullifierMetadata:r}}(e))})),r.result.compressionInfo.openedAccounts.map((e=>{o.push(ua(e))}))):(r.result.compressionInfo.closedAccounts.map((e=>{const t=Zo(s,e.account.tree),r=Mr(_r(t,Ar(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Ar(e.account.lamports),e.account.data?Qi(e.account.data):void 0,e.account.address||void 0);n.push({account:r,maybeTokenData:e.optionalTokenData})})),r.result.compressionInfo.openedAccounts.map((e=>{const t=Zo(s,e.account.tree),r=Mr(_r(t,Ar(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Ar(e.account.lamports),e.account.data?Qi(e.account.data):void 0,e.account.address||void 0);o.push({account:r,maybeTokenData:e.optionalTokenData})})));const i=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},a=i(n),u=i(o);return{compressionInfo:{closedAccounts:n,openedAccounts:o,preTokenBalances:a,postTokenBalances:u},transaction:r.result.transaction}}async getCompressionSignaturesForAddress(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ii(ji));if("error"in r)throw new l(r.error,`failed to get signatures for address ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for address ${e.toBase58()}`);return r.result.value}async getCompressionSignaturesForOwner(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ii(ji));if("error"in r)throw new l(r.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return r.result.value}async getCompressionSignaturesForTokenOwner(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ii(ji));if("error"in r)throw new l(r.error,`failed to get signatures for owner ${e.toBase58()}`);if(null===r.result.value)throw new Error(`failed to get signatures for owner ${e.toBase58()}`);return r.result.value}async getIndexerHealth(){const e=Os(await ra(this.compressionApiEndpoint,"getIndexerHealth"),si(Ai));if("error"in e)throw new l(e.error,"failed to get health");return e.result}async confirmTransactionIndexed(e){const t=Et(this.rpcEndpoint)?1e4:2e4,r=Et(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 e=Os(await ra(this.compressionApiEndpoint,"getIndexerSlot"),si(Ii));if("error"in e)throw new l(e.error,"failed to get slot");return e.result}async getCompressedMintTokenHolders(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:e.toBase58(),cursor:t?.cursor,limit:t?.limit?.toNumber()}),ii(Fi));if("error"in r)throw new l(r.error,"failed to get mint token holders");return r.result}async getLatestCompressionSignatures(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:t,cursor:e}),ii(xi));if("error"in r)throw new l(r.error,"failed to get latest non-voting signatures");return r.result}async getLatestNonVotingSignatures(e,t){const r=Os(await ra(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:e,cursor:t}),ii(Ei));if("error"in r)throw new l(r.error,"failed to get latest non-voting signatures");return r.result}async getMultipleNewAddressProofs(e){const t=Os(await ra(this.compressionApiEndpoint,"getMultipleNewAddressProofs",e.map((e=>Ir(e)))),ii(Vs(Ti)));if("error"in t)throw new l(t.error,`failed to get proofs for new addresses ${e.map((e=>Ir(e))).join(", ")}`);if(null===t.result.value)throw new Error(`failed to get proofs for new addresses ${e.map((e=>Ir(e))).join(", ")}`);const r=[];for(const e of t.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:Ar(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:Ar(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:Tt().addressQueue,treeType:Je.AddressV1,nextTreeInfo:null}};r.push(t)}return r}async getValidityProof(e=[],t=[]){const r=await this.getMultipleCompressedAccounts(e),n=r.map((e=>e.treeInfo.tree)),o=r.map((e=>e.treeInfo.queue)),s=Tt().addressTree,i=Tt().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===Gs.compressible||void 0===r){const r=wo(Uint8Array.from(e.address),e.treeInfo.tree,Ct);t=Ar(r.toBytes())}else t=Ar(e.address);return{address:t,tree:e.treeInfo.tree,queue:e.treeInfo.queue}})),{value:s}=await this.getValidityProofAndRpcContext(n,o);return s}async getValidityProofAndRpcContext(e=[],t=[]){cn(e.length,t.length);const r=it("getValidityProof"),n=await ra(this.compressionApiEndpoint,r,{hashes:e.map((({hash:e})=>Ir(e))),newAddressesWithTrees:t.map((({address:e,tree:t})=>({address:Ir(e),tree:t.toBase58()})))}),o=nt.isV2();let s;if(s=Os(n,ii(o?Li:Ci)),"error"in s)throw new l(s.error,`failed to get validity proof for hashes ${e.map((e=>e.hash.toString())).join(", ")}`);if(null===s.result.value)throw new Error(`failed to get validity proof for hashes ${e.map((e=>e.hash.toString())).join(", ")}`);const i=s.result.value;if(o)return{value:{compressedProof:i.compressedProof,leaves:i.accounts.map((e=>e.hash)).concat(i.addresses.map((e=>e.address))),roots:i.accounts.map((e=>e.root)).concat(i.addresses.map((e=>e.root))),rootIndices:i.accounts.map((e=>e.rootIndex.rootIndex)).concat(i.addresses.map((e=>e.rootIndex))),proveByIndices:i.accounts.map((e=>e.rootIndex.proveByIndex)).concat(i.addresses.map((()=>0))),treeInfos:i.accounts.map((e=>e.merkleContext)).concat(i.addresses.map((e=>e.merkleContext))),leafIndices:i.accounts.map((e=>e.leafIndex)).concat(i.addresses.map((()=>0)))},context:s.result.context};{const e=await this.getStateTreeInfos(),t=i.merkleTrees.map((t=>t.equals(Tt().addressTree)?{tree:t,queue:Tt().addressQueue,treeType:Je.AddressV1,nextTreeInfo:null}:Yo(e,t)));return{value:{compressedProof:i.compressedProof,roots:i.roots,rootIndices:i.rootIndices.map((e=>e)),leafIndices:i.leafIndices,leaves:i.leaves,treeInfos:t,proveByIndices:i.rootIndices.map((e=>e.proveByIndex))},context:s.result.context}}}async getAccountInfoInterface(e,t,r,n){st(),n=n??xt();const o=wo(e.toBytes(),n.tree,t),[s,i]=await Promise.allSettled([this.getAccountInfo(e,r),this.getCompressedAccount(Ar(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:T.concat([T.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){st();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:ca(s,i),solana:s,compressed:i}}async getSignaturesForOwnerInterface(e,t,r){st();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:ca(s,i),solana:s,compressed:i}}async getTokenAccountBalanceInterface(e,t,r,n){st();const[o,s]=await Promise.allSettled([this.getTokenAccountBalance(e,n),this.getCompressedTokenBalancesByOwner(t,{mint:r})]);let i=Ar(0),a=0,u=null;if("fulfilled"===o.status&&o.value){const e=o.value.value;i=Ar(e.amount),a=e.decimals,u=e}let c=Ar(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){st();const[r,n]=await Promise.allSettled([this.getBalance(e,t),this.getCompressedBalanceByOwner(e)]),o="fulfilled"===r.status?Ar(r.value):Ar(0),s="fulfilled"===n.status?n.value:Ar(0);return{total:o.isZero()?s:o,hasColdBalance:!s.isZero()}}}async function da(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 ha(t,e,r,n,void 0,{depth:o||Tt().merkleTreeHeight,log:s})}class ha extends c{compressionApiEndpoint;proverEndpoint;lightWasm;depth;log=0;allStateTreeInfos=null;lastStateTreeFetchTime=null;fetchPromise=null;CACHE_TTL=36e5;constructor(e,t,r,n,o,s){super(e,o||{commitment:"confirmed"}),this.compressionApiEndpoint=r,this.proverEndpoint=n;const{depth:i,log:a}=s??{},{merkleTreeHeight:u}=Tt();this.lightWasm=t,this.depth=i??u,this.log=a??0}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return ar()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}async getAddressTreeInfoV2(){const e=new t(or);return{tree:e,queue:e,cpiContext:void 0,treeType:Je.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");return await vs(this,t)??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 vs(this,t);if(!r)throw new Error("Account not found");return Ar(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),Ar(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await bs(e)).filter((e=>t.some((t=>Ar(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(e){const r=await ms(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=Zo(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 t(r);let u;if(i.treeType===Je.StateV1)u=new ps(this.depth,this.lightWasm,o.map((e=>Ar(e).toString())));else{if(i.treeType!==Je.StateV2)throw new Error(`Invalid tree type: ${i.treeType} in test-rpc.ts`);u=new ps(32,this.lightWasm,[])}for(let t=0;t<e.length;t++){const r=o.findIndex((r=>Ar(r).eq(e[t])));if(-1!==r)if(i.treeType===Je.StateV1){const n=u.path(r).pathElements.map((e=>Ar(e))),a=Ar(u.root()),c={hash:Ar(e[t].toArray("be",32)),treeInfo:i,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:o.length,root:a};s.set(e[t].toString(),c)}else if(i.treeType===Je.StateV2){const r=u._zeros.slice(0,-1).map((e=>Ar(e))),o=Ar(u.root()),c=n.get(a.toBase58()).leafIndices.findIndex((r=>e[t].eq(Ar(n.get(a.toBase58()).leaves[r])))),l={hash:Ar(e[t].toArray("be",32)),treeInfo:i,leafIndex:c,merkleProof:r,proveByIndex:1,rootIndex:0,root:o};s.set(e[t].toString(),l)}}}if(s.forEach(((e,t)=>{if(e.treeInfo.treeType===Je.StateV1){const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=Ar(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)}})),new Set(e.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 e.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 bs(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 Es(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await xs(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await Ms(this,e);return{amount:Ar(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await Es(this,e,t.mint)).items.map((e=>({balance:Ar(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await Es(this,e,t.mint)).items.map((e=>({balance:Ar(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=hs.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(Ar(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(Ar(r))}const o=new ps(this.depth,this.lightWasm,n.map((e=>Ar(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=>Ar(e))),u=t.get(n.nextIndex).value,c={root:Ar(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:Ar(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:Ar(n.index),treeInfo:{tree:Tt().addressTree,queue:Tt().addressQueue,treeType:Je.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 rt))))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 rt))))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===Je.StateV1)),o=await this.getMultipleCompressedAccountProofs(e);if(t){const e=oa(o);r={compressedProof:await na(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=>Ar(e.hash))),treeInfos:o.map((e=>e.treeInfo)),proveByIndices:o.map((e=>e.proveByIndex))}}else r={compressedProof:null,roots:o.map((()=>Ar(0))),rootIndices:o.map((e=>e.rootIndex)),leafIndices:o.map((e=>e.leafIndex)),leaves:o.map((e=>Ar(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=sa(e);r={compressedProof:await na(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=>Ar(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===Je.StateV1)),i=sa(o);let a;if(s){const e=oa(n);a=await na(this.proverEndpoint,"combined",[e,i],1)}else a=await na(this.proverEndpoint,"new-address",i,1);r={compressedProof:a,roots:n.map((e=>s?e.root:Ar(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=>Ar(e.hash))).concat(o.map((e=>Ar(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 fa=1;const pa=Ia(255),ma=Ia(254),ga=Ia(253),ya=Ia(252);function wa(e,t){if(typeof e!=typeof t)return console.log(`Type mismatch: ${typeof e} !== ${typeof t}`),0;if(e instanceof rt&&t instanceof rt)return e.eq(t);if("object"==typeof e&&null!==e&&null!==t){const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return console.log(`Key length mismatch: ${r.length} !== ${n.length}`),0;for(const o of r){if(!n.includes(o))return console.log(`Key ${o} not found in value`),0;if(!wa(e[o],t[o]))return console.log(`Value mismatch at key ${o}`),0}return 1}return e!==t&&console.log(`Value mismatch: ${e} !== ${t}`),e===t}async function va(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=Ia(r),o=await e.requestAirdrop(n.publicKey,t);return await qo(e,o),n}function ba(){return new c("http://127.0.0.1:8899","confirmed")}function Ia(e){if(e||(e=fa,fa++),e>255)return r.generate();const t=new Uint8Array(32);return t[31]=e,r.fromSeed(t)}if(import.meta.vitest){const{describe:e,it:t,expect:n}=import.meta.vitest;e("getTestKeypair",(()=>{t("should generate a keypair with a specific counter",(()=>{const e=Ia(10),t=Ia(10);n(e).toEqual(t),n(e).toBeInstanceOf(r),n(e.publicKey).toBeDefined(),n(e.secretKey).toBeDefined()})),t("should generate random keypair if counter is greater than 255",(()=>{const e=()=>Ia(256),t=e(),r=e();n(t).not.toEqual(r)})),t("should increment the global counter if no counter is provided",(()=>{const e=Ia(),t=Ia(),r=Ia(),o=Ia(3);n(e).not.toEqual(t),n(t).not.toEqual(r),n(r).toEqual(o)}))}))}var Aa,Ea,xa,Ma,_a,Ta,Sa,ka,Ca;!function(e){e.NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",e.NOT_U64="NOT_U64",e.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE"}(Aa||(Aa={})),function(e){e.FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",e.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS"}(Ea||(Ea={})),function(e){e.OWNER_UNDEFINED="OWNER_UNDEFINED",e.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",e.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED"}(xa||(xa={})),function(e){e.CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",e.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",e.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",e.RPC_INVALID="RPC_INVALID"}(Ma||(Ma={})),function(e){e.LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",e.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED"}(_a||(_a={})),function(e){e.NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED"}(Ta||(Ta={})),function(e){e.INVALID_PROOF="INVALID_PROOF",e.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",e.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED"}(Sa||(Sa={})),function(e){e.MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",e.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",e.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",e.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",e.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",e.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED"}(ka||(ka={})),function(e){e.ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",e.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",e.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",e.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",e.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",e.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",e.INVALID_NUMBER="INVALID_NUMBER"}(Ca||(Ca={}));class Pa extends Error{code;functionName;codeMessage;constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}class Ba extends Pa{}class La extends Pa{}class Oa extends Pa{}class Na extends Pa{}class Ra extends Pa{}class Ua extends Pa{}class Da extends Pa{}class Va extends Pa{}class qa extends Pa{}export{mr as ADDRESS_QUEUE_ROLLOVER_FEE,yr as ADDRESS_TREE_NETWORK_FEE_V1,wr as ADDRESS_TREE_NETWORK_FEE_V2,pa as ALICE,Hi as AccountProofResult,Yr as AppendLeavesInputLayout,Zr as AppendNullifyCreateAddressInputsMetaLayout,ot as BETA_REQUIRED_ERROR,ma as BOB,Ri as BalanceResult,ga as CHARLIE,kt as COMPRESSED_TOKEN_PROGRAM_ID,ct as COMPUTE_BUDGET_PATTERN,Ct as CTOKEN_PROGRAM_ID,Tr as CompressedAccountLayout,li as CompressedAccountResult,di as CompressedAccountResultV2,yi as CompressedAccountsByOwnerResult,wi as CompressedAccountsByOwnerResultV2,Or as CompressedCpiContextLayout,Fi as CompressedMintTokenHoldersResult,Lr as CompressedProofLayout,fi as CompressedTokenAccountResult,pi as CompressedTokenAccountResultV2,vi as CompressedTokenAccountsByOwnerOrDelegateResult,bi as CompressedTokenAccountsByOwnerOrDelegateResultV2,Ki as CompressedTransactionResult,Zi as CompressedTransactionResultV2,Oa as CreateUtxoError,xa as CreateUtxoErrorCode,ya as DAVE,cr as DEFAULT_MERKLE_TREE_HEIGHT,lr as DEFAULT_MERKLE_TREE_ROOTS,fs as DEFAULT_ZERO,Gs as DerivationMode,at as FIELD_SIZE,ut as HIGHEST_ADDRESS_PLUS_ONE,Ua as HashError,Ta as HashErrorCode,Ai as HealthResult,d as IDL,pt as INSERT_INTO_QUEUES_DISCRIMINATOR,dt as INVOKE_CPI_DISCRIMINATOR,ft as INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR,ht as INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR,lt as INVOKE_DISCRIMINATOR,Ur as InAccountLayout,hs as IndexedArray,ls as IndexedElement,ds as IndexedElementBundle,Xr as InsertAddressInputLayout,Gr as InsertNullifierInputLayout,Br as InstructionDataInvokeCpiLayout,qr as InstructionDataInvokeCpiWithReadOnlyLayout,Cr as InstructionDataInvokeLayout,Ei as LatestNonVotingSignaturesResult,xi as LatestNonVotingSignaturesResultPaginated,ns as LightSystemProgram,Ra as LookupTableError,_a as LookupTableErrorCode,Sr as MerkleContextLayout,Mi as MerkleProofResult,_i as MerkleProofResultV2,ps as MerkleTree,Va as MerkleTreeError,ka as MerkleTreeErrorCode,Qr as MerkleTreeSequenceNumberLayout,mi as MultipleCompressedAccountsResult,gi as MultipleCompressedAccountsResultV2,Oi as MultipleMerkleProofsResult,Ni as MultipleMerkleProofsResultV2,Ui as NativeBalanceResult,Nr as NewAddressParamsAssignedPackedLayout,kr as NewAddressParamsLayout,Ti as NewAddressProofResult,Mo as PackedAccounts,Rr as PackedMerkleContextLayout,Dr as PackedReadOnlyAddressLayout,Vr as PackedReadOnlyCompressedAccountLayout,Da as ProofError,Sa as ProofErrorCode,jr as PublicTransactionEventLayout,ki as RootIndexResultV2,la as Rpc,Na as RpcError,Ma as RpcErrorCode,gr as STATE_MERKLE_TREE_NETWORK_FEE,pr as STATE_MERKLE_TREE_ROLLOVER_FEE,La as SelectInUtxosError,Ea as SelectInUtxosErrorCode,$i as SignatureListResult,ji as SignatureListWithCursorResult,Yi as SignatureSource,Ii as SlotResult,_o as SystemAccountMetaConfig,fr as TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD,ha as TestRpc,Vi as TokenBalanceListResult,qi as TokenBalanceListResultV2,Di as TokenBalanceResult,hi as TokenDataResult,Je as TreeType,hr as UTXO_MERGE_MAXIMUM,dr as UTXO_MERGE_THRESHOLD,qa as UtilsError,Ca as UtilsErrorCode,Ba as UtxoError,Aa as UtxoErrorCode,et as VERSION,Ci as ValidityProofResult,Li as ValidityProofResultV2,yt as accountCompressionProgram,Vt as addressQueue,Dt as addressTree,Io as airdropSol,st as assertBetaEnabled,or as batchAddressTree,jt as batchCpiContext1,Zt as batchCpiContext2,Xt as batchCpiContext3,er as batchCpiContext4,nr as batchCpiContext5,sr as batchMerkleTree,Wt as batchMerkleTree1,zt as batchMerkleTree2,Yt as batchMerkleTree3,Qt as batchMerkleTree4,tr as batchMerkleTree5,ir as batchQueue,$t as batchQueue1,Kt as batchQueue2,Gt as batchQueue3,Jt as batchQueue4,rr as batchQueue5,Ar as bn,so as bufToDecStr,Fo as buildAndSignTx,Do as buildTx,ro as byteArrayToKeypair,Eo as calculateComputeUnitPrice,Po as checkValidityProofShape,ss as compress,ur as confirmConfig,Ao as confirmTransaction,qo as confirmTx,fo as convertInvokeCpiWithReadOnlyToInvoke,oa as convertMerkleProofsWithContextToHex,sa as convertNonInclusionMerkleProofInputsToHex,en as convertToPublicTransactionEvent,Ht as cpiContext2Pubkey,Rt as cpiContextPubkey,is as createAccount,as as createAccountWithLamports,br as createBN254,xr as createCompressedAccountLegacy,Er as createCompressedAccountMeta,Mr as createCompressedAccountWithMerkleContextLegacy,_r as createMerkleContextLegacy,ea as createRpc,ni as createRpcResult,Wo as createStateTreeLookupTable,Hr as decodeInstructionDataInvoke,Wr as decodeInstructionDataInvokeCpi,Fr as decodeInstructionDataInvokeCpiWithReadOnly,Kr as decodePublicTransactionEvent,us as decompress,xo as dedupeSigner,wa as deepEqual,At as defaultStateTreeLookupTables,bt as defaultStaticAccounts,It as defaultStaticAccountsStruct,Tt as defaultTestStateTreeAccounts,St as defaultTestStateTreeAccounts2,vo as deriveAddress,mo as deriveAddressLegacy,yo as deriveAddressSeed,po as deriveAddressSeedLegacy,go as deriveAddressSeedV2,wo as deriveAddressV2,Jr as deserializeAppendNullifyCreateAddressInputsIndexer,Ir as encodeBN254toBase58,Pr as encodeInstructionDataInvoke,zr as encodePublicTransactionEvent,$o as extendStateTreeLookupTable,nt as featureFlags,vt as getAccountCompressionAuthority,Jo as getAllStateTreeInfos,_t as getBatchAddressTreeInfo,Ms as getCompressedTokenAccountByHashTest,As as getCompressedTokenAccounts,xs as getCompressedTokenAccountsByDelegateTest,Es as getCompressedTokenAccountsByOwnerTest,ba as getConnection,xt as getDefaultAddressSpace,Mt as getDefaultAddressTreeInfo,tn as getIndexOrAdd,So as getLightSystemAccountMetas,To as getLightSystemAccountMetasLegacy,ko as getLightSystemAccountMetasV2,zo as getOutputQueue,Ko as getOutputTreeInfo,ms as getParsedEvents,aa as getPublicInputHash,wt as getRegisteredProgramPda,Zo as getStateTreeInfoByPubkey,Ia as getTestKeypair,da as getTestRpc,Yo as getTreeInfoByPubkey,uo as hashToBn254FieldSizeBe,lo as hashvToBn254FieldSizeBe,co as hashvToBn254FieldSizeBeU8Array,$r as invokeAccountsLayout,Xi as isDevnetCompat,Et as isLocalTest,io as isSmallerThanBn254FieldSizeBe,si as jsonRpcResult,ii as jsonRpcResultAndContext,gt as lightSystemProgram,ar as localTestActiveStateTreeInfos,ca as mergeSignatures,qt as merkleTree2Pubkey,Ut as merkletreePubkey,Lo as negateAndCompressProof,va as newAccountWithLamports,mt as noopProgram,Ot as nullifiedStateTreeLookupTableDevnet,Bt as nullifiedStateTreeLookupTableMainnet,Ft as nullifierQueue2Pubkey,Nt as nullifierQueuePubkey,jo as nullifyLookupTable,sn as packCompressedAccounts,es as packDecompressAccountsIdempotent,bo as packNewAddressParams,on as packTreeInfos,rn as padOutputStateMerkleTrees,Qi as parseAccountData,gs as parseEvents,ws as parseLightTransaction,ys as parsePublicTransactionEventWithIdl,Is as parseTokenLayoutWithIdl,Go as pickRandomTreeAndQueue,Uo as pipe,Co as placeholderValidityProof,Bo as proofFromJsonStruct,na as proverRequest,ho as pushUniqueItems,ra as rpcRequest,os as selectMinCompressedSolAccountsForTransfer,Qo as selectStateTreeInfo,Vo as sendAndConfirmTx,Ho as sleep,Lt as stateTreeLookupTableDevnet,Pt as stateTreeLookupTableMainnet,ts as sumUpLamports,nn as toAccountMetas,oo as toArray,ao as toCamelCase,no as toHex,Wi as toUnixTimestamp,cs as transfer,hn as validateNumbers,ln as validateNumbersForInclusionProof,dn as validateNumbersForNonInclusionProof,cn as validateNumbersForProof,un as validateSameOwner,an as validateSufficientBalance,it as versionedEndpoint,ta as wrapBigNumbersAsStrings};
2
2
  //# sourceMappingURL=index.js.map