@arcana/auth
Version:
Arcana Auth
1 lines • 125 kB
JavaScript
import{e,b as t,s as r,d as s,a as n,c as i,B as o,f as a,g as c,u,h as d,j as l,n as h,k as g,l as p,o as m,m as y,p as b,q as f,t as k,r as w,v as S,w as I,x as A,y as _,z as v,A as P,C as B,D as E,E as x,F as T,G as R,H as C,I as z,J as W,K as L,L as K,M as O,N,O as q,W as M}from"./vendor.chunk.js";const U=e.utils.randomPrivateKey,$=()=>{const t=e.utils.randomPrivateKey(),r=V(t),s=new Uint8Array(64);return s.set(t),s.set(r,32),{publicKey:r,secretKey:s}},V=e.getPublicKey;function D(t){try{return e.ExtendedPoint.fromHex(t),!0}catch{return!1}}const F=(t,r)=>e.sign(t,r.slice(0,32)),H=e.verify,j=e=>t.Buffer.isBuffer(e)?e:e instanceof Uint8Array?t.Buffer.from(e.buffer,e.byteOffset,e.byteLength):t.Buffer.from(e);class J{constructor(e){Object.assign(this,e)}encode(){return t.Buffer.from(r(X,this))}static decode(e){return s(X,this,e)}static decodeUnchecked(e){return n(X,this,e)}}class G extends J{constructor(e){if(super(e),this.enum="",1!==Object.keys(e).length)throw new Error("Enum can only take single value");Object.keys(e).map((e=>{this.enum=e}))}}const X=new Map;var Y;const Q=32,Z=32;let ee=1;class te extends J{constructor(e){if(super({}),this._bn=void 0,function(e){return void 0!==e._bn}(e))this._bn=e._bn;else{if("string"==typeof e){const t=i.decode(e);if(t.length!=Z)throw new Error("Invalid public key input");this._bn=new o(t)}else this._bn=new o(e);if(this._bn.byteLength()>Z)throw new Error("Invalid public key input")}}static unique(){const e=new te(ee);return ee+=1,new te(e.toBuffer())}equals(e){return this._bn.eq(e._bn)}toBase58(){return i.encode(this.toBytes())}toJSON(){return this.toBase58()}toBytes(){const e=this.toBuffer();return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}toBuffer(){const e=this._bn.toArrayLike(t.Buffer);if(e.length===Z)return e;const r=t.Buffer.alloc(32);return e.copy(r,32-e.length),r}get[Symbol.toStringTag](){return`PublicKey(${this.toString()})`}toString(){return this.toBase58()}static async createWithSeed(e,r,s){const n=t.Buffer.concat([e.toBuffer(),t.Buffer.from(r),s.toBuffer()]),i=a(n);return new te(i)}static createProgramAddressSync(e,r){let s=t.Buffer.alloc(0);e.forEach((function(e){if(e.length>32)throw new TypeError("Max seed length exceeded");s=t.Buffer.concat([s,j(e)])})),s=t.Buffer.concat([s,r.toBuffer(),t.Buffer.from("ProgramDerivedAddress")]);const n=a(s);if(D(n))throw new Error("Invalid seeds, address must fall off the curve");return new te(n)}static async createProgramAddress(e,t){return this.createProgramAddressSync(e,t)}static findProgramAddressSync(e,r){let s,n=255;for(;0!=n;){try{const i=e.concat(t.Buffer.from([n]));s=this.createProgramAddressSync(i,r)}catch(e){if(e instanceof TypeError)throw e;n--;continue}return[s,n]}throw new Error("Unable to find a viable program address nonce")}static async findProgramAddress(e,t){return this.findProgramAddressSync(e,t)}static isOnCurve(e){return D(new te(e).toBytes())}}Y=te,te.default=new Y("11111111111111111111111111111111"),X.set(te,{kind:"struct",fields:[["_bn","u256"]]});class re{constructor(e){if(this._publicKey=void 0,this._secretKey=void 0,e){const t=j(e);if(64!==e.length)throw new Error("bad secret key size");this._publicKey=t.slice(32,64),this._secretKey=t.slice(0,32)}else this._secretKey=j(U()),this._publicKey=j(V(this._secretKey))}get publicKey(){return new te(this._publicKey)}get secretKey(){return t.Buffer.concat([this._secretKey,this._publicKey],64)}}const se=new te("BPFLoader1111111111111111111111111111111111"),ne=1232,ie=127,oe=64;class ae extends Error{constructor(e){super(`Signature ${e} has expired: block height exceeded.`),this.signature=void 0,this.signature=e}}Object.defineProperty(ae.prototype,"name",{value:"TransactionExpiredBlockheightExceededError"});class ce extends Error{constructor(e,t){super(`Transaction was not confirmed in ${t.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${e} using the Solana Explorer or CLI tools.`),this.signature=void 0,this.signature=e}}Object.defineProperty(ce.prototype,"name",{value:"TransactionExpiredTimeoutError"});class ue extends Error{constructor(e){super(`Signature ${e} has expired: the nonce is no longer valid.`),this.signature=void 0,this.signature=e}}Object.defineProperty(ue.prototype,"name",{value:"TransactionExpiredNonceInvalidError"});class de{constructor(e,t){this.staticAccountKeys=void 0,this.accountKeysFromLookups=void 0,this.staticAccountKeys=e,this.accountKeysFromLookups=t}keySegments(){const e=[this.staticAccountKeys];return this.accountKeysFromLookups&&(e.push(this.accountKeysFromLookups.writable),e.push(this.accountKeysFromLookups.readonly)),e}get(e){for(const t of this.keySegments()){if(e<t.length)return t[e];e-=t.length}}get length(){return this.keySegments().flat().length}compileInstructions(e){if(this.length>256)throw new Error("Account index overflow encountered during compilation");const t=new Map;this.keySegments().flat().forEach(((e,r)=>{t.set(e.toBase58(),r)}));const r=e=>{const r=t.get(e.toBase58());if(void 0===r)throw new Error("Encountered an unknown instruction account key during compilation");return r};return e.map((e=>({programIdIndex:r(e.programId),accountKeyIndexes:e.keys.map((e=>r(e.pubkey))),data:e.data})))}}const le=(e="publicKey")=>d(32,e),he=(e="signature")=>d(64,e),ge=(e="string")=>{const r=c([g("length"),g("lengthPadding"),d(m(g(),-8),"chars")],e),s=r.decode.bind(r),n=r.encode.bind(r),i=r;return i.decode=(e,t)=>s(e,t).chars.toString(),i.encode=(e,r,s)=>{const i={chars:t.Buffer.from(e,"utf8")};return n(i,r,s)},i.alloc=e=>g().span+g().span+t.Buffer.from(e,"utf8").length,i};function pe(e,t){const r=e=>{if(e.span>=0)return e.span;if("function"==typeof e.alloc)return e.alloc(t[e.property]);if("count"in e&&"elementLayout"in e){const s=t[e.property];if(Array.isArray(s))return s.length*r(e.elementLayout)}else if("fields"in e)return pe({layout:e},t[e.property]);return 0};let s=0;return e.layout.fields.forEach((e=>{s+=r(e)})),s}function me(e){let t=0,r=0;for(;;){let s=e.shift();if(t|=(127&s)<<7*r,r+=1,!(128&s))break}return t}function ye(e,t){let r=t;for(;;){let t=127&r;if(r>>=7,0==r){e.push(t);break}t|=128,e.push(t)}}function be(e,t){if(!e)throw new Error(t||"Assertion failed")}class fe{constructor(e,t){this.payer=void 0,this.keyMetaMap=void 0,this.payer=e,this.keyMetaMap=t}static compile(e,t){const r=new Map,s=e=>{const t=e.toBase58();let s=r.get(t);return void 0===s&&(s={isSigner:!1,isWritable:!1,isInvoked:!1},r.set(t,s)),s},n=s(t);n.isSigner=!0,n.isWritable=!0;for(const t of e){s(t.programId).isInvoked=!0;for(const e of t.keys){const t=s(e.pubkey);t.isSigner||=e.isSigner,t.isWritable||=e.isWritable}}return new fe(t,r)}getMessageComponents(){const e=[...this.keyMetaMap.entries()];be(e.length<=256,"Max static account keys length exceeded");const t=e.filter((([,e])=>e.isSigner&&e.isWritable)),r=e.filter((([,e])=>e.isSigner&&!e.isWritable)),s=e.filter((([,e])=>!e.isSigner&&e.isWritable)),n=e.filter((([,e])=>!e.isSigner&&!e.isWritable)),i={numRequiredSignatures:t.length+r.length,numReadonlySignedAccounts:r.length,numReadonlyUnsignedAccounts:n.length};{be(t.length>0,"Expected at least one writable signer key");const[e]=t[0];be(e===this.payer.toBase58(),"Expected first writable signer key to be the fee payer")}return[i,[...t.map((([e])=>new te(e))),...r.map((([e])=>new te(e))),...s.map((([e])=>new te(e))),...n.map((([e])=>new te(e)))]]}extractTableLookup(e){const[t,r]=this.drainKeysFoundInLookupTable(e.state.addresses,(e=>!e.isSigner&&!e.isInvoked&&e.isWritable)),[s,n]=this.drainKeysFoundInLookupTable(e.state.addresses,(e=>!e.isSigner&&!e.isInvoked&&!e.isWritable));if(0!==t.length||0!==s.length)return[{accountKey:e.key,writableIndexes:t,readonlyIndexes:s},{writable:r,readonly:n}]}drainKeysFoundInLookupTable(e,t){const r=new Array,s=new Array;for(const[n,i]of this.keyMetaMap.entries())if(t(i)){const t=new te(n),i=e.findIndex((e=>e.equals(t)));i>=0&&(be(i<256,"Max lookup table index exceeded"),r.push(i),s.push(t),this.keyMetaMap.delete(n))}return[r,s]}}const ke="Reached end of buffer unexpectedly";function we(e){if(0===e.length)throw new Error(ke);return e.shift()}function Se(e,...t){const[r]=t;if(2===t.length?r+(t[1]??0)>e.length:r>=e.length)throw new Error(ke);return e.splice(...t)}class Ie{constructor(e){this.header=void 0,this.accountKeys=void 0,this.recentBlockhash=void 0,this.instructions=void 0,this.indexToProgramIds=new Map,this.header=e.header,this.accountKeys=e.accountKeys.map((e=>new te(e))),this.recentBlockhash=e.recentBlockhash,this.instructions=e.instructions,this.instructions.forEach((e=>this.indexToProgramIds.set(e.programIdIndex,this.accountKeys[e.programIdIndex])))}get version(){return"legacy"}get staticAccountKeys(){return this.accountKeys}get compiledInstructions(){return this.instructions.map((e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:i.decode(e.data)})))}get addressTableLookups(){return[]}getAccountKeys(){return new de(this.staticAccountKeys)}static compile(e){const t=fe.compile(e.instructions,e.payerKey),[r,s]=t.getMessageComponents(),n=new de(s).compileInstructions(e.instructions).map((e=>({programIdIndex:e.programIdIndex,accounts:e.accountKeyIndexes,data:i.encode(e.data)})));return new Ie({header:r,accountKeys:s,recentBlockhash:e.recentBlockhash,instructions:n})}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){const t=this.header.numRequiredSignatures;if(e>=this.header.numRequiredSignatures){return e-t<this.accountKeys.length-t-this.header.numReadonlyUnsignedAccounts}return e<t-this.header.numReadonlySignedAccounts}isProgramId(e){return this.indexToProgramIds.has(e)}programIds(){return[...this.indexToProgramIds.values()]}nonProgramIds(){return this.accountKeys.filter(((e,t)=>!this.isProgramId(t)))}serialize(){const e=this.accountKeys.length;let r=[];ye(r,e);const s=this.instructions.map((e=>{const{accounts:r,programIdIndex:s}=e,n=Array.from(i.decode(e.data));let o=[];ye(o,r.length);let a=[];return ye(a,n.length),{programIdIndex:s,keyIndicesCount:t.Buffer.from(o),keyIndices:r,dataLength:t.Buffer.from(a),data:n}}));let n=[];ye(n,s.length);let o=t.Buffer.alloc(ne);t.Buffer.from(n).copy(o);let a=n.length;s.forEach((e=>{const t=c([u("programIdIndex"),d(e.keyIndicesCount.length,"keyIndicesCount"),l(u("keyIndex"),e.keyIndices.length,"keyIndices"),d(e.dataLength.length,"dataLength"),l(u("userdatum"),e.data.length,"data")]).encode(e,o,a);a+=t})),o=o.slice(0,a);const h=c([d(1,"numRequiredSignatures"),d(1,"numReadonlySignedAccounts"),d(1,"numReadonlyUnsignedAccounts"),d(r.length,"keyCount"),l(le("key"),e,"keys"),le("recentBlockhash")]),g={numRequiredSignatures:t.Buffer.from([this.header.numRequiredSignatures]),numReadonlySignedAccounts:t.Buffer.from([this.header.numReadonlySignedAccounts]),numReadonlyUnsignedAccounts:t.Buffer.from([this.header.numReadonlyUnsignedAccounts]),keyCount:t.Buffer.from(r),keys:this.accountKeys.map((e=>j(e.toBytes()))),recentBlockhash:i.decode(this.recentBlockhash)};let p=t.Buffer.alloc(2048);const m=h.encode(g,p);return o.copy(p,m),p.slice(0,m+o.length)}static from(e){let r=[...e];const s=we(r);if(s!==(s&ie))throw new Error("Versioned messages must be deserialized with VersionedMessage.deserialize()");const n=we(r),o=we(r),a=me(r);let c=[];for(let e=0;e<a;e++){const e=Se(r,0,Z);c.push(new te(t.Buffer.from(e)))}const u=Se(r,0,Z),d=me(r);let l=[];for(let e=0;e<d;e++){const e=we(r),s=Se(r,0,me(r)),n=Se(r,0,me(r)),o=i.encode(t.Buffer.from(n));l.push({programIdIndex:e,accounts:s,data:o})}const h={header:{numRequiredSignatures:s,numReadonlySignedAccounts:n,numReadonlyUnsignedAccounts:o},recentBlockhash:i.encode(t.Buffer.from(u)),accountKeys:c,instructions:l};return new Ie(h)}}class Ae{constructor(e){this.header=void 0,this.staticAccountKeys=void 0,this.recentBlockhash=void 0,this.compiledInstructions=void 0,this.addressTableLookups=void 0,this.header=e.header,this.staticAccountKeys=e.staticAccountKeys,this.recentBlockhash=e.recentBlockhash,this.compiledInstructions=e.compiledInstructions,this.addressTableLookups=e.addressTableLookups}get version(){return 0}get numAccountKeysFromLookups(){let e=0;for(const t of this.addressTableLookups)e+=t.readonlyIndexes.length+t.writableIndexes.length;return e}getAccountKeys(e){let t;if(e&&"accountKeysFromLookups"in e&&e.accountKeysFromLookups){if(this.numAccountKeysFromLookups!=e.accountKeysFromLookups.writable.length+e.accountKeysFromLookups.readonly.length)throw new Error("Failed to get account keys because of a mismatch in the number of account keys from lookups");t=e.accountKeysFromLookups}else if(e&&"addressLookupTableAccounts"in e&&e.addressLookupTableAccounts)t=this.resolveAddressTableLookups(e.addressLookupTableAccounts);else if(this.addressTableLookups.length>0)throw new Error("Failed to get account keys because address table lookups were not resolved");return new de(this.staticAccountKeys,t)}isAccountSigner(e){return e<this.header.numRequiredSignatures}isAccountWritable(e){const t=this.header.numRequiredSignatures,r=this.staticAccountKeys.length;if(e>=r){return e-r<this.addressTableLookups.reduce(((e,t)=>e+t.writableIndexes.length),0)}if(e>=this.header.numRequiredSignatures){return e-t<r-t-this.header.numReadonlyUnsignedAccounts}return e<t-this.header.numReadonlySignedAccounts}resolveAddressTableLookups(e){const t={writable:[],readonly:[]};for(const r of this.addressTableLookups){const s=e.find((e=>e.key.equals(r.accountKey)));if(!s)throw new Error(`Failed to find address lookup table account for table key ${r.accountKey.toBase58()}`);for(const e of r.writableIndexes){if(!(e<s.state.addresses.length))throw new Error(`Failed to find address for index ${e} in address lookup table ${r.accountKey.toBase58()}`);t.writable.push(s.state.addresses[e])}for(const e of r.readonlyIndexes){if(!(e<s.state.addresses.length))throw new Error(`Failed to find address for index ${e} in address lookup table ${r.accountKey.toBase58()}`);t.readonly.push(s.state.addresses[e])}}return t}static compile(e){const t=fe.compile(e.instructions,e.payerKey),r=new Array,s={writable:new Array,readonly:new Array},n=e.addressLookupTableAccounts||[];for(const e of n){const n=t.extractTableLookup(e);if(void 0!==n){const[e,{writable:t,readonly:i}]=n;r.push(e),s.writable.push(...t),s.readonly.push(...i)}}const[i,o]=t.getMessageComponents(),a=new de(o,s).compileInstructions(e.instructions);return new Ae({header:i,staticAccountKeys:o,recentBlockhash:e.recentBlockhash,compiledInstructions:a,addressTableLookups:r})}serialize(){const e=Array();ye(e,this.staticAccountKeys.length);const t=this.serializeInstructions(),r=Array();ye(r,this.compiledInstructions.length);const s=this.serializeAddressTableLookups(),n=Array();ye(n,this.addressTableLookups.length);const o=c([u("prefix"),c([u("numRequiredSignatures"),u("numReadonlySignedAccounts"),u("numReadonlyUnsignedAccounts")],"header"),d(e.length,"staticAccountKeysLength"),l(le(),this.staticAccountKeys.length,"staticAccountKeys"),le("recentBlockhash"),d(r.length,"instructionsLength"),d(t.length,"serializedInstructions"),d(n.length,"addressTableLookupsLength"),d(s.length,"serializedAddressTableLookups")]),a=new Uint8Array(ne),h=o.encode({prefix:128,header:this.header,staticAccountKeysLength:new Uint8Array(e),staticAccountKeys:this.staticAccountKeys.map((e=>e.toBytes())),recentBlockhash:i.decode(this.recentBlockhash),instructionsLength:new Uint8Array(r),serializedInstructions:t,addressTableLookupsLength:new Uint8Array(n),serializedAddressTableLookups:s},a);return a.slice(0,h)}serializeInstructions(){let e=0;const t=new Uint8Array(ne);for(const r of this.compiledInstructions){const s=Array();ye(s,r.accountKeyIndexes.length);const n=Array();ye(n,r.data.length);e+=c([u("programIdIndex"),d(s.length,"encodedAccountKeyIndexesLength"),l(u(),r.accountKeyIndexes.length,"accountKeyIndexes"),d(n.length,"encodedDataLength"),d(r.data.length,"data")]).encode({programIdIndex:r.programIdIndex,encodedAccountKeyIndexesLength:new Uint8Array(s),accountKeyIndexes:r.accountKeyIndexes,encodedDataLength:new Uint8Array(n),data:r.data},t,e)}return t.slice(0,e)}serializeAddressTableLookups(){let e=0;const t=new Uint8Array(ne);for(const r of this.addressTableLookups){const s=Array();ye(s,r.writableIndexes.length);const n=Array();ye(n,r.readonlyIndexes.length);e+=c([le("accountKey"),d(s.length,"encodedWritableIndexesLength"),l(u(),r.writableIndexes.length,"writableIndexes"),d(n.length,"encodedReadonlyIndexesLength"),l(u(),r.readonlyIndexes.length,"readonlyIndexes")]).encode({accountKey:r.accountKey.toBytes(),encodedWritableIndexesLength:new Uint8Array(s),writableIndexes:r.writableIndexes,encodedReadonlyIndexesLength:new Uint8Array(n),readonlyIndexes:r.readonlyIndexes},t,e)}return t.slice(0,e)}static deserialize(e){let t=[...e];const r=we(t),s=r&ie;be(r!==s,"Expected versioned message but received legacy message");be(0===s,`Expected versioned message with version 0 but found version ${s}`);const n={numRequiredSignatures:we(t),numReadonlySignedAccounts:we(t),numReadonlyUnsignedAccounts:we(t)},o=[],a=me(t);for(let e=0;e<a;e++)o.push(new te(Se(t,0,Z)));const c=i.encode(Se(t,0,Z)),u=me(t),d=[];for(let e=0;e<u;e++){const e=we(t),r=Se(t,0,me(t)),s=me(t),n=new Uint8Array(Se(t,0,s));d.push({programIdIndex:e,accountKeyIndexes:r,data:n})}const l=me(t),h=[];for(let e=0;e<l;e++){const e=new te(Se(t,0,Z)),r=Se(t,0,me(t)),s=Se(t,0,me(t));h.push({accountKey:e,writableIndexes:r,readonlyIndexes:s})}return new Ae({header:n,staticAccountKeys:o,recentBlockhash:c,compiledInstructions:d,addressTableLookups:h})}}const _e={deserializeMessageVersion(e){const t=e[0],r=t&ie;return r===t?"legacy":r},deserialize:e=>{const t=_e.deserializeMessageVersion(e);if("legacy"===t)return Ie.from(e);if(0===t)return Ae.deserialize(e);throw new Error(`Transaction message version ${t} deserialization is not supported`)}};let ve=function(e){return e[e.BLOCKHEIGHT_EXCEEDED=0]="BLOCKHEIGHT_EXCEEDED",e[e.PROCESSED=1]="PROCESSED",e[e.TIMED_OUT=2]="TIMED_OUT",e[e.NONCE_INVALID=3]="NONCE_INVALID",e}({});const Pe=t.Buffer.alloc(64).fill(0);class Be{constructor(e){this.keys=void 0,this.programId=void 0,this.data=t.Buffer.alloc(0),this.programId=e.programId,this.keys=e.keys,e.data&&(this.data=e.data)}toJSON(){return{keys:this.keys.map((({pubkey:e,isSigner:t,isWritable:r})=>({pubkey:e.toJSON(),isSigner:t,isWritable:r}))),programId:this.programId.toJSON(),data:[...this.data]}}}class Ee{get signature(){return this.signatures.length>0?this.signatures[0].signature:null}constructor(e){if(this.signatures=[],this.feePayer=void 0,this.instructions=[],this.recentBlockhash=void 0,this.lastValidBlockHeight=void 0,this.nonceInfo=void 0,this.minNonceContextSlot=void 0,this._message=void 0,this._json=void 0,e)if(e.feePayer&&(this.feePayer=e.feePayer),e.signatures&&(this.signatures=e.signatures),Object.prototype.hasOwnProperty.call(e,"nonceInfo")){const{minContextSlot:t,nonceInfo:r}=e;this.minNonceContextSlot=t,this.nonceInfo=r}else if(Object.prototype.hasOwnProperty.call(e,"lastValidBlockHeight")){const{blockhash:t,lastValidBlockHeight:r}=e;this.recentBlockhash=t,this.lastValidBlockHeight=r}else{const{recentBlockhash:t,nonceInfo:r}=e;r&&(this.nonceInfo=r),this.recentBlockhash=t}}toJSON(){return{recentBlockhash:this.recentBlockhash||null,feePayer:this.feePayer?this.feePayer.toJSON():null,nonceInfo:this.nonceInfo?{nonce:this.nonceInfo.nonce,nonceInstruction:this.nonceInfo.nonceInstruction.toJSON()}:null,instructions:this.instructions.map((e=>e.toJSON())),signers:this.signatures.map((({publicKey:e})=>e.toJSON()))}}add(...e){if(0===e.length)throw new Error("No instructions");return e.forEach((e=>{"instructions"in e?this.instructions=this.instructions.concat(e.instructions):"data"in e&&"programId"in e&&"keys"in e?this.instructions.push(e):this.instructions.push(new Be(e))})),this}compileMessage(){if(this._message&&JSON.stringify(this.toJSON())===JSON.stringify(this._json))return this._message;let e,t,r;if(this.nonceInfo?(e=this.nonceInfo.nonce,t=this.instructions[0]!=this.nonceInfo.nonceInstruction?[this.nonceInfo.nonceInstruction,...this.instructions]:this.instructions):(e=this.recentBlockhash,t=this.instructions),!e)throw new Error("Transaction recentBlockhash required");if(t.length<1&&console.warn("No instructions provided"),this.feePayer)r=this.feePayer;else{if(!(this.signatures.length>0&&this.signatures[0].publicKey))throw new Error("Transaction fee payer required");r=this.signatures[0].publicKey}for(let e=0;e<t.length;e++)if(void 0===t[e].programId)throw new Error(`Transaction instruction index ${e} has undefined program id`);const s=[],n=[];t.forEach((e=>{e.keys.forEach((e=>{n.push({...e})}));const t=e.programId.toString();s.includes(t)||s.push(t)})),s.forEach((e=>{n.push({pubkey:new te(e),isSigner:!1,isWritable:!1})}));const o=[];n.forEach((e=>{const t=e.pubkey.toString(),r=o.findIndex((e=>e.pubkey.toString()===t));r>-1?(o[r].isWritable=o[r].isWritable||e.isWritable,o[r].isSigner=o[r].isSigner||e.isSigner):o.push(e)})),o.sort((function(e,t){if(e.isSigner!==t.isSigner)return e.isSigner?-1:1;if(e.isWritable!==t.isWritable)return e.isWritable?-1:1;return e.pubkey.toBase58().localeCompare(t.pubkey.toBase58(),"en",{localeMatcher:"best fit",usage:"sort",sensitivity:"variant",ignorePunctuation:!1,numeric:!1,caseFirst:"lower"})}));const a=o.findIndex((e=>e.pubkey.equals(r)));if(a>-1){const[e]=o.splice(a,1);e.isSigner=!0,e.isWritable=!0,o.unshift(e)}else o.unshift({pubkey:r,isSigner:!0,isWritable:!0});for(const e of this.signatures){const t=o.findIndex((t=>t.pubkey.equals(e.publicKey)));if(!(t>-1))throw new Error(`unknown signer: ${e.publicKey.toString()}`);o[t].isSigner||(o[t].isSigner=!0,console.warn("Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts should sign a transaction. This behavior is deprecated and will throw an error in the next major version release."))}let c=0,u=0,d=0;const l=[],h=[];o.forEach((({pubkey:e,isSigner:t,isWritable:r})=>{t?(l.push(e.toString()),c+=1,r||(u+=1)):(h.push(e.toString()),r||(d+=1))}));const g=l.concat(h),p=t.map((e=>{const{data:t,programId:r}=e;return{programIdIndex:g.indexOf(r.toString()),accounts:e.keys.map((e=>g.indexOf(e.pubkey.toString()))),data:i.encode(t)}}));return p.forEach((e=>{be(e.programIdIndex>=0),e.accounts.forEach((e=>be(e>=0)))})),new Ie({header:{numRequiredSignatures:c,numReadonlySignedAccounts:u,numReadonlyUnsignedAccounts:d},accountKeys:g,recentBlockhash:e,instructions:p})}_compile(){const e=this.compileMessage(),t=e.accountKeys.slice(0,e.header.numRequiredSignatures);if(this.signatures.length===t.length){if(this.signatures.every(((e,r)=>t[r].equals(e.publicKey))))return e}return this.signatures=t.map((e=>({signature:null,publicKey:e}))),e}serializeMessage(){return this._compile().serialize()}async getEstimatedFee(e){return(await e.getFeeForMessage(this.compileMessage())).value}setSigners(...e){if(0===e.length)throw new Error("No signers");const t=new Set;this.signatures=e.filter((e=>{const r=e.toString();return!t.has(r)&&(t.add(r),!0)})).map((e=>({signature:null,publicKey:e})))}sign(...e){if(0===e.length)throw new Error("No signers");const t=new Set,r=[];for(const s of e){const e=s.publicKey.toString();t.has(e)||(t.add(e),r.push(s))}this.signatures=r.map((e=>({signature:null,publicKey:e.publicKey})));const s=this._compile();this._partialSign(s,...r)}partialSign(...e){if(0===e.length)throw new Error("No signers");const t=new Set,r=[];for(const s of e){const e=s.publicKey.toString();t.has(e)||(t.add(e),r.push(s))}const s=this._compile();this._partialSign(s,...r)}_partialSign(e,...t){const r=e.serialize();t.forEach((e=>{const t=F(r,e.secretKey);this._addSignature(e.publicKey,j(t))}))}addSignature(e,t){this._compile(),this._addSignature(e,t)}_addSignature(e,r){be(64===r.length);const s=this.signatures.findIndex((t=>e.equals(t.publicKey)));if(s<0)throw new Error(`unknown signer: ${e.toString()}`);this.signatures[s].signature=t.Buffer.from(r)}verifySignatures(e=!0){return!this._getMessageSignednessErrors(this.serializeMessage(),e)}_getMessageSignednessErrors(e,t){const r={};for(const{signature:s,publicKey:n}of this.signatures)null===s?t&&(r.missing||=[]).push(n):H(s,e,n.toBytes())||(r.invalid||=[]).push(n);return r.invalid||r.missing?r:void 0}serialize(e){const{requireAllSignatures:t,verifySignatures:r}=Object.assign({requireAllSignatures:!0,verifySignatures:!0},e),s=this.serializeMessage();if(r){const e=this._getMessageSignednessErrors(s,t);if(e){let t="Signature verification failed.";throw e.invalid&&(t+=`\nInvalid signature for public key${1===e.invalid.length?"":"(s)"} [\`${e.invalid.map((e=>e.toBase58())).join("`, `")}\`].`),e.missing&&(t+=`\nMissing signature for public key${1===e.missing.length?"":"(s)"} [\`${e.missing.map((e=>e.toBase58())).join("`, `")}\`].`),new Error(t)}}return this._serialize(s)}_serialize(e){const{signatures:r}=this,s=[];ye(s,r.length);const n=s.length+64*r.length+e.length,i=t.Buffer.alloc(n);return be(r.length<256),t.Buffer.from(s).copy(i,0),r.forEach((({signature:e},r)=>{null!==e&&(be(64===e.length,"signature has invalid length"),t.Buffer.from(e).copy(i,s.length+64*r))})),e.copy(i,s.length+64*r.length),be(i.length<=ne,`Transaction too large: ${i.length} > 1232`),i}get keys(){return be(1===this.instructions.length),this.instructions[0].keys.map((e=>e.pubkey))}get programId(){return be(1===this.instructions.length),this.instructions[0].programId}get data(){return be(1===this.instructions.length),this.instructions[0].data}static from(e){let r=[...e];const s=me(r);let n=[];for(let e=0;e<s;e++){const e=Se(r,0,64);n.push(i.encode(t.Buffer.from(e)))}return Ee.populate(Ie.from(r),n)}static populate(e,t=[]){const r=new Ee;return r.recentBlockhash=e.recentBlockhash,e.header.numRequiredSignatures>0&&(r.feePayer=e.accountKeys[0]),t.forEach(((t,s)=>{const n={signature:t==i.encode(Pe)?null:i.decode(t),publicKey:e.accountKeys[s]};r.signatures.push(n)})),e.instructions.forEach((t=>{const s=t.accounts.map((t=>{const s=e.accountKeys[t];return{pubkey:s,isSigner:r.signatures.some((e=>e.publicKey.toString()===s.toString()))||e.isAccountSigner(t),isWritable:e.isAccountWritable(t)}}));r.instructions.push(new Be({keys:s,programId:e.accountKeys[t.programIdIndex],data:i.decode(t.data)}))})),r._message=e,r._json=r.toJSON(),r}}class xe{constructor(e){this.payerKey=void 0,this.instructions=void 0,this.recentBlockhash=void 0,this.payerKey=e.payerKey,this.instructions=e.instructions,this.recentBlockhash=e.recentBlockhash}static decompile(e,t){const{header:r,compiledInstructions:s,recentBlockhash:n}=e,{numRequiredSignatures:i,numReadonlySignedAccounts:o,numReadonlyUnsignedAccounts:a}=r,c=i-o;be(c>0,"Message header is invalid");const u=e.staticAccountKeys.length-i-a;be(u>=0,"Message header is invalid");const d=e.getAccountKeys(t),l=d.get(0);if(void 0===l)throw new Error("Failed to decompile message because no account keys were found");const h=[];for(const e of s){const t=[];for(const s of e.accountKeyIndexes){const e=d.get(s);if(void 0===e)throw new Error(`Failed to find key for account key index ${s}`);let n;n=s<i?s<c:s<d.staticAccountKeys.length?s-i<u:s-d.staticAccountKeys.length<d.accountKeysFromLookups.writable.length,t.push({pubkey:e,isSigner:s<r.numRequiredSignatures,isWritable:n})}const s=d.get(e.programIdIndex);if(void 0===s)throw new Error(`Failed to find program id for program id index ${e.programIdIndex}`);h.push(new Be({programId:s,data:j(e.data),keys:t}))}return new xe({payerKey:l,instructions:h,recentBlockhash:n})}compileToLegacyMessage(){return Ie.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions})}compileToV0Message(e){return Ae.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions,addressLookupTableAccounts:e})}}class Te{get version(){return this.message.version}constructor(e,t){if(this.signatures=void 0,this.message=void 0,void 0!==t)be(t.length===e.header.numRequiredSignatures,"Expected signatures length to be equal to the number of required signatures"),this.signatures=t;else{const t=[];for(let r=0;r<e.header.numRequiredSignatures;r++)t.push(new Uint8Array(64));this.signatures=t}this.message=e}serialize(){const e=this.message.serialize(),t=Array();ye(t,this.signatures.length);const r=c([d(t.length,"encodedSignaturesLength"),l(he(),this.signatures.length,"signatures"),d(e.length,"serializedMessage")]),s=new Uint8Array(2048),n=r.encode({encodedSignaturesLength:new Uint8Array(t),signatures:this.signatures,serializedMessage:e},s);return s.slice(0,n)}static deserialize(e){let t=[...e];const r=[],s=me(t);for(let e=0;e<s;e++)r.push(new Uint8Array(Se(t,0,64)));const n=_e.deserialize(new Uint8Array(t));return new Te(n,r)}sign(e){const t=this.message.serialize(),r=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures);for(const s of e){const e=r.findIndex((e=>e.equals(s.publicKey)));be(e>=0,`Cannot sign with non signer key ${s.publicKey.toBase58()}`),this.signatures[e]=F(t,s.secretKey)}}addSignature(e,t){be(64===t.byteLength,"Signature must be 64 bytes long");const r=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures).findIndex((t=>t.equals(e)));be(r>=0,`Can not add signature; \`${e.toBase58()}\` is not required to sign this transaction`),this.signatures[r]=t}}const Re=new te("SysvarC1ock11111111111111111111111111111111"),Ce=new te("SysvarEpochSchedu1e111111111111111111111111"),ze=new te("Sysvar1nstructions1111111111111111111111111"),We=new te("SysvarRecentB1ockHashes11111111111111111111"),Le=new te("SysvarRent111111111111111111111111111111111"),Ke=new te("SysvarRewards111111111111111111111111111111"),Oe=new te("SysvarS1otHashes111111111111111111111111111"),Ne=new te("SysvarS1otHistory11111111111111111111111111"),qe=new te("SysvarStakeHistory1111111111111111111111111");class Me extends Error{constructor({action:e,signature:t,transactionMessage:r,logs:s}){const n=s?`Logs: \n${JSON.stringify(s.slice(-10),null,2)}. `:"",i="\nCatch the `SendTransactionError` and call `getLogs()` on it for full details.";let o;switch(e){case"send":o=`Transaction ${t} resulted in an error. \n${r}. `+n+i;break;case"simulate":o=`Simulation failed. \nMessage: ${r}. \n`+n+i;break;default:o=`Unknown action '${e}'`}super(o),this.signature=void 0,this.transactionMessage=void 0,this.transactionLogs=void 0,this.signature=t,this.transactionMessage=r,this.transactionLogs=s||void 0}get transactionError(){return{message:this.transactionMessage,logs:Array.isArray(this.transactionLogs)?this.transactionLogs:void 0}}get logs(){const e=this.transactionLogs;if(null==e||"object"!=typeof e||!("then"in e))return e}async getLogs(e){return Array.isArray(this.transactionLogs)||(this.transactionLogs=new Promise(((t,r)=>{e.getTransaction(this.signature).then((e=>{if(e&&e.meta&&e.meta.logMessages){const r=e.meta.logMessages;this.transactionLogs=r,t(r)}else r(new Error("Log messages not found"))})).catch(r)}))),await this.transactionLogs}}const Ue={JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP:-32001,JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE:-32002,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE:-32003,JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE:-32004,JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY:-32005,JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE:-32006,JSON_RPC_SERVER_ERROR_SLOT_SKIPPED:-32007,JSON_RPC_SERVER_ERROR_NO_SNAPSHOT:-32008,JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED:-32009,JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX:-32010,JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE:-32011,JSON_RPC_SCAN_ERROR:-32012,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH:-32013,JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET:-32014,JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION:-32015,JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED:-32016};class $e extends Error{constructor({code:e,message:t,data:r},s){super(null!=s?`${s}: ${t}`:t),this.code=void 0,this.data=void 0,this.code=e,this.data=r,this.name="SolanaJSONRPCError"}}async function Ve(e,t,r,s){const n=s&&{skipPreflight:s.skipPreflight,preflightCommitment:s.preflightCommitment||s.commitment,maxRetries:s.maxRetries,minContextSlot:s.minContextSlot},i=await e.sendTransaction(t,r,n);let o;if(null!=t.recentBlockhash&&null!=t.lastValidBlockHeight)o=(await e.confirmTransaction({abortSignal:s?.abortSignal,signature:i,blockhash:t.recentBlockhash,lastValidBlockHeight:t.lastValidBlockHeight},s&&s.commitment)).value;else if(null!=t.minNonceContextSlot&&null!=t.nonceInfo){const{nonceInstruction:r}=t.nonceInfo,n=r.keys[0].pubkey;o=(await e.confirmTransaction({abortSignal:s?.abortSignal,minContextSlot:t.minNonceContextSlot,nonceAccountPubkey:n,nonceValue:t.nonceInfo.nonce,signature:i},s&&s.commitment)).value}else null!=s?.abortSignal&&console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable."),o=(await e.confirmTransaction(i,s&&s.commitment)).value;if(o.err){if(null!=i)throw new Me({action:"send",signature:i,transactionMessage:`Status: (${JSON.stringify(o)})`});throw new Error(`Transaction ${i} failed (${JSON.stringify(o)})`)}return i}function De(e){return new Promise((t=>setTimeout(t,e)))}function Fe(e,r){const s=e.layout.span>=0?e.layout.span:pe(e,r),n=t.Buffer.alloc(s),i=Object.assign({instruction:e.index},r);return e.layout.encode(i,n),n}function He(e,t){let r;try{r=e.layout.decode(t)}catch(e){throw new Error("invalid instruction; "+e)}if(r.instruction!==e.index)throw new Error(`invalid instruction; instruction index mismatch ${r.instruction} != ${e.index}`);return r}const je=h("lamportsPerSignature"),Je=c([g("version"),g("state"),le("authorizedPubkey"),le("nonce"),c([je],"feeCalculator")]),Ge=Je.span;class Xe{constructor(e){this.authorizedPubkey=void 0,this.nonce=void 0,this.feeCalculator=void 0,this.authorizedPubkey=e.authorizedPubkey,this.nonce=e.nonce,this.feeCalculator=e.feeCalculator}static fromAccountData(e){const t=Je.decode(j(e),0);return new Xe({authorizedPubkey:new te(t.authorizedPubkey),nonce:new te(t.nonce).toString(),feeCalculator:t.feeCalculator})}}function Ye(e){const t=d(8,e),r=t.decode.bind(t),s=t.encode.bind(t),n=t,i=L();return n.decode=(e,t)=>{const s=r(e,t);return i.decode(s)},n.encode=(e,t,r)=>{const n=i.encode(e);return s(n,t,r)},n}class Qe{constructor(){}static decodeInstructionType(e){this.checkProgramId(e.programId);const t=g("instruction").decode(e.data);let r;for(const[e,s]of Object.entries(Ze))if(s.index==t){r=e;break}if(!r)throw new Error("Instruction type incorrect; not a SystemInstruction");return r}static decodeCreateAccount(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);const{lamports:t,space:r,programId:s}=He(Ze.Create,e.data);return{fromPubkey:e.keys[0].pubkey,newAccountPubkey:e.keys[1].pubkey,lamports:t,space:r,programId:new te(s)}}static decodeTransfer(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);const{lamports:t}=He(Ze.Transfer,e.data);return{fromPubkey:e.keys[0].pubkey,toPubkey:e.keys[1].pubkey,lamports:t}}static decodeTransferWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);const{lamports:t,seed:r,programId:s}=He(Ze.TransferWithSeed,e.data);return{fromPubkey:e.keys[0].pubkey,basePubkey:e.keys[1].pubkey,toPubkey:e.keys[2].pubkey,lamports:t,seed:r,programId:new te(s)}}static decodeAllocate(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);const{space:t}=He(Ze.Allocate,e.data);return{accountPubkey:e.keys[0].pubkey,space:t}}static decodeAllocateWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);const{base:t,seed:r,space:s,programId:n}=He(Ze.AllocateWithSeed,e.data);return{accountPubkey:e.keys[0].pubkey,basePubkey:new te(t),seed:r,space:s,programId:new te(n)}}static decodeAssign(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);const{programId:t}=He(Ze.Assign,e.data);return{accountPubkey:e.keys[0].pubkey,programId:new te(t)}}static decodeAssignWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,1);const{base:t,seed:r,programId:s}=He(Ze.AssignWithSeed,e.data);return{accountPubkey:e.keys[0].pubkey,basePubkey:new te(t),seed:r,programId:new te(s)}}static decodeCreateWithSeed(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);const{base:t,seed:r,lamports:s,space:n,programId:i}=He(Ze.CreateWithSeed,e.data);return{fromPubkey:e.keys[0].pubkey,newAccountPubkey:e.keys[1].pubkey,basePubkey:new te(t),seed:r,lamports:s,space:n,programId:new te(i)}}static decodeNonceInitialize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3);const{authorized:t}=He(Ze.InitializeNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,authorizedPubkey:new te(t)}}static decodeNonceAdvance(e){return this.checkProgramId(e.programId),this.checkKeyLength(e.keys,3),He(Ze.AdvanceNonceAccount,e.data),{noncePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[2].pubkey}}static decodeNonceWithdraw(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,5);const{lamports:t}=He(Ze.WithdrawNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,toPubkey:e.keys[1].pubkey,authorizedPubkey:e.keys[4].pubkey,lamports:t}}static decodeNonceAuthorize(e){this.checkProgramId(e.programId),this.checkKeyLength(e.keys,2);const{authorized:t}=He(Ze.AuthorizeNonceAccount,e.data);return{noncePubkey:e.keys[0].pubkey,authorizedPubkey:e.keys[1].pubkey,newAuthorizedPubkey:new te(t)}}static checkProgramId(e){if(!e.equals(et.programId))throw new Error("invalid instruction; programId is not SystemProgram")}static checkKeyLength(e,t){if(e.length<t)throw new Error(`invalid instruction; found ${e.length} keys, expected at least ${t}`)}}const Ze=Object.freeze({Create:{index:0,layout:c([g("instruction"),p("lamports"),p("space"),le("programId")])},Assign:{index:1,layout:c([g("instruction"),le("programId")])},Transfer:{index:2,layout:c([g("instruction"),Ye("lamports")])},CreateWithSeed:{index:3,layout:c([g("instruction"),le("base"),ge("seed"),p("lamports"),p("space"),le("programId")])},AdvanceNonceAccount:{index:4,layout:c([g("instruction")])},WithdrawNonceAccount:{index:5,layout:c([g("instruction"),p("lamports")])},InitializeNonceAccount:{index:6,layout:c([g("instruction"),le("authorized")])},AuthorizeNonceAccount:{index:7,layout:c([g("instruction"),le("authorized")])},Allocate:{index:8,layout:c([g("instruction"),p("space")])},AllocateWithSeed:{index:9,layout:c([g("instruction"),le("base"),ge("seed"),p("space"),le("programId")])},AssignWithSeed:{index:10,layout:c([g("instruction"),le("base"),ge("seed"),le("programId")])},TransferWithSeed:{index:11,layout:c([g("instruction"),Ye("lamports"),ge("seed"),le("programId")])},UpgradeNonceAccount:{index:12,layout:c([g("instruction")])}});class et{constructor(){}static createAccount(e){const t=Fe(Ze.Create,{lamports:e.lamports,space:e.space,programId:j(e.programId.toBuffer())});return new Be({keys:[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!0,isWritable:!0}],programId:this.programId,data:t})}static transfer(e){let t,r;if("basePubkey"in e){t=Fe(Ze.TransferWithSeed,{lamports:BigInt(e.lamports),seed:e.seed,programId:j(e.programId.toBuffer())}),r=[{pubkey:e.fromPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}else{t=Fe(Ze.Transfer,{lamports:BigInt(e.lamports)}),r=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0}]}return new Be({keys:r,programId:this.programId,data:t})}static assign(e){let t,r;if("basePubkey"in e){t=Fe(Ze.AssignWithSeed,{base:j(e.basePubkey.toBuffer()),seed:e.seed,programId:j(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{t=Fe(Ze.Assign,{programId:j(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Be({keys:r,programId:this.programId,data:t})}static createAccountWithSeed(e){const t=Fe(Ze.CreateWithSeed,{base:j(e.basePubkey.toBuffer()),seed:e.seed,lamports:e.lamports,space:e.space,programId:j(e.programId.toBuffer())});let r=[{pubkey:e.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:e.newAccountPubkey,isSigner:!1,isWritable:!0}];return e.basePubkey.equals(e.fromPubkey)||r.push({pubkey:e.basePubkey,isSigner:!0,isWritable:!1}),new Be({keys:r,programId:this.programId,data:t})}static createNonceAccount(e){const t=new Ee;"basePubkey"in e&&"seed"in e?t.add(et.createAccountWithSeed({fromPubkey:e.fromPubkey,newAccountPubkey:e.noncePubkey,basePubkey:e.basePubkey,seed:e.seed,lamports:e.lamports,space:Ge,programId:this.programId})):t.add(et.createAccount({fromPubkey:e.fromPubkey,newAccountPubkey:e.noncePubkey,lamports:e.lamports,space:Ge,programId:this.programId}));const r={noncePubkey:e.noncePubkey,authorizedPubkey:e.authorizedPubkey};return t.add(this.nonceInitialize(r)),t}static nonceInitialize(e){const t=Fe(Ze.InitializeNonceAccount,{authorized:j(e.authorizedPubkey.toBuffer())}),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:We,isSigner:!1,isWritable:!1},{pubkey:Le,isSigner:!1,isWritable:!1}],programId:this.programId,data:t};return new Be(r)}static nonceAdvance(e){const t=Fe(Ze.AdvanceNonceAccount),r={keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:We,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:t};return new Be(r)}static nonceWithdraw(e){const t=Fe(Ze.WithdrawNonceAccount,{lamports:e.lamports});return new Be({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.toPubkey,isSigner:!1,isWritable:!0},{pubkey:We,isSigner:!1,isWritable:!1},{pubkey:Le,isSigner:!1,isWritable:!1},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:t})}static nonceAuthorize(e){const t=Fe(Ze.AuthorizeNonceAccount,{authorized:j(e.newAuthorizedPubkey.toBuffer())});return new Be({keys:[{pubkey:e.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:e.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:t})}static allocate(e){let t,r;if("basePubkey"in e){t=Fe(Ze.AllocateWithSeed,{base:j(e.basePubkey.toBuffer()),seed:e.seed,space:e.space,programId:j(e.programId.toBuffer())}),r=[{pubkey:e.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:e.basePubkey,isSigner:!0,isWritable:!1}]}else{t=Fe(Ze.Allocate,{space:e.space}),r=[{pubkey:e.accountPubkey,isSigner:!0,isWritable:!0}]}return new Be({keys:r,programId:this.programId,data:t})}}et.programId=new te("11111111111111111111111111111111");class tt{constructor(){}static getMinNumSignatures(e){return 2*(Math.ceil(e/tt.chunkSize)+1+1)}static async load(e,r,s,n,i){{const t=await e.getMinimumBalanceForRentExemption(i.length),o=await e.getAccountInfo(s.publicKey,"confirmed");let a=null;if(null!==o){if(o.executable)return console.error("Program load failed, account is already executable"),!1;o.data.length!==i.length&&(a=a||new Ee,a.add(et.allocate({accountPubkey:s.publicKey,space:i.length}))),o.owner.equals(n)||(a=a||new Ee,a.add(et.assign({accountPubkey:s.publicKey,programId:n}))),o.lamports<t&&(a=a||new Ee,a.add(et.transfer({fromPubkey:r.publicKey,toPubkey:s.publicKey,lamports:t-o.lamports})))}else a=(new Ee).add(et.createAccount({fromPubkey:r.publicKey,newAccountPubkey:s.publicKey,lamports:t>0?t:1,space:i.length,programId:n}));null!==a&&await Ve(e,a,[r,s],{commitment:"confirmed"})}const o=c([g("instruction"),g("offset"),g("bytesLength"),g("bytesLengthPadding"),l(u("byte"),m(g(),-8),"bytes")]),a=tt.chunkSize;let d=0,h=i,p=[];for(;h.length>0;){const i=h.slice(0,a),c=t.Buffer.alloc(a+16);o.encode({instruction:0,offset:d,bytes:i,bytesLength:0,bytesLengthPadding:0},c);const u=(new Ee).add({keys:[{pubkey:s.publicKey,isSigner:!0,isWritable:!0}],programId:n,data:c});if(p.push(Ve(e,u,[r,s],{commitment:"confirmed"})),e._rpcEndpoint.includes("solana.com")){const e=4;await De(1e3/e)}d+=a,h=h.slice(a)}await Promise.all(p);{const i=c([g("instruction")]),o=t.Buffer.alloc(i.span);i.encode({instruction:1},o);const a=(new Ee).add({keys:[{pubkey:s.publicKey,isSigner:!0,isWritable:!0},{pubkey:Le,isSigner:!1,isWritable:!1}],programId:n,data:o}),u="processed",d=await e.sendTransaction(a,[r,s],{preflightCommitment:u}),{context:l,value:h}=await e.confirmTransaction({signature:d,lastValidBlockHeight:a.lastValidBlockHeight,blockhash:a.recentBlockhash},u);if(h.err)throw new Error(`Transaction ${d} failed (${JSON.stringify(h)})`);for(;;){try{if(await e.getSlot({commitment:u})>l.slot)break}catch{}await new Promise((e=>setTimeout(e,Math.round(200))))}}return!0}}tt.chunkSize=932;const rt=new te("BPFLoader2111111111111111111111111111111111");class st{static getMinNumSignatures(e){return tt.getMinNumSignatures(e)}static load(e,t,r,s,n){return tt.load(e,t,r,n,s)}}function nt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var it,ot;function at(){if(ot)return it;ot=1;var e=Object.prototype.toString,t=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};function r(s,n){var i,o,a,c,u,d,l;if(!0===s)return"true";if(!1===s)return"false";switch(typeof s){case"object":if(null===s)return null;if(s.toJSON&&"function"==typeof s.toJSON)return r(s.toJSON(),n);if("[object Array]"===(l=e.call(s))){for(a="[",o=s.length-1,i=0;i<o;i++)a+=r(s[i],!0)+",";return o>-1&&(a+=r(s[i],!0)),a+"]"}if("[object Object]"===l){for(o=(c=t(s).sort()).length,a="",i=0;i<o;)void 0!==(d=r(s[u=c[i]],!1))&&(a&&(a+=","),a+=JSON.stringify(u)+":"+d),i++;return"{"+a+"}"}return JSON.stringify(s);case"function":case"undefined":return n?null:void 0;case"string":return JSON.stringify(s);default:return isFinite(s)?s:null}}return it=function(e){var t=r(e,!1);if(void 0!==t)return""+t}}var ct=nt(at());function ut(e){let t=0;for(;e>1;)e/=2,t++;return t}class dt{constructor(e,t,r,s,n){this.slotsPerEpoch=void 0,this.leaderScheduleSlotOffset=void 0,this.warmup=void 0,this.firstNormalEpoch=void 0,this.firstNormalSlot=void 0,this.slotsPerEpoch=e,this.leaderScheduleSlotOffset=t,this.warmup=r,this.firstNormalEpoch=s,this.firstNormalSlot=n}getEpoch(e){return this.getEpochAndSlotIndex(e)[0]}getEpochAndSlotIndex(e){if(e<this.firstNormalSlot){const r=ut(0===(t=e+32+1)?1:(t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,1+(t|=t>>32)))-ut(32)-1;return[r,e-(this.getSlotsInEpoch(r)-32)]}{const t=e-this.firstNormalSlot,r=Math.floor(t/this.slotsPerEpoch);return[this.firstNormalEpoch+r,t%this.slotsPerEpoch]}var t}getFirstSlotInEpoch(e){return e<=this.firstNormalEpoch?32*(Math.pow(2,e)-1):(e-this.firstNormalEpoch)*this.slotsPerEpoch+this.firstNormalSlot}getLastSlotInEpoch(e){return this.getFirstSlotInEpoch(e)+this.getSlotsInEpoch(e)-1}getSlotsInEpoch(e){return e<this.firstNormalEpoch?Math.pow(2,e+ut(32)):this.slotsPerEpoch}}var lt=globalThis.fetch;class ht extends K{constructor(e,t,r){super((e=>{const r=M(e,{autoconnect:!0,max_reconnects:5,reconnect:!0,reconnect_interval:1e3,...t});return this.underlyingSocket="socket"in r?r.socket:r,r}),e,t,r),this.underlyingSocket=void 0}call(...e){const t=this.underlyingSocket?.readyState;return 1===t?super.call(...e):Promise.reject(new Error("Tried to call a JSON-RPC method `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+")"))}notify(...e){const t=this.underlyingSocket?.readyState;return 1===t?super.notify(...e):Promise.reject(new Error("Tried to send a JSON-RPC notification `"+e[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+t+")"))}}class gt{constructor(e){this.key=void 0,this.state=void 0,this.key=e.key,this.state=e.state}isActive(){const e=BigInt("0xffffffffffffffff");return this.state.deactivationSlot===e}static deserialize(e){const t=function(e,t){let r;try{r=e.layout.decode(t)}catch(e){throw new Error("invalid instruction; "+e)}if(r.typeIndex!==e.index)throw new Error(`invalid account data; account type mismatch ${r.typeIndex} != ${e.index}`);return r}(pt,e),r=e.length-56;be(r>=0,"lookup table is invalid"),be(r%32==0,"lookup table is invalid");const s=r/32,{addresses:n}=c([l(le(),s,"addresses")]).decode(e.slice(56));return{deactivationSlot:t.deactivationSlot,lastExtendedSlot:t.lastExtendedSlot,lastExtendedSlotStartIndex:t.lastExtendedStartIndex,authority:0!==t.authority.length?new te(t.authority[0]):void 0,addresses:n.map((e=>new te(e)))}}}const pt={index:1,layout:c([g("typeIndex"),Ye("deactivationSlot"),h("lastExtendedSlot"),u("lastExtendedStartIndex"),u(),l(le(),m(u(),-1),"authority")])},mt=/^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;const yt=y(f(te),b(),(e=>new te(e))),bt=k([b(),w("base64")]),ft=y(f(t.Buffer),bt,(e=>t.Buffer.from(e[0],"base64"))),kt=3e4;function wt(e){let t,r;if("string"==typeof e)t=e;else if(e){const{commitment:s,...n}=e;t=s,r=n}return{commitment:t,config:r}}function St(e){return e.map((e=>"memcmp"in e?{...e,memcmp:{...e.memcmp,encoding:e.memcmp.encoding??"base58"}}:e))}function It(e){return x([I({jsonrpc:w("2.0"),id:b(),result:e}),I({jsonrpc:w("2.0"),id:b(),error:I({code:S(),message:b(),data:P(O())})})])}const At=It(S());function _t(e){return y(It(e),At,(t=>"error"in t?t:{...t,result:T(t.result,e)}))}function vt(e){return _t(I({context:I({slot:A()}),value:e}))}function Pt(e){return I({context:I({slot:A()}),value:e})}function Bt(e,t){return 0===e?new Ae({header:t.header,staticAccountKeys:t.accountKeys.map((e=>new te(e))),recentBlockhash:t.recentBlockhash,compiledInstructions:t.instructions.map((e=>({programIdIndex:e.programIdIndex,accountKeyIndexes:e.accounts,data:i.decode(e.data)}))),addressTableLookups:t.addressTableLookups}):new Ie(t)}const Et=I({foundation:A(),foundationTerm:A(),initial:A(),taper:A(),terminal:A()}),xt=_t(_(v(I({epoch:A(),effectiveSlot:A(),amount:A(),postBalance:A(),commission:P(v(A()))})))),Tt=_(I({slot:A(),prioritizationFee:A()})),Rt=